@algomotion/spec 0.0.0-stage → 1.0.0-alpha.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.
- package/LICENSE +675 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/common.d.ts +136 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +181 -0
- package/dist/common.js.map +1 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +3 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +16 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/kinds/array.d.ts +171 -0
- package/dist/kinds/array.d.ts.map +1 -0
- package/dist/kinds/array.js +179 -0
- package/dist/kinds/array.js.map +1 -0
- package/dist/kinds/btree.d.ts +190 -0
- package/dist/kinds/btree.d.ts.map +1 -0
- package/dist/kinds/btree.js +274 -0
- package/dist/kinds/btree.js.map +1 -0
- package/dist/kinds/graph.d.ts +227 -0
- package/dist/kinds/graph.d.ts.map +1 -0
- package/dist/kinds/graph.js +229 -0
- package/dist/kinds/graph.js.map +1 -0
- package/dist/kinds/hash-table.d.ts +108 -0
- package/dist/kinds/hash-table.d.ts.map +1 -0
- package/dist/kinds/hash-table.js +133 -0
- package/dist/kinds/hash-table.js.map +1 -0
- package/dist/kinds/index.d.ts +98 -0
- package/dist/kinds/index.d.ts.map +1 -0
- package/dist/kinds/index.js +53 -0
- package/dist/kinds/index.js.map +1 -0
- package/dist/kinds/kind.d.ts +73 -0
- package/dist/kinds/kind.d.ts.map +1 -0
- package/dist/kinds/kind.js +4 -0
- package/dist/kinds/kind.js.map +1 -0
- package/dist/kinds/linear.d.ts +24 -0
- package/dist/kinds/linear.d.ts.map +1 -0
- package/dist/kinds/linear.js +26 -0
- package/dist/kinds/linear.js.map +1 -0
- package/dist/kinds/linked-list.d.ts +132 -0
- package/dist/kinds/linked-list.d.ts.map +1 -0
- package/dist/kinds/linked-list.js +95 -0
- package/dist/kinds/linked-list.js.map +1 -0
- package/dist/kinds/plane.d.ts +190 -0
- package/dist/kinds/plane.d.ts.map +1 -0
- package/dist/kinds/plane.js +206 -0
- package/dist/kinds/plane.js.map +1 -0
- package/dist/kinds/priority-queue.d.ts +120 -0
- package/dist/kinds/priority-queue.d.ts.map +1 -0
- package/dist/kinds/priority-queue.js +108 -0
- package/dist/kinds/priority-queue.js.map +1 -0
- package/dist/kinds/queue.d.ts +94 -0
- package/dist/kinds/queue.d.ts.map +1 -0
- package/dist/kinds/queue.js +59 -0
- package/dist/kinds/queue.js.map +1 -0
- package/dist/kinds/stack.d.ts +70 -0
- package/dist/kinds/stack.d.ts.map +1 -0
- package/dist/kinds/stack.js +50 -0
- package/dist/kinds/stack.js.map +1 -0
- package/dist/kinds/table.d.ts +65 -0
- package/dist/kinds/table.d.ts.map +1 -0
- package/dist/kinds/table.js +116 -0
- package/dist/kinds/table.js.map +1 -0
- package/dist/kinds/tree.d.ts +272 -0
- package/dist/kinds/tree.d.ts.map +1 -0
- package/dist/kinds/tree.js +380 -0
- package/dist/kinds/tree.js.map +1 -0
- package/dist/parse.d.ts +26 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +380 -0
- package/dist/parse.js.map +1 -0
- package/dist/result.d.ts +16 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +3 -0
- package/dist/result.js.map +1 -0
- package/dist/share.d.ts +68 -0
- package/dist/share.d.ts.map +1 -0
- package/dist/share.js +319 -0
- package/dist/share.js.map +1 -0
- package/dist/version.d.ts +108 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +167 -0
- package/dist/version.js.map +1 -0
- package/dist/visualization.d.ts +3591 -0
- package/dist/visualization.d.ts.map +1 -0
- package/dist/visualization.js +131 -0
- package/dist/visualization.js.map +1 -0
- package/package.json +45 -4
- package/schema/visualization.schema.json +5717 -0
- package/README.md +0 -3
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `tree` kind: rooted trees and forests. Nodes have ordered child
|
|
3
|
+
* slots; a slot may be empty (null), which binary trees use to tell a lone
|
|
4
|
+
* right child from a left one.
|
|
5
|
+
*
|
|
6
|
+
* Covers binary search trees (with rotations and red–black colours),
|
|
7
|
+
* n-ary trees, tries, recursion trees and union–find forests.
|
|
8
|
+
*
|
|
9
|
+
* Marks: `highlight` and `compare` last one step; `visit`, `settle`,
|
|
10
|
+
* `group`, `pointer`, `annotate`, `markEdge` and `labelEdge` persist.
|
|
11
|
+
*
|
|
12
|
+
* Protocol 0.5 (ADR 0034) adds root slots, pointers at empty child slots
|
|
13
|
+
* (NIL), named notes, edge marks and labels, and root lists.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { ElementId, Group, isElement, LIMITS, Place, PointerName, Scalar, } from "../common.js";
|
|
17
|
+
import { typesOf } from "./kind.js";
|
|
18
|
+
const Color = z.enum(['red', 'black']).describe('Red–black tree colour.');
|
|
19
|
+
export const TreeNode = z
|
|
20
|
+
.strictObject({
|
|
21
|
+
id: ElementId,
|
|
22
|
+
value: Scalar,
|
|
23
|
+
children: z
|
|
24
|
+
.array(ElementId.nullable())
|
|
25
|
+
.max(LIMITS.elementsPerStructure)
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('Child ids in order; null leaves a slot empty (e.g. no left child).'),
|
|
28
|
+
color: Color.optional(),
|
|
29
|
+
})
|
|
30
|
+
.describe('A tree node.');
|
|
31
|
+
const Nodes = z.array(TreeNode).max(LIMITS.elementsPerStructure);
|
|
32
|
+
const RootList = z
|
|
33
|
+
.enum(['list', 'circular'])
|
|
34
|
+
.describe('Join the roots in order, as a Fibonacci heap’s root list; "circular" also joins the last root to the first.');
|
|
35
|
+
/** Canonical declaration. */
|
|
36
|
+
export const TreeDecl = z
|
|
37
|
+
.strictObject({
|
|
38
|
+
kind: z.literal('tree'),
|
|
39
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
40
|
+
place: Place.optional(),
|
|
41
|
+
binary: z
|
|
42
|
+
.boolean()
|
|
43
|
+
.describe('Binary trees have exactly two child slots per node: 0 = left, 1 = right.'),
|
|
44
|
+
nodes: Nodes,
|
|
45
|
+
roots: z.array(ElementId).describe('Root ids, left to right.'),
|
|
46
|
+
rootList: RootList.optional(),
|
|
47
|
+
})
|
|
48
|
+
.describe('A rooted tree or forest.');
|
|
49
|
+
export const TreeDeclInput = z
|
|
50
|
+
.strictObject({
|
|
51
|
+
kind: z.literal('tree'),
|
|
52
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
53
|
+
place: Place.optional(),
|
|
54
|
+
binary: z
|
|
55
|
+
.boolean()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('Default false, or true with `levelOrder`.'),
|
|
58
|
+
nodes: Nodes.optional(),
|
|
59
|
+
roots: z
|
|
60
|
+
.array(ElementId)
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('Root ids; by default every node that is nobody’s child, in order.'),
|
|
63
|
+
rootList: RootList.optional(),
|
|
64
|
+
levelOrder: z
|
|
65
|
+
.array(Scalar)
|
|
66
|
+
.max(LIMITS.elementsPerStructure)
|
|
67
|
+
.optional()
|
|
68
|
+
.describe('Binary tree in level order as on LeetCode, null for missing nodes, e.g. [3, 9, 20, null, null, 15, 7]. Node ids are e0, e1, … in order. Use instead of `nodes`.'),
|
|
69
|
+
})
|
|
70
|
+
.refine((d) => d.nodes === undefined || d.levelOrder === undefined, {
|
|
71
|
+
message: 'Give either `nodes` or `levelOrder`, not both',
|
|
72
|
+
path: ['levelOrder'],
|
|
73
|
+
})
|
|
74
|
+
.superRefine((d, ctx) => {
|
|
75
|
+
if (d.levelOrder === undefined)
|
|
76
|
+
return;
|
|
77
|
+
const { consumed } = fromLevelOrder(d.levelOrder);
|
|
78
|
+
const orphan = d.levelOrder.findIndex((v, k) => k >= consumed && v !== null);
|
|
79
|
+
if (orphan >= 0)
|
|
80
|
+
ctx.addIssue({
|
|
81
|
+
code: 'custom',
|
|
82
|
+
path: ['levelOrder', orphan],
|
|
83
|
+
message: `Value ${JSON.stringify(d.levelOrder[orphan])} has no parent: every slot before it is taken or empty`,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
/** Builds a binary tree from LeetCode-style level order. */
|
|
87
|
+
function fromLevelOrder(values) {
|
|
88
|
+
const nodes = [];
|
|
89
|
+
const first = values[0];
|
|
90
|
+
if (values.length === 0 || first === null || first === undefined)
|
|
91
|
+
return { nodes, roots: [], consumed: Math.min(1, values.length) };
|
|
92
|
+
const queue = [];
|
|
93
|
+
const make = (value) => {
|
|
94
|
+
const node = {
|
|
95
|
+
id: `e${nodes.length}`,
|
|
96
|
+
value,
|
|
97
|
+
children: [null, null],
|
|
98
|
+
};
|
|
99
|
+
nodes.push(node);
|
|
100
|
+
queue.push(node);
|
|
101
|
+
return node.id;
|
|
102
|
+
};
|
|
103
|
+
make(first);
|
|
104
|
+
let k = 1;
|
|
105
|
+
while (queue.length > 0 && k < values.length) {
|
|
106
|
+
const parent = queue.shift();
|
|
107
|
+
for (const slot of [0, 1]) {
|
|
108
|
+
if (k >= values.length)
|
|
109
|
+
break;
|
|
110
|
+
const value = values[k++];
|
|
111
|
+
if (value !== null)
|
|
112
|
+
parent.children[slot] = make(value);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { nodes, roots: ['e0'], consumed: k };
|
|
116
|
+
}
|
|
117
|
+
function normalizeTreeDecl(input) {
|
|
118
|
+
const { levelOrder, nodes: given, roots: givenRoots, binary, ...rest } = input;
|
|
119
|
+
if (levelOrder !== undefined) {
|
|
120
|
+
const { nodes, roots } = fromLevelOrder(levelOrder);
|
|
121
|
+
return { ...rest, binary: true, nodes, roots };
|
|
122
|
+
}
|
|
123
|
+
const nodes = given ?? [];
|
|
124
|
+
const isBinary = binary ?? false;
|
|
125
|
+
const children = new Set(nodes.flatMap((n) => n.children ?? []).filter((c) => c !== null));
|
|
126
|
+
const roots = givenRoots ?? nodes.filter((n) => !children.has(n.id)).map((n) => n.id);
|
|
127
|
+
// Binary nodes get both slots; extra children are kept so that
|
|
128
|
+
// validation can report them.
|
|
129
|
+
const normalized = isBinary
|
|
130
|
+
? nodes.map((n) => ({
|
|
131
|
+
...n,
|
|
132
|
+
children: [
|
|
133
|
+
n.children?.[0] ?? null,
|
|
134
|
+
n.children?.[1] ?? null,
|
|
135
|
+
...(n.children?.slice(2) ?? []),
|
|
136
|
+
],
|
|
137
|
+
}))
|
|
138
|
+
: nodes;
|
|
139
|
+
return { ...rest, binary: isBinary, nodes: normalized, roots };
|
|
140
|
+
}
|
|
141
|
+
/** Rules a schema cannot express: references exist, one parent each, no cycles. */
|
|
142
|
+
export function validateTreeDecl(decl) {
|
|
143
|
+
const issues = [];
|
|
144
|
+
const index = new Map(decl.nodes.map((n, k) => [n.id, k]));
|
|
145
|
+
const parent = new Map();
|
|
146
|
+
decl.nodes.forEach((node, k) => {
|
|
147
|
+
const children = node.children ?? [];
|
|
148
|
+
if (decl.binary && children.length > 2)
|
|
149
|
+
issues.push({
|
|
150
|
+
path: ['nodes', k, 'children'],
|
|
151
|
+
message: `Node "${node.id}" has more than two child slots in a binary tree`,
|
|
152
|
+
});
|
|
153
|
+
children.forEach((child, c) => {
|
|
154
|
+
if (child === null)
|
|
155
|
+
return;
|
|
156
|
+
const path = ['nodes', k, 'children', c];
|
|
157
|
+
if (!index.has(child))
|
|
158
|
+
issues.push({
|
|
159
|
+
path,
|
|
160
|
+
message: `Child "${child}" is not a node of this tree`,
|
|
161
|
+
});
|
|
162
|
+
else if (parent.has(child))
|
|
163
|
+
issues.push({
|
|
164
|
+
path,
|
|
165
|
+
message: `Node "${child}" has two parents ("${parent.get(child)}" and "${node.id}")`,
|
|
166
|
+
});
|
|
167
|
+
else
|
|
168
|
+
parent.set(child, node.id);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
decl.roots.forEach((root, r) => {
|
|
172
|
+
if (decl.roots.indexOf(root) !== r)
|
|
173
|
+
issues.push({
|
|
174
|
+
path: ['roots', r],
|
|
175
|
+
message: `Root "${root}" is listed twice`,
|
|
176
|
+
});
|
|
177
|
+
else if (!index.has(root))
|
|
178
|
+
issues.push({
|
|
179
|
+
path: ['roots', r],
|
|
180
|
+
message: `Root "${root}" is not a node of this tree`,
|
|
181
|
+
});
|
|
182
|
+
else if (parent.has(root))
|
|
183
|
+
issues.push({
|
|
184
|
+
path: ['roots', r],
|
|
185
|
+
message: `Root "${root}" is also the child of "${parent.get(root)}"`,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
// Every node must be reachable from a root exactly once (no cycles).
|
|
189
|
+
const seen = new Set();
|
|
190
|
+
const stack = [...decl.roots].filter((r) => index.has(r));
|
|
191
|
+
while (stack.length > 0) {
|
|
192
|
+
const id = stack.pop();
|
|
193
|
+
if (seen.has(id))
|
|
194
|
+
continue;
|
|
195
|
+
seen.add(id);
|
|
196
|
+
for (const child of decl.nodes[index.get(id)].children ?? [])
|
|
197
|
+
// Missing children are reported above.
|
|
198
|
+
if (child !== null && index.has(child))
|
|
199
|
+
stack.push(child);
|
|
200
|
+
}
|
|
201
|
+
decl.nodes.forEach((node, k) => {
|
|
202
|
+
if (!seen.has(node.id))
|
|
203
|
+
issues.push({
|
|
204
|
+
path: ['nodes', k],
|
|
205
|
+
message: `Node "${node.id}" is not reachable from a root (it is in a cycle or its root is missing)`,
|
|
206
|
+
hint: 'List every root in `roots`, or omit `roots` to use all parentless nodes.',
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
return issues;
|
|
210
|
+
}
|
|
211
|
+
const NodeRef = ElementId.describe('A node id.');
|
|
212
|
+
const Slot = z.int().min(0).max(LIMITS.elementsPerStructure);
|
|
213
|
+
const SlotInput = z
|
|
214
|
+
.union([Slot, z.enum(['left', 'right'])])
|
|
215
|
+
.describe('A child position; binary trees also accept "left" (0) and "right" (1).');
|
|
216
|
+
const RootSlot = Slot.describe('A position among the roots, from 0.');
|
|
217
|
+
/** An empty child slot of a binary tree: the NIL leaf there. */
|
|
218
|
+
const nilSlot = (slotType) => z
|
|
219
|
+
.strictObject({ parent: NodeRef, slot: slotType })
|
|
220
|
+
.describe('The empty child slot `slot` of `parent`: the NIL leaf there.');
|
|
221
|
+
/** A named note's field, such as `size`, `max`, `deg` or `mark`. */
|
|
222
|
+
export const NoteField = z
|
|
223
|
+
.string()
|
|
224
|
+
.max(16)
|
|
225
|
+
.regex(/^[a-z][a-z0-9-]*$/, 'Use lower-case letters, digits and hyphens, starting with a letter')
|
|
226
|
+
.describe('The field a note shows, e.g. "size"; a node holds one note per field.');
|
|
227
|
+
const EdgeLabel = z
|
|
228
|
+
.union([z.string().max(16), z.number()])
|
|
229
|
+
.describe('A short label beside the edge, e.g. a code bit "0".');
|
|
230
|
+
const actions = (newNode, slotType) => {
|
|
231
|
+
const slot = { slot: slotType.optional() };
|
|
232
|
+
return z.discriminatedUnion('type', [
|
|
233
|
+
z
|
|
234
|
+
.strictObject({
|
|
235
|
+
type: z.literal('addNode'),
|
|
236
|
+
node: newNode,
|
|
237
|
+
parent: NodeRef.nullable(),
|
|
238
|
+
...slot,
|
|
239
|
+
})
|
|
240
|
+
.describe('Add a node under `parent`. Binary trees: `slot` is "left" or "right" (default the first empty one) and must be empty. Other trees: inserts at `slot`, default appends. With `parent: null` the node is a new root, at position `slot` among the roots (default last).'),
|
|
241
|
+
z
|
|
242
|
+
.strictObject({ type: z.literal('removeNode'), node: NodeRef })
|
|
243
|
+
.describe('Remove a node together with its subtree.'),
|
|
244
|
+
z
|
|
245
|
+
.strictObject({
|
|
246
|
+
type: z.literal('setChild'),
|
|
247
|
+
parent: NodeRef,
|
|
248
|
+
child: NodeRef.nullable(),
|
|
249
|
+
...slot,
|
|
250
|
+
})
|
|
251
|
+
.describe('Move `child` (with its subtree) under `parent`, detaching it from where it was. Binary trees: `slot` is required and any child already there becomes a separate root. Other trees: inserts at `slot`, default appends. With `child: null`, removes the child at `slot` from `parent`; it becomes a separate root.'),
|
|
252
|
+
z
|
|
253
|
+
.strictObject({
|
|
254
|
+
type: z.literal('detach'),
|
|
255
|
+
node: NodeRef,
|
|
256
|
+
slot: RootSlot.optional(),
|
|
257
|
+
})
|
|
258
|
+
.describe('Detach a subtree from its parent so it becomes a separate root, at position `slot` among the roots (default last). A root with a `slot` moves there.'),
|
|
259
|
+
z
|
|
260
|
+
.strictObject({
|
|
261
|
+
type: z.literal('rotate'),
|
|
262
|
+
node: NodeRef,
|
|
263
|
+
direction: z.enum(['left', 'right']),
|
|
264
|
+
})
|
|
265
|
+
.describe('Binary trees: rotate around `node` (left rotation lifts its right child).'),
|
|
266
|
+
z
|
|
267
|
+
.strictObject({
|
|
268
|
+
type: z.literal('setValue'),
|
|
269
|
+
node: NodeRef,
|
|
270
|
+
value: Scalar,
|
|
271
|
+
})
|
|
272
|
+
.describe('Change a value.'),
|
|
273
|
+
z
|
|
274
|
+
.strictObject({ type: z.literal('swapValues'), a: NodeRef, b: NodeRef })
|
|
275
|
+
.describe('Exchange the values of two nodes (as in heapify on a tree).'),
|
|
276
|
+
z
|
|
277
|
+
.strictObject({
|
|
278
|
+
type: z.literal('setColor'),
|
|
279
|
+
node: NodeRef,
|
|
280
|
+
color: Color.nullable(),
|
|
281
|
+
})
|
|
282
|
+
.describe('Set a red–black colour; null removes it.'),
|
|
283
|
+
z
|
|
284
|
+
.strictObject({
|
|
285
|
+
type: z.literal('highlight'),
|
|
286
|
+
nodes: z.array(NodeRef).min(1).max(LIMITS.elementsPerStructure),
|
|
287
|
+
})
|
|
288
|
+
.describe('Highlight nodes (this step only).'),
|
|
289
|
+
z
|
|
290
|
+
.strictObject({ type: z.literal('compare'), a: NodeRef, b: NodeRef })
|
|
291
|
+
.describe('Mark two nodes as being compared (this step only).'),
|
|
292
|
+
z
|
|
293
|
+
.strictObject({ type: z.literal('visit'), node: NodeRef })
|
|
294
|
+
.describe('Mark a node as visited (persists).'),
|
|
295
|
+
z
|
|
296
|
+
.strictObject({ type: z.literal('settle'), node: NodeRef })
|
|
297
|
+
.describe('Mark a node as final or found (persists).'),
|
|
298
|
+
z
|
|
299
|
+
.strictObject({ type: z.literal('group'), node: NodeRef, group: Group })
|
|
300
|
+
.describe('Put a node in a categorical group 0–5; null removes it.'),
|
|
301
|
+
z
|
|
302
|
+
.strictObject({
|
|
303
|
+
type: z.literal('pointer'),
|
|
304
|
+
name: PointerName,
|
|
305
|
+
node: z.union([NodeRef, nilSlot(slotType)]).nullable(),
|
|
306
|
+
})
|
|
307
|
+
.describe('Point a named pointer (e.g. "curr") at a node, or at an empty child slot `{ "parent", "slot" }` of a binary tree (NIL); null removes it.'),
|
|
308
|
+
z
|
|
309
|
+
.strictObject({
|
|
310
|
+
type: z.literal('annotate'),
|
|
311
|
+
node: NodeRef,
|
|
312
|
+
text: z.string().max(32).nullable(),
|
|
313
|
+
field: NoteField.optional(),
|
|
314
|
+
})
|
|
315
|
+
.describe('Show a short note beside a node, e.g. its height or balance factor; null removes it. With `field`, the note is one of several the node shows, e.g. "size" and "max".'),
|
|
316
|
+
z
|
|
317
|
+
.strictObject({
|
|
318
|
+
type: z.literal('markEdge'),
|
|
319
|
+
node: NodeRef,
|
|
320
|
+
mark: z.enum(['selected', 'rejected']).nullable(),
|
|
321
|
+
})
|
|
322
|
+
.describe('Mark the edge from `node`’s parent to `node`: selected (e.g. a search path) or rejected; null clears it. Persists while the edge does.'),
|
|
323
|
+
z
|
|
324
|
+
.strictObject({
|
|
325
|
+
type: z.literal('labelEdge'),
|
|
326
|
+
node: NodeRef,
|
|
327
|
+
label: EdgeLabel.nullable(),
|
|
328
|
+
})
|
|
329
|
+
.describe('Label the edge from `node`’s parent to `node`, e.g. "0" or "1" in a Huffman tree; null removes it. Persists while the edge does.'),
|
|
330
|
+
]);
|
|
331
|
+
};
|
|
332
|
+
const NewNode = z.strictObject({
|
|
333
|
+
id: ElementId,
|
|
334
|
+
value: Scalar,
|
|
335
|
+
color: Color.optional(),
|
|
336
|
+
});
|
|
337
|
+
const NewNodeInput = z
|
|
338
|
+
.union([NewNode, Scalar])
|
|
339
|
+
.describe('`{ "id", "value", "color"? }`, or a bare value to get a generated id.');
|
|
340
|
+
export const TreeAction = actions(NewNode, Slot);
|
|
341
|
+
export const TreeActionInput = actions(NewNodeInput, SlotInput);
|
|
342
|
+
const slotNumber = (slot) => (slot === 'left' ? 0 : 1);
|
|
343
|
+
export const treeSpec = {
|
|
344
|
+
kind: 'tree',
|
|
345
|
+
decl: TreeDecl,
|
|
346
|
+
declInput: TreeDeclInput,
|
|
347
|
+
action: TreeAction,
|
|
348
|
+
actionInput: TreeActionInput,
|
|
349
|
+
actionTypes: typesOf(TreeAction),
|
|
350
|
+
normalizeDecl: normalizeTreeDecl,
|
|
351
|
+
declIds: (decl) => decl.nodes.map((n, k) => ({ id: n.id, path: ['nodes', k, 'id'] })),
|
|
352
|
+
validateDecl: validateTreeDecl,
|
|
353
|
+
normalizeAction: (input, ctx) => {
|
|
354
|
+
let action = { ...input };
|
|
355
|
+
// A root's slot is a position among the roots, so "left" and "right"
|
|
356
|
+
// stay as written there, and the canonical schema refuses them.
|
|
357
|
+
if ('slot' in input &&
|
|
358
|
+
typeof input.slot === 'string' &&
|
|
359
|
+
!(input.type === 'addNode' && input.parent === null))
|
|
360
|
+
action = { ...action, slot: slotNumber(input.slot) };
|
|
361
|
+
if (input.type === 'pointer' &&
|
|
362
|
+
typeof input.node === 'object' &&
|
|
363
|
+
input.node !== null &&
|
|
364
|
+
typeof input.node.slot === 'string')
|
|
365
|
+
action = {
|
|
366
|
+
...action,
|
|
367
|
+
node: { ...input.node, slot: slotNumber(input.node.slot) },
|
|
368
|
+
};
|
|
369
|
+
if (input.type === 'addNode' && !isElement(input.node))
|
|
370
|
+
action = {
|
|
371
|
+
...action,
|
|
372
|
+
node: { id: ctx.allocateId('e'), value: input.node },
|
|
373
|
+
};
|
|
374
|
+
return action;
|
|
375
|
+
},
|
|
376
|
+
introducedIds: (action) => action.type === 'addNode'
|
|
377
|
+
? [{ id: action.node.id, path: ['node', 'id'] }]
|
|
378
|
+
: [],
|
|
379
|
+
};
|
|
380
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/kinds/tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,SAAS,EACT,KAAK,EACL,SAAS,EACT,MAAM,EACN,KAAK,EACL,WAAW,EACX,MAAM,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAA6C,MAAM,WAAW,CAAC;AAE/E,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC;KACtB,YAAY,CAAC;IACZ,EAAE,EAAE,SAAS;IACb,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,CAAC;SACR,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;SAC3B,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC;SAChC,QAAQ,EAAE;SACV,QAAQ,CACP,oEAAoE,CACrE;IACH,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;CACxB,CAAC;KACD,QAAQ,CAAC,cAAc,CAAC,CAAC;AAG5B,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAEjE,MAAM,QAAQ,GAAG,CAAC;KACf,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;K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,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;YACpD,MAAM,GAAG;gBACP,GAAG,MAAM;gBACT,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE;aACrD,CAAC;QACJ,OAAO,MAAoB,CAAC;IAC9B,CAAC;IACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACxB,MAAM,CAAC,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QAChD,CAAC,CAAC,EAAE;CACT,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsing pipeline: untrusted input → canonical `Visualization`.
|
|
3
|
+
*
|
|
4
|
+
* 1. Reject versions this package cannot read with a dedicated error
|
|
5
|
+
* (ADR 0021).
|
|
6
|
+
* 2. Check the document's shape (actions only by `target` and `type`).
|
|
7
|
+
* 3. Expand shorthands in structure declarations.
|
|
8
|
+
* 4. Validate each action against the schema of its target's kind, expand
|
|
9
|
+
* its shorthands, and check that ids it introduces are new.
|
|
10
|
+
* 5. Check that steps point into the source code: `meta.line` into
|
|
11
|
+
* `source`, or `meta.at` at an anchor of every entry of `sources`
|
|
12
|
+
* (ADR 0017).
|
|
13
|
+
* 6. Check sections against the steps (ADR 0020), and that `version` holds
|
|
14
|
+
* every feature the document uses (ADR 0021).
|
|
15
|
+
*
|
|
16
|
+
* Every kind-specific step goes through the kind registry (ADR 0012).
|
|
17
|
+
*
|
|
18
|
+
* Only static validity is checked here. Whether an action is valid at its
|
|
19
|
+
* point in the timeline (e.g. an index within the current length) depends
|
|
20
|
+
* on state and is checked by the core reducer.
|
|
21
|
+
*/
|
|
22
|
+
import { type ProtocolError } from './errors.ts';
|
|
23
|
+
import { type Result } from './result.ts';
|
|
24
|
+
import { type Visualization } from './visualization.ts';
|
|
25
|
+
export declare function parseVisualization(input: unknown): Result<Visualization, readonly ProtocolError[]>;
|
|
26
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,aAAa,EAAE,SAAS,aAAa,EAAE,CAAC,CAIjD"}
|