@alpaca-software/40kdc-data 0.1.2 → 0.1.3
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/README.md +2 -0
- package/dist/abilities-resolver/resolver.d.ts +13 -4
- package/dist/abilities-resolver/resolver.d.ts.map +1 -1
- package/dist/abilities-resolver/resolver.js +22 -15
- package/dist/abilities-resolver/resolver.js.map +1 -1
- package/dist/audit-coverage.d.ts +78 -0
- package/dist/audit-coverage.d.ts.map +1 -0
- package/dist/audit-coverage.js +341 -0
- package/dist/audit-coverage.js.map +1 -0
- package/dist/author-batch.d.ts +147 -0
- package/dist/author-batch.d.ts.map +1 -0
- package/dist/author-batch.js +675 -0
- package/dist/author-batch.js.map +1 -0
- package/dist/author-input.d.ts +37 -0
- package/dist/author-input.d.ts.map +1 -0
- package/dist/author-input.js +162 -0
- package/dist/author-input.js.map +1 -0
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/translate.d.ts.map +1 -1
- package/dist/commands/translate.js +9 -4
- package/dist/commands/translate.js.map +1 -1
- package/dist/cruncher/attribution.d.ts +66 -0
- package/dist/cruncher/attribution.d.ts.map +1 -0
- package/dist/cruncher/attribution.js +88 -0
- package/dist/cruncher/attribution.js.map +1 -0
- package/dist/cruncher/buffs.d.ts +23 -1
- package/dist/cruncher/buffs.d.ts.map +1 -1
- package/dist/cruncher/buffs.js +1 -1
- package/dist/cruncher/buffs.js.map +1 -1
- package/dist/cruncher/from-dsl.d.ts +32 -0
- package/dist/cruncher/from-dsl.d.ts.map +1 -1
- package/dist/cruncher/from-dsl.js +485 -40
- package/dist/cruncher/from-dsl.js.map +1 -1
- package/dist/cruncher/index.d.ts +1 -0
- package/dist/cruncher/index.d.ts.map +1 -1
- package/dist/cruncher/index.js +1 -0
- package/dist/cruncher/index.js.map +1 -1
- package/dist/data/bundle.generated.js +1 -1
- package/dist/data/bundle.generated.js.map +1 -1
- package/dist/data/collection.d.ts +9 -0
- package/dist/data/collection.d.ts.map +1 -1
- package/dist/data/collection.js +14 -0
- package/dist/data/collection.js.map +1 -1
- package/dist/data/dataset.d.ts +80 -2
- package/dist/data/dataset.d.ts.map +1 -1
- package/dist/data/dataset.js +143 -6
- package/dist/data/dataset.js.map +1 -1
- package/dist/data/entities.d.ts +2 -5
- package/dist/data/entities.d.ts.map +1 -1
- package/dist/data/entities.js.map +1 -1
- package/dist/data/index.d.ts +3 -2
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/data/roster-resolve.d.ts +26 -1
- package/dist/data/roster-resolve.d.ts.map +1 -1
- package/dist/data/roster-resolve.js +46 -0
- package/dist/data/roster-resolve.js.map +1 -1
- package/dist/export/index.d.ts +1 -0
- package/dist/export/index.d.ts.map +1 -1
- package/dist/export/index.js +3 -0
- package/dist/export/index.js.map +1 -1
- package/dist/export/rosterizer.d.ts +3 -0
- package/dist/export/rosterizer.d.ts.map +1 -0
- package/dist/export/rosterizer.js +144 -0
- package/dist/export/rosterizer.js.map +1 -0
- package/dist/export/serializer.d.ts +1 -1
- package/dist/export/serializer.d.ts.map +1 -1
- package/dist/export/serializer.js.map +1 -1
- package/dist/gen-conformance.js +212 -11
- package/dist/gen-conformance.js.map +1 -1
- package/dist/import/gw.d.ts +69 -0
- package/dist/import/gw.d.ts.map +1 -0
- package/dist/import/gw.js +245 -0
- package/dist/import/gw.js.map +1 -0
- package/dist/import/import-roster.d.ts +52 -3
- package/dist/import/import-roster.d.ts.map +1 -1
- package/dist/import/import-roster.js +114 -4
- package/dist/import/import-roster.js.map +1 -1
- package/dist/import/index.d.ts +2 -2
- package/dist/import/index.d.ts.map +1 -1
- package/dist/import/index.js +1 -1
- package/dist/import/index.js.map +1 -1
- package/dist/import/listforge.d.ts.map +1 -1
- package/dist/import/listforge.js +15 -1
- package/dist/import/listforge.js.map +1 -1
- package/dist/import/newrecruit-text.d.ts +3 -0
- package/dist/import/newrecruit-text.d.ts.map +1 -1
- package/dist/import/newrecruit-text.js +6 -0
- package/dist/import/newrecruit-text.js.map +1 -1
- package/dist/import/newrecruit-wtc.d.ts.map +1 -1
- package/dist/import/newrecruit-wtc.js +10 -7
- package/dist/import/newrecruit-wtc.js.map +1 -1
- package/dist/import/rosterizer.d.ts +70 -0
- package/dist/import/rosterizer.d.ts.map +1 -0
- package/dist/import/rosterizer.js +348 -0
- package/dist/import/rosterizer.js.map +1 -0
- package/dist/import/types.d.ts +1 -1
- package/dist/import/types.d.ts.map +1 -1
- package/dist/import/types.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/migrations/2026-weapon-keywords.js +4 -0
- package/dist/migrations/2026-weapon-keywords.js.map +1 -1
- package/dist/runner.d.ts +38 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +492 -0
- package/dist/runner.js.map +1 -0
- package/dist/scrub-ip.d.ts +14 -0
- package/dist/scrub-ip.d.ts.map +1 -0
- package/dist/scrub-ip.js +88 -0
- package/dist/scrub-ip.js.map +1 -0
- package/package.json +9 -2
- package/schemas/core/roster.schema.json +3 -1
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Dataset } from "./data/dataset.js";
|
|
3
|
+
import type Ajv from "ajv";
|
|
4
|
+
export type RunnerResponse = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error_kind: ErrorKind;
|
|
10
|
+
error_payload?: unknown;
|
|
11
|
+
};
|
|
12
|
+
declare const ERROR_KINDS: readonly ["INVALID_INPUT", "UNKNOWN_OP", "UNKNOWN_ENTITY", "IMPORT_FAILED", "EXPORT_FAILED", "VALIDATION_ERROR", "CRUNCH_ERROR", "INTERNAL_ERROR"];
|
|
13
|
+
type ErrorKind = (typeof ERROR_KINDS)[number];
|
|
14
|
+
export interface RunnerState {
|
|
15
|
+
initialized: boolean;
|
|
16
|
+
locale: string;
|
|
17
|
+
tz: string;
|
|
18
|
+
seed: number;
|
|
19
|
+
dataset?: Dataset;
|
|
20
|
+
validator?: Ajv;
|
|
21
|
+
}
|
|
22
|
+
export declare function createRunnerState(): RunnerState;
|
|
23
|
+
/**
|
|
24
|
+
* Apply one decoded request to the runner state and return the response. Used
|
|
25
|
+
* directly by tests; the CLI loop wraps it with line parsing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function dispatch(state: RunnerState, req: {
|
|
28
|
+
op: string;
|
|
29
|
+
args?: unknown;
|
|
30
|
+
}): RunnerResponse;
|
|
31
|
+
/**
|
|
32
|
+
* Process one line of stdin (one NDJSON request) and return the line that
|
|
33
|
+
* should be written to stdout (one NDJSON response). Returns `null` only on
|
|
34
|
+
* fully-empty input lines, which should be silently ignored.
|
|
35
|
+
*/
|
|
36
|
+
export declare function processRequest(state: RunnerState, line: string): string | null;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";AAsBA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AA8C3B,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,SAAS,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE,QAAA,MAAM,WAAW,oJASP,CAAC;AACX,KAAK,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAgB9C,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB;AAED,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C;AAoTD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,cAAc,CA4BhG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc9E"}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* NDJSON conformance runner — the TypeScript implementation of the wire
|
|
4
|
+
* protocol in `conformance/RUNNER_PROTOCOL.md`. Each line on stdin is a JSON
|
|
5
|
+
* request `{op, args?}`; each line on stdout is a JSON response
|
|
6
|
+
* `{ok: true, value}` or `{ok: false, error_kind, error_payload?}`.
|
|
7
|
+
*
|
|
8
|
+
* This file exports {@link processRequest} so vitest can drive the runner
|
|
9
|
+
* in-process without spawning a child; the bottom `if (isCliMain())` block
|
|
10
|
+
* wires the same dispatcher to real stdin/stdout for the cross-impl differ.
|
|
11
|
+
*
|
|
12
|
+
* The runner is a *thin* wrapper over the existing public API — it is not the
|
|
13
|
+
* canonical way to use the package. Library consumers should import the
|
|
14
|
+
* functions directly; the runner exists to give the cross-implementation
|
|
15
|
+
* differ a uniform interface across language ports.
|
|
16
|
+
*/
|
|
17
|
+
import { createInterface } from "node:readline";
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import process from "node:process";
|
|
22
|
+
import { Dataset } from "./data/dataset.js";
|
|
23
|
+
import { normalizeName } from "./data/normalize.js";
|
|
24
|
+
import { exportRoster } from "./export/index.js";
|
|
25
|
+
import { importRoster, tryImportRoster } from "./import/import-roster.js";
|
|
26
|
+
import { createValidator } from "./schema-loader.js";
|
|
27
|
+
import { crunch } from "./cruncher/index.js";
|
|
28
|
+
// -----------------------------------------------------------------------------
|
|
29
|
+
// Constants — spec version and implementation identity.
|
|
30
|
+
// -----------------------------------------------------------------------------
|
|
31
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
function loadSpecVersion() {
|
|
33
|
+
// The corpus lives at repo-root/conformance/. Walk up from tools/src/ until
|
|
34
|
+
// we find it so the runner works both from source (tsx) and from dist/.
|
|
35
|
+
for (const candidate of [
|
|
36
|
+
join(__dirname, "../../conformance/SPEC_VERSION"),
|
|
37
|
+
join(__dirname, "../../../conformance/SPEC_VERSION"),
|
|
38
|
+
]) {
|
|
39
|
+
try {
|
|
40
|
+
return Number.parseInt(readFileSync(candidate, "utf8").trim(), 10);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// try next
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error("could not locate conformance/SPEC_VERSION");
|
|
47
|
+
}
|
|
48
|
+
function loadImplVersion() {
|
|
49
|
+
for (const candidate of [
|
|
50
|
+
join(__dirname, "../package.json"),
|
|
51
|
+
join(__dirname, "../../package.json"),
|
|
52
|
+
]) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(readFileSync(candidate, "utf8")).version;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// try next
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return "unknown";
|
|
61
|
+
}
|
|
62
|
+
const SPEC_VERSION = loadSpecVersion();
|
|
63
|
+
const IMPL_VERSION = loadImplVersion();
|
|
64
|
+
const IMPL_NAME = "ts";
|
|
65
|
+
const ERROR_KINDS = [
|
|
66
|
+
"INVALID_INPUT",
|
|
67
|
+
"UNKNOWN_OP",
|
|
68
|
+
"UNKNOWN_ENTITY",
|
|
69
|
+
"IMPORT_FAILED",
|
|
70
|
+
"EXPORT_FAILED",
|
|
71
|
+
"VALIDATION_ERROR",
|
|
72
|
+
"CRUNCH_ERROR",
|
|
73
|
+
"INTERNAL_ERROR",
|
|
74
|
+
];
|
|
75
|
+
function ok(value) {
|
|
76
|
+
return { ok: true, value };
|
|
77
|
+
}
|
|
78
|
+
function err(kind, payload) {
|
|
79
|
+
return payload === undefined
|
|
80
|
+
? { ok: false, error_kind: kind }
|
|
81
|
+
: { ok: false, error_kind: kind, error_payload: payload };
|
|
82
|
+
}
|
|
83
|
+
export function createRunnerState() {
|
|
84
|
+
return { initialized: false, locale: "C", tz: "UTC", seed: 0 };
|
|
85
|
+
}
|
|
86
|
+
function getDataset(state) {
|
|
87
|
+
if (!state.dataset)
|
|
88
|
+
state.dataset = Dataset.embedded();
|
|
89
|
+
return state.dataset;
|
|
90
|
+
}
|
|
91
|
+
function getValidator(state) {
|
|
92
|
+
if (!state.validator)
|
|
93
|
+
state.validator = createValidator();
|
|
94
|
+
return state.validator;
|
|
95
|
+
}
|
|
96
|
+
// -----------------------------------------------------------------------------
|
|
97
|
+
// Op handlers.
|
|
98
|
+
// -----------------------------------------------------------------------------
|
|
99
|
+
function handleInit(state, args) {
|
|
100
|
+
if (state.initialized) {
|
|
101
|
+
return err("INVALID_INPUT", { detail: "init called twice" });
|
|
102
|
+
}
|
|
103
|
+
if (typeof args !== "object" || args === null) {
|
|
104
|
+
return err("INVALID_INPUT", { detail: "init args must be an object" });
|
|
105
|
+
}
|
|
106
|
+
const a = args;
|
|
107
|
+
if (a.spec_version !== SPEC_VERSION) {
|
|
108
|
+
return err("INVALID_INPUT", {
|
|
109
|
+
detail: `spec_version mismatch: runner=${SPEC_VERSION}, request=${String(a.spec_version)}`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (a.locale !== "C") {
|
|
113
|
+
return err("INVALID_INPUT", { detail: `unsupported locale: ${String(a.locale)} (only "C")` });
|
|
114
|
+
}
|
|
115
|
+
if (a.tz !== "UTC") {
|
|
116
|
+
return err("INVALID_INPUT", { detail: `unsupported tz: ${String(a.tz)} (only "UTC")` });
|
|
117
|
+
}
|
|
118
|
+
if (typeof a.seed !== "number") {
|
|
119
|
+
return err("INVALID_INPUT", { detail: "seed must be a number" });
|
|
120
|
+
}
|
|
121
|
+
state.initialized = true;
|
|
122
|
+
state.locale = a.locale;
|
|
123
|
+
state.tz = a.tz;
|
|
124
|
+
state.seed = a.seed;
|
|
125
|
+
return ok({ impl: IMPL_NAME, spec_version: SPEC_VERSION, impl_version: IMPL_VERSION });
|
|
126
|
+
}
|
|
127
|
+
function handleNormalize(args) {
|
|
128
|
+
if (typeof args !== "object" || args === null) {
|
|
129
|
+
return err("INVALID_INPUT", { detail: "normalize args must be an object" });
|
|
130
|
+
}
|
|
131
|
+
const a = args;
|
|
132
|
+
if (typeof a.input !== "string") {
|
|
133
|
+
return err("INVALID_INPUT", { detail: "normalize.input must be a string" });
|
|
134
|
+
}
|
|
135
|
+
return ok(normalizeName(a.input));
|
|
136
|
+
}
|
|
137
|
+
function handleImport(state, args) {
|
|
138
|
+
if (typeof args !== "object" || args === null) {
|
|
139
|
+
return err("INVALID_INPUT", { detail: "import args must be an object" });
|
|
140
|
+
}
|
|
141
|
+
const a = args;
|
|
142
|
+
if (typeof a.input !== "string") {
|
|
143
|
+
return err("INVALID_INPUT", { detail: "import.input must be a string" });
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
// The wire protocol carries every input as a string: JSON payloads come
|
|
147
|
+
// through as the JSON text, text payloads come through as-is. The import
|
|
148
|
+
// pipeline decides which by attempting to parse JSON first.
|
|
149
|
+
const trimmed = a.input.trimStart();
|
|
150
|
+
let decoded;
|
|
151
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
152
|
+
try {
|
|
153
|
+
decoded = JSON.parse(a.input);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
decoded = a.input;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
decoded = a.input;
|
|
161
|
+
}
|
|
162
|
+
const roster = importRoster(decoded, { dataset: getDataset(state) });
|
|
163
|
+
return ok(roster);
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
return err("IMPORT_FAILED", { detail: e.message, format: a.format ?? null });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function handleTryImport(state, args) {
|
|
170
|
+
if (typeof args !== "object" || args === null) {
|
|
171
|
+
return err("INVALID_INPUT", { detail: "try_import args must be an object" });
|
|
172
|
+
}
|
|
173
|
+
const a = args;
|
|
174
|
+
if (typeof a.input !== "string") {
|
|
175
|
+
return err("INVALID_INPUT", { detail: "try_import.input must be a string" });
|
|
176
|
+
}
|
|
177
|
+
const result = tryImportRoster(a.input, { dataset: getDataset(state) });
|
|
178
|
+
if (!result.ok) {
|
|
179
|
+
return err("IMPORT_FAILED", { reason: result.reason, message: result.message });
|
|
180
|
+
}
|
|
181
|
+
return ok({ format: result.format, roster: result.roster });
|
|
182
|
+
}
|
|
183
|
+
const EXPORT_FORMATS = [
|
|
184
|
+
"newrecruit-json",
|
|
185
|
+
"newrecruit-wtc-compact",
|
|
186
|
+
"newrecruit-wtc-full",
|
|
187
|
+
"newrecruit-simple",
|
|
188
|
+
"roster-json",
|
|
189
|
+
"rosterizer",
|
|
190
|
+
];
|
|
191
|
+
function handleExport(args) {
|
|
192
|
+
if (typeof args !== "object" || args === null) {
|
|
193
|
+
return err("INVALID_INPUT", { detail: "export args must be an object" });
|
|
194
|
+
}
|
|
195
|
+
const a = args;
|
|
196
|
+
if (typeof a.format !== "string" || !EXPORT_FORMATS.includes(a.format)) {
|
|
197
|
+
return err("INVALID_INPUT", { detail: `unknown export format: ${String(a.format)}` });
|
|
198
|
+
}
|
|
199
|
+
if (typeof a.roster !== "object" || a.roster === null) {
|
|
200
|
+
return err("INVALID_INPUT", { detail: "export.roster must be an object" });
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// We assume the caller passes the canonical resolved Roster shape; if they
|
|
204
|
+
// pass something the serializer can't handle, this throws.
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
+
return ok(exportRoster(a.roster, a.format));
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
return err("EXPORT_FAILED", { detail: e.message });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function handleLinkedQuery(state, args) {
|
|
213
|
+
if (typeof args !== "object" || args === null) {
|
|
214
|
+
return err("INVALID_INPUT", { detail: "linked_query args must be an object" });
|
|
215
|
+
}
|
|
216
|
+
const a = args;
|
|
217
|
+
if (typeof a.query !== "string") {
|
|
218
|
+
return err("INVALID_INPUT", { detail: "linked_query.query must be a string" });
|
|
219
|
+
}
|
|
220
|
+
const ds = getDataset(state);
|
|
221
|
+
const input = (a.input ?? {});
|
|
222
|
+
try {
|
|
223
|
+
switch (a.query) {
|
|
224
|
+
case "find_unit":
|
|
225
|
+
return ok(ds.units.find(input.query ?? "")?.id ?? null);
|
|
226
|
+
case "find_weapon":
|
|
227
|
+
return ok(ds.weapons.find(input.query ?? "")?.id ?? null);
|
|
228
|
+
case "find_faction":
|
|
229
|
+
return ok(ds.factions.find(input.query ?? "")?.id ?? null);
|
|
230
|
+
case "find_ability":
|
|
231
|
+
return ok(ds.abilities.find(input.query ?? "")?.id ?? null);
|
|
232
|
+
case "abilities_of": {
|
|
233
|
+
const u = ds.units.get(input.unitId);
|
|
234
|
+
if (!u)
|
|
235
|
+
return err("UNKNOWN_ENTITY", { kind: "unit", id: input.unitId });
|
|
236
|
+
return ok(u.abilities.map((x) => x.id));
|
|
237
|
+
}
|
|
238
|
+
case "weapons_of": {
|
|
239
|
+
const u = ds.units.get(input.unitId);
|
|
240
|
+
if (!u)
|
|
241
|
+
return err("UNKNOWN_ENTITY", { kind: "unit", id: input.unitId });
|
|
242
|
+
return ok(u.weapons.map((x) => x.id));
|
|
243
|
+
}
|
|
244
|
+
case "phases_of": {
|
|
245
|
+
const ab = ds.abilities.get(input.abilityId);
|
|
246
|
+
if (!ab)
|
|
247
|
+
return err("UNKNOWN_ENTITY", { kind: "ability", id: input.abilityId });
|
|
248
|
+
return ok([...ab.phases]);
|
|
249
|
+
}
|
|
250
|
+
case "faction_of": {
|
|
251
|
+
const u = ds.units.get(input.unitId);
|
|
252
|
+
if (!u)
|
|
253
|
+
return err("UNKNOWN_ENTITY", { kind: "unit", id: input.unitId });
|
|
254
|
+
return ok(u.faction?.id ?? null);
|
|
255
|
+
}
|
|
256
|
+
case "abilities_of_faction":
|
|
257
|
+
return ok(ds.abilities.byFaction(input.factionId).map((x) => x.id));
|
|
258
|
+
case "weapons_of_faction": {
|
|
259
|
+
const f = ds.factions.get(input.factionId);
|
|
260
|
+
if (!f)
|
|
261
|
+
return err("UNKNOWN_ENTITY", { kind: "faction", id: input.factionId });
|
|
262
|
+
return ok(f.weapons.map((x) => x.id));
|
|
263
|
+
}
|
|
264
|
+
default:
|
|
265
|
+
return err("INVALID_INPUT", { detail: `unknown linked_query: ${a.query}` });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
return err("INTERNAL_ERROR", { detail: e.message });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const VALIDATOR_TARGETS = {
|
|
273
|
+
unit: "https://40kdc.dev/schemas/core/unit.schema.json",
|
|
274
|
+
weapon: "https://40kdc.dev/schemas/core/weapon.schema.json",
|
|
275
|
+
faction: "https://40kdc.dev/schemas/core/faction.schema.json",
|
|
276
|
+
ability: "https://40kdc.dev/schemas/enrichment/ability-dsl/ability.schema.json",
|
|
277
|
+
};
|
|
278
|
+
function ajvKeywordToCode(keyword) {
|
|
279
|
+
switch (keyword) {
|
|
280
|
+
case "required":
|
|
281
|
+
return "REQUIRED_MISSING";
|
|
282
|
+
case "type":
|
|
283
|
+
return "TYPE_MISMATCH";
|
|
284
|
+
case "enum":
|
|
285
|
+
return "ENUM_VIOLATION";
|
|
286
|
+
case "pattern":
|
|
287
|
+
case "format":
|
|
288
|
+
return "PATTERN_MISMATCH";
|
|
289
|
+
case "minimum":
|
|
290
|
+
case "maximum":
|
|
291
|
+
case "exclusiveMinimum":
|
|
292
|
+
case "exclusiveMaximum":
|
|
293
|
+
case "minLength":
|
|
294
|
+
case "maxLength":
|
|
295
|
+
case "minItems":
|
|
296
|
+
case "maxItems":
|
|
297
|
+
return "RANGE_VIOLATION";
|
|
298
|
+
case "additionalProperties":
|
|
299
|
+
return "ADDITIONAL_PROPERTY";
|
|
300
|
+
case "uniqueItems":
|
|
301
|
+
return "UNIQUE_VIOLATION";
|
|
302
|
+
default:
|
|
303
|
+
return `UNMAPPED:${keyword}`;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function handleValidate(state, args) {
|
|
307
|
+
if (typeof args !== "object" || args === null) {
|
|
308
|
+
return err("INVALID_INPUT", { detail: "validate args must be an object" });
|
|
309
|
+
}
|
|
310
|
+
const a = args;
|
|
311
|
+
if (typeof a.target !== "string" || !(a.target in VALIDATOR_TARGETS)) {
|
|
312
|
+
return err("INVALID_INPUT", { detail: `unknown validator target: ${String(a.target)}` });
|
|
313
|
+
}
|
|
314
|
+
let validate;
|
|
315
|
+
try {
|
|
316
|
+
validate = getValidator(state).getSchema(VALIDATOR_TARGETS[a.target]);
|
|
317
|
+
}
|
|
318
|
+
catch (e) {
|
|
319
|
+
return err("VALIDATION_ERROR", { detail: e.message });
|
|
320
|
+
}
|
|
321
|
+
if (!validate) {
|
|
322
|
+
return err("VALIDATION_ERROR", { detail: `schema not loaded: ${a.target}` });
|
|
323
|
+
}
|
|
324
|
+
validate(a.value);
|
|
325
|
+
const raw = validate.errors ?? [];
|
|
326
|
+
const seen = new Set();
|
|
327
|
+
const out = [];
|
|
328
|
+
for (const e of raw) {
|
|
329
|
+
const code = ajvKeywordToCode(e.keyword);
|
|
330
|
+
if (code.startsWith("UNMAPPED:"))
|
|
331
|
+
continue;
|
|
332
|
+
const path = e.keyword === "required"
|
|
333
|
+
? `${e.instancePath}/${e.params.missingProperty ?? ""}`
|
|
334
|
+
: e.instancePath;
|
|
335
|
+
const key = `${path}|${code}`;
|
|
336
|
+
if (seen.has(key))
|
|
337
|
+
continue;
|
|
338
|
+
seen.add(key);
|
|
339
|
+
out.push({ path, code });
|
|
340
|
+
}
|
|
341
|
+
return ok(out);
|
|
342
|
+
}
|
|
343
|
+
function handleCrunch(state, args) {
|
|
344
|
+
if (typeof args !== "object" || args === null) {
|
|
345
|
+
return err("INVALID_INPUT", { detail: "crunch args must be an object" });
|
|
346
|
+
}
|
|
347
|
+
const a = args;
|
|
348
|
+
if (!a.attacker?.weaponId || typeof a.attacker.profileIndex !== "number") {
|
|
349
|
+
return err("INVALID_INPUT", { detail: "crunch.attacker.weaponId/profileIndex required" });
|
|
350
|
+
}
|
|
351
|
+
if (!a.target?.unitId || typeof a.target.profileIndex !== "number") {
|
|
352
|
+
return err("INVALID_INPUT", { detail: "crunch.target.unitId/profileIndex required" });
|
|
353
|
+
}
|
|
354
|
+
if (typeof a.modelsFiring !== "number") {
|
|
355
|
+
return err("INVALID_INPUT", { detail: "crunch.modelsFiring required" });
|
|
356
|
+
}
|
|
357
|
+
if (!a.context) {
|
|
358
|
+
return err("INVALID_INPUT", { detail: "crunch.context required" });
|
|
359
|
+
}
|
|
360
|
+
const ds = getDataset(state);
|
|
361
|
+
const weapon = ds.weapons.get(a.attacker.weaponId);
|
|
362
|
+
if (!weapon)
|
|
363
|
+
return err("UNKNOWN_ENTITY", { kind: "weapon", id: a.attacker.weaponId });
|
|
364
|
+
const unit = ds.units.get(a.target.unitId);
|
|
365
|
+
if (!unit)
|
|
366
|
+
return err("UNKNOWN_ENTITY", { kind: "unit", id: a.target.unitId });
|
|
367
|
+
try {
|
|
368
|
+
const input = {
|
|
369
|
+
attacker: { weapon: weapon.raw, profileIndex: a.attacker.profileIndex },
|
|
370
|
+
target: {
|
|
371
|
+
unit: unit.raw,
|
|
372
|
+
profileIndex: a.target.profileIndex,
|
|
373
|
+
...(a.target.modelCount !== undefined ? { modelCount: a.target.modelCount } : {}),
|
|
374
|
+
},
|
|
375
|
+
modelsFiring: a.modelsFiring,
|
|
376
|
+
buffs: a.buffs ?? [],
|
|
377
|
+
context: a.context,
|
|
378
|
+
};
|
|
379
|
+
return ok(crunch(input, ds));
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
return err("CRUNCH_ERROR", { detail: e.message });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// -----------------------------------------------------------------------------
|
|
386
|
+
// Dispatcher and per-line entry point.
|
|
387
|
+
// -----------------------------------------------------------------------------
|
|
388
|
+
/**
|
|
389
|
+
* Apply one decoded request to the runner state and return the response. Used
|
|
390
|
+
* directly by tests; the CLI loop wraps it with line parsing.
|
|
391
|
+
*/
|
|
392
|
+
export function dispatch(state, req) {
|
|
393
|
+
if (!state.initialized && req.op !== "init") {
|
|
394
|
+
return err("INVALID_INPUT", { detail: "must init before any other op" });
|
|
395
|
+
}
|
|
396
|
+
switch (req.op) {
|
|
397
|
+
case "init":
|
|
398
|
+
return handleInit(state, req.args);
|
|
399
|
+
case "version":
|
|
400
|
+
return ok({ impl: IMPL_NAME, spec_version: SPEC_VERSION, impl_version: IMPL_VERSION });
|
|
401
|
+
case "normalize":
|
|
402
|
+
return handleNormalize(req.args);
|
|
403
|
+
case "import":
|
|
404
|
+
return handleImport(state, req.args);
|
|
405
|
+
case "try_import":
|
|
406
|
+
return handleTryImport(state, req.args);
|
|
407
|
+
case "export":
|
|
408
|
+
return handleExport(req.args);
|
|
409
|
+
case "linked_query":
|
|
410
|
+
return handleLinkedQuery(state, req.args);
|
|
411
|
+
case "validate":
|
|
412
|
+
return handleValidate(state, req.args);
|
|
413
|
+
case "crunch":
|
|
414
|
+
return handleCrunch(state, req.args);
|
|
415
|
+
case "shutdown":
|
|
416
|
+
return ok(null);
|
|
417
|
+
default:
|
|
418
|
+
return err("UNKNOWN_OP", { op: req.op });
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Process one line of stdin (one NDJSON request) and return the line that
|
|
423
|
+
* should be written to stdout (one NDJSON response). Returns `null` only on
|
|
424
|
+
* fully-empty input lines, which should be silently ignored.
|
|
425
|
+
*/
|
|
426
|
+
export function processRequest(state, line) {
|
|
427
|
+
const trimmed = line.trim();
|
|
428
|
+
if (trimmed === "")
|
|
429
|
+
return null;
|
|
430
|
+
let req;
|
|
431
|
+
try {
|
|
432
|
+
req = JSON.parse(trimmed);
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
return JSON.stringify(err("INVALID_INPUT", { detail: `not valid JSON: ${e.message}` }));
|
|
436
|
+
}
|
|
437
|
+
if (typeof req.op !== "string") {
|
|
438
|
+
return JSON.stringify(err("INVALID_INPUT", { detail: "request must have a string `op` field" }));
|
|
439
|
+
}
|
|
440
|
+
const response = dispatch(state, { op: req.op, args: req.args });
|
|
441
|
+
return JSON.stringify(response);
|
|
442
|
+
}
|
|
443
|
+
// -----------------------------------------------------------------------------
|
|
444
|
+
// CLI: wire stdin/stdout. Only runs when this file is the process entry point.
|
|
445
|
+
// -----------------------------------------------------------------------------
|
|
446
|
+
function isCliMain() {
|
|
447
|
+
// process.argv[1] is the path the runtime invoked. With tsx and node both,
|
|
448
|
+
// it points at this file (or its compiled .js form). Comparing absolute
|
|
449
|
+
// paths is the most robust portable check.
|
|
450
|
+
if (!process.argv[1])
|
|
451
|
+
return false;
|
|
452
|
+
const entry = process.argv[1];
|
|
453
|
+
const here = fileURLToPath(import.meta.url);
|
|
454
|
+
return entry === here || entry.endsWith("/runner.js") || entry.endsWith("/runner.ts");
|
|
455
|
+
}
|
|
456
|
+
async function runCli() {
|
|
457
|
+
const state = createRunnerState();
|
|
458
|
+
const rl = createInterface({ input: process.stdin });
|
|
459
|
+
// We must respond on the same tick the request arrives — the differ
|
|
460
|
+
// pipelines requests and expects responses in order. readline preserves
|
|
461
|
+
// line ordering, so processing inside `line` handler is sufficient.
|
|
462
|
+
for await (const line of rl) {
|
|
463
|
+
const out = processRequest(state, line);
|
|
464
|
+
if (out !== null) {
|
|
465
|
+
process.stdout.write(out + "\n");
|
|
466
|
+
}
|
|
467
|
+
// `shutdown` returns `ok(null)`; honor it by exiting after the response
|
|
468
|
+
// is flushed.
|
|
469
|
+
try {
|
|
470
|
+
const req = JSON.parse(line);
|
|
471
|
+
if (req && req.op === "shutdown") {
|
|
472
|
+
process.exit(0);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
// already handled above; not a shutdown
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (isCliMain()) {
|
|
481
|
+
runCli().catch((e) => {
|
|
482
|
+
// Last-ditch INTERNAL_ERROR so the differ sees a typed failure rather
|
|
483
|
+
// than an opaque crash.
|
|
484
|
+
process.stdout.write(JSON.stringify({
|
|
485
|
+
ok: false,
|
|
486
|
+
error_kind: "INTERNAL_ERROR",
|
|
487
|
+
error_payload: { detail: e.message },
|
|
488
|
+
}) + "\n");
|
|
489
|
+
process.exit(1);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,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K,CAClB,IAAI,CAAC,SAAS,CAAC;YACb,EAAE,EAAE,KAAK;YACT,UAAU,EAAE,gBAAgB;YAC5B,aAAa,EAAE,EAAE,MAAM,EAAG,CAAW,CAAC,OAAO,EAAE;SAChD,CAAC,GAAG,IAAI,CACV,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * NDJSON conformance runner — the TypeScript implementation of the wire\n * protocol in `conformance/RUNNER_PROTOCOL.md`. Each line on stdin is a JSON\n * request `{op, args?}`; each line on stdout is a JSON response\n * `{ok: true, value}` or `{ok: false, error_kind, error_payload?}`.\n *\n * This file exports {@link processRequest} so vitest can drive the runner\n * in-process without spawning a child; the bottom `if (isCliMain())` block\n * wires the same dispatcher to real stdin/stdout for the cross-impl differ.\n *\n * The runner is a *thin* wrapper over the existing public API — it is not the\n * canonical way to use the package. Library consumers should import the\n * functions directly; the runner exists to give the cross-implementation\n * differ a uniform interface across language ports.\n */\nimport { createInterface } from \"node:readline\";\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport process from \"node:process\";\n\nimport { Dataset } from \"./data/dataset.js\";\nimport { normalizeName } from \"./data/normalize.js\";\nimport { exportRoster, type ExportFormat } from \"./export/index.js\";\nimport { importRoster, tryImportRoster, REGISTERED_ADAPTERS } from \"./import/import-roster.js\";\nimport { selectAdapter } from \"./import/adapter.js\";\nimport { createValidator } from \"./schema-loader.js\";\nimport { crunch, type Buff, type EngineContext, type EngineInput } from \"./cruncher/index.js\";\nimport type Ajv from \"ajv\";\n\n// -----------------------------------------------------------------------------\n// Constants — spec version and implementation identity.\n// -----------------------------------------------------------------------------\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nfunction loadSpecVersion(): number {\n // The corpus lives at repo-root/conformance/. Walk up from tools/src/ until\n // we find it so the runner works both from source (tsx) and from dist/.\n for (const candidate of [\n join(__dirname, \"../../conformance/SPEC_VERSION\"),\n join(__dirname, \"../../../conformance/SPEC_VERSION\"),\n ]) {\n try {\n return Number.parseInt(readFileSync(candidate, \"utf8\").trim(), 10);\n } catch {\n // try next\n }\n }\n throw new Error(\"could not locate conformance/SPEC_VERSION\");\n}\n\nfunction loadImplVersion(): string {\n for (const candidate of [\n join(__dirname, \"../package.json\"),\n join(__dirname, \"../../package.json\"),\n ]) {\n try {\n return (JSON.parse(readFileSync(candidate, \"utf8\")) as { version: string }).version;\n } catch {\n // try next\n }\n }\n return \"unknown\";\n}\n\nconst SPEC_VERSION = loadSpecVersion();\nconst IMPL_VERSION = loadImplVersion();\nconst IMPL_NAME = \"ts\";\n\n// -----------------------------------------------------------------------------\n// Error envelope helpers and the closed `error_kind` enum.\n// -----------------------------------------------------------------------------\n\nexport type RunnerResponse =\n | { ok: true; value: unknown }\n | { ok: false; error_kind: ErrorKind; error_payload?: unknown };\n\nconst ERROR_KINDS = [\n \"INVALID_INPUT\",\n \"UNKNOWN_OP\",\n \"UNKNOWN_ENTITY\",\n \"IMPORT_FAILED\",\n \"EXPORT_FAILED\",\n \"VALIDATION_ERROR\",\n \"CRUNCH_ERROR\",\n \"INTERNAL_ERROR\",\n] as const;\ntype ErrorKind = (typeof ERROR_KINDS)[number];\n\nfunction ok(value: unknown): RunnerResponse {\n return { ok: true, value };\n}\nfunction err(kind: ErrorKind, payload?: unknown): RunnerResponse {\n return payload === undefined\n ? { ok: false, error_kind: kind }\n : { ok: false, error_kind: kind, error_payload: payload };\n}\n\n// -----------------------------------------------------------------------------\n// Runner state — init must be the first request; subsequent ops fail with\n// INVALID_INPUT until init succeeds. Dataset and validator are lazy.\n// -----------------------------------------------------------------------------\n\nexport interface RunnerState {\n initialized: boolean;\n locale: string;\n tz: string;\n seed: number;\n dataset?: Dataset;\n validator?: Ajv;\n}\n\nexport function createRunnerState(): RunnerState {\n return { initialized: false, locale: \"C\", tz: \"UTC\", seed: 0 };\n}\n\nfunction getDataset(state: RunnerState): Dataset {\n if (!state.dataset) state.dataset = Dataset.embedded();\n return state.dataset;\n}\n\nfunction getValidator(state: RunnerState): Ajv {\n if (!state.validator) state.validator = createValidator();\n return state.validator;\n}\n\n// -----------------------------------------------------------------------------\n// Op handlers.\n// -----------------------------------------------------------------------------\n\nfunction handleInit(state: RunnerState, args: unknown): RunnerResponse {\n if (state.initialized) {\n return err(\"INVALID_INPUT\", { detail: \"init called twice\" });\n }\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"init args must be an object\" });\n }\n const a = args as { spec_version?: unknown; locale?: unknown; tz?: unknown; seed?: unknown };\n if (a.spec_version !== SPEC_VERSION) {\n return err(\"INVALID_INPUT\", {\n detail: `spec_version mismatch: runner=${SPEC_VERSION}, request=${String(a.spec_version)}`,\n });\n }\n if (a.locale !== \"C\") {\n return err(\"INVALID_INPUT\", { detail: `unsupported locale: ${String(a.locale)} (only \"C\")` });\n }\n if (a.tz !== \"UTC\") {\n return err(\"INVALID_INPUT\", { detail: `unsupported tz: ${String(a.tz)} (only \"UTC\")` });\n }\n if (typeof a.seed !== \"number\") {\n return err(\"INVALID_INPUT\", { detail: \"seed must be a number\" });\n }\n state.initialized = true;\n state.locale = a.locale;\n state.tz = a.tz;\n state.seed = a.seed;\n return ok({ impl: IMPL_NAME, spec_version: SPEC_VERSION, impl_version: IMPL_VERSION });\n}\n\nfunction handleNormalize(args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"normalize args must be an object\" });\n }\n const a = args as { input?: unknown };\n if (typeof a.input !== \"string\") {\n return err(\"INVALID_INPUT\", { detail: \"normalize.input must be a string\" });\n }\n return ok(normalizeName(a.input));\n}\n\nfunction handleImport(state: RunnerState, args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"import args must be an object\" });\n }\n const a = args as { format?: unknown; input?: unknown };\n if (typeof a.input !== \"string\") {\n return err(\"INVALID_INPUT\", { detail: \"import.input must be a string\" });\n }\n try {\n // The wire protocol carries every input as a string: JSON payloads come\n // through as the JSON text, text payloads come through as-is. The import\n // pipeline decides which by attempting to parse JSON first.\n const trimmed = a.input.trimStart();\n let decoded: unknown;\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n decoded = JSON.parse(a.input);\n } catch {\n decoded = a.input;\n }\n } else {\n decoded = a.input;\n }\n const roster = importRoster(decoded, { dataset: getDataset(state) });\n return ok(roster);\n } catch (e) {\n return err(\"IMPORT_FAILED\", { detail: (e as Error).message, format: a.format ?? null });\n }\n}\n\nfunction handleTryImport(state: RunnerState, args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"try_import args must be an object\" });\n }\n const a = args as { input?: unknown };\n if (typeof a.input !== \"string\") {\n return err(\"INVALID_INPUT\", { detail: \"try_import.input must be a string\" });\n }\n const result = tryImportRoster(a.input, { dataset: getDataset(state) });\n if (!result.ok) {\n return err(\"IMPORT_FAILED\", { reason: result.reason, message: result.message });\n }\n return ok({ format: result.format, roster: result.roster });\n}\n\nconst EXPORT_FORMATS: ExportFormat[] = [\n \"newrecruit-json\",\n \"newrecruit-wtc-compact\",\n \"newrecruit-wtc-full\",\n \"newrecruit-simple\",\n \"roster-json\",\n \"rosterizer\",\n];\n\nfunction handleExport(args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"export args must be an object\" });\n }\n const a = args as { format?: unknown; roster?: unknown };\n if (typeof a.format !== \"string\" || !EXPORT_FORMATS.includes(a.format as ExportFormat)) {\n return err(\"INVALID_INPUT\", { detail: `unknown export format: ${String(a.format)}` });\n }\n if (typeof a.roster !== \"object\" || a.roster === null) {\n return err(\"INVALID_INPUT\", { detail: \"export.roster must be an object\" });\n }\n try {\n // We assume the caller passes the canonical resolved Roster shape; if they\n // pass something the serializer can't handle, this throws.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(exportRoster(a.roster as any, a.format as ExportFormat));\n } catch (e) {\n return err(\"EXPORT_FAILED\", { detail: (e as Error).message });\n }\n}\n\nfunction handleLinkedQuery(state: RunnerState, args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"linked_query args must be an object\" });\n }\n const a = args as { query?: unknown; input?: unknown };\n if (typeof a.query !== \"string\") {\n return err(\"INVALID_INPUT\", { detail: \"linked_query.query must be a string\" });\n }\n const ds = getDataset(state);\n const input = (a.input ?? {}) as Record<string, string>;\n try {\n switch (a.query) {\n case \"find_unit\":\n return ok(ds.units.find(input.query ?? \"\")?.id ?? null);\n case \"find_weapon\":\n return ok(ds.weapons.find(input.query ?? \"\")?.id ?? null);\n case \"find_faction\":\n return ok(ds.factions.find(input.query ?? \"\")?.id ?? null);\n case \"find_ability\":\n return ok(ds.abilities.find(input.query ?? \"\")?.id ?? null);\n case \"abilities_of\": {\n const u = ds.units.get(input.unitId);\n if (!u) return err(\"UNKNOWN_ENTITY\", { kind: \"unit\", id: input.unitId });\n return ok(u.abilities.map((x) => x.id));\n }\n case \"weapons_of\": {\n const u = ds.units.get(input.unitId);\n if (!u) return err(\"UNKNOWN_ENTITY\", { kind: \"unit\", id: input.unitId });\n return ok(u.weapons.map((x) => x.id));\n }\n case \"phases_of\": {\n const ab = ds.abilities.get(input.abilityId);\n if (!ab) return err(\"UNKNOWN_ENTITY\", { kind: \"ability\", id: input.abilityId });\n return ok([...ab.phases]);\n }\n case \"faction_of\": {\n const u = ds.units.get(input.unitId);\n if (!u) return err(\"UNKNOWN_ENTITY\", { kind: \"unit\", id: input.unitId });\n return ok(u.faction?.id ?? null);\n }\n case \"abilities_of_faction\":\n return ok(ds.abilities.byFaction(input.factionId).map((x) => x.id));\n case \"weapons_of_faction\": {\n const f = ds.factions.get(input.factionId);\n if (!f) return err(\"UNKNOWN_ENTITY\", { kind: \"faction\", id: input.factionId });\n return ok(f.weapons.map((x) => x.id));\n }\n default:\n return err(\"INVALID_INPUT\", { detail: `unknown linked_query: ${a.query}` });\n }\n } catch (e) {\n return err(\"INTERNAL_ERROR\", { detail: (e as Error).message });\n }\n}\n\nconst VALIDATOR_TARGETS: Record<string, string> = {\n unit: \"https://40kdc.dev/schemas/core/unit.schema.json\",\n weapon: \"https://40kdc.dev/schemas/core/weapon.schema.json\",\n faction: \"https://40kdc.dev/schemas/core/faction.schema.json\",\n ability: \"https://40kdc.dev/schemas/enrichment/ability-dsl/ability.schema.json\",\n};\n\nfunction ajvKeywordToCode(keyword: string): string {\n switch (keyword) {\n case \"required\":\n return \"REQUIRED_MISSING\";\n case \"type\":\n return \"TYPE_MISMATCH\";\n case \"enum\":\n return \"ENUM_VIOLATION\";\n case \"pattern\":\n case \"format\":\n return \"PATTERN_MISMATCH\";\n case \"minimum\":\n case \"maximum\":\n case \"exclusiveMinimum\":\n case \"exclusiveMaximum\":\n case \"minLength\":\n case \"maxLength\":\n case \"minItems\":\n case \"maxItems\":\n return \"RANGE_VIOLATION\";\n case \"additionalProperties\":\n return \"ADDITIONAL_PROPERTY\";\n case \"uniqueItems\":\n return \"UNIQUE_VIOLATION\";\n default:\n return `UNMAPPED:${keyword}`;\n }\n}\n\nfunction handleValidate(state: RunnerState, args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"validate args must be an object\" });\n }\n const a = args as { target?: unknown; value?: unknown };\n if (typeof a.target !== \"string\" || !(a.target in VALIDATOR_TARGETS)) {\n return err(\"INVALID_INPUT\", { detail: `unknown validator target: ${String(a.target)}` });\n }\n let validate;\n try {\n validate = getValidator(state).getSchema(VALIDATOR_TARGETS[a.target]);\n } catch (e) {\n return err(\"VALIDATION_ERROR\", { detail: (e as Error).message });\n }\n if (!validate) {\n return err(\"VALIDATION_ERROR\", { detail: `schema not loaded: ${a.target}` });\n }\n validate(a.value);\n const raw = validate.errors ?? [];\n const seen = new Set<string>();\n const out: { path: string; code: string }[] = [];\n for (const e of raw) {\n const code = ajvKeywordToCode(e.keyword);\n if (code.startsWith(\"UNMAPPED:\")) continue;\n const path =\n e.keyword === \"required\"\n ? `${e.instancePath}/${(e.params as { missingProperty?: string }).missingProperty ?? \"\"}`\n : e.instancePath;\n const key = `${path}|${code}`;\n if (seen.has(key)) continue;\n seen.add(key);\n out.push({ path, code });\n }\n return ok(out);\n}\n\nfunction handleCrunch(state: RunnerState, args: unknown): RunnerResponse {\n if (typeof args !== \"object\" || args === null) {\n return err(\"INVALID_INPUT\", { detail: \"crunch args must be an object\" });\n }\n const a = args as {\n attacker?: { weaponId?: string; profileIndex?: number };\n modelsFiring?: number;\n target?: { unitId?: string; profileIndex?: number; modelCount?: number };\n context?: EngineContext;\n buffs?: Buff[];\n };\n if (!a.attacker?.weaponId || typeof a.attacker.profileIndex !== \"number\") {\n return err(\"INVALID_INPUT\", { detail: \"crunch.attacker.weaponId/profileIndex required\" });\n }\n if (!a.target?.unitId || typeof a.target.profileIndex !== \"number\") {\n return err(\"INVALID_INPUT\", { detail: \"crunch.target.unitId/profileIndex required\" });\n }\n if (typeof a.modelsFiring !== \"number\") {\n return err(\"INVALID_INPUT\", { detail: \"crunch.modelsFiring required\" });\n }\n if (!a.context) {\n return err(\"INVALID_INPUT\", { detail: \"crunch.context required\" });\n }\n const ds = getDataset(state);\n const weapon = ds.weapons.get(a.attacker.weaponId);\n if (!weapon) return err(\"UNKNOWN_ENTITY\", { kind: \"weapon\", id: a.attacker.weaponId });\n const unit = ds.units.get(a.target.unitId);\n if (!unit) return err(\"UNKNOWN_ENTITY\", { kind: \"unit\", id: a.target.unitId });\n try {\n const input: EngineInput = {\n attacker: { weapon: weapon.raw, profileIndex: a.attacker.profileIndex },\n target: {\n unit: unit.raw,\n profileIndex: a.target.profileIndex,\n ...(a.target.modelCount !== undefined ? { modelCount: a.target.modelCount } : {}),\n },\n modelsFiring: a.modelsFiring,\n buffs: a.buffs ?? [],\n context: a.context,\n };\n return ok(crunch(input, ds));\n } catch (e) {\n return err(\"CRUNCH_ERROR\", { detail: (e as Error).message });\n }\n}\n\n// -----------------------------------------------------------------------------\n// Dispatcher and per-line entry point.\n// -----------------------------------------------------------------------------\n\n/**\n * Apply one decoded request to the runner state and return the response. Used\n * directly by tests; the CLI loop wraps it with line parsing.\n */\nexport function dispatch(state: RunnerState, req: { op: string; args?: unknown }): RunnerResponse {\n if (!state.initialized && req.op !== \"init\") {\n return err(\"INVALID_INPUT\", { detail: \"must init before any other op\" });\n }\n switch (req.op) {\n case \"init\":\n return handleInit(state, req.args);\n case \"version\":\n return ok({ impl: IMPL_NAME, spec_version: SPEC_VERSION, impl_version: IMPL_VERSION });\n case \"normalize\":\n return handleNormalize(req.args);\n case \"import\":\n return handleImport(state, req.args);\n case \"try_import\":\n return handleTryImport(state, req.args);\n case \"export\":\n return handleExport(req.args);\n case \"linked_query\":\n return handleLinkedQuery(state, req.args);\n case \"validate\":\n return handleValidate(state, req.args);\n case \"crunch\":\n return handleCrunch(state, req.args);\n case \"shutdown\":\n return ok(null);\n default:\n return err(\"UNKNOWN_OP\", { op: req.op });\n }\n}\n\n/**\n * Process one line of stdin (one NDJSON request) and return the line that\n * should be written to stdout (one NDJSON response). Returns `null` only on\n * fully-empty input lines, which should be silently ignored.\n */\nexport function processRequest(state: RunnerState, line: string): string | null {\n const trimmed = line.trim();\n if (trimmed === \"\") return null;\n let req: { op?: unknown; args?: unknown };\n try {\n req = JSON.parse(trimmed);\n } catch (e) {\n return JSON.stringify(err(\"INVALID_INPUT\", { detail: `not valid JSON: ${(e as Error).message}` }));\n }\n if (typeof req.op !== \"string\") {\n return JSON.stringify(err(\"INVALID_INPUT\", { detail: \"request must have a string `op` field\" }));\n }\n const response = dispatch(state, { op: req.op, args: req.args });\n return JSON.stringify(response);\n}\n\n// -----------------------------------------------------------------------------\n// CLI: wire stdin/stdout. Only runs when this file is the process entry point.\n// -----------------------------------------------------------------------------\n\nfunction isCliMain(): boolean {\n // process.argv[1] is the path the runtime invoked. With tsx and node both,\n // it points at this file (or its compiled .js form). Comparing absolute\n // paths is the most robust portable check.\n if (!process.argv[1]) return false;\n const entry = process.argv[1];\n const here = fileURLToPath(import.meta.url);\n return entry === here || entry.endsWith(\"/runner.js\") || entry.endsWith(\"/runner.ts\");\n}\n\nasync function runCli(): Promise<void> {\n const state = createRunnerState();\n const rl = createInterface({ input: process.stdin });\n // We must respond on the same tick the request arrives — the differ\n // pipelines requests and expects responses in order. readline preserves\n // line ordering, so processing inside `line` handler is sufficient.\n for await (const line of rl) {\n const out = processRequest(state, line);\n if (out !== null) {\n process.stdout.write(out + \"\\n\");\n }\n // `shutdown` returns `ok(null)`; honor it by exiting after the response\n // is flushed.\n try {\n const req = JSON.parse(line);\n if (req && req.op === \"shutdown\") {\n process.exit(0);\n }\n } catch {\n // already handled above; not a shutdown\n }\n }\n}\n\nif (isCliMain()) {\n runCli().catch((e) => {\n // Last-ditch INTERNAL_ERROR so the differ sees a typed failure rather\n // than an opaque crash.\n process.stdout.write(\n JSON.stringify({\n ok: false,\n error_kind: \"INTERNAL_ERROR\",\n error_payload: { detail: (e as Error).message },\n }) + \"\\n\",\n );\n process.exit(1);\n });\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The note any GW-text-bearing entry is rewritten to. */
|
|
2
|
+
export declare const SCRUB_CITATION = "auto-generated stub \u2014 needs manual authoring (source: 10e Datasheets_abilities; rules text omitted for IP)";
|
|
3
|
+
/** True when this note carries verbatim GW rules text and must be scrubbed. */
|
|
4
|
+
export declare function isLeak(note: string | undefined): boolean;
|
|
5
|
+
/** Replace a leaking note with the citation; pass authored notes through unchanged. */
|
|
6
|
+
export declare function scrubNote(note: string | undefined): string | undefined;
|
|
7
|
+
interface AbilityEntry {
|
|
8
|
+
community_notes?: string;
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
/** Scrub one file's array in place; return how many entries changed. */
|
|
12
|
+
export declare function scrubAbilities(abilities: AbilityEntry[]): number;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=scrub-ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub-ip.d.ts","sourceRoot":"","sources":["../src/scrub-ip.ts"],"names":[],"mappings":"AAuBA,0DAA0D;AAC1D,eAAO,MAAM,cAAc,oHACmF,CAAC;AAK/G,+EAA+E;AAC/E,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAExD;AAED,uFAAuF;AACvF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED,UAAU,YAAY;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAShE"}
|