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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core-buffered-file.d.ts +41 -0
  3. package/dist/core-file.d.ts +18 -0
  4. package/dist/core-memory.d.ts +36 -0
  5. package/dist/core.d.ts +23 -0
  6. package/dist/database.d.ts +244 -0
  7. package/dist/exceptions.d.ts +51 -0
  8. package/dist/hasher.d.ts +9 -0
  9. package/dist/index.d.ts +26 -0
  10. package/dist/index.js +429 -266
  11. package/dist/read-array-list.d.ts +13 -0
  12. package/dist/read-counted-hash-map.d.ts +7 -0
  13. package/dist/read-counted-hash-set.d.ts +7 -0
  14. package/dist/read-cursor.d.ts +57 -0
  15. package/dist/read-hash-map.d.ts +27 -0
  16. package/dist/read-hash-set.d.ts +18 -0
  17. package/dist/read-linked-array-list.d.ts +13 -0
  18. package/dist/slot-pointer.d.ts +7 -0
  19. package/dist/slot.d.ts +15 -0
  20. package/{src/slotted.ts → dist/slotted.d.ts} +1 -2
  21. package/dist/tag.d.ts +17 -0
  22. package/dist/write-array-list.d.ts +16 -0
  23. package/dist/write-counted-hash-map.d.ts +7 -0
  24. package/dist/write-counted-hash-set.d.ts +7 -0
  25. package/dist/write-cursor.d.ts +36 -0
  26. package/dist/write-hash-map.d.ts +25 -0
  27. package/dist/write-hash-set.d.ts +19 -0
  28. package/dist/write-linked-array-list.d.ts +19 -0
  29. package/dist/writeable-data.d.ts +20 -0
  30. package/package.json +14 -1
  31. package/.claude/settings.local.json +0 -9
  32. package/bun.lock +0 -24
  33. package/bunfig.toml +0 -1
  34. package/example/README.md +0 -46
  35. package/example/dump.ts +0 -201
  36. package/src/core-buffered-file.ts +0 -226
  37. package/src/core-file.ts +0 -137
  38. package/src/core-memory.ts +0 -179
  39. package/src/core.ts +0 -25
  40. package/src/database.ts +0 -2232
  41. package/src/exceptions.ts +0 -31
  42. package/src/hasher.ts +0 -52
  43. package/src/index.ts +0 -110
  44. package/src/read-array-list.ts +0 -45
  45. package/src/read-counted-hash-map.ts +0 -28
  46. package/src/read-counted-hash-set.ts +0 -28
  47. package/src/read-cursor.ts +0 -546
  48. package/src/read-hash-map.ts +0 -117
  49. package/src/read-hash-set.ts +0 -70
  50. package/src/read-linked-array-list.ts +0 -45
  51. package/src/slot-pointer.ts +0 -15
  52. package/src/slot.ts +0 -51
  53. package/src/tag.ts +0 -23
  54. package/src/write-array-list.ts +0 -65
  55. package/src/write-counted-hash-map.ts +0 -31
  56. package/src/write-counted-hash-set.ts +0 -31
  57. package/src/write-cursor.ts +0 -166
  58. package/src/write-hash-map.ts +0 -129
  59. package/src/write-hash-set.ts +0 -86
  60. package/src/write-linked-array-list.ts +0 -80
  61. package/src/writeable-data.ts +0 -67
  62. package/tests/database.test.ts +0 -2519
  63. package/tests/fixtures/test.db +0 -0
  64. package/tsconfig.json +0 -17
package/src/exceptions.ts DELETED
@@ -1,31 +0,0 @@
1
- export class DatabaseException extends Error {
2
- constructor(message?: string) {
3
- super(message);
4
- this.name = this.constructor.name;
5
- }
6
- }
7
-
8
- export class NotImplementedException extends DatabaseException {}
9
- export class UnreachableException extends DatabaseException {}
10
- export class InvalidDatabaseException extends DatabaseException {}
11
- export class InvalidVersionException extends DatabaseException {}
12
- export class InvalidHashSizeException extends DatabaseException {}
13
- export class KeyNotFoundException extends DatabaseException {}
14
- export class WriteNotAllowedException extends DatabaseException {}
15
- export class UnexpectedTagException extends DatabaseException {}
16
- export class CursorNotWriteableException extends DatabaseException {}
17
- export class ExpectedTxStartException extends DatabaseException {}
18
- export class KeyOffsetExceededException extends DatabaseException {}
19
- export class PathPartMustBeAtEndException extends DatabaseException {}
20
- export class StreamTooLongException extends DatabaseException {}
21
- export class EndOfStreamException extends DatabaseException {}
22
- export class InvalidOffsetException extends DatabaseException {}
23
- export class InvalidTopLevelTypeException extends DatabaseException {}
24
- export class ExpectedUnsignedLongException extends DatabaseException {}
25
- export class NoAvailableSlotsException extends DatabaseException {}
26
- export class MustSetNewSlotsToFullException extends DatabaseException {}
27
- export class EmptySlotException extends DatabaseException {}
28
- export class ExpectedRootNodeException extends DatabaseException {}
29
- export class InvalidFormatTagSizeException extends DatabaseException {}
30
- export class UnexpectedWriterPositionException extends DatabaseException {}
31
- export class MaxShiftExceededException extends DatabaseException {}
package/src/hasher.ts DELETED
@@ -1,52 +0,0 @@
1
- export class Hasher {
2
- readonly algorithm: string;
3
- readonly id: number;
4
- readonly digestLength: number;
5
-
6
- constructor(algorithm: string, id: number = 0) {
7
- this.algorithm = algorithm;
8
- this.id = id;
9
- // Determine digest length based on algorithm
10
- switch (algorithm) {
11
- case 'SHA-1':
12
- this.digestLength = 20;
13
- break;
14
- case 'SHA-256':
15
- this.digestLength = 32;
16
- break;
17
- case 'SHA-384':
18
- this.digestLength = 48;
19
- break;
20
- case 'SHA-512':
21
- this.digestLength = 64;
22
- break;
23
- default:
24
- throw new Error(`Unsupported hash algorithm: ${algorithm}`);
25
- }
26
- }
27
-
28
- async digest(data: Uint8Array): Promise<Uint8Array> {
29
- // Create a new ArrayBuffer to ensure compatibility with crypto.subtle
30
- const buffer = new ArrayBuffer(data.length);
31
- const view = new Uint8Array(buffer);
32
- view.set(data);
33
- const hashBuffer = await crypto.subtle.digest(this.algorithm, buffer);
34
- return new Uint8Array(hashBuffer);
35
- }
36
-
37
- static stringToId(hashIdName: string): number {
38
- const bytes = new TextEncoder().encode(hashIdName);
39
- if (bytes.length !== 4) {
40
- throw new Error('Name must be exactly four bytes long');
41
- }
42
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
43
- return view.getInt32(0, false); // big-endian
44
- }
45
-
46
- static idToString(id: number): string {
47
- const buffer = new ArrayBuffer(4);
48
- const view = new DataView(buffer);
49
- view.setInt32(0, id, false); // big-endian
50
- return new TextDecoder().decode(new Uint8Array(buffer));
51
- }
52
- }
package/src/index.ts DELETED
@@ -1,110 +0,0 @@
1
- // Tag
2
- export { Tag, tagValueOf } from './tag';
3
-
4
- // Slot
5
- export { Slot } from './slot';
6
- export { SlotPointer } from './slot-pointer';
7
- export type { Slotted } from './slotted';
8
-
9
- // Writeable Data
10
- export { Uint, Int, Float, Bytes, type WriteableData } from './writeable-data';
11
-
12
- // Exceptions
13
- export {
14
- DatabaseException,
15
- NotImplementedException,
16
- UnreachableException,
17
- InvalidDatabaseException,
18
- InvalidVersionException,
19
- InvalidHashSizeException,
20
- KeyNotFoundException,
21
- WriteNotAllowedException,
22
- UnexpectedTagException,
23
- CursorNotWriteableException,
24
- ExpectedTxStartException,
25
- KeyOffsetExceededException,
26
- PathPartMustBeAtEndException,
27
- StreamTooLongException,
28
- EndOfStreamException,
29
- InvalidOffsetException,
30
- InvalidTopLevelTypeException,
31
- ExpectedUnsignedLongException,
32
- NoAvailableSlotsException,
33
- MustSetNewSlotsToFullException,
34
- EmptySlotException,
35
- ExpectedRootNodeException,
36
- InvalidFormatTagSizeException,
37
- UnexpectedWriterPositionException,
38
- MaxShiftExceededException,
39
- } from './exceptions';
40
-
41
- // Core
42
- export type { Core, DataReader, DataWriter } from './core';
43
- export { CoreMemory } from './core-memory';
44
- export { CoreFile } from './core-file';
45
- export { CoreBufferedFile } from './core-buffered-file';
46
- export { Hasher } from './hasher';
47
-
48
- // Database
49
- export {
50
- Database,
51
- WriteMode,
52
- Header,
53
- ArrayListHeader,
54
- TopLevelArrayListHeader,
55
- LinkedArrayListHeader,
56
- KeyValuePair,
57
- LinkedArrayListSlot,
58
- LinkedArrayListSlotPointer,
59
- LinkedArrayListBlockInfo,
60
- VERSION,
61
- MAGIC_NUMBER,
62
- BIT_COUNT,
63
- SLOT_COUNT,
64
- MASK,
65
- INDEX_BLOCK_SIZE,
66
- LINKED_ARRAY_LIST_INDEX_BLOCK_SIZE,
67
- MAX_BRANCH_LENGTH,
68
- // PathParts
69
- type PathPart,
70
- ArrayListInit,
71
- ArrayListGet,
72
- ArrayListAppend,
73
- ArrayListSlice,
74
- LinkedArrayListInit,
75
- LinkedArrayListGet,
76
- LinkedArrayListAppend,
77
- LinkedArrayListSlice,
78
- LinkedArrayListConcat,
79
- LinkedArrayListInsert,
80
- LinkedArrayListRemove,
81
- HashMapInit,
82
- HashMapGet,
83
- HashMapRemove,
84
- WriteData,
85
- Context,
86
- // HashMapGetTarget
87
- type HashMapGetTarget,
88
- HashMapGetKVPair,
89
- HashMapGetKey,
90
- HashMapGetValue,
91
- type ContextFunction,
92
- } from './database';
93
-
94
- // Cursors
95
- export { ReadCursor, Reader, CursorIterator, KeyValuePairCursor } from './read-cursor';
96
- export { WriteCursor, Writer, WriteCursorIterator, WriteKeyValuePairCursor } from './write-cursor';
97
-
98
- // Collections
99
- export { ReadArrayList } from './read-array-list';
100
- export { WriteArrayList } from './write-array-list';
101
- export { ReadHashMap } from './read-hash-map';
102
- export { WriteHashMap } from './write-hash-map';
103
- export { ReadHashSet } from './read-hash-set';
104
- export { WriteHashSet } from './write-hash-set';
105
- export { ReadLinkedArrayList } from './read-linked-array-list';
106
- export { WriteLinkedArrayList } from './write-linked-array-list';
107
- export { ReadCountedHashMap } from './read-counted-hash-map';
108
- export { WriteCountedHashMap } from './write-counted-hash-map';
109
- export { ReadCountedHashSet } from './read-counted-hash-set';
110
- export { WriteCountedHashSet } from './write-counted-hash-set';
@@ -1,45 +0,0 @@
1
- import { Tag } from './tag';
2
- import { Slot } from './slot';
3
- import type { Slotted } from './slotted';
4
- import { ReadCursor, CursorIterator } from './read-cursor';
5
- import { ArrayListGet } from './database';
6
- import { UnexpectedTagException } from './exceptions';
7
-
8
- export class ReadArrayList implements Slotted {
9
- public cursor: ReadCursor;
10
-
11
- constructor(cursor: ReadCursor) {
12
- switch (cursor.slotPtr.slot.tag) {
13
- case Tag.NONE:
14
- case Tag.ARRAY_LIST:
15
- this.cursor = cursor;
16
- break;
17
- default:
18
- throw new UnexpectedTagException();
19
- }
20
- }
21
-
22
- slot(): Slot {
23
- return this.cursor.slot();
24
- }
25
-
26
- async count(): Promise<number> {
27
- return this.cursor.count();
28
- }
29
-
30
- iterator(): CursorIterator {
31
- return this.cursor.iterator();
32
- }
33
-
34
- async *[Symbol.asyncIterator](): AsyncIterator<ReadCursor> {
35
- yield* this.cursor;
36
- }
37
-
38
- async getCursor(index: number): Promise<ReadCursor | null> {
39
- return this.cursor.readPath([new ArrayListGet(index)]);
40
- }
41
-
42
- async getSlot(index: number): Promise<Slot | null> {
43
- return this.cursor.readPathSlot([new ArrayListGet(index)]);
44
- }
45
- }
@@ -1,28 +0,0 @@
1
- import { Tag } from './tag';
2
- import { ReadHashMap } from './read-hash-map';
3
- import { ReadCursor } from './read-cursor';
4
- import { UnexpectedTagException } from './exceptions';
5
-
6
- export class ReadCountedHashMap extends ReadHashMap {
7
- protected constructor() {
8
- super();
9
- }
10
-
11
- static override async create(cursor: ReadCursor): Promise<ReadCountedHashMap> {
12
- const map = new ReadCountedHashMap();
13
- switch (cursor.slotPtr.slot.tag) {
14
- case Tag.NONE:
15
- case Tag.COUNTED_HASH_MAP:
16
- case Tag.COUNTED_HASH_SET:
17
- map.cursor = cursor;
18
- break;
19
- default:
20
- throw new UnexpectedTagException();
21
- }
22
- return map;
23
- }
24
-
25
- async count(): Promise<number> {
26
- return this.cursor.count();
27
- }
28
- }
@@ -1,28 +0,0 @@
1
- import { Tag } from './tag';
2
- import { ReadHashSet } from './read-hash-set';
3
- import { ReadCursor } from './read-cursor';
4
- import { UnexpectedTagException } from './exceptions';
5
-
6
- export class ReadCountedHashSet extends ReadHashSet {
7
- protected constructor() {
8
- super();
9
- }
10
-
11
- static override async create(cursor: ReadCursor): Promise<ReadCountedHashSet> {
12
- const set = new ReadCountedHashSet();
13
- switch (cursor.slotPtr.slot.tag) {
14
- case Tag.NONE:
15
- case Tag.COUNTED_HASH_MAP:
16
- case Tag.COUNTED_HASH_SET:
17
- set.cursor = cursor;
18
- break;
19
- default:
20
- throw new UnexpectedTagException();
21
- }
22
- return set;
23
- }
24
-
25
- async count(): Promise<number> {
26
- return this.cursor.count();
27
- }
28
- }