@nocobase/plugin-flow-engine 2.1.0-alpha.12 → 2.1.0-alpha.13

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 (152) hide show
  1. package/dist/externalVersion.js +12 -11
  2. package/dist/node_modules/ajv/package.json +1 -1
  3. package/dist/node_modules/ses/package.json +1 -1
  4. package/dist/node_modules/zod/package.json +1 -1
  5. package/dist/server/flow-models/schema-contribution-collector.d.ts +2 -1
  6. package/dist/server/flow-models/schema-contribution-collector.js +26 -5
  7. package/dist/server/flow-schema-contributions/actions/aclCheck.d.ts +1 -1
  8. package/dist/server/flow-schema-contributions/actions/aclCheckRefresh.d.ts +1 -1
  9. package/dist/server/flow-schema-contributions/actions/actionLinkageRules.d.ts +1 -1
  10. package/dist/server/flow-schema-contributions/actions/confirm.d.ts +1 -1
  11. package/dist/server/flow-schema-contributions/actions/customVariable.d.ts +1 -1
  12. package/dist/server/flow-schema-contributions/actions/dataScope.d.ts +1 -1
  13. package/dist/server/flow-schema-contributions/actions/detailsFieldLinkageRules.d.ts +1 -1
  14. package/dist/server/flow-schema-contributions/actions/fieldLinkageRules.d.ts +1 -1
  15. package/dist/server/flow-schema-contributions/actions/filterFormDefaultValues.d.ts +1 -1
  16. package/dist/server/flow-schema-contributions/actions/formAssignRules.d.ts +1 -1
  17. package/dist/server/flow-schema-contributions/actions/index.d.ts +1 -1
  18. package/dist/server/flow-schema-contributions/actions/layout.d.ts +1 -1
  19. package/dist/server/flow-schema-contributions/actions/linkageRulesRefresh.d.ts +1 -1
  20. package/dist/server/flow-schema-contributions/actions/navigateToURL.d.ts +1 -1
  21. package/dist/server/flow-schema-contributions/actions/openView.d.ts +1 -1
  22. package/dist/server/flow-schema-contributions/actions/refreshTargetBlocks.d.ts +1 -1
  23. package/dist/server/flow-schema-contributions/actions/runjs.d.ts +1 -1
  24. package/dist/server/flow-schema-contributions/actions/setTargetDataScope.d.ts +1 -1
  25. package/dist/server/flow-schema-contributions/actions/showMessage.d.ts +1 -1
  26. package/dist/server/flow-schema-contributions/actions/showNotification.d.ts +1 -1
  27. package/dist/server/flow-schema-contributions/actions/sortingRule.d.ts +1 -1
  28. package/dist/server/flow-schema-contributions/field-models.d.ts +1 -1
  29. package/dist/server/flow-schema-contributions/index.d.ts +1 -1
  30. package/dist/server/flow-schema-contributions/models/ActionBulkEditModel.d.ts +10 -0
  31. package/dist/server/flow-schema-contributions/models/ActionBulkEditModel.js +382 -0
  32. package/dist/server/flow-schema-contributions/models/ActionBulkUpdateModel.d.ts +10 -0
  33. package/dist/server/flow-schema-contributions/models/ActionBulkUpdateModel.js +169 -0
  34. package/dist/server/flow-schema-contributions/models/ActionCustomRequestModel.d.ts +11 -0
  35. package/dist/server/flow-schema-contributions/models/ActionCustomRequestModel.js +115 -0
  36. package/dist/server/flow-schema-contributions/models/ActionDuplicateModel.d.ts +10 -0
  37. package/dist/server/flow-schema-contributions/models/ActionDuplicateModel.js +169 -0
  38. package/dist/server/flow-schema-contributions/models/ActionExportModel.d.ts +10 -0
  39. package/dist/server/flow-schema-contributions/models/ActionExportModel.js +141 -0
  40. package/dist/server/flow-schema-contributions/models/ActionImportModel.d.ts +10 -0
  41. package/dist/server/flow-schema-contributions/models/ActionImportModel.js +122 -0
  42. package/dist/server/flow-schema-contributions/models/ActionModel.d.ts +1 -1
  43. package/dist/server/flow-schema-contributions/models/AddChildActionModel.d.ts +1 -1
  44. package/dist/server/flow-schema-contributions/models/AddNewActionModel.d.ts +1 -1
  45. package/dist/server/flow-schema-contributions/models/AssignFormGridModel.d.ts +1 -1
  46. package/dist/server/flow-schema-contributions/models/AssignFormItemModel.d.ts +1 -1
  47. package/dist/server/flow-schema-contributions/models/AssignFormModel.d.ts +1 -1
  48. package/dist/server/flow-schema-contributions/models/BasePageTabModel.d.ts +1 -1
  49. package/dist/server/flow-schema-contributions/models/BlockGridCardModel.d.ts +10 -0
  50. package/dist/server/flow-schema-contributions/models/BlockGridCardModel.js +449 -0
  51. package/dist/server/flow-schema-contributions/models/BlockGridModel.d.ts +1 -1
  52. package/dist/server/flow-schema-contributions/models/BlockIframeModel.d.ts +10 -0
  53. package/dist/server/flow-schema-contributions/models/BlockIframeModel.js +143 -0
  54. package/dist/server/flow-schema-contributions/models/BlockListModel.d.ts +10 -0
  55. package/dist/server/flow-schema-contributions/models/BlockListModel.js +435 -0
  56. package/dist/server/flow-schema-contributions/models/BlockMarkdownModel.d.ts +10 -0
  57. package/dist/server/flow-schema-contributions/models/BlockMarkdownModel.js +108 -0
  58. package/dist/server/flow-schema-contributions/models/BlockWorkbenchModel.d.ts +10 -0
  59. package/dist/server/flow-schema-contributions/models/BlockWorkbenchModel.js +173 -0
  60. package/dist/server/flow-schema-contributions/models/BulkDeleteActionModel.d.ts +1 -1
  61. package/dist/server/flow-schema-contributions/models/ChildPageModel.d.ts +1 -1
  62. package/dist/server/flow-schema-contributions/models/ChildPageTabModel.d.ts +1 -1
  63. package/dist/server/flow-schema-contributions/models/CommentsModel.d.ts +10 -0
  64. package/dist/server/flow-schema-contributions/models/CommentsModel.js +255 -0
  65. package/dist/server/flow-schema-contributions/models/CreateFormModel.d.ts +1 -1
  66. package/dist/server/flow-schema-contributions/models/DataVisualizationModel.d.ts +10 -0
  67. package/dist/server/flow-schema-contributions/models/DataVisualizationModel.js +240 -0
  68. package/dist/server/flow-schema-contributions/models/DeleteActionModel.d.ts +1 -1
  69. package/dist/server/flow-schema-contributions/models/DetailsBlockModel.d.ts +1 -1
  70. package/dist/server/flow-schema-contributions/models/DetailsGridModel.d.ts +1 -1
  71. package/dist/server/flow-schema-contributions/models/DetailsItemModel.d.ts +1 -1
  72. package/dist/server/flow-schema-contributions/models/EditActionModel.d.ts +1 -1
  73. package/dist/server/flow-schema-contributions/models/EditFormModel.d.ts +1 -1
  74. package/dist/server/flow-schema-contributions/models/ExpandCollapseActionModel.d.ts +1 -1
  75. package/dist/server/flow-schema-contributions/models/FieldAttachmentUrlModel.d.ts +10 -0
  76. package/dist/server/flow-schema-contributions/models/FieldAttachmentUrlModel.js +87 -0
  77. package/dist/server/flow-schema-contributions/models/FieldCodeModel.d.ts +10 -0
  78. package/dist/server/flow-schema-contributions/models/FieldCodeModel.js +99 -0
  79. package/dist/server/flow-schema-contributions/models/FieldFormulaModel.d.ts +10 -0
  80. package/dist/server/flow-schema-contributions/models/FieldFormulaModel.js +152 -0
  81. package/dist/server/flow-schema-contributions/models/FieldMarkdownVditorModel.d.ts +10 -0
  82. package/dist/server/flow-schema-contributions/models/FieldMarkdownVditorModel.js +92 -0
  83. package/dist/server/flow-schema-contributions/models/FieldSequenceModel.d.ts +10 -0
  84. package/dist/server/flow-schema-contributions/models/FieldSequenceModel.js +60 -0
  85. package/dist/server/flow-schema-contributions/models/FieldSortModel.d.ts +10 -0
  86. package/dist/server/flow-schema-contributions/models/FieldSortModel.js +87 -0
  87. package/dist/server/flow-schema-contributions/models/FileManagerModel.d.ts +10 -0
  88. package/dist/server/flow-schema-contributions/models/FileManagerModel.js +115 -0
  89. package/dist/server/flow-schema-contributions/models/FilterActionModel.d.ts +1 -1
  90. package/dist/server/flow-schema-contributions/models/FilterFormBlockModel.d.ts +1 -1
  91. package/dist/server/flow-schema-contributions/models/FilterFormCollapseActionModel.d.ts +1 -1
  92. package/dist/server/flow-schema-contributions/models/FilterFormCustomFieldModel.d.ts +1 -1
  93. package/dist/server/flow-schema-contributions/models/FilterFormGridModel.d.ts +1 -1
  94. package/dist/server/flow-schema-contributions/models/FilterFormItemModel.d.ts +1 -1
  95. package/dist/server/flow-schema-contributions/models/FilterFormJSActionModel.d.ts +1 -1
  96. package/dist/server/flow-schema-contributions/models/FilterFormResetActionModel.d.ts +1 -1
  97. package/dist/server/flow-schema-contributions/models/FilterFormSubmitActionModel.d.ts +1 -1
  98. package/dist/server/flow-schema-contributions/models/FormAssociationItemModel.d.ts +1 -1
  99. package/dist/server/flow-schema-contributions/models/FormBlockModel.d.ts +1 -1
  100. package/dist/server/flow-schema-contributions/models/FormGridModel.d.ts +1 -1
  101. package/dist/server/flow-schema-contributions/models/FormItemModel.d.ts +1 -1
  102. package/dist/server/flow-schema-contributions/models/FormSubmitActionModel.d.ts +1 -1
  103. package/dist/server/flow-schema-contributions/models/JSActionModel.d.ts +1 -1
  104. package/dist/server/flow-schema-contributions/models/JSBlockModel.d.ts +1 -1
  105. package/dist/server/flow-schema-contributions/models/JSCollectionActionModel.d.ts +1 -1
  106. package/dist/server/flow-schema-contributions/models/JSColumnModel.d.ts +1 -1
  107. package/dist/server/flow-schema-contributions/models/JSFormActionModel.d.ts +1 -1
  108. package/dist/server/flow-schema-contributions/models/JSItemModel.d.ts +1 -1
  109. package/dist/server/flow-schema-contributions/models/JSRecordActionModel.d.ts +1 -1
  110. package/dist/server/flow-schema-contributions/models/LinkActionModel.d.ts +1 -1
  111. package/dist/server/flow-schema-contributions/models/MapModel.d.ts +10 -0
  112. package/dist/server/flow-schema-contributions/models/MapModel.js +427 -0
  113. package/dist/server/flow-schema-contributions/models/PageModel.d.ts +1 -1
  114. package/dist/server/flow-schema-contributions/models/PageTabModel.d.ts +1 -1
  115. package/dist/server/flow-schema-contributions/models/PopupActionModel.d.ts +1 -1
  116. package/dist/server/flow-schema-contributions/models/PopupCollectionActionModel.d.ts +1 -1
  117. package/dist/server/flow-schema-contributions/models/RefreshActionModel.d.ts +1 -1
  118. package/dist/server/flow-schema-contributions/models/RootPageModel.d.ts +1 -1
  119. package/dist/server/flow-schema-contributions/models/RootPageTabModel.d.ts +1 -1
  120. package/dist/server/flow-schema-contributions/models/RouteModel.d.ts +1 -1
  121. package/dist/server/flow-schema-contributions/models/TableActionsColumnModel.d.ts +1 -1
  122. package/dist/server/flow-schema-contributions/models/TableBlockModel.d.ts +1 -1
  123. package/dist/server/flow-schema-contributions/models/TableColumnModel.d.ts +1 -1
  124. package/dist/server/flow-schema-contributions/models/TableCustomColumnModel.d.ts +1 -1
  125. package/dist/server/flow-schema-contributions/models/UiTemplatesModel.d.ts +10 -0
  126. package/dist/server/flow-schema-contributions/models/UiTemplatesModel.js +130 -0
  127. package/dist/server/flow-schema-contributions/models/UpdateRecordActionModel.d.ts +1 -1
  128. package/dist/server/flow-schema-contributions/models/ViewActionModel.d.ts +1 -1
  129. package/dist/server/flow-schema-contributions/models/index.d.ts +6 -1
  130. package/dist/server/flow-schema-contributions/models/index.js +114 -0
  131. package/dist/server/flow-schema-contributions/shared.d.ts +1 -1
  132. package/dist/server/flow-schema-registry/FlowSchemaRegistry.d.ts +154 -0
  133. package/dist/server/flow-schema-registry/FlowSchemaRegistry.js +1424 -0
  134. package/dist/server/flow-schema-registry/flow-schema-registry/fieldBinding.d.ts +32 -0
  135. package/dist/server/flow-schema-registry/flow-schema-registry/fieldBinding.js +159 -0
  136. package/dist/server/flow-schema-registry/flow-schema-registry/modelPatches.d.ts +16 -0
  137. package/dist/server/flow-schema-registry/flow-schema-registry/modelPatches.js +226 -0
  138. package/dist/server/flow-schema-registry/flow-schema-registry/schemaInference.d.ts +17 -0
  139. package/dist/server/flow-schema-registry/flow-schema-registry/schemaInference.js +204 -0
  140. package/dist/server/flow-schema-registry/flow-schema-registry/utils.d.ts +25 -0
  141. package/dist/server/flow-schema-registry/flow-schema-registry/utils.js +278 -0
  142. package/dist/server/flow-schema-registry/index.d.ts +10 -0
  143. package/dist/server/flow-schema-registry/index.js +32 -0
  144. package/dist/server/flow-schema-registry/types.d.ts +244 -0
  145. package/dist/server/flow-schema-registry/types.js +24 -0
  146. package/dist/server/flow-schema-service.d.ts +1 -1
  147. package/dist/server/flow-schema-service.js +2 -2
  148. package/dist/server/plugin.d.ts +1 -1
  149. package/dist/server/repository.d.ts +1 -0
  150. package/dist/server/repository.js +3 -5
  151. package/dist/server/server.js +1 -1
  152. package/package.json +2 -2
@@ -0,0 +1,1424 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var FlowSchemaRegistry_exports = {};
38
+ __export(FlowSchemaRegistry_exports, {
39
+ FlowSchemaRegistry: () => FlowSchemaRegistry
40
+ });
41
+ module.exports = __toCommonJS(FlowSchemaRegistry_exports);
42
+ var import_lodash = __toESM(require("lodash"));
43
+ var import_fieldBinding = require("./flow-schema-registry/fieldBinding");
44
+ var import_modelPatches = require("./flow-schema-registry/modelPatches");
45
+ var import_schemaInference = require("./flow-schema-registry/schemaInference");
46
+ var import_utils = require("./flow-schema-registry/utils");
47
+ class FlowSchemaRegistry {
48
+ modelSchemas = /* @__PURE__ */ new Map();
49
+ actionSchemas = /* @__PURE__ */ new Map();
50
+ fieldBindingContexts = /* @__PURE__ */ new Map();
51
+ fieldBindings = /* @__PURE__ */ new Map();
52
+ resolvedModelCache = /* @__PURE__ */ new Map();
53
+ modelSnapshotSchemaCache = /* @__PURE__ */ new Map();
54
+ compactModelSnapshotSchemaCache = /* @__PURE__ */ new Map();
55
+ modelSchemaHashCache = /* @__PURE__ */ new Map();
56
+ compactModelSchemaHashCache = /* @__PURE__ */ new Map();
57
+ modelDocumentCache = /* @__PURE__ */ new Map();
58
+ modelLocalDynamicHintsCache = /* @__PURE__ */ new Map();
59
+ publicModelDocumentCache = /* @__PURE__ */ new Map();
60
+ publicTreeRoots = /* @__PURE__ */ new Set();
61
+ slotUseExpansions = /* @__PURE__ */ new Map();
62
+ invalidateDerivedCaches() {
63
+ this.resolvedModelCache.clear();
64
+ this.modelSnapshotSchemaCache.clear();
65
+ this.compactModelSnapshotSchemaCache.clear();
66
+ this.modelSchemaHashCache.clear();
67
+ this.compactModelSchemaHashCache.clear();
68
+ this.modelDocumentCache.clear();
69
+ this.modelLocalDynamicHintsCache.clear();
70
+ this.publicModelDocumentCache.clear();
71
+ }
72
+ registerAction(action) {
73
+ var _a, _b, _c, _d;
74
+ const name = String((action == null ? void 0 : action.name) || "").trim();
75
+ if (!name) return;
76
+ const previous = this.actionSchemas.get(name);
77
+ const inferred = (0, import_schemaInference.inferParamsSchemaFromUiSchema)(name, action.uiSchema, `actions.${name}`);
78
+ const mergedSchema = (0, import_utils.mergeSchemas)(action.paramsSchema || inferred.schema, action.paramsSchemaPatch);
79
+ const explicit = !!action.paramsSchema || !!action.paramsSchemaPatch;
80
+ const coverageStatus = explicit ? inferred.schema ? "mixed" : "manual" : inferred.coverage;
81
+ const docs = (0, import_utils.normalizeSchemaDocs)({
82
+ ...previous == null ? void 0 : previous.docs,
83
+ ...action.schemaDocs,
84
+ examples: ((_a = action.schemaDocs) == null ? void 0 : _a.examples) || ((_b = previous == null ? void 0 : previous.docs) == null ? void 0 : _b.examples),
85
+ dynamicHints: [...((_c = previous == null ? void 0 : previous.docs) == null ? void 0 : _c.dynamicHints) || [], ...((_d = action.schemaDocs) == null ? void 0 : _d.dynamicHints) || []]
86
+ });
87
+ this.actionSchemas.set(name, {
88
+ name,
89
+ title: action.title,
90
+ definition: action,
91
+ schema: mergedSchema,
92
+ coverage: {
93
+ status: mergedSchema ? coverageStatus : "unresolved",
94
+ source: (previous == null ? void 0 : previous.coverage.source) || "official",
95
+ strict: previous == null ? void 0 : previous.coverage.strict
96
+ },
97
+ docs,
98
+ dynamicHints: (0, import_utils.normalizeSchemaHints)([
99
+ ...(previous == null ? void 0 : previous.dynamicHints) || [],
100
+ ...inferred.hints || [],
101
+ ...docs.dynamicHints || []
102
+ ])
103
+ });
104
+ this.invalidateDerivedCaches();
105
+ }
106
+ registerActions(actions) {
107
+ for (const action of Object.values(actions || {})) {
108
+ this.registerAction(action);
109
+ }
110
+ }
111
+ registerActionContribution(contribution) {
112
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
113
+ const name = String((contribution == null ? void 0 : contribution.name) || "").trim();
114
+ if (!name) return;
115
+ const previous = this.actionSchemas.get(name);
116
+ const docs = (0, import_utils.normalizeSchemaDocs)({
117
+ ...previous == null ? void 0 : previous.docs,
118
+ ...contribution.docs,
119
+ examples: ((_a = contribution.docs) == null ? void 0 : _a.examples) || ((_b = previous == null ? void 0 : previous.docs) == null ? void 0 : _b.examples),
120
+ dynamicHints: [...((_c = previous == null ? void 0 : previous.docs) == null ? void 0 : _c.dynamicHints) || [], ...((_d = contribution.docs) == null ? void 0 : _d.dynamicHints) || []],
121
+ commonPatterns: ((_e = contribution.docs) == null ? void 0 : _e.commonPatterns) || ((_f = previous == null ? void 0 : previous.docs) == null ? void 0 : _f.commonPatterns),
122
+ antiPatterns: ((_g = contribution.docs) == null ? void 0 : _g.antiPatterns) || ((_h = previous == null ? void 0 : previous.docs) == null ? void 0 : _h.antiPatterns),
123
+ minimalExample: ((_i = contribution.docs) == null ? void 0 : _i.minimalExample) !== void 0 ? contribution.docs.minimalExample : (_j = previous == null ? void 0 : previous.docs) == null ? void 0 : _j.minimalExample
124
+ });
125
+ this.actionSchemas.set(name, {
126
+ name,
127
+ title: contribution.title || (previous == null ? void 0 : previous.title),
128
+ definition: previous == null ? void 0 : previous.definition,
129
+ schema: contribution.paramsSchema ? import_lodash.default.cloneDeep(contribution.paramsSchema) : previous == null ? void 0 : previous.schema,
130
+ docs,
131
+ coverage: {
132
+ status: contribution.paramsSchema ? "manual" : (previous == null ? void 0 : previous.coverage.status) || "unresolved",
133
+ source: contribution.source || (previous == null ? void 0 : previous.coverage.source) || "official",
134
+ strict: contribution.strict ?? (previous == null ? void 0 : previous.coverage.strict)
135
+ },
136
+ dynamicHints: (0, import_utils.normalizeSchemaHints)([...(previous == null ? void 0 : previous.dynamicHints) || [], ...docs.dynamicHints || []])
137
+ });
138
+ this.invalidateDerivedCaches();
139
+ }
140
+ registerActionContributions(contributions) {
141
+ const values = Array.isArray(contributions) ? contributions : Object.values(contributions || {});
142
+ for (const contribution of values) {
143
+ this.registerActionContribution(contribution);
144
+ }
145
+ }
146
+ registerFieldBindingContext(contribution, fallbackName) {
147
+ const normalized = (0, import_fieldBinding.normalizeFieldBindingContextContribution)(contribution, fallbackName);
148
+ if (!normalized) {
149
+ return;
150
+ }
151
+ const previous = this.fieldBindingContexts.get(normalized.name);
152
+ this.fieldBindingContexts.set(normalized.name, {
153
+ name: normalized.name,
154
+ inherits: import_lodash.default.uniq([...(previous == null ? void 0 : previous.inherits) || [], ...normalized.inherits])
155
+ });
156
+ this.invalidateDerivedCaches();
157
+ }
158
+ registerFieldBindingContexts(contributions) {
159
+ if (!contributions) {
160
+ return;
161
+ }
162
+ if (Array.isArray(contributions)) {
163
+ for (const contribution of contributions) {
164
+ this.registerFieldBindingContext(contribution);
165
+ }
166
+ return;
167
+ }
168
+ for (const [name, contribution] of Object.entries(contributions)) {
169
+ if (!contribution) {
170
+ continue;
171
+ }
172
+ this.registerFieldBindingContext(contribution, name);
173
+ }
174
+ }
175
+ registerFieldBinding(contribution, source = "official") {
176
+ const normalized = (0, import_fieldBinding.normalizeFieldBindingContribution)(contribution, source);
177
+ if (!normalized) {
178
+ return;
179
+ }
180
+ const bindings = this.fieldBindings.get(normalized.context) || [];
181
+ bindings.push(normalized);
182
+ this.fieldBindings.set(normalized.context, bindings);
183
+ this.invalidateDerivedCaches();
184
+ }
185
+ registerFieldBindings(contributions, source = "official") {
186
+ if (!contributions) {
187
+ return;
188
+ }
189
+ if (Array.isArray(contributions)) {
190
+ for (const contribution of contributions) {
191
+ this.registerFieldBinding(contribution, source);
192
+ }
193
+ return;
194
+ }
195
+ for (const [context, contribution] of Object.entries(contributions)) {
196
+ if (!contribution) {
197
+ continue;
198
+ }
199
+ const items = Array.isArray(contribution) ? contribution : [contribution];
200
+ for (const item of items) {
201
+ this.registerFieldBinding(
202
+ {
203
+ ...item,
204
+ context: item.context || context
205
+ },
206
+ source
207
+ );
208
+ }
209
+ }
210
+ }
211
+ registerModel(use, options) {
212
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
213
+ const name = String(use || "").trim();
214
+ if (!name) return;
215
+ const previous = this.modelSchemas.get(name);
216
+ this.modelSchemas.set(name, {
217
+ use: name,
218
+ title: options.title || (previous == null ? void 0 : previous.title),
219
+ modelClass: options.modelClass || (previous == null ? void 0 : previous.modelClass),
220
+ stepParamsSchema: options.stepParamsSchema || (previous == null ? void 0 : previous.stepParamsSchema),
221
+ flowRegistrySchema: options.flowRegistrySchema || (previous == null ? void 0 : previous.flowRegistrySchema),
222
+ subModelSlots: (0, import_modelPatches.normalizeSubModelSlots)(options.subModelSlots || (previous == null ? void 0 : previous.subModelSlots)),
223
+ flowRegistrySchemaPatch: options.flowRegistrySchemaPatch || (previous == null ? void 0 : previous.flowRegistrySchemaPatch),
224
+ examples: options.examples || (previous == null ? void 0 : previous.examples) || [],
225
+ docs: (0, import_utils.normalizeSchemaDocs)({
226
+ ...previous == null ? void 0 : previous.docs,
227
+ ...options.docs,
228
+ examples: ((_a = options.docs) == null ? void 0 : _a.examples) || ((_b = previous == null ? void 0 : previous.docs) == null ? void 0 : _b.examples),
229
+ dynamicHints: [...((_c = previous == null ? void 0 : previous.docs) == null ? void 0 : _c.dynamicHints) || [], ...((_d = options.docs) == null ? void 0 : _d.dynamicHints) || []],
230
+ commonPatterns: ((_e = options.docs) == null ? void 0 : _e.commonPatterns) || ((_f = previous == null ? void 0 : previous.docs) == null ? void 0 : _f.commonPatterns),
231
+ antiPatterns: ((_g = options.docs) == null ? void 0 : _g.antiPatterns) || ((_h = previous == null ? void 0 : previous.docs) == null ? void 0 : _h.antiPatterns),
232
+ minimalExample: ((_i = options.docs) == null ? void 0 : _i.minimalExample) !== void 0 ? options.docs.minimalExample : (_j = previous == null ? void 0 : previous.docs) == null ? void 0 : _j.minimalExample
233
+ }),
234
+ skeleton: options.skeleton !== void 0 ? import_lodash.default.cloneDeep(options.skeleton) : previous == null ? void 0 : previous.skeleton,
235
+ dynamicHints: (0, import_utils.normalizeSchemaHints)([...(previous == null ? void 0 : previous.dynamicHints) || [], ...options.dynamicHints || []]),
236
+ coverage: options.coverage || (previous == null ? void 0 : previous.coverage) || { status: "unresolved", source: "third-party" },
237
+ exposure: options.exposure ?? (previous == null ? void 0 : previous.exposure) ?? "public",
238
+ abstract: options.abstract ?? (previous == null ? void 0 : previous.abstract) ?? false,
239
+ allowDirectUse: options.allowDirectUse ?? (previous == null ? void 0 : previous.allowDirectUse) ?? true,
240
+ suggestedUses: (0, import_utils.normalizeStringArray)(options.suggestedUses || (previous == null ? void 0 : previous.suggestedUses))
241
+ });
242
+ this.invalidateDerivedCaches();
243
+ }
244
+ registerModelContribution(contribution) {
245
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
246
+ const use = String((contribution == null ? void 0 : contribution.use) || "").trim();
247
+ if (!use) return;
248
+ const previous = this.modelSchemas.get(use);
249
+ const hasSchemaContribution = !!contribution.stepParamsSchema || !!contribution.flowRegistrySchema || !!contribution.flowRegistrySchemaPatch || !!contribution.subModelSlots;
250
+ const docs = (0, import_utils.normalizeSchemaDocs)({
251
+ ...previous == null ? void 0 : previous.docs,
252
+ ...contribution.docs,
253
+ examples: contribution.examples || ((_a = contribution.docs) == null ? void 0 : _a.examples) || ((_b = previous == null ? void 0 : previous.docs) == null ? void 0 : _b.examples),
254
+ dynamicHints: [...((_c = previous == null ? void 0 : previous.docs) == null ? void 0 : _c.dynamicHints) || [], ...((_d = contribution.docs) == null ? void 0 : _d.dynamicHints) || []],
255
+ commonPatterns: ((_e = contribution.docs) == null ? void 0 : _e.commonPatterns) || ((_f = previous == null ? void 0 : previous.docs) == null ? void 0 : _f.commonPatterns),
256
+ antiPatterns: ((_g = contribution.docs) == null ? void 0 : _g.antiPatterns) || ((_h = previous == null ? void 0 : previous.docs) == null ? void 0 : _h.antiPatterns),
257
+ minimalExample: ((_i = contribution.docs) == null ? void 0 : _i.minimalExample) !== void 0 ? contribution.docs.minimalExample : (_j = previous == null ? void 0 : previous.docs) == null ? void 0 : _j.minimalExample
258
+ });
259
+ this.registerModel(use, {
260
+ title: contribution.title,
261
+ stepParamsSchema: contribution.stepParamsSchema ? import_lodash.default.cloneDeep(contribution.stepParamsSchema) : void 0,
262
+ flowRegistrySchema: contribution.flowRegistrySchema ? import_lodash.default.cloneDeep(contribution.flowRegistrySchema) : void 0,
263
+ subModelSlots: contribution.subModelSlots ? (0, import_modelPatches.normalizeSubModelSlots)(contribution.subModelSlots) : void 0,
264
+ flowRegistrySchemaPatch: contribution.flowRegistrySchemaPatch ? import_lodash.default.cloneDeep(contribution.flowRegistrySchemaPatch) : void 0,
265
+ examples: contribution.examples || docs.examples || [],
266
+ docs,
267
+ skeleton: contribution.skeleton,
268
+ dynamicHints: [...contribution.dynamicHints || [], ...docs.dynamicHints || []],
269
+ coverage: hasSchemaContribution ? {
270
+ status: (previous == null ? void 0 : previous.coverage.status) === "auto" ? "mixed" : "manual",
271
+ source: contribution.source || (previous == null ? void 0 : previous.coverage.source) || "official",
272
+ strict: contribution.strict ?? (previous == null ? void 0 : previous.coverage.strict)
273
+ } : (previous == null ? void 0 : previous.coverage) || {
274
+ status: "unresolved",
275
+ source: contribution.source || "official",
276
+ strict: contribution.strict
277
+ },
278
+ exposure: contribution.exposure,
279
+ abstract: contribution.abstract,
280
+ allowDirectUse: contribution.allowDirectUse,
281
+ suggestedUses: contribution.suggestedUses
282
+ });
283
+ }
284
+ registerModelContributions(contributions) {
285
+ const values = Array.isArray(contributions) ? contributions : Object.values(contributions || {});
286
+ for (const contribution of values) {
287
+ this.registerModelContribution(contribution);
288
+ }
289
+ }
290
+ registerModelClass(use, modelClass) {
291
+ var _a, _b;
292
+ const meta = modelClass.meta || {};
293
+ const schemaMeta = meta.schema || {};
294
+ const inferredSlots = this.inferSubModelSlotsFromModelClass(use, modelClass);
295
+ const inferredHints = this.collectModelDynamicHints(use, modelClass, meta);
296
+ const hasManual = !!schemaMeta.stepParamsSchema || !!schemaMeta.flowRegistrySchema || !!schemaMeta.subModelSlots || !!schemaMeta.flowRegistrySchemaPatch;
297
+ const hasAuto = !!Object.keys(inferredSlots).length;
298
+ this.registerModel(use, {
299
+ modelClass,
300
+ title: (0, import_utils.toSchemaTitle)(meta.label, use),
301
+ stepParamsSchema: schemaMeta.stepParamsSchema,
302
+ flowRegistrySchema: schemaMeta.flowRegistrySchema,
303
+ subModelSlots: Object.keys(schemaMeta.subModelSlots || {}).length ? schemaMeta.subModelSlots : inferredSlots,
304
+ flowRegistrySchemaPatch: schemaMeta.flowRegistrySchemaPatch,
305
+ examples: schemaMeta.examples || ((_a = schemaMeta.docs) == null ? void 0 : _a.examples) || [],
306
+ docs: schemaMeta.docs,
307
+ skeleton: schemaMeta.skeleton,
308
+ dynamicHints: [...schemaMeta.dynamicHints || [], ...((_b = schemaMeta.docs) == null ? void 0 : _b.dynamicHints) || [], ...inferredHints],
309
+ coverage: {
310
+ status: hasManual && hasAuto ? "mixed" : hasManual ? "manual" : hasAuto ? "auto" : "unresolved",
311
+ source: schemaMeta.source || "official",
312
+ strict: schemaMeta.strict
313
+ },
314
+ exposure: schemaMeta.exposure,
315
+ abstract: schemaMeta.abstract,
316
+ allowDirectUse: schemaMeta.allowDirectUse,
317
+ suggestedUses: schemaMeta.suggestedUses
318
+ });
319
+ }
320
+ registerModels(models) {
321
+ for (const [use, modelClass] of Object.entries(models || {})) {
322
+ if (modelClass) {
323
+ this.registerModelClass(use, modelClass);
324
+ }
325
+ }
326
+ }
327
+ registerInventory(inventory, _source) {
328
+ if (!inventory) {
329
+ return;
330
+ }
331
+ for (const use of (0, import_utils.normalizeStringArray)(inventory.publicTreeRoots)) {
332
+ this.publicTreeRoots.add(use);
333
+ }
334
+ for (const item of inventory.slotUseExpansions || []) {
335
+ const parentUse = String((item == null ? void 0 : item.parentUse) || "").trim();
336
+ const slotKey = String((item == null ? void 0 : item.slotKey) || "").trim();
337
+ const uses = (0, import_utils.normalizeStringArray)(item == null ? void 0 : item.uses);
338
+ if (!parentUse || !slotKey || uses.length === 0) {
339
+ continue;
340
+ }
341
+ const key = this.createSlotUseExpansionKey(parentUse, slotKey);
342
+ this.slotUseExpansions.set(key, import_lodash.default.uniq([...this.slotUseExpansions.get(key) || [], ...uses]));
343
+ }
344
+ this.invalidateDerivedCaches();
345
+ }
346
+ resolveFieldBindingCandidates(context, options = {}) {
347
+ const contextChain = this.resolveFieldBindingContextChain(context);
348
+ const entries = contextChain.flatMap(
349
+ (contextName, contextIndex) => (this.fieldBindings.get(contextName) || []).map((binding, bindingIndex) => ({
350
+ binding,
351
+ contextIndex,
352
+ bindingIndex
353
+ }))
354
+ );
355
+ const candidates = entries.filter(({ binding }) => (0, import_fieldBinding.matchesFieldBinding)(binding, options)).filter(({ binding }) => this.hasQueryableModel(binding.use)).sort((a, b) => {
356
+ if (a.binding.isDefault !== b.binding.isDefault) {
357
+ return a.binding.isDefault ? -1 : 1;
358
+ }
359
+ const aOrder = typeof a.binding.order === "number" ? a.binding.order : Number.MAX_SAFE_INTEGER;
360
+ const bOrder = typeof b.binding.order === "number" ? b.binding.order : Number.MAX_SAFE_INTEGER;
361
+ if (aOrder !== bOrder) {
362
+ return aOrder - bOrder;
363
+ }
364
+ if (a.contextIndex !== b.contextIndex) {
365
+ return a.contextIndex - b.contextIndex;
366
+ }
367
+ return a.bindingIndex - b.bindingIndex;
368
+ }).map(({ binding }) => ({
369
+ use: binding.use,
370
+ defaultProps: binding.defaultProps === void 0 ? void 0 : import_lodash.default.cloneDeep(binding.defaultProps),
371
+ compatibility: (0, import_fieldBinding.buildFieldModelCompatibility)(binding)
372
+ }));
373
+ return import_lodash.default.uniqBy(candidates, (candidate) => `${candidate.use}:${(0, import_utils.stableStringify)(candidate.compatibility)}`);
374
+ }
375
+ getAction(name) {
376
+ return this.actionSchemas.get(name);
377
+ }
378
+ listActionNames() {
379
+ return Array.from(this.actionSchemas.keys()).sort();
380
+ }
381
+ getModel(use) {
382
+ return this.modelSchemas.get(use);
383
+ }
384
+ resolveFieldBindingContextChain(context, visited = /* @__PURE__ */ new Set()) {
385
+ var _a;
386
+ const name = String(context || "").trim();
387
+ if (!name || visited.has(name)) {
388
+ return [];
389
+ }
390
+ visited.add(name);
391
+ const chain = [name];
392
+ const inherits = ((_a = this.fieldBindingContexts.get(name)) == null ? void 0 : _a.inherits) || [];
393
+ for (const inheritedContext of inherits) {
394
+ for (const item of this.resolveFieldBindingContextChain(inheritedContext, visited)) {
395
+ if (!chain.includes(item)) {
396
+ chain.push(item);
397
+ }
398
+ }
399
+ }
400
+ return chain;
401
+ }
402
+ resolveModelSchemaRef(use, contextChain = []) {
403
+ const name = String(use || "").trim();
404
+ const cacheKey = `${name}::${(0, import_utils.stableStringify)(contextChain)}`;
405
+ const cached = this.resolvedModelCache.get(cacheKey);
406
+ if (cached) {
407
+ return cached;
408
+ }
409
+ const registered = this.modelSchemas.get(name);
410
+ const resolved = {
411
+ use: name,
412
+ title: (registered == null ? void 0 : registered.title) || name,
413
+ modelClass: registered == null ? void 0 : registered.modelClass,
414
+ stepParamsSchema: (registered == null ? void 0 : registered.stepParamsSchema) ? import_lodash.default.cloneDeep(registered.stepParamsSchema) : this.buildInferredStepParamsSchema(name),
415
+ flowRegistrySchema: (registered == null ? void 0 : registered.flowRegistrySchema) ? import_lodash.default.cloneDeep(registered.flowRegistrySchema) : this.buildInferredFlowRegistrySchema(name),
416
+ subModelSlots: (0, import_modelPatches.normalizeSubModelSlots)(registered == null ? void 0 : registered.subModelSlots),
417
+ flowRegistrySchemaPatch: (registered == null ? void 0 : registered.flowRegistrySchemaPatch) ? import_lodash.default.cloneDeep(registered.flowRegistrySchemaPatch) : void 0,
418
+ examples: import_lodash.default.cloneDeep((registered == null ? void 0 : registered.examples) || []),
419
+ docs: (0, import_utils.normalizeSchemaDocs)(registered == null ? void 0 : registered.docs),
420
+ skeleton: (registered == null ? void 0 : registered.skeleton) === void 0 ? void 0 : import_lodash.default.cloneDeep(registered.skeleton),
421
+ dynamicHints: (0, import_utils.normalizeSchemaHints)(registered == null ? void 0 : registered.dynamicHints),
422
+ coverage: (registered == null ? void 0 : registered.coverage) || { status: "unresolved", source: "third-party" },
423
+ exposure: (registered == null ? void 0 : registered.exposure) || "public",
424
+ abstract: (registered == null ? void 0 : registered.abstract) ?? false,
425
+ allowDirectUse: (registered == null ? void 0 : registered.allowDirectUse) ?? true,
426
+ suggestedUses: (0, import_utils.normalizeStringArray)(registered == null ? void 0 : registered.suggestedUses)
427
+ };
428
+ for (const contribution of this.collectContextPatches(name, contextChain)) {
429
+ (0, import_modelPatches.applyModelSchemaPatch)(resolved, contribution.patch, contribution.source, contribution.strict);
430
+ }
431
+ const frozen = (0, import_utils.deepFreezePlainGraph)(resolved);
432
+ this.resolvedModelCache.set(cacheKey, frozen);
433
+ return frozen;
434
+ }
435
+ resolveModelSchema(use, contextChain = []) {
436
+ return import_lodash.default.cloneDeep(this.resolveModelSchemaRef(use, contextChain));
437
+ }
438
+ isPublicModel(model) {
439
+ return ((model == null ? void 0 : model.exposure) || "public") === "public";
440
+ }
441
+ isQueryableModel(model) {
442
+ return !!model && model.abstract !== true;
443
+ }
444
+ getSuggestedUses(use) {
445
+ var _a;
446
+ const model = this.modelSchemas.get(String(use || "").trim());
447
+ if ((_a = model == null ? void 0 : model.suggestedUses) == null ? void 0 : _a.length) {
448
+ return (0, import_utils.normalizeStringArray)(model.suggestedUses);
449
+ }
450
+ return this.listModelUses({ directUseOnly: true }).filter((item) => item !== use).slice(0, 20);
451
+ }
452
+ hasQueryableModel(use) {
453
+ const model = this.modelSchemas.get(String(use || "").trim());
454
+ return this.isQueryableModel(model);
455
+ }
456
+ isDirectUseAllowed(use) {
457
+ const model = this.modelSchemas.get(String(use || "").trim());
458
+ return model ? this.isQueryableModel(model) && model.allowDirectUse !== false : true;
459
+ }
460
+ listPublicTreeRoots() {
461
+ return Array.from(this.publicTreeRoots).sort();
462
+ }
463
+ listModelUses(options = {}) {
464
+ const { publicOnly = false, directUseOnly = false, queryableOnly = false } = options;
465
+ return Array.from(this.modelSchemas.values()).filter((model) => !publicOnly || this.isPublicModel(model) && this.isQueryableModel(model)).filter((model) => !queryableOnly || this.isQueryableModel(model)).filter((model) => !directUseOnly || this.isQueryableModel(model) && model.allowDirectUse !== false).map((model) => model.use).sort();
466
+ }
467
+ getSchemaBundle(uses) {
468
+ return {
469
+ items: (Array.isArray(uses) && uses.length > 0 ? uses.filter((use) => this.hasQueryableModel(use)) : []).map(
470
+ (use) => this.buildBundleNode(use, [], /* @__PURE__ */ new Set())
471
+ )
472
+ };
473
+ }
474
+ getModelDocument(use, contextChain = []) {
475
+ return import_lodash.default.cloneDeep(this.getModelDocumentRef(use, contextChain));
476
+ }
477
+ getModelDocumentRef(use, contextChain = []) {
478
+ const cacheKey = this.createContextVisitKey(use, contextChain);
479
+ const cached = this.modelDocumentCache.get(cacheKey);
480
+ if (cached) {
481
+ return cached;
482
+ }
483
+ const document = this.buildModelDocument(use, contextChain, /* @__PURE__ */ new Set());
484
+ const frozen = (0, import_utils.deepFreezePlainGraph)(document);
485
+ this.modelDocumentCache.set(cacheKey, frozen);
486
+ return frozen;
487
+ }
488
+ getPublicModelDocument(use, options = {}) {
489
+ return import_lodash.default.cloneDeep(this.getPublicModelDocumentRef(use, options));
490
+ }
491
+ getPublicModelDocumentRef(use, options = {}) {
492
+ const detail = options.detail === "full" ? "full" : "compact";
493
+ const contextChain = options.contextChain || [];
494
+ const cacheKey = `${detail}::${this.createContextVisitKey(use, contextChain)}`;
495
+ const cached = this.publicModelDocumentCache.get(cacheKey);
496
+ if (cached) {
497
+ return cached;
498
+ }
499
+ const document = detail === "full" ? this.buildFullPublicModelDocument(use, contextChain) : this.buildCompactPublicModelDocument(use, contextChain);
500
+ const frozen = (0, import_utils.deepFreezePlainGraph)(document);
501
+ this.publicModelDocumentCache.set(cacheKey, frozen);
502
+ return frozen;
503
+ }
504
+ buildFullPublicModelDocument(use, contextChain) {
505
+ const document = this.getModelDocumentRef(use, contextChain);
506
+ return {
507
+ use: document.use,
508
+ title: document.title,
509
+ jsonSchema: document.jsonSchema,
510
+ dynamicHints: document.dynamicHints,
511
+ minimalExample: document.minimalExample,
512
+ commonPatterns: document.commonPatterns,
513
+ antiPatterns: document.antiPatterns,
514
+ hash: document.hash,
515
+ source: document.source
516
+ };
517
+ }
518
+ buildCompactPublicModelDocument(use, contextChain) {
519
+ var _a, _b, _c, _d;
520
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
521
+ const jsonSchema = this.buildCompactModelSnapshotSchemaRef(use, contextChain);
522
+ const minimalExample = import_lodash.default.cloneDeep(
523
+ ((_a = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _a.minimalExample) ?? ((_b = resolved == null ? void 0 : resolved.examples) == null ? void 0 : _b[0]) ?? (resolved == null ? void 0 : resolved.skeleton) ?? (0, import_utils.buildSkeletonFromSchema)(jsonSchema)
524
+ );
525
+ return {
526
+ use,
527
+ title: (resolved == null ? void 0 : resolved.title) || use,
528
+ jsonSchema,
529
+ dynamicHints: [...this.getModelLocalDynamicHintsRef(use, contextChain)],
530
+ minimalExample,
531
+ commonPatterns: import_lodash.default.cloneDeep(((_c = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _c.commonPatterns) || []),
532
+ antiPatterns: import_lodash.default.cloneDeep(((_d = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _d.antiPatterns) || []),
533
+ hash: this.getCompactModelSchemaHash(use, contextChain),
534
+ source: ((resolved == null ? void 0 : resolved.coverage) || { source: "third-party" }).source
535
+ };
536
+ }
537
+ getModelLocalDynamicHintsRef(use, contextChain = []) {
538
+ const cacheKey = this.createContextVisitKey(use, contextChain);
539
+ const cached = this.modelLocalDynamicHintsCache.get(cacheKey);
540
+ if (cached) {
541
+ return cached;
542
+ }
543
+ const hints = this.buildModelLocalDynamicHints(use, contextChain);
544
+ const frozen = (0, import_utils.deepFreezePlainGraph)(hints);
545
+ this.modelLocalDynamicHintsCache.set(cacheKey, frozen);
546
+ return frozen;
547
+ }
548
+ buildModelLocalDynamicHints(use, contextChain) {
549
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
550
+ const baseCoverage = resolved.coverage || { status: "unresolved", source: "third-party" };
551
+ const flowDiagnostics = this.collectFlowSchemaDiagnostics(use);
552
+ const slotHints = Object.entries((resolved == null ? void 0 : resolved.subModelSlots) || {}).map(([slotKey, slot]) => {
553
+ const allowedUses = this.resolveSlotAllowedUses(use, slotKey, slot);
554
+ return (0, import_utils.createFlowHint)(
555
+ {
556
+ kind: slot.dynamic || slot.fieldBindingContext ? "dynamic-children" : "manual-schema-required",
557
+ path: `${use}.subModels.${slotKey}`,
558
+ message: slot.description || `${use}.subModels.${slotKey} accepts ${slot.type}${allowedUses.length ? `: ${allowedUses.join(", ")}` : ""}.`
559
+ },
560
+ {
561
+ slotRules: {
562
+ slotKey,
563
+ type: slot.type,
564
+ allowedUses
565
+ }
566
+ }
567
+ );
568
+ });
569
+ const coverage = this.buildDocumentCoverage(baseCoverage, flowDiagnostics.statuses);
570
+ return (0, import_utils.normalizeSchemaHints)([
571
+ ...(resolved == null ? void 0 : resolved.dynamicHints) || [],
572
+ ...slotHints,
573
+ ...flowDiagnostics.hints,
574
+ ...coverage.status === "unresolved" ? [
575
+ (0, import_utils.createFlowHint)(
576
+ {
577
+ kind: "unresolved-model",
578
+ path: use,
579
+ message: `${use} has no registered server-safe schema contribution yet.`
580
+ },
581
+ {
582
+ unresolvedReason: "missing-model-contribution",
583
+ recommendedFallback: { use }
584
+ }
585
+ )
586
+ ] : []
587
+ ]);
588
+ }
589
+ getModelSchemaHash(use, contextChain = []) {
590
+ const cacheKey = this.createContextVisitKey(use, contextChain);
591
+ const cached = this.modelSchemaHashCache.get(cacheKey);
592
+ if (cached) {
593
+ return cached;
594
+ }
595
+ const hash = (0, import_utils.hashString)((0, import_utils.stableStringify)(this.buildModelSnapshotSchemaRef(use, contextChain)));
596
+ this.modelSchemaHashCache.set(cacheKey, hash);
597
+ return hash;
598
+ }
599
+ getCompactModelSchemaHash(use, contextChain = []) {
600
+ const cacheKey = this.createContextVisitKey(use, contextChain);
601
+ const cached = this.compactModelSchemaHashCache.get(cacheKey);
602
+ if (cached) {
603
+ return cached;
604
+ }
605
+ const hash = (0, import_utils.hashString)((0, import_utils.stableStringify)(this.buildCompactModelSnapshotSchemaRef(use, contextChain)));
606
+ this.compactModelSchemaHashCache.set(cacheKey, hash);
607
+ return hash;
608
+ }
609
+ createSlotUseExpansionKey(parentUse, slotKey) {
610
+ return `${parentUse}::${slotKey}`;
611
+ }
612
+ getSlotUseExpansionUses(parentUse, slotKey) {
613
+ return this.slotUseExpansions.get(this.createSlotUseExpansionKey(parentUse, slotKey)) || [];
614
+ }
615
+ resolveSlotAllowedUses(parentUse, slotKey, slot) {
616
+ if (!slot) {
617
+ return [];
618
+ }
619
+ if (slot.fieldBindingContext) {
620
+ return import_lodash.default.uniq(this.resolveFieldBindingCandidates(slot.fieldBindingContext).map((candidate) => candidate.use));
621
+ }
622
+ return import_lodash.default.uniq([...(0, import_utils.collectAllowedUses)(slot), ...this.getSlotUseExpansionUses(parentUse, slotKey)]);
623
+ }
624
+ buildModelDocument(use, contextChain, visited) {
625
+ var _a, _b, _c, _d;
626
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
627
+ const baseCoverage = resolved.coverage || { status: "unresolved", source: "third-party" };
628
+ const flowDiagnostics = this.collectFlowSchemaDiagnostics(use);
629
+ const coverage = this.buildDocumentCoverage(baseCoverage, flowDiagnostics.statuses);
630
+ const dynamicHints = (0, import_utils.normalizeSchemaHints)([
631
+ ...this.getModelLocalDynamicHintsRef(use, contextChain),
632
+ ...this.collectNestedDocumentHints(use, contextChain, visited)
633
+ ]);
634
+ const jsonSchema = this.buildModelSnapshotSchemaRef(use, contextChain);
635
+ const skeleton = import_lodash.default.cloneDeep((resolved == null ? void 0 : resolved.skeleton) ?? (0, import_utils.buildSkeletonFromSchema)(jsonSchema));
636
+ const minimalExample = import_lodash.default.cloneDeep(((_a = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _a.minimalExample) ?? ((_b = resolved == null ? void 0 : resolved.examples) == null ? void 0 : _b[0]) ?? skeleton);
637
+ const hash = this.getModelSchemaHash(use, contextChain);
638
+ return {
639
+ use,
640
+ title: (resolved == null ? void 0 : resolved.title) || use,
641
+ jsonSchema,
642
+ coverage,
643
+ dynamicHints,
644
+ examples: (resolved == null ? void 0 : resolved.examples) || [],
645
+ minimalExample,
646
+ commonPatterns: import_lodash.default.cloneDeep(((_c = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _c.commonPatterns) || []),
647
+ antiPatterns: import_lodash.default.cloneDeep(((_d = resolved == null ? void 0 : resolved.docs) == null ? void 0 : _d.antiPatterns) || []),
648
+ skeleton,
649
+ hash,
650
+ source: coverage.source
651
+ };
652
+ }
653
+ buildBundleNode(use, contextChain, visited, compatibility) {
654
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
655
+ const visitKey = this.createContextVisitKey(use, contextChain);
656
+ const node = {
657
+ use,
658
+ title: (resolved == null ? void 0 : resolved.title) || use
659
+ };
660
+ if (compatibility) {
661
+ node.compatibility = import_lodash.default.cloneDeep(compatibility);
662
+ }
663
+ if (visited.has(visitKey) || this.isContextCycle(use, contextChain)) {
664
+ return node;
665
+ }
666
+ visited.add(visitKey);
667
+ try {
668
+ const subModelCatalog = this.buildBundleSubModelCatalog(use, resolved == null ? void 0 : resolved.subModelSlots, contextChain, visited);
669
+ if (subModelCatalog && Object.keys(subModelCatalog).length > 0) {
670
+ node.subModelCatalog = subModelCatalog;
671
+ }
672
+ return node;
673
+ } finally {
674
+ visited.delete(visitKey);
675
+ }
676
+ }
677
+ buildBundleSubModelCatalog(parentUse, slots, contextChain, visited) {
678
+ if (!slots || Object.keys(slots).length === 0) {
679
+ return void 0;
680
+ }
681
+ const entries = Object.entries(slots).map(([slotKey, slot]) => {
682
+ const edgeBase = {
683
+ parentUse,
684
+ slotKey
685
+ };
686
+ const fieldBindingCandidates = slot.fieldBindingContext ? this.resolveFieldBindingCandidates(slot.fieldBindingContext) : [];
687
+ const allowedUses = fieldBindingCandidates.length > 0 ? import_lodash.default.uniq(fieldBindingCandidates.map((item) => item.use)) : this.resolveSlotAllowedUses(parentUse, slotKey, slot);
688
+ const catalog = {
689
+ type: slot.type,
690
+ candidates: fieldBindingCandidates.length > 0 ? fieldBindingCandidates.map(
691
+ (candidate) => this.buildBundleNode(
692
+ candidate.use,
693
+ [
694
+ ...contextChain,
695
+ {
696
+ ...edgeBase,
697
+ childUse: candidate.use
698
+ }
699
+ ],
700
+ visited,
701
+ candidate.compatibility
702
+ )
703
+ ) : allowedUses.map(
704
+ (childUse) => this.buildBundleNode(
705
+ childUse,
706
+ [
707
+ ...contextChain,
708
+ {
709
+ ...edgeBase,
710
+ childUse
711
+ }
712
+ ],
713
+ visited
714
+ )
715
+ )
716
+ };
717
+ if (slot.required !== void 0) {
718
+ catalog.required = slot.required;
719
+ }
720
+ if (slot.type === "array" && typeof slot.minItems === "number") {
721
+ catalog.minItems = slot.minItems;
722
+ }
723
+ if (allowedUses.length === 0) {
724
+ catalog.open = true;
725
+ }
726
+ return [slotKey, catalog];
727
+ });
728
+ return entries.length ? Object.fromEntries(entries) : void 0;
729
+ }
730
+ createContextVisitKey(use, contextChain) {
731
+ return `${use}::${(0, import_utils.stableStringify)(contextChain)}`;
732
+ }
733
+ isContextCycle(use, contextChain) {
734
+ if (!contextChain.length) {
735
+ return false;
736
+ }
737
+ const ancestorUses = [contextChain[0].parentUse, ...contextChain.slice(0, -1).map((edge) => edge.childUse)];
738
+ return ancestorUses.includes(use);
739
+ }
740
+ buildModelSnapshotSchema(use, contextChain = []) {
741
+ return import_lodash.default.cloneDeep(this.buildModelSnapshotSchemaRef(use, contextChain));
742
+ }
743
+ buildCompactModelSnapshotSchema(use, contextChain = []) {
744
+ return import_lodash.default.cloneDeep(this.buildCompactModelSnapshotSchemaRef(use, contextChain));
745
+ }
746
+ buildModelSnapshotSchemaRef(use, contextChain = []) {
747
+ const cacheKey = this.createContextVisitKey(use, contextChain);
748
+ const cached = this.modelSnapshotSchemaCache.get(cacheKey);
749
+ if (cached) {
750
+ return cached;
751
+ }
752
+ const schema = this.buildModelSnapshotSchemaInternal(use, contextChain, /* @__PURE__ */ new Set());
753
+ const frozen = (0, import_utils.deepFreezePlainGraph)(schema);
754
+ this.modelSnapshotSchemaCache.set(cacheKey, frozen);
755
+ return frozen;
756
+ }
757
+ buildCompactModelSnapshotSchemaRef(use, contextChain = []) {
758
+ const cacheKey = this.createContextVisitKey(use, contextChain);
759
+ const cached = this.compactModelSnapshotSchemaCache.get(cacheKey);
760
+ if (cached) {
761
+ return cached;
762
+ }
763
+ const schema = this.buildCompactModelSnapshotSchemaInternal(use, contextChain);
764
+ const frozen = (0, import_utils.deepFreezePlainGraph)(schema);
765
+ this.compactModelSnapshotSchemaCache.set(cacheKey, frozen);
766
+ return frozen;
767
+ }
768
+ buildCompactModelSnapshotSchemaInternal(use, contextChain) {
769
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
770
+ const subModelsSchema = this.buildCompactSubModelsSchemaFromSlots(use, resolved == null ? void 0 : resolved.subModelSlots, contextChain);
771
+ return this.buildSnapshotShellSchema(use, resolved, subModelsSchema);
772
+ }
773
+ buildModelSnapshotSchemaInternal(use, contextChain, visited) {
774
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
775
+ const visitKey = this.createContextVisitKey(use, contextChain);
776
+ if (visited.has(visitKey) || this.isContextCycle(use, contextChain)) {
777
+ return this.buildTruncatedSnapshotSchema(use, resolved);
778
+ }
779
+ visited.add(visitKey);
780
+ try {
781
+ return this.buildSnapshotSchemaFromResolved(use, resolved, contextChain, visited);
782
+ } finally {
783
+ visited.delete(visitKey);
784
+ }
785
+ }
786
+ buildSnapshotSchemaFromResolved(use, resolved, contextChain, visited) {
787
+ const subModelsSchema = this.buildSubModelsSchemaFromSlots(
788
+ use || "",
789
+ resolved == null ? void 0 : resolved.subModelSlots,
790
+ contextChain,
791
+ visited
792
+ );
793
+ return this.buildSnapshotShellSchema(use, resolved, subModelsSchema);
794
+ }
795
+ buildSnapshotShellSchema(use, resolved, subModelsSchema) {
796
+ const flowRegistrySchema = (resolved == null ? void 0 : resolved.flowRegistrySchema) || { type: "object", additionalProperties: true };
797
+ const stepParamsSchema = (resolved == null ? void 0 : resolved.stepParamsSchema) || { type: "object", additionalProperties: true };
798
+ return {
799
+ $schema: import_utils.JSON_SCHEMA_DRAFT_07,
800
+ type: "object",
801
+ properties: {
802
+ uid: { type: "string" },
803
+ use: use ? { const: use } : { type: "string" },
804
+ async: { type: "boolean" },
805
+ parentId: { type: "string" },
806
+ subKey: { type: "string" },
807
+ subType: { type: "string", enum: ["object", "array"] },
808
+ sortIndex: { type: "number" },
809
+ stepParams: stepParamsSchema,
810
+ flowRegistry: (0, import_utils.mergeSchemas)(flowRegistrySchema, resolved == null ? void 0 : resolved.flowRegistrySchemaPatch) || {
811
+ type: "object",
812
+ additionalProperties: true
813
+ },
814
+ subModels: subModelsSchema
815
+ },
816
+ required: ["uid", "use"],
817
+ additionalProperties: true
818
+ };
819
+ }
820
+ buildTruncatedSnapshotSchema(use, resolved) {
821
+ return this.buildSnapshotShellSchema(use, resolved, {
822
+ type: "object",
823
+ additionalProperties: true
824
+ });
825
+ }
826
+ buildStaticFlowRegistrySchema(use, contextChain = []) {
827
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
828
+ const schema = (0, import_utils.mergeSchemas)(resolved == null ? void 0 : resolved.flowRegistrySchema, resolved == null ? void 0 : resolved.flowRegistrySchemaPatch);
829
+ if (schema) {
830
+ return import_lodash.default.cloneDeep(schema);
831
+ }
832
+ return { type: "object", additionalProperties: true };
833
+ }
834
+ buildStaticStepParamsSchema(use, contextChain = []) {
835
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
836
+ if (resolved == null ? void 0 : resolved.stepParamsSchema) {
837
+ return import_lodash.default.cloneDeep(resolved.stepParamsSchema);
838
+ }
839
+ return { type: "object", additionalProperties: true };
840
+ }
841
+ buildSubModelsSchema(use, contextChain = []) {
842
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
843
+ return this.buildSubModelsSchemaFromSlots(use, resolved == null ? void 0 : resolved.subModelSlots, contextChain, /* @__PURE__ */ new Set());
844
+ }
845
+ buildCompactSubModelsSchemaFromSlots(parentUse, slots, contextChain = []) {
846
+ if (!slots || Object.keys(slots).length === 0) {
847
+ return { type: "object", additionalProperties: true };
848
+ }
849
+ const properties = {};
850
+ const required = [];
851
+ for (const [slotKey, slot] of Object.entries(slots)) {
852
+ const itemSchema = this.buildCompactSlotTargetSchema(parentUse, slotKey, slot, contextChain);
853
+ properties[slotKey] = slot.type === "array" ? {
854
+ type: "array",
855
+ ...typeof slot.minItems === "number" ? { minItems: slot.minItems } : {},
856
+ items: itemSchema
857
+ } : itemSchema;
858
+ if (slot.required) {
859
+ required.push(slotKey);
860
+ }
861
+ }
862
+ return {
863
+ type: "object",
864
+ properties,
865
+ ...required.length ? { required } : {},
866
+ additionalProperties: true
867
+ };
868
+ }
869
+ buildSubModelsSchemaFromSlots(parentUse, slots, contextChain = [], visited) {
870
+ if (!slots || Object.keys(slots).length === 0) {
871
+ return { type: "object", additionalProperties: true };
872
+ }
873
+ const properties = {};
874
+ const required = [];
875
+ for (const [slotKey, slot] of Object.entries(slots)) {
876
+ const itemSchema = this.buildSlotTargetSchema(parentUse, slotKey, slot, contextChain, visited);
877
+ properties[slotKey] = slot.type === "array" ? {
878
+ type: "array",
879
+ ...typeof slot.minItems === "number" ? { minItems: slot.minItems } : {},
880
+ items: itemSchema
881
+ } : itemSchema;
882
+ if (slot.required) {
883
+ required.push(slotKey);
884
+ }
885
+ }
886
+ return {
887
+ type: "object",
888
+ properties,
889
+ ...required.length ? { required } : {},
890
+ additionalProperties: true
891
+ };
892
+ }
893
+ buildInferredFlowRegistrySchema(use) {
894
+ var _a, _b;
895
+ const registered = this.modelSchemas.get(use);
896
+ const modelClass = registered == null ? void 0 : registered.modelClass;
897
+ const flowsMap = (_b = (_a = modelClass == null ? void 0 : modelClass.globalFlowRegistry) == null ? void 0 : _a.getFlows) == null ? void 0 : _b.call(_a);
898
+ if (!(flowsMap == null ? void 0 : flowsMap.size)) {
899
+ return void 0;
900
+ }
901
+ const properties = {};
902
+ for (const [flowKey, flowDef] of flowsMap.entries()) {
903
+ const stepProperties = {};
904
+ const steps = (flowDef == null ? void 0 : flowDef.steps) || {};
905
+ for (const [stepKey, stepDef] of Object.entries(steps)) {
906
+ stepProperties[stepKey] = this.buildStepDefinitionSchema(stepDef);
907
+ }
908
+ properties[flowKey] = {
909
+ type: "object",
910
+ properties: {
911
+ key: { type: "string" },
912
+ title: { type: "string" },
913
+ manual: { type: "boolean" },
914
+ sort: { type: "number" },
915
+ on: this.buildFlowOnSchema(),
916
+ steps: {
917
+ type: "object",
918
+ properties: stepProperties,
919
+ additionalProperties: false
920
+ }
921
+ },
922
+ additionalProperties: true
923
+ };
924
+ }
925
+ return {
926
+ type: "object",
927
+ properties,
928
+ additionalProperties: true
929
+ };
930
+ }
931
+ buildInferredStepParamsSchema(use) {
932
+ var _a, _b;
933
+ const registered = this.modelSchemas.get(use);
934
+ const modelClass = registered == null ? void 0 : registered.modelClass;
935
+ const flowsMap = (_b = (_a = modelClass == null ? void 0 : modelClass.globalFlowRegistry) == null ? void 0 : _a.getFlows) == null ? void 0 : _b.call(_a);
936
+ if (!(flowsMap == null ? void 0 : flowsMap.size)) {
937
+ return void 0;
938
+ }
939
+ const properties = {};
940
+ for (const [flowKey, flowDef] of flowsMap.entries()) {
941
+ const stepProperties = {};
942
+ const steps = (flowDef == null ? void 0 : flowDef.steps) || {};
943
+ for (const [stepKey, stepDef] of Object.entries(steps)) {
944
+ const resolved = this.resolveStepParamsSchema(stepDef, `${use}.${flowKey}.${stepKey}`);
945
+ stepProperties[stepKey] = resolved.schema || { type: "object", additionalProperties: true };
946
+ }
947
+ properties[flowKey] = {
948
+ type: "object",
949
+ properties: stepProperties,
950
+ additionalProperties: false
951
+ };
952
+ }
953
+ return {
954
+ type: "object",
955
+ properties,
956
+ additionalProperties: true
957
+ };
958
+ }
959
+ buildFlowOnSchema() {
960
+ return {
961
+ anyOf: [
962
+ { type: "string" },
963
+ {
964
+ type: "object",
965
+ properties: {
966
+ eventName: { type: "string" },
967
+ defaultParams: { type: "object", additionalProperties: true },
968
+ phase: {
969
+ type: "string",
970
+ enum: ["beforeAllFlows", "afterAllFlows", "beforeFlow", "afterFlow", "beforeStep", "afterStep"]
971
+ },
972
+ flowKey: { type: "string" },
973
+ stepKey: { type: "string" }
974
+ },
975
+ required: ["eventName"],
976
+ additionalProperties: true
977
+ }
978
+ ]
979
+ };
980
+ }
981
+ buildStepDefinitionSchema(step) {
982
+ return {
983
+ type: "object",
984
+ properties: {
985
+ key: { type: "string" },
986
+ flowKey: { type: "string" },
987
+ title: { type: "string" },
988
+ use: { type: "string" },
989
+ sort: { type: "number" },
990
+ preset: { type: "boolean" },
991
+ isAwait: { type: "boolean" },
992
+ manual: { type: "boolean" },
993
+ on: this.buildFlowOnSchema(),
994
+ defaultParams: { type: ["object", "array", "string", "number", "boolean", "null"] },
995
+ paramsSchemaOverride: { type: "object", additionalProperties: true }
996
+ },
997
+ additionalProperties: true
998
+ };
999
+ }
1000
+ resolveStepParamsSchema(step, path) {
1001
+ var _a, _b, _c, _d;
1002
+ if (step.paramsSchemaOverride) {
1003
+ return {
1004
+ schema: import_lodash.default.cloneDeep(step.paramsSchemaOverride),
1005
+ hints: (0, import_utils.normalizeSchemaHints)((_a = step.schemaDocs) == null ? void 0 : _a.dynamicHints),
1006
+ coverage: "manual"
1007
+ };
1008
+ }
1009
+ if (step.use) {
1010
+ const action = this.getAction(step.use);
1011
+ if (action == null ? void 0 : action.schema) {
1012
+ return {
1013
+ schema: import_lodash.default.cloneDeep(action.schema),
1014
+ hints: (0, import_utils.normalizeSchemaHints)([...action.dynamicHints || [], ...((_b = step.schemaDocs) == null ? void 0 : _b.dynamicHints) || []]),
1015
+ coverage: action.coverage.status === "auto" || action.coverage.status === "manual" ? action.coverage.status : action.coverage.status === "unresolved" ? "unresolved" : "mixed"
1016
+ };
1017
+ }
1018
+ return {
1019
+ schema: { type: "object", additionalProperties: true },
1020
+ hints: [
1021
+ (0, import_utils.createFlowHint)(
1022
+ {
1023
+ kind: "unresolved-action",
1024
+ path,
1025
+ message: `${path} references unresolved action "${step.use}".`
1026
+ },
1027
+ {
1028
+ unresolvedReason: "missing-action-contribution",
1029
+ recommendedFallback: { use: step.use, params: {} }
1030
+ }
1031
+ ),
1032
+ ...((_c = step.schemaDocs) == null ? void 0 : _c.dynamicHints) || []
1033
+ ],
1034
+ coverage: "unresolved"
1035
+ };
1036
+ }
1037
+ const inferred = (0, import_schemaInference.inferParamsSchemaFromUiSchema)(path, step.uiSchema, path);
1038
+ return {
1039
+ schema: (0, import_utils.mergeSchemas)(inferred.schema, step.paramsSchemaPatch),
1040
+ hints: (0, import_utils.normalizeSchemaHints)([...inferred.hints || [], ...((_d = step.schemaDocs) == null ? void 0 : _d.dynamicHints) || []]),
1041
+ coverage: step.paramsSchemaPatch ? "mixed" : inferred.coverage
1042
+ };
1043
+ }
1044
+ buildSlotTargetSchema(parentUse, slotKey, slot, contextChain, visited) {
1045
+ var _a, _b;
1046
+ if (slot.fieldBindingContext) {
1047
+ const candidateUses = import_lodash.default.uniq(
1048
+ this.resolveFieldBindingCandidates(slot.fieldBindingContext).map((item) => item.use)
1049
+ );
1050
+ if (candidateUses.length > 0) {
1051
+ const candidateSchemas = candidateUses.map(
1052
+ (use) => this.buildModelSnapshotSchemaInternal(
1053
+ use,
1054
+ [
1055
+ ...contextChain,
1056
+ {
1057
+ parentUse,
1058
+ slotKey,
1059
+ childUse: use
1060
+ }
1061
+ ],
1062
+ visited
1063
+ )
1064
+ );
1065
+ if (slot.schema) {
1066
+ return {
1067
+ anyOf: [...candidateSchemas, import_lodash.default.cloneDeep(slot.schema)]
1068
+ };
1069
+ }
1070
+ return candidateSchemas.length === 1 ? candidateSchemas[0] : { oneOf: candidateSchemas };
1071
+ }
1072
+ }
1073
+ const allowedUses = this.resolveSlotAllowedUses(parentUse, slotKey, slot);
1074
+ if (allowedUses.length > 0) {
1075
+ const knownSchemas = allowedUses.map(
1076
+ (use) => this.buildModelSnapshotSchemaInternal(
1077
+ use,
1078
+ [
1079
+ ...contextChain,
1080
+ {
1081
+ parentUse,
1082
+ slotKey,
1083
+ childUse: use
1084
+ }
1085
+ ],
1086
+ visited
1087
+ )
1088
+ );
1089
+ if (slot.schema) {
1090
+ return {
1091
+ anyOf: [...knownSchemas, import_lodash.default.cloneDeep(slot.schema)]
1092
+ };
1093
+ }
1094
+ if (knownSchemas.length === 1) {
1095
+ return knownSchemas[0];
1096
+ }
1097
+ return {
1098
+ oneOf: knownSchemas
1099
+ };
1100
+ }
1101
+ if (slot.childSchemaPatch || ((_a = slot.descendantSchemaPatches) == null ? void 0 : _a.length)) {
1102
+ return this.buildAnonymousSlotSnapshotSchema(parentUse, slotKey, slot, contextChain, visited);
1103
+ }
1104
+ if (slot.schema && !slot.childSchemaPatch && !((_b = slot.descendantSchemaPatches) == null ? void 0 : _b.length)) {
1105
+ return import_lodash.default.cloneDeep(slot.schema);
1106
+ }
1107
+ return { type: "object", additionalProperties: true };
1108
+ }
1109
+ buildCompactSlotTargetSchema(parentUse, slotKey, slot, contextChain) {
1110
+ var _a, _b;
1111
+ if (slot.fieldBindingContext) {
1112
+ const candidateUses = import_lodash.default.uniq(
1113
+ this.resolveFieldBindingCandidates(slot.fieldBindingContext).map((item) => item.use)
1114
+ );
1115
+ if (candidateUses.length > 0) {
1116
+ const candidateSchemas = candidateUses.map(
1117
+ (use) => this.buildCompactSlotCandidateSchema(use, [
1118
+ ...contextChain,
1119
+ {
1120
+ parentUse,
1121
+ slotKey,
1122
+ childUse: use
1123
+ }
1124
+ ])
1125
+ );
1126
+ if (slot.schema) {
1127
+ return {
1128
+ anyOf: [...candidateSchemas, import_lodash.default.cloneDeep(slot.schema)]
1129
+ };
1130
+ }
1131
+ return candidateSchemas.length === 1 ? candidateSchemas[0] : { oneOf: candidateSchemas };
1132
+ }
1133
+ }
1134
+ const allowedUses = this.resolveSlotAllowedUses(parentUse, slotKey, slot);
1135
+ if (allowedUses.length > 0) {
1136
+ const knownSchemas = allowedUses.map(
1137
+ (use) => this.buildCompactSlotCandidateSchema(use, [
1138
+ ...contextChain,
1139
+ {
1140
+ parentUse,
1141
+ slotKey,
1142
+ childUse: use
1143
+ }
1144
+ ])
1145
+ );
1146
+ if (slot.schema) {
1147
+ return {
1148
+ anyOf: [...knownSchemas, import_lodash.default.cloneDeep(slot.schema)]
1149
+ };
1150
+ }
1151
+ return knownSchemas.length === 1 ? knownSchemas[0] : { oneOf: knownSchemas };
1152
+ }
1153
+ if (slot.childSchemaPatch || ((_a = slot.descendantSchemaPatches) == null ? void 0 : _a.length)) {
1154
+ return this.buildCompactAnonymousSlotSnapshotSchema(parentUse, slotKey, slot);
1155
+ }
1156
+ if (slot.schema && !slot.childSchemaPatch && !((_b = slot.descendantSchemaPatches) == null ? void 0 : _b.length)) {
1157
+ return import_lodash.default.cloneDeep(slot.schema);
1158
+ }
1159
+ return { type: "object", additionalProperties: true };
1160
+ }
1161
+ buildCompactSlotCandidateSchema(use, contextChain) {
1162
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
1163
+ return this.buildTruncatedSnapshotSchema(use, resolved);
1164
+ }
1165
+ buildCompactAnonymousSlotSnapshotSchema(parentUse, slotKey, slot) {
1166
+ const anonymousResolved = this.createAnonymousResolvedSchema(parentUse, slotKey, slot);
1167
+ return this.buildTruncatedSnapshotSchema(void 0, anonymousResolved);
1168
+ }
1169
+ buildAnonymousSlotSnapshotSchema(parentUse, slotKey, slot, contextChain, visited) {
1170
+ const anonymousResolved = this.createAnonymousResolvedSchema(parentUse, slotKey, slot);
1171
+ return this.buildSnapshotSchemaFromResolved(
1172
+ "",
1173
+ anonymousResolved,
1174
+ [
1175
+ ...contextChain,
1176
+ {
1177
+ parentUse,
1178
+ slotKey,
1179
+ childUse: ""
1180
+ }
1181
+ ],
1182
+ visited
1183
+ );
1184
+ }
1185
+ createAnonymousResolvedSchema(parentUse, slotKey, slot) {
1186
+ const anonymousResolved = {
1187
+ use: "",
1188
+ title: slot.description || `${parentUse || "AnonymousModel"}.${slotKey}`,
1189
+ examples: [],
1190
+ docs: (0, import_utils.normalizeSchemaDocs)(),
1191
+ dynamicHints: [],
1192
+ coverage: {
1193
+ status: "unresolved",
1194
+ source: "third-party"
1195
+ },
1196
+ exposure: "internal",
1197
+ abstract: false,
1198
+ allowDirectUse: true,
1199
+ suggestedUses: []
1200
+ };
1201
+ const directPatch = (0, import_modelPatches.resolveChildSchemaPatch)(slot, "");
1202
+ if (directPatch) {
1203
+ (0, import_modelPatches.applyModelSchemaPatch)(anonymousResolved, directPatch, "third-party");
1204
+ }
1205
+ return anonymousResolved;
1206
+ }
1207
+ collectNestedDocumentHints(use, contextChain, visited) {
1208
+ const visitKey = this.createContextVisitKey(use, contextChain);
1209
+ if (visited.has(visitKey) || this.isContextCycle(use, contextChain)) {
1210
+ return [];
1211
+ }
1212
+ visited.add(visitKey);
1213
+ try {
1214
+ const resolved = this.resolveModelSchemaRef(use, contextChain);
1215
+ const hints = [];
1216
+ for (const [slotKey, slot] of Object.entries(resolved.subModelSlots || {})) {
1217
+ const childUses = this.resolveSlotAllowedUses(use, slotKey, slot);
1218
+ for (const childUse of childUses) {
1219
+ const childContext = [
1220
+ ...contextChain,
1221
+ {
1222
+ parentUse: use,
1223
+ slotKey,
1224
+ childUse
1225
+ }
1226
+ ];
1227
+ const childDocument = this.buildModelDocument(childUse, childContext, visited);
1228
+ const basePath = `${use}.subModels.${slotKey}`;
1229
+ hints.push(...childDocument.dynamicHints.map((hint) => this.prefixNestedHint(hint, basePath, childUse)));
1230
+ }
1231
+ }
1232
+ return (0, import_utils.normalizeSchemaHints)(hints);
1233
+ } finally {
1234
+ visited.delete(visitKey);
1235
+ }
1236
+ }
1237
+ prefixNestedHint(hint, basePath, childUse) {
1238
+ if (!hint.path) {
1239
+ return {
1240
+ ...hint,
1241
+ path: basePath
1242
+ };
1243
+ }
1244
+ if (hint.path === childUse) {
1245
+ return {
1246
+ ...hint,
1247
+ path: basePath
1248
+ };
1249
+ }
1250
+ if (hint.path.startsWith(`${childUse}.`)) {
1251
+ return {
1252
+ ...hint,
1253
+ path: `${basePath}.${hint.path.slice(childUse.length + 1)}`
1254
+ };
1255
+ }
1256
+ return {
1257
+ ...hint,
1258
+ path: `${basePath}.${hint.path}`
1259
+ };
1260
+ }
1261
+ collectContextPatches(use, contextChain) {
1262
+ var _a;
1263
+ if (!contextChain.length) {
1264
+ return [];
1265
+ }
1266
+ const contributions = [];
1267
+ const targetEdgeIndex = contextChain.length - 1;
1268
+ for (let index = 0; index < contextChain.length; index++) {
1269
+ const edge = contextChain[index];
1270
+ const parentContext = contextChain.slice(0, index);
1271
+ const parentResolved = this.resolveModelSchemaRef(edge.parentUse, parentContext);
1272
+ const slot = (_a = parentResolved.subModelSlots) == null ? void 0 : _a[edge.slotKey];
1273
+ if (!slot) {
1274
+ continue;
1275
+ }
1276
+ const remainingEdges = contextChain.slice(index + 1);
1277
+ for (const patch of slot.descendantSchemaPatches || []) {
1278
+ if ((0, import_modelPatches.matchesDescendantSchemaPatch)(patch, remainingEdges)) {
1279
+ contributions.push({
1280
+ patch: patch.patch,
1281
+ source: parentResolved.coverage.source,
1282
+ strict: parentResolved.coverage.strict
1283
+ });
1284
+ }
1285
+ }
1286
+ if (index === targetEdgeIndex) {
1287
+ const directPatch = (0, import_modelPatches.resolveChildSchemaPatch)(slot, use);
1288
+ if (directPatch) {
1289
+ contributions.push({
1290
+ patch: directPatch,
1291
+ source: parentResolved.coverage.source,
1292
+ strict: parentResolved.coverage.strict
1293
+ });
1294
+ }
1295
+ }
1296
+ }
1297
+ return contributions;
1298
+ }
1299
+ collectModelDynamicHints(use, modelClass, meta) {
1300
+ const hints = [];
1301
+ if (typeof meta.children === "function") {
1302
+ hints.push(
1303
+ (0, import_utils.createFlowHint)(
1304
+ {
1305
+ kind: "dynamic-children",
1306
+ path: `${use}.meta.children`,
1307
+ message: `${use} uses function-based children and only static slot hints are available.`
1308
+ },
1309
+ {
1310
+ unresolvedReason: "function-children"
1311
+ }
1312
+ )
1313
+ );
1314
+ }
1315
+ if (typeof meta.createModelOptions === "function") {
1316
+ hints.push(
1317
+ (0, import_utils.createFlowHint)(
1318
+ {
1319
+ kind: "dynamic-children",
1320
+ path: `${use}.meta.createModelOptions`,
1321
+ message: `${use} uses function-based createModelOptions and may need manual sub-model slot schema.`
1322
+ },
1323
+ {
1324
+ unresolvedReason: "function-create-model-options"
1325
+ }
1326
+ )
1327
+ );
1328
+ }
1329
+ if (typeof modelClass.defineChildren === "function") {
1330
+ hints.push(
1331
+ (0, import_utils.createFlowHint)(
1332
+ {
1333
+ kind: "dynamic-children",
1334
+ path: `${use}.defineChildren`,
1335
+ message: `${use} defines dynamic children. Schema generation only keeps static baseline.`
1336
+ },
1337
+ {
1338
+ unresolvedReason: "runtime-define-children"
1339
+ }
1340
+ )
1341
+ );
1342
+ }
1343
+ return hints;
1344
+ }
1345
+ collectFlowSchemaDiagnostics(use) {
1346
+ var _a, _b, _c;
1347
+ const registered = this.modelSchemas.get(use);
1348
+ const modelClass = registered == null ? void 0 : registered.modelClass;
1349
+ const flowsMap = (_b = (_a = modelClass == null ? void 0 : modelClass.globalFlowRegistry) == null ? void 0 : _a.getFlows) == null ? void 0 : _b.call(_a);
1350
+ if (!(flowsMap == null ? void 0 : flowsMap.size)) {
1351
+ return {
1352
+ hints: [],
1353
+ statuses: []
1354
+ };
1355
+ }
1356
+ const hints = [];
1357
+ const statuses = [];
1358
+ for (const [flowKey, flowDef] of flowsMap.entries()) {
1359
+ for (const [stepKey, stepDef] of Object.entries((flowDef == null ? void 0 : flowDef.steps) || {})) {
1360
+ const resolved = this.resolveStepParamsSchema(stepDef, `${use}.${flowKey}.${stepKey}`);
1361
+ if ((_c = resolved.hints) == null ? void 0 : _c.length) {
1362
+ hints.push(...resolved.hints);
1363
+ }
1364
+ statuses.push(resolved.coverage);
1365
+ }
1366
+ }
1367
+ return {
1368
+ hints: (0, import_utils.normalizeSchemaHints)(hints),
1369
+ statuses
1370
+ };
1371
+ }
1372
+ buildDocumentCoverage(base, stepStatuses) {
1373
+ const statuses = new Set([base.status, ...stepStatuses].filter(Boolean));
1374
+ let status = base.status;
1375
+ if (statuses.size > 1) {
1376
+ statuses.delete("unresolved");
1377
+ if (statuses.size === 0) {
1378
+ status = "unresolved";
1379
+ } else {
1380
+ status = "mixed";
1381
+ }
1382
+ } else if (statuses.size === 1) {
1383
+ status = Array.from(statuses)[0] || "unresolved";
1384
+ }
1385
+ return {
1386
+ ...base,
1387
+ status
1388
+ };
1389
+ }
1390
+ inferSubModelSlotsFromModelClass(use, modelClass) {
1391
+ const meta = (modelClass.meta || {}).schema;
1392
+ if (meta == null ? void 0 : meta.subModelSlots) {
1393
+ return import_lodash.default.cloneDeep(meta.subModelSlots);
1394
+ }
1395
+ const createModelOptions = (modelClass.meta || {}).createModelOptions;
1396
+ if (!import_lodash.default.isPlainObject(createModelOptions) || !import_lodash.default.isPlainObject(createModelOptions.subModels)) {
1397
+ return {};
1398
+ }
1399
+ const slots = {};
1400
+ for (const [slotKey, slotValue] of Object.entries(createModelOptions.subModels || {})) {
1401
+ if (Array.isArray(slotValue)) {
1402
+ const first = slotValue[0];
1403
+ slots[slotKey] = {
1404
+ type: "array",
1405
+ ...typeof (first == null ? void 0 : first.use) === "string" ? { use: first.use } : {}
1406
+ };
1407
+ } else if (import_lodash.default.isPlainObject(slotValue)) {
1408
+ slots[slotKey] = {
1409
+ type: "object",
1410
+ ...slotValue.use ? { use: slotValue.use } : {}
1411
+ };
1412
+ } else {
1413
+ slots[slotKey] = {
1414
+ type: "object"
1415
+ };
1416
+ }
1417
+ }
1418
+ return slots;
1419
+ }
1420
+ }
1421
+ // Annotate the CommonJS export names for ESM import in node:
1422
+ 0 && (module.exports = {
1423
+ FlowSchemaRegistry
1424
+ });