@horizon36596/zenith-schema 0.1.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 +21 -0
- package/NOTICE +18 -0
- package/README.md +24 -0
- package/dist/auto.d.ts +1882 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +236 -0
- package/dist/auto.js.map +1 -0
- package/dist/common.d.ts +76 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +30 -0
- package/dist/common.js.map +1 -0
- package/dist/expr.d.ts +56 -0
- package/dist/expr.d.ts.map +1 -0
- package/dist/expr.js +245 -0
- package/dist/expr.js.map +1 -0
- package/dist/field.d.ts +719 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +158 -0
- package/dist/field.js.map +1 -0
- package/dist/ids.d.ts +62 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +79 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonschema.d.ts +14 -0
- package/dist/jsonschema.d.ts.map +1 -0
- package/dist/jsonschema.js +31 -0
- package/dist/jsonschema.js.map +1 -0
- package/dist/link.d.ts +117 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +58 -0
- package/dist/link.js.map +1 -0
- package/dist/migrate.d.ts +2699 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +109 -0
- package/dist/migrate.js.map +1 -0
- package/dist/parse.d.ts +28 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +46 -0
- package/dist/parse.js.map +1 -0
- package/dist/robot.d.ts +2935 -0
- package/dist/robot.d.ts.map +1 -0
- package/dist/robot.js +231 -0
- package/dist/robot.js.map +1 -0
- package/dist/waypoints.d.ts +63 -0
- package/dist/waypoints.d.ts.map +1 -0
- package/dist/waypoints.js +20 -0
- package/dist/waypoints.js.map +1 -0
- package/json/auto.json +683 -0
- package/json/field.json +457 -0
- package/json/link.json +110 -0
- package/json/robot.json +664 -0
- package/json/waypoints.json +50 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqE,KAAK,IAAI,EAAE,MAAM,UAAU,CAAC;AAKxG,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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vB,IAAI,EAAE,IAAI,CAAC;IACX,+EAA+E;IAC/E,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;CACf;AAiCD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,CAgChE"}
|
package/dist/migrate.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { autoSchema } from "./auto.js";
|
|
2
|
+
import { fieldSchema } from "./field.js";
|
|
3
|
+
import { FORMAT_VERSIONS, LEGACY_SCHEMA_ID, SCHEMA_ID, withCurrentSchemaId } from "./ids.js";
|
|
4
|
+
import { linkSchema } from "./link.js";
|
|
5
|
+
import { robotSchema } from "./robot.js";
|
|
6
|
+
import { waypointsSchema } from "./waypoints.js";
|
|
7
|
+
export const schemaByKind = {
|
|
8
|
+
link: linkSchema,
|
|
9
|
+
robot: robotSchema,
|
|
10
|
+
field: fieldSchema,
|
|
11
|
+
waypoints: waypointsSchema,
|
|
12
|
+
auto: autoSchema,
|
|
13
|
+
};
|
|
14
|
+
export class MigrationError extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "MigrationError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Both the current ids and their legacy aliases (`ids.ts`) name a kind. */
|
|
21
|
+
const idToKind = new Map(Object.keys(SCHEMA_ID).flatMap((kind) => [
|
|
22
|
+
[SCHEMA_ID[kind], kind],
|
|
23
|
+
[LEGACY_SCHEMA_ID[kind], kind],
|
|
24
|
+
]));
|
|
25
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
/**
|
|
27
|
+
* Works out which of the five files this is: from `$schema` when it is there, otherwise from the
|
|
28
|
+
* keys that only one kind has. Returns null when nothing identifies it.
|
|
29
|
+
*/
|
|
30
|
+
export function detectKind(json) {
|
|
31
|
+
if (!isRecord(json))
|
|
32
|
+
return null;
|
|
33
|
+
const id = json["$schema"];
|
|
34
|
+
if (typeof id === "string") {
|
|
35
|
+
const known = idToKind.get(id);
|
|
36
|
+
if (known !== undefined)
|
|
37
|
+
return known;
|
|
38
|
+
}
|
|
39
|
+
if ("steps" in json && "start" in json)
|
|
40
|
+
return "auto";
|
|
41
|
+
if ("waypoints" in json)
|
|
42
|
+
return "waypoints";
|
|
43
|
+
if ("obstacles" in json || "season" in json)
|
|
44
|
+
return "field";
|
|
45
|
+
if ("kinematics" in json || "footprint" in json)
|
|
46
|
+
return "robot";
|
|
47
|
+
if ("autosDir" in json)
|
|
48
|
+
return "link";
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The same document at the next version with nothing else changed. Right for any bump whose new
|
|
53
|
+
* version only adds optional keys or step kinds: every older file is already a valid newer one
|
|
54
|
+
* once it says so.
|
|
55
|
+
*/
|
|
56
|
+
const bumpOnly = (to) => (doc) => ({ ...doc, formatVersion: to });
|
|
57
|
+
/**
|
|
58
|
+
* The migrations, per kind, indexed by the version they start from: `steps[kind][1]` takes a v1
|
|
59
|
+
* file to v2. Every entry has a fixture pair under `packages/schema/fixtures/migrate/`.
|
|
60
|
+
*
|
|
61
|
+
* - auto 1 -> 2 (2026-09-22): v2 adds the `sequence` step kind. A v1 auto holds no sequence, so the
|
|
62
|
+
* migration is the identity plus the version bump.
|
|
63
|
+
* - field 1 -> 2 (2026-09-22): v2 adds the optional `image` layer (site/docs/editor.md). A v1 field
|
|
64
|
+
* has none, so again the identity plus the bump.
|
|
65
|
+
* - auto 2 -> 3 (2026-09-24): v3 adds the `piecewise` heading mode (site/docs/file-format.md,
|
|
66
|
+
* "Piecewise heading"). A v2 auto has none, so the identity plus the bump.
|
|
67
|
+
*/
|
|
68
|
+
const MIGRATIONS = {
|
|
69
|
+
link: {},
|
|
70
|
+
robot: {},
|
|
71
|
+
field: { 1: bumpOnly(2) },
|
|
72
|
+
waypoints: {},
|
|
73
|
+
auto: { 1: bumpOnly(2), 2: bumpOnly(3) },
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Brings a document up to its kind's current `formatVersion` (`FORMAT_VERSIONS`), one version at a
|
|
77
|
+
* time. A file from the future is refused by name and number, the same way the robot runtime
|
|
78
|
+
* refuses it (site/docs/file-format.md, Versioning). A legacy `$schema` alias comes back as the
|
|
79
|
+
* current id, so whatever writes the result writes the current one. The input is never mutated.
|
|
80
|
+
*/
|
|
81
|
+
export function migrate(json, kindHint) {
|
|
82
|
+
if (!isRecord(json))
|
|
83
|
+
throw new MigrationError("A Zenith file must be a JSON object.");
|
|
84
|
+
const kind = kindHint ?? detectKind(json);
|
|
85
|
+
if (kind === null) {
|
|
86
|
+
throw new MigrationError("Cannot tell which kind of Zenith file this is: no $schema and no distinguishing keys.");
|
|
87
|
+
}
|
|
88
|
+
const raw = json["formatVersion"];
|
|
89
|
+
if (typeof raw !== "number" || !Number.isInteger(raw)) {
|
|
90
|
+
throw new MigrationError(`A ${kind} file needs an integer formatVersion.`);
|
|
91
|
+
}
|
|
92
|
+
const current = FORMAT_VERSIONS[kind];
|
|
93
|
+
if (raw > current) {
|
|
94
|
+
throw new MigrationError(`This ${kind} file is formatVersion ${String(raw)}; this build of Zenith knows ${String(current)}.`);
|
|
95
|
+
}
|
|
96
|
+
if (raw < 1) {
|
|
97
|
+
throw new MigrationError(`formatVersion ${String(raw)} never existed; the first version is 1.`);
|
|
98
|
+
}
|
|
99
|
+
let doc = json;
|
|
100
|
+
for (let version = raw; version < current; version += 1) {
|
|
101
|
+
const step = MIGRATIONS[kind][version];
|
|
102
|
+
if (step === undefined) {
|
|
103
|
+
throw new MigrationError(`No migration takes a ${kind} file from formatVersion ${String(version)} to ${String(version + 1)}.`);
|
|
104
|
+
}
|
|
105
|
+
doc = step(doc);
|
|
106
|
+
}
|
|
107
|
+
return { kind, formatVersion: current, fromVersion: raw, data: withCurrentSchemaId(kind, doc) };
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,SAAS,EAAE,mBAAmB,EAAa,MAAM,UAAU,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,eAAe;IAC1B,IAAI,EAAE,UAAU;CACR,CAAC;AAEX,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,QAAQ,GAAG,IAAI,GAAG,CACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;IACnD,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAU;IAChC,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,CAAU;CACxC,CAAC,CACH,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,O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AA4B,MAAM,CAAC,OAAO,CAAC,OAAO,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CACrG,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;AAClG,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Auto } from "./auto.js";
|
|
3
|
+
import type { Field } from "./field.js";
|
|
4
|
+
import type { Kind } from "./ids.js";
|
|
5
|
+
import type { Link } from "./link.js";
|
|
6
|
+
import type { Robot } from "./robot.js";
|
|
7
|
+
import type { Waypoints } from "./waypoints.js";
|
|
8
|
+
export declare class SchemaError extends Error {
|
|
9
|
+
readonly kind: Kind;
|
|
10
|
+
readonly issues: z.ZodIssue[];
|
|
11
|
+
constructor(message: string, kind: Kind, issues: z.ZodIssue[]);
|
|
12
|
+
}
|
|
13
|
+
/** `path/to/key: message`, the shape the CLI prints and the SCHEMA finding carries. */
|
|
14
|
+
export declare function formatIssue(issue: z.ZodIssue): string;
|
|
15
|
+
export declare const parseLink: (json: unknown) => Link;
|
|
16
|
+
export declare const parseRobot: (json: unknown) => Robot;
|
|
17
|
+
export declare const parseField: (json: unknown) => Field;
|
|
18
|
+
export declare const parseWaypoints: (json: unknown) => Waypoints;
|
|
19
|
+
export declare const parseAuto: (json: unknown) => Auto;
|
|
20
|
+
/** Validates without throwing; the SCHEMA check wants the issue list, not an exception. */
|
|
21
|
+
export declare function validateKind(kind: Kind, json: unknown): {
|
|
22
|
+
ok: true;
|
|
23
|
+
data: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
issues: string[];
|
|
27
|
+
};
|
|
28
|
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EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAU/D"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { migrate, schemaByKind } from "./migrate.js";
|
|
3
|
+
export class SchemaError extends Error {
|
|
4
|
+
kind;
|
|
5
|
+
issues;
|
|
6
|
+
constructor(message, kind, issues) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.kind = kind;
|
|
9
|
+
this.issues = issues;
|
|
10
|
+
this.name = "SchemaError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** `path/to/key: message`, the shape the CLI prints and the SCHEMA finding carries. */
|
|
14
|
+
export function formatIssue(issue) {
|
|
15
|
+
const where = issue.path.length === 0 ? "(root)" : issue.path.join(".");
|
|
16
|
+
return `${where}: ${issue.message}`;
|
|
17
|
+
}
|
|
18
|
+
function parseAs(kind, json) {
|
|
19
|
+
const migrated = migrate(json, kind);
|
|
20
|
+
const result = schemaByKind[kind].safeParse(migrated.data);
|
|
21
|
+
if (!result.success) {
|
|
22
|
+
const issues = result.error.issues;
|
|
23
|
+
throw new SchemaError(`Invalid ${kind} file:\n ${issues.map(formatIssue).join("\n ")}`, kind, issues);
|
|
24
|
+
}
|
|
25
|
+
return result.data;
|
|
26
|
+
}
|
|
27
|
+
export const parseLink = (json) => parseAs("link", json);
|
|
28
|
+
export const parseRobot = (json) => parseAs("robot", json);
|
|
29
|
+
export const parseField = (json) => parseAs("field", json);
|
|
30
|
+
export const parseWaypoints = (json) => parseAs("waypoints", json);
|
|
31
|
+
export const parseAuto = (json) => parseAs("auto", json);
|
|
32
|
+
/** Validates without throwing; the SCHEMA check wants the issue list, not an exception. */
|
|
33
|
+
export function validateKind(kind, json) {
|
|
34
|
+
let migrated;
|
|
35
|
+
try {
|
|
36
|
+
migrated = migrate(json, kind);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return { ok: false, issues: [error instanceof Error ? error.message : String(error)] };
|
|
40
|
+
}
|
|
41
|
+
const result = schemaByKind[kind].safeParse(migrated.data);
|
|
42
|
+
if (result.success)
|
|
43
|
+
return { ok: true, data: result.data };
|
|
44
|
+
return { ok: false, issues: result.error.issues.map(formatIssue) };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGzB;IACA;IAHX,YACE,OAAe,EACN,IAAU,EACV,MAAoB;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAM;QACV,WAAM,GAAN,MAAM,CAAc;QAG7B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,GAAG,KAAK,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,OAAO,CAAI,IAAU,EAAE,IAAa;IAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,IA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