/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@data-client/endpoint@0.16.6/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";function isImmutable(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function denormalizeImmutable(e,t,r){let n;const i=Object.keys(e).reduce(((t,i)=>{const s=`${i}`,o=r(e[s],t.get(s));return"symbol"==typeof o&&(n=o),t.has(s)?t.set(s,o):t}),t);return null!=n?n:i}class PolymorphicSchema{schema;constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){e._hoistable&&!this._schemaAttribute?(this.schema=e.schema,this._schemaAttribute=e._schemaAttribute):this.schema=e}getSchemaAttribute(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}schemaKey(){return this.isSingleSchema?this.schema.key:Object.values(this.schema).join(";")}normalizeValue(e,t,r,n,i){if(!e)return e;const s=this.isSingleSchema,o=s?this.schema:this.schema[this._schemaAttribute(e,t,r)];if(!o){if("production"!==process.env.NODE_ENV){const n=this._schemaAttribute(e,t,r);console.warn(`Schema attribute ${JSON.stringify(n,void 0,2)} is not expected.\nExpected one of: ${Object.keys(this.schema).map((e=>`"${e}"`)).join(", ")}\n\nValue: ${JSON.stringify(e,void 0,2)}`)}return e}const a=i(o,e,t,r,n);return s||null==a?a:{id:a,schema:this._schemaAttribute(e,t,r)}}denormalizeValue(e,t){const r=this.isSingleSchema,n=!r&&e&&(isImmutable(e)?e.get("schema"):e.schema);if(!r&&!n){if("object"==typeof e&&null!==e){const r=this.inferSchema(e,void 0,void 0);if(r)return t(r,e)}return"production"!==process.env.NODE_ENV&&e&&console.warn(`TypeError: Unable to determine schema for ${this.constructor.name}\nValue: ${JSON.stringify(e,void 0,2)}.`),e}const i=r?void 0:isImmutable(e)?e.get("id"):e.id;return t(r?this.schema:this.schema[n],i||e)}}class UnionSchema extends PolymorphicSchema{_hoistable=!0;constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,i){return this.normalizeValue(e,t,r,n,i)}denormalize(e,t,r){return this.denormalizeValue(e,r)}queryKey(e,t){if(!e[0])return;const r=this.getSchemaAttribute(e[0],void 0,""),n=this.schema[r];if(n){const i=t(n,e);if(void 0===i)return;return{id:i,schema:r}}for(const r in this.schema){const n=t(this.schema[r],e);if(void 0!==n)return{id:n,schema:r}}}}class ValuesSchema extends PolymorphicSchema{normalize(e,t,r,n,i,s){const o={},a=Object.keys(e);for(let t=0;t<a.length;t++){const r=a[t],s=e[r];null!=s&&(o[r]=this.normalizeValue(s,e,r,n,i))}return o}denormalize(e,t,r){const n={},i=Object.keys(e);for(let t=0;t<i.length;t++){const s=i[t],o=e[s],a=this.denormalizeValue(o,r);a&&"symbol"!=typeof a&&(n[s]=a)}return n}queryKey(e,t,r){}}const getValues=e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])),filterEmpty=e=>void 0!==e&&"symbol"!=typeof e;class ArraySchema extends PolymorphicSchema{normalize(e,t,r,n,i){return getValues(e).map((e=>this.normalizeValue(e,t,r,n,i)))}denormalize(e,t,r){return e.map?e.map((e=>this.denormalizeValue(e,r))).filter(filterEmpty):e}queryKey(e,t,r){}toJSON(){return[this.schema]}}class AllSchema extends ArraySchema{constructor(e,t){super(e,t)}normalize(e,t,r,n,i){super.normalize(e,t,r,n,i)}queryKey(e,t,r){if(this.isSingleSchema){const e=r.getEntities(this.schema.key);return e?[...e.keys()]:r.INVALID}let n=!1;const i=Object.values(this.schema).flatMap((e=>{const t=r.getEntities(e.key);if(!t)return[];n=!0;const i=[];for(const[r,n]of t.entries())n&&"symbol"!=typeof n&&i.push({id:e.pk(n,void 0,r,[]),schema:this.getSchemaAttribute(n,void 0,r)});return i}));return n?i:r.INVALID}}const normalize=(e,t,r,n,i,s)=>{const o={...t},a=Object.keys(e);for(let r=0;r<a.length;r++){const n=a[r],c=s(e[n],t[n],t,n,i);void 0===c?delete o[n]:o[n]=c}return o};function denormalize$1(e,t,r,n){if(isImmutable(t))return denormalizeImmutable(e,t,n);const i={...t},s=Object.keys(e);for(let t=0;t<s.length;t++){const r=s[t],o=n(e[r],i[r]);if(void 0!==i[r]&&(i[r]=o),"symbol"==typeof o)return o}return i}function objectQueryKey(e,t,r){const n={},i=Object.keys(e);for(let s=0;s<i.length;s++){const o=i[s];n[o]=r(e[o],t)}return n}class ObjectSchema{schema;constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce(((t,r)=>{const n=e[r];return{...t,[r]:n}}),this.schema||{})}normalize(...e){return normalize(this.schema,...e)}denormalize(e,t,r){return denormalize$1(this.schema,e,t,r)}queryKey(e,t){return objectQueryKey(this.schema,e,t)}}class Invalidate extends PolymorphicSchema{constructor(e,t){if("production"!==process.env.NODE_ENV&&!e)throw new Error('Invalidate schema requires "entity" option.');super(e,t)}get key(){return this.schemaKey()}normalize(e,t,r,n,i,s){const o=this.inferSchema(e,t,r);if(!o)return e;let a;if("string"==typeof e||"number"==typeof e)a=e;else{const i=o.process(e,t,r,n);if(a=o.pk(null!=i?i:e,t,r,n),"production"!==process.env.NODE_ENV&&(void 0===a||""===a||"undefined"===a)){const t=new Error(`Missing usable primary key when normalizing response.\n\n  This is likely due to a malformed response.\n  Try inspecting the network response or fetch() return value.\n  Or use debugging tools: https://dataclient.io/docs/getting-started/debugging\n  Learn more about schemas: https://dataclient.io/docs/api/schema\n\n  Invalidate(Entity): Invalidate(${o.key})\n  Value (processed): ${e&&JSON.stringify(e,null,2)}\n  `);throw t.status=400,t}}return a=`${a}`,s.invalidate(o,a),this.isSingleSchema?a:{id:a,schema:this.getSchemaAttribute(e,t,r)}}queryKey(e,t,r){}denormalize(e,t,r){return this.denormalizeValue(e,r)}_denormalizeNullable(){return{}}_normalizeNullable(){return{}}}function consistentSerialize(e){const t=Object.keys(e).sort(),r={};for(const n of t)r[n]=e[n];return JSON.stringify(r)}const pushMerge=(e,t)=>[...e,...t],unshift=(e,t)=>[...t,...e],valuesMerge=(e,t)=>({...e,...t}),isShallowEqual=(e,t)=>"object"==typeof e&&"object"==typeof t?e.id===t.id&&e.schema===t.schema:e===t,removeMerge=(e,t)=>e.filter((e=>!t.some((t=>isShallowEqual(e,t))))),valuesRemoveMerge=(e,t)=>{const r=Object.values(t),n={};for(const[t,i]of Object.entries(e))r.some((e=>isShallowEqual(i,e)))||(n[t]=i);return n},createArray=e=>[...e],createValue=e=>({...e});class CollectionSchema{addWith(e,t){return CreateAdder(this,e,t)}moveWith(e){return CreateMover(this,e,this.schema instanceof ArraySchema?removeMerge:valuesRemoveMerge)}createCollectionFilter(...e){return t=>Object.entries(t).every((([t,r])=>{var n;return this.nonFilterArgumentKeys(t)||`${e[0][t]}`===r||`${null==(n=e[1])?void 0:n[t]}`===r}))}nonFilterArgumentKeys(e){return e.startsWith("order")}constructor(e,t){if(this.schema=Array.isArray(e)?new ArraySchema(e[0]):e,t?"nestKey"in t?this.nestKey=t.nestKey:this.argsKey="argsKey"in t?t.argsKey:e=>({...e}):this.argsKey=e=>({...e}),this.key=keyFromSchema(this.schema),null!=t&&t.nonFilterArgumentKeys){const{nonFilterArgumentKeys:e}=t;"function"==typeof e?this.nonFilterArgumentKeys=e:e instanceof RegExp?this.nonFilterArgumentKeys=t=>e.test(t):this.nonFilterArgumentKeys=t=>e.includes(t)}else null!=t&&t.createCollectionFilter&&(this.createCollectionFilter=t.createCollectionFilter.bind(this));this.schema instanceof ArraySchema?(this.createIfValid=createArray,this.push=CreateAdder(this,pushMerge),this.unshift=CreateAdder(this,unshift),this.remove=CreateAdder(this,removeMerge),this.move=CreateMover(this,pushMerge,removeMerge)):e instanceof ValuesSchema&&(this.createIfValid=createValue,this.assign=CreateAdder(this,valuesMerge),this.remove=CreateAdder(this,valuesRemoveMerge),this.move=CreateMover(this,valuesMerge,valuesRemoveMerge))}get cacheWith(){return this.schema.schema}toString(){return this.key}toJSON(){return{key:this.key,schema:this.schema.schema}}pk(e,t,r,n){const i=this.argsKey?this.argsKey(...n):this.nestKey(t,r);for(const e in i)["number","boolean"].includes(typeof i[e])&&(i[e]=`${i[e]}`);return consistentSerialize(i)}normalize(e,t,r,n,i,s){const o=this.schema.normalize(e,t,r,n,i,s),a=this.pk(o,t,r,n);return s.mergeEntity(this,a,o),a}merge(e,t){return t}shouldReorder(e,t,r,n){return t.fetchedAt<e.fetchedAt}mergeWithStore(e,t,r,n){return this.shouldReorder(e,t,r,n)?this.merge(n,r):this.merge(r,n)}mergeMetaWithStore(e,t,r,n){return this.shouldReorder(e,t,r,n)?e:t}queryKey(e,t,r){if(this.argsKey){const t=this.pk(void 0,void 0,"",e);if(r.getEntity(this.key,t))return t}}denormalize(e,t,r){return this.schema.denormalize(e,t,r)}}function derivedProperties(e,t,r){const n={merge:{value:t},normalize:{value:r},queryKey:{value:queryKeyCreate}};return e.schema instanceof ArraySchema&&(n.createIfValid={value:createIfValid},n.denormalize={value:denormalize}),n}function CreateAdder(e,t,r){const n=derivedProperties(e,t,normalizeCreate);return r&&(n.createCollectionFilter={value:r}),Object.create(e,n)}function queryKeyCreate(){}function normalizeCreate(e,t,r,n,i,s){"production"!==process.env.NODE_ENV&&(i.creating=!0);const o=this.schema.normalize(this.schema instanceof ArraySchema&&!Array.isArray(e)?[e]:e,t,r,n,i,s),a=this.createCollectionFilter(...n),c=s.getEntities(this.key);if(c)for(const e of c.keys())a(JSON.parse(e))&&s.mergeEntity(this,e,o);return o}function CreateMover(e,t,r){const n=Object.create(e,derivedProperties(e,t,(function(e,t,r,n,i,s){return normalizeMove.call(this,this._removeSchema,e,t,r,n,i,s)})));return n._removeSchema=Object.create(n,{merge:{value:r}}),n}function normalizeMove(e,t,r,n,i,s,o){const a=this.schema instanceof ArraySchema,c=this.schema.schema,h=(a&&Array.isArray(t)?t:[t]).map((e=>{const t=c.process(e,r,n,i),s=`${c.pk(t,r,n,i)}`;return{pk:s,processed:t,existingEntity:s?o.getEntity(c.key,s):void 0}})),u=a?Array.isArray(t)?t:[t]:h[0].pk?{[h[0].pk]:t}:t,l=this.schema.normalize(u,r,n,i,s,o),m=i[i.length-1],y=o.getEntities(this.key);if(y)for(let t=0;t<h.length;t++){const{processed:r,existingEntity:n}=h[t],s=a?[l[t]]:l,c=a?{...m,...r}:m,u=n?{...n,...c}:c,d=n?this.createCollectionFilter({...i[0],...n},n):void 0,p=this.createCollectionFilter({...i[0],...c},u);for(const t of y.keys()){const r=JSON.parse(t),n=null==d?void 0:d(r),i=p(r);n&&!i?o.mergeEntity(e,t,s):i&&!n&&o.mergeEntity(this,t,s)}}return l}function createIfValid(e){return Array.isArray(e)?[...e]:{...e}}function denormalize(e,t,r){return Array.isArray(e)?this.schema.denormalize(e,t,r):this.schema.denormalize([e],t,r)[0]}function keyFromSchema(e){return e instanceof ArraySchema?`[${e.schemaKey()}]`:e instanceof ValuesSchema?`{${e.schemaKey()}}`:`(${e.schemaKey()})`}function EntityMixin(e,t={}){class r extends e{static toString(){return this.key}static toJSON(){return{key:this.key,schema:this.schema}}static pk(e,t,r,n){return this.prototype.pk.call(e,t,r,n)}static shouldUpdate(e,t,r,n){return!0}static shouldReorder(e,t,r,n){return t.fetchedAt<e.fetchedAt}static merge(e,t){return{...e,...t}}static mergeWithStore(e,t,r,n){return this.shouldUpdate(e,t,r,n)?typeof n!=typeof r?n:this.shouldReorder(e,t,r,n)?this.merge(n,r):this.merge(r,n):r}static mergeMetaWithStore(e,t,r,n){return this.shouldReorder(e,t,r,n)?e:t}static fromJS(e={}){const t=new this(e);return Object.assign(t,e),t}static createIfValid(e){if(!this.validate(e))return this.fromJS(e)}static process(e,t,r,n){return{...e}}static normalize(e,n,i,s,o,a){const c=this.process(e,n,i,s);let h;if(void 0===c)return h=`${this.pk(e,n,i,s)}`,a.invalidate(this,h),h;if(h=this.pk(c,n,i,s),void 0===h||""===h||"undefined"===h){if("production"!==process.env.NODE_ENV&&!o.creating){let e;e="pk"in t||r.prototype.pk!==this.prototype.pk||"id"in c?"This is likely due to a malformed response.\n  Try inspecting the network response or fetch() return value.\n  Or use debugging tools: https://dataclient.io/docs/getting-started/debugging":"'id' missing but needed for default pk(). Try defining pk() for your Entity.";const n=new Error(`Missing usable primary key when normalizing response.\n\n  ${e}\n  Learn more about primary keys: https://dataclient.io/rest/api/Entity#pk\n\n  Entity: ${this.key}\n  Value (processed): ${c&&JSON.stringify(c,null,2)}\n`);throw n.status=400,n}h=`MISS-${Math.random()}`}else h=`${h}`;if(a.checkLoop(this.key,h,e))return h;throwValidationError(this.validate(c));const u=Object.keys(this.schema);for(let e=0;e<u.length;e++){const t=u[e];Object.hasOwn(c,t)&&(c[t]=o(this.schema[t],c[t],c,t,s))}return a.mergeEntity(this,h,c),h}static validate(e){}static queryKey(e,t,r){if(!e[0])return;const n=queryKeyCandidate(this,e,r);return n&&r.getEntity(this.key,n)?n:void 0}static denormalize(e,t,r){if("symbol"==typeof e)return e;for(const t of Object.keys(this.schema)){const n=r(this.schema[t],e[t]);if("symbol"==typeof n){if(this.defaults[t])return n;e[t]=void 0}else e[t]=n}return e}static get defaults(){return Object.hasOwn(this,"__defaults")||Object.defineProperty(this,"__defaults",{value:new this,writable:!0,configurable:!0}),this.__defaults}}const{pk:n,schema:i,key:s,...o}=t;if(Object.assign(r,o),"schema"in t?r.schema=t.schema:e.schema||(r.schema={}),"pk"in t?"function"==typeof t.pk?r.prototype.pk=function(e,r){return t.pk(this,e,r)}:r.prototype.pk=function(){return this[t.pk]}:"function"!=typeof e.prototype.pk&&(r.prototype.pk=function(){return this.id}),"key"in t)Object.defineProperty(r,"key",{value:t.key,configurable:!0,writable:!0,enumerable:!0});else if(!("key"in e)){function a(e){Object.defineProperty(this,"key",{value:e,writable:!0,enumerable:!0,configurable:!0})}const c=function(){const t="EntityMixin"===this.name?e.name:this.name;if("production"!==process.env.NODE_ENV&&(""===t||"EntityMixin"===t||"_temp"===t))throw new Error("Entity classes without a name must define `static key`\nSee: https://dataclient.io/rest/api/Entity#key");return t},h="undefined"!=typeof document&&document.CLS_MANGLE?function(){return null==document.CLS_MANGLE||document.CLS_MANGLE(this),Object.defineProperty(r,"key",{get:c,set:a,enumerable:!0,configurable:!0}),c.call(this)}:c;Object.defineProperty(r,"key",{get:h,set:a,enumerable:!0,configurable:!0})}return r}function indexFromParams(e,t){if(t)return t.find((t=>Object.hasOwn(e,t)))}function throwValidationError(e){if(e){const t=new Error(e);throw t.status=400,t}}function queryKeyCandidate(e,t,r){if(["string","number"].includes(typeof t[0]))return`${t[0]}`;const n=e.pk(t[0],void 0,"",t);if(void 0!==n&&""!==n)return n;const i=indexFromParams(t[0],e.indexes);if(!i)return;const s=t[0][i];return r.getIndex(e.key,i,s)}class Query{constructor(e,t){this.schema=e,this.process=t}normalize(...e){return this.schema.normalize(...e)}denormalize(e,t,r){const n=r(this.schema,e);return"symbol"==typeof n?n:this.process(n,...t)}queryKey(e,t){return t(this.schema,e)}}class Lazy{constructor(e){this.schema=e}normalize(e,t,r,n,i,s){return i(this.schema,e,t,r,n)}denormalize(e,t,r){return e}queryKey(e,t,r){}get query(){return this._query||(this._query=new LazyQuery(this.schema)),this._query}_query}class LazyQuery{constructor(e){this.schema=e}denormalize(e,t,r){return r(this.schema,e)}queryKey(e,t,r){const n=this.schema;return"function"==typeof n.queryKey&&n.key?n.queryKey(e,t,r):e[0]}}var schema=Object.freeze({__proto__:null,All:AllSchema,Array:ArraySchema,Collection:CollectionSchema,Entity:EntityMixin,EntityMixin:EntityMixin,Invalidate:Invalidate,Lazy:Lazy,Object:ObjectSchema,Query:Query,Union:UnionSchema,Values:ValuesSchema,unshift:unshift});const EmptyBase=class{};class Entity extends(EntityMixin(EmptyBase)){static process(e,t,r,n){if("production"!==process.env.NODE_ENV&&"silent"!==this.automaticValidation&&Array.isArray(e)){const t=`Attempted to initialize ${this.name} with an array, but named members were expected\n\nThis is likely due to a malformed response.\nTry inspecting the network response or fetch() return value.\nOr use debugging tools: https://dataclient.io/docs/getting-started/debugging\nLearn more about schemas: https://dataclient.io/docs/api/schema\nIf this is a mistake, you can disable this check by setting static automaticValidation = 'silent'\n\nFirst three members: ${JSON.stringify(e.slice(0,3),null,2)}`;if("warn"!==this.automaticValidation){const e=new Error(t);throw e.status=400,e}console.warn(t)}return super.process(e,t,r,n)}}function validateRequired(e,t){let r="";if(Object.keys(t).some((t=>!Object.hasOwn(e,t)&&(r=t,!0))))return`Missing key ${r}`}var _document$querySelect;const isBrowser="undefined"!=typeof document;let CSP=isBrowser&&!(null!=(_document$querySelect=document.querySelector("meta[http-equiv='Content-Security-Policy']"))&&_document$querySelect.getAttribute("content"));try{CSP||Function()}catch(e){CSP=!0,isBrowser&&console.error("Content Security Policy: The previous CSP log can be safely ignored - @data-client/endpoint will use setPrototypeOf instead")}var _Endpoint;class Endpoint extends Function{constructor(e,t){let r,n;return CSP?(r=(...e)=>r.fetch(...e),Object.setPrototypeOf(r,new.target.prototype)):(super("return arguments.callee.fetch.apply(arguments.callee, arguments)"),r=this),e&&(r.fetch=e),t&&"name"in t||!e||!e.name||"anonymous"===e.name||(n=e.name),Object.defineProperty(r,"name",{get(){return"production"===process.env.NODE_ENV||r.key!==Endpoint.prototype.key||n||this.__name||console.error("Endpoint: Autonaming failure.\n\nEndpoint initialized with anonymous function.\nPlease add `name` option or hoist the function definition. https://dataclient.io/rest/api/Endpoint#name"),n||this.__name},set(e){this.__name=e}}),Object.assign(r,t),r}key(...e){return`${this.name} ${JSON.stringify(e)}`}testKey(e){return e.startsWith(this.name)}bind(e,...t){const r=this.fetch,n=this.key;return this.extend({fetch(){return r.apply(null!=e?e:this,t)},key(){return n.apply(this,t)}})}extend(e){class t extends this.constructor{}return Object.assign(t.prototype,this),new t(e.fetch,e)}}_Endpoint=Endpoint,(()=>{if("undefined"!=typeof document&&document.FUNC_MANGLE){const e=_Endpoint.prototype.key;_Endpoint.prototype.key=function(...t){return null==document.FUNC_MANGLE||document.FUNC_MANGLE(this),this.prototype.key=e,e.call(this,...t)}}})();const ExtendableEndpoint=Endpoint;Object.hasOwn=Object.hasOwn||function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},exports.All=AllSchema,exports.Collection=CollectionSchema,exports.Endpoint=Endpoint,exports.Entity=Entity,exports.EntityMixin=EntityMixin,exports.ExtendableEndpoint=ExtendableEndpoint,exports.Invalidate=Invalidate,exports.Lazy=Lazy,exports.Query=Query,exports.Union=UnionSchema,exports.Values=ValuesSchema,exports.schema=schema,exports.unshift=unshift,exports.validateRequired=validateRequired;
//# sourceMappingURL=/sm/738c884e296a33b84b9a20a6eaded37774530b9d778fcb4cad562b6610655442.map