@wxn0brp/db-storage-bin 0.0.3 → 0.0.4
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/CHANGELOG.md +8 -0
- package/dist/bin/data.d.ts +1 -1
- package/dist/bin/data.js +2 -2
- package/dist/bin/head.js +2 -2
- package/dist/bin/index.d.ts +3 -3
- package/package.json +1 -1
- package/src/bin/data.ts +3 -3
- package/src/bin/head.ts +2 -2
- package/src/bin/index.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.4](https://github.com/wxn0brp/ValtheraDB-storage-bin/compare/v0.0.3...v0.0.4) (2025-09-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add generic, BinManager.write<T> ([a2bb851](https://github.com/wxn0brp/ValtheraDB-storage-bin/commit/a2bb851c2b3977d133b85bde917dd268b3256a41))
|
|
11
|
+
* format.encode(data, collection) ([6a20cb5](https://github.com/wxn0brp/ValtheraDB-storage-bin/commit/6a20cb57444ac6e9e1d5a61a63316f6e3184118e))
|
|
12
|
+
|
|
5
13
|
### [0.0.3](https://github.com/wxn0brp/ValtheraDB-storage-bin/compare/v0.0.2...v0.0.3) (2025-08-24)
|
|
6
14
|
|
|
7
15
|
|
package/dist/bin/data.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { BinManager, CollectionMeta } from "./index.js";
|
|
|
2
2
|
import { FileMeta } from "./head.js";
|
|
3
3
|
export declare function findCollection(cmp: BinManager, name: string): CollectionMeta | undefined;
|
|
4
4
|
export declare function findFreeSlot(cmp: BinManager, size: number): Promise<FileMeta["freeList"][number] | undefined>;
|
|
5
|
-
export declare function writeLogic(cmp: BinManager, collection: string, data:
|
|
5
|
+
export declare function writeLogic(cmp: BinManager, collection: string, data: any): Promise<void>;
|
|
6
6
|
export declare function readLogic(cmp: BinManager, collection: string): Promise<any>;
|
package/dist/bin/data.js
CHANGED
|
@@ -23,7 +23,7 @@ export async function writeLogic(cmp, collection, data) {
|
|
|
23
23
|
const { fd, meta } = cmp;
|
|
24
24
|
await _log(3, "Writing data to collection:", collection);
|
|
25
25
|
const existingCollection = findCollection(cmp, collection);
|
|
26
|
-
const encoded = Buffer.from(await cmp.options.format.encode(data));
|
|
26
|
+
const encoded = Buffer.from(await cmp.options.format.encode(data, collection));
|
|
27
27
|
const length = encoded.length;
|
|
28
28
|
const capacity = roundUpCapacity(meta, length + 4);
|
|
29
29
|
let offset = existingCollection?.offset;
|
|
@@ -85,5 +85,5 @@ export async function readLogic(cmp, collection) {
|
|
|
85
85
|
throw new Error("Collection not found");
|
|
86
86
|
const len = await readData(cmp.fd, collectionMeta.offset, 4);
|
|
87
87
|
const data = await readData(cmp.fd, collectionMeta.offset + 4, len.readUInt32LE(0));
|
|
88
|
-
return await cmp.options.format.decode(data);
|
|
88
|
+
return await cmp.options.format.decode(data, collection);
|
|
89
89
|
}
|
package/dist/bin/head.js
CHANGED
|
@@ -76,7 +76,7 @@ export async function readHeaderPayload(cmp) {
|
|
|
76
76
|
await _log(6, "err", `Incomplete payload header read: expected ${payloadLength} bytes, got ${bytesRead}`);
|
|
77
77
|
throw new Error(`Incomplete payload header read: expected ${payloadLength} bytes, got ${bytesRead}`);
|
|
78
78
|
}
|
|
79
|
-
const obj = await cmp.options.format.decode(payloadBuf);
|
|
79
|
+
const obj = await cmp.options.format.decode(payloadBuf, "");
|
|
80
80
|
meta.collections = (obj.c || []).map(([name, offset, capacity]) => ({ name, offset, capacity }));
|
|
81
81
|
meta.freeList = (obj.f || []).map(([offset, capacity]) => ({ offset, capacity }));
|
|
82
82
|
await _log(6, "Collections and freeList loaded", meta);
|
|
@@ -94,7 +94,7 @@ export async function saveHeaderAndPayload(cmp, recursion = false) {
|
|
|
94
94
|
const { collections, freeList, fileSize } = meta;
|
|
95
95
|
await _log(6, "Saving header payload:", collections, freeList);
|
|
96
96
|
const payloadObj = getHeaderPayload(meta);
|
|
97
|
-
const payloadBuf = Buffer.from(await cmp.options.format.encode(payloadObj));
|
|
97
|
+
const payloadBuf = Buffer.from(await cmp.options.format.encode(payloadObj, ""));
|
|
98
98
|
if (payloadBuf.length > 64 * 1024) {
|
|
99
99
|
console.error("Header payload too large");
|
|
100
100
|
throw new Error("Header payload too large");
|
package/dist/bin/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface Options {
|
|
|
15
15
|
crc: number;
|
|
16
16
|
overwriteRemovedCollection: boolean;
|
|
17
17
|
format: {
|
|
18
|
-
encode(data: any): Promise<Parameters<typeof Buffer.from>[0]>;
|
|
19
|
-
decode(data: Buffer): Promise<any>;
|
|
18
|
+
encode(data: any, collection: string): Promise<Parameters<typeof Buffer.from>[0]>;
|
|
19
|
+
decode(data: Buffer, collection: string): Promise<any>;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export declare class BinManager {
|
|
@@ -34,7 +34,7 @@ export declare class BinManager {
|
|
|
34
34
|
constructor(path: string, options?: Partial<Options>);
|
|
35
35
|
open(): Promise<void>;
|
|
36
36
|
close(): Promise<void>;
|
|
37
|
-
write(collection: string, data:
|
|
37
|
+
write<T = object[]>(collection: string, data: T): Promise<void>;
|
|
38
38
|
read(collection: string): Promise<any>;
|
|
39
39
|
optimize(): Promise<void>;
|
|
40
40
|
removeCollection(collection: string): Promise<void>;
|
package/package.json
CHANGED
package/src/bin/data.ts
CHANGED
|
@@ -27,12 +27,12 @@ export async function findFreeSlot(cmp: BinManager, size: number): Promise<FileM
|
|
|
27
27
|
return slot;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export async function writeLogic(cmp: BinManager, collection: string, data:
|
|
30
|
+
export async function writeLogic(cmp: BinManager, collection: string, data: any) {
|
|
31
31
|
const { fd, meta } = cmp;
|
|
32
32
|
await _log(3, "Writing data to collection:", collection);
|
|
33
33
|
|
|
34
34
|
const existingCollection = findCollection(cmp, collection);
|
|
35
|
-
const encoded = Buffer.from(await cmp.options.format.encode(data));
|
|
35
|
+
const encoded = Buffer.from(await cmp.options.format.encode(data, collection));
|
|
36
36
|
const length = encoded.length;
|
|
37
37
|
const capacity = roundUpCapacity(meta, length + 4);
|
|
38
38
|
|
|
@@ -95,5 +95,5 @@ export async function readLogic(cmp: BinManager, collection: string) {
|
|
|
95
95
|
|
|
96
96
|
const len = await readData(cmp.fd, collectionMeta.offset, 4);
|
|
97
97
|
const data = await readData(cmp.fd, collectionMeta.offset + 4, len.readUInt32LE(0));
|
|
98
|
-
return await cmp.options.format.decode(data);
|
|
98
|
+
return await cmp.options.format.decode(data, collection);
|
|
99
99
|
}
|
package/src/bin/head.ts
CHANGED
|
@@ -106,7 +106,7 @@ export async function readHeaderPayload(cmp: BinManager) {
|
|
|
106
106
|
throw new Error(`Incomplete payload header read: expected ${payloadLength} bytes, got ${bytesRead}`);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
const obj = await cmp.options.format.decode(payloadBuf) as {
|
|
109
|
+
const obj = await cmp.options.format.decode(payloadBuf, "") as {
|
|
110
110
|
c: [string, number, number][];
|
|
111
111
|
f: [number, number][];
|
|
112
112
|
};
|
|
@@ -133,7 +133,7 @@ export async function saveHeaderAndPayload(cmp: BinManager, recursion = false) {
|
|
|
133
133
|
|
|
134
134
|
const payloadObj = getHeaderPayload(meta);
|
|
135
135
|
|
|
136
|
-
const payloadBuf = Buffer.from(await cmp.options.format.encode(payloadObj));
|
|
136
|
+
const payloadBuf = Buffer.from(await cmp.options.format.encode(payloadObj, ""));
|
|
137
137
|
if (payloadBuf.length > 64 * 1024) {
|
|
138
138
|
console.error("Header payload too large");
|
|
139
139
|
throw new Error("Header payload too large");
|
package/src/bin/index.ts
CHANGED
|
@@ -33,8 +33,8 @@ export interface Options {
|
|
|
33
33
|
crc: number;
|
|
34
34
|
overwriteRemovedCollection: boolean;
|
|
35
35
|
format: {
|
|
36
|
-
encode(data: any): Promise<Parameters<typeof Buffer.from>[0]>;
|
|
37
|
-
decode(data: Buffer): Promise<any>;
|
|
36
|
+
encode(data: any, collection: string): Promise<Parameters<typeof Buffer.from>[0]>;
|
|
37
|
+
decode(data: Buffer, collection: string): Promise<any>;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -87,7 +87,7 @@ export class BinManager {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
async write(collection: string, data:
|
|
90
|
+
async write<T = object[]>(collection: string, data: T) {
|
|
91
91
|
if (!this.fd) throw new Error("File not open");
|
|
92
92
|
await writeLogic(this, collection, data);
|
|
93
93
|
}
|