shelving 1.134.1 → 1.136.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.
- package/api/Resource.d.ts +2 -2
- package/api/Resource.js +4 -4
- package/db/ItemStore.js +9 -2
- package/db/Provider.js +29 -8
- package/db/QueryStore.js +16 -4
- package/db/ValidationProvider.js +26 -26
- package/error/AssertionError.d.ts +8 -0
- package/error/AssertionError.js +12 -0
- package/error/BaseError.d.ts +19 -0
- package/error/BaseError.js +18 -0
- package/error/NetworkError.d.ts +5 -0
- package/error/NetworkError.js +9 -0
- package/error/RequestError.d.ts +32 -0
- package/error/RequestError.js +50 -0
- package/error/RequiredError.d.ts +8 -0
- package/error/RequiredError.js +12 -0
- package/error/UnexpectedError.d.ts +5 -0
- package/error/UnexpectedError.js +9 -0
- package/error/UnimplementedError.d.ts +5 -0
- package/error/UnimplementedError.js +9 -0
- package/error/ValueError.d.ts +5 -0
- package/error/ValueError.js +9 -0
- package/error/index.d.ts +8 -8
- package/error/index.js +8 -8
- package/firestore/lite/FirestoreLiteProvider.js +3 -3
- package/iterate/InspectIterator.js +14 -4
- package/markup/rule/link.js +2 -2
- package/package.json +1 -1
- package/react/createCacheContext.js +12 -13
- package/react/createDataContext.js +2 -2
- package/schema/AllowSchema.js +2 -2
- package/schema/DateSchema.d.ts +1 -1
- package/schema/DateSchema.js +12 -12
- package/schema/FileSchema.js +2 -2
- package/schema/LinkSchema.js +2 -2
- package/schema/SlugSchema.js +2 -2
- package/schema/TimeSchema.js +4 -4
- package/sequence/InspectSequence.js +14 -4
- package/store/ArrayStore.js +6 -5
- package/store/PathStore.js +4 -4
- package/test/util.js +6 -3
- package/util/array.d.ts +39 -42
- package/util/array.js +48 -82
- package/util/async.d.ts +3 -3
- package/util/async.js +7 -7
- package/util/base64.d.ts +8 -0
- package/util/base64.js +16 -0
- package/util/boolean.js +6 -6
- package/util/class.d.ts +4 -0
- package/util/class.js +14 -3
- package/util/color.d.ts +3 -3
- package/util/color.js +8 -8
- package/util/data.d.ts +3 -3
- package/util/data.js +3 -3
- package/util/date.d.ts +20 -15
- package/util/date.js +87 -37
- package/util/dictionary.d.ts +12 -12
- package/util/dictionary.js +20 -19
- package/util/entity.js +2 -2
- package/util/equal.d.ts +4 -0
- package/util/equal.js +12 -1
- package/util/error.d.ts +0 -2
- package/util/error.js +0 -20
- package/util/file.d.ts +3 -3
- package/util/file.js +6 -6
- package/util/function.js +2 -2
- package/util/hydrate.js +5 -3
- package/util/index.d.ts +1 -2
- package/util/index.js +1 -2
- package/util/iterate.d.ts +13 -0
- package/util/iterate.js +48 -0
- package/util/link.d.ts +4 -4
- package/util/link.js +8 -8
- package/util/map.d.ts +4 -4
- package/util/map.js +9 -9
- package/util/null.js +5 -5
- package/util/number.d.ts +6 -11
- package/util/number.js +23 -18
- package/util/object.js +4 -4
- package/util/optional.js +2 -2
- package/util/path.d.ts +3 -3
- package/util/path.js +6 -6
- package/util/query.d.ts +4 -4
- package/util/query.js +10 -9
- package/util/regexp.d.ts +12 -12
- package/util/regexp.js +13 -12
- package/util/sequence.d.ts +0 -2
- package/util/sequence.js +0 -7
- package/util/serialise.js +2 -2
- package/util/set.js +3 -3
- package/util/source.d.ts +4 -8
- package/util/source.js +8 -12
- package/util/string.d.ts +14 -22
- package/util/string.js +27 -29
- package/util/template.js +10 -11
- package/util/time.d.ts +2 -5
- package/util/time.js +12 -13
- package/util/undefined.js +2 -2
- package/util/units.d.ts +17 -12
- package/util/units.js +61 -40
- package/util/url.d.ts +3 -3
- package/util/url.js +11 -7
- package/util/validate.d.ts +4 -4
- package/util/validate.js +4 -8
- package/error/CodedError.d.ts +0 -13
- package/error/CodedError.js +0 -21
- package/error/ConflictError.d.ts +0 -6
- package/error/ConflictError.js +0 -11
- package/error/ConnectionError.d.ts +0 -5
- package/error/ConnectionError.js +0 -10
- package/error/ForbiddenError.d.ts +0 -6
- package/error/ForbiddenError.js +0 -11
- package/error/NotFoundError.d.ts +0 -6
- package/error/NotFoundError.js +0 -11
- package/error/NotImplementedError.d.ts +0 -6
- package/error/NotImplementedError.js +0 -11
- package/error/UnauthorizedError.d.ts +0 -6
- package/error/UnauthorizedError.js +0 -11
- package/error/ValidationError.d.ts +0 -6
- package/error/ValidationError.js +0 -11
- package/util/assert.d.ts +0 -4
- package/util/assert.js +0 -11
- package/util/duration.d.ts +0 -10
- package/util/duration.js +0 -50
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnexpectedError } from "../error/UnexpectedError.js";
|
|
2
|
+
import { getGetter } from "../util/class.js";
|
|
2
3
|
import { ThroughIterator } from "./ThroughIterator.js";
|
|
3
4
|
/** Used when the sequence hasn't inspected anything yet. */
|
|
4
5
|
const _NOVALUE = Symbol("shelving/InspectGenerator.NOVALUE");
|
|
@@ -20,21 +21,30 @@ export class InspectIterator extends ThroughIterator {
|
|
|
20
21
|
/** The first yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
21
22
|
get first() {
|
|
22
23
|
if (this._first === _NOVALUE)
|
|
23
|
-
throw new
|
|
24
|
+
throw new UnexpectedError("Iteration not started", {
|
|
25
|
+
iterator: this,
|
|
26
|
+
caller: getGetter(this, "first"),
|
|
27
|
+
});
|
|
24
28
|
return this._first;
|
|
25
29
|
}
|
|
26
30
|
_first = _NOVALUE;
|
|
27
31
|
/** The last yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
28
32
|
get last() {
|
|
29
33
|
if (this._last === _NOVALUE)
|
|
30
|
-
throw new
|
|
34
|
+
throw new UnexpectedError("Iteration not started", {
|
|
35
|
+
iterator: this,
|
|
36
|
+
caller: getGetter(this, "last"),
|
|
37
|
+
});
|
|
31
38
|
return this._last;
|
|
32
39
|
}
|
|
33
40
|
_last = _NOVALUE;
|
|
34
41
|
/** The returned value (throws if the iteration is not done, i.e. `this.done === false`). */
|
|
35
42
|
get returned() {
|
|
36
43
|
if (this._returned === _NOVALUE)
|
|
37
|
-
throw new
|
|
44
|
+
throw new UnexpectedError("Iteration not done", {
|
|
45
|
+
iterator: this,
|
|
46
|
+
caller: getGetter(this, "returned"),
|
|
47
|
+
});
|
|
38
48
|
return this._returned;
|
|
39
49
|
}
|
|
40
50
|
_returned = _NOVALUE;
|
package/markup/rule/link.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLink } from "../../util/link.js";
|
|
2
2
|
import { getRegExp } from "../../util/regexp.js";
|
|
3
3
|
import { formatURL, getOptionalURL } from "../../util/url.js";
|
|
4
4
|
import { renderMarkup } from "../render.js";
|
|
@@ -8,7 +8,7 @@ import { getMarkupRule } from "../util/rule.js";
|
|
|
8
8
|
function renderLinkMarkupRule({ groups: { title, href: unsafeHref } }, options, key) {
|
|
9
9
|
const { base, schemes, hosts, rel } = options;
|
|
10
10
|
const url = getOptionalURL(unsafeHref, base);
|
|
11
|
-
const href =
|
|
11
|
+
const href = getLink(url, base, schemes, hosts);
|
|
12
12
|
const children = title ? renderMarkup(title, options, "link") : url ? formatURL(url) : "";
|
|
13
13
|
return {
|
|
14
14
|
key,
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { createContext, createElement, useContext, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { UnexpectedError } from "../error/UnexpectedError.js";
|
|
3
3
|
/**
|
|
4
4
|
* Create a cache context that can be provided to React elements and allows them to call `useCache()`
|
|
5
5
|
* - Cache is a `Map` indexed by strings that can be used to store any value.
|
|
6
6
|
*/
|
|
7
7
|
export function createCacheContext() {
|
|
8
8
|
const context = createContext(undefined);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return cache;
|
|
15
|
-
},
|
|
16
|
-
CacheContext({ children }) {
|
|
17
|
-
// biome-ignore lint/suspicious/noAssignInExpressions: This is the most efficient way to do this.
|
|
18
|
-
const cache = (useRef().current ||= new Map());
|
|
19
|
-
return createElement(context.Provider, { children, value: cache });
|
|
20
|
-
},
|
|
9
|
+
const useCache = () => {
|
|
10
|
+
const cache = useContext(context);
|
|
11
|
+
if (!cache)
|
|
12
|
+
throw new UnexpectedError("useCache() must be used inside <Cache>", { caller: useCache });
|
|
13
|
+
return cache;
|
|
21
14
|
};
|
|
15
|
+
const CacheContext = ({ children }) => {
|
|
16
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: This is the most efficient way to do this.
|
|
17
|
+
const cache = (useRef().current ||= new Map());
|
|
18
|
+
return createElement(context.Provider, { children, value: cache });
|
|
19
|
+
};
|
|
20
|
+
return { useCache, CacheContext };
|
|
22
21
|
}
|
|
@@ -2,7 +2,7 @@ import { CacheProvider } from "../db/CacheProvider.js";
|
|
|
2
2
|
import { ItemStore } from "../db/ItemStore.js";
|
|
3
3
|
import { QueryStore } from "../db/QueryStore.js";
|
|
4
4
|
import { setMapItem } from "../util/map.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getSource } from "../util/source.js";
|
|
6
6
|
import { createCacheContext } from "./createCacheContext.js";
|
|
7
7
|
import { useStore } from "./useStore.js";
|
|
8
8
|
/**
|
|
@@ -14,7 +14,7 @@ export function createDataContext(provider) {
|
|
|
14
14
|
// biome-ignore lint/suspicious/noExplicitAny: The outer function enforces the type.
|
|
15
15
|
const { CacheContext, useCache } = createCacheContext();
|
|
16
16
|
// If this provider is backed by an in-memory cache, pass it to the `ItemStore` and `QueryStore` instances we create.
|
|
17
|
-
const memory =
|
|
17
|
+
const memory = getSource(CacheProvider, provider)?.memory;
|
|
18
18
|
return {
|
|
19
19
|
useItem: (collection, id) => {
|
|
20
20
|
const cache = useCache();
|
package/schema/AllowSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import {
|
|
2
|
+
import { requireFirstItem } from "../util/iterate.js";
|
|
3
3
|
import { getMap, isMapItem } from "../util/map.js";
|
|
4
4
|
import { getString } from "../util/string.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
@@ -8,7 +8,7 @@ export class AllowSchema extends Schema {
|
|
|
8
8
|
allow;
|
|
9
9
|
constructor(options) {
|
|
10
10
|
const allow = getMap(options.allow);
|
|
11
|
-
const value =
|
|
11
|
+
const value = requireFirstItem(allow.keys());
|
|
12
12
|
super({ value, ...options });
|
|
13
13
|
this.allow = allow;
|
|
14
14
|
}
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class DateSchema extends Schema<string> {
|
|
|
14
14
|
readonly min: Date | undefined;
|
|
15
15
|
readonly max: Date | undefined;
|
|
16
16
|
constructor({ min, max, title, value, ...options }: DateSchemaOptions);
|
|
17
|
-
validate(
|
|
17
|
+
validate(value?: unknown): string;
|
|
18
18
|
}
|
|
19
19
|
/** Valid date, e.g. `2005-09-12` (required because falsy values are invalid). */
|
|
20
20
|
export declare const DATE: DateSchema;
|
package/schema/DateSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import { formatDate,
|
|
2
|
+
import { formatDate, getDate, requireYMD } from "../util/date.js";
|
|
3
3
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
5
5
|
/** Define a valid date in YMD format, e.g. `2005-09-12` */
|
|
@@ -8,18 +8,18 @@ export class DateSchema extends Schema {
|
|
|
8
8
|
max;
|
|
9
9
|
constructor({ min, max, title = "Date", value = "now", ...options }) {
|
|
10
10
|
super({ title, value, ...options });
|
|
11
|
-
this.min =
|
|
12
|
-
this.max =
|
|
11
|
+
this.min = getDate(min);
|
|
12
|
+
this.max = getDate(max);
|
|
13
13
|
}
|
|
14
|
-
validate(
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
throw new ValueFeedback(
|
|
18
|
-
if (this.min &&
|
|
19
|
-
throw new ValueFeedback(`Minimum ${formatDate(this.min)}`,
|
|
20
|
-
if (this.max &&
|
|
21
|
-
throw new ValueFeedback(`Maximum ${formatDate(this.max)}`,
|
|
22
|
-
return
|
|
14
|
+
validate(value = this.value) {
|
|
15
|
+
const date = getDate(value);
|
|
16
|
+
if (!date)
|
|
17
|
+
throw new ValueFeedback(value ? "Invalid date" : "Required", value);
|
|
18
|
+
if (this.min && date < this.min)
|
|
19
|
+
throw new ValueFeedback(`Minimum ${formatDate(this.min)}`, date);
|
|
20
|
+
if (this.max && date > this.max)
|
|
21
|
+
throw new ValueFeedback(`Maximum ${formatDate(this.max)}`, date);
|
|
22
|
+
return requireYMD(date);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/** Valid date, e.g. `2005-09-12` (required because falsy values are invalid). */
|
package/schema/FileSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getFileExtension } from "../util/file.js";
|
|
3
3
|
import { isProp } from "../util/object.js";
|
|
4
4
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
import { StringSchema } from "./StringSchema.js";
|
|
@@ -12,7 +12,7 @@ export class FileSchema extends StringSchema {
|
|
|
12
12
|
}
|
|
13
13
|
validate(unsafeValue = this.value) {
|
|
14
14
|
const path = super.validate(unsafeValue);
|
|
15
|
-
const extension =
|
|
15
|
+
const extension = getFileExtension(path);
|
|
16
16
|
if (!extension)
|
|
17
17
|
throw new ValueFeedback("Must be file name with extension", unsafeValue);
|
|
18
18
|
if (this.types && !isProp(this.types, extension))
|
package/schema/LinkSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getLinkURL } from "../util/link.js";
|
|
3
3
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
4
4
|
import { TextSchema } from "./TextSchema.js";
|
|
5
5
|
/**
|
|
@@ -28,7 +28,7 @@ export class LinkSchema extends TextSchema {
|
|
|
28
28
|
// Override to clean the URL using builtin helper functions and check the schemes and hosts against the whitelists.
|
|
29
29
|
validate(unsafeValue) {
|
|
30
30
|
const str = super.validate(unsafeValue);
|
|
31
|
-
const url =
|
|
31
|
+
const url = getLinkURL(str, this.base, this.schemes, this.hosts);
|
|
32
32
|
if (!url)
|
|
33
33
|
throw new ValueFeedback(str ? "Invalid format" : "Required", str);
|
|
34
34
|
return url.href;
|
package/schema/SlugSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requireSlug } from "../util/string.js";
|
|
2
2
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
3
3
|
import { StringSchema } from "./StringSchema.js";
|
|
4
4
|
/**
|
|
@@ -17,7 +17,7 @@ export class SlugSchema extends StringSchema {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
sanitize(str) {
|
|
20
|
-
return
|
|
20
|
+
return requireSlug(str);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
/** Valid slug, e.g. `this-is-a-slug` */
|
package/schema/TimeSchema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
2
|
import { roundStep } from "../util/number.js";
|
|
3
|
-
import { Time,
|
|
3
|
+
import { Time, getTime } from "../util/time.js";
|
|
4
4
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
6
6
|
/** Define a valid time in 24h hh:mm:ss.fff format, e.g. `23:59` or `24:00 */
|
|
@@ -14,12 +14,12 @@ export class TimeSchema extends Schema {
|
|
|
14
14
|
step;
|
|
15
15
|
constructor({ min, max, step = 60, title = "Time", value = "now", ...options }) {
|
|
16
16
|
super({ title, value, ...options });
|
|
17
|
-
this.min =
|
|
18
|
-
this.max =
|
|
17
|
+
this.min = getTime(min);
|
|
18
|
+
this.max = getTime(max);
|
|
19
19
|
this.step = step;
|
|
20
20
|
}
|
|
21
21
|
validate(unsafeValue = this.value) {
|
|
22
|
-
const optionalTime =
|
|
22
|
+
const optionalTime = getTime(unsafeValue);
|
|
23
23
|
if (!optionalTime)
|
|
24
24
|
throw new ValueFeedback(unsafeValue ? "Invalid time" : "Required", unsafeValue);
|
|
25
25
|
const roundedTime = typeof this.step === "number" ? new Time(roundStep(optionalTime.time, this.step)) : optionalTime;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnexpectedError } from "../error/UnexpectedError.js";
|
|
2
|
+
import { getGetter } from "../util/class.js";
|
|
2
3
|
import { ThroughSequence } from "./ThroughSequence.js";
|
|
3
4
|
/** Used when the sequence hasn't inspected anything yet. */
|
|
4
5
|
const _NOVALUE = Symbol("shelving/InspectSequence.NOVALUE");
|
|
@@ -20,21 +21,30 @@ export class InspectSequence extends ThroughSequence {
|
|
|
20
21
|
/** The first yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
21
22
|
get first() {
|
|
22
23
|
if (this._first === _NOVALUE)
|
|
23
|
-
throw new
|
|
24
|
+
throw new UnexpectedError("Iteration not started", {
|
|
25
|
+
sequence: this,
|
|
26
|
+
caller: getGetter(this, "first"),
|
|
27
|
+
});
|
|
24
28
|
return this._first;
|
|
25
29
|
}
|
|
26
30
|
_first = _NOVALUE;
|
|
27
31
|
/** The last yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
28
32
|
get last() {
|
|
29
33
|
if (this._last === _NOVALUE)
|
|
30
|
-
throw new
|
|
34
|
+
throw new UnexpectedError("Iteration not started", {
|
|
35
|
+
sequence: this,
|
|
36
|
+
caller: getGetter(this, "last"),
|
|
37
|
+
});
|
|
31
38
|
return this._last;
|
|
32
39
|
}
|
|
33
40
|
_last = _NOVALUE;
|
|
34
41
|
/** The returned value (throws if the iteration is not done, i.e. `this.done === false`). */
|
|
35
42
|
get returned() {
|
|
36
43
|
if (this._returned === _NOVALUE)
|
|
37
|
-
throw new
|
|
44
|
+
throw new UnexpectedError("Iteration not done", {
|
|
45
|
+
sequence: this,
|
|
46
|
+
caller: getGetter(this, "returned"),
|
|
47
|
+
});
|
|
38
48
|
return this._returned;
|
|
39
49
|
}
|
|
40
50
|
_returned = _NOVALUE;
|
package/store/ArrayStore.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { omitArrayItems, toggleArrayItems, withArrayItems } from "../util/array.js";
|
|
2
|
+
import { getFirstItem, getLastItem, requireFirstItem, requireLastItem } from "../util/iterate.js";
|
|
2
3
|
import { Store } from "./Store.js";
|
|
3
4
|
/** Store an array. */
|
|
4
5
|
export class ArrayStore extends Store {
|
|
@@ -7,19 +8,19 @@ export class ArrayStore extends Store {
|
|
|
7
8
|
}
|
|
8
9
|
/** Get the first item in this store or `null` if this query has no items. */
|
|
9
10
|
get optionalFirst() {
|
|
10
|
-
return
|
|
11
|
+
return getFirstItem(this.value);
|
|
11
12
|
}
|
|
12
13
|
/** Get the last item in this store or `null` if this query has no items. */
|
|
13
14
|
get optionalLast() {
|
|
14
|
-
return
|
|
15
|
+
return getLastItem(this.value);
|
|
15
16
|
}
|
|
16
17
|
/** Get the first item in this store. */
|
|
17
18
|
get first() {
|
|
18
|
-
return
|
|
19
|
+
return requireFirstItem(this.value);
|
|
19
20
|
}
|
|
20
21
|
/** Get the last item in this store. */
|
|
21
22
|
get last() {
|
|
22
|
-
return
|
|
23
|
+
return requireLastItem(this.value);
|
|
23
24
|
}
|
|
24
25
|
/** Does the document have at least one result. */
|
|
25
26
|
get exists() {
|
package/store/PathStore.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPathActive, isPathProud, requirePath } from "../util/path.js";
|
|
2
2
|
import { Store } from "./Store.js";
|
|
3
3
|
/** Store an absolute path, e.g. `/a/b/c` */
|
|
4
4
|
export class PathStore extends Store {
|
|
5
5
|
constructor(path = ".", time) {
|
|
6
|
-
super(
|
|
6
|
+
super(requirePath(path), time);
|
|
7
7
|
}
|
|
8
8
|
/** Based on the current store path, is a path active? */
|
|
9
9
|
isActive(path) {
|
|
@@ -15,10 +15,10 @@ export class PathStore extends Store {
|
|
|
15
15
|
}
|
|
16
16
|
/** Get an absolute path from a path relative to the current store path. */
|
|
17
17
|
getPath(path) {
|
|
18
|
-
return
|
|
18
|
+
return requirePath(path, this.value);
|
|
19
19
|
}
|
|
20
20
|
// Override to clean the path.
|
|
21
21
|
set(path) {
|
|
22
|
-
super.set(
|
|
22
|
+
super.set(requirePath(path, this.value));
|
|
23
23
|
}
|
|
24
24
|
}
|
package/test/util.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { expect } from "bun:test";
|
|
2
|
-
import { popErrorStack } from "../util/error.js";
|
|
3
2
|
import { getItemIDs } from "../util/item.js";
|
|
4
3
|
/** Expect that an object matches `PromiseLike` */
|
|
5
4
|
export const EXPECT_PROMISELIKE = expect.objectContaining({
|
|
@@ -13,7 +12,9 @@ export function expectUnorderedItems(items, keys) {
|
|
|
13
12
|
expect(Array.from(getItemIDs(items)).sort()).toEqual(Array.from(keys).sort());
|
|
14
13
|
}
|
|
15
14
|
catch (thrown) {
|
|
16
|
-
|
|
15
|
+
if (thrown instanceof Error)
|
|
16
|
+
Error.captureStackTrace(thrown, expectUnorderedItems);
|
|
17
|
+
throw thrown;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
/** Expect `Item` objects with an `.id` prop in a specified order. */
|
|
@@ -23,6 +24,8 @@ export function expectOrderedItems(items, keys) {
|
|
|
23
24
|
expect(Array.from(getItemIDs(items))).toEqual(Array.from(keys));
|
|
24
25
|
}
|
|
25
26
|
catch (thrown) {
|
|
26
|
-
|
|
27
|
+
if (thrown instanceof Error)
|
|
28
|
+
Error.captureStackTrace(thrown, expectOrderedItems);
|
|
29
|
+
throw thrown;
|
|
27
30
|
}
|
|
28
31
|
}
|
package/util/array.d.ts
CHANGED
|
@@ -21,39 +21,36 @@ export declare function isArrayItem<T>(arr: ImmutableArray<T>, item: unknown): i
|
|
|
21
21
|
/** Assert that an unknown value is an item in a specified array. */
|
|
22
22
|
export declare function assertArrayItem<T>(arr: ImmutableArray<T>, item: unknown): asserts item is T;
|
|
23
23
|
/** Convert an iterable to an array (if its not already an array). */
|
|
24
|
-
export declare function getArray<T>(
|
|
24
|
+
export declare function getArray<T>(list: PossibleArray<T>): ImmutableArray<T>;
|
|
25
25
|
/** Add multiple items to an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
|
26
|
-
export declare function withArrayItems<T>(
|
|
26
|
+
export declare function withArrayItems<T>(list: PossibleArray<T>, ...add: T[]): ImmutableArray<T>;
|
|
27
27
|
/** Pick multiple items from an array (immutably) and return a new array without those items (or the same array if no changes were made). */
|
|
28
|
-
export declare function pickArrayItems<T>(
|
|
28
|
+
export declare function pickArrayItems<T>(items: PossibleArray<T>, ...pick: T[]): ImmutableArray<T>;
|
|
29
29
|
/** Remove multiple items from an array (immutably) and return a new array without those items (or the same array if no changes were made). */
|
|
30
|
-
export declare function omitArrayItems<T>(
|
|
30
|
+
export declare function omitArrayItems<T>(items: PossibleArray<T>, ...omit: T[]): ImmutableArray<T>;
|
|
31
31
|
/** Toggle an item in and out of an array (immutably) and return a new array with or without the specified items (or the same array if no changes were made). */
|
|
32
|
-
export declare function toggleArrayItems<T>(
|
|
33
|
-
/** Get the first item from an array or iterable, or `undefined` if it didn't exist. */
|
|
34
|
-
export declare function getOptionalFirstItem<T>(items: PossibleArray<T>): T | undefined;
|
|
35
|
-
/** Get the first item from an array or iterable. */
|
|
36
|
-
export declare function getFirstItem<T>(items: PossibleArray<T>): T;
|
|
37
|
-
/** Get the last item from an array or iterable, or `undefined` if it didn't exist. */
|
|
38
|
-
export declare function getOptionalLastItem<T>(items: PossibleArray<T>): T | undefined;
|
|
39
|
-
/** Get the last item from an array or iterable. */
|
|
40
|
-
export declare function getLastItem<T>(items: PossibleArray<T>): T;
|
|
41
|
-
/** Get the next item in an array or iterable. */
|
|
42
|
-
export declare function getOptionalNextItem<T>(items: PossibleArray<T>, value: T): T | undefined;
|
|
43
|
-
/** Get the previous item in an array or iterable. */
|
|
44
|
-
export declare function getOptionalPrevItem<T>(items: PossibleArray<T>, value: T): T | undefined;
|
|
32
|
+
export declare function toggleArrayItems<T>(items: PossibleArray<T>, ...toggle: T[]): ImmutableArray<T>;
|
|
45
33
|
/** Return a shuffled version of an array or iterable. */
|
|
46
|
-
export declare function shuffleArray<T>(
|
|
47
|
-
/**
|
|
34
|
+
export declare function shuffleArray<T>(items: PossibleArray<T>): ImmutableArray<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Add an item to an array (by reference) and return the item.
|
|
37
|
+
* - Skip items that already exist.
|
|
38
|
+
*/
|
|
48
39
|
export declare function addArrayItem<T>(arr: MutableArray<T>, item: T): T;
|
|
49
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Add multiple items to an array (by reference).
|
|
42
|
+
* - Skip items that already exist.
|
|
43
|
+
*/
|
|
50
44
|
export declare function addArrayItems<T>(arr: MutableArray<T>, ...items: T[]): void;
|
|
51
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Remove multiple items from an array (by reference).
|
|
47
|
+
* - Skip items that already exist.
|
|
48
|
+
*/
|
|
52
49
|
export declare function deleteArrayItems<T>(arr: MutableArray<T>, ...items: T[]): void;
|
|
53
50
|
/** Return an array of the unique items in an array. */
|
|
54
|
-
export declare function getUniqueArray<T>(
|
|
51
|
+
export declare function getUniqueArray<T>(list: PossibleArray<T>): ImmutableArray<T>;
|
|
55
52
|
/** Apply a limit to an array. */
|
|
56
|
-
export declare function limitArray<T>(
|
|
53
|
+
export declare function limitArray<T>(list: PossibleArray<T>, limit: number): ImmutableArray<T>;
|
|
57
54
|
/** Count the items in an array. */
|
|
58
55
|
export declare function countArray<T>(arr: ImmutableArray<T>): number;
|
|
59
56
|
/** Does an array have the specified minimum length. */
|
|
@@ -94,22 +91,22 @@ export declare function assertArrayLength<T>(arr: ImmutableArray<T>, min: 2, max
|
|
|
94
91
|
export declare function assertArrayLength<T>(arr: ImmutableArray<T>, min: 3, max?: number): asserts arr is readonly [T, T, T, ...T[]];
|
|
95
92
|
export declare function assertArrayLength<T>(arr: ImmutableArray<T>, min: 4, max?: number): asserts arr is readonly [T, T, T, T, ...T[]];
|
|
96
93
|
export declare function assertArrayLength<T>(arr: ImmutableArray<T>, min: number, max?: number): asserts arr is ImmutableArray<T>;
|
|
97
|
-
/**
|
|
98
|
-
export declare function
|
|
99
|
-
export declare function
|
|
100
|
-
export declare function
|
|
101
|
-
export declare function
|
|
102
|
-
export declare function
|
|
103
|
-
export declare function
|
|
104
|
-
export declare function
|
|
105
|
-
export declare function
|
|
106
|
-
export declare function
|
|
107
|
-
export declare function
|
|
108
|
-
export declare function
|
|
109
|
-
export declare function
|
|
110
|
-
export declare function
|
|
111
|
-
export declare function
|
|
112
|
-
export declare function
|
|
113
|
-
export declare function
|
|
114
|
-
export declare function
|
|
115
|
-
export declare function
|
|
94
|
+
/** Require that an array if has the specified minimum length, or throw `RequiredError` if is not. */
|
|
95
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 1, max: 1): [T];
|
|
96
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 2, max: 2): [T, T];
|
|
97
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 3, max: 3): [T, T, T];
|
|
98
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 4, max: 4): [T, T, T, T];
|
|
99
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min?: 1, max?: number): [T, ...T[]];
|
|
100
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 2, max?: number): [T, T, ...T[]];
|
|
101
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 3, max?: number): [T, T, T, ...T[]];
|
|
102
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min: 4, max?: number): [T, T, T, T, ...T[]];
|
|
103
|
+
export declare function requireArrayLength<T>(arr: MutableArray<T>, min?: number, max?: number): MutableArray<T>;
|
|
104
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 1, max: 1): readonly [T];
|
|
105
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 2, max: 2): readonly [T, T];
|
|
106
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 3, max: 3): readonly [T, T, T];
|
|
107
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 4, max: 4): readonly [T, T, T, T];
|
|
108
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min?: 1, max?: number): readonly [T, ...T[]];
|
|
109
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 2, max?: number): readonly [T, T, ...T[]];
|
|
110
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 3, max?: number): readonly [T, T, T, ...T[]];
|
|
111
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min: 4, max?: number): readonly [T, T, T, T, ...T[]];
|
|
112
|
+
export declare function requireArrayLength<T>(arr: ImmutableArray<T>, min?: number, max?: number): ImmutableArray<T>;
|