Optional options: KosContainerAwareOptions<T>Configuration options for the decorator
A class decorator that modifies the target class prototype
// Minimal configuration - parentId automatically inferred
interface ItemContainerModelImpl extends KosContainerAware<ItemModel> {}
@kosContainerAware<ItemModel>()
class ItemContainerModelImpl implements IKosDataModel {
id: string;
constructor(modelId: string, options: ContainerOptions, context: KosCreationContext) {
this.id = modelId;
// Container automatically created with parentId: modelId
}
}
// With index configuration
interface UserContainerModelImpl extends KosContainerAware<UserModel> {}
@kosContainerAware<UserModel>({
containerOptions: {
indexMap: {
byRole: "role",
byStatus: (user) => user.status
}
}
})
class UserContainerModelImpl implements IKosDataModel {
constructor(modelId: string, options: ContainerOptions, context: KosCreationContext) {
this.id = modelId;
}
}
// Legacy mode for backward compatibility
interface LegacyContainerModelImpl extends KosContainerAware<LegacyModel> {}
@kosContainerAware<LegacyModel>({
legacy: true, // Uses '_models' as property name
containerOptions: {
sortKey: "name"
}
})
class LegacyContainerModelImpl implements IKosDataModel {
// Container available as this._models for backward compatibility
}
2.1.0
Class decorator that automatically adds container management capabilities to a KOS model.
This decorator eliminates the need for manual container setup by:
container) for managing model collectionsgetModel,addModel,removeModel,addAll,removeAll,removeAndDestroy,removeAndDestroyAll) ifincludeMethodsis true (default)models,data) ifincludeGettersis true (default)modelIdparametercontainerOptions.indexMapfor efficient queriesAutomatic Hierarchy Integration
The decorator automatically registers the container as a
@kosChild, ensuring:TypeScript Usage
IMPORTANT: Use TypeScript interface merging to get proper type information:
Model Lifecycle: removeModel vs removeAndDestroy
The decorator provides both removal and destruction methods with different purposes:
removeModel(id) / removeAll(ids) - Removes from container WITHOUT destroying:
removeAndDestroy(id) / removeAndDestroyAll(ids) - Removes AND destroys:
Configuration Options