@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-grid-hook.d.ts","sourceRoot":"","sources":["../src/tanstack-grid-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"tanstack-grid-hook.d.ts","sourceRoot":"","sources":["../src/tanstack-grid-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,EAGxD,MAAM,4BAA4B,CAAC;AAIpC,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,EA2ExB,gBAAgB,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { perEntity, formatTs, entityOutputPath, entityMetaFileName, renderEntityMetaFile, servesReadApi, isTphSubtype, withClientDirective, namesRef, namesConstArg, } from "@metaobjectsdev/codegen-ts";
|
|
1
|
+
import { perEntity, formatTs, entityOutputPath, entityMetaFileName, renderEntityMetaFile, servesReadApi, isTphSubtype, withClientDirective, namesRef, namesConstArg, effectivePackage, } from "@metaobjectsdev/codegen-ts";
|
|
2
2
|
import { hasDataGridLayout, warnMissingDataGridLayout } from "./data-grid-gate.js";
|
|
3
3
|
import { renderGridHookFile } from "./templates/grid-hook-file.js";
|
|
4
4
|
/**
|
|
@@ -54,16 +54,21 @@ export const tanstackGridHook = function tanstackGridHook(opts) {
|
|
|
54
54
|
// module's).
|
|
55
55
|
const rc = ctx.renderContext;
|
|
56
56
|
const metaNames = namesRef(entity, rc);
|
|
57
|
+
const pkg = effectivePackage(entity);
|
|
57
58
|
return [{
|
|
58
|
-
path: entityOutputPath(ctx.renderContext.outputLayout,
|
|
59
|
+
path: entityOutputPath(ctx.renderContext.outputLayout, pkg, entityMetaFileName(entity.name)),
|
|
59
60
|
content: await formatTs(renderEntityMetaFile(entity, ctx.renderContext.apiPrefix, namesConstArg(metaNames))),
|
|
60
61
|
}, {
|
|
61
|
-
path: entityOutputPath(ctx.renderContext.outputLayout,
|
|
62
|
+
path: entityOutputPath(ctx.renderContext.outputLayout, pkg, `${entity.name}.grid.ts`),
|
|
62
63
|
content: withClientDirective(await formatTs(renderGridHookFile(entity, ctx.renderContext)), ctx.renderContext.clientDirective),
|
|
63
64
|
}];
|
|
64
65
|
});
|
|
65
66
|
const generator = {
|
|
66
67
|
name: "tanstack-grid-hook",
|
|
68
|
+
// Marks this generator as part of the CLIENT UI tier — the runner aggregates it
|
|
69
|
+
// into ctx.config.includeUiTier so `agent/ui.md` describes a tier that this run
|
|
70
|
+
// actually emits, rather than one the metadata merely permits.
|
|
71
|
+
emitsUiTier: true,
|
|
67
72
|
filter: (e) => passesOtherGates(e) && hasDataGridLayout(e),
|
|
68
73
|
generate: async (ctx) => {
|
|
69
74
|
warnMissingDataGridLayout(ctx, passesOtherGates, "<Entity>.grid.ts");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-grid-hook.js","sourceRoot":"","sources":["../src/tanstack-grid-hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAC1J,mBAAmB,EAAE,QAAQ,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"tanstack-grid-hook.js","sourceRoot":"","sources":["../src/tanstack-grid-hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAC1J,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAC5C,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACnF,O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ourceRoot":"","sources":["../src/tanstack-grid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"tanstack-grid.d.ts","sourceRoot":"","sources":["../src/tanstack-grid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,EAGxD,MAAM,4BAA4B,CAAC;AAIpC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,EA6CpB,gBAAgB,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC"}
|
package/dist/tanstack-grid.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { perEntity, formatTs, entityOutputPath, servesReadApi, isTphSubtype, withClientDirective, } from "@metaobjectsdev/codegen-ts";
|
|
1
|
+
import { perEntity, formatTs, entityOutputPath, servesReadApi, isTphSubtype, withClientDirective, effectivePackage, } from "@metaobjectsdev/codegen-ts";
|
|
2
2
|
import { hasDataGridLayout, warnMissingDataGridLayout } from "./data-grid-gate.js";
|
|
3
3
|
import { renderColumnsFile } from "./templates/columns-file.js";
|
|
4
4
|
/**
|
|
@@ -34,12 +34,16 @@ export const tanstackGrid = function tanstackGrid(opts) {
|
|
|
34
34
|
throw new Error("tanstack-grid: renderContext is required (provided by runGen)");
|
|
35
35
|
}
|
|
36
36
|
return {
|
|
37
|
-
path: entityOutputPath(ctx.renderContext.outputLayout, entity
|
|
37
|
+
path: entityOutputPath(ctx.renderContext.outputLayout, effectivePackage(entity), `${entity.name}.columns.tsx`),
|
|
38
38
|
content: withClientDirective(await formatTs(renderColumnsFile(entity, ctx.renderContext)), ctx.renderContext.clientDirective),
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
const generator = {
|
|
42
42
|
name: "tanstack-grid",
|
|
43
|
+
// Marks this generator as part of the CLIENT UI tier — the runner aggregates it
|
|
44
|
+
// into ctx.config.includeUiTier so `agent/ui.md` describes a tier that this run
|
|
45
|
+
// actually emits, rather than one the metadata merely permits.
|
|
46
|
+
emitsUiTier: true,
|
|
43
47
|
filter: (e) => passesOtherGates(e) && hasDataGridLayout(e),
|
|
44
48
|
generate: async (ctx) => {
|
|
45
49
|
warnMissingDataGridLayout(ctx, passesOtherGates, "<Entity>.columns.tsx");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-grid.js","sourceRoot":"","sources":["../src/tanstack-grid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAChH,mBAAmB,
|
|
1
|
+
{"version":3,"file":"tanstack-grid.js","sourceRoot":"","sources":["../src/tanstack-grid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAChH,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAwBhE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,YAAY,CAAC,IAAuB;IACvE,MAAM,UAAU,GAAG,IAAI,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAChD,oFAAoF;IACpF,gCA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EAAE,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;YACzE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;IACF,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAA8C,CAAC"}
|
package/dist/tanstack-query.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface TanstackQueryOpts {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Per-entity generator that emits <Entity>.hooks.ts — a query-key factory
|
|
9
|
-
* plus 2 query hooks and 3 mutation hooks backed by
|
|
9
|
+
* plus 2 query hooks and 3 mutation hooks backed by useEntityPathFetcher().
|
|
10
10
|
*
|
|
11
11
|
* If the user supplies their own filter, it AND-composes with the built-in gates.
|
|
12
12
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-query.d.ts","sourceRoot":"","sources":["../src/tanstack-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"tanstack-query.d.ts","sourceRoot":"","sources":["../src/tanstack-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,EAGxD,MAAM,4BAA4B,CAAC;AAGpC,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EA4DrB,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC"}
|
package/dist/tanstack-query.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { perEntity, formatTs, entityOutputPath, entityMetaFileName, renderEntityMetaFile, servesReadApi, isTphSubtype, withClientDirective, namesRef, namesConstArg, } from "@metaobjectsdev/codegen-ts";
|
|
1
|
+
import { perEntity, formatTs, entityOutputPath, entityMetaFileName, renderEntityMetaFile, servesReadApi, isTphSubtype, withClientDirective, namesRef, namesConstArg, effectivePackage, } from "@metaobjectsdev/codegen-ts";
|
|
2
2
|
import { renderHooksFile } from "./templates/hooks-file.js";
|
|
3
3
|
/**
|
|
4
4
|
* Per-entity generator that emits <Entity>.hooks.ts — a query-key factory
|
|
5
|
-
* plus 2 query hooks and 3 mutation hooks backed by
|
|
5
|
+
* plus 2 query hooks and 3 mutation hooks backed by useEntityPathFetcher().
|
|
6
6
|
*
|
|
7
7
|
* If the user supplies their own filter, it AND-composes with the built-in gates.
|
|
8
8
|
*
|
|
@@ -15,6 +15,10 @@ export const tanstackQuery = function tanstackQuery(opts) {
|
|
|
15
15
|
const userFilter = opts?.filter ?? (() => true);
|
|
16
16
|
const generator = {
|
|
17
17
|
name: "tanstack-query",
|
|
18
|
+
// Marks this generator as part of the CLIENT UI tier — the runner aggregates it
|
|
19
|
+
// into ctx.config.includeUiTier so `agent/ui.md` describes a tier that this run
|
|
20
|
+
// actually emits, rather than one the metadata merely permits.
|
|
21
|
+
emitsUiTier: true,
|
|
18
22
|
// AND-composes the framework instance-artifact guard (skips abstract types —
|
|
19
23
|
// they contribute shape via inheritance only and have no instance to query)
|
|
20
24
|
// with the optional user filter. Projections still pass here and get read-only
|
|
@@ -40,12 +44,13 @@ export const tanstackQuery = function tanstackQuery(opts) {
|
|
|
40
44
|
// generator's own target — no separate check needed.
|
|
41
45
|
const rc = ctx.renderContext;
|
|
42
46
|
const metaNames = namesRef(entity, rc);
|
|
47
|
+
const pkg = effectivePackage(entity);
|
|
43
48
|
const metaFile = {
|
|
44
|
-
path: entityOutputPath(ctx.renderContext.outputLayout,
|
|
49
|
+
path: entityOutputPath(ctx.renderContext.outputLayout, pkg, entityMetaFileName(entity.name)),
|
|
45
50
|
content: await formatTs(renderEntityMetaFile(entity, ctx.renderContext.apiPrefix, namesConstArg(metaNames))),
|
|
46
51
|
};
|
|
47
52
|
return [metaFile, {
|
|
48
|
-
path: entityOutputPath(ctx.renderContext.outputLayout,
|
|
53
|
+
path: entityOutputPath(ctx.renderContext.outputLayout, pkg, `${entity.name}.hooks.ts`),
|
|
49
54
|
// Outside formatTs deliberately: the directive must stay the module's first
|
|
50
55
|
// token, and a formatter is entitled to move a leading string expression.
|
|
51
56
|
content: withClientDirective(await formatTs(renderHooksFile(entity, ctx.renderContext)), ctx.renderContext.clientDirective),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-query.js","sourceRoot":"","sources":["../src/tanstack-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAC1J,mBAAmB,EAAE,QAAQ,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"tanstack-query.js","sourceRoot":"","sources":["../src/tanstack-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,QAAQ,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAC1J,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAC5C,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAO5D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,aAAa,CAAC,IAAwB;IAC1E,MAAM,UAAU,GAAG,IAAI,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,SAAS,GAAc;QAC3B,IAAI,EAAE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,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,WAAW,CAAC;oBACtF,4EAA4E;oBAC5E,0EAA0E;oBAC1E,OAAO,EAAE,mBAAmB,CAC1B,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,EAC1D,GAAG,CAAC,aAAa,CAAC,eAAe,CAClC;iBACF,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC;IACF,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAA+C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns-file.d.ts","sourceRoot":"","sources":["../../src/templates/columns-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"columns-file.d.ts","sourceRoot":"","sources":["../../src/templates/columns-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,0BAA0B,CAAC;AAUtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAgLhE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAkFhF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { code, imp, joinCode } from "ts-poet";
|
|
2
|
-
import { LAYOUT_SUBTYPE_DATA_GRID, LAYOUT_DATA_GRID_ATTR_PAGE_SIZE,
|
|
3
|
-
import { GENERATED_HEADER, entityModuleSpecifier, isTphDiscriminatorBase, collectTphSubtypeFields, isSortableField, viewForContext, VIEW_CONTEXT_GRID, } from "@metaobjectsdev/codegen-ts";
|
|
2
|
+
import { LAYOUT_SUBTYPE_DATA_GRID, LAYOUT_DATA_GRID_ATTR_PAGE_SIZE, LAYOUT_DATA_GRID_ATTR_FILTERABLE, LAYOUT_DATA_GRID_ATTR_FILTER, LAYOUT_DATA_GRID_ATTR_COLUMNS, OBJECT_ATTR_DISCRIMINATOR, VIEW_SUBTYPE_HIDDEN, } from "@metaobjectsdev/metadata";
|
|
3
|
+
import { GENERATED_HEADER, entityModuleSpecifier, isTphDiscriminatorBase, collectTphSubtypeFields, isSortableField, viewForContext, VIEW_CONTEXT_GRID, effectivePackage, resolveGridDefaultSort, } from "@metaobjectsdev/codegen-ts";
|
|
4
4
|
function humanize(s) {
|
|
5
5
|
return s
|
|
6
6
|
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
@@ -99,8 +99,7 @@ function extractGrids(entity, tph) {
|
|
|
99
99
|
return [spec];
|
|
100
100
|
});
|
|
101
101
|
// ADR-0039: resolving — dataGrid layout attrs may be inherited via extends.
|
|
102
|
-
const
|
|
103
|
-
const sortOrder = layout.attr(LAYOUT_DATA_GRID_ATTR_DEFAULT_SORT_ORDER);
|
|
102
|
+
const defaultSort = resolveGridDefaultSort(entity, layout);
|
|
104
103
|
const filterAttr = layout.attr(LAYOUT_DATA_GRID_ATTR_FILTER);
|
|
105
104
|
const grid = {
|
|
106
105
|
name: layout.name || "default",
|
|
@@ -108,10 +107,8 @@ function extractGrids(entity, tph) {
|
|
|
108
107
|
filterable: layout.attr(LAYOUT_DATA_GRID_ATTR_FILTERABLE) === true,
|
|
109
108
|
columns,
|
|
110
109
|
};
|
|
111
|
-
if (
|
|
112
|
-
grid.
|
|
113
|
-
if (sortOrder === "asc" || sortOrder === "desc")
|
|
114
|
-
grid.defaultSortOrder = sortOrder;
|
|
110
|
+
if (defaultSort !== undefined)
|
|
111
|
+
grid.defaultSort = defaultSort;
|
|
115
112
|
if (typeof filterAttr === "object" && filterAttr !== null && !Array.isArray(filterAttr)) {
|
|
116
113
|
grid.filter = filterAttr;
|
|
117
114
|
}
|
|
@@ -156,8 +153,8 @@ export function renderColumnsFile(entity, ctx) {
|
|
|
156
153
|
const sections = grids.map((grid) => {
|
|
157
154
|
const gridConstName = `${lcEntity}${capitalize(grid.name)}Grid`;
|
|
158
155
|
const columnsConstName = `${lcEntity}${capitalize(grid.name)}Columns`;
|
|
159
|
-
const sortBlock = grid.
|
|
160
|
-
? ` defaultSort: { field: ${JSON.stringify(grid.
|
|
156
|
+
const sortBlock = grid.defaultSort
|
|
157
|
+
? ` defaultSort: { field: ${JSON.stringify(grid.defaultSort.field)}, order: ${JSON.stringify(grid.defaultSort.order)} as const },\n`
|
|
161
158
|
: "";
|
|
162
159
|
const gridConst = code `
|
|
163
160
|
export const ${gridConstName} = {
|
|
@@ -190,7 +187,7 @@ export const ${filterConstName}: ${entityName}Filter = ${JSON.stringify(grid.fil
|
|
|
190
187
|
`// Source metadata: ${entityName} (${entity.fqn()})\n`;
|
|
191
188
|
// Import the entity's own file. Same target → relative "./Entity"; cross
|
|
192
189
|
// target → importBase-qualified package path.
|
|
193
|
-
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, entity
|
|
190
|
+
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, effectivePackage(entity), entityName, ctx.extStyle);
|
|
194
191
|
// Import <Entity>Row always; import <Entity>Filter only when a filter const is emitted.
|
|
195
192
|
// TPH base: <Base>Row is a distinct export (the all-columns row); import it
|
|
196
193
|
// directly. Non-TPH: the entity type IS the row, imported under the Row alias.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns-file.js","sourceRoot":"","sources":["../../src/templates/columns-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAC;AAEzD,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,
|
|
1
|
+
{"version":3,"file":"columns-file.js","sourceRoot":"","sources":["../../src/templates/columns-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI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U,EAAc,MAAM,0BAA0B,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"grid-hook-file.d.ts","sourceRoot":"","sources":["../../src/templates/grid-hook-file.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AA2ChE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAkHjF"}
|
|
@@ -18,7 +18,7 @@ function metaModuleOf(entityModule) {
|
|
|
18
18
|
? `${entityModule.slice(0, -3)}.meta.js`
|
|
19
19
|
: `${entityModule}.meta`;
|
|
20
20
|
}
|
|
21
|
-
import { GENERATED_HEADER, entityModuleSpecifier, siblingSpecifier } from "@metaobjectsdev/codegen-ts";
|
|
21
|
+
import { GENERATED_HEADER, entityModuleSpecifier, siblingSpecifier, effectivePackage, resolveGridDefaultSort, } from "@metaobjectsdev/codegen-ts";
|
|
22
22
|
function extractGrids(entity) {
|
|
23
23
|
const out = [];
|
|
24
24
|
for (const l of entity.layouts()) {
|
|
@@ -28,8 +28,7 @@ function extractGrids(entity) {
|
|
|
28
28
|
name: l.name || "default",
|
|
29
29
|
pageSize: l.pageSize ?? 25,
|
|
30
30
|
hasFilterPreset: l.filter !== undefined,
|
|
31
|
-
|
|
32
|
-
defaultSortOrder: l.defaultSortOrder,
|
|
31
|
+
defaultSort: resolveGridDefaultSort(entity, l),
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
return out;
|
|
@@ -43,9 +42,10 @@ export function renderGridHookFile(entity, ctx) {
|
|
|
43
42
|
const grids = extractGrids(entity);
|
|
44
43
|
if (grids.length === 0)
|
|
45
44
|
return "";
|
|
45
|
+
const pkg = effectivePackage(entity);
|
|
46
46
|
// Import the entity's own file. Same target → relative "./Entity"; cross
|
|
47
47
|
// target → importBase-qualified package path.
|
|
48
|
-
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget,
|
|
48
|
+
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, pkg, entityName, ctx.extStyle);
|
|
49
49
|
// ts-poet symbols (imp()) — typed and deduped on emit.
|
|
50
50
|
const useStateSym = imp("useState@react");
|
|
51
51
|
const useMemoSym = imp("useMemo@react");
|
|
@@ -53,7 +53,7 @@ export function renderGridHookFile(entity, ctx) {
|
|
|
53
53
|
const SortingStateSym = imp("t:SortingState@@tanstack/react-table");
|
|
54
54
|
const PaginationStateSym = imp("t:PaginationState@@tanstack/react-table");
|
|
55
55
|
const ColumnFiltersStateSym = imp("t:ColumnFiltersState@@tanstack/react-table");
|
|
56
|
-
const
|
|
56
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
57
57
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
58
58
|
const entityImports = code `
|
|
59
59
|
import { ${entityName} } from ${JSON.stringify(metaModuleOf(entityModule))};
|
|
@@ -65,7 +65,7 @@ import type { ${entityName} as ${entityName}Row } from ${JSON.stringify(entityMo
|
|
|
65
65
|
.map((g) => `${lcEntity}${capitalize(g.name)}Filter`);
|
|
66
66
|
// Columns file is a same-target sibling of the grid-hook (both emitted to
|
|
67
67
|
// selfTarget) — always relative, package-layout aware.
|
|
68
|
-
const columnsModule = siblingSpecifier(ctx.selfTarget,
|
|
68
|
+
const columnsModule = siblingSpecifier(ctx.selfTarget, pkg, `${entityName}.columns`, ctx.extStyle);
|
|
69
69
|
const filterPresetImportCode = filterPresetImports.length > 0
|
|
70
70
|
? code `import { ${filterPresetImports.join(", ")} } from ${JSON.stringify(columnsModule)};\n`
|
|
71
71
|
: code ``;
|
|
@@ -73,8 +73,8 @@ import type { ${entityName} as ${entityName}Row } from ${JSON.stringify(entityMo
|
|
|
73
73
|
const cap = capitalize(grid.name);
|
|
74
74
|
const hookName = `use${entityName}${cap}Grid`;
|
|
75
75
|
const presetConst = grid.hasFilterPreset ? `${lcEntity}${cap}Filter` : null;
|
|
76
|
-
const initialSorting = grid.
|
|
77
|
-
? `[{ id: ${JSON.stringify(grid.
|
|
76
|
+
const initialSorting = grid.defaultSort
|
|
77
|
+
? `[{ id: ${JSON.stringify(grid.defaultSort.field)}, desc: ${JSON.stringify(grid.defaultSort.order === "desc")} }]`
|
|
78
78
|
: `[]`;
|
|
79
79
|
const initialPagination = `{ pageIndex: 0, pageSize: ${grid.pageSize} }`;
|
|
80
80
|
return code `
|
|
@@ -84,7 +84,7 @@ export function ${hookName}() {
|
|
|
84
84
|
const [columnFilters, setColumnFilters] = ${useStateSym}<${ColumnFiltersStateSym}>([]);
|
|
85
85
|
const [search, setSearch] = ${useStateSym}<string>("");
|
|
86
86
|
|
|
87
|
-
const fetcher = ${
|
|
87
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
88
88
|
|
|
89
89
|
const qs = ${useMemoSym}(() => {
|
|
90
90
|
const filterObj: Record<string, unknown> = ${presetConst ? `{ ...${presetConst} }` : `{}`};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-hook-file.js","sourceRoot":"","sources":["../../src/templates/grid-hook-file.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yDAAyD;AACzD,wEAAwE;AACxE,2EAA2E;AAC3E,EAAE;AACF,yEAAyE;AACzE,gBAAgB;AAChB,6CAA6C;AAC7C,6FAA6F;AAE7F,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAGpE;;;kFAGkF;AAClF,SAAS,YAAY,CAAC,YAAoB;IACxC,OAAO,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjC,CAAC,CAAC,GAAG,YAAY,CAAC,KAA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en-ts";
|
|
|
13
13
|
* - useUpdate<Entity>
|
|
14
14
|
* - useDelete<Entity>
|
|
15
15
|
*
|
|
16
|
-
* All hooks call
|
|
16
|
+
* All hooks call useEntityPathFetcher() (from @metaobjectsdev/tanstack) for
|
|
17
17
|
* the underlying HTTP. Mutations aggressively invalidate <entity>Keys.all().
|
|
18
18
|
*/
|
|
19
19
|
export declare function renderHooksFile(entity: MetaObject, ctx: RenderContext): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-file.d.ts","sourceRoot":"","sources":["../../src/templates/hooks-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks-file.d.ts","sourceRoot":"","sources":["../../src/templates/hooks-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,4BAA4B,CAAC;AAuB/E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAmB9E"}
|
|
@@ -8,7 +8,7 @@ function metaModuleOf(entityModule) {
|
|
|
8
8
|
? `${entityModule.slice(0, -3)}.meta.js`
|
|
9
9
|
: `${entityModule}.meta`;
|
|
10
10
|
}
|
|
11
|
-
import { GENERATED_HEADER, isProjection, pluralize, entityModuleSpecifier, isTphDiscriminatorBase, tphPlan, getPkInfo, } from "@metaobjectsdev/codegen-ts";
|
|
11
|
+
import { GENERATED_HEADER, isProjection, pluralize, entityModuleSpecifier, isTphDiscriminatorBase, tphPlan, getPkInfo, effectivePackage, } from "@metaobjectsdev/codegen-ts";
|
|
12
12
|
/**
|
|
13
13
|
* Render <Entity>.hooks.ts — query-key factory + 2 query hooks + (for non-projections) 3 mutation hooks.
|
|
14
14
|
*
|
|
@@ -22,13 +22,13 @@ import { GENERATED_HEADER, isProjection, pluralize, entityModuleSpecifier, isTph
|
|
|
22
22
|
* - useUpdate<Entity>
|
|
23
23
|
* - useDelete<Entity>
|
|
24
24
|
*
|
|
25
|
-
* All hooks call
|
|
25
|
+
* All hooks call useEntityPathFetcher() (from @metaobjectsdev/tanstack) for
|
|
26
26
|
* the underlying HTTP. Mutations aggressively invalidate <entity>Keys.all().
|
|
27
27
|
*/
|
|
28
28
|
export function renderHooksFile(entity, ctx) {
|
|
29
29
|
// Import the entity's own file. Same target → relative "./Entity"; cross
|
|
30
30
|
// target → importBase-qualified package path.
|
|
31
|
-
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, entity
|
|
31
|
+
const entityModule = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, effectivePackage(entity), entity.name, ctx.extStyle);
|
|
32
32
|
// FR-017 Tier 3: a TPH discriminator base gets a polymorphic + per-subtype
|
|
33
33
|
// hooks file (the subtype entities are filtered out of this generator).
|
|
34
34
|
if (isTphDiscriminatorBase(entity, ctx.loadedRoot)) {
|
|
@@ -73,7 +73,7 @@ function renderM2mHooks(entity, ctx, keysVar, entries) {
|
|
|
73
73
|
const useQuerySym = imp("useQuery@@tanstack/react-query");
|
|
74
74
|
const useQueryOptionsSym = imp("t:UseQueryOptions@@tanstack/react-query");
|
|
75
75
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
76
|
-
const
|
|
76
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
77
77
|
const source = entity.name;
|
|
78
78
|
// Distinct target row types, imported (aliased) from each target's entity
|
|
79
79
|
// module. ts-poet's imp() tracks + hoists these into the import block. The
|
|
@@ -98,7 +98,7 @@ export function ${hookName}(
|
|
|
98
98
|
sourceId: ${pkType} | undefined,
|
|
99
99
|
opts?: Omit<${useQueryOptionsSym}<${targetSym}[]>, "queryKey" | "queryFn">,
|
|
100
100
|
): ${useQueryResultSym}<${targetSym}[]> {
|
|
101
|
-
const fetcher = ${
|
|
101
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
102
102
|
return ${useQuerySym}<${targetSym}[]>({
|
|
103
103
|
queryKey: ${keysVar}.relation(${relLit}, sourceId),
|
|
104
104
|
queryFn: () => fetcher<${targetSym}[]>(\`\${${source}.$path}/\${sourceId}/${e.name}\`),
|
|
@@ -129,7 +129,7 @@ function renderReadOnlyHooksFile(entity, entityModule, ctx) {
|
|
|
129
129
|
const useQuerySym = imp("useQuery@@tanstack/react-query");
|
|
130
130
|
const useQueryOptionsSym = imp("t:UseQueryOptions@@tanstack/react-query");
|
|
131
131
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
132
|
-
const
|
|
132
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
133
133
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
134
134
|
const entityImports = code `
|
|
135
135
|
import { ${entityName} } from ${JSON.stringify(metaModuleOf(entityModule))};
|
|
@@ -152,7 +152,7 @@ export function use${entityName}(
|
|
|
152
152
|
id: ${pkType},
|
|
153
153
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row>, "queryKey" | "queryFn">,
|
|
154
154
|
): ${useQueryResultSym}<${entityName}Row> {
|
|
155
|
-
const fetcher = ${
|
|
155
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
156
156
|
return ${useQuerySym}<${entityName}Row>({
|
|
157
157
|
queryKey: ${keysVar}.detail(id),
|
|
158
158
|
queryFn: () => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`),
|
|
@@ -164,7 +164,7 @@ export function use${entityNamePlural}(
|
|
|
164
164
|
filter?: ${entityName}Filter,
|
|
165
165
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row[]>, "queryKey" | "queryFn">,
|
|
166
166
|
): ${useQueryResultSym}<${entityName}Row[]> {
|
|
167
|
-
const fetcher = ${
|
|
167
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
168
168
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
169
169
|
return ${useQuerySym}<${entityName}Row[]>({
|
|
170
170
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -199,7 +199,7 @@ function renderFullHooksFile(entity, entityModule, ctx) {
|
|
|
199
199
|
const useMutationOptionsSym = imp("t:UseMutationOptions@@tanstack/react-query");
|
|
200
200
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
201
201
|
const useMutationResultSym = imp("t:UseMutationResult@@tanstack/react-query");
|
|
202
|
-
const
|
|
202
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
203
203
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
204
204
|
const entityImports = code `
|
|
205
205
|
import { ${entityName} } from ${JSON.stringify(metaModuleOf(entityModule))};
|
|
@@ -224,7 +224,7 @@ export function use${entityName}(
|
|
|
224
224
|
id: ${pkType},
|
|
225
225
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row>, "queryKey" | "queryFn">,
|
|
226
226
|
): ${useQueryResultSym}<${entityName}Row> {
|
|
227
|
-
const fetcher = ${
|
|
227
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
228
228
|
return ${useQuerySym}<${entityName}Row>({
|
|
229
229
|
queryKey: ${keysVar}.detail(id),
|
|
230
230
|
queryFn: () => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`),
|
|
@@ -236,7 +236,7 @@ export function use${entityNamePlural}(
|
|
|
236
236
|
filter?: ${entityName}Filter,
|
|
237
237
|
opts?: Omit<${useQueryOptionsSym}<${entityName}Row[]>, "queryKey" | "queryFn">,
|
|
238
238
|
): ${useQueryResultSym}<${entityName}Row[]> {
|
|
239
|
-
const fetcher = ${
|
|
239
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
240
240
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
241
241
|
return ${useQuerySym}<${entityName}Row[]>({
|
|
242
242
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -250,7 +250,7 @@ export function use${entityNamePlural}(
|
|
|
250
250
|
export function useCreate${entityName}(
|
|
251
251
|
opts?: Omit<${useMutationOptionsSym}<${entityName}Row, Error, ${entityName}Insert>, "mutationFn">,
|
|
252
252
|
): ${useMutationResultSym}<${entityName}Row, Error, ${entityName}Insert> {
|
|
253
|
-
const fetcher = ${
|
|
253
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
254
254
|
const qc = ${useQueryClientSym}();
|
|
255
255
|
return ${useMutationSym}<${entityName}Row, Error, ${entityName}Insert>({
|
|
256
256
|
mutationFn: (input) => fetcher<${entityName}Row>(\`\${${entityName}.$path}\`, {
|
|
@@ -269,7 +269,7 @@ export function useCreate${entityName}(
|
|
|
269
269
|
export function useUpdate${entityName}(
|
|
270
270
|
opts?: Omit<${useMutationOptionsSym}<${entityName}Row, Error, { id: ${pkType}; input: ${entityName}Update }>, "mutationFn">,
|
|
271
271
|
): ${useMutationResultSym}<${entityName}Row, Error, { id: ${pkType}; input: ${entityName}Update }> {
|
|
272
|
-
const fetcher = ${
|
|
272
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
273
273
|
const qc = ${useQueryClientSym}();
|
|
274
274
|
return ${useMutationSym}({
|
|
275
275
|
mutationFn: ({ id, input }) => fetcher<${entityName}Row>(\`\${${entityName}.$path}/\${id}\`, {
|
|
@@ -288,7 +288,7 @@ export function useUpdate${entityName}(
|
|
|
288
288
|
export function useDelete${entityName}(
|
|
289
289
|
opts?: Omit<${useMutationOptionsSym}<void, Error, ${pkType}>, "mutationFn">,
|
|
290
290
|
): ${useMutationResultSym}<void, Error, ${pkType}> {
|
|
291
|
-
const fetcher = ${
|
|
291
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
292
292
|
const qc = ${useQueryClientSym}();
|
|
293
293
|
return ${useMutationSym}({
|
|
294
294
|
mutationFn: (id) => fetcher<void>(\`\${${entityName}.$path}/\${id}\`, { method: "DELETE" }),
|
|
@@ -325,7 +325,7 @@ function renderTphHooksFile(base, ctx, baseModule) {
|
|
|
325
325
|
const useMutationOptionsSym = imp("t:UseMutationOptions@@tanstack/react-query");
|
|
326
326
|
const useQueryResultSym = imp("t:UseQueryResult@@tanstack/react-query");
|
|
327
327
|
const useMutationResultSym = imp("t:UseMutationResult@@tanstack/react-query");
|
|
328
|
-
const
|
|
328
|
+
const useEntityPathFetcherSym = imp("useEntityPathFetcher@@metaobjectsdev/tanstack");
|
|
329
329
|
const buildFilterQsSym = imp("buildFilterQs@@metaobjectsdev/runtime-web");
|
|
330
330
|
const subtypes = plan.subtypes;
|
|
331
331
|
// `${baseName}` imports BOTH the constants value (for $path) and the
|
|
@@ -335,7 +335,7 @@ function renderTphHooksFile(base, ctx, baseModule) {
|
|
|
335
335
|
// allowlist actually permits.
|
|
336
336
|
const subImportLines = subtypes
|
|
337
337
|
.map((s) => {
|
|
338
|
-
const m = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, s.entity
|
|
338
|
+
const m = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, effectivePackage(s.entity), s.entity.name, ctx.extStyle);
|
|
339
339
|
return `import { type ${s.entity.name}, type ${s.entity.name}Filter } from ${JSON.stringify(m)};`;
|
|
340
340
|
})
|
|
341
341
|
.join("\n");
|
|
@@ -364,7 +364,7 @@ export function use${baseName}(
|
|
|
364
364
|
id: ${pkType},
|
|
365
365
|
opts?: Omit<${useQueryOptionsSym}<${baseName}>, "queryKey" | "queryFn">,
|
|
366
366
|
): ${useQueryResultSym}<${baseName}> {
|
|
367
|
-
const fetcher = ${
|
|
367
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
368
368
|
return ${useQuerySym}<${baseName}>({
|
|
369
369
|
queryKey: ${keysVar}.detail(id),
|
|
370
370
|
queryFn: () => fetcher<${baseName}>(\`\${${baseName}.$path}/\${id}\`),
|
|
@@ -376,7 +376,7 @@ export function use${pluralize(baseName)}(
|
|
|
376
376
|
filter?: ${baseName}Filter,
|
|
377
377
|
opts?: Omit<${useQueryOptionsSym}<${baseName}[]>, "queryKey" | "queryFn">,
|
|
378
378
|
): ${useQueryResultSym}<${baseName}[]> {
|
|
379
|
-
const fetcher = ${
|
|
379
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
380
380
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
381
381
|
return ${useQuerySym}<${baseName}[]>({
|
|
382
382
|
queryKey: ${keysVar}.list(filter),
|
|
@@ -397,7 +397,7 @@ export function use${pluralize(subName)}(
|
|
|
397
397
|
filter?: ${subName}Filter,
|
|
398
398
|
opts?: Omit<${useQueryOptionsSym}<${subName}[]>, "queryKey" | "queryFn">,
|
|
399
399
|
): ${useQueryResultSym}<${subName}[]> {
|
|
400
|
-
const fetcher = ${
|
|
400
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
401
401
|
const qs = filter ? "?" + ${buildFilterQsSym}(filter as Record<string, unknown>) : "";
|
|
402
402
|
return ${useQuerySym}<${subName}[]>({
|
|
403
403
|
queryKey: ${keysVar}.subtypeList(${valueLit}, filter),
|
|
@@ -410,7 +410,7 @@ export function use${subName}(
|
|
|
410
410
|
id: ${pkType},
|
|
411
411
|
opts?: Omit<${useQueryOptionsSym}<${subName}>, "queryKey" | "queryFn">,
|
|
412
412
|
): ${useQueryResultSym}<${subName}> {
|
|
413
|
-
const fetcher = ${
|
|
413
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
414
414
|
return ${useQuerySym}<${subName}>({
|
|
415
415
|
queryKey: ${keysVar}.subtypeDetail(${valueLit}, id),
|
|
416
416
|
queryFn: () => fetcher<${subName}>(\`\${${baseName}.$path}/${seg}/\${id}\`),
|
|
@@ -421,7 +421,7 @@ export function use${subName}(
|
|
|
421
421
|
export function useCreate${subName}(
|
|
422
422
|
opts?: Omit<${useMutationOptionsSym}<${subName}, Error, ${createInput}>, "mutationFn">,
|
|
423
423
|
): ${useMutationResultSym}<${subName}, Error, ${createInput}> {
|
|
424
|
-
const fetcher = ${
|
|
424
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
425
425
|
const qc = ${useQueryClientSym}();
|
|
426
426
|
return ${useMutationSym}<${subName}, Error, ${createInput}>({
|
|
427
427
|
mutationFn: (input) => fetcher<${subName}>(${subPath}, {
|
|
@@ -440,7 +440,7 @@ export function useCreate${subName}(
|
|
|
440
440
|
export function useUpdate${subName}(
|
|
441
441
|
opts?: Omit<${useMutationOptionsSym}<${subName}, Error, { id: ${pkType}; input: ${updateInput} }>, "mutationFn">,
|
|
442
442
|
): ${useMutationResultSym}<${subName}, Error, { id: ${pkType}; input: ${updateInput} }> {
|
|
443
|
-
const fetcher = ${
|
|
443
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
444
444
|
const qc = ${useQueryClientSym}();
|
|
445
445
|
return ${useMutationSym}({
|
|
446
446
|
mutationFn: ({ id, input }) => fetcher<${subName}>(\`\${${baseName}.$path}/${seg}/\${id}\`, {
|
|
@@ -459,7 +459,7 @@ export function useUpdate${subName}(
|
|
|
459
459
|
export function useDelete${subName}(
|
|
460
460
|
opts?: Omit<${useMutationOptionsSym}<void, Error, ${pkType}>, "mutationFn">,
|
|
461
461
|
): ${useMutationResultSym}<void, Error, ${pkType}> {
|
|
462
|
-
const fetcher = ${
|
|
462
|
+
const fetcher = ${useEntityPathFetcherSym}();
|
|
463
463
|
const qc = ${useQueryClientSym}();
|
|
464
464
|
return ${useMutationSym}({
|
|
465
465
|
mutationFn: (id) => fetcher<void>(\`\${${baseName}.$path}/${seg}/\${id}\`, { method: "DELETE" }),
|