xitdb 0.13.0 → 0.14.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 (61) hide show
  1. package/README.md +16 -15
  2. package/dist/core-buffered-file.d.ts +2 -2
  3. package/dist/core-buffered-file.js +182 -0
  4. package/dist/core-file.d.ts +1 -1
  5. package/dist/core-file.js +105 -0
  6. package/dist/core-memory.d.ts +1 -1
  7. package/dist/core-memory.js +152 -0
  8. package/dist/core.js +1 -0
  9. package/dist/database.d.ts +174 -49
  10. package/dist/database.js +3047 -0
  11. package/dist/exceptions.d.ts +4 -0
  12. package/dist/exceptions.js +62 -0
  13. package/dist/hasher.js +49 -0
  14. package/dist/index.d.ts +30 -26
  15. package/dist/index.js +35 -3923
  16. package/dist/read-array-list.d.ts +3 -3
  17. package/dist/read-array-list.js +35 -0
  18. package/dist/read-counted-hash-map.d.ts +2 -2
  19. package/dist/read-counted-hash-map.js +19 -0
  20. package/dist/read-counted-hash-set.d.ts +2 -2
  21. package/dist/read-counted-hash-set.js +19 -0
  22. package/dist/read-cursor.d.ts +11 -5
  23. package/dist/read-cursor.js +577 -0
  24. package/dist/read-hash-map.d.ts +4 -4
  25. package/dist/read-hash-map.js +65 -0
  26. package/dist/read-hash-set.d.ts +4 -4
  27. package/dist/read-hash-set.js +47 -0
  28. package/dist/read-linked-array-list.d.ts +3 -3
  29. package/dist/read-linked-array-list.js +35 -0
  30. package/dist/read-sorted-map.d.ts +21 -0
  31. package/dist/read-sorted-map.js +73 -0
  32. package/dist/read-sorted-set.d.ts +19 -0
  33. package/dist/read-sorted-set.js +65 -0
  34. package/dist/slot-pointer.d.ts +1 -1
  35. package/dist/slot-pointer.js +11 -0
  36. package/dist/slot.d.ts +2 -2
  37. package/dist/slot.js +41 -0
  38. package/dist/slotted.d.ts +1 -1
  39. package/dist/slotted.js +1 -0
  40. package/dist/tag.d.ts +3 -1
  41. package/dist/tag.js +25 -0
  42. package/dist/write-array-list.d.ts +4 -4
  43. package/dist/write-array-list.js +42 -0
  44. package/dist/write-counted-hash-map.d.ts +2 -2
  45. package/dist/write-counted-hash-map.js +18 -0
  46. package/dist/write-counted-hash-set.d.ts +2 -2
  47. package/dist/write-counted-hash-set.js +18 -0
  48. package/dist/write-cursor.d.ts +5 -5
  49. package/dist/write-cursor.js +124 -0
  50. package/dist/write-hash-map.d.ts +4 -4
  51. package/dist/write-hash-map.js +90 -0
  52. package/dist/write-hash-set.d.ts +4 -4
  53. package/dist/write-hash-set.js +59 -0
  54. package/dist/write-linked-array-list.d.ts +4 -4
  55. package/dist/write-linked-array-list.js +52 -0
  56. package/dist/write-sorted-map.d.ts +12 -0
  57. package/dist/write-sorted-map.js +37 -0
  58. package/dist/write-sorted-set.d.ts +10 -0
  59. package/dist/write-sorted-set.js +29 -0
  60. package/dist/writeable-data.js +68 -0
  61. package/package.json +6 -6
@@ -49,6 +49,10 @@ export declare class UnexpectedWriterPositionException extends DatabaseException
49
49
  }
50
50
  export declare class MaxShiftExceededException extends DatabaseException {
51
51
  }
52
+ export declare class InvalidBTreeNodeException extends DatabaseException {
53
+ }
54
+ export declare class InvalidBTreeNodeKindException extends DatabaseException {
55
+ }
52
56
  export declare class Uint64OverflowException extends DatabaseException {
53
57
  }
54
58
  export declare class Int64OverflowException extends DatabaseException {
@@ -0,0 +1,62 @@
1
+ export class DatabaseException extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = this.constructor.name;
5
+ }
6
+ }
7
+ export class NotImplementedException extends DatabaseException {
8
+ }
9
+ export class UnreachableException extends DatabaseException {
10
+ }
11
+ export class InvalidDatabaseException extends DatabaseException {
12
+ }
13
+ export class InvalidVersionException extends DatabaseException {
14
+ }
15
+ export class InvalidHashSizeException extends DatabaseException {
16
+ }
17
+ export class KeyNotFoundException extends DatabaseException {
18
+ }
19
+ export class WriteNotAllowedException extends DatabaseException {
20
+ }
21
+ export class UnexpectedTagException extends DatabaseException {
22
+ }
23
+ export class CursorNotWriteableException extends DatabaseException {
24
+ }
25
+ export class ExpectedTxStartException extends DatabaseException {
26
+ }
27
+ export class KeyOffsetExceededException extends DatabaseException {
28
+ }
29
+ export class PathPartMustBeAtEndException extends DatabaseException {
30
+ }
31
+ export class StreamTooLongException extends DatabaseException {
32
+ }
33
+ export class EndOfStreamException extends DatabaseException {
34
+ }
35
+ export class InvalidOffsetException extends DatabaseException {
36
+ }
37
+ export class InvalidTopLevelTypeException extends DatabaseException {
38
+ }
39
+ export class ExpectedUnsignedLongException extends DatabaseException {
40
+ }
41
+ export class NoAvailableSlotsException extends DatabaseException {
42
+ }
43
+ export class MustSetNewSlotsToFullException extends DatabaseException {
44
+ }
45
+ export class EmptySlotException extends DatabaseException {
46
+ }
47
+ export class ExpectedRootNodeException extends DatabaseException {
48
+ }
49
+ export class InvalidFormatTagSizeException extends DatabaseException {
50
+ }
51
+ export class UnexpectedWriterPositionException extends DatabaseException {
52
+ }
53
+ export class MaxShiftExceededException extends DatabaseException {
54
+ }
55
+ export class InvalidBTreeNodeException extends DatabaseException {
56
+ }
57
+ export class InvalidBTreeNodeKindException extends DatabaseException {
58
+ }
59
+ export class Uint64OverflowException extends DatabaseException {
60
+ }
61
+ export class Int64OverflowException extends DatabaseException {
62
+ }
package/dist/hasher.js ADDED
@@ -0,0 +1,49 @@
1
+ import { createHash } from 'crypto';
2
+ export class Hasher {
3
+ algorithm;
4
+ nodeAlgorithm;
5
+ id;
6
+ digestLength;
7
+ constructor(algorithm, id = 0) {
8
+ this.algorithm = algorithm;
9
+ this.id = id;
10
+ // Determine digest length and node algorithm name based on algorithm
11
+ switch (algorithm) {
12
+ case 'SHA-1':
13
+ this.digestLength = 20;
14
+ this.nodeAlgorithm = 'sha1';
15
+ break;
16
+ case 'SHA-256':
17
+ this.digestLength = 32;
18
+ this.nodeAlgorithm = 'sha256';
19
+ break;
20
+ case 'SHA-384':
21
+ this.digestLength = 48;
22
+ this.nodeAlgorithm = 'sha384';
23
+ break;
24
+ case 'SHA-512':
25
+ this.digestLength = 64;
26
+ this.nodeAlgorithm = 'sha512';
27
+ break;
28
+ default:
29
+ throw new Error(`Unsupported hash algorithm: ${algorithm}`);
30
+ }
31
+ }
32
+ digest(data) {
33
+ return new Uint8Array(createHash(this.nodeAlgorithm).update(data).digest());
34
+ }
35
+ static stringToId(hashIdName) {
36
+ const bytes = new TextEncoder().encode(hashIdName);
37
+ if (bytes.length !== 4) {
38
+ throw new Error('Name must be exactly four bytes long');
39
+ }
40
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
41
+ return view.getInt32(0, false); // big-endian
42
+ }
43
+ static idToString(id) {
44
+ const buffer = new ArrayBuffer(4);
45
+ const view = new DataView(buffer);
46
+ view.setInt32(0, id, false); // big-endian
47
+ return new TextDecoder().decode(new Uint8Array(buffer));
48
+ }
49
+ }
package/dist/index.d.ts CHANGED
@@ -1,26 +1,30 @@
1
- export { Tag, tagValueOf } from './tag';
2
- export { Slot } from './slot';
3
- export { SlotPointer } from './slot-pointer';
4
- export type { Slotted } from './slotted';
5
- export { Uint, Int, Float, Bytes, type WriteableData } from './writeable-data';
6
- export { DatabaseException, NotImplementedException, UnreachableException, InvalidDatabaseException, InvalidVersionException, InvalidHashSizeException, KeyNotFoundException, WriteNotAllowedException, UnexpectedTagException, CursorNotWriteableException, ExpectedTxStartException, KeyOffsetExceededException, PathPartMustBeAtEndException, StreamTooLongException, EndOfStreamException, InvalidOffsetException, InvalidTopLevelTypeException, ExpectedUnsignedLongException, NoAvailableSlotsException, MustSetNewSlotsToFullException, EmptySlotException, ExpectedRootNodeException, InvalidFormatTagSizeException, UnexpectedWriterPositionException, MaxShiftExceededException, } from './exceptions';
7
- export type { Core, DataReader, DataWriter } from './core';
8
- export { CoreMemory } from './core-memory';
9
- export { CoreFile } from './core-file';
10
- export { CoreBufferedFile } from './core-buffered-file';
11
- export { Hasher } from './hasher';
12
- export { Database, WriteMode, Header, ArrayListHeader, TopLevelArrayListHeader, LinkedArrayListHeader, KeyValuePair, LinkedArrayListSlot, LinkedArrayListSlotPointer, LinkedArrayListBlockInfo, VERSION, MAGIC_NUMBER, BIT_COUNT, SLOT_COUNT, MASK, INDEX_BLOCK_SIZE, LINKED_ARRAY_LIST_INDEX_BLOCK_SIZE, MAX_BRANCH_LENGTH, type PathPart, ArrayListInit, ArrayListGet, ArrayListAppend, ArrayListSlice, LinkedArrayListInit, LinkedArrayListGet, LinkedArrayListAppend, LinkedArrayListSlice, LinkedArrayListConcat, LinkedArrayListInsert, LinkedArrayListRemove, HashMapInit, HashMapGet, HashMapRemove, WriteData, Context, type HashMapGetTarget, HashMapGetKVPair, HashMapGetKey, HashMapGetValue, type ContextFunction, } from './database';
13
- export { ReadCursor, Reader, CursorIterator, KeyValuePairCursor } from './read-cursor';
14
- export { WriteCursor, Writer, WriteCursorIterator, WriteKeyValuePairCursor } from './write-cursor';
15
- export { ReadArrayList } from './read-array-list';
16
- export { WriteArrayList } from './write-array-list';
17
- export { ReadHashMap } from './read-hash-map';
18
- export { WriteHashMap } from './write-hash-map';
19
- export { ReadHashSet } from './read-hash-set';
20
- export { WriteHashSet } from './write-hash-set';
21
- export { ReadLinkedArrayList } from './read-linked-array-list';
22
- export { WriteLinkedArrayList } from './write-linked-array-list';
23
- export { ReadCountedHashMap } from './read-counted-hash-map';
24
- export { WriteCountedHashMap } from './write-counted-hash-map';
25
- export { ReadCountedHashSet } from './read-counted-hash-set';
26
- export { WriteCountedHashSet } from './write-counted-hash-set';
1
+ export { Tag, tagValueOf } from './tag.js';
2
+ export { Slot } from './slot.js';
3
+ export { SlotPointer } from './slot-pointer.js';
4
+ export type { Slotted } from './slotted.js';
5
+ export { Uint, Int, Float, Bytes, type WriteableData } from './writeable-data.js';
6
+ export { DatabaseException, NotImplementedException, UnreachableException, InvalidDatabaseException, InvalidVersionException, InvalidHashSizeException, KeyNotFoundException, WriteNotAllowedException, UnexpectedTagException, CursorNotWriteableException, ExpectedTxStartException, KeyOffsetExceededException, PathPartMustBeAtEndException, StreamTooLongException, EndOfStreamException, InvalidOffsetException, InvalidTopLevelTypeException, ExpectedUnsignedLongException, NoAvailableSlotsException, MustSetNewSlotsToFullException, EmptySlotException, ExpectedRootNodeException, InvalidFormatTagSizeException, UnexpectedWriterPositionException, MaxShiftExceededException, } from './exceptions.js';
7
+ export type { Core, DataReader, DataWriter } from './core.js';
8
+ export { CoreMemory } from './core-memory.js';
9
+ export { CoreFile } from './core-file.js';
10
+ export { CoreBufferedFile } from './core-buffered-file.js';
11
+ export { Hasher } from './hasher.js';
12
+ export { Database, WriteMode, Header, ArrayListHeader, TopLevelArrayListHeader, BTreeHeader, KeyValuePair, BTreeNode, BTreeNodeKind, BTreeNodeRef, BTreeInsertResult, BTreeWriteSlot, BTreeJoinResult, BTreeSplitResult, SortedNode, SortedSplit, SortedInsertResult, SortedRemoveResult, SortedSlot, SortedEntry, VERSION, MAGIC_NUMBER, BIT_COUNT, SLOT_COUNT, MASK, INDEX_BLOCK_SIZE, MAX_BRANCH_LENGTH, BTREE_SLOT_COUNT, BTREE_SPLIT_COUNT, BTREE_NODE_HEADER_SIZE, BTREE_LEAF_BLOCK_SIZE, BTREE_BRANCH_BLOCK_SIZE, SORTED_LEAF_BLOCK_SIZE, SORTED_BRANCH_BLOCK_SIZE, type PathPart, ArrayListInit, ArrayListGet, ArrayListAppend, ArrayListSlice, LinkedArrayListInit, LinkedArrayListGet, LinkedArrayListAppend, LinkedArrayListSlice, LinkedArrayListConcat, LinkedArrayListInsert, LinkedArrayListRemove, HashMapInit, HashMapGet, HashMapRemove, SortedMapInit, SortedMapGet, SortedMapGetIndex, SortedMapRemove, WriteData, Context, type HashMapGetTarget, HashMapGetKVPair, HashMapGetKey, HashMapGetValue, type SortedMapGetTarget, SortedMapGetKVPair, SortedMapGetKey, SortedMapGetValue, type ContextFunction, } from './database.js';
13
+ export { ReadCursor, Reader, CursorIterator, KeyValuePairCursor } from './read-cursor.js';
14
+ export { WriteCursor, Writer, WriteCursorIterator, WriteKeyValuePairCursor } from './write-cursor.js';
15
+ export { ReadArrayList } from './read-array-list.js';
16
+ export { WriteArrayList } from './write-array-list.js';
17
+ export { ReadHashMap } from './read-hash-map.js';
18
+ export { WriteHashMap } from './write-hash-map.js';
19
+ export { ReadHashSet } from './read-hash-set.js';
20
+ export { WriteHashSet } from './write-hash-set.js';
21
+ export { ReadLinkedArrayList } from './read-linked-array-list.js';
22
+ export { WriteLinkedArrayList } from './write-linked-array-list.js';
23
+ export { ReadCountedHashMap } from './read-counted-hash-map.js';
24
+ export { WriteCountedHashMap } from './write-counted-hash-map.js';
25
+ export { ReadCountedHashSet } from './read-counted-hash-set.js';
26
+ export { WriteCountedHashSet } from './write-counted-hash-set.js';
27
+ export { ReadSortedMap } from './read-sorted-map.js';
28
+ export { WriteSortedMap } from './write-sorted-map.js';
29
+ export { ReadSortedSet } from './read-sorted-set.js';
30
+ export { WriteSortedSet } from './write-sorted-set.js';