fetchium 0.2.4 → 0.3.0
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 +19 -0
- package/dist/cjs/development/QueryClient-QKhS8mhg.js +2 -0
- package/dist/cjs/development/QueryClient-QKhS8mhg.js.map +1 -0
- package/dist/cjs/development/index.js +1 -1
- package/dist/cjs/{production/mutation-LrsiDsl7.js → development/mutation-w67Vpuvw.js} +2 -2
- package/dist/cjs/{production/mutation-LrsiDsl7.js.map → development/mutation-w67Vpuvw.js.map} +1 -1
- package/dist/cjs/development/react/index.js +1 -1
- package/dist/cjs/development/react/index.js.map +1 -1
- package/dist/cjs/development/rest/index.js +1 -1
- package/dist/cjs/development/topic/index.js +1 -1
- package/dist/cjs/production/QueryClient-DIAqDTHF.js +2 -0
- package/dist/cjs/production/QueryClient-DIAqDTHF.js.map +1 -0
- package/dist/cjs/production/index.js +1 -1
- package/dist/cjs/{development/mutation-CUV5TC93.js → production/mutation-CgS9gXW7.js} +2 -2
- package/dist/cjs/{development/mutation-CUV5TC93.js.map → production/mutation-CgS9gXW7.js.map} +1 -1
- package/dist/cjs/production/react/index.js +1 -1
- package/dist/cjs/production/react/index.js.map +1 -1
- package/dist/cjs/production/rest/index.js +1 -1
- package/dist/cjs/production/topic/index.js +1 -1
- package/dist/esm/EntityInstance.d.ts.map +1 -1
- package/dist/esm/QueryResult.d.ts +3 -3
- package/dist/esm/QueryResult.d.ts.map +1 -1
- package/dist/esm/development/{QueryClient-WObL5AFz.js → QueryClient-C9tBdK1Z.js} +347 -330
- package/dist/esm/development/QueryClient-C9tBdK1Z.js.map +1 -0
- package/dist/esm/development/index.js +2 -2
- package/dist/esm/development/{mutation-C3e7FM9D.js → mutation-Dx63NCGk.js} +2 -2
- package/dist/esm/development/{mutation-C3e7FM9D.js.map → mutation-Dx63NCGk.js.map} +1 -1
- package/dist/esm/development/react/index.js +5 -36
- package/dist/esm/development/react/index.js.map +1 -1
- package/dist/esm/development/rest/index.js +2 -2
- package/dist/esm/development/topic/index.js +1 -1
- package/dist/esm/production/{QueryClient-DqHBCvA1.js → QueryClient-D64xo0EA.js} +319 -304
- package/dist/esm/production/QueryClient-D64xo0EA.js.map +1 -0
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/{mutation-BOc53DJi.js → mutation-Aw1JE7VO.js} +2 -2
- package/dist/esm/production/{mutation-BOc53DJi.js.map → mutation-Aw1JE7VO.js.map} +1 -1
- package/dist/esm/production/react/index.js +5 -36
- package/dist/esm/production/react/index.js.map +1 -1
- package/dist/esm/production/rest/index.js +2 -2
- package/dist/esm/production/topic/index.js +1 -1
- package/dist/esm/react/use-query.d.ts +8 -0
- package/dist/esm/react/use-query.d.ts.map +1 -1
- package/dist/esm/types.d.ts +3 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/plugin/docs/api/fetchium-react.md +5 -4
- package/plugin/docs/api/fetchium.md +2 -2
- package/dist/cjs/development/QueryClient-DjKxdY2y.js +0 -2
- package/dist/cjs/development/QueryClient-DjKxdY2y.js.map +0 -1
- package/dist/cjs/production/QueryClient-YzaJT_2g.js +0 -2
- package/dist/cjs/production/QueryClient-YzaJT_2g.js.map +0 -1
- package/dist/esm/development/QueryClient-WObL5AFz.js.map +0 -1
- package/dist/esm/production/QueryClient-DqHBCvA1.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-C9tBdK1Z.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-Dx63NCGk.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-C9tBdK1Z.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-Dx63NCGk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-
|
|
1
|
+
{"version":3,"file":"mutation-Dx63NCGk.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,40 +1,9 @@
|
|
|
1
|
-
import { useReactive as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (Array.isArray(e))
|
|
6
|
-
return e.map(n);
|
|
7
|
-
if (e && typeof e == "object") {
|
|
8
|
-
if (e instanceof Date)
|
|
9
|
-
return new Date(e);
|
|
10
|
-
if (e instanceof RegExp)
|
|
11
|
-
return new RegExp(e);
|
|
12
|
-
if (e instanceof Map)
|
|
13
|
-
return new Map(Array.from(e.entries()).map(([r, o]) => [n(r), n(o)]));
|
|
14
|
-
if (e instanceof Set)
|
|
15
|
-
return new Set(Array.from(e).map(n));
|
|
16
|
-
const t = Object.create(Object.getPrototypeOf(e));
|
|
17
|
-
for (const r of Object.keys(e))
|
|
18
|
-
t[r] = n(e[r]);
|
|
19
|
-
return t;
|
|
20
|
-
}
|
|
21
|
-
return e;
|
|
22
|
-
}
|
|
23
|
-
const y = f((e) => n(e.value)), p = f(
|
|
24
|
-
(e, ...t) => {
|
|
25
|
-
const r = u(e, ...t);
|
|
26
|
-
return new Proxy(r, {
|
|
27
|
-
get(o, c, s) {
|
|
28
|
-
return c === "value" ? y(o) : Reflect.get(o, c, s);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
), m = f((e) => e.value);
|
|
33
|
-
function b(e, ...t) {
|
|
34
|
-
const r = i(p, e, ...t);
|
|
35
|
-
return i(m, r), r;
|
|
1
|
+
import { useReactive as t } from "signalium/react";
|
|
2
|
+
import { k as o } from "../QueryClient-C9tBdK1Z.js";
|
|
3
|
+
function i(e, ...r) {
|
|
4
|
+
return t(() => o(e, ...r));
|
|
36
5
|
}
|
|
37
6
|
export {
|
|
38
|
-
|
|
7
|
+
i as useQuery
|
|
39
8
|
};
|
|
40
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/react/use-query.ts"],"sourcesContent":["import { useReactive } from 'signalium/react';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/react/use-query.ts"],"sourcesContent":["import { useReactive } from 'signalium/react';\nimport { ExtractType, QueryPromise } from '../types.js';\nimport { fetchQuery, Query } from '../query.js';\nimport { HasRequiredKeys, Optionalize, Signalize } from '../type-utils.js';\n\n/**\n * React hook for fetching a query.\n *\n * Returns a structurally-shared deep snapshot of the query's `ReactivePromise`,\n * so memoized children that receive subtrees as props keep stable references\n * when the underlying data is unchanged. Implemented as a thin wrapper around\n * Signalium v3's `useReactive`, which is deep-by-default.\n */\nexport function useQuery<T extends Query>(\n QueryClass: new () => T,\n ...args: HasRequiredKeys<ExtractType<T['params']>> extends true\n ? [params: Optionalize<Signalize<ExtractType<T['params']>>>]\n : [params?: Optionalize<Signalize<ExtractType<T['params']>>> | undefined]\n): QueryPromise<T> {\n return useReactive(() => fetchQuery(QueryClass, ...args)) as QueryPromise<T>;\n}\n"],"names":["useQuery","QueryClass","args","useReactive","fetchQuery"],"mappings":";;AAaO,SAASA,EACdC,MACGC,GAGc;AACjB,SAAOC,EAAY,MAAMC,EAAWH,GAAY,GAAGC,CAAI,CAAC;AAC1D;"}
|
|
@@ -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-C9tBdK1Z.js";
|
|
2
2
|
import { Q as T } from "../QueryAdapter-Bu5UJjE4.js";
|
|
3
|
-
import { M as w } from "../mutation-
|
|
3
|
+
import { M as w } from "../mutation-Dx63NCGk.js";
|
|
4
4
|
class P extends T {
|
|
5
5
|
_fetch;
|
|
6
6
|
_baseUrl;
|