@comet/admin-generator 9.0.0-canary-20251013121422 → 9.0.0-canary-20251124092450
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/lib/commands/generate/config/transformConfig.d.ts +6 -0
- package/lib/commands/generate/config/transformConfig.js +36 -8
- package/lib/commands/generate/generate-command.d.ts +49 -15
- package/lib/commands/generate/generate-command.js +5 -0
- package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +46 -22
- package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +2 -0
- package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +22 -0
- package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.d.ts +6 -0
- package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.js +22 -0
- package/lib/commands/generate/generateForm/formField/options.d.ts +1 -5
- package/lib/commands/generate/generateForm/formField/options.js +2 -11
- package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -1
- package/lib/commands/generate/generateForm/generateFields.d.ts +9 -4
- package/lib/commands/generate/generateForm/generateFields.js +0 -3
- package/lib/commands/generate/generateForm/generateForm.js +99 -132
- package/lib/commands/generate/generateForm/generateFormField.js +34 -44
- package/lib/commands/generate/generateForm/generateFormLayout.js +23 -44
- package/lib/commands/generate/generateForm/generateFormValues.d.ts +39 -0
- package/lib/commands/generate/generateForm/generateFormValues.js +217 -0
- package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +1 -1
- package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +3 -36
- package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +4 -5
- package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +18 -17
- package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +5 -0
- package/lib/commands/generate/generateGrid/detectMuiXVersion.js +32 -0
- package/lib/commands/generate/generateGrid/generateGrid.js +71 -51
- package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +3 -3
- package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +12 -16
- package/lib/commands/generate/generateGrid/usableFields.d.ts +6 -1
- package/lib/commands/generate/utils/convertConfigImport.d.ts +1 -0
- package/lib/commands/generate/utils/convertConfigImport.js +1 -1
- package/lib/commands/generate/utils/generateGqlOperation.d.ts +12 -0
- package/lib/commands/generate/utils/generateGqlOperation.js +87 -0
- package/lib/commands/generate/utils/generateImportsCode.d.ts +1 -0
- package/lib/commands/generate/utils/generateImportsCode.js +6 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/package.json +10 -9
|
@@ -18,8 +18,10 @@ const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
|
18
18
|
const findMutationType_1 = require("../utils/findMutationType");
|
|
19
19
|
const findQueryType_1 = require("../utils/findQueryType");
|
|
20
20
|
const findRootBlocks_1 = require("../utils/findRootBlocks");
|
|
21
|
+
const generateGqlOperation_1 = require("../utils/generateGqlOperation");
|
|
21
22
|
const generateImportsCode_1 = require("../utils/generateImportsCode");
|
|
22
23
|
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
24
|
+
const detectMuiXVersion_1 = require("./detectMuiXVersion");
|
|
23
25
|
const findInputObjectType_1 = require("./findInputObjectType");
|
|
24
26
|
const generateGqlFieldList_1 = require("./generateGqlFieldList");
|
|
25
27
|
const generateGridToolbar_1 = require("./generateGridToolbar");
|
|
@@ -120,6 +122,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
120
122
|
if (!gqlType) {
|
|
121
123
|
throw new Error("gqlType is required in grid config");
|
|
122
124
|
}
|
|
125
|
+
const muiXGridVariant = (0, detectMuiXVersion_1.detectMuiXGridVariant)();
|
|
123
126
|
const gqlTypePlural = (0, pluralize_1.plural)(gqlType);
|
|
124
127
|
//const title = config.title ?? camelCaseToHumanReadable(gqlType);
|
|
125
128
|
const instanceGqlType = gqlType[0].toLowerCase() + gqlType.substring(1);
|
|
@@ -160,7 +163,6 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
160
163
|
{ name: "useDataGridRemote", importPath: "@comet/admin" },
|
|
161
164
|
{ name: "usePersistentColumnState", importPath: "@comet/admin" },
|
|
162
165
|
{ name: "BlockPreviewContent", importPath: "@comet/cms-admin" },
|
|
163
|
-
{ name: "useContentScope", importPath: "@comet/cms-admin" },
|
|
164
166
|
{ name: "Alert", importPath: "@mui/material" },
|
|
165
167
|
{ name: "Box", importPath: "@mui/material" },
|
|
166
168
|
{ name: "IconButton", importPath: "@mui/material" },
|
|
@@ -171,14 +173,16 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
171
173
|
{ name: "ListItemIcon", importPath: "@mui/material" },
|
|
172
174
|
{ name: "ListItemText", importPath: "@mui/material" },
|
|
173
175
|
{ name: "CircularProgress", importPath: "@mui/material" },
|
|
174
|
-
{ name:
|
|
175
|
-
{ name:
|
|
176
|
-
{ name: "
|
|
177
|
-
{ name: "
|
|
178
|
-
{ name: "
|
|
179
|
-
{ name: "
|
|
180
|
-
{ name: "
|
|
181
|
-
{ name: "
|
|
176
|
+
{ name: muiXGridVariant.gridComponent, importPath: muiXGridVariant.package },
|
|
177
|
+
{ name: `${muiXGridVariant.gridComponent}Props`, importPath: muiXGridVariant.package },
|
|
178
|
+
{ name: "GridLogicOperator", importPath: muiXGridVariant.package },
|
|
179
|
+
{ name: "GridRenderCellParams", importPath: muiXGridVariant.package },
|
|
180
|
+
{ name: "GridSlotsComponent", importPath: muiXGridVariant.package },
|
|
181
|
+
{ name: "GridToolbarProps", importPath: muiXGridVariant.package },
|
|
182
|
+
{ name: "GridColumnHeaderTitle", importPath: muiXGridVariant.package },
|
|
183
|
+
{ name: "GridToolbarQuickFilter", importPath: muiXGridVariant.package },
|
|
184
|
+
{ name: "GridRowOrderChangeParams", importPath: muiXGridVariant.package },
|
|
185
|
+
{ name: "useMemo", importPath: "react" },
|
|
182
186
|
];
|
|
183
187
|
const iconsToImport = ["Add", "Edit", "Info", "Excel"];
|
|
184
188
|
const props = [];
|
|
@@ -229,9 +233,24 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
229
233
|
const showCrudContextMenuInActionsColumn = allowDeleting;
|
|
230
234
|
const showEditInActionsColumn = allowEditing && !forwardRowAction;
|
|
231
235
|
const defaultActionsColumnWidth = getDefaultActionsColumnWidth(showCrudContextMenuInActionsColumn, showEditInActionsColumn);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
236
|
+
let useScopeFromContext = false;
|
|
237
|
+
const gqlArgs = [];
|
|
238
|
+
{
|
|
239
|
+
const forwardedArgs = (0, getForwardedGqlArgs_1.getForwardedGqlArgs)([gridQueryType]);
|
|
240
|
+
for (const forwardedArg of forwardedArgs) {
|
|
241
|
+
imports.push(...forwardedArg.imports);
|
|
242
|
+
if (forwardedArg.gqlArg.name === "scope" && !config.scopeAsProp) {
|
|
243
|
+
useScopeFromContext = true;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
props.push(forwardedArg.prop);
|
|
247
|
+
gqlArgs.push(forwardedArg.gqlArg);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (useScopeFromContext) {
|
|
252
|
+
imports.push({ name: "useContentScope", importPath: "@comet/cms-admin" });
|
|
253
|
+
}
|
|
235
254
|
const renderToolbar = (_f = config.toolbar) !== null && _f !== void 0 ? _f : true;
|
|
236
255
|
const filterArg = gridQueryType.args.find((arg) => arg.name === "filter");
|
|
237
256
|
const hasFilter = !!filterArg && renderToolbar && !allowRowReordering;
|
|
@@ -255,16 +274,20 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
255
274
|
const hasSort = !!sortArg;
|
|
256
275
|
let sortFields = [];
|
|
257
276
|
if (sortArg) {
|
|
258
|
-
|
|
277
|
+
let sortArgType = sortArg.type;
|
|
278
|
+
if (sortArgType.kind === "NON_NULL") {
|
|
279
|
+
sortArgType = sortArgType.ofType;
|
|
280
|
+
}
|
|
281
|
+
if (sortArgType.kind !== "LIST") {
|
|
259
282
|
throw new Error("Sort argument must be LIST");
|
|
260
283
|
}
|
|
261
|
-
if (
|
|
284
|
+
if (sortArgType.ofType.kind !== "NON_NULL") {
|
|
262
285
|
throw new Error("Sort argument must be LIST->NON_NULL");
|
|
263
286
|
}
|
|
264
|
-
if (
|
|
287
|
+
if (sortArgType.ofType.ofType.kind !== "INPUT_OBJECT") {
|
|
265
288
|
throw new Error("Sort argument must be LIST->NON_NULL->INPUT_OBJECT");
|
|
266
289
|
}
|
|
267
|
-
const sortTypeName =
|
|
290
|
+
const sortTypeName = sortArgType.ofType.ofType.name;
|
|
268
291
|
const sortType = gqlIntrospection.__schema.types.find((type) => type.kind === "INPUT_OBJECT" && type.name === sortTypeName);
|
|
269
292
|
if (!sortType)
|
|
270
293
|
throw new Error("Can't find sort type");
|
|
@@ -285,7 +308,6 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
285
308
|
}
|
|
286
309
|
}
|
|
287
310
|
const hasSearch = gridQueryType.args.some((arg) => arg.name === "search") && !allowRowReordering;
|
|
288
|
-
const hasScope = gridQueryType.args.some((arg) => arg.name === "scope");
|
|
289
311
|
const schemaEntity = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
|
|
290
312
|
if (!schemaEntity)
|
|
291
313
|
throw new Error("didn't find entity in schema types");
|
|
@@ -489,7 +511,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
489
511
|
if (forwardRowAction) {
|
|
490
512
|
props.push({
|
|
491
513
|
name: "rowAction",
|
|
492
|
-
type: `(params: GridRenderCellParams<
|
|
514
|
+
type: `(params: GridRenderCellParams<GQL${fragmentName}Fragment>) => ReactNode`,
|
|
493
515
|
optional: true,
|
|
494
516
|
});
|
|
495
517
|
props.push({
|
|
@@ -500,15 +522,14 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
500
522
|
});
|
|
501
523
|
}
|
|
502
524
|
if (config.selectionProps) {
|
|
503
|
-
imports.push({ name: "DataGridProProps", importPath: "@mui/x-data-grid-pro" });
|
|
504
525
|
props.push({
|
|
505
526
|
name: "rowSelectionModel",
|
|
506
|
-
type:
|
|
527
|
+
type: `${muiXGridVariant.gridComponent}Props["rowSelectionModel"]`,
|
|
507
528
|
optional: true,
|
|
508
529
|
});
|
|
509
530
|
props.push({
|
|
510
531
|
name: "onRowSelectionModelChange",
|
|
511
|
-
type:
|
|
532
|
+
type: `${muiXGridVariant.gridComponent}Props["onRowSelectionModelChange"]`,
|
|
512
533
|
optional: true,
|
|
513
534
|
});
|
|
514
535
|
}
|
|
@@ -555,31 +576,30 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
555
576
|
}
|
|
556
577
|
\`;
|
|
557
578
|
|
|
558
|
-
const ${instanceGqlTypePlural}Query = gql
|
|
559
|
-
query
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
\`;
|
|
579
|
+
const ${instanceGqlTypePlural}Query = gql\`${(0, generateGqlOperation_1.generateGqlOperation)({
|
|
580
|
+
type: "query",
|
|
581
|
+
operationName: `${gqlTypePlural}Grid`,
|
|
582
|
+
rootOperation: gridQuery,
|
|
583
|
+
fields: [`nodes...${fragmentName}`, "totalCount"],
|
|
584
|
+
fragmentVariables: [`\${${instanceGqlTypePlural}Fragment}`],
|
|
585
|
+
variables: [
|
|
586
|
+
...gqlArgs
|
|
587
|
+
.filter((gqlArg) => gqlArg.queryOrMutationName === gridQueryType.name)
|
|
588
|
+
.map((gqlArg) => ({ name: gqlArg.name, type: `${gqlArg.type}!` })),
|
|
589
|
+
{
|
|
590
|
+
name: "offset",
|
|
591
|
+
type: "Int!",
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
name: "limit",
|
|
595
|
+
type: "Int!",
|
|
596
|
+
},
|
|
597
|
+
...(hasSort ? [{ name: "sort", type: `[${gqlType}Sort!]` }] : []),
|
|
598
|
+
...(hasSearch ? [{ name: "search", type: "String" }] : []),
|
|
599
|
+
...(filterArg && (hasFilter || hasFilterProp) ? [{ name: "filter", type: `${gqlType}Filter` }] : []),
|
|
600
|
+
...(useScopeFromContext ? [{ name: "scope", type: `${gqlType}ContentScopeInput!` }] : []),
|
|
601
|
+
],
|
|
602
|
+
})}\`;
|
|
583
603
|
|
|
584
604
|
${allowRowReordering
|
|
585
605
|
? `const update${gqlType}PositionMutation = gql\`
|
|
@@ -627,12 +647,12 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
627
647
|
: config.selectionProps === "singleSelect"
|
|
628
648
|
? `, rowSelectionModel, onRowSelectionModelChange, checkboxSelection: false, keepNonExistentRowsSelected: false, disableRowSelectionOnClick: false`
|
|
629
649
|
: ``} };
|
|
630
|
-
${
|
|
650
|
+
${useScopeFromContext ? `const { scope } = useContentScope();` : ""}
|
|
631
651
|
${gridNeedsTheme ? `const theme = useTheme();` : ""}
|
|
632
652
|
|
|
633
653
|
${generateHandleRowOrderChange(allowRowReordering, gqlType, instanceGqlTypePlural)}
|
|
634
654
|
|
|
635
|
-
const columns: GridColDef<GQL${fragmentName}Fragment>[] = [
|
|
655
|
+
const columns: GridColDef<GQL${fragmentName}Fragment>[] = useMemo(()=>[
|
|
636
656
|
${gridColumnFields
|
|
637
657
|
.map((column) => {
|
|
638
658
|
const defaultMinWidth = 150;
|
|
@@ -727,7 +747,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
727
747
|
);
|
|
728
748
|
}` }))
|
|
729
749
|
: ""}
|
|
730
|
-
];
|
|
750
|
+
],[intl${gridNeedsTheme ? ", theme" : ""}${showCrudContextMenuInActionsColumn ? ", client" : ""}${forwardRowAction ? ", rowAction, actionsColumnWidth" : ""}]);
|
|
731
751
|
|
|
732
752
|
${hasFilter || hasSearch
|
|
733
753
|
? `const { ${hasFilter ? `filter: gqlFilter, ` : ""}${hasSearch ? `search: gqlSearch, ` : ""} } = muiGridFilterToGql(columns, dataGridProps.filterModel);`
|
|
@@ -737,7 +757,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
737
757
|
variables: {
|
|
738
758
|
${[
|
|
739
759
|
...gqlArgs.filter((gqlArg) => gqlArg.queryOrMutationName === gridQueryType.name).map((arg) => arg.name),
|
|
740
|
-
...(
|
|
760
|
+
...(useScopeFromContext ? ["scope"] : []),
|
|
741
761
|
...(filterArg
|
|
742
762
|
? hasFilter && hasFilterProp
|
|
743
763
|
? ["filter: filter ? { and: [gqlFilter, filter] } : gqlFilter"]
|
|
@@ -766,7 +786,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
766
786
|
${generateGridExportApi(config.excelExport, gqlTypePlural, instanceGqlTypePlural, gridQuery, gqlArgs)}
|
|
767
787
|
|
|
768
788
|
return (
|
|
769
|
-
|
|
789
|
+
<${muiXGridVariant.gridComponent}
|
|
770
790
|
{...dataGridProps}
|
|
771
791
|
rows={rows}
|
|
772
792
|
rowCount={rowCount}
|
|
@@ -2,34 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getForwardedGqlArgs = getForwardedGqlArgs;
|
|
4
4
|
function getForwardedGqlArgs(gqlFields) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const props = [];
|
|
8
|
-
const gqlArgs = [];
|
|
5
|
+
const ret = [];
|
|
6
|
+
const supportedGqlArgs = ["offset", "limit", "sort", "search", "filter", "input"]; // this arguments need to be handled differently or are already handled somewhere else
|
|
9
7
|
getArgs(gqlFields, supportedGqlArgs).forEach((arg) => {
|
|
8
|
+
let prop;
|
|
9
|
+
const imports = [];
|
|
10
10
|
if (arg.type === "ID" || arg.type === "String" || arg.type === "DateTime") {
|
|
11
|
-
|
|
11
|
+
prop = { name: arg.name, optional: false, type: "string" };
|
|
12
12
|
}
|
|
13
13
|
else if (arg.type === "Boolean") {
|
|
14
|
-
|
|
14
|
+
prop = { name: arg.name, optional: false, type: "boolean" };
|
|
15
15
|
}
|
|
16
16
|
else if (arg.type === "Int" || arg.type === "Float") {
|
|
17
|
-
|
|
17
|
+
prop = { name: arg.name, optional: false, type: "number" };
|
|
18
18
|
}
|
|
19
19
|
else if (arg.type === "JSONObject") {
|
|
20
|
-
|
|
20
|
+
prop = { name: arg.name, optional: false, type: "unknown" };
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
-
|
|
24
|
-
imports.push({ name: arg.type
|
|
23
|
+
prop = { name: arg.name, optional: false, type: `GQL${arg.type}` }; // generated types contain GQL prefix
|
|
24
|
+
imports.push({ name: `GQL${arg.type}`, importPath: "@src/graphql.generated" });
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
ret.push({ gqlArg: { name: arg.name, type: arg.type, queryOrMutationName: arg.gqlField.name }, prop, imports });
|
|
27
27
|
});
|
|
28
|
-
return
|
|
29
|
-
imports,
|
|
30
|
-
props,
|
|
31
|
-
gqlArgs,
|
|
32
|
-
};
|
|
28
|
+
return ret;
|
|
33
29
|
}
|
|
34
30
|
function getArgs(gqlFields, skipGqlArgs) {
|
|
35
31
|
return gqlFields.reduce((acc, gqlField) => {
|
|
@@ -2,8 +2,13 @@ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
2
2
|
type GqlLeaves<T, FollowArrays extends boolean = false, Depth extends number = 5> = [Depth] extends [never] ? never : T extends any ? T extends Array<infer ArrayType> ? FollowArrays extends true ? GqlLeaves<ArrayType, FollowArrays, Prev[Depth]> : never : "__typename" extends keyof T ? {
|
|
3
3
|
[K in keyof T as K extends "__typename" ? never : K]-?: GqlLeaves<T[K], FollowArrays, Prev[Depth]>;
|
|
4
4
|
} : never : never;
|
|
5
|
+
type IfExplicitAny<T, Y, N> = T extends never ? Y : N;
|
|
5
6
|
type FieldNames<T> = {
|
|
6
7
|
[K in keyof T]: `${Exclude<K, symbol>}${FieldNames<T[K]> extends never ? "" : `.${FieldNames<T[K]>}`}`;
|
|
7
8
|
}[keyof T];
|
|
8
|
-
export type UsableFields<T, FollowArrays extends boolean = false> = FieldNames<GqlLeaves<T, FollowArrays
|
|
9
|
+
export type UsableFields<T, FollowArrays extends boolean = false> = IfExplicitAny<T, any, FieldNames<GqlLeaves<T, FollowArrays>>>;
|
|
10
|
+
type FormFieldNames<T> = {
|
|
11
|
+
[K in keyof T]: `${Exclude<K, symbol>}` | (FormFieldNames<T[K]> extends never ? never : `${Exclude<K, symbol>}.${FormFieldNames<T[K]>}`);
|
|
12
|
+
}[keyof T];
|
|
13
|
+
export type UsableFormFields<T> = IfExplicitAny<T, any, FormFieldNames<GqlLeaves<T, false>>>;
|
|
9
14
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function generateGqlQueryTreeFromFields(fields: string[]): string;
|
|
2
|
+
export declare function generateGqlOperation(options: {
|
|
3
|
+
type: "query" | "mutation";
|
|
4
|
+
operationName: string;
|
|
5
|
+
rootOperation: string;
|
|
6
|
+
variables?: {
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}[];
|
|
10
|
+
fields: string[];
|
|
11
|
+
fragmentVariables?: string[];
|
|
12
|
+
}): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGqlQueryTreeFromFields = generateGqlQueryTreeFromFields;
|
|
4
|
+
exports.generateGqlOperation = generateGqlOperation;
|
|
5
|
+
function generateGqlQueryTreeFromFields(fields) {
|
|
6
|
+
// Helper to get or create a node at a given path
|
|
7
|
+
function getOrCreateNode(root, path) {
|
|
8
|
+
let node = root;
|
|
9
|
+
for (const part of path) {
|
|
10
|
+
if (!node.children[part]) {
|
|
11
|
+
node.children[part] = { children: {}, fragments: [] };
|
|
12
|
+
}
|
|
13
|
+
node = node.children[part];
|
|
14
|
+
}
|
|
15
|
+
return node;
|
|
16
|
+
}
|
|
17
|
+
// 1. create tree out of dot separated fields
|
|
18
|
+
const root = { children: {}, fragments: [] };
|
|
19
|
+
for (const field of fields) {
|
|
20
|
+
const fragmentMatch = field.match(/(.*)(\.{3}.*)/);
|
|
21
|
+
if (fragmentMatch) {
|
|
22
|
+
// e.g. foo.bar...Fragment
|
|
23
|
+
const key = fragmentMatch[1].trim();
|
|
24
|
+
const fragment = fragmentMatch[2].trim();
|
|
25
|
+
if (key === "") {
|
|
26
|
+
root.fragments.push(fragment);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const path = key.split(".").filter(Boolean);
|
|
30
|
+
const node = getOrCreateNode(root, path);
|
|
31
|
+
node.fragments.push(fragment);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// e.g. foo.bar.baz
|
|
36
|
+
const path = field.split(".").filter(Boolean);
|
|
37
|
+
if (path.length === 0)
|
|
38
|
+
continue;
|
|
39
|
+
// Mark the leaf node (no need to store field names, just ensure the path exists)
|
|
40
|
+
getOrCreateNode(root, path);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// 2. create fragment string out of tree
|
|
44
|
+
function recursiveStringify(node) {
|
|
45
|
+
const parts = [];
|
|
46
|
+
// Add fields (children)
|
|
47
|
+
for (const key of Object.keys(node.children)) {
|
|
48
|
+
const child = node.children[key];
|
|
49
|
+
const childStr = recursiveStringify(child);
|
|
50
|
+
if (childStr) {
|
|
51
|
+
parts.push(`${key} { ${childStr} }`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
parts.push(key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Add fragments
|
|
58
|
+
if (node.fragments.length > 0) {
|
|
59
|
+
parts.push(...node.fragments);
|
|
60
|
+
}
|
|
61
|
+
return parts.join(" ");
|
|
62
|
+
}
|
|
63
|
+
return recursiveStringify(root);
|
|
64
|
+
}
|
|
65
|
+
function generateGqlOperation(options) {
|
|
66
|
+
var _a;
|
|
67
|
+
let queryArgs = "";
|
|
68
|
+
if (options.variables && options.variables.length > 0) {
|
|
69
|
+
queryArgs += `(`;
|
|
70
|
+
queryArgs += options.variables.map((v) => `$${v.name}: ${v.type}`).join(", ");
|
|
71
|
+
queryArgs += `)`;
|
|
72
|
+
}
|
|
73
|
+
let rootQueryArgs = "";
|
|
74
|
+
if (options.variables && options.variables.length > 0) {
|
|
75
|
+
rootQueryArgs += `(`;
|
|
76
|
+
rootQueryArgs += options.variables.map((v) => `${v.name}: $${v.name}`).join(", ");
|
|
77
|
+
rootQueryArgs += `)`;
|
|
78
|
+
}
|
|
79
|
+
return `
|
|
80
|
+
${options.type} ${options.operationName}${queryArgs} {
|
|
81
|
+
${options.rootOperation}${rootQueryArgs} {
|
|
82
|
+
${generateGqlQueryTreeFromFields(options.fields)}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
${((_a = options.fragmentVariables) !== null && _a !== void 0 ? _a : []).join("\n")}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
@@ -19,7 +19,12 @@ function generateImportsCode(imports) {
|
|
|
19
19
|
});
|
|
20
20
|
const importsString = filteredImports
|
|
21
21
|
.map((imp) => {
|
|
22
|
-
|
|
22
|
+
if (imp.defaultImport) {
|
|
23
|
+
return `import ${imp.name} from "${imp.importPath}";`;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return `import { ${imp.name} } from "${imp.importPath}";`;
|
|
27
|
+
}
|
|
23
28
|
})
|
|
24
29
|
.join("\n");
|
|
25
30
|
return importsString;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { FormConfig, FormFieldConfig, GeneratorConfig, GridColumnConfig, GridColumnStaticSelectValue, GridConfig, StaticSelectValue, } from "./commands/generate/generate-command";
|
|
2
|
-
export { defineConfig } from "./commands/generate/generate-command";
|
|
1
|
+
export type { FormConfig, FormFieldConfig, GeneratorConfig, GridColumnConfig, GridColumnStaticSelectValue, GridConfig, InjectedFormVariables, StaticSelectValue, } from "./commands/generate/generate-command";
|
|
2
|
+
export { defineConfig, injectFormVariables } from "./commands/generate/generate-command";
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineConfig = void 0;
|
|
3
|
+
exports.injectFormVariables = exports.defineConfig = void 0;
|
|
4
4
|
var generate_command_1 = require("./commands/generate/generate-command");
|
|
5
5
|
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return generate_command_1.defineConfig; } });
|
|
6
|
+
Object.defineProperty(exports, "injectFormVariables", { enumerable: true, get: function () { return generate_command_1.injectFormVariables; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/admin-generator",
|
|
3
|
-
"version": "9.0.0-canary-
|
|
3
|
+
"version": "9.0.0-canary-20251124092450",
|
|
4
4
|
"description": "Comet Admin Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/admin/admin-generator",
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"ts-node": "^10.9.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@apollo/client": "^3.7.0",
|
|
33
34
|
"@mui/material": "^7.2.0",
|
|
34
35
|
"@mui/x-data-grid": "^7.29.8",
|
|
35
36
|
"@types/jest": "^29.5.14",
|
|
36
|
-
"@types/node": "^
|
|
37
|
+
"@types/node": "^24.9.1",
|
|
37
38
|
"@types/object-path": "^0.11.4",
|
|
38
39
|
"@types/pluralize": "^0.0.33",
|
|
39
40
|
"@types/react": "^18.3.23",
|
|
@@ -48,11 +49,11 @@
|
|
|
48
49
|
"react-intl": "^7.1.11",
|
|
49
50
|
"rimraf": "^6.0.1",
|
|
50
51
|
"ts-jest": "^29.4.0",
|
|
51
|
-
"typescript": "5.
|
|
52
|
-
"@comet/admin": "9.0.0-canary-
|
|
53
|
-
"@comet/admin-icons": "9.0.0-canary-
|
|
54
|
-
"@comet/cms-admin": "9.0.0-canary-
|
|
55
|
-
"@comet/eslint-config": "9.0.0-canary-
|
|
52
|
+
"typescript": "5.9.3",
|
|
53
|
+
"@comet/admin": "9.0.0-canary-20251124092450",
|
|
54
|
+
"@comet/admin-icons": "9.0.0-canary-20251124092450",
|
|
55
|
+
"@comet/cms-admin": "9.0.0-canary-20251124092450",
|
|
56
|
+
"@comet/eslint-config": "9.0.0-canary-20251124092450"
|
|
56
57
|
},
|
|
57
58
|
"engines": {
|
|
58
59
|
"node": ">=22.0.0"
|
|
@@ -62,12 +63,12 @@
|
|
|
62
63
|
"registry": "https://registry.npmjs.org"
|
|
63
64
|
},
|
|
64
65
|
"scripts": {
|
|
65
|
-
"build": "
|
|
66
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
66
67
|
"clean": "rimraf lib",
|
|
67
68
|
"dev": "tsc --watch --preserveWatchOutput -p tsconfig.build.json",
|
|
68
69
|
"lint": "run-p lint:prettier lint:eslint lint:tsc",
|
|
69
70
|
"lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
|
|
70
|
-
"lint:prettier": "
|
|
71
|
+
"lint:prettier": "pnpm exec prettier --check './**/*.{js,json,md,yml,yaml}'",
|
|
71
72
|
"lint:tsc": "tsc",
|
|
72
73
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
|
|
73
74
|
"test:updateSnapshot": "NODE_OPTIONS=--experimental-vm-modules jest --updateSnapshot",
|