shelving 1.89.2 → 1.89.4

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.
@@ -1,4 +1,4 @@
1
- import type { Data, Datas, DataKey } from "../util/data.js";
1
+ import type { Data } from "../util/data.js";
2
2
  import type { ItemArray, ItemValue, ItemData, ItemConstraints } from "../db/Item.js";
3
3
  import { Updates } from "../update/DataUpdate.js";
4
4
  import { DeferredSequence } from "../sequence/DeferredSequence.js";
@@ -8,30 +8,27 @@ import type { Provider } from "./Provider.js";
8
8
  * - Extremely fast (ideal for caching!), but does not persist data after the browser window is closed.
9
9
  * - `get()` etc return the exact same instance of an object that's passed into `set()`
10
10
  */
11
- export declare class MemoryProvider<T extends Datas> implements Provider<T> {
11
+ export declare class MemoryProvider implements Provider {
12
12
  /** List of tables in `{ collection: Table }` format. */
13
13
  private _tables;
14
14
  /** Get a table for a collection. */
15
- getTable<K extends DataKey<T>>(collection: K): MemoryTable<T[K]>;
16
- getDocumentTime<K extends DataKey<T>>(collection: K, id: string): number | null;
17
- getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
18
- getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
19
- addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
20
- setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
21
- updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
22
- deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
23
- getQueryTime<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number | null;
24
- getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
25
- getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
26
- setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
27
- updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
28
- deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
15
+ getTable(collection: string): MemoryTable;
16
+ getDocumentTime(collection: string, id: string): number | null;
17
+ getItem(collection: string, id: string): ItemValue;
18
+ getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
19
+ addItem(collection: string, data: Data): string;
20
+ setItem(collection: string, id: string, data: Data): void;
21
+ updateItem(collection: string, id: string, updates: Updates): void;
22
+ deleteItem(collection: string, id: string): void;
23
+ getQueryTime(collection: string, constraints: ItemConstraints): number | null;
24
+ getQuery(collection: string, constraints: ItemConstraints): ItemArray;
25
+ getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterable<ItemArray>;
26
+ setQuery(collection: string, constraints: ItemConstraints, data: Data): number;
27
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): number;
28
+ deleteQuery(collection: string, constraints: ItemConstraints): number;
29
29
  }
30
- /**
31
- * An individual table of data.
32
- * - Fires with an array of string IDs.
33
- */
34
- export declare class MemoryTable<T extends Data> {
30
+ /** An individual table of data. */
31
+ export declare class MemoryTable<T extends Data = Data> {
35
32
  /** Actual data in this table. */
36
33
  protected readonly _data: Map<string, ItemData<T>>;
37
34
  /** Times data was last updated. */
@@ -47,7 +44,7 @@ export declare class MemoryTable<T extends Data> {
47
44
  private _setItemData;
48
45
  setItem(id: string, item: ItemData<T> | T): void;
49
46
  setItemValue(id: string, value: ItemData<T> | T | null): void;
50
- setItemValueSequence(id: string, sequence: AsyncIterable<ItemValue<T>>): AsyncIterable<ItemValue<T>>;
47
+ setItemValueSequence(id: string, sequence: AsyncIterable<ItemValue<T>>): AsyncIterable<ItemValue>;
51
48
  updateItem(id: string, updates: Updates<T>): void;
52
49
  deleteItem(id: string): void;
53
50
  getQueryTime(constraints: ItemConstraints<T>): number | null;
@@ -59,10 +59,7 @@ export class MemoryProvider {
59
59
  return this.getTable(collection).deleteQuery(constraints);
60
60
  }
61
61
  }
62
- /**
63
- * An individual table of data.
64
- * - Fires with an array of string IDs.
65
- */
62
+ /** An individual table of data. */
66
63
  export class MemoryTable {
67
64
  constructor() {
68
65
  /** Actual data in this table. */
@@ -1,18 +1,18 @@
1
1
  import type { Updates } from "../update/DataUpdate.js";
2
- import type { Datas, DataKey } from "../util/data.js";
2
+ import type { Data } from "../util/data.js";
3
3
  import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
4
4
  /** Provides access to data (e.g. IndexedDB, Firebase, or in-memory cache providers). */
5
- declare abstract class AbstractProvider<T extends Datas = Datas> {
5
+ declare abstract class AbstractProvider {
6
6
  /**
7
7
  * Get the value of a item.
8
8
  *
9
9
  * @return The item value, or `null` if it doesn't exist.
10
10
  */
11
- abstract getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | PromiseLike<ItemValue<T[K]>>;
11
+ abstract getItem(collection: string, id: string): ItemValue | PromiseLike<ItemValue>;
12
12
  /**
13
13
  * Subscribe to the value of this item with an async iterator.
14
14
  */
15
- abstract getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
15
+ abstract getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
16
16
  /**
17
17
  * Create a new item with a random ID.
18
18
  * - Created item is guaranteed to have a unique ID.
@@ -20,75 +20,75 @@ declare abstract class AbstractProvider<T extends Datas = Datas> {
20
20
  * @param data Complete data to set the item to.
21
21
  * @return String ID for the created item (possibly promised).
22
22
  */
23
- abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): string | PromiseLike<string>;
23
+ abstract addItem(collection: string, data: Data): string | PromiseLike<string>;
24
24
  /**
25
25
  * Set the data a item (whether it exists or not).
26
26
  * @param data Data to set the item to.
27
27
  */
28
- abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void | PromiseLike<void>;
28
+ abstract setItem(collection: string, id: string, data: Data): void | PromiseLike<void>;
29
29
  /**
30
30
  * Update the data an existing item.
31
31
  *
32
32
  * @param updates Set of property updates to apply to the item.
33
33
  * @throws Error If the item does not exist (ideally a `RequiredError` but may be provider-specific).
34
34
  */
35
- abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void | PromiseLike<void>;
35
+ abstract updateItem(collection: string, id: string, updates: Updates): void | PromiseLike<void>;
36
36
  /**
37
37
  * Delete a specified item.
38
38
  */
39
- abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): void | PromiseLike<void>;
39
+ abstract deleteItem(collection: string, id: string): void | PromiseLike<void>;
40
40
  /**
41
41
  * Get all matching items.
42
42
  *
43
43
  * @return Set of values in `id: data` format.
44
44
  */
45
- abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]> | PromiseLike<ItemArray<T[K]>>;
45
+ abstract getQuery(collection: string, constraints: ItemConstraints): ItemArray | PromiseLike<ItemArray>;
46
46
  /**
47
47
  * Subscribe to all matching items with an async iterator.
48
48
  */
49
- abstract getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
49
+ abstract getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterable<ItemArray>;
50
50
  /**
51
51
  * Set the data of all matching items.
52
52
  *
53
53
  * @param data Data to set matching items to.
54
54
  * @return Number of items that were set.
55
55
  */
56
- abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number | PromiseLike<number>;
56
+ abstract setQuery(collection: string, constraints: ItemConstraints, data: Data): number | PromiseLike<number>;
57
57
  /**
58
58
  * Update the data of all matching items.
59
59
  *
60
60
  * @param updates Set of property updates to apply to matching items.
61
61
  * @return Number of items that were updated.
62
62
  */
63
- abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number | PromiseLike<number>;
63
+ abstract updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): number | PromiseLike<number>;
64
64
  /**
65
65
  * Delete all matching items.
66
66
  * @return Number of items that were deleted.
67
67
  */
68
- abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number | PromiseLike<number>;
68
+ abstract deleteQuery(collection: string, constraints: ItemConstraints): number | PromiseLike<number>;
69
69
  }
70
70
  /** Provider with a fully synchronous interface */
71
- export declare abstract class Provider<T extends Datas = Datas> extends AbstractProvider<T> {
72
- abstract getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
73
- abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
74
- abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
75
- abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
76
- abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
77
- abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
78
- abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
79
- abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
80
- abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
71
+ export declare abstract class Provider extends AbstractProvider {
72
+ abstract getItem(collection: string, id: string): ItemValue;
73
+ abstract addItem(collection: string, data: Data): string;
74
+ abstract setItem(collection: string, id: string, data: Data): void;
75
+ abstract updateItem(collection: string, id: string, updates: Updates): void;
76
+ abstract deleteItem(collection: string, id: string): void;
77
+ abstract getQuery(collection: string, constraints: ItemConstraints): ItemArray;
78
+ abstract setQuery(collection: string, constraints: ItemConstraints, data: Data): number;
79
+ abstract updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): number;
80
+ abstract deleteQuery(collection: string, constraints: ItemConstraints): number;
81
81
  }
82
82
  /** Provider with a fully asynchronous interface */
83
- export declare abstract class AsyncProvider<T extends Datas = Datas> extends AbstractProvider<T> {
84
- abstract getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
85
- abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
86
- abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
87
- abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
88
- abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
89
- abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
90
- abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
91
- abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
92
- abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
83
+ export declare abstract class AsyncProvider extends AbstractProvider {
84
+ abstract getItem(collection: string, id: string): Promise<ItemValue>;
85
+ abstract addItem(collection: string, data: Data): Promise<string>;
86
+ abstract setItem(collection: string, id: string, data: Data): Promise<void>;
87
+ abstract updateItem(collection: string, id: string, updates: Updates): Promise<void>;
88
+ abstract deleteItem(collection: string, id: string): Promise<void>;
89
+ abstract getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
90
+ abstract setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
91
+ abstract updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
92
+ abstract deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
93
93
  }
94
94
  export {};
@@ -1,37 +1,37 @@
1
- import type { Datas, DataKey } from "../util/data.js";
1
+ import type { Data } from "../util/data.js";
2
2
  import type { Sourceable } from "../util/source.js";
3
3
  import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
4
4
  import type { Updates } from "../update/DataUpdate.js";
5
5
  import type { Provider, AsyncProvider } from "./Provider.js";
6
6
  /** A provider that passes through to a synchronous source. */
7
- export declare class ThroughProvider<T extends Datas = Datas> implements Provider<T>, Sourceable<Provider<T>> {
8
- readonly source: Provider<T>;
9
- constructor(source: Provider<T>);
10
- getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
11
- getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
12
- addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
13
- setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
14
- updateItem<K extends DataKey<T>>(collection: K, id: string, update: Updates<T[K]>): void;
15
- deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
16
- getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
17
- getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
18
- setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
19
- updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: Updates<T[K]>): number;
20
- deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
7
+ export declare class ThroughProvider implements Provider, Sourceable<Provider> {
8
+ readonly source: Provider;
9
+ constructor(source: Provider);
10
+ getItem(collection: string, id: string): ItemValue;
11
+ getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
12
+ addItem(collection: string, data: Data): string;
13
+ setItem(collection: string, id: string, data: Data): void;
14
+ updateItem(collection: string, id: string, update: Updates): void;
15
+ deleteItem(collection: string, id: string): void;
16
+ getQuery(collection: string, constraints: ItemConstraints): ItemArray;
17
+ getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterable<ItemArray>;
18
+ setQuery(collection: string, constraints: ItemConstraints, data: Data): number;
19
+ updateQuery(collection: string, constraints: ItemConstraints, update: Updates): number;
20
+ deleteQuery(collection: string, constraints: ItemConstraints): number;
21
21
  }
22
22
  /** A provider that passes through to an asynchronous source. */
23
- export declare class AsyncThroughProvider<T extends Datas = Datas> implements AsyncProvider<T>, Sourceable<AsyncProvider<T>> {
24
- readonly source: AsyncProvider<T>;
25
- constructor(source: AsyncProvider<T>);
26
- getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
27
- getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
28
- addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
29
- setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
30
- updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
31
- deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
32
- getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
33
- getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
34
- setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
35
- updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
36
- deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
23
+ export declare class AsyncThroughProvider implements AsyncProvider, Sourceable<AsyncProvider> {
24
+ readonly source: AsyncProvider;
25
+ constructor(source: AsyncProvider);
26
+ getItem(collection: string, id: string): Promise<ItemValue>;
27
+ getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
28
+ addItem(collection: string, data: Data): Promise<string>;
29
+ setItem(collection: string, id: string, data: Data): Promise<void>;
30
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
31
+ deleteItem(collection: string, id: string): Promise<void>;
32
+ getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
33
+ getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterable<ItemArray>;
34
+ setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
35
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
36
+ deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
37
37
  }
@@ -14,7 +14,7 @@ declare abstract class BaseValidationProvider<T extends Datas> {
14
14
  getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
15
15
  }
16
16
  /** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
17
- export declare class ValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements Provider<T>, Sourceable<Provider> {
17
+ export declare class ValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements Provider, Sourceable<Provider> {
18
18
  readonly source: Provider;
19
19
  constructor(source: Provider, schemas: DataSchemas<T>);
20
20
  getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
@@ -28,7 +28,7 @@ export declare class ValidationProvider<T extends Datas> extends BaseValidationP
28
28
  deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
29
29
  }
30
30
  /** Validate an asynchronous source provider (source can have any type because validation guarantees the type). */
31
- export declare class AsyncValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements AsyncProvider<T>, Sourceable<AsyncProvider> {
31
+ export declare class AsyncValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements AsyncProvider, Sourceable<AsyncProvider> {
32
32
  readonly source: AsyncProvider;
33
33
  constructor(source: AsyncProvider, schemas: DataSchemas<T>);
34
34
  getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
@@ -4,11 +4,10 @@ import { AsyncItem } from "../db/Item.js";
4
4
  import { ItemState } from "../db/ItemState.js";
5
5
  import { AsyncQuery } from "../db/Query.js";
6
6
  import { QueryState } from "../db/QueryState.js";
7
- type AnyRef = AsyncItem<any, any> | AsyncQuery<any, any>;
8
- type RefToState<T> = T extends undefined ? undefined : T extends AsyncItem<infer D, infer K> ? ItemState<D, K> : T extends AsyncQuery<infer D, infer K> ? QueryState<D, K> : never;
7
+ type RefToState<T> = T extends undefined ? undefined : T extends AsyncItem<infer X> ? ItemState<X> : T extends AsyncQuery<infer X> ? QueryState<X> : never;
9
8
  /** Use one or more data items or queries. */
10
- export declare function useData<T extends AnyRef | undefined>(ref: T): RefToState<T>;
11
- export declare function useData<T extends ImmutableArray<AnyRef | undefined>>(...refs: T): {
9
+ export declare function useData<T extends AsyncItem | AsyncQuery | undefined>(ref: T): RefToState<T>;
10
+ export declare function useData<T extends ImmutableArray<AsyncItem | AsyncQuery | undefined>>(...refs: T): {
12
11
  [K in keyof T]: RefToState<T[K]>;
13
12
  };
14
13
  /** Wrap components with `<DataCache>` to allow the use of `useData()`. */