@magmonium/cli 0.8.29 → 0.10.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.
@@ -0,0 +1,4087 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target2, all) => {
7
+ for (var name in all)
8
+ __defProp(target2, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // apps/m-one-ui/src/app/pages/design/lib/invariant-catalog.ts
21
+ var invariant_catalog_exports = {};
22
+ __export(invariant_catalog_exports, {
23
+ INVARIANTS: () => INVARIANTS,
24
+ codecDrops: () => codecDrops,
25
+ collectEmitGaps: () => collectEmitGaps,
26
+ invariantScopeOf: () => invariantScopeOf,
27
+ runInvariants: () => runInvariants
28
+ });
29
+ module.exports = __toCommonJS(invariant_catalog_exports);
30
+ var import_codegen52 = require("./index.js");
31
+
32
+ // apps/m-one-ui/src/app/pages/design/model/invariant.ts
33
+ var targetKey = (target2) => {
34
+ switch (target2.kind) {
35
+ case "panel":
36
+ return `panel:${target2.panel}${target2.featureId ? `:${target2.featureId}` : ""}${target2.subStoreId ? `:${target2.subStoreId}` : ""}${target2.memberId ? `:${target2.memberId}` : ""}`;
37
+ case "nav":
38
+ return `nav:${target2.navId}`;
39
+ case "screen":
40
+ return `screen:${target2.screenId}${target2.computedId ? `:${target2.computedId}` : ""}${target2.memberId ? `:${target2.memberId}` : ""}`;
41
+ case "compare":
42
+ return `compare:${target2.tab}:${target2.item.id}`;
43
+ case "function":
44
+ return `function:${target2.functionId}`;
45
+ case "control":
46
+ return `control:${target2.screenId}:${target2.controlId}${target2.inputId ? `:${target2.inputId}` : ""}`;
47
+ }
48
+ };
49
+ var defineInvariant = (def) => ({
50
+ name: def.name,
51
+ severity: def.severity,
52
+ deps: def.deps,
53
+ run: (scope) => {
54
+ const view = {};
55
+ def.deps.forEach((dep) => {
56
+ view[dep] = scope[dep];
57
+ });
58
+ return def.validate(view).map(
59
+ ({
60
+ message,
61
+ subject,
62
+ target: target2,
63
+ computedFix,
64
+ routeInputFix,
65
+ screenRetarget
66
+ }) => ({
67
+ id: `${def.name}::${targetKey(target2)}${computedFix ? `::${computedFix.computedId}` : ""}${routeInputFix ? `::${routeInputFix.navId}` : ""}`,
68
+ invariant: def.name,
69
+ message: message ?? def.message,
70
+ subject,
71
+ severity: def.severity,
72
+ target: target2,
73
+ ...computedFix ? { computedFix } : {},
74
+ ...routeInputFix ? { routeInputFix } : {},
75
+ ...screenRetarget ? { screenRetarget } : {}
76
+ })
77
+ );
78
+ }
79
+ });
80
+
81
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/backend-url-declared.ts
82
+ var backendUrlDeclared = defineInvariant({
83
+ name: "backend-url-declared",
84
+ message: "invariant-backend-url-blank",
85
+ severity: "blocking",
86
+ deps: ["appTarget", "features"],
87
+ validate: ({ appTarget, features }) => {
88
+ const drawsMethods = Object.values(features).some(
89
+ (feature) => Object.keys(feature.methods ?? {}).length > 0
90
+ );
91
+ if (!drawsMethods) return [];
92
+ const { preset, hosts } = appTarget.environment;
93
+ if (hosts.backendUrl.trim()) return [];
94
+ return [
95
+ {
96
+ subject: preset,
97
+ target: { kind: "panel", panel: "environment" }
98
+ }
99
+ ];
100
+ }
101
+ });
102
+
103
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/dynamic-nav-input-declared.ts
104
+ var import_codegen = require("./index.js");
105
+ var dynamicNavInputDeclared = defineInvariant({
106
+ name: "dynamic-nav-input-declared",
107
+ message: "invariant-dynamic-nav-input-missing",
108
+ severity: "blocking",
109
+ deps: ["navMap", "screens"],
110
+ validate: ({ navMap, screens }) => Object.values(navMap).filter(
111
+ (nav) => nav.linkKind === "url" && nav.presentation === "dynamic" && !!nav.pageId
112
+ ).flatMap((nav) => {
113
+ const routed = screens.find(
114
+ (screen) => screen.id === nav.pageId && (0, import_codegen.isRoutableScreen)(screen)
115
+ );
116
+ if (!routed) return [];
117
+ const param = (0, import_codegen.navParam)(nav);
118
+ const declared = Object.values(routed.inputs ?? {}).some(
119
+ (input) => input.name === param
120
+ );
121
+ if (declared) return [];
122
+ return [
123
+ {
124
+ // The parameter is named in the subject: with the name authorable,
125
+ // "this Page is missing an input" is only half of what the User has
126
+ // to know to fix it.
127
+ subject: `${nav.navId} \u2192 ${routed.name} (:${param})`,
128
+ routeInputFix: {
129
+ navId: nav.navId,
130
+ screenId: routed.id,
131
+ name: param
132
+ },
133
+ target: {
134
+ kind: "screen",
135
+ screenId: routed.id,
136
+ panel: "screen"
137
+ }
138
+ }
139
+ ];
140
+ })
141
+ });
142
+
143
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-tail-input-declared.ts
144
+ var import_codegen2 = require("./index.js");
145
+ var navTailInputDeclared = defineInvariant({
146
+ name: "nav-tail-input-declared",
147
+ message: "invariant-nav-tail-input-missing",
148
+ severity: "blocking",
149
+ deps: ["navMap", "screens"],
150
+ validate: ({ navMap, screens }) => Object.values(navMap).filter(
151
+ (nav) => nav.tail !== void 0 && nav.linkKind === "url" && !!nav.pageId
152
+ ).flatMap((nav) => {
153
+ const routed = screens.find(
154
+ (screen) => screen.id === nav.pageId && (0, import_codegen2.isRoutableScreen)(screen)
155
+ );
156
+ if (!routed) return [];
157
+ const declared = Object.values(routed.inputs ?? {}).some(
158
+ (input) => input.name === nav.tail
159
+ );
160
+ if (declared) return [];
161
+ return [
162
+ {
163
+ subject: `${nav.navId} \u2192 ${routed.name} (*${nav.tail})`,
164
+ target: {
165
+ kind: "screen",
166
+ screenId: routed.id,
167
+ panel: "screen"
168
+ }
169
+ }
170
+ ];
171
+ })
172
+ });
173
+
174
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-tail-childless.ts
175
+ var navTailChildless = defineInvariant({
176
+ name: "nav-tail-childless",
177
+ message: "invariant-nav-tail-has-children",
178
+ severity: "blocking",
179
+ deps: ["navMap"],
180
+ validate: ({ navMap }) => Object.values(navMap).filter((nav) => nav.tail !== void 0 && nav.children.length > 0).map((nav) => ({
181
+ subject: nav.navId,
182
+ target: { kind: "nav", navId: nav.navId }
183
+ }))
184
+ });
185
+
186
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-variant-on-chain.ts
187
+ var import_codegen3 = require("./index.js");
188
+ var navVariantOnChain = defineInvariant({
189
+ name: "nav-variant-on-chain",
190
+ message: "invariant-nav-variant-off-chain",
191
+ severity: "blocking",
192
+ deps: ["screens", "navMap"],
193
+ validate: ({ screens, navMap }) => screens.flatMap((screen) => {
194
+ const chain = (0, import_codegen3.navVariantNavIds)(navMap, screen.id);
195
+ return Object.values(screen.variants ?? {}).filter(
196
+ (variant) => (0, import_codegen3.variantNavIds)(variant).some((navId) => !chain.includes(navId))
197
+ ).map((variant) => ({
198
+ subject: `${screen.name}.${variant.name}`,
199
+ target: { kind: "screen", screenId: screen.id }
200
+ }));
201
+ })
202
+ });
203
+
204
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-nav-on-chain.ts
205
+ var import_codegen4 = require("./index.js");
206
+ var computedNavOnChain = defineInvariant({
207
+ name: "computed-nav-on-chain",
208
+ message: "invariant-computed-nav-off-chain",
209
+ severity: "blocking",
210
+ deps: ["screens", "navMap"],
211
+ validate: ({ screens, navMap }) => screens.flatMap((screen) => {
212
+ const chain = (0, import_codegen4.navVariantNavIds)(navMap, screen.id);
213
+ return Object.values(screen.computeds ?? {}).filter(
214
+ (computed) => (0, import_codegen4.screenComputedNavIds)(computed).some((navId) => !chain.includes(navId))
215
+ ).map((computed) => ({
216
+ subject: `${screen.name}.${computed.name}`,
217
+ // The computed's own editor is where its Nav argument is repointed,
218
+ // so the reveal opens the Screen panel with it docked alongside.
219
+ target: {
220
+ kind: "screen",
221
+ screenId: screen.id,
222
+ panel: "screen",
223
+ computedId: computed.id
224
+ }
225
+ }));
226
+ })
227
+ });
228
+
229
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-one-function-known.ts
230
+ var import_codegen5 = require("./index.js");
231
+ var computedOneFunctionKnown = defineInvariant({
232
+ name: "computed-one-function-known",
233
+ message: "invariant-computed-one-function-unknown",
234
+ severity: "blocking",
235
+ deps: ["screens", "features"],
236
+ validate: ({ screens, features }) => [
237
+ ...screens.flatMap(
238
+ (screen) => Object.values(screen.computeds ?? {}).filter(
239
+ (computed) => (0, import_codegen5.isOneFunctionComputed)(computed) && !(0, import_codegen5.oneFunctionOf)(computed.oneFunction)?.reach.includes(
240
+ "screen-computed"
241
+ )
242
+ ).map((computed) => ({
243
+ subject: `${screen.name}.${computed.name}`,
244
+ target: {
245
+ kind: "screen",
246
+ screenId: screen.id,
247
+ panel: "screen",
248
+ computedId: computed.id
249
+ }
250
+ }))
251
+ ),
252
+ ...Object.values(features).flatMap(
253
+ (feature) => (0, import_codegen5.storesOf)(feature).flatMap(
254
+ (owned) => Object.values(owned.computeds).filter(
255
+ (computed) => (0, import_codegen5.isOneFunctionStateComputed)(computed) && !(0, import_codegen5.oneFunctionOf)(computed.oneFunction)?.reach.includes(
256
+ "state-computed"
257
+ )
258
+ ).map((computed) => ({
259
+ subject: `${feature.name}.${computed.name}`,
260
+ target: {
261
+ kind: "panel",
262
+ panel: "store",
263
+ featureId: feature.id,
264
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
265
+ memberId: computed.id
266
+ }
267
+ }))
268
+ )
269
+ )
270
+ ]
271
+ });
272
+
273
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/remote-control-url.ts
274
+ var import_codegen6 = require("./index.js");
275
+ var remotesOf = (maps) => Object.entries(maps).flatMap(
276
+ ([screenId, map]) => Object.values(map ?? {}).filter((control) => control.type === import_codegen6.ControlType.REMOTE).map((control) => ({ screenId, control }))
277
+ );
278
+ var urlModeOf = ({ control }) => (0, import_codegen6.remoteUrlModeOf)(control.configs);
279
+ var subjectOf = ({ control }) => (0, import_codegen6.remoteMountName)(control) || "remote-unnamed";
280
+ var target = ({ screenId, control }) => ({
281
+ kind: "control",
282
+ screenId,
283
+ controlId: control.id
284
+ });
285
+ var remoteTailSingle = defineInvariant({
286
+ name: "remote-tail-single",
287
+ message: "invariant-remote-tail-single",
288
+ severity: "blocking",
289
+ deps: ["screenControlMaps"],
290
+ validate: ({ screenControlMaps }) => {
291
+ const tails = remotesOf(screenControlMaps).filter(
292
+ (f) => urlModeOf(f) === "tail"
293
+ );
294
+ const byScreen = /* @__PURE__ */ new Map();
295
+ tails.forEach(
296
+ (f) => byScreen.set(f.screenId, [...byScreen.get(f.screenId) ?? [], f])
297
+ );
298
+ return [...byScreen.values()].filter((found) => found.length > 1).map((found) => ({
299
+ subject: subjectOf(found[1]),
300
+ target: target(found[1])
301
+ }));
302
+ }
303
+ });
304
+ var tailableNavOf = (screenId, navMap) => Object.values(navMap).find(
305
+ (nav) => nav.pageId === screenId && (0, import_codegen6.routesNavTail)(nav)
306
+ );
307
+ var remoteTailRouted = defineInvariant({
308
+ name: "remote-tail-routed",
309
+ message: "invariant-remote-tail-unrouted",
310
+ severity: "blocking",
311
+ deps: ["screenControlMaps", "navMap"],
312
+ validate: ({ screenControlMaps, navMap }) => {
313
+ const tailed = new Set(
314
+ Object.values(navMap).filter((nav) => nav.tail !== void 0 && nav.pageId).map((nav) => nav.pageId)
315
+ );
316
+ return remotesOf(screenControlMaps).filter((f) => urlModeOf(f) === "tail" && !tailed.has(f.screenId)).map((f) => {
317
+ const nav = tailableNavOf(f.screenId, navMap);
318
+ return {
319
+ subject: subjectOf(f),
320
+ target: nav ? { kind: "nav", navId: nav.navId } : target(f)
321
+ };
322
+ });
323
+ }
324
+ });
325
+ var remoteNameUnique = defineInvariant({
326
+ name: "remote-name-unique",
327
+ message: "invariant-remote-name-taken",
328
+ severity: "blocking",
329
+ deps: ["screenControlMaps"],
330
+ validate: ({ screenControlMaps }) => {
331
+ const seen = /* @__PURE__ */ new Set();
332
+ return remotesOf(screenControlMaps).flatMap((f) => {
333
+ const key = `${f.screenId}::${(0, import_codegen6.remoteMountName)(f.control)}`;
334
+ if (!(0, import_codegen6.remoteMountName)(f.control) || !seen.has(key)) {
335
+ seen.add(key);
336
+ return [];
337
+ }
338
+ return [{ subject: (0, import_codegen6.remoteMountName)(f.control), target: target(f) }];
339
+ });
340
+ }
341
+ });
342
+ var remoteMountPatternValid = defineInvariant({
343
+ name: "remote-mount-pattern",
344
+ message: "invariant-remote-mount-pattern",
345
+ severity: "blocking",
346
+ deps: ["screenControlMaps"],
347
+ validate: ({ screenControlMaps }) => remotesOf(screenControlMaps).filter((f) => (0, import_codegen6.remoteMountProblemOf)(f.control.configs)).map((f) => ({ subject: subjectOf(f), target: target(f) }))
348
+ });
349
+ var remoteMountMatchesRoute = defineInvariant({
350
+ name: "remote-mount-route",
351
+ message: "invariant-remote-mount-route",
352
+ severity: "blocking",
353
+ deps: ["screenControlMaps", "navMap"],
354
+ validate: ({ screenControlMaps, navMap }) => remotesOf(screenControlMaps).filter((f) => {
355
+ if ((0, import_codegen6.remoteMountProblemOf)(f.control.configs)) return false;
356
+ if ((0, import_codegen6.remoteMountTextOf)(f.control.configs) === void 0) return false;
357
+ const paths = (0, import_codegen6.navTailPathsOf)(f.screenId, navMap);
358
+ const pattern = (0, import_codegen6.remoteMountPatternOf)(f.control.configs);
359
+ return paths.length > 0 && !paths.some((p) => (0, import_codegen6.mountAgreesWithRoute)(pattern, p));
360
+ }).map((f) => ({ subject: subjectOf(f), target: target(f) }))
361
+ });
362
+
363
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/landing-page-bound.ts
364
+ var import_codegen7 = require("./index.js");
365
+ var landingPageBound = defineInvariant({
366
+ name: "landing-page-bound",
367
+ message: "invariant-landing-page-unbound",
368
+ severity: "advisory",
369
+ deps: ["navMap", "screens"],
370
+ validate: ({ navMap, screens }) => {
371
+ if (!screens.some(import_codegen7.isRoutableScreen)) return [];
372
+ const navId = (0, import_codegen7.landingNavId)(navMap);
373
+ const landing = navMap[navId];
374
+ if (!landing) return [];
375
+ const bound = landing.linkKind === "url" && !!landing.pageId && screens.some(
376
+ (screen) => screen.id === landing.pageId && (0, import_codegen7.isRoutableScreen)(screen)
377
+ );
378
+ if (bound) return [];
379
+ return [{ subject: navId, target: { kind: "nav", navId } }];
380
+ }
381
+ });
382
+
383
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-visibility-resolvable.ts
384
+ var import_codegen8 = require("./index.js");
385
+ var navVisibilityResolvable = defineInvariant({
386
+ name: "nav-visibility-resolvable",
387
+ message: "invariant-nav-visibility-unresolvable",
388
+ severity: "blocking",
389
+ deps: ["navMap", "features"],
390
+ validate: ({ navMap, features }) => Object.values(navMap).filter((nav) => !!nav.visibilitySource).flatMap((nav) => {
391
+ const source = nav.visibilitySource;
392
+ if (!source) return [];
393
+ const target2 = { kind: "nav", navId: nav.navId };
394
+ if (!source.hidesRow && !source.guardsRoute) {
395
+ return [{ subject: `${nav.navId} \u2014 no effect`, target: target2 }];
396
+ }
397
+ const feature = source.featureId ? features[source.featureId] : void 0;
398
+ if (!feature) {
399
+ return [{ subject: `${nav.navId} \u2014 feature gone`, target: target2 }];
400
+ }
401
+ const fn = source.functionId ? feature.functions?.[source.functionId] : void 0;
402
+ if (!fn) {
403
+ return [{ subject: `${nav.navId} \u2014 function gone`, target: target2 }];
404
+ }
405
+ if (!(0, import_codegen8.isNavVisibilityFunction)(fn)) {
406
+ return [
407
+ { subject: `${nav.navId} \u2192 ${fn.name} \u2014 not a boolean`, target: target2 }
408
+ ];
409
+ }
410
+ const unmapped = fn.params.filter((param) => !source.args?.[param.id]).map((param) => param.name);
411
+ if (unmapped.length) {
412
+ return [
413
+ {
414
+ subject: `${nav.navId} \u2192 ${fn.name} \u2014 unmapped: ${unmapped.join(
415
+ ", "
416
+ )}`,
417
+ target: target2
418
+ }
419
+ ];
420
+ }
421
+ if (source.methodId && !Object.values(feature.methods ?? {}).some(
422
+ (method) => method.id === source.methodId
423
+ ) && !Object.values(feature.subStores ?? {}).some(
424
+ (sub) => Object.values(sub.methods ?? {}).some(
425
+ (method) => method.id === source.methodId
426
+ )
427
+ )) {
428
+ return [{ subject: `${nav.navId} \u2014 load method gone`, target: target2 }];
429
+ }
430
+ return [];
431
+ })
432
+ });
433
+
434
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/method-variant-no-landing.ts
435
+ var import_codegen9 = require("./index.js");
436
+ var methodVariantNoLanding = defineInvariant({
437
+ name: "method-variant-no-landing",
438
+ message: "invariant-method-variant-no-landing",
439
+ severity: "advisory",
440
+ deps: ["features", "screens"],
441
+ validate: ({ features, screens }) => Object.values(features).flatMap((feature) => {
442
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
443
+ return (0, import_codegen9.storesOf)(feature).flatMap(
444
+ (store) => Object.values(store.methods).flatMap((method) => {
445
+ if (!(method.variants ?? []).length) return [];
446
+ const mappings = method.response ?? [];
447
+ const codes = [...new Set(mappings.map((m) => m.code))];
448
+ return codes.filter((code) => {
449
+ const rows = mappings.filter((m) => m.code === code);
450
+ return rows.length && rows.every((row) => !!row.landsWhen);
451
+ }).map((code) => ({
452
+ subject: `${feature.name}.${method.name} \u2192 ${code}`,
453
+ target: { kind: "screen", screenId }
454
+ }));
455
+ })
456
+ );
457
+ })
458
+ });
459
+
460
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/method-variant-unused.ts
461
+ var import_codegen10 = require("./index.js");
462
+ var methodVariantUnused = defineInvariant({
463
+ name: "method-variant-unused",
464
+ message: "invariant-method-variant-unused",
465
+ severity: "advisory",
466
+ deps: ["features", "screens"],
467
+ validate: ({ features, screens }) => Object.values(features).flatMap((feature) => {
468
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
469
+ return (0, import_codegen10.storesOf)(feature).flatMap(
470
+ (store) => Object.values(store.methods).flatMap((method) => {
471
+ const named2 = new Set(
472
+ (method.response ?? []).map((mapping) => mapping.landsWhen).filter((id) => !!id)
473
+ );
474
+ return (method.variants ?? []).filter((variant) => !named2.has(variant.id)).map((variant) => ({
475
+ subject: `${feature.name}.${method.name} \u2192 ${variant.name}`,
476
+ target: { kind: "screen", screenId }
477
+ }));
478
+ })
479
+ );
480
+ })
481
+ });
482
+
483
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/overlay-body-bound.ts
484
+ var import_codegen11 = require("./index.js");
485
+ var overlayBodyBound = defineInvariant({
486
+ name: "overlay-body-bound",
487
+ message: "invariant-overlay-body-unbound",
488
+ severity: "advisory",
489
+ deps: ["screens", "screenControlMaps"],
490
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
491
+ const controlMap = screenControlMaps[screen.id] ?? {};
492
+ return Object.values(controlMap).flatMap((control) => {
493
+ const unbound = Object.entries(control.directives ?? {}).some(
494
+ ([name, directive]) => {
495
+ if (!(0, import_codegen11.isOverlayDirectiveName)(name)) return false;
496
+ const configs = directive.overlayId ? controlMap[directive.overlayId]?.configs : directive.configs;
497
+ const component = configs?.["component"];
498
+ return component === import_codegen11.NEW_SCREEN || typeof component !== "string" || !component;
499
+ }
500
+ );
501
+ if (!unbound) return [];
502
+ return [
503
+ {
504
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
505
+ target: {
506
+ kind: "control",
507
+ screenId: screen.id,
508
+ controlId: control.id
509
+ }
510
+ }
511
+ ];
512
+ });
513
+ })
514
+ });
515
+
516
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/page-input-routable.ts
517
+ var import_codegen12 = require("./index.js");
518
+ var pageInputRoutable = defineInvariant({
519
+ name: "page-input-routable",
520
+ message: "invariant-page-input-unroutable",
521
+ severity: "advisory",
522
+ deps: ["navMap", "screens"],
523
+ validate: ({ navMap, screens }) => screens.filter((screen) => screen.kind === "page").flatMap((page) => {
524
+ const navs = Object.values(navMap).filter(
525
+ (nav) => nav.linkKind === "url" && nav.pageId === page.id
526
+ );
527
+ if (!navs.length) return [];
528
+ const routed = new Set(
529
+ navs.flatMap((nav) => (0, import_codegen12.navRouteParams)(nav.navId, navMap))
530
+ );
531
+ const unfillable = Object.values(page.inputs ?? {}).filter((input) => input.origin !== "card").filter(
532
+ (input) => !routed.has(input.name) || input.dataType.type === "enum"
533
+ ).map((input) => input.name);
534
+ if (!unfillable.length) return [];
535
+ return [
536
+ {
537
+ subject: `${page.name} \u2192 ${unfillable.join(", ")}`,
538
+ target: {
539
+ kind: "screen",
540
+ screenId: page.id,
541
+ panel: "screen"
542
+ }
543
+ }
544
+ ];
545
+ })
546
+ });
547
+
548
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/app-scaffold-complete.ts
549
+ var appScaffoldComplete = defineInvariant({
550
+ name: "app-scaffold-complete",
551
+ message: "app-scaffold-incomplete",
552
+ severity: "blocking",
553
+ deps: ["appTarget", "screens"],
554
+ validate: ({ appTarget, screens }) => {
555
+ if (!screens.length) return [];
556
+ const missing = [];
557
+ if (!appTarget.appName.trim()) missing.push("app-name");
558
+ if (!missing.length) return [];
559
+ return [
560
+ {
561
+ subject: missing.join(", "),
562
+ target: { kind: "panel", panel: "config" }
563
+ }
564
+ ];
565
+ }
566
+ });
567
+
568
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/binding-resolves.ts
569
+ var import_codegen13 = require("./index.js");
570
+ var bindingResolves = defineInvariant({
571
+ name: "binding-resolves",
572
+ message: "invariant-binding-unresolved",
573
+ severity: "blocking",
574
+ deps: ["features", "screens", "screenControlMaps", "functions"],
575
+ validate: ({ features, screens, screenControlMaps, functions }) => screens.flatMap((screen) => {
576
+ const feature = (0, import_codegen13.isFeatureScreen)(screen) ? features[screen.featureId] : void 0;
577
+ const controlMap = screenControlMaps[screen.id] ?? {};
578
+ const readable = feature ? (0, import_codegen13.readableMembers)(feature, import_codegen13.MAIN_STORE_OWNER) : void 0;
579
+ const scope = {
580
+ properties: readable?.properties,
581
+ shapes: feature?.shapes,
582
+ computeds: readable?.computeds,
583
+ inputs: screen.inputs,
584
+ screenComputeds: screen.computeds,
585
+ screenVariables: screen.variables,
586
+ // Screen-owned and read off the meta, as emit reads them (ADR 0127):
587
+ // without them every form-value read judged dangling.
588
+ formModels: screen.formModels,
589
+ functions: { ...functions, ...feature?.functions },
590
+ constants: screen.constants,
591
+ storeProp: (0, import_codegen13.isFeatureScreen)(screen) ? "store" : void 0,
592
+ controlMap
593
+ };
594
+ return Object.values(controlMap).flatMap((control) => {
595
+ const screenInputBindings = Object.values(
596
+ control.screenInputs ?? {}
597
+ ).flatMap(
598
+ (binding) => binding.kind === "data" ? [binding.binding] : []
599
+ );
600
+ const broken = [
601
+ ...Object.values(control.bindings ?? {}),
602
+ ...(0, import_codegen13.formatPipeBindings)(control),
603
+ ...screenInputBindings
604
+ ].some((binding) => !(0, import_codegen13.bindingExpression)(binding, scope));
605
+ if (!broken) return [];
606
+ return [
607
+ {
608
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
609
+ target: {
610
+ kind: "control",
611
+ screenId: screen.id,
612
+ controlId: control.id
613
+ }
614
+ }
615
+ ];
616
+ });
617
+ })
618
+ });
619
+
620
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/binding-resolves-outputs.ts
621
+ var import_codegen14 = require("./index.js");
622
+ var writesGone = (value, state) => {
623
+ if (Array.isArray(value)) return value.some((item) => writesGone(item, state));
624
+ if (!value || typeof value !== "object") return false;
625
+ const record = value;
626
+ if (typeof record.propertyId === "string" && "value" in record && !state.has(record.propertyId))
627
+ return true;
628
+ return Object.values(value).some((item) => writesGone(item, state));
629
+ };
630
+ var bindingResolvesOutputs = defineInvariant({
631
+ name: "binding-resolves-outputs",
632
+ message: "invariant-state-write-unresolved",
633
+ severity: "blocking",
634
+ deps: ["features", "screens", "screenControlMaps"],
635
+ validate: ({ features, screens, screenControlMaps }) => {
636
+ const state = new Set(
637
+ Object.values(features).flatMap(
638
+ (feature) => (0, import_codegen14.storesOf)(feature).flatMap((store) => Object.keys(store.properties ?? {}))
639
+ )
640
+ );
641
+ const found = [];
642
+ for (const screen of screens) {
643
+ const map = screenControlMaps[screen.id] ?? {};
644
+ for (const control of Object.values(map)) {
645
+ if (writesGone([control.outputWrites, control.outputOutcomes], state))
646
+ found.push({
647
+ subject: `${screen.name} \u2192 ${String(control.configs?.["name"] ?? control.id)}`,
648
+ target: { kind: "control", screenId: screen.id, controlId: control.id }
649
+ });
650
+ }
651
+ if (writesGone([screen.methods, screen.autoCalls], state))
652
+ found.push({
653
+ subject: `${screen.name} \u2192 ScreenMethod / AutoCall`,
654
+ target: { kind: "screen", screenId: screen.id, panel: "screen" }
655
+ });
656
+ }
657
+ return found;
658
+ }
659
+ });
660
+
661
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/control-rules.ts
662
+ var import_codegen15 = require("./index.js");
663
+ var nameOf = (map, id) => String(map[id]?.configs?.["name"] ?? id);
664
+ var routerOutletPlaced = defineInvariant({
665
+ name: "router-outlet-placed",
666
+ message: "invariant-router-outlet-misplaced",
667
+ severity: "blocking",
668
+ deps: ["screens", "screenControlMaps"],
669
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
670
+ const outlets = Object.values(screenControlMaps[screen.id] ?? {}).filter(
671
+ (control) => control.type === import_codegen15.ControlType.ROUTER_OUTLET
672
+ );
673
+ const misplaced = (0, import_codegen15.isRoutableKind)(screen.kind) ? outlets.slice(1) : outlets;
674
+ return misplaced.map((control) => ({
675
+ subject: `${screen.name} \u2192 ${nameOf(screenControlMaps[screen.id], control.id)}`,
676
+ target: { kind: "control", screenId: screen.id, controlId: control.id }
677
+ }));
678
+ })
679
+ });
680
+ var controlIdUnique = defineInvariant({
681
+ name: "control-id-unique",
682
+ message: "invariant-control-id-duplicate",
683
+ severity: "blocking",
684
+ deps: ["screens", "screenControlMaps"],
685
+ validate: ({ screens, screenControlMaps }) => {
686
+ const seen = /* @__PURE__ */ new Map();
687
+ const found = [];
688
+ for (const screen of screens) {
689
+ for (const id of Object.keys(screenControlMaps[screen.id] ?? {})) {
690
+ const first = seen.get(id);
691
+ if (first === void 0) {
692
+ seen.set(id, screen.name);
693
+ continue;
694
+ }
695
+ found.push({
696
+ subject: `${screen.name} \u2192 ${nameOf(screenControlMaps[screen.id], id)}, also on ${first}`,
697
+ target: { kind: "control", screenId: screen.id, controlId: id }
698
+ });
699
+ }
700
+ }
701
+ return found;
702
+ }
703
+ });
704
+ var fieldKeyTypeAgrees = defineInvariant({
705
+ name: "field-key-type-agrees",
706
+ message: "invariant-field-key-type-split",
707
+ severity: "blocking",
708
+ deps: ["screens", "screenControlMaps"],
709
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
710
+ const map = screenControlMaps[screen.id] ?? {};
711
+ return Object.values(map).filter((control) => control.type === import_codegen15.ControlType.FIELD).filter((field) => (0, import_codegen15.fieldKeyClashes)(map, field.id, field.configs).length > 0).map((field) => ({
712
+ subject: `${screen.name} \u2192 ${nameOf(map, field.id)}`,
713
+ target: { kind: "control", screenId: screen.id, controlId: field.id }
714
+ }));
715
+ })
716
+ });
717
+ var submitTargetResolves = defineInvariant({
718
+ name: "submit-target-resolves",
719
+ message: "invariant-submit-target-unresolved",
720
+ severity: "blocking",
721
+ deps: ["screens", "screenControlMaps"],
722
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
723
+ const map = screenControlMaps[screen.id] ?? {};
724
+ return Object.values(map).filter((control) => {
725
+ const target2 = control.configs?.[import_codegen15.SUBMIT_TARGET_KEY];
726
+ return typeof target2 === "string" && !map[target2];
727
+ }).map((control) => ({
728
+ subject: `${screen.name} \u2192 ${nameOf(map, control.id)}`,
729
+ target: { kind: "control", screenId: screen.id, controlId: control.id }
730
+ }));
731
+ })
732
+ });
733
+ var formResetResolves = defineInvariant({
734
+ name: "form-reset-resolves",
735
+ message: "invariant-form-reset-unresolved",
736
+ severity: "blocking",
737
+ deps: ["screens", "screenControlMaps"],
738
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
739
+ const map = screenControlMaps[screen.id] ?? {};
740
+ const onControls = Object.values(map).filter(
741
+ (control) => Object.values(control.outputOutcomes ?? {}).some(
742
+ (outcome) => !!(0, import_codegen15.repairCallOutcome)(map, outcome)
743
+ )
744
+ ).map((control) => ({
745
+ subject: `${screen.name} \u2192 ${nameOf(map, control.id)}`,
746
+ target: { kind: "control", screenId: screen.id, controlId: control.id }
747
+ }));
748
+ const onSites = (0, import_codegen15.repairClassCallSites)(map, {
749
+ methods: screen.methods,
750
+ autoCalls: screen.autoCalls
751
+ }) ? [
752
+ {
753
+ subject: `${screen.name} \u2192 ScreenMethod / AutoCall`,
754
+ target: { kind: "screen", screenId: screen.id, panel: "screen" }
755
+ }
756
+ ] : [];
757
+ return [...onControls, ...onSites];
758
+ })
759
+ });
760
+ var ruleFieldResolves = defineInvariant({
761
+ name: "rule-field-resolves",
762
+ message: "invariant-rule-field-unresolved",
763
+ severity: "blocking",
764
+ deps: ["screens", "screenControlMaps"],
765
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
766
+ const map = screenControlMaps[screen.id] ?? {};
767
+ const models = /* @__PURE__ */ new Set([
768
+ ...Object.keys(screen.formModels ?? {}),
769
+ ...Object.values(screen.formModels ?? {}).map((model) => model.id)
770
+ ]);
771
+ if (!models.size) return [];
772
+ const readsGone = (node) => {
773
+ if (Array.isArray(node)) return node.some(readsGone);
774
+ if (!node || typeof node !== "object") return false;
775
+ const path = node.path;
776
+ if (node.kind === "check" && Array.isArray(path) && typeof path[0] === "string" && models.has(path[0]) && typeof path[1] === "string" && !map[path[1]]) {
777
+ return true;
778
+ }
779
+ return Object.values(node).some(readsGone);
780
+ };
781
+ return Object.values(screen.variants ?? {}).filter((variant) => readsGone(variant.rule)).map((variant) => ({
782
+ subject: `${screen.name} \u2192 variant ${variant.name}`,
783
+ target: { kind: "screen", screenId: screen.id, panel: "screen", memberId: variant.id }
784
+ }));
785
+ })
786
+ });
787
+ var embedShapeWithinFeature = defineInvariant({
788
+ name: "embed-shape-within-feature",
789
+ message: "invariant-embed-shape-crosses-feature",
790
+ severity: "blocking",
791
+ deps: ["screens", "screenControlMaps"],
792
+ validate: ({ screens, screenControlMaps }) => {
793
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
794
+ return screens.flatMap(
795
+ (host) => Object.values(screenControlMaps[host.id] ?? {}).flatMap((control) => {
796
+ const target2 = control.screenId ? byId.get(control.screenId) : void 0;
797
+ if (!target2 || !(0, import_codegen15.embedShapeBlocked)(host, target2)) return [];
798
+ return [
799
+ {
800
+ subject: `${host.name} \u2192 ${target2.name}`,
801
+ target: { kind: "control", screenId: host.id, controlId: control.id }
802
+ }
803
+ ];
804
+ })
805
+ );
806
+ }
807
+ });
808
+
809
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/function-rules.ts
810
+ var import_codegen16 = require("./index.js");
811
+ var functionNameUnshadowed = defineInvariant({
812
+ name: "function-name-unshadowed",
813
+ message: "invariant-function-name-shadowed",
814
+ severity: "blocking",
815
+ deps: ["features", "functions"],
816
+ validate: ({ features, functions }) => {
817
+ const appNames = new Set(Object.values(functions).map((fn) => fn.name));
818
+ return Object.values(features).flatMap(
819
+ (feature) => Object.values(feature.functions ?? {}).filter((fn) => appNames.has(fn.name)).map((fn) => ({
820
+ subject: `${feature.name} \xB7 ${fn.name}`,
821
+ target: { kind: "function", featureId: feature.id, functionId: fn.id }
822
+ }))
823
+ );
824
+ }
825
+ });
826
+ var functionTierFiled = defineInvariant({
827
+ name: "function-tier-filed",
828
+ message: "invariant-function-tier-misfiled",
829
+ severity: "blocking",
830
+ deps: ["features", "functions", "sharedShapes"],
831
+ validate: ({ features, functions, sharedShapes }) => {
832
+ const found = Object.values(functions).filter((fn) => (0, import_codegen16.tierOf)(fn) === "feature" && !fn.tier).filter((fn) => (0, import_codegen16.featureShapeIds)(fn).some((id) => !sharedShapes[id])).map((fn) => ({
833
+ subject: `shared \xB7 ${fn.name}`,
834
+ target: { kind: "function", functionId: fn.id }
835
+ }));
836
+ for (const feature of Object.values(features)) {
837
+ const foreign = (fn) => (0, import_codegen16.featureShapeIds)(fn).some((id) => !feature.shapes[id] && !sharedShapes[id]);
838
+ for (const fn of Object.values(feature.functions ?? {}).filter(foreign))
839
+ found.push({
840
+ subject: `${feature.name} \xB7 ${fn.name}`,
841
+ target: { kind: "function", featureId: feature.id, functionId: fn.id }
842
+ });
843
+ }
844
+ return found;
845
+ }
846
+ });
847
+ var namesBoth = (value) => {
848
+ if (Array.isArray(value)) return value.some(namesBoth);
849
+ if (!value || typeof value !== "object") return false;
850
+ const record = value;
851
+ if (typeof record.functionId === "string" && record.functionId !== "" && typeof record.oneFunction === "string" && record.oneFunction !== "") {
852
+ return true;
853
+ }
854
+ return Object.values(value).some(namesBoth);
855
+ };
856
+ var functionRefExclusive = defineInvariant({
857
+ name: "function-ref-exclusive",
858
+ message: "invariant-function-ref-both",
859
+ severity: "blocking",
860
+ deps: ["features", "screens"],
861
+ validate: ({ features, screens }) => [
862
+ ...Object.values(features).filter((feature) => namesBoth(feature.computeds) || namesBoth(feature.methods) || namesBoth(feature.subStores)).map((feature) => ({
863
+ subject: feature.name,
864
+ target: { kind: "panel", panel: "store", featureId: feature.id }
865
+ })),
866
+ ...screens.filter((screen) => namesBoth(screen.computeds) || namesBoth(screen.methods)).map((screen) => ({
867
+ subject: screen.name,
868
+ target: { kind: "screen", screenId: screen.id, panel: "screen" }
869
+ }))
870
+ ]
871
+ });
872
+
873
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/store-rules.ts
874
+ var import_codegen17 = require("./index.js");
875
+ var storeNameReserved = defineInvariant({
876
+ name: "store-name-reserved",
877
+ message: "invariant-store-name-reserved",
878
+ severity: "blocking",
879
+ deps: ["features"],
880
+ validate: ({ features }) => Object.values(features).flatMap((feature) => {
881
+ const at = { kind: "panel", panel: "store", featureId: feature.id };
882
+ return (0, import_codegen17.storesOf)(feature).flatMap((store) => {
883
+ const subStoreId = store.subStore?.id;
884
+ const owner = subStoreId ? { ...at, subStoreId } : at;
885
+ const found = Object.values(store.methods ?? {}).filter((method) => import_codegen17.RESERVED_METHOD_NAMES.includes(method.name)).map((method) => ({
886
+ subject: `${feature.name} \u2192 method ${method.name}`,
887
+ target: { ...owner, memberId: method.id }
888
+ }));
889
+ if (store.subStore && store.subStore.name === import_codegen17.MAIN_STORE_VALUE)
890
+ found.push({ subject: `${feature.name} \u2192 store ${store.subStore.name}`, target: owner });
891
+ return found;
892
+ });
893
+ })
894
+ });
895
+ var storeMemberNameUnique = defineInvariant({
896
+ name: "store-member-name-unique",
897
+ message: "invariant-store-member-name-taken",
898
+ severity: "blocking",
899
+ deps: ["features"],
900
+ validate: ({ features }) => Object.values(features).flatMap((feature) => {
901
+ const at = { kind: "panel", panel: "store", featureId: feature.id };
902
+ return (0, import_codegen17.storesOf)(feature).flatMap((store) => {
903
+ const subStoreId = store.subStore?.id;
904
+ const owner = subStoreId ? { ...at, subStoreId } : at;
905
+ const others = /* @__PURE__ */ new Set([
906
+ ...Object.values(store.methods ?? {}).map((member) => member.name),
907
+ ...Object.values(store.computeds ?? {}).map((member) => member.name)
908
+ ]);
909
+ return Object.values(store.properties ?? {}).filter((property) => others.has(property.name)).map((property) => ({
910
+ subject: `${feature.name} \u2192 ${property.name}`,
911
+ target: { ...owner, memberId: property.id }
912
+ }));
913
+ });
914
+ })
915
+ });
916
+
917
+ // apps/m-one-ui/src/app/pages/design/lib/screen-embed-helper.ts
918
+ var import_codegen18 = require("./index.js");
919
+ var isScreenControl = (control) => control.type === import_codegen18.ControlType.SCREEN && typeof control.screenId === "string";
920
+ function embeddedScreenIds(controlMap) {
921
+ return Object.values(controlMap).filter(isScreenControl).map((control) => control.screenId);
922
+ }
923
+ function reachableScreenIds(rootId, maps) {
924
+ const seen = /* @__PURE__ */ new Set();
925
+ const queue = [...embeddedScreenIds(maps[rootId] ?? {})];
926
+ while (queue.length) {
927
+ const id = queue.shift();
928
+ if (seen.has(id)) continue;
929
+ seen.add(id);
930
+ queue.push(...embeddedScreenIds(maps[id] ?? {}));
931
+ }
932
+ return seen;
933
+ }
934
+ var firesFromMount = (screen) => (0, import_codegen18.isFeatureScreen)(screen) && !!screen.autoCalls?.length;
935
+ function duplicateFeatureEmbeds(rootId, maps, screens) {
936
+ return [
937
+ ...new Set(
938
+ duplicateFeatureEmbedControls(rootId, maps, screens).map(
939
+ (mount) => mount.screenId
940
+ )
941
+ )
942
+ ].sort();
943
+ }
944
+ function duplicateFeatureEmbedControls(rootId, maps, screens) {
945
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
946
+ const mounts = /* @__PURE__ */ new Map();
947
+ const duplicates = /* @__PURE__ */ new Map();
948
+ const contains = (left, right) => [...right].every((gate) => left.has(gate));
949
+ const walk = (hostId, inherited, ancestors, instance) => {
950
+ if (ancestors.has(hostId)) return;
951
+ const seen = /* @__PURE__ */ new Set([...ancestors, hostId]);
952
+ const controls = maps[hostId] ?? {};
953
+ for (const control of Object.values(controls).filter(isScreenControl)) {
954
+ const gates = new Set(inherited);
955
+ const parents = /* @__PURE__ */ new Set();
956
+ let parent = control;
957
+ while (parent && !parents.has(parent.id)) {
958
+ parents.add(parent.id);
959
+ if (parent.variants?.length) {
960
+ gates.add(JSON.stringify([instance, "variants", parent.variants]));
961
+ }
962
+ if (parent.type === import_codegen18.ControlType.BRANCH_ARM) {
963
+ gates.add(
964
+ JSON.stringify([instance, "arm", parent.parentId, parent.id])
965
+ );
966
+ }
967
+ parent = parent.parentId ? controls[parent.parentId] : void 0;
968
+ }
969
+ const screen = byId.get(control.screenId);
970
+ if (screen && firesFromMount(screen)) {
971
+ const previous = mounts.get(screen.id) ?? [];
972
+ const mount = {
973
+ hostId,
974
+ controlId: control.id,
975
+ screenId: screen.id,
976
+ gates
977
+ };
978
+ previous.forEach((other) => {
979
+ if (contains(gates, other.gates) || contains(other.gates, gates)) {
980
+ duplicates.set(JSON.stringify([hostId, control.id]), mount);
981
+ duplicates.set(
982
+ JSON.stringify([other.hostId, other.controlId]),
983
+ other
984
+ );
985
+ }
986
+ });
987
+ previous.push(mount);
988
+ mounts.set(screen.id, previous);
989
+ }
990
+ walk(control.screenId, gates, seen, [...instance, control.id]);
991
+ }
992
+ };
993
+ walk(rootId, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), [rootId]);
994
+ return [...duplicates.values()].map(({ hostId, controlId, screenId }) => ({
995
+ hostId,
996
+ controlId,
997
+ screenId
998
+ }));
999
+ }
1000
+ function featureReachEdges(maps, screens) {
1001
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
1002
+ const edges = /* @__PURE__ */ new Map();
1003
+ for (const screen of screens) {
1004
+ if (!(0, import_codegen18.isFeatureScreen)(screen)) continue;
1005
+ for (const id of embeddedScreenIds(maps[screen.id] ?? {})) {
1006
+ const target2 = byId.get(id);
1007
+ if (!target2 || !(0, import_codegen18.isFeatureScreen)(target2)) continue;
1008
+ if (target2.featureId === screen.featureId) continue;
1009
+ const reached = edges.get(screen.featureId) ?? /* @__PURE__ */ new Set();
1010
+ reached.add(target2.featureId);
1011
+ edges.set(screen.featureId, reached);
1012
+ }
1013
+ }
1014
+ return edges;
1015
+ }
1016
+ function featuresReachedBy(featureId, edges) {
1017
+ const seen = /* @__PURE__ */ new Set();
1018
+ const queue = [...edges.get(featureId) ?? []];
1019
+ while (queue.length) {
1020
+ const id = queue.shift();
1021
+ if (seen.has(id)) continue;
1022
+ seen.add(id);
1023
+ queue.push(...edges.get(id) ?? []);
1024
+ }
1025
+ return seen;
1026
+ }
1027
+ function wouldCycleFeatures(hostFeatureId, targetFeatureId, edges) {
1028
+ if (hostFeatureId === targetFeatureId) return false;
1029
+ return targetFeatureId === hostFeatureId || featuresReachedBy(targetFeatureId, edges).has(hostFeatureId);
1030
+ }
1031
+ function screenEmbedProblems(host, maps, screens) {
1032
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
1033
+ const problems = [];
1034
+ const featureEdges = featureReachEdges(maps, screens);
1035
+ for (const control of Object.values(maps[host.id] ?? {})) {
1036
+ if (!isScreenControl(control)) continue;
1037
+ const target2 = byId.get(control.screenId);
1038
+ if (!target2) {
1039
+ problems.push({
1040
+ kind: "missing-screen",
1041
+ controlId: control.id,
1042
+ screenId: control.screenId
1043
+ });
1044
+ continue;
1045
+ }
1046
+ if (!(0, import_codegen18.canEmbedScreen)(host, target2)) {
1047
+ problems.push({
1048
+ kind: "illegal-target",
1049
+ controlId: control.id,
1050
+ screenId: target2.id
1051
+ });
1052
+ continue;
1053
+ }
1054
+ if ((0, import_codegen18.isFeatureScreen)(host) && (0, import_codegen18.isFeatureScreen)(target2) && wouldCycleFeatures(host.featureId, target2.featureId, featureEdges)) {
1055
+ problems.push({
1056
+ kind: "feature-cycle",
1057
+ controlId: control.id,
1058
+ screenId: target2.id,
1059
+ featureId: target2.featureId
1060
+ });
1061
+ continue;
1062
+ }
1063
+ const bound = control.screenInputs ?? {};
1064
+ for (const input of Object.values(target2.inputs ?? {})) {
1065
+ if (!input.required) continue;
1066
+ const binding = bound[input.id];
1067
+ if (!binding || binding.kind === "output") {
1068
+ problems.push({
1069
+ kind: "required-unbound",
1070
+ controlId: control.id,
1071
+ screenId: target2.id,
1072
+ input: input.name
1073
+ });
1074
+ }
1075
+ }
1076
+ }
1077
+ for (const screenId of duplicateFeatureEmbeds(host.id, maps, screens)) {
1078
+ problems.push({ kind: "duplicate-feature-screen", screenId });
1079
+ }
1080
+ if (reachableScreenIds(host.id, maps).has(host.id)) {
1081
+ problems.push({ kind: "cycle", screenId: host.id });
1082
+ }
1083
+ return problems;
1084
+ }
1085
+
1086
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/screen-control-reachable.ts
1087
+ var screenControlReachable = defineInvariant({
1088
+ name: "screen-control-reachable",
1089
+ message: "invariant-screen-control-unreachable",
1090
+ severity: "blocking",
1091
+ deps: ["screens", "screenControlMaps"],
1092
+ // `screenControlMaps` already holds the open Screen live (ADR 0163), so a
1093
+ // Screen edited since its last slot write is validated as it stands.
1094
+ validate: ({ screens, screenControlMaps: maps }) => {
1095
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
1096
+ const findings = screens.flatMap(
1097
+ (host) => screenEmbedProblems(host, maps, screens).flatMap(
1098
+ (problem) => {
1099
+ const subject = `${host.name} \u2192 ${byId.get(problem.screenId)?.name ?? problem.screenId}`;
1100
+ if (problem.kind === "illegal-target" || problem.kind === "feature-cycle") {
1101
+ return [
1102
+ {
1103
+ subject,
1104
+ screenRetarget: true,
1105
+ target: {
1106
+ kind: "control",
1107
+ screenId: host.id,
1108
+ controlId: problem.controlId
1109
+ }
1110
+ }
1111
+ ];
1112
+ }
1113
+ if (problem.kind === "duplicate-feature-screen") {
1114
+ const mountName = (mount) => {
1115
+ const control = maps[mount.hostId]?.[mount.controlId];
1116
+ return `${byId.get(mount.hostId)?.name ?? mount.hostId}.${String(control?.configs["name"] ?? mount.controlId)}`;
1117
+ };
1118
+ const mounts = duplicateFeatureEmbedControls(
1119
+ host.id,
1120
+ maps,
1121
+ screens
1122
+ ).filter((mount) => mount.screenId === problem.screenId);
1123
+ return mounts.map((mount) => ({
1124
+ message: "invariant-screen-control-duplicate",
1125
+ subject: `${mountName(mount)} \u2192 ${byId.get(mount.screenId)?.name ?? mount.screenId}, also at ${mounts.filter((other) => other !== mount).map(mountName).join(", ")}`,
1126
+ target: {
1127
+ kind: "control",
1128
+ screenId: mount.hostId,
1129
+ controlId: mount.controlId
1130
+ }
1131
+ }));
1132
+ }
1133
+ if (problem.kind === "missing-screen") {
1134
+ return [
1135
+ {
1136
+ subject: `${host.name} \u2192 missing Screen ${problem.screenId}`,
1137
+ screenRetarget: true,
1138
+ target: {
1139
+ kind: "control",
1140
+ screenId: host.id,
1141
+ controlId: problem.controlId
1142
+ }
1143
+ }
1144
+ ];
1145
+ }
1146
+ if (problem.kind === "cycle") {
1147
+ return [
1148
+ {
1149
+ subject: `${host.name} \u2192 embeds itself through its ScreenControls`,
1150
+ target: { kind: "screen", screenId: host.id, panel: "screen" }
1151
+ }
1152
+ ];
1153
+ }
1154
+ return [];
1155
+ }
1156
+ )
1157
+ );
1158
+ const unique = /* @__PURE__ */ new Map();
1159
+ findings.forEach((finding) => {
1160
+ const key = targetKey(finding.target);
1161
+ if (!unique.has(key) || !finding.message) unique.set(key, finding);
1162
+ });
1163
+ return [...unique.values()];
1164
+ }
1165
+ });
1166
+
1167
+ // apps/m-one-ui/src/app/pages/design/lib/screen-input-binding-check.ts
1168
+ var import_codegen19 = require("./index.js");
1169
+ var staticFits = (input, value) => {
1170
+ const primitive = (0, import_codegen19.inputPrimitive)(input);
1171
+ if (!primitive) return false;
1172
+ if (input.cardinality === "many") {
1173
+ return (0, import_codegen19.fixedItems)(value).every(
1174
+ (item) => staticFits({ ...input, cardinality: "one" }, item)
1175
+ );
1176
+ }
1177
+ if (input.cardinality !== "one") return false;
1178
+ if (primitive === "number")
1179
+ return value.trim() !== "" && !isNaN(Number(value));
1180
+ if (primitive === "boolean") return value === "true" || value === "false";
1181
+ return true;
1182
+ };
1183
+ var outputFits = (input, binding, controlMap, screens) => {
1184
+ if (input.required) return false;
1185
+ const sibling = controlMap[binding.controlId];
1186
+ if (!sibling || sibling.type !== import_codegen19.ControlType.SCREEN) return false;
1187
+ const siblingScreen = screens.find(
1188
+ (screen) => screen.id === sibling.screenId
1189
+ );
1190
+ if (!siblingScreen) return false;
1191
+ const output = (0, import_codegen19.listScreenOutputs)(siblingScreen.outputs).find(
1192
+ (entry) => entry.id === binding.outputId
1193
+ );
1194
+ const primitive = (0, import_codegen19.inputPrimitive)(input);
1195
+ return !!output && !!primitive && output.payload?.dataType === primitive && output.payload?.cardinality === input.cardinality;
1196
+ };
1197
+ var sourceScope = (host, control, controlMap, features, functions, enums) => {
1198
+ const feature = (0, import_codegen19.isFeatureScreen)(host) ? features[host.featureId] : void 0;
1199
+ const readable = feature ? (0, import_codegen19.readableMembers)(feature, import_codegen19.MAIN_STORE_OWNER) : void 0;
1200
+ const inScope = { ...functions, ...feature?.functions };
1201
+ const properties = readable?.properties ?? {};
1202
+ return {
1203
+ inputs: host.inputs ?? {},
1204
+ variables: host.variables ?? {},
1205
+ constants: host.constants ?? {},
1206
+ computeds: host.computeds ?? {},
1207
+ enums,
1208
+ functions: inScope,
1209
+ data: {
1210
+ controlId: control.id,
1211
+ controlMap,
1212
+ roots: (0, import_codegen19.propertiesWithComputeds)(
1213
+ properties,
1214
+ readable?.computeds ?? {},
1215
+ inScope
1216
+ ),
1217
+ properties,
1218
+ shapes: feature?.shapes ?? {},
1219
+ inputs: host.inputs,
1220
+ screenComputeds: host.computeds,
1221
+ screenVariables: host.variables,
1222
+ functions: inScope
1223
+ }
1224
+ };
1225
+ };
1226
+ function screenInputProblems(host, controlMap, screens, features, functions, enums) {
1227
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
1228
+ const problems = [];
1229
+ for (const control of Object.values(controlMap)) {
1230
+ if (!isScreenControl(control)) continue;
1231
+ const target2 = byId.get(control.screenId);
1232
+ if (!target2) continue;
1233
+ const bound = control.screenInputs ?? {};
1234
+ const scope = sourceScope(
1235
+ host,
1236
+ control,
1237
+ controlMap,
1238
+ features,
1239
+ functions,
1240
+ enums
1241
+ );
1242
+ for (const input of (0, import_codegen19.listScreenInputs)(target2.inputs)) {
1243
+ if (input.origin) continue;
1244
+ const binding = bound[input.id];
1245
+ const row = {
1246
+ controlId: control.id,
1247
+ targetScreenId: target2.id,
1248
+ inputId: input.id,
1249
+ inputName: input.name
1250
+ };
1251
+ if (!binding || binding.kind === "output" && input.required) {
1252
+ if (input.required) problems.push({ kind: "required-unbound", ...row });
1253
+ continue;
1254
+ }
1255
+ const fits = binding.kind === "static" ? staticFits(input, binding.value) : binding.kind === "output" ? outputFits(input, binding, controlMap, screens) : (0, import_codegen19.screenInputSourceOptions)(scope, {
1256
+ dataType: (0, import_codegen19.inputPrimitive)(input),
1257
+ cardinality: input.cardinality,
1258
+ declared: input.dataType,
1259
+ required: input.required
1260
+ }).some(
1261
+ (option) => option.value === (0, import_codegen19.screenInputSourceValue)(binding)
1262
+ );
1263
+ if (!fits) problems.push({ kind: "unfit", ...row });
1264
+ }
1265
+ }
1266
+ return problems;
1267
+ }
1268
+
1269
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/screen-input-bound.ts
1270
+ var screenInputBound = defineInvariant({
1271
+ name: "screen-input-bound",
1272
+ message: "invariant-screen-input-unbound",
1273
+ severity: "blocking",
1274
+ deps: [
1275
+ "screens",
1276
+ "screenControlMaps",
1277
+ "features",
1278
+ "functions",
1279
+ "enums"
1280
+ ],
1281
+ validate: ({ screens, screenControlMaps, features, functions, enums }) => screens.flatMap((host) => {
1282
+ const controlMap = screenControlMaps[host.id] ?? {};
1283
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
1284
+ return screenInputProblems(
1285
+ host,
1286
+ controlMap,
1287
+ screens,
1288
+ features,
1289
+ functions,
1290
+ enums
1291
+ ).map((problem) => ({
1292
+ message: problem.kind === "unfit" ? "invariant-screen-input-unfit" : "invariant-screen-input-unbound",
1293
+ subject: `${host.name} \u2192 ${byId.get(problem.targetScreenId)?.name ?? problem.targetScreenId}: ${problem.inputName}`,
1294
+ target: {
1295
+ kind: "control",
1296
+ screenId: host.id,
1297
+ controlId: problem.controlId,
1298
+ inputId: problem.inputId
1299
+ }
1300
+ }));
1301
+ })
1302
+ });
1303
+
1304
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/per-screen.ts
1305
+ function perScreen(judge) {
1306
+ const held = /* @__PURE__ */ new Map();
1307
+ const sameDeps = (a, b) => Object.keys(b).every((key) => a[key] === b[key]);
1308
+ return (screens, controlMaps, deps) => screens.flatMap((screen) => {
1309
+ const controlMap = controlMaps[screen.id];
1310
+ if (!controlMap) return [];
1311
+ const kept = held.get(screen.id);
1312
+ if (kept && kept.controlMap === controlMap && kept.screen === screen && sameDeps(kept.deps, deps)) {
1313
+ return kept.answer;
1314
+ }
1315
+ const answer = judge(controlMap, screen, deps);
1316
+ held.set(screen.id, { controlMap, screen, deps, answer });
1317
+ return answer;
1318
+ });
1319
+ }
1320
+
1321
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/branch-arm-reachable.ts
1322
+ var import_codegen20 = require("./index.js");
1323
+ var ATOM_CAP = 12;
1324
+ var foldText = (arm, names) => (0, import_codegen20.controlVariants)(arm).map((entry, index) => {
1325
+ const name = names.get(entry.id) ?? entry.id;
1326
+ const term = (0, import_codegen20.variantJoinIsNot)(entry.join) ? `!${name}` : name;
1327
+ if (index === 0) return term;
1328
+ return `${(0, import_codegen20.variantJoinIsAnd)(entry.join) ? "&&" : "||"} ${term}`;
1329
+ }).join(" ");
1330
+ var armSubject = (arm, names) => (0, import_codegen20.armKind)(arm) === "default" ? import_codegen20.ARM_KIND_LABEL.default : foldText(arm, names) || import_codegen20.ARM_KIND_LABEL.branch;
1331
+ var variantNames = (features, screens, currentScreenId) => {
1332
+ const screen = screens.find((one) => one.id === currentScreenId);
1333
+ const feature = screen?.featureId ? features[screen.featureId] : void 0;
1334
+ const names = /* @__PURE__ */ new Map();
1335
+ Object.values(feature?.variants ?? {}).forEach(
1336
+ (variant) => names.set(variant.id, variant.name)
1337
+ );
1338
+ return names;
1339
+ };
1340
+ var unreachableArmIds = (branchId, controlMap) => {
1341
+ const arms = (0, import_codegen20.orderedArms)(branchId, controlMap).filter(
1342
+ (arm) => (0, import_codegen20.armKind)(arm) === "default" || (0, import_codegen20.controlVariants)(arm).length > 0
1343
+ );
1344
+ if (arms.length < 2) return [];
1345
+ const atoms = [
1346
+ ...new Set(
1347
+ arms.flatMap((arm) => (0, import_codegen20.controlVariants)(arm).map((entry) => entry.id))
1348
+ )
1349
+ ];
1350
+ if (atoms.length > ATOM_CAP) return [];
1351
+ const reached = /* @__PURE__ */ new Set();
1352
+ const rows = 1 << atoms.length;
1353
+ for (let row = 0; row < rows; row++) {
1354
+ const on = atoms.filter((_, index) => row & 1 << index);
1355
+ for (const arm of arms) {
1356
+ if ((0, import_codegen20.armKind)(arm) === "default" || (0, import_codegen20.evaluateVariantGate)((0, import_codegen20.controlVariants)(arm), on)) {
1357
+ reached.add(arm.id);
1358
+ break;
1359
+ }
1360
+ }
1361
+ }
1362
+ return arms.filter((arm) => !reached.has(arm.id)).map((arm) => arm.id);
1363
+ };
1364
+ var unreachableArms = perScreen(
1365
+ (controlMap, screen, { features, screens }) => {
1366
+ const names = variantNames(features, screens, screen.id);
1367
+ return Object.entries(controlMap).flatMap(([branchId, control]) => {
1368
+ if (control.type !== import_codegen20.ControlType.VARIANT_BRANCH) return [];
1369
+ return unreachableArmIds(branchId, controlMap).map((armId) => ({
1370
+ subject: armSubject(controlMap[armId], names),
1371
+ target: {
1372
+ kind: "control",
1373
+ screenId: screen.id,
1374
+ controlId: armId
1375
+ }
1376
+ }));
1377
+ });
1378
+ }
1379
+ );
1380
+ var branchArmReachable = defineInvariant({
1381
+ name: "branch-arm-reachable",
1382
+ message: "invariant-branch-arm-unreachable",
1383
+ severity: "advisory",
1384
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
1385
+ deps: ["screenControlMaps", "features", "screens"],
1386
+ validate: ({ screenControlMaps, features, screens }) => unreachableArms(screens, screenControlMaps, { features, screens })
1387
+ });
1388
+
1389
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-args-bound.ts
1390
+ var import_codegen21 = require("./index.js");
1391
+ var computedArgsBound = defineInvariant({
1392
+ name: "computed-args-bound",
1393
+ message: "invariant-computed-args-unbound",
1394
+ severity: "advisory",
1395
+ deps: ["features", "screens", "functions"],
1396
+ validate: ({ features, screens, functions }) => {
1397
+ const scopeFor = (featureId) => featureId ? { ...functions, ...features[featureId]?.functions ?? {} } : functions;
1398
+ const broken = (fn, args) => !fn || !(0, import_codegen21.argsComplete)(fn, args);
1399
+ const stateFindings = Object.values(features).flatMap((feature) => {
1400
+ const fns = scopeFor(feature.id);
1401
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
1402
+ return Object.values(feature.computeds ?? {}).filter((computed) => broken((0, import_codegen21.stateComputedFunction)(computed, fns), computed.args)).map((computed) => ({
1403
+ subject: `${feature.name}.${computed.name}`,
1404
+ target: { kind: "screen", screenId }
1405
+ }));
1406
+ });
1407
+ const screenFindings = screens.flatMap((screen) => {
1408
+ const fns = scopeFor(
1409
+ (0, import_codegen21.isFeatureScreen)(screen) ? screen.featureId : void 0
1410
+ );
1411
+ return Object.values(screen.computeds ?? {}).filter(
1412
+ (computed) => broken((0, import_codegen21.screenComputedFunction)(computed, fns), computed.args)
1413
+ ).map((computed) => ({
1414
+ subject: `${screen.name}.${computed.name}`,
1415
+ target: { kind: "screen", screenId: screen.id }
1416
+ }));
1417
+ });
1418
+ return [...stateFindings, ...screenFindings];
1419
+ }
1420
+ });
1421
+
1422
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-args-typed.ts
1423
+ var import_codegen22 = require("./index.js");
1424
+ var computedArgsTyped = defineInvariant({
1425
+ name: "computed-args-typed",
1426
+ message: "invariant-computed-args-mistyped",
1427
+ severity: "blocking",
1428
+ deps: ["features", "screens", "screenControlMaps", "functions"],
1429
+ validate: ({ features, screens, screenControlMaps, functions }) => {
1430
+ const scopeFor = (featureId) => featureId ? { ...functions, ...features[featureId]?.functions ?? {} } : functions;
1431
+ const stateFindings = Object.values(features).flatMap((feature) => {
1432
+ const fns = scopeFor(feature.id);
1433
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
1434
+ const roots = (0, import_codegen22.propertiesWithComputeds)(
1435
+ feature.properties,
1436
+ feature.computeds,
1437
+ fns
1438
+ );
1439
+ return Object.values(feature.computeds ?? {}).flatMap(
1440
+ (computed) => (
1441
+ // A OneFunction call has no signature to repair; its own Invariant
1442
+ // raises it (`one-function-arg-mismatch`, ADR 0218).
1443
+ computed.functionId ? [{ ...computed, functionId: computed.functionId }] : []
1444
+ )
1445
+ ).filter((computed) => {
1446
+ const fn = fns[computed.functionId];
1447
+ return !!fn && (0, import_codegen22.mistypedStateArgs)(fn, computed.args, roots, feature.shapes).length > 0;
1448
+ }).map((computed) => ({
1449
+ subject: `${feature.name}.${computed.name}`,
1450
+ target: { kind: "screen", screenId },
1451
+ computedFix: {
1452
+ computedId: computed.id,
1453
+ featureId: feature.id,
1454
+ functionId: computed.functionId,
1455
+ params: fns[computed.functionId].params.map((param) => {
1456
+ const held = (0, import_codegen22.stateComputedArgHeldType)(
1457
+ computed.args[param.id],
1458
+ roots,
1459
+ feature.shapes
1460
+ );
1461
+ return held && !(0, import_codegen22.argAnswersParam)(held, param, feature.shapes) ? { ...param, ...held } : param;
1462
+ })
1463
+ }
1464
+ }));
1465
+ });
1466
+ const screenFindings = screens.flatMap((screen) => {
1467
+ const featureId = (0, import_codegen22.isFeatureScreen)(screen) ? screen.featureId : void 0;
1468
+ const fns = scopeFor(featureId);
1469
+ const feature = featureId ? features[featureId] : void 0;
1470
+ const scope = {
1471
+ constants: screen.constants,
1472
+ variables: (0, import_codegen22.withVariableEnums)(
1473
+ screen.variables ?? {},
1474
+ screenControlMaps[screen.id] ?? {}
1475
+ ),
1476
+ properties: feature ? (0, import_codegen22.propertiesWithComputeds)(
1477
+ feature.properties,
1478
+ feature.computeds,
1479
+ fns
1480
+ ) : {},
1481
+ shapes: feature?.shapes ?? {}
1482
+ };
1483
+ return Object.values(screen.computeds ?? {}).filter((computed) => {
1484
+ if ((0, import_codegen22.isOneFunctionComputed)(computed)) return false;
1485
+ const fn = (0, import_codegen22.screenComputedFunction)(computed, fns);
1486
+ return !!fn && (0, import_codegen22.mistypedScreenArgs)(
1487
+ fn,
1488
+ computed.args,
1489
+ screen.inputs ?? {},
1490
+ screen.computeds ?? {},
1491
+ fns,
1492
+ scope
1493
+ ).length > 0;
1494
+ }).map((computed) => {
1495
+ const fn = (0, import_codegen22.screenComputedFunction)(computed, fns);
1496
+ const params = fn.params.map((param) => {
1497
+ const arg = computed.args[param.id];
1498
+ const shapeId = arg?.source === "options" ? (0, import_codegen22.findOptionRowShapeId)(scope.shapes) : void 0;
1499
+ const held = shapeId ? {
1500
+ dataType: { type: "shape", shapeId },
1501
+ cardinality: "many"
1502
+ } : (0, import_codegen22.screenComputedArgHeldType)(
1503
+ arg,
1504
+ screen.inputs ?? {},
1505
+ screen.computeds ?? {},
1506
+ fns,
1507
+ scope
1508
+ );
1509
+ return held && !(0, import_codegen22.argAnswersParam)(held, param, scope.shapes) ? { ...param, ...held } : param;
1510
+ });
1511
+ const repaired = { ...fn, params };
1512
+ const canFix = !(0, import_codegen22.isPassthroughComputed)(computed) && !(0, import_codegen22.isOneFunctionComputed)(computed) && (0, import_codegen22.mistypedScreenArgs)(
1513
+ repaired,
1514
+ computed.args,
1515
+ screen.inputs ?? {},
1516
+ screen.computeds ?? {},
1517
+ fns,
1518
+ scope
1519
+ ).length === 0;
1520
+ return {
1521
+ subject: `${screen.name}.${computed.name}`,
1522
+ target: { kind: "screen", screenId: screen.id },
1523
+ ...canFix ? {
1524
+ computedFix: {
1525
+ computedId: computed.id,
1526
+ featureId,
1527
+ functionId: fn.id,
1528
+ params
1529
+ }
1530
+ } : {}
1531
+ };
1532
+ });
1533
+ });
1534
+ return [...stateFindings, ...screenFindings];
1535
+ }
1536
+ });
1537
+
1538
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/one-function-arg-mismatch.ts
1539
+ var import_codegen23 = require("./index.js");
1540
+ var sameDataType = (a, b) => a.type === "shape" ? b.type === "shape" && a.shapeId === b.shapeId : a.type === "form" ? b.type === "form" && a.formId === b.formId : a.type === b.type;
1541
+ var oneFunctionArgMismatch = defineInvariant({
1542
+ name: "one-function-arg-mismatch",
1543
+ message: "invariant-one-function-arg-mismatch",
1544
+ severity: "blocking",
1545
+ deps: ["features", "screens", "functions"],
1546
+ validate: ({ features, screens, functions }) => [
1547
+ ...screens.flatMap((screen) => {
1548
+ const featureId = (0, import_codegen23.isFeatureScreen)(screen) ? screen.featureId : void 0;
1549
+ const feature = featureId ? features[featureId] : void 0;
1550
+ const fns = feature ? { ...functions, ...feature.functions ?? {} } : functions;
1551
+ const scope = {
1552
+ constants: screen.constants,
1553
+ variables: screen.variables,
1554
+ properties: feature ? (0, import_codegen23.propertiesWithComputeds)(feature.properties, feature.computeds, fns) : {},
1555
+ shapes: feature?.shapes ?? {}
1556
+ };
1557
+ return Object.values(screen.computeds ?? {}).filter(import_codegen23.isOneFunctionComputed).filter((computed) => {
1558
+ const entry = (0, import_codegen23.oneFunctionOf)(computed.oneFunction);
1559
+ const returns = computed.returns;
1560
+ if (!entry || !returns) return false;
1561
+ if (!feature) return true;
1562
+ return entry.params.some((param) => {
1563
+ const arg = computed.args[param.id];
1564
+ if (!arg) return false;
1565
+ const held = (0, import_codegen23.screenComputedArgHeldType)(
1566
+ arg,
1567
+ screen.inputs ?? {},
1568
+ screen.computeds ?? {},
1569
+ fns,
1570
+ scope
1571
+ );
1572
+ if (!held) return false;
1573
+ if (!(0, import_codegen23.oneFunctionArgFits)(param, held, arg.source === "path"))
1574
+ return true;
1575
+ return entry.returnsRow && param.id === entry.rowParamId && (!sameDataType(held.dataType, returns.dataType) || // A `map` turned `map-many` (or back) moves the return
1576
+ // between the row and the row list (ADR 0205).
1577
+ (0, import_codegen23.oneFunctionReturns)(entry, held.dataType, held.cardinality).cardinality !== returns.cardinality);
1578
+ });
1579
+ }).map((computed) => ({
1580
+ subject: `${screen.name}.${computed.name}`,
1581
+ // Its own editor is where the binding is re-saved.
1582
+ target: {
1583
+ kind: "screen",
1584
+ screenId: screen.id,
1585
+ panel: "screen",
1586
+ computedId: computed.id
1587
+ }
1588
+ }));
1589
+ }),
1590
+ ...Object.values(features).flatMap(
1591
+ (feature) => conditionFindings(feature, functions)
1592
+ ),
1593
+ ...Object.values(features).flatMap(
1594
+ (feature) => stateComputedFindings(feature, functions)
1595
+ )
1596
+ ]
1597
+ });
1598
+ function stateComputedFindings(feature, functions) {
1599
+ const fns = { ...functions, ...feature.functions ?? {} };
1600
+ const stores = (0, import_codegen23.storesOf)(feature);
1601
+ const roots = Object.assign(
1602
+ {},
1603
+ ...stores.map(
1604
+ (owned) => (0, import_codegen23.propertiesWithComputeds)(owned.properties, owned.computeds, fns)
1605
+ )
1606
+ );
1607
+ return stores.flatMap(
1608
+ (owned) => Object.values(owned.computeds).filter(import_codegen23.isOneFunctionStateComputed).filter((computed) => {
1609
+ const entry = (0, import_codegen23.oneFunctionOf)(computed.oneFunction);
1610
+ const returns = computed.returns;
1611
+ if (!entry?.reach.includes("state-computed") || !returns) return false;
1612
+ const rowArg = computed.args[entry.rowParamId];
1613
+ const row = rowArg?.source === "path" ? (0, import_codegen23.statePathHeldType)(rowArg.path, roots, feature.shapes) : void 0;
1614
+ const fits = entry.params.every((param) => {
1615
+ const arg = computed.args[param.id];
1616
+ if (!arg) return true;
1617
+ const held = arg.source === "fixed" ? (0, import_codegen23.oneParamFixedHeld)(param, arg.value) : (0, import_codegen23.statePathHeldType)(arg.path, roots, feature.shapes);
1618
+ if (arg.source === "path" && !held) return true;
1619
+ return (0, import_codegen23.oneFunctionArgFits)(param, held, arg.source === "path");
1620
+ });
1621
+ if (!fits) return true;
1622
+ if (entry.returnsRow && row && (!sameDataType(row.dataType, returns.dataType) || (0, import_codegen23.oneFunctionReturns)(entry, row.dataType, row.cardinality).cardinality !== returns.cardinality))
1623
+ return true;
1624
+ const key = computed.args[import_codegen23.ONE_FUNCTION_KEY_PARAM];
1625
+ if (key?.source === "fixed" && entry.params.some((param) => param.id === import_codegen23.ONE_FUNCTION_KEY_PARAM) && row?.dataType.type === "shape") {
1626
+ const shape = feature.shapes[row.dataType.shapeId];
1627
+ return !!shape && !shape.keys.some(
1628
+ (member) => member.name === key.value && member.cardinality === "one" && member.dataType.type === "string"
1629
+ );
1630
+ }
1631
+ return false;
1632
+ }).map((computed) => ({
1633
+ subject: `${feature.name}.${computed.name}`,
1634
+ target: {
1635
+ kind: "panel",
1636
+ panel: "store",
1637
+ featureId: feature.id,
1638
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
1639
+ memberId: computed.id
1640
+ }
1641
+ }))
1642
+ );
1643
+ }
1644
+ function conditionFindings(feature, functions) {
1645
+ const fns = { ...functions, ...feature.functions ?? {} };
1646
+ const stores = (0, import_codegen23.storesOf)(feature);
1647
+ const roots = Object.assign(
1648
+ {},
1649
+ ...stores.map(
1650
+ (owned) => (0, import_codegen23.propertiesWithComputeds)(owned.properties, owned.computeds, fns)
1651
+ )
1652
+ );
1653
+ const mismatched = (condition) => {
1654
+ if (!condition.oneFunction) return false;
1655
+ const entry = (0, import_codegen23.oneFunctionOf)(condition.oneFunction);
1656
+ if (!entry?.reach.includes("call-condition")) return true;
1657
+ return entry.params.some((param) => {
1658
+ const binding = condition.args[param.id];
1659
+ if (binding?.source !== "store") return false;
1660
+ const held = (0, import_codegen23.statePathHeldType)(binding.path, roots, feature.shapes);
1661
+ return !!held && !(0, import_codegen23.oneFunctionArgFits)(param, held, true);
1662
+ });
1663
+ };
1664
+ const computeMismatched = (compute) => {
1665
+ if (!compute.oneFunction) return false;
1666
+ const entry = (0, import_codegen23.oneFunctionOf)(compute.oneFunction);
1667
+ if (!entry?.reach.includes("call-compute") || !compute.returns) return true;
1668
+ const returns = compute.returns;
1669
+ return entry.params.some((param) => {
1670
+ const binding = compute.args[param.id];
1671
+ if (binding?.source !== "store") return false;
1672
+ const held = (0, import_codegen23.statePathHeldType)(binding.path, roots, feature.shapes);
1673
+ if (!held) return false;
1674
+ if (!(0, import_codegen23.oneFunctionArgFits)(param, held, true)) return true;
1675
+ return entry.returnsRow && param.id === entry.rowParamId && (!sameDataType(held.dataType, returns.dataType) || (0, import_codegen23.oneFunctionReturns)(entry, held.dataType, held.cardinality).cardinality !== returns.cardinality);
1676
+ });
1677
+ };
1678
+ return stores.flatMap(
1679
+ (owned) => Object.values(owned.methods).filter(
1680
+ (method) => (method.conditions ?? []).some(mismatched) || (method.computes ?? []).some(computeMismatched)
1681
+ ).map((method) => ({
1682
+ subject: `${feature.name}.${method.name}`,
1683
+ target: {
1684
+ kind: "panel",
1685
+ panel: "store",
1686
+ featureId: feature.id,
1687
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
1688
+ memberId: method.id
1689
+ }
1690
+ }))
1691
+ );
1692
+ }
1693
+
1694
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/one-function-required-param.ts
1695
+ var import_codegen24 = require("./index.js");
1696
+ var requiresParam = (method, name) => (method.params ?? []).some(
1697
+ (param) => param.name === name && param.required === true
1698
+ ) || method.inputs.some(
1699
+ (mapping) => mapping.source === "args" && mapping.arg === name && mapping.target[0] === "path"
1700
+ );
1701
+ var oneFunctionRequiredParam = defineInvariant({
1702
+ name: "one-function-required-param",
1703
+ message: "invariant-one-function-required-param",
1704
+ severity: "blocking",
1705
+ deps: ["features", "screens", "screenControlMaps"],
1706
+ validate: ({ features, screens, screenControlMaps }) => screens.flatMap((screen) => {
1707
+ if (!(0, import_codegen24.isFeatureScreen)(screen)) return [];
1708
+ const feature = features[screen.featureId];
1709
+ if (!feature) return [];
1710
+ const methods = Object.assign(
1711
+ {},
1712
+ ...(0, import_codegen24.storesOf)(feature).map((owned) => owned.methods)
1713
+ );
1714
+ const computeds = screen.computeds ?? {};
1715
+ return Object.values(screenControlMaps[screen.id] ?? {}).flatMap(
1716
+ (control) => Object.entries(control.outputs ?? {}).flatMap(
1717
+ ([output, methodId]) => {
1718
+ const method = methods[methodId];
1719
+ if (!method) return [];
1720
+ return (control.outputArgs?.[output] ?? []).filter((row) => {
1721
+ const root = row.binding?.root;
1722
+ if (row.source !== "binding" || root?.kind !== "screen_computed")
1723
+ return false;
1724
+ const computed = computeds[root.id];
1725
+ const name = row.target[0];
1726
+ return !!computed && (0, import_codegen24.isOneFunctionComputed)(computed) && (0, import_codegen24.screenComputedFunction)(computed, {})?.returnUndefined === true && !!name && requiresParam(method, name);
1727
+ }).map((row) => ({
1728
+ subject: `${screen.name}.${method.name}(${row.target[0]})`,
1729
+ target: {
1730
+ kind: "control",
1731
+ screenId: screen.id,
1732
+ controlId: control.id
1733
+ }
1734
+ }));
1735
+ }
1736
+ )
1737
+ );
1738
+ })
1739
+ });
1740
+
1741
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/confirm-unattended-call.ts
1742
+ var import_codegen25 = require("./index.js");
1743
+ var confirmUnattendedCall = defineInvariant({
1744
+ name: "confirm-unattended-call",
1745
+ message: "invariant-confirm-unattended",
1746
+ severity: "advisory",
1747
+ deps: ["features", "screens"],
1748
+ validate: ({ features, screens }) => {
1749
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
1750
+ return Object.values(features).flatMap((feature) => {
1751
+ const asking = new Set(
1752
+ Object.values(feature.methods).filter((method) => !!(0, import_codegen25.drawnConfirm)(method)).map((method) => method.id)
1753
+ );
1754
+ if (!asking.size) return [];
1755
+ const named2 = (methodId) => feature.methods[methodId]?.name ?? methodId;
1756
+ const fromHook = (feature.hook?.calls ?? []).filter((call) => asking.has(call.methodId)).map((call) => ({
1757
+ subject: `${feature.name}.${named2(call.methodId)}`,
1758
+ target: {
1759
+ kind: "screen",
1760
+ screenId: featureScreen(feature.id)
1761
+ }
1762
+ }));
1763
+ const fromTimers = Object.values(feature.timers ?? {}).flatMap(
1764
+ (timer) => timer.calls.filter((call) => asking.has(call.methodId)).map((call) => ({
1765
+ subject: `${feature.name}.${timer.name} \u2192 ${named2(call.methodId)}`,
1766
+ target: {
1767
+ kind: "screen",
1768
+ screenId: featureScreen(feature.id)
1769
+ }
1770
+ }))
1771
+ );
1772
+ const fromAutoCalls = screens.filter((screen) => screen.featureId === feature.id).flatMap(
1773
+ (screen) => (screen.autoCalls ?? []).flatMap(
1774
+ (call) => call.methodId && asking.has(call.methodId) ? [call.methodId] : []
1775
+ ).map((methodId) => ({
1776
+ subject: `${screen.name} \u2192 ${named2(methodId)}`,
1777
+ target: { kind: "screen", screenId: screen.id }
1778
+ }))
1779
+ );
1780
+ return [...fromHook, ...fromTimers, ...fromAutoCalls];
1781
+ });
1782
+ }
1783
+ });
1784
+
1785
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/close-overlay-off-overlay.ts
1786
+ var import_codegen27 = require("./index.js");
1787
+
1788
+ // apps/m-one-ui/src/app/pages/design/lib/screen-link.ts
1789
+ var import_codegen26 = require("./index.js");
1790
+ function overlayLinks(fromScreenId, map) {
1791
+ const links = [];
1792
+ Object.values(map).forEach((control) => {
1793
+ Object.entries(control.directives ?? {}).forEach(([name, directive]) => {
1794
+ if (!(0, import_codegen26.isOverlayDirectiveName)(name)) return;
1795
+ const configs = directive.overlayId ? map[directive.overlayId]?.configs : directive.configs;
1796
+ const component = configs?.["component"];
1797
+ if (typeof component !== "string" || !component) return;
1798
+ links.push({
1799
+ kind: "overlay-component",
1800
+ fromScreenId,
1801
+ controlId: directive.overlayId ?? control.id,
1802
+ toScreenId: component
1803
+ });
1804
+ });
1805
+ });
1806
+ return links;
1807
+ }
1808
+ var cardKind = (control) => control.type === import_codegen26.ControlType.SECTION_CAROUSEL ? "carousel-element" : "card-element";
1809
+ function controlMapLinks(fromScreenId, map) {
1810
+ const links = [];
1811
+ Object.values(map).forEach((control) => {
1812
+ if (isScreenControl(control)) {
1813
+ links.push({
1814
+ kind: "screen-control",
1815
+ fromScreenId,
1816
+ controlId: control.id,
1817
+ toScreenId: control.screenId
1818
+ });
1819
+ }
1820
+ const cardScreenId = control.cards?.screenId;
1821
+ if (cardScreenId) {
1822
+ links.push({
1823
+ kind: cardKind(control),
1824
+ fromScreenId,
1825
+ controlId: control.id,
1826
+ toScreenId: cardScreenId
1827
+ });
1828
+ }
1829
+ Object.keys(control.outputOpens ?? {}).forEach((output) => {
1830
+ const screenId = (0, import_codegen26.outputOpenOf)(control.outputOpens, output)?.screenId;
1831
+ if (!screenId) return;
1832
+ links.push({
1833
+ kind: "output-open",
1834
+ fromScreenId,
1835
+ controlId: control.id,
1836
+ toScreenId: screenId
1837
+ });
1838
+ });
1839
+ const searchScreenId = control.search?.screenId;
1840
+ if (searchScreenId) {
1841
+ links.push({
1842
+ kind: "search-results",
1843
+ fromScreenId,
1844
+ controlId: control.id,
1845
+ toScreenId: searchScreenId
1846
+ });
1847
+ }
1848
+ });
1849
+ return [...links, ...overlayLinks(fromScreenId, map)];
1850
+ }
1851
+ function navLinks(navMap) {
1852
+ const links = [];
1853
+ Object.values(navMap).forEach((nav) => {
1854
+ if (nav.pageId) {
1855
+ links.push({
1856
+ kind: "nav-url",
1857
+ fromNavId: nav.navId,
1858
+ toScreenId: nav.pageId
1859
+ });
1860
+ }
1861
+ if (nav.componentKey) {
1862
+ links.push({
1863
+ kind: "nav-component",
1864
+ fromNavId: nav.navId,
1865
+ toScreenId: nav.componentKey
1866
+ });
1867
+ }
1868
+ if (nav.rowSource?.kind === "screen" && nav.rowSource.screenId) {
1869
+ links.push({
1870
+ kind: "nav-rows",
1871
+ fromNavId: nav.navId,
1872
+ toScreenId: nav.rowSource.screenId
1873
+ });
1874
+ }
1875
+ if (nav.searchAnswer?.kind === "screen" && nav.searchAnswer.screenId) {
1876
+ links.push({
1877
+ kind: "search-answer",
1878
+ fromNavId: nav.navId,
1879
+ toScreenId: nav.searchAnswer.screenId
1880
+ });
1881
+ }
1882
+ });
1883
+ return links;
1884
+ }
1885
+ function methodLinks(features) {
1886
+ const links = [];
1887
+ Object.values(features).forEach((feature) => {
1888
+ const stores = [
1889
+ { subStoreId: void 0, methods: feature.methods },
1890
+ ...Object.values(feature.subStores ?? {}).map((sub) => ({
1891
+ subStoreId: sub.id,
1892
+ methods: sub.methods
1893
+ }))
1894
+ ];
1895
+ stores.forEach(({ subStoreId, methods }) => {
1896
+ Object.values(methods).forEach((method) => {
1897
+ const screenId = method.open?.screenId;
1898
+ if (!screenId) return;
1899
+ links.push({
1900
+ kind: "method-open",
1901
+ fromFeatureId: feature.id,
1902
+ methodId: method.id,
1903
+ ...subStoreId ? { subStoreId } : {},
1904
+ toScreenId: screenId
1905
+ });
1906
+ });
1907
+ });
1908
+ });
1909
+ return links;
1910
+ }
1911
+ function screenLinks(maps, navMap, features = {}) {
1912
+ const fromControls = Object.entries(maps).flatMap(
1913
+ ([screenId, map]) => controlMapLinks(screenId, map)
1914
+ );
1915
+ return [...fromControls, ...navLinks(navMap), ...methodLinks(features)];
1916
+ }
1917
+ var inboundLinks = (links, screenId) => links.filter((link) => link.toScreenId === screenId);
1918
+
1919
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/close-overlay-off-overlay.ts
1920
+ var OVERLAY_KINDS = [
1921
+ "overlay-component",
1922
+ "output-open",
1923
+ "method-open"
1924
+ ];
1925
+ var closeOverlayOffOverlay = defineInvariant({
1926
+ name: "close-overlay-off-overlay",
1927
+ message: "invariant-close-overlay-off-overlay",
1928
+ severity: "advisory",
1929
+ // The link index's own dependencies. Read on a coarse change, the habit
1930
+ // ADR 0126 keeps: what opens a Screen is not this Screen's own business.
1931
+ deps: ["screens", "screenControlMaps", "navMap", "features"],
1932
+ validate: ({ screens, screenControlMaps, navMap, features }) => {
1933
+ const closing = screens.map((screen) => ({
1934
+ screen,
1935
+ controls: Object.values(screenControlMaps[screen.id] ?? {}).filter(
1936
+ import_codegen27.controlUsesOverlayRef
1937
+ )
1938
+ })).filter(({ controls }) => controls.length);
1939
+ if (!closing.length) return [];
1940
+ const links = screenLinks(screenControlMaps, navMap, features);
1941
+ return closing.flatMap(
1942
+ ({ screen, controls }) => inboundLinks(links, screen.id).some(
1943
+ (link) => OVERLAY_KINDS.includes(link.kind)
1944
+ ) ? [] : controls.map((control) => ({
1945
+ subject: `${screen.name} \u2192 ${String(
1946
+ control.configs["name"] ?? control.id
1947
+ )}`,
1948
+ target: {
1949
+ kind: "control",
1950
+ screenId: screen.id,
1951
+ controlId: control.id
1952
+ }
1953
+ }))
1954
+ );
1955
+ }
1956
+ });
1957
+
1958
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-unattended-call.ts
1959
+ var import_codegen28 = require("./index.js");
1960
+ var outcomeUnattendedCall = defineInvariant({
1961
+ name: "outcome-on-unattended-call",
1962
+ message: "invariant-outcome-unattended",
1963
+ severity: "advisory",
1964
+ // Every Screen's Controls rather than the open one's: a hook fires a method
1965
+ // some other Screen's button armed, and the finding belongs to the Feature.
1966
+ // Read on a coarse change, which is what this dependency already costs.
1967
+ deps: ["features", "screens", "screenControlMaps"],
1968
+ validate: ({ features, screens, screenControlMaps }) => {
1969
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
1970
+ return Object.values(features).flatMap((feature) => {
1971
+ const armed = (0, import_codegen28.methodArms)(
1972
+ screens.filter((screen) => screen.featureId === feature.id).map((screen) => screenControlMaps[screen.id] ?? {})
1973
+ );
1974
+ const wired = new Set(Object.keys(armed));
1975
+ if (!wired.size) return [];
1976
+ const named2 = (methodId) => feature.methods[methodId]?.name ?? methodId;
1977
+ const fromHook = (feature.hook?.calls ?? []).filter((call) => wired.has(call.methodId)).map((call) => ({
1978
+ subject: `${feature.name}.${named2(call.methodId)}`,
1979
+ target: {
1980
+ kind: "screen",
1981
+ screenId: featureScreen(feature.id)
1982
+ }
1983
+ }));
1984
+ const fromTimers = Object.values(feature.timers ?? {}).flatMap(
1985
+ (timer) => timer.calls.filter((call) => wired.has(call.methodId)).map((call) => ({
1986
+ subject: `${feature.name}.${timer.name} \u2192 ${named2(call.methodId)}`,
1987
+ target: {
1988
+ kind: "screen",
1989
+ screenId: featureScreen(feature.id)
1990
+ }
1991
+ }))
1992
+ );
1993
+ const fromAutoCalls = screens.filter((screen) => screen.featureId === feature.id).flatMap(
1994
+ (screen) => (screen.autoCalls ?? []).flatMap(
1995
+ (call) => call.methodId && wired.has(call.methodId) ? [call.methodId] : []
1996
+ ).map((methodId) => ({
1997
+ subject: `${screen.name} \u2192 ${named2(methodId)}`,
1998
+ target: { kind: "screen", screenId: screen.id }
1999
+ }))
2000
+ );
2001
+ return [...fromHook, ...fromTimers, ...fromAutoCalls];
2002
+ });
2003
+ }
2004
+ });
2005
+
2006
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-call-nested.ts
2007
+ var import_codegen29 = require("./index.js");
2008
+ var outcomeCallNested = defineInvariant({
2009
+ name: "outcome-call-nested",
2010
+ message: "invariant-outcome-call-nested",
2011
+ severity: "advisory",
2012
+ deps: ["screens", "screenControlMaps"],
2013
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
2014
+ const onScreen = (outcomes) => outcomes.flatMap(import_codegen29.nestedOutcomeCalls).map((id) => ({
2015
+ subject: `${screen.name} \u2192 ${id}`,
2016
+ target: { kind: "screen", screenId: screen.id }
2017
+ }));
2018
+ const onControls = Object.values(
2019
+ screenControlMaps[screen.id] ?? {}
2020
+ ).flatMap(
2021
+ (control) => Object.values(control.outputOutcomes ?? {}).flatMap(import_codegen29.nestedOutcomeCalls).map((id) => ({
2022
+ subject: `${screen.name} \u2192 ${control.id} \u2192 ${id}`,
2023
+ target: {
2024
+ kind: "control",
2025
+ screenId: screen.id,
2026
+ controlId: control.id
2027
+ }
2028
+ }))
2029
+ );
2030
+ return [
2031
+ ...onControls,
2032
+ ...onScreen([
2033
+ ...Object.values(screen.methods ?? {}).flatMap((handler) => [
2034
+ handler.outcome,
2035
+ ...(handler.calls ?? []).map((one) => one.outcome)
2036
+ ]),
2037
+ ...(screen.autoCalls ?? []).map((call) => call.outcome)
2038
+ ])
2039
+ ];
2040
+ })
2041
+ });
2042
+
2043
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/reaction-writes-own-watch.ts
2044
+ var reactionWritesOwnWatch = defineInvariant({
2045
+ name: "reaction-writes-own-watch",
2046
+ message: "invariant-reaction-writes-own-watch",
2047
+ severity: "blocking",
2048
+ deps: ["screens"],
2049
+ validate: ({ screens }) => screens.flatMap(
2050
+ (screen) => (screen.autoCalls ?? []).flatMap((call) => {
2051
+ const watched = new Set(
2052
+ (call.reads ?? []).filter((read) => !read.path.length).map(
2053
+ (read) => read.root.kind === "screen_variable" || read.root.kind === "property" ? `${read.root.kind}:${read.root.id}` : ""
2054
+ ).filter(Boolean)
2055
+ );
2056
+ if (!watched.size) return [];
2057
+ const written = [
2058
+ ...(call.screenWrites ?? []).map((row) => ({
2059
+ key: `screen_variable:${row.variableId}`,
2060
+ name: screen.variables?.[row.variableId]?.name ?? row.variableId
2061
+ })),
2062
+ ...(call.writes ?? []).map((row) => ({
2063
+ key: `property:${row.propertyId}`,
2064
+ name: row.propertyId
2065
+ }))
2066
+ ];
2067
+ return written.filter((row) => watched.has(row.key)).map((row) => ({
2068
+ subject: `${screen.name} \u2192 ${row.name}`,
2069
+ target: { kind: "screen", screenId: screen.id }
2070
+ }));
2071
+ })
2072
+ )
2073
+ });
2074
+
2075
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-nav-complete.ts
2076
+ var import_codegen30 = require("./index.js");
2077
+ var outcomeNavComplete = defineInvariant({
2078
+ name: "outcome-nav-complete",
2079
+ message: "invariant-outcome-nav-incomplete",
2080
+ severity: "advisory",
2081
+ deps: ["screens", "screenControlMaps", "navMap"],
2082
+ validate: ({ screens, screenControlMaps, navMap }) => screens.flatMap((screen) => {
2083
+ const controlMap = screenControlMaps[screen.id] ?? {};
2084
+ return Object.values(controlMap).flatMap((control) => {
2085
+ const broken = Object.values(control.outputOutcomes ?? {}).some(
2086
+ (outcome) => import_codegen30.OUTCOME_ARMS.some(
2087
+ (arm) => !!(0, import_codegen30.validateOutcomeNav)(outcome?.[arm]?.nav, navMap)
2088
+ )
2089
+ ) || (0, import_codegen30.controlNavReferences)(control).some(
2090
+ (row) => row.some((navId) => !navMap[navId])
2091
+ );
2092
+ if (!broken) return [];
2093
+ return [
2094
+ {
2095
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
2096
+ target: {
2097
+ kind: "control",
2098
+ screenId: screen.id,
2099
+ controlId: control.id
2100
+ }
2101
+ }
2102
+ ];
2103
+ });
2104
+ })
2105
+ });
2106
+
2107
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/field-check-bound.ts
2108
+ var import_codegen31 = require("./index.js");
2109
+ var fieldCheckBound = defineInvariant({
2110
+ name: "field-check-bound",
2111
+ message: "invariant-field-check-unbound",
2112
+ severity: "advisory",
2113
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
2114
+ deps: ["screenControlMaps", "features", "functions", "screens"],
2115
+ validate: ({ screenControlMaps, features, functions, screens }) => unboundChecks(screens, screenControlMaps, { features, functions })
2116
+ });
2117
+ var unboundChecks = perScreen(
2118
+ (controlMap, screen, {
2119
+ features,
2120
+ functions
2121
+ }) => {
2122
+ const feature = (0, import_codegen31.isFeatureScreen)(screen) ? features[screen.featureId] : void 0;
2123
+ const properties = feature?.properties ?? {};
2124
+ const sources = (0, import_codegen31.limitSources)({
2125
+ inputs: screen.inputs,
2126
+ constants: screen.constants,
2127
+ variables: screen.variables,
2128
+ screenComputeds: screen.computeds,
2129
+ properties,
2130
+ computeds: feature?.computeds,
2131
+ functions: { ...functions, ...feature?.functions ?? {} }
2132
+ });
2133
+ return Object.entries(controlMap).flatMap(([controlId, control]) => {
2134
+ if (control.type !== import_codegen31.ControlType.FIELD) return [];
2135
+ const checks = (0, import_codegen31.fieldChecks)(control);
2136
+ if (!checks.length) return [];
2137
+ const formId = (0, import_codegen31.owningFormId)(controlId, controlMap);
2138
+ const broken = checks.some((check) => {
2139
+ if ((0, import_codegen31.checkKind)(check) !== "function") {
2140
+ return !(0, import_codegen31.isCheckComplete)(
2141
+ check,
2142
+ functions,
2143
+ controlMap,
2144
+ properties,
2145
+ sources
2146
+ );
2147
+ }
2148
+ const fn = functions[check.functionId];
2149
+ if (!fn) return true;
2150
+ if (!(0, import_codegen31.isFieldCheckEligible)(fn)) return true;
2151
+ const writtenFor = (0, import_codegen31.fieldCheckFormId)(fn);
2152
+ if (writtenFor && writtenFor !== formId) return true;
2153
+ return !(0, import_codegen31.isCheckComplete)(check, functions, controlMap, properties);
2154
+ });
2155
+ if (!broken) return [];
2156
+ return [
2157
+ {
2158
+ subject: (0, import_codegen31.resolveFieldName)({
2159
+ id: controlId,
2160
+ configs: control.configs
2161
+ }),
2162
+ target: {
2163
+ kind: "control",
2164
+ screenId: screen.id,
2165
+ controlId
2166
+ }
2167
+ }
2168
+ ];
2169
+ });
2170
+ }
2171
+ );
2172
+
2173
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/function-case-args.ts
2174
+ var import_codegen32 = require("./index.js");
2175
+ var functionCaseArgs = defineInvariant({
2176
+ name: "function-case-args",
2177
+ message: "invariant-function-case-args",
2178
+ severity: "advisory",
2179
+ deps: ["features", "functions", "sharedShapes"],
2180
+ validate: ({ features, functions, sharedShapes }) => {
2181
+ const shared = sharedShapes ?? {};
2182
+ return [
2183
+ ...(0, import_codegen32.listFunctions)(functions).map((fn) => ({
2184
+ fn,
2185
+ featureId: void 0,
2186
+ shapes: (0, import_codegen32.shapesInReach)(void 0, shared)
2187
+ })),
2188
+ ...Object.values(features).flatMap(
2189
+ (feature) => (0, import_codegen32.listFunctions)(feature.functions).map((fn) => ({
2190
+ fn,
2191
+ featureId: feature.id,
2192
+ shapes: (0, import_codegen32.shapesInReach)(feature, shared)
2193
+ }))
2194
+ )
2195
+ ].filter(({ fn, shapes }) => (0, import_codegen32.staleCases)(fn, shapes).length > 0).map(({ fn, featureId, shapes }) => ({
2196
+ subject: `${fn.name}: ${(0, import_codegen32.staleCases)(fn, shapes).map((entry) => entry.name).join(", ")}`,
2197
+ target: {
2198
+ kind: "function",
2199
+ ...featureId ? { featureId } : {},
2200
+ functionId: fn.id
2201
+ }
2202
+ }));
2203
+ }
2204
+ });
2205
+
2206
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/filter-group-squeeze-orphan.ts
2207
+ var import_codegen33 = require("./index.js");
2208
+ var orphanIds = (groupId, controlMap) => {
2209
+ const found = [];
2210
+ const seen = /* @__PURE__ */ new Set();
2211
+ const walk = (id) => {
2212
+ if (seen.has(id)) return;
2213
+ seen.add(id);
2214
+ for (const childId of controlMap[id]?.childrens ?? []) {
2215
+ const child = controlMap[childId];
2216
+ if (!child) continue;
2217
+ if (child.type === import_codegen33.ControlType.SECTION_FILTER) continue;
2218
+ if (child.type === import_codegen33.ControlType.COL) {
2219
+ walk(childId);
2220
+ continue;
2221
+ }
2222
+ found.push(childId);
2223
+ }
2224
+ };
2225
+ walk(groupId);
2226
+ return found;
2227
+ };
2228
+ var filterGroupSqueezeOrphan = defineInvariant({
2229
+ name: "filter-group-squeeze-orphan",
2230
+ message: "invariant-filter-group-squeeze-orphan",
2231
+ severity: "advisory",
2232
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
2233
+ deps: ["screenControlMaps", "screens"],
2234
+ validate: ({ screenControlMaps, screens }) => squeezedOrphans(screens, screenControlMaps, {})
2235
+ });
2236
+ var squeezedOrphans = perScreen(
2237
+ (controlMap, screen) => Object.entries(controlMap).flatMap(([groupId, control]) => {
2238
+ if (control.type !== import_codegen33.ControlType.SECTION_FILTER_GROUP) return [];
2239
+ const parentId = control.parentId;
2240
+ const squeezed = !!control.configs?.["squeeze"] || !!parentId && controlMap[parentId]?.type === import_codegen33.ControlType.SECTION_HEADER;
2241
+ if (!squeezed) return [];
2242
+ return orphanIds(groupId, controlMap).map((orphanId) => ({
2243
+ subject: import_codegen33.CONTROL_LABEL[controlMap[orphanId].type],
2244
+ target: {
2245
+ kind: "control",
2246
+ screenId: screen.id,
2247
+ controlId: orphanId
2248
+ }
2249
+ }));
2250
+ })
2251
+ );
2252
+
2253
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/context-group-primary-unique.ts
2254
+ var import_codegen34 = require("./index.js");
2255
+ var contextGroupPrimaryUnique = defineInvariant({
2256
+ name: "context-group-primary-unique",
2257
+ message: "invariant-context-group-primary-unique",
2258
+ severity: "advisory",
2259
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
2260
+ deps: ["screenControlMaps", "screens"],
2261
+ validate: ({ screenControlMaps, screens }) => duplicatePrimaries(screens, screenControlMaps, {})
2262
+ });
2263
+ var duplicatePrimaries = perScreen(
2264
+ (controlMap, screen) => Object.entries(controlMap).flatMap(([groupId, control]) => {
2265
+ if (control.type !== import_codegen34.ControlType.SECTION_BUTTON_GROUP) return [];
2266
+ if (control.configs?.["variant"] !== "context") return [];
2267
+ const primaries = (control.childrens ?? []).filter((childId) => {
2268
+ const child = controlMap[childId];
2269
+ return child?.type === import_codegen34.ControlType.BUTTON && child.configs?.["variant"] === "primary";
2270
+ });
2271
+ return primaries.slice(1).map((buttonId) => ({
2272
+ subject: import_codegen34.CONTROL_LABEL[import_codegen34.ControlType.BUTTON],
2273
+ target: {
2274
+ kind: "control",
2275
+ screenId: screen.id,
2276
+ controlId: buttonId
2277
+ }
2278
+ }));
2279
+ })
2280
+ );
2281
+
2282
+ // apps/m-one-ui/src/app/pages/design/lib/hand-binding-helper.ts
2283
+ var import_codegen36 = require("./index.js");
2284
+
2285
+ // apps/m-one-ui/src/app/pages/design/lib/control-outputs.ts
2286
+ var import_codegen35 = require("./index.js");
2287
+ var embeddedOutputsOf = (screens, contractOf = () => void 0) => (control) => {
2288
+ if (control.type !== import_codegen35.ControlType.SCREEN) return void 0;
2289
+ if (control.handRef) {
2290
+ const contract = contractOf(control.handRef);
2291
+ return contract ? (0, import_codegen35.handTargetOf)(contract).outputs : void 0;
2292
+ }
2293
+ return screens.find((screen) => screen.id === control.screenId)?.outputs;
2294
+ };
2295
+ var embeddedOutputOf = (control, key, embedded) => embedded?.(control)?.[(0, import_codegen35.outputArmBaseKey)(key)];
2296
+ var outputPayloadShape = (control, key, embedded) => control.type === import_codegen35.ControlType.SCREEN ? embeddedOutputOf(control, key, embedded)?.payload?.dataType ?? "void" : (0, import_codegen35.payloadShape)(key, control.type, control.configs);
2297
+ var outputCallLabelOf = (control, key, embedded) => {
2298
+ const label2 = (0, import_codegen35.outputCallLabel)(control, key);
2299
+ const name = embeddedOutputOf(control, key, embedded)?.name;
2300
+ const base = (0, import_codegen35.outputArmBaseKey)(key);
2301
+ return name && label2.startsWith(base) ? `${name}${label2.slice(base.length)}` : label2;
2302
+ };
2303
+ var CONTROL_OUTPUTS = {
2304
+ [import_codegen35.ControlType.BUTTON]: ["clicked"],
2305
+ [import_codegen35.ControlType.CONTEXT_MENU]: ["action"],
2306
+ // The picker's own value, once the User has moved it — the write half of the
2307
+ // controlled binding, drawn as a StateWrite rather than as `[(audience)]`
2308
+ // (ADR 0187, ADR 0065). Offered whatever the two halves hold: a picker bound
2309
+ // to no `audience` still edits its own value and still fires this.
2310
+ [import_codegen35.ControlType.AUDIENCE_PICKER]: ["audienceChange"],
2311
+ [import_codegen35.ControlType.CARD]: ["clicked"],
2312
+ // `submitted` is offered only under a Button declaring `isSubmit` — see
2313
+ // `outputsOf` below.
2314
+ [import_codegen35.ControlType.FORM]: ["submitted", "dataChange", "formInitialized"],
2315
+ // The Field's own `dataChange`, at field granularity — the value the User
2316
+ // typed into this one field, not the form's record (libs/one ADR 0032).
2317
+ // Needs no Button, the way the form's does not (see `outputsOf`).
2318
+ [import_codegen35.ControlType.FIELD]: ["dataChange"],
2319
+ [import_codegen35.ControlType.SECTION]: ["inView"],
2320
+ [import_codegen35.ControlType.SECTION_HEADER]: ["actionClick", "action", "back"],
2321
+ // Debounced already by the component — what arrives here is the term the User
2322
+ // stopped typing, which is the only thing worth binding a call to.
2323
+ [import_codegen35.ControlType.SECTION_SEARCH]: ["searchChange"],
2324
+ // One output for the whole bar, carrying the Button that was pressed — an
2325
+ // `m-action` names its Buttons rather than holding them, so there is no
2326
+ // per-Button Control for a binding to sit on (ADR 0009).
2327
+ [import_codegen35.ControlType.SECTION_ACTION]: ["clicked"],
2328
+ // Which slide is showing, every time it changes — by drag, by indicator, or
2329
+ // by the clock. Two spellings of the one event, because what a caller binds
2330
+ // differs: `slideChange` carries the position, `itemChange` the row behind it,
2331
+ // which is what a call needing the slide's own data takes.
2332
+ [import_codegen35.ControlType.SECTION_CAROUSEL]: ["slideChange", "itemChange"],
2333
+ // The whole group's selection, every time any Filter beneath it changes
2334
+ // (libs/one ADR 0025). Per-change rather than on-close: a group has no single
2335
+ // close event full-width, and `switchMap` in the emitted store already drops
2336
+ // the responses of calls a later change supersedes.
2337
+ [import_codegen35.ControlType.SECTION_FILTER_GROUP]: ["filterChange"],
2338
+ // Offered only outside a group — see `outputsOf` below.
2339
+ [import_codegen35.ControlType.SECTION_FILTER]: ["filterChange"],
2340
+ // One payload, `{offset, perPage}`, and both members are pickable — a
2341
+ // CallArgMapping reading `event.offset` gets a number, which is what an
2342
+ // ApiOperation's query param takes. The whole `$event` works too, unlike a
2343
+ // FilterGroup's list of pairs (ADR 0097).
2344
+ [import_codegen35.ControlType.SECTION_PAGINATION]: ["paginationChange"],
2345
+ // `{id, direction}`, after the rows were reordered in place — bound when the
2346
+ // table holds one page of a longer list and whoever fetches has to sort the
2347
+ // rest (ADR 0148). `tableInitialized` fires once, after the first render —
2348
+ // no payload, the Form's `formInitialized` for a table.
2349
+ [import_codegen35.ControlType.SECTION_TABLE]: ["sortChange", "tableInitialized"],
2350
+ // Repeated rows emit their Repeat item; static rows emit `undefined`.
2351
+ [import_codegen35.ControlType.SECTION_TABLE_ROW]: ["rowClick"],
2352
+ // The preset picked, and the window it drew as `{from, to}` ISO text — both
2353
+ // members pickable, each a date an ApiOperation's param takes. Fired when the
2354
+ // reader picks a preset or lets go of the navigator, never because an input
2355
+ // moved, so a fetch bound here cannot loop (libs/one GLOSSARY.md
2356
+ // SectionChart, the SectionPagination rule of ADR 0097).
2357
+ [import_codegen35.ControlType.SECTION_CHART]: ["rangeChange", "windowChange"],
2358
+ // Offered under the `link` variant alone — see `outputsOf` below.
2359
+ [import_codegen35.ControlType.TEXT_OUTPUT]: ["clicked"]
2360
+ };
2361
+ function outputsOf(control, controlMap, embedded) {
2362
+ if (control.type === import_codegen35.ControlType.SCREEN) {
2363
+ return (0, import_codegen35.listScreenOutputs)(embedded?.(control)).map((output) => output.id);
2364
+ }
2365
+ if (control.type === import_codegen35.ControlType.PLUGIN) {
2366
+ return (0, import_codegen35.pluginNamesOf)(control.configs, import_codegen35.PLUGIN_OUTPUTS_KEY);
2367
+ }
2368
+ const offered = CONTROL_OUTPUTS[control.type] ?? [];
2369
+ if (control.type === import_codegen35.ControlType.FORM) {
2370
+ return controlMap && !hasSubmitButton(control, controlMap) && !(control.id && (0, import_codegen35.hasSubmitTargetButton)(control.id, controlMap)) ? offered.filter((output) => output !== "submitted") : offered;
2371
+ }
2372
+ if (control.type === import_codegen35.ControlType.SECTION_FILTER) {
2373
+ return controlMap && insideFilterGroup(control, controlMap) ? [] : offered;
2374
+ }
2375
+ if (control.type !== import_codegen35.ControlType.TEXT_OUTPUT) return offered;
2376
+ const variant = control.configs?.["variant"];
2377
+ const isLink = variant === "link" || variant === "link-small";
2378
+ return isLink && !(0, import_codegen35.hasRouterLinkDirective)(control) ? offered : [];
2379
+ }
2380
+ function hasSubmitButton(control, controlMap) {
2381
+ const queue = [...control.childrens ?? []];
2382
+ const seen = /* @__PURE__ */ new Set();
2383
+ while (queue.length) {
2384
+ const id = queue.shift();
2385
+ if (!id || seen.has(id)) continue;
2386
+ seen.add(id);
2387
+ const child = controlMap[id];
2388
+ if (!child || child.type === import_codegen35.ControlType.FORM) continue;
2389
+ if (child.type === import_codegen35.ControlType.BUTTON && child.configs?.["isSubmit"] === true)
2390
+ return true;
2391
+ queue.push(...child.childrens ?? []);
2392
+ }
2393
+ return false;
2394
+ }
2395
+ function insideFilterGroup(control, controlMap) {
2396
+ const seen = /* @__PURE__ */ new Set();
2397
+ let current = control.parentId ? controlMap[control.parentId] : void 0;
2398
+ while (current && !seen.has(current.id)) {
2399
+ if (current.type === import_codegen35.ControlType.SECTION_FILTER_GROUP) return true;
2400
+ seen.add(current.id);
2401
+ current = current.parentId ? controlMap[current.parentId] : void 0;
2402
+ }
2403
+ return false;
2404
+ }
2405
+ function offersOutputKey(control, controlMap, key, embedded) {
2406
+ if ((0, import_codegen35.hasRouterLink)(control.directives?.["routerLink"]?.configs)) return false;
2407
+ const base = (0, import_codegen35.outputArmBaseKey)(key);
2408
+ const output = (0, import_codegen35.isMenuActionKey)(base) ? import_codegen35.MENU_ACTION_OUTPUT : base;
2409
+ return outputsOf(control, controlMap, embedded).includes(output);
2410
+ }
2411
+ var OUTPUT_MAP_FIELDS = [
2412
+ ...import_codegen35.OUTPUT_GROUP_MAPS,
2413
+ "outputCalls",
2414
+ "outputArms"
2415
+ ];
2416
+ var wiredOutputKeys = (control) => [
2417
+ ...new Set(
2418
+ OUTPUT_MAP_FIELDS.flatMap(
2419
+ (field) => Object.keys(control[field] ?? {}).map(import_codegen35.outputArmBaseKey)
2420
+ )
2421
+ )
2422
+ ];
2423
+ var CLEARED_OUTPUT_WIRING = Object.fromEntries(
2424
+ OUTPUT_MAP_FIELDS.map((field) => [field, void 0])
2425
+ );
2426
+
2427
+ // apps/m-one-ui/src/app/pages/design/lib/hand-binding-helper.ts
2428
+ var handControls = (controlMap) => Object.values(controlMap).filter(
2429
+ (control) => control.type === import_codegen36.ControlType.SCREEN && !!control.handRef
2430
+ );
2431
+ var unmountableReason = (handRef, hand) => {
2432
+ const contract = hand.contracts[handRef];
2433
+ if (!contract) {
2434
+ const skipped = hand.skips.find(
2435
+ (skip) => `${skip.slice}/${skip.className}` === handRef
2436
+ );
2437
+ return skipped ? skipped.reason : "gone";
2438
+ }
2439
+ const blockers = (0, import_codegen36.mountBlockers)(contract);
2440
+ return blockers.length ? `required: ${blockers.join(", ")}` : void 0;
2441
+ };
2442
+ var memberOf = (screen, binding) => {
2443
+ if (binding.kind === "input") {
2444
+ const found = screen.inputs?.[binding.inputId];
2445
+ if (!found)
2446
+ return { type: void 0, cardinality: void 0, present: false };
2447
+ return {
2448
+ type: found.dataType.type,
2449
+ cardinality: found.cardinality,
2450
+ present: true
2451
+ };
2452
+ }
2453
+ if (binding.kind === "variable") {
2454
+ const found = screen.variables?.[binding.variableId];
2455
+ if (!found)
2456
+ return { type: void 0, cardinality: void 0, present: false };
2457
+ return {
2458
+ type: found.dataType,
2459
+ cardinality: found.cardinality,
2460
+ present: true
2461
+ };
2462
+ }
2463
+ if (binding.kind === "constant") {
2464
+ const found = screen.constants?.[binding.constantId];
2465
+ if (!found)
2466
+ return { type: void 0, cardinality: void 0, present: false };
2467
+ return { type: found.dataType, cardinality: "one", present: true };
2468
+ }
2469
+ return void 0;
2470
+ };
2471
+ var brokenHandBindings = (control, contract, screen, controlMap, hand) => {
2472
+ const problems = [];
2473
+ const inputs = new Map(contract.inputs.map((one) => [one.name, one]));
2474
+ const outputs = new Map(contract.outputs.map((one) => [one.name, one]));
2475
+ Object.entries(control.screenInputs ?? {}).forEach(([name, binding]) => {
2476
+ const declared = inputs.get(name);
2477
+ if (!declared) {
2478
+ problems.push(name);
2479
+ return;
2480
+ }
2481
+ if (binding.kind === "static") return;
2482
+ if (binding.kind === "output") {
2483
+ const producer = controlMap[binding.controlId];
2484
+ const from = producer?.handRef ? hand.contracts[producer.handRef]?.outputs.find(
2485
+ (one) => one.name === binding.outputId
2486
+ )?.payload : void 0;
2487
+ if (producer?.handRef && !from) problems.push(name);
2488
+ else if (from && (from.type !== declared.type || from.cardinality !== declared.cardinality)) {
2489
+ problems.push(name);
2490
+ }
2491
+ return;
2492
+ }
2493
+ const member = memberOf(screen, binding);
2494
+ if (!member) return;
2495
+ if (!member.present || member.type !== declared.type || member.cardinality !== declared.cardinality) {
2496
+ problems.push(name);
2497
+ }
2498
+ });
2499
+ wiredOutputKeys(control).forEach((name) => {
2500
+ if (!outputs.has(name)) problems.push(name);
2501
+ });
2502
+ return [...new Set(problems)].sort();
2503
+ };
2504
+ var unboundRequiredInputs = (control, contract) => {
2505
+ const bound = control.screenInputs ?? {};
2506
+ return contract.inputs.filter((declared) => declared.required && !bound[declared.name]).map((declared) => declared.name).sort();
2507
+ };
2508
+ var mountedContract = (control, hand) => {
2509
+ const contract = control.handRef ? hand.contracts[control.handRef] : void 0;
2510
+ return contract && (0, import_codegen36.isMountable)(contract) ? contract : void 0;
2511
+ };
2512
+
2513
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-binding-resolves.ts
2514
+ var handBindingResolves = defineInvariant({
2515
+ name: "hand-binding-resolves",
2516
+ message: "invariant-hand-binding-unresolved",
2517
+ severity: "blocking",
2518
+ deps: ["screens", "screenControlMaps", "hand"],
2519
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2520
+ const controlMap = screenControlMaps[screen.id] ?? {};
2521
+ return handControls(controlMap).flatMap((control) => {
2522
+ const contract = mountedContract(control, hand);
2523
+ if (!contract) return [];
2524
+ const broken = brokenHandBindings(
2525
+ control,
2526
+ contract,
2527
+ screen,
2528
+ controlMap,
2529
+ hand
2530
+ );
2531
+ if (!broken.length) return [];
2532
+ return [
2533
+ {
2534
+ subject: `${screen.name} \u2192 ${contract.ref}: ${broken.join(", ")}`,
2535
+ target: {
2536
+ kind: "control",
2537
+ screenId: screen.id,
2538
+ controlId: control.id
2539
+ }
2540
+ }
2541
+ ];
2542
+ });
2543
+ })
2544
+ });
2545
+
2546
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-required-input-bound.ts
2547
+ var handRequiredInputBound = defineInvariant({
2548
+ name: "hand-required-input-bound",
2549
+ message: "invariant-hand-required-input-unbound",
2550
+ severity: "blocking",
2551
+ deps: ["screens", "screenControlMaps", "hand"],
2552
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2553
+ const controlMap = screenControlMaps[screen.id] ?? {};
2554
+ return handControls(controlMap).flatMap((control) => {
2555
+ const contract = mountedContract(control, hand);
2556
+ if (!contract) return [];
2557
+ const missing = unboundRequiredInputs(control, contract);
2558
+ if (!missing.length) return [];
2559
+ return [
2560
+ {
2561
+ subject: `${screen.name} \u2192 ${contract.ref}: ${missing.join(", ")}`,
2562
+ target: {
2563
+ kind: "control",
2564
+ screenId: screen.id,
2565
+ controlId: control.id
2566
+ }
2567
+ }
2568
+ ];
2569
+ });
2570
+ })
2571
+ });
2572
+
2573
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-screen-resolves.ts
2574
+ var handScreenResolves = defineInvariant({
2575
+ name: "hand-screen-resolves",
2576
+ message: "invariant-hand-screen-unresolved",
2577
+ severity: "blocking",
2578
+ deps: ["screens", "screenControlMaps", "hand"],
2579
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2580
+ const controlMap = screenControlMaps[screen.id] ?? {};
2581
+ return handControls(controlMap).flatMap((control) => {
2582
+ const reason = unmountableReason(control.handRef, hand);
2583
+ if (!reason) return [];
2584
+ return [
2585
+ {
2586
+ subject: `${screen.name} \u2192 ${control.handRef} (${reason})`,
2587
+ target: {
2588
+ kind: "control",
2589
+ screenId: screen.id,
2590
+ controlId: control.id
2591
+ }
2592
+ }
2593
+ ];
2594
+ });
2595
+ })
2596
+ });
2597
+
2598
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/reserved-variant-name-free.ts
2599
+ var import_codegen37 = require("./index.js");
2600
+ var reservedVariantNameFree = defineInvariant({
2601
+ name: "reserved-variant-name-free",
2602
+ message: "invariant-reserved-variant-name",
2603
+ severity: "blocking",
2604
+ deps: ["features", "screens"],
2605
+ validate: ({ features, screens }) => {
2606
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
2607
+ const fromFeatures = Object.values(features).flatMap((feature) => {
2608
+ const held = [
2609
+ ...Object.values(feature.properties).map((property) => property.name),
2610
+ ...Object.values(feature.variants).map((variant) => variant.name)
2611
+ ].filter(import_codegen37.isReservedVariantName);
2612
+ return held.length ? [
2613
+ {
2614
+ subject: `${feature.name}.${held[0]}`,
2615
+ target: {
2616
+ kind: "screen",
2617
+ screenId: featureScreen(feature.id)
2618
+ }
2619
+ }
2620
+ ] : [];
2621
+ });
2622
+ const fromScreens = screens.flatMap((screen) => {
2623
+ const held = [
2624
+ ...Object.values(screen.inputs ?? {}),
2625
+ ...Object.values(screen.outputs ?? {}),
2626
+ ...Object.values(screen.constants ?? {}),
2627
+ ...Object.values(screen.computeds ?? {})
2628
+ ].map((member) => member.name).filter(import_codegen37.isReservedVariantName);
2629
+ return held.length ? [
2630
+ {
2631
+ subject: `${screen.name}.${held[0]}`,
2632
+ target: { kind: "screen", screenId: screen.id }
2633
+ }
2634
+ ] : [];
2635
+ });
2636
+ return [...fromFeatures, ...fromScreens];
2637
+ }
2638
+ });
2639
+
2640
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/feature-name-free.ts
2641
+ var import_codegen38 = require("./index.js");
2642
+ var featureNameFree = defineInvariant({
2643
+ name: "feature-name-free",
2644
+ message: "invariant-feature-name-reserved",
2645
+ severity: "advisory",
2646
+ deps: ["features", "screens"],
2647
+ validate: ({ features, screens }) => Object.values(features).filter((feature) => (0, import_codegen38.isReservedFeatureName)(feature.name)).map((feature) => ({
2648
+ subject: feature.name,
2649
+ target: {
2650
+ kind: "screen",
2651
+ screenId: screens.find((screen) => screen.featureId === feature.id)?.id ?? ""
2652
+ }
2653
+ }))
2654
+ });
2655
+
2656
+ // apps/m-one-ui/src/app/pages/design/lib/compare-register.ts
2657
+ var import_codegen42 = require("./index.js");
2658
+
2659
+ // apps/m-one-ui/src/app/pages/design/lib/code-tree.ts
2660
+ var import_codegen39 = require("./index.js");
2661
+ var CODE_AREA_ROOTS = [
2662
+ ["pages", `${import_codegen39.PAGES_ROOT}/`],
2663
+ ["features", `${import_codegen39.FEATURES_ROOT}/`],
2664
+ ["widgets", `${import_codegen39.WIDGETS_ROOT}/`],
2665
+ ["shared", "src/app/shared/"],
2666
+ ["mag_assets", "mag_assets/"],
2667
+ ["magmonium", ".magmonium/"]
2668
+ ];
2669
+
2670
+ // apps/m-one-ui/src/app/pages/design/lib/function-register.ts
2671
+ var import_codegen40 = require("./index.js");
2672
+ var everyFunction = (appFunctions, features) => [
2673
+ ...(0, import_codegen40.listFunctions)(appFunctions).map((fn) => ({ fn })),
2674
+ ...(0, import_codegen40.listFeatures)(features).flatMap(
2675
+ (feature) => (0, import_codegen40.listFunctions)(feature.functions).map((fn) => ({
2676
+ fn,
2677
+ featureId: feature.id
2678
+ }))
2679
+ )
2680
+ ];
2681
+ var canonical = (value) => {
2682
+ if (Array.isArray(value)) return value.map(canonical);
2683
+ if (!value || typeof value !== "object") return value;
2684
+ return Object.fromEntries(
2685
+ Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, canonical(entry)])
2686
+ );
2687
+ };
2688
+
2689
+ // apps/m-one-ui/src/app/pages/design/lib/shape-register.ts
2690
+ var import_codegen41 = require("./index.js");
2691
+
2692
+ // apps/m-one-ui/src/app/pages/design/lib/compare-register.ts
2693
+ var import_codegen43 = require("./index.js");
2694
+ var everyShape = (features, sharedShapes = {}) => [
2695
+ ...(0, import_codegen42.listShapes)(sharedShapes).map((shape) => ({ shape })),
2696
+ ...(0, import_codegen42.listFeatures)(features).flatMap(
2697
+ (feature) => (0, import_codegen42.listShapes)(feature.shapes).filter((shape) => !(0, import_codegen42.isSharedShapeId)(shape.id)).map((shape) => ({ shape, featureId: feature.id }))
2698
+ )
2699
+ ];
2700
+ var distinctPair = (kind, a, b) => ({ kind, ids: a < b ? [a, b] : [b, a] });
2701
+ var isDistinct = (distinct, kind, a, b) => {
2702
+ const [first, second] = distinctPair(kind, a, b).ids;
2703
+ return distinct.some(
2704
+ (pair) => pair.kind === kind && pair.ids[0] === first && pair.ids[1] === second
2705
+ );
2706
+ };
2707
+ var liveDistinct = (distinct, features, appFunctions, sharedShapes = {}) => {
2708
+ const shapes = new Set(
2709
+ everyShape(features, sharedShapes).map(({ shape }) => shape.id)
2710
+ );
2711
+ const functions = new Set(
2712
+ everyFunction(appFunctions, features).map(({ fn }) => fn.id)
2713
+ );
2714
+ return distinct.filter((pair) => {
2715
+ const live = pair.kind === "shapes" ? shapes : functions;
2716
+ return live.has(pair.ids[0]) && live.has(pair.ids[1]);
2717
+ });
2718
+ };
2719
+ var shapeStructureKey = (shape) => JSON.stringify(
2720
+ canonical(
2721
+ [...shape.keys].sort((a, b) => a.name.localeCompare(b.name)).map((key) => [key.name, key.dataType, key.cardinality])
2722
+ )
2723
+ );
2724
+ var shapeMatchIndex = (all, distinct = []) => {
2725
+ const byStructure = /* @__PURE__ */ new Map();
2726
+ for (const entry of all) {
2727
+ if (!entry.shape.keys.length) continue;
2728
+ const key = shapeStructureKey(entry.shape);
2729
+ byStructure.set(key, [...byStructure.get(key) ?? [], entry]);
2730
+ }
2731
+ const index = /* @__PURE__ */ new Map();
2732
+ for (const group of byStructure.values()) {
2733
+ for (const entry of group) {
2734
+ const matches = group.filter(
2735
+ (other) => other.shape.id !== entry.shape.id && !isDistinct(distinct, "shapes", other.shape.id, entry.shape.id)
2736
+ );
2737
+ if (matches.length) index.set(entry.shape.id, matches);
2738
+ }
2739
+ }
2740
+ return index;
2741
+ };
2742
+
2743
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/shape-match.ts
2744
+ var shapeMatch = defineInvariant({
2745
+ name: "shape-match",
2746
+ message: "invariant-shape-match",
2747
+ severity: "advisory",
2748
+ deps: ["features", "functions", "sharedShapes", "distinct"],
2749
+ validate: ({ features, functions, sharedShapes, distinct }) => {
2750
+ const shapes = everyShape(features, sharedShapes);
2751
+ const index = shapeMatchIndex(
2752
+ shapes,
2753
+ liveDistinct(distinct, features, functions, sharedShapes)
2754
+ );
2755
+ return shapes.filter(({ shape }) => index.has(shape.id)).map(({ shape, featureId }) => ({
2756
+ subject: `${shape.name} \u2261 ${(index.get(shape.id) ?? []).map((match) => match.shape.name).join(", ")}`,
2757
+ target: {
2758
+ kind: "compare",
2759
+ tab: "shapes",
2760
+ item: featureId ? { featureId, id: shape.id } : { id: shape.id }
2761
+ }
2762
+ }));
2763
+ }
2764
+ });
2765
+
2766
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/theme-selection-resolves.ts
2767
+ var themeSelectionResolves = defineInvariant({
2768
+ name: "theme-selection-resolves",
2769
+ message: "invariant-theme-selection-missing",
2770
+ severity: "advisory",
2771
+ deps: ["wcConfig", "themes", "themeCatalog"],
2772
+ validate: ({ wcConfig, themes, themeCatalog }) => {
2773
+ const selected = wcConfig.theme?.trim();
2774
+ if (!selected) return [];
2775
+ if (themes[selected] || themeCatalog.includes(selected)) return [];
2776
+ return [
2777
+ { subject: selected, target: { kind: "panel", panel: "config" } }
2778
+ ];
2779
+ }
2780
+ });
2781
+
2782
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/search-feed-resolves.ts
2783
+ var import_codegen44 = require("./index.js");
2784
+ var searchFeedResolves = defineInvariant({
2785
+ name: "search-feed-resolves",
2786
+ message: "invariant-search-feed-unresolved",
2787
+ severity: "advisory",
2788
+ deps: ["features", "functions"],
2789
+ validate: ({ features, functions }) => Object.values(features).flatMap(
2790
+ (feature) => (0, import_codegen44.storesOf)(feature).flatMap((store) => {
2791
+ const feed = store.searchFeed;
2792
+ if (!feed) return [];
2793
+ const property = store.properties[feed.propertyId];
2794
+ const rows = property?.cardinality === "many" ? property.dataType : void 0;
2795
+ if (feed.functionId) {
2796
+ const fn = feature.functions?.[feed.functionId] ?? functions[feed.functionId];
2797
+ if (fn && (0, import_codegen44.isSearchFeedFunction)(fn, property, feature.shapes) && (0, import_codegen44.searchFeedArgsComplete)(fn, feed.args)) {
2798
+ return [];
2799
+ }
2800
+ } else if (rows && (0, import_codegen44.resolveSearchFeedMember)(feed.title, rows, feature.shapes)) {
2801
+ return [];
2802
+ }
2803
+ return [
2804
+ {
2805
+ subject: property ? `${feature.name} \u2192 ${property.name}` : feature.name,
2806
+ target: {
2807
+ kind: "panel",
2808
+ panel: "store",
2809
+ featureId: feature.id,
2810
+ ...store.owner.kind === "sub" ? { subStoreId: store.owner.subStoreId } : {}
2811
+ }
2812
+ }
2813
+ ];
2814
+ })
2815
+ )
2816
+ });
2817
+
2818
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/search-answer-resolves.ts
2819
+ var import_codegen45 = require("./index.js");
2820
+ var searchAnswerResolves = defineInvariant({
2821
+ name: "search-answer-resolves",
2822
+ message: "invariant-search-answer-unresolved",
2823
+ severity: "advisory",
2824
+ deps: ["navMap", "screens"],
2825
+ validate: ({ navMap, screens }) => {
2826
+ const screenId = (0, import_codegen45.searchAnswerScreenId)(navMap);
2827
+ if (!screenId) return [];
2828
+ const screen = screens.find((s) => s.id === screenId);
2829
+ if (screen && (screen.kind === "app_widget" || screen.kind === "feature")) {
2830
+ return [];
2831
+ }
2832
+ return [
2833
+ {
2834
+ subject: screen?.name ?? screenId,
2835
+ target: { kind: "nav", navId: import_codegen45.SEARCH_NAV_ID }
2836
+ }
2837
+ ];
2838
+ }
2839
+ });
2840
+
2841
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/state-path-resolves.ts
2842
+ var import_codegen46 = require("./index.js");
2843
+ var reachOf = (feature, shared) => ({
2844
+ properties: Object.assign(
2845
+ {},
2846
+ ...(0, import_codegen46.storesOf)(feature).map((store) => store.properties)
2847
+ ),
2848
+ shapes: (0, import_codegen46.shapesInReach)(feature, shared)
2849
+ });
2850
+ function declaredIds(value, into = /* @__PURE__ */ new Set()) {
2851
+ if (Array.isArray(value)) value.forEach((item) => declaredIds(item, into));
2852
+ else if (value && typeof value === "object") {
2853
+ const id = value.id;
2854
+ if (typeof id === "string") into.add(id);
2855
+ Object.values(value).forEach((item) => declaredIds(item, into));
2856
+ }
2857
+ return into;
2858
+ }
2859
+ var STATE_ROOT_KINDS = /* @__PURE__ */ new Set(["property", "computed"]);
2860
+ var STATE_SOURCES = /* @__PURE__ */ new Set(["state", "path", "store"]);
2861
+ function holdsDeadPath(value, reach, roots, state) {
2862
+ if (Array.isArray(value)) {
2863
+ if (value.length > 1 && value.every((id) => typeof id === "string") && value[0] in reach.properties && !value.slice(1).some((id) => id in reach.properties)) {
2864
+ return !(0, import_codegen46.isPathResolved)(value, reach.properties, reach.shapes);
2865
+ }
2866
+ return value.some((item) => holdsDeadPath(item, reach, roots, state));
2867
+ }
2868
+ if (value && typeof value === "object") {
2869
+ const record = value;
2870
+ const path = record.path;
2871
+ if (roots && record.root === void 0 && (record.source === void 0 || typeof record.source === "string" && STATE_SOURCES.has(record.source)) && Array.isArray(path) && path.length > 0 && path.every((id) => typeof id === "string") && !roots.has(path[0])) {
2872
+ return true;
2873
+ }
2874
+ const root = record.root;
2875
+ if (state && root && typeof root.kind === "string" && STATE_ROOT_KINDS.has(root.kind) && typeof root.id === "string" && !state.has(root.id)) {
2876
+ return true;
2877
+ }
2878
+ return Object.values(value).some((item) => holdsDeadPath(item, reach, roots, state));
2879
+ }
2880
+ return false;
2881
+ }
2882
+ var named = (members) => Object.values(members ?? {}).map((member) => ({
2883
+ id: member.id,
2884
+ name: member.name,
2885
+ value: member
2886
+ }));
2887
+ var statePathResolves = defineInvariant({
2888
+ name: "state-path-resolves",
2889
+ message: "invariant-state-path-unresolved",
2890
+ severity: "blocking",
2891
+ deps: ["features", "screens", "navMap", "sharedShapes"],
2892
+ validate: ({ features, screens, navMap, sharedShapes }) => {
2893
+ const found = [];
2894
+ const reaches = /* @__PURE__ */ new Map();
2895
+ const state = new Set(
2896
+ Object.values(features).flatMap(
2897
+ (feature) => (0, import_codegen46.storesOf)(feature).flatMap((store) => [
2898
+ ...Object.keys(store.properties ?? {}),
2899
+ ...Object.keys(store.computeds ?? {})
2900
+ ])
2901
+ )
2902
+ );
2903
+ const rootsFor = (holder, extra = []) => /* @__PURE__ */ new Set([...state, ...declaredIds(holder), ...extra]);
2904
+ for (const feature of Object.values(features)) {
2905
+ const reach = reachOf(feature, sharedShapes);
2906
+ reaches.set(feature.id, reach);
2907
+ const at = { kind: "panel", panel: "store", featureId: feature.id };
2908
+ for (const variant of named(feature.variants)) {
2909
+ if (holdsDeadPath(variant.value, reach, rootsFor(variant.value), state)) {
2910
+ found.push({
2911
+ subject: `${feature.name} \u2192 variant ${variant.name}`,
2912
+ target: { ...at, memberId: variant.id }
2913
+ });
2914
+ }
2915
+ }
2916
+ for (const store of (0, import_codegen46.storesOf)(feature)) {
2917
+ const subStoreId = store.subStore?.id;
2918
+ const owner = subStoreId ? { ...at, subStoreId } : at;
2919
+ const prefix = store.subStore ? `${feature.name} \u2192 ${store.subStore.name}` : feature.name;
2920
+ for (const [word, members] of [
2921
+ ["computed", store.computeds],
2922
+ ["method", store.methods],
2923
+ ["timer", store.timers]
2924
+ ]) {
2925
+ for (const member of named(members)) {
2926
+ if (holdsDeadPath(member.value, reach, rootsFor(member.value), state)) {
2927
+ found.push({
2928
+ subject: `${prefix} \u2192 ${word} ${member.name}`,
2929
+ target: { ...owner, memberId: member.id }
2930
+ });
2931
+ }
2932
+ }
2933
+ }
2934
+ }
2935
+ }
2936
+ for (const screen of screens) {
2937
+ const reach = (0, import_codegen46.isFeatureScreen)(screen) ? reaches.get(screen.featureId) : void 0;
2938
+ if (!reach) continue;
2939
+ const at = { kind: "screen", screenId: screen.id, panel: "screen" };
2940
+ const own = [
2941
+ ...Object.keys(screen.inputs ?? {}),
2942
+ ...Object.keys(screen.computeds ?? {}),
2943
+ ...Object.keys(screen.constants ?? {}),
2944
+ ...Object.keys(screen.variables ?? {}),
2945
+ ...Object.keys(screen.formModels ?? {}),
2946
+ ...Object.values(screen.formModels ?? {}).map((model) => model.id)
2947
+ ];
2948
+ for (const variant of named(screen.variants)) {
2949
+ if (holdsDeadPath(variant.value, reach, rootsFor(variant.value, own), state)) {
2950
+ found.push({
2951
+ subject: `${screen.name} \u2192 variant ${variant.name}`,
2952
+ target: { ...at, memberId: variant.id }
2953
+ });
2954
+ }
2955
+ }
2956
+ for (const computed of named(screen.computeds)) {
2957
+ if (holdsDeadPath(computed.value, reach, rootsFor(computed.value, own), state)) {
2958
+ found.push({
2959
+ subject: `${screen.name} \u2192 computed ${computed.name}`,
2960
+ target: { ...at, computedId: computed.id }
2961
+ });
2962
+ }
2963
+ }
2964
+ }
2965
+ const everywhere = {
2966
+ properties: Object.assign({}, ...[...reaches.values()].map((r) => r.properties)),
2967
+ shapes: Object.assign({}, ...[...reaches.values()].map((r) => r.shapes))
2968
+ };
2969
+ for (const nav of Object.values(navMap)) {
2970
+ if (holdsDeadPath(nav, everywhere, rootsFor(nav), state)) {
2971
+ found.push({
2972
+ subject: `nav ${nav.label ?? nav.navId}`,
2973
+ target: { kind: "nav", navId: nav.navId }
2974
+ });
2975
+ }
2976
+ }
2977
+ return found;
2978
+ }
2979
+ });
2980
+
2981
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/rule-operand-fits.ts
2982
+ var import_codegen47 = require("./index.js");
2983
+ var unfit = (check, properties, shapes) => {
2984
+ const error = (0, import_codegen47.checkError)(check, properties, shapes);
2985
+ if (error === "rule-path-missing") return false;
2986
+ if (error === "rule-operator-invalid" || error === "rule-path-not-leaf" || error === "rule-operand-missing" && check.operand.kind === "path") {
2987
+ return true;
2988
+ }
2989
+ if ((0, import_codegen47.isUnaryOperator)(check.operator) || check.operand.kind !== "literal") {
2990
+ return false;
2991
+ }
2992
+ const segments = (0, import_codegen47.resolvePath)(check.path, properties, shapes);
2993
+ if (!check.count && (0, import_codegen47.pathLeafEnumId)(segments)) return false;
2994
+ const type = (0, import_codegen47.operandType)((0, import_codegen47.pathLeafType)(segments), !!check.count);
2995
+ if (!type) return false;
2996
+ return (0, import_codegen47.validateLiteral)(String(check.operand.value), { type }, "one") === "value-type-mismatch";
2997
+ };
2998
+ var ruleOperandFits = defineInvariant({
2999
+ name: "rule-operand-fits",
3000
+ message: "invariant-rule-operand-unfit",
3001
+ severity: "blocking",
3002
+ deps: ["features", "sharedShapes"],
3003
+ validate: ({ features, sharedShapes }) => {
3004
+ const found = [];
3005
+ for (const feature of Object.values(features)) {
3006
+ const properties = Object.assign(
3007
+ {},
3008
+ ...(0, import_codegen47.storesOf)(feature).map((store) => store.properties)
3009
+ );
3010
+ const shapes = (0, import_codegen47.shapesInReach)(feature, sharedShapes);
3011
+ for (const variant of Object.values(feature.variants ?? {})) {
3012
+ if ((0, import_codegen47.ruleChecks)(variant.rule).some(
3013
+ (check) => unfit(check, properties, shapes)
3014
+ )) {
3015
+ found.push({
3016
+ subject: `${feature.name} \u2192 variant ${variant.name}`,
3017
+ target: {
3018
+ kind: "panel",
3019
+ panel: "store",
3020
+ featureId: feature.id,
3021
+ memberId: variant.id
3022
+ }
3023
+ });
3024
+ }
3025
+ }
3026
+ }
3027
+ return found;
3028
+ }
3029
+ });
3030
+
3031
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/timer-complete.ts
3032
+ var import_codegen48 = require("./index.js");
3033
+ var timerComplete = defineInvariant({
3034
+ name: "timer-complete",
3035
+ message: "invariant-timer-incomplete",
3036
+ severity: "blocking",
3037
+ deps: ["features", "screens"],
3038
+ validate: ({ features, screens }) => {
3039
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
3040
+ return Object.values(features).flatMap(
3041
+ (feature) => Object.values(feature.timers ?? {}).filter((timer) => (0, import_codegen48.timerError)(timer)).map((timer) => ({
3042
+ subject: `${feature.name}.${timer.name}`,
3043
+ target: {
3044
+ kind: "screen",
3045
+ screenId: featureScreen(feature.id)
3046
+ }
3047
+ }))
3048
+ );
3049
+ }
3050
+ });
3051
+
3052
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/variant-gate-satisfiable.ts
3053
+ var import_codegen49 = require("./index.js");
3054
+ var ATOM_CAP2 = 12;
3055
+ var foldText2 = (entries, names) => entries.map((entry, index) => {
3056
+ const name = names.get(entry.id) ?? entry.id;
3057
+ const term = (0, import_codegen49.variantJoinIsNot)(entry.join) ? `!${name}` : name;
3058
+ if (index === 0) return term;
3059
+ return `${(0, import_codegen49.variantJoinIsAnd)(entry.join) ? "&&" : "||"} ${term}`;
3060
+ }).join(" ");
3061
+ var variantNames2 = (features, screens, currentScreenId) => {
3062
+ const screen = screens.find((one) => one.id === currentScreenId);
3063
+ const feature = screen?.featureId ? features[screen.featureId] : void 0;
3064
+ const names = /* @__PURE__ */ new Map([
3065
+ [import_codegen49.ELSE_VARIANT_ID, import_codegen49.ELSE_VARIANT_NAME],
3066
+ [import_codegen49.BUSY_VARIANT_ID, import_codegen49.BUSY_VARIANT_NAME]
3067
+ ]);
3068
+ Object.values(feature?.variants ?? {}).forEach(
3069
+ (variant) => names.set(variant.id, variant.name)
3070
+ );
3071
+ return names;
3072
+ };
3073
+ var satisfiable = (gates) => {
3074
+ const atoms = [
3075
+ ...new Set(
3076
+ gates.flat().map((entry) => entry.id).filter((id) => !(0, import_codegen49.isReservedVariantId)(id))
3077
+ )
3078
+ ];
3079
+ if (atoms.length > ATOM_CAP2) return true;
3080
+ const rows = 1 << atoms.length;
3081
+ for (let row = 0; row < rows; row++) {
3082
+ const on = atoms.filter((_, index) => row & 1 << index);
3083
+ const base = on.length ? on : [...on, import_codegen49.ELSE_VARIANT_ID];
3084
+ for (const withBusy of [base, [...base, import_codegen49.BUSY_VARIANT_ID]]) {
3085
+ if (gates.every((gate) => (0, import_codegen49.evaluateVariantGate)(gate, withBusy))) {
3086
+ return true;
3087
+ }
3088
+ }
3089
+ }
3090
+ return false;
3091
+ };
3092
+ var variantGateSatisfiable = defineInvariant({
3093
+ name: "variant-gate-satisfiable",
3094
+ message: "invariant-variant-gate-unsatisfiable",
3095
+ severity: "advisory",
3096
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
3097
+ deps: ["screenControlMaps", "features", "screens"],
3098
+ validate: ({ screenControlMaps, features, screens }) => unsatisfiableGates(screens, screenControlMaps, { features, screens })
3099
+ });
3100
+ var unsatisfiableGates = perScreen(
3101
+ (controlMap, screen, { features, screens }) => {
3102
+ const names = variantNames2(features, screens, screen.id);
3103
+ return Object.entries(controlMap).flatMap(([controlId, control]) => {
3104
+ const own = (0, import_codegen49.controlVariants)(control);
3105
+ if (!own.length) return [];
3106
+ const above = (0, import_codegen49.enclosingGates)(controlId, controlMap);
3107
+ if (above === null) return [];
3108
+ const gates = [own, ...above];
3109
+ if (satisfiable(gates)) return [];
3110
+ return [
3111
+ {
3112
+ // Its own guard, then what encloses it, innermost first — the two
3113
+ // halves that cannot hold together.
3114
+ subject: `${foldText2(own, names)} \u2014 ${gates.slice(1).map((gate) => foldText2(gate, names)).join(" & ")}`,
3115
+ target: {
3116
+ kind: "control",
3117
+ screenId: screen.id,
3118
+ controlId
3119
+ }
3120
+ }
3121
+ ];
3122
+ });
3123
+ }
3124
+ );
3125
+
3126
+ // apps/m-one-ui/src/app/pages/design/lib/codec-drops.ts
3127
+ var parse = (text) => {
3128
+ if (text === void 0) return void 0;
3129
+ try {
3130
+ return JSON.parse(text);
3131
+ } catch {
3132
+ return void 0;
3133
+ }
3134
+ };
3135
+ var label = (row, id) => typeof row?.name === "string" && row.name ? row.name : id;
3136
+ function codecDrops(files, source, root = ".magmonium") {
3137
+ const raw = parse(files[`${root}/index.json`]);
3138
+ if (!raw) return [];
3139
+ const found = [];
3140
+ const drop = (kind, key, subject, target2) => found.push({
3141
+ id: `codec-dropped-${kind}::${key}`,
3142
+ invariant: `codec-dropped-${kind}`,
3143
+ message: "invariant-codec-dropped",
3144
+ subject,
3145
+ severity: "blocking",
3146
+ target: target2
3147
+ });
3148
+ for (const [featureId, rawFeature] of Object.entries(raw.features ?? {})) {
3149
+ const fname = label(rawFeature, featureId);
3150
+ const feature = source.features[featureId];
3151
+ const at = { kind: "panel", panel: "store", featureId };
3152
+ if (!feature) {
3153
+ drop("feature", featureId, `Feature ${fname}`, at);
3154
+ continue;
3155
+ }
3156
+ const members = (store, decoded, prefix, owner) => {
3157
+ for (const [word, key] of [
3158
+ ["property", "properties"],
3159
+ ["computed", "computeds"],
3160
+ ["method", "methods"],
3161
+ ["timer", "timers"]
3162
+ ]) {
3163
+ for (const [id, row] of Object.entries(store?.[key] ?? {})) {
3164
+ if (!decoded?.[key]?.[id])
3165
+ drop(word, `${featureId}:${id}`, `${prefix} \u2192 ${word} ${label(row, id)}`, { ...owner, memberId: id });
3166
+ }
3167
+ }
3168
+ };
3169
+ members(rawFeature, feature, fname, at);
3170
+ for (const [subId, rawSub] of Object.entries(rawFeature?.subStores ?? {})) {
3171
+ const sub = feature.subStores?.[subId];
3172
+ if (!sub) {
3173
+ drop("substore", `${featureId}:${subId}`, `${fname} \u2192 store ${label(rawSub, subId)}`, at);
3174
+ continue;
3175
+ }
3176
+ members(rawSub, sub, `${fname} \u2192 ${label(rawSub, subId)}`, { ...at, subStoreId: subId });
3177
+ }
3178
+ }
3179
+ const decodedFunctions = /* @__PURE__ */ new Set([
3180
+ ...Object.keys(source.functions),
3181
+ ...Object.values(source.features).flatMap((feature) => Object.keys(feature.functions ?? {}))
3182
+ ]);
3183
+ const rawFunctions = [
3184
+ ...Object.entries(raw.functions ?? {}).map(([id, row]) => [id, row, void 0]),
3185
+ ...Object.entries(raw.features ?? {}).flatMap(
3186
+ ([featureId, feature]) => Object.entries(feature?.functions ?? {}).map(([id, row]) => [id, row, featureId])
3187
+ )
3188
+ ];
3189
+ for (const [id, row, featureId] of rawFunctions) {
3190
+ if (!decodedFunctions.has(id))
3191
+ drop("function", id, `function ${label(row, id)}`, {
3192
+ kind: "function",
3193
+ ...featureId ? { featureId } : {},
3194
+ functionId: id
3195
+ });
3196
+ }
3197
+ const decodedScreens = new Map(source.screens.map((slot) => [slot.meta.id, slot]));
3198
+ for (const rawScreen of raw.screens ?? []) {
3199
+ const id = typeof rawScreen.id === "string" ? rawScreen.id : void 0;
3200
+ if (!id) continue;
3201
+ const name = label(rawScreen, id);
3202
+ const slot = decodedScreens.get(id);
3203
+ if (!slot) {
3204
+ drop("screen", id, `Screen ${name}`, { kind: "screen", screenId: id });
3205
+ continue;
3206
+ }
3207
+ for (const [cid, row] of Object.entries(rawScreen.computeds ?? {})) {
3208
+ if (!slot.meta.computeds?.[cid])
3209
+ drop("screen-computed", `${id}:${cid}`, `${name} \u2192 computed ${label(row, cid)}`, {
3210
+ kind: "screen",
3211
+ screenId: id,
3212
+ panel: "screen",
3213
+ computedId: cid
3214
+ });
3215
+ }
3216
+ const rawSlot = parse(
3217
+ files[`${root}/screens/${id}.json`]
3218
+ );
3219
+ for (const [controlId, control] of Object.entries(rawSlot?.state?.controlMap ?? {})) {
3220
+ if (!slot.state.controlMap[controlId])
3221
+ drop("control", `${id}:${controlId}`, `${name} \u2192 ${String(control?.type ?? "control")} ${controlId}`, {
3222
+ kind: "screen",
3223
+ screenId: id
3224
+ });
3225
+ }
3226
+ }
3227
+ return found;
3228
+ }
3229
+
3230
+ // apps/m-one-ui/src/app/pages/design/lib/emit-gap-helper.ts
3231
+ var import_codegen51 = require("./index.js");
3232
+
3233
+ // apps/m-one-ui/src/app/pages/design/lib/store-method-check.ts
3234
+ var import_codegen50 = require("./index.js");
3235
+ function storeMethodError(method, scope) {
3236
+ const name = (0, import_codegen50.validateMethodName)(method.name, scope.siblings, method.id);
3237
+ if (name) return name;
3238
+ if ((0, import_codegen50.isStorageMethod)(method)) {
3239
+ const config = method.storage;
3240
+ if (!config?.key.trim()) return "emit-gap-storage-method";
3241
+ if (config.op !== "delete" && !scope.properties[config.propertyId ?? ""]) {
3242
+ return "emit-gap-storage-method";
3243
+ }
3244
+ return void 0;
3245
+ }
3246
+ if ((0, import_codegen50.isCacheMethod)(method)) {
3247
+ return (0, import_codegen50.cacheMethodError)(
3248
+ method,
3249
+ scope.methods,
3250
+ scope.properties,
3251
+ scope.operationOf
3252
+ );
3253
+ }
3254
+ const operation = scope.operationOf(method);
3255
+ if (!operation) return "emit-gap-unknown-operation";
3256
+ return (0, import_codegen50.validateInputs)(method, operation) ?? (0, import_codegen50.computeInputMemberError)(method, scope.functions, scope.shapes);
3257
+ }
3258
+
3259
+ // apps/m-one-ui/src/app/pages/design/lib/emit-gap-helper.ts
3260
+ var controlLabel = (control) => {
3261
+ const name = String(control.configs?.["name"] ?? "").trim();
3262
+ return name || control.type;
3263
+ };
3264
+ var featureSliceOf = (meta, features, appFunctions) => {
3265
+ if (!(0, import_codegen51.isFeatureScreen)(meta)) {
3266
+ return {
3267
+ methods: {},
3268
+ properties: {},
3269
+ functions: { ...appFunctions },
3270
+ computeds: {},
3271
+ roots: {},
3272
+ shapes: {}
3273
+ };
3274
+ }
3275
+ const feature = features[meta.featureId];
3276
+ const functions = { ...appFunctions, ...feature?.functions ?? {} };
3277
+ const readable = feature ? (0, import_codegen51.readableMembers)(feature, import_codegen51.MAIN_STORE_OWNER) : void 0;
3278
+ return {
3279
+ methods: readable?.methods ?? {},
3280
+ properties: readable?.properties ?? {},
3281
+ functions,
3282
+ computeds: readable?.computeds ?? {},
3283
+ roots: (0, import_codegen51.propertiesWithComputeds)(
3284
+ readable?.properties ?? {},
3285
+ readable?.computeds ?? {},
3286
+ functions
3287
+ ),
3288
+ shapes: feature?.shapes ?? {}
3289
+ };
3290
+ };
3291
+ var screenBindingOptions = (meta, controlMap, slice, inputs, variables, where) => ({
3292
+ ...where.controlId ? { controlId: where.controlId } : {},
3293
+ controlMap,
3294
+ roots: slice.roots,
3295
+ properties: slice.properties,
3296
+ shapes: slice.shapes,
3297
+ inputs,
3298
+ screenComputeds: meta.computeds,
3299
+ screenVariables: variables,
3300
+ formModels: meta.formModels,
3301
+ functions: slice.functions,
3302
+ enums: slice.enums,
3303
+ allowAlias: where.allowAlias
3304
+ });
3305
+ var callSiteError = (method, operationOf, rows, payload, constants, functions, bindings, properties = {}, methods = {}, eventMembers = []) => {
3306
+ if (!method) return "emit-gap-unknown-method";
3307
+ const op = operationOf(method);
3308
+ if (!op && !(0, import_codegen51.isStorageMethod)(method) && !(0, import_codegen51.isCacheMethod)(method)) {
3309
+ return "emit-gap-unknown-operation";
3310
+ }
3311
+ const args = (0, import_codegen51.isCacheMethod)(method) ? (0, import_codegen51.cacheMethodArgs)(method, methods, operationOf) : op ? (0, import_codegen51.methodArgs)(method, op) : (0, import_codegen51.storageMethodArgs)(method, properties);
3312
+ return (0, import_codegen51.validateCallArgs)(
3313
+ args,
3314
+ rows,
3315
+ payload,
3316
+ eventMembers,
3317
+ constants,
3318
+ functions,
3319
+ { roots: properties, bindings }
3320
+ );
3321
+ };
3322
+ var collectControlGaps = (gaps, meta, controlMap, slice, constants, inputs, variables, operationOf, screens = []) => {
3323
+ const embedded = embeddedOutputsOf(screens);
3324
+ const emitBindings = (control, scope) => ({
3325
+ options: screenBindingOptions(meta, controlMap, slice, inputs, variables, {
3326
+ controlId: control.id,
3327
+ allowAlias: scope === "template"
3328
+ })
3329
+ });
3330
+ Object.values(controlMap).forEach((control) => {
3331
+ const outputs = new Set([
3332
+ ...Object.keys(control.outputs ?? {}),
3333
+ ...Object.keys(control.outputWrites ?? {}),
3334
+ ...Object.keys(control.outputScreenWrites ?? {}),
3335
+ // An output that only opens a Screen holds nothing in the maps above, and
3336
+ // an overlay naming a Screen that is gone is a gesture that does nothing.
3337
+ ...Object.keys(control.outputOpens ?? {}),
3338
+ // An output whose rows all sit in an arm holds nothing in the three maps
3339
+ // above, and a broken row there is still a row that will not emit.
3340
+ ...Object.keys(control.outputOutcomes ?? {}),
3341
+ // An output whose one block is a ScreenEmit holds nothing in them
3342
+ // either, and a half-drawn emission is still a gesture that does
3343
+ // nothing (ADR 0143).
3344
+ ...Object.keys(control.outputEmits ?? {}),
3345
+ // A ScreenMethod whose parameters this call site leaves unanswered is a
3346
+ // call that cannot be spelled (ADR 0149).
3347
+ ...Object.keys(control.outputScreenMethods ?? {})
3348
+ ].filter(
3349
+ (output) => offersOutputKey(control, controlMap, output, embedded)
3350
+ ));
3351
+ const eventMembers = (0, import_codegen51.formEventMembers)(controlMap, control.id);
3352
+ const eventFields = (0, import_codegen51.formEventFieldTypes)(controlMap, control.id);
3353
+ const callBindings = screenBindingOptions(
3354
+ meta,
3355
+ controlMap,
3356
+ slice,
3357
+ inputs,
3358
+ variables,
3359
+ { controlId: control.id, allowAlias: true }
3360
+ );
3361
+ outputs.forEach((output) => {
3362
+ const methodId = control.outputs?.[output];
3363
+ const globalMethod = methodId ? (0, import_codegen51.globalMethodOf)(methodId) : void 0;
3364
+ if (methodId) {
3365
+ const err = globalMethod ? (0, import_codegen51.validateCallArgs)(
3366
+ (0, import_codegen51.globalMethodArgs)(globalMethod),
3367
+ (0, import_codegen51.outputArgRows)(control.outputArgs, output),
3368
+ outputPayloadShape(control, output, embedded),
3369
+ eventMembers,
3370
+ constants,
3371
+ slice.functions,
3372
+ { roots: slice.properties, bindings: callBindings }
3373
+ ) : callSiteError(
3374
+ slice.methods[methodId],
3375
+ operationOf,
3376
+ (0, import_codegen51.outputArgRows)(control.outputArgs, output),
3377
+ outputPayloadShape(control, output, embedded),
3378
+ constants,
3379
+ slice.functions,
3380
+ callBindings,
3381
+ slice.properties,
3382
+ slice.methods,
3383
+ eventMembers
3384
+ );
3385
+ if (err) {
3386
+ gaps.push({
3387
+ kind: "call-arg",
3388
+ screenId: meta.id,
3389
+ screenName: meta.name,
3390
+ message: err,
3391
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${outputCallLabelOf(control, output, embedded)}`,
3392
+ controlId: control.id,
3393
+ output,
3394
+ methodId
3395
+ });
3396
+ }
3397
+ }
3398
+ const screenMethodId = control.outputScreenMethods?.[output];
3399
+ const screenMethod = screenMethodId ? meta.methods?.[screenMethodId] : void 0;
3400
+ if (screenMethod && (0, import_codegen51.screenMethodArgs)(screenMethod).length) {
3401
+ const err = (0, import_codegen51.validateCallArgs)(
3402
+ (0, import_codegen51.screenMethodArgs)(screenMethod),
3403
+ (0, import_codegen51.outputArgRows)(control.outputArgs, output),
3404
+ outputPayloadShape(control, output, embedded),
3405
+ eventMembers,
3406
+ constants,
3407
+ slice.functions,
3408
+ { roots: slice.properties, bindings: callBindings }
3409
+ );
3410
+ if (err) {
3411
+ gaps.push({
3412
+ kind: "call-arg",
3413
+ screenId: meta.id,
3414
+ screenName: meta.name,
3415
+ message: err,
3416
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${outputCallLabelOf(control, output, embedded)}`,
3417
+ controlId: control.id,
3418
+ output
3419
+ });
3420
+ }
3421
+ }
3422
+ import_codegen51.OUTCOME_ARMS.forEach((arm) => {
3423
+ const rows = control.outputOutcomes?.[output]?.[arm];
3424
+ if (!rows) return;
3425
+ const resetErr = (0, import_codegen51.validateFormResets)(
3426
+ controlMap,
3427
+ rows.formResets ?? [],
3428
+ meta.formModels ?? {}
3429
+ );
3430
+ if (resetErr) {
3431
+ gaps.push({
3432
+ kind: "call-outcome",
3433
+ screenId: meta.id,
3434
+ screenName: meta.name,
3435
+ message: resetErr,
3436
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${outputCallLabelOf(control, output, embedded)} \xB7 ${arm}`,
3437
+ controlId: control.id,
3438
+ output
3439
+ });
3440
+ }
3441
+ const armScreenWriteErr = (0, import_codegen51.validateScreenWrites)(
3442
+ variables,
3443
+ rows.screenWrites ?? [],
3444
+ outputPayloadShape(control, output, embedded),
3445
+ [],
3446
+ inputs,
3447
+ constants,
3448
+ slice.functions,
3449
+ eventFields
3450
+ );
3451
+ if (armScreenWriteErr) {
3452
+ gaps.push({
3453
+ kind: "call-outcome",
3454
+ screenId: meta.id,
3455
+ screenName: meta.name,
3456
+ message: armScreenWriteErr,
3457
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${outputCallLabelOf(control, output, embedded)} \xB7 ${arm}`,
3458
+ controlId: control.id,
3459
+ output
3460
+ });
3461
+ }
3462
+ const armWriteErr = Object.keys(slice.properties).length ? (0, import_codegen51.validateStateWrites)(
3463
+ slice.properties,
3464
+ rows.writes ?? [],
3465
+ outputPayloadShape(control, output, embedded),
3466
+ [],
3467
+ inputs,
3468
+ constants,
3469
+ slice.functions,
3470
+ eventFields
3471
+ ) : void 0;
3472
+ if (armWriteErr) {
3473
+ gaps.push({
3474
+ kind: "call-outcome",
3475
+ screenId: meta.id,
3476
+ screenName: meta.name,
3477
+ message: armWriteErr,
3478
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${outputCallLabelOf(control, output, embedded)} \xB7 ${arm}`,
3479
+ controlId: control.id,
3480
+ output
3481
+ });
3482
+ }
3483
+ });
3484
+ const openErr = (0, import_codegen51.validateOutputOpen)(
3485
+ (0, import_codegen51.outputOpenOf)(control.outputOpens, output),
3486
+ [...screens],
3487
+ outputPayloadShape(control, output, embedded),
3488
+ inputs,
3489
+ constants
3490
+ );
3491
+ if (openErr) {
3492
+ gaps.push({
3493
+ kind: "output-open",
3494
+ screenId: meta.id,
3495
+ screenName: meta.name,
3496
+ message: openErr,
3497
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output}`,
3498
+ controlId: control.id,
3499
+ output
3500
+ });
3501
+ }
3502
+ const emitErr = (0, import_codegen51.validateScreenEmits)(
3503
+ meta.outputs ?? {},
3504
+ (0, import_codegen51.screenEmitRows)(control.outputEmits, output),
3505
+ outputPayloadShape(control, output, embedded),
3506
+ [],
3507
+ inputs,
3508
+ constants,
3509
+ emitBindings(control, "template")
3510
+ );
3511
+ if (emitErr) {
3512
+ gaps.push({
3513
+ kind: "emit",
3514
+ screenId: meta.id,
3515
+ screenName: meta.name,
3516
+ message: emitErr,
3517
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output}`,
3518
+ controlId: control.id,
3519
+ output
3520
+ });
3521
+ }
3522
+ const open = (0, import_codegen51.outputOpenOf)(control.outputOpens, output);
3523
+ const opened = open?.screenId ? screens.find((one) => one.id === open.screenId) : void 0;
3524
+ for (const [outputId, wire] of Object.entries(open?.outputs ?? {})) {
3525
+ const declared = opened?.outputs?.[outputId];
3526
+ const failing = [
3527
+ ...wire.binding ? [wire.binding] : [],
3528
+ ...(wire.calls ?? []).filter((call) => !!call.methodId)
3529
+ ].map((one) => ({
3530
+ one,
3531
+ err: callSiteError(
3532
+ slice.methods[one.methodId],
3533
+ operationOf,
3534
+ one.args ?? [],
3535
+ declared?.payload ? declared.payload.dataType : "void",
3536
+ constants,
3537
+ slice.functions,
3538
+ // A wire's call is emitted into the class body (ADR 0144).
3539
+ screenBindingOptions(meta, controlMap, slice, inputs, variables, {
3540
+ allowAlias: false
3541
+ }),
3542
+ slice.properties,
3543
+ slice.methods
3544
+ )
3545
+ })).find(({ err }) => !!err);
3546
+ const callErr = failing?.err;
3547
+ const binding = failing?.one ?? wire.binding;
3548
+ const wireErr = !declared ? "screen-emit-unknown-output" : callErr ?? (0, import_codegen51.validateScreenEmits)(
3549
+ meta.outputs ?? {},
3550
+ wire.emits ?? [],
3551
+ declared.payload ? declared.payload.dataType : "void",
3552
+ [],
3553
+ inputs,
3554
+ constants,
3555
+ emitBindings(control, "class")
3556
+ );
3557
+ if (!wireErr) continue;
3558
+ gaps.push({
3559
+ kind: "output-open-output",
3560
+ screenId: meta.id,
3561
+ screenName: meta.name,
3562
+ message: wireErr,
3563
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output} \xB7 ${declared?.name ?? outputId}`,
3564
+ controlId: control.id,
3565
+ output,
3566
+ ...binding ? { methodId: binding.methodId } : {}
3567
+ });
3568
+ }
3569
+ const screenWriteErr = (0, import_codegen51.validateScreenWrites)(
3570
+ variables,
3571
+ (0, import_codegen51.screenWriteRows)(control.outputScreenWrites, output),
3572
+ outputPayloadShape(control, output, embedded),
3573
+ [],
3574
+ inputs,
3575
+ constants,
3576
+ slice.functions,
3577
+ eventFields
3578
+ );
3579
+ if (screenWriteErr) {
3580
+ gaps.push({
3581
+ kind: "screen-write",
3582
+ screenId: meta.id,
3583
+ screenName: meta.name,
3584
+ message: screenWriteErr,
3585
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output}`,
3586
+ controlId: control.id,
3587
+ output
3588
+ });
3589
+ }
3590
+ const writeRows = (0, import_codegen51.stateWriteRows)(control.outputWrites, output);
3591
+ if (!writeRows.length) return;
3592
+ if (!Object.keys(slice.properties).length) return;
3593
+ const writeErr = (0, import_codegen51.validateStateWrites)(
3594
+ slice.properties,
3595
+ writeRows,
3596
+ outputPayloadShape(control, output, embedded),
3597
+ [],
3598
+ inputs,
3599
+ constants,
3600
+ slice.functions,
3601
+ eventFields
3602
+ );
3603
+ if (writeErr) {
3604
+ gaps.push({
3605
+ kind: "state-write",
3606
+ screenId: meta.id,
3607
+ screenName: meta.name,
3608
+ message: writeErr,
3609
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output}`,
3610
+ controlId: control.id,
3611
+ output
3612
+ });
3613
+ }
3614
+ });
3615
+ });
3616
+ };
3617
+ var collectBindingGaps = (gaps, meta, controlMap, slice) => {
3618
+ Object.values(controlMap).forEach((control) => {
3619
+ Object.entries(control.bindings ?? {}).forEach(([slot, binding]) => {
3620
+ if (!binding.transform) return;
3621
+ const err = (0, import_codegen51.transformIncomplete)(
3622
+ binding.transform,
3623
+ slice.functions,
3624
+ slice.roots,
3625
+ slice.shapes
3626
+ );
3627
+ if (!err) return;
3628
+ gaps.push({
3629
+ kind: "binding",
3630
+ screenId: meta.id,
3631
+ screenName: meta.name,
3632
+ message: err,
3633
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${slot}`,
3634
+ // The parameter still unanswered where one of them is, so the panel
3635
+ // names what to go and fill in rather than only the call it sits under.
3636
+ detail: (0, import_codegen51.transformGapDetail)(
3637
+ binding.transform,
3638
+ slice.functions,
3639
+ slice.roots,
3640
+ slice.shapes
3641
+ ) ?? (0, import_codegen51.transformLabel)(binding.transform, slice.functions),
3642
+ controlId: control.id,
3643
+ slot
3644
+ });
3645
+ });
3646
+ });
3647
+ };
3648
+ var autoCallReadError = (call, bindings) => {
3649
+ if (!call.reads?.length) return void 0;
3650
+ const offered = new Set(
3651
+ (0, import_codegen51.bindingOptions)(bindings, () => true).map((option) => option.value)
3652
+ );
3653
+ return call.reads.every((read) => offered.has((0, import_codegen51.encodeBinding)(read))) ? void 0 : "auto-call-read-gone";
3654
+ };
3655
+ var collectAutoCallGaps = (gaps, meta, calls, slice, constants, operationOf, bindings) => {
3656
+ calls.forEach((call) => {
3657
+ const err = (0, import_codegen51.screenAutoCallError)(call) ?? (call.methodId ? callSiteError(
3658
+ slice.methods[call.methodId],
3659
+ operationOf,
3660
+ call.args,
3661
+ "void",
3662
+ constants,
3663
+ slice.functions,
3664
+ bindings,
3665
+ slice.properties,
3666
+ slice.methods
3667
+ ) : void 0) ?? (0, import_codegen51.validateScreenEmits)(
3668
+ meta.outputs ?? {},
3669
+ call.emits ?? [],
3670
+ "void",
3671
+ [],
3672
+ meta.inputs ?? {},
3673
+ constants,
3674
+ { options: bindings }
3675
+ ) ?? autoCallReadError(call, bindings);
3676
+ if (!err) return;
3677
+ gaps.push({
3678
+ kind: "auto-call",
3679
+ screenId: meta.id,
3680
+ screenName: meta.name,
3681
+ message: err,
3682
+ subject: `${meta.name} \xB7 auto-call`,
3683
+ ...call.methodId ? { methodId: call.methodId } : {},
3684
+ autoCallId: call.id
3685
+ });
3686
+ });
3687
+ };
3688
+ var collectMethodGaps = (gaps, scope) => {
3689
+ Object.values(scope.features).forEach((feature) => {
3690
+ const screen = scope.screens.find(
3691
+ ({ meta }) => (0, import_codegen51.isFeatureScreen)(meta) && meta.featureId === feature.id
3692
+ )?.meta;
3693
+ const functions = { ...scope.functions, ...feature.functions ?? {} };
3694
+ (0, import_codegen51.storesOf)(feature).forEach((owned) => {
3695
+ const readable = (0, import_codegen51.readableMembers)(feature, owned.owner);
3696
+ Object.values(owned.methods).forEach((method) => {
3697
+ const error = storeMethodError(method, {
3698
+ operationOf: scope.operationOf,
3699
+ siblings: owned.methods,
3700
+ methods: readable.methods,
3701
+ properties: readable.properties,
3702
+ functions,
3703
+ shapes: feature.shapes ?? {}
3704
+ });
3705
+ if (!error || error === "emit-gap-unknown-operation") return;
3706
+ gaps.push({
3707
+ kind: "method",
3708
+ screenId: screen?.id ?? "",
3709
+ screenName: screen?.name ?? feature.name,
3710
+ message: error,
3711
+ subject: `${feature.name} \xB7 ${method.name}`,
3712
+ methodId: method.id
3713
+ });
3714
+ });
3715
+ });
3716
+ });
3717
+ };
3718
+ var collectResponseGaps = (gaps, scope) => {
3719
+ Object.values(scope.features).forEach((feature) => {
3720
+ const screen = scope.screens.find(
3721
+ ({ meta }) => (0, import_codegen51.isFeatureScreen)(meta) && meta.featureId === feature.id
3722
+ )?.meta;
3723
+ (0, import_codegen51.storesOf)(feature).forEach((owned) => {
3724
+ const readable = (0, import_codegen51.readableMembers)(feature, owned.owner);
3725
+ Object.values(owned.methods).forEach((method) => {
3726
+ const read = scope.operationOf(method);
3727
+ if (!read) return;
3728
+ const emitted = (0, import_codegen51.emittedOperation)(read, feature.shapes);
3729
+ const roots = (0, import_codegen51.propertiesWithComputeds)(
3730
+ readable.properties,
3731
+ readable.computeds,
3732
+ feature.functions ?? {}
3733
+ );
3734
+ const judge = (mapping, op) => {
3735
+ if (mapping.transform) {
3736
+ const failure = (0, import_codegen51.outcomeTransformFailure)(
3737
+ mapping,
3738
+ method,
3739
+ op,
3740
+ readable.properties,
3741
+ feature.shapes,
3742
+ feature.functions ?? {},
3743
+ roots
3744
+ );
3745
+ return failure && { err: failure.error, ...failure };
3746
+ }
3747
+ const err = (0, import_codegen51.responseMappingError)(
3748
+ mapping,
3749
+ op,
3750
+ readable.properties,
3751
+ feature.shapes
3752
+ );
3753
+ return err && {
3754
+ err,
3755
+ detail: (0, import_codegen51.responseMappingDetail)(
3756
+ mapping,
3757
+ op,
3758
+ readable.properties,
3759
+ feature.shapes
3760
+ ),
3761
+ paramIndex: void 0
3762
+ };
3763
+ };
3764
+ method.response.forEach((mapping) => {
3765
+ const verdict = judge(mapping, read) ?? judge(mapping, emitted);
3766
+ if (!verdict) return;
3767
+ const { err, detail, paramIndex } = verdict;
3768
+ gaps.push({
3769
+ kind: "response",
3770
+ screenId: screen?.id ?? "",
3771
+ screenName: screen?.name ?? feature.name,
3772
+ message: err,
3773
+ subject: `${feature.name} \xB7 ${method.name} \xB7 ${mapping.code}`,
3774
+ ...detail ? { detail } : {},
3775
+ methodId: method.id,
3776
+ anchor: `${mapping.code}:${mapping.propertyId}`,
3777
+ ...paramIndex !== void 0 ? { paramIndex } : {}
3778
+ });
3779
+ });
3780
+ });
3781
+ });
3782
+ });
3783
+ };
3784
+ var collectShadowedShapeGaps = (gaps, scope) => {
3785
+ Object.values(scope.features).forEach((feature) => {
3786
+ const screen = scope.screens.find(
3787
+ ({ meta }) => (0, import_codegen51.isFeatureScreen)(meta) && meta.featureId === feature.id
3788
+ )?.meta;
3789
+ const reads = (0, import_codegen51.storesOf)(feature).flatMap(
3790
+ (owned) => Object.values(owned.methods).flatMap((method) => {
3791
+ const op = scope.operationOf(method);
3792
+ return op ? [{ method, op }] : [];
3793
+ })
3794
+ );
3795
+ (0, import_codegen51.shadowedShapes)(
3796
+ reads.map(({ op }) => op),
3797
+ feature.shapes
3798
+ ).forEach((shadow) => {
3799
+ const first = reads.find(
3800
+ ({ op }) => (0, import_codegen51.shadowedShapes)([op], feature.shapes).some(
3801
+ (row) => row.shapeId === shadow.shapeId
3802
+ )
3803
+ );
3804
+ gaps.push({
3805
+ kind: "response",
3806
+ screenId: screen?.id ?? "",
3807
+ screenName: screen?.name ?? feature.name,
3808
+ message: "emit-gap-shape-shadowed",
3809
+ subject: `${feature.name} \xB7 ${shadow.name}`,
3810
+ detail: shadow.details.join("; "),
3811
+ ...first ? { methodId: first.method.id } : {},
3812
+ anchor: shadow.shapeId
3813
+ });
3814
+ });
3815
+ });
3816
+ };
3817
+ var collectNavInstanceGaps = (gaps, scope) => {
3818
+ const navMap = scope.navMap;
3819
+ if (!navMap) return;
3820
+ Object.values(navMap).filter((nav) => nav.presentation === "dynamic" && !!nav.instanceSource).forEach((nav) => {
3821
+ const source = nav.instanceSource;
3822
+ if (!source?.featureId) return;
3823
+ const subject = `${nav.navId} \xB7 :${(0, import_codegen51.navParam)(nav)}`;
3824
+ const push = (message, detail) => {
3825
+ gaps.push({
3826
+ kind: "nav-instance",
3827
+ screenId: "",
3828
+ screenName: nav.navId,
3829
+ message,
3830
+ subject,
3831
+ ...detail ? { detail } : {},
3832
+ navId: nav.navId
3833
+ });
3834
+ };
3835
+ const feature = scope.features[source.featureId];
3836
+ if (!feature) return push("instance-resolver-feature-gone");
3837
+ if (!source.functionId) return push("instance-resolver-unbound");
3838
+ const fn = feature.functions?.[source.functionId];
3839
+ if (!fn) return push("instance-resolver-function-gone");
3840
+ if (!(0, import_codegen51.navInstanceReturn)(fn, feature))
3841
+ return push("instance-resolver-return-unfit", fn.name);
3842
+ const unmapped = (0, import_codegen51.unmappedParams)(fn, source.args);
3843
+ if (unmapped.length)
3844
+ push("instance-resolver-args-unmapped", unmapped.join(", "));
3845
+ });
3846
+ };
3847
+ var collectEmitGaps = (scope) => {
3848
+ const gaps = [];
3849
+ const embedded = embeddedOutputsOf(scope.screens.map(({ meta }) => meta));
3850
+ scope.screens.forEach(({ meta, state }) => {
3851
+ const slice = {
3852
+ ...featureSliceOf(meta, scope.features, scope.functions),
3853
+ enums: scope.enums
3854
+ };
3855
+ collectControlGaps(
3856
+ gaps,
3857
+ meta,
3858
+ state.controlMap,
3859
+ slice,
3860
+ meta.constants ?? {},
3861
+ meta.inputs ?? {},
3862
+ meta.variables ?? {},
3863
+ scope.operationOf,
3864
+ scope.screens.map((screen) => screen.meta)
3865
+ );
3866
+ Object.values(state.controlMap).forEach((control) => {
3867
+ Object.keys(control.outputArms ?? {}).forEach((output) => {
3868
+ if (!offersOutputKey(control, state.controlMap, output, embedded)) return;
3869
+ (0, import_codegen51.outputArms)(control, output).forEach((arm, index) => {
3870
+ if ((0, import_codegen51.isOutputArmComplete)(arm)) return;
3871
+ gaps.push({
3872
+ kind: "binding",
3873
+ screenId: meta.id,
3874
+ screenName: meta.name,
3875
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output} ${index + 1}`,
3876
+ controlId: control.id,
3877
+ slot: (0, import_codegen51.outputArmKey)(output, arm.id),
3878
+ message: arm.checks.length ? "Finish this arm condition \u2014 a check is missing its subject, operator or value." : "Give this arm a condition, or it never runs."
3879
+ });
3880
+ });
3881
+ });
3882
+ });
3883
+ Object.values(state.controlMap).forEach((control) => {
3884
+ const outputs = /* @__PURE__ */ new Set([
3885
+ ...Object.keys(control.outputNavs ?? {}),
3886
+ ...Object.keys(control.outputNewTabs ?? {})
3887
+ ]);
3888
+ outputs.forEach((output) => {
3889
+ if (!offersOutputKey(control, state.controlMap, output, embedded)) return;
3890
+ const message = (0, import_codegen51.validateOutputNewTab)(
3891
+ (0, import_codegen51.outputNewTabOf)(control.outputNewTabs, output),
3892
+ slice.functions
3893
+ ) ?? (scope.navMap ? (0, import_codegen51.validateOutputNav)(
3894
+ (0, import_codegen51.outputNavOf)(control.outputNavs, output),
3895
+ scope.navMap
3896
+ ) : void 0);
3897
+ if (!message) return;
3898
+ gaps.push({
3899
+ kind: "output-link",
3900
+ screenId: meta.id,
3901
+ screenName: meta.name,
3902
+ message,
3903
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${output}`,
3904
+ controlId: control.id,
3905
+ output
3906
+ });
3907
+ });
3908
+ });
3909
+ Object.values(state.controlMap).forEach((control) => {
3910
+ if (control.type !== import_codegen51.ControlType.CONTEXT_MENU) return;
3911
+ const binding = control.bindings?.["options"];
3912
+ const message = binding ? (0, import_codegen51.bindingGapReason)(binding, {
3913
+ properties: slice.roots,
3914
+ shapes: slice.shapes,
3915
+ computeds: slice.computeds,
3916
+ functions: slice.functions,
3917
+ inputs: meta.inputs,
3918
+ screenComputeds: meta.computeds,
3919
+ screenVariables: meta.variables,
3920
+ formModels: meta.formModels,
3921
+ constants: meta.constants,
3922
+ storeProp: "store",
3923
+ controlMap: state.controlMap
3924
+ }) : (0, import_codegen51.menuOptionsOf)(control).some((group) => group.length) ? void 0 : "Author menu options or bind a collection.";
3925
+ if (message)
3926
+ gaps.push({
3927
+ kind: "binding",
3928
+ screenId: meta.id,
3929
+ screenName: meta.name,
3930
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 options`,
3931
+ controlId: control.id,
3932
+ slot: "options",
3933
+ message
3934
+ });
3935
+ (0, import_codegen51.menuActionSlots)(control).forEach((slot, index) => {
3936
+ if ((0, import_codegen51.isMenuActionSlotComplete)(slot)) return;
3937
+ gaps.push({
3938
+ kind: "binding",
3939
+ screenId: meta.id,
3940
+ screenName: meta.name,
3941
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 action ${index + 1}`,
3942
+ controlId: control.id,
3943
+ slot: (0, import_codegen51.menuActionKey)(slot.id),
3944
+ message: slot.checks.length ? "Finish this action condition \u2014 a check is missing its operator or value." : "Give this action a condition, or it fires for nothing."
3945
+ });
3946
+ });
3947
+ if (binding) return;
3948
+ (0, import_codegen51.staleMenuActionItems)(control).forEach(
3949
+ ({ slotId, itemId }) => gaps.push({
3950
+ kind: "binding",
3951
+ screenId: meta.id,
3952
+ screenName: meta.name,
3953
+ subject: `${meta.name} \xB7 ${controlLabel(control)} \xB7 ${itemId}`,
3954
+ controlId: control.id,
3955
+ slot: (0, import_codegen51.menuActionKey)(slotId),
3956
+ message: "This menu no longer holds the item this action is gated on."
3957
+ })
3958
+ );
3959
+ });
3960
+ collectBindingGaps(gaps, meta, state.controlMap, slice);
3961
+ collectAutoCallGaps(
3962
+ gaps,
3963
+ meta,
3964
+ meta.autoCalls ?? [],
3965
+ slice,
3966
+ meta.constants ?? {},
3967
+ scope.operationOf,
3968
+ screenBindingOptions(
3969
+ meta,
3970
+ state.controlMap,
3971
+ slice,
3972
+ meta.inputs ?? {},
3973
+ meta.variables ?? {},
3974
+ { allowAlias: false }
3975
+ )
3976
+ );
3977
+ });
3978
+ collectShadowedShapeGaps(gaps, scope);
3979
+ collectResponseGaps(gaps, scope);
3980
+ collectMethodGaps(gaps, scope);
3981
+ collectNavInstanceGaps(gaps, scope);
3982
+ return gaps;
3983
+ };
3984
+
3985
+ // apps/m-one-ui/src/app/pages/design/lib/invariant-catalog.ts
3986
+ var INVARIANTS = [
3987
+ appScaffoldComplete,
3988
+ backendUrlDeclared,
3989
+ bindingResolves,
3990
+ branchArmReachable,
3991
+ computedArgsBound,
3992
+ computedArgsTyped,
3993
+ oneFunctionArgMismatch,
3994
+ oneFunctionRequiredParam,
3995
+ confirmUnattendedCall,
3996
+ outcomeUnattendedCall,
3997
+ outcomeCallNested,
3998
+ reactionWritesOwnWatch,
3999
+ closeOverlayOffOverlay,
4000
+ outcomeNavComplete,
4001
+ dynamicNavInputDeclared,
4002
+ navTailInputDeclared,
4003
+ navTailChildless,
4004
+ navVariantOnChain,
4005
+ computedNavOnChain,
4006
+ computedOneFunctionKnown,
4007
+ remoteTailSingle,
4008
+ remoteTailRouted,
4009
+ remoteNameUnique,
4010
+ remoteMountPatternValid,
4011
+ remoteMountMatchesRoute,
4012
+ fieldCheckBound,
4013
+ filterGroupSqueezeOrphan,
4014
+ contextGroupPrimaryUnique,
4015
+ functionCaseArgs,
4016
+ handBindingResolves,
4017
+ handRequiredInputBound,
4018
+ handScreenResolves,
4019
+ landingPageBound,
4020
+ navVisibilityResolvable,
4021
+ methodVariantNoLanding,
4022
+ methodVariantUnused,
4023
+ overlayBodyBound,
4024
+ pageInputRoutable,
4025
+ reservedVariantNameFree,
4026
+ featureNameFree,
4027
+ screenControlReachable,
4028
+ screenInputBound,
4029
+ searchFeedResolves,
4030
+ searchAnswerResolves,
4031
+ shapeMatch,
4032
+ statePathResolves,
4033
+ ruleOperandFits,
4034
+ themeSelectionResolves,
4035
+ timerComplete,
4036
+ variantGateSatisfiable,
4037
+ // Gesture rules, judged on the design as it stands so an edit made outside
4038
+ // the editor meets them too (0128_11).
4039
+ routerOutletPlaced,
4040
+ controlIdUnique,
4041
+ fieldKeyTypeAgrees,
4042
+ submitTargetResolves,
4043
+ formResetResolves,
4044
+ ruleFieldResolves,
4045
+ embedShapeWithinFeature,
4046
+ storeNameReserved,
4047
+ storeMemberNameUnique,
4048
+ functionNameUnshadowed,
4049
+ functionTierFiled,
4050
+ functionRefExclusive,
4051
+ bindingResolvesOutputs
4052
+ ];
4053
+ var runInvariants = (scope) => INVARIANTS.flatMap((invariant) => invariant.run(scope));
4054
+ var invariantScopeOf = (source, themeCatalog) => ({
4055
+ appTarget: source.appTarget,
4056
+ wcConfig: source.wcConfig,
4057
+ features: (0, import_codegen52.featuresAsRead)(
4058
+ source.features,
4059
+ source.sharedShapes,
4060
+ source.screens.map(({ meta, state }) => ({
4061
+ ...(0, import_codegen52.isFeatureScreen)(meta) ? { featureId: meta.featureId } : {},
4062
+ controlMap: state.controlMap
4063
+ }))
4064
+ ),
4065
+ screens: source.screens.map(({ meta }) => meta),
4066
+ navMap: source.navMap,
4067
+ controlMap: {},
4068
+ screenControlMaps: Object.fromEntries(
4069
+ source.screens.map(({ meta, state }) => [meta.id, state.controlMap])
4070
+ ),
4071
+ functions: source.functions,
4072
+ distinct: source.distinct,
4073
+ sharedShapes: source.sharedShapes,
4074
+ enums: source.enums,
4075
+ themes: source.themes,
4076
+ themeCatalog: [...themeCatalog],
4077
+ hand: source.hand,
4078
+ currentScreenId: void 0
4079
+ });
4080
+ // Annotate the CommonJS export names for ESM import in node:
4081
+ 0 && (module.exports = {
4082
+ INVARIANTS,
4083
+ codecDrops,
4084
+ collectEmitGaps,
4085
+ invariantScopeOf,
4086
+ runInvariants
4087
+ });