@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,244 @@
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 { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, readFileSync, realpathSync, } from "node:fs";
15
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
16
+ import ts from "typescript";
17
+ const nonRegularInputDiagnostic = "spine-proto: source view contains non-regular TypeScript input";
18
+ const SourceSnapshotFiles = Object.freeze({
19
+ read(path) {
20
+ let descriptor;
21
+ try {
22
+ descriptor = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW);
23
+ if (!fstatSync(descriptor).isFile())
24
+ throw new Error(nonRegularInputDiagnostic);
25
+ return readFileSync(descriptor, "utf8");
26
+ }
27
+ catch (error) {
28
+ if (error instanceof Error && error.message === nonRegularInputDiagnostic)
29
+ throw error;
30
+ throw new Error(nonRegularInputDiagnostic, { cause: error });
31
+ }
32
+ finally {
33
+ if (descriptor !== undefined)
34
+ closeSync(descriptor);
35
+ }
36
+ },
37
+ });
38
+ /**
39
+ * Resolves authored TypeScript interfaces from the validated model source view.
40
+ */
41
+ export class AuthoredInterfaceProvider {
42
+ // prettier-ignore
43
+ programs = new WeakMap();
44
+ // prettier-ignore
45
+ /**
46
+ * Resolves one compatible authored interface from the staged model Program.
47
+ *
48
+ * @param name Requested TypeScript interface identifier.
49
+ * @param members Generated messages that must satisfy the interface.
50
+ * @param sourceView Validated authored/staged compiler input.
51
+ * @returns The authored declaration import, or undefined without a source view.
52
+ */
53
+ resolve(name, members, sourceView) {
54
+ if (sourceView === undefined)
55
+ return undefined;
56
+ const program = this.program(sourceView);
57
+ const authoredSources = new Set(sourceView.authoredFiles.map((file) => resolve(file)));
58
+ const discoveryRoots = program
59
+ .getRootFileNames()
60
+ .filter((file) => authoredSources.has(resolve(file)));
61
+ const declaration = this.declaration(program, discoveryRoots, name);
62
+ const checker = program.getTypeChecker();
63
+ this.assertNamedModuleExport(checker, declaration, name);
64
+ this.assertLocalParents(checker, declaration, name, new Set(), authoredSources);
65
+ const interfaceType = checker.getTypeAtLocation(declaration);
66
+ for (const member of members) {
67
+ const type = this.messageType(program, checker, sourceView, member);
68
+ if (!checker.isTypeAssignableTo(type, interfaceType))
69
+ throw new Error(`spine-proto: authored interface ${name}: incompatible message ${member.typeName}`);
70
+ }
71
+ return Object.freeze({
72
+ importPath: this.importPath(sourceView, name, declaration.getSourceFile().fileName),
73
+ name,
74
+ });
75
+ }
76
+ program(sourceView) {
77
+ const cached = this.programs.get(sourceView);
78
+ if (cached !== undefined)
79
+ return cached;
80
+ this.assertSourceView(sourceView);
81
+ const configFile = join(sourceView.packageRoot, "tsconfig.json");
82
+ if (!existsSync(configFile))
83
+ throw new Error("spine-proto: authored interface discovery requires tsconfig.json");
84
+ const readSourceViewText = (path) => SourceSnapshotFiles.read(path);
85
+ const config = ts.readConfigFile(configFile, readSourceViewText);
86
+ if (config.error !== undefined)
87
+ throw new Error("spine-proto: authored interface discovery could not read tsconfig.json");
88
+ const parsed = ts.parseJsonConfigFileContent(config.config, { ...ts.sys, readFile: readSourceViewText }, sourceView.packageRoot, undefined, configFile);
89
+ if (parsed.errors.length > 0)
90
+ throw new Error("spine-proto: authored interface discovery has invalid tsconfig.json");
91
+ const configuredFiles = new Set(parsed.fileNames.map((file) => resolve(file)));
92
+ const authoredFiles = sourceView.authoredFiles.filter((file) => configuredFiles.has(resolve(file)));
93
+ const compilerFiles = sourceView.compilerFiles ?? sourceView.authoredFiles;
94
+ const capturedAuthored = new Map(compilerFiles.map((file) => [resolve(file), SourceSnapshotFiles.read(file)]));
95
+ const host = ts.createCompilerHost(parsed.options);
96
+ const redirect = (path) => {
97
+ const liveRelative = relative(sourceView.liveGeneratedRoot, resolve(path));
98
+ return liveRelative === "" || (!liveRelative.startsWith("..") && !isAbsolute(liveRelative))
99
+ ? join(sourceView.stagedGeneratedRoot, liveRelative)
100
+ : path;
101
+ };
102
+ const readFile = host.readFile.bind(host);
103
+ const fileExists = host.fileExists.bind(host);
104
+ host.readFile = (path) => capturedAuthored.get(resolve(path)) ?? readFile(redirect(path));
105
+ host.fileExists = (path) => capturedAuthored.has(resolve(path)) || fileExists(redirect(path));
106
+ const program = ts.createProgram({
107
+ options: parsed.options,
108
+ ...(parsed.projectReferences === undefined
109
+ ? {}
110
+ : { projectReferences: parsed.projectReferences }),
111
+ rootNames: [...authoredFiles, ...this.stagedFiles(sourceView.stagedGeneratedRoot)],
112
+ host,
113
+ });
114
+ this.programs.set(sourceView, program);
115
+ return program;
116
+ }
117
+ stagedFiles(root) {
118
+ return ts.sys.readDirectory(root, [".cts", ".mts", ".ts", ".tsx"], undefined, ["**/*"]);
119
+ }
120
+ assertSourceView(sourceView) {
121
+ const packageRoot = realpathSync(sourceView.packageRoot);
122
+ const canonicalPath = (path) => resolve(packageRoot, relative(sourceView.packageRoot, resolve(path)));
123
+ const liveGeneratedRoot = canonicalPath(sourceView.liveGeneratedRoot);
124
+ const parent = dirname(liveGeneratedRoot);
125
+ const generatedName = basename(liveGeneratedRoot);
126
+ const stage = join(parent, `.${generatedName}.stage-`);
127
+ const backup = join(parent, `.${generatedName}.`);
128
+ const dist = join(packageRoot, "dist");
129
+ const authoredFiles = new Set(sourceView.authoredFiles.map((file) => resolve(file)));
130
+ const isDeclaration = (path) => [".d.cts", ".d.mts", ".d.ts"].some((extension) => path.endsWith(extension));
131
+ const within = (root, path) => {
132
+ const pathRelative = relative(root, path);
133
+ return pathRelative === "" || (!pathRelative.startsWith("..") && !isAbsolute(pathRelative));
134
+ };
135
+ for (const file of sourceView.compilerFiles ?? sourceView.authoredFiles) {
136
+ const candidate = canonicalPath(file);
137
+ if (candidate === dist || candidate.startsWith(`${dist}/`))
138
+ throw new Error("spine-proto: authored interface discovery source path escapes model module");
139
+ if (lstatSync(file).isSymbolicLink() ||
140
+ !within(packageRoot, realpathSync(file)) ||
141
+ candidate === liveGeneratedRoot ||
142
+ candidate.startsWith(`${liveGeneratedRoot}/`) ||
143
+ candidate.startsWith(stage) ||
144
+ (candidate.startsWith(backup) && candidate.includes(".backup")) ||
145
+ (authoredFiles.has(resolve(file)) && isDeclaration(candidate)))
146
+ throw new Error("spine-proto: authored interface discovery source path escapes model module");
147
+ }
148
+ }
149
+ declaration(program, discoveryRoots, name) {
150
+ const sources = discoveryRoots
151
+ .map((file) => program.getSourceFile(file))
152
+ .filter((source) => source !== undefined);
153
+ const candidates = discoveryRoots.flatMap((file) => {
154
+ const source = program.getSourceFile(file);
155
+ if (source === undefined)
156
+ return [];
157
+ return source.statements.filter((statement) => ts.isInterfaceDeclaration(statement) && statement.name.text === name);
158
+ });
159
+ if (candidates.length === 0) {
160
+ if (sources.some((source) => source.statements.some((statement) => ts.isTypeAliasDeclaration(statement) && statement.name.text === name)))
161
+ throw new Error(`spine-proto: authored interface ${name}: declaration is not an interface`);
162
+ if (sources.some((source) => this.nestedInterface(source, name)))
163
+ throw new Error(`spine-proto: authored interface ${name}: nested interface is not supported`);
164
+ throw new Error(`spine-proto: authored interface ${name}: missing top-level interface`);
165
+ }
166
+ if (candidates.length > 1)
167
+ throw new Error(`spine-proto: authored interface ${name}: ambiguous top-level interface`);
168
+ const declaration = candidates[0];
169
+ if (declaration === undefined)
170
+ throw new Error(`spine-proto: authored interface ${name}: missing top-level interface`);
171
+ if (declaration.typeParameters !== undefined && declaration.typeParameters.length > 0)
172
+ throw new Error(`spine-proto: authored interface ${name}: generic interface is unbound`);
173
+ return declaration;
174
+ }
175
+ nestedInterface(source, name) {
176
+ let nested = false;
177
+ const visit = (node) => {
178
+ if (node !== source && ts.isInterfaceDeclaration(node) && node.name.text === name)
179
+ nested = true;
180
+ ts.forEachChild(node, visit);
181
+ };
182
+ ts.forEachChild(source, visit);
183
+ return nested;
184
+ }
185
+ assertNamedModuleExport(checker, declaration, name) {
186
+ const module = checker.getSymbolAtLocation(declaration.getSourceFile());
187
+ if (module === undefined ||
188
+ !checker.getExportsOfModule(module).some((candidate) => candidate.name === name))
189
+ throw new Error(`spine-proto: authored interface ${name}: declaration must be a named module export`);
190
+ }
191
+ messageType(program, checker, sourceView, member) {
192
+ const proto = member.file.proto.name;
193
+ const generated = join(sourceView.stagedGeneratedRoot, `${proto.slice(0, -".proto".length)}_pb.ts`);
194
+ const source = program.getSourceFile(generated);
195
+ if (source === undefined)
196
+ throw new Error(`spine-proto: authored interface ${member.name}: missing staged generated message`);
197
+ const module = checker.getSymbolAtLocation(source);
198
+ const packagePrefix = `${member.file.proto.package}.`;
199
+ const generatedName = member.typeName.startsWith(packagePrefix)
200
+ ? member.typeName.slice(packagePrefix.length).replaceAll(".", "_")
201
+ : member.name;
202
+ const symbol = module === undefined
203
+ ? undefined
204
+ : checker.getExportsOfModule(module).find((value) => value.name === generatedName);
205
+ if (symbol === undefined)
206
+ throw new Error(`spine-proto: authored interface ${member.name}: missing staged generated message`);
207
+ return checker.getDeclaredTypeOfSymbol(symbol);
208
+ }
209
+ assertLocalParents(checker, declaration, name, active, localSources) {
210
+ const clauses = Object.getOwnPropertyDescriptor(declaration, "heritageClauses")?.value;
211
+ if (clauses === undefined)
212
+ return;
213
+ for (const clause of clauses) {
214
+ for (const parent of clause.types) {
215
+ const referenced = checker.getSymbolAtLocation(parent.expression);
216
+ const symbol = referenced !== undefined && (referenced.flags & ts.SymbolFlags.Alias) !== 0
217
+ ? checker.getAliasedSymbol(referenced)
218
+ : referenced;
219
+ if (symbol === undefined)
220
+ throw new Error(`spine-proto: authored interface ${name}: extends parent must stay in the model module`);
221
+ if (active.has(symbol))
222
+ throw new Error(`spine-proto: authored interface ${name}: cyclic extends chain`);
223
+ active.add(symbol);
224
+ const parentDeclaration = symbol.declarations?.find(ts.isInterfaceDeclaration);
225
+ if (parentDeclaration === undefined)
226
+ throw new Error(`spine-proto: authored interface ${name}: extends parent must stay in the model module`);
227
+ if (parentDeclaration.typeParameters !== undefined &&
228
+ parentDeclaration.typeParameters.length > 0)
229
+ throw new Error(`spine-proto: authored interface ${name}: generic extends parent is not supported`);
230
+ if (!localSources.has(resolve(parentDeclaration.getSourceFile().fileName)))
231
+ throw new Error(`spine-proto: authored interface ${name}: extends parent must stay in the model module`);
232
+ this.assertLocalParents(checker, parentDeclaration, name, active, localSources);
233
+ active.delete(symbol);
234
+ }
235
+ }
236
+ }
237
+ importPath(sourceView, name, source) {
238
+ const output = join(sourceView.liveGeneratedRoot, "interfaces", `${name}.ts`);
239
+ const extension = extname(source);
240
+ const path = `${relative(dirname(output), source.slice(0, -extension.length))}.js`;
241
+ return path.startsWith(".") ? path : `./${path}`;
242
+ }
243
+ }
244
+ //# sourceMappingURL=authored-interface-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authored-interface-provider.js","sourceRoot":"","sources":["../../../src/generation/authored-interface-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG5F,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ5B,MAAM,yBAAyB,GAAG,gEAAgE,CAAC;AAEnG,MAAM,mBAAmB,GAAG,MAAM,CA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BAC/E,IAAI,iBAAiB,KAAK,SAAS;oBACjC,MAAM,IAAI,KAAK,CACb,mCAAmC,IAAI,gDAAgD,CACxF,CAAC;gBACJ,IACE,iBAAiB,CAAC,cAAc,KAAK,SAAS;oBAC9C,iBAAiB,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;oBAE3C,MAAM,IAAI,KAAK,CACb,mCAAmC,IAAI,2CAA2C,CACnF,CAAC;gBACJ,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC;oBACxE,MAAM,IAAI,KAAK,CACb,mCAAmC,IAAI,gDAAgD,CACxF,CAAC;gBACJ,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;gBAChF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAEO,UAAU,CAAC,UAA2B,EAAE,IAAY,EAAE,MAAc;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,YAAY,EAAE,GAAG,IAAI,KAAK,CAAC,CAAC;QAC9E,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC;QACnF,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;IACnD,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Renders a deterministic generated-file notice.
3
+ */
4
+ export declare const generatedNotice: (sources: readonly string[]) => string;
5
+ /**
6
+ * Renders the deterministic generated-file notice for script consumers.
7
+ */
8
+ export declare const generatedFileNotice: (sources: readonly string[]) => string;
9
+ /**
10
+ * Applies generated provenance to TypeScript source.
11
+ */
12
+ export declare const generatedSource: (source: string, sources: readonly string[]) => string;
13
+ /**
14
+ * Applies generated provenance using the script-compatible name.
15
+ */
16
+ export declare const generatedTypeScript: (source: string, sources: readonly string[]) => string;
17
+ /**
18
+ * Normalizes generated TypeScript files below a directory.
19
+ */
20
+ export declare const normalizeGeneratedTree: (root: string, sources: readonly string[]) => void;
21
+ //# sourceMappingURL=generated-source-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-source-policy.d.ts","sourceRoot":"","sources":["../../../src/generation/generated-source-policy.ts"],"names":[],"mappings":"AA+IA;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,MAC7B,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,MAAwB,CAAC;AAE3F;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,MAC7C,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,MACjE,CAAC;AAElB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,IAC3C,CAAC"}
@@ -0,0 +1,126 @@
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
+ /* Shared publishable generated-TypeScript provenance policy. */
15
+ import { readFileSync, readdirSync, writeFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ /**
18
+ * Renders a deterministic generated-file notice.
19
+ * @param sources Stable source Proto import paths.
20
+ * @returns The generated-file notice.
21
+ */
22
+ const generatedPolicy = Object.freeze({
23
+ generatedNotice(sources) {
24
+ const paths = [...new Set(sources)].sort();
25
+ if (paths.length === 0 || !paths.every(generatedPolicy.stableProtoPath))
26
+ throw new Error(`spine-proto: generated source requires stable Proto provenance ${JSON.stringify(paths)}`);
27
+ return [
28
+ "/*",
29
+ " * Generated by Spine TypeScript. Do not edit manually.",
30
+ ...paths.map((path) => ` * Source Proto: ${path}`),
31
+ " */",
32
+ "",
33
+ "",
34
+ ].join("\n");
35
+ },
36
+ /* Applies generated provenance to TypeScript source. */
37
+ generatedSource(source, sources) {
38
+ let copiedPreamble = source.replace(/^\/\*\n \* Generated by Spine TypeScript\. Do not edit manually\.\n(?: \* Source Proto: .*\n)+ \*\/\n*/u, "");
39
+ const leadingBlock = /^\/\*[\s\S]*?\*\/\s*/u.exec(copiedPreamble)?.[0];
40
+ if (leadingBlock !== undefined &&
41
+ /copyright|licen[cs](?:ed|e)|proprietary|confidential/iu.test(leadingBlock))
42
+ copiedPreamble = copiedPreamble.slice(leadingBlock.length);
43
+ const leadingLines = /^(?:(?:\/\/[^\n]*\n)+)/u.exec(copiedPreamble)?.[0];
44
+ if (leadingLines !== undefined &&
45
+ /copyright|licen[cs](?:ed|e)|proprietary|confidential/iu.test(leadingLines))
46
+ copiedPreamble = `${leadingLines
47
+ .split("\n")
48
+ .filter((line) => line.startsWith("// @generated"))
49
+ .join("\n")}\n${copiedPreamble.slice(leadingLines.length)}`;
50
+ const withoutCopyright = copiedPreamble;
51
+ const lines = withoutCopyright.split("\n");
52
+ const generatedAt = lines.findIndex((line) => line.startsWith("// @generated"));
53
+ const body = generatedAt !== -1 && lines.slice(0, generatedAt).some((line) => line.includes("CodeMatters"))
54
+ ? lines.slice(generatedAt).join("\n")
55
+ : withoutCopyright;
56
+ const provenance = ` * Generated from Proto: ${[...new Set(sources)].sort().join(", ")}.`;
57
+ return `${generatedPolicy.generatedNotice(sources)}${body.replace(/(^|\n)(\/\*\*[\s\S]*?\*\/\n)?(export (?:declare )?(?:const|interface|enum|type|class|function) )/gu, (_match, prefix, documentation, declaration) => {
58
+ const cleaned = (documentation ?? "").replace(/ \* Generated from Proto: .*\.\n/gu, "");
59
+ const oneLine = /^\/\*\*[ \t]*([^\n]*?)[ \t]*\*\/\n$/u.exec(cleaned);
60
+ const normalized = oneLine === null ? cleaned : `/**\n * ${oneLine[1] ?? ""}\n */\n`;
61
+ return cleaned === ""
62
+ ? `${prefix}/**\n${provenance}\n */\n${declaration}`
63
+ : `${prefix}${normalized.replace(/ \*\/\n$/u, `${provenance}\n */\n`)}${declaration}`;
64
+ })}`;
65
+ },
66
+ /* Normalizes generated TypeScript files below a directory. */
67
+ normalizeGeneratedTree(root, sources) {
68
+ generatedPolicy.normalizeGeneratedTreeAt(root, sources, 0, { entries: 0 });
69
+ },
70
+ normalizeGeneratedTreeAt(root, sources, depth, state) {
71
+ if (depth > 64 || state.entries > 1_000)
72
+ throw new Error("spine-proto: generated source traversal exceeds bounded inventory");
73
+ for (const entry of readdirSync(root, { withFileTypes: true })) {
74
+ state.entries += 1;
75
+ if (state.entries > 1_000)
76
+ throw new Error("spine-proto: generated source traversal exceeds bounded inventory");
77
+ const path = join(root, entry.name);
78
+ if (entry.isDirectory())
79
+ generatedPolicy.normalizeGeneratedTreeAt(path, sources, depth + 1, state);
80
+ else if (entry.isFile() &&
81
+ (/(?:_pb|rejections|_columns|proto-module|generated-handler-registry)\.ts$/u.test(path) ||
82
+ /[\\/]interfaces[\\/].+\.ts$/u.test(path))) {
83
+ const source = readFileSync(path, "utf8");
84
+ const derived = [
85
+ ...source.matchAll(/from "(?:[^" ]+\/generated\/)?([^" ]+)_pb\.js"/gu),
86
+ ].map((match) => (match[1] ?? "").replace(/^\.\//u, "").replace(/^.*?spine\//u, "spine/") + ".proto");
87
+ const generated = [...source.matchAll(/@generated from file ([^\s)]+)/gu)].map((match) => match[1] ?? "");
88
+ const provenance = generated.length > 0 ? generated : derived.length > 0 ? derived : sources;
89
+ if (provenance.length > 0)
90
+ writeFileSync(path, generatedPolicy.generatedSource(source, provenance), "utf8");
91
+ }
92
+ }
93
+ },
94
+ stableProtoPath(path) {
95
+ const components = path.split("/");
96
+ return (typeof path === "string" &&
97
+ path.length > 0 &&
98
+ path.endsWith(".proto") &&
99
+ !path.startsWith("/") &&
100
+ !/^[A-Za-z]:/u.test(path) &&
101
+ !components.some((part) => part === "" || part === "." || part === "..") &&
102
+ !path.includes("\\") &&
103
+ !components.some((part) => part === "tmp" || part === "temp" || /^\.(?:generated|stage|backup)(?:-|$)/u.test(part)));
104
+ },
105
+ });
106
+ /**
107
+ * Renders a deterministic generated-file notice.
108
+ */
109
+ export const generatedNotice = generatedPolicy.generatedNotice;
110
+ /**
111
+ * Renders the deterministic generated-file notice for script consumers.
112
+ */
113
+ export const generatedFileNotice = generatedNotice;
114
+ /**
115
+ * Applies generated provenance to TypeScript source.
116
+ */
117
+ export const generatedSource = generatedPolicy.generatedSource;
118
+ /**
119
+ * Applies generated provenance using the script-compatible name.
120
+ */
121
+ export const generatedTypeScript = generatedSource;
122
+ /**
123
+ * Normalizes generated TypeScript files below a directory.
124
+ */
125
+ export const normalizeGeneratedTree = generatedPolicy.normalizeGeneratedTree;
126
+ //# sourceMappingURL=generated-source-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-source-policy.js","sourceRoot":"","sources":["../../../src/generation/generated-source-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAY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,QAAQ;YACxB,IAAI,CAAC,MAAM,GAAG,CAAC;YACf,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACvB,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YACrB,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;YACzB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC;YACxE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpB,CAAC,UAAU,CAAC,IAAI,CACd,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,MAAM,IAAI,uCAAuC,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1F,CACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,eAAe,CAAC,eAAe,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA2C,eAAe,CAAC;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,eAAe,CAAC,eAAe,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,eAAe,CAAC;AAElB;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GACjC,eAAe,CAAC,sBAAsB,CAAC"}
@@ -0,0 +1,84 @@
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
+ import { lstatSync, readFileSync, readdirSync } from "node:fs";
16
+ import { join, relative, sep } from "node:path";
17
+
18
+ export const generationMarkerFile = ".spine-proto-generation.json";
19
+
20
+ function canonicalJson(value) {
21
+ if (Array.isArray(value)) return value.map(canonicalJson);
22
+ if (typeof value === "object" && value !== null)
23
+ return Object.fromEntries(
24
+ Object.entries(value)
25
+ .sort(([left], [right]) => left.localeCompare(right))
26
+ .map(([key, nested]) => [key, canonicalJson(nested)]),
27
+ );
28
+ return value;
29
+ }
30
+
31
+ function markerId(root) {
32
+ try {
33
+ const marker = JSON.parse(readFileSync(join(root, generationMarkerFile), "utf8"));
34
+ return typeof marker.generationId === "string" && marker.generationId.length > 0
35
+ ? marker.generationId
36
+ : undefined;
37
+ } catch {
38
+ return undefined;
39
+ }
40
+ }
41
+
42
+ function treeContents(root) {
43
+ const files = [];
44
+ const pending = [[root, 0]];
45
+ let entries = 0;
46
+ while (pending.length > 0) {
47
+ const [directory, depth] = pending.pop();
48
+ if (depth > 64) throw new Error("generated TypeScript traversal exceeds bounded inventory");
49
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
50
+ entries += 1;
51
+ if (entries > 1_000)
52
+ throw new Error("generated TypeScript traversal exceeds bounded inventory");
53
+ const path = join(directory, entry.name);
54
+ if (lstatSync(path).isSymbolicLink())
55
+ throw new Error("generated TypeScript traversal must not contain symlinks");
56
+ if (entry.isDirectory()) pending.push([path, depth + 1]);
57
+ else if (entry.isFile() && entry.name !== generationMarkerFile)
58
+ files.push([relative(root, path).split(sep).join("/"), readFileSync(path, "utf8")]);
59
+ }
60
+ }
61
+ return files.sort(([left], [right]) => left.localeCompare(right));
62
+ }
63
+
64
+ export function reusableGenerationId(liveManifestPath, liveRoot, stagedManifest, stagedRoot) {
65
+ try {
66
+ const liveManifest = JSON.parse(readFileSync(liveManifestPath, "utf8"));
67
+ const { generationId: liveGenerationId, ...liveContents } = liveManifest;
68
+ const { generationId: stagedGenerationId, ...stagedContents } = stagedManifest;
69
+ if (
70
+ liveManifest.formatVersion !== 2 ||
71
+ typeof liveGenerationId !== "string" ||
72
+ liveGenerationId.length === 0 ||
73
+ markerId(liveRoot) !== liveGenerationId ||
74
+ markerId(stagedRoot) !== stagedGenerationId ||
75
+ JSON.stringify(canonicalJson(liveContents)) !==
76
+ JSON.stringify(canonicalJson(stagedContents)) ||
77
+ JSON.stringify(treeContents(liveRoot)) !== JSON.stringify(treeContents(stagedRoot))
78
+ )
79
+ return undefined;
80
+ return liveGenerationId;
81
+ } catch {
82
+ return undefined;
83
+ }
84
+ }