shelving 1.20.2 → 1.20.3
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/package.json +1 -1
- package/react/useDocument.d.ts +2 -2
- package/react/useDocument.js +1 -1
- package/schema/ColorSchema.d.ts +4 -3
- package/schema/ColorSchema.js +5 -4
- package/schema/DataSchema.d.ts +2 -2
- package/schema/DataSchema.js +2 -2
- package/schema/DateSchema.d.ts +2 -2
- package/schema/DateSchema.js +3 -3
- package/schema/EmailSchema.d.ts +4 -3
- package/schema/EmailSchema.js +5 -4
- package/schema/KeySchema.d.ts +2 -2
- package/schema/KeySchema.js +3 -3
- package/schema/{UrlSchema.d.ts → LinkSchema.d.ts} +6 -5
- package/schema/{UrlSchema.js → LinkSchema.js} +7 -6
- package/schema/MapSchema.d.ts +0 -1
- package/schema/MapSchema.js +0 -3
- package/schema/NumberSchema.d.ts +1 -1
- package/schema/NumberSchema.js +2 -2
- package/schema/{NullableSchema.d.ts → OptionalSchema.d.ts} +3 -3
- package/schema/{NullableSchema.js → OptionalSchema.js} +4 -4
- package/schema/PhoneSchema.d.ts +4 -3
- package/schema/PhoneSchema.js +5 -4
- package/schema/StringSchema.d.ts +4 -2
- package/schema/ThroughSchema.d.ts +1 -1
- package/schema/ThroughSchema.js +2 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +2 -2
- package/util/entry.d.ts +5 -0
package/package.json
CHANGED
package/react/useDocument.d.ts
CHANGED
|
@@ -30,5 +30,5 @@ export declare function useAsyncDocument<T extends Data>(ref: DataDocument<T> |
|
|
|
30
30
|
* @trhows `Error` if a `CacheProvider` is not part of the database's provider chain.
|
|
31
31
|
* @throws `Error` if there was a problem retrieving the result.
|
|
32
32
|
*/
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
33
|
+
export declare function useDocument<T extends Data>(ref: DataDocument<T>, maxAge?: number | true): Result<T>;
|
|
34
|
+
export declare function useDocument<T extends Data>(ref: DataDocument<T> | undefined, maxAge?: number | true): Result<T> | undefined;
|
package/react/useDocument.js
CHANGED
package/schema/ColorSchema.d.ts
CHANGED
|
@@ -9,13 +9,14 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
9
9
|
* Colors are limited to 512 characters (this can be changed with `max`), but generally these won't be data: URIs so this is a reasonable limit.
|
|
10
10
|
*/
|
|
11
11
|
export declare class ColorSchema extends StringSchema {
|
|
12
|
-
readonly max = 7;
|
|
13
12
|
readonly type = "color";
|
|
13
|
+
readonly min = 1;
|
|
14
|
+
readonly max = 7;
|
|
14
15
|
readonly multiline = false;
|
|
15
16
|
readonly match: RegExp;
|
|
16
17
|
sanitize(uncleanString: string): string;
|
|
17
18
|
}
|
|
18
19
|
/** Valid color hex string, e.g. `#00CCFF` (required because empty string is invalid). */
|
|
19
|
-
export declare const
|
|
20
|
+
export declare const COLOR: ColorSchema;
|
|
20
21
|
/** Valid color hex string, e.g. `#00CCFF`, or `null` */
|
|
21
|
-
export declare const OPTIONAL_COLOR: import("./
|
|
22
|
+
export declare const OPTIONAL_COLOR: import("./OptionalSchema.js").OptionalSchema<string>;
|
package/schema/ColorSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
2
2
|
import { StringSchema } from "./StringSchema.js";
|
|
3
3
|
const R_MATCH = /^#[0-9A-F]{6}$/;
|
|
4
4
|
const R_STRIP = /[^0-9A-F]/g;
|
|
@@ -14,8 +14,9 @@ const R_STRIP = /[^0-9A-F]/g;
|
|
|
14
14
|
export class ColorSchema extends StringSchema {
|
|
15
15
|
constructor() {
|
|
16
16
|
super(...arguments);
|
|
17
|
-
this.max = 7;
|
|
18
17
|
this.type = "color";
|
|
18
|
+
this.min = 1;
|
|
19
|
+
this.max = 7;
|
|
19
20
|
this.multiline = false;
|
|
20
21
|
this.match = R_MATCH;
|
|
21
22
|
}
|
|
@@ -25,6 +26,6 @@ export class ColorSchema extends StringSchema {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
/** Valid color hex string, e.g. `#00CCFF` (required because empty string is invalid). */
|
|
28
|
-
export const
|
|
29
|
+
export const COLOR = new ColorSchema({});
|
|
29
30
|
/** Valid color hex string, e.g. `#00CCFF`, or `null` */
|
|
30
|
-
export const OPTIONAL_COLOR =
|
|
31
|
+
export const OPTIONAL_COLOR = OPTIONAL(COLOR);
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Validators, Data } from "../util/index.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
import {
|
|
3
|
+
import { OptionalSchema } from "./OptionalSchema.js";
|
|
4
4
|
/** Validate a data object. */
|
|
5
5
|
export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
6
6
|
readonly props: Validators<T>;
|
|
@@ -14,4 +14,4 @@ export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
|
14
14
|
/** Valid data object with specifed properties. */
|
|
15
15
|
export declare const DATA: <T extends Data>(props: Validators<T>) => DataSchema<T>;
|
|
16
16
|
/** Valid data object with specifed properties, or `null` */
|
|
17
|
-
export declare const OPTIONAL_DATA: <T extends Data>(props: Validators<T>) =>
|
|
17
|
+
export declare const OPTIONAL_DATA: <T extends Data>(props: Validators<T>) => OptionalSchema<T>;
|
package/schema/DataSchema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isObject, validateData } from "../util/index.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/index.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
|
-
import {
|
|
4
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
/** Validate a data object. */
|
|
6
6
|
export class DataSchema extends Schema {
|
|
7
7
|
constructor({ value = {}, props, ...options }) {
|
|
@@ -18,4 +18,4 @@ export class DataSchema extends Schema {
|
|
|
18
18
|
/** Valid data object with specifed properties. */
|
|
19
19
|
export const DATA = (props) => new DataSchema({ props });
|
|
20
20
|
/** Valid data object with specifed properties, or `null` */
|
|
21
|
-
export const OPTIONAL_DATA = (props) =>
|
|
21
|
+
export const OPTIONAL_DATA = (props) => OPTIONAL(new DataSchema({ props }));
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export declare class DateSchema extends Schema<string> {
|
|
|
13
13
|
validate(unsafeValue?: unknown): string;
|
|
14
14
|
}
|
|
15
15
|
/** Valid date, e.g. `2005-09-12` (required because falsy values are invalid). */
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const DATE: DateSchema;
|
|
17
17
|
/** Valid date, e.g. `2005-09-12`, or `null` */
|
|
18
|
-
export declare const OPTIONAL_DATE: import("./
|
|
18
|
+
export declare const OPTIONAL_DATE: import("./OptionalSchema.js").OptionalSchema<string>;
|
package/schema/DateSchema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toDate, getYmd } from "../util/index.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/index.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
|
-
import {
|
|
4
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
/** Define a valid date, e.g. `2005-09-12` */
|
|
6
6
|
export class DateSchema extends Schema {
|
|
7
7
|
constructor({ value = "now", min = null, max = null, ...options }) {
|
|
@@ -24,6 +24,6 @@ export class DateSchema extends Schema {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
/** Valid date, e.g. `2005-09-12` (required because falsy values are invalid). */
|
|
27
|
-
export const
|
|
27
|
+
export const DATE = new DateSchema({});
|
|
28
28
|
/** Valid date, e.g. `2005-09-12`, or `null` */
|
|
29
|
-
export const OPTIONAL_DATE =
|
|
29
|
+
export const OPTIONAL_DATE = OPTIONAL(DATE);
|
package/schema/EmailSchema.d.ts
CHANGED
|
@@ -18,12 +18,13 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
18
18
|
*/
|
|
19
19
|
export declare class EmailSchema extends StringSchema {
|
|
20
20
|
readonly type = "email";
|
|
21
|
+
readonly min = 1;
|
|
21
22
|
readonly max = 254;
|
|
22
23
|
readonly match: RegExp;
|
|
23
24
|
readonly multiline = false;
|
|
24
25
|
sanitize(uncleanString: string): string;
|
|
25
26
|
}
|
|
26
|
-
/** Valid email, e.g. `test@test.com`
|
|
27
|
-
export declare const
|
|
27
|
+
/** Valid email, e.g. `test@test.com` */
|
|
28
|
+
export declare const EMAIL: EmailSchema;
|
|
28
29
|
/** Valid email, e.g. `test@test.com`, or `null` */
|
|
29
|
-
export declare const OPTIONAL_EMAIL: import("./
|
|
30
|
+
export declare const OPTIONAL_EMAIL: import("./OptionalSchema.js").OptionalSchema<string>;
|
package/schema/EmailSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
2
2
|
import { StringSchema } from "./StringSchema.js";
|
|
3
3
|
const R_MATCH = /^[a-z0-9](?:[a-zA-Z0-9._+-]{0,62}[a-zA-Z0-9])?@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.){1,3}(?:[a-z]{2,63}|xn--[a-z0-9-]{0,58}[a-z0-9])$/;
|
|
4
4
|
/**
|
|
@@ -22,6 +22,7 @@ export class EmailSchema extends StringSchema {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
super(...arguments);
|
|
24
24
|
this.type = "email";
|
|
25
|
+
this.min = 1;
|
|
25
26
|
this.max = 254;
|
|
26
27
|
this.match = R_MATCH;
|
|
27
28
|
this.multiline = false;
|
|
@@ -31,7 +32,7 @@ export class EmailSchema extends StringSchema {
|
|
|
31
32
|
return typeof cleanString === "string" ? cleanString.toLowerCase() : cleanString;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
/** Valid email, e.g. `test@test.com`
|
|
35
|
-
export const
|
|
35
|
+
/** Valid email, e.g. `test@test.com` */
|
|
36
|
+
export const EMAIL = new EmailSchema({});
|
|
36
37
|
/** Valid email, e.g. `test@test.com`, or `null` */
|
|
37
|
-
export const OPTIONAL_EMAIL =
|
|
38
|
+
export const OPTIONAL_EMAIL = OPTIONAL(EMAIL);
|
package/schema/KeySchema.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare class KeySchema extends StringSchema {
|
|
|
11
11
|
readonly max = 64;
|
|
12
12
|
}
|
|
13
13
|
/** Valid color hex string, e.g. `#00CCFF` (required because empty string is invalid). */
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const KEY: KeySchema;
|
|
15
15
|
/** Valid color hex string, e.g. `#00CCFF`, or `null` */
|
|
16
|
-
export declare const OPTIONAL_KEY: import("./
|
|
16
|
+
export declare const OPTIONAL_KEY: import("./OptionalSchema.js").OptionalSchema<string>;
|
package/schema/KeySchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringSchema } from "./StringSchema.js";
|
|
2
|
-
import {
|
|
2
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
3
3
|
/**
|
|
4
4
|
* Define a valid database key.
|
|
5
5
|
*
|
|
@@ -15,6 +15,6 @@ export class KeySchema extends StringSchema {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
/** Valid color hex string, e.g. `#00CCFF` (required because empty string is invalid). */
|
|
18
|
-
export const
|
|
18
|
+
export const KEY = new KeySchema({});
|
|
19
19
|
/** Valid color hex string, e.g. `#00CCFF`, or `null` */
|
|
20
|
-
export const OPTIONAL_KEY =
|
|
20
|
+
export const OPTIONAL_KEY = OPTIONAL(KEY);
|
|
@@ -5,8 +5,9 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
5
5
|
* - URLs are limited to 512 characters, but generally these won't be data: URIs so this is a reasonable limit.
|
|
6
6
|
* - Falsy values are converted to `""` empty string.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class LinkSchema extends StringSchema {
|
|
9
9
|
readonly type = "url";
|
|
10
|
+
readonly min = 1;
|
|
10
11
|
readonly max = 512;
|
|
11
12
|
readonly schemes: string[];
|
|
12
13
|
readonly hosts: string[] | null;
|
|
@@ -16,7 +17,7 @@ export declare class UrlSchema extends StringSchema {
|
|
|
16
17
|
});
|
|
17
18
|
validate(unsafeValue: unknown): string;
|
|
18
19
|
}
|
|
19
|
-
/** Valid
|
|
20
|
-
export declare const
|
|
21
|
-
/** Valid
|
|
22
|
-
export declare const
|
|
20
|
+
/** Valid link, e.g. `https://www.google.com` */
|
|
21
|
+
export declare const LINK: LinkSchema;
|
|
22
|
+
/** Valid link, e.g. `https://www.google.com`, or `null` */
|
|
23
|
+
export declare const OPTIONAL_LINK: import("./OptionalSchema.js").OptionalSchema<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InvalidFeedback } from "../feedback/index.js";
|
|
2
2
|
import { toURL } from "../util/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
4
4
|
import { StringSchema } from "./StringSchema.js";
|
|
5
5
|
/**
|
|
6
6
|
* Type of `StringSchema` that defines a valid URL.
|
|
@@ -8,10 +8,11 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
8
8
|
* - URLs are limited to 512 characters, but generally these won't be data: URIs so this is a reasonable limit.
|
|
9
9
|
* - Falsy values are converted to `""` empty string.
|
|
10
10
|
*/
|
|
11
|
-
export class
|
|
11
|
+
export class LinkSchema extends StringSchema {
|
|
12
12
|
constructor({ schemes = ["http:", "https:"], hosts = null, ...rest }) {
|
|
13
13
|
super(rest);
|
|
14
14
|
this.type = "url";
|
|
15
|
+
this.min = 1;
|
|
15
16
|
this.max = 512;
|
|
16
17
|
this.schemes = ["http:", "https:"];
|
|
17
18
|
this.hosts = null;
|
|
@@ -31,7 +32,7 @@ export class UrlSchema extends StringSchema {
|
|
|
31
32
|
return url.href;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
/** Valid
|
|
35
|
-
export const
|
|
36
|
-
/** Valid
|
|
37
|
-
export const
|
|
35
|
+
/** Valid link, e.g. `https://www.google.com` */
|
|
36
|
+
export const LINK = new LinkSchema({});
|
|
37
|
+
/** Valid link, e.g. `https://www.google.com`, or `null` */
|
|
38
|
+
export const OPTIONAL_LINK = OPTIONAL(LINK);
|
package/schema/MapSchema.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { ImmutableMap, Validator } from "../util/index.js";
|
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
3
|
/** Validate a `Map` instance. */
|
|
4
4
|
export declare class MapSchema<T> extends Schema<ImmutableMap<T>> {
|
|
5
|
-
static from<X>(items: Validator<X>): MapSchema<X>;
|
|
6
5
|
readonly value: ImmutableMap;
|
|
7
6
|
readonly items: Validator<T>;
|
|
8
7
|
readonly min: number | null;
|
package/schema/MapSchema.js
CHANGED
|
@@ -12,9 +12,6 @@ export class MapSchema extends Schema {
|
|
|
12
12
|
this.min = min;
|
|
13
13
|
this.max = max;
|
|
14
14
|
}
|
|
15
|
-
static from(items) {
|
|
16
|
-
return new MapSchema({ items });
|
|
17
|
-
}
|
|
18
15
|
validate(unsafeValue = this.value) {
|
|
19
16
|
if (!isObject(unsafeValue))
|
|
20
17
|
throw new InvalidFeedback("Must be map");
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export declare class NumberSchema extends Schema<number> {
|
|
|
16
16
|
/** Valid number, e.g. `2048` or `0` zero. */
|
|
17
17
|
export declare const NUMBER: NumberSchema;
|
|
18
18
|
/** Valid number, e.g. `#2048` or `0` zero, or `null` */
|
|
19
|
-
export declare const OPTIONAL_NUMBER: import("./
|
|
19
|
+
export declare const OPTIONAL_NUMBER: import("./OptionalSchema.js").OptionalSchema<number>;
|
package/schema/NumberSchema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toNumber, roundNumber } from "../util/index.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/index.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
|
-
import {
|
|
4
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
/** Schema that defines a valid number. */
|
|
6
6
|
export class NumberSchema extends Schema {
|
|
7
7
|
constructor({ value = 0, min = null, max = null, step = null, ...rest }) {
|
|
@@ -26,4 +26,4 @@ export class NumberSchema extends Schema {
|
|
|
26
26
|
/** Valid number, e.g. `2048` or `0` zero. */
|
|
27
27
|
export const NUMBER = new NumberSchema({});
|
|
28
28
|
/** Valid number, e.g. `#2048` or `0` zero, or `null` */
|
|
29
|
-
export const OPTIONAL_NUMBER =
|
|
29
|
+
export const OPTIONAL_NUMBER = OPTIONAL(NUMBER);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "./Schema.js";
|
|
2
2
|
import { ThroughSchema } from "./ThroughSchema.js";
|
|
3
3
|
/** Validate a value of a specific type or `null`. */
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class OptionalSchema<T> extends ThroughSchema<T | null> {
|
|
5
5
|
readonly value: T | null;
|
|
6
6
|
constructor({ value, ...rest }: ConstructorParameters<typeof Schema>[0] & {
|
|
7
7
|
source: Schema<T>;
|
|
@@ -9,5 +9,5 @@ export declare class NullableSchema<T> extends ThroughSchema<T | null> {
|
|
|
9
9
|
});
|
|
10
10
|
validate(unsafeValue?: unknown): T | null;
|
|
11
11
|
}
|
|
12
|
-
/** Create a new
|
|
13
|
-
export declare const
|
|
12
|
+
/** Create a new optional schema from a source schema. */
|
|
13
|
+
export declare const OPTIONAL: <T>(source: Schema<T>) => OptionalSchema<T>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ThroughSchema } from "./ThroughSchema.js";
|
|
2
2
|
/** Validate a value of a specific type or `null`. */
|
|
3
|
-
export class
|
|
3
|
+
export class OptionalSchema extends ThroughSchema {
|
|
4
4
|
constructor({ value = null, ...rest }) {
|
|
5
5
|
super(rest);
|
|
6
6
|
this.value = null;
|
|
7
7
|
this.value = value;
|
|
8
8
|
}
|
|
9
9
|
validate(unsafeValue = this.value) {
|
|
10
|
-
if (unsafeValue === null)
|
|
10
|
+
if (unsafeValue === null || unsafeValue === undefined || unsafeValue === "" || Number.isNaN(unsafeValue))
|
|
11
11
|
return null;
|
|
12
12
|
return super.validate(unsafeValue);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
/** Create a new
|
|
16
|
-
export const
|
|
15
|
+
/** Create a new optional schema from a source schema. */
|
|
16
|
+
export const OPTIONAL = (source) => new OptionalSchema({ source });
|
package/schema/PhoneSchema.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
5
5
|
* - Falsy values are converted to `""` empty string.
|
|
6
6
|
*/
|
|
7
7
|
export declare class PhoneSchema extends StringSchema {
|
|
8
|
-
readonly type = "
|
|
8
|
+
readonly type = "tel";
|
|
9
9
|
readonly match: RegExp;
|
|
10
|
+
readonly min = 1;
|
|
10
11
|
readonly max: number;
|
|
11
12
|
sanitize(str: string): string;
|
|
12
13
|
}
|
|
13
14
|
/** Valid phone number, e.g. `+441234567890` */
|
|
14
|
-
export declare const
|
|
15
|
+
export declare const PHONE: PhoneSchema;
|
|
15
16
|
/** Valid phone number, e.g. `+441234567890`, or `null` */
|
|
16
|
-
export declare const OPTIONAL_PHONE: import("./
|
|
17
|
+
export declare const OPTIONAL_PHONE: import("./OptionalSchema.js").OptionalSchema<string>;
|
package/schema/PhoneSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringSchema } from "./StringSchema.js";
|
|
2
|
-
import {
|
|
2
|
+
import { OPTIONAL } from "./OptionalSchema.js";
|
|
3
3
|
// Valid phone number is max 16 digits made up of:
|
|
4
4
|
// - Country code (`+` plus character and 1-3 digits, e.g. `+44` or `+1`).
|
|
5
5
|
// - Subscriber number (5-12 digits — the Solomon Islands have five-digit phone numbers apparently).
|
|
@@ -12,8 +12,9 @@ const R_MATCH = /^\+[1-9][0-9]{0,2}[0-9]{5,12}$/;
|
|
|
12
12
|
export class PhoneSchema extends StringSchema {
|
|
13
13
|
constructor() {
|
|
14
14
|
super(...arguments);
|
|
15
|
-
this.type = "
|
|
15
|
+
this.type = "tel";
|
|
16
16
|
this.match = R_MATCH;
|
|
17
|
+
this.min = 1;
|
|
17
18
|
this.max = 16; // Valid phone number is 16 digits or fewer (15 numerals with a leading `+` plus).
|
|
18
19
|
}
|
|
19
20
|
sanitize(str) {
|
|
@@ -24,6 +25,6 @@ export class PhoneSchema extends StringSchema {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
/** Valid phone number, e.g. `+441234567890` */
|
|
27
|
-
export const
|
|
28
|
+
export const PHONE = new PhoneSchema({});
|
|
28
29
|
/** Valid phone number, e.g. `+441234567890`, or `null` */
|
|
29
|
-
export const OPTIONAL_PHONE =
|
|
30
|
+
export const OPTIONAL_PHONE = OPTIONAL(PHONE);
|
package/schema/StringSchema.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Schema } from "./Schema.js";
|
|
2
|
+
/** `type=""` prop for HTML `<input />` tags that are relevant for strings. */
|
|
3
|
+
export declare type HtmlInputType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url";
|
|
2
4
|
/**
|
|
3
5
|
* Schema that defines a valid string.
|
|
4
6
|
*
|
|
@@ -21,7 +23,7 @@ import { Schema } from "./Schema.js";
|
|
|
21
23
|
*/
|
|
22
24
|
export declare class StringSchema extends Schema<string> {
|
|
23
25
|
readonly value: string;
|
|
24
|
-
readonly type:
|
|
26
|
+
readonly type: HtmlInputType;
|
|
25
27
|
readonly min: number;
|
|
26
28
|
readonly max: number | null;
|
|
27
29
|
readonly match: RegExp | null;
|
|
@@ -29,7 +31,7 @@ export declare class StringSchema extends Schema<string> {
|
|
|
29
31
|
readonly trim: boolean;
|
|
30
32
|
constructor({ value, type, min, max, match, multiline, trim, ...rest }: ConstructorParameters<typeof Schema>[0] & {
|
|
31
33
|
readonly value?: string;
|
|
32
|
-
readonly type?:
|
|
34
|
+
readonly type?: HtmlInputType;
|
|
33
35
|
readonly min?: number;
|
|
34
36
|
readonly max?: number | null;
|
|
35
37
|
readonly match?: RegExp | null;
|
|
@@ -2,7 +2,7 @@ import type { Class } from "../util/index.js";
|
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
3
|
export declare abstract class ThroughSchema<T> extends Schema<T> {
|
|
4
4
|
readonly source: Schema<T>;
|
|
5
|
-
constructor({ source,
|
|
5
|
+
constructor({ source, title, description, placeholder, }: ConstructorParameters<typeof Schema>[0] & {
|
|
6
6
|
source: Schema<T>;
|
|
7
7
|
});
|
|
8
8
|
validate(unsafeValue: unknown): T;
|
package/schema/ThroughSchema.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AssertionError } from "../error/index.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
3
|
export class ThroughSchema extends Schema {
|
|
4
|
-
constructor({ source,
|
|
5
|
-
super(
|
|
4
|
+
constructor({ source, title = source.title, description = source.description, placeholder = source.placeholder, }) {
|
|
5
|
+
super({ title, description, placeholder });
|
|
6
6
|
this.source = source;
|
|
7
7
|
}
|
|
8
8
|
validate(unsafeValue) {
|
package/schema/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ export * from "./DateSchema.js";
|
|
|
8
8
|
export * from "./EmailSchema.js";
|
|
9
9
|
export * from "./KeySchema.js";
|
|
10
10
|
export * from "./MapSchema.js";
|
|
11
|
-
export * from "./
|
|
11
|
+
export * from "./OptionalSchema.js";
|
|
12
12
|
export * from "./NumberSchema.js";
|
|
13
13
|
export * from "./ObjectSchema.js";
|
|
14
14
|
export * from "./PhoneSchema.js";
|
|
15
15
|
export * from "./RequiredSchema.js";
|
|
16
16
|
export * from "./StringSchema.js";
|
|
17
17
|
export * from "./ThroughSchema.js";
|
|
18
|
-
export * from "./
|
|
18
|
+
export * from "./LinkSchema.js";
|
package/schema/index.js
CHANGED
|
@@ -8,11 +8,11 @@ export * from "./DateSchema.js";
|
|
|
8
8
|
export * from "./EmailSchema.js";
|
|
9
9
|
export * from "./KeySchema.js";
|
|
10
10
|
export * from "./MapSchema.js";
|
|
11
|
-
export * from "./
|
|
11
|
+
export * from "./OptionalSchema.js";
|
|
12
12
|
export * from "./NumberSchema.js";
|
|
13
13
|
export * from "./ObjectSchema.js";
|
|
14
14
|
export * from "./PhoneSchema.js";
|
|
15
15
|
export * from "./RequiredSchema.js";
|
|
16
16
|
export * from "./StringSchema.js";
|
|
17
17
|
export * from "./ThroughSchema.js";
|
|
18
|
-
export * from "./
|
|
18
|
+
export * from "./LinkSchema.js";
|
package/util/entry.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ImmutableArray, MutableArray } from "./array.js";
|
|
1
2
|
import type { PossibleOptionalDate } from "./date.js";
|
|
2
3
|
/**
|
|
3
4
|
* Single entry from a map-like object.
|
|
@@ -9,6 +10,10 @@ export declare type Entry<T = unknown> = readonly [string, T];
|
|
|
9
10
|
export declare type AnyEntry = readonly [string, any];
|
|
10
11
|
/** Extract the type for an entry. */
|
|
11
12
|
export declare type EntryType<X extends AnyEntry> = X extends Entry<infer Y> ? Y : never;
|
|
13
|
+
/** Readonly list of entries with string keys. */
|
|
14
|
+
export declare type ImmutableEntries<T = unknown> = ImmutableArray<Entry<T>>;
|
|
15
|
+
/** Writable object with string keys. */
|
|
16
|
+
export declare type MutableEntries<T = unknown> = MutableArray<Entry<T>>;
|
|
12
17
|
/** Extract the key from an object entry. */
|
|
13
18
|
export declare const ENTRY_KEY: ([k]: Entry<unknown>) => string;
|
|
14
19
|
/** Extract the value from an object entry. */
|