@zenstackhq/tanstack-query 1.0.0-beta.8 → 1.0.0-beta.9
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/generator.d.ts +1 -1
- package/generator.js +22 -39
- package/generator.js.map +1 -1
- package/package.json +30 -14
- package/runtime/common-52ab2c3a.d.ts +19 -0
- package/runtime/index.d.mts +7 -0
- package/runtime/index.d.ts +7 -0
- package/runtime/index.js +19 -0
- package/runtime/index.js.map +1 -0
- package/runtime/index.mjs +1 -0
- package/runtime/index.mjs.map +1 -0
- package/runtime/react.d.mts +55 -0
- package/runtime/react.d.ts +55 -0
- package/runtime/react.js +216 -0
- package/runtime/react.js.map +1 -0
- package/runtime/react.mjs +193 -0
- package/runtime/react.mjs.map +1 -0
- package/runtime/svelte.d.mts +51 -0
- package/runtime/svelte.d.ts +51 -0
- package/runtime/svelte.js +208 -0
- package/runtime/svelte.js.map +1 -0
- package/runtime/svelte.mjs +186 -0
- package/runtime/svelte.mjs.map +1 -0
- package/res/marshal-json.ts +0 -12
- package/res/marshal-superjson.ts +0 -20
- package/res/react/helper.ts +0 -164
- package/res/shared.ts +0 -50
- package/res/svelte/helper.ts +0 -155
package/generator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DMMF } from '@prisma/generator-helper';
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { PluginOptions } from '@zenstackhq/sdk';
|
|
3
3
|
import { Model } from '@zenstackhq/sdk/ast';
|
|
4
4
|
export declare function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document): Promise<string[]>;
|
package/generator.js
CHANGED
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.generate = void 0;
|
|
16
16
|
const sdk_1 = require("@zenstackhq/sdk");
|
|
17
17
|
const change_case_1 = require("change-case");
|
|
18
|
-
const fs_1 = __importDefault(require("fs"));
|
|
19
18
|
const lower_case_first_1 = require("lower-case-first");
|
|
20
19
|
const path_1 = __importDefault(require("path"));
|
|
21
20
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -34,7 +33,6 @@ function generate(model, options, dmmf) {
|
|
|
34
33
|
throw new sdk_1.PluginError(options.name, `Unsupported target "${target}", supported values: ${supportedTargets.join(', ')}`);
|
|
35
34
|
}
|
|
36
35
|
generateIndex(project, outDir, models);
|
|
37
|
-
generateHelper(target, project, outDir, options.useSuperJson === true);
|
|
38
36
|
models.forEach((dataModel) => {
|
|
39
37
|
const mapping = dmmf.mappings.modelOperations.find((op) => op.model === dataModel.name);
|
|
40
38
|
if (!mapping) {
|
|
@@ -74,12 +72,15 @@ function generateQueryHook(target, sf, model, operation, returnArray, optionalIn
|
|
|
74
72
|
`return query<${returnType}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, args, options, fetch);`,
|
|
75
73
|
]);
|
|
76
74
|
}
|
|
77
|
-
function generateMutationHook(target, sf, model, operation, httpVerb, overrideReturnType) {
|
|
75
|
+
function generateMutationHook(target, sf, model, operation, httpVerb, checkReadBack, overrideReturnType) {
|
|
78
76
|
const capOperation = (0, upper_case_first_1.upperCaseFirst)(operation);
|
|
79
77
|
const argsType = `Prisma.${model}${capOperation}Args`;
|
|
80
78
|
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
let returnType = overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : `Prisma.CheckSelect<T, ${model}, Prisma.${model}GetPayload<T>>`;
|
|
80
|
+
if (checkReadBack) {
|
|
81
|
+
returnType = `(${returnType} | undefined )`;
|
|
82
|
+
}
|
|
83
|
+
const nonGenericOptionsType = `Omit<${makeMutationOptions(target, checkReadBack ? `(${overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model} | undefined)` : overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model, argsType)}, 'mutationFn'>`;
|
|
83
84
|
const optionsType = `Omit<${makeMutationOptions(target, returnType, inputType)}, 'mutationFn'>`;
|
|
84
85
|
const func = sf.addFunction({
|
|
85
86
|
name: `use${capOperation}${model}`,
|
|
@@ -104,7 +105,7 @@ function generateMutationHook(target, sf, model, operation, httpVerb, overrideRe
|
|
|
104
105
|
{
|
|
105
106
|
name: `_mutation`,
|
|
106
107
|
initializer: `
|
|
107
|
-
${httpVerb}Mutation<${argsType}, ${overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, options, fetch, invalidateQueries)
|
|
108
|
+
${httpVerb}Mutation<${argsType}, ${overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model}, ${checkReadBack}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, options, fetch, invalidateQueries, ${checkReadBack})
|
|
108
109
|
`,
|
|
109
110
|
},
|
|
110
111
|
],
|
|
@@ -177,11 +178,11 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
177
178
|
// create is somehow named "createOne" in the DMMF
|
|
178
179
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
180
|
if (mapping.create || mapping.createOne) {
|
|
180
|
-
generateMutationHook(target, sf, model.name, 'create', 'post');
|
|
181
|
+
generateMutationHook(target, sf, model.name, 'create', 'post', true);
|
|
181
182
|
}
|
|
182
183
|
// createMany
|
|
183
184
|
if (mapping.createMany) {
|
|
184
|
-
generateMutationHook(target, sf, model.name, 'createMany', 'post', 'Prisma.BatchPayload');
|
|
185
|
+
generateMutationHook(target, sf, model.name, 'createMany', 'post', false, 'Prisma.BatchPayload');
|
|
185
186
|
}
|
|
186
187
|
// findMany
|
|
187
188
|
if (mapping.findMany) {
|
|
@@ -199,27 +200,27 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
199
200
|
// update is somehow named "updateOne" in the DMMF
|
|
200
201
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
202
|
if (mapping.update || mapping.updateOne) {
|
|
202
|
-
generateMutationHook(target, sf, model.name, 'update', 'put');
|
|
203
|
+
generateMutationHook(target, sf, model.name, 'update', 'put', true);
|
|
203
204
|
}
|
|
204
205
|
// updateMany
|
|
205
206
|
if (mapping.updateMany) {
|
|
206
|
-
generateMutationHook(target, sf, model.name, 'updateMany', 'put', 'Prisma.BatchPayload');
|
|
207
|
+
generateMutationHook(target, sf, model.name, 'updateMany', 'put', false, 'Prisma.BatchPayload');
|
|
207
208
|
}
|
|
208
209
|
// upsert
|
|
209
210
|
// upsert is somehow named "upsertOne" in the DMMF
|
|
210
211
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
211
212
|
if (mapping.upsert || mapping.upsertOne) {
|
|
212
|
-
generateMutationHook(target, sf, model.name, 'upsert', 'post');
|
|
213
|
+
generateMutationHook(target, sf, model.name, 'upsert', 'post', true);
|
|
213
214
|
}
|
|
214
215
|
// del
|
|
215
216
|
// delete is somehow named "deleteOne" in the DMMF
|
|
216
217
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
217
218
|
if (mapping.delete || mapping.deleteOne) {
|
|
218
|
-
generateMutationHook(target, sf, model.name, 'delete', 'delete');
|
|
219
|
+
generateMutationHook(target, sf, model.name, 'delete', 'delete', true);
|
|
219
220
|
}
|
|
220
221
|
// deleteMany
|
|
221
222
|
if (mapping.deleteMany) {
|
|
222
|
-
generateMutationHook(target, sf, model.name, 'deleteMany', 'delete', 'Prisma.BatchPayload');
|
|
223
|
+
generateMutationHook(target, sf, model.name, 'deleteMany', 'delete', false, 'Prisma.BatchPayload');
|
|
223
224
|
}
|
|
224
225
|
// aggregate
|
|
225
226
|
if (mapping.aggregate) {
|
|
@@ -232,7 +233,7 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
232
233
|
`HasSelectOrTake extends Prisma.Or<Prisma.Extends<'skip', Prisma.Keys<T>>, Prisma.Extends<'take', Prisma.Keys<T>>>`,
|
|
233
234
|
`OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.${model.name}GroupByArgs['orderBy'] }: { orderBy?: Prisma.${model.name}GroupByArgs['orderBy'] },`,
|
|
234
235
|
`OrderFields extends Prisma.ExcludeUnderscoreKeys<Prisma.Keys<Prisma.MaybeTupleToUnion<T['orderBy']>>>`,
|
|
235
|
-
`ByFields extends Prisma.
|
|
236
|
+
`ByFields extends Prisma.MaybeTupleToUnion<T['by']>`,
|
|
236
237
|
`ByValid extends Prisma.Has<ByFields, OrderFields>`,
|
|
237
238
|
`HavingFields extends Prisma.GetHavingFields<T['having']>`,
|
|
238
239
|
`HavingValid extends Prisma.Has<ByFields, HavingFields>`,
|
|
@@ -281,7 +282,7 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
281
282
|
}[OrderFields]`,
|
|
282
283
|
];
|
|
283
284
|
const returnType = `{} extends InputErrors ?
|
|
284
|
-
Array<
|
|
285
|
+
Array<PickEnumerable<Prisma.${model.name}GroupByOutputType, T['by']> &
|
|
285
286
|
{
|
|
286
287
|
[P in ((keyof T) & (keyof Prisma.${model.name}GroupByOutputType))]: P extends '_count'
|
|
287
288
|
? T[P] extends boolean
|
|
@@ -300,27 +301,6 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
300
301
|
function generateIndex(project, outDir, models) {
|
|
301
302
|
const sf = project.createSourceFile(path_1.default.join(outDir, 'index.ts'), undefined, { overwrite: true });
|
|
302
303
|
sf.addStatements(models.map((d) => `export * from './${(0, change_case_1.paramCase)(d.name)}';`));
|
|
303
|
-
sf.addStatements(`export * from './_helper';`);
|
|
304
|
-
}
|
|
305
|
-
function generateHelper(target, project, outDir, useSuperJson) {
|
|
306
|
-
let srcFile;
|
|
307
|
-
switch (target) {
|
|
308
|
-
case 'react':
|
|
309
|
-
srcFile = path_1.default.join(__dirname, './res/react/helper.ts');
|
|
310
|
-
break;
|
|
311
|
-
case 'svelte':
|
|
312
|
-
srcFile = path_1.default.join(__dirname, './res/svelte/helper.ts');
|
|
313
|
-
break;
|
|
314
|
-
default:
|
|
315
|
-
throw new sdk_1.PluginError(_1.name, `Unsupported target: ${target}`);
|
|
316
|
-
}
|
|
317
|
-
// merge content of `shared.ts`, `helper.ts` and `marshal-?.ts`
|
|
318
|
-
const sharedContent = fs_1.default.readFileSync(path_1.default.join(__dirname, './res/shared.ts'), 'utf-8');
|
|
319
|
-
const helperContent = fs_1.default.readFileSync(srcFile, 'utf-8');
|
|
320
|
-
const marshalContent = fs_1.default.readFileSync(path_1.default.join(__dirname, useSuperJson ? './res/marshal-superjson.ts' : './res/marshal-json.ts'), 'utf-8');
|
|
321
|
-
project.createSourceFile(path_1.default.join(outDir, '_helper.ts'), `${sharedContent}\n${helperContent}\n${marshalContent}`, {
|
|
322
|
-
overwrite: true,
|
|
323
|
-
});
|
|
324
304
|
}
|
|
325
305
|
function makeGetContext(target) {
|
|
326
306
|
switch (target) {
|
|
@@ -333,13 +313,16 @@ function makeGetContext(target) {
|
|
|
333
313
|
}
|
|
334
314
|
}
|
|
335
315
|
function makeBaseImports(target) {
|
|
336
|
-
const shared = [
|
|
316
|
+
const shared = [
|
|
317
|
+
`import { query, postMutation, putMutation, deleteMutation } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
318
|
+
`import type { PickEnumerable } from '@zenstackhq/tanstack-query/runtime';`,
|
|
319
|
+
];
|
|
337
320
|
switch (target) {
|
|
338
321
|
case 'react':
|
|
339
322
|
return [
|
|
340
323
|
`import { useContext } from 'react';`,
|
|
341
324
|
`import type { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';`,
|
|
342
|
-
`import { RequestHandlerContext } from '
|
|
325
|
+
`import { RequestHandlerContext } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
343
326
|
...shared,
|
|
344
327
|
];
|
|
345
328
|
case 'svelte':
|
|
@@ -347,7 +330,7 @@ function makeBaseImports(target) {
|
|
|
347
330
|
`import { getContext } from 'svelte';`,
|
|
348
331
|
`import { derived } from 'svelte/store';`,
|
|
349
332
|
`import type { MutationOptions, QueryOptions } from '@tanstack/svelte-query';`,
|
|
350
|
-
`import { SvelteQueryContextKey, type RequestHandlerContext } from '
|
|
333
|
+
`import { SvelteQueryContextKey, type RequestHandlerContext } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
351
334
|
...shared,
|
|
352
335
|
];
|
|
353
336
|
default:
|
package/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,yCASyB;AAEzB,6CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,yCASyB;AAEzB,6CAAwC;AACxC,uDAAkD;AAClD,gDAAwB;AACxB,uCAAwE;AACxE,uDAAkD;AAClD,wBAAyB;AAEzB,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAG7C,SAAsB,QAAQ,CAAC,KAAY,EAAE,OAAsB,EAAE,IAAmB;;QACpF,IAAI,MAAM,GAAG,IAAA,mBAAa,EAAS,OAAO,EAAE,QAAQ,CAAC,CAAC;QACtD,MAAM,GAAG,IAAA,iBAAW,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEtC,MAAM,OAAO,GAAG,IAAA,mBAAa,GAAE,CAAC;QAChC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAA,mBAAa,EAAC,KAAK,CAAC,CAAC;QAEpC,MAAM,MAAM,GAAG,IAAA,mBAAa,EAAS,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,MAAM,IAAI,iBAAW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AAwG,MAAM,IAAI;QAClH,2EAA2E;KAC9E,CAAC;IACF,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO;YACR,OAAO;gBACH,qCAAqC;gBACrC,mFAAmF;gBACnF,6EAA6E,MAAM,IAAI;gBACvF,GAAG,MAAM;aACZ,CAAC;QACN,KAAK,QAAQ;YACT,OAAO;gBACH,sCAAsC;gBACtC,yCAAyC;gBACzC,8EAA8E;gBAC9E,yGAAyG,MAAM,IAAI;gBACnH,GAAG,MAAM;aACZ,CAAC;QACN;YACI,MAAM,IAAI,iBAAW,CAAC,OAAI,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;KACpE;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc,EAAE,UAAkB;IACxD,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO;YACR,OAAO,mBAAmB,UAAU,GAAG,CAAC;QAC5C,KAAK,QAAQ;YACT,OAAO,gBAAgB,UAAU,GAAG,CAAC;QACzC;YACI,MAAM,IAAI,iBAAW,CAAC,OAAI,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;KACpE;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc,EAAE,UAAkB,EAAE,QAAgB;IAC7E,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO;YACR,OAAO,sBAAsB,UAAU,cAAc,QAAQ,GAAG,CAAC;QACrE,KAAK,QAAQ;YACT,OAAO,mBAAmB,UAAU,cAAc,QAAQ,GAAG,CAAC;QAClE;YACI,MAAM,IAAI,iBAAW,CAAC,OAAI,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;KACpE;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenstackhq/tanstack-query",
|
|
3
3
|
"displayName": "ZenStack plugin for generating tanstack-query hooks",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.9",
|
|
5
5
|
"description": "ZenStack plugin for generating tanstack-query hooks",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./runtime/react": {
|
|
12
|
+
"import": "./runtime/react.mjs",
|
|
13
|
+
"require": "./runtime/react.js",
|
|
14
|
+
"default": "./runtime/react.js",
|
|
15
|
+
"types": "./runtime/react.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./runtime/svelte": {
|
|
18
|
+
"import": "./runtime/svelte.mjs",
|
|
19
|
+
"require": "./runtime/svelte.js",
|
|
20
|
+
"default": "./runtime/svelte.js",
|
|
21
|
+
"types": "./runtime/svelte.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
7
24
|
"repository": {
|
|
8
25
|
"type": "git",
|
|
9
26
|
"url": "https://github.com/zenstackhq/zenstack"
|
|
@@ -16,39 +33,38 @@
|
|
|
16
33
|
"author": "ZenStack Team",
|
|
17
34
|
"license": "MIT",
|
|
18
35
|
"dependencies": {
|
|
19
|
-
"@prisma/generator-helper": "
|
|
36
|
+
"@prisma/generator-helper": "^5.0.0",
|
|
20
37
|
"change-case": "^4.1.2",
|
|
21
38
|
"decimal.js": "^10.4.2",
|
|
22
39
|
"lower-case-first": "^2.0.2",
|
|
23
40
|
"superjson": "^1.11.0",
|
|
24
41
|
"ts-morph": "^16.0.0",
|
|
25
42
|
"upper-case-first": "^2.0.2",
|
|
26
|
-
"@zenstackhq/
|
|
43
|
+
"@zenstackhq/runtime": "1.0.0-beta.9",
|
|
44
|
+
"@zenstackhq/sdk": "1.0.0-beta.9"
|
|
27
45
|
},
|
|
28
46
|
"devDependencies": {
|
|
29
|
-
"@tanstack/react-query": "
|
|
30
|
-
"@tanstack/svelte-query": "
|
|
47
|
+
"@tanstack/react-query": "4.29.7",
|
|
48
|
+
"@tanstack/svelte-query": "4.29.7",
|
|
31
49
|
"@types/jest": "^29.5.0",
|
|
32
|
-
"@types/
|
|
33
|
-
"@types/react": "
|
|
50
|
+
"@types/node": "^18.0.0",
|
|
51
|
+
"@types/react": "18.2.0",
|
|
34
52
|
"@types/tmp": "^0.2.3",
|
|
35
|
-
"@types/upper-case-first": "^1.1.2",
|
|
36
53
|
"copyfiles": "^2.4.1",
|
|
37
54
|
"jest": "^29.5.0",
|
|
38
|
-
"react": "
|
|
39
|
-
"react-dom": "^17.0.2 || ^18",
|
|
55
|
+
"react": "18.2.0",
|
|
40
56
|
"rimraf": "^3.0.2",
|
|
41
57
|
"swr": "^2.0.3",
|
|
42
58
|
"ts-jest": "^29.0.5",
|
|
43
59
|
"typescript": "^4.9.4",
|
|
44
|
-
"@zenstackhq/testtools": "1.0.0-beta.
|
|
60
|
+
"@zenstackhq/testtools": "1.0.0-beta.9"
|
|
45
61
|
},
|
|
46
62
|
"scripts": {
|
|
47
63
|
"clean": "rimraf dist",
|
|
48
|
-
"build": "pnpm lint && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE
|
|
49
|
-
"watch": "tsc --watch",
|
|
64
|
+
"build": "pnpm lint && pnpm clean && tsc && tsup-node && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'",
|
|
65
|
+
"watch": "concurrently \"tsc --watch\" \"tsup-node --watch\"",
|
|
50
66
|
"lint": "eslint src --ext ts",
|
|
51
|
-
"test": "jest",
|
|
67
|
+
"test": "ZENSTACK_TEST=1 jest",
|
|
52
68
|
"publish-dev": "pnpm publish --tag dev"
|
|
53
69
|
}
|
|
54
70
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function signature for `fetch`.
|
|
3
|
+
*/
|
|
4
|
+
type FetchFn = (url: string, options?: RequestInit) => Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Context type for configuring the hooks.
|
|
7
|
+
*/
|
|
8
|
+
type APIContext = {
|
|
9
|
+
/**
|
|
10
|
+
* The endpoint to use for the queries.
|
|
11
|
+
*/
|
|
12
|
+
endpoint: string;
|
|
13
|
+
/**
|
|
14
|
+
* A custom fetch function for sending the HTTP requests.
|
|
15
|
+
*/
|
|
16
|
+
fetch?: FetchFn;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { APIContext as A, FetchFn as F };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Enumerable<T> = T | Array<T>;
|
|
2
|
+
type _TupleToUnion<T> = T extends (infer E)[] ? E : never;
|
|
3
|
+
type TupleToUnion<K extends readonly any[]> = _TupleToUnion<K>;
|
|
4
|
+
type MaybeTupleToUnion<T> = T extends any[] ? TupleToUnion<T> : T;
|
|
5
|
+
type PickEnumerable<T, K extends Enumerable<keyof T> | keyof T> = Pick<T, MaybeTupleToUnion<K>>;
|
|
6
|
+
|
|
7
|
+
export { Enumerable, MaybeTupleToUnion, PickEnumerable, TupleToUnion };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Enumerable<T> = T | Array<T>;
|
|
2
|
+
type _TupleToUnion<T> = T extends (infer E)[] ? E : never;
|
|
3
|
+
type TupleToUnion<K extends readonly any[]> = _TupleToUnion<K>;
|
|
4
|
+
type MaybeTupleToUnion<T> = T extends any[] ? TupleToUnion<T> : T;
|
|
5
|
+
type PickEnumerable<T, K extends Enumerable<keyof T> | keyof T> = Pick<T, MaybeTupleToUnion<K>>;
|
|
6
|
+
|
|
7
|
+
export { Enumerable, MaybeTupleToUnion, PickEnumerable, TupleToUnion };
|
package/runtime/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/runtime/index.ts
|
|
17
|
+
var runtime_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/index.ts"],"sourcesContent":["export * from './prisma-types';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { A as APIContext, F as FetchFn } from './common-52ab2c3a.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context for configuring react hooks.
|
|
8
|
+
*/
|
|
9
|
+
declare const RequestHandlerContext: react.Context<APIContext>;
|
|
10
|
+
/**
|
|
11
|
+
* Context provider.
|
|
12
|
+
*/
|
|
13
|
+
declare const Provider: react.Provider<APIContext>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a react-query query.
|
|
16
|
+
*
|
|
17
|
+
* @param model The name of the model under query.
|
|
18
|
+
* @param url The request URL.
|
|
19
|
+
* @param args The request args object, URL-encoded and appended as "?q=" parameter
|
|
20
|
+
* @param options The react-query options object
|
|
21
|
+
* @returns useQuery hook
|
|
22
|
+
*/
|
|
23
|
+
declare function query<R>(model: string, url: string, args?: unknown, options?: UseQueryOptions<R>, fetch?: FetchFn): _tanstack_react_query.UseQueryResult<R, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a POST mutation with react-query.
|
|
26
|
+
*
|
|
27
|
+
* @param model The name of the model under mutation.
|
|
28
|
+
* @param url The request URL.
|
|
29
|
+
* @param options The react-query options.
|
|
30
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
31
|
+
* @returns useMutation hooks
|
|
32
|
+
*/
|
|
33
|
+
declare function postMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a PUT mutation with react-query.
|
|
36
|
+
*
|
|
37
|
+
* @param model The name of the model under mutation.
|
|
38
|
+
* @param url The request URL.
|
|
39
|
+
* @param options The react-query options.
|
|
40
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
41
|
+
* @returns useMutation hooks
|
|
42
|
+
*/
|
|
43
|
+
declare function putMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a DELETE mutation with react-query.
|
|
46
|
+
*
|
|
47
|
+
* @param model The name of the model under mutation.
|
|
48
|
+
* @param url The request URL.
|
|
49
|
+
* @param options The react-query options.
|
|
50
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
51
|
+
* @returns useMutation hooks
|
|
52
|
+
*/
|
|
53
|
+
declare function deleteMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
54
|
+
|
|
55
|
+
export { Provider, RequestHandlerContext, deleteMutation, postMutation, putMutation, query };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { A as APIContext, F as FetchFn } from './common-52ab2c3a.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context for configuring react hooks.
|
|
8
|
+
*/
|
|
9
|
+
declare const RequestHandlerContext: react.Context<APIContext>;
|
|
10
|
+
/**
|
|
11
|
+
* Context provider.
|
|
12
|
+
*/
|
|
13
|
+
declare const Provider: react.Provider<APIContext>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a react-query query.
|
|
16
|
+
*
|
|
17
|
+
* @param model The name of the model under query.
|
|
18
|
+
* @param url The request URL.
|
|
19
|
+
* @param args The request args object, URL-encoded and appended as "?q=" parameter
|
|
20
|
+
* @param options The react-query options object
|
|
21
|
+
* @returns useQuery hook
|
|
22
|
+
*/
|
|
23
|
+
declare function query<R>(model: string, url: string, args?: unknown, options?: UseQueryOptions<R>, fetch?: FetchFn): _tanstack_react_query.UseQueryResult<R, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a POST mutation with react-query.
|
|
26
|
+
*
|
|
27
|
+
* @param model The name of the model under mutation.
|
|
28
|
+
* @param url The request URL.
|
|
29
|
+
* @param options The react-query options.
|
|
30
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
31
|
+
* @returns useMutation hooks
|
|
32
|
+
*/
|
|
33
|
+
declare function postMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a PUT mutation with react-query.
|
|
36
|
+
*
|
|
37
|
+
* @param model The name of the model under mutation.
|
|
38
|
+
* @param url The request URL.
|
|
39
|
+
* @param options The react-query options.
|
|
40
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
41
|
+
* @returns useMutation hooks
|
|
42
|
+
*/
|
|
43
|
+
declare function putMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a DELETE mutation with react-query.
|
|
46
|
+
*
|
|
47
|
+
* @param model The name of the model under mutation.
|
|
48
|
+
* @param url The request URL.
|
|
49
|
+
* @param options The react-query options.
|
|
50
|
+
* @param invalidateQueries Whether to invalidate queries after mutation.
|
|
51
|
+
* @returns useMutation hooks
|
|
52
|
+
*/
|
|
53
|
+
declare function deleteMutation<T, R = any, C extends boolean = boolean, Result = C extends true ? R | undefined : R>(model: string, url: string, options?: Omit<UseMutationOptions<Result, unknown, T>, 'mutationFn'>, fetch?: FetchFn, invalidateQueries?: boolean, checkReadBack?: C): _tanstack_react_query.UseMutationResult<Result, unknown, T, unknown>;
|
|
54
|
+
|
|
55
|
+
export { Provider, RequestHandlerContext, deleteMutation, postMutation, putMutation, query };
|