shelving 1.150.14 → 1.151.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/CacheProvider.d.ts +18 -17
- package/db/Change.d.ts +20 -19
- package/db/ChangesProvider.d.ts +22 -21
- package/db/DebugProvider.d.ts +28 -27
- package/db/ItemStore.d.ts +10 -10
- package/db/MemoryProvider.d.ts +47 -44
- package/db/MemoryProvider.js +9 -4
- package/db/Provider.d.ts +50 -49
- package/db/QueryStore.d.ts +11 -10
- package/db/ThroughProvider.d.ts +38 -37
- package/db/ValidationProvider.d.ts +33 -29
- package/db/ValidationProvider.js +24 -22
- package/firestore/client/FirestoreClientProvider.d.ts +11 -10
- package/firestore/lite/FirestoreLiteProvider.d.ts +11 -10
- package/firestore/server/FirestoreServerProvider.d.ts +11 -10
- package/package.json +1 -1
- package/react/createDataContext.d.ts +8 -7
- package/schema/DataSchema.d.ts +3 -3
- package/schema/DataSchema.js +2 -3
- package/schema/EntitySchema.js +2 -2
- package/sequence/DeferredSequence.d.ts +2 -0
- package/sequence/DeferredSequence.js +11 -3
- package/store/Store.d.ts +1 -1
- package/store/Store.js +6 -1
- package/test/basics.d.ts +11 -10
- package/test/people.d.ts +7 -6
- package/test/util.d.ts +3 -3
- package/test/util.js +3 -3
- package/util/array.d.ts +2 -2
- package/util/array.js +3 -3
- package/util/error.d.ts +1 -1
- package/util/item.d.ts +15 -16
- package/util/item.js +9 -8
- package/util/query.d.ts +3 -0
- package/util/random.d.ts +1 -1
- package/util/set.d.ts +3 -3
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { Firestore } from "@google-cloud/firestore";
|
|
2
2
|
import { AsyncProvider } from "../../db/Provider.js";
|
|
3
3
|
import type { DataKey, Database } from "../../util/data.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Items, OptionalItem } from "../../util/item.js";
|
|
5
|
+
import type { ItemQuery } from "../../util/query.js";
|
|
5
6
|
import type { Updates } from "../../util/update.js";
|
|
6
7
|
/**
|
|
7
8
|
* Firestore server database provider.
|
|
8
9
|
* - Works with the Firebase Admin SDK for Node.JS
|
|
9
10
|
*/
|
|
10
|
-
export declare class FirestoreServerProvider<T extends Database> extends AsyncProvider<T> {
|
|
11
|
+
export declare class FirestoreServerProvider<T extends Database> extends AsyncProvider<string, T> {
|
|
11
12
|
private readonly _firestore;
|
|
12
13
|
constructor(firestore?: Firestore);
|
|
13
|
-
getItem<K extends DataKey<T>>(c: K, id: string): Promise<OptionalItem<T[K]>>;
|
|
14
|
-
getItemSequence<K extends DataKey<T>>(c: K, id: string): AsyncIterable<OptionalItem<T[K]>>;
|
|
14
|
+
getItem<K extends DataKey<T>>(c: K, id: string): Promise<OptionalItem<string, T[K]>>;
|
|
15
|
+
getItemSequence<K extends DataKey<T>>(c: K, id: string): AsyncIterable<OptionalItem<string, T[K]>>;
|
|
15
16
|
addItem<K extends DataKey<T>>(c: K, data: T[K]): Promise<string>;
|
|
16
17
|
setItem<K extends DataKey<T>>(c: K, id: string, data: T[K]): Promise<void>;
|
|
17
18
|
updateItem<K extends DataKey<T>>(c: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
18
19
|
deleteItem<K extends DataKey<T>>(c: K, id: string): Promise<void>;
|
|
19
|
-
countQuery<K extends DataKey<T>>(c: K, q?: ItemQuery<T[K]>): Promise<number>;
|
|
20
|
-
getQuery<K extends DataKey<T>>(c: K, q?: ItemQuery<T[K]>): Promise<Items<T[K]>>;
|
|
21
|
-
getQuerySequence<K extends DataKey<T>>(c: K, q?: ItemQuery<T[K]>): AsyncIterable<Items<T[K]>>;
|
|
22
|
-
setQuery<K extends DataKey<T>>(c: K, q: ItemQuery<T[K]>, data: T[K]): Promise<void>;
|
|
23
|
-
updateQuery<K extends DataKey<T>>(c: K, q: ItemQuery<T[K]>, updates: Updates): Promise<void>;
|
|
24
|
-
deleteQuery<K extends DataKey<T>>(c: K, q: ItemQuery<T[K]>): Promise<void>;
|
|
20
|
+
countQuery<K extends DataKey<T>>(c: K, q?: ItemQuery<string, T[K]>): Promise<number>;
|
|
21
|
+
getQuery<K extends DataKey<T>>(c: K, q?: ItemQuery<string, T[K]>): Promise<Items<string, T[K]>>;
|
|
22
|
+
getQuerySequence<K extends DataKey<T>>(c: K, q?: ItemQuery<string, T[K]>): AsyncIterable<Items<string, T[K]>>;
|
|
23
|
+
setQuery<K extends DataKey<T>>(c: K, q: ItemQuery<string, T[K]>, data: T[K]): Promise<void>;
|
|
24
|
+
updateQuery<K extends DataKey<T>>(c: K, q: ItemQuery<string, T[K]>, updates: Updates): Promise<void>;
|
|
25
|
+
deleteQuery<K extends DataKey<T>>(c: K, q: ItemQuery<string, T[K]>): Promise<void>;
|
|
25
26
|
}
|
package/package.json
CHANGED
|
@@ -3,15 +3,16 @@ import { ItemStore } from "../db/ItemStore.js";
|
|
|
3
3
|
import type { AbstractProvider } from "../db/Provider.js";
|
|
4
4
|
import { QueryStore } from "../db/QueryStore.js";
|
|
5
5
|
import type { DataKey, Database } from "../util/data.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { Identifier } from "../util/item.js";
|
|
7
7
|
import type { Nullish } from "../util/null.js";
|
|
8
|
-
|
|
8
|
+
import type { ItemQuery } from "../util/query.js";
|
|
9
|
+
export interface DataContext<I extends Identifier, T extends Database> {
|
|
9
10
|
/** Get an `ItemStore` for the specified collection item in the current `DataProvider` context and subscribe to any changes in it. */
|
|
10
|
-
useItem<K extends DataKey<T>>(this: void, collection: K, id:
|
|
11
|
-
useItem<K extends DataKey<T>>(this: void, collection: Nullish<K>, id: Nullish<
|
|
11
|
+
useItem<K extends DataKey<T>>(this: void, collection: K, id: I): ItemStore<I, T, K>;
|
|
12
|
+
useItem<K extends DataKey<T>>(this: void, collection: Nullish<K>, id: Nullish<I>): ItemStore<I, T, K> | undefined;
|
|
12
13
|
/** Get an `QueryStore` for the specified collection query in the current `DataProvider` context and subscribe to any changes in it. */
|
|
13
|
-
useQuery<K extends DataKey<T>>(this: void, collection: K, query: ItemQuery<T[K]>): QueryStore<T, K>;
|
|
14
|
-
useQuery<K extends DataKey<T>>(this: void, collection: Nullish<K>, query: Nullish<ItemQuery<T[K]>>): QueryStore<T, K> | undefined;
|
|
14
|
+
useQuery<K extends DataKey<T>>(this: void, collection: K, query: ItemQuery<I, T[K]>): QueryStore<I, T, K>;
|
|
15
|
+
useQuery<K extends DataKey<T>>(this: void, collection: Nullish<K>, query: Nullish<ItemQuery<I, T[K]>>): QueryStore<I, T, K> | undefined;
|
|
15
16
|
readonly DataContext: ({ children }: {
|
|
16
17
|
children: ReactNode;
|
|
17
18
|
}) => ReactElement;
|
|
@@ -21,4 +22,4 @@ export interface DataContext<T extends Database> {
|
|
|
21
22
|
* - Allows React elements to call `useItem()` and `useQuery()` to access items/queries in a database provider.
|
|
22
23
|
* - If the database has a `CacheProvider` in its chain then in-memory data will be used in the returned stores.
|
|
23
24
|
*/
|
|
24
|
-
export declare function createDataContext<T extends Database>(provider: AbstractProvider<T>): DataContext<T>;
|
|
25
|
+
export declare function createDataContext<I extends Identifier, T extends Database>(provider: AbstractProvider<I, T>): DataContext<I, T>;
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Data, Database } from "../util/data.js";
|
|
2
|
-
import type { Item } from "../util/item.js";
|
|
2
|
+
import type { Identifier, Item } from "../util/item.js";
|
|
3
3
|
import type { Validator, Validators } from "../util/validate.js";
|
|
4
4
|
import type { NullableSchema } from "./NullableSchema.js";
|
|
5
5
|
import type { SchemaOptions } from "./Schema.js";
|
|
@@ -27,5 +27,5 @@ export declare const DATA: <T extends Data>(props: Validators<T>) => DataSchema<
|
|
|
27
27
|
export declare const NULLABLE_DATA: <T extends Data>(props: Validators<T>) => NullableSchema<T>;
|
|
28
28
|
/** Create a `DataSchema` that validates partially, i.e. properties can be their value, or `undefined` */
|
|
29
29
|
export declare function PARTIAL<T extends Data>(source: Validators<T> | DataSchema<T>): DataSchema<Partial<T>>;
|
|
30
|
-
/** Create a `DataSchema` that validates a data item, i.e. it has a string `.id` property. */
|
|
31
|
-
export declare function ITEM<T extends Data>(validators: Validators<T> | DataSchema<T
|
|
30
|
+
/** Create a `DataSchema` that validates a data item, i.e. it has a string or number `.id` identifier property. */
|
|
31
|
+
export declare function ITEM<I extends Identifier, T extends Data>(id: Validator<I>, validators: Validators<T> | DataSchema<T>): DataSchema<Item<I, T>>;
|
package/schema/DataSchema.js
CHANGED
|
@@ -2,7 +2,6 @@ import { ValueFeedback } from "../feedback/Feedback.js";
|
|
|
2
2
|
import { isData } from "../util/data.js";
|
|
3
3
|
import { mapObject } from "../util/transform.js";
|
|
4
4
|
import { validateData } from "../util/validate.js";
|
|
5
|
-
import { KEY } from "./KeySchema.js";
|
|
6
5
|
import { NULLABLE } from "./NullableSchema.js";
|
|
7
6
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
8
7
|
import { Schema } from "./Schema.js";
|
|
@@ -30,8 +29,8 @@ export function PARTIAL(source) {
|
|
|
30
29
|
props: mapObject(props, OPTIONAL),
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
|
-
/** Create a `DataSchema` that validates a data item, i.e. it has a string `.id` property. */
|
|
34
|
-
export function ITEM(
|
|
32
|
+
/** Create a `DataSchema` that validates a data item, i.e. it has a string or number `.id` identifier property. */
|
|
33
|
+
export function ITEM(id, validators) {
|
|
35
34
|
const props = validators instanceof DataSchema ? validators.props : validators;
|
|
36
35
|
return new DataSchema({
|
|
37
36
|
props: { id, ...props },
|
package/schema/EntitySchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isArrayItem } from "../util/array.js";
|
|
3
3
|
import { getEntity } from "../util/entity.js";
|
|
4
4
|
import { NULLABLE } from "./NullableSchema.js";
|
|
5
5
|
import { StringSchema } from "./StringSchema.js";
|
|
@@ -15,7 +15,7 @@ export class EntitySchema extends StringSchema {
|
|
|
15
15
|
const [type] = getEntity(entity);
|
|
16
16
|
if (!type)
|
|
17
17
|
throw new ValueFeedback("Must be entity", unsafeValue);
|
|
18
|
-
if (this.types && !
|
|
18
|
+
if (this.types && !isArrayItem(this.types, type))
|
|
19
19
|
throw new ValueFeedback("Invalid entity type", type);
|
|
20
20
|
return entity;
|
|
21
21
|
}
|
|
@@ -20,6 +20,8 @@ export declare class DeferredSequence<T = void> extends AbstractSequence<T, void
|
|
|
20
20
|
/** Reject the current deferred in the sequence. */
|
|
21
21
|
reject(reason: unknown): void;
|
|
22
22
|
private _nextReason;
|
|
23
|
+
/** Cancel the current resolution or rejection. */
|
|
24
|
+
cancel(): void;
|
|
23
25
|
/** Fulfill the current deferred by resolving or rejecting it. */
|
|
24
26
|
private _fulfill;
|
|
25
27
|
next(): Promise<IteratorResult<T, void>>;
|
|
@@ -33,17 +33,25 @@ export class DeferredSequence extends AbstractSequence {
|
|
|
33
33
|
queueMicrotask(() => this._fulfill());
|
|
34
34
|
}
|
|
35
35
|
_nextReason = _NOVALUE;
|
|
36
|
+
/** Cancel the current resolution or rejection. */
|
|
37
|
+
cancel() {
|
|
38
|
+
this._nextValue = _NOVALUE;
|
|
39
|
+
this._nextReason = _NOVALUE;
|
|
40
|
+
}
|
|
36
41
|
/** Fulfill the current deferred by resolving or rejecting it. */
|
|
37
42
|
_fulfill() {
|
|
38
43
|
const { _deferred, _nextReason, _nextValue } = this;
|
|
39
|
-
this._deferred = undefined;
|
|
40
44
|
this._nextReason = _NOVALUE;
|
|
41
45
|
this._nextValue = _NOVALUE;
|
|
42
46
|
if (_deferred) {
|
|
43
|
-
if (_nextReason !== _NOVALUE)
|
|
47
|
+
if (_nextReason !== _NOVALUE) {
|
|
48
|
+
this._deferred = undefined;
|
|
44
49
|
_deferred.reject(_nextReason);
|
|
45
|
-
|
|
50
|
+
}
|
|
51
|
+
else if (_nextValue !== _NOVALUE) {
|
|
52
|
+
this._deferred = undefined;
|
|
46
53
|
_deferred.resolve(_nextValue);
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
57
|
// Implement `AsyncIterator`
|
package/store/Store.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class Store<T> implements AsyncIterable<T> {
|
|
|
18
18
|
readonly next: DeferredSequence<T>;
|
|
19
19
|
/** Current value of the store (or throw a promise that resolves when this store receives its next value or error). */
|
|
20
20
|
get value(): T;
|
|
21
|
-
set value(value: T);
|
|
21
|
+
set value(value: T | typeof NONE);
|
|
22
22
|
private _value;
|
|
23
23
|
/** Is there a current value, or is it still loading. */
|
|
24
24
|
get loading(): boolean;
|
package/store/Store.js
CHANGED
|
@@ -25,7 +25,12 @@ export class Store {
|
|
|
25
25
|
}
|
|
26
26
|
set value(value) {
|
|
27
27
|
this._reason = undefined;
|
|
28
|
-
if (
|
|
28
|
+
if (value === NONE) {
|
|
29
|
+
this._time = undefined;
|
|
30
|
+
this._value = value;
|
|
31
|
+
this.next.cancel();
|
|
32
|
+
}
|
|
33
|
+
else if (this._value === NONE || !this.equal(value, this._value)) {
|
|
29
34
|
this._time = Date.now();
|
|
30
35
|
this._value = value;
|
|
31
36
|
this.next.resolve(value);
|
package/test/basics.d.ts
CHANGED
|
@@ -15,14 +15,15 @@ export declare const BASIC_SCHEMA: import("../schema/DataSchema.js").DataSchema<
|
|
|
15
15
|
};
|
|
16
16
|
}>;
|
|
17
17
|
export type BasicData = ValidatorType<typeof BASIC_SCHEMA>;
|
|
18
|
-
export
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
18
|
+
export type BasicItem = Item<string, BasicData>;
|
|
19
|
+
export declare const basic1: BasicItem;
|
|
20
|
+
export declare const basic2: BasicItem;
|
|
21
|
+
export declare const basic3: BasicItem;
|
|
22
|
+
export declare const basic4: BasicItem;
|
|
23
|
+
export declare const basic5: BasicItem;
|
|
24
|
+
export declare const basic6: BasicItem;
|
|
25
|
+
export declare const basic7: BasicItem;
|
|
26
|
+
export declare const basic8: BasicItem;
|
|
27
|
+
export declare const basic9: BasicItem;
|
|
28
|
+
export declare const basics: ReadonlyArray<BasicItem>;
|
|
28
29
|
export declare const basic999: BasicData;
|
package/test/people.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ export declare const PERSON_SCHEMA: import("../schema/DataSchema.js").DataSchema
|
|
|
8
8
|
birthday: string | null;
|
|
9
9
|
}>;
|
|
10
10
|
export type PersonData = ValidatorType<typeof PERSON_SCHEMA>;
|
|
11
|
-
export
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
11
|
+
export type PersonItem = Item<string, PersonData>;
|
|
12
|
+
export declare const person1: PersonItem;
|
|
13
|
+
export declare const person2: PersonItem;
|
|
14
|
+
export declare const person3: PersonItem;
|
|
15
|
+
export declare const person4: PersonItem;
|
|
16
|
+
export declare const person5: PersonItem;
|
|
17
|
+
export declare const people: ReadonlyArray<PersonItem>;
|
package/test/util.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Data } from "../util/data.js";
|
|
2
|
-
import type { Item } from "../util/item.js";
|
|
2
|
+
import type { Identifier, Item } from "../util/item.js";
|
|
3
3
|
import type { NotString } from "../util/string.js";
|
|
4
4
|
/** Expect that an object matches `PromiseLike` */
|
|
5
5
|
export declare const EXPECT_PROMISELIKE: any;
|
|
6
6
|
/** Expect `Item` objects with an `.id` prop in any order. */
|
|
7
|
-
export declare function expectUnorderedItems<T extends Data>(items: Iterable<Item<T>>, keys: Iterable<string> & NotString): void;
|
|
7
|
+
export declare function expectUnorderedItems<I extends Identifier, T extends Data>(items: Iterable<Item<I, T>>, keys: Iterable<string> & NotString): void;
|
|
8
8
|
/** Expect `Item` objects with an `.id` prop in a specified order. */
|
|
9
|
-
export declare function expectOrderedItems<T extends Data>(items: Iterable<Item<T>>, keys: Iterable<string> & NotString): void;
|
|
9
|
+
export declare function expectOrderedItems<I extends Identifier, T extends Data>(items: Iterable<Item<I, T>>, keys: Iterable<string> & NotString): void;
|
package/test/util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import { getIdentifiers } from "../util/item.js";
|
|
3
3
|
/** Expect that an object matches `PromiseLike` */
|
|
4
4
|
export const EXPECT_PROMISELIKE = expect.objectContaining({
|
|
5
5
|
// biome-ignore lint/suspicious/noThenProperty: On purpose.
|
|
@@ -9,7 +9,7 @@ export const EXPECT_PROMISELIKE = expect.objectContaining({
|
|
|
9
9
|
export function expectUnorderedItems(items, keys) {
|
|
10
10
|
try {
|
|
11
11
|
expect(items).toBeInstanceOf(Object);
|
|
12
|
-
expect(Array.from(
|
|
12
|
+
expect(Array.from(getIdentifiers(items)).sort()).toEqual(Array.from(keys).sort());
|
|
13
13
|
}
|
|
14
14
|
catch (thrown) {
|
|
15
15
|
if (thrown instanceof Error)
|
|
@@ -21,7 +21,7 @@ export function expectUnorderedItems(items, keys) {
|
|
|
21
21
|
export function expectOrderedItems(items, keys) {
|
|
22
22
|
try {
|
|
23
23
|
expect(items).toBeInstanceOf(Object);
|
|
24
|
-
expect(Array.from(
|
|
24
|
+
expect(Array.from(getIdentifiers(items))).toEqual(Array.from(keys));
|
|
25
25
|
}
|
|
26
26
|
catch (thrown) {
|
|
27
27
|
if (thrown instanceof Error)
|
package/util/array.d.ts
CHANGED
|
@@ -61,9 +61,9 @@ export declare function requireArray<T>(arr: ImmutableArray<T>, min: 2, max?: nu
|
|
|
61
61
|
export declare function requireArray<T>(arr: ImmutableArray<T>, min: 3, max?: number, caller?: AnyCaller): readonly [T, T, T, ...T[]];
|
|
62
62
|
export declare function requireArray<T>(list: PossibleArray<T>, min?: number, max?: number, caller?: AnyCaller): ImmutableArray<T>;
|
|
63
63
|
/** Is an unknown value an item in a specified array or iterable? */
|
|
64
|
-
export declare function
|
|
64
|
+
export declare function isArrayItem<T>(list: PossibleArray<T>, item: unknown): item is T;
|
|
65
65
|
/** Assert that an unknown value is an item in a specified array. */
|
|
66
|
-
export declare function
|
|
66
|
+
export declare function assertArrayItem<T>(arr: PossibleArray<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
67
67
|
/** Add multiple items to an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
|
68
68
|
export declare function withArrayItems<T>(list: PossibleArray<T>, ...add: T[]): ImmutableArray<T>;
|
|
69
69
|
/** Pick multiple items from an array (immutably) and return a new array without those items (or the same array if no changes were made). */
|
package/util/array.js
CHANGED
|
@@ -20,7 +20,7 @@ export function requireArray(list, min, max, caller = requireArray) {
|
|
|
20
20
|
return arr;
|
|
21
21
|
}
|
|
22
22
|
/** Is an unknown value an item in a specified array or iterable? */
|
|
23
|
-
export function
|
|
23
|
+
export function isArrayItem(list, item) {
|
|
24
24
|
if (isArray(list))
|
|
25
25
|
list.includes(item);
|
|
26
26
|
for (const i of list)
|
|
@@ -29,8 +29,8 @@ export function isItem(list, item) {
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
/** Assert that an unknown value is an item in a specified array. */
|
|
32
|
-
export function
|
|
33
|
-
if (!
|
|
32
|
+
export function assertArrayItem(arr, item, caller = assertArrayItem) {
|
|
33
|
+
if (!isArrayItem(arr, item))
|
|
34
34
|
throw new RequiredError("Item must exist in array", { item, array: arr, caller });
|
|
35
35
|
}
|
|
36
36
|
/** Add multiple items to an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
package/util/error.d.ts
CHANGED
|
@@ -25,4 +25,4 @@ export declare function splitMessage(input: PossibleMessage): ImmutableDictionar
|
|
|
25
25
|
* Name a message by applying a `name: ` prefix to it.
|
|
26
26
|
* - Assumes each line in the message is a separate error, so each line has the same prefix applied.
|
|
27
27
|
*/
|
|
28
|
-
export declare function getNamedMessage(name: string, message: string): string;
|
|
28
|
+
export declare function getNamedMessage(name: string | number, message: string): string;
|
package/util/item.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import type { ImmutableArray } from "./array.js";
|
|
2
2
|
import type { Data } from "./data.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/** Allowed types for the "id" property (identifier) for an item. */
|
|
4
|
+
export type Identifier = string | number;
|
|
5
|
+
/** An item object is a data object that includes an "id" identifier property that is either a string or number. */
|
|
6
|
+
export type Item<I extends Identifier, T extends Data> = {
|
|
7
|
+
id: I;
|
|
8
|
+
} & T;
|
|
8
9
|
/** Entity or `undefined` to indicate the item doesn't exist. */
|
|
9
|
-
export type OptionalItem<
|
|
10
|
-
/** Get the
|
|
11
|
-
export declare function
|
|
12
|
-
/** Get the
|
|
13
|
-
export declare function
|
|
10
|
+
export type OptionalItem<I extends Identifier, T extends Data> = Item<I, T> | undefined;
|
|
11
|
+
/** Get the identifier from an item object. */
|
|
12
|
+
export declare function getIdentifier<I extends Identifier, T extends Data>({ id }: Item<I, T>): I;
|
|
13
|
+
/** Get the identifiers from an iterable set item objects. */
|
|
14
|
+
export declare function getIdentifiers<I extends Identifier, T extends Data>(entities: Iterable<Item<I, T>>): Iterable<I>;
|
|
15
|
+
/** Does a data object or data item object. */
|
|
16
|
+
export declare function hasIdentifier<I extends Identifier, T extends Data>(item: T | Item<I, T>, id: I): item is Item<I, T>;
|
|
14
17
|
/** Merge an ID into a set of data to make an `ItemData` */
|
|
15
|
-
export declare function getItem<T extends Data>(id:
|
|
18
|
+
export declare function getItem<I extends Identifier, T extends Data>(id: I, data: T | Item<I, T>): Item<I, T>;
|
|
16
19
|
/** An array of item data. */
|
|
17
|
-
export type Items<
|
|
18
|
-
/** A set of query constraints for item data. */
|
|
19
|
-
export type ItemQuery<T extends Data = Data> = Query<Item<T>>;
|
|
20
|
-
/** Get query that targets a single database item by its ID. */
|
|
21
|
-
export declare function getItemQuery<T extends Data>(id: string): Query<Item<T>>;
|
|
20
|
+
export type Items<I extends Identifier, T extends Data> = ImmutableArray<Item<I, T>>;
|
package/util/item.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
/** Get the
|
|
2
|
-
export function
|
|
1
|
+
/** Get the identifier from an item object. */
|
|
2
|
+
export function getIdentifier({ id }) {
|
|
3
3
|
return id;
|
|
4
4
|
}
|
|
5
|
-
/** Get the
|
|
6
|
-
export function*
|
|
5
|
+
/** Get the identifiers from an iterable set item objects. */
|
|
6
|
+
export function* getIdentifiers(entities) {
|
|
7
7
|
for (const { id } of entities)
|
|
8
8
|
yield id;
|
|
9
9
|
}
|
|
10
|
+
/** Does a data object or data item object. */
|
|
11
|
+
export function hasIdentifier(item, id) {
|
|
12
|
+
return item.id === id;
|
|
13
|
+
}
|
|
10
14
|
/** Merge an ID into a set of data to make an `ItemData` */
|
|
11
15
|
export function getItem(id, data) {
|
|
12
|
-
return data
|
|
13
|
-
}
|
|
14
|
-
export function getItemQuery(id) {
|
|
15
|
-
return { id, $limit: 1 };
|
|
16
|
+
return hasIdentifier(data, id) ? data : { ...data, id };
|
|
16
17
|
}
|
package/util/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ImmutableArray } from "./array.js";
|
|
2
2
|
import type { Data, LeafData, LeafKey } from "./data.js";
|
|
3
|
+
import type { Item } from "./item.js";
|
|
3
4
|
/** Query that can be applied to a list of data objects. */
|
|
4
5
|
export type Query<T extends Data> = {
|
|
5
6
|
readonly [K in LeafKey<T> as `${K}` | `!${K}`]?: LeafData<T>[K] | ImmutableArray<LeafData<T>[K]> | undefined;
|
|
@@ -11,6 +12,8 @@ export type Query<T extends Data> = {
|
|
|
11
12
|
readonly $order?: `${LeafKey<T>}` | `!${LeafKey<T>}` | undefined | ImmutableArray<`${LeafKey<T>}` | `!${LeafKey<T>}` | undefined>;
|
|
12
13
|
readonly $limit?: number | undefined;
|
|
13
14
|
};
|
|
15
|
+
/** A set of query constraints for item data. */
|
|
16
|
+
export type ItemQuery<I extends string | number, T extends Data> = Query<Item<I, T>>;
|
|
14
17
|
/** A single filter that can be applied to a list of data objects. */
|
|
15
18
|
export type Filter = {
|
|
16
19
|
key: string;
|
package/util/random.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export declare function getRandomKey(length?: number): string;
|
|
|
13
13
|
/** Get a random character from a string. */
|
|
14
14
|
export declare function getRandomCharacter(str: string): string;
|
|
15
15
|
/** Get a random item from an array or random character from a string string. */
|
|
16
|
-
export declare function getRandomItem<T>(arr: ImmutableArray<T>): T;
|
|
16
|
+
export declare function getRandomItem<I, T>(arr: ImmutableArray<T>): T;
|
package/util/set.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ export declare function getSet<T>(value: PossibleSet<T>): ImmutableSet;
|
|
|
16
16
|
/** Apply a limit to a set. */
|
|
17
17
|
export declare function limitSet<T>(set: ImmutableSet<T>, limit: number): ImmutableSet<T>;
|
|
18
18
|
/** Is an unknown value an item in a set? */
|
|
19
|
-
export declare function isSetItem<T>(set: ImmutableSet<T>, item: unknown): item is T;
|
|
19
|
+
export declare function isSetItem<I, T>(set: ImmutableSet<T>, item: unknown): item is T;
|
|
20
20
|
/** Assert that an unknown value is an item in a set. */
|
|
21
|
-
export declare function assertSetItem<T>(set: ImmutableSet<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
21
|
+
export declare function assertSetItem<I, T>(set: ImmutableSet<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
22
22
|
/** Add an item to a set (by reference) and return the set item. */
|
|
23
|
-
export declare function addSetItem<T>(set: MutableSet<T>, item: T): T;
|
|
23
|
+
export declare function addSetItem<I, T>(set: MutableSet<T>, item: T): T;
|
|
24
24
|
/** Add multiple items to a set (by reference). */
|
|
25
25
|
export declare function addSetItems<T>(set: MutableSet<T>, ...items: T[]): void;
|
|
26
26
|
/** Remove multiple items from a set (by reference). */
|