@metaobjectsdev/codegen-ts-tanstack 1.0.0-rc.4 → 1.0.0-rc.6
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/dist/tanstack-grid-hook.d.ts.map +1 -1
- package/dist/tanstack-grid-hook.js +8 -3
- package/dist/tanstack-grid-hook.js.map +1 -1
- package/dist/tanstack-grid.d.ts.map +1 -1
- package/dist/tanstack-grid.js +6 -2
- package/dist/tanstack-grid.js.map +1 -1
- package/dist/tanstack-query.d.ts +1 -1
- package/dist/tanstack-query.d.ts.map +1 -1
- package/dist/tanstack-query.js +9 -4
- package/dist/tanstack-query.js.map +1 -1
- package/dist/templates/columns-file.d.ts.map +1 -1
- package/dist/templates/columns-file.js +8 -11
- package/dist/templates/columns-file.js.map +1 -1
- package/dist/templates/grid-hook-file.d.ts.map +1 -1
- package/dist/templates/grid-hook-file.js +9 -9
- package/dist/templates/grid-hook-file.js.map +1 -1
- package/dist/templates/hooks-file.d.ts +1 -1
- package/dist/templates/hooks-file.d.ts.map +1 -1
- package/dist/templates/hooks-file.js +23 -23
- package/dist/templates/hooks-file.js.map +1 -1
- package/package.json +3 -3
- package/src/reference/grid-hook.ts +9 -3
- package/src/reference/grid.ts +6 -1
- package/src/reference/hooks.ts +10 -4
- package/src/tanstack-grid-hook.ts +8 -2
- package/src/tanstack-grid.ts +6 -1
- package/src/tanstack-query.ts +9 -3
- package/src/templates/columns-file.ts +13 -11
- package/src/templates/grid-hook-file.ts +15 -11
- package/src/templates/hooks-file.ts +23 -22
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
isTphDiscriminatorBase,
|
|
21
21
|
tphPlan,
|
|
22
22
|
getPkInfo,
|
|
23
|
+
effectivePackage,
|
|
23
24
|
} from "@metaobjectsdev/codegen-ts";
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
* - useUpdate<Entity>
|
|
36
37
|
* - useDelete<Entity>
|
|
37
38
|
*
|
|
38
|
-
* All hooks call
|
|
39
|
+
* All hooks call useEntityPathFetcher() (from @metaobjectsdev/tanstack) for
|
|
39
40
|
* the underlying HTTP. Mutations aggressively invalidate <entity>Keys.all().
|
|
40
41
|
*/
|
|
41
42
|
export function renderHooksFile(entity: MetaObject, ctx: RenderContext): string {
|
|
@@ -44,7 +45,7 @@ export function renderHooksFile(entity: MetaObject, ctx: RenderContext): string
|
|
|
44
45
|
const entityModule = entityModuleSpecifier(
|
|
45
46
|
ctx.selfTarget,
|
|
46
47
|
ctx.entityModuleTarget,
|
|
47
|
-
entity
|
|
48
|
+
effectivePackage(entity),
|
|
48
49
|
entity.name,
|
|
49
50
|
ctx.extStyle,
|
|
50
51
|
);
|
|
@@ -105,7 +106,7 @@ function renderM2mHooks(
|
|
|
105
106
|
const useQuerySym = imp("useQuery@@tanstack/react-query");
|
|
106
107
|
const useQueryOptionsSym = imp("t:UseQueryOptions@@tanstack/react-query");
|
|
107
108
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
108
|
-
const
|
|
109
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
109
110
|
|
|
110
111
|
const source = entity.name;
|
|
111
112
|
|
|
@@ -141,7 +142,7 @@ export function ${hookName}(
|
|
|
141
142
|
sourceId: ${pkType} | undefined,
|
|
142
143
|
opts?: Omit<${useQueryOptionsSym}<${targetSym}[]>, "queryKey" | "queryFn">,
|
|
143
144
|
): ${useQueryResultSym}<${targetSym}[]> {
|
|
144
|
-
const fetcher = ${
|
|
145
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
145
146
|
return ${useQuerySym}<${targetSym}[]>({
|
|
146
147
|
queryKey: ${keysVar}.relation(${relLit}, sourceId),
|
|
147
148
|
queryFn: () => fetcher<${targetSym}[]>(\`\${${source}.$path}/\${sourceId}/${e.name}\`),
|
|
@@ -177,7 +178,7 @@ function renderReadOnlyHooksFile(entity: MetaObject, entityModule: string, ctx:
|
|
|
177
178
|
const useQuerySym = imp("useQuery@@tanstack/react-query");
|
|
178
179
|
const useQueryOptionsSym = imp("t:UseQueryOptions@@tanstack/react-query");
|
|
179
180
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
180
|
-
const
|
|
181
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
181
182
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
182
183
|
|
|
183
184
|
const entityImports: Code = code`
|
|
@@ -203,7 +204,7 @@ export function use${entityName}(
|
|
|
203
204
|
id: ${pkType},
|
|
204
205
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row>, "queryKey" | "queryFn">,
|
|
205
206
|
): ${useQueryResultSym}<${entityName}Row> {
|
|
206
|
-
const fetcher = ${
|
|
207
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
207
208
|
return ${useQuerySym}<${entityName}Row>({
|
|
208
209
|
queryKey: ${keysVar}.detail(id),
|
|
209
210
|
queryFn: () => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`),
|
|
@@ -215,7 +216,7 @@ export function use${entityNamePlural}(
|
|
|
215
216
|
filter?: ${entityName}Filter,
|
|
216
217
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row[]>, "queryKey" | "queryFn">,
|
|
217
218
|
): ${useQueryResultSym}<${entityName}Row[]> {
|
|
218
|
-
const fetcher = ${
|
|
219
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
219
220
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
220
221
|
return ${useQuerySym}<${entityName}Row[]>({
|
|
221
222
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -256,7 +257,7 @@ function renderFullHooksFile(entity: MetaObject, entityModule: string, ctx: Rend
|
|
|
256
257
|
const useMutationOptionsSym = imp("t:UseMutationOptions@@tanstack/react-query");
|
|
257
258
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
258
259
|
const useMutationResultSym = imp("t:UseMutationResult@@tanstack/react-query");
|
|
259
|
-
const
|
|
260
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
260
261
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
261
262
|
|
|
262
263
|
const entityImports: Code = code`
|
|
@@ -284,7 +285,7 @@ export function use${entityName}(
|
|
|
284
285
|
id: ${pkType},
|
|
285
286
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row>, "queryKey" | "queryFn">,
|
|
286
287
|
): ${useQueryResultSym}<${entityName}Row> {
|
|
287
|
-
const fetcher = ${
|
|
288
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
288
289
|
return ${useQuerySym}<${entityName}Row>({
|
|
289
290
|
queryKey: ${keysVar}.detail(id),
|
|
290
291
|
queryFn: () => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`),
|
|
@@ -296,7 +297,7 @@ export function use${entityNamePlural}(
|
|
|
296
297
|
filter?: ${entityName}Filter,
|
|
297
298
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row[]>, "queryKey" | "queryFn">,
|
|
298
299
|
): ${useQueryResultSym}<${entityName}Row[]> {
|
|
299
|
-
const fetcher = ${
|
|
300
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
300
301
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
301
302
|
return ${useQuerySym}<${entityName}Row[]>({
|
|
302
303
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -312,7 +313,7 @@ export function use${entityNamePlural}(
|
|
|
312
313
|
export function useCreate${entityName}(
|
|
313
314
|
opts?: Omit<${useMutationOptionsSym}<${entityName}Row, Error, ${entityName}Insert>, "mutationFn">,
|
|
314
315
|
): ${useMutationResultSym}<${entityName}Row, Error, ${entityName}Insert> {
|
|
315
|
-
const fetcher = ${
|
|
316
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
316
317
|
const qc = ${useQueryClientSym}();
|
|
317
318
|
return ${useMutationSym}<${entityName}Row, Error, ${entityName}Insert>({
|
|
318
319
|
mutationFn: (input) => fetcher<${entityName}Row>(\`\${${entityName}.$path}\`, {
|
|
@@ -331,7 +332,7 @@ export function useCreate${entityName}(
|
|
|
331
332
|
export function useUpdate${entityName}(
|
|
332
333
|
opts?: Omit<${useMutationOptionsSym}<${entityName}Row, Error, { id: ${pkType}; input: ${entityName}Update }>, "mutationFn">,
|
|
333
334
|
): ${useMutationResultSym}<${entityName}Row, Error, { id: ${pkType}; input: ${entityName}Update }> {
|
|
334
|
-
const fetcher = ${
|
|
335
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
335
336
|
const qc = ${useQueryClientSym}();
|
|
336
337
|
return ${useMutationSym}({
|
|
337
338
|
mutationFn: ({ id, input }) => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`, {
|
|
@@ -350,7 +351,7 @@ export function useUpdate${entityName}(
|
|
|
350
351
|
export function useDelete${entityName}(
|
|
351
352
|
opts?: Omit<${useMutationOptionsSym}<void, Error, ${pkType}>, "mutationFn">,
|
|
352
353
|
): ${useMutationResultSym}<void, Error, ${pkType}> {
|
|
353
|
-
const fetcher = ${
|
|
354
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
354
355
|
const qc = ${useQueryClientSym}();
|
|
355
356
|
return ${useMutationSym}({
|
|
356
357
|
mutationFn: (id) => fetcher<void>(\`\${${entityName}.$path}/\${id}\`, { method: "DELETE" }),
|
|
@@ -396,7 +397,7 @@ function renderTphHooksFile(base: MetaObject, ctx: RenderContext, baseModule: st
|
|
|
396
397
|
const useMutationOptionsSym = imp("t:UseMutationOptions@@tanstack/react-query");
|
|
397
398
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
398
399
|
const useMutationResultSym = imp("t:UseMutationResult@@tanstack/react-query");
|
|
399
|
-
const
|
|
400
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
400
401
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
401
402
|
|
|
402
403
|
const subtypes = plan.subtypes;
|
|
@@ -408,7 +409,7 @@ function renderTphHooksFile(base: MetaObject, ctx: RenderContext, baseModule: st
|
|
|
408
409
|
// allowlist actually permits.
|
|
409
410
|
const subImportLines = subtypes
|
|
410
411
|
.map((s) => {
|
|
411
|
-
const m = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, s.entity
|
|
412
|
+
const m = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, effectivePackage(s.entity), s.entity.name, ctx.extStyle);
|
|
412
413
|
return `import { type ${s.entity.name}, type ${s.entity.name}Filter } from ${JSON.stringify(m)};`;
|
|
413
414
|
})
|
|
414
415
|
.join("\n");
|
|
@@ -439,7 +440,7 @@ export function use${baseName}(
|
|
|
439
440
|
id: ${pkType},
|
|
440
441
|
opts?: Omit<${useQueryOptionsSym}<${baseName}>, "queryKey" | "queryFn">,
|
|
441
442
|
): ${useQueryResultSym}<${baseName}> {
|
|
442
|
-
const fetcher = ${
|
|
443
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
443
444
|
return ${useQuerySym}<${baseName}>({
|
|
444
445
|
queryKey: ${keysVar}.detail(id),
|
|
445
446
|
queryFn: () => fetcher<${baseName}>(\`\${${baseName}.$path}/\${id}\`),
|
|
@@ -451,7 +452,7 @@ export function use${pluralize(baseName)}(
|
|
|
451
452
|
filter?: ${baseName}Filter,
|
|
452
453
|
opts?: Omit<${useQueryOptionsSym}<${baseName}[]>, "queryKey" | "queryFn">,
|
|
453
454
|
): ${useQueryResultSym}<${baseName}[]> {
|
|
454
|
-
const fetcher = ${
|
|
455
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
455
456
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
456
457
|
return ${useQuerySym}<${baseName}[]>({
|
|
457
458
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -473,7 +474,7 @@ export function use${pluralize(subName)}(
|
|
|
473
474
|
filter?: ${subName}Filter,
|
|
474
475
|
opts?: Omit<${useQueryOptionsSym}<${subName}[]>, "queryKey" | "queryFn">,
|
|
475
476
|
): ${useQueryResultSym}<${subName}[]> {
|
|
476
|
-
const fetcher = ${
|
|
477
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
477
478
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
478
479
|
return ${useQuerySym}<${subName}[]>({
|
|
479
480
|
queryKey: ${keysVar}.subtypeList(${valueLit}, filter),
|
|
@@ -486,7 +487,7 @@ export function use${subName}(
|
|
|
486
487
|
id: ${pkType},
|
|
487
488
|
opts?: Omit<${useQueryOptionsSym}<${subName}>, "queryKey" | "queryFn">,
|
|
488
489
|
): ${useQueryResultSym}<${subName}> {
|
|
489
|
-
const fetcher = ${
|
|
490
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
490
491
|
return ${useQuerySym}<${subName}>({
|
|
491
492
|
queryKey: ${keysVar}.subtypeDetail(${valueLit}, id),
|
|
492
493
|
queryFn: () => fetcher<${subName}>(\`\${${baseName}.$path}/${seg}/\${id}\`),
|
|
@@ -497,7 +498,7 @@ export function use${subName}(
|
|
|
497
498
|
export function useCreate${subName}(
|
|
498
499
|
opts?: Omit<${useMutationOptionsSym}<${subName}, Error, ${createInput}>, "mutationFn">,
|
|
499
500
|
): ${useMutationResultSym}<${subName}, Error, ${createInput}> {
|
|
500
|
-
const fetcher = ${
|
|
501
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
501
502
|
const qc = ${useQueryClientSym}();
|
|
502
503
|
return ${useMutationSym}<${subName}, Error, ${createInput}>({
|
|
503
504
|
mutationFn: (input) => fetcher<${subName}>(${subPath}, {
|
|
@@ -516,7 +517,7 @@ export function useCreate${subName}(
|
|
|
516
517
|
export function useUpdate${subName}(
|
|
517
518
|
opts?: Omit<${useMutationOptionsSym}<${subName}, Error, { id: ${pkType}; input: ${updateInput} }>, "mutationFn">,
|
|
518
519
|
): ${useMutationResultSym}<${subName}, Error, { id: ${pkType}; input: ${updateInput} }> {
|
|
519
|
-
const fetcher = ${
|
|
520
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
520
521
|
const qc = ${useQueryClientSym}();
|
|
521
522
|
return ${useMutationSym}({
|
|
522
523
|
mutationFn: ({ id, input }) => fetcher<${subName}>(\`\${${baseName}.$path}/${seg}/\${id}\`, {
|
|
@@ -535,7 +536,7 @@ export function useUpdate${subName}(
|
|
|
535
536
|
export function useDelete${subName}(
|
|
536
537
|
opts?: Omit<${useMutationOptionsSym}<void, Error, ${pkType}>, "mutationFn">,
|
|
537
538
|
): ${useMutationResultSym}<void, Error, ${pkType}> {
|
|
538
|
-
const fetcher = ${
|
|
539
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
539
540
|
const qc = ${useQueryClientSym}();
|
|
540
541
|
return ${useMutationSym}({
|
|
541
542
|
mutationFn: (id) => fetcher<void>(\`\${${baseName}.$path}/${seg}/\${id}\`, { method: "DELETE" }),
|