shelving 1.94.0 → 1.95.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.94.0",
14
+ "version": "1.95.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,12 +1,14 @@
1
- import type { Schema } from "./Schema.js";
1
+ import type { Schema, SchemaOptions } from "./Schema.js";
2
2
  import { ThroughSchema } from "./ThroughSchema.js";
3
+ /** Allowed options for `OptionalSchema` */
4
+ export type OptionalSchemaOptions<T> = SchemaOptions & {
5
+ readonly source: Schema<T>;
6
+ readonly value?: T | null;
7
+ };
3
8
  /** Validate a value of a specific type or `null`. */
4
9
  export declare class OptionalSchema<T> extends ThroughSchema<T | null> {
5
10
  readonly value: T | null;
6
- constructor(options: ConstructorParameters<typeof Schema>[0] & {
7
- source: Schema<T>;
8
- value?: T | null;
9
- });
11
+ constructor(options: OptionalSchemaOptions<T>);
10
12
  validate(unsafeValue?: unknown): T | null;
11
13
  }
12
14
  /** Create a new optional schema from a source schema. */
@@ -1,6 +1,6 @@
1
1
  import type { Schema } from "./Schema.js";
2
2
  import { ThroughSchema } from "./ThroughSchema.js";
3
- /** Validate a value of a specifed type, but return `Feedback` if the validated value is falsy. */
3
+ /** Validate a value of a specifed type, but throw `Feedback` if the validated value is falsy. */
4
4
  export declare class RequiredSchema<T> extends ThroughSchema<T> {
5
5
  validate(unsafeValue: unknown): T;
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { Feedback } from "../feedback/Feedback.js";
2
2
  import { ThroughSchema } from "./ThroughSchema.js";
3
- /** Validate a value of a specifed type, but return `Feedback` if the validated value is falsy. */
3
+ /** Validate a value of a specifed type, but throw `Feedback` if the validated value is falsy. */
4
4
  export class RequiredSchema extends ThroughSchema {
5
5
  validate(unsafeValue) {
6
6
  const safeValue = super.validate(unsafeValue);
@@ -2,8 +2,9 @@ import { Schema } from "./Schema.js";
2
2
  /** Schema that passes through to a source schema. */
3
3
  export class ThroughSchema extends Schema {
4
4
  constructor(options) {
5
- super(options);
6
- this.source = options.source;
5
+ const source = options.source;
6
+ super({ ...source, ...options });
7
+ this.source = source;
7
8
  }
8
9
  validate(unsafeValue) {
9
10
  return this.source.validate(unsafeValue);