@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.7 → 6.2.3-dev.71
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/dist/browser/document-models/index.js +2 -1
- package/dist/browser/documents-BLZ-QW5b.js +16 -0
- package/dist/browser/documents-BLZ-QW5b.js.map +1 -0
- package/dist/browser/{editor-DHysndk4.js → editor-Dmpkd8pQ.js} +4 -5
- package/dist/browser/{editor-DHysndk4.js.map → editor-Dmpkd8pQ.js.map} +1 -1
- package/dist/browser/{editor-6T4WF2og.js → editor-x1UIfSot.js} +740 -272
- package/dist/browser/editor-x1UIfSot.js.map +1 -0
- package/dist/browser/editors/document-model-editor/module.js +1 -1
- package/dist/browser/editors/document-model-editor/module.js.map +1 -1
- package/dist/browser/editors/generic-drive-explorer/index.js +4 -324
- package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
- package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
- package/dist/browser/editors/generic-drive-explorer/module.js.map +1 -1
- package/dist/browser/{folder-view-DTewe8q8.js → folder-view-CwIU4XEe.js} +17 -12
- package/dist/browser/folder-view-CwIU4XEe.js.map +1 -0
- package/dist/browser/graphql-editor-CpcGaYmP.js +103 -0
- package/dist/browser/graphql-editor-CpcGaYmP.js.map +1 -0
- package/dist/browser/hooks-BmHa-lY2.js +126 -0
- package/dist/browser/hooks-BmHa-lY2.js.map +1 -0
- package/dist/browser/index.js +6 -703
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/json-editor-CB1XmZgN.js +55 -0
- package/dist/browser/json-editor-CB1XmZgN.js.map +1 -0
- package/dist/browser/{schema-context-ZyeclQwy.js → schema-context-5evhtuMb.js} +6 -5
- package/dist/browser/{schema-context-ZyeclQwy.js.map → schema-context-5evhtuMb.js.map} +1 -1
- package/dist/browser/{state-schemas-CpcWN_Qo.js → state-schemas-DHLAg1w0.js} +20 -18
- package/dist/browser/state-schemas-DHLAg1w0.js.map +1 -0
- package/dist/{browser/dist-BAJ5nRDl.js → node/bundle-mjs-Cuu3DEfT.mjs} +1251 -822
- package/dist/node/bundle-mjs-Cuu3DEfT.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +2 -1
- package/dist/node/{graphql-BfAoPeWM.mjs → documents-CFiuC6XV.mjs} +64 -50
- package/dist/node/documents-CFiuC6XV.mjs.map +1 -0
- package/dist/node/editor-7g9ujMII.mjs +4747 -0
- package/dist/node/editor-7g9ujMII.mjs.map +1 -0
- package/dist/node/{editor-DPv5LEug.mjs → editor-NwTlNx8z.mjs} +4 -5
- package/dist/node/{editor-DPv5LEug.mjs.map → editor-NwTlNx8z.mjs.map} +1 -1
- package/dist/node/editors/document-model-editor/module.mjs +1 -1
- package/dist/node/editors/document-model-editor/module.mjs.map +1 -1
- package/dist/node/editors/generic-drive-explorer/index.mjs +26 -21
- package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
- package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
- package/dist/node/editors/generic-drive-explorer/module.mjs.map +1 -1
- package/dist/node/folder-view-CkCNU8A_.mjs +966 -0
- package/dist/node/folder-view-CkCNU8A_.mjs.map +1 -0
- package/dist/node/{graphql-editor-D0CHQeCL.mjs → graphql-editor-v1OXETjM.mjs} +5130 -63
- package/dist/node/graphql-editor-v1OXETjM.mjs.map +1 -0
- package/dist/node/{hooks-D0DcS3MV.mjs → hooks-gEAaW5rF.mjs} +824 -444
- package/dist/node/{hooks-D0DcS3MV.mjs.map → hooks-gEAaW5rF.mjs.map} +1 -1
- package/dist/node/index.mjs +38 -90
- package/dist/node/index.mjs.map +1 -1
- package/dist/{browser/json-editor-xI_oaxyT.js → node/json-editor-8dfjgcaX.mjs} +8 -9
- package/dist/node/{json-editor-Ckaem6ky.mjs.map → json-editor-8dfjgcaX.mjs.map} +1 -1
- package/dist/node/rolldown-runtime-Bl3dcgcQ.mjs +16 -0
- package/dist/node/{schema-context-DL8jhi_d.mjs → schema-context-DgUu7l_Q.mjs} +5 -5
- package/dist/node/schema-context-DgUu7l_Q.mjs.map +1 -0
- package/dist/node/state-schemas-DXWpf1zO.mjs +1064 -0
- package/dist/node/state-schemas-DXWpf1zO.mjs.map +1 -0
- package/package.json +25 -23
- package/style.css +2 -0
- package/dist/browser/assets/entry-DSBtQnit.js +0 -314
- package/dist/browser/assets/projection-entry-Bem3exmO.js +0 -404
- package/dist/browser/button-CuO8Gh3v.js +0 -696
- package/dist/browser/button-CuO8Gh3v.js.map +0 -1
- package/dist/browser/connect-5NZDVmbb.js +0 -14328
- package/dist/browser/connect-5NZDVmbb.js.map +0 -1
- package/dist/browser/dist-1yB-AuT-.js +0 -4641
- package/dist/browser/dist-1yB-AuT-.js.map +0 -1
- package/dist/browser/dist-B4FWbuEM.js +0 -4148
- package/dist/browser/dist-B4FWbuEM.js.map +0 -1
- package/dist/browser/dist-BAJ5nRDl.js.map +0 -1
- package/dist/browser/document-drive-CrvzV1D4.js +0 -8319
- package/dist/browser/document-drive-CrvzV1D4.js.map +0 -1
- package/dist/browser/documents-J_l59mSV.js +0 -6188
- package/dist/browser/documents-J_l59mSV.js.map +0 -1
- package/dist/browser/editor-6T4WF2og.js.map +0 -1
- package/dist/browser/folder-view-DTewe8q8.js.map +0 -1
- package/dist/browser/graphql-editor-C2EtXqb9.js +0 -11698
- package/dist/browser/graphql-editor-C2EtXqb9.js.map +0 -1
- package/dist/browser/hooks-KKcNp2X0.js +0 -24213
- package/dist/browser/hooks-KKcNp2X0.js.map +0 -1
- package/dist/browser/json-editor-xI_oaxyT.js.map +0 -1
- package/dist/browser/lib-CPkPeg_u.js +0 -209
- package/dist/browser/lib-CPkPeg_u.js.map +0 -1
- package/dist/browser/parser-CkF6Qt8V.js +0 -2553
- package/dist/browser/parser-CkF6Qt8V.js.map +0 -1
- package/dist/browser/printer-CEYr4JOg.js +0 -604
- package/dist/browser/printer-CEYr4JOg.js.map +0 -1
- package/dist/browser/state-schemas-CpcWN_Qo.js.map +0 -1
- package/dist/node/button-Da7CxMn7.mjs +0 -678
- package/dist/node/button-Da7CxMn7.mjs.map +0 -1
- package/dist/node/connect-cjzsd2cR.mjs +0 -15022
- package/dist/node/connect-cjzsd2cR.mjs.map +0 -1
- package/dist/node/dist-C30J_pcg.mjs +0 -4649
- package/dist/node/dist-C30J_pcg.mjs.map +0 -1
- package/dist/node/dist-CzYOpeXN.mjs +0 -2711
- package/dist/node/dist-CzYOpeXN.mjs.map +0 -1
- package/dist/node/dist-DT7jI9ol.mjs +0 -4148
- package/dist/node/dist-DT7jI9ol.mjs.map +0 -1
- package/dist/node/document-drive-BByBwg-I.mjs +0 -8336
- package/dist/node/document-drive-BByBwg-I.mjs.map +0 -1
- package/dist/node/documents-DCf53bzO.mjs +0 -747
- package/dist/node/documents-DCf53bzO.mjs.map +0 -1
- package/dist/node/editor-B4vhYrmV.mjs +0 -1809
- package/dist/node/editor-B4vhYrmV.mjs.map +0 -1
- package/dist/node/folder-view-BhackcXO.mjs +0 -232
- package/dist/node/folder-view-BhackcXO.mjs.map +0 -1
- package/dist/node/graphql-BfAoPeWM.mjs.map +0 -1
- package/dist/node/graphql-editor-D0CHQeCL.mjs.map +0 -1
- package/dist/node/json-editor-Ckaem6ky.mjs +0 -154
- package/dist/node/main-BhH_ajBM.mjs +0 -745
- package/dist/node/main-BhH_ajBM.mjs.map +0 -1
- package/dist/node/schema-context-DL8jhi_d.mjs.map +0 -1
- package/dist/node/state-schemas-B1SNl8Ob.mjs +0 -299
- package/dist/node/state-schemas-B1SNl8Ob.mjs.map +0 -1
|
@@ -1,223 +1,704 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as Kind, t as parse$1 } from "./parser-CkF6Qt8V.js";
|
|
4
|
-
import { t as print } from "./printer-CEYr4JOg.js";
|
|
5
|
-
import { a as compareStringsWithoutWhitespace, c as isEmptyOperationSchema, f as makeOperationInitialDoc, l as makeEmptyOperationSchema, m as renameSchemaType, n as ensureValidOperationSchemaInputName, o as handleModelNameChange, s as initializeModelSchema, t as Button, u as makeInitialSchemaDoc } from "./button-CuO8Gh3v.js";
|
|
6
|
-
import { _ as Modal, a as DocumentToolbar, b as Primitive, c as ModalButton, d as FormProvider, f as appendErrors, g as useFormContext, h as useForm, m as set, p as get, r as ConnectSelect, u as Controller, x as Slot } from "./connect-5NZDVmbb.js";
|
|
7
|
-
import { w as twMerge } from "./dist-BAJ5nRDl.js";
|
|
8
|
-
import { j as usePHToast, v as useSetPHDocumentEditorConfig, x as useSelectedDocumentOfType } from "./dist-1yB-AuT-.js";
|
|
9
|
-
import { t as SchemaContextProvider } from "./schema-context-ZyeclQwy.js";
|
|
1
|
+
import { n as safeParseSdl, t as SchemaContextProvider } from "./schema-context-5evhtuMb.js";
|
|
2
|
+
import { addModule, addOperation, addOperationError, deleteModule, deleteOperation, deleteOperationError, generateId, releaseNewVersion, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleName, setOperationDescription, setOperationErrorName, setOperationName, setOperationSchema, setStateSchema } from "@powerhousedao/shared/document-model";
|
|
10
3
|
import * as React$1 from "react";
|
|
11
4
|
import React, { Suspense, forwardRef, lazy, useCallback, useEffect, useId, useImperativeHandle, useRef, useState } from "react";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
//#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const variantProp = props === null || props === void 0 ? void 0 : props[variant];
|
|
36
|
-
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
|
|
37
|
-
if (variantProp === null) return null;
|
|
38
|
-
const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
|
|
39
|
-
return variants[variant][variantKey];
|
|
40
|
-
});
|
|
41
|
-
const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
|
|
42
|
-
let [key, value] = param;
|
|
43
|
-
if (value === void 0) return acc;
|
|
44
|
-
acc[key] = value;
|
|
45
|
-
return acc;
|
|
46
|
-
}, {});
|
|
47
|
-
return cx(base, getVariantClassNames, config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1) => {
|
|
48
|
-
let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param1;
|
|
49
|
-
return Object.entries(compoundVariantOptions).every((param) => {
|
|
50
|
-
let [key, value] = param;
|
|
51
|
-
return Array.isArray(value) ? value.includes({
|
|
52
|
-
...defaultVariants,
|
|
53
|
-
...propsWithoutUndefined
|
|
54
|
-
}[key]) : {
|
|
55
|
-
...defaultVariants,
|
|
56
|
-
...propsWithoutUndefined
|
|
57
|
-
}[key] === value;
|
|
58
|
-
}) ? [
|
|
59
|
-
...acc,
|
|
60
|
-
cvClass,
|
|
61
|
-
cvClassName
|
|
62
|
-
] : acc;
|
|
63
|
-
}, []), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
64
|
-
};
|
|
5
|
+
import { ConnectSelect, DocumentToolbar, Modal, ModalButton } from "@powerhousedao/design-system/connect";
|
|
6
|
+
import { usePHToast, useSetPHDocumentEditorConfig } from "@powerhousedao/reactor-browser";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { twMerge } from "tailwind-merge";
|
|
9
|
+
import { GraphQLError, Kind, buildASTSchema, getOperationAST, getVariableValues, parse, print, visit } from "graphql";
|
|
10
|
+
import { getPHCustomScalarByTypeName } from "@powerhousedao/document-engineering/graphql";
|
|
11
|
+
import { constantCase, pascalCase, sentenceCase, snakeCase } from "change-case";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
14
|
+
import { Controller, FormProvider, useForm, useFormContext } from "react-hook-form";
|
|
15
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
16
|
+
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
17
|
+
import { cva } from "class-variance-authority";
|
|
18
|
+
//#region \0rolldown/runtime.js
|
|
19
|
+
var __defProp = Object.defineProperty;
|
|
20
|
+
var __exportAll = (all, no_symbols) => {
|
|
21
|
+
let target = {};
|
|
22
|
+
for (var name in all) __defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true
|
|
25
|
+
});
|
|
26
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
27
|
+
return target;
|
|
65
28
|
};
|
|
66
29
|
//#endregion
|
|
67
|
-
//#region editors/document-model-editor/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
30
|
+
//#region editors/document-model-editor/constants/graphql-kinds.ts
|
|
31
|
+
const STRING_GQL_PRIMITIVE_NAME = "String";
|
|
32
|
+
const BOOLEAN_GQL_PRIMITIVE_NAME = "Boolean";
|
|
33
|
+
const FLOAT_GQL_PRIMITIVE_NAME = "Float";
|
|
34
|
+
const gqlPrimitiveNodeNamesList = [
|
|
35
|
+
STRING_GQL_PRIMITIVE_NAME,
|
|
36
|
+
BOOLEAN_GQL_PRIMITIVE_NAME,
|
|
37
|
+
"Int",
|
|
38
|
+
FLOAT_GQL_PRIMITIVE_NAME,
|
|
39
|
+
"ID"
|
|
40
|
+
];
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region editors/document-model-editor/utils/helpers.ts
|
|
43
|
+
function makeStateSchemaNameForScope(modelName, scope) {
|
|
44
|
+
const modelNamePascalCase = pascalCase(modelName);
|
|
45
|
+
const scopePascalCase = pascalCase(scope);
|
|
46
|
+
return scopePascalCase === "Global" ? `${modelNamePascalCase}State` : `${modelNamePascalCase}${scopePascalCase}State`;
|
|
47
|
+
}
|
|
48
|
+
function makeInitialSchemaDoc(modelName, scope) {
|
|
49
|
+
return `type ${makeStateSchemaNameForScope(modelName, scope)} {
|
|
50
|
+
"Add your ${scope} state fields here"
|
|
51
|
+
_placeholder: String
|
|
52
|
+
}`;
|
|
53
|
+
}
|
|
54
|
+
function makeOperationInitialDoc(name) {
|
|
55
|
+
return `input ${pascalCase(name)}Input {
|
|
56
|
+
"Add your inputs here"
|
|
57
|
+
_placeholder: String
|
|
58
|
+
}`;
|
|
59
|
+
}
|
|
60
|
+
function makeEmptyOperationSchema(operationName) {
|
|
61
|
+
return `input ${pascalCase(operationName)}Input {\n _empty: Boolean\n}`;
|
|
62
|
+
}
|
|
63
|
+
function isEmptyOperationSchema(schema) {
|
|
64
|
+
if (!schema) return false;
|
|
65
|
+
return /_empty:\s*Boolean/.test(schema) && !schema.replace(/_empty:\s*Boolean/, "").match(/\w+:\s*\w+/);
|
|
66
|
+
}
|
|
67
|
+
function safeParseJsonRecord(json) {
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(json);
|
|
70
|
+
} catch (_error) {
|
|
71
|
+
return null;
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
}
|
|
74
|
+
function makeMinimalObjectForStateType(args) {
|
|
75
|
+
const { sharedSchemaDocumentNode, stateTypeDefinitionNode, existingValue } = args;
|
|
76
|
+
const existingValueObject = safeParseJsonRecord(existingValue);
|
|
77
|
+
if (!existingValueObject) return existingValue;
|
|
78
|
+
const stateTypeDefinitionFields = stateTypeDefinitionNode.fields;
|
|
79
|
+
if (!stateTypeDefinitionFields?.length) return existingValue;
|
|
80
|
+
const minimalObject = makeMinimalValuesForObjectFields({
|
|
81
|
+
schemaDocumentNode: sharedSchemaDocumentNode,
|
|
82
|
+
fieldDefinitionNodes: stateTypeDefinitionFields,
|
|
83
|
+
existingValueObject,
|
|
84
|
+
visitedTypes: /* @__PURE__ */ new Set([stateTypeDefinitionNode.name.value])
|
|
85
|
+
});
|
|
86
|
+
return JSON.stringify(minimalObject, null, 2);
|
|
87
|
+
}
|
|
88
|
+
function makeMinimalValuesForObjectFields(args) {
|
|
89
|
+
const { schemaDocumentNode, existingValueObject, fieldDefinitionNodes, visitedTypes } = args;
|
|
90
|
+
const newJson = {};
|
|
91
|
+
for (const astNode of fieldDefinitionNodes) {
|
|
92
|
+
const fieldName = getASTNodeName(astNode);
|
|
93
|
+
if (!fieldName) continue;
|
|
94
|
+
const minimalValue = makeMinimalValueForASTNode({
|
|
95
|
+
fieldName,
|
|
96
|
+
astNode,
|
|
97
|
+
schemaDocumentNode,
|
|
98
|
+
existingValueObject,
|
|
99
|
+
visitedTypes
|
|
100
|
+
});
|
|
101
|
+
newJson[astNode.name.value] = minimalValue;
|
|
78
102
|
}
|
|
79
|
-
return
|
|
103
|
+
return newJson;
|
|
80
104
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
function makeMinimalValueForASTNode(args) {
|
|
106
|
+
const { fieldName, astNode, schemaDocumentNode, existingValueObject, visitedTypes } = args;
|
|
107
|
+
const existingFieldValue = existingValueObject?.[fieldName];
|
|
108
|
+
let node = astNode;
|
|
109
|
+
if (isFieldDefinitionNode(astNode)) node = getASTNodeTypeNode(node);
|
|
110
|
+
const isNonNull = isNonNullNode(node);
|
|
111
|
+
if (isNonNull) node = getASTNodeTypeNode(node);
|
|
112
|
+
if (isListTypeNode(node)) return makeMinimalValueForGqlListNode(node, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes);
|
|
113
|
+
if (isGqlPrimitiveNode(node)) return makeMinimalValueForGQLPrimitiveNode(node, existingFieldValue, isNonNull);
|
|
114
|
+
const namedTypeDefinitionNode = getNamedTypeDefinitionNode(node, schemaDocumentNode);
|
|
115
|
+
if (isEnumTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull);
|
|
116
|
+
if (isScalarTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlScalar(namedTypeDefinitionNode, existingFieldValue, isNonNull);
|
|
117
|
+
if (isUnionTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes);
|
|
118
|
+
if (isObjectTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlObject(namedTypeDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
|
|
119
|
+
return existingFieldValue;
|
|
120
|
+
}
|
|
121
|
+
function isFieldDefinitionNode(astNodeTypeNode) {
|
|
122
|
+
if (!astNodeTypeNode) return false;
|
|
123
|
+
return astNodeTypeNode.kind === Kind.FIELD_DEFINITION;
|
|
124
|
+
}
|
|
125
|
+
function isNonNullNode(astNode) {
|
|
126
|
+
if (!astNode) return false;
|
|
127
|
+
return astNode.kind === Kind.NON_NULL_TYPE;
|
|
128
|
+
}
|
|
129
|
+
function isGqlPrimitiveNode(astNodeTypeNode) {
|
|
130
|
+
if (!astNodeTypeNode) return false;
|
|
131
|
+
const name = getASTNodeName(astNodeTypeNode);
|
|
132
|
+
return gqlPrimitiveNodeNamesList.includes(name);
|
|
133
|
+
}
|
|
134
|
+
function isListTypeNode(astNodeTypeNode) {
|
|
135
|
+
if (!astNodeTypeNode) return false;
|
|
136
|
+
return astNodeTypeNode.kind === Kind.LIST_TYPE;
|
|
137
|
+
}
|
|
138
|
+
function isEnumTypeDefinitionNode(definitionNode) {
|
|
139
|
+
if (!definitionNode) return false;
|
|
140
|
+
return definitionNode.kind === Kind.ENUM_TYPE_DEFINITION;
|
|
141
|
+
}
|
|
142
|
+
function isScalarTypeDefinitionNode(definitionNode) {
|
|
143
|
+
if (!definitionNode) return false;
|
|
144
|
+
return definitionNode.kind === Kind.SCALAR_TYPE_DEFINITION;
|
|
145
|
+
}
|
|
146
|
+
function isUnionTypeDefinitionNode(definitionNode) {
|
|
147
|
+
if (!definitionNode) return false;
|
|
148
|
+
return definitionNode.kind === Kind.UNION_TYPE_DEFINITION;
|
|
149
|
+
}
|
|
150
|
+
function isObjectTypeDefinitionNode(definitionNode) {
|
|
151
|
+
if (!definitionNode) return false;
|
|
152
|
+
return definitionNode.kind === Kind.OBJECT_TYPE_DEFINITION;
|
|
153
|
+
}
|
|
154
|
+
function getASTNodeName(astNode) {
|
|
155
|
+
if (!astNode) return null;
|
|
156
|
+
if (!("name" in astNode)) return null;
|
|
157
|
+
if (!astNode.name) return null;
|
|
158
|
+
if (!("value" in astNode.name)) return null;
|
|
159
|
+
return astNode.name.value;
|
|
160
|
+
}
|
|
161
|
+
function getASTNodeTypeNode(astNode) {
|
|
162
|
+
if (!astNode) return null;
|
|
163
|
+
if (!("type" in astNode)) return null;
|
|
164
|
+
return astNode.type;
|
|
165
|
+
}
|
|
166
|
+
function makeMinimalValueForGQLPrimitiveNode(primitiveTypeNode, existingFieldValue, isNonNull) {
|
|
167
|
+
const name = getASTNodeName(primitiveTypeNode);
|
|
168
|
+
if (!name) return null;
|
|
169
|
+
switch (name) {
|
|
170
|
+
case "ID":
|
|
171
|
+
if (z.string().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
172
|
+
return isNonNull ? "placeholder-id" : null;
|
|
173
|
+
case BOOLEAN_GQL_PRIMITIVE_NAME:
|
|
174
|
+
if (z.boolean().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
175
|
+
return isNonNull ? false : null;
|
|
176
|
+
case "Int":
|
|
177
|
+
if (z.number().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
178
|
+
return isNonNull ? 0 : null;
|
|
179
|
+
case FLOAT_GQL_PRIMITIVE_NAME:
|
|
180
|
+
if (z.number().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
181
|
+
return isNonNull ? 0 : null;
|
|
182
|
+
case STRING_GQL_PRIMITIVE_NAME:
|
|
183
|
+
if (z.string().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
184
|
+
return isNonNull ? "" : null;
|
|
87
185
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
186
|
+
return isNonNull ? existingFieldValue : null;
|
|
187
|
+
}
|
|
188
|
+
function makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull) {
|
|
189
|
+
const enumValues = namedTypeDefinitionNode.values?.map((value) => value.name.value) ?? [];
|
|
190
|
+
if (typeof existingFieldValue === "string" && enumValues.includes(existingFieldValue)) return existingFieldValue;
|
|
191
|
+
if (isNonNull) return enumValues[0];
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
function makeMinimalValueForGqlScalar(scalarTypeDefinitionNode, existingFieldValue, isNonNull) {
|
|
195
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
196
|
+
const name = getASTNodeName(scalarTypeDefinitionNode);
|
|
197
|
+
if (!name) {
|
|
198
|
+
console.error("No name for scalar type definition node", scalarTypeDefinitionNode);
|
|
199
|
+
return null;
|
|
92
200
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
201
|
+
const scalar = getPHCustomScalarByTypeName(name);
|
|
202
|
+
if (!scalar) return null;
|
|
203
|
+
if (scalar.schema.safeParse(existingFieldValue).success) return existingFieldValue;
|
|
204
|
+
if (!isNonNull) return null;
|
|
205
|
+
const minimalValue = scalar.getDefaultValue?.();
|
|
206
|
+
if (minimalValue) return minimalValue;
|
|
207
|
+
return existingFieldValue;
|
|
208
|
+
}
|
|
209
|
+
function makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes) {
|
|
210
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
211
|
+
if (!namedTypeDefinitionNode.types?.length) return null;
|
|
212
|
+
const firstNamedTypeDefinitionNode = namedTypeDefinitionNode.types?.at(0);
|
|
213
|
+
if (!firstNamedTypeDefinitionNode) return null;
|
|
214
|
+
const firstNamedTypeObjectDefinitionNode = getNamedTypeDefinitionNode(firstNamedTypeDefinitionNode, schemaDocumentNode);
|
|
215
|
+
if (!isObjectTypeDefinitionNode(firstNamedTypeObjectDefinitionNode)) return null;
|
|
216
|
+
return makeMinimalValueForGqlObject(firstNamedTypeObjectDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
|
|
217
|
+
}
|
|
218
|
+
function makeMinimalValueForGqlListNode(listTypeNode, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes) {
|
|
219
|
+
if (!isNonNull && !Array.isArray(existingFieldValue)) return null;
|
|
220
|
+
if (isNonNull && !Array.isArray(existingFieldValue)) return [];
|
|
221
|
+
return existingFieldValue.map((item, index) => makeMinimalValueForASTNode({
|
|
222
|
+
fieldName: String(index),
|
|
223
|
+
astNode: listTypeNode.type,
|
|
224
|
+
schemaDocumentNode,
|
|
225
|
+
existingValueObject: { [index]: item },
|
|
226
|
+
visitedTypes
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
function makeMinimalValueForGqlObject(objectTypeDefinitionNode, schemaDocumentNode, _existingValueObject, existingFieldValue, isNonNull, visitedTypes) {
|
|
230
|
+
const typeName = objectTypeDefinitionNode.name.value;
|
|
231
|
+
if (visitedTypes?.has(typeName)) return null;
|
|
232
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
233
|
+
const fields = objectTypeDefinitionNode.fields;
|
|
234
|
+
if (!fields?.length) return {};
|
|
235
|
+
const newVisitedTypes = new Set(visitedTypes);
|
|
236
|
+
newVisitedTypes.add(typeName);
|
|
237
|
+
return makeMinimalValuesForObjectFields({
|
|
238
|
+
schemaDocumentNode,
|
|
239
|
+
existingValueObject: existingFieldValue && typeof existingFieldValue === "object" && !Array.isArray(existingFieldValue) ? existingFieldValue : null,
|
|
240
|
+
fieldDefinitionNodes: fields,
|
|
241
|
+
visitedTypes: newVisitedTypes
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function getNamedTypeDefinitionNode(astNodeTypeNode, schemaDocumentNode) {
|
|
245
|
+
if (!astNodeTypeNode) return null;
|
|
246
|
+
const name = getASTNodeName(astNodeTypeNode);
|
|
247
|
+
if (!name) return null;
|
|
248
|
+
const definitionNode = schemaDocumentNode.definitions.find((def) => "kind" in def && "name" in def && def.name?.value === name);
|
|
249
|
+
if (!definitionNode) return null;
|
|
250
|
+
return definitionNode;
|
|
251
|
+
}
|
|
252
|
+
function removeWhitespace(str) {
|
|
253
|
+
return str.replace(/\s+|\\n|\\t/g, "").toLowerCase();
|
|
254
|
+
}
|
|
255
|
+
function compareStringsWithoutWhitespace(str1, str2) {
|
|
256
|
+
if (str1 === null || str2 === null || str1 === void 0 || str2 === void 0) return false;
|
|
257
|
+
return removeWhitespace(str1) === removeWhitespace(str2);
|
|
258
|
+
}
|
|
259
|
+
function renameSchemaType(sdl, oldName, newName, scope) {
|
|
260
|
+
const typeSuffix = scope === "global" ? "State" : "LocalState";
|
|
261
|
+
const oldTypeName = `${pascalCase(oldName)}${typeSuffix}`;
|
|
262
|
+
const newTypeName = `${pascalCase(newName)}${typeSuffix}`;
|
|
263
|
+
const ast = safeParseSdl(sdl);
|
|
264
|
+
if (!ast) return sdl;
|
|
265
|
+
const updatedAst = visit(ast, { ObjectTypeDefinition: (node) => {
|
|
266
|
+
if (node.name.value === oldTypeName) return {
|
|
267
|
+
...node,
|
|
268
|
+
name: {
|
|
269
|
+
...node.name,
|
|
270
|
+
value: newTypeName
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
} });
|
|
274
|
+
return print(updatedAst);
|
|
275
|
+
}
|
|
276
|
+
function initializeModelSchema(modelName) {
|
|
277
|
+
return makeInitialSchemaDoc(modelName, "global");
|
|
278
|
+
}
|
|
279
|
+
function updateModelSchemaNames(params) {
|
|
280
|
+
const { oldName, newName, globalStateSchema, localStateSchema, setStateSchema } = params;
|
|
281
|
+
setStateSchema(renameSchemaType(globalStateSchema, oldName, newName, "global"), "global");
|
|
282
|
+
if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, oldName, newName, "local"), "local");
|
|
283
|
+
}
|
|
284
|
+
function handleModelNameChange(params) {
|
|
285
|
+
const { newName, globalStateSchema, setStateSchema } = params;
|
|
286
|
+
if (!!!globalStateSchema) {
|
|
287
|
+
setStateSchema(initializeModelSchema(newName), "global");
|
|
288
|
+
return;
|
|
102
289
|
}
|
|
103
|
-
|
|
104
|
-
}, i$1 = (e, t) => {
|
|
105
|
-
const r = n(t);
|
|
106
|
-
return e.some((e) => n(e).match(`^${r}\\.\\d+`));
|
|
107
|
-
};
|
|
108
|
-
function n(e) {
|
|
109
|
-
return e.replace(/\]|\[/g, "");
|
|
290
|
+
updateModelSchemaNames(params);
|
|
110
291
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function t(r, e) {
|
|
292
|
+
function validateStateObject(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateValue) {
|
|
293
|
+
let stateObjectJson;
|
|
114
294
|
try {
|
|
115
|
-
|
|
116
|
-
} catch (
|
|
117
|
-
return
|
|
295
|
+
stateObjectJson = JSON.parse(stateValue);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return [new Error("Invalid JSON object", { cause: error })];
|
|
118
298
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
299
|
+
const typeDefByName = indexTypeDefinitions(sharedSchemaDocumentNode);
|
|
300
|
+
const stateTypeName = stateTypeDefinitionNode.name.value;
|
|
301
|
+
if (!typeDefByName.has(stateTypeName)) return [/* @__PURE__ */ new Error(`State type "${stateTypeName}" was not found in sharedSchemaDocumentNode`)];
|
|
302
|
+
const inputSuffix = "Input";
|
|
303
|
+
const generatedInputDefs = generateInputTypesForObjectTree(stateTypeName, typeDefByName, inputSuffix);
|
|
304
|
+
const augmentedDoc = {
|
|
305
|
+
...sharedSchemaDocumentNode,
|
|
306
|
+
definitions: [...sharedSchemaDocumentNode.definitions, ...generatedInputDefs]
|
|
307
|
+
};
|
|
308
|
+
let schema;
|
|
309
|
+
try {
|
|
310
|
+
schema = buildASTSchema(augmentedDoc, { assumeValidSDL: false });
|
|
311
|
+
} catch (e) {
|
|
312
|
+
return [new Error("Failed to build schema from SDL", { cause: e })];
|
|
313
|
+
}
|
|
314
|
+
const inputTypeName = `${stateTypeName}${inputSuffix}`;
|
|
315
|
+
const opDoc = parse(`query($v: ${inputTypeName}!) { __typename }`);
|
|
316
|
+
const op = getOperationAST(opDoc);
|
|
317
|
+
if (!op) return [/* @__PURE__ */ new Error("Failed to create validation operation AST")];
|
|
318
|
+
const { errors } = getVariableValues(schema, op.variableDefinitions ?? [], { v: stateObjectJson });
|
|
319
|
+
const recursiveTypeErrors = detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName);
|
|
320
|
+
const recursiveFieldNames = new Set(recursiveTypeErrors.map((e) => e.field));
|
|
321
|
+
const validationErrors = errors ? graphQLErrorsToStateValidationErrors(errors).filter((e) => {
|
|
322
|
+
if (e instanceof StateValidationError && e.kind === "NON_NULL") {
|
|
323
|
+
const rootField = e.path[0];
|
|
324
|
+
if (typeof rootField === "string" && recursiveFieldNames.has(rootField)) return false;
|
|
141
325
|
}
|
|
142
|
-
|
|
326
|
+
return true;
|
|
327
|
+
}) : [];
|
|
328
|
+
validationErrors.unshift(...recursiveTypeErrors);
|
|
329
|
+
const missingOptionalErrors = detectMissingOptionalFields(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateObjectJson);
|
|
330
|
+
validationErrors.push(...missingOptionalErrors);
|
|
331
|
+
return validationErrors;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Indexes object/input/enum/scalar/interface/union type definition nodes by name.
|
|
335
|
+
* Note: only AST definitions that have a "name" field are indexed.
|
|
336
|
+
*/
|
|
337
|
+
function indexTypeDefinitions(doc) {
|
|
338
|
+
const map = /* @__PURE__ */ new Map();
|
|
339
|
+
for (const def of doc.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION || def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || def.kind === Kind.ENUM_TYPE_DEFINITION || def.kind === Kind.SCALAR_TYPE_DEFINITION || def.kind === Kind.INTERFACE_TYPE_DEFINITION || def.kind === Kind.UNION_TYPE_DEFINITION || def.kind === Kind.OBJECT_TYPE_EXTENSION || def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION || def.kind === Kind.ENUM_TYPE_EXTENSION || def.kind === Kind.INTERFACE_TYPE_EXTENSION || def.kind === Kind.UNION_TYPE_EXTENSION) {
|
|
340
|
+
const name = def.name.value;
|
|
341
|
+
if (!map.has(name)) map.set(name, def);
|
|
143
342
|
}
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
343
|
+
return map;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Generates InputObjectTypeDefinitionNode(s) for a root object type and any nested
|
|
347
|
+
* object types reachable via fields, converting object references to their *Input equivalents*.
|
|
348
|
+
*/
|
|
349
|
+
function generateInputTypesForObjectTree(rootObjectTypeName, typeDefByName, inputSuffix) {
|
|
350
|
+
const generated = /* @__PURE__ */ new Map();
|
|
351
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
352
|
+
const ensureInputForObject = (objectTypeName) => {
|
|
353
|
+
const inputName = `${objectTypeName}${inputSuffix}`;
|
|
354
|
+
if (generated.has(inputName)) return;
|
|
355
|
+
if (visiting.has(objectTypeName)) return;
|
|
356
|
+
visiting.add(objectTypeName);
|
|
357
|
+
const def = typeDefByName.get(objectTypeName);
|
|
358
|
+
if (!def) throw new GraphQLError(`Unknown referenced type "${objectTypeName}"`);
|
|
359
|
+
if (def.kind !== Kind.OBJECT_TYPE_DEFINITION && def.kind !== Kind.OBJECT_TYPE_EXTENSION) throw new GraphQLError(`Type "${objectTypeName}" is not an object type; cannot generate input from kind "${def.kind}"`);
|
|
360
|
+
const objDef = def;
|
|
361
|
+
const inputFields = objDef.fields?.map((f) => {
|
|
362
|
+
return {
|
|
363
|
+
kind: Kind.INPUT_VALUE_DEFINITION,
|
|
364
|
+
name: f.name,
|
|
365
|
+
description: f.description,
|
|
366
|
+
directives: [],
|
|
367
|
+
type: convertOutputTypeNodeToInputTypeNode(f.type, typeDefByName, inputSuffix, ensureInputForObject),
|
|
368
|
+
defaultValue: void 0
|
|
154
369
|
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
370
|
+
}) ?? [];
|
|
371
|
+
const inputDef = {
|
|
372
|
+
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
373
|
+
name: {
|
|
374
|
+
kind: Kind.NAME,
|
|
375
|
+
value: inputName
|
|
376
|
+
},
|
|
377
|
+
description: objDef.description,
|
|
378
|
+
directives: [],
|
|
379
|
+
fields: inputFields
|
|
158
380
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var c = n[a].types, f = c && c[t.code];
|
|
165
|
-
n[a] = appendErrors(a, e, n, s, f ? [].concat(f, t.message) : t.message);
|
|
166
|
-
}
|
|
167
|
-
r.shift();
|
|
168
|
-
}
|
|
169
|
-
return n;
|
|
381
|
+
generated.set(inputName, inputDef);
|
|
382
|
+
visiting.delete(objectTypeName);
|
|
383
|
+
};
|
|
384
|
+
ensureInputForObject(rootObjectTypeName);
|
|
385
|
+
return Array.from(generated.values());
|
|
170
386
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
387
|
+
function convertOutputTypeNodeToInputTypeNode(typeNode, typeDefByName, inputSuffix, ensureInputForObject) {
|
|
388
|
+
switch (typeNode.kind) {
|
|
389
|
+
case Kind.NON_NULL_TYPE: return {
|
|
390
|
+
kind: Kind.NON_NULL_TYPE,
|
|
391
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
392
|
+
};
|
|
393
|
+
case Kind.LIST_TYPE: return {
|
|
394
|
+
kind: Kind.LIST_TYPE,
|
|
395
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
396
|
+
};
|
|
397
|
+
case Kind.NAMED_TYPE: {
|
|
398
|
+
const named = typeNode;
|
|
399
|
+
const name = named.name.value;
|
|
400
|
+
const def = typeDefByName.get(name);
|
|
401
|
+
if (def?.kind === Kind.OBJECT_TYPE_DEFINITION || def?.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
402
|
+
ensureInputForObject(name);
|
|
403
|
+
return {
|
|
404
|
+
kind: Kind.NAMED_TYPE,
|
|
405
|
+
name: {
|
|
406
|
+
kind: Kind.NAME,
|
|
407
|
+
value: `${name}${inputSuffix}`
|
|
408
|
+
}
|
|
189
409
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
410
|
+
}
|
|
411
|
+
if (!def || def.kind === Kind.SCALAR_TYPE_DEFINITION || def.kind === Kind.ENUM_TYPE_DEFINITION || def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) return named;
|
|
412
|
+
if (def.kind === Kind.INTERFACE_TYPE_DEFINITION || def.kind === Kind.UNION_TYPE_DEFINITION) throw new GraphQLError(`Type "${name}" (${def.kind}) cannot be used in an input type`);
|
|
413
|
+
throw new GraphQLError(`Unsupported named type "${name}" of kind "${def.kind}"`);
|
|
194
414
|
}
|
|
415
|
+
default: throw new GraphQLError(`Unsupported TypeNode kind: ${JSON.stringify(typeNode)}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
var StateValidationError = class extends Error {
|
|
419
|
+
payload;
|
|
420
|
+
originalMessage;
|
|
421
|
+
constructor(payload, originalMessage) {
|
|
422
|
+
super(payload.kind);
|
|
423
|
+
this.name = "StateValidationError";
|
|
424
|
+
this.payload = payload;
|
|
425
|
+
this.originalMessage = originalMessage;
|
|
426
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
427
|
+
}
|
|
428
|
+
get kind() {
|
|
429
|
+
return this.payload.kind;
|
|
430
|
+
}
|
|
431
|
+
get path() {
|
|
432
|
+
return this.payload.path;
|
|
433
|
+
}
|
|
434
|
+
get field() {
|
|
435
|
+
return this.payload.field;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
function extractInputPath(message) {
|
|
439
|
+
const match = message.match(/at\s+"([^"]+)"/);
|
|
440
|
+
if (!match) return [];
|
|
441
|
+
const parts = match[1].split(".").filter(Boolean);
|
|
442
|
+
return (parts[0] === "v" ? parts.slice(1) : parts).map((p) => /^\d+$/.test(p) ? Number(p) : p);
|
|
443
|
+
}
|
|
444
|
+
const RE_MISSING_REQUIRED_FIELD = /Field "([^"]+)" of required type "([^"]+)" was not provided\./;
|
|
445
|
+
const RE_UNKNOWN_FIELD = /Field "([^"]+)" is not defined by type "([^"]+)"\.(?: Did you mean "([^"]+)"\?)?/;
|
|
446
|
+
function extractMissingRequiredField(message) {
|
|
447
|
+
const m = message.match(RE_MISSING_REQUIRED_FIELD);
|
|
448
|
+
if (!m) return null;
|
|
449
|
+
return {
|
|
450
|
+
field: m[1],
|
|
451
|
+
expectedType: m[2]
|
|
195
452
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
453
|
+
}
|
|
454
|
+
function extractUnknownField(message) {
|
|
455
|
+
const m = message.match(RE_UNKNOWN_FIELD);
|
|
456
|
+
if (!m) return null;
|
|
457
|
+
return {
|
|
458
|
+
field: m[1],
|
|
459
|
+
typeName: m[2],
|
|
460
|
+
didYouMean: m[3]
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function lastFieldFromPath(path) {
|
|
464
|
+
for (let i = path.length - 1; i >= 0; i--) if (typeof path[i] === "string") return path[i];
|
|
465
|
+
}
|
|
466
|
+
function extractExpectedType(message) {
|
|
467
|
+
let m = message.match(/Expected non-nullable type "([^"]+)"/);
|
|
468
|
+
if (m?.[1]) return m[1];
|
|
469
|
+
m = message.match(/Expected type "([^"]+)"/);
|
|
470
|
+
if (m?.[1]) return m[1];
|
|
471
|
+
m = message.match(/;\s*([_A-Za-z][_0-9A-Za-z]*)\s+cannot represent/i);
|
|
472
|
+
if (m?.[1]) return m[1];
|
|
473
|
+
}
|
|
474
|
+
function graphQLErrorsToStateValidationErrors(errors) {
|
|
475
|
+
const out = [];
|
|
476
|
+
for (const e of errors) {
|
|
477
|
+
const originalMessage = e.message;
|
|
478
|
+
const missing = extractMissingRequiredField(originalMessage);
|
|
479
|
+
if (missing) {
|
|
480
|
+
out.push(new StateValidationError({
|
|
481
|
+
kind: "MISSING",
|
|
482
|
+
path: [missing.field],
|
|
483
|
+
field: missing.field,
|
|
484
|
+
expectedType: missing.expectedType
|
|
485
|
+
}, originalMessage));
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const unknown = extractUnknownField(originalMessage);
|
|
489
|
+
if (unknown) {
|
|
490
|
+
out.push(new StateValidationError({
|
|
491
|
+
kind: "UNKNOWN_FIELD",
|
|
492
|
+
path: [unknown.field],
|
|
493
|
+
field: unknown.field,
|
|
494
|
+
didYouMean: unknown.didYouMean
|
|
495
|
+
}, originalMessage));
|
|
496
|
+
continue;
|
|
218
497
|
}
|
|
498
|
+
const path = extractInputPath(originalMessage);
|
|
499
|
+
const field = lastFieldFromPath(path) ?? "value";
|
|
500
|
+
const expectedType = extractExpectedType(originalMessage);
|
|
501
|
+
if (originalMessage.includes("Expected non-nullable type") && originalMessage.includes("not to be null")) {
|
|
502
|
+
out.push(new StateValidationError({
|
|
503
|
+
kind: "NON_NULL",
|
|
504
|
+
path,
|
|
505
|
+
field,
|
|
506
|
+
expectedType
|
|
507
|
+
}, originalMessage));
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
if (originalMessage.includes("cannot represent") || originalMessage.includes("Expected type")) {
|
|
511
|
+
out.push(new StateValidationError({
|
|
512
|
+
kind: "TYPE",
|
|
513
|
+
path,
|
|
514
|
+
field,
|
|
515
|
+
expectedType,
|
|
516
|
+
details: originalMessage
|
|
517
|
+
}, originalMessage));
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
out.push(new StateValidationError({
|
|
521
|
+
kind: "TYPE",
|
|
522
|
+
path,
|
|
523
|
+
field,
|
|
524
|
+
details: originalMessage
|
|
525
|
+
}, originalMessage));
|
|
526
|
+
}
|
|
527
|
+
return out;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Finds all fields defined in the schema that are missing from the state object.
|
|
531
|
+
* Returns information about each missing field including whether it's required.
|
|
532
|
+
*/
|
|
533
|
+
function findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value, basePath = []) {
|
|
534
|
+
let stateObjectJson;
|
|
535
|
+
try {
|
|
536
|
+
stateObjectJson = typeof value === "string" ? JSON.parse(value) : value;
|
|
537
|
+
} catch {
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
const typeByName = indexObjectTypes(sharedSchemaDocumentNode);
|
|
541
|
+
const missingFields = [];
|
|
542
|
+
for (const field of rootTypeNode.fields ?? []) {
|
|
543
|
+
const fieldName = field.name.value;
|
|
544
|
+
const fieldPath = [...basePath, fieldName];
|
|
545
|
+
const isRequired = field.type.kind === Kind.NON_NULL_TYPE;
|
|
546
|
+
const underlyingType = isRequired ? field.type.type : field.type;
|
|
547
|
+
if (!(fieldName in stateObjectJson)) {
|
|
548
|
+
missingFields.push({
|
|
549
|
+
fieldName,
|
|
550
|
+
path: fieldPath,
|
|
551
|
+
isRequired,
|
|
552
|
+
type: underlyingType
|
|
553
|
+
});
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
const namedType = unwrapNamedType(field.type);
|
|
557
|
+
const childType = namedType ? typeByName.get(namedType) : void 0;
|
|
558
|
+
if (childType && typeof stateObjectJson[fieldName] === "object" && stateObjectJson[fieldName] !== null && !Array.isArray(stateObjectJson[fieldName])) {
|
|
559
|
+
const nestedMissing = findMissingFields(sharedSchemaDocumentNode, childType, stateObjectJson[fieldName], fieldPath);
|
|
560
|
+
missingFields.push(...nestedMissing);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return missingFields;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Detects optional fields defined in the schema that are missing from the state object.
|
|
567
|
+
* Returns StateValidationError[] for each missing optional field.
|
|
568
|
+
*/
|
|
569
|
+
function detectMissingOptionalFields(sharedSchemaDocumentNode, rootTypeNode, value) {
|
|
570
|
+
return findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value).filter((field) => !field.isRequired).map((field) => new StateValidationError({
|
|
571
|
+
kind: "MISSING_OPTIONAL",
|
|
572
|
+
path: field.path,
|
|
573
|
+
field: field.fieldName,
|
|
574
|
+
expectedType: typeNodeToString(field.type)
|
|
575
|
+
}));
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Detects fields that have recursive types (types that reference themselves directly or indirectly).
|
|
579
|
+
* Returns a RECURSIVE_TYPE error for each field that contains a recursive type.
|
|
580
|
+
*/
|
|
581
|
+
function detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName) {
|
|
582
|
+
const errors = [];
|
|
583
|
+
for (const field of stateTypeDefinitionNode.fields ?? []) {
|
|
584
|
+
const fieldName = field.name.value;
|
|
585
|
+
const namedTypeName = getNamedTypeName(field.type);
|
|
586
|
+
if (!namedTypeName) continue;
|
|
587
|
+
if (isRecursiveType(namedTypeName, typeDefByName, /* @__PURE__ */ new Set())) errors.push(new StateValidationError({
|
|
588
|
+
kind: "RECURSIVE_TYPE",
|
|
589
|
+
path: [fieldName],
|
|
590
|
+
field: fieldName,
|
|
591
|
+
typeName: namedTypeName
|
|
592
|
+
}));
|
|
593
|
+
}
|
|
594
|
+
return errors;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Gets the named type name from a TypeNode, unwrapping NonNull and List types.
|
|
598
|
+
*/
|
|
599
|
+
function getNamedTypeName(typeNode) {
|
|
600
|
+
if (typeNode.kind === Kind.NAMED_TYPE) return typeNode.name.value;
|
|
601
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE || typeNode.kind === Kind.LIST_TYPE) return getNamedTypeName(typeNode.type);
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Checks if a type is recursive (references itself directly or indirectly through required fields).
|
|
606
|
+
*/
|
|
607
|
+
function isRecursiveType(typeName, typeDefByName, visitedTypes) {
|
|
608
|
+
if (visitedTypes.has(typeName)) return true;
|
|
609
|
+
const typeDef = typeDefByName.get(typeName);
|
|
610
|
+
if (!typeDef || typeDef.kind !== Kind.OBJECT_TYPE_DEFINITION) return false;
|
|
611
|
+
visitedTypes.add(typeName);
|
|
612
|
+
for (const field of typeDef.fields ?? []) {
|
|
613
|
+
if (field.type.kind !== Kind.NON_NULL_TYPE) continue;
|
|
614
|
+
const innerType = field.type.type;
|
|
615
|
+
let fieldTypeName = null;
|
|
616
|
+
if (innerType.kind === Kind.NAMED_TYPE) fieldTypeName = innerType.name.value;
|
|
617
|
+
else if (innerType.kind === Kind.LIST_TYPE) fieldTypeName = getNamedTypeName(innerType);
|
|
618
|
+
if (fieldTypeName && isRecursiveType(fieldTypeName, typeDefByName, visitedTypes)) return true;
|
|
619
|
+
}
|
|
620
|
+
visitedTypes.delete(typeName);
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Converts a TypeNode to its string representation (e.g., "String", "Int!", "[String]!")
|
|
625
|
+
*/
|
|
626
|
+
function typeNodeToString(typeNode) {
|
|
627
|
+
switch (typeNode.kind) {
|
|
628
|
+
case Kind.NAMED_TYPE: return typeNode.name.value;
|
|
629
|
+
case Kind.NON_NULL_TYPE: return `${typeNodeToString(typeNode.type)}!`;
|
|
630
|
+
case Kind.LIST_TYPE: return `[${typeNodeToString(typeNode.type)}]`;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function indexObjectTypes(doc) {
|
|
634
|
+
const map = /* @__PURE__ */ new Map();
|
|
635
|
+
for (const def of doc.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION) map.set(def.name.value, def);
|
|
636
|
+
return map;
|
|
637
|
+
}
|
|
638
|
+
function unwrapNamedType(typeNode) {
|
|
639
|
+
if (typeNode.kind === Kind.NAMED_TYPE) return typeNode.name.value;
|
|
640
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE) return unwrapNamedType(typeNode.type);
|
|
641
|
+
if (typeNode.kind === Kind.LIST_TYPE) return unwrapNamedType(typeNode.type);
|
|
642
|
+
}
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region editors/document-model-editor/utils/linting.ts
|
|
645
|
+
function ensureDocumentContainsNodeWithNameAndType(doc, nodeName, nodeType) {
|
|
646
|
+
const parsedDoc = safeParseSdl(doc);
|
|
647
|
+
if (!parsedDoc) return true;
|
|
648
|
+
return parsedDoc.definitions.some((def) => {
|
|
649
|
+
return def.kind === Kind[nodeType] && "name" in def && def.name?.value === nodeName;
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
function createNodeTypeAndNameDiagnostic(doc, errorMessage) {
|
|
653
|
+
const parsedDoc = safeParseSdl(doc);
|
|
654
|
+
if (!parsedDoc) return void 0;
|
|
655
|
+
const firstNode = parsedDoc.definitions[0];
|
|
656
|
+
const nameNode = "name" in firstNode ? firstNode.name : null;
|
|
657
|
+
return {
|
|
658
|
+
from: nameNode?.loc?.start ?? firstNode.loc?.start ?? 0,
|
|
659
|
+
to: nameNode?.loc?.end ?? firstNode.loc?.end ?? 0,
|
|
660
|
+
severity: "error",
|
|
661
|
+
message: errorMessage
|
|
219
662
|
};
|
|
220
|
-
|
|
663
|
+
}
|
|
664
|
+
function ensureValidStateSchemaName(doc, modelName, scope) {
|
|
665
|
+
if (!safeParseSdl(doc)) return [];
|
|
666
|
+
const requiredTypeName = makeStateSchemaNameForScope(modelName, scope);
|
|
667
|
+
if (!ensureDocumentContainsNodeWithNameAndType(doc, requiredTypeName, "OBJECT_TYPE_DEFINITION")) return [createNodeTypeAndNameDiagnostic(doc, `${sentenceCase(scope)} state schema must be named ${requiredTypeName}`)].filter((d) => d !== void 0);
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
function ensureValidOperationSchemaInputName(doc, operationName) {
|
|
671
|
+
if (!doc || !safeParseSdl(doc)) return [];
|
|
672
|
+
const requiredTypeName = `${pascalCase(operationName)}Input`;
|
|
673
|
+
if (!ensureDocumentContainsNodeWithNameAndType(doc, requiredTypeName, "INPUT_OBJECT_TYPE_DEFINITION")) return [createNodeTypeAndNameDiagnostic(doc, `Operation schema must contain an input type named ${requiredTypeName}`)].filter((d) => d !== void 0);
|
|
674
|
+
return [];
|
|
675
|
+
}
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region editors/document-model-editor/components/button.tsx
|
|
678
|
+
const Button = forwardRef((props, ref) => {
|
|
679
|
+
const { className, ...rest } = props;
|
|
680
|
+
return /* @__PURE__ */ jsx("button", {
|
|
681
|
+
ref,
|
|
682
|
+
...rest,
|
|
683
|
+
className: twMerge("h-10 rounded-md border border-border bg-background px-4 py-2 text-sm font-medium whitespace-nowrap text-foreground transition-colors hover:hover-effect focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:disabled-effect", className)
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
//#endregion
|
|
687
|
+
//#region editors/document-model-editor/components/divider.tsx
|
|
688
|
+
function Divider({ className, size = "sm", margin = "md" }) {
|
|
689
|
+
function getSize() {
|
|
690
|
+
if (size === "sm") return "h-px";
|
|
691
|
+
if (size === "md") return "h-1";
|
|
692
|
+
return "h-1.5";
|
|
693
|
+
}
|
|
694
|
+
function getMargin() {
|
|
695
|
+
if (margin === "sm") return "my-4";
|
|
696
|
+
if (margin === "md") return "my-6";
|
|
697
|
+
return "my-8";
|
|
698
|
+
}
|
|
699
|
+
const sizeClass = getSize();
|
|
700
|
+
const marginClass = getMargin();
|
|
701
|
+
return /* @__PURE__ */ jsx("div", { className: twMerge("bg-secondary", sizeClass, marginClass, className) });
|
|
221
702
|
}
|
|
222
703
|
//#endregion
|
|
223
704
|
//#region editors/document-model-editor/schemas/inputs.ts
|
|
@@ -225,16 +706,16 @@ const isUppercase = (value) => !/\p{Ll}/u.test(value);
|
|
|
225
706
|
const isLowercase = (value) => !/\p{Lu}/u.test(value);
|
|
226
707
|
function createNameSchema(options = {}) {
|
|
227
708
|
const { required = false, allowEmpty = false, unique = [] } = options;
|
|
228
|
-
const baseSchema = allowEmpty ? string() : string().min(1);
|
|
709
|
+
const baseSchema = allowEmpty ? z.string() : z.string().min(1);
|
|
229
710
|
const uniqueRefinement = baseSchema.refine((value) => {
|
|
230
711
|
if (!value && allowEmpty) return true;
|
|
231
712
|
return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
|
|
232
713
|
}, { message: "Item with this name already exists" });
|
|
233
|
-
if (!required) return unique.length > 0 ? string().optional().refine((value) => {
|
|
714
|
+
if (!required) return unique.length > 0 ? z.string().optional().refine((value) => {
|
|
234
715
|
if (value === void 0) return true;
|
|
235
716
|
if (!value && allowEmpty) return true;
|
|
236
717
|
return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
|
|
237
|
-
}, { message: "Item with this name already exists" }) : string().optional();
|
|
718
|
+
}, { message: "Item with this name already exists" }) : z.string().optional();
|
|
238
719
|
return unique.length > 0 ? uniqueRefinement : baseSchema;
|
|
239
720
|
}
|
|
240
721
|
function createConstantCaseSchema(options = {}) {
|
|
@@ -249,9 +730,9 @@ function toLowercaseSnakeCase(value, options = {}) {
|
|
|
249
730
|
function toConstantCase(value, options = {}) {
|
|
250
731
|
return createConstantCaseSchema(options).parse(constantCase(value));
|
|
251
732
|
}
|
|
252
|
-
object({
|
|
733
|
+
z.object({
|
|
253
734
|
name: createNameSchema({ allowEmpty: true }),
|
|
254
|
-
website: union([url(), literal("")]).optional().default("")
|
|
735
|
+
website: z.union([z.url(), z.literal("")]).optional().default("")
|
|
255
736
|
}).default({
|
|
256
737
|
name: "",
|
|
257
738
|
website: ""
|
|
@@ -279,30 +760,14 @@ const useFormField = () => {
|
|
|
279
760
|
};
|
|
280
761
|
};
|
|
281
762
|
//#endregion
|
|
282
|
-
//#region ../../node_modules/.pnpm/@radix-ui+react-label@2.1.8_@types+react-dom@19.2.3_@types+react@19.2.14__@types+react@_8d35ec453e0b59eefe06771bb1432577/node_modules/@radix-ui/react-label/dist/index.mjs
|
|
283
|
-
var NAME = "Label";
|
|
284
|
-
var Label$1 = React$1.forwardRef((props, forwardedRef) => {
|
|
285
|
-
return /* @__PURE__ */ jsx(Primitive.label, {
|
|
286
|
-
...props,
|
|
287
|
-
ref: forwardedRef,
|
|
288
|
-
onMouseDown: (event) => {
|
|
289
|
-
if (event.target.closest("button, input, select, textarea")) return;
|
|
290
|
-
props.onMouseDown?.(event);
|
|
291
|
-
if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
Label$1.displayName = NAME;
|
|
296
|
-
var Root = Label$1;
|
|
297
|
-
//#endregion
|
|
298
763
|
//#region editors/document-model-editor/components/label.tsx
|
|
299
764
|
const labelVariants = cva("text-sm leading-none font-medium peer-disabled:disabled-effect");
|
|
300
|
-
const Label = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Root, {
|
|
765
|
+
const Label = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(LabelPrimitive.Root, {
|
|
301
766
|
ref,
|
|
302
767
|
className: twMerge(labelVariants(), className),
|
|
303
768
|
...props
|
|
304
769
|
}));
|
|
305
|
-
Label.displayName = Root.displayName;
|
|
770
|
+
Label.displayName = LabelPrimitive.Root.displayName;
|
|
306
771
|
//#endregion
|
|
307
772
|
//#region editors/document-model-editor/components/form.tsx
|
|
308
773
|
const Form = FormProvider;
|
|
@@ -403,12 +868,13 @@ const TextField = forwardRef(({ name, value, onSubmit, label, placeholder, uniqu
|
|
|
403
868
|
useEffect(() => {
|
|
404
869
|
if (focusOnMount && textareaRef.current) textareaRef.current.focus();
|
|
405
870
|
}, [focusOnMount]);
|
|
871
|
+
const fieldSchema = z.object({ [name]: createNameSchema({
|
|
872
|
+
required,
|
|
873
|
+
allowEmpty,
|
|
874
|
+
unique
|
|
875
|
+
}) });
|
|
406
876
|
const form = useForm({
|
|
407
|
-
resolver:
|
|
408
|
-
required,
|
|
409
|
-
allowEmpty,
|
|
410
|
-
unique
|
|
411
|
-
}) })),
|
|
877
|
+
resolver: zodResolver(fieldSchema),
|
|
412
878
|
defaultValues: { [name]: value ?? "" }
|
|
413
879
|
});
|
|
414
880
|
const handleSubmit = useCallback((values) => {
|
|
@@ -497,13 +963,13 @@ const TextField = forwardRef(({ name, value, onSubmit, label, placeholder, uniqu
|
|
|
497
963
|
});
|
|
498
964
|
});
|
|
499
965
|
TextField.displayName = "TextField";
|
|
500
|
-
object({
|
|
501
|
-
name: string(),
|
|
502
|
-
documentType: string(),
|
|
503
|
-
extension: string().optional().default(""),
|
|
504
|
-
description: string(),
|
|
505
|
-
authorName: string(),
|
|
506
|
-
authorWebsite: string()
|
|
966
|
+
z.object({
|
|
967
|
+
name: z.string(),
|
|
968
|
+
documentType: z.string(),
|
|
969
|
+
extension: z.string().optional().default(""),
|
|
970
|
+
description: z.string(),
|
|
971
|
+
authorName: z.string(),
|
|
972
|
+
authorWebsite: z.string()
|
|
507
973
|
});
|
|
508
974
|
function ModelMetadata(props) {
|
|
509
975
|
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(ModelNameForm, { ...props }), /* @__PURE__ */ jsx("div", {
|
|
@@ -532,32 +998,38 @@ function ModelMetadata(props) {
|
|
|
532
998
|
}
|
|
533
999
|
function ModelNameForm(props) {
|
|
534
1000
|
const { name, globalStateSchema, localStateSchema, setModelName, setStateSchema } = props;
|
|
1001
|
+
const onSubmit = useCallback((newName) => {
|
|
1002
|
+
if (name === newName) return;
|
|
1003
|
+
setModelName(newName);
|
|
1004
|
+
if (!!!globalStateSchema) {
|
|
1005
|
+
const initialSchemaDoc = makeInitialSchemaDoc(newName, "global");
|
|
1006
|
+
setStateSchema(initialSchemaDoc, "global");
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
const newSchema = renameSchemaType(globalStateSchema, name, newName, "global");
|
|
1010
|
+
setStateSchema(newSchema, "global");
|
|
1011
|
+
if (localStateSchema) {
|
|
1012
|
+
const newLocalStateSchema = renameSchemaType(localStateSchema, name, newName, "local");
|
|
1013
|
+
setStateSchema(newLocalStateSchema, "local");
|
|
1014
|
+
}
|
|
1015
|
+
handleModelNameChange({
|
|
1016
|
+
oldName: name,
|
|
1017
|
+
newName,
|
|
1018
|
+
globalStateSchema,
|
|
1019
|
+
localStateSchema,
|
|
1020
|
+
setStateSchema
|
|
1021
|
+
});
|
|
1022
|
+
}, [
|
|
1023
|
+
name,
|
|
1024
|
+
globalStateSchema,
|
|
1025
|
+
localStateSchema,
|
|
1026
|
+
setStateSchema,
|
|
1027
|
+
setModelName
|
|
1028
|
+
]);
|
|
535
1029
|
return /* @__PURE__ */ jsx(TextField, {
|
|
536
1030
|
name: "name",
|
|
537
1031
|
value: name,
|
|
538
|
-
onSubmit
|
|
539
|
-
if (name === newName) return;
|
|
540
|
-
setModelName(newName);
|
|
541
|
-
if (!!!globalStateSchema) {
|
|
542
|
-
setStateSchema(makeInitialSchemaDoc(newName, "global"), "global");
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
setStateSchema(renameSchemaType(globalStateSchema, name, newName, "global"), "global");
|
|
546
|
-
if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, name, newName, "local"), "local");
|
|
547
|
-
handleModelNameChange({
|
|
548
|
-
oldName: name,
|
|
549
|
-
newName,
|
|
550
|
-
globalStateSchema,
|
|
551
|
-
localStateSchema,
|
|
552
|
-
setStateSchema
|
|
553
|
-
});
|
|
554
|
-
}, [
|
|
555
|
-
name,
|
|
556
|
-
globalStateSchema,
|
|
557
|
-
localStateSchema,
|
|
558
|
-
setStateSchema,
|
|
559
|
-
setModelName
|
|
560
|
-
]),
|
|
1032
|
+
onSubmit,
|
|
561
1033
|
placeholder: "Model name",
|
|
562
1034
|
className: "border-none pl-0 text-xl font-bold text-foreground",
|
|
563
1035
|
required: true,
|
|
@@ -758,7 +1230,7 @@ function OperationErrors({ operation, addOperationError, deleteOperationError, s
|
|
|
758
1230
|
}
|
|
759
1231
|
//#endregion
|
|
760
1232
|
//#region editors/document-model-editor/components/operation.tsx
|
|
761
|
-
const GraphqlEditor = lazy(() => import("./graphql-editor-
|
|
1233
|
+
const GraphqlEditor = lazy(() => import("./graphql-editor-CpcGaYmP.js"));
|
|
762
1234
|
function Operation(props) {
|
|
763
1235
|
const { operation, module, allOperationNames, lastCreatedOperationId, onAddOperationAndInitialSchema, updateOperationName, deleteOperation, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired } = props;
|
|
764
1236
|
const noInputRequired = isEmptyOperationSchema(operation.schema);
|
|
@@ -1141,7 +1613,7 @@ function VersionAdvisoryModal(props) {
|
|
|
1141
1613
|
" ",
|
|
1142
1614
|
"may stop working correctly."
|
|
1143
1615
|
] }),
|
|
1144
|
-
diff && /* @__PURE__ */ jsxs(Fragment
|
|
1616
|
+
diff && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1145
1617
|
/* @__PURE__ */ jsx(FieldDiffList, {
|
|
1146
1618
|
fields: diff.addedFields,
|
|
1147
1619
|
label: "New fields:"
|
|
@@ -1194,11 +1666,6 @@ function VersionAdvisoryModal(props) {
|
|
|
1194
1666
|
//#region editors/document-model-editor/config.ts
|
|
1195
1667
|
const editorConfig = { isExternalControlsEnabled: false };
|
|
1196
1668
|
//#endregion
|
|
1197
|
-
//#region editors/document-model-editor/hooks/useDocumentModelDocument.ts
|
|
1198
|
-
function useSelectedDocumentModelDocument() {
|
|
1199
|
-
return useSelectedDocumentOfType("powerhouse/document-model");
|
|
1200
|
-
}
|
|
1201
|
-
//#endregion
|
|
1202
1669
|
//#region editors/document-model-editor/utils/change-classification.ts
|
|
1203
1670
|
function isShapeTypeNode(node) {
|
|
1204
1671
|
return node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === Kind.ENUM_TYPE_DEFINITION;
|
|
@@ -1261,8 +1728,8 @@ function diffSdlShapes(oldSdl, newSdl) {
|
|
|
1261
1728
|
let oldDoc;
|
|
1262
1729
|
let newDoc;
|
|
1263
1730
|
try {
|
|
1264
|
-
oldDoc = parse
|
|
1265
|
-
newDoc = parse
|
|
1731
|
+
oldDoc = parse(oldSdl);
|
|
1732
|
+
newDoc = parse(newSdl);
|
|
1266
1733
|
} catch {
|
|
1267
1734
|
return empty;
|
|
1268
1735
|
}
|
|
@@ -1298,7 +1765,7 @@ function isPlaceholderOnlySchema(sdl) {
|
|
|
1298
1765
|
if (isBlank(sdl)) return true;
|
|
1299
1766
|
let doc;
|
|
1300
1767
|
try {
|
|
1301
|
-
doc = parse
|
|
1768
|
+
doc = parse(sdl);
|
|
1302
1769
|
} catch {
|
|
1303
1770
|
return false;
|
|
1304
1771
|
}
|
|
@@ -1494,13 +1961,13 @@ function useVersionAdvisory(args) {
|
|
|
1494
1961
|
}
|
|
1495
1962
|
//#endregion
|
|
1496
1963
|
//#region editors/document-model-editor/editor.tsx
|
|
1497
|
-
|
|
1964
|
+
var editor_exports = /* @__PURE__ */ __exportAll({ default: () => Editor });
|
|
1965
|
+
const StateSchemas = lazy(() => import("./state-schemas-DHLAg1w0.js"));
|
|
1498
1966
|
const noopSetStateSchema = () => void 0;
|
|
1499
1967
|
const noopSetInitialState = () => void 0;
|
|
1500
|
-
function Editor() {
|
|
1968
|
+
function Editor({ document, dispatch }) {
|
|
1501
1969
|
useSetPHDocumentEditorConfig(editorConfig);
|
|
1502
1970
|
const toast = usePHToast();
|
|
1503
|
-
const [document, dispatch] = useSelectedDocumentModelDocument();
|
|
1504
1971
|
const [scope, setScope] = useState("global");
|
|
1505
1972
|
const documentNodeName = document.header.name;
|
|
1506
1973
|
const { name: modelName, id: documentType, extension, description, author: { name: authorName, website: authorWebsite } } = document.state.global;
|
|
@@ -1672,11 +2139,12 @@ function Editor() {
|
|
|
1672
2139
|
return;
|
|
1673
2140
|
}
|
|
1674
2141
|
const id = generateId();
|
|
2142
|
+
const errorCode = pascalCase(errorName);
|
|
1675
2143
|
guardedDispatch(addOperationError({
|
|
1676
2144
|
id,
|
|
1677
2145
|
operationId,
|
|
1678
2146
|
errorName,
|
|
1679
|
-
errorCode
|
|
2147
|
+
errorCode
|
|
1680
2148
|
}));
|
|
1681
2149
|
resolve(id);
|
|
1682
2150
|
} catch (error) {
|
|
@@ -1714,7 +2182,7 @@ function Editor() {
|
|
|
1714
2182
|
return /* @__PURE__ */ jsxs("main", {
|
|
1715
2183
|
className: "min-h-dvh bg-background p-6",
|
|
1716
2184
|
children: [
|
|
1717
|
-
/* @__PURE__ */ jsx(DocumentToolbar, {}),
|
|
2185
|
+
/* @__PURE__ */ jsx(DocumentToolbar, { document }),
|
|
1718
2186
|
/* @__PURE__ */ jsx(SchemaContextProvider, {
|
|
1719
2187
|
globalStateSchemaSdl: globalStateSchema,
|
|
1720
2188
|
localStateSchemaSdl: localStateSchema,
|
|
@@ -1804,6 +2272,6 @@ function Editor() {
|
|
|
1804
2272
|
});
|
|
1805
2273
|
}
|
|
1806
2274
|
//#endregion
|
|
1807
|
-
export { Editor as default };
|
|
2275
|
+
export { makeInitialSchemaDoc as a, validateStateObject as c, Editor as default, StateValidationError as i, Button as n, makeMinimalObjectForStateType as o, ensureValidStateSchemaName as r, makeStateSchemaNameForScope as s, editor_exports as t };
|
|
1808
2276
|
|
|
1809
|
-
//# sourceMappingURL=editor-
|
|
2277
|
+
//# sourceMappingURL=editor-x1UIfSot.js.map
|