@rtpaulino/entity 0.24.0 → 0.24.2

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.
@@ -1,7 +1,7 @@
1
1
  import { PropertyOptions, type AnyCtor } from './types.js';
2
2
  import { EntityOptions } from './entity.js';
3
3
  import { Problem } from './problem.js';
4
- import { stringPropertyOptions, enumPropertyOptions, numberPropertyOptions, intPropertyOptions, booleanPropertyOptions, datePropertyOptions, bigIntPropertyOptions, entityPropertyOptions, arrayPropertyOptions, passthroughPropertyOptions, discriminatedEntityPropertyOptions } from './property.js';
4
+ import { stringPropertyOptions, enumPropertyOptions, numberPropertyOptions, intPropertyOptions, booleanPropertyOptions, datePropertyOptions, bigIntPropertyOptions, entityPropertyOptions, arrayPropertyOptions, passthroughPropertyOptions, discriminatedEntityPropertyOptions, stringifiablePropertyOptions } from './property.js';
5
5
  import { zodPropertyOptions } from './zod-property.js';
6
6
  /**
7
7
  * Configuration for defining an entity schema
@@ -24,6 +24,12 @@ export interface EntitySchemaConfig<T = any> {
24
24
  * Each function receives the entity instance and returns problems
25
25
  */
26
26
  validators?: Array<(instance: T) => Problem[] | Promise<Problem[]>>;
27
+ /**
28
+ * Whether to register this entity in the EntityRegistry.
29
+ * For dynamic schemas, defaults to false to prevent memory leaks.
30
+ * Set to true if you need discriminated entity deserialization.
31
+ */
32
+ register?: boolean;
27
33
  }
28
34
  /**
29
35
  * Wrapper object returned by EntitySchema.define() with EntityUtils methods
@@ -284,5 +290,21 @@ export declare const EntityProps: {
284
290
  * })
285
291
  */
286
292
  DiscriminatedEntity: typeof discriminatedEntityPropertyOptions;
293
+ /**
294
+ * Stringifiable property (for types with toString() and static parse())
295
+ * @example
296
+ * class CustomId {
297
+ * constructor(public value: string) {}
298
+ * toString() { return this.value; }
299
+ * static parse(str: string) { return new CustomId(str); }
300
+ * }
301
+ * EntitySchema.define({
302
+ * name: 'User',
303
+ * properties: {
304
+ * id: EntityProps.Stringifiable(() => CustomId),
305
+ * }
306
+ * })
307
+ */
308
+ Stringifiable: typeof stringifiablePropertyOptions;
287
309
  };
288
310
  //# sourceMappingURL=entity-definition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity-definition.d.ts","sourceRoot":"","sources":["../../src/lib/entity-definition.ts"],"names":[],"mappings":"AACA,OAAO,EAML,eAAe,EACf,KAAK,OAAO,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,kCAAkC,EACnC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG;IACzC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C;;;OAGG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;CACrE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjC;;OAEG;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A;KAAE,CAAC,CAAC;IAEjE;;OAEG;IACH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpC;AA0ED;;GAEG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAClC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC5B,mBAAmB,CAAC,CAAC,CAAC;CAuF1B;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;;OAcG;;CAEJ,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */ import { ENTITY_METADATA_KEY, ENTITY_OPTIONS_METADATA_KEY, ENTITY_VALIDATOR_METADATA_KEY, PROPERTY_METADATA_KEY, PROPERTY_OPTIONS_METADATA_KEY } from './types.js';
2
2
  import { EntityRegistry } from './entity-registry.js';
3
3
  import { EntityUtils } from './entity-utils.js';
4
- import { stringPropertyOptions, enumPropertyOptions, numberPropertyOptions, intPropertyOptions, booleanPropertyOptions, datePropertyOptions, bigIntPropertyOptions, entityPropertyOptions, arrayPropertyOptions, passthroughPropertyOptions, discriminatedEntityPropertyOptions } from './property.js';
4
+ import { stringPropertyOptions, enumPropertyOptions, numberPropertyOptions, intPropertyOptions, booleanPropertyOptions, datePropertyOptions, bigIntPropertyOptions, entityPropertyOptions, arrayPropertyOptions, passthroughPropertyOptions, discriminatedEntityPropertyOptions, stringifiablePropertyOptions } from './property.js';
5
5
  import { zodPropertyOptions } from './zod-property.js';
6
6
  /**
7
7
  * Define entity metadata on an existing class programmatically
@@ -20,8 +20,10 @@ import { zodPropertyOptions } from './zod-property.js';
20
20
  name: entityName
21
21
  };
22
22
  Reflect.defineMetadata(ENTITY_OPTIONS_METADATA_KEY, entityOptions, entityClass);
23
- // 3. Register in EntityRegistry
24
- EntityRegistry.register(entityName, entityClass);
23
+ // 3. Register in EntityRegistry if enabled
24
+ if (config.register) {
25
+ EntityRegistry.register(entityName, entityClass);
26
+ }
25
27
  // 4. Set property keys
26
28
  const propertyKeys = Object.keys(config.properties);
27
29
  Reflect.defineMetadata(PROPERTY_METADATA_KEY, propertyKeys, entityClass.prototype);
@@ -80,7 +82,8 @@ import { zodPropertyOptions } from './zod-property.js';
80
82
  name: config.name,
81
83
  options: config.options,
82
84
  properties: config.properties,
83
- validators: config.validators
85
+ validators: config.validators,
86
+ register: config.register ?? false
84
87
  });
85
88
  // Create wrapper with EntityUtils methods
86
89
  const wrapper = {
@@ -264,7 +267,22 @@ import { zodPropertyOptions } from './zod-property.js';
264
267
  * shape: EntityProps.DiscriminatedEntity({ discriminatorProperty: 'type' }),
265
268
  * }
266
269
  * })
267
- */ DiscriminatedEntity: discriminatedEntityPropertyOptions
270
+ */ DiscriminatedEntity: discriminatedEntityPropertyOptions,
271
+ /**
272
+ * Stringifiable property (for types with toString() and static parse())
273
+ * @example
274
+ * class CustomId {
275
+ * constructor(public value: string) {}
276
+ * toString() { return this.value; }
277
+ * static parse(str: string) { return new CustomId(str); }
278
+ * }
279
+ * EntitySchema.define({
280
+ * name: 'User',
281
+ * properties: {
282
+ * id: EntityProps.Stringifiable(() => CustomId),
283
+ * }
284
+ * })
285
+ */ Stringifiable: stringifiablePropertyOptions
268
286
  };
269
287
 
270
288
  //# sourceMappingURL=entity-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/entity-definition.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n ENTITY_METADATA_KEY,\n ENTITY_OPTIONS_METADATA_KEY,\n ENTITY_VALIDATOR_METADATA_KEY,\n PROPERTY_METADATA_KEY,\n PROPERTY_OPTIONS_METADATA_KEY,\n PropertyOptions,\n type AnyCtor,\n} from './types.js';\nimport { EntityOptions } from './entity.js';\nimport { EntityRegistry } from './entity-registry.js';\nimport { EntityUtils } from './entity-utils.js';\nimport { Problem } from './problem.js';\nimport {\n stringPropertyOptions,\n enumPropertyOptions,\n numberPropertyOptions,\n intPropertyOptions,\n booleanPropertyOptions,\n datePropertyOptions,\n bigIntPropertyOptions,\n entityPropertyOptions,\n arrayPropertyOptions,\n passthroughPropertyOptions,\n discriminatedEntityPropertyOptions,\n} from './property.js';\nimport { zodPropertyOptions } from './zod-property.js';\n\n/**\n * Configuration for defining an entity schema\n */\nexport interface EntitySchemaConfig<T = any> {\n /**\n * Name for the entity (required for schema-based entities)\n */\n name: string;\n /**\n * Entity options (collection, stringifiable, etc.)\n */\n options?: Omit<EntityOptions, 'name'>;\n /**\n * Property definitions - key is property name, value is property options\n */\n properties: Record<string, PropertyOptions>;\n /**\n * Validator functions that will be attached to the entity class\n * Each function receives the entity instance and returns problems\n */\n validators?: Array<(instance: T) => Problem[] | Promise<Problem[]>>;\n}\n\n/**\n * Wrapper object returned by EntitySchema.define() with EntityUtils methods\n */\nexport interface EntitySchemaWrapper<T> {\n /**\n * The generated entity class\n */\n readonly entityClass: AnyCtor<T>;\n\n /**\n * Parse data into an entity instance\n */\n parse(data: unknown): Promise<T>;\n\n /**\n * Parse data into an entity instance without throwing\n */\n safeParse(\n data: unknown,\n ): Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n\n /**\n * Parse only present properties without throwing\n */\n parsePartial(data: unknown): Promise<Partial<T>>;\n\n /**\n * Parse only present properties without throwing\n */\n safeParsePartial(\n data: unknown,\n ): Promise<\n | { success: true; data: Partial<T>; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n\n /**\n * Serialize entity instance to plain object\n */\n serialize(instance: T): unknown;\n\n /**\n * Update entity instance with new data\n */\n update(instance: T, data: unknown): Promise<T>;\n\n /**\n * Update entity instance with new data without throwing\n */\n safeUpdate(\n instance: T,\n data: unknown,\n ): Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: T; problems: Problem[] }\n >;\n\n /**\n * Validate entity instance\n */\n validate(instance: T): Promise<Problem[]>;\n\n /**\n * Check if two instances are equal\n */\n equals(a: T, b: T): boolean;\n\n /**\n * Get differences between two instances\n */\n diff(a: T, b: T): Record<string, { from: unknown; to: unknown }>;\n\n /**\n * Get changed values as partial object\n */\n getChanges(a: T, b: T): Partial<T>;\n}\n\n/**\n * Define entity metadata on an existing class programmatically\n * This sets the same metadata that @Entity() and @Property() decorators would set\n *\n * @param entityClass - The class to define as an entity\n * @param config - Configuration with properties, options, and validators\n * @internal\n */\nfunction defineEntity<T>(\n entityClass: AnyCtor<T>,\n config: EntitySchemaConfig<T>,\n): void {\n const entityName = config.name;\n\n // 1. Mark as entity\n Reflect.defineMetadata(ENTITY_METADATA_KEY, true, entityClass);\n\n // 2. Set entity options with resolved name\n const entityOptions: EntityOptions = {\n ...config.options,\n name: entityName,\n };\n Reflect.defineMetadata(\n ENTITY_OPTIONS_METADATA_KEY,\n entityOptions,\n entityClass,\n );\n\n // 3. Register in EntityRegistry\n EntityRegistry.register(entityName, entityClass);\n\n // 4. Set property keys\n const propertyKeys = Object.keys(config.properties);\n Reflect.defineMetadata(\n PROPERTY_METADATA_KEY,\n propertyKeys,\n entityClass.prototype,\n );\n\n // 5. Set property options\n Reflect.defineMetadata(\n PROPERTY_OPTIONS_METADATA_KEY,\n config.properties,\n entityClass.prototype,\n );\n\n // 6. Set up validators if provided\n if (config.validators && config.validators.length > 0) {\n const validatorMethodNames: string[] = [];\n\n config.validators.forEach((validatorFn, index) => {\n const methodName = `__dynamicValidator${index}`;\n validatorMethodNames.push(methodName);\n\n // Attach validator as instance method that uses 'this'\n (entityClass.prototype as any)[methodName] = function ():\n | Problem[]\n | Promise<Problem[]> {\n return validatorFn(this);\n };\n });\n\n Reflect.defineMetadata(\n ENTITY_VALIDATOR_METADATA_KEY,\n validatorMethodNames,\n entityClass.prototype,\n );\n }\n}\n\n/**\n * Factory for creating schema-based entities without pre-defining a class\n */\nexport class EntitySchema {\n /**\n * Define a new entity schema and return a wrapper with EntityUtils methods\n *\n * @param config - Schema configuration with name, properties, options, and validators\n * @returns Wrapper object with parse, serialize, validate, etc. methods\n *\n * @example\n * ```typescript\n * const UserSchema = EntitySchema.define({\n * name: 'User',\n * properties: {\n * name: { type: () => String },\n * age: { type: () => Number, optional: true },\n * tags: { type: () => String, array: true },\n * },\n * validators: [\n * (user) => user.name.length < 2 ? [{ path: 'name', message: 'Too short' }] : []\n * ]\n * });\n *\n * const user = await UserSchema.parse({ name: 'John', age: 30, tags: ['admin'] });\n * const serialized = UserSchema.serialize(user);\n * const isValid = (await UserSchema.validate(user)).length === 0;\n * ```\n */\n static define<T extends object = any>(\n config: EntitySchemaConfig<T>,\n ): EntitySchemaWrapper<T> {\n // Generate anonymous entity class\n const entityClass = class {\n constructor(data: any) {\n Object.assign(this, data);\n }\n } as unknown as AnyCtor<T>;\n\n // Define entity metadata\n defineEntity(entityClass, {\n name: config.name,\n options: config.options,\n properties: config.properties,\n validators: config.validators,\n });\n\n // Create wrapper with EntityUtils methods\n const wrapper: EntitySchemaWrapper<T> = {\n entityClass,\n\n async parse(data: unknown): Promise<T> {\n return EntityUtils.parse(entityClass as any, data) as Promise<T>;\n },\n\n async safeParse(data: unknown) {\n return EntityUtils.safeParse(entityClass as any, data) as Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n },\n\n async parsePartial(data: unknown): Promise<Partial<T>> {\n return EntityUtils.partialParse(entityClass as any, data) as Promise<\n Partial<T>\n >;\n },\n\n async safeParsePartial(data: unknown) {\n return EntityUtils.safePartialParse(\n entityClass as any,\n data,\n ) as unknown as Promise<\n | { success: true; data: Partial<T>; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n },\n\n serialize(instance: T): unknown {\n return EntityUtils.toJSON(instance as any);\n },\n\n async update(instance: T, data: unknown): Promise<T> {\n return EntityUtils.update(instance as any, data as any) as Promise<T>;\n },\n\n async safeUpdate(instance: T, data: unknown) {\n return EntityUtils.safeUpdate(instance as any, data as any) as Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: T; problems: Problem[] }\n >;\n },\n\n async validate(instance: T): Promise<Problem[]> {\n return EntityUtils.validate(instance as any);\n },\n\n equals(a: T, b: T): boolean {\n return EntityUtils.equals(a as any, b as any);\n },\n\n diff(a: T, b: T): Record<string, { from: unknown; to: unknown }> {\n const diffs = EntityUtils.diff(a as any, b as any);\n const result: Record<string, { from: unknown; to: unknown }> = {};\n for (const diff of diffs) {\n result[diff.property] = { from: diff.oldValue, to: diff.newValue };\n }\n return result;\n },\n\n getChanges(a: T, b: T): Partial<T> {\n return EntityUtils.changes(a as any, b as any) as Partial<T>;\n },\n };\n\n return wrapper;\n }\n}\n\n/**\n * Property definition helpers for EntitySchema\n * These mirror the decorator-based property helpers but return PropertyOptions objects\n */\nexport const EntityProps = {\n /**\n * String property with optional validation\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * name: EntityProps.String({ minLength: 2, maxLength: 50 }),\n * email: EntityProps.String({ pattern: /^.+@.+\\..+$/ }),\n * }\n * })\n */\n String: stringPropertyOptions,\n\n /**\n * Enum property (validates string against enum values)\n * @example\n * enum Status { Active = 'active', Inactive = 'inactive' }\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * status: EntityProps.Enum(Status),\n * }\n * })\n */\n Enum: enumPropertyOptions,\n\n /**\n * Number property with optional min/max validation\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * age: EntityProps.Number({ min: 0, max: 150 }),\n * score: EntityProps.Number({ optional: true }),\n * }\n * })\n */\n Number: numberPropertyOptions,\n\n /**\n * Integer property (number that must be an integer)\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * age: EntityProps.Int({ min: 0 }),\n * }\n * })\n */\n Int: intPropertyOptions,\n\n /**\n * Boolean property\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * isActive: EntityProps.Boolean(),\n * emailVerified: EntityProps.Boolean({ optional: true }),\n * }\n * })\n */\n Boolean: booleanPropertyOptions,\n\n /**\n * Date property\n * @example\n * EntitySchema.define({\n * name: 'Event',\n * properties: {\n * createdAt: EntityProps.Date(),\n * scheduledFor: EntityProps.Date({ optional: true }),\n * }\n * })\n */\n Date: datePropertyOptions,\n\n /**\n * BigInt property\n * @example\n * EntitySchema.define({\n * name: 'Transaction',\n * properties: {\n * amount: EntityProps.BigInt(),\n * }\n * })\n */\n BigInt: bigIntPropertyOptions,\n\n /**\n * Entity property (nested entity)\n * @example\n * const AddressSchema = EntitySchema.define({ ... });\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * address: EntityProps.Entity(() => AddressSchema.entityClass),\n * }\n * })\n */\n Entity: entityPropertyOptions,\n\n /**\n * Array property\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * tags: EntityProps.Array(() => String),\n * addresses: EntityProps.Array(() => AddressSchema.entityClass),\n * }\n * })\n */\n Array: arrayPropertyOptions,\n\n /**\n * Passthrough property (no deserialization/validation)\n * @example\n * EntitySchema.define({\n * name: 'Config',\n * properties: {\n * metadata: EntityProps.Passthrough(),\n * }\n * })\n */\n Passthrough: passthroughPropertyOptions,\n\n /**\n * Zod schema property (validates using Zod schema)\n * @example\n * import { z } from 'zod';\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * data: EntityProps.Zod(z.object({\n * name: z.string().min(3),\n * age: z.number().int().min(0)\n * })),\n * }\n * })\n */\n Zod: zodPropertyOptions,\n\n /**\n * Discriminated entity property (for polymorphic entities with discriminator)\n * @example\n * EntitySchema.define({\n * name: 'Shape',\n * properties: {\n * shape: EntityProps.DiscriminatedEntity({ discriminatorProperty: 'type' }),\n * }\n * })\n */\n DiscriminatedEntity: discriminatedEntityPropertyOptions,\n};\n"],"names":["ENTITY_METADATA_KEY","ENTITY_OPTIONS_METADATA_KEY","ENTITY_VALIDATOR_METADATA_KEY","PROPERTY_METADATA_KEY","PROPERTY_OPTIONS_METADATA_KEY","EntityRegistry","EntityUtils","stringPropertyOptions","enumPropertyOptions","numberPropertyOptions","intPropertyOptions","booleanPropertyOptions","datePropertyOptions","bigIntPropertyOptions","entityPropertyOptions","arrayPropertyOptions","passthroughPropertyOptions","discriminatedEntityPropertyOptions","zodPropertyOptions","defineEntity","entityClass","config","entityName","name","Reflect","defineMetadata","entityOptions","options","register","propertyKeys","Object","keys","properties","prototype","validators","length","validatorMethodNames","forEach","validatorFn","index","methodName","push","EntitySchema","define","data","assign","wrapper","parse","safeParse","parsePartial","partialParse","safeParsePartial","safePartialParse","serialize","instance","toJSON","update","safeUpdate","validate","equals","a","b","diff","diffs","result","property","from","oldValue","to","newValue","getChanges","changes","EntityProps","String","Enum","Number","Int","Boolean","Date","BigInt","Entity","Array","Passthrough","Zod","DiscriminatedEntity"],"mappings":"AAAA,qDAAqD,GACrD,SACEA,mBAAmB,EACnBC,2BAA2B,EAC3BC,6BAA6B,EAC7BC,qBAAqB,EACrBC,6BAA6B,QAGxB,aAAa;AAEpB,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,WAAW,QAAQ,oBAAoB;AAEhD,SACEC,qBAAqB,EACrBC,mBAAmB,EACnBC,qBAAqB,EACrBC,kBAAkB,EAClBC,sBAAsB,EACtBC,mBAAmB,EACnBC,qBAAqB,EACrBC,qBAAqB,EACrBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,kCAAkC,QAC7B,gBAAgB;AACvB,SAASC,kBAAkB,QAAQ,oBAAoB;AA0Gv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C;QACF;QAEA,OAAOf;IACT;AACF;AAEA;;;CAGC,GACD,OAAO,MAAM0B,cAAc;IACzB;;;;;;;;;;GAUC,GACDC,QAAQlE;IAER;;;;;;;;;;GAUC,GACDmE,MAAMlE;IAEN;;;;;;;;;;GAUC,GACDmE,QAAQlE;IAER;;;;;;;;;GASC,GACDmE,KAAKlE;IAEL;;;;;;;;;;GAUC,GACDmE,SAASlE;IAET;;;;;;;;;;GAUC,GACDmE,MAAMlE;IAEN;;;;;;;;;GASC,GACDmE,QAAQlE;IAER;;;;;;;;;;GAUC,GACDmE,QAAQlE;IAER;;;;;;;;;;GAUC,GACDmE,OAAOlE;IAEP;;;;;;;;;GASC,GACDmE,aAAalE;IAEb;;;;;;;;;;;;;GAaC,GACDmE,KAAKjE;IAEL;;;;;;;;;GASC,GACDkE,qBAAqBnE;AACvB,EAAE"}
1
+ {"version":3,"sources":["../../src/lib/entity-definition.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n ENTITY_METADATA_KEY,\n ENTITY_OPTIONS_METADATA_KEY,\n ENTITY_VALIDATOR_METADATA_KEY,\n PROPERTY_METADATA_KEY,\n PROPERTY_OPTIONS_METADATA_KEY,\n PropertyOptions,\n type AnyCtor,\n} from './types.js';\nimport { EntityOptions } from './entity.js';\nimport { EntityRegistry } from './entity-registry.js';\nimport { EntityUtils } from './entity-utils.js';\nimport { Problem } from './problem.js';\nimport {\n stringPropertyOptions,\n enumPropertyOptions,\n numberPropertyOptions,\n intPropertyOptions,\n booleanPropertyOptions,\n datePropertyOptions,\n bigIntPropertyOptions,\n entityPropertyOptions,\n arrayPropertyOptions,\n passthroughPropertyOptions,\n discriminatedEntityPropertyOptions,\n stringifiablePropertyOptions,\n} from './property.js';\nimport { zodPropertyOptions } from './zod-property.js';\n\n/**\n * Configuration for defining an entity schema\n */\nexport interface EntitySchemaConfig<T = any> {\n /**\n * Name for the entity (required for schema-based entities)\n */\n name: string;\n /**\n * Entity options (collection, stringifiable, etc.)\n */\n options?: Omit<EntityOptions, 'name'>;\n /**\n * Property definitions - key is property name, value is property options\n */\n properties: Record<string, PropertyOptions>;\n /**\n * Validator functions that will be attached to the entity class\n * Each function receives the entity instance and returns problems\n */\n validators?: Array<(instance: T) => Problem[] | Promise<Problem[]>>;\n /**\n * Whether to register this entity in the EntityRegistry.\n * For dynamic schemas, defaults to false to prevent memory leaks.\n * Set to true if you need discriminated entity deserialization.\n */\n register?: boolean;\n}\n\n/**\n * Wrapper object returned by EntitySchema.define() with EntityUtils methods\n */\nexport interface EntitySchemaWrapper<T> {\n /**\n * The generated entity class\n */\n readonly entityClass: AnyCtor<T>;\n\n /**\n * Parse data into an entity instance\n */\n parse(data: unknown): Promise<T>;\n\n /**\n * Parse data into an entity instance without throwing\n */\n safeParse(\n data: unknown,\n ): Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n\n /**\n * Parse only present properties without throwing\n */\n parsePartial(data: unknown): Promise<Partial<T>>;\n\n /**\n * Parse only present properties without throwing\n */\n safeParsePartial(\n data: unknown,\n ): Promise<\n | { success: true; data: Partial<T>; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n\n /**\n * Serialize entity instance to plain object\n */\n serialize(instance: T): unknown;\n\n /**\n * Update entity instance with new data\n */\n update(instance: T, data: unknown): Promise<T>;\n\n /**\n * Update entity instance with new data without throwing\n */\n safeUpdate(\n instance: T,\n data: unknown,\n ): Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: T; problems: Problem[] }\n >;\n\n /**\n * Validate entity instance\n */\n validate(instance: T): Promise<Problem[]>;\n\n /**\n * Check if two instances are equal\n */\n equals(a: T, b: T): boolean;\n\n /**\n * Get differences between two instances\n */\n diff(a: T, b: T): Record<string, { from: unknown; to: unknown }>;\n\n /**\n * Get changed values as partial object\n */\n getChanges(a: T, b: T): Partial<T>;\n}\n\n/**\n * Define entity metadata on an existing class programmatically\n * This sets the same metadata that @Entity() and @Property() decorators would set\n *\n * @param entityClass - The class to define as an entity\n * @param config - Configuration with properties, options, and validators\n * @internal\n */\nfunction defineEntity<T>(\n entityClass: AnyCtor<T>,\n config: EntitySchemaConfig<T>,\n): void {\n const entityName = config.name;\n\n // 1. Mark as entity\n Reflect.defineMetadata(ENTITY_METADATA_KEY, true, entityClass);\n\n // 2. Set entity options with resolved name\n const entityOptions: EntityOptions = {\n ...config.options,\n name: entityName,\n };\n Reflect.defineMetadata(\n ENTITY_OPTIONS_METADATA_KEY,\n entityOptions,\n entityClass,\n );\n\n // 3. Register in EntityRegistry if enabled\n if (config.register) {\n EntityRegistry.register(entityName, entityClass);\n }\n\n // 4. Set property keys\n const propertyKeys = Object.keys(config.properties);\n Reflect.defineMetadata(\n PROPERTY_METADATA_KEY,\n propertyKeys,\n entityClass.prototype,\n );\n\n // 5. Set property options\n Reflect.defineMetadata(\n PROPERTY_OPTIONS_METADATA_KEY,\n config.properties,\n entityClass.prototype,\n );\n\n // 6. Set up validators if provided\n if (config.validators && config.validators.length > 0) {\n const validatorMethodNames: string[] = [];\n\n config.validators.forEach((validatorFn, index) => {\n const methodName = `__dynamicValidator${index}`;\n validatorMethodNames.push(methodName);\n\n // Attach validator as instance method that uses 'this'\n (entityClass.prototype as any)[methodName] = function ():\n | Problem[]\n | Promise<Problem[]> {\n return validatorFn(this);\n };\n });\n\n Reflect.defineMetadata(\n ENTITY_VALIDATOR_METADATA_KEY,\n validatorMethodNames,\n entityClass.prototype,\n );\n }\n}\n\n/**\n * Factory for creating schema-based entities without pre-defining a class\n */\nexport class EntitySchema {\n /**\n * Define a new entity schema and return a wrapper with EntityUtils methods\n *\n * @param config - Schema configuration with name, properties, options, and validators\n * @returns Wrapper object with parse, serialize, validate, etc. methods\n *\n * @example\n * ```typescript\n * const UserSchema = EntitySchema.define({\n * name: 'User',\n * properties: {\n * name: { type: () => String },\n * age: { type: () => Number, optional: true },\n * tags: { type: () => String, array: true },\n * },\n * validators: [\n * (user) => user.name.length < 2 ? [{ path: 'name', message: 'Too short' }] : []\n * ]\n * });\n *\n * const user = await UserSchema.parse({ name: 'John', age: 30, tags: ['admin'] });\n * const serialized = UserSchema.serialize(user);\n * const isValid = (await UserSchema.validate(user)).length === 0;\n * ```\n */\n static define<T extends object = any>(\n config: EntitySchemaConfig<T>,\n ): EntitySchemaWrapper<T> {\n // Generate anonymous entity class\n const entityClass = class {\n constructor(data: any) {\n Object.assign(this, data);\n }\n } as unknown as AnyCtor<T>;\n\n // Define entity metadata\n defineEntity(entityClass, {\n name: config.name,\n options: config.options,\n properties: config.properties,\n validators: config.validators,\n register: config.register ?? false, // Default to false for dynamic schemas to prevent memory leaks\n });\n\n // Create wrapper with EntityUtils methods\n const wrapper: EntitySchemaWrapper<T> = {\n entityClass,\n\n async parse(data: unknown): Promise<T> {\n return EntityUtils.parse(entityClass as any, data) as Promise<T>;\n },\n\n async safeParse(data: unknown) {\n return EntityUtils.safeParse(entityClass as any, data) as Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n },\n\n async parsePartial(data: unknown): Promise<Partial<T>> {\n return EntityUtils.partialParse(entityClass as any, data) as Promise<\n Partial<T>\n >;\n },\n\n async safeParsePartial(data: unknown) {\n return EntityUtils.safePartialParse(\n entityClass as any,\n data,\n ) as unknown as Promise<\n | { success: true; data: Partial<T>; problems: Problem[] }\n | { success: false; data: undefined; problems: Problem[] }\n >;\n },\n\n serialize(instance: T): unknown {\n return EntityUtils.toJSON(instance as any);\n },\n\n async update(instance: T, data: unknown): Promise<T> {\n return EntityUtils.update(instance as any, data as any) as Promise<T>;\n },\n\n async safeUpdate(instance: T, data: unknown) {\n return EntityUtils.safeUpdate(instance as any, data as any) as Promise<\n | { success: true; data: T; problems: Problem[] }\n | { success: false; data: T; problems: Problem[] }\n >;\n },\n\n async validate(instance: T): Promise<Problem[]> {\n return EntityUtils.validate(instance as any);\n },\n\n equals(a: T, b: T): boolean {\n return EntityUtils.equals(a as any, b as any);\n },\n\n diff(a: T, b: T): Record<string, { from: unknown; to: unknown }> {\n const diffs = EntityUtils.diff(a as any, b as any);\n const result: Record<string, { from: unknown; to: unknown }> = {};\n for (const diff of diffs) {\n result[diff.property] = { from: diff.oldValue, to: diff.newValue };\n }\n return result;\n },\n\n getChanges(a: T, b: T): Partial<T> {\n return EntityUtils.changes(a as any, b as any) as Partial<T>;\n },\n };\n\n return wrapper;\n }\n}\n\n/**\n * Property definition helpers for EntitySchema\n * These mirror the decorator-based property helpers but return PropertyOptions objects\n */\nexport const EntityProps = {\n /**\n * String property with optional validation\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * name: EntityProps.String({ minLength: 2, maxLength: 50 }),\n * email: EntityProps.String({ pattern: /^.+@.+\\..+$/ }),\n * }\n * })\n */\n String: stringPropertyOptions,\n\n /**\n * Enum property (validates string against enum values)\n * @example\n * enum Status { Active = 'active', Inactive = 'inactive' }\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * status: EntityProps.Enum(Status),\n * }\n * })\n */\n Enum: enumPropertyOptions,\n\n /**\n * Number property with optional min/max validation\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * age: EntityProps.Number({ min: 0, max: 150 }),\n * score: EntityProps.Number({ optional: true }),\n * }\n * })\n */\n Number: numberPropertyOptions,\n\n /**\n * Integer property (number that must be an integer)\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * age: EntityProps.Int({ min: 0 }),\n * }\n * })\n */\n Int: intPropertyOptions,\n\n /**\n * Boolean property\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * isActive: EntityProps.Boolean(),\n * emailVerified: EntityProps.Boolean({ optional: true }),\n * }\n * })\n */\n Boolean: booleanPropertyOptions,\n\n /**\n * Date property\n * @example\n * EntitySchema.define({\n * name: 'Event',\n * properties: {\n * createdAt: EntityProps.Date(),\n * scheduledFor: EntityProps.Date({ optional: true }),\n * }\n * })\n */\n Date: datePropertyOptions,\n\n /**\n * BigInt property\n * @example\n * EntitySchema.define({\n * name: 'Transaction',\n * properties: {\n * amount: EntityProps.BigInt(),\n * }\n * })\n */\n BigInt: bigIntPropertyOptions,\n\n /**\n * Entity property (nested entity)\n * @example\n * const AddressSchema = EntitySchema.define({ ... });\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * address: EntityProps.Entity(() => AddressSchema.entityClass),\n * }\n * })\n */\n Entity: entityPropertyOptions,\n\n /**\n * Array property\n * @example\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * tags: EntityProps.Array(() => String),\n * addresses: EntityProps.Array(() => AddressSchema.entityClass),\n * }\n * })\n */\n Array: arrayPropertyOptions,\n\n /**\n * Passthrough property (no deserialization/validation)\n * @example\n * EntitySchema.define({\n * name: 'Config',\n * properties: {\n * metadata: EntityProps.Passthrough(),\n * }\n * })\n */\n Passthrough: passthroughPropertyOptions,\n\n /**\n * Zod schema property (validates using Zod schema)\n * @example\n * import { z } from 'zod';\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * data: EntityProps.Zod(z.object({\n * name: z.string().min(3),\n * age: z.number().int().min(0)\n * })),\n * }\n * })\n */\n Zod: zodPropertyOptions,\n\n /**\n * Discriminated entity property (for polymorphic entities with discriminator)\n * @example\n * EntitySchema.define({\n * name: 'Shape',\n * properties: {\n * shape: EntityProps.DiscriminatedEntity({ discriminatorProperty: 'type' }),\n * }\n * })\n */\n DiscriminatedEntity: discriminatedEntityPropertyOptions,\n\n /**\n * Stringifiable property (for types with toString() and static parse())\n * @example\n * class CustomId {\n * constructor(public value: string) {}\n * toString() { return this.value; }\n * static parse(str: string) { return new CustomId(str); }\n * }\n * EntitySchema.define({\n * name: 'User',\n * properties: {\n * id: EntityProps.Stringifiable(() => CustomId),\n * }\n * })\n */\n Stringifiable: stringifiablePropertyOptions,\n};\n"],"names":["ENTITY_METADATA_KEY","ENTITY_OPTIONS_METADATA_KEY","ENTITY_VALIDATOR_METADATA_KEY","PROPERTY_METADATA_KEY","PROPERTY_OPTIONS_METADATA_KEY","EntityRegistry","EntityUtils","stringPropertyOptions","enumPropertyOptions","numberPropertyOptions","intPropertyOptions","booleanPropertyOptions","datePropertyOptions","bigIntPropertyOptions","entityPropertyOptions","arrayPropertyOptions","passthroughPropertyOptions","discriminatedEntityPropertyOptions","stringifiablePropertyOptions","zodPropertyOptions","defineEntity","entityClass","config","entityName","name","Reflect","defineMetadata","entityOptions","options","register","propertyKeys","Object","keys","properties","prototype","validators","length","validatorMethodNames","forEach","validatorFn","index","methodName","push","EntitySchema","define","data","assign","wrapper","parse","safeParse","parsePartial","partialParse","safeParsePartial","safePartialParse","serialize","instance","toJSON","update","safeUpdate","validate","equals","a","b","diff","diffs","result","property","from","oldValue","to","newValue","getChanges","changes","EntityProps","String","Enum","Number","Int","Boolean","Date","BigInt","Entity","Array","Passthrough","Zod","DiscriminatedEntity","Stringifiable"],"mappings":"AAAA,qDAAqD,GACrD,SACEA,mBAAmB,EACnBC,2BAA2B,EAC3BC,6BAA6B,EAC7BC,qBAAqB,EACrBC,6BAA6B,QAGxB,aAAa;AAEpB,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,WAAW,QAAQ,oBAAoB;AAEhD,SACEC,qBAAqB,EACrBC,mBAAmB,EACnBC,qBAAqB,EACrBC,kBAAkB,EAClBC,sBAAsB,EACtBC,mBAAmB,EACnBC,qBAAqB,EACrBC,qBAAqB,EACrBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,4BAA4B,QACvB,gBAAgB;AACvB,SAASC,kBAAkB,QAAQ,oBAAoB;AAgHvD;;;;;;;CAOC,GACD,SAASC,aACPC,WAAuB,EACvBC,MAA6B;IAE7B,MAAMC,aAAaD,OAAOE,IAAI;IAE9B,oBAAoB;IACpBC,QAAQC,cAAc,CAAC1B,qBAAqB,MAAMqB;IAElD,2CAA2C;IAC3C,MAAMM,gBAA+B;QACnC,GAAGL,OAAOM,OAAO;QACjBJ,MAAMD;IACR;IACAE,QAA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C,GACDoE,QAAQnE;IAER;;;;;;;;;GASC,GACDoE,KAAKnE;IAEL;;;;;;;;;;GAUC,GACDoE,SAASnE;IAET;;;;;;;;;;GAUC,GACDoE,MAAMnE;IAEN;;;;;;;;;GASC,GACDoE,QAAQnE;IAER;;;;;;;;;;GAUC,GACDoE,QAAQnE;IAER;;;;;;;;;;GAUC,GACDoE,OAAOnE;IAEP;;;;;;;;;GASC,GACDoE,aAAanE;IAEb;;;;;;;;;;;;;GAaC,GACDoE,KAAKjE;IAEL;;;;;;;;;GASC,GACDkE,qBAAqBpE;IAErB;;;;;;;;;;;;;;GAcC,GACDqE,eAAepE;AACjB,EAAE"}
@@ -28,6 +28,12 @@ export interface EntityOptions {
28
28
  * Used by @CollectionEntity ('collection') and @Stringifiable ('value').
29
29
  */
30
30
  wrapperProperty?: string;
31
+ /**
32
+ * Whether to register this entity in the EntityRegistry.
33
+ * Set to false for dynamic entities to prevent memory leaks.
34
+ * Defaults to true.
35
+ */
36
+ register?: boolean;
31
37
  }
32
38
  /**
33
39
  * Decorator that marks a class as an Entity.
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/lib/entity.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,cAAc,CAqBlE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAM,GACxC,cAAc,CAMhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,aAAa,CAC3B,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAM,GACxC,cAAc,CAEhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAmBjD"}
1
+ {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/lib/entity.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,cAAc,CAwBlE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAM,GACxC,cAAc,CAMhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,aAAa,CAC3B,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAM,GACxC,cAAc,CAEhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAmBjD"}
@@ -31,8 +31,11 @@ import { EntityRegistry } from './entity-registry.js';
31
31
  Reflect.defineMetadata(ENTITY_METADATA_KEY, true, target);
32
32
  // Determine the entity name - use provided name or fall back to class name
33
33
  const entityName = options.name ?? target.name;
34
- // Register the entity in the global registry
35
- EntityRegistry.register(entityName, target);
34
+ // Register the entity in the global registry (unless explicitly disabled)
35
+ const shouldRegister = options.register !== false;
36
+ if (shouldRegister) {
37
+ EntityRegistry.register(entityName, target);
38
+ }
36
39
  // Store the name in options for later retrieval
37
40
  const optionsWithName = {
38
41
  ...options,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/entity.ts"],"sourcesContent":["import {\n ENTITY_METADATA_KEY,\n ENTITY_OPTIONS_METADATA_KEY,\n ENTITY_VALIDATOR_METADATA_KEY,\n} from './types.js';\nimport { EntityRegistry } from './entity-registry.js';\n\n/**\n * Options for Entity decorator\n */\nexport interface EntityOptions {\n /**\n * Optional name for the entity. Used for discriminated entity deserialization.\n * If not specified, the class name will be used.\n * Must be unique across all entities - conflicts will throw an error.\n */\n name?: string;\n /**\n * Whether this entity represents a collection.\n * Collection entities must have a 'collection' property that is an array.\n * When serialized, collection entities are unwrapped to just their array.\n * When deserialized from an array, the array is wrapped in { collection: [...] }.\n */\n collection?: boolean;\n /**\n * Whether this entity represents a stringifiable value.\n * Stringifiable classes must have a 'value' property that is a string.\n * When serialized, stringifiable instances are unwrapped to just their string.\n * When deserialized from a string, the string is wrapped in { value: \"...\" }.\n */\n stringifiable?: boolean;\n /**\n * The name of the single \"wrapper\" property for entities that act as transparent wrappers.\n * When set, this property name is excluded from error paths during validation.\n * Used by @CollectionEntity ('collection') and @Stringifiable ('value').\n */\n wrapperProperty?: string;\n}\n\n/**\n * Decorator that marks a class as an Entity.\n * This allows us to identify entity instances later.\n *\n * @param options - Optional configuration for the entity\n *\n * @example\n * ```typescript\n * @Entity()\n * class User {\n * name: string;\n * }\n *\n * @Entity({ name: 'CustomUser' })\n * class User {\n * name: string;\n * }\n *\n * @Entity({ collection: true })\n * class Tags {\n * @ArrayProperty(() => String)\n * collection: string[];\n * }\n * ```\n */\nexport function Entity(options: EntityOptions = {}): ClassDecorator {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n return function (target: Function) {\n // Store metadata on the class constructor\n Reflect.defineMetadata(ENTITY_METADATA_KEY, true, target);\n\n // Determine the entity name - use provided name or fall back to class name\n const entityName = options.name ?? target.name;\n\n // Register the entity in the global registry\n EntityRegistry.register(entityName, target);\n\n // Store the name in options for later retrieval\n const optionsWithName = { ...options, name: entityName };\n\n Reflect.defineMetadata(\n ENTITY_OPTIONS_METADATA_KEY,\n optionsWithName,\n target,\n );\n };\n}\n\n/**\n * Decorator that marks a class as a Collection Entity.\n * This is syntax sugar for @Entity({ collection: true }).\n *\n * Collection entities must have a 'collection' property that is an array.\n * When serialized with EntityUtils.toJSON(), they are unwrapped to just the array.\n * When deserialized from an array, the array is wrapped in { collection: [...] }.\n *\n * @example\n * ```typescript\n * @CollectionEntity()\n * class Tags {\n * @ArrayProperty(() => String)\n * readonly collection: string[];\n *\n * constructor(data: { collection: string[] }) {\n * this.collection = data.collection;\n * }\n * }\n *\n * @Entity()\n * class Article {\n * @EntityProperty(() => Tags)\n * tags!: Tags;\n * }\n *\n * const article = new Article(...);\n * const json = EntityUtils.toJSON(article);\n * // { tags: [\"tag1\", \"tag2\"] } - unwrapped to array\n *\n * // Also works when serializing the collection directly:\n * const tagsJson = EntityUtils.toJSON(tags);\n * // [\"tag1\", \"tag2\"] - unwrapped to array\n * ```\n */\nexport function CollectionEntity(\n options: Pick<EntityOptions, 'name'> = {},\n): ClassDecorator {\n return Entity({\n collection: true,\n wrapperProperty: 'collection',\n ...options,\n });\n}\n\n/**\n * Decorator that marks a class as Stringifiable.\n * This is syntax sugar for @Entity({ stringifiable: true }).\n *\n * Stringifiable classes must have a 'value' property that is a string.\n * When serialized with EntityUtils.toJSON(), they are unwrapped to just the string.\n * When deserialized from a string, the string is wrapped in { value: \"...\" }.\n *\n * @example\n * ```typescript\n * @Stringifiable()\n * class UserId {\n * @StringProperty()\n * readonly value: string;\n *\n * constructor(data: { value: string }) {\n * this.value = data.value;\n * }\n * }\n *\n * @Entity()\n * class User {\n * @EntityProperty(() => UserId)\n * id!: UserId;\n * }\n *\n * const user = new User(...);\n * const json = EntityUtils.toJSON(user);\n * // { id: \"user-123\" } - unwrapped to string\n *\n * // Also works when serializing the stringifiable directly:\n * const userId = new UserId({ value: \"user-123\" });\n * const idJson = EntityUtils.toJSON(userId);\n * // \"user-123\" - unwrapped to string\n *\n * // Parse from string:\n * const parsed = await EntityUtils.parse(UserId, \"user-456\");\n * // UserId { value: \"user-456\" }\n * ```\n */\nexport function Stringifiable(\n options: Pick<EntityOptions, 'name'> = {},\n): ClassDecorator {\n return Entity({ stringifiable: true, wrapperProperty: 'value', ...options });\n}\n\n/**\n * Decorator that marks a method as an entity validator.\n * The method should return an array of Problems.\n *\n * @example\n * ```typescript\n * @Entity()\n * class User {\n * @Property({ type: () => String }) firstName!: string;\n * @Property({ type: () => String }) lastName!: string;\n *\n * @EntityValidator()\n * validateNames(): Problem[] {\n * const problems: Problem[] = [];\n * if (this.firstName === this.lastName) {\n * problems.push(new Problem({\n * property: 'firstName',\n * message: 'First and last name cannot be the same'\n * }));\n * }\n * return problems;\n * }\n * }\n * ```\n */\nexport function EntityValidator(): MethodDecorator {\n return (target: object, propertyKey: string | symbol): void => {\n if (typeof propertyKey !== 'string') {\n return;\n }\n\n const existingValidators: string[] =\n Reflect.getOwnMetadata(ENTITY_VALIDATOR_METADATA_KEY, target) || [];\n\n if (!existingValidators.includes(propertyKey)) {\n existingValidators.push(propertyKey);\n }\n\n Reflect.defineMetadata(\n ENTITY_VALIDATOR_METADATA_KEY,\n existingValidators,\n target,\n );\n };\n}\n"],"names":["ENTITY_METADATA_KEY","ENTITY_OPTIONS_METADATA_KEY","ENTITY_VALIDATOR_METADATA_KEY","EntityRegistry","Entity","options","target","Reflect","defineMetadata","entityName","name","register","optionsWithName","CollectionEntity","collection","wrapperProperty","Stringifiable","stringifiable","EntityValidator","propertyKey","existingValidators","getOwnMetadata","includes","push"],"mappings":"AAAA,SACEA,mBAAmB,EACn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/lib/entity.ts"],"sourcesContent":["import {\n ENTITY_METADATA_KEY,\n ENTITY_OPTIONS_METADATA_KEY,\n ENTITY_VALIDATOR_METADATA_KEY,\n} from './types.js';\nimport { EntityRegistry } from './entity-registry.js';\n\n/**\n * Options for Entity decorator\n */\nexport interface EntityOptions {\n /**\n * Optional name for the entity. Used for discriminated entity deserialization.\n * If not specified, the class name will be used.\n * Must be unique across all entities - conflicts will throw an error.\n */\n name?: string;\n /**\n * Whether this entity represents a collection.\n * Collection entities must have a 'collection' property that is an array.\n * When serialized, collection entities are unwrapped to just their array.\n * When deserialized from an array, the array is wrapped in { collection: [...] }.\n */\n collection?: boolean;\n /**\n * Whether this entity represents a stringifiable value.\n * Stringifiable classes must have a 'value' property that is a string.\n * When serialized, stringifiable instances are unwrapped to just their string.\n * When deserialized from a string, the string is wrapped in { value: \"...\" }.\n */\n stringifiable?: boolean;\n /**\n * The name of the single \"wrapper\" property for entities that act as transparent wrappers.\n * When set, this property name is excluded from error paths during validation.\n * Used by @CollectionEntity ('collection') and @Stringifiable ('value').\n */\n wrapperProperty?: string;\n /**\n * Whether to register this entity in the EntityRegistry.\n * Set to false for dynamic entities to prevent memory leaks.\n * Defaults to true.\n */\n register?: boolean;\n}\n\n/**\n * Decorator that marks a class as an Entity.\n * This allows us to identify entity instances later.\n *\n * @param options - Optional configuration for the entity\n *\n * @example\n * ```typescript\n * @Entity()\n * class User {\n * name: string;\n * }\n *\n * @Entity({ name: 'CustomUser' })\n * class User {\n * name: string;\n * }\n *\n * @Entity({ collection: true })\n * class Tags {\n * @ArrayProperty(() => String)\n * collection: string[];\n * }\n * ```\n */\nexport function Entity(options: EntityOptions = {}): ClassDecorator {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n return function (target: Function) {\n // Store metadata on the class constructor\n Reflect.defineMetadata(ENTITY_METADATA_KEY, true, target);\n\n // Determine the entity name - use provided name or fall back to class name\n const entityName = options.name ?? target.name;\n\n // Register the entity in the global registry (unless explicitly disabled)\n const shouldRegister = options.register !== false;\n if (shouldRegister) {\n EntityRegistry.register(entityName, target);\n }\n\n // Store the name in options for later retrieval\n const optionsWithName = { ...options, name: entityName };\n\n Reflect.defineMetadata(\n ENTITY_OPTIONS_METADATA_KEY,\n optionsWithName,\n target,\n );\n };\n}\n\n/**\n * Decorator that marks a class as a Collection Entity.\n * This is syntax sugar for @Entity({ collection: true }).\n *\n * Collection entities must have a 'collection' property that is an array.\n * When serialized with EntityUtils.toJSON(), they are unwrapped to just the array.\n * When deserialized from an array, the array is wrapped in { collection: [...] }.\n *\n * @example\n * ```typescript\n * @CollectionEntity()\n * class Tags {\n * @ArrayProperty(() => String)\n * readonly collection: string[];\n *\n * constructor(data: { collection: string[] }) {\n * this.collection = data.collection;\n * }\n * }\n *\n * @Entity()\n * class Article {\n * @EntityProperty(() => Tags)\n * tags!: Tags;\n * }\n *\n * const article = new Article(...);\n * const json = EntityUtils.toJSON(article);\n * // { tags: [\"tag1\", \"tag2\"] } - unwrapped to array\n *\n * // Also works when serializing the collection directly:\n * const tagsJson = EntityUtils.toJSON(tags);\n * // [\"tag1\", \"tag2\"] - unwrapped to array\n * ```\n */\nexport function CollectionEntity(\n options: Pick<EntityOptions, 'name'> = {},\n): ClassDecorator {\n return Entity({\n collection: true,\n wrapperProperty: 'collection',\n ...options,\n });\n}\n\n/**\n * Decorator that marks a class as Stringifiable.\n * This is syntax sugar for @Entity({ stringifiable: true }).\n *\n * Stringifiable classes must have a 'value' property that is a string.\n * When serialized with EntityUtils.toJSON(), they are unwrapped to just the string.\n * When deserialized from a string, the string is wrapped in { value: \"...\" }.\n *\n * @example\n * ```typescript\n * @Stringifiable()\n * class UserId {\n * @StringProperty()\n * readonly value: string;\n *\n * constructor(data: { value: string }) {\n * this.value = data.value;\n * }\n * }\n *\n * @Entity()\n * class User {\n * @EntityProperty(() => UserId)\n * id!: UserId;\n * }\n *\n * const user = new User(...);\n * const json = EntityUtils.toJSON(user);\n * // { id: \"user-123\" } - unwrapped to string\n *\n * // Also works when serializing the stringifiable directly:\n * const userId = new UserId({ value: \"user-123\" });\n * const idJson = EntityUtils.toJSON(userId);\n * // \"user-123\" - unwrapped to string\n *\n * // Parse from string:\n * const parsed = await EntityUtils.parse(UserId, \"user-456\");\n * // UserId { value: \"user-456\" }\n * ```\n */\nexport function Stringifiable(\n options: Pick<EntityOptions, 'name'> = {},\n): ClassDecorator {\n return Entity({ stringifiable: true, wrapperProperty: 'value', ...options });\n}\n\n/**\n * Decorator that marks a method as an entity validator.\n * The method should return an array of Problems.\n *\n * @example\n * ```typescript\n * @Entity()\n * class User {\n * @Property({ type: () => String }) firstName!: string;\n * @Property({ type: () => String }) lastName!: string;\n *\n * @EntityValidator()\n * validateNames(): Problem[] {\n * const problems: Problem[] = [];\n * if (this.firstName === this.lastName) {\n * problems.push(new Problem({\n * property: 'firstName',\n * message: 'First and last name cannot be the same'\n * }));\n * }\n * return problems;\n * }\n * }\n * ```\n */\nexport function EntityValidator(): MethodDecorator {\n return (target: object, propertyKey: string | symbol): void => {\n if (typeof propertyKey !== 'string') {\n return;\n }\n\n const existingValidators: string[] =\n Reflect.getOwnMetadata(ENTITY_VALIDATOR_METADATA_KEY, target) || [];\n\n if (!existingValidators.includes(propertyKey)) {\n existingValidators.push(propertyKey);\n }\n\n Reflect.defineMetadata(\n ENTITY_VALIDATOR_METADATA_KEY,\n existingValidators,\n target,\n );\n };\n}\n"],"names":["ENTITY_METADATA_KEY","ENTITY_OPTIONS_METADATA_KEY","ENTITY_VALIDATOR_METADATA_KEY","EntityRegistry","Entity","options","target","Reflect","defineMetadata","entityName","name","shouldRegister","register","optionsWithName","CollectionEntity","collection","wrapperProperty","Stringifiable","stringifiable","EntityValidator","propertyKey","existingValidators","getOwnMetadata","includes","push"],"mappings":"AAAA,SACEA,mBAAmB,EACnBC,2BAA2B,EAC3BC,6BAA6B,QACxB,aAAa;AACpB,SAASC,cAAc,QAAQ,uBAAuB;AAwCtD;;;;;;;;;;;;;;;;;;;;;;;;CAw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269
  */
270
270
  export declare function PassthroughProperty(): PropertyDecorator;
271
+ /**
272
+ * Property options for stringifiable types (types with toString() and static parse())
273
+ * Used internally by StringifiableProperty decorator and EntityProps.Stringifiable helper
274
+ */
275
+ export declare function stringifiablePropertyOptions<T extends {
276
+ equals?(other: T): boolean;
277
+ toString(): string;
278
+ }, C extends CtorLike<T> & {
279
+ parse(value: string): T;
280
+ }>(type: () => C, options?: Omit<PropertyOptions<T, C>, 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'>): PropertyOptions<T, C>;
271
281
  export declare const StringifiableProperty: <T extends {
272
282
  equals?(other: T): boolean;
273
283
  toString(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../src/lib/property.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,OAAO,EACP,KAAK,QAAQ,EAIb,eAAe,EAChB,MAAM,YAAY,CAAC;AAapB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAC/C,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,iBAAiB,CA2EnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,GAAG;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GACA,eAAe,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAwB5C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,iBAA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E,MAAM,GAAG,eAAe,CAAC,GAAG;IACpE,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,GACA,iBAAiB,CAEnB"}
@@ -403,8 +403,12 @@ import { enumValidator, intValidator, minLengthValidator, maxLengthValidator, pa
403
403
  */ export function PassthroughProperty() {
404
404
  return Property(passthroughPropertyOptions());
405
405
  }
406
- export const StringifiableProperty = (type, data = {})=>Property({
407
- ...data,
406
+ /**
407
+ * Property options for stringifiable types (types with toString() and static parse())
408
+ * Used internally by StringifiableProperty decorator and EntityProps.Stringifiable helper
409
+ */ export function stringifiablePropertyOptions(type, options) {
410
+ return {
411
+ ...options,
408
412
  type,
409
413
  equals: (a, b)=>a.equals ? a.equals(b) : a.toString() === b.toString(),
410
414
  serialize: (value)=>value.toString(),
@@ -414,7 +418,9 @@ export const StringifiableProperty = (type, data = {})=>Property({
414
418
  }
415
419
  throw new Error(`Invalid value ${type().name}: ${String(value)}`);
416
420
  }
417
- });
421
+ };
422
+ }
423
+ export const StringifiableProperty = (type, data = {})=>Property(stringifiablePropertyOptions(type, data));
418
424
  export const SerializableProperty = (type, data = {})=>Property({
419
425
  ...data,
420
426
  type,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/property.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-wrapper-object-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { isEqual } from 'lodash-es';\nimport {\n AnyCtor,\n type CtorLike,\n type InstanceOfCtorLike,\n PROPERTY_METADATA_KEY,\n PROPERTY_OPTIONS_METADATA_KEY,\n PropertyOptions,\n} from './types.js';\nimport {\n enumValidator,\n intValidator,\n minLengthValidator,\n maxLengthValidator,\n patternValidator,\n minValidator,\n maxValidator,\n arrayMinLengthValidator,\n arrayMaxLengthValidator,\n} from './validators.js';\n\n/**\n * Property decorator that marks class properties with metadata.\n * This decorator can be used to identify and track properties within classes.\n *\n * @param options - Configuration for the property (type is required)\n *\n * @example\n * class User {\n * @Property({ type: () => String })\n * name: string;\n *\n * @Property({ type: () => String, equals: (a, b) => a.toLowerCase() === b.toLowerCase() })\n * email: string;\n *\n * @Property({ type: () => Number })\n * age: number;\n * }\n */\nexport function Property<T, C extends CtorLike<T>>(\n options: PropertyOptions<T, C>,\n): PropertyDecorator {\n return (target: object, propertyKey: string | symbol): void => {\n if (typeof propertyKey !== 'string') {\n return;\n }\n\n const existingProperties: string[] =\n Reflect.getOwnMetadata(PROPERTY_METADATA_KEY, target) || [];\n\n if (!existingProperties.includes(propertyKey)) {\n existingProperties.push(propertyKey);\n }\n\n Reflect.defineMetadata(PROPERTY_METADATA_KEY, existingProperties, target);\n\n if (options.passthrough === true) {\n if (options.array === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and array: true. Passthrough cannot be combined with array.`,\n );\n }\n if (options.optional === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and optional: true. Passthrough cannot be combined with optional.`,\n );\n }\n if (options.sparse === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and sparse: true. Passthrough cannot be combined with sparse.`,\n );\n }\n if (\n options.serialize !== undefined ||\n options.deserialize !== undefined\n ) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and custom serialize/deserialize functions. Passthrough cannot be combined with serialize or deserialize.`,\n );\n }\n }\n\n if (options.sparse === true && options.array !== true) {\n throw new Error(\n `Property '${propertyKey}' has sparse: true but array is not true. The sparse option only applies to arrays.`,\n );\n }\n\n if (options.arrayValidators && options.array !== true) {\n throw new Error(\n `Property '${propertyKey}' has arrayValidators defined but array is not true. The arrayValidators option only applies to arrays.`,\n );\n }\n\n // Validate serialize/deserialize pairing\n const hasSerialize = options.serialize !== undefined;\n const hasDeserialize = options.deserialize !== undefined;\n if (hasSerialize !== hasDeserialize) {\n throw new Error(\n `Property '${propertyKey}' must define both serialize and deserialize functions, or neither. Found only ${hasSerialize ? 'serialize' : 'deserialize'}.`,\n );\n }\n\n const existingOptions: Record<\n string,\n PropertyOptions<any, any>\n > = Reflect.getOwnMetadata(PROPERTY_OPTIONS_METADATA_KEY, target) || {};\n\n existingOptions[propertyKey] = options;\n\n Reflect.defineMetadata(\n PROPERTY_OPTIONS_METADATA_KEY,\n existingOptions,\n target,\n );\n };\n}\n\n/**\n * Helper decorator for string properties\n * @example\n * class User {\n * @StringProperty()\n * name!: string;\n *\n * @StringProperty({ optional: true })\n * nickname?: string;\n *\n * @StringProperty({ minLength: 3, maxLength: 50 })\n * username!: string;\n *\n * @StringProperty({ pattern: /^[a-z]+$/ })\n * slug!: string;\n * }\n */\n/**\n * Creates property options for a string property with optional validation\n * Used internally by StringProperty decorator and Props.String helper\n */\nexport function stringPropertyOptions(\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'> & {\n minLength?: number;\n maxLength?: number;\n pattern?: RegExp;\n patternMessage?: string;\n },\n): PropertyOptions<string, StringConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.minLength !== undefined) {\n validators.unshift(minLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n validators.unshift(maxLengthValidator(options.maxLength));\n }\n if (options?.pattern !== undefined) {\n validators.unshift(\n patternValidator(options.pattern, options.patternMessage),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, pattern, patternMessage, ...restOptions } =\n options || {};\n\n return {\n ...restOptions,\n type: () => String,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for string properties\n * @example\n * class User {\n * @StringProperty()\n * name!: string;\n *\n * @StringProperty({ optional: true })\n * nickname?: string;\n *\n * @StringProperty({ minLength: 2, maxLength: 50 })\n * username!: string;\n *\n * @StringProperty({ pattern: /^[a-z]+$/, patternMessage: 'Must be lowercase letters only' })\n * slug!: string;\n * }\n */\nexport function StringProperty(\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'> & {\n minLength?: number;\n maxLength?: number;\n pattern?: RegExp;\n patternMessage?: string;\n },\n): PropertyDecorator {\n return Property(stringPropertyOptions(options));\n}\n\n/**\n * Creates property options for an enum property\n * Used internally by EnumProperty decorator and Props.Enum helper\n */\nexport function enumPropertyOptions<T extends Record<string, string>>(\n enumType: T,\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'>,\n): PropertyOptions<string, StringConstructor> {\n const validators = options?.validators\n ? [enumValidator(enumType), ...options.validators]\n : [enumValidator(enumType)];\n\n return { ...options, type: () => String, validators };\n}\n\n/**\n * Helper decorator for enum properties (string enums)\n * Validates that the string value matches one of the enum values\n * @param enumType - The enum object (e.g., MyEnum)\n * @param options - Additional property options\n * @example\n * enum Status {\n * Active = 'active',\n * Inactive = 'inactive'\n * }\n *\n * class User {\n * @EnumProperty(Status)\n * status!: Status;\n *\n * @EnumProperty(Status, { optional: true })\n * previousStatus?: Status;\n * }\n */\nexport function EnumProperty<T extends Record<string, string>>(\n enumType: T,\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(enumPropertyOptions(enumType, options));\n}\n\n/**\n * Creates property options for a number property\n * Used internally by NumberProperty decorator and Props.Number helper\n */\nexport function numberPropertyOptions(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyOptions<number, NumberConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.min !== undefined) {\n validators.unshift(minValidator(options.min));\n }\n if (options?.max !== undefined) {\n validators.unshift(maxValidator(options.max));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { min, max, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type: () => Number,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for number properties\n * @example\n * class User {\n * @NumberProperty()\n * age!: number;\n *\n * @NumberProperty({ optional: true })\n * score?: number;\n *\n * @NumberProperty({ min: 0, max: 100 })\n * percentage!: number;\n * }\n */\nexport function NumberProperty(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyDecorator {\n return Property(numberPropertyOptions(options));\n}\n\n/**\n * Creates property options for an integer property\n * Used internally by IntProperty decorator and Props.Int helper\n */\nexport function intPropertyOptions(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyOptions<number, NumberConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.min !== undefined) {\n validators.unshift(minValidator(options.min));\n }\n if (options?.max !== undefined) {\n validators.unshift(maxValidator(options.max));\n }\n\n validators.unshift(intValidator());\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { min, max, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type: () => Number,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for integer properties\n * Validates that the number is an integer (no decimal places)\n * @example\n * class User {\n * @IntProperty()\n * age!: number;\n *\n * @IntProperty({ optional: true })\n * count?: number;\n *\n * @IntProperty({ min: 0, max: 100 })\n * percentage!: number;\n * }\n */\nexport function IntProperty(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyDecorator {\n return Property(intPropertyOptions(options));\n}\n\n/**\n * Creates property options for a boolean property\n * Used internally by BooleanProperty decorator and Props.Boolean helper\n */\nexport function booleanPropertyOptions(\n options?: Omit<PropertyOptions<boolean, BooleanConstructor>, 'type'>,\n): PropertyOptions<boolean, BooleanConstructor> {\n return { ...options, type: () => Boolean };\n}\n\n/**\n * Helper decorator for boolean properties\n * @example\n * class User {\n * @BooleanProperty()\n * active!: boolean;\n *\n * @BooleanProperty({ optional: true })\n * verified?: boolean;\n * }\n */\nexport function BooleanProperty(\n options?: Omit<PropertyOptions<boolean, BooleanConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(booleanPropertyOptions(options));\n}\n\n/**\n * Creates property options for a Date property\n * Used internally by DateProperty decorator and Props.Date helper\n */\nexport function datePropertyOptions(\n options?: Omit<PropertyOptions<Date, DateConstructor>, 'type'>,\n): PropertyOptions<Date, DateConstructor> {\n return { ...options, type: () => Date };\n}\n\n/**\n * Helper decorator for Date properties\n * @example\n * class User {\n * @DateProperty()\n * createdAt!: Date;\n *\n * @DateProperty({ optional: true })\n * deletedAt?: Date;\n * }\n */\nexport function DateProperty(\n options?: Omit<PropertyOptions<Date, DateConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(datePropertyOptions(options));\n}\n\n/**\n * Creates property options for a BigInt property\n * Used internally by BigIntProperty decorator and Props.BigInt helper\n */\nexport function bigIntPropertyOptions(\n options?: Omit<PropertyOptions<bigint, BigIntConstructor>, 'type'>,\n): PropertyOptions<bigint, BigIntConstructor> {\n return { ...options, type: () => BigInt };\n}\n\n/**\n * Helper decorator for BigInt properties\n * @example\n * class User {\n * @BigIntProperty()\n * id!: bigint;\n *\n * @BigIntProperty({ optional: true })\n * balance?: bigint;\n * }\n */\nexport function BigIntProperty(\n options?: Omit<PropertyOptions<bigint, BigIntConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(bigIntPropertyOptions(options));\n}\n\n/**\n * Creates property options for an entity property\n * Used internally by EntityProperty decorator and Props.Entity helper\n */\nexport function entityPropertyOptions<\n T,\n C extends AnyCtor<T> & { new (data: any): T },\n>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type'>,\n): PropertyOptions<T, C> {\n return { ...options, type };\n}\n\n/**\n * Helper decorator for entity properties\n * @example\n * class User {\n * @EntityProperty(() => Address)\n * address!: Address;\n *\n * @EntityProperty(() => Profile, { optional: true })\n * profile?: Profile;\n * }\n */\nexport function EntityProperty<\n T,\n C extends AnyCtor<T> & { new (data: any): T },\n>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type'>,\n): PropertyDecorator {\n return Property<T, C>(entityPropertyOptions(type, options));\n}\n\n/**\n * Creates property options for an array property\n * Used internally by ArrayProperty decorator and Props.Array helper\n */\nexport function arrayPropertyOptions<T, C extends CtorLike<T>>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type' | 'array'> & {\n minLength?: number;\n maxLength?: number;\n },\n): PropertyOptions<T, C> {\n const validators = [...(options?.arrayValidators || [])];\n\n if (options?.minLength !== undefined) {\n validators.unshift(arrayMinLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n validators.unshift(arrayMaxLengthValidator(options.maxLength));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type,\n array: true,\n arrayValidators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for array properties\n * @example\n * class User {\n * @ArrayProperty(() => String)\n * tags!: string[];\n *\n * @ArrayProperty(() => Phone)\n * phones!: Phone[];\n *\n * @ArrayProperty(() => Number, { optional: true })\n * scores?: number[];\n *\n * @ArrayProperty(() => String, { sparse: true })\n * sparseList!: (string | null)[];\n *\n * @ArrayProperty(() => String, { minLength: 1, maxLength: 10 })\n * limitedList!: string[];\n * }\n */\nexport function ArrayProperty<T, C extends CtorLike<T>>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type' | 'array'> & {\n minLength?: number;\n maxLength?: number;\n },\n): PropertyDecorator {\n const arrayValidators = [...(options?.arrayValidators || [])];\n\n if (options?.minLength !== undefined) {\n arrayValidators.unshift(arrayMinLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n arrayValidators.unshift(arrayMaxLengthValidator(options.maxLength));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, ...restOptions } = options || {};\n\n return Property({\n ...restOptions,\n type,\n array: true,\n arrayValidators: arrayValidators.length > 0 ? arrayValidators : undefined,\n });\n}\n\n/**\n * Creates property options for a passthrough property\n * Used internally by PassthroughProperty decorator and Props.Passthrough helper\n */\nexport function passthroughPropertyOptions(\n options?: Omit<PropertyOptions, 'type' | 'passthrough'>,\n): PropertyOptions {\n return { ...options, type: () => Object, passthrough: true };\n}\n\n/**\n * Helper decorator for passthrough properties that bypass type validation.\n * Use this for generic types like Record<string, unknown>, any, or custom objects.\n * @example\n * class Config {\n * @PassthroughProperty()\n * metadata!: Record<string, unknown>;\n *\n * @PassthroughProperty()\n * customData!: any;\n * }\n */\nexport function PassthroughProperty(): PropertyDecorator {\n return Property(passthroughPropertyOptions());\n}\n\nexport const StringifiableProperty = <\n T extends { equals?(other: T): boolean; toString(): string },\n C extends CtorLike<T> & { parse(value: string): T },\n>(\n type: () => C,\n data: Omit<\n PropertyOptions<T, C>,\n 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'\n > = {},\n): PropertyDecorator =>\n Property<T, C>({\n ...data,\n type,\n equals: (a, b) => (a.equals ? a.equals(b) : a.toString() === b.toString()),\n serialize: (value) => value.toString(),\n deserialize: (value) => {\n if (typeof value === 'string') {\n return type().parse(value) as InstanceOfCtorLike<C>;\n }\n throw new Error(`Invalid value ${type().name}: ${String(value)}`);\n },\n });\n\nexport const SerializableProperty = <\n T extends { equals?(other: T): boolean; toJSON(): unknown },\n C extends CtorLike<T> & { parse(value: unknown): T },\n>(\n type: () => C,\n data: Omit<\n PropertyOptions<T, C>,\n 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'\n > = {},\n) =>\n Property({\n ...data,\n type,\n equals: (a: T, b: T) =>\n a.equals ? a.equals(b) : isEqual(a.toJSON(), b.toJSON()),\n serialize: (value: T) => value.toJSON(),\n deserialize: (value: unknown) => {\n return type().parse(value) as InstanceOfCtorLike<C>;\n },\n });\n\n/**\n * Helper decorator for discriminated entity properties.\n * The entity type is determined at runtime using a discriminator property.\n * Unlike EntityProperty, this does not require the type parameter upfront.\n *\n * @param options - Configuration for the discriminated property\n *\n * @example\n * ```typescript\n * // Define entity types\n * @Entity({ name: 'Circle' })\n * class Circle {\n * @StringProperty() readonly type = 'Circle';\n * @NumberProperty() radius!: number;\n * constructor(data: Partial<Circle>) { Object.assign(this, data); }\n * }\n *\n * @Entity({ name: 'Rectangle' })\n * class Rectangle {\n * @StringProperty() readonly type = 'Rectangle';\n * @NumberProperty() width!: number;\n * @NumberProperty() height!: number;\n * constructor(data: Partial<Rectangle>) { Object.assign(this, data); }\n * }\n *\n * // Use discriminated property\n * @Entity()\n * class Drawing {\n * @DiscriminatedEntityProperty()\n * shape!: Circle | Rectangle;\n *\n * @DiscriminatedEntityProperty({ discriminatorProperty: 'entityType' })\n * item!: BaseItem;\n * }\n *\n * // When serialized, the discriminator is included inline:\n * // { shape: { __type: 'Circle', radius: 5 } }\n *\n * // When deserialized, the discriminator is used to determine the type:\n * const drawing = await EntityUtils.parse(Drawing, {\n * shape: { __type: 'Circle', radius: 5 }\n * });\n * // drawing.shape is a Circle instance\n * ```\n */\n/**\n * Creates property options for a discriminated entity property\n * Used internally by DiscriminatedEntityProperty decorator and EntityProps.DiscriminatedEntity helper\n */\nexport function discriminatedEntityPropertyOptions(\n options?: Omit<PropertyOptions<any, any>, 'type' | 'discriminated'> & {\n discriminatorProperty?: string;\n },\n): PropertyOptions<any, any> {\n const discriminatorProperty = options?.discriminatorProperty ?? '__type';\n\n return {\n ...options,\n discriminated: true,\n discriminatorProperty,\n };\n}\n\nexport function DiscriminatedEntityProperty(\n options?: Omit<PropertyOptions<any, any>, 'type' | 'discriminated'> & {\n discriminatorProperty?: string;\n },\n): PropertyDecorator {\n return Property(discriminatedEntityPropertyOptions(options));\n}\n"],"names":["isEqual","PROPERTY_METADATA_KEY","PROPERTY_OPTIONS_METADATA_KEY","enumValidator","intValidator","minLengthValidator","maxLengthValidator","patternValidator","minValidator","maxValidator","arrayMinLengthValidator","arrayMaxLengthValidator","Property","options","target","propertyKey","existingProperties","Reflect","getOwnMetadata","includes","push","defineMetadata","passthrough","array","Error","optional","sparse","serialize","undefined","deserialize","arrayValidators","hasSerialize","hasDeserialize","existingOptions","stringPropertyOptions","validators","minLength","unshift","maxLength","pattern","patternMessage","restOptions","type","String","length","StringProperty","enumPropertyOptions","enumType","EnumProperty","numberPropertyOptions","min","max","Number","NumberProperty","intPropertyOptions","IntProperty","booleanPropertyOptions","Boolean","BooleanProperty","datePropertyOptions","Date","DateProperty","bigIntPropertyOptions","BigInt","BigIntProperty","entityPropertyOptions","EntityProperty","arrayPropertyOptions","ArrayProperty","passthroughPropertyOptions","Object","PassthroughProperty","StringifiableProperty","data","equals","a","b","toString","value","parse","name","SerializableProperty","toJSON","discriminatedEntityPropertyOptions","discriminatorProperty","discriminated","DiscriminatedEntityProperty"],"mappings":"AAAA,6DAA6D,GAC7D,qDAAqD,GACrD,SAASA,OAAO,QAAQ,YAAY;AACpC,SAIEC,qBAAqB,EACrBC,6BAA6B,QAExB,aAAa;AACpB,SACEC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,YAAY,EACZC,uBAAuB,EACvBC,uBAAuB,QAClB,kBAAkB;AAEzB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC,SACdC,OAA8B;IAE9B,OAAO,CAACC,QAAgBC;QACtB,IAAI,OAAOA,gBAAgB,UAAU;YACnC;QACF;QAEA,MAAMC,qBACJC,QAAQC,cAAc,CAACjB,uBAAuBa,WAAW,EAAE;QAE7D,IAAI,CAACE,mBAAmBG,QAAQ,CAACJ,cAAc;YAC7CC,mBAAmBI,IAAI,CAACL;QAC1B;QAEAE,QAAQI,cAAc,CAACpB,uBAAuBe,oBAAoBF;QAElE,IAAID,QAAQS,WAAW,KAAK,MAAM;YAChC,IAAIT,QAAQU,KAAK,KAAK,MAAM;gBAC1B,MAAM,IAAIC,MACR,CAAC,UAAU,EAAET,YAAY,mFAAmF,CAAC;YAEjH;YACA,IAAIF,QAAQY,QAAQ,KAAK,MAAM;gBAC7B,MAAM,IAAID,MACR,CAAC,UAAU,EAAET,YAAY,yFAAyF,CAAC;YAEvH;YACA,IAAIF,QAAQa,MAAM,KAAK,MAAM;gBAC3B,MAAM,IAAIF,MACR,CAAC,UAAU,EAAET,YAAY,qFAAqF,CAAC;YAE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SAASK,mCACdtE,OAEC;IAED,MAAMuE,wBAAwBvE,SAASuE,yBAAyB;IAEhE,OAAO;QACL,GAAGvE,OAAO;QACVwE,eAAe;QACfD;IACF;AACF;AAEA,OAAO,SAASE,4BACdzE,OAEC;IAED,OAAOD,SAASuE,mCAAmCtE;AACrD"}
1
+ {"version":3,"sources":["../../src/lib/property.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-wrapper-object-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { isEqual } from 'lodash-es';\nimport {\n AnyCtor,\n type CtorLike,\n type InstanceOfCtorLike,\n PROPERTY_METADATA_KEY,\n PROPERTY_OPTIONS_METADATA_KEY,\n PropertyOptions,\n} from './types.js';\nimport {\n enumValidator,\n intValidator,\n minLengthValidator,\n maxLengthValidator,\n patternValidator,\n minValidator,\n maxValidator,\n arrayMinLengthValidator,\n arrayMaxLengthValidator,\n} from './validators.js';\n\n/**\n * Property decorator that marks class properties with metadata.\n * This decorator can be used to identify and track properties within classes.\n *\n * @param options - Configuration for the property (type is required)\n *\n * @example\n * class User {\n * @Property({ type: () => String })\n * name: string;\n *\n * @Property({ type: () => String, equals: (a, b) => a.toLowerCase() === b.toLowerCase() })\n * email: string;\n *\n * @Property({ type: () => Number })\n * age: number;\n * }\n */\nexport function Property<T, C extends CtorLike<T>>(\n options: PropertyOptions<T, C>,\n): PropertyDecorator {\n return (target: object, propertyKey: string | symbol): void => {\n if (typeof propertyKey !== 'string') {\n return;\n }\n\n const existingProperties: string[] =\n Reflect.getOwnMetadata(PROPERTY_METADATA_KEY, target) || [];\n\n if (!existingProperties.includes(propertyKey)) {\n existingProperties.push(propertyKey);\n }\n\n Reflect.defineMetadata(PROPERTY_METADATA_KEY, existingProperties, target);\n\n if (options.passthrough === true) {\n if (options.array === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and array: true. Passthrough cannot be combined with array.`,\n );\n }\n if (options.optional === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and optional: true. Passthrough cannot be combined with optional.`,\n );\n }\n if (options.sparse === true) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and sparse: true. Passthrough cannot be combined with sparse.`,\n );\n }\n if (\n options.serialize !== undefined ||\n options.deserialize !== undefined\n ) {\n throw new Error(\n `Property '${propertyKey}' has passthrough: true and custom serialize/deserialize functions. Passthrough cannot be combined with serialize or deserialize.`,\n );\n }\n }\n\n if (options.sparse === true && options.array !== true) {\n throw new Error(\n `Property '${propertyKey}' has sparse: true but array is not true. The sparse option only applies to arrays.`,\n );\n }\n\n if (options.arrayValidators && options.array !== true) {\n throw new Error(\n `Property '${propertyKey}' has arrayValidators defined but array is not true. The arrayValidators option only applies to arrays.`,\n );\n }\n\n // Validate serialize/deserialize pairing\n const hasSerialize = options.serialize !== undefined;\n const hasDeserialize = options.deserialize !== undefined;\n if (hasSerialize !== hasDeserialize) {\n throw new Error(\n `Property '${propertyKey}' must define both serialize and deserialize functions, or neither. Found only ${hasSerialize ? 'serialize' : 'deserialize'}.`,\n );\n }\n\n const existingOptions: Record<\n string,\n PropertyOptions<any, any>\n > = Reflect.getOwnMetadata(PROPERTY_OPTIONS_METADATA_KEY, target) || {};\n\n existingOptions[propertyKey] = options;\n\n Reflect.defineMetadata(\n PROPERTY_OPTIONS_METADATA_KEY,\n existingOptions,\n target,\n );\n };\n}\n\n/**\n * Helper decorator for string properties\n * @example\n * class User {\n * @StringProperty()\n * name!: string;\n *\n * @StringProperty({ optional: true })\n * nickname?: string;\n *\n * @StringProperty({ minLength: 3, maxLength: 50 })\n * username!: string;\n *\n * @StringProperty({ pattern: /^[a-z]+$/ })\n * slug!: string;\n * }\n */\n/**\n * Creates property options for a string property with optional validation\n * Used internally by StringProperty decorator and Props.String helper\n */\nexport function stringPropertyOptions(\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'> & {\n minLength?: number;\n maxLength?: number;\n pattern?: RegExp;\n patternMessage?: string;\n },\n): PropertyOptions<string, StringConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.minLength !== undefined) {\n validators.unshift(minLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n validators.unshift(maxLengthValidator(options.maxLength));\n }\n if (options?.pattern !== undefined) {\n validators.unshift(\n patternValidator(options.pattern, options.patternMessage),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, pattern, patternMessage, ...restOptions } =\n options || {};\n\n return {\n ...restOptions,\n type: () => String,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for string properties\n * @example\n * class User {\n * @StringProperty()\n * name!: string;\n *\n * @StringProperty({ optional: true })\n * nickname?: string;\n *\n * @StringProperty({ minLength: 2, maxLength: 50 })\n * username!: string;\n *\n * @StringProperty({ pattern: /^[a-z]+$/, patternMessage: 'Must be lowercase letters only' })\n * slug!: string;\n * }\n */\nexport function StringProperty(\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'> & {\n minLength?: number;\n maxLength?: number;\n pattern?: RegExp;\n patternMessage?: string;\n },\n): PropertyDecorator {\n return Property(stringPropertyOptions(options));\n}\n\n/**\n * Creates property options for an enum property\n * Used internally by EnumProperty decorator and Props.Enum helper\n */\nexport function enumPropertyOptions<T extends Record<string, string>>(\n enumType: T,\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'>,\n): PropertyOptions<string, StringConstructor> {\n const validators = options?.validators\n ? [enumValidator(enumType), ...options.validators]\n : [enumValidator(enumType)];\n\n return { ...options, type: () => String, validators };\n}\n\n/**\n * Helper decorator for enum properties (string enums)\n * Validates that the string value matches one of the enum values\n * @param enumType - The enum object (e.g., MyEnum)\n * @param options - Additional property options\n * @example\n * enum Status {\n * Active = 'active',\n * Inactive = 'inactive'\n * }\n *\n * class User {\n * @EnumProperty(Status)\n * status!: Status;\n *\n * @EnumProperty(Status, { optional: true })\n * previousStatus?: Status;\n * }\n */\nexport function EnumProperty<T extends Record<string, string>>(\n enumType: T,\n options?: Omit<PropertyOptions<string, StringConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(enumPropertyOptions(enumType, options));\n}\n\n/**\n * Creates property options for a number property\n * Used internally by NumberProperty decorator and Props.Number helper\n */\nexport function numberPropertyOptions(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyOptions<number, NumberConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.min !== undefined) {\n validators.unshift(minValidator(options.min));\n }\n if (options?.max !== undefined) {\n validators.unshift(maxValidator(options.max));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { min, max, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type: () => Number,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for number properties\n * @example\n * class User {\n * @NumberProperty()\n * age!: number;\n *\n * @NumberProperty({ optional: true })\n * score?: number;\n *\n * @NumberProperty({ min: 0, max: 100 })\n * percentage!: number;\n * }\n */\nexport function NumberProperty(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyDecorator {\n return Property(numberPropertyOptions(options));\n}\n\n/**\n * Creates property options for an integer property\n * Used internally by IntProperty decorator and Props.Int helper\n */\nexport function intPropertyOptions(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyOptions<number, NumberConstructor> {\n const validators = [...(options?.validators || [])];\n\n if (options?.min !== undefined) {\n validators.unshift(minValidator(options.min));\n }\n if (options?.max !== undefined) {\n validators.unshift(maxValidator(options.max));\n }\n\n validators.unshift(intValidator());\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { min, max, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type: () => Number,\n validators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for integer properties\n * Validates that the number is an integer (no decimal places)\n * @example\n * class User {\n * @IntProperty()\n * age!: number;\n *\n * @IntProperty({ optional: true })\n * count?: number;\n *\n * @IntProperty({ min: 0, max: 100 })\n * percentage!: number;\n * }\n */\nexport function IntProperty(\n options?: Omit<PropertyOptions<number, NumberConstructor>, 'type'> & {\n min?: number;\n max?: number;\n },\n): PropertyDecorator {\n return Property(intPropertyOptions(options));\n}\n\n/**\n * Creates property options for a boolean property\n * Used internally by BooleanProperty decorator and Props.Boolean helper\n */\nexport function booleanPropertyOptions(\n options?: Omit<PropertyOptions<boolean, BooleanConstructor>, 'type'>,\n): PropertyOptions<boolean, BooleanConstructor> {\n return { ...options, type: () => Boolean };\n}\n\n/**\n * Helper decorator for boolean properties\n * @example\n * class User {\n * @BooleanProperty()\n * active!: boolean;\n *\n * @BooleanProperty({ optional: true })\n * verified?: boolean;\n * }\n */\nexport function BooleanProperty(\n options?: Omit<PropertyOptions<boolean, BooleanConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(booleanPropertyOptions(options));\n}\n\n/**\n * Creates property options for a Date property\n * Used internally by DateProperty decorator and Props.Date helper\n */\nexport function datePropertyOptions(\n options?: Omit<PropertyOptions<Date, DateConstructor>, 'type'>,\n): PropertyOptions<Date, DateConstructor> {\n return { ...options, type: () => Date };\n}\n\n/**\n * Helper decorator for Date properties\n * @example\n * class User {\n * @DateProperty()\n * createdAt!: Date;\n *\n * @DateProperty({ optional: true })\n * deletedAt?: Date;\n * }\n */\nexport function DateProperty(\n options?: Omit<PropertyOptions<Date, DateConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(datePropertyOptions(options));\n}\n\n/**\n * Creates property options for a BigInt property\n * Used internally by BigIntProperty decorator and Props.BigInt helper\n */\nexport function bigIntPropertyOptions(\n options?: Omit<PropertyOptions<bigint, BigIntConstructor>, 'type'>,\n): PropertyOptions<bigint, BigIntConstructor> {\n return { ...options, type: () => BigInt };\n}\n\n/**\n * Helper decorator for BigInt properties\n * @example\n * class User {\n * @BigIntProperty()\n * id!: bigint;\n *\n * @BigIntProperty({ optional: true })\n * balance?: bigint;\n * }\n */\nexport function BigIntProperty(\n options?: Omit<PropertyOptions<bigint, BigIntConstructor>, 'type'>,\n): PropertyDecorator {\n return Property(bigIntPropertyOptions(options));\n}\n\n/**\n * Creates property options for an entity property\n * Used internally by EntityProperty decorator and Props.Entity helper\n */\nexport function entityPropertyOptions<\n T,\n C extends AnyCtor<T> & { new (data: any): T },\n>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type'>,\n): PropertyOptions<T, C> {\n return { ...options, type };\n}\n\n/**\n * Helper decorator for entity properties\n * @example\n * class User {\n * @EntityProperty(() => Address)\n * address!: Address;\n *\n * @EntityProperty(() => Profile, { optional: true })\n * profile?: Profile;\n * }\n */\nexport function EntityProperty<\n T,\n C extends AnyCtor<T> & { new (data: any): T },\n>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type'>,\n): PropertyDecorator {\n return Property<T, C>(entityPropertyOptions(type, options));\n}\n\n/**\n * Creates property options for an array property\n * Used internally by ArrayProperty decorator and Props.Array helper\n */\nexport function arrayPropertyOptions<T, C extends CtorLike<T>>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type' | 'array'> & {\n minLength?: number;\n maxLength?: number;\n },\n): PropertyOptions<T, C> {\n const validators = [...(options?.arrayValidators || [])];\n\n if (options?.minLength !== undefined) {\n validators.unshift(arrayMinLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n validators.unshift(arrayMaxLengthValidator(options.maxLength));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, ...restOptions } = options || {};\n\n return {\n ...restOptions,\n type,\n array: true,\n arrayValidators: validators.length > 0 ? validators : undefined,\n };\n}\n\n/**\n * Helper decorator for array properties\n * @example\n * class User {\n * @ArrayProperty(() => String)\n * tags!: string[];\n *\n * @ArrayProperty(() => Phone)\n * phones!: Phone[];\n *\n * @ArrayProperty(() => Number, { optional: true })\n * scores?: number[];\n *\n * @ArrayProperty(() => String, { sparse: true })\n * sparseList!: (string | null)[];\n *\n * @ArrayProperty(() => String, { minLength: 1, maxLength: 10 })\n * limitedList!: string[];\n * }\n */\nexport function ArrayProperty<T, C extends CtorLike<T>>(\n type: () => C,\n options?: Omit<PropertyOptions<T, C>, 'type' | 'array'> & {\n minLength?: number;\n maxLength?: number;\n },\n): PropertyDecorator {\n const arrayValidators = [...(options?.arrayValidators || [])];\n\n if (options?.minLength !== undefined) {\n arrayValidators.unshift(arrayMinLengthValidator(options.minLength));\n }\n if (options?.maxLength !== undefined) {\n arrayValidators.unshift(arrayMaxLengthValidator(options.maxLength));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { minLength, maxLength, ...restOptions } = options || {};\n\n return Property({\n ...restOptions,\n type,\n array: true,\n arrayValidators: arrayValidators.length > 0 ? arrayValidators : undefined,\n });\n}\n\n/**\n * Creates property options for a passthrough property\n * Used internally by PassthroughProperty decorator and Props.Passthrough helper\n */\nexport function passthroughPropertyOptions(\n options?: Omit<PropertyOptions, 'type' | 'passthrough'>,\n): PropertyOptions {\n return { ...options, type: () => Object, passthrough: true };\n}\n\n/**\n * Helper decorator for passthrough properties that bypass type validation.\n * Use this for generic types like Record<string, unknown>, any, or custom objects.\n * @example\n * class Config {\n * @PassthroughProperty()\n * metadata!: Record<string, unknown>;\n *\n * @PassthroughProperty()\n * customData!: any;\n * }\n */\nexport function PassthroughProperty(): PropertyDecorator {\n return Property(passthroughPropertyOptions());\n}\n\n/**\n * Property options for stringifiable types (types with toString() and static parse())\n * Used internally by StringifiableProperty decorator and EntityProps.Stringifiable helper\n */\nexport function stringifiablePropertyOptions<\n T extends { equals?(other: T): boolean; toString(): string },\n C extends CtorLike<T> & { parse(value: string): T },\n>(\n type: () => C,\n options?: Omit<\n PropertyOptions<T, C>,\n 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'\n >,\n): PropertyOptions<T, C> {\n return {\n ...options,\n type,\n equals: (a, b) => (a.equals ? a.equals(b) : a.toString() === b.toString()),\n serialize: (value) => value.toString(),\n deserialize: (value) => {\n if (typeof value === 'string') {\n return type().parse(value) as InstanceOfCtorLike<C>;\n }\n throw new Error(`Invalid value ${type().name}: ${String(value)}`);\n },\n };\n}\n\nexport const StringifiableProperty = <\n T extends { equals?(other: T): boolean; toString(): string },\n C extends CtorLike<T> & { parse(value: string): T },\n>(\n type: () => C,\n data: Omit<\n PropertyOptions<T, C>,\n 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'\n > = {},\n): PropertyDecorator =>\n Property<T, C>(stringifiablePropertyOptions(type, data));\n\nexport const SerializableProperty = <\n T extends { equals?(other: T): boolean; toJSON(): unknown },\n C extends CtorLike<T> & { parse(value: unknown): T },\n>(\n type: () => C,\n data: Omit<\n PropertyOptions<T, C>,\n 'serialize' | 'deserialize' | 'passthrough' | 'type' | 'equals'\n > = {},\n) =>\n Property({\n ...data,\n type,\n equals: (a: T, b: T) =>\n a.equals ? a.equals(b) : isEqual(a.toJSON(), b.toJSON()),\n serialize: (value: T) => value.toJSON(),\n deserialize: (value: unknown) => {\n return type().parse(value) as InstanceOfCtorLike<C>;\n },\n });\n\n/**\n * Helper decorator for discriminated entity properties.\n * The entity type is determined at runtime using a discriminator property.\n * Unlike EntityProperty, this does not require the type parameter upfront.\n *\n * @param options - Configuration for the discriminated property\n *\n * @example\n * ```typescript\n * // Define entity types\n * @Entity({ name: 'Circle' })\n * class Circle {\n * @StringProperty() readonly type = 'Circle';\n * @NumberProperty() radius!: number;\n * constructor(data: Partial<Circle>) { Object.assign(this, data); }\n * }\n *\n * @Entity({ name: 'Rectangle' })\n * class Rectangle {\n * @StringProperty() readonly type = 'Rectangle';\n * @NumberProperty() width!: number;\n * @NumberProperty() height!: number;\n * constructor(data: Partial<Rectangle>) { Object.assign(this, data); }\n * }\n *\n * // Use discriminated property\n * @Entity()\n * class Drawing {\n * @DiscriminatedEntityProperty()\n * shape!: Circle | Rectangle;\n *\n * @DiscriminatedEntityProperty({ discriminatorProperty: 'entityType' })\n * item!: BaseItem;\n * }\n *\n * // When serialized, the discriminator is included inline:\n * // { shape: { __type: 'Circle', radius: 5 } }\n *\n * // When deserialized, the discriminator is used to determine the type:\n * const drawing = await EntityUtils.parse(Drawing, {\n * shape: { __type: 'Circle', radius: 5 }\n * });\n * // drawing.shape is a Circle instance\n * ```\n */\n/**\n * Creates property options for a discriminated entity property\n * Used internally by DiscriminatedEntityProperty decorator and EntityProps.DiscriminatedEntity helper\n */\nexport function discriminatedEntityPropertyOptions(\n options?: Omit<PropertyOptions<any, any>, 'type' | 'discriminated'> & {\n discriminatorProperty?: string;\n },\n): PropertyOptions<any, any> {\n const discriminatorProperty = options?.discriminatorProperty ?? '__type';\n\n return {\n ...options,\n discriminated: true,\n discriminatorProperty,\n };\n}\n\nexport function DiscriminatedEntityProperty(\n options?: Omit<PropertyOptions<any, any>, 'type' | 'discriminated'> & {\n discriminatorProperty?: string;\n },\n): PropertyDecorator {\n return Property(discriminatedEntityPropertyOptions(options));\n}\n"],"names":["isEqual","PROPERTY_METADATA_KEY","PROPERTY_OPTIONS_METADATA_KEY","enumValidator","intValidator","minLengthValidator","maxLengthValidator","patternValidator","minValidator","maxValidator","arrayMinLengthValidator","arrayMaxLengthValidator","Property","options","target","propertyKey","existingProperties","Reflect","getOwnMetadata","includes","push","defineMetadata","passthrough","array","Error","optional","sparse","serialize","undefined","deserialize","arrayValidators","hasSerialize","hasDeserialize","existingOptions","stringPropertyOptions","validators","minLength","unshift","maxLength","pattern","patternMessage","restOptions","type","String","length","StringProperty","enumPropertyOptions","enumType","EnumProperty","numberPropertyOptions","min","max","Number","NumberProperty","intPropertyOptions","IntProperty","booleanPropertyOptions","Boolean","BooleanProperty","datePropertyOptions","Date","DateProperty","bigIntPropertyOptions","BigInt","BigIntProperty","entityPropertyOptions","EntityProperty","arrayPropertyOptions","ArrayProperty","passthroughPropertyOptions","Object","PassthroughProperty","stringifiablePropertyOptions","equals","a","b","toString","value","parse","name","StringifiableProperty","data","SerializableProperty","toJSON","discriminatedEntityPropertyOptions","discriminatorProperty","discriminated","DiscriminatedEntityProperty"],"mappings":"AAAA,6DAA6D,GAC7D,qDAAqD,GACrD,SAASA,OAAO,QAAQ,YAAY;AACpC,SAIEC,qBAAqB,EACrBC,6BAA6B,QAExB,aAAa;AACpB,SACEC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,YAAY,EACZC,uBAAuB,EACvBC,uBAAuB,QAClB,kBAAkB;AAEzB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC,SACdC,OAA8B;IAE9B,OAAO,CAACC,QAAgBC;QACtB,IAAI,OAAOA,gBAAgB,UAAU;YACnC;QACF;QAEA,MAAMC,qBACJC,QAAQC,cAAc,CAACjB,uBAAuBa,WAAW,EAAE;QAE7D,IAAI,CAACE,mBAAmBG,QAAQ,CAACJ,cAAc;YAC7CC,mBAAmBI,IAAI,CAACL;QAC1B;QAEAE,QAAQI,cAAc,CAACpB,uBAAuBe,oBAAoBF;QAElE,IAAID,QAAQS,WAAW,KAAK,MAAM;YAChC,IAAIT,QAAQU,KAAK,KAAK,MAAM;gBAC1B,MAAM,IAAIC,MACR,CAAC,UAAU,EAAET,YAAY,mFAAmF,CAAC;YAEjH;YACA,IAAIF,QAAQY,QAAQ,KAAK,MAAM;gBAC7B,MAAM,IAAID,MACR,CAAC,UAAU,EAAET,YAAY,yFAAyF,CAAC;YAEvH;YACA,IAAIF,QAAQa,MAAM,KAAK,MAAM;gBAC3B,MAAM,IAAIF,MACR,CAAC,UAAU,EAAET,YAAY,qFAAqF,CAAC;YAEnH;YACA,IACEF,QAAQc,SAAS,KAAKC,aACtBf,QAAQgB,WAAW,KAAKD,WACxB;gBACA,MAAM,IAAIJ,MACR,CAAC,UAAU,EAAET,YAAY,iIAAiI,CAAC;YAE/J;QACF;QAEA,IAAIF,QAAQa,MAAM,KAAK,QAAQb,QAAQU,KAAK,KAAK,MAAM;YACrD,MAAM,IA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,OAAO,SAASE,4BACd1E,OAEC;IAED,OAAOD,SAASwE,mCAAmCvE;AACrD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtpaulino/entity",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",