@spine-event-engine/proto-tools 2.0.0-snapshot.2

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 (73) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +102 -0
  3. package/REFERENCE.md +80 -0
  4. package/bin/spine-proto.mjs +2 -0
  5. package/dist/src/cli/spine-proto-bootstrap.d.ts +4 -0
  6. package/dist/src/cli/spine-proto-bootstrap.d.ts.map +1 -0
  7. package/dist/src/cli/spine-proto-bootstrap.js +52 -0
  8. package/dist/src/cli/spine-proto-bootstrap.js.map +1 -0
  9. package/dist/src/cli/spine-proto.d.ts +3 -0
  10. package/dist/src/cli/spine-proto.d.ts.map +1 -0
  11. package/dist/src/cli/spine-proto.js +32 -0
  12. package/dist/src/cli/spine-proto.js.map +1 -0
  13. package/dist/src/generation/authored-interface-provider.d.ts +28 -0
  14. package/dist/src/generation/authored-interface-provider.d.ts.map +1 -0
  15. package/dist/src/generation/authored-interface-provider.js +244 -0
  16. package/dist/src/generation/authored-interface-provider.js.map +1 -0
  17. package/dist/src/generation/generated-source-policy.d.ts +21 -0
  18. package/dist/src/generation/generated-source-policy.d.ts.map +1 -0
  19. package/dist/src/generation/generated-source-policy.js +126 -0
  20. package/dist/src/generation/generated-source-policy.js.map +1 -0
  21. package/dist/src/generation/generation-reuse.mjs +84 -0
  22. package/dist/src/generation/generator.d.ts +195 -0
  23. package/dist/src/generation/generator.d.ts.map +1 -0
  24. package/dist/src/generation/generator.js +566 -0
  25. package/dist/src/generation/generator.js.map +1 -0
  26. package/dist/src/generation/handler-generator.d.ts +7 -0
  27. package/dist/src/generation/handler-generator.d.ts.map +1 -0
  28. package/dist/src/generation/handler-generator.js +55 -0
  29. package/dist/src/generation/handler-generator.js.map +1 -0
  30. package/dist/src/generation/interface-generator.d.ts +21 -0
  31. package/dist/src/generation/interface-generator.d.ts.map +1 -0
  32. package/dist/src/generation/interface-generator.js +277 -0
  33. package/dist/src/generation/interface-generator.js.map +1 -0
  34. package/dist/src/generation/interface-provider.d.ts +30 -0
  35. package/dist/src/generation/interface-provider.d.ts.map +1 -0
  36. package/dist/src/generation/interface-provider.js +15 -0
  37. package/dist/src/generation/interface-provider.js.map +1 -0
  38. package/dist/src/generation/rejection-generator.d.ts +9 -0
  39. package/dist/src/generation/rejection-generator.d.ts.map +1 -0
  40. package/dist/src/generation/rejection-generator.js +62 -0
  41. package/dist/src/generation/rejection-generator.js.map +1 -0
  42. package/dist/src/generation/source-view.d.ts +103 -0
  43. package/dist/src/generation/source-view.d.ts.map +1 -0
  44. package/dist/src/generation/source-view.js +298 -0
  45. package/dist/src/generation/source-view.js.map +1 -0
  46. package/dist/src/index.d.ts +139 -0
  47. package/dist/src/index.d.ts.map +1 -0
  48. package/dist/src/index.js +546 -0
  49. package/dist/src/index.js.map +1 -0
  50. package/dist/src/io/atomic-manifest.d.ts +32 -0
  51. package/dist/src/io/atomic-manifest.d.ts.map +1 -0
  52. package/dist/src/io/atomic-manifest.js +56 -0
  53. package/dist/src/io/atomic-manifest.js.map +1 -0
  54. package/dist/src/io/manifest-reader.d.ts +8 -0
  55. package/dist/src/io/manifest-reader.d.ts.map +1 -0
  56. package/dist/src/io/manifest-reader.js +19 -0
  57. package/dist/src/io/manifest-reader.js.map +1 -0
  58. package/dist/src/model/model-graph.d.ts +68 -0
  59. package/dist/src/model/model-graph.d.ts.map +1 -0
  60. package/dist/src/model/model-graph.js +220 -0
  61. package/dist/src/model/model-graph.js.map +1 -0
  62. package/dist/src/model/npm-package-name.d.ts +7 -0
  63. package/dist/src/model/npm-package-name.d.ts.map +1 -0
  64. package/dist/src/model/npm-package-name.js +33 -0
  65. package/dist/src/model/npm-package-name.js.map +1 -0
  66. package/dist/src/model/registry-dependency.d.ts +10 -0
  67. package/dist/src/model/registry-dependency.d.ts.map +1 -0
  68. package/dist/src/model/registry-dependency.js +66 -0
  69. package/dist/src/model/registry-dependency.js.map +1 -0
  70. package/dist/tsconfig.tsbuildinfo +1 -0
  71. package/package.json +51 -0
  72. package/scripts/clean-dist.mjs +7 -0
  73. package/scripts/copy-runtime-modules.mjs +23 -0
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { renameSync, rmSync, writeFileSync } from "node:fs";
15
+ import { basename, dirname, join } from "node:path";
16
+ const defaultOperations = {
17
+ writeFile: (path, content) => {
18
+ writeFileSync(path, content, "utf8");
19
+ },
20
+ rename: renameSync,
21
+ remove: (path) => {
22
+ rmSync(path, { force: true });
23
+ },
24
+ };
25
+ /**
26
+ * Publishes manifest files through complete sibling staging files.
27
+ */
28
+ export const ManifestFile = Object.freeze({
29
+ // prettier-ignore
30
+ /**
31
+ * Replaces a manifest only after complete content exists in a unique sibling staging file.
32
+ *
33
+ * @param target The manifest file to replace.
34
+ * @param content The complete manifest content.
35
+ * @param operations Optional filesystem seams used by failure tests.
36
+ * @returns Nothing.
37
+ */
38
+ writeAtomically(target, content, operations = {}) {
39
+ const fileOperations = { ...defaultOperations, ...operations };
40
+ const staging = join(dirname(target), `.${basename(target)}.${String(process.pid)}.${crypto.randomUUID()}.tmp`);
41
+ try {
42
+ fileOperations.writeFile(staging, content);
43
+ fileOperations.rename(staging, target);
44
+ }
45
+ catch (error) {
46
+ try {
47
+ fileOperations.remove(staging);
48
+ }
49
+ catch {
50
+ // Preserves the primary write or rename failure.
51
+ }
52
+ throw error;
53
+ }
54
+ },
55
+ });
56
+ //# sourceMappingURL=atomic-manifest.js.map
@@ -0,0 +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C,CAAC;YACjC,CAAC;YAAC,MAAM,CAAC;gBACP,iDAAiD;YACnD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type ProtoManifest as Manifest } from "../index.js";
2
+ type ManifestReader = (packageRoot: string, manifestPath: string) => Manifest;
3
+ /**
4
+ * Internal exact-manifest reader; it is intentionally not re-exported by the package root.
5
+ */
6
+ export declare const readManifestAt: ManifestReader;
7
+ export {};
8
+ //# sourceMappingURL=manifest-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-reader.d.ts","sourceRoot":"","sources":["../../../src/io/manifest-reader.ts"],"names":[],"mappings":"AAcA,OAAO,EAAiB,KAAK,aAAa,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5E,KAAK,cAAc,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,QAAQ,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,cAAmC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { ProtoManifest } from "../index.js";
15
+ /**
16
+ * Internal exact-manifest reader; it is intentionally not re-exported by the package root.
17
+ */
18
+ export const readManifestAt = ProtoManifest.read;
19
+ //# sourceMappingURL=manifest-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-reader.js","sourceRoot":"","sources":["../../../src/io/manifest-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAkC,MAAM,aAAa,CAAC;AAI5E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmB,aAAa,CAAC,IAAI,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type ProtoManifest } from "../index.js";
2
+ /**
3
+ * Describes one installed model package in a resolved dependency graph.
4
+ */
5
+ export interface ResolvedModel {
6
+ /**
7
+ * Names the resolved model package.
8
+ */
9
+ readonly name: string;
10
+ /**
11
+ * States the resolved package version.
12
+ */
13
+ readonly version: string;
14
+ /**
15
+ * Names the package export that provides its Proto module.
16
+ */
17
+ readonly moduleExport: string;
18
+ /**
19
+ * Locates the installed package root.
20
+ */
21
+ readonly root: string;
22
+ }
23
+ /**
24
+ * Identifies the model package that owns a generated Proto path.
25
+ */
26
+ export interface ProtoOwner {
27
+ /**
28
+ * Names the package that owns the Proto path.
29
+ */
30
+ readonly packageName: string;
31
+ /**
32
+ * Names the package-relative generated import subpath.
33
+ */
34
+ readonly generatedExport: string;
35
+ }
36
+ /**
37
+ * Contains the resolved model packages and their Proto-path owners.
38
+ */
39
+ export interface ResolvedModelGraph {
40
+ /**
41
+ * Lists model packages in deterministic dependency order.
42
+ */
43
+ readonly models: readonly ResolvedModel[];
44
+ /**
45
+ * Maps every owned Proto path to its model package.
46
+ */
47
+ readonly protoOwners: Readonly<Record<string, ProtoOwner>>;
48
+ }
49
+ interface PackageJson {
50
+ readonly name: string;
51
+ readonly version: string;
52
+ readonly dependencies: Readonly<Record<string, string>>;
53
+ }
54
+ /**
55
+ * Resolves explicitly declared installed model-package graphs.
56
+ */
57
+ export declare const ModelGraph: Readonly<{
58
+ resolve(requesterRoot: string, modelPackages: readonly string[]): ResolvedModelGraph;
59
+ findPackageRoot(manifestPath: string, requester: string): string;
60
+ resolveManifest(requesterRoot: string, name: string): string;
61
+ readPackageJson(path: string, requester: string): PackageJson;
62
+ validateDeclaredDependencies(packageJson: PackageJson, manifest: ProtoManifest): void;
63
+ isStringRecord(value: unknown): value is Readonly<Record<string, string>>;
64
+ satisfiesRegistrySpecifier(version: string, specifier: string): boolean;
65
+ fail(name: string, message: string): never;
66
+ }>;
67
+ export {};
68
+ //# sourceMappingURL=model-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-graph.d.ts","sourceRoot":"","sources":["../../../src/model/model-graph.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjD;;GAEG;AACH,MAAM,WAAW,aAAa;IAG5B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAGzB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAGjC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAE1C;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC5D;AAED,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACzD;AAWD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC;IAChC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAAC;IACrF,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACjE,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7D,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC;IAC9D,4BAA4B,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IACtF,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACxE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5C,CA8OC,CAAC"}
@@ -0,0 +1,220 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { createRequire } from "node:module";
15
+ import { dirname, join } from "node:path";
16
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
17
+ import { satisfies, validRange } from "semver";
18
+ import {} from "../index.js";
19
+ import { readManifestAt } from "../io/manifest-reader.js";
20
+ import { RegistryDependency } from "./registry-dependency.js";
21
+ import { NpmPackageName } from "./npm-package-name.js";
22
+ /**
23
+ * Resolves explicitly declared installed model-package graphs.
24
+ */
25
+ export const ModelGraph = Object.freeze({
26
+ // prettier-ignore
27
+ /**
28
+ * Resolves explicitly declared installed model packages without scanning `node_modules`.
29
+ *
30
+ * @param requesterRoot The application or model package root.
31
+ * @param modelPackages The explicitly declared direct model packages.
32
+ * @returns The deterministically resolved model graph.
33
+ */
34
+ resolve(requesterRoot, modelPackages) {
35
+ if (modelPackages.length > 10000) {
36
+ ModelGraph.fail(ModelGraph.readPackageJson(join(requesterRoot, "package.json"), requesterRoot).name, "model dependency graph exceeds 10000 packages");
37
+ }
38
+ const rootPackage = ModelGraph.readPackageJson(join(requesterRoot, "package.json"), requesterRoot);
39
+ for (const modelPackage of modelPackages) {
40
+ const candidate = modelPackage;
41
+ if (!NpmPackageName.is(candidate))
42
+ ModelGraph.fail(rootPackage.name, `model package ${modelPackage} must be a valid npm package name`);
43
+ }
44
+ const resolved = new Map();
45
+ const owners = {};
46
+ const models = [];
47
+ const states = new Map();
48
+ let packageCount = 0;
49
+ let ownedProtoPaths = 0;
50
+ let scheduledEdges = modelPackages.length;
51
+ const pending = modelPackages
52
+ .slice()
53
+ .sort()
54
+ .reverse()
55
+ .map((name) => ({ kind: "visit", requesterRoot, name }));
56
+ const walker = {
57
+ resolveNode(requester, name) {
58
+ const manifestPath = ModelGraph.resolveManifest(requester, name);
59
+ const root = ModelGraph.findPackageRoot(manifestPath, name);
60
+ const packageJson = ModelGraph.readPackageJson(join(root, "package.json"), name);
61
+ if (packageJson.name !== name)
62
+ ModelGraph.fail(name, "package.json name must match requested package");
63
+ const manifest = readManifestAt(root, manifestPath);
64
+ ModelGraph.validateDeclaredDependencies(packageJson, manifest);
65
+ const model = {
66
+ name: packageJson.name,
67
+ version: packageJson.version,
68
+ moduleExport: manifest.moduleExport,
69
+ root,
70
+ };
71
+ const existing = resolved.get(model.name);
72
+ if (existing !== undefined && existing.model.root !== root)
73
+ ModelGraph.fail(name, `package ${name} resolves to multiple installed roots`);
74
+ if (existing !== undefined)
75
+ return existing;
76
+ const node = { model, manifest };
77
+ resolved.set(model.name, node);
78
+ return node;
79
+ },
80
+ };
81
+ while (pending.length > 0) {
82
+ const step = pending.pop();
83
+ if (step === undefined)
84
+ continue;
85
+ const node = walker.resolveNode(step.requesterRoot, step.name);
86
+ const requesterPackage = ModelGraph.readPackageJson(join(step.requesterRoot, "package.json"), step.name);
87
+ const requestedVersion = requesterPackage.dependencies[step.name];
88
+ if (requestedVersion !== undefined &&
89
+ !ModelGraph.satisfiesRegistrySpecifier(node.model.version, requestedVersion)) {
90
+ ModelGraph.fail(requesterPackage.name, `dependency ${step.name} version ${node.model.version} does not satisfy ${requestedVersion}`);
91
+ }
92
+ const state = states.get(node.model.root);
93
+ if (step.kind === "complete") {
94
+ states.set(node.model.root, "visited");
95
+ models.push(node.model);
96
+ for (const protoFile of node.manifest.protoFiles) {
97
+ ownedProtoPaths += 1;
98
+ if (ownedProtoPaths > 10000)
99
+ ModelGraph.fail(node.model.name, "resolved model graph exceeds 10000 owned Proto paths");
100
+ const existing = owners[protoFile];
101
+ if (existing !== undefined && existing.packageName !== node.model.name) {
102
+ ModelGraph.fail(node.model.name, `Proto path ${protoFile} is already owned by ${existing.packageName}`);
103
+ }
104
+ owners[protoFile] = {
105
+ packageName: node.model.name,
106
+ generatedExport: node.manifest.generatedExports[protoFile] ?? "",
107
+ };
108
+ }
109
+ continue;
110
+ }
111
+ if (state === "visited")
112
+ continue;
113
+ if (state === "visiting")
114
+ ModelGraph.fail(step.name, "dependency cycle");
115
+ packageCount += 1;
116
+ if (packageCount > 10000)
117
+ ModelGraph.fail(step.name, "model dependency graph exceeds 10000 packages");
118
+ states.set(node.model.root, "visiting");
119
+ pending.push({
120
+ kind: "complete",
121
+ requesterRoot: step.requesterRoot,
122
+ name: step.name,
123
+ });
124
+ if (node.manifest.dependencies.length > 10000 - scheduledEdges) {
125
+ ModelGraph.fail(node.model.name, "model dependency graph exceeds 10000 scheduled dependency edges");
126
+ }
127
+ scheduledEdges += node.manifest.dependencies.length;
128
+ for (const dependency of node.manifest.dependencies.slice().sort().reverse()) {
129
+ pending.push({ kind: "visit", requesterRoot: node.model.root, name: dependency });
130
+ }
131
+ }
132
+ return { models, protoOwners: Object.fromEntries(Object.entries(owners).sort()) };
133
+ },
134
+ findPackageRoot(manifestPath, requester) {
135
+ let root = dirname(manifestPath);
136
+ for (let depth = 0; depth <= 100; depth += 1) {
137
+ const packageJsonPath = join(root, "package.json");
138
+ if (existsSync(packageJsonPath)) {
139
+ try {
140
+ if (ModelGraph.readPackageJson(packageJsonPath, requester).name === requester)
141
+ return realpathSync(root);
142
+ }
143
+ catch {
144
+ // Nested metadata does not establish the owner of this manifest.
145
+ }
146
+ }
147
+ const parent = dirname(root);
148
+ if (parent === root)
149
+ break;
150
+ root = parent;
151
+ }
152
+ return ModelGraph.fail(requester, "cannot locate owning package.json for resolved manifest");
153
+ },
154
+ resolveManifest(requesterRoot, name) {
155
+ try {
156
+ return createRequire(join(requesterRoot, "package.json")).resolve(`${name}/spine-proto-manifest.json`);
157
+ }
158
+ catch {
159
+ return ModelGraph.fail(name, `cannot resolve manifest from ${requesterRoot}`);
160
+ }
161
+ },
162
+ readPackageJson(path, requester) {
163
+ try {
164
+ const value = JSON.parse(readFileSync(path, "utf8"));
165
+ if (typeof value !== "object" || value === null || Array.isArray(value))
166
+ throw new Error();
167
+ const packageJson = value;
168
+ if (typeof packageJson.name !== "string" || packageJson.name.length === 0)
169
+ ModelGraph.fail(requester, "package.json name must be a non-empty string");
170
+ if (!NpmPackageName.is(packageJson.name))
171
+ ModelGraph.fail(requester, "package.json name must be a valid npm package name");
172
+ if (typeof packageJson.version !== "string" || packageJson.version.length === 0)
173
+ ModelGraph.fail(requester, "package.json version must be a non-empty string");
174
+ if (packageJson.dependencies !== undefined &&
175
+ !ModelGraph.isStringRecord(packageJson.dependencies)) {
176
+ ModelGraph.fail(requester, "package.json dependencies must contain string versions");
177
+ }
178
+ const validPackageJson = packageJson;
179
+ return {
180
+ name: validPackageJson.name,
181
+ version: validPackageJson.version,
182
+ dependencies: validPackageJson.dependencies ?? {},
183
+ };
184
+ }
185
+ catch (error) {
186
+ if (error instanceof Error && error.message.startsWith("spine-proto:"))
187
+ throw error;
188
+ return ModelGraph.fail(requester, "cannot read package.json");
189
+ }
190
+ },
191
+ validateDeclaredDependencies(packageJson, manifest) {
192
+ for (const dependency of manifest.dependencies) {
193
+ const candidate = dependency;
194
+ if (!NpmPackageName.is(candidate))
195
+ ModelGraph.fail(packageJson.name, `dependency ${dependency} must be a valid npm package name`);
196
+ const specifier = packageJson.dependencies[dependency];
197
+ if (specifier === undefined)
198
+ ModelGraph.fail(packageJson.name, `dependency ${dependency} must be declared in package.json dependencies`);
199
+ if (!RegistryDependency.is(specifier))
200
+ ModelGraph.fail(packageJson.name, `dependency ${dependency} must use a registry version`);
201
+ }
202
+ },
203
+ isStringRecord(value) {
204
+ return (typeof value === "object" &&
205
+ value !== null &&
206
+ !Array.isArray(value) &&
207
+ Object.values(value).every((item) => typeof item === "string"));
208
+ },
209
+ satisfiesRegistrySpecifier(version, specifier) {
210
+ const range = specifier.startsWith("npm:")
211
+ ? specifier.slice(specifier.lastIndexOf("@") + 1)
212
+ : specifier;
213
+ const parsedRange = validRange(range);
214
+ return parsedRange === null || satisfies(version, parsedRange);
215
+ },
216
+ fail(name, message) {
217
+ throw new Error(`spine-proto: ${name}: ${message}`);
218
+ },
219
+ });
220
+ //# sourceMappingURL=model-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-graph.js","sourceRoot":"","sources":["../../../src/model/model-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU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AAI,CACb,WAAW,CAAC,IAAI,EAChB,cAAc,UAAU,gDAAgD,CACzE,CAAC;YACJ,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,SAAS,CAAC;gBACnC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,cAAc,UAAU,8BAA8B,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;IAED,cAAc,CAAC,KAAc;QAC3B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACrB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAC/D,CAAC;IACJ,CAAC;IAED,0BAA0B,CAAC,OAAe,EAAE,SAAiB;QAC3D,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;YACxC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjD,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACtC,OAAO,WAAW,KAAK,IAAI,IAAI,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,CAAC,IAAY,EAAE,OAAe;QAChC,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Validates npm package names used by the model-package contract.
3
+ */
4
+ export declare const NpmPackageName: Readonly<{
5
+ is(value: unknown): value is string;
6
+ }>;
7
+ //# sourceMappingURL=npm-package-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-package-name.d.ts","sourceRoot":"","sources":["../../../src/model/npm-package-name.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC;IAAE,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAA;CAAE,CAY3E,CAAC"}
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ /**
15
+ * Registry package names accepted by the model-package contract.
16
+ */
17
+ const npmPackageName = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
18
+ /**
19
+ * Validates npm package names used by the model-package contract.
20
+ */
21
+ export const NpmPackageName = Object.freeze({
22
+ // prettier-ignore
23
+ /**
24
+ * Returns whether a value is a scoped or unscoped npm package name.
25
+ *
26
+ * @param value The candidate package name.
27
+ * @returns Whether the value is a valid package name.
28
+ */
29
+ is(value) {
30
+ return typeof value === "string" && npmPackageName.test(value);
31
+ },
32
+ });
33
+ //# sourceMappingURL=npm-package-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-package-name.js","sourceRoot":"","sources":["../../../src/model/npm-package-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,cAAc,GAAG,oDAAoD,CAAC;AAE5E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsD,MAAM,CAAC,MAAM,CAAC;IAC7F,kBAAkB;IAElB;;;;;OAKG;IACH,EAAE,CAAC,KAAc;QACf,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Validates npm registry dependency specifiers used by model packages.
3
+ */
4
+ export declare const RegistryDependency: Readonly<{
5
+ is(specifier: unknown): specifier is string;
6
+ isAlias(alias: string): boolean;
7
+ isPackageName(value: string): boolean;
8
+ isVersion(value: string): boolean;
9
+ }>;
10
+ //# sourceMappingURL=registry-dependency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-dependency.d.ts","sourceRoot":"","sources":["../../../src/model/registry-dependency.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC;IACxC,EAAE,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI,MAAM,CAAC;IAC5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC,CAsDC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { validRange } from "semver";
15
+ /**
16
+ * Validates npm registry dependency specifiers used by model packages.
17
+ */
18
+ export const RegistryDependency = Object.freeze({
19
+ // prettier-ignore
20
+ /**
21
+ * Returns whether a specifier is an ordinary npm registry reference.
22
+ *
23
+ * @param specifier The dependency specifier to inspect.
24
+ * @returns Whether the specifier is a supported registry reference.
25
+ */
26
+ is(specifier) {
27
+ if (typeof specifier !== "string")
28
+ return false;
29
+ if (specifier.startsWith("npm:"))
30
+ return RegistryDependency.isAlias(specifier.slice("npm:".length));
31
+ return (!specifier.includes(":") &&
32
+ !specifier.includes("/") &&
33
+ RegistryDependency.isVersion(specifier));
34
+ },
35
+ /**
36
+ * Returns whether an npm alias names a registry package and version.
37
+ *
38
+ * @param alias The npm alias value without its `npm:` prefix.
39
+ * @returns Whether the alias is valid.
40
+ */
41
+ isAlias(alias) {
42
+ const versionIndex = alias.lastIndexOf("@");
43
+ return (versionIndex > 0 &&
44
+ RegistryDependency.isPackageName(alias.slice(0, versionIndex)) &&
45
+ RegistryDependency.isVersion(alias.slice(versionIndex + 1)));
46
+ },
47
+ /**
48
+ * Returns whether a value names an npm package.
49
+ *
50
+ * @param value The package-name candidate.
51
+ * @returns Whether the value is valid.
52
+ */
53
+ isPackageName(value) {
54
+ return /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i.test(value);
55
+ },
56
+ /**
57
+ * Returns whether a value is a registry tag or semantic-version range.
58
+ *
59
+ * @param value The version-specifier candidate.
60
+ * @returns Whether the value is valid.
61
+ */
62
+ isVersion(value) {
63
+ return /^[a-z][a-z0-9._-]*$/i.test(value) || validRange(value) !== null;
64
+ },
65
+ });
66
+ //# sourceMappingURL=registry-dependency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-dependency.js","sourceRoot":"","sources":["../../../src/model/registry-dependency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAK1B,MAAM,CAAC,MAAM,CAAC;IACjB,kBAAkB;IAElB;;;;;OAKG;IACH,EA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