@hot-updater/bsdiff 0.28.0 → 0.29.1

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/assets/hdiff.wasm CHANGED
Binary file
package/dist/bun.js CHANGED
@@ -2,7 +2,6 @@ import { HdiffError } from "./errors.js";
2
2
  import { hdiff } from "./hdiff.js";
3
3
  import { installPrecompiledWasm } from "./precompiled.js";
4
4
  import { readFileSync } from "node:fs";
5
-
6
5
  //#region src/bun.ts
7
6
  const HDIFF_WASM_URL = new URL("../assets/hdiff.wasm", import.meta.url);
8
7
  installPrecompiledWasm(loadBunWasmModule());
@@ -13,7 +12,7 @@ function loadBunWasmModule() {
13
12
  throw new HdiffError("PATCH_FAILED", `Failed to load hdiff.wasm for Bun runtime: ${HDIFF_WASM_URL.toString()}`);
14
13
  }
15
14
  }
16
-
17
15
  //#endregion
18
16
  export { HdiffError, hdiff };
17
+
19
18
  //# sourceMappingURL=bun.js.map
package/dist/bun.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bun.js","names":[],"sources":["../src/bun.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadBunWasmModule());\n\nfunction loadBunWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Bun runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,mBAAmB,CAAC;AAE3C,SAAS,oBAAwC;AAC/C,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,8CAA8C,eAAe,UAAU,GACxE"}
1
+ {"version":3,"file":"bun.js","names":[],"sources":["../src/bun.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadBunWasmModule());\n\nfunction loadBunWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Bun runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,mBAAmB,CAAC;AAE3C,SAAS,oBAAwC;AAC/C,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,8CAA8C,eAAe,UAAU,GACxE"}
package/dist/deno.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { HdiffError } from "./errors.js";
2
+ import { toUint8Array } from "./internal/bytes.js";
2
3
  import { hdiff } from "./hdiff.js";
3
4
  import { installPrecompiledWasm } from "./precompiled.js";
4
-
5
5
  //#region src/deno.ts
6
6
  const HDIFF_WASM_URL = new URL("../assets/hdiff.wasm", import.meta.url);
7
7
  installPrecompiledWasm(loadDenoWasmModule());
@@ -9,12 +9,12 @@ function loadDenoWasmModule() {
9
9
  const deno = globalThis.Deno;
10
10
  if (!deno || typeof deno.readFileSync !== "function") throw new HdiffError("PATCH_FAILED", "Deno runtime does not expose Deno.readFileSync");
11
11
  try {
12
- return new WebAssembly.Module(deno.readFileSync(HDIFF_WASM_URL));
12
+ return new WebAssembly.Module(toUint8Array(deno.readFileSync(HDIFF_WASM_URL)));
13
13
  } catch {
14
14
  throw new HdiffError("PATCH_FAILED", `Failed to load hdiff.wasm for Deno runtime: ${HDIFF_WASM_URL.toString()}`);
15
15
  }
16
16
  }
17
-
18
17
  //#endregion
19
18
  export { HdiffError, hdiff };
19
+
20
20
  //# sourceMappingURL=deno.js.map
package/dist/deno.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"deno.js","names":[],"sources":["../src/deno.ts"],"sourcesContent":["import { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadDenoWasmModule());\n\nfunction loadDenoWasmModule(): WebAssembly.Module {\n const deno = (\n globalThis as {\n Deno?: { readFileSync?: (path: string | URL) => Uint8Array };\n }\n ).Deno;\n if (!deno || typeof deno.readFileSync !== \"function\") {\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"Deno runtime does not expose Deno.readFileSync\",\n );\n }\n\n try {\n return new WebAssembly.Module(deno.readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Deno runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAIA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;CAChD,MAAM,OACJ,WAGA;AACF,KAAI,CAAC,QAAQ,OAAO,KAAK,iBAAiB,WACxC,OAAM,IAAI,WACR,gBACA,iDACD;AAGH,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,KAAK,aAAa,eAAe,CAAC;SAC1D;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
1
+ {"version":3,"file":"deno.js","names":[],"sources":["../src/deno.ts"],"sourcesContent":["import { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { toUint8Array } from \"./internal/bytes.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadDenoWasmModule());\n\nfunction loadDenoWasmModule(): WebAssembly.Module {\n const deno = (\n globalThis as {\n Deno?: {\n readFileSync?: (path: string | URL) => Uint8Array<ArrayBufferLike>;\n };\n }\n ).Deno;\n if (!deno || typeof deno.readFileSync !== \"function\") {\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"Deno runtime does not expose Deno.readFileSync\",\n );\n }\n\n try {\n return new WebAssembly.Module(\n toUint8Array(deno.readFileSync(HDIFF_WASM_URL)),\n );\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Deno runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;CAChD,MAAM,OACJ,WAKA;AACF,KAAI,CAAC,QAAQ,OAAO,KAAK,iBAAiB,WACxC,OAAM,IAAI,WACR,gBACA,iDACD;AAGH,KAAI;AACF,SAAO,IAAI,YAAY,OACrB,aAAa,KAAK,aAAa,eAAe,CAAC,CAChD;SACK;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
package/dist/errors.js CHANGED
@@ -7,7 +7,7 @@ var HdiffError = class extends Error {
7
7
  this.code = code;
8
8
  }
9
9
  };
10
-
11
10
  //#endregion
12
11
  export { HdiffError };
12
+
13
13
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type HdiffErrorCode =\n | \"INVALID_HBC\"\n | \"NON_EXECUTION_FORM\"\n | \"BYTECODE_VERSION_MISMATCH\"\n | \"PATCH_FAILED\";\n\nexport class HdiffError extends Error {\n public readonly code: HdiffErrorCode;\n\n public constructor(\n code: HdiffErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"HdiffError\";\n this.code = code;\n }\n}\n"],"mappings":";AAMA,IAAa,aAAb,cAAgC,MAAM;CACpC,AAAgB;CAEhB,AAAO,YACL,MACA,SACA,SACA;AACA,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,OAAO"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type HdiffErrorCode =\n | \"INVALID_HBC\"\n | \"NON_EXECUTION_FORM\"\n | \"BYTECODE_VERSION_MISMATCH\"\n | \"PATCH_FAILED\";\n\nexport class HdiffError extends Error {\n public readonly code: HdiffErrorCode;\n\n public constructor(\n code: HdiffErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"HdiffError\";\n this.code = code;\n }\n}\n"],"mappings":";AAMA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YACE,MACA,SACA,SACA;AACA,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,OAAO"}
package/dist/hdiff.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { BytesLike } from "./internal/bytes.js";
1
+ import { Bytes, BytesLike } from "./internal/bytes.js";
2
2
 
3
3
  //#region src/hdiff.d.ts
4
- declare function hdiff(base: BytesLike, next: BytesLike): Promise<Uint8Array>;
4
+ declare function hdiff(base: BytesLike, next: BytesLike): Promise<Bytes>;
5
5
  //#endregion
6
6
  export { hdiff };
7
7
  //# sourceMappingURL=hdiff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hdiff.d.ts","names":[],"sources":["../src/hdiff.ts"],"mappings":";;;iBAKsB,KAAA,CACpB,IAAA,EAAM,SAAA,EACN,IAAA,EAAM,SAAA,GACL,OAAA,CAAQ,UAAA"}
1
+ {"version":3,"file":"hdiff.d.ts","names":[],"sources":["../src/hdiff.ts"],"mappings":";;;iBAKsB,KAAA,CAAM,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,SAAA,GAAY,OAAA,CAAQ,KAAA"}
package/dist/hdiff.js CHANGED
@@ -2,7 +2,6 @@ import { HdiffError } from "./errors.js";
2
2
  import { createBsdiffPatch } from "./internal/bsdiff.js";
3
3
  import { toUint8Array } from "./internal/bytes.js";
4
4
  import { validateExecutionHbc } from "./internal/hermes-validate.js";
5
-
6
5
  //#region src/hdiff.ts
7
6
  async function hdiff(base, next) {
8
7
  const baseBytes = toUint8Array(base);
@@ -12,7 +11,7 @@ async function hdiff(base, next) {
12
11
  if (baseMeta.version !== nextMeta.version) throw new HdiffError("BYTECODE_VERSION_MISMATCH", `HBC version mismatch: base=${baseMeta.version}, next=${nextMeta.version}`);
13
12
  return await createBsdiffPatch(baseBytes, nextBytes);
14
13
  }
15
-
16
14
  //#endregion
17
15
  export { hdiff };
16
+
18
17
  //# sourceMappingURL=hdiff.js.map
package/dist/hdiff.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hdiff.js","names":[],"sources":["../src/hdiff.ts"],"sourcesContent":["import { HdiffError } from \"./errors.js\";\nimport { createBsdiffPatch } from \"./internal/bsdiff.js\";\nimport { type BytesLike, toUint8Array } from \"./internal/bytes.js\";\nimport { validateExecutionHbc } from \"./internal/hermes-validate.js\";\n\nexport async function hdiff(\n base: BytesLike,\n next: BytesLike,\n): Promise<Uint8Array> {\n const baseBytes = toUint8Array(base);\n const nextBytes = toUint8Array(next);\n\n const baseMeta = await validateExecutionHbc(baseBytes);\n const nextMeta = await validateExecutionHbc(nextBytes);\n\n if (baseMeta.version !== nextMeta.version) {\n throw new HdiffError(\n \"BYTECODE_VERSION_MISMATCH\",\n `HBC version mismatch: base=${baseMeta.version}, next=${nextMeta.version}`,\n );\n }\n\n return await createBsdiffPatch(baseBytes, nextBytes);\n}\n"],"mappings":";;;;;;AAKA,eAAsB,MACpB,MACA,MACqB;CACrB,MAAM,YAAY,aAAa,KAAK;CACpC,MAAM,YAAY,aAAa,KAAK;CAEpC,MAAM,WAAW,MAAM,qBAAqB,UAAU;CACtD,MAAM,WAAW,MAAM,qBAAqB,UAAU;AAEtD,KAAI,SAAS,YAAY,SAAS,QAChC,OAAM,IAAI,WACR,6BACA,8BAA8B,SAAS,QAAQ,SAAS,SAAS,UAClE;AAGH,QAAO,MAAM,kBAAkB,WAAW,UAAU"}
1
+ {"version":3,"file":"hdiff.js","names":[],"sources":["../src/hdiff.ts"],"sourcesContent":["import { HdiffError } from \"./errors.js\";\nimport { createBsdiffPatch } from \"./internal/bsdiff.js\";\nimport { type Bytes, type BytesLike, toUint8Array } from \"./internal/bytes.js\";\nimport { validateExecutionHbc } from \"./internal/hermes-validate.js\";\n\nexport async function hdiff(base: BytesLike, next: BytesLike): Promise<Bytes> {\n const baseBytes = toUint8Array(base);\n const nextBytes = toUint8Array(next);\n\n const baseMeta = await validateExecutionHbc(baseBytes);\n const nextMeta = await validateExecutionHbc(nextBytes);\n\n if (baseMeta.version !== nextMeta.version) {\n throw new HdiffError(\n \"BYTECODE_VERSION_MISMATCH\",\n `HBC version mismatch: base=${baseMeta.version}, next=${nextMeta.version}`,\n );\n }\n\n return await createBsdiffPatch(baseBytes, nextBytes);\n}\n"],"mappings":";;;;;AAKA,eAAsB,MAAM,MAAiB,MAAiC;CAC5E,MAAM,YAAY,aAAa,KAAK;CACpC,MAAM,YAAY,aAAa,KAAK;CAEpC,MAAM,WAAW,MAAM,qBAAqB,UAAU;CACtD,MAAM,WAAW,MAAM,qBAAqB,UAAU;AAEtD,KAAI,SAAS,YAAY,SAAS,QAChC,OAAM,IAAI,WACR,6BACA,8BAA8B,SAAS,QAAQ,SAAS,SAAS,UAClE;AAGH,QAAO,MAAM,kBAAkB,WAAW,UAAU"}
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HdiffError } from "./errors.js";
2
2
  import { hdiff } from "./hdiff.js";
3
3
  import "./node.js";
4
-
5
- export { HdiffError, hdiff };
4
+ export { HdiffError, hdiff };
@@ -1,6 +1,8 @@
1
+ import { Bytes } from "./bytes.js";
2
+
1
3
  //#region src/internal/bsdiff.d.ts
2
- declare function createBsdiffPatch(base: Uint8Array, next: Uint8Array): Promise<Uint8Array>;
3
- declare function applyBsdiffPatch(base: Uint8Array, patch: Uint8Array): Promise<Uint8Array>;
4
+ declare function createBsdiffPatch(base: Bytes, next: Bytes): Promise<Bytes>;
5
+ declare function applyBsdiffPatch(base: Bytes, patch: Bytes): Promise<Bytes>;
4
6
  //#endregion
5
7
  export { applyBsdiffPatch, createBsdiffPatch };
6
8
  //# sourceMappingURL=bsdiff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bsdiff.d.ts","names":[],"sources":["../../src/internal/bsdiff.ts"],"mappings":";iBAgCsB,iBAAA,CACpB,IAAA,EAAM,UAAA,EACN,IAAA,EAAM,UAAA,GACL,OAAA,CAAQ,UAAA;AAAA,iBAkBW,gBAAA,CACpB,IAAA,EAAM,UAAA,EACN,KAAA,EAAO,UAAA,GACN,OAAA,CAAQ,UAAA"}
1
+ {"version":3,"file":"bsdiff.d.ts","names":[],"sources":["../../src/internal/bsdiff.ts"],"mappings":";;;iBAiCsB,iBAAA,CACpB,IAAA,EAAM,KAAA,EACN,IAAA,EAAM,KAAA,GACL,OAAA,CAAQ,KAAA;AAAA,iBAkBW,gBAAA,CACpB,IAAA,EAAM,KAAA,EACN,KAAA,EAAO,KAAA,GACN,OAAA,CAAQ,KAAA"}
@@ -1,5 +1,4 @@
1
1
  import { HdiffError } from "../errors.js";
2
-
3
2
  //#region src/internal/bsdiff.ts
4
3
  var BsdiffStatus = /* @__PURE__ */ function(BsdiffStatus) {
5
4
  BsdiffStatus[BsdiffStatus["OK"] = 0] = "OK";
@@ -97,7 +96,7 @@ function asBsdiffExports(source) {
97
96
  if (isWasmMemoryLike(maybe.memory) && typeof maybe.alloc === "function" && typeof maybe.dealloc === "function" && typeof maybe.create_patch === "function" && typeof maybe.apply_patch === "function" && typeof maybe.output_ptr === "function" && typeof maybe.output_len === "function" && typeof maybe.free_output === "function") return maybe;
98
97
  }
99
98
  }
100
-
101
99
  //#endregion
102
100
  export { applyBsdiffPatch, createBsdiffPatch };
101
+
103
102
  //# sourceMappingURL=bsdiff.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bsdiff.js","names":[],"sources":["../../src/internal/bsdiff.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\n\ntype BsdiffExports = {\n memory: WebAssembly.Memory;\n alloc: (len: number) => number;\n dealloc: (ptr: number, len: number) => void;\n create_patch: (\n basePtr: number,\n baseLen: number,\n nextPtr: number,\n nextLen: number,\n ) => number;\n apply_patch: (\n basePtr: number,\n baseLen: number,\n patchPtr: number,\n patchLen: number,\n ) => number;\n output_ptr: () => number;\n output_len: () => number;\n free_output: () => void;\n};\n\nenum BsdiffStatus {\n OK = 0,\n INVALID_INPUT = 1,\n PATCH_FAILED = 2,\n INVALID_PATCH = 3,\n}\n\nlet wasmPromise: Promise<BsdiffExports> | undefined;\n\nexport async function createBsdiffPatch(\n base: Uint8Array,\n next: Uint8Array,\n): Promise<Uint8Array> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n next,\n (basePtr, baseLen, nextPtr, nextLen) =>\n wasm.create_patch(basePtr, baseLen, nextPtr, nextLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapPatchError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nexport async function applyBsdiffPatch(\n base: Uint8Array,\n patch: Uint8Array,\n): Promise<Uint8Array> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n patch,\n (basePtr, baseLen, patchPtr, patchLen) =>\n wasm.apply_patch(basePtr, baseLen, patchPtr, patchLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapApplyError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nfunction runBinaryOperation(\n wasm: BsdiffExports,\n left: Uint8Array,\n right: Uint8Array,\n run: (\n leftPtr: number,\n leftLen: number,\n rightPtr: number,\n rightLen: number,\n ) => number,\n): number {\n const leftPtr = wasm.alloc(left.byteLength);\n const rightPtr = wasm.alloc(right.byteLength);\n\n try {\n writeBytesToMemory(wasm.memory, leftPtr, left);\n writeBytesToMemory(wasm.memory, rightPtr, right);\n return run(leftPtr, left.byteLength, rightPtr, right.byteLength);\n } finally {\n if (left.byteLength > 0) {\n wasm.dealloc(leftPtr, left.byteLength);\n }\n if (right.byteLength > 0) {\n wasm.dealloc(rightPtr, right.byteLength);\n }\n }\n}\n\nfunction writeBytesToMemory(\n memory: WebAssembly.Memory,\n ptr: number,\n bytes: Uint8Array,\n): void {\n if (bytes.byteLength === 0) {\n return;\n }\n new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes);\n}\n\nfunction readAndFreeOutput(wasm: BsdiffExports): Uint8Array {\n const outPtr = wasm.output_ptr();\n const outLen = wasm.output_len();\n\n if (outLen === 0) {\n wasm.free_output();\n return new Uint8Array();\n }\n\n const output = new Uint8Array(wasm.memory.buffer, outPtr, outLen);\n const copied = new Uint8Array(output);\n wasm.free_output();\n return copied;\n}\n\nfunction mapPatchError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bsdiff wasm\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\"PATCH_FAILED\", \"Failed to generate BSDIFF40 patch\");\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-validation status while creating patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bsdiff wasm status: ${status}`,\n );\n}\n\nfunction mapApplyError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bspatch wasm\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\"PATCH_FAILED\", \"Invalid BSDIFF40 patch bytes\");\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-generation status while applying patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bspatch wasm status: ${status}`,\n );\n}\n\nasync function getBsdiffWasm(): Promise<BsdiffExports> {\n wasmPromise ??= loadBsdiffWasm();\n return wasmPromise;\n}\n\nasync function loadBsdiffWasm(): Promise<BsdiffExports> {\n const precompiled = getPrecompiledBsdiffModule();\n const directExports = asBsdiffExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toBsdiffExports(instance.exports);\n }\n\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"No precompiled bsdiff WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledBsdiffModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toBsdiffExports(source: unknown): BsdiffExports {\n const direct = asBsdiffExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\"PATCH_FAILED\", \"bsdiff wasm exports are incomplete\");\n}\n\nfunction asBsdiffExports(source: unknown): BsdiffExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<BsdiffExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.alloc === \"function\" &&\n typeof maybe.dealloc === \"function\" &&\n typeof maybe.create_patch === \"function\" &&\n typeof maybe.apply_patch === \"function\" &&\n typeof maybe.output_ptr === \"function\" &&\n typeof maybe.output_len === \"function\" &&\n typeof maybe.free_output === \"function\"\n ) {\n return maybe as BsdiffExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;;AAuBA,IAAK,eAAL;AACE;AACA;AACA;AACA;;EAJG,mBAKJ;AAED,IAAI;AAEJ,eAAsB,kBACpB,MACA,MACqB;CACrB,MAAM,OAAO,MAAM,eAAe;CAElC,MAAM,SAAS,mBACb,MACA,MACA,OACC,SAAS,SAAS,SAAS,YAC1B,KAAK,aAAa,SAAS,SAAS,SAAS,QAAQ,CACxD;AAED,KAAI,WAAW,aAAa,GAC1B,OAAM,cAAc,OAAO;AAG7B,QAAO,kBAAkB,KAAK;;AAGhC,eAAsB,iBACpB,MACA,OACqB;CACrB,MAAM,OAAO,MAAM,eAAe;CAElC,MAAM,SAAS,mBACb,MACA,MACA,QACC,SAAS,SAAS,UAAU,aAC3B,KAAK,YAAY,SAA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AAM,eAAe,cAC5B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,gBAAgB,WAE7B,QAAO"}
1
+ {"version":3,"file":"bsdiff.js","names":[],"sources":["../../src/internal/bsdiff.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype BsdiffExports = {\n memory: WebAssembly.Memory;\n alloc: (len: number) => number;\n dealloc: (ptr: number, len: number) => void;\n create_patch: (\n basePtr: number,\n baseLen: number,\n nextPtr: number,\n nextLen: number,\n ) => number;\n apply_patch: (\n basePtr: number,\n baseLen: number,\n patchPtr: number,\n patchLen: number,\n ) => number;\n output_ptr: () => number;\n output_len: () => number;\n free_output: () => void;\n};\n\nenum BsdiffStatus {\n OK = 0,\n INVALID_INPUT = 1,\n PATCH_FAILED = 2,\n INVALID_PATCH = 3,\n}\n\nlet wasmPromise: Promise<BsdiffExports> | undefined;\n\nexport async function createBsdiffPatch(\n base: Bytes,\n next: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n next,\n (basePtr, baseLen, nextPtr, nextLen) =>\n wasm.create_patch(basePtr, baseLen, nextPtr, nextLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapPatchError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nexport async function applyBsdiffPatch(\n base: Bytes,\n patch: Bytes,\n): Promise<Bytes> {\n const wasm = await getBsdiffWasm();\n\n const status = runBinaryOperation(\n wasm,\n base,\n patch,\n (basePtr, baseLen, patchPtr, patchLen) =>\n wasm.apply_patch(basePtr, baseLen, patchPtr, patchLen),\n );\n\n if (status !== BsdiffStatus.OK) {\n throw mapApplyError(status);\n }\n\n return readAndFreeOutput(wasm);\n}\n\nfunction runBinaryOperation(\n wasm: BsdiffExports,\n left: Bytes,\n right: Bytes,\n run: (\n leftPtr: number,\n leftLen: number,\n rightPtr: number,\n rightLen: number,\n ) => number,\n): number {\n const leftPtr = wasm.alloc(left.byteLength);\n const rightPtr = wasm.alloc(right.byteLength);\n\n try {\n writeBytesToMemory(wasm.memory, leftPtr, left);\n writeBytesToMemory(wasm.memory, rightPtr, right);\n return run(leftPtr, left.byteLength, rightPtr, right.byteLength);\n } finally {\n if (left.byteLength > 0) {\n wasm.dealloc(leftPtr, left.byteLength);\n }\n if (right.byteLength > 0) {\n wasm.dealloc(rightPtr, right.byteLength);\n }\n }\n}\n\nfunction writeBytesToMemory(\n memory: WebAssembly.Memory,\n ptr: number,\n bytes: Bytes,\n): void {\n if (bytes.byteLength === 0) {\n return;\n }\n new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes);\n}\n\nfunction readAndFreeOutput(wasm: BsdiffExports): Bytes {\n const outPtr = wasm.output_ptr();\n const outLen = wasm.output_len();\n\n if (outLen === 0) {\n wasm.free_output();\n return new Uint8Array();\n }\n\n const output = new Uint8Array(wasm.memory.buffer, outPtr, outLen);\n const copied = new Uint8Array(output);\n wasm.free_output();\n return copied;\n}\n\nfunction mapPatchError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bsdiff wasm\",\n );\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\"PATCH_FAILED\", \"Failed to generate BSDIFF40 patch\");\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-validation status while creating patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bsdiff wasm status: ${status}`,\n );\n}\n\nfunction mapApplyError(status: number): HdiffError {\n if (status === BsdiffStatus.INVALID_INPUT) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Invalid input bytes provided to bspatch wasm\",\n );\n }\n if (status === BsdiffStatus.INVALID_PATCH) {\n return new HdiffError(\"PATCH_FAILED\", \"Invalid BSDIFF40 patch bytes\");\n }\n if (status === BsdiffStatus.PATCH_FAILED) {\n return new HdiffError(\n \"PATCH_FAILED\",\n \"Unexpected patch-generation status while applying patch\",\n );\n }\n return new HdiffError(\n \"PATCH_FAILED\",\n `Unknown bspatch wasm status: ${status}`,\n );\n}\n\nasync function getBsdiffWasm(): Promise<BsdiffExports> {\n wasmPromise ??= loadBsdiffWasm();\n return wasmPromise;\n}\n\nasync function loadBsdiffWasm(): Promise<BsdiffExports> {\n const precompiled = getPrecompiledBsdiffModule();\n const directExports = asBsdiffExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toBsdiffExports(instance.exports);\n }\n\n throw new HdiffError(\n \"PATCH_FAILED\",\n \"No precompiled bsdiff WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledBsdiffModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toBsdiffExports(source: unknown): BsdiffExports {\n const direct = asBsdiffExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\"PATCH_FAILED\", \"bsdiff wasm exports are incomplete\");\n}\n\nfunction asBsdiffExports(source: unknown): BsdiffExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<BsdiffExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.alloc === \"function\" &&\n typeof maybe.dealloc === \"function\" &&\n typeof maybe.create_patch === \"function\" &&\n typeof maybe.apply_patch === \"function\" &&\n typeof maybe.output_ptr === \"function\" &&\n typeof maybe.output_len === \"function\" &&\n typeof maybe.free_output === \"function\"\n ) {\n return maybe as BsdiffExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAwBA,IAAK,eAAL,yBAAA,cAAA;AACE,cAAA,aAAA,QAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;AACA,cAAA,aAAA,kBAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;;EAJG,gBAAA,EAAA,CAKJ;AAED,IAAI;AAEJ,eAAsB,kBACpB,MACA,MACgB;CAChB,MAAM,OAAO,MAAM,eAAe;CAElC,MAAM,SAAS,mBACb,MACA,MACA,OACC,SAAS,SAAS,SAAS,YAC1B,KAAK,aAAa,SAAS,SAAS,SAAS,QAAQ,CACxD;AAED,KAAI,WAAW,aAAa,GAC1B,OAAM,cAAc,OAAO;AAG7B,QAAO,kBAAkB,KAAK;;AAGhC,eAAsB,iBACpB,MACA,OACgB;CAChB,MAAM,OAAO,MAAM,eAAe;CAElC,MAAM,SAAS,mBACb,MACA,MACA,QACC,SAAS,SAAS,UAAU,aAC3B,KAAK,YAAY,SAAS,SAAS,UAAU,SAAS,CACzD;AAED,KAAI,WAAW,aAAa,GAC1B,OAAM,cAAc,OAAO;AAG7B,QAAO,kBAAkB,KAAK;;AAGhC,SAAS,mBACP,MACA,MACA,OACA,KAMQ;CACR,MAAM,UAAU,KAAK,MAAM,KAAK,WAAW;CAC3C,MAAM,WAAW,KAAK,MAAM,MAAM,WAAW;AAE7C,KAAI;AACF,qBAAmB,KAAK,QAAQ,SAAS,KAAK;AAC9C,qBAAmB,KAAK,QAAQ,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B;CAChD,MAAM,gBAAgB,gBAAgB,YAAY;AAClD,KAAI,cACF,QAAO;AAGT,KAAI,iBAAiB,YAAY,CAE/B,QAAO,iBADU,MAAM,YAAY,YAAY,YAAY,EAC3B,QAAQ;AAG1C,OAAM,IAAI,WACR,gBACA,2HACD;;AAGH,SAAS,6BAAsC;CAC7C,MAAM,cAAc;CAKpB,MAAM,MACJ,YAAY,qCACZ,YAAY;AACd,KAAI,OAAO,OAAO,QAAQ,YAAY,aAAa,IACjD,QAAQ,IAA8B;AAExC,QAAO;;AAGT,SAAS,iBAAiB,KAAyC;AACjE,KAAI,eAAe,YAAY,OAC7B,QAAO;AAET,QAAO,OAAO,UAAU,SAAS,KAAK,IAAI,KAAK;;AAGjD,SAAS,iBAAiB,QAA+C;AACvE,KAAI,kBAAkB,YAAY,OAChC,QAAO;AAET,QACE,OAAO,UAAU,SAAS,KAAK,OAAO,KAAK;;AAI/C,SAAS,gBAAgB,QAAgC;CACvD,MAAM,SAAS,gBAAgB,OAAO;AACtC,KAAI,OACF,QAAO;AAGT,OAAM,IAAI,WAAW,gBAAgB,qCAAqC;;AAG5E,SAAS,gBAAgB,QAA4C;AACnE,KAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;AACd,MACE,iBAAiB,MAAM,OAAO,IAC9B,OAAO,MAAM,UAAU,cACvB,OAAO,MAAM,YAAY,cACzB,OAAO,MAAM,iBAAiB,cAC9B,OAAO,MAAM,gBAAgB,cAC7B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,eAAe,cAC5B,OAAO,MAAM,gBAAgB,WAE7B,QAAO"}
@@ -1,8 +1,9 @@
1
1
  //#region src/internal/bytes.d.ts
2
- type BytesLike = Uint8Array | ArrayBuffer;
3
- declare function toUint8Array(value: BytesLike): Uint8Array;
4
- declare function equalsBytes(a: Uint8Array, b: Uint8Array): boolean;
5
- declare function cloneBytes(value: Uint8Array): Uint8Array;
2
+ type Bytes = Uint8Array<ArrayBuffer>;
3
+ type BytesLike = Uint8Array<ArrayBufferLike> | ArrayBufferLike;
4
+ declare function toUint8Array(value: BytesLike): Bytes;
5
+ declare function equalsBytes(a: Bytes, b: Bytes): boolean;
6
+ declare function cloneBytes(value: Uint8Array<ArrayBufferLike>): Bytes;
6
7
  //#endregion
7
- export { BytesLike, cloneBytes, equalsBytes, toUint8Array };
8
+ export { Bytes, BytesLike, cloneBytes, equalsBytes, toUint8Array };
8
9
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","names":[],"sources":["../../src/internal/bytes.ts"],"mappings":";KAAY,SAAA,GAAY,UAAA,GAAa,WAAA;AAAA,iBAErB,YAAA,CAAa,KAAA,EAAO,SAAA,GAAY,UAAA;AAAA,iBAUhC,WAAA,CAAY,CAAA,EAAG,UAAA,EAAY,CAAA,EAAG,UAAA;AAAA,iBAY9B,UAAA,CAAW,KAAA,EAAO,UAAA,GAAa,UAAA"}
1
+ {"version":3,"file":"bytes.d.ts","names":[],"sources":["../../src/internal/bytes.ts"],"mappings":";KAAY,KAAA,GAAQ,UAAA,CAAW,WAAA;AAAA,KACnB,SAAA,GAAY,UAAA,CAAW,eAAA,IAAmB,eAAA;AAAA,iBAEtC,YAAA,CAAa,KAAA,EAAO,SAAA,GAAY,KAAA;AAAA,iBAgBhC,WAAA,CAAY,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA;AAAA,iBAYzB,UAAA,CAAW,KAAA,EAAO,UAAA,CAAW,eAAA,IAAmB,KAAA"}
@@ -1,8 +1,9 @@
1
1
  //#region src/internal/bytes.ts
2
2
  function toUint8Array(value) {
3
- if (value instanceof Uint8Array) return value;
3
+ if (value instanceof Uint8Array) return Uint8Array.from(value);
4
4
  if (value instanceof ArrayBuffer) return new Uint8Array(value);
5
- throw new TypeError("Expected Uint8Array or ArrayBuffer");
5
+ if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) return Uint8Array.from(new Uint8Array(value));
6
+ throw new TypeError("Expected Uint8Array or ArrayBufferLike");
6
7
  }
7
8
  function equalsBytes(a, b) {
8
9
  if (a.byteLength !== b.byteLength) return false;
@@ -10,9 +11,9 @@ function equalsBytes(a, b) {
10
11
  return true;
11
12
  }
12
13
  function cloneBytes(value) {
13
- return new Uint8Array(value);
14
+ return Uint8Array.from(value);
14
15
  }
15
-
16
16
  //#endregion
17
17
  export { cloneBytes, equalsBytes, toUint8Array };
18
+
18
19
  //# sourceMappingURL=bytes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","names":[],"sources":["../../src/internal/bytes.ts"],"sourcesContent":["export type BytesLike = Uint8Array | ArrayBuffer;\n\nexport function toUint8Array(value: BytesLike): Uint8Array {\n if (value instanceof Uint8Array) {\n return value;\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n throw new TypeError(\"Expected Uint8Array or ArrayBuffer\");\n}\n\nexport function equalsBytes(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n for (let i = 0; i < a.byteLength; i += 1) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport function cloneBytes(value: Uint8Array): Uint8Array {\n return new Uint8Array(value);\n}\n"],"mappings":";AAEA,SAAgB,aAAa,OAA8B;AACzD,KAAI,iBAAiB,WACnB,QAAO;AAET,KAAI,iBAAiB,YACnB,QAAO,IAAI,WAAW,MAAM;AAE9B,OAAM,IAAI,UAAU,qCAAqC;;AAG3D,SAAgB,YAAY,GAAe,GAAwB;AACjE,KAAI,EAAE,eAAe,EAAE,WACrB,QAAO;AAET,MAAK,IAAI,IAAI,GAAG,IAAI,EAAE,YAAY,KAAK,EACrC,KAAI,EAAE,OAAO,EAAE,GACb,QAAO;AAGX,QAAO;;AAGT,SAAgB,WAAW,OAA+B;AACxD,QAAO,IAAI,WAAW,MAAM"}
1
+ {"version":3,"file":"bytes.js","names":[],"sources":["../../src/internal/bytes.ts"],"sourcesContent":["export type Bytes = Uint8Array<ArrayBuffer>;\nexport type BytesLike = Uint8Array<ArrayBufferLike> | ArrayBufferLike;\n\nexport function toUint8Array(value: BytesLike): Bytes {\n if (value instanceof Uint8Array) {\n return Uint8Array.from(value);\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n if (\n typeof SharedArrayBuffer !== \"undefined\" &&\n value instanceof SharedArrayBuffer\n ) {\n return Uint8Array.from(new Uint8Array(value));\n }\n throw new TypeError(\"Expected Uint8Array or ArrayBufferLike\");\n}\n\nexport function equalsBytes(a: Bytes, b: Bytes): boolean {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n for (let i = 0; i < a.byteLength; i += 1) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport function cloneBytes(value: Uint8Array<ArrayBufferLike>): Bytes {\n return Uint8Array.from(value);\n}\n"],"mappings":";AAGA,SAAgB,aAAa,OAAyB;AACpD,KAAI,iBAAiB,WACnB,QAAO,WAAW,KAAK,MAAM;AAE/B,KAAI,iBAAiB,YACnB,QAAO,IAAI,WAAW,MAAM;AAE9B,KACE,OAAO,sBAAsB,eAC7B,iBAAiB,kBAEjB,QAAO,WAAW,KAAK,IAAI,WAAW,MAAM,CAAC;AAE/C,OAAM,IAAI,UAAU,yCAAyC;;AAG/D,SAAgB,YAAY,GAAU,GAAmB;AACvD,KAAI,EAAE,eAAe,EAAE,WACrB,QAAO;AAET,MAAK,IAAI,IAAI,GAAG,IAAI,EAAE,YAAY,KAAK,EACrC,KAAI,EAAE,OAAO,EAAE,GACb,QAAO;AAGX,QAAO;;AAGT,SAAgB,WAAW,OAA2C;AACpE,QAAO,WAAW,KAAK,MAAM"}
@@ -1,8 +1,10 @@
1
+ import { Bytes } from "./bytes.js";
2
+
1
3
  //#region src/internal/hermes-validate.d.ts
2
4
  type ValidatedHbc = {
3
5
  version: number;
4
6
  };
5
- declare function validateExecutionHbc(input: Uint8Array): Promise<ValidatedHbc>;
7
+ declare function validateExecutionHbc(input: Bytes): Promise<ValidatedHbc>;
6
8
  //#endregion
7
9
  export { validateExecutionHbc };
8
10
  //# sourceMappingURL=hermes-validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hermes-validate.d.ts","names":[],"sources":["../../src/internal/hermes-validate.ts"],"mappings":";KAUK,YAAA;EACH,OAAA;AAAA;AAAA,iBAaoB,oBAAA,CACpB,KAAA,EAAO,UAAA,GACN,OAAA,CAAQ,YAAA"}
1
+ {"version":3,"file":"hermes-validate.d.ts","names":[],"sources":["../../src/internal/hermes-validate.ts"],"mappings":";;;KAWK,YAAA;EACH,OAAA;AAAA;AAAA,iBAaoB,oBAAA,CACpB,KAAA,EAAO,KAAA,GACN,OAAA,CAAQ,YAAA"}
@@ -1,5 +1,4 @@
1
1
  import { HdiffError } from "../errors.js";
2
-
3
2
  //#region src/internal/hermes-validate.ts
4
3
  var ValidateCode = /* @__PURE__ */ function(ValidateCode) {
5
4
  ValidateCode[ValidateCode["OK"] = 0] = "OK";
@@ -78,7 +77,7 @@ function asHermesExports(source) {
78
77
  if (isWasmMemoryLike(maybe.memory) && typeof maybe.validate === "function" && typeof maybe.version === "function") return maybe;
79
78
  }
80
79
  }
81
-
82
80
  //#endregion
83
81
  export { validateExecutionHbc };
82
+
84
83
  //# sourceMappingURL=hermes-validate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hermes-validate.js","names":[],"sources":["../../src/internal/hermes-validate.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\n\ntype HermesValidateExports = {\n memory: WebAssembly.Memory;\n validate: (ptr: number, len: number) => number;\n version: (ptr: number) => number;\n alloc?: (len: number) => number;\n dealloc?: (ptr: number, len: number) => void;\n};\n\ntype ValidatedHbc = {\n version: number;\n};\n\nenum ValidateCode {\n OK = 0,\n TOO_SMALL = 1,\n INVALID_MAGIC = 2,\n DELTA_MAGIC = 3,\n INVALID_LENGTH = 4,\n}\n\nlet wasmPromise: Promise<HermesValidateExports> | undefined;\n\nexport async function validateExecutionHbc(\n input: Uint8Array,\n): Promise<ValidatedHbc> {\n const wasm = await getHermesValidator();\n if (typeof wasm.alloc === \"function\" && typeof wasm.dealloc === \"function\") {\n const ptr = wasm.alloc(input.byteLength);\n try {\n if (input.byteLength > 0) {\n new Uint8Array(wasm.memory.buffer, ptr, input.byteLength).set(input);\n }\n\n const code = wasm.validate(ptr, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(ptr) >>> 0 };\n } finally {\n if (input.byteLength > 0) {\n wasm.dealloc(ptr, input.byteLength);\n }\n }\n }\n\n ensureMemorySize(wasm.memory, input.byteLength);\n const view = new Uint8Array(wasm.memory.buffer, 0, input.byteLength);\n view.set(input);\n\n const code = wasm.validate(0, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(0) >>> 0 };\n}\n\nasync function getHermesValidator(): Promise<HermesValidateExports> {\n wasmPromise ??= loadHermesValidator();\n return wasmPromise;\n}\n\nasync function loadHermesValidator(): Promise<HermesValidateExports> {\n const precompiled = getPrecompiledHermesModule();\n const directExports = asHermesExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toHermesExports(instance.exports);\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"No precompiled Hermes validator WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledHermesModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction ensureMemorySize(\n memory: WebAssembly.Memory,\n requiredBytes: number,\n): void {\n const pageSize = 64 * 1024;\n const currentBytes = memory.buffer.byteLength;\n if (currentBytes >= requiredBytes) {\n return;\n }\n\n const bytesNeeded = requiredBytes - currentBytes;\n const additionalPages = Math.ceil(bytesNeeded / pageSize);\n memory.grow(additionalPages);\n}\n\nfunction mapValidationError(code: number): HdiffError {\n if (code === ValidateCode.DELTA_MAGIC) {\n return new HdiffError(\n \"NON_EXECUTION_FORM\",\n \"Input HBC is delta-form. execution-form HBC is required.\",\n );\n }\n if (\n code === ValidateCode.TOO_SMALL ||\n code === ValidateCode.INVALID_MAGIC ||\n code === ValidateCode.INVALID_LENGTH\n ) {\n return new HdiffError(\n \"INVALID_HBC\",\n \"Input is not a valid execution-form HBC\",\n );\n }\n return new HdiffError(\n \"INVALID_HBC\",\n `Unknown Hermes validation error: ${code}`,\n );\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toHermesExports(source: unknown): HermesValidateExports {\n const direct = asHermesExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"Hermes validator WASM exports are incomplete\",\n );\n}\n\nfunction asHermesExports(source: unknown): HermesValidateExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<HermesValidateExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.validate === \"function\" &&\n typeof maybe.version === \"function\"\n ) {\n return maybe as HermesValidateExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;;AAcA,IAAK,eAAL;AACE;AACA;AACA;AACA;AACA;;E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O;;AAGT,SAAS,iBACP,QACA,eACM;CACN,MAAM,WAAW,KAAK;CACtB,MAAM,eAAe,OAAO,OAAO;AACnC,KAAI,gBAAgB,cAClB;CAGF,MAAM,cAAc,gBAAgB;CACpC,MAAM,kBAAkB,KAAK,KAAK,cAAc,SAAS;AACzD,QAAO,KAAK,gBAAgB;;AAG9B,SAAS,mBAAmB,MAA0B;AACpD,KAAI,SAAS,aAAa,YACxB,QAAO,IAAI,WACT,sBACA,2DACD;AAEH,KACE,SAAS,aAAa,aACtB,SAAS,aAAa,iBACtB,SAAS,aAAa,eAEtB,QAAO,IAAI,WACT,eACA,0CACD;AAEH,QAAO,IAAI,WACT,eACA,oCAAoC,OACrC;;AAGH,SAAS,iBAAiB,KAAyC;AACjE,KAAI,eAAe,YAAY,OAC7B,QAAO;AAET,QAAO,OAAO,UAAU,SAAS,KAAK,IAAI,KAAK;;AAGjD,SAAS,iBAAiB,QAA+C;AACvE,KAAI,kBAAkB,YAAY,OAChC,QAAO;AAET,QACE,OAAO,UAAU,SAAS,KAAK,OAAO,KAAK;;AAI/C,SAAS,gBAAgB,QAAwC;CAC/D,MAAM,SAAS,gBAAgB,OAAO;AACtC,KAAI,OACF,QAAO;AAGT,OAAM,IAAI,WACR,eACA,+CACD;;AAGH,SAAS,gBAAgB,QAAoD;AAC3E,KAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,QAAQ;AACd,MACE,iBAAiB,MAAM,OAAO,IAC9B,OAAO,MAAM,aAAa,cAC1B,OAAO,MAAM,YAAY,WAEzB,QAAO"}
1
+ {"version":3,"file":"hermes-validate.js","names":[],"sources":["../../src/internal/hermes-validate.ts"],"sourcesContent":["import { HdiffError } from \"../errors.js\";\nimport type { Bytes } from \"./bytes.js\";\n\ntype HermesValidateExports = {\n memory: WebAssembly.Memory;\n validate: (ptr: number, len: number) => number;\n version: (ptr: number) => number;\n alloc?: (len: number) => number;\n dealloc?: (ptr: number, len: number) => void;\n};\n\ntype ValidatedHbc = {\n version: number;\n};\n\nenum ValidateCode {\n OK = 0,\n TOO_SMALL = 1,\n INVALID_MAGIC = 2,\n DELTA_MAGIC = 3,\n INVALID_LENGTH = 4,\n}\n\nlet wasmPromise: Promise<HermesValidateExports> | undefined;\n\nexport async function validateExecutionHbc(\n input: Bytes,\n): Promise<ValidatedHbc> {\n const wasm = await getHermesValidator();\n if (typeof wasm.alloc === \"function\" && typeof wasm.dealloc === \"function\") {\n const ptr = wasm.alloc(input.byteLength);\n try {\n if (input.byteLength > 0) {\n new Uint8Array(wasm.memory.buffer, ptr, input.byteLength).set(input);\n }\n\n const code = wasm.validate(ptr, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(ptr) >>> 0 };\n } finally {\n if (input.byteLength > 0) {\n wasm.dealloc(ptr, input.byteLength);\n }\n }\n }\n\n ensureMemorySize(wasm.memory, input.byteLength);\n const view = new Uint8Array(wasm.memory.buffer, 0, input.byteLength);\n view.set(input);\n\n const code = wasm.validate(0, input.byteLength);\n if (code !== ValidateCode.OK) {\n throw mapValidationError(code);\n }\n\n return { version: wasm.version(0) >>> 0 };\n}\n\nasync function getHermesValidator(): Promise<HermesValidateExports> {\n wasmPromise ??= loadHermesValidator();\n return wasmPromise;\n}\n\nasync function loadHermesValidator(): Promise<HermesValidateExports> {\n const precompiled = getPrecompiledHermesModule();\n const directExports = asHermesExports(precompiled);\n if (directExports) {\n return directExports;\n }\n\n if (isWasmModuleLike(precompiled)) {\n const instance = await WebAssembly.instantiate(precompiled);\n return toHermesExports(instance.exports);\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"No precompiled Hermes validator WASM configured. Import a runtime entry such as @hot-updater/bsdiff/node, /bun, /deno, or /worker.\",\n );\n}\n\nfunction getPrecompiledHermesModule(): unknown {\n const hdiffGlobal = globalThis as {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n };\n\n const mod =\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ ??\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__;\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return (mod as { default?: unknown }).default;\n }\n return mod;\n}\n\nfunction ensureMemorySize(\n memory: WebAssembly.Memory,\n requiredBytes: number,\n): void {\n const pageSize = 64 * 1024;\n const currentBytes = memory.buffer.byteLength;\n if (currentBytes >= requiredBytes) {\n return;\n }\n\n const bytesNeeded = requiredBytes - currentBytes;\n const additionalPages = Math.ceil(bytesNeeded / pageSize);\n memory.grow(additionalPages);\n}\n\nfunction mapValidationError(code: number): HdiffError {\n if (code === ValidateCode.DELTA_MAGIC) {\n return new HdiffError(\n \"NON_EXECUTION_FORM\",\n \"Input HBC is delta-form. execution-form HBC is required.\",\n );\n }\n if (\n code === ValidateCode.TOO_SMALL ||\n code === ValidateCode.INVALID_MAGIC ||\n code === ValidateCode.INVALID_LENGTH\n ) {\n return new HdiffError(\n \"INVALID_HBC\",\n \"Input is not a valid execution-form HBC\",\n );\n }\n return new HdiffError(\n \"INVALID_HBC\",\n `Unknown Hermes validation error: ${code}`,\n );\n}\n\nfunction isWasmModuleLike(mod: unknown): mod is WebAssembly.Module {\n if (mod instanceof WebAssembly.Module) {\n return true;\n }\n return Object.prototype.toString.call(mod) === \"[object WebAssembly.Module]\";\n}\n\nfunction isWasmMemoryLike(memory: unknown): memory is WebAssembly.Memory {\n if (memory instanceof WebAssembly.Memory) {\n return true;\n }\n return (\n Object.prototype.toString.call(memory) === \"[object WebAssembly.Memory]\"\n );\n}\n\nfunction toHermesExports(source: unknown): HermesValidateExports {\n const direct = asHermesExports(source);\n if (direct) {\n return direct;\n }\n\n throw new HdiffError(\n \"INVALID_HBC\",\n \"Hermes validator WASM exports are incomplete\",\n );\n}\n\nfunction asHermesExports(source: unknown): HermesValidateExports | undefined {\n if (source && typeof source === \"object\") {\n const maybe = source as Partial<HermesValidateExports>;\n if (\n isWasmMemoryLike(maybe.memory) &&\n typeof maybe.validate === \"function\" &&\n typeof maybe.version === \"function\"\n ) {\n return maybe as HermesValidateExports;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAeA,IAAK,eAAL,yBAAA,cAAA;AACE,cAAA,aAAA,QAAA,KAAA;AACA,cAAA,aAAA,eAAA,KAAA;AACA,cAAA,aAAA,mBAAA,KAAA;AACA,cAAA,aAAA,iBAAA,KAAA;AACA,cAAA,aAAA,oBAAA,KAAA;;EALG,gBAAA,EAAA,CAMJ;AAED,IAAI;AAEJ,eAAsB,qBACpB,OACuB;CACvB,MAAM,OAAO,MAAM,oBAAoB;AACvC,KAAI,OAAO,KAAK,UAAU,cAAc,OAAO,KAAK,YAAY,YAAY;EAC1E,MAAM,MAAM,KAAK,MAAM,MAAM,WAAW;AACxC,MAAI;AACF,OAAI,MAAM,aAAa,EACrB,KAAI,WAAW,KAAK,OAAO,QAAQ,KAAK,MAAM,WAAW,CAAC,IAAI,MAAM;GAGtE,MAAM,OAAO,KAAK,SAAS,KAAK,MAAM,WAAW;AACjD,OAAI,SAAS,aAAa,GACxB,OAAM,mBAAmB,KAAK;AAGhC,UAAO,EAAE,SAAS,KAAK,QAAQ,IAAI,KAAK,GAAG;YACnC;AACR,OAAI,MAAM,aAAa,EACrB,MAAK,QAAQ,KAAK,MAAM,WAAW;;;AAKzC,kBAAiB,KAAK,QAAQ,MAAM,WAAW;AAClC,KAAI,WAAW,KAAK,OAAO,QAAQ,GAAG,MAAM,WAAW,CAC/D,IAAI,MAAM;CAEf,MAAM,OAAO,KAAK,SAAS,GAAG,MAAM,WAAW;AAC/C,KAAI,SAAS,aAAa,GACxB,OAAM,mBAAmB,KAAK;AAGhC,QAAO,EAAE,SAAS,KAAK,QAAQ,EAAE,KAAK,GAAG;;AAG3C,eAAe,qBAAqD;AAClE,iBAAgB,qBAAqB;AACrC,QAAO;;AAGT,eAAe,sBAAsD;CACnE,MAAM,cAAc,4BAA4B;CAChD,MAAM,gBAAgB,gBAAgB,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AO,MAAM,YAAY,WAEzB,QAAO"}
package/dist/node.js CHANGED
@@ -2,7 +2,6 @@ import { HdiffError } from "./errors.js";
2
2
  import { hdiff } from "./hdiff.js";
3
3
  import { installPrecompiledWasm } from "./precompiled.js";
4
4
  import { readFileSync } from "node:fs";
5
-
6
5
  //#region src/node.ts
7
6
  const HDIFF_WASM_URL = new URL("../assets/hdiff.wasm", import.meta.url);
8
7
  installPrecompiledWasm(loadNodeWasmModule());
@@ -13,7 +12,7 @@ function loadNodeWasmModule() {
13
12
  throw new HdiffError("PATCH_FAILED", `Failed to load hdiff.wasm for Node runtime: ${HDIFF_WASM_URL.toString()}`);
14
13
  }
15
14
  }
16
-
17
15
  //#endregion
18
16
  export { HdiffError, hdiff };
17
+
19
18
  //# sourceMappingURL=node.js.map
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadNodeWasmModule());\n\nfunction loadNodeWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Node runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;AAChD,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\nconst HDIFF_WASM_URL = new URL(\"../assets/hdiff.wasm\", import.meta.url);\n\ninstallPrecompiledWasm(loadNodeWasmModule());\n\nfunction loadNodeWasmModule(): WebAssembly.Module {\n try {\n return new WebAssembly.Module(readFileSync(HDIFF_WASM_URL));\n } catch {\n throw new HdiffError(\n \"PATCH_FAILED\",\n `Failed to load hdiff.wasm for Node runtime: ${HDIFF_WASM_URL.toString()}`,\n );\n }\n}\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB,IAAI,IAAI,wBAAwB,OAAO,KAAK,IAAI;AAEvE,uBAAuB,oBAAoB,CAAC;AAE5C,SAAS,qBAAyC;AAChD,KAAI;AACF,SAAO,IAAI,YAAY,OAAO,aAAa,eAAe,CAAC;SACrD;AACN,QAAM,IAAI,WACR,gBACA,+CAA+C,eAAe,UAAU,GACzE"}
@@ -5,7 +5,7 @@ function installPrecompiledWasm(wasmModule) {
5
5
  if (hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ === void 0) hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ = wasmModule;
6
6
  if (hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ === void 0) hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ = wasmModule;
7
7
  }
8
-
9
8
  //#endregion
10
9
  export { installPrecompiledWasm };
10
+
11
11
  //# sourceMappingURL=precompiled.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"precompiled.js","names":[],"sources":["../src/precompiled.ts"],"sourcesContent":["type HdiffGlobal = {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n};\n\nexport function installPrecompiledWasm(wasmModule: WebAssembly.Module): void {\n const hdiffGlobal = globalThis as HdiffGlobal;\n\n if (hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ = wasmModule;\n }\n}\n"],"mappings":";AAMA,SAAgB,uBAAuB,YAAsC;CAC3E,MAAM,cAAc;AAEpB,KAAI,YAAY,+BAA+B,OAC7C,aAAY,6BAA6B;AAE3C,KAAI,YAAY,sCAAsC,OACpD,aAAY,oCAAoC;AAElD,KAAI,YAAY,0CAA0C,OACxD,aAAY,wCAAwC"}
1
+ {"version":3,"file":"precompiled.js","names":[],"sources":["../src/precompiled.ts"],"sourcesContent":["type HdiffGlobal = {\n __HDIFF_PRECOMPILED_WASM__?: unknown;\n __HDIFF_PRECOMPILED_BSDIFF_WASM__?: unknown;\n __HDIFF_PRECOMPILED_HERMES_HBC_WASM__?: unknown;\n};\n\nexport function installPrecompiledWasm(wasmModule: WebAssembly.Module): void {\n const hdiffGlobal = globalThis as HdiffGlobal;\n\n if (hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_BSDIFF_WASM__ = wasmModule;\n }\n if (hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ === undefined) {\n hdiffGlobal.__HDIFF_PRECOMPILED_HERMES_HBC_WASM__ = wasmModule;\n }\n}\n"],"mappings":";AAMA,SAAgB,uBAAuB,YAAsC;CAC3E,MAAM,cAAc;AAEpB,KAAI,YAAY,+BAA+B,KAAA,EAC7C,aAAY,6BAA6B;AAE3C,KAAI,YAAY,sCAAsC,KAAA,EACpD,aAAY,oCAAoC;AAElD,KAAI,YAAY,0CAA0C,KAAA,EACxD,aAAY,wCAAwC"}
package/dist/worker.js CHANGED
@@ -2,10 +2,9 @@ import { HdiffError } from "./errors.js";
2
2
  import { hdiff } from "./hdiff.js";
3
3
  import { installPrecompiledWasm } from "./precompiled.js";
4
4
  import hdiffWasmModule from "../assets/hdiff.wasm";
5
-
6
5
  //#region src/worker.ts
7
6
  installPrecompiledWasm(hdiffWasmModule);
8
-
9
7
  //#endregion
10
8
  export { HdiffError, hdiff };
9
+
11
10
  //# sourceMappingURL=worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","names":[],"sources":["../src/worker.ts"],"sourcesContent":["import hdiffWasmModule from \"../assets/hdiff.wasm\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\ninstallPrecompiledWasm(hdiffWasmModule);\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;;AAKA,uBAAuB,gBAAgB"}
1
+ {"version":3,"file":"worker.js","names":[],"sources":["../src/worker.ts"],"sourcesContent":["import hdiffWasmModule from \"../assets/hdiff.wasm\";\nimport { HdiffError, type HdiffErrorCode } from \"./errors.js\";\nimport { hdiff } from \"./hdiff.js\";\nimport { installPrecompiledWasm } from \"./precompiled.js\";\n\ninstallPrecompiledWasm(hdiffWasmModule);\n\nexport { hdiff, HdiffError, type HdiffErrorCode };\n"],"mappings":";;;;;AAKA,uBAAuB,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/bsdiff",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "Hot Updater BSdiff library that produces BSDIFF40 patches for RN bspatch flows",
5
5
  "type": "module",
6
6
  "main": "./dist/node.js",
@@ -54,9 +54,9 @@
54
54
  "repository": "https://github.com/gronxb/hot-updater",
55
55
  "devDependencies": {
56
56
  "@types/node": "^25.3.2",
57
- "tsdown": "0.21.0-beta.2",
57
+ "tsdown": "0.21.6",
58
58
  "typescript": "^5.9.3",
59
- "vitest": "^4.0.18",
59
+ "vitest": "4.1.0",
60
60
  "wrangler": "^4.69.0"
61
61
  },
62
62
  "publishConfig": {
@@ -67,8 +67,9 @@
67
67
  "build:watch": "tsdown --watch",
68
68
  "build:wasm": "node ./scripts/wasm-build/build-wasm.mjs",
69
69
  "test": "vitest run",
70
+ "test:type": "tsc --noEmit",
70
71
  "test:watch": "vitest",
71
72
  "test:runtime:node": "vitest run tests/runtime.node.test.ts",
72
- "test:runtime:endpoints": "vitest run tests/runtime.endpoints.test.ts"
73
+ "test:runtime:endpoints": "vitest run tests/runtime.endpoints.integration.spec.ts"
73
74
  }
74
75
  }