fetchium 0.4.0 → 0.4.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/development/{QueryClient-CbG-qdpt.js → QueryClient-D_e76rYS.js} +2 -2
  3. package/dist/cjs/development/QueryClient-D_e76rYS.js.map +1 -0
  4. package/dist/cjs/development/index.js +1 -1
  5. package/dist/cjs/{production/mutation-B0wMYfHP.js → development/mutation-bq06T6Wg.js} +2 -2
  6. package/dist/cjs/{production/mutation-B0wMYfHP.js.map → development/mutation-bq06T6Wg.js.map} +1 -1
  7. package/dist/cjs/development/react/index.js +1 -1
  8. package/dist/cjs/development/rest/index.js +1 -1
  9. package/dist/cjs/development/topic/index.js +1 -1
  10. package/dist/cjs/development/topic/index.js.map +1 -1
  11. package/dist/cjs/production/{QueryClient-DGCBmyPp.js → QueryClient-BPdrfgtE.js} +2 -2
  12. package/dist/cjs/production/QueryClient-BPdrfgtE.js.map +1 -0
  13. package/dist/cjs/production/index.js +1 -1
  14. package/dist/cjs/{development/mutation-CFkoRirO.js → production/mutation-BVVlcTsK.js} +2 -2
  15. package/dist/cjs/{development/mutation-CFkoRirO.js.map → production/mutation-BVVlcTsK.js.map} +1 -1
  16. package/dist/cjs/production/react/index.js +1 -1
  17. package/dist/cjs/production/rest/index.js +1 -1
  18. package/dist/cjs/production/topic/index.js +1 -1
  19. package/dist/cjs/production/topic/index.js.map +1 -1
  20. package/dist/esm/QueryResult.d.ts.map +1 -1
  21. package/dist/esm/development/{QueryClient-BZY2FTv3.js → QueryClient-CkO_s9Uh.js} +9 -5
  22. package/dist/esm/development/QueryClient-CkO_s9Uh.js.map +1 -0
  23. package/dist/esm/development/index.js +2 -2
  24. package/dist/esm/development/{mutation-Dot2Ejg6.js → mutation-SZTEGudR.js} +2 -2
  25. package/dist/esm/development/{mutation-Dot2Ejg6.js.map → mutation-SZTEGudR.js.map} +1 -1
  26. package/dist/esm/development/react/index.js +1 -1
  27. package/dist/esm/development/rest/index.js +2 -2
  28. package/dist/esm/development/topic/index.js +27 -22
  29. package/dist/esm/development/topic/index.js.map +1 -1
  30. package/dist/esm/production/{QueryClient-WtzRneAd.js → QueryClient--PrsE8Kj.js} +9 -5
  31. package/dist/esm/production/QueryClient--PrsE8Kj.js.map +1 -0
  32. package/dist/esm/production/index.js +2 -2
  33. package/dist/esm/production/{mutation-AXg513Dg.js → mutation-20F2qe90.js} +2 -2
  34. package/dist/esm/production/{mutation-AXg513Dg.js.map → mutation-20F2qe90.js.map} +1 -1
  35. package/dist/esm/production/react/index.js +1 -1
  36. package/dist/esm/production/rest/index.js +2 -2
  37. package/dist/esm/production/topic/index.js +27 -22
  38. package/dist/esm/production/topic/index.js.map +1 -1
  39. package/dist/esm/topic/TopicQuery.d.ts +2 -1
  40. package/dist/esm/topic/TopicQuery.d.ts.map +1 -1
  41. package/dist/esm/topic/TopicQueryAdapter.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/cjs/development/QueryClient-CbG-qdpt.js.map +0 -1
  44. package/dist/cjs/production/QueryClient-DGCBmyPp.js.map +0 -1
  45. package/dist/esm/development/QueryClient-BZY2FTv3.js.map +0 -1
  46. package/dist/esm/production/QueryClient-WtzRneAd.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./QueryClient-CbG-qdpt.js"),r=require("./QueryAdapter-DUo338ga.js"),t=require("./mutation-CFkoRirO.js");exports.ARRAY_KEY=e.ARRAY_KEY;exports.Entity=e.Entity;exports.GcManager=e.GcManager;exports.LiveFieldConfig=e.LiveFieldConfig;exports.LiveFieldType=e.LiveFieldType;exports.Mask=e.Mask;exports.NetworkManager=e.NetworkManager;exports.NetworkManagerContext=e.NetworkManagerContext;exports.NetworkMode=e.NetworkMode;exports.NoOpGcManager=e.NoOpGcManager;exports.NoOpNetworkManager=e.NoOpNetworkManager;exports.QUERY_ID=e.QUERY_ID;exports.Query=e.Query;exports.QueryClient=e.QueryClient;exports.QueryClientContext=e.QueryClientContext;exports.RECORD_KEY=e.RECORD_KEY;exports.defaultNetworkManager=e.defaultNetworkManager;exports.draft=e.draft;exports.fetchQuery=e.fetchQuery;exports.queryKeyForClass=e.queryKeyForClass;exports.registerFormat=e.registerFormat;exports.t=e.t;exports.QueryAdapter=r.QueryAdapter;exports.Mutation=t.Mutation;exports.getMutation=t.getMutation;exports.mutationKeyForClass=t.mutationKeyForClass;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./QueryClient-D_e76rYS.js"),r=require("./QueryAdapter-DUo338ga.js"),t=require("./mutation-bq06T6Wg.js");exports.ARRAY_KEY=e.ARRAY_KEY;exports.Entity=e.Entity;exports.GcManager=e.GcManager;exports.LiveFieldConfig=e.LiveFieldConfig;exports.LiveFieldType=e.LiveFieldType;exports.Mask=e.Mask;exports.NetworkManager=e.NetworkManager;exports.NetworkManagerContext=e.NetworkManagerContext;exports.NetworkMode=e.NetworkMode;exports.NoOpGcManager=e.NoOpGcManager;exports.NoOpNetworkManager=e.NoOpNetworkManager;exports.QUERY_ID=e.QUERY_ID;exports.Query=e.Query;exports.QueryClient=e.QueryClient;exports.QueryClientContext=e.QueryClientContext;exports.RECORD_KEY=e.RECORD_KEY;exports.defaultNetworkManager=e.defaultNetworkManager;exports.draft=e.draft;exports.fetchQuery=e.fetchQuery;exports.queryKeyForClass=e.queryKeyForClass;exports.registerFormat=e.registerFormat;exports.t=e.t;exports.QueryAdapter=r.QueryAdapter;exports.Mutation=t.Mutation;exports.getMutation=t.getMutation;exports.mutationKeyForClass=t.mutationKeyForClass;
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";const g=require("signalium"),o=require("./QueryClient-DGCBmyPp.js");class y{static adapter;params;result;optimisticUpdates;config;effects;constructor(){return o.createDefinitionProxy(this)}}const c=new WeakMap,h=t=>{const e=c.get(t);if(e===void 0)throw new Error("Mutation definition not found");return e().id};function D(t){let e=c.get(t);if(e!==void 0)return e;let n;const f=()=>{if(n!==void 0)return n;const d=new t,r=o.extractDefinition(d),{fields:i}=r,p=`mutation:${String(r.methods.getIdentityKey.call(i))}`,a=i.params??{},l=a instanceof o.ValidatorDef?a:o.t.object(a),s=i.result,m=s!==void 0?s instanceof o.ValidatorDef?s:o.t.object(s):void 0,u=t.adapter;if(!u)throw new Error(`Mutation class "${t.name}" must define a static \`adapter\` property. Extend RESTMutation (from fetchium/rest) or set \`static adapter = MyAdapter\` on your mutation class.`);return n={id:p,requestShape:l,responseShape:m,captured:r,optimisticUpdates:i.optimisticUpdates??!1,config:i.config,effects:i.effects,hasGetEffects:typeof r.methods.getEffects=="function",adapterClass:u},n};return c.set(t,f),f}function M(t){const e=D(t),n=g.getContext(o.QueryClientContext);if(n===void 0)throw new Error("QueryClient not found");return n.getMutation(e())}exports.Mutation=y;exports.getMutation=M;exports.mutationKeyForClass=h;
2
- //# sourceMappingURL=mutation-B0wMYfHP.js.map
1
+ "use strict";const g=require("signalium"),o=require("./QueryClient-D_e76rYS.js");class y{static adapter;params;result;optimisticUpdates;config;effects;constructor(){return o.createDefinitionProxy(this)}}const c=new WeakMap,h=t=>{const e=c.get(t);if(e===void 0)throw new Error("Mutation definition not found");return e().id};function D(t){let e=c.get(t);if(e!==void 0)return e;let n;const f=()=>{if(n!==void 0)return n;const d=new t,r=o.extractDefinition(d),{fields:i}=r,p=`mutation:${String(r.methods.getIdentityKey.call(i))}`,a=i.params??{},l=a instanceof o.ValidatorDef?a:o.t.object(a),s=i.result,m=s!==void 0?s instanceof o.ValidatorDef?s:o.t.object(s):void 0,u=t.adapter;if(!u)throw new Error(`Mutation class "${t.name}" must define a static \`adapter\` property. Extend RESTMutation (from fetchium/rest) or set \`static adapter = MyAdapter\` on your mutation class.`);return n={id:p,requestShape:l,responseShape:m,captured:r,optimisticUpdates:i.optimisticUpdates??!1,config:i.config,effects:i.effects,hasGetEffects:typeof r.methods.getEffects=="function",adapterClass:u},n};return c.set(t,f),f}function M(t){const e=D(t),n=g.getContext(o.QueryClientContext);if(n===void 0)throw new Error("QueryClient not found");return n.getMutation(e())}exports.Mutation=y;exports.getMutation=M;exports.mutationKeyForClass=h;
2
+ //# sourceMappingURL=mutation-bq06T6Wg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutation-B0wMYfHP.js","sources":["../../../src/mutation.ts"],"sourcesContent":["import { getContext, ReactiveTask } from 'signalium';\nimport { ExtractType, InternalTypeDef, MutationEffects, TypeDef, RetryConfig, TypeDefShape } from './types.js';\nimport { QueryClientContext, type QueryContext } from './QueryClient.js';\nimport { ValidatorDef, t } from './typeDefs.js';\nimport { createDefinitionProxy, extractDefinition, type CapturedDefinition } from './fieldRef.js';\nimport type { QueryAdapter, QueryAdapterClass } from './QueryAdapter.js';\n\n// ================================\n// Mutation Definition Types\n// ================================\n\nexport interface MutationConfigOptions {\n retry?: RetryConfig | number | false;\n}\n\nexport interface MutationDefinition<Request, Response> {\n id: string;\n requestShape: InternalTypeDef;\n responseShape: InternalTypeDef | undefined;\n captured: CapturedDefinition<Mutation>;\n optimisticUpdates: boolean;\n config?: MutationConfigOptions;\n effects?: MutationEffects;\n hasGetEffects: boolean;\n adapterClass: QueryAdapterClass;\n}\n\n// ================================\n// Mutation base class\n// ================================\n\nexport abstract class Mutation {\n static adapter?: QueryAdapterClass;\n\n readonly params?: TypeDefShape;\n readonly result?: TypeDefShape;\n readonly optimisticUpdates?: boolean;\n readonly config?: MutationConfigOptions;\n readonly effects?: Readonly<MutationEffects>;\n\n declare context: QueryContext;\n\n abstract getIdentityKey(): unknown;\n\n getEffects?(): MutationEffects;\n\n constructor() {\n return createDefinitionProxy(this);\n }\n}\n\n// ================================\n// Mutation definition cache and lookup\n// ================================\n\nconst mutationDefCache = new WeakMap<new () => Mutation, () => MutationDefinition<any, any>>();\n\nexport const mutationKeyForClass = (cls: new () => Mutation): string => {\n const getMutationDef = mutationDefCache.get(cls);\n\n if (getMutationDef === undefined) {\n throw new Error('Mutation definition not found');\n }\n\n return getMutationDef().id;\n};\n\n// ================================\n// Internal: build mutation definition from class\n// ================================\n\nfunction buildMutationDefinition(MutationClass: new () => Mutation): () => MutationDefinition<any, any> {\n let cached = mutationDefCache.get(MutationClass);\n\n if (cached !== undefined) {\n return cached;\n }\n\n let mutationDefinition: MutationDefinition<any, any> | undefined;\n\n const getter = (): MutationDefinition<any, any> => {\n if (mutationDefinition !== undefined) {\n return mutationDefinition;\n }\n\n const instance = new MutationClass();\n const captured = extractDefinition(instance);\n const { fields } = captured;\n\n const id = `mutation:${String(captured.methods.getIdentityKey.call(fields))}`;\n\n const requestDef = fields.params ?? {};\n const requestShape = (requestDef instanceof ValidatorDef\n ? requestDef\n : t.object(requestDef)) as unknown as InternalTypeDef;\n const responseDef = fields.result;\n const responseShape =\n responseDef !== undefined\n ? ((responseDef instanceof ValidatorDef ? responseDef : t.object(responseDef)) as unknown as InternalTypeDef)\n : undefined;\n\n const adapterClass = (MutationClass as typeof Mutation).adapter;\n if (!adapterClass) {\n throw new Error(\n `Mutation class \"${MutationClass.name}\" must define a static \\`adapter\\` property. ` +\n `Extend RESTMutation (from fetchium/rest) or set \\`static adapter = MyAdapter\\` on your mutation class.`,\n );\n }\n\n mutationDefinition = {\n id,\n requestShape,\n responseShape,\n captured,\n optimisticUpdates: fields.optimisticUpdates ?? false,\n config: fields.config,\n effects: fields.effects,\n hasGetEffects: typeof captured.methods.getEffects === 'function',\n adapterClass,\n };\n\n return mutationDefinition;\n };\n\n mutationDefCache.set(MutationClass, getter);\n return getter;\n}\n\n// ================================\n// Public API\n// ================================\n\nexport function getMutation<T extends Mutation>(\n MutationClass: new () => T,\n): ReactiveTask<Readonly<ExtractType<T['result']>>, [ExtractType<T['params']>]> {\n const getMutationDef = buildMutationDefinition(MutationClass);\n\n const queryClient = getContext(QueryClientContext);\n\n if (queryClient === undefined) {\n throw new Error('QueryClient not found');\n }\n\n return queryClient.getMutation<any, any>(getMutationDef());\n}\n"],"names":["Mutation","createDefinitionProxy","mutationDefCache","mutationKeyForClass","cls","getMutationDef","buildMutationDefinition","MutationClass","cached","mutationDefinition","getter","instance","captured","extractDefinition","fields","id","requestDef","requestShape","ValidatorDef","t","responseDef","responseShape","adapterClass","getMutation","queryClient","getContext","QueryClientContext"],"mappings":"iFA+BO,MAAeA,CAAS,CAC7B,OAAO,QAEE,OACA,OACA,kBACA,OACA,QAQT,aAAc,CACZ,OAAOC,EAAAA,sBAAsB,IAAI,CACnC,CACF,CAMA,MAAMC,MAAuB,QAEhBC,EAAuBC,GAAoC,CACtE,MAAMC,EAAiBH,EAAiB,IAAIE,CAAG,EAE/C,GAAIC,IAAmB,OACrB,MAAM,IAAI,MAAM,+BAA+B,EAGjD,OAAOA,IAAiB,EAC1B,EAMA,SAASC,EAAwBC,EAAuE,CACtG,IAAIC,EAASN,EAAiB,IAAIK,CAAa,EAE/C,GAAIC,IAAW,OACb,OAAOA,EAGT,IAAIC,EAEJ,MAAMC,EAAS,IAAoC,CACjD,GAAID,IAAuB,OACzB,OAAOA,EAGT,MAAME,EAAW,IAAIJ,EACfK,EAAWC,EAAAA,kBAAkBF,CAAQ,EACrC,CAAE,OAAAG,GAAWF,EAEbG,EAAK,YAAY,OAAOH,EAAS,QAAQ,eAAe,KAAKE,CAAM,CAAC,CAAC,GAErEE,EAAaF,EAAO,QAAU,CAAA,EAC9BG,EAAgBD,aAAsBE,EAAAA,aACxCF,EACAG,EAAAA,EAAE,OAAOH,CAAU,EACjBI,EAAcN,EAAO,OACrBO,EACJD,IAAgB,OACVA,aAAuBF,EAAAA,aAAeE,EAAcD,IAAE,OAAOC,CAAW,EAC1E,OAEAE,EAAgBf,EAAkC,QACxD,GAAI,CAACe,EACH,MAAM,IAAI,MACR,mBAAmBf,EAAc,IAAI,qJAAA,EAKzC,OAAAE,EAAqB,CACnB,GAAAM,EACA,aAAAE,EACA,cAAAI,EACA,SAAAT,EACA,kBAAmBE,EAAO,mBAAqB,GAC/C,OAAQA,EAAO,OACf,QAASA,EAAO,QAChB,cAAe,OAAOF,EAAS,QAAQ,YAAe,WACtD,aAAAU,CAAA,EAGKb,CACT,EAEA,OAAAP,EAAiB,IAAIK,EAAeG,CAAM,EACnCA,CACT,CAMO,SAASa,EACdhB,EAC8E,CAC9E,MAAMF,EAAiBC,EAAwBC,CAAa,EAEtDiB,EAAcC,EAAAA,WAAWC,oBAAkB,EAEjD,GAAIF,IAAgB,OAClB,MAAM,IAAI,MAAM,uBAAuB,EAGzC,OAAOA,EAAY,YAAsBnB,GAAgB,CAC3D"}
1
+ {"version":3,"file":"mutation-bq06T6Wg.js","sources":["../../../src/mutation.ts"],"sourcesContent":["import { getContext, ReactiveTask } from 'signalium';\nimport { ExtractType, InternalTypeDef, MutationEffects, TypeDef, RetryConfig, TypeDefShape } from './types.js';\nimport { QueryClientContext, type QueryContext } from './QueryClient.js';\nimport { ValidatorDef, t } from './typeDefs.js';\nimport { createDefinitionProxy, extractDefinition, type CapturedDefinition } from './fieldRef.js';\nimport type { QueryAdapter, QueryAdapterClass } from './QueryAdapter.js';\n\n// ================================\n// Mutation Definition Types\n// ================================\n\nexport interface MutationConfigOptions {\n retry?: RetryConfig | number | false;\n}\n\nexport interface MutationDefinition<Request, Response> {\n id: string;\n requestShape: InternalTypeDef;\n responseShape: InternalTypeDef | undefined;\n captured: CapturedDefinition<Mutation>;\n optimisticUpdates: boolean;\n config?: MutationConfigOptions;\n effects?: MutationEffects;\n hasGetEffects: boolean;\n adapterClass: QueryAdapterClass;\n}\n\n// ================================\n// Mutation base class\n// ================================\n\nexport abstract class Mutation {\n static adapter?: QueryAdapterClass;\n\n readonly params?: TypeDefShape;\n readonly result?: TypeDefShape;\n readonly optimisticUpdates?: boolean;\n readonly config?: MutationConfigOptions;\n readonly effects?: Readonly<MutationEffects>;\n\n declare context: QueryContext;\n\n abstract getIdentityKey(): unknown;\n\n getEffects?(): MutationEffects;\n\n constructor() {\n return createDefinitionProxy(this);\n }\n}\n\n// ================================\n// Mutation definition cache and lookup\n// ================================\n\nconst mutationDefCache = new WeakMap<new () => Mutation, () => MutationDefinition<any, any>>();\n\nexport const mutationKeyForClass = (cls: new () => Mutation): string => {\n const getMutationDef = mutationDefCache.get(cls);\n\n if (getMutationDef === undefined) {\n throw new Error('Mutation definition not found');\n }\n\n return getMutationDef().id;\n};\n\n// ================================\n// Internal: build mutation definition from class\n// ================================\n\nfunction buildMutationDefinition(MutationClass: new () => Mutation): () => MutationDefinition<any, any> {\n let cached = mutationDefCache.get(MutationClass);\n\n if (cached !== undefined) {\n return cached;\n }\n\n let mutationDefinition: MutationDefinition<any, any> | undefined;\n\n const getter = (): MutationDefinition<any, any> => {\n if (mutationDefinition !== undefined) {\n return mutationDefinition;\n }\n\n const instance = new MutationClass();\n const captured = extractDefinition(instance);\n const { fields } = captured;\n\n const id = `mutation:${String(captured.methods.getIdentityKey.call(fields))}`;\n\n const requestDef = fields.params ?? {};\n const requestShape = (requestDef instanceof ValidatorDef\n ? requestDef\n : t.object(requestDef)) as unknown as InternalTypeDef;\n const responseDef = fields.result;\n const responseShape =\n responseDef !== undefined\n ? ((responseDef instanceof ValidatorDef ? responseDef : t.object(responseDef)) as unknown as InternalTypeDef)\n : undefined;\n\n const adapterClass = (MutationClass as typeof Mutation).adapter;\n if (!adapterClass) {\n throw new Error(\n `Mutation class \"${MutationClass.name}\" must define a static \\`adapter\\` property. ` +\n `Extend RESTMutation (from fetchium/rest) or set \\`static adapter = MyAdapter\\` on your mutation class.`,\n );\n }\n\n mutationDefinition = {\n id,\n requestShape,\n responseShape,\n captured,\n optimisticUpdates: fields.optimisticUpdates ?? false,\n config: fields.config,\n effects: fields.effects,\n hasGetEffects: typeof captured.methods.getEffects === 'function',\n adapterClass,\n };\n\n return mutationDefinition;\n };\n\n mutationDefCache.set(MutationClass, getter);\n return getter;\n}\n\n// ================================\n// Public API\n// ================================\n\nexport function getMutation<T extends Mutation>(\n MutationClass: new () => T,\n): ReactiveTask<Readonly<ExtractType<T['result']>>, [ExtractType<T['params']>]> {\n const getMutationDef = buildMutationDefinition(MutationClass);\n\n const queryClient = getContext(QueryClientContext);\n\n if (queryClient === undefined) {\n throw new Error('QueryClient not found');\n }\n\n return queryClient.getMutation<any, any>(getMutationDef());\n}\n"],"names":["Mutation","createDefinitionProxy","mutationDefCache","mutationKeyForClass","cls","getMutationDef","buildMutationDefinition","MutationClass","cached","mutationDefinition","getter","instance","captured","extractDefinition","fields","id","requestDef","requestShape","ValidatorDef","t","responseDef","responseShape","adapterClass","getMutation","queryClient","getContext","QueryClientContext"],"mappings":"iFA+BO,MAAeA,CAAS,CAC7B,OAAO,QAEE,OACA,OACA,kBACA,OACA,QAQT,aAAc,CACZ,OAAOC,EAAAA,sBAAsB,IAAI,CACnC,CACF,CAMA,MAAMC,MAAuB,QAEhBC,EAAuBC,GAAoC,CACtE,MAAMC,EAAiBH,EAAiB,IAAIE,CAAG,EAE/C,GAAIC,IAAmB,OACrB,MAAM,IAAI,MAAM,+BAA+B,EAGjD,OAAOA,IAAiB,EAC1B,EAMA,SAASC,EAAwBC,EAAuE,CACtG,IAAIC,EAASN,EAAiB,IAAIK,CAAa,EAE/C,GAAIC,IAAW,OACb,OAAOA,EAGT,IAAIC,EAEJ,MAAMC,EAAS,IAAoC,CACjD,GAAID,IAAuB,OACzB,OAAOA,EAGT,MAAME,EAAW,IAAIJ,EACfK,EAAWC,EAAAA,kBAAkBF,CAAQ,EACrC,CAAE,OAAAG,GAAWF,EAEbG,EAAK,YAAY,OAAOH,EAAS,QAAQ,eAAe,KAAKE,CAAM,CAAC,CAAC,GAErEE,EAAaF,EAAO,QAAU,CAAA,EAC9BG,EAAgBD,aAAsBE,EAAAA,aACxCF,EACAG,EAAAA,EAAE,OAAOH,CAAU,EACjBI,EAAcN,EAAO,OACrBO,EACJD,IAAgB,OACVA,aAAuBF,EAAAA,aAAeE,EAAcD,IAAE,OAAOC,CAAW,EAC1E,OAEAE,EAAgBf,EAAkC,QACxD,GAAI,CAACe,EACH,MAAM,IAAI,MACR,mBAAmBf,EAAc,IAAI,qJAAA,EAKzC,OAAAE,EAAqB,CACnB,GAAAM,EACA,aAAAE,EACA,cAAAI,EACA,SAAAT,EACA,kBAAmBE,EAAO,mBAAqB,GAC/C,OAAQA,EAAO,OACf,QAASA,EAAO,QAChB,cAAe,OAAOF,EAAS,QAAQ,YAAe,WACtD,aAAAU,CAAA,EAGKb,CACT,EAEA,OAAAP,EAAiB,IAAIK,EAAeG,CAAM,EACnCA,CACT,CAMO,SAASa,EACdhB,EAC8E,CAC9E,MAAMF,EAAiBC,EAAwBC,CAAa,EAEtDiB,EAAcC,EAAAA,WAAWC,oBAAkB,EAEjD,GAAIF,IAAgB,OAClB,MAAM,IAAI,MAAM,uBAAuB,EAGzC,OAAOA,EAAY,YAAsBnB,GAAgB,CAC3D"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("signalium/react"),u=require("../QueryClient-CbG-qdpt.js");function c(e,...r){return t.useReactive(()=>u.fetchQuery(e,...r))}exports.useQuery=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("signalium/react"),u=require("../QueryClient-D_e76rYS.js");function c(e,...r){return t.useReactive(()=>u.fetchQuery(e,...r))}exports.useQuery=c;
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../QueryClient-CbG-qdpt.js"),q=require("../QueryAdapter-DUo338ga.js"),T=require("../mutation-CFkoRirO.js");class f extends q.QueryAdapter{_fetch;_baseUrl;constructor(e){super(),this._fetch=e?.fetch??globalThis.fetch,this._baseUrl=e?.baseUrl}async send(e,s){return this.executeRequest(e,s)}async sendNext(e,s){const t=this.resolveFetchNext(e);if(t===void 0)throw new Error("fetchNext is not configured for this query");return this.executeRequest(e,s,t)}hasNext(e){const s=this.resolveFetchNext(e);if(s===void 0)return!1;if(s.url!==void 0&&s.url!==null)return!0;if(s.searchParams!==void 0){const t=Object.keys(s.searchParams);if(t.length===0)return!1;for(const r of t)if(s.searchParams[r]===void 0||s.searchParams[r]===null)return!1;return!0}return!1}resolveFetchNext(e){const t=(e.getFetchNext?e.getFetchNext():void 0)??e.rawFetchNext;if(t===void 0)return;const r={params:e.params??{},result:e.resultData};return{url:t.url!==void 0?i.reifyValue(t.url,r):void 0,searchParams:t.searchParams!==void 0?i.reifyValue(t.searchParams,r):void 0}}buildUrl(e,s){if(e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//"))return e;if(e.startsWith("/")){const t=i.resolveBaseUrl(s)??i.resolveBaseUrl(this._baseUrl)??globalThis.location?.origin;if(!t)throw new Error(`RESTQueryAdapter: cannot resolve URL for path "${e}". Set \`baseUrl\` on the query/mutation, pass it to \`new RESTQueryAdapter({ baseUrl })\`, or use an absolute URL.`);return`${t}${e}`}return e}async executeRequest(e,s,t){const r=t?.url??(e.getPath?e.getPath():e.path),u=e.getMethod?e.getMethod():e.method,a=e.getSearchParams?e.getSearchParams():e.searchParams,o=t?.searchParams?{...a,...t.searchParams}:a,n=e.getBody?e.getBody():e.body,h=e.getRequestOptions?e.getRequestOptions():e.requestOptions;if(!r)throw new Error("RESTQuery requires a path. Define `path` as a field or override `getPath()`.");let l=r;if(o){const m=new URLSearchParams;for(const U in o){const c=o[U];c!=null&&m.append(U,String(c))}const v=m.toString();v&&(l+="?"+v)}const p=h?.baseUrl??e.baseUrl,d=this.buildUrl(l,p),{baseUrl:g,signal:P,...R}=h??{},S=n||e.headers?{...n?{"Content-Type":"application/json"}:void 0,...e.headers}:void 0,b=await this._fetch(d,{method:u,headers:S,body:n?JSON.stringify(n):void 0,signal:s,...R});return e.response=b,e.responseNotifier.notify(),b.json()}async sendMutation(e,s){const t=e,r=t.getPath?t.getPath():t.path,u=t.getMethod?t.getMethod():t.method,a=t.getBody?t.getBody():t.body,o=t.getRequestOptions?t.getRequestOptions():t.requestOptions;if(!r)throw new Error("RESTMutation requires a path. Define `path` as a field or override `getPath()`.");const n=o?.baseUrl??t.baseUrl,h=this.buildUrl(r,n),{baseUrl:l,signal:p,...d}=o??{},g={...a!==void 0?{"Content-Type":"application/json"}:{},...t.headers};return(await this._fetch(h,{method:u,headers:g,...a!==void 0?{body:JSON.stringify(a)}:{},signal:s,...d})).json()}}class O extends i.Query{static adapter=f;method="GET";path;baseUrl;searchParams;body;headers;requestOptions;fetchNext;getIdentityKey(){return`${this.method??"GET"}:${this.path??""}`}}class E extends T.Mutation{static adapter=f;path;baseUrl;method="POST";body;headers;requestOptions;getIdentityKey(){return`${this.method??"POST"}:${this.path??""}`}}exports.RESTMutation=E;exports.RESTQuery=O;exports.RESTQueryAdapter=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../QueryClient-D_e76rYS.js"),q=require("../QueryAdapter-DUo338ga.js"),T=require("../mutation-bq06T6Wg.js");class f extends q.QueryAdapter{_fetch;_baseUrl;constructor(e){super(),this._fetch=e?.fetch??globalThis.fetch,this._baseUrl=e?.baseUrl}async send(e,s){return this.executeRequest(e,s)}async sendNext(e,s){const t=this.resolveFetchNext(e);if(t===void 0)throw new Error("fetchNext is not configured for this query");return this.executeRequest(e,s,t)}hasNext(e){const s=this.resolveFetchNext(e);if(s===void 0)return!1;if(s.url!==void 0&&s.url!==null)return!0;if(s.searchParams!==void 0){const t=Object.keys(s.searchParams);if(t.length===0)return!1;for(const r of t)if(s.searchParams[r]===void 0||s.searchParams[r]===null)return!1;return!0}return!1}resolveFetchNext(e){const t=(e.getFetchNext?e.getFetchNext():void 0)??e.rawFetchNext;if(t===void 0)return;const r={params:e.params??{},result:e.resultData};return{url:t.url!==void 0?i.reifyValue(t.url,r):void 0,searchParams:t.searchParams!==void 0?i.reifyValue(t.searchParams,r):void 0}}buildUrl(e,s){if(e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//"))return e;if(e.startsWith("/")){const t=i.resolveBaseUrl(s)??i.resolveBaseUrl(this._baseUrl)??globalThis.location?.origin;if(!t)throw new Error(`RESTQueryAdapter: cannot resolve URL for path "${e}". Set \`baseUrl\` on the query/mutation, pass it to \`new RESTQueryAdapter({ baseUrl })\`, or use an absolute URL.`);return`${t}${e}`}return e}async executeRequest(e,s,t){const r=t?.url??(e.getPath?e.getPath():e.path),u=e.getMethod?e.getMethod():e.method,a=e.getSearchParams?e.getSearchParams():e.searchParams,o=t?.searchParams?{...a,...t.searchParams}:a,n=e.getBody?e.getBody():e.body,h=e.getRequestOptions?e.getRequestOptions():e.requestOptions;if(!r)throw new Error("RESTQuery requires a path. Define `path` as a field or override `getPath()`.");let l=r;if(o){const m=new URLSearchParams;for(const U in o){const c=o[U];c!=null&&m.append(U,String(c))}const v=m.toString();v&&(l+="?"+v)}const p=h?.baseUrl??e.baseUrl,d=this.buildUrl(l,p),{baseUrl:g,signal:P,...R}=h??{},S=n||e.headers?{...n?{"Content-Type":"application/json"}:void 0,...e.headers}:void 0,b=await this._fetch(d,{method:u,headers:S,body:n?JSON.stringify(n):void 0,signal:s,...R});return e.response=b,e.responseNotifier.notify(),b.json()}async sendMutation(e,s){const t=e,r=t.getPath?t.getPath():t.path,u=t.getMethod?t.getMethod():t.method,a=t.getBody?t.getBody():t.body,o=t.getRequestOptions?t.getRequestOptions():t.requestOptions;if(!r)throw new Error("RESTMutation requires a path. Define `path` as a field or override `getPath()`.");const n=o?.baseUrl??t.baseUrl,h=this.buildUrl(r,n),{baseUrl:l,signal:p,...d}=o??{},g={...a!==void 0?{"Content-Type":"application/json"}:{},...t.headers};return(await this._fetch(h,{method:u,headers:g,...a!==void 0?{body:JSON.stringify(a)}:{},signal:s,...d})).json()}}class O extends i.Query{static adapter=f;method="GET";path;baseUrl;searchParams;body;headers;requestOptions;fetchNext;getIdentityKey(){return`${this.method??"GET"}:${this.path??""}`}}class E extends T.Mutation{static adapter=f;path;baseUrl;method="POST";body;headers;requestOptions;getIdentityKey(){return`${this.method??"POST"}:${this.path??""}`}}exports.RESTMutation=E;exports.RESTQuery=O;exports.RESTQueryAdapter=f;
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../QueryClient-CbG-qdpt.js"),h=require("../QueryAdapter-DUo338ga.js");class p extends h.QueryAdapter{_topics=new Map;fulfillTopic(e,s){const t=this._topics.get(e);if(t===void 0){this._topics.set(e,{status:"fulfilled",data:s});return}t.status==="pending"&&(t.status="fulfilled",t.data=s,t.resolve(s))}rejectTopic(e,s){const t=this._topics.get(e);if(t===void 0){this._topics.set(e,{status:"rejected",error:s});return}t.status==="pending"&&(t.status="rejected",t.error=s,t.reject(s))}clearTopic(e){this._topics.delete(e)}clearAll(){this._topics.clear()}async send(e,s){const t=e;t._topicAdapter=this;const r=t.topic,i=this._topics.get(r);if(i)switch(i.status){case"fulfilled":return i.data;case"rejected":throw i.error;case"pending":return i.promise}let c,o;const n=new Promise((u,l)=>{c=u,o=l});return this._topics.set(r,{status:"pending",promise:n,resolve:c,reject:o}),this.subscribe(r),n}sendMutationEvent(e){this.queryClient.applyMutationEvent(e)}}class f extends d.Query{static adapter=p;getIdentityKey(){return`topic:${this.topic}`}getConfig(){return{staleTime:0,subscribe:()=>()=>{this._topicAdapter?.unsubscribe(this.topic)}}}}exports.TopicQuery=f;exports.TopicQueryAdapter=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../QueryClient-D_e76rYS.js"),f=require("../QueryAdapter-DUo338ga.js");class n extends f.QueryAdapter{_topics=new Map;fulfillTopic(e,i){const t=this._topics.get(e);if(t===void 0){this._topics.set(e,{status:"fulfilled",data:i});return}t.status==="pending"&&(t.status="fulfilled",t.data=i,t.resolve(i))}rejectTopic(e,i){const t=this._topics.get(e);if(t===void 0){this._topics.set(e,{status:"rejected",error:i});return}t.status==="pending"&&(t.status="rejected",t.error=i,t.reject(i))}clearTopic(e){this._topics.delete(e)}clearAll(){this._topics.clear()}async send(e,i){const t=e;t._topicAdapter=this;const r=t.getTopic?t.getTopic():t.topic;if(r===void 0)throw new Error("TopicQuery requires a topic. Define `topic` as a field or override `getTopic()`.");const s=this._topics.get(r);if(s)switch(s.status){case"fulfilled":return s.data;case"rejected":throw s.error;case"pending":return s.promise}let c,o;const p=new Promise((a,l)=>{c=a,o=l});return this._topics.set(r,{status:"pending",promise:p,resolve:c,reject:o}),this.subscribe(r),p}sendMutationEvent(e){this.queryClient.applyMutationEvent(e)}}class g extends d.Query{static adapter=n;topic;getIdentityKey(){return`topic:${this.topic??""}`}getConfig(){return{staleTime:0,subscribe:()=>()=>{const e=this._topicAdapter,i=this.getTopic?this.getTopic():this.topic;i!==void 0&&e?.unsubscribe(i)}}}}exports.TopicQuery=g;exports.TopicQueryAdapter=n;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/topic/TopicQueryAdapter.ts","../../../../src/topic/TopicQuery.ts"],"sourcesContent":["import { QueryAdapter } from '../QueryAdapter.js';\nimport type { Query } from '../query.js';\nimport type { MutationEvent } from '../types.js';\n\n// ================================\n// TopicQueryAdapter — abstract adapter for topic-based subscriptions\n// ================================\n\ninterface TopicCtx extends Query {\n topic: string;\n _topicAdapter?: TopicQueryAdapter;\n}\n\ninterface TopicState {\n status: 'pending' | 'fulfilled' | 'rejected';\n promise?: Promise<unknown>;\n resolve?: (data: unknown) => void;\n reject?: (error: unknown) => void;\n data?: unknown;\n error?: unknown;\n}\n\nexport abstract class TopicQueryAdapter extends QueryAdapter {\n private _topics = new Map<string, TopicState>();\n\n /**\n * Called when a query activates for a given topic.\n * Implementations should start delivering data for this topic,\n * calling `fulfillTopic()` when initial data is available and\n * `sendMutationEvent()` for ongoing updates.\n */\n abstract subscribe(topic: string): void;\n\n /**\n * Called when the query deactivates. Implementations should\n * tear down any resources for this topic.\n */\n abstract unsubscribe(topic: string): void;\n\n /**\n * Resolve the pending promise for a topic with initial data.\n * Can be called before `send()` — the data will be picked up\n * when the query activates.\n */\n protected fulfillTopic(topic: string, data: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'fulfilled', data });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'fulfilled';\n state.data = data;\n state.resolve!(data);\n }\n }\n\n /**\n * Reject the pending promise for a topic.\n * Can be called before `send()` — the error will be propagated\n * when the query activates.\n */\n protected rejectTopic(topic: string, error: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'rejected', error });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'rejected';\n state.error = error;\n state.reject!(error);\n }\n }\n\n /**\n * Clears internal state for a topic. Called automatically by\n * `unsubscribe` — subclasses generally don't need to call this.\n */\n protected clearTopic(topic: string): void {\n this._topics.delete(topic);\n }\n\n protected clearAll(): void {\n this._topics.clear();\n }\n\n override async send(ctx: Query, _signal: AbortSignal): Promise<unknown> {\n const topicCtx = ctx as TopicCtx;\n topicCtx._topicAdapter = this;\n const topic = topicCtx.topic;\n\n const existing = this._topics.get(topic);\n\n if (existing) {\n switch (existing.status) {\n case 'fulfilled':\n return existing.data;\n case 'rejected':\n throw existing.error;\n case 'pending':\n return existing.promise;\n }\n }\n\n // No state yet — create a deferred and subscribe\n let resolve!: (data: unknown) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<unknown>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n this._topics.set(topic, { status: 'pending', promise, resolve, reject });\n this.subscribe(topic);\n\n return promise;\n }\n\n /**\n * Convenience wrapper — pushes a mutation event through the QueryClient\n * so that entities and live collections are updated reactively.\n */\n protected sendMutationEvent(event: MutationEvent): void {\n this.queryClient!.applyMutationEvent(event);\n }\n}\n","import { Query } from '../query.js';\nimport { TopicQueryAdapter } from './TopicQueryAdapter.js';\nimport type { QueryAdapterClass } from '../QueryAdapter.js';\nimport type { QueryConfigOptions } from '../query-types.js';\n\n// ================================\n// TopicQuery — declarative topic-based query definition\n// ================================\n\nexport abstract class TopicQuery extends Query {\n // Explicit type lets subclasses override with adapters that take constructor args.\n static override adapter: QueryAdapterClass<TopicQueryAdapter> = TopicQueryAdapter;\n\n abstract topic: string;\n\n getIdentityKey(): string {\n return `topic:${this.topic}`;\n }\n\n getConfig(): QueryConfigOptions {\n return {\n staleTime: 0,\n subscribe: () => {\n return () => {\n const adapter = (this as Record<string, any>)._topicAdapter as TopicQueryAdapter | undefined;\n adapter?.unsubscribe(this.topic);\n };\n },\n };\n }\n}\n"],"names":["TopicQueryAdapter","QueryAdapter","topic","data","state","error","ctx","_signal","topicCtx","existing","resolve","reject","promise","res","rej","event","TopicQuery","Query"],"mappings":"uKAsBO,MAAeA,UAA0BC,EAAAA,YAAa,CACnD,YAAc,IAqBZ,aAAaC,EAAeC,EAAqB,CACzD,MAAMC,EAAQ,KAAK,QAAQ,IAAIF,CAAK,EAEpC,GAAIE,IAAU,OAAW,CACvB,KAAK,QAAQ,IAAIF,EAAO,CAAE,OAAQ,YAAa,KAAAC,EAAM,EACrD,MACF,CAEIC,EAAM,SAAW,YACnBA,EAAM,OAAS,YACfA,EAAM,KAAOD,EACbC,EAAM,QAASD,CAAI,EAEvB,CAOU,YAAYD,EAAeG,EAAsB,CACzD,MAAMD,EAAQ,KAAK,QAAQ,IAAIF,CAAK,EAEpC,GAAIE,IAAU,OAAW,CACvB,KAAK,QAAQ,IAAIF,EAAO,CAAE,OAAQ,WAAY,MAAAG,EAAO,EACrD,MACF,CAEID,EAAM,SAAW,YACnBA,EAAM,OAAS,WACfA,EAAM,MAAQC,EACdD,EAAM,OAAQC,CAAK,EAEvB,CAMU,WAAWH,EAAqB,CACxC,KAAK,QAAQ,OAAOA,CAAK,CAC3B,CAEU,UAAiB,CACzB,KAAK,QAAQ,MAAA,CACf,CAEA,MAAe,KAAKI,EAAYC,EAAwC,CACtE,MAAMC,EAAWF,EACjBE,EAAS,cAAgB,KACzB,MAAMN,EAAQM,EAAS,MAEjBC,EAAW,KAAK,QAAQ,IAAIP,CAAK,EAEvC,GAAIO,EACF,OAAQA,EAAS,OAAA,CACf,IAAK,YACH,OAAOA,EAAS,KAClB,IAAK,WACH,MAAMA,EAAS,MACjB,IAAK,UACH,OAAOA,EAAS,OAAA,CAKtB,IAAIC,EACAC,EACJ,MAAMC,EAAU,IAAI,QAAiB,CAACC,EAAKC,IAAQ,CACjDJ,EAAUG,EACVF,EAASG,CACX,CAAC,EAED,YAAK,QAAQ,IAAIZ,EAAO,CAAE,OAAQ,UAAW,QAAAU,EAAS,QAAAF,EAAS,OAAAC,EAAQ,EACvE,KAAK,UAAUT,CAAK,EAEbU,CACT,CAMU,kBAAkBG,EAA4B,CACtD,KAAK,YAAa,mBAAmBA,CAAK,CAC5C,CACF,CCzHO,MAAeC,UAAmBC,EAAAA,KAAM,CAE7C,OAAgB,QAAgDjB,EAIhE,gBAAyB,CACvB,MAAO,SAAS,KAAK,KAAK,EAC5B,CAEA,WAAgC,CAC9B,MAAO,CACL,UAAW,EACX,UAAW,IACF,IAAM,CACM,KAA6B,eACrC,YAAY,KAAK,KAAK,CACjC,CACF,CAEJ,CACF"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/topic/TopicQueryAdapter.ts","../../../../src/topic/TopicQuery.ts"],"sourcesContent":["import { QueryAdapter } from '../QueryAdapter.js';\nimport type { Query } from '../query.js';\nimport type { MutationEvent } from '../types.js';\n\n// ================================\n// TopicQueryAdapter — abstract adapter for topic-based subscriptions\n// ================================\n\ninterface TopicCtx extends Query {\n topic?: string;\n getTopic?(): string;\n _topicAdapter?: TopicQueryAdapter;\n}\n\ninterface TopicState {\n status: 'pending' | 'fulfilled' | 'rejected';\n promise?: Promise<unknown>;\n resolve?: (data: unknown) => void;\n reject?: (error: unknown) => void;\n data?: unknown;\n error?: unknown;\n}\n\nexport abstract class TopicQueryAdapter extends QueryAdapter {\n private _topics = new Map<string, TopicState>();\n\n /**\n * Called when a query activates for a given topic.\n * Implementations should start delivering data for this topic,\n * calling `fulfillTopic()` when initial data is available and\n * `sendMutationEvent()` for ongoing updates.\n */\n abstract subscribe(topic: string): void;\n\n /**\n * Called when the query deactivates. Implementations should\n * tear down any resources for this topic.\n */\n abstract unsubscribe(topic: string): void;\n\n /**\n * Resolve the pending promise for a topic with initial data.\n * Can be called before `send()` — the data will be picked up\n * when the query activates.\n */\n protected fulfillTopic(topic: string, data: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'fulfilled', data });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'fulfilled';\n state.data = data;\n state.resolve!(data);\n }\n }\n\n /**\n * Reject the pending promise for a topic.\n * Can be called before `send()` — the error will be propagated\n * when the query activates.\n */\n protected rejectTopic(topic: string, error: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'rejected', error });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'rejected';\n state.error = error;\n state.reject!(error);\n }\n }\n\n /**\n * Clears internal state for a topic. Called automatically by\n * `unsubscribe` — subclasses generally don't need to call this.\n */\n protected clearTopic(topic: string): void {\n this._topics.delete(topic);\n }\n\n protected clearAll(): void {\n this._topics.clear();\n }\n\n override async send(ctx: Query, _signal: AbortSignal): Promise<unknown> {\n const topicCtx = ctx as TopicCtx;\n topicCtx._topicAdapter = this;\n const topic = topicCtx.getTopic ? topicCtx.getTopic() : topicCtx.topic;\n\n if (topic === undefined) {\n throw new Error('TopicQuery requires a topic. Define `topic` as a field or override `getTopic()`.');\n }\n\n const existing = this._topics.get(topic);\n\n if (existing) {\n switch (existing.status) {\n case 'fulfilled':\n return existing.data;\n case 'rejected':\n throw existing.error;\n case 'pending':\n return existing.promise;\n }\n }\n\n // No state yet — create a deferred and subscribe\n let resolve!: (data: unknown) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<unknown>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n this._topics.set(topic, { status: 'pending', promise, resolve, reject });\n this.subscribe(topic);\n\n return promise;\n }\n\n /**\n * Convenience wrapper — pushes a mutation event through the QueryClient\n * so that entities and live collections are updated reactively.\n */\n protected sendMutationEvent(event: MutationEvent): void {\n this.queryClient!.applyMutationEvent(event);\n }\n}\n","import { Query } from '../query.js';\nimport { TopicQueryAdapter } from './TopicQueryAdapter.js';\nimport type { QueryAdapterClass } from '../QueryAdapter.js';\nimport type { QueryConfigOptions } from '../query-types.js';\n\n// ================================\n// TopicQuery — declarative topic-based query definition\n// ================================\n\nexport abstract class TopicQuery extends Query {\n // Explicit type lets subclasses override with adapters that take constructor args.\n static override adapter: QueryAdapterClass<TopicQueryAdapter> = TopicQueryAdapter;\n\n topic?: string;\n\n // User-overridable getter — the adapter reads this from the execution context.\n getTopic?(): string;\n\n getIdentityKey(): string {\n return `topic:${this.topic ?? ''}`;\n }\n\n getConfig(): QueryConfigOptions {\n return {\n staleTime: 0,\n subscribe: () => {\n return () => {\n const adapter = (this as Record<string, any>)._topicAdapter as TopicQueryAdapter | undefined;\n const topic = this.getTopic ? this.getTopic() : this.topic;\n if (topic !== undefined) {\n adapter?.unsubscribe(topic);\n }\n };\n },\n };\n }\n}\n"],"names":["TopicQueryAdapter","QueryAdapter","topic","data","state","error","ctx","_signal","topicCtx","existing","resolve","reject","promise","res","rej","event","TopicQuery","Query","adapter"],"mappings":"uKAuBO,MAAeA,UAA0BC,EAAAA,YAAa,CACnD,YAAc,IAqBZ,aAAaC,EAAeC,EAAqB,CACzD,MAAMC,EAAQ,KAAK,QAAQ,IAAIF,CAAK,EAEpC,GAAIE,IAAU,OAAW,CACvB,KAAK,QAAQ,IAAIF,EAAO,CAAE,OAAQ,YAAa,KAAAC,EAAM,EACrD,MACF,CAEIC,EAAM,SAAW,YACnBA,EAAM,OAAS,YACfA,EAAM,KAAOD,EACbC,EAAM,QAASD,CAAI,EAEvB,CAOU,YAAYD,EAAeG,EAAsB,CACzD,MAAMD,EAAQ,KAAK,QAAQ,IAAIF,CAAK,EAEpC,GAAIE,IAAU,OAAW,CACvB,KAAK,QAAQ,IAAIF,EAAO,CAAE,OAAQ,WAAY,MAAAG,EAAO,EACrD,MACF,CAEID,EAAM,SAAW,YACnBA,EAAM,OAAS,WACfA,EAAM,MAAQC,EACdD,EAAM,OAAQC,CAAK,EAEvB,CAMU,WAAWH,EAAqB,CACxC,KAAK,QAAQ,OAAOA,CAAK,CAC3B,CAEU,UAAiB,CACzB,KAAK,QAAQ,MAAA,CACf,CAEA,MAAe,KAAKI,EAAYC,EAAwC,CACtE,MAAMC,EAAWF,EACjBE,EAAS,cAAgB,KACzB,MAAMN,EAAQM,EAAS,SAAWA,EAAS,SAAA,EAAaA,EAAS,MAEjE,GAAIN,IAAU,OACZ,MAAM,IAAI,MAAM,kFAAkF,EAGpG,MAAMO,EAAW,KAAK,QAAQ,IAAIP,CAAK,EAEvC,GAAIO,EACF,OAAQA,EAAS,OAAA,CACf,IAAK,YACH,OAAOA,EAAS,KAClB,IAAK,WACH,MAAMA,EAAS,MACjB,IAAK,UACH,OAAOA,EAAS,OAAA,CAKtB,IAAIC,EACAC,EACJ,MAAMC,EAAU,IAAI,QAAiB,CAACC,EAAKC,IAAQ,CACjDJ,EAAUG,EACVF,EAASG,CACX,CAAC,EAED,YAAK,QAAQ,IAAIZ,EAAO,CAAE,OAAQ,UAAW,QAAAU,EAAS,QAAAF,EAAS,OAAAC,EAAQ,EACvE,KAAK,UAAUT,CAAK,EAEbU,CACT,CAMU,kBAAkBG,EAA4B,CACtD,KAAK,YAAa,mBAAmBA,CAAK,CAC5C,CACF,CC9HO,MAAeC,UAAmBC,EAAAA,KAAM,CAE7C,OAAgB,QAAgDjB,EAEhE,MAKA,gBAAyB,CACvB,MAAO,SAAS,KAAK,OAAS,EAAE,EAClC,CAEA,WAAgC,CAC9B,MAAO,CACL,UAAW,EACX,UAAW,IACF,IAAM,CACX,MAAMkB,EAAW,KAA6B,cACxChB,EAAQ,KAAK,SAAW,KAAK,SAAA,EAAa,KAAK,MACjDA,IAAU,QACZgB,GAAS,YAAYhB,CAAK,CAE9B,CACF,CAEJ,CACF"}
@@ -1,2 +1,2 @@
1
- "use strict";const E=require("signalium"),S=require("signalium/utils"),qt=require("./shared-Ct5zKrt4.js"),At=require("./stores/sync.js");var j=(e=>(e.Always="always",e.Online="online",e.OfflineFirst="offlineFirst",e))(j||{}),d=(e=>(e[e.UNDEFINED=1]="UNDEFINED",e[e.NULL=2]="NULL",e[e.NUMBER=4]="NUMBER",e[e.STRING=8]="STRING",e[e.BOOLEAN=16]="BOOLEAN",e[e.OBJECT=32]="OBJECT",e[e.ARRAY=64]="ARRAY",e[e.ID=128]="ID",e[e.RECORD=256]="RECORD",e[e.UNION=512]="UNION",e[e.ENTITY=1024]="ENTITY",e[e.HAS_FORMAT=4096]="HAS_FORMAT",e[e.IS_EAGER_FORMAT=8192]="IS_EAGER_FORMAT",e[e.PARSE_RESULT=16384]="PARSE_RESULT",e[e.LIVE=32768]="LIVE",e))(d||{});const V=Symbol("array"),K=Symbol("record"),lt=Symbol("QUERY_ID");var J=(e=>(e[e.Array=0]="Array",e[e.Value=1]="Value",e))(J||{});class L{type;entityDefs;constraintFieldRefs;sort;valueType;onCreate;onUpdate;onDelete;constructor(t,i,n,r,s,o,a,c){this.type=t,this.entityDefs=i,this.constraintFieldRefs=n,this.sort=r,this.valueType=s,this.onCreate=o,this.onUpdate=a,this.onDelete=c}static array(t,i,n){return new L(0,t,i,n,void 0,void 0,void 0,void 0)}static value(t,i,n,r,s,o){return new L(1,t,i,void 0,n,r,s,o)}}const O=new WeakMap;function T(e){return O.get(e)}var X=(e=>(e[e.Query=0]="Query",e[e.Entity=1]="Entity",e))(X||{});class we{constructor(t,i,n){this._onEvict=i,this._intervalId=setInterval(this._tick,t*6e4*n)}_currentFlush=new Map;_nextFlush=new Map;_intervalId;schedule(t,i){this._nextFlush.set(t,i)}cancel(t){this._currentFlush.delete(t),this._nextFlush.delete(t)}_tick=()=>{const{_currentFlush:t,_nextFlush:i,_onEvict:n}=this;for(const[r,s]of t)n(r,s);this._currentFlush=i,this._nextFlush=new Map};destroy(){clearInterval(this._intervalId)}}class Ut{_buckets=new Map;_nextTickEntries=new Map;_nextTickScheduled=!1;_onEvict;_multiplier;constructor(t,i=1){this._onEvict=t,this._multiplier=i}schedule(t,i,n){if(i===1/0)return;if(i===0){const{_nextTickEntries:o}=this;o.set(t,n),this._nextTickScheduled||(this._nextTickScheduled=!0,setTimeout(this._flushNextTick,0));return}const{_buckets:r}=this;let s=r.get(i);s||(s=new we(i,this._onEvict,this._multiplier),r.set(i,s)),s.schedule(t,n)}cancel(t,i){if(i!==1/0){if(i===0){this._nextTickEntries.delete(t);return}this._buckets.get(i)?.cancel(t)}}_flushNextTick=()=>{const{_nextTickEntries:t,_onEvict:i}=this;this._nextTickScheduled=!1;for(const[n,r]of t)i(n,r);t.clear()};destroy(){const{_buckets:t,_nextTickEntries:i}=this;for(const n of t.values())n.destroy();t.clear(),i.clear()}}class Vt{schedule(t,i,n){}cancel(t,i){}destroy(){}}const z=Symbol("fieldRef"),k=Symbol("fieldRefPath"),ht=Symbol("DEFINITION_TARGET"),H=Symbol("CANCEL_PROXY"),Ee=/\[([^\]]+)\]/g;function Kt(e){const t={[z]:!0,[k]:e};return new Proxy(t,be)}const be={get(e,t){if(t===z)return!0;if(t===k)return e[k];if(t===Symbol.toPrimitive||t==="toString"||t==="valueOf"){const n=e[k];return()=>`[${n.join(".")}]`}if(typeof t=="symbol")return;const i=e[k];return Kt([...i,t])},has(e,t){return t===z||t===k}};function $t(e){return typeof e=="object"&&e!==null&&e[z]===!0}function Qt(e){return e[k]}function yt(e){return new Proxy(e,{set(t,i,n){return t[i]=n,!0},get(t,i){return i===ht?t:i===H?()=>{}:typeof i=="symbol"?t[i]:Kt([i])}})}function Bt(e){const t=e[ht];e[H]();const i={};for(const s of Object.getOwnPropertyNames(t))i[s]=t[s];const n={};let r=Object.getPrototypeOf(t);for(;r&&r!==Object.prototype;){for(const s of Object.getOwnPropertyNames(r)){if(s==="constructor")continue;const o=Object.getOwnPropertyDescriptor(r,s);typeof o.value=="function"&&!(s in n)&&(n[s]=o.value)}r=Object.getPrototypeOf(r)}return{fields:i,methods:n}}function pt(e,t){let i=t;for(const n of e){if(i==null)return;i=i[n]}return i}function Ce(e,t){return e.replace(Ee,(i,n)=>{const r=n.split("."),s=pt(r,t);return s!=null?encodeURIComponent(String(s)):""})}function $(e,t){if($t(e))return pt(Qt(e),t);if(typeof e=="string")return Ce(e,t);if(Array.isArray(e))return e.map(i=>$(i,t));if(typeof e=="object"&&e!==null&&Object.getPrototypeOf(e)===Object.prototype){const i={};for(const n of Object.keys(e))i[n]=$(e[n],t);return i}return e}function st(e,t,i){const n=e.fields,r=e.methods,s={params:t},o={};for(const[a,c]of Object.entries(n))o[a]=$(c,s);o.params=t,o.context=i,o.responseNotifier=E.notifier();for(const[a,c]of Object.entries(r))o[a]=c.bind(o);return o}class Z{static cache;constructor(){return yt(this)}}const Yt=Object.entries,ot=Object.keys;function Dt(e){return typeof e=="number"?e|d.UNDEFINED:e instanceof _?(e.mask&d.UNDEFINED)!==0?e:_.cloneWith(e,d.UNDEFINED):e}function xe(e){return e instanceof _&&(e.mask&d.OBJECT)!==0&&(e.mask&(d.ENTITY|d.ARRAY|d.UNION|d.RECORD|d.LIVE))===0}function Gt(e,t,i){const n=new Set;for(const s of e)if(s!==void 0)for(const o of Object.keys(s))n.add(o);const r={};for(const s of n){let o=0,a;const c=[];let f=!0;for(const l of e){const u=l?.[s];u!==void 0?(o++,a===void 0&&(a=u),xe(u)?c.push(u.shape):(f=!1,c.push(void 0))):(f=!1,c.push(void 0))}if(f&&o>0){const l=Gt(c,t),u=new _(d.OBJECT,l);r[s]=o<t?Dt(u):u}else r[s]=o<t?Dt(a):a}return r}class _{mask;shape;typenameField=void 0;typenameValue=void 0;idField=void 0;values=void 0;_methods=void 0;_entityConfig=void 0;_entityClass=void 0;_entityCache=void 0;_liveConfig=void 0;constructor(t,i,n,r,s,o){this.mask=t,this.shape=i,this.values=n,this.typenameField=r,this.typenameValue=s,this.idField=o}static merge(t){if(t.length===1)return t[0];const i=t.length,n=t.map(c=>c.shape);t[0].typenameValue;const r=Gt(n,i);let s,o,a;for(const c of t){if(s===void 0&&c.idField!==void 0)s=c.idField;else if(s!==void 0&&c.idField!==void 0&&c.idField!==s)throw new Error(`[fetchium] Entity typename '${c.typenameValue}' has conflicting id fields: '${String(s)}' vs '${String(c.idField)}'`);o===void 0&&(o=c.typenameField),a===void 0&&(a=c.typenameValue)}return new _(d.ENTITY|d.OBJECT,r,void 0,o,a,s)}static cloneWith(t,i){const n=new _(i|t.mask,t.shape,t.values,t.typenameField,t.typenameValue,t.idField);return n._methods=t._methods,n._entityConfig=t._entityConfig,n._entityClass=t._entityClass,n._entityCache=t._entityCache,n._liveConfig=t._liveConfig,n}}class tt extends Set{lowercaseMap;constructor(t){super(t),this.lowercaseMap=new Map;for(const i of t)if(typeof i=="string"){const n=i.toLowerCase(),r=this.lowercaseMap.get(n);if(r!==void 0)throw new Error(`Case-insensitive enum cannot have multiple values with the same lowercase form: '${r}' and '${i}' both become '${n}'`);this.lowercaseMap.set(n,i)}}has(t){return this.get(t)!==void 0}get(t){if(typeof t=="string")return this.lowercaseMap.get(t.toLowerCase());if(super.has(t))return t}}const Oe=1128875347;S.registerCustomHash(tt,e=>{let t=Oe;for(const i of e)t+=S.hashValue(i);return t>>>0});function gt(e,t){return new _(e,t)}function Re(e){return gt(d.ARRAY,e)}function Se(e){return gt(d.RECORD|d.OBJECT,e)}function Ae(e){return gt(d.PARSE_RESULT,e)}function Wt(e,t){let i=e,n,r,s;for(const[o,a]of Yt(t))switch(typeof a){case"number":if((a&d.ID)!==0){if(n!==void 0)throw new Error(`Duplicate id field: ${o}`);n=o}break;case"string":if(r!==void 0&&r!==o)throw new Error(`Duplicate typename field: ${o}`);r=o,s=a;break;case"object":if(a instanceof tt||a instanceof Set)break;a.mask&d.LIVE&&(i|=d.LIVE);break}return new _(i,t,void 0,r,s,n)}function De(e){return Wt(d.OBJECT,e)}function Nt(e,t,i){const n=e.mask;if((n&d.UNION)!==0){const r=e;if(r.typenameField!==void 0){if(i!==void 0&&i!==r.typenameField)throw new Error(`Union typename field conflict: Cannot merge unions with different typename fields ('${i}' vs '${r.typenameField}')`);i=r.typenameField}const s=r.shape;if(s!==void 0)for(const o of[...ot(s),V,K]){const a=s[o];if(t[o]!==void 0&&t[o]!==a)throw new Error(`Union merge conflict: Duplicate typename value '${String(o)}' found when merging nested unions (${String(t[o])} vs ${String(a)})`);t[o]=a}}else if((n&d.ARRAY)!==0){if(t[V]!==void 0)throw new Error("Array shape already defined");t[V]=e.shape}else if((n&d.RECORD)!==0){if(t[K]!==void 0)throw new Error("Record shape already defined");t[K]=e.shape}else{const r=e.typenameField,s=e.typenameValue;if(s===void 0)throw new Error("Object definitions must have a typename to be in a union with other objects, records, or arrays");if(i!==void 0&&r!==i)throw new Error("Object definitions must have the same typename field to be in the same union");i=r,t[s]=e}return i}function vt(...e){const t=e;let i=0,n=0,r,s,o,a,c=0;for(const l of t){if(typeof l=="number"){i|=l;continue}if(l instanceof Set){if(s===void 0)s=new Set(l);else for(const u of l)s.add(u);continue}if(n++,c|=l.mask,n===1){r=l;continue}n===2&&(o=Object.create(null),a=Nt(r,o,a)),a=Nt(l,o,a)}if(n===0)return s===void 0?i:i===0?s:new _(i|d.UNION,void 0,s);if(n===1)return _.cloneWith(r,i);const f=i|c|d.UNION;return new _(f,o,s,a)}function _t(e,t,i){const n=e;if(typeof n=="number")return n|t;if(n instanceof Set)return vt(e,t);let r=i.get(n);return r===void 0&&(r=_.cloneWith(n,t),i.set(n,r)),r}const Ne=new WeakMap,Ie=new WeakMap,Me=new WeakMap;function ke(e){return _t(e,d.UNDEFINED|d.NULL,Me)}function Fe(e){return _t(e,d.UNDEFINED,Ne)}function Te(e){return _t(e,d.NULL,Ie)}function Pe(e){return e}function je(e){return new Set([e])}const zt=((...e)=>new Set(e));zt.caseInsensitive=(...e)=>new tt(e);const Ht=16;let Le=0;const at=[],Jt=[],Xt=new Map,et=new WeakSet;class Q{_raw;_formatted;_parsed;_formatId;constructor(t,i,n){this._raw=t,this._formatId=i,n?(this._formatted=at[i](t),this._parsed=!0):this._parsed=!1,et.add(this)}getValue(){return this._parsed||(this._formatted=at[this._formatId](this._raw),this._parsed=!0),this._formatted}toJSON(){return this._parsed?Jt[this._formatId](this._formatted):this._raw}}function qe(e){const t=Xt.get(e);if(t===void 0)throw new Error(`Format ${e} not registered`);return t}function mt(e,t,i,n,r){const s=Le++;at[s]=i,Jt[s]=n;const o=r?.eager??!0,c=s<<Ht|t|d.HAS_FORMAT|(o?d.IS_EAGER_FORMAT:0);Xt.set(e,c)}mt("date",d.STRING,e=>{const t=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)throw new Error(`Invalid date string: ${e}. Expected YYYY-MM-DD format.`);const[,i,n,r]=t,s=new Date(Date.UTC(parseInt(i,10),parseInt(n,10)-1,parseInt(r,10)));if(isNaN(s.getTime()))throw new Error(`Invalid date string: ${e}`);return s},e=>{const t=e.getUTCFullYear(),i=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0");return`${t}-${i}-${n}`});mt("date-time",d.STRING,e=>{const t=new Date(e);if(isNaN(t.getTime()))throw new Error(`Invalid date-time string: ${e}`);return t},e=>e.toISOString());const It=new WeakMap;function q(e){let t=It.get(e);if(t===void 0){const i=new e,n=i[ht]??i;i[H]&&i[H]();const r={};for(const[f,l]of Yt(n))r[f]=l;const s=Object.getPrototypeOf(e.prototype);if(s!=null){const f=s.constructor;if(f!==Z&&typeof f=="function"){const u=q(f).shape;for(const y of ot(u))if(y in r&&r[y]!==u[y])throw new Error(`Cannot extend: field '${y}' already exists in type definition`)}}const o={},a=e.prototype;for(const f of Object.getOwnPropertyNames(a))f!=="constructor"&&typeof a[f]=="function"&&(o[f]=a[f]);t=Wt(d.ENTITY|d.OBJECT,r),t._entityClass=e,ot(o).length>0&&(t._methods=o),typeof o.__subscribe=="function"&&(t._entityConfig={hasSubscribe:!0});const c=e;c.cache&&(t._entityCache=c.cache),It.set(e,t)}return t}function Ue(e){return q(e)}function Zt(e,t){if(t==null)return;const i=new Map;if(Array.isArray(t))for(const n of t){const[r,s]=n,a=q(r).typenameValue;if(a===void 0)continue;const c=[];for(const[f,l]of Object.entries(s))c.push([f,l]);c.length>0&&i.set(a,c)}else{const r=Object.entries(t);if(r.length===0)return;const s=r.map(([o,a])=>[o,a]);for(const o of e){const a=o.typenameValue;a!==void 0&&i.set(a,s)}}return i.size>0?i:void 0}function te(e){return Array.isArray(e)?e.map(t=>q(t)):[q(e)]}function Ve(e,t){const i=te(e),n=i.length===1?i[0]:vt(...i.map(o=>o)),r=d.ARRAY|d.LIVE,s=new _(r,n);return s._liveConfig=L.array(i,Zt(i,t?.constraints),t?.sort),s}function Ke(e,t,i){const n=te(t),r=e,s=d.LIVE,o=new _(s,void 0);return o._liveConfig=L.value(n,Zt(n,i?.constraints),r,i.onCreate,i.onUpdate,i.onDelete),o}const ee={format:qe,typename:Pe,const:je,enum:zt,id:d.ID|d.STRING|d.NUMBER,string:d.STRING,number:d.NUMBER,boolean:d.BOOLEAN,null:d.NULL,undefined:d.UNDEFINED,array:Re,object:De,record:Se,union:vt,nullish:ke,optional:Fe,nullable:Te,result:Ae,entity:Ue,liveArray:Ve,liveValue:Ke};function U(e,t,i){return new TypeError(`Validation error at ${e}`)}const ie=Array.isArray;function Mt(e){if(e===null)return d.NULL;switch(typeof e){case"number":return d.NUMBER;case"string":return d.STRING;case"boolean":return d.BOOLEAN;case"undefined":return d.UNDEFINED;case"object":return ie(e)?d.ARRAY:d.OBJECT;default:throw new Error(`Invalid type: ${typeof e}`)}}function $e(e){return P(e)}function P(e){if(e===null||typeof e!="object")return e;if(ie(e))return e.map(i=>P(i));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){const i=new Map;for(const[n,r]of e)i.set(P(n),P(r));return i}if(e instanceof Set){const i=new Set;for(const n of e)i.add(P(n));return i}const t={};for(const i of Object.keys(e))t[i]=P(e[i]);return t}const wt=Object.entries,Qe=()=>{};class ct{queryClient=void 0;preloadedEntities=void 0;warn=Qe;isPartialEvent=!1;seen=void 0;seenByKey=void 0;reset(t,i,n,r=!1){this.queryClient=t,this.preloadedEntities=i,this.warn=n,this.isPartialEvent=r,t!==void 0&&(this.seen===void 0?(this.seen=new Map,this.seenByKey=new Map):(this.seen.clear(),this.seenByKey.clear()))}}function ne(e,t,i){return F(e,t,i,"")}function Be(e,t,i){return Et(e,t,i)}function kt(e,t,i,n){const r=e>>Ht;if((e&d.IS_EAGER_FORMAT)!==0)try{return new Q(t,r,!0)}catch(o){if((e&d.UNDEFINED)!==0){i.warn("Invalid formatted value for optional type, defaulting to undefined",{value:t,path:n,error:o instanceof Error?o.message:String(o)});return}throw o}return new Q(t,r,!1)}function F(e,t,i,n){const r=t;if(r instanceof tt){const c=r.get(e);if(c===void 0)throw U(n);return c}if(r instanceof Set){if(!r.has(e))throw U(n);return e}if(typeof r=="string"){if(e==null)return r;if(e!==r)throw U(n);return e}if(typeof r=="number"){const c=Mt(e);if((r&c)===0){if((r&d.UNDEFINED)!==0){i.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:n});return}throw U(n)}return(r&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?kt(r,e,i,n):e}const s=r.mask,o=r._liveConfig;if(o!==void 0&&o.type===J.Value)return o.valueType!==void 0?F(e,o.valueType,i,n):e;if((s&d.PARSE_RESULT)!==0)try{return{success:!0,value:F(e,r.shape,i,n)}}catch(c){return{success:!1,error:c instanceof Error?c:new Error(String(c))}}const a=Mt(e);if((s&a)===0&&!r.values?.has(e)){if((s&d.UNDEFINED)!==0){i.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:n});return}throw U(n)}return a<d.OBJECT?(s&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?kt(s,e,i,n):e:(s&d.UNION)!==0?Ye(a,e,r,i,n):a===d.ARRAY?re(e,r.shape,i,n):(s&d.RECORD)!==0?se(e,r.shape,i,n):(s&d.ENTITY)!==0&&i.queryClient!==void 0?Et(e,r,i):oe(e,r,i,n)}function Ye(e,t,i,n,r){if(e===d.ARRAY){const s=i.shape[V];return s===void 0||typeof s=="number"?t:re(t,s,n,r)}else{const s=i.typenameField,o=s?t[s]:void 0;if(o===void 0||typeof o!="string"){const c=i.shape[K];if(c===void 0)throw new Error(`Typename field '${s}' is required for union discrimination but was not found in the data`);return se(t,c,n,r)}const a=i.shape[o];if(a===void 0||typeof a=="number")throw new Error(`Unknown typename '${o}' in union`);return a.mask&d.ENTITY&&n.queryClient!==void 0?Et(t,a,n):oe(t,a,n,r)}}function re(e,t,i,n){const r=[];for(let s=0;s<e.length;s++)try{r.push(F(e[s],t,i,`${n}[${s}]`))}catch(o){i.warn("Failed to parse array item, filtering out",{index:s,value:e[s],error:o instanceof Error?o.message:String(o)})}return r}function se(e,t,i,n){for(const[r,s]of wt(e))e[r]=F(s,t,i,`${n}["${r}"]`);return e}function oe(e,t,i,n){if(O.has(e))return e;const r=t.shape;for(const[s,o]of wt(r))e[s]=F(e[s],o,i,`${n}.${s}`);return e}function Et(e,t,i){const n=i.queryClient,r=i.preloadedEntities;let s,o;if(r!==void 0)s=e.__entityRef,o=s;else{const p=e[t.idField];if(p==null||typeof p!="string"&&typeof p!="number")throw new Error(`Entity id must be a string or number: ${t.typenameValue} (got ${typeof p})`);o=p,s=S.hashValue([t.typenameValue,o])}const a=i.seenByKey.get(s);if(a!==void 0)return a.data;if(r!==void 0){const g=n.entityMap.getEntity(s)?.data??r.get(s);if(g===void 0)throw new Error(`Cached entity ${s} not found in preloaded map`);e=g}const c={};typeof t.idField=="symbol"&&(c[t.idField]=o);const f=n.entityMap.getEntity(s),l=i.isPartialEvent&&f!==void 0,u={key:s,shape:t,data:c,rawKeys:l?new Set(Object.keys(e)):void 0};i.seen.set(c,u),i.seenByKey.set(s,u);const y=`[[${t.typenameValue}:${o}]]`,v=t.shape;for(const[p,g]of wt(v))l&&!(p in e)||(c[p]=F(e[p],g,i,`${y}.${p}`));return c}function Ge(e,t){return We(e,t.shape,t.typenameField)}function We(e,t,i){if(t===void 0)return!0;for(const n of Object.keys(t)){if(n===i)continue;const r=t[n];if(r instanceof _){if((r.mask&d.UNDEFINED)!==0)continue;if(!(n in e)||e[n]===void 0)return!1}else if(typeof r=="number"){if((r&d.UNDEFINED)!==0)continue;if(!(n in e)||e[n]===void 0)return!1}else if(!(n in e)||e[n]===void 0)return!1}return!0}const ze=Object.prototype,W=new WeakMap;function N(e){if(typeof e!="object"||e===null)return e;if(et.has(e))return N(e.getValue());if(O.has(e))return e;if(Array.isArray(e)){let t=W.get(e);return t===void 0&&(t=new Proxy(e,He),W.set(e,t)),t}if(Object.getPrototypeOf(e)===ze){let t=W.get(e);return t===void 0&&(t=new Proxy(e,Je),W.set(e,t)),t}return e}const He={get(e,t,i){if(typeof t=="string"){const n=Number(t);if(Number.isInteger(n)&&n>=0&&n<e.length)return N(e[n])}return Reflect.get(e,t,i)},set(){return!1},deleteProperty(){return!1}},Je={get(e,t,i){return typeof t=="string"?N(e[t]):Reflect.get(e,t,i)},set(){return!1},deleteProperty(){return!1},has(e,t){return t in e},ownKeys(e){return Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Object.getOwnPropertyDescriptor(e,t)}},Xe=(e,t,i)=>{const n=e,r=Object.keys(n),s=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:void 0;let o=!s||Object.keys(s).length!==r.length;const a={};for(let c=0;c<r.length;c++){const f=r[c],l=n[f];let u;typeof l=="function"?u=l:u=i(l,s?.[f]),a[f]=u,!o&&u!==s?.[f]&&(o=!0)}return o?a:s};S.registerCustomSnapshot(Z,Xe);class Ze{_notifier;_queryClient;_proxies=new Map;key;typename;id;idField;data;refCount=0;entityRefs;liveCollections=[];satisfiedDefs=new WeakSet;parseId=-1;_entityCache;_extraMethods;_extraGetters;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._queryClient=o,this.key=t,this.typename=i,this.id=n,this.idField=r,this.data=s,this.entityRefs=void 0}retain(){this.refCount++;const t=this._entityCache?.gcTime;t!==void 0&&this._queryClient.gcManager.cancel(this.key,t)}release(){if(--this.refCount>0||this.refCount<0)return;const t=this._entityCache?.gcTime;t!==void 0?this._queryClient.gcManager.schedule(this.key,t,X.Entity):this.evict()}evict(){const t=this.liveCollections.slice();this.liveCollections.length=0;for(const n of t)n.destroy();this._queryClient.entityMap.remove(this.key);const i=this.entityRefs;if(this.entityRefs=void 0,i)for(const n of i.keys())n.release()}setChildRefs(t,i){const n=this.entityRefs;if(t!==void 0&&t.size>0)for(const r of t.keys())(n===void 0||!n.has(r))&&r.retain();if(n!==void 0&&n.size>0)for(const r of n.keys())(t===void 0||!t.has(r))&&r.release();this.entityRefs=t,i&&this.save()}addChildRef(t){this.entityRefs===void 0&&(this.entityRefs=new Map);const i=this.entityRefs.get(t)??0;this.entityRefs.set(t,i+1),i===0&&t.retain(),this.save()}removeChildRef(t){if(this.entityRefs===void 0)return;const i=this.entityRefs.get(t);i!==void 0&&(i<=1?(this.entityRefs.delete(t),t.release()):this.entityRefs.set(t,i-1),this.save())}getProxy(t){const i=t;let n=this._proxies.get(i);return n===void 0&&(n=ei(this,this.key,t,this._notifier,this._queryClient),this._proxies.set(i,n)),n}get proxy(){return this._proxies.values().next().value}satisfiesDef(t){return this.satisfiedDefs.has(t)?!0:Ge(this.data,t)?(this.satisfiedDefs.add(t),!0):!1}save(){this._queryClient.entityMap.save(this)}notify(){this._notifier.notify()}consume(){this._notifier.consume()}}function ti(e,t,i){const n=[];for(const r of e){if(typeof r!="object"||r===null)continue;const s=O.get(r);if(s===void 0)continue;const o=i.entityMap.getEntity(s);o!==void 0&&o.satisfiesDef(t)&&n.push(r)}return n}function ei(e,t,i,n,r){const s=i.shape??{},o=i,a=o._methods,c=o._entityClass,f=o._entityConfig,l=c?c.prototype:Z.prototype;i.typenameField;const u=new Map,y=new Map,v=()=>({__entityRef:t});let p;f?.hasSubscribe&&a&&"__subscribe"in a&&(p=E.relay(b=>{const h=w=>{w.__eventSource=t,r.applyMutationEvent(w)},C=a.__subscribe.call(g,h);return b.value=g,C}));let g;const m=Object.keys(s);if(m.includes("__typename")||m.push("__typename"),a)for(const b of Object.keys(a))m.includes(b)||m.push(b);let I,R=m;function G(){const b=e._extraMethods;if(b!==I){if(I=b,R=m.slice(),b!==void 0)for(const C of Object.keys(b))R.includes(C)||R.push(C);const h=e._extraGetters;if(h!==void 0)for(const C of Object.keys(h))R.includes(C)||R.push(C)}return R}const A={getPrototypeOf(){return l},get(b,h,C){if(typeof h=="symbol")return Reflect.get(l,h,C);if(h==="toJSON")return v;if(h==="__context")return r.getContext();if(h==="__typename")return e.typename;if(p?.value,n.consume(),typeof h=="string"){const M=e._extraGetters;if(M!==void 0&&h in M)return M[h]();const D=e._extraMethods;if(D!==void 0&&h in D){let x=u.get(h);return x||(x=D[h].bind(g),u.set(h,x)),x}if(a&&h in a){let x=u.get(h);return x||(x=E.reactiveMethod(g,a[h].bind(g)),u.set(h,x)),x}}const w=e.data[h];if(typeof w=="object"&&w!==null&&et.has(w))return N(w.getValue());if(Array.isArray(w)&&typeof h=="string"){const M=s[h];if(M instanceof _&&(M.mask&d.ARRAY)!==0){const D=M.shape;if(D instanceof _&&(D.mask&d.ENTITY)!==0){const x=D.typenameValue;if(x!==void 0){const Rt=r.getEntityDefsForTypename(x);if(Rt!==void 0&&Rt.length>1){const it=y.get(h);if(it!==void 0&&it.source===w)return N(it.filtered);const St=ti(w,D,r);return y.set(h,{source:w,filtered:St}),N(St)}}}}return N(w)}return N(w)},set(){return!1},has(b,h){if(h==="__typename")return!0;if(typeof h=="string"){const C=e._extraGetters;if(C&&h in C)return!0;const w=e._extraMethods;if(w&&h in w||a&&h in a)return!0}return h in s},ownKeys(){return G()},getOwnPropertyDescriptor(b,h){if(h==="__typename")return{enumerable:!0,configurable:!0,value:e.typename,writable:!1};if(h in s)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};if(typeof h=="string"){const C=e._extraGetters;if(C&&h in C)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};const w=e._extraMethods;if(w&&h in w)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};if(a&&h in a)return{enumerable:!1,configurable:!0,value:A.get(b,h,g),writable:!1}}}};return g=new Proxy({},A),O.set(g,t),E.setScopeOwner(g,r),g}class ii{instances=new Map;persistEntity;constructor(t){this.persistEntity=t}hasEntity(t){return this.instances.has(t)}getEntity(t){return this.instances.get(t)}getOrCreateEntity(t,i,n,r){let s=this.instances.get(t);if(s===void 0){const o=n.idField;if(o===void 0)throw new Error(`Entity id field is required ${n.typenameValue}`);const a=i[o];if(typeof a!="string"&&typeof a!="number")throw new Error(`Entity id must be string or number: ${n.typenameValue}`);const c=n;s=new Ze(t,n.typenameValue,a,o,i,r),s._entityCache=c._entityCache,this.instances.set(t,s)}return s.parseId=r.currentParseId,s}remove(t){this.instances.delete(t)}save(t){let i;if(t.entityRefs){i=new Set;for(const n of t.entityRefs.keys())i.add(n.key)}this.persistEntity(t.key,t.data,i)}}class bt{onlineSignal;manualOverride=void 0;eventListenersAttached=!1;constructor(t){const i=t??this.detectOnlineStatus();this.onlineSignal=E.signal(i),this.canAttachListeners()&&this.attachEventListeners()}get isOnline(){return this.manualOverride!==void 0?this.manualOverride:this.onlineSignal.value}setNetworkStatus(t){this.manualOverride=t,this.onlineSignal.value=t}clearManualOverride(){this.manualOverride=void 0,this.onlineSignal.value=this.detectOnlineStatus()}getOnlineSignal(){return this.onlineSignal}detectOnlineStatus(){return typeof navigator<"u"&&"onLine"in navigator?navigator.onLine:!0}canAttachListeners(){return typeof window<"u"&&typeof window.addEventListener=="function"}destroy(){this.eventListenersAttached&&this.handleOnline&&this.handleOffline&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline),this.eventListenersAttached=!1)}handleOnline=void 0;handleOffline=void 0;attachEventListeners(){this.eventListenersAttached||(this.handleOnline=()=>{this.manualOverride===void 0&&(this.onlineSignal.value=!0)},this.handleOffline=()=>{this.manualOverride===void 0&&(this.onlineSignal.value=!1)},window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline),this.eventListenersAttached=!0)}}class Ct{static onlineSignal=E.signal(!0);get isOnline(){return!0}setNetworkStatus(t){}clearManualOverride(){}getOnlineSignal(){return Ct.onlineSignal}destroy(){}}const ae=new bt,ni=E.context(ae);function xt(e,t=typeof window>"u"){let i;e===!1?i=0:e===void 0||e===!0?i=t?0:3:typeof e=="number"?i=e:i=e.retries;const n=typeof e=="object"&&e.retryDelay?e.retryDelay:r=>1e3*Math.pow(2,r);return{retries:i,retryDelay:n}}class ri{static cache;static adapter;params;config;constructor(){return yt(this)}}const Ft=new WeakMap;class Y{constructor(t,i){this.captured=i,this.statics=t}statics;createExecutionContext(t,i){return st(this.captured,t,i)}resolveOptions(t){const{methods:i}=this.captured,n=i.getConfig?i.getConfig.call(t):t.config,r=xt(n?.retry);return{config:n,retryConfig:r}}static for(t){let i=Ft.get(t);if(i!==void 0)return i;const n=new t,r=Bt(n),s=String(r.methods.getIdentityKey.call(r.fields)),o=r.fields.result,a=o instanceof _?o:ee.object(o),c=(a.mask&d.ENTITY)!==0,f=t.cache,l=r.fields.fetchNext,u=t.adapter;if(!u)throw new Error(`Query class "${t.name}" must define a static \`adapter\` property. Extend RESTQuery (from fetchium/rest) or set \`static adapter = MyAdapter\` on your query class.`);const y=typeof u.prototype.sendNext=="function",v=c?a:new _(d.ENTITY|d.OBJECT,a.shape,void 0,void 0,s,lt);return i=new Y({id:s,shape:v,cache:f,rawFetchNext:l,hasSendNext:y,isEntityResult:c,adapterClass:u},r),Ft.set(t,i),i}}const si=(e,t)=>{const i=Y.for(e);return Ot(i,t)};function oi(e,...t){const i=Y.for(e),n=E.getContext(me);if(n===void 0)throw new Error("QueryClient not found");const r=t[0];return n.getQuery(i,r)}function ft(e){if(e.reason!==void 0)return e.reason;if(typeof DOMException<"u")return new DOMException("The operation was aborted","AbortError");const t=new Error("The operation was aborted");return t.name="AbortError",t}function ce(e,t){return new Promise((i,n)=>{if(t?.aborted){n(ft(t));return}const r=setTimeout(i,e);t?.addEventListener("abort",()=>{clearTimeout(r),n(ft(t))},{once:!0})})}async function ut(e,t,i){const n=Math.max(0,t.retries);let r;for(let s=0;s<=n;s++){if(i?.aborted)throw ft(i);try{return await e()}catch(o){if(r=o,s>=n)throw o;await ce(t.retryDelay(s),i)}}throw r}class ai{def;queryKey;storageKey=-1;relay;queryClient;initialized=!1;updatedAt=void 0;params=void 0;unsubscribe=void 0;lastSubscribeFn=void 0;_relayState=void 0;_isActive=!1;wasPaused=!1;currentParams=void 0;debounceTimer=void 0;_resolvedOptions=E.reactiveSignal(()=>this.def.resolveOptions(this._executionCtx));get config(){if(this._executionCtx!==void 0)return this._resolvedOptions.value.config}get retryConfig(){return this._executionCtx===void 0?xt(void 0):this._resolvedOptions.value.retryConfig}_abortController=void 0;_executionCtx=void 0;_executionCtxKey=-1;rootEntity;_extraMethods={};_queryId=0;get key(){return this.queryKey}get relayState(){return this._relayState}constructor(t,i,n,r){this.def=t,this.queryClient=i,this.queryKey=n,this.params=r,this._extraMethods={__refetch:this.refetch},t.statics.hasSendNext&&(this._extraMethods.__fetchNext=this.fetchNext);const s=Lt(r);this._queryId=s!==void 0?S.hashValue(s):0,this.relay=E.relay(o=>{this._relayState=o;const a=()=>{this._isActive=!1,clearTimeout(this.debounceTimer),this.debounceTimer=void 0,this._abortController?.abort(),this._abortController=void 0,this._fetchNextAbort?.abort(),this._fetchNextAbort=void 0,this._fetchNextPromise=void 0,this.unsubscribe?.(),this.unsubscribe=void 0,this.lastSubscribeFn=void 0;const f=this.config?.gcTime??qt.DEFAULT_GC_TIME;this.queryClient.gcManager.schedule(this.queryKey,f,X.Query)},c=(f=!1)=>{const{wasPaused:l,isPaused:u,initialized:y}=this;if(this.wasPaused=u,u&&!l&&y){a();return}this._isActive=!0;const v=Lt(this.params),p=Ot(this.def,v),g=p!==this.storageKey;g&&(this.currentParams=v,this.storageKey=p),this.getOrCreateExecutionContext(),this.initialized?l||f?(this.queryClient.activateQuery(this),f&&this.updatedAt!==void 0&&this.reconcileSubscription(),this.relayState.isPending&&this._abortController===void 0?this.runQueryImmediately():(this.config?.refreshStaleOnReconnect??!0)&&this.isStale&&this.runDebounced()):g&&(this.lastSubscribeFn=void 0,this.reconcileSubscription(),this.runDebounced()):(this.queryClient.activateQuery(this),this.initialize())};return c(!0),{update:c,deactivate:a}},{desc:`Query(${t.statics.id})`})}applyData(t,i,n=!1,r){const s=this.def;return this.rootEntity=this.queryClient.parseAndApplyRootEntity(t,this._queryId,s.statics.shape,i,n,r),this.rootEntity._extraMethods===void 0&&(this.rootEntity._extraMethods=this._extraMethods,this.rootEntity._extraGetters={__hasNext:()=>this.hasNext,__isFetchingNext:()=>this._fetchNextPromise!==void 0}),this.rootEntity.getProxy(s.statics.shape)}saveQueryMetadata(){if(this.rootEntity===void 0||this.updatedAt===void 0)return;const t=new Map(this.rootEntity.entityRefs??[]);t.set(this.rootEntity,1),this.queryClient.saveQueryData(this.def,this.storageKey,{__entityRef:this.rootEntity.key},this.updatedAt,t)}async initialize(){const t=this.queryClient,i=this.relayState;this.initialized=!0;let n;try{n=await t.loadCachedQuery(this.def,this.storageKey),n!==void 0&&(this.updatedAt=n.updatedAt,i.value=this.applyData(n.value,!1,!1,n.preloadedEntities))}catch(r){t.store.deleteQuery(this.storageKey),t.getContext().log?.warn?.("Failed to initialize query, the query cache may be corrupted or invalid",r)}if(!this.isPaused)try{if(n!==void 0&&this.reconcileSubscription(),n===void 0||this.isStale){if(await ce(0),this.isPaused)return;this.runQueryImmediately()}}catch(r){i.setError(r)}}reconcileSubscription(){const t=this.config?.subscribe;if(t===this.lastSubscribeFn||(this.unsubscribe?.(),this.unsubscribe=void 0,this.lastSubscribeFn=t,!t))return;const i=this._executionCtx;this.unsubscribe=t.call(i,n=>{n.__eventSource=this.queryKey,this.queryClient.applyMutationEvent(n)})}getOrCreateExecutionContext(){return(this._executionCtx===void 0||this._executionCtxKey!==this.storageKey)&&(this._executionCtxKey=this.storageKey,this._executionCtx=this.def.createExecutionContext(this.currentParams??{},this.queryClient.getContext()),this._executionCtx.refetch=()=>this.refetch(),this._executionCtx.rawFetchNext=this.def.statics.rawFetchNext,this._resolvedOptions=E.reactiveSignal(()=>this.def.resolveOptions(this._executionCtx))),this._executionCtx}async runQuery(){const t=this.def;if(this.isPaused)throw new Error("Query is paused due to network status");const i=this.getOrCreateExecutionContext(),n=this.queryClient.getAdapter(t.statics.adapterClass),r=this._abortController?.signal??new AbortController().signal;return ut(async()=>{const s=await n.send(i,r);this.updatedAt=Date.now();const o=this.applyData(s,!0);return this.saveQueryMetadata(),this.reconcileSubscription(),o},this.retryConfig,r)}runQueryImmediately(){this._abortController?.abort(),this._abortController=new AbortController,this._fetchNextAbort?.abort(),this._fetchNextAbort=void 0,this._fetchNextPromise=void 0,this.relayState.setPromise(this.runQuery())}runDebounced(){if(this.relayState.isPending)return;const t=this.config?.debounce??0;clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=void 0,this.runQueryImmediately()},t)}refetch=()=>this.relayState.isPending?this.relay:(this.runQueryImmediately(),this.relay);markStale(){this.updatedAt=0,this._isActive&&!this.isPaused&&this.runDebounced()}get resolvedParams(){return this.currentParams}_fetchNextPromise=void 0;_fetchNextAbort=void 0;fetchNext=()=>{if(this.updatedAt===void 0)throw new Error("Cannot call __fetchNext before initial data has loaded");return this._fetchNextPromise!==void 0?this._fetchNextPromise:(queueMicrotask(()=>this.rootEntity?.notify()),this._fetchNextPromise=this.runFetchNext().then(t=>(this._fetchNextPromise=void 0,this.rootEntity?.notify(),t),t=>{throw this._fetchNextPromise=void 0,this.rootEntity?.notify(),t}),this._fetchNextPromise)};get hasNext(){if(this.rootEntity===void 0||!this._executionCtx)return!1;const t=this.queryClient.getAdapter(this.def.statics.adapterClass);return t.hasNext?(this._executionCtx.resultData=this.rootEntity.data,t.hasNext(this._executionCtx)):!1}async runFetchNext(){const t=this.def;this._fetchNextAbort=new AbortController;const i=this._fetchNextAbort.signal,n=this.getOrCreateExecutionContext();n.resultData=this.rootEntity.data;const r=this.queryClient.getAdapter(t.statics.adapterClass);return ut(async()=>{const s=await r.sendNext(n,i);this.updatedAt=Date.now();const o=this.applyData(s,!0,!0);return this.saveQueryMetadata(),o},this.retryConfig,i)}get isStale(){if(this.updatedAt===void 0)return!0;const t=this.config?.staleTime??0;return Date.now()-this.updatedAt>=t}get isPaused(){const t=this.config?.networkMode??j.Online;if(t===j.Always)return!1;const i=this.queryClient.networkManager.getOnlineSignal().value;switch(t){case j.Online:return!i;case j.OfflineFirst:return!i&&this.updatedAt===void 0;default:return!1}}}class ci{def;queryClient;_inFlight=!1;task;constructor(t,i){this.def=t,this.queryClient=i,this.task=this.createTask()}createTask(){return E.task(async t=>{if(this._inFlight)throw new Error("A mutation is already in progress. Await the previous call before starting a new one.");this._inFlight=!0;try{const i=await this.executeWithRetry(t),n=this.validateResponse(i);return this.processEffects(t,n),n}finally{this._inFlight=!1}},{desc:`Mutation(${this.def.id})`})}validateResponse(t){const i=this.def.responseShape;if(!(i instanceof _))return t;const n=this.queryClient.getContext().log?.warn??(()=>{}),r=new ct;return r.reset(void 0,void 0,n),ne(t,i,r)}processEffects(t,i){let n;if(this.def.hasGetEffects){const s=st(this.def.captured,t??{},this.queryClient.getContext());s.result=i,n=s.getEffects()}else if(this.def.effects!==void 0){const s={params:t,result:i};n=$(this.def.effects,s)}if(n===void 0)return;const r=this.queryClient;nt(n.creates,"create",r),nt(n.updates,"update",r),nt(n.deletes,"delete",r),n.invalidates&&r.invalidateQueries(n.invalidates)}executeWithRetry(t){const i=xt(this.def.config?.retry,!0),n=this.queryClient.getAdapter(this.def.adapterClass);if(!n.sendMutation)throw new Error(`Adapter "${this.def.adapterClass.name}" does not implement sendMutation(). Add a sendMutation() method to handle mutations.`);return ut(async()=>{const r=new AbortController,s=st(this.def.captured,t??{},this.queryClient.getContext());return await n.sendMutation(s,r.signal)},i)}}function fi(e){return typeof e=="string"?e:q(e).typenameValue}function nt(e,t,i){if(e)for(const[n,r]of e){const s=fi(n);s!==void 0&&i.applyMutationEvent({type:t,typename:s,data:r})}}const fe="__eventSource";function ue(e){return{field:e,segments:e.indexOf(".")!==-1?e.split("."):void 0}}function ui(e){return e.map(ue)}function di(e,t){if(t.segments===void 0)return e[t.field];let i=e;for(const n of t.segments){if(i==null)return;i=i[n]}return i}function de(e,t){const i=[];for(let n=0;n<t.length;n++){const r=t[n],s=di(e,r);if(s===void 0)return;i.push(r.field,s)}return S.hashValue(i)}function li(e,t){if(e===void 0)return;const i=new Map;for(const[n,r]of e){const s=r.slice().sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0),o=[];let a=!0;for(const[c,f]of s){let l;if($t(f)){const u=Qt(f);l=pt(u,t)}else l=f;if(l===void 0){a=!1;break}o.push(c,l)}a&&i.set(n,S.hashValue(o))}return i.size>0?i:void 0}function Tt(e,t){const i=e.get(t);if(i!==void 0)return i.map(([n])=>n).sort()}class hi{fields;fieldPaths;_bindings=new Map;constructor(t){this.fields=t,this.fieldPaths=t.map(ue)}register(t,i){let n=this._bindings.get(t);n===void 0&&(n=new Set,this._bindings.set(t,n)),n.add(i)}unregister(t,i){const n=this._bindings.get(t);n!==void 0&&(n.delete(i),n.size===0&&this._bindings.delete(t))}getMatching(t){return this._bindings.get(t)}get isEmpty(){return this._bindings.size===0}}function Pt(e){return S.hashValue(e)}class yi{_groups=new Map;getOrCreateGroup(t){const i=Pt(t);let n=this._groups.get(i);return n===void 0&&(n=new hi(t),this._groups.set(i,n)),n}register(t,i,n){this.getOrCreateGroup(i).register(t,n)}unregister(t,i,n){const r=Pt(i),s=this._groups.get(r);s!==void 0&&(s.unregister(t,n),s.isEmpty&&this._groups.delete(r))}registerBinding(t,i){const n=t._constraintHashes.get(i);if(n===void 0)return;const r=Tt(t._constraintFieldRefs,i);r!==void 0&&this.register(n,r,t)}unregisterBinding(t,i){const n=t._constraintHashes.get(i);if(n===void 0)return;const r=Tt(t._constraintFieldRefs,i);r!==void 0&&this.unregister(n,r,t)}routeEvent(t,i,n,r,s,o){for(const a of this._groups.values()){const c=de(i,a.fieldPaths);if(c===void 0)continue;const f=a.getMatching(c);if(f!==void 0)for(const l of f)l.onEvent(t,n,r,s,o)}}}function jt(e){const t=new Set;for(const i of e)if(typeof i=="object"&&i!==null){const n=T(i);n!==void 0&&t.add(n)}return t}class le{_queryClient;_parent;_constraintHashes;_entityDefsByTypename;_constraintFieldRefs;instance;constructor(t,i,n,r,s,o){this._queryClient=n,this._parent=r,this._constraintHashes=s,this._constraintFieldRefs=i,this.instance=o,this._entityDefsByTypename=new Map;for(const a of t)a.typenameValue!==void 0&&this._entityDefsByTypename.set(a.typenameValue,a);et.add(this)}getValue(){return this.instance.getValue()}toJSON(){return this.instance.getRawValue()}reset(t){this.instance.reset(t)}append(t){this.instance.append(t)}onEvent(t,i,n,r,s){const o=this._entityDefsByTypename.get(t);if(o===void 0)return;const a=this._queryClient.entityMap.getEntity(i);if(n==="delete"){const f=a!==void 0?a.getProxy(o):s;f!==void 0&&(this.instance.onEvent(i,f,s??a?.data??{},"delete"),r?.());return}if(a===void 0||!a.satisfiesDef(o))return;r?.();const c=a.getProxy(o);this.instance.onEvent(i,c,a.data,n)}destroy(){this._queryClient.unregisterLiveCollection(this);const t=this._parent.liveCollections,i=t.indexOf(this);i!==-1&&t.splice(i,1)}}class pi{_notifier;_items;_keys;_outputSignal;_queryClient;_parent;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._items=n,this._keys=jt(n),this._queryClient=t,this._parent=i;const a=r!==void 0&&s!==void 0,c=o!==void 0;(a||c)&&(this._outputSignal=E.reactiveSignal(()=>{this._notifier.consume();let f=this._items;if(a){const l=[];for(const u of f){if(typeof u!="object"||u===null){l.push(u);continue}const y=T(u);if(y===void 0){l.push(u);continue}const v=t.entityMap.getEntity(y);if(v===void 0){l.push(u);continue}v.consume(),de(v.data,r)===s&&l.push(u)}f=l}return c&&(f=(f===this._items?f.slice():f).sort(o)),f}))}onEvent(t,i,n,r){switch(r){case"create":this.add(t,i);break;case"update":!this.has(t)&&i!==void 0&&this.add(t,i);break;case"delete":this.remove(t);break}}getValue(){return this._outputSignal!==void 0?this._outputSignal.value:(this._notifier.consume(),this._items)}getRawValue(){return this._items}add(t,i){if(this._keys.has(t))return!1;this._keys.add(t),this._items.push(i);const n=this._queryClient.entityMap.getEntity(t);return n!==void 0&&(this._parent.addChildRef(n),n.save()),this._notifier.notify(),!0}remove(t){if(!this._keys.has(t))return!1;this._keys.delete(t);const i=this._findIndex(t);i!==-1&&this._items.splice(i,1);const n=this._queryClient.entityMap.getEntity(t);return n!==void 0&&this._parent.removeChildRef(n),this._notifier.notify(),!0}has(t){return this._keys.has(t)}reset(t){const i=this._items,n=Array.isArray(t)?t:[];this._items=n,this._keys=jt(n);for(const r of n)if(typeof r=="object"&&r!==null){const s=T(r);if(s!==void 0){const o=this._queryClient.entityMap.getEntity(s);o!==void 0&&this._parent.addChildRef(o)}}for(const r of i)if(typeof r=="object"&&r!==null){const s=T(r);if(s!==void 0){const o=this._queryClient.entityMap.getEntity(s);o!==void 0&&this._parent.removeChildRef(o)}}this._notifier.notify()}append(t){if(Array.isArray(t))for(const i of t){if(typeof i!="object"||i===null)continue;const n=T(i);n!==void 0&&this.add(n,i)}}_findIndex(t){for(let i=0;i<this._items.length;i++){const n=this._items[i];if(typeof n=="object"&&n!==null&&T(n)===t)return i}return-1}}class gi{_notifier;_value;_createdKeys;_deletedKeys;_queryClient;_parent;_onCreate;_onUpdate;_onDelete;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._value=n,this._createdKeys=new Set,this._deletedKeys=new Set,this._queryClient=t,this._parent=i,this._onCreate=r,this._onUpdate=s,this._onDelete=o}onEvent(t,i,n,r){switch(r){case"create":if(this._createdKeys.has(t))return;this._createdKeys.add(t),this._value=this._onCreate(this._value,i);break;case"update":this._value=this._onUpdate(this._value,i??n);break;case"delete":if(this._deletedKeys.has(t))return;this._deletedKeys.add(t),this._value=this._onDelete(this._value,i??n);break}this._notifier.notify()}getValue(){return this._notifier.consume(),this._value}getRawValue(){return this._value}reset(t){this._value=t,this._createdKeys.clear(),this._deletedKeys.clear(),this._notifier.notify()}append(t){}}function he(e,t,i,n,r){let s=e.constraintFieldRefs;if(s===void 0){s=new Map;for(const f of e.entityDefs){const l=f.typenameValue;l!==void 0&&s.set(l,[[fe,i.key]])}}const o=li(s,n)??new Map;let a;if(e.type===J.Array){let f,l;if(e.constraintFieldRefs!==void 0&&o.size>0&&o.size===1)for(const[u]of e.constraintFieldRefs){const y=o.get(u);if(y!==void 0){l=y;const v=e.constraintFieldRefs.get(u);v!==void 0&&(f=ui(v.map(([p])=>p)));break}}a=new pi(r,i,Array.isArray(t)?t:[],f,l,e.sort)}else a=new gi(r,i,t,e.onCreate,e.onUpdate,e.onDelete);const c=new le(e.entityDefs,s,r,i,o,a);return i.liveCollections.push(c),r.registerLiveCollection(c),c}const ye=Object.entries,pe=Object.prototype;function rt(e,t,i,n=!1){const r=e.queryClient;r.currentParseId++;const s=e.seen,o=new Map;return{data:B(t,s,r,i,o,n),entityRefs:o}}function B(e,t,i,n,r,s){if(typeof e!="object"||e===null)return e;const o=t.get(e);if(o!==void 0)return vi(o,t,i,n,r,s);if(Array.isArray(e)){for(let a=0;a<e.length;a++){const c=e[a];typeof c=="object"&&c!==null&&!(c instanceof Q)&&!O.has(c)&&(e[a]=B(c,t,i,n,r,s))}return e}if(Object.getPrototypeOf(e)===pe&&!O.has(e)){const a=e;for(const c of Object.keys(a)){const f=a[c];typeof f=="object"&&f!==null&&!(f instanceof Q)&&!O.has(f)&&(a[c]=B(f,t,i,n,r,s))}}return e}function ge(e){return typeof e=="object"&&e!==null&&!(e instanceof Q)&&!O.has(e)}function vi(e,t,i,n,r,s){const{key:o,data:a,shape:c,rawKeys:f}=e,l=c.shape,u=i.prepareEntity(o,a,c),y=u.data,v=y!==a,p=v&&f!==void 0&&u.entityRefs!==void 0?new Map(u.entityRefs):new Map;if(v?(ve(l,a,y,f,u,y,t,i,n,p,s),u.notify()):_e(l,a,u,a,t,i,n,p,s),s&&u.liveCollections.length>0)for(const m of u.liveCollections){const I=m.instance.getRawValue();if(Array.isArray(I))for(const R of I){if(typeof R!="object"||R===null)continue;const G=O.get(R);if(G===void 0)continue;const A=i.entityMap.getEntity(G);A!==void 0&&p.set(A,(p.get(A)??0)+1)}}u.setChildRefs(p.size>0?p:void 0,n);const g=u.getProxy(c);return r.set(u,(r.get(u)??0)+1),g}function ve(e,t,i,n,r,s,o,a,c,f,l){for(const[u,y]of ye(e))if(!(n!==void 0&&!n.has(u)))if(ge(t[u])&&(t[u]=B(t[u],o,a,c,f,l)),y instanceof _&&y._liveConfig!==void 0){const v=i[u];v instanceof le?l?v.append(t[u]):v.reset(t[u]):i[u]=he(y._liveConfig,t[u],r,s,a)}else{const v=t[u],p=i[u];if(dt(v)&&dt(p)){const g=y instanceof _&&y.shape!==void 0?y.shape:void 0;if(g!==void 0)ve(g,v,p,void 0,r,s,o,a,c,f,l);else for(const m of Object.keys(v))p[m]=v[m];i[u]=p}else i[u]=v}}function _e(e,t,i,n,r,s,o,a,c){for(const[f,l]of ye(e))if(f in t)if(ge(t[f])&&(t[f]=B(t[f],r,s,o,a,c)),l instanceof _&&l._liveConfig!==void 0)t[f]=he(l._liveConfig,t[f],i,n,s);else{const u=t[f];if(dt(u)){const y=l instanceof _&&l.shape!==void 0?l.shape:void 0;y!==void 0&&_e(y,u,i,n,r,s,o,a,c)}}}function dt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.getPrototypeOf(e)===pe&&!O.has(e)}function _i(e){if(e!==void 0)return typeof e=="string"?e:typeof e=="function"?e():e.value}function mi(e){return E.isSignal(e)}function Lt(e){if(e===void 0)return;const t={};for(const[i,n]of Object.entries(e))mi(n)?t[i]=n.value:t[i]=n;return t}const Ot=(e,t)=>S.hashValue([e.statics.id,t]);class wi{entityMap;queryInstances=new Map;mutationInstances=new Map;gcManager;networkManager;isServer;store;currentParseId=0;context;typenameRegistry=new Map;constraintRegistry=new Map;mergedDefCache=new Map;adapters=new Map;networkUnsubscribe;constructor(t={}){const{store:i=new At.SyncQueryStore(new At.MemoryPersistentStore),log:n,evictionMultiplier:r,adapters:s,networkManager:o,gcManager:a,...c}=t;this.isServer=typeof window>"u",this.store=i,this.context={...c,log:n??console,evictionMultiplier:r},this.gcManager=t.gcManager??(this.isServer?new Vt:new Ut(this.handleEviction,r)),this.networkManager=t.networkManager??new bt,this.entityMap=new ii((u,y,v)=>this.store.saveEntity(u,y,v));for(const u of t.adapters??[])this.adapters.set(u.constructor,u),u.register(this);const f=this.networkManager.getOnlineSignal(),l=E.watcher(()=>f.value);this.networkUnsubscribe=l.addListener(()=>{const u=f.value;for(const y of this.adapters.values())y.onNetworkStatusChange?.(u)},{skipInitial:!0}),this.store.purgeStaleQueries?.()}getAdapter(t){const i=this.adapters.get(t);if(i)return i;let n;for(const s of this.adapters.values())s instanceof t&&(n??=s);if(n!==void 0)return this.adapters.set(t,n),n;let r;try{r=new t}catch{throw new Error(`No adapter registered for ${t.name} and auto-instantiation failed. Pass an instance via QueryClient config: new QueryClient({ store, adapters: [new ${t.name}(...)] })`)}return this.adapters.set(t,r),r.register(this),r}getContext(){return this.context}registerEntityDef(t){const i=t.typenameValue;if(i===void 0||t._entityClass===void 0)return;const n=this.typenameRegistry.get(i);if(n!==void 0){if(n.indexOf(t)!==-1)return;n.push(t),this.mergedDefCache.delete(i),this.getMergedDef(i)}else this.typenameRegistry.set(i,[t])}getEntityDefsForTypename(t){return this.typenameRegistry.get(t)}getMergedDef(t){let i=this.mergedDefCache.get(t);if(i!==void 0)return i;const n=this.typenameRegistry.get(t);if(n!==void 0)return i=_.merge(n),this.mergedDefCache.set(t,i),i}saveQueryData(t,i,n,r,s){const o=s!==void 0&&s.size>0?new Set([...s.keys()].map(a=>a.key)):void 0;this.store.saveQuery(t,i,n,r,o)}activateQuery(t){const{def:i,queryKey:n,storageKey:r,config:s}=t;this.store.activateQuery(i,r);const o=s?.gcTime??qt.DEFAULT_GC_TIME;this.gcManager.cancel(n,o)}loadCachedQuery(t,i){return this.store.loadQuery(t,i)}getQuery(t,i){const n=Ot(t,i);let r=this.queryInstances.get(n);return r===void 0&&(r=new ai(t,this,n,i),this.queryInstances.set(n,r)),r.relay}getMutation(t){const i=t.id;let n=this.mutationInstances.get(i);return n===void 0&&(n=new ci(t,this),this.mutationInstances.set(i,n)),n.task}parseData(t,i,n){const r=this.context.log?.warn??(()=>{}),s=new ct;return s.reset(this,n,r),{data:ne(t,i,s),ctx:s}}applyRefs(t,i=!0,n=!1){return rt(t.ctx,t.data,i,n)}parseAndApplyRootEntity(t,i,n,r,s=!1,o){typeof n.idField=="symbol"&&typeof t=="object"&&t!==null&&!("__entityRef"in t)&&(t[lt]=i);const a=this.parseData(t,n,o),c=rt(a.ctx,a.data,r,s),f=O.get(c.data);return this.entityMap.getEntity(f)}prepareEntity(t,i,n){return this.registerEntityDef(n),this.entityMap.getOrCreateEntity(t,i,n,this)}applyMutationEvent(t){const{type:i,typename:n}=t,r=this.getMergedDef(n);if(r===void 0)return;const s=r.idField;if(s===void 0||typeof s=="symbol")return;const o=t.data,a=t.id!==void 0?t.id:i==="delete"&&(typeof o=="string"||typeof o=="number")?o:o[s];if(a===void 0)return;const c=S.hashValue([n,a]),f=t.__eventSource,l=typeof o=="object"&&o!==null?o:{},u=this.entityMap.getEntity(c);if(i==="delete"){const g=u!==void 0?u.data:l;this.routeEvent(n,g,c,i,f,void 0,g);return}try{const g=this.context.log?.warn??(()=>{}),m=new ct;m.reset(this,void 0,g,!0);const I=Be(l,r,m);rt(m,I,!0)}catch(g){if(this.context.log?.warn?.("Failed to apply mutation event",g),u===void 0){const m=this.entityMap.getEntity(c);m!==void 0&&m.evict()}return}const y=this.entityMap.getEntity(c);if(y===void 0)return;this.entityMap.save(y);const v=u===void 0;let p=!1;this.routeEvent(n,y.data,c,i,f,()=>{p=!0}),v&&!p&&y.evict()}invalidateQueries(t){for(const i of t){const n=Array.isArray(i),r=n?i[0]:i,s=n?i[1]:void 0,a=Y.for(r).statics.id;for(const[,c]of this.queryInstances)c.def.statics.id===a&&(s===void 0||Ei(c.resolvedParams,s))&&c.markStale()}}handleEviction=(t,i)=>{if(i===X.Query){const r=this.queryInstances.get(t);if(r===void 0)return;r.rootEntity?.evict(),this.queryInstances.delete(t);return}const n=this.entityMap.getEntity(t);n!==void 0&&n.evict()};getOrCreateMatcher(t){let i=this.constraintRegistry.get(t);return i===void 0&&(i=new yi,this.constraintRegistry.set(t,i)),i}registerLiveCollection(t){for(const[i,n]of t._entityDefsByTypename)this.registerEntityDef(n),this.getOrCreateMatcher(i).registerBinding(t,i)}unregisterLiveCollection(t){for(const i of t._entityDefsByTypename.keys()){const n=this.constraintRegistry.get(i);n!==void 0&&n.unregisterBinding(t,i)}}routeEvent(t,i,n,r,s,o,a){const c=this.constraintRegistry.get(t);if(c===void 0)return;const f=s!==void 0?{...i,[fe]:s}:i;c.routeEvent(t,f,n,r,o,a)}destroy(){this.networkUnsubscribe?.(),this.gcManager.destroy(),this.networkManager.destroy();for(const t of this.adapters.values())t.destroy?.();this.adapters.clear(),this.queryInstances.clear(),this.mutationInstances.clear(),this.constraintRegistry.clear(),this.typenameRegistry.clear(),this.mergedDefCache.clear()}}const me=E.context(void 0);function Ei(e,t){if(e===void 0)return!1;for(const i in t)if(e[i]!==t[i])return!1;return!0}exports.ARRAY_KEY=V;exports.Entity=Z;exports.GcManager=Ut;exports.LiveFieldConfig=L;exports.LiveFieldType=J;exports.Mask=d;exports.NetworkManager=bt;exports.NetworkManagerContext=ni;exports.NetworkMode=j;exports.NoOpGcManager=Vt;exports.NoOpNetworkManager=Ct;exports.QUERY_ID=lt;exports.Query=ri;exports.QueryClient=wi;exports.QueryClientContext=me;exports.RECORD_KEY=K;exports.ValidatorDef=_;exports.createDefinitionProxy=yt;exports.defaultNetworkManager=ae;exports.draft=$e;exports.extractDefinition=Bt;exports.fetchQuery=oi;exports.queryKeyForClass=si;exports.registerFormat=mt;exports.reifyValue=$;exports.resolveBaseUrl=_i;exports.t=ee;
2
- //# sourceMappingURL=QueryClient-DGCBmyPp.js.map
1
+ "use strict";const E=require("signalium"),S=require("signalium/utils"),qt=require("./shared-Ct5zKrt4.js"),At=require("./stores/sync.js");var j=(e=>(e.Always="always",e.Online="online",e.OfflineFirst="offlineFirst",e))(j||{}),d=(e=>(e[e.UNDEFINED=1]="UNDEFINED",e[e.NULL=2]="NULL",e[e.NUMBER=4]="NUMBER",e[e.STRING=8]="STRING",e[e.BOOLEAN=16]="BOOLEAN",e[e.OBJECT=32]="OBJECT",e[e.ARRAY=64]="ARRAY",e[e.ID=128]="ID",e[e.RECORD=256]="RECORD",e[e.UNION=512]="UNION",e[e.ENTITY=1024]="ENTITY",e[e.HAS_FORMAT=4096]="HAS_FORMAT",e[e.IS_EAGER_FORMAT=8192]="IS_EAGER_FORMAT",e[e.PARSE_RESULT=16384]="PARSE_RESULT",e[e.LIVE=32768]="LIVE",e))(d||{});const V=Symbol("array"),K=Symbol("record"),lt=Symbol("QUERY_ID");var J=(e=>(e[e.Array=0]="Array",e[e.Value=1]="Value",e))(J||{});class L{type;entityDefs;constraintFieldRefs;sort;valueType;onCreate;onUpdate;onDelete;constructor(t,i,n,r,s,o,a,c){this.type=t,this.entityDefs=i,this.constraintFieldRefs=n,this.sort=r,this.valueType=s,this.onCreate=o,this.onUpdate=a,this.onDelete=c}static array(t,i,n){return new L(0,t,i,n,void 0,void 0,void 0,void 0)}static value(t,i,n,r,s,o){return new L(1,t,i,void 0,n,r,s,o)}}const O=new WeakMap;function T(e){return O.get(e)}var X=(e=>(e[e.Query=0]="Query",e[e.Entity=1]="Entity",e))(X||{});class we{constructor(t,i,n){this._onEvict=i,this._intervalId=setInterval(this._tick,t*6e4*n)}_currentFlush=new Map;_nextFlush=new Map;_intervalId;schedule(t,i){this._nextFlush.set(t,i)}cancel(t){this._currentFlush.delete(t),this._nextFlush.delete(t)}_tick=()=>{const{_currentFlush:t,_nextFlush:i,_onEvict:n}=this;for(const[r,s]of t)n(r,s);this._currentFlush=i,this._nextFlush=new Map};destroy(){clearInterval(this._intervalId)}}class Ut{_buckets=new Map;_nextTickEntries=new Map;_nextTickScheduled=!1;_onEvict;_multiplier;constructor(t,i=1){this._onEvict=t,this._multiplier=i}schedule(t,i,n){if(i===1/0)return;if(i===0){const{_nextTickEntries:o}=this;o.set(t,n),this._nextTickScheduled||(this._nextTickScheduled=!0,setTimeout(this._flushNextTick,0));return}const{_buckets:r}=this;let s=r.get(i);s||(s=new we(i,this._onEvict,this._multiplier),r.set(i,s)),s.schedule(t,n)}cancel(t,i){if(i!==1/0){if(i===0){this._nextTickEntries.delete(t);return}this._buckets.get(i)?.cancel(t)}}_flushNextTick=()=>{const{_nextTickEntries:t,_onEvict:i}=this;this._nextTickScheduled=!1;for(const[n,r]of t)i(n,r);t.clear()};destroy(){const{_buckets:t,_nextTickEntries:i}=this;for(const n of t.values())n.destroy();t.clear(),i.clear()}}class Vt{schedule(t,i,n){}cancel(t,i){}destroy(){}}const z=Symbol("fieldRef"),k=Symbol("fieldRefPath"),ht=Symbol("DEFINITION_TARGET"),H=Symbol("CANCEL_PROXY"),Ee=/\[([^\]]+)\]/g;function Kt(e){const t={[z]:!0,[k]:e};return new Proxy(t,be)}const be={get(e,t){if(t===z)return!0;if(t===k)return e[k];if(t===Symbol.toPrimitive||t==="toString"||t==="valueOf"){const n=e[k];return()=>`[${n.join(".")}]`}if(typeof t=="symbol")return;const i=e[k];return Kt([...i,t])},has(e,t){return t===z||t===k}};function $t(e){return typeof e=="object"&&e!==null&&e[z]===!0}function Qt(e){return e[k]}function yt(e){return new Proxy(e,{set(t,i,n){return t[i]=n,!0},get(t,i){return i===ht?t:i===H?()=>{}:typeof i=="symbol"?t[i]:Kt([i])}})}function Bt(e){const t=e[ht];e[H]();const i={};for(const s of Object.getOwnPropertyNames(t))i[s]=t[s];const n={};let r=Object.getPrototypeOf(t);for(;r&&r!==Object.prototype;){for(const s of Object.getOwnPropertyNames(r)){if(s==="constructor")continue;const o=Object.getOwnPropertyDescriptor(r,s);typeof o.value=="function"&&!(s in n)&&(n[s]=o.value)}r=Object.getPrototypeOf(r)}return{fields:i,methods:n}}function pt(e,t){let i=t;for(const n of e){if(i==null)return;i=i[n]}return i}function Ce(e,t){return e.replace(Ee,(i,n)=>{const r=n.split("."),s=pt(r,t);return s!=null?encodeURIComponent(String(s)):""})}function $(e,t){if($t(e))return pt(Qt(e),t);if(typeof e=="string")return Ce(e,t);if(Array.isArray(e))return e.map(i=>$(i,t));if(typeof e=="object"&&e!==null&&Object.getPrototypeOf(e)===Object.prototype){const i={};for(const n of Object.keys(e))i[n]=$(e[n],t);return i}return e}function st(e,t,i){const n=e.fields,r=e.methods,s={params:t},o={};for(const[a,c]of Object.entries(n))o[a]=$(c,s);o.params=t,o.context=i,o.responseNotifier=E.notifier();for(const[a,c]of Object.entries(r))o[a]=c.bind(o);return o}class Z{static cache;constructor(){return yt(this)}}const Yt=Object.entries,ot=Object.keys;function Dt(e){return typeof e=="number"?e|d.UNDEFINED:e instanceof _?(e.mask&d.UNDEFINED)!==0?e:_.cloneWith(e,d.UNDEFINED):e}function xe(e){return e instanceof _&&(e.mask&d.OBJECT)!==0&&(e.mask&(d.ENTITY|d.ARRAY|d.UNION|d.RECORD|d.LIVE))===0}function Gt(e,t,i){const n=new Set;for(const s of e)if(s!==void 0)for(const o of Object.keys(s))n.add(o);const r={};for(const s of n){let o=0,a;const c=[];let f=!0;for(const l of e){const u=l?.[s];u!==void 0?(o++,a===void 0&&(a=u),xe(u)?c.push(u.shape):(f=!1,c.push(void 0))):(f=!1,c.push(void 0))}if(f&&o>0){const l=Gt(c,t),u=new _(d.OBJECT,l);r[s]=o<t?Dt(u):u}else r[s]=o<t?Dt(a):a}return r}class _{mask;shape;typenameField=void 0;typenameValue=void 0;idField=void 0;values=void 0;_methods=void 0;_entityConfig=void 0;_entityClass=void 0;_entityCache=void 0;_liveConfig=void 0;constructor(t,i,n,r,s,o){this.mask=t,this.shape=i,this.values=n,this.typenameField=r,this.typenameValue=s,this.idField=o}static merge(t){if(t.length===1)return t[0];const i=t.length,n=t.map(c=>c.shape);t[0].typenameValue;const r=Gt(n,i);let s,o,a;for(const c of t){if(s===void 0&&c.idField!==void 0)s=c.idField;else if(s!==void 0&&c.idField!==void 0&&c.idField!==s)throw new Error(`[fetchium] Entity typename '${c.typenameValue}' has conflicting id fields: '${String(s)}' vs '${String(c.idField)}'`);o===void 0&&(o=c.typenameField),a===void 0&&(a=c.typenameValue)}return new _(d.ENTITY|d.OBJECT,r,void 0,o,a,s)}static cloneWith(t,i){const n=new _(i|t.mask,t.shape,t.values,t.typenameField,t.typenameValue,t.idField);return n._methods=t._methods,n._entityConfig=t._entityConfig,n._entityClass=t._entityClass,n._entityCache=t._entityCache,n._liveConfig=t._liveConfig,n}}class tt extends Set{lowercaseMap;constructor(t){super(t),this.lowercaseMap=new Map;for(const i of t)if(typeof i=="string"){const n=i.toLowerCase(),r=this.lowercaseMap.get(n);if(r!==void 0)throw new Error(`Case-insensitive enum cannot have multiple values with the same lowercase form: '${r}' and '${i}' both become '${n}'`);this.lowercaseMap.set(n,i)}}has(t){return this.get(t)!==void 0}get(t){if(typeof t=="string")return this.lowercaseMap.get(t.toLowerCase());if(super.has(t))return t}}const Oe=1128875347;S.registerCustomHash(tt,e=>{let t=Oe;for(const i of e)t+=S.hashValue(i);return t>>>0});function gt(e,t){return new _(e,t)}function Re(e){return gt(d.ARRAY,e)}function Se(e){return gt(d.RECORD|d.OBJECT,e)}function Ae(e){return gt(d.PARSE_RESULT,e)}function Wt(e,t){let i=e,n,r,s;for(const[o,a]of Yt(t))switch(typeof a){case"number":if((a&d.ID)!==0){if(n!==void 0)throw new Error(`Duplicate id field: ${o}`);n=o}break;case"string":if(r!==void 0&&r!==o)throw new Error(`Duplicate typename field: ${o}`);r=o,s=a;break;case"object":if(a instanceof tt||a instanceof Set)break;a.mask&d.LIVE&&(i|=d.LIVE);break}return new _(i,t,void 0,r,s,n)}function De(e){return Wt(d.OBJECT,e)}function Nt(e,t,i){const n=e.mask;if((n&d.UNION)!==0){const r=e;if(r.typenameField!==void 0){if(i!==void 0&&i!==r.typenameField)throw new Error(`Union typename field conflict: Cannot merge unions with different typename fields ('${i}' vs '${r.typenameField}')`);i=r.typenameField}const s=r.shape;if(s!==void 0)for(const o of[...ot(s),V,K]){const a=s[o];if(t[o]!==void 0&&t[o]!==a)throw new Error(`Union merge conflict: Duplicate typename value '${String(o)}' found when merging nested unions (${String(t[o])} vs ${String(a)})`);t[o]=a}}else if((n&d.ARRAY)!==0){if(t[V]!==void 0)throw new Error("Array shape already defined");t[V]=e.shape}else if((n&d.RECORD)!==0){if(t[K]!==void 0)throw new Error("Record shape already defined");t[K]=e.shape}else{const r=e.typenameField,s=e.typenameValue;if(s===void 0)throw new Error("Object definitions must have a typename to be in a union with other objects, records, or arrays");if(i!==void 0&&r!==i)throw new Error("Object definitions must have the same typename field to be in the same union");i=r,t[s]=e}return i}function vt(...e){const t=e;let i=0,n=0,r,s,o,a,c=0;for(const l of t){if(typeof l=="number"){i|=l;continue}if(l instanceof Set){if(s===void 0)s=new Set(l);else for(const u of l)s.add(u);continue}if(n++,c|=l.mask,n===1){r=l;continue}n===2&&(o=Object.create(null),a=Nt(r,o,a)),a=Nt(l,o,a)}if(n===0)return s===void 0?i:i===0?s:new _(i|d.UNION,void 0,s);if(n===1)return _.cloneWith(r,i);const f=i|c|d.UNION;return new _(f,o,s,a)}function _t(e,t,i){const n=e;if(typeof n=="number")return n|t;if(n instanceof Set)return vt(e,t);let r=i.get(n);return r===void 0&&(r=_.cloneWith(n,t),i.set(n,r)),r}const Ne=new WeakMap,Ie=new WeakMap,Me=new WeakMap;function ke(e){return _t(e,d.UNDEFINED|d.NULL,Me)}function Fe(e){return _t(e,d.UNDEFINED,Ne)}function Te(e){return _t(e,d.NULL,Ie)}function Pe(e){return e}function je(e){return new Set([e])}const zt=((...e)=>new Set(e));zt.caseInsensitive=(...e)=>new tt(e);const Ht=16;let Le=0;const at=[],Jt=[],Xt=new Map,et=new WeakSet;class Q{_raw;_formatted;_parsed;_formatId;constructor(t,i,n){this._raw=t,this._formatId=i,n?(this._formatted=at[i](t),this._parsed=!0):this._parsed=!1,et.add(this)}getValue(){return this._parsed||(this._formatted=at[this._formatId](this._raw),this._parsed=!0),this._formatted}toJSON(){return this._parsed?Jt[this._formatId](this._formatted):this._raw}}function qe(e){const t=Xt.get(e);if(t===void 0)throw new Error(`Format ${e} not registered`);return t}function mt(e,t,i,n,r){const s=Le++;at[s]=i,Jt[s]=n;const o=r?.eager??!0,c=s<<Ht|t|d.HAS_FORMAT|(o?d.IS_EAGER_FORMAT:0);Xt.set(e,c)}mt("date",d.STRING,e=>{const t=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)throw new Error(`Invalid date string: ${e}. Expected YYYY-MM-DD format.`);const[,i,n,r]=t,s=new Date(Date.UTC(parseInt(i,10),parseInt(n,10)-1,parseInt(r,10)));if(isNaN(s.getTime()))throw new Error(`Invalid date string: ${e}`);return s},e=>{const t=e.getUTCFullYear(),i=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0");return`${t}-${i}-${n}`});mt("date-time",d.STRING,e=>{const t=new Date(e);if(isNaN(t.getTime()))throw new Error(`Invalid date-time string: ${e}`);return t},e=>e.toISOString());const It=new WeakMap;function q(e){let t=It.get(e);if(t===void 0){const i=new e,n=i[ht]??i;i[H]&&i[H]();const r={};for(const[f,l]of Yt(n))r[f]=l;const s=Object.getPrototypeOf(e.prototype);if(s!=null){const f=s.constructor;if(f!==Z&&typeof f=="function"){const u=q(f).shape;for(const y of ot(u))if(y in r&&r[y]!==u[y])throw new Error(`Cannot extend: field '${y}' already exists in type definition`)}}const o={},a=e.prototype;for(const f of Object.getOwnPropertyNames(a))f!=="constructor"&&typeof a[f]=="function"&&(o[f]=a[f]);t=Wt(d.ENTITY|d.OBJECT,r),t._entityClass=e,ot(o).length>0&&(t._methods=o),typeof o.__subscribe=="function"&&(t._entityConfig={hasSubscribe:!0});const c=e;c.cache&&(t._entityCache=c.cache),It.set(e,t)}return t}function Ue(e){return q(e)}function Zt(e,t){if(t==null)return;const i=new Map;if(Array.isArray(t))for(const n of t){const[r,s]=n,a=q(r).typenameValue;if(a===void 0)continue;const c=[];for(const[f,l]of Object.entries(s))c.push([f,l]);c.length>0&&i.set(a,c)}else{const r=Object.entries(t);if(r.length===0)return;const s=r.map(([o,a])=>[o,a]);for(const o of e){const a=o.typenameValue;a!==void 0&&i.set(a,s)}}return i.size>0?i:void 0}function te(e){return Array.isArray(e)?e.map(t=>q(t)):[q(e)]}function Ve(e,t){const i=te(e),n=i.length===1?i[0]:vt(...i.map(o=>o)),r=d.ARRAY|d.LIVE,s=new _(r,n);return s._liveConfig=L.array(i,Zt(i,t?.constraints),t?.sort),s}function Ke(e,t,i){const n=te(t),r=e,s=d.LIVE,o=new _(s,void 0);return o._liveConfig=L.value(n,Zt(n,i?.constraints),r,i.onCreate,i.onUpdate,i.onDelete),o}const ee={format:qe,typename:Pe,const:je,enum:zt,id:d.ID|d.STRING|d.NUMBER,string:d.STRING,number:d.NUMBER,boolean:d.BOOLEAN,null:d.NULL,undefined:d.UNDEFINED,array:Re,object:De,record:Se,union:vt,nullish:ke,optional:Fe,nullable:Te,result:Ae,entity:Ue,liveArray:Ve,liveValue:Ke};function U(e,t,i){return new TypeError(`Validation error at ${e}`)}const ie=Array.isArray;function Mt(e){if(e===null)return d.NULL;switch(typeof e){case"number":return d.NUMBER;case"string":return d.STRING;case"boolean":return d.BOOLEAN;case"undefined":return d.UNDEFINED;case"object":return ie(e)?d.ARRAY:d.OBJECT;default:throw new Error(`Invalid type: ${typeof e}`)}}function $e(e){return P(e)}function P(e){if(e===null||typeof e!="object")return e;if(ie(e))return e.map(i=>P(i));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){const i=new Map;for(const[n,r]of e)i.set(P(n),P(r));return i}if(e instanceof Set){const i=new Set;for(const n of e)i.add(P(n));return i}const t={};for(const i of Object.keys(e))t[i]=P(e[i]);return t}const wt=Object.entries,Qe=()=>{};class ct{queryClient=void 0;preloadedEntities=void 0;warn=Qe;isPartialEvent=!1;seen=void 0;seenByKey=void 0;reset(t,i,n,r=!1){this.queryClient=t,this.preloadedEntities=i,this.warn=n,this.isPartialEvent=r,t!==void 0&&(this.seen===void 0?(this.seen=new Map,this.seenByKey=new Map):(this.seen.clear(),this.seenByKey.clear()))}}function ne(e,t,i){return F(e,t,i,"")}function Be(e,t,i){return Et(e,t,i)}function kt(e,t,i,n){const r=e>>Ht;if((e&d.IS_EAGER_FORMAT)!==0)try{return new Q(t,r,!0)}catch(o){if((e&d.UNDEFINED)!==0){i.warn("Invalid formatted value for optional type, defaulting to undefined",{value:t,path:n,error:o instanceof Error?o.message:String(o)});return}throw o}return new Q(t,r,!1)}function F(e,t,i,n){const r=t;if(r instanceof tt){const c=r.get(e);if(c===void 0)throw U(n);return c}if(r instanceof Set){if(!r.has(e))throw U(n);return e}if(typeof r=="string"){if(e==null)return r;if(e!==r)throw U(n);return e}if(typeof r=="number"){const c=Mt(e);if((r&c)===0){if((r&d.UNDEFINED)!==0){i.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:n});return}throw U(n)}return(r&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?kt(r,e,i,n):e}const s=r.mask,o=r._liveConfig;if(o!==void 0&&o.type===J.Value)return o.valueType!==void 0?F(e,o.valueType,i,n):e;if((s&d.PARSE_RESULT)!==0)try{return{success:!0,value:F(e,r.shape,i,n)}}catch(c){return{success:!1,error:c instanceof Error?c:new Error(String(c))}}const a=Mt(e);if((s&a)===0&&!r.values?.has(e)){if((s&d.UNDEFINED)!==0){i.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:n});return}throw U(n)}return a<d.OBJECT?(s&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?kt(s,e,i,n):e:(s&d.UNION)!==0?Ye(a,e,r,i,n):a===d.ARRAY?re(e,r.shape,i,n):(s&d.RECORD)!==0?se(e,r.shape,i,n):(s&d.ENTITY)!==0&&i.queryClient!==void 0?Et(e,r,i):oe(e,r,i,n)}function Ye(e,t,i,n,r){if(e===d.ARRAY){const s=i.shape[V];return s===void 0||typeof s=="number"?t:re(t,s,n,r)}else{const s=i.typenameField,o=s?t[s]:void 0;if(o===void 0||typeof o!="string"){const c=i.shape[K];if(c===void 0)throw new Error(`Typename field '${s}' is required for union discrimination but was not found in the data`);return se(t,c,n,r)}const a=i.shape[o];if(a===void 0||typeof a=="number")throw new Error(`Unknown typename '${o}' in union`);return a.mask&d.ENTITY&&n.queryClient!==void 0?Et(t,a,n):oe(t,a,n,r)}}function re(e,t,i,n){const r=[];for(let s=0;s<e.length;s++)try{r.push(F(e[s],t,i,`${n}[${s}]`))}catch(o){i.warn("Failed to parse array item, filtering out",{index:s,value:e[s],error:o instanceof Error?o.message:String(o)})}return r}function se(e,t,i,n){for(const[r,s]of wt(e))e[r]=F(s,t,i,`${n}["${r}"]`);return e}function oe(e,t,i,n){if(O.has(e))return e;const r=t.shape;for(const[s,o]of wt(r))e[s]=F(e[s],o,i,`${n}.${s}`);return e}function Et(e,t,i){const n=i.queryClient,r=i.preloadedEntities;let s,o;if(r!==void 0)s=e.__entityRef,o=s;else{const p=e[t.idField];if(p==null||typeof p!="string"&&typeof p!="number")throw new Error(`Entity id must be a string or number: ${t.typenameValue} (got ${typeof p})`);o=p,s=S.hashValue([t.typenameValue,o])}const a=i.seenByKey.get(s);if(a!==void 0)return a.data;if(r!==void 0){const g=n.entityMap.getEntity(s)?.data??r.get(s);if(g===void 0)throw new Error(`Cached entity ${s} not found in preloaded map`);e=g}const c={};typeof t.idField=="symbol"&&(c[t.idField]=o);const f=n.entityMap.getEntity(s),l=i.isPartialEvent&&f!==void 0,u={key:s,shape:t,data:c,rawKeys:l?new Set(Object.keys(e)):void 0};i.seen.set(c,u),i.seenByKey.set(s,u);const y=`[[${t.typenameValue}:${o}]]`,v=t.shape;for(const[p,g]of wt(v))l&&!(p in e)||(c[p]=F(e[p],g,i,`${y}.${p}`));return c}function Ge(e,t){return We(e,t.shape,t.typenameField)}function We(e,t,i){if(t===void 0)return!0;for(const n of Object.keys(t)){if(n===i)continue;const r=t[n];if(r instanceof _){if((r.mask&d.UNDEFINED)!==0)continue;if(!(n in e)||e[n]===void 0)return!1}else if(typeof r=="number"){if((r&d.UNDEFINED)!==0)continue;if(!(n in e)||e[n]===void 0)return!1}else if(!(n in e)||e[n]===void 0)return!1}return!0}const ze=Object.prototype,W=new WeakMap;function N(e){if(typeof e!="object"||e===null)return e;if(et.has(e))return N(e.getValue());if(O.has(e))return e;if(Array.isArray(e)){let t=W.get(e);return t===void 0&&(t=new Proxy(e,He),W.set(e,t)),t}if(Object.getPrototypeOf(e)===ze){let t=W.get(e);return t===void 0&&(t=new Proxy(e,Je),W.set(e,t)),t}return e}const He={get(e,t,i){if(typeof t=="string"){const n=Number(t);if(Number.isInteger(n)&&n>=0&&n<e.length)return N(e[n])}return Reflect.get(e,t,i)},set(){return!1},deleteProperty(){return!1}},Je={get(e,t,i){return typeof t=="string"?N(e[t]):Reflect.get(e,t,i)},set(){return!1},deleteProperty(){return!1},has(e,t){return t in e},ownKeys(e){return Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Object.getOwnPropertyDescriptor(e,t)}},Xe=(e,t,i)=>{const n=e,r=Object.keys(n),s=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:void 0;let o=!s||Object.keys(s).length!==r.length;const a={};for(let c=0;c<r.length;c++){const f=r[c],l=n[f];let u;typeof l=="function"?u=l:u=i(l,s?.[f]),a[f]=u,!o&&u!==s?.[f]&&(o=!0)}return o?a:s};S.registerCustomSnapshot(Z,Xe);class Ze{_notifier;_queryClient;_proxies=new Map;key;typename;id;idField;data;refCount=0;entityRefs;liveCollections=[];satisfiedDefs=new WeakSet;parseId=-1;_entityCache;_extraMethods;_extraGetters;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._queryClient=o,this.key=t,this.typename=i,this.id=n,this.idField=r,this.data=s,this.entityRefs=void 0}retain(){this.refCount++;const t=this._entityCache?.gcTime;t!==void 0&&this._queryClient.gcManager.cancel(this.key,t)}release(){if(--this.refCount>0||this.refCount<0)return;const t=this._entityCache?.gcTime;t!==void 0?this._queryClient.gcManager.schedule(this.key,t,X.Entity):this.evict()}evict(){const t=this.liveCollections.slice();this.liveCollections.length=0;for(const n of t)n.destroy();this._queryClient.entityMap.remove(this.key);const i=this.entityRefs;if(this.entityRefs=void 0,i)for(const n of i.keys())n.release()}setChildRefs(t,i){const n=this.entityRefs;if(t!==void 0&&t.size>0)for(const r of t.keys())(n===void 0||!n.has(r))&&r.retain();if(n!==void 0&&n.size>0)for(const r of n.keys())(t===void 0||!t.has(r))&&r.release();this.entityRefs=t,i&&this.save()}addChildRef(t){this.entityRefs===void 0&&(this.entityRefs=new Map);const i=this.entityRefs.get(t)??0;this.entityRefs.set(t,i+1),i===0&&t.retain(),this.save()}removeChildRef(t){if(this.entityRefs===void 0)return;const i=this.entityRefs.get(t);i!==void 0&&(i<=1?(this.entityRefs.delete(t),t.release()):this.entityRefs.set(t,i-1),this.save())}getProxy(t){const i=t;let n=this._proxies.get(i);return n===void 0&&(n=ei(this,this.key,t,this._notifier,this._queryClient),this._proxies.set(i,n)),n}get proxy(){return this._proxies.values().next().value}satisfiesDef(t){return this.satisfiedDefs.has(t)?!0:Ge(this.data,t)?(this.satisfiedDefs.add(t),!0):!1}save(){this._queryClient.entityMap.save(this)}notify(){this._notifier.notify()}consume(){this._notifier.consume()}}function ti(e,t,i){const n=[];for(const r of e){if(typeof r!="object"||r===null)continue;const s=O.get(r);if(s===void 0)continue;const o=i.entityMap.getEntity(s);o!==void 0&&o.satisfiesDef(t)&&n.push(r)}return n}function ei(e,t,i,n,r){const s=i.shape??{},o=i,a=o._methods,c=o._entityClass,f=o._entityConfig,l=c?c.prototype:Z.prototype;i.typenameField;const u=new Map,y=new Map,v=()=>({__entityRef:t});let p;f?.hasSubscribe&&a&&"__subscribe"in a&&(p=E.relay(b=>{const h=w=>{w.__eventSource=t,r.applyMutationEvent(w)},C=a.__subscribe.call(g,h);return b.value=g,C}));let g;const m=Object.keys(s);if(m.includes("__typename")||m.push("__typename"),a)for(const b of Object.keys(a))m.includes(b)||m.push(b);let I,R=m;function G(){const b=e._extraMethods;if(b!==I){if(I=b,R=m.slice(),b!==void 0)for(const C of Object.keys(b))R.includes(C)||R.push(C);const h=e._extraGetters;if(h!==void 0)for(const C of Object.keys(h))R.includes(C)||R.push(C)}return R}const A={getPrototypeOf(){return l},get(b,h,C){if(typeof h=="symbol")return Reflect.get(l,h,C);if(h==="toJSON")return v;if(h==="__context")return r.getContext();if(h==="__typename")return e.typename;if(p?.value,n.consume(),typeof h=="string"){const M=e._extraGetters;if(M!==void 0&&h in M)return M[h]();const D=e._extraMethods;if(D!==void 0&&h in D){let x=u.get(h);return x||(x=D[h].bind(g),u.set(h,x)),x}if(a&&h in a){let x=u.get(h);return x||(x=E.reactiveMethod(g,a[h].bind(g)),u.set(h,x)),x}}const w=e.data[h];if(typeof w=="object"&&w!==null&&et.has(w))return N(w.getValue());if(Array.isArray(w)&&typeof h=="string"){const M=s[h];if(M instanceof _&&(M.mask&d.ARRAY)!==0){const D=M.shape;if(D instanceof _&&(D.mask&d.ENTITY)!==0){const x=D.typenameValue;if(x!==void 0){const Rt=r.getEntityDefsForTypename(x);if(Rt!==void 0&&Rt.length>1){const it=y.get(h);if(it!==void 0&&it.source===w)return N(it.filtered);const St=ti(w,D,r);return y.set(h,{source:w,filtered:St}),N(St)}}}}return N(w)}return N(w)},set(){return!1},has(b,h){if(h==="__typename")return!0;if(typeof h=="string"){const C=e._extraGetters;if(C&&h in C)return!0;const w=e._extraMethods;if(w&&h in w||a&&h in a)return!0}return h in s},ownKeys(){return G()},getOwnPropertyDescriptor(b,h){if(h==="__typename")return{enumerable:!0,configurable:!0,value:e.typename,writable:!1};if(h in s)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};if(typeof h=="string"){const C=e._extraGetters;if(C&&h in C)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};const w=e._extraMethods;if(w&&h in w)return{enumerable:!0,configurable:!0,value:A.get(b,h,g),writable:!1};if(a&&h in a)return{enumerable:!1,configurable:!0,value:A.get(b,h,g),writable:!1}}}};return g=new Proxy({},A),O.set(g,t),E.setScopeOwner(g,r),g}class ii{instances=new Map;persistEntity;constructor(t){this.persistEntity=t}hasEntity(t){return this.instances.has(t)}getEntity(t){return this.instances.get(t)}getOrCreateEntity(t,i,n,r){let s=this.instances.get(t);if(s===void 0){const o=n.idField;if(o===void 0)throw new Error(`Entity id field is required ${n.typenameValue}`);const a=i[o];if(typeof a!="string"&&typeof a!="number")throw new Error(`Entity id must be string or number: ${n.typenameValue}`);const c=n;s=new Ze(t,n.typenameValue,a,o,i,r),s._entityCache=c._entityCache,this.instances.set(t,s)}return s.parseId=r.currentParseId,s}remove(t){this.instances.delete(t)}save(t){let i;if(t.entityRefs){i=new Set;for(const n of t.entityRefs.keys())i.add(n.key)}this.persistEntity(t.key,t.data,i)}}class bt{onlineSignal;manualOverride=void 0;eventListenersAttached=!1;constructor(t){const i=t??this.detectOnlineStatus();this.onlineSignal=E.signal(i),this.canAttachListeners()&&this.attachEventListeners()}get isOnline(){return this.manualOverride!==void 0?this.manualOverride:this.onlineSignal.value}setNetworkStatus(t){this.manualOverride=t,this.onlineSignal.value=t}clearManualOverride(){this.manualOverride=void 0,this.onlineSignal.value=this.detectOnlineStatus()}getOnlineSignal(){return this.onlineSignal}detectOnlineStatus(){return typeof navigator<"u"&&"onLine"in navigator?navigator.onLine:!0}canAttachListeners(){return typeof window<"u"&&typeof window.addEventListener=="function"}destroy(){this.eventListenersAttached&&this.handleOnline&&this.handleOffline&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline),this.eventListenersAttached=!1)}handleOnline=void 0;handleOffline=void 0;attachEventListeners(){this.eventListenersAttached||(this.handleOnline=()=>{this.manualOverride===void 0&&(this.onlineSignal.value=!0)},this.handleOffline=()=>{this.manualOverride===void 0&&(this.onlineSignal.value=!1)},window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline),this.eventListenersAttached=!0)}}class Ct{static onlineSignal=E.signal(!0);get isOnline(){return!0}setNetworkStatus(t){}clearManualOverride(){}getOnlineSignal(){return Ct.onlineSignal}destroy(){}}const ae=new bt,ni=E.context(ae);function xt(e,t=typeof window>"u"){let i;e===!1?i=0:e===void 0||e===!0?i=t?0:3:typeof e=="number"?i=e:i=e.retries;const n=typeof e=="object"&&e.retryDelay?e.retryDelay:r=>1e3*Math.pow(2,r);return{retries:i,retryDelay:n}}class ri{static cache;static adapter;params;config;constructor(){return yt(this)}}const Ft=new WeakMap;class Y{constructor(t,i){this.captured=i,this.statics=t}statics;createExecutionContext(t,i){return st(this.captured,t,i)}resolveOptions(t){const{methods:i}=this.captured,n=i.getConfig?i.getConfig.call(t):t.config,r=xt(n?.retry);return{config:n,retryConfig:r}}static for(t){let i=Ft.get(t);if(i!==void 0)return i;const n=new t,r=Bt(n),s=String(r.methods.getIdentityKey.call(r.fields)),o=r.fields.result,a=o instanceof _?o:ee.object(o),c=(a.mask&d.ENTITY)!==0,f=t.cache,l=r.fields.fetchNext,u=t.adapter;if(!u)throw new Error(`Query class "${t.name}" must define a static \`adapter\` property. Extend RESTQuery (from fetchium/rest) or set \`static adapter = MyAdapter\` on your query class.`);const y=typeof u.prototype.sendNext=="function",v=c?a:new _(d.ENTITY|d.OBJECT,a.shape,void 0,void 0,s,lt);return i=new Y({id:s,shape:v,cache:f,rawFetchNext:l,hasSendNext:y,isEntityResult:c,adapterClass:u},r),Ft.set(t,i),i}}const si=(e,t)=>{const i=Y.for(e);return Ot(i,t)};function oi(e,...t){const i=Y.for(e),n=E.getContext(me);if(n===void 0)throw new Error("QueryClient not found");const r=t[0];return n.getQuery(i,r)}function ft(e){if(e.reason!==void 0)return e.reason;if(typeof DOMException<"u")return new DOMException("The operation was aborted","AbortError");const t=new Error("The operation was aborted");return t.name="AbortError",t}function ce(e,t){return new Promise((i,n)=>{if(t?.aborted){n(ft(t));return}const r=setTimeout(i,e);t?.addEventListener("abort",()=>{clearTimeout(r),n(ft(t))},{once:!0})})}async function ut(e,t,i){const n=Math.max(0,t.retries);let r;for(let s=0;s<=n;s++){if(i?.aborted)throw ft(i);try{return await e()}catch(o){if(r=o,s>=n)throw o;await ce(t.retryDelay(s),i)}}throw r}class ai{def;queryKey;storageKey=-1;relay;queryClient;initialized=!1;updatedAt=void 0;params=void 0;unsubscribe=void 0;lastSubscribeFn=void 0;_relayState=void 0;_isActive=!1;wasPaused=!1;currentParams=void 0;debounceTimer=void 0;_resolvedOptions=E.reactiveSignal(()=>this.def.resolveOptions(this._executionCtx));get config(){if(this._executionCtx!==void 0)return this._resolvedOptions.value.config}get retryConfig(){return this._executionCtx===void 0?xt(void 0):this._resolvedOptions.value.retryConfig}_abortController=void 0;_executionCtx=void 0;_executionCtxKey=-1;rootEntity;_extraMethods={};_queryId=0;get key(){return this.queryKey}get relayState(){return this._relayState}constructor(t,i,n,r){this.def=t,this.queryClient=i,this.queryKey=n,this.params=r,this._extraMethods={__refetch:this.refetch},t.statics.hasSendNext&&(this._extraMethods.__fetchNext=this.fetchNext);const s=Lt(r);this._queryId=s!==void 0?S.hashValue(s):0,this.relay=E.relay(o=>{this._relayState=o;const a=()=>{this._isActive=!1,clearTimeout(this.debounceTimer),this.debounceTimer=void 0,this._abortController?.abort(),this._abortController=void 0,this._fetchNextAbort?.abort(),this._fetchNextAbort=void 0,this._fetchNextPromise=void 0,this.unsubscribe?.(),this.unsubscribe=void 0,this.lastSubscribeFn=void 0;const f=this.config?.gcTime??qt.DEFAULT_GC_TIME;this.queryClient.gcManager.schedule(this.queryKey,f,X.Query)},c=(f=!1)=>{const{wasPaused:l,isPaused:u,initialized:y}=this;if(this.wasPaused=u,u&&!l&&y){a();return}this._isActive=!0;const v=Lt(this.params),p=Ot(this.def,v),g=p!==this.storageKey;g&&(this.currentParams=v,this.storageKey=p),this.getOrCreateExecutionContext(),this.initialized?l||f?(this.queryClient.activateQuery(this),f&&this.updatedAt!==void 0&&this.reconcileSubscription(),this.relayState.isPending&&this._abortController===void 0?this.runQueryImmediately():(this.config?.refreshStaleOnReconnect??!0)&&this.isStale&&this.runDebounced()):g&&(this.lastSubscribeFn=void 0,this.reconcileSubscription(),this.runDebounced()):(this.queryClient.activateQuery(this),this.initialize())};return c(!0),{update:c,deactivate:a}},{desc:`Query(${t.statics.id})`})}applyData(t,i,n=!1,r){const s=this.def;return this.rootEntity=this.queryClient.parseAndApplyRootEntity(t,this._queryId,s.statics.shape,i,n,r),this.rootEntity._extraMethods===void 0&&(this.rootEntity._extraMethods=this._extraMethods,this.rootEntity._extraGetters={__hasNext:()=>this.hasNext,__isFetchingNext:()=>this._fetchNextPromise!==void 0}),this.rootEntity.getProxy(s.statics.shape)}saveQueryMetadata(){if(this.rootEntity===void 0||this.updatedAt===void 0)return;const t=new Map(this.rootEntity.entityRefs??[]);t.set(this.rootEntity,1),this.queryClient.saveQueryData(this.def,this.storageKey,{__entityRef:this.rootEntity.key},this.updatedAt,t)}async initialize(){const t=this.queryClient,i=this.relayState;this.initialized=!0;let n;try{n=await t.loadCachedQuery(this.def,this.storageKey),n!==void 0&&(this.updatedAt=n.updatedAt,i.value=this.applyData(n.value,!1,!1,n.preloadedEntities))}catch(r){t.store.deleteQuery(this.storageKey),t.getContext().log?.warn?.("Failed to initialize query, the query cache may be corrupted or invalid",r)}if(!this.isPaused)try{if(n!==void 0&&this.reconcileSubscription(),n===void 0||this.isStale){if(await ce(0),this.isPaused)return;this.runQueryImmediately()}}catch(r){i.setError(r)}}reconcileSubscription(){const t=this.config?.subscribe;if(t===this.lastSubscribeFn||(this.unsubscribe?.(),this.unsubscribe=void 0,this.lastSubscribeFn=t,!t))return;const i=this._executionCtx;this.unsubscribe=t.call(i,n=>{n.__eventSource=this.queryKey,this.queryClient.applyMutationEvent(n)})}getOrCreateExecutionContext(){return(this._executionCtx===void 0||this._executionCtxKey!==this.storageKey)&&(this._executionCtxKey=this.storageKey,this._executionCtx=this.def.createExecutionContext(this.currentParams??{},this.queryClient.getContext()),this._executionCtx.refetch=()=>this.refetch(),this._executionCtx.rawFetchNext=this.def.statics.rawFetchNext,this._resolvedOptions=E.reactiveSignal(()=>this.def.resolveOptions(this._executionCtx))),this._executionCtx}async runQuery(){const t=this.def;if(this.isPaused)throw new Error("Query is paused due to network status");const i=this.getOrCreateExecutionContext(),n=this.queryClient.getAdapter(t.statics.adapterClass),r=this._abortController?.signal??new AbortController().signal;return ut(async()=>{try{const s=await n.send(i,r);this.updatedAt=Date.now();const o=this.applyData(s,!0);return this.saveQueryMetadata(),o}finally{this.reconcileSubscription()}},this.retryConfig,r)}runQueryImmediately(){this._abortController?.abort(),this._abortController=new AbortController,this._fetchNextAbort?.abort(),this._fetchNextAbort=void 0,this._fetchNextPromise=void 0,this.relayState.setPromise(this.runQuery())}runDebounced(){if(this.relayState.isPending)return;const t=this.config?.debounce??0;clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=void 0,this.runQueryImmediately()},t)}refetch=()=>this.relayState.isPending?this.relay:(this.runQueryImmediately(),this.relay);markStale(){this.updatedAt=0,this._isActive&&!this.isPaused&&this.runDebounced()}get resolvedParams(){return this.currentParams}_fetchNextPromise=void 0;_fetchNextAbort=void 0;fetchNext=()=>{if(this.updatedAt===void 0)throw new Error("Cannot call __fetchNext before initial data has loaded");return this._fetchNextPromise!==void 0?this._fetchNextPromise:(queueMicrotask(()=>this.rootEntity?.notify()),this._fetchNextPromise=this.runFetchNext().then(t=>(this._fetchNextPromise=void 0,this.rootEntity?.notify(),t),t=>{throw this._fetchNextPromise=void 0,this.rootEntity?.notify(),t}),this._fetchNextPromise)};get hasNext(){if(this.rootEntity===void 0||!this._executionCtx)return!1;const t=this.queryClient.getAdapter(this.def.statics.adapterClass);return t.hasNext?(this._executionCtx.resultData=this.rootEntity.data,t.hasNext(this._executionCtx)):!1}async runFetchNext(){const t=this.def;this._fetchNextAbort=new AbortController;const i=this._fetchNextAbort.signal,n=this.getOrCreateExecutionContext();n.resultData=this.rootEntity.data;const r=this.queryClient.getAdapter(t.statics.adapterClass);return ut(async()=>{const s=await r.sendNext(n,i);this.updatedAt=Date.now();const o=this.applyData(s,!0,!0);return this.saveQueryMetadata(),o},this.retryConfig,i)}get isStale(){if(this.updatedAt===void 0)return!0;const t=this.config?.staleTime??0;return Date.now()-this.updatedAt>=t}get isPaused(){const t=this.config?.networkMode??j.Online;if(t===j.Always)return!1;const i=this.queryClient.networkManager.getOnlineSignal().value;switch(t){case j.Online:return!i;case j.OfflineFirst:return!i&&this.updatedAt===void 0;default:return!1}}}class ci{def;queryClient;_inFlight=!1;task;constructor(t,i){this.def=t,this.queryClient=i,this.task=this.createTask()}createTask(){return E.task(async t=>{if(this._inFlight)throw new Error("A mutation is already in progress. Await the previous call before starting a new one.");this._inFlight=!0;try{const i=await this.executeWithRetry(t),n=this.validateResponse(i);return this.processEffects(t,n),n}finally{this._inFlight=!1}},{desc:`Mutation(${this.def.id})`})}validateResponse(t){const i=this.def.responseShape;if(!(i instanceof _))return t;const n=this.queryClient.getContext().log?.warn??(()=>{}),r=new ct;return r.reset(void 0,void 0,n),ne(t,i,r)}processEffects(t,i){let n;if(this.def.hasGetEffects){const s=st(this.def.captured,t??{},this.queryClient.getContext());s.result=i,n=s.getEffects()}else if(this.def.effects!==void 0){const s={params:t,result:i};n=$(this.def.effects,s)}if(n===void 0)return;const r=this.queryClient;nt(n.creates,"create",r),nt(n.updates,"update",r),nt(n.deletes,"delete",r),n.invalidates&&r.invalidateQueries(n.invalidates)}executeWithRetry(t){const i=xt(this.def.config?.retry,!0),n=this.queryClient.getAdapter(this.def.adapterClass);if(!n.sendMutation)throw new Error(`Adapter "${this.def.adapterClass.name}" does not implement sendMutation(). Add a sendMutation() method to handle mutations.`);return ut(async()=>{const r=new AbortController,s=st(this.def.captured,t??{},this.queryClient.getContext());return await n.sendMutation(s,r.signal)},i)}}function fi(e){return typeof e=="string"?e:q(e).typenameValue}function nt(e,t,i){if(e)for(const[n,r]of e){const s=fi(n);s!==void 0&&i.applyMutationEvent({type:t,typename:s,data:r})}}const fe="__eventSource";function ue(e){return{field:e,segments:e.indexOf(".")!==-1?e.split("."):void 0}}function ui(e){return e.map(ue)}function di(e,t){if(t.segments===void 0)return e[t.field];let i=e;for(const n of t.segments){if(i==null)return;i=i[n]}return i}function de(e,t){const i=[];for(let n=0;n<t.length;n++){const r=t[n],s=di(e,r);if(s===void 0)return;i.push(r.field,s)}return S.hashValue(i)}function li(e,t){if(e===void 0)return;const i=new Map;for(const[n,r]of e){const s=r.slice().sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0),o=[];let a=!0;for(const[c,f]of s){let l;if($t(f)){const u=Qt(f);l=pt(u,t)}else l=f;if(l===void 0){a=!1;break}o.push(c,l)}a&&i.set(n,S.hashValue(o))}return i.size>0?i:void 0}function Tt(e,t){const i=e.get(t);if(i!==void 0)return i.map(([n])=>n).sort()}class hi{fields;fieldPaths;_bindings=new Map;constructor(t){this.fields=t,this.fieldPaths=t.map(ue)}register(t,i){let n=this._bindings.get(t);n===void 0&&(n=new Set,this._bindings.set(t,n)),n.add(i)}unregister(t,i){const n=this._bindings.get(t);n!==void 0&&(n.delete(i),n.size===0&&this._bindings.delete(t))}getMatching(t){return this._bindings.get(t)}get isEmpty(){return this._bindings.size===0}}function Pt(e){return S.hashValue(e)}class yi{_groups=new Map;getOrCreateGroup(t){const i=Pt(t);let n=this._groups.get(i);return n===void 0&&(n=new hi(t),this._groups.set(i,n)),n}register(t,i,n){this.getOrCreateGroup(i).register(t,n)}unregister(t,i,n){const r=Pt(i),s=this._groups.get(r);s!==void 0&&(s.unregister(t,n),s.isEmpty&&this._groups.delete(r))}registerBinding(t,i){const n=t._constraintHashes.get(i);if(n===void 0)return;const r=Tt(t._constraintFieldRefs,i);r!==void 0&&this.register(n,r,t)}unregisterBinding(t,i){const n=t._constraintHashes.get(i);if(n===void 0)return;const r=Tt(t._constraintFieldRefs,i);r!==void 0&&this.unregister(n,r,t)}routeEvent(t,i,n,r,s,o){for(const a of this._groups.values()){const c=de(i,a.fieldPaths);if(c===void 0)continue;const f=a.getMatching(c);if(f!==void 0)for(const l of f)l.onEvent(t,n,r,s,o)}}}function jt(e){const t=new Set;for(const i of e)if(typeof i=="object"&&i!==null){const n=T(i);n!==void 0&&t.add(n)}return t}class le{_queryClient;_parent;_constraintHashes;_entityDefsByTypename;_constraintFieldRefs;instance;constructor(t,i,n,r,s,o){this._queryClient=n,this._parent=r,this._constraintHashes=s,this._constraintFieldRefs=i,this.instance=o,this._entityDefsByTypename=new Map;for(const a of t)a.typenameValue!==void 0&&this._entityDefsByTypename.set(a.typenameValue,a);et.add(this)}getValue(){return this.instance.getValue()}toJSON(){return this.instance.getRawValue()}reset(t){this.instance.reset(t)}append(t){this.instance.append(t)}onEvent(t,i,n,r,s){const o=this._entityDefsByTypename.get(t);if(o===void 0)return;const a=this._queryClient.entityMap.getEntity(i);if(n==="delete"){const f=a!==void 0?a.getProxy(o):s;f!==void 0&&(this.instance.onEvent(i,f,s??a?.data??{},"delete"),r?.());return}if(a===void 0||!a.satisfiesDef(o))return;r?.();const c=a.getProxy(o);this.instance.onEvent(i,c,a.data,n)}destroy(){this._queryClient.unregisterLiveCollection(this);const t=this._parent.liveCollections,i=t.indexOf(this);i!==-1&&t.splice(i,1)}}class pi{_notifier;_items;_keys;_outputSignal;_queryClient;_parent;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._items=n,this._keys=jt(n),this._queryClient=t,this._parent=i;const a=r!==void 0&&s!==void 0,c=o!==void 0;(a||c)&&(this._outputSignal=E.reactiveSignal(()=>{this._notifier.consume();let f=this._items;if(a){const l=[];for(const u of f){if(typeof u!="object"||u===null){l.push(u);continue}const y=T(u);if(y===void 0){l.push(u);continue}const v=t.entityMap.getEntity(y);if(v===void 0){l.push(u);continue}v.consume(),de(v.data,r)===s&&l.push(u)}f=l}return c&&(f=(f===this._items?f.slice():f).sort(o)),f}))}onEvent(t,i,n,r){switch(r){case"create":this.add(t,i);break;case"update":!this.has(t)&&i!==void 0&&this.add(t,i);break;case"delete":this.remove(t);break}}getValue(){return this._outputSignal!==void 0?this._outputSignal.value:(this._notifier.consume(),this._items)}getRawValue(){return this._items}add(t,i){if(this._keys.has(t))return!1;this._keys.add(t),this._items.push(i);const n=this._queryClient.entityMap.getEntity(t);return n!==void 0&&(this._parent.addChildRef(n),n.save()),this._notifier.notify(),!0}remove(t){if(!this._keys.has(t))return!1;this._keys.delete(t);const i=this._findIndex(t);i!==-1&&this._items.splice(i,1);const n=this._queryClient.entityMap.getEntity(t);return n!==void 0&&this._parent.removeChildRef(n),this._notifier.notify(),!0}has(t){return this._keys.has(t)}reset(t){const i=this._items,n=Array.isArray(t)?t:[];this._items=n,this._keys=jt(n);for(const r of n)if(typeof r=="object"&&r!==null){const s=T(r);if(s!==void 0){const o=this._queryClient.entityMap.getEntity(s);o!==void 0&&this._parent.addChildRef(o)}}for(const r of i)if(typeof r=="object"&&r!==null){const s=T(r);if(s!==void 0){const o=this._queryClient.entityMap.getEntity(s);o!==void 0&&this._parent.removeChildRef(o)}}this._notifier.notify()}append(t){if(Array.isArray(t))for(const i of t){if(typeof i!="object"||i===null)continue;const n=T(i);n!==void 0&&this.add(n,i)}}_findIndex(t){for(let i=0;i<this._items.length;i++){const n=this._items[i];if(typeof n=="object"&&n!==null&&T(n)===t)return i}return-1}}class gi{_notifier;_value;_createdKeys;_deletedKeys;_queryClient;_parent;_onCreate;_onUpdate;_onDelete;constructor(t,i,n,r,s,o){this._notifier=E.notifier(),this._value=n,this._createdKeys=new Set,this._deletedKeys=new Set,this._queryClient=t,this._parent=i,this._onCreate=r,this._onUpdate=s,this._onDelete=o}onEvent(t,i,n,r){switch(r){case"create":if(this._createdKeys.has(t))return;this._createdKeys.add(t),this._value=this._onCreate(this._value,i);break;case"update":this._value=this._onUpdate(this._value,i??n);break;case"delete":if(this._deletedKeys.has(t))return;this._deletedKeys.add(t),this._value=this._onDelete(this._value,i??n);break}this._notifier.notify()}getValue(){return this._notifier.consume(),this._value}getRawValue(){return this._value}reset(t){this._value=t,this._createdKeys.clear(),this._deletedKeys.clear(),this._notifier.notify()}append(t){}}function he(e,t,i,n,r){let s=e.constraintFieldRefs;if(s===void 0){s=new Map;for(const f of e.entityDefs){const l=f.typenameValue;l!==void 0&&s.set(l,[[fe,i.key]])}}const o=li(s,n)??new Map;let a;if(e.type===J.Array){let f,l;if(e.constraintFieldRefs!==void 0&&o.size>0&&o.size===1)for(const[u]of e.constraintFieldRefs){const y=o.get(u);if(y!==void 0){l=y;const v=e.constraintFieldRefs.get(u);v!==void 0&&(f=ui(v.map(([p])=>p)));break}}a=new pi(r,i,Array.isArray(t)?t:[],f,l,e.sort)}else a=new gi(r,i,t,e.onCreate,e.onUpdate,e.onDelete);const c=new le(e.entityDefs,s,r,i,o,a);return i.liveCollections.push(c),r.registerLiveCollection(c),c}const ye=Object.entries,pe=Object.prototype;function rt(e,t,i,n=!1){const r=e.queryClient;r.currentParseId++;const s=e.seen,o=new Map;return{data:B(t,s,r,i,o,n),entityRefs:o}}function B(e,t,i,n,r,s){if(typeof e!="object"||e===null)return e;const o=t.get(e);if(o!==void 0)return vi(o,t,i,n,r,s);if(Array.isArray(e)){for(let a=0;a<e.length;a++){const c=e[a];typeof c=="object"&&c!==null&&!(c instanceof Q)&&!O.has(c)&&(e[a]=B(c,t,i,n,r,s))}return e}if(Object.getPrototypeOf(e)===pe&&!O.has(e)){const a=e;for(const c of Object.keys(a)){const f=a[c];typeof f=="object"&&f!==null&&!(f instanceof Q)&&!O.has(f)&&(a[c]=B(f,t,i,n,r,s))}}return e}function ge(e){return typeof e=="object"&&e!==null&&!(e instanceof Q)&&!O.has(e)}function vi(e,t,i,n,r,s){const{key:o,data:a,shape:c,rawKeys:f}=e,l=c.shape,u=i.prepareEntity(o,a,c),y=u.data,v=y!==a,p=v&&f!==void 0&&u.entityRefs!==void 0?new Map(u.entityRefs):new Map;if(v?(ve(l,a,y,f,u,y,t,i,n,p,s),u.notify()):_e(l,a,u,a,t,i,n,p,s),s&&u.liveCollections.length>0)for(const m of u.liveCollections){const I=m.instance.getRawValue();if(Array.isArray(I))for(const R of I){if(typeof R!="object"||R===null)continue;const G=O.get(R);if(G===void 0)continue;const A=i.entityMap.getEntity(G);A!==void 0&&p.set(A,(p.get(A)??0)+1)}}u.setChildRefs(p.size>0?p:void 0,n);const g=u.getProxy(c);return r.set(u,(r.get(u)??0)+1),g}function ve(e,t,i,n,r,s,o,a,c,f,l){for(const[u,y]of ye(e))if(!(n!==void 0&&!n.has(u)))if(ge(t[u])&&(t[u]=B(t[u],o,a,c,f,l)),y instanceof _&&y._liveConfig!==void 0){const v=i[u];v instanceof le?l?v.append(t[u]):v.reset(t[u]):i[u]=he(y._liveConfig,t[u],r,s,a)}else{const v=t[u],p=i[u];if(dt(v)&&dt(p)){const g=y instanceof _&&y.shape!==void 0?y.shape:void 0;if(g!==void 0)ve(g,v,p,void 0,r,s,o,a,c,f,l);else for(const m of Object.keys(v))p[m]=v[m];i[u]=p}else i[u]=v}}function _e(e,t,i,n,r,s,o,a,c){for(const[f,l]of ye(e))if(f in t)if(ge(t[f])&&(t[f]=B(t[f],r,s,o,a,c)),l instanceof _&&l._liveConfig!==void 0)t[f]=he(l._liveConfig,t[f],i,n,s);else{const u=t[f];if(dt(u)){const y=l instanceof _&&l.shape!==void 0?l.shape:void 0;y!==void 0&&_e(y,u,i,n,r,s,o,a,c)}}}function dt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.getPrototypeOf(e)===pe&&!O.has(e)}function _i(e){if(e!==void 0)return typeof e=="string"?e:typeof e=="function"?e():e.value}function mi(e){return E.isSignal(e)}function Lt(e){if(e===void 0)return;const t={};for(const[i,n]of Object.entries(e))mi(n)?t[i]=n.value:t[i]=n;return t}const Ot=(e,t)=>S.hashValue([e.statics.id,t]);class wi{entityMap;queryInstances=new Map;mutationInstances=new Map;gcManager;networkManager;isServer;store;currentParseId=0;context;typenameRegistry=new Map;constraintRegistry=new Map;mergedDefCache=new Map;adapters=new Map;networkUnsubscribe;constructor(t={}){const{store:i=new At.SyncQueryStore(new At.MemoryPersistentStore),log:n,evictionMultiplier:r,adapters:s,networkManager:o,gcManager:a,...c}=t;this.isServer=typeof window>"u",this.store=i,this.context={...c,log:n??console,evictionMultiplier:r},this.gcManager=t.gcManager??(this.isServer?new Vt:new Ut(this.handleEviction,r)),this.networkManager=t.networkManager??new bt,this.entityMap=new ii((u,y,v)=>this.store.saveEntity(u,y,v));for(const u of t.adapters??[])this.adapters.set(u.constructor,u),u.register(this);const f=this.networkManager.getOnlineSignal(),l=E.watcher(()=>f.value);this.networkUnsubscribe=l.addListener(()=>{const u=f.value;for(const y of this.adapters.values())y.onNetworkStatusChange?.(u)},{skipInitial:!0}),this.store.purgeStaleQueries?.()}getAdapter(t){const i=this.adapters.get(t);if(i)return i;let n;for(const s of this.adapters.values())s instanceof t&&(n??=s);if(n!==void 0)return this.adapters.set(t,n),n;let r;try{r=new t}catch{throw new Error(`No adapter registered for ${t.name} and auto-instantiation failed. Pass an instance via QueryClient config: new QueryClient({ store, adapters: [new ${t.name}(...)] })`)}return this.adapters.set(t,r),r.register(this),r}getContext(){return this.context}registerEntityDef(t){const i=t.typenameValue;if(i===void 0||t._entityClass===void 0)return;const n=this.typenameRegistry.get(i);if(n!==void 0){if(n.indexOf(t)!==-1)return;n.push(t),this.mergedDefCache.delete(i),this.getMergedDef(i)}else this.typenameRegistry.set(i,[t])}getEntityDefsForTypename(t){return this.typenameRegistry.get(t)}getMergedDef(t){let i=this.mergedDefCache.get(t);if(i!==void 0)return i;const n=this.typenameRegistry.get(t);if(n!==void 0)return i=_.merge(n),this.mergedDefCache.set(t,i),i}saveQueryData(t,i,n,r,s){const o=s!==void 0&&s.size>0?new Set([...s.keys()].map(a=>a.key)):void 0;this.store.saveQuery(t,i,n,r,o)}activateQuery(t){const{def:i,queryKey:n,storageKey:r,config:s}=t;this.store.activateQuery(i,r);const o=s?.gcTime??qt.DEFAULT_GC_TIME;this.gcManager.cancel(n,o)}loadCachedQuery(t,i){return this.store.loadQuery(t,i)}getQuery(t,i){const n=Ot(t,i);let r=this.queryInstances.get(n);return r===void 0&&(r=new ai(t,this,n,i),this.queryInstances.set(n,r)),r.relay}getMutation(t){const i=t.id;let n=this.mutationInstances.get(i);return n===void 0&&(n=new ci(t,this),this.mutationInstances.set(i,n)),n.task}parseData(t,i,n){const r=this.context.log?.warn??(()=>{}),s=new ct;return s.reset(this,n,r),{data:ne(t,i,s),ctx:s}}applyRefs(t,i=!0,n=!1){return rt(t.ctx,t.data,i,n)}parseAndApplyRootEntity(t,i,n,r,s=!1,o){typeof n.idField=="symbol"&&typeof t=="object"&&t!==null&&!("__entityRef"in t)&&(t[lt]=i);const a=this.parseData(t,n,o),c=rt(a.ctx,a.data,r,s),f=O.get(c.data);return this.entityMap.getEntity(f)}prepareEntity(t,i,n){return this.registerEntityDef(n),this.entityMap.getOrCreateEntity(t,i,n,this)}applyMutationEvent(t){const{type:i,typename:n}=t,r=this.getMergedDef(n);if(r===void 0)return;const s=r.idField;if(s===void 0||typeof s=="symbol")return;const o=t.data,a=t.id!==void 0?t.id:i==="delete"&&(typeof o=="string"||typeof o=="number")?o:o[s];if(a===void 0)return;const c=S.hashValue([n,a]),f=t.__eventSource,l=typeof o=="object"&&o!==null?o:{},u=this.entityMap.getEntity(c);if(i==="delete"){const g=u!==void 0?u.data:l;this.routeEvent(n,g,c,i,f,void 0,g);return}try{const g=this.context.log?.warn??(()=>{}),m=new ct;m.reset(this,void 0,g,!0);const I=Be(l,r,m);rt(m,I,!0)}catch(g){if(this.context.log?.warn?.("Failed to apply mutation event",g),u===void 0){const m=this.entityMap.getEntity(c);m!==void 0&&m.evict()}return}const y=this.entityMap.getEntity(c);if(y===void 0)return;this.entityMap.save(y);const v=u===void 0;let p=!1;this.routeEvent(n,y.data,c,i,f,()=>{p=!0}),v&&!p&&y.evict()}invalidateQueries(t){for(const i of t){const n=Array.isArray(i),r=n?i[0]:i,s=n?i[1]:void 0,a=Y.for(r).statics.id;for(const[,c]of this.queryInstances)c.def.statics.id===a&&(s===void 0||Ei(c.resolvedParams,s))&&c.markStale()}}handleEviction=(t,i)=>{if(i===X.Query){const r=this.queryInstances.get(t);if(r===void 0)return;r.rootEntity?.evict(),this.queryInstances.delete(t);return}const n=this.entityMap.getEntity(t);n!==void 0&&n.evict()};getOrCreateMatcher(t){let i=this.constraintRegistry.get(t);return i===void 0&&(i=new yi,this.constraintRegistry.set(t,i)),i}registerLiveCollection(t){for(const[i,n]of t._entityDefsByTypename)this.registerEntityDef(n),this.getOrCreateMatcher(i).registerBinding(t,i)}unregisterLiveCollection(t){for(const i of t._entityDefsByTypename.keys()){const n=this.constraintRegistry.get(i);n!==void 0&&n.unregisterBinding(t,i)}}routeEvent(t,i,n,r,s,o,a){const c=this.constraintRegistry.get(t);if(c===void 0)return;const f=s!==void 0?{...i,[fe]:s}:i;c.routeEvent(t,f,n,r,o,a)}destroy(){this.networkUnsubscribe?.(),this.gcManager.destroy(),this.networkManager.destroy();for(const t of this.adapters.values())t.destroy?.();this.adapters.clear(),this.queryInstances.clear(),this.mutationInstances.clear(),this.constraintRegistry.clear(),this.typenameRegistry.clear(),this.mergedDefCache.clear()}}const me=E.context(void 0);function Ei(e,t){if(e===void 0)return!1;for(const i in t)if(e[i]!==t[i])return!1;return!0}exports.ARRAY_KEY=V;exports.Entity=Z;exports.GcManager=Ut;exports.LiveFieldConfig=L;exports.LiveFieldType=J;exports.Mask=d;exports.NetworkManager=bt;exports.NetworkManagerContext=ni;exports.NetworkMode=j;exports.NoOpGcManager=Vt;exports.NoOpNetworkManager=Ct;exports.QUERY_ID=lt;exports.Query=ri;exports.QueryClient=wi;exports.QueryClientContext=me;exports.RECORD_KEY=K;exports.ValidatorDef=_;exports.createDefinitionProxy=yt;exports.defaultNetworkManager=ae;exports.draft=$e;exports.extractDefinition=Bt;exports.fetchQuery=oi;exports.queryKeyForClass=si;exports.registerFormat=mt;exports.reifyValue=$;exports.resolveBaseUrl=_i;exports.t=ee;
2
+ //# sourceMappingURL=QueryClient-BPdrfgtE.js.map