keyframe-store 4.3.1 → 4.3.3

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { InvalidOperationError } from "@esposter/shared";
2
2
  import { ResultAsync } from "neverthrow";
3
- //#region src/constants.d.ts
4
3
  export declare const OBJECT_MAGIC: Uint8Array;
5
4
  export declare const OBJECT_FORMAT_VERSION = 1;
6
5
  export declare const OBJECT_VERSION_OFFSET = 4;
@@ -13,14 +12,10 @@ export declare const HASH_BYTE_COUNT = 32;
13
12
  export declare const DELTA_HEADER_BYTE_COUNT: number;
14
13
  export declare const DEFAULT_PROMOTION_RATIO: number;
15
14
  export declare const DEFAULT_SEGMENT_BUDGET_RATIO = 1;
16
- //#endregion
17
- //#region src/models/VersionAnchor.d.ts
18
15
  export interface VersionAnchor {
19
16
  anchoredBytes: number;
20
17
  hash: string;
21
18
  }
22
- //#endregion
23
- //#region src/models/WrittenVersion.d.ts
24
19
  export interface WrittenVersion {
25
20
  baseHash: string;
26
21
  hash: string;
@@ -28,55 +23,34 @@ export interface WrittenVersion {
28
23
  plaintextBytes: number;
29
24
  storedBytes: number;
30
25
  }
31
- //#endregion
32
- //#region src/models/KeyframeStore.d.ts
33
26
  export interface KeyframeStore {
34
27
  collect: (releasedHashes: string[], retainedHashes: string[]) => ResultAsync<string[], Error>;
35
28
  read: (hash: string) => ResultAsync<Uint8Array, Error>;
36
29
  write: (plaintext: Uint8Array, anchor: VersionAnchor) => ResultAsync<WrittenVersion, Error>;
37
30
  }
38
- //#endregion
39
- //#region src/models/KeyframeStoreOptions.d.ts
40
31
  export interface KeyframeStoreOptions {
41
32
  compressionLevel?: number;
42
33
  promotionRatio?: number;
43
34
  segmentBudgetRatio?: number;
44
35
  }
45
- //#endregion
46
- //#region src/models/ObjectStore.d.ts
47
36
  export interface ObjectStore {
48
37
  delete: (keys: string[]) => Promise<void>;
49
38
  read: (key: string) => Promise<Uint8Array | undefined>;
50
39
  write: (key: string, bytes: Uint8Array) => Promise<boolean>;
51
40
  }
52
- //#endregion
53
- //#region src/createKeyframeStore.d.ts
54
41
  export declare const createKeyframeStore: (objectStore: ObjectStore, { compressionLevel, promotionRatio, segmentBudgetRatio }?: KeyframeStoreOptions) => KeyframeStore;
55
- //#endregion
56
- //#region src/models/ObjectNotStoredError.d.ts
57
42
  export declare class ObjectNotStoredError extends InvalidOperationError {
58
43
  constructor(hash: string, message: string);
59
44
  }
60
- //#endregion
61
- //#region src/models/ParsedObject.d.ts
62
45
  export interface ParsedObject {
63
46
  baseHash: string;
64
47
  payload: Uint8Array;
65
48
  windowLog: number;
66
49
  }
67
- //#endregion
68
- //#region src/services/decodeObject.d.ts
69
50
  export declare const decodeObject: (parsedObject: ParsedObject, basePlaintext?: Uint8Array) => Promise<Buffer>;
70
- //#endregion
71
- //#region src/services/encodeObject.d.ts
72
51
  export declare const encodeObject: (plaintext: Uint8Array, compressionLevel: number, base?: {
73
52
  hash: string;
74
53
  plaintext: Uint8Array;
75
54
  }) => Promise<Uint8Array>;
76
- //#endregion
77
- //#region src/services/getContentAddress.d.ts
78
55
  export declare const getContentAddress: (plaintext: Uint8Array) => string;
79
- //#endregion
80
- //#region src/services/parseObject.d.ts
81
- export declare const parseObject: (hash: string, bytes: Uint8Array) => ParsedObject;
82
- //#endregion
56
+ export declare const parseObject: (hash: string, bytes: Uint8Array) => ParsedObject;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { DEFAULT_COMPRESSION_LEVEL, InvalidOperationError, Operation, getResultA
2
2
  import { promisify } from "node:util";
3
3
  import { constants, zstdCompress, zstdDecompress } from "node:zlib";
4
4
  import { createHash } from "node:crypto";
5
- //#region src/constants.ts
5
+ // src/constants.ts
6
6
  const OBJECT_MAGIC = new Uint8Array([
7
7
  75,
8
8
  70,
@@ -20,23 +20,20 @@ const HASH_BYTE_COUNT = 32;
20
20
  const DELTA_HEADER_BYTE_COUNT = 40;
21
21
  const DEFAULT_PROMOTION_RATIO = 1 / 3;
22
22
  const DEFAULT_SEGMENT_BUDGET_RATIO = 1;
23
- //#endregion
24
- //#region src/models/ObjectNotStoredError.ts
23
+ // src/models/ObjectNotStoredError.ts
25
24
  var ObjectNotStoredError = class extends InvalidOperationError {
26
25
  constructor(hash, message) {
27
26
  super(Operation.Read, hash, message);
28
27
  this.name = "ObjectNotStoredError";
29
28
  }
30
29
  };
31
- //#endregion
32
- //#region src/services/decodeObject.ts
30
+ // src/services/decodeObject.ts
33
31
  const decompress = promisify(zstdDecompress);
34
32
  const decodeObject = (parsedObject, basePlaintext) => decompress(parsedObject.payload, {
35
33
  ...basePlaintext ? { dictionary: basePlaintext } : {},
36
34
  params: { [constants.ZSTD_d_windowLogMax]: parsedObject.windowLog }
37
35
  });
38
- //#endregion
39
- //#region src/services/encodeObject.ts
36
+ // src/services/encodeObject.ts
40
37
  const compress = promisify(zstdCompress);
41
38
  const encodeObject = async (plaintext, compressionLevel, base) => {
42
39
  const windowLog = getWindowLog(base?.plaintext.byteLength ?? 0, plaintext.byteLength);
@@ -57,11 +54,9 @@ const encodeObject = async (plaintext, compressionLevel, base) => {
57
54
  bytes.set(payload, headerByteCount);
58
55
  return bytes;
59
56
  };
60
- //#endregion
61
- //#region src/services/getContentAddress.ts
57
+ // src/services/getContentAddress.ts
62
58
  const getContentAddress = (plaintext) => createHash("sha256").update(plaintext).digest("hex");
63
- //#endregion
64
- //#region src/services/parseObject.ts
59
+ // src/services/parseObject.ts
65
60
  const parseObject = (hash, bytes) => {
66
61
  if (!(bytes.byteLength >= 8 && OBJECT_MAGIC.every((byte, index) => bytes[index] === byte))) throw new InvalidOperationError(Operation.Read, hash, "not a keyframe store object");
67
62
  else if (bytes[4] !== 1) throw new InvalidOperationError(Operation.Read, hash, `unknown object format version ${bytes[4]}`);
@@ -80,8 +75,7 @@ const parseObject = (hash, bytes) => {
80
75
  windowLog
81
76
  };
82
77
  };
83
- //#endregion
84
- //#region src/createKeyframeStore.ts
78
+ // src/createKeyframeStore.ts
85
79
  const decodeVerifiedObject = async (hash, parsedObject, basePlaintext) => {
86
80
  const plaintext = await decodeObject(parsedObject, basePlaintext);
87
81
  if (getContentAddress(plaintext) !== hash) throw new InvalidOperationError(Operation.Read, hash, "object does not hash to its key");
@@ -171,5 +165,4 @@ const createKeyframeStore = (objectStore, { compressionLevel = DEFAULT_COMPRESSI
171
165
  })
172
166
  };
173
167
  };
174
- //#endregion
175
168
  export { DEFAULT_PROMOTION_RATIO, DEFAULT_SEGMENT_BUDGET_RATIO, DELTA_FLAG, DELTA_HEADER_BYTE_COUNT, HASH_BYTE_COUNT, KEYFRAME_FLAG, OBJECT_FLAGS_OFFSET, OBJECT_FORMAT_VERSION, OBJECT_HEADER_BYTE_COUNT, OBJECT_MAGIC, OBJECT_VERSION_OFFSET, OBJECT_WINDOW_LOG_OFFSET, ObjectNotStoredError, createKeyframeStore, decodeObject, encodeObject, getContentAddress, parseObject };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyframe-store",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "Content-addressed version storage — every version is a zstd keyframe or a delta against one, over any backend that can store bytes by key.",
5
5
  "keywords": [
6
6
  "compression",
@@ -50,14 +50,14 @@
50
50
  "typecheck": "tsc"
51
51
  },
52
52
  "dependencies": {
53
- "@esposter/shared": "4.3.1",
53
+ "@esposter/shared": "4.3.3",
54
54
  "neverthrow": "^8.2.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@esposter/configuration": "4.3.1",
58
- "@esposter/shared-node": "4.3.1",
57
+ "@esposter/configuration": "4.3.3",
58
+ "@esposter/shared-node": "4.3.3",
59
59
  "@types/node": "^26.6.5",
60
60
  "tsdown": "^0.23.1"
61
61
  },
62
- "gitHead": "777a39636b789c13af33ed13370246ccf6dbaf31"
62
+ "gitHead": "955bbc130ad9b28877fd4ae8efc73a045141ce01"
63
63
  }