shelving 1.116.1 → 1.116.2
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/ConvenienceProvider.js +19 -6
- package/package.json +1 -1
- package/store/PathStore.js +2 -2
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { getItemAdd, getItemDelete, getItemSet, getItemUpdate, getQueryDelete, getQuerySet, getQueryUpdate, writeAsyncProviderChange, writeAsyncProviderChanges, writeProviderChange, writeProviderChanges } from "../change/Change.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { RequiredError } from "../error/RequiredError.js";
|
|
3
|
+
import { getOptionalFirstItem } from "../util/array.js";
|
|
4
|
+
import {} from "../util/optional.js";
|
|
4
5
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
5
6
|
export class ConvenienceProvider extends ThroughProvider {
|
|
6
7
|
requireItem(collection, id) {
|
|
7
|
-
|
|
8
|
+
const item = this.getItem(collection, id);
|
|
9
|
+
if (!item)
|
|
10
|
+
throw new RequiredError(`Item must exist in "${collection}"`, id);
|
|
11
|
+
return item;
|
|
8
12
|
}
|
|
9
13
|
getFirst(collection, query) {
|
|
10
14
|
return getOptionalFirstItem(this.getQuery(collection, { ...query, $limit: 1 }));
|
|
11
15
|
}
|
|
12
16
|
requireFirst(collection, query) {
|
|
13
|
-
|
|
17
|
+
const first = this.getFirst(collection, query);
|
|
18
|
+
if (!first)
|
|
19
|
+
throw new RequiredError(`First item must exist in "${collection}"`, query);
|
|
20
|
+
return first;
|
|
14
21
|
}
|
|
15
22
|
getItemAdd(collection, data) {
|
|
16
23
|
return getItemAdd(this, collection, data);
|
|
@@ -42,13 +49,19 @@ export class ConvenienceProvider extends ThroughProvider {
|
|
|
42
49
|
}
|
|
43
50
|
export class AsyncConvenienceProvider extends AsyncThroughProvider {
|
|
44
51
|
async requireItem(collection, id) {
|
|
45
|
-
|
|
52
|
+
const item = await this.getItem(collection, id);
|
|
53
|
+
if (!item)
|
|
54
|
+
throw new RequiredError(`Item must exist in "${collection}"`, id);
|
|
55
|
+
return item;
|
|
46
56
|
}
|
|
47
57
|
async getFirst(collection, query) {
|
|
48
58
|
return getOptionalFirstItem(await this.getQuery(collection, { ...query, $limit: 1 }));
|
|
49
59
|
}
|
|
50
60
|
async requireFirst(collection, query) {
|
|
51
|
-
|
|
61
|
+
const first = await this.getFirst(collection, query);
|
|
62
|
+
if (!first)
|
|
63
|
+
throw new RequiredError(`First item must exist in "${collection}"`, query);
|
|
64
|
+
return first;
|
|
52
65
|
}
|
|
53
66
|
getItemAdd(collection, data) {
|
|
54
67
|
return getItemAdd(this, collection, data);
|
package/package.json
CHANGED
package/store/PathStore.js
CHANGED
|
@@ -7,11 +7,11 @@ export class PathStore extends Store {
|
|
|
7
7
|
}
|
|
8
8
|
/** Based on the current store path, is a path active? */
|
|
9
9
|
isActive(path) {
|
|
10
|
-
return isPathActive(
|
|
10
|
+
return isPathActive(this.value, path);
|
|
11
11
|
}
|
|
12
12
|
/** Based on the current store path, is a path proud (i.e. a child of the current store path)? */
|
|
13
13
|
isProud(path) {
|
|
14
|
-
return isPathProud(
|
|
14
|
+
return isPathProud(this.value, path);
|
|
15
15
|
}
|
|
16
16
|
/** Get an absolute path from a path relative to the current store path. */
|
|
17
17
|
getPath(path) {
|