shelving 1.102.0 → 1.102.2
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 +3 -3
- package/db/Database.d.ts +4 -4
- package/db/ItemReference.js +1 -1
- package/db/ItemState.js +4 -3
- package/db/QueryReference.js +1 -1
- package/db/QueryState.js +2 -2
- package/package.json +1 -1
- package/react/useData.d.ts +3 -2
- package/react/useState.d.ts +2 -1
- package/react/useState.js +1 -1
- package/state/DataState.js +1 -1
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/null.d.ts +0 -2
- package/util/null.js +0 -7
- package/util/optional.d.ts +4 -0
- package/util/optional.js +7 -0
package/db/Change.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
2
2
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
3
|
import type { Data } from "../util/data.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Optional } from "../util/optional.js";
|
|
5
5
|
import type { Updates } from "../util/update.js";
|
|
6
6
|
/** Add on an item. */
|
|
7
7
|
export interface AddChange<T extends Data> {
|
|
@@ -38,6 +38,6 @@ export type WriteChange<T extends Data> = ItemChange<T> | AddChange<T>;
|
|
|
38
38
|
/** Array of write changes. */
|
|
39
39
|
export type WriteChanges = ImmutableArray<WriteChange<Data>>;
|
|
40
40
|
/** Apply a set of changes to a synchronous provider. */
|
|
41
|
-
export declare function changeProvider(provider: Provider, ...changes:
|
|
41
|
+
export declare function changeProvider(provider: Provider, ...changes: Optional<WriteChange<Data>>[]): ItemChanges;
|
|
42
42
|
/** Apply a set of changes to an asynchronous provider. */
|
|
43
|
-
export declare function changeAsyncProvider(provider: AsyncProvider, ...changes:
|
|
43
|
+
export declare function changeAsyncProvider(provider: AsyncProvider, ...changes: Optional<WriteChange<Data>>[]): Promise<ItemChanges>;
|
package/db/Database.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AddChange, DeleteChange, ItemChanges, SetChange, UpdateChange, Wri
|
|
|
2
2
|
import type { ItemQuery, ItemValue } from "./ItemReference.js";
|
|
3
3
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
4
4
|
import type { Data, DataKey, Datas } from "../util/data.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { Optional } from "../util/optional.js";
|
|
6
6
|
import type { Updates } from "../util/update.js";
|
|
7
7
|
import { AsyncCollectionReference, CollectionReference } from "./CollectionReference.js";
|
|
8
8
|
import { AsyncItemReference, ItemReference } from "./ItemReference.js";
|
|
@@ -17,7 +17,7 @@ declare abstract class AbstractDatabase<T extends Datas> {
|
|
|
17
17
|
/** Reference an item in a collection in this database. */
|
|
18
18
|
abstract item<K extends DataKey<T>>(collection: K, id: string): ItemReference<T[K]> | AsyncItemReference<T[K]>;
|
|
19
19
|
/** Run a set of changes in this database. */
|
|
20
|
-
abstract change(...changes:
|
|
20
|
+
abstract change(...changes: Optional<WriteChange<Data>>[]): ItemChanges | Promise<ItemChanges>;
|
|
21
21
|
/** Get a document from a collection in this database. */
|
|
22
22
|
abstract get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
23
23
|
/** Add a document to a collection in this database. */
|
|
@@ -44,7 +44,7 @@ export declare class Database<T extends Datas = Datas> extends AbstractDatabase<
|
|
|
44
44
|
collection<K extends DataKey<T>>(collection: K): CollectionReference<T[K]>;
|
|
45
45
|
query<K extends DataKey<T>>(collection: K, query?: ItemQuery<T[K]>): QueryReference<T[K]>;
|
|
46
46
|
item<K extends DataKey<T>>(collection: K, id: string): ItemReference<T[K]>;
|
|
47
|
-
change(...changes:
|
|
47
|
+
change(...changes: Optional<WriteChange<Data>>[]): ItemChanges;
|
|
48
48
|
get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
49
49
|
add<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
50
50
|
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
@@ -58,7 +58,7 @@ export declare class AsyncDatabase<T extends Datas = Datas> extends AbstractData
|
|
|
58
58
|
collection<K extends DataKey<T>>(collection: K): AsyncCollectionReference<T[K]>;
|
|
59
59
|
query<K extends DataKey<T>>(collection: K, query?: ItemQuery<T[K]>): AsyncQueryReference<T[K]>;
|
|
60
60
|
item<K extends DataKey<T>>(collection: K, id: string): AsyncItemReference<T[K]>;
|
|
61
|
-
change(...changes:
|
|
61
|
+
change(...changes: Optional<WriteChange<Data>>[]): Promise<ItemChanges>;
|
|
62
62
|
get<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
63
63
|
add<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
64
64
|
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
package/db/ItemReference.js
CHANGED
package/db/ItemState.js
CHANGED
|
@@ -2,7 +2,8 @@ import { CacheProvider } from "../provider/CacheProvider.js";
|
|
|
2
2
|
import { BooleanState } from "../state/BooleanState.js";
|
|
3
3
|
import { State } from "../state/State.js";
|
|
4
4
|
import { call } from "../util/callback.js";
|
|
5
|
-
import {
|
|
5
|
+
import { NONE } from "../util/constants.js";
|
|
6
|
+
import { getRequired } from "../util/optional.js";
|
|
6
7
|
import { getOptionalSource } from "../util/source.js";
|
|
7
8
|
import { getItemData } from "./ItemReference.js";
|
|
8
9
|
/** Hold the current state of a item. */
|
|
@@ -17,14 +18,14 @@ export class ItemState extends State {
|
|
|
17
18
|
}
|
|
18
19
|
/** Does the item exist? */
|
|
19
20
|
get exists() {
|
|
20
|
-
return
|
|
21
|
+
return !!this.value;
|
|
21
22
|
}
|
|
22
23
|
constructor(ref) {
|
|
23
24
|
var _a;
|
|
24
25
|
const { provider, collection, id } = ref;
|
|
25
26
|
const memory = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory;
|
|
26
27
|
const time = memory ? memory.getItemTime(collection, id) : undefined;
|
|
27
|
-
super(memory && typeof time === "number" ? memory.getItem(collection, id) :
|
|
28
|
+
super(memory && typeof time === "number" ? memory.getItem(collection, id) : NONE, time);
|
|
28
29
|
this.busy = new BooleanState();
|
|
29
30
|
this._iterating = 0;
|
|
30
31
|
this._stop = undefined;
|
package/db/QueryReference.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { countArray, getOptionalFirstItem, getOptionalLastItem, isArrayLength } from "../util/array.js";
|
|
2
|
-
import { getRequired } from "../util/null.js";
|
|
3
2
|
import { cloneObjectWith } from "../util/object.js";
|
|
3
|
+
import { getRequired } from "../util/optional.js";
|
|
4
4
|
import { runSequence } from "../util/sequence.js";
|
|
5
5
|
/** Reference to a set of items in a sync or async provider. */
|
|
6
6
|
class AbstractQueryReference {
|
package/db/QueryState.js
CHANGED
|
@@ -4,7 +4,7 @@ import { State } from "../state/State.js";
|
|
|
4
4
|
import { getOptionalFirstItem, getOptionalLastItem } from "../util/array.js";
|
|
5
5
|
import { call } from "../util/callback.js";
|
|
6
6
|
import { NONE } from "../util/constants.js";
|
|
7
|
-
import { getRequired } from "../util/
|
|
7
|
+
import { getRequired } from "../util/optional.js";
|
|
8
8
|
import { getAfterQuery, getLimit } from "../util/query.js";
|
|
9
9
|
import { getOptionalSource } from "../util/source.js";
|
|
10
10
|
/** Hold the current state of a query. */
|
|
@@ -31,7 +31,7 @@ export class QueryState extends State {
|
|
|
31
31
|
}
|
|
32
32
|
/** Does the document have at least one result. */
|
|
33
33
|
get exists() {
|
|
34
|
-
return
|
|
34
|
+
return !!this.value.length;
|
|
35
35
|
}
|
|
36
36
|
/** Get the number of items matching this query. */
|
|
37
37
|
get count() {
|
package/package.json
CHANGED
package/react/useData.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { AsyncQueryReference } from "../db/QueryReference.js";
|
|
3
3
|
import type { Data } from "../util/data.js";
|
|
4
|
+
import type { Optional } from "../util/optional.js";
|
|
4
5
|
import { AsyncItemReference } from "../db/ItemReference.js";
|
|
5
6
|
import { ItemState } from "../db/ItemState.js";
|
|
6
7
|
import { QueryState } from "../db/QueryState.js";
|
|
7
8
|
export declare function useData<T extends Data>(ref: AsyncItemReference<T>): ItemState<T>;
|
|
8
|
-
export declare function useData<T extends Data>(ref: AsyncItemReference<T
|
|
9
|
+
export declare function useData<T extends Data>(ref: Optional<AsyncItemReference<T>>): ItemState<T> | undefined;
|
|
9
10
|
export declare function useData<T extends Data>(ref: AsyncQueryReference<T>): QueryState<T>;
|
|
10
|
-
export declare function useData<T extends Data>(ref: AsyncQueryReference<T
|
|
11
|
+
export declare function useData<T extends Data>(ref: Optional<AsyncQueryReference<T>>): QueryState<T> | undefined;
|
|
11
12
|
/** Wrap components with `<DataProvider>` to allow the use of `useData()`. */
|
|
12
13
|
export declare const DataProvider: ({ children }: {
|
|
13
14
|
children: import("react").ReactNode;
|
package/react/useState.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyState } from "../state/State.js";
|
|
2
|
+
import type { Optional } from "../util/optional.js";
|
|
2
3
|
export declare function useState<T extends AnyState>(state: T): T;
|
|
3
|
-
export declare function useState<T extends AnyState>(state?: T
|
|
4
|
+
export declare function useState<T extends AnyState>(state?: Optional<T>): T | undefined;
|
package/react/useState.js
CHANGED
|
@@ -3,5 +3,5 @@ import { NONE } from "../util/constants.js";
|
|
|
3
3
|
import { BLACKHOLE } from "../util/function.js";
|
|
4
4
|
export function useState(state) {
|
|
5
5
|
useSyncExternalStore(useCallback(onStateChange => (state === null || state === void 0 ? void 0 : state.to(onStateChange, onStateChange)) || BLACKHOLE, [state]), () => (!state ? state : state.loading ? NONE : state.value));
|
|
6
|
-
return state;
|
|
6
|
+
return state !== null && state !== void 0 ? state : undefined;
|
|
7
7
|
}
|
package/state/DataState.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRequired } from "../util/null.js";
|
|
2
1
|
import { withProp } from "../util/object.js";
|
|
2
|
+
import { getRequired } from "../util/optional.js";
|
|
3
3
|
import { updateData } from "../util/update.js";
|
|
4
4
|
import { State } from "./State.js";
|
|
5
5
|
/** State that stores a data object and has additional methods to help with that. */
|
package/util/index.d.ts
CHANGED
package/util/index.js
CHANGED
package/util/null.d.ts
CHANGED
|
@@ -24,5 +24,3 @@ export declare const notNullish: <T>(value: Nullish<T>) => value is T;
|
|
|
24
24
|
export declare function assertNotNullish<T>(value: Nullish<T>): asserts value is T;
|
|
25
25
|
/** Get the not-nullish version of value. */
|
|
26
26
|
export declare function getNotNullish<T>(value: Nullish<T>): T;
|
|
27
|
-
/** Get a required value. */
|
|
28
|
-
export declare function getRequired<T>(value: Nullish<T>): T;
|
package/util/null.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AssertionError } from "../error/AssertionError.js";
|
|
2
|
-
import { RequiredError } from "../error/RequiredError.js";
|
|
3
2
|
/** Function that always returns null. */
|
|
4
3
|
export const getNull = () => null;
|
|
5
4
|
/** Is a value null? */
|
|
@@ -40,9 +39,3 @@ export function getNotNullish(value) {
|
|
|
40
39
|
assertNotNullish(value);
|
|
41
40
|
return value;
|
|
42
41
|
}
|
|
43
|
-
/** Get a required value. */
|
|
44
|
-
export function getRequired(value) {
|
|
45
|
-
if (isNullish(value))
|
|
46
|
-
throw new RequiredError("Value is required");
|
|
47
|
-
return value;
|
|
48
|
-
}
|
package/util/optional.js
ADDED