diff --git a/batched_atomic.ts b/batched_atomic.ts index 28bf8c0..c79bcad 100644 --- a/batched_atomic.ts +++ b/batched_atomic.ts @@ -29,8 +29,6 @@ * @module */ -import { serialize } from "node:v8"; - import { BLOB_KEY, BLOB_META_KEY, setBlob } from "./blob_util.ts"; import { keys } from "./keys.ts"; @@ -54,6 +52,9 @@ const MAX_MUTATIONS = 999; const MAX_TOTAL_MUTATION_SIZE_BYTES = 800_000; const MAX_TOTAL_KEY_SIZE_BYTES = 80_000; +let serialize: ((value: unknown) => { byteLength: number }) | undefined = + undefined; + function getByteLength(value: unknown): number { if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) { return value.byteLength; @@ -61,7 +62,7 @@ function getByteLength(value: unknown): number { if (value instanceof Deno.KvU64) { return 8; } - return serialize(value).byteLength; + return serialize!(value).byteLength; } /** @@ -258,6 +259,9 @@ export class BatchedAtomicOperation { if (!this.#queue.length) { return Promise.resolve([]); } + if (!serialize) { + serialize = (await import("node:v8")).serialize; + } const results: Promise[] = []; let checks = 0; let mutations = 0; diff --git a/deno.json b/deno.json index 9e1f249..f29c0b2 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@kitsonk/kv-toolbox", - "version": "0.16.0", + "version": "0.16.1-beta.1", "exports": { "./batched_atomic": "./batched_atomic.ts", "./blob": "./blob.ts",