xitdb 0.13.0 → 0.15.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 +129 -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 +4 -3
  17. package/dist/read-array-list.js +41 -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 +16 -5
  23. package/dist/read-cursor.js +678 -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 +4 -3
  29. package/dist/read-linked-array-list.js +41 -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
@@ -0,0 +1,65 @@
1
+ import { HashMapGet, HashMapGetValue, HashMapGetKey, HashMapGetKVPair } from './database.js';
2
+ import { UnexpectedTagException } from './exceptions.js';
3
+ export class ReadHashMap {
4
+ cursor;
5
+ constructor(cursor) {
6
+ if (cursor) {
7
+ switch (cursor.slotPtr.slot.tag) {
8
+ case 0 /* Tag.NONE */:
9
+ case 4 /* Tag.HASH_MAP */:
10
+ case 11 /* Tag.HASH_SET */:
11
+ this.cursor = cursor;
12
+ break;
13
+ default:
14
+ throw new UnexpectedTagException();
15
+ }
16
+ }
17
+ }
18
+ slot() {
19
+ return this.cursor.slot();
20
+ }
21
+ iterator() {
22
+ return this.cursor.iterator();
23
+ }
24
+ *[Symbol.iterator]() {
25
+ yield* this.cursor;
26
+ }
27
+ getCursor(key) {
28
+ const hash = this.resolveHash(key);
29
+ return this.cursor.readPath([new HashMapGet(new HashMapGetValue(hash))]);
30
+ }
31
+ getSlot(key) {
32
+ const hash = this.resolveHash(key);
33
+ return this.cursor.readPathSlot([new HashMapGet(new HashMapGetValue(hash))]);
34
+ }
35
+ getKeyCursor(key) {
36
+ const hash = this.resolveHash(key);
37
+ return this.cursor.readPath([new HashMapGet(new HashMapGetKey(hash))]);
38
+ }
39
+ getKeySlot(key) {
40
+ const hash = this.resolveHash(key);
41
+ return this.cursor.readPathSlot([new HashMapGet(new HashMapGetKey(hash))]);
42
+ }
43
+ getKeyValuePair(key) {
44
+ const hash = this.resolveHash(key);
45
+ const cursor = this.cursor.readPath([new HashMapGet(new HashMapGetKVPair(hash))]);
46
+ if (cursor === null) {
47
+ return null;
48
+ }
49
+ else {
50
+ return cursor.readKeyValuePair();
51
+ }
52
+ }
53
+ // Helper to resolve key to hash
54
+ resolveHash(key) {
55
+ if (key instanceof Uint8Array) {
56
+ return key;
57
+ }
58
+ else if (typeof key === 'string') {
59
+ return this.cursor.db.hasher.digest(new TextEncoder().encode(key));
60
+ }
61
+ else {
62
+ return this.cursor.db.hasher.digest(key.value);
63
+ }
64
+ }
65
+ }
@@ -1,7 +1,7 @@
1
- import { Slot } from './slot';
2
- import type { Slotted } from './slotted';
3
- import { ReadCursor, CursorIterator } from './read-cursor';
4
- import { Bytes } from './writeable-data';
1
+ import { Slot } from './slot.js';
2
+ import type { Slotted } from './slotted.js';
3
+ import { ReadCursor, CursorIterator } from './read-cursor.js';
4
+ import { Bytes } from './writeable-data.js';
5
5
  export declare class ReadHashSet implements Slotted {
6
6
  cursor: ReadCursor;
7
7
  constructor();
@@ -0,0 +1,47 @@
1
+ import { HashMapGet, HashMapGetKey } from './database.js';
2
+ import { UnexpectedTagException } from './exceptions.js';
3
+ export class ReadHashSet {
4
+ cursor;
5
+ constructor(cursor) {
6
+ if (cursor) {
7
+ switch (cursor.slotPtr.slot.tag) {
8
+ case 0 /* Tag.NONE */:
9
+ case 4 /* Tag.HASH_MAP */:
10
+ case 11 /* Tag.HASH_SET */:
11
+ this.cursor = cursor;
12
+ break;
13
+ default:
14
+ throw new UnexpectedTagException();
15
+ }
16
+ }
17
+ }
18
+ slot() {
19
+ return this.cursor.slot();
20
+ }
21
+ iterator() {
22
+ return this.cursor.iterator();
23
+ }
24
+ *[Symbol.iterator]() {
25
+ yield* this.cursor;
26
+ }
27
+ getCursor(key) {
28
+ const hash = this.resolveHash(key);
29
+ return this.cursor.readPath([new HashMapGet(new HashMapGetKey(hash))]);
30
+ }
31
+ getSlot(key) {
32
+ const hash = this.resolveHash(key);
33
+ return this.cursor.readPathSlot([new HashMapGet(new HashMapGetKey(hash))]);
34
+ }
35
+ // Helper to resolve key to hash
36
+ resolveHash(key) {
37
+ if (key instanceof Uint8Array) {
38
+ return key;
39
+ }
40
+ else if (typeof key === 'string') {
41
+ return this.cursor.db.hasher.digest(new TextEncoder().encode(key));
42
+ }
43
+ else {
44
+ return this.cursor.db.hasher.digest(key.value);
45
+ }
46
+ }
47
+ }
@@ -1,6 +1,6 @@
1
- import { Slot } from './slot';
2
- import type { Slotted } from './slotted';
3
- import { ReadCursor, CursorIterator } from './read-cursor';
1
+ import { Slot } from './slot.js';
2
+ import type { Slotted } from './slotted.js';
3
+ import { ReadCursor, CursorIterator } from './read-cursor.js';
4
4
  export declare class ReadLinkedArrayList implements Slotted {
5
5
  cursor: ReadCursor;
6
6
  constructor();
@@ -8,6 +8,7 @@ export declare class ReadLinkedArrayList implements Slotted {
8
8
  slot(): Slot;
9
9
  count(): number;
10
10
  iterator(): CursorIterator;
11
+ iteratorFrom(index: number): CursorIterator;
11
12
  [Symbol.iterator](): Iterator<ReadCursor>;
12
13
  getCursor(index: number): ReadCursor | null;
13
14
  getSlot(index: number): Slot | null;
@@ -0,0 +1,41 @@
1
+ import { CursorIterator } from './read-cursor.js';
2
+ import { LinkedArrayListGet } from './database.js';
3
+ import { UnexpectedTagException } from './exceptions.js';
4
+ export class ReadLinkedArrayList {
5
+ cursor;
6
+ constructor(cursor) {
7
+ if (cursor) {
8
+ switch (cursor.slotPtr.slot.tag) {
9
+ case 0 /* Tag.NONE */:
10
+ case 3 /* Tag.LINKED_ARRAY_LIST */:
11
+ this.cursor = cursor;
12
+ break;
13
+ default:
14
+ throw new UnexpectedTagException();
15
+ }
16
+ }
17
+ }
18
+ slot() {
19
+ return this.cursor.slot();
20
+ }
21
+ count() {
22
+ return this.cursor.count();
23
+ }
24
+ iterator() {
25
+ return this.cursor.iterator();
26
+ }
27
+ // iterate starting at the given index, seeking straight to it instead of
28
+ // walking from the front. negative indexes count from the end.
29
+ iteratorFrom(index) {
30
+ return CursorIterator.initLinkedArrayListFromIndex(this.cursor, index);
31
+ }
32
+ *[Symbol.iterator]() {
33
+ yield* this.cursor;
34
+ }
35
+ getCursor(index) {
36
+ return this.cursor.readPath([new LinkedArrayListGet(index)]);
37
+ }
38
+ getSlot(index) {
39
+ return this.cursor.readPathSlot([new LinkedArrayListGet(index)]);
40
+ }
41
+ }
@@ -0,0 +1,21 @@
1
+ import { Slot } from './slot.js';
2
+ import type { Slotted } from './slotted.js';
3
+ import { ReadCursor, CursorIterator, KeyValuePairCursor } from './read-cursor.js';
4
+ import { Bytes } from './writeable-data.js';
5
+ export declare class ReadSortedMap implements Slotted {
6
+ cursor: ReadCursor;
7
+ constructor();
8
+ constructor(cursor: ReadCursor);
9
+ slot(): Slot;
10
+ count(): number;
11
+ iterator(): CursorIterator;
12
+ [Symbol.iterator](): Iterator<ReadCursor>;
13
+ iteratorFrom(key: string | Bytes | Uint8Array): CursorIterator;
14
+ iteratorFromIndex(startIndex: number): CursorIterator;
15
+ getCursor(key: string | Bytes | Uint8Array): ReadCursor | null;
16
+ getSlot(key: string | Bytes | Uint8Array): Slot | null;
17
+ getKeyValuePair(key: string | Bytes | Uint8Array): KeyValuePairCursor | null;
18
+ getIndexKeyValuePair(index: number): KeyValuePairCursor | null;
19
+ rank(key: string | Bytes | Uint8Array): number;
20
+ protected resolveKey(key: string | Bytes | Uint8Array): Uint8Array;
21
+ }
@@ -0,0 +1,73 @@
1
+ import { CursorIterator } from './read-cursor.js';
2
+ import { SortedMapGet, SortedMapGetValue, SortedMapGetKVPair, SortedMapGetIndex, BTreeHeader, } from './database.js';
3
+ import { UnexpectedTagException } from './exceptions.js';
4
+ export class ReadSortedMap {
5
+ cursor;
6
+ constructor(cursor) {
7
+ if (cursor) {
8
+ switch (cursor.slotPtr.slot.tag) {
9
+ case 0 /* Tag.NONE */:
10
+ case 14 /* Tag.SORTED_MAP */:
11
+ case 15 /* Tag.SORTED_SET */:
12
+ this.cursor = cursor;
13
+ break;
14
+ default:
15
+ throw new UnexpectedTagException();
16
+ }
17
+ }
18
+ }
19
+ slot() {
20
+ return this.cursor.slot();
21
+ }
22
+ count() {
23
+ return this.cursor.count();
24
+ }
25
+ iterator() {
26
+ return this.cursor.iterator();
27
+ }
28
+ *[Symbol.iterator]() {
29
+ yield* this.cursor;
30
+ }
31
+ // iterate in key order starting at the first entry with key >= startKey
32
+ iteratorFrom(key) {
33
+ return CursorIterator.initSortedFromKey(this.cursor, this.resolveKey(key));
34
+ }
35
+ // iterate in key order starting at the entry with rank startIndex
36
+ iteratorFromIndex(startIndex) {
37
+ return CursorIterator.initSortedFromIndex(this.cursor, startIndex);
38
+ }
39
+ getCursor(key) {
40
+ return this.cursor.readPath([new SortedMapGet(new SortedMapGetValue(this.resolveKey(key)))]);
41
+ }
42
+ getSlot(key) {
43
+ return this.cursor.readPathSlot([new SortedMapGet(new SortedMapGetValue(this.resolveKey(key)))]);
44
+ }
45
+ getKeyValuePair(key) {
46
+ const cursor = this.cursor.readPath([new SortedMapGet(new SortedMapGetKVPair(this.resolveKey(key)))]);
47
+ return cursor === null ? null : cursor.readKeyValuePair();
48
+ }
49
+ // the key/value pair at the given rank (negative counts from the end)
50
+ getIndexKeyValuePair(index) {
51
+ const cursor = this.cursor.readPath([new SortedMapGetIndex(index)]);
52
+ return cursor === null ? null : cursor.readKeyValuePair();
53
+ }
54
+ // number of keys strictly less than key (the inverse of getIndexKeyValuePair)
55
+ rank(key) {
56
+ if (this.cursor.slotPtr.slot.tag === 0 /* Tag.NONE */)
57
+ return 0;
58
+ this.cursor.db.core.seek(Number(this.cursor.slotPtr.slot.value));
59
+ const reader = this.cursor.db.core.reader();
60
+ const headerBytes = new Uint8Array(BTreeHeader.LENGTH);
61
+ reader.readFully(headerBytes);
62
+ const header = BTreeHeader.fromBytes(headerBytes);
63
+ return this.cursor.db.sortedRank(header.rootPtr, this.resolveKey(key));
64
+ }
65
+ // sorted-map keys are byte strings, not hashes
66
+ resolveKey(key) {
67
+ if (key instanceof Uint8Array)
68
+ return key;
69
+ if (typeof key === 'string')
70
+ return new TextEncoder().encode(key);
71
+ return key.value;
72
+ }
73
+ }
@@ -0,0 +1,19 @@
1
+ import { Slot } from './slot.js';
2
+ import type { Slotted } from './slotted.js';
3
+ import { ReadCursor, CursorIterator, KeyValuePairCursor } from './read-cursor.js';
4
+ import { Bytes } from './writeable-data.js';
5
+ export declare class ReadSortedSet implements Slotted {
6
+ cursor: ReadCursor;
7
+ constructor();
8
+ constructor(cursor: ReadCursor);
9
+ slot(): Slot;
10
+ count(): number;
11
+ iterator(): CursorIterator;
12
+ [Symbol.iterator](): Iterator<ReadCursor>;
13
+ iteratorFrom(key: string | Bytes | Uint8Array): CursorIterator;
14
+ iteratorFromIndex(startIndex: number): CursorIterator;
15
+ getIndexKeyValuePair(index: number): KeyValuePairCursor | null;
16
+ contains(key: string | Bytes | Uint8Array): boolean;
17
+ rank(key: string | Bytes | Uint8Array): number;
18
+ protected resolveKey(key: string | Bytes | Uint8Array): Uint8Array;
19
+ }
@@ -0,0 +1,65 @@
1
+ import { CursorIterator } from './read-cursor.js';
2
+ import { SortedMapGet, SortedMapGetKey, SortedMapGetIndex, BTreeHeader } from './database.js';
3
+ import { UnexpectedTagException } from './exceptions.js';
4
+ // a sorted set of byte-string keys (a SortedMap with no values).
5
+ export class ReadSortedSet {
6
+ cursor;
7
+ constructor(cursor) {
8
+ if (cursor) {
9
+ switch (cursor.slotPtr.slot.tag) {
10
+ case 0 /* Tag.NONE */:
11
+ case 14 /* Tag.SORTED_MAP */:
12
+ case 15 /* Tag.SORTED_SET */:
13
+ this.cursor = cursor;
14
+ break;
15
+ default:
16
+ throw new UnexpectedTagException();
17
+ }
18
+ }
19
+ }
20
+ slot() {
21
+ return this.cursor.slot();
22
+ }
23
+ count() {
24
+ return this.cursor.count();
25
+ }
26
+ iterator() {
27
+ return this.cursor.iterator();
28
+ }
29
+ *[Symbol.iterator]() {
30
+ yield* this.cursor;
31
+ }
32
+ iteratorFrom(key) {
33
+ return CursorIterator.initSortedFromKey(this.cursor, this.resolveKey(key));
34
+ }
35
+ iteratorFromIndex(startIndex) {
36
+ return CursorIterator.initSortedFromIndex(this.cursor, startIndex);
37
+ }
38
+ // the key/value pair at the given rank (negative counts from the end)
39
+ getIndexKeyValuePair(index) {
40
+ const cursor = this.cursor.readPath([new SortedMapGetIndex(index)]);
41
+ return cursor === null ? null : cursor.readKeyValuePair();
42
+ }
43
+ contains(key) {
44
+ return this.cursor.readPath([new SortedMapGet(new SortedMapGetKey(this.resolveKey(key)))]) !== null;
45
+ }
46
+ // number of keys strictly less than key
47
+ rank(key) {
48
+ if (this.cursor.slotPtr.slot.tag === 0 /* Tag.NONE */)
49
+ return 0;
50
+ this.cursor.db.core.seek(Number(this.cursor.slotPtr.slot.value));
51
+ const reader = this.cursor.db.core.reader();
52
+ const headerBytes = new Uint8Array(BTreeHeader.LENGTH);
53
+ reader.readFully(headerBytes);
54
+ const header = BTreeHeader.fromBytes(headerBytes);
55
+ return this.cursor.db.sortedRank(header.rootPtr, this.resolveKey(key));
56
+ }
57
+ // sorted-set keys are byte strings, not hashes
58
+ resolveKey(key) {
59
+ if (key instanceof Uint8Array)
60
+ return key;
61
+ if (typeof key === 'string')
62
+ return new TextEncoder().encode(key);
63
+ return key.value;
64
+ }
65
+ }
@@ -1,4 +1,4 @@
1
- import { Slot } from './slot';
1
+ import { Slot } from './slot.js';
2
2
  export declare class SlotPointer {
3
3
  readonly position: number | null;
4
4
  readonly slot: Slot;
@@ -0,0 +1,11 @@
1
+ export class SlotPointer {
2
+ position;
3
+ slot;
4
+ constructor(position, slot) {
5
+ this.position = position;
6
+ this.slot = slot;
7
+ }
8
+ withSlot(slot) {
9
+ return new SlotPointer(this.position, slot);
10
+ }
11
+ }
package/dist/slot.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Tag } from './tag';
2
- import type { WriteableData } from './writeable-data';
1
+ import { Tag } from './tag.js';
2
+ import type { WriteableData } from './writeable-data.js';
3
3
  export declare class Slot implements WriteableData {
4
4
  static readonly LENGTH = 9;
5
5
  readonly value: bigint;
package/dist/slot.js ADDED
@@ -0,0 +1,41 @@
1
+ import { tagValueOf } from './tag.js';
2
+ export class Slot {
3
+ static LENGTH = 9;
4
+ value;
5
+ tag;
6
+ full;
7
+ constructor(value = 0n, tag = 0 /* Tag.NONE */, full = false) {
8
+ this.value = typeof value === 'bigint' ? value : BigInt(value);
9
+ this.tag = tag;
10
+ this.full = full;
11
+ }
12
+ withTag(tag) {
13
+ return new Slot(this.value, tag, this.full);
14
+ }
15
+ withFull(full) {
16
+ return new Slot(this.value, this.tag, full);
17
+ }
18
+ empty() {
19
+ return this.tag === 0 /* Tag.NONE */ && !this.full;
20
+ }
21
+ toBytes() {
22
+ const buffer = new ArrayBuffer(Slot.LENGTH);
23
+ const view = new DataView(buffer);
24
+ let tagInt = this.full ? 0b1000_0000 : 0;
25
+ tagInt = tagInt | this.tag;
26
+ view.setUint8(0, tagInt);
27
+ view.setBigInt64(1, this.value, false);
28
+ return new Uint8Array(buffer);
29
+ }
30
+ static fromBytes(bytes) {
31
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
32
+ const tagByte = view.getUint8(0);
33
+ const full = (tagByte & 0b1000_0000) !== 0;
34
+ const tag = tagValueOf(tagByte & 0b0111_1111);
35
+ const value = view.getBigInt64(1, false);
36
+ return new Slot(value, tag, full);
37
+ }
38
+ equals(other) {
39
+ return this.value === other.value && this.tag === other.tag && this.full === other.full;
40
+ }
41
+ }
package/dist/slotted.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Slot } from './slot';
1
+ import type { Slot } from './slot.js';
2
2
  export interface Slotted {
3
3
  slot(): Slot;
4
4
  }
@@ -0,0 +1 @@
1
+ export {};
package/dist/tag.d.ts CHANGED
@@ -12,6 +12,8 @@ export declare const enum Tag {
12
12
  FLOAT = 10,
13
13
  HASH_SET = 11,
14
14
  COUNTED_HASH_MAP = 12,
15
- COUNTED_HASH_SET = 13
15
+ COUNTED_HASH_SET = 13,
16
+ SORTED_MAP = 14,
17
+ SORTED_SET = 15
16
18
  }
17
19
  export declare function tagValueOf(n: number): Tag;
package/dist/tag.js ADDED
@@ -0,0 +1,25 @@
1
+ export var Tag;
2
+ (function (Tag) {
3
+ Tag[Tag["NONE"] = 0] = "NONE";
4
+ Tag[Tag["INDEX"] = 1] = "INDEX";
5
+ Tag[Tag["ARRAY_LIST"] = 2] = "ARRAY_LIST";
6
+ Tag[Tag["LINKED_ARRAY_LIST"] = 3] = "LINKED_ARRAY_LIST";
7
+ Tag[Tag["HASH_MAP"] = 4] = "HASH_MAP";
8
+ Tag[Tag["KV_PAIR"] = 5] = "KV_PAIR";
9
+ Tag[Tag["BYTES"] = 6] = "BYTES";
10
+ Tag[Tag["SHORT_BYTES"] = 7] = "SHORT_BYTES";
11
+ Tag[Tag["UINT"] = 8] = "UINT";
12
+ Tag[Tag["INT"] = 9] = "INT";
13
+ Tag[Tag["FLOAT"] = 10] = "FLOAT";
14
+ Tag[Tag["HASH_SET"] = 11] = "HASH_SET";
15
+ Tag[Tag["COUNTED_HASH_MAP"] = 12] = "COUNTED_HASH_MAP";
16
+ Tag[Tag["COUNTED_HASH_SET"] = 13] = "COUNTED_HASH_SET";
17
+ Tag[Tag["SORTED_MAP"] = 14] = "SORTED_MAP";
18
+ Tag[Tag["SORTED_SET"] = 15] = "SORTED_SET";
19
+ })(Tag || (Tag = {}));
20
+ export function tagValueOf(n) {
21
+ if (n < 0 || n > 15) {
22
+ throw new Error(`Invalid tag value: ${n}`);
23
+ }
24
+ return n;
25
+ }
@@ -1,7 +1,7 @@
1
- import { ReadArrayList } from './read-array-list';
2
- import { WriteCursor, WriteCursorIterator } from './write-cursor';
3
- import { type ContextFunction } from './database';
4
- import type { WriteableData } from './writeable-data';
1
+ import { ReadArrayList } from './read-array-list.js';
2
+ import { WriteCursor, WriteCursorIterator } from './write-cursor.js';
3
+ import { type ContextFunction } from './database.js';
4
+ import type { WriteableData } from './writeable-data.js';
5
5
  export declare class WriteArrayList extends ReadArrayList {
6
6
  constructor(cursor: WriteCursor);
7
7
  iterator(): WriteCursorIterator;
@@ -0,0 +1,42 @@
1
+ import { ReadArrayList } from './read-array-list.js';
2
+ import { ArrayListInit, ArrayListGet, ArrayListAppend, ArrayListSlice, WriteData, Context, } from './database.js';
3
+ export class WriteArrayList extends ReadArrayList {
4
+ constructor(cursor) {
5
+ super();
6
+ this.cursor = cursor.writePath([new ArrayListInit()]);
7
+ }
8
+ iterator() {
9
+ return this.cursor.iterator();
10
+ }
11
+ *[Symbol.iterator]() {
12
+ yield* this.cursor;
13
+ }
14
+ put(index, data) {
15
+ this.cursor.writePath([
16
+ new ArrayListGet(index),
17
+ new WriteData(data),
18
+ ]);
19
+ }
20
+ putCursor(index) {
21
+ return this.cursor.writePath([new ArrayListGet(index)]);
22
+ }
23
+ append(data) {
24
+ this.cursor.writePath([
25
+ new ArrayListAppend(),
26
+ new WriteData(data),
27
+ ]);
28
+ }
29
+ appendCursor() {
30
+ return this.cursor.writePath([new ArrayListAppend()]);
31
+ }
32
+ appendContext(data, fn) {
33
+ this.cursor.writePath([
34
+ new ArrayListAppend(),
35
+ new WriteData(data),
36
+ new Context(fn),
37
+ ]);
38
+ }
39
+ slice(size) {
40
+ this.cursor.writePath([new ArrayListSlice(size)]);
41
+ }
42
+ }
@@ -1,5 +1,5 @@
1
- import { WriteHashMap } from './write-hash-map';
2
- import { WriteCursor } from './write-cursor';
1
+ import { WriteHashMap } from './write-hash-map.js';
2
+ import { WriteCursor } from './write-cursor.js';
3
3
  export declare class WriteCountedHashMap extends WriteHashMap {
4
4
  constructor(cursor: WriteCursor);
5
5
  count(): number;
@@ -0,0 +1,18 @@
1
+ import { WriteHashMap } from './write-hash-map.js';
2
+ import { UnexpectedTagException } from './exceptions.js';
3
+ export class WriteCountedHashMap extends WriteHashMap {
4
+ constructor(cursor) {
5
+ switch (cursor.slotPtr.slot.tag) {
6
+ case 0 /* Tag.NONE */:
7
+ case 12 /* Tag.COUNTED_HASH_MAP */:
8
+ case 13 /* Tag.COUNTED_HASH_SET */:
9
+ super(cursor, true);
10
+ break;
11
+ default:
12
+ throw new UnexpectedTagException();
13
+ }
14
+ }
15
+ count() {
16
+ return this.cursor.count();
17
+ }
18
+ }
@@ -1,5 +1,5 @@
1
- import { WriteHashSet } from './write-hash-set';
2
- import { WriteCursor } from './write-cursor';
1
+ import { WriteHashSet } from './write-hash-set.js';
2
+ import { WriteCursor } from './write-cursor.js';
3
3
  export declare class WriteCountedHashSet extends WriteHashSet {
4
4
  constructor(cursor: WriteCursor);
5
5
  count(): number;
@@ -0,0 +1,18 @@
1
+ import { WriteHashSet } from './write-hash-set.js';
2
+ import { UnexpectedTagException } from './exceptions.js';
3
+ export class WriteCountedHashSet extends WriteHashSet {
4
+ constructor(cursor) {
5
+ switch (cursor.slotPtr.slot.tag) {
6
+ case 0 /* Tag.NONE */:
7
+ case 12 /* Tag.COUNTED_HASH_MAP */:
8
+ case 13 /* Tag.COUNTED_HASH_SET */:
9
+ super(cursor, true);
10
+ break;
11
+ default:
12
+ throw new UnexpectedTagException();
13
+ }
14
+ }
15
+ count() {
16
+ return this.cursor.count();
17
+ }
18
+ }
@@ -1,8 +1,8 @@
1
- import { Slot } from './slot';
2
- import { SlotPointer } from './slot-pointer';
3
- import { Database, type PathPart } from './database';
4
- import { ReadCursor, KeyValuePairCursor, CursorIterator } from './read-cursor';
5
- import type { WriteableData } from './writeable-data';
1
+ import { Slot } from './slot.js';
2
+ import { SlotPointer } from './slot-pointer.js';
3
+ import { Database, type PathPart } from './database.js';
4
+ import { ReadCursor, KeyValuePairCursor, CursorIterator } from './read-cursor.js';
5
+ import type { WriteableData } from './writeable-data.js';
6
6
  export declare class WriteKeyValuePairCursor extends KeyValuePairCursor {
7
7
  valueCursor: WriteCursor;
8
8
  keyCursor: WriteCursor;