xitdb 0.1.0 → 0.3.0
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/LICENSE +21 -0
- package/dist/core-buffered-file.d.ts +41 -0
- package/dist/core-file.d.ts +18 -0
- package/dist/core-memory.d.ts +36 -0
- package/dist/core.d.ts +23 -0
- package/dist/database.d.ts +244 -0
- package/dist/exceptions.d.ts +51 -0
- package/dist/hasher.d.ts +9 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +429 -266
- package/dist/read-array-list.d.ts +13 -0
- package/dist/read-counted-hash-map.d.ts +7 -0
- package/dist/read-counted-hash-set.d.ts +7 -0
- package/dist/read-cursor.d.ts +57 -0
- package/dist/read-hash-map.d.ts +27 -0
- package/dist/read-hash-set.d.ts +18 -0
- package/dist/read-linked-array-list.d.ts +13 -0
- package/dist/slot-pointer.d.ts +7 -0
- package/dist/slot.d.ts +15 -0
- package/{src/slotted.ts → dist/slotted.d.ts} +1 -2
- package/dist/tag.d.ts +17 -0
- package/dist/write-array-list.d.ts +16 -0
- package/dist/write-counted-hash-map.d.ts +7 -0
- package/dist/write-counted-hash-set.d.ts +7 -0
- package/dist/write-cursor.d.ts +36 -0
- package/dist/write-hash-map.d.ts +25 -0
- package/dist/write-hash-set.d.ts +19 -0
- package/dist/write-linked-array-list.d.ts +19 -0
- package/dist/writeable-data.d.ts +20 -0
- package/package.json +14 -1
- package/.claude/settings.local.json +0 -9
- package/bun.lock +0 -24
- package/bunfig.toml +0 -1
- package/example/README.md +0 -46
- package/example/dump.ts +0 -201
- package/src/core-buffered-file.ts +0 -226
- package/src/core-file.ts +0 -137
- package/src/core-memory.ts +0 -179
- package/src/core.ts +0 -25
- package/src/database.ts +0 -2232
- package/src/exceptions.ts +0 -31
- package/src/hasher.ts +0 -52
- package/src/index.ts +0 -110
- package/src/read-array-list.ts +0 -45
- package/src/read-counted-hash-map.ts +0 -28
- package/src/read-counted-hash-set.ts +0 -28
- package/src/read-cursor.ts +0 -546
- package/src/read-hash-map.ts +0 -117
- package/src/read-hash-set.ts +0 -70
- package/src/read-linked-array-list.ts +0 -45
- package/src/slot-pointer.ts +0 -15
- package/src/slot.ts +0 -51
- package/src/tag.ts +0 -23
- package/src/write-array-list.ts +0 -65
- package/src/write-counted-hash-map.ts +0 -31
- package/src/write-counted-hash-set.ts +0 -31
- package/src/write-cursor.ts +0 -166
- package/src/write-hash-map.ts +0 -129
- package/src/write-hash-set.ts +0 -86
- package/src/write-linked-array-list.ts +0 -80
- package/src/writeable-data.ts +0 -67
- package/tests/database.test.ts +0 -2519
- package/tests/fixtures/test.db +0 -0
- package/tsconfig.json +0 -17
package/src/core-memory.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type { Core, DataReader, DataWriter } from './core';
|
|
2
|
-
|
|
3
|
-
export class CoreMemory implements Core {
|
|
4
|
-
public memory: RandomAccessMemory;
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
this.memory = new RandomAccessMemory();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
reader(): DataReader {
|
|
11
|
-
return this.memory;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
writer(): DataWriter {
|
|
15
|
-
return this.memory;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async length(): Promise<number> {
|
|
19
|
-
return this.memory.size();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async seek(pos: number): Promise<void> {
|
|
23
|
-
this.memory.seek(pos);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
position(): number {
|
|
27
|
-
return this.memory.getPosition();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async setLength(len: number): Promise<void> {
|
|
31
|
-
this.memory.setLength(len);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async flush(): Promise<void> {
|
|
35
|
-
// no-op for in-memory
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async sync(): Promise<void> {
|
|
39
|
-
// no-op for in-memory
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class RandomAccessMemory implements DataReader, DataWriter {
|
|
44
|
-
private buffer: Uint8Array;
|
|
45
|
-
private _position: number = 0;
|
|
46
|
-
private _count: number = 0;
|
|
47
|
-
|
|
48
|
-
constructor(initialSize: number = 1024) {
|
|
49
|
-
this.buffer = new Uint8Array(initialSize);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private ensureCapacity(minCapacity: number): void {
|
|
53
|
-
if (minCapacity > this.buffer.length) {
|
|
54
|
-
let newCapacity = this.buffer.length * 2;
|
|
55
|
-
if (newCapacity < minCapacity) {
|
|
56
|
-
newCapacity = minCapacity;
|
|
57
|
-
}
|
|
58
|
-
const newBuffer = new Uint8Array(newCapacity);
|
|
59
|
-
newBuffer.set(this.buffer.subarray(0, this._count));
|
|
60
|
-
this.buffer = newBuffer;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
size(): number {
|
|
65
|
-
return this._count;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
seek(pos: number): void {
|
|
69
|
-
if (pos > this._count) {
|
|
70
|
-
this._position = this._count;
|
|
71
|
-
} else {
|
|
72
|
-
this._position = pos;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getPosition(): number {
|
|
77
|
-
return this._position;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
setLength(len: number): void {
|
|
81
|
-
if (len === 0) {
|
|
82
|
-
this.reset();
|
|
83
|
-
} else {
|
|
84
|
-
if (len > this._count) throw new Error('Cannot extend length');
|
|
85
|
-
this._count = len;
|
|
86
|
-
if (this._position > len) {
|
|
87
|
-
this._position = len;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
reset(): void {
|
|
93
|
-
this._count = 0;
|
|
94
|
-
this._position = 0;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
toByteArray(): Uint8Array {
|
|
98
|
-
return this.buffer.slice(0, this._count);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// DataWriter interface
|
|
102
|
-
async write(data: Uint8Array): Promise<void> {
|
|
103
|
-
const pos = this._position;
|
|
104
|
-
if (pos < this._count) {
|
|
105
|
-
const bytesBeforeEnd = Math.min(data.length, this._count - pos);
|
|
106
|
-
for (let i = 0; i < bytesBeforeEnd; i++) {
|
|
107
|
-
this.buffer[pos + i] = data[i];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (bytesBeforeEnd < data.length) {
|
|
111
|
-
const bytesAfterEnd = data.length - bytesBeforeEnd;
|
|
112
|
-
this.ensureCapacity(this._count + bytesAfterEnd);
|
|
113
|
-
this.buffer.set(data.subarray(bytesBeforeEnd), this._count);
|
|
114
|
-
this._count += bytesAfterEnd;
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
this.ensureCapacity(this._count + data.length);
|
|
118
|
-
this.buffer.set(data, this._count);
|
|
119
|
-
this._count += data.length;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this._position = pos + data.length;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async writeByte(v: number): Promise<void> {
|
|
126
|
-
await this.write(new Uint8Array([v & 0xff]));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async writeShort(v: number): Promise<void> {
|
|
130
|
-
const buffer = new ArrayBuffer(2);
|
|
131
|
-
const view = new DataView(buffer);
|
|
132
|
-
view.setInt16(0, v, false); // big-endian
|
|
133
|
-
await this.write(new Uint8Array(buffer));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async writeLong(v: number): Promise<void> {
|
|
137
|
-
const buffer = new ArrayBuffer(8);
|
|
138
|
-
const view = new DataView(buffer);
|
|
139
|
-
view.setBigInt64(0, BigInt(v), false);
|
|
140
|
-
await this.write(new Uint8Array(buffer));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// DataReader interface
|
|
144
|
-
async readFully(b: Uint8Array): Promise<void> {
|
|
145
|
-
const pos = this._position;
|
|
146
|
-
if (pos + b.length > this._count) {
|
|
147
|
-
throw new Error('End of stream');
|
|
148
|
-
}
|
|
149
|
-
b.set(this.buffer.subarray(pos, pos + b.length));
|
|
150
|
-
this._position = pos + b.length;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async readByte(): Promise<number> {
|
|
154
|
-
const bytes = new Uint8Array(1);
|
|
155
|
-
await this.readFully(bytes);
|
|
156
|
-
return bytes[0];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async readShort(): Promise<number> {
|
|
160
|
-
const bytes = new Uint8Array(2);
|
|
161
|
-
await this.readFully(bytes);
|
|
162
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
163
|
-
return view.getInt16(0, false); // big-endian
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async readInt(): Promise<number> {
|
|
167
|
-
const bytes = new Uint8Array(4);
|
|
168
|
-
await this.readFully(bytes);
|
|
169
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
170
|
-
return view.getInt32(0, false); // big-endian
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async readLong(): Promise<number> {
|
|
174
|
-
const bytes = new Uint8Array(8);
|
|
175
|
-
await this.readFully(bytes);
|
|
176
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
177
|
-
return Number(view.getBigInt64(0, false));
|
|
178
|
-
}
|
|
179
|
-
}
|
package/src/core.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface DataReader {
|
|
2
|
-
readFully(buffer: Uint8Array): Promise<void>;
|
|
3
|
-
readByte(): Promise<number>;
|
|
4
|
-
readShort(): Promise<number>;
|
|
5
|
-
readInt(): Promise<number>;
|
|
6
|
-
readLong(): Promise<number>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface DataWriter {
|
|
10
|
-
write(buffer: Uint8Array): Promise<void>;
|
|
11
|
-
writeByte(v: number): Promise<void>;
|
|
12
|
-
writeShort(v: number): Promise<void>;
|
|
13
|
-
writeLong(v: number): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Core {
|
|
17
|
-
reader(): DataReader;
|
|
18
|
-
writer(): DataWriter;
|
|
19
|
-
length(): Promise<number>;
|
|
20
|
-
seek(pos: number): Promise<void>;
|
|
21
|
-
position(): number;
|
|
22
|
-
setLength(len: number): Promise<void>;
|
|
23
|
-
flush(): Promise<void>;
|
|
24
|
-
sync(): Promise<void>;
|
|
25
|
-
}
|