@yimoka/designable-playground 0.0.0-stage → 0.1.1
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/README.md +8 -2
- package/dist/demo/components/Alert/index.d.ts +4 -0
- package/dist/demo/components/Alert/index.js +41 -0
- package/dist/demo/components/ArrayCards/index.d.ts +17 -0
- package/dist/demo/components/ArrayCards/index.js +62 -0
- package/dist/demo/components/ArrayList/index.d.ts +25 -0
- package/dist/demo/components/ArrayList/index.js +143 -0
- package/dist/demo/components/ArrayTable/index.d.ts +39 -0
- package/dist/demo/components/ArrayTable/index.js +247 -0
- package/dist/demo/components/AutoComplete/index.d.ts +4 -0
- package/dist/demo/components/AutoComplete/index.js +52 -0
- package/dist/demo/components/Avatar/index.d.ts +4 -0
- package/dist/demo/components/Avatar/index.js +34 -0
- package/dist/demo/components/Badge/index.d.ts +4 -0
- package/dist/demo/components/Badge/index.js +35 -0
- package/dist/demo/components/Button/index.d.ts +4 -0
- package/dist/demo/components/Button/index.js +86 -0
- package/dist/demo/components/Card/index.d.ts +4 -0
- package/dist/demo/components/Card/index.js +72 -0
- package/dist/demo/components/Carousel/index.d.ts +4 -0
- package/dist/demo/components/Carousel/index.js +33 -0
- package/dist/demo/components/Cascader/index.d.ts +4 -0
- package/dist/demo/components/Cascader/index.js +60 -0
- package/dist/demo/components/Checkbox/index.d.ts +8 -0
- package/dist/demo/components/Checkbox/index.js +55 -0
- package/dist/demo/components/ColorPicker/index.d.ts +4 -0
- package/dist/demo/components/ColorPicker/index.js +38 -0
- package/dist/demo/components/DatePicker/index.d.ts +4 -0
- package/dist/demo/components/DatePicker/index.js +61 -0
- package/dist/demo/components/DateRangePicker/index.d.ts +4 -0
- package/dist/demo/components/DateRangePicker/index.js +58 -0
- package/dist/demo/components/Divider/index.d.ts +4 -0
- package/dist/demo/components/Divider/index.js +39 -0
- package/dist/demo/components/Empty/index.d.ts +4 -0
- package/dist/demo/components/Empty/index.js +29 -0
- package/dist/demo/components/Flex/index.d.ts +4 -0
- package/dist/demo/components/Flex/index.js +51 -0
- package/dist/demo/components/Form/index.d.ts +21 -0
- package/dist/demo/components/Form/index.js +116 -0
- package/dist/demo/components/FormCollapse/index.d.ts +28 -0
- package/dist/demo/components/FormCollapse/index.js +164 -0
- package/dist/demo/components/FormGrid/index.d.ts +22 -0
- package/dist/demo/components/FormGrid/index.js +134 -0
- package/dist/demo/components/FormItem/index.d.ts +14 -0
- package/dist/demo/components/FormItem/index.js +33 -0
- package/dist/demo/components/FormLayout/index.d.ts +26 -0
- package/dist/demo/components/FormLayout/index.js +260 -0
- package/dist/demo/components/FormTab/index.d.ts +15 -0
- package/dist/demo/components/FormTab/index.js +186 -0
- package/dist/demo/components/GridCol/index.d.ts +4 -0
- package/dist/demo/components/GridCol/index.js +53 -0
- package/dist/demo/components/GridRow/index.d.ts +4 -0
- package/dist/demo/components/GridRow/index.js +70 -0
- package/dist/demo/components/HTMLContent/index.d.ts +4 -0
- package/dist/demo/components/HTMLContent/index.js +34 -0
- package/dist/demo/components/I18nEditor/index.d.ts +8 -0
- package/dist/demo/components/I18nEditor/index.js +64 -0
- package/dist/demo/components/Image/index.d.ts +4 -0
- package/dist/demo/components/Image/index.js +36 -0
- package/dist/demo/components/Input/index.d.ts +4 -0
- package/dist/demo/components/Input/index.js +36 -0
- package/dist/demo/components/InputSearch/index.d.ts +4 -0
- package/dist/demo/components/InputSearch/index.js +40 -0
- package/dist/demo/components/Link/index.d.ts +4 -0
- package/dist/demo/components/Link/index.js +37 -0
- package/dist/demo/components/Mentions/index.d.ts +4 -0
- package/dist/demo/components/Mentions/index.js +41 -0
- package/dist/demo/components/NumberPicker/index.d.ts +6 -0
- package/dist/demo/components/NumberPicker/index.js +63 -0
- package/dist/demo/components/ObjectContainer/index.d.ts +14 -0
- package/dist/demo/components/ObjectContainer/index.js +46 -0
- package/dist/demo/components/Password/index.d.ts +6 -0
- package/dist/demo/components/Password/index.js +44 -0
- package/dist/demo/components/QRCode/index.d.ts +4 -0
- package/dist/demo/components/QRCode/index.js +34 -0
- package/dist/demo/components/Radio/index.d.ts +6 -0
- package/dist/demo/components/Radio/index.js +49 -0
- package/dist/demo/components/Rate/index.d.ts +6 -0
- package/dist/demo/components/Rate/index.js +43 -0
- package/dist/demo/components/Search/index.d.ts +4 -0
- package/dist/demo/components/Search/index.js +42 -0
- package/dist/demo/components/SearchSelect/index.d.ts +4 -0
- package/dist/demo/components/SearchSelect/index.js +53 -0
- package/dist/demo/components/Select/index.d.ts +4 -0
- package/dist/demo/components/Select/index.js +59 -0
- package/dist/demo/components/Slider/index.d.ts +6 -0
- package/dist/demo/components/Slider/index.js +61 -0
- package/dist/demo/components/Space/index.d.ts +9 -0
- package/dist/demo/components/Space/index.js +61 -0
- package/dist/demo/components/Statistic/index.d.ts +4 -0
- package/dist/demo/components/Statistic/index.js +33 -0
- package/dist/demo/components/Switch/index.d.ts +4 -0
- package/dist/demo/components/Switch/index.js +49 -0
- package/dist/demo/components/Tabs/index.d.ts +10 -0
- package/dist/demo/components/Tabs/index.js +181 -0
- package/dist/demo/components/Tag/index.d.ts +4 -0
- package/dist/demo/components/Tag/index.js +33 -0
- package/dist/demo/components/Text/index.d.ts +11 -0
- package/dist/demo/components/Text/index.js +64 -0
- package/dist/demo/components/TextArea/index.d.ts +6 -0
- package/dist/demo/components/TextArea/index.js +43 -0
- package/dist/demo/components/TimePicker/index.d.ts +4 -0
- package/dist/demo/components/TimePicker/index.js +69 -0
- package/dist/demo/components/TimeRangePicker/index.d.ts +4 -0
- package/dist/demo/components/TimeRangePicker/index.js +68 -0
- package/dist/demo/components/Transfer/index.d.ts +6 -0
- package/dist/demo/components/Transfer/index.js +59 -0
- package/dist/demo/components/TreeSelect/index.d.ts +4 -0
- package/dist/demo/components/TreeSelect/index.js +63 -0
- package/dist/demo/components/Upload/index.d.ts +8 -0
- package/dist/demo/components/Upload/index.js +64 -0
- package/dist/demo/components/index.d.ts +55 -0
- package/dist/demo/components/index.js +55 -0
- package/dist/demo/components/shared.d.ts +143 -0
- package/dist/demo/components/shared.js +315 -0
- package/dist/src/Playground.d.ts +3 -0
- package/dist/src/Playground.js +304 -0
- package/dist/src/antd/AntdPlayground.d.ts +16 -0
- package/dist/src/antd/AntdPlayground.js +136 -0
- package/dist/src/antd/index.d.ts +1 -0
- package/dist/src/antd/index.js +1 -0
- package/dist/src/context.d.ts +4 -0
- package/dist/src/context.js +13 -0
- package/dist/src/examples/index.d.ts +267 -0
- package/dist/src/examples/index.js +824 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/remoteSchemaAdapter.d.ts +53 -0
- package/dist/src/hooks/remoteSchemaAdapter.js +262 -0
- package/dist/src/hooks/usePlayground.d.ts +38 -0
- package/dist/src/hooks/usePlayground.js +642 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.d.ts +135 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.js +736 -0
- package/dist/src/hooks/useSchemaEditorDraft.d.ts +4 -0
- package/dist/src/hooks/useSchemaEditorDraft.js +44 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +14 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.d.ts +59 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.js +161 -0
- package/dist/src/layouts/PlaygroundLayout/index.d.ts +7 -0
- package/dist/src/layouts/PlaygroundLayout/index.js +443 -0
- package/dist/src/layouts/index.d.ts +1 -0
- package/dist/src/layouts/index.js +1 -0
- package/dist/src/panels/CompositePanel/index.d.ts +6 -0
- package/dist/src/panels/CompositePanel/index.js +139 -0
- package/dist/src/panels/ToolbarPanel/index.d.ts +3 -0
- package/dist/src/panels/ToolbarPanel/index.js +24 -0
- package/dist/src/panels/index.d.ts +2 -0
- package/dist/src/panels/index.js +2 -0
- package/dist/src/presets/antd.d.ts +19 -0
- package/dist/src/presets/antd.js +112 -0
- package/dist/src/presets/index.d.ts +4 -0
- package/dist/src/presets/index.js +3 -0
- package/dist/src/presets/runtime-array-helpers.d.ts +8 -0
- package/dist/src/presets/runtime-array-helpers.js +147 -0
- package/dist/src/presets/runtime-component-props.d.ts +3 -0
- package/dist/src/presets/runtime-component-props.js +5 -0
- package/dist/src/presets/runtime-components.d.ts +5 -0
- package/dist/src/presets/runtime-components.js +419 -0
- package/dist/src/presets/runtime-form-components.d.ts +9 -0
- package/dist/src/presets/runtime-form-components.js +94 -0
- package/dist/src/presets/scenario-catalog.d.ts +6 -0
- package/dist/src/presets/scenario-catalog.js +128 -0
- package/dist/src/presets/scenarios.d.ts +52 -0
- package/dist/src/presets/scenarios.js +603 -0
- package/dist/src/runtime/actions.d.ts +19 -0
- package/dist/src/runtime/actions.js +307 -0
- package/dist/src/runtime/contracts.d.ts +149 -0
- package/dist/src/runtime/contracts.js +1 -0
- package/dist/src/runtime/document-bindings.d.ts +3 -0
- package/dist/src/runtime/document-bindings.js +101 -0
- package/dist/src/runtime/document-core.d.ts +57 -0
- package/dist/src/runtime/document-core.js +379 -0
- package/dist/src/runtime/document-entity.d.ts +12 -0
- package/dist/src/runtime/document-entity.js +351 -0
- package/dist/src/runtime/document-expressions.d.ts +35 -0
- package/dist/src/runtime/document-expressions.js +346 -0
- package/dist/src/runtime/document-security.d.ts +34 -0
- package/dist/src/runtime/document-security.js +538 -0
- package/dist/src/runtime/document.d.ts +16 -0
- package/dist/src/runtime/document.js +212 -0
- package/dist/src/runtime/environment.d.ts +16 -0
- package/dist/src/runtime/environment.js +76 -0
- package/dist/src/runtime/i18n-schema.d.ts +36 -0
- package/dist/src/runtime/i18n-schema.js +338 -0
- package/dist/src/runtime/i18n.d.ts +25 -0
- package/dist/src/runtime/i18n.js +447 -0
- package/dist/src/runtime/index.d.ts +8 -0
- package/dist/src/runtime/index.js +8 -0
- package/dist/src/runtime/navigation.d.ts +5 -0
- package/dist/src/runtime/navigation.js +43 -0
- package/dist/src/runtime/playground.d.ts +30 -0
- package/dist/src/runtime/playground.js +243 -0
- package/dist/src/runtime/preview-boundaries.d.ts +13 -0
- package/dist/src/runtime/preview-boundaries.js +43 -0
- package/dist/src/runtime/preview.d.ts +44 -0
- package/dist/src/runtime/preview.js +574 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.d.ts +10 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.js +21 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.d.ts +15 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.js +65 -0
- package/dist/src/runtime/templates.d.ts +1560 -0
- package/dist/src/runtime/templates.js +508 -0
- package/dist/src/runtime/website-contact-template.d.ts +1 -0
- package/dist/src/runtime/website-contact-template.js +66 -0
- package/dist/src/runtime/website-template-shared.d.ts +14 -0
- package/dist/src/runtime/website-template-shared.js +210 -0
- package/dist/src/runtime/website-templates.d.ts +5 -0
- package/dist/src/runtime/website-templates.js +976 -0
- package/dist/src/shared/clipboard.d.ts +4 -0
- package/dist/src/shared/clipboard.js +56 -0
- package/dist/src/shared/componentRegistry.d.ts +133 -0
- package/dist/src/shared/componentRegistry.js +381 -0
- package/dist/src/shared/formilyCompatibility.d.ts +8 -0
- package/dist/src/shared/formilyCompatibility.js +40 -0
- package/dist/src/shared/index.d.ts +6 -0
- package/dist/src/shared/index.js +6 -0
- package/dist/src/shared/productionAcceptance.d.ts +63 -0
- package/dist/src/shared/productionAcceptance.js +201 -0
- package/dist/src/shared/schema-options.d.ts +16 -0
- package/dist/src/shared/schema-options.js +138 -0
- package/dist/src/shared/schema.d.ts +63 -0
- package/dist/src/shared/schema.js +627 -0
- package/dist/src/shared/styleSecurity.d.ts +2 -0
- package/dist/src/shared/styleSecurity.js +35 -0
- package/dist/src/transformers/formily.d.ts +34 -0
- package/dist/src/transformers/formily.js +943 -0
- package/dist/src/transformers/index.d.ts +1 -0
- package/dist/src/transformers/index.js +1 -0
- package/dist/src/types.d.ts +186 -0
- package/dist/src/types.js +1 -0
- package/dist/src/widgets/ActionsWidget/index.d.ts +3 -0
- package/dist/src/widgets/ActionsWidget/index.js +10 -0
- package/dist/src/widgets/ComponentTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/ComponentTreeWidget/index.js +333 -0
- package/dist/src/widgets/NodeActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/NodeActionsWidget/index.js +125 -0
- package/dist/src/widgets/OutlineTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/OutlineTreeWidget/index.js +432 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.d.ts +32 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.js +79 -0
- package/dist/src/widgets/PreviewWidget/index.d.ts +2 -0
- package/dist/src/widgets/PreviewWidget/index.js +1566 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.d.ts +18 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.js +356 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.d.ts +18 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.js +438 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.d.ts +39 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.js +475 -0
- package/dist/src/widgets/ResourceWidget/index.d.ts +3 -0
- package/dist/src/widgets/ResourceWidget/index.js +491 -0
- package/dist/src/widgets/SchemaCodeView/index.d.ts +7 -0
- package/dist/src/widgets/SchemaCodeView/index.js +225 -0
- package/dist/src/widgets/SchemaEditorWidget/index.d.ts +10 -0
- package/dist/src/widgets/SchemaEditorWidget/index.js +484 -0
- package/dist/src/widgets/SettingsPanelWidget/index.d.ts +3 -0
- package/dist/src/widgets/SettingsPanelWidget/index.js +190 -0
- package/dist/src/widgets/StorageActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/StorageActionsWidget/index.js +284 -0
- package/dist/src/widgets/index.d.ts +13 -0
- package/dist/src/widgets/index.js +13 -0
- package/package.json +100 -4
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { UNSAFE_SCHEMA_OBJECT_KEYS } from "../shared/schema.js";
|
|
2
|
+
export const RUNTIME_DOCUMENT_KIND = 'yimoka.designable.runtime-document';
|
|
3
|
+
export const RUNTIME_DOCUMENT_VERSION = 1;
|
|
4
|
+
export const RUNTIME_SCHEMA_FIDELITY_PROP = '$runtimeSchemaFidelityV1';
|
|
5
|
+
export const RUNTIME_DOCUMENT_KEYS = new Set([
|
|
6
|
+
'entityConfig',
|
|
7
|
+
'kind',
|
|
8
|
+
'metadata',
|
|
9
|
+
'schema',
|
|
10
|
+
'scope',
|
|
11
|
+
'store',
|
|
12
|
+
'version',
|
|
13
|
+
]);
|
|
14
|
+
export const RUNTIME_DOCUMENT_SIDECAR_KEYS = new Set([
|
|
15
|
+
'entityConfig',
|
|
16
|
+
'metadata',
|
|
17
|
+
'scope',
|
|
18
|
+
'store',
|
|
19
|
+
]);
|
|
20
|
+
export const RUNTIME_SCOPE_RESERVED_KEYS = new Set([
|
|
21
|
+
'$biz',
|
|
22
|
+
'$config',
|
|
23
|
+
'$entity',
|
|
24
|
+
'$root',
|
|
25
|
+
'$store',
|
|
26
|
+
'components',
|
|
27
|
+
]);
|
|
28
|
+
export const RUNTIME_STORE_KEYS = new Set([
|
|
29
|
+
'api',
|
|
30
|
+
'defaultValues',
|
|
31
|
+
'dictConfig',
|
|
32
|
+
'extInfo',
|
|
33
|
+
'fieldsConfig',
|
|
34
|
+
'options',
|
|
35
|
+
'type',
|
|
36
|
+
]);
|
|
37
|
+
export const RUNTIME_DICT_KEYS = new Set([
|
|
38
|
+
'api',
|
|
39
|
+
'byField',
|
|
40
|
+
'childrenKey',
|
|
41
|
+
'data',
|
|
42
|
+
'field',
|
|
43
|
+
'keys',
|
|
44
|
+
'paramKeys',
|
|
45
|
+
'toMap',
|
|
46
|
+
'toOptions',
|
|
47
|
+
'type',
|
|
48
|
+
]);
|
|
49
|
+
export const RUNTIME_ENTITY_KEYS = new Set([
|
|
50
|
+
'api',
|
|
51
|
+
'basePath',
|
|
52
|
+
'breadcrumb',
|
|
53
|
+
'defaultDetailValues',
|
|
54
|
+
'defaultFormValues',
|
|
55
|
+
'defaultQueryValues',
|
|
56
|
+
'dictConfig',
|
|
57
|
+
'extensions',
|
|
58
|
+
'fieldsConfig',
|
|
59
|
+
'idKey',
|
|
60
|
+
'idsKey',
|
|
61
|
+
'i18nFieldMap',
|
|
62
|
+
'i18nInSchema',
|
|
63
|
+
'i18nLangAPI',
|
|
64
|
+
'i18nOutSchema',
|
|
65
|
+
'labelKey',
|
|
66
|
+
'map',
|
|
67
|
+
'name',
|
|
68
|
+
'options',
|
|
69
|
+
'path',
|
|
70
|
+
]);
|
|
71
|
+
export const RUNTIME_REQUEST_KEYS = new Set([
|
|
72
|
+
'data',
|
|
73
|
+
'method',
|
|
74
|
+
'params',
|
|
75
|
+
'url',
|
|
76
|
+
]);
|
|
77
|
+
export const RUNTIME_METADATA_KEYS = new Set([
|
|
78
|
+
'extensions',
|
|
79
|
+
'scenarioId',
|
|
80
|
+
'template',
|
|
81
|
+
]);
|
|
82
|
+
export const RUNTIME_TEMPLATE_REFERENCE_KEYS = new Set([
|
|
83
|
+
'id',
|
|
84
|
+
'version',
|
|
85
|
+
]);
|
|
86
|
+
export const DATA_BINDING_MANUAL_KEYS = {
|
|
87
|
+
Cascader: ['options', 'data'],
|
|
88
|
+
Checkbox: ['options', 'data'],
|
|
89
|
+
Mentions: ['options', 'data'],
|
|
90
|
+
Radio: ['options', 'data'],
|
|
91
|
+
SearchSelect: ['options', 'data'],
|
|
92
|
+
Select: ['options', 'data'],
|
|
93
|
+
Transfer: ['dataSource', 'data'],
|
|
94
|
+
TreeSelect: ['treeData', 'data'],
|
|
95
|
+
};
|
|
96
|
+
export const RUNTIME_OPTION_SCHEMA_KEYS = ['enum', 'oneOf', 'x-enum'];
|
|
97
|
+
export const RUNTIME_UPLOAD_NETWORK_KEYS = new Set([
|
|
98
|
+
'action',
|
|
99
|
+
'customRequest',
|
|
100
|
+
'headers',
|
|
101
|
+
'method',
|
|
102
|
+
'withCredentials',
|
|
103
|
+
]);
|
|
104
|
+
export const RUNTIME_SEARCH_REQUEST_PROP_KEYS = {
|
|
105
|
+
Search: ['api'],
|
|
106
|
+
SearchSelect: ['api', 'labelAPI'],
|
|
107
|
+
};
|
|
108
|
+
export const RUNTIME_NAVIGATION_PROP_KEYS = {
|
|
109
|
+
Button: ['href', 'ping'],
|
|
110
|
+
Link: ['href', 'to', 'ping'],
|
|
111
|
+
};
|
|
112
|
+
export class RuntimeDocumentValidationError extends Error {
|
|
113
|
+
code;
|
|
114
|
+
issues;
|
|
115
|
+
constructor(issues) {
|
|
116
|
+
super(issues.map(issue => `${issue.path}: ${issue.message}`).join(';'));
|
|
117
|
+
this.name = 'RuntimeDocumentValidationError';
|
|
118
|
+
this.code = issues[0]?.code ?? 'invalid-runtime-document';
|
|
119
|
+
this.issues = issues;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export const isObjectRecord = (value) => (typeof value === 'object'
|
|
123
|
+
&& value !== null
|
|
124
|
+
&& !Array.isArray(value));
|
|
125
|
+
export const pushRuntimeIssue = (issues, code, path, message) => {
|
|
126
|
+
const resolvedCode = code === 'runtime-unsafe-key'
|
|
127
|
+
&& path.includes('.entityConfig.i18nFieldMap.')
|
|
128
|
+
? 'invalid-i18n-field-map'
|
|
129
|
+
: code;
|
|
130
|
+
issues.push({
|
|
131
|
+
code: resolvedCode,
|
|
132
|
+
message,
|
|
133
|
+
path,
|
|
134
|
+
severity: 'error',
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
export const cloneRuntimeJsonValue = (value, path, issues, ancestors) => {
|
|
138
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') {
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
if (typeof value === 'number') {
|
|
142
|
+
if (Number.isFinite(value))
|
|
143
|
+
return value;
|
|
144
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, '数字必须是有限值');
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
if (typeof value !== 'object') {
|
|
148
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, `不支持持久化 ${typeof value} 值`);
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
if (ancestors.has(value)) {
|
|
152
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, 'Runtime 文档不能包含循环引用');
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
if (Array.isArray(value)) {
|
|
156
|
+
ancestors.add(value);
|
|
157
|
+
const cloned = [];
|
|
158
|
+
const arrayIndexKeys = new Set();
|
|
159
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
160
|
+
const key = String(index);
|
|
161
|
+
const nextPath = `${path}[${index}]`;
|
|
162
|
+
arrayIndexKeys.add(key);
|
|
163
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
164
|
+
if (!descriptor?.enumerable || !('value' in descriptor)) {
|
|
165
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', nextPath, 'Runtime 数组只允许连续、可枚举的数据项');
|
|
166
|
+
cloned.push(null);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
cloned.push(cloneRuntimeJsonValue(descriptor.value, nextPath, issues, ancestors) ?? null);
|
|
170
|
+
}
|
|
171
|
+
Reflect.ownKeys(value).forEach((key) => {
|
|
172
|
+
if (key === 'length' || (typeof key === 'string' && arrayIndexKeys.has(key)))
|
|
173
|
+
return;
|
|
174
|
+
if (typeof key !== 'string') {
|
|
175
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, 'Runtime 数组不能包含 Symbol 键');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const nextPath = `${path}.${key}`;
|
|
179
|
+
if (UNSAFE_SCHEMA_OBJECT_KEYS.has(key)) {
|
|
180
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-key', nextPath, `Runtime 文档包含危险对象键 ${key}`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', nextPath, 'Runtime 数组不能包含会被 JSON 忽略的附加属性');
|
|
184
|
+
});
|
|
185
|
+
ancestors.delete(value);
|
|
186
|
+
return cloned;
|
|
187
|
+
}
|
|
188
|
+
const prototype = Object.getPrototypeOf(value);
|
|
189
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
190
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, 'Runtime 文档只允许普通 JSON 对象,不能包含 Date 或 class instance');
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
ancestors.add(value);
|
|
194
|
+
const cloned = {};
|
|
195
|
+
Reflect.ownKeys(value).forEach((key) => {
|
|
196
|
+
if (typeof key !== 'string') {
|
|
197
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', path, 'Runtime 对象不能包含 Symbol 键');
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const nextPath = `${path}.${key}`;
|
|
201
|
+
if (UNSAFE_SCHEMA_OBJECT_KEYS.has(key)) {
|
|
202
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-key', nextPath, `Runtime 文档包含危险对象键 ${key}`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
206
|
+
if (!descriptor?.enumerable || !('value' in descriptor)) {
|
|
207
|
+
pushRuntimeIssue(issues, 'runtime-non-json-value', nextPath, 'Runtime 对象只允许可枚举的数据属性');
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const clonedValue = cloneRuntimeJsonValue(descriptor.value, nextPath, issues, ancestors);
|
|
211
|
+
if (clonedValue !== undefined) {
|
|
212
|
+
cloned[key] = clonedValue;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
ancestors.delete(value);
|
|
216
|
+
return cloned;
|
|
217
|
+
};
|
|
218
|
+
export const validateAllowedKeys = (value, allowedKeys, issues, path, code) => {
|
|
219
|
+
Object.keys(value).forEach((key) => {
|
|
220
|
+
if (!allowedKeys.has(key)) {
|
|
221
|
+
pushRuntimeIssue(issues, code, `${path}.${key}`, `字段 ${key} 不在 Runtime v1 allowlist 中`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
export const RUNTIME_EXPRESSION_PATTERN = /^\s*\{\{([\s\S]*)\}\}\s*$/;
|
|
226
|
+
export const validateRuntimeRequestExpressionFreeValue = (value, issues, path) => {
|
|
227
|
+
if (typeof value === 'string') {
|
|
228
|
+
if (RUNTIME_EXPRESSION_PATTERN.test(value)) {
|
|
229
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', path, 'Runtime 持久化请求配置不允许使用数据表达式');
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (Array.isArray(value)) {
|
|
234
|
+
value.forEach((item, index) => {
|
|
235
|
+
validateRuntimeRequestExpressionFreeValue(item, issues, `${path}[${index}]`);
|
|
236
|
+
});
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!isObjectRecord(value))
|
|
240
|
+
return;
|
|
241
|
+
Object.entries(value).forEach(([key, child]) => {
|
|
242
|
+
validateRuntimeRequestExpressionFreeValue(child, issues, `${path}.${key}`);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
export const validateRuntimeRequestConfig = (value, issues, path) => {
|
|
246
|
+
if (!isObjectRecord(value)) {
|
|
247
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', path, '请求配置必须是对象');
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
validateAllowedKeys(value, RUNTIME_REQUEST_KEYS, issues, path, 'runtime-unsafe-request-config');
|
|
251
|
+
validateRuntimeRequestExpressionFreeValue(value, issues, path);
|
|
252
|
+
if (typeof value.url !== 'string'
|
|
253
|
+
|| !value.url.trim()
|
|
254
|
+
|| value.url.trim() !== value.url) {
|
|
255
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', `${path}.url`, '请求配置 url 必须是非空且不含首尾空白的字符串');
|
|
256
|
+
}
|
|
257
|
+
if (value.method !== undefined
|
|
258
|
+
&& (typeof value.method !== 'string'
|
|
259
|
+
|| !value.method.trim()
|
|
260
|
+
|| value.method.trim() !== value.method)) {
|
|
261
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', `${path}.method`, '请求配置 method 必须是非空且不含首尾空白的字符串');
|
|
262
|
+
}
|
|
263
|
+
['params', 'data'].forEach((propertyName) => {
|
|
264
|
+
if (value[propertyName] !== undefined
|
|
265
|
+
&& !isObjectRecord(value[propertyName])) {
|
|
266
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', `${path}.${propertyName}`, `请求配置 ${propertyName} 必须是 JSON 对象`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
export const validateRuntimeDictMode = (value, issues, path) => {
|
|
271
|
+
if (value.type !== undefined && value.type !== 'self' && value.type !== 'by') {
|
|
272
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.type`, 'dictConfig.type 只允许 self 或 by');
|
|
273
|
+
}
|
|
274
|
+
const byFields = Array.isArray(value.byField) ? value.byField : [value.byField];
|
|
275
|
+
const hasInvalidByField = value.byField !== undefined
|
|
276
|
+
&& (!byFields.length
|
|
277
|
+
|| byFields.some(item => (typeof item !== 'string'
|
|
278
|
+
|| !item.trim()
|
|
279
|
+
|| item.trim() !== item)));
|
|
280
|
+
if (hasInvalidByField || (value.type === 'by' && value.byField === undefined)) {
|
|
281
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.byField`, value.type === 'by'
|
|
282
|
+
? 'by 模式必须提供非空 byField'
|
|
283
|
+
: 'byField 必须是非空字符串或非空字符串数组');
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
export const validateRuntimeDictOptions = (value, issues, path) => {
|
|
287
|
+
if (value.toMap !== undefined && typeof value.toMap !== 'boolean') {
|
|
288
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.toMap`, 'toMap 必须是布尔值');
|
|
289
|
+
}
|
|
290
|
+
if (value.toOptions !== undefined && typeof value.toOptions !== 'boolean') {
|
|
291
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.toOptions`, 'toOptions 必须是布尔值');
|
|
292
|
+
}
|
|
293
|
+
const validateStringMapping = (mapping, mappingPath) => {
|
|
294
|
+
Object.entries(mapping).forEach(([key, item]) => {
|
|
295
|
+
if (!key.trim()
|
|
296
|
+
|| key.trim() !== key
|
|
297
|
+
|| UNSAFE_SCHEMA_OBJECT_KEYS.has(key)
|
|
298
|
+
|| typeof item !== 'string'
|
|
299
|
+
|| !item.trim()
|
|
300
|
+
|| item.trim() !== item) {
|
|
301
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${mappingPath}.${key}`, '字段映射的键和值必须是不含首尾空白的安全非空字符串');
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
if (value.keys !== undefined) {
|
|
306
|
+
if (!isObjectRecord(value.keys)) {
|
|
307
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.keys`, 'keys 必须是对象');
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
validateStringMapping(value.keys, `${path}.keys`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (value.paramKeys !== undefined
|
|
314
|
+
&& typeof value.paramKeys !== 'string'
|
|
315
|
+
&& !isObjectRecord(value.paramKeys)) {
|
|
316
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.paramKeys`, 'paramKeys 必须是字符串或对象');
|
|
317
|
+
}
|
|
318
|
+
else if (typeof value.paramKeys === 'string') {
|
|
319
|
+
if (!value.paramKeys.trim() || value.paramKeys.trim() !== value.paramKeys) {
|
|
320
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.paramKeys`, 'paramKeys 字符串必须是不含首尾空白的非空值');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (isObjectRecord(value.paramKeys)) {
|
|
324
|
+
validateStringMapping(value.paramKeys, `${path}.paramKeys`);
|
|
325
|
+
}
|
|
326
|
+
if (value.childrenKey !== undefined && typeof value.childrenKey !== 'string') {
|
|
327
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.childrenKey`, 'childrenKey 必须是字符串');
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
export const validateRuntimeDictConfig = (value, issues, path) => {
|
|
331
|
+
if (!isObjectRecord(value)) {
|
|
332
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', path, 'dictConfig 条目必须是对象');
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
validateAllowedKeys(value, RUNTIME_DICT_KEYS, issues, path, 'invalid-runtime-document');
|
|
336
|
+
if (typeof value.field !== 'string'
|
|
337
|
+
|| !value.field.trim()
|
|
338
|
+
|| value.field.trim() !== value.field) {
|
|
339
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.field`, 'dictConfig.field 必须是不含首尾空白的非空字符串');
|
|
340
|
+
}
|
|
341
|
+
validateRuntimeDictMode(value, issues, path);
|
|
342
|
+
validateRuntimeDictOptions(value, issues, path);
|
|
343
|
+
if (value.api !== undefined) {
|
|
344
|
+
validateRuntimeRequestConfig(value.api, issues, `${path}.api`);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
export const validateRuntimeStoreConfig = (value, issues, path) => {
|
|
348
|
+
if (!isObjectRecord(value)) {
|
|
349
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', path, 'store 必须是对象');
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
validateAllowedKeys(value, RUNTIME_STORE_KEYS, issues, path, 'invalid-runtime-document');
|
|
353
|
+
if (value.type !== undefined && value.type !== 'base' && value.type !== 'list') {
|
|
354
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.type`, 'store.type 只允许 base 或 list');
|
|
355
|
+
}
|
|
356
|
+
[
|
|
357
|
+
'defaultValues',
|
|
358
|
+
'extInfo',
|
|
359
|
+
'fieldsConfig',
|
|
360
|
+
'options',
|
|
361
|
+
].forEach((key) => {
|
|
362
|
+
if (value[key] !== undefined && !isObjectRecord(value[key])) {
|
|
363
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.${key}`, `store.${key} 必须是对象`);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
if (value.dictConfig !== undefined) {
|
|
367
|
+
if (!Array.isArray(value.dictConfig)) {
|
|
368
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.dictConfig`, 'store.dictConfig 必须是数组');
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
value.dictConfig.forEach((item, index) => {
|
|
372
|
+
validateRuntimeDictConfig(item, issues, `${path}.dictConfig[${index}]`);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (value.api !== undefined) {
|
|
377
|
+
validateRuntimeRequestConfig(value.api, issues, `${path}.api`);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IFormilySchemaDocument } from "../transformers/index.js";
|
|
2
|
+
import type { IRuntimeSchemaFidelityV1, IRuntimeDocumentValidationIssue } from "./document-core.js";
|
|
3
|
+
export declare const validateRuntimeSchemaRoot: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string, schemaRoot?: unknown) => void;
|
|
4
|
+
export declare const validateRuntimeSchemaNode: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string, schemaRoot?: unknown) => void;
|
|
5
|
+
export declare const validateRuntimeEntityConfig: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
6
|
+
export declare const validateRuntimeMetadata: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
7
|
+
export declare const validateRuntimeDataBindings: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string, schemaRoot?: unknown) => void;
|
|
8
|
+
export declare const createRuntimeEntitySchemaRoot: (schema: unknown, entityConfig: unknown, storeConfig: unknown) => unknown;
|
|
9
|
+
export declare const validateRuntimeFieldsConfigDataBindings: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string, schemaRoot?: unknown) => void;
|
|
10
|
+
export declare const validateRuntimeI18nDataBindings: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
11
|
+
export declare const createRuntimeSchemaFidelity: (original: unknown, normalized: unknown) => IRuntimeSchemaFidelityV1;
|
|
12
|
+
export declare const restoreRuntimeSchemaFidelity: (schema: IFormilySchemaDocument, fidelity: unknown) => IFormilySchemaDocument;
|