shelving 1.18.0 → 1.19.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/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.18.0",
14
+ "version": "1.19.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -0,0 +1,19 @@
1
+ import { Schema } from "./Schema.js";
2
+ /** Specify a specific list of allowed values. */
3
+ export declare type AllowedOptions<T extends string> = ReadonlyArray<T> | {
4
+ readonly [K in T]: string;
5
+ };
6
+ /** Validate a value against a specific set of allowed values. */
7
+ export declare function validateAllowed<T extends string>(unsafeString: string, allowed: AllowedOptions<T>): T;
8
+ /** Define a valid string from an allowed set of strings. */
9
+ export declare class AllowSchema<T extends string> extends Schema<T> {
10
+ readonly allow: AllowedOptions<T>;
11
+ readonly value: T | null;
12
+ constructor({ allow, value, ...options }: ConstructorParameters<typeof Schema>[0] & {
13
+ allow: AllowedOptions<T>;
14
+ value?: T | null;
15
+ });
16
+ validate(unsafeValue?: unknown): T;
17
+ }
18
+ /** Valid string from an allowed set of strings. */
19
+ export declare const ALLOW: <T extends string>(allow: AllowedOptions<T>) => AllowSchema<T>;
@@ -14,15 +14,15 @@ export function validateAllowed(unsafeString, allowed) {
14
14
  throw new InvalidFeedback("Unknown value", { value: unsafeString });
15
15
  }
16
16
  /** Define a valid string from an allowed set of strings. */
17
- export class AllowedSchema extends Schema {
18
- constructor({ allow, ...options }) {
17
+ export class AllowSchema extends Schema {
18
+ constructor({ allow, value = null, ...options }) {
19
19
  super(options);
20
20
  this.allow = allow;
21
+ this.value = value;
21
22
  }
22
- validate(unsafeValue) {
23
- const unsafeString = toString(unsafeValue);
24
- return validateAllowed(unsafeString, this.allow);
23
+ validate(unsafeValue = this.value) {
24
+ return validateAllowed(toString(unsafeValue), this.allow);
25
25
  }
26
26
  }
27
27
  /** Valid string from an allowed set of strings. */
28
- export const ALLOW = (allow) => new AllowedSchema({ allow });
28
+ export const ALLOW = (allow) => new AllowSchema({ allow: allow });
package/schema/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./Schema.js";
2
- export * from "./AllowedSchema.js";
2
+ export * from "./AllowSchema.js";
3
3
  export * from "./ArraySchema.js";
4
4
  export * from "./BooleanSchema.js";
5
5
  export * from "./ColorSchema.js";
package/schema/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./Schema.js";
2
- export * from "./AllowedSchema.js";
2
+ export * from "./AllowSchema.js";
3
3
  export * from "./ArraySchema.js";
4
4
  export * from "./BooleanSchema.js";
5
5
  export * from "./ColorSchema.js";
@@ -1,17 +0,0 @@
1
- import { Schema } from "./Schema.js";
2
- /** Specify a specific list of allowed values. */
3
- export declare type Allowed<T extends string> = ReadonlyArray<T> | {
4
- readonly [K in T]: string;
5
- };
6
- /** Validate a value against a specific set of allowed values. */
7
- export declare function validateAllowed<T extends string>(unsafeString: string, allowed: Allowed<T>): T;
8
- /** Define a valid string from an allowed set of strings. */
9
- export declare class AllowedSchema<T extends string> extends Schema<T> {
10
- readonly allow: Allowed<T>;
11
- constructor({ allow, ...options }: ConstructorParameters<typeof Schema>[0] & {
12
- allow: Allowed<T>;
13
- });
14
- validate(unsafeValue: unknown): T;
15
- }
16
- /** Valid string from an allowed set of strings. */
17
- export declare const ALLOW: <T extends string>(allow: Allowed<T>) => AllowedSchema<T>;