@wildshard/shard-format 0.11.0 → 0.13.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -407,12 +407,12 @@
|
|
|
407
407
|
"packageManager": "pnpm@10.34.9",
|
|
408
408
|
"scripts": {
|
|
409
409
|
"pnpm:devPreinstall": "git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
|
|
410
|
-
"typecheck": "tsc -p kit/tsconfig.json && tsc -p src/format/tsconfig.json && tsc -p src/format/tsconfig.lib.json",
|
|
411
|
-
"lint": "node kit/scripts/lint.mjs --type-aware --deny-warnings --no-error-on-unmatched-pattern --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**' --ignore-pattern 'scripts/chromium-keychain*' --ignore-pattern 'scripts/worktree-ignore*' --ignore-pattern 'scripts/land*' --ignore-pattern 'scripts/worktree.mjs' --ignore-pattern 'scripts/worktree-reap.mjs' --ignore-pattern 'scripts/pid-lock*' --ignore-pattern 'scripts/apfs-clone.mjs' --ignore-pattern 'scripts/assert-store-layout.mjs' --ignore-pattern 'test/tooling/worktree-guard.test.mjs' --ignore-pattern 'scripts/vite-tmp*' --ignore-pattern 'vitest.config.ts' --ignore-pattern 'test/tooling/chrome-keychain.test.mjs' --ignore-pattern 'packages/wire/frozen/**' --ignore-pattern 'packages/wire/lib/**'",
|
|
410
|
+
"typecheck": "npr tsc -p kit/tsconfig.json && npr tsc -p src/format/tsconfig.json && npr tsc -p src/format/tsconfig.lib.json",
|
|
411
|
+
"lint": "node kit/scripts/lint.mjs --type-aware --deny-warnings --no-error-on-unmatched-pattern --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**' --ignore-pattern 'scripts/chromium-keychain*' --ignore-pattern 'scripts/worktree-ignore*' --ignore-pattern 'scripts/land*' --ignore-pattern 'scripts/main-push*' --ignore-pattern 'scripts/worktree.mjs' --ignore-pattern 'scripts/worktree-reap.mjs' --ignore-pattern 'scripts/pid-lock*' --ignore-pattern 'scripts/apfs-clone.mjs' --ignore-pattern 'scripts/assert-store-layout.mjs' --ignore-pattern 'test/tooling/worktree-guard.test.mjs' --ignore-pattern 'scripts/vite-tmp*' --ignore-pattern 'vitest.config.ts' --ignore-pattern 'test/tooling/chrome-keychain.test.mjs' --ignore-pattern 'packages/wire/frozen/**' --ignore-pattern 'packages/wire/lib/**'",
|
|
412
412
|
"lint:fix": "node kit/scripts/lint.mjs --type-aware --fix --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**'",
|
|
413
413
|
"lint:format": "node src/tools/format-ratchet.ts",
|
|
414
|
-
"format": "oxfmt -c kit/.oxfmtrc.json kit src '!src/format/**' '!src/test/fixtures/**'",
|
|
415
|
-
"format:check": "oxfmt -c kit/.oxfmtrc.json --check kit src '!src/format/**' '!src/test/fixtures/**'",
|
|
414
|
+
"format": "npr oxfmt -c kit/.oxfmtrc.json kit src '!src/format/**' '!src/test/fixtures/**'",
|
|
415
|
+
"format:check": "npr oxfmt -c kit/.oxfmtrc.json --check kit src '!src/format/**' '!src/test/fixtures/**'",
|
|
416
416
|
"test": "node --test 'src/!(format|ci)/**/*.test.ts'",
|
|
417
417
|
"test:ci": "node --test 'src/ci/**/*.test.ts'",
|
|
418
418
|
"test:format": "vitest run src/format --testTimeout=30000 --maxWorkers=2",
|
|
@@ -424,10 +424,11 @@
|
|
|
424
424
|
"agents:sync": "node scripts/agent-sync.mjs",
|
|
425
425
|
"md:wrap": "node kit/scripts/md-wrap.mjs",
|
|
426
426
|
"test:hooks": "node --test '.githooks/*.test.mjs'",
|
|
427
|
-
"check": "pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
|
|
427
|
+
"check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
|
|
428
428
|
"check:wire": "pnpm --dir packages/wire check && pnpm --dir packages/wire test && pnpm check:wire-proofs",
|
|
429
429
|
"check:wire-proofs": "node --test src/scripts/wire/recordings-proof.mjs src/scripts/wire/graph-proof.mjs src/scripts/wire/prepared-frame-proof.mjs",
|
|
430
|
-
"bench": "pnpm --dir packages/wire bench"
|
|
430
|
+
"bench": "pnpm --dir packages/wire bench",
|
|
431
|
+
"check:bin-pins": "node kit/scripts/bin-pins.mjs"
|
|
431
432
|
},
|
|
432
433
|
"dependencies": {
|
|
433
434
|
"meshoptimizer": "1.2.0",
|
|
@@ -438,13 +439,11 @@
|
|
|
438
439
|
"@typescript/typescript6": "6.0.2",
|
|
439
440
|
"binaryen": "132.0.0",
|
|
440
441
|
"fflate": "0.8.3",
|
|
441
|
-
"oxfmt": "0.74.0",
|
|
442
442
|
"oxlint": "1.89.0",
|
|
443
|
-
"oxlint-tsgolint": "7.0.2004",
|
|
444
443
|
"playwright": "1.64.1",
|
|
445
|
-
"typescript": "7.0.2",
|
|
446
444
|
"vite": "8.3.0",
|
|
447
|
-
"vitest": "5.0.1"
|
|
445
|
+
"vitest": "5.0.1",
|
|
446
|
+
"npm-bin-deps": "2.1.0"
|
|
448
447
|
},
|
|
449
448
|
"pnpm": {
|
|
450
449
|
"ignoredOptionalDependencies": [
|
|
@@ -529,5 +528,11 @@
|
|
|
529
528
|
"@typescript/typescript-win32-arm64",
|
|
530
529
|
"@typescript/typescript-win32-x64"
|
|
531
530
|
]
|
|
532
|
-
}
|
|
531
|
+
},
|
|
532
|
+
"binDependencies": {
|
|
533
|
+
"typescript": "7.0.2",
|
|
534
|
+
"oxfmt": "0.74.0",
|
|
535
|
+
"oxlint-tsgolint": "7.0.2004"
|
|
536
|
+
},
|
|
537
|
+
"binDependenciesInstaller": "npm"
|
|
533
538
|
}
|
|
@@ -85,10 +85,10 @@ interface AssetAdmission {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/** The checks before any byte is read: preflight, schema, decision modules, the graph and declared costs. */
|
|
88
|
-
// oxlint-disable-next-line eslint/max-statements, typescript/prefer-readonly-parameter-types --
|
|
89
|
-
function assetAdmission(input: unknown, memory: MemoryAdmission | undefined, scripts: ScriptAdmissionRows): AssetAdmission {
|
|
88
|
+
// oxlint-disable-next-line eslint/max-params, eslint/max-statements, typescript/prefer-readonly-parameter-types -- the existing admission state also receives its checked section context
|
|
89
|
+
function assetAdmission(input: unknown, memory: MemoryAdmission | undefined, scripts: ScriptAdmissionRows, sections?: ReadonlyMap<string, unknown>): AssetAdmission {
|
|
90
90
|
preflightShardfile(input);
|
|
91
|
-
const s = parseShardfile(input), files = new Map(s.files.map((f) => [f.hash, f]));
|
|
91
|
+
const s = parseShardfile(input, sections), files = new Map(s.files.map((f) => [f.hash, f]));
|
|
92
92
|
const contracts = decisionModuleContracts(scripts, s.files);
|
|
93
93
|
const legacyModules = new Set([...s.sim.scripts, ...s.clientScripts.bindings.map(row => row.module), ...s.movers.filter(row => row.execution !== 'native').map(row => row.module)]);
|
|
94
94
|
if ([...contracts.keys()].some(hash => legacyModules.has(hash))) throw new Error('Decision module cannot also use a legacy script host');
|
|
@@ -266,8 +266,8 @@ function admitAfterFiles(state: AssetAdmission, assets: ReadonlyMap<string, Uint
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
/** Admit exact bytes, graph closure, script growth and worst-location residency before a runtime is allocated. */
|
|
269
|
-
function validateShardfileAssets(input: unknown, assets: ReadonlyMap<string, Uint8Array>, contentHash: (bytes: Uint8Array) => string, memory?: MemoryAdmission, textures?: TextureTranscodeSupport, scripts: ScriptAdmissionRows = []): Shardfile {
|
|
270
|
-
const state = assetAdmission(input, memory, scripts);
|
|
269
|
+
function validateShardfileAssets(input: unknown, assets: ReadonlyMap<string, Uint8Array>, contentHash: (bytes: Uint8Array) => string, memory?: MemoryAdmission, textures?: TextureTranscodeSupport, scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
|
|
270
|
+
const state = assetAdmission(input, memory, scripts, sections);
|
|
271
271
|
admitCommonsBytes(state, assets, contentHash);
|
|
272
272
|
for (const file of state.shard.files) {
|
|
273
273
|
admitFileBytes(state, file, assets.get(file.hash), assets, contentHash);
|
|
@@ -148,7 +148,7 @@ export function assembleOutputFields(index: OutputIndex, sections: ReadonlyMap<s
|
|
|
148
148
|
}
|
|
149
149
|
/** The default untrusted reader always checks sections and the full host schema. */
|
|
150
150
|
export function assembleOutputShardfile(input: unknown, sections: ReadonlyMap<string, unknown>): Shardfile {
|
|
151
|
-
const source = parseShardfile(assembleOutputFields(parseOutputIndex(input), sections));
|
|
151
|
+
const source = parseShardfile(assembleOutputFields(parseOutputIndex(input), sections), sections);
|
|
152
152
|
const errors = clientOwnershipRules(source, sections); if (errors.length > 0) throw new Error(errors.join('; '));
|
|
153
153
|
return source;
|
|
154
154
|
}
|
package/src/format/props.ts
CHANGED
|
@@ -27,6 +27,41 @@ function boxWithinCell(b: v.InferOutput<typeof boxData>): boolean {
|
|
|
27
27
|
const box = v.pipe(boxData, v.check(boxWithinCell, 'collider within cell'));
|
|
28
28
|
const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
|
|
29
29
|
const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads])), v.minLength(1), v.maxLength(256)) });
|
|
30
|
+
const BODY_EXTENT_MIN = 0.005;
|
|
31
|
+
const BODY_EXTENT_MAX = 8;
|
|
32
|
+
const BODY_DENSITY_MIN = 1;
|
|
33
|
+
const BODY_DENSITY_MAX = 20_000;
|
|
34
|
+
const BODY_FRICTION_MAX = 2;
|
|
35
|
+
const BODY_DAMPING_MAX = 10;
|
|
36
|
+
const BODIES_MAX = 64;
|
|
37
|
+
const BODY_LEAST = 0;
|
|
38
|
+
const BODIES_LEAST = 1;
|
|
39
|
+
const BODY_SHARE_MAX = 1;
|
|
40
|
+
const halfExtent = v.pipe(finite, v.minValue(BODY_EXTENT_MIN), v.maxValue(BODY_EXTENT_MAX));
|
|
41
|
+
const share = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_SHARE_MAX));
|
|
42
|
+
const friction = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_FRICTION_MAX));
|
|
43
|
+
const damping = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_DAMPING_MAX));
|
|
44
|
+
const density = v.pipe(finite, v.minValue(BODY_DENSITY_MIN), v.maxValue(BODY_DENSITY_MAX));
|
|
45
|
+
const ballShape = v.strictObject({ ball: halfExtent });
|
|
46
|
+
const cylinderShape = v.strictObject({ cylinder: v.strictObject({ radius: halfExtent, halfHeight: halfExtent }) });
|
|
47
|
+
const cuboidShape = v.strictObject({ cuboid: v.strictObject({ x: halfExtent, y: halfExtent, z: halfExtent }) });
|
|
48
|
+
const bodyShape = v.union([ballShape, cylinderShape, cuboidShape]);
|
|
49
|
+
const bodyMaterial = v.picklist(['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt']);
|
|
50
|
+
/** SHARD-SOURCE SS9a: a touchable panel. The server keeps it as one Rapier dynamic body (its rest pose `at` and `yaw`,
|
|
51
|
+
* the shape's half extents in metres); players push it, and every page draws the panel at the body's pose. */
|
|
52
|
+
const body = v.strictObject({ id, panel: id, at: point, yaw: finite, shape: bodyShape, material: bodyMaterial,
|
|
53
|
+
density: v.exactOptional(density), friction: v.exactOptional(friction), restitution: v.exactOptional(share),
|
|
54
|
+
linearDamping: v.exactOptional(damping), angularDamping: v.exactOptional(damping), keep: v.exactOptional(v.boolean()) });
|
|
55
|
+
const bodies = v.pipe(v.array(body), v.minLength(BODIES_LEAST), v.maxLength(BODIES_MAX));
|
|
56
|
+
/** Each body has its own id and names a declared panel that no other body and no static collider claims. */
|
|
57
|
+
function bodiesAdmitted(section: { readonly bodies?: readonly { readonly id: string; readonly panel: string }[] | undefined; readonly panels: readonly { readonly id: string }[]; readonly colliders: readonly { readonly panel: string | null }[] }): boolean {
|
|
58
|
+
const declared = new Set(section.panels.map((panel): string => panel.id));
|
|
59
|
+
const claimed = new Set(section.colliders.map((solid): string | null => solid.panel));
|
|
60
|
+
const rows = section.bodies ?? [];
|
|
61
|
+
const ids = new Set(rows.map((row): string => row.id));
|
|
62
|
+
const owned = new Set(rows.map((row): string => row.panel));
|
|
63
|
+
return ids.size === rows.length && owned.size === rows.length && rows.every((row): boolean => declared.has(row.panel) && !claimed.has(row.panel));
|
|
64
|
+
}
|
|
30
65
|
/** Declared self-contained GLBs: merged tile meshes, EXT_mesh_gpu_instancing lists, far proxy and script-addressable panels. */
|
|
31
66
|
export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.unknown(), v.check(isJsonData, 'JSON-only props'), v.strictObject({ version: v.literal(1), family: id,
|
|
32
67
|
materials: v.exactOptional(PropMaterialsSchema),
|
|
@@ -40,7 +75,8 @@ export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.
|
|
|
40
75
|
panels: v.pipe(v.array(v.strictObject({ id, file: ref, visible: v.optional(v.boolean(), true) })), v.maxLength(64)), models: v.pipe(v.array(named), v.maxLength(64)), far: v.nullable(ref),
|
|
41
76
|
colliders: v.optional(v.pipe(v.array(collider), v.maxLength(1024)), []),
|
|
42
77
|
textures: v.pipe(v.array(v.strictObject({ model: ref, colour: ref })), v.maxLength(256)),
|
|
43
|
-
|
|
78
|
+
bodies: v.exactOptional(bodies),
|
|
79
|
+
}), v.check((s) => new Set(s.tiles.map((tile) => `${tile.lod}/${tile.x}/${tile.z}`)).size === s.tiles.length && s.tiles.every((tile) => tile.x < (tile.lod === 0 ? 8 : 4) && tile.z < (tile.lod === 0 ? 8 : 4)) && new Set([...s.panels, ...s.models].map((entry) => entry.id)).size === s.panels.length + s.models.length && new Set(s.textures.map((texture) => texture.model)).size === s.textures.length && new Set(s.colliders.map((solid) => solid.id)).size === s.colliders.length && s.colliders.reduce((sum, solid) => sum + solid.shapes.reduce((count, shape) => count + (shape.kind === 'treads' ? shape.count : 1), 0), 0) <= 2048 && s.colliders.every((solid) => solid.panel === null || s.panels.some((panel) => panel.id === solid.panel)), 'unique props addresses and ids'), v.check<PropsData, string>(bodiesAdmitted, 'touchable bodies have unique ids and each names its own panel, which no static collider claims'));
|
|
44
80
|
/** Validated data for the props renderer; no callbacks, URLs or generator code enter this section. */
|
|
45
81
|
export type ShardProps = v.InferOutput<typeof PropsSchema>;
|
|
46
82
|
/** Check every render binding against ordinary admitted file, tile and library rows before allocating content. */
|
|
@@ -133,5 +169,23 @@ interface PropsDataFields {
|
|
|
133
169
|
model: string;
|
|
134
170
|
colour: string;
|
|
135
171
|
})[];
|
|
172
|
+
bodies?: PropsBody[];
|
|
173
|
+
}
|
|
174
|
+
/** SS9a: a point, or a cuboid's half extents, in metres. */
|
|
175
|
+
interface PropsBodyVector { x: number; y: number; z: number }
|
|
176
|
+
/** SS9a: one touchable panel's body. */
|
|
177
|
+
interface PropsBody {
|
|
178
|
+
id: string;
|
|
179
|
+
panel: string;
|
|
180
|
+
at: PropsBodyVector;
|
|
181
|
+
yaw: number;
|
|
182
|
+
shape: { ball: number } | { cylinder: { radius: number; halfHeight: number } } | { cuboid: PropsBodyVector };
|
|
183
|
+
material: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt';
|
|
184
|
+
density?: number;
|
|
185
|
+
friction?: number;
|
|
186
|
+
restitution?: number;
|
|
187
|
+
linearDamping?: number;
|
|
188
|
+
angularDamping?: number;
|
|
189
|
+
keep?: boolean;
|
|
136
190
|
}
|
|
137
191
|
export type PropsData = { [Key in keyof PropsDataFields]: PropsDataFields[Key] };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readSpeciesPrograms } from './speciesPrograms.ts';
|
|
1
2
|
import type { StrikeDebrisPolicy } from './strike-debris.ts';
|
|
2
3
|
import { strikeDebrisCatalogueRules } from './strike-debris.ts';
|
|
3
4
|
import { harvestSpeciesRules } from './harvest-rows.ts';
|
|
@@ -210,7 +211,7 @@ export interface Shardfile {
|
|
|
210
211
|
function sceneOf(row: Readonly<{ scene: string }>): string { return row.scene; }
|
|
211
212
|
/** A hook's name. */
|
|
212
213
|
function idOf(row: Readonly<{ id: string }>): string { return row.id; }
|
|
213
|
-
export function shardfileRules(s: Shardfile): string[] {
|
|
214
|
+
export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unknown>): string[] {
|
|
214
215
|
const errors: string[] = [];
|
|
215
216
|
const pageOwner = hasDeclaredClientPage(s);
|
|
216
217
|
errors.push(...questNpcBindingRules(s.questNpcs ?? [], s.quests.flags, pageOwner || s.runtime?.binds?.includes('quests') === true));
|
|
@@ -309,7 +310,10 @@ export function shardfileRules(s: Shardfile): string[] {
|
|
|
309
310
|
if (moves.passes !== undefined) { debrisStrikes.push(moves.passes.left, moves.passes.right); }
|
|
310
311
|
}
|
|
311
312
|
}
|
|
312
|
-
|
|
313
|
+
const metadata = sections?.get('actors/species-programs');
|
|
314
|
+
const roster = metadata === undefined ? undefined : readSpeciesPrograms(metadata);
|
|
315
|
+
const targets = [...s.rows.species, ...roster?.page ?? [], ...roster?.native ?? [], ...roster?.program?.species ?? []];
|
|
316
|
+
errors.push(...strikeDebrisCatalogueRules({ strikes: debrisStrikes, species: targets }));
|
|
313
317
|
const harvestItems = new Set((s.items.catalogue ?? []).map((row: Readonly<{ id: string }>): string => row.id));
|
|
314
318
|
errors.push(...harvestSpeciesRules(s.rows.species, harvestItems));
|
|
315
319
|
if (s.migrations.some(step => step.equipmentSlots?.some(rename => !s.items.rows.some(row => row.kind === 'weapon' && row.slot === rename.to)))) errors.push('migration equipment slots resolve declared weapons');
|
|
@@ -382,7 +386,7 @@ export function shardfileRules(s: Shardfile): string[] {
|
|
|
382
386
|
}
|
|
383
387
|
/** Strict schema for the public SDK format; rejects unknown fields and invalid references.
|
|
384
388
|
* Keep the unknown-input/named-output boundary independent of the nested validator implementation. */
|
|
385
|
-
|
|
389
|
+
function shardfileSchema(sections?: ReadonlyMap<string, unknown>): v.GenericSchema<unknown, Shardfile> { return v.pipe(v.unknown(), v.rawCheck(({ dataset, addIssue }) => {
|
|
386
390
|
const input = dataset.value;
|
|
387
391
|
try { preflightShardfile(input); } catch (error) {
|
|
388
392
|
const nonData = error instanceof Error && /(?:JSON data|accessors)/u.test(error.message);
|
|
@@ -397,9 +401,14 @@ export const ShardfileSchema: v.GenericSchema<unknown, Shardfile> = v.pipe(v.unk
|
|
|
397
401
|
}
|
|
398
402
|
}), rawSchema,
|
|
399
403
|
v.rawCheck(({ dataset, addIssue }) => { if (dataset.typed) { try { preflightAssetGraph(dataset.value); } catch (error) { addIssue({ message: error instanceof Error ? error.message : 'shardfile asset graph admission' }); } } }),
|
|
400
|
-
v.check((s) => entrywayRules(s).length === 0, 'illegal shard: entryway openings must meet road height y=0'), v.check((s) => shardfileRules(s).length === 0, 'shardfile semantic rules'));
|
|
401
|
-
|
|
402
|
-
|
|
404
|
+
v.check((s) => entrywayRules(s).length === 0, 'illegal shard: entryway openings must meet road height y=0'), v.check((s) => shardfileRules(s, sections).length === 0, 'shardfile semantic rules')); }
|
|
405
|
+
export const ShardfileSchema: v.GenericSchema<unknown, Shardfile> = shardfileSchema();
|
|
406
|
+
/** Parse JSON through every shard rule. Optional section payloads extend item target
|
|
407
|
+
* references only through the defining species-program contract, never an id allowlist.
|
|
408
|
+
* Product readers must verify section inventories, hashes and sizes before calling. */
|
|
409
|
+
function parseShardfile(input: unknown, sections?: ReadonlyMap<string, unknown>): Shardfile {
|
|
410
|
+
return v.parse(sections === undefined ? ShardfileSchema : shardfileSchema(sections), input);
|
|
411
|
+
}
|
|
403
412
|
/** Admit one owned or cached declaration field with its defining schema.
|
|
404
413
|
* The assembled declaration still crosses parseShardfile's cross-field rules. */
|
|
405
414
|
function parseShardfileField<Key extends keyof Shardfile>(field: Key, input: unknown): Shardfile[Key] {
|
|
@@ -31,7 +31,7 @@ function admitHead(
|
|
|
31
31
|
payloads: ReadonlyMap<string, unknown>,
|
|
32
32
|
): Shardfile {
|
|
33
33
|
const shard = withIssueCode('shard-schema', (): Shardfile =>
|
|
34
|
-
parseShardfile(assembleOutputShardfile(index, payloads)),
|
|
34
|
+
parseShardfile(assembleOutputShardfile(index, payloads), payloads),
|
|
35
35
|
)
|
|
36
36
|
withIssueCode('declared-costs', (): void => {
|
|
37
37
|
preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
|
|
@@ -55,7 +55,7 @@ function admitBeforeAssets(
|
|
|
55
55
|
const head = admitHead(index, payloads)
|
|
56
56
|
return {
|
|
57
57
|
admission: withIssueCode('asset-admission', (): AssetAdmission =>
|
|
58
|
-
assetAdmission(head, offlineMemoryAdmission('warn'), scripts),
|
|
58
|
+
assetAdmission(head, offlineMemoryAdmission('warn'), scripts, payloads),
|
|
59
59
|
),
|
|
60
60
|
refusal: undefined,
|
|
61
61
|
}
|
|
@@ -114,11 +114,11 @@ export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refu
|
|
|
114
114
|
|
|
115
115
|
/** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
|
|
116
116
|
export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
|
|
117
|
-
policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = []): Shardfile {
|
|
118
|
-
const source = coded('shard-schema', (): Shardfile => parseShardfile(input));
|
|
117
|
+
policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
|
|
118
|
+
const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
|
|
119
119
|
coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
|
|
120
120
|
coded('performance-targets', (): void => { assertShardfileTargets(source, policy); });
|
|
121
|
-
return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts));
|
|
121
|
+
return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts, sections));
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/** Refuse world target rows that name items or quests the shardfile does not declare. */
|
|
@@ -229,7 +229,7 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
|
|
|
229
229
|
coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
|
|
230
230
|
}
|
|
231
231
|
for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
|
|
232
|
-
const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts);
|
|
232
|
+
const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, payloads);
|
|
233
233
|
checkWorldTargets(shard, payloads.get('world/targets'));
|
|
234
234
|
if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
|
|
235
235
|
return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
|