@comet/admin-generator 8.20.2 → 9.0.0-beta.1

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 (100) hide show
  1. package/bin/admin-generator.mjs +3 -0
  2. package/dist/acorn-DJxsNFiE.mjs +5080 -0
  3. package/dist/adminGenerator.d.mts +1 -0
  4. package/dist/adminGenerator.mjs +21290 -0
  5. package/dist/angular-C36OsqNr.mjs +3628 -0
  6. package/dist/babel-BsGOu8GE.mjs +10033 -0
  7. package/dist/estree-Biokeu50.mjs +6925 -0
  8. package/dist/flow-CB28NGHZ.mjs +52250 -0
  9. package/dist/glimmer-DR4e0tMz.mjs +7270 -0
  10. package/dist/graphql-VvXYjgLl.mjs +1896 -0
  11. package/dist/html-CrrCmVRu.mjs +6554 -0
  12. package/dist/index.d.mts +344 -0
  13. package/dist/index.mjs +21289 -0
  14. package/dist/markdown-DNhRA55T.mjs +6832 -0
  15. package/dist/meriyah-D6wW_ax3.mjs +8927 -0
  16. package/dist/postcss-BXXublqh.mjs +6753 -0
  17. package/dist/typescript-CSyKZscd.mjs +23001 -0
  18. package/dist/yaml-2rUejh4D.mjs +5216 -0
  19. package/package.json +34 -24
  20. package/bin/admin-generator.js +0 -8
  21. package/lib/adminGenerator.d.ts +0 -1
  22. package/lib/adminGenerator.js +0 -8
  23. package/lib/commands/generate/config/parseConfig.d.ts +0 -1
  24. package/lib/commands/generate/config/parseConfig.js +0 -72
  25. package/lib/commands/generate/config/transformConfig.d.ts +0 -7
  26. package/lib/commands/generate/config/transformConfig.js +0 -264
  27. package/lib/commands/generate/generate-command.d.ts +0 -340
  28. package/lib/commands/generate/generate-command.js +0 -116
  29. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.d.ts +0 -26
  30. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +0 -372
  31. package/lib/commands/generate/generateForm/extractErrorEnums.d.ts +0 -16
  32. package/lib/commands/generate/generateForm/extractErrorEnums.js +0 -100
  33. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +0 -2
  34. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +0 -22
  35. package/lib/commands/generate/generateForm/formField/options.d.ts +0 -24
  36. package/lib/commands/generate/generateForm/formField/options.js +0 -85
  37. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +0 -5
  38. package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -22
  39. package/lib/commands/generate/generateForm/generateErrorHandling.d.ts +0 -8
  40. package/lib/commands/generate/generateForm/generateErrorHandling.js +0 -24
  41. package/lib/commands/generate/generateForm/generateErrorMessages.d.ts +0 -11
  42. package/lib/commands/generate/generateForm/generateErrorMessages.js +0 -28
  43. package/lib/commands/generate/generateForm/generateFields.d.ts +0 -42
  44. package/lib/commands/generate/generateForm/generateFields.js +0 -87
  45. package/lib/commands/generate/generateForm/generateForm.d.ts +0 -14
  46. package/lib/commands/generate/generateForm/generateForm.js +0 -565
  47. package/lib/commands/generate/generateForm/generateFormField.d.ts +0 -12
  48. package/lib/commands/generate/generateForm/generateFormField.js +0 -368
  49. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +0 -12
  50. package/lib/commands/generate/generateForm/generateFormLayout.js +0 -154
  51. package/lib/commands/generate/generateForm/generateFormValues.d.ts +0 -40
  52. package/lib/commands/generate/generateForm/generateFormValues.js +0 -219
  53. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +0 -11
  54. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +0 -29
  55. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +0 -18
  56. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +0 -79
  57. package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +0 -5
  58. package/lib/commands/generate/generateGrid/detectMuiXVersion.js +0 -32
  59. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +0 -2
  60. package/lib/commands/generate/generateGrid/findInputObjectType.js +0 -15
  61. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +0 -6
  62. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +0 -56
  63. package/lib/commands/generate/generateGrid/generateGrid.d.ts +0 -16
  64. package/lib/commands/generate/generateGrid/generateGrid.js +0 -1017
  65. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +0 -15
  66. package/lib/commands/generate/generateGrid/generateGridToolbar.js +0 -90
  67. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +0 -13
  68. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +0 -59
  69. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +0 -14
  70. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +0 -13
  71. package/lib/commands/generate/generateGrid/usableFields.d.ts +0 -14
  72. package/lib/commands/generate/generateGrid/usableFields.js +0 -3
  73. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +0 -1
  74. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +0 -7
  75. package/lib/commands/generate/utils/columnVisibility.d.ts +0 -6
  76. package/lib/commands/generate/utils/columnVisibility.js +0 -2
  77. package/lib/commands/generate/utils/convertConfigImport.d.ts +0 -6
  78. package/lib/commands/generate/utils/convertConfigImport.js +0 -14
  79. package/lib/commands/generate/utils/findIntrospectionFieldType.d.ts +0 -6
  80. package/lib/commands/generate/utils/findIntrospectionFieldType.js +0 -22
  81. package/lib/commands/generate/utils/findMutationType.d.ts +0 -3
  82. package/lib/commands/generate/utils/findMutationType.js +0 -18
  83. package/lib/commands/generate/utils/findQueryType.d.ts +0 -2
  84. package/lib/commands/generate/utils/findQueryType.js +0 -18
  85. package/lib/commands/generate/utils/findRootBlocks.d.ts +0 -8
  86. package/lib/commands/generate/utils/findRootBlocks.js +0 -66
  87. package/lib/commands/generate/utils/generateGqlOperation.d.ts +0 -12
  88. package/lib/commands/generate/utils/generateGqlOperation.js +0 -87
  89. package/lib/commands/generate/utils/generateImportsCode.d.ts +0 -6
  90. package/lib/commands/generate/utils/generateImportsCode.js +0 -31
  91. package/lib/commands/generate/utils/intl.d.ts +0 -20
  92. package/lib/commands/generate/utils/intl.js +0 -44
  93. package/lib/commands/generate/utils/isFieldOptional.d.ts +0 -7
  94. package/lib/commands/generate/utils/isFieldOptional.js +0 -21
  95. package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +0 -20
  96. package/lib/commands/generate/utils/runtimeTypeGuards.js +0 -22
  97. package/lib/commands/generate/utils/writeGenerated.d.ts +0 -1
  98. package/lib/commands/generate/utils/writeGenerated.js +0 -123
  99. package/lib/index.d.ts +0 -2
  100. package/lib/index.js +0 -6
@@ -1,372 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findIntrospectionObjectType = findIntrospectionObjectType;
4
- exports.generateAsyncSelect = generateAsyncSelect;
5
- const generate_command_1 = require("../../generate-command");
6
- const findQueryType_1 = require("../../utils/findQueryType");
7
- const generateGqlOperation_1 = require("../../utils/generateGqlOperation");
8
- const isFieldOptional_1 = require("../../utils/isFieldOptional");
9
- const options_1 = require("../formField/options");
10
- const generateFields_1 = require("../generateFields");
11
- function gqlScalarToTypescriptType(scalarName) {
12
- if (scalarName === "String" || scalarName === "ID" || scalarName === "DateTime" || scalarName === "LocalDate" || scalarName === "Date") {
13
- return "string";
14
- }
15
- else if (scalarName === "Boolean") {
16
- return "boolean";
17
- }
18
- else if (scalarName === "Int" || scalarName === "Float") {
19
- return "number";
20
- }
21
- else if (scalarName === "JSONObject") {
22
- return "unknown";
23
- }
24
- else {
25
- return "unknown";
26
- }
27
- }
28
- function buildTypeInfo(arg, gqlIntrospection) {
29
- let typeKind = undefined;
30
- let typeClass = "unknown";
31
- let required = false;
32
- let type = arg.type;
33
- let inputType = undefined;
34
- if (type.kind === "NON_NULL") {
35
- required = true;
36
- type = type.ofType;
37
- }
38
- if (type.kind === "INPUT_OBJECT") {
39
- typeClass = type.name;
40
- typeKind = type.kind;
41
- inputType = gqlIntrospection.__schema.types.find((type) => type.name === typeClass);
42
- }
43
- else if (type.kind === "ENUM") {
44
- typeClass = type.name;
45
- typeKind = type.kind;
46
- }
47
- else if (type.kind === "SCALAR") {
48
- typeClass = type.name;
49
- typeKind = type.kind;
50
- }
51
- else {
52
- throw new Error(`getTypeInfo: Resolving kind ${type.kind} currently not supported.`);
53
- }
54
- return {
55
- required,
56
- typeKind,
57
- typeClass,
58
- inputType,
59
- };
60
- }
61
- /**
62
- * Helper that returns the introspection object type for a given form field config, supporting the special case for asyncSelectFilter
63
- */
64
- function findIntrospectionObjectType({ config, gqlIntrospection, gqlType, }) {
65
- const name = String(config.name);
66
- const introspectionObject = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
67
- if (!introspectionObject)
68
- throw new Error(`didn't find object ${gqlType} in gql introspection`);
69
- function findIntrospectionField(introspectionObject, name) {
70
- const introspectionField = introspectionObject.fields.find((field) => field.name === name);
71
- if (!introspectionField)
72
- throw new Error(`didn't find field ${name} in gql introspection type ${gqlType}`);
73
- let introspectionFieldType = introspectionField.type.kind === "NON_NULL" ? introspectionField.type.ofType : introspectionField.type;
74
- const multiple = (introspectionFieldType === null || introspectionFieldType === void 0 ? void 0 : introspectionFieldType.kind) === "LIST";
75
- if ((introspectionFieldType === null || introspectionFieldType === void 0 ? void 0 : introspectionFieldType.kind) === "LIST") {
76
- introspectionFieldType =
77
- introspectionFieldType.ofType.kind === "NON_NULL" ? introspectionFieldType.ofType.ofType : introspectionFieldType.ofType;
78
- }
79
- if (introspectionFieldType.kind !== "OBJECT")
80
- throw new Error(`asyncSelect only supports OBJECT types`);
81
- const objectType = gqlIntrospection.__schema.types.find((t) => t.kind === "OBJECT" && t.name === introspectionFieldType.name);
82
- if (!objectType)
83
- throw new Error(`Object type ${introspectionFieldType.name} not found for field ${name}`);
84
- return { multiple, objectType };
85
- }
86
- if (config.type === "asyncSelectFilter") {
87
- //for a filter select the field is "virtual", and it's ObjectType is defined by the path in config.loadValueQueryField
88
- return {
89
- multiple: false,
90
- objectType: config.loadValueQueryField.split(".").reduce((acc, fieldName) => {
91
- const introspectionField = findIntrospectionField(acc, fieldName);
92
- if (introspectionField.multiple)
93
- throw new Error(`asyncSelectFilter does not support list fields in loadValueQueryField`);
94
- return introspectionField.objectType;
95
- }, introspectionObject),
96
- };
97
- }
98
- else {
99
- //for a standard select we follow the nested path (if any) to find the final object type
100
- const nameParts = name.split(".");
101
- const lastPart = nameParts[nameParts.length - 1];
102
- const resolvedObject = nameParts.slice(0, -1).reduce((acc, fieldName) => {
103
- const introspectionField = findIntrospectionField(acc, fieldName);
104
- if (introspectionField.multiple)
105
- throw new Error(`asyncSelect does not support list fields in nested path`);
106
- return introspectionField.objectType;
107
- }, introspectionObject);
108
- return findIntrospectionField(resolvedObject, lastPart);
109
- }
110
- }
111
- function generateAsyncSelect({ gqlIntrospection, baseOutputFilename, config, formConfig, gqlType, namePrefix, }) {
112
- var _a, _b, _c;
113
- const imports = [];
114
- const formProps = [];
115
- const { name, fieldLabel, startAdornment,
116
- //endAdornment,
117
- imports: optionsImports, } = (0, options_1.buildFormFieldOptions)({ config, formConfig });
118
- imports.push(...optionsImports);
119
- const nameWithPrefix = `${namePrefix ? `${namePrefix}.` : ``}${name}`;
120
- const required = !(0, isFieldOptional_1.isFieldOptional)({ config, gqlIntrospection, gqlType });
121
- const formValueConfig = {
122
- fieldName: name,
123
- destructFromFormValues: config.type == "asyncSelectFilter",
124
- };
125
- let finalFormConfig;
126
- let code = "";
127
- const { objectType, multiple } = findIntrospectionObjectType({
128
- config,
129
- gqlIntrospection,
130
- gqlType,
131
- });
132
- //find labelField: 1. as configured
133
- let labelField = config.labelField;
134
- //find labelField: 2. common names (name or title)
135
- if (!labelField) {
136
- labelField = (_a = objectType.fields.find((field) => {
137
- let type = field.type;
138
- if (type.kind == "NON_NULL")
139
- type = type.ofType;
140
- if ((field.name == "name" || field.name == "title") && type.kind == "SCALAR" && type.name == "String") {
141
- return true;
142
- }
143
- })) === null || _a === void 0 ? void 0 : _a.name;
144
- }
145
- //find labelField: 3. first string field
146
- if (!labelField) {
147
- labelField = (_b = objectType.fields.find((field) => {
148
- let type = field.type;
149
- if (type.kind == "NON_NULL")
150
- type = type.ofType;
151
- if (field.type.kind == "SCALAR" && field.type.name == "String") {
152
- return true;
153
- }
154
- })) === null || _b === void 0 ? void 0 : _b.name;
155
- }
156
- const rootQuery = config.rootQuery; //TODO we should infer a default value from the gql schema
157
- const queryName = `${rootQuery[0].toUpperCase() + rootQuery.substring(1)}Select`;
158
- const rootQueryType = (0, findQueryType_1.findQueryTypeOrThrow)(rootQuery, gqlIntrospection);
159
- let formFragmentFields;
160
- if (config.type == "asyncSelectFilter") {
161
- formFragmentFields = [`${config.loadValueQueryField}.id`, `${config.loadValueQueryField}.${labelField}`];
162
- }
163
- else {
164
- formFragmentFields = [`${name}.id`, `${name}.${labelField}`];
165
- }
166
- const rootQueryHasSearchArg = rootQueryType.args.find((arg) => arg.name === "search");
167
- const useAutocomplete = (_c = config.autocomplete) !== null && _c !== void 0 ? _c : !!rootQueryHasSearchArg;
168
- if (useAutocomplete) {
169
- if (!rootQueryHasSearchArg) {
170
- throw new Error(`Field ${String(config.name)}: Autocomplete is enabled but root query "${rootQuery}" has no search argument.`);
171
- }
172
- if (rootQueryHasSearchArg.type.kind !== "SCALAR" || rootQueryHasSearchArg.type.name !== "String") {
173
- throw new Error(`Field ${String(config.name)}: Autocomplete is enabled but root query "${rootQuery}" has search argument that is not a string.`);
174
- }
175
- }
176
- const filterConfig = config.filter
177
- ? (() => {
178
- var _a;
179
- let filterField;
180
- let rootQueryArg = config.filter.rootQueryArg;
181
- let filterVar = "";
182
- if (config.filter.type === "field") {
183
- filterField = (0, generateFields_1.findFieldByName)(config.filter.formFieldName, formConfig.fields);
184
- if (!filterField) {
185
- throw new Error(`Field ${String(config.name)}: No field with name "${config.filter.formFieldName}" referenced as filter.formFieldName found in form-config.`);
186
- }
187
- if (!(0, generate_command_1.isFormFieldConfig)(filterField)) {
188
- throw new Error(`Field ${String(config.name)}: Field with name "${config.filter.formFieldName}" referenced as filter.formFieldName is no FormField.`);
189
- }
190
- filterVar = `values.${filterField.type === "asyncSelect" || filterField.type === "asyncSelectFilter" ? `${String(filterField.name)}?.id` : String(filterField.name)}`;
191
- if (!rootQueryArg) {
192
- rootQueryArg = config.filter.formFieldName;
193
- }
194
- }
195
- else if (config.filter.type === "formProp") {
196
- filterVar = config.filter.propName;
197
- if (!rootQueryArg) {
198
- rootQueryArg = config.filter.propName;
199
- }
200
- }
201
- else {
202
- throw new Error("unsupported filter type");
203
- }
204
- // try to find arg used to filter by checking names of root-arg and filter-arg-fields
205
- const rootArgForName = rootQueryType.args.find((arg) => arg.name === rootQueryArg);
206
- let filterType = rootArgForName ? buildTypeInfo(rootArgForName, gqlIntrospection) : undefined;
207
- let filterVarName = undefined;
208
- let filterVarValue = undefined;
209
- let filterVarType = "unknown";
210
- if (filterType) {
211
- // there is a query root arg with same name, filter using it
212
- filterVarName = rootQueryArg;
213
- filterVarValue = filterVar;
214
- if (filterType.typeKind === "INPUT_OBJECT" || filterType.typeKind === "ENUM") {
215
- filterVarType = `GQL${filterType.typeClass}`;
216
- imports.push({
217
- name: filterVarType,
218
- importPath: "@src/graphql.generated",
219
- });
220
- }
221
- else if (filterType.typeKind === "SCALAR") {
222
- filterVarType = gqlScalarToTypescriptType(filterType.typeClass);
223
- }
224
- }
225
- else {
226
- // no root-arg with same name, check filter-arg-fields
227
- const rootArgFilter = rootQueryType.args.find((arg) => arg.name === "filter");
228
- filterType = rootArgFilter ? buildTypeInfo(rootArgFilter, gqlIntrospection) : undefined;
229
- if (filterType) {
230
- filterVarName = "filter";
231
- filterVarValue = `{ ${rootQueryArg}: { equal: ${filterVar} } }`;
232
- // get type of field.equal in filter-arg used for filtering
233
- if (((_a = filterType.inputType) === null || _a === void 0 ? void 0 : _a.kind) !== "INPUT_OBJECT") {
234
- throw new Error(`Field ${String(config.name)}: Type of filter is no object-type.`);
235
- }
236
- const nestedFilterInput = filterType.inputType.inputFields.find((inputField) => inputField.name === rootQueryArg);
237
- if (!nestedFilterInput) {
238
- throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg} does not exist`);
239
- }
240
- const gqlFilterInputType = buildTypeInfo(nestedFilterInput, gqlIntrospection);
241
- if (!(gqlFilterInputType === null || gqlFilterInputType === void 0 ? void 0 : gqlFilterInputType.inputType) || gqlFilterInputType.inputType.kind !== "INPUT_OBJECT") {
242
- throw new Error(`Field ${String(config.name)}: Type of filter.${rootQueryArg} is no object-type, but needs to be e.g. StringFilter-type.`);
243
- }
244
- const gqlFilterEqualInputType = gqlFilterInputType.inputType.inputFields.find((inputField) => inputField.name === "equal");
245
- if (!gqlFilterEqualInputType) {
246
- throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg}.equal does not exist`);
247
- }
248
- const equalFieldType = buildTypeInfo(gqlFilterEqualInputType, gqlIntrospection);
249
- if (!equalFieldType) {
250
- throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg}.equal does not exist but is required for filtering.`);
251
- }
252
- if (equalFieldType.typeKind === "INPUT_OBJECT" || equalFieldType.typeKind === "ENUM") {
253
- filterVarType = `GQL${equalFieldType.typeClass}`;
254
- imports.push({
255
- name: filterVarType,
256
- importPath: "@src/graphql.generated",
257
- });
258
- }
259
- else if (equalFieldType.typeKind === "SCALAR") {
260
- filterVarType = gqlScalarToTypescriptType(equalFieldType.typeClass);
261
- }
262
- }
263
- else {
264
- throw new Error(`Neither filter-prop nor root-prop with name: ${rootQueryArg} for asyncSelect-query not found. Consider setting filterField.gqlVarName explicitly.`);
265
- }
266
- }
267
- if (config.filter.type === "formProp") {
268
- formProps.push({
269
- name: config.filter.propName,
270
- optional: false,
271
- type: filterVarType,
272
- });
273
- }
274
- return {
275
- filterField,
276
- filterType,
277
- filterVarName,
278
- filterVarValue,
279
- };
280
- })()
281
- : undefined;
282
- if (filterConfig) {
283
- imports.push({ name: "OnChangeField", importPath: "@comet/admin" });
284
- finalFormConfig = { subscription: { values: true }, renderProps: { values: true, form: true } };
285
- }
286
- if (config.type != "asyncSelectFilter") {
287
- if (!multiple) {
288
- if (!required) {
289
- formValueConfig.formValueToGqlInputCode = `$fieldName ? $fieldName.id : null`;
290
- }
291
- else {
292
- formValueConfig.formValueToGqlInputCode = `$fieldName?.id`;
293
- }
294
- }
295
- else {
296
- formValueConfig.formValueToGqlInputCode = `$fieldName.map((item) => item.id)`;
297
- }
298
- }
299
- imports.push({
300
- name: `GQL${queryName}Query`,
301
- importPath: `./${baseOutputFilename}.generated`,
302
- });
303
- imports.push({
304
- name: `GQL${queryName}QueryVariables`,
305
- importPath: `./${baseOutputFilename}.generated`,
306
- });
307
- if (useAutocomplete) {
308
- imports.push({ name: "AsyncAutocompleteField", importPath: "@comet/admin" });
309
- }
310
- else {
311
- imports.push({ name: "AsyncSelectField", importPath: "@comet/admin" });
312
- }
313
- const instanceGqlType = gqlType[0].toLowerCase() + gqlType.substring(1);
314
- if (config.type == "asyncSelectFilter") {
315
- // add (in the gql schema) non existing value for virtual filter field
316
- formValueConfig.typeCode = { nullable: true, type: `{ id: string; ${labelField}: string }` };
317
- formValueConfig.initializationCode = `data.${instanceGqlType}.${config.loadValueQueryField.replace(/\./g, "?.")}`;
318
- }
319
- code = `<${useAutocomplete ? "AsyncAutocompleteField" : "AsyncSelectField"}
320
- ${required ? "required" : ""}
321
- variant="horizontal"
322
- fullWidth
323
- ${config.readOnly ? "readOnly disabled" : ""}
324
- ${multiple ? "multiple" : ""}
325
- name="${nameWithPrefix}"
326
- label={${fieldLabel}}
327
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
328
- loadOptions={async (${useAutocomplete ? `search?: string` : ""}) => {
329
- const { data } = await client.query<GQL${queryName}Query, GQL${queryName}QueryVariables>({
330
- query: gql\`${(0, generateGqlOperation_1.generateGqlOperation)({
331
- type: "query",
332
- operationName: queryName,
333
- rootOperation: rootQuery,
334
- fields: ["nodes.id", `nodes.${labelField}`],
335
- variables: [
336
- useAutocomplete ? { name: "search", type: "String" } : undefined,
337
- filterConfig
338
- ? {
339
- name: filterConfig.filterVarName,
340
- type: filterConfig.filterType.typeClass + (filterConfig.filterType.required ? `!` : ``),
341
- }
342
- : undefined,
343
- ].filter((v) => v !== undefined),
344
- })}\`${filterConfig || useAutocomplete ? ", variables: { " : ""}
345
- ${filterConfig ? `${filterConfig.filterVarName}: ${filterConfig.filterVarValue},` : ``}
346
- ${useAutocomplete ? `search,` : ``}
347
- ${filterConfig || useAutocomplete ? " }" : ""}
348
- });
349
- return data.${rootQuery}.nodes;
350
- }}
351
- getOptionLabel={(option) => option.${labelField}}
352
- ${(filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.filterField) ? `disabled={!values?.${String(filterConfig.filterField.name)}}` : ``}
353
- />${(filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.filterField)
354
- ? `<OnChangeField name="${String(filterConfig.filterField.name)}">
355
- {(value, previousValue) => {
356
- if (value.id !== previousValue.id) {
357
- form.change("${String(config.name)}", undefined);
358
- }
359
- }}
360
- </OnChangeField>`
361
- : ``}`;
362
- return {
363
- code,
364
- hooksCode: "",
365
- formFragmentFields,
366
- gqlDocuments: {},
367
- imports,
368
- formProps,
369
- formValuesConfig: [formValueConfig],
370
- finalFormConfig,
371
- };
372
- }
@@ -1,16 +0,0 @@
1
- import { type IntrospectionField, type IntrospectionQuery } from "graphql";
2
- interface ErrorEnumsResult {
3
- createErrorEnum?: string;
4
- updateErrorEnum?: string;
5
- useDifferentEnums: boolean;
6
- }
7
- /**
8
- * Extracts error enum type names from create and update mutations.
9
- * Navigates: Mutation → return type → payload object → errors field → LIST → error object → code field → ENUM
10
- */
11
- export declare function extractErrorEnumsFromMutations({ createMutationType, updateMutationType, gqlIntrospection, }: {
12
- createMutationType: IntrospectionField | null;
13
- updateMutationType: IntrospectionField | null;
14
- gqlIntrospection: IntrospectionQuery;
15
- }): ErrorEnumsResult;
16
- export {};
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractErrorEnumsFromMutations = extractErrorEnumsFromMutations;
4
- /**
5
- * Extracts error enum type names from create and update mutations.
6
- * Navigates: Mutation → return type → payload object → errors field → LIST → error object → code field → ENUM
7
- */
8
- function extractErrorEnumsFromMutations({ createMutationType, updateMutationType, gqlIntrospection, }) {
9
- const createErrorEnum = createMutationType ? extractErrorEnumFromMutation(createMutationType, gqlIntrospection) : undefined;
10
- const updateErrorEnum = updateMutationType ? extractErrorEnumFromMutation(updateMutationType, gqlIntrospection) : undefined;
11
- const useDifferentEnums = Boolean(createErrorEnum && updateErrorEnum && createErrorEnum !== updateErrorEnum);
12
- return {
13
- createErrorEnum,
14
- updateErrorEnum,
15
- useDifferentEnums,
16
- };
17
- }
18
- /**
19
- * Extracts error enum type name from a single mutation field.
20
- * Returns undefined if mutation doesn't have error enum.
21
- */
22
- function extractErrorEnumFromMutation(mutationType, gqlIntrospection) {
23
- try {
24
- // 1. Get return type, unwrap NON_NULL if present
25
- let returnType = mutationType.type;
26
- if (returnType.kind === "NON_NULL") {
27
- returnType = returnType.ofType;
28
- }
29
- // 2. Check if return type is an OBJECT (payload type)
30
- if (returnType.kind !== "OBJECT") {
31
- return undefined;
32
- }
33
- // 3. Find the payload object type in introspection schema
34
- const payloadType = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === returnType.name);
35
- if (!payloadType) {
36
- return undefined;
37
- }
38
- // 4. Find "errors" field in the payload object
39
- const errorsField = payloadType.fields.find((field) => field.name === "errors");
40
- if (!errorsField) {
41
- return undefined;
42
- }
43
- // 5. Extract enum from errors field
44
- return extractEnumFromErrorsField(errorsField, gqlIntrospection);
45
- }
46
- catch (_a) {
47
- // If anything goes wrong during traversal, return undefined
48
- return undefined;
49
- }
50
- }
51
- /**
52
- * Extracts enum type name from the errors field.
53
- * Traverses: errors field → unwrap NON_NULL → unwrap LIST → unwrap NON_NULL → error OBJECT → code field → ENUM
54
- */
55
- function extractEnumFromErrorsField(errorsField, gqlIntrospection) {
56
- try {
57
- // 1. Get errors field type, unwrap NON_NULL if present
58
- let errorsType = errorsField.type;
59
- if (errorsType.kind === "NON_NULL") {
60
- errorsType = errorsType.ofType;
61
- }
62
- // 2. Check if it's a LIST
63
- if (errorsType.kind !== "LIST") {
64
- return undefined;
65
- }
66
- // 3. Get the list item type, unwrap NON_NULL if present
67
- let errorItemType = errorsType.ofType;
68
- if (errorItemType.kind === "NON_NULL") {
69
- errorItemType = errorItemType.ofType;
70
- }
71
- // 4. Check if item type is an OBJECT (error type)
72
- if (errorItemType.kind !== "OBJECT") {
73
- return undefined;
74
- }
75
- // 5. Find the error object type in introspection schema
76
- const errorObjectType = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === errorItemType.name);
77
- if (!errorObjectType) {
78
- return undefined;
79
- }
80
- // 6. Find "code" field in the error object
81
- const codeField = errorObjectType.fields.find((field) => field.name === "code");
82
- if (!codeField) {
83
- return undefined;
84
- }
85
- // 7. Get code field type, unwrap NON_NULL if present
86
- let codeType = codeField.type;
87
- if (codeType.kind === "NON_NULL") {
88
- codeType = codeType.ofType;
89
- }
90
- // 8. Check if it's an ENUM
91
- if (codeType.kind !== "ENUM") {
92
- return undefined;
93
- }
94
- // 9. Return the enum type name
95
- return codeType.name;
96
- }
97
- catch (_a) {
98
- return undefined;
99
- }
100
- }
@@ -1,2 +0,0 @@
1
- import { type FormConfig, type FormFieldConfig } from "../generate-command";
2
- export declare function flatFormFieldsFromFormConfig(config: FormConfig<any>): FormFieldConfig<any>[];
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flatFormFieldsFromFormConfig = flatFormFieldsFromFormConfig;
4
- const generate_command_1 = require("../generate-command");
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- function flatFormFieldsFromFormConfig(config) {
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- return config.fields.reduce((acc, field) => {
9
- if ((0, generate_command_1.isFormLayoutConfig)(field)) {
10
- // using forEach instead of acc.push(...field.fields.filter(isFormFieldConfig)) because typescript can't handle mixed typing
11
- field.fields.forEach((nestedFieldConfig) => {
12
- if ((0, generate_command_1.isFormFieldConfig)(nestedFieldConfig)) {
13
- acc.push(nestedFieldConfig);
14
- }
15
- });
16
- }
17
- else if ((0, generate_command_1.isFormFieldConfig)(field)) {
18
- acc.push(field);
19
- }
20
- return acc;
21
- }, []);
22
- }
@@ -1,24 +0,0 @@
1
- import { type FormConfig, type FormFieldConfig } from "../../generate-command";
2
- import { type Imports } from "../../utils/generateImportsCode";
3
- type AdornmentData = {
4
- adornmentString: string;
5
- adornmentImport?: {
6
- name: string;
7
- importPath: string;
8
- };
9
- };
10
- /**
11
- * Helper function that builds various options needed for generating form fields.
12
- */
13
- export declare function buildFormFieldOptions({ config, formConfig, }: {
14
- config: FormFieldConfig<any>;
15
- formConfig: FormConfig<any>;
16
- }): {
17
- name: string;
18
- formattedMessageRootId: any;
19
- fieldLabel: string;
20
- startAdornment: AdornmentData;
21
- endAdornment: AdornmentData;
22
- imports: Imports;
23
- };
24
- export {};
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.buildFormFieldOptions = buildFormFieldOptions;
15
- const camelCaseToHumanReadable_1 = require("../../utils/camelCaseToHumanReadable");
16
- const convertConfigImport_1 = require("../../utils/convertConfigImport");
17
- const intl_1 = require("../../utils/intl");
18
- const runtimeTypeGuards_1 = require("../../utils/runtimeTypeGuards");
19
- const buildAdornmentData = ({ adornmentData }) => {
20
- let adornmentString = "";
21
- let adornmentImport = { name: "", importPath: "" };
22
- if (typeof adornmentData === "string") {
23
- return { adornmentString: adornmentData };
24
- }
25
- if (typeof adornmentData.icon === "string") {
26
- adornmentString = `<${adornmentData.icon}Icon />`;
27
- adornmentImport = {
28
- name: `${adornmentData.icon} as ${adornmentData.icon}Icon`,
29
- importPath: "@comet/admin-icons",
30
- };
31
- }
32
- else if (typeof adornmentData.icon === "object") {
33
- if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(adornmentData.icon)) {
34
- adornmentString = `<${adornmentData.icon.name} />`;
35
- adornmentImport = (0, convertConfigImport_1.convertConfigImport)(adornmentData.icon);
36
- }
37
- else {
38
- const _a = adornmentData.icon, { name } = _a, iconProps = __rest(_a, ["name"]);
39
- adornmentString = `<${name}Icon
40
- ${Object.entries(iconProps)
41
- .map(([key, value]) => `${key}="${value}"`)
42
- .join("\n")}
43
- />`;
44
- adornmentImport = {
45
- name: `${adornmentData.icon.name} as ${adornmentData.icon.name}Icon`,
46
- importPath: "@comet/admin-icons",
47
- };
48
- }
49
- }
50
- return { adornmentString, adornmentImport };
51
- };
52
- /**
53
- * Helper function that builds various options needed for generating form fields.
54
- */
55
- function buildFormFieldOptions({ config, formConfig, }) {
56
- const rootGqlType = formConfig.gqlType;
57
- const name = String(config.name);
58
- const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
59
- const fieldLabel = (0, intl_1.generateFormattedMessage)({
60
- config: config.label,
61
- id: `${formattedMessageRootId}.${name}`,
62
- defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(name),
63
- type: "jsx",
64
- });
65
- const imports = [];
66
- let startAdornment = { adornmentString: "" };
67
- let endAdornment = { adornmentString: "" };
68
- if ("startAdornment" in config && config.startAdornment) {
69
- startAdornment = buildAdornmentData({
70
- adornmentData: config.startAdornment,
71
- });
72
- if (startAdornment.adornmentImport) {
73
- imports.push(startAdornment.adornmentImport);
74
- }
75
- }
76
- if ("endAdornment" in config && config.endAdornment) {
77
- endAdornment = buildAdornmentData({
78
- adornmentData: config.endAdornment,
79
- });
80
- if (endAdornment.adornmentImport) {
81
- imports.push(endAdornment.adornmentImport);
82
- }
83
- }
84
- return { name, formattedMessageRootId, fieldLabel, startAdornment, endAdornment, imports };
85
- }
@@ -1,5 +0,0 @@
1
- import { type ComponentFormFieldConfig } from "../generate-command";
2
- import { type GenerateFieldsReturn } from "./generateFields";
3
- export declare function generateComponentFormField({ config }: {
4
- config: ComponentFormFieldConfig;
5
- }): GenerateFieldsReturn;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateComponentFormField = generateComponentFormField;
4
- const convertConfigImport_1 = require("../utils/convertConfigImport");
5
- const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
6
- function generateComponentFormField({ config }) {
7
- if (!(0, runtimeTypeGuards_1.isGeneratorConfigImport)(config.component)) {
8
- throw new Error("config.component must be a GeneratorConfigImport");
9
- }
10
- const imports = [(0, convertConfigImport_1.convertConfigImport)(config.component)];
11
- const code = `<${config.component.name} />`;
12
- return {
13
- imports,
14
- formProps: [],
15
- hooksCode: "",
16
- formFragmentFields: [],
17
- formValuesConfig: [],
18
- finalFormConfig: undefined,
19
- code,
20
- gqlDocuments: {},
21
- };
22
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Generates error handling code for form submissions.
3
- * Creates errors.reduce() implementation that maps GraphQL errors to Final Form submission errors.
4
- */
5
- export declare function generateErrorHandlingCode({ mutationResponsePath, errorMessagesVariable, }: {
6
- mutationResponsePath: string;
7
- errorMessagesVariable: string;
8
- }): string;