shelving 1.89.3 → 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.
package/db/Change.d.ts CHANGED
@@ -3,28 +3,27 @@ import type { ImmutableArray } from "../util/array.js";
3
3
  import type { Provider, AsyncProvider } from "../provider/Provider.js";
4
4
  import { Updates } from "../update/DataUpdate.js";
5
5
  import { Nullish } from "../util/null.js";
6
- import { DeepIterable } from "../util/iterate.js";
7
6
  /** Change on a collection. */
8
7
  export interface Change {
9
8
  readonly action: string;
10
9
  readonly collection: string;
11
10
  }
12
11
  /** Add on an item. */
13
- export interface AddChange extends Change {
12
+ export interface AddChange<T extends Data> extends Change {
14
13
  readonly action: "ADD";
15
- readonly data: Data;
14
+ readonly data: T;
16
15
  }
17
16
  /** Set on an item. */
18
- export interface SetChange extends Change {
17
+ export interface SetChange<T extends Data = Data> extends Change {
19
18
  readonly action: "SET";
20
19
  readonly id: string;
21
- readonly data: Data;
20
+ readonly data: T;
22
21
  }
23
22
  /** Update change on an item. */
24
- export interface UpdateChange extends Change {
23
+ export interface UpdateChange<T extends Data = Data> extends Change {
25
24
  readonly action: "UPDATE";
26
25
  readonly id: string;
27
- readonly updates: Updates;
26
+ readonly updates: Updates<T>;
28
27
  }
29
28
  /** Delete change on an item. */
30
29
  export interface DeleteChange extends Change {
@@ -32,14 +31,14 @@ export interface DeleteChange extends Change {
32
31
  readonly id: string;
33
32
  }
34
33
  /** Set, update, or delete change on an item. */
35
- export type ItemChange = SetChange | UpdateChange | DeleteChange;
34
+ export type ItemChange<T extends Data = Data> = SetChange<T> | UpdateChange<T> | DeleteChange;
36
35
  /** Array of item changes. */
37
36
  export type ItemChanges = ImmutableArray<ItemChange>;
38
37
  /** Write change on an item. */
39
- export type WriteChange = ItemChange | AddChange;
38
+ export type WriteChange<T extends Data = Data> = ItemChange<T> | AddChange<T>;
40
39
  /** Array of write changes. */
41
40
  export type WriteChanges = ImmutableArray<WriteChange>;
42
41
  /** Apply a set of changes to a synchronous provider. */
43
- export declare function changeProvider(provider: Provider, ...changes: DeepIterable<Nullish<WriteChange>>[]): ItemChanges;
42
+ export declare function changeProvider(provider: Provider, ...changes: Nullish<WriteChange>[]): ItemChanges;
44
43
  /** Apply a set of changes to an asynchronous provider. */
45
- export declare function changeAsyncProvider(provider: AsyncProvider, ...changes: DeepIterable<Nullish<WriteChange>>[]): Promise<ItemChanges>;
44
+ export declare function changeAsyncProvider(provider: AsyncProvider, ...changes: Nullish<WriteChange>[]): Promise<ItemChanges>;
package/db/Change.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { notNullish } from "../util/null.js";
2
- import { flattenItems } from "../util/iterate.js";
3
2
  import { getItemConstraints } from "./Item.js";
4
3
  /** Apply a set of changes to a synchronous provider. */
5
4
  export function changeProvider(provider, ...changes) {
6
- return Array.from(flattenItems(changes)).filter(notNullish).map(_changeItem, provider);
5
+ return changes.filter(notNullish).map(_changeItem, provider);
7
6
  }
8
7
  function _changeItem(change) {
9
8
  const { action, collection } = change;
@@ -19,7 +18,7 @@ function _changeItem(change) {
19
18
  }
20
19
  /** Apply a set of changes to an asynchronous provider. */
21
20
  export function changeAsyncProvider(provider, ...changes) {
22
- return Promise.all(Array.from(flattenItems(changes)).filter(notNullish).map(_changeAsyncItem, provider));
21
+ return Promise.all(changes.filter(notNullish).map(_changeAsyncItem, provider));
23
22
  }
24
23
  async function _changeAsyncItem(change) {
25
24
  const { collection, action } = change;
@@ -25,11 +25,11 @@ declare abstract class BaseCollection<T extends Data = Data> {
25
25
  /** Delete a document in this collection. */
26
26
  abstract delete(id: string): void | Promise<void>;
27
27
  /** Get an add change for this collection. */
28
- getAdd(data: T): AddChange;
28
+ getAdd(data: T): AddChange<T>;
29
29
  /** Get a set change for this collection. */
30
- getSet(id: string, data: T): SetChange;
30
+ getSet(id: string, data: T): SetChange<T>;
31
31
  /** Get an update change for this collection. */
32
- getUpdate(id: string, updates: Updates<T>): UpdateChange;
32
+ getUpdate(id: string, updates: Updates<T>): UpdateChange<T>;
33
33
  /** Get a delete change for this collection. */
34
34
  getDelete(id: string): DeleteChange;
35
35
  toString(): string;
package/db/Database.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { DataKey, Datas } from "../util/data.js";
2
2
  import type { Nullish } from "../util/null.js";
3
- import type { DeepIterable } from "../util/iterate.js";
4
3
  import type { AsyncProvider, Provider } from "../provider/Provider.js";
5
4
  import type { FilterList } from "../constraint/FilterConstraint.js";
6
5
  import type { SortList } from "../constraint/SortConstraint.js";
@@ -20,7 +19,7 @@ declare abstract class BaseDatabase<T extends Datas> {
20
19
  /** Reference an item in a collection in this database. */
21
20
  abstract item<K extends DataKey<T>>(collection: K, id: string): Item<T[K]> | AsyncItem<T[K]>;
22
21
  /** Run a set of changes in this database. */
23
- abstract change(...changes: DeepIterable<Nullish<WriteChange>>[]): ItemChanges | Promise<ItemChanges>;
22
+ abstract change(...changes: Nullish<WriteChange>[]): ItemChanges | Promise<ItemChanges>;
24
23
  /** Get a document from a collection in this database. */
25
24
  abstract get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
26
25
  /** Add a document to a collection in this database. */
@@ -32,11 +31,11 @@ declare abstract class BaseDatabase<T extends Datas> {
32
31
  /** Delete a document from a collection in this database. */
33
32
  abstract delete<K extends DataKey<T>>(collection: K, id: string): void | Promise<void>;
34
33
  /** Get an add change for a collection in this database. */
35
- getAdd<K extends DataKey<T>>(collection: K, data: T[K]): AddChange;
34
+ getAdd<K extends DataKey<T>>(collection: K, data: T[K]): AddChange<T[K]>;
36
35
  /** Get a set change for a collection in this database. */
37
- getSet<K extends DataKey<T>>(collection: K, id: string, data: T[K]): SetChange;
36
+ getSet<K extends DataKey<T>>(collection: K, id: string, data: T[K]): SetChange<T[K]>;
38
37
  /** Get an update change for a collection in this database. */
39
- getUpdate<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange;
38
+ getUpdate<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T[K]>;
40
39
  /** Get a delete change for a collection in this database. */
41
40
  getDelete<K extends DataKey<T>>(collection: K, id: string): DeleteChange;
42
41
  }
@@ -47,7 +46,7 @@ export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
47
46
  collection<K extends DataKey<T>>(collection: K): Collection<T[K]>;
48
47
  query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T[K]>;
49
48
  item<K extends DataKey<T>>(collection: K, id: string): Item<T[K]>;
50
- change(...changes: DeepIterable<Nullish<WriteChange>>[]): ItemChanges;
49
+ change(...changes: Nullish<WriteChange>[]): ItemChanges;
51
50
  get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
52
51
  add<K extends DataKey<T>>(collection: K, data: T[K]): string;
53
52
  set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
@@ -61,7 +60,7 @@ export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase
61
60
  collection<K extends DataKey<T>>(collection: K): AsyncCollection<T[K]>;
62
61
  query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T[K]>;
63
62
  item<K extends DataKey<T>>(collection: K, id: string): AsyncItem<T[K]>;
64
- change(...changes: DeepIterable<Nullish<WriteChange>>[]): Promise<ItemChanges>;
63
+ change(...changes: Nullish<WriteChange>[]): Promise<ItemChanges>;
65
64
  get<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
66
65
  add<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
67
66
  set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
package/db/Database.js CHANGED
@@ -37,7 +37,7 @@ export class Database extends BaseDatabase {
37
37
  return new Item(this.provider, collection, id);
38
38
  }
39
39
  change(...changes) {
40
- return changeProvider(this.provider, changes);
40
+ return changeProvider(this.provider, ...changes);
41
41
  }
42
42
  get(collection, id) {
43
43
  return this.provider.getItem(collection, id);
@@ -71,7 +71,7 @@ export class AsyncDatabase extends BaseDatabase {
71
71
  return new AsyncItem(this.provider, collection, id);
72
72
  }
73
73
  change(...changes) {
74
- return changeAsyncProvider(this.provider, changes);
74
+ return changeAsyncProvider(this.provider, ...changes);
75
75
  }
76
76
  get(collection, id) {
77
77
  return this.provider.getItem(collection, id);
package/db/Item.d.ts CHANGED
@@ -51,9 +51,9 @@ declare abstract class BaseItem<T extends Data = Data> implements AsyncIterable<
51
51
  /** Delete this item. */
52
52
  abstract delete(): void | PromiseLike<void>;
53
53
  /** Get a set change for this item. */
54
- getSet(data: T): SetChange;
54
+ getSet(data: T): SetChange<T>;
55
55
  /** Get an update change for this item. */
56
- getUpdate(updates: Updates<T>): UpdateChange;
56
+ getUpdate(updates: Updates<T>): UpdateChange<T>;
57
57
  /** Get a delete change for this item. */
58
58
  getDelete(): DeleteChange;
59
59
  toString(): string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.89.3",
14
+ "version": "1.89.4",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",