@happyvertical/smrt-core 0.36.8 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/child-accessors.d.ts +1 -1
  2. package/dist/child-accessors.d.ts.map +1 -1
  3. package/dist/child-accessors.js +1 -1
  4. package/dist/child-accessors.js.map +1 -1
  5. package/dist/class.d.ts.map +1 -1
  6. package/dist/class.js +3 -1
  7. package/dist/class.js.map +1 -1
  8. package/dist/collection-cache.d.ts.map +1 -1
  9. package/dist/collection-cache.js +5 -3
  10. package/dist/collection-cache.js.map +1 -1
  11. package/dist/collection.d.ts +39 -16
  12. package/dist/collection.d.ts.map +1 -1
  13. package/dist/collection.js +40 -19
  14. package/dist/collection.js.map +1 -1
  15. package/dist/decorators/compatibility.d.ts +1 -1
  16. package/dist/decorators/compatibility.d.ts.map +1 -1
  17. package/dist/decorators/compatibility.js.map +1 -1
  18. package/dist/decorators/index.d.ts +4 -4
  19. package/dist/decorators/index.d.ts.map +1 -1
  20. package/dist/decorators/index.js.map +1 -1
  21. package/dist/hierarchical.d.ts.map +1 -1
  22. package/dist/hierarchical.js.map +1 -1
  23. package/dist/junction.d.ts.map +1 -1
  24. package/dist/junction.js.map +1 -1
  25. package/dist/manifest/static-manifest.d.ts.map +1 -1
  26. package/dist/manifest/static-manifest.js +39 -20
  27. package/dist/manifest/static-manifest.js.map +1 -1
  28. package/dist/manifest/store.js +2 -2
  29. package/dist/manifest/store.js.map +1 -1
  30. package/dist/manifest/test-manifest-stub.d.ts.map +1 -1
  31. package/dist/manifest/test-manifest-stub.js +2301 -629
  32. package/dist/manifest/test-manifest-stub.js.map +1 -1
  33. package/dist/manifest.json +39 -20
  34. package/dist/object.d.ts +64 -17
  35. package/dist/object.d.ts.map +1 -1
  36. package/dist/object.js +76 -30
  37. package/dist/object.js.map +1 -1
  38. package/dist/registry/class-registration.d.ts +3 -3
  39. package/dist/registry/class-registration.d.ts.map +1 -1
  40. package/dist/registry/class-registration.js +39 -42
  41. package/dist/registry/class-registration.js.map +1 -1
  42. package/dist/registry/inheritance-resolver.d.ts +17 -3
  43. package/dist/registry/inheritance-resolver.d.ts.map +1 -1
  44. package/dist/registry/inheritance-resolver.js +1 -1
  45. package/dist/registry/inheritance-resolver.js.map +1 -1
  46. package/dist/registry/manifest-field-merge.d.ts +17 -3
  47. package/dist/registry/manifest-field-merge.d.ts.map +1 -1
  48. package/dist/registry/manifest-field-merge.js +8 -6
  49. package/dist/registry/manifest-field-merge.js.map +1 -1
  50. package/dist/registry/schema-builder.d.ts +1 -1
  51. package/dist/registry/schema-builder.d.ts.map +1 -1
  52. package/dist/registry/schema-builder.js.map +1 -1
  53. package/dist/registry/shared-state.d.ts +3 -3
  54. package/dist/registry/shared-state.d.ts.map +1 -1
  55. package/dist/registry/shared-state.js.map +1 -1
  56. package/dist/registry/types.d.ts +78 -19
  57. package/dist/registry/types.d.ts.map +1 -1
  58. package/dist/registry/validator.d.ts +2 -1
  59. package/dist/registry/validator.d.ts.map +1 -1
  60. package/dist/registry/validator.js +38 -39
  61. package/dist/registry/validator.js.map +1 -1
  62. package/dist/registry.d.ts +84 -57
  63. package/dist/registry.d.ts.map +1 -1
  64. package/dist/registry.js +31 -25
  65. package/dist/registry.js.map +1 -1
  66. package/dist/smrt-knowledge.json +5 -4
  67. package/dist/system-fields.d.ts +1 -1
  68. package/dist/system-fields.d.ts.map +1 -1
  69. package/dist/system-fields.js.map +1 -1
  70. package/package.json +4 -4
@@ -4,7 +4,7 @@ export type LegacyPropertyDecoratorTarget = {
4
4
  };
5
5
  };
6
6
  export type CompatiblePropertyDecoratorContext<This, Value> = string | symbol | ClassFieldDecoratorContext<This, Value>;
7
- export interface CompatiblePropertyDecorator<This = any, Value = any> {
7
+ export interface CompatiblePropertyDecorator<This = unknown, Value = unknown> {
8
8
  (target: object, propertyKey: string | symbol): void;
9
9
  (value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../src/decorators/compatibility.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,CAAC,EAAE,QAAQ,GAAG;QACvB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,CAAC,IAAI,EAAE,KAAK,IACtD,MAAM,GACN,MAAM,GACN,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAE5C,MAAM,WAAW,2BAA2B,CAAC,IAAI,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG;IAClE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACrD,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;CAC5E;AA2FD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU7E;AAED,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,QAAQ,EAChB,gBAAgB,CAAC,EAAE,qBAAqB,GACvC,IAAI,CAsBN;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,KAAK,EAC1D,aAAa,EAAE,6BAA6B,GAAG,SAAS,EACxD,oBAAoB,EAAE,kCAAkC,CAAC,IAAI,EAAE,KAAK,CAAC,EACrE,sBAAsB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,GACvE,IAAI,CAiCN"}
1
+ {"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../src/decorators/compatibility.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,CAAC,EAAE,QAAQ,GAAG;QACvB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,CAAC,IAAI,EAAE,KAAK,IACtD,MAAM,GACN,MAAM,GACN,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAE5C,MAAM,WAAW,2BAA2B,CAAC,IAAI,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IAC1E,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACrD,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;CAC5E;AA2FD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU7E;AAED,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,QAAQ,EAChB,gBAAgB,CAAC,EAAE,qBAAqB,GACvC,IAAI,CAsBN;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,KAAK,EAC1D,aAAa,EAAE,6BAA6B,GAAG,SAAS,EACxD,oBAAoB,EAAE,kCAAkC,CAAC,IAAI,EAAE,KAAK,CAAC,EACrE,sBAAsB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,GACvE,IAAI,CAiCN"}
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.js","sources":["../../src/decorators/compatibility.ts"],"sourcesContent":["type DecoratorMetadataStore = Record<PropertyKey, unknown>;\n\nconst PENDING_FIELD_DECORATORS_KEY = Symbol.for(\n '@happyvertical/smrt-core/pending-field-decorators',\n);\nconst standardDecoratorRegistrations = new WeakMap<\n Function,\n WeakSet<(className: string) => void>\n>();\n\ntype PendingDecoratorRegistration = {\n register: (className: string) => void;\n};\n\nexport type LegacyPropertyDecoratorTarget = {\n constructor?: Function & {\n name?: string;\n };\n};\n\nexport type CompatiblePropertyDecoratorContext<This, Value> =\n | string\n | symbol\n | ClassFieldDecoratorContext<This, Value>;\n\nexport interface CompatiblePropertyDecorator<This = any, Value = any> {\n (target: object, propertyKey: string | symbol): void;\n (value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;\n}\n\nfunction getDecoratorConstructor(target: unknown): Function | undefined {\n if (typeof target === 'function') {\n return target;\n }\n\n if (target && typeof target === 'object') {\n return (target as LegacyPropertyDecoratorTarget).constructor;\n }\n\n return undefined;\n}\n\nfunction markStandardDecoratorRegistration(\n target: unknown,\n register: (className: string) => void,\n): boolean {\n const ctor = getDecoratorConstructor(target);\n if (!ctor) {\n return false;\n }\n\n const registeredCallbacks =\n standardDecoratorRegistrations.get(ctor) ?? new WeakSet();\n if (registeredCallbacks.has(register)) {\n return false;\n }\n\n registeredCallbacks.add(register);\n standardDecoratorRegistrations.set(ctor, registeredCallbacks);\n return true;\n}\n\nfunction getDecoratorMetadata(\n contextOrMetadata:\n | ClassFieldDecoratorContext<any, any>\n | ClassDecoratorContext\n | DecoratorMetadataStore\n | undefined,\n): DecoratorMetadataStore | undefined {\n if (!contextOrMetadata || typeof contextOrMetadata !== 'object') {\n return undefined;\n }\n\n if ('metadata' in contextOrMetadata) {\n const { metadata } = contextOrMetadata as {\n metadata?: DecoratorMetadataStore;\n };\n return metadata && typeof metadata === 'object' ? metadata : undefined;\n }\n\n return contextOrMetadata;\n}\n\nfunction getClassDecoratorMetadata(\n target: Function,\n decoratorContext?: ClassDecoratorContext,\n): DecoratorMetadataStore | undefined {\n const metadataFromContext = getDecoratorMetadata(decoratorContext);\n if (metadataFromContext) {\n return metadataFromContext;\n }\n\n const metadataSymbol = (Symbol as typeof Symbol & { metadata?: symbol })\n .metadata;\n if (!metadataSymbol) {\n return undefined;\n }\n\n const metadata = (target as unknown as Record<PropertyKey, unknown>)[\n metadataSymbol\n ];\n return metadata && typeof metadata === 'object'\n ? (metadata as DecoratorMetadataStore)\n : undefined;\n}\n\nfunction queuePendingFieldDecorator(\n metadata: DecoratorMetadataStore,\n register: (className: string) => void,\n): void {\n const pendingDecorators =\n (metadata[PENDING_FIELD_DECORATORS_KEY] as\n | PendingDecoratorRegistration[]\n | undefined) ?? [];\n\n pendingDecorators.push({ register });\n metadata[PENDING_FIELD_DECORATORS_KEY] = pendingDecorators;\n}\n\nexport function resolveDecoratorClassName(target: unknown): string | undefined {\n if (typeof target === 'function') {\n return target.name;\n }\n\n if (target && typeof target === 'object') {\n return (target as LegacyPropertyDecoratorTarget).constructor?.name;\n }\n\n return undefined;\n}\n\nexport function applyPendingDecoratorRegistrations(\n target: Function,\n decoratorContext?: ClassDecoratorContext,\n): void {\n const metadata = getClassDecoratorMetadata(target, decoratorContext);\n if (!metadata) {\n return;\n }\n\n const pendingDecorators = metadata[PENDING_FIELD_DECORATORS_KEY] as\n | PendingDecoratorRegistration[]\n | undefined;\n if (!pendingDecorators || pendingDecorators.length === 0) {\n return;\n }\n\n for (const { register } of pendingDecorators) {\n if (!markStandardDecoratorRegistration(target, register)) {\n continue;\n }\n\n register(target.name);\n }\n\n Reflect.deleteProperty(metadata, PENDING_FIELD_DECORATORS_KEY);\n}\n\nexport function registerCompatibleFieldDecorator<This, Value>(\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<This, Value>,\n registerFieldDecorator: (className: string, propertyKey: string) => void,\n): void {\n if (\n typeof propertyKeyOrContext === 'string' ||\n typeof propertyKeyOrContext === 'symbol'\n ) {\n const className = resolveDecoratorClassName(targetOrValue);\n if (className) {\n registerFieldDecorator(className, String(propertyKeyOrContext));\n }\n return;\n }\n\n const context = propertyKeyOrContext;\n const propertyKey = String(context.name);\n const register = (className: string) =>\n registerFieldDecorator(className, propertyKey);\n const metadata = getDecoratorMetadata(context);\n\n if (metadata) {\n queuePendingFieldDecorator(metadata, register);\n return;\n }\n\n context.addInitializer?.(function registerSmrtDecorator() {\n if (!markStandardDecoratorRegistration(this, register)) {\n return;\n }\n\n const className = resolveDecoratorClassName(this);\n if (className) {\n register(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,OAAO,WAAW,YAAY;AAChC,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,UAAU,OAAO,WAAW,UAAU;AACxC,WAAQ,OAAyC,aAAa;AAAA,EAChE;AAEA,SAAO;AACT;AAEO,SAAS,mCACd,QACA,kBACM;AACN,QAAM,WAAW,0BAA0B,QAAQ,gBAAgB;AACnE,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,QAAM,oBAAoB,SAAS,4BAA4B;AAG/D,MAAI,CAAC,qBAAqB,kBAAkB,WAAW,GAAG;AACxD;AAAA,EACF;AAEA,aAAW,EAAE,SAAA,KAAc,mBAAmB;AAC5C,QAAI,CAAC,kCAAkC,QAAQ,QAAQ,GAAG;AACxD;AAAA,IACF;AAEA,aAAS,OAAO,IAAI;AAAA,EACtB;AAEA,UAAQ,eAAe,UAAU,4BAA4B;AAC/D;AAEO,SAAS,iCACd,eACA,sBACA,wBACM;AACN,MACE,OAAO,yBAAyB,YAChC,OAAO,yBAAyB,UAChC;AACA,UAAM,YAAY,0BAA0B,aAAa;AACzD,QAAI,WAAW;AACb,6BAAuB,WAAW,OAAO,oBAAoB,CAAC;AAAA,IAChE;AACA;AAAA,EACF;AAEA,QAAM,UAAU;AAChB,QAAM,cAAc,OAAO,QAAQ,IAAI;AACvC,QAAM,WAAW,CAAC,cAChB,uBAAuB,WAAW,WAAW;AAC/C,QAAM,WAAW,qBAAqB,OAAO;AAE7C,MAAI,UAAU;AACZ,+BAA2B,UAAU,QAAQ;AAC7C;AAAA,EACF;AAEA,UAAQ,iBAAiB,SAAS,wBAAwB;AACxD,QAAI,CAAC,kCAAkC,MAAM,QAAQ,GAAG;AACtD;AAAA,IACF;AAEA,UAAM,YAAY,0BAA0B,IAAI;AAChD,QAAI,WAAW;AACb,eAAS,SAAS;AAAA,IACpB;AAAA,EACF,CAAC;AACH;"}
1
+ {"version":3,"file":"compatibility.js","sources":["../../src/decorators/compatibility.ts"],"sourcesContent":["type DecoratorMetadataStore = Record<PropertyKey, unknown>;\n\nconst PENDING_FIELD_DECORATORS_KEY = Symbol.for(\n '@happyvertical/smrt-core/pending-field-decorators',\n);\nconst standardDecoratorRegistrations = new WeakMap<\n Function,\n WeakSet<(className: string) => void>\n>();\n\ntype PendingDecoratorRegistration = {\n register: (className: string) => void;\n};\n\nexport type LegacyPropertyDecoratorTarget = {\n constructor?: Function & {\n name?: string;\n };\n};\n\nexport type CompatiblePropertyDecoratorContext<This, Value> =\n | string\n | symbol\n | ClassFieldDecoratorContext<This, Value>;\n\nexport interface CompatiblePropertyDecorator<This = unknown, Value = unknown> {\n (target: object, propertyKey: string | symbol): void;\n (value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;\n}\n\nfunction getDecoratorConstructor(target: unknown): Function | undefined {\n if (typeof target === 'function') {\n return target;\n }\n\n if (target && typeof target === 'object') {\n return (target as LegacyPropertyDecoratorTarget).constructor;\n }\n\n return undefined;\n}\n\nfunction markStandardDecoratorRegistration(\n target: unknown,\n register: (className: string) => void,\n): boolean {\n const ctor = getDecoratorConstructor(target);\n if (!ctor) {\n return false;\n }\n\n const registeredCallbacks =\n standardDecoratorRegistrations.get(ctor) ?? new WeakSet();\n if (registeredCallbacks.has(register)) {\n return false;\n }\n\n registeredCallbacks.add(register);\n standardDecoratorRegistrations.set(ctor, registeredCallbacks);\n return true;\n}\n\nfunction getDecoratorMetadata(\n contextOrMetadata:\n | ClassFieldDecoratorContext<unknown, unknown>\n | ClassDecoratorContext\n | DecoratorMetadataStore\n | undefined,\n): DecoratorMetadataStore | undefined {\n if (!contextOrMetadata || typeof contextOrMetadata !== 'object') {\n return undefined;\n }\n\n if ('metadata' in contextOrMetadata) {\n const { metadata } = contextOrMetadata as {\n metadata?: DecoratorMetadataStore;\n };\n return metadata && typeof metadata === 'object' ? metadata : undefined;\n }\n\n return contextOrMetadata;\n}\n\nfunction getClassDecoratorMetadata(\n target: Function,\n decoratorContext?: ClassDecoratorContext,\n): DecoratorMetadataStore | undefined {\n const metadataFromContext = getDecoratorMetadata(decoratorContext);\n if (metadataFromContext) {\n return metadataFromContext;\n }\n\n const metadataSymbol = (Symbol as typeof Symbol & { metadata?: symbol })\n .metadata;\n if (!metadataSymbol) {\n return undefined;\n }\n\n const metadata = (target as unknown as Record<PropertyKey, unknown>)[\n metadataSymbol\n ];\n return metadata && typeof metadata === 'object'\n ? (metadata as DecoratorMetadataStore)\n : undefined;\n}\n\nfunction queuePendingFieldDecorator(\n metadata: DecoratorMetadataStore,\n register: (className: string) => void,\n): void {\n const pendingDecorators =\n (metadata[PENDING_FIELD_DECORATORS_KEY] as\n | PendingDecoratorRegistration[]\n | undefined) ?? [];\n\n pendingDecorators.push({ register });\n metadata[PENDING_FIELD_DECORATORS_KEY] = pendingDecorators;\n}\n\nexport function resolveDecoratorClassName(target: unknown): string | undefined {\n if (typeof target === 'function') {\n return target.name;\n }\n\n if (target && typeof target === 'object') {\n return (target as LegacyPropertyDecoratorTarget).constructor?.name;\n }\n\n return undefined;\n}\n\nexport function applyPendingDecoratorRegistrations(\n target: Function,\n decoratorContext?: ClassDecoratorContext,\n): void {\n const metadata = getClassDecoratorMetadata(target, decoratorContext);\n if (!metadata) {\n return;\n }\n\n const pendingDecorators = metadata[PENDING_FIELD_DECORATORS_KEY] as\n | PendingDecoratorRegistration[]\n | undefined;\n if (!pendingDecorators || pendingDecorators.length === 0) {\n return;\n }\n\n for (const { register } of pendingDecorators) {\n if (!markStandardDecoratorRegistration(target, register)) {\n continue;\n }\n\n register(target.name);\n }\n\n Reflect.deleteProperty(metadata, PENDING_FIELD_DECORATORS_KEY);\n}\n\nexport function registerCompatibleFieldDecorator<This, Value>(\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<This, Value>,\n registerFieldDecorator: (className: string, propertyKey: string) => void,\n): void {\n if (\n typeof propertyKeyOrContext === 'string' ||\n typeof propertyKeyOrContext === 'symbol'\n ) {\n const className = resolveDecoratorClassName(targetOrValue);\n if (className) {\n registerFieldDecorator(className, String(propertyKeyOrContext));\n }\n return;\n }\n\n const context = propertyKeyOrContext;\n const propertyKey = String(context.name);\n const register = (className: string) =>\n registerFieldDecorator(className, propertyKey);\n const metadata = getDecoratorMetadata(context);\n\n if (metadata) {\n queuePendingFieldDecorator(metadata, register);\n return;\n }\n\n context.addInitializer?.(function registerSmrtDecorator() {\n if (!markStandardDecoratorRegistration(this, register)) {\n return;\n }\n\n const className = resolveDecoratorClassName(this);\n if (className) {\n register(className);\n }\n });\n}\n"],"names":[],"mappings":"AAEA,MAAM,+BAA+B,uBAAO;AAAA,EAC1C;AACF;AACA,MAAM,qDAAqC,QAAA;AAyB3C,SAAS,wBAAwB,QAAuC;AACtE,MAAI,OAAO,WAAW,YAAY;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,OAAO,WAAW,UAAU;AACxC,WAAQ,OAAyC;AAAA,EACnD;AAEA,SAAO;AACT;AAEA,SAAS,kCACP,QACA,UACS;AACT,QAAM,OAAO,wBAAwB,MAAM;AAC3C,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,sBACJ,+BAA+B,IAAI,IAAI,yBAAS,QAAA;AAClD,MAAI,oBAAoB,IAAI,QAAQ,GAAG;AACrC,WAAO;AAAA,EACT;AAEA,sBAAoB,IAAI,QAAQ;AAChC,iCAA+B,IAAI,MAAM,mBAAmB;AAC5D,SAAO;AACT;AAEA,SAAS,qBACP,mBAKoC;AACpC,MAAI,CAAC,qBAAqB,OAAO,sBAAsB,UAAU;AAC/D,WAAO;AAAA,EACT;AAEA,MAAI,cAAc,mBAAmB;AACnC,UAAM,EAAE,aAAa;AAGrB,WAAO,YAAY,OAAO,aAAa,WAAW,WAAW;AAAA,EAC/D;AAEA,SAAO;AACT;AAEA,SAAS,0BACP,QACA,kBACoC;AACpC,QAAM,sBAAsB,qBAAqB,gBAAgB;AACjE,MAAI,qBAAqB;AACvB,WAAO;AAAA,EACT;AAEA,QAAM,iBAAkB,OACrB;AACH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F;AAEA,UAAQ,iBAAiB,SAAS,wBAAwB;AACxD,QAAI,CAAC,kCAAkC,MAAM,QAAQ,GAAG;AACtD;AAAA,IACF;AAEA,UAAM,YAAY,0BAA0B,IAAI;AAChD,QAAI,WAAW;AACb,eAAS,SAAS;AAAA,IACpB;AAAA,EACF,CAAC;AACH;"}
@@ -36,7 +36,7 @@ export interface FieldOptions {
36
36
  /** Whether the field is required */
37
37
  required?: boolean;
38
38
  /** Default value for the field */
39
- default?: any;
39
+ default?: unknown;
40
40
  /** Whether the field is unique */
41
41
  unique?: boolean;
42
42
  /**
@@ -214,7 +214,7 @@ export declare function field(options?: FieldOptions | NumericFieldOptions | Tex
214
214
  * @see {@link oneToMany} for the inverse (parent) side of the relationship
215
215
  * @see SmrtObject.loadRelated for lazy-loading the related object at runtime
216
216
  */
217
- export declare function foreignKey(relatedClass: string | Function | any, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
217
+ export declare function foreignKey(relatedClass: string | Function, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
218
218
  /**
219
219
  * Declares a cross-package foreign key reference.
220
220
  *
@@ -315,7 +315,7 @@ export declare function crossPackageRef(qualifiedName: string, options?: CrossPa
315
315
  * @see {@link foreignKey} for the many-to-one (child) side of the relationship
316
316
  * @see SmrtObject.loadRelatedMany for lazy-loading at runtime
317
317
  */
318
- export declare function oneToMany(relatedClass: string | Function | any, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
318
+ export declare function oneToMany(relatedClass: string | Function, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
319
319
  /**
320
320
  * Declares a many-to-many relationship between two `SmrtObject` classes via a join table.
321
321
  *
@@ -342,7 +342,7 @@ export declare function oneToMany(relatedClass: string | Function | any, options
342
342
  *
343
343
  * @see {@link oneToMany} for one-to-many relationships
344
344
  */
345
- export declare function manyToMany(relatedClass: string | Function | any, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
345
+ export declare function manyToMany(relatedClass: string | Function, options?: Omit<RelationshipFieldOptions, 'related'>): CompatiblePropertyDecorator;
346
346
  /**
347
347
  * Marks a field as a Single Table Inheritance (STI) meta field.
348
348
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,KAAK,2BAA2B,EAIjC,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,SAAS,GACT,SAAS,GACT,SAAS,GACT,UAAU,GACV,MAAM,CAAC;AAEX,MAAM,MAAM,SAAS,GACjB,kBAAkB,GAClB,MAAM,GACN,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,YAAY,CAAC;AAEjB,MAAM,WAAW,YAAY;IAC3B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kCAAkC;IAClC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC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OAAO,GAAE,IAAI,CAAC,wBAAwB,EAAE,SAAS,CAAM,GAqBjD,2BAA2B,CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,YAAiB,GAevC,2BAA2B,CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/decorators/index.ts"],"sourcesContent":["/**\n * Field decorators for SMRT objects\n *\n * Modern decorator-based API for defining SMRT object properties.\n * Properties are typed as primitives with decorator metadata.\n */\n\nimport { ObjectRegistry } from '../registry.js';\nimport type { SQLDataType } from '../schema/types.js';\nimport {\n type CompatiblePropertyDecorator,\n type CompatiblePropertyDecoratorContext,\n type LegacyPropertyDecoratorTarget,\n registerCompatibleFieldDecorator,\n} from './compatibility.js';\n\n/**\n * Meta type wrapper for STI (Single Table Inheritance) meta fields\n *\n * Fields typed as Meta<T> are stored in the _meta_data JSONB column\n * rather than as direct table columns. Used for child-specific fields\n * in STI hierarchies.\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti' })\n * class Event extends SmrtObject {\n * title: string = '';\n * }\n *\n * @smrt()\n * class Meeting extends Event {\n * // Stored in _meta_data JSONB column\n * roomNumber: Meta<string> = '';\n * attendees: Meta<string[]> = [];\n * }\n * ```\n */\nexport type Meta<T> = T;\n\n/**\n * Base field options\n */\nexport type PrimitiveFieldType =\n | 'text'\n | 'integer'\n | 'decimal'\n | 'boolean'\n | 'datetime'\n | 'json';\n\nexport type FieldType =\n | PrimitiveFieldType\n | 'meta'\n | 'foreignKey'\n | 'crossPackageRef'\n | 'oneToMany'\n | 'manyToMany';\n\nexport interface FieldOptions {\n /** Explicit field type for runtime-only registration paths */\n type?: FieldType;\n /** Explicit SQL storage type when runtime and persistence contracts differ */\n sqlType?: SQLDataType;\n /** Whether the field is required */\n required?: boolean;\n /** Default value for the field */\n default?: any;\n /** Whether the field is unique */\n unique?: boolean;\n /**\n * When `true`, the schema emits a database index targeting this field.\n *\n * For regular (column-backed) fields the index is a plain column index.\n * For `@meta()` fields stored inside `_meta_data` JSONB, the index targets\n * the JSON path — `json_extract(_meta_data, '$.fieldName')` on SQLite,\n * `(_meta_data->>'fieldName')` on Postgres — giving WHERE clauses on that\n * meta key the same performance as a real column.\n */\n indexed?: boolean;\n /** Whether the field is nullable */\n nullable?: boolean;\n /** Whether the field should be excluded from database */\n transient?: boolean;\n /**\n * Marks the field as sensitive (e.g. API secrets, credentials, tax IDs).\n *\n * Sensitive fields are still persisted to the database, but the framework:\n * - excludes them from `toPublicJSON()` (the serializer used by generated\n * REST/MCP/SvelteKit routes), so they never appear in API responses; and\n * - rejects them as `where`-clause filter keys, closing the\n * `?secret[like]=...` value-probing oracle.\n *\n * Use this for any column that holds a secret value that must never be\n * read back over a generated network surface.\n */\n sensitive?: boolean;\n /**\n * Marks the field as read-only over generated write surfaces.\n *\n * Read-only fields are stripped from the request body before\n * `create`/`update` in generated REST/MCP/SvelteKit routes, so callers\n * cannot mass-assign them. Server-side code can still set them directly.\n */\n readonly?: boolean;\n /** Field description */\n description?: string;\n /**\n * Controls whether the field is included in JSON exports.\n * - `true`: Always exported (unless site explicitly excludes it)\n * - `false`: Never exported (cannot be overridden by site config)\n * - `undefined`: Uses site's fieldExportDefault setting\n */\n exported?: boolean;\n}\n\n/**\n * Options for text fields\n */\nexport interface TextFieldOptions extends FieldOptions {\n /** Minimum length for text fields */\n minLength?: number;\n /** Maximum length for text fields */\n maxLength?: number;\n /** Regex pattern for validation */\n pattern?: RegExp | string;\n}\n\n/**\n * Options for numeric fields\n */\nexport interface NumericFieldOptions extends FieldOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n}\n\n/**\n * Options for relationship fields\n */\nexport interface RelationshipFieldOptions extends FieldOptions {\n /** Related class name */\n related?: string;\n /** Foreign key field name */\n foreignKey?: string;\n /** Through table for many-to-many */\n through?: string;\n /** Relationship type */\n type?: 'foreignKey' | 'crossPackageRef' | 'oneToMany' | 'manyToMany';\n}\n\n/**\n * Options specific to cross-package references.\n */\nexport interface CrossPackageRefOptions\n extends Omit<RelationshipFieldOptions, 'related' | 'type'> {\n /**\n * Storage type for the referenced target id. Defaults to 'uuid'.\n *\n * Use 'text' only when the external target model declares\n * `@smrt({ idType: 'text' })`.\n */\n idType?: 'uuid' | 'text';\n\n /**\n * When `true`, the framework verifies the referenced object exists at save time.\n * Validation uses the target package's manifest (loaded on demand via\n * `ObjectRegistry.ensureManifestLoaded()`), so this requires the target manifest\n * to be discoverable at runtime.\n *\n * Empty/null values are always allowed (treated as \"no reference set\").\n *\n * Defaults to `false` — same behavior as a plain string field today.\n */\n validate?: boolean;\n}\n\n/**\n * Marks a class property with validation constraints and metadata options.\n *\n * Use `@field()` when you need options beyond what plain TypeScript initializers\n * express — required validation, numeric ranges, string length limits, uniqueness,\n * or transient (non-persisted) computed properties.\n *\n * For plain persisted fields with no constraints, no decorator is needed: just\n * declare the property with a TypeScript initializer and the framework will infer\n * the column type from the default value (`0` → INTEGER, `0.0` → DECIMAL, `''` → TEXT).\n *\n * @param options - Field configuration options\n * @param options.required - If `true`, `save()` throws `ValidationError` when empty/null\n * @param options.unique - Enforces a UNIQUE database constraint\n * @param options.nullable - If `true`, the column accepts NULL (default depends on type)\n * @param options.transient - If `true`, the property is not persisted to the database\n * @param options.default - Default value applied at the database level\n * @param options.description - Human-readable description used in generated API docs\n * @param options.exported - Controls JSON export visibility (see `FieldOptions`)\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Product extends SmrtObject {\n * @field({ required: true, maxLength: 100 })\n * name: string = '';\n *\n * @field({ min: 0 })\n * stock: number = 0;\n *\n * @field({ transient: true })\n * get displayPrice(): string { return `$${this.price.toFixed(2)}`; }\n * }\n * ```\n *\n * @see {@link meta} for STI child-specific fields stored in `_meta_data` JSON\n * @see {@link foreignKey} for typed relationship fields\n */\nexport function field(\n options: FieldOptions | NumericFieldOptions | TextFieldOptions = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, options);\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a many-to-one (foreign key) relationship to another `SmrtObject` class.\n *\n * The decorated property stores the UUID of the related object. At runtime, call\n * `instance.loadRelated('fieldName')` to lazy-load (and cache) the related object,\n * or pass `include: ['fieldName']` to `collection.list()` for batch eager loading.\n *\n * Cross-package rule: Use `@foreignKey()` only for same-package references.\n * For cross-package foreign keys, use a plain `string` property instead to avoid\n * circular dependencies between packages.\n *\n * @param relatedClass - The target class constructor (or class name string)\n * @param options - Optional field constraints (required, nullable, etc.)\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Order extends SmrtObject {\n * // Same-package FK — enables loadRelated() and eager loading\n * @foreignKey(Customer)\n * customerId: string = '';\n * }\n *\n * // Cross-package: use a plain string instead\n * @smrt()\n * class Post extends SmrtObject {\n * authorId: string = ''; // plain string — no circular dep\n * }\n * ```\n *\n * @see {@link oneToMany} for the inverse (parent) side of the relationship\n * @see SmrtObject.loadRelated for lazy-loading the related object at runtime\n */\nexport function foreignKey(\n relatedClass: string | Function | any,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'foreignKey',\n related: relatedClassName,\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a cross-package foreign key reference.\n *\n * Use this for relationships that point to a `SmrtObject` in a *different* package\n * (e.g. `Customer.profileId` pointing at `@happyvertical/smrt-profiles:Profile`).\n * Unlike `@foreignKey()`, this decorator does **not** emit a DDL `FOREIGN KEY`\n * constraint — cross-package classes are not visible at schema-generation time and\n * adding a constraint would force a circular package dependency. The decorated\n * property remains a plain `TEXT` column at the database level.\n *\n * What you get over a plain string field:\n * - The relationship is registered with the `ObjectRegistry`, so `loadRelated()`\n * and `Collection.list({ include })` can resolve it once the target package's\n * manifest is loaded.\n * - Optional save-time validation (`validate: true`) confirms the referenced\n * object exists, catching typos and stale IDs before they hit the database.\n *\n * The `qualifiedName` is a fully-qualified class identifier in the form\n * `@package/scope:ClassName` — for example `@happyvertical/smrt-profiles:Profile`.\n *\n * @param qualifiedName - Qualified name of the target class\n * @param options - Optional field constraints and `validate` flag\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Customer extends SmrtObject {\n * @crossPackageRef('@happyvertical/smrt-profiles:Profile')\n * profileId: string = '';\n *\n * // With save-time validation\n * @crossPackageRef('@happyvertical/smrt-profiles:Profile', { validate: true })\n * primaryContactId: string = '';\n * }\n * ```\n *\n * @see {@link foreignKey} for same-package relationships (emits FK constraint)\n * @see SmrtObject.loadRelated for runtime resolution\n */\nexport function crossPackageRef(\n qualifiedName: string,\n options: CrossPackageRefOptions = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'crossPackageRef',\n related: qualifiedName,\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a one-to-many relationship from this object to a collection of related objects.\n *\n * The decorated property is `transient` — it is not persisted as a database column.\n * At runtime, call `instance.loadRelatedMany('fieldName')` to load the related objects,\n * or pass `include: ['fieldName']` to `collection.list()` for batch eager loading (issues\n * a single batched query for all instances instead of N individual queries).\n *\n * The inverse side (`@foreignKey`) must exist on the `relatedClass` pointing back to this\n * class. The framework discovers it automatically via `ObjectRegistry.getInverseRelationships()`.\n *\n * **Generated accessor (R10):** registering the class installs a consistent\n * `get<FieldName>()` instance method (e.g. `items` → `order.getItems()`) that\n * delegates to `loadRelatedMany('items')`. Generation is additive — a\n * hand-rolled method of the same name is never overwritten.\n *\n * **Disambiguation:** when `relatedClass` declares more than one `@foreignKey`\n * back to this class, pass `{ foreignKey: '<inverseFieldName>' }` so both\n * `loadRelatedMany` and the generated accessor resolve the intended inverse\n * side. Without it the first matching foreign key is used.\n *\n * @param relatedClass - The class constructor of the child/related objects\n * @param options - Optional relationship options. `foreignKey` selects the\n * inverse foreign-key field on `relatedClass` when it has more than one.\n * @returns A TypeScript property decorator (sets `transient: true` automatically)\n *\n * @example\n * ```typescript\n * @smrt()\n * class Order extends SmrtObject {\n * @oneToMany(OrderItem)\n * items: OrderItem[] = [];\n * }\n *\n * @smrt()\n * class OrderItem extends SmrtObject {\n * @foreignKey(Order)\n * orderId: string = '';\n * }\n *\n * const order = await orders.get({ id });\n * const items = await order.getItems(); // generated; === loadRelatedMany('items')\n * ```\n *\n * @example\n * ```typescript\n * // Multiple inverse foreign keys → disambiguate explicitly.\n * @smrt()\n * class Profile extends SmrtObject {\n * @oneToMany(ProfileRelationship, { foreignKey: 'fromProfileId' })\n * relationshipsFrom: ProfileRelationship[] = [];\n * @oneToMany(ProfileRelationship, { foreignKey: 'toProfileId' })\n * relationshipsTo: ProfileRelationship[] = [];\n * }\n * ```\n *\n * @see {@link foreignKey} for the many-to-one (child) side of the relationship\n * @see SmrtObject.loadRelatedMany for lazy-loading at runtime\n */\nexport function oneToMany(\n relatedClass: string | Function | any,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'oneToMany',\n related: relatedClassName,\n transient: true, // Relationship fields are not database columns\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a many-to-many relationship between two `SmrtObject` classes via a join table.\n *\n * The decorated property is `transient` — it is not persisted as a database column.\n * The `through` option specifies the junction table name. The join table model must\n * be decorated with `@smrt({ conflictColumns: ['...', '...'] })` to use the natural\n * key columns for upsert operations.\n *\n * Runtime loading: call `instance.loadRelatedMany('field')` to lazy-load, or\n * pass `include: ['field']` to `collection.list()` for batched eager loading.\n *\n * @param relatedClass - The class constructor of the related objects\n * @param options - Relationship options; `through` specifies the junction table name\n * @returns A TypeScript property decorator (sets `transient: true` automatically)\n *\n * @example\n * ```typescript\n * @smrt()\n * class Product extends SmrtObject {\n * @manyToMany(Tag, { through: 'product_tags' })\n * tags: Tag[] = [];\n * }\n * ```\n *\n * @see {@link oneToMany} for one-to-many relationships\n */\nexport function manyToMany(\n relatedClass: string | Function | any,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'manyToMany',\n related: relatedClassName,\n transient: true, // Relationship fields are not database columns\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Marks a field as a Single Table Inheritance (STI) meta field.\n *\n * Meta fields are stored in the `_meta_data` JSONB column on the shared STI\n * table rather than as dedicated table columns. Use this decorator for fields\n * that are specific to an STI child class and should not pollute the shared\n * table schema with child-specific columns.\n *\n * The `@smrt({ tableStrategy: 'sti' })` decorator must be set on the base class.\n * All child-specific fields should use `@meta()` (or the `Meta<T>` type alias).\n *\n * @param options - Standard field options (required, nullable, description, etc.)\n * @returns A TypeScript property decorator (registers field with `type: 'meta'`)\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti' })\n * class Event extends SmrtObject {\n * title: string = ''; // shared column on events table\n * }\n *\n * @smrt()\n * class Meeting extends Event {\n * @meta()\n * roomNumber: string = ''; // stored in _meta_data JSON, not a column\n *\n * @meta({ required: true })\n * durationMinutes: number = 60;\n * }\n * ```\n *\n * @see {@link Meta} for the equivalent type alias approach\n * @see {@link field} for regular (non-STI) field declarations\n */\nexport function meta(options: FieldOptions = {}) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<any, any>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'meta', // Mark this field as a meta field for STI\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n"],"names":[],"mappings":";;AAyNO,SAAS,MACd,UAAiE,IACjE;AACA,UAAQ,CACN,eACA,yBACG;AACH;AAAA,MACE;AAAA,MACA;AAAA,MACA,CAAC,WAAW,gBAAgB;AAC1B,uBAAe,uBAAuB,WAAW,aAAa,OAAO;AAAA,MACvE;AAAA,IAAA;AAAA,EAEJ;AACF;AAoCO,SAAS,WACd,cACA,UAAqD,IACrD;AACA,UAAQ,CACN,eACA,yBACG;AACH,UAAM,mBACJ,OAAO,iBAAiB,WAAW,eAAe,aAAa;AAEjE;AAAA,MACE;AAAA,MACA;AAAA,MACA,CAAC,WAAW,gBAAgB;AAC1B,uBAAe,uBAAu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AAa;AAAA,UAC5D,GAAG;AAAA,UACH,MAAM;AAAA;AAAA,QAAA,CACP;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/decorators/index.ts"],"sourcesContent":["/**\n * Field decorators for SMRT objects\n *\n * Modern decorator-based API for defining SMRT object properties.\n * Properties are typed as primitives with decorator metadata.\n */\n\nimport { ObjectRegistry } from '../registry.js';\nimport type { SQLDataType } from '../schema/types.js';\nimport {\n type CompatiblePropertyDecorator,\n type CompatiblePropertyDecoratorContext,\n type LegacyPropertyDecoratorTarget,\n registerCompatibleFieldDecorator,\n} from './compatibility.js';\n\n/**\n * Meta type wrapper for STI (Single Table Inheritance) meta fields\n *\n * Fields typed as Meta<T> are stored in the _meta_data JSONB column\n * rather than as direct table columns. Used for child-specific fields\n * in STI hierarchies.\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti' })\n * class Event extends SmrtObject {\n * title: string = '';\n * }\n *\n * @smrt()\n * class Meeting extends Event {\n * // Stored in _meta_data JSONB column\n * roomNumber: Meta<string> = '';\n * attendees: Meta<string[]> = [];\n * }\n * ```\n */\nexport type Meta<T> = T;\n\n/**\n * Base field options\n */\nexport type PrimitiveFieldType =\n | 'text'\n | 'integer'\n | 'decimal'\n | 'boolean'\n | 'datetime'\n | 'json';\n\nexport type FieldType =\n | PrimitiveFieldType\n | 'meta'\n | 'foreignKey'\n | 'crossPackageRef'\n | 'oneToMany'\n | 'manyToMany';\n\nexport interface FieldOptions {\n /** Explicit field type for runtime-only registration paths */\n type?: FieldType;\n /** Explicit SQL storage type when runtime and persistence contracts differ */\n sqlType?: SQLDataType;\n /** Whether the field is required */\n required?: boolean;\n /** Default value for the field */\n default?: unknown;\n /** Whether the field is unique */\n unique?: boolean;\n /**\n * When `true`, the schema emits a database index targeting this field.\n *\n * For regular (column-backed) fields the index is a plain column index.\n * For `@meta()` fields stored inside `_meta_data` JSONB, the index targets\n * the JSON path — `json_extract(_meta_data, '$.fieldName')` on SQLite,\n * `(_meta_data->>'fieldName')` on Postgres — giving WHERE clauses on that\n * meta key the same performance as a real column.\n */\n indexed?: boolean;\n /** Whether the field is nullable */\n nullable?: boolean;\n /** Whether the field should be excluded from database */\n transient?: boolean;\n /**\n * Marks the field as sensitive (e.g. API secrets, credentials, tax IDs).\n *\n * Sensitive fields are still persisted to the database, but the framework:\n * - excludes them from `toPublicJSON()` (the serializer used by generated\n * REST/MCP/SvelteKit routes), so they never appear in API responses; and\n * - rejects them as `where`-clause filter keys, closing the\n * `?secret[like]=...` value-probing oracle.\n *\n * Use this for any column that holds a secret value that must never be\n * read back over a generated network surface.\n */\n sensitive?: boolean;\n /**\n * Marks the field as read-only over generated write surfaces.\n *\n * Read-only fields are stripped from the request body before\n * `create`/`update` in generated REST/MCP/SvelteKit routes, so callers\n * cannot mass-assign them. Server-side code can still set them directly.\n */\n readonly?: boolean;\n /** Field description */\n description?: string;\n /**\n * Controls whether the field is included in JSON exports.\n * - `true`: Always exported (unless site explicitly excludes it)\n * - `false`: Never exported (cannot be overridden by site config)\n * - `undefined`: Uses site's fieldExportDefault setting\n */\n exported?: boolean;\n}\n\n/**\n * Options for text fields\n */\nexport interface TextFieldOptions extends FieldOptions {\n /** Minimum length for text fields */\n minLength?: number;\n /** Maximum length for text fields */\n maxLength?: number;\n /** Regex pattern for validation */\n pattern?: RegExp | string;\n}\n\n/**\n * Options for numeric fields\n */\nexport interface NumericFieldOptions extends FieldOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n}\n\n/**\n * Options for relationship fields\n */\nexport interface RelationshipFieldOptions extends FieldOptions {\n /** Related class name */\n related?: string;\n /** Foreign key field name */\n foreignKey?: string;\n /** Through table for many-to-many */\n through?: string;\n /** Relationship type */\n type?: 'foreignKey' | 'crossPackageRef' | 'oneToMany' | 'manyToMany';\n}\n\n/**\n * Options specific to cross-package references.\n */\nexport interface CrossPackageRefOptions\n extends Omit<RelationshipFieldOptions, 'related' | 'type'> {\n /**\n * Storage type for the referenced target id. Defaults to 'uuid'.\n *\n * Use 'text' only when the external target model declares\n * `@smrt({ idType: 'text' })`.\n */\n idType?: 'uuid' | 'text';\n\n /**\n * When `true`, the framework verifies the referenced object exists at save time.\n * Validation uses the target package's manifest (loaded on demand via\n * `ObjectRegistry.ensureManifestLoaded()`), so this requires the target manifest\n * to be discoverable at runtime.\n *\n * Empty/null values are always allowed (treated as \"no reference set\").\n *\n * Defaults to `false` — same behavior as a plain string field today.\n */\n validate?: boolean;\n}\n\n/**\n * Marks a class property with validation constraints and metadata options.\n *\n * Use `@field()` when you need options beyond what plain TypeScript initializers\n * express — required validation, numeric ranges, string length limits, uniqueness,\n * or transient (non-persisted) computed properties.\n *\n * For plain persisted fields with no constraints, no decorator is needed: just\n * declare the property with a TypeScript initializer and the framework will infer\n * the column type from the default value (`0` → INTEGER, `0.0` → DECIMAL, `''` → TEXT).\n *\n * @param options - Field configuration options\n * @param options.required - If `true`, `save()` throws `ValidationError` when empty/null\n * @param options.unique - Enforces a UNIQUE database constraint\n * @param options.nullable - If `true`, the column accepts NULL (default depends on type)\n * @param options.transient - If `true`, the property is not persisted to the database\n * @param options.default - Default value applied at the database level\n * @param options.description - Human-readable description used in generated API docs\n * @param options.exported - Controls JSON export visibility (see `FieldOptions`)\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Product extends SmrtObject {\n * @field({ required: true, maxLength: 100 })\n * name: string = '';\n *\n * @field({ min: 0 })\n * stock: number = 0;\n *\n * @field({ transient: true })\n * get displayPrice(): string { return `$${this.price.toFixed(2)}`; }\n * }\n * ```\n *\n * @see {@link meta} for STI child-specific fields stored in `_meta_data` JSON\n * @see {@link foreignKey} for typed relationship fields\n */\nexport function field(\n options: FieldOptions | NumericFieldOptions | TextFieldOptions = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, options);\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a many-to-one (foreign key) relationship to another `SmrtObject` class.\n *\n * The decorated property stores the UUID of the related object. At runtime, call\n * `instance.loadRelated('fieldName')` to lazy-load (and cache) the related object,\n * or pass `include: ['fieldName']` to `collection.list()` for batch eager loading.\n *\n * Cross-package rule: Use `@foreignKey()` only for same-package references.\n * For cross-package foreign keys, use a plain `string` property instead to avoid\n * circular dependencies between packages.\n *\n * @param relatedClass - The target class constructor (or class name string)\n * @param options - Optional field constraints (required, nullable, etc.)\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Order extends SmrtObject {\n * // Same-package FK — enables loadRelated() and eager loading\n * @foreignKey(Customer)\n * customerId: string = '';\n * }\n *\n * // Cross-package: use a plain string instead\n * @smrt()\n * class Post extends SmrtObject {\n * authorId: string = ''; // plain string — no circular dep\n * }\n * ```\n *\n * @see {@link oneToMany} for the inverse (parent) side of the relationship\n * @see SmrtObject.loadRelated for lazy-loading the related object at runtime\n */\nexport function foreignKey(\n relatedClass: string | Function,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'foreignKey',\n related: relatedClassName,\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a cross-package foreign key reference.\n *\n * Use this for relationships that point to a `SmrtObject` in a *different* package\n * (e.g. `Customer.profileId` pointing at `@happyvertical/smrt-profiles:Profile`).\n * Unlike `@foreignKey()`, this decorator does **not** emit a DDL `FOREIGN KEY`\n * constraint — cross-package classes are not visible at schema-generation time and\n * adding a constraint would force a circular package dependency. The decorated\n * property remains a plain `TEXT` column at the database level.\n *\n * What you get over a plain string field:\n * - The relationship is registered with the `ObjectRegistry`, so `loadRelated()`\n * and `Collection.list({ include })` can resolve it once the target package's\n * manifest is loaded.\n * - Optional save-time validation (`validate: true`) confirms the referenced\n * object exists, catching typos and stale IDs before they hit the database.\n *\n * The `qualifiedName` is a fully-qualified class identifier in the form\n * `@package/scope:ClassName` — for example `@happyvertical/smrt-profiles:Profile`.\n *\n * @param qualifiedName - Qualified name of the target class\n * @param options - Optional field constraints and `validate` flag\n * @returns A TypeScript property decorator\n *\n * @example\n * ```typescript\n * @smrt()\n * class Customer extends SmrtObject {\n * @crossPackageRef('@happyvertical/smrt-profiles:Profile')\n * profileId: string = '';\n *\n * // With save-time validation\n * @crossPackageRef('@happyvertical/smrt-profiles:Profile', { validate: true })\n * primaryContactId: string = '';\n * }\n * ```\n *\n * @see {@link foreignKey} for same-package relationships (emits FK constraint)\n * @see SmrtObject.loadRelated for runtime resolution\n */\nexport function crossPackageRef(\n qualifiedName: string,\n options: CrossPackageRefOptions = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'crossPackageRef',\n related: qualifiedName,\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a one-to-many relationship from this object to a collection of related objects.\n *\n * The decorated property is `transient` — it is not persisted as a database column.\n * At runtime, call `instance.loadRelatedMany('fieldName')` to load the related objects,\n * or pass `include: ['fieldName']` to `collection.list()` for batch eager loading (issues\n * a single batched query for all instances instead of N individual queries).\n *\n * The inverse side (`@foreignKey`) must exist on the `relatedClass` pointing back to this\n * class. The framework discovers it automatically via `ObjectRegistry.getInverseRelationships()`.\n *\n * **Generated accessor (R10):** registering the class installs a consistent\n * `get<FieldName>()` instance method (e.g. `items` → `order.getItems()`) that\n * delegates to `loadRelatedMany('items')`. Generation is additive — a\n * hand-rolled method of the same name is never overwritten.\n *\n * **Disambiguation:** when `relatedClass` declares more than one `@foreignKey`\n * back to this class, pass `{ foreignKey: '<inverseFieldName>' }` so both\n * `loadRelatedMany` and the generated accessor resolve the intended inverse\n * side. Without it the first matching foreign key is used.\n *\n * @param relatedClass - The class constructor of the child/related objects\n * @param options - Optional relationship options. `foreignKey` selects the\n * inverse foreign-key field on `relatedClass` when it has more than one.\n * @returns A TypeScript property decorator (sets `transient: true` automatically)\n *\n * @example\n * ```typescript\n * @smrt()\n * class Order extends SmrtObject {\n * @oneToMany(OrderItem)\n * items: OrderItem[] = [];\n * }\n *\n * @smrt()\n * class OrderItem extends SmrtObject {\n * @foreignKey(Order)\n * orderId: string = '';\n * }\n *\n * const order = await orders.get({ id });\n * const items = await order.getItems(); // generated; === loadRelatedMany('items')\n * ```\n *\n * @example\n * ```typescript\n * // Multiple inverse foreign keys → disambiguate explicitly.\n * @smrt()\n * class Profile extends SmrtObject {\n * @oneToMany(ProfileRelationship, { foreignKey: 'fromProfileId' })\n * relationshipsFrom: ProfileRelationship[] = [];\n * @oneToMany(ProfileRelationship, { foreignKey: 'toProfileId' })\n * relationshipsTo: ProfileRelationship[] = [];\n * }\n * ```\n *\n * @see {@link foreignKey} for the many-to-one (child) side of the relationship\n * @see SmrtObject.loadRelatedMany for lazy-loading at runtime\n */\nexport function oneToMany(\n relatedClass: string | Function,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'oneToMany',\n related: relatedClassName,\n transient: true, // Relationship fields are not database columns\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Declares a many-to-many relationship between two `SmrtObject` classes via a join table.\n *\n * The decorated property is `transient` — it is not persisted as a database column.\n * The `through` option specifies the junction table name. The join table model must\n * be decorated with `@smrt({ conflictColumns: ['...', '...'] })` to use the natural\n * key columns for upsert operations.\n *\n * Runtime loading: call `instance.loadRelatedMany('field')` to lazy-load, or\n * pass `include: ['field']` to `collection.list()` for batched eager loading.\n *\n * @param relatedClass - The class constructor of the related objects\n * @param options - Relationship options; `through` specifies the junction table name\n * @returns A TypeScript property decorator (sets `transient: true` automatically)\n *\n * @example\n * ```typescript\n * @smrt()\n * class Product extends SmrtObject {\n * @manyToMany(Tag, { through: 'product_tags' })\n * tags: Tag[] = [];\n * }\n * ```\n *\n * @see {@link oneToMany} for one-to-many relationships\n */\nexport function manyToMany(\n relatedClass: string | Function,\n options: Omit<RelationshipFieldOptions, 'related'> = {},\n) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n const relatedClassName =\n typeof relatedClass === 'string' ? relatedClass : relatedClass.name;\n\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'manyToMany',\n related: relatedClassName,\n transient: true, // Relationship fields are not database columns\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n\n/**\n * Marks a field as a Single Table Inheritance (STI) meta field.\n *\n * Meta fields are stored in the `_meta_data` JSONB column on the shared STI\n * table rather than as dedicated table columns. Use this decorator for fields\n * that are specific to an STI child class and should not pollute the shared\n * table schema with child-specific columns.\n *\n * The `@smrt({ tableStrategy: 'sti' })` decorator must be set on the base class.\n * All child-specific fields should use `@meta()` (or the `Meta<T>` type alias).\n *\n * @param options - Standard field options (required, nullable, description, etc.)\n * @returns A TypeScript property decorator (registers field with `type: 'meta'`)\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti' })\n * class Event extends SmrtObject {\n * title: string = ''; // shared column on events table\n * }\n *\n * @smrt()\n * class Meeting extends Event {\n * @meta()\n * roomNumber: string = ''; // stored in _meta_data JSON, not a column\n *\n * @meta({ required: true })\n * durationMinutes: number = 60;\n * }\n * ```\n *\n * @see {@link Meta} for the equivalent type alias approach\n * @see {@link field} for regular (non-STI) field declarations\n */\nexport function meta(options: FieldOptions = {}) {\n return ((\n targetOrValue: LegacyPropertyDecoratorTarget | undefined,\n propertyKeyOrContext: CompatiblePropertyDecoratorContext<unknown, unknown>,\n ) => {\n registerCompatibleFieldDecorator(\n targetOrValue,\n propertyKeyOrContext,\n (className, propertyKey) => {\n ObjectRegistry.registerFieldDecorator(className, propertyKey, {\n ...options,\n type: 'meta', // Mark this field as a meta field for STI\n });\n },\n );\n }) as CompatiblePropertyDecorator;\n}\n"],"names":[],"mappings":";;AAyNO,SAAS,MACd,UAAiE,IACjE;AACA,UAAQ,CACN,eACA,yBACG;AACH;AAAA,MACE;AAAA,MACA;AAAA,MACA,CAAC,WAAW,gBAAgB;AAC1B,uBAAe,uBAAuB,WAAW,aAAa,OAAO;AAAA,MACvE;AAAA,IAAA;AAAA,EAEJ;AACF;AAoCO,SAAS,WACd,cACA,UAAqD,IACrD;AACA,UAAQ,CACN,eACA,yBACG;AACH,UAAM,mBACJ,OAAO,iBAAiB,WAAW,eAAe,aAAa;AAEjE;AAAA,MACE;AAAA,MACA;AAAA,MACA,CAAC,WAAW,gBAAgB;AAC1B,uBAAe,uBAAuB,WAAW,aAAa;AAAA,UAC5D,GAAG;AAAA,UACH,MAAM;AAAA,UACN,SAAS;AAAA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Root":"","sources":["../src/hierarchical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAKtC;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,gBAAgB;IACvD,SAAS,EAAE,CAAC,EAAE,CAAC;IACf,OAAO,EAAE,CAAC,CAAC;IACX,WAAW,EAAE,CAAC,EAAE,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,UAAU;IAC9C;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAG,IAAI,CAAU;IAEpD,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;cACa,oBAAoB,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAgCrE;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAOvC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IASpC;;;;;;;OAOG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAmBrC;;;;;;;;;;;;;;OAcG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAgCvC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAQlD;;;;;;;;;OASG;IACG,MAAM,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CA0B7D"}
@@ -1 +1 @@
1
- {"version":3,"file":"hierarchical.js","sources":["../src/hierarchical.ts"],"sourcesContent":["/**\n * SmrtHierarchical — base class for self-referencing tree hierarchies.\n *\n * Provides batched parent/children/ancestors/descendants/hierarchy traversal\n * and a cycle-safe `moveTo`. Replaces five copies of the same logic across\n * Place, Event, Tag, Account, and Zone.\n *\n * Examples in the monorepo:\n *\n * | Subclass | Domain |\n * |----------|------------------------------------------------|\n * | Place | hierarchical geographic places |\n * | Event | nestable event hierarchy (game → period → …) |\n * | Tag | tag taxonomies and category trees |\n * | Account | chart of accounts |\n * | Zone | placement zones inside a digital property |\n *\n * Convention: every subclass uses `parentId: string | null` referencing\n * another row in the same table (or STI base table) by UUID. Classes whose\n * self-reference has different semantics — e.g. `Fact.previousFactId` (an\n * evolution chain) or `Asset.sourceAssetId` (a derivation DAG) — should\n * NOT extend SmrtHierarchical. Use descriptive names and class-specific\n * methods instead.\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti', api: true })\n * export class Place extends SmrtHierarchical {\n * name = '';\n * }\n *\n * const ancestors = await place.getAncestors();\n * const descendants = await place.getDescendants(); // BFS, one query per level\n * await place.moveTo(newParent); // cycle-checked\n * ```\n */\n\nimport type { SmrtCollection } from './collection';\nimport { SmrtObject } from './object';\nimport { ObjectRegistry } from './registry';\nimport { chunkArray, IN_LIST_CHUNK_SIZE } from './utils/chunk';\n\n/**\n * Aggregate hierarchy view: ancestors (root-first), self, and all descendants\n * (BFS order). Generic on the concrete subclass so `getHierarchy()` preserves\n * the caller's type — `place.getHierarchy()` yields `HierarchyView<Place>`.\n */\nexport interface HierarchyView<T extends SmrtHierarchical> {\n ancestors: T[];\n current: T;\n descendants: T[];\n}\n\nexport class SmrtHierarchical extends SmrtObject {\n /**\n * Internal marker so the scanner can recognize this framework abstract base\n * even when consumers haven't built its package. Mirrors\n * `SmrtJunction._isJunctionBase`. Don't rename without also updating the\n * scanner's `FRAMEWORK_BASE_CLASSES` set in\n * `packages/scanner/src/inheritance-resolver.ts`.\n */\n static readonly _isHierarchicalBase = true as const;\n\n /** Self-referencing parent. `null` means top-level (no parent). */\n parentId: string | null = null;\n\n /**\n * Resolve the collection used to load siblings/ancestors/descendants.\n *\n * Goes through `ObjectRegistry.getCollection` so subclasses don't have to\n * hard-code a dynamic import of their own collection module. Also acts as\n * the abstract-base guard — `new SmrtHierarchical()` followed by any\n * traversal method throws a clear error rather than producing garbage.\n *\n * For STI subclasses, queries are issued against the STI base collection\n * so the table/discriminator are correct.\n *\n * Lookup uses the constructor's qualified name when available — set by\n * the registry on every registered class as `_smrtQualifiedName` (R5-\n * canon prep). Then `ObjectRegistry.getSTIBase(...)` returns the\n * qualified name of the STI base directly (R5-canon main), so the\n * `getCollection` lookup never collapses to a simple-name ambiguity\n * even when two packages ship a hierarchical class with the same\n * simple name. Falls back through `getClassByConstructor` → simple\n * `this.constructor.name` when the static / WeakMap aren't populated\n * (rare; `getCollection` then surfaces the existing \"not found in\n * ObjectRegistry\" error).\n *\n * The constructor prototype-chain walk that lived here from PR #1269\n * is gone — the registry now returns qualified names directly so the\n * walk became dead code.\n */\n protected async _hierarchyCollection(): Promise<SmrtCollection<this>> {\n if (this.constructor === SmrtHierarchical) {\n throw new Error(\n 'SmrtHierarchical is abstract — extend it from a concrete @smrt() class before calling hierarchy methods.',\n );\n }\n\n // Identity priority:\n // 1. The constructor's `_smrtQualifiedName` static (set at\n // registration, survives HMR / federated-module duplication).\n // 2. The registry's WeakMap (`getClassByConstructor`) — same value\n // as the static when both are populated, but the WeakMap is\n // where simple-name fallback lives.\n // 3. The simple constructor name as a last-ditch fallback.\n const ctor = this.constructor as typeof SmrtHierarchical & {\n _smrtQualifiedName?: string;\n };\n const tagged = ctor._smrtQualifiedName;\n const registered = tagged\n ? undefined\n : ObjectRegistry.getClassByConstructor(ctor as any);\n const className =\n tagged ?? registered?.qualifiedName ?? registered?.name ?? ctor.name;\n\n const stiBase = ObjectRegistry.getSTIBase(className);\n const collectionClass = stiBase ?? className;\n return await ObjectRegistry.getCollection<this>(\n collectionClass,\n this.options,\n );\n }\n\n /**\n * The parent row, or `null` when this row is top-level.\n *\n * Single query. Returns the hydrated row (STI dispatch applies, so an\n * Article-extends-Document subclass comes back as `Article`).\n */\n async getParent(): Promise<this | null> {\n if (!this.parentId) return null;\n const collection = await this._hierarchyCollection();\n const parent = await collection.get({ id: this.parentId });\n return parent as this | null;\n }\n\n /**\n * Immediate children. Single query: `WHERE parent_id = this.id`.\n */\n async getChildren(): Promise<this[]> {\n if (!this.id) return [];\n const collection = await this._hierarchyCollection();\n const children = await collection.list({\n where: { parentId: this.id },\n });\n return children as this[];\n }\n\n /**\n * All ancestors, root-first (immediate parent last). Does not include self.\n *\n * Intrinsically O(depth) queries — each step needs the previous level's\n * `parentId` before it can fetch the next. Includes cycle protection: if\n * a row's ancestor chain loops back on itself (data corruption), the walk\n * stops cleanly instead of looping forever.\n */\n async getAncestors(): Promise<this[]> {\n const ancestors: this[] = [];\n const visited = new Set<string>();\n if (this.id) visited.add(this.id);\n let current: this = this;\n\n while (current.parentId) {\n if (visited.has(current.parentId)) break;\n visited.add(current.parentId);\n\n const parent = (await current.getParent()) as this | null;\n if (!parent) break;\n ancestors.unshift(parent);\n current = parent;\n }\n\n return ancestors;\n }\n\n /**\n * All descendants in BFS order. One query per level of depth using `IN`\n * on the previous level's IDs — eliminates the recursive-per-child N+1\n * pattern the duplicated implementations used.\n *\n * Each level's frontier is chunked at `IN_LIST_CHUNK_SIZE` before being\n * expanded into a `parent_id IN (?, ?, …)` clause: the generic\n * `collection.list()` does NOT chunk array-valued WHERE clauses, so a level\n * wider than the backend's `SQLITE_MAX_VARIABLE_NUMBER` (999 on legacy\n * SQLite, 32766 on modern builds) would otherwise throw before traversal\n * completes. Mirrors the chunking the relationship/junction loaders in\n * `collection.ts` already do.\n *\n * Cycle-safe via a visited Set keyed on row id.\n */\n async getDescendants(): Promise<this[]> {\n if (!this.id) return [];\n const collection = await this._hierarchyCollection();\n const descendants: this[] = [];\n const visited = new Set<string>([this.id]);\n let frontier: string[] = [this.id];\n\n while (frontier.length > 0) {\n const next: string[] = [];\n\n // Chunk the frontier so each query stays under the bind-variable cap.\n // Children are merged into the same BFS level in chunk order, so the\n // overall ordering remains breadth-first.\n for (const idChunk of chunkArray(frontier, IN_LIST_CHUNK_SIZE)) {\n const children = (await collection.list({\n where: { parentId: idChunk },\n })) as this[];\n\n for (const child of children) {\n if (!child.id || visited.has(child.id)) continue;\n visited.add(child.id);\n descendants.push(child);\n next.push(child.id);\n }\n }\n\n frontier = next;\n }\n\n return descendants;\n }\n\n /**\n * Full hierarchy view: ancestors, self, descendants. Issued concurrently.\n */\n async getHierarchy(): Promise<HierarchyView<this>> {\n const [ancestors, descendants] = await Promise.all([\n this.getAncestors(),\n this.getDescendants(),\n ]);\n return { ancestors, current: this, descendants };\n }\n\n /**\n * Reparent this row. Pass `null` to make it a root, an id string, or the\n * target row itself. Refuses to:\n *\n * - move a row to itself (self-loop)\n * - move a row under one of its own descendants (would create a cycle)\n *\n * Persists via `save()`. Caller is responsible for any out-of-band\n * denormalization (e.g. depth caches on subclasses like Tag.level).\n */\n async moveTo(newParent: this | string | null): Promise<void> {\n const newParentId =\n newParent === null\n ? null\n : typeof newParent === 'string'\n ? newParent\n : (newParent.id ?? null);\n\n if (newParentId !== null && newParentId === this.id) {\n throw new Error(\n `Cannot move ${this.constructor.name} ${this.id} to itself.`,\n );\n }\n\n if (newParentId !== null) {\n const descendants = await this.getDescendants();\n if (descendants.some((d) => d.id === newParentId)) {\n throw new Error(\n `Cannot move ${this.constructor.name} ${this.id} under one of its own descendants (${newParentId}) — would create a cycle.`,\n );\n }\n }\n\n this.parentId = newParentId;\n await this.save();\n }\n}\n"],"names":[],"mappings":";;;AAqDO,MAAM,yBAAyB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/C,OAAgB,sBAAsB;AAAA;AAAA,EAGtC,WAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,MAAM;AAEzB,QAAI,gBAAgB,QAAQ,gBAAgB,KAAK,IAAI;AACnD,YAAM,IAAI;AAAA,QACR,eAAe,KAAK,YAAY,IAAI,IAAI,KAAK,EAAE;AAAA,MAAA;AAAA,IAEnD;AAEA,QAAI,gBAAgB,MAAM;AACxB,YAAM,cAAc,MAAM,KAAK,eAAA;AAC/B,UAAI,YAAY,KAAK,CAAC,MAAM,EAAE,OAAO,WAAW,GAAG;AACjD,cAAM,IAAI;AAAA,UACR,eAAe,KAAK,YAAY,IAAI,IAAI,KAAK,EAAE,sCAAsC,WAAW;AAAA,QAAA;AAAA,MAEpG;AAAA,IACF;AAEA,SAAK,WAAW;AAChB,UAAM,KAAK,KAAA;AAAA,EACb;AACF;"}
1
+ {"version":3,"file":"hierarchical.js","sources":["../src/hierarchical.ts"],"sourcesContent":["/**\n * SmrtHierarchical — base class for self-referencing tree hierarchies.\n *\n * Provides batched parent/children/ancestors/descendants/hierarchy traversal\n * and a cycle-safe `moveTo`. Replaces five copies of the same logic across\n * Place, Event, Tag, Account, and Zone.\n *\n * Examples in the monorepo:\n *\n * | Subclass | Domain |\n * |----------|------------------------------------------------|\n * | Place | hierarchical geographic places |\n * | Event | nestable event hierarchy (game → period → …) |\n * | Tag | tag taxonomies and category trees |\n * | Account | chart of accounts |\n * | Zone | placement zones inside a digital property |\n *\n * Convention: every subclass uses `parentId: string | null` referencing\n * another row in the same table (or STI base table) by UUID. Classes whose\n * self-reference has different semantics — e.g. `Fact.previousFactId` (an\n * evolution chain) or `Asset.sourceAssetId` (a derivation DAG) — should\n * NOT extend SmrtHierarchical. Use descriptive names and class-specific\n * methods instead.\n *\n * @example\n * ```typescript\n * @smrt({ tableStrategy: 'sti', api: true })\n * export class Place extends SmrtHierarchical {\n * name = '';\n * }\n *\n * const ancestors = await place.getAncestors();\n * const descendants = await place.getDescendants(); // BFS, one query per level\n * await place.moveTo(newParent); // cycle-checked\n * ```\n */\n\nimport type { SmrtCollection } from './collection';\nimport { SmrtObject } from './object';\nimport { ObjectRegistry } from './registry';\nimport type { SmrtObjectConstructor } from './registry/types';\nimport { chunkArray, IN_LIST_CHUNK_SIZE } from './utils/chunk';\n\n/**\n * Aggregate hierarchy view: ancestors (root-first), self, and all descendants\n * (BFS order). Generic on the concrete subclass so `getHierarchy()` preserves\n * the caller's type — `place.getHierarchy()` yields `HierarchyView<Place>`.\n */\nexport interface HierarchyView<T extends SmrtHierarchical> {\n ancestors: T[];\n current: T;\n descendants: T[];\n}\n\nexport class SmrtHierarchical extends SmrtObject {\n /**\n * Internal marker so the scanner can recognize this framework abstract base\n * even when consumers haven't built its package. Mirrors\n * `SmrtJunction._isJunctionBase`. Don't rename without also updating the\n * scanner's `FRAMEWORK_BASE_CLASSES` set in\n * `packages/scanner/src/inheritance-resolver.ts`.\n */\n static readonly _isHierarchicalBase = true as const;\n\n /** Self-referencing parent. `null` means top-level (no parent). */\n parentId: string | null = null;\n\n /**\n * Resolve the collection used to load siblings/ancestors/descendants.\n *\n * Goes through `ObjectRegistry.getCollection` so subclasses don't have to\n * hard-code a dynamic import of their own collection module. Also acts as\n * the abstract-base guard — `new SmrtHierarchical()` followed by any\n * traversal method throws a clear error rather than producing garbage.\n *\n * For STI subclasses, queries are issued against the STI base collection\n * so the table/discriminator are correct.\n *\n * Lookup uses the constructor's qualified name when available — set by\n * the registry on every registered class as `_smrtQualifiedName` (R5-\n * canon prep). Then `ObjectRegistry.getSTIBase(...)` returns the\n * qualified name of the STI base directly (R5-canon main), so the\n * `getCollection` lookup never collapses to a simple-name ambiguity\n * even when two packages ship a hierarchical class with the same\n * simple name. Falls back through `getClassByConstructor` → simple\n * `this.constructor.name` when the static / WeakMap aren't populated\n * (rare; `getCollection` then surfaces the existing \"not found in\n * ObjectRegistry\" error).\n *\n * The constructor prototype-chain walk that lived here from PR #1269\n * is gone — the registry now returns qualified names directly so the\n * walk became dead code.\n */\n protected async _hierarchyCollection(): Promise<SmrtCollection<this>> {\n if (this.constructor === SmrtHierarchical) {\n throw new Error(\n 'SmrtHierarchical is abstract — extend it from a concrete @smrt() class before calling hierarchy methods.',\n );\n }\n\n // Identity priority:\n // 1. The constructor's `_smrtQualifiedName` static (set at\n // registration, survives HMR / federated-module duplication).\n // 2. The registry's WeakMap (`getClassByConstructor`) — same value\n // as the static when both are populated, but the WeakMap is\n // where simple-name fallback lives.\n // 3. The simple constructor name as a last-ditch fallback.\n const ctor = this.constructor as typeof SmrtHierarchical & {\n _smrtQualifiedName?: string;\n };\n const tagged = ctor._smrtQualifiedName;\n const registered = tagged\n ? undefined\n : ObjectRegistry.getClassByConstructor(ctor as SmrtObjectConstructor);\n const className =\n tagged ?? registered?.qualifiedName ?? registered?.name ?? ctor.name;\n\n const stiBase = ObjectRegistry.getSTIBase(className);\n const collectionClass = stiBase ?? className;\n return await ObjectRegistry.getCollection<this>(\n collectionClass,\n this.options,\n );\n }\n\n /**\n * The parent row, or `null` when this row is top-level.\n *\n * Single query. Returns the hydrated row (STI dispatch applies, so an\n * Article-extends-Document subclass comes back as `Article`).\n */\n async getParent(): Promise<this | null> {\n if (!this.parentId) return null;\n const collection = await this._hierarchyCollection();\n const parent = await collection.get({ id: this.parentId });\n return parent as this | null;\n }\n\n /**\n * Immediate children. Single query: `WHERE parent_id = this.id`.\n */\n async getChildren(): Promise<this[]> {\n if (!this.id) return [];\n const collection = await this._hierarchyCollection();\n const children = await collection.list({\n where: { parentId: this.id },\n });\n return children as this[];\n }\n\n /**\n * All ancestors, root-first (immediate parent last). Does not include self.\n *\n * Intrinsically O(depth) queries — each step needs the previous level's\n * `parentId` before it can fetch the next. Includes cycle protection: if\n * a row's ancestor chain loops back on itself (data corruption), the walk\n * stops cleanly instead of looping forever.\n */\n async getAncestors(): Promise<this[]> {\n const ancestors: this[] = [];\n const visited = new Set<string>();\n if (this.id) visited.add(this.id);\n let current: this = this;\n\n while (current.parentId) {\n if (visited.has(current.parentId)) break;\n visited.add(current.parentId);\n\n const parent = (await current.getParent()) as this | null;\n if (!parent) break;\n ancestors.unshift(parent);\n current = parent;\n }\n\n return ancestors;\n }\n\n /**\n * All descendants in BFS order. One query per level of depth using `IN`\n * on the previous level's IDs — eliminates the recursive-per-child N+1\n * pattern the duplicated implementations used.\n *\n * Each level's frontier is chunked at `IN_LIST_CHUNK_SIZE` before being\n * expanded into a `parent_id IN (?, ?, …)` clause: the generic\n * `collection.list()` does NOT chunk array-valued WHERE clauses, so a level\n * wider than the backend's `SQLITE_MAX_VARIABLE_NUMBER` (999 on legacy\n * SQLite, 32766 on modern builds) would otherwise throw before traversal\n * completes. Mirrors the chunking the relationship/junction loaders in\n * `collection.ts` already do.\n *\n * Cycle-safe via a visited Set keyed on row id.\n */\n async getDescendants(): Promise<this[]> {\n if (!this.id) return [];\n const collection = await this._hierarchyCollection();\n const descendants: this[] = [];\n const visited = new Set<string>([this.id]);\n let frontier: string[] = [this.id];\n\n while (frontier.length > 0) {\n const next: string[] = [];\n\n // Chunk the frontier so each query stays under the bind-variable cap.\n // Children are merged into the same BFS level in chunk order, so the\n // overall ordering remains breadth-first.\n for (const idChunk of chunkArray(frontier, IN_LIST_CHUNK_SIZE)) {\n const children = (await collection.list({\n where: { parentId: idChunk },\n })) as this[];\n\n for (const child of children) {\n if (!child.id || visited.has(child.id)) continue;\n visited.add(child.id);\n descendants.push(child);\n next.push(child.id);\n }\n }\n\n frontier = next;\n }\n\n return descendants;\n }\n\n /**\n * Full hierarchy view: ancestors, self, descendants. Issued concurrently.\n */\n async getHierarchy(): Promise<HierarchyView<this>> {\n const [ancestors, descendants] = await Promise.all([\n this.getAncestors(),\n this.getDescendants(),\n ]);\n return { ancestors, current: this, descendants };\n }\n\n /**\n * Reparent this row. Pass `null` to make it a root, an id string, or the\n * target row itself. Refuses to:\n *\n * - move a row to itself (self-loop)\n * - move a row under one of its own descendants (would create a cycle)\n *\n * Persists via `save()`. Caller is responsible for any out-of-band\n * denormalization (e.g. depth caches on subclasses like Tag.level).\n */\n async moveTo(newParent: this | string | null): Promise<void> {\n const newParentId =\n newParent === null\n ? null\n : typeof newParent === 'string'\n ? newParent\n : (newParent.id ?? null);\n\n if (newParentId !== null && newParentId === this.id) {\n throw new Error(\n `Cannot move ${this.constructor.name} ${this.id} to itself.`,\n );\n }\n\n if (newParentId !== null) {\n const descendants = await this.getDescendants();\n if (descendants.some((d) => d.id === newParentId)) {\n throw new Error(\n `Cannot move ${this.constructor.name} ${this.id} under one of its own descendants (${newParentId}) — would create a cycle.`,\n );\n }\n }\n\n this.parentId = newParentId;\n await this.save();\n }\n}\n"],"names":[],"mappings":";;;AAsDO,MAAM,yBAAyB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/C,OAAgB,sBAAsB;AAAA;AAAA,EAGtC,WAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4B1B,MAAgB,uBAAsD;AACpE,QAAI,KAAK,gBAAgB,kBAAkB;AACzC,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AASA,UAAM,OAAO,KAAK;AAGlB,UAAM,SAAS,KAAK;AACpB,UAAM,aAAa,SACf,SACA,eAAe,sBAAsB,IAA6B;AACtE,UAAM,YACJ,UAAU,YAAY,iBAAiB,YAAY,QAAQ,KAAK;AAElE,UAAM,UAAU,eAAe,WAAW,SAAS;AACnD,UAAM,kBAAkB,WAAW;AACnC,WAAO,MAAM,eAAe;AAAA,MAC1B;AAAA,MACA,KAAK;AAAA,IAAA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YAAkC;AACtC,QAAI,CAAC,KAAK,SAAU,QAAO;AAC3B,UAAM,aAAa,MAAM,KAAK,qBAAA;AAC9B,UAAM,SAAS,MAAM,WAAW,IAAI,EAAE,IAAI,KAAK,UAA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MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,qBAA0B,GAC/B,OAAO,CAAC,KAAK,CAAC;IAWjB;;;;OAIG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,qBAA0B,GAC/B,OAAO,CAAC,IAAI,CAAC;IAahB;;;;;;;;;;OAUG;IACG,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,GAAE,qBAA0B,GAC/B,OAAO,CAAC,IAAI,CAAC;CAwBjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"junction.js","sources":["../src/junction.ts"],"sourcesContent":["/**\n * SmrtJunction — base class for two-sided junction (many-to-many) collections.\n *\n * A junction collection manages rows that link a \"left\" entity to a \"right\" entity,\n * typically with discriminator fields (relationship/role) and an optional sortOrder.\n * Examples in the monorepo:\n *\n * | Subclass | Left field | Right field | Discriminator |\n * |--------------------------------|---------------|-------------|-----------------|\n * | ContentAssetCollection | contentId | assetId | relationship |\n * | PerformerOwnedAssetCollection | performerId | assetId | role |\n * | PlaceAssetCollection | placeId | assetId | relationship |\n * | EventParticipantCollection | eventId | profileId | role |\n * | FactContentCollection | factId | contentId | relationship |\n *\n * Each subclass declares `leftField` / `rightField` (camelCase) and optionally\n * overrides `sortField` (defaults to `'sortOrder'`; set `null` to disable ORDER BY).\n *\n * Polymorphic subclasses (where \"left\" or \"right\" is a composite key like\n * `metaType + metaId`) may override `byLeft` / `byRight` / `attach` / `detach`\n * with diverging signatures — see `AssetAssociationCollection` for a reference.\n *\n * @typeParam TItem - The junction row class (extends `SmrtObject`)\n */\n\nimport { SmrtCollection } from './collection';\nimport type { SmrtObject } from './object';\n\n/**\n * Options passed to `attach` / `setLinks` — written into the created junction row.\n *\n * Common keys: `relationship`, `role`, `sortOrder`, `tenantId`.\n * Subclass-specific keys (e.g. `placement`, `groupId` on EventParticipant) pass through.\n * Keys must match actual camelCase column names on the junction model; unknown\n * keys are rejected by `SmrtCollection.create`'s WHERE/field validation.\n */\nexport type JunctionAttachOptions = Record<string, unknown>;\n\n/**\n * Options passed to `byLeft` / `byRight` / `detach` — additional WHERE filters\n * narrowing the operation. Keys must match camelCase column names.\n */\nexport type JunctionFilterOptions = Record<string, unknown>;\n\nfunction camelToSnake(name: string): string {\n return name.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);\n}\n\nexport abstract class SmrtJunction<\n TItem extends SmrtObject,\n> extends SmrtCollection<TItem> {\n /**\n * Internal marker used by `SmrtCollection.create` to detect that this\n * subclass is a junction and apply a registration-presence guard. Static\n * property is inherited by all subclasses via the constructor chain.\n * Don't rename or remove without also updating the guard.\n */\n static readonly _isJunctionBase = true as const;\n\n /** Field name (camelCase) holding the \"left\" foreign key, e.g. `'contentId'`. */\n protected abstract leftField: string;\n\n /** Field name (camelCase) holding the \"right\" foreign key, e.g. `'assetId'`. */\n protected abstract rightField: string;\n\n /**\n * Field name (camelCase) used to ORDER BY when calling `byLeft` / `byRight`.\n * Defaults to `'sortOrder'`. Set to `null` to omit ORDER BY entirely.\n *\n * Independent from `positionField` — `sortField` is a *query* concern\n * (how rows are ordered when read), while `positionField` is a *write*\n * concern (what column `setLinks` auto-assigns to). Tables that order\n * by a non-position field (e.g. `'createdAt'`) should set `sortField`\n * accordingly and leave `positionField` set to `null` or its dedicated\n * position column name.\n */\n protected sortField: string | null = 'sortOrder';\n\n /**\n * Field name (camelCase) that `setLinks` auto-assigns the array index\n * to when the caller doesn't supply a value. Defaults to `'sortOrder'`.\n * Set to `null` for tables without a dedicated position column (e.g.\n * pure-key junctions, or tables ordered by timestamps).\n *\n * Writing the array index into a non-position field — like `createdAt`\n * or `placement` — would corrupt data. Subclasses without a numeric\n * position column MUST set this to `null`.\n */\n protected positionField: string | null = 'sortOrder';\n\n /**\n * Return junction rows where the left FK matches `leftId`, narrowed by\n * optional additional WHERE filters. Ordered ASC by `sortField` if set.\n */\n async byLeft(\n leftId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<TItem[]> {\n return (await this.list({\n // Spread opts FIRST so the fixed key always wins — prevents a\n // caller-supplied `{ [leftField]: otherId }` from retargeting the\n // query when opts is forwarded from untrusted input.\n where: { ...opts, [this.leftField]: leftId },\n ...(this.sortField\n ? { orderBy: `${camelToSnake(this.sortField)} ASC` }\n : {}),\n })) as TItem[];\n }\n\n /**\n * Return junction rows where the right FK matches `rightId`, narrowed by\n * optional additional WHERE filters. Ordered ASC by `sortField` if set.\n */\n async byRight(\n rightId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<TItem[]> {\n return (await this.list({\n where: { ...opts, [this.rightField]: rightId },\n ...(this.sortField\n ? { orderBy: `${camelToSnake(this.sortField)} ASC` }\n : {}),\n })) as TItem[];\n }\n\n /**\n * Create a new junction row linking `leftId` ↔ `rightId`.\n *\n * Goes through `SmrtCollection.create` which performs an upsert keyed on\n * the model's `@smrt({ conflictColumns })`. Duplicates on the conflict key\n * resolve to an UPDATE that rewrites every column — including the row's\n * `id` and any timestamp columns — to the new instance's values. For most\n * junctions that's fine: callers identify rows by (left, right, discriminator),\n * not by junction-row-id, so id rewrites are invisible.\n *\n * If your junction table is externally addressable by id (e.g. its rows\n * are exposed under `/api/v1/<table>/[id]`), override this method with a\n * find-or-create check to preserve id stability across duplicate calls.\n * See `ContentReferences.attach` for an example.\n *\n * @param opts - Extra fields to write into the row (e.g. `{ relationship, sortOrder, tenantId }`)\n */\n async attach(\n leftId: string,\n rightId: string,\n opts: JunctionAttachOptions = {},\n ): Promise<TItem> {\n return (await this.create({\n // Spread opts FIRST so the fixed key fields always win — prevents\n // a caller-supplied `{ [leftField]: otherId }` from retargeting\n // the write when opts is forwarded from untrusted input.\n ...opts,\n [this.leftField]: leftId,\n [this.rightField]: rightId,\n } as any)) as TItem;\n }\n\n /**\n * Delete all junction rows matching `leftId` + `rightId` (+ optional filter `opts`).\n *\n * @param opts - Additional WHERE filters (e.g. `{ relationship: 'thumbnail' }`)\n */\n async detach(\n leftId: string,\n rightId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<void> {\n const links = (await this.list({\n where: {\n ...opts,\n [this.leftField]: leftId,\n [this.rightField]: rightId,\n },\n })) as TItem[];\n for (const link of links) {\n await (link as unknown as { delete(): Promise<void> }).delete();\n }\n }\n\n /**\n * Replace the full set of right-side rows for a `leftId`, scoped by `opts`.\n *\n * Behavior:\n * 1. Snapshots and deletes existing rows matching `{ leftField: leftId, ...opts }`.\n * 2. Creates a new row for each `rightId`, spreading `opts` into the row data.\n * 3. If `positionField` is set and `opts` doesn't specify it, assigns the array index.\n *\n * Not transactional — partial failure leaves the table in a mixed state.\n * For atomic replaces, wrap the call in your own DB transaction.\n */\n async setLinks(\n leftId: string,\n rightIds: string[],\n opts: JunctionAttachOptions = {},\n ): Promise<void> {\n // Strip the right-side key from snapshot opts — leaving it in would\n // narrow the delete to one specific right id, but `setLinks` is\n // contractually \"replace the full set of right rows for leftId\n // within the opts scope\". A rightField filter contradicts that.\n const snapshotOpts: JunctionAttachOptions = { ...opts };\n delete snapshotOpts[this.rightField];\n\n const existing = (await this.list({\n where: { ...snapshotOpts, [this.leftField]: leftId },\n })) as TItem[];\n for (const link of existing) {\n await (link as unknown as { delete(): Promise<void> }).delete();\n }\n\n const positionKey = this.positionField;\n for (let i = 0; i < rightIds.length; i++) {\n const rowOpts: JunctionAttachOptions = { ...opts };\n if (positionKey && rowOpts[positionKey] === undefined) {\n rowOpts[positionKey] = i;\n }\n await this.attach(leftId, rightIds[i], rowOpts);\n }\n }\n}\n"],"names":[],"mappings":";AA4CA,SAAS,aAAa,MAAsB;AAC1C,SAAO,KAAK,QAAQ,UAAU,CAAC,MAAM,IAAI,EAAE,YAAA,CAAa,EAAE;AAC5D;AAEO,MAAe,qBAEZ,eAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9B,OAAgB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AG;AAAA,MAAA;AAAA,IACrB,CACD;AACD,eAAW,QAAQ,OAAO;AACxB,YAAO,KAAgD,OAAA;AAAA,IACzD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,SACJ,QACA,UACA,OAA8B,CAAA,GACf;AAKf,UAAM,eAAsC,EAAE,GAAG,KAAA;AACjD,WAAO,aAAa,KAAK,UAAU;AAEnC,UAAM,WAAY,MAAM,KAAK,KAAK;AAAA,MAChC,OAAO,EAAE,GAAG,cAAc,CAAC,KAAK,SAAS,GAAG,OAAA;AAAA,IAAO,CACpD;AACD,eAAW,QAAQ,UAAU;AAC3B,YAAO,KAAgD,OAAA;AAAA,IACzD;AAEA,UAAM,cAAc,KAAK;AACzB,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,YAAM,UAAiC,EAAE,GAAG,KAAA;AAC5C,UAAI,eAAe,QAAQ,WAAW,MAAM,QAAW;AACrD,gBAAQ,WAAW,IAAI;AAAA,MACzB;AACA,YAAM,KAAK,OAAO,QAAQ,SAAS,CAAC,GAAG,OAAO;AAAA,IAChD;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"junction.js","sources":["../src/junction.ts"],"sourcesContent":["/**\n * SmrtJunction — base class for two-sided junction (many-to-many) collections.\n *\n * A junction collection manages rows that link a \"left\" entity to a \"right\" entity,\n * typically with discriminator fields (relationship/role) and an optional sortOrder.\n * Examples in the monorepo:\n *\n * | Subclass | Left field | Right field | Discriminator |\n * |--------------------------------|---------------|-------------|-----------------|\n * | ContentAssetCollection | contentId | assetId | relationship |\n * | PerformerOwnedAssetCollection | performerId | assetId | role |\n * | PlaceAssetCollection | placeId | assetId | relationship |\n * | EventParticipantCollection | eventId | profileId | role |\n * | FactContentCollection | factId | contentId | relationship |\n *\n * Each subclass declares `leftField` / `rightField` (camelCase) and optionally\n * overrides `sortField` (defaults to `'sortOrder'`; set `null` to disable ORDER BY).\n *\n * Polymorphic subclasses (where \"left\" or \"right\" is a composite key like\n * `metaType + metaId`) may override `byLeft` / `byRight` / `attach` / `detach`\n * with diverging signatures — see `AssetAssociationCollection` for a reference.\n *\n * @typeParam TItem - The junction row class (extends `SmrtObject`)\n */\n\nimport { SmrtCollection, type SmrtCreateInput } from './collection';\nimport type { SmrtObject } from './object';\n\n/**\n * Options passed to `attach` / `setLinks` — written into the created junction row.\n *\n * Common keys: `relationship`, `role`, `sortOrder`, `tenantId`.\n * Subclass-specific keys (e.g. `placement`, `groupId` on EventParticipant) pass through.\n * Keys must match actual camelCase column names on the junction model; unknown\n * keys are rejected by `SmrtCollection.create`'s WHERE/field validation.\n */\nexport type JunctionAttachOptions = Record<string, unknown>;\n\n/**\n * Options passed to `byLeft` / `byRight` / `detach` — additional WHERE filters\n * narrowing the operation. Keys must match camelCase column names.\n */\nexport type JunctionFilterOptions = Record<string, unknown>;\n\nfunction camelToSnake(name: string): string {\n return name.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);\n}\n\nexport abstract class SmrtJunction<\n TItem extends SmrtObject,\n> extends SmrtCollection<TItem> {\n /**\n * Internal marker used by `SmrtCollection.create` to detect that this\n * subclass is a junction and apply a registration-presence guard. Static\n * property is inherited by all subclasses via the constructor chain.\n * Don't rename or remove without also updating the guard.\n */\n static readonly _isJunctionBase = true as const;\n\n /** Field name (camelCase) holding the \"left\" foreign key, e.g. `'contentId'`. */\n protected abstract leftField: string;\n\n /** Field name (camelCase) holding the \"right\" foreign key, e.g. `'assetId'`. */\n protected abstract rightField: string;\n\n /**\n * Field name (camelCase) used to ORDER BY when calling `byLeft` / `byRight`.\n * Defaults to `'sortOrder'`. Set to `null` to omit ORDER BY entirely.\n *\n * Independent from `positionField` — `sortField` is a *query* concern\n * (how rows are ordered when read), while `positionField` is a *write*\n * concern (what column `setLinks` auto-assigns to). Tables that order\n * by a non-position field (e.g. `'createdAt'`) should set `sortField`\n * accordingly and leave `positionField` set to `null` or its dedicated\n * position column name.\n */\n protected sortField: string | null = 'sortOrder';\n\n /**\n * Field name (camelCase) that `setLinks` auto-assigns the array index\n * to when the caller doesn't supply a value. Defaults to `'sortOrder'`.\n * Set to `null` for tables without a dedicated position column (e.g.\n * pure-key junctions, or tables ordered by timestamps).\n *\n * Writing the array index into a non-position field — like `createdAt`\n * or `placement` — would corrupt data. Subclasses without a numeric\n * position column MUST set this to `null`.\n */\n protected positionField: string | null = 'sortOrder';\n\n /**\n * Return junction rows where the left FK matches `leftId`, narrowed by\n * optional additional WHERE filters. Ordered ASC by `sortField` if set.\n */\n async byLeft(\n leftId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<TItem[]> {\n return (await this.list({\n // Spread opts FIRST so the fixed key always wins — prevents a\n // caller-supplied `{ [leftField]: otherId }` from retargeting the\n // query when opts is forwarded from untrusted input.\n where: { ...opts, [this.leftField]: leftId },\n ...(this.sortField\n ? { orderBy: `${camelToSnake(this.sortField)} ASC` }\n : {}),\n })) as TItem[];\n }\n\n /**\n * Return junction rows where the right FK matches `rightId`, narrowed by\n * optional additional WHERE filters. Ordered ASC by `sortField` if set.\n */\n async byRight(\n rightId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<TItem[]> {\n return (await this.list({\n where: { ...opts, [this.rightField]: rightId },\n ...(this.sortField\n ? { orderBy: `${camelToSnake(this.sortField)} ASC` }\n : {}),\n })) as TItem[];\n }\n\n /**\n * Create a new junction row linking `leftId` ↔ `rightId`.\n *\n * Goes through `SmrtCollection.create` which performs an upsert keyed on\n * the model's `@smrt({ conflictColumns })`. Duplicates on the conflict key\n * resolve to an UPDATE that rewrites every column — including the row's\n * `id` and any timestamp columns — to the new instance's values. For most\n * junctions that's fine: callers identify rows by (left, right, discriminator),\n * not by junction-row-id, so id rewrites are invisible.\n *\n * If your junction table is externally addressable by id (e.g. its rows\n * are exposed under `/api/v1/<table>/[id]`), override this method with a\n * find-or-create check to preserve id stability across duplicate calls.\n * See `ContentReferences.attach` for an example.\n *\n * @param opts - Extra fields to write into the row (e.g. `{ relationship, sortOrder, tenantId }`)\n */\n async attach(\n leftId: string,\n rightId: string,\n opts: JunctionAttachOptions = {},\n ): Promise<TItem> {\n return (await this.create({\n // Spread opts FIRST so the fixed key fields always win — prevents\n // a caller-supplied `{ [leftField]: otherId }` from retargeting\n // the write when opts is forwarded from untrusted input.\n ...opts,\n [this.leftField]: leftId,\n [this.rightField]: rightId,\n } as SmrtCreateInput<TItem>)) as TItem;\n }\n\n /**\n * Delete all junction rows matching `leftId` + `rightId` (+ optional filter `opts`).\n *\n * @param opts - Additional WHERE filters (e.g. `{ relationship: 'thumbnail' }`)\n */\n async detach(\n leftId: string,\n rightId: string,\n opts: JunctionFilterOptions = {},\n ): Promise<void> {\n const links = (await this.list({\n where: {\n ...opts,\n [this.leftField]: leftId,\n [this.rightField]: rightId,\n },\n })) as TItem[];\n for (const link of links) {\n await (link as unknown as { delete(): Promise<void> }).delete();\n }\n }\n\n /**\n * Replace the full set of right-side rows for a `leftId`, scoped by `opts`.\n *\n * Behavior:\n * 1. Snapshots and deletes existing rows matching `{ leftField: leftId, ...opts }`.\n * 2. Creates a new row for each `rightId`, spreading `opts` into the row data.\n * 3. If `positionField` is set and `opts` doesn't specify it, assigns the array index.\n *\n * Not transactional — partial failure leaves the table in a mixed state.\n * For atomic replaces, wrap the call in your own DB transaction.\n */\n async setLinks(\n leftId: string,\n rightIds: string[],\n opts: JunctionAttachOptions = {},\n ): Promise<void> {\n // Strip the right-side key from snapshot opts — leaving it in would\n // narrow the delete to one specific right id, but `setLinks` is\n // contractually \"replace the full set of right rows for leftId\n // within the opts scope\". A rightField filter contradicts that.\n const snapshotOpts: JunctionAttachOptions = { ...opts };\n delete snapshotOpts[this.rightField];\n\n const existing = (await this.list({\n where: { ...snapshotOpts, [this.leftField]: leftId },\n })) as TItem[];\n for (const link of existing) {\n await (link as unknown as { delete(): Promise<void> }).delete();\n }\n\n const positionKey = this.positionField;\n for (let i = 0; i < rightIds.length; i++) {\n const rowOpts: JunctionAttachOptions = { ...opts };\n if (positionKey && rowOpts[positionKey] === undefined) {\n rowOpts[positionKey] = i;\n }\n await this.attach(leftId, rightIds[i], rowOpts);\n }\n }\n}\n"],"names":[],"mappings":";AA4CA,SAAS,aAAa,MAAsB;AAC1C,SAAO,KAAK,QAAQ,UAAU,CAAC,MAAM,IAAI,EAAE,YAAA,CAAa,EAAE;AAC5D;AAEO,MAAe,qBAEZ,eAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9B,OAAgB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBxB,YAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY3B,gBAA+B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzC,MAAM,OACJ,QACA,OAA8B,IACZ;AAClB,WAAQ,MAAM,KAAK,KAAK;AAAA;AAAA;AAAA;AAAA,MAItB,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,SAAS,GAAG,OAAA;AAAA,MACpC,GAAI,KAAK,YACL,EAAE,SAAS,GAAG,aAAa,KAAK,SAAS,CAAC,WAC1C,CAAA;AAAA,IAAC,CACN;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,QACJ,SACA,OAA8B,IACZ;AAClB,WAAQ,MAAM,KAAK,KAAK;AAAA,MACtB,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,UAAU,GAAG,QAAA;AAAA,MACrC,GAAI,KAAK,YACL,EAAE,SAAS,GAAG,aAAa,KAAK,SAAS,CAAC,WAC1C,CAAA;AAAA,IAAC,CACN;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,MAAM,OACJ,QACA,SACA,OAA8B,CA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"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,eAAO,MAAM,cAAc,EAAE,mBAszCnB,CAAC;AAEX,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"static-manifest.d.ts","sourceRoot":"","sources":["../../src/manifest/static-manifest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,eAAO,MAAM,cAAc,EAAE,mBAy0CnB,CAAC;AAEX,eAAe,cAAc,CAAC"}
@@ -1,8 +1,8 @@
1
1
  const staticManifest = {
2
2
  "version": "1.0.0",
3
- "timestamp": 1782522843119,
3
+ "timestamp": 1782683418480,
4
4
  "packageName": "@happyvertical/smrt-core",
5
- "packageVersion": "0.36.8",
5
+ "packageVersion": "0.37.0",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-core:SmrtClass": {
8
8
  "name": "smrtclass",
@@ -241,7 +241,7 @@ const staticManifest = {
241
241
  "parameters": [
242
242
  {
243
243
  "name": "filter",
244
- "type": "string | Record<string, any>",
244
+ "type": "string | SmrtWhereClause<ModelType>",
245
245
  "optional": false
246
246
  },
247
247
  {
@@ -274,12 +274,12 @@ const staticManifest = {
274
274
  "parameters": [
275
275
  {
276
276
  "name": "data",
277
- "type": "any",
277
+ "type": "Record<string>",
278
278
  "optional": false
279
279
  },
280
280
  {
281
281
  "name": "defaults",
282
- "type": "any",
282
+ "type": "Record<string>",
283
283
  "optional": true
284
284
  }
285
285
  ],
@@ -293,16 +293,16 @@ const staticManifest = {
293
293
  "parameters": [
294
294
  {
295
295
  "name": "existing",
296
- "type": "Record<string, any>",
296
+ "type": "SmrtObject | Record<string>",
297
297
  "optional": false
298
298
  },
299
299
  {
300
300
  "name": "data",
301
- "type": "Record<string, any>",
301
+ "type": "Record<string>",
302
302
  "optional": false
303
303
  }
304
304
  ],
305
- "returnType": "Promise<Record<string, any> | null>",
305
+ "returnType": "Promise<Record<string> | null>",
306
306
  "isStatic": false,
307
307
  "isPublic": true
308
308
  },
@@ -310,7 +310,7 @@ const staticManifest = {
310
310
  "name": "getFields",
311
311
  "async": true,
312
312
  "parameters": [],
313
- "returnType": "any",
313
+ "returnType": "Promise<Record<string, CollectionFieldDefinition>>",
314
314
  "isStatic": false,
315
315
  "isPublic": true
316
316
  },
@@ -318,7 +318,7 @@ const staticManifest = {
318
318
  "name": "getFieldsSync",
319
319
  "async": false,
320
320
  "parameters": [],
321
- "returnType": "Record<string, any>",
321
+ "returnType": "Record<string, CollectionFieldDefinition>",
322
322
  "isStatic": false,
323
323
  "isPublic": true
324
324
  },
@@ -385,7 +385,7 @@ const staticManifest = {
385
385
  },
386
386
  {
387
387
  "name": "params",
388
- "type": "any[]",
388
+ "type": "any",
389
389
  "optional": true
390
390
  },
391
391
  {
@@ -422,7 +422,7 @@ const staticManifest = {
422
422
  "optional": false
423
423
  }
424
424
  ],
425
- "returnType": "Promise<any | null>",
425
+ "returnType": "Promise",
426
426
  "isStatic": false,
427
427
  "isPublic": true
428
428
  },
@@ -436,7 +436,7 @@ const staticManifest = {
436
436
  "optional": true
437
437
  }
438
438
  ],
439
- "returnType": "Promise<Map<string, any>>",
439
+ "returnType": "Promise<Map<string>>",
440
440
  "isStatic": false,
441
441
  "isPublic": true
442
442
  },
@@ -839,7 +839,7 @@ const staticManifest = {
839
839
  "parameters": [
840
840
  {
841
841
  "name": "data",
842
- "type": "any",
842
+ "type": "Record<string>",
843
843
  "optional": false
844
844
  }
845
845
  ],
@@ -851,7 +851,7 @@ const staticManifest = {
851
851
  "name": "getFields",
852
852
  "async": true,
853
853
  "parameters": [],
854
- "returnType": "any",
854
+ "returnType": "Promise<any>",
855
855
  "isStatic": false,
856
856
  "isPublic": true
857
857
  },
@@ -960,7 +960,7 @@ const staticManifest = {
960
960
  },
961
961
  {
962
962
  "name": "options",
963
- "type": "any",
963
+ "type": "AiOperationOptions",
964
964
  "optional": true
965
965
  }
966
966
  ],
@@ -979,7 +979,7 @@ const staticManifest = {
979
979
  },
980
980
  {
981
981
  "name": "options",
982
- "type": "any",
982
+ "type": "AiOperationOptions",
983
983
  "optional": true
984
984
  }
985
985
  ],
@@ -993,7 +993,7 @@ const staticManifest = {
993
993
  "parameters": [
994
994
  {
995
995
  "name": "options",
996
- "type": "any",
996
+ "type": "AiOperationOptions",
997
997
  "optional": true
998
998
  }
999
999
  ],
@@ -1023,6 +1023,25 @@ const staticManifest = {
1023
1023
  "isStatic": false,
1024
1024
  "isPublic": true
1025
1025
  },
1026
+ "_setLoadedRelationship": {
1027
+ "name": "_setLoadedRelationship",
1028
+ "async": false,
1029
+ "parameters": [
1030
+ {
1031
+ "name": "fieldName",
1032
+ "type": "string",
1033
+ "optional": false
1034
+ },
1035
+ {
1036
+ "name": "value",
1037
+ "type": "any",
1038
+ "optional": false
1039
+ }
1040
+ ],
1041
+ "returnType": "void",
1042
+ "isStatic": false,
1043
+ "isPublic": true
1044
+ },
1026
1045
  "loadRelated": {
1027
1046
  "name": "loadRelated",
1028
1047
  "async": true,
@@ -1126,7 +1145,7 @@ const staticManifest = {
1126
1145
  "optional": false
1127
1146
  }
1128
1147
  ],
1129
- "returnType": "Promise<any | null>",
1148
+ "returnType": "Promise",
1130
1149
  "isStatic": false,
1131
1150
  "isPublic": true
1132
1151
  },
@@ -1140,7 +1159,7 @@ const staticManifest = {
1140
1159
  "optional": true
1141
1160
  }
1142
1161
  ],
1143
- "returnType": "Promise<Map<string, any>>",
1162
+ "returnType": "Promise<Map<string>>",
1144
1163
  "isStatic": false,
1145
1164
  "isPublic": true
1146
1165
  },