shelving 1.78.0 → 1.80.1
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/api/Resource.js +0 -1
- package/constraint/Constraints.js +2 -2
- package/constraint/QueryConstraints.d.ts +1 -1
- package/constraint/QueryConstraints.js +1 -1
- package/db/Collection.d.ts +34 -6
- package/db/Collection.js +47 -7
- package/db/Database.d.ts +41 -7
- package/db/Database.js +54 -2
- package/db/Item.d.ts +4 -4
- package/db/Item.js +19 -19
- package/feedback/ErrorFeedback.js +1 -5
- package/feedback/Feedback.js +1 -5
- package/feedback/InvalidFeedback.js +1 -5
- package/feedback/SuccessFeedback.js +1 -5
- package/feedback/WarningFeedback.js +1 -5
- package/package.json +10 -8
- package/schema/AllowSchema.js +2 -2
- package/state/ArrayState.d.ts +6 -8
- package/state/ArrayState.js +10 -14
- package/state/DataState.js +2 -1
- package/state/ObjectState.d.ts +1 -1
- package/state/ObjectState.js +4 -4
- package/update/ArrayUpdate.js +1 -1
- package/update/DataUpdate.d.ts +1 -3
- package/update/DataUpdate.js +1 -1
- package/update/hydrations.d.ts +2 -2
- package/update/hydrations.js +2 -2
- package/util/array.d.ts +6 -52
- package/util/array.js +15 -89
- package/util/data.d.ts +8 -60
- package/util/data.js +0 -51
- package/util/entry.d.ts +2 -2
- package/util/object.d.ts +49 -41
- package/util/object.js +56 -53
- package/util/transform.d.ts +8 -12
- package/util/transform.js +20 -8
- package/util/validate.d.ts +2 -2
- package/util/validate.js +1 -1
package/api/Resource.js
CHANGED
|
@@ -9,7 +9,6 @@ import { ValidationError } from "../error/ValidationError.js";
|
|
|
9
9
|
* @param returns The `Validator` the function's returned value must conform to (defaults to `undefined` if not specified).
|
|
10
10
|
*/
|
|
11
11
|
export class Resource {
|
|
12
|
-
// Protected to require use of `Resource.create()`
|
|
13
12
|
constructor(payload, result) {
|
|
14
13
|
this.payload = payload;
|
|
15
14
|
this.result = result;
|
|
@@ -20,12 +20,12 @@ export class Constraints extends Constraint {
|
|
|
20
20
|
}
|
|
21
21
|
/** Clone this set of constraints but add additional constraints. */
|
|
22
22
|
with(...constraints) {
|
|
23
|
-
const _constraints = withItems(this._constraints, constraints);
|
|
23
|
+
const _constraints = withItems(this._constraints, ...constraints);
|
|
24
24
|
return _constraints !== this._constraints ? { __proto__: Object.getPrototypeOf(this), ...this, _constraints: _constraints } : this;
|
|
25
25
|
}
|
|
26
26
|
/** Clone this set of constraints but remove specific constraints. */
|
|
27
27
|
without(...constraints) {
|
|
28
|
-
const _constraints = withoutItems(this._constraints, constraints);
|
|
28
|
+
const _constraints = withoutItems(this._constraints, ...constraints);
|
|
29
29
|
return _constraints !== this._constraints ? { __proto__: Object.getPrototypeOf(this), ...this, _constraints: _constraints } : this;
|
|
30
30
|
}
|
|
31
31
|
/** Iterate over the constraints. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data } from "../util/data.js";
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
2
|
import { Filterable, FilterConstraints } from "./FilterConstraints.js";
|
|
3
3
|
import { Sortable, SortConstraints } from "./SortConstraints.js";
|
|
4
4
|
import { Constraint } from "./Constraint.js";
|
package/db/Collection.d.ts
CHANGED
|
@@ -3,10 +3,14 @@ import type { Nullish } from "../util/null.js";
|
|
|
3
3
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
4
4
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
5
5
|
import type { DeepIterable } from "../util/iterate.js";
|
|
6
|
+
import type { Updates } from "../update/DataUpdate.js";
|
|
7
|
+
import type { PartialObserver } from "../observe/Observer.js";
|
|
8
|
+
import type { Dispatch } from "../util/function.js";
|
|
9
|
+
import type { Unsubscribe } from "../observe/Observable.js";
|
|
6
10
|
import type { AsyncDatabase, Database } from "./Database.js";
|
|
7
|
-
import { ItemData, AsyncItem, Item } from "./Item.js";
|
|
11
|
+
import { ItemData, AsyncItem, Item, ItemValue } from "./Item.js";
|
|
8
12
|
import { AsyncQuery, Query } from "./Query.js";
|
|
9
|
-
import { AddChange, ItemChanges, WriteChange } from "./Change.js";
|
|
13
|
+
import { AddChange, ItemChanges, WriteChange, UpdateChange, DeleteChange, SetChange } from "./Change.js";
|
|
10
14
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
11
15
|
declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> {
|
|
12
16
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
@@ -15,12 +19,28 @@ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T>
|
|
|
15
19
|
abstract query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
|
|
16
20
|
/** Create a query on this item's collection. */
|
|
17
21
|
abstract item(id: string): Item<T, K> | AsyncItem<T, K>;
|
|
18
|
-
/** Add an item to this collection. */
|
|
19
|
-
abstract add(data: T[K]): string | Promise<string>;
|
|
20
22
|
/** Run a set of changes on this database. */
|
|
21
23
|
abstract change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
|
|
24
|
+
/** Get an item from this collection. */
|
|
25
|
+
abstract get(id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
26
|
+
/** Subscribe a document from a collection in this database. */
|
|
27
|
+
subscribe(id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
|
|
28
|
+
/** Add an item to this collection. */
|
|
29
|
+
abstract add(data: T[K]): string | Promise<string>;
|
|
30
|
+
/** Set a document in this collection. */
|
|
31
|
+
abstract set(id: string, data: T[K]): void | Promise<void>;
|
|
32
|
+
/** Update a document in this collection. */
|
|
33
|
+
abstract update(id: string, updates: Updates<T[K]>): void | Promise<void>;
|
|
34
|
+
/** Delete a document in this collection. */
|
|
35
|
+
abstract delete(id: string): void | Promise<void>;
|
|
22
36
|
/** Get an add change for this collection. */
|
|
23
37
|
getAdd(data: T[K]): AddChange<T, K>;
|
|
38
|
+
/** Get a set change for this collection. */
|
|
39
|
+
getSet(id: string, data: T[K]): SetChange<T, K>;
|
|
40
|
+
/** Get an update change for this collection. */
|
|
41
|
+
getUpdate(id: string, updates: Updates<T[K]>): UpdateChange<T, K>;
|
|
42
|
+
/** Get a delete change for this collection. */
|
|
43
|
+
getDelete(id: string): DeleteChange<T, K>;
|
|
24
44
|
toString(): K;
|
|
25
45
|
}
|
|
26
46
|
/** Reference to a collection in a synchronous provider. */
|
|
@@ -30,8 +50,12 @@ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
30
50
|
constructor(db: Database<T>, collection: K);
|
|
31
51
|
query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
|
|
32
52
|
item(id: string): Item<T, K>;
|
|
33
|
-
add(data: T[K]): string;
|
|
34
53
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
54
|
+
get(id: string): ItemValue<T[K]>;
|
|
55
|
+
add(data: T[K]): string;
|
|
56
|
+
set(id: string, data: T[K]): void;
|
|
57
|
+
update(id: string, updates: Updates<T[K]>): void;
|
|
58
|
+
delete(id: string): void;
|
|
35
59
|
}
|
|
36
60
|
/** Reference to a collection in an asynchronous provider. */
|
|
37
61
|
export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseCollection<T, K> {
|
|
@@ -40,7 +64,11 @@ export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> =
|
|
|
40
64
|
constructor(db: AsyncDatabase<T>, collection: K);
|
|
41
65
|
query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
|
|
42
66
|
item(id: string): AsyncItem<T, K>;
|
|
43
|
-
add(data: T[K]): Promise<string>;
|
|
44
67
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
|
|
68
|
+
get(id: string): Promise<ItemValue<T[K]>>;
|
|
69
|
+
add(data: T[K]): Promise<string>;
|
|
70
|
+
set(id: string, data: T[K]): Promise<void>;
|
|
71
|
+
update(id: string, updates: Updates<T[K]>): Promise<void>;
|
|
72
|
+
delete(id: string): Promise<void>;
|
|
45
73
|
}
|
|
46
74
|
export {};
|
package/db/Collection.js
CHANGED
|
@@ -3,9 +3,25 @@ import { AsyncQuery, Query } from "./Query.js";
|
|
|
3
3
|
import { changeAsyncProvider, changeProvider } from "./Change.js";
|
|
4
4
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
5
5
|
class BaseCollection {
|
|
6
|
+
/** Subscribe a document from a collection in this database. */
|
|
7
|
+
subscribe(id, next) {
|
|
8
|
+
return this.db.subscribe(this.collection, id, typeof next === "function" ? { next } : next);
|
|
9
|
+
}
|
|
6
10
|
/** Get an add change for this collection. */
|
|
7
11
|
getAdd(data) {
|
|
8
|
-
return
|
|
12
|
+
return this.db.getAdd(this.collection, data);
|
|
13
|
+
}
|
|
14
|
+
/** Get a set change for this collection. */
|
|
15
|
+
getSet(id, data) {
|
|
16
|
+
return this.db.getSet(this.collection, id, data);
|
|
17
|
+
}
|
|
18
|
+
/** Get an update change for this collection. */
|
|
19
|
+
getUpdate(id, updates) {
|
|
20
|
+
return this.db.getUpdate(this.collection, id, updates);
|
|
21
|
+
}
|
|
22
|
+
/** Get a delete change for this collection. */
|
|
23
|
+
getDelete(id) {
|
|
24
|
+
return this.db.getDelete(this.collection, id);
|
|
9
25
|
}
|
|
10
26
|
// Implement toString()
|
|
11
27
|
toString() {
|
|
@@ -25,12 +41,24 @@ export class Collection extends BaseCollection {
|
|
|
25
41
|
item(id) {
|
|
26
42
|
return new Item(this.db, this.collection, id);
|
|
27
43
|
}
|
|
28
|
-
add(data) {
|
|
29
|
-
return this.db.provider.addItem(this.collection, data);
|
|
30
|
-
}
|
|
31
44
|
change(...changes) {
|
|
32
45
|
return changeProvider(this.db.provider, changes);
|
|
33
46
|
}
|
|
47
|
+
get(id) {
|
|
48
|
+
return this.db.get(this.collection, id);
|
|
49
|
+
}
|
|
50
|
+
add(data) {
|
|
51
|
+
return this.db.add(this.collection, data);
|
|
52
|
+
}
|
|
53
|
+
set(id, data) {
|
|
54
|
+
return this.db.set(this.collection, id, data);
|
|
55
|
+
}
|
|
56
|
+
update(id, updates) {
|
|
57
|
+
return this.db.update(this.collection, id, updates);
|
|
58
|
+
}
|
|
59
|
+
delete(id) {
|
|
60
|
+
return this.db.delete(this.collection, id);
|
|
61
|
+
}
|
|
34
62
|
}
|
|
35
63
|
/** Reference to a collection in an asynchronous provider. */
|
|
36
64
|
export class AsyncCollection extends BaseCollection {
|
|
@@ -45,10 +73,22 @@ export class AsyncCollection extends BaseCollection {
|
|
|
45
73
|
item(id) {
|
|
46
74
|
return new AsyncItem(this.db, this.collection, id);
|
|
47
75
|
}
|
|
48
|
-
add(data) {
|
|
49
|
-
return this.db.provider.addItem(this.collection, data);
|
|
50
|
-
}
|
|
51
76
|
change(...changes) {
|
|
52
77
|
return changeAsyncProvider(this.db.provider, changes);
|
|
53
78
|
}
|
|
79
|
+
get(id) {
|
|
80
|
+
return this.db.get(this.collection, id);
|
|
81
|
+
}
|
|
82
|
+
add(data) {
|
|
83
|
+
return this.db.add(this.collection, data);
|
|
84
|
+
}
|
|
85
|
+
set(id, data) {
|
|
86
|
+
return this.db.set(this.collection, id, data);
|
|
87
|
+
}
|
|
88
|
+
update(id, updates) {
|
|
89
|
+
return this.db.update(this.collection, id, updates);
|
|
90
|
+
}
|
|
91
|
+
delete(id) {
|
|
92
|
+
return this.db.delete(this.collection, id);
|
|
93
|
+
}
|
|
54
94
|
}
|
package/db/Database.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { Key, Datas } from "../util/data.js";
|
|
2
|
+
import type { Nullish } from "../util/null.js";
|
|
3
|
+
import type { DeepIterable } from "../util/iterate.js";
|
|
2
4
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
3
5
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
4
6
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
5
|
-
import type { ItemData } from "../db/Item.js";
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
7
|
+
import type { ItemData, ItemValue } from "../db/Item.js";
|
|
8
|
+
import type { Updates } from "../update/DataUpdate.js";
|
|
9
|
+
import type { PartialObserver } from "../observe/Observer.js";
|
|
10
|
+
import type { Dispatch } from "../util/function.js";
|
|
11
|
+
import type { Unsubscribe } from "../observe/Observable.js";
|
|
8
12
|
import { Item, AsyncItem } from "./Item.js";
|
|
9
13
|
import { Query, AsyncQuery } from "./Query.js";
|
|
10
14
|
import { Collection, AsyncCollection } from "./Collection.js";
|
|
11
|
-
import { ItemChanges, WriteChange } from "./Change.js";
|
|
15
|
+
import { AddChange, DeleteChange, ItemChanges, SetChange, UpdateChange, WriteChange } from "./Change.js";
|
|
12
16
|
/** Database with a synchronous or asynchronous provider. */
|
|
13
17
|
declare abstract class BaseDatabase<T extends Datas> {
|
|
14
18
|
abstract readonly provider: Provider<T> | AsyncProvider<T>;
|
|
@@ -18,25 +22,55 @@ declare abstract class BaseDatabase<T extends Datas> {
|
|
|
18
22
|
abstract query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
|
|
19
23
|
/** Reference an item in a collection in this database. */
|
|
20
24
|
abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
|
|
21
|
-
/** Run a set of changes
|
|
25
|
+
/** Run a set of changes in this database. */
|
|
22
26
|
abstract change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T> | Promise<ItemChanges<T>>;
|
|
27
|
+
/** Get a document from a collection in this database. */
|
|
28
|
+
abstract get<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
29
|
+
/** Subscribe a document from a collection in this database. */
|
|
30
|
+
subscribe<K extends Key<T>>(collection: K, id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
|
|
31
|
+
/** Add a document to a collection in this database. */
|
|
32
|
+
abstract add<K extends Key<T>>(collection: K, data: T[K]): string | Promise<string>;
|
|
33
|
+
/** Set a document in a collection in this database. */
|
|
34
|
+
abstract set<K extends Key<T>>(collection: K, id: string, data: T[K]): void | Promise<void>;
|
|
35
|
+
/** Update a document in a collection in this database. */
|
|
36
|
+
abstract update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void | Promise<void>;
|
|
37
|
+
/** Delete a document from a collection in this database. */
|
|
38
|
+
abstract delete<K extends Key<T>>(collection: K, id: string): void | Promise<void>;
|
|
39
|
+
/** Get an add change for a collection in this database. */
|
|
40
|
+
getAdd<K extends Key<T>>(collection: K, data: T[K]): AddChange<T, K>;
|
|
41
|
+
/** Get a set change for a collection in this database. */
|
|
42
|
+
getSet<K extends Key<T>>(collection: K, id: string, data: T[K]): SetChange<T, K>;
|
|
43
|
+
/** Get an update change for a collection in this database. */
|
|
44
|
+
getUpdate<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T, K>;
|
|
45
|
+
/** Get a delete change for a collection in this database. */
|
|
46
|
+
getDelete<K extends Key<T>>(collection: K, id: string): DeleteChange<T, K>;
|
|
23
47
|
}
|
|
24
48
|
/** Database with a synchronous provider. */
|
|
25
|
-
export declare class Database<T extends Datas = Datas>
|
|
49
|
+
export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
26
50
|
readonly provider: Provider<T>;
|
|
27
51
|
constructor(provider: Provider<T>);
|
|
28
52
|
collection<K extends Key<T>>(collection: K): Collection<T, K>;
|
|
29
53
|
query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
|
|
30
54
|
item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
|
|
31
55
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
|
|
56
|
+
get<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
57
|
+
add<K extends Key<T>>(collection: K, data: T[K]): string;
|
|
58
|
+
set<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
|
|
59
|
+
update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
60
|
+
delete<K extends Key<T>>(collection: K, id: string): void;
|
|
32
61
|
}
|
|
33
62
|
/** Database with a synchronous provider. */
|
|
34
|
-
export declare class AsyncDatabase<T extends Datas = Datas>
|
|
63
|
+
export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
35
64
|
readonly provider: AsyncProvider<T>;
|
|
36
65
|
constructor(provider: AsyncProvider<T>);
|
|
37
66
|
collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
|
|
38
67
|
query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
|
|
39
68
|
item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
|
|
40
69
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
|
|
70
|
+
get<K extends Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
71
|
+
add<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
|
|
72
|
+
set<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
|
73
|
+
update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
74
|
+
delete<K extends Key<T>>(collection: K, id: string): Promise<void>;
|
|
41
75
|
}
|
|
42
76
|
export {};
|
package/db/Database.js
CHANGED
|
@@ -4,10 +4,31 @@ import { Collection, AsyncCollection } from "./Collection.js";
|
|
|
4
4
|
import { changeAsyncProvider, changeProvider } from "./Change.js";
|
|
5
5
|
/** Database with a synchronous or asynchronous provider. */
|
|
6
6
|
class BaseDatabase {
|
|
7
|
+
/** Subscribe a document from a collection in this database. */
|
|
8
|
+
subscribe(collection, id, next) {
|
|
9
|
+
return this.provider.subscribeItem(collection, id, typeof next === "function" ? { next } : next);
|
|
10
|
+
}
|
|
11
|
+
/** Get an add change for a collection in this database. */
|
|
12
|
+
getAdd(collection, data) {
|
|
13
|
+
return { action: "ADD", collection, data };
|
|
14
|
+
}
|
|
15
|
+
/** Get a set change for a collection in this database. */
|
|
16
|
+
getSet(collection, id, data) {
|
|
17
|
+
return { action: "SET", collection, id, data };
|
|
18
|
+
}
|
|
19
|
+
/** Get an update change for a collection in this database. */
|
|
20
|
+
getUpdate(collection, id, updates) {
|
|
21
|
+
return { action: "UPDATE", collection, id, updates };
|
|
22
|
+
}
|
|
23
|
+
/** Get a delete change for a collection in this database. */
|
|
24
|
+
getDelete(collection, id) {
|
|
25
|
+
return { action: "DELETE", collection, id };
|
|
26
|
+
}
|
|
7
27
|
}
|
|
8
28
|
/** Database with a synchronous provider. */
|
|
9
|
-
export class Database {
|
|
29
|
+
export class Database extends BaseDatabase {
|
|
10
30
|
constructor(provider) {
|
|
31
|
+
super();
|
|
11
32
|
this.provider = provider;
|
|
12
33
|
}
|
|
13
34
|
collection(collection) {
|
|
@@ -22,10 +43,26 @@ export class Database {
|
|
|
22
43
|
change(...changes) {
|
|
23
44
|
return changeProvider(this.provider, changes);
|
|
24
45
|
}
|
|
46
|
+
get(collection, id) {
|
|
47
|
+
return this.provider.getItem(collection, id);
|
|
48
|
+
}
|
|
49
|
+
add(collection, data) {
|
|
50
|
+
return this.provider.addItem(collection, data);
|
|
51
|
+
}
|
|
52
|
+
set(collection, id, data) {
|
|
53
|
+
return this.provider.setItem(collection, id, data);
|
|
54
|
+
}
|
|
55
|
+
update(collection, id, updates) {
|
|
56
|
+
return this.provider.updateItem(collection, id, updates);
|
|
57
|
+
}
|
|
58
|
+
delete(collection, id) {
|
|
59
|
+
return this.provider.deleteItem(collection, id);
|
|
60
|
+
}
|
|
25
61
|
}
|
|
26
62
|
/** Database with a synchronous provider. */
|
|
27
|
-
export class AsyncDatabase {
|
|
63
|
+
export class AsyncDatabase extends BaseDatabase {
|
|
28
64
|
constructor(provider) {
|
|
65
|
+
super();
|
|
29
66
|
this.provider = provider;
|
|
30
67
|
}
|
|
31
68
|
collection(collection) {
|
|
@@ -40,4 +77,19 @@ export class AsyncDatabase {
|
|
|
40
77
|
change(...changes) {
|
|
41
78
|
return changeAsyncProvider(this.provider, changes);
|
|
42
79
|
}
|
|
80
|
+
get(collection, id) {
|
|
81
|
+
return this.provider.getItem(collection, id);
|
|
82
|
+
}
|
|
83
|
+
add(collection, data) {
|
|
84
|
+
return this.provider.addItem(collection, data);
|
|
85
|
+
}
|
|
86
|
+
set(collection, id, data) {
|
|
87
|
+
return this.provider.setItem(collection, id, data);
|
|
88
|
+
}
|
|
89
|
+
update(collection, id, updates) {
|
|
90
|
+
return this.provider.updateItem(collection, id, updates);
|
|
91
|
+
}
|
|
92
|
+
delete(collection, id) {
|
|
93
|
+
return this.provider.deleteItem(collection, id);
|
|
94
|
+
}
|
|
43
95
|
}
|
package/db/Item.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare type ItemValue<T extends Data = Data> = ItemData<T> | null;
|
|
|
18
18
|
export declare type ItemArray<T extends Data = Data> = ImmutableArray<ItemData<T>>;
|
|
19
19
|
/** A set of query constraints for item data. */
|
|
20
20
|
export declare type ItemConstraints<T extends Data = Data> = QueryConstraints<ItemData<T>>;
|
|
21
|
-
/** Reference to an item in a synchronous or asynchronous
|
|
21
|
+
/** Reference to an item in a synchronous or asynchronous database. */
|
|
22
22
|
declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<T>> implements Observable<ItemValue<T[K]>> {
|
|
23
23
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
24
24
|
abstract readonly collection: K;
|
|
@@ -65,7 +65,7 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
65
65
|
getDelete(): DeleteChange<T, K>;
|
|
66
66
|
toString(): `${K}/${string}`;
|
|
67
67
|
}
|
|
68
|
-
/** Reference to an item in a synchronous
|
|
68
|
+
/** Reference to an item in a synchronous database. */
|
|
69
69
|
export declare class Item<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseItem<T, K> {
|
|
70
70
|
readonly db: Database<T>;
|
|
71
71
|
readonly collection: K;
|
|
@@ -79,12 +79,12 @@ export declare class Item<T extends Datas = Datas, K extends Key<T> = Key<T>> ex
|
|
|
79
79
|
update(updates: Updates<T[K]>): void;
|
|
80
80
|
delete(): void;
|
|
81
81
|
}
|
|
82
|
-
/** Reference to an item in an asynchronous
|
|
82
|
+
/** Reference to an item in an asynchronous database. */
|
|
83
83
|
export declare class AsyncItem<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseItem<T, K> {
|
|
84
84
|
readonly db: AsyncDatabase<T>;
|
|
85
85
|
readonly collection: K;
|
|
86
86
|
readonly id: string;
|
|
87
|
-
constructor(
|
|
87
|
+
constructor(db: AsyncDatabase<T>, collection: K, id: string);
|
|
88
88
|
get optional(): AsyncQuery<T, K>;
|
|
89
89
|
get exists(): Promise<boolean>;
|
|
90
90
|
get value(): Promise<ItemValue<T[K]>>;
|
package/db/Item.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getData } from "../util/data.js";
|
|
2
2
|
import { FilterConstraint } from "../constraint/FilterConstraint.js";
|
|
3
|
-
/** Reference to an item in a synchronous or asynchronous
|
|
3
|
+
/** Reference to an item in a synchronous or asynchronous database. */
|
|
4
4
|
class BaseItem {
|
|
5
5
|
/**
|
|
6
6
|
* Subscribe to the result of this item (indefinitely).
|
|
@@ -10,26 +10,26 @@ class BaseItem {
|
|
|
10
10
|
* @return Function that ends the subscription.
|
|
11
11
|
*/
|
|
12
12
|
subscribe(next) {
|
|
13
|
-
return this.db.
|
|
13
|
+
return this.db.subscribe(this.collection, this.id, next);
|
|
14
14
|
}
|
|
15
15
|
/** Get a set change for this item. */
|
|
16
16
|
getSet(data) {
|
|
17
|
-
return
|
|
17
|
+
return this.db.getSet(this.collection, this.id, data);
|
|
18
18
|
}
|
|
19
19
|
/** Get an update change for this item. */
|
|
20
20
|
getUpdate(updates) {
|
|
21
|
-
return
|
|
21
|
+
return this.db.getUpdate(this.collection, this.id, updates);
|
|
22
22
|
}
|
|
23
23
|
/** Get a delete change for this item. */
|
|
24
24
|
getDelete() {
|
|
25
|
-
return
|
|
25
|
+
return this.db.getDelete(this.collection, this.id);
|
|
26
26
|
}
|
|
27
27
|
// Implement toString()
|
|
28
28
|
toString() {
|
|
29
29
|
return `${this.collection}/${this.id}`;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
/** Reference to an item in a synchronous
|
|
32
|
+
/** Reference to an item in a synchronous database. */
|
|
33
33
|
export class Item extends BaseItem {
|
|
34
34
|
constructor(db, collection, id) {
|
|
35
35
|
super();
|
|
@@ -41,29 +41,29 @@ export class Item extends BaseItem {
|
|
|
41
41
|
return this.db.query(this.collection, new FilterConstraint("id", this.id), undefined, 1);
|
|
42
42
|
}
|
|
43
43
|
get exists() {
|
|
44
|
-
return !!this.db.
|
|
44
|
+
return !!this.db.get(this.collection, this.id);
|
|
45
45
|
}
|
|
46
46
|
get value() {
|
|
47
|
-
return this.db.
|
|
47
|
+
return this.db.get(this.collection, this.id);
|
|
48
48
|
}
|
|
49
49
|
get data() {
|
|
50
50
|
return getData(this.value);
|
|
51
51
|
}
|
|
52
52
|
set(data) {
|
|
53
|
-
return this.db.
|
|
53
|
+
return this.db.set(this.collection, this.id, data);
|
|
54
54
|
}
|
|
55
55
|
update(updates) {
|
|
56
|
-
return this.db.
|
|
56
|
+
return this.db.update(this.collection, this.id, updates);
|
|
57
57
|
}
|
|
58
58
|
delete() {
|
|
59
|
-
return this.db.
|
|
59
|
+
return this.db.delete(this.collection, this.id);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
/** Reference to an item in an asynchronous
|
|
62
|
+
/** Reference to an item in an asynchronous database. */
|
|
63
63
|
export class AsyncItem extends BaseItem {
|
|
64
|
-
constructor(
|
|
64
|
+
constructor(db, collection, id) {
|
|
65
65
|
super();
|
|
66
|
-
this.db =
|
|
66
|
+
this.db = db;
|
|
67
67
|
this.collection = collection;
|
|
68
68
|
this.id = id;
|
|
69
69
|
}
|
|
@@ -71,22 +71,22 @@ export class AsyncItem extends BaseItem {
|
|
|
71
71
|
return this.db.query(this.collection, new FilterConstraint("id", this.id), undefined, 1);
|
|
72
72
|
}
|
|
73
73
|
get exists() {
|
|
74
|
-
return this.db.
|
|
74
|
+
return this.db.get(this.collection, this.id).then(Boolean);
|
|
75
75
|
}
|
|
76
76
|
get value() {
|
|
77
|
-
return this.db.
|
|
77
|
+
return this.db.get(this.collection, this.id);
|
|
78
78
|
}
|
|
79
79
|
get data() {
|
|
80
80
|
return this.value.then(getData);
|
|
81
81
|
}
|
|
82
82
|
set(data) {
|
|
83
|
-
return this.db.
|
|
83
|
+
return this.db.set(this.collection, this.id, data);
|
|
84
84
|
}
|
|
85
85
|
update(updates) {
|
|
86
|
-
return this.db.
|
|
86
|
+
return this.db.update(this.collection, this.id, updates);
|
|
87
87
|
}
|
|
88
88
|
delete() {
|
|
89
|
-
return this.db.
|
|
89
|
+
return this.db.delete(this.collection, this.id);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
/** Get the ID from item data. */
|
|
@@ -4,15 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { setPrototype } from "../util/class.js";
|
|
11
8
|
import { Feedback } from "./Feedback.js";
|
|
12
9
|
/** Specific type of `Feedback` to indicate an error (something went wrong). */
|
|
13
10
|
export class ErrorFeedback extends Feedback {
|
|
14
11
|
}
|
|
15
12
|
__decorate([
|
|
16
|
-
setPrototype("name", "ErrorFeedback")
|
|
17
|
-
__metadata("design:type", String)
|
|
13
|
+
setPrototype("name", "ErrorFeedback")
|
|
18
14
|
], ErrorFeedback.prototype, "name", void 0);
|
package/feedback/Feedback.js
CHANGED
|
@@ -4,9 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { isObject } from "../util/object.js";
|
|
11
8
|
import { getEntries } from "../util/entry.js";
|
|
12
9
|
import { setPrototype } from "../util/class.js";
|
|
@@ -28,8 +25,7 @@ export class Feedback {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
__decorate([
|
|
31
|
-
setPrototype("name", "Feedback")
|
|
32
|
-
__metadata("design:type", String)
|
|
28
|
+
setPrototype("name", "Feedback")
|
|
33
29
|
], Feedback.prototype, "name", void 0);
|
|
34
30
|
/** Is an unknown value a `Feedback` object. */
|
|
35
31
|
export const isFeedback = (v) => isObject(v) && typeof v.name === "string" && v.name.endsWith("Feedback") && typeof v.message === "string";
|
|
@@ -4,15 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { setPrototype } from "../util/class.js";
|
|
11
8
|
import { ErrorFeedback } from "./ErrorFeedback.js";
|
|
12
9
|
/** Specific type of `ErrorFeedback` returned from `validate()` when a value is invalid. */
|
|
13
10
|
export class InvalidFeedback extends ErrorFeedback {
|
|
14
11
|
}
|
|
15
12
|
__decorate([
|
|
16
|
-
setPrototype("name", "InvalidFeedback")
|
|
17
|
-
__metadata("design:type", String)
|
|
13
|
+
setPrototype("name", "InvalidFeedback")
|
|
18
14
|
], InvalidFeedback.prototype, "name", void 0);
|
|
@@ -4,15 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { setPrototype } from "../util/class.js";
|
|
11
8
|
import { Feedback } from "./Feedback.js";
|
|
12
9
|
/** Specific type of `Feedback` to indicate success (something went right!). */
|
|
13
10
|
export class SuccessFeedback extends Feedback {
|
|
14
11
|
}
|
|
15
12
|
__decorate([
|
|
16
|
-
setPrototype("name", "SuccessFeedback")
|
|
17
|
-
__metadata("design:type", String)
|
|
13
|
+
setPrototype("name", "SuccessFeedback")
|
|
18
14
|
], SuccessFeedback.prototype, "name", void 0);
|
|
@@ -4,15 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { setPrototype } from "../util/class.js";
|
|
11
8
|
import { Feedback } from "./Feedback.js";
|
|
12
9
|
/** Specific type of `Feedback` to indicate warning (something might go wrong soon). */
|
|
13
10
|
export class WarningFeedback extends Feedback {
|
|
14
11
|
}
|
|
15
12
|
__decorate([
|
|
16
|
-
setPrototype("name", "WarningFeedback")
|
|
17
|
-
__metadata("design:type", String)
|
|
13
|
+
setPrototype("name", "WarningFeedback")
|
|
18
14
|
], WarningFeedback.prototype, "name", void 0);
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.80.1",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -55,30 +55,32 @@
|
|
|
55
55
|
"test:dpdm": "dpdm ./modules/index.ts --transform --tree=false --warning=false --exit-code circular:1",
|
|
56
56
|
"test:jest": "jest --detectOpenHandles",
|
|
57
57
|
"test:jest:watch": "jest --watchAll",
|
|
58
|
-
"build": "npm run build:
|
|
59
|
-
"build:
|
|
58
|
+
"build": "npm run build:setup && npm run build:copy && npm run build:typescript && npm run build:check && npm run build:jest",
|
|
59
|
+
"build:setup": "rm -rf ./dist && mkdir -p ./dist",
|
|
60
60
|
"build:copy": "cp package.json dist/package.json && cp LICENSE.md dist/LICENSE.md && cp README.md dist/README.md && cp .npmignore dist/.npmignore",
|
|
61
|
+
"build:typescript": "tsc -p ./tsconfig.build.json",
|
|
62
|
+
"build:check": "node ./dist/index.js",
|
|
61
63
|
"build:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.build.cjs"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
66
|
"@google-cloud/firestore": "^5.0.2",
|
|
65
|
-
"@types/jest": "^28.1.
|
|
67
|
+
"@types/jest": "^28.1.7",
|
|
66
68
|
"@types/react": "^18.0.17",
|
|
67
69
|
"@types/react-dom": "^18.0.4",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.33.
|
|
69
|
-
"@typescript-eslint/parser": "^5.33.
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
71
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
70
72
|
"dpdm": "^3.9.0",
|
|
71
73
|
"eslint": "^8.22.0",
|
|
72
74
|
"eslint-config-prettier": "^8.5.0",
|
|
73
75
|
"eslint-plugin-import": "^2.26.0",
|
|
74
76
|
"eslint-plugin-prettier": "^4.0.0",
|
|
75
|
-
"firebase": "^9.9.
|
|
77
|
+
"firebase": "^9.9.3",
|
|
76
78
|
"jest": "^28.1.0",
|
|
77
79
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
78
80
|
"prettier": "^2.6.2",
|
|
79
81
|
"react": "^18.1.0",
|
|
80
82
|
"react-dom": "^18.1.0",
|
|
81
|
-
"ts-jest": "^28.0.
|
|
83
|
+
"ts-jest": "^28.0.8",
|
|
82
84
|
"typescript": "^4.6.4"
|
|
83
85
|
},
|
|
84
86
|
"peerDependencies": {
|