@carbonenginejs/runtime-resource 0.18.0 → 0.19.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/dist/format/carbonEffect/CjsCarbonEffectWriter.js +16 -4
- package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -1
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js +11 -1
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +36 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectRecords.js +45 -1
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js +120 -60
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -1
- package/dist/format/index.js +1 -1
- package/dist/formats/dds/core/helpers.js +35 -6
- package/dist/formats/dds/core/helpers.js.map +1 -1
- package/dist/formats/fbx/core/helpers.js +1 -1
- package/dist/formats/fbx/core/helpers.js.map +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +53 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +10 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -1
- package/dist/formats/index.js +3 -0
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/jpeg/core/helpers.js +1 -1
- package/dist/formats/jpeg/core/helpers.js.map +1 -1
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +205 -44
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -1
- package/dist/formats/schemabound/CjsSchemaBoundFormat.js +236 -0
- package/dist/formats/schemabound/CjsSchemaBoundFormat.js.map +1 -0
- package/dist/formats/schemabound/core/schemaBoundErrors.js +9 -0
- package/dist/formats/schemabound/core/schemaBoundErrors.js.map +1 -0
- package/dist/formats/schemabound/core/schemaBoundValues.js +336 -0
- package/dist/formats/schemabound/core/schemaBoundValues.js.map +1 -0
- package/dist/formats/schemabound/index.js +2 -0
- package/dist/formats/schemabound/index.js.map +1 -0
- package/dist/formats/sqlite/CjsSqliteFormat.js +244 -0
- package/dist/formats/sqlite/CjsSqliteFormat.js.map +1 -0
- package/dist/formats/sqlite/core/sqlitePages.js +159 -0
- package/dist/formats/sqlite/core/sqlitePages.js.map +1 -0
- package/dist/formats/sqlite/core/sqliteRecords.js +174 -0
- package/dist/formats/sqlite/core/sqliteRecords.js.map +1 -0
- package/dist/formats/sqlite/core/sqliteSchema.js +100 -0
- package/dist/formats/sqlite/core/sqliteSchema.js.map +1 -0
- package/dist/formats/sqlite/index.js +2 -0
- package/dist/formats/sqlite/index.js.map +1 -0
- package/dist/formats/static/CjsStaticFormat.js +222 -0
- package/dist/formats/static/CjsStaticFormat.js.map +1 -0
- package/dist/formats/static/index.js +3 -0
- package/dist/formats/static/index.js.map +1 -0
- package/dist/formats/static/staticContainers.js +157 -0
- package/dist/formats/static/staticContainers.js.map +1 -0
- package/dist/formats/webgl/core/buildGlslEffectContainer.js +3 -1
- package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -1
- package/dist/formats/webgl/core/effectPackage.js +11 -2
- package/dist/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +10 -2
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +3 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
- package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js +179 -131
- package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -1
- package/dist/formats/webgpu/core/effectBackendBodySet.js +20 -20
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +14 -1
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +9 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +14 -0
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/docs/concepts/shader-resource-model.md +34 -1
- package/docs/formats/README.md +21 -0
- package/docs/formats/carbon-effect-container.md +54 -27
- package/docs/formats/pickle.md +36 -0
- package/docs/formats/schemabound.md +123 -0
- package/docs/formats/static.md +166 -0
- package/docs/formats/webgl/README.md +5 -3
- package/docs/formats/webgpu/README.md +2 -2
- package/docs/formats/webgpu/architecture.md +2 -2
- package/docs/formats/webgpu/formats/carbon-webgpu.md +13 -2
- package/docs/formats/webgpu/guides/effect-packaging.md +1 -2
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +2 -2
- package/docs/reference/classes/formats.md +33 -0
- package/package.json +4 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const SQLITE_SIGNATURE = "SQLite format 3\0";
|
|
2
|
+
const PICKLE_PREFIX_BYTES = 4;
|
|
3
|
+
|
|
4
|
+
/** Container families found behind the single `.static` extension. */
|
|
5
|
+
const CJS_STATIC_FAMILIES = Object.freeze({
|
|
6
|
+
SQLITE: "sqlite",
|
|
7
|
+
PICKLE: "pickle",
|
|
8
|
+
UNKNOWN: "unknown"
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Identifies which container a client `.static` file actually holds.
|
|
13
|
+
*
|
|
14
|
+
* The extension names a role, not a format. Three unrelated containers ship
|
|
15
|
+
* under it, and each fails in its own way when guessed at:
|
|
16
|
+
*
|
|
17
|
+
* - **SQLite 3** — a `cache(key, value, time)` plus `indexes(key, value)`
|
|
18
|
+
* database whose values are JSON documents. `CjsSqliteFormat` reads it.
|
|
19
|
+
* - **Embedded schema** — a four-byte little-endian SCHEMA LENGTH followed by
|
|
20
|
+
* that schema as a protocol-0 pickle, and then a payload. The prefix is not a
|
|
21
|
+
* wrapper to skip: slice `[4, 4 + length)` for the schema and give the rest
|
|
22
|
+
* to `CjsSchemaBoundFormat`. All 25 of these name one global,
|
|
23
|
+
* `collections.OrderedDict`, which the pickle reader rebuilds as plain data.
|
|
24
|
+
* - **Schema-bound** — a binary record container whose `.schema` companion is
|
|
25
|
+
* YAML describing its own layout: attribute sizes and types, optional flags,
|
|
26
|
+
* lists with a fixed item size, vectors with a precision, and a key footer of
|
|
27
|
+
* key-to-offset pairs. Nothing needs deriving, because the build ships the
|
|
28
|
+
* layout. Six datasets are stored this way - the map skeleton of regions,
|
|
29
|
+
* constellations and systems. `CjsSchemaBoundFormat` reads it, given that
|
|
30
|
+
* companion, and reads the embedded-schema family above from the same code.
|
|
31
|
+
*
|
|
32
|
+
* Detection is signature-based and never executes or trusts file names.
|
|
33
|
+
*
|
|
34
|
+
* **This class identifies and does not decode.** It reports the family, the
|
|
35
|
+
* payload offset and what is still missing; the caller takes that answer to the
|
|
36
|
+
* format that owns the family. It carried a `read()` that dispatched to
|
|
37
|
+
* `CjsPickleFormat` and `CjsSqliteFormat` until 2026-08-15, which made an
|
|
38
|
+
* identification format the routing table for two others and put the decision
|
|
39
|
+
* about what to decode in the wrong place. Nothing outside its own tests ever
|
|
40
|
+
* called it.
|
|
41
|
+
*/
|
|
42
|
+
class CjsStaticFormat {
|
|
43
|
+
/**
|
|
44
|
+
* Report which family a container holds, on the declaration seam.
|
|
45
|
+
*
|
|
46
|
+
* `.static` declares nothing: the extension names a role and every family
|
|
47
|
+
* wears it. The signature is therefore the only claim there is, which is why
|
|
48
|
+
* this format reads it here rather than trusting a name.
|
|
49
|
+
*
|
|
50
|
+
* @param {ArrayBuffer|ArrayBufferView} input Container bytes.
|
|
51
|
+
* @param {object} [options] Probe options.
|
|
52
|
+
* @returns {CjsResourceProbe} Declaration-derived probe.
|
|
53
|
+
*/
|
|
54
|
+
static isSupported(input, options = null) {
|
|
55
|
+
return Probe(this.describe(input), false, options);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Alias for canonical naming.
|
|
60
|
+
*
|
|
61
|
+
* @param {ArrayBuffer|ArrayBufferView} input Container bytes.
|
|
62
|
+
* @param {object} [options] Probe options.
|
|
63
|
+
* @returns {CjsResourceProbe} Declaration-derived probe.
|
|
64
|
+
*/
|
|
65
|
+
static inspect(input, options = null) {
|
|
66
|
+
return this.isSupported(input, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Content-verified family resolution.
|
|
71
|
+
*
|
|
72
|
+
* Contract: docs/concepts/format-type-resolution.md. There is no declared
|
|
73
|
+
* type to disagree with here — the extension is silent — so the signature is
|
|
74
|
+
* both the claim and the evidence, and the resolution is always verified.
|
|
75
|
+
* `preferred` names the decode route, and all three now lead into this
|
|
76
|
+
* package: `CjsPickleFormat`, `CjsSqliteFormat`, and `CjsSchemaBoundFormat`
|
|
77
|
+
* once the caller has the `.schema` companion to hand it.
|
|
78
|
+
*
|
|
79
|
+
* @param {ArrayBuffer|ArrayBufferView} input Container bytes.
|
|
80
|
+
* @param {object} [options] Probe options.
|
|
81
|
+
* @returns {Promise<CjsResourceProbe>} Verified probe.
|
|
82
|
+
*/
|
|
83
|
+
static async resolveType(input, options = null) {
|
|
84
|
+
return Probe(this.describe(input), true, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Describe one container without decoding it or building a probe.
|
|
89
|
+
*
|
|
90
|
+
* @param {ArrayBuffer|ArrayBufferView} input Container bytes.
|
|
91
|
+
* @returns {object} Family, payload offset, and whether this package decodes it.
|
|
92
|
+
*/
|
|
93
|
+
static describe(input) {
|
|
94
|
+
const bytes = Normalize(input);
|
|
95
|
+
if (MatchesSqlite(bytes)) {
|
|
96
|
+
return Object.freeze({
|
|
97
|
+
family: CJS_STATIC_FAMILIES.SQLITE,
|
|
98
|
+
byteLength: bytes.byteLength,
|
|
99
|
+
payloadOffset: 0,
|
|
100
|
+
prefix: null,
|
|
101
|
+
// Decodable outright since CjsSqliteFormat landed. This reported
|
|
102
|
+
// `requires: "sqlite"` while a caller had to supply an engine, and was
|
|
103
|
+
// the example behind the argument that a capability can depend on the
|
|
104
|
+
// caller's environment - an argument that now needs a different one.
|
|
105
|
+
decodable: true,
|
|
106
|
+
requires: null,
|
|
107
|
+
reason: "Recognized a SQLite container."
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (MatchesPickle(bytes)) {
|
|
111
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
family: CJS_STATIC_FAMILIES.PICKLE,
|
|
114
|
+
byteLength: bytes.byteLength,
|
|
115
|
+
payloadOffset: PICKLE_PREFIX_BYTES,
|
|
116
|
+
prefix: view.getUint32(0, true),
|
|
117
|
+
decodable: true,
|
|
118
|
+
requires: null,
|
|
119
|
+
reason: null
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return Object.freeze({
|
|
123
|
+
family: CJS_STATIC_FAMILIES.UNKNOWN,
|
|
124
|
+
byteLength: bytes.byteLength,
|
|
125
|
+
payloadOffset: 0,
|
|
126
|
+
prefix: null,
|
|
127
|
+
decodable: false,
|
|
128
|
+
requires: "schema",
|
|
129
|
+
// `decodable` is this format's own answer, and it stays false: these bytes
|
|
130
|
+
// carry nothing to identify, so the family is an inference from the absence
|
|
131
|
+
// of the other two signatures rather than a reading. `requires` names what
|
|
132
|
+
// closes that gap - with the companion, CjsSchemaBoundFormat decodes it.
|
|
133
|
+
reason: "No signature. A schema-bound container needs its .schema companion, " + "which is YAML describing the layout. CjsSchemaBoundFormat reads it from there."
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Return the decodable payload for a container, without its wrapper.
|
|
139
|
+
*
|
|
140
|
+
* @param {ArrayBuffer|ArrayBufferView} input Container bytes.
|
|
141
|
+
* @returns {Uint8Array} Payload bytes.
|
|
142
|
+
*/
|
|
143
|
+
static payload(input) {
|
|
144
|
+
const bytes = Normalize(input);
|
|
145
|
+
const detected = this.describe(bytes);
|
|
146
|
+
return bytes.subarray(detected.payloadOffset);
|
|
147
|
+
}
|
|
148
|
+
static id = "static";
|
|
149
|
+
static extensions = Object.freeze([".static"]);
|
|
150
|
+
static type = Object.freeze(["data"]);
|
|
151
|
+
static mediaTypes = Object.freeze(["data"]);
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The extension is the only input this format claims.
|
|
155
|
+
*
|
|
156
|
+
* Naming the three families here would be a lie in the other direction: a
|
|
157
|
+
* caller cannot hand this format "a pickle" or "a sqlite" and expect it to
|
|
158
|
+
* route, because the whole point of the class is that `.static` declares
|
|
159
|
+
* nothing and the signature has to be read. The family belongs in
|
|
160
|
+
* `describe()`, which measures it, not in a static that asserts it.
|
|
161
|
+
*/
|
|
162
|
+
static inputTypes = Object.freeze(["static"]);
|
|
163
|
+
static outputTypes = Object.freeze(["json", "payload"]);
|
|
164
|
+
static debugOutputTypes = Object.freeze(["raw"]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Build the shared probe payload.
|
|
169
|
+
*
|
|
170
|
+
* Formats report a plain probe-shaped object rather than constructing a
|
|
171
|
+
* `CjsResourceProbe`, which keeps this module free of the decorated class and
|
|
172
|
+
* of the build transform it needs.
|
|
173
|
+
*/
|
|
174
|
+
function Probe(detected, verified, options) {
|
|
175
|
+
return {
|
|
176
|
+
format: "static",
|
|
177
|
+
source: "buffer",
|
|
178
|
+
supported: detected.decodable ? "full" : "partial",
|
|
179
|
+
confidence: detected.family === CJS_STATIC_FAMILIES.UNKNOWN ? 0.5 : 1,
|
|
180
|
+
preferred: detected.family,
|
|
181
|
+
verified,
|
|
182
|
+
reason: detected.reason ?? `Recognized a ${detected.family} container.`,
|
|
183
|
+
variants: [{
|
|
184
|
+
kind: "container",
|
|
185
|
+
codec: detected.family,
|
|
186
|
+
supported: detected.decodable
|
|
187
|
+
}],
|
|
188
|
+
metadata: verified ? {
|
|
189
|
+
...detected,
|
|
190
|
+
declared: null,
|
|
191
|
+
resolved: detected.family,
|
|
192
|
+
mismatch: false
|
|
193
|
+
} : detected,
|
|
194
|
+
...(options || {})
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function MatchesSqlite(bytes) {
|
|
198
|
+
if (bytes.byteLength < SQLITE_SIGNATURE.length) return false;
|
|
199
|
+
for (let index = 0; index < SQLITE_SIGNATURE.length; index++) {
|
|
200
|
+
if (bytes[index] !== SQLITE_SIGNATURE.charCodeAt(index)) return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
function MatchesPickle(bytes) {
|
|
205
|
+
// A protocol-0 pickle opens a container then names it: "(dp1\n" or "(lp1\n".
|
|
206
|
+
if (bytes.byteLength < PICKLE_PREFIX_BYTES + 3) return false;
|
|
207
|
+
if (bytes[PICKLE_PREFIX_BYTES] !== 0x28) return false;
|
|
208
|
+
const kind = bytes[PICKLE_PREFIX_BYTES + 1];
|
|
209
|
+
return kind === 0x64 || kind === 0x6c;
|
|
210
|
+
}
|
|
211
|
+
function Normalize(input) {
|
|
212
|
+
if (input instanceof ArrayBuffer) return new Uint8Array(input);
|
|
213
|
+
if (ArrayBuffer.isView(input)) {
|
|
214
|
+
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
215
|
+
}
|
|
216
|
+
const error = new TypeError("A .static container must be an ArrayBuffer or a view over one.");
|
|
217
|
+
error.code = "CJS_STATIC_FORMAT_INPUT_INVALID";
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { CJS_STATIC_FAMILIES, CjsStaticFormat };
|
|
222
|
+
//# sourceMappingURL=CjsStaticFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CjsStaticFormat.js","sources":["../../../../src/formats/static/CjsStaticFormat.js"],"sourcesContent":["\nconst SQLITE_SIGNATURE = \"SQLite format 3\\0\";\nconst PICKLE_PREFIX_BYTES = 4;\n\n/** Container families found behind the single `.static` extension. */\nexport const CJS_STATIC_FAMILIES = Object.freeze({\n SQLITE: \"sqlite\",\n PICKLE: \"pickle\",\n UNKNOWN: \"unknown\"\n});\n\n/**\n * Identifies which container a client `.static` file actually holds.\n *\n * The extension names a role, not a format. Three unrelated containers ship\n * under it, and each fails in its own way when guessed at:\n *\n * - **SQLite 3** — a `cache(key, value, time)` plus `indexes(key, value)`\n * database whose values are JSON documents. `CjsSqliteFormat` reads it.\n * - **Embedded schema** — a four-byte little-endian SCHEMA LENGTH followed by\n * that schema as a protocol-0 pickle, and then a payload. The prefix is not a\n * wrapper to skip: slice `[4, 4 + length)` for the schema and give the rest\n * to `CjsSchemaBoundFormat`. All 25 of these name one global,\n * `collections.OrderedDict`, which the pickle reader rebuilds as plain data.\n * - **Schema-bound** — a binary record container whose `.schema` companion is\n * YAML describing its own layout: attribute sizes and types, optional flags,\n * lists with a fixed item size, vectors with a precision, and a key footer of\n * key-to-offset pairs. Nothing needs deriving, because the build ships the\n * layout. Six datasets are stored this way - the map skeleton of regions,\n * constellations and systems. `CjsSchemaBoundFormat` reads it, given that\n * companion, and reads the embedded-schema family above from the same code.\n *\n * Detection is signature-based and never executes or trusts file names.\n *\n * **This class identifies and does not decode.** It reports the family, the\n * payload offset and what is still missing; the caller takes that answer to the\n * format that owns the family. It carried a `read()` that dispatched to\n * `CjsPickleFormat` and `CjsSqliteFormat` until 2026-08-15, which made an\n * identification format the routing table for two others and put the decision\n * about what to decode in the wrong place. Nothing outside its own tests ever\n * called it.\n */\nexport class CjsStaticFormat\n{\n\n /**\n * Report which family a container holds, on the declaration seam.\n *\n * `.static` declares nothing: the extension names a role and every family\n * wears it. The signature is therefore the only claim there is, which is why\n * this format reads it here rather than trusting a name.\n *\n * @param {ArrayBuffer|ArrayBufferView} input Container bytes.\n * @param {object} [options] Probe options.\n * @returns {CjsResourceProbe} Declaration-derived probe.\n */\n static isSupported(input, options = null)\n {\n return Probe(this.describe(input), false, options);\n }\n\n /**\n * Alias for canonical naming.\n *\n * @param {ArrayBuffer|ArrayBufferView} input Container bytes.\n * @param {object} [options] Probe options.\n * @returns {CjsResourceProbe} Declaration-derived probe.\n */\n static inspect(input, options = null)\n {\n return this.isSupported(input, options);\n }\n\n /**\n * Content-verified family resolution.\n *\n * Contract: docs/concepts/format-type-resolution.md. There is no declared\n * type to disagree with here — the extension is silent — so the signature is\n * both the claim and the evidence, and the resolution is always verified.\n * `preferred` names the decode route, and all three now lead into this\n * package: `CjsPickleFormat`, `CjsSqliteFormat`, and `CjsSchemaBoundFormat`\n * once the caller has the `.schema` companion to hand it.\n *\n * @param {ArrayBuffer|ArrayBufferView} input Container bytes.\n * @param {object} [options] Probe options.\n * @returns {Promise<CjsResourceProbe>} Verified probe.\n */\n static async resolveType(input, options = null)\n {\n return Probe(this.describe(input), true, options);\n }\n\n /**\n * Describe one container without decoding it or building a probe.\n *\n * @param {ArrayBuffer|ArrayBufferView} input Container bytes.\n * @returns {object} Family, payload offset, and whether this package decodes it.\n */\n static describe(input)\n {\n const bytes = Normalize(input);\n\n if (MatchesSqlite(bytes))\n {\n return Object.freeze({\n family: CJS_STATIC_FAMILIES.SQLITE,\n byteLength: bytes.byteLength,\n payloadOffset: 0,\n prefix: null,\n // Decodable outright since CjsSqliteFormat landed. This reported\n // `requires: \"sqlite\"` while a caller had to supply an engine, and was\n // the example behind the argument that a capability can depend on the\n // caller's environment - an argument that now needs a different one.\n decodable: true,\n requires: null,\n reason: \"Recognized a SQLite container.\"\n });\n }\n\n if (MatchesPickle(bytes))\n {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\n return Object.freeze({\n family: CJS_STATIC_FAMILIES.PICKLE,\n byteLength: bytes.byteLength,\n payloadOffset: PICKLE_PREFIX_BYTES,\n prefix: view.getUint32(0, true),\n decodable: true,\n requires: null,\n reason: null\n });\n }\n\n return Object.freeze({\n family: CJS_STATIC_FAMILIES.UNKNOWN,\n byteLength: bytes.byteLength,\n payloadOffset: 0,\n prefix: null,\n decodable: false,\n requires: \"schema\",\n // `decodable` is this format's own answer, and it stays false: these bytes\n // carry nothing to identify, so the family is an inference from the absence\n // of the other two signatures rather than a reading. `requires` names what\n // closes that gap - with the companion, CjsSchemaBoundFormat decodes it.\n reason: \"No signature. A schema-bound container needs its .schema companion, \"\n + \"which is YAML describing the layout. CjsSchemaBoundFormat reads it from there.\"\n });\n }\n\n /**\n * Return the decodable payload for a container, without its wrapper.\n *\n * @param {ArrayBuffer|ArrayBufferView} input Container bytes.\n * @returns {Uint8Array} Payload bytes.\n */\n static payload(input)\n {\n const bytes = Normalize(input);\n const detected = this.describe(bytes);\n\n return bytes.subarray(detected.payloadOffset);\n }\n\n\n static id = \"static\";\n static extensions = Object.freeze([ \".static\" ]);\n static type = Object.freeze([ \"data\" ]);\n static mediaTypes = Object.freeze([ \"data\" ]);\n\n /**\n * The extension is the only input this format claims.\n *\n * Naming the three families here would be a lie in the other direction: a\n * caller cannot hand this format \"a pickle\" or \"a sqlite\" and expect it to\n * route, because the whole point of the class is that `.static` declares\n * nothing and the signature has to be read. The family belongs in\n * `describe()`, which measures it, not in a static that asserts it.\n */\n static inputTypes = Object.freeze([ \"static\" ]);\n static outputTypes = Object.freeze([ \"json\", \"payload\" ]);\n static debugOutputTypes = Object.freeze([ \"raw\" ]);\n\n}\n\n/**\n * Build the shared probe payload.\n *\n * Formats report a plain probe-shaped object rather than constructing a\n * `CjsResourceProbe`, which keeps this module free of the decorated class and\n * of the build transform it needs.\n */\nfunction Probe(detected, verified, options)\n{\n return {\n format: \"static\",\n source: \"buffer\",\n supported: detected.decodable ? \"full\" : \"partial\",\n confidence: detected.family === CJS_STATIC_FAMILIES.UNKNOWN ? 0.5 : 1,\n preferred: detected.family,\n verified,\n reason: detected.reason ?? `Recognized a ${detected.family} container.`,\n variants: [ { kind: \"container\", codec: detected.family, supported: detected.decodable } ],\n metadata: verified\n ? { ...detected, declared: null, resolved: detected.family, mismatch: false }\n : detected,\n ...(options || {})\n };\n}\n\nfunction MatchesSqlite(bytes)\n{\n if (bytes.byteLength < SQLITE_SIGNATURE.length) return false;\n\n for (let index = 0; index < SQLITE_SIGNATURE.length; index++)\n {\n if (bytes[index] !== SQLITE_SIGNATURE.charCodeAt(index)) return false;\n }\n\n return true;\n}\n\nfunction MatchesPickle(bytes)\n{\n // A protocol-0 pickle opens a container then names it: \"(dp1\\n\" or \"(lp1\\n\".\n if (bytes.byteLength < PICKLE_PREFIX_BYTES + 3) return false;\n if (bytes[PICKLE_PREFIX_BYTES] !== 0x28) return false;\n\n const kind = bytes[PICKLE_PREFIX_BYTES + 1];\n\n return kind === 0x64 || kind === 0x6c;\n}\n\nfunction Normalize(input)\n{\n if (input instanceof ArrayBuffer) return new Uint8Array(input);\n\n if (ArrayBuffer.isView(input))\n {\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n }\n\n const error = new TypeError(\"A .static container must be an ArrayBuffer or a view over one.\");\n\n error.code = \"CJS_STATIC_FORMAT_INPUT_INVALID\";\n throw error;\n}\n"],"names":["SQLITE_SIGNATURE","PICKLE_PREFIX_BYTES","CJS_STATIC_FAMILIES","Object","freeze","SQLITE","PICKLE","UNKNOWN","CjsStaticFormat","isSupported","input","options","Probe","describe","inspect","resolveType","bytes","Normalize","MatchesSqlite","family","byteLength","payloadOffset","prefix","decodable","requires","reason","MatchesPickle","view","DataView","buffer","byteOffset","getUint32","payload","detected","subarray","id","extensions","type","mediaTypes","inputTypes","outputTypes","debugOutputTypes","verified","format","source","supported","confidence","preferred","variants","kind","codec","metadata","declared","resolved","mismatch","length","index","charCodeAt","ArrayBuffer","Uint8Array","isView","error","TypeError","code"],"mappings":"AACA,MAAMA,gBAAgB,GAAG,mBAAmB;AAC5C,MAAM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D,WAAW,EAAE,OAAO,IAAIC,UAAU,CAACjD,KAAK,CAAC;AAE9D,EAAA,IAAIgD,WAAW,CAACE,MAAM,CAAClD,KAAK,CAAC,EAC7B;AACE,IAAA,OAAO,IAAIiD,UAAU,CAACjD,KAAK,CAACmB,MAAM,EAAEnB,KAAK,CAACoB,UAAU,EAAEpB,KAAK,CAACU,UAAU,CAAC;AACzE,EAAA;AAEA,EAAA,MAAMyC,KAAK,GAAG,IAAIC,SAAS,CAAC,gEAAgE,CAAC;EAE7FD,KAAK,CAACE,IAAI,GAAG,iCAAiC;AAC9C,EAAA,MAAMF,KAAK;AACb;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { CjsPickleFormat } from '../pickle/CjsPickleFormat.js';
|
|
2
|
+
import { CjsSchemaBoundFormat } from '../schemabound/CjsSchemaBoundFormat.js';
|
|
3
|
+
import { CjsSqliteFormat } from '../sqlite/CjsSqliteFormat.js';
|
|
4
|
+
import { CjsStaticFormat, CJS_STATIC_FAMILIES } from './CjsStaticFormat.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads a client `.static` container of whichever family it holds.
|
|
8
|
+
*
|
|
9
|
+
* `.static` names a role rather than a format, and three unrelated containers
|
|
10
|
+
* wear the extension, so identification and decoding are separate jobs done by
|
|
11
|
+
* separate formats. `CjsStaticFormat` says which family the bytes hold and
|
|
12
|
+
* decodes nothing; these functions take that answer to the format that owns the
|
|
13
|
+
* family. Nothing routes on the extension, which proves nothing.
|
|
14
|
+
*
|
|
15
|
+
* Reading a `.static` needs the three formats that own its families, so this
|
|
16
|
+
* module imports them. That is the format depending on formats, which is what a
|
|
17
|
+
* container format that wraps other containers has to do; what a format must not
|
|
18
|
+
* do is drag the rest of the library in behind it, and nothing here reaches
|
|
19
|
+
* outside `formats/`.
|
|
20
|
+
*
|
|
21
|
+
* It is a sibling of `CjsStaticFormat` rather than part of it, which keeps the
|
|
22
|
+
* 2026-08-15 decision intact: that class dispatched to two other formats and was
|
|
23
|
+
* cut back to identifying only, so that identification is not also the routing
|
|
24
|
+
* table. Routing lives here and the identification stays clean.
|
|
25
|
+
*
|
|
26
|
+
* Nothing here is specific to one publisher or one export. Measured 2026-08-16
|
|
27
|
+
* across three publishers at builds 3466501, 3466054 and 3466057: 45 `.static`
|
|
28
|
+
* files on each, split 14 SQLite, 25 embedded-schema and 6 schema-companion,
|
|
29
|
+
* with not one file unique to a publisher and not one that changes family
|
|
30
|
+
* between them.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const CACHE_TABLE = "cache";
|
|
34
|
+
|
|
35
|
+
/** Raises a family mismatch, naming what was found and what was wanted. */
|
|
36
|
+
function FamilyError(path, found, wanted, reason) {
|
|
37
|
+
const error = new TypeError(`${path} is a ${found} .static container, not a ${wanted} one.${reason ? ` ${reason}` : ""}`);
|
|
38
|
+
error.code = "CJS_STATIC_FORMAT_FAMILY_UNSUPPORTED";
|
|
39
|
+
error.family = found;
|
|
40
|
+
error.path = path;
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reads the SQLite family into records keyed by their container key.
|
|
46
|
+
*
|
|
47
|
+
* The record shape is the container's own: a `cache` table of `key`, `value`
|
|
48
|
+
* and `time`, where every `value` is a JSON document.
|
|
49
|
+
*
|
|
50
|
+
* @param {Uint8Array|ArrayBuffer} bytes Container bytes.
|
|
51
|
+
* @param {string} [path] Logical path, for error messages.
|
|
52
|
+
* @returns {Promise<object>} Records keyed by their container key.
|
|
53
|
+
*/
|
|
54
|
+
async function ReadStaticContainer(bytes, path = ".static input") {
|
|
55
|
+
const probe = await CjsStaticFormat.resolveType(bytes);
|
|
56
|
+
if (probe.preferred !== CJS_STATIC_FAMILIES.SQLITE) {
|
|
57
|
+
throw FamilyError(path, probe.preferred, CJS_STATIC_FAMILIES.SQLITE, probe.reason);
|
|
58
|
+
}
|
|
59
|
+
const tables = CjsSqliteFormat.readJSON(bytes, {
|
|
60
|
+
tables: [CACHE_TABLE]
|
|
61
|
+
});
|
|
62
|
+
const rows = tables[CACHE_TABLE];
|
|
63
|
+
if (!Array.isArray(rows)) {
|
|
64
|
+
const error = new TypeError(`${path} has no ${CACHE_TABLE} table.`);
|
|
65
|
+
error.code = "CJS_STATIC_FORMAT_SHAPE_INVALID";
|
|
66
|
+
error.path = path;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
const records = {};
|
|
70
|
+
for (const row of rows) {
|
|
71
|
+
records[String(row.key)] = ParseRecord(row.value, row.key, path);
|
|
72
|
+
}
|
|
73
|
+
return records;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Reads the family whose schema is embedded ahead of the payload.
|
|
78
|
+
*
|
|
79
|
+
* The framing is a `uint32` schema length, the schema as a protocol-0 pickle,
|
|
80
|
+
* and then a payload in exactly the container `CjsSchemaBoundFormat` reads. It
|
|
81
|
+
* is the same format as the `.schema` sibling family; only the schema's encoding
|
|
82
|
+
* differs.
|
|
83
|
+
*
|
|
84
|
+
* **Slice the schema exactly.** Handing the whole file to a pickle reader fails,
|
|
85
|
+
* but it fails on the payload's bytes long after the schema has parsed, so the
|
|
86
|
+
* error names an opcode and points nowhere near the real boundary. That reading
|
|
87
|
+
* is what left this family classified as a separate self-describing format for
|
|
88
|
+
* as long as it was.
|
|
89
|
+
*
|
|
90
|
+
* @param {Uint8Array|ArrayBuffer} bytes Container bytes.
|
|
91
|
+
* @param {string} [path] Logical path, for error messages.
|
|
92
|
+
* @returns {object|Array} Decoded records.
|
|
93
|
+
*/
|
|
94
|
+
function ReadEmbeddedSchemaContainer(bytes, path = ".static input") {
|
|
95
|
+
const source = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
96
|
+
if (source.byteLength < 4) {
|
|
97
|
+
const error = new TypeError(`${path} is too short to carry a schema length.`);
|
|
98
|
+
error.code = "CJS_STATIC_FORMAT_SHAPE_INVALID";
|
|
99
|
+
error.path = path;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
103
|
+
const length = view.getUint32(0, true);
|
|
104
|
+
if (length <= 0 || length + 4 > source.byteLength) {
|
|
105
|
+
const error = new TypeError(`${path} does not begin with a usable schema length.`);
|
|
106
|
+
error.code = "CJS_STATIC_FORMAT_SHAPE_INVALID";
|
|
107
|
+
error.path = path;
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
return CjsSchemaBoundFormat.read(source.subarray(4 + length), {
|
|
111
|
+
schema: CjsPickleFormat.read(source.subarray(4, 4 + length))
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Reads the family whose layout lives in a `.schema` sibling.
|
|
117
|
+
*
|
|
118
|
+
* The family check is worth keeping even though the caller already fetched a
|
|
119
|
+
* `.schema` alongside the payload, because these bytes carry no signature at
|
|
120
|
+
* all - given the wrong schema they decode into plausible nonsense rather than
|
|
121
|
+
* failing, so the one cheap guard there is belongs in the path.
|
|
122
|
+
*
|
|
123
|
+
* @param {Uint8Array|ArrayBuffer} bytes Container bytes.
|
|
124
|
+
* @param {Uint8Array|ArrayBuffer|string|object} schema The sibling `.schema`.
|
|
125
|
+
* @param {string} [path] Logical path, for error messages.
|
|
126
|
+
* @returns {Promise<object|Array>} Decoded records.
|
|
127
|
+
*/
|
|
128
|
+
async function ReadSchemaBoundContainer(bytes, schema, path = ".static input") {
|
|
129
|
+
const probe = await CjsStaticFormat.resolveType(bytes);
|
|
130
|
+
|
|
131
|
+
// The schema-bound family is the one with nothing to recognize, so it is
|
|
132
|
+
// reported as `unknown` with `requires: "schema"` rather than named outright.
|
|
133
|
+
if (probe.preferred !== CJS_STATIC_FAMILIES.UNKNOWN) {
|
|
134
|
+
throw FamilyError(path, probe.preferred, "schema-bound", null);
|
|
135
|
+
}
|
|
136
|
+
return CjsSchemaBoundFormat.read(bytes, {
|
|
137
|
+
schema
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Parses one stored JSON document, naming the record that failed. */
|
|
142
|
+
function ParseRecord(value, key, path) {
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(value);
|
|
145
|
+
} catch (cause) {
|
|
146
|
+
const error = new TypeError(`${path} record ${key} is not JSON.`, {
|
|
147
|
+
cause
|
|
148
|
+
});
|
|
149
|
+
error.code = "CJS_STATIC_FORMAT_RECORD_INVALID";
|
|
150
|
+
error.key = String(key);
|
|
151
|
+
error.path = path;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { ReadEmbeddedSchemaContainer, ReadSchemaBoundContainer, ReadStaticContainer };
|
|
157
|
+
//# sourceMappingURL=staticContainers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticContainers.js","sources":["../../../../src/formats/static/staticContainers.js"],"sourcesContent":["import { CjsPickleFormat } from \"../pickle/index.js\";\nimport { CjsSchemaBoundFormat } from \"../schemabound/index.js\";\nimport { CjsSqliteFormat } from \"../sqlite/index.js\";\nimport { CJS_STATIC_FAMILIES, CjsStaticFormat } from \"./CjsStaticFormat.js\";\n\n/**\n * Reads a client `.static` container of whichever family it holds.\n *\n * `.static` names a role rather than a format, and three unrelated containers\n * wear the extension, so identification and decoding are separate jobs done by\n * separate formats. `CjsStaticFormat` says which family the bytes hold and\n * decodes nothing; these functions take that answer to the format that owns the\n * family. Nothing routes on the extension, which proves nothing.\n *\n * Reading a `.static` needs the three formats that own its families, so this\n * module imports them. That is the format depending on formats, which is what a\n * container format that wraps other containers has to do; what a format must not\n * do is drag the rest of the library in behind it, and nothing here reaches\n * outside `formats/`.\n *\n * It is a sibling of `CjsStaticFormat` rather than part of it, which keeps the\n * 2026-08-15 decision intact: that class dispatched to two other formats and was\n * cut back to identifying only, so that identification is not also the routing\n * table. Routing lives here and the identification stays clean.\n *\n * Nothing here is specific to one publisher or one export. Measured 2026-08-16\n * across three publishers at builds 3466501, 3466054 and 3466057: 45 `.static`\n * files on each, split 14 SQLite, 25 embedded-schema and 6 schema-companion,\n * with not one file unique to a publisher and not one that changes family\n * between them.\n */\n\nconst CACHE_TABLE = \"cache\";\n\n/** Raises a family mismatch, naming what was found and what was wanted. */\nfunction FamilyError(path, found, wanted, reason)\n{\n const error = new TypeError(\n `${path} is a ${found} .static container, not a ${wanted} one.${reason ? ` ${reason}` : \"\"}`,\n );\n\n error.code = \"CJS_STATIC_FORMAT_FAMILY_UNSUPPORTED\";\n error.family = found;\n error.path = path;\n\n return error;\n}\n\n/**\n * Reads the SQLite family into records keyed by their container key.\n *\n * The record shape is the container's own: a `cache` table of `key`, `value`\n * and `time`, where every `value` is a JSON document.\n *\n * @param {Uint8Array|ArrayBuffer} bytes Container bytes.\n * @param {string} [path] Logical path, for error messages.\n * @returns {Promise<object>} Records keyed by their container key.\n */\nexport async function ReadStaticContainer(bytes, path = \".static input\")\n{\n const probe = await CjsStaticFormat.resolveType(bytes);\n\n if (probe.preferred !== CJS_STATIC_FAMILIES.SQLITE)\n {\n throw FamilyError(path, probe.preferred, CJS_STATIC_FAMILIES.SQLITE, probe.reason);\n }\n\n const tables = CjsSqliteFormat.readJSON(bytes, { tables: [ CACHE_TABLE ] });\n const rows = tables[CACHE_TABLE];\n\n if (!Array.isArray(rows))\n {\n const error = new TypeError(`${path} has no ${CACHE_TABLE} table.`);\n\n error.code = \"CJS_STATIC_FORMAT_SHAPE_INVALID\";\n error.path = path;\n throw error;\n }\n\n const records = {};\n\n for (const row of rows)\n {\n records[String(row.key)] = ParseRecord(row.value, row.key, path);\n }\n\n return records;\n}\n\n/**\n * Reads the family whose schema is embedded ahead of the payload.\n *\n * The framing is a `uint32` schema length, the schema as a protocol-0 pickle,\n * and then a payload in exactly the container `CjsSchemaBoundFormat` reads. It\n * is the same format as the `.schema` sibling family; only the schema's encoding\n * differs.\n *\n * **Slice the schema exactly.** Handing the whole file to a pickle reader fails,\n * but it fails on the payload's bytes long after the schema has parsed, so the\n * error names an opcode and points nowhere near the real boundary. That reading\n * is what left this family classified as a separate self-describing format for\n * as long as it was.\n *\n * @param {Uint8Array|ArrayBuffer} bytes Container bytes.\n * @param {string} [path] Logical path, for error messages.\n * @returns {object|Array} Decoded records.\n */\nexport function ReadEmbeddedSchemaContainer(bytes, path = \".static input\")\n{\n const source = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n\n if (source.byteLength < 4)\n {\n const error = new TypeError(`${path} is too short to carry a schema length.`);\n\n error.code = \"CJS_STATIC_FORMAT_SHAPE_INVALID\";\n error.path = path;\n throw error;\n }\n\n const view = new DataView(source.buffer, source.byteOffset, source.byteLength);\n const length = view.getUint32(0, true);\n\n if (length <= 0 || length + 4 > source.byteLength)\n {\n const error = new TypeError(`${path} does not begin with a usable schema length.`);\n\n error.code = \"CJS_STATIC_FORMAT_SHAPE_INVALID\";\n error.path = path;\n throw error;\n }\n\n return CjsSchemaBoundFormat.read(source.subarray(4 + length), {\n schema: CjsPickleFormat.read(source.subarray(4, 4 + length)),\n });\n}\n\n/**\n * Reads the family whose layout lives in a `.schema` sibling.\n *\n * The family check is worth keeping even though the caller already fetched a\n * `.schema` alongside the payload, because these bytes carry no signature at\n * all - given the wrong schema they decode into plausible nonsense rather than\n * failing, so the one cheap guard there is belongs in the path.\n *\n * @param {Uint8Array|ArrayBuffer} bytes Container bytes.\n * @param {Uint8Array|ArrayBuffer|string|object} schema The sibling `.schema`.\n * @param {string} [path] Logical path, for error messages.\n * @returns {Promise<object|Array>} Decoded records.\n */\nexport async function ReadSchemaBoundContainer(bytes, schema, path = \".static input\")\n{\n const probe = await CjsStaticFormat.resolveType(bytes);\n\n // The schema-bound family is the one with nothing to recognize, so it is\n // reported as `unknown` with `requires: \"schema\"` rather than named outright.\n if (probe.preferred !== CJS_STATIC_FAMILIES.UNKNOWN)\n {\n throw FamilyError(path, probe.preferred, \"schema-bound\", null);\n }\n\n return CjsSchemaBoundFormat.read(bytes, { schema });\n}\n\n/** Parses one stored JSON document, naming the record that failed. */\nfunction ParseRecord(value, key, path)\n{\n try\n {\n return JSON.parse(value);\n }\n catch (cause)\n {\n const error = new TypeError(`${path} record ${key} is not JSON.`, { cause });\n\n error.code = \"CJS_STATIC_FORMAT_RECORD_INVALID\";\n error.key = String(key);\n error.path = path;\n throw error;\n }\n}\n"],"names":["CACHE_TABLE","FamilyError","path","found","wanted","reason","error","TypeError","code","family","ReadStaticContainer","bytes","probe","CjsStaticFormat","resolveType","preferred","CJS_STATIC_FAMILIES","SQLITE","tables","CjsSqliteFormat","readJSON","rows","Array","isArray","records","row","String","key","ParseRecord","value","ReadEmbeddedSchemaContainer","source","Uint8Array","byteLength","view","DataView","buffer","byteOffset","length","getUint32","CjsSchemaBoundFormat","read","subarray","schema","CjsPickleFormat","ReadSchemaBoundContainer","UNKNOWN","JSON","parse","cause"],"mappings":";;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,WAAW,GAAG,OAAO;;AAE3B;AACA,SAASC,WAAWA,CAACC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAChD;EACI,MAAMC,KAAK,GAAG,IAAIC,SAAS,CACvB,CAAA,EAAGL,IAAI,SAASC,KAAK,CAAA,0BAAA,EAA6BC,MAAM,CAAA,KAAA,EAAQC,MAAM,GAAG,CAAA,CAAA,EAAIA,MAAM,EAAE,GAAG,EAAE,EAC9F,CAAC;EAEDC,KAAK,CAACE,IAAI,GAAG,sCAAsC;EACnDF,KAAK,CAACG,MAAM,GAAGN,KAAK;EACpBG,KAAK,CAACJ,IAAI,GAAGA,IAAI;AAEjB,EAA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AACA;AACO,eAAeO,wBAAwBA,CAAClC,KAAK,EAAEgC,MAAM,EAAEzC,IAAI,GAAG,eAAe,EACpF;EACI,MAAMU,KAAK,GAAG,MAAMC,eAAe,CAACC,WAAW,CAACH,KAAK,CAAC;;AAEtD;AACA;AACA,EAAA,IAAIC,KAAK,CAACG,SAAS,KAAKC,mBAAmB,CAAC8B,OAAO,EACnD;IACI,MAAM7C,WAAW,CAACC,IAAI,EAAEU,KAAK,CAACG,SAAS,EAAE,cAAc,EAAE,IAAI,CAAC;AAClE,EAAA;AAEA,EAAA,OAAOyB,oBAAoB,CAACC,IAAI,CAAC9B,KAAK,EAAE;AAAEgC,IAAAA;AAAO,GAAC,CAAC;AACvD;;AAEA;AACA,SAASf,WAAWA,CAACC,KAAK,EAAEF,GAAG,EAAEzB,IAAI,EACrC;EACI,IACA;AACI,IAAA,OAAO6C,IAAI,CAACC,KAAK,CAACnB,KAAK,CAAC;EAC5B,CAAC,CACD,OAAOoB,KAAK,EACZ;IACI,MAAM3C,KAAK,GAAG,IAAIC,SAAS,CAAC,GAAGL,IAAI,CAAA,QAAA,EAAWyB,GAAG,CAAA,aAAA,CAAe,EAAE;AAAEsB,MAAAA;AAAM,KAAC,CAAC;IAE5E3C,KAAK,CAACE,IAAI,GAAG,kCAAkC;AAC/CF,IAAAA,KAAK,CAACqB,GAAG,GAAGD,MAAM,CAACC,GAAG,CAAC;IACvBrB,KAAK,CAACJ,IAAI,GAAGA,IAAI;AACjB,IAAA,MAAMI,KAAK;AACf,EAAA;AACJ;;;;"}
|
|
@@ -55,9 +55,11 @@ const GLSL_CONTAINER_BACKEND = Object.freeze({
|
|
|
55
55
|
* Builds the complete WebGL 2 effect container.
|
|
56
56
|
*
|
|
57
57
|
* @param {object} effectRes Loaded version-15 `Tr2EffectRes`.
|
|
58
|
-
* @param {object} permutationGraph Validated `
|
|
58
|
+
* @param {object} permutationGraph Validated derived `CJS_EFFECT_PERMUTATION_GRAPH` document (no chunk is stored).
|
|
59
59
|
* @param {object} backendBodySet Translated GLSL bodies.
|
|
60
60
|
* @param {object} [options] Container options.
|
|
61
|
+
* @param {number} [options.version] Container data version to emit; defaults to
|
|
62
|
+
* the current version. Independent of the source effect's version.
|
|
61
63
|
* @param {number[]|Uint8Array} [options.compilerVersion] Four version bytes.
|
|
62
64
|
* @param {string} [options.sourceHash] 32 ASCII hash characters.
|
|
63
65
|
* @returns {{bytes:Uint8Array, permutationCount:number, bodyCount:number}} Container and its body accounting.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildGlslEffectContainer.js","sources":["../../../../../src/formats/webgl/core/buildGlslEffectContainer.js"],"sourcesContent":["import {\n buildCarbonEffectContainer\n} from \"../../../format/carbonEffect/buildCarbonEffectContainer.js\";\nimport { writeGlslBackendBlock } from \"./glslBackendBlock.js\";\n\n/**\n * The WebGL 2 backend adapter for the shared Carbon container builder.\n *\n * The record layout, the permutation walk and the description mapping are shared\n * with WebGPU and live in `format/carbonEffect/buildCarbonEffectContainer.js`.\n * What remains here is the two backend-varying decisions: a program is GLSL ES\n * 3.00 text, and a pass's trailing block is the GLSL lowering data.\n *\n * There is no entry-point assertion to make. GLSL's entry point is `main` by\n * language rule rather than by our emitter's choice, so unlike WGSL there is\n * nothing a future lowerer could change.\n */\n\n/**\n * Encodes one GLSL stage program.\n *\n * @param {object} shader Translated shader record.\n * @returns {Uint8Array} Program bytes.\n */\nfunction encodeProgram(shader)\n{\n return new TextEncoder().encode(shader.code);\n}\n\n/**\n * Builds the per-pass backend block for one pass of one translated body.\n *\n * A pass whose stages added no lowering data emits no block at all rather than\n * an empty one, so the description ends where Carbon's would and the optional\n * block stays genuinely optional.\n *\n * @param {object} unit Pass translation unit.\n * @param {string} passKey Enclosing pass key.\n * @returns {Uint8Array|null} Block bytes, or null when the pass has none.\n */\nfunction encodeBackendBlock(unit, passKey)\n{\n const stages = unit.block;\n const transforms = (unit.resourceTransforms ?? [])\n .filter((transform) => transform.layoutKey === passKey);\n\n if (!stages && !transforms.length) return null;\n\n return writeGlslBackendBlock({ stages: stages ?? {}, transforms });\n}\n\n/** The WebGL encoders, as the shared builder's backend argument. */\nexport const GLSL_CONTAINER_BACKEND = Object.freeze({ encodeProgram, encodeBackendBlock });\n\n/**\n * Builds the complete WebGL 2 effect container.\n *\n * @param {object} effectRes Loaded version-15 `Tr2EffectRes`.\n * @param {object} permutationGraph Validated `
|
|
1
|
+
{"version":3,"file":"buildGlslEffectContainer.js","sources":["../../../../../src/formats/webgl/core/buildGlslEffectContainer.js"],"sourcesContent":["import {\n buildCarbonEffectContainer\n} from \"../../../format/carbonEffect/buildCarbonEffectContainer.js\";\nimport { writeGlslBackendBlock } from \"./glslBackendBlock.js\";\n\n/**\n * The WebGL 2 backend adapter for the shared Carbon container builder.\n *\n * The record layout, the permutation walk and the description mapping are shared\n * with WebGPU and live in `format/carbonEffect/buildCarbonEffectContainer.js`.\n * What remains here is the two backend-varying decisions: a program is GLSL ES\n * 3.00 text, and a pass's trailing block is the GLSL lowering data.\n *\n * There is no entry-point assertion to make. GLSL's entry point is `main` by\n * language rule rather than by our emitter's choice, so unlike WGSL there is\n * nothing a future lowerer could change.\n */\n\n/**\n * Encodes one GLSL stage program.\n *\n * @param {object} shader Translated shader record.\n * @returns {Uint8Array} Program bytes.\n */\nfunction encodeProgram(shader)\n{\n return new TextEncoder().encode(shader.code);\n}\n\n/**\n * Builds the per-pass backend block for one pass of one translated body.\n *\n * A pass whose stages added no lowering data emits no block at all rather than\n * an empty one, so the description ends where Carbon's would and the optional\n * block stays genuinely optional.\n *\n * @param {object} unit Pass translation unit.\n * @param {string} passKey Enclosing pass key.\n * @returns {Uint8Array|null} Block bytes, or null when the pass has none.\n */\nfunction encodeBackendBlock(unit, passKey)\n{\n const stages = unit.block;\n const transforms = (unit.resourceTransforms ?? [])\n .filter((transform) => transform.layoutKey === passKey);\n\n if (!stages && !transforms.length) return null;\n\n return writeGlslBackendBlock({ stages: stages ?? {}, transforms });\n}\n\n/** The WebGL encoders, as the shared builder's backend argument. */\nexport const GLSL_CONTAINER_BACKEND = Object.freeze({ encodeProgram, encodeBackendBlock });\n\n/**\n * Builds the complete WebGL 2 effect container.\n *\n * @param {object} effectRes Loaded version-15 `Tr2EffectRes`.\n * @param {object} permutationGraph Validated derived `CJS_EFFECT_PERMUTATION_GRAPH` document (no chunk is stored).\n * @param {object} backendBodySet Translated GLSL bodies.\n * @param {object} [options] Container options.\n * @param {number} [options.version] Container data version to emit; defaults to\n * the current version. Independent of the source effect's version.\n * @param {number[]|Uint8Array} [options.compilerVersion] Four version bytes.\n * @param {string} [options.sourceHash] 32 ASCII hash characters.\n * @returns {{bytes:Uint8Array, permutationCount:number, bodyCount:number}} Container and its body accounting.\n */\nexport function buildGlslEffectContainer(\n effectRes,\n permutationGraph,\n backendBodySet,\n options = {}\n)\n{\n return buildCarbonEffectContainer(\n effectRes,\n permutationGraph,\n backendBodySet,\n GLSL_CONTAINER_BACKEND,\n options\n );\n}\n\nexport default buildGlslEffectContainer;\n"],"names":["encodeProgram","shader","TextEncoder","encode","code","encodeBackendBlock","unit","passKey","stages","block","transforms","resourceTransforms","filter","transform","layoutKey","length","writeGlslBackendBlock","GLSL_CONTAINER_BACKEND","Object","freeze","buildGlslEffectContainer","effectRes","permutationGraph","backendBodySet","options","buildCarbonEffectContainer"],"mappings":";;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAACC,MAAM,EAC7B;EACI,OAAO,IAAIC,WAAW,EAAE,CAACC,MAAM,CAACF,MAAM,CAACG,IAAI,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAACC,IAAI,EAAEC,OAAO,EACzC;AACI,EAAA,MAAMC,MAAM,GAAGF,IAAI,CAACG,KAAK;AACzB,EAAA,MAAMC,UAAU,GAAG,CAACJ,IAAI,CAACK,kBAAkB,IAAI,EAAE,EAC5CC,MAAM,CAAEC,SAAS,IAAKA,SAAS,CAACC,SAAS,KAAKP,OAAO,CAAC;EAE3D,IAAI,CAACC,MAAM,IAAI,CAACE,UAAU,CAACK,MAAM,EAAE,OAAO,IAAI;AAE9C,EAAA,OAAOC,qBAAqB,CAAC;AAAER,IAAAA,MAAM,EAAEA,MAAM,IAAI,EAAE;AAAEE,IAAAA;AAAW,GAAC,CAAC;AACtE;;AAEA;MACaO,sBAAsB,GAAGC,MAAM,CAACC,MAAM,CAAC;EAAEnB,aAAa;AAAEK,EAAAA;AAAmB,CAAC;;AAEzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASe,wBAAwBA,CACpCC,SAAS,EACTC,gBAAgB,EAChBC,cAAc,EACdC,OAAO,GAAG,EAAE,EAEhB;EACI,OAAOC,0BAA0B,CAC7BJ,SAAS,EACTC,gBAAgB,EAChBC,cAAc,EACdN,sBAAsB,EACtBO,OACJ,CAAC;AACL;;;;"}
|
|
@@ -3,7 +3,7 @@ import { HlslRenderContextEnum, hlslShaderStageName } from '../../hlsl/core/tr2/
|
|
|
3
3
|
import '@carbonenginejs/runtime-utils/bytes';
|
|
4
4
|
import '../../hlsl/core/carbonDescriptionToRuntime.js';
|
|
5
5
|
import '../../../format/CjsByteReader.js';
|
|
6
|
-
import '../../../format/
|
|
6
|
+
import { resolveWriteVersion } from '../../../format/carbonEffect/carbonEffectRecords.js';
|
|
7
7
|
import { HlslEffectBindingManifest } from '../../hlsl/core/tr2/shader/HlslEffectBindingManifest.js';
|
|
8
8
|
import { buildEffectPermutationGraph, EFFECT_PERMUTATION_GRAPH_VERSION, EFFECT_PERMUTATION_GRAPH_FORMAT } from '../../../format/effect/effectPermutationGraph.js';
|
|
9
9
|
import { emitGlslWithOptions } from './helpers.js';
|
|
@@ -38,6 +38,9 @@ const PACKAGE_VERSION = "0.11.1";
|
|
|
38
38
|
*/
|
|
39
39
|
function buildEffectPackage(input, options = {}) {
|
|
40
40
|
const values = normalizeOptions(input, options);
|
|
41
|
+
// Resolved before any translation work, so an unwritable version is refused
|
|
42
|
+
// up front. What lands in `info.containerVersion` is what was emitted.
|
|
43
|
+
const containerVersion = resolveWriteVersion(options.version);
|
|
41
44
|
const effectRes = CjsHlslFormat.read(values.sourceBytes, {
|
|
42
45
|
emit: CjsHlslFormat.OUTPUT_RAW,
|
|
43
46
|
source: values.source
|
|
@@ -155,6 +158,11 @@ function buildEffectPackage(input, options = {}) {
|
|
|
155
158
|
format: "CARBON_WEBGL",
|
|
156
159
|
formatVersion: EFFECT_INFO_VERSION,
|
|
157
160
|
packageKind: values.allPermutations ? "tr2-effect-webgl-permutations" : "tr2-effect-webgl",
|
|
161
|
+
// What these bytes ARE, next to `sourceEffectVersion` below, which is
|
|
162
|
+
// what they were read FROM. The reader accepts 8..15; the writer emits
|
|
163
|
+
// 15 only, so the two are not the same number and a consumer must not
|
|
164
|
+
// infer one from the other.
|
|
165
|
+
containerVersion,
|
|
158
166
|
targetBackend: "webgl",
|
|
159
167
|
backendPackage: "@carbonenginejs/runtime-resource/formats/webgl",
|
|
160
168
|
backendPackageVersion: PACKAGE_VERSION,
|
|
@@ -270,7 +278,8 @@ function buildEffectPackage(input, options = {}) {
|
|
|
270
278
|
permutationGraph
|
|
271
279
|
});
|
|
272
280
|
const container = buildGlslEffectContainer(effectRes, permutationGraph, backendBodySet, {
|
|
273
|
-
compilerVersion: effectRes.m_compilerVersionBytes
|
|
281
|
+
compilerVersion: effectRes.m_compilerVersionBytes,
|
|
282
|
+
version: containerVersion
|
|
274
283
|
});
|
|
275
284
|
const bytes = container.bytes;
|
|
276
285
|
const inspection = inspectGlslEffectContainer(bytes, {
|