shelving 1.158.2 → 1.159.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.158.2",
14
+ "version": "1.159.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -39,7 +39,7 @@ export interface ArraySchemaOptions<T> extends SchemaOptions {
39
39
  * schema.validate(["a", null], schema); // Throws Invalids({ "1": Invalid('Must be a string') });
40
40
  */
41
41
  export declare class ArraySchema<T> extends Schema<ImmutableArray<T>> {
42
- readonly value: ImmutableArray;
42
+ readonly value: ImmutableArray<T>;
43
43
  readonly one: string;
44
44
  readonly many: string;
45
45
  readonly items: Schema<T>;
@@ -11,9 +11,9 @@ export interface DataSchemaOptions<T extends Data> extends SchemaOptions {
11
11
  }
12
12
  /** Validate a data object. */
13
13
  export declare class DataSchema<T extends Data> extends Schema<unknown> {
14
- readonly value: Partial<T>;
14
+ readonly value: T;
15
15
  readonly props: Schemas<T>;
16
- constructor({ props, title, value, ...options }: DataSchemaOptions<T>);
16
+ constructor({ props, title, value: partialValue, ...options }: DataSchemaOptions<T>);
17
17
  validate(unsafeValue?: unknown): T;
18
18
  }
19
19
  /** Set of named data schemas. */
@@ -8,7 +8,9 @@ import { Schema } from "./Schema.js";
8
8
  /** Validate a data object. */
9
9
  export class DataSchema extends Schema {
10
10
  props;
11
- constructor({ props, title = "Data", value = {}, ...options }) {
11
+ constructor({ props, title = "Data", value: partialValue, ...options }) {
12
+ // Build default value from props and partial value.
13
+ const value = { ...mapProps(props, _getSchemaValue), ...partialValue };
12
14
  super({ title, value, ...options });
13
15
  this.props = props;
14
16
  }
@@ -18,6 +20,9 @@ export class DataSchema extends Schema {
18
20
  return validateData(unsafeValue, this.props);
19
21
  }
20
22
  }
23
+ function _getSchemaValue([, { value }]) {
24
+ return value;
25
+ }
21
26
  /** Create a `DataSchema` for a set of properties. */
22
27
  export const DATA = (props) => new DataSchema({ props });
23
28
  /** Valid data object with specifed properties, or `null` */
@@ -12,7 +12,7 @@ export interface DictionarySchemaOptions<T> extends SchemaOptions {
12
12
  }
13
13
  /** Validate a dictionary object (whose props are all the same with string keys). */
14
14
  export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>> {
15
- readonly value: ImmutableDictionary;
15
+ readonly value: ImmutableDictionary<T>;
16
16
  readonly one: string;
17
17
  readonly many: string;
18
18
  readonly items: Schema<T>;
@@ -15,3 +15,5 @@ export declare function repeatDelay(ms: number): AsyncIterable<number>;
15
15
  export declare function callSequence<T>(sequence: AsyncIterable<T>, callback: AsyncValueCallback<T>): AsyncIterable<T>;
16
16
  /** Pull values from a sequence until the returned function is called. */
17
17
  export declare function runSequence<T>(sequence: AsyncIterable<T>, onNext?: ValueCallback<T>, onError?: ErrorCallback): StopCallback;
18
+ /** Merge several sequences (calls the sequences in series). */
19
+ export declare function mergeSequences<T>(...sequences: AsyncIterable<T>[]): AsyncIterable<T>;
package/util/sequence.js CHANGED
@@ -71,3 +71,8 @@ async function _runSequence(sequence, stopped, onNext, onError) {
71
71
  // Continue iteration.
72
72
  return _runSequence(sequence, stopped, onNext, onError);
73
73
  }
74
+ /** Merge several sequences (calls the sequences in series). */
75
+ export async function* mergeSequences(...sequences) {
76
+ for await (const sequence of sequences)
77
+ yield* sequence;
78
+ }