@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
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateFormLayout = void 0;
4
+ const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
5
+ const generateFields_1 = require("./generateFields");
6
+ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }) {
7
+ var _a, _b, _c, _d, _e;
8
+ const rootGqlType = formConfig.gqlType;
9
+ const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
10
+ const dataRootName = rootGqlType[0].toLowerCase() + rootGqlType.substring(1); // TODO should probably be deteced via query
11
+ let code = "";
12
+ let hooksCode = "";
13
+ let formValueToGqlInputCode = "";
14
+ const formFragmentFields = [];
15
+ const gqlDocuments = {};
16
+ const imports = [];
17
+ const formValuesConfig = [];
18
+ const finalFormConfig = { subscription: {}, renderProps: {} };
19
+ if (config.type === "fieldSet") {
20
+ const title = (_a = config.title) !== null && _a !== void 0 ? _a : (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(config.name);
21
+ const generatedFields = (0, generateFields_1.generateFields)({
22
+ gqlIntrospection,
23
+ baseOutputFilename,
24
+ fields: config.fields,
25
+ formFragmentName,
26
+ formConfig,
27
+ gqlType,
28
+ namePrefix,
29
+ });
30
+ hooksCode += generatedFields.hooksCode;
31
+ formValueToGqlInputCode += generatedFields.formValueToGqlInputCode;
32
+ formFragmentFields.push(...generatedFields.formFragmentFields);
33
+ for (const name in generatedFields.gqlDocuments) {
34
+ gqlDocuments[name] = generatedFields.gqlDocuments[name];
35
+ }
36
+ imports.push(...generatedFields.imports);
37
+ formValuesConfig.push(...generatedFields.formValuesConfig);
38
+ finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (_b = generatedFields.finalFormConfig) === null || _b === void 0 ? void 0 : _b.subscription);
39
+ finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (_c = generatedFields.finalFormConfig) === null || _c === void 0 ? void 0 : _c.renderProps);
40
+ imports.push({ name: "FieldSet", importPath: "@comet/admin" });
41
+ const supportPlaceholder = (_d = config.supportText) === null || _d === void 0 ? void 0 : _d.includes("{");
42
+ if (supportPlaceholder) {
43
+ imports.push({ name: "FormSpy", importPath: "react-final-form" });
44
+ }
45
+ code = `
46
+ <FieldSet
47
+ ${config.collapsible === undefined || config.collapsible ? `collapsible` : ``}
48
+ ${config.initiallyExpanded != null ? `initiallyExpanded={${config.initiallyExpanded}}` : ``}
49
+ title={<FormattedMessage id="${formattedMessageRootId}.${config.name}.title" defaultMessage="${title}" />}
50
+ ${config.supportText
51
+ ? `supportText={
52
+ ${supportPlaceholder ? `mode === "edit" && (<FormSpy subscription={{ values: true }}>{({ values }) => (` : ``}
53
+ <FormattedMessage
54
+ id="${formattedMessageRootId}.${config.name}.supportText"
55
+ defaultMessage="${config.supportText}"
56
+ ${supportPlaceholder ? `values={{ ...values }}` : ``}
57
+ />
58
+ ${supportPlaceholder ? `)}</FormSpy>)` : ``}
59
+ }`
60
+ : ``}
61
+ >
62
+ ${generatedFields.code}
63
+ </FieldSet>`;
64
+ }
65
+ else if (config.type === "optionalNestedFields") {
66
+ const name = String(config.name);
67
+ const introspectionObject = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
68
+ if (!introspectionObject)
69
+ throw new Error(`didn't find object ${gqlType} in gql introspection`);
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
+ if (introspectionField.type.kind === "NON_NULL") {
74
+ throw new Error(`field ${name} in gql introspection type ${gqlType} must not be required to be usable with optionalNestedFields`);
75
+ }
76
+ if (introspectionField.type.kind !== "OBJECT")
77
+ throw new Error(`field ${name} in gql introspection type ${gqlType} has to be OBJECT`);
78
+ const checkboxLabel = (_e = config.checkboxLabel) !== null && _e !== void 0 ? _e : `Enable ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(String(config.name))}`;
79
+ const generatedFields = (0, generateFields_1.generateFields)({
80
+ gqlIntrospection,
81
+ baseOutputFilename,
82
+ fields: config.fields,
83
+ formFragmentName,
84
+ formConfig,
85
+ gqlType: introspectionField.type.name,
86
+ namePrefix: name,
87
+ });
88
+ hooksCode += generatedFields.hooksCode;
89
+ formFragmentFields.push(`${name} { ${generatedFields.formFragmentFields.join(" ")} }`);
90
+ for (const name in generatedFields.gqlDocuments) {
91
+ gqlDocuments[name] = generatedFields.gqlDocuments[name];
92
+ }
93
+ imports.push(...generatedFields.imports);
94
+ const wrappingFormValuesConfig = {
95
+ omitFromFragmentType: name,
96
+ destructFromFormValues: `${name}Enabled`,
97
+ typeCode: `${name}Enabled: boolean;`,
98
+ initializationCode: `${name}Enabled: !!data.${dataRootName}.${name}`,
99
+ };
100
+ const subfieldsFormValuesTypeCode = generatedFields.formValuesConfig
101
+ .filter((config) => !!config.omitFromFragmentType)
102
+ .map((config) => `"${config.omitFromFragmentType}"`);
103
+ if (subfieldsFormValuesTypeCode.length) {
104
+ wrappingFormValuesConfig.typeCode = `${wrappingFormValuesConfig.typeCode}
105
+ ${name}: Omit<NonNullable<GQL${formFragmentName}Fragment["${name}"]>, ${subfieldsFormValuesTypeCode.join(" | ")}> & {
106
+ ${generatedFields.formValuesConfig.map((config) => config.typeCode).join("\n")}
107
+ };`;
108
+ }
109
+ const subfieldsFormValuesInitCode = generatedFields.formValuesConfig
110
+ .filter((config) => !!config.initializationCode)
111
+ .map((config) => config.initializationCode);
112
+ if (subfieldsFormValuesInitCode.length) {
113
+ wrappingFormValuesConfig.initializationCode = `${wrappingFormValuesConfig.initializationCode},
114
+ ${name}: data.${dataRootName}.${name} ? { ${subfieldsFormValuesInitCode.join(", ")}} : undefined `;
115
+ }
116
+ const subfieldsFormValuesDefaultInitCode = generatedFields.formValuesConfig
117
+ .filter((config) => !!config.defaultInitializationCode)
118
+ .map((config) => config.defaultInitializationCode);
119
+ if (subfieldsFormValuesDefaultInitCode.length) {
120
+ wrappingFormValuesConfig.defaultInitializationCode = `${name}: { ${subfieldsFormValuesDefaultInitCode.join(", ")}}`;
121
+ }
122
+ formValuesConfig.push(wrappingFormValuesConfig);
123
+ imports.push({ name: "FinalFormSwitch", importPath: "@comet/admin" });
124
+ imports.push({ name: "messages", importPath: "@comet/admin" });
125
+ imports.push({ name: "FormControlLabel", importPath: "@mui/material" });
126
+ formValueToGqlInputCode += `${String(config.name)}: ${String(config.name)}Enabled && formValues.${String(config.name)} ? {${generatedFields.formValueToGqlInputCode}} : null,`;
127
+ code = `<Field
128
+ fullWidth
129
+ name="${String(config.name)}Enabled"
130
+ type="checkbox"
131
+ label={<FormattedMessage id="${formattedMessageRootId}.${String(config.name)}.${String(config.name)}Enabled" defaultMessage="${checkboxLabel}" />}
132
+ >
133
+ {(props) => (
134
+ <FormControlLabel
135
+ control={<FinalFormSwitch {...props} />}
136
+ label={props.input.checked ? <FormattedMessage {...messages.yes} /> : <FormattedMessage {...messages.no} />}
137
+ />
138
+ )}
139
+ </Field>
140
+ <Field name="${String(config.name)}Enabled" fullWidth subscription={{ value: true }}>
141
+ {({ input: { value } }) =>
142
+ value ? (
143
+ <>
144
+ ${generatedFields.code}
145
+ </>
146
+ ) : null
147
+ }
148
+ </Field>`;
149
+ }
150
+ else {
151
+ throw new Error(`Unsupported type`);
152
+ }
153
+ return {
154
+ code,
155
+ hooksCode,
156
+ formValueToGqlInputCode,
157
+ formFragmentFields,
158
+ gqlDocuments,
159
+ imports,
160
+ formValuesConfig,
161
+ finalFormConfig,
162
+ };
163
+ }
164
+ exports.generateFormLayout = generateFormLayout;
@@ -0,0 +1,19 @@
1
+ import { type IntrospectionField, type IntrospectionQuery } from "graphql";
2
+ import { type FormFieldConfig } from "../generate-command";
3
+ import { type Imports } from "../utils/generateImportsCode";
4
+ import { type Prop } from "./generateForm";
5
+ type GqlArg = {
6
+ type: string;
7
+ name: string;
8
+ isInputArgSubfield: boolean;
9
+ };
10
+ export declare function getForwardedGqlArgs({ fields, gqlOperation, gqlIntrospection, }: {
11
+ fields: FormFieldConfig<any>[];
12
+ gqlOperation: IntrospectionField;
13
+ gqlIntrospection: IntrospectionQuery;
14
+ }): {
15
+ imports: Imports;
16
+ props: Prop[];
17
+ gqlArgs: GqlArg[];
18
+ };
19
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getForwardedGqlArgs = void 0;
4
+ function getForwardedGqlArgs({ fields, gqlOperation, gqlIntrospection, }) {
5
+ const imports = [];
6
+ const props = [];
7
+ const gqlArgs = [];
8
+ const skipGqlInputArgFields = fields.map((field) => String(field.name));
9
+ getArgsIncludingInputArgSubfields(gqlOperation, gqlIntrospection).forEach((arg) => {
10
+ if (arg.isInputArgSubfield && skipGqlInputArgFields.includes(arg.name))
11
+ return;
12
+ if (arg.type === "ID" || arg.type === "String" || arg.type === "DateTime") {
13
+ props.push({ name: arg.name, optional: false, type: "string" });
14
+ }
15
+ else if (arg.type === "Boolean") {
16
+ props.push({ name: arg.name, optional: false, type: "boolean" });
17
+ }
18
+ else if (arg.type === "Int" || arg.type === "Float") {
19
+ props.push({ name: arg.name, optional: false, type: "number" });
20
+ }
21
+ else if (arg.type === "JSONObject") {
22
+ props.push({ name: arg.name, optional: false, type: "unknown" });
23
+ }
24
+ else {
25
+ props.push({ name: arg.name, optional: false, type: `GQL${arg.type}` }); // generated types contain GQL prefix
26
+ imports.push({ name: `GQL${arg.type}`, importPath: "@src/graphql.generated" });
27
+ }
28
+ gqlArgs.push({ name: arg.name, type: arg.type, isInputArgSubfield: arg.isInputArgSubfield });
29
+ });
30
+ return {
31
+ imports,
32
+ props,
33
+ gqlArgs,
34
+ };
35
+ }
36
+ exports.getForwardedGqlArgs = getForwardedGqlArgs;
37
+ function getArgsIncludingInputArgSubfields(gqlOperation, gqlIntrospection) {
38
+ const nativeScalars = ["ID", "String", "Boolean", "Int", "Float", "DateTime", "JSONObject"];
39
+ // reducer is not created inline to reuse it to look into "input" arg
40
+ function reducer(acc, inputField) {
41
+ if (inputField.type.kind !== "NON_NULL" || inputField.defaultValue)
42
+ return acc;
43
+ const gqlType = inputField.type.ofType;
44
+ if (gqlType.kind === "INPUT_OBJECT") {
45
+ if (inputField.name === "input") {
46
+ // input-arg typically contains entity fields, so look into it
47
+ const typeDef = gqlIntrospection.__schema.types.find((type) => type.kind === "INPUT_OBJECT" && type.name === gqlType.name);
48
+ if (typeDef && typeDef.kind === "INPUT_OBJECT") {
49
+ const inputArgSubfields = typeDef.inputFields.reduce(reducer, []).map((inputArgSubfield) => {
50
+ return Object.assign(Object.assign({}, inputArgSubfield), { isInputArgSubfield: true });
51
+ });
52
+ acc.push(...inputArgSubfields);
53
+ }
54
+ else {
55
+ console.warn(`IntrospectionType for ${gqlType.name} not found or no INPUT_OBJECT`);
56
+ }
57
+ }
58
+ else {
59
+ acc.push({ name: inputField.name, type: gqlType.name, isInputArgSubfield: false });
60
+ }
61
+ }
62
+ else if (gqlType.kind === "SCALAR") {
63
+ if (!nativeScalars.includes(gqlType.name)) {
64
+ console.warn(`Currently not supported special SCALAR of type ${gqlType.name} in arg/field ${inputField.name}`);
65
+ }
66
+ else {
67
+ acc.push({ name: inputField.name, type: gqlType.name, isInputArgSubfield: false });
68
+ }
69
+ }
70
+ else if (gqlType.kind === "ENUM") {
71
+ acc.push({ name: inputField.name, type: gqlType.name, isInputArgSubfield: false });
72
+ }
73
+ else if (gqlType.kind === "LIST") {
74
+ throw new Error(`Not supported kind ${gqlType.kind}, arg: input.${inputField.name}`);
75
+ }
76
+ return acc;
77
+ }
78
+ return gqlOperation.args.reduce(reducer, []);
79
+ }
@@ -0,0 +1,43 @@
1
+ import { type GridColDef } from "@comet/admin";
2
+ import { type ComponentProps } from "react";
3
+ import { type FormattedNumber } from "react-intl";
4
+ import { type BaseColumnConfig, type ImportReference } from "../generate-command";
5
+ type AbstractField<FieldName extends string> = {
6
+ field: FieldName;
7
+ emptyValue?: string;
8
+ };
9
+ type TextField<FieldName extends string> = AbstractField<FieldName> & {
10
+ type: "text";
11
+ };
12
+ type StaticText = {
13
+ type: "static";
14
+ text: string;
15
+ };
16
+ type FormattedNumberPropsForNumberField = Omit<ComponentProps<typeof FormattedNumber>, "value" | "children">;
17
+ type NumberField<FieldName extends string> = AbstractField<FieldName> & FormattedNumberPropsForNumberField & {
18
+ type: "number";
19
+ decimals?: number;
20
+ };
21
+ type StaticSelectField<FieldName extends string> = AbstractField<FieldName> & {
22
+ type: "staticSelect";
23
+ values: Array<string | {
24
+ value: string | number | boolean;
25
+ label: string;
26
+ }>;
27
+ };
28
+ type FormattedMessage<FieldName extends string> = {
29
+ type: "formattedMessage";
30
+ message: string;
31
+ valueFields: Record<string, Field<FieldName>>;
32
+ };
33
+ type Field<FieldName extends string> = StaticText | FieldName | TextField<FieldName> | NumberField<FieldName> | StaticSelectField<FieldName> | FormattedMessage<FieldName>;
34
+ export type GridCombinationColumnConfig<FieldName extends string> = {
35
+ type: "combination";
36
+ name: string;
37
+ primaryText?: Field<FieldName>;
38
+ secondaryText?: Field<FieldName>;
39
+ filterOperators?: ImportReference;
40
+ } & BaseColumnConfig & Pick<GridColDef, "sortBy">;
41
+ export declare const getCombinationColumnRenderCell: (column: GridCombinationColumnConfig<string>, messageIdPrefix: string) => string;
42
+ export declare const getAllColumnFieldNames: (column: GridCombinationColumnConfig<string>) => string[];
43
+ export {};
@@ -0,0 +1,151 @@
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.getAllColumnFieldNames = exports.getCombinationColumnRenderCell = void 0;
15
+ const intl_1 = require("../utils/intl");
16
+ const getTextForCellContent = (textConfig, messageIdPrefix) => {
17
+ if (typeof textConfig !== "string" && textConfig.type === "static") {
18
+ return {
19
+ textContent: (0, intl_1.getFormattedMessageNode)(messageIdPrefix, textConfig.text),
20
+ };
21
+ }
22
+ if (typeof textConfig !== "string" && textConfig.type === "formattedMessage") {
23
+ const variableDefinitions = [];
24
+ const values = Object.entries(textConfig.valueFields)
25
+ .map(([key, value]) => {
26
+ const { textContent, variableDefinitions: cellVariableDefinitions } = getTextForCellContent(value, `${messageIdPrefix}.${key}`);
27
+ if (cellVariableDefinitions === null || cellVariableDefinitions === void 0 ? void 0 : cellVariableDefinitions.length) {
28
+ variableDefinitions.push(...cellVariableDefinitions);
29
+ }
30
+ return `${key}: ${textContent}`;
31
+ })
32
+ .join(", ");
33
+ return {
34
+ textContent: (0, intl_1.getFormattedMessageNode)(messageIdPrefix, textConfig.message, `{${values}}`),
35
+ variableDefinitions,
36
+ };
37
+ }
38
+ const emptyText = typeof textConfig !== "string" && "emptyValue" in textConfig
39
+ ? (0, intl_1.getFormattedMessageNode)(`${messageIdPrefix}.empty`, textConfig.emptyValue)
40
+ : "'-'";
41
+ const fieldName = typeof textConfig === "string" ? textConfig : textConfig.field;
42
+ const rowValue = `row.${fieldName.replace(/\./g, "?.")}`;
43
+ const stringTextContent = `${rowValue} ?? ${emptyText}`;
44
+ if (typeof textConfig === "string") {
45
+ return {
46
+ textContent: stringTextContent,
47
+ };
48
+ }
49
+ if (textConfig.type === "number") {
50
+ const { type, decimals: decimalsConfigValue, field, emptyValue } = textConfig, configForFormattedNumberProps = __rest(textConfig, ["type", "decimals", "field", "emptyValue"]);
51
+ const hasCurrency = Boolean(textConfig.currency);
52
+ const hasUnit = Boolean(textConfig.unit);
53
+ const defaultDecimalsProp = hasCurrency && decimalsConfigValue === undefined ? 2 : decimalsConfigValue;
54
+ let defaultStyleProp = undefined;
55
+ if (hasCurrency) {
56
+ defaultStyleProp = '"currency"';
57
+ }
58
+ else if (hasUnit) {
59
+ defaultStyleProp = '"unit"';
60
+ }
61
+ const formattedNumberProps = {
62
+ value: `{${rowValue}}`,
63
+ minimumFractionDigits: typeof defaultDecimalsProp !== "undefined" ? `{${defaultDecimalsProp}}` : undefined,
64
+ maximumFractionDigits: typeof defaultDecimalsProp !== "undefined" ? `{${defaultDecimalsProp}}` : undefined,
65
+ style: typeof defaultStyleProp !== "undefined" ? defaultStyleProp : undefined,
66
+ };
67
+ Object.entries(configForFormattedNumberProps).forEach(([key, value]) => {
68
+ if (typeof value === "string") {
69
+ formattedNumberProps[key] = `"${value}"`;
70
+ }
71
+ else {
72
+ formattedNumberProps[key] = `{${value}}`;
73
+ }
74
+ });
75
+ const formattedNumberPropsString = Object.entries(formattedNumberProps)
76
+ .map(([key, value]) => {
77
+ if (typeof value === "undefined") {
78
+ return null;
79
+ }
80
+ return `${key}=${value}`;
81
+ })
82
+ .join(" ");
83
+ return {
84
+ textContent: `typeof ${rowValue} === "undefined" || ${rowValue} === null ? ${emptyText} : <FormattedNumber ${formattedNumberPropsString} />`,
85
+ };
86
+ }
87
+ if (textConfig.type === "staticSelect") {
88
+ const labelsVariableName = `${textConfig.field}Labels`;
89
+ const labelMapping = textConfig.values
90
+ .map((valueOption) => {
91
+ const value = typeof valueOption === "string" ? valueOption : valueOption.value;
92
+ const label = typeof valueOption === "string" ? valueOption : valueOption.label;
93
+ return `${value}: ${(0, intl_1.getFormattedMessageNode)(`${messageIdPrefix}.${value}`, label)}`;
94
+ })
95
+ .join(", ");
96
+ const labelMappingVar = `const ${labelsVariableName}: Record<string, ReactNode> = { ${labelMapping} };`;
97
+ const textContent = `(${rowValue} == null ? ${emptyText} : ${labelsVariableName}[` + `\`\${${rowValue}}\`` + `] ?? ${rowValue})`;
98
+ return {
99
+ textContent,
100
+ variableDefinitions: [labelMappingVar],
101
+ };
102
+ }
103
+ return {
104
+ textContent: stringTextContent,
105
+ };
106
+ };
107
+ const getCombinationColumnRenderCell = (column, messageIdPrefix) => {
108
+ const gridCellContentProps = {};
109
+ const allVariableDefinitions = [];
110
+ if (column.primaryText) {
111
+ const { textContent, variableDefinitions = [] } = getTextForCellContent(column.primaryText, `${messageIdPrefix}.primaryText`);
112
+ gridCellContentProps.primaryText = textContent;
113
+ allVariableDefinitions.push(...variableDefinitions);
114
+ }
115
+ if (column.secondaryText) {
116
+ const { textContent, variableDefinitions = [] } = getTextForCellContent(column.secondaryText, `${messageIdPrefix}.secondaryText`);
117
+ gridCellContentProps.secondaryText = textContent;
118
+ allVariableDefinitions.push(...variableDefinitions);
119
+ }
120
+ const allUniqueVariableDefinitions = Array.from(new Set(allVariableDefinitions));
121
+ return `({ row }) => {
122
+ ${allUniqueVariableDefinitions.join("\n")}
123
+ return <GridCellContent ${Object.entries(gridCellContentProps)
124
+ .map(([key, value]) => `${key}={${value}}`)
125
+ .join(" ")} />;
126
+ }`;
127
+ };
128
+ exports.getCombinationColumnRenderCell = getCombinationColumnRenderCell;
129
+ const getFieldNamesFromText = (textConfig) => {
130
+ if (typeof textConfig === "string") {
131
+ return [textConfig];
132
+ }
133
+ if (textConfig.type === "static") {
134
+ return [];
135
+ }
136
+ if (textConfig.type === "formattedMessage") {
137
+ return Object.values(textConfig.valueFields).flatMap((value) => getFieldNamesFromText(value));
138
+ }
139
+ return [textConfig.field];
140
+ };
141
+ const getAllColumnFieldNames = (column) => {
142
+ const fieldNames = [];
143
+ if (column.primaryText) {
144
+ fieldNames.push(...getFieldNamesFromText(column.primaryText));
145
+ }
146
+ if (column.secondaryText) {
147
+ fieldNames.push(...getFieldNamesFromText(column.secondaryText));
148
+ }
149
+ return fieldNames.filter((fieldName) => fieldName !== "id");
150
+ };
151
+ exports.getAllColumnFieldNames = getAllColumnFieldNames;
@@ -0,0 +1,2 @@
1
+ import { type IntrospectionInputObjectType, type IntrospectionInputValue, type IntrospectionQuery } from "graphql";
2
+ export declare function findInputObjectType(input: IntrospectionInputValue, schema: IntrospectionQuery): IntrospectionInputObjectType | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findInputObjectType = void 0;
4
+ function findInputObjectType(input, schema) {
5
+ let type = input.type;
6
+ if (type.kind == "NON_NULL") {
7
+ type = type.ofType;
8
+ }
9
+ if (type.kind !== "INPUT_OBJECT") {
10
+ throw new Error("must be INPUT_OBJECT");
11
+ }
12
+ const typeName = type.name;
13
+ const filterType = schema.__schema.types.find((type) => type.kind === "INPUT_OBJECT" && type.name === typeName);
14
+ return filterType;
15
+ }
16
+ exports.findInputObjectType = findInputObjectType;
@@ -0,0 +1,5 @@
1
+ import { type ActionsGridColumnConfig, type GridColumnConfig } from "../generate-command";
2
+ import { type GridCombinationColumnConfig } from "./combinationColumn";
3
+ export declare function generateGqlFieldList({ columns, }: {
4
+ columns: Array<GridColumnConfig<any> | GridCombinationColumnConfig<string> | ActionsGridColumnConfig>;
5
+ }): string;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateGqlFieldList = void 0;
7
+ const object_path_1 = __importDefault(require("object-path"));
8
+ const combinationColumn_1 = require("./combinationColumn");
9
+ const recursiveStringify = (obj) => {
10
+ let ret = "";
11
+ let prefixField = "";
12
+ for (const key in obj) {
13
+ const valueForKey = obj[key];
14
+ if (typeof valueForKey === "boolean") {
15
+ ret += `${prefixField}${key}`;
16
+ }
17
+ else if (typeof valueForKey === "string") {
18
+ ret += `${prefixField}${key}${valueForKey}`;
19
+ }
20
+ else {
21
+ ret += `${prefixField}${key} { ${recursiveStringify(valueForKey)} }`;
22
+ }
23
+ prefixField = " ";
24
+ }
25
+ return ret;
26
+ };
27
+ function generateGqlFieldList({ columns, }) {
28
+ const fieldsObject = columns.reduce((acc, field) => {
29
+ if (field.type !== "actions") {
30
+ if (field.type === "combination") {
31
+ (0, combinationColumn_1.getAllColumnFieldNames)(field).map((fieldName) => {
32
+ object_path_1.default.set(acc, fieldName, true);
33
+ });
34
+ }
35
+ else {
36
+ object_path_1.default.set(acc, field.name, true);
37
+ }
38
+ }
39
+ return acc;
40
+ }, {});
41
+ return recursiveStringify(fieldsObject);
42
+ }
43
+ exports.generateGqlFieldList = generateGqlFieldList;
@@ -0,0 +1,14 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ import { type GeneratorReturn, type GridConfig } from "../generate-command";
3
+ export type Prop = {
4
+ type: string;
5
+ optional: boolean;
6
+ name: string;
7
+ defaultValue?: string | number;
8
+ };
9
+ export declare function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, }: {
10
+ exportName: string;
11
+ baseOutputFilename: string;
12
+ targetDirectory: string;
13
+ gqlIntrospection: IntrospectionQuery;
14
+ }, config: GridConfig<any>): GeneratorReturn;