shelving 1.91.2 → 1.92.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/db/Change.d.ts +19 -20
- package/db/Change.js +22 -21
- package/db/CollectionReference.d.ts +103 -0
- package/db/CollectionReference.js +127 -0
- package/db/Database.d.ts +21 -23
- package/db/Database.js +18 -18
- package/db/{Item.d.ts → ItemReference.d.ts} +13 -14
- package/db/{Item.js → ItemReference.js} +14 -17
- package/db/ItemState.d.ts +3 -3
- package/db/{Query.d.ts → QueryReference.d.ts} +25 -33
- package/db/QueryReference.js +101 -0
- package/db/QueryState.d.ts +10 -10
- package/db/QueryState.js +20 -18
- package/db/index.d.ts +3 -3
- package/db/index.js +3 -3
- package/firestore/client/FirestoreClientProvider.d.ts +13 -13
- package/firestore/client/FirestoreClientProvider.js +55 -84
- package/firestore/lite/FirestoreLiteProvider.d.ts +11 -11
- package/firestore/lite/FirestoreLiteProvider.js +52 -83
- package/firestore/server/FirestoreServerProvider.d.ts +13 -13
- package/firestore/server/FirestoreServerProvider.js +51 -84
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/package.json +1 -3
- package/provider/CacheProvider.d.ts +7 -7
- package/provider/CacheProvider.js +14 -14
- package/provider/DebugProvider.d.ts +11 -11
- package/provider/DebugProvider.js +28 -29
- package/provider/MemoryProvider.d.ts +17 -17
- package/provider/MemoryProvider.js +41 -43
- package/provider/Provider.d.ts +15 -15
- package/provider/ThroughProvider.d.ts +12 -12
- package/provider/ThroughProvider.js +20 -20
- package/provider/ValidationProvider.d.ts +11 -11
- package/provider/ValidationProvider.js +16 -12
- package/react/useData.d.ts +5 -5
- package/react/useData.js +2 -2
- package/state/DataState.d.ts +4 -8
- package/state/DataState.js +6 -16
- package/state/DictionaryState.d.ts +4 -6
- package/state/DictionaryState.js +4 -9
- package/test/basics.d.ts +1 -1
- package/test/people.d.ts +1 -1
- package/test/util.d.ts +1 -1
- package/test/util.js +1 -1
- package/util/data.d.ts +2 -2
- package/util/equal.js +5 -5
- package/util/hydrate.d.ts +13 -26
- package/util/hydrate.js +44 -60
- package/util/index.d.ts +2 -0
- package/util/index.js +2 -0
- package/util/iterate.d.ts +2 -0
- package/util/match.d.ts +2 -10
- package/util/match.js +4 -8
- package/util/query.d.ts +83 -0
- package/util/query.js +129 -0
- package/util/sort.d.ts +8 -15
- package/util/sort.js +15 -19
- package/util/transform.d.ts +26 -45
- package/util/transform.js +24 -29
- package/util/update.d.ts +22 -0
- package/util/update.js +42 -0
- package/util/validate.js +2 -2
- package/constraint/Constraint.d.ts +0 -7
- package/constraint/Constraint.js +0 -3
- package/constraint/Constraints.d.ts +0 -20
- package/constraint/Constraints.js +0 -34
- package/constraint/Filter.d.ts +0 -34
- package/constraint/Filter.js +0 -89
- package/constraint/Filters.d.ts +0 -27
- package/constraint/Filters.js +0 -41
- package/constraint/Sort.d.ts +0 -18
- package/constraint/Sort.js +0 -33
- package/constraint/Sorts.d.ts +0 -26
- package/constraint/Sorts.js +0 -47
- package/constraint/Statement.d.ts +0 -45
- package/constraint/Statement.js +0 -79
- package/constraint/index.d.ts +0 -7
- package/constraint/index.js +0 -7
- package/db/Collection.d.ts +0 -64
- package/db/Collection.js +0 -83
- package/db/Query.js +0 -94
- package/update/ArrayUpdate.d.ts +0 -17
- package/update/ArrayUpdate.js +0 -31
- package/update/DataUpdate.d.ts +0 -37
- package/update/DataUpdate.js +0 -44
- package/update/Delete.d.ts +0 -10
- package/update/Delete.js +0 -12
- package/update/DictionaryUpdate.d.ts +0 -31
- package/update/DictionaryUpdate.js +0 -62
- package/update/Increment.d.ts +0 -18
- package/update/Increment.js +0 -22
- package/update/Update.d.ts +0 -8
- package/update/Update.js +0 -6
- package/update/hydrations.d.ts +0 -3
- package/update/hydrations.js +0 -13
- package/update/index.d.ts +0 -7
- package/update/index.js +0 -7
package/db/Query.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Statement } from "../constraint/Statement.js";
|
|
2
|
-
import { countArray, getFirstItem, getLastItem, getOptionalFirstItem, getOptionalLastItem, isArrayLength } from "../util/array.js";
|
|
3
|
-
import { runSequence } from "../util/sequence.js";
|
|
4
|
-
/** Reference to a set of items in a sync or async provider. */
|
|
5
|
-
class BaseQuery extends Statement {
|
|
6
|
-
// Override to include the collection name.
|
|
7
|
-
toString() {
|
|
8
|
-
return `${this.collection}?{${super.toString()}`;
|
|
9
|
-
}
|
|
10
|
-
/** Subscribe to this item. */
|
|
11
|
-
subscribe(onNext, onError) {
|
|
12
|
-
return runSequence(this, onNext, onError);
|
|
13
|
-
}
|
|
14
|
-
// Implement AsyncIterable
|
|
15
|
-
[Symbol.asyncIterator]() {
|
|
16
|
-
return this.provider.getQuerySequence(this.collection, this)[Symbol.asyncIterator]();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/** Reference to a set of items in a provider. */
|
|
20
|
-
export class Query extends BaseQuery {
|
|
21
|
-
constructor(provider, collection, filters, sorts, limit) {
|
|
22
|
-
super(filters, sorts, limit);
|
|
23
|
-
this.provider = provider;
|
|
24
|
-
this.collection = collection;
|
|
25
|
-
}
|
|
26
|
-
get value() {
|
|
27
|
-
return this.provider.getQuery(this.collection, this);
|
|
28
|
-
}
|
|
29
|
-
get count() {
|
|
30
|
-
return this.value.length;
|
|
31
|
-
}
|
|
32
|
-
get exists() {
|
|
33
|
-
return !!this.max(1).value.length;
|
|
34
|
-
}
|
|
35
|
-
get firstValue() {
|
|
36
|
-
return getOptionalFirstItem(this.max(1).value);
|
|
37
|
-
}
|
|
38
|
-
get firstData() {
|
|
39
|
-
return getFirstItem(this.max(1).value);
|
|
40
|
-
}
|
|
41
|
-
get lastValue() {
|
|
42
|
-
return getOptionalLastItem(this.value);
|
|
43
|
-
}
|
|
44
|
-
get lastData() {
|
|
45
|
-
return getLastItem(this.value);
|
|
46
|
-
}
|
|
47
|
-
set(data) {
|
|
48
|
-
return this.provider.setQuery(this.collection, this, data);
|
|
49
|
-
}
|
|
50
|
-
update(updates) {
|
|
51
|
-
return this.provider.updateQuery(this.collection, this, updates);
|
|
52
|
-
}
|
|
53
|
-
delete() {
|
|
54
|
-
return this.provider.deleteQuery(this.collection, this);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** Reference to a set of items in a provider. */
|
|
58
|
-
export class AsyncQuery extends BaseQuery {
|
|
59
|
-
constructor(provider, collection, filters, sorts, limit) {
|
|
60
|
-
super(filters, sorts, limit);
|
|
61
|
-
this.provider = provider;
|
|
62
|
-
this.collection = collection;
|
|
63
|
-
}
|
|
64
|
-
get value() {
|
|
65
|
-
return this.provider.getQuery(this.collection, this);
|
|
66
|
-
}
|
|
67
|
-
get count() {
|
|
68
|
-
return this.value.then(countArray);
|
|
69
|
-
}
|
|
70
|
-
get exists() {
|
|
71
|
-
return this.max(1).value.then(isArrayLength);
|
|
72
|
-
}
|
|
73
|
-
get firstValue() {
|
|
74
|
-
return this.max(1).value.then(getOptionalFirstItem);
|
|
75
|
-
}
|
|
76
|
-
get firstData() {
|
|
77
|
-
return this.max(1).value.then(getFirstItem);
|
|
78
|
-
}
|
|
79
|
-
get lastValue() {
|
|
80
|
-
return this.value.then(getOptionalLastItem);
|
|
81
|
-
}
|
|
82
|
-
get lastData() {
|
|
83
|
-
return this.value.then(getLastItem);
|
|
84
|
-
}
|
|
85
|
-
set(data) {
|
|
86
|
-
return this.provider.setQuery(this.collection, this, data);
|
|
87
|
-
}
|
|
88
|
-
update(updates) {
|
|
89
|
-
return this.provider.updateQuery(this.collection, this, updates);
|
|
90
|
-
}
|
|
91
|
-
delete() {
|
|
92
|
-
return this.provider.deleteQuery(this.collection, this);
|
|
93
|
-
}
|
|
94
|
-
}
|
package/update/ArrayUpdate.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ImmutableArray } from "../util/array.js";
|
|
2
|
-
import { Update } from "./Update.js";
|
|
3
|
-
/** Update that can be applied to an array to add/remove items. */
|
|
4
|
-
export declare class ArrayUpdate<T> extends Update<ImmutableArray<T>> {
|
|
5
|
-
/** Return an array update with an item marked for addition. */
|
|
6
|
-
static add<X>(...adds: X[]): ArrayUpdate<X>;
|
|
7
|
-
/** Return an array update with an item marked for deletion. */
|
|
8
|
-
static delete<X>(...deletes: X[]): ArrayUpdate<X>;
|
|
9
|
-
readonly adds: ImmutableArray<T>;
|
|
10
|
-
readonly deletes: ImmutableArray<T>;
|
|
11
|
-
constructor(adds?: ImmutableArray<T>, deletes?: ImmutableArray<T>);
|
|
12
|
-
/** Return an array update with an additional item marked for addition. */
|
|
13
|
-
add(...adds: T[]): this;
|
|
14
|
-
/** Return an array update with an additional item marked for deletion. */
|
|
15
|
-
delete(...deletes: T[]): this;
|
|
16
|
-
transform(arr?: ImmutableArray<T>): ImmutableArray<T>;
|
|
17
|
-
}
|
package/update/ArrayUpdate.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { omitArrayItems, withArrayItems } from "../util/array.js";
|
|
2
|
-
import { cloneObjectWith } from "../util/object.js";
|
|
3
|
-
import { Update } from "./Update.js";
|
|
4
|
-
/** Update that can be applied to an array to add/remove items. */
|
|
5
|
-
export class ArrayUpdate extends Update {
|
|
6
|
-
/** Return an array update with an item marked for addition. */
|
|
7
|
-
static add(...adds) {
|
|
8
|
-
return new ArrayUpdate(adds);
|
|
9
|
-
}
|
|
10
|
-
/** Return an array update with an item marked for deletion. */
|
|
11
|
-
static delete(...deletes) {
|
|
12
|
-
return new ArrayUpdate([], deletes);
|
|
13
|
-
}
|
|
14
|
-
constructor(adds = [], deletes = []) {
|
|
15
|
-
super();
|
|
16
|
-
this.adds = adds;
|
|
17
|
-
this.deletes = deletes;
|
|
18
|
-
}
|
|
19
|
-
/** Return an array update with an additional item marked for addition. */
|
|
20
|
-
add(...adds) {
|
|
21
|
-
return cloneObjectWith(this, "deletes", withArrayItems(this.adds, ...adds));
|
|
22
|
-
}
|
|
23
|
-
/** Return an array update with an additional item marked for deletion. */
|
|
24
|
-
delete(...deletes) {
|
|
25
|
-
return cloneObjectWith(this, "deletes", withArrayItems(this.deletes, ...deletes));
|
|
26
|
-
}
|
|
27
|
-
// Implement `Transformable`
|
|
28
|
-
transform(arr = []) {
|
|
29
|
-
return omitArrayItems(withArrayItems(arr, ...this.adds), ...this.deletes);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/update/DataUpdate.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Data, DataKey, DataProp } from "../util/data.js";
|
|
2
|
-
import type { Nullish } from "../util/null.js";
|
|
3
|
-
import type { Transformable } from "../util/transform.js";
|
|
4
|
-
import { Update } from "./Update.js";
|
|
5
|
-
/**
|
|
6
|
-
* Set of named updates for the props of a data object.
|
|
7
|
-
* - Similar to `Transformers` but only allows `Update` instances.
|
|
8
|
-
* - If a prop contains a new value, the prop is set to that new value.
|
|
9
|
-
* - If a prop contains an `Update` instance, the existing value is updated.
|
|
10
|
-
*/
|
|
11
|
-
export type Updates<T extends Data = Data> = {
|
|
12
|
-
readonly [K in keyof T]?: T[K] | Update<T[K]> | undefined;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Update that can be applied to a data object to update its props.
|
|
16
|
-
*/
|
|
17
|
-
export declare class DataUpdate<T extends Data = Data> extends Update<T> implements Iterable<DataProp<Updates<T>>>, Transformable<T, T> {
|
|
18
|
-
/** Return a data update with multiple props updated. */
|
|
19
|
-
static update<X extends Data>(updates: Updates<X>): DataUpdate<X>;
|
|
20
|
-
/** Return a data update with a specific prop set. */
|
|
21
|
-
static setProp<X extends Data, K extends DataKey<X>>(key: Nullish<K>, value: X[K]): DataUpdate<X>;
|
|
22
|
-
/** Return a data update with a specific prop updated. */
|
|
23
|
-
static updateProp<X extends Data, K extends DataKey<X>>(key: Nullish<K>, value: X[K] | Update<X[K]>): DataUpdate<X>;
|
|
24
|
-
readonly updates: Updates<T>;
|
|
25
|
-
constructor(props: Updates<T>);
|
|
26
|
-
/** Return a data update with multiple props updated. */
|
|
27
|
-
update(updates: Updates<T>): this;
|
|
28
|
-
/** Return a data update with a specific prop set. */
|
|
29
|
-
setProp<K extends DataKey<T>>(key: Nullish<K>, value: T[K]): this;
|
|
30
|
-
/** Return a data update with a specific prop updated. */
|
|
31
|
-
updateProp<K extends DataKey<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
32
|
-
transform(data: T): T;
|
|
33
|
-
transform(data?: T | Partial<T>): Partial<T>;
|
|
34
|
-
[Symbol.iterator](): Iterator<DataProp<{
|
|
35
|
-
readonly [K in keyof T]: T[K] | Update<T[K]>;
|
|
36
|
-
}>, void>;
|
|
37
|
-
}
|
package/update/DataUpdate.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isNullish } from "../util/null.js";
|
|
2
|
-
import { cloneObjectWith } from "../util/object.js";
|
|
3
|
-
import { transformObject } from "../util/transform.js";
|
|
4
|
-
import { Update } from "./Update.js";
|
|
5
|
-
/**
|
|
6
|
-
* Update that can be applied to a data object to update its props.
|
|
7
|
-
*/
|
|
8
|
-
export class DataUpdate extends Update {
|
|
9
|
-
/** Return a data update with multiple props updated. */
|
|
10
|
-
static update(updates) {
|
|
11
|
-
return new DataUpdate(updates);
|
|
12
|
-
}
|
|
13
|
-
/** Return a data update with a specific prop set. */
|
|
14
|
-
static setProp(key, value) {
|
|
15
|
-
return DataUpdate.updateProp(key, value);
|
|
16
|
-
}
|
|
17
|
-
/** Return a data update with a specific prop updated. */
|
|
18
|
-
static updateProp(key, value) {
|
|
19
|
-
return new DataUpdate(!isNullish(key) ? { [key]: value } : {});
|
|
20
|
-
}
|
|
21
|
-
constructor(props) {
|
|
22
|
-
super();
|
|
23
|
-
this.updates = props;
|
|
24
|
-
}
|
|
25
|
-
/** Return a data update with multiple props updated. */
|
|
26
|
-
update(updates) {
|
|
27
|
-
return cloneObjectWith(this, "updates", { ...this.updates, ...updates });
|
|
28
|
-
}
|
|
29
|
-
/** Return a data update with a specific prop set. */
|
|
30
|
-
setProp(key, value) {
|
|
31
|
-
return this.updateProp(key, value);
|
|
32
|
-
}
|
|
33
|
-
/** Return a data update with a specific prop updated. */
|
|
34
|
-
updateProp(key, value) {
|
|
35
|
-
return isNullish(key) ? this : cloneObjectWith(this, "updates", { ...this.updates, [key]: value });
|
|
36
|
-
}
|
|
37
|
-
transform(data = {}) {
|
|
38
|
-
return transformObject(data, this.updates);
|
|
39
|
-
}
|
|
40
|
-
// Implement `Iterable`
|
|
41
|
-
[Symbol.iterator]() {
|
|
42
|
-
return Object.entries(this.updates).values();
|
|
43
|
-
}
|
|
44
|
-
}
|
package/update/Delete.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Update } from "./Update.js";
|
|
2
|
-
/**
|
|
3
|
-
* Delete update: an object that deletes a value.
|
|
4
|
-
* - Hint: you can use negative numbers to decrement the number too!
|
|
5
|
-
*/
|
|
6
|
-
export declare class Delete extends Update<undefined> {
|
|
7
|
-
transform(): undefined;
|
|
8
|
-
}
|
|
9
|
-
/** Update that deletes any value. */
|
|
10
|
-
export declare const DELETE: Delete;
|
package/update/Delete.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Update } from "./Update.js";
|
|
2
|
-
/**
|
|
3
|
-
* Delete update: an object that deletes a value.
|
|
4
|
-
* - Hint: you can use negative numbers to decrement the number too!
|
|
5
|
-
*/
|
|
6
|
-
export class Delete extends Update {
|
|
7
|
-
transform() {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/** Update that deletes any value. */
|
|
12
|
-
export const DELETE = new Delete();
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Delete } from "./Delete.js";
|
|
2
|
-
import type { DictionaryItem, ImmutableDictionary } from "../util/dictionary.js";
|
|
3
|
-
import type { Nullish } from "../util/null.js";
|
|
4
|
-
import { Update } from "./Update.js";
|
|
5
|
-
/** Update that can be applied to a dictionary object to add/remove/update its entries. */
|
|
6
|
-
export declare class DictionaryUpdate<T> extends Update<ImmutableDictionary<T>> implements Iterable<DictionaryItem<T | Update<T> | Delete>> {
|
|
7
|
-
/** Return a dictionary update with multiple items set. */
|
|
8
|
-
static set<X>(items: ImmutableDictionary<X>): DictionaryUpdate<X>;
|
|
9
|
-
/** Return a dictionary update with multiple items updated. */
|
|
10
|
-
static update<X>(updates: ImmutableDictionary<X | Update<X> | Delete>): DictionaryUpdate<X>;
|
|
11
|
-
/** Return a dictionary update with a specific item set. */
|
|
12
|
-
static setItem<X>(key: Nullish<string>, value: X): DictionaryUpdate<X>;
|
|
13
|
-
/** Return a dictionary update with a specific item updated. */
|
|
14
|
-
static updateItem<X>(key: Nullish<string>, value: X | Update<X> | Delete): DictionaryUpdate<X>;
|
|
15
|
-
/** Return a dictionary update with a specific item marked for deletion. */
|
|
16
|
-
static deleteItem<X>(key: Nullish<string>): DictionaryUpdate<X>;
|
|
17
|
-
readonly updates: ImmutableDictionary<T | Update<T> | Delete>;
|
|
18
|
-
constructor(updates?: ImmutableDictionary<T | Update<T> | Delete>);
|
|
19
|
-
/** Return a dictionary update with multiple items updated. */
|
|
20
|
-
set(items: ImmutableDictionary<T>): DictionaryUpdate<T>;
|
|
21
|
-
/** Return a dictionary update with multiple items updated. */
|
|
22
|
-
update(updates: ImmutableDictionary<T | Update<T> | Delete>): DictionaryUpdate<T>;
|
|
23
|
-
/** Return a dictionary update with a specific item set. */
|
|
24
|
-
setItem(key: Nullish<string>, value: T): this;
|
|
25
|
-
/** Return a dictionary update with a specific item updated. */
|
|
26
|
-
updateItem(key: Nullish<string>, value: T | Update<T> | Delete): this;
|
|
27
|
-
/** Return a dictionary update with a specific item deleted. */
|
|
28
|
-
deleteItem(key: Nullish<string>): this;
|
|
29
|
-
transform(input?: ImmutableDictionary<T>): ImmutableDictionary<T>;
|
|
30
|
-
[Symbol.iterator](): Iterator<DictionaryItem<T | Update<T> | Delete>, void>;
|
|
31
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getDictionaryItems } from "../util/dictionary.js";
|
|
2
|
-
import { isNullish } from "../util/null.js";
|
|
3
|
-
import { cloneObjectWith } from "../util/object.js";
|
|
4
|
-
import { transformObject } from "../util/transform.js";
|
|
5
|
-
import { DELETE } from "./Delete.js";
|
|
6
|
-
import { Update } from "./Update.js";
|
|
7
|
-
/** Update that can be applied to a dictionary object to add/remove/update its entries. */
|
|
8
|
-
export class DictionaryUpdate extends Update {
|
|
9
|
-
/** Return a dictionary update with multiple items set. */
|
|
10
|
-
static set(items) {
|
|
11
|
-
return new DictionaryUpdate(items);
|
|
12
|
-
}
|
|
13
|
-
/** Return a dictionary update with multiple items updated. */
|
|
14
|
-
static update(updates) {
|
|
15
|
-
return new DictionaryUpdate(updates);
|
|
16
|
-
}
|
|
17
|
-
/** Return a dictionary update with a specific item set. */
|
|
18
|
-
static setItem(key, value) {
|
|
19
|
-
return DictionaryUpdate.updateItem(key, value);
|
|
20
|
-
}
|
|
21
|
-
/** Return a dictionary update with a specific item updated. */
|
|
22
|
-
static updateItem(key, value) {
|
|
23
|
-
return new DictionaryUpdate(isNullish(key) ? {} : { [key]: value });
|
|
24
|
-
}
|
|
25
|
-
/** Return a dictionary update with a specific item marked for deletion. */
|
|
26
|
-
static deleteItem(key) {
|
|
27
|
-
return DictionaryUpdate.updateItem(key, DELETE);
|
|
28
|
-
}
|
|
29
|
-
constructor(updates = {}) {
|
|
30
|
-
super();
|
|
31
|
-
this.updates = updates;
|
|
32
|
-
}
|
|
33
|
-
/** Return a dictionary update with multiple items updated. */
|
|
34
|
-
set(items) {
|
|
35
|
-
return cloneObjectWith(this, "updates", { ...this.updates, ...items });
|
|
36
|
-
}
|
|
37
|
-
/** Return a dictionary update with multiple items updated. */
|
|
38
|
-
update(updates) {
|
|
39
|
-
return cloneObjectWith(this, "updates", { ...this.updates, ...updates });
|
|
40
|
-
}
|
|
41
|
-
/** Return a dictionary update with a specific item set. */
|
|
42
|
-
setItem(key, value) {
|
|
43
|
-
return this.updateItem(key, value);
|
|
44
|
-
}
|
|
45
|
-
/** Return a dictionary update with a specific item updated. */
|
|
46
|
-
updateItem(key, value) {
|
|
47
|
-
return isNullish(key) ? this : cloneObjectWith(this, "updates", { ...this.updates, [key]: value });
|
|
48
|
-
}
|
|
49
|
-
/** Return a dictionary update with a specific item deleted. */
|
|
50
|
-
deleteItem(key) {
|
|
51
|
-
return this.updateItem(key, DELETE);
|
|
52
|
-
}
|
|
53
|
-
// Implement `Transformable`
|
|
54
|
-
transform(input = {}) {
|
|
55
|
-
return transformObject(input, this.updates);
|
|
56
|
-
}
|
|
57
|
-
// Implement `Iterable`
|
|
58
|
-
*[Symbol.iterator]() {
|
|
59
|
-
for (const item of getDictionaryItems(this.updates))
|
|
60
|
-
yield item;
|
|
61
|
-
}
|
|
62
|
-
}
|
package/update/Increment.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Update } from "./Update.js";
|
|
2
|
-
/**
|
|
3
|
-
* Increment update: an object that increments/decrements a value.
|
|
4
|
-
* - Hint: you can use negative numbers to decrement the number too!
|
|
5
|
-
*/
|
|
6
|
-
export declare class Increment extends Update<number> {
|
|
7
|
-
readonly amount: number;
|
|
8
|
-
constructor(amount: number);
|
|
9
|
-
transform(existing?: unknown): number;
|
|
10
|
-
}
|
|
11
|
-
/** Update that increments a value by one. */
|
|
12
|
-
export declare const INCREMENT: Increment;
|
|
13
|
-
/** Update that increments a value by a specific amount. */
|
|
14
|
-
export declare const INCREMENT_BY: (amount: number) => Increment;
|
|
15
|
-
/** Update that decrements a value by one. */
|
|
16
|
-
export declare const DECREMENT: Increment;
|
|
17
|
-
/** Update that decrements a value by a specific amount. */
|
|
18
|
-
export declare const DECREMENT_BY: (amount: number) => Increment;
|
package/update/Increment.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Update } from "./Update.js";
|
|
2
|
-
/**
|
|
3
|
-
* Increment update: an object that increments/decrements a value.
|
|
4
|
-
* - Hint: you can use negative numbers to decrement the number too!
|
|
5
|
-
*/
|
|
6
|
-
export class Increment extends Update {
|
|
7
|
-
constructor(amount) {
|
|
8
|
-
super();
|
|
9
|
-
this.amount = amount;
|
|
10
|
-
}
|
|
11
|
-
transform(existing) {
|
|
12
|
-
return typeof existing === "number" ? existing + this.amount : this.amount;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/** Update that increments a value by one. */
|
|
16
|
-
export const INCREMENT = new Increment(1);
|
|
17
|
-
/** Update that increments a value by a specific amount. */
|
|
18
|
-
export const INCREMENT_BY = (amount) => new Increment(amount);
|
|
19
|
-
/** Update that decrements a value by one. */
|
|
20
|
-
export const DECREMENT = new Increment(-1);
|
|
21
|
-
/** Update that decrements a value by a specific amount. */
|
|
22
|
-
export const DECREMENT_BY = (amount) => new Increment(0 - amount);
|
package/update/Update.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Transformable } from "../util/transform.js";
|
|
2
|
-
/**
|
|
3
|
-
* An object that represents an update of an existing value.
|
|
4
|
-
* - Implements `Transformable` for applying that update with its `transform()` method.
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class Update<T> implements Transformable<T, T> {
|
|
7
|
-
abstract transform(value?: unknown): T;
|
|
8
|
-
}
|
package/update/Update.js
DELETED
package/update/hydrations.d.ts
DELETED
package/update/hydrations.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ArrayUpdate } from "./ArrayUpdate.js";
|
|
2
|
-
import { DataUpdate } from "./DataUpdate.js";
|
|
3
|
-
import { Delete } from "./Delete.js";
|
|
4
|
-
import { DictionaryUpdate } from "./DictionaryUpdate.js";
|
|
5
|
-
import { Increment } from "./Increment.js";
|
|
6
|
-
/** Set of hydrations for all update classes. */
|
|
7
|
-
export const UPDATE_HYDRATIONS = {
|
|
8
|
-
Increment,
|
|
9
|
-
Delete,
|
|
10
|
-
ArrayUpdate,
|
|
11
|
-
DictionaryUpdate,
|
|
12
|
-
DataUpdate,
|
|
13
|
-
};
|
package/update/index.d.ts
DELETED
package/update/index.js
DELETED