@sf-kmods/kdataforgejs-cli 2026.4.30 → 2026.4.37
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 +10 -2
- package/dist/commands/add.js +96 -23
- package/dist/commands/sync.js +5 -4
- package/dist/pack/capabilityEnums.js +65 -0
- package/dist/pack/sourceGraph.js +15 -7
- package/dist/pack/usage.js +3 -2
- package/dist/types/apiEnums.js +21 -0
- package/dist/types/configTypes.js +78 -12
- package/dist/types/contentTypes.js +21 -14
- package/package.json +2 -2
- package/schemas/common.schema.yml +59 -4
- package/schemas/pack.schema.yml +76 -1
- package/schemas/sound.schema.yml +3 -3
- package/templates/default/DataForge/scripts/features/catalog.ts +2 -2
- package/templates/default/DataForge/scripts/main.ts +3 -3
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ npm run verify
|
|
|
23
23
|
| `kdf game-data [dir]` | Runs manifest sync, finds a modded Satisfactory installation, reuses a valid cached export or starts a full reflection export, closes the game and imports the archive plus generated TypeScript declarations. Use `--game-path <root-or-executable>` to select an installation explicitly; add `--content-types` for schema-derived content document types and `--force` to bypass the cache. |
|
|
24
24
|
| `kdf doctor [dir]` | Read-only health report for Node, project checks, manifest drift, installation and imported game data. `--json` emits machine-readable statuses: `pass`, `warn`, `fail`, `unknown`. |
|
|
25
25
|
| `kdf dev [dir]` | Watches authored files, debounces changes, then runs sync, check, lint and validate in order. After success, prints manual `KDF.Reload` instruction. |
|
|
26
|
-
| `kdf add <handler\|hook\|item\|recipe\|document> <name> [dir]` | Creates one scaffold and updates entry imports, handler call and
|
|
26
|
+
| `kdf add <handler\|hook\|item\|recipe\|document> <name> [dir]` | Creates one scaffold and updates entry imports, handler call and Capability enum members. Existing destinations and computed metadata are refused. Documents default to `cdo`; `--type item` or `--type recipe` selects another minimal document form. |
|
|
27
27
|
| `kdf update [dir]` | Read-only, network-free report of declared and locally installed SDK/CLI versions and game-data status. `--apply` updates local dev dependencies, then runs the newly installed local CLI's `game-data` once. `--offline --apply` skips the package manager and refreshes from installed packages/cache/game only. |
|
|
28
28
|
|
|
29
29
|
Exit code `0` means all good, `1` means findings, `2` means the command was used wrong.
|
|
@@ -35,6 +35,11 @@ The generated project keeps `package.json` and `tsconfig.json` next to the `Data
|
|
|
35
35
|
itself has no `node_modules`. `npm run refresh` runs `kdf game-data`; `npm run fix` formats scripts and synchronizes
|
|
36
36
|
generated manifest fields. `format`, `lint`, `check`, `validate`, `hash`, `sync`, `test`, and `verify` are available too.
|
|
37
37
|
|
|
38
|
+
New scripts and scaffolded helpers import `ctx` from `@sf-kmods/kdataforgejs` and use parameterless
|
|
39
|
+
handlers or functions. All local modules share the current script realm's context. Existing handlers
|
|
40
|
+
with a context parameter remain supported by `kdf add`. Update the runtime and SDK and refresh generated
|
|
41
|
+
game declarations before using imported `ctx` in an older project.
|
|
42
|
+
|
|
38
43
|
## Multiple packs in one workspace
|
|
39
44
|
|
|
40
45
|
Keep each pack in its own tooling project, for example `packs/Alpha/DataForge/pack.yml` and
|
|
@@ -76,7 +81,7 @@ reflection files remain untouched until game-data succeeds. `kdf update --offlin
|
|
|
76
81
|
requires both packages already installed at matching versions, skips package-manager registry
|
|
77
82
|
access, and only refreshes game data. Offline mode never alters lockfiles.
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
Direct `ctx.import(ImportKind.Member, "path")` calls and reflected paths used by `ctx.getClass`, `ctx.getObject` and
|
|
80
85
|
`ctx.getDataAsset` are source of truth. YAML imports are scanned for `target` paths. Run `kdf sync`; do not maintain
|
|
81
86
|
manifest import digests or reflection class lists by hand. Dynamic import paths are rejected because CLI cannot grant
|
|
82
87
|
their authority safely.
|
|
@@ -129,3 +134,6 @@ fresh export. `--force` bypasses the hit. The game-data archive and declarations
|
|
|
129
134
|
own sync do not trigger another run. No automatic game command is sent: run `KDF.Reload` in the local game/server console
|
|
130
135
|
after successful checks. Item and recipe scaffolds contain placeholder definitions; fill in actual parent classes,
|
|
131
136
|
ingredients, products and machines before loading them. Hook scaffolds leave target selection for the author.
|
|
137
|
+
|
|
138
|
+
Closed API choices use named enums from `@sf-kmods/kdataforgejs`. Run `kdf game-data` after updating the runtime and SDK.
|
|
139
|
+
`kdf sync` generates select enums in `DataForge/scripts/generated/kdataforgejs-config-enums.ts` and pairs them with each pack's config map. Import those values inside the script graph; authored files at that path are never overwritten.
|
package/dist/commands/add.js
CHANGED
|
@@ -5,6 +5,8 @@ import ts from "typescript";
|
|
|
5
5
|
import { parseDocument } from "yaml";
|
|
6
6
|
import { RUNTIME_MODULE } from "../conventions.js";
|
|
7
7
|
import { assertSafeWrite } from "../pack/transaction.js";
|
|
8
|
+
import { capabilityLiteral, sdkEnumLiteral } from "../pack/capabilityEnums.js";
|
|
9
|
+
import { apiEnums, enumMember } from "../types/apiEnums.js";
|
|
8
10
|
const CAPABILITY = {
|
|
9
11
|
hook: "kdf.native.hook", item: "kdf.items.define", recipe: "kdf.recipes.define", document: "kdf.documents.apply",
|
|
10
12
|
};
|
|
@@ -59,12 +61,57 @@ function scaffold(kind, name, functionName, documentType) {
|
|
|
59
61
|
return `type: ${documentType}\n${field}: []\n`;
|
|
60
62
|
}
|
|
61
63
|
if (kind === "item")
|
|
62
|
-
return `import
|
|
64
|
+
return `import { ctx, ResourceForm, StackSize } from "${RUNTIME_MODULE}";\n\nexport function ${functionName}(): void {\n\tctx.createItem({\n\t\tid: "${name}",\n\t\tparent: { classPath: "/Script/FactoryGame.FGItemDescriptor" },\n\t\tdisplayName: { namespace: "${name}", key: "name", source: "${name}" },\n\t\tform: ResourceForm.Solid,\n\t\tstackSize: StackSize.Small,\n\t});\n}\n`;
|
|
63
65
|
if (kind === "recipe")
|
|
64
|
-
return `import
|
|
66
|
+
return `import { ctx } from "${RUNTIME_MODULE}";\n\nexport function ${functionName}(): void {\n\tctx.createRecipe({\n\t\tid: "${name}",\n\t\tingredients: [],\n\t\tproducts: [],\n\t\tproducedIn: [],\n\t\tdurationSeconds: 1,\n\t});\n}\n`;
|
|
65
67
|
if (kind === "hook")
|
|
66
|
-
return `import
|
|
67
|
-
return `import
|
|
68
|
+
return `import { ctx } from "${RUNTIME_MODULE}";\n\nexport function ${functionName}(): void {\n\t// Add ctx.hook(target, hook, callback) after selecting a reflected native target.\n\tvoid ctx;\n}\n`;
|
|
69
|
+
return `import { ctx } from "${RUNTIME_MODULE}";\n\nexport function ${functionName}(): void {\n\tconsole.info(ctx.catalog().digest);\n}\n`;
|
|
70
|
+
}
|
|
71
|
+
function bindingNames(node) {
|
|
72
|
+
const names = new Set();
|
|
73
|
+
const binding = (name) => {
|
|
74
|
+
if (ts.isIdentifier(name))
|
|
75
|
+
names.add(name.text);
|
|
76
|
+
else
|
|
77
|
+
for (const element of name.elements)
|
|
78
|
+
if (ts.isBindingElement(element))
|
|
79
|
+
binding(element.name);
|
|
80
|
+
};
|
|
81
|
+
const visit = (current) => {
|
|
82
|
+
if (ts.isVariableDeclaration(current) || ts.isParameter(current))
|
|
83
|
+
binding(current.name);
|
|
84
|
+
else if ((ts.isFunctionDeclaration(current) || ts.isClassDeclaration(current) || ts.isEnumDeclaration(current) ||
|
|
85
|
+
ts.isImportSpecifier(current) || ts.isNamespaceImport(current) || ts.isImportClause(current)) && current.name)
|
|
86
|
+
names.add(current.name.text);
|
|
87
|
+
ts.forEachChild(current, visit);
|
|
88
|
+
};
|
|
89
|
+
visit(node);
|
|
90
|
+
return names;
|
|
91
|
+
}
|
|
92
|
+
function documentContext(source, callback, edits) {
|
|
93
|
+
const parameter = callback.parameters[0]?.name;
|
|
94
|
+
if (parameter) {
|
|
95
|
+
if (!ts.isIdentifier(parameter))
|
|
96
|
+
throw new Error("Cannot identify handler context parameter.");
|
|
97
|
+
return parameter.text;
|
|
98
|
+
}
|
|
99
|
+
const locals = bindingNames(callback);
|
|
100
|
+
for (const node of source.statements) {
|
|
101
|
+
if (!ts.isImportDeclaration(node) || !ts.isStringLiteral(node.moduleSpecifier) ||
|
|
102
|
+
node.moduleSpecifier.text !== RUNTIME_MODULE || node.importClause?.isTypeOnly ||
|
|
103
|
+
!node.importClause?.namedBindings || !ts.isNamedImports(node.importClause.namedBindings))
|
|
104
|
+
continue;
|
|
105
|
+
const imported = node.importClause.namedBindings.elements.find((element) => !element.isTypeOnly && (element.propertyName ?? element.name).text === "ctx" && !locals.has(element.name.text));
|
|
106
|
+
if (imported)
|
|
107
|
+
return imported.name.text;
|
|
108
|
+
}
|
|
109
|
+
const names = bindingNames(source);
|
|
110
|
+
let name = "ctx";
|
|
111
|
+
for (let suffix = 1; names.has(name); suffix++)
|
|
112
|
+
name = `kdfContext${suffix === 1 ? "" : suffix}`;
|
|
113
|
+
edits.push({ start: 0, end: 0, text: `import { ${name === "ctx" ? "ctx" : `ctx as ${name}`} } from "${RUNTIME_MODULE}";\n` });
|
|
114
|
+
return name;
|
|
68
115
|
}
|
|
69
116
|
function editEntry(before, kind, name, functionName, documentType) {
|
|
70
117
|
const source = ts.createSourceFile("main.ts", before, ts.ScriptTarget.ES2022, true);
|
|
@@ -73,10 +120,7 @@ function editEntry(before, kind, name, functionName, documentType) {
|
|
|
73
120
|
throw new Error("Entry has syntax errors; refusing to edit it.");
|
|
74
121
|
}
|
|
75
122
|
const edits = [];
|
|
76
|
-
if (kind !== "document" && source
|
|
77
|
-
(ts.isVariableStatement(node) && node.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === functionName)) ||
|
|
78
|
-
(ts.isImportDeclaration(node) && node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings) &&
|
|
79
|
-
node.importClause.namedBindings.elements.some((element) => element.name.text === functionName)))) {
|
|
123
|
+
if (kind !== "document" && bindingNames(source).has(functionName)) {
|
|
80
124
|
throw new Error(`Entry already declares '${functionName}'; refusing ambiguous edit.`);
|
|
81
125
|
}
|
|
82
126
|
const capability = CAPABILITY[kind];
|
|
@@ -91,12 +135,13 @@ function editEntry(before, kind, name, functionName, documentType) {
|
|
|
91
135
|
if (!callback || (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback)) || !ts.isBlock(callback.body)) {
|
|
92
136
|
throw new Error("defineHandler callback must have a block body; refusing ambiguous edit.");
|
|
93
137
|
}
|
|
94
|
-
const ctx = callback
|
|
95
|
-
|
|
96
|
-
|
|
138
|
+
const ctx = kind === "document" ? documentContext(source, callback, edits) : undefined;
|
|
139
|
+
const documentEnum = kind === "document" ? enumBinding(source, "DocumentType", edits) : "";
|
|
140
|
+
const importEnum = kind === "document" ? enumBinding(source, "ImportKind", edits) : "";
|
|
141
|
+
const documentMember = kind === "document" ? enumMember("DocumentType", documentType).split(".")[1] : "";
|
|
97
142
|
const invocation = kind === "document"
|
|
98
|
-
? `${ctx
|
|
99
|
-
: `${functionName}(
|
|
143
|
+
? `${ctx}.applyDocument(${documentEnum}.${documentMember}, ${ctx}.import(${importEnum}.Yaml, "${name}.yml") as HandlerDocument<${documentEnum}.${documentMember}>);`
|
|
144
|
+
: `${functionName}();`;
|
|
100
145
|
edits.push({ start: callback.body.end - 1, end: callback.body.end - 1, text: `\n\t${invocation}\n` });
|
|
101
146
|
if (kind === "document") {
|
|
102
147
|
const hasHandlerDocument = source.statements.some((node) => ts.isImportDeclaration(node) &&
|
|
@@ -111,27 +156,33 @@ function editEntry(before, kind, name, functionName, documentType) {
|
|
|
111
156
|
return edits.sort((left, right) => right.start - left.start).reduce((content, edit) => content.slice(0, edit.start) + edit.text + content.slice(edit.end), before);
|
|
112
157
|
}
|
|
113
158
|
function addCapability(source, capability, edits) {
|
|
114
|
-
const
|
|
159
|
+
const handlerImports = source.statements.flatMap((node) => ts.isImportDeclaration(node) &&
|
|
115
160
|
ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === RUNTIME_MODULE &&
|
|
116
161
|
!node.importClause?.isTypeOnly && node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings) &&
|
|
117
|
-
node.importClause.namedBindings.elements.some((element) => element.name.text === "
|
|
162
|
+
node.importClause.namedBindings.elements.some((element) => element.name.text === "defineHandler" && !element.propertyName && !element.isTypeOnly)
|
|
163
|
+
? [node.importClause.namedBindings] : []);
|
|
164
|
+
const handlerImport = handlerImports[0];
|
|
165
|
+
if (handlerImports.length !== 1 || !handlerImport)
|
|
166
|
+
throw new Error("Entry needs one unaliased value defineHandler import.");
|
|
167
|
+
const imported = handlerImport.elements.some((element) => element.name.text === "defineMeta" && !element.propertyName && !element.isTypeOnly);
|
|
118
168
|
const meta = source.statements.flatMap((node) => ts.isVariableStatement(node) &&
|
|
119
169
|
node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)
|
|
120
170
|
? node.declarationList.declarations.filter((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === "meta") : []);
|
|
121
171
|
if (meta.length > 1)
|
|
122
172
|
throw new Error("Multiple exported meta declarations; refusing ambiguous edit.");
|
|
123
173
|
if (meta.length === 0) {
|
|
124
|
-
if (!imported && source
|
|
125
|
-
node.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === "defineMeta"))) {
|
|
174
|
+
if (!imported && bindingNames(source).has("defineMeta")) {
|
|
126
175
|
throw new Error("Local defineMeta binding conflicts with required import; refusing ambiguous edit.");
|
|
127
176
|
}
|
|
128
177
|
if (!imported)
|
|
129
|
-
edits.push({ start:
|
|
178
|
+
edits.push({ start: handlerImport.elements.end, end: handlerImport.elements.end,
|
|
179
|
+
text: `${handlerImport.elements.hasTrailingComma ? " " : ", "}defineMeta` });
|
|
130
180
|
const assignment = source.statements.find((node) => ts.isExportAssignment(node));
|
|
131
181
|
if (!assignment)
|
|
132
182
|
throw new Error("No default export for metadata insertion.");
|
|
183
|
+
const value = `${enumBinding(source, "Capability", edits)}.${enumMember("Capability", capability).split(".")[1]}`;
|
|
133
184
|
edits.push({ start: assignment.getStart(source), end: assignment.getStart(source),
|
|
134
|
-
text: `export const meta = defineMeta({ capabilities: [
|
|
185
|
+
text: `export const meta = defineMeta({ capabilities: [${value}] });\n\n` });
|
|
135
186
|
return;
|
|
136
187
|
}
|
|
137
188
|
if (!imported)
|
|
@@ -142,11 +193,33 @@ function addCapability(source, capability, edits) {
|
|
|
142
193
|
const property = arg && ts.isObjectLiteralExpression(arg) && arg.properties.length === 1 ? arg.properties[0] : undefined;
|
|
143
194
|
const array = property && ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) &&
|
|
144
195
|
property.name.text === "capabilities" && ts.isArrayLiteralExpression(property.initializer) ? property.initializer : undefined;
|
|
145
|
-
if (!array || array.elements.some((element) =>
|
|
146
|
-
throw new Error("Computed or
|
|
196
|
+
if (!array || array.elements.some((element) => capabilityLiteral(element, source) === undefined)) {
|
|
197
|
+
throw new Error("Computed or unresolved defineMeta capabilities; refusing ambiguous edit.");
|
|
147
198
|
}
|
|
148
|
-
if (array.elements.some((element) =>
|
|
199
|
+
if (array.elements.some((element) => capabilityLiteral(element, source) === capability))
|
|
149
200
|
return;
|
|
201
|
+
const value = `${enumBinding(source, "Capability", edits)}.${enumMember("Capability", capability).split(".")[1]}`;
|
|
150
202
|
edits.push({ start: array.end - 1, end: array.end - 1,
|
|
151
|
-
text: `${array.elements.hasTrailingComma ? " " : array.elements.length > 0 ? ", " : ""}
|
|
203
|
+
text: `${array.elements.hasTrailingComma ? " " : array.elements.length > 0 ? ", " : ""}${value}` });
|
|
204
|
+
}
|
|
205
|
+
function enumBinding(source, name, edits) {
|
|
206
|
+
const member = Object.keys(apiEnums.enums.find((entry) => entry.name === name)?.members ?? {})[0];
|
|
207
|
+
if (!member)
|
|
208
|
+
throw new Error(`Unknown SDK enum '${name}'.`);
|
|
209
|
+
for (const statement of source.statements) {
|
|
210
|
+
if (!ts.isImportDeclaration(statement) || !statement.importClause?.namedBindings || !ts.isNamedImports(statement.importClause.namedBindings))
|
|
211
|
+
continue;
|
|
212
|
+
for (const element of statement.importClause.namedBindings.elements) {
|
|
213
|
+
if ((element.propertyName ?? element.name).text !== name)
|
|
214
|
+
continue;
|
|
215
|
+
if (sdkEnumLiteral(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(element.name.text), member), source, name) !== undefined)
|
|
216
|
+
return element.name.text;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const names = bindingNames(source);
|
|
220
|
+
let alias = name;
|
|
221
|
+
for (let index = 1; names.has(alias); ++index)
|
|
222
|
+
alias = `kdf${name}${index}`;
|
|
223
|
+
edits.push({ start: 0, end: 0, text: `import { ${alias === name ? name : `${name} as ${alias}`} } from "${RUNTIME_MODULE}";\n` });
|
|
224
|
+
return alias;
|
|
152
225
|
}
|
package/dist/commands/sync.js
CHANGED
|
@@ -28,12 +28,13 @@ export function prepareSync(projectRoot, packRef) {
|
|
|
28
28
|
const outputs = discoverPacks(projectRoot, packRef).packs.map((pack) => syncPack(pack.root));
|
|
29
29
|
for (const output of outputs) {
|
|
30
30
|
assertSafeWrite(output.root, output.manifest.path);
|
|
31
|
-
|
|
31
|
+
for (const config of output.config)
|
|
32
|
+
assertSafeWrite(output.root, config.path);
|
|
32
33
|
}
|
|
33
34
|
return {
|
|
34
35
|
result: { changedPacks: outputs.filter((output) => output.manifest.changed).map((output) => output.root),
|
|
35
|
-
changedTypes: outputs.
|
|
36
|
-
files: outputs.flatMap((output) => [output.manifest, output.config].filter((file) => file.changed)
|
|
36
|
+
changedTypes: outputs.flatMap((output) => output.config.filter((file) => file.changed).map((file) => file.path)) },
|
|
37
|
+
files: outputs.flatMap((output) => [output.manifest, ...output.config].filter((file) => file.changed)
|
|
37
38
|
.map((file) => ({ path: file.path, content: file.content,
|
|
38
39
|
...(existsSync(file.path) ? { expected: readFileSync(file.path, "utf8") } : {}) }))),
|
|
39
40
|
};
|
|
@@ -57,7 +58,7 @@ function syncPack(packRoot) {
|
|
|
57
58
|
const after = document.toString();
|
|
58
59
|
return { root: packRoot,
|
|
59
60
|
manifest: { path: manifestFile, content: after, changed: after !== before },
|
|
60
|
-
config: { ...
|
|
61
|
+
config: [config, ...config.runtimeFiles].map((file) => ({ ...file, changed: !existsSync(file.path) || readFileSync(file.path, "utf8") !== file.content })) };
|
|
61
62
|
}
|
|
62
63
|
function setSequence(map, key, values) {
|
|
63
64
|
if (values.length === 0) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { apiEnums } from "../types/apiEnums.js";
|
|
3
|
+
/** Resolve only literals and direct, uniquely imported SDK Capability members. Never evaluate user code. */
|
|
4
|
+
export function capabilityLiteral(value, source) {
|
|
5
|
+
return sdkEnumLiteral(value, source, "Capability");
|
|
6
|
+
}
|
|
7
|
+
export function sdkEnumLiteral(value, source, enumName) {
|
|
8
|
+
if (ts.isStringLiteral(value))
|
|
9
|
+
return value.text;
|
|
10
|
+
if (!ts.isPropertyAccessExpression(value) || !ts.isIdentifier(value.expression))
|
|
11
|
+
return undefined;
|
|
12
|
+
const alias = value.expression.text;
|
|
13
|
+
let bindings = 0;
|
|
14
|
+
let capabilityImport = false;
|
|
15
|
+
function count(name) {
|
|
16
|
+
if (ts.isIdentifier(name)) {
|
|
17
|
+
if (name.text === alias)
|
|
18
|
+
++bindings;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
for (const element of name.elements)
|
|
22
|
+
if (ts.isBindingElement(element))
|
|
23
|
+
count(element.name);
|
|
24
|
+
}
|
|
25
|
+
for (const statement of source.statements) {
|
|
26
|
+
if (ts.isImportDeclaration(statement) && statement.importClause) {
|
|
27
|
+
const clause = statement.importClause;
|
|
28
|
+
if (clause.name)
|
|
29
|
+
count(clause.name);
|
|
30
|
+
if (clause.namedBindings) {
|
|
31
|
+
if (ts.isNamespaceImport(clause.namedBindings))
|
|
32
|
+
count(clause.namedBindings.name);
|
|
33
|
+
else
|
|
34
|
+
for (const element of clause.namedBindings.elements) {
|
|
35
|
+
count(element.name);
|
|
36
|
+
if (element.name.text === alias && !clause.isTypeOnly && !element.isTypeOnly &&
|
|
37
|
+
ts.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === "@sf-kmods/kdataforgejs" &&
|
|
38
|
+
(element.propertyName ?? element.name).text === enumName)
|
|
39
|
+
capabilityImport = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (ts.isVariableStatement(statement)) {
|
|
44
|
+
for (const declaration of statement.declarationList.declarations)
|
|
45
|
+
count(declaration.name);
|
|
46
|
+
}
|
|
47
|
+
else if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name)
|
|
48
|
+
count(statement.name);
|
|
49
|
+
}
|
|
50
|
+
const enumMembers = apiEnums.enums.find((entry) => entry.name === enumName)?.members;
|
|
51
|
+
// Import use within callbacks must not resolve through a local shadow.
|
|
52
|
+
let shadowed = false;
|
|
53
|
+
const visit = (node) => {
|
|
54
|
+
if (ts.isParameter(node) || ts.isVariableDeclaration(node)) {
|
|
55
|
+
const names = (name) => ts.isIdentifier(name) ? name.text === alias : name.elements.some((entry) => ts.isBindingElement(entry) && names(entry.name));
|
|
56
|
+
if (names(node.name))
|
|
57
|
+
shadowed = true;
|
|
58
|
+
}
|
|
59
|
+
ts.forEachChild(node, visit);
|
|
60
|
+
};
|
|
61
|
+
if (enumName !== "Capability")
|
|
62
|
+
visit(source);
|
|
63
|
+
const result = bindings === 1 && !shadowed && capabilityImport && enumMembers && Object.hasOwn(enumMembers, value.name.text) ? enumMembers[value.name.text] : undefined;
|
|
64
|
+
return typeof result === "string" ? result : undefined;
|
|
65
|
+
}
|
package/dist/pack/sourceGraph.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, extname, relative, resolve, sep } from "node:path";
|
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { RUNTIME_MODULE, SATISFACTORY_MODULE } from "../conventions.js";
|
|
5
5
|
import { isInside } from "./discover.js";
|
|
6
|
+
import { capabilityLiteral } from "./capabilityEnums.js";
|
|
6
7
|
/** Walks the static import graph from the entry and reports everything the runtime would reject. */
|
|
7
8
|
export function checkSourceGraph(packRoot, entry) {
|
|
8
9
|
const diagnostics = [];
|
|
@@ -87,10 +88,10 @@ export function checkEntryShape(packRoot, entry) {
|
|
|
87
88
|
}
|
|
88
89
|
const diagnostics = [];
|
|
89
90
|
if (!hasDefault)
|
|
90
|
-
diagnostics.push({ severity: "error", code: "entry.handler", file: entry, message: "Entry must default-export `defineHandler(async (
|
|
91
|
+
diagnostics.push({ severity: "error", code: "entry.handler", file: entry, message: "Entry must default-export `defineHandler(async () => ...)`." });
|
|
91
92
|
return diagnostics;
|
|
92
93
|
}
|
|
93
|
-
/**
|
|
94
|
+
/** Resolves the runtime's static optional defineMeta contract without executing pack code. */
|
|
94
95
|
export function readEntryMeta(packRoot, entry) {
|
|
95
96
|
const file = resolve(packRoot, entry);
|
|
96
97
|
if (!existsSync(file))
|
|
@@ -99,8 +100,9 @@ export function readEntryMeta(packRoot, entry) {
|
|
|
99
100
|
const diagnostics = [];
|
|
100
101
|
const hasDefineMetaImport = source.statements.some((statement) => ts.isImportDeclaration(statement) &&
|
|
101
102
|
ts.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === RUNTIME_MODULE &&
|
|
103
|
+
!statement.importClause?.isTypeOnly &&
|
|
102
104
|
statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings) &&
|
|
103
|
-
statement.importClause.namedBindings.elements.some((element) => !element.propertyName && element.name.text === "defineMeta"));
|
|
105
|
+
statement.importClause.namedBindings.elements.some((element) => !element.isTypeOnly && !element.propertyName && element.name.text === "defineMeta"));
|
|
104
106
|
const metaDeclarations = source.statements.flatMap((statement) => ts.isVariableStatement(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)
|
|
105
107
|
? statement.declarationList.declarations.filter((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === "meta")
|
|
106
108
|
: []);
|
|
@@ -110,6 +112,11 @@ export function readEntryMeta(packRoot, entry) {
|
|
|
110
112
|
diagnostics.push({ severity: "error", code: "entry.meta", file: entry,
|
|
111
113
|
message: "Optional meta requires an unaliased defineMeta import from @sf-kmods/kdataforgejs." });
|
|
112
114
|
const declaration = metaDeclarations.length === 1 ? metaDeclarations[0] : undefined;
|
|
115
|
+
if (!declaration || !ts.isVariableDeclarationList(declaration.parent) ||
|
|
116
|
+
(declaration.parent.flags & ts.NodeFlags.Const) === 0 || declaration.parent.declarations.length !== 1) {
|
|
117
|
+
diagnostics.push({ severity: "error", code: "entry.meta", file: entry, message: "Meta must be one exported const declaration." });
|
|
118
|
+
return { capabilities: [], diagnostics };
|
|
119
|
+
}
|
|
113
120
|
const call = declaration?.initializer;
|
|
114
121
|
const argument = call && ts.isCallExpression(call) ? call.arguments.at(0) : undefined;
|
|
115
122
|
const object = call && ts.isCallExpression(call) && ts.isIdentifier(call.expression) && call.expression.text === "defineMeta" &&
|
|
@@ -118,14 +125,15 @@ export function readEntryMeta(packRoot, entry) {
|
|
|
118
125
|
const property = object?.properties.length === 1 && firstProperty && ts.isPropertyAssignment(firstProperty) &&
|
|
119
126
|
ts.isIdentifier(firstProperty.name) && firstProperty.name.text === "capabilities" ? firstProperty : undefined;
|
|
120
127
|
const array = property && ts.isArrayLiteralExpression(property.initializer) ? property.initializer : undefined;
|
|
121
|
-
|
|
128
|
+
const resolved = array?.elements.map((element) => capabilityLiteral(element, source));
|
|
129
|
+
if (!resolved || resolved.some((value) => value === undefined)) {
|
|
122
130
|
diagnostics.push({ severity: "error", code: "entry.meta", file: entry,
|
|
123
|
-
message: "Optional meta
|
|
131
|
+
message: "Optional meta requires literal capability IDs or direct SDK Capability members." });
|
|
124
132
|
return { capabilities: [], diagnostics };
|
|
125
133
|
}
|
|
126
|
-
const capabilities =
|
|
134
|
+
const capabilities = resolved.filter((value) => value !== undefined);
|
|
127
135
|
if (new Set(capabilities).size !== capabilities.length)
|
|
128
136
|
diagnostics.push({ severity: "error", code: "entry.meta", file: entry,
|
|
129
137
|
message: "Meta capability ids must be unique." });
|
|
130
|
-
return { capabilities, diagnostics };
|
|
138
|
+
return { capabilities: diagnostics.length === 0 ? capabilities : [], diagnostics };
|
|
131
139
|
}
|
package/dist/pack/usage.js
CHANGED
|
@@ -4,6 +4,7 @@ import ts from "typescript";
|
|
|
4
4
|
import { parse } from "yaml";
|
|
5
5
|
import { RUNTIME_MODULE, SATISFACTORY_MODULE } from "../conventions.js";
|
|
6
6
|
import { isInside } from "./discover.js";
|
|
7
|
+
import { sdkEnumLiteral } from "./capabilityEnums.js";
|
|
7
8
|
const REFLECTION_METHODS = new Set(["getClass", "getObject", "getDataAsset"]);
|
|
8
9
|
/** Discovers manifest authority inputs from reachable TypeScript and imported YAML without executing pack code. */
|
|
9
10
|
export function discoverPackUsage(packRoot, entry) {
|
|
@@ -44,10 +45,10 @@ export function discoverPackUsage(packRoot, entry) {
|
|
|
44
45
|
return;
|
|
45
46
|
const method = node.expression.name.text;
|
|
46
47
|
if (method === "import") {
|
|
47
|
-
const kind =
|
|
48
|
+
const kind = node.arguments[0] && sdkEnumLiteral(node.arguments[0], source, "ImportKind");
|
|
48
49
|
const path = stringLiteral(node.arguments[1]);
|
|
49
50
|
if (kind === undefined || path === undefined) {
|
|
50
|
-
throw new Error(`${shownPath(packRoot, file)}: ctx.import requires literal
|
|
51
|
+
throw new Error(`${shownPath(packRoot, file)}: ctx.import requires a literal or imported ImportKind member and a literal path so CLI can secure manifest imports.`);
|
|
51
52
|
}
|
|
52
53
|
imports.set(`${kind}\n${path}`, { kind, path });
|
|
53
54
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const raw = JSON.parse(readFileSync(require.resolve("@sf-kmods/kdataforgejs/enums.kdfjs.json"), "utf8"));
|
|
5
|
+
function record(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
if (!record(raw) || !Array.isArray(raw.enums) || !Array.isArray(raw.schemaBindings) ||
|
|
9
|
+
raw.enums.some((value) => !record(value) || typeof value.name !== "string" || !record(value.members) ||
|
|
10
|
+
Object.values(value.members).some((member) => typeof member !== "string" && !Number.isSafeInteger(member))) ||
|
|
11
|
+
raw.schemaBindings.some((value) => !record(value) || typeof value.file !== "string" || typeof value.pointer !== "string" || typeof value.enum !== "string")) {
|
|
12
|
+
throw new Error("Invalid canonical SDK enum description.");
|
|
13
|
+
}
|
|
14
|
+
export const apiEnums = raw;
|
|
15
|
+
export function enumMember(name, value) {
|
|
16
|
+
const entry = apiEnums.enums.find((entry) => entry.name === name);
|
|
17
|
+
const member = entry && Object.entries(entry.members).find(([, candidate]) => candidate === value)?.[0];
|
|
18
|
+
if (member === undefined)
|
|
19
|
+
throw new Error(`Unknown ${name} enum value '${String(value)}'; synchronize the SDK and schemas.`);
|
|
20
|
+
return `${name}.${member}`;
|
|
21
|
+
}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
import { existsSync,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { isScalar, parseDocument } from "yaml";
|
|
4
5
|
import { formatGeneratedContent } from "./format.js";
|
|
6
|
+
import { assertSafeWrite, commitStaged, stageTexts } from "../pack/transaction.js";
|
|
5
7
|
const CONFIG_ID = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/u;
|
|
6
8
|
const MAX_CONFIG_FILES = 256;
|
|
7
9
|
const MAX_FIELDS = 1024;
|
|
8
10
|
const MAX_DIRECTORY_DEPTH = 16;
|
|
11
|
+
const GENERATED = "// Generated by kdf sync. Do not edit.";
|
|
9
12
|
/** Emits pack-local keys only; a generated map never grants config access to a script. */
|
|
10
13
|
export function syncConfigTypes(packRoot) {
|
|
11
14
|
const output = generateConfigTypes(packRoot);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const files = [output, ...output.runtimeFiles];
|
|
16
|
+
for (const file of files)
|
|
17
|
+
assertSafeWrite(packRoot, file.path);
|
|
18
|
+
commitStaged(stageTexts(files.filter((file) => !existsSync(file.path) || readFileSync(file.path, "utf8") !== file.content)));
|
|
16
19
|
return output.path;
|
|
17
20
|
}
|
|
18
21
|
export function generateConfigTypes(packRoot) {
|
|
19
22
|
const fields = new Map();
|
|
23
|
+
const enums = [];
|
|
20
24
|
for (const path of configFiles(packRoot)) {
|
|
21
|
-
const
|
|
25
|
+
const yaml = parseDocument(readFileSync(path, "utf8"), { intAsBigInt: true });
|
|
26
|
+
if (yaml.errors.length > 0)
|
|
27
|
+
throw new Error(`Invalid config YAML: ${path}`);
|
|
28
|
+
const document = yaml.toJS();
|
|
22
29
|
const entries = asRecord(document)?.fields;
|
|
23
30
|
if (!Array.isArray(entries))
|
|
24
31
|
continue;
|
|
25
|
-
for (const entry of entries) {
|
|
32
|
+
for (const [index, entry] of entries.entries()) {
|
|
26
33
|
const field = asRecord(entry);
|
|
27
34
|
if (field === undefined || typeof field.id !== "string" || !CONFIG_ID.test(field.id))
|
|
28
35
|
throw new Error(`Invalid config id in ${path}.`);
|
|
@@ -30,14 +37,73 @@ export function generateConfigTypes(packRoot) {
|
|
|
30
37
|
throw new Error(`Duplicate config id '${field.id}'.`);
|
|
31
38
|
if (fields.size >= MAX_FIELDS)
|
|
32
39
|
throw new Error("Config type generation exceeds field limit.");
|
|
33
|
-
|
|
40
|
+
const options = Array.isArray(field.options) ? field.options.map((option, optionIndex) => {
|
|
41
|
+
const scalar = yaml.getIn(["fields", index, "options", optionIndex, "value"], true);
|
|
42
|
+
return { ...asRecord(option), value: isScalar(scalar) && typeof scalar.value !== "string" ? scalar.source ?? scalar.value : asRecord(option)?.value };
|
|
43
|
+
}) : field.options;
|
|
44
|
+
const selection = field.type === "select" ? selectionEnum({ ...field, options }) : undefined;
|
|
45
|
+
if (selection)
|
|
46
|
+
enums.push(selection.declaration);
|
|
47
|
+
const scalar = selection ? `import("../scripts/generated/kdataforgejs-config-enums").${selection.name}` : fieldType({ ...field, multiple: false });
|
|
48
|
+
fields.set(field.id, field.multiple === true ? `readonly (${scalar})[]` : scalar);
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
51
|
const path = join(packRoot, "typescript/kdataforgejs-config.d.ts");
|
|
37
52
|
const entries = [...fields].sort(([left], [right]) => left.localeCompare(right))
|
|
38
53
|
.map(([id, type]) => `readonly ${JSON.stringify(id)}: ${type};`).join("\n");
|
|
39
|
-
const content = formatGeneratedContent(
|
|
40
|
-
|
|
54
|
+
const content = formatGeneratedContent(`${GENERATED}\ndeclare module "@sf-kmods/kdataforgejs" { export interface ConfigValueMap {\n${entries}\n} }\n`, path);
|
|
55
|
+
const runtimePath = join(packRoot, "scripts/generated/kdataforgejs-config-enums.ts");
|
|
56
|
+
assertSafeWrite(packRoot, runtimePath);
|
|
57
|
+
if (existsSync(runtimePath) && !readFileSync(runtimePath, "utf8").startsWith(GENERATED))
|
|
58
|
+
throw new Error(`Refusing to overwrite authored file: ${runtimePath}`);
|
|
59
|
+
const runtimeContent = formatGeneratedContent(`${GENERATED}\n${enums.sort().join("\n")}\nexport {};\n`, runtimePath);
|
|
60
|
+
if (Buffer.byteLength(runtimeContent) > 256 * 1024)
|
|
61
|
+
throw new Error("Generated config enums exceed the script module byte limit.");
|
|
62
|
+
return { path, content, runtimeFiles: [{ path: runtimePath, content: runtimeContent }] };
|
|
63
|
+
}
|
|
64
|
+
function selectionEnum(field) {
|
|
65
|
+
if (!Array.isArray(field.options) || field.options.length === 0 || field.options.length > 1024)
|
|
66
|
+
throw new Error(`Select '${String(field.id)}' requires 1–1024 static options.`);
|
|
67
|
+
const id = String(field.id);
|
|
68
|
+
const name = `Config${id.split(/[^A-Za-z0-9]+/u).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}_${createHash("sha256").update(id).digest("hex").slice(0, 8)}`;
|
|
69
|
+
const values = field.options.map((option) => choiceValue(asRecord(option)?.value, String(field.valueType ?? "string").trim().toLowerCase()));
|
|
70
|
+
const names = new Set();
|
|
71
|
+
const members = values.map((value, index) => {
|
|
72
|
+
const stem = typeof value === "string" ? value.split(/[^A-Za-z0-9]+/u).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("") : `Value${index}`;
|
|
73
|
+
let member = /^[A-Za-z][A-Za-z0-9]*$/u.test(stem) ? stem : `Value${index}`;
|
|
74
|
+
if (["constructor", "prototype", "__proto__"].includes(member) || names.has(member))
|
|
75
|
+
member = `Value${index}_${createHash("sha256").update(String(value)).digest("hex").slice(0, 8)}`;
|
|
76
|
+
names.add(member);
|
|
77
|
+
return `${member}: ${typeof value === "bigint" ? `${value}n` : JSON.stringify(value)}`;
|
|
78
|
+
});
|
|
79
|
+
if (values.every((value) => typeof value === "string" || typeof value === "number"))
|
|
80
|
+
return { name, declaration: `export enum ${name} { ${members.map((entry) => entry.replace(": ", " = ")).join(", ")} }` };
|
|
81
|
+
return { name, declaration: `export const ${name} = Object.freeze({ ${members.join(", ")} } as const);\nexport type ${name} = (typeof ${name})[keyof typeof ${name}];` };
|
|
82
|
+
}
|
|
83
|
+
function choiceValue(value, type) {
|
|
84
|
+
if (!["string", "number", "bigint", "boolean"].includes(typeof value))
|
|
85
|
+
throw new Error("Config option values must be scalar.");
|
|
86
|
+
const text = String(value);
|
|
87
|
+
if (["string", "text", "name", "tag"].includes(type))
|
|
88
|
+
return text;
|
|
89
|
+
if (type === "bool") {
|
|
90
|
+
if (["true", "yes", "on", "1"].includes(text.trim().toLowerCase()))
|
|
91
|
+
return true;
|
|
92
|
+
if (["false", "no", "off", "0"].includes(text.trim().toLowerCase()))
|
|
93
|
+
return false;
|
|
94
|
+
throw new Error(`Invalid boolean config option '${text}'.`);
|
|
95
|
+
}
|
|
96
|
+
if (["int8", "int16", "int32", "int64", "uint8"].includes(type)) {
|
|
97
|
+
if (!/^[+-]?\d+$/u.test(text))
|
|
98
|
+
throw new Error(`Invalid integer config option '${text}'.`);
|
|
99
|
+
const integer = BigInt(text);
|
|
100
|
+
if (integer < -(2n ** 63n) || integer > 2n ** 63n - 1n)
|
|
101
|
+
throw new Error("Config option is outside int64 range.");
|
|
102
|
+
return integer >= BigInt(Number.MIN_SAFE_INTEGER) && integer <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(integer) : integer;
|
|
103
|
+
}
|
|
104
|
+
if (["float", "double"].includes(type) && text.trim() !== "" && Number.isFinite(Number(text)))
|
|
105
|
+
return Number(text);
|
|
106
|
+
throw new Error(`Unsupported config option valueType '${type}'.`);
|
|
41
107
|
}
|
|
42
108
|
function configFiles(root) {
|
|
43
109
|
const result = [];
|
|
@@ -3,6 +3,7 @@ import { basename, join } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import ts from "typescript";
|
|
5
5
|
import { parse } from "yaml";
|
|
6
|
+
import { apiEnums, enumMember } from "./apiEnums.js";
|
|
6
7
|
const DOCUMENTS = {
|
|
7
8
|
AssetDocument: "asset", CategoryReorderDocument: "category_reorder", CdoDocument: "cdo",
|
|
8
9
|
CurveDocument: "curve", DataAssetDocument: "dataasset", EventRuleDocument: "eventrule",
|
|
@@ -58,7 +59,7 @@ class ContentTypes {
|
|
|
58
59
|
declarations() {
|
|
59
60
|
const declarations = [];
|
|
60
61
|
for (const [key, located] of this.aliases) {
|
|
61
|
-
declarations.push(`type ${aliasName(key)} = ${this.render(located
|
|
62
|
+
declarations.push(`type ${aliasName(key)} = ${this.render(located)};`);
|
|
62
63
|
}
|
|
63
64
|
return declarations.join("\n");
|
|
64
65
|
}
|
|
@@ -72,18 +73,23 @@ class ContentTypes {
|
|
|
72
73
|
this.schemas.set(file, schema);
|
|
73
74
|
return schema;
|
|
74
75
|
}
|
|
75
|
-
render(
|
|
76
|
+
render(located) {
|
|
77
|
+
const { schema, file, pointer } = located;
|
|
76
78
|
const parts = [];
|
|
77
79
|
if (typeof schema.$ref === "string") {
|
|
78
80
|
const [path = "", pointer = ""] = schema.$ref.split("#");
|
|
79
81
|
parts.push(this.reference(path === "" ? file : basename(path), pointer));
|
|
80
82
|
}
|
|
83
|
+
const binding = apiEnums.schemaBindings.find((entry) => entry.file === file && entry.pointer === pointer);
|
|
81
84
|
if ("const" in schema)
|
|
82
|
-
parts.push(literal(schema.const));
|
|
83
|
-
else if (Array.isArray(schema.enum))
|
|
84
|
-
|
|
85
|
+
parts.push(binding ? enumMember(binding.enum, schema.const) : literal(schema.const));
|
|
86
|
+
else if (Array.isArray(schema.enum)) {
|
|
87
|
+
if (!binding)
|
|
88
|
+
throw new Error(`Unmapped schema enum: ${file}#${pointer}`);
|
|
89
|
+
parts.push(schema.enum.map((value) => enumMember(binding.enum, value)).join(" | "));
|
|
90
|
+
}
|
|
85
91
|
else {
|
|
86
|
-
const type = this.valueType(
|
|
92
|
+
const type = this.valueType(located);
|
|
87
93
|
if (type !== undefined)
|
|
88
94
|
parts.push(type);
|
|
89
95
|
}
|
|
@@ -91,15 +97,16 @@ class ContentTypes {
|
|
|
91
97
|
const entries = schema[key];
|
|
92
98
|
if (!Array.isArray(entries))
|
|
93
99
|
continue;
|
|
94
|
-
const types = entries.map((entry) => this.render(record(entry) ?? {}
|
|
100
|
+
const types = entries.map((entry, index) => this.render({ file, pointer: `${pointer}/${key}/${index}`, schema: record(entry) ?? {} }));
|
|
95
101
|
if (types.length > 0)
|
|
96
102
|
parts.push(`(${types.join(key === "allOf" ? " & " : " | ")})`);
|
|
97
103
|
}
|
|
98
104
|
return parts.length === 0 ? "unknown" : parts.map((part) => `(${part})`).join(" & ");
|
|
99
105
|
}
|
|
100
|
-
valueType(
|
|
106
|
+
valueType(located) {
|
|
107
|
+
const { schema, file, pointer } = located;
|
|
101
108
|
if (Array.isArray(schema.type)) {
|
|
102
|
-
return schema.type.map((type) => this.valueType({ ...schema, type }
|
|
109
|
+
return schema.type.map((type) => this.valueType({ ...located, schema: { ...schema, type } }) ?? "unknown").join(" | ");
|
|
103
110
|
}
|
|
104
111
|
if (schema.type === "string")
|
|
105
112
|
return "string";
|
|
@@ -110,23 +117,23 @@ class ContentTypes {
|
|
|
110
117
|
if (schema.type === "null")
|
|
111
118
|
return "null";
|
|
112
119
|
if (schema.type === "array")
|
|
113
|
-
return `ReadonlyArray<${this.render(record(schema.items) ?? {}
|
|
120
|
+
return `ReadonlyArray<${this.render({ file, pointer: `${pointer}/items`, schema: record(schema.items) ?? {} })}>`;
|
|
114
121
|
if (schema.type === "object" || schema.properties !== undefined || schema.required !== undefined)
|
|
115
|
-
return this.objectType(
|
|
122
|
+
return this.objectType(located);
|
|
116
123
|
return undefined;
|
|
117
124
|
}
|
|
118
|
-
objectType(schema, file) {
|
|
125
|
+
objectType({ schema, file, pointer }) {
|
|
119
126
|
const properties = record(schema.properties) ?? {};
|
|
120
127
|
const required = new Set(Array.isArray(schema.required) ? schema.required.filter((value) => typeof value === "string") : []);
|
|
121
128
|
const names = [...new Set([...Object.keys(properties), ...required])].sort();
|
|
122
|
-
const fields = names.map((name) => `readonly ${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${this.render(record(properties[name]) ?? {}
|
|
129
|
+
const fields = names.map((name) => `readonly ${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${this.render({ file, pointer: `${pointer}/properties/${name.replaceAll("~", "~0").replaceAll("/", "~1")}`, schema: record(properties[name]) ?? {} })};`);
|
|
123
130
|
const excluded = record(schema.not)?.required;
|
|
124
131
|
if (Array.isArray(excluded) && excluded.length === 1 && typeof excluded[0] === "string") {
|
|
125
132
|
fields.push(`readonly ${JSON.stringify(excluded[0])}?: never;`);
|
|
126
133
|
}
|
|
127
134
|
const additional = record(schema.additionalProperties);
|
|
128
135
|
if (additional !== undefined)
|
|
129
|
-
fields.push(`readonly [key: string]: ${this.render(
|
|
136
|
+
fields.push(`readonly [key: string]: ${this.render({ file, pointer: `${pointer}/additionalProperties`, schema: additional })};`);
|
|
130
137
|
if (fields.length === 0 && schema.additionalProperties !== false)
|
|
131
138
|
return "Readonly<Record<string, unknown>>";
|
|
132
139
|
return `{ ${fields.join(" ")} }`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sf-kmods/kdataforgejs-cli",
|
|
3
|
-
"version": "2026.4.
|
|
3
|
+
"version": "2026.4.37",
|
|
4
4
|
"description": "kdf - create, type-check and validate KDataForge projects with KDataForgeJS (TypeScript) scripts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kyri123/Kyrium",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@biomejs/wasm-nodejs": "2.6.3",
|
|
40
40
|
"typescript": ">=5.7.3 <6",
|
|
41
41
|
"yaml": "^2.6.1",
|
|
42
|
-
"@sf-kmods/kdataforgejs": "^2026.4.
|
|
42
|
+
"@sf-kmods/kdataforgejs": "^2026.4.37"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^22.10.0"
|
|
@@ -351,10 +351,65 @@ $defs:
|
|
|
351
351
|
properties:
|
|
352
352
|
op: { const: update_where }
|
|
353
353
|
properties:
|
|
354
|
-
type:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
354
|
+
if: { type: object }
|
|
355
|
+
then:
|
|
356
|
+
minProperties: 1
|
|
357
|
+
propertyNames:
|
|
358
|
+
anyOf:
|
|
359
|
+
- $ref: '#/$defs/propertyPath'
|
|
360
|
+
- const: '@tagContainers'
|
|
361
|
+
additionalProperties:
|
|
362
|
+
if:
|
|
363
|
+
type: object
|
|
364
|
+
required: ['$op']
|
|
365
|
+
then:
|
|
366
|
+
$ref: '#/$defs/mappingOperation'
|
|
367
|
+
else:
|
|
368
|
+
type: array
|
|
369
|
+
minItems: 1
|
|
370
|
+
items:
|
|
371
|
+
$ref: '#/$defs/operation'
|
|
372
|
+
mappingOperation:
|
|
373
|
+
type: object
|
|
374
|
+
required: ['$op']
|
|
375
|
+
additionalProperties: false
|
|
376
|
+
properties:
|
|
377
|
+
$op:
|
|
378
|
+
enum: [add, append, append_unique, clamp, clear, copy, divide, duplicate, insert, max, min, move, multiply, prepend, remove, remove_at, replace_refs, replace, reverse, set, sort, subtract, swap, unique, update_where]
|
|
379
|
+
value: {}
|
|
380
|
+
where:
|
|
381
|
+
oneOf:
|
|
382
|
+
- $ref: '#/$defs/whereClause'
|
|
383
|
+
- type: array
|
|
384
|
+
minItems: 1
|
|
385
|
+
items:
|
|
386
|
+
$ref: '#/$defs/whereClause'
|
|
387
|
+
whereMode:
|
|
388
|
+
$ref: '#/$defs/whereMode'
|
|
389
|
+
min:
|
|
390
|
+
anyOf: [{ type: number }, { $ref: '#/$defs/typedRef' }]
|
|
391
|
+
max:
|
|
392
|
+
anyOf: [{ type: number }, { $ref: '#/$defs/typedRef' }]
|
|
393
|
+
index:
|
|
394
|
+
anyOf: [{ type: integer }, { $ref: '#/$defs/typedRef' }]
|
|
395
|
+
with:
|
|
396
|
+
anyOf: [{ type: integer }, { $ref: '#/$defs/typedRef' }]
|
|
397
|
+
from:
|
|
398
|
+
$ref: '#/$defs/nonEmptyString'
|
|
399
|
+
allOf:
|
|
400
|
+
- if:
|
|
401
|
+
properties:
|
|
402
|
+
$op: { enum: [copy, move] }
|
|
403
|
+
then:
|
|
404
|
+
properties:
|
|
405
|
+
from:
|
|
406
|
+
$ref: '#/$defs/propertyPath'
|
|
407
|
+
- if:
|
|
408
|
+
required: [whereMode]
|
|
409
|
+
then:
|
|
410
|
+
required: ['$op', where]
|
|
411
|
+
properties:
|
|
412
|
+
$op: { const: update_where }
|
|
358
413
|
generatedEntry:
|
|
359
414
|
type: object
|
|
360
415
|
additionalProperties: false
|
package/schemas/pack.schema.yml
CHANGED
|
@@ -4,7 +4,7 @@ x-kdf-type: pack
|
|
|
4
4
|
title: KDataForge pack manifest
|
|
5
5
|
type: object
|
|
6
6
|
additionalProperties: false
|
|
7
|
-
required: [ref, name, version
|
|
7
|
+
required: [ref, name, version]
|
|
8
8
|
properties:
|
|
9
9
|
$schema:
|
|
10
10
|
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/schemaReference
|
|
@@ -58,3 +58,78 @@ properties:
|
|
|
58
58
|
type: object
|
|
59
59
|
additionalProperties:
|
|
60
60
|
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/token
|
|
61
|
+
scripts:
|
|
62
|
+
description: Explicit runtime script entries. IDs are generated; capabilities belong in TypeScript meta.
|
|
63
|
+
type: array
|
|
64
|
+
items:
|
|
65
|
+
type: object
|
|
66
|
+
additionalProperties: false
|
|
67
|
+
required: [language, entry]
|
|
68
|
+
not:
|
|
69
|
+
required: [reflectionClasses, classes]
|
|
70
|
+
properties:
|
|
71
|
+
language:
|
|
72
|
+
type: string
|
|
73
|
+
maxLength: 128
|
|
74
|
+
pattern: '^\s*[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z][A-Za-z0-9_-]*)*\s*$'
|
|
75
|
+
languageVersion:
|
|
76
|
+
type: integer
|
|
77
|
+
minimum: 1
|
|
78
|
+
maximum: 4294967295
|
|
79
|
+
default: 1
|
|
80
|
+
entry:
|
|
81
|
+
$ref: '#/$defs/scriptPath'
|
|
82
|
+
realm:
|
|
83
|
+
type: string
|
|
84
|
+
pattern: '^([aA][nN][yY]|[sS][eE][rR][vV][eE][rR]|[cC][lL][iI][eE][nN][tT])$'
|
|
85
|
+
network:
|
|
86
|
+
type: string
|
|
87
|
+
pattern: '^([aA][nN][yY]|[sS][tT][aA][nN][dD][aA][lL][oO][nN][eE]|[nN][eE][tT][wW][oO][rR][kK][eE][dD])$'
|
|
88
|
+
authority:
|
|
89
|
+
type: string
|
|
90
|
+
pattern: '^([aA][nN][yY]|[rR][eE][qQ][uU][iI][rR][eE][dD]|[fF][oO][rR][bB][iI][dD][dD][eE][nN])$'
|
|
91
|
+
reflectionClasses:
|
|
92
|
+
$ref: '#/$defs/reflectionClasses'
|
|
93
|
+
classes:
|
|
94
|
+
$ref: '#/$defs/reflectionClasses'
|
|
95
|
+
imports:
|
|
96
|
+
type: array
|
|
97
|
+
maxItems: 64
|
|
98
|
+
items:
|
|
99
|
+
type: object
|
|
100
|
+
additionalProperties: false
|
|
101
|
+
required: [key, kind, path]
|
|
102
|
+
anyOf:
|
|
103
|
+
- required: [sha256]
|
|
104
|
+
- required: [digest]
|
|
105
|
+
properties:
|
|
106
|
+
key:
|
|
107
|
+
type: string
|
|
108
|
+
maxLength: 128
|
|
109
|
+
pattern: '^[A-Za-z][A-Za-z0-9._/-]*$'
|
|
110
|
+
kind:
|
|
111
|
+
type: string
|
|
112
|
+
pattern: '^([yY][aA][mM][lL]|[sS][tT][rR][uU][cC][tT][uU][rR][eE][dD]|[tT][eE][xX][tT]|[bB][iI][nN][aA][rR][yY]|[iI][mM][aA][gG][eE]|[aA][uU][dD][iI][oO])$'
|
|
113
|
+
path:
|
|
114
|
+
$ref: '#/$defs/scriptPath'
|
|
115
|
+
sha256:
|
|
116
|
+
$ref: '#/$defs/sha256'
|
|
117
|
+
digest:
|
|
118
|
+
$ref: '#/$defs/sha256'
|
|
119
|
+
$defs:
|
|
120
|
+
scriptPath:
|
|
121
|
+
type: string
|
|
122
|
+
minLength: 1
|
|
123
|
+
maxLength: 1024
|
|
124
|
+
pattern: '^[A-Za-z0-9][A-Za-z0-9._/-]*$'
|
|
125
|
+
sha256:
|
|
126
|
+
type: string
|
|
127
|
+
pattern: '^[A-Fa-f0-9]{64}$'
|
|
128
|
+
reflectionClasses:
|
|
129
|
+
type: array
|
|
130
|
+
maxItems: 64
|
|
131
|
+
uniqueItems: true
|
|
132
|
+
items:
|
|
133
|
+
type: string
|
|
134
|
+
maxLength: 1024
|
|
135
|
+
pattern: '^/[^\\\s]+\.[^\\\s/]+$'
|
package/schemas/sound.schema.yml
CHANGED
|
@@ -2,7 +2,7 @@ $schema: https://json-schema.org/draft/2020-12/schema
|
|
|
2
2
|
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/sound.schema.yml
|
|
3
3
|
x-kdf-type: sound
|
|
4
4
|
title: KDataForge Wwise sounds
|
|
5
|
-
description: Import pack-relative PCM16 WAV
|
|
5
|
+
description: Import pack-relative PCM16 WAV, native FLAC or Ogg Vorbis files as Wwise audio events, including ADA voice-over. Finite 2D sounds, mono/stereo, 8000-192000 Hz, maximum 64 MiB encoded and decoded.
|
|
6
6
|
allOf:
|
|
7
7
|
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
8
8
|
- type: object
|
|
@@ -24,8 +24,8 @@ allOf:
|
|
|
24
24
|
file:
|
|
25
25
|
type: string
|
|
26
26
|
minLength: 1
|
|
27
|
-
pattern: '\.([Ww][Aa][Vv]|[Ff][Ll][Aa][Cc])$'
|
|
28
|
-
description: Path relative to pack root. PCM16
|
|
27
|
+
pattern: '\.([Ww][Aa][Vv]|[Ff][Ll][Aa][Cc]|[Oo][Gg][Gg])$'
|
|
28
|
+
description: Path relative to pack root. PCM16 WAV, native 16-bit FLAC or Ogg Vorbis, mono/stereo, 8000-192000 Hz, at most 64 MiB encoded and decoded. FLAC requires a known nonzero frame count. Ogg FLAC, Opus, 24-bit FLAC and float WAV are unsupported. Path and symbolic links must stay inside pack.
|
|
29
29
|
name:
|
|
30
30
|
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
31
31
|
pattern: '\S'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ctx } from "@sf-kmods/kdataforgejs";
|
|
2
2
|
import { describeCatalog } from "../lib/catalog-v1";
|
|
3
3
|
|
|
4
|
-
export function install(
|
|
4
|
+
export function install(): () => void {
|
|
5
5
|
const timer = ctx.setTimeout(() => console.info(describeCatalog("{{ref}}", ctx.catalog().digest)), 0.1);
|
|
6
6
|
return () => ctx.clearTimeout(timer);
|
|
7
7
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineHandler, defineMeta } from "@sf-kmods/kdataforgejs";
|
|
1
|
+
import { ctx, defineHandler, defineMeta } from "@sf-kmods/kdataforgejs";
|
|
2
2
|
import { install as installCatalog } from "./features/catalog";
|
|
3
3
|
|
|
4
4
|
export const meta = defineMeta({ capabilities: [] });
|
|
5
5
|
|
|
6
6
|
const ENABLE_CATALOG_FEATURE = false;
|
|
7
7
|
|
|
8
|
-
export default defineHandler(async (
|
|
8
|
+
export default defineHandler(async () => {
|
|
9
9
|
const cleanup = ctx.createCleanupBag();
|
|
10
|
-
if (ENABLE_CATALOG_FEATURE) cleanup.add(installCatalog(
|
|
10
|
+
if (ENABLE_CATALOG_FEATURE) cleanup.add(installCatalog());
|
|
11
11
|
await Promise.resolve();
|
|
12
12
|
});
|