(function(p,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(p=typeof globalThis<"u"?globalThis:p||self,N(p.UntypedJSON={}))})(this,function(p){"use strict";class N{}const v=Symbol("UntypedJSONMetadata"),S=r=>r.hasOwnProperty(v)?r[v]:Object.create({mixins:[],options:{},properties:Object.create(null)}),T=r=>r===String||r===Number||r===Boolean,I=(r,n,e)=>function(o,t){var l,s;const y=Array.isArray(n);let i=!1,a,P=n;T(n)||y&&T(n[0])?P=y?[(l=n[0].name)==null?void 0:l.toLowerCase()]:(s=n.name)==null?void 0:s.toLowerCase():(i=y?typeof n[0]=="function":typeof n=="function",a=i?y?n[0]:n:void 0);const w={array:y,classType:a,jsonProperty:r,nested:i,nullabilityMode:e,type:P},u=o.constructor,c=S(u);c.properties[t]=w,u[v]=c},J=(...r)=>function(n){const e=S(n);e.mixins=r,n[v]=e},g=r=>function(n){const e=S(n);e.options=r,n[v]=e};var d=(r=>(r[r.MAP=0]="MAP",r[r.IGNORE=1]="IGNORE",r[r.PASS=2]="PASS",r))(d||{}),O=(r=>(r.ANY="any",r.BOOLEAN="boolean",r.NUMBER="number",r.OBJECT="object",r.STRING="string",r))(O||{});const k="string",R="number",B="boolean",C="object",G="any",$=(r,n,e)=>{const{nullabilityMode:o,jsonProperty:t}=n;if(!(o===d.IGNORE&&(e[t]===null||e[t]===void 0))&&!(o===d.PASS&&(e[t]===null||e[t]===void 0))){if(o===d.MAP&&e[t]===null)throw new TypeError(`Property ${t} is not a ${n.type}. It is null.`);if(!e.hasOwnProperty(t))throw new ReferenceError(`Property ${t} is not defined in the JSON.\r ${JSON.stringify(e,null,4)}`)}},D=(r,n,e,o)=>{const{jsonProperty:t,nullabilityMode:y}=n;let i=n.type;if(i===void 0&&o===void 0)throw new TypeError(`Property ${r} does not have a type and cannot be inferred from the default value.`);if(!(i===O.ANY&&o===void 0)&&(o!==void 0&&i===void 0&&(i=o),!((typeof e[t]>"u"||e[t]===null)&&y===(d.IGNORE||d.PASS)))){if(Array.isArray(i)){if(!Array.isArray(e[t]))throw new TypeError(`Property ${t} is not an array. It is a ${typeof e[t]}.`);if(i.length!==1)throw new TypeError(`Property ${t} is an array of multiple types. This is not supported.`);const a=i[0];if(a===O.ANY)return;for(const P of e[t])if(typeof P!==a&&typeof a!="function"||typeof a=="function"&&typeof P!="object")throw new TypeError(`Property ${t} is not an array of ${a}. It is an array of ${typeof P}.`);return}if(typeof i=="function"&&Object.getPrototypeOf(i.prototype).constructor.name==="JsonConverter"){if(typeof i.prototype.Deserialize!="function"||typeof i.prototype.Serialize!="function")throw new TypeError(`Property ${r} is a JsonConverter without a Serialize and/or Deserialize method.`);return}if(typeof i=="function"&&typeof e[t]!="object")throw new TypeError(`Property ${t} is not an object. It is a ${typeof e[t]}.`);if(typeof i=="function"&&typeof e[t]=="object")return;if(i!==typeof e[t]&&i!==O.ANY)throw new TypeError(`Property ${t} is not a ${i}${o?" (inferred)":""}. It is a ${typeof e[t]}.`)}},h=(r,n,e,o,t=!1,y)=>{const{jsonProperty:i,array:a,nested:P,classType:w,type:u,nullabilityMode:c}=n,l=t?r:i,s=t?i:r;if(!t){const f=o[s]===null||o[s]===void 0?void 0:typeof o[s];D(r,n,e,f)}if(typeof u=="function"&&typeof u.prototype.Deserialize=="function"){o[s]=u.prototype.Deserialize(e[l]);return}else if(typeof u=="function"&&typeof u.prototype.Serialize=="function"){e[s]=u.prototype.Serialize(e[l]);return}if(P)a?o[s]=e[l].map(f=>t?E(f,y):b(f,w,y)):o[s]=t?E(e[l],y):b(e[l],w,y);else if(a){if(w===void 0){if(c===d.IGNORE&&(e[l]===null||e[l]===void 0))return;o[s]=e[l];return}o[s]=e[l].map(f=>t?E(f):b(f,w))}else{if(c===d.IGNORE&&(e[l]===null||e[l]===void 0))return;o[s]=e[l]}},b=(r,n,e)=>{var i,a,P,w,u;const o=typeof r=="string"?JSON.parse(r):r;if(typeof o!="object")throw new TypeError("json is not an object or string.");const t=new n;let y=n;for(;y!==null&&(y==null?void 0:y.prototype)!==Object.prototype;){const c=S(y);for(const s of c.mixins){const f=b(o,s,e);Object.assign(t,f);const A=Object.getOwnPropertyNames(s.prototype);for(const M of A){const m=Object.getOwnPropertyDescriptor(s.prototype,M);m!==void 0&&M!=="constructor"&&Object.defineProperty(t,M,m)}}const l=Object.keys(c==null?void 0:c.properties);for(const s of l)(a=c.properties[s]).nullabilityMode??(a.nullabilityMode=((i=c.options)==null?void 0:i.defaultNullabilityMode)??d.MAP),$(s,c.properties[s],o),h(s,c.properties[s],o,t,!1,e);if((y==null?void 0:y.prototype)!==void 0){if((P=c.options)!=null&&P.mapClassProperties||e!=null&&e.mapClassProperties){const s=Object.keys(t);for(const f of s)if(!l.includes(f)){const A={array:Array.isArray(t[f]),jsonProperty:f,nested:!1,nullabilityMode:((w=c.options)==null?void 0:w.defaultNullabilityMode)??d.MAP,type:O.ANY};$(f,A,o),h(f,A,o,t,!1,e)}}if((u=c.options)!=null&&u.passUnknownProperties||e!=null&&e.passUnknownProperties){const s=Object.keys(o).filter(f=>!Object.values(c.properties).some(A=>A.jsonProperty===f));for(const f of s)t[f]=o[f]}}y=Object.getPrototypeOf(y)}return t},E=(r,n)=>{const e={};let o=r.constructor;for(;o!==null&&(o==null?void 0:o.prototype)!==Object.prototype;){const t=S(o),y=Object.keys(t==null?void 0:t.properties);for(const i of y)h(i,t.properties[i],r,e,!0,n);if(n!=null&&n.passUnknownProperties&&o===r.constructor){const i=Object.keys(r).filter(a=>!y.includes(a));for(const a of i)e[a]=r[a]}o=Object.getPrototypeOf(o)}return e};p.ANY=G,p.BOOLEAN=B,p.DeserializeObject=b,p.JsonConverter=N,p.JsonMixin=J,p.JsonOptions=g,p.JsonProperty=I,p.JsonType=O,p.NUMBER=R,p.OBJECT=C,p.PropertyNullability=d,p.STRING=k,p.SerializeObject=E,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=untypedjson.umd.cjs.map