@zyno-io/ts-reflection 26.911.1944 → 26.912.2242

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.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=function(e){return e[e.never=0]=`never`,e[e.any=1]=`any`,e[e.unknown=2]=`unknown`,e[e.void=3]=`void`,e[e.undefined=4]=`undefined`,e[e.null=5]=`null`,e[e.string=6]=`string`,e[e.number=7]=`number`,e[e.boolean=8]=`boolean`,e[e.bigint=9]=`bigint`,e[e.literal=10]=`literal`,e[e.enum=11]=`enum`,e[e.union=12]=`union`,e[e.intersection=13]=`intersection`,e[e.array=14]=`array`,e[e.tuple=15]=`tuple`,e[e.class=16]=`class`,e[e.object=17]=`object`,e[e.objectLiteral=18]=`objectLiteral`,e[e.property=19]=`property`,e[e.propertySignature=20]=`propertySignature`,e[e.method=21]=`method`,e[e.promise=22]=`promise`,e[e.templateLiteral=23]=`templateLiteral`,e}({});function t(e){return!!e&&typeof e==`object`&&typeof e.kind==`number`}var n=class extends Error{code;path;errors;constructor(e,t,n=``){super(t),this.code=e,this.path=n,this.errors=[this]}};Object.defineProperty(n,"name",{configurable:!0,value:`ValidatorError`});var r=class{decorators=[];addDecorator(e,t){this.decorators.push({predicate:e,handler:t})}apply(e,t){let n=t;for(let t of this.decorators){if(!t.predicate(e))continue;let r=new i;t.handler(e,r),n=r.apply(n)}return n}},i=class{transforms=[];addTransform(e){this.transforms.push(e)}apply(e){return this.transforms.reduce((e,t)=>t(e),e)}},a=new r;function o(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(typeof e==`bigint`)return e!==0n;if(typeof e==`string`){if(e===`true`||e===`1`)return!0;if(e===`false`||e===`0`)return!1}return e}function s(t){if(t.kind===e.union){let n=t.types.filter(t=>t.kind!==e.undefined&&t.kind!==e.null);return n.length===1?s(n[0]):t}if(t.kind===e.intersection){let e=c(t);if(e)return e;let n=t.types.find(e=>!p(e));return n?s(n):t}return t}function c(t){if(t.kind!==e.intersection||!l(t))return;let n=u(t);if(n.length!==0)return{kind:e.objectLiteral,typeName:t.typeName,types:n}}function l(t){return t.kind===e.intersection&&t.types.every(t=>p(t)?!0:t.kind===e.intersection?l(t):t.kind===e.objectLiteral)}function u(t){let n=[],r=new Map,i=t=>{let i=String(t.name);r.has(i)||n.push(i),r.set(i,{kind:e.propertySignature,name:t.name,type:t.type,optional:t.optional})},a=t=>{if(!p(t)){if(t.kind===e.intersection){for(let e of t.types)a(e);return}if(t.kind===e.objectLiteral){for(let e of d(t))i(e);return}}};return a(t),n.map(e=>r.get(e))}function d(t,n=new Set){if(n.has(t)||p(t))return[];n.add(t);let r=[];for(let i of t.implements??[]){let t=s(i);n.has(t)||(t.kind===e.objectLiteral?r.push(...d(t,n)):t.kind===e.intersection?r.push(...u(t)):t.kind===e.class&&r.push(...C(t)))}return w([...r,...t.types.map(T)])}function f(t,n=new Set){if(t.index)return t.index;if(!n.has(t)){n.add(t);for(let r of t.implements??[]){let t=s(r);if(t.kind===e.objectLiteral){let e=f(t,n);if(e)return e}}}}function p(e){return!!(e.annotations||e.validation||e.database||ee(e)||ne(e))}function ee(t){return te(t.typeName)?t.kind===e.unknown||t.kind===e.class&&!g(t.classType):!1}function te(e){switch(e){case`ApiName`:case`AutoIncrement`:case`DatabaseField`:case`GreaterThan`:case`HasDefault`:case`Index`:case`Length`:case`LessThan`:case`Maximum`:case`MaxLength`:case`Minimum`:case`MinLength`:case`MySQL`:case`OnUpdate`:case`Pattern`:case`PrimaryKey`:case`Reference`:case`TypeAnnotation`:case`Unique`:return!0;default:return!1}}function ne(t){return t.kind===e.objectLiteral&&t.types.length>0&&t.types.every(t=>t.kind===e.propertySignature&&String(t.name)===`typia.tag`)}function m(t){return t.kind===e.any||t.kind===e.undefined||t.kind===e.union&&t.types.some(m)}function h(t){return t.kind===e.any||t.kind===e.null||t.kind===e.union&&t.types.some(h)}function re(e){let t=g(e);if(!t)throw Error(`Target is not a constructor`);return t}function g(e){if(v(e))return e;try{let t=e();return v(t)?t:void 0}catch{return}}function _(t,n=new Set){if(!t||typeof t!=`object`||n.has(t))return;n.add(t);let r=t;if(r.kind===e.class&&typeof r.classType==`function`&&!v(r.classType))try{let e=r.classType();v(e)&&(r.classType=e)}catch{}for(let e of Object.values(r))if(typeof e!=`function`){if(Array.isArray(e))for(let t of e)_(t,n);else _(e,n)}ie(r),ce(r)}function ie(n){if(n.kind!==e.intersection||!Array.isArray(n.types))return;let r=n.types.filter(t);if(r.length!==n.types.length)return;let i=r.filter(t=>t.kind===e.union);if(i.length===0||i.length===1&&r.every(e=>e===i[0]||p(e)))return;let a=[[]];for(let e of r){let t=ae(e);a=a.flatMap(e=>t.map(t=>[...e,...t]))}n.kind=e.union,n.types=a.map(se)}function ae(t){if(t.kind!==e.union)return[[t]];let n=oe(t);return t.types.flatMap(e=>ae(e).map(e=>n?[...e,n]:e))}function oe(t){if(!(!t.annotations&&!t.validation&&!t.database))return{kind:e.unknown,annotations:t.annotations,validation:t.validation,database:t.database}}function se(t){return t.some(t=>t.kind===e.never)?{kind:e.never}:t.length===1?t[0]:{kind:e.intersection,types:t}}function v(e){return!!(typeof e==`function`&&e.prototype&&e.prototype.constructor===e)}function ce(n){let r=de(n);if(!r)return;let i=Array.isArray(n.typeArguments)?n.typeArguments:[];if(r===`Record`){if(n.kind!==e.objectLiteral||(n.types??[]).length>0)return;let r=i[0],a=i[1];if(!t(r)||!t(a))return;let o=le(r,a);o.length>0?(n.types=o,delete n.index):n.index=a;return}if((n.types??[]).length>0)return;let a=i[0];if(!t(a))return;if(r===`Extract`){let r=i[1];if(n.kind!==e.union||!t(r))return;n.types=y(a).filter(e=>b(e,r));return}if(n.kind!==e.objectLiteral)return;let o=C(a),s=a.kind===e.objectLiteral?f(a):void 0;if(o.length===0){s&&(n.index=s);return}let c=new Set((Array.isArray(n.utilityKeys)?n.utilityKeys:[]).filter(e=>typeof e==`string`)),l=o.map(T);r===`Pick`?l=l.filter(e=>c.has(String(e.name))):r===`Omit`?l=l.filter(e=>!c.has(String(e.name))):r===`Partial`?l=l.map(e=>({...e,optional:!0})):r===`Required`?l=l.map(e=>({...e,optional:void 0})):r===`OptionalNulls`&&(l=l.map(e=>h(e.type)?{...e,optional:!0}:e)),n.types=l,s&&(n.index=s)}function le(t,n){return ue(t).map(t=>({kind:e.propertySignature,name:t,type:n,optional:void 0}))}function ue(t){let n=[];for(let r of y(t)){if(r.kind!==e.literal||typeof r.literal!=`string`&&typeof r.literal!=`number`)return[];n.push(r.literal)}return n}function y(t){return t.kind===e.union?t.types.flatMap(y):[t]}function b(t,n){let r=s(t),i=s(n);if(i.kind===e.union)return i.types.some(e=>b(r,e));if(r.kind===e.union)return r.types.every(e=>b(e,i));if(i.kind===e.objectLiteral){let t=d(i).filter(e=>!e.optional&&!m(e.type));if(t.length===0)return r.kind===e.objectLiteral||r.kind===e.class;let n=C(r);return n.length!==0&&t.every(e=>{let t=n.find(t=>String(t.name)===String(e.name));return t?x(t.type,e.type):!1})}return x(r,i)}function x(t,n){let r=s(t),i=s(n);return r.kind===e.any||r.kind===e.unknown||i.kind===e.any||i.kind===e.unknown?!0:r.kind===e.union?r.types.some(e=>x(e,i)):i.kind===e.union?i.types.some(e=>x(r,e)):r.kind===e.literal&&i.kind===e.literal?r.literal===i.literal:r.kind===e.literal?S(r.literal,i):i.kind===e.literal?S(i.literal,r):r.kind===i.kind}function S(t,n){return t===null?n.kind===e.null:t===void 0?n.kind===e.undefined:typeof t==`string`?n.kind===e.string||n.kind===e.templateLiteral:typeof t==`number`?n.kind===e.number:typeof t==`boolean`?n.kind===e.boolean:typeof t==`bigint`&&n.kind===e.bigint}function C(t){if(t.kind===e.class){let n=g(t.classType);if(!n)return[];try{return G.from(n).getProperties().map(t=>({kind:e.propertySignature,name:t.name,type:t.getType(),optional:t.isOptional()?!0:void 0,description:t.getDescription()||void 0}))}catch(e){if(e instanceof Error&&e.message.startsWith(`No runtime type metadata for `))return[];throw e}}return t.kind===e.objectLiteral?d(t):t.kind===e.intersection?w(t.types.flatMap(C)):[]}function w(e){let t=[],n=new Map;for(let r of e){let e=String(r.name);n.has(e)||t.push(e),n.set(e,T(r))}return t.map(e=>n.get(e))}function T(t){return{kind:e.propertySignature,name:t.name,type:t.type,optional:t.optional?!0:void 0,description:t.description}}function E(e){return e===`Pick`||e===`Omit`||e===`Partial`||e===`Required`||e===`Extract`||e===`Record`||e===`OptionalNulls`}function de(e){if(E(e.utilityType))return e.utilityType;if(E(e.typeName))return e.typeName}function D(t,n){if(n(t),(t.kind===e.union||t.kind===e.intersection)&&`types`in t)for(let e of t.types)D(e,n);else if((t.kind===e.array||t.kind===e.promise)&&`type`in t)D(t.type,n);else if(t.kind===e.objectLiteral&&`types`in t){for(let e of t.types)D(e.type,n);t.index&&D(t.index,n)}}function O(t,n){if(n(t),(t.kind===e.union||t.kind===e.intersection)&&`types`in t)for(let e of t.types)O(e,n)}function fe(e,t){let n;return D(e,r=>{n===void 0&&r!==e&&(n=t(r))}),n}function k(e,t){let n;return O(e,r=>{n===void 0&&r!==e&&(n=t(r))}),n}function pe(e,t){let n=!1;return D(e,e=>{n||=t(e)}),n}function A(t){return t?.kind===e.literal&&typeof t.literal==`number`?t.literal:void 0}function j(t){if(!t)return;let n=t.runtime;if(n!==void 0)return typeof n==`function`?n():n;if(t.kind===e.literal)return t.literal}function M(e,t){return e?`${e}.${t}`:t}function me(t){let n=N.getType(t,`tsf:type`);return n?.kind===e.literal&&(n.literal===`uuid`||n.literal===`uuidString`)}function he(t){let n=N.getType(t,`tsf:type`);return n?.kind===e.literal&&n.literal===`uuid`}var N={getType(e,t){return e.annotations?.[t]||(k(e,e=>e.annotations?.[t])??ve(e,t))},getOption(e,t){return this.getType(e,t)}},ge={getAnnotations(e){let t=[],n=new Set;return O(e,e=>{if(e.validation)for(let r of e.validation){let e=Ee(r);n.has(e)||(n.add(e),t.push(r))}let r=be(e);if(r){let e=Ee(r);n.has(e)||(n.add(e),t.push(r))}}),t}},P={getDatabase(t,n){let r=t.database?.[n]??(n===`*`?void 0:t.database?.[`*`]);if(r)return r;if(t.kind===e.union){let r=t.types.filter(t=>t.kind!==e.null&&t.kind!==e.undefined);return r.length===1?this.getDatabase(r[0],n):void 0}let i=k(t,e=>e.database?.[n]??(n===`*`?void 0:e.database?.[`*`]));if(i)return i;let a=xe(t,n);if(a)return a}},F={kind:e.undefined};function _e(t){return{kind:e.literal,literal:t}}function I(e,...t){return{name:e,args:t}}function ve(e,t){return we(e,e=>ye(e,t))}function ye(e,t){let n=L(e);if(!(!n||n.kind!==t)&&!(!n.kind.startsWith(`tsf:`)&&!n.kind.startsWith(`openapi:`)))return n.value??F}function be(e){let t=L(e);if(t)switch(t.kind){case`minLength`:case`maxLength`:case`minimum`:case`greaterThan`:case`maximum`:case`lessThan`:return t.value?I(t.kind,t.value):void 0;case`pattern`:return I(`pattern`,t.value??R(t.schema,`pattern`)??F);case`format`:{let e=B(t.value)??B(R(t.schema,`format`)),n=e?Te(e):void 0;return n?I(`pattern`,_e(n)):void 0}case`tsf:validator`:return I(`validator`,t.value??F);default:return}}function xe(e,t){return we(e,e=>Se(e,t))}function Se(e,t){let n=L(e);if(!n)return;let r=V(n.schema)??V(n.value);if(r&&(n.kind===`database:field`||n.kind===`database:mysql`&&t===`mysql`))return r}function L(t){if(t.kind!==e.objectLiteral)return;let n=t.types.find(e=>String(e.name)===`typia.tag`);if(!n)return;let r=z(n.type);if(r.kind!==e.objectLiteral)return;let i=B(R(r,`kind`));if(i)return{kind:i,value:R(r,`value`),schema:R(r,`schema`)}}function R(t,n){let r=t?z(t):void 0;if(!(!r||r.kind!==e.objectLiteral))return r.types.find(e=>String(e.name)===n)?.type}function z(t){if(t.kind!==e.union)return t;let n=t.types.filter(t=>t.kind!==e.undefined&&t.kind!==e.null);return n.length===1?n[0]:t}function B(t){return t?.kind===e.literal&&typeof t.literal==`string`?t.literal:void 0}function V(t){let n=t?z(t):void 0;if(!n||n.kind!==e.objectLiteral)return;let r={};for(let e of n.types){let t=Ce(e.type);t!==void 0&&(r[String(e.name)]=t)}return r}function Ce(t){let n=z(t);if(n.kind===e.literal)return n.literal;if(n.kind!==e.undefined&&n.kind===e.objectLiteral)return V(n)}function we(e,t){let n;return O(e,e=>{n===void 0&&(n=t(e))}),n}function Te(e){switch(e){case`date`:return`^\\d{4}-\\d{2}-\\d{2}$`;case`email`:return`^[a-zA-Z0-9_+.-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]+$`;case`uuid`:return`^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$`;default:return}}function Ee(e){return`${e.name}:${e.args.map(De).join(`|`)}`}function De(t){if(t.kind===e.literal&&`literal`in t)return`literal:${String(t.literal)}`;let n=t.runtime;return n?`runtime:${String(n)}`:`${t.kind}:${t.typeName??``}`}function Oe(t){let n=N.getType(t,`tsf:type`);if(n?.kind===e.literal){if(n.literal===`integer`)return e.number;if(typeof n.literal==`string`)return e.string}}var H=new WeakMap,U=new WeakMap;function W(e,t){t&&(t.collectionName&&(e.collectionName=t.collectionName),t.indexes?.length&&(e.indexes=[...t.indexes]),t.excludeMigration&&(e.excludeMigration=!0))}function ke(e){if(!e)throw Error(`typeOf<T>() was not transformed by the metadata compiler`);return _(e),e}function Ae(e,t){t.classType=e,W(t,U.get(e)),H.set(e,t)}var G=class t{classType;name;indexes;metadata;constructor(e,t){this.classType=e,this.metadata=t,this.name=t.name||e.name;let n=t.properties.flatMap(e=>{let t=[];return e.index&&t.push({names:[e.name],options:e.index}),e.unique&&t.push({names:[e.name],options:{...e.unique,unique:!0}}),t});this.indexes=[...t.indexes??[],...n]}static from(e){let n=J(e);if(!n)throw Error(`No runtime type metadata for ${e.name}. Did the tsf metadata compiler run?`);return new t(e,n)}getClassType(){return this.classType}getCollectionName(){return this.metadata.collectionName??U.get(this.classType)?.collectionName}isDatabaseMigrationSkipped(e){return this.metadata.excludeMigration===!0||U.get(this.classType)?.excludeMigration===!0}getProperties(){return Y(this.classType,this.metadata).map(e=>new K(e))}getProperty(e){let t=Y(this.classType,this.metadata).find(t=>t.name===e);if(!t)throw Error(`Property ${String(e)} does not exist on ${this.name}`);return new K(t)}getPrimary(){let e=Y(this.classType,this.metadata).find(e=>e.primaryKey);if(!e)throw Error(`Class ${this.name} has no primary key`);return new K(e)}getMethod(e){let t=Me(this.classType,this.metadata).find(t=>t.name===e||String(t.name)===String(e));if(!t)throw Error(`Method ${String(e)} does not exist on ${this.name}`);return new q(t)}getConstructorOrUndefined(){let t=Ne(this.classType,this.metadata);if(t.length)return new q({name:`constructor`,parameters:t,returnType:{kind:e.void}})}},K=class{metadata;type;name;constructor(e){this.metadata=e,this.type=e.type,this.name=e.name}getNameAsString(){return String(this.name)}getType(){return this.type}getDescription(){return this.metadata.description??``}isPublic(){return!0}isPrimaryKey(){return this.metadata.primaryKey===!0}isAutoIncrement(){return this.metadata.autoIncrement===!0}isOptional(){return this.metadata.optional===!0||m(this.type)}isNullable(){return h(this.type)}getDatabase(e=`*`){return P.getDatabase(this.type,e)||P.getDatabase(this.type,`*`)}isBackReference(){return!1}isDatabaseSkipped(e){return!1}isDatabaseMigrationSkipped(e){return!1}isReference(){return this.metadata.reference!==void 0}getReference(){return this.metadata.reference}getResolvedReflectionClass(){let t=s(this.type);if(t.kind!==e.class)throw Error(`Property ${String(this.name)} is not a class reference`);return G.from(re(t.classType))}},q=class{metadata;constructor(e){this.metadata=e}getDescription(){return this.metadata.description??``}getParameters(){return this.metadata.parameters.map(e=>new je(e))}getReturnType(){return this.metadata.returnType}},je=class{metadata;constructor(e){this.metadata=e}getName(){return this.metadata.name}getType(){return this.metadata.type}isOptional(){return this.metadata.optional===!0||m(this.metadata.type)}hasDefault(){return this.metadata.default===!0}};function J(t){let n=H.get(t);if(n)return _(n),n;let r=Object.prototype.hasOwnProperty.call(t,`__tsfType`)?t.__tsfType:void 0;if(!r){if(!X(t))return;let n={kind:e.class,classType:t,name:t.name,typeName:t.name,properties:[],methods:[],constructorParameters:[],hasConstructor:!0};return W(n,U.get(t)),H.set(t,n),n}return W(r,U.get(t)),_(r),H.set(t,r),r}function Y(e,t){let n=X(e),r=n?Y(n.classType,n.metadata):[],i=new Set(t.properties.map(e=>e.name));return[...r.filter(e=>!i.has(e.name)),...t.properties]}function Me(e,t){let n=X(e),r=n?Me(n.classType,n.metadata):[],i=new Set(t.methods.map(e=>e.name));return[...r.filter(e=>!i.has(e.name)),...t.methods]}function Ne(e,t){if(t.constructorParameters.length||t.hasConstructor)return t.constructorParameters;let n=X(e);return n?Ne(n.classType,n.metadata):[]}function X(e){let t=(e.prototype?Object.getPrototypeOf(e.prototype):void 0)?.constructor;if(!t||t===Object||t===e)return;let n=J(t);return n?{classType:t,metadata:n}:void 0}var Pe=new Map,Z={register(e,t){Pe.set(e,t)},get(e){return Pe.get(e)}};function Fe(e,t){let n=He(e,t);return n?Q(e,n):[]}function Ie(e,t){if(!t)throw Error(`deserialize<T>() was not transformed by the metadata compiler`);return _(t),$(e,t)}function Le(e,t,n,r,i){if(!i)throw Error(`validatedDeserialize<T>() requires reflected type metadata`);_(i);let a=$(e,i),o=Q(a,i);if(o.length)throw o[0];return a}function Re(e,t,n){if(!n)throw Error(`assert<T>() requires explicit reflected type metadata`);_(n);let r=Q(e,n);if(r.length)throw r[0]}function ze(e,t,n){if(!n)throw Error(`is<T>() requires explicit reflected type metadata`);return _(n),Q(e,n).length===0}function Be(e,t,n,r,i){if(!i)throw Error(`cast<T>() requires explicit reflected type metadata`);return _(i),$(e,i)}function Ve(e){if(t(e))return e;throw Error(`Unsupported receive type payload`)}function He(e,n){if(t(n))return _(n),n;if(typeof n==`function`)return J(n);if(e&&typeof e==`object`)return J(e.constructor)}function Q(t,r,i=``){let a=[],o=s(r),c=Oe(o);if(t===void 0)return m(r)||a.push(new n(`required`,`The value is required.`,i)),a;if(t===null)return h(r)||a.push(new n(`required`,`The value cannot be null.`,i)),a;if(c===e.string)typeof t!=`string`&&a.push(new n(`type`,`The value must be a string.`,i));else if(c===e.number)(typeof t!=`number`||Number.isNaN(t))&&a.push(new n(`type`,`The value must be a number.`,i));else if(c===e.boolean)typeof t!=`boolean`&&a.push(new n(`type`,`The value must be a boolean.`,i));else if(o.kind===e.undefined||o.kind===e.null||o.kind===e.never)a.push(new n(`type`,`The value does not match the required type.`,i));else if(o.kind===e.string||o.kind===e.templateLiteral)typeof t!=`string`&&a.push(new n(`type`,`The value must be a string.`,i));else if(o.kind===e.number)(typeof t!=`number`||Number.isNaN(t))&&a.push(new n(`type`,`The value must be a number.`,i));else if(o.kind===e.boolean)typeof t!=`boolean`&&a.push(new n(`type`,`The value must be a boolean.`,i));else if(o.kind===e.array)Array.isArray(t)?t.forEach((e,t)=>{a.push(...Q(e,o.type,M(i,String(t))))}):a.push(new n(`type`,`The value must be an array.`,i));else if(o.kind===e.tuple)Array.isArray(t)?o.types.forEach((e,n)=>{a.push(...Q(t[n],e.type,M(i,String(n))))}):a.push(new n(`type`,`The value must be an array.`,i));else if(o.kind===e.union){let e=o.types.map(e=>Q(t,e,i));if(!e.some(e=>e.length===0)){let t=e.filter(e=>e.length>0).sort((e,t)=>e.length-t.length)[0];t?.length?a.push(...t):a.push(new n(`type`,`The value does not match any allowed type.`,i))}}else if(o.kind===e.objectLiteral){if(!t||typeof t!=`object`||Array.isArray(t))return a.push(new n(`type`,`The value must be an object.`,i)),a;let e=t,r=new Set;for(let t of d(o)){r.add(String(t.name));let n=M(i,String(t.name));e[t.name]===void 0&&t.optional||a.push(...Q(e[t.name],t.type,n))}let s=f(o);if(s)for(let[t,n]of Object.entries(e))r.has(t)||a.push(...Q(n,s,M(i,t)))}else if(o.kind===e.literal)t!==o.literal&&a.push(new n(`type`,`The value must be ${String(o.literal)}.`,i));else if(o.kind===e.enum)o.values.includes(t)||a.push(new n(`type`,`The value does not match any allowed enum value.`,i));else if(o.kind===e.class){let e=g(o.classType);if(!e)return(!t||typeof t!=`object`||Array.isArray(t))&&a.push(new n(`type`,`The value must be an object.`,i)),a;if(e!==Date){let n=G.from(e),r=t;for(let e of n.getProperties())r[String(e.name)]===void 0&&e.isOptional()||a.push(...Q(r[String(e.name)],e.getType(),M(i,String(e.name))))}}for(let e of ge.getAnnotations(r))if(e.name===`minLength`&&typeof t==`string`){let r=A(e.args[0]);r!==void 0&&t.length<r&&a.push(new n(`minLength`,`The value must be at least ${r} characters.`,i))}else if(e.name===`maxLength`&&typeof t==`string`){let r=A(e.args[0]);r!==void 0&&t.length>r&&a.push(new n(`maxLength`,`The value must be at most ${r} characters.`,i))}else if(e.name===`minimum`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t<r&&a.push(new n(`minimum`,`The value must be at least ${r}.`,i))}else if(e.name===`greaterThan`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t<=r&&a.push(new n(`greaterThan`,`The value must be greater than ${r}.`,i))}else if(e.name===`maximum`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t>r&&a.push(new n(`maximum`,`The value must be at most ${r}.`,i))}else if(e.name===`lessThan`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t>=r&&a.push(new n(`lessThan`,`The value must be less than ${r}.`,i))}else if(e.name===`pattern`&&typeof t==`string`){let r=j(e.args[0]),o=typeof r==`string`?new RegExp(r):r instanceof RegExp?r:void 0;o&&!o.test(t)&&a.push(new n(`pattern`,`The value does not match the required pattern.`,i))}else if(e.name===`validate`){let r=j(e.args[0]);if(typeof r==`function`){let e=r(t);e instanceof n&&a.push(new n(e.code,e.message,i))}}else if(e.name===`validator`){let r=j(e.args[0]),o=typeof r==`string`?Z.get(r):void 0;if(o){let e=o(t);e instanceof n&&a.push(new n(e.code,e.message,i))}}return a}function $(t,n){if(t==null)return t;if(n.kind===e.intersection){let e=c(n);if(e&&t&&typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date))return a.apply(n,$(t,e));let r=t;if(t&&typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date)){let e={},i=!1;for(let r of n.types){let n=$(t,r);n&&typeof n==`object`&&!Array.isArray(n)&&!(n instanceof Date)&&(Object.assign(e,n),i=!0)}r=i?e:t}else for(let e of n.types)r=$(r,e);return a.apply(n,r)}let r=s(n),i=t;if(r.kind===e.number&&typeof t==`string`&&t.trim()!==``)i=Number(t);else if(r.kind===e.boolean)i=o(t);else if(r.kind===e.enum&&typeof t==`string`){let e=Number(t);!Number.isNaN(e)&&r.values.includes(e)&&(i=e)}else if(r.kind===e.array&&Array.isArray(t))i=t.map(e=>$(e,r.type));else if(r.kind===e.tuple&&Array.isArray(t))i=r.types.map((e,n)=>$(t[n],e.type));else if(r.kind===e.union)for(let e of r.types){let n=$(t,e);if(Q(n,e).length===0){i=n;break}}else if(r.kind===e.class){let e=g(r.classType);if(!e)return a.apply(n,t);if(e===Date)return a.apply(n,t instanceof Date?t:new Date(t));if(typeof t!=`object`)return a.apply(n,t);let o=new e,s=t;for(let t of G.from(e).getProperties())o[String(t.name)]=$(s[String(t.name)],t.getType());i=o}else if(r.kind===e.objectLiteral&&typeof t==`object`){let e=d(r),o=f(r);if(e.length===0&&!o)return a.apply(n,t);let s=t,c={},l=new Set;for(let t of e){let e=String(t.name);l.add(e),c[e]=$(s[e],t.type)}if(o)for(let[e,t]of Object.entries(s))l.has(e)||(c[e]=$(t,o));i=c}return a.apply(n,i)}var Ue=class{x;y};function We(e){if(!(e instanceof Date)||Number.isNaN(e.getTime()))return new n(`invalidDate`,`The date is invalid.`)}Z.register(`validDate`,We);function Ge(e,...t){for(let n of t){let t=N.getType(e,n);if(t)return t}}a.addDecorator(e=>Ge(e,`tsf:trim`)!==void 0,(e,t)=>{t.addTransform(e=>typeof e==`string`?e.trim():e)});var Ke=/^[a-z0-9_+.-]+@[a-z0-9-.]+\.[a-z]+$/i;function qe(e){return typeof e==`function`?e.name||`anonymous class`:e&&typeof e==`object`?e.constructor?.name||`anonymous class`:String(e)}exports.Coordinate=Ue,exports.DeserializerRegistry=r,exports.DeserializerState=i,exports.EMAIL_REGEX=Ke,exports.ReflectionClass=G,exports.ReflectionKind=e,exports.ReflectionMethod=q,exports.ReflectionParameter=je,exports.ReflectionProperty=K,exports.ValidationError=n,exports.ValidatorError=n,exports.allowsNull=h,exports.allowsUndefined=m,exports.applyMetadataOptions=W,exports.assert=Re,exports.cast=Be,exports.classMetadata=H,exports.classOptions=U,exports.cloneUtilityProperty=T,exports.coerceBooleanValue=o,exports.databaseAnnotation=P,exports.deserialize=Ie,exports.deserializer=a,exports.expandUtilityTypeMetadata=ce,exports.findNested=fe,exports.findNestedSurface=k,exports.flattenRuntimeUnionTypes=y,exports.getClassName=qe,exports.getFirstTypeAnnotation=Ge,exports.getUtilityTypeName=de,exports.hasNestedType=pe,exports.is=ze,exports.isClass=v,exports.isDatabaseUUIDType=he,exports.isExtractAssignable=b,exports.isMarkerType=p,exports.isReflectedType=t,exports.isUUIDType=me,exports.isUtilityTypeName=E,exports.joinPath=M,exports.knownPrimitiveKind=Oe,exports.literalMatchesType=S,exports.literalNumber=A,exports.mergeStructuredProperties=u,exports.mergeUtilityProperties=w,exports.mergedIntersectionObjectLiteral=c,exports.normalizeTypeMetadata=_,exports.objectLiteralIndexType=f,exports.objectLiteralPropertiesFromType=d,exports.readClassMetadata=J,exports.recordLiteralKeysFromType=ue,exports.recordPropertiesFromKeyType=le,exports.registerClassMetadata=Ae,exports.resolveClassType=re,exports.resolveReceiveType=Ve,exports.resolveRuntimeValue=j,exports.tryResolveClassType=g,exports.typeAnnotation=N,exports.typeOf=ke,exports.typesOverlap=x,exports.unwrapValueType=s,exports.utilitySourcePropertiesFromType=C,exports.validate=Fe,exports.validatedDeserialize=Le,exports.validationAnnotation=ge,exports.validationRegistry=Z,exports.visitType=D,exports.visitTypeSurface=O;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=function(e){return e[e.never=0]=`never`,e[e.any=1]=`any`,e[e.unknown=2]=`unknown`,e[e.void=3]=`void`,e[e.undefined=4]=`undefined`,e[e.null=5]=`null`,e[e.string=6]=`string`,e[e.number=7]=`number`,e[e.boolean=8]=`boolean`,e[e.bigint=9]=`bigint`,e[e.literal=10]=`literal`,e[e.enum=11]=`enum`,e[e.union=12]=`union`,e[e.intersection=13]=`intersection`,e[e.array=14]=`array`,e[e.tuple=15]=`tuple`,e[e.class=16]=`class`,e[e.object=17]=`object`,e[e.objectLiteral=18]=`objectLiteral`,e[e.property=19]=`property`,e[e.propertySignature=20]=`propertySignature`,e[e.method=21]=`method`,e[e.promise=22]=`promise`,e[e.templateLiteral=23]=`templateLiteral`,e}({});function t(e){return!!e&&typeof e==`object`&&typeof e.kind==`number`}var n=class extends Error{code;path;errors;constructor(e,t,n=``){super(t),this.code=e,this.path=n,this.errors=[this]}};Object.defineProperty(n,"name",{configurable:!0,value:`ValidatorError`});var r=class{decorators=[];addDecorator(e,t){this.decorators.push({predicate:e,handler:t})}apply(e,t){let n=t;for(let t of this.decorators){if(!t.predicate(e))continue;let r=new i;t.handler(e,r),n=r.apply(n)}return n}},i=class{transforms=[];addTransform(e){this.transforms.push(e)}apply(e){return this.transforms.reduce((e,t)=>t(e),e)}},a=new r;function o(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(typeof e==`bigint`)return e!==0n;if(typeof e==`string`){if(e===`true`||e===`1`)return!0;if(e===`false`||e===`0`)return!1}return e}function s(t){if(t.kind===e.union){let n=t.types.filter(t=>t.kind!==e.undefined&&t.kind!==e.null);return n.length===1?s(n[0]):t}if(t.kind===e.intersection){let e=c(t);if(e)return e;let n=t.types.find(e=>!p(e));return n?s(n):t}return t}function c(t){if(t.kind!==e.intersection||!l(t))return;let n=u(t);if(n.length!==0)return{kind:e.objectLiteral,typeName:t.typeName,types:n}}function l(t){return t.kind===e.intersection&&t.types.every(t=>p(t)?!0:t.kind===e.intersection?l(t):t.kind===e.objectLiteral)}function u(t){let n=[],r=new Map,i=t=>{let i=String(t.name);r.has(i)||n.push(i),r.set(i,{kind:e.propertySignature,name:t.name,type:t.type,optional:t.optional})},a=t=>{if(!p(t)){if(t.kind===e.intersection){for(let e of t.types)a(e);return}if(t.kind===e.objectLiteral){for(let e of d(t))i(e);return}}};return a(t),n.map(e=>r.get(e))}function d(t,n=new Set){if(n.has(t)||p(t))return[];n.add(t);let r=[];for(let i of t.implements??[]){let t=s(i);n.has(t)||(t.kind===e.objectLiteral?r.push(...d(t,n)):t.kind===e.intersection?r.push(...u(t)):t.kind===e.class&&r.push(...C(t)))}return w([...r,...t.types.map(T)])}function f(t,n=new Set){if(t.index)return t.index;if(!n.has(t)){n.add(t);for(let r of t.implements??[]){let t=s(r);if(t.kind===e.objectLiteral){let e=f(t,n);if(e)return e}}}}function p(e){return!!(e.annotations||e.validation||e.database||ee(e)||ne(e))}function ee(t){return te(t.typeName)?t.kind===e.unknown||t.kind===e.class&&!g(t.classType):!1}function te(e){switch(e){case`ApiName`:case`AutoIncrement`:case`DatabaseField`:case`GreaterThan`:case`HasDefault`:case`Index`:case`Length`:case`LessThan`:case`Maximum`:case`MaxLength`:case`Minimum`:case`MinLength`:case`MySQL`:case`OnUpdate`:case`Pattern`:case`PrimaryKey`:case`Reference`:case`TypeAnnotation`:case`Unique`:return!0;default:return!1}}function ne(t){return t.kind===e.objectLiteral&&t.types.length>0&&t.types.every(t=>t.kind===e.propertySignature&&String(t.name)===`typia.tag`)}function m(t){return t.kind===e.any||t.kind===e.undefined||t.kind===e.union&&t.types.some(m)}function h(t){return t.kind===e.any||t.kind===e.null||t.kind===e.union&&t.types.some(h)}function re(e){let t=g(e);if(!t)throw Error(`Target is not a constructor`);return t}function g(e){if(v(e))return e;try{let t=e();return v(t)?t:void 0}catch{return}}function _(t,n=new Set){if(!t||typeof t!=`object`||n.has(t))return;n.add(t);let r=t;if(r.kind===e.class&&typeof r.classType==`function`&&!v(r.classType))try{let e=r.classType();v(e)&&(r.classType=e)}catch{}for(let e of Object.values(r))if(typeof e!=`function`){if(Array.isArray(e))for(let t of e)_(t,n);else _(e,n)}ie(r),ce(r)}function ie(n){if(n.kind!==e.intersection||!Array.isArray(n.types))return;let r=n.types.filter(t);if(r.length!==n.types.length)return;let i=r.filter(t=>t.kind===e.union);if(i.length===0||i.length===1&&r.every(e=>e===i[0]||p(e)))return;let a=[[]];for(let e of r){let t=ae(e);a=a.flatMap(e=>t.map(t=>[...e,...t]))}n.kind=e.union,n.types=a.map(se)}function ae(t){if(t.kind!==e.union)return[[t]];let n=oe(t);return t.types.flatMap(e=>ae(e).map(e=>n?[...e,n]:e))}function oe(t){if(!(!t.annotations&&!t.validation&&!t.database))return{kind:e.unknown,annotations:t.annotations,validation:t.validation,database:t.database}}function se(t){return t.some(t=>t.kind===e.never)?{kind:e.never}:t.length===1?t[0]:{kind:e.intersection,types:t}}function v(e){return!!(typeof e==`function`&&e.prototype&&e.prototype.constructor===e)}function ce(n){let r=de(n);if(!r)return;let i=Array.isArray(n.typeArguments)?n.typeArguments:[];if(r===`Record`){if(n.kind!==e.objectLiteral||(n.types??[]).length>0)return;let r=i[0],a=i[1];if(!t(r)||!t(a))return;let o=le(r,a);o.length>0?(n.types=o,delete n.index):n.index=a;return}if((n.types??[]).length>0)return;let a=i[0];if(!t(a))return;if(r===`Extract`){let r=i[1];if(n.kind!==e.union||!t(r))return;n.types=y(a).filter(e=>b(e,r));return}if(n.kind!==e.objectLiteral)return;let o=C(a),s=a.kind===e.objectLiteral?f(a):void 0;if(o.length===0){s&&(n.index=s);return}let c=new Set((Array.isArray(n.utilityKeys)?n.utilityKeys:[]).filter(e=>typeof e==`string`)),l=o.map(T);r===`Pick`?l=l.filter(e=>c.has(String(e.name))):r===`Omit`?l=l.filter(e=>!c.has(String(e.name))):r===`Partial`?l=l.map(e=>({...e,optional:!0})):r===`Required`?l=l.map(e=>({...e,optional:void 0})):r===`OptionalNulls`&&(l=l.map(e=>h(e.type)?{...e,optional:!0}:e)),n.types=l,s&&(n.index=s)}function le(t,n){return ue(t).map(t=>({kind:e.propertySignature,name:t,type:n,optional:void 0}))}function ue(t){let n=[];for(let r of y(t)){if(r.kind!==e.literal||typeof r.literal!=`string`&&typeof r.literal!=`number`)return[];n.push(r.literal)}return n}function y(t){return t.kind===e.union?t.types.flatMap(y):[t]}function b(t,n){let r=s(t),i=s(n);if(i.kind===e.union)return i.types.some(e=>b(r,e));if(r.kind===e.union)return r.types.every(e=>b(e,i));if(i.kind===e.objectLiteral){let t=d(i).filter(e=>!e.optional&&!m(e.type));if(t.length===0)return r.kind===e.objectLiteral||r.kind===e.class;let n=C(r);return n.length!==0&&t.every(e=>{let t=n.find(t=>String(t.name)===String(e.name));return t?x(t.type,e.type):!1})}return x(r,i)}function x(t,n){let r=s(t),i=s(n);return r.kind===e.any||r.kind===e.unknown||i.kind===e.any||i.kind===e.unknown?!0:r.kind===e.union?r.types.some(e=>x(e,i)):i.kind===e.union?i.types.some(e=>x(r,e)):r.kind===e.literal&&i.kind===e.literal?r.literal===i.literal:r.kind===e.literal?S(r.literal,i):i.kind===e.literal?S(i.literal,r):r.kind===i.kind}function S(t,n){return t===null?n.kind===e.null:t===void 0?n.kind===e.undefined:typeof t==`string`?n.kind===e.string||n.kind===e.templateLiteral:typeof t==`number`?n.kind===e.number:typeof t==`boolean`?n.kind===e.boolean:typeof t==`bigint`&&n.kind===e.bigint}function C(t){if(t.kind===e.class){let n=g(t.classType);if(!n)return[];try{return G.from(n).getProperties().map(t=>({kind:e.propertySignature,name:t.name,type:t.getType(),optional:t.isOptional()?!0:void 0,description:t.getDescription()||void 0}))}catch(e){if(e instanceof Error&&e.message.startsWith(`No runtime type metadata for `))return[];throw e}}return t.kind===e.objectLiteral?d(t):t.kind===e.intersection?w(t.types.flatMap(C)):[]}function w(e){let t=[],n=new Map;for(let r of e){let e=String(r.name);n.has(e)||t.push(e),n.set(e,T(r))}return t.map(e=>n.get(e))}function T(t){return{kind:e.propertySignature,name:t.name,type:t.type,optional:t.optional?!0:void 0,description:t.description}}function E(e){return e===`Pick`||e===`Omit`||e===`Partial`||e===`Required`||e===`Extract`||e===`Record`||e===`OptionalNulls`}function de(e){if(E(e.utilityType))return e.utilityType;if(E(e.typeName))return e.typeName}function D(t,n){if(n(t),(t.kind===e.union||t.kind===e.intersection)&&`types`in t)for(let e of t.types)D(e,n);else if((t.kind===e.array||t.kind===e.promise)&&`type`in t)D(t.type,n);else if(t.kind===e.objectLiteral&&`types`in t){for(let e of t.types)D(e.type,n);t.index&&D(t.index,n)}}function O(t,n){if(n(t),(t.kind===e.union||t.kind===e.intersection)&&`types`in t)for(let e of t.types)O(e,n)}function fe(e,t){let n;return D(e,r=>{n===void 0&&r!==e&&(n=t(r))}),n}function k(e,t){let n;return O(e,r=>{n===void 0&&r!==e&&(n=t(r))}),n}function pe(e,t){let n=!1;return D(e,e=>{n||=t(e)}),n}function A(t){return t?.kind===e.literal&&typeof t.literal==`number`?t.literal:void 0}function j(t){if(!t)return;let n=t.runtime;if(n!==void 0)return typeof n==`function`?n():n;if(t.kind===e.literal)return t.literal}function M(e,t){return e?`${e}.${t}`:t}function me(t){let n=N.getType(t,`tsf:type`);return n?.kind===e.literal&&(n.literal===`uuid`||n.literal===`uuidString`)}function he(t){let n=N.getType(t,`tsf:type`);return n?.kind===e.literal&&n.literal===`uuid`}var N={getType(e,t){return e.annotations?.[t]||(k(e,e=>e.annotations?.[t])??ve(e,t))},getOption(e,t){return this.getType(e,t)}},ge={getAnnotations(e){let t=[],n=new Set;return O(e,e=>{if(e.validation)for(let r of e.validation){let e=Ee(r);n.has(e)||(n.add(e),t.push(r))}let r=be(e);if(r){let e=Ee(r);n.has(e)||(n.add(e),t.push(r))}}),t}},P={getDatabase(t,n){let r=t.database?.[n]??(n===`*`?void 0:t.database?.[`*`]);if(r)return r;if(t.kind===e.union){let r=t.types.filter(t=>t.kind!==e.null&&t.kind!==e.undefined);return r.length===1?this.getDatabase(r[0],n):void 0}let i=k(t,e=>e.database?.[n]??(n===`*`?void 0:e.database?.[`*`]));if(i)return i;let a=xe(t,n);if(a)return a}},F={kind:e.undefined};function _e(t){return{kind:e.literal,literal:t}}function I(e,...t){return{name:e,args:t}}function ve(e,t){return we(e,e=>ye(e,t))}function ye(e,t){let n=L(e);if(!(!n||n.kind!==t)&&!(!n.kind.startsWith(`tsf:`)&&!n.kind.startsWith(`openapi:`)))return n.value??F}function be(e){let t=L(e);if(t)switch(t.kind){case`minLength`:case`maxLength`:case`minimum`:case`greaterThan`:case`maximum`:case`lessThan`:return t.value?I(t.kind,t.value):void 0;case`pattern`:return I(`pattern`,t.value??R(t.schema,`pattern`)??F);case`format`:{let e=B(t.value)??B(R(t.schema,`format`)),n=e?Te(e):void 0;return n?I(`pattern`,_e(n)):void 0}case`tsf:validator`:return I(`validator`,t.value??F);default:return}}function xe(e,t){return we(e,e=>Se(e,t))}function Se(e,t){let n=L(e);if(!n)return;let r=V(n.schema)??V(n.value);if(r&&(n.kind===`database:field`||n.kind===`database:mysql`&&t===`mysql`))return r}function L(t){if(t.kind!==e.objectLiteral)return;let n=t.types.find(e=>String(e.name)===`typia.tag`);if(!n)return;let r=z(n.type);if(r.kind!==e.objectLiteral)return;let i=B(R(r,`kind`));if(i)return{kind:i,value:R(r,`value`),schema:R(r,`schema`)}}function R(t,n){let r=t?z(t):void 0;if(!(!r||r.kind!==e.objectLiteral))return r.types.find(e=>String(e.name)===n)?.type}function z(t){if(t.kind!==e.union)return t;let n=t.types.filter(t=>t.kind!==e.undefined&&t.kind!==e.null);return n.length===1?n[0]:t}function B(t){return t?.kind===e.literal&&typeof t.literal==`string`?t.literal:void 0}function V(t){let n=t?z(t):void 0;if(!n||n.kind!==e.objectLiteral)return;let r={};for(let e of n.types){let t=Ce(e.type);t!==void 0&&(r[String(e.name)]=t)}return r}function Ce(t){let n=z(t);if(n.kind===e.literal)return n.literal;if(n.kind!==e.undefined&&n.kind===e.objectLiteral)return V(n)}function we(e,t){let n;return O(e,e=>{n===void 0&&(n=t(e))}),n}function Te(e){switch(e){case`date`:return`^\\d{4}-\\d{2}-\\d{2}$`;case`email`:return`^[a-zA-Z0-9_+.-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]+$`;case`uuid`:return`^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$`;default:return}}function Ee(e){return`${e.name}:${e.args.map(De).join(`|`)}`}function De(t){if(t.kind===e.literal&&`literal`in t)return`literal:${String(t.literal)}`;let n=t.runtime;return n?`runtime:${String(n)}`:`${t.kind}:${t.typeName??``}`}function Oe(t){let n=N.getType(t,`tsf:type`);if(n?.kind===e.literal){if(n.literal===`integer`)return e.number;if(typeof n.literal==`string`)return e.string}}var H=new WeakMap,U=new WeakMap;function W(e,t){t&&(t.collectionName&&(e.collectionName=t.collectionName),t.indexes?.length&&(e.indexes=[...t.indexes]),t.excludeMigration&&(e.excludeMigration=!0))}function ke(e){if(!e)throw Error(`typeOf<T>() was not transformed by the metadata compiler`);return _(e),e}function Ae(e,t){t.classType=e,W(t,U.get(e)),H.set(e,t)}var G=class t{classType;name;indexes;metadata;constructor(e,t){this.classType=e,this.metadata=t,this.name=t.name||e.name;let n=t.properties.flatMap(e=>{let t=[];return e.index&&t.push({names:[e.name],options:e.index}),e.unique&&t.push({names:[e.name],options:{...e.unique,unique:!0}}),t});this.indexes=[...t.indexes??[],...n]}static from(e){let n=J(e);if(!n)throw Error(`No runtime type metadata for ${e.name}. Did the tsf metadata compiler run?`);return new t(e,n)}getClassType(){return this.classType}getCollectionName(){return this.metadata.collectionName??U.get(this.classType)?.collectionName}isDatabaseMigrationSkipped(e){return this.metadata.excludeMigration===!0||U.get(this.classType)?.excludeMigration===!0}getProperties(){return Y(this.classType,this.metadata).map(e=>new K(e))}getProperty(e){let t=Y(this.classType,this.metadata).find(t=>t.name===e);if(!t)throw Error(`Property ${String(e)} does not exist on ${this.name}`);return new K(t)}getPrimary(){let e=Y(this.classType,this.metadata).find(e=>e.primaryKey);if(!e)throw Error(`Class ${this.name} has no primary key`);return new K(e)}getMethod(e){let t=Me(this.classType,this.metadata).find(t=>t.name===e||String(t.name)===String(e));if(!t)throw Error(`Method ${String(e)} does not exist on ${this.name}`);return new q(t)}getConstructorOrUndefined(){let t=Ne(this.classType,this.metadata);if(t.length)return new q({name:`constructor`,parameters:t,returnType:{kind:e.void}})}},K=class{metadata;type;name;constructor(e){this.metadata=e,this.type=e.type,this.name=e.name}getNameAsString(){return String(this.name)}getType(){return this.type}getDescription(){return this.metadata.description??``}isPublic(){return!0}isPrimaryKey(){return this.metadata.primaryKey===!0}isAutoIncrement(){return this.metadata.autoIncrement===!0}isOptional(){return this.metadata.optional===!0||m(this.type)}isNullable(){return h(this.type)}getDatabase(e=`*`){return P.getDatabase(this.type,e)||P.getDatabase(this.type,`*`)}isBackReference(){return!1}isDatabaseSkipped(e){return!1}isDatabaseMigrationSkipped(e){return!1}isReference(){return this.metadata.reference!==void 0}getReference(){return this.metadata.reference}getResolvedReflectionClass(){let t=s(this.type);if(t.kind!==e.class)throw Error(`Property ${String(this.name)} is not a class reference`);return G.from(re(t.classType))}},q=class{metadata;constructor(e){this.metadata=e}getDescription(){return this.metadata.description??``}getParameters(){return this.metadata.parameters.map(e=>new je(e))}getReturnType(){return this.metadata.returnType}},je=class{metadata;constructor(e){this.metadata=e}getName(){return this.metadata.name}getType(){return this.metadata.type}isOptional(){return this.metadata.optional===!0||m(this.metadata.type)}hasDefault(){return this.metadata.default===!0}};function J(t){let n=H.get(t);if(n)return _(n),n;let r=Object.prototype.hasOwnProperty.call(t,`__tsfType`)?t.__tsfType:void 0;if(!r){if(!X(t))return;let n={kind:e.class,classType:t,name:t.name,typeName:t.name,properties:[],methods:[],constructorParameters:[],hasConstructor:!0};return W(n,U.get(t)),H.set(t,n),n}return W(r,U.get(t)),_(r),H.set(t,r),r}function Y(e,t){let n=X(e),r=n?Y(n.classType,n.metadata):[],i=new Set(t.properties.map(e=>e.name));return[...r.filter(e=>!i.has(e.name)),...t.properties]}function Me(e,t){let n=X(e),r=n?Me(n.classType,n.metadata):[],i=new Set(t.methods.map(e=>e.name));return[...r.filter(e=>!i.has(e.name)),...t.methods]}function Ne(e,t){if(t.constructorParameters.length||t.hasConstructor)return t.constructorParameters;let n=X(e);return n?Ne(n.classType,n.metadata):[]}function X(e){let t=(e.prototype?Object.getPrototypeOf(e.prototype):void 0)?.constructor;if(!t||t===Object||t===e)return;let n=J(t);return n?{classType:t,metadata:n}:void 0}var Pe=new Map,Z={register(e,t){Pe.set(e,t)},get(e){return Pe.get(e)}};function Fe(e,t){let n=He(e,t);return n?Q(e,n):[]}function Ie(e,t){if(!t)throw Error(`deserialize<T>() was not transformed by the metadata compiler`);return _(t),$(e,t)}function Le(e,t,n,r,i){if(!i)throw Error(`validatedDeserialize<T>() requires reflected type metadata`);_(i);let a=$(e,i),o=Q(a,i);if(o.length)throw o[0];return a}function Re(e,t,n){if(!n)throw Error(`assert<T>() requires explicit reflected type metadata`);_(n);let r=Q(e,n);if(r.length)throw r[0]}function ze(e,t,n){if(!n)throw Error(`is<T>() requires explicit reflected type metadata`);return _(n),Q(e,n).length===0}function Be(e,t,n,r,i){if(!i)throw Error(`cast<T>() requires explicit reflected type metadata`);return _(i),$(e,i)}function Ve(e){if(t(e))return e;throw Error(`Unsupported receive type payload`)}function He(e,n){if(t(n))return _(n),n;if(typeof n==`function`)return J(n);if(e&&typeof e==`object`)return J(e.constructor)}function Q(t,r,i=``){let a=[],o=s(r),c=Oe(o);if(t===void 0)return m(r)||a.push(new n(`required`,`The value is required.`,i)),a;if(t===null)return h(r)||a.push(new n(`required`,`The value cannot be null.`,i)),a;if(c===e.string)typeof t!=`string`&&a.push(new n(`type`,`The value must be a string.`,i));else if(c===e.number)(typeof t!=`number`||Number.isNaN(t))&&a.push(new n(`type`,`The value must be a number.`,i));else if(c===e.boolean)typeof t!=`boolean`&&a.push(new n(`type`,`The value must be a boolean.`,i));else if(o.kind===e.undefined||o.kind===e.null||o.kind===e.never)a.push(new n(`type`,`The value does not match the required type.`,i));else if(o.kind===e.string||o.kind===e.templateLiteral)typeof t!=`string`&&a.push(new n(`type`,`The value must be a string.`,i));else if(o.kind===e.number)(typeof t!=`number`||Number.isNaN(t))&&a.push(new n(`type`,`The value must be a number.`,i));else if(o.kind===e.boolean)typeof t!=`boolean`&&a.push(new n(`type`,`The value must be a boolean.`,i));else if(o.kind===e.array)Array.isArray(t)?t.forEach((e,t)=>{a.push(...Q(e,o.type,M(i,String(t))))}):a.push(new n(`type`,`The value must be an array.`,i));else if(o.kind===e.tuple)Array.isArray(t)?o.types.forEach((e,n)=>{a.push(...Q(t[n],e.type,M(i,String(n))))}):a.push(new n(`type`,`The value must be an array.`,i));else if(o.kind===e.union){let e=o.types.map(e=>Q(t,e,i));if(!e.some(e=>e.length===0)){let t=e.filter(e=>e.length>0).sort((e,t)=>e.length-t.length)[0];t?.length?a.push(...t):a.push(new n(`type`,`The value does not match any allowed type.`,i))}}else if(o.kind===e.objectLiteral){if(!t||typeof t!=`object`||Array.isArray(t))return a.push(new n(`type`,`The value must be an object.`,i)),a;let e=t,r=new Set;for(let t of d(o)){r.add(String(t.name));let n=M(i,String(t.name));e[t.name]===void 0&&t.optional||a.push(...Q(e[t.name],t.type,n))}let s=f(o);if(s)for(let[t,n]of Object.entries(e))r.has(t)||a.push(...Q(n,s,M(i,t)))}else if(o.kind===e.literal)t!==o.literal&&a.push(new n(`type`,`The value must be ${String(o.literal)}.`,i));else if(o.kind===e.enum)o.values.includes(t)||a.push(new n(`type`,`The value does not match any allowed enum value.`,i));else if(o.kind===e.class){let e=g(o.classType);if(!e)return(!t||typeof t!=`object`||Array.isArray(t))&&a.push(new n(`type`,`The value must be an object.`,i)),a;if(e!==Date){let n=G.from(e),r=t;for(let e of n.getProperties())r[String(e.name)]===void 0&&e.isOptional()||a.push(...Q(r[String(e.name)],e.getType(),M(i,String(e.name))))}}for(let e of ge.getAnnotations(r))if(e.name===`minLength`&&typeof t==`string`){let r=A(e.args[0]);r!==void 0&&t.length<r&&a.push(new n(`minLength`,`The value must be at least ${r} characters.`,i))}else if(e.name===`maxLength`&&typeof t==`string`){let r=A(e.args[0]);r!==void 0&&t.length>r&&a.push(new n(`maxLength`,`The value must be at most ${r} characters.`,i))}else if(e.name===`minimum`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t<r&&a.push(new n(`minimum`,`The value must be at least ${r}.`,i))}else if(e.name===`greaterThan`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t<=r&&a.push(new n(`greaterThan`,`The value must be greater than ${r}.`,i))}else if(e.name===`maximum`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t>r&&a.push(new n(`maximum`,`The value must be at most ${r}.`,i))}else if(e.name===`lessThan`&&typeof t==`number`){let r=A(e.args[0]);r!==void 0&&t>=r&&a.push(new n(`lessThan`,`The value must be less than ${r}.`,i))}else if(e.name===`pattern`&&typeof t==`string`){let r=j(e.args[0]),o=typeof r==`string`?new RegExp(r):r instanceof RegExp?r:void 0;o&&!o.test(t)&&a.push(new n(`pattern`,`The value does not match the required pattern.`,i))}else if(e.name===`validate`){let r=j(e.args[0]);if(typeof r==`function`){let e=r(t);e instanceof n&&a.push(new n(e.code,e.message,i))}}else if(e.name===`validator`){let r=j(e.args[0]),o=typeof r==`string`?Z.get(r):void 0;if(o){let e=o(t);e instanceof n&&a.push(new n(e.code,e.message,i))}}return a}function $(t,n){if(t==null)return t;if(n.kind===e.intersection){let e=c(n);if(e&&t&&typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date))return a.apply(n,$(t,e));let r=t;if(t&&typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date)){let e={},i=!1;for(let r of n.types){let n=$(t,r);n&&typeof n==`object`&&!Array.isArray(n)&&!(n instanceof Date)&&(Object.assign(e,n),i=!0)}r=i?e:t}else for(let e of n.types)r=$(r,e);return a.apply(n,r)}let r=s(n),i=t;if(r.kind===e.number&&typeof t==`string`&&t.trim()!==``)i=Number(t);else if(r.kind===e.boolean)i=o(t);else if(r.kind===e.enum&&typeof t==`string`){let e=Number(t);!Number.isNaN(e)&&r.values.includes(e)&&(i=e)}else if(r.kind===e.array&&Array.isArray(t))i=t.map(e=>$(e,r.type));else if(r.kind===e.tuple&&Array.isArray(t))i=r.types.map((e,n)=>$(t[n],e.type));else if(r.kind===e.union)for(let e of r.types){let n=$(t,e);if(Q(n,e).length===0){i=n;break}}else if(r.kind===e.class){let e=g(r.classType);if(!e)return a.apply(n,t);if(e===Date)return a.apply(n,t instanceof Date?t:new Date(t));if(typeof t!=`object`)return a.apply(n,t);let o=new e,s=t;for(let t of G.from(e).getProperties())o[String(t.name)]=$(s[String(t.name)],t.getType());i=o}else if(r.kind===e.objectLiteral&&typeof t==`object`){let e=d(r),o=f(r);if(e.length===0&&!o)return a.apply(n,t);let s=t,c={},l=new Set;for(let t of e){let e=String(t.name);l.add(e),c[e]=$(s[e],t.type)}if(o)for(let[e,t]of Object.entries(s))l.has(e)||(c[e]=$(t,o));i=c}return a.apply(n,i)}var Ue=class{x;y};Ae(Ue,{kind:e.class,classType:Ue,name:`Coordinate`,typeName:`Coordinate`,properties:[{name:`x`,type:{kind:e.number}},{name:`y`,type:{kind:e.number}}],methods:[],constructorParameters:[],hasConstructor:!1});function We(e){if(!(e instanceof Date)||Number.isNaN(e.getTime()))return new n(`invalidDate`,`The date is invalid.`)}Z.register(`validDate`,We);function Ge(e,...t){for(let n of t){let t=N.getType(e,n);if(t)return t}}a.addDecorator(e=>Ge(e,`tsf:trim`)!==void 0,(e,t)=>{t.addTransform(e=>typeof e==`string`?e.trim():e)});var Ke=/^[a-z0-9_+.-]+@[a-z0-9-.]+\.[a-z]+$/i;function qe(e){return typeof e==`function`?e.name||`anonymous class`:e&&typeof e==`object`?e.constructor?.name||`anonymous class`:String(e)}exports.Coordinate=Ue,exports.DeserializerRegistry=r,exports.DeserializerState=i,exports.EMAIL_REGEX=Ke,exports.ReflectionClass=G,exports.ReflectionKind=e,exports.ReflectionMethod=q,exports.ReflectionParameter=je,exports.ReflectionProperty=K,exports.ValidationError=n,exports.ValidatorError=n,exports.allowsNull=h,exports.allowsUndefined=m,exports.applyMetadataOptions=W,exports.assert=Re,exports.cast=Be,exports.classMetadata=H,exports.classOptions=U,exports.cloneUtilityProperty=T,exports.coerceBooleanValue=o,exports.databaseAnnotation=P,exports.deserialize=Ie,exports.deserializer=a,exports.expandUtilityTypeMetadata=ce,exports.findNested=fe,exports.findNestedSurface=k,exports.flattenRuntimeUnionTypes=y,exports.getClassName=qe,exports.getFirstTypeAnnotation=Ge,exports.getUtilityTypeName=de,exports.hasNestedType=pe,exports.is=ze,exports.isClass=v,exports.isDatabaseUUIDType=he,exports.isExtractAssignable=b,exports.isMarkerType=p,exports.isReflectedType=t,exports.isUUIDType=me,exports.isUtilityTypeName=E,exports.joinPath=M,exports.knownPrimitiveKind=Oe,exports.literalMatchesType=S,exports.literalNumber=A,exports.mergeStructuredProperties=u,exports.mergeUtilityProperties=w,exports.mergedIntersectionObjectLiteral=c,exports.normalizeTypeMetadata=_,exports.objectLiteralIndexType=f,exports.objectLiteralPropertiesFromType=d,exports.readClassMetadata=J,exports.recordLiteralKeysFromType=ue,exports.recordPropertiesFromKeyType=le,exports.registerClassMetadata=Ae,exports.resolveClassType=re,exports.resolveReceiveType=Ve,exports.resolveRuntimeValue=j,exports.tryResolveClassType=g,exports.typeAnnotation=N,exports.typeOf=ke,exports.typesOverlap=x,exports.unwrapValueType=s,exports.utilitySourcePropertiesFromType=C,exports.validate=Fe,exports.validatedDeserialize=Le,exports.validationAnnotation=ge,exports.validationRegistry=Z,exports.visitType=D,exports.visitTypeSurface=O;
package/dist/index.js CHANGED
@@ -945,6 +945,22 @@ var Ue = class {
945
945
  x;
946
946
  y;
947
947
  };
948
+ Ae(Ue, {
949
+ kind: e.class,
950
+ classType: Ue,
951
+ name: "Coordinate",
952
+ typeName: "Coordinate",
953
+ properties: [{
954
+ name: "x",
955
+ type: { kind: e.number }
956
+ }, {
957
+ name: "y",
958
+ type: { kind: e.number }
959
+ }],
960
+ methods: [],
961
+ constructorParameters: [],
962
+ hasConstructor: !1
963
+ });
948
964
  function We(e) {
949
965
  if (!(e instanceof Date) || Number.isNaN(e.getTime())) return new n("invalidDate", "The date is invalid.");
950
966
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type-annotations.d.ts","sourceRoot":"","sources":["../../src/types/type-annotations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,IAAI,EACJ,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,eAAe,EAClB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7H,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;AAC3E,MAAM,MAAM,UAAU,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;AAC5C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AAC3F,YAAY,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjD,qBAAa,UAAU;IACnB,CAAC,EAAG,MAAM,CAAC;IACX,CAAC,EAAG,MAAM,CAAC;CACd;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACpE,MAAM,MAAM,uBAAuB,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,GAAG,IAAI,CAAC;AAErF,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;AAUrH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAEtE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACvE,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEjE,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,oBAKjE;AASD,eAAO,MAAM,WAAW,QAAyC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"type-annotations.d.ts","sourceRoot":"","sources":["../../src/types/type-annotations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,IAAI,EACJ,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,eAAe,EAClB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7H,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;AAC3E,MAAM,MAAM,UAAU,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;AAC5C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AAC3F,YAAY,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjD,qBAAa,UAAU;IACnB,CAAC,EAAG,MAAM,CAAC;IACX,CAAC,EAAG,MAAM,CAAC;CACd;AAgBD,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACpE,MAAM,MAAM,uBAAuB,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,GAAG,IAAI,CAAC;AAErF,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;AAUrH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAEtE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACvE,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEjE,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,oBAKjE;AASD,eAAO,MAAM,WAAW,QAAyC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyno-io/ts-reflection",
3
- "version": "26.911.1944",
3
+ "version": "26.912.2242",
4
4
  "description": "Browser-neutral TypeScript reflection and runtime metadata",
5
5
  "license": "MIT",
6
6
  "files": [