shelving 1.86.0 → 1.86.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/api/Resource.d.ts +2 -2
- package/constraint/Constraints.js +7 -6
- package/constraint/FilterConstraint.d.ts +4 -4
- package/constraint/FilterConstraint.js +17 -17
- package/constraint/QueryConstraints.d.ts +1 -1
- package/constraint/QueryConstraints.js +8 -8
- package/constraint/SortConstraint.d.ts +4 -4
- package/constraint/SortConstraint.js +3 -3
- package/db/Change.d.ts +4 -4
- package/db/Item.d.ts +4 -4
- package/error/ThroughError.js +1 -1
- package/markup/index.d.ts +1 -0
- package/markup/index.js +1 -0
- package/markup/options.d.ts +2 -2
- package/markup/regexp.d.ts +2 -2
- package/markup/render.js +19 -20
- package/markup/rule.d.ts +80 -0
- package/markup/rule.js +63 -0
- package/markup/rules.d.ts +17 -67
- package/markup/rules.js +88 -160
- package/package.json +17 -17
- package/react/useItem.js +10 -10
- package/react/useQuery.js +29 -29
- package/schema/AllowSchema.d.ts +4 -4
- package/schema/AllowSchema.js +3 -3
- package/schema/ArraySchema.d.ts +1 -1
- package/schema/BooleanSchema.d.ts +1 -1
- package/schema/DataSchema.d.ts +2 -2
- package/schema/DateSchema.d.ts +1 -1
- package/schema/DictionarySchema.d.ts +1 -1
- package/schema/LinkSchema.d.ts +1 -1
- package/schema/NumberSchema.d.ts +1 -1
- package/schema/NumberSchema.js +4 -4
- package/schema/Schema.d.ts +1 -1
- package/schema/StringSchema.d.ts +3 -3
- package/schema/ThroughSchema.d.ts +1 -1
- package/schema/TimeSchema.d.ts +1 -1
- package/state/State.d.ts +1 -1
- package/state/State.js +6 -6
- package/test/basics.d.ts +2 -2
- package/test/index.d.ts +1 -1
- package/test/people.d.ts +2 -2
- package/update/ArrayUpdate.d.ts +2 -1
- package/update/ArrayUpdate.js +9 -8
- package/update/DataUpdate.d.ts +1 -1
- package/update/DataUpdate.js +7 -6
- package/update/DictionaryUpdate.d.ts +1 -1
- package/update/DictionaryUpdate.js +8 -7
- package/util/array.d.ts +4 -4
- package/util/async.js +8 -8
- package/util/class.d.ts +3 -3
- package/util/clone.js +4 -3
- package/util/color.d.ts +2 -2
- package/util/color.js +6 -6
- package/util/data.d.ts +7 -14
- package/util/data.js +1 -19
- package/util/date.d.ts +3 -3
- package/util/debug.d.ts +1 -0
- package/util/debug.js +5 -5
- package/util/dictionary.d.ts +5 -5
- package/util/duration.d.ts +17 -0
- package/util/duration.js +52 -0
- package/util/entry.d.ts +3 -3
- package/util/equal.js +6 -3
- package/util/function.d.ts +8 -8
- package/util/hydrate.d.ts +3 -3
- package/util/hydrate.js +2 -2
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/iterate.d.ts +1 -1
- package/util/jsx.d.ts +3 -3
- package/util/lazy.d.ts +1 -1
- package/util/map.d.ts +15 -19
- package/util/map.js +11 -13
- package/util/match.d.ts +2 -2
- package/util/merge.d.ts +1 -1
- package/util/null.d.ts +1 -1
- package/util/number.d.ts +4 -2
- package/util/number.js +8 -6
- package/util/object.d.ts +24 -11
- package/util/object.js +30 -4
- package/util/regexp.d.ts +2 -3
- package/util/serialise.js +2 -2
- package/util/set.d.ts +4 -4
- package/util/sort.d.ts +2 -2
- package/util/source.js +2 -2
- package/util/string.d.ts +1 -1
- package/util/string.js +3 -3
- package/util/template.d.ts +2 -2
- package/util/template.js +9 -9
- package/util/time.d.ts +2 -2
- package/util/time.js +3 -3
- package/util/transform.d.ts +5 -5
- package/util/units.d.ts +39 -50
- package/util/units.js +36 -74
- package/util/url.d.ts +2 -2
- package/util/validate.d.ts +5 -5
package/schema/AllowSchema.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { Entry } from "../util/entry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ImmutableMap, PossibleMap, PossibleStringMap } from "../util/map.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `AllowSchama` */
|
|
5
|
-
export
|
|
5
|
+
export type AllowSchemaOptions<K, T> = Omit<SchemaOptions, "value"> & {
|
|
6
6
|
allow: PossibleMap<K, T>;
|
|
7
7
|
};
|
|
8
8
|
/** Define a valid value from an allowed set of values. */
|
|
9
9
|
export declare class AllowSchema<K, T> extends Schema<K> implements Iterable<Entry<K, T>> {
|
|
10
10
|
readonly value: K;
|
|
11
|
-
readonly allow:
|
|
11
|
+
readonly allow: ImmutableMap<K, T>;
|
|
12
12
|
constructor({ allow, ...options }: AllowSchemaOptions<K, T>);
|
|
13
13
|
validate(value?: unknown): K;
|
|
14
14
|
/** Iterate over the the allowed options in `[key, value]` format. */
|
|
15
15
|
[Symbol.iterator](): Iterator<Entry<K, T>>;
|
|
16
16
|
}
|
|
17
17
|
/** Allowed options for `AllowStringSchama` */
|
|
18
|
-
export
|
|
18
|
+
export type AllowStringSchemaOptions<K extends string, T> = Omit<SchemaOptions, "value"> & {
|
|
19
19
|
allow: PossibleStringMap<K, T>;
|
|
20
20
|
};
|
|
21
21
|
/** Define a valid string value from an allowed set of string values. */
|
package/schema/AllowSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getString } from "../util/string.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getMap, isMapKey } from "../util/map.js";
|
|
3
3
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
4
4
|
import { getFirstItem } from "../util/array.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
@@ -7,7 +7,7 @@ import { Schema } from "./Schema.js";
|
|
|
7
7
|
export class AllowSchema extends Schema {
|
|
8
8
|
constructor({ allow, ...options }) {
|
|
9
9
|
super(options);
|
|
10
|
-
this.allow =
|
|
10
|
+
this.allow = getMap(allow);
|
|
11
11
|
this.value = getFirstItem(this.allow.keys());
|
|
12
12
|
}
|
|
13
13
|
validate(value = this.value) {
|
|
@@ -23,7 +23,7 @@ export class AllowSchema extends Schema {
|
|
|
23
23
|
/** Define a valid string value from an allowed set of string values. */
|
|
24
24
|
export class AllowStringSchema extends AllowSchema {
|
|
25
25
|
constructor({ allow, ...options }) {
|
|
26
|
-
super({ allow:
|
|
26
|
+
super({ allow: getMap(allow), ...options });
|
|
27
27
|
}
|
|
28
28
|
validator(value = this.value) {
|
|
29
29
|
return super.validate(getString(value));
|
package/schema/ArraySchema.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ImmutableArray } from "../util/array.js";
|
|
|
2
2
|
import { Validator } from "../util/validate.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `ArraySchema` */
|
|
5
|
-
export
|
|
5
|
+
export type ArraySchemaOptions<T> = SchemaOptions & {
|
|
6
6
|
readonly value?: ImmutableArray;
|
|
7
7
|
readonly items: Validator<T>;
|
|
8
8
|
readonly min?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Allowed options for `BooleanSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type BooleanSchemaOptions = SchemaOptions & {
|
|
4
4
|
readonly value?: boolean;
|
|
5
5
|
};
|
|
6
6
|
/** Define a valid boolean. */
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Validators } from "../util/validate.js";
|
|
|
3
3
|
import { OptionalSchema } from "./OptionalSchema.js";
|
|
4
4
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
5
5
|
/** Allowed options for `DataSchema` */
|
|
6
|
-
export
|
|
6
|
+
export type DataSchemaOptions<T extends Data> = SchemaOptions & {
|
|
7
7
|
readonly props: Validators<T>;
|
|
8
8
|
readonly value?: Partial<T>;
|
|
9
9
|
};
|
|
@@ -15,7 +15,7 @@ export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
|
15
15
|
validate(unsafeValue?: unknown): T;
|
|
16
16
|
}
|
|
17
17
|
/** Set of named data schemas. */
|
|
18
|
-
export
|
|
18
|
+
export type DataSchemas<T extends Datas> = {
|
|
19
19
|
[K in keyof T]: DataSchema<T[K]>;
|
|
20
20
|
};
|
|
21
21
|
/** Valid data object with specifed properties. */
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PossibleDate } from "../util/date.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `DateSchema` */
|
|
4
|
-
export
|
|
4
|
+
export type DateSchemaOptions = SchemaOptions & {
|
|
5
5
|
readonly value?: PossibleDate;
|
|
6
6
|
readonly min?: PossibleDate | null;
|
|
7
7
|
readonly max?: PossibleDate | null;
|
|
@@ -2,7 +2,7 @@ import { ImmutableDictionary } from "../util/dictionary.js";
|
|
|
2
2
|
import { Validator } from "../util/validate.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `DictionarySchema` */
|
|
5
|
-
export
|
|
5
|
+
export type DictionarySchemaOptions<T> = SchemaOptions & {
|
|
6
6
|
readonly items: Validator<T>;
|
|
7
7
|
readonly value?: ImmutableDictionary;
|
|
8
8
|
readonly min?: number | null;
|
package/schema/LinkSchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringSchema, StringSchemaOptions } from "./StringSchema.js";
|
|
2
2
|
/** Allowed options for `LinkSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type LinkSchemaOptions = StringSchemaOptions & {
|
|
4
4
|
readonly schemes?: string[];
|
|
5
5
|
readonly hosts?: string[] | null;
|
|
6
6
|
};
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Allowed options for `NumberSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type NumberSchemaOptions = SchemaOptions & {
|
|
4
4
|
readonly value?: number | null;
|
|
5
5
|
readonly min?: number | null;
|
|
6
6
|
readonly max?: number | null;
|
package/schema/NumberSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getOptionalNumber, roundStep } from "../util/number.js";
|
|
1
|
+
import { formatNumber, getOptionalNumber, roundStep } from "../util/number.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
@@ -17,9 +17,9 @@ export class NumberSchema extends Schema {
|
|
|
17
17
|
throw new InvalidFeedback("Must be number", { value: unsafeValue });
|
|
18
18
|
const safeNumber = typeof this.step === "number" ? roundStep(unsafeNumber, this.step) : unsafeNumber;
|
|
19
19
|
if (typeof this.max === "number" && safeNumber > this.max)
|
|
20
|
-
throw new InvalidFeedback(`Maximum ${this.max}`, { value: safeNumber });
|
|
20
|
+
throw new InvalidFeedback(`Maximum ${formatNumber(this.max)}`, { value: safeNumber });
|
|
21
21
|
if (typeof this.min === "number" && safeNumber < this.min)
|
|
22
|
-
throw new InvalidFeedback(`Minimum ${this.min}`, { value: safeNumber });
|
|
22
|
+
throw new InvalidFeedback(`Minimum ${formatNumber(this.min)}`, { value: safeNumber });
|
|
23
23
|
return safeNumber;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -28,6 +28,6 @@ export const NUMBER = new NumberSchema({});
|
|
|
28
28
|
/** Valid number, e.g. `2048.12345` or `0` zero, or `null` */
|
|
29
29
|
export const OPTIONAL_NUMBER = OPTIONAL(NUMBER);
|
|
30
30
|
/** Valid integer number, e.g. `2048` or `0` zero. */
|
|
31
|
-
export const INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: Number.
|
|
31
|
+
export const INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER });
|
|
32
32
|
/** Valid integer number, e.g. `2048` or `0` zero, or `null` */
|
|
33
33
|
export const OPTIONAL_INTEGER = OPTIONAL(INTEGER);
|
package/schema/Schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Validatable } from "../util/validate.js";
|
|
2
2
|
/** Options allowed by a `Schema` instance. */
|
|
3
|
-
export
|
|
3
|
+
export type SchemaOptions = {
|
|
4
4
|
/** Title of the schema, e.g. for using as the title of a corresponding field. */
|
|
5
5
|
readonly title?: string | null;
|
|
6
6
|
/** Description of the schema, e.g. for using as a description in a corresponding field. */
|
package/schema/StringSchema.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** `type=""` prop for HTML `<input />` tags that are relevant for strings. */
|
|
3
|
-
export
|
|
3
|
+
export type HtmlInputType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url";
|
|
4
4
|
/** Function that sanitizes a string. */
|
|
5
|
-
export
|
|
5
|
+
export type Sanitizer = (str: string) => string;
|
|
6
6
|
/** Options for `StringSchema` */
|
|
7
|
-
export
|
|
7
|
+
export type StringSchemaOptions = SchemaOptions & {
|
|
8
8
|
readonly value?: string;
|
|
9
9
|
readonly type?: HtmlInputType;
|
|
10
10
|
readonly min?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Sourceable } from "../util/source.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `ThroughSchama` */
|
|
4
|
-
export
|
|
4
|
+
export type ThroughSchemaOptions<T> = SchemaOptions & {
|
|
5
5
|
source: Schema<T>;
|
|
6
6
|
};
|
|
7
7
|
/** Schema that passes through to a source schema. */
|
package/schema/TimeSchema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PossibleTime, Time } from "../util/time.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `TimeSchama` */
|
|
4
|
-
export
|
|
4
|
+
export type TimeSchemaOptions = SchemaOptions & {
|
|
5
5
|
readonly value?: PossibleTime;
|
|
6
6
|
readonly min?: PossibleTime | null;
|
|
7
7
|
readonly max?: PossibleTime | null;
|
package/state/State.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch, Handler, Stop } from "../util/function.js";
|
|
2
2
|
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
3
3
|
/** Any `State` instance. */
|
|
4
|
-
export
|
|
4
|
+
export type AnyState = State<any>;
|
|
5
5
|
/**
|
|
6
6
|
* Stream that retains its most recent value
|
|
7
7
|
* - Current value can be read at `state.value` and `state.data`
|
package/state/State.js
CHANGED
|
@@ -11,12 +11,6 @@ import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
|
11
11
|
* - To set the state to an explicit value, use that value or another `State` instance with a value.
|
|
12
12
|
* */
|
|
13
13
|
export class State {
|
|
14
|
-
/** State is initiated with an initial state. */
|
|
15
|
-
constructor(initial = State.NOVALUE, next = new DeferredSequence()) {
|
|
16
|
-
this._value = initial;
|
|
17
|
-
this._time = initial !== State.NOVALUE ? Date.now() : null;
|
|
18
|
-
this.next = next;
|
|
19
|
-
}
|
|
20
14
|
/** Most recently dispatched value (or throw `Promise` that resolves to the next value). */
|
|
21
15
|
get value() {
|
|
22
16
|
if (this._value === State.NOVALUE)
|
|
@@ -32,6 +26,12 @@ export class State {
|
|
|
32
26
|
const time = this.time;
|
|
33
27
|
return time !== null ? Date.now() - time : Infinity;
|
|
34
28
|
}
|
|
29
|
+
/** State is initiated with an initial state. */
|
|
30
|
+
constructor(initial = State.NOVALUE, next = new DeferredSequence()) {
|
|
31
|
+
this._value = initial;
|
|
32
|
+
this._time = initial !== State.NOVALUE ? Date.now() : null;
|
|
33
|
+
this.next = next;
|
|
34
|
+
}
|
|
35
35
|
/** Is there a current value, or is it still loading. */
|
|
36
36
|
get loading() {
|
|
37
37
|
return this._value === State.NOVALUE;
|
package/test/basics.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare const BASIC_SCHEMA: import("../schema/DataSchema.js").DataSchema<
|
|
|
6
6
|
group: "a" | "b" | "c";
|
|
7
7
|
tags: import("../index.js").ImmutableArray<string>;
|
|
8
8
|
}>;
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type BasicData = ValidatorType<typeof BASIC_SCHEMA>;
|
|
10
|
+
export type BasicItemData = ItemData<BasicData>;
|
|
11
11
|
export declare const basic1: BasicItemData;
|
|
12
12
|
export declare const basic2: BasicItemData;
|
|
13
13
|
export declare const basic3: BasicItemData;
|
package/test/index.d.ts
CHANGED
package/test/people.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare const PERSON_SCHEMA: import("../schema/DataSchema.js").DataSchema
|
|
|
7
7
|
};
|
|
8
8
|
birthday: string | null;
|
|
9
9
|
}>;
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type PersonData = ValidatorType<typeof PERSON_SCHEMA>;
|
|
11
|
+
export type PersonItemData = ItemData<PersonData>;
|
|
12
12
|
export declare const person1: PersonItemData;
|
|
13
13
|
export declare const person2: PersonItemData;
|
|
14
14
|
export declare const person3: PersonItemData;
|
package/update/ArrayUpdate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ArraySchema } from "../schema/ArraySchema.js";
|
|
1
2
|
import { ImmutableArray } from "../util/array.js";
|
|
2
3
|
import { Validator } from "../util/validate.js";
|
|
3
4
|
import { Update } from "./Update.js";
|
|
@@ -15,5 +16,5 @@ export declare class ArrayUpdate<T> extends Update<ImmutableArray<T>> {
|
|
|
15
16
|
/** Return an array update with an additional item marked for deletion. */
|
|
16
17
|
delete(...deletes: T[]): this;
|
|
17
18
|
transform(arr?: ImmutableArray<T>): ImmutableArray<T>;
|
|
18
|
-
validate(validator: Validator<ImmutableArray<T>>): this;
|
|
19
|
+
validate(validator: ArraySchema<T> | Validator<ImmutableArray<T>>): this;
|
|
19
20
|
}
|
package/update/ArrayUpdate.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { ArraySchema } from "../schema/ArraySchema.js";
|
|
2
2
|
import { withArrayItems, omitArrayItems } from "../util/array.js";
|
|
3
|
+
import { getPrototype } from "../util/object.js";
|
|
3
4
|
import { validateArray } from "../util/validate.js";
|
|
4
5
|
import { Update } from "./Update.js";
|
|
5
6
|
/** Update that can be applied to an array to add/remove items. */
|
|
6
7
|
export class ArrayUpdate extends Update {
|
|
7
|
-
constructor(adds = [], deletes = []) {
|
|
8
|
-
super();
|
|
9
|
-
this.adds = adds;
|
|
10
|
-
this.deletes = deletes;
|
|
11
|
-
}
|
|
12
8
|
/** Return an array update with an item marked for addition. */
|
|
13
9
|
static add(...adds) {
|
|
14
10
|
return new ArrayUpdate(adds);
|
|
@@ -17,10 +13,15 @@ export class ArrayUpdate extends Update {
|
|
|
17
13
|
static delete(...deletes) {
|
|
18
14
|
return new ArrayUpdate([], deletes);
|
|
19
15
|
}
|
|
16
|
+
constructor(adds = [], deletes = []) {
|
|
17
|
+
super();
|
|
18
|
+
this.adds = adds;
|
|
19
|
+
this.deletes = deletes;
|
|
20
|
+
}
|
|
20
21
|
/** Return an array update with an additional item marked for addition. */
|
|
21
22
|
add(...adds) {
|
|
22
23
|
return {
|
|
23
|
-
__proto__:
|
|
24
|
+
__proto__: getPrototype(this),
|
|
24
25
|
...this,
|
|
25
26
|
adds: [...this.adds, ...adds],
|
|
26
27
|
};
|
|
@@ -28,7 +29,7 @@ export class ArrayUpdate extends Update {
|
|
|
28
29
|
/** Return an array update with an additional item marked for deletion. */
|
|
29
30
|
delete(...deletes) {
|
|
30
31
|
return {
|
|
31
|
-
__proto__:
|
|
32
|
+
__proto__: getPrototype(this),
|
|
32
33
|
...this,
|
|
33
34
|
deletes: [...this.deletes, ...deletes],
|
|
34
35
|
};
|
|
@@ -42,7 +43,7 @@ export class ArrayUpdate extends Update {
|
|
|
42
43
|
if (!(validator instanceof ArraySchema))
|
|
43
44
|
return super.validate(validator);
|
|
44
45
|
return {
|
|
45
|
-
__proto__:
|
|
46
|
+
__proto__: getPrototype(this),
|
|
46
47
|
...this,
|
|
47
48
|
adds: validateArray(this.adds, validator.items),
|
|
48
49
|
deletes: validateArray(this.deletes, validator.items),
|
package/update/DataUpdate.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Update } from "./Update.js";
|
|
|
9
9
|
* - If a prop contains a new value, the prop is set to that new value.
|
|
10
10
|
* - If a prop contains an `Update` instance, the existing value is updated.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type Updates<T extends Data = Data> = {
|
|
13
13
|
readonly [K in keyof T]?: T[K] | Update<T[K]> | undefined;
|
|
14
14
|
};
|
|
15
15
|
/**
|
package/update/DataUpdate.js
CHANGED
|
@@ -3,6 +3,7 @@ import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
|
3
3
|
import { DataSchema } from "../schema/DataSchema.js";
|
|
4
4
|
import { getDataProps } from "../util/data.js";
|
|
5
5
|
import { isNullish } from "../util/null.js";
|
|
6
|
+
import { getPrototype } from "../util/object.js";
|
|
6
7
|
import { transformObject } from "../util/transform.js";
|
|
7
8
|
import { validate } from "../util/validate.js";
|
|
8
9
|
import { Update } from "./Update.js";
|
|
@@ -36,20 +37,20 @@ export const updateData = transformObject;
|
|
|
36
37
|
* Update that can be applied to a data object to update its props.
|
|
37
38
|
*/
|
|
38
39
|
export class DataUpdate extends Update {
|
|
39
|
-
constructor(props) {
|
|
40
|
-
super();
|
|
41
|
-
this.updates = props;
|
|
42
|
-
}
|
|
43
40
|
/** Return a data update with a specific prop marked for update. */
|
|
44
41
|
static update(key, value) {
|
|
45
42
|
return new DataUpdate(!isNullish(key) ? { [key]: value } : {});
|
|
46
43
|
}
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super();
|
|
46
|
+
this.updates = props;
|
|
47
|
+
}
|
|
47
48
|
/** Return a data update with a specific prop marked for update. */
|
|
48
49
|
update(key, value) {
|
|
49
50
|
if (isNullish(key))
|
|
50
51
|
return this;
|
|
51
52
|
return {
|
|
52
|
-
__proto__:
|
|
53
|
+
__proto__: getPrototype(this),
|
|
53
54
|
...this,
|
|
54
55
|
updates: { ...this.updates, [key]: value },
|
|
55
56
|
};
|
|
@@ -63,7 +64,7 @@ export class DataUpdate extends Update {
|
|
|
63
64
|
if (!(validator instanceof DataSchema))
|
|
64
65
|
return super.validate(validator);
|
|
65
66
|
return {
|
|
66
|
-
__proto__:
|
|
67
|
+
__proto__: getPrototype(this),
|
|
67
68
|
...this,
|
|
68
69
|
updates: validateUpdates(this.updates, validator.props),
|
|
69
70
|
};
|
|
@@ -5,7 +5,7 @@ import { Validator } from "../util/validate.js";
|
|
|
5
5
|
import { Update } from "./Update.js";
|
|
6
6
|
import { Delete } from "./Delete.js";
|
|
7
7
|
/** Set of named transforms for the entries of a dictionary object. */
|
|
8
|
-
export
|
|
8
|
+
export type DictionaryUpdates<T> = ImmutableDictionary<T | Update<T> | Delete>;
|
|
9
9
|
/** Update that can be applied to a dictionary object to add/remove/update its entries. */
|
|
10
10
|
export declare class DictionaryUpdate<T> extends Update<ImmutableDictionary<T>> implements Iterable<Entry<string, T | Update<T> | Delete>> {
|
|
11
11
|
/** Return a dictionary update with a specific entry marked for update. */
|
|
@@ -4,14 +4,11 @@ import { DictionarySchema } from "../schema/DictionarySchema.js";
|
|
|
4
4
|
import { validate } from "../util/validate.js";
|
|
5
5
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
6
6
|
import { isFeedback } from "../feedback/Feedback.js";
|
|
7
|
+
import { getPrototype } from "../util/object.js";
|
|
7
8
|
import { Update } from "./Update.js";
|
|
8
9
|
import { Delete, DELETE } from "./Delete.js";
|
|
9
10
|
/** Update that can be applied to a dictionary object to add/remove/update its entries. */
|
|
10
11
|
export class DictionaryUpdate extends Update {
|
|
11
|
-
constructor(updates = {}) {
|
|
12
|
-
super();
|
|
13
|
-
this.updates = updates;
|
|
14
|
-
}
|
|
15
12
|
/** Return a dictionary update with a specific entry marked for update. */
|
|
16
13
|
static update(key, value) {
|
|
17
14
|
return new DictionaryUpdate(isNullish(key) ? {} : { [key]: value });
|
|
@@ -20,12 +17,16 @@ export class DictionaryUpdate extends Update {
|
|
|
20
17
|
static delete(key) {
|
|
21
18
|
return new DictionaryUpdate(isNullish(key) ? {} : { [key]: DELETE });
|
|
22
19
|
}
|
|
20
|
+
constructor(updates = {}) {
|
|
21
|
+
super();
|
|
22
|
+
this.updates = updates;
|
|
23
|
+
}
|
|
23
24
|
/** Return a dictionary update with a specific entry marked for update. */
|
|
24
25
|
update(key, value) {
|
|
25
26
|
if (isNullish(key))
|
|
26
27
|
return this;
|
|
27
28
|
return {
|
|
28
|
-
__proto__:
|
|
29
|
+
__proto__: getPrototype(this),
|
|
29
30
|
...this,
|
|
30
31
|
updates: { ...this.updates, [key]: value },
|
|
31
32
|
};
|
|
@@ -35,7 +36,7 @@ export class DictionaryUpdate extends Update {
|
|
|
35
36
|
if (isNullish(key))
|
|
36
37
|
return this;
|
|
37
38
|
return {
|
|
38
|
-
__proto__:
|
|
39
|
+
__proto__: getPrototype(this),
|
|
39
40
|
...this,
|
|
40
41
|
updates: { ...this.updates, [key]: DELETE },
|
|
41
42
|
};
|
|
@@ -49,7 +50,7 @@ export class DictionaryUpdate extends Update {
|
|
|
49
50
|
if (!(validator instanceof DictionarySchema))
|
|
50
51
|
return super.validate(validator);
|
|
51
52
|
return {
|
|
52
|
-
__proto__:
|
|
53
|
+
__proto__: getPrototype(this),
|
|
53
54
|
...this,
|
|
54
55
|
updates: Object.fromEntries(_validateDictionaryUpdates(this.updates, validator.items)),
|
|
55
56
|
};
|
package/util/array.d.ts
CHANGED
|
@@ -4,16 +4,16 @@ import { Matcher } from "./match.js";
|
|
|
4
4
|
* Mutable array: an array that can be changed.
|
|
5
5
|
* - Consistency with `MutableObject<T>` and `ImmutableArray<T>`
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type MutableArray<T = unknown> = T[];
|
|
8
8
|
/**
|
|
9
9
|
* Immutable array: an array that cannot be changed.
|
|
10
10
|
* - Consistency with `ImmutableObject<T>` and `MutableArray<T>`
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type ImmutableArray<T = unknown> = readonly T[];
|
|
13
13
|
/** Get the type of the _items_ in an array. */
|
|
14
|
-
export
|
|
14
|
+
export type ArrayItem<T extends ImmutableArray> = T[number];
|
|
15
15
|
/** Things that can be converted to arrays. */
|
|
16
|
-
export
|
|
16
|
+
export type PossibleArray<T> = ImmutableArray<T> | Iterable<T>;
|
|
17
17
|
/** Is an unknown value an array? */
|
|
18
18
|
export declare const isArray: <T extends ImmutableArray<unknown>>(v: unknown) => v is T;
|
|
19
19
|
/** Assert that a value is an array. */
|
package/util/async.js
CHANGED
|
@@ -36,6 +36,11 @@ export function runMicrotasks() {
|
|
|
36
36
|
}
|
|
37
37
|
/** Type of `Promise` with `._resolve()` and `._reject()` methods available. */
|
|
38
38
|
export class AbstractPromise extends Promise {
|
|
39
|
+
// Make `this.then()` create a `Promise` not a `Deferred`
|
|
40
|
+
// Done with a getter because some implementations implement this with a getter and we need to override it.
|
|
41
|
+
static get [Symbol.species]() {
|
|
42
|
+
return Promise;
|
|
43
|
+
}
|
|
39
44
|
constructor() {
|
|
40
45
|
let _resolve;
|
|
41
46
|
let _reject;
|
|
@@ -46,14 +51,14 @@ export class AbstractPromise extends Promise {
|
|
|
46
51
|
this._resolve = _resolve; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
47
52
|
this._reject = _reject; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
48
53
|
}
|
|
54
|
+
}
|
|
55
|
+
/** Type of `Promise` with its `resolve()` and `reject()` methods exposed publicly. */
|
|
56
|
+
export class Deferred extends Promise {
|
|
49
57
|
// Make `this.then()` create a `Promise` not a `Deferred`
|
|
50
58
|
// Done with a getter because some implementations implement this with a getter and we need to override it.
|
|
51
59
|
static get [Symbol.species]() {
|
|
52
60
|
return Promise;
|
|
53
61
|
}
|
|
54
|
-
}
|
|
55
|
-
/** Type of `Promise` with its `resolve()` and `reject()` methods exposed publicly. */
|
|
56
|
-
export class Deferred extends Promise {
|
|
57
62
|
constructor() {
|
|
58
63
|
let resolve;
|
|
59
64
|
let reject;
|
|
@@ -64,11 +69,6 @@ export class Deferred extends Promise {
|
|
|
64
69
|
this.resolve = resolve; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
65
70
|
this.reject = reject; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
66
71
|
}
|
|
67
|
-
// Make `this.then()` create a `Promise` not a `Deferred`
|
|
68
|
-
// Done with a getter because some implementations implement this with a getter and we need to override it.
|
|
69
|
-
static get [Symbol.species]() {
|
|
70
|
-
return Promise;
|
|
71
|
-
}
|
|
72
72
|
}
|
|
73
73
|
/** Promise that resolves after a specified delay in milliseconds. */
|
|
74
74
|
export class Delay extends AbstractPromise {
|
package/util/class.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Arguments } from "./function.js";
|
|
2
2
|
/** Class that has a public `constructor()` function. */
|
|
3
|
-
export
|
|
3
|
+
export type Constructor<T, A extends Arguments> = new (...args: A) => T;
|
|
4
4
|
/** Any function arguments (designed for use with `extends Arguments` guards). */
|
|
5
|
-
export
|
|
5
|
+
export type AnyConstructor = new (...args: any) => any;
|
|
6
6
|
/** Class prototype that can be used with `instanceof` (string name, as per `Function`, and a prototype field matching the object). */
|
|
7
|
-
export
|
|
7
|
+
export type Class<T = unknown> = Omit<Function, "prototype"> & {
|
|
8
8
|
prototype: T;
|
|
9
9
|
};
|
|
10
10
|
/** Is a given value a class constructor? */
|
package/util/clone.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isArray } from "./array.js";
|
|
2
2
|
import { isData } from "./data.js";
|
|
3
3
|
import { mapArray, mapObject } from "./transform.js";
|
|
4
|
+
import { getPrototype } from "./object.js";
|
|
4
5
|
/** Does an object implement `Cloneable` */
|
|
5
|
-
export const isCloneable = (v) => isData(v) && typeof v.
|
|
6
|
+
export const isCloneable = (v) => isData(v) && typeof v.clone === "function";
|
|
6
7
|
/** Shallow clone a value. */
|
|
7
8
|
export const shallowClone = (value) => value;
|
|
8
9
|
/** Deep clone a value. */
|
|
@@ -20,7 +21,7 @@ export function cloneArray(input, recursor = shallowClone) {
|
|
|
20
21
|
if (isCloneable(input))
|
|
21
22
|
return input.clone();
|
|
22
23
|
const output = mapArray(input, recursor);
|
|
23
|
-
Object.setPrototypeOf(output,
|
|
24
|
+
Object.setPrototypeOf(output, getPrototype(input));
|
|
24
25
|
return output;
|
|
25
26
|
}
|
|
26
27
|
/** Clone an object. */
|
|
@@ -28,6 +29,6 @@ export function cloneObject(input, recursor = shallowClone) {
|
|
|
28
29
|
if (isCloneable(input))
|
|
29
30
|
return input.clone();
|
|
30
31
|
const output = mapObject(input, recursor);
|
|
31
|
-
Object.setPrototypeOf(input,
|
|
32
|
+
Object.setPrototypeOf(input, getPrototype(input));
|
|
32
33
|
return output;
|
|
33
34
|
}
|
package/util/color.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const HEX3_REGEXP: RegExp;
|
|
2
2
|
export declare const HEX6_REGEXP: RegExp;
|
|
3
3
|
/** Things that can be converted to a `Color` instance. */
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type PossibleColor = Color | string;
|
|
5
|
+
export type PossibleOptionalColor = PossibleColor | null;
|
|
6
6
|
/** Represent a color. */
|
|
7
7
|
export declare class Color {
|
|
8
8
|
/** Make a `Color` from a 3 or 6 or 8 byte hex string. */
|
package/util/color.js
CHANGED
|
@@ -7,12 +7,6 @@ export const HEX3_REGEXP = /^#?([0-F])([0-F])([0-F])$/i;
|
|
|
7
7
|
export const HEX6_REGEXP = /^#?([0-F]{2})([0-F]{2})([0-F]{2})([0-F]{2})?$/i;
|
|
8
8
|
/** Represent a color. */
|
|
9
9
|
export class Color {
|
|
10
|
-
constructor(r = 255, g = 255, b = 255, a = 255) {
|
|
11
|
-
this.r = boundNumber(r, 0, 255);
|
|
12
|
-
this.g = boundNumber(g, 0, 255);
|
|
13
|
-
this.b = boundNumber(b, 0, 255);
|
|
14
|
-
this.a = boundNumber(a, 0, 255);
|
|
15
|
-
}
|
|
16
10
|
/** Make a `Color` from a 3 or 6 or 8 byte hex string. */
|
|
17
11
|
static fromHex(str) {
|
|
18
12
|
const matches = (str.match(HEX3_REGEXP) || str.match(HEX6_REGEXP));
|
|
@@ -21,6 +15,12 @@ export class Color {
|
|
|
21
15
|
const [, r, g, b, a] = matches;
|
|
22
16
|
return new Color(_parse(r), _parse(g), _parse(b), typeof a === "string" ? _parse(a) : undefined);
|
|
23
17
|
}
|
|
18
|
+
constructor(r = 255, g = 255, b = 255, a = 255) {
|
|
19
|
+
this.r = boundNumber(r, 0, 255);
|
|
20
|
+
this.g = boundNumber(g, 0, 255);
|
|
21
|
+
this.b = boundNumber(b, 0, 255);
|
|
22
|
+
this.a = boundNumber(a, 0, 255);
|
|
23
|
+
}
|
|
24
24
|
/** Convert this color to a six or eight digit hex color. */
|
|
25
25
|
get hex() {
|
|
26
26
|
return `#${_hex(this.r)}${_hex(this.g)}${_hex(this.b)}${this.a < 255 ? _hex(this.a) : ""}`;
|
package/util/data.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ImmutableArray } from "./array.js";
|
|
2
2
|
/** Data object. */
|
|
3
|
-
export
|
|
3
|
+
export type Data = {
|
|
4
4
|
readonly [K in string]: unknown;
|
|
5
5
|
};
|
|
6
6
|
/** Prop for a data object. */
|
|
7
|
-
export
|
|
7
|
+
export type DataProp<T extends Data> = readonly [keyof T & string, T[keyof T & string]];
|
|
8
8
|
/** Key for a data object prop. */
|
|
9
|
-
export
|
|
9
|
+
export type DataKey<T extends Data> = keyof T & string;
|
|
10
10
|
/** Value for a data object prop. */
|
|
11
|
-
export
|
|
11
|
+
export type DataValue<T extends Data> = T[keyof T & string];
|
|
12
12
|
/** Data or `null` to indicate the data doesn't exist. */
|
|
13
|
-
export
|
|
13
|
+
export type OptionalData<T extends Data> = T | null;
|
|
14
14
|
/** Set of named data objects. */
|
|
15
|
-
export
|
|
15
|
+
export type Datas = {
|
|
16
16
|
readonly [K in string]: Data;
|
|
17
17
|
};
|
|
18
18
|
/** Is an unknown value a data object? */
|
|
@@ -24,15 +24,8 @@ export declare function getData<T extends Data>(result: OptionalData<T>): T;
|
|
|
24
24
|
/** Get the props of a data object. */
|
|
25
25
|
export declare function getDataProps<T extends Data>(data: T): ImmutableArray<DataProp<T>>;
|
|
26
26
|
export declare function getDataProps<T extends Data>(data: T | Partial<T>): ImmutableArray<DataProp<T>>;
|
|
27
|
-
/**
|
|
28
|
-
* Format a data object as a string.
|
|
29
|
-
* - Use the custom `.toString()` function if it exists (don't use built in `Object.prototype.toString` because it's useless.
|
|
30
|
-
* - Use `.title` or `.name` or `.id` if they exist and are strings.
|
|
31
|
-
* - Use `Object` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
export declare function formatData(data: Data): string;
|
|
34
27
|
/** Type that represents an empty data object. */
|
|
35
|
-
export
|
|
28
|
+
export type EmptyData = {
|
|
36
29
|
readonly [K in never]: never;
|
|
37
30
|
};
|
|
38
31
|
/** An empty object. */
|