@plasius/gpu-shader 0.1.1 → 0.1.2

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/dist/node.cjs CHANGED
@@ -5991,6 +5991,29 @@ ${canonicalizeGpuContract(core)}`
5991
5991
  );
5992
5992
  }
5993
5993
 
5994
+ // src/asset-version.ts
5995
+ var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
5996
+ var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
5997
+ "latest",
5998
+ "current",
5999
+ "stable",
6000
+ "preview",
6001
+ "default",
6002
+ "production",
6003
+ "canary",
6004
+ "next",
6005
+ "head",
6006
+ "main"
6007
+ ]);
6008
+ var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
6009
+ var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
6010
+ function assertImmutableAssetVersion(value) {
6011
+ if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
6012
+ throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
6013
+ }
6014
+ return value;
6015
+ }
6016
+
5994
6017
  // src/requirements-validation.ts
5995
6018
  var ENABLED_FEATURES = Object.freeze({
5996
6019
  f16: "shader-f16",
@@ -6318,6 +6341,15 @@ function validateShaderDerivedRequirements(input) {
6318
6341
  // src/manifest-validation.ts
6319
6342
  var stages = ["vertex", "fragment", "compute"];
6320
6343
  var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
6344
+ function detachedJson(value, path2) {
6345
+ try {
6346
+ return JSON.parse(canonicalizeGpuContract(value));
6347
+ } catch (cause) {
6348
+ const detail = cause instanceof Error ? cause.message : "Contract snapshot failed.";
6349
+ const boundedDetail = [...detail].slice(0, 512).join("");
6350
+ throw new TypeError(`${path2} must contain detached JSON contract data: ${boundedDetail}`, { cause });
6351
+ }
6352
+ }
6321
6353
  function object(value, path2) {
6322
6354
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
6323
6355
  return value;
@@ -6338,6 +6370,16 @@ function token(value, path2) {
6338
6370
  if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
6339
6371
  return result;
6340
6372
  }
6373
+ function immutableVersion(value, path2) {
6374
+ try {
6375
+ return assertImmutableAssetVersion(value);
6376
+ } catch (cause) {
6377
+ throw new TypeError(
6378
+ `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
6379
+ { cause }
6380
+ );
6381
+ }
6382
+ }
6341
6383
  function enumeration(value, values, path2) {
6342
6384
  if (!values.includes(value)) throw new TypeError(`${path2} is invalid.`);
6343
6385
  return value;
@@ -6611,7 +6653,7 @@ function interfaceRef(value, path2) {
6611
6653
  const input = object(value, path2);
6612
6654
  exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
6613
6655
  token(input.interfaceId, `${path2}.interfaceId`);
6614
- token(input.interfaceVersion, `${path2}.interfaceVersion`);
6656
+ immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
6615
6657
  uri(input.manifestUri, `${path2}.manifestUri`);
6616
6658
  digest(input.manifestSha256, `${path2}.manifestSha256`);
6617
6659
  digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
@@ -6749,7 +6791,7 @@ function pipeline(value, path2, moduleIds) {
6749
6791
  return input;
6750
6792
  }
6751
6793
  function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
6752
- const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
6794
+ const parsed = array(detachedJson(value, path2), path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
6753
6795
  unique(parsed, (item) => item.pipelineId, path2);
6754
6796
  return freeze(parsed);
6755
6797
  }
@@ -6757,7 +6799,7 @@ function compatibleModel(value, path2) {
6757
6799
  const input = object(value, path2);
6758
6800
  exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
6759
6801
  token(input.interfaceId, `${path2}.interfaceId`);
6760
- token(input.interfaceVersion, `${path2}.interfaceVersion`);
6802
+ immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
6761
6803
  digest(input.manifestSha256, `${path2}.manifestSha256`);
6762
6804
  digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
6763
6805
  digest(input.modelAbiHash, `${path2}.modelAbiHash`);
@@ -6770,7 +6812,7 @@ function validationEvidenceRef(value, path2) {
6770
6812
  uri(evidence.uri, `${path2}.uri`);
6771
6813
  digest(evidence.sha256, `${path2}.sha256`);
6772
6814
  token(evidence.matrixId, `${path2}.matrixId`);
6773
- token(evidence.matrixVersion, `${path2}.matrixVersion`);
6815
+ immutableVersion(evidence.matrixVersion, `${path2}.matrixVersion`);
6774
6816
  digest(evidence.matrixSha256, `${path2}.matrixSha256`);
6775
6817
  const attestation = object(evidence.attestationRef, `${path2}.attestationRef`);
6776
6818
  exact(attestation, ["uri", "sha256"], `${path2}.attestationRef`);
@@ -6797,11 +6839,11 @@ function reflectedRecordBindingSize(record) {
6797
6839
  return Math.ceil(unrounded / record.alignment) * record.alignment;
6798
6840
  }
6799
6841
  function parseGpuInterfaceManifest(value) {
6800
- const input = object(value, "GpuInterfaceManifest");
6842
+ const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
6801
6843
  exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
6802
6844
  if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
6803
6845
  token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
6804
- token(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
6846
+ immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
6805
6847
  const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
6806
6848
  if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
6807
6849
  const moduleIds = moduleValues.map((value2, index) => {
@@ -6983,11 +7025,11 @@ function parseGpuInterfaceManifest(value) {
6983
7025
  return freeze(input);
6984
7026
  }
6985
7027
  function parseShaderVersionManifest(value) {
6986
- const input = object(value, "ShaderVersionManifest");
7028
+ const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
6987
7029
  exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
6988
7030
  if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
6989
7031
  token(input.shaderId, "ShaderVersionManifest.shaderId");
6990
- token(input.version, "ShaderVersionManifest.version");
7032
+ immutableVersion(input.version, "ShaderVersionManifest.version");
6991
7033
  const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
6992
7034
  if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
6993
7035
  const moduleIds = moduleValues.map((item, index) => {
@@ -7100,7 +7142,7 @@ function parseShaderVersionManifest(value) {
7100
7142
  return freeze(input);
7101
7143
  }
7102
7144
  function parseShaderVersionManifestCore(value) {
7103
- const input = object(value, "ShaderVersionManifestCore");
7145
+ const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
7104
7146
  if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
7105
7147
  throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
7106
7148
  }
@@ -7126,10 +7168,10 @@ function parseShaderVersionManifestCore(value) {
7126
7168
  return freeze(core);
7127
7169
  }
7128
7170
  function parseModelGpuCompatibilityDescriptor(value) {
7129
- const input = object(value, "ModelGpuCompatibilityDescriptor");
7171
+ const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
7130
7172
  exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
7131
7173
  token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
7132
- token(input.version, "ModelGpuCompatibilityDescriptor.version");
7174
+ immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
7133
7175
  const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
7134
7176
  const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
7135
7177
  if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
@@ -7138,14 +7180,17 @@ function parseModelGpuCompatibilityDescriptor(value) {
7138
7180
  const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
7139
7181
  exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
7140
7182
  token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
7141
- token(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
7183
+ immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
7142
7184
  uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
7143
7185
  digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
7144
7186
  }
7145
7187
  return freeze(input);
7146
7188
  }
7147
7189
  function parseShaderQualificationModelCompatibilityFixture(value) {
7148
- const input = object(value, "ShaderQualificationModelCompatibilityFixture");
7190
+ const input = object(
7191
+ detachedJson(value, "ShaderQualificationModelCompatibilityFixture"),
7192
+ "ShaderQualificationModelCompatibilityFixture"
7193
+ );
7149
7194
  exact(input, ["contractVersion", "fixtureId", "model"], "ShaderQualificationModelCompatibilityFixture");
7150
7195
  if (input.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported model compatibility fixture version.");
7151
7196
  token(input.fixtureId, "ShaderQualificationModelCompatibilityFixture.fixtureId");
@@ -7510,7 +7555,7 @@ function validatePipelineInterfaces(input) {
7510
7555
  // package.json
7511
7556
  var package_default = {
7512
7557
  name: "@plasius/gpu-shader",
7513
- version: "0.1.1",
7558
+ version: "0.1.2",
7514
7559
  description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
7515
7560
  type: "module",
7516
7561
  sideEffects: false,
@@ -8962,6 +9007,11 @@ function issue2(code, message, path2) {
8962
9007
  function object2(value) {
8963
9008
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
8964
9009
  }
9010
+ function freezeJson(value) {
9011
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
9012
+ for (const child of Object.values(value)) freezeJson(child);
9013
+ return Object.freeze(value);
9014
+ }
8965
9015
  function exactKeys(value, keys) {
8966
9016
  const expected = new Set(keys);
8967
9017
  return Object.keys(value).every((key) => expected.has(key)) && keys.every((key) => key in value);
@@ -8969,6 +9019,14 @@ function exactKeys(value, keys) {
8969
9019
  function safeToken(value) {
8970
9020
  return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
8971
9021
  }
9022
+ function immutableVersion2(value) {
9023
+ try {
9024
+ assertImmutableAssetVersion(value);
9025
+ return true;
9026
+ } catch {
9027
+ return false;
9028
+ }
9029
+ }
8972
9030
  function validSha(value) {
8973
9031
  try {
8974
9032
  asSha256Hex(String(value));
@@ -8978,8 +9036,20 @@ function validSha(value) {
8978
9036
  }
8979
9037
  }
8980
9038
  function validateCompileUnitInventory(value) {
8981
- const envelope = object2(value);
8982
- const candidate = envelope && "inventory" in envelope ? object2(value.inventory) : envelope;
9039
+ let snapshot;
9040
+ try {
9041
+ snapshot = JSON.parse(canonicalizeGpuContract(value));
9042
+ } catch (cause) {
9043
+ return {
9044
+ ok: false,
9045
+ diagnostics: [issue2(
9046
+ "invalid-contract",
9047
+ cause instanceof Error ? cause.message : "Compile-unit inventory must contain detached JSON data."
9048
+ )]
9049
+ };
9050
+ }
9051
+ const envelope = object2(snapshot);
9052
+ const candidate = envelope && Object.hasOwn(envelope, "inventory") ? object2(snapshot.inventory) : envelope;
8983
9053
  const diagnostics = [];
8984
9054
  if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
8985
9055
  return { ok: false, diagnostics: [issue2("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
@@ -9110,7 +9180,7 @@ function validateCompileUnitInventory(value) {
9110
9180
  diagnostics.push(issue2("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
9111
9181
  }
9112
9182
  const interfaceRef2 = object2(unit.interfaceRef);
9113
- if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !safeToken(interfaceRef2.interfaceVersion) || typeof interfaceRef2.manifestUri !== "string" || !interfaceRef2.manifestUri.startsWith("https://") || !validSha(interfaceRef2.manifestSha256) || !validSha(interfaceRef2.interfaceAbiHash) || !validSha(interfaceRef2.modelAbiHash)) {
9183
+ if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !immutableVersion2(interfaceRef2.interfaceVersion) || typeof interfaceRef2.manifestUri !== "string" || !interfaceRef2.manifestUri.startsWith("https://") || !validSha(interfaceRef2.manifestSha256) || !validSha(interfaceRef2.interfaceAbiHash) || !validSha(interfaceRef2.modelAbiHash)) {
9114
9184
  diagnostics.push(issue2("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
9115
9185
  }
9116
9186
  const fixture = object2(unit.qualificationFixture);
@@ -9121,7 +9191,7 @@ function validateCompileUnitInventory(value) {
9121
9191
  for (const fragmentId of fragmentIds) {
9122
9192
  if (!covered.has(fragmentId)) diagnostics.push(issue2("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
9123
9193
  }
9124
- return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
9194
+ return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson(candidate) };
9125
9195
  }
9126
9196
 
9127
9197
  // src/testing/qualification-bundle.ts
@@ -9213,6 +9283,18 @@ function object3(value, path2) {
9213
9283
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
9214
9284
  return value;
9215
9285
  }
9286
+ function detachedJson2(value, label) {
9287
+ try {
9288
+ return JSON.parse(canonicalizeGpuContract(value));
9289
+ } catch (cause) {
9290
+ throw new TypeError(`${label} must contain detached JSON contract data.`, { cause });
9291
+ }
9292
+ }
9293
+ function freezeJson2(value) {
9294
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
9295
+ for (const child of Object.values(value)) freezeJson2(child);
9296
+ return Object.freeze(value);
9297
+ }
9216
9298
  function exact2(value, keys, path2) {
9217
9299
  const expected = new Set(keys);
9218
9300
  if (!Object.keys(value).every((key) => expected.has(key)) || !keys.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
@@ -9221,6 +9303,16 @@ function token2(value, path2) {
9221
9303
  if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
9222
9304
  return value;
9223
9305
  }
9306
+ function immutableVersion3(value, path2) {
9307
+ try {
9308
+ return assertImmutableAssetVersion(value);
9309
+ } catch (cause) {
9310
+ throw new TypeError(
9311
+ `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
9312
+ { cause }
9313
+ );
9314
+ }
9315
+ }
9224
9316
  function path(value, label, extensions) {
9225
9317
  if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
9226
9318
  throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
@@ -9355,7 +9447,7 @@ function jsonValue(value, label, depth = 0) {
9355
9447
  }
9356
9448
  function validateQualificationFixture(value, unit) {
9357
9449
  try {
9358
- const fixture = object3(value, "fixture");
9450
+ const fixture = object3(detachedJson2(value, "fixture"), "fixture");
9359
9451
  exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
9360
9452
  if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
9361
9453
  token2(fixture.fixtureId, "fixture.fixtureId");
@@ -9691,14 +9783,14 @@ function validateQualificationFixture(value, unit) {
9691
9783
  }
9692
9784
  unique2(probeIds, "fixture.layoutProbes probe IDs");
9693
9785
  unique2(probeSources, "fixture.layoutProbes model sources");
9694
- return { ok: true, value: fixture };
9786
+ return { ok: true, value: freezeJson2(fixture) };
9695
9787
  } catch (cause) {
9696
9788
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
9697
9789
  }
9698
9790
  }
9699
9791
  function validateQualificationBundleManifest(value) {
9700
9792
  try {
9701
- const bundle = object3(value, "qualification");
9793
+ const bundle = object3(detachedJson2(value, "qualification"), "qualification");
9702
9794
  exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
9703
9795
  if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
9704
9796
  const inventory = validateCompileUnitInventory(bundle.inventory);
@@ -9708,7 +9800,7 @@ function validateQualificationBundleManifest(value) {
9708
9800
  const candidate = object3(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
9709
9801
  exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
9710
9802
  token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
9711
- token2(candidate.version, "qualification.subject.shaderManifestCore.version");
9803
+ immutableVersion3(candidate.version, "qualification.subject.shaderManifestCore.version");
9712
9804
  sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
9713
9805
  path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
9714
9806
  const interfaceManifest = object3(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
@@ -9768,7 +9860,7 @@ function validateQualificationBundleManifest(value) {
9768
9860
  const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
9769
9861
  if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
9770
9862
  orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
9771
- return { ok: true, value: bundle };
9863
+ return { ok: true, value: freezeJson2(bundle) };
9772
9864
  } catch (cause) {
9773
9865
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
9774
9866
  }