@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.23 → 6.2.3-dev.25
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/assets/{entry-4ObkElbc.js → entry-GDzXcBs1.js} +10 -6
- package/dist/browser/assets/{projection-entry-4FDMlGcp.js → projection-entry-BJpyPvov.js} +7 -13
- package/dist/browser/{documents-C-lAnv6o.js → documents-CRzouuNR.js} +45 -35
- package/dist/browser/{documents-C-lAnv6o.js.map → documents-CRzouuNR.js.map} +1 -1
- package/dist/browser/{editor-DNV-46lY.js → editor-CYdXmSpt.js} +2 -3
- package/dist/browser/{editor-DNV-46lY.js.map → editor-CYdXmSpt.js.map} +1 -1
- package/dist/browser/{editor-CQ4wUFK5.js → editor-Dk_HEgr2.js} +943 -66
- package/dist/browser/editor-Dk_HEgr2.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 +68 -57
- 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/{src-CVV6HzQZ-D-OQvEkh.js → folder-view-DjGlA0kT.js} +901 -1643
- package/dist/browser/folder-view-DjGlA0kT.js.map +1 -0
- package/dist/browser/{graphql-editor-DoXZvdNr.js → graphql-editor-C9Nc_cOY.js} +97 -85
- package/dist/browser/graphql-editor-C9Nc_cOY.js.map +1 -0
- package/dist/{node/hooks-Di3FASx-.mjs → browser/hooks-eQxBX7g4.js} +824 -444
- package/dist/browser/{hooks-Bh1JCohS.js.map → hooks-eQxBX7g4.js.map} +1 -1
- package/dist/browser/index.js +16 -14
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/{json-editor-DBhkG5TF.js → json-editor-DfRD-pfk.js} +7 -7
- package/dist/browser/{json-editor-DBhkG5TF.js.map → json-editor-DfRD-pfk.js.map} +1 -1
- package/dist/browser/{parser-BBzK7bLd.js → parser-DtbeHA3H.js} +7 -6
- package/dist/browser/{parser-BBzK7bLd.js.map → parser-DtbeHA3H.js.map} +1 -1
- package/dist/browser/{chunk-BVTlhY3a.js → rolldown-runtime-DC62tzP2.js} +12 -3
- package/dist/browser/src-CrUksCLW-Co0PBoNN.js +5255 -0
- package/dist/browser/src-CrUksCLW-Co0PBoNN.js.map +1 -0
- package/dist/browser/{state-schemas-B47wHvDV.js → state-schemas-BSc_36Vd.js} +12 -10
- package/dist/browser/{state-schemas-B47wHvDV.js.map → state-schemas-BSc_36Vd.js.map} +1 -1
- package/dist/browser/{tslib.es6-CeIASJ2O.js → tslib.es6-Cno80yFJ.js} +1 -1
- package/dist/browser/{tslib.es6-CeIASJ2O.js.map → tslib.es6-Cno80yFJ.js.map} +1 -1
- package/dist/node/{documents-XAQfHX5Q.mjs → documents-D70S9PZL.mjs} +2 -2
- package/dist/node/documents-D70S9PZL.mjs.map +1 -0
- package/dist/node/{editor-Cp2TC5MJ.mjs → editor-BZZ0eN3p.mjs} +2 -3
- package/dist/node/{editor-Cp2TC5MJ.mjs.map → editor-BZZ0eN3p.mjs.map} +1 -1
- package/dist/node/{editor-BiiLqEe9.mjs → editor-CeSEXEgf.mjs} +866 -68
- package/dist/node/editor-CeSEXEgf.mjs.map +1 -0
- 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 +19 -13
- 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/{src-CVV6HzQZ-CvqjXbXk.mjs → folder-view-B2Jo-wsr.mjs} +891 -2311
- package/dist/node/{src-CVV6HzQZ-CvqjXbXk.mjs.map → folder-view-B2Jo-wsr.mjs.map} +1 -1
- package/dist/node/{graphql-BvV3tC1U.mjs → graphql-Dp4j7rmx.mjs} +50 -49
- package/dist/node/{graphql-BvV3tC1U.mjs.map → graphql-Dp4j7rmx.mjs.map} +1 -1
- package/dist/node/{graphql-editor-BhF6KN6y.mjs → graphql-editor-CBJXEY_C.mjs} +76 -61
- package/dist/node/graphql-editor-CBJXEY_C.mjs.map +1 -0
- package/dist/{browser/hooks-Bh1JCohS.js → node/hooks-C2b46djt.mjs} +824 -444
- package/dist/node/{hooks-Di3FASx-.mjs.map → hooks-C2b46djt.mjs.map} +1 -1
- package/dist/node/index.mjs +16 -15
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{json-editor-Cqc0zuz0.mjs → json-editor-DaqHARBD.mjs} +7 -7
- package/dist/node/{json-editor-Cqc0zuz0.mjs.map → json-editor-DaqHARBD.mjs.map} +1 -1
- package/dist/node/{schema-context-mHmP3Cl6.mjs → schema-context-CojjnSE6.mjs} +6 -5
- package/dist/node/schema-context-CojjnSE6.mjs.map +1 -0
- package/dist/node/src-CrUksCLW-BHpiSprT.mjs +5936 -0
- package/dist/node/src-CrUksCLW-BHpiSprT.mjs.map +1 -0
- package/dist/node/{state-schemas-DXG02fMh.mjs → state-schemas-CWuLjYFF.mjs} +13 -10
- package/dist/node/{state-schemas-DXG02fMh.mjs.map → state-schemas-CWuLjYFF.mjs.map} +1 -1
- package/dist/node/{tslib.es6-DdiHgz9e.mjs → tslib.es6-VORZjfk3.mjs} +45 -7
- package/dist/node/{tslib.es6-DdiHgz9e.mjs.map → tslib.es6-VORZjfk3.mjs.map} +1 -1
- package/package.json +11 -10
- package/dist/browser/button-sZQCXeCo.js +0 -803
- package/dist/browser/button-sZQCXeCo.js.map +0 -1
- package/dist/browser/dist-D3_ER0Dn.js +0 -2314
- package/dist/browser/dist-D3_ER0Dn.js.map +0 -1
- package/dist/browser/editor-CQ4wUFK5.js.map +0 -1
- package/dist/browser/folder-view-CzItU0hn.js +0 -957
- package/dist/browser/folder-view-CzItU0hn.js.map +0 -1
- package/dist/browser/graphql-editor-DoXZvdNr.js.map +0 -1
- package/dist/browser/schema-context-p2bhyog_.js +0 -69
- package/dist/browser/schema-context-p2bhyog_.js.map +0 -1
- package/dist/browser/src-CVV6HzQZ-D-OQvEkh.js.map +0 -1
- package/dist/node/button-5bnYEAVq.mjs +0 -785
- package/dist/node/button-5bnYEAVq.mjs.map +0 -1
- package/dist/node/chunk-17FXJ3dL.mjs +0 -31
- package/dist/node/dist-Bf_PIbO7.mjs +0 -2314
- package/dist/node/dist-Bf_PIbO7.mjs.map +0 -1
- package/dist/node/documents-XAQfHX5Q.mjs.map +0 -1
- package/dist/node/editor-BiiLqEe9.mjs.map +0 -1
- package/dist/node/folder-view-m_rH84Nz.mjs +0 -962
- package/dist/node/folder-view-m_rH84Nz.mjs.map +0 -1
- package/dist/node/graphql-editor-BhF6KN6y.mjs.map +0 -1
- package/dist/node/schema-context-mHmP3Cl6.mjs.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { h as twMerge } from "./
|
|
4
|
-
import { t as SchemaContextProvider } from "./schema-context-
|
|
5
|
-
import { _ as pascalCase, a as compareStringsWithoutWhitespace, c as isEmptyOperationSchema, f as makeOperationInitialDoc, g as constantCase, l as makeEmptyOperationSchema, m as renameSchemaType, n as ensureValidOperationSchemaInputName, o as handleModelNameChange, s as initializeModelSchema, t as Button, u as makeInitialSchemaDoc, v as snakeCase } from "./button-5bnYEAVq.mjs";
|
|
1
|
+
import { i as __exportAll } from "./tslib.es6-VORZjfk3.mjs";
|
|
2
|
+
import { t as require_graphql } from "./graphql-Dp4j7rmx.mjs";
|
|
3
|
+
import { a as Slot, h as twMerge, i as Primitive, t as Modal } from "./src-CrUksCLW-BHpiSprT.mjs";
|
|
4
|
+
import { n as safeParseSdl, t as SchemaContextProvider } from "./schema-context-CojjnSE6.mjs";
|
|
6
5
|
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";
|
|
7
6
|
import { z } from "zod";
|
|
8
7
|
import * as React$1 from "react";
|
|
@@ -10,8 +9,10 @@ import React, { Suspense, forwardRef, lazy, useCallback, useEffect, useId, useIm
|
|
|
10
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
10
|
import { ConnectSelect, DocumentToolbar, ModalButton } from "@powerhousedao/design-system/connect";
|
|
12
11
|
import { usePHToast, useSelectedDocumentOfType, useSetPHDocumentEditorConfig } from "@powerhousedao/reactor-browser";
|
|
12
|
+
import { getPHCustomScalarByTypeName } from "@powerhousedao/document-engineering/graphql";
|
|
13
13
|
import * as n from "zod/v4/core";
|
|
14
14
|
//#region ../../node_modules/.pnpm/clsx@2.0.0/node_modules/clsx/dist/clsx.mjs
|
|
15
|
+
var import_graphql = require_graphql();
|
|
15
16
|
function r$1(e) {
|
|
16
17
|
var t, f, n = "";
|
|
17
18
|
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
@@ -45,7 +46,7 @@ const cva = (base, config) => {
|
|
|
45
46
|
acc[key] = value;
|
|
46
47
|
return acc;
|
|
47
48
|
}, {});
|
|
48
|
-
|
|
49
|
+
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1) => {
|
|
49
50
|
let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param1;
|
|
50
51
|
return Object.entries(compoundVariantOptions).every((param) => {
|
|
51
52
|
let [key, value] = param;
|
|
@@ -61,7 +62,8 @@ const cva = (base, config) => {
|
|
|
61
62
|
cvClass,
|
|
62
63
|
cvClassName
|
|
63
64
|
] : acc;
|
|
64
|
-
}, [])
|
|
65
|
+
}, []);
|
|
66
|
+
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
//#endregion
|
|
@@ -69,8 +71,8 @@ const cva = (base, config) => {
|
|
|
69
71
|
var isCheckBoxInput = (element) => element.type === "checkbox";
|
|
70
72
|
var isDateObject = (value) => value instanceof Date;
|
|
71
73
|
var isNullOrUndefined = (value) => value == null;
|
|
72
|
-
const isObjectType = (value) => typeof value === "object";
|
|
73
|
-
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
|
|
74
|
+
const isObjectType$1 = (value) => typeof value === "object";
|
|
75
|
+
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType$1(value) && !isDateObject(value);
|
|
74
76
|
var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
|
|
75
77
|
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
76
78
|
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
@@ -233,7 +235,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
|
233
235
|
isGlobal && (_names.watchAll = true);
|
|
234
236
|
return formValues;
|
|
235
237
|
};
|
|
236
|
-
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
238
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType$1(value);
|
|
237
239
|
function deepEqual(object1, object2, _internal_visited = /* @__PURE__ */ new WeakSet()) {
|
|
238
240
|
if (isPrimitive(object1) || isPrimitive(object2)) return Object.is(object1, object2);
|
|
239
241
|
if (isDateObject(object1) && isDateObject(object2)) return Object.is(object1.getTime(), object2.getTime());
|
|
@@ -742,9 +744,10 @@ function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
|
|
|
742
744
|
if (!dirtyFieldsFromValues) dirtyFieldsFromValues = markFieldsDirty(formValues);
|
|
743
745
|
for (const key in data) {
|
|
744
746
|
const value = data[key];
|
|
745
|
-
if (isTraversable(value))
|
|
746
|
-
|
|
747
|
-
|
|
747
|
+
if (isTraversable(value)) {
|
|
748
|
+
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) dirtyFieldsFromValues[key] = markFieldsDirty(value, Array.isArray(value) ? [] : {});
|
|
749
|
+
else getDirtyFields(value, isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
750
|
+
} else {
|
|
748
751
|
const formValue = formValues[key];
|
|
749
752
|
dirtyFieldsFromValues[key] = !deepEqual(value, formValue);
|
|
750
753
|
}
|
|
@@ -1264,12 +1267,15 @@ function createFormControl(props = {}) {
|
|
|
1264
1267
|
!fieldReference.disabled && set(_formValues, name, getFieldValueAs(value, fieldReference));
|
|
1265
1268
|
fieldValue = isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ? "" : value;
|
|
1266
1269
|
if (isMultipleSelect(fieldReference.ref)) [...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
|
|
1267
|
-
else if (fieldReference.refs)
|
|
1268
|
-
if (
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1270
|
+
else if (fieldReference.refs) {
|
|
1271
|
+
if (isCheckBoxInput(fieldReference.ref)) fieldReference.refs.forEach((checkboxRef) => {
|
|
1272
|
+
if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
|
|
1273
|
+
if (Array.isArray(fieldValue)) checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
|
|
1274
|
+
else checkboxRef.checked = fieldValue === checkboxRef.value || !!fieldValue;
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
else fieldReference.refs.forEach((radioRef) => radioRef.checked = radioRef.value === fieldValue);
|
|
1278
|
+
} else if (isFileInput(fieldReference.ref)) fieldReference.ref.value = "";
|
|
1273
1279
|
else {
|
|
1274
1280
|
fieldReference.ref.value = fieldValue;
|
|
1275
1281
|
if (!fieldReference.ref.type) _subjects.state.next({
|
|
@@ -1407,7 +1413,7 @@ function createFormControl(props = {}) {
|
|
|
1407
1413
|
const field = get(_fields, fieldName);
|
|
1408
1414
|
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
|
1409
1415
|
}))).every(Boolean);
|
|
1410
|
-
|
|
1416
|
+
(validationResult || _formState.isValid) && _setValid();
|
|
1411
1417
|
} else validationResult = isValid = await executeBuiltInValidation(_fields);
|
|
1412
1418
|
_subjects.state.next({
|
|
1413
1419
|
...!isString(name) || (_proxyFormState.isValid || _proxySubscribeFormState.isValid) && isValid !== _formState.isValid ? {} : { name },
|
|
@@ -1647,7 +1653,7 @@ function createFormControl(props = {}) {
|
|
|
1647
1653
|
if (!keepStateOptions.keepDefaultValues) _defaultValues = updatedValues;
|
|
1648
1654
|
if (!keepStateOptions.keepValues) {
|
|
1649
1655
|
if (keepStateOptions.keepDirtyValues) {
|
|
1650
|
-
const fieldsToCheck = new Set([..._names.mount, ...Object.keys(getDirtyFields(_defaultValues, _formValues))]);
|
|
1656
|
+
const fieldsToCheck = /* @__PURE__ */ new Set([..._names.mount, ...Object.keys(getDirtyFields(_defaultValues, _formValues))]);
|
|
1651
1657
|
for (const fieldName of Array.from(fieldsToCheck)) {
|
|
1652
1658
|
const isDirty = get(_formState.dirtyFields, fieldName);
|
|
1653
1659
|
const existingValue = get(_formValues, fieldName);
|
|
@@ -1854,18 +1860,20 @@ function useForm(props = {}) {
|
|
|
1854
1860
|
isReady: false,
|
|
1855
1861
|
defaultValues: isFunction(props.defaultValues) ? void 0 : props.defaultValues
|
|
1856
1862
|
});
|
|
1857
|
-
if (!_formControl.current)
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1863
|
+
if (!_formControl.current) {
|
|
1864
|
+
if (props.formControl) {
|
|
1865
|
+
_formControl.current = {
|
|
1866
|
+
...props.formControl,
|
|
1867
|
+
formState
|
|
1868
|
+
};
|
|
1869
|
+
if (props.defaultValues && !isFunction(props.defaultValues)) props.formControl.reset(props.defaultValues, props.resetOptions);
|
|
1870
|
+
} else {
|
|
1871
|
+
const { formControl, ...rest } = createFormControl(props);
|
|
1872
|
+
_formControl.current = {
|
|
1873
|
+
...rest,
|
|
1874
|
+
formState
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1869
1877
|
}
|
|
1870
1878
|
const control = _formControl.current.control;
|
|
1871
1879
|
control._options = props;
|
|
@@ -1933,6 +1941,783 @@ function useForm(props = {}) {
|
|
|
1933
1941
|
return _formControl.current;
|
|
1934
1942
|
}
|
|
1935
1943
|
//#endregion
|
|
1944
|
+
//#region ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
|
|
1945
|
+
const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
1946
|
+
const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
1947
|
+
const SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
|
|
1948
|
+
const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
1949
|
+
const SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
1950
|
+
const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
|
|
1951
|
+
/**
|
|
1952
|
+
* Split any cased input strings into an array of words.
|
|
1953
|
+
*/
|
|
1954
|
+
function split(value) {
|
|
1955
|
+
let result = value.trim();
|
|
1956
|
+
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
1957
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
1958
|
+
let start = 0;
|
|
1959
|
+
let end = result.length;
|
|
1960
|
+
while (result.charAt(start) === "\0") start++;
|
|
1961
|
+
if (start === end) return [];
|
|
1962
|
+
while (result.charAt(end - 1) === "\0") end--;
|
|
1963
|
+
return result.slice(start, end).split(/\0/g);
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Split the input string into an array of words, separating numbers.
|
|
1967
|
+
*/
|
|
1968
|
+
function splitSeparateNumbers(value) {
|
|
1969
|
+
const words = split(value);
|
|
1970
|
+
for (let i = 0; i < words.length; i++) {
|
|
1971
|
+
const word = words[i];
|
|
1972
|
+
const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
|
|
1973
|
+
if (match) {
|
|
1974
|
+
const offset = match.index + (match[1] ?? match[2]).length;
|
|
1975
|
+
words.splice(i, 1, word.slice(0, offset), word.slice(offset));
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
return words;
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Convert a string to space separated lower case (`foo bar`).
|
|
1982
|
+
*/
|
|
1983
|
+
function noCase(input, options) {
|
|
1984
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
1985
|
+
return prefix + words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") + suffix;
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Convert a string to pascal case (`FooBar`).
|
|
1989
|
+
*/
|
|
1990
|
+
function pascalCase(input, options) {
|
|
1991
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
1992
|
+
const lower = lowerFactory(options?.locale);
|
|
1993
|
+
const upper = upperFactory(options?.locale);
|
|
1994
|
+
const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
|
|
1995
|
+
return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Convert a string to constant case (`FOO_BAR`).
|
|
1999
|
+
*/
|
|
2000
|
+
function constantCase(input, options) {
|
|
2001
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
2002
|
+
return prefix + words.map(upperFactory(options?.locale)).join(options?.delimiter ?? "_") + suffix;
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Convert a string to path case (`Foo bar`).
|
|
2006
|
+
*/
|
|
2007
|
+
function sentenceCase(input, options) {
|
|
2008
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
2009
|
+
const lower = lowerFactory(options?.locale);
|
|
2010
|
+
const transform = capitalCaseTransformFactory(lower, upperFactory(options?.locale));
|
|
2011
|
+
return prefix + words.map((word, index) => {
|
|
2012
|
+
if (index === 0) return transform(word);
|
|
2013
|
+
return lower(word);
|
|
2014
|
+
}).join(options?.delimiter ?? " ") + suffix;
|
|
2015
|
+
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Convert a string to snake case (`foo_bar`).
|
|
2018
|
+
*/
|
|
2019
|
+
function snakeCase(input, options) {
|
|
2020
|
+
return noCase(input, {
|
|
2021
|
+
delimiter: "_",
|
|
2022
|
+
...options
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
function lowerFactory(locale) {
|
|
2026
|
+
return locale === false ? (input) => input.toLowerCase() : (input) => input.toLocaleLowerCase(locale);
|
|
2027
|
+
}
|
|
2028
|
+
function upperFactory(locale) {
|
|
2029
|
+
return locale === false ? (input) => input.toUpperCase() : (input) => input.toLocaleUpperCase(locale);
|
|
2030
|
+
}
|
|
2031
|
+
function capitalCaseTransformFactory(lower, upper) {
|
|
2032
|
+
return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
|
|
2033
|
+
}
|
|
2034
|
+
function pascalCaseTransformFactory(lower, upper) {
|
|
2035
|
+
return (word, index) => {
|
|
2036
|
+
const char0 = word[0];
|
|
2037
|
+
return (index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0)) + lower(word.slice(1));
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
function splitPrefixSuffix(input, options = {}) {
|
|
2041
|
+
const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
|
|
2042
|
+
const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
2043
|
+
const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
2044
|
+
let prefixIndex = 0;
|
|
2045
|
+
let suffixIndex = input.length;
|
|
2046
|
+
while (prefixIndex < input.length) {
|
|
2047
|
+
const char = input.charAt(prefixIndex);
|
|
2048
|
+
if (!prefixCharacters.includes(char)) break;
|
|
2049
|
+
prefixIndex++;
|
|
2050
|
+
}
|
|
2051
|
+
while (suffixIndex > prefixIndex) {
|
|
2052
|
+
const index = suffixIndex - 1;
|
|
2053
|
+
const char = input.charAt(index);
|
|
2054
|
+
if (!suffixCharacters.includes(char)) break;
|
|
2055
|
+
suffixIndex = index;
|
|
2056
|
+
}
|
|
2057
|
+
return [
|
|
2058
|
+
input.slice(0, prefixIndex),
|
|
2059
|
+
splitFn(input.slice(prefixIndex, suffixIndex)),
|
|
2060
|
+
input.slice(suffixIndex)
|
|
2061
|
+
];
|
|
2062
|
+
}
|
|
2063
|
+
//#endregion
|
|
2064
|
+
//#region editors/document-model-editor/constants/graphql-kinds.ts
|
|
2065
|
+
const STRING_GQL_PRIMITIVE_NAME = "String";
|
|
2066
|
+
const BOOLEAN_GQL_PRIMITIVE_NAME = "Boolean";
|
|
2067
|
+
const FLOAT_GQL_PRIMITIVE_NAME = "Float";
|
|
2068
|
+
const gqlPrimitiveNodeNamesList = [
|
|
2069
|
+
STRING_GQL_PRIMITIVE_NAME,
|
|
2070
|
+
BOOLEAN_GQL_PRIMITIVE_NAME,
|
|
2071
|
+
"Int",
|
|
2072
|
+
FLOAT_GQL_PRIMITIVE_NAME,
|
|
2073
|
+
"ID"
|
|
2074
|
+
];
|
|
2075
|
+
//#endregion
|
|
2076
|
+
//#region editors/document-model-editor/utils/helpers.ts
|
|
2077
|
+
function makeStateSchemaNameForScope(modelName, scope) {
|
|
2078
|
+
const modelNamePascalCase = pascalCase(modelName);
|
|
2079
|
+
const scopePascalCase = pascalCase(scope);
|
|
2080
|
+
return scopePascalCase === "Global" ? `${modelNamePascalCase}State` : `${modelNamePascalCase}${scopePascalCase}State`;
|
|
2081
|
+
}
|
|
2082
|
+
function makeInitialSchemaDoc(modelName, scope) {
|
|
2083
|
+
return `type ${makeStateSchemaNameForScope(modelName, scope)} {
|
|
2084
|
+
"Add your ${scope} state fields here"
|
|
2085
|
+
_placeholder: String
|
|
2086
|
+
}`;
|
|
2087
|
+
}
|
|
2088
|
+
function makeOperationInitialDoc(name) {
|
|
2089
|
+
return `input ${pascalCase(name)}Input {
|
|
2090
|
+
"Add your inputs here"
|
|
2091
|
+
_placeholder: String
|
|
2092
|
+
}`;
|
|
2093
|
+
}
|
|
2094
|
+
function makeEmptyOperationSchema(operationName) {
|
|
2095
|
+
return `input ${pascalCase(operationName)}Input {\n _empty: Boolean\n}`;
|
|
2096
|
+
}
|
|
2097
|
+
function isEmptyOperationSchema(schema) {
|
|
2098
|
+
if (!schema) return false;
|
|
2099
|
+
return /_empty:\s*Boolean/.test(schema) && !schema.replace(/_empty:\s*Boolean/, "").match(/\w+:\s*\w+/);
|
|
2100
|
+
}
|
|
2101
|
+
function safeParseJsonRecord(json) {
|
|
2102
|
+
try {
|
|
2103
|
+
return JSON.parse(json);
|
|
2104
|
+
} catch (_error) {
|
|
2105
|
+
return null;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
function makeMinimalObjectForStateType(args) {
|
|
2109
|
+
const { sharedSchemaDocumentNode, stateTypeDefinitionNode, existingValue } = args;
|
|
2110
|
+
const existingValueObject = safeParseJsonRecord(existingValue);
|
|
2111
|
+
if (!existingValueObject) return existingValue;
|
|
2112
|
+
const stateTypeDefinitionFields = stateTypeDefinitionNode.fields;
|
|
2113
|
+
if (!stateTypeDefinitionFields?.length) return existingValue;
|
|
2114
|
+
const minimalObject = makeMinimalValuesForObjectFields({
|
|
2115
|
+
schemaDocumentNode: sharedSchemaDocumentNode,
|
|
2116
|
+
fieldDefinitionNodes: stateTypeDefinitionFields,
|
|
2117
|
+
existingValueObject,
|
|
2118
|
+
visitedTypes: /* @__PURE__ */ new Set([stateTypeDefinitionNode.name.value])
|
|
2119
|
+
});
|
|
2120
|
+
return JSON.stringify(minimalObject, null, 2);
|
|
2121
|
+
}
|
|
2122
|
+
function makeMinimalValuesForObjectFields(args) {
|
|
2123
|
+
const { schemaDocumentNode, existingValueObject, fieldDefinitionNodes, visitedTypes } = args;
|
|
2124
|
+
const newJson = {};
|
|
2125
|
+
for (const astNode of fieldDefinitionNodes) {
|
|
2126
|
+
const fieldName = getASTNodeName(astNode);
|
|
2127
|
+
if (!fieldName) continue;
|
|
2128
|
+
const minimalValue = makeMinimalValueForASTNode({
|
|
2129
|
+
fieldName,
|
|
2130
|
+
astNode,
|
|
2131
|
+
schemaDocumentNode,
|
|
2132
|
+
existingValueObject,
|
|
2133
|
+
visitedTypes
|
|
2134
|
+
});
|
|
2135
|
+
newJson[astNode.name.value] = minimalValue;
|
|
2136
|
+
}
|
|
2137
|
+
return newJson;
|
|
2138
|
+
}
|
|
2139
|
+
function makeMinimalValueForASTNode(args) {
|
|
2140
|
+
const { fieldName, astNode, schemaDocumentNode, existingValueObject, visitedTypes } = args;
|
|
2141
|
+
const existingFieldValue = existingValueObject?.[fieldName];
|
|
2142
|
+
let node = astNode;
|
|
2143
|
+
if (isFieldDefinitionNode(astNode)) node = getASTNodeTypeNode(node);
|
|
2144
|
+
const isNonNull = isNonNullNode(node);
|
|
2145
|
+
if (isNonNull) node = getASTNodeTypeNode(node);
|
|
2146
|
+
if (isListTypeNode(node)) return makeMinimalValueForGqlListNode(node, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes);
|
|
2147
|
+
if (isGqlPrimitiveNode(node)) return makeMinimalValueForGQLPrimitiveNode(node, existingFieldValue, isNonNull);
|
|
2148
|
+
const namedTypeDefinitionNode = getNamedTypeDefinitionNode(node, schemaDocumentNode);
|
|
2149
|
+
if (isEnumTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull);
|
|
2150
|
+
if (isScalarTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlScalar(namedTypeDefinitionNode, existingFieldValue, isNonNull);
|
|
2151
|
+
if (isUnionTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes);
|
|
2152
|
+
if (isObjectTypeDefinitionNode(namedTypeDefinitionNode)) return makeMinimalValueForGqlObject(namedTypeDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
|
|
2153
|
+
return existingFieldValue;
|
|
2154
|
+
}
|
|
2155
|
+
function isFieldDefinitionNode(astNodeTypeNode) {
|
|
2156
|
+
if (!astNodeTypeNode) return false;
|
|
2157
|
+
return astNodeTypeNode.kind === import_graphql.Kind.FIELD_DEFINITION;
|
|
2158
|
+
}
|
|
2159
|
+
function isNonNullNode(astNode) {
|
|
2160
|
+
if (!astNode) return false;
|
|
2161
|
+
return astNode.kind === import_graphql.Kind.NON_NULL_TYPE;
|
|
2162
|
+
}
|
|
2163
|
+
function isGqlPrimitiveNode(astNodeTypeNode) {
|
|
2164
|
+
if (!astNodeTypeNode) return false;
|
|
2165
|
+
const name = getASTNodeName(astNodeTypeNode);
|
|
2166
|
+
return gqlPrimitiveNodeNamesList.includes(name);
|
|
2167
|
+
}
|
|
2168
|
+
function isListTypeNode(astNodeTypeNode) {
|
|
2169
|
+
if (!astNodeTypeNode) return false;
|
|
2170
|
+
return astNodeTypeNode.kind === import_graphql.Kind.LIST_TYPE;
|
|
2171
|
+
}
|
|
2172
|
+
function isEnumTypeDefinitionNode(definitionNode) {
|
|
2173
|
+
if (!definitionNode) return false;
|
|
2174
|
+
return definitionNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION;
|
|
2175
|
+
}
|
|
2176
|
+
function isScalarTypeDefinitionNode(definitionNode) {
|
|
2177
|
+
if (!definitionNode) return false;
|
|
2178
|
+
return definitionNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION;
|
|
2179
|
+
}
|
|
2180
|
+
function isUnionTypeDefinitionNode(definitionNode) {
|
|
2181
|
+
if (!definitionNode) return false;
|
|
2182
|
+
return definitionNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION;
|
|
2183
|
+
}
|
|
2184
|
+
function isObjectTypeDefinitionNode(definitionNode) {
|
|
2185
|
+
if (!definitionNode) return false;
|
|
2186
|
+
return definitionNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION;
|
|
2187
|
+
}
|
|
2188
|
+
function getASTNodeName(astNode) {
|
|
2189
|
+
if (!astNode) return null;
|
|
2190
|
+
if (!("name" in astNode)) return null;
|
|
2191
|
+
if (!astNode.name) return null;
|
|
2192
|
+
if (!("value" in astNode.name)) return null;
|
|
2193
|
+
return astNode.name.value;
|
|
2194
|
+
}
|
|
2195
|
+
function getASTNodeTypeNode(astNode) {
|
|
2196
|
+
if (!astNode) return null;
|
|
2197
|
+
if (!("type" in astNode)) return null;
|
|
2198
|
+
return astNode.type;
|
|
2199
|
+
}
|
|
2200
|
+
function makeMinimalValueForGQLPrimitiveNode(primitiveTypeNode, existingFieldValue, isNonNull) {
|
|
2201
|
+
const name = getASTNodeName(primitiveTypeNode);
|
|
2202
|
+
if (!name) return null;
|
|
2203
|
+
switch (name) {
|
|
2204
|
+
case "ID":
|
|
2205
|
+
if (z.string().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2206
|
+
return isNonNull ? "placeholder-id" : null;
|
|
2207
|
+
case BOOLEAN_GQL_PRIMITIVE_NAME:
|
|
2208
|
+
if (z.boolean().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2209
|
+
return isNonNull ? false : null;
|
|
2210
|
+
case "Int":
|
|
2211
|
+
if (z.number().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2212
|
+
return isNonNull ? 0 : null;
|
|
2213
|
+
case FLOAT_GQL_PRIMITIVE_NAME:
|
|
2214
|
+
if (z.number().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2215
|
+
return isNonNull ? 0 : null;
|
|
2216
|
+
case STRING_GQL_PRIMITIVE_NAME:
|
|
2217
|
+
if (z.string().safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2218
|
+
return isNonNull ? "" : null;
|
|
2219
|
+
}
|
|
2220
|
+
return isNonNull ? existingFieldValue : null;
|
|
2221
|
+
}
|
|
2222
|
+
function makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull) {
|
|
2223
|
+
const enumValues = namedTypeDefinitionNode.values?.map((value) => value.name.value) ?? [];
|
|
2224
|
+
if (typeof existingFieldValue === "string" && enumValues.includes(existingFieldValue)) return existingFieldValue;
|
|
2225
|
+
if (isNonNull) return enumValues[0];
|
|
2226
|
+
return null;
|
|
2227
|
+
}
|
|
2228
|
+
function makeMinimalValueForGqlScalar(scalarTypeDefinitionNode, existingFieldValue, isNonNull) {
|
|
2229
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
2230
|
+
const name = getASTNodeName(scalarTypeDefinitionNode);
|
|
2231
|
+
if (!name) {
|
|
2232
|
+
console.error("No name for scalar type definition node", scalarTypeDefinitionNode);
|
|
2233
|
+
return null;
|
|
2234
|
+
}
|
|
2235
|
+
const scalar = getPHCustomScalarByTypeName(name);
|
|
2236
|
+
if (!scalar) return null;
|
|
2237
|
+
if (scalar.schema.safeParse(existingFieldValue).success) return existingFieldValue;
|
|
2238
|
+
if (!isNonNull) return null;
|
|
2239
|
+
const minimalValue = scalar.getDefaultValue?.();
|
|
2240
|
+
if (minimalValue) return minimalValue;
|
|
2241
|
+
return existingFieldValue;
|
|
2242
|
+
}
|
|
2243
|
+
function makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes) {
|
|
2244
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
2245
|
+
if (!namedTypeDefinitionNode.types?.length) return null;
|
|
2246
|
+
const firstNamedTypeDefinitionNode = namedTypeDefinitionNode.types?.at(0);
|
|
2247
|
+
if (!firstNamedTypeDefinitionNode) return null;
|
|
2248
|
+
const firstNamedTypeObjectDefinitionNode = getNamedTypeDefinitionNode(firstNamedTypeDefinitionNode, schemaDocumentNode);
|
|
2249
|
+
if (!isObjectTypeDefinitionNode(firstNamedTypeObjectDefinitionNode)) return null;
|
|
2250
|
+
return makeMinimalValueForGqlObject(firstNamedTypeObjectDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
|
|
2251
|
+
}
|
|
2252
|
+
function makeMinimalValueForGqlListNode(listTypeNode, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes) {
|
|
2253
|
+
if (!isNonNull && !Array.isArray(existingFieldValue)) return null;
|
|
2254
|
+
if (isNonNull && !Array.isArray(existingFieldValue)) return [];
|
|
2255
|
+
return existingFieldValue.map((item, index) => makeMinimalValueForASTNode({
|
|
2256
|
+
fieldName: String(index),
|
|
2257
|
+
astNode: listTypeNode.type,
|
|
2258
|
+
schemaDocumentNode,
|
|
2259
|
+
existingValueObject: { [index]: item },
|
|
2260
|
+
visitedTypes
|
|
2261
|
+
}));
|
|
2262
|
+
}
|
|
2263
|
+
function makeMinimalValueForGqlObject(objectTypeDefinitionNode, schemaDocumentNode, _existingValueObject, existingFieldValue, isNonNull, visitedTypes) {
|
|
2264
|
+
const typeName = objectTypeDefinitionNode.name.value;
|
|
2265
|
+
if (visitedTypes?.has(typeName)) return null;
|
|
2266
|
+
if (!isNonNull && !existingFieldValue) return null;
|
|
2267
|
+
const fields = objectTypeDefinitionNode.fields;
|
|
2268
|
+
if (!fields?.length) return {};
|
|
2269
|
+
const newVisitedTypes = new Set(visitedTypes);
|
|
2270
|
+
newVisitedTypes.add(typeName);
|
|
2271
|
+
return makeMinimalValuesForObjectFields({
|
|
2272
|
+
schemaDocumentNode,
|
|
2273
|
+
existingValueObject: existingFieldValue && typeof existingFieldValue === "object" && !Array.isArray(existingFieldValue) ? existingFieldValue : null,
|
|
2274
|
+
fieldDefinitionNodes: fields,
|
|
2275
|
+
visitedTypes: newVisitedTypes
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
function getNamedTypeDefinitionNode(astNodeTypeNode, schemaDocumentNode) {
|
|
2279
|
+
if (!astNodeTypeNode) return null;
|
|
2280
|
+
const name = getASTNodeName(astNodeTypeNode);
|
|
2281
|
+
if (!name) return null;
|
|
2282
|
+
const definitionNode = schemaDocumentNode.definitions.find((def) => "kind" in def && "name" in def && def.name?.value === name);
|
|
2283
|
+
if (!definitionNode) return null;
|
|
2284
|
+
return definitionNode;
|
|
2285
|
+
}
|
|
2286
|
+
function removeWhitespace(str) {
|
|
2287
|
+
return str.replace(/\s+|\\n|\\t/g, "").toLowerCase();
|
|
2288
|
+
}
|
|
2289
|
+
function compareStringsWithoutWhitespace(str1, str2) {
|
|
2290
|
+
if (str1 === null || str2 === null || str1 === void 0 || str2 === void 0) return false;
|
|
2291
|
+
return removeWhitespace(str1) === removeWhitespace(str2);
|
|
2292
|
+
}
|
|
2293
|
+
function renameSchemaType(sdl, oldName, newName, scope) {
|
|
2294
|
+
const typeSuffix = scope === "global" ? "State" : "LocalState";
|
|
2295
|
+
const oldTypeName = `${pascalCase(oldName)}${typeSuffix}`;
|
|
2296
|
+
const newTypeName = `${pascalCase(newName)}${typeSuffix}`;
|
|
2297
|
+
const ast = safeParseSdl(sdl);
|
|
2298
|
+
if (!ast) return sdl;
|
|
2299
|
+
const updatedAst = (0, import_graphql.visit)(ast, { ObjectTypeDefinition: (node) => {
|
|
2300
|
+
if (node.name.value === oldTypeName) return {
|
|
2301
|
+
...node,
|
|
2302
|
+
name: {
|
|
2303
|
+
...node.name,
|
|
2304
|
+
value: newTypeName
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
} });
|
|
2308
|
+
return (0, import_graphql.print)(updatedAst);
|
|
2309
|
+
}
|
|
2310
|
+
function initializeModelSchema(modelName) {
|
|
2311
|
+
return makeInitialSchemaDoc(modelName, "global");
|
|
2312
|
+
}
|
|
2313
|
+
function updateModelSchemaNames(params) {
|
|
2314
|
+
const { oldName, newName, globalStateSchema, localStateSchema, setStateSchema } = params;
|
|
2315
|
+
setStateSchema(renameSchemaType(globalStateSchema, oldName, newName, "global"), "global");
|
|
2316
|
+
if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, oldName, newName, "local"), "local");
|
|
2317
|
+
}
|
|
2318
|
+
function handleModelNameChange(params) {
|
|
2319
|
+
const { newName, globalStateSchema, setStateSchema } = params;
|
|
2320
|
+
if (!!!globalStateSchema) {
|
|
2321
|
+
setStateSchema(initializeModelSchema(newName), "global");
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2324
|
+
updateModelSchemaNames(params);
|
|
2325
|
+
}
|
|
2326
|
+
function validateStateObject(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateValue) {
|
|
2327
|
+
let stateObjectJson;
|
|
2328
|
+
try {
|
|
2329
|
+
stateObjectJson = JSON.parse(stateValue);
|
|
2330
|
+
} catch (error) {
|
|
2331
|
+
return [new Error("Invalid JSON object", { cause: error })];
|
|
2332
|
+
}
|
|
2333
|
+
const typeDefByName = indexTypeDefinitions(sharedSchemaDocumentNode);
|
|
2334
|
+
const stateTypeName = stateTypeDefinitionNode.name.value;
|
|
2335
|
+
if (!typeDefByName.has(stateTypeName)) return [/* @__PURE__ */ new Error(`State type "${stateTypeName}" was not found in sharedSchemaDocumentNode`)];
|
|
2336
|
+
const inputSuffix = "Input";
|
|
2337
|
+
const generatedInputDefs = generateInputTypesForObjectTree(stateTypeName, typeDefByName, inputSuffix);
|
|
2338
|
+
const augmentedDoc = {
|
|
2339
|
+
...sharedSchemaDocumentNode,
|
|
2340
|
+
definitions: [...sharedSchemaDocumentNode.definitions, ...generatedInputDefs]
|
|
2341
|
+
};
|
|
2342
|
+
let schema;
|
|
2343
|
+
try {
|
|
2344
|
+
schema = (0, import_graphql.buildASTSchema)(augmentedDoc, { assumeValidSDL: false });
|
|
2345
|
+
} catch (e) {
|
|
2346
|
+
return [new Error("Failed to build schema from SDL", { cause: e })];
|
|
2347
|
+
}
|
|
2348
|
+
const inputTypeName = `${stateTypeName}${inputSuffix}`;
|
|
2349
|
+
const opDoc = (0, import_graphql.parse)(`query($v: ${inputTypeName}!) { __typename }`);
|
|
2350
|
+
const op = (0, import_graphql.getOperationAST)(opDoc);
|
|
2351
|
+
if (!op) return [/* @__PURE__ */ new Error("Failed to create validation operation AST")];
|
|
2352
|
+
const { errors } = (0, import_graphql.getVariableValues)(schema, op.variableDefinitions ?? [], { v: stateObjectJson });
|
|
2353
|
+
const recursiveTypeErrors = detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName);
|
|
2354
|
+
const recursiveFieldNames = new Set(recursiveTypeErrors.map((e) => e.field));
|
|
2355
|
+
const validationErrors = errors ? graphQLErrorsToStateValidationErrors(errors).filter((e) => {
|
|
2356
|
+
if (e instanceof StateValidationError && e.kind === "NON_NULL") {
|
|
2357
|
+
const rootField = e.path[0];
|
|
2358
|
+
if (typeof rootField === "string" && recursiveFieldNames.has(rootField)) return false;
|
|
2359
|
+
}
|
|
2360
|
+
return true;
|
|
2361
|
+
}) : [];
|
|
2362
|
+
validationErrors.unshift(...recursiveTypeErrors);
|
|
2363
|
+
const missingOptionalErrors = detectMissingOptionalFields(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateObjectJson);
|
|
2364
|
+
validationErrors.push(...missingOptionalErrors);
|
|
2365
|
+
return validationErrors;
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Indexes object/input/enum/scalar/interface/union type definition nodes by name.
|
|
2369
|
+
* Note: only AST definitions that have a "name" field are indexed.
|
|
2370
|
+
*/
|
|
2371
|
+
function indexTypeDefinitions(doc) {
|
|
2372
|
+
const map = /* @__PURE__ */ new Map();
|
|
2373
|
+
for (const def of doc.definitions) if (def.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION || def.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || def.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION || def.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION || def.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION || def.kind === import_graphql.Kind.UNION_TYPE_DEFINITION || def.kind === import_graphql.Kind.OBJECT_TYPE_EXTENSION || def.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION || def.kind === import_graphql.Kind.ENUM_TYPE_EXTENSION || def.kind === import_graphql.Kind.INTERFACE_TYPE_EXTENSION || def.kind === import_graphql.Kind.UNION_TYPE_EXTENSION) {
|
|
2374
|
+
const name = def.name.value;
|
|
2375
|
+
if (!map.has(name)) map.set(name, def);
|
|
2376
|
+
}
|
|
2377
|
+
return map;
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Generates InputObjectTypeDefinitionNode(s) for a root object type and any nested
|
|
2381
|
+
* object types reachable via fields, converting object references to their *Input equivalents*.
|
|
2382
|
+
*/
|
|
2383
|
+
function generateInputTypesForObjectTree(rootObjectTypeName, typeDefByName, inputSuffix) {
|
|
2384
|
+
const generated = /* @__PURE__ */ new Map();
|
|
2385
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2386
|
+
const ensureInputForObject = (objectTypeName) => {
|
|
2387
|
+
const inputName = `${objectTypeName}${inputSuffix}`;
|
|
2388
|
+
if (generated.has(inputName)) return;
|
|
2389
|
+
if (visiting.has(objectTypeName)) return;
|
|
2390
|
+
visiting.add(objectTypeName);
|
|
2391
|
+
const def = typeDefByName.get(objectTypeName);
|
|
2392
|
+
if (!def) throw new import_graphql.GraphQLError(`Unknown referenced type "${objectTypeName}"`);
|
|
2393
|
+
if (def.kind !== import_graphql.Kind.OBJECT_TYPE_DEFINITION && def.kind !== import_graphql.Kind.OBJECT_TYPE_EXTENSION) throw new import_graphql.GraphQLError(`Type "${objectTypeName}" is not an object type; cannot generate input from kind "${def.kind}"`);
|
|
2394
|
+
const objDef = def;
|
|
2395
|
+
const inputFields = objDef.fields?.map((f) => {
|
|
2396
|
+
return {
|
|
2397
|
+
kind: import_graphql.Kind.INPUT_VALUE_DEFINITION,
|
|
2398
|
+
name: f.name,
|
|
2399
|
+
description: f.description,
|
|
2400
|
+
directives: [],
|
|
2401
|
+
type: convertOutputTypeNodeToInputTypeNode(f.type, typeDefByName, inputSuffix, ensureInputForObject),
|
|
2402
|
+
defaultValue: void 0
|
|
2403
|
+
};
|
|
2404
|
+
}) ?? [];
|
|
2405
|
+
const inputDef = {
|
|
2406
|
+
kind: import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
2407
|
+
name: {
|
|
2408
|
+
kind: import_graphql.Kind.NAME,
|
|
2409
|
+
value: inputName
|
|
2410
|
+
},
|
|
2411
|
+
description: objDef.description,
|
|
2412
|
+
directives: [],
|
|
2413
|
+
fields: inputFields
|
|
2414
|
+
};
|
|
2415
|
+
generated.set(inputName, inputDef);
|
|
2416
|
+
visiting.delete(objectTypeName);
|
|
2417
|
+
};
|
|
2418
|
+
ensureInputForObject(rootObjectTypeName);
|
|
2419
|
+
return Array.from(generated.values());
|
|
2420
|
+
}
|
|
2421
|
+
function convertOutputTypeNodeToInputTypeNode(typeNode, typeDefByName, inputSuffix, ensureInputForObject) {
|
|
2422
|
+
switch (typeNode.kind) {
|
|
2423
|
+
case import_graphql.Kind.NON_NULL_TYPE: return {
|
|
2424
|
+
kind: import_graphql.Kind.NON_NULL_TYPE,
|
|
2425
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
2426
|
+
};
|
|
2427
|
+
case import_graphql.Kind.LIST_TYPE: return {
|
|
2428
|
+
kind: import_graphql.Kind.LIST_TYPE,
|
|
2429
|
+
type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject)
|
|
2430
|
+
};
|
|
2431
|
+
case import_graphql.Kind.NAMED_TYPE: {
|
|
2432
|
+
const named = typeNode;
|
|
2433
|
+
const name = named.name.value;
|
|
2434
|
+
const def = typeDefByName.get(name);
|
|
2435
|
+
if (def?.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION || def?.kind === import_graphql.Kind.OBJECT_TYPE_EXTENSION) {
|
|
2436
|
+
ensureInputForObject(name);
|
|
2437
|
+
return {
|
|
2438
|
+
kind: import_graphql.Kind.NAMED_TYPE,
|
|
2439
|
+
name: {
|
|
2440
|
+
kind: import_graphql.Kind.NAME,
|
|
2441
|
+
value: `${name}${inputSuffix}`
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
}
|
|
2445
|
+
if (!def || def.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION || def.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION || def.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || def.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION) return named;
|
|
2446
|
+
if (def.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION || def.kind === import_graphql.Kind.UNION_TYPE_DEFINITION) throw new import_graphql.GraphQLError(`Type "${name}" (${def.kind}) cannot be used in an input type`);
|
|
2447
|
+
throw new import_graphql.GraphQLError(`Unsupported named type "${name}" of kind "${def.kind}"`);
|
|
2448
|
+
}
|
|
2449
|
+
default: throw new import_graphql.GraphQLError(`Unsupported TypeNode kind: ${JSON.stringify(typeNode)}`);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
var StateValidationError = class extends Error {
|
|
2453
|
+
payload;
|
|
2454
|
+
originalMessage;
|
|
2455
|
+
constructor(payload, originalMessage) {
|
|
2456
|
+
super(payload.kind);
|
|
2457
|
+
this.name = "StateValidationError";
|
|
2458
|
+
this.payload = payload;
|
|
2459
|
+
this.originalMessage = originalMessage;
|
|
2460
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
2461
|
+
}
|
|
2462
|
+
get kind() {
|
|
2463
|
+
return this.payload.kind;
|
|
2464
|
+
}
|
|
2465
|
+
get path() {
|
|
2466
|
+
return this.payload.path;
|
|
2467
|
+
}
|
|
2468
|
+
get field() {
|
|
2469
|
+
return this.payload.field;
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
function extractInputPath(message) {
|
|
2473
|
+
const match = message.match(/at\s+"([^"]+)"/);
|
|
2474
|
+
if (!match) return [];
|
|
2475
|
+
const parts = match[1].split(".").filter(Boolean);
|
|
2476
|
+
return (parts[0] === "v" ? parts.slice(1) : parts).map((p) => /^\d+$/.test(p) ? Number(p) : p);
|
|
2477
|
+
}
|
|
2478
|
+
const RE_MISSING_REQUIRED_FIELD = /Field "([^"]+)" of required type "([^"]+)" was not provided\./;
|
|
2479
|
+
const RE_UNKNOWN_FIELD = /Field "([^"]+)" is not defined by type "([^"]+)"\.(?: Did you mean "([^"]+)"\?)?/;
|
|
2480
|
+
function extractMissingRequiredField(message) {
|
|
2481
|
+
const m = message.match(RE_MISSING_REQUIRED_FIELD);
|
|
2482
|
+
if (!m) return null;
|
|
2483
|
+
return {
|
|
2484
|
+
field: m[1],
|
|
2485
|
+
expectedType: m[2]
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
function extractUnknownField(message) {
|
|
2489
|
+
const m = message.match(RE_UNKNOWN_FIELD);
|
|
2490
|
+
if (!m) return null;
|
|
2491
|
+
return {
|
|
2492
|
+
field: m[1],
|
|
2493
|
+
typeName: m[2],
|
|
2494
|
+
didYouMean: m[3]
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
function lastFieldFromPath(path) {
|
|
2498
|
+
for (let i = path.length - 1; i >= 0; i--) if (typeof path[i] === "string") return path[i];
|
|
2499
|
+
}
|
|
2500
|
+
function extractExpectedType(message) {
|
|
2501
|
+
let m = message.match(/Expected non-nullable type "([^"]+)"/);
|
|
2502
|
+
if (m?.[1]) return m[1];
|
|
2503
|
+
m = message.match(/Expected type "([^"]+)"/);
|
|
2504
|
+
if (m?.[1]) return m[1];
|
|
2505
|
+
m = message.match(/;\s*([_A-Za-z][_0-9A-Za-z]*)\s+cannot represent/i);
|
|
2506
|
+
if (m?.[1]) return m[1];
|
|
2507
|
+
}
|
|
2508
|
+
function graphQLErrorsToStateValidationErrors(errors) {
|
|
2509
|
+
const out = [];
|
|
2510
|
+
for (const e of errors) {
|
|
2511
|
+
const originalMessage = e.message;
|
|
2512
|
+
const missing = extractMissingRequiredField(originalMessage);
|
|
2513
|
+
if (missing) {
|
|
2514
|
+
out.push(new StateValidationError({
|
|
2515
|
+
kind: "MISSING",
|
|
2516
|
+
path: [missing.field],
|
|
2517
|
+
field: missing.field,
|
|
2518
|
+
expectedType: missing.expectedType
|
|
2519
|
+
}, originalMessage));
|
|
2520
|
+
continue;
|
|
2521
|
+
}
|
|
2522
|
+
const unknown = extractUnknownField(originalMessage);
|
|
2523
|
+
if (unknown) {
|
|
2524
|
+
out.push(new StateValidationError({
|
|
2525
|
+
kind: "UNKNOWN_FIELD",
|
|
2526
|
+
path: [unknown.field],
|
|
2527
|
+
field: unknown.field,
|
|
2528
|
+
didYouMean: unknown.didYouMean
|
|
2529
|
+
}, originalMessage));
|
|
2530
|
+
continue;
|
|
2531
|
+
}
|
|
2532
|
+
const path = extractInputPath(originalMessage);
|
|
2533
|
+
const field = lastFieldFromPath(path) ?? "value";
|
|
2534
|
+
const expectedType = extractExpectedType(originalMessage);
|
|
2535
|
+
if (originalMessage.includes("Expected non-nullable type") && originalMessage.includes("not to be null")) {
|
|
2536
|
+
out.push(new StateValidationError({
|
|
2537
|
+
kind: "NON_NULL",
|
|
2538
|
+
path,
|
|
2539
|
+
field,
|
|
2540
|
+
expectedType
|
|
2541
|
+
}, originalMessage));
|
|
2542
|
+
continue;
|
|
2543
|
+
}
|
|
2544
|
+
if (originalMessage.includes("cannot represent") || originalMessage.includes("Expected type")) {
|
|
2545
|
+
out.push(new StateValidationError({
|
|
2546
|
+
kind: "TYPE",
|
|
2547
|
+
path,
|
|
2548
|
+
field,
|
|
2549
|
+
expectedType,
|
|
2550
|
+
details: originalMessage
|
|
2551
|
+
}, originalMessage));
|
|
2552
|
+
continue;
|
|
2553
|
+
}
|
|
2554
|
+
out.push(new StateValidationError({
|
|
2555
|
+
kind: "TYPE",
|
|
2556
|
+
path,
|
|
2557
|
+
field,
|
|
2558
|
+
details: originalMessage
|
|
2559
|
+
}, originalMessage));
|
|
2560
|
+
}
|
|
2561
|
+
return out;
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* Finds all fields defined in the schema that are missing from the state object.
|
|
2565
|
+
* Returns information about each missing field including whether it's required.
|
|
2566
|
+
*/
|
|
2567
|
+
function findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value, basePath = []) {
|
|
2568
|
+
let stateObjectJson;
|
|
2569
|
+
try {
|
|
2570
|
+
stateObjectJson = typeof value === "string" ? JSON.parse(value) : value;
|
|
2571
|
+
} catch {
|
|
2572
|
+
return [];
|
|
2573
|
+
}
|
|
2574
|
+
const typeByName = indexObjectTypes(sharedSchemaDocumentNode);
|
|
2575
|
+
const missingFields = [];
|
|
2576
|
+
for (const field of rootTypeNode.fields ?? []) {
|
|
2577
|
+
const fieldName = field.name.value;
|
|
2578
|
+
const fieldPath = [...basePath, fieldName];
|
|
2579
|
+
const isRequired = field.type.kind === import_graphql.Kind.NON_NULL_TYPE;
|
|
2580
|
+
const underlyingType = isRequired ? field.type.type : field.type;
|
|
2581
|
+
if (!(fieldName in stateObjectJson)) {
|
|
2582
|
+
missingFields.push({
|
|
2583
|
+
fieldName,
|
|
2584
|
+
path: fieldPath,
|
|
2585
|
+
isRequired,
|
|
2586
|
+
type: underlyingType
|
|
2587
|
+
});
|
|
2588
|
+
continue;
|
|
2589
|
+
}
|
|
2590
|
+
const namedType = unwrapNamedType(field.type);
|
|
2591
|
+
const childType = namedType ? typeByName.get(namedType) : void 0;
|
|
2592
|
+
if (childType && typeof stateObjectJson[fieldName] === "object" && stateObjectJson[fieldName] !== null && !Array.isArray(stateObjectJson[fieldName])) {
|
|
2593
|
+
const nestedMissing = findMissingFields(sharedSchemaDocumentNode, childType, stateObjectJson[fieldName], fieldPath);
|
|
2594
|
+
missingFields.push(...nestedMissing);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
return missingFields;
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* Detects optional fields defined in the schema that are missing from the state object.
|
|
2601
|
+
* Returns StateValidationError[] for each missing optional field.
|
|
2602
|
+
*/
|
|
2603
|
+
function detectMissingOptionalFields(sharedSchemaDocumentNode, rootTypeNode, value) {
|
|
2604
|
+
return findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value).filter((field) => !field.isRequired).map((field) => new StateValidationError({
|
|
2605
|
+
kind: "MISSING_OPTIONAL",
|
|
2606
|
+
path: field.path,
|
|
2607
|
+
field: field.fieldName,
|
|
2608
|
+
expectedType: typeNodeToString(field.type)
|
|
2609
|
+
}));
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Detects fields that have recursive types (types that reference themselves directly or indirectly).
|
|
2613
|
+
* Returns a RECURSIVE_TYPE error for each field that contains a recursive type.
|
|
2614
|
+
*/
|
|
2615
|
+
function detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName) {
|
|
2616
|
+
const errors = [];
|
|
2617
|
+
for (const field of stateTypeDefinitionNode.fields ?? []) {
|
|
2618
|
+
const fieldName = field.name.value;
|
|
2619
|
+
const namedTypeName = getNamedTypeName(field.type);
|
|
2620
|
+
if (!namedTypeName) continue;
|
|
2621
|
+
if (isRecursiveType(namedTypeName, typeDefByName, /* @__PURE__ */ new Set())) errors.push(new StateValidationError({
|
|
2622
|
+
kind: "RECURSIVE_TYPE",
|
|
2623
|
+
path: [fieldName],
|
|
2624
|
+
field: fieldName,
|
|
2625
|
+
typeName: namedTypeName
|
|
2626
|
+
}));
|
|
2627
|
+
}
|
|
2628
|
+
return errors;
|
|
2629
|
+
}
|
|
2630
|
+
/**
|
|
2631
|
+
* Gets the named type name from a TypeNode, unwrapping NonNull and List types.
|
|
2632
|
+
*/
|
|
2633
|
+
function getNamedTypeName(typeNode) {
|
|
2634
|
+
if (typeNode.kind === import_graphql.Kind.NAMED_TYPE) return typeNode.name.value;
|
|
2635
|
+
if (typeNode.kind === import_graphql.Kind.NON_NULL_TYPE || typeNode.kind === import_graphql.Kind.LIST_TYPE) return getNamedTypeName(typeNode.type);
|
|
2636
|
+
return null;
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* Checks if a type is recursive (references itself directly or indirectly through required fields).
|
|
2640
|
+
*/
|
|
2641
|
+
function isRecursiveType(typeName, typeDefByName, visitedTypes) {
|
|
2642
|
+
if (visitedTypes.has(typeName)) return true;
|
|
2643
|
+
const typeDef = typeDefByName.get(typeName);
|
|
2644
|
+
if (!typeDef || typeDef.kind !== import_graphql.Kind.OBJECT_TYPE_DEFINITION) return false;
|
|
2645
|
+
visitedTypes.add(typeName);
|
|
2646
|
+
for (const field of typeDef.fields ?? []) {
|
|
2647
|
+
if (field.type.kind !== import_graphql.Kind.NON_NULL_TYPE) continue;
|
|
2648
|
+
const innerType = field.type.type;
|
|
2649
|
+
let fieldTypeName = null;
|
|
2650
|
+
if (innerType.kind === import_graphql.Kind.NAMED_TYPE) fieldTypeName = innerType.name.value;
|
|
2651
|
+
else if (innerType.kind === import_graphql.Kind.LIST_TYPE) fieldTypeName = getNamedTypeName(innerType);
|
|
2652
|
+
if (fieldTypeName && isRecursiveType(fieldTypeName, typeDefByName, visitedTypes)) return true;
|
|
2653
|
+
}
|
|
2654
|
+
visitedTypes.delete(typeName);
|
|
2655
|
+
return false;
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Converts a TypeNode to its string representation (e.g., "String", "Int!", "[String]!")
|
|
2659
|
+
*/
|
|
2660
|
+
function typeNodeToString(typeNode) {
|
|
2661
|
+
switch (typeNode.kind) {
|
|
2662
|
+
case import_graphql.Kind.NAMED_TYPE: return typeNode.name.value;
|
|
2663
|
+
case import_graphql.Kind.NON_NULL_TYPE: return `${typeNodeToString(typeNode.type)}!`;
|
|
2664
|
+
case import_graphql.Kind.LIST_TYPE: return `[${typeNodeToString(typeNode.type)}]`;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
function indexObjectTypes(doc) {
|
|
2668
|
+
const map = /* @__PURE__ */ new Map();
|
|
2669
|
+
for (const def of doc.definitions) if (def.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) map.set(def.name.value, def);
|
|
2670
|
+
return map;
|
|
2671
|
+
}
|
|
2672
|
+
function unwrapNamedType(typeNode) {
|
|
2673
|
+
if (typeNode.kind === import_graphql.Kind.NAMED_TYPE) return typeNode.name.value;
|
|
2674
|
+
if (typeNode.kind === import_graphql.Kind.NON_NULL_TYPE) return unwrapNamedType(typeNode.type);
|
|
2675
|
+
if (typeNode.kind === import_graphql.Kind.LIST_TYPE) return unwrapNamedType(typeNode.type);
|
|
2676
|
+
}
|
|
2677
|
+
//#endregion
|
|
2678
|
+
//#region editors/document-model-editor/utils/linting.ts
|
|
2679
|
+
function ensureDocumentContainsNodeWithNameAndType(doc, nodeName, nodeType) {
|
|
2680
|
+
const parsedDoc = safeParseSdl(doc);
|
|
2681
|
+
if (!parsedDoc) return true;
|
|
2682
|
+
return parsedDoc.definitions.some((def) => {
|
|
2683
|
+
return def.kind === import_graphql.Kind[nodeType] && "name" in def && def.name?.value === nodeName;
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
function createNodeTypeAndNameDiagnostic(doc, errorMessage) {
|
|
2687
|
+
const parsedDoc = safeParseSdl(doc);
|
|
2688
|
+
if (!parsedDoc) return void 0;
|
|
2689
|
+
const firstNode = parsedDoc.definitions[0];
|
|
2690
|
+
const nameNode = "name" in firstNode ? firstNode.name : null;
|
|
2691
|
+
return {
|
|
2692
|
+
from: nameNode?.loc?.start ?? firstNode.loc?.start ?? 0,
|
|
2693
|
+
to: nameNode?.loc?.end ?? firstNode.loc?.end ?? 0,
|
|
2694
|
+
severity: "error",
|
|
2695
|
+
message: errorMessage
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
function ensureValidStateSchemaName(doc, modelName, scope) {
|
|
2699
|
+
if (!safeParseSdl(doc)) return [];
|
|
2700
|
+
const requiredTypeName = makeStateSchemaNameForScope(modelName, scope);
|
|
2701
|
+
if (!ensureDocumentContainsNodeWithNameAndType(doc, requiredTypeName, "OBJECT_TYPE_DEFINITION")) return [createNodeTypeAndNameDiagnostic(doc, `${sentenceCase(scope)} state schema must be named ${requiredTypeName}`)].filter((d) => d !== void 0);
|
|
2702
|
+
return [];
|
|
2703
|
+
}
|
|
2704
|
+
function ensureValidOperationSchemaInputName(doc, operationName) {
|
|
2705
|
+
if (!doc || !safeParseSdl(doc)) return [];
|
|
2706
|
+
const requiredTypeName = `${pascalCase(operationName)}Input`;
|
|
2707
|
+
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);
|
|
2708
|
+
return [];
|
|
2709
|
+
}
|
|
2710
|
+
//#endregion
|
|
2711
|
+
//#region editors/document-model-editor/components/button.tsx
|
|
2712
|
+
const Button = forwardRef((props, ref) => {
|
|
2713
|
+
const { className, ...rest } = props;
|
|
2714
|
+
return /* @__PURE__ */ jsx("button", {
|
|
2715
|
+
ref,
|
|
2716
|
+
...rest,
|
|
2717
|
+
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)
|
|
2718
|
+
});
|
|
2719
|
+
});
|
|
2720
|
+
//#endregion
|
|
1936
2721
|
//#region editors/document-model-editor/components/divider.tsx
|
|
1937
2722
|
function Divider({ className, size = "sm", margin = "md" }) {
|
|
1938
2723
|
function getSize() {
|
|
@@ -1945,7 +2730,9 @@ function Divider({ className, size = "sm", margin = "md" }) {
|
|
|
1945
2730
|
if (margin === "md") return "my-6";
|
|
1946
2731
|
return "my-8";
|
|
1947
2732
|
}
|
|
1948
|
-
|
|
2733
|
+
const sizeClass = getSize();
|
|
2734
|
+
const marginClass = getMargin();
|
|
2735
|
+
return /* @__PURE__ */ jsx("div", { className: twMerge("bg-secondary", sizeClass, marginClass, className) });
|
|
1949
2736
|
}
|
|
1950
2737
|
//#endregion
|
|
1951
2738
|
//#region ../../node_modules/.pnpm/@hookform+resolvers@5.2.2_react-hook-form@7.71.2_react@19.2.6_/node_modules/@hookform/resolvers/dist/resolvers.mjs
|
|
@@ -1954,12 +2741,14 @@ const r = (t, r, o) => {
|
|
|
1954
2741
|
const s = get(o, r);
|
|
1955
2742
|
t.setCustomValidity(s && s.message || ""), t.reportValidity();
|
|
1956
2743
|
}
|
|
1957
|
-
}
|
|
2744
|
+
};
|
|
2745
|
+
const o = (e, t) => {
|
|
1958
2746
|
for (const o in t.fields) {
|
|
1959
2747
|
const s = t.fields[o];
|
|
1960
2748
|
s && s.ref && "reportValidity" in s.ref ? r(s.ref, o, e) : s && s.refs && s.refs.forEach((t) => r(t, o, e));
|
|
1961
2749
|
}
|
|
1962
|
-
}
|
|
2750
|
+
};
|
|
2751
|
+
const s$1 = (r, s) => {
|
|
1963
2752
|
s.shouldUseNativeValidation && o(r, s);
|
|
1964
2753
|
const n = {};
|
|
1965
2754
|
for (const o in r) {
|
|
@@ -1970,7 +2759,8 @@ const r = (t, r, o) => {
|
|
|
1970
2759
|
} else set(n, o, c);
|
|
1971
2760
|
}
|
|
1972
2761
|
return n;
|
|
1973
|
-
}
|
|
2762
|
+
};
|
|
2763
|
+
const i$1 = (e, t) => {
|
|
1974
2764
|
const r = n$1(t);
|
|
1975
2765
|
return e.some((e) => n$1(e).match(`^${r}\\.\\d+`));
|
|
1976
2766
|
};
|
|
@@ -2401,32 +3191,38 @@ function ModelMetadata(props) {
|
|
|
2401
3191
|
}
|
|
2402
3192
|
function ModelNameForm(props) {
|
|
2403
3193
|
const { name, globalStateSchema, localStateSchema, setModelName, setStateSchema } = props;
|
|
3194
|
+
const onSubmit = useCallback((newName) => {
|
|
3195
|
+
if (name === newName) return;
|
|
3196
|
+
setModelName(newName);
|
|
3197
|
+
if (!!!globalStateSchema) {
|
|
3198
|
+
const initialSchemaDoc = makeInitialSchemaDoc(newName, "global");
|
|
3199
|
+
setStateSchema(initialSchemaDoc, "global");
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
const newSchema = renameSchemaType(globalStateSchema, name, newName, "global");
|
|
3203
|
+
setStateSchema(newSchema, "global");
|
|
3204
|
+
if (localStateSchema) {
|
|
3205
|
+
const newLocalStateSchema = renameSchemaType(localStateSchema, name, newName, "local");
|
|
3206
|
+
setStateSchema(newLocalStateSchema, "local");
|
|
3207
|
+
}
|
|
3208
|
+
handleModelNameChange({
|
|
3209
|
+
oldName: name,
|
|
3210
|
+
newName,
|
|
3211
|
+
globalStateSchema,
|
|
3212
|
+
localStateSchema,
|
|
3213
|
+
setStateSchema
|
|
3214
|
+
});
|
|
3215
|
+
}, [
|
|
3216
|
+
name,
|
|
3217
|
+
globalStateSchema,
|
|
3218
|
+
localStateSchema,
|
|
3219
|
+
setStateSchema,
|
|
3220
|
+
setModelName
|
|
3221
|
+
]);
|
|
2404
3222
|
return /* @__PURE__ */ jsx(TextField, {
|
|
2405
3223
|
name: "name",
|
|
2406
3224
|
value: name,
|
|
2407
|
-
onSubmit
|
|
2408
|
-
if (name === newName) return;
|
|
2409
|
-
setModelName(newName);
|
|
2410
|
-
if (!!!globalStateSchema) {
|
|
2411
|
-
setStateSchema(makeInitialSchemaDoc(newName, "global"), "global");
|
|
2412
|
-
return;
|
|
2413
|
-
}
|
|
2414
|
-
setStateSchema(renameSchemaType(globalStateSchema, name, newName, "global"), "global");
|
|
2415
|
-
if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, name, newName, "local"), "local");
|
|
2416
|
-
handleModelNameChange({
|
|
2417
|
-
oldName: name,
|
|
2418
|
-
newName,
|
|
2419
|
-
globalStateSchema,
|
|
2420
|
-
localStateSchema,
|
|
2421
|
-
setStateSchema
|
|
2422
|
-
});
|
|
2423
|
-
}, [
|
|
2424
|
-
name,
|
|
2425
|
-
globalStateSchema,
|
|
2426
|
-
localStateSchema,
|
|
2427
|
-
setStateSchema,
|
|
2428
|
-
setModelName
|
|
2429
|
-
]),
|
|
3225
|
+
onSubmit,
|
|
2430
3226
|
placeholder: "Model name",
|
|
2431
3227
|
className: "border-none pl-0 text-xl font-bold text-foreground",
|
|
2432
3228
|
required: true,
|
|
@@ -2627,7 +3423,7 @@ function OperationErrors({ operation, addOperationError, deleteOperationError, s
|
|
|
2627
3423
|
}
|
|
2628
3424
|
//#endregion
|
|
2629
3425
|
//#region editors/document-model-editor/components/operation.tsx
|
|
2630
|
-
const GraphqlEditor = lazy(() => import("./graphql-editor-
|
|
3426
|
+
const GraphqlEditor = lazy(() => import("./graphql-editor-CBJXEY_C.mjs"));
|
|
2631
3427
|
function Operation(props) {
|
|
2632
3428
|
const { operation, module, allOperationNames, lastCreatedOperationId, onAddOperationAndInitialSchema, updateOperationName, deleteOperation, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired } = props;
|
|
2633
3429
|
const noInputRequired = isEmptyOperationSchema(operation.schema);
|
|
@@ -3069,7 +3865,6 @@ function useSelectedDocumentModelDocument() {
|
|
|
3069
3865
|
}
|
|
3070
3866
|
//#endregion
|
|
3071
3867
|
//#region editors/document-model-editor/utils/change-classification.ts
|
|
3072
|
-
var import_graphql = require_graphql();
|
|
3073
3868
|
function isShapeTypeNode(node) {
|
|
3074
3869
|
return node.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION || node.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION;
|
|
3075
3870
|
}
|
|
@@ -3364,7 +4159,8 @@ function useVersionAdvisory(args) {
|
|
|
3364
4159
|
}
|
|
3365
4160
|
//#endregion
|
|
3366
4161
|
//#region editors/document-model-editor/editor.tsx
|
|
3367
|
-
|
|
4162
|
+
var editor_exports = /* @__PURE__ */ __exportAll({ default: () => Editor });
|
|
4163
|
+
const StateSchemas = lazy(() => import("./state-schemas-CWuLjYFF.mjs"));
|
|
3368
4164
|
const noopSetStateSchema = () => void 0;
|
|
3369
4165
|
const noopSetInitialState = () => void 0;
|
|
3370
4166
|
function Editor() {
|
|
@@ -3388,10 +4184,11 @@ function Editor() {
|
|
|
3388
4184
|
useEffect(() => {
|
|
3389
4185
|
if (!shouldSetInitialName.current || !documentNodeName) return;
|
|
3390
4186
|
const initialSchemaDoc = initializeModelSchema(documentNodeName);
|
|
3391
|
-
|
|
4187
|
+
const actions = [setModelName({ name: documentNodeName }), setStateSchema({
|
|
3392
4188
|
schema: initialSchemaDoc,
|
|
3393
4189
|
scope: "global"
|
|
3394
|
-
})]
|
|
4190
|
+
})];
|
|
4191
|
+
dispatch(actions);
|
|
3395
4192
|
shouldSetInitialName.current = false;
|
|
3396
4193
|
}, [documentNodeName, dispatch]);
|
|
3397
4194
|
const { guardedDispatch, prompt, releaseFirst, keepEditing, cancelAdvisory, markVersionInDevelopment } = useVersionAdvisory({
|
|
@@ -3542,11 +4339,12 @@ function Editor() {
|
|
|
3542
4339
|
return;
|
|
3543
4340
|
}
|
|
3544
4341
|
const id = generateId();
|
|
4342
|
+
const errorCode = pascalCase(errorName);
|
|
3545
4343
|
guardedDispatch(addOperationError({
|
|
3546
4344
|
id,
|
|
3547
4345
|
operationId,
|
|
3548
4346
|
errorName,
|
|
3549
|
-
errorCode
|
|
4347
|
+
errorCode
|
|
3550
4348
|
}));
|
|
3551
4349
|
resolve(id);
|
|
3552
4350
|
} catch (error) {
|
|
@@ -3674,6 +4472,6 @@ function Editor() {
|
|
|
3674
4472
|
});
|
|
3675
4473
|
}
|
|
3676
4474
|
//#endregion
|
|
3677
|
-
export { Editor as default };
|
|
4475
|
+
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 };
|
|
3678
4476
|
|
|
3679
|
-
//# sourceMappingURL=editor-
|
|
4477
|
+
//# sourceMappingURL=editor-CeSEXEgf.mjs.map
|