fetchium 0.3.1 → 0.4.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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/development/QueryClient-D_e76rYS.js +2 -0
- package/dist/cjs/development/QueryClient-D_e76rYS.js.map +1 -0
- package/dist/cjs/development/index.js +1 -1
- package/dist/cjs/{production/mutation-CjSajlTU.js → development/mutation-bq06T6Wg.js} +2 -2
- package/dist/cjs/{production/mutation-CjSajlTU.js.map → development/mutation-bq06T6Wg.js.map} +1 -1
- package/dist/cjs/development/react/index.js +1 -1
- package/dist/cjs/development/rest/index.js +1 -1
- package/dist/cjs/development/rest/index.js.map +1 -1
- package/dist/cjs/development/topic/index.js +1 -1
- package/dist/cjs/production/QueryClient-BPdrfgtE.js +2 -0
- package/dist/cjs/production/QueryClient-BPdrfgtE.js.map +1 -0
- package/dist/cjs/production/index.js +1 -1
- package/dist/cjs/{development/mutation-OJNwoJcf.js → production/mutation-BVVlcTsK.js} +2 -2
- package/dist/cjs/{development/mutation-OJNwoJcf.js.map → production/mutation-BVVlcTsK.js.map} +1 -1
- package/dist/cjs/production/react/index.js +1 -1
- package/dist/cjs/production/rest/index.js +1 -1
- package/dist/cjs/production/rest/index.js.map +1 -1
- package/dist/cjs/production/topic/index.js +1 -1
- package/dist/esm/QueryResult.d.ts +5 -5
- package/dist/esm/QueryResult.d.ts.map +1 -1
- package/dist/esm/development/{QueryClient-DfxP7pt2.js → QueryClient-CkO_s9Uh.js} +347 -338
- package/dist/esm/development/QueryClient-CkO_s9Uh.js.map +1 -0
- package/dist/esm/development/index.js +2 -2
- package/dist/esm/development/{mutation-DZAq7Pbu.js → mutation-SZTEGudR.js} +2 -2
- package/dist/esm/development/{mutation-DZAq7Pbu.js.map → mutation-SZTEGudR.js.map} +1 -1
- package/dist/esm/development/react/index.js +1 -1
- package/dist/esm/development/rest/index.js +8 -8
- package/dist/esm/development/rest/index.js.map +1 -1
- package/dist/esm/development/topic/index.js +1 -1
- package/dist/esm/fieldRef.d.ts.map +1 -1
- package/dist/esm/production/{QueryClient-DrWSXg0y.js → QueryClient--PrsE8Kj.js} +286 -277
- package/dist/esm/production/QueryClient--PrsE8Kj.js.map +1 -0
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/{mutation-B8dmX5lz.js → mutation-20F2qe90.js} +2 -2
- package/dist/esm/production/{mutation-B8dmX5lz.js.map → mutation-20F2qe90.js.map} +1 -1
- package/dist/esm/production/react/index.js +1 -1
- package/dist/esm/production/rest/index.js +8 -8
- package/dist/esm/production/rest/index.js.map +1 -1
- package/dist/esm/production/topic/index.js +1 -1
- package/dist/esm/rest/RESTQuery.d.ts +2 -0
- package/dist/esm/rest/RESTQuery.d.ts.map +1 -1
- package/dist/esm/rest/RESTQueryAdapter.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/docs/api/fetchium.md +16 -15
- package/plugin/docs/core/queries.md +10 -3
- package/plugin/docs/reference/rest-queries.md +1 -1
- package/dist/cjs/development/QueryClient-BefSCMoE.js +0 -2
- package/dist/cjs/development/QueryClient-BefSCMoE.js.map +0 -1
- package/dist/cjs/production/QueryClient-rbPYznie.js +0 -2
- package/dist/cjs/production/QueryClient-rbPYznie.js.map +0 -1
- package/dist/esm/development/QueryClient-DfxP7pt2.js.map +0 -1
- package/dist/esm/production/QueryClient-DrWSXg0y.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as r, E as s, G as t, L as o, a as n, M as i, N as M, b as g, c as u, d as y, e as f, Q as C, f as N, g as Q, h as d, R as k, i as l, j as p, k as m, q as E, r as R, t as w } from "./QueryClient
|
|
1
|
+
import { A as r, E as s, G as t, L as o, a as n, M as i, N as M, b as g, c as u, d as y, e as f, Q as C, f as N, g as Q, h as d, R as k, i as l, j as p, k as m, q as E, r as R, t as w } from "./QueryClient--PrsE8Kj.js";
|
|
2
2
|
import { Q as F } from "./QueryAdapter-Bu5UJjE4.js";
|
|
3
|
-
import { M as A, g as K, m as Y } from "./mutation-
|
|
3
|
+
import { M as A, g as K, m as Y } from "./mutation-20F2qe90.js";
|
|
4
4
|
export {
|
|
5
5
|
r as ARRAY_KEY,
|
|
6
6
|
s as Entity,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getContext as h } from "signalium";
|
|
2
|
-
import { l as y, h as D, m as w, V as u, t as d } from "./QueryClient
|
|
2
|
+
import { l as y, h as D, m as w, V as u, t as d } from "./QueryClient--PrsE8Kj.js";
|
|
3
3
|
class x {
|
|
4
4
|
static adapter;
|
|
5
5
|
params;
|
|
@@ -55,4 +55,4 @@ export {
|
|
|
55
55
|
S as g,
|
|
56
56
|
C as m
|
|
57
57
|
};
|
|
58
|
-
//# sourceMappingURL=mutation-
|
|
58
|
+
//# sourceMappingURL=mutation-20F2qe90.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-
|
|
1
|
+
{"version":3,"file":"mutation-20F2qe90.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":";;AA+BO,MAAeA,EAAS;AAAA,EAC7B,OAAO;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAQT,cAAc;AACZ,WAAOC,EAAsB,IAAI;AAAA,EACnC;AACF;AAMA,MAAMC,wBAAuB,QAAA,GAEhBC,IAAsB,CAACC,MAAoC;AACtE,QAAMC,IAAiBH,EAAiB,IAAIE,CAAG;AAE/C,MAAIC,MAAmB;AACrB,UAAM,IAAI,MAAM,+BAA+B;AAGjD,SAAOA,IAAiB;AAC1B;AAMA,SAASC,EAAwBC,GAAuE;AACtG,MAAIC,IAASN,EAAiB,IAAIK,CAAa;AAE/C,MAAIC,MAAW;AACb,WAAOA;AAGT,MAAIC;AAEJ,QAAMC,IAAS,MAAoC;AACjD,QAAID,MAAuB;AACzB,aAAOA;AAGT,UAAME,IAAW,IAAIJ,EAAA,GACfK,IAAWC,EAAkBF,CAAQ,GACrC,EAAE,QAAAG,MAAWF,GAEbG,IAAK,YAAY,OAAOH,EAAS,QAAQ,eAAe,KAAKE,CAAM,CAAC,CAAC,IAErEE,IAAaF,EAAO,UAAU,CAAA,GAC9BG,IAAgBD,aAAsBE,IACxCF,IACAG,EAAE,OAAOH,CAAU,GACjBI,IAAcN,EAAO,QACrBO,IACJD,MAAgB,SACVA,aAAuBF,IAAeE,IAAcD,EAAE,OAAOC,CAAW,IAC1E,QAEAE,IAAgBf,EAAkC;AACxD,QAAI,CAACe;AACH,YAAM,IAAI;AAAA,QACR,mBAAmBf,EAAc,IAAI;AAAA,MAAA;AAKzC,WAAAE,IAAqB;AAAA,MACnB,IAAAM;AAAA,MACA,cAAAE;AAAA,MACA,eAAAI;AAAA,MACA,UAAAT;AAAA,MACA,mBAAmBE,EAAO,qBAAqB;AAAA,MAC/C,QAAQA,EAAO;AAAA,MACf,SAASA,EAAO;AAAA,MAChB,eAAe,OAAOF,EAAS,QAAQ,cAAe;AAAA,MACtD,cAAAU;AAAA,IAAA,GAGKb;AAAA,EACT;AAEA,SAAAP,EAAiB,IAAIK,GAAeG,CAAM,GACnCA;AACT;AAMO,SAASa,EACdhB,GAC8E;AAC9E,QAAMF,IAAiBC,EAAwBC,CAAa,GAEtDiB,IAAcC,EAAWC,CAAkB;AAEjD,MAAIF,MAAgB;AAClB,UAAM,IAAI,MAAM,uBAAuB;AAGzC,SAAOA,EAAY,YAAsBnB,GAAgB;AAC3D;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as v, o as U, f as O } from "../QueryClient
|
|
1
|
+
import { n as v, o as U, f as O } from "../QueryClient--PrsE8Kj.js";
|
|
2
2
|
import { Q as T } from "../QueryAdapter-Bu5UJjE4.js";
|
|
3
|
-
import { M as
|
|
3
|
+
import { M as N } from "../mutation-20F2qe90.js";
|
|
4
4
|
class P extends T {
|
|
5
5
|
_fetch;
|
|
6
6
|
_baseUrl;
|
|
@@ -71,25 +71,25 @@ class P extends T {
|
|
|
71
71
|
throw new Error("RESTQuery requires a path. Define `path` as a field or override `getPath()`.");
|
|
72
72
|
let l = r;
|
|
73
73
|
if (o) {
|
|
74
|
-
const
|
|
74
|
+
const g = new URLSearchParams();
|
|
75
75
|
for (const b in o) {
|
|
76
76
|
const u = o[b];
|
|
77
|
-
u != null &&
|
|
77
|
+
u != null && g.append(b, String(u));
|
|
78
78
|
}
|
|
79
|
-
const m =
|
|
79
|
+
const m = g.toString();
|
|
80
80
|
m && (l += "?" + m);
|
|
81
81
|
}
|
|
82
82
|
const f = i?.baseUrl ?? e.baseUrl, d = this.buildUrl(l, f), { baseUrl: p, signal: R, ...q } = i ?? {}, S = n || e.headers ? {
|
|
83
83
|
...n ? { "Content-Type": "application/json" } : void 0,
|
|
84
84
|
...e.headers
|
|
85
|
-
} : void 0,
|
|
85
|
+
} : void 0, y = await this._fetch(d, {
|
|
86
86
|
method: h,
|
|
87
87
|
headers: S,
|
|
88
88
|
body: n ? JSON.stringify(n) : void 0,
|
|
89
89
|
signal: s,
|
|
90
90
|
...q
|
|
91
91
|
});
|
|
92
|
-
return e.response =
|
|
92
|
+
return e.response = y, e.responseNotifier.notify(), y.json();
|
|
93
93
|
}
|
|
94
94
|
async sendMutation(e, s) {
|
|
95
95
|
const t = e, r = t.getPath ? t.getPath() : t.path, h = t.getMethod ? t.getMethod() : t.method, a = t.getBody ? t.getBody() : t.body, o = t.getRequestOptions ? t.getRequestOptions() : t.requestOptions;
|
|
@@ -122,7 +122,7 @@ class Q extends O {
|
|
|
122
122
|
return `${this.method ?? "GET"}:${this.path ?? ""}`;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
class B extends
|
|
125
|
+
class B extends N {
|
|
126
126
|
static adapter = P;
|
|
127
127
|
path;
|
|
128
128
|
baseUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/rest/RESTQueryAdapter.ts","../../../../src/rest/RESTQuery.ts","../../../../src/rest/RESTMutation.ts"],"sourcesContent":["import { QueryAdapter } from '../QueryAdapter.js';\nimport { resolveBaseUrl } from '../query-types.js';\nimport { reifyValue } from '../fieldRef.js';\nimport type { Query } from '../query.js';\nimport type { Mutation } from '../mutation.js';\nimport type { FetchNextConfig } from '../query-types.js';\nimport type { RESTQuery } from './RESTQuery.js';\nimport type { RESTMutation } from './RESTMutation.js';\nimport type { QueryRequestInit, BaseUrlValue, QueryRequestOptions } from '../types.js';\n\n// ================================\n// ResolvedFetchNext\n// ================================\n\nexport interface ResolvedFetchNext {\n url?: string;\n searchParams?: Record<string, unknown>;\n}\n\n// ================================\n// RESTQueryAdapter options\n// ================================\n\nexport interface RESTQueryAdapterOptions {\n fetch?: (url: string, init?: QueryRequestInit) => Promise<Response>;\n baseUrl?: BaseUrlValue;\n}\n\n// ================================\n// RESTQueryAdapter\n// ================================\n\nexport class RESTQueryAdapter extends QueryAdapter {\n private readonly _fetch: (url: string, init?: QueryRequestInit) => Promise<Response>;\n private readonly _baseUrl: BaseUrlValue | undefined;\n\n constructor(options?: RESTQueryAdapterOptions) {\n super();\n this._fetch =\n options?.fetch ?? (globalThis.fetch as unknown as (url: string, init?: QueryRequestInit) => Promise<Response>);\n this._baseUrl = options?.baseUrl;\n }\n\n override async send(ctx: Query, signal: AbortSignal): Promise<unknown> {\n return this.executeRequest(ctx as RESTQuery, signal);\n }\n\n override async sendNext(ctx: Query, signal: AbortSignal): Promise<unknown> {\n const resolved = this.resolveFetchNext(ctx as RESTQuery);\n if (resolved === undefined) {\n throw new Error('fetchNext is not configured for this query');\n }\n return this.executeRequest(ctx as RESTQuery, signal, resolved);\n }\n\n override hasNext(ctx: Query): boolean {\n const resolved = this.resolveFetchNext(ctx as RESTQuery);\n if (resolved === undefined) return false;\n\n if (resolved.url !== undefined && resolved.url !== null) {\n return true;\n }\n\n if (resolved.searchParams !== undefined) {\n const keys = Object.keys(resolved.searchParams);\n if (keys.length === 0) return false;\n for (const key of keys) {\n if (resolved.searchParams[key] === undefined || resolved.searchParams[key] === null) {\n return false;\n }\n }\n return true;\n }\n\n return false;\n }\n\n private resolveFetchNext(ctx: RESTQuery): ResolvedFetchNext | undefined {\n const dynamicConfig = ctx.getFetchNext ? ctx.getFetchNext() : undefined;\n const fetchNextConfig: FetchNextConfig | undefined = dynamicConfig ?? ctx.rawFetchNext;\n if (fetchNextConfig === undefined) return undefined;\n\n const resolveRoot: Record<string, unknown> = {\n params: ctx.params ?? {},\n result: ctx.resultData,\n };\n\n return {\n url: fetchNextConfig.url !== undefined ? (reifyValue(fetchNextConfig.url, resolveRoot) as string) : undefined,\n searchParams:\n fetchNextConfig.searchParams !== undefined\n ? (reifyValue(fetchNextConfig.searchParams, resolveRoot) as Record<string, unknown>)\n : undefined,\n };\n }\n\n /**\n * Resolves a path to a full URL.\n *\n * - Absolute URLs (`https://...`, `//...`) are returned as-is.\n * - Root-relative paths (`/foo`) are prepended with the resolved baseUrl.\n * The baseUrl priority is: per-query/mutation > adapter-level > `location.origin`.\n * If none is available and the path is root-relative, an error is thrown.\n * - Other paths (e.g. `example.com/foo`) are returned as-is.\n */\n private buildUrl(path: string, ctxBaseUrl: BaseUrlValue | undefined): string {\n // Absolute URL — use as-is regardless of any configured baseUrl\n if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('//')) {\n return path;\n }\n\n // Root-relative path — needs a base\n if (path.startsWith('/')) {\n const base = resolveBaseUrl(ctxBaseUrl) ?? resolveBaseUrl(this._baseUrl) ?? globalThis.location?.origin;\n\n if (!base) {\n throw new Error(\n `RESTQueryAdapter: cannot resolve URL for path \"${path}\". ` +\n `Set \\`baseUrl\\` on the query/mutation, pass it to \\`new RESTQueryAdapter({ baseUrl })\\`, ` +\n `or use an absolute URL.`,\n );\n }\n\n return `${base}${path}`;\n }\n\n // Relative path — use as-is\n return path;\n }\n\n private async executeRequest(\n ctx: RESTQuery,\n signal: AbortSignal,\n next?: { url?: string; searchParams?: Record<string, unknown> },\n ): Promise<unknown> {\n const path = next?.url ?? (ctx.getPath ? ctx.getPath() : ctx.path);\n const method = ctx.getMethod ? ctx.getMethod() : ctx.method;\n const baseSearchParams = ctx.getSearchParams ? ctx.getSearchParams() : ctx.searchParams;\n const searchParams = next?.searchParams ? { ...baseSearchParams, ...next.searchParams } : baseSearchParams;\n const body = ctx.getBody ? ctx.getBody() : ctx.body;\n const requestOptions = ctx.getRequestOptions ? ctx.getRequestOptions() : ctx.requestOptions;\n\n if (!path) {\n throw new Error('RESTQuery requires a path. Define `path` as a field or override `getPath()`.');\n }\n\n let url = path;\n\n if (searchParams) {\n const sp = new URLSearchParams();\n for (const key in searchParams) {\n const val = searchParams[key];\n if (val !== undefined && val !== null) {\n sp.append(key, String(val));\n }\n }\n const qs = sp.toString();\n if (qs) {\n url += '?' + qs;\n }\n }\n\n const ctxBaseUrl = requestOptions?.baseUrl ?? ctx.baseUrl;\n const fullUrl = this.buildUrl(url, ctxBaseUrl);\n\n const { baseUrl: _baseUrl, signal: _signal, ...fetchOptions } = requestOptions ?? ({} as Record<string, unknown>);\n\n const hasHeaders = body || ctx.headers;\n const headers: HeadersInit | undefined = hasHeaders\n ? {\n ...(body ? { 'Content-Type': 'application/json' } : undefined),\n ...(ctx.headers as Record<string, string>),\n }\n : undefined;\n\n const fetchResponse = await this._fetch(fullUrl, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal,\n ...fetchOptions,\n });\n\n ctx.response = fetchResponse as unknown as Response;\n\n return fetchResponse.json();\n }\n\n override async sendMutation(ctx: Mutation, signal: AbortSignal): Promise<unknown> {\n const restCtx = ctx as RESTMutation;\n const path = restCtx.getPath ? restCtx.getPath() : restCtx.path;\n const method = restCtx.getMethod ? restCtx.getMethod() : restCtx.method;\n const body = restCtx.getBody ? restCtx.getBody() : restCtx.body;\n const requestOptions = restCtx.getRequestOptions ? restCtx.getRequestOptions() : restCtx.requestOptions;\n\n if (!path) {\n throw new Error('RESTMutation requires a path. Define `path` as a field or override `getPath()`.');\n }\n\n const ctxBaseUrl = (requestOptions as QueryRequestOptions | undefined)?.baseUrl ?? restCtx.baseUrl;\n const fullUrl = this.buildUrl(path, ctxBaseUrl);\n\n const { baseUrl: _baseUrl, signal: _signal, ...fetchOptions } = (requestOptions ?? {}) as Record<string, unknown>;\n\n const headers: HeadersInit = {\n ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),\n ...(restCtx.headers as Record<string, string>),\n };\n\n const fetchResponse = await this._fetch(fullUrl, {\n method,\n headers,\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n signal,\n ...fetchOptions,\n });\n\n return fetchResponse.json();\n }\n}\n","import { Query } from '../query.js';\nimport { RESTQueryAdapter } from './RESTQueryAdapter.js';\nimport type { FetchNextConfig } from '../query-types.js';\nimport type { BaseUrlValue, QueryRequestOptions } from '../types.js';\n\n// ================================\n// RESTQuery — declarative HTTP query definition\n// ================================\n\nexport abstract class RESTQuery extends Query {\n static override adapter = RESTQueryAdapter;\n\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' = 'GET';\n path?: string;\n baseUrl?: BaseUrlValue;\n searchParams?: Record<string, unknown>;\n body?: Record<string, unknown>;\n headers?: HeadersInit;\n requestOptions?: QueryRequestOptions;\n fetchNext?: FetchNextConfig;\n\n declare response: Response | undefined;\n\n getIdentityKey(): string {\n return `${this.method ?? 'GET'}:${this.path ?? ''}`;\n }\n\n // User-overridable getters — the adapter reads these from the execution context\n getPath?(): string | undefined;\n getMethod?(): string;\n getSearchParams?(): Record<string, unknown> | undefined;\n getBody?(): Record<string, unknown> | undefined;\n getRequestOptions?(): QueryRequestOptions | undefined;\n getFetchNext?(): FetchNextConfig | undefined;\n}\n","import { Mutation } from '../mutation.js';\nimport type { BaseUrlValue, QueryRequestOptions } from '../types.js';\nimport { RESTQueryAdapter } from './RESTQueryAdapter.js';\n\nexport abstract class RESTMutation extends Mutation {\n static override adapter = RESTQueryAdapter;\n\n path?: string;\n baseUrl?: BaseUrlValue;\n method: 'POST' | 'PUT' | 'DELETE' | 'PATCH' = 'POST';\n body?: Record<string, unknown>;\n headers?: HeadersInit;\n requestOptions?: QueryRequestOptions;\n\n getIdentityKey(): string {\n return `${this.method ?? 'POST'}:${this.path ?? ''}`;\n }\n\n getPath?(): string | undefined;\n getMethod?(): string;\n getBody?(): Record<string, unknown> | undefined;\n getRequestOptions?(): QueryRequestOptions | undefined;\n}\n"],"names":["RESTQueryAdapter","QueryAdapter","options","ctx","signal","resolved","keys","key","fetchNextConfig","resolveRoot","reifyValue","path","ctxBaseUrl","base","resolveBaseUrl","next","method","baseSearchParams","searchParams","body","requestOptions","url","sp","val","qs","fullUrl","_baseUrl","_signal","fetchOptions","headers","fetchResponse","restCtx","RESTQuery","Query","RESTMutation","Mutation"],"mappings":";;;AAgCO,MAAMA,UAAyBC,EAAa;AAAA,EAChC;AAAA,EACA;AAAA,EAEjB,YAAYC,GAAmC;AAC7C,UAAA,GACA,KAAK,SACHA,GAAS,SAAU,WAAW,OAChC,KAAK,WAAWA,GAAS;AAAA,EAC3B;AAAA,EAEA,MAAe,KAAKC,GAAYC,GAAuC;AACrE,WAAO,KAAK,eAAeD,GAAkBC,CAAM;AAAA,EACrD;AAAA,EAEA,MAAe,SAASD,GAAYC,GAAuC;AACzE,UAAMC,IAAW,KAAK,iBAAiBF,CAAgB;AACvD,QAAIE,MAAa;AACf,YAAM,IAAI,MAAM,4CAA4C;AAE9D,WAAO,KAAK,eAAeF,GAAkBC,GAAQC,CAAQ;AAAA,EAC/D;AAAA,EAES,QAAQF,GAAqB;AACpC,UAAME,IAAW,KAAK,iBAAiBF,CAAgB;AACvD,QAAIE,MAAa,OAAW,QAAO;AAEnC,QAAIA,EAAS,QAAQ,UAAaA,EAAS,QAAQ;AACjD,aAAO;AAGT,QAAIA,EAAS,iBAAiB,QAAW;AACvC,YAAMC,IAAO,OAAO,KAAKD,EAAS,YAAY;AAC9C,UAAIC,EAAK,WAAW,EAAG,QAAO;AAC9B,iBAAWC,KAAOD;AAChB,YAAID,EAAS,aAAaE,CAAG,MAAM,UAAaF,EAAS,aAAaE,CAAG,MAAM;AAC7E,iBAAO;AAGX,aAAO;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IAAsBA,EAAQ;AAEzF,QAAI,CAACpB;AACH,YAAM,IAAI,MAAM,iFAAiF;AAGnG,UAAMC,IAAcQ,GAAoD,WAAWW,EAAQ,SACrFN,IAAU,KAAK,SAASd,GAAMC,CAAU,GAExC,EAAE,SAASc,GAAU,QAAQC,GAAS,GAAGC,EAAA,IAAkBR,KAAkB,CAAA,GAE7ES,IAAuB;AAAA,MAC3B,GAAIV,MAAS,SAAY,EAAE,gBAAgB,mBAAA,IAAuB,CAAA;AAAA,MAClE,GAAIY,EAAQ;AAAA,IAAA;AAWd,YARsB,MAAM,KAAK,OAAON,GAAS;AAAA,MAC/C,QAAAT;AAAA,MACA,SAAAa;AAAA,MACA,GAAIV,MAAS,SAAY,EAAE,MAAM,KAAK,UAAUA,CAAI,EAAA,IAAM,CAAA;AAAA,MAC1D,QAAAf;AAAA,MACA,GAAGwB;AAAA,IAAA,CACJ,GAEoB,KAAA;AAAA,EACvB;AACF;AClNO,MAAeI,UAAkBC,EAAM;AAAA,EAC5C,OAAgB,UAAUjC;AAAA,EAE1B,SAAsD;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA,iBAAyB;AACvB,WAAO,GAAG,KAAK,UAAU,KAAK,IAAI,KAAK,QAAQ,EAAE;AAAA,EACnD;AASF;AC9BO,MAAekC,UAAqBC,EAAS;AAAA,EAClD,OAAgB,UAAUnC;AAAA,EAE1B;AAAA,EACA;AAAA,EACA,SAA8C;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EAEA,iBAAyB;AACvB,WAAO,GAAG,KAAK,UAAU,MAAM,IAAI,KAAK,QAAQ,EAAE;AAAA,EACpD;AAMF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/rest/RESTQueryAdapter.ts","../../../../src/rest/RESTQuery.ts","../../../../src/rest/RESTMutation.ts"],"sourcesContent":["import { QueryAdapter } from '../QueryAdapter.js';\nimport { resolveBaseUrl } from '../query-types.js';\nimport { reifyValue } from '../fieldRef.js';\nimport type { Query } from '../query.js';\nimport type { Mutation } from '../mutation.js';\nimport type { FetchNextConfig } from '../query-types.js';\nimport type { RESTQuery } from './RESTQuery.js';\nimport type { RESTMutation } from './RESTMutation.js';\nimport type { QueryRequestInit, BaseUrlValue, QueryRequestOptions } from '../types.js';\n\n// ================================\n// ResolvedFetchNext\n// ================================\n\nexport interface ResolvedFetchNext {\n url?: string;\n searchParams?: Record<string, unknown>;\n}\n\n// ================================\n// RESTQueryAdapter options\n// ================================\n\nexport interface RESTQueryAdapterOptions {\n fetch?: (url: string, init?: QueryRequestInit) => Promise<Response>;\n baseUrl?: BaseUrlValue;\n}\n\n// ================================\n// RESTQueryAdapter\n// ================================\n\nexport class RESTQueryAdapter extends QueryAdapter {\n private readonly _fetch: (url: string, init?: QueryRequestInit) => Promise<Response>;\n private readonly _baseUrl: BaseUrlValue | undefined;\n\n constructor(options?: RESTQueryAdapterOptions) {\n super();\n this._fetch =\n options?.fetch ?? (globalThis.fetch as unknown as (url: string, init?: QueryRequestInit) => Promise<Response>);\n this._baseUrl = options?.baseUrl;\n }\n\n override async send(ctx: Query, signal: AbortSignal): Promise<unknown> {\n return this.executeRequest(ctx as RESTQuery, signal);\n }\n\n override async sendNext(ctx: Query, signal: AbortSignal): Promise<unknown> {\n const resolved = this.resolveFetchNext(ctx as RESTQuery);\n if (resolved === undefined) {\n throw new Error('fetchNext is not configured for this query');\n }\n return this.executeRequest(ctx as RESTQuery, signal, resolved);\n }\n\n override hasNext(ctx: Query): boolean {\n const resolved = this.resolveFetchNext(ctx as RESTQuery);\n if (resolved === undefined) return false;\n\n if (resolved.url !== undefined && resolved.url !== null) {\n return true;\n }\n\n if (resolved.searchParams !== undefined) {\n const keys = Object.keys(resolved.searchParams);\n if (keys.length === 0) return false;\n for (const key of keys) {\n if (resolved.searchParams[key] === undefined || resolved.searchParams[key] === null) {\n return false;\n }\n }\n return true;\n }\n\n return false;\n }\n\n private resolveFetchNext(ctx: RESTQuery): ResolvedFetchNext | undefined {\n const dynamicConfig = ctx.getFetchNext ? ctx.getFetchNext() : undefined;\n const fetchNextConfig: FetchNextConfig | undefined = dynamicConfig ?? ctx.rawFetchNext;\n if (fetchNextConfig === undefined) return undefined;\n\n const resolveRoot: Record<string, unknown> = {\n params: ctx.params ?? {},\n result: ctx.resultData,\n };\n\n return {\n url: fetchNextConfig.url !== undefined ? (reifyValue(fetchNextConfig.url, resolveRoot) as string) : undefined,\n searchParams:\n fetchNextConfig.searchParams !== undefined\n ? (reifyValue(fetchNextConfig.searchParams, resolveRoot) as Record<string, unknown>)\n : undefined,\n };\n }\n\n /**\n * Resolves a path to a full URL.\n *\n * - Absolute URLs (`https://...`, `//...`) are returned as-is.\n * - Root-relative paths (`/foo`) are prepended with the resolved baseUrl.\n * The baseUrl priority is: per-query/mutation > adapter-level > `location.origin`.\n * If none is available and the path is root-relative, an error is thrown.\n * - Other paths (e.g. `example.com/foo`) are returned as-is.\n */\n private buildUrl(path: string, ctxBaseUrl: BaseUrlValue | undefined): string {\n // Absolute URL — use as-is regardless of any configured baseUrl\n if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('//')) {\n return path;\n }\n\n // Root-relative path — needs a base\n if (path.startsWith('/')) {\n const base = resolveBaseUrl(ctxBaseUrl) ?? resolveBaseUrl(this._baseUrl) ?? globalThis.location?.origin;\n\n if (!base) {\n throw new Error(\n `RESTQueryAdapter: cannot resolve URL for path \"${path}\". ` +\n `Set \\`baseUrl\\` on the query/mutation, pass it to \\`new RESTQueryAdapter({ baseUrl })\\`, ` +\n `or use an absolute URL.`,\n );\n }\n\n return `${base}${path}`;\n }\n\n // Relative path — use as-is\n return path;\n }\n\n private async executeRequest(\n ctx: RESTQuery,\n signal: AbortSignal,\n next?: { url?: string; searchParams?: Record<string, unknown> },\n ): Promise<unknown> {\n const path = next?.url ?? (ctx.getPath ? ctx.getPath() : ctx.path);\n const method = ctx.getMethod ? ctx.getMethod() : ctx.method;\n const baseSearchParams = ctx.getSearchParams ? ctx.getSearchParams() : ctx.searchParams;\n const searchParams = next?.searchParams ? { ...baseSearchParams, ...next.searchParams } : baseSearchParams;\n const body = ctx.getBody ? ctx.getBody() : ctx.body;\n const requestOptions = ctx.getRequestOptions ? ctx.getRequestOptions() : ctx.requestOptions;\n\n if (!path) {\n throw new Error('RESTQuery requires a path. Define `path` as a field or override `getPath()`.');\n }\n\n let url = path;\n\n if (searchParams) {\n const sp = new URLSearchParams();\n for (const key in searchParams) {\n const val = searchParams[key];\n if (val !== undefined && val !== null) {\n sp.append(key, String(val));\n }\n }\n const qs = sp.toString();\n if (qs) {\n url += '?' + qs;\n }\n }\n\n const ctxBaseUrl = requestOptions?.baseUrl ?? ctx.baseUrl;\n const fullUrl = this.buildUrl(url, ctxBaseUrl);\n\n const { baseUrl: _baseUrl, signal: _signal, ...fetchOptions } = requestOptions ?? ({} as Record<string, unknown>);\n\n const hasHeaders = body || ctx.headers;\n const headers: HeadersInit | undefined = hasHeaders\n ? {\n ...(body ? { 'Content-Type': 'application/json' } : undefined),\n ...(ctx.headers as Record<string, string>),\n }\n : undefined;\n\n const fetchResponse = await this._fetch(fullUrl, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal,\n ...fetchOptions,\n });\n\n ctx.response = fetchResponse as unknown as Response;\n ctx.responseNotifier.notify();\n\n return fetchResponse.json();\n }\n\n override async sendMutation(ctx: Mutation, signal: AbortSignal): Promise<unknown> {\n const restCtx = ctx as RESTMutation;\n const path = restCtx.getPath ? restCtx.getPath() : restCtx.path;\n const method = restCtx.getMethod ? restCtx.getMethod() : restCtx.method;\n const body = restCtx.getBody ? restCtx.getBody() : restCtx.body;\n const requestOptions = restCtx.getRequestOptions ? restCtx.getRequestOptions() : restCtx.requestOptions;\n\n if (!path) {\n throw new Error('RESTMutation requires a path. Define `path` as a field or override `getPath()`.');\n }\n\n const ctxBaseUrl = (requestOptions as QueryRequestOptions | undefined)?.baseUrl ?? restCtx.baseUrl;\n const fullUrl = this.buildUrl(path, ctxBaseUrl);\n\n const { baseUrl: _baseUrl, signal: _signal, ...fetchOptions } = (requestOptions ?? {}) as Record<string, unknown>;\n\n const headers: HeadersInit = {\n ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),\n ...(restCtx.headers as Record<string, string>),\n };\n\n const fetchResponse = await this._fetch(fullUrl, {\n method,\n headers,\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n signal,\n ...fetchOptions,\n });\n\n return fetchResponse.json();\n }\n}\n","import type { Notifier } from 'signalium';\nimport { Query } from '../query.js';\nimport { RESTQueryAdapter } from './RESTQueryAdapter.js';\nimport type { FetchNextConfig } from '../query-types.js';\nimport type { BaseUrlValue, QueryRequestOptions } from '../types.js';\n\n// ================================\n// RESTQuery — declarative HTTP query definition\n// ================================\n\nexport abstract class RESTQuery extends Query {\n static override adapter = RESTQueryAdapter;\n\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' = 'GET';\n path?: string;\n baseUrl?: BaseUrlValue;\n searchParams?: Record<string, unknown>;\n body?: Record<string, unknown>;\n headers?: HeadersInit;\n requestOptions?: QueryRequestOptions;\n fetchNext?: FetchNextConfig;\n\n declare response: Response | undefined;\n declare responseNotifier: Notifier;\n\n getIdentityKey(): string {\n return `${this.method ?? 'GET'}:${this.path ?? ''}`;\n }\n\n // User-overridable getters — the adapter reads these from the execution context\n getPath?(): string | undefined;\n getMethod?(): string;\n getSearchParams?(): Record<string, unknown> | undefined;\n getBody?(): Record<string, unknown> | undefined;\n getRequestOptions?(): QueryRequestOptions | undefined;\n getFetchNext?(): FetchNextConfig | undefined;\n}\n","import { Mutation } from '../mutation.js';\nimport type { BaseUrlValue, QueryRequestOptions } from '../types.js';\nimport { RESTQueryAdapter } from './RESTQueryAdapter.js';\n\nexport abstract class RESTMutation extends Mutation {\n static override adapter = RESTQueryAdapter;\n\n path?: string;\n baseUrl?: BaseUrlValue;\n method: 'POST' | 'PUT' | 'DELETE' | 'PATCH' = 'POST';\n body?: Record<string, unknown>;\n headers?: HeadersInit;\n requestOptions?: QueryRequestOptions;\n\n getIdentityKey(): string {\n return `${this.method ?? 'POST'}:${this.path ?? ''}`;\n }\n\n getPath?(): string | undefined;\n getMethod?(): string;\n getBody?(): Record<string, unknown> | undefined;\n getRequestOptions?(): QueryRequestOptions | undefined;\n}\n"],"names":["RESTQueryAdapter","QueryAdapter","options","ctx","signal","resolved","keys","key","fetchNextConfig","resolveRoot","reifyValue","path","ctxBaseUrl","base","resolveBaseUrl","next","method","baseSearchParams","searchParams","body","requestOptions","url","sp","val","qs","fullUrl","_baseUrl","_signal","fetchOptions","headers","fetchResponse","restCtx","RESTQuery","Query","RESTMutation","Mutation"],"mappings":";;;AAgCO,MAAMA,UAAyBC,EAAa;AAAA,EAChC;AAAA,EACA;AAAA,EAEjB,YAAYC,GAAmC;AAC7C,UAAA,GACA,KAAK,SACHA,GAAS,SAAU,WAAW,OAChC,KAAK,WAAWA,GAAS;AAAA,EAC3B;AAAA,EAEA,MAAe,KAAKC,GAAYC,GAAuC;AACrE,WAAO,KAAK,eAAeD,GAAkBC,CAAM;AAAA,EACrD;AAAA,EAEA,MAAe,SAASD,GAAYC,GAAuC;AACzE,UAAMC,IAAW,KAAK,iBAAiBF,CAAgB;AACvD,QAAIE,MAAa;AACf,YAAM,IAAI,MAAM,4CAA4C;AAE9D,WAAO,KAAK,eAAeF,GAAkBC,GAAQC,CAAQ;AAAA,EAC/D;AAAA,EAES,QAAQF,GAAqB;AACpC,UAAME,IAAW,KAAK,iBAAiBF,CAAgB;AACvD,QAAIE,MAAa,OAAW,QAAO;AAEnC,QAAIA,EAAS,QAAQ,UAAaA,EAAS,QAAQ;AACjD,aAAO;AAGT,QAAIA,EAAS,iBAAiB,QAAW;AACvC,YAAMC,IAAO,OAAO,KAAKD,EAAS,YAAY;AAC9C,UAAIC,EAAK,WAAW,EAAG,QAAO;AAC9B,iBAAWC,KAAOD;AAChB,YAAID,EAAS,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 'signalium';
|
|
1
2
|
import { Query } from '../query.js';
|
|
2
3
|
import { RESTQueryAdapter } from './RESTQueryAdapter.js';
|
|
3
4
|
import type { FetchNextConfig } from '../query-types.js';
|
|
@@ -13,6 +14,7 @@ export declare abstract class RESTQuery extends Query {
|
|
|
13
14
|
requestOptions?: QueryRequestOptions;
|
|
14
15
|
fetchNext?: FetchNextConfig;
|
|
15
16
|
response: Response | undefined;
|
|
17
|
+
responseNotifier: Notifier;
|
|
16
18
|
getIdentityKey(): string;
|
|
17
19
|
getPath?(): string | undefined;
|
|
18
20
|
getMethod?(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RESTQuery.d.ts","sourceRoot":"","sources":["../../../src/rest/RESTQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMrE,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,OAAgB,OAAO,0BAAoB;IAE3C,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAS;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,SAAS,CAAC,EAAE,eAAe,CAAC;IAEpB,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,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C7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RESTQueryAdapter.d.ts","sourceRoot":"","sources":["../../../src/rest/RESTQueryAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAuB,MAAM,aAAa,CAAC;AAMvF,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAMD,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpE,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAMD,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8D;IACrF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;gBAExC,OAAO,CAAC,EAAE,uBAAuB;IAO9B,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvD,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAQjE,OAAO,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO;IAsBrC,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;YAyBF,cAAc;
|
|
1
|
+
{"version":3,"file":"RESTQueryAdapter.d.ts","sourceRoot":"","sources":["../../../src/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define custom data-fetching
|
|
|
65
65
|
|
|
66
66
|
#### Methods
|
|
67
67
|
|
|
68
|
-
| Method | Signature | Description
|
|
69
|
-
| ---------------- | ------------------------------------- |
|
|
70
|
-
| `getIdentityKey` | `(): unknown` | **(abstract)** Returns a value used to compute the cache/identity key for this query class.
|
|
71
|
-
| `refetch` | `(): void` | Triggers a refetch of this query, bypassing staleTime.
|
|
72
|
-
| `getConfig` | `(): QueryConfigOptions \| undefined` | Optional. Dynamically compute config at execution time.
|
|
68
|
+
| Method | Signature | Description |
|
|
69
|
+
| ---------------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
70
|
+
| `getIdentityKey` | `(): unknown` | **(abstract)** Returns a value used to compute the cache/identity key for this query class. |
|
|
71
|
+
| `refetch` | `(): void` | Triggers a refetch of this query, bypassing staleTime. |
|
|
72
|
+
| `getConfig` | `(): QueryConfigOptions \| undefined` | Optional. Dynamically compute config at execution time. Reactive: re-runs when any signal consumed inside notifies (e.g. `this.responseNotifier`). |
|
|
73
73
|
|
|
74
74
|
---
|
|
75
75
|
|
|
@@ -79,16 +79,17 @@ Convenience base class for REST/JSON queries. Handles URL construction, search p
|
|
|
79
79
|
|
|
80
80
|
#### Instance properties
|
|
81
81
|
|
|
82
|
-
| Property
|
|
83
|
-
|
|
|
84
|
-
| `method`
|
|
85
|
-
| `path`
|
|
86
|
-
| `searchParams`
|
|
87
|
-
| `body`
|
|
88
|
-
| `headers`
|
|
89
|
-
| `requestOptions`
|
|
90
|
-
| `fetchNext`
|
|
91
|
-
| `response`
|
|
82
|
+
| Property | Type | Default | Description |
|
|
83
|
+
| ------------------ | ------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
84
|
+
| `method` | `'GET' \| 'POST' \| 'PUT' \| 'DELETE' \| 'PATCH'` | `'GET'` | HTTP method. |
|
|
85
|
+
| `path` | `string \| undefined` | — | URL path. Use template literal interpolation with `this.params` references. |
|
|
86
|
+
| `searchParams` | `Record<string, unknown> \| undefined` | — | Query string parameters. |
|
|
87
|
+
| `body` | `Record<string, unknown> \| undefined` | — | Request body (JSON-serialized). |
|
|
88
|
+
| `headers` | `HeadersInit \| undefined` | — | Custom HTTP headers. |
|
|
89
|
+
| `requestOptions` | `QueryRequestOptions \| undefined` | — | Additional fetch options (credentials, mode, baseUrl, etc.). |
|
|
90
|
+
| `fetchNext` | `FetchNextConfig \| undefined` | — | Static pagination config. Values can be FieldRefs (e.g. `this.result.nextCursor`). |
|
|
91
|
+
| `response` | `Response \| undefined` | — | The raw HTTP `Response` from the last fetch. Set by `RESTQueryAdapter` after each request completes. Available in `getConfig()`. |
|
|
92
|
+
| `responseNotifier` | `Notifier` | — | Notifier fired by `RESTQueryAdapter` after each fetch completes. Consume inside a `reactiveSignal` in `getConfig()` to react to new responses. |
|
|
92
93
|
|
|
93
94
|
#### `getIdentityKey()` default
|
|
94
95
|
|
|
@@ -97,7 +97,7 @@ The full list of options provided by `RESTQuery` is available below, but there a
|
|
|
97
97
|
1. Parameters should not be connected to the _specifics_ of your Queries. You should be able to change if a parameter is passed as a search param, a path param, a header, or so on, without having to change every _usage_ of the query.
|
|
98
98
|
2. More broadly, this distinction allows you to keep your Queries _protocol agnostic_. If you decide to switch from REST to GraphQL or gRPC in the future, none of your usage sites need to change.
|
|
99
99
|
|
|
100
|
-
The same distinction applies to query _results_. Internally, `RESTQuery` exposes the raw HTTP response on `this.response` after each fetch completes (which can be used in `getConfig()`
|
|
100
|
+
The same distinction applies to query _results_. Internally, `RESTQuery` exposes the raw HTTP response on `this.response` after each fetch completes (which can be used reactively in `getConfig()` via `this.responseNotifier` to control retry or polling behavior based on whether the response was successful or errored). Externally, the result gets parsed by the `this.result` definition and exposed as the query's value.
|
|
101
101
|
|
|
102
102
|
This brings us to the next topic: Using Queries.
|
|
103
103
|
|
|
@@ -394,9 +394,11 @@ class GetUser extends RESTQuery {
|
|
|
394
394
|
}
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
But let's say we wanted to provide a _dynamic_ polling interval based on the query response. We can't use conditional logic in the _field_ version of `config`, but we can in the _method_ version:
|
|
397
|
+
But let's say we wanted to provide a _dynamic_ polling interval based on the query response. We can't use conditional logic in the _field_ version of `config`, but we can in the _method_ version. `getConfig()` is reactive: it re-runs whenever a signal it consumed notifies. `this.responseNotifier` is fired after every fetch, so wrap response reads in a `reactiveSignal` that consumes it:
|
|
398
398
|
|
|
399
399
|
```ts
|
|
400
|
+
import { reactiveSignal } from 'signalium';
|
|
401
|
+
|
|
400
402
|
class GetUser extends RESTQuery {
|
|
401
403
|
params = {
|
|
402
404
|
id: t.number,
|
|
@@ -409,7 +411,10 @@ class GetUser extends RESTQuery {
|
|
|
409
411
|
};
|
|
410
412
|
|
|
411
413
|
getConfig() {
|
|
412
|
-
const lastResponseOk =
|
|
414
|
+
const lastResponseOk = reactiveSignal(() => {
|
|
415
|
+
this.responseNotifier.consume();
|
|
416
|
+
return this.response?.ok ?? true;
|
|
417
|
+
}).value;
|
|
413
418
|
|
|
414
419
|
// If the last response was ok, poll quickly. Else, poll
|
|
415
420
|
// slowly - the service might be having trouble.
|
|
@@ -422,6 +427,8 @@ class GetUser extends RESTQuery {
|
|
|
422
427
|
}
|
|
423
428
|
```
|
|
424
429
|
|
|
430
|
+
`this.response` is a plain field, not a signal, so reading it directly inside `getConfig()` would only evaluate once at activation and never re-run as new responses arrive. `responseNotifier.consume()` inside a `reactiveSignal` is what subscribes the outer `getConfig()` to fetch completions.
|
|
431
|
+
|
|
425
432
|
### Field reference
|
|
426
433
|
|
|
427
434
|
Here is a quick reference of the fields that are available for configuration on `RESTQuery`:
|
|
@@ -86,7 +86,7 @@ This is useful when search params or body fields affect the response but don't a
|
|
|
86
86
|
|
|
87
87
|
## Dynamic Config with getConfig()
|
|
88
88
|
|
|
89
|
-
For runtime-dependent configuration, override `getConfig()`. This is useful when caching, network behavior, or retry logic should vary based on the query's params or other runtime state:
|
|
89
|
+
For runtime-dependent configuration, override `getConfig()`. This is useful when caching, network behavior, or retry logic should vary based on the query's params or other runtime state. `getConfig()` is reactive: it re-runs whenever a signal consumed inside notifies. Read `this.response` reactively via `this.responseNotifier` (see [Core: Queries](/core/queries#avoid-arrow-functions-for-dynamic-logic)).
|
|
90
90
|
|
|
91
91
|
```tsx
|
|
92
92
|
class GetDashboard extends RESTQuery {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const b=require("signalium"),x=require("signalium/utils"),Qt=require("./shared-Ct5zKrt4.js"),It=require("./stores/sync.js");var L=(e=>(e.Always="always",e.Online="online",e.OfflineFirst="offlineFirst",e))(L||{}),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 I=Symbol("array"),k=Symbol("record"),yt=Symbol("QUERY_ID");var tt=(e=>(e[e.Array=0]="Array",e[e.Value=1]="Value",e))(tt||{});class U{type;entityDefs;constraintFieldRefs;sort;valueType;onCreate;onUpdate;onDelete;constructor(t,n,i,r,s,o,a,c){this.type=t,this.entityDefs=n,this.constraintFieldRefs=i,this.sort=r,this.valueType=s,this.onCreate=o,this.onUpdate=a,this.onDelete=c}static array(t,n,i){return new U(0,t,n,i,void 0,void 0,void 0,void 0)}static value(t,n,i,r,s,o){return new U(1,t,n,void 0,i,r,s,o)}}const R=new WeakMap;function j(e){return R.get(e)}var et=(e=>(e[e.Query=0]="Query",e[e.Entity=1]="Entity",e))(et||{});class Se{constructor(t,n,i){this._onEvict=n,this._intervalId=setInterval(this._tick,t*6e4*i)}_currentFlush=new Map;_nextFlush=new Map;_intervalId;schedule(t,n){this._nextFlush.set(t,n)}cancel(t){this._currentFlush.delete(t),this._nextFlush.delete(t)}_tick=()=>{const{_currentFlush:t,_nextFlush:n,_onEvict:i}=this;for(const[r,s]of t)i(r,s);this._currentFlush=n,this._nextFlush=new Map};destroy(){clearInterval(this._intervalId)}}class Bt{_buckets=new Map;_nextTickEntries=new Map;_nextTickScheduled=!1;_onEvict;_multiplier;constructor(t,n=1){this._onEvict=t,this._multiplier=n}schedule(t,n,i){if(n===1/0)return;if(n===0){const{_nextTickEntries:o}=this;o.set(t,i),this._nextTickScheduled||(this._nextTickScheduled=!0,setTimeout(this._flushNextTick,0));return}const{_buckets:r}=this;let s=r.get(n);s||(s=new Se(n,this._onEvict,this._multiplier),r.set(n,s)),s.schedule(t,i)}cancel(t,n){if(n!==1/0){if(n===0){this._nextTickEntries.delete(t);return}this._buckets.get(n)?.cancel(t)}}_flushNextTick=()=>{const{_nextTickEntries:t,_onEvict:n}=this;this._nextTickScheduled=!1;for(const[i,r]of t)n(i,r);t.clear()};destroy(){const{_buckets:t,_nextTickEntries:n}=this;for(const i of t.values())i.destroy();t.clear(),n.clear()}}class Yt{schedule(t,n,i){}cancel(t,n){}destroy(){}}const X=Symbol("fieldRef"),M=Symbol("fieldRefPath"),pt=Symbol("DEFINITION_TARGET"),Z=Symbol("CANCEL_PROXY"),xe=/\[([^\]]+)\]/g;function Gt(e){const t={[X]:!0,[M]:e};return new Proxy(t,Ae)}const Ae={get(e,t){if(t===X)return!0;if(t===M)return e[M];if(t===Symbol.toPrimitive||t==="toString"||t==="valueOf"){const i=e[M];return()=>`[${i.join(".")}]`}if(typeof t=="symbol")return;const n=e[M];return Gt([...n,t])},has(e,t){return t===X||t===M}};function Ht(e){return typeof e=="object"&&e!==null&&e[X]===!0}function Wt(e){return e[M]}function gt(e){let t=!1;return new Proxy(e,{set(n,i,r){return n[i]=r,!0},get(n,i){if(t)throw new Error("Definition proxy accessed after extraction. Avoid arrow functions that capture `this`.");return i===pt?n:i===Z?()=>{t=!0}:typeof i=="symbol"?n[i]:Gt([i])}})}function zt(e){const t=e[pt];e[Z]();const n={};for(const s of Object.getOwnPropertyNames(t))n[s]=t[s];const i={};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 i)&&(i[s]=o.value)}r=Object.getPrototypeOf(r)}return{fields:n,methods:i}}function vt(e,t){let n=t;for(const i of e){if(n==null)return;n=n[i]}return n}function Ne(e,t){return e.replace(xe,(n,i)=>{const r=i.split("."),s=vt(r,t);return s!=null?encodeURIComponent(String(s)):""})}function G(e,t){if(Ht(e))return vt(Wt(e),t);if(typeof e=="string")return Ne(e,t);if(Array.isArray(e))return e.map(n=>G(n,t));if(typeof e=="object"&&e!==null&&Object.getPrototypeOf(e)===Object.prototype){const n={};for(const i of Object.keys(e))n[i]=G(e[i],t);return n}return e}function at(e,t,n){const i=e.fields,r=e.methods,s={params:t},o={};for(const[a,c]of Object.entries(i))o[a]=G(c,s);o.params=t,o.context=n;for(const[a,c]of Object.entries(r))o[a]=c.bind(o);return o}class nt{static cache;constructor(){return gt(this)}}const Jt=Object.entries,ct=Object.keys;let Xt=()=>{};{const t=(i,r)=>{if(i.size!==r.size)return!1;for(const s of i)if(!r.has(s))return!1;return!0},n=(i,r)=>{if(i===r)return!0;if(typeof i!=typeof r)return!1;if(typeof i=="number"){const s=r;if((i&65535)!==(s&65535))return!1;const o=i>>16,a=s>>16;return!(o!==0&&a!==0&&o!==a)}if(typeof i=="string")return i===r;if(i instanceof Set&&r instanceof Set)return t(i,r);if(i instanceof v&&r instanceof v){const s=i.mask,o=r.mask;if((s&65535)!==(o&65535))return!1;const a=s>>16,c=o>>16;if(a!==0&&c!==0&&a!==c)return!1;if(i.shape===r.shape)return!0;if(i.shape!==void 0&&r.shape!==void 0&&typeof i.shape=="object"&&typeof r.shape=="object"){const f=i.shape,l=r.shape;for(const u of Object.keys(f))if(u in l&&!n(f[u],l[u]))return!1;for(const u of Object.keys(l))if(u in f&&!n(f[u],l[u]))return!1}return!0}return!1};Xt=(i,r,s,o)=>{if(!n(s,o))throw new Error(`[fetchium] Entity typename '${i}' has incompatible type for field '${r}' across different entity definitions`)}}function kt(e){return typeof e=="number"?e|d.UNDEFINED:e instanceof v?(e.mask&d.UNDEFINED)!==0?e:v.cloneWith(e,d.UNDEFINED):e}function Ft(e){return e instanceof v&&(e.mask&d.OBJECT)!==0&&(e.mask&(d.ENTITY|d.ARRAY|d.UNION|d.RECORD|d.LIVE))===0}function Zt(e,t,n){const i=new Set;for(const s of e)if(s!==void 0)for(const o of Object.keys(s))i.add(o);const r={};for(const s of i){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),a!==void 0&&u!==a&&!Ft(u)&&Xt(n,s,a,u),Ft(u)?c.push(u.shape):(f=!1,c.push(void 0))):(f=!1,c.push(void 0))}if(f&&o>0){const l=Zt(c,t,n),u=new v(d.OBJECT,l);r[s]=o<t?kt(u):u}else r[s]=o<t?kt(a):a}return r}class v{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,n,i,r,s,o){this.mask=t,this.shape=n,this.values=i,this.typenameField=r,this.typenameValue=s,this.idField=o}static merge(t){if(t.length===1)return t[0];const n=t.length,i=t.map(f=>f.shape),r=t[0].typenameValue??"(unknown)",s=Zt(i,n,r);let o,a,c;for(const f of t){if(o===void 0&&f.idField!==void 0)o=f.idField;else if(o!==void 0&&f.idField!==void 0&&f.idField!==o)throw new Error(`[fetchium] Entity typename '${f.typenameValue}' has conflicting id fields: '${String(o)}' vs '${String(f.idField)}'`);a===void 0&&(a=f.typenameField),c===void 0&&(c=f.typenameValue)}return new v(d.ENTITY|d.OBJECT,s,void 0,a,c,o)}static cloneWith(t,n){const i=new v(n|t.mask,t.shape,t.values,t.typenameField,t.typenameValue,t.idField);return i._methods=t._methods,i._entityConfig=t._entityConfig,i._entityClass=t._entityClass,i._entityCache=t._entityCache,i._liveConfig=t._liveConfig,i}}class V extends Set{lowercaseMap;constructor(t){super(t),this.lowercaseMap=new Map;for(const n of t)if(typeof n=="string"){const i=n.toLowerCase(),r=this.lowercaseMap.get(i);if(r!==void 0)throw new Error(`Case-insensitive enum cannot have multiple values with the same lowercase form: '${r}' and '${n}' both become '${i}'`);this.lowercaseMap.set(i,n)}}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 De=1128875347;x.registerCustomHash(V,e=>{let t=De;for(const n of e)t+=x.hashValue(n);return t>>>0});function mt(e,t){return new v(e,t)}function Ie(e){return mt(d.ARRAY,e)}function ke(e){return mt(d.RECORD|d.OBJECT,e)}function Fe(e){return mt(d.PARSE_RESULT,e)}function te(e,t){let n=e,i,r,s;for(const[o,a]of Jt(t))switch(typeof a){case"number":if((a&d.ID)!==0){if(i!==void 0)throw new Error(`Duplicate id field: ${o}`);i=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 V||a instanceof Set)break;a.mask&d.LIVE&&(n|=d.LIVE);break}return new v(n,t,void 0,r,s,i)}function Me(e){return te(d.OBJECT,e)}function Mt(e,t,n){const i=e.mask;if((i&d.UNION)!==0){const r=e;if(r.typenameField!==void 0){if(n!==void 0&&n!==r.typenameField)throw new Error(`Union typename field conflict: Cannot merge unions with different typename fields ('${n}' vs '${r.typenameField}')`);n=r.typenameField}const s=r.shape;if(s!==void 0)for(const o of[...ct(s),I,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((i&d.ARRAY)!==0){if(t[I]!==void 0)throw new Error("Array shape already defined");t[I]=e.shape}else if((i&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(n!==void 0&&r!==n)throw new Error("Object definitions must have the same typename field to be in the same union");n=r,t[s]=e}return n}function _t(...e){const t=e;let n=0,i=0,r,s,o,a,c=0;for(const l of t){if(typeof l=="number"){n|=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(i++,c|=l.mask,i===1){r=l;continue}i===2&&(o=Object.create(null),a=Mt(r,o,a)),a=Mt(l,o,a)}if(i===0)return s===void 0?n:n===0?s:new v(n|d.UNION,void 0,s);if(i===1)return v.cloneWith(r,n);const f=n|c|d.UNION;return new v(f,o,s,a)}function wt(e,t,n){const i=e;if(typeof i=="number")return i|t;if(i instanceof Set)return _t(e,t);let r=n.get(i);return r===void 0&&(r=v.cloneWith(i,t),n.set(i,r)),r}const Te=new WeakMap,Pe=new WeakMap,je=new WeakMap;function $e(e){return wt(e,d.UNDEFINED|d.NULL,je)}function Le(e){return wt(e,d.UNDEFINED,Te)}function Ue(e){return wt(e,d.NULL,Pe)}function qe(e){return e}function Ve(e){return new Set([e])}const ee=((...e)=>new Set(e));ee.caseInsensitive=(...e)=>new V(e);const Et=16;let Ke=0;const ft=[],ne=[],ie=new Map,re=new Map,it=new WeakSet;class H{_raw;_formatted;_parsed;_formatId;constructor(t,n,i){this._raw=t,this._formatId=n,i?(this._formatted=ft[n](t),this._parsed=!0):this._parsed=!1,it.add(this)}getValue(){return this._parsed||(this._formatted=ft[this._formatId](this._raw),this._parsed=!0),this._formatted}toJSON(){return this._parsed?ne[this._formatId](this._formatted):this._raw}}function Qe(e){const t=ie.get(e);if(t===void 0)throw new Error(`Format ${e} not registered`);return t}function Tt(e){const t=e>>Et;return re.get(t)}function bt(e,t,n,i,r){const s=Ke++;ft[s]=n,ne[s]=i,re.set(s,e);const o=r?.eager??!0,c=s<<Et|t|d.HAS_FORMAT|(o?d.IS_EAGER_FORMAT:0);ie.set(e,c)}bt("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[,n,i,r]=t,s=new Date(Date.UTC(parseInt(n,10),parseInt(i,10)-1,parseInt(r,10)));if(isNaN(s.getTime()))throw new Error(`Invalid date string: ${e}`);return s},e=>{const t=e.getUTCFullYear(),n=String(e.getUTCMonth()+1).padStart(2,"0"),i=String(e.getUTCDate()).padStart(2,"0");return`${t}-${n}-${i}`});bt("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 Pt=new WeakMap;function q(e){let t=Pt.get(e);if(t===void 0){const n=new e,i=n[pt]??n;n[Z]&&n[Z]();const r={};for(const[f,l]of Jt(i)){if(!(typeof l=="number"||typeof l=="string"||l instanceof Set||l instanceof v||l instanceof V))throw new Error(`[fetchium] Entity '${e.name}' field '${f}' has an invalid type definition. All entity fields must be type definitions (e.g. t.string, t.number, t.entity(...), etc). Got: ${typeof l=="object"?l?.constructor?.name??typeof l:typeof l}`);r[f]=l}const s=Object.getPrototypeOf(e.prototype);if(s!=null){const f=s.constructor;if(f!==nt&&typeof f=="function"){const u=q(f).shape;for(const h of ct(u))if(h in r&&r[h]!==u[h])throw new Error(`Cannot extend: field '${h}' 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=te(d.ENTITY|d.OBJECT,r),t._entityClass=e,ct(o).length>0&&(t._methods=o),typeof o.__subscribe=="function"&&(t._entityConfig={hasSubscribe:!0});const c=e;c.cache&&(t._entityCache=c.cache),Pt.set(e,t)}return t}function Be(e){return q(e)}function se(e,t){if(t==null)return;const n=new Map;if(Array.isArray(t))for(const i of t){const[r,s]=i,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&&n.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&&n.set(a,s)}}return n.size>0?n:void 0}function oe(e){return Array.isArray(e)?e.map(t=>q(t)):[q(e)]}function Ye(e,t){const n=oe(e),i=n.length===1?n[0]:_t(...n.map(o=>o)),r=d.ARRAY|d.LIVE,s=new v(r,i);return s._liveConfig=U.array(n,se(n,t?.constraints),t?.sort),s}function Ge(e,t,n){const i=oe(t),r=e,s=d.LIVE,o=new v(s,void 0);return o._liveConfig=U.value(i,se(i,n?.constraints),r,n.onCreate,n.onUpdate,n.onDelete),o}const ae={format:Qe,typename:qe,const:Ve,enum:ee,id:d.ID|d.STRING|d.NUMBER,string:d.STRING,number:d.NUMBER,boolean:d.BOOLEAN,null:d.NULL,undefined:d.UNDEFINED,array:Ie,object:Me,record:ke,union:_t,nullish:$e,optional:Le,nullable:Ue,result:Fe,entity:Be,liveArray:Ye,liveValue:Ge};function Y(e){if(e instanceof V)return Array.from(e).map(i=>typeof i=="string"?`"${i}"`:String(i)).join(" | ");if(e instanceof Set)return Array.from(e).map(i=>typeof i=="string"?`"${i}"`:String(i)).join(" | ");if(typeof e=="string")return`"${e}"`;if(typeof e=="boolean")return String(e);if(typeof e=="number"){if((e&d.HAS_FORMAT)!==0){const r=Tt(e);if(r)return`"${r}"`}const i=[];return e&d.UNDEFINED&&i.push("undefined"),e&d.NULL&&i.push("null"),e&d.NUMBER&&i.push("number"),e&d.STRING&&i.push("string"),e&d.BOOLEAN&&i.push("boolean"),e&d.OBJECT&&i.push("object"),e&d.ARRAY&&i.push("array"),i.length===0?"unknown":i.length===1?i[0]:i.join(" | ")}let t=e.mask;if(t&d.UNION){const n=e,i=[];if(n.values!==void 0&&n.values.size>0)for(const s of n.values){const o=typeof s=="string"?`"${s}"`:String(s);i.push(o)}if(n.shape!==void 0){n.shape[I]!==void 0&&i.push(`Array<${Y(n.shape[I])}>`),n.shape[k]!==void 0&&i.push(`Record<string, ${Y(n.shape[k])}>`);for(const[s,o]of Object.entries(n.shape))s!==I&&s!==k&&i.push(s)}if(t=n.mask,(t&d.HAS_FORMAT)!==0){const s=Tt(t);s&&i.push(`"${s}"`)}return t&d.UNDEFINED&&i.push("undefined"),t&d.NULL&&i.push("null"),t&d.NUMBER&&i.push("number"),t&d.STRING&&i.push("string"),t&d.BOOLEAN&&i.push("boolean"),i.length===0?"union":i.join(" | ")}if(t&d.ENTITY)return`Entity<${e.typenameValue}>`;if(t&d.ARRAY){const n=e.shape;return`Array<${Y(n)}>`}if(t&d.RECORD){const n=e.shape;return`Record<string, ${Y(n)}>`}if(t&d.OBJECT){const n=e.typenameValue;return n?`Object<${n}>`:"object"}return"unknown"}function B(e,t,n){return new TypeError(`Validation error at ${e}: expected ${Y(t)}, got ${typeof n=="object"?n===null?"null":Array.isArray(n)?"array":"object":typeof n}`)}const ce=Array.isArray;function jt(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 ce(e)?d.ARRAY:d.OBJECT;default:throw new Error(`Invalid type: ${typeof e}`)}}function He(e){return $(e)}function $(e){if(e===null||typeof e!="object")return e;if(ce(e))return e.map(n=>$(n));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){const n=new Map;for(const[i,r]of e)n.set($(i),$(r));return n}if(e instanceof Set){const n=new Set;for(const i of e)n.add($(i));return n}const t={};for(const n of Object.keys(e))t[n]=$(e[n]);return t}const Ct=Object.entries,We=()=>{};class ut{queryClient=void 0;preloadedEntities=void 0;warn=We;isPartialEvent=!1;seen=void 0;seenByKey=void 0;reset(t,n,i,r=!1){this.queryClient=t,this.preloadedEntities=n,this.warn=i,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 fe(e,t,n){return T(e,t,n,"")}function ze(e,t,n){return Ot(e,t,n)}function $t(e,t,n,i){const r=e>>Et;if((e&d.IS_EAGER_FORMAT)!==0)try{return new H(t,r,!0)}catch(o){if((e&d.UNDEFINED)!==0){n.warn("Invalid formatted value for optional type, defaulting to undefined",{value:t,path:i,error:o instanceof Error?o.message:String(o)});return}throw o}return new H(t,r,!1)}function T(e,t,n,i){const r=t;if(r instanceof V){const c=r.get(e);if(c===void 0)throw B(i,r,e);return c}if(r instanceof Set){if(!r.has(e))throw B(i,r,e);return e}if(typeof r=="string"){if(e==null)return r;if(e!==r)throw B(i,r,e);return e}if(typeof r=="number"){const c=jt(e);if((r&c)===0){if((r&d.UNDEFINED)!==0){n.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:i});return}throw B(i,r,e)}return(r&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?$t(r,e,n,i):e}const s=r.mask,o=r._liveConfig;if(o!==void 0&&o.type===tt.Value)return o.valueType!==void 0?T(e,o.valueType,n,i):e;if((s&d.PARSE_RESULT)!==0)try{return{success:!0,value:T(e,r.shape,n,i)}}catch(c){return{success:!1,error:c instanceof Error?c:new Error(String(c))}}const a=jt(e);if((s&a)===0&&!r.values?.has(e)){if((s&d.UNDEFINED)!==0){n.warn("Invalid value for optional type, defaulting to undefined",{value:e,path:i});return}throw B(i,s,e)}return a<d.OBJECT?(s&d.HAS_FORMAT)!==0&&e!==null&&e!==void 0?$t(s,e,n,i):e:(s&d.UNION)!==0?Je(a,e,r,n,i):a===d.ARRAY?ue(e,r.shape,n,i):(s&d.RECORD)!==0?de(e,r.shape,n,i):(s&d.ENTITY)!==0&&n.queryClient!==void 0?Ot(e,r,n):le(e,r,n,i)}function Je(e,t,n,i,r){if(e===d.ARRAY){const s=n.shape[I];return s===void 0||typeof s=="number"?t:ue(t,s,i,r)}else{const s=n.typenameField,o=s?t[s]:void 0;if(o===void 0||typeof o!="string"){const c=n.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 de(t,c,i,r)}const a=n.shape[o];if(a===void 0||typeof a=="number")throw new Error(`Unknown typename '${o}' in union`);return a.mask&d.ENTITY&&i.queryClient!==void 0?Ot(t,a,i):le(t,a,i,r)}}function ue(e,t,n,i){const r=[];for(let s=0;s<e.length;s++)try{r.push(T(e[s],t,n,`${i}[${s}]`))}catch(o){n.warn("Failed to parse array item, filtering out",{index:s,value:e[s],error:o instanceof Error?o.message:String(o)})}return r}function de(e,t,n,i){for(const[r,s]of Ct(e))e[r]=T(s,t,n,`${i}["${r}"]`);return e}function le(e,t,n,i){if(R.has(e))return e;const r=t.shape;for(const[s,o]of Ct(r))e[s]=T(e[s],o,n,`${i}.${s}`);return e}function Ot(e,t,n){const i=n.queryClient,r=n.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=x.hashValue([t.typenameValue,o])}const a=n.seenByKey.get(s);if(a!==void 0)return a.data;if(r!==void 0){const _=i.entityMap.getEntity(s)?.data??r.get(s);if(_===void 0)throw new Error(`Cached entity ${s} not found in preloaded map`);e=_}const c={};typeof t.idField=="symbol"&&(c[t.idField]=o);const f=i.entityMap.getEntity(s),l=n.isPartialEvent&&f!==void 0,u={key:s,shape:t,data:c,rawKeys:l?new Set(Object.keys(e)):void 0};n.seen.set(c,u),n.seenByKey.set(s,u);const h=`[[${t.typenameValue}:${o}]]`,g=t.shape;for(const[p,_]of Ct(g))l&&!(p in e)||(c[p]=T(e[p],_,n,`${h}.${p}`));return c}function Xe(e,t){return Ze(e,t.shape,t.typenameField)}function Ze(e,t,n){if(t===void 0)return!0;for(const i of Object.keys(t)){if(i===n)continue;const r=t[i];if(r instanceof v){if((r.mask&d.UNDEFINED)!==0)continue;if(!(i in e)||e[i]===void 0)return!1}else if(typeof r=="number"){if((r&d.UNDEFINED)!==0)continue;if(!(i in e)||e[i]===void 0)return!1}else if(!(i in e)||e[i]===void 0)return!1}return!0}const tn=Object.prototype,J=new WeakMap;function D(e){if(typeof e!="object"||e===null)return e;if(it.has(e))return D(e.getValue());if(R.has(e))return e;if(Array.isArray(e)){let t=J.get(e);return t===void 0&&(t=new Proxy(e,en),J.set(e,t)),t}if(Object.getPrototypeOf(e)===tn){let t=J.get(e);return t===void 0&&(t=new Proxy(e,nn),J.set(e,t)),t}return e}const en={get(e,t,n){if(typeof t=="string"){const i=Number(t);if(Number.isInteger(i)&&i>=0&&i<e.length)return D(e[i])}return Reflect.get(e,t,n)},set(){throw new Error("Cannot mutate a read-only array")},deleteProperty(){throw new Error("Cannot mutate a read-only array")}},nn={get(e,t,n){return typeof t=="string"?D(e[t]):Reflect.get(e,t,n)},set(){throw new Error("Cannot mutate a read-only object")},deleteProperty(){throw new Error("Cannot mutate a read-only object")},has(e,t){return t in e},ownKeys(e){return Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Object.getOwnPropertyDescriptor(e,t)}},rn=(e,t,n)=>{const i=e,r=Object.keys(i),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=i[f];let u;typeof l=="function"?u=l:u=n(l,s?.[f]),a[f]=u,!o&&u!==s?.[f]&&(o=!0)}return o?a:s};x.registerCustomSnapshot(nt,rn);class sn{_notifier;_queryClient;_proxies=new Map;key;typename;id;idField;data;refCount=0;entityRefs;liveCollections=[];satisfiedDefs=new WeakSet;parseId=-1;_entityCache;_extraMethods;_extraGetters;constructor(t,n,i,r,s,o){this._notifier=b.notifier(),this._queryClient=o,this.key=t,this.typename=n,this.id=i,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)return;if(this.refCount<0)throw new Error(`Entity ${this.typename}:${this.id} released more times than retained`);const t=this._entityCache?.gcTime;t!==void 0?this._queryClient.gcManager.schedule(this.key,t,et.Entity):this.evict()}evict(){const t=this.liveCollections.slice();this.liveCollections.length=0;for(const i of t)i.destroy();this._queryClient.entityMap.remove(this.key);const n=this.entityRefs;if(this.entityRefs=void 0,n)for(const i of n.keys())i.release()}setChildRefs(t,n){const i=this.entityRefs;if(t!==void 0&&t.size>0)for(const r of t.keys())(i===void 0||!i.has(r))&&r.retain();if(i!==void 0&&i.size>0)for(const r of i.keys())(t===void 0||!t.has(r))&&r.release();this.entityRefs=t,n&&this.save()}addChildRef(t){this.entityRefs===void 0&&(this.entityRefs=new Map);const n=this.entityRefs.get(t)??0;this.entityRefs.set(t,n+1),n===0&&t.retain(),this.save()}removeChildRef(t){if(this.entityRefs===void 0)return;const n=this.entityRefs.get(t);n!==void 0&&(n<=1?(this.entityRefs.delete(t),t.release()):this.entityRefs.set(t,n-1),this.save())}getProxy(t){const n=t;let i=this._proxies.get(n);return i===void 0&&(i=an(this,this.key,t,this._notifier,this._queryClient),this._proxies.set(n,i)),i}get proxy(){return this._proxies.values().next().value}satisfiesDef(t){return this.satisfiedDefs.has(t)?!0:Xe(this.data,t)?(this.satisfiedDefs.add(t),!0):!1}save(){this._queryClient.entityMap.save(this)}notify(){this._notifier.notify()}consume(){this._notifier.consume()}}function on(e,t,n){const i=[];for(const r of e){if(typeof r!="object"||r===null)continue;const s=R.get(r);if(s===void 0)continue;const o=n.entityMap.getEntity(s);o!==void 0&&o.satisfiesDef(t)&&i.push(r)}return i}function an(e,t,n,i,r){const s=n.shape??{},o=n,a=o._methods,c=o._entityClass,f=o._entityConfig,l=c?c.prototype:nt.prototype,u=n.typenameField,h=new Map,g=new Map,p=()=>({__entityRef:t});let _;f?.hasSubscribe&&a&&"__subscribe"in a&&(_=b.relay(E=>{const y=w=>{w.__eventSource=t,r.applyMutationEvent(w)},C=a.__subscribe.call(m,y);return E.value=m,C}));let m;if(u&&!(u in s))throw new Error(`typenameField "${u}" must be declared in the entity shape`);const S=Object.keys(s);if(S.includes("__typename")||S.push("__typename"),a)for(const E of Object.keys(a))S.includes(E)||S.push(E);let P,A=S;function K(){const E=e._extraMethods;if(E!==P){if(P=E,A=S.slice(),E!==void 0)for(const C of Object.keys(E))A.includes(C)||A.push(C);const y=e._extraGetters;if(y!==void 0)for(const C of Object.keys(y))A.includes(C)||A.push(C)}return A}const Q={getPrototypeOf(){return l},get(E,y,C){if(typeof y=="symbol")return Reflect.get(l,y,C);if(y==="toJSON")return p;if(y==="__context")return r.getContext();if(y==="__typename")return e.typename;if(_?.value,i.consume(),typeof y=="string"){const F=e._extraGetters;if(F!==void 0&&y in F)return F[y]();const N=e._extraMethods;if(N!==void 0&&y in N){let O=h.get(y);return O||(O=N[y].bind(m),h.set(y,O)),O}if(a&&y in a){let O=h.get(y);return O||(O=b.reactiveMethod(m,a[y].bind(m)),h.set(y,O)),O}}const w=e.data[y];if(typeof w=="object"&&w!==null&&it.has(w))return D(w.getValue());if(Array.isArray(w)&&typeof y=="string"){const F=s[y];if(F instanceof v&&(F.mask&d.ARRAY)!==0){const N=F.shape;if(N instanceof v&&(N.mask&d.ENTITY)!==0){const O=N.typenameValue;if(O!==void 0){const Nt=r.getEntityDefsForTypename(O);if(Nt!==void 0&&Nt.length>1){const rt=g.get(y);if(rt!==void 0&&rt.source===w)return D(rt.filtered);const Dt=on(w,N,r);return g.set(y,{source:w,filtered:Dt}),D(Dt)}}}}return D(w)}return D(w)},set(){throw new Error("Entity properties are read-only")},has(E,y){if(y==="__typename")return!0;if(typeof y=="string"){const C=e._extraGetters;if(C&&y in C)return!0;const w=e._extraMethods;if(w&&y in w||a&&y in a)return!0}return y in s},ownKeys(){return K()},getOwnPropertyDescriptor(E,y){if(y==="__typename")return{enumerable:!0,configurable:!0,value:e.typename,writable:!1};if(y in s)return{enumerable:!0,configurable:!0,value:Q.get(E,y,m),writable:!1};if(typeof y=="string"){const C=e._extraGetters;if(C&&y in C)return{enumerable:!0,configurable:!0,value:Q.get(E,y,m),writable:!1};const w=e._extraMethods;if(w&&y in w)return{enumerable:!0,configurable:!0,value:Q.get(E,y,m),writable:!1};if(a&&y in a)return{enumerable:!1,configurable:!0,value:Q.get(E,y,m),writable:!1}}}};return m=new Proxy({},Q),R.set(m,t),b.setScopeOwner(m,r),m}class cn{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,n,i,r){let s=this.instances.get(t);if(s===void 0){const o=i.idField;if(o===void 0)throw new Error(`Entity id field is required ${i.typenameValue}`);const a=n[o];if(typeof a!="string"&&typeof a!="number")throw new Error(`Entity id must be string or number: ${i.typenameValue}`);const c=i;s=new sn(t,i.typenameValue,a,o,n,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 n;if(t.entityRefs){n=new Set;for(const i of t.entityRefs.keys())n.add(i.key)}this.persistEntity(t.key,t.data,n)}}class Rt{onlineSignal;manualOverride=void 0;eventListenersAttached=!1;constructor(t){const n=t??this.detectOnlineStatus();this.onlineSignal=b.signal(n),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 St{static onlineSignal=b.signal(!0);get isOnline(){return!0}setNetworkStatus(t){}clearManualOverride(){}getOnlineSignal(){return St.onlineSignal}destroy(){}}const he=new Rt,fn=b.context(he);function xt(e,t=typeof window>"u"){let n;e===!1?n=0:e===void 0||e===!0?n=t?0:3:typeof e=="number"?n=e:n=e.retries;const i=typeof e=="object"&&e.retryDelay?e.retryDelay:r=>1e3*Math.pow(2,r);return{retries:n,retryDelay:i}}class un{static cache;static adapter;params;config;constructor(){return gt(this)}}const Lt=new WeakMap;class z{constructor(t,n){this.captured=n,this.statics=t}statics;createExecutionContext(t,n){return at(this.captured,t,n)}resolveOptions(t){const{methods:n}=this.captured,i=n.getConfig?n.getConfig.call(t):t.config,r=xt(i?.retry);return{config:i,retryConfig:r}}static for(t){let n=Lt.get(t);if(n!==void 0)return n;const i=new t,r=zt(i),s=String(r.methods.getIdentityKey.call(r.fields)),o=r.fields.result,a=o instanceof v?o:ae.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 h=typeof u.prototype.sendNext=="function",g=c?a:new v(d.ENTITY|d.OBJECT,a.shape,void 0,void 0,s,yt);return n=new z({id:s,shape:g,cache:f,rawFetchNext:l,hasSendNext:h,isEntityResult:c,adapterClass:u},r),Lt.set(t,n),n}}const dn=(e,t)=>{const n=z.for(e);return At(n,t)};function ln(e,...t){const n=z.for(e),i=b.getContext(Re);if(i===void 0)throw new Error("QueryClient not found");const r=t[0];return i.getQuery(n,r)}function dt(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 ye(e,t){return new Promise((n,i)=>{if(t?.aborted){i(dt(t));return}const r=setTimeout(n,e);t?.addEventListener("abort",()=>{clearTimeout(r),i(dt(t))},{once:!0})})}async function lt(e,t,n){if(t.retries<0)throw new Error("retries must be non-negative");const i=Math.max(0,t.retries);let r;for(let s=0;s<=i;s++){if(n?.aborted)throw dt(n);try{return await e()}catch(o){if(r=o,s>=i)throw o;await ye(t.retryDelay(s),n)}}throw r}class hn{def;queryKey;storageKey=-1;relay;queryClient;initialized=!1;updatedAt=void 0;params=void 0;unsubscribe=void 0;_relayState=void 0;_isActive=!1;wasPaused=!1;currentParams=void 0;debounceTimer=void 0;config=void 0;retryConfig=xt(void 0);_abortController=void 0;_executionCtx=void 0;_executionCtxKey=-1;rootEntity;_extraMethods={};_queryId=0;get key(){return this.queryKey}get relayState(){if(!this._relayState)throw new Error("Relay state not initialized");return this._relayState}constructor(t,n,i,r){this.def=t,this.queryClient=n,this.queryKey=i,this.params=r,this._extraMethods={__refetch:this.refetch},t.statics.hasSendNext&&(this._extraMethods.__fetchNext=this.fetchNext);const s=Kt(r);this._queryId=s!==void 0?x.hashValue(s):0,this.relay=b.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;const f=this.config?.gcTime??Qt.DEFAULT_GC_TIME;this.queryClient.gcManager.schedule(this.queryKey,f,et.Query)},c=(f=!1)=>{const{wasPaused:l,isPaused:u,initialized:h}=this;if(this.wasPaused=u,u&&!l&&h){a();return}this._isActive=!0;const g=Kt(this.params),p=At(this.def,g),_=p!==this.storageKey;_&&(this.currentParams=g,this.storageKey=p),this.getOrCreateExecutionContext(),this.initialized?l||f?(this.queryClient.activateQuery(this),f&&this.updatedAt!==void 0&&this.setupSubscription(),this.relayState.isPending&&this._abortController===void 0?this.runQueryImmediately():(this.config?.refreshStaleOnReconnect??!0)&&this.isStale&&this.runDebounced()):_&&(this.setupSubscription(),this.runDebounced()):(this.queryClient.activateQuery(this),this.initialize())};return c(!0),{update:c,deactivate:a}},{desc:`Query(${t.statics.id})`})}applyData(t,n,i=!1,r){const s=this.def;return this.rootEntity=this.queryClient.parseAndApplyRootEntity(t,this._queryId,s.statics.shape,n,i,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,n=this.relayState;this.initialized=!0;let i;try{i=await t.loadCachedQuery(this.def,this.storageKey),i!==void 0&&(this.updatedAt=i.updatedAt,n.value=this.applyData(i.value,!1,!1,i.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(i!==void 0&&this.setupSubscription(),i===void 0||this.isStale){if(await ye(0),this.isPaused)return;this.runQueryImmediately()}}catch(r){n.setError(r)}}setupSubscription(){this.unsubscribe?.(),this.unsubscribe=void 0;const t=this.config?.subscribe;if(!t)return;const n=this._executionCtx;this.unsubscribe=t.call(n,i=>{i.__eventSource=this.queryKey,this.queryClient.applyMutationEvent(i)})}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.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 n=this.getOrCreateExecutionContext(),i=this.queryClient.getAdapter(t.statics.adapterClass),r=this._abortController?.signal??new AbortController().signal;return lt(async()=>{const s=await i.send(n,r);this.updatedAt=Date.now();const o=this.applyData(s,!0);return this.saveQueryMetadata(),this.unsubscribe===void 0&&this.setupSubscription(),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 n=this._fetchNextAbort.signal,i=this.getOrCreateExecutionContext();i.resultData=this.rootEntity.data;const r=this.queryClient.getAdapter(t.statics.adapterClass);return lt(async()=>{const s=await r.sendNext(i,n);this.updatedAt=Date.now();const o=this.applyData(s,!0,!0);return this.saveQueryMetadata(),o},this.retryConfig,n)}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 n=this.queryClient.networkManager.getOnlineSignal().value;switch(t){case L.Online:return!n;case L.OfflineFirst:return!n&&this.updatedAt===void 0;default:return!1}}}class yn{def;queryClient;_inFlight=!1;task;constructor(t,n){this.def=t,this.queryClient=n,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 n=await this.executeWithRetry(t),i=this.validateResponse(n);return this.processEffects(t,i),i}finally{this._inFlight=!1}},{desc:`Mutation(${this.def.id})`})}validateResponse(t){const n=this.def.responseShape;if(!(n instanceof v))return t;const i=this.queryClient.getContext().log?.warn??(()=>{}),r=new ut;return r.reset(void 0,void 0,i),fe(t,n,r)}processEffects(t,n){let i;if(this.def.hasGetEffects){const s=at(this.def.captured,t??{},this.queryClient.getContext());s.result=n,i=s.getEffects()}else if(this.def.effects!==void 0){const s={params:t,result:n};i=G(this.def.effects,s)}if(i===void 0)return;const r=this.queryClient;st(i.creates,"create",r),st(i.updates,"update",r),st(i.deletes,"delete",r),i.invalidates&&r.invalidateQueries(i.invalidates)}executeWithRetry(t){const n=xt(this.def.config?.retry,!0),i=this.queryClient.getAdapter(this.def.adapterClass);if(!i.sendMutation)throw new Error(`Adapter "${this.def.adapterClass.name}" does not implement sendMutation(). Add a sendMutation() method to handle mutations.`);return lt(async()=>{const r=new AbortController,s=at(this.def.captured,t??{},this.queryClient.getContext());return await i.sendMutation(s,r.signal)},n)}}function pn(e){return typeof e=="string"?e:q(e).typenameValue}function st(e,t,n){if(e)for(const[i,r]of e){const s=pn(i);s!==void 0&&n.applyMutationEvent({type:t,typename:s,data:r})}}const pe="__eventSource";function ge(e){return{field:e,segments:e.indexOf(".")!==-1?e.split("."):void 0}}function gn(e){return e.map(ge)}function vn(e,t){if(t.segments===void 0)return e[t.field];let n=e;for(const i of t.segments){if(n==null)return;n=n[i]}return n}function ve(e,t){const n=[];for(let i=0;i<t.length;i++){const r=t[i],s=vn(e,r);if(s===void 0)return;n.push(r.field,s)}return x.hashValue(n)}function mn(e,t){if(e===void 0)return;const n=new Map;for(const[i,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(Ht(f)){const u=Wt(f);l=vt(u,t)}else l=f;if(l===void 0){a=!1;break}o.push(c,l)}a&&n.set(i,x.hashValue(o))}return n.size>0?n:void 0}function Ut(e,t){const n=e.get(t);if(n!==void 0)return n.map(([i])=>i).sort()}class _n{fields;fieldPaths;_bindings=new Map;constructor(t){this.fields=t,this.fieldPaths=t.map(ge)}register(t,n){let i=this._bindings.get(t);i===void 0&&(i=new Set,this._bindings.set(t,i)),i.add(n)}unregister(t,n){const i=this._bindings.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._bindings.delete(t))}getMatching(t){return this._bindings.get(t)}get isEmpty(){return this._bindings.size===0}}function qt(e){return x.hashValue(e)}class wn{_groups=new Map;getOrCreateGroup(t){const n=qt(t);let i=this._groups.get(n);return i===void 0&&(i=new _n(t),this._groups.set(n,i)),i}register(t,n,i){this.getOrCreateGroup(n).register(t,i)}unregister(t,n,i){const r=qt(n),s=this._groups.get(r);s!==void 0&&(s.unregister(t,i),s.isEmpty&&this._groups.delete(r))}registerBinding(t,n){const i=t._constraintHashes.get(n);if(i===void 0)return;const r=Ut(t._constraintFieldRefs,n);r!==void 0&&this.register(i,r,t)}unregisterBinding(t,n){const i=t._constraintHashes.get(n);if(i===void 0)return;const r=Ut(t._constraintFieldRefs,n);r!==void 0&&this.unregister(i,r,t)}routeEvent(t,n,i,r,s,o){for(const a of this._groups.values()){const c=ve(n,a.fieldPaths);if(c===void 0)continue;const f=a.getMatching(c);if(f!==void 0)for(const l of f)l.onEvent(t,i,r,s,o)}}}function Vt(e){const t=new Set;for(const n of e)if(typeof n=="object"&&n!==null){const i=j(n);i!==void 0&&t.add(i)}return t}class me{_queryClient;_parent;_constraintHashes;_entityDefsByTypename;_constraintFieldRefs;instance;constructor(t,n,i,r,s,o){this._queryClient=i,this._parent=r,this._constraintHashes=s,this._constraintFieldRefs=n,this.instance=o,this._entityDefsByTypename=new Map;for(const a of t)a.typenameValue!==void 0&&this._entityDefsByTypename.set(a.typenameValue,a);it.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,n,i,r,s){const o=this._entityDefsByTypename.get(t);if(o===void 0)return;const a=this._queryClient.entityMap.getEntity(n);if(i==="delete"){const f=a!==void 0?a.getProxy(o):s;f!==void 0&&(this.instance.onEvent(n,f,s??a?.data??{},"delete"),r?.());return}if(a===void 0||!a.satisfiesDef(o))return;r?.();const c=a.getProxy(o);this.instance.onEvent(n,c,a.data,i)}destroy(){this._queryClient.unregisterLiveCollection(this);const t=this._parent.liveCollections,n=t.indexOf(this);n!==-1&&t.splice(n,1)}}class En{_notifier;_items;_keys;_outputSignal;_queryClient;_parent;constructor(t,n,i,r,s,o){this._notifier=b.notifier(),this._items=i,this._keys=Vt(i),this._queryClient=t,this._parent=n;const a=r!==void 0&&s!==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 u of f){if(typeof u!="object"||u===null){l.push(u);continue}const h=j(u);if(h===void 0){l.push(u);continue}const g=t.entityMap.getEntity(h);if(g===void 0){l.push(u);continue}g.consume(),ve(g.data,r)===s&&l.push(u)}f=l}return c&&(f=(f===this._items?f.slice():f).sort(o)),f}))}onEvent(t,n,i,r){switch(r){case"create":this.add(t,n);break;case"update":!this.has(t)&&n!==void 0&&this.add(t,n);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,n){if(this._keys.has(t))return!1;this._keys.add(t),this._items.push(n);const i=this._queryClient.entityMap.getEntity(t);return i!==void 0&&(this._parent.addChildRef(i),i.save()),this._notifier.notify(),!0}remove(t){if(!this._keys.has(t))return!1;this._keys.delete(t);const n=this._findIndex(t);n!==-1&&this._items.splice(n,1);const i=this._queryClient.entityMap.getEntity(t);return i!==void 0&&this._parent.removeChildRef(i),this._notifier.notify(),!0}has(t){return this._keys.has(t)}reset(t){const n=this._items,i=Array.isArray(t)?t:[];this._items=i,this._keys=Vt(i);for(const r of i)if(typeof r=="object"&&r!==null){const s=j(r);if(s!==void 0){const o=this._queryClient.entityMap.getEntity(s);o!==void 0&&this._parent.addChildRef(o)}}for(const r of n)if(typeof r=="object"&&r!==null){const s=j(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 n of t){if(typeof n!="object"||n===null)continue;const i=j(n);i!==void 0&&this.add(i,n)}}_findIndex(t){for(let n=0;n<this._items.length;n++){const i=this._items[n];if(typeof i=="object"&&i!==null&&j(i)===t)return n}return-1}}class bn{_notifier;_value;_createdKeys;_deletedKeys;_queryClient;_parent;_onCreate;_onUpdate;_onDelete;constructor(t,n,i,r,s,o){this._notifier=b.notifier(),this._value=i,this._createdKeys=new Set,this._deletedKeys=new Set,this._queryClient=t,this._parent=n,this._onCreate=r,this._onUpdate=s,this._onDelete=o}onEvent(t,n,i,r){switch(r){case"create":if(this._createdKeys.has(t))return;this._createdKeys.add(t),this._value=this._onCreate(this._value,n);break;case"update":this._value=this._onUpdate(this._value,n??i);break;case"delete":if(this._deletedKeys.has(t))return;this._deletedKeys.add(t),this._value=this._onDelete(this._value,n??i);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 _e(e,t,n,i,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,[[pe,n.key]])}}const o=mn(s,i)??new Map;let a;if(e.type===tt.Array){let f,l;if(e.constraintFieldRefs!==void 0&&o.size>0&&o.size===1)for(const[u]of e.constraintFieldRefs){const h=o.get(u);if(h!==void 0){l=h;const g=e.constraintFieldRefs.get(u);g!==void 0&&(f=gn(g.map(([p])=>p)));break}}a=new En(r,n,Array.isArray(t)?t:[],f,l,e.sort)}else a=new bn(r,n,t,e.onCreate,e.onUpdate,e.onDelete);const c=new me(e.entityDefs,s,r,n,o,a);return n.liveCollections.push(c),r.registerLiveCollection(c),c}const we=Object.entries,Ee=Object.prototype;function ot(e,t,n,i=!1){const r=e.queryClient;r.currentParseId++;const s=e.seen,o=new Map;return{data:W(t,s,r,n,o,i),entityRefs:o}}function W(e,t,n,i,r,s){if(typeof e!="object"||e===null)return e;const o=t.get(e);if(o!==void 0)return Cn(o,t,n,i,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 H)&&!R.has(c)&&(e[a]=W(c,t,n,i,r,s))}return e}if(Object.getPrototypeOf(e)===Ee&&!R.has(e)){const a=e;for(const c of Object.keys(a)){const f=a[c];typeof f=="object"&&f!==null&&!(f instanceof H)&&!R.has(f)&&(a[c]=W(f,t,n,i,r,s))}}return e}function be(e){return typeof e=="object"&&e!==null&&!(e instanceof H)&&!R.has(e)}function Cn(e,t,n,i,r,s){const{key:o,data:a,shape:c,rawKeys:f}=e,l=c.shape,u=n.prepareEntity(o,a,c),h=u.data,g=h!==a,p=g&&f!==void 0&&u.entityRefs!==void 0?new Map(u.entityRefs):new Map;if(g?(Ce(l,a,h,f,u,h,t,n,i,p,s),u.notify()):Oe(l,a,u,a,t,n,i,p,s),s&&u.liveCollections.length>0)for(const m of u.liveCollections){const S=m.instance.getRawValue();if(Array.isArray(S))for(const P of S){if(typeof P!="object"||P===null)continue;const A=R.get(P);if(A===void 0)continue;const K=n.entityMap.getEntity(A);K!==void 0&&p.set(K,(p.get(K)??0)+1)}}u.setChildRefs(p.size>0?p:void 0,i);const _=u.getProxy(c);return r.set(u,(r.get(u)??0)+1),_}function Ce(e,t,n,i,r,s,o,a,c,f,l){for(const[u,h]of we(e))if(!(i!==void 0&&!i.has(u)))if(be(t[u])&&(t[u]=W(t[u],o,a,c,f,l)),h instanceof v&&h._liveConfig!==void 0){const g=n[u];g instanceof me?l?g.append(t[u]):g.reset(t[u]):n[u]=_e(h._liveConfig,t[u],r,s,a)}else{const g=t[u],p=n[u];if(ht(g)&&ht(p)){const _=h instanceof v&&h.shape!==void 0?h.shape:void 0;if(_!==void 0)Ce(_,g,p,void 0,r,s,o,a,c,f,l);else for(const m of Object.keys(g))p[m]=g[m];n[u]=p}else n[u]=g}}function Oe(e,t,n,i,r,s,o,a,c){for(const[f,l]of we(e))if(f in t)if(be(t[f])&&(t[f]=W(t[f],r,s,o,a,c)),l instanceof v&&l._liveConfig!==void 0)t[f]=_e(l._liveConfig,t[f],n,i,s);else{const u=t[f];if(ht(u)){const h=l instanceof v&&l.shape!==void 0?l.shape:void 0;h!==void 0&&Oe(h,u,n,i,r,s,o,a,c)}}}function ht(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Ee&&!R.has(e)}function On(e){if(e!==void 0)return typeof e=="string"?e:typeof e=="function"?e():e.value}function Rn(e){return b.isSignal(e)}function Kt(e){if(e===void 0)return;const t={};for(const[n,i]of Object.entries(e))Rn(i)?t[n]=i.value:t[n]=i;return t}const At=(e,t)=>x.hashValue([e.statics.id,t]);class Sn{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:n=new It.SyncQueryStore(new It.MemoryPersistentStore),log:i,evictionMultiplier:r,adapters:s,networkManager:o,gcManager:a,...c}=t;this.isServer=typeof window>"u",this.store=n,this.context={...c,log:i??console,evictionMultiplier:r},this.gcManager=t.gcManager??(this.isServer?new Yt:new Bt(this.handleEviction,r)),this.networkManager=t.networkManager??new Rt,this.entityMap=new cn((u,h,g)=>this.store.saveEntity(u,h,g));for(const u of t.adapters??[])this.adapters.set(u.constructor,u),u.register(this);const f=this.networkManager.getOnlineSignal(),l=b.watcher(()=>f.value);this.networkUnsubscribe=l.addListener(()=>{const u=f.value;for(const h of this.adapters.values())h.onNetworkStatusChange?.(u)},{skipInitial:!0}),this.store.purgeStaleQueries?.()}getAdapter(t){const n=this.adapters.get(t);if(n)return n;let i;for(const s of this.adapters.values())if(s instanceof t){if(i!==void 0)throw new Error(`Adapter lookup for ${t.name} matches multiple registered adapters: ${i.constructor.name} and ${s.constructor.name}. Register only one adapter per lookup base on a single QueryClient, or split into separate QueryClients.`);i??=s}if(i!==void 0)return this.adapters.set(t,i),i;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 n=t.typenameValue;if(n===void 0||t._entityClass===void 0)return;const i=this.typenameRegistry.get(n);if(i!==void 0){if(i.indexOf(t)!==-1)return;i.push(t),this.mergedDefCache.delete(n),this.getMergedDef(n)}else this.typenameRegistry.set(n,[t])}getEntityDefsForTypename(t){return this.typenameRegistry.get(t)}getMergedDef(t){let n=this.mergedDefCache.get(t);if(n!==void 0)return n;const i=this.typenameRegistry.get(t);if(i!==void 0)return n=v.merge(i),this.mergedDefCache.set(t,n),n}saveQueryData(t,n,i,r,s){const o=s!==void 0&&s.size>0?new Set([...s.keys()].map(a=>a.key)):void 0;this.store.saveQuery(t,n,i,r,o)}activateQuery(t){const{def:n,queryKey:i,storageKey:r,config:s}=t;this.store.activateQuery(n,r);const o=s?.gcTime??Qt.DEFAULT_GC_TIME;this.gcManager.cancel(i,o)}loadCachedQuery(t,n){return this.store.loadQuery(t,n)}getQuery(t,n){const i=At(t,n);let r=this.queryInstances.get(i);return r===void 0&&(r=new hn(t,this,i,n),this.queryInstances.set(i,r)),r.relay}getMutation(t){const n=t.id;let i=this.mutationInstances.get(n);return i===void 0&&(i=new yn(t,this),this.mutationInstances.set(n,i)),i.task}parseData(t,n,i){const r=this.context.log?.warn??(()=>{}),s=new ut;return s.reset(this,i,r),{data:fe(t,n,s),ctx:s}}applyRefs(t,n=!0,i=!1){return ot(t.ctx,t.data,n,i)}parseAndApplyRootEntity(t,n,i,r,s=!1,o){typeof i.idField=="symbol"&&typeof t=="object"&&t!==null&&!("__entityRef"in t)&&(t[yt]=n);const a=this.parseData(t,i,o),c=ot(a.ctx,a.data,r,s),f=R.get(c.data);return this.entityMap.getEntity(f)}prepareEntity(t,n,i){return this.registerEntityDef(i),this.entityMap.getOrCreateEntity(t,n,i,this)}applyMutationEvent(t){const{type:n,typename:i}=t,r=this.getMergedDef(i);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:n==="delete"&&(typeof o=="string"||typeof o=="number")?o:o[s];if(a===void 0)return;const c=x.hashValue([i,a]),f=t.__eventSource,l=typeof o=="object"&&o!==null?o:{},u=this.entityMap.getEntity(c);if(n==="delete"){const _=u!==void 0?u.data:l;this.routeEvent(i,_,c,n,f,void 0,_);return}try{const _=this.context.log?.warn??(()=>{}),m=new ut;m.reset(this,void 0,_,!0);const S=ze(l,r,m);ot(m,S,!0)}catch(_){if(this.context.log?.warn?.("Failed to apply mutation event",_),u===void 0){const m=this.entityMap.getEntity(c);m!==void 0&&m.evict()}return}const h=this.entityMap.getEntity(c);if(h===void 0)return;this.entityMap.save(h);const g=u===void 0;let p=!1;this.routeEvent(i,h.data,c,n,f,()=>{p=!0}),g&&!p&&h.evict()}invalidateQueries(t){for(const n of t){const i=Array.isArray(n),r=i?n[0]:n,s=i?n[1]:void 0,a=z.for(r).statics.id;for(const[,c]of this.queryInstances)c.def.statics.id===a&&(s===void 0||xn(c.resolvedParams,s))&&c.markStale()}}handleEviction=(t,n)=>{if(n===et.Query){const r=this.queryInstances.get(t);if(r===void 0)return;r.rootEntity?.evict(),this.queryInstances.delete(t);return}const i=this.entityMap.getEntity(t);i!==void 0&&i.evict()};getOrCreateMatcher(t){let n=this.constraintRegistry.get(t);return n===void 0&&(n=new wn,this.constraintRegistry.set(t,n)),n}registerLiveCollection(t){for(const[n,i]of t._entityDefsByTypename)this.registerEntityDef(i),this.getOrCreateMatcher(n).registerBinding(t,n)}unregisterLiveCollection(t){for(const n of t._entityDefsByTypename.keys()){const i=this.constraintRegistry.get(n);i!==void 0&&i.unregisterBinding(t,n)}}routeEvent(t,n,i,r,s,o,a){const c=this.constraintRegistry.get(t);if(c===void 0)return;const f=s!==void 0?{...n,[pe]:s}:n;c.routeEvent(t,f,i,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 Re=b.context(void 0);function xn(e,t){if(e===void 0)return!1;for(const n in t)if(e[n]!==t[n])return!1;return!0}exports.ARRAY_KEY=I;exports.Entity=nt;exports.GcManager=Bt;exports.LiveFieldConfig=U;exports.LiveFieldType=tt;exports.Mask=d;exports.NetworkManager=Rt;exports.NetworkManagerContext=fn;exports.NetworkMode=L;exports.NoOpGcManager=Yt;exports.NoOpNetworkManager=St;exports.QUERY_ID=yt;exports.Query=un;exports.QueryClient=Sn;exports.QueryClientContext=Re;exports.RECORD_KEY=k;exports.ValidatorDef=v;exports.createDefinitionProxy=gt;exports.defaultNetworkManager=he;exports.draft=He;exports.extractDefinition=zt;exports.fetchQuery=ln;exports.queryKeyForClass=dn;exports.registerFormat=bt;exports.reifyValue=G;exports.resolveBaseUrl=On;exports.t=ae;
|
|
2
|
-
//# sourceMappingURL=QueryClient-BefSCMoE.js.map
|