shelving 1.120.0 → 1.121.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/{change → db}/Change.d.ts +6 -1
- package/{change → db}/Change.js +9 -0
- package/db/{LoggedProvider.d.ts → ChangesProvider.d.ts} +5 -5
- package/db/{LoggedProvider.js → ChangesProvider.js} +12 -12
- package/db/index.d.ts +2 -1
- package/db/index.js +3 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +1 -3
- package/change/index.d.ts +0 -1
- package/change/index.js +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "
|
|
1
|
+
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
2
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { ItemQuery } from "../util/item.js";
|
|
5
5
|
import type { Updates } from "../util/update.js";
|
|
6
|
+
import { type Optional } from "../util/optional.js";
|
|
6
7
|
/** A change to a database. */
|
|
7
8
|
export interface Change {
|
|
8
9
|
readonly action: string;
|
|
@@ -66,5 +67,9 @@ export type DatabaseChange<T extends Database> = ItemAddChange<T, DataKey<T>> |
|
|
|
66
67
|
export type DatabaseChanges<T extends Database> = ImmutableArray<DatabaseChange<T>>;
|
|
67
68
|
/** Write a single change to a synchronous provider and return an array of the changes that were written. */
|
|
68
69
|
export declare function writeChange<T extends Database>(provider: Provider<T>, change: DatabaseChange<T>): DatabaseChange<T>;
|
|
70
|
+
/** Write a set of changes to a synchronous provider. */
|
|
71
|
+
export declare function writeChanges<T extends Database>(provider: Provider<T>, ...changes: Optional<DatabaseChange<T>>[]): DatabaseChanges<T>;
|
|
69
72
|
/** Write a single change to an asynchronous provider and return the change that was written. */
|
|
70
73
|
export declare function writeAsyncChange<T extends Database>(provider: AsyncProvider<T>, change: DatabaseChange<T>): Promise<DatabaseChange<T>>;
|
|
74
|
+
/** Write a set of changes to an asynchronous provider. */
|
|
75
|
+
export declare function writeAsyncChanges<T extends Database>(provider: AsyncProvider<T>, ...changes: Optional<DatabaseChange<T>>[]): Promise<DatabaseChanges<T>>;
|
package/{change → db}/Change.js
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { notOptional } from "../util/optional.js";
|
|
1
2
|
/** Write a single change to a synchronous provider and return an array of the changes that were written. */
|
|
2
3
|
export function writeChange(provider, change) {
|
|
3
4
|
const { action, collection, id, query } = change;
|
|
@@ -23,6 +24,10 @@ export function writeChange(provider, change) {
|
|
|
23
24
|
}
|
|
24
25
|
return change;
|
|
25
26
|
}
|
|
27
|
+
/** Write a set of changes to a synchronous provider. */
|
|
28
|
+
export function writeChanges(provider, ...changes) {
|
|
29
|
+
return changes.filter(notOptional).map(change => writeChange(provider, change));
|
|
30
|
+
}
|
|
26
31
|
/** Write a single change to an asynchronous provider and return the change that was written. */
|
|
27
32
|
export async function writeAsyncChange(provider, change) {
|
|
28
33
|
const { collection, action, id, query } = change;
|
|
@@ -48,3 +53,7 @@ export async function writeAsyncChange(provider, change) {
|
|
|
48
53
|
}
|
|
49
54
|
return change;
|
|
50
55
|
}
|
|
56
|
+
/** Write a set of changes to an asynchronous provider. */
|
|
57
|
+
export function writeAsyncChanges(provider, ...changes) {
|
|
58
|
+
return Promise.all(changes.filter(notOptional).map(change => writeAsyncChange(provider, change)));
|
|
59
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { DatabaseChange, DatabaseChanges } from "
|
|
1
|
+
import type { DatabaseChange, DatabaseChanges } from "./Change.js";
|
|
2
2
|
import type { MutableArray } from "../util/array.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { ItemQuery } from "../util/item.js";
|
|
5
5
|
import type { Updates } from "../util/update.js";
|
|
6
6
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
7
|
-
/** Synchronous provider that keeps a log of any written changes to its `.
|
|
8
|
-
export declare class
|
|
9
|
-
get
|
|
10
|
-
readonly
|
|
7
|
+
/** Synchronous provider that keeps a log of any written changes to its `.changes` property. */
|
|
8
|
+
export declare class ChangesProvider<T extends Database> extends ThroughProvider<T> {
|
|
9
|
+
get changes(): DatabaseChanges<T>;
|
|
10
|
+
readonly _changes: MutableArray<DatabaseChange<T>>;
|
|
11
11
|
addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
12
12
|
setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
13
13
|
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
2
|
-
/** Synchronous provider that keeps a log of any written changes to its `.
|
|
3
|
-
export class
|
|
4
|
-
get
|
|
5
|
-
return this.
|
|
2
|
+
/** Synchronous provider that keeps a log of any written changes to its `.changes` property. */
|
|
3
|
+
export class ChangesProvider extends ThroughProvider {
|
|
4
|
+
get changes() {
|
|
5
|
+
return this._changes;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
_changes = [];
|
|
8
8
|
addItem(collection, data) {
|
|
9
9
|
const id = super.addItem(collection, data);
|
|
10
|
-
this.
|
|
10
|
+
this._changes.push({ action: "set", collection, id, data });
|
|
11
11
|
return id;
|
|
12
12
|
}
|
|
13
13
|
setItem(collection, id, data) {
|
|
14
14
|
super.setItem(collection, id, data);
|
|
15
|
-
this.
|
|
15
|
+
this._changes.push({ action: "set", collection, id, data });
|
|
16
16
|
}
|
|
17
17
|
updateItem(collection, id, updates) {
|
|
18
18
|
super.updateItem(collection, id, updates);
|
|
19
|
-
this.
|
|
19
|
+
this._changes.push({ action: "update", collection, id, updates });
|
|
20
20
|
}
|
|
21
21
|
deleteItem(collection, id) {
|
|
22
22
|
super.deleteItem(collection, id);
|
|
23
|
-
this.
|
|
23
|
+
this._changes.push({ action: "delete", collection, id });
|
|
24
24
|
}
|
|
25
25
|
setQuery(collection, query, data) {
|
|
26
26
|
super.setQuery(collection, query, data);
|
|
27
|
-
this.
|
|
27
|
+
this._changes.push({ action: "set", collection, query, data });
|
|
28
28
|
}
|
|
29
29
|
updateQuery(collection, query, updates) {
|
|
30
30
|
super.updateQuery(collection, query, updates);
|
|
31
|
-
this.
|
|
31
|
+
this._changes.push({ action: "update", collection, query, updates });
|
|
32
32
|
}
|
|
33
33
|
deleteQuery(collection, query) {
|
|
34
34
|
super.deleteQuery(collection, query);
|
|
35
|
-
this.
|
|
35
|
+
this._changes.push({ action: "delete", collection, query });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/** Asynchronous provider that keeps a log of any written changes to its `.written` property. */
|
package/db/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from "./QueryStore.js";
|
|
|
3
3
|
export * from "./Provider.js";
|
|
4
4
|
export * from "./ThroughProvider.js";
|
|
5
5
|
export * from "./CacheProvider.js";
|
|
6
|
+
export * from "./ChangesProvider.js";
|
|
6
7
|
export * from "./DebugProvider.js";
|
|
7
|
-
export * from "./LoggedProvider.js";
|
|
8
8
|
export * from "./MemoryProvider.js";
|
|
9
9
|
export * from "./ValidationProvider.js";
|
|
10
|
+
export * from "./Change.js";
|
package/db/index.js
CHANGED
|
@@ -5,7 +5,9 @@ export * from "./QueryStore.js";
|
|
|
5
5
|
export * from "./Provider.js";
|
|
6
6
|
export * from "./ThroughProvider.js";
|
|
7
7
|
export * from "./CacheProvider.js";
|
|
8
|
+
export * from "./ChangesProvider.js";
|
|
8
9
|
export * from "./DebugProvider.js";
|
|
9
|
-
export * from "./LoggedProvider.js";
|
|
10
10
|
export * from "./MemoryProvider.js";
|
|
11
11
|
export * from "./ValidationProvider.js";
|
|
12
|
+
// Util.
|
|
13
|
+
export * from "./Change.js";
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.121.0",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./index.js",
|
|
24
24
|
"./api": "./api/index.js",
|
|
25
|
-
"./change": "./change/index.js",
|
|
26
25
|
"./db": "./db/index.js",
|
|
27
26
|
"./error": "./error/index.js",
|
|
28
27
|
"./feedback": "./feedback/index.js",
|
|
@@ -31,7 +30,6 @@
|
|
|
31
30
|
"./firestore/server": "./firestore/server/index.js",
|
|
32
31
|
"./iterate": "./iterate/index.js",
|
|
33
32
|
"./markup": "./markup/index.js",
|
|
34
|
-
"./provider": "./provider/index.js",
|
|
35
33
|
"./react": "./react/index.js",
|
|
36
34
|
"./schema": "./schema/index.js",
|
|
37
35
|
"./sequence": "./sequence/index.js",
|
package/change/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Change.js";
|
package/change/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Change.js";
|