@comet/admin-generator 8.17.1 → 9.0.0-beta.0

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.
Files changed (87) hide show
  1. package/bin/admin-generator.mjs +3 -0
  2. package/dist/adminGenerator.d.mts +1 -0
  3. package/dist/adminGenerator.mjs +4441 -0
  4. package/dist/index.d.mts +344 -0
  5. package/dist/index.mjs +4440 -0
  6. package/package.json +31 -21
  7. package/bin/admin-generator.js +0 -8
  8. package/lib/adminGenerator.d.ts +0 -1
  9. package/lib/adminGenerator.js +0 -8
  10. package/lib/commands/generate/config/parseConfig.d.ts +0 -1
  11. package/lib/commands/generate/config/parseConfig.js +0 -72
  12. package/lib/commands/generate/config/transformConfig.d.ts +0 -7
  13. package/lib/commands/generate/config/transformConfig.js +0 -264
  14. package/lib/commands/generate/generate-command.d.ts +0 -340
  15. package/lib/commands/generate/generate-command.js +0 -112
  16. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.d.ts +0 -26
  17. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +0 -364
  18. package/lib/commands/generate/generateForm/extractErrorEnums.d.ts +0 -16
  19. package/lib/commands/generate/generateForm/extractErrorEnums.js +0 -100
  20. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +0 -2
  21. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +0 -22
  22. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.d.ts +0 -6
  23. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.js +0 -22
  24. package/lib/commands/generate/generateForm/formField/options.d.ts +0 -24
  25. package/lib/commands/generate/generateForm/formField/options.js +0 -85
  26. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +0 -5
  27. package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -22
  28. package/lib/commands/generate/generateForm/generateErrorHandling.d.ts +0 -8
  29. package/lib/commands/generate/generateForm/generateErrorHandling.js +0 -24
  30. package/lib/commands/generate/generateForm/generateErrorMessages.d.ts +0 -11
  31. package/lib/commands/generate/generateForm/generateErrorMessages.js +0 -28
  32. package/lib/commands/generate/generateForm/generateFields.d.ts +0 -42
  33. package/lib/commands/generate/generateForm/generateFields.js +0 -87
  34. package/lib/commands/generate/generateForm/generateForm.d.ts +0 -14
  35. package/lib/commands/generate/generateForm/generateForm.js +0 -565
  36. package/lib/commands/generate/generateForm/generateFormField.d.ts +0 -12
  37. package/lib/commands/generate/generateForm/generateFormField.js +0 -368
  38. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +0 -12
  39. package/lib/commands/generate/generateForm/generateFormLayout.js +0 -154
  40. package/lib/commands/generate/generateForm/generateFormValues.d.ts +0 -40
  41. package/lib/commands/generate/generateForm/generateFormValues.js +0 -219
  42. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +0 -11
  43. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +0 -29
  44. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +0 -18
  45. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +0 -79
  46. package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +0 -5
  47. package/lib/commands/generate/generateGrid/detectMuiXVersion.js +0 -32
  48. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +0 -2
  49. package/lib/commands/generate/generateGrid/findInputObjectType.js +0 -15
  50. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +0 -6
  51. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +0 -56
  52. package/lib/commands/generate/generateGrid/generateGrid.d.ts +0 -16
  53. package/lib/commands/generate/generateGrid/generateGrid.js +0 -1017
  54. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +0 -15
  55. package/lib/commands/generate/generateGrid/generateGridToolbar.js +0 -90
  56. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +0 -13
  57. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +0 -59
  58. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +0 -14
  59. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +0 -13
  60. package/lib/commands/generate/generateGrid/usableFields.d.ts +0 -14
  61. package/lib/commands/generate/generateGrid/usableFields.js +0 -3
  62. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +0 -1
  63. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +0 -7
  64. package/lib/commands/generate/utils/columnVisibility.d.ts +0 -6
  65. package/lib/commands/generate/utils/columnVisibility.js +0 -2
  66. package/lib/commands/generate/utils/convertConfigImport.d.ts +0 -6
  67. package/lib/commands/generate/utils/convertConfigImport.js +0 -14
  68. package/lib/commands/generate/utils/findMutationType.d.ts +0 -3
  69. package/lib/commands/generate/utils/findMutationType.js +0 -18
  70. package/lib/commands/generate/utils/findQueryType.d.ts +0 -2
  71. package/lib/commands/generate/utils/findQueryType.js +0 -18
  72. package/lib/commands/generate/utils/findRootBlocks.d.ts +0 -8
  73. package/lib/commands/generate/utils/findRootBlocks.js +0 -66
  74. package/lib/commands/generate/utils/generateGqlOperation.d.ts +0 -12
  75. package/lib/commands/generate/utils/generateGqlOperation.js +0 -87
  76. package/lib/commands/generate/utils/generateImportsCode.d.ts +0 -6
  77. package/lib/commands/generate/utils/generateImportsCode.js +0 -31
  78. package/lib/commands/generate/utils/intl.d.ts +0 -20
  79. package/lib/commands/generate/utils/intl.js +0 -44
  80. package/lib/commands/generate/utils/isFieldOptional.d.ts +0 -7
  81. package/lib/commands/generate/utils/isFieldOptional.js +0 -21
  82. package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +0 -20
  83. package/lib/commands/generate/utils/runtimeTypeGuards.js +0 -22
  84. package/lib/commands/generate/utils/writeGenerated.d.ts +0 -1
  85. package/lib/commands/generate/utils/writeGenerated.js +0 -123
  86. package/lib/index.d.ts +0 -2
  87. package/lib/index.js +0 -6
@@ -0,0 +1,344 @@
1
+ import { Command } from "commander";
2
+ import { FormattedMessage, MessageDescriptor } from "react-intl";
3
+ import { ApolloClient } from "@apollo/client";
4
+ import { GridColDef } from "@comet/admin";
5
+ import { IconName } from "@comet/admin-icons";
6
+ import { BlockInterface, ContentScope, FinalFormFileUploadProps } from "@comet/cms-admin";
7
+ import { Breakpoint, IconProps } from "@mui/material";
8
+ import { GridCellParams, GridFilterItem, GridFilterOperator, GridRenderCellParams, GridSortDirection, GridValidRowModel } from "@mui/x-data-grid";
9
+ import { FieldValidator, FormApi } from "final-form";
10
+ import { ComponentType, JSX, ReactElement } from "react";
11
+
12
+ //#region src/commands/generate/generateGrid/usableFields.d.ts
13
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
14
+ 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 ? { [K in keyof T as K extends "__typename" ? never : K]-?: GqlLeaves<T[K], FollowArrays, Prev[Depth]> } : never : never;
15
+ type IfExplicitAny<T, Y, N> = T extends never ? Y : N;
16
+ type FieldNames<T> = { [K in keyof T]: `${Exclude<K, symbol>}${FieldNames<T[K]> extends never ? "" : `.${FieldNames<T[K]>}`}` }[keyof T];
17
+ type UsableFields<T, FollowArrays extends boolean = false> = IfExplicitAny<T, any, FieldNames<GqlLeaves<T, FollowArrays>>>;
18
+ type FormFieldNames<T> = { [K in keyof T]: `${Exclude<K, symbol>}` | (FormFieldNames<T[K]> extends never ? never : `${Exclude<K, symbol>}.${FormFieldNames<T[K]>}`) }[keyof T];
19
+ type UsableFormFields<T> = IfExplicitAny<T, any, FormFieldNames<GqlLeaves<T, false>>>;
20
+ //#endregion
21
+ //#region src/commands/generate/utils/columnVisibility.d.ts
22
+ type BreakpointKey = `'${Breakpoint}'` | number;
23
+ type SingleValueBrakpointTypes = "up" | "down" | "only" | "not";
24
+ type MultiValueBrakpointTypes = "between";
25
+ type ColumnVisibleOption = `${SingleValueBrakpointTypes}(${BreakpointKey})` | `${MultiValueBrakpointTypes}(${BreakpointKey}, ${BreakpointKey})` | false;
26
+ //#endregion
27
+ //#region src/commands/generate/generate-command.d.ts
28
+ type FormattedMessageElement = ReactElement<MessageDescriptor, typeof FormattedMessage>;
29
+ type IconObject = Pick<IconProps, "color" | "fontSize"> & {
30
+ name: IconName;
31
+ };
32
+ type Icon = IconName | IconObject | ComponentType;
33
+ type Adornment = string | {
34
+ icon: Icon;
35
+ };
36
+ type InputBaseFieldConfig = {
37
+ startAdornment?: Adornment;
38
+ endAdornment?: Adornment;
39
+ };
40
+ type ComponentFormFieldConfig = {
41
+ type: "component";
42
+ component: ComponentType;
43
+ };
44
+ type StaticSelectValue = {
45
+ value: string;
46
+ label: string | FormattedMessageElement;
47
+ } | string;
48
+ type AsyncSelectFilter = {
49
+ /**
50
+ * Filter by value of field in current form
51
+ */
52
+ type: "field";
53
+ /**
54
+ * Name of the field in current form, that will be used to filter the query
55
+ */
56
+ formFieldName: string;
57
+ /**
58
+ * Name of the graphql argument the prop will be applied to. Defaults to propdName.
59
+ *
60
+ * Root Argument or filter argument are supported.
61
+ */
62
+ rootQueryArg?: string;
63
+ } | {
64
+ /**
65
+ * Filter by a prop passed into the form, this prop will be generated
66
+ */
67
+ type: "formProp";
68
+ /**
69
+ * Name of the prop generated for this form
70
+ */
71
+ propName: string;
72
+ /**
73
+ * Name of the graphql argument the prop will be applied to. Defaults to propdName.
74
+ *
75
+ * Root Argument or filter argument are supported.
76
+ */
77
+ rootQueryArg?: string;
78
+ };
79
+ type FormFieldConfig<T> = (({
80
+ type: "text";
81
+ name: UsableFormFields<T>;
82
+ multiline?: boolean;
83
+ initialValue?: string;
84
+ } & InputBaseFieldConfig) | ({
85
+ type: "number";
86
+ name: UsableFormFields<T>;
87
+ decimals?: number;
88
+ initialValue?: number;
89
+ } & InputBaseFieldConfig) | ({
90
+ type: "numberRange";
91
+ name: UsableFormFields<T>;
92
+ minValue: number;
93
+ maxValue: number;
94
+ disableSlider?: boolean;
95
+ initialValue?: {
96
+ min: number;
97
+ max: number;
98
+ };
99
+ } & InputBaseFieldConfig) | {
100
+ type: "boolean";
101
+ name: UsableFormFields<T>;
102
+ initialValue?: boolean;
103
+ checkboxLabel?: string | FormattedMessageElement;
104
+ } | ({
105
+ type: "date";
106
+ name: UsableFormFields<T>;
107
+ initialValue?: string;
108
+ } & InputBaseFieldConfig) | ({
109
+ type: "dateTime";
110
+ name: UsableFormFields<T>;
111
+ initialValue?: Date;
112
+ } & InputBaseFieldConfig) | ({
113
+ type: "staticSelect";
114
+ name: UsableFormFields<T>;
115
+ values?: StaticSelectValue[];
116
+ inputType?: "select" | "radio";
117
+ initialValue?: string;
118
+ } & Omit<InputBaseFieldConfig, "endAdornment">) | ({
119
+ type: "asyncSelect";
120
+ name: UsableFormFields<T>;
121
+ rootQuery: string;
122
+ labelField?: string;
123
+ /** Whether Autocomplete or Select should be used.
124
+ *
125
+ * defaults to true if rootQuery has a search argument
126
+ */
127
+ autocomplete?: boolean;
128
+ /**
129
+ * filter for query, passed as variable to graphql query
130
+ */
131
+ filter?: AsyncSelectFilter;
132
+ } & Omit<InputBaseFieldConfig, "endAdornment">) | ({
133
+ type: "asyncSelectFilter";
134
+ name: string;
135
+ loadValueQueryField: string;
136
+ rootQuery: string;
137
+ labelField?: string;
138
+ /** Whether Autocomplete or Select should be used.
139
+ *
140
+ * defaults to true if rootQuery has a search argument
141
+ */
142
+ autocomplete?: boolean;
143
+ /**
144
+ * filter for query, passed as variable to graphql query
145
+ */
146
+ filter?: AsyncSelectFilter;
147
+ } & Omit<InputBaseFieldConfig, "endAdornment">) | {
148
+ type: "block";
149
+ name: UsableFormFields<T>;
150
+ block: BlockInterface;
151
+ } | ({
152
+ type: "fileUpload";
153
+ multiple?: false;
154
+ name: UsableFormFields<T>;
155
+ maxFiles?: 1;
156
+ download?: boolean;
157
+ } & Pick<Partial<FinalFormFileUploadProps<false>>, "maxFileSize" | "readOnly" | "layout" | "accept">) | ({
158
+ type: "fileUpload";
159
+ multiple: true;
160
+ name: UsableFormFields<T>;
161
+ maxFiles?: number;
162
+ download?: boolean;
163
+ } & Pick<Partial<FinalFormFileUploadProps<true>>, "maxFileSize" | "readOnly" | "layout" | "accept">)) & {
164
+ label?: string | FormattedMessageElement;
165
+ required?: boolean;
166
+ validate?: FieldValidator<unknown>;
167
+ helperText?: string | FormattedMessageElement;
168
+ readOnly?: boolean;
169
+ };
170
+ type OptionalNestedFieldsConfig<T> = {
171
+ type: "optionalNestedFields";
172
+ name: UsableFormFields<T>;
173
+ checkboxLabel?: string | FormattedMessageElement;
174
+ fields: FormFieldConfig<any>[];
175
+ };
176
+ type FormLayoutConfig<T> = {
177
+ type: "fieldSet";
178
+ name: string;
179
+ title?: string | FormattedMessageElement;
180
+ supportText?: string;
181
+ collapsible?: boolean;
182
+ initiallyExpanded?: boolean;
183
+ fields: (FormFieldConfig<T> | OptionalNestedFieldsConfig<T> | ComponentFormFieldConfig)[];
184
+ } | OptionalNestedFieldsConfig<T>;
185
+ type FormConfig<T extends {
186
+ __typename?: string;
187
+ }> = {
188
+ type: "form";
189
+ gqlType: T["__typename"];
190
+ mode?: "edit" | "add" | "all";
191
+ fragmentName?: string;
192
+ createMutation?: string;
193
+ /**
194
+ * If true, scope will be passed as prop, if false scope will be fetched from ContentScopeContext
195
+ * @default false
196
+ */
197
+ scopeAsProp?: boolean;
198
+ fields: (FormFieldConfig<T> | FormLayoutConfig<T> | ComponentFormFieldConfig)[];
199
+ /**
200
+ * If true, the form will navigate to the edit page using stackSwitchApi.activatePage of the newly created item after a successful creation.
201
+ * @default true
202
+ */
203
+ navigateOnCreate?: boolean;
204
+ /**
205
+ * If true, the generated form will have an initialValues prop to set initial form values.
206
+ * @default false
207
+ */
208
+ initialValuesAsProp?: boolean;
209
+ };
210
+ type InjectedFormVariables = {
211
+ id?: string;
212
+ mode?: "edit" | "add";
213
+ client: ApolloClient<object>;
214
+ formApi: FormApi<unknown, Partial<unknown>>;
215
+ scope: ContentScope;
216
+ };
217
+ declare function injectFormVariables<T>(fn: (injectedVariables: InjectedFormVariables) => T): T;
218
+ type BaseColumnConfig = Pick<GridColDef, "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
219
+ headerName?: string | FormattedMessageElement;
220
+ headerInfoTooltip?: string | FormattedMessageElement;
221
+ visible?: ColumnVisibleOption;
222
+ fieldName?: string;
223
+ };
224
+ type GridColumnStaticSelectLabelCellContent = {
225
+ primaryText?: string | FormattedMessageElement;
226
+ secondaryText?: string | FormattedMessageElement;
227
+ icon?: Icon;
228
+ };
229
+ type GridColumnStaticSelectValue = StaticSelectValue | {
230
+ value: string | number | boolean;
231
+ label: string | FormattedMessageElement | GridColumnStaticSelectLabelCellContent;
232
+ } | number | boolean;
233
+ type GridColumnConfig<T extends GridValidRowModel> = ({
234
+ type: "text";
235
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
236
+ } | {
237
+ type: "number";
238
+ currency?: string;
239
+ decimals?: number;
240
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
241
+ } | {
242
+ type: "boolean";
243
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
244
+ } | {
245
+ type: "date";
246
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
247
+ } | {
248
+ type: "dateTime";
249
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
250
+ } | {
251
+ type: "staticSelect";
252
+ values?: GridColumnStaticSelectValue[];
253
+ } | {
254
+ type: "block";
255
+ block: BlockInterface;
256
+ } | {
257
+ type: "id";
258
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
259
+ } | {
260
+ type: "manyToMany";
261
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
262
+ queryFields?: UsableFields<T, true>[];
263
+ /**
264
+ * The field to use as label for the default renderCell implementation.
265
+ */
266
+ labelField?: string;
267
+ } | {
268
+ type: "oneToMany";
269
+ renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
270
+ queryFields?: UsableFields<T, true>[];
271
+ /**
272
+ * The field to use as label for the default renderCell implementation.
273
+ */
274
+ labelField?: string;
275
+ }) & {
276
+ name: UsableFields<T>;
277
+ filterOperators?: GridFilterOperator[];
278
+ } & BaseColumnConfig;
279
+ type ActionsGridColumnConfig<T> = {
280
+ type: "actions";
281
+ queryFields?: UsableFields<T, true>[];
282
+ component?: ComponentType<GridCellParams>;
283
+ } & BaseColumnConfig;
284
+ type VirtualGridColumnConfig<T extends GridValidRowModel> = {
285
+ type: "virtual";
286
+ name: string;
287
+ queryFields?: UsableFields<T, true>[];
288
+ renderCell: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
289
+ } & Pick<GridColDef, "sortBy"> & BaseColumnConfig;
290
+ type InitialFilterConfig = {
291
+ items: GridFilterItem[];
292
+ linkOperator?: "and" | "or";
293
+ };
294
+ type GridConfigGridColumnDef<T extends {
295
+ __typename?: string;
296
+ }> = GridColumnConfig<T> | ActionsGridColumnConfig<T> | VirtualGridColumnConfig<T>;
297
+ type GridConfig<T extends {
298
+ __typename?: string;
299
+ }> = {
300
+ type: "grid";
301
+ gqlType: T["__typename"];
302
+ fragmentName?: string;
303
+ query?: string;
304
+ queryParamsPrefix?: string;
305
+ columns: Array<GridConfigGridColumnDef<T>>;
306
+ excelExport?: boolean;
307
+ add?: boolean;
308
+ edit?: boolean;
309
+ delete?: boolean;
310
+ readOnly?: boolean;
311
+ initialSort?: Array<{
312
+ field: string;
313
+ sort: GridSortDirection;
314
+ }>;
315
+ initialFilter?: InitialFilterConfig;
316
+ filterProp?: boolean;
317
+ toolbar?: boolean;
318
+ toolbarActionProp?: boolean;
319
+ newEntryText?: string | FormattedMessageElement;
320
+ rowActionProp?: boolean;
321
+ selectionProps?: "multiSelect" | "singleSelect";
322
+ rowReordering?: {
323
+ enabled: boolean;
324
+ dragPreviewField?: UsableFields<T>;
325
+ };
326
+ /**
327
+ * If true, scope will be passed as prop, if false scope will be fetched from ContentScopeContext
328
+ * @default false
329
+ */
330
+ scopeAsProp?: boolean;
331
+ density?: "comfortable" | "compact" | "standard";
332
+ crudContextMenu?: {
333
+ deleteType?: "delete" | "remove";
334
+ deleteText?: string;
335
+ };
336
+ };
337
+ type GeneratorConfig<T extends {
338
+ __typename?: string;
339
+ }> = FormConfig<T> | GridConfig<T>;
340
+ declare function defineConfig<T extends {
341
+ __typename?: string;
342
+ }>(config: GeneratorConfig<T>): GeneratorConfig<T>;
343
+ //#endregion
344
+ export { type FormConfig, type FormFieldConfig, type GeneratorConfig, type GridColumnConfig, type GridColumnStaticSelectValue, type GridConfig, type InjectedFormVariables, type StaticSelectValue, defineConfig, injectFormVariables };