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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/development/QueryAdapter-DUo338ga.js.map +1 -1
- package/dist/cjs/development/QueryClient-BZpqASy3.js +2 -0
- package/dist/cjs/development/QueryClient-BZpqASy3.js.map +1 -0
- package/dist/cjs/development/index.js +1 -1
- package/dist/cjs/{production/mutation-Dk0gznwX.js → development/mutation-COeBCn7p.js} +2 -2
- package/dist/cjs/development/mutation-COeBCn7p.js.map +1 -0
- package/dist/cjs/development/react/index.js +1 -1
- package/dist/cjs/development/rest/index.js +1 -1
- package/dist/cjs/development/topic/index.js +1 -1
- package/dist/cjs/development/topic/index.js.map +1 -1
- package/dist/cjs/production/QueryAdapter-DUo338ga.js.map +1 -1
- package/dist/cjs/production/QueryClient-BmoHLlvu.js +2 -0
- package/dist/cjs/production/QueryClient-BmoHLlvu.js.map +1 -0
- package/dist/cjs/production/index.js +1 -1
- package/dist/cjs/{development/mutation-wUhcGxKl.js → production/mutation-CfFdNkYV.js} +2 -2
- package/dist/cjs/production/mutation-CfFdNkYV.js.map +1 -0
- package/dist/cjs/production/react/index.js +1 -1
- package/dist/cjs/production/rest/index.js +1 -1
- package/dist/cjs/production/topic/index.js +1 -1
- package/dist/cjs/production/topic/index.js.map +1 -1
- package/dist/esm/QueryAdapter.d.ts +11 -0
- package/dist/esm/QueryAdapter.d.ts.map +1 -1
- package/dist/esm/QueryClient.d.ts +5 -5
- package/dist/esm/QueryClient.d.ts.map +1 -1
- package/dist/esm/QueryResult.d.ts.map +1 -1
- package/dist/esm/development/QueryAdapter-Bu5UJjE4.js.map +1 -1
- package/dist/esm/development/{QueryClient-BajBmpnA.js → QueryClient-4co72n4i.js} +636 -628
- package/dist/esm/development/QueryClient-4co72n4i.js.map +1 -0
- package/dist/esm/development/index.js +2 -2
- package/dist/esm/development/{mutation-DAOZE4Ok.js → mutation-BMAWDUP4.js} +2 -2
- package/dist/esm/development/mutation-BMAWDUP4.js.map +1 -0
- package/dist/esm/development/react/index.js +1 -1
- package/dist/esm/development/rest/index.js +2 -2
- package/dist/esm/development/topic/index.js +1 -1
- package/dist/esm/development/topic/index.js.map +1 -1
- package/dist/esm/mutation.d.ts +3 -3
- package/dist/esm/mutation.d.ts.map +1 -1
- package/dist/esm/production/QueryAdapter-Bu5UJjE4.js.map +1 -1
- package/dist/esm/production/{QueryClient-KH0Ex_8m.js → QueryClient-CS4iUKWj.js} +782 -774
- package/dist/esm/production/QueryClient-CS4iUKWj.js.map +1 -0
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/{mutation-C7BOChR2.js → mutation-B1EiA34B.js} +2 -2
- package/dist/esm/production/mutation-B1EiA34B.js.map +1 -0
- package/dist/esm/production/react/index.js +1 -1
- package/dist/esm/production/rest/index.js +2 -2
- package/dist/esm/production/topic/index.js +1 -1
- package/dist/esm/production/topic/index.js.map +1 -1
- package/dist/esm/query.d.ts +3 -3
- package/dist/esm/query.d.ts.map +1 -1
- package/dist/esm/retry.d.ts.map +1 -1
- package/dist/esm/topic/TopicQuery.d.ts +2 -1
- package/dist/esm/topic/TopicQuery.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/docs/api/fetchium.md +2 -2
- package/plugin/docs/api/stores-async.md +9 -3
- package/plugin/docs/api/stores-sync.md +9 -3
- package/plugin/docs/core/entities.md +2 -2
- package/plugin/docs/core/queries.md +12 -19
- package/plugin/docs/data/mutations.md +1 -1
- package/plugin/docs/guides/auth.md +65 -42
- package/plugin/docs/guides/error-handling.md +9 -5
- package/plugin/docs/guides/offline.md +11 -8
- package/plugin/docs/guides/testing.md +1 -1
- package/plugin/docs/quickstart.md +1 -1
- package/plugin/docs/reference/rest-queries.md +9 -9
- package/plugin/docs/setup/project-setup.md +5 -5
- package/dist/cjs/development/QueryClient-m7BzCIe9.js +0 -2
- package/dist/cjs/development/QueryClient-m7BzCIe9.js.map +0 -1
- package/dist/cjs/development/mutation-wUhcGxKl.js.map +0 -1
- package/dist/cjs/production/QueryClient-4T90peFN.js +0 -2
- package/dist/cjs/production/QueryClient-4T90peFN.js.map +0 -1
- package/dist/cjs/production/mutation-Dk0gznwX.js.map +0 -1
- package/dist/esm/development/QueryClient-BajBmpnA.js.map +0 -1
- package/dist/esm/development/mutation-DAOZE4Ok.js.map +0 -1
- package/dist/esm/production/QueryClient-KH0Ex_8m.js.map +0 -1
- package/dist/esm/production/mutation-C7BOChR2.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-Dk0gznwX.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 } 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: typeof QueryAdapter;\n}\n\n// ================================\n// Mutation base class\n// ================================\n\nexport abstract class Mutation {\n static adapter?: typeof QueryAdapter;\n\n readonly params?: TypeDefShape;\n readonly result?: TypeDefShape;\n readonly optimisticUpdates?: boolean;\n readonly config?: MutationConfigOptions;\n readonly effects?: Readonly<MutationEffects>;\n\n declare context: QueryContext;\n\n abstract getIdentityKey(): unknown;\n\n getEffects?(): MutationEffects;\n\n constructor() {\n return createDefinitionProxy(this);\n }\n}\n\n// ================================\n// Mutation definition cache and lookup\n// ================================\n\nconst mutationDefCache = new WeakMap<new () => Mutation, () => MutationDefinition<any, any>>();\n\nexport const mutationKeyForClass = (cls: new () => Mutation): string => {\n const getMutationDef = mutationDefCache.get(cls);\n\n if (getMutationDef === undefined) {\n throw new Error('Mutation definition not found');\n }\n\n return getMutationDef().id;\n};\n\n// ================================\n// Internal: build mutation definition from class\n// ================================\n\nfunction buildMutationDefinition(MutationClass: new () => Mutation): () => MutationDefinition<any, any> {\n let cached = mutationDefCache.get(MutationClass);\n\n if (cached !== undefined) {\n return cached;\n }\n\n let mutationDefinition: MutationDefinition<any, any> | undefined;\n\n const getter = (): MutationDefinition<any, any> => {\n if (mutationDefinition !== undefined) {\n return mutationDefinition;\n }\n\n const instance = new MutationClass();\n const captured = extractDefinition(instance);\n const { fields } = captured;\n\n const id = `mutation:${String(captured.methods.getIdentityKey.call(fields))}`;\n\n const requestDef = fields.params ?? {};\n const requestShape = (requestDef instanceof ValidatorDef\n ? requestDef\n : t.object(requestDef)) as unknown as InternalTypeDef;\n const responseDef = fields.result;\n const responseShape =\n responseDef !== undefined\n ? ((responseDef instanceof ValidatorDef ? responseDef : t.object(responseDef)) as unknown as InternalTypeDef)\n : undefined;\n\n const adapterClass = (MutationClass as typeof Mutation).adapter;\n if (!adapterClass) {\n throw new Error(\n `Mutation class \"${MutationClass.name}\" must define a static \\`adapter\\` property. ` +\n `Extend RESTMutation (from fetchium/rest) or set \\`static adapter = MyAdapter\\` on your mutation class.`,\n );\n }\n\n mutationDefinition = {\n id,\n requestShape,\n responseShape,\n captured,\n optimisticUpdates: fields.optimisticUpdates ?? false,\n config: fields.config,\n effects: fields.effects,\n hasGetEffects: typeof captured.methods.getEffects === 'function',\n adapterClass,\n };\n\n return mutationDefinition;\n };\n\n mutationDefCache.set(MutationClass, getter);\n return getter;\n}\n\n// ================================\n// Public API\n// ================================\n\nexport function getMutation<T extends Mutation>(\n MutationClass: new () => T,\n): ReactiveTask<Readonly<ExtractType<T['result']>>, [ExtractType<T['params']>]> {\n const getMutationDef = buildMutationDefinition(MutationClass);\n\n const queryClient = getContext(QueryClientContext);\n\n if (queryClient === undefined) {\n throw new Error('QueryClient not found');\n }\n\n return queryClient.getMutation<any, any>(getMutationDef());\n}\n"],"names":["Mutation","createDefinitionProxy","mutationDefCache","mutationKeyForClass","cls","getMutationDef","buildMutationDefinition","MutationClass","cached","mutationDefinition","getter","instance","captured","extractDefinition","fields","id","requestDef","requestShape","ValidatorDef","t","responseDef","responseShape","adapterClass","getMutation","queryClient","getContext","QueryClientContext"],"mappings":"iFA+BO,MAAeA,CAAS,CAC7B,OAAO,QAEE,OACA,OACA,kBACA,OACA,QAQT,aAAc,CACZ,OAAOC,EAAAA,sBAAsB,IAAI,CACnC,CACF,CAMA,MAAMC,MAAuB,QAEhBC,EAAuBC,GAAoC,CACtE,MAAMC,EAAiBH,EAAiB,IAAIE,CAAG,EAE/C,GAAIC,IAAmB,OACrB,MAAM,IAAI,MAAM,+BAA+B,EAGjD,OAAOA,IAAiB,EAC1B,EAMA,SAASC,EAAwBC,EAAuE,CACtG,IAAIC,EAASN,EAAiB,IAAIK,CAAa,EAE/C,GAAIC,IAAW,OACb,OAAOA,EAGT,IAAIC,EAEJ,MAAMC,EAAS,IAAoC,CACjD,GAAID,IAAuB,OACzB,OAAOA,EAGT,MAAME,EAAW,IAAIJ,EACfK,EAAWC,EAAAA,kBAAkBF,CAAQ,EACrC,CAAE,OAAAG,GAAWF,EAEbG,EAAK,YAAY,OAAOH,EAAS,QAAQ,eAAe,KAAKE,CAAM,CAAC,CAAC,GAErEE,EAAaF,EAAO,QAAU,CAAA,EAC9BG,EAAgBD,aAAsBE,EAAAA,aACxCF,EACAG,EAAAA,EAAE,OAAOH,CAAU,EACjBI,EAAcN,EAAO,OACrBO,EACJD,IAAgB,OACVA,aAAuBF,EAAAA,aAAeE,EAAcD,IAAE,OAAOC,CAAW,EAC1E,OAEAE,EAAgBf,EAAkC,QACxD,GAAI,CAACe,EACH,MAAM,IAAI,MACR,mBAAmBf,EAAc,IAAI,qJAAA,EAKzC,OAAAE,EAAqB,CACnB,GAAAM,EACA,aAAAE,EACA,cAAAI,EACA,SAAAT,EACA,kBAAmBE,EAAO,mBAAqB,GAC/C,OAAQA,EAAO,OACf,QAASA,EAAO,QAChB,cAAe,OAAOF,EAAS,QAAQ,YAAe,WACtD,aAAAU,CAAA,EAGKb,CACT,EAEA,OAAAP,EAAiB,IAAIK,EAAeG,CAAM,EACnCA,CACT,CAMO,SAASa,EACdhB,EAC8E,CAC9E,MAAMF,EAAiBC,EAAwBC,CAAa,EAEtDiB,EAAcC,EAAAA,WAAWC,oBAAkB,EAEjD,GAAIF,IAAgB,OAClB,MAAM,IAAI,MAAM,uBAAuB,EAGzC,OAAOA,EAAY,YAAsBnB,GAAgB,CAC3D"}
|