@wildshard/shard-format 0.71.0 → 0.73.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.71.0",
3
+ "version": "0.73.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": {
@@ -402,6 +402,7 @@
402
402
  "./ui": "./src/format/ui.ts",
403
403
  "./uiStrings": "./src/format/uiStrings.ts",
404
404
  "./uniformRows": "./src/format/uniformRows.ts",
405
+ "./uploadCaps": "./src/format/upload-caps.ts",
405
406
  "./uploadWire": "./src/format/upload-wire.ts",
406
407
  "./validationReceipt": "./src/format/validationReceipt.ts",
407
408
  "./version": "./src/format/version.ts",
@@ -11,6 +11,8 @@ import {
11
11
  string,
12
12
  } from 'valibot'
13
13
 
14
+ import { MAX_SHARDFILE_BYTES } from './upload-caps.ts'
15
+
14
16
  import type { GenericSchema } from 'valibot'
15
17
 
16
18
  // AUDIO AU5: a dated waiver for a shard over the audio budget's red line. It
@@ -35,7 +37,6 @@ const NONE = 0
35
37
  const ONE_CHAR = 1
36
38
  const REASON_LIMIT = 240
37
39
  const SLUG_LIMIT = 64
38
- const MAX_WAIVER_BYTES = 450_000_000
39
40
 
40
41
  const AudioWaiverSchema: GenericSchema<AudioWaiver, AudioWaiver> = strictObject(
41
42
  {
@@ -45,7 +46,7 @@ const AudioWaiverSchema: GenericSchema<AudioWaiver, AudioWaiver> = strictObject(
45
46
  number(),
46
47
  safeInteger(),
47
48
  minValue(NONE),
48
- maxValue(MAX_WAIVER_BYTES),
49
+ maxValue(MAX_SHARDFILE_BYTES),
49
50
  ),
50
51
  reason: pipe(string(), minLength(ONE_CHAR), maxLength(REASON_LIMIT)),
51
52
  },
@@ -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 { COOK_DATA_PATH, CookDataSchema, cookMountPath, readCookData }
179
+ export {
180
+ COOK_DATA_PATH,
181
+ CookDataSchema,
182
+ cookDataSpec,
183
+ cookMountPath,
184
+ readCookData,
185
+ }
@@ -3,6 +3,7 @@
3
3
  * both validators warn on it and the corpus counts its kept users (`shard-format corpus`). A path with a migration is
4
4
  * mended by the chain; one without is deleted once no kept file uses it. */
5
5
  import { COOK_DEPRECATIONS } from './cook-deprecations.ts'
6
+ import { MANIFEST_MOVED_DEPRECATIONS } from './manifest-deprecations.ts'
6
7
  import { SAVE_REVISION_DEPRECATION } from './save-revision.ts'
7
8
  import { SCHEMA_SOURCE_DEPRECATION } from './schema-source.ts'
8
9
  import {
@@ -155,6 +156,7 @@ const RULES: readonly DeprecationRule[] = [
155
156
  'gridShardfile',
156
157
  ) !== undefined,
157
158
  },
159
+ ...MANIFEST_MOVED_DEPRECATIONS,
158
160
  {
159
161
  id: 'runtime.trust',
160
162
  path: 'shard.json runtime.trust',
@@ -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: { sdk: SHARDFILE_VERSION, ...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
- /** Project one registered consumer contract to its exact named draft-07 document.
1241
- * Author tools name the contract without borrowing the format's Valibot object. */
1242
- export function namedFormatJsonSchema(
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 namedJsonSchema(schema)
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. */
@@ -0,0 +1,57 @@
1
+ /** ONE-FORMAT OF9b5 under J486: the level manifest's moved words. SDK 0.4.25 builds write none of them (OF9b3b moved
2
+ * the page-start words to their sections, OF9b4 the herd fields to declared rows), but every product built before it
3
+ * still carries some in `ui/level`. FE7 counts each one's kept users; OF9b5a deletes the field from
4
+ * `ManifestMetadataSchema` at zero users. No data migration exists: the start words have a lift at the door
5
+ * (`level-start.ts`), and the herd fields became declared rows in the build, which a copy of the file can't redo. */
6
+
7
+ /** The registry's row shape (`deprecations.ts`). */
8
+ interface ManifestDeprecation {
9
+ readonly id: string
10
+ readonly path: string
11
+ readonly since: string
12
+ readonly replacement: string
13
+ readonly migration: undefined
14
+ readonly uses: (
15
+ shard: Readonly<{ sections: ReadonlyMap<string, unknown> }>,
16
+ ) => boolean
17
+ }
18
+
19
+ /** Each moved word and where it lives now. */
20
+ const MOVED: readonly (readonly [string, string])[] = [
21
+ ['spawn', 'world/spawn (OF9b3)'],
22
+ ['loadout', "combat/items' loadout.level (OF9b3)"],
23
+ ['audio', "audio/audio's level (OF9b3)"],
24
+ ['weapon', 'nothing: combat/items arms the player (OF9b3)'],
25
+ ['species', 'declared species rows, actors/species (OF9b4)'],
26
+ ['spawns', 'declared spawn rows (OF9b4)'],
27
+ ['faunaTuning', "declared species rows' tuning (OF9b4)"],
28
+ ]
29
+
30
+ function manifestOf(sections: ReadonlyMap<string, unknown>): unknown {
31
+ const level = sections.get('ui/level')
32
+ return typeof level === 'object' && level !== null && !Array.isArray(level)
33
+ ? Reflect.get(level, 'manifest')
34
+ : undefined
35
+ }
36
+
37
+ const MANIFEST_MOVED_DEPRECATIONS: readonly ManifestDeprecation[] = MOVED.map(
38
+ ([word, replacement]: readonly [string, string]): ManifestDeprecation => ({
39
+ id: `manifest.${word}`,
40
+ path: `sections/ui/level manifest.${word} (ONE-FORMAT OF9b5)`,
41
+ since: '0.1.0.4',
42
+ replacement,
43
+ migration: undefined,
44
+ uses: (
45
+ shard: Readonly<{ sections: ReadonlyMap<string, unknown> }>,
46
+ ): boolean => {
47
+ const manifest = manifestOf(shard.sections)
48
+ return (
49
+ typeof manifest === 'object' &&
50
+ manifest !== null &&
51
+ Object.hasOwn(manifest, word)
52
+ )
53
+ },
54
+ }),
55
+ )
56
+
57
+ export { MANIFEST_MOVED_DEPRECATIONS }
@@ -1,6 +1,6 @@
1
1
  import { platformFileFamily } from './platformFileFamilies.ts';
2
2
  import { MAX_COOK_BYTES } from './cook-preparation.ts';
3
- import { PREPARATION_SPECS, preparationSpecOf } from './preparation-spec.ts';
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
- preparation: v.exactOptional(v.picklist(PREPARATION_SPECS)),
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
- preparation?: PreparationSpec;
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
- preparation?: PreparationSpec;
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 { isPreparationSpec, preparationSpecOf } from './preparation-spec.ts'
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 }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The upload caps every host shares (EG-8, D31, J137). api-server refuses a
3
+ * bigger upload and the cook refuses a bigger read; both import this one
4
+ * number, so they cannot drift apart again (BUG-3: the cook refused Pine's
5
+ * 300 MB head while the API took 450 MB).
6
+ */
7
+
8
+ /**
9
+ * The largest shardfile tarball, stored or once decoded. The API commit
10
+ * streams through its `/tmp` (500 MB), which bounds it; Pine Hollow is the
11
+ * largest at 372 MB.
12
+ */
13
+ export const MAX_SHARDFILE_BYTES = 450_000_000