Class

ModelRegistryManager

ModelRegistryManager(testFunctionopt)

Constructor

# new ModelRegistryManager(testFunctionopt)

The ModelRegistryManager implements the ModelRegistry interface and provides functionality for registering, retrieving, and building model instances. It maintains a cache of model constructors indexed by name, allowing for efficient lookup and instantiation. This class is essential for the serialization and deserialization of model objects.

Registry manager for model constructors that enables serialization and rebuilding

sequenceDiagram participant C as Client participant R as ModelRegistryManager participant M as Model Class C->>R: new ModelRegistryManager(testFunction) C->>R: register(ModelClass) R->>R: Store in cache C->>R: get("ModelName") R-->>C: ModelClass constructor C->>R: build(data, "ModelName") R->>R: Get constructor from cache R->>M: new ModelClass(data) M-->>R: Model instance R-->>C: Model instance
Parameters:
Name Type Attributes Description
testFunction function <optional>

Function to test if an object is a model, defaults to Model#isModel

Implements:
  • ModelRegistry.<M>

View Source model/ModelRegistry.ts, line 7

Example
```typescript
// Create a model registry
const registry = new ModelRegistryManager();

// Register a model class
registry.register(User);

// Retrieve a model constructor by name
const UserClass = registry.get("User");

// Build a model instance from a plain object
const userData = { name: "John", age: 30 };
const user = registry.build(userData, "User");
```

Methods

# build(obj, clazzopt) → {M}

Parameters:
Name Type Attributes Description
obj Record.<string, any>
clazz string <optional>

when provided, it will attempt to find the matching constructor

View Source model/ModelRegistry.ts, line 332

Error If clazz is not found, or obj is not a Model meaning it has no ModelKeys.ANCHOR property

M

# get(name) → {ModelConstructor.<M>|undefined}

Gets a registered Model ModelConstructor

Parameters:
Name Type Description
name string

View Source model/ModelRegistry.ts, line 323

ModelConstructor.<M> | undefined

# register(constructor, nameopt) → {void}

Adds a model constructor to the registry cache, making it available for later retrieval and instantiation. If no name is provided, the constructor's name property is used as the key in the registry.

Registers a model constructor with the registry

Parameters:
Name Type Attributes Description
constructor ModelConstructor.<M>

The model constructor to register

name string <optional>

Optional name to register the constructor under, defaults to constructor.name

View Source model/ModelRegistry.ts, line 316

If the constructor is not a function

Error
void

# static fromModel(self, objopt) → {T}

Repopulates the instance with properties from the new Model Object, recursively rebuilding nested models

Copies and rebuilds properties from a source object to a model instance, handling nested models

sequenceDiagram participant C as Client participant M as Model.fromModel participant B as Model.build participant R as Reflection C->>M: fromModel(self, obj) M->>M: Get attributes from self loop For each property M->>M: Copy property from obj to self alt Property is a model M->>M: Check if property is a model M->>B: build(property, modelType) B-->>M: Return built model else Property is a complex type M->>R: Get property decorators R-->>M: Return decorators M->>M: Filter type decorators alt Property is Array/Set with list decorator M->>M: Process each item in collection loop For each item M->>B: build(item, itemModelType) B-->>M: Return built model end else Property is another model type M->>B: build(property, propertyType) B-->>M: Return built model end end end M-->>C: Return updated self
Parameters:
Name Type Attributes Description
self T

The target model instance to update

obj T | Record.<string, any> <optional>

The source object containing properties to copy

View Source model/ModelRegistry.ts, line 393

  • The updated model instance with rebuilt nested models
T

# static getBuilder() → {ModelBuilderFunction|undefined}

Returns the current global ModelBuilderFunction used for building model instances

Retrieves the currently configured global model builder function

View Source model/ModelRegistry.ts, line 349

  • The current global builder function or undefined if not set
ModelBuilderFunction | undefined

# static setBuilder(builderopt) → {void}

Sets the Global ModelBuilderFunction used for building model instances

Configures the global model builder function

Parameters:
Name Type Attributes Description
builder ModelBuilderFunction <optional>

The builder function to set as the global builder

View Source model/ModelRegistry.ts, line 341

void

# static setRegistry(modelRegistry) → {void}

Sets the current model registry to a custom implementation

Configures the model registry to be used by the Model system

Parameters:
Name Type Description
modelRegistry BuilderRegistry.<any>

The new implementation of Registry to use

View Source model/ModelRegistry.ts, line 411

void