@magmonium/cli 0.8.28 → 0.8.30

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,2788 @@
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
+ invariantScopeOf: () => invariantScopeOf,
25
+ runInvariants: () => runInvariants
26
+ });
27
+ module.exports = __toCommonJS(invariant_catalog_exports);
28
+ var import_codegen46 = require("./index.js");
29
+
30
+ // apps/m-one-ui/src/app/pages/design/model/invariant.ts
31
+ var targetKey = (target2) => {
32
+ switch (target2.kind) {
33
+ case "panel":
34
+ return `panel:${target2.panel}${target2.featureId ? `:${target2.featureId}` : ""}${target2.subStoreId ? `:${target2.subStoreId}` : ""}${target2.memberId ? `:${target2.memberId}` : ""}`;
35
+ case "nav":
36
+ return `nav:${target2.navId}`;
37
+ case "screen":
38
+ return `screen:${target2.screenId}${target2.computedId ? `:${target2.computedId}` : ""}${target2.memberId ? `:${target2.memberId}` : ""}`;
39
+ case "compare":
40
+ return `compare:${target2.tab}:${target2.item.id}`;
41
+ case "function":
42
+ return `function:${target2.functionId}`;
43
+ case "control":
44
+ return `control:${target2.screenId}:${target2.controlId}${target2.inputId ? `:${target2.inputId}` : ""}`;
45
+ }
46
+ };
47
+ var defineInvariant = (def) => ({
48
+ name: def.name,
49
+ severity: def.severity,
50
+ deps: def.deps,
51
+ run: (scope) => {
52
+ const view = {};
53
+ def.deps.forEach((dep) => {
54
+ view[dep] = scope[dep];
55
+ });
56
+ return def.validate(view).map(
57
+ ({
58
+ message,
59
+ subject,
60
+ target: target2,
61
+ computedFix,
62
+ routeInputFix,
63
+ screenRetarget
64
+ }) => ({
65
+ id: `${def.name}::${targetKey(target2)}${computedFix ? `::${computedFix.computedId}` : ""}${routeInputFix ? `::${routeInputFix.navId}` : ""}`,
66
+ invariant: def.name,
67
+ message: message ?? def.message,
68
+ subject,
69
+ severity: def.severity,
70
+ target: target2,
71
+ ...computedFix ? { computedFix } : {},
72
+ ...routeInputFix ? { routeInputFix } : {},
73
+ ...screenRetarget ? { screenRetarget } : {}
74
+ })
75
+ );
76
+ }
77
+ });
78
+
79
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/backend-url-declared.ts
80
+ var backendUrlDeclared = defineInvariant({
81
+ name: "backend-url-declared",
82
+ message: "invariant-backend-url-blank",
83
+ severity: "blocking",
84
+ deps: ["appTarget", "features"],
85
+ validate: ({ appTarget, features }) => {
86
+ const drawsMethods = Object.values(features).some(
87
+ (feature) => Object.keys(feature.methods ?? {}).length > 0
88
+ );
89
+ if (!drawsMethods) return [];
90
+ const { preset, hosts } = appTarget.environment;
91
+ if (hosts.backendUrl.trim()) return [];
92
+ return [
93
+ {
94
+ subject: preset,
95
+ target: { kind: "panel", panel: "environment" }
96
+ }
97
+ ];
98
+ }
99
+ });
100
+
101
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/dynamic-nav-input-declared.ts
102
+ var import_codegen = require("./index.js");
103
+ var dynamicNavInputDeclared = defineInvariant({
104
+ name: "dynamic-nav-input-declared",
105
+ message: "invariant-dynamic-nav-input-missing",
106
+ severity: "blocking",
107
+ deps: ["navMap", "screens"],
108
+ validate: ({ navMap, screens }) => Object.values(navMap).filter(
109
+ (nav) => nav.linkKind === "url" && nav.presentation === "dynamic" && !!nav.pageId
110
+ ).flatMap((nav) => {
111
+ const routed = screens.find(
112
+ (screen) => screen.id === nav.pageId && (0, import_codegen.isRoutableScreen)(screen)
113
+ );
114
+ if (!routed) return [];
115
+ const param = (0, import_codegen.navParam)(nav);
116
+ const declared = Object.values(routed.inputs ?? {}).some(
117
+ (input) => input.name === param
118
+ );
119
+ if (declared) return [];
120
+ return [
121
+ {
122
+ // The parameter is named in the subject: with the name authorable,
123
+ // "this Page is missing an input" is only half of what the User has
124
+ // to know to fix it.
125
+ subject: `${nav.navId} \u2192 ${routed.name} (:${param})`,
126
+ routeInputFix: {
127
+ navId: nav.navId,
128
+ screenId: routed.id,
129
+ name: param
130
+ },
131
+ target: {
132
+ kind: "screen",
133
+ screenId: routed.id,
134
+ panel: "screen"
135
+ }
136
+ }
137
+ ];
138
+ })
139
+ });
140
+
141
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-tail-input-declared.ts
142
+ var import_codegen2 = require("./index.js");
143
+ var navTailInputDeclared = defineInvariant({
144
+ name: "nav-tail-input-declared",
145
+ message: "invariant-nav-tail-input-missing",
146
+ severity: "blocking",
147
+ deps: ["navMap", "screens"],
148
+ validate: ({ navMap, screens }) => Object.values(navMap).filter(
149
+ (nav) => nav.tail !== void 0 && nav.linkKind === "url" && !!nav.pageId
150
+ ).flatMap((nav) => {
151
+ const routed = screens.find(
152
+ (screen) => screen.id === nav.pageId && (0, import_codegen2.isRoutableScreen)(screen)
153
+ );
154
+ if (!routed) return [];
155
+ const declared = Object.values(routed.inputs ?? {}).some(
156
+ (input) => input.name === nav.tail
157
+ );
158
+ if (declared) return [];
159
+ return [
160
+ {
161
+ subject: `${nav.navId} \u2192 ${routed.name} (*${nav.tail})`,
162
+ target: {
163
+ kind: "screen",
164
+ screenId: routed.id,
165
+ panel: "screen"
166
+ }
167
+ }
168
+ ];
169
+ })
170
+ });
171
+
172
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-tail-childless.ts
173
+ var navTailChildless = defineInvariant({
174
+ name: "nav-tail-childless",
175
+ message: "invariant-nav-tail-has-children",
176
+ severity: "blocking",
177
+ deps: ["navMap"],
178
+ validate: ({ navMap }) => Object.values(navMap).filter((nav) => nav.tail !== void 0 && nav.children.length > 0).map((nav) => ({
179
+ subject: nav.navId,
180
+ target: { kind: "nav", navId: nav.navId }
181
+ }))
182
+ });
183
+
184
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-variant-on-chain.ts
185
+ var import_codegen3 = require("./index.js");
186
+ var navVariantOnChain = defineInvariant({
187
+ name: "nav-variant-on-chain",
188
+ message: "invariant-nav-variant-off-chain",
189
+ severity: "blocking",
190
+ deps: ["screens", "navMap"],
191
+ validate: ({ screens, navMap }) => screens.flatMap((screen) => {
192
+ const chain = (0, import_codegen3.navVariantNavIds)(navMap, screen.id);
193
+ return Object.values(screen.variants ?? {}).filter(
194
+ (variant) => (0, import_codegen3.variantNavIds)(variant).some((navId) => !chain.includes(navId))
195
+ ).map((variant) => ({
196
+ subject: `${screen.name}.${variant.name}`,
197
+ target: { kind: "screen", screenId: screen.id }
198
+ }));
199
+ })
200
+ });
201
+
202
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-nav-on-chain.ts
203
+ var import_codegen4 = require("./index.js");
204
+ var computedNavOnChain = defineInvariant({
205
+ name: "computed-nav-on-chain",
206
+ message: "invariant-computed-nav-off-chain",
207
+ severity: "blocking",
208
+ deps: ["screens", "navMap"],
209
+ validate: ({ screens, navMap }) => screens.flatMap((screen) => {
210
+ const chain = (0, import_codegen4.navVariantNavIds)(navMap, screen.id);
211
+ return Object.values(screen.computeds ?? {}).filter(
212
+ (computed) => (0, import_codegen4.screenComputedNavIds)(computed).some((navId) => !chain.includes(navId))
213
+ ).map((computed) => ({
214
+ subject: `${screen.name}.${computed.name}`,
215
+ // The computed's own editor is where its Nav argument is repointed,
216
+ // so the reveal opens the Screen panel with it docked alongside.
217
+ target: {
218
+ kind: "screen",
219
+ screenId: screen.id,
220
+ panel: "screen",
221
+ computedId: computed.id
222
+ }
223
+ }));
224
+ })
225
+ });
226
+
227
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-one-function-known.ts
228
+ var import_codegen5 = require("./index.js");
229
+ var computedOneFunctionKnown = defineInvariant({
230
+ name: "computed-one-function-known",
231
+ message: "invariant-computed-one-function-unknown",
232
+ severity: "blocking",
233
+ deps: ["screens", "features"],
234
+ validate: ({ screens, features }) => [
235
+ ...screens.flatMap(
236
+ (screen) => Object.values(screen.computeds ?? {}).filter(
237
+ (computed) => (0, import_codegen5.isOneFunctionComputed)(computed) && !(0, import_codegen5.oneFunctionOf)(computed.oneFunction)?.reach.includes(
238
+ "screen-computed"
239
+ )
240
+ ).map((computed) => ({
241
+ subject: `${screen.name}.${computed.name}`,
242
+ target: {
243
+ kind: "screen",
244
+ screenId: screen.id,
245
+ panel: "screen",
246
+ computedId: computed.id
247
+ }
248
+ }))
249
+ ),
250
+ ...Object.values(features).flatMap(
251
+ (feature) => (0, import_codegen5.storesOf)(feature).flatMap(
252
+ (owned) => Object.values(owned.computeds).filter(
253
+ (computed) => (0, import_codegen5.isOneFunctionStateComputed)(computed) && !(0, import_codegen5.oneFunctionOf)(computed.oneFunction)?.reach.includes(
254
+ "state-computed"
255
+ )
256
+ ).map((computed) => ({
257
+ subject: `${feature.name}.${computed.name}`,
258
+ target: {
259
+ kind: "panel",
260
+ panel: "store",
261
+ featureId: feature.id,
262
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
263
+ memberId: computed.id
264
+ }
265
+ }))
266
+ )
267
+ )
268
+ ]
269
+ });
270
+
271
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/remote-control-url.ts
272
+ var import_codegen6 = require("./index.js");
273
+ var remotesOf = (maps) => Object.entries(maps).flatMap(
274
+ ([screenId, map]) => Object.values(map ?? {}).filter((control) => control.type === import_codegen6.ControlType.REMOTE).map((control) => ({ screenId, control }))
275
+ );
276
+ var urlModeOf = ({ control }) => (0, import_codegen6.remoteUrlModeOf)(control.configs);
277
+ var subjectOf = ({ control }) => (0, import_codegen6.remoteMountName)(control) || "remote-unnamed";
278
+ var target = ({ screenId, control }) => ({
279
+ kind: "control",
280
+ screenId,
281
+ controlId: control.id
282
+ });
283
+ var remoteTailSingle = defineInvariant({
284
+ name: "remote-tail-single",
285
+ message: "invariant-remote-tail-single",
286
+ severity: "blocking",
287
+ deps: ["screenControlMaps"],
288
+ validate: ({ screenControlMaps }) => {
289
+ const tails = remotesOf(screenControlMaps).filter(
290
+ (f) => urlModeOf(f) === "tail"
291
+ );
292
+ const byScreen = /* @__PURE__ */ new Map();
293
+ tails.forEach(
294
+ (f) => byScreen.set(f.screenId, [...byScreen.get(f.screenId) ?? [], f])
295
+ );
296
+ return [...byScreen.values()].filter((found) => found.length > 1).map((found) => ({
297
+ subject: subjectOf(found[1]),
298
+ target: target(found[1])
299
+ }));
300
+ }
301
+ });
302
+ var tailableNavOf = (screenId, navMap) => Object.values(navMap).find(
303
+ (nav) => nav.pageId === screenId && (0, import_codegen6.routesNavTail)(nav)
304
+ );
305
+ var remoteTailRouted = defineInvariant({
306
+ name: "remote-tail-routed",
307
+ message: "invariant-remote-tail-unrouted",
308
+ severity: "blocking",
309
+ deps: ["screenControlMaps", "navMap"],
310
+ validate: ({ screenControlMaps, navMap }) => {
311
+ const tailed = new Set(
312
+ Object.values(navMap).filter((nav) => nav.tail !== void 0 && nav.pageId).map((nav) => nav.pageId)
313
+ );
314
+ return remotesOf(screenControlMaps).filter((f) => urlModeOf(f) === "tail" && !tailed.has(f.screenId)).map((f) => {
315
+ const nav = tailableNavOf(f.screenId, navMap);
316
+ return {
317
+ subject: subjectOf(f),
318
+ target: nav ? { kind: "nav", navId: nav.navId } : target(f)
319
+ };
320
+ });
321
+ }
322
+ });
323
+ var remoteNameUnique = defineInvariant({
324
+ name: "remote-name-unique",
325
+ message: "invariant-remote-name-taken",
326
+ severity: "blocking",
327
+ deps: ["screenControlMaps"],
328
+ validate: ({ screenControlMaps }) => {
329
+ const seen = /* @__PURE__ */ new Set();
330
+ return remotesOf(screenControlMaps).flatMap((f) => {
331
+ const key = `${f.screenId}::${(0, import_codegen6.remoteMountName)(f.control)}`;
332
+ if (!(0, import_codegen6.remoteMountName)(f.control) || !seen.has(key)) {
333
+ seen.add(key);
334
+ return [];
335
+ }
336
+ return [{ subject: (0, import_codegen6.remoteMountName)(f.control), target: target(f) }];
337
+ });
338
+ }
339
+ });
340
+ var remoteMountPatternValid = defineInvariant({
341
+ name: "remote-mount-pattern",
342
+ message: "invariant-remote-mount-pattern",
343
+ severity: "blocking",
344
+ deps: ["screenControlMaps"],
345
+ validate: ({ screenControlMaps }) => remotesOf(screenControlMaps).filter((f) => (0, import_codegen6.remoteMountProblemOf)(f.control.configs)).map((f) => ({ subject: subjectOf(f), target: target(f) }))
346
+ });
347
+ var remoteMountMatchesRoute = defineInvariant({
348
+ name: "remote-mount-route",
349
+ message: "invariant-remote-mount-route",
350
+ severity: "blocking",
351
+ deps: ["screenControlMaps", "navMap"],
352
+ validate: ({ screenControlMaps, navMap }) => remotesOf(screenControlMaps).filter((f) => {
353
+ if ((0, import_codegen6.remoteMountProblemOf)(f.control.configs)) return false;
354
+ if ((0, import_codegen6.remoteMountTextOf)(f.control.configs) === void 0) return false;
355
+ const paths = (0, import_codegen6.navTailPathsOf)(f.screenId, navMap);
356
+ const pattern = (0, import_codegen6.remoteMountPatternOf)(f.control.configs);
357
+ return paths.length > 0 && !paths.some((p) => (0, import_codegen6.mountAgreesWithRoute)(pattern, p));
358
+ }).map((f) => ({ subject: subjectOf(f), target: target(f) }))
359
+ });
360
+
361
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/landing-page-bound.ts
362
+ var import_codegen7 = require("./index.js");
363
+ var landingPageBound = defineInvariant({
364
+ name: "landing-page-bound",
365
+ message: "invariant-landing-page-unbound",
366
+ severity: "advisory",
367
+ deps: ["navMap", "screens"],
368
+ validate: ({ navMap, screens }) => {
369
+ if (!screens.some(import_codegen7.isRoutableScreen)) return [];
370
+ const navId = (0, import_codegen7.landingNavId)(navMap);
371
+ const landing = navMap[navId];
372
+ if (!landing) return [];
373
+ const bound = landing.linkKind === "url" && !!landing.pageId && screens.some(
374
+ (screen) => screen.id === landing.pageId && (0, import_codegen7.isRoutableScreen)(screen)
375
+ );
376
+ if (bound) return [];
377
+ return [{ subject: navId, target: { kind: "nav", navId } }];
378
+ }
379
+ });
380
+
381
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/nav-visibility-resolvable.ts
382
+ var import_codegen8 = require("./index.js");
383
+ var navVisibilityResolvable = defineInvariant({
384
+ name: "nav-visibility-resolvable",
385
+ message: "invariant-nav-visibility-unresolvable",
386
+ severity: "blocking",
387
+ deps: ["navMap", "features"],
388
+ validate: ({ navMap, features }) => Object.values(navMap).filter((nav) => !!nav.visibilitySource).flatMap((nav) => {
389
+ const source = nav.visibilitySource;
390
+ if (!source) return [];
391
+ const target2 = { kind: "nav", navId: nav.navId };
392
+ if (!source.hidesRow && !source.guardsRoute) {
393
+ return [{ subject: `${nav.navId} \u2014 no effect`, target: target2 }];
394
+ }
395
+ const feature = source.featureId ? features[source.featureId] : void 0;
396
+ if (!feature) {
397
+ return [{ subject: `${nav.navId} \u2014 feature gone`, target: target2 }];
398
+ }
399
+ const fn = source.functionId ? feature.functions?.[source.functionId] : void 0;
400
+ if (!fn) {
401
+ return [{ subject: `${nav.navId} \u2014 function gone`, target: target2 }];
402
+ }
403
+ if (!(0, import_codegen8.isNavVisibilityFunction)(fn)) {
404
+ return [
405
+ { subject: `${nav.navId} \u2192 ${fn.name} \u2014 not a boolean`, target: target2 }
406
+ ];
407
+ }
408
+ const unmapped = fn.params.filter((param) => !source.args?.[param.id]).map((param) => param.name);
409
+ if (unmapped.length) {
410
+ return [
411
+ {
412
+ subject: `${nav.navId} \u2192 ${fn.name} \u2014 unmapped: ${unmapped.join(
413
+ ", "
414
+ )}`,
415
+ target: target2
416
+ }
417
+ ];
418
+ }
419
+ if (source.methodId && !Object.values(feature.methods ?? {}).some(
420
+ (method) => method.id === source.methodId
421
+ ) && !Object.values(feature.subStores ?? {}).some(
422
+ (sub) => Object.values(sub.methods ?? {}).some(
423
+ (method) => method.id === source.methodId
424
+ )
425
+ )) {
426
+ return [{ subject: `${nav.navId} \u2014 load method gone`, target: target2 }];
427
+ }
428
+ return [];
429
+ })
430
+ });
431
+
432
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/method-variant-no-landing.ts
433
+ var import_codegen9 = require("./index.js");
434
+ var methodVariantNoLanding = defineInvariant({
435
+ name: "method-variant-no-landing",
436
+ message: "invariant-method-variant-no-landing",
437
+ severity: "advisory",
438
+ deps: ["features", "screens"],
439
+ validate: ({ features, screens }) => Object.values(features).flatMap((feature) => {
440
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
441
+ return (0, import_codegen9.storesOf)(feature).flatMap(
442
+ (store) => Object.values(store.methods).flatMap((method) => {
443
+ if (!(method.variants ?? []).length) return [];
444
+ const mappings = method.response ?? [];
445
+ const codes = [...new Set(mappings.map((m) => m.code))];
446
+ return codes.filter((code) => {
447
+ const rows = mappings.filter((m) => m.code === code);
448
+ return rows.length && rows.every((row) => !!row.landsWhen);
449
+ }).map((code) => ({
450
+ subject: `${feature.name}.${method.name} \u2192 ${code}`,
451
+ target: { kind: "screen", screenId }
452
+ }));
453
+ })
454
+ );
455
+ })
456
+ });
457
+
458
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/method-variant-unused.ts
459
+ var import_codegen10 = require("./index.js");
460
+ var methodVariantUnused = defineInvariant({
461
+ name: "method-variant-unused",
462
+ message: "invariant-method-variant-unused",
463
+ severity: "advisory",
464
+ deps: ["features", "screens"],
465
+ validate: ({ features, screens }) => Object.values(features).flatMap((feature) => {
466
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
467
+ return (0, import_codegen10.storesOf)(feature).flatMap(
468
+ (store) => Object.values(store.methods).flatMap((method) => {
469
+ const named2 = new Set(
470
+ (method.response ?? []).map((mapping) => mapping.landsWhen).filter((id) => !!id)
471
+ );
472
+ return (method.variants ?? []).filter((variant) => !named2.has(variant.id)).map((variant) => ({
473
+ subject: `${feature.name}.${method.name} \u2192 ${variant.name}`,
474
+ target: { kind: "screen", screenId }
475
+ }));
476
+ })
477
+ );
478
+ })
479
+ });
480
+
481
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/overlay-body-bound.ts
482
+ var import_codegen11 = require("./index.js");
483
+ var overlayBodyBound = defineInvariant({
484
+ name: "overlay-body-bound",
485
+ message: "invariant-overlay-body-unbound",
486
+ severity: "advisory",
487
+ deps: ["screens", "screenControlMaps"],
488
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
489
+ const controlMap = screenControlMaps[screen.id] ?? {};
490
+ return Object.values(controlMap).flatMap((control) => {
491
+ const unbound = Object.entries(control.directives ?? {}).some(
492
+ ([name, directive]) => {
493
+ if (!(0, import_codegen11.isOverlayDirectiveName)(name)) return false;
494
+ const configs = directive.overlayId ? controlMap[directive.overlayId]?.configs : directive.configs;
495
+ const component = configs?.["component"];
496
+ return component === import_codegen11.NEW_SCREEN || typeof component !== "string" || !component;
497
+ }
498
+ );
499
+ if (!unbound) return [];
500
+ return [
501
+ {
502
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
503
+ target: {
504
+ kind: "control",
505
+ screenId: screen.id,
506
+ controlId: control.id
507
+ }
508
+ }
509
+ ];
510
+ });
511
+ })
512
+ });
513
+
514
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/page-input-routable.ts
515
+ var import_codegen12 = require("./index.js");
516
+ var pageInputRoutable = defineInvariant({
517
+ name: "page-input-routable",
518
+ message: "invariant-page-input-unroutable",
519
+ severity: "advisory",
520
+ deps: ["navMap", "screens"],
521
+ validate: ({ navMap, screens }) => screens.filter((screen) => screen.kind === "page").flatMap((page) => {
522
+ const navs = Object.values(navMap).filter(
523
+ (nav) => nav.linkKind === "url" && nav.pageId === page.id
524
+ );
525
+ if (!navs.length) return [];
526
+ const routed = new Set(
527
+ navs.flatMap((nav) => (0, import_codegen12.navRouteParams)(nav.navId, navMap))
528
+ );
529
+ const unfillable = Object.values(page.inputs ?? {}).filter((input) => input.origin !== "card").filter(
530
+ (input) => !routed.has(input.name) || input.dataType.type === "enum"
531
+ ).map((input) => input.name);
532
+ if (!unfillable.length) return [];
533
+ return [
534
+ {
535
+ subject: `${page.name} \u2192 ${unfillable.join(", ")}`,
536
+ target: {
537
+ kind: "screen",
538
+ screenId: page.id,
539
+ panel: "screen"
540
+ }
541
+ }
542
+ ];
543
+ })
544
+ });
545
+
546
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/app-scaffold-complete.ts
547
+ var appScaffoldComplete = defineInvariant({
548
+ name: "app-scaffold-complete",
549
+ message: "app-scaffold-incomplete",
550
+ severity: "blocking",
551
+ deps: ["appTarget", "screens"],
552
+ validate: ({ appTarget, screens }) => {
553
+ if (!screens.length) return [];
554
+ const missing = [];
555
+ if (!appTarget.appName.trim()) missing.push("app-name");
556
+ if (!missing.length) return [];
557
+ return [
558
+ {
559
+ subject: missing.join(", "),
560
+ target: { kind: "panel", panel: "config" }
561
+ }
562
+ ];
563
+ }
564
+ });
565
+
566
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/binding-resolves.ts
567
+ var import_codegen13 = require("./index.js");
568
+ var bindingResolves = defineInvariant({
569
+ name: "binding-resolves",
570
+ message: "invariant-binding-unresolved",
571
+ severity: "blocking",
572
+ deps: ["features", "screens", "screenControlMaps", "functions"],
573
+ validate: ({ features, screens, screenControlMaps, functions }) => screens.flatMap((screen) => {
574
+ const feature = (0, import_codegen13.isFeatureScreen)(screen) ? features[screen.featureId] : void 0;
575
+ const controlMap = screenControlMaps[screen.id] ?? {};
576
+ const readable = feature ? (0, import_codegen13.readableMembers)(feature, import_codegen13.MAIN_STORE_OWNER) : void 0;
577
+ const scope = {
578
+ properties: readable?.properties,
579
+ shapes: feature?.shapes,
580
+ computeds: readable?.computeds,
581
+ inputs: screen.inputs,
582
+ screenComputeds: screen.computeds,
583
+ screenVariables: screen.variables,
584
+ // Screen-owned and read off the meta, as emit reads them (ADR 0127):
585
+ // without them every form-value read judged dangling.
586
+ formModels: screen.formModels,
587
+ functions: { ...functions, ...feature?.functions },
588
+ constants: screen.constants,
589
+ storeProp: (0, import_codegen13.isFeatureScreen)(screen) ? "store" : void 0,
590
+ controlMap
591
+ };
592
+ return Object.values(controlMap).flatMap((control) => {
593
+ const screenInputBindings = Object.values(
594
+ control.screenInputs ?? {}
595
+ ).flatMap(
596
+ (binding) => binding.kind === "data" ? [binding.binding] : []
597
+ );
598
+ const broken = [
599
+ ...Object.values(control.bindings ?? {}),
600
+ ...(0, import_codegen13.formatPipeBindings)(control),
601
+ ...screenInputBindings
602
+ ].some((binding) => !(0, import_codegen13.bindingExpression)(binding, scope));
603
+ if (!broken) return [];
604
+ return [
605
+ {
606
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
607
+ target: {
608
+ kind: "control",
609
+ screenId: screen.id,
610
+ controlId: control.id
611
+ }
612
+ }
613
+ ];
614
+ });
615
+ })
616
+ });
617
+
618
+ // apps/m-one-ui/src/app/pages/design/lib/screen-embed-helper.ts
619
+ var import_codegen14 = require("./index.js");
620
+ var isScreenControl = (control) => control.type === import_codegen14.ControlType.SCREEN && typeof control.screenId === "string";
621
+ function embeddedScreenIds(controlMap) {
622
+ return Object.values(controlMap).filter(isScreenControl).map((control) => control.screenId);
623
+ }
624
+ function reachableScreenIds(rootId, maps) {
625
+ const seen = /* @__PURE__ */ new Set();
626
+ const queue = [...embeddedScreenIds(maps[rootId] ?? {})];
627
+ while (queue.length) {
628
+ const id = queue.shift();
629
+ if (seen.has(id)) continue;
630
+ seen.add(id);
631
+ queue.push(...embeddedScreenIds(maps[id] ?? {}));
632
+ }
633
+ return seen;
634
+ }
635
+ var firesFromMount = (screen) => (0, import_codegen14.isFeatureScreen)(screen) && !!screen.autoCalls?.length;
636
+ function duplicateFeatureEmbeds(rootId, maps, screens) {
637
+ return [
638
+ ...new Set(
639
+ duplicateFeatureEmbedControls(rootId, maps, screens).map(
640
+ (mount) => mount.screenId
641
+ )
642
+ )
643
+ ].sort();
644
+ }
645
+ function duplicateFeatureEmbedControls(rootId, maps, screens) {
646
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
647
+ const mounts = /* @__PURE__ */ new Map();
648
+ const duplicates = /* @__PURE__ */ new Map();
649
+ const contains = (left, right) => [...right].every((gate) => left.has(gate));
650
+ const walk = (hostId, inherited, ancestors, instance) => {
651
+ if (ancestors.has(hostId)) return;
652
+ const seen = /* @__PURE__ */ new Set([...ancestors, hostId]);
653
+ const controls = maps[hostId] ?? {};
654
+ for (const control of Object.values(controls).filter(isScreenControl)) {
655
+ const gates = new Set(inherited);
656
+ const parents = /* @__PURE__ */ new Set();
657
+ let parent = control;
658
+ while (parent && !parents.has(parent.id)) {
659
+ parents.add(parent.id);
660
+ if (parent.variants?.length) {
661
+ gates.add(JSON.stringify([instance, "variants", parent.variants]));
662
+ }
663
+ if (parent.type === import_codegen14.ControlType.BRANCH_ARM) {
664
+ gates.add(
665
+ JSON.stringify([instance, "arm", parent.parentId, parent.id])
666
+ );
667
+ }
668
+ parent = parent.parentId ? controls[parent.parentId] : void 0;
669
+ }
670
+ const screen = byId.get(control.screenId);
671
+ if (screen && firesFromMount(screen)) {
672
+ const previous = mounts.get(screen.id) ?? [];
673
+ const mount = {
674
+ hostId,
675
+ controlId: control.id,
676
+ screenId: screen.id,
677
+ gates
678
+ };
679
+ previous.forEach((other) => {
680
+ if (contains(gates, other.gates) || contains(other.gates, gates)) {
681
+ duplicates.set(JSON.stringify([hostId, control.id]), mount);
682
+ duplicates.set(
683
+ JSON.stringify([other.hostId, other.controlId]),
684
+ other
685
+ );
686
+ }
687
+ });
688
+ previous.push(mount);
689
+ mounts.set(screen.id, previous);
690
+ }
691
+ walk(control.screenId, gates, seen, [...instance, control.id]);
692
+ }
693
+ };
694
+ walk(rootId, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), [rootId]);
695
+ return [...duplicates.values()].map(({ hostId, controlId, screenId }) => ({
696
+ hostId,
697
+ controlId,
698
+ screenId
699
+ }));
700
+ }
701
+ function featureReachEdges(maps, screens) {
702
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
703
+ const edges = /* @__PURE__ */ new Map();
704
+ for (const screen of screens) {
705
+ if (!(0, import_codegen14.isFeatureScreen)(screen)) continue;
706
+ for (const id of embeddedScreenIds(maps[screen.id] ?? {})) {
707
+ const target2 = byId.get(id);
708
+ if (!target2 || !(0, import_codegen14.isFeatureScreen)(target2)) continue;
709
+ if (target2.featureId === screen.featureId) continue;
710
+ const reached = edges.get(screen.featureId) ?? /* @__PURE__ */ new Set();
711
+ reached.add(target2.featureId);
712
+ edges.set(screen.featureId, reached);
713
+ }
714
+ }
715
+ return edges;
716
+ }
717
+ function featuresReachedBy(featureId, edges) {
718
+ const seen = /* @__PURE__ */ new Set();
719
+ const queue = [...edges.get(featureId) ?? []];
720
+ while (queue.length) {
721
+ const id = queue.shift();
722
+ if (seen.has(id)) continue;
723
+ seen.add(id);
724
+ queue.push(...edges.get(id) ?? []);
725
+ }
726
+ return seen;
727
+ }
728
+ function wouldCycleFeatures(hostFeatureId, targetFeatureId, edges) {
729
+ if (hostFeatureId === targetFeatureId) return false;
730
+ return targetFeatureId === hostFeatureId || featuresReachedBy(targetFeatureId, edges).has(hostFeatureId);
731
+ }
732
+ function screenEmbedProblems(host, maps, screens) {
733
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
734
+ const problems = [];
735
+ const featureEdges = featureReachEdges(maps, screens);
736
+ for (const control of Object.values(maps[host.id] ?? {})) {
737
+ if (!isScreenControl(control)) continue;
738
+ const target2 = byId.get(control.screenId);
739
+ if (!target2) {
740
+ problems.push({
741
+ kind: "missing-screen",
742
+ controlId: control.id,
743
+ screenId: control.screenId
744
+ });
745
+ continue;
746
+ }
747
+ if (!(0, import_codegen14.canEmbedScreen)(host, target2)) {
748
+ problems.push({
749
+ kind: "illegal-target",
750
+ controlId: control.id,
751
+ screenId: target2.id
752
+ });
753
+ continue;
754
+ }
755
+ if ((0, import_codegen14.isFeatureScreen)(host) && (0, import_codegen14.isFeatureScreen)(target2) && wouldCycleFeatures(host.featureId, target2.featureId, featureEdges)) {
756
+ problems.push({
757
+ kind: "feature-cycle",
758
+ controlId: control.id,
759
+ screenId: target2.id,
760
+ featureId: target2.featureId
761
+ });
762
+ continue;
763
+ }
764
+ const bound = control.screenInputs ?? {};
765
+ for (const input of Object.values(target2.inputs ?? {})) {
766
+ if (!input.required) continue;
767
+ const binding = bound[input.id];
768
+ if (!binding || binding.kind === "output") {
769
+ problems.push({
770
+ kind: "required-unbound",
771
+ controlId: control.id,
772
+ screenId: target2.id,
773
+ input: input.name
774
+ });
775
+ }
776
+ }
777
+ }
778
+ for (const screenId of duplicateFeatureEmbeds(host.id, maps, screens)) {
779
+ problems.push({ kind: "duplicate-feature-screen", screenId });
780
+ }
781
+ if (reachableScreenIds(host.id, maps).has(host.id)) {
782
+ problems.push({ kind: "cycle", screenId: host.id });
783
+ }
784
+ return problems;
785
+ }
786
+
787
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/screen-control-reachable.ts
788
+ var screenControlReachable = defineInvariant({
789
+ name: "screen-control-reachable",
790
+ message: "invariant-screen-control-unreachable",
791
+ severity: "blocking",
792
+ deps: ["screens", "screenControlMaps"],
793
+ // `screenControlMaps` already holds the open Screen live (ADR 0163), so a
794
+ // Screen edited since its last slot write is validated as it stands.
795
+ validate: ({ screens, screenControlMaps: maps }) => {
796
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
797
+ const findings = screens.flatMap(
798
+ (host) => screenEmbedProblems(host, maps, screens).flatMap(
799
+ (problem) => {
800
+ const subject = `${host.name} \u2192 ${byId.get(problem.screenId)?.name ?? problem.screenId}`;
801
+ if (problem.kind === "illegal-target" || problem.kind === "feature-cycle") {
802
+ return [
803
+ {
804
+ subject,
805
+ screenRetarget: true,
806
+ target: {
807
+ kind: "control",
808
+ screenId: host.id,
809
+ controlId: problem.controlId
810
+ }
811
+ }
812
+ ];
813
+ }
814
+ if (problem.kind === "duplicate-feature-screen") {
815
+ const mountName = (mount) => {
816
+ const control = maps[mount.hostId]?.[mount.controlId];
817
+ return `${byId.get(mount.hostId)?.name ?? mount.hostId}.${String(control?.configs["name"] ?? mount.controlId)}`;
818
+ };
819
+ const mounts = duplicateFeatureEmbedControls(
820
+ host.id,
821
+ maps,
822
+ screens
823
+ ).filter((mount) => mount.screenId === problem.screenId);
824
+ return mounts.map((mount) => ({
825
+ message: "invariant-screen-control-duplicate",
826
+ subject: `${mountName(mount)} \u2192 ${byId.get(mount.screenId)?.name ?? mount.screenId}, also at ${mounts.filter((other) => other !== mount).map(mountName).join(", ")}`,
827
+ target: {
828
+ kind: "control",
829
+ screenId: mount.hostId,
830
+ controlId: mount.controlId
831
+ }
832
+ }));
833
+ }
834
+ return [];
835
+ }
836
+ )
837
+ );
838
+ const unique = /* @__PURE__ */ new Map();
839
+ findings.forEach((finding) => {
840
+ const key = targetKey(finding.target);
841
+ if (!unique.has(key) || !finding.message) unique.set(key, finding);
842
+ });
843
+ return [...unique.values()];
844
+ }
845
+ });
846
+
847
+ // apps/m-one-ui/src/app/pages/design/lib/screen-input-binding-check.ts
848
+ var import_codegen15 = require("./index.js");
849
+ var staticFits = (input, value) => {
850
+ const primitive = (0, import_codegen15.inputPrimitive)(input);
851
+ if (!primitive) return false;
852
+ if (input.cardinality === "many") {
853
+ return (0, import_codegen15.fixedItems)(value).every(
854
+ (item) => staticFits({ ...input, cardinality: "one" }, item)
855
+ );
856
+ }
857
+ if (input.cardinality !== "one") return false;
858
+ if (primitive === "number")
859
+ return value.trim() !== "" && !isNaN(Number(value));
860
+ if (primitive === "boolean") return value === "true" || value === "false";
861
+ return true;
862
+ };
863
+ var outputFits = (input, binding, controlMap, screens) => {
864
+ if (input.required) return false;
865
+ const sibling = controlMap[binding.controlId];
866
+ if (!sibling || sibling.type !== import_codegen15.ControlType.SCREEN) return false;
867
+ const siblingScreen = screens.find(
868
+ (screen) => screen.id === sibling.screenId
869
+ );
870
+ if (!siblingScreen) return false;
871
+ const output = (0, import_codegen15.listScreenOutputs)(siblingScreen.outputs).find(
872
+ (entry) => entry.id === binding.outputId
873
+ );
874
+ const primitive = (0, import_codegen15.inputPrimitive)(input);
875
+ return !!output && !!primitive && output.payload?.dataType === primitive && output.payload?.cardinality === input.cardinality;
876
+ };
877
+ var sourceScope = (host, control, controlMap, features, functions, enums) => {
878
+ const feature = (0, import_codegen15.isFeatureScreen)(host) ? features[host.featureId] : void 0;
879
+ const readable = feature ? (0, import_codegen15.readableMembers)(feature, import_codegen15.MAIN_STORE_OWNER) : void 0;
880
+ const inScope = { ...functions, ...feature?.functions };
881
+ const properties = readable?.properties ?? {};
882
+ return {
883
+ inputs: host.inputs ?? {},
884
+ variables: host.variables ?? {},
885
+ constants: host.constants ?? {},
886
+ computeds: host.computeds ?? {},
887
+ enums,
888
+ functions: inScope,
889
+ data: {
890
+ controlId: control.id,
891
+ controlMap,
892
+ roots: (0, import_codegen15.propertiesWithComputeds)(
893
+ properties,
894
+ readable?.computeds ?? {},
895
+ inScope
896
+ ),
897
+ properties,
898
+ shapes: feature?.shapes ?? {},
899
+ inputs: host.inputs,
900
+ screenComputeds: host.computeds,
901
+ screenVariables: host.variables,
902
+ functions: inScope
903
+ }
904
+ };
905
+ };
906
+ function screenInputProblems(host, controlMap, screens, features, functions, enums) {
907
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
908
+ const problems = [];
909
+ for (const control of Object.values(controlMap)) {
910
+ if (!isScreenControl(control)) continue;
911
+ const target2 = byId.get(control.screenId);
912
+ if (!target2) continue;
913
+ const bound = control.screenInputs ?? {};
914
+ const scope = sourceScope(
915
+ host,
916
+ control,
917
+ controlMap,
918
+ features,
919
+ functions,
920
+ enums
921
+ );
922
+ for (const input of (0, import_codegen15.listScreenInputs)(target2.inputs)) {
923
+ if (input.origin) continue;
924
+ const binding = bound[input.id];
925
+ const row = {
926
+ controlId: control.id,
927
+ targetScreenId: target2.id,
928
+ inputId: input.id,
929
+ inputName: input.name
930
+ };
931
+ if (!binding || binding.kind === "output" && input.required) {
932
+ if (input.required) problems.push({ kind: "required-unbound", ...row });
933
+ continue;
934
+ }
935
+ const fits = binding.kind === "static" ? staticFits(input, binding.value) : binding.kind === "output" ? outputFits(input, binding, controlMap, screens) : (0, import_codegen15.screenInputSourceOptions)(scope, {
936
+ dataType: (0, import_codegen15.inputPrimitive)(input),
937
+ cardinality: input.cardinality,
938
+ declared: input.dataType,
939
+ required: input.required
940
+ }).some(
941
+ (option) => option.value === (0, import_codegen15.screenInputSourceValue)(binding)
942
+ );
943
+ if (!fits) problems.push({ kind: "unfit", ...row });
944
+ }
945
+ }
946
+ return problems;
947
+ }
948
+
949
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/screen-input-bound.ts
950
+ var screenInputBound = defineInvariant({
951
+ name: "screen-input-bound",
952
+ message: "invariant-screen-input-unbound",
953
+ severity: "blocking",
954
+ deps: [
955
+ "screens",
956
+ "screenControlMaps",
957
+ "features",
958
+ "functions",
959
+ "enums"
960
+ ],
961
+ validate: ({ screens, screenControlMaps, features, functions, enums }) => screens.flatMap((host) => {
962
+ const controlMap = screenControlMaps[host.id] ?? {};
963
+ const byId = new Map(screens.map((screen) => [screen.id, screen]));
964
+ return screenInputProblems(
965
+ host,
966
+ controlMap,
967
+ screens,
968
+ features,
969
+ functions,
970
+ enums
971
+ ).map((problem) => ({
972
+ message: problem.kind === "unfit" ? "invariant-screen-input-unfit" : "invariant-screen-input-unbound",
973
+ subject: `${host.name} \u2192 ${byId.get(problem.targetScreenId)?.name ?? problem.targetScreenId}: ${problem.inputName}`,
974
+ target: {
975
+ kind: "control",
976
+ screenId: host.id,
977
+ controlId: problem.controlId,
978
+ inputId: problem.inputId
979
+ }
980
+ }));
981
+ })
982
+ });
983
+
984
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/per-screen.ts
985
+ function perScreen(judge) {
986
+ const held = /* @__PURE__ */ new Map();
987
+ const sameDeps = (a, b) => Object.keys(b).every((key) => a[key] === b[key]);
988
+ return (screens, controlMaps, deps) => screens.flatMap((screen) => {
989
+ const controlMap = controlMaps[screen.id];
990
+ if (!controlMap) return [];
991
+ const kept = held.get(screen.id);
992
+ if (kept && kept.controlMap === controlMap && kept.screen === screen && sameDeps(kept.deps, deps)) {
993
+ return kept.answer;
994
+ }
995
+ const answer = judge(controlMap, screen, deps);
996
+ held.set(screen.id, { controlMap, screen, deps, answer });
997
+ return answer;
998
+ });
999
+ }
1000
+
1001
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/branch-arm-reachable.ts
1002
+ var import_codegen16 = require("./index.js");
1003
+ var ATOM_CAP = 12;
1004
+ var foldText = (arm, names) => (0, import_codegen16.controlVariants)(arm).map((entry, index) => {
1005
+ const name = names.get(entry.id) ?? entry.id;
1006
+ const term = (0, import_codegen16.variantJoinIsNot)(entry.join) ? `!${name}` : name;
1007
+ if (index === 0) return term;
1008
+ return `${(0, import_codegen16.variantJoinIsAnd)(entry.join) ? "&&" : "||"} ${term}`;
1009
+ }).join(" ");
1010
+ var armSubject = (arm, names) => (0, import_codegen16.armKind)(arm) === "default" ? import_codegen16.ARM_KIND_LABEL.default : foldText(arm, names) || import_codegen16.ARM_KIND_LABEL.branch;
1011
+ var variantNames = (features, screens, currentScreenId) => {
1012
+ const screen = screens.find((one) => one.id === currentScreenId);
1013
+ const feature = screen?.featureId ? features[screen.featureId] : void 0;
1014
+ const names = /* @__PURE__ */ new Map();
1015
+ Object.values(feature?.variants ?? {}).forEach(
1016
+ (variant) => names.set(variant.id, variant.name)
1017
+ );
1018
+ return names;
1019
+ };
1020
+ var unreachableArmIds = (branchId, controlMap) => {
1021
+ const arms = (0, import_codegen16.orderedArms)(branchId, controlMap).filter(
1022
+ (arm) => (0, import_codegen16.armKind)(arm) === "default" || (0, import_codegen16.controlVariants)(arm).length > 0
1023
+ );
1024
+ if (arms.length < 2) return [];
1025
+ const atoms = [
1026
+ ...new Set(
1027
+ arms.flatMap((arm) => (0, import_codegen16.controlVariants)(arm).map((entry) => entry.id))
1028
+ )
1029
+ ];
1030
+ if (atoms.length > ATOM_CAP) return [];
1031
+ const reached = /* @__PURE__ */ new Set();
1032
+ const rows = 1 << atoms.length;
1033
+ for (let row = 0; row < rows; row++) {
1034
+ const on = atoms.filter((_, index) => row & 1 << index);
1035
+ for (const arm of arms) {
1036
+ if ((0, import_codegen16.armKind)(arm) === "default" || (0, import_codegen16.evaluateVariantGate)((0, import_codegen16.controlVariants)(arm), on)) {
1037
+ reached.add(arm.id);
1038
+ break;
1039
+ }
1040
+ }
1041
+ }
1042
+ return arms.filter((arm) => !reached.has(arm.id)).map((arm) => arm.id);
1043
+ };
1044
+ var unreachableArms = perScreen(
1045
+ (controlMap, screen, { features, screens }) => {
1046
+ const names = variantNames(features, screens, screen.id);
1047
+ return Object.entries(controlMap).flatMap(([branchId, control]) => {
1048
+ if (control.type !== import_codegen16.ControlType.VARIANT_BRANCH) return [];
1049
+ return unreachableArmIds(branchId, controlMap).map((armId) => ({
1050
+ subject: armSubject(controlMap[armId], names),
1051
+ target: {
1052
+ kind: "control",
1053
+ screenId: screen.id,
1054
+ controlId: armId
1055
+ }
1056
+ }));
1057
+ });
1058
+ }
1059
+ );
1060
+ var branchArmReachable = defineInvariant({
1061
+ name: "branch-arm-reachable",
1062
+ message: "invariant-branch-arm-unreachable",
1063
+ severity: "advisory",
1064
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
1065
+ deps: ["screenControlMaps", "features", "screens"],
1066
+ validate: ({ screenControlMaps, features, screens }) => unreachableArms(screens, screenControlMaps, { features, screens })
1067
+ });
1068
+
1069
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-args-bound.ts
1070
+ var import_codegen17 = require("./index.js");
1071
+ var computedArgsBound = defineInvariant({
1072
+ name: "computed-args-bound",
1073
+ message: "invariant-computed-args-unbound",
1074
+ severity: "advisory",
1075
+ deps: ["features", "screens", "functions"],
1076
+ validate: ({ features, screens, functions }) => {
1077
+ const scopeFor = (featureId) => featureId ? { ...functions, ...features[featureId]?.functions ?? {} } : functions;
1078
+ const broken = (fn, args) => !fn || !(0, import_codegen17.argsComplete)(fn, args);
1079
+ const stateFindings = Object.values(features).flatMap((feature) => {
1080
+ const fns = scopeFor(feature.id);
1081
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
1082
+ return Object.values(feature.computeds ?? {}).filter((computed) => broken((0, import_codegen17.stateComputedFunction)(computed, fns), computed.args)).map((computed) => ({
1083
+ subject: `${feature.name}.${computed.name}`,
1084
+ target: { kind: "screen", screenId }
1085
+ }));
1086
+ });
1087
+ const screenFindings = screens.flatMap((screen) => {
1088
+ const fns = scopeFor(
1089
+ (0, import_codegen17.isFeatureScreen)(screen) ? screen.featureId : void 0
1090
+ );
1091
+ return Object.values(screen.computeds ?? {}).filter(
1092
+ (computed) => broken((0, import_codegen17.screenComputedFunction)(computed, fns), computed.args)
1093
+ ).map((computed) => ({
1094
+ subject: `${screen.name}.${computed.name}`,
1095
+ target: { kind: "screen", screenId: screen.id }
1096
+ }));
1097
+ });
1098
+ return [...stateFindings, ...screenFindings];
1099
+ }
1100
+ });
1101
+
1102
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/computed-args-typed.ts
1103
+ var import_codegen18 = require("./index.js");
1104
+ var computedArgsTyped = defineInvariant({
1105
+ name: "computed-args-typed",
1106
+ message: "invariant-computed-args-mistyped",
1107
+ severity: "blocking",
1108
+ deps: ["features", "screens", "screenControlMaps", "functions"],
1109
+ validate: ({ features, screens, screenControlMaps, functions }) => {
1110
+ const scopeFor = (featureId) => featureId ? { ...functions, ...features[featureId]?.functions ?? {} } : functions;
1111
+ const stateFindings = Object.values(features).flatMap((feature) => {
1112
+ const fns = scopeFor(feature.id);
1113
+ const screenId = screens.find((screen) => screen.featureId === feature.id)?.id ?? "";
1114
+ const roots = (0, import_codegen18.propertiesWithComputeds)(
1115
+ feature.properties,
1116
+ feature.computeds,
1117
+ fns
1118
+ );
1119
+ return Object.values(feature.computeds ?? {}).flatMap(
1120
+ (computed) => (
1121
+ // A OneFunction call has no signature to repair; its own Invariant
1122
+ // raises it (`one-function-arg-mismatch`, ADR 0218).
1123
+ computed.functionId ? [{ ...computed, functionId: computed.functionId }] : []
1124
+ )
1125
+ ).filter((computed) => {
1126
+ const fn = fns[computed.functionId];
1127
+ return !!fn && (0, import_codegen18.mistypedStateArgs)(fn, computed.args, roots, feature.shapes).length > 0;
1128
+ }).map((computed) => ({
1129
+ subject: `${feature.name}.${computed.name}`,
1130
+ target: { kind: "screen", screenId },
1131
+ computedFix: {
1132
+ computedId: computed.id,
1133
+ featureId: feature.id,
1134
+ functionId: computed.functionId,
1135
+ params: fns[computed.functionId].params.map((param) => {
1136
+ const held = (0, import_codegen18.stateComputedArgHeldType)(
1137
+ computed.args[param.id],
1138
+ roots,
1139
+ feature.shapes
1140
+ );
1141
+ return held && !(0, import_codegen18.argAnswersParam)(held, param, feature.shapes) ? { ...param, ...held } : param;
1142
+ })
1143
+ }
1144
+ }));
1145
+ });
1146
+ const screenFindings = screens.flatMap((screen) => {
1147
+ const featureId = (0, import_codegen18.isFeatureScreen)(screen) ? screen.featureId : void 0;
1148
+ const fns = scopeFor(featureId);
1149
+ const feature = featureId ? features[featureId] : void 0;
1150
+ const scope = {
1151
+ constants: screen.constants,
1152
+ variables: (0, import_codegen18.withVariableEnums)(
1153
+ screen.variables ?? {},
1154
+ screenControlMaps[screen.id] ?? {}
1155
+ ),
1156
+ properties: feature ? (0, import_codegen18.propertiesWithComputeds)(
1157
+ feature.properties,
1158
+ feature.computeds,
1159
+ fns
1160
+ ) : {},
1161
+ shapes: feature?.shapes ?? {}
1162
+ };
1163
+ return Object.values(screen.computeds ?? {}).filter((computed) => {
1164
+ if ((0, import_codegen18.isOneFunctionComputed)(computed)) return false;
1165
+ const fn = (0, import_codegen18.screenComputedFunction)(computed, fns);
1166
+ return !!fn && (0, import_codegen18.mistypedScreenArgs)(
1167
+ fn,
1168
+ computed.args,
1169
+ screen.inputs ?? {},
1170
+ screen.computeds ?? {},
1171
+ fns,
1172
+ scope
1173
+ ).length > 0;
1174
+ }).map((computed) => {
1175
+ const fn = (0, import_codegen18.screenComputedFunction)(computed, fns);
1176
+ const params = fn.params.map((param) => {
1177
+ const arg = computed.args[param.id];
1178
+ const shapeId = arg?.source === "options" ? (0, import_codegen18.findOptionRowShapeId)(scope.shapes) : void 0;
1179
+ const held = shapeId ? {
1180
+ dataType: { type: "shape", shapeId },
1181
+ cardinality: "many"
1182
+ } : (0, import_codegen18.screenComputedArgHeldType)(
1183
+ arg,
1184
+ screen.inputs ?? {},
1185
+ screen.computeds ?? {},
1186
+ fns,
1187
+ scope
1188
+ );
1189
+ return held && !(0, import_codegen18.argAnswersParam)(held, param, scope.shapes) ? { ...param, ...held } : param;
1190
+ });
1191
+ const repaired = { ...fn, params };
1192
+ const canFix = !(0, import_codegen18.isPassthroughComputed)(computed) && !(0, import_codegen18.isOneFunctionComputed)(computed) && (0, import_codegen18.mistypedScreenArgs)(
1193
+ repaired,
1194
+ computed.args,
1195
+ screen.inputs ?? {},
1196
+ screen.computeds ?? {},
1197
+ fns,
1198
+ scope
1199
+ ).length === 0;
1200
+ return {
1201
+ subject: `${screen.name}.${computed.name}`,
1202
+ target: { kind: "screen", screenId: screen.id },
1203
+ ...canFix ? {
1204
+ computedFix: {
1205
+ computedId: computed.id,
1206
+ featureId,
1207
+ functionId: fn.id,
1208
+ params
1209
+ }
1210
+ } : {}
1211
+ };
1212
+ });
1213
+ });
1214
+ return [...stateFindings, ...screenFindings];
1215
+ }
1216
+ });
1217
+
1218
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/one-function-arg-mismatch.ts
1219
+ var import_codegen19 = require("./index.js");
1220
+ 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;
1221
+ var oneFunctionArgMismatch = defineInvariant({
1222
+ name: "one-function-arg-mismatch",
1223
+ message: "invariant-one-function-arg-mismatch",
1224
+ severity: "blocking",
1225
+ deps: ["features", "screens", "functions"],
1226
+ validate: ({ features, screens, functions }) => [
1227
+ ...screens.flatMap((screen) => {
1228
+ const featureId = (0, import_codegen19.isFeatureScreen)(screen) ? screen.featureId : void 0;
1229
+ const feature = featureId ? features[featureId] : void 0;
1230
+ const fns = feature ? { ...functions, ...feature.functions ?? {} } : functions;
1231
+ const scope = {
1232
+ constants: screen.constants,
1233
+ variables: screen.variables,
1234
+ properties: feature ? (0, import_codegen19.propertiesWithComputeds)(feature.properties, feature.computeds, fns) : {},
1235
+ shapes: feature?.shapes ?? {}
1236
+ };
1237
+ return Object.values(screen.computeds ?? {}).filter(import_codegen19.isOneFunctionComputed).filter((computed) => {
1238
+ const entry = (0, import_codegen19.oneFunctionOf)(computed.oneFunction);
1239
+ const returns = computed.returns;
1240
+ if (!entry || !returns) return false;
1241
+ if (!feature) return true;
1242
+ return entry.params.some((param) => {
1243
+ const arg = computed.args[param.id];
1244
+ if (!arg) return false;
1245
+ const held = (0, import_codegen19.screenComputedArgHeldType)(
1246
+ arg,
1247
+ screen.inputs ?? {},
1248
+ screen.computeds ?? {},
1249
+ fns,
1250
+ scope
1251
+ );
1252
+ if (!held) return false;
1253
+ if (!(0, import_codegen19.oneFunctionArgFits)(param, held, arg.source === "path"))
1254
+ return true;
1255
+ return entry.returnsRow && param.id === entry.rowParamId && (!sameDataType(held.dataType, returns.dataType) || // A `map` turned `map-many` (or back) moves the return
1256
+ // between the row and the row list (ADR 0205).
1257
+ (0, import_codegen19.oneFunctionReturns)(entry, held.dataType, held.cardinality).cardinality !== returns.cardinality);
1258
+ });
1259
+ }).map((computed) => ({
1260
+ subject: `${screen.name}.${computed.name}`,
1261
+ // Its own editor is where the binding is re-saved.
1262
+ target: {
1263
+ kind: "screen",
1264
+ screenId: screen.id,
1265
+ panel: "screen",
1266
+ computedId: computed.id
1267
+ }
1268
+ }));
1269
+ }),
1270
+ ...Object.values(features).flatMap(
1271
+ (feature) => conditionFindings(feature, functions)
1272
+ ),
1273
+ ...Object.values(features).flatMap(
1274
+ (feature) => stateComputedFindings(feature, functions)
1275
+ )
1276
+ ]
1277
+ });
1278
+ function stateComputedFindings(feature, functions) {
1279
+ const fns = { ...functions, ...feature.functions ?? {} };
1280
+ const stores = (0, import_codegen19.storesOf)(feature);
1281
+ const roots = Object.assign(
1282
+ {},
1283
+ ...stores.map(
1284
+ (owned) => (0, import_codegen19.propertiesWithComputeds)(owned.properties, owned.computeds, fns)
1285
+ )
1286
+ );
1287
+ return stores.flatMap(
1288
+ (owned) => Object.values(owned.computeds).filter(import_codegen19.isOneFunctionStateComputed).filter((computed) => {
1289
+ const entry = (0, import_codegen19.oneFunctionOf)(computed.oneFunction);
1290
+ const returns = computed.returns;
1291
+ if (!entry?.reach.includes("state-computed") || !returns) return false;
1292
+ const rowArg = computed.args[entry.rowParamId];
1293
+ const row = rowArg?.source === "path" ? (0, import_codegen19.statePathHeldType)(rowArg.path, roots, feature.shapes) : void 0;
1294
+ const fits = entry.params.every((param) => {
1295
+ const arg = computed.args[param.id];
1296
+ if (!arg) return true;
1297
+ const held = arg.source === "fixed" ? (0, import_codegen19.oneParamFixedHeld)(param, arg.value) : (0, import_codegen19.statePathHeldType)(arg.path, roots, feature.shapes);
1298
+ if (arg.source === "path" && !held) return true;
1299
+ return (0, import_codegen19.oneFunctionArgFits)(param, held, arg.source === "path");
1300
+ });
1301
+ if (!fits) return true;
1302
+ if (entry.returnsRow && row && (!sameDataType(row.dataType, returns.dataType) || (0, import_codegen19.oneFunctionReturns)(entry, row.dataType, row.cardinality).cardinality !== returns.cardinality))
1303
+ return true;
1304
+ const key = computed.args[import_codegen19.ONE_FUNCTION_KEY_PARAM];
1305
+ if (key?.source === "fixed" && entry.params.some((param) => param.id === import_codegen19.ONE_FUNCTION_KEY_PARAM) && row?.dataType.type === "shape") {
1306
+ const shape = feature.shapes[row.dataType.shapeId];
1307
+ return !!shape && !shape.keys.some(
1308
+ (member) => member.name === key.value && member.cardinality === "one" && member.dataType.type === "string"
1309
+ );
1310
+ }
1311
+ return false;
1312
+ }).map((computed) => ({
1313
+ subject: `${feature.name}.${computed.name}`,
1314
+ target: {
1315
+ kind: "panel",
1316
+ panel: "store",
1317
+ featureId: feature.id,
1318
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
1319
+ memberId: computed.id
1320
+ }
1321
+ }))
1322
+ );
1323
+ }
1324
+ function conditionFindings(feature, functions) {
1325
+ const fns = { ...functions, ...feature.functions ?? {} };
1326
+ const stores = (0, import_codegen19.storesOf)(feature);
1327
+ const roots = Object.assign(
1328
+ {},
1329
+ ...stores.map(
1330
+ (owned) => (0, import_codegen19.propertiesWithComputeds)(owned.properties, owned.computeds, fns)
1331
+ )
1332
+ );
1333
+ const mismatched = (condition) => {
1334
+ if (!condition.oneFunction) return false;
1335
+ const entry = (0, import_codegen19.oneFunctionOf)(condition.oneFunction);
1336
+ if (!entry?.reach.includes("call-condition")) return true;
1337
+ return entry.params.some((param) => {
1338
+ const binding = condition.args[param.id];
1339
+ if (binding?.source !== "store") return false;
1340
+ const held = (0, import_codegen19.statePathHeldType)(binding.path, roots, feature.shapes);
1341
+ return !!held && !(0, import_codegen19.oneFunctionArgFits)(param, held, true);
1342
+ });
1343
+ };
1344
+ const computeMismatched = (compute) => {
1345
+ if (!compute.oneFunction) return false;
1346
+ const entry = (0, import_codegen19.oneFunctionOf)(compute.oneFunction);
1347
+ if (!entry?.reach.includes("call-compute") || !compute.returns) return true;
1348
+ const returns = compute.returns;
1349
+ return entry.params.some((param) => {
1350
+ const binding = compute.args[param.id];
1351
+ if (binding?.source !== "store") return false;
1352
+ const held = (0, import_codegen19.statePathHeldType)(binding.path, roots, feature.shapes);
1353
+ if (!held) return false;
1354
+ if (!(0, import_codegen19.oneFunctionArgFits)(param, held, true)) return true;
1355
+ return entry.returnsRow && param.id === entry.rowParamId && (!sameDataType(held.dataType, returns.dataType) || (0, import_codegen19.oneFunctionReturns)(entry, held.dataType, held.cardinality).cardinality !== returns.cardinality);
1356
+ });
1357
+ };
1358
+ return stores.flatMap(
1359
+ (owned) => Object.values(owned.methods).filter(
1360
+ (method) => (method.conditions ?? []).some(mismatched) || (method.computes ?? []).some(computeMismatched)
1361
+ ).map((method) => ({
1362
+ subject: `${feature.name}.${method.name}`,
1363
+ target: {
1364
+ kind: "panel",
1365
+ panel: "store",
1366
+ featureId: feature.id,
1367
+ ...owned.subStore ? { subStoreId: owned.subStore.id } : {},
1368
+ memberId: method.id
1369
+ }
1370
+ }))
1371
+ );
1372
+ }
1373
+
1374
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/one-function-required-param.ts
1375
+ var import_codegen20 = require("./index.js");
1376
+ var requiresParam = (method, name) => (method.params ?? []).some(
1377
+ (param) => param.name === name && param.required === true
1378
+ ) || method.inputs.some(
1379
+ (mapping) => mapping.source === "args" && mapping.arg === name && mapping.target[0] === "path"
1380
+ );
1381
+ var oneFunctionRequiredParam = defineInvariant({
1382
+ name: "one-function-required-param",
1383
+ message: "invariant-one-function-required-param",
1384
+ severity: "blocking",
1385
+ deps: ["features", "screens", "screenControlMaps"],
1386
+ validate: ({ features, screens, screenControlMaps }) => screens.flatMap((screen) => {
1387
+ if (!(0, import_codegen20.isFeatureScreen)(screen)) return [];
1388
+ const feature = features[screen.featureId];
1389
+ if (!feature) return [];
1390
+ const methods = Object.assign(
1391
+ {},
1392
+ ...(0, import_codegen20.storesOf)(feature).map((owned) => owned.methods)
1393
+ );
1394
+ const computeds = screen.computeds ?? {};
1395
+ return Object.values(screenControlMaps[screen.id] ?? {}).flatMap(
1396
+ (control) => Object.entries(control.outputs ?? {}).flatMap(
1397
+ ([output, methodId]) => {
1398
+ const method = methods[methodId];
1399
+ if (!method) return [];
1400
+ return (control.outputArgs?.[output] ?? []).filter((row) => {
1401
+ const root = row.binding?.root;
1402
+ if (row.source !== "binding" || root?.kind !== "screen_computed")
1403
+ return false;
1404
+ const computed = computeds[root.id];
1405
+ const name = row.target[0];
1406
+ return !!computed && (0, import_codegen20.isOneFunctionComputed)(computed) && (0, import_codegen20.screenComputedFunction)(computed, {})?.returnUndefined === true && !!name && requiresParam(method, name);
1407
+ }).map((row) => ({
1408
+ subject: `${screen.name}.${method.name}(${row.target[0]})`,
1409
+ target: {
1410
+ kind: "control",
1411
+ screenId: screen.id,
1412
+ controlId: control.id
1413
+ }
1414
+ }));
1415
+ }
1416
+ )
1417
+ );
1418
+ })
1419
+ });
1420
+
1421
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/confirm-unattended-call.ts
1422
+ var import_codegen21 = require("./index.js");
1423
+ var confirmUnattendedCall = defineInvariant({
1424
+ name: "confirm-unattended-call",
1425
+ message: "invariant-confirm-unattended",
1426
+ severity: "advisory",
1427
+ deps: ["features", "screens"],
1428
+ validate: ({ features, screens }) => {
1429
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
1430
+ return Object.values(features).flatMap((feature) => {
1431
+ const asking = new Set(
1432
+ Object.values(feature.methods).filter((method) => !!(0, import_codegen21.drawnConfirm)(method)).map((method) => method.id)
1433
+ );
1434
+ if (!asking.size) return [];
1435
+ const named2 = (methodId) => feature.methods[methodId]?.name ?? methodId;
1436
+ const fromHook = (feature.hook?.calls ?? []).filter((call) => asking.has(call.methodId)).map((call) => ({
1437
+ subject: `${feature.name}.${named2(call.methodId)}`,
1438
+ target: {
1439
+ kind: "screen",
1440
+ screenId: featureScreen(feature.id)
1441
+ }
1442
+ }));
1443
+ const fromTimers = Object.values(feature.timers ?? {}).flatMap(
1444
+ (timer) => timer.calls.filter((call) => asking.has(call.methodId)).map((call) => ({
1445
+ subject: `${feature.name}.${timer.name} \u2192 ${named2(call.methodId)}`,
1446
+ target: {
1447
+ kind: "screen",
1448
+ screenId: featureScreen(feature.id)
1449
+ }
1450
+ }))
1451
+ );
1452
+ const fromAutoCalls = screens.filter((screen) => screen.featureId === feature.id).flatMap(
1453
+ (screen) => (screen.autoCalls ?? []).flatMap(
1454
+ (call) => call.methodId && asking.has(call.methodId) ? [call.methodId] : []
1455
+ ).map((methodId) => ({
1456
+ subject: `${screen.name} \u2192 ${named2(methodId)}`,
1457
+ target: { kind: "screen", screenId: screen.id }
1458
+ }))
1459
+ );
1460
+ return [...fromHook, ...fromTimers, ...fromAutoCalls];
1461
+ });
1462
+ }
1463
+ });
1464
+
1465
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/close-overlay-off-overlay.ts
1466
+ var import_codegen23 = require("./index.js");
1467
+
1468
+ // apps/m-one-ui/src/app/pages/design/lib/screen-link.ts
1469
+ var import_codegen22 = require("./index.js");
1470
+ function overlayLinks(fromScreenId, map) {
1471
+ const links = [];
1472
+ Object.values(map).forEach((control) => {
1473
+ Object.entries(control.directives ?? {}).forEach(([name, directive]) => {
1474
+ if (!(0, import_codegen22.isOverlayDirectiveName)(name)) return;
1475
+ const configs = directive.overlayId ? map[directive.overlayId]?.configs : directive.configs;
1476
+ const component = configs?.["component"];
1477
+ if (typeof component !== "string" || !component) return;
1478
+ links.push({
1479
+ kind: "overlay-component",
1480
+ fromScreenId,
1481
+ controlId: directive.overlayId ?? control.id,
1482
+ toScreenId: component
1483
+ });
1484
+ });
1485
+ });
1486
+ return links;
1487
+ }
1488
+ var cardKind = (control) => control.type === import_codegen22.ControlType.SECTION_CAROUSEL ? "carousel-element" : "card-element";
1489
+ function controlMapLinks(fromScreenId, map) {
1490
+ const links = [];
1491
+ Object.values(map).forEach((control) => {
1492
+ if (isScreenControl(control)) {
1493
+ links.push({
1494
+ kind: "screen-control",
1495
+ fromScreenId,
1496
+ controlId: control.id,
1497
+ toScreenId: control.screenId
1498
+ });
1499
+ }
1500
+ const cardScreenId = control.cards?.screenId;
1501
+ if (cardScreenId) {
1502
+ links.push({
1503
+ kind: cardKind(control),
1504
+ fromScreenId,
1505
+ controlId: control.id,
1506
+ toScreenId: cardScreenId
1507
+ });
1508
+ }
1509
+ Object.keys(control.outputOpens ?? {}).forEach((output) => {
1510
+ const screenId = (0, import_codegen22.outputOpenOf)(control.outputOpens, output)?.screenId;
1511
+ if (!screenId) return;
1512
+ links.push({
1513
+ kind: "output-open",
1514
+ fromScreenId,
1515
+ controlId: control.id,
1516
+ toScreenId: screenId
1517
+ });
1518
+ });
1519
+ const searchScreenId = control.search?.screenId;
1520
+ if (searchScreenId) {
1521
+ links.push({
1522
+ kind: "search-results",
1523
+ fromScreenId,
1524
+ controlId: control.id,
1525
+ toScreenId: searchScreenId
1526
+ });
1527
+ }
1528
+ });
1529
+ return [...links, ...overlayLinks(fromScreenId, map)];
1530
+ }
1531
+ function navLinks(navMap) {
1532
+ const links = [];
1533
+ Object.values(navMap).forEach((nav) => {
1534
+ if (nav.pageId) {
1535
+ links.push({
1536
+ kind: "nav-url",
1537
+ fromNavId: nav.navId,
1538
+ toScreenId: nav.pageId
1539
+ });
1540
+ }
1541
+ if (nav.componentKey) {
1542
+ links.push({
1543
+ kind: "nav-component",
1544
+ fromNavId: nav.navId,
1545
+ toScreenId: nav.componentKey
1546
+ });
1547
+ }
1548
+ if (nav.rowSource?.kind === "screen" && nav.rowSource.screenId) {
1549
+ links.push({
1550
+ kind: "nav-rows",
1551
+ fromNavId: nav.navId,
1552
+ toScreenId: nav.rowSource.screenId
1553
+ });
1554
+ }
1555
+ if (nav.searchAnswer?.kind === "screen" && nav.searchAnswer.screenId) {
1556
+ links.push({
1557
+ kind: "search-answer",
1558
+ fromNavId: nav.navId,
1559
+ toScreenId: nav.searchAnswer.screenId
1560
+ });
1561
+ }
1562
+ });
1563
+ return links;
1564
+ }
1565
+ function methodLinks(features) {
1566
+ const links = [];
1567
+ Object.values(features).forEach((feature) => {
1568
+ const stores = [
1569
+ { subStoreId: void 0, methods: feature.methods },
1570
+ ...Object.values(feature.subStores ?? {}).map((sub) => ({
1571
+ subStoreId: sub.id,
1572
+ methods: sub.methods
1573
+ }))
1574
+ ];
1575
+ stores.forEach(({ subStoreId, methods }) => {
1576
+ Object.values(methods).forEach((method) => {
1577
+ const screenId = method.open?.screenId;
1578
+ if (!screenId) return;
1579
+ links.push({
1580
+ kind: "method-open",
1581
+ fromFeatureId: feature.id,
1582
+ methodId: method.id,
1583
+ ...subStoreId ? { subStoreId } : {},
1584
+ toScreenId: screenId
1585
+ });
1586
+ });
1587
+ });
1588
+ });
1589
+ return links;
1590
+ }
1591
+ function screenLinks(maps, navMap, features = {}) {
1592
+ const fromControls = Object.entries(maps).flatMap(
1593
+ ([screenId, map]) => controlMapLinks(screenId, map)
1594
+ );
1595
+ return [...fromControls, ...navLinks(navMap), ...methodLinks(features)];
1596
+ }
1597
+ var inboundLinks = (links, screenId) => links.filter((link) => link.toScreenId === screenId);
1598
+
1599
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/close-overlay-off-overlay.ts
1600
+ var OVERLAY_KINDS = [
1601
+ "overlay-component",
1602
+ "output-open",
1603
+ "method-open"
1604
+ ];
1605
+ var closeOverlayOffOverlay = defineInvariant({
1606
+ name: "close-overlay-off-overlay",
1607
+ message: "invariant-close-overlay-off-overlay",
1608
+ severity: "advisory",
1609
+ // The link index's own dependencies. Read on a coarse change, the habit
1610
+ // ADR 0126 keeps: what opens a Screen is not this Screen's own business.
1611
+ deps: ["screens", "screenControlMaps", "navMap", "features"],
1612
+ validate: ({ screens, screenControlMaps, navMap, features }) => {
1613
+ const closing = screens.map((screen) => ({
1614
+ screen,
1615
+ controls: Object.values(screenControlMaps[screen.id] ?? {}).filter(
1616
+ import_codegen23.controlUsesOverlayRef
1617
+ )
1618
+ })).filter(({ controls }) => controls.length);
1619
+ if (!closing.length) return [];
1620
+ const links = screenLinks(screenControlMaps, navMap, features);
1621
+ return closing.flatMap(
1622
+ ({ screen, controls }) => inboundLinks(links, screen.id).some(
1623
+ (link) => OVERLAY_KINDS.includes(link.kind)
1624
+ ) ? [] : controls.map((control) => ({
1625
+ subject: `${screen.name} \u2192 ${String(
1626
+ control.configs["name"] ?? control.id
1627
+ )}`,
1628
+ target: {
1629
+ kind: "control",
1630
+ screenId: screen.id,
1631
+ controlId: control.id
1632
+ }
1633
+ }))
1634
+ );
1635
+ }
1636
+ });
1637
+
1638
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-unattended-call.ts
1639
+ var import_codegen24 = require("./index.js");
1640
+ var outcomeUnattendedCall = defineInvariant({
1641
+ name: "outcome-on-unattended-call",
1642
+ message: "invariant-outcome-unattended",
1643
+ severity: "advisory",
1644
+ // Every Screen's Controls rather than the open one's: a hook fires a method
1645
+ // some other Screen's button armed, and the finding belongs to the Feature.
1646
+ // Read on a coarse change, which is what this dependency already costs.
1647
+ deps: ["features", "screens", "screenControlMaps"],
1648
+ validate: ({ features, screens, screenControlMaps }) => {
1649
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
1650
+ return Object.values(features).flatMap((feature) => {
1651
+ const armed = (0, import_codegen24.methodArms)(
1652
+ screens.filter((screen) => screen.featureId === feature.id).map((screen) => screenControlMaps[screen.id] ?? {})
1653
+ );
1654
+ const wired = new Set(Object.keys(armed));
1655
+ if (!wired.size) return [];
1656
+ const named2 = (methodId) => feature.methods[methodId]?.name ?? methodId;
1657
+ const fromHook = (feature.hook?.calls ?? []).filter((call) => wired.has(call.methodId)).map((call) => ({
1658
+ subject: `${feature.name}.${named2(call.methodId)}`,
1659
+ target: {
1660
+ kind: "screen",
1661
+ screenId: featureScreen(feature.id)
1662
+ }
1663
+ }));
1664
+ const fromTimers = Object.values(feature.timers ?? {}).flatMap(
1665
+ (timer) => timer.calls.filter((call) => wired.has(call.methodId)).map((call) => ({
1666
+ subject: `${feature.name}.${timer.name} \u2192 ${named2(call.methodId)}`,
1667
+ target: {
1668
+ kind: "screen",
1669
+ screenId: featureScreen(feature.id)
1670
+ }
1671
+ }))
1672
+ );
1673
+ const fromAutoCalls = screens.filter((screen) => screen.featureId === feature.id).flatMap(
1674
+ (screen) => (screen.autoCalls ?? []).flatMap(
1675
+ (call) => call.methodId && wired.has(call.methodId) ? [call.methodId] : []
1676
+ ).map((methodId) => ({
1677
+ subject: `${screen.name} \u2192 ${named2(methodId)}`,
1678
+ target: { kind: "screen", screenId: screen.id }
1679
+ }))
1680
+ );
1681
+ return [...fromHook, ...fromTimers, ...fromAutoCalls];
1682
+ });
1683
+ }
1684
+ });
1685
+
1686
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-call-nested.ts
1687
+ var import_codegen25 = require("./index.js");
1688
+ var outcomeCallNested = defineInvariant({
1689
+ name: "outcome-call-nested",
1690
+ message: "invariant-outcome-call-nested",
1691
+ severity: "advisory",
1692
+ deps: ["screens", "screenControlMaps"],
1693
+ validate: ({ screens, screenControlMaps }) => screens.flatMap((screen) => {
1694
+ const onScreen = (outcomes) => outcomes.flatMap(import_codegen25.nestedOutcomeCalls).map((id) => ({
1695
+ subject: `${screen.name} \u2192 ${id}`,
1696
+ target: { kind: "screen", screenId: screen.id }
1697
+ }));
1698
+ const onControls = Object.values(
1699
+ screenControlMaps[screen.id] ?? {}
1700
+ ).flatMap(
1701
+ (control) => Object.values(control.outputOutcomes ?? {}).flatMap(import_codegen25.nestedOutcomeCalls).map((id) => ({
1702
+ subject: `${screen.name} \u2192 ${control.id} \u2192 ${id}`,
1703
+ target: {
1704
+ kind: "control",
1705
+ screenId: screen.id,
1706
+ controlId: control.id
1707
+ }
1708
+ }))
1709
+ );
1710
+ return [
1711
+ ...onControls,
1712
+ ...onScreen([
1713
+ ...Object.values(screen.methods ?? {}).flatMap((handler) => [
1714
+ handler.outcome,
1715
+ ...(handler.calls ?? []).map((one) => one.outcome)
1716
+ ]),
1717
+ ...(screen.autoCalls ?? []).map((call) => call.outcome)
1718
+ ])
1719
+ ];
1720
+ })
1721
+ });
1722
+
1723
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/reaction-writes-own-watch.ts
1724
+ var reactionWritesOwnWatch = defineInvariant({
1725
+ name: "reaction-writes-own-watch",
1726
+ message: "invariant-reaction-writes-own-watch",
1727
+ severity: "blocking",
1728
+ deps: ["screens"],
1729
+ validate: ({ screens }) => screens.flatMap(
1730
+ (screen) => (screen.autoCalls ?? []).flatMap((call) => {
1731
+ const watched = new Set(
1732
+ (call.reads ?? []).filter((read) => !read.path.length).map(
1733
+ (read) => read.root.kind === "screen_variable" || read.root.kind === "property" ? `${read.root.kind}:${read.root.id}` : ""
1734
+ ).filter(Boolean)
1735
+ );
1736
+ if (!watched.size) return [];
1737
+ const written = [
1738
+ ...(call.screenWrites ?? []).map((row) => ({
1739
+ key: `screen_variable:${row.variableId}`,
1740
+ name: screen.variables?.[row.variableId]?.name ?? row.variableId
1741
+ })),
1742
+ ...(call.writes ?? []).map((row) => ({
1743
+ key: `property:${row.propertyId}`,
1744
+ name: row.propertyId
1745
+ }))
1746
+ ];
1747
+ return written.filter((row) => watched.has(row.key)).map((row) => ({
1748
+ subject: `${screen.name} \u2192 ${row.name}`,
1749
+ target: { kind: "screen", screenId: screen.id }
1750
+ }));
1751
+ })
1752
+ )
1753
+ });
1754
+
1755
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/outcome-nav-complete.ts
1756
+ var import_codegen26 = require("./index.js");
1757
+ var outcomeNavComplete = defineInvariant({
1758
+ name: "outcome-nav-complete",
1759
+ message: "invariant-outcome-nav-incomplete",
1760
+ severity: "advisory",
1761
+ deps: ["screens", "screenControlMaps", "navMap"],
1762
+ validate: ({ screens, screenControlMaps, navMap }) => screens.flatMap((screen) => {
1763
+ const controlMap = screenControlMaps[screen.id] ?? {};
1764
+ return Object.values(controlMap).flatMap((control) => {
1765
+ const broken = Object.values(control.outputOutcomes ?? {}).some(
1766
+ (outcome) => import_codegen26.OUTCOME_ARMS.some(
1767
+ (arm) => !!(0, import_codegen26.validateOutcomeNav)(outcome?.[arm]?.nav, navMap)
1768
+ )
1769
+ ) || (0, import_codegen26.controlNavReferences)(control).some(
1770
+ (row) => row.some((navId) => !navMap[navId])
1771
+ );
1772
+ if (!broken) return [];
1773
+ return [
1774
+ {
1775
+ subject: `${screen.name} \u2192 ${String(control.configs["name"] ?? control.id)}`,
1776
+ target: {
1777
+ kind: "control",
1778
+ screenId: screen.id,
1779
+ controlId: control.id
1780
+ }
1781
+ }
1782
+ ];
1783
+ });
1784
+ })
1785
+ });
1786
+
1787
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/field-check-bound.ts
1788
+ var import_codegen27 = require("./index.js");
1789
+ var fieldCheckBound = defineInvariant({
1790
+ name: "field-check-bound",
1791
+ message: "invariant-field-check-unbound",
1792
+ severity: "advisory",
1793
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
1794
+ deps: ["screenControlMaps", "features", "functions", "screens"],
1795
+ validate: ({ screenControlMaps, features, functions, screens }) => unboundChecks(screens, screenControlMaps, { features, functions })
1796
+ });
1797
+ var unboundChecks = perScreen(
1798
+ (controlMap, screen, {
1799
+ features,
1800
+ functions
1801
+ }) => {
1802
+ const feature = (0, import_codegen27.isFeatureScreen)(screen) ? features[screen.featureId] : void 0;
1803
+ const properties = feature?.properties ?? {};
1804
+ const sources = (0, import_codegen27.limitSources)({
1805
+ inputs: screen.inputs,
1806
+ constants: screen.constants,
1807
+ variables: screen.variables,
1808
+ screenComputeds: screen.computeds,
1809
+ properties,
1810
+ computeds: feature?.computeds,
1811
+ functions: { ...functions, ...feature?.functions ?? {} }
1812
+ });
1813
+ return Object.entries(controlMap).flatMap(([controlId, control]) => {
1814
+ if (control.type !== import_codegen27.ControlType.FIELD) return [];
1815
+ const checks = (0, import_codegen27.fieldChecks)(control);
1816
+ if (!checks.length) return [];
1817
+ const formId = (0, import_codegen27.owningFormId)(controlId, controlMap);
1818
+ const broken = checks.some((check) => {
1819
+ if ((0, import_codegen27.checkKind)(check) !== "function") {
1820
+ return !(0, import_codegen27.isCheckComplete)(
1821
+ check,
1822
+ functions,
1823
+ controlMap,
1824
+ properties,
1825
+ sources
1826
+ );
1827
+ }
1828
+ const fn = functions[check.functionId];
1829
+ if (!fn) return true;
1830
+ if (!(0, import_codegen27.isFieldCheckEligible)(fn)) return true;
1831
+ const writtenFor = (0, import_codegen27.fieldCheckFormId)(fn);
1832
+ if (writtenFor && writtenFor !== formId) return true;
1833
+ return !(0, import_codegen27.isCheckComplete)(check, functions, controlMap, properties);
1834
+ });
1835
+ if (!broken) return [];
1836
+ return [
1837
+ {
1838
+ subject: (0, import_codegen27.resolveFieldName)({
1839
+ id: controlId,
1840
+ configs: control.configs
1841
+ }),
1842
+ target: {
1843
+ kind: "control",
1844
+ screenId: screen.id,
1845
+ controlId
1846
+ }
1847
+ }
1848
+ ];
1849
+ });
1850
+ }
1851
+ );
1852
+
1853
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/function-case-args.ts
1854
+ var import_codegen28 = require("./index.js");
1855
+ var functionCaseArgs = defineInvariant({
1856
+ name: "function-case-args",
1857
+ message: "invariant-function-case-args",
1858
+ severity: "advisory",
1859
+ deps: ["features", "functions", "sharedShapes"],
1860
+ validate: ({ features, functions, sharedShapes }) => {
1861
+ const shared = sharedShapes ?? {};
1862
+ return [
1863
+ ...(0, import_codegen28.listFunctions)(functions).map((fn) => ({
1864
+ fn,
1865
+ featureId: void 0,
1866
+ shapes: (0, import_codegen28.shapesInReach)(void 0, shared)
1867
+ })),
1868
+ ...Object.values(features).flatMap(
1869
+ (feature) => (0, import_codegen28.listFunctions)(feature.functions).map((fn) => ({
1870
+ fn,
1871
+ featureId: feature.id,
1872
+ shapes: (0, import_codegen28.shapesInReach)(feature, shared)
1873
+ }))
1874
+ )
1875
+ ].filter(({ fn, shapes }) => (0, import_codegen28.staleCases)(fn, shapes).length > 0).map(({ fn, featureId, shapes }) => ({
1876
+ subject: `${fn.name}: ${(0, import_codegen28.staleCases)(fn, shapes).map((entry) => entry.name).join(", ")}`,
1877
+ target: {
1878
+ kind: "function",
1879
+ ...featureId ? { featureId } : {},
1880
+ functionId: fn.id
1881
+ }
1882
+ }));
1883
+ }
1884
+ });
1885
+
1886
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/filter-group-squeeze-orphan.ts
1887
+ var import_codegen29 = require("./index.js");
1888
+ var orphanIds = (groupId, controlMap) => {
1889
+ const found = [];
1890
+ const seen = /* @__PURE__ */ new Set();
1891
+ const walk = (id) => {
1892
+ if (seen.has(id)) return;
1893
+ seen.add(id);
1894
+ for (const childId of controlMap[id]?.childrens ?? []) {
1895
+ const child = controlMap[childId];
1896
+ if (!child) continue;
1897
+ if (child.type === import_codegen29.ControlType.SECTION_FILTER) continue;
1898
+ if (child.type === import_codegen29.ControlType.COL) {
1899
+ walk(childId);
1900
+ continue;
1901
+ }
1902
+ found.push(childId);
1903
+ }
1904
+ };
1905
+ walk(groupId);
1906
+ return found;
1907
+ };
1908
+ var filterGroupSqueezeOrphan = defineInvariant({
1909
+ name: "filter-group-squeeze-orphan",
1910
+ message: "invariant-filter-group-squeeze-orphan",
1911
+ severity: "advisory",
1912
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
1913
+ deps: ["screenControlMaps", "screens"],
1914
+ validate: ({ screenControlMaps, screens }) => squeezedOrphans(screens, screenControlMaps, {})
1915
+ });
1916
+ var squeezedOrphans = perScreen(
1917
+ (controlMap, screen) => Object.entries(controlMap).flatMap(([groupId, control]) => {
1918
+ if (control.type !== import_codegen29.ControlType.SECTION_FILTER_GROUP) return [];
1919
+ const parentId = control.parentId;
1920
+ const squeezed = !!control.configs?.["squeeze"] || !!parentId && controlMap[parentId]?.type === import_codegen29.ControlType.SECTION_HEADER;
1921
+ if (!squeezed) return [];
1922
+ return orphanIds(groupId, controlMap).map((orphanId) => ({
1923
+ subject: import_codegen29.CONTROL_LABEL[controlMap[orphanId].type],
1924
+ target: {
1925
+ kind: "control",
1926
+ screenId: screen.id,
1927
+ controlId: orphanId
1928
+ }
1929
+ }));
1930
+ })
1931
+ );
1932
+
1933
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/context-group-primary-unique.ts
1934
+ var import_codegen30 = require("./index.js");
1935
+ var contextGroupPrimaryUnique = defineInvariant({
1936
+ name: "context-group-primary-unique",
1937
+ message: "invariant-context-group-primary-unique",
1938
+ severity: "advisory",
1939
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
1940
+ deps: ["screenControlMaps", "screens"],
1941
+ validate: ({ screenControlMaps, screens }) => duplicatePrimaries(screens, screenControlMaps, {})
1942
+ });
1943
+ var duplicatePrimaries = perScreen(
1944
+ (controlMap, screen) => Object.entries(controlMap).flatMap(([groupId, control]) => {
1945
+ if (control.type !== import_codegen30.ControlType.SECTION_BUTTON_GROUP) return [];
1946
+ if (control.configs?.["variant"] !== "context") return [];
1947
+ const primaries = (control.childrens ?? []).filter((childId) => {
1948
+ const child = controlMap[childId];
1949
+ return child?.type === import_codegen30.ControlType.BUTTON && child.configs?.["variant"] === "primary";
1950
+ });
1951
+ return primaries.slice(1).map((buttonId) => ({
1952
+ subject: import_codegen30.CONTROL_LABEL[import_codegen30.ControlType.BUTTON],
1953
+ target: {
1954
+ kind: "control",
1955
+ screenId: screen.id,
1956
+ controlId: buttonId
1957
+ }
1958
+ }));
1959
+ })
1960
+ );
1961
+
1962
+ // apps/m-one-ui/src/app/pages/design/lib/hand-binding-helper.ts
1963
+ var import_codegen32 = require("./index.js");
1964
+
1965
+ // apps/m-one-ui/src/app/pages/design/lib/control-outputs.ts
1966
+ var import_codegen31 = require("./index.js");
1967
+ var CONTROL_OUTPUTS = {
1968
+ [import_codegen31.ControlType.BUTTON]: ["clicked"],
1969
+ [import_codegen31.ControlType.CONTEXT_MENU]: ["action"],
1970
+ // The picker's own value, once the User has moved it — the write half of the
1971
+ // controlled binding, drawn as a StateWrite rather than as `[(audience)]`
1972
+ // (ADR 0187, ADR 0065). Offered whatever the two halves hold: a picker bound
1973
+ // to no `audience` still edits its own value and still fires this.
1974
+ [import_codegen31.ControlType.AUDIENCE_PICKER]: ["audienceChange"],
1975
+ [import_codegen31.ControlType.CARD]: ["clicked"],
1976
+ // `submitted` is offered only under a Button declaring `isSubmit` — see
1977
+ // `outputsOf` below.
1978
+ [import_codegen31.ControlType.FORM]: ["submitted", "dataChange", "formInitialized"],
1979
+ // The Field's own `dataChange`, at field granularity — the value the User
1980
+ // typed into this one field, not the form's record (libs/one ADR 0032).
1981
+ // Needs no Button, the way the form's does not (see `outputsOf`).
1982
+ [import_codegen31.ControlType.FIELD]: ["dataChange"],
1983
+ [import_codegen31.ControlType.SECTION]: ["inView"],
1984
+ [import_codegen31.ControlType.SECTION_HEADER]: ["actionClick", "action", "back"],
1985
+ // Debounced already by the component — what arrives here is the term the User
1986
+ // stopped typing, which is the only thing worth binding a call to.
1987
+ [import_codegen31.ControlType.SECTION_SEARCH]: ["searchChange"],
1988
+ // One output for the whole bar, carrying the Button that was pressed — an
1989
+ // `m-action` names its Buttons rather than holding them, so there is no
1990
+ // per-Button Control for a binding to sit on (ADR 0009).
1991
+ [import_codegen31.ControlType.SECTION_ACTION]: ["clicked"],
1992
+ // Which slide is showing, every time it changes — by drag, by indicator, or
1993
+ // by the clock. Two spellings of the one event, because what a caller binds
1994
+ // differs: `slideChange` carries the position, `itemChange` the row behind it,
1995
+ // which is what a call needing the slide's own data takes.
1996
+ [import_codegen31.ControlType.SECTION_CAROUSEL]: ["slideChange", "itemChange"],
1997
+ // The whole group's selection, every time any Filter beneath it changes
1998
+ // (libs/one ADR 0025). Per-change rather than on-close: a group has no single
1999
+ // close event full-width, and `switchMap` in the emitted store already drops
2000
+ // the responses of calls a later change supersedes.
2001
+ [import_codegen31.ControlType.SECTION_FILTER_GROUP]: ["filterChange"],
2002
+ // Offered only outside a group — see `outputsOf` below.
2003
+ [import_codegen31.ControlType.SECTION_FILTER]: ["filterChange"],
2004
+ // One payload, `{offset, perPage}`, and both members are pickable — a
2005
+ // CallArgMapping reading `event.offset` gets a number, which is what an
2006
+ // ApiOperation's query param takes. The whole `$event` works too, unlike a
2007
+ // FilterGroup's list of pairs (ADR 0097).
2008
+ [import_codegen31.ControlType.SECTION_PAGINATION]: ["paginationChange"],
2009
+ // `{id, direction}`, after the rows were reordered in place — bound when the
2010
+ // table holds one page of a longer list and whoever fetches has to sort the
2011
+ // rest (ADR 0148). `tableInitialized` fires once, after the first render —
2012
+ // no payload, the Form's `formInitialized` for a table.
2013
+ [import_codegen31.ControlType.SECTION_TABLE]: ["sortChange", "tableInitialized"],
2014
+ // Repeated rows emit their Repeat item; static rows emit `undefined`.
2015
+ [import_codegen31.ControlType.SECTION_TABLE_ROW]: ["rowClick"],
2016
+ // The preset picked, and the window it drew as `{from, to}` ISO text — both
2017
+ // members pickable, each a date an ApiOperation's param takes. Fired when the
2018
+ // reader picks a preset or lets go of the navigator, never because an input
2019
+ // moved, so a fetch bound here cannot loop (libs/one GLOSSARY.md
2020
+ // SectionChart, the SectionPagination rule of ADR 0097).
2021
+ [import_codegen31.ControlType.SECTION_CHART]: ["rangeChange", "windowChange"],
2022
+ // Offered under the `link` variant alone — see `outputsOf` below.
2023
+ [import_codegen31.ControlType.TEXT_OUTPUT]: ["clicked"]
2024
+ };
2025
+ var OUTPUT_MAP_FIELDS = [
2026
+ ...import_codegen31.OUTPUT_GROUP_MAPS,
2027
+ "outputCalls",
2028
+ "outputArms"
2029
+ ];
2030
+ var wiredOutputKeys = (control) => [
2031
+ ...new Set(
2032
+ OUTPUT_MAP_FIELDS.flatMap(
2033
+ (field) => Object.keys(control[field] ?? {}).map(import_codegen31.outputArmBaseKey)
2034
+ )
2035
+ )
2036
+ ];
2037
+ var CLEARED_OUTPUT_WIRING = Object.fromEntries(
2038
+ OUTPUT_MAP_FIELDS.map((field) => [field, void 0])
2039
+ );
2040
+
2041
+ // apps/m-one-ui/src/app/pages/design/lib/hand-binding-helper.ts
2042
+ var handControls = (controlMap) => Object.values(controlMap).filter(
2043
+ (control) => control.type === import_codegen32.ControlType.SCREEN && !!control.handRef
2044
+ );
2045
+ var unmountableReason = (handRef, hand) => {
2046
+ const contract = hand.contracts[handRef];
2047
+ if (!contract) {
2048
+ const skipped = hand.skips.find(
2049
+ (skip) => `${skip.slice}/${skip.className}` === handRef
2050
+ );
2051
+ return skipped ? skipped.reason : "gone";
2052
+ }
2053
+ const blockers = (0, import_codegen32.mountBlockers)(contract);
2054
+ return blockers.length ? `required: ${blockers.join(", ")}` : void 0;
2055
+ };
2056
+ var memberOf = (screen, binding) => {
2057
+ if (binding.kind === "input") {
2058
+ const found = screen.inputs?.[binding.inputId];
2059
+ if (!found)
2060
+ return { type: void 0, cardinality: void 0, present: false };
2061
+ return {
2062
+ type: found.dataType.type,
2063
+ cardinality: found.cardinality,
2064
+ present: true
2065
+ };
2066
+ }
2067
+ if (binding.kind === "variable") {
2068
+ const found = screen.variables?.[binding.variableId];
2069
+ if (!found)
2070
+ return { type: void 0, cardinality: void 0, present: false };
2071
+ return {
2072
+ type: found.dataType,
2073
+ cardinality: found.cardinality,
2074
+ present: true
2075
+ };
2076
+ }
2077
+ if (binding.kind === "constant") {
2078
+ const found = screen.constants?.[binding.constantId];
2079
+ if (!found)
2080
+ return { type: void 0, cardinality: void 0, present: false };
2081
+ return { type: found.dataType, cardinality: "one", present: true };
2082
+ }
2083
+ return void 0;
2084
+ };
2085
+ var brokenHandBindings = (control, contract, screen, controlMap, hand) => {
2086
+ const problems = [];
2087
+ const inputs = new Map(contract.inputs.map((one) => [one.name, one]));
2088
+ const outputs = new Map(contract.outputs.map((one) => [one.name, one]));
2089
+ Object.entries(control.screenInputs ?? {}).forEach(([name, binding]) => {
2090
+ const declared = inputs.get(name);
2091
+ if (!declared) {
2092
+ problems.push(name);
2093
+ return;
2094
+ }
2095
+ if (binding.kind === "static") return;
2096
+ if (binding.kind === "output") {
2097
+ const producer = controlMap[binding.controlId];
2098
+ const from = producer?.handRef ? hand.contracts[producer.handRef]?.outputs.find(
2099
+ (one) => one.name === binding.outputId
2100
+ )?.payload : void 0;
2101
+ if (producer?.handRef && !from) problems.push(name);
2102
+ else if (from && (from.type !== declared.type || from.cardinality !== declared.cardinality)) {
2103
+ problems.push(name);
2104
+ }
2105
+ return;
2106
+ }
2107
+ const member = memberOf(screen, binding);
2108
+ if (!member) return;
2109
+ if (!member.present || member.type !== declared.type || member.cardinality !== declared.cardinality) {
2110
+ problems.push(name);
2111
+ }
2112
+ });
2113
+ wiredOutputKeys(control).forEach((name) => {
2114
+ if (!outputs.has(name)) problems.push(name);
2115
+ });
2116
+ return [...new Set(problems)].sort();
2117
+ };
2118
+ var unboundRequiredInputs = (control, contract) => {
2119
+ const bound = control.screenInputs ?? {};
2120
+ return contract.inputs.filter((declared) => declared.required && !bound[declared.name]).map((declared) => declared.name).sort();
2121
+ };
2122
+ var mountedContract = (control, hand) => {
2123
+ const contract = control.handRef ? hand.contracts[control.handRef] : void 0;
2124
+ return contract && (0, import_codegen32.isMountable)(contract) ? contract : void 0;
2125
+ };
2126
+
2127
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-binding-resolves.ts
2128
+ var handBindingResolves = defineInvariant({
2129
+ name: "hand-binding-resolves",
2130
+ message: "invariant-hand-binding-unresolved",
2131
+ severity: "blocking",
2132
+ deps: ["screens", "screenControlMaps", "hand"],
2133
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2134
+ const controlMap = screenControlMaps[screen.id] ?? {};
2135
+ return handControls(controlMap).flatMap((control) => {
2136
+ const contract = mountedContract(control, hand);
2137
+ if (!contract) return [];
2138
+ const broken = brokenHandBindings(
2139
+ control,
2140
+ contract,
2141
+ screen,
2142
+ controlMap,
2143
+ hand
2144
+ );
2145
+ if (!broken.length) return [];
2146
+ return [
2147
+ {
2148
+ subject: `${screen.name} \u2192 ${contract.ref}: ${broken.join(", ")}`,
2149
+ target: {
2150
+ kind: "control",
2151
+ screenId: screen.id,
2152
+ controlId: control.id
2153
+ }
2154
+ }
2155
+ ];
2156
+ });
2157
+ })
2158
+ });
2159
+
2160
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-required-input-bound.ts
2161
+ var handRequiredInputBound = defineInvariant({
2162
+ name: "hand-required-input-bound",
2163
+ message: "invariant-hand-required-input-unbound",
2164
+ severity: "blocking",
2165
+ deps: ["screens", "screenControlMaps", "hand"],
2166
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2167
+ const controlMap = screenControlMaps[screen.id] ?? {};
2168
+ return handControls(controlMap).flatMap((control) => {
2169
+ const contract = mountedContract(control, hand);
2170
+ if (!contract) return [];
2171
+ const missing = unboundRequiredInputs(control, contract);
2172
+ if (!missing.length) return [];
2173
+ return [
2174
+ {
2175
+ subject: `${screen.name} \u2192 ${contract.ref}: ${missing.join(", ")}`,
2176
+ target: {
2177
+ kind: "control",
2178
+ screenId: screen.id,
2179
+ controlId: control.id
2180
+ }
2181
+ }
2182
+ ];
2183
+ });
2184
+ })
2185
+ });
2186
+
2187
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/hand-screen-resolves.ts
2188
+ var handScreenResolves = defineInvariant({
2189
+ name: "hand-screen-resolves",
2190
+ message: "invariant-hand-screen-unresolved",
2191
+ severity: "blocking",
2192
+ deps: ["screens", "screenControlMaps", "hand"],
2193
+ validate: ({ screens, screenControlMaps, hand }) => screens.flatMap((screen) => {
2194
+ const controlMap = screenControlMaps[screen.id] ?? {};
2195
+ return handControls(controlMap).flatMap((control) => {
2196
+ const reason = unmountableReason(control.handRef, hand);
2197
+ if (!reason) return [];
2198
+ return [
2199
+ {
2200
+ subject: `${screen.name} \u2192 ${control.handRef} (${reason})`,
2201
+ target: {
2202
+ kind: "control",
2203
+ screenId: screen.id,
2204
+ controlId: control.id
2205
+ }
2206
+ }
2207
+ ];
2208
+ });
2209
+ })
2210
+ });
2211
+
2212
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/reserved-variant-name-free.ts
2213
+ var import_codegen33 = require("./index.js");
2214
+ var reservedVariantNameFree = defineInvariant({
2215
+ name: "reserved-variant-name-free",
2216
+ message: "invariant-reserved-variant-name",
2217
+ severity: "blocking",
2218
+ deps: ["features", "screens"],
2219
+ validate: ({ features, screens }) => {
2220
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
2221
+ const fromFeatures = Object.values(features).flatMap((feature) => {
2222
+ const held = [
2223
+ ...Object.values(feature.properties).map((property) => property.name),
2224
+ ...Object.values(feature.variants).map((variant) => variant.name)
2225
+ ].filter(import_codegen33.isReservedVariantName);
2226
+ return held.length ? [
2227
+ {
2228
+ subject: `${feature.name}.${held[0]}`,
2229
+ target: {
2230
+ kind: "screen",
2231
+ screenId: featureScreen(feature.id)
2232
+ }
2233
+ }
2234
+ ] : [];
2235
+ });
2236
+ const fromScreens = screens.flatMap((screen) => {
2237
+ const held = [
2238
+ ...Object.values(screen.inputs ?? {}),
2239
+ ...Object.values(screen.outputs ?? {}),
2240
+ ...Object.values(screen.constants ?? {}),
2241
+ ...Object.values(screen.computeds ?? {})
2242
+ ].map((member) => member.name).filter(import_codegen33.isReservedVariantName);
2243
+ return held.length ? [
2244
+ {
2245
+ subject: `${screen.name}.${held[0]}`,
2246
+ target: { kind: "screen", screenId: screen.id }
2247
+ }
2248
+ ] : [];
2249
+ });
2250
+ return [...fromFeatures, ...fromScreens];
2251
+ }
2252
+ });
2253
+
2254
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/feature-name-free.ts
2255
+ var import_codegen34 = require("./index.js");
2256
+ var featureNameFree = defineInvariant({
2257
+ name: "feature-name-free",
2258
+ message: "invariant-feature-name-reserved",
2259
+ severity: "advisory",
2260
+ deps: ["features", "screens"],
2261
+ validate: ({ features, screens }) => Object.values(features).filter((feature) => (0, import_codegen34.isReservedFeatureName)(feature.name)).map((feature) => ({
2262
+ subject: feature.name,
2263
+ target: {
2264
+ kind: "screen",
2265
+ screenId: screens.find((screen) => screen.featureId === feature.id)?.id ?? ""
2266
+ }
2267
+ }))
2268
+ });
2269
+
2270
+ // apps/m-one-ui/src/app/pages/design/lib/compare-register.ts
2271
+ var import_codegen38 = require("./index.js");
2272
+
2273
+ // apps/m-one-ui/src/app/pages/design/lib/code-tree.ts
2274
+ var import_codegen35 = require("./index.js");
2275
+ var CODE_AREA_ROOTS = [
2276
+ ["pages", `${import_codegen35.PAGES_ROOT}/`],
2277
+ ["features", `${import_codegen35.FEATURES_ROOT}/`],
2278
+ ["widgets", `${import_codegen35.WIDGETS_ROOT}/`],
2279
+ ["shared", "src/app/shared/"],
2280
+ ["mag_assets", "mag_assets/"],
2281
+ ["magmonium", ".magmonium/"]
2282
+ ];
2283
+
2284
+ // apps/m-one-ui/src/app/pages/design/lib/function-register.ts
2285
+ var import_codegen36 = require("./index.js");
2286
+ var everyFunction = (appFunctions, features) => [
2287
+ ...(0, import_codegen36.listFunctions)(appFunctions).map((fn) => ({ fn })),
2288
+ ...(0, import_codegen36.listFeatures)(features).flatMap(
2289
+ (feature) => (0, import_codegen36.listFunctions)(feature.functions).map((fn) => ({
2290
+ fn,
2291
+ featureId: feature.id
2292
+ }))
2293
+ )
2294
+ ];
2295
+ var canonical = (value) => {
2296
+ if (Array.isArray(value)) return value.map(canonical);
2297
+ if (!value || typeof value !== "object") return value;
2298
+ return Object.fromEntries(
2299
+ Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, canonical(entry)])
2300
+ );
2301
+ };
2302
+
2303
+ // apps/m-one-ui/src/app/pages/design/lib/shape-register.ts
2304
+ var import_codegen37 = require("./index.js");
2305
+
2306
+ // apps/m-one-ui/src/app/pages/design/lib/compare-register.ts
2307
+ var import_codegen39 = require("./index.js");
2308
+ var everyShape = (features, sharedShapes = {}) => [
2309
+ ...(0, import_codegen38.listShapes)(sharedShapes).map((shape) => ({ shape })),
2310
+ ...(0, import_codegen38.listFeatures)(features).flatMap(
2311
+ (feature) => (0, import_codegen38.listShapes)(feature.shapes).filter((shape) => !(0, import_codegen38.isSharedShapeId)(shape.id)).map((shape) => ({ shape, featureId: feature.id }))
2312
+ )
2313
+ ];
2314
+ var distinctPair = (kind, a, b) => ({ kind, ids: a < b ? [a, b] : [b, a] });
2315
+ var isDistinct = (distinct, kind, a, b) => {
2316
+ const [first, second] = distinctPair(kind, a, b).ids;
2317
+ return distinct.some(
2318
+ (pair) => pair.kind === kind && pair.ids[0] === first && pair.ids[1] === second
2319
+ );
2320
+ };
2321
+ var liveDistinct = (distinct, features, appFunctions, sharedShapes = {}) => {
2322
+ const shapes = new Set(
2323
+ everyShape(features, sharedShapes).map(({ shape }) => shape.id)
2324
+ );
2325
+ const functions = new Set(
2326
+ everyFunction(appFunctions, features).map(({ fn }) => fn.id)
2327
+ );
2328
+ return distinct.filter((pair) => {
2329
+ const live = pair.kind === "shapes" ? shapes : functions;
2330
+ return live.has(pair.ids[0]) && live.has(pair.ids[1]);
2331
+ });
2332
+ };
2333
+ var shapeStructureKey = (shape) => JSON.stringify(
2334
+ canonical(
2335
+ [...shape.keys].sort((a, b) => a.name.localeCompare(b.name)).map((key) => [key.name, key.dataType, key.cardinality])
2336
+ )
2337
+ );
2338
+ var shapeMatchIndex = (all, distinct = []) => {
2339
+ const byStructure = /* @__PURE__ */ new Map();
2340
+ for (const entry of all) {
2341
+ if (!entry.shape.keys.length) continue;
2342
+ const key = shapeStructureKey(entry.shape);
2343
+ byStructure.set(key, [...byStructure.get(key) ?? [], entry]);
2344
+ }
2345
+ const index = /* @__PURE__ */ new Map();
2346
+ for (const group of byStructure.values()) {
2347
+ for (const entry of group) {
2348
+ const matches = group.filter(
2349
+ (other) => other.shape.id !== entry.shape.id && !isDistinct(distinct, "shapes", other.shape.id, entry.shape.id)
2350
+ );
2351
+ if (matches.length) index.set(entry.shape.id, matches);
2352
+ }
2353
+ }
2354
+ return index;
2355
+ };
2356
+
2357
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/shape-match.ts
2358
+ var shapeMatch = defineInvariant({
2359
+ name: "shape-match",
2360
+ message: "invariant-shape-match",
2361
+ severity: "advisory",
2362
+ deps: ["features", "functions", "sharedShapes", "distinct"],
2363
+ validate: ({ features, functions, sharedShapes, distinct }) => {
2364
+ const shapes = everyShape(features, sharedShapes);
2365
+ const index = shapeMatchIndex(
2366
+ shapes,
2367
+ liveDistinct(distinct, features, functions, sharedShapes)
2368
+ );
2369
+ return shapes.filter(({ shape }) => index.has(shape.id)).map(({ shape, featureId }) => ({
2370
+ subject: `${shape.name} \u2261 ${(index.get(shape.id) ?? []).map((match) => match.shape.name).join(", ")}`,
2371
+ target: {
2372
+ kind: "compare",
2373
+ tab: "shapes",
2374
+ item: featureId ? { featureId, id: shape.id } : { id: shape.id }
2375
+ }
2376
+ }));
2377
+ }
2378
+ });
2379
+
2380
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/theme-selection-resolves.ts
2381
+ var themeSelectionResolves = defineInvariant({
2382
+ name: "theme-selection-resolves",
2383
+ message: "invariant-theme-selection-missing",
2384
+ severity: "advisory",
2385
+ deps: ["wcConfig", "themes", "themeCatalog"],
2386
+ validate: ({ wcConfig, themes, themeCatalog }) => {
2387
+ const selected = wcConfig.theme?.trim();
2388
+ if (!selected) return [];
2389
+ if (themes[selected] || themeCatalog.includes(selected)) return [];
2390
+ return [
2391
+ { subject: selected, target: { kind: "panel", panel: "config" } }
2392
+ ];
2393
+ }
2394
+ });
2395
+
2396
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/search-feed-resolves.ts
2397
+ var import_codegen40 = require("./index.js");
2398
+ var searchFeedResolves = defineInvariant({
2399
+ name: "search-feed-resolves",
2400
+ message: "invariant-search-feed-unresolved",
2401
+ severity: "advisory",
2402
+ deps: ["features", "functions"],
2403
+ validate: ({ features, functions }) => Object.values(features).flatMap(
2404
+ (feature) => (0, import_codegen40.storesOf)(feature).flatMap((store) => {
2405
+ const feed = store.searchFeed;
2406
+ if (!feed) return [];
2407
+ const property = store.properties[feed.propertyId];
2408
+ const rows = property?.cardinality === "many" ? property.dataType : void 0;
2409
+ if (feed.functionId) {
2410
+ const fn = feature.functions?.[feed.functionId] ?? functions[feed.functionId];
2411
+ if (fn && (0, import_codegen40.isSearchFeedFunction)(fn, property, feature.shapes) && (0, import_codegen40.searchFeedArgsComplete)(fn, feed.args)) {
2412
+ return [];
2413
+ }
2414
+ } else if (rows && (0, import_codegen40.resolveSearchFeedMember)(feed.title, rows, feature.shapes)) {
2415
+ return [];
2416
+ }
2417
+ return [
2418
+ {
2419
+ subject: property ? `${feature.name} \u2192 ${property.name}` : feature.name,
2420
+ target: {
2421
+ kind: "panel",
2422
+ panel: "store",
2423
+ featureId: feature.id,
2424
+ ...store.owner.kind === "sub" ? { subStoreId: store.owner.subStoreId } : {}
2425
+ }
2426
+ }
2427
+ ];
2428
+ })
2429
+ )
2430
+ });
2431
+
2432
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/search-answer-resolves.ts
2433
+ var import_codegen41 = require("./index.js");
2434
+ var searchAnswerResolves = defineInvariant({
2435
+ name: "search-answer-resolves",
2436
+ message: "invariant-search-answer-unresolved",
2437
+ severity: "advisory",
2438
+ deps: ["navMap", "screens"],
2439
+ validate: ({ navMap, screens }) => {
2440
+ const screenId = (0, import_codegen41.searchAnswerScreenId)(navMap);
2441
+ if (!screenId) return [];
2442
+ const screen = screens.find((s) => s.id === screenId);
2443
+ if (screen && (screen.kind === "app_widget" || screen.kind === "feature")) {
2444
+ return [];
2445
+ }
2446
+ return [
2447
+ {
2448
+ subject: screen?.name ?? screenId,
2449
+ target: { kind: "nav", navId: import_codegen41.SEARCH_NAV_ID }
2450
+ }
2451
+ ];
2452
+ }
2453
+ });
2454
+
2455
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/state-path-resolves.ts
2456
+ var import_codegen42 = require("./index.js");
2457
+ var reachOf = (feature, shared) => ({
2458
+ properties: Object.assign(
2459
+ {},
2460
+ ...(0, import_codegen42.storesOf)(feature).map((store) => store.properties)
2461
+ ),
2462
+ shapes: (0, import_codegen42.shapesInReach)(feature, shared)
2463
+ });
2464
+ function holdsDeadPath(value, reach) {
2465
+ if (Array.isArray(value)) {
2466
+ if (value.length > 1 && value.every((id) => typeof id === "string") && value[0] in reach.properties && !value.slice(1).some((id) => id in reach.properties)) {
2467
+ return !(0, import_codegen42.isPathResolved)(value, reach.properties, reach.shapes);
2468
+ }
2469
+ return value.some((item) => holdsDeadPath(item, reach));
2470
+ }
2471
+ if (value && typeof value === "object") {
2472
+ return Object.values(value).some((item) => holdsDeadPath(item, reach));
2473
+ }
2474
+ return false;
2475
+ }
2476
+ var named = (members) => Object.values(members ?? {}).map((member) => ({
2477
+ id: member.id,
2478
+ name: member.name,
2479
+ value: member
2480
+ }));
2481
+ var statePathResolves = defineInvariant({
2482
+ name: "state-path-resolves",
2483
+ message: "invariant-state-path-unresolved",
2484
+ severity: "blocking",
2485
+ deps: ["features", "screens", "navMap", "sharedShapes"],
2486
+ validate: ({ features, screens, navMap, sharedShapes }) => {
2487
+ const found = [];
2488
+ const reaches = /* @__PURE__ */ new Map();
2489
+ for (const feature of Object.values(features)) {
2490
+ const reach = reachOf(feature, sharedShapes);
2491
+ reaches.set(feature.id, reach);
2492
+ const at = { kind: "panel", panel: "store", featureId: feature.id };
2493
+ for (const variant of named(feature.variants)) {
2494
+ if (holdsDeadPath(variant.value, reach)) {
2495
+ found.push({
2496
+ subject: `${feature.name} \u2192 variant ${variant.name}`,
2497
+ target: { ...at, memberId: variant.id }
2498
+ });
2499
+ }
2500
+ }
2501
+ for (const store of (0, import_codegen42.storesOf)(feature)) {
2502
+ const subStoreId = store.subStore?.id;
2503
+ const owner = subStoreId ? { ...at, subStoreId } : at;
2504
+ const prefix = store.subStore ? `${feature.name} \u2192 ${store.subStore.name}` : feature.name;
2505
+ for (const [word, members] of [
2506
+ ["computed", store.computeds],
2507
+ ["method", store.methods],
2508
+ ["timer", store.timers]
2509
+ ]) {
2510
+ for (const member of named(members)) {
2511
+ if (holdsDeadPath(member.value, reach)) {
2512
+ found.push({
2513
+ subject: `${prefix} \u2192 ${word} ${member.name}`,
2514
+ target: { ...owner, memberId: member.id }
2515
+ });
2516
+ }
2517
+ }
2518
+ }
2519
+ }
2520
+ }
2521
+ for (const screen of screens) {
2522
+ const reach = (0, import_codegen42.isFeatureScreen)(screen) ? reaches.get(screen.featureId) : void 0;
2523
+ if (!reach) continue;
2524
+ const at = { kind: "screen", screenId: screen.id, panel: "screen" };
2525
+ for (const variant of named(screen.variants)) {
2526
+ if (holdsDeadPath(variant.value, reach)) {
2527
+ found.push({
2528
+ subject: `${screen.name} \u2192 variant ${variant.name}`,
2529
+ target: { ...at, memberId: variant.id }
2530
+ });
2531
+ }
2532
+ }
2533
+ for (const computed of named(screen.computeds)) {
2534
+ if (holdsDeadPath(computed.value, reach)) {
2535
+ found.push({
2536
+ subject: `${screen.name} \u2192 computed ${computed.name}`,
2537
+ target: { ...at, computedId: computed.id }
2538
+ });
2539
+ }
2540
+ }
2541
+ }
2542
+ const everywhere = {
2543
+ properties: Object.assign({}, ...[...reaches.values()].map((r) => r.properties)),
2544
+ shapes: Object.assign({}, ...[...reaches.values()].map((r) => r.shapes))
2545
+ };
2546
+ for (const nav of Object.values(navMap)) {
2547
+ if (holdsDeadPath(nav, everywhere)) {
2548
+ found.push({
2549
+ subject: `nav ${nav.label ?? nav.navId}`,
2550
+ target: { kind: "nav", navId: nav.navId }
2551
+ });
2552
+ }
2553
+ }
2554
+ return found;
2555
+ }
2556
+ });
2557
+
2558
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/rule-operand-fits.ts
2559
+ var import_codegen43 = require("./index.js");
2560
+ var unfit = (check, properties, shapes) => {
2561
+ const error = (0, import_codegen43.checkError)(check, properties, shapes);
2562
+ if (error === "rule-path-missing") return false;
2563
+ if (error === "rule-operator-invalid" || error === "rule-path-not-leaf" || error === "rule-operand-missing" && check.operand.kind === "path") {
2564
+ return true;
2565
+ }
2566
+ if ((0, import_codegen43.isUnaryOperator)(check.operator) || check.operand.kind !== "literal") {
2567
+ return false;
2568
+ }
2569
+ const segments = (0, import_codegen43.resolvePath)(check.path, properties, shapes);
2570
+ if (!check.count && (0, import_codegen43.pathLeafEnumId)(segments)) return false;
2571
+ const type = (0, import_codegen43.operandType)((0, import_codegen43.pathLeafType)(segments), !!check.count);
2572
+ if (!type) return false;
2573
+ return (0, import_codegen43.validateLiteral)(String(check.operand.value), { type }, "one") === "value-type-mismatch";
2574
+ };
2575
+ var ruleOperandFits = defineInvariant({
2576
+ name: "rule-operand-fits",
2577
+ message: "invariant-rule-operand-unfit",
2578
+ severity: "blocking",
2579
+ deps: ["features", "sharedShapes"],
2580
+ validate: ({ features, sharedShapes }) => {
2581
+ const found = [];
2582
+ for (const feature of Object.values(features)) {
2583
+ const properties = Object.assign(
2584
+ {},
2585
+ ...(0, import_codegen43.storesOf)(feature).map((store) => store.properties)
2586
+ );
2587
+ const shapes = (0, import_codegen43.shapesInReach)(feature, sharedShapes);
2588
+ for (const variant of Object.values(feature.variants ?? {})) {
2589
+ if ((0, import_codegen43.ruleChecks)(variant.rule).some(
2590
+ (check) => unfit(check, properties, shapes)
2591
+ )) {
2592
+ found.push({
2593
+ subject: `${feature.name} \u2192 variant ${variant.name}`,
2594
+ target: {
2595
+ kind: "panel",
2596
+ panel: "store",
2597
+ featureId: feature.id,
2598
+ memberId: variant.id
2599
+ }
2600
+ });
2601
+ }
2602
+ }
2603
+ }
2604
+ return found;
2605
+ }
2606
+ });
2607
+
2608
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/timer-complete.ts
2609
+ var import_codegen44 = require("./index.js");
2610
+ var timerComplete = defineInvariant({
2611
+ name: "timer-complete",
2612
+ message: "invariant-timer-incomplete",
2613
+ severity: "blocking",
2614
+ deps: ["features", "screens"],
2615
+ validate: ({ features, screens }) => {
2616
+ const featureScreen = (featureId) => screens.find((screen) => screen.featureId === featureId)?.id ?? "";
2617
+ return Object.values(features).flatMap(
2618
+ (feature) => Object.values(feature.timers ?? {}).filter((timer) => (0, import_codegen44.timerError)(timer)).map((timer) => ({
2619
+ subject: `${feature.name}.${timer.name}`,
2620
+ target: {
2621
+ kind: "screen",
2622
+ screenId: featureScreen(feature.id)
2623
+ }
2624
+ }))
2625
+ );
2626
+ }
2627
+ });
2628
+
2629
+ // apps/m-one-ui/src/app/pages/design/lib/invariants/variant-gate-satisfiable.ts
2630
+ var import_codegen45 = require("./index.js");
2631
+ var ATOM_CAP2 = 12;
2632
+ var foldText2 = (entries, names) => entries.map((entry, index) => {
2633
+ const name = names.get(entry.id) ?? entry.id;
2634
+ const term = (0, import_codegen45.variantJoinIsNot)(entry.join) ? `!${name}` : name;
2635
+ if (index === 0) return term;
2636
+ return `${(0, import_codegen45.variantJoinIsAnd)(entry.join) ? "&&" : "||"} ${term}`;
2637
+ }).join(" ");
2638
+ var variantNames2 = (features, screens, currentScreenId) => {
2639
+ const screen = screens.find((one) => one.id === currentScreenId);
2640
+ const feature = screen?.featureId ? features[screen.featureId] : void 0;
2641
+ const names = /* @__PURE__ */ new Map([
2642
+ [import_codegen45.ELSE_VARIANT_ID, import_codegen45.ELSE_VARIANT_NAME],
2643
+ [import_codegen45.BUSY_VARIANT_ID, import_codegen45.BUSY_VARIANT_NAME]
2644
+ ]);
2645
+ Object.values(feature?.variants ?? {}).forEach(
2646
+ (variant) => names.set(variant.id, variant.name)
2647
+ );
2648
+ return names;
2649
+ };
2650
+ var satisfiable = (gates) => {
2651
+ const atoms = [
2652
+ ...new Set(
2653
+ gates.flat().map((entry) => entry.id).filter((id) => !(0, import_codegen45.isReservedVariantId)(id))
2654
+ )
2655
+ ];
2656
+ if (atoms.length > ATOM_CAP2) return true;
2657
+ const rows = 1 << atoms.length;
2658
+ for (let row = 0; row < rows; row++) {
2659
+ const on = atoms.filter((_, index) => row & 1 << index);
2660
+ const base = on.length ? on : [...on, import_codegen45.ELSE_VARIANT_ID];
2661
+ for (const withBusy of [base, [...base, import_codegen45.BUSY_VARIANT_ID]]) {
2662
+ if (gates.every((gate) => (0, import_codegen45.evaluateVariantGate)(gate, withBusy))) {
2663
+ return true;
2664
+ }
2665
+ }
2666
+ }
2667
+ return false;
2668
+ };
2669
+ var variantGateSatisfiable = defineInvariant({
2670
+ name: "variant-gate-satisfiable",
2671
+ message: "invariant-variant-gate-unsatisfiable",
2672
+ severity: "advisory",
2673
+ // Every Screen, each judged again only when its own Controls move (ADR 0192).
2674
+ deps: ["screenControlMaps", "features", "screens"],
2675
+ validate: ({ screenControlMaps, features, screens }) => unsatisfiableGates(screens, screenControlMaps, { features, screens })
2676
+ });
2677
+ var unsatisfiableGates = perScreen(
2678
+ (controlMap, screen, { features, screens }) => {
2679
+ const names = variantNames2(features, screens, screen.id);
2680
+ return Object.entries(controlMap).flatMap(([controlId, control]) => {
2681
+ const own = (0, import_codegen45.controlVariants)(control);
2682
+ if (!own.length) return [];
2683
+ const above = (0, import_codegen45.enclosingGates)(controlId, controlMap);
2684
+ if (above === null) return [];
2685
+ const gates = [own, ...above];
2686
+ if (satisfiable(gates)) return [];
2687
+ return [
2688
+ {
2689
+ // Its own guard, then what encloses it, innermost first — the two
2690
+ // halves that cannot hold together.
2691
+ subject: `${foldText2(own, names)} \u2014 ${gates.slice(1).map((gate) => foldText2(gate, names)).join(" & ")}`,
2692
+ target: {
2693
+ kind: "control",
2694
+ screenId: screen.id,
2695
+ controlId
2696
+ }
2697
+ }
2698
+ ];
2699
+ });
2700
+ }
2701
+ );
2702
+
2703
+ // apps/m-one-ui/src/app/pages/design/lib/invariant-catalog.ts
2704
+ var INVARIANTS = [
2705
+ appScaffoldComplete,
2706
+ backendUrlDeclared,
2707
+ bindingResolves,
2708
+ branchArmReachable,
2709
+ computedArgsBound,
2710
+ computedArgsTyped,
2711
+ oneFunctionArgMismatch,
2712
+ oneFunctionRequiredParam,
2713
+ confirmUnattendedCall,
2714
+ outcomeUnattendedCall,
2715
+ outcomeCallNested,
2716
+ reactionWritesOwnWatch,
2717
+ closeOverlayOffOverlay,
2718
+ outcomeNavComplete,
2719
+ dynamicNavInputDeclared,
2720
+ navTailInputDeclared,
2721
+ navTailChildless,
2722
+ navVariantOnChain,
2723
+ computedNavOnChain,
2724
+ computedOneFunctionKnown,
2725
+ remoteTailSingle,
2726
+ remoteTailRouted,
2727
+ remoteNameUnique,
2728
+ remoteMountPatternValid,
2729
+ remoteMountMatchesRoute,
2730
+ fieldCheckBound,
2731
+ filterGroupSqueezeOrphan,
2732
+ contextGroupPrimaryUnique,
2733
+ functionCaseArgs,
2734
+ handBindingResolves,
2735
+ handRequiredInputBound,
2736
+ handScreenResolves,
2737
+ landingPageBound,
2738
+ navVisibilityResolvable,
2739
+ methodVariantNoLanding,
2740
+ methodVariantUnused,
2741
+ overlayBodyBound,
2742
+ pageInputRoutable,
2743
+ reservedVariantNameFree,
2744
+ featureNameFree,
2745
+ screenControlReachable,
2746
+ screenInputBound,
2747
+ searchFeedResolves,
2748
+ searchAnswerResolves,
2749
+ shapeMatch,
2750
+ statePathResolves,
2751
+ ruleOperandFits,
2752
+ themeSelectionResolves,
2753
+ timerComplete,
2754
+ variantGateSatisfiable
2755
+ ];
2756
+ var runInvariants = (scope) => INVARIANTS.flatMap((invariant) => invariant.run(scope));
2757
+ var invariantScopeOf = (source, themeCatalog) => ({
2758
+ appTarget: source.appTarget,
2759
+ wcConfig: source.wcConfig,
2760
+ features: (0, import_codegen46.featuresAsRead)(
2761
+ source.features,
2762
+ source.sharedShapes,
2763
+ source.screens.map(({ meta, state }) => ({
2764
+ ...(0, import_codegen46.isFeatureScreen)(meta) ? { featureId: meta.featureId } : {},
2765
+ controlMap: state.controlMap
2766
+ }))
2767
+ ),
2768
+ screens: source.screens.map(({ meta }) => meta),
2769
+ navMap: source.navMap,
2770
+ controlMap: {},
2771
+ screenControlMaps: Object.fromEntries(
2772
+ source.screens.map(({ meta, state }) => [meta.id, state.controlMap])
2773
+ ),
2774
+ functions: source.functions,
2775
+ distinct: source.distinct,
2776
+ sharedShapes: source.sharedShapes,
2777
+ enums: source.enums,
2778
+ themes: source.themes,
2779
+ themeCatalog: [...themeCatalog],
2780
+ hand: source.hand,
2781
+ currentScreenId: void 0
2782
+ });
2783
+ // Annotate the CommonJS export names for ESM import in node:
2784
+ 0 && (module.exports = {
2785
+ INVARIANTS,
2786
+ invariantScopeOf,
2787
+ runInvariants
2788
+ });