(function(r,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(r=typeof globalThis<"u"?globalThis:r||self,h(r.corello={}))})(this,function(r){"use strict";function h(e,n){let t=e;for(;t;){if(t===n)return!0;t=Object.getPrototypeOf(t)}return!1}const b=e=>typeof e=="function",E=(e,n=!0)=>{let t=Object.getOwnPropertyNames(e);return!n&&(t=t.filter(l=>{var o;return!((o=Object.getOwnPropertyDescriptor(e,l))!=null&&o.get)})),t},D=({instance:e,methodPrefix:n=void 0,ignoreGetters:t=!1,both:l=!1})=>{const o={},a=u=>{E(u,!t).forEach(c=>{const s=u[c];(l||n===void 0)&&(b(s)||(o[c]=s)),(l||n!==void 0)&&c.startsWith(l?n||"":n)&&b(s)&&(o[c]=s)}),u!==Object.prototype&&a(Object.getPrototypeOf(u))};return a(e),Object.freeze(o)},v=e=>e instanceof Date,j=e=>typeof e=="function"&&/^class\s/.test(Function.prototype.toString.call(e)),P=e=>e!==Object(e),d=Symbol("?"),y=Symbol(),m=Symbol();function $(e){if(!h(e,S))throw new Error(`${e.name} needs to have DtoBase in its inhertiance chain.`);const n=e.name||"";return class extends e{constructor(...t){super(t==null?void 0:t[0]);const l=(t==null?void 0:t[0])||{};!this[d]&&Object.defineProperty(this,d,{enumerable:!0,configurable:!1,get:function(){return Object.freeze({name:e.name,instance:this})}}),!this[m]&&Object.defineProperty(this,m,{enumerable:!1,configurable:!1,value:function(o){const a=D({instance:this,ignoreGetters:!1}),u=(i,c,s,O,...w)=>{if(Array.isArray(c)){if(!Array.isArray(s))throw new Error(`Expected Array for [${i}] but the received json is not an Array!`);return s.map((f,A)=>u(i,f,f,O,A))}else if(v(c))if(O){const f=O();return j(f)||f===Date?new f(s,...w):f(s,...w)}else return s?new Date(s):new Date;else if(O){const f=O();return j(f)||f===Date?new f(s,...w):f(s,...w)}else return P(c)?s:(Object.getPrototypeOf(c)===Object.prototype&&console.warn(`Missing a possible factory to serialize ${n?n+".":""}${i}, will treat [${JSON.stringify(c)}] as plain object`),c.constructor?new c.constructor(s):s)};Object.entries(a).forEach(([i,c])=>{var s;o[i]!==void 0&&(this[i]=u(i,this[i],o[i],(s=this[y])==null?void 0:s[i]))})}}),this[m](l)}toJSON(){const t=Object.assign({},this),l=o=>{Object.entries(Object.getOwnPropertyDescriptors(o)).filter(([a,u])=>b(u.get)).map(([a,u])=>{if(u&&a[0]!=="_")try{const i=this[a];t[a]=i}catch(i){console.error(`Error calling getter ${a}`,i)}}),o!==Object.prototype&&l(Object.getPrototypeOf(o))};return l(this),t}toString(){return`[DTO:${n}]`}}}function p(e){return function(n,t){!n[y]&&(n[y]={}),n[y][t]=e}}function F(e){return function(n,t){if(j(e()))throw new Error(`Factory must return an instance, update your factory for property ${t} to return NEW instnace`);!n[y]&&(n[y]={}),n[y][t]=()=>e}}class S{constructor(n){}from(n){return this[m](n)}}r.Class=p,r.Dto=$,r.DtoBase=S,r.Factory=F,r.extract=D,r.hasParentClass=h,r.isClass=j,r.isDate=v,r.isFn=b,r.isPrimitive=P,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});