@wildshard/shard-format 0.4.9 → 0.5.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/corpus/brasscap-mesa/sections/look/look.json +1 -1
- package/corpus/brasscap-mesa/shard.json +1 -1
- package/corpus/brasscap-mesa/validation.json +1 -1
- package/package.json +16 -15
- package/src/cli/main.ts +2 -2
- package/src/cli/pack.ts +3 -3
- package/src/cli/validate.ts +33 -27
- package/src/format/assembly-hosts.ts +77 -0
- package/src/format/assetAdmission.ts +5 -5
- package/src/format/cook-preparation.ts +2 -2
- package/src/format/deviceMemoryCost.ts +2 -2
- package/src/format/{directorProduct.ts → directorDocument.ts} +3 -3
- package/src/format/entryClearance.ts +1 -1
- package/src/format/glbCost.ts +1 -1
- package/src/format/immutable.ts +1 -1
- package/src/format/issue-codes.ts +1 -1
- package/src/format/ktx2Cost.ts +1 -1
- package/src/format/look-light.ts +78 -0
- package/src/format/materials.ts +1 -1
- package/src/format/namedJsonContracts.ts +1 -1
- package/src/format/nearPlaceholderAssets.ts +1 -1
- package/src/format/outputDownload.ts +1 -1
- package/src/format/outputIndex.ts +1 -1
- package/src/format/platformFileFamilies.ts +3 -2
- package/src/format/receipt-cost.ts +3 -3
- package/src/format/registeredJson.ts +4 -4
- package/src/format/script-side-grandfather.ts +12 -13
- package/src/format/script-sides.ts +36 -38
- package/src/format/script-view-returns.ts +142 -0
- package/src/format/shardSchema.ts +7 -5
- package/src/format/{product-audio.ts → shardfile-audio.ts} +7 -7
- package/src/format/{product-stream-admit.ts → shardfile-stream-admit.ts} +11 -8
- package/src/format/{product-stream-assets.ts → shardfile-stream-assets.ts} +7 -7
- package/src/format/{product-stream-facts.ts → shardfile-stream-facts.ts} +3 -3
- package/src/format/{product-stream-node.ts → shardfile-stream-node.ts} +2 -2
- package/src/format/{product-stream-packs.ts → shardfile-stream-packs.ts} +1 -1
- package/src/format/{product-stream-rows.ts → shardfile-stream-rows.ts} +6 -6
- package/src/format/{product-stream.ts → shardfile-stream.ts} +25 -25
- package/src/format/{productValidation.ts → shardfileValidation.ts} +14 -14
- package/src/format/sourceResidency.ts +4 -4
- package/src/format/tar.ts +1 -1
- package/src/format/validationReceipt.ts +2 -2
- /package/src/format/{product.ts → shardfile-assets.ts} +0 -0
- /package/src/format/{product-reads.ts → shardfile-reads.ts} +0 -0
- /package/src/format/{product-stream-miss.ts → shardfile-stream-miss.ts} +0 -0
- /package/src/format/{product-stream-tar.ts → shardfile-stream-tar.ts} +0 -0
|
@@ -9,7 +9,7 @@ import { CELL_ABOVE, CELL_BELOW, CHUNK_HALF, CONTENT_CAPS } from './contentBound
|
|
|
9
9
|
import { jsonDataNodes } from './json.ts';
|
|
10
10
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
11
11
|
import { preflightShardfile } from './preflight.ts';
|
|
12
|
-
import { preflightAssetGraph } from './
|
|
12
|
+
import { preflightAssetGraph } from './shardfile-assets.ts';
|
|
13
13
|
import { SHARDFILE_VERSION } from './version.ts';
|
|
14
14
|
import { UiSchema, uiRules } from './ui.ts';
|
|
15
15
|
import { scriptBindingRules } from './scripts.ts';
|
|
@@ -53,8 +53,8 @@ import { MigrationsSchema, migrationRules } from './migrations.ts';
|
|
|
53
53
|
import { skinLookRules } from './skinAssets.ts';
|
|
54
54
|
import { MaterialsSchema, FamilyLooksSchema, MaterialCurvesSchema, TextureSamplersSchema, materialExists, materialTextureRefs, materialGraphRules, materialCurveRules, textureSamplerRules } from './materials.ts';
|
|
55
55
|
import { PostStackSchema, postStackRules } from './postStack.ts';
|
|
56
|
-
import { LookBloomSchema, LookLightSchema } from './look-light.ts';
|
|
57
|
-
import type { LookBloom, LookBloomInput, LookLight, LookLightInput } from './look-light.ts';
|
|
56
|
+
import { LookBloomSchema, LookLightSchema, LookToneSchema } from './look-light.ts';
|
|
57
|
+
import type { LookBloom, LookBloomInput, LookLight, LookLightInput, LookTone } from './look-light.ts';
|
|
58
58
|
|
|
59
59
|
const channel = v.pipe(finite, v.minValue(0), v.maxValue(1));
|
|
60
60
|
const colour = v.tuple([channel, channel, channel]);
|
|
@@ -62,7 +62,7 @@ const unsigned = v.pipe(finite, v.minValue(0));
|
|
|
62
62
|
const key: v.GenericSchema<DayKeyRowsInput, DayKeyRows> = v.strictObject({ time: channel, sky: v.strictObject({ zenith: colour, horizon: colour }), fog: v.strictObject({ colour, density: unsigned, near: v.optional(unsigned), far: v.optional(unsigned) }), sun: v.strictObject({ colour, intensity: unsigned }), ambient: v.strictObject({ sky: colour, ground: colour, intensity: unsigned }) });
|
|
63
63
|
const day: v.GenericSchema<DayRowsInput, DayRows> = v.strictObject({ minutes: v.pipe(finite, v.minValue(1), v.maxValue(1440)), start: channel, maxElevation: v.pipe(finite, v.minValue(0), v.maxValue(90)), azimuth: v.pipe(finite, v.minValue(-180), v.maxValue(180)) });
|
|
64
64
|
const lookBloom = v.exactOptional(LookBloomSchema);
|
|
65
|
-
const lookGrade = v.strictObject({ exposure: finite, saturation: v.pipe(finite, v.minValue(0)), contrast: v.pipe(finite, v.minValue(0)), lut: v.nullable(ref), bloom: lookBloom });
|
|
65
|
+
const lookGrade = v.strictObject({ exposure: finite, saturation: v.pipe(finite, v.minValue(0)), contrast: v.pipe(finite, v.minValue(0)), lut: v.nullable(ref), bloom: lookBloom, tone: v.exactOptional(LookToneSchema) });
|
|
66
66
|
/** A colour LUT file's exact wire size: 33³ RGBA8 (the engine's render/lut format). */
|
|
67
67
|
export const LOOK_LUT_BYTES: number = 33 ** 3 * 4;
|
|
68
68
|
const rawSchema: v.GenericSchema<ShardfileRowsInput, ShardfileRows> & { readonly entries: { readonly [Key in keyof ShardfileRows]-?: v.GenericSchema<ShardfileRowsInput[Key], ShardfileRows[Key]> } } = v.strictObject({
|
|
@@ -184,7 +184,7 @@ export interface Shardfile {
|
|
|
184
184
|
samplers?: v.InferOutput<typeof TextureSamplersSchema>;
|
|
185
185
|
post?: v.InferOutput<typeof PostStackSchema>;
|
|
186
186
|
light?: LookLight;
|
|
187
|
-
grade: { exposure: number; saturation: number; contrast: number; lut: string | null; bloom?: LookBloom };
|
|
187
|
+
grade: { exposure: number; saturation: number; contrast: number; lut: string | null; bloom?: LookBloom; tone?: LookTone };
|
|
188
188
|
clock: 'engine';
|
|
189
189
|
day?: v.InferOutput<typeof day> | undefined;
|
|
190
190
|
dayOverride: number | null;
|
|
@@ -397,6 +397,7 @@ interface ShardfileRowsInputFields {
|
|
|
397
397
|
contrast: v.InferInput<typeof finite>;
|
|
398
398
|
lut: (v.InferInput<typeof ref>) | null;
|
|
399
399
|
bloom?: LookBloomInput;
|
|
400
|
+
tone?: LookTone;
|
|
400
401
|
};
|
|
401
402
|
clock: 'engine';
|
|
402
403
|
day?: DayRowsInput | undefined;
|
|
@@ -471,6 +472,7 @@ interface ShardfileRowsFields {
|
|
|
471
472
|
contrast: v.InferOutput<typeof finite>;
|
|
472
473
|
lut: (v.InferOutput<typeof ref>) | null;
|
|
473
474
|
bloom?: LookBloom;
|
|
475
|
+
tone?: LookTone;
|
|
474
476
|
};
|
|
475
477
|
clock: 'engine';
|
|
476
478
|
day?: DayRows | undefined;
|
|
@@ -20,8 +20,8 @@ import type { Shardfile } from './shardSchema.ts'
|
|
|
20
20
|
// section's non-commons `recordings` blobs. Commons recordings are shared, so
|
|
21
21
|
// they are not the shard's own.
|
|
22
22
|
|
|
23
|
-
/** What `
|
|
24
|
-
interface
|
|
23
|
+
/** What `shardfileRecordings` reads from a validated product. */
|
|
24
|
+
interface ShardfileAudioInput {
|
|
25
25
|
readonly cook: CookData | undefined
|
|
26
26
|
readonly read: (path: string, maxBytes: number) => Uint8Array
|
|
27
27
|
readonly shard: Readonly<{
|
|
@@ -33,9 +33,9 @@ interface ProductAudioInput {
|
|
|
33
33
|
const COMMONS = 'commons:'
|
|
34
34
|
|
|
35
35
|
/** Every own recording in a validated product, measured from its bytes. */
|
|
36
|
-
function
|
|
36
|
+
function shardfileRecordings(
|
|
37
37
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's row types and a read port, only read
|
|
38
|
-
input: Readonly<
|
|
38
|
+
input: Readonly<ShardfileAudioInput>,
|
|
39
39
|
): RecordingMeasure[] {
|
|
40
40
|
const mounts = (input.cook?.mounts ?? [])
|
|
41
41
|
.filter((mount: Readonly<CookMount>): boolean =>
|
|
@@ -58,7 +58,7 @@ function productRecordings(
|
|
|
58
58
|
|
|
59
59
|
/** The product's audio against AU5's rules, its waiver read from `admission.audioWaiver`. A red report refuses only at
|
|
60
60
|
* upload (`assertAudioAdmission`); pack prints it. `today` decides whether the waiver is still in date. */
|
|
61
|
-
function
|
|
61
|
+
function shardfileAudioReport(
|
|
62
62
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's row types, only read
|
|
63
63
|
product: Readonly<{ index: OutputIndex; audio: readonly RecordingMeasure[] }>,
|
|
64
64
|
today: Readonly<Date>,
|
|
@@ -71,5 +71,5 @@ function productAudioReport(
|
|
|
71
71
|
})
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export type {
|
|
75
|
-
export {
|
|
74
|
+
export type { ShardfileAudioInput }
|
|
75
|
+
export { shardfileAudioReport, shardfileRecordings }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `
|
|
1
|
+
// `admitShardfileFolder`'s steps around `validateShardfileAssets` for the
|
|
2
2
|
// streaming validator (API-CLOUDFLARE AC6a): the schema, declared costs and
|
|
3
3
|
// targets before it; the world targets and the source hash after it.
|
|
4
4
|
|
|
@@ -10,18 +10,21 @@ import {
|
|
|
10
10
|
} from './assetAdmission.ts'
|
|
11
11
|
import { issueError, withIssueCode } from './issue-codes.ts'
|
|
12
12
|
import { assembleOutputShardfile } from './outputIndex.ts'
|
|
13
|
-
import { offlineMemoryAdmission } from './
|
|
14
|
-
import {
|
|
13
|
+
import { offlineMemoryAdmission } from './shardfile-assets.ts'
|
|
14
|
+
import {
|
|
15
|
+
assertShardfileTargets,
|
|
16
|
+
checkWorldTargets,
|
|
17
|
+
} from './shardfileValidation.ts'
|
|
15
18
|
import { parseShardfile } from './shardSchema.ts'
|
|
16
19
|
import { validationSourceBytes } from './validationReceipt.ts'
|
|
17
20
|
|
|
18
21
|
import type { AssetAdmission } from './assetAdmission.ts'
|
|
19
22
|
import type { OutputIndex } from './outputIndex.ts'
|
|
20
|
-
import type { AssetPasses } from './product-stream-assets.ts'
|
|
21
23
|
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
24
|
+
import type { AssetPasses } from './shardfile-stream-assets.ts'
|
|
22
25
|
import type { Shardfile } from './shardSchema.ts'
|
|
23
26
|
|
|
24
|
-
/** `
|
|
27
|
+
/** `admitShardfileFolder`'s steps before `validateShardfileAssets`: the schema, declared costs and targets. */
|
|
25
28
|
function admitHead(
|
|
26
29
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
27
30
|
index: OutputIndex,
|
|
@@ -34,13 +37,13 @@ function admitHead(
|
|
|
34
37
|
preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
|
|
35
38
|
})
|
|
36
39
|
withIssueCode('performance-targets', (): void => {
|
|
37
|
-
|
|
40
|
+
assertShardfileTargets(shard, 'warn')
|
|
38
41
|
})
|
|
39
42
|
return shard
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/** The shard's head and its asset admission's first steps, or the refusal they gave: thrown only after the packs, the
|
|
43
|
-
* cook and the inventory, as `
|
|
46
|
+
* cook and the inventory, as `validateShardfileFolder` orders them. */
|
|
44
47
|
function admitBeforeAssets(
|
|
45
48
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
46
49
|
index: OutputIndex,
|
|
@@ -88,7 +91,7 @@ function admitAssets(
|
|
|
88
91
|
})
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
/** `
|
|
94
|
+
/** `validateShardfileFolder`'s steps after the assets: the world targets and the source hash. */
|
|
92
95
|
function admitTail(
|
|
93
96
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
94
97
|
shard: Shardfile,
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
// Wasm stay from the first read. A later check that asks for any other file
|
|
11
11
|
// is refused, never answered from a guess (StreamMissError): the corpus and pin
|
|
12
12
|
// tests prove no check does. Packs the reads' groups need come with them
|
|
13
|
-
// (
|
|
13
|
+
// (shardfile-stream-packs.ts).
|
|
14
14
|
|
|
15
15
|
import { admitFileBytes } from './assetAdmission.ts'
|
|
16
16
|
import { issueError, withIssueCodeAsync } from './issue-codes.ts'
|
|
17
|
-
import { StreamMissError } from './
|
|
18
|
-
import { packGroups, packPass } from './
|
|
19
|
-
import { walkTar } from './
|
|
17
|
+
import { StreamMissError } from './shardfile-stream-miss.ts'
|
|
18
|
+
import { packGroups, packPass } from './shardfile-stream-packs.ts'
|
|
19
|
+
import { walkTar } from './shardfile-stream-tar.ts'
|
|
20
20
|
|
|
21
21
|
import type { AssetAdmission } from './assetAdmission.ts'
|
|
22
22
|
import type { OutputIndex } from './outputIndex.ts'
|
|
23
|
-
import type { PackPass, PackVerdicts } from './
|
|
24
|
-
import type { KeptMember } from './
|
|
25
|
-
import type { StreamHasher, StreamMember } from './
|
|
23
|
+
import type { PackPass, PackVerdicts } from './shardfile-stream-packs.ts'
|
|
24
|
+
import type { KeptMember } from './shardfile-stream-rows.ts'
|
|
25
|
+
import type { StreamHasher, StreamMember } from './shardfile-stream-tar.ts'
|
|
26
26
|
|
|
27
27
|
/** A stored object to read again: each call opens a fresh stream from its start. */
|
|
28
28
|
type StoredSource = () =>
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
import { parseNamedJson } from './json.ts'
|
|
9
9
|
import { ktx2DeviceCosts } from './ktx2Cost.ts'
|
|
10
10
|
import { validatePlatformFile } from './platformFileFamilies.ts'
|
|
11
|
-
import { assetCost } from './product.ts'
|
|
12
|
-
import { outputBlobExtension, outputBlobKind } from './productValidation.ts'
|
|
13
11
|
import {
|
|
14
12
|
registeredJsonContract,
|
|
15
13
|
validateRegisteredJson,
|
|
16
14
|
} from './registeredJson.ts'
|
|
15
|
+
import { assetCost } from './shardfile-assets.ts'
|
|
16
|
+
import { outputBlobExtension, outputBlobKind } from './shardfileValidation.ts'
|
|
17
17
|
import { validationSourceBytes } from './validationReceipt.ts'
|
|
18
18
|
|
|
19
19
|
import type { OutputFile } from './outputIndex.ts'
|
|
20
|
-
import type { AssetCost } from './product.ts'
|
|
21
20
|
import type { ScriptContract } from './scriptContract.ts'
|
|
21
|
+
import type { AssetCost } from './shardfile-assets.ts'
|
|
22
22
|
|
|
23
23
|
/** A computed value, or the message of the refusal computing it threw: thrown later, in the old validator's order. */
|
|
24
24
|
type Outcome<Value> =
|
|
@@ -9,8 +9,8 @@ import { Readable, pipeline } from 'node:stream'
|
|
|
9
9
|
// oxlint-disable-next-line import/no-nodejs-modules -- a Node and Workers host adapter
|
|
10
10
|
import { createBrotliDecompress } from 'node:zlib'
|
|
11
11
|
|
|
12
|
-
import type { StreamHasher } from './
|
|
13
|
-
import type { StreamValidationPorts } from './
|
|
12
|
+
import type { StreamHasher } from './shardfile-stream-tar.ts'
|
|
13
|
+
import type { StreamValidationPorts } from './shardfile-stream.ts'
|
|
14
14
|
|
|
15
15
|
function sha256(bytes: Readonly<Uint8Array>): string {
|
|
16
16
|
return createHash('sha256').update(bytes).digest('hex')
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { issueError } from './issue-codes.ts'
|
|
12
12
|
|
|
13
13
|
import type { OutputIndex } from './outputIndex.ts'
|
|
14
|
-
import type { StreamHasher } from './
|
|
14
|
+
import type { StreamHasher } from './shardfile-stream-tar.ts'
|
|
15
15
|
|
|
16
16
|
type Pack = NonNullable<OutputIndex['packs']>[number]
|
|
17
17
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// oxlint-disable import/max-dependencies -- the old validator's steps, each from its defining module
|
|
2
|
-
// `
|
|
2
|
+
// `validateShardfileFolder`'s inventory steps, replayed over what one
|
|
3
3
|
// streaming pass kept (API-CLOUDFLARE AC6a): each listed file's hash and
|
|
4
4
|
// size, the blobs' facts, server files, KTX2 device costs, the cook and its
|
|
5
5
|
// mounts, and no unlisted file. The order and the messages are the old ones.
|
|
@@ -10,16 +10,16 @@ import { cookMountPath, readCookData } from './cook-data.ts'
|
|
|
10
10
|
import { requireCookPreparation } from './cook-preparation.ts'
|
|
11
11
|
import { issueError, withIssueCode } from './issue-codes.ts'
|
|
12
12
|
import { validatePlatformFile } from './platformFileFamilies.ts'
|
|
13
|
-
import { mountSharesBlob } from './product-reads.ts'
|
|
14
|
-
import { inspectFacts, ktx2Text } from './product-stream-facts.ts'
|
|
15
|
-
import { outputBlobKind, readCanonicalJson } from './productValidation.ts'
|
|
16
13
|
import { decisionModuleContracts } from './scriptContract.ts'
|
|
14
|
+
import { mountSharesBlob } from './shardfile-reads.ts'
|
|
15
|
+
import { inspectFacts, ktx2Text } from './shardfile-stream-facts.ts'
|
|
16
|
+
import { outputBlobKind, readCanonicalJson } from './shardfileValidation.ts'
|
|
17
17
|
import { validationSourceBytes } from './validationReceipt.ts'
|
|
18
18
|
|
|
19
19
|
import type { OutputIndex } from './outputIndex.ts'
|
|
20
|
-
import type { FactsMember } from './product-stream-facts.ts'
|
|
21
|
-
import type { StreamMember } from './product-stream-tar.ts'
|
|
22
20
|
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
21
|
+
import type { FactsMember } from './shardfile-stream-facts.ts'
|
|
22
|
+
import type { StreamMember } from './shardfile-stream-tar.ts'
|
|
23
23
|
|
|
24
24
|
/** One tar member after the walk. */
|
|
25
25
|
type KeptMember = FactsMember & StreamMember
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
// oxlint-disable eslint/max-statements, import/max-dependencies -- the old validator's steps in its order
|
|
2
|
-
// API-CLOUDFLARE AC6a: `
|
|
2
|
+
// API-CLOUDFLARE AC6a: `validateShardfileFolder` over a stream, for a host
|
|
3
3
|
// with no disk and no synchronous reads (the API Worker: 128 MB, `node:zlib`,
|
|
4
4
|
// no WebAssembly compiled from bytes). The first read of the stored object
|
|
5
5
|
// takes its SHA-256, its decoding (Brotli, a host port), a strict ustar walk
|
|
6
6
|
// and every member's SHA-256 and size. Blobs are checked as they stream and
|
|
7
|
-
// only their facts kept (
|
|
7
|
+
// only their facts kept (shardfile-stream-facts.ts); JSON, Wasm and every file
|
|
8
8
|
// outside `blobs/`, `mounts/` and `packs/` are kept whole. Then the old
|
|
9
9
|
// validator's steps run in its order, so a refusal is the one it gives (its
|
|
10
10
|
// message may differ only for a blob whose declared kind contradicts its path).
|
|
11
11
|
//
|
|
12
12
|
// AC6a2: `validateShardfileAssets`' byte checks and the pack checks read
|
|
13
13
|
// assets by hash in any order (153 MB of blobs on the 327 MB pin), so they
|
|
14
|
-
// take a second read of the stored object (
|
|
15
|
-
// further read per group of left-out packs (
|
|
14
|
+
// take a second read of the stored object (shardfile-stream-assets.ts), and a
|
|
15
|
+
// further read per group of left-out packs (shardfile-stream-packs.ts). Hence
|
|
16
16
|
// `open`: a host passes a function that opens the stored object afresh.
|
|
17
17
|
|
|
18
18
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts'
|
|
19
19
|
import { assertSectionSides } from './feature-sides.ts'
|
|
20
20
|
import { issueError, withIssueCode } from './issue-codes.ts'
|
|
21
21
|
import { parseOutputIndex, validateOutputSection } from './outputIndex.ts'
|
|
22
|
+
import { assertScriptSides } from './script-sides.ts'
|
|
23
|
+
import { scriptAdmissionRows } from './scriptContract.ts'
|
|
24
|
+
import { prepareAssetDecoders } from './shardfile-assets.ts'
|
|
22
25
|
import {
|
|
23
26
|
admitAssets,
|
|
24
27
|
admitBeforeAssets,
|
|
25
28
|
admitTail,
|
|
26
|
-
} from './
|
|
27
|
-
import { assetPasses } from './
|
|
28
|
-
import { blobFacts } from './
|
|
29
|
+
} from './shardfile-stream-admit.ts'
|
|
30
|
+
import { assetPasses } from './shardfile-stream-assets.ts'
|
|
31
|
+
import { blobFacts } from './shardfile-stream-facts.ts'
|
|
29
32
|
import {
|
|
30
33
|
listedBytes,
|
|
31
34
|
replayBeforePacks,
|
|
32
35
|
replayPacksToInventory,
|
|
33
|
-
} from './
|
|
34
|
-
import { walkTar } from './
|
|
35
|
-
import {
|
|
36
|
-
import { readCanonicalJson } from './productValidation.ts'
|
|
37
|
-
import { assertScriptSides } from './script-sides.ts'
|
|
38
|
-
import { scriptAdmissionRows } from './scriptContract.ts'
|
|
36
|
+
} from './shardfile-stream-rows.ts'
|
|
37
|
+
import { walkTar } from './shardfile-stream-tar.ts'
|
|
38
|
+
import { readCanonicalJson } from './shardfileValidation.ts'
|
|
39
39
|
|
|
40
40
|
import type { OutputIndex } from './outputIndex.ts'
|
|
41
|
-
import type {
|
|
42
|
-
import type {
|
|
41
|
+
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
42
|
+
import type { StoredSource } from './shardfile-stream-assets.ts'
|
|
43
|
+
import type { KeptMember, Replay } from './shardfile-stream-rows.ts'
|
|
43
44
|
import type {
|
|
44
45
|
StreamHasher,
|
|
45
46
|
StreamMember,
|
|
46
47
|
WalkPorts,
|
|
47
|
-
} from './
|
|
48
|
-
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
48
|
+
} from './shardfile-stream-tar.ts'
|
|
49
49
|
import type { Shardfile } from './shardSchema.ts'
|
|
50
50
|
|
|
51
51
|
/** The host services a streaming validation needs. */
|
|
@@ -61,7 +61,7 @@ interface StreamValidationPorts {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** What one streaming validation found. */
|
|
64
|
-
interface
|
|
64
|
+
interface StreamedShardfile {
|
|
65
65
|
/** SHA-256 and byte length of the stored object, before decoding. */
|
|
66
66
|
readonly hash: string
|
|
67
67
|
readonly bytes: number
|
|
@@ -73,7 +73,7 @@ interface StreamedProduct {
|
|
|
73
73
|
readonly scripts: ScriptAdmissionRows
|
|
74
74
|
/** Admitted with a warning: grandfathered script side lines (`SCRIPT_SIDE_GRANDFATHER`, SERVER-PARITY SS11). */
|
|
75
75
|
readonly warnings: readonly string[]
|
|
76
|
-
/** True only when every check `
|
|
76
|
+
/** True only when every check `validateShardfileFolder` runs has run: always, since AC6a2. */
|
|
77
77
|
readonly complete: boolean
|
|
78
78
|
/** The checks still to run, by name, while `complete` is false: none, since AC6a2. */
|
|
79
79
|
readonly pending: readonly string[]
|
|
@@ -196,7 +196,7 @@ async function walkStored(
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
/** `shard.json`, read as `
|
|
199
|
+
/** `shard.json`, read as `validateShardfileFolder` reads it: bounded, canonical, then parsed. */
|
|
200
200
|
function readIndex(replay: Readonly<Replay>): OutputIndex {
|
|
201
201
|
const shardJson = replay.members.get('shard.json')
|
|
202
202
|
if (shardJson === undefined) {
|
|
@@ -218,7 +218,7 @@ function readSections(
|
|
|
218
218
|
replay: Readonly<Replay>,
|
|
219
219
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
220
220
|
index: OutputIndex,
|
|
221
|
-
): Pick<
|
|
221
|
+
): Pick<StreamedShardfile, 'sections' | 'warnings' | 'scripts'> {
|
|
222
222
|
const payloads = new Map<string, unknown>()
|
|
223
223
|
for (const entry of index.sections) {
|
|
224
224
|
withIssueCode('section-invalid', (): void => {
|
|
@@ -245,11 +245,11 @@ function readSections(
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
/** Stream-validate a stored shardfile object (see the file comment): `open` gives a fresh stream of it on each call.
|
|
248
|
-
* Rejects with the refusal `
|
|
248
|
+
* Rejects with the refusal `validateShardfileFolder` would give first. */
|
|
249
249
|
async function validateShardfileStream(
|
|
250
250
|
open: StoredSource,
|
|
251
251
|
ports: StreamValidationPorts,
|
|
252
|
-
): Promise<
|
|
252
|
+
): Promise<StreamedShardfile> {
|
|
253
253
|
// GLB costs need the meshopt decoder before any blob streams (Codex review: a cold start refused valid GLBs).
|
|
254
254
|
await prepareAssetDecoders()
|
|
255
255
|
const walked = await walkStored(await open(), ports)
|
|
@@ -292,6 +292,6 @@ async function validateShardfileStream(
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
export type { StoredSource } from './
|
|
296
|
-
export type { StreamValidationPorts,
|
|
295
|
+
export type { StoredSource } from './shardfile-stream-assets.ts'
|
|
296
|
+
export type { StreamValidationPorts, StreamedShardfile }
|
|
297
297
|
export { STREAM_BLOB_CAP, STREAM_KEPT_CAP, validateShardfileStream }
|
|
@@ -10,14 +10,14 @@ import { isTerrainTileData } from './terrainTileBytes.ts';
|
|
|
10
10
|
import { parseImageAsset } from './stillImage.ts';
|
|
11
11
|
import { parseWorldTargets, worldTargetRules } from './worldTargets.ts';
|
|
12
12
|
import { parseShardfile, type Shardfile } from './shardSchema.ts';
|
|
13
|
-
import { assetCost, offlineMemoryAdmission, performanceTargetIssues } from './
|
|
13
|
+
import { assetCost, offlineMemoryAdmission, performanceTargetIssues } from './shardfile-assets.ts';
|
|
14
14
|
import { preflightDeclaredCosts, validateShardfileAssets } from './assetAdmission.ts';
|
|
15
15
|
import { validationSourceBytes } from './validationReceipt.ts';
|
|
16
16
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
17
|
-
import { assetStore, checkPacks, mountSharesBlob } from './
|
|
17
|
+
import { assetStore, checkPacks, mountSharesBlob } from './shardfile-reads.ts';
|
|
18
18
|
import { assertSectionSides } from './feature-sides.ts';
|
|
19
19
|
import { assertScriptSides } from './script-sides.ts';
|
|
20
|
-
import {
|
|
20
|
+
import { shardfileRecordings } from './shardfile-audio.ts';
|
|
21
21
|
import type { RecordingMeasure } from './audio-measure.ts';
|
|
22
22
|
import { issueError, withIssueCode as coded } from './issue-codes.ts';
|
|
23
23
|
|
|
@@ -27,11 +27,11 @@ import { issueError, withIssueCode as coded } from './issue-codes.ts';
|
|
|
27
27
|
* only this package. It never executes script bytes: re-running admitted WASM (G491) is the execution proof, which
|
|
28
28
|
* stays with the author CLI and the cook worker.
|
|
29
29
|
*
|
|
30
|
-
* Call `prepareAssetDecoders()` (`@wildshard/shard-format/
|
|
30
|
+
* Call `prepareAssetDecoders()` (`@wildshard/shard-format/shardfileAssets`) once before validating; GLB costs need the decoder.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
/** Read access to one product folder. Paths are `/`-separated and relative to the product root. */
|
|
34
|
-
export interface
|
|
34
|
+
export interface ShardfileFiles {
|
|
35
35
|
/** The bytes of one regular file, refusing symlinks and anything larger than `maxBytes`. */
|
|
36
36
|
readonly read: (path: string, maxBytes: number) => Uint8Array;
|
|
37
37
|
/** Every non-directory entry under the root (symlinks and special files included, so they are refused as unlisted). */
|
|
@@ -39,7 +39,7 @@ export interface ProductFiles {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/** The host services format validation needs but does not own. */
|
|
42
|
-
export interface
|
|
42
|
+
export interface ShardfileValidationPorts {
|
|
43
43
|
/** Lowercase hex SHA-256 of exact bytes. */
|
|
44
44
|
readonly hash: (bytes: Uint8Array) => string;
|
|
45
45
|
/** Whether bytes have the expected hash; `whole` marks a complete inventory file a caller may remember. Default: `hash`. */
|
|
@@ -55,7 +55,7 @@ export interface ProductValidationPorts {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** A product that passed format validation. */
|
|
58
|
-
export interface
|
|
58
|
+
export interface ValidatedShardfile {
|
|
59
59
|
readonly index: OutputIndex;
|
|
60
60
|
readonly shard: Shardfile;
|
|
61
61
|
/** Admitted bytes by hash (`commons:<hash>` for pinned commons). */
|
|
@@ -106,18 +106,18 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/** Refuse the declared targets a policy treats as refusals, before any byte is read or executed. */
|
|
109
|
-
export function
|
|
109
|
+
export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse'): void {
|
|
110
110
|
const issues = performanceTargetIssues(source, policy).filter(issue => issue.severity === 'refusal');
|
|
111
111
|
if (issues.length === 0) return;
|
|
112
112
|
throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
|
|
116
|
-
export function
|
|
116
|
+
export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
|
|
117
117
|
policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = []): Shardfile {
|
|
118
118
|
const source = coded('shard-schema', (): Shardfile => parseShardfile(input));
|
|
119
119
|
coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
|
|
120
|
-
coded('performance-targets', (): void => {
|
|
120
|
+
coded('performance-targets', (): void => { assertShardfileTargets(source, policy); });
|
|
121
121
|
return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts));
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -128,7 +128,7 @@ export function checkWorldTargets(source: Shardfile, input: unknown): void {
|
|
|
128
128
|
if (errors.length > 0) throw issueError('world-targets', errors.join('; '));
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function inspectBlob(file: OutputFile, bytes: Uint8Array, ports:
|
|
131
|
+
function inspectBlob(file: OutputFile, bytes: Uint8Array, ports: ShardfileValidationPorts, script?: ScriptContract): void {
|
|
132
132
|
const contract = file.name === undefined ? undefined : registeredJsonContract(file.name);
|
|
133
133
|
if (contract !== undefined && (file.kind !== 'json' || file.jsonSchema === undefined)) throw new Error('Registered JSON requires its defining schema');
|
|
134
134
|
if (file.jsonSchema !== undefined) {
|
|
@@ -203,7 +203,7 @@ function readCook(index: OutputIndex, read: ReadListed, hash: (bytes: Uint8Array
|
|
|
203
203
|
* kind with no declared side (SERVER-PARITY SS2, `feature-sides.ts`) is refused by name before its section schema runs, and
|
|
204
204
|
* a script run on the wrong side (SS7, `script-sides.ts`) once the sections are read. A refusal carries the `code` of the
|
|
205
205
|
* check that refused (SA41, `issue-codes.ts`). */
|
|
206
|
-
export function
|
|
206
|
+
export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileValidationPorts): ValidatedShardfile {
|
|
207
207
|
const verify = ports.verify ?? ((bytes: Uint8Array, expected: string): boolean => ports.hash(bytes) === expected);
|
|
208
208
|
const index = coded('index-invalid', (): OutputIndex => parseOutputIndex(readCanonicalJson(files.read('shard.json', limits.sourceBytes))));
|
|
209
209
|
const listed = new Set(['shard.json', 'validation.json']), { assets, keep } = assetStore(files.read, ports.readThrough === true);
|
|
@@ -229,8 +229,8 @@ export function validateShardfileProduct(files: ProductFiles, ports: ProductVali
|
|
|
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 =
|
|
232
|
+
const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts);
|
|
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
|
-
return { index, shard, assets, sections: payloads, scripts, warnings, audio:
|
|
235
|
+
return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
|
|
236
236
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type {Shardfile} from './shardSchema.ts';
|
|
2
2
|
import {preflightShardfile} from './preflight.ts';
|
|
3
3
|
|
|
4
|
-
/** What `
|
|
4
|
+
/** What `shardfileWireBytes` reads of a product. */
|
|
5
5
|
type Wire=Readonly<{files:readonly Readonly<{compressed:number}>[];requires:Readonly<{commons:readonly string[];commonsWire:Readonly<Record<string,number>>}>}>;
|
|
6
6
|
/** The wire a product claim holds: every file's and pinned common's compressed bytes. No residency figure is below it. */
|
|
7
|
-
function
|
|
7
|
+
function shardfileWireBytes(source:Wire):number{
|
|
8
8
|
return source.files.reduce((sum,file)=>sum+file.compressed,0)
|
|
9
9
|
+source.requires.commons.reduce((sum,hash)=>sum+(source.requires.commonsWire[hash]??0),0);
|
|
10
10
|
}
|
|
11
11
|
/** Exact existing source/wire claim, computed once by the publisher for first-party clients. */
|
|
12
12
|
function publishedSourceResidency(source:Shardfile):number{
|
|
13
13
|
const accounting={heapBytes:0};preflightShardfile(source,accounting);
|
|
14
|
-
return
|
|
14
|
+
return shardfileWireBytes(source)+accounting.heapBytes*2+(source.files.length+source.requires.commons.length)*128+1024;
|
|
15
15
|
}
|
|
16
|
-
export {
|
|
16
|
+
export {shardfileWireBytes,publishedSourceResidency};
|
package/src/format/tar.ts
CHANGED
|
@@ -200,5 +200,5 @@ function readTar(bytes: Readonly<Uint8Array>): ReadonlyMap<string, Uint8Array> {
|
|
|
200
200
|
|
|
201
201
|
export type { TarEntry, TarSource } from './tar-source.ts'
|
|
202
202
|
export { writeTar } from './tar-write.ts'
|
|
203
|
-
// `readTarHeader` is the streaming walk's (
|
|
203
|
+
// `readTarHeader` is the streaming walk's (shardfileStream.ts): one header, the same refusals.
|
|
204
204
|
export { header as readTarHeader, indexTar, readTar }
|
|
@@ -9,7 +9,7 @@ export interface ValidationReceipt {
|
|
|
9
9
|
residentBytes?:number;
|
|
10
10
|
}
|
|
11
11
|
/** Lookup of a build-stamped number, not a client cost/preflight calculation. */
|
|
12
|
-
export function
|
|
12
|
+
export function builtShardfileResidency(sourceHash:string):number|undefined{
|
|
13
13
|
const rows:unknown=typeof __SHARDFILE_VERDICTS__==='object'?__SHARDFILE_VERDICTS__:null;
|
|
14
14
|
if(!Array.isArray(rows))return undefined;
|
|
15
15
|
for(const item of rows){
|
|
@@ -19,7 +19,7 @@ export function builtProductResidency(sourceHash:string):number|undefined{
|
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
21
21
|
/** Static post cost is validated with the published graph bytes, never recosted at entry. */
|
|
22
|
-
export function
|
|
22
|
+
export function builtShardfilePostCost(sourceHash:string):PostStackCost|undefined{
|
|
23
23
|
const rows:unknown=typeof __SHARDFILE_VERDICTS__==='object'?__SHARDFILE_VERDICTS__:null;
|
|
24
24
|
if(!Array.isArray(rows))return undefined;
|
|
25
25
|
for(const item of rows){
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|