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/Model.ts, line 13

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/Model.ts, line 642

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/Model.ts, line 633

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/Model.ts, line 626

If the constructor is not a function

Error
void