shelving 1.96.2 → 1.98.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.
Files changed (75) hide show
  1. package/db/ItemReference.d.ts +3 -3
  2. package/db/ItemState.d.ts +2 -2
  3. package/db/ItemState.js +6 -6
  4. package/db/QueryReference.d.ts +2 -2
  5. package/db/QueryState.d.ts +2 -2
  6. package/db/QueryState.js +6 -5
  7. package/firestore/client/FirestoreClientProvider.js +7 -6
  8. package/firestore/lite/FirestoreLiteProvider.js +2 -1
  9. package/firestore/server/FirestoreServerProvider.js +7 -6
  10. package/iterate/AbstractGenerator.d.ts +1 -1
  11. package/iterate/AbstractGenerator.js +3 -10
  12. package/package.json +1 -1
  13. package/provider/CacheProvider.js +2 -2
  14. package/provider/DebugProvider.js +53 -75
  15. package/provider/MemoryProvider.d.ts +16 -17
  16. package/provider/MemoryProvider.js +54 -93
  17. package/provider/ValidationProvider.js +11 -11
  18. package/react/useReduce.js +2 -2
  19. package/react/useState.js +6 -11
  20. package/sequence/AbstractSequence.d.ts +1 -1
  21. package/sequence/AbstractSequence.js +3 -10
  22. package/sequence/DeferredSequence.d.ts +10 -8
  23. package/sequence/DeferredSequence.js +11 -10
  24. package/sequence/SwitchingDeferredSequence.d.ts +8 -0
  25. package/sequence/SwitchingDeferredSequence.js +13 -0
  26. package/sequence/SwitchingSequence.d.ts +10 -0
  27. package/sequence/SwitchingSequence.js +52 -0
  28. package/sequence/index.d.ts +2 -2
  29. package/sequence/index.js +2 -2
  30. package/state/ArrayState.d.ts +2 -1
  31. package/state/ArrayState.js +2 -2
  32. package/state/BooleanState.d.ts +2 -1
  33. package/state/BooleanState.js +2 -2
  34. package/state/DataState.d.ts +2 -2
  35. package/state/DataState.js +2 -2
  36. package/state/DictionaryState.d.ts +2 -1
  37. package/state/DictionaryState.js +2 -2
  38. package/state/State.d.ts +21 -12
  39. package/state/State.js +33 -20
  40. package/util/array.d.ts +6 -6
  41. package/util/array.js +9 -10
  42. package/util/async.d.ts +16 -24
  43. package/util/async.js +16 -33
  44. package/util/callback.d.ts +22 -0
  45. package/util/callback.js +26 -0
  46. package/util/class.d.ts +0 -25
  47. package/util/class.js +0 -61
  48. package/util/constants.d.ts +4 -2
  49. package/util/constants.js +4 -2
  50. package/util/data.d.ts +0 -2
  51. package/util/error.d.ts +2 -2
  52. package/util/function.d.ts +0 -18
  53. package/util/function.js +0 -28
  54. package/util/index.d.ts +1 -1
  55. package/util/index.js +1 -1
  56. package/util/map.d.ts +2 -2
  57. package/util/map.js +2 -2
  58. package/util/match.d.ts +2 -0
  59. package/util/match.js +6 -0
  60. package/util/null.d.ts +2 -2
  61. package/util/random.d.ts +3 -1
  62. package/util/random.js +9 -1
  63. package/util/sequence.d.ts +5 -5
  64. package/util/sequence.js +16 -16
  65. package/util/switch.d.ts +33 -0
  66. package/util/switch.js +49 -0
  67. package/util/timeout.d.ts +3 -4
  68. package/util/timeout.js +3 -8
  69. package/util/undefined.d.ts +5 -5
  70. package/sequence/LazyDeferredSequence.d.ts +0 -9
  71. package/sequence/LazyDeferredSequence.js +0 -14
  72. package/sequence/RegisteringSequence.d.ts +0 -9
  73. package/sequence/RegisteringSequence.js +0 -51
  74. package/util/activity.d.ts +0 -38
  75. package/util/activity.js +0 -64
@@ -1,8 +1,8 @@
1
1
  import type { DeleteChange, SetChange, UpdateChange } from "./Change.js";
2
2
  import type { AsyncProvider, Provider } from "../provider/Provider.js";
3
3
  import type { ImmutableArray } from "../util/array.js";
4
+ import type { Callback, ErrorCallback, StopCallback } from "../util/callback.js";
4
5
  import type { Data } from "../util/data.js";
5
- import type { Dispatch, Handler, Stop } from "../util/function.js";
6
6
  import type { Query } from "../util/query.js";
7
7
  import type { Updates } from "../util/update.js";
8
8
  /** Item data with a string ID that uniquely identifies it. */
@@ -10,7 +10,7 @@ export type ItemData<T extends Data = Data> = T & {
10
10
  id: string;
11
11
  };
12
12
  /** Entity or `null` to indicate the item doesn't exist. */
13
- export type ItemValue<T extends Data = Data> = ItemData<T> | null;
13
+ export type ItemValue<T extends Data = Data> = ItemData<T> | undefined;
14
14
  /** Get the ID from item data. */
15
15
  export declare const getID: <T extends Data>({ id }: ItemData<T>) => string;
16
16
  /** Get the IDs of an iterable set item data. */
@@ -61,7 +61,7 @@ declare abstract class AbstractItemReference<T extends Data = Data> implements A
61
61
  getDelete(): DeleteChange;
62
62
  toString(): string;
63
63
  /** Subscribe to this item. */
64
- subscribe(onNext?: Dispatch<[ItemValue<T>]>, onError?: Handler): Stop;
64
+ subscribe(onNext?: Callback<ItemValue<T>>, onError?: ErrorCallback): StopCallback;
65
65
  [Symbol.asyncIterator](): AsyncIterator<ItemValue<T>>;
66
66
  }
67
67
  /** Reference to an item in a synchronous database. */
package/db/ItemState.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AsyncItemReference, ItemData, ItemReference, ItemValue } from "./ItemReference.js";
2
+ import type { StopCallback } from "../util/callback.js";
2
3
  import type { Data } from "../util/data.js";
3
- import type { Dispatch } from "../util/function.js";
4
4
  import { BooleanState } from "../state/BooleanState.js";
5
5
  import { State } from "../state/State.js";
6
6
  /** Hold the current state of a item. */
@@ -18,5 +18,5 @@ export declare class ItemState<T extends Data = Data> extends State<ItemValue<T>
18
18
  /** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
19
19
  refreshStale(maxAge: number): void;
20
20
  /** Subscribe this state to the source provider. */
21
- connectSource(): Dispatch;
21
+ connectSource(): StopCallback;
22
22
  }
package/db/ItemState.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CacheProvider } from "../provider/CacheProvider.js";
2
- import { LazyDeferredSequence } from "../sequence/LazyDeferredSequence.js";
2
+ import { SwitchingDeferredSequence } from "../sequence/SwitchingDeferredSequence.js";
3
3
  import { BooleanState } from "../state/BooleanState.js";
4
4
  import { State } from "../state/State.js";
5
5
  import { getRequired } from "../util/null.js";
@@ -18,16 +18,15 @@ export class ItemState extends State {
18
18
  var _a;
19
19
  const { provider, collection, id } = ref;
20
20
  const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
21
- const time = table ? table.getItemTime(id) : null;
22
- const isCached = typeof time === "number";
23
- super(table && isCached ? table.getItem(id) : State.NOVALUE, table ? new LazyDeferredSequence(() => this.from(table.getCachedItemSequence(id))) : undefined);
21
+ const time = table ? table.getQueryTime(ref) : null;
22
+ const next = table ? new SwitchingDeferredSequence(sequence => sequence.from(table.getCachedItemSequence(id))) : undefined;
23
+ super(table && typeof time === "number" ? { value: table.getItem(id), time, next } : { next });
24
24
  this.busy = new BooleanState();
25
25
  /** Refresh this state from the source provider. */
26
26
  this.refresh = () => {
27
27
  if (!this.busy.value)
28
28
  void this._refresh();
29
29
  };
30
- this._time = time;
31
30
  this.ref = ref;
32
31
  // Queue a request to refresh the value if it doesn't exist.
33
32
  if (this.loading)
@@ -35,11 +34,12 @@ export class ItemState extends State {
35
34
  }
36
35
  async _refresh() {
37
36
  this.busy.set(true);
37
+ this.error(undefined); // Optimistically clear the error.
38
38
  try {
39
39
  this.set(await this.ref.value);
40
40
  }
41
41
  catch (thrown) {
42
- this.next.reject(thrown);
42
+ this.error(thrown);
43
43
  }
44
44
  finally {
45
45
  this.busy.set(false);
@@ -1,7 +1,7 @@
1
1
  import type { ItemArray, ItemData, ItemQuery, ItemValue } from "./ItemReference.js";
2
2
  import type { AsyncProvider, Provider } from "../provider/Provider.js";
3
+ import type { Callback, ErrorCallback, StopCallback } from "../util/callback.js";
3
4
  import type { Data } from "../util/data.js";
4
- import type { Dispatch, Handler, Stop } from "../util/function.js";
5
5
  import type { Updates } from "../util/update.js";
6
6
  /** Reference to a set of items in a sync or async provider. */
7
7
  declare abstract class AbstractQueryReference<T extends Data = Data> implements AsyncIterable<ItemArray<T>> {
@@ -62,7 +62,7 @@ declare abstract class AbstractQueryReference<T extends Data = Data> implements
62
62
  abstract delete(): number | PromiseLike<number>;
63
63
  toString(): string;
64
64
  /** Subscribe to this item. */
65
- subscribe(onNext?: Dispatch<[ItemArray<T>]>, onError?: Handler): Stop;
65
+ subscribe(onNext?: Callback<ItemArray<T>>, onError?: ErrorCallback): StopCallback;
66
66
  [Symbol.asyncIterator](): AsyncIterator<ItemArray<T>>;
67
67
  }
68
68
  /** Reference to a set of items in a provider. */
@@ -1,7 +1,7 @@
1
1
  import type { ItemArray, ItemData, ItemValue } from "./ItemReference.js";
2
2
  import type { AsyncQueryReference, QueryReference } from "./QueryReference.js";
3
+ import type { StopCallback } from "../util/callback.js";
3
4
  import type { Data } from "../util/data.js";
4
- import type { Stop } from "../util/function.js";
5
5
  import { BooleanState } from "../state/BooleanState.js";
6
6
  import { State } from "../state/State.js";
7
7
  /** Hold the current state of a query. */
@@ -31,7 +31,7 @@ export declare class QueryState<T extends Data = Data> extends State<ItemArray<T
31
31
  /** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
32
32
  refreshStale(maxAge: number): void;
33
33
  /** Subscribe this state to the source provider. */
34
- connectSource(): Stop;
34
+ connectSource(): StopCallback;
35
35
  /**
36
36
  * Load more items after the last once.
37
37
  * - Promise that needs to be handled.
package/db/QueryState.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CacheProvider } from "../provider/CacheProvider.js";
2
- import { LazyDeferredSequence } from "../sequence/LazyDeferredSequence.js";
2
+ import { SwitchingDeferredSequence } from "../sequence/SwitchingDeferredSequence.js";
3
3
  import { BooleanState } from "../state/BooleanState.js";
4
4
  import { State } from "../state/State.js";
5
5
  import { getOptionalFirstItem, getOptionalLastItem } from "../util/array.js";
@@ -41,8 +41,8 @@ export class QueryState extends State {
41
41
  const { provider, collection, query } = ref;
42
42
  const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
43
43
  const time = table ? table.getQueryTime(ref) : null;
44
- const isCached = typeof time === "number";
45
- super(table && isCached ? table.getQuery(ref) : State.NOVALUE, table ? new LazyDeferredSequence(() => this.from(table.getCachedQuerySequence(ref))) : undefined);
44
+ const next = table ? new SwitchingDeferredSequence(sequence => sequence.from(table.getCachedQuerySequence(ref))) : undefined;
45
+ super(table && typeof time === "number" ? { value: table.getQuery(ref), time, next } : { next });
46
46
  this.busy = new BooleanState();
47
47
  this._hasMore = false;
48
48
  /** Refresh this state from the source provider. */
@@ -58,7 +58,6 @@ export class QueryState extends State {
58
58
  if (!this.busy.value)
59
59
  void this._loadMore();
60
60
  };
61
- this._time = time;
62
61
  this.ref = ref;
63
62
  this.limit = (_b = getLimit(query)) !== null && _b !== void 0 ? _b : Infinity;
64
63
  // Queue a request to refresh the value if it doesn't exist.
@@ -67,6 +66,7 @@ export class QueryState extends State {
67
66
  }
68
67
  async _refresh() {
69
68
  this.busy.set(true);
69
+ this.error(undefined); // Optimistically clear the error.
70
70
  try {
71
71
  const items = await this.ref.items;
72
72
  this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
@@ -90,6 +90,7 @@ export class QueryState extends State {
90
90
  }
91
91
  async _loadMore() {
92
92
  this.busy.set(true);
93
+ this.error(undefined); // Optimistically clear the error.
93
94
  try {
94
95
  const last = this.last;
95
96
  const ref = last ? this.ref.with(getAfterQuery(this.ref.query, last)) : this.ref;
@@ -98,7 +99,7 @@ export class QueryState extends State {
98
99
  this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
99
100
  }
100
101
  catch (thrown) {
101
- this.next.reject(thrown);
102
+ this.error(thrown);
102
103
  }
103
104
  finally {
104
105
  this.busy.set(false);
@@ -1,5 +1,5 @@
1
1
  import { addDoc, collection, deleteDoc, doc, documentId, getDoc, getDocs, increment, limit, onSnapshot, orderBy, query, setDoc, updateDoc, where } from "firebase/firestore";
2
- import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
2
+ import { SwitchingDeferredSequence } from "../../sequence/SwitchingDeferredSequence.js";
3
3
  import { getObject } from "../../util/object.js";
4
4
  import { getFilters, getLimit, getOrders } from "../../util/query.js";
5
5
  import { mapItems } from "../../util/transform.js";
@@ -40,7 +40,8 @@ function _getItemData(snapshot) {
40
40
  }
41
41
  function _getItemValue(snapshot) {
42
42
  const data = snapshot.data();
43
- return data ? { ...data, id: snapshot.id } : null;
43
+ if (data)
44
+ return { ...data, id: snapshot.id };
44
45
  }
45
46
  /** Convert `Updates` object into corresponding Firestore `FieldValue` instances. */
46
47
  const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
@@ -59,9 +60,9 @@ export class FirestoreClientProvider {
59
60
  return _getItemValue(await getDoc(doc(this._firestore, c, id)));
60
61
  }
61
62
  getItemSequence(c, id) {
62
- return new LazyDeferredSequence(({ resolve, reject }) => onSnapshot(doc(this._firestore, c, id), //
63
+ return new SwitchingDeferredSequence(sequence => onSnapshot(doc(this._firestore, c, id), //
63
64
  //
64
- snapshot => resolve(_getItemValue(snapshot)), reject));
65
+ snapshot => sequence.resolve(_getItemValue(snapshot)), reason => sequence.reject(reason)));
65
66
  }
66
67
  async addItem(c, data) {
67
68
  const reference = await addDoc(collection(this._firestore, c), data);
@@ -80,9 +81,9 @@ export class FirestoreClientProvider {
80
81
  return _getItems(await getDocs(_getQuery(this._firestore, c, q)));
81
82
  }
82
83
  getQuerySequence(c, q) {
83
- return new LazyDeferredSequence(({ resolve, reject }) => onSnapshot(_getQuery(this._firestore, c, q), //
84
+ return new SwitchingDeferredSequence(sequence => onSnapshot(_getQuery(this._firestore, c, q), //
84
85
  //
85
- snapshot => resolve(_getItems(snapshot)), reject));
86
+ snapshot => sequence.resolve(_getItems(snapshot)), reason => sequence.reject(reason)));
86
87
  }
87
88
  async setQuery(c, q, data) {
88
89
  const snapshot = await getDocs(_getQuery(this._firestore, c, q));
@@ -37,7 +37,8 @@ function _getItemData(snapshot) {
37
37
  }
38
38
  function _getItemValue(snapshot) {
39
39
  const data = snapshot.data();
40
- return data ? { ...data, id: snapshot.id } : null;
40
+ if (data)
41
+ return { ...data, id: snapshot.id };
41
42
  }
42
43
  /** Convert `Updates` object into corresponding Firestore `FieldValue` instances. */
43
44
  const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
@@ -1,5 +1,5 @@
1
1
  import { FieldPath, FieldValue, Firestore } from "@google-cloud/firestore";
2
- import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
2
+ import { SwitchingDeferredSequence } from "../../sequence/SwitchingDeferredSequence.js";
3
3
  import { getObject } from "../../util/object.js";
4
4
  import { getFilters, getLimit, getOrders } from "../../util/query.js";
5
5
  import { mapItems } from "../../util/transform.js";
@@ -39,7 +39,8 @@ function _getItemData(snapshot) {
39
39
  }
40
40
  function _getItemValue(snapshot) {
41
41
  const data = snapshot.data();
42
- return data ? { ...data, id: snapshot.id } : null;
42
+ if (data)
43
+ return { ...data, id: snapshot.id };
43
44
  }
44
45
  /** Convert `Update` instances into corresponding Firestore `FieldValue` instances. */
45
46
  const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
@@ -57,8 +58,8 @@ export class FirestoreServerProvider {
57
58
  }
58
59
  getItemSequence(c, id) {
59
60
  const ref = this._firestore.collection(c).doc(id);
60
- return new LazyDeferredSequence(({ resolve, reject }) => ref.onSnapshot(snapshot => resolve(_getItemValue(snapshot)), //
61
- reject));
61
+ return new SwitchingDeferredSequence(sequence => ref.onSnapshot(snapshot => sequence.resolve(_getItemValue(snapshot)), //
62
+ sequence.reject));
62
63
  }
63
64
  async addItem(c, data) {
64
65
  return (await this._firestore.collection(c).add(data)).id;
@@ -77,8 +78,8 @@ export class FirestoreServerProvider {
77
78
  }
78
79
  getQuerySequence(c, q) {
79
80
  const ref = _getQuery(this._firestore, c, q);
80
- return new LazyDeferredSequence(({ resolve, reject }) => ref.onSnapshot(snapshot => resolve(_getItemArray(snapshot)), //
81
- reject));
81
+ return new SwitchingDeferredSequence(sequence => ref.onSnapshot(snapshot => sequence.resolve(_getItemArray(snapshot)), //
82
+ sequence.reject));
82
83
  }
83
84
  async setQuery(c, q, data) {
84
85
  return await bulkWrite(this._firestore, c, q, (w, s) => void w.set(s.ref, data));
@@ -1,6 +1,6 @@
1
1
  /** Abstract generator designed to be extended that implements the full generator protocol. */
2
2
  export declare abstract class AbstractGenerator<T, R, N> implements Generator<T, R, N> {
3
- readonly [Symbol.toStringTag]: string;
3
+ readonly [Symbol.toStringTag] = "Generator";
4
4
  abstract next(value: N): IteratorResult<T, R>;
5
5
  throw(thrown: Error | unknown): IteratorResult<T, R>;
6
6
  return(value: R): IteratorResult<T, R>;
@@ -1,13 +1,9 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
1
  var _a;
8
- import { setPrototype } from "../util/class.js";
9
2
  /** Abstract generator designed to be extended that implements the full generator protocol. */
10
3
  export class AbstractGenerator {
4
+ constructor() {
5
+ this[_a] = "Generator";
6
+ }
11
7
  throw(thrown) {
12
8
  // Default behaviour for a generator is to throw the error back out of the iterator and not continue.
13
9
  throw thrown;
@@ -21,6 +17,3 @@ export class AbstractGenerator {
21
17
  return this;
22
18
  }
23
19
  }
24
- __decorate([
25
- setPrototype(Symbol.toStringTag, "Generator")
26
- ], AbstractGenerator.prototype, _a, void 0);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.96.2",
14
+ "version": "1.98.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -37,12 +37,12 @@ export class CacheProvider {
37
37
  async getQuery(collection, query) {
38
38
  const items = await this.source.getQuery(collection, query);
39
39
  const table = this.memory.getTable(collection);
40
- table.setQueryItems(query, items);
40
+ table.setQueryArray(query, items);
41
41
  return items;
42
42
  }
43
43
  async *getQuerySequence(collection, query) {
44
44
  const table = this.memory.getTable(collection);
45
- yield* table.setQueryItemsSequence(query, this.source.getQuerySequence(collection, query));
45
+ yield* table.setQueryArraySequence(query, this.source.getQuerySequence(collection, query));
46
46
  }
47
47
  async setQuery(collection, query, data) {
48
48
  const count = await this.source.setQuery(collection, query, data);
@@ -2,31 +2,29 @@
2
2
  /** Provider that logs operations to a source provider to the console. */
3
3
  class AbstractDebugProvider {
4
4
  async *getItemSequence(collection, id) {
5
- const key = _getItemKey(collection, id);
6
5
  try {
7
- console.log("ITERATE", key, "DATA:");
6
+ console.debug("ITERATE", collection, id);
8
7
  for await (const item of this.source.getItemSequence(collection, id)) {
9
- console.log("ITERATE", key, "GOT:", item);
8
+ console.debug("ITERATE", collection, id, "GOT", item);
10
9
  yield item;
11
10
  }
12
- console.log("ITERATE", key, "DONE");
11
+ console.debug("ITERATE", collection, id);
13
12
  }
14
13
  catch (thrown) {
15
- console.error("ITERATE", key, thrown);
14
+ console.error("ITERATE", collection, id, thrown);
16
15
  }
17
16
  }
18
17
  async *getQuerySequence(collection, query) {
19
- const key = _getQueryKey(collection, query);
20
18
  try {
21
- console.log("ITERATE", key, "DATA:");
19
+ console.debug("ITERATE", collection, query);
22
20
  for await (const items of this.source.getQuerySequence(collection, query)) {
23
- console.log("ITERATE", key, "ITEMS:", items);
21
+ console.debug("ITERATE", collection, query, items);
24
22
  yield items;
25
23
  }
26
- console.log("ITERATE", key, "DONE");
24
+ console.debug("ITERATE", collection, query);
27
25
  }
28
26
  catch (thrown) {
29
- console.error("ITERATE", key, thrown);
27
+ console.error("ITERATE", collection, query, thrown);
30
28
  }
31
29
  }
32
30
  }
@@ -37,107 +35,98 @@ export class DebugProvider extends AbstractDebugProvider {
37
35
  this.source = source;
38
36
  }
39
37
  getItem(collection, id) {
40
- const key = _getItemKey(collection, id);
41
38
  try {
42
39
  const item = this.source.getItem(collection, id);
43
- console.log("GET:", key, "ITEM:", item);
40
+ console.debug("GET", collection, id, "ITEM", item);
44
41
  return item;
45
42
  }
46
43
  catch (reason) {
47
- console.error("GET:", key, "ERROR:", reason);
44
+ console.error("GET", collection, id, reason);
48
45
  throw reason;
49
46
  }
50
47
  }
51
48
  addItem(collection, data) {
52
- const key = collection;
53
49
  try {
54
50
  const id = this.source.addItem(collection, data);
55
- console.log("ADD", key, "DATA:", data, "ID", id);
51
+ console.debug("ADD", collection, data, "ID", id);
56
52
  return id;
57
53
  }
58
54
  catch (reason) {
59
- console.error("ADD", key, "DATA:", data, "ERROR:", reason);
55
+ console.error("ADD", collection, data, reason);
60
56
  throw reason;
61
57
  }
62
58
  }
63
59
  setItem(collection, id, data) {
64
- const key = _getItemKey(collection, id);
65
60
  try {
66
61
  this.source.setItem(collection, id, data);
67
- console.log("SET:", key, "DATA:", data);
62
+ console.debug("SET", collection, id, data);
68
63
  }
69
64
  catch (reason) {
70
- console.error("SET:", key, "DATA:", data, "ERROR:", reason);
65
+ console.error("SET", collection, id, data, reason);
71
66
  throw reason;
72
67
  }
73
68
  }
74
69
  updateItem(collection, id, updates) {
75
- const key = _getItemKey(collection, id);
76
70
  try {
77
- console.log("UPDATE:", key, "UPDATES:", updates);
71
+ console.debug("UPDATE", collection, id, updates);
78
72
  return this.source.updateItem(collection, id, updates);
79
73
  }
80
74
  catch (reason) {
81
- console.error("UPDATE:", key, "UPDATES:", updates, "ERROR:", reason);
75
+ console.error("UPDATE", collection, id, updates, reason);
82
76
  throw reason;
83
77
  }
84
78
  }
85
79
  deleteItem(collection, id) {
86
- const key = _getItemKey(collection, id);
87
80
  try {
88
81
  this.source.deleteItem(collection, id);
89
- console.log("DELETE:", key);
82
+ console.debug("DELETE", collection, id);
90
83
  }
91
84
  catch (reason) {
92
- console.error("DELETE:", key, "ERROR:", reason);
85
+ console.error("DELETE", collection, id, reason);
93
86
  throw reason;
94
87
  }
95
88
  }
96
89
  getQuery(collection, query) {
97
- const key = _getQueryKey(collection, query);
98
90
  try {
99
91
  const items = this.source.getQuery(collection, query);
100
- console.log("GET:", key, "ITEMS:", items);
92
+ console.debug("✔ ✅ GET", collection, query, "ITEMS", items);
101
93
  return items;
102
94
  }
103
95
  catch (reason) {
104
- console.error("GET:", key, "ERROR:", reason);
96
+ console.error("GET", collection, query, reason);
105
97
  throw reason;
106
98
  }
107
99
  }
108
100
  setQuery(collection, query, data) {
109
- const key = _getQueryKey(collection, query);
110
101
  try {
111
102
  const num = this.source.setQuery(collection, query, data);
112
- console.log("SET:", key, "DATA:", data, "DONE:", num);
103
+ console.debug("SET", collection, query, data, num);
113
104
  return num;
114
105
  }
115
106
  catch (reason) {
116
- console.error("SET:", key, "DATA:", data, "ERROR:", reason);
107
+ console.error("SET", collection, query, data, reason);
117
108
  throw reason;
118
109
  }
119
110
  }
120
111
  updateQuery(collection, query, updates) {
121
- const key = _getQueryKey(collection, query);
122
112
  try {
123
113
  const num = this.source.updateQuery(collection, query, updates);
124
- console.log("UPDATE:", key, "UPDATES:", updates, "DONE:", num);
114
+ console.debug("UPDATE", collection, query, updates, num);
125
115
  return num;
126
116
  }
127
117
  catch (reason) {
128
- console.error("UPDATE:", key, "UPDATES:", updates, "ERROR:", reason);
118
+ console.error("UPDATE", collection, query, updates, reason);
129
119
  throw reason;
130
120
  }
131
121
  }
132
122
  deleteQuery(collection, query) {
133
- const key = _getQueryKey(collection, query);
134
123
  try {
135
124
  const num = this.source.deleteQuery(collection, query);
136
- console.log("DELETE:", key, "DONE:", num);
125
+ console.debug("DELETE", collection, query, num);
137
126
  return num;
138
127
  }
139
128
  catch (reason) {
140
- console.error("DELETE:", key, "ERROR:", reason);
129
+ console.error("DELETE", collection, query, reason);
141
130
  throw reason;
142
131
  }
143
132
  }
@@ -149,119 +138,108 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
149
138
  this.source = source;
150
139
  }
151
140
  async getItem(collection, id) {
152
- const key = _getItemKey(collection, id);
153
141
  try {
154
- console.log("GET:", key);
142
+ console.debug("GET", collection, id);
155
143
  const item = await this.source.getItem(collection, id);
156
- console.log("GET:", key, "ITEM:", item);
144
+ console.debug("GET", collection, id, "ITEM", item);
157
145
  return item;
158
146
  }
159
147
  catch (reason) {
160
- console.error("GET:", key, "ERROR:", reason);
148
+ console.error("GET", collection, id, reason);
161
149
  throw reason;
162
150
  }
163
151
  }
164
152
  async addItem(collection, data) {
165
- const key = collection;
166
153
  try {
167
- console.log("ADD", key, "DATA:", data);
154
+ console.debug("ADD", collection, data);
168
155
  const id = await this.source.addItem(collection, data);
169
- console.log("ADD", key, "DATA:", data, "ID:", id);
156
+ console.debug("ADD", collection, id, data);
170
157
  return id;
171
158
  }
172
159
  catch (reason) {
173
- console.error("ADD", key, "DATA:", data, "ERROR:", reason);
160
+ console.error("ADD", collection, data, reason);
174
161
  throw reason;
175
162
  }
176
163
  }
177
164
  async setItem(collection, id, data) {
178
- const key = _getItemKey(collection, id);
179
165
  try {
180
- console.log("SET:", key, "DATA:", data);
166
+ console.debug("SET", collection, id, data);
181
167
  await this.source.setItem(collection, id, data);
182
- console.log("SET:", key, "DATA:", data, "DONE:", 1);
168
+ console.debug("SET", collection, id, data, 1);
183
169
  }
184
170
  catch (reason) {
185
- console.error("SET:", key, "DATA:", data, "ERROR:", reason);
171
+ console.error("SET", collection, id, data, reason);
186
172
  throw reason;
187
173
  }
188
174
  }
189
175
  async updateItem(collection, id, updates) {
190
- const key = _getItemKey(collection, id);
191
176
  try {
192
- console.log("UPDATE:", key, "UPDATES:", updates);
177
+ console.debug("UPDATE", collection, id, updates);
193
178
  await this.source.updateItem(collection, id, updates);
194
- console.log("UPDATE:", key, "UPDATES:", updates, "DONE:", 1);
179
+ console.debug("UPDATE", collection, id, updates, 1);
195
180
  }
196
181
  catch (reason) {
197
- console.error("UPDATE:", key, "UPDATES:", updates, "ERROR:", reason);
182
+ console.error("UPDATE", collection, id, updates, reason);
198
183
  throw reason;
199
184
  }
200
185
  }
201
186
  async deleteItem(collection, id) {
202
- const key = _getItemKey(collection, id);
203
187
  try {
204
- console.log("DELETE:", key);
188
+ console.debug("DELETE", collection, id);
205
189
  await this.source.deleteItem(collection, id);
206
- console.log("DELETE:", key, "DONE:", 1);
190
+ console.debug("DELETE", collection, id, 1);
207
191
  }
208
192
  catch (reason) {
209
- console.error("DELETE:", key, "ERROR:", reason);
193
+ console.error("DELETE", collection, id, reason);
210
194
  throw reason;
211
195
  }
212
196
  }
213
197
  async getQuery(collection, query) {
214
- const key = _getQueryKey(collection, query);
215
198
  try {
216
- console.log("GET:", key);
199
+ console.debug("GET", collection, query);
217
200
  const items = await this.source.getQuery(collection, query);
218
- console.log("GET:", key, "ITEMS:", items);
201
+ console.debug("GET", collection, query, "ITEMS", items);
219
202
  return items;
220
203
  }
221
204
  catch (reason) {
222
- console.error("GET:", key, "ERROR:", reason);
205
+ console.error("GET", collection, query, reason);
223
206
  throw reason;
224
207
  }
225
208
  }
226
209
  async setQuery(collection, query, data) {
227
- const key = _getQueryKey(collection, query);
228
210
  try {
229
- console.log("SET:", key, "DATA:", data);
211
+ console.debug("SET", collection, query, data);
230
212
  const num = await this.source.setQuery(collection, query, data);
231
- console.log("SET:", key, "DATA:", data, "DONE:", num);
213
+ console.debug("SET", collection, query, data, num);
232
214
  return num;
233
215
  }
234
216
  catch (reason) {
235
- console.error("SET:", key, "DATA:", data, "ERROR:", reason);
217
+ console.error("SET", collection, query, data, reason);
236
218
  throw reason;
237
219
  }
238
220
  }
239
221
  async updateQuery(collection, query, updates) {
240
- const key = _getQueryKey(collection, query);
241
222
  try {
242
- console.log("UPDATE:", key, "UPDATES:", updates);
223
+ console.debug("UPDATE", collection, query, updates);
243
224
  const num = await this.source.updateQuery(collection, query, updates);
244
- console.log("UPDATE:", key, "UPDATES:", updates, "DONE:", num);
225
+ console.debug("UPDATE", collection, query, updates, num);
245
226
  return num;
246
227
  }
247
228
  catch (reason) {
248
- console.error("UPDATE:", key, "UPDATES:", updates, "ERROR:", reason);
229
+ console.error("UPDATE", collection, query, updates, reason);
249
230
  throw reason;
250
231
  }
251
232
  }
252
233
  async deleteQuery(collection, query) {
253
- const key = _getQueryKey(collection, query);
254
234
  try {
255
- console.log("DELETE:", key);
235
+ console.debug("DELETE", collection, query);
256
236
  const num = await this.source.deleteQuery(collection, query);
257
- console.log("DELETE:", key, "DONE:", num);
237
+ console.debug("DELETE", collection, query, num);
258
238
  return num;
259
239
  }
260
240
  catch (reason) {
261
- console.error("DELETE:", key, "ERROR:", reason);
241
+ console.error("DELETE", collection, query, reason);
262
242
  throw reason;
263
243
  }
264
244
  }
265
245
  }
266
- const _getItemKey = (collection, id) => `${collection}/${id}`;
267
- const _getQueryKey = (collection, query) => `${collection}?${JSON.stringify(query)}`;