|
|
|
|
@@ -93,38 +93,62 @@ export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) {
|
|
|
|
|
// Initialize prototype properties from context.metadata (TC39 decorator metadata)
|
|
|
|
|
// This ensures prototype properties are available before any instance is created
|
|
|
|
|
const metadata = context.metadata as any;
|
|
|
|
|
logger.log('debug', `Collection decorator: metadata keys = ${metadata ? Object.keys(metadata).join(', ') : 'null'}`);
|
|
|
|
|
logger.log('debug', `Collection decorator: saveableProperties in metadata = ${metadata?.saveableProperties?.length ?? 0}`);
|
|
|
|
|
logger.log('debug', `Collection decorator: globalSaveableProperties in metadata = ${metadata?.globalSaveableProperties?.length ?? 0}`);
|
|
|
|
|
logger.log('debug', `Collection decorator for ${constructor.name}: metadata.saveableProperties = ${metadata?.saveableProperties?.length ?? 'undefined'}`);
|
|
|
|
|
if (metadata) {
|
|
|
|
|
const proto = decoratedClass.prototype;
|
|
|
|
|
const origProto = constructor.prototype;
|
|
|
|
|
|
|
|
|
|
// Initialize globalSaveableProperties
|
|
|
|
|
if (metadata.globalSaveableProperties && !proto.globalSaveableProperties) {
|
|
|
|
|
// Initialize globalSaveableProperties on BOTH prototypes
|
|
|
|
|
if (metadata.globalSaveableProperties) {
|
|
|
|
|
if (!proto.globalSaveableProperties) {
|
|
|
|
|
proto.globalSaveableProperties = [...metadata.globalSaveableProperties];
|
|
|
|
|
logger.log('debug', `Collection decorator: initialized globalSaveableProperties with ${proto.globalSaveableProperties.length} properties`);
|
|
|
|
|
}
|
|
|
|
|
if (!origProto.globalSaveableProperties) {
|
|
|
|
|
origProto.globalSaveableProperties = [...metadata.globalSaveableProperties];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize saveableProperties
|
|
|
|
|
if (metadata.saveableProperties && !proto.saveableProperties) {
|
|
|
|
|
// Initialize saveableProperties on BOTH prototypes (closure fix)
|
|
|
|
|
if (metadata.saveableProperties) {
|
|
|
|
|
if (!proto.saveableProperties) {
|
|
|
|
|
proto.saveableProperties = [...metadata.saveableProperties];
|
|
|
|
|
logger.log('debug', `Collection decorator: initialized saveableProperties with ${proto.saveableProperties.length} properties`);
|
|
|
|
|
}
|
|
|
|
|
// Also set on original constructor's prototype for closure references
|
|
|
|
|
if (!origProto.saveableProperties) {
|
|
|
|
|
origProto.saveableProperties = [...metadata.saveableProperties];
|
|
|
|
|
logger.log('debug', `Collection decorator: set saveableProperties on original prototype (${origProto.saveableProperties.length} props)`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize uniqueIndexes
|
|
|
|
|
if (metadata.uniqueIndexes && !proto.uniqueIndexes) {
|
|
|
|
|
// Initialize uniqueIndexes on BOTH prototypes
|
|
|
|
|
if (metadata.uniqueIndexes) {
|
|
|
|
|
if (!proto.uniqueIndexes) {
|
|
|
|
|
proto.uniqueIndexes = [...metadata.uniqueIndexes];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize regularIndexes
|
|
|
|
|
if (metadata.regularIndexes && !proto.regularIndexes) {
|
|
|
|
|
proto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
if (!origProto.uniqueIndexes) {
|
|
|
|
|
origProto.uniqueIndexes = [...metadata.uniqueIndexes];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize searchableFields on constructor (not prototype)
|
|
|
|
|
if (metadata.searchableFields && !Array.isArray((decoratedClass as any).searchableFields)) {
|
|
|
|
|
// Initialize regularIndexes on BOTH prototypes
|
|
|
|
|
if (metadata.regularIndexes) {
|
|
|
|
|
if (!proto.regularIndexes) {
|
|
|
|
|
proto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
}
|
|
|
|
|
if (!origProto.regularIndexes) {
|
|
|
|
|
origProto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize searchableFields on BOTH constructors
|
|
|
|
|
if (metadata.searchableFields) {
|
|
|
|
|
if (!Array.isArray((decoratedClass as any).searchableFields)) {
|
|
|
|
|
(decoratedClass as any).searchableFields = [...metadata.searchableFields];
|
|
|
|
|
}
|
|
|
|
|
if (!Array.isArray((constructor as any).searchableFields)) {
|
|
|
|
|
(constructor as any).searchableFields = [...metadata.searchableFields];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize _svDbOptions from metadata
|
|
|
|
|
if (metadata._svDbOptions && !originalConstructor._svDbOptions) {
|
|
|
|
|
@@ -249,31 +273,57 @@ export function managed<TManager extends IManager>(managerArg?: TManager | TDela
|
|
|
|
|
const metadata = context.metadata as any;
|
|
|
|
|
if (metadata) {
|
|
|
|
|
const proto = decoratedClass.prototype;
|
|
|
|
|
const origProto = constructor.prototype;
|
|
|
|
|
|
|
|
|
|
// Initialize globalSaveableProperties
|
|
|
|
|
if (metadata.globalSaveableProperties && !proto.globalSaveableProperties) {
|
|
|
|
|
// Initialize globalSaveableProperties on BOTH prototypes
|
|
|
|
|
if (metadata.globalSaveableProperties) {
|
|
|
|
|
if (!proto.globalSaveableProperties) {
|
|
|
|
|
proto.globalSaveableProperties = [...metadata.globalSaveableProperties];
|
|
|
|
|
}
|
|
|
|
|
if (!origProto.globalSaveableProperties) {
|
|
|
|
|
origProto.globalSaveableProperties = [...metadata.globalSaveableProperties];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize saveableProperties
|
|
|
|
|
if (metadata.saveableProperties && !proto.saveableProperties) {
|
|
|
|
|
// Initialize saveableProperties on BOTH prototypes (closure fix)
|
|
|
|
|
if (metadata.saveableProperties) {
|
|
|
|
|
if (!proto.saveableProperties) {
|
|
|
|
|
proto.saveableProperties = [...metadata.saveableProperties];
|
|
|
|
|
}
|
|
|
|
|
if (!origProto.saveableProperties) {
|
|
|
|
|
origProto.saveableProperties = [...metadata.saveableProperties];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize uniqueIndexes
|
|
|
|
|
if (metadata.uniqueIndexes && !proto.uniqueIndexes) {
|
|
|
|
|
// Initialize uniqueIndexes on BOTH prototypes
|
|
|
|
|
if (metadata.uniqueIndexes) {
|
|
|
|
|
if (!proto.uniqueIndexes) {
|
|
|
|
|
proto.uniqueIndexes = [...metadata.uniqueIndexes];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize regularIndexes
|
|
|
|
|
if (metadata.regularIndexes && !proto.regularIndexes) {
|
|
|
|
|
proto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
if (!origProto.uniqueIndexes) {
|
|
|
|
|
origProto.uniqueIndexes = [...metadata.uniqueIndexes];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize searchableFields on constructor (not prototype)
|
|
|
|
|
if (metadata.searchableFields && !Array.isArray((decoratedClass as any).searchableFields)) {
|
|
|
|
|
// Initialize regularIndexes on BOTH prototypes
|
|
|
|
|
if (metadata.regularIndexes) {
|
|
|
|
|
if (!proto.regularIndexes) {
|
|
|
|
|
proto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
}
|
|
|
|
|
if (!origProto.regularIndexes) {
|
|
|
|
|
origProto.regularIndexes = [...metadata.regularIndexes];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize searchableFields on BOTH constructors
|
|
|
|
|
if (metadata.searchableFields) {
|
|
|
|
|
if (!Array.isArray((decoratedClass as any).searchableFields)) {
|
|
|
|
|
(decoratedClass as any).searchableFields = [...metadata.searchableFields];
|
|
|
|
|
}
|
|
|
|
|
if (!Array.isArray((constructor as any).searchableFields)) {
|
|
|
|
|
(constructor as any).searchableFields = [...metadata.searchableFields];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize _svDbOptions from metadata
|
|
|
|
|
if (metadata._svDbOptions && !originalConstructor._svDbOptions) {
|
|
|
|
|
|