@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.
Files changed (97) hide show
  1. package/LICENSE +675 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/common.d.ts +136 -0
  4. package/dist/common.d.ts.map +1 -0
  5. package/dist/common.js +181 -0
  6. package/dist/common.js.map +1 -0
  7. package/dist/errors.d.ts +71 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +43 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/json-schema.d.ts +3 -0
  16. package/dist/json-schema.d.ts.map +1 -0
  17. package/dist/json-schema.js +16 -0
  18. package/dist/json-schema.js.map +1 -0
  19. package/dist/kinds/array.d.ts +171 -0
  20. package/dist/kinds/array.d.ts.map +1 -0
  21. package/dist/kinds/array.js +179 -0
  22. package/dist/kinds/array.js.map +1 -0
  23. package/dist/kinds/btree.d.ts +190 -0
  24. package/dist/kinds/btree.d.ts.map +1 -0
  25. package/dist/kinds/btree.js +274 -0
  26. package/dist/kinds/btree.js.map +1 -0
  27. package/dist/kinds/graph.d.ts +227 -0
  28. package/dist/kinds/graph.d.ts.map +1 -0
  29. package/dist/kinds/graph.js +229 -0
  30. package/dist/kinds/graph.js.map +1 -0
  31. package/dist/kinds/hash-table.d.ts +108 -0
  32. package/dist/kinds/hash-table.d.ts.map +1 -0
  33. package/dist/kinds/hash-table.js +133 -0
  34. package/dist/kinds/hash-table.js.map +1 -0
  35. package/dist/kinds/index.d.ts +98 -0
  36. package/dist/kinds/index.d.ts.map +1 -0
  37. package/dist/kinds/index.js +53 -0
  38. package/dist/kinds/index.js.map +1 -0
  39. package/dist/kinds/kind.d.ts +73 -0
  40. package/dist/kinds/kind.d.ts.map +1 -0
  41. package/dist/kinds/kind.js +4 -0
  42. package/dist/kinds/kind.js.map +1 -0
  43. package/dist/kinds/linear.d.ts +24 -0
  44. package/dist/kinds/linear.d.ts.map +1 -0
  45. package/dist/kinds/linear.js +26 -0
  46. package/dist/kinds/linear.js.map +1 -0
  47. package/dist/kinds/linked-list.d.ts +132 -0
  48. package/dist/kinds/linked-list.d.ts.map +1 -0
  49. package/dist/kinds/linked-list.js +95 -0
  50. package/dist/kinds/linked-list.js.map +1 -0
  51. package/dist/kinds/plane.d.ts +190 -0
  52. package/dist/kinds/plane.d.ts.map +1 -0
  53. package/dist/kinds/plane.js +206 -0
  54. package/dist/kinds/plane.js.map +1 -0
  55. package/dist/kinds/priority-queue.d.ts +120 -0
  56. package/dist/kinds/priority-queue.d.ts.map +1 -0
  57. package/dist/kinds/priority-queue.js +108 -0
  58. package/dist/kinds/priority-queue.js.map +1 -0
  59. package/dist/kinds/queue.d.ts +94 -0
  60. package/dist/kinds/queue.d.ts.map +1 -0
  61. package/dist/kinds/queue.js +59 -0
  62. package/dist/kinds/queue.js.map +1 -0
  63. package/dist/kinds/stack.d.ts +70 -0
  64. package/dist/kinds/stack.d.ts.map +1 -0
  65. package/dist/kinds/stack.js +50 -0
  66. package/dist/kinds/stack.js.map +1 -0
  67. package/dist/kinds/table.d.ts +65 -0
  68. package/dist/kinds/table.d.ts.map +1 -0
  69. package/dist/kinds/table.js +116 -0
  70. package/dist/kinds/table.js.map +1 -0
  71. package/dist/kinds/tree.d.ts +272 -0
  72. package/dist/kinds/tree.d.ts.map +1 -0
  73. package/dist/kinds/tree.js +380 -0
  74. package/dist/kinds/tree.js.map +1 -0
  75. package/dist/parse.d.ts +26 -0
  76. package/dist/parse.d.ts.map +1 -0
  77. package/dist/parse.js +380 -0
  78. package/dist/parse.js.map +1 -0
  79. package/dist/result.d.ts +16 -0
  80. package/dist/result.d.ts.map +1 -0
  81. package/dist/result.js +3 -0
  82. package/dist/result.js.map +1 -0
  83. package/dist/share.d.ts +68 -0
  84. package/dist/share.d.ts.map +1 -0
  85. package/dist/share.js +319 -0
  86. package/dist/share.js.map +1 -0
  87. package/dist/version.d.ts +108 -0
  88. package/dist/version.d.ts.map +1 -0
  89. package/dist/version.js +167 -0
  90. package/dist/version.js.map +1 -0
  91. package/dist/visualization.d.ts +3591 -0
  92. package/dist/visualization.d.ts.map +1 -0
  93. package/dist/visualization.js +131 -0
  94. package/dist/visualization.js.map +1 -0
  95. package/package.json +45 -4
  96. package/schema/visualization.schema.json +5717 -0
  97. package/README.md +0 -3
package/dist/parse.js ADDED
@@ -0,0 +1,380 @@
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 { formatPath, fromZodIssues, } from "./errors.js";
23
+ import { kinds, } from "./kinds/index.js";
24
+ import { err, ok } from "./result.js";
25
+ import { checkFeatures, checkVersion, upgradeDocument, listOf, PROTOCOL_FEATURES, } from "./version.js";
26
+ import { Envelope, } from "./visualization.js";
27
+ export function parseVisualization(input) {
28
+ const versionError = checkDocumentVersion(input);
29
+ if (versionError)
30
+ return err([versionError]);
31
+ return parseCurrent(upgradeDocument(input).document);
32
+ }
33
+ /** Parses a document of the current version. */
34
+ function parseCurrent(input) {
35
+ const protoErrors = checkProtoKeys(input);
36
+ if (protoErrors.length > 0)
37
+ return err(protoErrors);
38
+ const envelope = Envelope.safeParse(input);
39
+ if (!envelope.success)
40
+ return err(fromZodIssues(envelope.error.issues, [], 'INVALID_SHAPE'));
41
+ const doc = envelope.data;
42
+ const errors = checkSources(doc.source, doc.sources);
43
+ const structures = {};
44
+ // Ids are unique per structure for the whole trace (ADR 0007), so an id
45
+ // removed earlier cannot be reused by a later action.
46
+ const usedIds = new Map();
47
+ for (const [name, input] of Object.entries(doc.structures)) {
48
+ const decl = normalizeDecl(input);
49
+ structures[name] = decl;
50
+ const ids = new Set();
51
+ for (const { id, path } of declIds(decl)) {
52
+ if (ids.has(id))
53
+ errors.push(duplicateId(id, name, ['structures', name, ...path]));
54
+ ids.add(id);
55
+ }
56
+ for (const issue of validateDecl(decl))
57
+ errors.push({
58
+ code: 'INVALID_STRUCTURE',
59
+ path: formatPath(['structures', name, ...issue.path]),
60
+ message: issue.message,
61
+ ...(issue.hint === undefined ? {} : { hint: issue.hint }),
62
+ });
63
+ usedIds.set(name, ids);
64
+ }
65
+ const code = codeOf(doc.source, doc.sources);
66
+ const steps = doc.steps.map((step, s) => {
67
+ if (step.meta !== undefined)
68
+ errors.push(...checkStepCode(step.meta, ['steps', s, 'meta'], code));
69
+ const actions = step.actions.flatMap((raw, a) => {
70
+ const path = ['steps', s, 'actions', a];
71
+ const result = parseAction(raw, structures, usedIds, path);
72
+ if (!result.ok) {
73
+ errors.push(...result.error);
74
+ return [];
75
+ }
76
+ return [result.value];
77
+ });
78
+ return step.meta === undefined ? { actions } : { actions, meta: step.meta };
79
+ });
80
+ if (doc.sections !== undefined)
81
+ errors.push(...checkSections(doc.sections, steps.length));
82
+ const vis = {
83
+ version: doc.version,
84
+ ...(doc.title === undefined ? {} : { title: doc.title }),
85
+ ...(doc.source === undefined ? {} : { source: doc.source }),
86
+ ...(doc.sources === undefined ? {} : { sources: doc.sources }),
87
+ structures,
88
+ steps,
89
+ ...(doc.sections === undefined ? {} : { sections: doc.sections }),
90
+ };
91
+ // The version is the first thing to fix, so it is reported first.
92
+ const tooOld = checkFeatures(vis, doc.version, PROTOCOL_FEATURES);
93
+ if (tooOld !== undefined)
94
+ errors.unshift(tooOld);
95
+ return errors.length > 0 ? err(errors) : ok(vis);
96
+ }
97
+ const lineCount = (code) => code.split('\n').length;
98
+ /**
99
+ * Checks the source code itself: not both forms, one entry per language,
100
+ * and every anchor on a line of its code.
101
+ */
102
+ function checkSources(source, sources) {
103
+ if (sources === undefined)
104
+ return [];
105
+ const errors = [];
106
+ if (source !== undefined)
107
+ errors.push({
108
+ code: 'MIXED_SOURCES',
109
+ path: '$.sources',
110
+ message: 'The document gives both `source` and `sources`',
111
+ hint: 'Keep only `sources`, with the code of `source` as one of its languages, or only `source`.',
112
+ });
113
+ const languages = new Map();
114
+ sources.forEach(({ language, code, anchors }, k) => {
115
+ const first = languages.get(language);
116
+ if (first !== undefined)
117
+ errors.push({
118
+ code: 'DUPLICATE_LANGUAGE',
119
+ path: formatPath(['sources', k, 'language']),
120
+ message: `Language "${language}" is already used by sources[${first}]`,
121
+ hint: 'Give each language once in `sources`.',
122
+ });
123
+ else
124
+ languages.set(language, k);
125
+ const lines = lineCount(code);
126
+ for (const [name, line] of Object.entries(anchors))
127
+ if (line > lines)
128
+ errors.push({
129
+ code: 'LINE_OUT_OF_RANGE',
130
+ path: formatPath(['sources', k, 'anchors', name]),
131
+ message: `Anchor "${name}" is on line ${line}, past the end of the ${language} code`,
132
+ hint: `The ${language} code has ${lines} lines.`,
133
+ });
134
+ });
135
+ return errors;
136
+ }
137
+ function codeOf(source, sources) {
138
+ // With both, `checkSources` reports the mix once; steps are checked
139
+ // against `sources`, which is what a reader shows.
140
+ if (sources !== undefined)
141
+ return { form: 'sources', sources };
142
+ if (source !== undefined)
143
+ return { form: 'source', lines: lineCount(source.code) };
144
+ return { form: 'none' };
145
+ }
146
+ /** At most this many names in a hint. */
147
+ const HINT_NAMES = 12;
148
+ const quoted = (names) => names.length === 0
149
+ ? ''
150
+ : `${names
151
+ .slice(0, HINT_NAMES)
152
+ .map((n) => `"${n}"`)
153
+ .join(', ')}${names.length > HINT_NAMES ? ', …' : ''}`;
154
+ /** Checks a step's `meta.line` or `meta.at` against the document's code. */
155
+ function checkStepCode({ line, at }, path, code) {
156
+ const errors = [];
157
+ if (line !== undefined) {
158
+ if (code.form === 'sources')
159
+ errors.push({
160
+ code: 'MIXED_SOURCES',
161
+ path: formatPath([...path, 'line']),
162
+ message: '`meta.line` cannot be used with `sources`, whose languages put the step on different lines',
163
+ hint: "Name the step's point in the code in `meta.at`, and give its line in each source's `anchors`.",
164
+ });
165
+ else if (code.form === 'source' && line > code.lines)
166
+ errors.push({
167
+ code: 'LINE_OUT_OF_RANGE',
168
+ path: formatPath([...path, 'line']),
169
+ message: `Line ${line} is past the end of the source code`,
170
+ hint: `The source code has ${code.lines} lines.`,
171
+ });
172
+ }
173
+ if (at !== undefined) {
174
+ const error = anchorError(at, code);
175
+ if (error !== undefined)
176
+ errors.push({ ...error, path: formatPath([...path, 'at']) });
177
+ }
178
+ return errors;
179
+ }
180
+ function anchorError(at, code) {
181
+ if (code.form === 'source')
182
+ return {
183
+ code: 'MIXED_SOURCES',
184
+ message: `\`meta.at\` ("${at}") needs \`sources\`, but the document gives \`source\``,
185
+ hint: 'Replace `source` with `sources`: [{ "language", "code", "anchors" }], or point at a line with `meta.line`.',
186
+ };
187
+ if (code.form === 'none')
188
+ return {
189
+ code: 'UNKNOWN_ANCHOR',
190
+ message: `Anchor "${at}" needs code in \`sources\`, but the document has none`,
191
+ hint: 'Give the code in `sources`, each language with an `anchors` map, or remove `meta.at`.',
192
+ };
193
+ const missing = code.sources.filter((s) => !Object.hasOwn(s.anchors, at));
194
+ if (missing.length === 0)
195
+ return undefined;
196
+ // Anchors that every source has, which `meta.at` could name instead.
197
+ const shared = Object.keys(code.sources[0].anchors).filter((name) => code.sources.every((s) => Object.hasOwn(s.anchors, name)));
198
+ const languages = listOf(missing.map((s) => s.language));
199
+ return {
200
+ code: 'UNKNOWN_ANCHOR',
201
+ message: `Anchor "${at}" is not in the ${languages} source${missing.length > 1 ? 's' : ''}`,
202
+ hint: `Every source must map "${at}" to a line in \`anchors\`. ${shared.length === 0
203
+ ? 'No anchor is in every source yet.'
204
+ : `Anchors in every source: ${quoted(shared)}.`}`,
205
+ };
206
+ }
207
+ /**
208
+ * Sections start at a step, each after the one before, and have distinct
209
+ * ids. Starting after the previous one also keeps every section non-empty.
210
+ */
211
+ function checkSections(sections, stepCount) {
212
+ const errors = [];
213
+ const ids = new Set();
214
+ sections.forEach(({ id, start }, k) => {
215
+ if (ids.has(id))
216
+ errors.push({
217
+ code: 'DUPLICATE_SECTION',
218
+ path: formatPath(['sections', k, 'id']),
219
+ message: `Section id "${id}" is already used`,
220
+ hint: 'Section ids must be unique within a document.',
221
+ });
222
+ ids.add(id);
223
+ const previous = sections[k - 1];
224
+ if (start >= stepCount)
225
+ errors.push({
226
+ code: 'SECTION_OUT_OF_RANGE',
227
+ path: formatPath(['sections', k, 'start']),
228
+ message: `Section "${id}" starts at step ${start}, past the last step`,
229
+ hint: stepCount === 0
230
+ ? 'The document has no steps, so it can have no sections.'
231
+ : `Steps are numbered 0 to ${stepCount - 1}.`,
232
+ });
233
+ else if (previous !== undefined && start <= previous.start)
234
+ errors.push({
235
+ code: 'SECTION_OUT_OF_ORDER',
236
+ path: formatPath(['sections', k, 'start']),
237
+ message: `Section "${id}" starts at step ${start}, but must start after section "${previous.id}" (step ${previous.start})`,
238
+ hint: 'List sections in the order of their steps; each has at least one step.',
239
+ });
240
+ });
241
+ return errors;
242
+ }
243
+ /** A missing `version` is left to the shape check, which reports it. */
244
+ function checkDocumentVersion(input) {
245
+ if (typeof input !== 'object' || input === null || !('version' in input))
246
+ return undefined;
247
+ return checkVersion(input.version);
248
+ }
249
+ const isRecord = (x) => typeof x === 'object' && x !== null && !Array.isArray(x);
250
+ /**
251
+ * Reports `__proto__` keys where documents use names as keys. Zod silently
252
+ * drops such keys, which would turn a clear mistake into a confusing one
253
+ * (or lose data), so they are rejected up front.
254
+ */
255
+ function checkProtoKeys(input) {
256
+ const errors = [];
257
+ const check = (obj, path) => {
258
+ if (isRecord(obj) && Object.hasOwn(obj, '__proto__'))
259
+ errors.push({
260
+ code: 'INVALID_SHAPE',
261
+ path: formatPath([...path, '__proto__']),
262
+ message: '"__proto__" cannot be used as a name',
263
+ hint: 'Choose another name.',
264
+ });
265
+ };
266
+ if (!isRecord(input))
267
+ return errors;
268
+ check(input['structures'], ['structures']);
269
+ const sources = input['sources'];
270
+ if (Array.isArray(sources))
271
+ sources.forEach((source, k) => {
272
+ check(isRecord(source) ? source['anchors'] : undefined, [
273
+ 'sources',
274
+ k,
275
+ 'anchors',
276
+ ]);
277
+ });
278
+ const steps = input['steps'];
279
+ if (Array.isArray(steps))
280
+ steps.forEach((step, s) => {
281
+ const meta = isRecord(step) ? step['meta'] : undefined;
282
+ check(isRecord(meta) ? meta['vars'] : undefined, [
283
+ 'steps',
284
+ s,
285
+ 'meta',
286
+ 'vars',
287
+ ]);
288
+ });
289
+ return errors;
290
+ }
291
+ // Kind dispatch. Each helper is generic in the kind, so `kinds[kind]` has
292
+ // the matching spec type; the casts restate what the discriminant guarantees.
293
+ function normalizeDeclOf(kind, input) {
294
+ return kinds[kind].normalizeDecl(input);
295
+ }
296
+ function declIdsOf(kind, decl) {
297
+ return kinds[kind].declIds(decl);
298
+ }
299
+ function normalizeActionOf(kind, input, ctx) {
300
+ return kinds[kind].normalizeAction(input, ctx);
301
+ }
302
+ function introducedIdsOf(kind, action) {
303
+ return kinds[kind].introducedIds(action);
304
+ }
305
+ const normalizeDecl = (input) => normalizeDeclOf(input.kind, input);
306
+ function validateDeclOf(kind, decl) {
307
+ return kinds[kind].validateDecl?.(decl) ?? [];
308
+ }
309
+ const validateDecl = (decl) => validateDeclOf(decl.kind, decl);
310
+ const declIds = (decl) => declIdsOf(decl.kind, decl);
311
+ function duplicateId(id, target, path) {
312
+ return {
313
+ code: 'DUPLICATE_ID',
314
+ path: formatPath(path),
315
+ message: `Id "${id}" is already used in "${target}"`,
316
+ hint: 'Ids must be unique within a structure for the whole trace, even after removal; choose a new id.',
317
+ };
318
+ }
319
+ function parseAction(raw, structures, usedIds, path) {
320
+ const { target, ...payload } = raw;
321
+ const decl = Object.hasOwn(structures, target)
322
+ ? structures[target]
323
+ : undefined;
324
+ if (decl === undefined) {
325
+ return fail('UNKNOWN_TARGET', [...path, 'target'], `No structure named "${target}"`, `Declared structures: ${Object.keys(structures).join(', ')}.`);
326
+ }
327
+ const kind = decl.kind;
328
+ const spec = kinds[kind];
329
+ if (!spec.actionTypes.includes(raw.type)) {
330
+ return fail('UNKNOWN_ACTION', [...path, 'type'], `"${raw.type}" is not an action of ${kind} "${target}"`, `Valid actions for ${kind}: ${spec.actionTypes.join(', ')}.`);
331
+ }
332
+ const parsed = spec.actionInput.safeParse(payload);
333
+ if (!parsed.success)
334
+ return err(fromZodIssues(parsed.error.issues, path, 'INVALID_ACTION'));
335
+ const ids = usedIds.get(target) ?? new Set();
336
+ // The payload was parsed with this kind's schema, so it is this kind's input.
337
+ const input = parsed.data;
338
+ const action = normalizeActionOf(kind, input, {
339
+ allocateId(prefix) {
340
+ let n = 0;
341
+ while (ids.has(`${prefix}${n}`))
342
+ n += 1;
343
+ const id = `${prefix}${n}`;
344
+ ids.add(id);
345
+ return id;
346
+ },
347
+ });
348
+ // Shorthands can produce values the canonical schema rejects, such as an
349
+ // id made from a node name with a space; check the result as well.
350
+ const canonical = spec.action.safeParse(action);
351
+ if (!canonical.success)
352
+ return err(fromZodIssues(canonical.error.issues, path, 'INVALID_ACTION'));
353
+ const errors = [];
354
+ for (const ref of introducedIdsOf(kind, action)) {
355
+ if (ids.has(ref.id) && !wasAllocated(input, ref)) {
356
+ errors.push(duplicateId(ref.id, target, [...path, ...ref.path]));
357
+ }
358
+ ids.add(ref.id);
359
+ }
360
+ if (errors.length > 0)
361
+ return err(errors);
362
+ return ok({ target, ...action });
363
+ }
364
+ /**
365
+ * Whether an introduced id was generated during normalisation (and so
366
+ * already reserved), rather than written in the input.
367
+ */
368
+ function wasAllocated(input, ref) {
369
+ let node = input;
370
+ for (const key of ref.path) {
371
+ if (typeof node !== 'object' || node === null)
372
+ return true;
373
+ node = node[key];
374
+ }
375
+ return node === undefined;
376
+ }
377
+ function fail(code, path, message, hint) {
378
+ return err([{ code, path: formatPath(path), message, hint }]);
379
+ }
380
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,UAAU,EACV,aAAa,GAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,GAMN,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,EACf,MAAM,EACN,iBAAiB,GAElB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,QAAQ,GAKT,MAAM,oBAAoB,CAAC;AAE5B,MAAM,UAAU,kBAAkB,CAChC,KAAc;IAEd,MAAM,YAAY,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,YAAY;QAAE,OAAO,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC7C,OAAO,YAAY,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;AACvD,CAAC;AAED,gDAAgD;AAChD,SAAS,YAAY,CACnB,KAAc;IAEd,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,WAAW,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,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,EAC5B,OAAe,EACf,IAAY;IAEZ,OAAO,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A value that is either a success or a failure.
3
+ *
4
+ * Validation of LLM-generated input fails routinely, so failures are values
5
+ * the caller must handle rather than exceptions it may forget to catch.
6
+ */
7
+ export type Result<T, E> = {
8
+ readonly ok: true;
9
+ readonly value: T;
10
+ } | {
11
+ readonly ok: false;
12
+ readonly error: E;
13
+ };
14
+ export declare const ok: <T>(value: T) => Result<T, never>;
15
+ export declare const err: <E>(error: E) => Result<never, E>;
16
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9C,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAA0B,CAAC;AAE3E,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAA2B,CAAC"}
package/dist/result.js ADDED
@@ -0,0 +1,3 @@
1
+ export const ok = (value) => ({ ok: true, value });
2
+ export const err = (error) => ({ ok: false, error });
3
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAAQ,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Share links (ADR 0040): a document, or an algorithm and its input, in
3
+ * the fragment of a player page's URL, after a version marker:
4
+ *
5
+ * #v=1&doc=<the document's JSON, raw DEFLATE, base64url>
6
+ * #v=1&alg=dijkstra&in=A-B%204&frame=improve%233&theme=dark
7
+ *
8
+ * Compression uses the platform's `CompressionStream`, which browsers,
9
+ * Node.js and Workers have. The protocol stays free of DOM and Node.js
10
+ * types (ADR 0005), so the few web APIs used here are looked up on
11
+ * `globalThis` and typed locally; a runtime without them, such as the
12
+ * Typst plugin's, can still write and read algorithm links.
13
+ */
14
+ import type { Diagnostic } from './errors.ts';
15
+ import { type Result } from './result.ts';
16
+ /** The version of the link format that this code writes and reads. */
17
+ export declare const SHARE_LINK_VERSION = 1;
18
+ export declare const SHARE_LIMITS: {
19
+ /** The longest link a writer makes. */
20
+ readonly linkLength: 16384;
21
+ /** The longest fragment a reader takes: Chrome's longest URL. */
22
+ readonly fragmentLength: 2097152;
23
+ /** The most bytes a document may inflate to (ADR 0041). */
24
+ readonly documentBytes: number;
25
+ /** The longest `alg`, `frame` or `theme`. */
26
+ readonly textLength: 200;
27
+ /** The longest `in` (ADR 0041). */
28
+ readonly inputLength: 65536;
29
+ };
30
+ export type ShareErrorCode =
31
+ /** The fragment, or a base URL, is not a share link's. */
32
+ 'INVALID_LINK'
33
+ /** The link, or the document it holds, is over a limit. */
34
+ | 'LINK_TOO_LARGE';
35
+ export type ShareDiagnostic = Diagnostic<ShareErrorCode>;
36
+ /** How the player opens the content: as its `frame` and `theme`. */
37
+ interface ShareView {
38
+ /** A frame number or a selector (ADR 0020); a reader gives it as text. */
39
+ readonly frame?: string | number;
40
+ /** A theme as the player's `theme` attribute takes it. */
41
+ readonly theme?: string;
42
+ }
43
+ /** What a share link carries: a document, or an algorithm and its input. */
44
+ export type ShareContent = (ShareView & {
45
+ readonly document: unknown;
46
+ }) | (ShareView & {
47
+ /** A registry id, such as `dijkstra`. */
48
+ readonly algorithm: string;
49
+ /** The input as text, read by `readInput` (ADR 0032). */
50
+ readonly input?: string;
51
+ });
52
+ type Shared<T> = Promise<Result<T, readonly ShareDiagnostic[]>>;
53
+ /** The fragment of a link, without its `#`. */
54
+ export declare function shareFragment(content: ShareContent): Shared<string>;
55
+ /** A whole link: the page's address, then the fragment. */
56
+ export declare function shareLink(base: string, content: ShareContent): Shared<string>;
57
+ /**
58
+ * Checks the address of a share page: an absolute `http:` or `https:`
59
+ * URL without a fragment, such as `https://example.org/play/`.
60
+ */
61
+ export declare function checkShareBase(base: string): Result<string, readonly ShareDiagnostic[]>;
62
+ /**
63
+ * Reads a fragment, with or without its `#`: the content it carries, or
64
+ * undefined for an empty fragment. Keys it does not know are ignored.
65
+ */
66
+ export declare function readShareFragment(fragment: string): Shared<ShareContent | undefined>;
67
+ export {};
68
+ //# sourceMappingURL=share.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAEnD,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,eAAO,MAAM,YAAY;IACvB,uCAAuC;;IAEvC,iEAAiE;;IAEjE,2DAA2D;;IAE3D,6CAA6C;;IAE7C,mCAAmC;;CAE3B,CAAC;AAEX,MAAM,MAAM,c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