@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.
Files changed (87) hide show
  1. package/bin/admin-generator.mjs +3 -0
  2. package/dist/adminGenerator.d.mts +1 -0
  3. package/dist/adminGenerator.mjs +4441 -0
  4. package/dist/index.d.mts +344 -0
  5. package/dist/index.mjs +4440 -0
  6. package/package.json +31 -21
  7. package/bin/admin-generator.js +0 -8
  8. package/lib/adminGenerator.d.ts +0 -1
  9. package/lib/adminGenerator.js +0 -8
  10. package/lib/commands/generate/config/parseConfig.d.ts +0 -1
  11. package/lib/commands/generate/config/parseConfig.js +0 -72
  12. package/lib/commands/generate/config/transformConfig.d.ts +0 -7
  13. package/lib/commands/generate/config/transformConfig.js +0 -264
  14. package/lib/commands/generate/generate-command.d.ts +0 -340
  15. package/lib/commands/generate/generate-command.js +0 -112
  16. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.d.ts +0 -26
  17. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +0 -364
  18. package/lib/commands/generate/generateForm/extractErrorEnums.d.ts +0 -16
  19. package/lib/commands/generate/generateForm/extractErrorEnums.js +0 -100
  20. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +0 -2
  21. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +0 -22
  22. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.d.ts +0 -6
  23. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.js +0 -22
  24. package/lib/commands/generate/generateForm/formField/options.d.ts +0 -24
  25. package/lib/commands/generate/generateForm/formField/options.js +0 -85
  26. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +0 -5
  27. package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -22
  28. package/lib/commands/generate/generateForm/generateErrorHandling.d.ts +0 -8
  29. package/lib/commands/generate/generateForm/generateErrorHandling.js +0 -24
  30. package/lib/commands/generate/generateForm/generateErrorMessages.d.ts +0 -11
  31. package/lib/commands/generate/generateForm/generateErrorMessages.js +0 -28
  32. package/lib/commands/generate/generateForm/generateFields.d.ts +0 -42
  33. package/lib/commands/generate/generateForm/generateFields.js +0 -87
  34. package/lib/commands/generate/generateForm/generateForm.d.ts +0 -14
  35. package/lib/commands/generate/generateForm/generateForm.js +0 -565
  36. package/lib/commands/generate/generateForm/generateFormField.d.ts +0 -12
  37. package/lib/commands/generate/generateForm/generateFormField.js +0 -368
  38. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +0 -12
  39. package/lib/commands/generate/generateForm/generateFormLayout.js +0 -154
  40. package/lib/commands/generate/generateForm/generateFormValues.d.ts +0 -40
  41. package/lib/commands/generate/generateForm/generateFormValues.js +0 -219
  42. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +0 -11
  43. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +0 -29
  44. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +0 -18
  45. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +0 -79
  46. package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +0 -5
  47. package/lib/commands/generate/generateGrid/detectMuiXVersion.js +0 -32
  48. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +0 -2
  49. package/lib/commands/generate/generateGrid/findInputObjectType.js +0 -15
  50. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +0 -6
  51. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +0 -56
  52. package/lib/commands/generate/generateGrid/generateGrid.d.ts +0 -16
  53. package/lib/commands/generate/generateGrid/generateGrid.js +0 -1017
  54. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +0 -15
  55. package/lib/commands/generate/generateGrid/generateGridToolbar.js +0 -90
  56. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +0 -13
  57. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +0 -59
  58. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +0 -14
  59. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +0 -13
  60. package/lib/commands/generate/generateGrid/usableFields.d.ts +0 -14
  61. package/lib/commands/generate/generateGrid/usableFields.js +0 -3
  62. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +0 -1
  63. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +0 -7
  64. package/lib/commands/generate/utils/columnVisibility.d.ts +0 -6
  65. package/lib/commands/generate/utils/columnVisibility.js +0 -2
  66. package/lib/commands/generate/utils/convertConfigImport.d.ts +0 -6
  67. package/lib/commands/generate/utils/convertConfigImport.js +0 -14
  68. package/lib/commands/generate/utils/findMutationType.d.ts +0 -3
  69. package/lib/commands/generate/utils/findMutationType.js +0 -18
  70. package/lib/commands/generate/utils/findQueryType.d.ts +0 -2
  71. package/lib/commands/generate/utils/findQueryType.js +0 -18
  72. package/lib/commands/generate/utils/findRootBlocks.d.ts +0 -8
  73. package/lib/commands/generate/utils/findRootBlocks.js +0 -66
  74. package/lib/commands/generate/utils/generateGqlOperation.d.ts +0 -12
  75. package/lib/commands/generate/utils/generateGqlOperation.js +0 -87
  76. package/lib/commands/generate/utils/generateImportsCode.d.ts +0 -6
  77. package/lib/commands/generate/utils/generateImportsCode.js +0 -31
  78. package/lib/commands/generate/utils/intl.d.ts +0 -20
  79. package/lib/commands/generate/utils/intl.js +0 -44
  80. package/lib/commands/generate/utils/isFieldOptional.d.ts +0 -7
  81. package/lib/commands/generate/utils/isFieldOptional.js +0 -21
  82. package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +0 -20
  83. package/lib/commands/generate/utils/runtimeTypeGuards.js +0 -22
  84. package/lib/commands/generate/utils/writeGenerated.d.ts +0 -1
  85. package/lib/commands/generate/utils/writeGenerated.js +0 -123
  86. package/lib/index.d.ts +0 -2
  87. package/lib/index.js +0 -6
@@ -1,15 +0,0 @@
1
- import { type FormattedMessageElement } from "../generate-command";
2
- type Options = {
3
- componentName: string;
4
- forwardToolbarAction: boolean | undefined;
5
- hasSearch: boolean;
6
- hasFilter: boolean;
7
- excelExport: boolean | undefined;
8
- allowAdding: boolean;
9
- instanceGqlType: string;
10
- gqlType: string;
11
- newEntryText: string | FormattedMessageElement | undefined;
12
- fragmentName: string;
13
- };
14
- export declare const generateGridToolbar: ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }: Options) => string;
15
- export {};
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateGridToolbar = void 0;
4
- const change_case_1 = require("change-case");
5
- const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
6
- const intl_1 = require("../utils/intl");
7
- const generateGridToolbar = ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }) => {
8
- return `${renderToolbarProps(componentName, !!forwardToolbarAction, !!excelExport)}
9
- function ${componentName}(${getGridToolbarProps(componentName, !!forwardToolbarAction, !!excelExport)}) {
10
- return (
11
- <DataGridToolbar>
12
- ${hasSearch ? "<GridToolbarQuickFilter />" : ""}
13
- ${hasFilter ? "<GridFilterButton />" : ""}
14
- <FillSpace />
15
- ${renderToolbarActions({
16
- forwardToolbarAction,
17
- addItemText: (0, intl_1.generateFormattedMessage)({
18
- config: newEntryText,
19
- id: `${instanceGqlType}.${(0, change_case_1.camelCase)(fragmentName)}.newEntry`,
20
- defaultMessage: `New ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(gqlType)}`,
21
- type: "jsx",
22
- }),
23
- excelExport,
24
- allowAdding,
25
- })}
26
- </DataGridToolbar>
27
- );
28
- }`.replace(/^\s+\n/gm, "");
29
- };
30
- exports.generateGridToolbar = generateGridToolbar;
31
- const getGridToolbarProps = (componentName, toolbarAction, exportApi) => {
32
- const props = [];
33
- if (toolbarAction) {
34
- props.push({
35
- destructured: "toolbarAction",
36
- typeDefinition: "toolbarAction?: ReactNode",
37
- });
38
- }
39
- if (exportApi) {
40
- props.push({
41
- destructured: "exportApi",
42
- typeDefinition: "exportApi: ExportApi",
43
- });
44
- }
45
- if (!props.length) {
46
- return "";
47
- }
48
- return `{
49
- ${props.map((prop) => `${prop.destructured}`).join(",")}
50
- }: ${componentName}ToolbarProps`;
51
- };
52
- const renderToolbarActions = ({ forwardToolbarAction, addItemText, excelExport, allowAdding }) => {
53
- const showMoreActionsMenu = excelExport;
54
- if (!showMoreActionsMenu && !allowAdding) {
55
- return "";
56
- }
57
- const moreActionsMenu = `<CrudMoreActionsMenu
58
- slotProps={{
59
- button: {
60
- responsive: true
61
- }
62
- }}
63
- overallActions={[
64
- ${excelExport
65
- ? `{
66
- label: <FormattedMessage {...messages.downloadAsExcel} />,
67
- icon: exportApi.loading ? <CircularProgress size={20} /> : <ExcelIcon />,
68
- onClick: () => exportApi.exportGrid(),
69
- disabled: exportApi.loading,
70
- }`
71
- : ""}
72
- ]}
73
- />`;
74
- const defaultAddItemButton = `<Button responsive startIcon={<AddIcon />} component={StackLink} pageName="add" payload="add">
75
- ${addItemText}
76
- </Button>`;
77
- const addAction = forwardToolbarAction ? "{toolbarAction}" : defaultAddItemButton;
78
- return `
79
- ${showMoreActionsMenu ? moreActionsMenu : ""}
80
- ${allowAdding ? addAction : ""}`;
81
- };
82
- const renderToolbarProps = (componentName, forwardToolbarAction, exportApi) => {
83
- if (forwardToolbarAction || exportApi) {
84
- return `interface ${componentName}ToolbarProps extends GridToolbarProps {
85
- ${forwardToolbarAction ? "toolbarAction: ReactNode;" : ""}
86
- ${exportApi ? "exportApi: ExportApi;" : ""}
87
- }`;
88
- }
89
- return "";
90
- };
@@ -1,13 +0,0 @@
1
- import { type IntrospectionField } from "graphql";
2
- import { type Imports } from "../utils/generateImportsCode";
3
- import { type Prop } from "./generateGrid";
4
- export type GqlArg = {
5
- type: string;
6
- name: string;
7
- queryOrMutationName: string;
8
- };
9
- export declare function getForwardedGqlArgs(gqlFields: IntrospectionField[]): {
10
- imports: Imports;
11
- prop: Prop;
12
- gqlArg: GqlArg;
13
- }[];
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getForwardedGqlArgs = getForwardedGqlArgs;
4
- function getForwardedGqlArgs(gqlFields) {
5
- const ret = [];
6
- const supportedGqlArgs = ["offset", "limit", "sort", "search", "filter", "input"]; // this arguments need to be handled differently or are already handled somewhere else
7
- getArgs(gqlFields, supportedGqlArgs).forEach((arg) => {
8
- let prop;
9
- const imports = [];
10
- if (arg.type === "ID" || arg.type === "String" || arg.type === "DateTime") {
11
- prop = { name: arg.name, optional: false, type: "string" };
12
- }
13
- else if (arg.type === "Boolean") {
14
- prop = { name: arg.name, optional: false, type: "boolean" };
15
- }
16
- else if (arg.type === "Int" || arg.type === "Float") {
17
- prop = { name: arg.name, optional: false, type: "number" };
18
- }
19
- else if (arg.type === "JSONObject") {
20
- prop = { name: arg.name, optional: false, type: "unknown" };
21
- }
22
- else {
23
- prop = { name: arg.name, optional: false, type: `GQL${arg.type}` }; // generated types contain GQL prefix
24
- imports.push({ name: `GQL${arg.type}`, importPath: "@src/graphql.generated" });
25
- }
26
- ret.push({ gqlArg: { name: arg.name, type: arg.type, queryOrMutationName: arg.gqlField.name }, prop, imports });
27
- });
28
- return ret;
29
- }
30
- function getArgs(gqlFields, skipGqlArgs) {
31
- return gqlFields.reduce((acc, gqlField) => {
32
- gqlField.args.forEach((gqlArg) => {
33
- if (skipGqlArgs.includes(gqlArg.name))
34
- return acc;
35
- if (gqlArg.type.kind !== "NON_NULL" || gqlArg.defaultValue)
36
- return acc;
37
- const gqlType = gqlArg.type.ofType;
38
- let type = "unknown";
39
- if (gqlType.kind === "SCALAR") {
40
- const nativeScalars = ["ID", "String", "Boolean", "Int", "Float", "DateTime", "JSONObject"];
41
- if (!nativeScalars.includes(gqlType.name)) {
42
- // probably just add to gqlFields-array, but needs to be tested
43
- console.warn(`Currently not supported special SCALAR of type ${gqlType.name} in param ${gqlArg.name} of ${gqlField.name}`);
44
- }
45
- else {
46
- type = gqlType.name;
47
- }
48
- }
49
- else if (gqlType.kind === "INPUT_OBJECT") {
50
- type = gqlType.name;
51
- }
52
- else {
53
- throw new Error(`Not supported kind ${gqlType.kind}, arg: ${gqlArg.name}`);
54
- }
55
- acc.push({ name: gqlArg.name, type, gqlArg, gqlField });
56
- });
57
- return acc;
58
- }, []);
59
- }
@@ -1,14 +0,0 @@
1
- import { type IntrospectionInputObjectType } from "graphql";
2
- import { type GridConfig } from "../generate-command";
3
- import { type Imports } from "../utils/generateImportsCode";
4
- import { type Prop } from "./generateGrid";
5
- export declare function getPropsForFilterProp<T extends {
6
- __typename?: string;
7
- }>({ config, filterType, }: {
8
- config: GridConfig<T>;
9
- filterType: IntrospectionInputObjectType;
10
- }): {
11
- hasFilterProp: boolean;
12
- imports: Imports;
13
- props: Prop[];
14
- };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPropsForFilterProp = getPropsForFilterProp;
4
- function getPropsForFilterProp({ config, filterType, }) {
5
- if (!config.filterProp)
6
- return { hasFilterProp: false, imports: [], props: [] };
7
- const filterTypeName = `GQL${filterType.name}`;
8
- return {
9
- hasFilterProp: true,
10
- imports: [{ name: filterTypeName, importPath: "@src/graphql.generated" }],
11
- props: [{ name: "filter", optional: true, type: filterTypeName }],
12
- };
13
- }
@@ -1,14 +0,0 @@
1
- type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
2
- type GqlLeaves<T, FollowArrays extends boolean = false, Depth extends number = 5> = [Depth] extends [never] ? never : T extends any ? T extends Array<infer ArrayType> ? FollowArrays extends true ? GqlLeaves<ArrayType, FollowArrays, Prev[Depth]> : never : "__typename" extends keyof T ? {
3
- [K in keyof T as K extends "__typename" ? never : K]-?: GqlLeaves<T[K], FollowArrays, Prev[Depth]>;
4
- } : never : never;
5
- type IfExplicitAny<T, Y, N> = T extends never ? Y : N;
6
- type FieldNames<T> = {
7
- [K in keyof T]: `${Exclude<K, symbol>}${FieldNames<T[K]> extends never ? "" : `.${FieldNames<T[K]>}`}`;
8
- }[keyof T];
9
- export type UsableFields<T, FollowArrays extends boolean = false> = IfExplicitAny<T, any, FieldNames<GqlLeaves<T, FollowArrays>>>;
10
- type FormFieldNames<T> = {
11
- [K in keyof T]: `${Exclude<K, symbol>}` | (FormFieldNames<T[K]> extends never ? never : `${Exclude<K, symbol>}.${FormFieldNames<T[K]>}`);
12
- }[keyof T];
13
- export type UsableFormFields<T> = IfExplicitAny<T, any, FormFieldNames<GqlLeaves<T, false>>>;
14
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare function camelCaseToHumanReadable(s: string): string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.camelCaseToHumanReadable = camelCaseToHumanReadable;
4
- const change_case_1 = require("change-case");
5
- function camelCaseToHumanReadable(s) {
6
- return (0, change_case_1.capitalCase)(s);
7
- }
@@ -1,6 +0,0 @@
1
- import { type Breakpoint } from "@mui/material";
2
- type BreakpointKey = `'${Breakpoint}'` | number;
3
- type SingleValueBrakpointTypes = "up" | "down" | "only" | "not";
4
- type MultiValueBrakpointTypes = "between";
5
- export type ColumnVisibleOption = `${SingleValueBrakpointTypes}(${BreakpointKey})` | `${MultiValueBrakpointTypes}(${BreakpointKey}, ${BreakpointKey})` | false;
6
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- import { type Imports } from "./generateImportsCode";
2
- export declare function convertConfigImport(imprt: {
3
- name: string;
4
- import: string;
5
- defaultImport?: boolean;
6
- }): Imports[0];
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertConfigImport = convertConfigImport;
4
- // generated code is one level below config, this function converts relative imports to go one level up
5
- function convertConfigImport(imprt) {
6
- let importPath = imprt.import;
7
- if (importPath.startsWith("../")) {
8
- importPath = `../${importPath}`;
9
- }
10
- else if (importPath.startsWith("./")) {
11
- importPath = `.${importPath}`;
12
- }
13
- return { name: imprt.name, importPath, defaultImport: imprt.defaultImport };
14
- }
@@ -1,3 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- export declare function findMutationType(mutationName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField | undefined;
3
- export declare function findMutationTypeOrThrow(mutationName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findMutationType = findMutationType;
4
- exports.findMutationTypeOrThrow = findMutationTypeOrThrow;
5
- function findMutationType(mutationName, schema) {
6
- if (!schema.__schema.mutationType)
7
- throw new Error("Schema has no Mutation type");
8
- const queryType = schema.__schema.types.find((type) => { var _a; return type.name === ((_a = schema.__schema.mutationType) === null || _a === void 0 ? void 0 : _a.name); });
9
- if (!queryType)
10
- throw new Error("Can't find Mutation type in gql schema");
11
- return queryType.fields.find((field) => field.name === mutationName);
12
- }
13
- function findMutationTypeOrThrow(mutationName, schema) {
14
- const ret = findMutationType(mutationName, schema);
15
- if (!ret)
16
- throw new Error(`Can't find Mutation ${mutationName} in gql schema`);
17
- return ret;
18
- }
@@ -1,2 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- export declare function findQueryTypeOrThrow(queryName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findQueryTypeOrThrow = findQueryTypeOrThrow;
4
- function findQueryType(queryName, schema) {
5
- const queryType = schema.__schema.types.find((type) => type.name === schema.__schema.queryType.name);
6
- if (!queryType)
7
- throw new Error("Can't find Query type in gql schema");
8
- const ret = queryType.fields.find((field) => field.name === queryName);
9
- if (!ret)
10
- throw new Error(`Can't find query ${queryName} in gql schema`);
11
- return ret;
12
- }
13
- function findQueryTypeOrThrow(queryName, schema) {
14
- const ret = findQueryType(queryName, schema);
15
- if (!ret)
16
- throw new Error(`Can't find query ${queryName} in gql schema`);
17
- return ret;
18
- }
@@ -1,8 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- export declare function findRootBlocks({ gqlType, targetDirectory }: {
3
- gqlType: string;
4
- targetDirectory: string;
5
- }, schema: IntrospectionQuery): Record<string, {
6
- import: string;
7
- name: string;
8
- }>;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findRootBlocks = findRootBlocks;
4
- const fs_1 = require("fs");
5
- const fallbackLibraryBlocks = {
6
- AnchorBlock: "@comet/cms-admin",
7
- DamImageBlock: "@comet/cms-admin",
8
- DamVideoBlock: "@comet/cms-admin",
9
- ExternalLinkBlock: "@comet/cms-admin",
10
- InternalLinkBlock: "@comet/cms-admin",
11
- PixelImageBlock: "@comet/cms-admin",
12
- SpaceBlock: "@comet/cms-admin",
13
- SvgImageBlock: "@comet/cms-admin",
14
- YouTubeVideoBlock: "@comet/cms-admin",
15
- };
16
- function findRootBlocks({ gqlType, targetDirectory }, schema) {
17
- const ret = {};
18
- const schemaEntity = schema.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
19
- if (!schemaEntity)
20
- throw new Error("didn't find entity in schema types");
21
- schemaEntity.fields.forEach((field) => {
22
- if (ret[field.name])
23
- return; // already defined
24
- let type = field.type;
25
- if (type.kind == "NON_NULL")
26
- type = type.ofType;
27
- if (type.kind == "SCALAR" && type.name.endsWith("BlockData")) {
28
- let match = false;
29
- const blockName = `${type.name.replace(/BlockData$/, "")}Block`;
30
- const checkNames = [
31
- {
32
- folderName: `${targetDirectory.replace(/\/generated$/, "")}/blocks`,
33
- import: `../blocks/${blockName}`,
34
- },
35
- {
36
- folderName: `src/common/blocks`,
37
- import: `@src/common/blocks/${blockName}`,
38
- },
39
- ];
40
- for (const checkName of checkNames) {
41
- if ((0, fs_1.existsSync)(`${checkName.folderName}/${blockName}.tsx`)) {
42
- match = true;
43
- ret[field.name] = {
44
- import: checkName.import,
45
- name: blockName,
46
- };
47
- break;
48
- }
49
- }
50
- if (!match) {
51
- const fallback = fallbackLibraryBlocks[blockName];
52
- if (fallback) {
53
- ret[field.name] = {
54
- import: fallback,
55
- name: blockName,
56
- };
57
- match = true;
58
- }
59
- }
60
- if (!match) {
61
- throw new Error(`Didn't find admin block for ${blockName} in ${checkNames.map((c) => c.folderName).join(" or ")}`);
62
- }
63
- }
64
- });
65
- return ret;
66
- }
@@ -1,12 +0,0 @@
1
- export declare function generateGqlQueryTreeFromFields(fields: string[]): string;
2
- export declare function generateGqlOperation(options: {
3
- type: "query" | "mutation";
4
- operationName: string;
5
- rootOperation: string;
6
- variables?: {
7
- name: string;
8
- type: string;
9
- }[];
10
- fields: string[];
11
- fragmentVariables?: string[];
12
- }): string;
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateGqlQueryTreeFromFields = generateGqlQueryTreeFromFields;
4
- exports.generateGqlOperation = generateGqlOperation;
5
- function generateGqlQueryTreeFromFields(fields) {
6
- // Helper to get or create a node at a given path
7
- function getOrCreateNode(root, path) {
8
- let node = root;
9
- for (const part of path) {
10
- if (!node.children[part]) {
11
- node.children[part] = { children: {}, fragments: [] };
12
- }
13
- node = node.children[part];
14
- }
15
- return node;
16
- }
17
- // 1. create tree out of dot separated fields
18
- const root = { children: {}, fragments: [] };
19
- for (const field of fields) {
20
- const fragmentMatch = field.match(/(.*)(\.{3}.*)/);
21
- if (fragmentMatch) {
22
- // e.g. foo.bar...Fragment
23
- const key = fragmentMatch[1].trim();
24
- const fragment = fragmentMatch[2].trim();
25
- if (key === "") {
26
- root.fragments.push(fragment);
27
- }
28
- else {
29
- const path = key.split(".").filter(Boolean);
30
- const node = getOrCreateNode(root, path);
31
- node.fragments.push(fragment);
32
- }
33
- }
34
- else {
35
- // e.g. foo.bar.baz
36
- const path = field.split(".").filter(Boolean);
37
- if (path.length === 0)
38
- continue;
39
- // Mark the leaf node (no need to store field names, just ensure the path exists)
40
- getOrCreateNode(root, path);
41
- }
42
- }
43
- // 2. create fragment string out of tree
44
- function recursiveStringify(node) {
45
- const parts = [];
46
- // Add fields (children)
47
- for (const key of Object.keys(node.children)) {
48
- const child = node.children[key];
49
- const childStr = recursiveStringify(child);
50
- if (childStr) {
51
- parts.push(`${key} { ${childStr} }`);
52
- }
53
- else {
54
- parts.push(key);
55
- }
56
- }
57
- // Add fragments
58
- if (node.fragments.length > 0) {
59
- parts.push(...node.fragments);
60
- }
61
- return parts.join(" ");
62
- }
63
- return recursiveStringify(root);
64
- }
65
- function generateGqlOperation(options) {
66
- var _a;
67
- let queryArgs = "";
68
- if (options.variables && options.variables.length > 0) {
69
- queryArgs += `(`;
70
- queryArgs += options.variables.map((v) => `$${v.name}: ${v.type}`).join(", ");
71
- queryArgs += `)`;
72
- }
73
- let rootQueryArgs = "";
74
- if (options.variables && options.variables.length > 0) {
75
- rootQueryArgs += `(`;
76
- rootQueryArgs += options.variables.map((v) => `${v.name}: $${v.name}`).join(", ");
77
- rootQueryArgs += `)`;
78
- }
79
- return `
80
- ${options.type} ${options.operationName}${queryArgs} {
81
- ${options.rootOperation}${rootQueryArgs} {
82
- ${generateGqlQueryTreeFromFields(options.fields)}
83
- }
84
- }
85
- ${((_a = options.fragmentVariables) !== null && _a !== void 0 ? _a : []).join("\n")}
86
- `;
87
- }
@@ -1,6 +0,0 @@
1
- export type Imports = Array<{
2
- name: string;
3
- importPath: string;
4
- defaultImport?: boolean;
5
- }>;
6
- export declare function generateImportsCode(imports: Imports): string;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateImportsCode = generateImportsCode;
4
- // generate imports code and filter duplicates
5
- function generateImportsCode(imports) {
6
- const importsNameToPath = new Map(); // name -> importPath
7
- const filteredImports = imports.filter((imp) => {
8
- if (importsNameToPath.has(imp.name)) {
9
- if (importsNameToPath.get(imp.name) !== imp.importPath) {
10
- throw new Error(`Duplicate import name ${imp.name}`);
11
- }
12
- else {
13
- // duplicate import, skip
14
- return false;
15
- }
16
- }
17
- importsNameToPath.set(imp.name, imp.importPath);
18
- return true;
19
- });
20
- const importsString = filteredImports
21
- .map((imp) => {
22
- if (imp.defaultImport) {
23
- return `import ${imp.name} from "${imp.importPath}";`;
24
- }
25
- else {
26
- return `import { ${imp.name} } from "${imp.importPath}";`;
27
- }
28
- })
29
- .join("\n");
30
- return importsString;
31
- }
@@ -1,20 +0,0 @@
1
- import { type ComponentProps, type ReactElement } from "react";
2
- import { FormattedMessage } from "react-intl";
3
- import { type FormattedMessageElement } from "../generate-command";
4
- type GenerateFormattedMessageOptions = ({
5
- config: string | FormattedMessageElement | undefined;
6
- defaultMessage: string;
7
- } | {
8
- config: string | FormattedMessageElement;
9
- }) & {
10
- id: string;
11
- type: "jsx" | "intlCall";
12
- };
13
- export declare function isFormattedMessageElement(node: unknown): node is ReactElement<ComponentProps<typeof FormattedMessage>, typeof FormattedMessage>;
14
- /**
15
- * Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
16
- *
17
- * either config or defaultMessage is required
18
- */
19
- export declare const generateFormattedMessage: (options: GenerateFormattedMessageOptions) => string;
20
- export {};
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFormattedMessage = void 0;
4
- exports.isFormattedMessageElement = isFormattedMessageElement;
5
- const react_1 = require("react");
6
- const react_intl_1 = require("react-intl");
7
- function isFormattedMessageElement(node) {
8
- return (0, react_1.isValidElement)(node) && node.type === react_intl_1.FormattedMessage;
9
- }
10
- /**
11
- * Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
12
- *
13
- * either config or defaultMessage is required
14
- */
15
- const generateFormattedMessage = (options) => {
16
- let id = options.id;
17
- let defaultMessage = "";
18
- if ("defaultMessage" in options) {
19
- defaultMessage = options.defaultMessage;
20
- }
21
- if (isFormattedMessageElement(options.config)) {
22
- if (!options.config.props.id) {
23
- throw new Error("FormattedMessage requires an id");
24
- }
25
- id = options.config.props.id;
26
- if (!options.config.props.defaultMessage) {
27
- throw new Error("FormattedMessage requires an defaultMessage");
28
- }
29
- if (typeof options.config.props.defaultMessage !== "string") {
30
- throw new Error("FormattedMessage requires a string defaultMessage");
31
- }
32
- defaultMessage = options.config.props.defaultMessage;
33
- }
34
- else if (typeof options.config === "string") {
35
- defaultMessage = options.config;
36
- }
37
- if (options.type === "jsx") {
38
- return `<FormattedMessage id=${JSON.stringify(id)} defaultMessage=${JSON.stringify(defaultMessage)} />`;
39
- }
40
- else {
41
- return `intl.formatMessage({ id: ${JSON.stringify(id)}, defaultMessage: ${JSON.stringify(defaultMessage)} })`;
42
- }
43
- };
44
- exports.generateFormattedMessage = generateFormattedMessage;
@@ -1,7 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- import { type FormFieldConfig } from "../generate-command";
3
- export declare const isFieldOptional: ({ config, gqlIntrospection, gqlType, }: {
4
- config: FormFieldConfig<any>;
5
- gqlIntrospection: IntrospectionQuery;
6
- gqlType: string;
7
- }) => boolean;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFieldOptional = void 0;
4
- const isFieldOptional = ({ config, gqlIntrospection, gqlType, }) => {
5
- if (config.required !== undefined) {
6
- return !config.required;
7
- }
8
- if (config.readOnly) {
9
- return true;
10
- }
11
- const schemaEntity = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
12
- if (!schemaEntity)
13
- throw new Error(`didn't find entity ${gqlType} in schema types`);
14
- if (schemaEntity.kind !== "OBJECT")
15
- throw new Error(`kind of ${gqlType} is not object, but should be.`); // this should not happen
16
- const fieldDef = schemaEntity.fields.find((field) => field.name === String(config.name));
17
- if (!fieldDef)
18
- return false;
19
- return fieldDef.type.kind !== "NON_NULL";
20
- };
21
- exports.isFieldOptional = isFieldOptional;