fetchium 0.1.0 → 0.1.1

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 (138) hide show
  1. package/CHANGELOG.md +6 -5
  2. package/dist/cjs/development/QueryClient-CLi3ONNM.js +2 -0
  3. package/dist/cjs/development/QueryClient-CLi3ONNM.js.map +1 -0
  4. package/dist/cjs/development/QueryController-BQA49OYU.js +2 -0
  5. package/dist/cjs/development/QueryController-BQA49OYU.js.map +1 -0
  6. package/dist/cjs/development/index.js +1 -1
  7. package/dist/cjs/development/index.js.map +1 -1
  8. package/dist/cjs/development/mutation-CikIl_6k.js +2 -0
  9. package/dist/cjs/development/mutation-CikIl_6k.js.map +1 -0
  10. package/dist/cjs/development/react/index.js +1 -1
  11. package/dist/cjs/development/rest/index.js +2 -0
  12. package/dist/cjs/development/rest/index.js.map +1 -0
  13. package/dist/cjs/development/topic/index.js +2 -0
  14. package/dist/cjs/development/topic/index.js.map +1 -0
  15. package/dist/cjs/production/QueryClient-N0MJmuHW.js +2 -0
  16. package/dist/cjs/production/QueryClient-N0MJmuHW.js.map +1 -0
  17. package/dist/cjs/production/QueryController-BQA49OYU.js +2 -0
  18. package/dist/cjs/production/QueryController-BQA49OYU.js.map +1 -0
  19. package/dist/cjs/production/index.js +1 -1
  20. package/dist/cjs/production/index.js.map +1 -1
  21. package/dist/cjs/production/mutation-P_Yb4LI9.js +2 -0
  22. package/dist/cjs/production/mutation-P_Yb4LI9.js.map +1 -0
  23. package/dist/cjs/production/react/index.js +1 -1
  24. package/dist/cjs/production/rest/index.js +2 -0
  25. package/dist/cjs/production/rest/index.js.map +1 -0
  26. package/dist/cjs/production/topic/index.js +2 -0
  27. package/dist/cjs/production/topic/index.js.map +1 -0
  28. package/dist/esm/MutationResult.d.ts +0 -1
  29. package/dist/esm/MutationResult.d.ts.map +1 -1
  30. package/dist/esm/QueryClient.d.ts +26 -4
  31. package/dist/esm/QueryClient.d.ts.map +1 -1
  32. package/dist/esm/QueryController.d.ts +49 -0
  33. package/dist/esm/QueryController.d.ts.map +1 -0
  34. package/dist/esm/QueryResult.d.ts +10 -10
  35. package/dist/esm/QueryResult.d.ts.map +1 -1
  36. package/dist/esm/development/QueryClient-Dtde3pss.js +2572 -0
  37. package/dist/esm/development/QueryClient-Dtde3pss.js.map +1 -0
  38. package/dist/esm/development/QueryController-Ch_ncxiI.js +14 -0
  39. package/dist/esm/development/QueryController-Ch_ncxiI.js.map +1 -0
  40. package/dist/esm/development/index.js +29 -100
  41. package/dist/esm/development/index.js.map +1 -1
  42. package/dist/esm/development/mutation-UZshUQAf.js +58 -0
  43. package/dist/esm/development/mutation-UZshUQAf.js.map +1 -0
  44. package/dist/esm/development/react/index.js +1 -1
  45. package/dist/esm/development/rest/index.js +142 -0
  46. package/dist/esm/development/rest/index.js.map +1 -0
  47. package/dist/esm/development/{shared-Dq2yW78d.js → shared-DcuVH8Pf.js} +5 -5
  48. package/dist/esm/development/{shared-Dq2yW78d.js.map → shared-DcuVH8Pf.js.map} +1 -1
  49. package/dist/esm/development/stores/async.js +6 -6
  50. package/dist/esm/development/stores/sync.js +5 -5
  51. package/dist/esm/development/topic/index.js +86 -0
  52. package/dist/esm/development/topic/index.js.map +1 -0
  53. package/dist/esm/index.d.ts +5 -4
  54. package/dist/esm/index.d.ts.map +1 -1
  55. package/dist/esm/mutation.d.ts +6 -19
  56. package/dist/esm/mutation.d.ts.map +1 -1
  57. package/dist/esm/production/{QueryClient-BP0Z1rQV.js → QueryClient-YqnBxFy1.js} +972 -968
  58. package/dist/esm/production/QueryClient-YqnBxFy1.js.map +1 -0
  59. package/dist/esm/production/QueryController-Ch_ncxiI.js +14 -0
  60. package/dist/esm/production/QueryController-Ch_ncxiI.js.map +1 -0
  61. package/dist/esm/production/index.js +29 -100
  62. package/dist/esm/production/index.js.map +1 -1
  63. package/dist/esm/production/mutation-pgFl1uIY.js +58 -0
  64. package/dist/esm/production/mutation-pgFl1uIY.js.map +1 -0
  65. package/dist/esm/production/react/index.js +1 -1
  66. package/dist/esm/production/rest/index.js +142 -0
  67. package/dist/esm/production/rest/index.js.map +1 -0
  68. package/dist/esm/production/{shared-Dq2yW78d.js → shared-DcuVH8Pf.js} +5 -5
  69. package/dist/esm/production/{shared-Dq2yW78d.js.map → shared-DcuVH8Pf.js.map} +1 -1
  70. package/dist/esm/production/stores/async.js +6 -6
  71. package/dist/esm/production/stores/sync.js +5 -5
  72. package/dist/esm/production/topic/index.js +86 -0
  73. package/dist/esm/production/topic/index.js.map +1 -0
  74. package/dist/esm/query-types.d.ts +2 -4
  75. package/dist/esm/query-types.d.ts.map +1 -1
  76. package/dist/esm/query.d.ts +17 -39
  77. package/dist/esm/query.d.ts.map +1 -1
  78. package/dist/esm/rest/RESTMutation.d.ts +18 -0
  79. package/dist/esm/rest/RESTMutation.d.ts.map +1 -0
  80. package/dist/esm/rest/RESTQuery.d.ts +24 -0
  81. package/dist/esm/rest/RESTQuery.d.ts.map +1 -0
  82. package/dist/esm/rest/RESTQueryController.d.ts +34 -0
  83. package/dist/esm/rest/RESTQueryController.d.ts.map +1 -0
  84. package/dist/esm/rest/index.d.ts +5 -0
  85. package/dist/esm/rest/index.d.ts.map +1 -0
  86. package/dist/esm/stores/shared.d.ts.map +1 -1
  87. package/dist/esm/testing/MockClient.d.ts +64 -0
  88. package/dist/esm/testing/MockClient.d.ts.map +1 -0
  89. package/dist/esm/testing/auto-generate.d.ts +20 -0
  90. package/dist/esm/testing/auto-generate.d.ts.map +1 -0
  91. package/dist/esm/testing/entity-factory.d.ts +13 -0
  92. package/dist/esm/testing/entity-factory.d.ts.map +1 -0
  93. package/dist/esm/testing/index.d.ts +6 -0
  94. package/dist/esm/testing/index.d.ts.map +1 -0
  95. package/dist/esm/testing/types.d.ts +37 -0
  96. package/dist/esm/testing/types.d.ts.map +1 -0
  97. package/dist/esm/topic/TopicQuery.d.ts +10 -0
  98. package/dist/esm/topic/TopicQuery.d.ts.map +1 -0
  99. package/dist/esm/topic/TopicQueryController.d.ts +43 -0
  100. package/dist/esm/topic/TopicQueryController.d.ts.map +1 -0
  101. package/dist/esm/topic/index.d.ts +3 -0
  102. package/dist/esm/topic/index.d.ts.map +1 -0
  103. package/dist/esm/typeDefs.d.ts +1 -1
  104. package/dist/esm/types.d.ts +9 -4
  105. package/dist/esm/types.d.ts.map +1 -1
  106. package/package.json +51 -4
  107. package/plugin/.claude-plugin/plugin.json +10 -0
  108. package/plugin/agents/fetchium.md +168 -0
  109. package/plugin/docs/api/fetchium-react.md +135 -0
  110. package/plugin/docs/api/fetchium.md +674 -0
  111. package/plugin/docs/api/stores-async.md +219 -0
  112. package/plugin/docs/api/stores-sync.md +133 -0
  113. package/plugin/docs/core/entities.md +351 -0
  114. package/plugin/docs/core/queries.md +600 -0
  115. package/plugin/docs/core/streaming.md +550 -0
  116. package/plugin/docs/core/types.md +374 -0
  117. package/plugin/docs/data/caching.md +298 -0
  118. package/plugin/docs/data/live-data.md +435 -0
  119. package/plugin/docs/data/mutations.md +465 -0
  120. package/plugin/docs/guides/auth.md +318 -0
  121. package/plugin/docs/guides/error-handling.md +351 -0
  122. package/plugin/docs/guides/offline.md +270 -0
  123. package/plugin/docs/guides/testing.md +301 -0
  124. package/plugin/docs/quickstart.md +170 -0
  125. package/plugin/docs/reference/pagination.md +519 -0
  126. package/plugin/docs/reference/rest-queries.md +107 -0
  127. package/plugin/docs/reference/why-signalium.md +364 -0
  128. package/plugin/docs/setup/project-setup.md +319 -0
  129. package/plugin/install.mjs +88 -0
  130. package/plugin/skills/design/SKILL.md +140 -0
  131. package/plugin/skills/teach/SKILL.md +105 -0
  132. package/dist/cjs/development/QueryClient-CpmwggOn.js +0 -2
  133. package/dist/cjs/development/QueryClient-CpmwggOn.js.map +0 -1
  134. package/dist/cjs/production/QueryClient-qi3bR0eD.js +0 -2
  135. package/dist/cjs/production/QueryClient-qi3bR0eD.js.map +0 -1
  136. package/dist/esm/development/QueryClient-DRZtPKFD.js +0 -2568
  137. package/dist/esm/development/QueryClient-DRZtPKFD.js.map +0 -1
  138. package/dist/esm/production/QueryClient-BP0Z1rQV.js.map +0 -1
@@ -1,2 +0,0 @@
1
- "use strict";const b=require("signalium"),D=require("signalium/utils"),Lt=require("./shared-Ct5zKrt4.js");var L=(i=>(i.Always="always",i.Online="online",i.OfflineFirst="offlineFirst",i))(L||{}),u=(i=>(i[i.UNDEFINED=1]="UNDEFINED",i[i.NULL=2]="NULL",i[i.NUMBER=4]="NUMBER",i[i.STRING=8]="STRING",i[i.BOOLEAN=16]="BOOLEAN",i[i.OBJECT=32]="OBJECT",i[i.ARRAY=64]="ARRAY",i[i.ID=128]="ID",i[i.RECORD=256]="RECORD",i[i.UNION=512]="UNION",i[i.ENTITY=1024]="ENTITY",i[i.HAS_FORMAT=4096]="HAS_FORMAT",i[i.IS_EAGER_FORMAT=8192]="IS_EAGER_FORMAT",i[i.PARSE_RESULT=16384]="PARSE_RESULT",i[i.LIVE=32768]="LIVE",i))(u||{});const K=Symbol("array"),$=Symbol("record"),ut=Symbol("QUERY_ID");var H=(i=>(i[i.Array=0]="Array",i[i.Value=1]="Value",i))(H||{});class q{type;entityDefs;constraintFieldRefs;sort;valueType;onCreate;onUpdate;onDelete;constructor(t,e,n,s,r,o,a,c){this.type=t,this.entityDefs=e,this.constraintFieldRefs=n,this.sort=s,this.valueType=r,this.onCreate=o,this.onUpdate=a,this.onDelete=c}static array(t,e,n){return new q(0,t,e,n,void 0,void 0,void 0,void 0)}static value(t,e,n,s,r,o){return new q(1,t,e,void 0,n,s,r,o)}}const S=new WeakMap;function k(i){return S.get(i)}var z=(i=>(i[i.Query=0]="Query",i[i.Entity=1]="Entity",i))(z||{});class me{constructor(t,e,n){this._onEvict=e,this._intervalId=setInterval(this._tick,t*6e4*n)}_currentFlush=new Map;_nextFlush=new Map;_intervalId;schedule(t,e){this._nextFlush.set(t,e)}cancel(t){this._currentFlush.delete(t),this._nextFlush.delete(t)}_tick=()=>{const{_currentFlush:t,_nextFlush:e,_onEvict:n}=this;for(const[s,r]of t)n(s,r);this._currentFlush=e,this._nextFlush=new Map};destroy(){clearInterval(this._intervalId)}}class qt{_buckets=new Map;_nextTickEntries=new Map;_nextTickScheduled=!1;_onEvict;_multiplier;constructor(t,e=1){this._onEvict=t,this._multiplier=e}schedule(t,e,n){if(e===1/0)return;if(e===0){const{_nextTickEntries:o}=this;o.set(t,n),this._nextTickScheduled||(this._nextTickScheduled=!0,setTimeout(this._flushNextTick,0));return}const{_buckets:s}=this;let r=s.get(e);r||(r=new me(e,this._onEvict,this._multiplier),s.set(e,r)),r.schedule(t,n)}cancel(t,e){if(e!==1/0){if(e===0){this._nextTickEntries.delete(t);return}this._buckets.get(e)?.cancel(t)}}_flushNextTick=()=>{const{_nextTickEntries:t,_onEvict:e}=this;this._nextTickScheduled=!1;for(const[n,s]of t)e(n,s);t.clear()};destroy(){const{_buckets:t,_nextTickEntries:e}=this;for(const n of t.values())n.destroy();t.clear(),e.clear()}}class jt{schedule(t,e,n){}cancel(t,e){}destroy(){}}const G=Symbol("fieldRef"),F=Symbol("fieldRefPath"),dt=Symbol("DEFINITION_TARGET"),W=Symbol("CANCEL_PROXY"),Ee=/\[([^\]]+)\]/g;function Ut(i){const t={[G]:!0,[F]:i};return new Proxy(t,we)}const we={get(i,t){if(t===G)return!0;if(t===F)return i[F];if(t===Symbol.toPrimitive||t==="toString"||t==="valueOf"){const n=i[F];return()=>`[${n.join(".")}]`}if(typeof t=="symbol")return;const e=i[F];return Ut([...e,t])},has(i,t){return t===G||t===F}};function Vt(i){return typeof i=="object"&&i!==null&&i[G]===!0}function Kt(i){return i[F]}function lt(i){return new Proxy(i,{set(t,e,n){return t[e]=n,!0},get(t,e){return e===dt?t:e===W?()=>{}:typeof e=="symbol"?t[e]:Ut([e])}})}function $t(i){const t=i[dt];i[W]();const e={};for(const r of Object.getOwnPropertyNames(t))e[r]=t[r];const n={};let s=Object.getPrototypeOf(t);for(;s&&s!==Object.prototype;){for(const r of Object.getOwnPropertyNames(s)){if(r==="constructor")continue;const o=Object.getOwnPropertyDescriptor(s,r);typeof o.value=="function"&&!(r in n)&&(n[r]=o.value)}s=Object.getPrototypeOf(s)}return{fields:e,methods:n}}function ht(i,t){let e=t;for(const n of i){if(e==null)return;e=e[n]}return e}function Ce(i,t){return i.replace(Ee,(e,n)=>{const s=n.split("."),r=ht(s,t);return r!=null?encodeURIComponent(String(r)):""})}function j(i,t){if(Vt(i))return ht(Kt(i),t);if(typeof i=="string")return Ce(i,t);if(Array.isArray(i))return i.map(e=>j(e,t));if(typeof i=="object"&&i!==null&&Object.getPrototypeOf(i)===Object.prototype){const e={};for(const n of Object.keys(i))e[n]=j(i[n],t);return e}return i}function nt(i,t,e){const n=i.fields,s=i.methods,r={params:t},o={};for(const[a,c]of Object.entries(n))o[a]=j(c,r);o.params=t,o.context=e;for(const[a,c]of Object.entries(s))o[a]=c.bind(o);return o}class yt{static cache;constructor(){return lt(this)}}const Bt=Object.entries,st=Object.keys;function St(i){return typeof i=="number"?i|u.UNDEFINED:i instanceof _?(i.mask&u.UNDEFINED)!==0?i:_.cloneWith(i,u.UNDEFINED):i}function be(i){return i instanceof _&&(i.mask&u.OBJECT)!==0&&(i.mask&(u.ENTITY|u.ARRAY|u.UNION|u.RECORD|u.LIVE))===0}function Qt(i,t,e){const n=new Set;for(const r of i)if(r!==void 0)for(const o of Object.keys(r))n.add(o);const s={};for(const r of n){let o=0,a;const c=[];let f=!0;for(const l of i){const d=l?.[r];d!==void 0?(o++,a===void 0&&(a=d),be(d)?c.push(d.shape):(f=!1,c.push(void 0))):(f=!1,c.push(void 0))}if(f&&o>0){const l=Qt(c,t),d=new _(u.OBJECT,l);s[r]=o<t?St(d):d}else s[r]=o<t?St(a):a}return s}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,e,n,s,r,o){this.mask=t,this.shape=e,this.values=n,this.typenameField=s,this.typenameValue=r,this.idField=o}static merge(t){if(t.length===1)return t[0];const e=t.length,n=t.map(c=>c.shape);t[0].typenameValue;const s=Qt(n,e);let r,o,a;for(const c of t){if(r===void 0&&c.idField!==void 0)r=c.idField;else if(r!==void 0&&c.idField!==void 0&&c.idField!==r)throw new Error(`[fetchium] Entity typename '${c.typenameValue}' has conflicting id fields: '${String(r)}' vs '${String(c.idField)}'`);o===void 0&&(o=c.typenameField),a===void 0&&(a=c.typenameValue)}return new _(u.ENTITY|u.OBJECT,s,void 0,o,a,r)}static cloneWith(t,e){const n=new _(e|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 J extends Set{lowercaseMap;constructor(t){super(t),this.lowercaseMap=new Map;for(const e of t)if(typeof e=="string"){const n=e.toLowerCase(),s=this.lowercaseMap.get(n);if(s!==void 0)throw new Error(`Case-insensitive enum cannot have multiple values with the same lowercase form: '${s}' and '${e}' both become '${n}'`);this.lowercaseMap.set(n,e)}}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 xe=1128875347;D.registerCustomHash(J,i=>{let t=xe;for(const e of i)t+=D.hashValue(e);return t>>>0});function pt(i,t){return new _(i,t)}function Re(i){return pt(u.ARRAY,i)}function Oe(i){return pt(u.RECORD|u.OBJECT,i)}function Se(i){return pt(u.PARSE_RESULT,i)}function Yt(i,t){let e=i,n,s,r;for(const[o,a]of Bt(t))switch(typeof a){case"number":if((a&u.ID)!==0){if(n!==void 0)throw new Error(`Duplicate id field: ${o}`);n=o}break;case"string":if(s!==void 0&&s!==o)throw new Error(`Duplicate typename field: ${o}`);s=o,r=a;break;case"object":if(a instanceof J||a instanceof Set)break;a.mask&u.LIVE&&(e|=u.LIVE);break}return new _(e,t,void 0,s,r,n)}function Ne(i){return Yt(u.OBJECT,i)}function Nt(i,t,e){const n=i.mask;if((n&u.UNION)!==0){const s=i;if(s.typenameField!==void 0){if(e!==void 0&&e!==s.typenameField)throw new Error(`Union typename field conflict: Cannot merge unions with different typename fields ('${e}' vs '${s.typenameField}')`);e=s.typenameField}const r=s.shape;if(r!==void 0)for(const o of[...st(r),K,$]){const a=r[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&u.ARRAY)!==0){if(t[K]!==void 0)throw new Error("Array shape already defined");t[K]=i.shape}else if((n&u.RECORD)!==0){if(t[$]!==void 0)throw new Error("Record shape already defined");t[$]=i.shape}else{const s=i.typenameField,r=i.typenameValue;if(r===void 0)throw new Error("Object definitions must have a typename to be in a union with other objects, records, or arrays");if(e!==void 0&&s!==e)throw new Error("Object definitions must have the same typename field to be in the same union");e=s,t[r]=i}return e}function gt(...i){const t=i;let e=0,n=0,s,r,o,a,c=0;for(const l of t){if(typeof l=="number"){e|=l;continue}if(l instanceof Set){if(r===void 0)r=new Set(l);else for(const d of l)r.add(d);continue}if(n++,c|=l.mask,n===1){s=l;continue}n===2&&(o=Object.create(null),a=Nt(s,o,a)),a=Nt(l,o,a)}if(n===0)return r===void 0?e:e===0?r:new _(e|u.UNION,void 0,r);if(n===1)return _.cloneWith(s,e);const f=e|c|u.UNION;return new _(f,o,r,a)}function vt(i,t,e){const n=i;if(typeof n=="number")return n|t;if(n instanceof Set)return gt(i,t);let s=e.get(n);return s===void 0&&(s=_.cloneWith(n,t),e.set(n,s)),s}const De=new WeakMap,Ae=new WeakMap,Ie=new WeakMap;function Me(i){return vt(i,u.UNDEFINED|u.NULL,Ie)}function Fe(i){return vt(i,u.UNDEFINED,De)}function Te(i){return vt(i,u.NULL,Ae)}function ke(i){return i}function Pe(i){return new Set([i])}const Gt=((...i)=>new Set(i));Gt.caseInsensitive=(...i)=>new J(i);const Wt=16;let Le=0;const rt=[],Ht=[],zt=new Map,X=new WeakSet;class B{_raw;_formatted;_parsed;_formatId;constructor(t,e,n){this._raw=t,this._formatId=e,n?(this._formatted=rt[e](t),this._parsed=!0):this._parsed=!1,X.add(this)}getValue(){return this._parsed||(this._formatted=rt[this._formatId](this._raw),this._parsed=!0),this._formatted}toJSON(){return this._parsed?Ht[this._formatId](this._formatted):this._raw}}function qe(i){const t=zt.get(i);if(t===void 0)throw new Error(`Format ${i} not registered`);return t}function _t(i,t,e,n,s){const r=Le++;rt[r]=e,Ht[r]=n;const o=s?.eager??!0,c=r<<Wt|t|u.HAS_FORMAT|(o?u.IS_EAGER_FORMAT:0);zt.set(i,c)}_t("date",u.STRING,i=>{const t=i.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)throw new Error(`Invalid date string: ${i}. Expected YYYY-MM-DD format.`);const[,e,n,s]=t,r=new Date(Date.UTC(parseInt(e,10),parseInt(n,10)-1,parseInt(s,10)));if(isNaN(r.getTime()))throw new Error(`Invalid date string: ${i}`);return r},i=>{const t=i.getUTCFullYear(),e=String(i.getUTCMonth()+1).padStart(2,"0"),n=String(i.getUTCDate()).padStart(2,"0");return`${t}-${e}-${n}`});_t("date-time",u.STRING,i=>{const t=new Date(i);if(isNaN(t.getTime()))throw new Error(`Invalid date-time string: ${i}`);return t},i=>i.toISOString());const Dt=new WeakMap;function U(i){let t=Dt.get(i);if(t===void 0){const e=new i,n=e[dt]??e;e[W]&&e[W]();const s={};for(const[f,l]of Bt(n))s[f]=l;const r=Object.getPrototypeOf(i.prototype);if(r!=null){const f=r.constructor;if(f!==yt&&typeof f=="function"){const d=U(f).shape;for(const y of st(d))if(y in s&&s[y]!==d[y])throw new Error(`Cannot extend: field '${y}' already exists in type definition`)}}const o={},a=i.prototype;for(const f of Object.getOwnPropertyNames(a))f!=="constructor"&&typeof a[f]=="function"&&(o[f]=a[f]);t=Yt(u.ENTITY|u.OBJECT,s),t._entityClass=i,st(o).length>0&&(t._methods=o),typeof o.__subscribe=="function"&&(t._entityConfig={hasSubscribe:!0});const c=i;c.cache&&(t._entityCache=c.cache),Dt.set(i,t)}return t}function je(i){return U(i)}function Jt(i,t){if(t==null)return;const e=new Map;if(Array.isArray(t))for(const n of t){const[s,r]=n,a=U(s).typenameValue;if(a===void 0)continue;const c=[];for(const[f,l]of Object.entries(r))c.push([f,l]);c.length>0&&e.set(a,c)}else{const s=Object.entries(t);if(s.length===0)return;const r=s.map(([o,a])=>[o,a]);for(const o of i){const a=o.typenameValue;a!==void 0&&e.set(a,r)}}return e.size>0?e:void 0}function Xt(i){return Array.isArray(i)?i.map(t=>U(t)):[U(i)]}function Ue(i,t){const e=Xt(i),n=e.length===1?e[0]:gt(...e.map(o=>o)),s=u.ARRAY|u.LIVE,r=new _(s,n);return r._liveConfig=q.array(e,Jt(e,t?.constraints),t?.sort),r}function Ve(i,t,e){const n=Xt(t),s=i,r=u.LIVE,o=new _(r,void 0);return o._liveConfig=q.value(n,Jt(n,e?.constraints),s,e.onCreate,e.onUpdate,e.onDelete),o}const Zt={format:qe,typename:ke,const:Pe,enum:Gt,id:u.ID|u.STRING|u.NUMBER,string:u.STRING,number:u.NUMBER,boolean:u.BOOLEAN,null:u.NULL,undefined:u.UNDEFINED,array:Re,object:Ne,record:Oe,union:gt,nullish:Me,optional:Fe,nullable:Te,result:Se,entity:je,liveArray:Ue,liveValue:Ve};function V(i,t,e){return new TypeError(`Validation error at ${i}`)}const te=Array.isArray;function At(i){if(i===null)return u.NULL;switch(typeof i){case"number":return u.NUMBER;case"string":return u.STRING;case"boolean":return u.BOOLEAN;case"undefined":return u.UNDEFINED;case"object":return te(i)?u.ARRAY:u.OBJECT;default:throw new Error(`Invalid type: ${typeof i}`)}}function Ke(i){return P(i)}function P(i){if(i===null||typeof i!="object")return i;if(te(i))return i.map(e=>P(e));if(i instanceof Date)return new Date(i.getTime());if(i instanceof Map){const e=new Map;for(const[n,s]of i)e.set(P(n),P(s));return e}if(i instanceof Set){const e=new Set;for(const n of i)e.add(P(n));return e}const t={};for(const e of Object.keys(i))t[e]=P(i[e]);return t}const mt=Object.entries,$e=()=>{};class ot{queryClient=void 0;preloadedEntities=void 0;warn=$e;isPartialEvent=!1;seen=void 0;seenByKey=void 0;reset(t,e,n,s=!1){this.queryClient=t,this.preloadedEntities=e,this.warn=n,this.isPartialEvent=s,t!==void 0&&(this.seen===void 0?(this.seen=new Map,this.seenByKey=new Map):(this.seen.clear(),this.seenByKey.clear()))}}function ee(i,t,e){return T(i,t,e,"")}function Be(i,t,e){return Et(i,t,e)}function It(i,t,e,n){const s=i>>Wt;if((i&u.IS_EAGER_FORMAT)!==0)try{return new B(t,s,!0)}catch(o){if((i&u.UNDEFINED)!==0){e.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 B(t,s,!1)}function T(i,t,e,n){const s=t;if(s instanceof J){const c=s.get(i);if(c===void 0)throw V(n);return c}if(s instanceof Set){if(!s.has(i))throw V(n);return i}if(typeof s=="string"){if(i==null)return s;if(i!==s)throw V(n);return i}if(typeof s=="number"){const c=At(i);if((s&c)===0){if((s&u.UNDEFINED)!==0){e.warn("Invalid value for optional type, defaulting to undefined",{value:i,path:n});return}throw V(n)}return(s&u.HAS_FORMAT)!==0&&i!==null&&i!==void 0?It(s,i,e,n):i}const r=s.mask,o=s._liveConfig;if(o!==void 0&&o.type===H.Value)return o.valueType!==void 0?T(i,o.valueType,e,n):i;if((r&u.PARSE_RESULT)!==0)try{return{success:!0,value:T(i,s.shape,e,n)}}catch(c){return{success:!1,error:c instanceof Error?c:new Error(String(c))}}const a=At(i);if((r&a)===0&&!s.values?.has(i)){if((r&u.UNDEFINED)!==0){e.warn("Invalid value for optional type, defaulting to undefined",{value:i,path:n});return}throw V(n)}return a<u.OBJECT?(r&u.HAS_FORMAT)!==0&&i!==null&&i!==void 0?It(r,i,e,n):i:(r&u.UNION)!==0?Qe(a,i,s,e,n):a===u.ARRAY?ie(i,s.shape,e,n):(r&u.RECORD)!==0?ne(i,s.shape,e,n):(r&u.ENTITY)!==0&&e.queryClient!==void 0?Et(i,s,e):se(i,s,e,n)}function Qe(i,t,e,n,s){if(i===u.ARRAY){const r=e.shape[K];return r===void 0||typeof r=="number"?t:ie(t,r,n,s)}else{const r=e.typenameField,o=r?t[r]:void 0;if(o===void 0||typeof o!="string"){const c=e.shape[$];if(c===void 0)throw new Error(`Typename field '${r}' is required for union discrimination but was not found in the data`);return ne(t,c,n,s)}const a=e.shape[o];if(a===void 0||typeof a=="number")throw new Error(`Unknown typename '${o}' in union`);return a.mask&u.ENTITY&&n.queryClient!==void 0?Et(t,a,n):se(t,a,n,s)}}function ie(i,t,e,n){const s=[];for(let r=0;r<i.length;r++)try{s.push(T(i[r],t,e,`${n}[${r}]`))}catch(o){e.warn("Failed to parse array item, filtering out",{index:r,value:i[r],error:o instanceof Error?o.message:String(o)})}return s}function ne(i,t,e,n){for(const[s,r]of mt(i))i[s]=T(r,t,e,`${n}["${s}"]`);return i}function se(i,t,e,n){if(S.has(i))return i;const s=t.shape;for(const[r,o]of mt(s))i[r]=T(i[r],o,e,`${n}.${r}`);return i}function Et(i,t,e){const n=e.queryClient,s=e.preloadedEntities;let r,o;if(s!==void 0)r=i.__entityRef,o=r;else{const p=i[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,r=D.hashValue([t.typenameValue,o])}const a=e.seenByKey.get(r);if(a!==void 0)return a.data;if(s!==void 0){const g=n.entityMap.getEntity(r)?.data??s.get(r);if(g===void 0)throw new Error(`Cached entity ${r} not found in preloaded map`);i=g}const c={};typeof t.idField=="symbol"&&(c[t.idField]=o);const f=n.entityMap.getEntity(r),l=e.isPartialEvent&&f!==void 0,d={key:r,shape:t,data:c,rawKeys:l?new Set(Object.keys(i)):void 0};e.seen.set(c,d),e.seenByKey.set(r,d);const y=`[[${t.typenameValue}:${o}]]`,v=t.shape;for(const[p,g]of mt(v))l&&!(p in i)||(c[p]=T(i[p],g,e,`${y}.${p}`));return c}function Ye(i,t){return Ge(i,t.shape,t.typenameField)}function Ge(i,t,e){if(t===void 0)return!0;for(const n of Object.keys(t)){if(n===e)continue;const s=t[n];if(s instanceof _){if((s.mask&u.UNDEFINED)!==0)continue;if(!(n in i)||i[n]===void 0)return!1}else if(typeof s=="number"){if((s&u.UNDEFINED)!==0)continue;if(!(n in i)||i[n]===void 0)return!1}else if(!(n in i)||i[n]===void 0)return!1}return!0}const We=Object.prototype,Y=new WeakMap;function I(i){if(typeof i!="object"||i===null)return i;if(X.has(i))return I(i.getValue());if(S.has(i))return i;if(Array.isArray(i)){let t=Y.get(i);return t===void 0&&(t=new Proxy(i,He),Y.set(i,t)),t}if(Object.getPrototypeOf(i)===We){let t=Y.get(i);return t===void 0&&(t=new Proxy(i,ze),Y.set(i,t)),t}return i}const He={get(i,t,e){if(typeof t=="string"){const n=Number(t);if(Number.isInteger(n)&&n>=0&&n<i.length)return I(i[n])}return Reflect.get(i,t,e)},set(){return!1},deleteProperty(){return!1}},ze={get(i,t,e){return typeof t=="string"?I(i[t]):Reflect.get(i,t,e)},set(){return!1},deleteProperty(){return!1},has(i,t){return t in i},ownKeys(i){return Reflect.ownKeys(i)},getOwnPropertyDescriptor(i,t){return Object.getOwnPropertyDescriptor(i,t)}};class Je{_notifier;_queryClient;_proxies=new Map;key;typename;id;idField;data;refCount=0;entityRefs;liveCollections=[];satisfiedDefs=new WeakSet;parseId=-1;_entityCache;_extraMethods;_extraGetters;constructor(t,e,n,s,r,o){this._notifier=b.notifier(),this._queryClient=o,this.key=t,this.typename=e,this.id=n,this.idField=s,this.data=r,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,z.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 e=this.entityRefs;if(this.entityRefs=void 0,e)for(const n of e.keys())n.release()}setChildRefs(t,e){const n=this.entityRefs;if(t!==void 0&&t.size>0)for(const s of t.keys())(n===void 0||!n.has(s))&&s.retain();if(n!==void 0&&n.size>0)for(const s of n.keys())(t===void 0||!t.has(s))&&s.release();this.entityRefs=t,e&&this.save()}addChildRef(t){this.entityRefs===void 0&&(this.entityRefs=new Map);const e=this.entityRefs.get(t)??0;this.entityRefs.set(t,e+1),e===0&&t.retain(),this.save()}removeChildRef(t){if(this.entityRefs===void 0)return;const e=this.entityRefs.get(t);e!==void 0&&(e<=1?(this.entityRefs.delete(t),t.release()):this.entityRefs.set(t,e-1),this.save())}getProxy(t){const e=t;let n=this._proxies.get(e);return n===void 0&&(n=Ze(this,this.key,t,this._notifier,this._queryClient),this._proxies.set(e,n)),n}get proxy(){return this._proxies.values().next().value}satisfiesDef(t){return this.satisfiedDefs.has(t)?!0:Ye(this.data,t)?(this.satisfiedDefs.add(t),!0):!1}save(){this._queryClient.entityMap.save(this)}notify(){this._notifier.notify()}consume(){this._notifier.consume()}}function Xe(i,t,e){const n=[];for(const s of i){if(typeof s!="object"||s===null)continue;const r=S.get(s);if(r===void 0)continue;const o=e.entityMap.getEntity(r);o!==void 0&&o.satisfiesDef(t)&&n.push(s)}return n}function Ze(i,t,e,n,s){const r=e.shape??{},o=e,a=o._methods,c=o._entityClass,f=o._entityConfig,l=c?c.prototype:yt.prototype;e.typenameField;const d=new Map,y=new Map,v=()=>({__entityRef:t});let p;f?.hasSubscribe&&a&&"__subscribe"in a&&(p=b.relay(w=>{const h=C=>{C.__eventSource=t,s.applyMutationEvent(C)},m=a.__subscribe.call(g,h);return w.value=g,m}));let g;const E=Object.keys(r);if(E.includes("__typename")||E.push("__typename"),a)for(const w of Object.keys(a))E.includes(w)||E.push(w);let N,x=E;function M(){const w=i._extraMethods;if(w!==N){if(N=w,x=E.slice(),w!==void 0)for(const m of Object.keys(w))x.includes(m)||x.push(m);const h=i._extraGetters;if(h!==void 0)for(const m of Object.keys(h))x.includes(m)||x.push(m)}return x}const R={getPrototypeOf(){return l},get(w,h){if(typeof h=="symbol")return;if(h==="toJSON")return v;if(h==="__context")return s.getContext();if(h==="__typename")return i.typename;if(p?.value,n.consume(),typeof h=="string"){const C=i._extraGetters;if(C!==void 0&&h in C)return C[h]();const A=i._extraMethods;if(A!==void 0&&h in A){let O=d.get(h);return O||(O=A[h].bind(g),d.set(h,O)),O}if(a&&h in a){let O=d.get(h);return O||(O=b.reactiveMethod(g,a[h].bind(g)),d.set(h,O)),O}}const m=i.data[h];if(typeof m=="object"&&m!==null&&X.has(m))return I(m.getValue());if(Array.isArray(m)&&typeof h=="string"){const C=r[h];if(C instanceof _&&(C.mask&u.ARRAY)!==0){const A=C.shape;if(A instanceof _&&(A.mask&u.ENTITY)!==0){const O=A.typenameValue;if(O!==void 0){const Rt=s.getEntityDefsForTypename(O);if(Rt!==void 0&&Rt.length>1){const tt=y.get(h);if(tt!==void 0&&tt.source===m)return I(tt.filtered);const Ot=Xe(m,A,s);return y.set(h,{source:m,filtered:Ot}),I(Ot)}}}}return I(m)}return I(m)},set(){return!1},has(w,h){if(h==="__typename")return!0;if(typeof h=="string"){const m=i._extraGetters;if(m&&h in m)return!0;const C=i._extraMethods;if(C&&h in C||a&&h in a)return!0}return h in r},ownKeys(){return M()},getOwnPropertyDescriptor(w,h){if(h==="__typename")return{enumerable:!0,configurable:!0,value:i.typename,writable:!1};if(h in r)return{enumerable:!0,configurable:!0,value:R.get(w,h,g),writable:!1};if(typeof h=="string"){const m=i._extraGetters;if(m&&h in m)return{enumerable:!0,configurable:!0,value:R.get(w,h,g),writable:!1};const C=i._extraMethods;if(C&&h in C)return{enumerable:!0,configurable:!0,value:R.get(w,h,g),writable:!1};if(a&&h in a)return{enumerable:!1,configurable:!0,value:R.get(w,h,g),writable:!1}}}};return g=new Proxy({},R),S.set(g,t),b.setScopeOwner(g,s),g}class ti{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,e,n,s){let r=this.instances.get(t);if(r===void 0){const o=n.idField;if(o===void 0)throw new Error(`Entity id field is required ${n.typenameValue}`);const a=e[o];if(typeof a!="string"&&typeof a!="number")throw new Error(`Entity id must be string or number: ${n.typenameValue}`);const c=n;r=new Je(t,n.typenameValue,a,o,e,s),r._entityCache=c._entityCache,this.instances.set(t,r)}return r.parseId=s.currentParseId,r}remove(t){this.instances.delete(t)}save(t){let e;if(t.entityRefs){e=new Set;for(const n of t.entityRefs.keys())e.add(n.key)}this.persistEntity(t.key,t.data,e)}}class wt{onlineSignal;manualOverride=void 0;eventListenersAttached=!1;constructor(t){const e=t??this.detectOnlineStatus();this.onlineSignal=b.signal(e),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=b.signal(!0);get isOnline(){return!0}setNetworkStatus(t){}clearManualOverride(){}getOnlineSignal(){return Ct.onlineSignal}destroy(){}}const re=new wt,ei=b.context(re);function bt(i,t=typeof window>"u"){let e;i===!1?e=0:i===void 0||i===!0?e=t?0:3:typeof i=="number"?e=i:e=i.retries;const n=typeof i=="object"&&i.retryDelay?i.retryDelay:s=>1e3*Math.pow(2,s);return{retries:e,retryDelay:n}}class oe{static cache;params;config;constructor(){return lt(this)}}class ii extends oe{method="GET";path;searchParams;body;headers;requestOptions;loadNext;getStorageKey(){return`${this.method??"GET"}:${this.path??""}`}async send(){return this.executeRequest()}resolveLoadNext(){const e=(this.getLoadNext?this.getLoadNext():void 0)??this.rawLoadNext;if(e===void 0)return;const n={params:this.params??{},result:this.resultData};return{url:e.url!==void 0?j(e.url,n):void 0,searchParams:e.searchParams!==void 0?j(e.searchParams,n):void 0}}hasNext(){const t=this.resolveLoadNext();if(t===void 0)return!1;if(t.url!==void 0&&t.url!==null)return!0;if(t.searchParams!==void 0){const e=Object.keys(t.searchParams);if(e.length===0)return!1;for(const n of e)if(t.searchParams[n]===void 0||t.searchParams[n]===null)return!1;return!0}return!1}async sendNext(){const t=this.resolveLoadNext();if(t===void 0)throw new Error("loadNext is not configured for this query");return this.executeRequest(t)}async executeRequest(t){const e=t?.url??(this.getPath?this.getPath():this.path),n=this.getMethod?this.getMethod():this.method,s=this.getSearchParams?this.getSearchParams():this.searchParams,r=t?.searchParams?{...s,...t.searchParams}:s,o=this.getBody?this.getBody():this.body,a=this.getRequestOptions?this.getRequestOptions():this.requestOptions;if(!e)throw new Error("RESTQuery requires a path. Define `path` as a field or override `getPath()`.");let c=e;if(r){const N=new URLSearchParams;for(const M in r){const R=r[M];R!=null&&N.append(M,String(R))}const x=N.toString();x&&(c+="?"+x)}const f=ft(a?.baseUrl)??ft(this.context.baseUrl),l=f?`${f}${c}`:c,{baseUrl:d,signal:y,...v}=a??{},g=o||this.headers?{...o?{"Content-Type":"application/json"}:void 0,...this.headers}:void 0,E=await this.context.fetch(l,{method:n,headers:g,body:o?JSON.stringify(o):void 0,signal:this.signal,...v});return this.response=E,E.json()}}const Mt=new WeakMap;class Z{constructor(t,e){this.captured=e,this.statics=t}statics;createExecutionContext(t,e){return nt(this.captured,t,e)}resolveOptions(t){const{methods:e}=this.captured,n=e.getConfig?e.getConfig.call(t):t.config,s=bt(n?.retry);return{config:n,retryConfig:s}}static for(t){let e=Mt.get(t);if(e!==void 0)return e;const n=new t,s=$t(n),r=String(s.methods.getStorageKey.call(s.fields)),o=s.fields.result,a=o instanceof _?o:Zt.object(o),c=(a.mask&u.ENTITY)!==0,f=t.cache,l=s.fields.loadNext,d=typeof s.methods.sendNext=="function",y=c?a:new _(u.ENTITY|u.OBJECT,a.shape,void 0,void 0,r,ut);return e=new Z({id:r,shape:y,cache:f,rawLoadNext:l,hasSendNext:d,isEntityResult:c},s),Mt.set(t,e),e}}const ni=(i,t)=>{const e=Z.for(i);return xt(e,t)};function si(i,...t){const e=Z.for(i),n=b.getContext(_e);if(n===void 0)throw new Error("QueryClient not found");const s=t[0];return n.getQuery(e,s)}function ae(i,t){return new Promise((e,n)=>{if(t?.aborted){n(t.reason);return}const s=setTimeout(e,i);t?.addEventListener("abort",()=>{clearTimeout(s),n(t.reason)},{once:!0})})}async function at(i,t,e){const n=Math.max(0,t.retries);let s;for(let r=0;r<=n;r++){e?.throwIfAborted();try{return await i()}catch(o){if(s=o,r>=n)throw o;await ae(t.retryDelay(r),e)}}throw s}class ri{def;queryKey;storageKey=-1;relay;queryClient;initialized=!1;updatedAt=void 0;params=void 0;unsubscribe=void 0;_relayState=void 0;wasPaused=!1;currentParams=void 0;debounceTimer=void 0;config=void 0;retryConfig=bt(void 0);_lastResponse=void 0;_abortController=void 0;_executionCtx=void 0;_executionCtxKey=-1;rootEntity;_extraMethods={};_queryId=0;get key(){return this.queryKey}get relayState(){return this._relayState}constructor(t,e,n,s){this.def=t,this.queryClient=e,this.queryKey=n,this.params=s,this._extraMethods={__refetch:this.refetch},t.statics.hasSendNext&&(this._extraMethods.__loadNext=this.loadNext);const r=Pt(s);this._queryId=r!==void 0?D.hashValue(r):0,this.relay=b.relay(o=>{this._relayState=o;const a=()=>{clearTimeout(this.debounceTimer),this.debounceTimer=void 0,this._abortController?.abort(),this._abortController=void 0,this._loadNextAbort?.abort(),this._loadNextAbort=void 0,this._loadNextPromise=void 0,this.unsubscribe?.(),this.unsubscribe=void 0;const f=this.config?.gcTime??Lt.DEFAULT_GC_TIME;this.queryClient.gcManager.schedule(this.queryKey,f,z.Query)},c=(f=!1)=>{const{wasPaused:l,isPaused:d,initialized:y}=this;if(this.wasPaused=d,d&&!l&&y){a();return}const v=Pt(this.params),p=xt(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.setupSubscription(),(this.config?.refreshStaleOnReconnect??!0)&&this.isStale&&this.runDebounced()):g&&(this.setupSubscription(),this.runDebounced()):(this.queryClient.activateQuery(this),this.initialize())};return c(!0),{update:c,deactivate:a}},{desc:`Query(${t.statics.id})`})}applyData(t,e,n=!1,s){const r=this.def;return this.rootEntity=this.queryClient.parseAndApplyRootEntity(t,this._queryId,r.statics.shape,e,n,s),this.rootEntity._extraMethods===void 0&&(this.rootEntity._extraMethods=this._extraMethods,this.rootEntity._extraGetters={__hasNext:()=>this.hasNext,__isLoadingNext:()=>this._loadNextPromise!==void 0}),this.rootEntity.getProxy(r.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,e=this.relayState;this.initialized=!0;let n;try{n=await t.loadCachedQuery(this.def,this.storageKey),n!==void 0&&(this.updatedAt=n.updatedAt,e.value=this.applyData(n.value,!1,!1,n.preloadedEntities))}catch(s){t.store.deleteQuery(this.storageKey),t.getContext().log?.warn?.("Failed to initialize query, the query cache may be corrupted or invalid",s)}if(!this.isPaused)try{if(n!==void 0&&this.setupSubscription(),n===void 0||this.isStale){if(await ae(0),this.isPaused)return;this.runQueryImmediately()}}catch(s){e.setError(s)}}setupSubscription(){this.unsubscribe?.(),this.unsubscribe=void 0;const t=this.config?.subscribe;if(!t)return;const e=this._executionCtx;this.unsubscribe=t.call(e,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.rawLoadNext=this.def.statics.rawLoadNext),this._executionCtx.response=this._lastResponse,this.resolveAndApplyOptions(),this._executionCtx}resolveAndApplyOptions(){const t=this.def.resolveOptions(this._executionCtx);this.config=t.config,this.retryConfig=t.retryConfig}async runQuery(){const t=this.def;if(this.isPaused)throw new Error("Query is paused due to network status");const e=this.getOrCreateExecutionContext(),{send:n}=t.captured.methods,s=this._abortController?.signal;return e.signal=s,at(async()=>{const r=await n.call(e);this._lastResponse=e.response,this._executionCtx.response=this._lastResponse,this.resolveAndApplyOptions(),this.updatedAt=Date.now();const o=this.applyData(r,!0);return this.saveQueryMetadata(),this.unsubscribe===void 0&&this.setupSubscription(),o},this.retryConfig,s)}runQueryImmediately(){this._abortController?.abort(),this._abortController=new AbortController,this._loadNextAbort?.abort(),this._loadNextAbort=void 0,this._loadNextPromise=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);_loadNextPromise=void 0;_loadNextAbort=void 0;loadNext=()=>{if(this.updatedAt===void 0)throw new Error("Cannot call __loadNext before initial data has loaded");return this._loadNextPromise!==void 0?this._loadNextPromise:(queueMicrotask(()=>this.rootEntity?.notify()),this._loadNextPromise=this.runLoadNext().then(t=>(this._loadNextPromise=void 0,this.rootEntity?.notify(),t),t=>{throw this._loadNextPromise=void 0,this.rootEntity?.notify(),t}),this._loadNextPromise)};get hasNext(){if(this.rootEntity===void 0||!this._executionCtx)return!1;const t=this.def.captured.methods.hasNext;return t?(this._executionCtx.resultData=this.rootEntity.data,t.call(this._executionCtx)):!1}async runLoadNext(){const t=this.def;this._loadNextAbort=new AbortController;const e=this._loadNextAbort.signal,n=this.getOrCreateExecutionContext();n.signal=e,n.resultData=this.rootEntity.data;const s=t.captured.methods.sendNext;return at(async()=>{const r=await s.call(n);this._lastResponse=n.response,this._executionCtx.response=this._lastResponse,this.resolveAndApplyOptions(),this.updatedAt=Date.now();const o=this.applyData(r,!0,!0);return this.saveQueryMetadata(),o},this.retryConfig,e)}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??L.Online;if(t===L.Always)return!1;const e=this.queryClient.networkManager.getOnlineSignal().value;switch(t){case L.Online:return!e;case L.OfflineFirst:return!e&&this.updatedAt===void 0;default:return!1}}}class oi{def;queryClient;_lastResponse;_inFlight=!1;task;constructor(t,e){this.def=t,this.queryClient=e,this.task=this.createTask()}createTask(){return b.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 e=await this.executeWithRetry(t),n=this.validateResponse(e);return this.processEffects(t,n),n}finally{this._inFlight=!1}},{desc:`Mutation(${this.def.id})`})}validateResponse(t){const e=this.def.responseShape;if(!(e instanceof _))return t;const n=this.queryClient.getContext().log?.warn??(()=>{}),s=new ot;return s.reset(void 0,void 0,n),ee(t,e,s)}processEffects(t,e){let n;if(this.def.hasGetEffects){const r=nt(this.def.captured,t??{},this.queryClient.getContext());r.result=e,r.response=this._lastResponse,n=r.getEffects()}else if(this.def.effects!==void 0){const r={params:t,result:e};n=j(this.def.effects,r)}if(n===void 0)return;const s=this.queryClient;et(n.creates,"create",s),et(n.updates,"update",s),et(n.deletes,"delete",s)}executeWithRetry(t){const e=bt(this.def.config?.retry,!0);return at(async()=>{const n=nt(this.def.captured,t??{},this.queryClient.getContext()),s=await this.def.captured.methods.send.call(n);return this._lastResponse=n.response,s},e)}}function ai(i){return typeof i=="string"?i:U(i).typenameValue}function et(i,t,e){if(i)for(const[n,s]of i){const r=ai(n);r!==void 0&&e.applyMutationEvent({type:t,typename:r,data:s})}}const ce="__eventSource";function fe(i){return{field:i,segments:i.indexOf(".")!==-1?i.split("."):void 0}}function ci(i){return i.map(fe)}function fi(i,t){if(t.segments===void 0)return i[t.field];let e=i;for(const n of t.segments){if(e==null)return;e=e[n]}return e}function ue(i,t){const e=[];for(let n=0;n<t.length;n++){const s=t[n],r=fi(i,s);if(r===void 0)return;e.push(s.field,r)}return D.hashValue(e)}function ui(i,t){if(i===void 0)return;const e=new Map;for(const[n,s]of i){const r=s.slice().sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0),o=[];let a=!0;for(const[c,f]of r){let l;if(Vt(f)){const d=Kt(f);l=ht(d,t)}else l=f;if(l===void 0){a=!1;break}o.push(c,l)}a&&e.set(n,D.hashValue(o))}return e.size>0?e:void 0}function Ft(i,t){const e=i.get(t);if(e!==void 0)return e.map(([n])=>n).sort()}class di{fields;fieldPaths;_bindings=new Map;constructor(t){this.fields=t,this.fieldPaths=t.map(fe)}register(t,e){let n=this._bindings.get(t);n===void 0&&(n=new Set,this._bindings.set(t,n)),n.add(e)}unregister(t,e){const n=this._bindings.get(t);n!==void 0&&(n.delete(e),n.size===0&&this._bindings.delete(t))}getMatching(t){return this._bindings.get(t)}get isEmpty(){return this._bindings.size===0}}function Tt(i){return D.hashValue(i)}class li{_groups=new Map;getOrCreateGroup(t){const e=Tt(t);let n=this._groups.get(e);return n===void 0&&(n=new di(t),this._groups.set(e,n)),n}register(t,e,n){this.getOrCreateGroup(e).register(t,n)}unregister(t,e,n){const s=Tt(e),r=this._groups.get(s);r!==void 0&&(r.unregister(t,n),r.isEmpty&&this._groups.delete(s))}registerBinding(t,e){const n=t._constraintHashes.get(e);if(n===void 0)return;const s=Ft(t._constraintFieldRefs,e);s!==void 0&&this.register(n,s,t)}unregisterBinding(t,e){const n=t._constraintHashes.get(e);if(n===void 0)return;const s=Ft(t._constraintFieldRefs,e);s!==void 0&&this.unregister(n,s,t)}routeEvent(t,e,n,s,r,o){for(const a of this._groups.values()){const c=ue(e,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,s,r,o)}}}function kt(i){const t=new Set;for(const e of i)if(typeof e=="object"&&e!==null){const n=k(e);n!==void 0&&t.add(n)}return t}class de{_queryClient;_parent;_constraintHashes;_entityDefsByTypename;_constraintFieldRefs;instance;constructor(t,e,n,s,r,o){this._queryClient=n,this._parent=s,this._constraintHashes=r,this._constraintFieldRefs=e,this.instance=o,this._entityDefsByTypename=new Map;for(const a of t)a.typenameValue!==void 0&&this._entityDefsByTypename.set(a.typenameValue,a);X.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,e,n,s,r){const o=this._entityDefsByTypename.get(t);if(o===void 0)return;const a=this._queryClient.entityMap.getEntity(e);if(n==="delete"){const f=a!==void 0?a.getProxy(o):r;f!==void 0&&(this.instance.onEvent(e,f,r??a?.data??{},"delete"),s?.());return}if(a===void 0||!a.satisfiesDef(o))return;s?.();const c=a.getProxy(o);this.instance.onEvent(e,c,a.data,n)}destroy(){this._queryClient.unregisterLiveCollection(this);const t=this._parent.liveCollections,e=t.indexOf(this);e!==-1&&t.splice(e,1)}}class hi{_notifier;_items;_keys;_outputSignal;_queryClient;_parent;constructor(t,e,n,s,r,o){this._notifier=b.notifier(),this._items=n,this._keys=kt(n),this._queryClient=t,this._parent=e;const a=s!==void 0&&r!==void 0,c=o!==void 0;(a||c)&&(this._outputSignal=b.reactiveSignal(()=>{this._notifier.consume();let f=this._items;if(a){const l=[];for(const d of f){if(typeof d!="object"||d===null){l.push(d);continue}const y=k(d);if(y===void 0){l.push(d);continue}const v=t.entityMap.getEntity(y);if(v===void 0){l.push(d);continue}v.consume(),ue(v.data,s)===r&&l.push(d)}f=l}return c&&(f=(f===this._items?f.slice():f).sort(o)),f}))}onEvent(t,e,n,s){switch(s){case"create":this.add(t,e);break;case"update":!this.has(t)&&e!==void 0&&this.add(t,e);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,e){if(this._keys.has(t))return!1;this._keys.add(t),this._items.push(e);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 e=this._findIndex(t);e!==-1&&this._items.splice(e,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 e=this._items,n=Array.isArray(t)?t:[];this._items=n,this._keys=kt(n);for(const s of n)if(typeof s=="object"&&s!==null){const r=k(s);if(r!==void 0){const o=this._queryClient.entityMap.getEntity(r);o!==void 0&&this._parent.addChildRef(o)}}for(const s of e)if(typeof s=="object"&&s!==null){const r=k(s);if(r!==void 0){const o=this._queryClient.entityMap.getEntity(r);o!==void 0&&this._parent.removeChildRef(o)}}this._notifier.notify()}append(t){if(Array.isArray(t))for(const e of t){if(typeof e!="object"||e===null)continue;const n=k(e);n!==void 0&&this.add(n,e)}}_findIndex(t){for(let e=0;e<this._items.length;e++){const n=this._items[e];if(typeof n=="object"&&n!==null&&k(n)===t)return e}return-1}}class yi{_notifier;_value;_createdKeys;_deletedKeys;_queryClient;_parent;_onCreate;_onUpdate;_onDelete;constructor(t,e,n,s,r,o){this._notifier=b.notifier(),this._value=n,this._createdKeys=new Set,this._deletedKeys=new Set,this._queryClient=t,this._parent=e,this._onCreate=s,this._onUpdate=r,this._onDelete=o}onEvent(t,e,n,s){switch(s){case"create":if(this._createdKeys.has(t))return;this._createdKeys.add(t),this._value=this._onCreate(this._value,e);break;case"update":this._value=this._onUpdate(this._value,e??n);break;case"delete":if(this._deletedKeys.has(t))return;this._deletedKeys.add(t),this._value=this._onDelete(this._value,e??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 le(i,t,e,n,s){let r=i.constraintFieldRefs;if(r===void 0){r=new Map;for(const f of i.entityDefs){const l=f.typenameValue;l!==void 0&&r.set(l,[[ce,e.key]])}}const o=ui(r,n)??new Map;let a;if(i.type===H.Array){let f,l;if(i.constraintFieldRefs!==void 0&&o.size>0&&o.size===1)for(const[d]of i.constraintFieldRefs){const y=o.get(d);if(y!==void 0){l=y;const v=i.constraintFieldRefs.get(d);v!==void 0&&(f=ci(v.map(([p])=>p)));break}}a=new hi(s,e,Array.isArray(t)?t:[],f,l,i.sort)}else a=new yi(s,e,t,i.onCreate,i.onUpdate,i.onDelete);const c=new de(i.entityDefs,r,s,e,o,a);return e.liveCollections.push(c),s.registerLiveCollection(c),c}const he=Object.entries,ye=Object.prototype;function it(i,t,e,n=!1){const s=i.queryClient;s.currentParseId++;const r=i.seen,o=new Map;return{data:Q(t,r,s,e,o,n),entityRefs:o}}function Q(i,t,e,n,s,r){if(typeof i!="object"||i===null)return i;const o=t.get(i);if(o!==void 0)return pi(o,t,e,n,s,r);if(Array.isArray(i)){for(let a=0;a<i.length;a++){const c=i[a];typeof c=="object"&&c!==null&&!(c instanceof B)&&!S.has(c)&&(i[a]=Q(c,t,e,n,s,r))}return i}if(Object.getPrototypeOf(i)===ye&&!S.has(i)){const a=i;for(const c of Object.keys(a)){const f=a[c];typeof f=="object"&&f!==null&&!(f instanceof B)&&!S.has(f)&&(a[c]=Q(f,t,e,n,s,r))}}return i}function pe(i){return typeof i=="object"&&i!==null&&!(i instanceof B)&&!S.has(i)}function pi(i,t,e,n,s,r){const{key:o,data:a,shape:c,rawKeys:f}=i,l=c.shape,d=e.prepareEntity(o,a,c),y=d.data,v=y!==a,p=v&&f!==void 0&&d.entityRefs!==void 0?new Map(d.entityRefs):new Map;if(v?(ge(l,a,y,f,d,y,t,e,n,p,r),d.notify()):ve(l,a,d,a,t,e,n,p,r),r&&d.liveCollections.length>0)for(const E of d.liveCollections){const N=E.instance.getRawValue();if(Array.isArray(N))for(const x of N){if(typeof x!="object"||x===null)continue;const M=S.get(x);if(M===void 0)continue;const R=e.entityMap.getEntity(M);R!==void 0&&p.set(R,(p.get(R)??0)+1)}}d.setChildRefs(p.size>0?p:void 0,n);const g=d.getProxy(c);return s.set(d,(s.get(d)??0)+1),g}function ge(i,t,e,n,s,r,o,a,c,f,l){for(const[d,y]of he(i))if(!(n!==void 0&&!n.has(d)))if(pe(t[d])&&(t[d]=Q(t[d],o,a,c,f,l)),y instanceof _&&y._liveConfig!==void 0){const v=e[d];v instanceof de?l?v.append(t[d]):v.reset(t[d]):e[d]=le(y._liveConfig,t[d],s,r,a)}else{const v=t[d],p=e[d];if(ct(v)&&ct(p)){const g=y instanceof _&&y.shape!==void 0?y.shape:void 0;if(g!==void 0)ge(g,v,p,void 0,s,r,o,a,c,f,l);else for(const E of Object.keys(v))p[E]=v[E];e[d]=p}else e[d]=v}}function ve(i,t,e,n,s,r,o,a,c){for(const[f,l]of he(i))if(f in t)if(pe(t[f])&&(t[f]=Q(t[f],s,r,o,a,c)),l instanceof _&&l._liveConfig!==void 0)t[f]=le(l._liveConfig,t[f],e,n,r);else{const d=t[f];if(ct(d)){const y=l instanceof _&&l.shape!==void 0?l.shape:void 0;y!==void 0&&ve(y,d,e,n,s,r,o,a,c)}}}function ct(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)&&Object.getPrototypeOf(i)===ye&&!S.has(i)}function ft(i){if(i!==void 0)return typeof i=="string"?i:typeof i=="function"?i():i.value}function gi(i){return b.isSignal(i)}function Pt(i){if(i===void 0)return;const t={};for(const[e,n]of Object.entries(i))gi(n)?t[e]=n.value:t[e]=n;return t}const xt=(i,t)=>D.hashValue([i.statics.id,t]);class vi{constructor(t,e={fetch,log:console},n,s){this.context=e,this.isServer=typeof window>"u",this.store=t,this.gcManager=s??(this.isServer?new jt:new qt(this.handleEviction,this.context.evictionMultiplier)),this.networkManager=n??new wt,this.entityMap=new ti((r,o,a)=>this.store.saveEntity(r,o,a)),this.store.purgeStaleQueries?.()}entityMap;queryInstances=new Map;mutationInstances=new Map;gcManager;networkManager;isServer;store;currentParseId=0;typenameRegistry=new Map;constraintRegistry=new Map;mergedDefCache=new Map;getContext(){return this.context}registerEntityDef(t){const e=t.typenameValue;if(e===void 0||t._entityClass===void 0)return;const n=this.typenameRegistry.get(e);if(n!==void 0){if(n.indexOf(t)!==-1)return;n.push(t),this.mergedDefCache.delete(e),this.getMergedDef(e)}else this.typenameRegistry.set(e,[t])}getEntityDefsForTypename(t){return this.typenameRegistry.get(t)}getMergedDef(t){let e=this.mergedDefCache.get(t);if(e!==void 0)return e;const n=this.typenameRegistry.get(t);if(n!==void 0)return e=_.merge(n),this.mergedDefCache.set(t,e),e}saveQueryData(t,e,n,s,r){const o=r!==void 0&&r.size>0?new Set([...r.keys()].map(a=>a.key)):void 0;this.store.saveQuery(t,e,n,s,o)}activateQuery(t){const{def:e,queryKey:n,storageKey:s,config:r}=t;this.store.activateQuery(e,s);const o=r?.gcTime??Lt.DEFAULT_GC_TIME;this.gcManager.cancel(n,o)}loadCachedQuery(t,e){return this.store.loadQuery(t,e)}getQuery(t,e){const n=xt(t,e);let s=this.queryInstances.get(n);return s===void 0&&(s=new ri(t,this,n,e),this.queryInstances.set(n,s)),s.relay}getMutation(t){const e=t.id;let n=this.mutationInstances.get(e);return n===void 0&&(n=new oi(t,this),this.mutationInstances.set(e,n)),n.task}parseData(t,e,n){const s=this.context.log?.warn??(()=>{}),r=new ot;return r.reset(this,n,s),{data:ee(t,e,r),ctx:r}}applyRefs(t,e=!0,n=!1){return it(t.ctx,t.data,e,n)}parseAndApplyRootEntity(t,e,n,s,r=!1,o){typeof n.idField=="symbol"&&typeof t=="object"&&t!==null&&!("__entityRef"in t)&&(t[ut]=e);const a=this.parseData(t,n,o),c=it(a.ctx,a.data,s,r),f=S.get(c.data);return this.entityMap.getEntity(f)}prepareEntity(t,e,n){return this.registerEntityDef(n),this.entityMap.getOrCreateEntity(t,e,n,this)}applyMutationEvent(t){const{type:e,typename:n}=t,s=this.getMergedDef(n);if(s===void 0)return;const r=s.idField;if(r===void 0||typeof r=="symbol")return;const o=t.data,a=t.id!==void 0?t.id:e==="delete"&&(typeof o=="string"||typeof o=="number")?o:o[r];if(a===void 0)return;const c=D.hashValue([n,a]),f=t.__eventSource,l=typeof o=="object"&&o!==null?o:{},d=this.entityMap.getEntity(c);if(e==="delete"){const g=d!==void 0?d.data:l;this.routeEvent(n,g,c,e,f,void 0,g);return}try{const g=this.context.log?.warn??(()=>{}),E=new ot;E.reset(this,void 0,g,!0);const N=Be(l,s,E);it(E,N,!0)}catch(g){if(this.context.log?.warn?.("Failed to apply mutation event",g),d===void 0){const E=this.entityMap.getEntity(c);E!==void 0&&E.evict()}return}const y=this.entityMap.getEntity(c);if(y===void 0)return;this.entityMap.save(y);const v=d===void 0;let p=!1;this.routeEvent(n,y.data,c,e,f,()=>{p=!0}),v&&!p&&y.evict()}handleEviction=(t,e)=>{if(e===z.Query){const s=this.queryInstances.get(t);if(s===void 0)return;s.rootEntity?.evict(),this.queryInstances.delete(t);return}const n=this.entityMap.getEntity(t);n!==void 0&&n.evict()};getOrCreateMatcher(t){let e=this.constraintRegistry.get(t);return e===void 0&&(e=new li,this.constraintRegistry.set(t,e)),e}registerLiveCollection(t){for(const[e,n]of t._entityDefsByTypename)this.registerEntityDef(n),this.getOrCreateMatcher(e).registerBinding(t,e)}unregisterLiveCollection(t){for(const e of t._entityDefsByTypename.keys()){const n=this.constraintRegistry.get(e);n!==void 0&&n.unregisterBinding(t,e)}}routeEvent(t,e,n,s,r,o,a){const c=this.constraintRegistry.get(t);if(c===void 0)return;const f=r!==void 0?{...e,[ce]:r}:e;c.routeEvent(t,f,n,s,o,a)}destroy(){this.gcManager.destroy(),this.networkManager.destroy(),this.queryInstances.clear(),this.mutationInstances.clear(),this.constraintRegistry.clear(),this.typenameRegistry.clear(),this.mergedDefCache.clear()}}const _e=b.context(void 0);exports.ARRAY_KEY=K;exports.Entity=yt;exports.GcManager=qt;exports.LiveFieldConfig=q;exports.LiveFieldType=H;exports.Mask=u;exports.NetworkManager=wt;exports.NetworkManagerContext=ei;exports.NetworkMode=L;exports.NoOpGcManager=jt;exports.NoOpNetworkManager=Ct;exports.QUERY_ID=ut;exports.Query=oe;exports.QueryClient=vi;exports.QueryClientContext=_e;exports.RECORD_KEY=$;exports.RESTQuery=ii;exports.ValidatorDef=_;exports.createDefinitionProxy=lt;exports.defaultNetworkManager=re;exports.draft=Ke;exports.extractDefinition=$t;exports.fetchQuery=si;exports.queryKeyForClass=ni;exports.registerFormat=_t;exports.resolveBaseUrl=ft;exports.t=Zt;
2
- //# sourceMappingURL=QueryClient-qi3bR0eD.js.map