shelving 1.157.1 → 1.157.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/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.157.1",
14
+ "version": "1.157.2",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,8 +1,8 @@
1
- import type { Schema, SchemaOptions } from "./Schema.js";
2
- import { ThroughSchema } from "./ThroughSchema.js";
1
+ import type { Schema } from "./Schema.js";
2
+ import { ThroughSchema, type ThroughSchemaOptions } from "./ThroughSchema.js";
3
3
  /** Allowed options for `NullableSchema` */
4
- export interface NullableSchemaOptions<T> extends SchemaOptions {
5
- readonly source: Schema<T>;
4
+ export interface NullableSchemaOptions<T> extends ThroughSchemaOptions<T | null> {
5
+ /** Default value (defaults to `null`). */
6
6
  readonly value?: T | null;
7
7
  }
8
8
  /** Validate a value of a specific type or `null`. */
@@ -1,11 +1,18 @@
1
1
  import type { Schema } from "./Schema.js";
2
- import { ThroughSchema } from "./ThroughSchema.js";
2
+ import { ThroughSchema, type ThroughSchemaOptions } from "./ThroughSchema.js";
3
+ export interface OptionalSchemaOptions<T> extends ThroughSchemaOptions<T | undefined> {
4
+ /** Default value for an `OptionalSchema` can always `undefined` */
5
+ readonly value?: undefined;
6
+ }
3
7
  /**
4
8
  * Validate a property in an optional way, i.e. it can be the value, or `undefined`
5
9
  * - If the prop is `undefined`, then `undefined` is returned.
6
10
  * - When used with `validateData()` this means the prop can be silently skipped.
7
11
  */
8
12
  export declare class OptionalSchema<T> extends ThroughSchema<T | undefined> {
13
+ /** Default value for an `OptionalSchema` is always `undefined` (default value is only used when a value is `undefined`, so otherwise `undefined` could never be returned as a value). */
14
+ readonly value: undefined;
15
+ constructor(options: OptionalSchemaOptions<T>);
9
16
  validate(unsafeValue: unknown): T | undefined;
10
17
  }
11
18
  /** Make a property of a set of data optional, i.e. it can be the value or `undefined` */
@@ -5,6 +5,9 @@ import { ThroughSchema } from "./ThroughSchema.js";
5
5
  * - When used with `validateData()` this means the prop can be silently skipped.
6
6
  */
7
7
  export class OptionalSchema extends ThroughSchema {
8
+ constructor(options) {
9
+ super({ ...options, value: undefined });
10
+ }
8
11
  validate(unsafeValue) {
9
12
  if (unsafeValue === undefined)
10
13
  return undefined;