@magmonium/cli 0.8.30 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1548 @@
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 = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, 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/inspect-catalog.ts
21
+ var inspect_catalog_exports = {};
22
+ __export(inspect_catalog_exports, {
23
+ INSPECTIONS: () => INSPECTIONS,
24
+ inspectionByName: () => inspectionByName,
25
+ runInspection: () => runInspection
26
+ });
27
+ module.exports = __toCommonJS(inspect_catalog_exports);
28
+ var import_codegen12 = require("./index.js");
29
+
30
+ // apps/m-one-ui/src/app/pages/design/lib/api-holders.ts
31
+ var import_codegen = require("./index.js");
32
+ var apiHolders = (features, sharedShapes, verb, path) => {
33
+ const atOperation = (shape) => shape.origin?.verb === verb && shape.origin.path === path;
34
+ const groups = [
35
+ { id: import_codegen.SHARED_SHAPES, name: import_codegen.SHARED_SHAPES, shapes: sharedShapes },
36
+ ...(0, import_codegen.listFeatures)(features)
37
+ ];
38
+ const shapes = groups.flatMap(
39
+ (group) => (0, import_codegen.listShapes)(group.shapes).filter(atOperation).map((shape) => ({
40
+ kind: "shape",
41
+ featureId: group.id,
42
+ featureName: group.name,
43
+ id: shape.id,
44
+ name: shape.name
45
+ }))
46
+ );
47
+ const methods = (0, import_codegen.listFeatures)(features).flatMap(
48
+ (feature) => Object.values(feature.methods).filter(
49
+ (method) => !(0, import_codegen.isStorageMethod)(method) && !(0, import_codegen.isCacheMethod)(method) && method.verb === verb && method.path === path
50
+ ).map((method) => ({
51
+ kind: "method",
52
+ featureId: feature.id,
53
+ featureName: feature.name,
54
+ id: method.id,
55
+ name: method.name
56
+ }))
57
+ );
58
+ return [...shapes, ...methods];
59
+ };
60
+
61
+ // apps/m-one-ui/src/app/pages/design/lib/app-repo-change.ts
62
+ var import_codegen3 = require("./index.js");
63
+
64
+ // apps/m-one-ui/src/app/pages/design/lib/ai-translation.ts
65
+ var import_codegen2 = require("./index.js");
66
+ var SYSTEM_PROMPT = [
67
+ "You translate one user-interface message into many languages.",
68
+ "Reply with ONE JSON object and nothing else: keys are the language codes you are given, values are the translation.",
69
+ "Keep every <$name> variable and every markup tag exactly as written in the source \u2014 never translate or rename them.",
70
+ "Keep the tone short and suitable for a button, label or message in an app."
71
+ ].join("\n");
72
+
73
+ // apps/m-one-ui/src/app/pages/design/lib/app-repo-change.ts
74
+ var PIN_FIELDS = {
75
+ codegen: "@magmonium/cli",
76
+ one: "@magmonium/one"
77
+ };
78
+ var parseIndex = (files) => {
79
+ try {
80
+ const index = JSON.parse(files[import_codegen3.DESIGN_INDEX_PATH] ?? "{}");
81
+ return index && typeof index === "object" ? index : {};
82
+ } catch {
83
+ return {};
84
+ }
85
+ };
86
+ function packagesOf(files) {
87
+ const index = parseIndex(files);
88
+ const pins = {};
89
+ for (const [field, name] of Object.entries(PIN_FIELDS)) {
90
+ const version = index[field];
91
+ if (typeof version === "string" && version) pins[name] = version;
92
+ }
93
+ return pins;
94
+ }
95
+ var indexDigest = (contents) => {
96
+ try {
97
+ const index = JSON.parse(contents);
98
+ const unpinned = Object.fromEntries(
99
+ Object.entries(index).filter(([key]) => !(key in PIN_FIELDS))
100
+ );
101
+ return (0, import_codegen3.fnv64)(JSON.stringify(unpinned));
102
+ } catch {
103
+ return (0, import_codegen3.fnv64)(contents);
104
+ }
105
+ };
106
+ var bumpedPackages = (before, now) => before ? Object.entries(now).filter(([name, version]) => before[name] && before[name] !== version).map(([name, version]) => `${name} ${version}`) : [];
107
+ var IGNORED = /\/(write-id|emitted\.json|hand\.json|operations\.json)$/;
108
+ var screenPath = (id) => `${import_codegen3.DESIGN_SCREENS_DIR}/${id}.json`;
109
+ function screenLabels(files) {
110
+ const labels = {};
111
+ let index;
112
+ try {
113
+ index = JSON.parse(files[import_codegen3.DESIGN_INDEX_PATH] ?? "{}");
114
+ } catch {
115
+ return labels;
116
+ }
117
+ for (const meta of index.screens ?? []) {
118
+ const feature = meta.featureId ? index.features?.[meta.featureId]?.name : void 0;
119
+ labels[meta.id] = feature ? { name: meta.name, feature } : { name: meta.name };
120
+ }
121
+ return labels;
122
+ }
123
+ function designBaseline(files, packages = packagesOf(files)) {
124
+ const digests = {};
125
+ for (const [path, contents] of Object.entries(files)) {
126
+ if (IGNORED.test(path)) continue;
127
+ digests[path] = path === import_codegen3.DESIGN_INDEX_PATH ? indexDigest(contents) : (0, import_codegen3.fnv64)(contents);
128
+ }
129
+ return { digests, screens: screenLabels(files), packages };
130
+ }
131
+ function designChange(base, files) {
132
+ const now = designBaseline(files);
133
+ const before = base ?? { digests: {}, screens: {} };
134
+ const change2 = {
135
+ added: [],
136
+ removed: [],
137
+ changed: [],
138
+ other: []
139
+ };
140
+ for (const [id, label] of Object.entries(now.screens)) {
141
+ if (!before.screens[id]) change2.added.push(label);
142
+ else if (now.digests[screenPath(id)] !== before.digests[screenPath(id)]) {
143
+ change2.changed.push(label);
144
+ }
145
+ }
146
+ for (const [id, label] of Object.entries(before.screens)) {
147
+ if (!now.screens[id]) change2.removed.push(label);
148
+ }
149
+ const other = /* @__PURE__ */ new Set();
150
+ const paths = /* @__PURE__ */ new Set([
151
+ ...Object.keys(now.digests),
152
+ ...Object.keys(before.digests)
153
+ ]);
154
+ for (const path of paths) {
155
+ if (path.startsWith(`${import_codegen3.DESIGN_SCREENS_DIR}/`)) continue;
156
+ if (now.digests[path] === before.digests[path]) continue;
157
+ if (path === import_codegen3.DESIGN_NAV_PATH) other.add("nav");
158
+ else if (path.startsWith(`${import_codegen3.DESIGN_ASSETS_DIR}/`)) {
159
+ other.add(
160
+ path.slice(import_codegen3.DESIGN_ASSETS_DIR.length + 1).replace(/\.json$/, "")
161
+ );
162
+ } else if (path === import_codegen3.DESIGN_INDEX_PATH) {
163
+ if (!change2.added.length && !change2.removed.length) other.add("app");
164
+ }
165
+ }
166
+ bumpedPackages(before.packages, now.packages ?? {}).forEach(
167
+ (row2) => other.add(row2)
168
+ );
169
+ change2.other = [...other].sort();
170
+ return change2;
171
+ }
172
+ var SYSTEM_PROMPT2 = [
173
+ "You write one git commit message for a change to an app design.",
174
+ "Reply with ONE line and nothing else, in the form: type(scope): few words",
175
+ "type is one of feat, fix, refactor, style, chore. Use the scope you are given exactly.",
176
+ "The words after the colon are lowercase, minimal, at most eight words, no trailing period."
177
+ ].join("\n");
178
+
179
+ // apps/m-one-ui/src/app/pages/design/lib/function-holders.ts
180
+ var import_codegen4 = require("./index.js");
181
+ function mentionsFunction(value, functionId) {
182
+ if (Array.isArray(value)) {
183
+ return value.some((entry) => mentionsFunction(entry, functionId));
184
+ }
185
+ if (!value || typeof value !== "object") return false;
186
+ const record = value;
187
+ if (record["functionId"] === functionId) return true;
188
+ return Object.values(record).some(
189
+ (entry) => mentionsFunction(entry, functionId)
190
+ );
191
+ }
192
+ var without = (value, keys) => Object.fromEntries(
193
+ Object.entries(value).filter(([key]) => !keys.includes(key))
194
+ );
195
+ var membersNaming = (map, functionId) => Object.values(map ?? {}).filter((member) => mentionsFunction(member, functionId)).sort((a, b) => a.name.localeCompare(b.name));
196
+ function functionHolders(functionId, scope) {
197
+ const holders = [];
198
+ for (const feature of Object.values(scope.features)) {
199
+ const at = { where: feature.name, featureId: feature.id };
200
+ const stores = [
201
+ { subStoreId: void 0, store: feature },
202
+ ...Object.values(feature.subStores ?? {}).map((store) => ({
203
+ subStoreId: store.id,
204
+ store
205
+ }))
206
+ ];
207
+ for (const { subStoreId, store } of stores) {
208
+ const on = subStoreId ? { ...at, subStoreId } : at;
209
+ membersNaming(store.computeds, functionId).forEach(
210
+ (member) => holders.push({ kind: "state-computed", name: member.name, ...on })
211
+ );
212
+ membersNaming(store.methods, functionId).forEach(
213
+ (member) => holders.push({ kind: "store-method", name: member.name, ...on })
214
+ );
215
+ }
216
+ const rest = without(feature, [
217
+ "functions",
218
+ "shapes",
219
+ "computeds",
220
+ "methods",
221
+ "subStores"
222
+ ]);
223
+ const restOfSubStores = Object.values(feature.subStores ?? {}).map(
224
+ (store) => without(store, ["computeds", "methods"])
225
+ );
226
+ if (mentionsFunction([rest, restOfSubStores], functionId)) {
227
+ holders.push({ kind: "feature", name: feature.name, ...at });
228
+ }
229
+ }
230
+ const screenById = new Map(
231
+ scope.screens.map((screen) => [screen.id, screen])
232
+ );
233
+ for (const screen of scope.screens) {
234
+ const at = {
235
+ where: screen.name,
236
+ screenId: screen.id,
237
+ ...screen.featureId ? { featureId: screen.featureId } : {}
238
+ };
239
+ membersNaming(screen.computeds, functionId).forEach(
240
+ (member) => holders.push({ kind: "screen-computed", name: member.name, ...at })
241
+ );
242
+ membersNaming(screen.methods, functionId).forEach(
243
+ (member) => holders.push({ kind: "screen-method", name: member.name, ...at })
244
+ );
245
+ if (mentionsFunction(without(screen, ["computeds", "methods"]), functionId)) {
246
+ holders.push({ kind: "screen", name: screen.name, ...at });
247
+ }
248
+ }
249
+ for (const { screenId, controlMap } of scope.controlMaps) {
250
+ const screen = screenById.get(screenId);
251
+ if (!screen) continue;
252
+ for (const [controlId, control] of Object.entries(controlMap)) {
253
+ if (!mentionsFunction(control, functionId)) continue;
254
+ const checks = (0, import_codegen4.fieldChecks)(control).some(
255
+ (check) => check.functionId === functionId
256
+ );
257
+ holders.push({
258
+ kind: checks ? "field-check" : "control",
259
+ name: (0, import_codegen4.resolveFieldName)({ id: controlId, configs: control.configs }),
260
+ where: screen.name,
261
+ screenId,
262
+ controlId,
263
+ ...screen.featureId ? { featureId: screen.featureId } : {}
264
+ });
265
+ }
266
+ }
267
+ for (const nav of Object.values(scope.navMap)) {
268
+ const at = { name: nav.navId, where: nav.navId, navId: nav.navId };
269
+ const visibility = nav.visibilitySource;
270
+ const instance = nav.instanceSource;
271
+ if (visibility && mentionsFunction(visibility, functionId)) {
272
+ holders.push({
273
+ kind: "nav-visibility",
274
+ ...at,
275
+ ...visibility.featureId ? { featureId: visibility.featureId } : {}
276
+ });
277
+ }
278
+ if (instance && mentionsFunction(instance, functionId)) {
279
+ holders.push({
280
+ kind: "nav-instance",
281
+ ...at,
282
+ ...instance.featureId ? { featureId: instance.featureId } : {}
283
+ });
284
+ }
285
+ const rest = without(nav, ["visibilitySource", "instanceSource"]);
286
+ if (mentionsFunction(rest, functionId)) {
287
+ holders.push({ kind: "nav", ...at });
288
+ }
289
+ }
290
+ return holders;
291
+ }
292
+
293
+ // apps/m-one-ui/src/app/pages/design/lib/member-usage.ts
294
+ var import_codegen7 = require("./index.js");
295
+
296
+ // apps/m-one-ui/src/app/pages/design/lib/control-outputs.ts
297
+ var import_codegen5 = require("./index.js");
298
+ var embeddedOutputsOf = (screens, contractOf = () => void 0) => (control) => {
299
+ if (control.type !== import_codegen5.ControlType.SCREEN) return void 0;
300
+ if (control.handRef) {
301
+ const contract = contractOf(control.handRef);
302
+ return contract ? (0, import_codegen5.handTargetOf)(contract).outputs : void 0;
303
+ }
304
+ return screens.find((screen) => screen.id === control.screenId)?.outputs;
305
+ };
306
+ var embeddedOutputOf = (control, key, embedded) => embedded?.(control)?.[(0, import_codegen5.outputArmBaseKey)(key)];
307
+ var outputCallLabelOf = (control, key, embedded) => {
308
+ const label = (0, import_codegen5.outputCallLabel)(control, key);
309
+ const name = embeddedOutputOf(control, key, embedded)?.name;
310
+ const base = (0, import_codegen5.outputArmBaseKey)(key);
311
+ return name && label.startsWith(base) ? `${name}${label.slice(base.length)}` : label;
312
+ };
313
+ var CONTROL_OUTPUTS = {
314
+ [import_codegen5.ControlType.BUTTON]: ["clicked"],
315
+ [import_codegen5.ControlType.CONTEXT_MENU]: ["action"],
316
+ // The picker's own value, once the User has moved it — the write half of the
317
+ // controlled binding, drawn as a StateWrite rather than as `[(audience)]`
318
+ // (ADR 0187, ADR 0065). Offered whatever the two halves hold: a picker bound
319
+ // to no `audience` still edits its own value and still fires this.
320
+ [import_codegen5.ControlType.AUDIENCE_PICKER]: ["audienceChange"],
321
+ [import_codegen5.ControlType.CARD]: ["clicked"],
322
+ // `submitted` is offered only under a Button declaring `isSubmit` — see
323
+ // `outputsOf` below.
324
+ [import_codegen5.ControlType.FORM]: ["submitted", "dataChange", "formInitialized"],
325
+ // The Field's own `dataChange`, at field granularity — the value the User
326
+ // typed into this one field, not the form's record (libs/one ADR 0032).
327
+ // Needs no Button, the way the form's does not (see `outputsOf`).
328
+ [import_codegen5.ControlType.FIELD]: ["dataChange"],
329
+ [import_codegen5.ControlType.SECTION]: ["inView"],
330
+ [import_codegen5.ControlType.SECTION_HEADER]: ["actionClick", "action", "back"],
331
+ // Debounced already by the component — what arrives here is the term the User
332
+ // stopped typing, which is the only thing worth binding a call to.
333
+ [import_codegen5.ControlType.SECTION_SEARCH]: ["searchChange"],
334
+ // One output for the whole bar, carrying the Button that was pressed — an
335
+ // `m-action` names its Buttons rather than holding them, so there is no
336
+ // per-Button Control for a binding to sit on (ADR 0009).
337
+ [import_codegen5.ControlType.SECTION_ACTION]: ["clicked"],
338
+ // Which slide is showing, every time it changes — by drag, by indicator, or
339
+ // by the clock. Two spellings of the one event, because what a caller binds
340
+ // differs: `slideChange` carries the position, `itemChange` the row behind it,
341
+ // which is what a call needing the slide's own data takes.
342
+ [import_codegen5.ControlType.SECTION_CAROUSEL]: ["slideChange", "itemChange"],
343
+ // The whole group's selection, every time any Filter beneath it changes
344
+ // (libs/one ADR 0025). Per-change rather than on-close: a group has no single
345
+ // close event full-width, and `switchMap` in the emitted store already drops
346
+ // the responses of calls a later change supersedes.
347
+ [import_codegen5.ControlType.SECTION_FILTER_GROUP]: ["filterChange"],
348
+ // Offered only outside a group — see `outputsOf` below.
349
+ [import_codegen5.ControlType.SECTION_FILTER]: ["filterChange"],
350
+ // One payload, `{offset, perPage}`, and both members are pickable — a
351
+ // CallArgMapping reading `event.offset` gets a number, which is what an
352
+ // ApiOperation's query param takes. The whole `$event` works too, unlike a
353
+ // FilterGroup's list of pairs (ADR 0097).
354
+ [import_codegen5.ControlType.SECTION_PAGINATION]: ["paginationChange"],
355
+ // `{id, direction}`, after the rows were reordered in place — bound when the
356
+ // table holds one page of a longer list and whoever fetches has to sort the
357
+ // rest (ADR 0148). `tableInitialized` fires once, after the first render —
358
+ // no payload, the Form's `formInitialized` for a table.
359
+ [import_codegen5.ControlType.SECTION_TABLE]: ["sortChange", "tableInitialized"],
360
+ // Repeated rows emit their Repeat item; static rows emit `undefined`.
361
+ [import_codegen5.ControlType.SECTION_TABLE_ROW]: ["rowClick"],
362
+ // The preset picked, and the window it drew as `{from, to}` ISO text — both
363
+ // members pickable, each a date an ApiOperation's param takes. Fired when the
364
+ // reader picks a preset or lets go of the navigator, never because an input
365
+ // moved, so a fetch bound here cannot loop (libs/one GLOSSARY.md
366
+ // SectionChart, the SectionPagination rule of ADR 0097).
367
+ [import_codegen5.ControlType.SECTION_CHART]: ["rangeChange", "windowChange"],
368
+ // Offered under the `link` variant alone — see `outputsOf` below.
369
+ [import_codegen5.ControlType.TEXT_OUTPUT]: ["clicked"]
370
+ };
371
+ var OUTPUT_MAP_FIELDS = [
372
+ ...import_codegen5.OUTPUT_GROUP_MAPS,
373
+ "outputCalls",
374
+ "outputArms"
375
+ ];
376
+ var CLEARED_OUTPUT_WIRING = Object.fromEntries(
377
+ OUTPUT_MAP_FIELDS.map((field) => [field, void 0])
378
+ );
379
+
380
+ // apps/m-one-ui/src/app/pages/design/lib/screen-option-helper.ts
381
+ var import_codegen6 = require("./index.js");
382
+ var screenOptionLabel = (screen, features) => screen.kind === "feature" ? `${features[screen.featureId ?? ""]?.name ?? "?"}/${screen.name}` : screen.name;
383
+
384
+ // apps/m-one-ui/src/app/pages/design/lib/member-usage.ts
385
+ var controlLabel = (control) => {
386
+ const name = String(control.configs?.["name"] ?? "").trim();
387
+ return name || control.type;
388
+ };
389
+ var pathSpeller = (feature, functions) => {
390
+ const stores = (0, import_codegen7.storesOf)(feature);
391
+ const roots = (0, import_codegen7.propertiesWithComputeds)(
392
+ Object.assign({}, ...stores.map((store) => store.properties)),
393
+ Object.assign({}, ...stores.map((store) => store.computeds)),
394
+ functions
395
+ );
396
+ return (path) => path?.length ? (0, import_codegen7.pathDisplay)((0, import_codegen7.resolvePath)(path, roots, feature.shapes)) : "";
397
+ };
398
+ var ownerName = (feature, owner) => {
399
+ if (owner.kind === "main") return "";
400
+ const subStore = feature.subStores?.[owner.subStoreId];
401
+ return subStore ? (0, import_codegen7.subStoreFullName)(feature.name, subStore.name) : "";
402
+ };
403
+ var computedParamText = (reader, feature, functions) => {
404
+ if (reader.kind !== "computed-input" || typeof reader.paramKey !== "string") {
405
+ return void 0;
406
+ }
407
+ const store = (0, import_codegen7.storesOf)(feature).find(
408
+ (candidate) => (0, import_codegen7.sameOwner)(candidate.owner, reader.owner)
409
+ );
410
+ const computed = Object.values(store?.computeds ?? {}).find(
411
+ (candidate) => candidate.name === reader.label
412
+ );
413
+ const fn = computed ? (0, import_codegen7.stateComputedFunction)(computed, functions) : void 0;
414
+ const param = fn?.params.find(
415
+ (candidate) => candidate.id === reader.paramKey
416
+ );
417
+ if (!param) return void 0;
418
+ const type = (0, import_codegen7.tsTypeExpression)(
419
+ feature.shapes,
420
+ param.dataType,
421
+ param.cardinality
422
+ );
423
+ return `${param.name}: ${type}`;
424
+ };
425
+ var declaredArgs = (feature, methodId) => {
426
+ const method = (0, import_codegen7.storesOf)(feature).map((store) => store.methods[methodId]).find(Boolean);
427
+ const names = method ? (0, import_codegen7.authoredArgs)(method).map((arg) => arg.name) : [];
428
+ return names.length ? names.join(", ") : void 0;
429
+ };
430
+ var callColumns = (feature, methodId, args, spell) => {
431
+ const needs = declaredArgs(feature, methodId);
432
+ const passed = args.map((row2) => callArgText(row2, spell)).filter(Boolean);
433
+ return {
434
+ ...needs ? { needs } : {},
435
+ ...passed.length ? { passed: passed.join(", ") } : {}
436
+ };
437
+ };
438
+ var STORE_CALL_KINDS = /* @__PURE__ */ new Set([
439
+ "hook-call",
440
+ "timer-call",
441
+ "cache-fallthrough"
442
+ ]);
443
+ var storeRows = (scope, memberId, functions, spell) => (0, import_codegen7.storeReaders)(scope.feature).filter((reader) => reader.memberId === memberId).map((reader) => {
444
+ const store = ownerName(scope.feature, reader.owner);
445
+ const needs = computedParamText(reader, scope.feature, functions) ?? reader.slot ?? (STORE_CALL_KINDS.has(reader.kind) ? declaredArgs(scope.feature, memberId) : void 0);
446
+ const passed = reader.kind === "state-write" ? "" : spell(reader.path);
447
+ return {
448
+ kind: reader.kind,
449
+ where: store ? `${store} \xB7 ${reader.label}` : reader.label,
450
+ ...needs ? { needs } : {},
451
+ ...passed ? { passed } : {}
452
+ };
453
+ });
454
+ var screenRows = (scope, memberId, spell) => {
455
+ const rows = [];
456
+ const embedded = embeddedOutputsOf(scope.screens.map(({ meta }) => meta));
457
+ scope.screens.forEach(({ meta, state }) => {
458
+ const screenName = screenOptionLabel(meta, scope.features);
459
+ const map = state.controlMap;
460
+ (meta.autoCalls ?? []).filter((call) => call.methodId === memberId).forEach((call) => {
461
+ rows.push({
462
+ kind: "auto-call",
463
+ // What fires it, which is the whole of what the row has to say: a
464
+ // ScreenAutoCall carries no name of its own.
465
+ where: `${screenName} \xB7 ${(0, import_codegen7.screenAutoCallWhen)(call)}`,
466
+ screenId: meta.id,
467
+ ...callColumns(scope.feature, memberId, call.args, spell)
468
+ });
469
+ });
470
+ Object.values(meta.methods ?? {}).forEach(
471
+ (method) => (0, import_codegen7.screenMethodCalls)(method).filter((one) => one.methodId === memberId).forEach((one) => {
472
+ rows.push({
473
+ kind: "screen-method",
474
+ where: `${screenName} \xB7 ${method.name}`,
475
+ screenId: meta.id,
476
+ ...callColumns(scope.feature, memberId, one.args ?? [], spell)
477
+ });
478
+ })
479
+ );
480
+ Object.values(map).forEach((control) => {
481
+ const at = (tail) => `${screenName} \xB7 ${controlLabel(control)} \xB7 ${tail}`;
482
+ Object.entries(control.bindings ?? {}).forEach(([slot, binding]) => {
483
+ const root = binding.root;
484
+ const rootHit = (root.kind === "property" || root.kind === "computed") && root.id === memberId;
485
+ const leafHit = (0, import_codegen7.transformStateRootIds)(binding.transform).includes(
486
+ memberId
487
+ );
488
+ if (!rootHit && !leafHit) return;
489
+ const passed = rootHit && "id" in root ? spell([root.id, ...binding.path]) : "";
490
+ rows.push({
491
+ kind: "binding",
492
+ where: at(slot),
493
+ screenId: meta.id,
494
+ controlId: control.id,
495
+ ...passed ? { passed } : {}
496
+ });
497
+ });
498
+ (0, import_codegen7.everyStateWrite)(control).filter((write) => write.propertyId === memberId).forEach(() => {
499
+ rows.push({
500
+ kind: "state-write",
501
+ where: at("output"),
502
+ screenId: meta.id,
503
+ controlId: control.id
504
+ });
505
+ });
506
+ Object.entries(control.outputs ?? {}).forEach(([output, methodId]) => {
507
+ if (methodId !== memberId) return;
508
+ rows.push({
509
+ kind: "output-call",
510
+ where: at(outputCallLabelOf(control, output, embedded)),
511
+ screenId: meta.id,
512
+ controlId: control.id,
513
+ ...callColumns(
514
+ scope.feature,
515
+ memberId,
516
+ (0, import_codegen7.outputArgRows)(control.outputArgs, output),
517
+ spell
518
+ )
519
+ });
520
+ });
521
+ Object.entries(control.screenInputs ?? {}).forEach(
522
+ ([inputId, bindingSource]) => {
523
+ if (bindingSource.kind !== "data") return;
524
+ const binding = bindingSource.binding;
525
+ const root = binding.root;
526
+ if (root.kind !== "property" && root.kind !== "computed" || root.id !== memberId) {
527
+ return;
528
+ }
529
+ const target = scope.screens.find(
530
+ (candidate) => candidate.meta.id === control.screenId
531
+ );
532
+ const input = target?.meta.inputs?.[inputId];
533
+ const needs = input ? `${input.name}: ${(0, import_codegen7.tsTypeExpression)(
534
+ scope.feature.shapes,
535
+ input.dataType,
536
+ input.cardinality
537
+ )}` : void 0;
538
+ const passed = spell([root.id, ...binding.path]);
539
+ rows.push({
540
+ kind: "screen-input",
541
+ where: at(input?.name ?? inputId),
542
+ screenId: meta.id,
543
+ controlId: control.id,
544
+ ...needs ? { needs } : {},
545
+ ...passed ? { passed } : {}
546
+ });
547
+ }
548
+ );
549
+ });
550
+ });
551
+ return rows;
552
+ };
553
+ var callArgText = (row2, spell) => {
554
+ const name = row2.target.join(".") || "args";
555
+ const value = () => {
556
+ switch (row2.source) {
557
+ case "state":
558
+ return row2.propertyId ? spell([row2.propertyId]) : "";
559
+ case "binding": {
560
+ const root = row2.binding?.root;
561
+ return root && (root.kind === "property" || root.kind === "computed") ? spell([root.id, ...row2.binding?.path ?? []]) : "";
562
+ }
563
+ case "fixed":
564
+ return row2.value ? `"${row2.value}"` : "";
565
+ case "input":
566
+ return row2.input ? `input.${row2.input}` : "";
567
+ case "event":
568
+ return `$event${row2.event?.length ? `.${row2.event.join(".")}` : ""}`;
569
+ case "storage":
570
+ return row2.storageKey ? `${row2.storageShelf ?? "local"}.${row2.storageKey}` : "";
571
+ default:
572
+ return "";
573
+ }
574
+ };
575
+ const spelled = value();
576
+ return spelled ? `${name} \u2190 ${spelled}` : name;
577
+ };
578
+ function memberUsage(scope, memberId) {
579
+ if (!(0, import_codegen7.ownedStoreOfMember)(scope.feature, memberId)) return [];
580
+ const functions = { ...scope.functions, ...scope.feature.functions };
581
+ const spell = pathSpeller(scope.feature, functions);
582
+ const byWhere = (a, b) => a.where.localeCompare(b.where);
583
+ return [
584
+ ...screenRows(scope, memberId, spell).sort(byWhere),
585
+ ...storeRows(scope, memberId, functions, spell).sort(byWhere)
586
+ ];
587
+ }
588
+
589
+ // apps/m-one-ui/src/app/pages/design/lib/screen-used-by.ts
590
+ var import_codegen10 = require("./index.js");
591
+
592
+ // apps/m-one-ui/src/app/pages/design/lib/screen-link.ts
593
+ var import_codegen9 = require("./index.js");
594
+
595
+ // apps/m-one-ui/src/app/pages/design/lib/screen-embed-helper.ts
596
+ var import_codegen8 = require("./index.js");
597
+ var isScreenControl = (control) => control.type === import_codegen8.ControlType.SCREEN && typeof control.screenId === "string";
598
+
599
+ // apps/m-one-ui/src/app/pages/design/lib/screen-link.ts
600
+ function overlayLinks(fromScreenId, map) {
601
+ const links = [];
602
+ Object.values(map).forEach((control) => {
603
+ Object.entries(control.directives ?? {}).forEach(([name, directive]) => {
604
+ if (!(0, import_codegen9.isOverlayDirectiveName)(name)) return;
605
+ const configs = directive.overlayId ? map[directive.overlayId]?.configs : directive.configs;
606
+ const component = configs?.["component"];
607
+ if (typeof component !== "string" || !component) return;
608
+ links.push({
609
+ kind: "overlay-component",
610
+ fromScreenId,
611
+ controlId: directive.overlayId ?? control.id,
612
+ toScreenId: component
613
+ });
614
+ });
615
+ });
616
+ return links;
617
+ }
618
+ var cardKind = (control) => control.type === import_codegen9.ControlType.SECTION_CAROUSEL ? "carousel-element" : "card-element";
619
+ function controlMapLinks(fromScreenId, map) {
620
+ const links = [];
621
+ Object.values(map).forEach((control) => {
622
+ if (isScreenControl(control)) {
623
+ links.push({
624
+ kind: "screen-control",
625
+ fromScreenId,
626
+ controlId: control.id,
627
+ toScreenId: control.screenId
628
+ });
629
+ }
630
+ const cardScreenId = control.cards?.screenId;
631
+ if (cardScreenId) {
632
+ links.push({
633
+ kind: cardKind(control),
634
+ fromScreenId,
635
+ controlId: control.id,
636
+ toScreenId: cardScreenId
637
+ });
638
+ }
639
+ Object.keys(control.outputOpens ?? {}).forEach((output) => {
640
+ const screenId = (0, import_codegen9.outputOpenOf)(control.outputOpens, output)?.screenId;
641
+ if (!screenId) return;
642
+ links.push({
643
+ kind: "output-open",
644
+ fromScreenId,
645
+ controlId: control.id,
646
+ toScreenId: screenId
647
+ });
648
+ });
649
+ const searchScreenId = control.search?.screenId;
650
+ if (searchScreenId) {
651
+ links.push({
652
+ kind: "search-results",
653
+ fromScreenId,
654
+ controlId: control.id,
655
+ toScreenId: searchScreenId
656
+ });
657
+ }
658
+ });
659
+ return [...links, ...overlayLinks(fromScreenId, map)];
660
+ }
661
+ function navLinks(navMap) {
662
+ const links = [];
663
+ Object.values(navMap).forEach((nav) => {
664
+ if (nav.pageId) {
665
+ links.push({
666
+ kind: "nav-url",
667
+ fromNavId: nav.navId,
668
+ toScreenId: nav.pageId
669
+ });
670
+ }
671
+ if (nav.componentKey) {
672
+ links.push({
673
+ kind: "nav-component",
674
+ fromNavId: nav.navId,
675
+ toScreenId: nav.componentKey
676
+ });
677
+ }
678
+ if (nav.rowSource?.kind === "screen" && nav.rowSource.screenId) {
679
+ links.push({
680
+ kind: "nav-rows",
681
+ fromNavId: nav.navId,
682
+ toScreenId: nav.rowSource.screenId
683
+ });
684
+ }
685
+ if (nav.searchAnswer?.kind === "screen" && nav.searchAnswer.screenId) {
686
+ links.push({
687
+ kind: "search-answer",
688
+ fromNavId: nav.navId,
689
+ toScreenId: nav.searchAnswer.screenId
690
+ });
691
+ }
692
+ });
693
+ return links;
694
+ }
695
+ function methodLinks(features) {
696
+ const links = [];
697
+ Object.values(features).forEach((feature) => {
698
+ const stores = [
699
+ { subStoreId: void 0, methods: feature.methods },
700
+ ...Object.values(feature.subStores ?? {}).map((sub) => ({
701
+ subStoreId: sub.id,
702
+ methods: sub.methods
703
+ }))
704
+ ];
705
+ stores.forEach(({ subStoreId, methods }) => {
706
+ Object.values(methods).forEach((method) => {
707
+ const screenId = method.open?.screenId;
708
+ if (!screenId) return;
709
+ links.push({
710
+ kind: "method-open",
711
+ fromFeatureId: feature.id,
712
+ methodId: method.id,
713
+ ...subStoreId ? { subStoreId } : {},
714
+ toScreenId: screenId
715
+ });
716
+ });
717
+ });
718
+ });
719
+ return links;
720
+ }
721
+ function screenLinks(maps, navMap, features = {}) {
722
+ const fromControls = Object.entries(maps).flatMap(
723
+ ([screenId, map]) => controlMapLinks(screenId, map)
724
+ );
725
+ return [...fromControls, ...navLinks(navMap), ...methodLinks(features)];
726
+ }
727
+ var inboundLinks = (links, screenId) => links.filter((link) => link.toScreenId === screenId);
728
+
729
+ // apps/m-one-ui/src/app/pages/design/lib/screen-used-by.ts
730
+ function holderOf(link, scope) {
731
+ if (link.fromScreenId && link.controlId) {
732
+ const screen = scope.screens.find((s) => s.id === link.fromScreenId);
733
+ const control = scope.maps[link.fromScreenId]?.[link.controlId];
734
+ return {
735
+ kind: "control",
736
+ name: (0, import_codegen10.resolveFieldName)({ id: link.controlId, configs: control?.configs }),
737
+ // A stale slot keeps its id rather than going blank.
738
+ where: screen?.name ?? link.fromScreenId,
739
+ screenId: link.fromScreenId,
740
+ controlId: link.controlId,
741
+ ...screen?.featureId ? { featureId: screen.featureId } : {}
742
+ };
743
+ }
744
+ if (link.fromNavId) {
745
+ return {
746
+ kind: "nav",
747
+ name: link.fromNavId,
748
+ where: link.fromNavId,
749
+ navId: link.fromNavId
750
+ };
751
+ }
752
+ if (link.fromFeatureId && link.methodId) {
753
+ const feature = scope.features[link.fromFeatureId];
754
+ const store = link.subStoreId ? feature?.subStores?.[link.subStoreId] : feature;
755
+ return {
756
+ kind: "store-method",
757
+ name: store?.methods[link.methodId]?.name ?? link.methodId,
758
+ where: feature?.name ?? link.fromFeatureId,
759
+ featureId: link.fromFeatureId,
760
+ ...link.subStoreId ? { subStoreId: link.subStoreId } : {}
761
+ };
762
+ }
763
+ return void 0;
764
+ }
765
+ function screenUsedBy(screenId, scope) {
766
+ const links = inboundLinks(
767
+ screenLinks(scope.maps, scope.navMap, scope.features),
768
+ screenId
769
+ );
770
+ return links.flatMap((link) => {
771
+ const holder = holderOf(link, scope);
772
+ return holder ? [{ link, holder }] : [];
773
+ }).sort(
774
+ (a, b) => a.holder.where.localeCompare(b.holder.where) || a.holder.name.localeCompare(b.holder.name)
775
+ );
776
+ }
777
+
778
+ // apps/m-one-ui/src/app/pages/design/lib/spec-drift.ts
779
+ var import_codegen11 = require("./index.js");
780
+ var operationAt = (spec, verb, path) => spec.operations.find((op) => op.verb === verb && op.path === path);
781
+ var covered = (label, mapped) => mapped.some(
782
+ (key) => label.startsWith(`${key}.`) || key.startsWith(`${label}.`)
783
+ );
784
+ function shapeAtOrigin(spec, origin) {
785
+ const op = operationAt(spec, origin.verb, origin.path);
786
+ const response = op ? (0, import_codegen11.responseOf)(op, origin.code) : void 0;
787
+ if (!response?.dataType) return void 0;
788
+ const shapes = Object.fromEntries(
789
+ response.shapes.map((shape2) => [shape2.id, shape2])
790
+ );
791
+ let dataType = response.dataType;
792
+ for (const member of origin.pointer) {
793
+ if (dataType.type !== "shape") return void 0;
794
+ const key = shapes[dataType.shapeId]?.keys.find((k) => k.name === member);
795
+ if (!key) return void 0;
796
+ dataType = key.dataType;
797
+ }
798
+ if (dataType.type !== "shape") return void 0;
799
+ const shape = shapes[dataType.shapeId];
800
+ return shape ? { shape, shapes } : void 0;
801
+ }
802
+ var keyLabel = (key, shapes) => (0, import_codegen11.typeLabel)(key.dataType, key.cardinality, shapes);
803
+ var sameKeyType = (held, fresh, heldShapes, freshShapes) => {
804
+ if (held.dataType?.type === "shape" && fresh.dataType?.type === "shape") {
805
+ return held.cardinality === fresh.cardinality && (0, import_codegen11.dataTypeFits)(held, heldShapes, fresh, freshShapes) && (0, import_codegen11.dataTypeFits)(fresh, freshShapes, held, heldShapes);
806
+ }
807
+ return keyLabel(held, heldShapes) === keyLabel(fresh, freshShapes);
808
+ };
809
+ var driftRowKey = (row2) => [
810
+ row2.kind,
811
+ row2.featureId,
812
+ row2.methodId ?? "",
813
+ row2.shapeId ?? "",
814
+ row2.propertyId ?? "",
815
+ row2.functionId ?? "",
816
+ row2.code ?? "",
817
+ row2.key ?? "",
818
+ (row2.target ?? row2.source ?? []).join("."),
819
+ row2.paramIndex ?? ""
820
+ ].join("|");
821
+ function detectDriftRows(scope, spec) {
822
+ const rows = [];
823
+ const shared = scope.sharedShapes ?? {};
824
+ for (const feature of Object.values(scope.features)) {
825
+ const seen2 = { ...feature, shapes: (0, import_codegen11.shapesInReach)(feature, shared) };
826
+ rows.push(...methodRows(seen2, scope.functions, spec));
827
+ rows.push(...shapeRows(feature, spec, seen2.shapes));
828
+ rows.push(...signatureRows(seen2, scope.functions, spec));
829
+ }
830
+ if (Object.keys(shared).length) {
831
+ rows.push(
832
+ ...shapeRows(
833
+ { ...(0, import_codegen11.emptyFeature)(import_codegen11.SHARED_SHAPES, import_codegen11.SHARED_SHAPES), shapes: shared },
834
+ spec
835
+ )
836
+ );
837
+ }
838
+ const seen = /* @__PURE__ */ new Set();
839
+ return rows.filter((row2) => {
840
+ const key = driftRowKey(row2);
841
+ if (seen.has(key)) return false;
842
+ seen.add(key);
843
+ return true;
844
+ });
845
+ }
846
+ function detectDrift(scope, spec) {
847
+ const holders = driftHolders(scope);
848
+ return detectDriftRows(scope, spec).map((row2) => ({
849
+ ...row2,
850
+ downstream: holders(row2)
851
+ }));
852
+ }
853
+ function methodRows(feature, appFunctions, spec) {
854
+ const rows = [];
855
+ const functions = { ...appFunctions, ...feature.functions };
856
+ const main = new Set(Object.keys(feature.methods));
857
+ for (const method of (0, import_codegen11.storesOf)(feature).flatMap(
858
+ (owned) => Object.values(owned.methods)
859
+ )) {
860
+ if ((0, import_codegen11.isStorageMethod)(method) || (0, import_codegen11.isCacheMethod)(method)) continue;
861
+ const at = { feature, method };
862
+ const op = operationAt(spec, method.verb, method.path);
863
+ if (!op) {
864
+ rows.push(
865
+ row(at, {
866
+ kind: "operation-gone",
867
+ repair: "remove",
868
+ detail: `${method.verb.toUpperCase()} ${method.path}`
869
+ })
870
+ );
871
+ continue;
872
+ }
873
+ if (!main.has(method.id)) continue;
874
+ rows.push(...inputRows(feature, method, op));
875
+ rows.push(...responseRows(feature, method, op, functions));
876
+ }
877
+ return rows;
878
+ }
879
+ function inputRows(feature, method, op) {
880
+ const rows = [];
881
+ const at = { feature, method };
882
+ const targets = (0, import_codegen11.inputPaths)(op);
883
+ const byLabel = new Map(targets.map((target) => [target.label, target]));
884
+ const mapped = method.inputs.map((mapping) => (0, import_codegen11.targetKey)(mapping.target));
885
+ const paths = (0, import_codegen11.bindablePaths)(feature.properties, feature.shapes);
886
+ for (const mapping of method.inputs) {
887
+ const label = (0, import_codegen11.targetKey)(mapping.target);
888
+ const target = byLabel.get(label);
889
+ if (!target) {
890
+ rows.push(
891
+ row(at, {
892
+ kind: "input-gone",
893
+ repair: "prune",
894
+ target: mapping.target,
895
+ detail: label
896
+ })
897
+ );
898
+ continue;
899
+ }
900
+ if (mapping.source === "fixed" && !(0, import_codegen11.fixedAllowed)(target)) {
901
+ rows.push(
902
+ row(at, {
903
+ kind: "input-retyped",
904
+ repair: "prune",
905
+ target: mapping.target,
906
+ detail: `${label} \u2014 ${(0, import_codegen11.typeLabel)(
907
+ target.dataType,
908
+ target.cardinality,
909
+ target.shapes
910
+ )}`
911
+ })
912
+ );
913
+ continue;
914
+ }
915
+ if (mapping.source !== "store" || !mapping.path?.length) continue;
916
+ const drawn = mapping.path.join(".");
917
+ const accepted = (0, import_codegen11.pathsFor)(target, paths, feature.shapes).some(
918
+ (path) => path.path.join(".") === drawn
919
+ );
920
+ if (accepted) continue;
921
+ const held = paths.find((path) => path.path.join(".") === drawn);
922
+ rows.push(
923
+ row(at, {
924
+ kind: "input-retyped",
925
+ repair: "prune",
926
+ target: mapping.target,
927
+ detail: `${label}: ${held ? (0, import_codegen11.typeLabel)(held.dataType, held.cardinality, feature.shapes) : "state"} \u2192 ${(0, import_codegen11.typeLabel)(target.dataType, target.cardinality, target.shapes)}`
928
+ })
929
+ );
930
+ }
931
+ for (const target of targets) {
932
+ if (!target.required) continue;
933
+ if (mapped.includes(target.label) || covered(target.label, mapped))
934
+ continue;
935
+ rows.push(
936
+ row(at, {
937
+ kind: "input-now-required",
938
+ repair: "none",
939
+ target: target.target,
940
+ detail: `${target.label}: ${(0, import_codegen11.typeLabel)(
941
+ target.dataType,
942
+ target.cardinality,
943
+ target.shapes
944
+ )}`
945
+ })
946
+ );
947
+ }
948
+ return rows;
949
+ }
950
+ function responseRows(feature, method, op, functions) {
951
+ const rows = [];
952
+ const at = { feature, method };
953
+ for (const mapping of method.response) {
954
+ if (!(0, import_codegen11.responseOf)(op, mapping.code)) {
955
+ rows.push(
956
+ row(at, {
957
+ kind: "response-code-gone",
958
+ repair: "prune",
959
+ code: mapping.code,
960
+ source: mapping.source,
961
+ detail: mapping.code
962
+ })
963
+ );
964
+ continue;
965
+ }
966
+ if (mapping.transform) {
967
+ rows.push(...transformRows(at, mapping, op, functions));
968
+ continue;
969
+ }
970
+ const error = (0, import_codegen11.responseMappingError)(
971
+ mapping,
972
+ op,
973
+ feature.properties,
974
+ feature.shapes
975
+ );
976
+ if (!error) continue;
977
+ const mismatch = (0, import_codegen11.responseMappingDetail)(
978
+ mapping,
979
+ op,
980
+ feature.properties,
981
+ feature.shapes
982
+ );
983
+ const landing = feature.properties[mapping.propertyId]?.name;
984
+ const read = mapping.source.join(".") || "body";
985
+ const where = landing ? `${read} \u2192 ${landing}` : read;
986
+ const detail = mismatch ? `${where}: ${mismatch}` : where;
987
+ const gone = error === "emit-gap-response-source";
988
+ rows.push(
989
+ row(at, {
990
+ kind: gone ? "response-path-gone" : "response-retyped",
991
+ // A source the spec stopped answering with has nothing to cast from;
992
+ // a type that moved is exactly what `cast to response` is for.
993
+ repair: gone ? "prune" : "cast",
994
+ code: mapping.code,
995
+ source: mapping.source,
996
+ propertyId: mapping.propertyId,
997
+ detail
998
+ })
999
+ );
1000
+ }
1001
+ return rows;
1002
+ }
1003
+ function transformRows(at, mapping, op, functions) {
1004
+ const transform = mapping.transform;
1005
+ const fn = (0, import_codegen11.outcomeTransformFunction)(
1006
+ transform,
1007
+ at.feature.properties[mapping.propertyId],
1008
+ functions
1009
+ );
1010
+ if (!transform || !fn) return [];
1011
+ const response = (0, import_codegen11.responseOf)(op, mapping.code);
1012
+ const sourceShapes = (0, import_codegen11.responseShapeMap)(response);
1013
+ const landing = at.feature.properties[mapping.propertyId]?.name;
1014
+ const rows = [];
1015
+ fn.params.forEach((param, index) => {
1016
+ const binding = transform.args[index];
1017
+ if (binding?.source !== "response") return;
1018
+ const label = (0, import_codegen11.paramLabel)(param.name, index);
1019
+ const read = binding.path.join(".") || "body";
1020
+ const where = [read, fn.name, landing].filter(Boolean).join(" \u2192 ");
1021
+ const held = { dataType: param.dataType, cardinality: param.cardinality };
1022
+ const value = (0, import_codegen11.responsePathAt)(response, binding.path);
1023
+ const fields = {
1024
+ repair: "none",
1025
+ code: mapping.code,
1026
+ source: binding.path,
1027
+ propertyId: mapping.propertyId,
1028
+ paramIndex: index
1029
+ };
1030
+ if (!value) {
1031
+ rows.push(
1032
+ row(at, {
1033
+ kind: "response-path-gone",
1034
+ detail: `${where}: ${label}`,
1035
+ ...fields
1036
+ })
1037
+ );
1038
+ return;
1039
+ }
1040
+ if ((0, import_codegen11.outcomeTransformArgFits)(
1041
+ transform,
1042
+ index,
1043
+ value,
1044
+ sourceShapes,
1045
+ held,
1046
+ at.feature.shapes
1047
+ ))
1048
+ return;
1049
+ const mismatch = (0, import_codegen11.dataTypeMismatch)(
1050
+ value,
1051
+ sourceShapes,
1052
+ held,
1053
+ at.feature.shapes,
1054
+ false,
1055
+ label,
1056
+ "the response"
1057
+ );
1058
+ rows.push(
1059
+ row(at, {
1060
+ kind: "response-retyped",
1061
+ detail: mismatch ? `${where}: ${mismatch}` : `${where}: ${label}`,
1062
+ ...fields
1063
+ })
1064
+ );
1065
+ });
1066
+ return rows;
1067
+ }
1068
+ function shapeRows(feature, spec, reach = feature.shapes) {
1069
+ const rows = [];
1070
+ for (const shape of Object.values(feature.shapes)) {
1071
+ if (!shape.origin) continue;
1072
+ const found = shapeAtOrigin(spec, shape.origin);
1073
+ if (!found) continue;
1074
+ const at = { feature, shape };
1075
+ const held = new Map(shape.keys.map((key) => [key.name, key]));
1076
+ const fresh = new Map(found.shape.keys.map((key) => [key.name, key]));
1077
+ for (const [name, key] of fresh) {
1078
+ const mine = held.get(name);
1079
+ if (!mine) {
1080
+ rows.push(
1081
+ row(at, {
1082
+ kind: "shape-key-added",
1083
+ repair: "cast",
1084
+ key: name,
1085
+ code: shape.origin.code,
1086
+ detail: `${name}: ${keyLabel(key, found.shapes)}`
1087
+ })
1088
+ );
1089
+ continue;
1090
+ }
1091
+ if (sameKeyType(mine, key, reach, found.shapes)) continue;
1092
+ const before = keyLabel(mine, reach);
1093
+ const after = keyLabel(key, found.shapes);
1094
+ rows.push(
1095
+ row(at, {
1096
+ kind: "shape-key-retyped",
1097
+ repair: "cast",
1098
+ key: name,
1099
+ code: shape.origin.code,
1100
+ detail: `${name}: ${before} \u2192 ${after}`
1101
+ })
1102
+ );
1103
+ }
1104
+ for (const [name, key] of held) {
1105
+ if (fresh.has(name)) continue;
1106
+ rows.push(
1107
+ row(at, {
1108
+ kind: "shape-key-gone",
1109
+ repair: "cast",
1110
+ key: name,
1111
+ code: shape.origin.code,
1112
+ detail: `${name}: ${keyLabel(key, reach)}`
1113
+ })
1114
+ );
1115
+ }
1116
+ const layout = layoutDrift(shape, found.shape);
1117
+ if (layout) {
1118
+ rows.push(
1119
+ row(at, {
1120
+ kind: "shape-layout-changed",
1121
+ repair: "cast",
1122
+ code: shape.origin.code,
1123
+ detail: layout
1124
+ })
1125
+ );
1126
+ }
1127
+ }
1128
+ return rows;
1129
+ }
1130
+ var layoutLabel = (shape) => shape.positional ? `[${shape.keys.map((key) => key.name).join(", ")}]` : "object";
1131
+ function layoutDrift(held, fresh) {
1132
+ if (!held.positional && !fresh.positional) return void 0;
1133
+ const before = layoutLabel(held);
1134
+ const after = layoutLabel(fresh);
1135
+ return before === after ? void 0 : `${before} \u2192 ${after}`;
1136
+ }
1137
+ function signatureRows(feature, appFunctions, spec) {
1138
+ const rows = [];
1139
+ const register = { ...appFunctions, ...feature.functions };
1140
+ for (const fn of Object.values(register)) {
1141
+ const at = { feature, fn };
1142
+ for (const shapeId of (0, import_codegen11.signatureShapeIds)(fn)) {
1143
+ const shape = feature.shapes[shapeId];
1144
+ const members = [
1145
+ ...fn.params.filter(
1146
+ (param) => param.dataType.type === "shape" && param.dataType.shapeId === shapeId
1147
+ ).map((param) => param.name)
1148
+ ];
1149
+ if (fn.returnType.type === "shape" && fn.returnType.shapeId === shapeId) {
1150
+ members.push("return");
1151
+ }
1152
+ const detail = members.join(", ");
1153
+ if (!shape) {
1154
+ rows.push(
1155
+ row(at, {
1156
+ kind: "signature-shape-gone",
1157
+ // No landing to guess: the shape is gone, and which of the
1158
+ // Feature's shapes the parameter *meant* is not a thing the spec
1159
+ // can answer. The function has to be redrawn by hand.
1160
+ repair: "none",
1161
+ shapeId,
1162
+ detail
1163
+ })
1164
+ );
1165
+ continue;
1166
+ }
1167
+ if (!shape.origin) continue;
1168
+ const twin = (0, import_codegen11.shapeTwinAtOrigin)(feature.shapes, shapeId);
1169
+ if (twin) {
1170
+ rows.push(
1171
+ row(at, {
1172
+ kind: "signature-shape-retyped",
1173
+ repair: "cast",
1174
+ shapeId,
1175
+ detail: `${detail}: ${shape.name} \u2192 ${twin.name}`
1176
+ })
1177
+ );
1178
+ continue;
1179
+ }
1180
+ if (!shapeAtOrigin(spec, shape.origin)) {
1181
+ rows.push(
1182
+ row(at, {
1183
+ kind: "signature-shape-retyped",
1184
+ // The operation, the code or the path to it has gone — the same
1185
+ // silence the shape rows give, said here from the signature's
1186
+ // side because the function still declares the interface. No
1187
+ // fresh shape to cast onto, so no Accept.
1188
+ repair: "none",
1189
+ shapeId,
1190
+ detail: `${detail}: ${shape.name}`
1191
+ })
1192
+ );
1193
+ }
1194
+ }
1195
+ }
1196
+ return rows;
1197
+ }
1198
+ function row(at, rest) {
1199
+ const subject = [
1200
+ at.feature.name,
1201
+ at.method?.name ?? at.shape?.name ?? at.fn?.name
1202
+ ].filter(Boolean).join(" \xB7 ");
1203
+ return {
1204
+ featureId: at.feature.id,
1205
+ featureName: at.feature.name,
1206
+ methodId: at.method?.id,
1207
+ methodName: at.method?.name,
1208
+ shapeName: at.shape?.name,
1209
+ functionId: at.fn?.id,
1210
+ functionName: at.fn?.name,
1211
+ message: `drift-${rest.kind}`,
1212
+ subject,
1213
+ downstream: [],
1214
+ ...rest,
1215
+ // After the spread: an omitted `shapeId` must not read as a cleared one,
1216
+ // and a signature row's own is the stale shape rather than the subject's.
1217
+ shapeId: rest.shapeId ?? at.shape?.id
1218
+ };
1219
+ }
1220
+ function driftHolders(scope) {
1221
+ const index = /* @__PURE__ */ new Map();
1222
+ for (const container of containers(scope)) {
1223
+ for (const id of namedIds(container.value)) {
1224
+ const held = index.get(id);
1225
+ if (held) held.push(container);
1226
+ else index.set(id, [container]);
1227
+ }
1228
+ }
1229
+ return (row2) => {
1230
+ const found = /* @__PURE__ */ new Map();
1231
+ for (const group of subjectIds(scope, row2)) {
1232
+ const [first, ...rest] = group;
1233
+ for (const container of index.get(first) ?? []) {
1234
+ if (container.selfId && group.includes(container.selfId)) continue;
1235
+ if (!rest.every((id) => index.get(id)?.includes(container))) continue;
1236
+ const { value: _value, selfId: _selfId, ...holder } = container;
1237
+ found.set(`${holder.kind}:${holder.id}`, holder);
1238
+ }
1239
+ }
1240
+ return [...found.values()].sort((a, b) => a.subject.localeCompare(b.subject));
1241
+ };
1242
+ }
1243
+ function subjectIds(scope, row2) {
1244
+ const shapes = row2.featureId === import_codegen11.SHARED_SHAPES ? scope.sharedShapes : scope.features[row2.featureId]?.shapes;
1245
+ if (!shapes) return [];
1246
+ if (row2.kind === "operation-gone") return row2.methodId ? [[row2.methodId]] : [];
1247
+ if (row2.functionId) return [[row2.functionId]];
1248
+ if (row2.shapeId && row2.key) {
1249
+ const key = shapes[row2.shapeId]?.keys.find((k) => k.name === row2.key);
1250
+ return key ? [[key.id]] : [];
1251
+ }
1252
+ if (row2.target && row2.methodId) {
1253
+ const method = (0, import_codegen11.storesOf)(scope.features[row2.featureId]).map((store) => store.methods[row2.methodId]).find(Boolean);
1254
+ const key = (0, import_codegen11.targetKey)(row2.target);
1255
+ const mapping = method?.inputs.find(
1256
+ (input) => (0, import_codegen11.targetKey)(input.target) === key
1257
+ );
1258
+ return mapping?.source === "args" && mapping.arg ? [[row2.methodId, mapping.arg]] : [];
1259
+ }
1260
+ return row2.propertyId ? [[row2.propertyId]] : [];
1261
+ }
1262
+ function containers(scope) {
1263
+ const out = [];
1264
+ for (const feature of Object.values(scope.features)) {
1265
+ const featureId = feature.id;
1266
+ for (const variant of Object.values(feature.variants)) {
1267
+ out.push({
1268
+ kind: "variant",
1269
+ id: variant.id,
1270
+ featureId,
1271
+ subject: `${feature.name} \xB7 variant ${variant.name}`,
1272
+ value: variant
1273
+ });
1274
+ }
1275
+ for (const store of (0, import_codegen11.storesOf)(feature)) {
1276
+ const subStoreId = store.subStore?.id;
1277
+ const at = subStoreId ? { featureId, subStoreId } : { featureId };
1278
+ const name = store.subStore ? `${feature.name} \xB7 ${store.subStore.name}` : feature.name;
1279
+ for (const computed of Object.values(store.computeds)) {
1280
+ out.push({
1281
+ kind: "computed",
1282
+ id: computed.id,
1283
+ ...at,
1284
+ subject: `${name} \xB7 computed ${computed.name}`,
1285
+ value: computed
1286
+ });
1287
+ }
1288
+ for (const method of Object.values(store.methods)) {
1289
+ out.push({
1290
+ kind: "method",
1291
+ id: method.id,
1292
+ ...at,
1293
+ subject: `${name} \xB7 method ${method.name}`,
1294
+ selfId: method.id,
1295
+ value: method
1296
+ });
1297
+ }
1298
+ for (const property of Object.values(store.properties)) {
1299
+ out.push({
1300
+ kind: "property",
1301
+ id: property.id,
1302
+ ...at,
1303
+ subject: `${name} \xB7 state ${property.name}`,
1304
+ selfId: property.id,
1305
+ value: property
1306
+ });
1307
+ }
1308
+ for (const timer of Object.values(store.timers)) {
1309
+ out.push({
1310
+ kind: "timer",
1311
+ id: timer.id,
1312
+ ...at,
1313
+ subject: `${name} \xB7 timer ${timer.name}`,
1314
+ value: timer
1315
+ });
1316
+ }
1317
+ if (store.hook) {
1318
+ out.push({
1319
+ kind: "hook",
1320
+ id: subStoreId ?? featureId,
1321
+ ...at,
1322
+ subject: `${name} \xB7 hook`,
1323
+ value: store.hook
1324
+ });
1325
+ }
1326
+ if (store.searchFeed) {
1327
+ out.push({
1328
+ kind: "search-feed",
1329
+ id: subStoreId ?? featureId,
1330
+ ...at,
1331
+ subject: `${name} \xB7 search feed`,
1332
+ value: store.searchFeed
1333
+ });
1334
+ }
1335
+ }
1336
+ }
1337
+ for (const screen of scope.screens) {
1338
+ const screenId = screen.meta.id;
1339
+ for (const control of Object.values(screen.state.controlMap)) {
1340
+ out.push({
1341
+ kind: "control",
1342
+ id: control.id,
1343
+ screenId,
1344
+ subject: `${screen.meta.name} \xB7 ${controlLabel2(control)}`,
1345
+ value: control
1346
+ });
1347
+ }
1348
+ out.push({
1349
+ kind: "screen",
1350
+ id: screenId,
1351
+ screenId,
1352
+ subject: `${screen.meta.name} \xB7 screen`,
1353
+ value: screen.meta
1354
+ });
1355
+ }
1356
+ for (const nav of Object.values(scope.navMap ?? {})) {
1357
+ out.push({
1358
+ kind: "nav",
1359
+ id: nav.navId,
1360
+ subject: `nav ${nav.label ?? nav.navId}`,
1361
+ value: nav
1362
+ });
1363
+ }
1364
+ return out;
1365
+ }
1366
+ var controlLabel2 = (control) => {
1367
+ const name = String(control.configs?.["name"] ?? "").trim();
1368
+ return name || control.type;
1369
+ };
1370
+ function namedIds(value, into = /* @__PURE__ */ new Set()) {
1371
+ if (typeof value === "string") into.add(value);
1372
+ else if (Array.isArray(value)) value.forEach((item) => namedIds(item, into));
1373
+ else if (value && typeof value === "object") {
1374
+ Object.values(value).forEach((item) => namedIds(item, into));
1375
+ }
1376
+ return into;
1377
+ }
1378
+
1379
+ // apps/m-one-ui/src/app/pages/design/lib/inspect-catalog.ts
1380
+ var refuse = (reason, detail) => ({ ok: false, refusal: { reason, detail } });
1381
+ var answer = (result) => ({ ok: true, result });
1382
+ var controlMapsOf = (source) => source.screens.map(({ meta, state }) => ({
1383
+ screenId: meta.id,
1384
+ controlMap: state.controlMap
1385
+ }));
1386
+ var usage = {
1387
+ name: "usage",
1388
+ summary: "Everything that uses one store member (the StatePanel Usage list)",
1389
+ args: { member: { type: "string", required: true, doc: "Store member id" } },
1390
+ run: ({ source }, { member }) => {
1391
+ const feature = Object.values(source.features).find(
1392
+ (one) => (0, import_codegen12.ownedStoreOfMember)(one, member)
1393
+ );
1394
+ if (!feature) return refuse("member-unknown", { member });
1395
+ return answer({
1396
+ feature: feature.name,
1397
+ rows: memberUsage(
1398
+ {
1399
+ feature,
1400
+ screens: source.screens,
1401
+ features: source.features,
1402
+ functions: source.functions
1403
+ },
1404
+ member
1405
+ )
1406
+ });
1407
+ }
1408
+ };
1409
+ var usedBy = {
1410
+ name: "used-by",
1411
+ summary: "Everything that names one Screen or one PureFunction (its Used by \u2014 what a delete refuses over)",
1412
+ args: {
1413
+ screen: { type: "string", doc: "Screen id" },
1414
+ function: { type: "string", doc: "PureFunction id" }
1415
+ },
1416
+ run: ({ source }, args) => {
1417
+ const screens = source.screens.map(({ meta }) => meta);
1418
+ if (args["screen"]) {
1419
+ const screenId = args["screen"];
1420
+ if (!screens.some(({ id }) => id === screenId))
1421
+ return refuse("screen-unknown", { screen: screenId });
1422
+ const maps = Object.fromEntries(
1423
+ source.screens.map(({ meta, state }) => [meta.id, state.controlMap])
1424
+ );
1425
+ return answer(
1426
+ screenUsedBy(screenId, {
1427
+ screens,
1428
+ features: source.features,
1429
+ maps,
1430
+ navMap: source.navMap
1431
+ })
1432
+ );
1433
+ }
1434
+ if (args["function"]) {
1435
+ const functionId = args["function"];
1436
+ const known = !!source.functions[functionId] || Object.values(source.features).some(
1437
+ (feature) => !!feature.functions?.[functionId]
1438
+ );
1439
+ if (!known) return refuse("function-unknown", { function: functionId });
1440
+ return answer(
1441
+ functionHolders(functionId, {
1442
+ features: source.features,
1443
+ screens,
1444
+ controlMaps: controlMapsOf(source),
1445
+ navMap: source.navMap
1446
+ })
1447
+ );
1448
+ }
1449
+ return refuse("args-invalid", { missing: ["screen | function"] });
1450
+ }
1451
+ };
1452
+ var apiHoldersInspection = {
1453
+ name: "api-holders",
1454
+ summary: "Every StateShape and StoreMethod drawn from one ApiOperation, shapes first",
1455
+ args: {
1456
+ op: { type: "string", required: true, doc: '"<VERB> <path>", e.g. "GET /orders/{id}"' }
1457
+ },
1458
+ run: ({ source }, { op }) => {
1459
+ const [verb, path] = op.trim().split(/\s+/);
1460
+ const lower = (verb ?? "").toLowerCase();
1461
+ if (!import_codegen12.HTTP_VERBS.includes(lower) || !path)
1462
+ return refuse("op-invalid", { op });
1463
+ return answer(
1464
+ apiHolders(source.features, source.sharedShapes, lower, path)
1465
+ );
1466
+ }
1467
+ };
1468
+ var drift = {
1469
+ name: "drift",
1470
+ summary: "What the backend changed under the design (SpecDrift), with the holders each repair touches",
1471
+ args: {},
1472
+ run: ({ source, spec }) => {
1473
+ if (!spec) return refuse("spec-absent");
1474
+ return answer(
1475
+ detectDrift(
1476
+ {
1477
+ screens: source.screens,
1478
+ features: source.features,
1479
+ functions: source.functions,
1480
+ sharedShapes: source.sharedShapes,
1481
+ navMap: source.navMap
1482
+ },
1483
+ spec
1484
+ )
1485
+ );
1486
+ }
1487
+ };
1488
+ var REACHES = [
1489
+ "screen-computed",
1490
+ "state-computed",
1491
+ "call-condition",
1492
+ "call-compute",
1493
+ "outcome-transform"
1494
+ ];
1495
+ var oneFunctions = {
1496
+ name: "one-functions",
1497
+ summary: "The OneFunctionCatalog: each entry, where it is offered, its signature",
1498
+ args: {
1499
+ reach: { type: "string", doc: `One of ${REACHES.join(", ")}; all when absent` }
1500
+ },
1501
+ run: (_input, { reach }) => {
1502
+ if (reach && !REACHES.includes(reach))
1503
+ return refuse("reach-invalid", { reach, reaches: REACHES });
1504
+ const reaches = reach ? [reach] : REACHES;
1505
+ const byName = new Map(
1506
+ reaches.flatMap((one) => (0, import_codegen12.listOneFunctions)(one)).map((entry) => [entry.name, entry])
1507
+ );
1508
+ return answer(
1509
+ [...byName.values()].sort((a, b) => a.name.localeCompare(b.name)).map((entry) => ({
1510
+ name: entry.name,
1511
+ reach: entry.reach,
1512
+ signature: (0, import_codegen12.oneFunctionSignatureText)(entry)
1513
+ }))
1514
+ );
1515
+ }
1516
+ };
1517
+ var change = {
1518
+ name: "change",
1519
+ summary: "What changed in the design between two refs, in domain words (what a Push message is drafted from)",
1520
+ args: {
1521
+ from: { type: "string", required: true, doc: "Base git ref" },
1522
+ to: { type: "string", doc: "Compared git ref; the working tree when absent" }
1523
+ },
1524
+ run: ({ baseFiles, files }) => {
1525
+ if (!baseFiles || !files) return refuse("files-absent");
1526
+ return answer(designChange(designBaseline(baseFiles), files));
1527
+ }
1528
+ };
1529
+ var INSPECTIONS = [
1530
+ usage,
1531
+ usedBy,
1532
+ apiHoldersInspection,
1533
+ drift,
1534
+ oneFunctions,
1535
+ change
1536
+ ];
1537
+ var inspectionByName = (name) => INSPECTIONS.find((inspection) => inspection.name === name);
1538
+ var runInspection = (inspection, input, args) => {
1539
+ const missing = Object.entries(inspection.args).filter(([key, arg]) => arg.required && !args[key]).map(([key]) => key);
1540
+ if (missing.length) return refuse("args-invalid", { missing });
1541
+ return inspection.run(input, args);
1542
+ };
1543
+ // Annotate the CommonJS export names for ESM import in node:
1544
+ 0 && (module.exports = {
1545
+ INSPECTIONS,
1546
+ inspectionByName,
1547
+ runInspection
1548
+ });