Skip to main content

ModelTypeResolver

@webda/core


Class: ModelTypeResolver

Defined in: packages/models/lib/types-resolver.d.ts:53

Resolve the __type stored in a row (Webda 3 short, lower-case or renamed forms included) to a model

Resolution order, first match wins:

  1. the exact identifier (or a map key that is not the identifier);
  2. a @WebdaAlias, exact, then case-insensitive;
  3. an identifier, case-insensitive;
  4. for a value without /: <namespace>/<value> then Webda/<value>, case-insensitive, identifiers then aliases;
  5. otherwise unknown.

Two different models matching at the same step make the value ambiguous: it resolves to nothing.

Constructors​

Constructor​

new ModelTypeResolver(models, options?): ModelTypeResolver

Defined in: packages/models/lib/types-resolver.d.ts:80

Parameters​

models​

ModelClass<Storable<any, any>>[] | Record<string, ModelClass<Storable<any, any>>>

models by identifier (an application model map), or a list of classes carrying Metadata

options?​

ModelTypeResolverOptions

namespace and exact mode

Returns​

ModelTypeResolver

Properties​

accepted​

protected readonly accepted: Map<ModelClass<Storable<any, any>>, string[]>

Defined in: packages/models/lib/types-resolver.d.ts:75

Cache of accepted types


aliases​

protected readonly aliases: Map<string, Set<ModelClass<Storable<any, any>>>>

Defined in: packages/models/lib/types-resolver.d.ts:67

Aliases


byName​

protected readonly byName: Map<string, ModelClass<Storable<any, any>>>

Defined in: packages/models/lib/types-resolver.d.ts:59

Exact names (identifiers and extra map keys) to class


exactOnly​

readonly exactOnly: boolean

Defined in: packages/models/lib/types-resolver.d.ts:57

Only exact identifiers match


extraNames​

protected readonly extraNames: Map<ModelClass<Storable<any, any>>, string[]>

Defined in: packages/models/lib/types-resolver.d.ts:63

Map keys of a class that are not its identifier


families​

protected readonly families: Map<ModelClass<Storable<any, any>>, ModelClass<Storable<any, any>>[]>

Defined in: packages/models/lib/types-resolver.d.ts:73

Cache of families


identifiers​

protected readonly identifiers: Map<ModelClass<Storable<any, any>>, string>

Defined in: packages/models/lib/types-resolver.d.ts:61

Current identifier of each class


lowerAliases​

protected readonly lowerAliases: Map<string, Set<ModelClass<Storable<any, any>>>>

Defined in: packages/models/lib/types-resolver.d.ts:69

Lower-case aliases


lowerNames​

protected readonly lowerNames: Map<string, Set<ModelClass<Storable<any, any>>>>

Defined in: packages/models/lib/types-resolver.d.ts:65

Lower-case identifiers and extra names


namespace​

readonly namespace: string

Defined in: packages/models/lib/types-resolver.d.ts:55

Application namespace


resolutions​

protected readonly resolutions: Map<string, TypeResolution>

Defined in: packages/models/lib/types-resolver.d.ts:71

Cache of resolutions

Methods​

acceptedTypes()​

acceptedTypes(model): string[]

Defined in: packages/models/lib/types-resolver.d.ts:147

Every stored string that resolves to the model or one of its transitive subclasses: identifiers, short names, lower-case forms, aliases and their short and lower-case forms

Parameters​

model​

ModelClass

the model

Returns​

string[]

the strings, deduplicated


addName()​

protected addName(name, clazz, extra): void

Defined in: packages/models/lib/types-resolver.d.ts:87

Index a name of a class

Parameters​

name​

string

identifier or extra name

clazz​

ModelClass

the class

extra​

boolean

true for a map key that is not the identifier

Returns​

void


belongsToModel()​

belongsToModel(model, stored, tableRoot?): boolean

Defined in: packages/models/lib/types-resolver.d.ts:157

Whether a stored row belongs to a model

Parameters​

model​

ModelClass

the model queried

stored​

string

the stored __type, undefined for an untyped row

tableRoot?​

ModelClass

the model owning the untyped rows of the table, when known

Returns​

boolean

true when the row resolves to the model or one of its transitive subclasses; an untyped row belongs to the table root and its ancestors (to every model when the root is not known), and so does a row typed as a strict ancestor of the table root


computeResolution()​

protected computeResolution(stored): TypeResolution

Defined in: packages/models/lib/types-resolver.d.ts:122

Run the resolution steps

Parameters​

stored​

string

the stored value

Returns​

TypeResolution

the resolution


family()​

family(model): ModelClass<Storable<any, any>>[]

Defined in: packages/models/lib/types-resolver.d.ts:135

The model and all its transitive subclasses: from Metadata.Subclasses (direct only), then any known class extending the model that the metadata does not list

Parameters​

model​

ModelClass

the model

Returns​

ModelClass<Storable<any, any>>[]

the model first, then its subclasses


found()​

protected found(stored, model): TypeResolution

Defined in: packages/models/lib/types-resolver.d.ts:128

Parameters​

stored​

string

the stored value

model​

ModelClass

the matched model

Returns​

TypeResolution

the resolution of a match


getIdentifier()​

getIdentifier(model): string

Defined in: packages/models/lib/types-resolver.d.ts:105

Parameters​

model​

ModelClass

a class

Returns​

string

its current identifier, undefined when the class is not known


identifiersOf()​

identifiersOf(model): string[]

Defined in: packages/models/lib/types-resolver.d.ts:140

Parameters​

model​

ModelClass

the model

Returns​

string[]

the current identifiers of the model and its transitive subclasses


knows()​

knows(model): boolean

Defined in: packages/models/lib/types-resolver.d.ts:100

Parameters​

model​

ModelClass

a class

Returns​

boolean

true when the class is one of the models of this resolver


resolve()​

resolve(stored): TypeResolution

Defined in: packages/models/lib/types-resolver.d.ts:111

Resolve a stored __type

Parameters​

stored​

string

the stored value

Returns​

TypeResolution

the resolution


resolveStoredType()​

resolveStoredType(stored): ModelClass<Storable<any, any>>

Defined in: packages/models/lib/types-resolver.d.ts:116

Parameters​

stored​

string

the stored value

Returns​

ModelClass<Storable<any, any>>

the model, undefined when unknown or ambiguous


forHierarchy()​

static forHierarchy(model): ModelTypeResolver

Defined in: packages/models/lib/types-resolver.d.ts:95

Resolver of the hierarchy of a model only, exact identifiers only

Used for repositories whose model is not part of the installed application: today's exact matching.

Parameters​

model​

ModelClass

the model

Returns​

ModelTypeResolver

the resolver