@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.
- package/bin/admin-generator.mjs +3 -0
- package/dist/adminGenerator.d.mts +1 -0
- package/dist/adminGenerator.mjs +4441 -0
- package/dist/index.d.mts +344 -0
- package/dist/index.mjs +4440 -0
- package/package.json +31 -21
- package/bin/admin-generator.js +0 -8
- package/lib/adminGenerator.d.ts +0 -1
- package/lib/adminGenerator.js +0 -8
- package/lib/commands/generate/config/parseConfig.d.ts +0 -1
- package/lib/commands/generate/config/parseConfig.js +0 -72
- package/lib/commands/generate/config/transformConfig.d.ts +0 -7
- package/lib/commands/generate/config/transformConfig.js +0 -264
- package/lib/commands/generate/generate-command.d.ts +0 -340
- package/lib/commands/generate/generate-command.js +0 -112
- package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.d.ts +0 -26
- package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +0 -364
- package/lib/commands/generate/generateForm/extractErrorEnums.d.ts +0 -16
- package/lib/commands/generate/generateForm/extractErrorEnums.js +0 -100
- package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +0 -2
- package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +0 -22
- package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.d.ts +0 -6
- package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.js +0 -22
- package/lib/commands/generate/generateForm/formField/options.d.ts +0 -24
- package/lib/commands/generate/generateForm/formField/options.js +0 -85
- package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +0 -5
- package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -22
- package/lib/commands/generate/generateForm/generateErrorHandling.d.ts +0 -8
- package/lib/commands/generate/generateForm/generateErrorHandling.js +0 -24
- package/lib/commands/generate/generateForm/generateErrorMessages.d.ts +0 -11
- package/lib/commands/generate/generateForm/generateErrorMessages.js +0 -28
- package/lib/commands/generate/generateForm/generateFields.d.ts +0 -42
- package/lib/commands/generate/generateForm/generateFields.js +0 -87
- package/lib/commands/generate/generateForm/generateForm.d.ts +0 -14
- package/lib/commands/generate/generateForm/generateForm.js +0 -565
- package/lib/commands/generate/generateForm/generateFormField.d.ts +0 -12
- package/lib/commands/generate/generateForm/generateFormField.js +0 -368
- package/lib/commands/generate/generateForm/generateFormLayout.d.ts +0 -12
- package/lib/commands/generate/generateForm/generateFormLayout.js +0 -154
- package/lib/commands/generate/generateForm/generateFormValues.d.ts +0 -40
- package/lib/commands/generate/generateForm/generateFormValues.js +0 -219
- package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +0 -11
- package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +0 -29
- package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +0 -18
- package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +0 -79
- package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +0 -5
- package/lib/commands/generate/generateGrid/detectMuiXVersion.js +0 -32
- package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +0 -2
- package/lib/commands/generate/generateGrid/findInputObjectType.js +0 -15
- package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +0 -6
- package/lib/commands/generate/generateGrid/generateGqlFieldList.js +0 -56
- package/lib/commands/generate/generateGrid/generateGrid.d.ts +0 -16
- package/lib/commands/generate/generateGrid/generateGrid.js +0 -1017
- package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +0 -15
- package/lib/commands/generate/generateGrid/generateGridToolbar.js +0 -90
- package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +0 -13
- package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +0 -59
- package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +0 -14
- package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +0 -13
- package/lib/commands/generate/generateGrid/usableFields.d.ts +0 -14
- package/lib/commands/generate/generateGrid/usableFields.js +0 -3
- package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +0 -1
- package/lib/commands/generate/utils/camelCaseToHumanReadable.js +0 -7
- package/lib/commands/generate/utils/columnVisibility.d.ts +0 -6
- package/lib/commands/generate/utils/columnVisibility.js +0 -2
- package/lib/commands/generate/utils/convertConfigImport.d.ts +0 -6
- package/lib/commands/generate/utils/convertConfigImport.js +0 -14
- package/lib/commands/generate/utils/findMutationType.d.ts +0 -3
- package/lib/commands/generate/utils/findMutationType.js +0 -18
- package/lib/commands/generate/utils/findQueryType.d.ts +0 -2
- package/lib/commands/generate/utils/findQueryType.js +0 -18
- package/lib/commands/generate/utils/findRootBlocks.d.ts +0 -8
- package/lib/commands/generate/utils/findRootBlocks.js +0 -66
- package/lib/commands/generate/utils/generateGqlOperation.d.ts +0 -12
- package/lib/commands/generate/utils/generateGqlOperation.js +0 -87
- package/lib/commands/generate/utils/generateImportsCode.d.ts +0 -6
- package/lib/commands/generate/utils/generateImportsCode.js +0 -31
- package/lib/commands/generate/utils/intl.d.ts +0 -20
- package/lib/commands/generate/utils/intl.js +0 -44
- package/lib/commands/generate/utils/isFieldOptional.d.ts +0 -7
- package/lib/commands/generate/utils/isFieldOptional.js +0 -21
- package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +0 -20
- package/lib/commands/generate/utils/runtimeTypeGuards.js +0 -22
- package/lib/commands/generate/utils/writeGenerated.d.ts +0 -1
- package/lib/commands/generate/utils/writeGenerated.js +0 -123
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -6
|
@@ -1,364 +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 just find the field directly (no nested path to follow, name can be only one level deep)
|
|
100
|
-
return findIntrospectionField(introspectionObject, name);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function generateAsyncSelect({ gqlIntrospection, baseOutputFilename, config, formConfig, gqlType, namePrefix, }) {
|
|
104
|
-
var _a, _b, _c;
|
|
105
|
-
const imports = [];
|
|
106
|
-
const formProps = [];
|
|
107
|
-
const { name, fieldLabel, startAdornment,
|
|
108
|
-
//endAdornment,
|
|
109
|
-
imports: optionsImports, } = (0, options_1.buildFormFieldOptions)({ config, formConfig });
|
|
110
|
-
imports.push(...optionsImports);
|
|
111
|
-
const nameWithPrefix = `${namePrefix ? `${namePrefix}.` : ``}${name}`;
|
|
112
|
-
const required = !(0, isFieldOptional_1.isFieldOptional)({ config, gqlIntrospection, gqlType });
|
|
113
|
-
const formValueConfig = {
|
|
114
|
-
fieldName: name,
|
|
115
|
-
destructFromFormValues: config.type == "asyncSelectFilter",
|
|
116
|
-
};
|
|
117
|
-
let finalFormConfig;
|
|
118
|
-
let code = "";
|
|
119
|
-
const { objectType, multiple } = findIntrospectionObjectType({
|
|
120
|
-
config,
|
|
121
|
-
gqlIntrospection,
|
|
122
|
-
gqlType,
|
|
123
|
-
});
|
|
124
|
-
//find labelField: 1. as configured
|
|
125
|
-
let labelField = config.labelField;
|
|
126
|
-
//find labelField: 2. common names (name or title)
|
|
127
|
-
if (!labelField) {
|
|
128
|
-
labelField = (_a = objectType.fields.find((field) => {
|
|
129
|
-
let type = field.type;
|
|
130
|
-
if (type.kind == "NON_NULL")
|
|
131
|
-
type = type.ofType;
|
|
132
|
-
if ((field.name == "name" || field.name == "title") && type.kind == "SCALAR" && type.name == "String") {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
136
|
-
}
|
|
137
|
-
//find labelField: 3. first string field
|
|
138
|
-
if (!labelField) {
|
|
139
|
-
labelField = (_b = objectType.fields.find((field) => {
|
|
140
|
-
let type = field.type;
|
|
141
|
-
if (type.kind == "NON_NULL")
|
|
142
|
-
type = type.ofType;
|
|
143
|
-
if (field.type.kind == "SCALAR" && field.type.name == "String") {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
})) === null || _b === void 0 ? void 0 : _b.name;
|
|
147
|
-
}
|
|
148
|
-
const rootQuery = config.rootQuery; //TODO we should infer a default value from the gql schema
|
|
149
|
-
const queryName = `${rootQuery[0].toUpperCase() + rootQuery.substring(1)}Select`;
|
|
150
|
-
const rootQueryType = (0, findQueryType_1.findQueryTypeOrThrow)(rootQuery, gqlIntrospection);
|
|
151
|
-
let formFragmentFields;
|
|
152
|
-
if (config.type == "asyncSelectFilter") {
|
|
153
|
-
formFragmentFields = [`${config.loadValueQueryField}.id`, `${config.loadValueQueryField}.${labelField}`];
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
formFragmentFields = [`${name}.id`, `${name}.${labelField}`];
|
|
157
|
-
}
|
|
158
|
-
const rootQueryHasSearchArg = rootQueryType.args.find((arg) => arg.name === "search");
|
|
159
|
-
const useAutocomplete = (_c = config.autocomplete) !== null && _c !== void 0 ? _c : !!rootQueryHasSearchArg;
|
|
160
|
-
if (useAutocomplete) {
|
|
161
|
-
if (!rootQueryHasSearchArg) {
|
|
162
|
-
throw new Error(`Field ${String(config.name)}: Autocomplete is enabled but root query "${rootQuery}" has no search argument.`);
|
|
163
|
-
}
|
|
164
|
-
if (rootQueryHasSearchArg.type.kind !== "SCALAR" || rootQueryHasSearchArg.type.name !== "String") {
|
|
165
|
-
throw new Error(`Field ${String(config.name)}: Autocomplete is enabled but root query "${rootQuery}" has search argument that is not a string.`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const filterConfig = config.filter
|
|
169
|
-
? (() => {
|
|
170
|
-
var _a;
|
|
171
|
-
let filterField;
|
|
172
|
-
let rootQueryArg = config.filter.rootQueryArg;
|
|
173
|
-
let filterVar = "";
|
|
174
|
-
if (config.filter.type === "field") {
|
|
175
|
-
filterField = (0, generateFields_1.findFieldByName)(config.filter.formFieldName, formConfig.fields);
|
|
176
|
-
if (!filterField) {
|
|
177
|
-
throw new Error(`Field ${String(config.name)}: No field with name "${config.filter.formFieldName}" referenced as filter.formFieldName found in form-config.`);
|
|
178
|
-
}
|
|
179
|
-
if (!(0, generate_command_1.isFormFieldConfig)(filterField)) {
|
|
180
|
-
throw new Error(`Field ${String(config.name)}: Field with name "${config.filter.formFieldName}" referenced as filter.formFieldName is no FormField.`);
|
|
181
|
-
}
|
|
182
|
-
filterVar = `values.${filterField.type === "asyncSelect" || filterField.type === "asyncSelectFilter" ? `${String(filterField.name)}?.id` : String(filterField.name)}`;
|
|
183
|
-
if (!rootQueryArg) {
|
|
184
|
-
rootQueryArg = config.filter.formFieldName;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else if (config.filter.type === "formProp") {
|
|
188
|
-
filterVar = config.filter.propName;
|
|
189
|
-
if (!rootQueryArg) {
|
|
190
|
-
rootQueryArg = config.filter.propName;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
throw new Error("unsupported filter type");
|
|
195
|
-
}
|
|
196
|
-
// try to find arg used to filter by checking names of root-arg and filter-arg-fields
|
|
197
|
-
const rootArgForName = rootQueryType.args.find((arg) => arg.name === rootQueryArg);
|
|
198
|
-
let filterType = rootArgForName ? buildTypeInfo(rootArgForName, gqlIntrospection) : undefined;
|
|
199
|
-
let filterVarName = undefined;
|
|
200
|
-
let filterVarValue = undefined;
|
|
201
|
-
let filterVarType = "unknown";
|
|
202
|
-
if (filterType) {
|
|
203
|
-
// there is a query root arg with same name, filter using it
|
|
204
|
-
filterVarName = rootQueryArg;
|
|
205
|
-
filterVarValue = filterVar;
|
|
206
|
-
if (filterType.typeKind === "INPUT_OBJECT" || filterType.typeKind === "ENUM") {
|
|
207
|
-
filterVarType = `GQL${filterType.typeClass}`;
|
|
208
|
-
imports.push({
|
|
209
|
-
name: filterVarType,
|
|
210
|
-
importPath: "@src/graphql.generated",
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else if (filterType.typeKind === "SCALAR") {
|
|
214
|
-
filterVarType = gqlScalarToTypescriptType(filterType.typeClass);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
// no root-arg with same name, check filter-arg-fields
|
|
219
|
-
const rootArgFilter = rootQueryType.args.find((arg) => arg.name === "filter");
|
|
220
|
-
filterType = rootArgFilter ? buildTypeInfo(rootArgFilter, gqlIntrospection) : undefined;
|
|
221
|
-
if (filterType) {
|
|
222
|
-
filterVarName = "filter";
|
|
223
|
-
filterVarValue = `{ ${rootQueryArg}: { equal: ${filterVar} } }`;
|
|
224
|
-
// get type of field.equal in filter-arg used for filtering
|
|
225
|
-
if (((_a = filterType.inputType) === null || _a === void 0 ? void 0 : _a.kind) !== "INPUT_OBJECT") {
|
|
226
|
-
throw new Error(`Field ${String(config.name)}: Type of filter is no object-type.`);
|
|
227
|
-
}
|
|
228
|
-
const nestedFilterInput = filterType.inputType.inputFields.find((inputField) => inputField.name === rootQueryArg);
|
|
229
|
-
if (!nestedFilterInput) {
|
|
230
|
-
throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg} does not exist`);
|
|
231
|
-
}
|
|
232
|
-
const gqlFilterInputType = buildTypeInfo(nestedFilterInput, gqlIntrospection);
|
|
233
|
-
if (!(gqlFilterInputType === null || gqlFilterInputType === void 0 ? void 0 : gqlFilterInputType.inputType) || gqlFilterInputType.inputType.kind !== "INPUT_OBJECT") {
|
|
234
|
-
throw new Error(`Field ${String(config.name)}: Type of filter.${rootQueryArg} is no object-type, but needs to be e.g. StringFilter-type.`);
|
|
235
|
-
}
|
|
236
|
-
const gqlFilterEqualInputType = gqlFilterInputType.inputType.inputFields.find((inputField) => inputField.name === "equal");
|
|
237
|
-
if (!gqlFilterEqualInputType) {
|
|
238
|
-
throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg}.equal does not exist`);
|
|
239
|
-
}
|
|
240
|
-
const equalFieldType = buildTypeInfo(gqlFilterEqualInputType, gqlIntrospection);
|
|
241
|
-
if (!equalFieldType) {
|
|
242
|
-
throw new Error(`Field ${String(config.name)}: Field filter.${rootQueryArg}.equal does not exist but is required for filtering.`);
|
|
243
|
-
}
|
|
244
|
-
if (equalFieldType.typeKind === "INPUT_OBJECT" || equalFieldType.typeKind === "ENUM") {
|
|
245
|
-
filterVarType = `GQL${equalFieldType.typeClass}`;
|
|
246
|
-
imports.push({
|
|
247
|
-
name: filterVarType,
|
|
248
|
-
importPath: "@src/graphql.generated",
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
else if (equalFieldType.typeKind === "SCALAR") {
|
|
252
|
-
filterVarType = gqlScalarToTypescriptType(equalFieldType.typeClass);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
throw new Error(`Neither filter-prop nor root-prop with name: ${rootQueryArg} for asyncSelect-query not found. Consider setting filterField.gqlVarName explicitly.`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (config.filter.type === "formProp") {
|
|
260
|
-
formProps.push({
|
|
261
|
-
name: config.filter.propName,
|
|
262
|
-
optional: false,
|
|
263
|
-
type: filterVarType,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
filterField,
|
|
268
|
-
filterType,
|
|
269
|
-
filterVarName,
|
|
270
|
-
filterVarValue,
|
|
271
|
-
};
|
|
272
|
-
})()
|
|
273
|
-
: undefined;
|
|
274
|
-
if (filterConfig) {
|
|
275
|
-
imports.push({ name: "OnChangeField", importPath: "@comet/admin" });
|
|
276
|
-
finalFormConfig = { subscription: { values: true }, renderProps: { values: true, form: true } };
|
|
277
|
-
}
|
|
278
|
-
if (config.type != "asyncSelectFilter") {
|
|
279
|
-
if (!multiple) {
|
|
280
|
-
if (!required) {
|
|
281
|
-
formValueConfig.formValueToGqlInputCode = `$fieldName ? $fieldName.id : null`;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
formValueConfig.formValueToGqlInputCode = `$fieldName?.id`;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
formValueConfig.formValueToGqlInputCode = `$fieldName.map((item) => item.id)`;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
imports.push({
|
|
292
|
-
name: `GQL${queryName}Query`,
|
|
293
|
-
importPath: `./${baseOutputFilename}.generated`,
|
|
294
|
-
});
|
|
295
|
-
imports.push({
|
|
296
|
-
name: `GQL${queryName}QueryVariables`,
|
|
297
|
-
importPath: `./${baseOutputFilename}.generated`,
|
|
298
|
-
});
|
|
299
|
-
if (useAutocomplete) {
|
|
300
|
-
imports.push({ name: "AsyncAutocompleteField", importPath: "@comet/admin" });
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
imports.push({ name: "AsyncSelectField", importPath: "@comet/admin" });
|
|
304
|
-
}
|
|
305
|
-
const instanceGqlType = gqlType[0].toLowerCase() + gqlType.substring(1);
|
|
306
|
-
if (config.type == "asyncSelectFilter") {
|
|
307
|
-
// add (in the gql schema) non existing value for virtual filter field
|
|
308
|
-
formValueConfig.typeCode = { nullable: true, type: `{ id: string; ${labelField}: string }` };
|
|
309
|
-
formValueConfig.initializationCode = `data.${instanceGqlType}.${config.loadValueQueryField.replace(/\./g, "?.")}`;
|
|
310
|
-
}
|
|
311
|
-
code = `<${useAutocomplete ? "AsyncAutocompleteField" : "AsyncSelectField"}
|
|
312
|
-
${required ? "required" : ""}
|
|
313
|
-
variant="horizontal"
|
|
314
|
-
fullWidth
|
|
315
|
-
${config.readOnly ? "readOnly disabled" : ""}
|
|
316
|
-
${multiple ? "multiple" : ""}
|
|
317
|
-
name="${nameWithPrefix}"
|
|
318
|
-
label={${fieldLabel}}
|
|
319
|
-
${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
|
|
320
|
-
loadOptions={async (${useAutocomplete ? `search?: string` : ""}) => {
|
|
321
|
-
const { data } = await client.query<GQL${queryName}Query, GQL${queryName}QueryVariables>({
|
|
322
|
-
query: gql\`${(0, generateGqlOperation_1.generateGqlOperation)({
|
|
323
|
-
type: "query",
|
|
324
|
-
operationName: queryName,
|
|
325
|
-
rootOperation: rootQuery,
|
|
326
|
-
fields: ["nodes.id", `nodes.${labelField}`],
|
|
327
|
-
variables: [
|
|
328
|
-
useAutocomplete ? { name: "search", type: "String" } : undefined,
|
|
329
|
-
filterConfig
|
|
330
|
-
? {
|
|
331
|
-
name: filterConfig.filterVarName,
|
|
332
|
-
type: filterConfig.filterType.typeClass + (filterConfig.filterType.required ? `!` : ``),
|
|
333
|
-
}
|
|
334
|
-
: undefined,
|
|
335
|
-
].filter((v) => v !== undefined),
|
|
336
|
-
})}\`${filterConfig || useAutocomplete ? ", variables: { " : ""}
|
|
337
|
-
${filterConfig ? `${filterConfig.filterVarName}: ${filterConfig.filterVarValue},` : ``}
|
|
338
|
-
${useAutocomplete ? `search,` : ``}
|
|
339
|
-
${filterConfig || useAutocomplete ? " }" : ""}
|
|
340
|
-
});
|
|
341
|
-
return data.${rootQuery}.nodes;
|
|
342
|
-
}}
|
|
343
|
-
getOptionLabel={(option) => option.${labelField}}
|
|
344
|
-
${(filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.filterField) ? `disabled={!values?.${String(filterConfig.filterField.name)}}` : ``}
|
|
345
|
-
/>${(filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.filterField)
|
|
346
|
-
? `<OnChangeField name="${String(filterConfig.filterField.name)}">
|
|
347
|
-
{(value, previousValue) => {
|
|
348
|
-
if (value.id !== previousValue.id) {
|
|
349
|
-
form.change("${String(config.name)}", undefined);
|
|
350
|
-
}
|
|
351
|
-
}}
|
|
352
|
-
</OnChangeField>`
|
|
353
|
-
: ``}`;
|
|
354
|
-
return {
|
|
355
|
-
code,
|
|
356
|
-
hooksCode: "",
|
|
357
|
-
formFragmentFields,
|
|
358
|
-
gqlDocuments: {},
|
|
359
|
-
imports,
|
|
360
|
-
formProps,
|
|
361
|
-
formValuesConfig: [formValueConfig],
|
|
362
|
-
finalFormConfig,
|
|
363
|
-
};
|
|
364
|
-
}
|
|
@@ -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,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,6 +0,0 @@
|
|
|
1
|
-
import { type IntrospectionQuery } from "graphql";
|
|
2
|
-
export declare function findIntrospectionFieldType({ name, gqlType, gqlIntrospection, }: {
|
|
3
|
-
name: string;
|
|
4
|
-
gqlType: string;
|
|
5
|
-
gqlIntrospection: IntrospectionQuery;
|
|
6
|
-
}): import("graphql").IntrospectionNamedTypeRef<import("graphql").IntrospectionOutputType> | import("graphql").IntrospectionListTypeRef<import("graphql").IntrospectionOutputTypeRef> | undefined;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findIntrospectionFieldType = findIntrospectionFieldType;
|
|
4
|
-
function findIntrospectionFieldType({ name, gqlType, gqlIntrospection, }) {
|
|
5
|
-
let introspectionFieldType;
|
|
6
|
-
for (const namePart of name.split(".")) {
|
|
7
|
-
const introspectionObject = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
|
|
8
|
-
if (!introspectionObject)
|
|
9
|
-
throw new Error(`didn't find object ${gqlType} in gql introspection`);
|
|
10
|
-
const introspectionField = introspectionObject.fields.find((field) => field.name === namePart);
|
|
11
|
-
introspectionFieldType = introspectionField
|
|
12
|
-
? introspectionField.type.kind === "NON_NULL"
|
|
13
|
-
? introspectionField.type.ofType
|
|
14
|
-
: introspectionField.type
|
|
15
|
-
: undefined;
|
|
16
|
-
if ((introspectionFieldType === null || introspectionFieldType === void 0 ? void 0 : introspectionFieldType.kind) === "OBJECT") {
|
|
17
|
-
// for next loop iteration (nested fields)
|
|
18
|
-
gqlType = introspectionFieldType.name;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return introspectionFieldType;
|
|
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
|
-
}
|