@comet/admin-generator 8.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +24 -0
  2. package/bin/admin-generator.js +5 -0
  3. package/lib/adminGenerator.d.ts +1 -0
  4. package/lib/adminGenerator.js +8 -0
  5. package/lib/commands/generate/generate-command.d.ts +197 -0
  6. package/lib/commands/generate/generate-command.js +114 -0
  7. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +5 -0
  8. package/lib/commands/generate/generateForm/generateComponentFormField.js +18 -0
  9. package/lib/commands/generate/generateForm/generateFields.d.ts +35 -0
  10. package/lib/commands/generate/generateForm/generateFields.js +88 -0
  11. package/lib/commands/generate/generateForm/generateForm.d.ts +13 -0
  12. package/lib/commands/generate/generateForm/generateForm.js +468 -0
  13. package/lib/commands/generate/generateForm/generateFormField.d.ts +12 -0
  14. package/lib/commands/generate/generateForm/generateFormField.js +525 -0
  15. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +12 -0
  16. package/lib/commands/generate/generateForm/generateFormLayout.js +164 -0
  17. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +19 -0
  18. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +79 -0
  19. package/lib/commands/generate/generateGrid/combinationColumn.d.ts +43 -0
  20. package/lib/commands/generate/generateGrid/combinationColumn.js +151 -0
  21. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +2 -0
  22. package/lib/commands/generate/generateGrid/findInputObjectType.js +16 -0
  23. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +5 -0
  24. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +43 -0
  25. package/lib/commands/generate/generateGrid/generateGrid.d.ts +14 -0
  26. package/lib/commands/generate/generateGrid/generateGrid.js +827 -0
  27. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +14 -0
  28. package/lib/commands/generate/generateGrid/generateGridToolbar.js +92 -0
  29. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +14 -0
  30. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +64 -0
  31. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +12 -0
  32. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +14 -0
  33. package/lib/commands/generate/generateGrid/usableFields.d.ts +8 -0
  34. package/lib/commands/generate/generateGrid/usableFields.js +2 -0
  35. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +1 -0
  36. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +8 -0
  37. package/lib/commands/generate/utils/columnVisibility.d.ts +6 -0
  38. package/lib/commands/generate/utils/columnVisibility.js +2 -0
  39. package/lib/commands/generate/utils/findMutationType.d.ts +3 -0
  40. package/lib/commands/generate/utils/findMutationType.js +19 -0
  41. package/lib/commands/generate/utils/findQueryType.d.ts +2 -0
  42. package/lib/commands/generate/utils/findQueryType.js +19 -0
  43. package/lib/commands/generate/utils/findRootBlocks.d.ts +8 -0
  44. package/lib/commands/generate/utils/findRootBlocks.js +67 -0
  45. package/lib/commands/generate/utils/generateImportsCode.d.ts +5 -0
  46. package/lib/commands/generate/utils/generateImportsCode.js +27 -0
  47. package/lib/commands/generate/utils/intl.d.ts +1 -0
  48. package/lib/commands/generate/utils/intl.js +7 -0
  49. package/lib/commands/generate/utils/isFieldOptional.d.ts +7 -0
  50. package/lib/commands/generate/utils/isFieldOptional.js +21 -0
  51. package/lib/commands/generate/utils/writeGenerated.d.ts +1 -0
  52. package/lib/commands/generate/utils/writeGenerated.js +57 -0
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +2 -0
  55. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2023, Vivid Planet Software GmbH
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ require("ts-node").register({
3
+ require: ["tsconfig-paths/register"],
4
+ });
5
+ require("../lib/adminGenerator");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const generate_command_1 = require("./commands/generate/generate-command");
5
+ const program = new commander_1.Command();
6
+ program.addCommand(generate_command_1.generateCommand);
7
+ program.addHelpText("beforeAll", `⚠️️️⚠️️️⚠️️️ Admin Generator is still experimental and in beta phase. ⚠️️️⚠️️️⚠️️️ \n\n`);
8
+ program.parse();
@@ -0,0 +1,197 @@
1
+ import { type GridColDef } from "@comet/admin";
2
+ import { type IconName } from "@comet/admin-icons";
3
+ import { type FinalFormFileUploadProps } from "@comet/cms-admin";
4
+ import { type IconProps } from "@mui/material";
5
+ import { type GridFilterItem, type GridSortDirection } from "@mui/x-data-grid";
6
+ import { Command } from "commander";
7
+ import { type GridCombinationColumnConfig } from "./generateGrid/combinationColumn";
8
+ import { type UsableFields } from "./generateGrid/usableFields";
9
+ import { type ColumnVisibleOption } from "./utils/columnVisibility";
10
+ export type ImportReference = {
11
+ name: string;
12
+ import: string;
13
+ };
14
+ type IconObject = Pick<IconProps, "color" | "fontSize"> & {
15
+ name: IconName;
16
+ };
17
+ type Icon = IconName | IconObject | ImportReference;
18
+ export type Adornment = string | {
19
+ icon: Icon;
20
+ };
21
+ type SingleFileFormFieldConfig = {
22
+ type: "fileUpload";
23
+ multiple?: false;
24
+ maxFiles?: 1;
25
+ download?: boolean;
26
+ } & Pick<Partial<FinalFormFileUploadProps<false>>, "maxFileSize" | "readOnly" | "layout" | "accept">;
27
+ type MultiFileFormFieldConfig = {
28
+ type: "fileUpload";
29
+ multiple: true;
30
+ maxFiles?: number;
31
+ download?: boolean;
32
+ } & Pick<Partial<FinalFormFileUploadProps<true>>, "maxFileSize" | "readOnly" | "layout" | "accept">;
33
+ type InputBaseFieldConfig = {
34
+ startAdornment?: Adornment;
35
+ endAdornment?: Adornment;
36
+ };
37
+ export type ComponentFormFieldConfig = {
38
+ type: "component";
39
+ component: ImportReference;
40
+ };
41
+ export type FormFieldConfig<T> = (({
42
+ type: "text";
43
+ multiline?: boolean;
44
+ } & InputBaseFieldConfig) | ({
45
+ type: "number";
46
+ } & InputBaseFieldConfig) | ({
47
+ type: "numberRange";
48
+ minValue: number;
49
+ maxValue: number;
50
+ disableSlider?: boolean;
51
+ } & InputBaseFieldConfig) | {
52
+ type: "boolean";
53
+ } | ({
54
+ type: "date";
55
+ } & InputBaseFieldConfig) | ({
56
+ type: "dateTime";
57
+ } & InputBaseFieldConfig) | ({
58
+ type: "staticSelect";
59
+ values?: Array<{
60
+ value: string;
61
+ label: string;
62
+ } | string>;
63
+ inputType?: "select" | "radio";
64
+ } & Omit<InputBaseFieldConfig, "endAdornment">) | ({
65
+ type: "asyncSelect";
66
+ rootQuery: string;
67
+ labelField?: string;
68
+ filterField?: {
69
+ name: string;
70
+ gqlName?: string;
71
+ };
72
+ } & Omit<InputBaseFieldConfig, "endAdornment">) | {
73
+ type: "block";
74
+ block: ImportReference;
75
+ } | SingleFileFormFieldConfig | MultiFileFormFieldConfig) & {
76
+ name: keyof T;
77
+ label?: string;
78
+ required?: boolean;
79
+ virtual?: boolean;
80
+ validate?: ImportReference;
81
+ helperText?: string;
82
+ readOnly?: boolean;
83
+ };
84
+ export declare function isFormFieldConfig<T>(arg: any): arg is FormFieldConfig<T>;
85
+ type OptionalNestedFieldsConfig<T> = {
86
+ type: "optionalNestedFields";
87
+ name: keyof T;
88
+ checkboxLabel?: string;
89
+ fields: FormFieldConfig<any>[];
90
+ };
91
+ export type FormLayoutConfig<T> = {
92
+ type: "fieldSet";
93
+ name: string;
94
+ title?: string;
95
+ supportText?: string;
96
+ collapsible?: boolean;
97
+ initiallyExpanded?: boolean;
98
+ fields: (FormFieldConfig<T> | OptionalNestedFieldsConfig<T> | ComponentFormFieldConfig)[];
99
+ } | OptionalNestedFieldsConfig<T>;
100
+ export declare function isFormLayoutConfig<T>(arg: any): arg is FormLayoutConfig<T>;
101
+ export type FormConfig<T extends {
102
+ __typename?: string;
103
+ }> = {
104
+ type: "form";
105
+ gqlType: T["__typename"];
106
+ mode?: "edit" | "add" | "all";
107
+ fragmentName?: string;
108
+ createMutation?: string;
109
+ fields: (FormFieldConfig<T> | FormLayoutConfig<T> | ComponentFormFieldConfig)[];
110
+ };
111
+ type TabsConfig = {
112
+ type: "tabs";
113
+ tabs: {
114
+ name: string;
115
+ content: GeneratorConfig;
116
+ }[];
117
+ };
118
+ export type BaseColumnConfig = Pick<GridColDef, "headerName" | "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
119
+ headerInfoTooltip?: string;
120
+ visible?: ColumnVisibleOption;
121
+ fieldName?: string;
122
+ };
123
+ export type StaticSelectLabelCellContent = {
124
+ primaryText?: string;
125
+ secondaryText?: string;
126
+ icon?: Icon;
127
+ };
128
+ export type GridColumnConfig<T> = ({
129
+ type: "text";
130
+ } | {
131
+ type: "number";
132
+ } | {
133
+ type: "boolean";
134
+ } | {
135
+ type: "date";
136
+ } | {
137
+ type: "dateTime";
138
+ } | {
139
+ type: "staticSelect";
140
+ values?: Array<{
141
+ value: string;
142
+ label: string | StaticSelectLabelCellContent;
143
+ } | string>;
144
+ } | {
145
+ type: "block";
146
+ block: ImportReference;
147
+ }) & {
148
+ name: UsableFields<T>;
149
+ filterOperators?: ImportReference;
150
+ } & BaseColumnConfig;
151
+ export type ActionsGridColumnConfig = {
152
+ type: "actions";
153
+ component?: ImportReference;
154
+ } & BaseColumnConfig;
155
+ type InitialFilterConfig = {
156
+ items: GridFilterItem[];
157
+ linkOperator?: "and" | "or";
158
+ };
159
+ export type GridConfig<T extends {
160
+ __typename?: string;
161
+ }> = {
162
+ type: "grid";
163
+ gqlType: T["__typename"];
164
+ fragmentName?: string;
165
+ query?: string;
166
+ queryParamsPrefix?: string;
167
+ columns: Array<GridColumnConfig<T> | GridCombinationColumnConfig<UsableFields<T>> | ActionsGridColumnConfig>;
168
+ excelExport?: boolean;
169
+ add?: boolean;
170
+ edit?: boolean;
171
+ delete?: boolean;
172
+ copyPaste?: boolean;
173
+ readOnly?: boolean;
174
+ initialSort?: Array<{
175
+ field: string;
176
+ sort: GridSortDirection;
177
+ }>;
178
+ initialFilter?: InitialFilterConfig;
179
+ filterProp?: boolean;
180
+ toolbar?: boolean;
181
+ toolbarActionProp?: boolean;
182
+ newEntryText?: string;
183
+ rowActionProp?: boolean;
184
+ selectionProps?: "multiSelect" | "singleSelect";
185
+ };
186
+ export type GeneratorConfig = FormConfig<any> | GridConfig<any> | TabsConfig;
187
+ type GQLDocumentConfig = {
188
+ document: string;
189
+ export: boolean;
190
+ };
191
+ export type GQLDocumentConfigMap = Record<string, GQLDocumentConfig>;
192
+ export type GeneratorReturn = {
193
+ code: string;
194
+ gqlDocuments: GQLDocumentConfigMap;
195
+ };
196
+ export declare const generateCommand: Command;
197
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.generateCommand = exports.isFormLayoutConfig = exports.isFormFieldConfig = void 0;
36
+ const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
37
+ const load_1 = require("@graphql-tools/load");
38
+ const commander_1 = require("commander");
39
+ const fs_1 = require("fs");
40
+ const glob_1 = require("glob");
41
+ const graphql_1 = require("graphql");
42
+ const path_1 = require("path");
43
+ const generateForm_1 = require("./generateForm/generateForm");
44
+ const generateGrid_1 = require("./generateGrid/generateGrid");
45
+ const writeGenerated_1 = require("./utils/writeGenerated");
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ function isFormFieldConfig(arg) {
48
+ return !isFormLayoutConfig(arg);
49
+ }
50
+ exports.isFormFieldConfig = isFormFieldConfig;
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ function isFormLayoutConfig(arg) {
53
+ return arg.type !== undefined && ["fieldSet", "optionalNestedFields"].includes(arg.type);
54
+ }
55
+ exports.isFormLayoutConfig = isFormLayoutConfig;
56
+ /**
57
+ * @experimental
58
+ */
59
+ function runGenerate(filePattern = "src/**/*.cometGen.ts") {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
+ const schema = yield (0, load_1.loadSchema)("./schema.gql", {
63
+ loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
64
+ });
65
+ const gqlIntrospection = (0, graphql_1.introspectionFromSchema)(schema);
66
+ const files = yield (0, glob_1.glob)(filePattern);
67
+ for (const file of files) {
68
+ let outputCode = "";
69
+ let gqlDocumentsOutputCode = "";
70
+ const targetDirectory = `${(0, path_1.dirname)(file)}/generated`;
71
+ const baseOutputFilename = (0, path_1.basename)(file).replace(/\.cometGen\.ts$/, "");
72
+ const configs = yield (_a = `${process.cwd()}/${file.replace(/\.ts$/, "")}`, Promise.resolve().then(() => __importStar(require(_a))));
73
+ //const configs = await import(`${process.cwd()}/${file}`);
74
+ const codeOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.ts$/, ""))}.tsx`;
75
+ yield fs_1.promises.rm(codeOuputFilename, { force: true });
76
+ console.log(`generating ${file}`);
77
+ for (const exportName in configs) {
78
+ const config = configs[exportName];
79
+ let generated;
80
+ if (config.type == "form") {
81
+ generated = (0, generateForm_1.generateForm)({ exportName, gqlIntrospection, baseOutputFilename, targetDirectory }, config);
82
+ }
83
+ else if (config.type == "grid") {
84
+ generated = (0, generateGrid_1.generateGrid)({ exportName, gqlIntrospection, baseOutputFilename, targetDirectory }, config);
85
+ }
86
+ else {
87
+ throw new Error(`Unknown config type: ${config.type}`);
88
+ }
89
+ outputCode += generated.code;
90
+ for (const queryName in generated.gqlDocuments) {
91
+ const exportStatement = generated.gqlDocuments[queryName].export ? "export " : "";
92
+ gqlDocumentsOutputCode += `${exportStatement} const ${queryName} = gql\`${generated.gqlDocuments[queryName].document}\`\n`;
93
+ }
94
+ }
95
+ yield (0, writeGenerated_1.writeGenerated)(codeOuputFilename, outputCode);
96
+ if (gqlDocumentsOutputCode != "") {
97
+ const gqlDocumentsOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.ts$/, ""))}.gql.tsx`;
98
+ yield fs_1.promises.rm(gqlDocumentsOuputFilename, { force: true });
99
+ gqlDocumentsOutputCode = `import { gql } from "@apollo/client";
100
+ import { finalFormFileUploadFragment, finalFormFileUploadDownloadableFragment } from "@comet/cms-admin";
101
+
102
+ ${gqlDocumentsOutputCode}
103
+ `;
104
+ yield (0, writeGenerated_1.writeGenerated)(gqlDocumentsOuputFilename, gqlDocumentsOutputCode);
105
+ }
106
+ }
107
+ });
108
+ }
109
+ exports.generateCommand = new commander_1.Command("generate")
110
+ .option("-f, --file <file>", "path to config file or glob pattern to generate specific files")
111
+ .action(({ file: filePattern }) => __awaiter(void 0, void 0, void 0, function* () {
112
+ console.log("️️️⚠️️️⚠️️️⚠️️️ Admin Generator is still experimental and in beta phase. ⚠️️️⚠️️️⚠️️️\n\n");
113
+ yield runGenerate(filePattern);
114
+ }));
@@ -0,0 +1,5 @@
1
+ import { type ComponentFormFieldConfig } from "../generate-command";
2
+ import { type GenerateFieldsReturn } from "./generateFields";
3
+ export declare function generateComponentFormField({ config }: {
4
+ config: ComponentFormFieldConfig;
5
+ }): GenerateFieldsReturn;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateComponentFormField = void 0;
4
+ function generateComponentFormField({ config }) {
5
+ const imports = [{ name: config.component.name, importPath: config.component.import }];
6
+ const code = `<${config.component.name} />`;
7
+ return {
8
+ imports,
9
+ hooksCode: "",
10
+ formFragmentFields: [],
11
+ formValueToGqlInputCode: "",
12
+ formValuesConfig: [],
13
+ finalFormConfig: undefined,
14
+ code,
15
+ gqlDocuments: {},
16
+ };
17
+ }
18
+ exports.generateComponentFormField = generateComponentFormField;
@@ -0,0 +1,35 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ import { type FormConfig, type GeneratorReturn } from "../generate-command";
3
+ import { type Imports } from "../utils/generateImportsCode";
4
+ export type GenerateFieldsReturn = GeneratorReturn & {
5
+ imports: Imports;
6
+ hooksCode: string;
7
+ formFragmentFields: string[];
8
+ formValueToGqlInputCode: string;
9
+ formValuesConfig: {
10
+ omitFromFragmentType?: string;
11
+ destructFromFormValues?: string;
12
+ typeCode?: string;
13
+ initializationCode?: string;
14
+ defaultInitializationCode?: string;
15
+ }[];
16
+ finalFormConfig?: {
17
+ subscription?: {
18
+ values?: true;
19
+ };
20
+ renderProps?: {
21
+ values?: true;
22
+ form?: true;
23
+ };
24
+ };
25
+ };
26
+ export declare function findFieldByName(name: string, fields: FormConfig<any>["fields"]): FormConfig<any>["fields"][0] | undefined;
27
+ export declare function generateFields({ gqlIntrospection, baseOutputFilename, fields, formFragmentName, formConfig, gqlType, namePrefix, }: {
28
+ gqlIntrospection: IntrospectionQuery;
29
+ baseOutputFilename: string;
30
+ fields: FormConfig<any>["fields"];
31
+ formConfig: FormConfig<any>;
32
+ formFragmentName: string;
33
+ gqlType: string;
34
+ namePrefix?: string;
35
+ }): GenerateFieldsReturn;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateFields = exports.findFieldByName = void 0;
4
+ const generate_command_1 = require("../generate-command");
5
+ const generateComponentFormField_1 = require("./generateComponentFormField");
6
+ const generateFormField_1 = require("./generateFormField");
7
+ const generateFormLayout_1 = require("./generateFormLayout");
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ function findFieldByName(name, fields) {
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ return fields.reduce((acc, field) => {
12
+ return acc
13
+ ? acc
14
+ : "name" in field && field.name === name
15
+ ? field
16
+ : (0, generate_command_1.isFormLayoutConfig)(field)
17
+ ? findFieldByName(name, field.fields)
18
+ : undefined;
19
+ }, undefined);
20
+ }
21
+ exports.findFieldByName = findFieldByName;
22
+ function generateFields({ gqlIntrospection, baseOutputFilename, fields, formFragmentName, formConfig, gqlType, namePrefix, }) {
23
+ const gqlDocuments = {};
24
+ let hooksCode = "";
25
+ let formValueToGqlInputCode = "";
26
+ const formFragmentFields = [];
27
+ const imports = [];
28
+ const formValuesConfig = [];
29
+ const finalFormConfig = { subscription: {}, renderProps: {} };
30
+ const code = fields
31
+ .map((field) => {
32
+ var _a, _b;
33
+ let generated;
34
+ if (field.type === "component") {
35
+ generated = (0, generateComponentFormField_1.generateComponentFormField)({
36
+ config: field,
37
+ });
38
+ }
39
+ else if ((0, generate_command_1.isFormFieldConfig)(field)) {
40
+ generated = (0, generateFormField_1.generateFormField)({
41
+ gqlIntrospection,
42
+ baseOutputFilename,
43
+ formFragmentName,
44
+ config: field,
45
+ formConfig,
46
+ gqlType,
47
+ namePrefix,
48
+ });
49
+ }
50
+ else if ((0, generate_command_1.isFormLayoutConfig)(field)) {
51
+ generated = (0, generateFormLayout_1.generateFormLayout)({
52
+ gqlIntrospection,
53
+ baseOutputFilename,
54
+ formFragmentName,
55
+ config: field,
56
+ formConfig,
57
+ gqlType,
58
+ namePrefix,
59
+ });
60
+ }
61
+ else {
62
+ throw new Error("Not supported config");
63
+ }
64
+ for (const name in generated.gqlDocuments) {
65
+ gqlDocuments[name] = generated.gqlDocuments[name];
66
+ }
67
+ imports.push(...generated.imports);
68
+ hooksCode += generated.hooksCode;
69
+ formValueToGqlInputCode += generated.formValueToGqlInputCode;
70
+ formFragmentFields.push(...generated.formFragmentFields);
71
+ formValuesConfig.push(...generated.formValuesConfig);
72
+ finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (_a = generated.finalFormConfig) === null || _a === void 0 ? void 0 : _a.subscription);
73
+ finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (_b = generated.finalFormConfig) === null || _b === void 0 ? void 0 : _b.renderProps);
74
+ return generated.code;
75
+ })
76
+ .join("\n");
77
+ return {
78
+ code,
79
+ hooksCode,
80
+ formValueToGqlInputCode,
81
+ formFragmentFields,
82
+ gqlDocuments,
83
+ imports,
84
+ formValuesConfig,
85
+ finalFormConfig,
86
+ };
87
+ }
88
+ exports.generateFields = generateFields;
@@ -0,0 +1,13 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ import { type FormConfig, type GeneratorReturn } from "../generate-command";
3
+ export type Prop = {
4
+ type: string;
5
+ optional: boolean;
6
+ name: string;
7
+ };
8
+ export declare function generateForm({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, }: {
9
+ exportName: string;
10
+ baseOutputFilename: string;
11
+ targetDirectory: string;
12
+ gqlIntrospection: IntrospectionQuery;
13
+ }, config: FormConfig<any>): GeneratorReturn;