3.0.0 • Published 1 year ago

@mathquis/modelx-resolvables v3.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

ModelX Resolvables

Resolve ModelX model recursively

Installation

This package requires @mathquis/modelx installed as a peer dependency.

npm install -D @mathquis/modelx-resolvables

Usage

import { AbstractResolvableModel, AbstractResolvableCollection, resolvable } from '@mathquis/modelx-resolvables';
import { ResolvableModelClass, Identifier } from '@mathquis/modelx-resolvables/lib/types/AbstrackResolvableModel';

class ResolvableCollection extends AbstractResolvableCollection {
	public listById<T extends AbstractResolvableModel>(identifiers: Identifier[]): Promise<this> {
		// Implement how to list model by ids
	}
}

class UnresolvedModel extends AbstractResolvableModel {}

class ParentModel extends AbstractResolvableModel {}

class ResolvableModel extends AbstractResolvableModel {
	@resolvable(ParentModel, {
		// Model attribute used as resolvable attributes
		attributeName: 'parent',
		// Store the resolvable in cache for later resolutions
		cache: true,
		// Store the resolvable in a collection specific cache
		// If false (default) then store the resolvable in a global cache
		local: true,
		// Model to instanciate when the resolvable is not resolved
		unresolved: UnresolvedModel,
		// Only allow specific models (model and unresolved will be automatically allowed)
		allow: [ParentAltModel]
	})
	declare parent: ParentModel;

	static getResolvableCollection(): ResolvableCollection<AbstractResolvableModel> {
		// Implement this to provide a resolvable collection class for this model
	}

    protected getResolvableAttributes(propName: string, attributeName: string, attribute: any): IResolvableAttributes | undefined {
    	// Implement this to return attributes (with id property) of the resolvable for an attribute
    	// ex: return {...attribute, id: attribute.id};
    }

	public getModelClassFromAttribute(propName: string, attributeName: string, attribute: any): ResolvableModelClass<AbstractResolvableModel> | undefined {
		// Implement this to return different model according to the attribute value
		// Return nothing when you don't want to change the default model class define on the resolvable
	}

	protected getAttributeFromModel(propName: string, attributeName: string, model: AbstractResolvableModel): any {
		// Implement this to update the model with the specified resolvable attributes
		// ex: return model.attributes;
	}

}
3.0.0

1 year ago

2.2.0

2 years ago

2.1.3

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

3 years ago

1.0.0

3 years ago