🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@autometa/dto-builder

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@autometa/dto-builder - npm Package Compare versions

Comparing version
0.13.8
to
0.13.9
+1
-1
dist/esm/index.js

@@ -169,3 +169,2 @@ // src/dto-default.decorator.ts

function classProxy(defaults, built, inst) {
const instance = constructDefaultDto(defaults);
const clsBuilder = new Proxy(inst, {

@@ -175,2 +174,3 @@ get(_, prop) {

return () => {
const instance = constructDefaultDto(defaults);
return Object.assign(instance, { ...built });

@@ -177,0 +177,0 @@ };

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../src/dto-default.decorator.ts","../../src/property.enum.ts","../../src/property.decorator.ts","../../src/dto.ts","../../src/interface-proxy.ts"],"sourcesContent":["import { metadata } from \"@autometa/injection\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport \"any-date-parser\";\n\nexport interface Default {\n value(value: unknown): PropertyDecorator;\n\n factory(factory: (...args: unknown[]) => unknown): PropertyDecorator;\n\n dto(dtoType: Class<unknown>): PropertyDecorator;\n\n date(): PropertyDecorator;\n date(format: string): PropertyDecorator;\n date(stamp: number): PropertyDecorator;\n date(stamp?: string | number): PropertyDecorator;\n}\n\nexport const DefaultValueDecorators: Default = {\n value: (value: unknown) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { value };\n container[propertyKey as string] = datum;\n },\n factory:\n (factory: (...args: unknown[]) => unknown) =>\n (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { factory };\n container[propertyKey as string] = datum;\n },\n dto: (dtoType: Class<unknown>) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { dtoType };\n container[propertyKey as string] = datum;\n },\n date: (stamp?: string | number | undefined) => {\n return (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = {\n factory: () => {\n if (\"number\" === typeof stamp) {\n return new Date(stamp);\n }\n if (!stamp) {\n return new Date();\n }\n return (Date as unknown as { fromString: (s: string) => Date }).fromString(stamp);\n },\n };\n container[propertyKey as string] = datum;\n };\n },\n};\n\nexport function getConstructor(target: unknown) {\n if (target && \"constructor\" in (target as object)) {\n return target.constructor;\n }\n throw new Error(`Cannot get constructor for ${target}`);\n}","const PROPERTY_DEFAULTS: unique symbol = Symbol(\"autometa:meta-data:property-defaults\");\nexport const DtoBuilderSymbols = {\n PROPERTY_DEFAULTS,\n} as const;\n","import { DefaultValueDecorators } from \"./dto-default.decorator\";\nimport type { Class } from \"./types\";\n\n/**\n * \n * @param defaultValue \n * \n * @deprecated Use `@DTO.value`, `@DTO.factory` and `@DTO.dto` instead\n */\nexport function Property<T extends () => unknown>(defaultValue: T): PropertyDecorator;\nexport function Property<T>(defaultValue: T): PropertyDecorator;\nexport function Property(defaultOrFactory: unknown | (() => unknown)): PropertyDecorator {\n return determineDefaultType(defaultOrFactory);\n}\nfunction determineDefaultType(defaultOrFactory: unknown | Class<unknown> | (() => unknown)): PropertyDecorator {\n if (isClass(defaultOrFactory)) {\n return DefaultValueDecorators.dto(defaultOrFactory);\n }\n\n if (\"function\" === typeof defaultOrFactory) {\n return DefaultValueDecorators.factory(defaultOrFactory as () => unknown);\n }\n\n if (defaultOrFactory instanceof Date.constructor) {\n return DefaultValueDecorators.date();\n }\n\n return DefaultValueDecorators.value(defaultOrFactory);\n}\n\nfunction isClass(value: unknown): value is Class<unknown> {\n if (!(\"function\" != typeof value)) {\n return false;\n }\n\n return /^class[\\s{]/.test(toString.call(value));\n}\n","import { DefaultValueDecorators, Default } from \"./dto-default.decorator\";\nimport { Class } from \"./types\";\n\nexport function DTOWrapper<T extends object>() {\n return class {} as Class<T>;\n}\n\nexport const DTO: typeof DTOWrapper & Default = Object.assign(DTOWrapper, DefaultValueDecorators);\n","import { metadata } from \"@autometa/injection\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nexport type IBuilder<T> = {\n [k in keyof T]-?: ((arg: T[k]) => IBuilder<T>) & (() => T[k]);\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Derive a new builder from the current builder, copying it's\n * current values into a new builder. Allows default values to\n * be set in a copy, which will not be modified by child copies.\n */\n derive(): IBuilder<T>;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): IBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): IBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\nexport type ClsBuilder<T> = {\n [k in keyof T]-?: BuilderMethod<T, T[k]>;\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): ClsBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): ClsBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\n\nexport type BuilderMethod<TTarget, TType> = ((arg: TType) => ClsBuilder<TTarget>) & {\n value: TType;\n};\nexport type DtoBuilder<T> = Class<ClsBuilder<T>> & {\n /**\n * Construct a builder from a raw object or class instance,\n * inheriting any properties that have already been defined.\n * @param value /\n */\n fromRaw(value: Partial<T>): ClsBuilder<T>;\n /**\n * Constructs a DTO, prefilled with any default values\n * assigned to the DTO via either the `Property` decorator\n * or the `DTO.*` decorators.\n *\n * With property:\n *\n * ```ts\n * class FooDto {\n * @Property(1)\n * foo: number;\n * @Property(()=> \"factory string\")\n * bar: string;\n * @Property(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n *\n * With DTO:\n *\n * ```ts\n * class FooDto {\n * @DTO.value(1)\n * foo: number;\n * @DTO.factory(()=> \"factory string\")\n * bar: string;\n * @DTO.dto(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n */\n default(): T;\n};\n\nexport function Builder<T>(cls: Class<T>): DtoBuilder<T>;\nexport function Builder<T>(): IBuilder<T>;\nexport function Builder<T>(defaults?: Partial<T> | Class<T>): IBuilder<T> | DtoBuilder<T> {\n if (isClassBuilder(defaults)) {\n return class BuilderClass<TType> {\n constructor() {\n const built: Record<string, unknown> = { ...defaults };\n const proxy = classProxy.bind(null, defaults as Class<unknown>, built);\n return proxy(this) as BuilderClass<TType>;\n }\n declare build: () => T;\n declare assign: <K>(property: string, value: K) => BuilderClass<TType>;\n static fromRaw(value: T) {\n const builder = new this();\n const keys = Object.keys(value as object) as (keyof T)[];\n for (const key of keys) {\n builder.assign(key.toString(), value[key]);\n }\n return builder;\n }\n\n static default() {\n return new this().build();\n }\n } as DtoBuilder<T>;\n // return clsBuilder as IBuilder<T>;\n }\n const built: Record<string, unknown> = { ...defaults };\n const builder = new Proxy(built, {\n get(target, prop) {\n if (\"build\" === prop) {\n return () => built;\n }\n\n if (\"derive\" === prop) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return () => Builder<T>({ ...built } as any);\n }\n\n if (\"assign\" === prop) {\n return (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return target;\n };\n }\n\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (typeof built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return target;\n };\n }\n\n if (\"append\" === prop) {\n return (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return target;\n };\n }\n\n return (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n\n built[prop.toString()] = args[0];\n return builder;\n };\n },\n });\n\n return builder as IBuilder<T>;\n}\n\nfunction classProxy<T>(defaults: Class<T>, built: Record<string, unknown>, inst: T) {\n const instance = constructDefaultDto(defaults);\n const clsBuilder = new Proxy(inst as object, {\n get(_, prop) {\n if (\"build\" === prop) {\n return () => {\n return Object.assign(instance as object, { ...built });\n };\n }\n if (\"assign\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"append\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return clsBuilder;\n };\n }\n if ((prop) in (inst as Record<string, unknown>)) {\n return (inst as Record<string, unknown>)[prop as string];\n }\n const fn = (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n built[prop.toString()] = args[0];\n return clsBuilder;\n };\n const modified = Object.defineProperty(fn, \"value\", {\n get() {\n return built[prop.toString()];\n },\n });\n return modified;\n },\n });\n return clsBuilder as ClsBuilder<T>;\n}\n\nfunction isClassBuilder<T>(cls: unknown): cls is Class<T> {\n return \"function\" === typeof cls;\n}\n\nfunction constructDefaultDto<T>(base: Class<T>): T {\n const defaultSetters = metadata(base).getCustom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS\n );\n const instance = new base();\n if (!defaultSetters) {\n return instance;\n }\n const keys = Object.keys(defaultSetters) as unknown as (keyof typeof instance)[] &\n (keyof typeof defaultSetters)[];\n\n for (const key of keys) {\n const value = defaultSetters[key];\n if (\"value\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.value,\n writable: true,\n enumerable: true,\n });\n }\n if (\"factory\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.factory(),\n writable: true,\n enumerable: true,\n });\n }\n if (\"dtoType\" in value) {\n const dtoInst = constructDefaultDto(value.dtoType);\n Object.defineProperty(instance as object, key, {\n value: dtoInst,\n writable: true,\n enumerable: true,\n });\n }\n }\n return instance;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,IAAM,oBAAmC,OAAO,sCAAsC;AAC/E,IAAM,oBAAoB;AAAA,EAC/B;AACF;;;ADAA,OAAO;AAeA,IAAM,yBAAkC;AAAA,E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,MAAM;AACJ,iBAAO,MAAM,KAAK,SAAS,CAAC;AAAA,QAC9B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEA,SAAS,eAAkB,KAA+B;AACxD,SAAO,eAAe,OAAO;AAC/B;AAEA,SAAS,oBAAuB,MAAmB;AACjD,QAAM,iBAAiBC,UAAS,IAAI,EAAE;AAAA,IACpC,kBAAkB;AAAA,EACpB;AACA,QAAM,WAAW,IAAI,KAAK;AAC1B,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,OAAO,KAAK,cAAc;AAGvC,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,eAAe,GAAG;AAChC,QAAI,WAAW,OAAO;AACpB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM;AAAA,QACb,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM,QAAQ;AAAA,QACrB,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,YAAM,UAAU,oBAAoB,MAAM,OAAO;AACjD,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;","names":["metadata","built","builder","fn","metadata"]}
{"version":3,"sources":["../../src/dto-default.decorator.ts","../../src/property.enum.ts","../../src/property.decorator.ts","../../src/dto.ts","../../src/interface-proxy.ts"],"sourcesContent":["import { metadata } from \"@autometa/injection\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport \"any-date-parser\";\n\nexport interface Default {\n value(value: unknown): PropertyDecorator;\n\n factory(factory: (...args: unknown[]) => unknown): PropertyDecorator;\n\n dto(dtoType: Class<unknown>): PropertyDecorator;\n\n date(): PropertyDecorator;\n date(format: string): PropertyDecorator;\n date(stamp: number): PropertyDecorator;\n date(stamp?: string | number): PropertyDecorator;\n}\n\nexport const DefaultValueDecorators: Default = {\n value: (value: unknown) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { value };\n container[propertyKey as string] = datum;\n },\n factory:\n (factory: (...args: unknown[]) => unknown) =>\n (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { factory };\n container[propertyKey as string] = datum;\n },\n dto: (dtoType: Class<unknown>) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { dtoType };\n container[propertyKey as string] = datum;\n },\n date: (stamp?: string | number | undefined) => {\n return (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = {\n factory: () => {\n if (\"number\" === typeof stamp) {\n return new Date(stamp);\n }\n if (!stamp) {\n return new Date();\n }\n return (Date as unknown as { fromString: (s: string) => Date }).fromString(stamp);\n },\n };\n container[propertyKey as string] = datum;\n };\n },\n};\n\nexport function getConstructor(target: unknown) {\n if (target && \"constructor\" in (target as object)) {\n return target.constructor;\n }\n throw new Error(`Cannot get constructor for ${target}`);\n}","const PROPERTY_DEFAULTS: unique symbol = Symbol(\"autometa:meta-data:property-defaults\");\nexport const DtoBuilderSymbols = {\n PROPERTY_DEFAULTS,\n} as const;\n","import { DefaultValueDecorators } from \"./dto-default.decorator\";\nimport type { Class } from \"./types\";\n\n/**\n * \n * @param defaultValue \n * \n * @deprecated Use `@DTO.value`, `@DTO.factory` and `@DTO.dto` instead\n */\nexport function Property<T extends () => unknown>(defaultValue: T): PropertyDecorator;\nexport function Property<T>(defaultValue: T): PropertyDecorator;\nexport function Property(defaultOrFactory: unknown | (() => unknown)): PropertyDecorator {\n return determineDefaultType(defaultOrFactory);\n}\nfunction determineDefaultType(defaultOrFactory: unknown | Class<unknown> | (() => unknown)): PropertyDecorator {\n if (isClass(defaultOrFactory)) {\n return DefaultValueDecorators.dto(defaultOrFactory);\n }\n\n if (\"function\" === typeof defaultOrFactory) {\n return DefaultValueDecorators.factory(defaultOrFactory as () => unknown);\n }\n\n if (defaultOrFactory instanceof Date.constructor) {\n return DefaultValueDecorators.date();\n }\n\n return DefaultValueDecorators.value(defaultOrFactory);\n}\n\nfunction isClass(value: unknown): value is Class<unknown> {\n if (!(\"function\" != typeof value)) {\n return false;\n }\n\n return /^class[\\s{]/.test(toString.call(value));\n}\n","import { DefaultValueDecorators, Default } from \"./dto-default.decorator\";\nimport { Class } from \"./types\";\n\nexport function DTOWrapper<T extends object>() {\n return class {} as Class<T>;\n}\n\nexport const DTO: typeof DTOWrapper & Default = Object.assign(DTOWrapper, DefaultValueDecorators);\n","import { metadata } from \"@autometa/injection\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nexport type IBuilder<T> = {\n [k in keyof T]-?: ((arg: T[k]) => IBuilder<T>) & (() => T[k]);\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Derive a new builder from the current builder, copying it's\n * current values into a new builder. Allows default values to\n * be set in a copy, which will not be modified by child copies.\n */\n derive(): IBuilder<T>;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): IBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): IBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\nexport type ClsBuilder<T> = {\n [k in keyof T]-?: BuilderMethod<T, T[k]>;\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): ClsBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): ClsBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\n\nexport type BuilderMethod<TTarget, TType> = ((arg: TType) => ClsBuilder<TTarget>) & {\n value: TType;\n};\nexport type DtoBuilder<T> = Class<ClsBuilder<T>> & {\n /**\n * Construct a builder from a raw object or class instance,\n * inheriting any properties that have already been defined.\n * @param value /\n */\n fromRaw(value: Partial<T>): ClsBuilder<T>;\n /**\n * Constructs a DTO, prefilled with any default values\n * assigned to the DTO via either the `Property` decorator\n * or the `DTO.*` decorators.\n *\n * With property:\n *\n * ```ts\n * class FooDto {\n * @Property(1)\n * foo: number;\n * @Property(()=> \"factory string\")\n * bar: string;\n * @Property(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n *\n * With DTO:\n *\n * ```ts\n * class FooDto {\n * @DTO.value(1)\n * foo: number;\n * @DTO.factory(()=> \"factory string\")\n * bar: string;\n * @DTO.dto(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n */\n default(): T;\n};\n\nexport function Builder<T>(cls: Class<T>): DtoBuilder<T>;\nexport function Builder<T>(): IBuilder<T>;\nexport function Builder<T>(defaults?: Partial<T> | Class<T>): IBuilder<T> | DtoBuilder<T> {\n if (isClassBuilder(defaults)) {\n return class BuilderClass<TType> {\n constructor() {\n const built: Record<string, unknown> = { ...defaults };\n const proxy = classProxy.bind(null, defaults as Class<unknown>, built);\n return proxy(this) as BuilderClass<TType>;\n }\n declare build: () => T;\n declare assign: <K>(property: string, value: K) => BuilderClass<TType>;\n static fromRaw(value: T) {\n const builder = new this();\n const keys = Object.keys(value as object) as (keyof T)[];\n for (const key of keys) {\n builder.assign(key.toString(), value[key]);\n }\n return builder;\n }\n\n static default() {\n return new this().build();\n }\n } as DtoBuilder<T>;\n // return clsBuilder as IBuilder<T>;\n }\n const built: Record<string, unknown> = { ...defaults };\n const builder = new Proxy(built, {\n get(target, prop) {\n if (\"build\" === prop) {\n return () => built;\n }\n\n if (\"derive\" === prop) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return () => Builder<T>({ ...built } as any);\n }\n\n if (\"assign\" === prop) {\n return (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return target;\n };\n }\n\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (typeof built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return target;\n };\n }\n\n if (\"append\" === prop) {\n return (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return target;\n };\n }\n\n return (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n\n built[prop.toString()] = args[0];\n return builder;\n };\n },\n });\n\n return builder as IBuilder<T>;\n}\n\nfunction classProxy<T>(defaults: Class<T>, built: Record<string, unknown>, inst: T) {\n const clsBuilder = new Proxy(inst as object, {\n get(_, prop) {\n if (\"build\" === prop) {\n return () => {\n const instance = constructDefaultDto(defaults);\n return Object.assign(instance as object, { ...built });\n };\n }\n if (\"assign\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"append\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return clsBuilder;\n };\n }\n if (prop in (inst as Record<string, unknown>)) {\n return (inst as Record<string, unknown>)[prop as string];\n }\n const fn = (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n built[prop.toString()] = args[0];\n return clsBuilder;\n };\n const modified = Object.defineProperty(fn, \"value\", {\n get() {\n return built[prop.toString()];\n },\n });\n return modified;\n },\n });\n return clsBuilder as ClsBuilder<T>;\n}\n\nfunction isClassBuilder<T>(cls: unknown): cls is Class<T> {\n return \"function\" === typeof cls;\n}\n\nfunction constructDefaultDto<T>(base: Class<T>): T {\n const defaultSetters = metadata(base).getCustom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS\n );\n const instance = new base();\n if (!defaultSetters) {\n return instance;\n }\n const keys = Object.keys(defaultSetters) as unknown as (keyof typeof instance)[] &\n (keyof typeof defaultSetters)[];\n\n for (const key of keys) {\n const value = defaultSetters[key];\n if (\"value\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.value,\n writable: true,\n enumerable: true,\n });\n }\n if (\"factory\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.factory(),\n writable: true,\n enumerable: true,\n });\n }\n if (\"dtoType\" in value) {\n const dtoInst = constructDefaultDto(value.dtoType);\n Object.defineProperty(instance as object, key, {\n value: dtoInst,\n writable: true,\n enumerable: true,\n });\n }\n }\n return instance;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,IAAM,oBAAmC,OAAO,sCAAsC;AAC/E,IAAM,oBAAoB;AAAA,EAC/B;AACF;;;ADAA,OAAO;AAeA,IAAM,yBAAkC;AAAA,EAC7C,OAAO,CAAC,UAAmB,CAAC,QAAgB,gBAAiC;AAC3E,UAAM,YAAY,SAAS,eAAe,MAAM,CAAC,EAAE;AAAA,MACjD,kBAAkB;AAAA,MAClB,CAAC;AAAA,MACD;AAAA,IACF;AACA,UAAM,QAAQ,EAAE,MAAM;AACtB,cAAU,WAAqB,IAAI;AAAA,EACrC;AAAA,EACA,SACE,CAAC,YACD,CAAC,QAAgB,gBAAiC;AAChD,UAAM,YAAY,SAAS,eAAe,MAAM,CAAC,EAAE;AAAA,MACjD,kBAAkB;AAAA,MAClB,CAAC;AAAA,MACD;AAAA,IACF;AACA,UAAM,QAAQ,EAAE,QAAQ;AACxB,cAAU,WAAqB,IAAI;AAAA,EACrC;AAAA,EACF,KAAK,CAAC,YAA4B,CAAC,QAAgB,gBAAiC;AAClF,UAAM,YAAY,SAAS,eAAe,MAAM,CAAC,EAAE;AAAA,MACjD,kBAAkB;AAAA,MAClB,CAAC;AAAA,MACD;AAAA,IACF;AACA,UAAM,QAAQ,EAAE,QAAQ;AACxB,cAAU,WAAqB,IAAI;AAAA,EACrC;AAAA,EACA,MAAM,CAAC,UAAwC;AAC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QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,YAAM,UAAU,oBAAoB,MAAM,OAAO;AACjD,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;","names":["metadata","built","builder","fn","metadata"]}

@@ -197,3 +197,2 @@ "use strict";

function classProxy(defaults, built, inst) {
const instance = constructDefaultDto(defaults);
const clsBuilder = new Proxy(inst, {

@@ -203,2 +202,3 @@ get(_, prop) {

return () => {
const instance = constructDefaultDto(defaults);
return Object.assign(instance, { ...built });

@@ -205,0 +205,0 @@ };

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/index.ts","../src/dto-default.decorator.ts","../src/property.enum.ts","../src/property.decorator.ts","../src/dto.ts","../src/interface-proxy.ts"],"sourcesContent":["export { Property } from './property.decorator'\nexport { DTO } from './dto'\nexport { Builder, DtoBuilder, ClsBuilder } from './interface-proxy'","import { metadata } from \"@autometa/injection\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport \"any-date-parser\";\n\nexport interface Default {\n value(value: unknown): PropertyDecorator;\n\n factory(factory: (...args: unknown[]) => unknown): PropertyDecorator;\n\n dto(dtoType: Class<unknown>): PropertyDecorator;\n\n date(): PropertyDecorator;\n date(format: string): PropertyDecorator;\n date(stamp: number): PropertyDecorator;\n date(stamp?: string | number): PropertyDecorator;\n}\n\nexport const DefaultValueDecorators: Default = {\n value: (value: unknown) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { value };\n container[propertyKey as string] = datum;\n },\n factory:\n (factory: (...args: unknown[]) => unknown) =>\n (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { factory };\n container[propertyKey as string] = datum;\n },\n dto: (dtoType: Class<unknown>) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { dtoType };\n container[propertyKey as string] = datum;\n },\n date: (stamp?: string | number | undefined) => {\n return (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = {\n factory: () => {\n if (\"number\" === typeof stamp) {\n return new Date(stamp);\n }\n if (!stamp) {\n return new Date();\n }\n return (Date as unknown as { fromString: (s: string) => Date }).fromString(stamp);\n },\n };\n container[propertyKey as string] = datum;\n };\n },\n};\n\nexport function getConstructor(target: unknown) {\n if (target && \"constructor\" in (target as object)) {\n return target.constructor;\n }\n throw new Error(`Cannot get constructor for ${target}`);\n}","const PROPERTY_DEFAULTS: unique symbol = Symbol(\"autometa:meta-data:property-defaults\");\nexport const DtoBuilderSymbols = {\n PROPERTY_DEFAULTS,\n} as const;\n","import { DefaultValueDecorators } from \"./dto-default.decorator\";\nimport type { Class } from \"./types\";\n\n/**\n * \n * @param defaultValue \n * \n * @deprecated Use `@DTO.value`, `@DTO.factory` and `@DTO.dto` instead\n */\nexport function Property<T extends () => unknown>(defaultValue: T): PropertyDecorator;\nexport function Property<T>(defaultValue: T): PropertyDecorator;\nexport function Property(defaultOrFactory: unknown | (() => unknown)): PropertyDecorator {\n return determineDefaultType(defaultOrFactory);\n}\nfunction determineDefaultType(defaultOrFactory: unknown | Class<unknown> | (() => unknown)): PropertyDecorator {\n if (isClass(defaultOrFactory)) {\n return DefaultValueDecorators.dto(defaultOrFactory);\n }\n\n if (\"function\" === typeof defaultOrFactory) {\n return DefaultValueDecorators.factory(defaultOrFactory as () => unknown);\n }\n\n if (defaultOrFactory instanceof Date.constructor) {\n return DefaultValueDecorators.date();\n }\n\n return DefaultValueDecorators.value(defaultOrFactory);\n}\n\nfunction isClass(value: unknown): value is Class<unknown> {\n if (!(\"function\" != typeof value)) {\n return false;\n }\n\n return /^class[\\s{]/.test(toString.call(value));\n}\n","import { DefaultValueDecorators, Default } from \"./dto-default.decorator\";\nimport { Class } from \"./types\";\n\nexport function DTOWrapper<T extends object>() {\n return class {} as Class<T>;\n}\n\nexport const DTO: typeof DTOWrapper & Default = Object.assign(DTOWrapper, DefaultValueDecorators);\n","import { metadata } from \"@autometa/injection\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nexport type IBuilder<T> = {\n [k in keyof T]-?: ((arg: T[k]) => IBuilder<T>) & (() => T[k]);\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Derive a new builder from the current builder, copying it's\n * current values into a new builder. Allows default values to\n * be set in a copy, which will not be modified by child copies.\n */\n derive(): IBuilder<T>;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): IBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): IBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\nexport type ClsBuilder<T> = {\n [k in keyof T]-?: BuilderMethod<T, T[k]>;\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): ClsBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): ClsBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\n\nexport type BuilderMethod<TTarget, TType> = ((arg: TType) => ClsBuilder<TTarget>) & {\n value: TType;\n};\nexport type DtoBuilder<T> = Class<ClsBuilder<T>> & {\n /**\n * Construct a builder from a raw object or class instance,\n * inheriting any properties that have already been defined.\n * @param value /\n */\n fromRaw(value: Partial<T>): ClsBuilder<T>;\n /**\n * Constructs a DTO, prefilled with any default values\n * assigned to the DTO via either the `Property` decorator\n * or the `DTO.*` decorators.\n *\n * With property:\n *\n * ```ts\n * class FooDto {\n * @Property(1)\n * foo: number;\n * @Property(()=> \"factory string\")\n * bar: string;\n * @Property(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n *\n * With DTO:\n *\n * ```ts\n * class FooDto {\n * @DTO.value(1)\n * foo: number;\n * @DTO.factory(()=> \"factory string\")\n * bar: string;\n * @DTO.dto(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n */\n default(): T;\n};\n\nexport function Builder<T>(cls: Class<T>): DtoBuilder<T>;\nexport function Builder<T>(): IBuilder<T>;\nexport function Builder<T>(defaults?: Partial<T> | Class<T>): IBuilder<T> | DtoBuilder<T> {\n if (isClassBuilder(defaults)) {\n return class BuilderClass<TType> {\n constructor() {\n const built: Record<string, unknown> = { ...defaults };\n const proxy = classProxy.bind(null, defaults as Class<unknown>, built);\n return proxy(this) as BuilderClass<TType>;\n }\n declare build: () => T;\n declare assign: <K>(property: string, value: K) => BuilderClass<TType>;\n static fromRaw(value: T) {\n const builder = new this();\n const keys = Object.keys(value as object) as (keyof T)[];\n for (const key of keys) {\n builder.assign(key.toString(), value[key]);\n }\n return builder;\n }\n\n static default() {\n return new this().build();\n }\n } as DtoBuilder<T>;\n // return clsBuilder as IBuilder<T>;\n }\n const built: Record<string, unknown> = { ...defaults };\n const builder = new Proxy(built, {\n get(target, prop) {\n if (\"build\" === prop) {\n return () => built;\n }\n\n if (\"derive\" === prop) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return () => Builder<T>({ ...built } as any);\n }\n\n if (\"assign\" === prop) {\n return (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return target;\n };\n }\n\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (typeof built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return target;\n };\n }\n\n if (\"append\" === prop) {\n return (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return target;\n };\n }\n\n return (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n\n built[prop.toString()] = args[0];\n return builder;\n };\n },\n });\n\n return builder as IBuilder<T>;\n}\n\nfunction classProxy<T>(defaults: Class<T>, built: Record<string, unknown>, inst: T) {\n const instance = constructDefaultDto(defaults);\n const clsBuilder = new Proxy(inst as object, {\n get(_, prop) {\n if (\"build\" === prop) {\n return () => {\n return Object.assign(instance as object, { ...built });\n };\n }\n if (\"assign\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"append\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return clsBuilder;\n };\n }\n if ((prop) in (inst as Record<string, unknown>)) {\n return (inst as Record<string, unknown>)[prop as string];\n }\n const fn = (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n built[prop.toString()] = args[0];\n return clsBuilder;\n };\n const modified = Object.defineProperty(fn, \"value\", {\n get() {\n return built[prop.toString()];\n },\n });\n return modified;\n },\n });\n return clsBuilder as ClsBuilder<T>;\n}\n\nfunction isClassBuilder<T>(cls: unknown): cls is Class<T> {\n return \"function\" === typeof cls;\n}\n\nfunction constructDefaultDto<T>(base: Class<T>): T {\n const defaultSetters = metadata(base).getCustom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS\n );\n const instance = new base();\n if (!defaultSetters) {\n return instance;\n }\n const keys = Object.keys(defaultSetters) as unknown as (keyof typeof instance)[] &\n (keyof typeof defaultSetters)[];\n\n for (const key of keys) {\n const value = defaultSetters[key];\n if (\"value\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.value,\n writable: true,\n enumerable: true,\n });\n }\n if (\"factory\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.factory(),\n writable: true,\n enumerable: true,\n });\n }\n if (\"dtoType\" in value) {\n const dtoInst = constructDefaultDto(value.dtoType);\n Object.defineProperty(instance as object, key, {\n value: dtoInst,\n writable: true,\n enumerable: true,\n });\n }\n }\n return instance;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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iBAAO,MAAM,KAAK,SAAS,CAAC;AAAA,QAC9B;AACA,cAAM,KAAK,SAAS,CAAC,IAAI,KAAK,CAAC;AAC/B,eAAO;AAAA,MACT;AACA,YAAM,WAAW,OAAO,eAAe,IAAI,SAAS;AAAA,QAClD,MAAM;AACJ,iBAAO,MAAM,KAAK,SAAS,CAAC;AAAA,QAC9B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEA,SAAS,eAAkB,KAA+B;AACxD,SAAO,eAAe,OAAO;AAC/B;AAEA,SAAS,oBAAuB,MAAmB;AACjD,QAAM,qBAAiB,4BAAS,IAAI,EAAE;AAAA,IACpC,kBAAkB;AAAA,EACpB;AACA,QAAM,WAAW,IAAI,KAAK;AAC1B,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,OAAO,KAAK,cAAc;AAGvC,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,eAAe,GAAG;AAChC,QAAI,WAAW,OAAO;AACpB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM;AAAA,QACb,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM,QAAQ;AAAA,QACrB,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,YAAM,UAAU,oBAAoB,MAAM,OAAO;AACjD,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;","names":["import_injection","built","builder","fn"]}
{"version":3,"sources":["../src/index.ts","../src/dto-default.decorator.ts","../src/property.enum.ts","../src/property.decorator.ts","../src/dto.ts","../src/interface-proxy.ts"],"sourcesContent":["export { Property } from './property.decorator'\nexport { DTO } from './dto'\nexport { Builder, DtoBuilder, ClsBuilder } from './interface-proxy'","import { metadata } from \"@autometa/injection\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport \"any-date-parser\";\n\nexport interface Default {\n value(value: unknown): PropertyDecorator;\n\n factory(factory: (...args: unknown[]) => unknown): PropertyDecorator;\n\n dto(dtoType: Class<unknown>): PropertyDecorator;\n\n date(): PropertyDecorator;\n date(format: string): PropertyDecorator;\n date(stamp: number): PropertyDecorator;\n date(stamp?: string | number): PropertyDecorator;\n}\n\nexport const DefaultValueDecorators: Default = {\n value: (value: unknown) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { value };\n container[propertyKey as string] = datum;\n },\n factory:\n (factory: (...args: unknown[]) => unknown) =>\n (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { factory };\n container[propertyKey as string] = datum;\n },\n dto: (dtoType: Class<unknown>) => (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = { dtoType };\n container[propertyKey as string] = datum;\n },\n date: (stamp?: string | number | undefined) => {\n return (target: object, propertyKey: string | symbol) => {\n const container = metadata(getConstructor(target)).custom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS,\n {},\n false\n );\n const datum = {\n factory: () => {\n if (\"number\" === typeof stamp) {\n return new Date(stamp);\n }\n if (!stamp) {\n return new Date();\n }\n return (Date as unknown as { fromString: (s: string) => Date }).fromString(stamp);\n },\n };\n container[propertyKey as string] = datum;\n };\n },\n};\n\nexport function getConstructor(target: unknown) {\n if (target && \"constructor\" in (target as object)) {\n return target.constructor;\n }\n throw new Error(`Cannot get constructor for ${target}`);\n}","const PROPERTY_DEFAULTS: unique symbol = Symbol(\"autometa:meta-data:property-defaults\");\nexport const DtoBuilderSymbols = {\n PROPERTY_DEFAULTS,\n} as const;\n","import { DefaultValueDecorators } from \"./dto-default.decorator\";\nimport type { Class } from \"./types\";\n\n/**\n * \n * @param defaultValue \n * \n * @deprecated Use `@DTO.value`, `@DTO.factory` and `@DTO.dto` instead\n */\nexport function Property<T extends () => unknown>(defaultValue: T): PropertyDecorator;\nexport function Property<T>(defaultValue: T): PropertyDecorator;\nexport function Property(defaultOrFactory: unknown | (() => unknown)): PropertyDecorator {\n return determineDefaultType(defaultOrFactory);\n}\nfunction determineDefaultType(defaultOrFactory: unknown | Class<unknown> | (() => unknown)): PropertyDecorator {\n if (isClass(defaultOrFactory)) {\n return DefaultValueDecorators.dto(defaultOrFactory);\n }\n\n if (\"function\" === typeof defaultOrFactory) {\n return DefaultValueDecorators.factory(defaultOrFactory as () => unknown);\n }\n\n if (defaultOrFactory instanceof Date.constructor) {\n return DefaultValueDecorators.date();\n }\n\n return DefaultValueDecorators.value(defaultOrFactory);\n}\n\nfunction isClass(value: unknown): value is Class<unknown> {\n if (!(\"function\" != typeof value)) {\n return false;\n }\n\n return /^class[\\s{]/.test(toString.call(value));\n}\n","import { DefaultValueDecorators, Default } from \"./dto-default.decorator\";\nimport { Class } from \"./types\";\n\nexport function DTOWrapper<T extends object>() {\n return class {} as Class<T>;\n}\n\nexport const DTO: typeof DTOWrapper & Default = Object.assign(DTOWrapper, DefaultValueDecorators);\n","import { metadata } from \"@autometa/injection\";\nimport { Class, PropertyMetadata } from \"./types\";\nimport { DtoBuilderSymbols } from \"./property.enum\";\nexport type IBuilder<T> = {\n [k in keyof T]-?: ((arg: T[k]) => IBuilder<T>) & (() => T[k]);\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Derive a new builder from the current builder, copying it's\n * current values into a new builder. Allows default values to\n * be set in a copy, which will not be modified by child copies.\n */\n derive(): IBuilder<T>;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): IBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): IBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\nexport type ClsBuilder<T> = {\n [k in keyof T]-?: BuilderMethod<T, T[k]>;\n} & {\n /**\n * Build the object and return it\n */\n build(): T;\n /**\n * Assign an arbitrary value to a property. The value\n * does not need to match a valid property for the interface\n * and can be used to introduce \"unexpected\" values for testing,\n * or coming from other object maps.\n * @param property the name of the property to set a value for\n * @param value the value to set\n */\n assign<K>(property: string, value: K): ClsBuilder<T>;\n /**\n * Append a value to an array property. If no array\n * has been defined one will be created. If one exists,\n * it will be reused.\n * @param property\n * @param value\n */\n append<K>(property: string, value: K): ClsBuilder<T>;\n\n /**\n * Attach a value to a sub-property of a property.\n * If the property does not exist, a new empty object will be\n * assigned to it.\n *\n * The value is appended to the child object indexed by the sub-property.\n * @param property The name of the property to attach key:value pairs to\n * @param subProperty The name of the sub-property to attach the value to\n * @param value The value to attach to the child objects property\n */\n attach<K>(property: string, subProperty: string, value: K): ClsBuilder<T>;\n};\n\nexport type BuilderMethod<TTarget, TType> = ((arg: TType) => ClsBuilder<TTarget>) & {\n value: TType;\n};\nexport type DtoBuilder<T> = Class<ClsBuilder<T>> & {\n /**\n * Construct a builder from a raw object or class instance,\n * inheriting any properties that have already been defined.\n * @param value /\n */\n fromRaw(value: Partial<T>): ClsBuilder<T>;\n /**\n * Constructs a DTO, prefilled with any default values\n * assigned to the DTO via either the `Property` decorator\n * or the `DTO.*` decorators.\n *\n * With property:\n *\n * ```ts\n * class FooDto {\n * @Property(1)\n * foo: number;\n * @Property(()=> \"factory string\")\n * bar: string;\n * @Property(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n *\n * With DTO:\n *\n * ```ts\n * class FooDto {\n * @DTO.value(1)\n * foo: number;\n * @DTO.factory(()=> \"factory string\")\n * bar: string;\n * @DTO.dto(SomeDto)\n * baz: SomeDto;\n * }\n * ```\n */\n default(): T;\n};\n\nexport function Builder<T>(cls: Class<T>): DtoBuilder<T>;\nexport function Builder<T>(): IBuilder<T>;\nexport function Builder<T>(defaults?: Partial<T> | Class<T>): IBuilder<T> | DtoBuilder<T> {\n if (isClassBuilder(defaults)) {\n return class BuilderClass<TType> {\n constructor() {\n const built: Record<string, unknown> = { ...defaults };\n const proxy = classProxy.bind(null, defaults as Class<unknown>, built);\n return proxy(this) as BuilderClass<TType>;\n }\n declare build: () => T;\n declare assign: <K>(property: string, value: K) => BuilderClass<TType>;\n static fromRaw(value: T) {\n const builder = new this();\n const keys = Object.keys(value as object) as (keyof T)[];\n for (const key of keys) {\n builder.assign(key.toString(), value[key]);\n }\n return builder;\n }\n\n static default() {\n return new this().build();\n }\n } as DtoBuilder<T>;\n // return clsBuilder as IBuilder<T>;\n }\n const built: Record<string, unknown> = { ...defaults };\n const builder = new Proxy(built, {\n get(target, prop) {\n if (\"build\" === prop) {\n return () => built;\n }\n\n if (\"derive\" === prop) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return () => Builder<T>({ ...built } as any);\n }\n\n if (\"assign\" === prop) {\n return (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return target;\n };\n }\n\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (typeof built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return target;\n };\n }\n\n if (\"append\" === prop) {\n return (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return target;\n };\n }\n\n return (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n\n built[prop.toString()] = args[0];\n return builder;\n };\n },\n });\n\n return builder as IBuilder<T>;\n}\n\nfunction classProxy<T>(defaults: Class<T>, built: Record<string, unknown>, inst: T) {\n const clsBuilder = new Proxy(inst as object, {\n get(_, prop) {\n if (\"build\" === prop) {\n return () => {\n const instance = constructDefaultDto(defaults);\n return Object.assign(instance as object, { ...built });\n };\n }\n if (\"assign\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n built[property.toString()] = value;\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"append\" === prop) {\n const fn = (property: keyof T, value: unknown) => {\n if (!Array.isArray(built[property.toString()])) {\n built[property.toString()] = [value];\n } else {\n (built[property.toString()] as unknown[]).push(value);\n }\n return clsBuilder;\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return fn as any;\n }\n if (\"attach\" === prop) {\n return (property: keyof T, subProperty: string, value: unknown) => {\n if (built[property.toString()] === undefined) {\n built[property.toString()] = {};\n }\n const dict = built[property.toString()] as Record<string, unknown>;\n dict[subProperty] = value;\n return clsBuilder;\n };\n }\n if (prop in (inst as Record<string, unknown>)) {\n return (inst as Record<string, unknown>)[prop as string];\n }\n const fn = (...args: unknown[]): unknown => {\n // If no arguments passed return current value.\n if (0 === args.length) {\n return built[prop.toString()];\n }\n built[prop.toString()] = args[0];\n return clsBuilder;\n };\n const modified = Object.defineProperty(fn, \"value\", {\n get() {\n return built[prop.toString()];\n },\n });\n return modified;\n },\n });\n return clsBuilder as ClsBuilder<T>;\n}\n\nfunction isClassBuilder<T>(cls: unknown): cls is Class<T> {\n return \"function\" === typeof cls;\n}\n\nfunction constructDefaultDto<T>(base: Class<T>): T {\n const defaultSetters = metadata(base).getCustom<PropertyMetadata>(\n DtoBuilderSymbols.PROPERTY_DEFAULTS\n );\n const instance = new base();\n if (!defaultSetters) {\n return instance;\n }\n const keys = Object.keys(defaultSetters) as unknown as (keyof typeof instance)[] &\n (keyof typeof defaultSetters)[];\n\n for (const key of keys) {\n const value = defaultSetters[key];\n if (\"value\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.value,\n writable: true,\n enumerable: true,\n });\n }\n if (\"factory\" in value) {\n Object.defineProperty(instance as object, key, {\n value: value.factory(),\n writable: true,\n enumerable: true,\n });\n }\n if (\"dtoType\" in value) {\n const dtoInst = constructDefaultDto(value.dtoType);\n Object.defineProperty(instance as object, key, {\n value: dtoInst,\n writable: true,\n enumerable: true,\n });\n }\n }\n return instance;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAyB;;;ACAzB,IAAM,oBAAmC,OAAO,sCAAsC;AAC/E,IAAM,oBAAoB;AAAA,EAC/B;AACF;;;ADAA,6BAAO;AAeA,IAAM,yBAAkC;AAAA,EAC7C,OAAO,CAAC,UAAmB,CAAC,QAAgB,gBAAiC;AAC3E,UAAM,gBAAY,2BAAS,eAAe,MAAM,CAAC,EAAE;AAAA,MACjD,kBAAkB;AAAA,MAClB,CAAC;AAAA,MACD;AAAA,IACF;AACA,UAAM,QAAQ,EAAE,MAAM;AACtB,cAAU,WAAqB,IAAI;AAAA,EACrC;AAAA,EACA,SACE,CAAC,YACD,CAAC,QAAgB,gBAAiC;AAChD,UAAM,gBAAY,2BAAS,eAAe,MAAM,CAAC,EAAE;AAAA,MACjD,kBAAkB;AAAA,MAClB,CAAC;AAAA,MACD;AAAA,IACF;AACA,UAAM,QAAQ,EAA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AGvC,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,eAAe,GAAG;AAChC,QAAI,WAAW,OAAO;AACpB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM;AAAA,QACb,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO,MAAM,QAAQ;AAAA,QACrB,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,QAAI,aAAa,OAAO;AACtB,YAAM,UAAU,oBAAoB,MAAM,OAAO;AACjD,aAAO,eAAe,UAAoB,KAAK;AAAA,QAC7C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;","names":["import_injection","built","builder","fn"]}
{
"name": "@autometa/dto-builder",
"version": "0.13.8",
"version": "0.13.9",
"description": "Define DTOs and Entities and automatically create a builder class.",

@@ -5,0 +5,0 @@ "type": "module",