fetchium 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/development/QueryAdapter-DUo338ga.js.map +1 -1
  3. package/dist/cjs/development/QueryClient-BZpqASy3.js +2 -0
  4. package/dist/cjs/development/QueryClient-BZpqASy3.js.map +1 -0
  5. package/dist/cjs/development/index.js +1 -1
  6. package/dist/cjs/{production/mutation-Dk0gznwX.js → development/mutation-COeBCn7p.js} +2 -2
  7. package/dist/cjs/development/mutation-COeBCn7p.js.map +1 -0
  8. package/dist/cjs/development/react/index.js +1 -1
  9. package/dist/cjs/development/rest/index.js +1 -1
  10. package/dist/cjs/development/topic/index.js +1 -1
  11. package/dist/cjs/development/topic/index.js.map +1 -1
  12. package/dist/cjs/production/QueryAdapter-DUo338ga.js.map +1 -1
  13. package/dist/cjs/production/QueryClient-BmoHLlvu.js +2 -0
  14. package/dist/cjs/production/QueryClient-BmoHLlvu.js.map +1 -0
  15. package/dist/cjs/production/index.js +1 -1
  16. package/dist/cjs/{development/mutation-wUhcGxKl.js → production/mutation-CfFdNkYV.js} +2 -2
  17. package/dist/cjs/production/mutation-CfFdNkYV.js.map +1 -0
  18. package/dist/cjs/production/react/index.js +1 -1
  19. package/dist/cjs/production/rest/index.js +1 -1
  20. package/dist/cjs/production/topic/index.js +1 -1
  21. package/dist/cjs/production/topic/index.js.map +1 -1
  22. package/dist/esm/QueryAdapter.d.ts +11 -0
  23. package/dist/esm/QueryAdapter.d.ts.map +1 -1
  24. package/dist/esm/QueryClient.d.ts +5 -5
  25. package/dist/esm/QueryClient.d.ts.map +1 -1
  26. package/dist/esm/QueryResult.d.ts.map +1 -1
  27. package/dist/esm/development/QueryAdapter-Bu5UJjE4.js.map +1 -1
  28. package/dist/esm/development/{QueryClient-BajBmpnA.js → QueryClient-4co72n4i.js} +636 -628
  29. package/dist/esm/development/QueryClient-4co72n4i.js.map +1 -0
  30. package/dist/esm/development/index.js +2 -2
  31. package/dist/esm/development/{mutation-DAOZE4Ok.js → mutation-BMAWDUP4.js} +2 -2
  32. package/dist/esm/development/mutation-BMAWDUP4.js.map +1 -0
  33. package/dist/esm/development/react/index.js +1 -1
  34. package/dist/esm/development/rest/index.js +2 -2
  35. package/dist/esm/development/topic/index.js +1 -1
  36. package/dist/esm/development/topic/index.js.map +1 -1
  37. package/dist/esm/mutation.d.ts +3 -3
  38. package/dist/esm/mutation.d.ts.map +1 -1
  39. package/dist/esm/production/QueryAdapter-Bu5UJjE4.js.map +1 -1
  40. package/dist/esm/production/{QueryClient-KH0Ex_8m.js → QueryClient-CS4iUKWj.js} +782 -774
  41. package/dist/esm/production/QueryClient-CS4iUKWj.js.map +1 -0
  42. package/dist/esm/production/index.js +2 -2
  43. package/dist/esm/production/{mutation-C7BOChR2.js → mutation-B1EiA34B.js} +2 -2
  44. package/dist/esm/production/mutation-B1EiA34B.js.map +1 -0
  45. package/dist/esm/production/react/index.js +1 -1
  46. package/dist/esm/production/rest/index.js +2 -2
  47. package/dist/esm/production/topic/index.js +1 -1
  48. package/dist/esm/production/topic/index.js.map +1 -1
  49. package/dist/esm/query.d.ts +3 -3
  50. package/dist/esm/query.d.ts.map +1 -1
  51. package/dist/esm/retry.d.ts.map +1 -1
  52. package/dist/esm/topic/TopicQuery.d.ts +2 -1
  53. package/dist/esm/topic/TopicQuery.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/plugin/docs/api/fetchium.md +2 -2
  56. package/plugin/docs/api/stores-async.md +9 -3
  57. package/plugin/docs/api/stores-sync.md +9 -3
  58. package/plugin/docs/core/entities.md +2 -2
  59. package/plugin/docs/core/queries.md +12 -19
  60. package/plugin/docs/data/mutations.md +1 -1
  61. package/plugin/docs/guides/auth.md +65 -42
  62. package/plugin/docs/guides/error-handling.md +9 -5
  63. package/plugin/docs/guides/offline.md +11 -8
  64. package/plugin/docs/guides/testing.md +1 -1
  65. package/plugin/docs/quickstart.md +1 -1
  66. package/plugin/docs/reference/rest-queries.md +9 -9
  67. package/plugin/docs/setup/project-setup.md +5 -5
  68. package/dist/cjs/development/QueryClient-m7BzCIe9.js +0 -2
  69. package/dist/cjs/development/QueryClient-m7BzCIe9.js.map +0 -1
  70. package/dist/cjs/development/mutation-wUhcGxKl.js.map +0 -1
  71. package/dist/cjs/production/QueryClient-4T90peFN.js +0 -2
  72. package/dist/cjs/production/QueryClient-4T90peFN.js.map +0 -1
  73. package/dist/cjs/production/mutation-Dk0gznwX.js.map +0 -1
  74. package/dist/esm/development/QueryClient-BajBmpnA.js.map +0 -1
  75. package/dist/esm/development/mutation-DAOZE4Ok.js.map +0 -1
  76. package/dist/esm/production/QueryClient-KH0Ex_8m.js.map +0 -1
  77. package/dist/esm/production/mutation-C7BOChR2.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-BajBmpnA.js";
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-4co72n4i.js";
2
2
  import { Q as F } from "./QueryAdapter-Bu5UJjE4.js";
3
- import { M as A, g as K, m as Y } from "./mutation-DAOZE4Ok.js";
3
+ import { M as A, g as K, m as Y } from "./mutation-BMAWDUP4.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-BajBmpnA.js";
2
+ import { l as y, h as D, m as w, V as u, t as d } from "./QueryClient-4co72n4i.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-DAOZE4Ok.js.map
58
+ //# sourceMappingURL=mutation-BMAWDUP4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation-BMAWDUP4.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
1
  import { useReactive as i } from "signalium/react";
2
2
  import { reactive as f } from "signalium";
3
- import { k as u } from "../QueryClient-BajBmpnA.js";
3
+ import { k as u } from "../QueryClient-4co72n4i.js";
4
4
  function n(e) {
5
5
  if (Array.isArray(e))
6
6
  return e.map(n);
@@ -1,6 +1,6 @@
1
- import { n as v, o as U, f as O } from "../QueryClient-BajBmpnA.js";
1
+ import { n as v, o as U, f as O } from "../QueryClient-4co72n4i.js";
2
2
  import { Q as T } from "../QueryAdapter-Bu5UJjE4.js";
3
- import { M as w } from "../mutation-DAOZE4Ok.js";
3
+ import { M as w } from "../mutation-BMAWDUP4.js";
4
4
  class P extends T {
5
5
  _fetch;
6
6
  _baseUrl;
@@ -1,4 +1,4 @@
1
- import { f as l } from "../QueryClient-BajBmpnA.js";
1
+ import { f as l } from "../QueryClient-4co72n4i.js";
2
2
  import { Q as d } from "../QueryAdapter-Bu5UJjE4.js";
3
3
  class g extends l {
4
4
  static adapter;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/topic/TopicQuery.ts","../../../../src/topic/TopicQueryAdapter.ts"],"sourcesContent":["import { Query } from '../query.js';\nimport type { TopicQueryAdapter } from './TopicQueryAdapter.js';\nimport type { QueryConfigOptions } from '../query-types.js';\n\n// ================================\n// TopicQuery — declarative topic-based query definition\n// ================================\n\nexport abstract class TopicQuery extends Query {\n static override adapter: typeof TopicQueryAdapter;\n\n abstract topic: string;\n\n getIdentityKey(): string {\n return `topic:${this.topic}`;\n }\n\n getConfig(): QueryConfigOptions {\n return {\n staleTime: 0,\n subscribe: () => {\n return () => {\n const adapter = (this as Record<string, any>)._topicAdapter as TopicQueryAdapter | undefined;\n adapter?.unsubscribe(this.topic);\n };\n },\n };\n }\n}\n","import { QueryAdapter } from '../QueryAdapter.js';\nimport type { Query } from '../query.js';\nimport type { MutationEvent } from '../types.js';\n\n// ================================\n// TopicQueryAdapter — abstract adapter for topic-based subscriptions\n// ================================\n\ninterface TopicCtx extends Query {\n topic: string;\n _topicAdapter?: TopicQueryAdapter;\n}\n\ninterface TopicState {\n status: 'pending' | 'fulfilled' | 'rejected';\n promise?: Promise<unknown>;\n resolve?: (data: unknown) => void;\n reject?: (error: unknown) => void;\n data?: unknown;\n error?: unknown;\n}\n\nexport abstract class TopicQueryAdapter extends QueryAdapter {\n private _topics = new Map<string, TopicState>();\n\n /**\n * Called when a query activates for a given topic.\n * Implementations should start delivering data for this topic,\n * calling `fulfillTopic()` when initial data is available and\n * `sendMutationEvent()` for ongoing updates.\n */\n abstract subscribe(topic: string): void;\n\n /**\n * Called when the query deactivates. Implementations should\n * tear down any resources for this topic.\n */\n abstract unsubscribe(topic: string): void;\n\n /**\n * Resolve the pending promise for a topic with initial data.\n * Can be called before `send()` — the data will be picked up\n * when the query activates.\n */\n protected fulfillTopic(topic: string, data: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'fulfilled', data });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'fulfilled';\n state.data = data;\n state.resolve!(data);\n }\n }\n\n /**\n * Reject the pending promise for a topic.\n * Can be called before `send()` — the error will be propagated\n * when the query activates.\n */\n protected rejectTopic(topic: string, error: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'rejected', error });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'rejected';\n state.error = error;\n state.reject!(error);\n }\n }\n\n /**\n * Clears internal state for a topic. Called automatically by\n * `unsubscribe` — subclasses generally don't need to call this.\n */\n protected clearTopic(topic: string): void {\n this._topics.delete(topic);\n }\n\n protected clearAll(): void {\n this._topics.clear();\n }\n\n override async send(ctx: Query, _signal: AbortSignal): Promise<unknown> {\n const topicCtx = ctx as TopicCtx;\n topicCtx._topicAdapter = this;\n const topic = topicCtx.topic;\n\n const existing = this._topics.get(topic);\n\n if (existing) {\n switch (existing.status) {\n case 'fulfilled':\n return existing.data;\n case 'rejected':\n throw existing.error;\n case 'pending':\n return existing.promise;\n }\n }\n\n // No state yet — create a deferred and subscribe\n let resolve!: (data: unknown) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<unknown>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n this._topics.set(topic, { status: 'pending', promise, resolve, reject });\n this.subscribe(topic);\n\n return promise;\n }\n\n /**\n * Convenience wrapper — pushes a mutation event through the QueryClient\n * so that entities and live collections are updated reactively.\n */\n protected sendMutationEvent(event: MutationEvent): void {\n this.queryClient!.applyMutationEvent(event);\n }\n}\n"],"names":["TopicQuery","Query","TopicQueryAdapter","QueryAdapter","topic","data","state","error","ctx","_signal","topicCtx","existing","resolve","reject","promise","res","rej","event"],"mappings":";;AAQO,MAAeA,UAAmBC,EAAM;AAAA,EAC7C,OAAgB;AAAA,EAIhB,iBAAyB;AACvB,WAAO,SAAS,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEA,YAAgC;AAC9B,WAAO;AAAA,MACL,WAAW;AAAA,MACX,WAAW,MACF,MAAM;AAEX,QADiB,KAA6B,eACrC,YAAY,KAAK,KAAK;AAAA,MACjC;AAAA,IACF;AAAA,EAEJ;AACF;ACNO,MAAeC,UAA0BC,EAAa;AAAA,EACnD,8BAAc,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBZ,aAAaC,GAAeC,GAAqB;AACzD,UAAMC,IAAQ,KAAK,QAAQ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ACvE,KAAK,UAAUT,CAAK,GAEbU;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,kBAAkBG,GAA4B;AACtD,SAAK,YAAa,mBAAmBA,CAAK;AAAA,EAC5C;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/topic/TopicQuery.ts","../../../../src/topic/TopicQueryAdapter.ts"],"sourcesContent":["import { Query } from '../query.js';\nimport type { TopicQueryAdapter } from './TopicQueryAdapter.js';\nimport type { QueryAdapterClass } from '../QueryAdapter.js';\nimport type { QueryConfigOptions } from '../query-types.js';\n\n// ================================\n// TopicQuery — declarative topic-based query definition\n// ================================\n\nexport abstract class TopicQuery extends Query {\n static override adapter: QueryAdapterClass<TopicQueryAdapter>;\n\n abstract topic: string;\n\n getIdentityKey(): string {\n return `topic:${this.topic}`;\n }\n\n getConfig(): QueryConfigOptions {\n return {\n staleTime: 0,\n subscribe: () => {\n return () => {\n const adapter = (this as Record<string, any>)._topicAdapter as TopicQueryAdapter | undefined;\n adapter?.unsubscribe(this.topic);\n };\n },\n };\n }\n}\n","import { QueryAdapter } from '../QueryAdapter.js';\nimport type { Query } from '../query.js';\nimport type { MutationEvent } from '../types.js';\n\n// ================================\n// TopicQueryAdapter — abstract adapter for topic-based subscriptions\n// ================================\n\ninterface TopicCtx extends Query {\n topic: string;\n _topicAdapter?: TopicQueryAdapter;\n}\n\ninterface TopicState {\n status: 'pending' | 'fulfilled' | 'rejected';\n promise?: Promise<unknown>;\n resolve?: (data: unknown) => void;\n reject?: (error: unknown) => void;\n data?: unknown;\n error?: unknown;\n}\n\nexport abstract class TopicQueryAdapter extends QueryAdapter {\n private _topics = new Map<string, TopicState>();\n\n /**\n * Called when a query activates for a given topic.\n * Implementations should start delivering data for this topic,\n * calling `fulfillTopic()` when initial data is available and\n * `sendMutationEvent()` for ongoing updates.\n */\n abstract subscribe(topic: string): void;\n\n /**\n * Called when the query deactivates. Implementations should\n * tear down any resources for this topic.\n */\n abstract unsubscribe(topic: string): void;\n\n /**\n * Resolve the pending promise for a topic with initial data.\n * Can be called before `send()` — the data will be picked up\n * when the query activates.\n */\n protected fulfillTopic(topic: string, data: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'fulfilled', data });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'fulfilled';\n state.data = data;\n state.resolve!(data);\n }\n }\n\n /**\n * Reject the pending promise for a topic.\n * Can be called before `send()` — the error will be propagated\n * when the query activates.\n */\n protected rejectTopic(topic: string, error: unknown): void {\n const state = this._topics.get(topic);\n\n if (state === undefined) {\n this._topics.set(topic, { status: 'rejected', error });\n return;\n }\n\n if (state.status === 'pending') {\n state.status = 'rejected';\n state.error = error;\n state.reject!(error);\n }\n }\n\n /**\n * Clears internal state for a topic. Called automatically by\n * `unsubscribe` — subclasses generally don't need to call this.\n */\n protected clearTopic(topic: string): void {\n this._topics.delete(topic);\n }\n\n protected clearAll(): void {\n this._topics.clear();\n }\n\n override async send(ctx: Query, _signal: AbortSignal): Promise<unknown> {\n const topicCtx = ctx as TopicCtx;\n topicCtx._topicAdapter = this;\n const topic = topicCtx.topic;\n\n const existing = this._topics.get(topic);\n\n if (existing) {\n switch (existing.status) {\n case 'fulfilled':\n return existing.data;\n case 'rejected':\n throw existing.error;\n case 'pending':\n return existing.promise;\n }\n }\n\n // No state yet — create a deferred and subscribe\n let resolve!: (data: unknown) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<unknown>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n this._topics.set(topic, { status: 'pending', promise, resolve, reject });\n this.subscribe(topic);\n\n return promise;\n }\n\n /**\n * Convenience wrapper — pushes a mutation event through the QueryClient\n * so that entities and live collections are updated reactively.\n */\n protected sendMutationEvent(event: MutationEvent): void {\n this.queryClient!.applyMutationEvent(event);\n }\n}\n"],"names":["TopicQuery","Query","TopicQueryAdapter","QueryAdapter","topic","data","state","error","ctx","_signal","topicCtx","existing","resolve","reject","promise","res","rej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N,IAAQM,EAAS,OAEjBC,IAAW,KAAK,QAAQ,IAAIP,CAAK;AAEvC,QAAIO;AACF,cAAQA,EAAS,QAAA;AAAA,QACf,KAAK;AACH,iBAAOA,EAAS;AAAA,QAClB,KAAK;AACH,gBAAMA,EAAS;AAAA,QACjB,KAAK;AACH,iBAAOA,EAAS;AAAA,MAAA;AAKtB,QAAIC,GACAC;AACJ,UAAMC,IAAU,IAAI,QAAiB,CAACC,GAAKC,MAAQ;AACjD,MAAAJ,IAAUG,GACVF,IAASG;AAAA,IACX,CAAC;AAED,gBAAK,QAAQ,IAAIZ,GAAO,EAAE,QAAQ,WAAW,SAAAU,GAAS,SAAAF,GAAS,QAAAC,GAAQ,GACvE,KAAK,UAAUT,CAAK,GAEbU;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,kBAAkBG,GAA4B;AACtD,SAAK,YAAa,mBAAmBA,CAAK;AAAA,EAC5C;AACF;"}
@@ -2,7 +2,7 @@ import { ReactiveTask } from 'signalium';
2
2
  import { ExtractType, InternalTypeDef, MutationEffects, RetryConfig, TypeDefShape } from './types.js';
3
3
  import { type QueryContext } from './QueryClient.js';
4
4
  import { type CapturedDefinition } from './fieldRef.js';
5
- import type { QueryAdapter } from './QueryAdapter.js';
5
+ import type { QueryAdapterClass } from './QueryAdapter.js';
6
6
  export interface MutationConfigOptions {
7
7
  retry?: RetryConfig | number | false;
8
8
  }
@@ -15,10 +15,10 @@ export interface MutationDefinition<Request, Response> {
15
15
  config?: MutationConfigOptions;
16
16
  effects?: MutationEffects;
17
17
  hasGetEffects: boolean;
18
- adapterClass: typeof QueryAdapter;
18
+ adapterClass: QueryAdapterClass;
19
19
  }
20
20
  export declare abstract class Mutation {
21
- static adapter?: typeof QueryAdapter;
21
+ static adapter?: QueryAdapterClass;
22
22
  readonly params?: TypeDefShape;
23
23
  readonly result?: TypeDefShape;
24
24
  readonly optimisticUpdates?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.d.ts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,iBAAiB,CAAC;CACjC;AAMD,8BAAsB,QAAQ;IAC5B,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAEnC,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IAErC,OAAO,EAAE,YAAY,CAAC;IAE9B,QAAQ,CAAC,cAAc,IAAI,OAAO;IAElC,UAAU,CAAC,IAAI,eAAe;;CAK/B;AAQD,eAAO,MAAM,mBAAmB,GAAI,KAAK,UAAU,QAAQ,KAAG,MAQ7D,CAAC;AAmEF,wBAAgB,WAAW,CAAC,CAAC,SAAS,QAAQ,EAC5C,aAAa,EAAE,UAAU,CAAC,GACzB,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAU9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryAdapter-Bu5UJjE4.js","sources":["../../../src/QueryAdapter.ts"],"sourcesContent":["import { type QueryContext } from './query-types.js';\nimport type { Query } from './query.js';\nimport type { Mutation } from './mutation.js';\n\n// ================================\n// IQueryClient — minimal interface QueryAdapter needs from the client\n// (avoids circular import: QueryClient → QueryAdapter → QueryClient)\n// ================================\n\nexport interface IQueryClientForAdapter {\n getContext(): QueryContext;\n applyMutationEvent(event: import('./types.js').MutationEvent): void;\n}\n\n// ================================\n// QueryAdapter base class\n// ================================\n\nexport abstract class QueryAdapter {\n protected queryClient: IQueryClientForAdapter | undefined;\n\n /**\n * Called once by QueryClient when this adapter is registered.\n * Subclasses can override to do setup (e.g. open a WebSocket connection).\n */\n register(queryClient: IQueryClientForAdapter): void {\n this.queryClient = queryClient;\n }\n\n /**\n * Called when the network comes online or goes offline.\n * Subclasses can override to reconnect persistent connections (e.g. WebSocket).\n */\n onNetworkStatusChange?(isOnline: boolean): void;\n\n /**\n * Called when the QueryClient is destroyed.\n * Subclasses can override to clean up connections or timers.\n */\n destroy?(): void;\n\n /**\n * Send the query and return the raw response data.\n * @param ctx The query execution context (a reified Query instance with params applied).\n * @param signal AbortSignal to cancel the in-flight request.\n */\n abstract send(ctx: Query, signal: AbortSignal): Promise<unknown>;\n\n /**\n * Fetch the next page of results. Only implement if the adapter supports pagination.\n * @param ctx The query execution context. `ctx.resultData` contains the current page's data.\n * @param signal AbortSignal to cancel the in-flight request.\n */\n sendNext?(ctx: Query, signal: AbortSignal): Promise<unknown>;\n\n /**\n * Return true if more pages are available for the current result.\n * Called reactively — do not perform async work here.\n */\n hasNext?(ctx: Query): boolean;\n\n /**\n * Send a mutation and return the raw response data.\n * @param ctx The mutation execution context (a reified Mutation instance with params applied).\n * @param signal AbortSignal to cancel the in-flight request.\n */\n sendMutation?(ctx: Mutation, signal: AbortSignal): Promise<unknown>;\n}\n"],"names":["QueryAdapter","queryClient"],"mappings":"AAkBO,MAAeA,EAAa;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMV,SAASC,GAA2C;AAClD,SAAK,cAAcA;AAAA,EACrB;AAwCF;"}
1
+ {"version":3,"file":"QueryAdapter-Bu5UJjE4.js","sources":["../../../src/QueryAdapter.ts"],"sourcesContent":["import { type QueryContext } from './query-types.js';\nimport type { Query } from './query.js';\nimport type { Mutation } from './mutation.js';\n\n// ================================\n// IQueryClient — minimal interface QueryAdapter needs from the client\n// (avoids circular import: QueryClient → QueryAdapter → QueryClient)\n// ================================\n\nexport interface IQueryClientForAdapter {\n getContext(): QueryContext;\n applyMutationEvent(event: import('./types.js').MutationEvent): void;\n}\n\n// ================================\n// QueryAdapterClass — constructor reference for an adapter class\n// ================================\n\n/**\n * A reference to an adapter class (abstract or concrete) with any constructor\n * signature. Used as the type of `static adapter` properties on Query/Mutation\n * classes, so that subclasses with required constructor arguments can be\n * assigned directly without casts.\n *\n * The framework never instantiates these classes via this type (adapters are\n * registered as pre-built instances on the QueryClient); it only uses the\n * reference as a map key and for prototype/name introspection.\n */\nexport type QueryAdapterClass<T extends QueryAdapter = QueryAdapter> = abstract new (...args: any[]) => T;\n\n// ================================\n// QueryAdapter base class\n// ================================\n\nexport abstract class QueryAdapter {\n protected queryClient: IQueryClientForAdapter | undefined;\n\n /**\n * Called once by QueryClient when this adapter is registered.\n * Subclasses can override to do setup (e.g. open a WebSocket connection).\n */\n register(queryClient: IQueryClientForAdapter): void {\n this.queryClient = queryClient;\n }\n\n /**\n * Called when the network comes online or goes offline.\n * Subclasses can override to reconnect persistent connections (e.g. WebSocket).\n */\n onNetworkStatusChange?(isOnline: boolean): void;\n\n /**\n * Called when the QueryClient is destroyed.\n * Subclasses can override to clean up connections or timers.\n */\n destroy?(): void;\n\n /**\n * Send the query and return the raw response data.\n * @param ctx The query execution context (a reified Query instance with params applied).\n * @param signal AbortSignal to cancel the in-flight request.\n */\n abstract send(ctx: Query, signal: AbortSignal): Promise<unknown>;\n\n /**\n * Fetch the next page of results. Only implement if the adapter supports pagination.\n * @param ctx The query execution context. `ctx.resultData` contains the current page's data.\n * @param signal AbortSignal to cancel the in-flight request.\n */\n sendNext?(ctx: Query, signal: AbortSignal): Promise<unknown>;\n\n /**\n * Return true if more pages are available for the current result.\n * Called reactively — do not perform async work here.\n */\n hasNext?(ctx: Query): boolean;\n\n /**\n * Send a mutation and return the raw response data.\n * @param ctx The mutation execution context (a reified Mutation instance with params applied).\n * @param signal AbortSignal to cancel the in-flight request.\n */\n sendMutation?(ctx: Mutation, signal: AbortSignal): Promise<unknown>;\n}\n"],"names":["QueryAdapter","queryClient"],"mappings":"AAkCO,MAAeA,EAAa;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMV,SAASC,GAA2C;AAClD,SAAK,cAAcA;AAAA,EACrB;AAwCF;"}