@bodil/bdb 0.1.3 → 0.2.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/README.md +28 -7
- package/dist/backend.d.ts +40 -0
- package/dist/backend.js +31 -0
- package/dist/backend.js.map +1 -1
- package/dist/index.d.ts +80 -9
- package/dist/index.js +22 -17
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +37 -15
- package/dist/index.test.js.map +1 -1
- package/dist/indices.d.ts +6 -0
- package/dist/indices.js +6 -0
- package/dist/indices.js.map +1 -1
- package/dist/query.d.ts +26 -22
- package/dist/query.js +4 -1
- package/dist/query.js.map +1 -1
- package/dist/table.d.ts +152 -31
- package/dist/table.js +145 -13
- package/dist/table.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/backend.ts +40 -0
- package/src/index.test.ts +43 -17
- package/src/index.ts +112 -45
- package/src/indices.ts +11 -6
- package/src/query.ts +53 -45
- package/src/table.ts +224 -64
- package/src/types.ts +1 -1
package/dist/query.d.ts
CHANGED
|
@@ -6,46 +6,50 @@ export declare enum IteratorDirection {
|
|
|
6
6
|
Ascending = 0,
|
|
7
7
|
Descending = 1
|
|
8
8
|
}
|
|
9
|
-
export declare abstract class Query<
|
|
10
|
-
abstract [Symbol.iterator](): IterableIterator<Readonly<
|
|
11
|
-
abstract signal(): Signal.Computed<Array<Readonly<
|
|
12
|
-
map<B>(mapFn: (item: Readonly<
|
|
13
|
-
forEach(action: (item:
|
|
14
|
-
toArray(): Array<Readonly<
|
|
9
|
+
export declare abstract class Query<Document extends object> implements Iterable<Readonly<Document>> {
|
|
10
|
+
abstract [Symbol.iterator](): IterableIterator<Readonly<Document>>;
|
|
11
|
+
abstract signal(): Signal.Computed<Array<Readonly<Document>>>;
|
|
12
|
+
map<B>(mapFn: (item: Readonly<Document>) => B): IterableIterator<B>;
|
|
13
|
+
forEach(action: (item: Document) => void): void;
|
|
14
|
+
toArray(): Array<Readonly<Document>>;
|
|
15
15
|
}
|
|
16
|
-
export declare abstract class TableQuery<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
export declare abstract class TableQuery<Document extends object, PI extends UnitIndex<Document>, Ix extends object> extends Query<Document> {
|
|
17
|
+
/** @ignore */
|
|
18
|
+
protected table: Table<Document, PI, Ix>;
|
|
19
|
+
constructor(table: Table<Document, PI, Ix>);
|
|
20
|
+
signal(): Signal.Computed<Array<Readonly<Document>>>;
|
|
21
|
+
/**
|
|
22
|
+
* Delete all documents from the table matching this query.
|
|
23
|
+
*/
|
|
20
24
|
delete(): number;
|
|
21
|
-
filter(predicate: (item: Readonly<
|
|
22
|
-
limit(count: number): ChainQuery<
|
|
25
|
+
filter(predicate: (item: Readonly<Document>) => boolean): ChainQuery<Document, PI, Ix>;
|
|
26
|
+
limit(count: number): ChainQuery<Document, PI, Ix>;
|
|
23
27
|
}
|
|
24
|
-
export declare class IndexQuery<
|
|
28
|
+
export declare class IndexQuery<Document extends object, PI extends UnitIndex<Document>, I extends Index<Document>, Ix extends object> extends TableQuery<Document, PI, Ix> {
|
|
25
29
|
private readonly index;
|
|
26
30
|
private readonly indexTable?;
|
|
27
31
|
private readonly isPrimary;
|
|
28
32
|
private start?;
|
|
29
33
|
private skipStart;
|
|
30
34
|
private direction;
|
|
31
|
-
constructor(table: Table<
|
|
32
|
-
[Symbol.iterator](): IterableIterator<Readonly<
|
|
35
|
+
constructor(table: Table<Document, PI, Ix>, indexKey: keyof Ix & string, direction: IteratorDirection, start?: I["keyType"]);
|
|
36
|
+
[Symbol.iterator](): IterableIterator<Readonly<Document>>;
|
|
33
37
|
reverse(): this;
|
|
34
|
-
equals(value: I["keyType"]): ArrayQuery<
|
|
38
|
+
equals(value: I["keyType"]): ArrayQuery<Document, PI, Ix>;
|
|
35
39
|
below(value: I["keyType"]): this;
|
|
36
40
|
above(value: I["keyType"]): this;
|
|
37
41
|
inclusive(): this;
|
|
38
42
|
max(): Option<I["keyType"]>;
|
|
39
43
|
min(): Option<I["keyType"]>;
|
|
40
44
|
}
|
|
41
|
-
export declare class ChainQuery<
|
|
45
|
+
export declare class ChainQuery<Document extends object, PI extends UnitIndex<Document>, Ix extends object> extends TableQuery<Document, PI, Ix> {
|
|
42
46
|
private readonly parent;
|
|
43
47
|
private readonly iterator;
|
|
44
|
-
constructor(table: Table<
|
|
45
|
-
[Symbol.iterator](): IterableIterator<Readonly<
|
|
48
|
+
constructor(table: Table<Document, PI, Ix>, parent: Query<Document>, iterator: (parentIterator: IterableIterator<Readonly<Document>>) => IterableIterator<Readonly<Document>>);
|
|
49
|
+
[Symbol.iterator](): IterableIterator<Readonly<Document>>;
|
|
46
50
|
}
|
|
47
|
-
export declare class ArrayQuery<
|
|
51
|
+
export declare class ArrayQuery<Document extends object, PI extends UnitIndex<Document>, Ix extends object> extends TableQuery<Document, PI, Ix> {
|
|
48
52
|
private readonly values;
|
|
49
|
-
constructor(table: Table<
|
|
50
|
-
[Symbol.iterator](): IterableIterator<Readonly<
|
|
53
|
+
constructor(table: Table<Document, PI, Ix>, values: Array<Readonly<Document>>);
|
|
54
|
+
[Symbol.iterator](): IterableIterator<Readonly<Document>>;
|
|
51
55
|
}
|
package/dist/query.js
CHANGED
|
@@ -64,8 +64,11 @@ export class TableQuery extends Query {
|
|
|
64
64
|
return Array.from(this);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Delete all documents from the table matching this query.
|
|
69
|
+
*/
|
|
67
70
|
delete() {
|
|
68
|
-
return this.table.delete(...Array.from(this));
|
|
71
|
+
return this.table.delete(...Array.from(this).map((doc) => this.table.primaryIndex.extractKey(doc)));
|
|
69
72
|
}
|
|
70
73
|
filter(predicate) {
|
|
71
74
|
return new ChainQuery(this.table, this, (iter) => Iterator.from(iter).filter(predicate));
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"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YACI,KAA8B,EAC9B,MAAuB,EACvB,QAEyC;QAEzC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;CACJ;AAED,MAAM,OAAO,UAIX,SAAQ,UAA4B;IAGlC,YAAY,KAA8B,EAAE,MAAiC;QACzE,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1C,CAAC;CACJ"}
|
package/dist/table.d.ts
CHANGED
|
@@ -15,61 +15,182 @@ export type TableEvent<A extends object, PK> = {
|
|
|
15
15
|
type: "delete";
|
|
16
16
|
key: PK;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A database table.
|
|
20
|
+
*
|
|
21
|
+
* To learn how to create a table, see the static method {@link Table.create}.
|
|
22
|
+
*
|
|
23
|
+
* @template Document The type of the documents this table stores.
|
|
24
|
+
*/
|
|
25
|
+
export declare class Table<Document extends object, PrimaryIndex extends UnitIndex<Document>, Indices extends object> extends Emitter<TableEvent<Document, PrimaryIndex["keyType"]>> implements Disposable, Iterable<Readonly<Document>> {
|
|
19
26
|
#private;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A promise which resolves when this table is ready to use.
|
|
29
|
+
*
|
|
30
|
+
* If the table isn't connected to a {@link StorageBackend}, this is a
|
|
31
|
+
* promise which resolves immediately, and you don't really need to await
|
|
32
|
+
* it. The table will be ready for use immediately.
|
|
33
|
+
*
|
|
34
|
+
* With an attached {@link StorageBackend}, this promise will resolve when
|
|
35
|
+
* the table has finished restoring its contents from the storage. You
|
|
36
|
+
* should not under any circumstances use the table before this is complete.
|
|
37
|
+
*/
|
|
38
|
+
get ready(): Promise<void>;
|
|
39
|
+
/** @ignore */
|
|
40
|
+
readonly primaryIndex: PrimaryIndex;
|
|
41
|
+
/** @ignore */
|
|
42
|
+
readonly primary: BTree<PrimaryIndex["keyType"], Readonly<Document>>;
|
|
43
|
+
/** @ignore */
|
|
23
44
|
readonly indices: {
|
|
24
|
-
[K in Exclude<keyof
|
|
45
|
+
[K in Exclude<keyof Indices & string, PrimaryIndex["name"]>]: Index<Document>;
|
|
25
46
|
};
|
|
47
|
+
/** @ignore */
|
|
26
48
|
readonly indexTables: {
|
|
27
|
-
[K in Exclude<keyof
|
|
49
|
+
[K in Exclude<keyof Indices & string, PrimaryIndex["name"]>]: BTree<Indices[K], Array<Document>>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A signal which updates whenever the table has been modified.
|
|
53
|
+
*/
|
|
54
|
+
get changed(): Signal.Computed<null>;
|
|
55
|
+
/**
|
|
56
|
+
* Create a database {@link Table}.
|
|
57
|
+
*
|
|
58
|
+
* `Table.create` is a function which takes one type argument, the type of the
|
|
59
|
+
* object (which we'll call a *document*) you want the table to store, and no
|
|
60
|
+
* value arguments.
|
|
61
|
+
*
|
|
62
|
+
* This returns an object with one method: `withPrimaryIndex`. This method is
|
|
63
|
+
* what actually creates the table. So, the full incantation is, for instance:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* type Document = { id: string; value: number };
|
|
67
|
+
* const table = Table.create<Document>()
|
|
68
|
+
* .withPrimaryIndex(index<Document>().key("id"));
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* In order to look up something in a database table, you need an index. You can
|
|
72
|
+
* create an index using the {@link index} function, which, like `Table.create`,
|
|
73
|
+
* takes the document you're creating an index for as its type argument, and
|
|
74
|
+
* returns a selection of index constructors, of which the most straightforward
|
|
75
|
+
* one is {@link IndexConstructor.key}. This creates an index for a single named
|
|
76
|
+
* property of the document containing a primitive comparable value (a string, a
|
|
77
|
+
* number, or a bigint), and allows you to search for documents where the given
|
|
78
|
+
* property matches any given value. You can also create an index over multiple
|
|
79
|
+
* keys using {@link IndexConstructor.keys} or over a key containing an array
|
|
80
|
+
* using {@link IndexConstructor.array}. You can even create a completely
|
|
81
|
+
* customised index using {@link IndexConstructor.custom}.
|
|
82
|
+
*
|
|
83
|
+
* The primary index, unlike a regular index, is a unique identifier, and only
|
|
84
|
+
* one document can exist at any given time under the key or keys represented by
|
|
85
|
+
* the primary index. A table is required to have a primary index, which is why
|
|
86
|
+
* `Table.create` doesn't actually create the table until you call
|
|
87
|
+
* `withPrimaryIndex` on it. You can then add as many extra indices as you like
|
|
88
|
+
* using `withIndex`. To extend our example above with an additional index over
|
|
89
|
+
* the `value` property:
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* type Document = { id: string; value: number };
|
|
93
|
+
* const table = Table.create<Document>()
|
|
94
|
+
* .withPrimaryIndex(index<Document>().key("id"))
|
|
95
|
+
* .withIndex(index<Document>().key("value"));
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @see {@link index}
|
|
99
|
+
*
|
|
100
|
+
* @template Document The type of the document this table stores.
|
|
101
|
+
*/
|
|
102
|
+
static create<Document extends object>(): {
|
|
103
|
+
withPrimaryIndex: <PrimaryIndex extends UnitIndex<Document>>(primaryIndex: PrimaryIndex) => Table<Document, PrimaryIndex, PrimaryIndex["record"]>;
|
|
28
104
|
};
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
105
|
+
/** @internal */
|
|
106
|
+
private constructor();
|
|
31
107
|
[Symbol.dispose](): void;
|
|
32
|
-
|
|
33
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Add an index to a table.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* type Document = { id: string; value: number };
|
|
113
|
+
* const table = Table.create<Document>()
|
|
114
|
+
* .withPrimaryIndex(index<Document>().key("id"))
|
|
115
|
+
* .withIndex(index<Document>().key("value"));
|
|
116
|
+
*/
|
|
117
|
+
withIndex<I extends Index<Document>>(index: I): Table<Document, PrimaryIndex, {
|
|
118
|
+
[K in keyof (Indices & I["record"])]: (Indices & I["record"])[K];
|
|
34
119
|
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Attach a table to a {@link StorageBackend}.
|
|
122
|
+
*
|
|
123
|
+
* See {@link IndexedDBBackend.open} for an example of how to use this.
|
|
124
|
+
*/
|
|
35
125
|
withStorage(backend: StorageBackend, name: string): this;
|
|
36
|
-
signal(primaryKey:
|
|
37
|
-
get(primaryKey:
|
|
126
|
+
signal(primaryKey: PrimaryIndex["keyType"]): Signal.Computed<Readonly<Document> | undefined>;
|
|
127
|
+
get(primaryKey: PrimaryIndex["keyType"]): Readonly<Document> | undefined;
|
|
38
128
|
/**
|
|
39
129
|
* Given a primary key, apply an update function to the value stored under
|
|
40
130
|
* that key. If there's no value, call the create function to create the
|
|
41
131
|
* value before passing it to the update function.
|
|
42
132
|
*/
|
|
43
|
-
createAndUpdate(primaryKey:
|
|
133
|
+
createAndUpdate(primaryKey: PrimaryIndex["keyType"], create: () => Document, update: (item: Draft<Document>) => Draft<Document> | void): Readonly<Document>;
|
|
44
134
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
135
|
+
* Create or update a document.
|
|
136
|
+
*
|
|
137
|
+
* Given a primary key, apply the `update` function to the document stored
|
|
138
|
+
* under that key.
|
|
139
|
+
*
|
|
140
|
+
* If there's no such document, call the `create` function to create a new
|
|
141
|
+
* document and insert that under the given primary key. In this case, the
|
|
142
|
+
* update function is not called.
|
|
143
|
+
*
|
|
144
|
+
* The `update` function is passed to {@link produce | Immer.produce} to
|
|
145
|
+
* perform the update. It should modify the provided document in place, and
|
|
146
|
+
* it's not necessary to return it.
|
|
48
147
|
*/
|
|
49
|
-
createOrUpdate(primaryKey:
|
|
148
|
+
createOrUpdate(primaryKey: PrimaryIndex["keyType"], create: () => Document, update: (item: Draft<Document>) => Draft<Document> | void): Readonly<Document>;
|
|
50
149
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
150
|
+
* Update a document.
|
|
151
|
+
*
|
|
152
|
+
* Apply the `update` function to the document stored under the given
|
|
153
|
+
* primary key.
|
|
154
|
+
*
|
|
155
|
+
* If no such document exists, the update function is not called and
|
|
156
|
+
* `undefined` is returned. Otherwise, the updated document is returned.
|
|
157
|
+
*
|
|
158
|
+
* The `update` function is passed to {@link produce | Immer.produce} to
|
|
159
|
+
* perform the update. It should modify the provided document in place, and
|
|
160
|
+
* it's not necessary to return it.
|
|
54
161
|
*/
|
|
55
|
-
update(primaryKey:
|
|
162
|
+
update(primaryKey: PrimaryIndex["keyType"], update: (item: Draft<Document>) => void | Draft<Document>): Readonly<Document> | undefined;
|
|
56
163
|
/**
|
|
57
|
-
* Add
|
|
164
|
+
* Add documents to the table, overwriting any previous values under their
|
|
58
165
|
* primary keys.
|
|
59
166
|
*/
|
|
60
|
-
add(...items: Array<
|
|
61
|
-
add(items: Iterable<
|
|
167
|
+
add(...items: Array<Document>): void;
|
|
168
|
+
add(items: Iterable<Document>): void;
|
|
62
169
|
/**
|
|
63
|
-
* Delete
|
|
170
|
+
* Delete documents from the table by their primary keys.
|
|
64
171
|
*/
|
|
65
|
-
delete(...primaryKeys: Array<
|
|
66
|
-
delete(primaryKeys: Iterable<
|
|
172
|
+
delete(...primaryKeys: Array<PrimaryIndex["keyType"]>): number;
|
|
173
|
+
delete(primaryKeys: Iterable<PrimaryIndex["keyType"]>): number;
|
|
67
174
|
/**
|
|
68
|
-
* Delete all
|
|
175
|
+
* Delete all documents from the table.
|
|
69
176
|
*/
|
|
70
177
|
clear(): void;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Iterate over the documents in the table, ordered by primary key.
|
|
180
|
+
*/
|
|
181
|
+
[Symbol.iterator](): IteratorObject<Readonly<Document>>;
|
|
182
|
+
/**
|
|
183
|
+
* Perform an {@link IndexQuery} using the specified index.
|
|
184
|
+
*/
|
|
185
|
+
where<K extends keyof Indices & string, I extends Index<Document> & Indices[K]>(index: K): IndexQuery<Document, PrimaryIndex, I, Indices>;
|
|
186
|
+
/**
|
|
187
|
+
* Perform an {@link IndexQuery} using the specified index.
|
|
188
|
+
*
|
|
189
|
+
* This is an alias for {@link Table.where}.
|
|
190
|
+
*/
|
|
191
|
+
orderBy<K extends keyof Indices & string, I extends Index<Document> & Indices[K]>(index: K): IndexQuery<Document, PrimaryIndex, I, Indices>;
|
|
192
|
+
/**
|
|
193
|
+
* Get the number of documents currently stored in the table.
|
|
194
|
+
*/
|
|
74
195
|
size(): number;
|
|
75
196
|
}
|
package/dist/table.js
CHANGED
|
@@ -8,18 +8,105 @@ import BTree from "sorted-btree";
|
|
|
8
8
|
import { CustomIndex } from "./indices";
|
|
9
9
|
import { IndexQuery, IteratorDirection } from "./query";
|
|
10
10
|
import { TableStorage } from "./storage";
|
|
11
|
+
/**
|
|
12
|
+
* A database table.
|
|
13
|
+
*
|
|
14
|
+
* To learn how to create a table, see the static method {@link Table.create}.
|
|
15
|
+
*
|
|
16
|
+
* @template Document The type of the documents this table stores.
|
|
17
|
+
*/
|
|
11
18
|
export class Table extends Emitter {
|
|
19
|
+
/**
|
|
20
|
+
* A promise which resolves when this table is ready to use.
|
|
21
|
+
*
|
|
22
|
+
* If the table isn't connected to a {@link StorageBackend}, this is a
|
|
23
|
+
* promise which resolves immediately, and you don't really need to await
|
|
24
|
+
* it. The table will be ready for use immediately.
|
|
25
|
+
*
|
|
26
|
+
* With an attached {@link StorageBackend}, this promise will resolve when
|
|
27
|
+
* the table has finished restoring its contents from the storage. You
|
|
28
|
+
* should not under any circumstances use the table before this is complete.
|
|
29
|
+
*/
|
|
30
|
+
get ready() {
|
|
31
|
+
return this.#ready;
|
|
32
|
+
}
|
|
33
|
+
#ready;
|
|
34
|
+
#changed;
|
|
35
|
+
/**
|
|
36
|
+
* A signal which updates whenever the table has been modified.
|
|
37
|
+
*/
|
|
38
|
+
get changed() {
|
|
39
|
+
return this.#changed.readOnly;
|
|
40
|
+
}
|
|
12
41
|
#storage;
|
|
13
42
|
#signals;
|
|
14
43
|
#signalCleanupRegistry;
|
|
15
44
|
#context;
|
|
45
|
+
/**
|
|
46
|
+
* Create a database {@link Table}.
|
|
47
|
+
*
|
|
48
|
+
* `Table.create` is a function which takes one type argument, the type of the
|
|
49
|
+
* object (which we'll call a *document*) you want the table to store, and no
|
|
50
|
+
* value arguments.
|
|
51
|
+
*
|
|
52
|
+
* This returns an object with one method: `withPrimaryIndex`. This method is
|
|
53
|
+
* what actually creates the table. So, the full incantation is, for instance:
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* type Document = { id: string; value: number };
|
|
57
|
+
* const table = Table.create<Document>()
|
|
58
|
+
* .withPrimaryIndex(index<Document>().key("id"));
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* In order to look up something in a database table, you need an index. You can
|
|
62
|
+
* create an index using the {@link index} function, which, like `Table.create`,
|
|
63
|
+
* takes the document you're creating an index for as its type argument, and
|
|
64
|
+
* returns a selection of index constructors, of which the most straightforward
|
|
65
|
+
* one is {@link IndexConstructor.key}. This creates an index for a single named
|
|
66
|
+
* property of the document containing a primitive comparable value (a string, a
|
|
67
|
+
* number, or a bigint), and allows you to search for documents where the given
|
|
68
|
+
* property matches any given value. You can also create an index over multiple
|
|
69
|
+
* keys using {@link IndexConstructor.keys} or over a key containing an array
|
|
70
|
+
* using {@link IndexConstructor.array}. You can even create a completely
|
|
71
|
+
* customised index using {@link IndexConstructor.custom}.
|
|
72
|
+
*
|
|
73
|
+
* The primary index, unlike a regular index, is a unique identifier, and only
|
|
74
|
+
* one document can exist at any given time under the key or keys represented by
|
|
75
|
+
* the primary index. A table is required to have a primary index, which is why
|
|
76
|
+
* `Table.create` doesn't actually create the table until you call
|
|
77
|
+
* `withPrimaryIndex` on it. You can then add as many extra indices as you like
|
|
78
|
+
* using `withIndex`. To extend our example above with an additional index over
|
|
79
|
+
* the `value` property:
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* type Document = { id: string; value: number };
|
|
83
|
+
* const table = Table.create<Document>()
|
|
84
|
+
* .withPrimaryIndex(index<Document>().key("id"))
|
|
85
|
+
* .withIndex(index<Document>().key("value"));
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @see {@link index}
|
|
89
|
+
*
|
|
90
|
+
* @template Document The type of the document this table stores.
|
|
91
|
+
*/
|
|
92
|
+
static create() {
|
|
93
|
+
return {
|
|
94
|
+
withPrimaryIndex(primaryIndex) {
|
|
95
|
+
return new Table(primaryIndex);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** @internal */
|
|
16
100
|
constructor(primaryIndex) {
|
|
17
101
|
super();
|
|
18
|
-
this
|
|
102
|
+
this.#ready = Promise.resolve();
|
|
103
|
+
/** @ignore */
|
|
19
104
|
this.primary = new BTree();
|
|
105
|
+
/** @ignore */
|
|
20
106
|
this.indices = {};
|
|
107
|
+
/** @ignore */
|
|
21
108
|
this.indexTables = {};
|
|
22
|
-
this
|
|
109
|
+
this.#changed = Signal.from(null, { equals: () => false });
|
|
23
110
|
this.#signals = new BTree();
|
|
24
111
|
this.#signalCleanupRegistry = new FinalizationRegistry(this.#signalCleanup.bind(this));
|
|
25
112
|
this.#context = new DisposableContext();
|
|
@@ -29,6 +116,15 @@ export class Table extends Emitter {
|
|
|
29
116
|
super[Symbol.dispose]();
|
|
30
117
|
this.#context.dispose();
|
|
31
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Add an index to a table.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* type Document = { id: string; value: number };
|
|
124
|
+
* const table = Table.create<Document>()
|
|
125
|
+
* .withPrimaryIndex(index<Document>().key("id"))
|
|
126
|
+
* .withIndex(index<Document>().key("value"));
|
|
127
|
+
*/
|
|
32
128
|
withIndex(index) {
|
|
33
129
|
assert(this.indices[index.name] === undefined, `duplicate index definition: "${index.name}"`);
|
|
34
130
|
this.indices[index.name] = index;
|
|
@@ -36,9 +132,14 @@ export class Table extends Emitter {
|
|
|
36
132
|
index instanceof CustomIndex ? index.makeIndex() : new BTree();
|
|
37
133
|
return this;
|
|
38
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Attach a table to a {@link StorageBackend}.
|
|
137
|
+
*
|
|
138
|
+
* See {@link IndexedDBBackend.open} for an example of how to use this.
|
|
139
|
+
*/
|
|
39
140
|
withStorage(backend, name) {
|
|
40
141
|
this.#storage = new TableStorage(backend, name, this.primaryIndex);
|
|
41
|
-
this
|
|
142
|
+
this.#ready = this.#storage.ready;
|
|
42
143
|
this.#context.use(this.#storage.on((event) => {
|
|
43
144
|
switch (event.type) {
|
|
44
145
|
case "update":
|
|
@@ -78,9 +179,18 @@ export class Table extends Emitter {
|
|
|
78
179
|
return this.#setItem(item, oldItem, primaryKey);
|
|
79
180
|
}
|
|
80
181
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
182
|
+
* Create or update a document.
|
|
183
|
+
*
|
|
184
|
+
* Given a primary key, apply the `update` function to the document stored
|
|
185
|
+
* under that key.
|
|
186
|
+
*
|
|
187
|
+
* If there's no such document, call the `create` function to create a new
|
|
188
|
+
* document and insert that under the given primary key. In this case, the
|
|
189
|
+
* update function is not called.
|
|
190
|
+
*
|
|
191
|
+
* The `update` function is passed to {@link produce | Immer.produce} to
|
|
192
|
+
* perform the update. It should modify the provided document in place, and
|
|
193
|
+
* it's not necessary to return it.
|
|
84
194
|
*/
|
|
85
195
|
createOrUpdate(primaryKey, create, update) {
|
|
86
196
|
const oldItem = this.primary.get(primaryKey);
|
|
@@ -88,9 +198,17 @@ export class Table extends Emitter {
|
|
|
88
198
|
return this.#setItem(item, oldItem, primaryKey);
|
|
89
199
|
}
|
|
90
200
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
201
|
+
* Update a document.
|
|
202
|
+
*
|
|
203
|
+
* Apply the `update` function to the document stored under the given
|
|
204
|
+
* primary key.
|
|
205
|
+
*
|
|
206
|
+
* If no such document exists, the update function is not called and
|
|
207
|
+
* `undefined` is returned. Otherwise, the updated document is returned.
|
|
208
|
+
*
|
|
209
|
+
* The `update` function is passed to {@link produce | Immer.produce} to
|
|
210
|
+
* perform the update. It should modify the provided document in place, and
|
|
211
|
+
* it's not necessary to return it.
|
|
94
212
|
*/
|
|
95
213
|
update(primaryKey, update) {
|
|
96
214
|
const oldItem = this.primary.get(primaryKey);
|
|
@@ -107,20 +225,34 @@ export class Table extends Emitter {
|
|
|
107
225
|
return this.#deleteFrom(items.length === 1 && isIterable(items[0]) ? items[0] : items);
|
|
108
226
|
}
|
|
109
227
|
/**
|
|
110
|
-
* Delete all
|
|
228
|
+
* Delete all documents from the table.
|
|
111
229
|
*/
|
|
112
230
|
clear() {
|
|
113
231
|
this.delete(...this.primary.keys());
|
|
114
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Iterate over the documents in the table, ordered by primary key.
|
|
235
|
+
*/
|
|
115
236
|
[Symbol.iterator]() {
|
|
116
|
-
return this.primary.values();
|
|
237
|
+
return Iterator.from(this.primary.values());
|
|
117
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Perform an {@link IndexQuery} using the specified index.
|
|
241
|
+
*/
|
|
118
242
|
where(index) {
|
|
119
243
|
return new IndexQuery(this, index, IteratorDirection.Ascending);
|
|
120
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Perform an {@link IndexQuery} using the specified index.
|
|
247
|
+
*
|
|
248
|
+
* This is an alias for {@link Table.where}.
|
|
249
|
+
*/
|
|
121
250
|
orderBy(index) {
|
|
122
251
|
return this.where(index);
|
|
123
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Get the number of documents currently stored in the table.
|
|
255
|
+
*/
|
|
124
256
|
size() {
|
|
125
257
|
return this.primary.size;
|
|
126
258
|
}
|
|
@@ -176,7 +308,7 @@ export class Table extends Emitter {
|
|
|
176
308
|
// emit an update event and update signals
|
|
177
309
|
this.#withSignal(this.primaryIndex.extractKey(item), (sig) => sig.set(item));
|
|
178
310
|
this.emit({ type: "update", item });
|
|
179
|
-
this
|
|
311
|
+
this.#changed.set(null);
|
|
180
312
|
return item;
|
|
181
313
|
}
|
|
182
314
|
#deleteItem(item, primaryKey) {
|
|
@@ -187,7 +319,7 @@ export class Table extends Emitter {
|
|
|
187
319
|
// emit a delete event and update signals
|
|
188
320
|
this.#withSignal(primaryKey, (sig) => sig.set(undefined));
|
|
189
321
|
this.emit({ type: "delete", key: primaryKey });
|
|
190
|
-
this
|
|
322
|
+
this.#changed.set(null);
|
|
191
323
|
}
|
|
192
324
|
#withSignal(primaryKey, fn) {
|
|
193
325
|
const sigRef = this.#signals.get(primaryKey);
|
package/dist/table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAc,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,MAAM,cAAc,CAAC;AAGjC,OAAO,EAAE,WAAW,EAA8B,MAAM,WAAW,CAA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AAI,WAAW,IAAI,CAAC,EAAE,CAAC;wBACnB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BACtB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;wBACtB,CAAC;6BAAM,CAAC;4BACJ,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;wBAClC,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,cAAc,CAAC,UAAmC;QAC9C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;CACJ"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type IndexablePrimitive = string | number |
|
|
1
|
+
export type IndexablePrimitive = string | number | bigint;
|
|
2
2
|
export type IndexableType = IndexablePrimitive | Array<IndexablePrimitive> | ReadonlyArray<IndexablePrimitive>;
|
|
3
3
|
export type CustomIndexablesOf<A, T> = string & keyof A & {
|
|
4
4
|
[Key in keyof A]: A[Key] extends T ? Key : never;
|