@prenta/component-blocks 0.3.0

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.
package/dist/diff.js ADDED
@@ -0,0 +1,524 @@
1
+ /**
2
+ * Pure functional diff between two component manifests.
3
+ *
4
+ * Why this lives in the package (not in a CMS-server endpoint):
5
+ *
6
+ * - Authors run `prenta-component-blocks diff` locally to decide
7
+ * whether a refactor will require a content migration before they
8
+ * commit.
9
+ * - CI runs the same diff against the production manifest to surface a
10
+ * blocking comment on PRs that change a component's prop shape.
11
+ * - The {@link ManifestDiff} returned here is the input to the
12
+ * forthcoming `migrate` CLI (PR #3b).
13
+ *
14
+ * The classification rules are deliberately conservative: we'd rather
15
+ * tag a change "breaking" and have the author explicitly mark it safe
16
+ * than let bad content silently slip through.
17
+ */
18
+ /**
19
+ * Compare two manifests and return a structured description of the
20
+ * differences. Both arguments are treated as read-only; this function
21
+ * has no side effects and is safe to run on user-provided JSON.
22
+ */
23
+ export function diffManifests(oldManifest, newManifest) {
24
+ const oldByName = indexByName(oldManifest.components);
25
+ const newByName = indexByName(newManifest.components);
26
+ const addedComponents = [];
27
+ const removedComponents = [];
28
+ const changedComponents = [];
29
+ for (const [name, newSpec] of newByName) {
30
+ if (!oldByName.has(name))
31
+ addedComponents.push(newSpec);
32
+ }
33
+ for (const [name, oldSpec] of oldByName) {
34
+ if (!newByName.has(name))
35
+ removedComponents.push(oldSpec);
36
+ }
37
+ for (const [name, newSpec] of newByName) {
38
+ const oldSpec = oldByName.get(name);
39
+ if (!oldSpec)
40
+ continue;
41
+ const change = diffComponent(oldSpec, newSpec);
42
+ if (change)
43
+ changedComponents.push(change);
44
+ }
45
+ const worstSeverity = computeWorstSeverity(addedComponents, removedComponents, changedComponents);
46
+ return {
47
+ addedComponents,
48
+ removedComponents,
49
+ changedComponents,
50
+ worstSeverity,
51
+ };
52
+ }
53
+ function indexByName(components) {
54
+ const out = new Map();
55
+ for (const c of components)
56
+ out.set(c.name, c);
57
+ return out;
58
+ }
59
+ /**
60
+ * Diff a single component's prop list. Returns `null` when the
61
+ * component is unchanged (so callers can skip pushing empty entries).
62
+ */
63
+ function diffComponent(oldSpec, newSpec) {
64
+ const oldProps = indexProps(oldSpec.props);
65
+ const newProps = indexProps(newSpec.props);
66
+ const addedProps = [];
67
+ const removedProps = [];
68
+ const changedProps = [];
69
+ for (const [name, prop] of newProps) {
70
+ if (!oldProps.has(name))
71
+ addedProps.push(prop);
72
+ }
73
+ for (const [name, prop] of oldProps) {
74
+ if (!newProps.has(name))
75
+ removedProps.push(prop);
76
+ }
77
+ for (const [name, newProp] of newProps) {
78
+ const oldProp = oldProps.get(name);
79
+ if (!oldProp)
80
+ continue;
81
+ const change = diffProp(oldProp, newProp);
82
+ if (change)
83
+ changedProps.push(change);
84
+ }
85
+ if (addedProps.length === 0 && removedProps.length === 0 && changedProps.length === 0) {
86
+ return null;
87
+ }
88
+ return {
89
+ name: newSpec.name,
90
+ addedProps,
91
+ removedProps,
92
+ changedProps,
93
+ };
94
+ }
95
+ function indexProps(props) {
96
+ const out = new Map();
97
+ for (const p of props)
98
+ out.set(p.name, p);
99
+ return out;
100
+ }
101
+ /**
102
+ * Diff a single prop between two manifests. We report the first
103
+ * distinguishing factor — required/optional, type, or default value —
104
+ * so the surfaced reason matches what a human would write. Multiple
105
+ * simultaneous changes (e.g. type + required) bubble up via the worst
106
+ * severity.
107
+ */
108
+ function diffProp(oldProp, newProp) {
109
+ // Required-ness changes first because they're the most common
110
+ // source of "your existing content is now invalid" errors.
111
+ const requiredBecameStricter = !oldProp.required && newProp.required;
112
+ const requiredBecameLooser = oldProp.required && !newProp.required;
113
+ // Type comparison uses a deep structural equality on the type tree.
114
+ // This is intentionally exact: even a reorder of union members or
115
+ // enum values is treated as a difference. Surfacing false positives
116
+ // is better than silent data corruption.
117
+ const typesEqual = propTypesEqual(oldProp.type, newProp.type);
118
+ const defaultsEqual = oldProp.defaultValue === newProp.defaultValue;
119
+ if (typesEqual && !requiredBecameStricter && !requiredBecameLooser && defaultsEqual) {
120
+ return null;
121
+ }
122
+ // Compose the reason in priority order.
123
+ if (!typesEqual) {
124
+ const typeChange = classifyTypeChange(oldProp.type, newProp.type);
125
+ // The function's contract is "multiple simultaneous changes bubble
126
+ // up via the worst severity". A safe type change (e.g. an enum
127
+ // gaining a value) that ALSO flips optional→required must still
128
+ // surface as breaking — otherwise a breaking change slides past
129
+ // the CI gate at exit 0. Merge the per-axis severities here.
130
+ const severity = requiredBecameStricter ? 'breaking' : typeChange.severity;
131
+ const reasonParts = [typeChange.reason];
132
+ if (requiredBecameStricter) {
133
+ reasonParts.push(`Prop '${newProp.name}' also became required; existing content without it will fail validation.`);
134
+ }
135
+ else if (requiredBecameLooser) {
136
+ reasonParts.push(`Prop '${newProp.name}' is no longer required.`);
137
+ }
138
+ return {
139
+ name: newProp.name,
140
+ severity,
141
+ reason: reasonParts.join(' '),
142
+ oldType: oldProp.type,
143
+ newType: newProp.type,
144
+ ...(oldProp.required !== newProp.required
145
+ ? { oldRequired: oldProp.required, newRequired: newProp.required }
146
+ : {}),
147
+ ...(defaultsEqual
148
+ ? {}
149
+ : {
150
+ oldDefaultValue: oldProp.defaultValue ?? null,
151
+ newDefaultValue: newProp.defaultValue ?? null,
152
+ }),
153
+ };
154
+ }
155
+ if (requiredBecameStricter) {
156
+ return {
157
+ name: newProp.name,
158
+ severity: 'breaking',
159
+ reason: `Prop '${newProp.name}' became required; existing content without it will fail validation.`,
160
+ oldRequired: oldProp.required,
161
+ newRequired: newProp.required,
162
+ };
163
+ }
164
+ if (requiredBecameLooser) {
165
+ return {
166
+ name: newProp.name,
167
+ severity: 'safe',
168
+ reason: `Prop '${newProp.name}' is no longer required.`,
169
+ oldRequired: oldProp.required,
170
+ newRequired: newProp.required,
171
+ };
172
+ }
173
+ // Only the default value differs at this point.
174
+ return {
175
+ name: newProp.name,
176
+ severity: 'safe',
177
+ reason: `Default value for '${newProp.name}' changed; existing values are unaffected.`,
178
+ oldDefaultValue: oldProp.defaultValue ?? null,
179
+ newDefaultValue: newProp.defaultValue ?? null,
180
+ };
181
+ }
182
+ /**
183
+ * Classify a type change as breaking, safe, or unknown. The rules:
184
+ *
185
+ * - Kind change (string → number) is always breaking.
186
+ * - Enum where the new set is a *superset* of the old → safe (existing
187
+ * values stay valid).
188
+ * - Enum where the new set drops any old value → breaking.
189
+ * - Array itemType change recurses with the same rules.
190
+ * - Object field additions: required additions are breaking, optional
191
+ * additions are safe. Field removals are breaking.
192
+ * - Anything we can't categorize confidently → `unknown` so the
193
+ * migrate CLI prompts the author.
194
+ */
195
+ function classifyTypeChange(oldType, newType) {
196
+ if (oldType.kind !== newType.kind) {
197
+ return {
198
+ severity: 'breaking',
199
+ reason: `Type changed from '${oldType.kind}' to '${newType.kind}'.`,
200
+ };
201
+ }
202
+ if (oldType.kind === 'enum' && newType.kind === 'enum') {
203
+ const oldSet = new Set(oldType.values);
204
+ const newSet = new Set(newType.values);
205
+ const removed = [];
206
+ for (const v of oldSet)
207
+ if (!newSet.has(v))
208
+ removed.push(v);
209
+ if (removed.length > 0) {
210
+ return {
211
+ severity: 'breaking',
212
+ reason: `Enum dropped value(s): ${removed.map((v) => JSON.stringify(v)).join(', ')}.`,
213
+ };
214
+ }
215
+ return {
216
+ severity: 'safe',
217
+ reason: `Enum gained new value(s): ${[...newSet]
218
+ .filter((v) => !oldSet.has(v))
219
+ .map((v) => JSON.stringify(v))
220
+ .join(', ') || '(reordered)'}.`,
221
+ };
222
+ }
223
+ if (oldType.kind === 'literal' && newType.kind === 'literal') {
224
+ return {
225
+ severity: 'breaking',
226
+ reason: `Literal value changed from ${JSON.stringify(oldType.value)} to ${JSON.stringify(newType.value)}.`,
227
+ };
228
+ }
229
+ if (oldType.kind === 'array' && newType.kind === 'array') {
230
+ // classifyTypeChange is only called when propTypesEqual on the
231
+ // outer types already returned false, and for arrays that means
232
+ // the itemTypes definitionally differ (see propTypesEqual's array
233
+ // branch). Always drill into the itemType diff; an extra
234
+ // propTypesEqual check here would be guaranteed-false dead code.
235
+ const inner = classifyTypeChange(oldType.itemType, newType.itemType);
236
+ return { severity: inner.severity, reason: `Array itemType: ${inner.reason}` };
237
+ }
238
+ if (oldType.kind === 'object' && newType.kind === 'object') {
239
+ return classifyObjectChange(oldType.fields, newType.fields);
240
+ }
241
+ if (oldType.kind === 'reference' && newType.kind === 'reference') {
242
+ return {
243
+ severity: oldType.targetType === newType.targetType ? 'safe' : 'unknown',
244
+ reason: `Reference target changed from '${oldType.targetType}' to '${newType.targetType}'.`,
245
+ };
246
+ }
247
+ if (oldType.kind === 'union' && newType.kind === 'union') {
248
+ return {
249
+ severity: 'unknown',
250
+ reason: 'Union shape changed; review the diff against the manifest variants.',
251
+ };
252
+ }
253
+ return {
254
+ severity: 'unknown',
255
+ reason: `Type shape changed within kind '${oldType.kind}'.`,
256
+ };
257
+ }
258
+ function classifyObjectChange(oldFields, newFields) {
259
+ const oldMap = indexProps(oldFields);
260
+ const newMap = indexProps(newFields);
261
+ const addedRequired = [];
262
+ const addedOptional = [];
263
+ const removed = [];
264
+ const becameRequired = [];
265
+ const becameOptional = [];
266
+ const defaultChanged = [];
267
+ const fieldTypeChanges = [];
268
+ for (const [name, prop] of newMap) {
269
+ if (oldMap.has(name))
270
+ continue;
271
+ if (prop.required)
272
+ addedRequired.push(name);
273
+ else
274
+ addedOptional.push(name);
275
+ }
276
+ for (const name of oldMap.keys()) {
277
+ if (!newMap.has(name))
278
+ removed.push(name);
279
+ }
280
+ for (const [name, oldField] of oldMap) {
281
+ const newField = newMap.get(name);
282
+ if (!newField)
283
+ continue;
284
+ if (!propTypesEqual(oldField.type, newField.type)) {
285
+ // Recurse so per-field type changes are classified with the
286
+ // same precision as top-level prop type changes. The array
287
+ // branch in classifyTypeChange does the same; aligning here
288
+ // means a `string → number` flip nested inside an object is
289
+ // surfaced as `breaking`, not the catch-all `unknown` that
290
+ // bypasses the CI gate.
291
+ const inner = classifyTypeChange(oldField.type, newField.type);
292
+ fieldTypeChanges.push({ name, severity: inner.severity, reason: inner.reason });
293
+ }
294
+ // An existing field flipping optional→required is breaking: any
295
+ // existing content that omitted it will fail validation. Without
296
+ // this check propTypesEqual still flagged the change (it compares
297
+ // `required`), but classifyObjectChange used to short-circuit on
298
+ // type-only comparison and fall through to 'safe'.
299
+ if (!oldField.required && newField.required)
300
+ becameRequired.push(name);
301
+ if (oldField.required && !newField.required)
302
+ becameOptional.push(name);
303
+ if (oldField.defaultValue !== newField.defaultValue)
304
+ defaultChanged.push(name);
305
+ }
306
+ if (removed.length > 0) {
307
+ return {
308
+ severity: 'breaking',
309
+ reason: `Object dropped field(s): ${removed.join(', ')}.`,
310
+ };
311
+ }
312
+ if (becameRequired.length > 0) {
313
+ return {
314
+ severity: 'breaking',
315
+ reason: `Object field(s) became required: ${becameRequired.join(', ')}.`,
316
+ };
317
+ }
318
+ if (addedRequired.length > 0) {
319
+ return {
320
+ severity: 'breaking',
321
+ reason: `Object gained required field(s): ${addedRequired.join(', ')}.`,
322
+ };
323
+ }
324
+ if (fieldTypeChanges.length > 0) {
325
+ const worst = worstOf(fieldTypeChanges.map((c) => c.severity));
326
+ const summary = fieldTypeChanges.map((c) => `${c.name}: ${c.reason}`).join(' | ');
327
+ return {
328
+ severity: worst,
329
+ reason: `Object field type change(s) — ${summary}`,
330
+ };
331
+ }
332
+ // Safe-only changes: surface what actually changed so the CLI/JSON
333
+ // output reflects reality. The previous catch-all said "gained
334
+ // optional field(s) only" even when no new fields were added —
335
+ // e.g. an existing field becoming optional or a defaultValue tweak.
336
+ const parts = [];
337
+ if (addedOptional.length > 0)
338
+ parts.push(`gained optional field(s): ${addedOptional.join(', ')}`);
339
+ if (becameOptional.length > 0) {
340
+ parts.push(`field(s) became optional: ${becameOptional.join(', ')}`);
341
+ }
342
+ if (defaultChanged.length > 0) {
343
+ parts.push(`default value(s) changed: ${defaultChanged.join(', ')}`);
344
+ }
345
+ return {
346
+ severity: 'safe',
347
+ reason: parts.length > 0 ? `Object ${parts.join('; ')}.` : 'Object change with no structural impact.',
348
+ };
349
+ }
350
+ function worstOf(severities) {
351
+ if (severities.includes('breaking'))
352
+ return 'breaking';
353
+ if (severities.includes('unknown'))
354
+ return 'unknown';
355
+ return 'safe';
356
+ }
357
+ /**
358
+ * Deep structural equality on PropType trees. Covers all kinds; falls
359
+ * back to JSON serialization for safety on shapes we don't explicitly
360
+ * walk (in practice every kind is covered).
361
+ */
362
+ export function propTypesEqual(a, b) {
363
+ if (a.kind !== b.kind)
364
+ return false;
365
+ switch (a.kind) {
366
+ case 'string':
367
+ case 'number':
368
+ case 'boolean':
369
+ case 'unknown':
370
+ return true;
371
+ case 'literal':
372
+ return b.kind === 'literal' && a.value === b.value;
373
+ case 'enum':
374
+ if (b.kind !== 'enum')
375
+ return false;
376
+ if (a.values.length !== b.values.length)
377
+ return false;
378
+ for (let i = 0; i < a.values.length; i++) {
379
+ if (a.values[i] !== b.values[i])
380
+ return false;
381
+ }
382
+ return true;
383
+ case 'array':
384
+ return b.kind === 'array' && propTypesEqual(a.itemType, b.itemType);
385
+ case 'object':
386
+ if (b.kind !== 'object')
387
+ return false;
388
+ if (a.fields.length !== b.fields.length)
389
+ return false;
390
+ // Compare field-by-field. We index by name so reordering doesn't
391
+ // trip a false positive; ordering within objects isn't part of
392
+ // the contract.
393
+ {
394
+ const bMap = indexProps(b.fields);
395
+ for (const aField of a.fields) {
396
+ const bField = bMap.get(aField.name);
397
+ if (!bField)
398
+ return false;
399
+ if (aField.required !== bField.required)
400
+ return false;
401
+ if (aField.defaultValue !== bField.defaultValue)
402
+ return false;
403
+ if (!propTypesEqual(aField.type, bField.type))
404
+ return false;
405
+ }
406
+ }
407
+ return true;
408
+ case 'union':
409
+ if (b.kind !== 'union')
410
+ return false;
411
+ if (a.types.length !== b.types.length)
412
+ return false;
413
+ for (let i = 0; i < a.types.length; i++) {
414
+ if (!propTypesEqual(a.types[i], b.types[i]))
415
+ return false;
416
+ }
417
+ return true;
418
+ case 'reference':
419
+ return b.kind === 'reference' && a.targetType === b.targetType;
420
+ }
421
+ }
422
+ function computeWorstSeverity(addedComponents, removedComponents, changedComponents) {
423
+ // Removing a known component is always breaking (existing blocks
424
+ // referencing it will fail validation). Adding a new component is
425
+ // always safe (nothing in storage references it yet).
426
+ if (removedComponents.length > 0)
427
+ return 'breaking';
428
+ let worst = addedComponents.length > 0 ? 'safe' : null;
429
+ for (const change of changedComponents) {
430
+ if (change.addedProps.some((p) => p.required))
431
+ return 'breaking';
432
+ if (change.removedProps.length > 0)
433
+ return 'breaking';
434
+ for (const propChange of change.changedProps) {
435
+ worst = mergeSeverity(worst, propChange.severity);
436
+ if (worst === 'breaking')
437
+ return worst;
438
+ }
439
+ if (change.addedProps.length > 0 && worst === null)
440
+ worst = 'safe';
441
+ }
442
+ return worst;
443
+ }
444
+ const SEVERITY_RANK = {
445
+ safe: 0,
446
+ unknown: 1,
447
+ breaking: 2,
448
+ };
449
+ function mergeSeverity(existing, incoming) {
450
+ if (existing === null)
451
+ return incoming;
452
+ return SEVERITY_RANK[incoming] > SEVERITY_RANK[existing] ? incoming : existing;
453
+ }
454
+ // ─── Pretty-printer ─────────────────────────────────────────────────
455
+ /**
456
+ * Render a {@link ManifestDiff} as a human-readable text block for the
457
+ * CLI. The format is intentionally plain — no ANSI codes — so it
458
+ * pipes cleanly into PR comments, CI logs, and editor terminals on
459
+ * Windows. Color is the CLI's job, not this function's.
460
+ */
461
+ export function formatManifestDiff(diff) {
462
+ const lines = [];
463
+ const summary = diff.worstSeverity === null
464
+ ? 'No structural differences.'
465
+ : `Worst severity: ${diff.worstSeverity}`;
466
+ lines.push(`Manifest diff — ${summary}`);
467
+ lines.push('');
468
+ if (diff.addedComponents.length > 0) {
469
+ lines.push(`Added components (${diff.addedComponents.length}):`);
470
+ for (const c of diff.addedComponents) {
471
+ lines.push(` + ${c.name}`);
472
+ }
473
+ lines.push('');
474
+ }
475
+ if (diff.removedComponents.length > 0) {
476
+ lines.push(`Removed components (${diff.removedComponents.length}): [BREAKING]`);
477
+ for (const c of diff.removedComponents) {
478
+ lines.push(` - ${c.name}`);
479
+ }
480
+ lines.push('');
481
+ }
482
+ if (diff.changedComponents.length > 0) {
483
+ lines.push(`Changed components (${diff.changedComponents.length}):`);
484
+ for (const change of diff.changedComponents) {
485
+ lines.push(` ${change.name}:`);
486
+ for (const added of change.addedProps) {
487
+ const tag = added.required ? ' [BREAKING — required]' : '';
488
+ lines.push(` + prop '${added.name}': ${describeType(added.type)}${tag}`);
489
+ }
490
+ for (const removed of change.removedProps) {
491
+ lines.push(` - prop '${removed.name}': [BREAKING — removed]`);
492
+ }
493
+ for (const propChange of change.changedProps) {
494
+ const tag = propChange.severity === 'breaking' ? ' [BREAKING]' : '';
495
+ lines.push(` ~ prop '${propChange.name}': ${propChange.reason}${tag}`);
496
+ }
497
+ }
498
+ lines.push('');
499
+ }
500
+ return lines.join('\n').trimEnd() + '\n';
501
+ }
502
+ function describeType(type) {
503
+ switch (type.kind) {
504
+ case 'string':
505
+ case 'number':
506
+ case 'boolean':
507
+ return type.kind;
508
+ case 'literal':
509
+ return JSON.stringify(type.value);
510
+ case 'enum':
511
+ return `enum(${type.values.map((v) => JSON.stringify(v)).join(', ')})`;
512
+ case 'array':
513
+ return `array<${describeType(type.itemType)}>`;
514
+ case 'object':
515
+ return `object{${type.fields.map((f) => f.name).join(', ')}}`;
516
+ case 'union':
517
+ return `union(${type.types.map(describeType).join(' | ')})`;
518
+ case 'reference':
519
+ return `ref<${type.targetType}>`;
520
+ case 'unknown':
521
+ return 'unknown';
522
+ }
523
+ }
524
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,WAAqB,EAAE,WAAqB;IACxE,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,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C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;QAC/D,KAAK,OAAO;YACV,OAAO,SAAS,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAA;QAC7D,KAAK,WAAW;YACd,OAAO,OAAO,IAAI,CAAC,UAAU,GAAG,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Discriminated-union detection for component prop types.
3
+ *
4
+ * A discriminated union (aka tagged / sum type) is the TypeScript idiom
5
+ * for "this prop is one of N shapes, distinguished by a literal tag
6
+ * field":
7
+ *
8
+ * type CTA =
9
+ * | { kind: 'link'; href: string; label: string }
10
+ * | { kind: 'modal'; modalId: string; label: string }
11
+ *
12
+ * The extractor turns this into a `{ kind: 'union', types: [...] }`
13
+ * `PropType` with two `object` variants. Without further analysis,
14
+ * the admin form has to fall back to a JSON textarea — the editor has
15
+ * to type the JSON correctly, including the discriminator. With
16
+ * detection, we can render a `<select>` for the tag and a recursive
17
+ * object form for the chosen variant's remaining fields.
18
+ *
19
+ * The detection rule is intentionally strict:
20
+ *
21
+ * 1. Every variant must be an `object` `PropType`.
22
+ * 2. There must exist a single field name common to every variant
23
+ * whose type on every variant is a `literal` of the same
24
+ * primitive flavour (string / number / boolean).
25
+ * 3. The literal values must be pairwise distinct (otherwise it isn't
26
+ * a meaningful discriminator).
27
+ * 4. The discriminator field must be required on every variant.
28
+ *
29
+ * If any rule fails, the helper returns `null` and the caller falls
30
+ * back to the JSON textarea (preserving the prior behaviour exactly).
31
+ *
32
+ * Why a separate module: the same detection is useful in three places
33
+ * — the admin form (picker), the migrator (variant transitions), and
34
+ * future diff output (variant gained / removed). Keeping it pure +
35
+ * dependency-free here keeps every consumer in sync.
36
+ */
37
+ import type { PropSpec, PropType } from './types.js';
38
+ /**
39
+ * The literal field that distinguishes one variant from another. The
40
+ * primitive type matches `PropType['literal']['value']`.
41
+ */
42
+ export type DiscriminatorValue = string | number | boolean;
43
+ /**
44
+ * One branch of a detected discriminated union. The discriminator
45
+ * field has been pulled out so the admin form can render it as a
46
+ * dedicated picker; the remaining fields render as a normal recursive
47
+ * object form.
48
+ */
49
+ export interface DiscriminatedVariant {
50
+ /** The literal value identifying this variant (e.g. `'link'`). */
51
+ value: DiscriminatorValue;
52
+ /** The full object PropType for the variant (including the discriminator). */
53
+ type: Extract<PropType, {
54
+ kind: 'object';
55
+ }>;
56
+ /** Fields excluding the discriminator — what the recursive form renders. */
57
+ remainingFields: PropSpec[];
58
+ }
59
+ /**
60
+ * Result of a successful discriminator detection.
61
+ */
62
+ export interface DiscriminatedUnion {
63
+ /** The literal name of the discriminating field (e.g. `'kind'`). */
64
+ field: string;
65
+ /** The primitive flavour of the discriminator values. */
66
+ kind: 'string' | 'number' | 'boolean';
67
+ /** The ordered list of variants (input order preserved). */
68
+ variants: DiscriminatedVariant[];
69
+ }
70
+ /**
71
+ * Inspect a union PropType. Returns the detected discriminator + per-
72
+ * variant breakdown, or `null` if the union doesn't satisfy the rules
73
+ * documented at the top of this file.
74
+ *
75
+ * Idempotent and side-effect free — safe to call once per render.
76
+ */
77
+ export declare function detectDiscriminator(union: PropType): DiscriminatedUnion | null;
78
+ /**
79
+ * Convenience: given a value (typically `{ kind: 'link', ... }`) and a
80
+ * detected union, locate the variant whose discriminator value matches.
81
+ * Returns `null` when the value isn't an object, the discriminator
82
+ * field is missing, or no variant matches.
83
+ *
84
+ * Used by the admin form to keep the picker in sync with the stored
85
+ * value, and by the validator + migrator to route deeper checks into
86
+ * the correct variant's schema.
87
+ */
88
+ export declare function findVariant(value: unknown, union: DiscriminatedUnion): DiscriminatedVariant | null;
89
+ //# sourceMappingURL=discriminated-union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminated-union.d.ts","sourceRoot":"","sources":["../src/discriminated-union.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEpD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,KAAK,EAAE,kBAAkB,CAAA;IACzB,8EAA8E;IAC9E,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAA;IAC3C,4EAA4E;IAC5E,eAAe,EAAE,QAAQ,EAAE,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IACrC,4DAA4D;IAC5D,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,GAAG,kBAAkB,GAAG,IAAI,CAuB9E;AA0CD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,kBAAkB,GACxB,oBAAoB,GAAG,IAAI,CAQ7B"}