@zenstackhq/tanstack-query 1.0.0-beta.2 → 1.0.0-beta.20
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 +47 -47
- package/generator.js.map +1 -1
- package/package.json +35 -14
- package/runtime/common-52ab2c3a.d.ts +19 -0
- package/runtime/index.d.mts +18 -0
- package/runtime/index.d.ts +18 -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 -148
- package/res/shared.ts +0 -36
- package/res/svelte/helper.ts +0 -140
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,9 +15,9 @@ 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"));
|
|
20
|
+
const semver_1 = __importDefault(require("semver"));
|
|
21
21
|
const ts_morph_1 = require("ts-morph");
|
|
22
22
|
const upper_case_first_1 = require("upper-case-first");
|
|
23
23
|
const _1 = require(".");
|
|
@@ -33,8 +33,7 @@ function generate(model, options, dmmf) {
|
|
|
33
33
|
if (!supportedTargets.includes(target)) {
|
|
34
34
|
throw new sdk_1.PluginError(options.name, `Unsupported target "${target}", supported values: ${supportedTargets.join(', ')}`);
|
|
35
35
|
}
|
|
36
|
-
generateIndex(project, outDir, models);
|
|
37
|
-
generateHelper(target, project, outDir, options.useSuperJson === true);
|
|
36
|
+
generateIndex(project, outDir, models, target);
|
|
38
37
|
models.forEach((dataModel) => {
|
|
39
38
|
const mapping = dmmf.mappings.modelOperations.find((op) => op.model === dataModel.name);
|
|
40
39
|
if (!mapping) {
|
|
@@ -71,15 +70,18 @@ function generateQueryHook(target, sf, model, operation, returnArray, optionalIn
|
|
|
71
70
|
});
|
|
72
71
|
func.addStatements([
|
|
73
72
|
makeGetContext(target),
|
|
74
|
-
`return query<${returnType}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, args, options);`,
|
|
73
|
+
`return query<${returnType}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, args, options, fetch);`,
|
|
75
74
|
]);
|
|
76
75
|
}
|
|
77
|
-
function generateMutationHook(target, sf, model, operation, httpVerb, overrideReturnType) {
|
|
76
|
+
function generateMutationHook(target, sf, model, operation, httpVerb, checkReadBack, overrideReturnType) {
|
|
78
77
|
const capOperation = (0, upper_case_first_1.upperCaseFirst)(operation);
|
|
79
78
|
const argsType = `Prisma.${model}${capOperation}Args`;
|
|
80
79
|
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
let returnType = overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : `CheckSelect<T, ${model}, Prisma.${model}GetPayload<T>>`;
|
|
81
|
+
if (checkReadBack) {
|
|
82
|
+
returnType = `(${returnType} | undefined )`;
|
|
83
|
+
}
|
|
84
|
+
const nonGenericOptionsType = `Omit<${makeMutationOptions(target, checkReadBack ? `(${overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model} | undefined)` : overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model, argsType)}, 'mutationFn'>`;
|
|
83
85
|
const optionsType = `Omit<${makeMutationOptions(target, returnType, inputType)}, 'mutationFn'>`;
|
|
84
86
|
const func = sf.addFunction({
|
|
85
87
|
name: `use${capOperation}${model}`,
|
|
@@ -104,7 +106,7 @@ function generateMutationHook(target, sf, model, operation, httpVerb, overrideRe
|
|
|
104
106
|
{
|
|
105
107
|
name: `_mutation`,
|
|
106
108
|
initializer: `
|
|
107
|
-
${httpVerb}Mutation<${argsType}, ${overrideReturnType !== null && overrideReturnType !== void 0 ? overrideReturnType : model}>('${model}', \`\${endpoint}/${(0, lower_case_first_1.lowerCaseFirst)(model)}/${operation}\`, options, invalidateQueries)
|
|
109
|
+
${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
110
|
`,
|
|
109
111
|
},
|
|
110
112
|
],
|
|
@@ -164,23 +166,26 @@ function generateMutationHook(target, sf, model, operation, httpVerb, overrideRe
|
|
|
164
166
|
func.addStatements('return mutation;');
|
|
165
167
|
}
|
|
166
168
|
function generateModelHooks(target, project, outDir, model, mapping) {
|
|
169
|
+
const modelNameCap = (0, upper_case_first_1.upperCaseFirst)(model.name);
|
|
170
|
+
const prismaVersion = (0, sdk_1.getPrismaVersion)();
|
|
167
171
|
const fileName = (0, change_case_1.paramCase)(model.name);
|
|
168
172
|
const sf = project.createSourceFile(path_1.default.join(outDir, `${fileName}.ts`), undefined, { overwrite: true });
|
|
169
173
|
sf.addStatements('/* eslint-disable */');
|
|
174
|
+
const prismaImport = (0, sdk_1.getPrismaClientImportSpec)(model.$container, outDir);
|
|
170
175
|
sf.addImportDeclaration({
|
|
171
176
|
namedImports: ['Prisma', model.name],
|
|
172
177
|
isTypeOnly: true,
|
|
173
|
-
moduleSpecifier:
|
|
178
|
+
moduleSpecifier: prismaImport,
|
|
174
179
|
});
|
|
175
180
|
sf.addStatements(makeBaseImports(target));
|
|
176
181
|
// create is somehow named "createOne" in the DMMF
|
|
177
182
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
183
|
if (mapping.create || mapping.createOne) {
|
|
179
|
-
generateMutationHook(target, sf, model.name, 'create', 'post');
|
|
184
|
+
generateMutationHook(target, sf, model.name, 'create', 'post', true);
|
|
180
185
|
}
|
|
181
186
|
// createMany
|
|
182
187
|
if (mapping.createMany) {
|
|
183
|
-
generateMutationHook(target, sf, model.name, 'createMany', 'post', 'Prisma.BatchPayload');
|
|
188
|
+
generateMutationHook(target, sf, model.name, 'createMany', 'post', false, 'Prisma.BatchPayload');
|
|
184
189
|
}
|
|
185
190
|
// findMany
|
|
186
191
|
if (mapping.findMany) {
|
|
@@ -198,40 +203,45 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
198
203
|
// update is somehow named "updateOne" in the DMMF
|
|
199
204
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
205
|
if (mapping.update || mapping.updateOne) {
|
|
201
|
-
generateMutationHook(target, sf, model.name, 'update', 'put');
|
|
206
|
+
generateMutationHook(target, sf, model.name, 'update', 'put', true);
|
|
202
207
|
}
|
|
203
208
|
// updateMany
|
|
204
209
|
if (mapping.updateMany) {
|
|
205
|
-
generateMutationHook(target, sf, model.name, 'updateMany', 'put', 'Prisma.BatchPayload');
|
|
210
|
+
generateMutationHook(target, sf, model.name, 'updateMany', 'put', false, 'Prisma.BatchPayload');
|
|
206
211
|
}
|
|
207
212
|
// upsert
|
|
208
213
|
// upsert is somehow named "upsertOne" in the DMMF
|
|
209
214
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
215
|
if (mapping.upsert || mapping.upsertOne) {
|
|
211
|
-
generateMutationHook(target, sf, model.name, 'upsert', 'post');
|
|
216
|
+
generateMutationHook(target, sf, model.name, 'upsert', 'post', true);
|
|
212
217
|
}
|
|
213
218
|
// del
|
|
214
219
|
// delete is somehow named "deleteOne" in the DMMF
|
|
215
220
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
216
221
|
if (mapping.delete || mapping.deleteOne) {
|
|
217
|
-
generateMutationHook(target, sf, model.name, 'delete', 'delete');
|
|
222
|
+
generateMutationHook(target, sf, model.name, 'delete', 'delete', true);
|
|
218
223
|
}
|
|
219
224
|
// deleteMany
|
|
220
225
|
if (mapping.deleteMany) {
|
|
221
|
-
generateMutationHook(target, sf, model.name, 'deleteMany', 'delete', 'Prisma.BatchPayload');
|
|
226
|
+
generateMutationHook(target, sf, model.name, 'deleteMany', 'delete', false, 'Prisma.BatchPayload');
|
|
222
227
|
}
|
|
223
228
|
// aggregate
|
|
224
229
|
if (mapping.aggregate) {
|
|
225
|
-
generateQueryHook(target, sf,
|
|
230
|
+
generateQueryHook(target, sf, modelNameCap, 'aggregate', false, false, `Prisma.Get${modelNameCap}AggregateType<T>`);
|
|
226
231
|
}
|
|
227
232
|
// groupBy
|
|
228
233
|
if (mapping.groupBy) {
|
|
234
|
+
let useName = modelNameCap;
|
|
235
|
+
// prisma 4 and 5 different typing for "groupBy" and we have to deal with it separately
|
|
236
|
+
if (prismaVersion && semver_1.default.gte(prismaVersion, '5.0.0')) {
|
|
237
|
+
useName = model.name;
|
|
238
|
+
}
|
|
229
239
|
const typeParameters = [
|
|
230
|
-
`T extends Prisma.${
|
|
240
|
+
`T extends Prisma.${useName}GroupByArgs`,
|
|
231
241
|
`HasSelectOrTake extends Prisma.Or<Prisma.Extends<'skip', Prisma.Keys<T>>, Prisma.Extends<'take', Prisma.Keys<T>>>`,
|
|
232
|
-
`OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.${
|
|
242
|
+
`OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.${useName}GroupByArgs['orderBy'] }: { orderBy?: Prisma.${useName}GroupByArgs['orderBy'] },`,
|
|
233
243
|
`OrderFields extends Prisma.ExcludeUnderscoreKeys<Prisma.Keys<Prisma.MaybeTupleToUnion<T['orderBy']>>>`,
|
|
234
|
-
`ByFields extends Prisma.
|
|
244
|
+
`ByFields extends Prisma.MaybeTupleToUnion<T['by']>`,
|
|
235
245
|
`ByValid extends Prisma.Has<ByFields, OrderFields>`,
|
|
236
246
|
`HavingFields extends Prisma.GetHavingFields<T['having']>`,
|
|
237
247
|
`HavingValid extends Prisma.Has<ByFields, HavingFields>`,
|
|
@@ -280,65 +290,55 @@ function generateModelHooks(target, project, outDir, model, mapping) {
|
|
|
280
290
|
}[OrderFields]`,
|
|
281
291
|
];
|
|
282
292
|
const returnType = `{} extends InputErrors ?
|
|
283
|
-
Array<
|
|
293
|
+
Array<PickEnumerable<Prisma.${modelNameCap}GroupByOutputType, T['by']> &
|
|
284
294
|
{
|
|
285
|
-
[P in ((keyof T) & (keyof Prisma.${
|
|
295
|
+
[P in ((keyof T) & (keyof Prisma.${modelNameCap}GroupByOutputType))]: P extends '_count'
|
|
286
296
|
? T[P] extends boolean
|
|
287
297
|
? number
|
|
288
|
-
: Prisma.GetScalarType<T[P], Prisma.${
|
|
289
|
-
: Prisma.GetScalarType<T[P], Prisma.${
|
|
298
|
+
: Prisma.GetScalarType<T[P], Prisma.${modelNameCap}GroupByOutputType[P]>
|
|
299
|
+
: Prisma.GetScalarType<T[P], Prisma.${modelNameCap}GroupByOutputType[P]>
|
|
290
300
|
}
|
|
291
301
|
> : InputErrors`;
|
|
292
|
-
generateQueryHook(target, sf, model.name, 'groupBy', false, false, returnType, `Prisma.SubsetIntersection<T, Prisma.${
|
|
302
|
+
generateQueryHook(target, sf, model.name, 'groupBy', false, false, returnType, `Prisma.SubsetIntersection<T, Prisma.${useName}GroupByArgs, OrderByArg> & InputErrors`, typeParameters);
|
|
293
303
|
}
|
|
294
304
|
// somehow dmmf doesn't contain "count" operation, so we unconditionally add it here
|
|
295
305
|
{
|
|
296
|
-
generateQueryHook(target, sf, model.name, 'count', false, true, `T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.${
|
|
306
|
+
generateQueryHook(target, sf, model.name, 'count', false, true, `T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.${modelNameCap}CountAggregateOutputType> : number`);
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
|
-
function generateIndex(project, outDir, models) {
|
|
309
|
+
function generateIndex(project, outDir, models, target) {
|
|
300
310
|
const sf = project.createSourceFile(path_1.default.join(outDir, 'index.ts'), undefined, { overwrite: true });
|
|
301
311
|
sf.addStatements(models.map((d) => `export * from './${(0, change_case_1.paramCase)(d.name)}';`));
|
|
302
|
-
sf.addStatements(`export * from './_helper';`);
|
|
303
|
-
}
|
|
304
|
-
function generateHelper(target, project, outDir, useSuperJson) {
|
|
305
|
-
let srcFile;
|
|
306
312
|
switch (target) {
|
|
307
313
|
case 'react':
|
|
308
|
-
|
|
314
|
+
sf.addStatements(`export { Provider } from '@zenstackhq/tanstack-query/runtime/react';`);
|
|
309
315
|
break;
|
|
310
316
|
case 'svelte':
|
|
311
|
-
|
|
317
|
+
sf.addStatements(`export { SvelteQueryContextKey } from '@zenstackhq/tanstack-query/runtime/svelte';`);
|
|
312
318
|
break;
|
|
313
|
-
default:
|
|
314
|
-
throw new sdk_1.PluginError(_1.name, `Unsupported target: ${target}`);
|
|
315
319
|
}
|
|
316
|
-
// merge content of `shared.ts`, `helper.ts` and `marshal-?.ts`
|
|
317
|
-
const sharedContent = fs_1.default.readFileSync(path_1.default.join(__dirname, './res/shared.ts'), 'utf-8');
|
|
318
|
-
const helperContent = fs_1.default.readFileSync(srcFile, 'utf-8');
|
|
319
|
-
const marshalContent = fs_1.default.readFileSync(path_1.default.join(__dirname, useSuperJson ? './res/marshal-superjson.ts' : './res/marshal-json.ts'), 'utf-8');
|
|
320
|
-
project.createSourceFile(path_1.default.join(outDir, '_helper.ts'), `${sharedContent}\n${helperContent}\n${marshalContent}`, {
|
|
321
|
-
overwrite: true,
|
|
322
|
-
});
|
|
323
320
|
}
|
|
324
321
|
function makeGetContext(target) {
|
|
325
322
|
switch (target) {
|
|
326
323
|
case 'react':
|
|
327
|
-
return 'const { endpoint } = useContext(RequestHandlerContext);';
|
|
324
|
+
return 'const { endpoint, fetch } = useContext(RequestHandlerContext);';
|
|
328
325
|
case 'svelte':
|
|
329
|
-
return `const { endpoint } = getContext<RequestHandlerContext>(SvelteQueryContextKey);`;
|
|
326
|
+
return `const { endpoint, fetch } = getContext<RequestHandlerContext>(SvelteQueryContextKey);`;
|
|
330
327
|
default:
|
|
331
328
|
throw new sdk_1.PluginError(_1.name, `Unsupported target "${target}"`);
|
|
332
329
|
}
|
|
333
330
|
}
|
|
334
331
|
function makeBaseImports(target) {
|
|
335
|
-
const shared = [
|
|
332
|
+
const shared = [
|
|
333
|
+
`import { query, postMutation, putMutation, deleteMutation } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
334
|
+
`import type { PickEnumerable, CheckSelect } from '@zenstackhq/tanstack-query/runtime';`,
|
|
335
|
+
];
|
|
336
336
|
switch (target) {
|
|
337
337
|
case 'react':
|
|
338
338
|
return [
|
|
339
339
|
`import { useContext } from 'react';`,
|
|
340
340
|
`import type { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';`,
|
|
341
|
-
`import { RequestHandlerContext } from '
|
|
341
|
+
`import { RequestHandlerContext } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
342
342
|
...shared,
|
|
343
343
|
];
|
|
344
344
|
case 'svelte':
|
|
@@ -346,7 +346,7 @@ function makeBaseImports(target) {
|
|
|
346
346
|
`import { getContext } from 'svelte';`,
|
|
347
347
|
`import { derived } from 'svelte/store';`,
|
|
348
348
|
`import type { MutationOptions, QueryOptions } from '@tanstack/svelte-query';`,
|
|
349
|
-
`import { SvelteQueryContextKey, type RequestHandlerContext } from '
|
|
349
|
+
`import { SvelteQueryContextKey, type RequestHandlerContext } from '@zenstackhq/tanstack-query/runtime/${target}';`,
|
|
350
350
|
...shared,
|
|
351
351
|
];
|
|
352
352
|
default:
|
package/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,yCAUyB;AAEzB,6CAAwC;AACxC,uDAAkD;AAClD,gDAAwB;AACxB,oDAA4B;AAC5B,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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Q,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,29 @@
|
|
|
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.20",
|
|
5
5
|
"description": "ZenStack plugin for generating tanstack-query hooks",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": {
|
|
12
|
+
"default": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"./runtime/react": {
|
|
15
|
+
"import": "./runtime/react.mjs",
|
|
16
|
+
"require": "./runtime/react.js",
|
|
17
|
+
"default": "./runtime/react.js",
|
|
18
|
+
"types": "./runtime/react.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./runtime/svelte": {
|
|
21
|
+
"import": "./runtime/svelte.mjs",
|
|
22
|
+
"require": "./runtime/svelte.js",
|
|
23
|
+
"default": "./runtime/svelte.js",
|
|
24
|
+
"types": "./runtime/svelte.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
7
27
|
"repository": {
|
|
8
28
|
"type": "git",
|
|
9
29
|
"url": "https://github.com/zenstackhq/zenstack"
|
|
@@ -16,39 +36,40 @@
|
|
|
16
36
|
"author": "ZenStack Team",
|
|
17
37
|
"license": "MIT",
|
|
18
38
|
"dependencies": {
|
|
19
|
-
"@prisma/generator-helper": "^
|
|
39
|
+
"@prisma/generator-helper": "^5.0.0",
|
|
20
40
|
"change-case": "^4.1.2",
|
|
21
41
|
"decimal.js": "^10.4.2",
|
|
22
42
|
"lower-case-first": "^2.0.2",
|
|
43
|
+
"semver": "^7.3.8",
|
|
23
44
|
"superjson": "^1.11.0",
|
|
24
45
|
"ts-morph": "^16.0.0",
|
|
25
46
|
"upper-case-first": "^2.0.2",
|
|
26
|
-
"@zenstackhq/
|
|
47
|
+
"@zenstackhq/runtime": "1.0.0-beta.20",
|
|
48
|
+
"@zenstackhq/sdk": "1.0.0-beta.20"
|
|
27
49
|
},
|
|
28
50
|
"devDependencies": {
|
|
29
|
-
"@tanstack/react-query": "
|
|
30
|
-
"@tanstack/svelte-query": "
|
|
51
|
+
"@tanstack/react-query": "4.29.7",
|
|
52
|
+
"@tanstack/svelte-query": "4.29.7",
|
|
31
53
|
"@types/jest": "^29.5.0",
|
|
32
|
-
"@types/
|
|
33
|
-
"@types/react": "
|
|
54
|
+
"@types/node": "^18.0.0",
|
|
55
|
+
"@types/react": "18.2.0",
|
|
56
|
+
"@types/semver": "^7.3.13",
|
|
34
57
|
"@types/tmp": "^0.2.3",
|
|
35
|
-
"@types/upper-case-first": "^1.1.2",
|
|
36
58
|
"copyfiles": "^2.4.1",
|
|
37
59
|
"jest": "^29.5.0",
|
|
38
|
-
"react": "
|
|
39
|
-
"react-dom": "^17.0.2 || ^18",
|
|
60
|
+
"react": "18.2.0",
|
|
40
61
|
"rimraf": "^3.0.2",
|
|
41
62
|
"swr": "^2.0.3",
|
|
42
63
|
"ts-jest": "^29.0.5",
|
|
43
64
|
"typescript": "^4.9.4",
|
|
44
|
-
"@zenstackhq/testtools": "1.0.0-beta.
|
|
65
|
+
"@zenstackhq/testtools": "1.0.0-beta.20"
|
|
45
66
|
},
|
|
46
67
|
"scripts": {
|
|
47
68
|
"clean": "rimraf dist",
|
|
48
|
-
"build": "pnpm lint && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE '
|
|
49
|
-
"watch": "tsc --watch",
|
|
69
|
+
"build": "pnpm lint && pnpm clean && tsc && tsup-node && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'",
|
|
70
|
+
"watch": "concurrently \"tsc --watch\" \"tsup-node --watch\"",
|
|
50
71
|
"lint": "eslint src --ext ts",
|
|
51
|
-
"test": "jest",
|
|
72
|
+
"test": "ZENSTACK_TEST=1 jest",
|
|
52
73
|
"publish-dev": "pnpm publish --tag dev"
|
|
53
74
|
}
|
|
54
75
|
}
|
|
@@ -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,18 @@
|
|
|
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
|
+
type SelectAndInclude = {
|
|
7
|
+
select: any;
|
|
8
|
+
include: any;
|
|
9
|
+
};
|
|
10
|
+
type HasSelect = {
|
|
11
|
+
select: any;
|
|
12
|
+
};
|
|
13
|
+
type HasInclude = {
|
|
14
|
+
include: any;
|
|
15
|
+
};
|
|
16
|
+
type CheckSelect<T, S, U> = T extends SelectAndInclude ? 'Please either choose `select` or `include`' : T extends HasSelect ? U : T extends HasInclude ? U : S;
|
|
17
|
+
|
|
18
|
+
export { CheckSelect, Enumerable, MaybeTupleToUnion, PickEnumerable, TupleToUnion };
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
type SelectAndInclude = {
|
|
7
|
+
select: any;
|
|
8
|
+
include: any;
|
|
9
|
+
};
|
|
10
|
+
type HasSelect = {
|
|
11
|
+
select: any;
|
|
12
|
+
};
|
|
13
|
+
type HasInclude = {
|
|
14
|
+
include: any;
|
|
15
|
+
};
|
|
16
|
+
type CheckSelect<T, S, U> = T extends SelectAndInclude ? 'Please either choose `select` or `include`' : T extends HasSelect ? U : T extends HasInclude ? U : S;
|
|
17
|
+
|
|
18
|
+
export { CheckSelect, 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 };
|