@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,340 +0,0 @@
|
|
|
1
|
-
import { type ApolloClient } from "@apollo/client";
|
|
2
|
-
import { type GridColDef } from "@comet/admin";
|
|
3
|
-
import { type IconName } from "@comet/admin-icons";
|
|
4
|
-
import { type BlockInterface, type ContentScope, type FinalFormFileUploadProps } from "@comet/cms-admin";
|
|
5
|
-
import { type IconProps } from "@mui/material";
|
|
6
|
-
import { type GridCellParams, type GridFilterItem, type GridFilterOperator, type GridRenderCellParams, type GridSortDirection, type GridValidRowModel } from "@mui/x-data-grid";
|
|
7
|
-
import { Command } from "commander";
|
|
8
|
-
import { type FieldValidator, type FormApi } from "final-form";
|
|
9
|
-
import type { ComponentType, ReactElement } from "react";
|
|
10
|
-
import type { FormattedMessage, MessageDescriptor } from "react-intl";
|
|
11
|
-
import { type UsableFields, type UsableFormFields } from "./generateGrid/usableFields";
|
|
12
|
-
import { type ColumnVisibleOption } from "./utils/columnVisibility";
|
|
13
|
-
export type FormattedMessageElement = ReactElement<MessageDescriptor, typeof FormattedMessage>;
|
|
14
|
-
type IconObject = Pick<IconProps, "color" | "fontSize"> & {
|
|
15
|
-
name: IconName;
|
|
16
|
-
};
|
|
17
|
-
type Icon = IconName | IconObject | ComponentType;
|
|
18
|
-
export type Adornment = string | {
|
|
19
|
-
icon: Icon;
|
|
20
|
-
};
|
|
21
|
-
type InputBaseFieldConfig = {
|
|
22
|
-
startAdornment?: Adornment;
|
|
23
|
-
endAdornment?: Adornment;
|
|
24
|
-
};
|
|
25
|
-
export type ComponentFormFieldConfig = {
|
|
26
|
-
type: "component";
|
|
27
|
-
component: ComponentType;
|
|
28
|
-
};
|
|
29
|
-
export type StaticSelectValue = {
|
|
30
|
-
value: string;
|
|
31
|
-
label: string | FormattedMessageElement;
|
|
32
|
-
} | string;
|
|
33
|
-
type AsyncSelectFilter = {
|
|
34
|
-
/**
|
|
35
|
-
* Filter by value of field in current form
|
|
36
|
-
*/
|
|
37
|
-
type: "field";
|
|
38
|
-
/**
|
|
39
|
-
* Name of the field in current form, that will be used to filter the query
|
|
40
|
-
*/
|
|
41
|
-
formFieldName: string;
|
|
42
|
-
/**
|
|
43
|
-
* Name of the graphql argument the prop will be applied to. Defaults to propdName.
|
|
44
|
-
*
|
|
45
|
-
* Root Argument or filter argument are supported.
|
|
46
|
-
*/
|
|
47
|
-
rootQueryArg?: string;
|
|
48
|
-
} | {
|
|
49
|
-
/**
|
|
50
|
-
* Filter by a prop passed into the form, this prop will be generated
|
|
51
|
-
*/
|
|
52
|
-
type: "formProp";
|
|
53
|
-
/**
|
|
54
|
-
* Name of the prop generated for this form
|
|
55
|
-
*/
|
|
56
|
-
propName: 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
|
-
export type FormFieldConfig<T> = (({
|
|
65
|
-
type: "text";
|
|
66
|
-
name: UsableFormFields<T>;
|
|
67
|
-
multiline?: boolean;
|
|
68
|
-
initialValue?: string;
|
|
69
|
-
} & InputBaseFieldConfig) | ({
|
|
70
|
-
type: "number";
|
|
71
|
-
name: UsableFormFields<T>;
|
|
72
|
-
decimals?: number;
|
|
73
|
-
initialValue?: number;
|
|
74
|
-
} & InputBaseFieldConfig) | ({
|
|
75
|
-
type: "numberRange";
|
|
76
|
-
name: UsableFormFields<T>;
|
|
77
|
-
minValue: number;
|
|
78
|
-
maxValue: number;
|
|
79
|
-
disableSlider?: boolean;
|
|
80
|
-
initialValue?: {
|
|
81
|
-
min: number;
|
|
82
|
-
max: number;
|
|
83
|
-
};
|
|
84
|
-
} & InputBaseFieldConfig) | {
|
|
85
|
-
type: "boolean";
|
|
86
|
-
name: UsableFormFields<T>;
|
|
87
|
-
initialValue?: boolean;
|
|
88
|
-
checkboxLabel?: string | FormattedMessageElement;
|
|
89
|
-
} | ({
|
|
90
|
-
type: "date";
|
|
91
|
-
name: UsableFormFields<T>;
|
|
92
|
-
initialValue?: string;
|
|
93
|
-
} & InputBaseFieldConfig) | ({
|
|
94
|
-
type: "dateTime";
|
|
95
|
-
name: UsableFormFields<T>;
|
|
96
|
-
initialValue?: Date;
|
|
97
|
-
} & InputBaseFieldConfig) | ({
|
|
98
|
-
type: "staticSelect";
|
|
99
|
-
name: UsableFormFields<T>;
|
|
100
|
-
values?: StaticSelectValue[];
|
|
101
|
-
inputType?: "select" | "radio";
|
|
102
|
-
initialValue?: string;
|
|
103
|
-
} & Omit<InputBaseFieldConfig, "endAdornment">) | ({
|
|
104
|
-
type: "asyncSelect";
|
|
105
|
-
name: UsableFormFields<T>;
|
|
106
|
-
rootQuery: string;
|
|
107
|
-
labelField?: string;
|
|
108
|
-
/** Whether Autocomplete or Select should be used.
|
|
109
|
-
*
|
|
110
|
-
* defaults to true if rootQuery has a search argument
|
|
111
|
-
*/
|
|
112
|
-
autocomplete?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* filter for query, passed as variable to graphql query
|
|
115
|
-
*/
|
|
116
|
-
filter?: AsyncSelectFilter;
|
|
117
|
-
} & Omit<InputBaseFieldConfig, "endAdornment">) | ({
|
|
118
|
-
type: "asyncSelectFilter";
|
|
119
|
-
name: string;
|
|
120
|
-
loadValueQueryField: string;
|
|
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: "block";
|
|
134
|
-
name: UsableFormFields<T>;
|
|
135
|
-
block: BlockInterface;
|
|
136
|
-
} | ({
|
|
137
|
-
type: "fileUpload";
|
|
138
|
-
multiple?: false;
|
|
139
|
-
name: UsableFormFields<T>;
|
|
140
|
-
maxFiles?: 1;
|
|
141
|
-
download?: boolean;
|
|
142
|
-
} & Pick<Partial<FinalFormFileUploadProps<false>>, "maxFileSize" | "readOnly" | "layout" | "accept">) | ({
|
|
143
|
-
type: "fileUpload";
|
|
144
|
-
multiple: true;
|
|
145
|
-
name: UsableFormFields<T>;
|
|
146
|
-
maxFiles?: number;
|
|
147
|
-
download?: boolean;
|
|
148
|
-
} & Pick<Partial<FinalFormFileUploadProps<true>>, "maxFileSize" | "readOnly" | "layout" | "accept">)) & {
|
|
149
|
-
label?: string | FormattedMessageElement;
|
|
150
|
-
required?: boolean;
|
|
151
|
-
validate?: FieldValidator<unknown>;
|
|
152
|
-
helperText?: string | FormattedMessageElement;
|
|
153
|
-
readOnly?: boolean;
|
|
154
|
-
};
|
|
155
|
-
export declare function isFormFieldConfig<T>(arg: any): arg is FormFieldConfig<T>;
|
|
156
|
-
type OptionalNestedFieldsConfig<T> = {
|
|
157
|
-
type: "optionalNestedFields";
|
|
158
|
-
name: UsableFormFields<T>;
|
|
159
|
-
checkboxLabel?: string | FormattedMessageElement;
|
|
160
|
-
fields: FormFieldConfig<any>[];
|
|
161
|
-
};
|
|
162
|
-
export type FormLayoutConfig<T> = {
|
|
163
|
-
type: "fieldSet";
|
|
164
|
-
name: string;
|
|
165
|
-
title?: string | FormattedMessageElement;
|
|
166
|
-
supportText?: string;
|
|
167
|
-
collapsible?: boolean;
|
|
168
|
-
initiallyExpanded?: boolean;
|
|
169
|
-
fields: (FormFieldConfig<T> | OptionalNestedFieldsConfig<T> | ComponentFormFieldConfig)[];
|
|
170
|
-
} | OptionalNestedFieldsConfig<T>;
|
|
171
|
-
export declare function isFormLayoutConfig<T>(arg: any): arg is FormLayoutConfig<T>;
|
|
172
|
-
export type FormConfig<T extends {
|
|
173
|
-
__typename?: string;
|
|
174
|
-
}> = {
|
|
175
|
-
type: "form";
|
|
176
|
-
gqlType: T["__typename"];
|
|
177
|
-
mode?: "edit" | "add" | "all";
|
|
178
|
-
fragmentName?: string;
|
|
179
|
-
createMutation?: string;
|
|
180
|
-
/**
|
|
181
|
-
* If true, scope will be passed as prop, if false scope will be fetched from ContentScopeContext
|
|
182
|
-
* @default false
|
|
183
|
-
*/
|
|
184
|
-
scopeAsProp?: boolean;
|
|
185
|
-
fields: (FormFieldConfig<T> | FormLayoutConfig<T> | ComponentFormFieldConfig)[];
|
|
186
|
-
/**
|
|
187
|
-
* If true, the form will navigate to the edit page using stackSwitchApi.activatePage of the newly created item after a successful creation.
|
|
188
|
-
* @default true
|
|
189
|
-
*/
|
|
190
|
-
navigateOnCreate?: boolean;
|
|
191
|
-
/**
|
|
192
|
-
* If true, the generated form will have an initialValues prop to set initial form values.
|
|
193
|
-
* @default false
|
|
194
|
-
*/
|
|
195
|
-
initialValuesAsProp?: boolean;
|
|
196
|
-
};
|
|
197
|
-
export type InjectedFormVariables = {
|
|
198
|
-
id?: string;
|
|
199
|
-
mode?: "edit" | "add";
|
|
200
|
-
client: ApolloClient<object>;
|
|
201
|
-
formApi: FormApi<unknown, Partial<unknown>>;
|
|
202
|
-
scope: ContentScope;
|
|
203
|
-
};
|
|
204
|
-
export declare function injectFormVariables<T>(fn: (injectedVariables: InjectedFormVariables) => T): T;
|
|
205
|
-
type BaseColumnConfig = Pick<GridColDef, "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
|
|
206
|
-
headerName?: string | FormattedMessageElement;
|
|
207
|
-
headerInfoTooltip?: string | FormattedMessageElement;
|
|
208
|
-
visible?: ColumnVisibleOption;
|
|
209
|
-
fieldName?: string;
|
|
210
|
-
};
|
|
211
|
-
export type GridColumnStaticSelectLabelCellContent = {
|
|
212
|
-
primaryText?: string | FormattedMessageElement;
|
|
213
|
-
secondaryText?: string | FormattedMessageElement;
|
|
214
|
-
icon?: Icon;
|
|
215
|
-
};
|
|
216
|
-
export type GridColumnStaticSelectValue = StaticSelectValue | {
|
|
217
|
-
value: string | number | boolean;
|
|
218
|
-
label: string | FormattedMessageElement | GridColumnStaticSelectLabelCellContent;
|
|
219
|
-
} | number | boolean;
|
|
220
|
-
export type GridColumnConfig<T extends GridValidRowModel> = ({
|
|
221
|
-
type: "text";
|
|
222
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
223
|
-
} | {
|
|
224
|
-
type: "number";
|
|
225
|
-
currency?: string;
|
|
226
|
-
decimals?: number;
|
|
227
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
228
|
-
} | {
|
|
229
|
-
type: "boolean";
|
|
230
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
231
|
-
} | {
|
|
232
|
-
type: "date";
|
|
233
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
234
|
-
} | {
|
|
235
|
-
type: "dateTime";
|
|
236
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
237
|
-
} | {
|
|
238
|
-
type: "staticSelect";
|
|
239
|
-
values?: GridColumnStaticSelectValue[];
|
|
240
|
-
} | {
|
|
241
|
-
type: "block";
|
|
242
|
-
block: BlockInterface;
|
|
243
|
-
} | {
|
|
244
|
-
type: "id";
|
|
245
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
246
|
-
} | {
|
|
247
|
-
type: "manyToMany";
|
|
248
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
249
|
-
queryFields?: UsableFields<T, true>[];
|
|
250
|
-
/**
|
|
251
|
-
* The field to use as label for the default renderCell implementation.
|
|
252
|
-
*/
|
|
253
|
-
labelField?: string;
|
|
254
|
-
} | {
|
|
255
|
-
type: "oneToMany";
|
|
256
|
-
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
257
|
-
queryFields?: UsableFields<T, true>[];
|
|
258
|
-
/**
|
|
259
|
-
* The field to use as label for the default renderCell implementation.
|
|
260
|
-
*/
|
|
261
|
-
labelField?: string;
|
|
262
|
-
}) & {
|
|
263
|
-
name: UsableFields<T>;
|
|
264
|
-
filterOperators?: GridFilterOperator[];
|
|
265
|
-
} & BaseColumnConfig;
|
|
266
|
-
export type ActionsGridColumnConfig<T> = {
|
|
267
|
-
type: "actions";
|
|
268
|
-
queryFields?: UsableFields<T, true>[];
|
|
269
|
-
component?: ComponentType<GridCellParams>;
|
|
270
|
-
} & BaseColumnConfig;
|
|
271
|
-
export type VirtualGridColumnConfig<T extends GridValidRowModel> = {
|
|
272
|
-
type: "virtual";
|
|
273
|
-
name: string;
|
|
274
|
-
queryFields?: UsableFields<T, true>[];
|
|
275
|
-
renderCell: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
276
|
-
} & Pick<GridColDef, "sortBy"> & BaseColumnConfig;
|
|
277
|
-
type InitialFilterConfig = {
|
|
278
|
-
items: GridFilterItem[];
|
|
279
|
-
linkOperator?: "and" | "or";
|
|
280
|
-
};
|
|
281
|
-
type GridConfigGridColumnDef<T extends {
|
|
282
|
-
__typename?: string;
|
|
283
|
-
}> = GridColumnConfig<T> | ActionsGridColumnConfig<T> | VirtualGridColumnConfig<T>;
|
|
284
|
-
export type GridConfig<T extends {
|
|
285
|
-
__typename?: string;
|
|
286
|
-
}> = {
|
|
287
|
-
type: "grid";
|
|
288
|
-
gqlType: T["__typename"];
|
|
289
|
-
fragmentName?: string;
|
|
290
|
-
query?: string;
|
|
291
|
-
queryParamsPrefix?: string;
|
|
292
|
-
columns: Array<GridConfigGridColumnDef<T>>;
|
|
293
|
-
excelExport?: boolean;
|
|
294
|
-
add?: boolean;
|
|
295
|
-
edit?: boolean;
|
|
296
|
-
delete?: boolean;
|
|
297
|
-
readOnly?: boolean;
|
|
298
|
-
initialSort?: Array<{
|
|
299
|
-
field: string;
|
|
300
|
-
sort: GridSortDirection;
|
|
301
|
-
}>;
|
|
302
|
-
initialFilter?: InitialFilterConfig;
|
|
303
|
-
filterProp?: boolean;
|
|
304
|
-
toolbar?: boolean;
|
|
305
|
-
toolbarActionProp?: boolean;
|
|
306
|
-
newEntryText?: string | FormattedMessageElement;
|
|
307
|
-
rowActionProp?: boolean;
|
|
308
|
-
selectionProps?: "multiSelect" | "singleSelect";
|
|
309
|
-
rowReordering?: {
|
|
310
|
-
enabled: boolean;
|
|
311
|
-
dragPreviewField?: UsableFields<T>;
|
|
312
|
-
};
|
|
313
|
-
/**
|
|
314
|
-
* If true, scope will be passed as prop, if false scope will be fetched from ContentScopeContext
|
|
315
|
-
* @default false
|
|
316
|
-
*/
|
|
317
|
-
scopeAsProp?: boolean;
|
|
318
|
-
density?: "comfortable" | "compact" | "standard";
|
|
319
|
-
crudContextMenu?: {
|
|
320
|
-
deleteType?: "delete" | "remove";
|
|
321
|
-
deleteText?: string;
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
export type GeneratorConfig<T extends {
|
|
325
|
-
__typename?: string;
|
|
326
|
-
}> = FormConfig<T> | GridConfig<T>;
|
|
327
|
-
export declare function defineConfig<T extends {
|
|
328
|
-
__typename?: string;
|
|
329
|
-
}>(config: GeneratorConfig<T>): GeneratorConfig<T>;
|
|
330
|
-
type GQLDocumentConfig = {
|
|
331
|
-
document: string;
|
|
332
|
-
export: boolean;
|
|
333
|
-
};
|
|
334
|
-
export type GQLDocumentConfigMap = Record<string, GQLDocumentConfig>;
|
|
335
|
-
export type GeneratorReturn = {
|
|
336
|
-
code: string;
|
|
337
|
-
gqlDocuments: GQLDocumentConfigMap;
|
|
338
|
-
};
|
|
339
|
-
export declare const generateCommand: Command;
|
|
340
|
-
export {};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.generateCommand = void 0;
|
|
13
|
-
exports.isFormFieldConfig = isFormFieldConfig;
|
|
14
|
-
exports.isFormLayoutConfig = isFormLayoutConfig;
|
|
15
|
-
exports.injectFormVariables = injectFormVariables;
|
|
16
|
-
exports.defineConfig = defineConfig;
|
|
17
|
-
const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
18
|
-
const load_1 = require("@graphql-tools/load");
|
|
19
|
-
const child_process_1 = require("child_process");
|
|
20
|
-
const commander_1 = require("commander");
|
|
21
|
-
const fs_1 = require("fs");
|
|
22
|
-
const glob_1 = require("glob");
|
|
23
|
-
const graphql_1 = require("graphql");
|
|
24
|
-
const path_1 = require("path");
|
|
25
|
-
const util_1 = require("util");
|
|
26
|
-
const parseConfig_1 = require("./config/parseConfig");
|
|
27
|
-
const generateForm_1 = require("./generateForm/generateForm");
|
|
28
|
-
const generateGrid_1 = require("./generateGrid/generateGrid");
|
|
29
|
-
const writeGenerated_1 = require("./utils/writeGenerated");
|
|
30
|
-
const exec = (0, util_1.promisify)(child_process_1.exec);
|
|
31
|
-
function isComponentFormFieldConfig(arg) {
|
|
32
|
-
return arg && arg.type === "component";
|
|
33
|
-
}
|
|
34
|
-
function isFormFieldConfig(arg) {
|
|
35
|
-
return !isFormLayoutConfig(arg) && !isComponentFormFieldConfig(arg);
|
|
36
|
-
}
|
|
37
|
-
function isFormLayoutConfig(arg) {
|
|
38
|
-
return arg.type !== undefined && ["fieldSet", "optionalNestedFields"].includes(arg.type);
|
|
39
|
-
}
|
|
40
|
-
function injectFormVariables(fn) {
|
|
41
|
-
// this function is only used in config but never called at runtime
|
|
42
|
-
return fn({});
|
|
43
|
-
}
|
|
44
|
-
function defineConfig(config) {
|
|
45
|
-
return config;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @experimental
|
|
49
|
-
*/
|
|
50
|
-
function runGenerate() {
|
|
51
|
-
return __awaiter(this, arguments, void 0, function* (filePattern = "src/**/*.cometGen.{ts,tsx}") {
|
|
52
|
-
var _a;
|
|
53
|
-
const schema = yield (0, load_1.loadSchema)("./schema.gql", {
|
|
54
|
-
loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
|
|
55
|
-
});
|
|
56
|
-
const gqlIntrospection = (0, graphql_1.introspectionFromSchema)(schema);
|
|
57
|
-
const writtenFiles = [];
|
|
58
|
-
const files = yield (0, glob_1.glob)(filePattern);
|
|
59
|
-
for (const file of files) {
|
|
60
|
-
let outputCode = "";
|
|
61
|
-
let gqlDocumentsOutputCode = "";
|
|
62
|
-
const targetDirectory = `${(0, path_1.dirname)(file)}/generated`;
|
|
63
|
-
const baseOutputFilename = (0, path_1.basename)(file).replace(/\.cometGen\.tsx?$/, "");
|
|
64
|
-
console.log(`generating ${file}`);
|
|
65
|
-
const config = yield (0, parseConfig_1.parseConfig)(file);
|
|
66
|
-
const codeOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.tsx?$/, ""))}.tsx`;
|
|
67
|
-
yield fs_1.promises.rm(codeOuputFilename, { force: true });
|
|
68
|
-
const exportName = (_a = file.match(/([^/]+)\.cometGen\.tsx?$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
69
|
-
if (!exportName)
|
|
70
|
-
throw new Error("Can not determine exportName");
|
|
71
|
-
let generated;
|
|
72
|
-
if (config.type == "form") {
|
|
73
|
-
generated = (0, generateForm_1.generateForm)({ exportName, gqlIntrospection, baseOutputFilename, targetDirectory }, config);
|
|
74
|
-
}
|
|
75
|
-
else if (config.type == "grid") {
|
|
76
|
-
generated = (0, generateGrid_1.generateGrid)({ exportName, gqlIntrospection, baseOutputFilename, targetDirectory }, config);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
throw new Error(`Unknown config type`);
|
|
80
|
-
}
|
|
81
|
-
outputCode += generated.code;
|
|
82
|
-
for (const queryName in generated.gqlDocuments) {
|
|
83
|
-
const exportStatement = generated.gqlDocuments[queryName].export ? "export " : "";
|
|
84
|
-
gqlDocumentsOutputCode += `${exportStatement} const ${queryName} = gql\`${generated.gqlDocuments[queryName].document}\`\n`;
|
|
85
|
-
}
|
|
86
|
-
yield (0, writeGenerated_1.writeGenerated)(codeOuputFilename, outputCode);
|
|
87
|
-
writtenFiles.push(codeOuputFilename);
|
|
88
|
-
if (gqlDocumentsOutputCode != "") {
|
|
89
|
-
const gqlDocumentsOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.tsx?$/, ""))}.gql.tsx`;
|
|
90
|
-
yield fs_1.promises.rm(gqlDocumentsOuputFilename, { force: true });
|
|
91
|
-
gqlDocumentsOutputCode = `import { gql } from "@apollo/client";
|
|
92
|
-
import { finalFormFileUploadFragment, finalFormFileUploadDownloadableFragment } from "@comet/cms-admin";
|
|
93
|
-
|
|
94
|
-
${gqlDocumentsOutputCode}
|
|
95
|
-
`;
|
|
96
|
-
yield (0, writeGenerated_1.writeGenerated)(gqlDocumentsOuputFilename, gqlDocumentsOutputCode);
|
|
97
|
-
writtenFiles.push(gqlDocumentsOuputFilename);
|
|
98
|
-
}
|
|
99
|
-
console.log("");
|
|
100
|
-
}
|
|
101
|
-
if (writtenFiles.length > 0) {
|
|
102
|
-
console.log("Formatting generated files...");
|
|
103
|
-
yield exec(`./node_modules/.bin/prettier --write ${writtenFiles.join(" ")}`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
exports.generateCommand = new commander_1.Command("generate")
|
|
108
|
-
.option("-f, --file <file>", "path to config file or glob pattern to generate specific files")
|
|
109
|
-
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ file: filePattern }) {
|
|
110
|
-
console.log("️️️⚠️️️⚠️️️⚠️️️ Admin Generator is still experimental and in beta phase. ⚠️️️⚠️️️⚠️️️\n\n");
|
|
111
|
-
yield runGenerate(filePattern);
|
|
112
|
-
}));
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type IntrospectionObjectType, type IntrospectionQuery } from "graphql";
|
|
2
|
-
import { type FormConfig, type FormFieldConfig } from "../../generate-command";
|
|
3
|
-
import { type GenerateFieldsReturn } from "../generateFields";
|
|
4
|
-
/**
|
|
5
|
-
* Helper that returns the introspection object type for a given form field config, supporting the special case for asyncSelectFilter
|
|
6
|
-
*/
|
|
7
|
-
export declare function findIntrospectionObjectType({ config, gqlIntrospection, gqlType, }: {
|
|
8
|
-
config: FormFieldConfig<any>;
|
|
9
|
-
gqlIntrospection: IntrospectionQuery;
|
|
10
|
-
gqlType: string;
|
|
11
|
-
}): {
|
|
12
|
-
multiple: boolean;
|
|
13
|
-
objectType: IntrospectionObjectType;
|
|
14
|
-
};
|
|
15
|
-
export declare function generateAsyncSelect({ gqlIntrospection, baseOutputFilename, config, formConfig, gqlType, namePrefix, }: {
|
|
16
|
-
gqlIntrospection: IntrospectionQuery;
|
|
17
|
-
baseOutputFilename: string;
|
|
18
|
-
config: Extract<FormFieldConfig<any>, {
|
|
19
|
-
type: "asyncSelect";
|
|
20
|
-
} | {
|
|
21
|
-
type: "asyncSelectFilter";
|
|
22
|
-
}>;
|
|
23
|
-
formConfig: FormConfig<any>;
|
|
24
|
-
gqlType: string;
|
|
25
|
-
namePrefix?: string;
|
|
26
|
-
}): GenerateFieldsReturn;
|