@wildshard/shard-format 0.8.0 → 0.9.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.8.0",
3
+ "version": "0.9.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": {
@@ -15,7 +15,8 @@ import { ClientPlanRuntimeSchema } from './runtime.ts';
15
15
  import { RuntimeSpawnsSchema } from './runtimeSpawns.ts';
16
16
  import { RowsSchema } from './rows.ts';
17
17
  import { ShardHashSchema, ShardNaturalSchema, IdentitySchema, RequiresSchema, FilesSchema, type ShardIdentityInput, type ShardRequiresInput, type ShardReferencesInput, type ShardIdentity, type ShardRequires, type ShardReferences } from './shardSections.ts';
18
- import { SHARDFILE_VERSION } from './version.ts';
18
+ import { SHARDFILE_VERSIONS } from './version.ts';
19
+ import type { ShardfileVersion } from './version.ts';
19
20
  import { isJsonData, isJsonDataWithFileSchemas } from './json.ts';
20
21
  import { clientOwnershipRules } from './clientOwnership.ts';
21
22
  import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts';
@@ -31,7 +32,7 @@ const fileSchema = v.strictObject({ ...costs, path, kind: v.picklist(['glb', 'kt
31
32
  const runtime = v.strictObject({ ...v.omit(ClientPlanRuntimeSchema.pipe[0], ['spawns']).entries, trust: v.literal('first-party'), files: v.pipe(v.array(v.strictObject({ ...measuredFile, lines: ShardNaturalSchema })), v.maxLength(0)), lines: v.literal(0) });
32
33
  /** Format 2 inventories every emitted byte except its index and validation receipt. */
33
34
  export const OutputIndexSchema: v.GenericSchema<OutputIndexRowsInput, OutputIndexRows> & { readonly entries: { readonly [Key in keyof OutputIndexRows]-?: v.GenericSchema<OutputIndexRowsInput[Key], OutputIndexRows[Key]> } } = v.strictObject({
34
- format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.picklist(['0.2', '0.3']), version: v.literal(SHARDFILE_VERSION),
35
+ format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.picklist(['0.2', '0.3']), version: v.picklist(SHARDFILE_VERSIONS),
35
36
  identity: IdentitySchema, build: v.strictObject({ sourceHash: ShardHashSchema, validator: v.pipe(v.string(), v.minLength(1), v.maxLength(160)) }), requires: RequiresSchema,
36
37
  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) }),
37
38
  sections: v.pipe(v.array(section), v.maxLength(256)), schemas: v.pipe(v.array(v.strictObject(measuredFile)), v.maxLength(0)),
@@ -158,7 +159,7 @@ interface OutputIndexRowsInputFields {
158
159
  format: "wildshard.shardfile";
159
160
  formatVersion: 2;
160
161
  sdk: "0.2" | "0.3";
161
- version: "0.1";
162
+ version: ShardfileVersion;
162
163
  identity: ShardIdentityInput;
163
164
  build: {
164
165
  sourceHash: string;
@@ -256,7 +257,7 @@ interface OutputIndexRowsFields {
256
257
  format: "wildshard.shardfile";
257
258
  formatVersion: 2;
258
259
  sdk: "0.2" | "0.3";
259
- version: "0.1";
260
+ version: ShardfileVersion;
260
261
  identity: ShardIdentity;
261
262
  build: {
262
263
  sourceHash: string;
@@ -13,7 +13,8 @@ import { jsonDataNodes } from './json.ts';
13
13
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
14
14
  import { preflightShardfile } from './preflight.ts';
15
15
  import { preflightAssetGraph } from './shardfile-assets.ts';
16
- import { SHARDFILE_VERSION } from './version.ts';
16
+ import { SHARDFILE_VERSIONS } from './version.ts';
17
+ import type { ShardfileVersion } from './version.ts';
17
18
  import { UiSchema, uiRules } from './ui.ts';
18
19
  import { scriptBindingRules } from './scripts.ts';
19
20
  import { RowsSchema } from './rows.ts';
@@ -75,7 +76,7 @@ const lookGrade = v.strictObject({ exposure: finite, saturation: v.pipe(finite,
75
76
  /** A colour LUT file's exact wire size: 33³ RGBA8 (the engine's render/lut format). */
76
77
  export const LOOK_LUT_BYTES: number = 33 ** 3 * 4;
77
78
  const rawSchema: v.GenericSchema<ShardfileRowsInput, ShardfileRows> & { readonly entries: { readonly [Key in keyof ShardfileRows]-?: v.GenericSchema<ShardfileRowsInput[Key], ShardfileRows[Key]> } } = v.strictObject({
78
- version: v.literal(SHARDFILE_VERSION),
79
+ version: v.picklist(SHARDFILE_VERSIONS),
79
80
  accent: AccentSchema,
80
81
  identity: IdentitySchema,
81
82
  presentation: v.exactOptional(PresentationSchema),
@@ -132,7 +133,7 @@ export const ShardfileFieldSchemas: { readonly [Key in keyof Shardfile]-?: v.Gen
132
133
  /** Public parsed output, independently named by section. The unchanged schema
133
134
  * is checked against this interface, so consumers need not expand its input tree. */
134
135
  export interface Shardfile {
135
- version: typeof SHARDFILE_VERSION;
136
+ version: ShardfileVersion;
136
137
  accent: v.InferOutput<typeof AccentSchema>;
137
138
  identity: v.InferOutput<typeof IdentitySchema>;
138
139
  presentation?: v.InferOutput<typeof PresentationSchema>;
@@ -398,7 +399,7 @@ export { parseShardfile, parseShardfileField };
398
399
 
399
400
  /** Admitted data contracts, independent of validator implementation metadata. */
400
401
  interface ShardfileRowsInputFields {
401
- version: (typeof SHARDFILE_VERSION);
402
+ version: ShardfileVersion;
402
403
  accent: v.InferInput<typeof AccentSchema>;
403
404
  identity: v.InferInput<typeof IdentitySchema>;
404
405
  presentation?: v.InferInput<typeof PresentationSchema>;
@@ -476,7 +477,7 @@ interface ShardfileRowsInputFields {
476
477
  }
477
478
  export type ShardfileRowsInput = { [Key in keyof ShardfileRowsInputFields]: ShardfileRowsInputFields[Key] };
478
479
  interface ShardfileRowsFields {
479
- version: (typeof SHARDFILE_VERSION);
480
+ version: ShardfileVersion;
480
481
  accent: v.InferOutput<typeof AccentSchema>;
481
482
  identity: v.InferOutput<typeof IdentitySchema>;
482
483
  presentation?: v.InferOutput<typeof PresentationSchema>;
@@ -3,7 +3,8 @@
3
3
  import * as v from 'valibot';
4
4
  import { WIRE_CELL, WIRE_TILE_SIZES } from './wireLimits.ts';
5
5
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
6
- import { SHARDFILE_VERSION } from './version.ts';
6
+ import { SHARDFILE_VERSIONS } from './version.ts';
7
+ import type { ShardfileVersion } from './version.ts';
7
8
  import { RuntimeCostSchema } from './runtimeCost.ts';
8
9
  import { CommonsCostsSchema } from './commonsCosts.ts';
9
10
  import { ScriptBindingsSchema } from './scripts.ts';
@@ -35,7 +36,7 @@ const tileCount = (2 * CHUNK_HALF / WIRE_TILE_SIZES.l0) ** 2 + (2 * CHUNK_HALF /
35
36
  /** Stable authored shard identity and deterministic seed. */
36
37
  export const IdentitySchema: v.GenericSchema<ShardIdentityInput, ShardIdentity> = v.strictObject({ slug: name, name: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), author: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), revision: positive, seed: ShardNaturalSchema });
37
38
  /** Wire revision, capabilities and exact commons declarations. */
38
- export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.literal(SHARDFILE_VERSION), capabilities: ShardNamesSchema, commons: v.pipe(v.array(ShardHashSchema), v.maxLength(limits.commons)), commonsWire: v.optional(v.record(ShardHashSchema, ShardNaturalSchema), {}), commonsCosts: v.optional(CommonsCostsSchema, {}) });
39
+ export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.picklist(SHARDFILE_VERSIONS), capabilities: ShardNamesSchema, commons: v.pipe(v.array(ShardHashSchema), v.maxLength(limits.commons)), commonsWire: v.optional(v.record(ShardHashSchema, ShardNaturalSchema), {}), commonsCosts: v.optional(CommonsCostsSchema, {}) });
39
40
  /** Authored compressed and resident ceilings. */
40
41
  export const BudgetsSchema: v.GenericSchema<ShardBudgetsInput, ShardBudgets> = v.strictObject({
41
42
  /** Reviewed whole-client floor retained when an opaque runtime becomes declared data. */
@@ -216,7 +217,7 @@ interface ShardIdentityFields {
216
217
  }
217
218
  export type ShardIdentity = { [Key in keyof ShardIdentityFields]: ShardIdentityFields[Key] };
218
219
  interface ShardRequiresInputFields {
219
- sdk: (typeof SHARDFILE_VERSION);
220
+ sdk: ShardfileVersion;
220
221
  capabilities: ShardNamesInput;
221
222
  commons: (ShardHashInput)[];
222
223
  commonsWire?: Record<string, ShardNaturalInput> | undefined;
@@ -224,7 +225,7 @@ interface ShardRequiresInputFields {
224
225
  }
225
226
  export type ShardRequiresInput = { [Key in keyof ShardRequiresInputFields]: ShardRequiresInputFields[Key] };
226
227
  interface ShardRequiresFields {
227
- sdk: (typeof SHARDFILE_VERSION);
228
+ sdk: ShardfileVersion;
228
229
  capabilities: ShardNames;
229
230
  commons: (ShardHash)[];
230
231
  commonsWire: Record<string, ShardNatural>;
@@ -3,7 +3,7 @@ import { assertMigrationCompatibility } from './migrations.ts';
3
3
  import { StateSchema } from './state.ts';
4
4
  import type { Shardfile } from './shardSchema.ts';
5
5
  import { isJsonDataWithFileSchemas } from './json.ts';
6
- import { SHARDFILE_VERSION } from './version.ts';
6
+ import { SHARDFILE_VERSIONS } from './version.ts';
7
7
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
8
8
 
9
9
  const identity = v.object({ slug: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u)),
@@ -17,7 +17,7 @@ const path = v.pipe(v.string(), v.maxLength(240), v.regex(/^(?:[a-zA-Z0-9_-][a-z
17
17
  const measured = { path, hash: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u)),
18
18
  bytes: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)) };
19
19
  const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.literal('0.2'),
20
- version: v.literal(SHARDFILE_VERSION), identity,
20
+ version: v.picklist(SHARDFILE_VERSIONS), identity,
21
21
  sections: v.pipe(v.array(v.strictObject({ ...measured, name: v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9-]*\/[a-zA-Z][a-zA-Z0-9_-]*$/u)),
22
22
  schema: v.pipe(v.string(), v.maxLength(240)) })), v.maxLength(256)),
23
23
  schemas: v.pipe(v.array(v.strictObject(measured)), v.maxLength(128)) });
@@ -1,9 +1,81 @@
1
- /** Canonical format/script-ABI wire revision. The format stays 0.x; every breaking revision migrates first-party data. */
2
- export const SHARDFILE_VERSION = '0.1';
3
- /** Parse the decimal revision as a safe integer, never as a floating-point version (0.10 follows 0.9). */
4
- export function shardfileRevision(input: unknown): number {
5
- if (typeof input !== 'string' || !/^0\.(?:0|[1-9][0-9]*)$/u.test(input)) throw new Error('Shardfile needs a canonical format version 0.<revision>');
6
- const revision = Number(input.slice(2));
7
- if (!Number.isSafeInteger(revision)) throw new Error('Shardfile format revision exceeds safe integer range');
8
- return revision;
1
+ /** Canonical format revision, separate from the npm package and script ABI (J319).
2
+ * The fourth component adds fields; the third changes their meaning. */
3
+ const ZERO = 0
4
+ const ONE = 1
5
+
6
+ const SHARDFILE_VERSION = '0.1.0.1'
7
+ /** Legacy 0.1 is the byte-preserving spelling of 0.1.0.0. */
8
+ const SHARDFILE_VERSIONS: readonly [
9
+ '0.1',
10
+ '0.1.0.0',
11
+ typeof SHARDFILE_VERSION,
12
+ ] = ['0.1', '0.1.0.0', SHARDFILE_VERSION] as const
13
+ type ShardfileVersion = (typeof SHARDFILE_VERSIONS)[number]
14
+ type ShardfileVersionParts = readonly [number, number, number, number]
15
+
16
+ /** Read canonical bounded decimal components; the legacy two-part spelling has zero counters. */
17
+ function parseShardfileVersion(input: unknown): ShardfileVersionParts {
18
+ if (
19
+ typeof input !== 'string' ||
20
+ !/^(?:0|[1-9][0-9]{0,3})(?:\.(?:0|[1-9][0-9]{0,3}))(?:\.(?:0|[1-9][0-9]{0,3})\.(?:0|[1-9][0-9]{0,3}))?$/u.test(
21
+ input,
22
+ )
23
+ ) {
24
+ throw new Error('Shardfile needs a canonical format version X.Y or X.Y.B.A')
25
+ }
26
+ const [major = ZERO, minor = ZERO, breaking = ZERO, additive = ZERO] = input
27
+ .split('.')
28
+ .map(Number)
29
+ return [major, minor, breaking, additive]
30
+ }
31
+
32
+ /** Compare every format component numerically, including the additive counter. */
33
+ function compareShardfileVersions(left: unknown, right: unknown): number {
34
+ const leftParts = parseShardfileVersion(left),
35
+ rightParts = parseShardfileVersion(right)
36
+ for (let index = 0; index < leftParts.length; index += ONE) {
37
+ const difference = (leftParts[index] ?? ZERO) - (rightParts[index] ?? ZERO)
38
+ if (difference !== ZERO) {
39
+ return Math.sign(difference)
40
+ }
41
+ }
42
+ return ZERO
43
+ }
44
+
45
+ /** A reader accepts its own additive revision and the previous one in the same breaking format.
46
+ * Future additions can introduce required declarations, so they still require a newer reader. */
47
+ function compatibleShardfileVersion(
48
+ input: unknown,
49
+ reader: unknown = SHARDFILE_VERSION,
50
+ ): boolean {
51
+ try {
52
+ const [major, minor, breaking, additive] = parseShardfileVersion(input)
53
+ const [readMajor, readMinor, readBreaking, readAdditive] =
54
+ parseShardfileVersion(reader)
55
+ return (
56
+ major === readMajor &&
57
+ minor === readMinor &&
58
+ breaking === readBreaking &&
59
+ additive <= readAdditive &&
60
+ additive >= Math.max(ZERO, readAdditive - ONE)
61
+ )
62
+ } catch {
63
+ return false
64
+ }
65
+ }
66
+
67
+ /** Legacy callers use this only to validate the era's decimal minor; new code compares all four components. */
68
+ function shardfileRevision(input: unknown): number {
69
+ return parseShardfileVersion(input)[ONE]
70
+ }
71
+
72
+ export {
73
+ SHARDFILE_VERSION,
74
+ SHARDFILE_VERSIONS,
75
+ type ShardfileVersion,
76
+ type ShardfileVersionParts,
77
+ parseShardfileVersion,
78
+ compareShardfileVersions,
79
+ compatibleShardfileVersion,
80
+ shardfileRevision,
9
81
  }