@wildshard/shard-format 0.71.0 → 0.72.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 +1 -1
- package/src/format/cook-data.ts +19 -1
- package/src/format/empty-shardfile.ts +2 -2
- package/src/format/json-schema.ts +12 -6
- package/src/format/outputIndex.ts +11 -7
- package/src/format/preparation-checks.ts +12 -1
- package/src/format/preparation-spec.ts +24 -0
- package/src/format/shardfile-stream-assets.ts +11 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.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": {
|
package/src/format/cook-data.ts
CHANGED
|
@@ -163,5 +163,23 @@ function readCookData(input: unknown): CookData {
|
|
|
163
163
|
return data
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/** SHARD-COMPAT SP1b1a: `cook.json`'s version alone, read without its rows, so a reader can name a newer spec
|
|
167
|
+
* (`unreadPreparationSpec`) before `readCookData` refuses it. `undefined` when it names no integer version. */
|
|
168
|
+
function cookDataSpec(input: unknown): number | undefined {
|
|
169
|
+
if (typeof input !== 'object' || input === null) {
|
|
170
|
+
return undefined
|
|
171
|
+
}
|
|
172
|
+
const version: unknown = (input as { version?: unknown }).version
|
|
173
|
+
return typeof version === 'number' && Number.isInteger(version)
|
|
174
|
+
? version
|
|
175
|
+
: undefined
|
|
176
|
+
}
|
|
177
|
+
|
|
166
178
|
export type { CookData, CookMount }
|
|
167
|
-
export {
|
|
179
|
+
export {
|
|
180
|
+
COOK_DATA_PATH,
|
|
181
|
+
CookDataSchema,
|
|
182
|
+
cookDataSpec,
|
|
183
|
+
cookMountPath,
|
|
184
|
+
readCookData,
|
|
185
|
+
}
|
|
@@ -15,7 +15,7 @@ function widened(
|
|
|
15
15
|
return { edge: row.edge, at: row.at, width: ENTRY_WIDTH }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/** A valid empty world; add baked content before shipping a playable shard. The identity takes `saveRevision`, or
|
|
18
|
+
/** A valid empty world, with no `requires.sdk` (SHARD-COMPAT CP8: a copy of the format version, deprecated); add baked content before shipping a playable shard. The identity takes `saveRevision`, or
|
|
19
19
|
* the spelling up to format 0.1.0.3, `revision` (FP26); the file comes back with `saveRevision`. */
|
|
20
20
|
function emptyShardfile(identity: Readonly<ShardIdentityInput>): Shardfile {
|
|
21
21
|
const { edgeSamples, edgeGrey, edgeHeight, requires, entryways, ...rest } =
|
|
@@ -33,7 +33,7 @@ function emptyShardfile(identity: Readonly<ShardIdentityInput>): Shardfile {
|
|
|
33
33
|
...rest,
|
|
34
34
|
version: SHARDFILE_VERSION,
|
|
35
35
|
identity,
|
|
36
|
-
requires
|
|
36
|
+
requires,
|
|
37
37
|
entryways: entryways.map(
|
|
38
38
|
(row: Readonly<{ edge: string; at: readonly number[] }>): object =>
|
|
39
39
|
widened(row),
|
|
@@ -1237,17 +1237,23 @@ export function namedJsonSchema(
|
|
|
1237
1237
|
return result
|
|
1238
1238
|
}
|
|
1239
1239
|
|
|
1240
|
-
/**
|
|
1241
|
-
*
|
|
1242
|
-
export function
|
|
1243
|
-
name: string,
|
|
1244
|
-
): Readonly<Record<string, unknown>> {
|
|
1240
|
+
/** The defining Valibot root a named format contract resolves to (`terrain.Terrain`), for author tools
|
|
1241
|
+
* that compose rows from named roots (the SDK's `NamedJsonComposition`, FORMAT-PRUNE FP9c). */
|
|
1242
|
+
export function namedFormatSchema(name: string): GenericSchema {
|
|
1245
1243
|
if (!Object.hasOwn(wireRoots, name))
|
|
1246
1244
|
throw new Error(`Unknown named format contract: ${name}`)
|
|
1247
1245
|
const schema = wireRoots[name]
|
|
1248
1246
|
if (schema === undefined)
|
|
1249
1247
|
throw new Error(`Missing named format contract: ${name}`)
|
|
1250
|
-
return
|
|
1248
|
+
return schema
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
/** Project one registered consumer contract to its exact named draft-07 document.
|
|
1252
|
+
* Author tools name the contract without borrowing the format's Valibot object. */
|
|
1253
|
+
export function namedFormatJsonSchema(
|
|
1254
|
+
name: string,
|
|
1255
|
+
): Readonly<Record<string, unknown>> {
|
|
1256
|
+
return namedJsonSchema(namedFormatSchema(name))
|
|
1251
1257
|
}
|
|
1252
1258
|
|
|
1253
1259
|
/** Build-only provenance catalogue from the defining format objects, independently checked by the product freeze. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { platformFileFamily } from './platformFileFamilies.ts';
|
|
2
2
|
import { MAX_COOK_BYTES } from './cook-preparation.ts';
|
|
3
|
-
import {
|
|
3
|
+
import { LEGACY_PREPARATION_SPEC, MAX_PREPARATION_SPEC, preparationSpecOf, unreadPreparationSpec } from './preparation-spec.ts';
|
|
4
4
|
import type { Ktx2DeviceCosts } from './ktx2Cost.ts';
|
|
5
5
|
import { AdmissionLateSchema, lateLibraryRootsValid, type AdmissionLate } from './admissionLate.ts';
|
|
6
6
|
import { AdmissionServerSchema, serverFilesExclusive, type AdmissionServer } from './admissionServer.ts';
|
|
@@ -20,7 +20,6 @@ import { ShardHashSchema, ShardNaturalSchema, IdentitySchema, RequiresSchema, Fi
|
|
|
20
20
|
import { LEGACY_LAYOUT, writesPreparationMarker, writesSaveRevision } from './version.ts';
|
|
21
21
|
import { IndexFormatVersionSchema, LegacyIndexVersionSchema } from './index-format-version.ts';
|
|
22
22
|
import type { IndexFormatVersion, LegacyIndexVersion } from './version.ts';
|
|
23
|
-
import type { PreparationSpec } from './preparation-spec.ts';
|
|
24
23
|
import { isJsonData, isJsonDataWithFileSchemas } from './json.ts';
|
|
25
24
|
import { clientOwnershipRules } from './clientOwnership.ts';
|
|
26
25
|
import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts';
|
|
@@ -40,6 +39,8 @@ const fileSchema = v.strictObject({ ...costs, path, kind: v.picklist(['glb', 'kt
|
|
|
40
39
|
/** `files` and `lines` are always empty: the 0.1.0.2 envelope drops them (FORMAT-PRUNE FP4), the legacy one still carries them. */
|
|
41
40
|
const runtimeFiles = v.exactOptional(v.pipe(v.array(v.strictObject({ ...measuredFile, lines: ShardNaturalSchema })), v.maxLength(0)));
|
|
42
41
|
const runtime = v.strictObject({ ...v.omit(ClientPlanRuntimeSchema.pipe[0], ['spawns']).entries, trust: v.exactOptional(v.unknown()), files: runtimeFiles, lines: v.exactOptional(v.literal(0)) });
|
|
42
|
+
/** SP1b1a: a spec this package reads, or a newer one up to `MAX_PREPARATION_SPEC`, kept unread. */
|
|
43
|
+
const PreparationSpecNumberSchema = v.pipe(v.number(), v.integer(), v.minValue(LEGACY_PREPARATION_SPEC), v.maxValue(MAX_PREPARATION_SPEC));
|
|
43
44
|
/** Format 2 inventories every emitted byte except its index and validation receipt. */
|
|
44
45
|
export const OutputIndexSchema: v.GenericSchema<OutputIndexRowsInput, OutputIndexRows> & { readonly entries: { readonly [Key in keyof OutputIndexRows]-?: v.GenericSchema<OutputIndexRowsInput[Key], OutputIndexRows[Key]> } } = v.strictObject({
|
|
45
46
|
format: v.literal('wildshard.shardfile'),
|
|
@@ -49,8 +50,9 @@ export const OutputIndexSchema: v.GenericSchema<OutputIndexRowsInput, OutputInde
|
|
|
49
50
|
/** The legacy preparation marker (`'0.2'` built, `'0.3'` prepared) up to format 0.1.0.2; 0.1.0.3 drops it (PR4). */
|
|
50
51
|
sdk: v.exactOptional(v.picklist(['0.2', '0.3'])),
|
|
51
52
|
/** SHARD-COMPAT PR4 (J487): from format 0.1.0.3, the preparation spec version a prepared file was made to, owned by
|
|
52
|
-
* this package (`cook.json`'s `version`); absent on an unprepared file. It names no engine release.
|
|
53
|
-
|
|
53
|
+
* this package (`cook.json`'s `version`); absent on an unprepared file. It names no engine release. SP1b1a: a spec above
|
|
54
|
+
* the ones this package reads parses too, kept and unread (`unreadPreparationSpec`). */
|
|
55
|
+
preparation: v.exactOptional(PreparationSpecNumberSchema),
|
|
54
56
|
identity: IdentitySchema, build: v.strictObject({ sourceHash: ShardHashSchema, validator: v.pipe(v.string(), v.minLength(1), v.maxLength(160)) }), requires: RequiresSchema,
|
|
55
57
|
admission: v.strictObject({ budgets: ShardfileFieldSchemas.budgets, serverBudget: ShardfileFieldSchemas.serverBudget, authorCaps: ShardfileFieldSchemas.authorCaps, critical: ShardfileFieldSchemas.critical, library: ShardfileFieldSchemas.library, late: v.exactOptional(AdmissionLateSchema), server: v.exactOptional(AdmissionServerSchema), audioWaiver: v.exactOptional(AudioWaiverSchema) }),
|
|
56
58
|
sections: v.pipe(v.array(section), v.maxLength(256)), schemas: emptySchemas,
|
|
@@ -134,7 +136,7 @@ function parseOutputIndexRows(input: unknown): OutputIndex {
|
|
|
134
136
|
const index = v.parse(OutputIndexSchema, input);
|
|
135
137
|
checkIndexEnvelope(index);
|
|
136
138
|
checkSaveRevisionSpelling(input, index);
|
|
137
|
-
const prepared = preparationSpecOf(index) !== undefined;
|
|
139
|
+
const prepared = preparationSpecOf(index) !== undefined || unreadPreparationSpec(index) !== undefined;
|
|
138
140
|
if (prepared && index.cook === undefined) { throw new Error(`Missing cook preparation: run wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`); }
|
|
139
141
|
if (prepared && index.cook !== undefined && index.cook.bytes > MAX_COOK_BYTES) { throw new Error('Cook preparation exceeds byte cap'); }
|
|
140
142
|
const paths = new Set(['shard.json', 'validation.json']), names = new Set<string>();
|
|
@@ -232,7 +234,8 @@ interface OutputIndexRowsInputFields {
|
|
|
232
234
|
format: "wildshard.shardfile";
|
|
233
235
|
formatVersion: typeof LEGACY_LAYOUT | IndexFormatVersion;
|
|
234
236
|
sdk?: "0.2" | "0.3";
|
|
235
|
-
|
|
237
|
+
/** A spec this package reads (3, 4), or a newer one kept unread (SP1b1a). */
|
|
238
|
+
preparation?: number;
|
|
236
239
|
version?: LegacyIndexVersion;
|
|
237
240
|
identity: ShardIdentityInput;
|
|
238
241
|
build: {
|
|
@@ -331,7 +334,8 @@ interface OutputIndexRowsFields {
|
|
|
331
334
|
format: "wildshard.shardfile";
|
|
332
335
|
formatVersion: typeof LEGACY_LAYOUT | IndexFormatVersion;
|
|
333
336
|
sdk?: "0.2" | "0.3";
|
|
334
|
-
|
|
337
|
+
/** A spec this package reads (3, 4), or a newer one kept unread (SP1b1a). */
|
|
338
|
+
preparation?: number;
|
|
335
339
|
version?: LegacyIndexVersion;
|
|
336
340
|
identity: ShardIdentity;
|
|
337
341
|
build: {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/** The checks `requireCookPreparation` runs on a prepared file (SHARD-COMPAT PR4 and PR5, J487): the preparation
|
|
2
2
|
* marker against `cook.json`'s spec, the fence and the programs mount. */
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isPreparationSpec,
|
|
5
|
+
preparationSpecOf,
|
|
6
|
+
unreadPreparationLine,
|
|
7
|
+
unreadPreparationSpec,
|
|
8
|
+
} from './preparation-spec.ts'
|
|
4
9
|
import { validationSourceBytes } from './validationReceipt.ts'
|
|
5
10
|
|
|
6
11
|
import type { AnyPrograms } from './cook-preparation.ts'
|
|
@@ -81,6 +86,12 @@ function preparationMarked(
|
|
|
81
86
|
version: number | undefined,
|
|
82
87
|
fix: string,
|
|
83
88
|
): boolean {
|
|
89
|
+
const unread = unreadPreparationSpec(index)
|
|
90
|
+
if (unread !== undefined) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`shard.json names a newer preparation (${unreadPreparationLine(unread)}): update this reader or run ${fix}`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
84
95
|
const spec = preparationSpecOf(index)
|
|
85
96
|
const prepared = isPreparationSpec(version)
|
|
86
97
|
const refusal =
|
|
@@ -13,6 +13,9 @@ const PREPARATION_SPECS: readonly [
|
|
|
13
13
|
typeof PREPARATION_SPEC,
|
|
14
14
|
] = [LEGACY_PREPARATION_SPEC, PREPARATION_SPEC] as const
|
|
15
15
|
type PreparationSpec = (typeof PREPARATION_SPECS)[number]
|
|
16
|
+
/** SHARD-COMPAT SP1b1a: the highest spec a `shard.json` may name. A spec above `PREPARATION_SPEC` is a newer package's:
|
|
17
|
+
* this reader keeps its number and reads none of its lists (`unreadPreparationSpec`). */
|
|
18
|
+
const MAX_PREPARATION_SPEC = 255
|
|
16
19
|
/** The legacy `sdk` marker's prepared value, which always meant spec 3. */
|
|
17
20
|
const PREPARED_SDK = '0.3'
|
|
18
21
|
|
|
@@ -34,8 +37,29 @@ function preparationSpecOf(
|
|
|
34
37
|
return index.sdk === PREPARED_SDK ? LEGACY_PREPARATION_SPEC : undefined
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
/** SP1b1a: the spec a `shard.json` names above every spec this package reads, or `undefined`. A cook names such a file
|
|
41
|
+
* `stale preparation` with both numbers (`unreadPreparationLine`) instead of refusing its index. */
|
|
42
|
+
function unreadPreparationSpec(
|
|
43
|
+
index: Readonly<{ preparation?: unknown }>,
|
|
44
|
+
): number | undefined {
|
|
45
|
+
const spec = index.preparation
|
|
46
|
+
return typeof spec === 'number' &&
|
|
47
|
+
Number.isInteger(spec) &&
|
|
48
|
+
spec > PREPARATION_SPEC &&
|
|
49
|
+
spec <= MAX_PREPARATION_SPEC
|
|
50
|
+
? spec
|
|
51
|
+
: undefined
|
|
52
|
+
}
|
|
53
|
+
/** SP1b1a: `spec 5, reads 3 and 4`: what a file names beside what this package reads. */
|
|
54
|
+
function unreadPreparationLine(spec: number): string {
|
|
55
|
+
return `spec ${String(spec)}, reads ${PREPARATION_SPECS.join(' and ')}`
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
export {
|
|
38
59
|
LEGACY_PREPARATION_SPEC,
|
|
60
|
+
MAX_PREPARATION_SPEC,
|
|
61
|
+
unreadPreparationLine,
|
|
62
|
+
unreadPreparationSpec,
|
|
39
63
|
PREPARATION_SPEC,
|
|
40
64
|
PREPARATION_SPECS,
|
|
41
65
|
PREPARED_SDK,
|
|
@@ -135,6 +135,12 @@ function namedKeys(
|
|
|
135
135
|
)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/** A JSON's listed dependencies are held for the checks after the files (a skin file's GLB, its variant and phone
|
|
139
|
+
* tables), but not its textures (`ktx2`, OF27b): no later check reads a texture's bytes (`validateSkinAssets` reads the
|
|
140
|
+
* JSON and the GLB, and each texture's own costs were checked as it streamed, by `admitFileBytes`). Holding them put
|
|
141
|
+
* Nalati r7's declared skin looks (OF30: 18 textures, 15.7 MB) over `PLACED_HOLD_CAP`. */
|
|
142
|
+
const UNHELD_DEPENDENCY_KIND = 'ktx2'
|
|
143
|
+
|
|
138
144
|
/** The placed keys, and the listed dependencies of the JSON among them (a skin file names its GLB; Codex review). */
|
|
139
145
|
function placedKeys(
|
|
140
146
|
shard: Readonly<AssetAdmission['shard']>,
|
|
@@ -155,7 +161,10 @@ function placedKeys(
|
|
|
155
161
|
const row = rows.get(key)
|
|
156
162
|
if (row?.kind === 'json') {
|
|
157
163
|
for (const dependency of row.dependencies) {
|
|
158
|
-
for (const found of hashKeys(dependency, paths)
|
|
164
|
+
for (const found of hashKeys(dependency, paths).filter(
|
|
165
|
+
(held: string): boolean =>
|
|
166
|
+
rows.get(held)?.kind !== UNHELD_DEPENDENCY_KIND,
|
|
167
|
+
)) {
|
|
159
168
|
keys.add(found)
|
|
160
169
|
}
|
|
161
170
|
}
|
|
@@ -508,4 +517,4 @@ async function assetPasses(base: AssetPassInput): Promise<AssetPasses> {
|
|
|
508
517
|
}
|
|
509
518
|
|
|
510
519
|
export type { AssetPassInput, AssetPasses, StoredSource }
|
|
511
|
-
export { assetPasses }
|
|
520
|
+
export { assetPasses, placedPaths }
|