@conloca/content-api 0.1.14 → 0.1.16
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/asset-manifest.d.ts +23 -0
- package/dist/asset-manifest.d.ts.map +1 -0
- package/dist/asset-manifest.js +73 -0
- package/dist/asset-operations.d.ts +159 -0
- package/dist/asset-operations.d.ts.map +1 -0
- package/dist/asset-operations.js +736 -0
- package/dist/asset-types.d.ts +56 -0
- package/dist/asset-types.d.ts.map +1 -0
- package/dist/asset-types.js +7 -0
- package/dist/base-content-index.d.ts +57 -0
- package/dist/base-content-index.d.ts.map +1 -0
- package/dist/base-content-index.js +179 -0
- package/dist/block-index.d.ts +9 -0
- package/dist/block-index.d.ts.map +1 -0
- package/dist/block-index.js +11 -0
- package/dist/blocks.d.ts +16 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +103 -0
- package/dist/cf-access.d.ts +31 -0
- package/dist/cf-access.d.ts.map +1 -0
- package/dist/cf-access.js +66 -0
- package/dist/component-registry.d.ts +50 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +120 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts +71 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts.map +1 -0
- package/dist/component-registry.types.d.ts +11 -0
- package/dist/component-registry.types.d.ts.map +1 -0
- package/dist/component-registry.types.js +1 -0
- package/dist/content-api.interface.d.ts +64 -0
- package/dist/content-api.interface.d.ts.map +1 -0
- package/dist/content-api.interface.js +1 -0
- package/dist/content-filters.d.ts +31 -0
- package/dist/content-filters.d.ts.map +1 -0
- package/dist/content-filters.js +246 -0
- package/dist/content-index-D092_vk1.mjs +629 -0
- package/dist/content-index-D092_vk1.mjs.map +1 -0
- package/dist/content-index-D6IVMmAB.d.mts +127 -0
- package/dist/content-index-D6IVMmAB.d.mts.map +1 -0
- package/dist/content-index.d.ts +126 -0
- package/dist/content-index.d.ts.map +1 -0
- package/dist/content-index.js +418 -0
- package/dist/content-operations-DIbsxG5A.d.mts +354 -0
- package/dist/content-operations-DIbsxG5A.d.mts.map +1 -0
- package/dist/content-operations.d.ts +93 -0
- package/dist/content-operations.d.ts.map +1 -0
- package/dist/content-operations.js +275 -0
- package/dist/content-reader.d.ts +10 -0
- package/dist/content-reader.d.ts.map +1 -0
- package/dist/content-reader.js +13 -0
- package/dist/content-utils-fWNHTrPy.mjs +280 -0
- package/dist/content-utils-fWNHTrPy.mjs.map +1 -0
- package/dist/content-utils.d.ts +132 -0
- package/dist/content-utils.d.ts.map +1 -0
- package/dist/content-utils.js +352 -0
- package/dist/content-watcher.d.ts +43 -0
- package/dist/content-watcher.d.ts.map +1 -0
- package/dist/content-watcher.js +83 -0
- package/dist/data-DquNIEnQ.mjs +62 -0
- package/dist/data-DquNIEnQ.mjs.map +1 -0
- package/dist/data-index.d.ts +8 -0
- package/dist/data-index.d.ts.map +1 -0
- package/dist/data-index.js +7 -0
- package/dist/data.d.ts +43 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +103 -0
- package/dist/etag-utils.d.ts +77 -0
- package/dist/etag-utils.d.ts.map +1 -0
- package/dist/etag-utils.js +160 -0
- package/dist/filesystem-content-api-B1KIQJfk.mjs +2 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs +1620 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs.map +1 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts +134 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts.map +1 -0
- package/dist/filesystem-content-api.d.ts +135 -0
- package/dist/filesystem-content-api.d.ts.map +1 -0
- package/dist/filesystem-content-api.js +2181 -0
- package/dist/git-operations.d.ts +49 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +252 -0
- package/dist/header-parser.d.ts +37 -0
- package/dist/header-parser.d.ts.map +1 -0
- package/dist/header-parser.js +286 -0
- package/dist/in-memory-content-api.d.ts +35 -0
- package/dist/in-memory-content-api.d.ts.map +1 -0
- package/dist/in-memory-content-api.js +591 -0
- package/dist/index-DxVTFK66.d.mts +105 -0
- package/dist/index-DxVTFK66.d.mts.map +1 -0
- package/dist/index.d.mts +6 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/dist/indexing.d.mts +152 -0
- package/dist/indexing.d.mts.map +1 -0
- package/dist/indexing.d.ts +5 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/indexing.js +7 -0
- package/dist/indexing.mjs +255 -0
- package/dist/indexing.mjs.map +1 -0
- package/dist/json-whitespace-view.d.ts +32 -0
- package/dist/json-whitespace-view.d.ts.map +1 -0
- package/dist/json-whitespace-view.js +152 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +1031 -0
- package/dist/node.d.mts +28 -126
- package/dist/node.d.mts.map +1 -1
- package/dist/node.d.ts +25 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.mjs +199 -2890
- package/dist/node.mjs.map +1 -1
- package/dist/reader.d.mts +15 -0
- package/dist/reader.d.mts.map +1 -0
- package/dist/reader.d.ts +15 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +13 -0
- package/dist/reader.mjs +22 -0
- package/dist/reader.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2 -90
- package/dist/schemas/index.d.ts +102 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +87 -0
- package/dist/schemas/index.mjs +2 -70
- package/dist/schemas-CFRD0FIQ.mjs +84 -0
- package/dist/schemas-CFRD0FIQ.mjs.map +1 -0
- package/dist/{types-BUG0Cfkg.mjs → site-8oaj1Q60.mjs} +20 -222
- package/dist/site-8oaj1Q60.mjs.map +1 -0
- package/dist/site-index-B_254bCc.d.mts +136 -0
- package/dist/site-index-B_254bCc.d.mts.map +1 -0
- package/dist/site-index.d.ts +60 -0
- package/dist/site-index.d.ts.map +1 -0
- package/dist/site-index.js +287 -0
- package/dist/site.d.ts +21 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +168 -0
- package/dist/types-DOdldbfD.mjs +34 -0
- package/dist/types-DOdldbfD.mjs.map +1 -0
- package/dist/types-DjfhS272.d.mts +456 -0
- package/dist/types-DjfhS272.d.mts.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +36 -0
- package/dist/url-safe-base64.d.ts +12 -0
- package/dist/url-safe-base64.d.ts.map +1 -0
- package/dist/url-safe-base64.js +40 -0
- package/dist/url-validation.d.ts +14 -0
- package/dist/url-validation.d.ts.map +1 -0
- package/dist/url-validation.js +81 -0
- package/dist/utils/atomic-write.d.ts +6 -0
- package/dist/utils/atomic-write.d.ts.map +1 -0
- package/dist/utils/atomic-write.js +20 -0
- package/dist/utils.d.ts +46 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/vite-plugin.d.ts +12 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +29 -0
- package/dist/vxjson-qHrgLGip.mjs +555 -0
- package/dist/vxjson-qHrgLGip.mjs.map +1 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs +34 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs.map +1 -0
- package/dist/vxjson-serialize.d.mts +17 -0
- package/dist/vxjson-serialize.d.mts.map +1 -0
- package/dist/vxjson-serialize.d.ts +14 -0
- package/dist/vxjson-serialize.d.ts.map +1 -0
- package/dist/vxjson-serialize.js +50 -0
- package/dist/vxjson-serialize.mjs +2 -0
- package/dist/vxjson.d.ts +112 -0
- package/dist/vxjson.d.ts.map +1 -0
- package/dist/vxjson.js +391 -0
- package/dist/xxhash.d.ts +10 -0
- package/dist/xxhash.d.ts.map +1 -0
- package/dist/xxhash.js +31 -0
- package/package.json +88 -17
- package/dist/content-operations-BZLfJWqT.d.mts +0 -916
- package/dist/content-operations-BZLfJWqT.d.mts.map +0 -1
- package/dist/schemas/index.d.mts.map +0 -1
- package/dist/schemas/index.mjs.map +0 -1
- package/dist/types-BUG0Cfkg.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vxjson-serialize-geF6qvpn.mjs","names":[],"sources":["../src/vxjson-serialize.ts"],"sourcesContent":["import sortKeys from 'sort-keys';\nimport type { VXJSONFile } from './types';\n\n/**\n * The canonical VXJSON serializer: metadata alphabetical, content last so\n * the indexer reads all metadata from the first 4KB, 4KB position enforced.\n *\n * Lives apart from vxjson.ts on purpose: that module's ETag half imports\n * node crypto and WASM-backed xxhash at module level, which spec 14 §A90\n * bans inside registered functional cores. This file imports only sort-keys\n * and types, so the SaaS Branch DO's commit-plan core can consume it via\n * the dedicated `@conloca/content-api/vxjson-serialize` subpath — the A90\n * checker resolves workspace imports to their built output and scans it.\n */\nexport function serializeVxjson(data: VXJSONFile): string {\n // Extract content to add it last\n const { content, ...metadataFields } = data;\n\n // Ensure content field exists (required for VXJSON format)\n if (content === undefined || content === null) {\n throw new Error('VXJSON format requires a \"content\" field');\n }\n\n // Sort all metadata fields alphabetically and serialize with tab indentation\n // Use a replacer function to filter out empty strings\n const sortedMetadata = sortKeys(metadataFields, { deep: true });\n const metadataJson = JSON.stringify(\n sortedMetadata,\n (_key, value) => {\n // Filter out empty strings at any level\n if (value === '') {\n return undefined;\n }\n return value;\n },\n '\\t',\n );\n\n // Serialize content wrapped in an object to get proper indentation\n const wrappedContent = JSON.stringify({ c: sortKeys(content, { deep: true }) }, null, '\\t');\n // Extract just the content part, removing the wrapper\n // This transforms: '{\\n \"c\": {\\n \"puckData\": ...\\n }\\n}'\n // Into: '{\\n \"puckData\": ...\\n }'\n const contentJson = wrappedContent.slice(wrappedContent.indexOf(': ') + 2, -2);\n\n // Remove the closing } and newline from metadata\n const metadataWithoutClosing = metadataJson.slice(0, -2); // Remove \\n}\n const contentFieldPrefix = ',\\n\\t\"content\": ';\n const contentKeyPosition = metadataWithoutClosing.length + 1 + '\\n\\t'.length; // Position of \"content\":\n\n // VXJSON constraint: \"content\": must appear within first 4KB\n const maxContentKeyPosition = 4096 - '\"content\":'.length; // 4086\n if (contentKeyPosition > maxContentKeyPosition) {\n throw new Error(\n 'VXJSON format violation: metadata too large. ' +\n `\"content\" field would start at position ${contentKeyPosition}, ` +\n `but must start within ${maxContentKeyPosition} bytes. ` +\n `Reduce metadata size by ${contentKeyPosition - maxContentKeyPosition} bytes.`,\n );\n }\n\n // Build final JSON string efficiently\n return `${metadataWithoutClosing}${contentFieldPrefix}${contentJson}\\n}`;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,gBAAgB,MAA0B;CAExD,MAAM,EAAE,SAAS,GAAG,mBAAmB;CAGvC,IAAI,YAAY,KAAA,KAAa,YAAY,MACvC,MAAM,IAAI,MAAM,4CAA0C;CAK5D,MAAM,iBAAiB,SAAS,gBAAgB,EAAE,MAAM,KAAK,CAAC;CAC9D,MAAM,eAAe,KAAK,UACxB,iBACC,MAAM,UAAU;EAEf,IAAI,UAAU,IACZ;EAEF,OAAO;CACT,GACA,GACF;CAGA,MAAM,iBAAiB,KAAK,UAAU,EAAE,GAAG,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC,EAAE,GAAG,MAAM,GAAI;CAI1F,MAAM,cAAc,eAAe,MAAM,eAAe,QAAQ,IAAI,IAAI,GAAG,EAAE;CAG7E,MAAM,yBAAyB,aAAa,MAAM,GAAG,EAAE;CACvD,MAAM,qBAAqB;CAC3B,MAAM,qBAAqB,uBAAuB,SAAS,IAAI;CAG/D,MAAM,wBAAwB;CAC9B,IAAI,qBAAqB,uBACvB,MAAM,IAAI,MACR,wFAC6C,mBAAmB,0BACrC,sBAAsB,kCACpB,qBAAqB,sBAAsB,QAC1E;CAIF,OAAO,GAAG,yBAAyB,qBAAqB,YAAY;AACtE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { B as VXJSONFile } from "./types-DjfhS272.mjs";
|
|
2
|
+
//#region src/vxjson-serialize.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The canonical VXJSON serializer: metadata alphabetical, content last so
|
|
5
|
+
* the indexer reads all metadata from the first 4KB, 4KB position enforced.
|
|
6
|
+
*
|
|
7
|
+
* Lives apart from vxjson.ts on purpose: that module's ETag half imports
|
|
8
|
+
* node crypto and WASM-backed xxhash at module level, which spec 14 §A90
|
|
9
|
+
* bans inside registered functional cores. This file imports only sort-keys
|
|
10
|
+
* and types, so the SaaS Branch DO's commit-plan core can consume it via
|
|
11
|
+
* the dedicated `@conloca/content-api/vxjson-serialize` subpath — the A90
|
|
12
|
+
* checker resolves workspace imports to their built output and scans it.
|
|
13
|
+
*/
|
|
14
|
+
declare function serializeVxjson(data: VXJSONFile): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { serializeVxjson };
|
|
17
|
+
//# sourceMappingURL=vxjson-serialize.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vxjson-serialize.d.mts","names":[],"sources":["../src/vxjson-serialize.ts"],"mappings":";;;;;;;;;;;;;iBAcgB,gBAAgB,MAAM"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VXJSONFile } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The canonical VXJSON serializer: metadata alphabetical, content last so
|
|
4
|
+
* the indexer reads all metadata from the first 4KB, 4KB position enforced.
|
|
5
|
+
*
|
|
6
|
+
* Lives apart from vxjson.ts on purpose: that module's ETag half imports
|
|
7
|
+
* node crypto and WASM-backed xxhash at module level, which spec 14 §A90
|
|
8
|
+
* bans inside registered functional cores. This file imports only sort-keys
|
|
9
|
+
* and types, so the SaaS Branch DO's commit-plan core can consume it via
|
|
10
|
+
* the dedicated `@conloca/content-api/vxjson-serialize` subpath — the A90
|
|
11
|
+
* checker resolves workspace imports to their built output and scans it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function serializeVxjson(data: VXJSONFile): string;
|
|
14
|
+
//# sourceMappingURL=vxjson-serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vxjson-serialize.d.ts","sourceRoot":"","sources":["../src/vxjson-serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAiDxD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import sortKeys from 'sort-keys';
|
|
2
|
+
/**
|
|
3
|
+
* The canonical VXJSON serializer: metadata alphabetical, content last so
|
|
4
|
+
* the indexer reads all metadata from the first 4KB, 4KB position enforced.
|
|
5
|
+
*
|
|
6
|
+
* Lives apart from vxjson.ts on purpose: that module's ETag half imports
|
|
7
|
+
* node crypto and WASM-backed xxhash at module level, which spec 14 §A90
|
|
8
|
+
* bans inside registered functional cores. This file imports only sort-keys
|
|
9
|
+
* and types, so the SaaS Branch DO's commit-plan core can consume it via
|
|
10
|
+
* the dedicated `@conloca/content-api/vxjson-serialize` subpath — the A90
|
|
11
|
+
* checker resolves workspace imports to their built output and scans it.
|
|
12
|
+
*/
|
|
13
|
+
export function serializeVxjson(data) {
|
|
14
|
+
// Extract content to add it last
|
|
15
|
+
const { content, ...metadataFields } = data;
|
|
16
|
+
// Ensure content field exists (required for VXJSON format)
|
|
17
|
+
if (content === undefined || content === null) {
|
|
18
|
+
throw new Error('VXJSON format requires a "content" field');
|
|
19
|
+
}
|
|
20
|
+
// Sort all metadata fields alphabetically and serialize with tab indentation
|
|
21
|
+
// Use a replacer function to filter out empty strings
|
|
22
|
+
const sortedMetadata = sortKeys(metadataFields, { deep: true });
|
|
23
|
+
const metadataJson = JSON.stringify(sortedMetadata, (_key, value) => {
|
|
24
|
+
// Filter out empty strings at any level
|
|
25
|
+
if (value === '') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}, '\t');
|
|
30
|
+
// Serialize content wrapped in an object to get proper indentation
|
|
31
|
+
const wrappedContent = JSON.stringify({ c: sortKeys(content, { deep: true }) }, null, '\t');
|
|
32
|
+
// Extract just the content part, removing the wrapper
|
|
33
|
+
// This transforms: '{\n "c": {\n "puckData": ...\n }\n}'
|
|
34
|
+
// Into: '{\n "puckData": ...\n }'
|
|
35
|
+
const contentJson = wrappedContent.slice(wrappedContent.indexOf(': ') + 2, -2);
|
|
36
|
+
// Remove the closing } and newline from metadata
|
|
37
|
+
const metadataWithoutClosing = metadataJson.slice(0, -2); // Remove \n}
|
|
38
|
+
const contentFieldPrefix = ',\n\t"content": ';
|
|
39
|
+
const contentKeyPosition = metadataWithoutClosing.length + 1 + '\n\t'.length; // Position of "content":
|
|
40
|
+
// VXJSON constraint: "content": must appear within first 4KB
|
|
41
|
+
const maxContentKeyPosition = 4096 - '"content":'.length; // 4086
|
|
42
|
+
if (contentKeyPosition > maxContentKeyPosition) {
|
|
43
|
+
throw new Error('VXJSON format violation: metadata too large. ' +
|
|
44
|
+
`"content" field would start at position ${contentKeyPosition}, ` +
|
|
45
|
+
`but must start within ${maxContentKeyPosition} bytes. ` +
|
|
46
|
+
`Reduce metadata size by ${contentKeyPosition - maxContentKeyPosition} bytes.`);
|
|
47
|
+
}
|
|
48
|
+
// Build final JSON string efficiently
|
|
49
|
+
return `${metadataWithoutClosing}${contentFieldPrefix}${contentJson}\n}`;
|
|
50
|
+
}
|
package/dist/vxjson.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ContentData, ContentMeta, VXJSONFile } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate both ETags from a VXJSON buffer using views
|
|
4
|
+
* Finds the "content" field position and validates it's the last field
|
|
5
|
+
* @param buffer - The complete file buffer
|
|
6
|
+
* @returns Result with ETags or validation error
|
|
7
|
+
*/
|
|
8
|
+
declare function calculateEtagsFromVXJSONBuffer(buffer: Uint8Array, allowTruncated?: boolean): {
|
|
9
|
+
success: true;
|
|
10
|
+
metaEtag: string;
|
|
11
|
+
contentEtag?: string;
|
|
12
|
+
contentStartPos: number;
|
|
13
|
+
} | {
|
|
14
|
+
success: false;
|
|
15
|
+
error: 'content_not_last' | 'invalid_json';
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* VXJSON (Variant JSON) module for parsing and serializing VXJSON files
|
|
19
|
+
*
|
|
20
|
+
* VXJSON is a specialized JSON format that guarantees:
|
|
21
|
+
* 1. The root is always an object (never an array or primitive)
|
|
22
|
+
* 2. The "content" field always comes last in the object
|
|
23
|
+
* 3. Field order is deterministic for consistent ETag calculation
|
|
24
|
+
* 4. Metadata fits within 4085 bytes, ensuring "content" field is found within first 4KB
|
|
25
|
+
* 5. First 4KB must either be complete JSON OR end exactly with '"content":'
|
|
26
|
+
*
|
|
27
|
+
* This format enables efficient 4KB parsing where only the first 4KB of a file
|
|
28
|
+
* needs to be read to extract all metadata and locate the content position.
|
|
29
|
+
* The constraint that 4KB reads must end with '"content":' ensures reliable parsing.
|
|
30
|
+
*
|
|
31
|
+
* This module centralizes all VXJSON-specific logic including:
|
|
32
|
+
* - Parsing partial buffers (first 4KB for indexing)
|
|
33
|
+
* - Finding content position for ETag calculation
|
|
34
|
+
* - Serializing with proper field ordering and size validation
|
|
35
|
+
* - Calculating ETags from buffers
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* VXJSON static utilities for parsing and validating VXJSON files
|
|
39
|
+
*/
|
|
40
|
+
export declare class VXJSON {
|
|
41
|
+
/**
|
|
42
|
+
* Parse first 4KB of VXJSON content from buffer
|
|
43
|
+
* Used during indexing to extract metadata without loading full content
|
|
44
|
+
*
|
|
45
|
+
* VXJSON format requirement: first 4KB must either be complete JSON OR end with '"content":'
|
|
46
|
+
* This ensures reliable parsing and validation.
|
|
47
|
+
*/
|
|
48
|
+
static parse4KB(buffer: Uint8Array, bytesRead: number): {
|
|
49
|
+
id?: string;
|
|
50
|
+
created?: string;
|
|
51
|
+
modified?: string;
|
|
52
|
+
publishAt?: string;
|
|
53
|
+
unpublishAt?: string;
|
|
54
|
+
previousPathnames?: Record<string, string>;
|
|
55
|
+
pathname?: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
meta: ContentMeta;
|
|
58
|
+
content?: ContentData;
|
|
59
|
+
contentStartPos?: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Find the position of the "content" field in a VXJSON buffer
|
|
63
|
+
* Returns -1 if not found
|
|
64
|
+
*/
|
|
65
|
+
static findContentPosition(buffer: Uint8Array): number;
|
|
66
|
+
/**
|
|
67
|
+
* Calculate ETags for a VXJSON buffer
|
|
68
|
+
* Returns null if the buffer is not valid VXJSON
|
|
69
|
+
*/
|
|
70
|
+
static calculateEtagsOnly(buffer: Uint8Array): {
|
|
71
|
+
metaEtag: string;
|
|
72
|
+
contentEtag?: string;
|
|
73
|
+
} | null;
|
|
74
|
+
/**
|
|
75
|
+
* Create a dual ETag string from a VXJSON buffer
|
|
76
|
+
* Returns null if the buffer is not valid VXJSON
|
|
77
|
+
*/
|
|
78
|
+
static createEtag(buffer: Uint8Array): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Validate that a VXJSON buffer has the correct structure
|
|
81
|
+
* (content field must be last)
|
|
82
|
+
*/
|
|
83
|
+
static isValid(buffer: Uint8Array): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Parse a complete VXJSON file from string
|
|
86
|
+
*/
|
|
87
|
+
static parse(content: string): VXJSONFile;
|
|
88
|
+
/**
|
|
89
|
+
* Parse a complete VXJSON file from buffer
|
|
90
|
+
*/
|
|
91
|
+
static parseBuffer(buffer: Uint8Array): VXJSONFile;
|
|
92
|
+
/**
|
|
93
|
+
* Calculate both ETags from a VXJSON buffer using views
|
|
94
|
+
* Finds the "content" field position and validates it's the last field
|
|
95
|
+
* @param buffer - The complete file buffer
|
|
96
|
+
* @returns Result with ETags or validation error
|
|
97
|
+
*/
|
|
98
|
+
static calculateETags: typeof calculateEtagsFromVXJSONBuffer;
|
|
99
|
+
/**
|
|
100
|
+
* Calculate a simple single etag from the entire buffer
|
|
101
|
+
* Used for data files that don't follow the content-last convention
|
|
102
|
+
*/
|
|
103
|
+
static calculateSimpleEtag(buffer: Uint8Array): string;
|
|
104
|
+
/**
|
|
105
|
+
* Serialize a VXJSONFile to VXJSON format string. Delegates to the pure
|
|
106
|
+
* vxjson-serialize module — kept apart so spec-14 cores can import the
|
|
107
|
+
* serializer without this module's crypto/WASM ETag imports.
|
|
108
|
+
*/
|
|
109
|
+
static serialize(data: VXJSONFile): string;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=vxjson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vxjson.d.ts","sourceRoot":"","sources":["../src/vxjson.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA2BpE;;;;;GAKG;AACH,iBAAS,8BAA8B,CACrC,MAAM,EAAE,UAAU,EAClB,cAAc,UAAQ,GAEpB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAClF;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,GAAG,cAAc,CAAA;CAAE,CAsMjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;GAEG;AACH,qBAAa,MAAM;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CACb,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,GAChB;QACD,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,WAAW,CAAC;QAClB,OAAO,CAAC,EAAE,WAAW,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CA6EA;IAED;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAMrD;IAED;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAU/F;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAOnD;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAG1C;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAExC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAGjD;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,wCAAkC;IAEvD;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAErD;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEzC;CACF"}
|
package/dist/vxjson.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { JsonWhitespaceSkippingView } from './json-whitespace-view';
|
|
3
|
+
import { bigintToUrlSafeBase64, toUrlSafeBase64 } from './url-safe-base64';
|
|
4
|
+
import { serializeVxjson } from './vxjson-serialize';
|
|
5
|
+
import { createXxh64 } from './xxhash';
|
|
6
|
+
// Reusable TextDecoder instance - safe to reuse as it's stateless
|
|
7
|
+
const textDecoder = new TextDecoder();
|
|
8
|
+
// Pre-allocated content marker for efficiency
|
|
9
|
+
const CONTENT_MARKER = new TextEncoder().encode('"content":');
|
|
10
|
+
/**
|
|
11
|
+
* Calculate metadata ETag using xxHash from buffer view
|
|
12
|
+
* @param buffer - The file buffer view
|
|
13
|
+
* @param start - Start position (inclusive)
|
|
14
|
+
* @param end - End position (exclusive), or -1 for entire buffer
|
|
15
|
+
*/
|
|
16
|
+
function calculateMetaEtagFromBuffer(buffer, start = 0, end = -1) {
|
|
17
|
+
const actualEnd = end === -1 ? buffer.length : end;
|
|
18
|
+
const hasher = createXxh64();
|
|
19
|
+
const jsonView = new JsonWhitespaceSkippingView(hasher);
|
|
20
|
+
jsonView.updateBuffer(buffer, start, actualEnd);
|
|
21
|
+
return bigintToUrlSafeBase64(hasher.digest());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Calculate both ETags from a VXJSON buffer using views
|
|
25
|
+
* Finds the "content" field position and validates it's the last field
|
|
26
|
+
* @param buffer - The complete file buffer
|
|
27
|
+
* @returns Result with ETags or validation error
|
|
28
|
+
*/
|
|
29
|
+
function calculateEtagsFromVXJSONBuffer(buffer, allowTruncated = false) {
|
|
30
|
+
let pos = 0;
|
|
31
|
+
let depth = 0;
|
|
32
|
+
let inString = false;
|
|
33
|
+
let escaped = false;
|
|
34
|
+
let contentStartPos = -1;
|
|
35
|
+
let foundContentAtRoot = false;
|
|
36
|
+
let expectingKey = false; // At root level, are we expecting a key?
|
|
37
|
+
let expectingValue = false; // At root level, are we expecting a value?
|
|
38
|
+
let keyStart = -1;
|
|
39
|
+
// Skip whitespace and find opening brace
|
|
40
|
+
while (pos < buffer.length &&
|
|
41
|
+
(buffer[pos] === 0x20 || buffer[pos] === 0x09 || buffer[pos] === 0x0a || buffer[pos] === 0x0d)) {
|
|
42
|
+
pos++;
|
|
43
|
+
}
|
|
44
|
+
if (pos >= buffer.length || buffer[pos] !== 0x7b) {
|
|
45
|
+
// {
|
|
46
|
+
return { success: false, error: 'invalid_json' };
|
|
47
|
+
}
|
|
48
|
+
depth = 1;
|
|
49
|
+
expectingKey = true; // After { we expect a key
|
|
50
|
+
pos++;
|
|
51
|
+
// Parse JSON structure
|
|
52
|
+
while (pos < buffer.length && depth > 0) {
|
|
53
|
+
const byte = buffer[pos];
|
|
54
|
+
if (inString) {
|
|
55
|
+
if (escaped) {
|
|
56
|
+
escaped = false;
|
|
57
|
+
}
|
|
58
|
+
else if (byte === 0x5c) {
|
|
59
|
+
// backslash
|
|
60
|
+
escaped = true;
|
|
61
|
+
}
|
|
62
|
+
else if (byte === 0x22) {
|
|
63
|
+
// quote
|
|
64
|
+
inString = false;
|
|
65
|
+
// If we were in a root key, check if it's "content"
|
|
66
|
+
if (depth === 1 && expectingKey && keyStart >= 0) {
|
|
67
|
+
const keyLength = pos - keyStart + 1; // +1 to include current quote
|
|
68
|
+
// First check if we already found content and this is any key after it
|
|
69
|
+
if (foundContentAtRoot) {
|
|
70
|
+
// Check if this is another "content" key (duplicate)
|
|
71
|
+
if (keyLength === 9) {
|
|
72
|
+
let isContent = true;
|
|
73
|
+
for (let i = 0; i < 7; i++) {
|
|
74
|
+
if (buffer[keyStart + 1 + i] !== CONTENT_MARKER[i + 1]) {
|
|
75
|
+
isContent = false;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (isContent) {
|
|
80
|
+
// Duplicate content key
|
|
81
|
+
return { success: false, error: 'invalid_json' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Any other key after content is an error
|
|
85
|
+
return { success: false, error: 'content_not_last' };
|
|
86
|
+
}
|
|
87
|
+
// Check if this key is "content" (7 chars + 2 quotes = 9 total)
|
|
88
|
+
if (keyLength === 9) {
|
|
89
|
+
let isContent = true;
|
|
90
|
+
// Compare "content" part (skip opening quote)
|
|
91
|
+
for (let i = 0; i < 7; i++) {
|
|
92
|
+
if (buffer[keyStart + 1 + i] !== CONTENT_MARKER[i + 1]) {
|
|
93
|
+
isContent = false;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (isContent) {
|
|
98
|
+
// Found "content" at root level for the first time
|
|
99
|
+
foundContentAtRoot = true;
|
|
100
|
+
contentStartPos = keyStart; // Start of the quoted key
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
expectingKey = false;
|
|
104
|
+
expectingValue = true; // After a key, we expect : then value
|
|
105
|
+
keyStart = -1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Not in string
|
|
111
|
+
if (byte === 0x22) {
|
|
112
|
+
// quote
|
|
113
|
+
inString = true;
|
|
114
|
+
// Check if this is a root-level key
|
|
115
|
+
if (depth === 1 && expectingKey) {
|
|
116
|
+
keyStart = pos;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (byte === 0x7b || byte === 0x5b) {
|
|
120
|
+
// { or [
|
|
121
|
+
depth++;
|
|
122
|
+
if (depth === 1 && expectingValue) {
|
|
123
|
+
expectingValue = false; // We got our value
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (byte === 0x7d || byte === 0x5d) {
|
|
127
|
+
// } or ]
|
|
128
|
+
depth--;
|
|
129
|
+
if (depth === 0) {
|
|
130
|
+
break; // Done parsing
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (byte === 0x3a && depth === 1) {
|
|
134
|
+
// : at root level
|
|
135
|
+
if (!expectingValue) {
|
|
136
|
+
return { success: false, error: 'invalid_json' };
|
|
137
|
+
}
|
|
138
|
+
// After : we're still expecting a value
|
|
139
|
+
}
|
|
140
|
+
else if (byte === 0x2c && depth === 1) {
|
|
141
|
+
// , at root level
|
|
142
|
+
expectingKey = true;
|
|
143
|
+
expectingValue = false;
|
|
144
|
+
}
|
|
145
|
+
else if (depth === 1 && expectingValue && byte !== 0x20 && byte !== 0x09 && byte !== 0x0a && byte !== 0x0d) {
|
|
146
|
+
// Non-whitespace at root level when expecting value
|
|
147
|
+
// Could be number, true, false, null
|
|
148
|
+
expectingValue = false; // We're consuming the value
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
pos++;
|
|
152
|
+
}
|
|
153
|
+
// For truncated JSON (4KB parsing), we can still succeed if we found the content position
|
|
154
|
+
const isTruncated = depth !== 0;
|
|
155
|
+
// If JSON is truncated but we don't allow it, return invalid_json
|
|
156
|
+
if (isTruncated && !allowTruncated) {
|
|
157
|
+
return { success: false, error: 'invalid_json' };
|
|
158
|
+
}
|
|
159
|
+
if (contentStartPos === -1) {
|
|
160
|
+
// No content field found - this is valid for both complete and truncated JSON
|
|
161
|
+
return {
|
|
162
|
+
success: true,
|
|
163
|
+
metaEtag: calculateMetaEtagFromBuffer(buffer),
|
|
164
|
+
contentStartPos: -1,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// Found content field - proceed with ETag calculation
|
|
168
|
+
if (isTruncated) {
|
|
169
|
+
// For truncated JSON, we can still calculate metadata ETag up to content position
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
metaEtag: calculateMetaEtagFromBuffer(buffer, 0, contentStartPos),
|
|
173
|
+
contentStartPos,
|
|
174
|
+
// Don't calculate contentEtag for truncated content
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Find the end of metadata (before "content":)
|
|
178
|
+
let metaEnd = contentStartPos - 1;
|
|
179
|
+
while (metaEnd > 0) {
|
|
180
|
+
const byte = buffer[metaEnd];
|
|
181
|
+
if (byte === 0x2c || byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d) {
|
|
182
|
+
metaEnd--;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Hash metadata section: wrap in { } and exclude content field
|
|
189
|
+
const metaHasher = createXxh64();
|
|
190
|
+
const metaView = new JsonWhitespaceSkippingView(metaHasher);
|
|
191
|
+
const openBrace = new Uint8Array([0x7b]); // {
|
|
192
|
+
const closeBrace = new Uint8Array([0x7d]); // }
|
|
193
|
+
metaHasher.update(openBrace);
|
|
194
|
+
metaView.updateBuffer(buffer, 1, metaEnd); // Skip opening brace, stop before content
|
|
195
|
+
metaHasher.update(closeBrace);
|
|
196
|
+
const metaEtag = bigintToUrlSafeBase64(metaHasher.digest());
|
|
197
|
+
// Hash content section: wrap as {"content": ... }
|
|
198
|
+
const contentHasher = createHash('sha256');
|
|
199
|
+
const contentView = new JsonWhitespaceSkippingView(contentHasher);
|
|
200
|
+
contentHasher.update(openBrace); // {
|
|
201
|
+
contentView.updateBuffer(buffer, contentStartPos, buffer.length - 1); // content field to end, exclude final }
|
|
202
|
+
contentHasher.update(closeBrace); // }
|
|
203
|
+
const contentEtag = toUrlSafeBase64(contentHasher.digest());
|
|
204
|
+
return {
|
|
205
|
+
success: true,
|
|
206
|
+
metaEtag,
|
|
207
|
+
contentEtag,
|
|
208
|
+
contentStartPos,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* VXJSON (Variant JSON) module for parsing and serializing VXJSON files
|
|
213
|
+
*
|
|
214
|
+
* VXJSON is a specialized JSON format that guarantees:
|
|
215
|
+
* 1. The root is always an object (never an array or primitive)
|
|
216
|
+
* 2. The "content" field always comes last in the object
|
|
217
|
+
* 3. Field order is deterministic for consistent ETag calculation
|
|
218
|
+
* 4. Metadata fits within 4085 bytes, ensuring "content" field is found within first 4KB
|
|
219
|
+
* 5. First 4KB must either be complete JSON OR end exactly with '"content":'
|
|
220
|
+
*
|
|
221
|
+
* This format enables efficient 4KB parsing where only the first 4KB of a file
|
|
222
|
+
* needs to be read to extract all metadata and locate the content position.
|
|
223
|
+
* The constraint that 4KB reads must end with '"content":' ensures reliable parsing.
|
|
224
|
+
*
|
|
225
|
+
* This module centralizes all VXJSON-specific logic including:
|
|
226
|
+
* - Parsing partial buffers (first 4KB for indexing)
|
|
227
|
+
* - Finding content position for ETag calculation
|
|
228
|
+
* - Serializing with proper field ordering and size validation
|
|
229
|
+
* - Calculating ETags from buffers
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
* VXJSON static utilities for parsing and validating VXJSON files
|
|
233
|
+
*/
|
|
234
|
+
export class VXJSON {
|
|
235
|
+
/**
|
|
236
|
+
* Parse first 4KB of VXJSON content from buffer
|
|
237
|
+
* Used during indexing to extract metadata without loading full content
|
|
238
|
+
*
|
|
239
|
+
* VXJSON format requirement: first 4KB must either be complete JSON OR end with '"content":'
|
|
240
|
+
* This ensures reliable parsing and validation.
|
|
241
|
+
*/
|
|
242
|
+
static parse4KB(buffer, bytesRead) {
|
|
243
|
+
// Complete JSON (either small file or ends with })
|
|
244
|
+
if (bytesRead < 4096 || buffer[bytesRead - 1] === 0x7d) {
|
|
245
|
+
// 0x7D = '}'
|
|
246
|
+
const partialContent = textDecoder.decode(buffer.subarray(0, bytesRead));
|
|
247
|
+
const data = JSON.parse(partialContent);
|
|
248
|
+
// Find content position for ETag calculation
|
|
249
|
+
let contentStartPos = -1;
|
|
250
|
+
if (data.content !== undefined) {
|
|
251
|
+
const etagResult = calculateEtagsFromVXJSONBuffer(buffer.subarray(0, bytesRead));
|
|
252
|
+
if (etagResult.success) {
|
|
253
|
+
contentStartPos = etagResult.contentStartPos;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
id: data.id,
|
|
258
|
+
created: data.created,
|
|
259
|
+
modified: data.modified,
|
|
260
|
+
publishAt: data.publishAt,
|
|
261
|
+
unpublishAt: data.unpublishAt,
|
|
262
|
+
previousPathnames: data.previousPathnames,
|
|
263
|
+
pathname: data.pathname,
|
|
264
|
+
name: data.name,
|
|
265
|
+
meta: data.meta || {},
|
|
266
|
+
content: data.content,
|
|
267
|
+
contentStartPos,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
// Truncated 4KB read - use calculateETags to validate and find content position
|
|
271
|
+
const etagResult = calculateEtagsFromVXJSONBuffer(buffer.subarray(0, bytesRead), true); // Allow truncated for 4KB parsing
|
|
272
|
+
if (!etagResult.success) {
|
|
273
|
+
throw new Error(`Invalid VXJSON format: ${etagResult.error}. This violates the VXJSON specification.`);
|
|
274
|
+
}
|
|
275
|
+
const contentStartPos = etagResult.contentStartPos;
|
|
276
|
+
// Find end of metadata by working backwards from content position
|
|
277
|
+
let metadataEnd = contentStartPos;
|
|
278
|
+
while (metadataEnd > 0) {
|
|
279
|
+
const byte = buffer[metadataEnd - 1];
|
|
280
|
+
if (byte === 0x2c) {
|
|
281
|
+
// comma
|
|
282
|
+
metadataEnd--;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
if (byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d) {
|
|
286
|
+
// whitespace
|
|
287
|
+
metadataEnd--;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Create metadata-only JSON by adding closing brace
|
|
294
|
+
const metadataBuffer = new Uint8Array(metadataEnd + 1);
|
|
295
|
+
metadataBuffer.set(buffer.subarray(0, metadataEnd));
|
|
296
|
+
metadataBuffer[metadataEnd] = 0x7d; // }
|
|
297
|
+
const partialContent = textDecoder.decode(metadataBuffer);
|
|
298
|
+
const data = JSON.parse(partialContent);
|
|
299
|
+
return {
|
|
300
|
+
id: data.id,
|
|
301
|
+
created: data.created,
|
|
302
|
+
modified: data.modified,
|
|
303
|
+
publishAt: data.publishAt,
|
|
304
|
+
unpublishAt: data.unpublishAt,
|
|
305
|
+
previousPathnames: data.previousPathnames,
|
|
306
|
+
pathname: data.pathname,
|
|
307
|
+
name: data.name,
|
|
308
|
+
meta: data.meta || {},
|
|
309
|
+
contentStartPos,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Find the position of the "content" field in a VXJSON buffer
|
|
314
|
+
* Returns -1 if not found
|
|
315
|
+
*/
|
|
316
|
+
static findContentPosition(buffer) {
|
|
317
|
+
const etagResult = calculateEtagsFromVXJSONBuffer(buffer);
|
|
318
|
+
if (etagResult.success) {
|
|
319
|
+
return etagResult.contentStartPos;
|
|
320
|
+
}
|
|
321
|
+
return -1;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Calculate ETags for a VXJSON buffer
|
|
325
|
+
* Returns null if the buffer is not valid VXJSON
|
|
326
|
+
*/
|
|
327
|
+
static calculateEtagsOnly(buffer) {
|
|
328
|
+
const result = calculateEtagsFromVXJSONBuffer(buffer);
|
|
329
|
+
if (!result.success) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
metaEtag: result.metaEtag,
|
|
334
|
+
contentEtag: result.contentEtag,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Create a dual ETag string from a VXJSON buffer
|
|
339
|
+
* Returns null if the buffer is not valid VXJSON
|
|
340
|
+
*/
|
|
341
|
+
static createEtag(buffer) {
|
|
342
|
+
const etags = VXJSON.calculateEtagsOnly(buffer);
|
|
343
|
+
if (!etags) {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
return etags.contentEtag ? `${etags.metaEtag}.${etags.contentEtag}` : etags.metaEtag;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Validate that a VXJSON buffer has the correct structure
|
|
350
|
+
* (content field must be last)
|
|
351
|
+
*/
|
|
352
|
+
static isValid(buffer) {
|
|
353
|
+
const result = calculateEtagsFromVXJSONBuffer(buffer);
|
|
354
|
+
return result.success;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Parse a complete VXJSON file from string
|
|
358
|
+
*/
|
|
359
|
+
static parse(content) {
|
|
360
|
+
return JSON.parse(content);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Parse a complete VXJSON file from buffer
|
|
364
|
+
*/
|
|
365
|
+
static parseBuffer(buffer) {
|
|
366
|
+
const content = textDecoder.decode(buffer);
|
|
367
|
+
return VXJSON.parse(content);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Calculate both ETags from a VXJSON buffer using views
|
|
371
|
+
* Finds the "content" field position and validates it's the last field
|
|
372
|
+
* @param buffer - The complete file buffer
|
|
373
|
+
* @returns Result with ETags or validation error
|
|
374
|
+
*/
|
|
375
|
+
static calculateETags = calculateEtagsFromVXJSONBuffer;
|
|
376
|
+
/**
|
|
377
|
+
* Calculate a simple single etag from the entire buffer
|
|
378
|
+
* Used for data files that don't follow the content-last convention
|
|
379
|
+
*/
|
|
380
|
+
static calculateSimpleEtag(buffer) {
|
|
381
|
+
return calculateMetaEtagFromBuffer(buffer);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Serialize a VXJSONFile to VXJSON format string. Delegates to the pure
|
|
385
|
+
* vxjson-serialize module — kept apart so spec-14 cores can import the
|
|
386
|
+
* serializer without this module's crypto/WASM ETag imports.
|
|
387
|
+
*/
|
|
388
|
+
static serialize(data) {
|
|
389
|
+
return serializeVxjson(data);
|
|
390
|
+
}
|
|
391
|
+
}
|
package/dist/xxhash.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Streaming XXH64 hasher: the `update`/`digest` contract the etag pipeline drives. */
|
|
2
|
+
export interface Xxh64Hasher {
|
|
3
|
+
update(input: Uint8Array): Xxh64Hasher;
|
|
4
|
+
digest(): bigint;
|
|
5
|
+
}
|
|
6
|
+
/** Stateful streaming XXH64 hasher (seed 0). */
|
|
7
|
+
export declare function createXxh64(): Xxh64Hasher;
|
|
8
|
+
/** One-shot XXH64 of a buffer (seed 0). */
|
|
9
|
+
export declare function xxh64(input: Uint8Array): bigint;
|
|
10
|
+
//# sourceMappingURL=xxhash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xxhash.d.ts","sourceRoot":"","sources":["../src/xxhash.ts"],"names":[],"mappings":"AAuBA,uFAAuF;AACvF,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAAC;IACvC,MAAM,IAAI,MAAM,CAAC;CAClB;AAID,gDAAgD;AAChD,wBAAgB,WAAW,IAAI,WAAW,CAEzC;AAED,2CAA2C;AAC3C,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE/C"}
|
package/dist/xxhash.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xxHash-64 for content etags — the single hashing chokepoint for this package.
|
|
3
|
+
*
|
|
4
|
+
* Uses `xxhash-wasm`, the one xxHash build with a purpose-built `workerd` export
|
|
5
|
+
* (the WASM is imported as a module, not instantiated from an ArrayBuffer —
|
|
6
|
+
* Cloudflare forbids the latter). It runs identically in workerd, the browser
|
|
7
|
+
* (SPA editor), and Node/bun, so every consumer shares one implementation with
|
|
8
|
+
* no per-target alias or shim.
|
|
9
|
+
*
|
|
10
|
+
* The WASM instance is created ONCE via top-level await, so the exported hashers
|
|
11
|
+
* are SYNCHRONOUS — the etag pipeline (`JsonWhitespaceSkippingView`) streams
|
|
12
|
+
* bytes through `update()` and reads `digest()` synchronously, and ESM guarantees
|
|
13
|
+
* this module is fully evaluated (WASM ready) before any importer runs.
|
|
14
|
+
*
|
|
15
|
+
* This module performs exactly one top-level WASM instantiation, avoiding
|
|
16
|
+
* workerd issue #1529, which requires two top-level WASM instantiations.
|
|
17
|
+
*
|
|
18
|
+
* XXH64, not XXH3 (xxhash-wasm ships XXH32/64): etags are opaque cache
|
|
19
|
+
* validators, so the exact xxHash variant is irrelevant — only speed and a
|
|
20
|
+
* stable 64-bit fingerprint matter.
|
|
21
|
+
*/
|
|
22
|
+
import xxhash from 'xxhash-wasm';
|
|
23
|
+
const api = await xxhash();
|
|
24
|
+
/** Stateful streaming XXH64 hasher (seed 0). */
|
|
25
|
+
export function createXxh64() {
|
|
26
|
+
return api.create64(0n);
|
|
27
|
+
}
|
|
28
|
+
/** One-shot XXH64 of a buffer (seed 0). */
|
|
29
|
+
export function xxh64(input) {
|
|
30
|
+
return api.h64Raw(input);
|
|
31
|
+
}
|