shelving 1.89.3 → 1.89.5

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.5",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
package/util/debug.d.ts CHANGED
@@ -2,16 +2,15 @@
2
2
  import type { ImmutableArray } from "./array.js";
3
3
  import type { ImmutableMap } from "./map.js";
4
4
  import type { ImmutableSet } from "./set.js";
5
- import type { ImmutableObject } from "./object.js";
6
5
  /** Debug a random value as a string. */
7
- export declare function debug(value: unknown): string;
6
+ export declare function debug(value: unknown, depth?: number): string;
8
7
  /** Debug a string. */
9
8
  export declare const debugString: (value: string) => string;
10
9
  /** Debug an array. */
11
- export declare function debugArray(value: ImmutableArray): string;
10
+ export declare function debugArray(value: ImmutableArray, depth?: number): string;
12
11
  /** Debug a set. */
13
- export declare function debugSet(value: ImmutableSet): string;
12
+ export declare function debugSet(value: ImmutableSet, depth?: number): string;
14
13
  /** Debug a map. */
15
- export declare function debugMap(value: ImmutableMap): string;
14
+ export declare function debugMap(value: ImmutableMap, depth?: number): string;
16
15
  /** Debug an object. */
17
- export declare function debugObject(value: ImmutableObject): string;
16
+ export declare function debugObject(value: object, depth?: number): string;
package/util/debug.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-control-regex */
2
2
  /** Debug a random value as a string. */
3
- export function debug(value) {
3
+ export function debug(value, depth = 1) {
4
4
  if (value === null)
5
5
  return "null";
6
6
  if (value === undefined)
@@ -21,12 +21,12 @@ export function debug(value) {
21
21
  if (value instanceof Error)
22
22
  return value.toString();
23
23
  if (value instanceof Array)
24
- return debugArray(value);
24
+ return debugArray(value, depth);
25
25
  if (value instanceof Map)
26
- return debugMap(value);
26
+ return debugMap(value, depth);
27
27
  if (value instanceof Set)
28
- return debugSet(value);
29
- return debugObject(value);
28
+ return debugSet(value, depth);
29
+ return debugObject(value, depth);
30
30
  }
31
31
  return typeof value;
32
32
  }
@@ -36,29 +36,42 @@ const ESCAPE_REGEXP = /[\x00-\x08\x0B-\x1F\x7F-\x9F"\\]/g; // Match control char
36
36
  const ESCAPE_LIST = { '"': '\\"', "\\": "\\\\", "\r": "\\r", "\n": "\\n", "\t": "\\t", "\b": "\\b", "\f": "\\f", "\v": "\\v" };
37
37
  const _escapeChar = (char) => ESCAPE_LIST[char] || `\\x${char.charCodeAt(0).toString(16).padStart(2, "00")}`;
38
38
  /** Debug an array. */
39
- export function debugArray(value) {
39
+ export function debugArray(value, depth = 1) {
40
40
  const prototype = Object.getPrototypeOf(value);
41
41
  const name = prototype === Array.prototype ? "" : prototype.constructor.name || "";
42
- return `${name ? `${name} ` : ""}${value.length ? `[\n\t${value.map(debug).join(",\n\t")}\n]` : "[]"}`;
42
+ const items = depth > 0 && value.length ? value.map(v => debug(v, depth - 1)).join(",\n\t") : "";
43
+ return `${name ? `${name} ` : ""}${value.length ? `[\n\t${items}\n]` : "[]"}`;
43
44
  }
44
45
  /** Debug a set. */
45
- export function debugSet(value) {
46
+ export function debugSet(value, depth = 1) {
46
47
  const prototype = Object.getPrototypeOf(value);
47
48
  const name = prototype === Set.prototype ? "" : prototype.constructor.name || "Set";
48
- return `${name}(value.size) ${value.size ? `{\n\t${Array.from(value).map(debug).join(",\n\t")}\n}` : "{}"}`;
49
+ const items = depth > 0 && value.size
50
+ ? Array.from(value)
51
+ .map(v => debug(v, depth - 1))
52
+ .join(",\n\t")
53
+ : "";
54
+ return `${name}(value.size) ${items ? `{\n\t${items}\n}` : "{}"}`;
49
55
  }
50
56
  /** Debug a map. */
51
- export function debugMap(value) {
57
+ export function debugMap(value, depth = 1) {
52
58
  const prototype = Object.getPrototypeOf(value);
53
59
  const name = prototype === Map.prototype ? "" : prototype.constructor.name || "Map";
54
- return `${name}(value.size) ${value.size ? `{\n\t${Array.from(value).map(_debugProp).join(",\n\t")}\n}` : "{}"}`;
60
+ const entries = depth > 0 && value.size
61
+ ? Array.from(value)
62
+ .map(([k, v]) => `${debug(k)}: ${debug(v, depth - 1)}`)
63
+ .join(",\n\t")
64
+ : "";
65
+ return `${name}(value.size) ${entries ? `{\n\t${entries}\n}` : "{}"}`;
55
66
  }
56
67
  /** Debug an object. */
57
- export function debugObject(value) {
68
+ export function debugObject(value, depth = 1) {
58
69
  const prototype = Object.getPrototypeOf(value);
59
70
  const name = prototype === Object.prototype ? "" : prototype.constructor.name || "";
60
- const props = Object.entries(value).map(_debugProp);
61
- return `${name ? `${name} ` : ""}${props.length ? `{\n\t${props.join(",\n\t")}\n}` : "{}"}`;
71
+ const entries = depth > 0
72
+ ? Object.entries(value)
73
+ .map(([k, v]) => `${debug(k)}: ${debug(v, depth - 1)}`)
74
+ .join(",\n\t")
75
+ : "";
76
+ return `${name ? `${name} ` : ""}${entries ? `{\n\t${entries}\n}` : "{}"}`;
62
77
  }
63
- /** Debug a prop. */
64
- const _debugProp = ([key, value]) => `${debug(key)}: ${debug(value)}`;