@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.8 → 6.2.3-dev.81
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-cxt8RRxe.js +18 -0
- package/dist/browser/documents-cxt8RRxe.js.map +1 -0
- package/dist/browser/{editor-6T4WF2og.js → editor-DXAJ8Mqb.js} +761 -277
- package/dist/browser/editor-DXAJ8Mqb.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/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-CGxwONKl.js +103 -0
- package/dist/browser/graphql-editor-CGxwONKl.js.map +1 -0
- package/dist/browser/hooks-D15NCia0.js +126 -0
- package/dist/browser/hooks-D15NCia0.js.map +1 -0
- package/dist/browser/index.js +6 -703
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/json-editor--jgLEwP2.js +55 -0
- package/dist/browser/json-editor--jgLEwP2.js.map +1 -0
- package/dist/browser/{schema-context-ZyeclQwy.js → schema-context-CC_WFs1x.js} +10 -6
- package/dist/browser/schema-context-CC_WFs1x.js.map +1 -0
- package/dist/browser/{state-schemas-CpcWN_Qo.js → state-schemas-DSY44MOd.js} +28 -19
- package/dist/browser/state-schemas-DSY44MOd.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-CNInCxpO.mjs} +66 -50
- package/dist/node/documents-CNInCxpO.mjs.map +1 -0
- package/dist/node/editor-C54qhQLX.mjs +4762 -0
- package/dist/node/editor-C54qhQLX.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--ZZPvvGh.mjs} +5130 -63
- package/dist/node/graphql-editor--ZZPvvGh.mjs.map +1 -0
- package/dist/node/{hooks-D0DcS3MV.mjs → hooks-DI7akiay.mjs} +824 -444
- package/dist/node/{hooks-D0DcS3MV.mjs.map → hooks-DI7akiay.mjs.map} +1 -1
- package/dist/node/index.mjs +45 -97
- package/dist/node/index.mjs.map +1 -1
- package/dist/{browser/json-editor-xI_oaxyT.js → node/json-editor-gYEyOVXY.mjs} +8 -9
- package/dist/node/{json-editor-Ckaem6ky.mjs.map → json-editor-gYEyOVXY.mjs.map} +1 -1
- package/dist/node/rolldown-runtime-Bl3dcgcQ.mjs +16 -0
- package/dist/node/{schema-context-DL8jhi_d.mjs → schema-context-DTb0xqgJ.mjs} +9 -6
- package/dist/node/schema-context-DTb0xqgJ.mjs.map +1 -0
- package/dist/node/state-schemas-Ciq9kway.mjs +1071 -0
- package/dist/node/state-schemas-Ciq9kway.mjs.map +1 -0
- package/package.json +26 -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/schema-context-ZyeclQwy.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,713 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 { r as standardLibScalars } from "./documents-cxt8RRxe.js";
|
|
2
|
+
import { n as safeParseSdl, t as SchemaContextProvider } from "./schema-context-CC_WFs1x.js";
|
|
3
|
+
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
4
|
import * as React$1 from "react";
|
|
11
5
|
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
|
-
const getVariantClassNames = Object.keys(variants).map((variant) => {
|
|
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
|
-
};
|
|
6
|
+
import { ConnectSelect, DocumentToolbar, Modal, ModalButton } from "@powerhousedao/design-system/connect";
|
|
7
|
+
import { usePHToast, useSetPHDocumentEditorConfig } from "@powerhousedao/reactor-browser";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { twMerge } from "tailwind-merge";
|
|
10
|
+
import { GraphQLError, Kind, buildASTSchema, getOperationAST, getVariableValues, parse, print, visit } from "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 = standardLibScalars.get(name);
|
|
202
|
+
if (!scalar) return null;
|
|
203
|
+
if (name === "Upload") throw new Error("The editor cannot derive an initial state value for an Upload field.");
|
|
204
|
+
if (scalar.schema.safeParse(existingFieldValue).success) return existingFieldValue;
|
|
205
|
+
return isNonNull ? existingFieldValue : null;
|
|
206
|
+
}
|
|
207
|
+
function makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes) {
|
|
208
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
209
|
+
if (!namedTypeDefinitionNode.types?.length) return null;
|
|
210
|
+
const firstNamedTypeDefinitionNode = namedTypeDefinitionNode.types?.at(0);
|
|
211
|
+
if (!firstNamedTypeDefinitionNode) return null;
|
|
212
|
+
const firstNamedTypeObjectDefinitionNode = getNamedTypeDefinitionNode(firstNamedTypeDefinitionNode, schemaDocumentNode);
|
|
213
|
+
if (!isObjectTypeDefinitionNode(firstNamedTypeObjectDefinitionNode)) return null;
|
|
214
|
+
return makeMinimalValueForGqlObject(firstNamedTypeObjectDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
|
|
215
|
+
}
|
|
216
|
+
function makeMinimalValueForGqlListNode(listTypeNode, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes) {
|
|
217
|
+
if (!isNonNull && !Array.isArray(existingFieldValue)) return null;
|
|
218
|
+
if (isNonNull && !Array.isArray(existingFieldValue)) return [];
|
|
219
|
+
return existingFieldValue.map((item, index) => makeMinimalValueForASTNode({
|
|
220
|
+
fieldName: String(index),
|
|
221
|
+
astNode: listTypeNode.type,
|
|
222
|
+
schemaDocumentNode,
|
|
223
|
+
existingValueObject: { [index]: item },
|
|
224
|
+
visitedTypes
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
function makeMinimalValueForGqlObject(objectTypeDefinitionNode, schemaDocumentNode, _existingValueObject, existingFieldValue, isNonNull, visitedTypes) {
|
|
228
|
+
const typeName = objectTypeDefinitionNode.name.value;
|
|
229
|
+
if (visitedTypes?.has(typeName)) return null;
|
|
230
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
231
|
+
const fields = objectTypeDefinitionNode.fields;
|
|
232
|
+
if (!fields?.length) return {};
|
|
233
|
+
const newVisitedTypes = new Set(visitedTypes);
|
|
234
|
+
newVisitedTypes.add(typeName);
|
|
235
|
+
return makeMinimalValuesForObjectFields({
|
|
236
|
+
schemaDocumentNode,
|
|
237
|
+
existingValueObject: existingFieldValue && typeof existingFieldValue === "object" && !Array.isArray(existingFieldValue) ? existingFieldValue : null,
|
|
238
|
+
fieldDefinitionNodes: fields,
|
|
239
|
+
visitedTypes: newVisitedTypes
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function getNamedTypeDefinitionNode(astNodeTypeNode, schemaDocumentNode) {
|
|
243
|
+
if (!astNodeTypeNode) return null;
|
|
244
|
+
const name = getASTNodeName(astNodeTypeNode);
|
|
245
|
+
if (!name) return null;
|
|
246
|
+
const definitionNode = schemaDocumentNode.definitions.find((def) => "kind" in def && "name" in def && def.name?.value === name);
|
|
247
|
+
if (!definitionNode) return null;
|
|
248
|
+
return definitionNode;
|
|
249
|
+
}
|
|
250
|
+
function removeWhitespace(str) {
|
|
251
|
+
return str.replace(/\s+|\\n|\\t/g, "").toLowerCase();
|
|
252
|
+
}
|
|
253
|
+
function compareStringsWithoutWhitespace(str1, str2) {
|
|
254
|
+
if (str1 === null || str2 === null || str1 === void 0 || str2 === void 0) return false;
|
|
255
|
+
return removeWhitespace(str1) === removeWhitespace(str2);
|
|
256
|
+
}
|
|
257
|
+
function renameSchemaType(sdl, oldName, newName, scope) {
|
|
258
|
+
const typeSuffix = scope === "global" ? "State" : "LocalState";
|
|
259
|
+
const oldTypeName = `${pascalCase(oldName)}${typeSuffix}`;
|
|
260
|
+
const newTypeName = `${pascalCase(newName)}${typeSuffix}`;
|
|
261
|
+
const ast = safeParseSdl(sdl);
|
|
262
|
+
if (!ast) return sdl;
|
|
263
|
+
const updatedAst = visit(ast, { ObjectTypeDefinition: (node) => {
|
|
264
|
+
if (node.name.value === oldTypeName) return {
|
|
265
|
+
...node,
|
|
266
|
+
name: {
|
|
267
|
+
...node.name,
|
|
268
|
+
value: newTypeName
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
} });
|
|
272
|
+
return print(updatedAst);
|
|
273
|
+
}
|
|
274
|
+
function initializeModelSchema(modelName) {
|
|
275
|
+
return makeInitialSchemaDoc(modelName, "global");
|
|
276
|
+
}
|
|
277
|
+
/** The initial value the schema sync would write for a new model's schema. */
|
|
278
|
+
function makeInitialValueForSchema(stateSchemaSdl) {
|
|
279
|
+
const documentNode = parse(stateSchemaSdl);
|
|
280
|
+
const stateTypeDefinitionNode = documentNode.definitions.find((def) => def.kind === Kind.OBJECT_TYPE_DEFINITION);
|
|
281
|
+
if (!stateTypeDefinitionNode) return "{}";
|
|
282
|
+
return makeMinimalObjectForStateType({
|
|
283
|
+
sharedSchemaDocumentNode: documentNode,
|
|
284
|
+
stateTypeDefinitionNode,
|
|
285
|
+
existingValue: "{}"
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function updateModelSchemaNames(params) {
|
|
289
|
+
const { oldName, newName, globalStateSchema, localStateSchema, setStateSchema } = params;
|
|
290
|
+
setStateSchema(renameSchemaType(globalStateSchema, oldName, newName, "global"), "global");
|
|
291
|
+
if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, oldName, newName, "local"), "local");
|
|
292
|
+
}
|
|
293
|
+
function handleModelNameChange(params) {
|
|
294
|
+
const { newName, globalStateSchema, setStateSchema } = params;
|
|
295
|
+
if (!!!globalStateSchema) {
|
|
296
|
+
setStateSchema(initializeModelSchema(newName), "global");
|
|
297
|
+
return;
|
|
102
298
|
}
|
|
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, "");
|
|
299
|
+
updateModelSchemaNames(params);
|
|
110
300
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function t(r, e) {
|
|
301
|
+
function validateStateObject(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateValue) {
|
|
302
|
+
let stateObjectJson;
|
|
114
303
|
try {
|
|
115
|
-
|
|
116
|
-
} catch (
|
|
117
|
-
return
|
|
304
|
+
stateObjectJson = JSON.parse(stateValue);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return [new Error("Invalid JSON object", { cause: error })];
|
|
118
307
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
308
|
+
const typeDefByName = indexTypeDefinitions(sharedSchemaDocumentNode);
|
|
309
|
+
const stateTypeName = stateTypeDefinitionNode.name.value;
|
|
310
|
+
if (!typeDefByName.has(stateTypeName)) return [/* @__PURE__ */ new Error(`State type "${stateTypeName}" was not found in sharedSchemaDocumentNode`)];
|
|
311
|
+
const inputSuffix = "Input";
|
|
312
|
+
const generatedInputDefs = generateInputTypesForObjectTree(stateTypeName, typeDefByName, inputSuffix);
|
|
313
|
+
const augmentedDoc = {
|
|
314
|
+
...sharedSchemaDocumentNode,
|
|
315
|
+
definitions: [...sharedSchemaDocumentNode.definitions, ...generatedInputDefs]
|
|
316
|
+
};
|
|
317
|
+
let schema;
|
|
318
|
+
try {
|
|
319
|
+
schema = buildASTSchema(augmentedDoc, { assumeValidSDL: false });
|
|
320
|
+
} catch (e) {
|
|
321
|
+
return [new Error("Failed to build schema from SDL", { cause: e })];
|
|
322
|
+
}
|
|
323
|
+
const inputTypeName = `${stateTypeName}${inputSuffix}`;
|
|
324
|
+
const opDoc = parse(`query($v: ${inputTypeName}!) { __typename }`);
|
|
325
|
+
const op = getOperationAST(opDoc);
|
|
326
|
+
if (!op) return [/* @__PURE__ */ new Error("Failed to create validation operation AST")];
|
|
327
|
+
const { errors } = getVariableValues(schema, op.variableDefinitions ?? [], { v: stateObjectJson });
|
|
328
|
+
const recursiveTypeErrors = detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName);
|
|
329
|
+
const recursiveFieldNames = new Set(recursiveTypeErrors.map((e) => e.field));
|
|
330
|
+
const validationErrors = errors ? graphQLErrorsToStateValidationErrors(errors).filter((e) => {
|
|
331
|
+
if (e instanceof StateValidationError && e.kind === "NON_NULL") {
|
|
332
|
+
const rootField = e.path[0];
|
|
333
|
+
if (typeof rootField === "string" && recursiveFieldNames.has(rootField)) return false;
|
|
141
334
|
}
|
|
142
|
-
|
|
335
|
+
return true;
|
|
336
|
+
}) : [];
|
|
337
|
+
validationErrors.unshift(...recursiveTypeErrors);
|
|
338
|
+
const missingOptionalErrors = detectMissingOptionalFields(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateObjectJson);
|
|
339
|
+
validationErrors.push(...missingOptionalErrors);
|
|
340
|
+
return validationErrors;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Indexes object/input/enum/scalar/interface/union type definition nodes by name.
|
|
344
|
+
* Note: only AST definitions that have a "name" field are indexed.
|
|
345
|
+
*/
|
|
346
|
+
function indexTypeDefinitions(doc) {
|
|
347
|
+
const map = /* @__PURE__ */ new Map();
|
|
348
|
+
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) {
|
|
349
|
+
const name = def.name.value;
|
|
350
|
+
if (!map.has(name)) map.set(name, def);
|
|
143
351
|
}
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
352
|
+
return map;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Generates InputObjectTypeDefinitionNode(s) for a root object type and any nested
|
|
356
|
+
* object types reachable via fields, converting object references to their *Input equivalents*.
|
|
357
|
+
*/
|
|
358
|
+
function generateInputTypesForObjectTree(rootObjectTypeName, typeDefByName, inputSuffix) {
|
|
359
|
+
const generated = /* @__PURE__ */ new Map();
|
|
360
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
361
|
+
const ensureInputForObject = (objectTypeName) => {
|
|
362
|
+
const inputName = `${objectTypeName}${inputSuffix}`;
|
|
363
|
+
if (generated.has(inputName)) return;
|
|
364
|
+
if (visiting.has(objectTypeName)) return;
|
|
365
|
+
visiting.add(objectTypeName);
|
|
366
|
+
const def = typeDefByName.get(objectTypeName);
|
|
367
|
+
if (!def) throw new GraphQLError(`Unknown referenced type "${objectTypeName}"`);
|
|
368
|
+
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}"`);
|
|
369
|
+
const objDef = def;
|
|
370
|
+
const inputFields = objDef.fields?.map((f) => {
|
|
371
|
+
return {
|
|
372
|
+
kind: Kind.INPUT_VALUE_DEFINITION,
|
|
373
|
+
name: f.name,
|
|
374
|
+
description: f.description,
|
|
375
|
+
directives: [],
|
|
376
|
+
type: convertOutputTypeNodeToInputTypeNode(f.type, typeDefByName, inputSuffix, ensureInputForObject),
|
|
377
|
+
defaultValue: void 0
|
|
154
378
|
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
379
|
+
}) ?? [];
|
|
380
|
+
const inputDef = {
|
|
381
|
+
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
382
|
+
name: {
|
|
383
|
+
kind: Kind.NAME,
|
|
384
|
+
value: inputName
|
|
385
|
+
},
|
|
386
|
+
description: objDef.description,
|
|
387
|
+
directives: [],
|
|
388
|
+
fields: inputFields
|
|
158
389
|
};
|
|
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;
|
|
390
|
+
generated.set(inputName, inputDef);
|
|
391
|
+
visiting.delete(objectTypeName);
|
|
392
|
+
};
|
|
393
|
+
ensureInputForObject(rootObjectTypeName);
|
|
394
|
+
return Array.from(generated.values());
|
|
170
395
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
396
|
+
function convertOutputTypeNodeToInputTypeNode(typeNode, typeDefByName, inputSuffix, ensureInputForObject) {
|
|
397
|
+
switch (typeNode.kind) {
|
|
398
|
+
case Kind.NON_NULL_TYPE: return {
|
|
399
|
+
kind: Kind.NON_NULL_TYPE,
|
|
400
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
401
|
+
};
|
|
402
|
+
case Kind.LIST_TYPE: return {
|
|
403
|
+
kind: Kind.LIST_TYPE,
|
|
404
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
405
|
+
};
|
|
406
|
+
case Kind.NAMED_TYPE: {
|
|
407
|
+
const named = typeNode;
|
|
408
|
+
const name = named.name.value;
|
|
409
|
+
const def = typeDefByName.get(name);
|
|
410
|
+
if (def?.kind === Kind.OBJECT_TYPE_DEFINITION || def?.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
411
|
+
ensureInputForObject(name);
|
|
412
|
+
return {
|
|
413
|
+
kind: Kind.NAMED_TYPE,
|
|
414
|
+
name: {
|
|
415
|
+
kind: Kind.NAME,
|
|
416
|
+
value: `${name}${inputSuffix}`
|
|
417
|
+
}
|
|
189
418
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
419
|
+
}
|
|
420
|
+
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;
|
|
421
|
+
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`);
|
|
422
|
+
throw new GraphQLError(`Unsupported named type "${name}" of kind "${def.kind}"`);
|
|
194
423
|
}
|
|
424
|
+
default: throw new GraphQLError(`Unsupported TypeNode kind: ${JSON.stringify(typeNode)}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
var StateValidationError = class extends Error {
|
|
428
|
+
payload;
|
|
429
|
+
originalMessage;
|
|
430
|
+
constructor(payload, originalMessage) {
|
|
431
|
+
super(payload.kind);
|
|
432
|
+
this.name = "StateValidationError";
|
|
433
|
+
this.payload = payload;
|
|
434
|
+
this.originalMessage = originalMessage;
|
|
435
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
436
|
+
}
|
|
437
|
+
get kind() {
|
|
438
|
+
return this.payload.kind;
|
|
439
|
+
}
|
|
440
|
+
get path() {
|
|
441
|
+
return this.payload.path;
|
|
442
|
+
}
|
|
443
|
+
get field() {
|
|
444
|
+
return this.payload.field;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
function extractInputPath(message) {
|
|
448
|
+
const match = message.match(/at\s+"([^"]+)"/);
|
|
449
|
+
if (!match) return [];
|
|
450
|
+
const parts = match[1].split(".").filter(Boolean);
|
|
451
|
+
return (parts[0] === "v" ? parts.slice(1) : parts).map((p) => /^\d+$/.test(p) ? Number(p) : p);
|
|
452
|
+
}
|
|
453
|
+
const RE_MISSING_REQUIRED_FIELD = /Field "([^"]+)" of required type "([^"]+)" was not provided\./;
|
|
454
|
+
const RE_UNKNOWN_FIELD = /Field "([^"]+)" is not defined by type "([^"]+)"\.(?: Did you mean "([^"]+)"\?)?/;
|
|
455
|
+
function extractMissingRequiredField(message) {
|
|
456
|
+
const m = message.match(RE_MISSING_REQUIRED_FIELD);
|
|
457
|
+
if (!m) return null;
|
|
458
|
+
return {
|
|
459
|
+
field: m[1],
|
|
460
|
+
expectedType: m[2]
|
|
195
461
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
462
|
+
}
|
|
463
|
+
function extractUnknownField(message) {
|
|
464
|
+
const m = message.match(RE_UNKNOWN_FIELD);
|
|
465
|
+
if (!m) return null;
|
|
466
|
+
return {
|
|
467
|
+
field: m[1],
|
|
468
|
+
typeName: m[2],
|
|
469
|
+
didYouMean: m[3]
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function lastFieldFromPath(path) {
|
|
473
|
+
for (let i = path.length - 1; i >= 0; i--) if (typeof path[i] === "string") return path[i];
|
|
474
|
+
}
|
|
475
|
+
function extractExpectedType(message) {
|
|
476
|
+
let m = message.match(/Expected non-nullable type "([^"]+)"/);
|
|
477
|
+
if (m?.[1]) return m[1];
|
|
478
|
+
m = message.match(/Expected type "([^"]+)"/);
|
|
479
|
+
if (m?.[1]) return m[1];
|
|
480
|
+
m = message.match(/;\s*([_A-Za-z][_0-9A-Za-z]*)\s+cannot represent/i);
|
|
481
|
+
if (m?.[1]) return m[1];
|
|
482
|
+
}
|
|
483
|
+
function graphQLErrorsToStateValidationErrors(errors) {
|
|
484
|
+
const out = [];
|
|
485
|
+
for (const e of errors) {
|
|
486
|
+
const originalMessage = e.message;
|
|
487
|
+
const missing = extractMissingRequiredField(originalMessage);
|
|
488
|
+
if (missing) {
|
|
489
|
+
out.push(new StateValidationError({
|
|
490
|
+
kind: "MISSING",
|
|
491
|
+
path: [missing.field],
|
|
492
|
+
field: missing.field,
|
|
493
|
+
expectedType: missing.expectedType
|
|
494
|
+
}, originalMessage));
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
const unknown = extractUnknownField(originalMessage);
|
|
498
|
+
if (unknown) {
|
|
499
|
+
out.push(new StateValidationError({
|
|
500
|
+
kind: "UNKNOWN_FIELD",
|
|
501
|
+
path: [unknown.field],
|
|
502
|
+
field: unknown.field,
|
|
503
|
+
didYouMean: unknown.didYouMean
|
|
504
|
+
}, originalMessage));
|
|
505
|
+
continue;
|
|
218
506
|
}
|
|
507
|
+
const path = extractInputPath(originalMessage);
|
|
508
|
+
const field = lastFieldFromPath(path) ?? "value";
|
|
509
|
+
const expectedType = extractExpectedType(originalMessage);
|
|
510
|
+
if (originalMessage.includes("Expected non-nullable type") && originalMessage.includes("not to be null")) {
|
|
511
|
+
out.push(new StateValidationError({
|
|
512
|
+
kind: "NON_NULL",
|
|
513
|
+
path,
|
|
514
|
+
field,
|
|
515
|
+
expectedType
|
|
516
|
+
}, originalMessage));
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (originalMessage.includes("cannot represent") || originalMessage.includes("Expected type")) {
|
|
520
|
+
out.push(new StateValidationError({
|
|
521
|
+
kind: "TYPE",
|
|
522
|
+
path,
|
|
523
|
+
field,
|
|
524
|
+
expectedType,
|
|
525
|
+
details: originalMessage
|
|
526
|
+
}, originalMessage));
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
out.push(new StateValidationError({
|
|
530
|
+
kind: "TYPE",
|
|
531
|
+
path,
|
|
532
|
+
field,
|
|
533
|
+
details: originalMessage
|
|
534
|
+
}, originalMessage));
|
|
535
|
+
}
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Finds all fields defined in the schema that are missing from the state object.
|
|
540
|
+
* Returns information about each missing field including whether it's required.
|
|
541
|
+
*/
|
|
542
|
+
function findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value, basePath = []) {
|
|
543
|
+
let stateObjectJson;
|
|
544
|
+
try {
|
|
545
|
+
stateObjectJson = typeof value === "string" ? JSON.parse(value) : value;
|
|
546
|
+
} catch {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
const typeByName = indexObjectTypes(sharedSchemaDocumentNode);
|
|
550
|
+
const missingFields = [];
|
|
551
|
+
for (const field of rootTypeNode.fields ?? []) {
|
|
552
|
+
const fieldName = field.name.value;
|
|
553
|
+
const fieldPath = [...basePath, fieldName];
|
|
554
|
+
const isRequired = field.type.kind === Kind.NON_NULL_TYPE;
|
|
555
|
+
const underlyingType = isRequired ? field.type.type : field.type;
|
|
556
|
+
if (!(fieldName in stateObjectJson)) {
|
|
557
|
+
missingFields.push({
|
|
558
|
+
fieldName,
|
|
559
|
+
path: fieldPath,
|
|
560
|
+
isRequired,
|
|
561
|
+
type: underlyingType
|
|
562
|
+
});
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
const namedType = unwrapNamedType(field.type);
|
|
566
|
+
const childType = namedType ? typeByName.get(namedType) : void 0;
|
|
567
|
+
if (childType && typeof stateObjectJson[fieldName] === "object" && stateObjectJson[fieldName] !== null && !Array.isArray(stateObjectJson[fieldName])) {
|
|
568
|
+
const nestedMissing = findMissingFields(sharedSchemaDocumentNode, childType, stateObjectJson[fieldName], fieldPath);
|
|
569
|
+
missingFields.push(...nestedMissing);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return missingFields;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Detects optional fields defined in the schema that are missing from the state object.
|
|
576
|
+
* Returns StateValidationError[] for each missing optional field.
|
|
577
|
+
*/
|
|
578
|
+
function detectMissingOptionalFields(sharedSchemaDocumentNode, rootTypeNode, value) {
|
|
579
|
+
return findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value).filter((field) => !field.isRequired).map((field) => new StateValidationError({
|
|
580
|
+
kind: "MISSING_OPTIONAL",
|
|
581
|
+
path: field.path,
|
|
582
|
+
field: field.fieldName,
|
|
583
|
+
expectedType: typeNodeToString(field.type)
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Detects fields that have recursive types (types that reference themselves directly or indirectly).
|
|
588
|
+
* Returns a RECURSIVE_TYPE error for each field that contains a recursive type.
|
|
589
|
+
*/
|
|
590
|
+
function detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName) {
|
|
591
|
+
const errors = [];
|
|
592
|
+
for (const field of stateTypeDefinitionNode.fields ?? []) {
|
|
593
|
+
const fieldName = field.name.value;
|
|
594
|
+
const namedTypeName = getNamedTypeName(field.type);
|
|
595
|
+
if (!namedTypeName) continue;
|
|
596
|
+
if (isRecursiveType(namedTypeName, typeDefByName, /* @__PURE__ */ new Set())) errors.push(new StateValidationError({
|
|
597
|
+
kind: "RECURSIVE_TYPE",
|
|
598
|
+
path: [fieldName],
|
|
599
|
+
field: fieldName,
|
|
600
|
+
typeName: namedTypeName
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
return errors;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Gets the named type name from a TypeNode, unwrapping NonNull and List types.
|
|
607
|
+
*/
|
|
608
|
+
function getNamedTypeName(typeNode) {
|
|
609
|
+
if (typeNode.kind === Kind.NAMED_TYPE) return typeNode.name.value;
|
|
610
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE || typeNode.kind === Kind.LIST_TYPE) return getNamedTypeName(typeNode.type);
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Checks if a type is recursive (references itself directly or indirectly through required fields).
|
|
615
|
+
*/
|
|
616
|
+
function isRecursiveType(typeName, typeDefByName, visitedTypes) {
|
|
617
|
+
if (visitedTypes.has(typeName)) return true;
|
|
618
|
+
const typeDef = typeDefByName.get(typeName);
|
|
619
|
+
if (!typeDef || typeDef.kind !== Kind.OBJECT_TYPE_DEFINITION) return false;
|
|
620
|
+
visitedTypes.add(typeName);
|
|
621
|
+
for (const field of typeDef.fields ?? []) {
|
|
622
|
+
if (field.type.kind !== Kind.NON_NULL_TYPE) continue;
|
|
623
|
+
const innerType = field.type.type;
|
|
624
|
+
let fieldTypeName = null;
|
|
625
|
+
if (innerType.kind === Kind.NAMED_TYPE) fieldTypeName = innerType.name.value;
|
|
626
|
+
else if (innerType.kind === Kind.LIST_TYPE) fieldTypeName = getNamedTypeName(innerType);
|
|
627
|
+
if (fieldTypeName && isRecursiveType(fieldTypeName, typeDefByName, visitedTypes)) return true;
|
|
628
|
+
}
|
|
629
|
+
visitedTypes.delete(typeName);
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Converts a TypeNode to its string representation (e.g., "String", "Int!", "[String]!")
|
|
634
|
+
*/
|
|
635
|
+
function typeNodeToString(typeNode) {
|
|
636
|
+
switch (typeNode.kind) {
|
|
637
|
+
case Kind.NAMED_TYPE: return typeNode.name.value;
|
|
638
|
+
case Kind.NON_NULL_TYPE: return `${typeNodeToString(typeNode.type)}!`;
|
|
639
|
+
case Kind.LIST_TYPE: return `[${typeNodeToString(typeNode.type)}]`;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function indexObjectTypes(doc) {
|
|
643
|
+
const map = /* @__PURE__ */ new Map();
|
|
644
|
+
for (const def of doc.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION) map.set(def.name.value, def);
|
|
645
|
+
return map;
|
|
646
|
+
}
|
|
647
|
+
function unwrapNamedType(typeNode) {
|
|
648
|
+
if (typeNode.kind === Kind.NAMED_TYPE) return typeNode.name.value;
|
|
649
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE) return unwrapNamedType(typeNode.type);
|
|
650
|
+
if (typeNode.kind === Kind.LIST_TYPE) return unwrapNamedType(typeNode.type);
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region editors/document-model-editor/utils/linting.ts
|
|
654
|
+
function ensureDocumentContainsNodeWithNameAndType(doc, nodeName, nodeType) {
|
|
655
|
+
const parsedDoc = safeParseSdl(doc);
|
|
656
|
+
if (!parsedDoc) return true;
|
|
657
|
+
return parsedDoc.definitions.some((def) => {
|
|
658
|
+
return def.kind === Kind[nodeType] && "name" in def && def.name?.value === nodeName;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
function createNodeTypeAndNameDiagnostic(doc, errorMessage) {
|
|
662
|
+
const parsedDoc = safeParseSdl(doc);
|
|
663
|
+
if (!parsedDoc) return void 0;
|
|
664
|
+
const firstNode = parsedDoc.definitions[0];
|
|
665
|
+
const nameNode = "name" in firstNode ? firstNode.name : null;
|
|
666
|
+
return {
|
|
667
|
+
from: nameNode?.loc?.start ?? firstNode.loc?.start ?? 0,
|
|
668
|
+
to: nameNode?.loc?.end ?? firstNode.loc?.end ?? 0,
|
|
669
|
+
severity: "error",
|
|
670
|
+
message: errorMessage
|
|
219
671
|
};
|
|
220
|
-
|
|
672
|
+
}
|
|
673
|
+
function ensureValidStateSchemaName(doc, modelName, scope) {
|
|
674
|
+
if (!safeParseSdl(doc)) return [];
|
|
675
|
+
const requiredTypeName = makeStateSchemaNameForScope(modelName, scope);
|
|
676
|
+
if (!ensureDocumentContainsNodeWithNameAndType(doc, requiredTypeName, "OBJECT_TYPE_DEFINITION")) return [createNodeTypeAndNameDiagnostic(doc, `${sentenceCase(scope)} state schema must be named ${requiredTypeName}`)].filter((d) => d !== void 0);
|
|
677
|
+
return [];
|
|
678
|
+
}
|
|
679
|
+
function ensureValidOperationSchemaInputName(doc, operationName) {
|
|
680
|
+
if (!doc || !safeParseSdl(doc)) return [];
|
|
681
|
+
const requiredTypeName = `${pascalCase(operationName)}Input`;
|
|
682
|
+
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);
|
|
683
|
+
return [];
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region editors/document-model-editor/components/button.tsx
|
|
687
|
+
const Button = forwardRef((props, ref) => {
|
|
688
|
+
const { className, ...rest } = props;
|
|
689
|
+
return /* @__PURE__ */ jsx("button", {
|
|
690
|
+
ref,
|
|
691
|
+
...rest,
|
|
692
|
+
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)
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region editors/document-model-editor/components/divider.tsx
|
|
697
|
+
function Divider({ className, size = "sm", margin = "md" }) {
|
|
698
|
+
function getSize() {
|
|
699
|
+
if (size === "sm") return "h-px";
|
|
700
|
+
if (size === "md") return "h-1";
|
|
701
|
+
return "h-1.5";
|
|
702
|
+
}
|
|
703
|
+
function getMargin() {
|
|
704
|
+
if (margin === "sm") return "my-4";
|
|
705
|
+
if (margin === "md") return "my-6";
|
|
706
|
+
return "my-8";
|
|
707
|
+
}
|
|
708
|
+
const sizeClass = getSize();
|
|
709
|
+
const marginClass = getMargin();
|
|
710
|
+
return /* @__PURE__ */ jsx("div", { className: twMerge("bg-secondary", sizeClass, marginClass, className) });
|
|
221
711
|
}
|
|
222
712
|
//#endregion
|
|
223
713
|
//#region editors/document-model-editor/schemas/inputs.ts
|
|
@@ -225,16 +715,16 @@ const isUppercase = (value) => !/\p{Ll}/u.test(value);
|
|
|
225
715
|
const isLowercase = (value) => !/\p{Lu}/u.test(value);
|
|
226
716
|
function createNameSchema(options = {}) {
|
|
227
717
|
const { required = false, allowEmpty = false, unique = [] } = options;
|
|
228
|
-
const baseSchema = allowEmpty ? string() : string().min(1);
|
|
718
|
+
const baseSchema = allowEmpty ? z.string() : z.string().min(1);
|
|
229
719
|
const uniqueRefinement = baseSchema.refine((value) => {
|
|
230
720
|
if (!value && allowEmpty) return true;
|
|
231
721
|
return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
|
|
232
722
|
}, { message: "Item with this name already exists" });
|
|
233
|
-
if (!required) return unique.length > 0 ? string().optional().refine((value) => {
|
|
723
|
+
if (!required) return unique.length > 0 ? z.string().optional().refine((value) => {
|
|
234
724
|
if (value === void 0) return true;
|
|
235
725
|
if (!value && allowEmpty) return true;
|
|
236
726
|
return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
|
|
237
|
-
}, { message: "Item with this name already exists" }) : string().optional();
|
|
727
|
+
}, { message: "Item with this name already exists" }) : z.string().optional();
|
|
238
728
|
return unique.length > 0 ? uniqueRefinement : baseSchema;
|
|
239
729
|
}
|
|
240
730
|
function createConstantCaseSchema(options = {}) {
|
|
@@ -249,9 +739,9 @@ function toLowercaseSnakeCase(value, options = {}) {
|
|
|
249
739
|
function toConstantCase(value, options = {}) {
|
|
250
740
|
return createConstantCaseSchema(options).parse(constantCase(value));
|
|
251
741
|
}
|
|
252
|
-
object({
|
|
742
|
+
z.object({
|
|
253
743
|
name: createNameSchema({ allowEmpty: true }),
|
|
254
|
-
website: union([url(), literal("")]).optional().default("")
|
|
744
|
+
website: z.union([z.url(), z.literal("")]).optional().default("")
|
|
255
745
|
}).default({
|
|
256
746
|
name: "",
|
|
257
747
|
website: ""
|
|
@@ -279,30 +769,14 @@ const useFormField = () => {
|
|
|
279
769
|
};
|
|
280
770
|
};
|
|
281
771
|
//#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
772
|
//#region editors/document-model-editor/components/label.tsx
|
|
299
773
|
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, {
|
|
774
|
+
const Label = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(LabelPrimitive.Root, {
|
|
301
775
|
ref,
|
|
302
776
|
className: twMerge(labelVariants(), className),
|
|
303
777
|
...props
|
|
304
778
|
}));
|
|
305
|
-
Label.displayName = Root.displayName;
|
|
779
|
+
Label.displayName = LabelPrimitive.Root.displayName;
|
|
306
780
|
//#endregion
|
|
307
781
|
//#region editors/document-model-editor/components/form.tsx
|
|
308
782
|
const Form = FormProvider;
|
|
@@ -403,12 +877,13 @@ const TextField = forwardRef(({ name, value, onSubmit, label, placeholder, uniqu
|
|
|
403
877
|
useEffect(() => {
|
|
404
878
|
if (focusOnMount && textareaRef.current) textareaRef.current.focus();
|
|
405
879
|
}, [focusOnMount]);
|
|
880
|
+
const fieldSchema = z.object({ [name]: createNameSchema({
|
|
881
|
+
required,
|
|
882
|
+
allowEmpty,
|
|
883
|
+
unique
|
|
884
|
+
}) });
|
|
406
885
|
const form = useForm({
|
|
407
|
-
resolver:
|
|
408
|
-
required,
|
|
409
|
-
allowEmpty,
|
|
410
|
-
unique
|
|
411
|
-
}) })),
|
|
886
|
+
resolver: zodResolver(fieldSchema),
|
|
412
887
|
defaultValues: { [name]: value ?? "" }
|
|
413
888
|
});
|
|
414
889
|
const handleSubmit = useCallback((values) => {
|
|
@@ -497,13 +972,13 @@ const TextField = forwardRef(({ name, value, onSubmit, label, placeholder, uniqu
|
|
|
497
972
|
});
|
|
498
973
|
});
|
|
499
974
|
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()
|
|
975
|
+
z.object({
|
|
976
|
+
name: z.string(),
|
|
977
|
+
documentType: z.string(),
|
|
978
|
+
extension: z.string().optional().default(""),
|
|
979
|
+
description: z.string(),
|
|
980
|
+
authorName: z.string(),
|
|
981
|
+
authorWebsite: z.string()
|
|
507
982
|
});
|
|
508
983
|
function ModelMetadata(props) {
|
|
509
984
|
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(ModelNameForm, { ...props }), /* @__PURE__ */ jsx("div", {
|
|
@@ -532,32 +1007,38 @@ function ModelMetadata(props) {
|
|
|
532
1007
|
}
|
|
533
1008
|
function ModelNameForm(props) {
|
|
534
1009
|
const { name, globalStateSchema, localStateSchema, setModelName, setStateSchema } = props;
|
|
1010
|
+
const onSubmit = useCallback((newName) => {
|
|
1011
|
+
if (name === newName) return;
|
|
1012
|
+
setModelName(newName);
|
|
1013
|
+
if (!!!globalStateSchema) {
|
|
1014
|
+
const initialSchemaDoc = makeInitialSchemaDoc(newName, "global");
|
|
1015
|
+
setStateSchema(initialSchemaDoc, "global");
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const newSchema = renameSchemaType(globalStateSchema, name, newName, "global");
|
|
1019
|
+
setStateSchema(newSchema, "global");
|
|
1020
|
+
if (localStateSchema) {
|
|
1021
|
+
const newLocalStateSchema = renameSchemaType(localStateSchema, name, newName, "local");
|
|
1022
|
+
setStateSchema(newLocalStateSchema, "local");
|
|
1023
|
+
}
|
|
1024
|
+
handleModelNameChange({
|
|
1025
|
+
oldName: name,
|
|
1026
|
+
newName,
|
|
1027
|
+
globalStateSchema,
|
|
1028
|
+
localStateSchema,
|
|
1029
|
+
setStateSchema
|
|
1030
|
+
});
|
|
1031
|
+
}, [
|
|
1032
|
+
name,
|
|
1033
|
+
globalStateSchema,
|
|
1034
|
+
localStateSchema,
|
|
1035
|
+
setStateSchema,
|
|
1036
|
+
setModelName
|
|
1037
|
+
]);
|
|
535
1038
|
return /* @__PURE__ */ jsx(TextField, {
|
|
536
1039
|
name: "name",
|
|
537
1040
|
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
|
-
]),
|
|
1041
|
+
onSubmit,
|
|
561
1042
|
placeholder: "Model name",
|
|
562
1043
|
className: "border-none pl-0 text-xl font-bold text-foreground",
|
|
563
1044
|
required: true,
|
|
@@ -758,7 +1239,7 @@ function OperationErrors({ operation, addOperationError, deleteOperationError, s
|
|
|
758
1239
|
}
|
|
759
1240
|
//#endregion
|
|
760
1241
|
//#region editors/document-model-editor/components/operation.tsx
|
|
761
|
-
const GraphqlEditor = lazy(() => import("./graphql-editor-
|
|
1242
|
+
const GraphqlEditor = lazy(() => import("./graphql-editor-CGxwONKl.js"));
|
|
762
1243
|
function Operation(props) {
|
|
763
1244
|
const { operation, module, allOperationNames, lastCreatedOperationId, onAddOperationAndInitialSchema, updateOperationName, deleteOperation, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired } = props;
|
|
764
1245
|
const noInputRequired = isEmptyOperationSchema(operation.schema);
|
|
@@ -1141,7 +1622,7 @@ function VersionAdvisoryModal(props) {
|
|
|
1141
1622
|
" ",
|
|
1142
1623
|
"may stop working correctly."
|
|
1143
1624
|
] }),
|
|
1144
|
-
diff && /* @__PURE__ */ jsxs(Fragment
|
|
1625
|
+
diff && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1145
1626
|
/* @__PURE__ */ jsx(FieldDiffList, {
|
|
1146
1627
|
fields: diff.addedFields,
|
|
1147
1628
|
label: "New fields:"
|
|
@@ -1194,11 +1675,6 @@ function VersionAdvisoryModal(props) {
|
|
|
1194
1675
|
//#region editors/document-model-editor/config.ts
|
|
1195
1676
|
const editorConfig = { isExternalControlsEnabled: false };
|
|
1196
1677
|
//#endregion
|
|
1197
|
-
//#region editors/document-model-editor/hooks/useDocumentModelDocument.ts
|
|
1198
|
-
function useSelectedDocumentModelDocument() {
|
|
1199
|
-
return useSelectedDocumentOfType("powerhouse/document-model");
|
|
1200
|
-
}
|
|
1201
|
-
//#endregion
|
|
1202
1678
|
//#region editors/document-model-editor/utils/change-classification.ts
|
|
1203
1679
|
function isShapeTypeNode(node) {
|
|
1204
1680
|
return node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === Kind.ENUM_TYPE_DEFINITION;
|
|
@@ -1261,8 +1737,8 @@ function diffSdlShapes(oldSdl, newSdl) {
|
|
|
1261
1737
|
let oldDoc;
|
|
1262
1738
|
let newDoc;
|
|
1263
1739
|
try {
|
|
1264
|
-
oldDoc = parse
|
|
1265
|
-
newDoc = parse
|
|
1740
|
+
oldDoc = parse(oldSdl);
|
|
1741
|
+
newDoc = parse(newSdl);
|
|
1266
1742
|
} catch {
|
|
1267
1743
|
return empty;
|
|
1268
1744
|
}
|
|
@@ -1298,7 +1774,7 @@ function isPlaceholderOnlySchema(sdl) {
|
|
|
1298
1774
|
if (isBlank(sdl)) return true;
|
|
1299
1775
|
let doc;
|
|
1300
1776
|
try {
|
|
1301
|
-
doc = parse
|
|
1777
|
+
doc = parse(sdl);
|
|
1302
1778
|
} catch {
|
|
1303
1779
|
return false;
|
|
1304
1780
|
}
|
|
@@ -1494,13 +1970,13 @@ function useVersionAdvisory(args) {
|
|
|
1494
1970
|
}
|
|
1495
1971
|
//#endregion
|
|
1496
1972
|
//#region editors/document-model-editor/editor.tsx
|
|
1497
|
-
|
|
1973
|
+
var editor_exports = /* @__PURE__ */ __exportAll({ default: () => Editor });
|
|
1974
|
+
const StateSchemas = lazy(() => import("./state-schemas-DSY44MOd.js"));
|
|
1498
1975
|
const noopSetStateSchema = () => void 0;
|
|
1499
1976
|
const noopSetInitialState = () => void 0;
|
|
1500
|
-
function Editor() {
|
|
1977
|
+
function Editor({ document, dispatch }) {
|
|
1501
1978
|
useSetPHDocumentEditorConfig(editorConfig);
|
|
1502
1979
|
const toast = usePHToast();
|
|
1503
|
-
const [document, dispatch] = useSelectedDocumentModelDocument();
|
|
1504
1980
|
const [scope, setScope] = useState("global");
|
|
1505
1981
|
const documentNodeName = document.header.name;
|
|
1506
1982
|
const { name: modelName, id: documentType, extension, description, author: { name: authorName, website: authorWebsite } } = document.state.global;
|
|
@@ -1514,14 +1990,21 @@ function Editor() {
|
|
|
1514
1990
|
const operations = modules.flatMap((module) => module.operations);
|
|
1515
1991
|
const { state: { global: { schema: latestGlobalStateSchema, initialValue: latestGlobalStateInitialValue }, local: { schema: latestLocalStateSchema, initialValue: latestLocalStateInitialValue } }, modules: latestModules } = latestSpec;
|
|
1516
1992
|
const latestOperations = latestModules.flatMap((module) => module.operations);
|
|
1517
|
-
const shouldSetInitialName = useRef(!modelName && !!documentNodeName &&
|
|
1993
|
+
const shouldSetInitialName = useRef(!modelName && !!documentNodeName && specifications.length === 1 && !latestGlobalStateSchema && latestModules.length === 0);
|
|
1518
1994
|
useEffect(() => {
|
|
1519
1995
|
if (!shouldSetInitialName.current || !documentNodeName) return;
|
|
1520
1996
|
const initialSchemaDoc = initializeModelSchema(documentNodeName);
|
|
1521
|
-
dispatch([
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1997
|
+
dispatch([
|
|
1998
|
+
setModelName({ name: documentNodeName }),
|
|
1999
|
+
setStateSchema({
|
|
2000
|
+
schema: initialSchemaDoc,
|
|
2001
|
+
scope: "global"
|
|
2002
|
+
}),
|
|
2003
|
+
setInitialState({
|
|
2004
|
+
initialValue: makeInitialValueForSchema(initialSchemaDoc),
|
|
2005
|
+
scope: "global"
|
|
2006
|
+
})
|
|
2007
|
+
]);
|
|
1525
2008
|
shouldSetInitialName.current = false;
|
|
1526
2009
|
}, [documentNodeName, dispatch]);
|
|
1527
2010
|
const { guardedDispatch, prompt, releaseFirst, keepEditing, cancelAdvisory, markVersionInDevelopment } = useVersionAdvisory({
|
|
@@ -1672,11 +2155,12 @@ function Editor() {
|
|
|
1672
2155
|
return;
|
|
1673
2156
|
}
|
|
1674
2157
|
const id = generateId();
|
|
2158
|
+
const errorCode = pascalCase(errorName);
|
|
1675
2159
|
guardedDispatch(addOperationError({
|
|
1676
2160
|
id,
|
|
1677
2161
|
operationId,
|
|
1678
2162
|
errorName,
|
|
1679
|
-
errorCode
|
|
2163
|
+
errorCode
|
|
1680
2164
|
}));
|
|
1681
2165
|
resolve(id);
|
|
1682
2166
|
} catch (error) {
|
|
@@ -1714,7 +2198,7 @@ function Editor() {
|
|
|
1714
2198
|
return /* @__PURE__ */ jsxs("main", {
|
|
1715
2199
|
className: "min-h-dvh bg-background p-6",
|
|
1716
2200
|
children: [
|
|
1717
|
-
/* @__PURE__ */ jsx(DocumentToolbar, {}),
|
|
2201
|
+
/* @__PURE__ */ jsx(DocumentToolbar, { document }),
|
|
1718
2202
|
/* @__PURE__ */ jsx(SchemaContextProvider, {
|
|
1719
2203
|
globalStateSchemaSdl: globalStateSchema,
|
|
1720
2204
|
localStateSchemaSdl: localStateSchema,
|
|
@@ -1804,6 +2288,6 @@ function Editor() {
|
|
|
1804
2288
|
});
|
|
1805
2289
|
}
|
|
1806
2290
|
//#endregion
|
|
1807
|
-
export { Editor as default };
|
|
2291
|
+
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
2292
|
|
|
1809
|
-
//# sourceMappingURL=editor-
|
|
2293
|
+
//# sourceMappingURL=editor-DXAJ8Mqb.js.map
|