@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.
Files changed (262) hide show
  1. package/README.md +8 -2
  2. package/dist/demo/components/Alert/index.d.ts +4 -0
  3. package/dist/demo/components/Alert/index.js +41 -0
  4. package/dist/demo/components/ArrayCards/index.d.ts +17 -0
  5. package/dist/demo/components/ArrayCards/index.js +62 -0
  6. package/dist/demo/components/ArrayList/index.d.ts +25 -0
  7. package/dist/demo/components/ArrayList/index.js +143 -0
  8. package/dist/demo/components/ArrayTable/index.d.ts +39 -0
  9. package/dist/demo/components/ArrayTable/index.js +247 -0
  10. package/dist/demo/components/AutoComplete/index.d.ts +4 -0
  11. package/dist/demo/components/AutoComplete/index.js +52 -0
  12. package/dist/demo/components/Avatar/index.d.ts +4 -0
  13. package/dist/demo/components/Avatar/index.js +34 -0
  14. package/dist/demo/components/Badge/index.d.ts +4 -0
  15. package/dist/demo/components/Badge/index.js +35 -0
  16. package/dist/demo/components/Button/index.d.ts +4 -0
  17. package/dist/demo/components/Button/index.js +86 -0
  18. package/dist/demo/components/Card/index.d.ts +4 -0
  19. package/dist/demo/components/Card/index.js +72 -0
  20. package/dist/demo/components/Carousel/index.d.ts +4 -0
  21. package/dist/demo/components/Carousel/index.js +33 -0
  22. package/dist/demo/components/Cascader/index.d.ts +4 -0
  23. package/dist/demo/components/Cascader/index.js +60 -0
  24. package/dist/demo/components/Checkbox/index.d.ts +8 -0
  25. package/dist/demo/components/Checkbox/index.js +55 -0
  26. package/dist/demo/components/ColorPicker/index.d.ts +4 -0
  27. package/dist/demo/components/ColorPicker/index.js +38 -0
  28. package/dist/demo/components/DatePicker/index.d.ts +4 -0
  29. package/dist/demo/components/DatePicker/index.js +61 -0
  30. package/dist/demo/components/DateRangePicker/index.d.ts +4 -0
  31. package/dist/demo/components/DateRangePicker/index.js +58 -0
  32. package/dist/demo/components/Divider/index.d.ts +4 -0
  33. package/dist/demo/components/Divider/index.js +39 -0
  34. package/dist/demo/components/Empty/index.d.ts +4 -0
  35. package/dist/demo/components/Empty/index.js +29 -0
  36. package/dist/demo/components/Flex/index.d.ts +4 -0
  37. package/dist/demo/components/Flex/index.js +51 -0
  38. package/dist/demo/components/Form/index.d.ts +21 -0
  39. package/dist/demo/components/Form/index.js +116 -0
  40. package/dist/demo/components/FormCollapse/index.d.ts +28 -0
  41. package/dist/demo/components/FormCollapse/index.js +164 -0
  42. package/dist/demo/components/FormGrid/index.d.ts +22 -0
  43. package/dist/demo/components/FormGrid/index.js +134 -0
  44. package/dist/demo/components/FormItem/index.d.ts +14 -0
  45. package/dist/demo/components/FormItem/index.js +33 -0
  46. package/dist/demo/components/FormLayout/index.d.ts +26 -0
  47. package/dist/demo/components/FormLayout/index.js +260 -0
  48. package/dist/demo/components/FormTab/index.d.ts +15 -0
  49. package/dist/demo/components/FormTab/index.js +186 -0
  50. package/dist/demo/components/GridCol/index.d.ts +4 -0
  51. package/dist/demo/components/GridCol/index.js +53 -0
  52. package/dist/demo/components/GridRow/index.d.ts +4 -0
  53. package/dist/demo/components/GridRow/index.js +70 -0
  54. package/dist/demo/components/HTMLContent/index.d.ts +4 -0
  55. package/dist/demo/components/HTMLContent/index.js +34 -0
  56. package/dist/demo/components/I18nEditor/index.d.ts +8 -0
  57. package/dist/demo/components/I18nEditor/index.js +64 -0
  58. package/dist/demo/components/Image/index.d.ts +4 -0
  59. package/dist/demo/components/Image/index.js +36 -0
  60. package/dist/demo/components/Input/index.d.ts +4 -0
  61. package/dist/demo/components/Input/index.js +36 -0
  62. package/dist/demo/components/InputSearch/index.d.ts +4 -0
  63. package/dist/demo/components/InputSearch/index.js +40 -0
  64. package/dist/demo/components/Link/index.d.ts +4 -0
  65. package/dist/demo/components/Link/index.js +37 -0
  66. package/dist/demo/components/Mentions/index.d.ts +4 -0
  67. package/dist/demo/components/Mentions/index.js +41 -0
  68. package/dist/demo/components/NumberPicker/index.d.ts +6 -0
  69. package/dist/demo/components/NumberPicker/index.js +63 -0
  70. package/dist/demo/components/ObjectContainer/index.d.ts +14 -0
  71. package/dist/demo/components/ObjectContainer/index.js +46 -0
  72. package/dist/demo/components/Password/index.d.ts +6 -0
  73. package/dist/demo/components/Password/index.js +44 -0
  74. package/dist/demo/components/QRCode/index.d.ts +4 -0
  75. package/dist/demo/components/QRCode/index.js +34 -0
  76. package/dist/demo/components/Radio/index.d.ts +6 -0
  77. package/dist/demo/components/Radio/index.js +49 -0
  78. package/dist/demo/components/Rate/index.d.ts +6 -0
  79. package/dist/demo/components/Rate/index.js +43 -0
  80. package/dist/demo/components/Search/index.d.ts +4 -0
  81. package/dist/demo/components/Search/index.js +42 -0
  82. package/dist/demo/components/SearchSelect/index.d.ts +4 -0
  83. package/dist/demo/components/SearchSelect/index.js +53 -0
  84. package/dist/demo/components/Select/index.d.ts +4 -0
  85. package/dist/demo/components/Select/index.js +59 -0
  86. package/dist/demo/components/Slider/index.d.ts +6 -0
  87. package/dist/demo/components/Slider/index.js +61 -0
  88. package/dist/demo/components/Space/index.d.ts +9 -0
  89. package/dist/demo/components/Space/index.js +61 -0
  90. package/dist/demo/components/Statistic/index.d.ts +4 -0
  91. package/dist/demo/components/Statistic/index.js +33 -0
  92. package/dist/demo/components/Switch/index.d.ts +4 -0
  93. package/dist/demo/components/Switch/index.js +49 -0
  94. package/dist/demo/components/Tabs/index.d.ts +10 -0
  95. package/dist/demo/components/Tabs/index.js +181 -0
  96. package/dist/demo/components/Tag/index.d.ts +4 -0
  97. package/dist/demo/components/Tag/index.js +33 -0
  98. package/dist/demo/components/Text/index.d.ts +11 -0
  99. package/dist/demo/components/Text/index.js +64 -0
  100. package/dist/demo/components/TextArea/index.d.ts +6 -0
  101. package/dist/demo/components/TextArea/index.js +43 -0
  102. package/dist/demo/components/TimePicker/index.d.ts +4 -0
  103. package/dist/demo/components/TimePicker/index.js +69 -0
  104. package/dist/demo/components/TimeRangePicker/index.d.ts +4 -0
  105. package/dist/demo/components/TimeRangePicker/index.js +68 -0
  106. package/dist/demo/components/Transfer/index.d.ts +6 -0
  107. package/dist/demo/components/Transfer/index.js +59 -0
  108. package/dist/demo/components/TreeSelect/index.d.ts +4 -0
  109. package/dist/demo/components/TreeSelect/index.js +63 -0
  110. package/dist/demo/components/Upload/index.d.ts +8 -0
  111. package/dist/demo/components/Upload/index.js +64 -0
  112. package/dist/demo/components/index.d.ts +55 -0
  113. package/dist/demo/components/index.js +55 -0
  114. package/dist/demo/components/shared.d.ts +143 -0
  115. package/dist/demo/components/shared.js +315 -0
  116. package/dist/src/Playground.d.ts +3 -0
  117. package/dist/src/Playground.js +304 -0
  118. package/dist/src/antd/AntdPlayground.d.ts +16 -0
  119. package/dist/src/antd/AntdPlayground.js +136 -0
  120. package/dist/src/antd/index.d.ts +1 -0
  121. package/dist/src/antd/index.js +1 -0
  122. package/dist/src/context.d.ts +4 -0
  123. package/dist/src/context.js +13 -0
  124. package/dist/src/examples/index.d.ts +267 -0
  125. package/dist/src/examples/index.js +824 -0
  126. package/dist/src/hooks/index.d.ts +4 -0
  127. package/dist/src/hooks/index.js +4 -0
  128. package/dist/src/hooks/remoteSchemaAdapter.d.ts +53 -0
  129. package/dist/src/hooks/remoteSchemaAdapter.js +262 -0
  130. package/dist/src/hooks/usePlayground.d.ts +38 -0
  131. package/dist/src/hooks/usePlayground.js +642 -0
  132. package/dist/src/hooks/usePlaygroundRemotePersistence.d.ts +135 -0
  133. package/dist/src/hooks/usePlaygroundRemotePersistence.js +736 -0
  134. package/dist/src/hooks/useSchemaEditorDraft.d.ts +4 -0
  135. package/dist/src/hooks/useSchemaEditorDraft.js +44 -0
  136. package/dist/src/index.d.ts +14 -0
  137. package/dist/src/index.js +14 -0
  138. package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.d.ts +59 -0
  139. package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.js +161 -0
  140. package/dist/src/layouts/PlaygroundLayout/index.d.ts +7 -0
  141. package/dist/src/layouts/PlaygroundLayout/index.js +443 -0
  142. package/dist/src/layouts/index.d.ts +1 -0
  143. package/dist/src/layouts/index.js +1 -0
  144. package/dist/src/panels/CompositePanel/index.d.ts +6 -0
  145. package/dist/src/panels/CompositePanel/index.js +139 -0
  146. package/dist/src/panels/ToolbarPanel/index.d.ts +3 -0
  147. package/dist/src/panels/ToolbarPanel/index.js +24 -0
  148. package/dist/src/panels/index.d.ts +2 -0
  149. package/dist/src/panels/index.js +2 -0
  150. package/dist/src/presets/antd.d.ts +19 -0
  151. package/dist/src/presets/antd.js +112 -0
  152. package/dist/src/presets/index.d.ts +4 -0
  153. package/dist/src/presets/index.js +3 -0
  154. package/dist/src/presets/runtime-array-helpers.d.ts +8 -0
  155. package/dist/src/presets/runtime-array-helpers.js +147 -0
  156. package/dist/src/presets/runtime-component-props.d.ts +3 -0
  157. package/dist/src/presets/runtime-component-props.js +5 -0
  158. package/dist/src/presets/runtime-components.d.ts +5 -0
  159. package/dist/src/presets/runtime-components.js +419 -0
  160. package/dist/src/presets/runtime-form-components.d.ts +9 -0
  161. package/dist/src/presets/runtime-form-components.js +94 -0
  162. package/dist/src/presets/scenario-catalog.d.ts +6 -0
  163. package/dist/src/presets/scenario-catalog.js +128 -0
  164. package/dist/src/presets/scenarios.d.ts +52 -0
  165. package/dist/src/presets/scenarios.js +603 -0
  166. package/dist/src/runtime/actions.d.ts +19 -0
  167. package/dist/src/runtime/actions.js +307 -0
  168. package/dist/src/runtime/contracts.d.ts +149 -0
  169. package/dist/src/runtime/contracts.js +1 -0
  170. package/dist/src/runtime/document-bindings.d.ts +3 -0
  171. package/dist/src/runtime/document-bindings.js +101 -0
  172. package/dist/src/runtime/document-core.d.ts +57 -0
  173. package/dist/src/runtime/document-core.js +379 -0
  174. package/dist/src/runtime/document-entity.d.ts +12 -0
  175. package/dist/src/runtime/document-entity.js +351 -0
  176. package/dist/src/runtime/document-expressions.d.ts +35 -0
  177. package/dist/src/runtime/document-expressions.js +346 -0
  178. package/dist/src/runtime/document-security.d.ts +34 -0
  179. package/dist/src/runtime/document-security.js +538 -0
  180. package/dist/src/runtime/document.d.ts +16 -0
  181. package/dist/src/runtime/document.js +212 -0
  182. package/dist/src/runtime/environment.d.ts +16 -0
  183. package/dist/src/runtime/environment.js +76 -0
  184. package/dist/src/runtime/i18n-schema.d.ts +36 -0
  185. package/dist/src/runtime/i18n-schema.js +338 -0
  186. package/dist/src/runtime/i18n.d.ts +25 -0
  187. package/dist/src/runtime/i18n.js +447 -0
  188. package/dist/src/runtime/index.d.ts +8 -0
  189. package/dist/src/runtime/index.js +8 -0
  190. package/dist/src/runtime/navigation.d.ts +5 -0
  191. package/dist/src/runtime/navigation.js +43 -0
  192. package/dist/src/runtime/playground.d.ts +30 -0
  193. package/dist/src/runtime/playground.js +243 -0
  194. package/dist/src/runtime/preview-boundaries.d.ts +13 -0
  195. package/dist/src/runtime/preview-boundaries.js +43 -0
  196. package/dist/src/runtime/preview.d.ts +44 -0
  197. package/dist/src/runtime/preview.js +574 -0
  198. package/dist/src/runtime/settings/RuntimeJsonEditor.d.ts +10 -0
  199. package/dist/src/runtime/settings/RuntimeJsonEditor.js +21 -0
  200. package/dist/src/runtime/settings/RuntimeStoreEntitySettings.d.ts +15 -0
  201. package/dist/src/runtime/settings/RuntimeStoreEntitySettings.js +65 -0
  202. package/dist/src/runtime/templates.d.ts +1560 -0
  203. package/dist/src/runtime/templates.js +508 -0
  204. package/dist/src/runtime/website-contact-template.d.ts +1 -0
  205. package/dist/src/runtime/website-contact-template.js +66 -0
  206. package/dist/src/runtime/website-template-shared.d.ts +14 -0
  207. package/dist/src/runtime/website-template-shared.js +210 -0
  208. package/dist/src/runtime/website-templates.d.ts +5 -0
  209. package/dist/src/runtime/website-templates.js +976 -0
  210. package/dist/src/shared/clipboard.d.ts +4 -0
  211. package/dist/src/shared/clipboard.js +56 -0
  212. package/dist/src/shared/componentRegistry.d.ts +133 -0
  213. package/dist/src/shared/componentRegistry.js +381 -0
  214. package/dist/src/shared/formilyCompatibility.d.ts +8 -0
  215. package/dist/src/shared/formilyCompatibility.js +40 -0
  216. package/dist/src/shared/index.d.ts +6 -0
  217. package/dist/src/shared/index.js +6 -0
  218. package/dist/src/shared/productionAcceptance.d.ts +63 -0
  219. package/dist/src/shared/productionAcceptance.js +201 -0
  220. package/dist/src/shared/schema-options.d.ts +16 -0
  221. package/dist/src/shared/schema-options.js +138 -0
  222. package/dist/src/shared/schema.d.ts +63 -0
  223. package/dist/src/shared/schema.js +627 -0
  224. package/dist/src/shared/styleSecurity.d.ts +2 -0
  225. package/dist/src/shared/styleSecurity.js +35 -0
  226. package/dist/src/transformers/formily.d.ts +34 -0
  227. package/dist/src/transformers/formily.js +943 -0
  228. package/dist/src/transformers/index.d.ts +1 -0
  229. package/dist/src/transformers/index.js +1 -0
  230. package/dist/src/types.d.ts +186 -0
  231. package/dist/src/types.js +1 -0
  232. package/dist/src/widgets/ActionsWidget/index.d.ts +3 -0
  233. package/dist/src/widgets/ActionsWidget/index.js +10 -0
  234. package/dist/src/widgets/ComponentTreeWidget/index.d.ts +3 -0
  235. package/dist/src/widgets/ComponentTreeWidget/index.js +333 -0
  236. package/dist/src/widgets/NodeActionsWidget/index.d.ts +2 -0
  237. package/dist/src/widgets/NodeActionsWidget/index.js +125 -0
  238. package/dist/src/widgets/OutlineTreeWidget/index.d.ts +3 -0
  239. package/dist/src/widgets/OutlineTreeWidget/index.js +432 -0
  240. package/dist/src/widgets/OutlineTreeWidget/shared.d.ts +32 -0
  241. package/dist/src/widgets/OutlineTreeWidget/shared.js +79 -0
  242. package/dist/src/widgets/PreviewWidget/index.d.ts +2 -0
  243. package/dist/src/widgets/PreviewWidget/index.js +1566 -0
  244. package/dist/src/widgets/ProductionReadinessWidget/index.d.ts +18 -0
  245. package/dist/src/widgets/ProductionReadinessWidget/index.js +356 -0
  246. package/dist/src/widgets/RemotePersistenceStatusWidget/index.d.ts +18 -0
  247. package/dist/src/widgets/RemotePersistenceStatusWidget/index.js +438 -0
  248. package/dist/src/widgets/RemoteVersionHistoryWidget/index.d.ts +39 -0
  249. package/dist/src/widgets/RemoteVersionHistoryWidget/index.js +475 -0
  250. package/dist/src/widgets/ResourceWidget/index.d.ts +3 -0
  251. package/dist/src/widgets/ResourceWidget/index.js +491 -0
  252. package/dist/src/widgets/SchemaCodeView/index.d.ts +7 -0
  253. package/dist/src/widgets/SchemaCodeView/index.js +225 -0
  254. package/dist/src/widgets/SchemaEditorWidget/index.d.ts +10 -0
  255. package/dist/src/widgets/SchemaEditorWidget/index.js +484 -0
  256. package/dist/src/widgets/SettingsPanelWidget/index.d.ts +3 -0
  257. package/dist/src/widgets/SettingsPanelWidget/index.js +190 -0
  258. package/dist/src/widgets/StorageActionsWidget/index.d.ts +2 -0
  259. package/dist/src/widgets/StorageActionsWidget/index.js +284 -0
  260. package/dist/src/widgets/index.d.ts +13 -0
  261. package/dist/src/widgets/index.js +13 -0
  262. package/package.json +100 -4
@@ -0,0 +1,212 @@
1
+ import { RUNTIME_DOCUMENT_SIDECAR_PROP } from "../shared/schema.js";
2
+ import { RUNTIME_DOCUMENT_KIND, RUNTIME_DOCUMENT_VERSION, RUNTIME_SCHEMA_FIDELITY_PROP, RUNTIME_DOCUMENT_KEYS, RUNTIME_DOCUMENT_SIDECAR_KEYS, RUNTIME_SCOPE_RESERVED_KEYS, RuntimeDocumentValidationError, isObjectRecord, pushRuntimeIssue, cloneRuntimeJsonValue, validateAllowedKeys, validateRuntimeStoreConfig, } from "./document-core.js";
3
+ import { validateRuntimeSchemaRoot, validateRuntimeEntityConfig, validateRuntimeMetadata, validateRuntimeDataBindings, createRuntimeEntitySchemaRoot, validateRuntimeFieldsConfigDataBindings, validateRuntimeI18nDataBindings, createRuntimeSchemaFidelity, restoreRuntimeSchemaFidelity, } from "./document-entity.js";
4
+ export { RuntimeDocumentValidationError, } from "./document-core.js";
5
+ export { isAllowedRuntimeDataKeyPath } from "./document-expressions.js";
6
+ export { createRuntimeEntitySchemaRoot } from "./document-entity.js";
7
+ export const isRuntimeDocumentCandidate = (value) => {
8
+ try {
9
+ if (!isObjectRecord(value)
10
+ || !Object.prototype.hasOwnProperty.call(value, 'schema')) {
11
+ return false;
12
+ }
13
+ return ['kind', 'version', ...RUNTIME_DOCUMENT_SIDECAR_KEYS]
14
+ .some(key => Object.prototype.hasOwnProperty.call(value, key));
15
+ }
16
+ catch {
17
+ return true;
18
+ }
19
+ };
20
+ const validateRuntimeDocumentRecord = (value, issues) => {
21
+ try {
22
+ if (isObjectRecord(value))
23
+ return true;
24
+ }
25
+ catch {
26
+ pushRuntimeIssue(issues, 'runtime-non-json-value', 'document', 'Runtime 文档包含无法安全读取的非 JSON 对象');
27
+ return false;
28
+ }
29
+ pushRuntimeIssue(issues, 'invalid-runtime-document', 'document', 'Runtime 文档必须是对象');
30
+ return false;
31
+ };
32
+ const readRuntimeDocumentDiscriminator = (value, issues) => {
33
+ const discriminator = {};
34
+ try {
35
+ ['kind', 'version'].forEach((key) => {
36
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
37
+ if (descriptor
38
+ && (!descriptor.enumerable || !('value' in descriptor))) {
39
+ pushRuntimeIssue(issues, 'runtime-non-json-value', `document.${key}`, 'Runtime 文档判别字段必须是可枚举的数据属性');
40
+ return;
41
+ }
42
+ discriminator[key] = descriptor?.value;
43
+ });
44
+ }
45
+ catch {
46
+ pushRuntimeIssue(issues, 'runtime-non-json-value', 'document', 'Runtime 文档包含无法安全读取的判别字段');
47
+ }
48
+ return discriminator;
49
+ };
50
+ export const validateRuntimeDocument = (value) => {
51
+ const issues = [];
52
+ if (!validateRuntimeDocumentRecord(value, issues)) {
53
+ return { issues, valid: false };
54
+ }
55
+ const { kind, version } = readRuntimeDocumentDiscriminator(value, issues);
56
+ if (issues.length > 0) {
57
+ return { issues, valid: false };
58
+ }
59
+ if (kind !== RUNTIME_DOCUMENT_KIND) {
60
+ pushRuntimeIssue(issues, 'invalid-runtime-document', 'document.kind', `Runtime 文档 kind 必须是 ${RUNTIME_DOCUMENT_KIND}`);
61
+ return { issues, valid: false };
62
+ }
63
+ if (version !== RUNTIME_DOCUMENT_VERSION) {
64
+ const code = typeof version === 'number' && Number.isInteger(version)
65
+ ? 'unsupported-runtime-document-version'
66
+ : 'invalid-runtime-document';
67
+ pushRuntimeIssue(issues, code, 'document.version', `Runtime 文档仅支持版本 ${RUNTIME_DOCUMENT_VERSION}`);
68
+ return { issues, valid: false };
69
+ }
70
+ let cloned;
71
+ try {
72
+ cloned = cloneRuntimeJsonValue(value, 'document', issues, new Set());
73
+ }
74
+ catch {
75
+ pushRuntimeIssue(issues, 'runtime-non-json-value', 'document', 'Runtime 文档包含无法安全读取的非 JSON 对象');
76
+ }
77
+ if (!isObjectRecord(cloned) || issues.length > 0) {
78
+ return { issues, valid: false };
79
+ }
80
+ validateAllowedKeys(cloned, RUNTIME_DOCUMENT_KEYS, issues, 'document', 'invalid-runtime-document');
81
+ const effectiveSchemaRoot = createRuntimeEntitySchemaRoot(cloned.schema, cloned.entityConfig, cloned.store);
82
+ validateRuntimeSchemaRoot(cloned.schema, issues, 'document.schema', effectiveSchemaRoot);
83
+ if (cloned.store !== undefined) {
84
+ validateRuntimeStoreConfig(cloned.store, issues, 'document.store');
85
+ }
86
+ if (cloned.entityConfig !== undefined) {
87
+ validateRuntimeEntityConfig(cloned.entityConfig, issues, 'document.entityConfig');
88
+ }
89
+ if (cloned.scope !== undefined) {
90
+ if (!isObjectRecord(cloned.scope)) {
91
+ pushRuntimeIssue(issues, 'invalid-runtime-document', 'document.scope', 'scope 必须是 JSON 对象');
92
+ }
93
+ else {
94
+ Object.keys(cloned.scope).forEach((key) => {
95
+ if (!RUNTIME_SCOPE_RESERVED_KEYS.has(key))
96
+ return;
97
+ pushRuntimeIssue(issues, 'invalid-runtime-document', `document.scope.${key}`, `scope.${key} 是运行时保留键,只能由受信宿主注入`);
98
+ });
99
+ }
100
+ }
101
+ if (cloned.metadata !== undefined) {
102
+ validateRuntimeMetadata(cloned.metadata, issues, 'document.metadata');
103
+ }
104
+ validateRuntimeDataBindings(cloned.schema, issues, 'document.schema', effectiveSchemaRoot);
105
+ validateRuntimeFieldsConfigDataBindings(cloned.store, issues, 'document.store', effectiveSchemaRoot);
106
+ validateRuntimeFieldsConfigDataBindings(cloned.entityConfig, issues, 'document.entityConfig', effectiveSchemaRoot);
107
+ validateRuntimeI18nDataBindings(cloned.entityConfig, issues, 'document.entityConfig');
108
+ return {
109
+ document: issues.length ? undefined : cloned,
110
+ issues,
111
+ valid: issues.length === 0,
112
+ };
113
+ };
114
+ export const validateRuntimeEnvironmentScope = (value) => {
115
+ if (value === undefined) {
116
+ return { issues: [], scope: undefined, valid: true };
117
+ }
118
+ const issues = [];
119
+ let cloned;
120
+ try {
121
+ cloned = cloneRuntimeJsonValue(value, 'environment.scope', issues, new Set());
122
+ }
123
+ catch {
124
+ pushRuntimeIssue(issues, 'runtime-non-json-value', 'environment.scope', 'Runtime 宿主 scope 包含无法安全读取的非 JSON 对象');
125
+ }
126
+ if (!isObjectRecord(cloned) && issues.length === 0) {
127
+ pushRuntimeIssue(issues, 'invalid-runtime-document', 'environment.scope', 'Runtime 宿主 scope 必须是 JSON 对象');
128
+ }
129
+ return {
130
+ issues,
131
+ scope: issues.length === 0 && isObjectRecord(cloned)
132
+ ? cloned
133
+ : undefined,
134
+ valid: issues.length === 0,
135
+ };
136
+ };
137
+ export const assertRuntimeDocument = (value) => {
138
+ const result = validateRuntimeDocument(value);
139
+ if (!result.valid || !result.document) {
140
+ throw new RuntimeDocumentValidationError(result.issues);
141
+ }
142
+ return result.document;
143
+ };
144
+ const createRuntimeDocumentSidecar = (document, fidelity) => {
145
+ const sidecar = Object.fromEntries(Object.entries(document).filter(([key]) => key !== 'schema'));
146
+ return {
147
+ ...sidecar,
148
+ [RUNTIME_SCHEMA_FIDELITY_PROP]: fidelity,
149
+ };
150
+ };
151
+ const createEmptyRuntimeDocument = (value) => {
152
+ const document = assertRuntimeDocument(value);
153
+ const schema = { ...document.schema };
154
+ delete schema.required;
155
+ return {
156
+ ...document,
157
+ schema: {
158
+ ...schema,
159
+ properties: {},
160
+ type: 'object',
161
+ },
162
+ };
163
+ };
164
+ export const createRuntimeDocumentTransformer = (baseTransformer) => {
165
+ const mapUnsafeSchemaObjectKeyError = (error) => {
166
+ const genericPath = error.message.slice('Schema 包含不安全字段路径:'.length);
167
+ const path = genericPath.replace(/^Schema(?=\.|$)/, 'document');
168
+ const pathSegments = path.split('.');
169
+ const key = pathSegments[pathSegments.length - 1] ?? path;
170
+ const issues = [];
171
+ pushRuntimeIssue(issues, 'runtime-unsafe-key', path, `Runtime 文档包含危险对象键 ${key}`);
172
+ return new RuntimeDocumentValidationError(issues);
173
+ };
174
+ const prepareSchema = (schema) => assertRuntimeDocument(schema);
175
+ const createEmptySchema = (schema) => createEmptyRuntimeDocument(schema);
176
+ const toTreeNode = (value) => {
177
+ if (!isRuntimeDocumentCandidate(value)) {
178
+ return baseTransformer.toTreeNode(value);
179
+ }
180
+ const document = assertRuntimeDocument(value);
181
+ const tree = baseTransformer.toTreeNode(document.schema);
182
+ const normalizedSchema = baseTransformer.toSchema(tree);
183
+ tree.props = {
184
+ ...tree.props,
185
+ [RUNTIME_DOCUMENT_SIDECAR_PROP]: createRuntimeDocumentSidecar(document, createRuntimeSchemaFidelity(document.schema, normalizedSchema)),
186
+ };
187
+ return tree;
188
+ };
189
+ const toSchema = (tree) => {
190
+ const sidecar = tree.props?.[RUNTIME_DOCUMENT_SIDECAR_PROP];
191
+ if (sidecar === undefined) {
192
+ return baseTransformer.toSchema(tree);
193
+ }
194
+ const sidecarRecord = isObjectRecord(sidecar) ? sidecar : {};
195
+ const { [RUNTIME_SCHEMA_FIDELITY_PROP]: fidelity, ...documentSidecar } = sidecarRecord;
196
+ const schema = restoreRuntimeSchemaFidelity(baseTransformer.toSchema(tree), fidelity);
197
+ const document = {
198
+ ...documentSidecar,
199
+ schema,
200
+ };
201
+ return assertRuntimeDocument(document);
202
+ };
203
+ return {
204
+ createEmptySchema,
205
+ historySnapshotMode: 'atomic',
206
+ mapUnsafeSchemaObjectKeyError,
207
+ prepareSchema,
208
+ toSchema,
209
+ toTreeNode,
210
+ };
211
+ };
212
+ export { RUNTIME_DOCUMENT_SIDECAR_PROP };
@@ -0,0 +1,16 @@
1
+ import type { RuntimeDocumentV1, RuntimeEnvironment, RuntimeStoreCatalogItem } from "./contracts.js";
2
+ import type { IRuntimeDocumentValidationIssue } from "./document.js";
3
+ export declare const RUNTIME_STORE_CATALOG_ID_KEY = "storeCatalogId";
4
+ export interface IRuntimeStoreCatalogNormalization {
5
+ error?: string;
6
+ items: RuntimeStoreCatalogItem[];
7
+ }
8
+ export interface IRuntimeStoreCatalogBinding {
9
+ catalogId?: string;
10
+ environment: RuntimeEnvironment;
11
+ issue?: IRuntimeDocumentValidationIssue;
12
+ }
13
+ export declare const getRuntimeStoreCatalogId: (document: RuntimeDocumentV1) => string | undefined;
14
+ export declare const normalizeRuntimeStoreCatalog: (catalog?: readonly RuntimeStoreCatalogItem[]) => IRuntimeStoreCatalogNormalization;
15
+ export declare const resolveRuntimeStoreCatalogBinding: (document: RuntimeDocumentV1, environment: RuntimeEnvironment) => IRuntimeStoreCatalogBinding;
16
+ export declare const setRuntimeStoreCatalogId: (document: RuntimeDocumentV1, catalogId: string | undefined) => RuntimeDocumentV1;
@@ -0,0 +1,76 @@
1
+ export const RUNTIME_STORE_CATALOG_ID_KEY = 'storeCatalogId';
2
+ export const getRuntimeStoreCatalogId = (document) => {
3
+ const value = document.metadata?.extensions?.[RUNTIME_STORE_CATALOG_ID_KEY];
4
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
5
+ };
6
+ export const normalizeRuntimeStoreCatalog = (catalog = []) => {
7
+ const items = catalog.map(item => ({ ...item, id: item.id.trim(), label: item.label.trim() }));
8
+ const counts = new Map();
9
+ items.forEach(item => counts.set(item.id, (counts.get(item.id) ?? 0) + 1));
10
+ const invalidIds = items
11
+ .filter(item => !item.id || !item.label || counts.get(item.id) > 1 || item.id === '__document__')
12
+ .map(item => item.id || '(空白)');
13
+ if (!invalidIds.length)
14
+ return { items };
15
+ return {
16
+ error: `Store 目录包含空白、重复或保留 ID:${[...new Set(invalidIds)].join('、')}`,
17
+ items: [],
18
+ };
19
+ };
20
+ export const resolveRuntimeStoreCatalogBinding = (document, environment) => {
21
+ const catalogId = getRuntimeStoreCatalogId(document);
22
+ if (!catalogId)
23
+ return { environment };
24
+ const normalized = normalizeRuntimeStoreCatalog(environment.storeCatalog);
25
+ if (normalized.error) {
26
+ return {
27
+ catalogId,
28
+ environment,
29
+ issue: {
30
+ code: 'invalid-runtime-store-catalog',
31
+ message: normalized.error,
32
+ path: 'environment.storeCatalog',
33
+ severity: 'error',
34
+ },
35
+ };
36
+ }
37
+ const selected = normalized.items.find(item => item.id === catalogId);
38
+ if (!selected) {
39
+ return {
40
+ catalogId,
41
+ environment,
42
+ issue: {
43
+ code: 'unknown-runtime-store-reference',
44
+ message: `宿主 Store 目录中不存在“${catalogId}”`,
45
+ path: `document.metadata.extensions.${RUNTIME_STORE_CATALOG_ID_KEY}`,
46
+ severity: 'error',
47
+ },
48
+ };
49
+ }
50
+ return {
51
+ catalogId,
52
+ environment: {
53
+ ...environment,
54
+ apiExecutor: selected.apiExecutor,
55
+ entity: selected.entity,
56
+ store: selected.store,
57
+ },
58
+ };
59
+ };
60
+ export const setRuntimeStoreCatalogId = (document, catalogId) => {
61
+ const extensions = { ...(document.metadata?.extensions ?? {}) };
62
+ if (catalogId)
63
+ extensions[RUNTIME_STORE_CATALOG_ID_KEY] = catalogId;
64
+ else
65
+ delete extensions[RUNTIME_STORE_CATALOG_ID_KEY];
66
+ const metadata = {
67
+ ...(document.metadata ?? {}),
68
+ extensions,
69
+ };
70
+ if (!Object.keys(extensions).length)
71
+ delete metadata.extensions;
72
+ const nextDocument = { ...document, metadata };
73
+ if (!Object.keys(metadata).length)
74
+ delete nextDocument.metadata;
75
+ return nextDocument;
76
+ };
@@ -0,0 +1,36 @@
1
+ import type { IFormilySchemaDocument } from "../transformers/index.js";
2
+ import type { RuntimeAPIRequestConfigV1, RuntimeDiagnosticCode, RuntimeDocumentV1, RuntimeLanguageCatalogItem } from "./contracts.js";
3
+ import { type IRuntimeDocumentValidationResult } from "./document.js";
4
+ export interface IRuntimeI18nDiagnostic {
5
+ code: RuntimeDiagnosticCode;
6
+ message: string;
7
+ path: string;
8
+ severity: 'warning';
9
+ }
10
+ export interface IRuntimeI18nSchemaGenerationResult {
11
+ diagnostics: IRuntimeI18nDiagnostic[];
12
+ inputSchema?: IFormilySchemaDocument;
13
+ outputSchema?: IFormilySchemaDocument;
14
+ valid: boolean;
15
+ }
16
+ export interface IRuntimeLanguageSourceResolution {
17
+ catalogId?: string;
18
+ diagnostics: IRuntimeI18nDiagnostic[];
19
+ langAPI: RuntimeAPIRequestConfigV1 | false;
20
+ }
21
+ export interface IResolveRuntimeLanguageSourceOptions {
22
+ document: RuntimeDocumentV1;
23
+ languageCatalog?: RuntimeLanguageCatalogItem[];
24
+ }
25
+ export declare const isObjectRecord: (value: unknown) => value is Record<string, unknown>;
26
+ export declare const createI18nDiagnostic: (code: RuntimeDiagnosticCode, path: string, message: string) => IRuntimeI18nDiagnostic;
27
+ export declare const stringifyNormalizedJson: (value: unknown) => string;
28
+ export declare const RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID = "__custom__";
29
+ export interface INormalizedRuntimeLanguageCatalog {
30
+ error?: string;
31
+ items: RuntimeLanguageCatalogItem[];
32
+ }
33
+ export declare const normalizeRuntimeLanguageCatalog: (languageCatalog: readonly RuntimeLanguageCatalogItem[]) => INormalizedRuntimeLanguageCatalog;
34
+ export declare const validateRuntimeI18nConfig: (document: unknown) => IRuntimeDocumentValidationResult;
35
+ export declare const createRuntimeI18nSchemas: (document: RuntimeDocumentV1, selectedFields: string[]) => IRuntimeI18nSchemaGenerationResult;
36
+ export declare const resolveRuntimeLanguageSource: ({ document, languageCatalog, }: IResolveRuntimeLanguageSourceOptions) => IRuntimeLanguageSourceResolution;
@@ -0,0 +1,338 @@
1
+ import { cloneDeep } from 'lodash-es';
2
+ import { decodeJsonPointerSegment, isSafeSchemaObjectKey, } from "../shared/schema.js";
3
+ import { createRuntimeEntitySchemaRoot, validateRuntimeDocument, } from "./document.js";
4
+ const I18N_SCHEMA_COPY_KEYS = [
5
+ '$ref',
6
+ 'type',
7
+ 'title',
8
+ 'description',
9
+ 'x-component',
10
+ 'x-component-props',
11
+ 'x-decorator',
12
+ 'x-decorator-props',
13
+ 'enum',
14
+ 'enumNames',
15
+ 'x-validator',
16
+ ];
17
+ const I18N_SCHEMA_RECORD_CHILD_KEYS = new Set([
18
+ '$defs',
19
+ 'definitions',
20
+ 'dependentSchemas',
21
+ 'patternProperties',
22
+ 'properties',
23
+ ]);
24
+ const I18N_SCHEMA_SINGLE_CHILD_KEYS = new Set([
25
+ 'additionalProperties',
26
+ 'additionalItems',
27
+ 'contains',
28
+ 'else',
29
+ 'if',
30
+ 'not',
31
+ 'then',
32
+ ]);
33
+ const I18N_SCHEMA_ARRAY_CHILD_KEYS = new Set([
34
+ 'allOf',
35
+ 'anyOf',
36
+ 'oneOf',
37
+ 'prefixItems',
38
+ ]);
39
+ const I18N_SCHEMA_REMOVED_KEYS = new Set([
40
+ 'default',
41
+ 'reactions',
42
+ 'x-reactions',
43
+ ]);
44
+ export const isObjectRecord = (value) => (typeof value === 'object'
45
+ && value !== null
46
+ && !Array.isArray(value));
47
+ export const createI18nDiagnostic = (code, path, message) => ({
48
+ code,
49
+ message,
50
+ path,
51
+ severity: 'warning',
52
+ });
53
+ const normalizeJsonValue = (value) => {
54
+ if (Array.isArray(value)) {
55
+ return value.map(normalizeJsonValue);
56
+ }
57
+ if (!isObjectRecord(value))
58
+ return value;
59
+ return Object.fromEntries(Object.keys(value)
60
+ .sort()
61
+ .map(key => [key, normalizeJsonValue(value[key])]));
62
+ };
63
+ export const stringifyNormalizedJson = (value) => (JSON.stringify(normalizeJsonValue(value)));
64
+ export const RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID = '__custom__';
65
+ export const normalizeRuntimeLanguageCatalog = (languageCatalog) => {
66
+ const normalizedItems = languageCatalog.map(item => ({
67
+ ...item,
68
+ id: item.id.trim(),
69
+ }));
70
+ const idCounts = new Map();
71
+ normalizedItems.forEach((item) => {
72
+ idCounts.set(item.id, (idCounts.get(item.id) ?? 0) + 1);
73
+ });
74
+ const invalidIds = normalizedItems
75
+ .filter(item => (!item.id
76
+ || item.id === RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID
77
+ || (idCounts.get(item.id) ?? 0) > 1))
78
+ .map(item => item.id || '(空 ID)');
79
+ return {
80
+ error: invalidIds.length
81
+ ? `语言目录包含空白、重复或保留 ID:${[...new Set(invalidIds)].join('、')}`
82
+ : undefined,
83
+ items: normalizedItems.filter(item => (!!item.id
84
+ && item.id !== RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID
85
+ && (idCounts.get(item.id) ?? 0) === 1)),
86
+ };
87
+ };
88
+ const parseLocalDefinitionName = (ref) => {
89
+ if (typeof ref !== 'string')
90
+ return undefined;
91
+ const match = /^#\/definitions\/([^/]+)$/.exec(ref);
92
+ if (!match)
93
+ return undefined;
94
+ return decodeJsonPointerSegment(match[1]);
95
+ };
96
+ const removeRequiredValidator = (value) => {
97
+ if (value === 'required')
98
+ return undefined;
99
+ if (Array.isArray(value)) {
100
+ const rules = value
101
+ .map(removeRequiredValidator)
102
+ .filter(rule => rule !== undefined);
103
+ return rules.length ? rules : undefined;
104
+ }
105
+ if (!isObjectRecord(value))
106
+ return cloneDeep(value);
107
+ if (value.validator === 'required')
108
+ return undefined;
109
+ const rule = cloneDeep(value);
110
+ if (rule.required === true)
111
+ delete rule.required;
112
+ return Object.keys(rule).length ? rule : undefined;
113
+ };
114
+ const copyAllowedSchemaNode = (node, path, context) => {
115
+ const copied = {};
116
+ I18N_SCHEMA_COPY_KEYS.forEach((key) => {
117
+ if (!Object.prototype.hasOwnProperty.call(node, key))
118
+ return;
119
+ const value = key === 'x-validator'
120
+ ? removeRequiredValidator(node[key])
121
+ : cloneDeep(node[key]);
122
+ if (value !== undefined)
123
+ copied[key] = value;
124
+ });
125
+ Object.entries(node).forEach(([key, value]) => {
126
+ const isStructuredChild = I18N_SCHEMA_RECORD_CHILD_KEYS.has(key)
127
+ || I18N_SCHEMA_SINGLE_CHILD_KEYS.has(key)
128
+ || I18N_SCHEMA_ARRAY_CHILD_KEYS.has(key)
129
+ || key === 'items';
130
+ if (!isStructuredChild)
131
+ return;
132
+ const copiedContainer = copyRuntimeDefinitionNode({ [key]: value }, path, context);
133
+ if (!copiedContainer)
134
+ return;
135
+ copied[key] = copiedContainer[key];
136
+ });
137
+ if (Object.prototype.hasOwnProperty.call(node, '$ref')) {
138
+ const definitionName = parseLocalDefinitionName(node.$ref);
139
+ if (!definitionName
140
+ || !isSafeSchemaObjectKey(definitionName)
141
+ || !Object.prototype.hasOwnProperty.call(context.definitions, definitionName)) {
142
+ context.diagnostics.push(createI18nDiagnostic('unsupported-i18n-schema-ref', `${path}.$ref`, '多语言 Schema 只支持可解析的本地 #/definitions/* 引用'));
143
+ return undefined;
144
+ }
145
+ if (!copyRuntimeDefinition(definitionName, context))
146
+ return undefined;
147
+ }
148
+ return copied;
149
+ };
150
+ function copyRuntimeDefinitionNode(node, path, context) {
151
+ const copied = {};
152
+ for (const [key, value] of Object.entries(node)) {
153
+ if (I18N_SCHEMA_REMOVED_KEYS.has(key))
154
+ continue;
155
+ if (key === 'x-validator') {
156
+ const validator = removeRequiredValidator(value);
157
+ if (validator !== undefined)
158
+ copied[key] = validator;
159
+ continue;
160
+ }
161
+ if (key === '$ref') {
162
+ const definitionName = parseLocalDefinitionName(value);
163
+ if (!definitionName
164
+ || !isSafeSchemaObjectKey(definitionName)
165
+ || !Object.prototype.hasOwnProperty.call(context.definitions, definitionName)
166
+ || !copyRuntimeDefinition(definitionName, context)) {
167
+ if (!context.diagnostics.some(diagnostic => (diagnostic.path === `${path}.$ref`))) {
168
+ context.diagnostics.push(createI18nDiagnostic('unsupported-i18n-schema-ref', `${path}.$ref`, '多语言 Schema 只支持无循环的本地 #/definitions/* 引用'));
169
+ }
170
+ return undefined;
171
+ }
172
+ copied[key] = value;
173
+ continue;
174
+ }
175
+ if (I18N_SCHEMA_RECORD_CHILD_KEYS.has(key) && isObjectRecord(value)) {
176
+ const children = {};
177
+ for (const [childKey, childValue] of Object.entries(value)) {
178
+ if (!isObjectRecord(childValue)) {
179
+ children[childKey] = cloneDeep(childValue);
180
+ continue;
181
+ }
182
+ const child = copyRuntimeDefinitionNode(childValue, `${path}.${key}.${childKey}`, context);
183
+ if (!child)
184
+ return undefined;
185
+ children[childKey] = child;
186
+ }
187
+ copied[key] = children;
188
+ continue;
189
+ }
190
+ if ((I18N_SCHEMA_SINGLE_CHILD_KEYS.has(key) || key === 'items')
191
+ && isObjectRecord(value)) {
192
+ const child = copyRuntimeDefinitionNode(value, `${path}.${key}`, context);
193
+ if (!child)
194
+ return undefined;
195
+ copied[key] = child;
196
+ continue;
197
+ }
198
+ if ((I18N_SCHEMA_ARRAY_CHILD_KEYS.has(key) || key === 'items')
199
+ && Array.isArray(value)) {
200
+ const children = [];
201
+ for (const [index, childValue] of value.entries()) {
202
+ if (!isObjectRecord(childValue)) {
203
+ children.push(cloneDeep(childValue));
204
+ continue;
205
+ }
206
+ const child = copyRuntimeDefinitionNode(childValue, `${path}.${key}[${index}]`, context);
207
+ if (!child)
208
+ return undefined;
209
+ children.push(child);
210
+ }
211
+ copied[key] = children;
212
+ continue;
213
+ }
214
+ copied[key] = cloneDeep(value);
215
+ }
216
+ return copied;
217
+ }
218
+ function copyRuntimeDefinition(definitionName, context) {
219
+ if (context.resolved.has(definitionName))
220
+ return true;
221
+ if (context.resolving.has(definitionName)) {
222
+ context.diagnostics.push(createI18nDiagnostic('unsupported-i18n-schema-ref', `document.schema.definitions.${definitionName}`, '多语言 Schema 不支持循环 definitions 引用'));
223
+ return false;
224
+ }
225
+ const definition = context.definitions[definitionName];
226
+ if (!isObjectRecord(definition)) {
227
+ context.diagnostics.push(createI18nDiagnostic('unsupported-i18n-schema-ref', `document.schema.definitions.${definitionName}`, '多语言 Schema 引用的 definition 不存在或不是对象'));
228
+ return false;
229
+ }
230
+ context.resolving.add(definitionName);
231
+ const copied = copyRuntimeDefinitionNode(definition, `document.schema.definitions.${definitionName}`, context);
232
+ context.resolving.delete(definitionName);
233
+ if (!copied || context.diagnostics.length > 0)
234
+ return false;
235
+ context.outputDefinitions[definitionName] = copied;
236
+ context.resolved.add(definitionName);
237
+ return true;
238
+ }
239
+ export const validateRuntimeI18nConfig = (document) => validateRuntimeDocument(document);
240
+ export const createRuntimeI18nSchemas = (document, selectedFields) => {
241
+ const validation = validateRuntimeDocument(document);
242
+ if (!validation.valid || !validation.document) {
243
+ return {
244
+ diagnostics: [],
245
+ valid: false,
246
+ };
247
+ }
248
+ const effectiveSchema = createRuntimeEntitySchemaRoot(validation.document.schema, validation.document.entityConfig, validation.document.store);
249
+ const rootProperties = effectiveSchema.properties ?? {};
250
+ const definitions = isObjectRecord(effectiveSchema.definitions)
251
+ ? effectiveSchema.definitions
252
+ : {};
253
+ const context = {
254
+ definitions,
255
+ diagnostics: [],
256
+ outputDefinitions: {},
257
+ resolved: new Set(),
258
+ resolving: new Set(),
259
+ };
260
+ const inputProperties = {};
261
+ const outputProperties = {};
262
+ const normalizedFields = [...new Set(selectedFields.map(field => field.trim()).filter(Boolean))];
263
+ if (!normalizedFields.length) {
264
+ return {
265
+ diagnostics: [],
266
+ valid: false,
267
+ };
268
+ }
269
+ for (const field of normalizedFields) {
270
+ const sourceNode = rootProperties[field];
271
+ if (!isSafeSchemaObjectKey(field) || !isObjectRecord(sourceNode)) {
272
+ context.diagnostics.push(createI18nDiagnostic('unsupported-i18n-schema-ref', `document.schema.properties.${field}`, '自动生成只能选择当前根 Schema 中的安全顶层字段'));
273
+ break;
274
+ }
275
+ const copied = copyAllowedSchemaNode(sourceNode, `document.schema.properties.${field}`, context);
276
+ if (!copied || context.diagnostics.length > 0)
277
+ break;
278
+ inputProperties[field] = {
279
+ ...copied,
280
+ required: false,
281
+ };
282
+ outputProperties[field] = {
283
+ ...cloneDeep(copied),
284
+ required: false,
285
+ 'x-pattern': 'readPretty',
286
+ };
287
+ }
288
+ if (context.diagnostics.length > 0) {
289
+ return {
290
+ diagnostics: context.diagnostics,
291
+ valid: false,
292
+ };
293
+ }
294
+ const definitionsResult = Object.keys(context.outputDefinitions).length
295
+ ? { definitions: context.outputDefinitions }
296
+ : {};
297
+ return {
298
+ diagnostics: [],
299
+ inputSchema: {
300
+ ...definitionsResult,
301
+ properties: inputProperties,
302
+ type: 'object',
303
+ },
304
+ outputSchema: {
305
+ ...cloneDeep(definitionsResult),
306
+ properties: outputProperties,
307
+ type: 'object',
308
+ },
309
+ valid: true,
310
+ };
311
+ };
312
+ export const resolveRuntimeLanguageSource = ({ document, languageCatalog = [], }) => {
313
+ const normalizedCatalog = normalizeRuntimeLanguageCatalog(languageCatalog);
314
+ const langAPI = document.entityConfig?.i18nLangAPI;
315
+ if (!langAPI) {
316
+ return {
317
+ diagnostics: [
318
+ createI18nDiagnostic('missing-i18n-language-source', 'document.entityConfig.i18nLangAPI', '缺少显式语言源,已禁用 I18nEditor 的默认业务请求'),
319
+ ],
320
+ langAPI: false,
321
+ };
322
+ }
323
+ const normalizedSource = stringifyNormalizedJson(langAPI);
324
+ const catalogItem = normalizedCatalog.items.find(item => stringifyNormalizedJson(item.langAPI) === normalizedSource);
325
+ if (catalogItem) {
326
+ return {
327
+ catalogId: catalogItem.id,
328
+ diagnostics: [],
329
+ langAPI: cloneDeep(catalogItem.langAPI),
330
+ };
331
+ }
332
+ return {
333
+ diagnostics: [
334
+ createI18nDiagnostic('custom-i18n-language-source', 'document.entityConfig.i18nLangAPI', '当前语言源不在宿主目录中,将按自定义 JSON 无损保留'),
335
+ ],
336
+ langAPI: cloneDeep(langAPI),
337
+ };
338
+ };