shelving 1.23.2 → 1.24.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/db/Database.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validata
2
2
  import { Transform, Transforms } from "../transform/index.js";
3
3
  import type { Provider } from "../provider/Provider.js";
4
4
  import { Filters, Sorts, Query } from "../query/index.js";
5
- import { DocumentWrite, Write } from "./Write.js";
5
+ import { DocumentWrite, Write, Writes } from "./Write.js";
6
6
  /**
7
7
  * Combines a database model and a provider.
8
8
  *
@@ -18,8 +18,10 @@ export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
18
18
  query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DataQuery<ValidatorType<V[K]>>;
19
19
  /** Reference a document in a collection in this model. */
20
20
  doc<K extends Key<V>>(collection: K, id: string): DataDocument<ValidatorType<V[K]>>;
21
- /** Perform a write on this database. */
22
- write(write: Write): void | PromiseLike<void>;
21
+ /** Perform a write on this database and return the `Write` instance representing the changes. */
22
+ write(write: Write): Promise<Write>;
23
+ /** Perform multiple writes on this database by combining them into a single `Writes` instance representing the changes. */
24
+ writes(...writes: (Write | undefined)[]): Promise<Writes>;
23
25
  }
24
26
  /** A documents reference within a specific database. */
25
27
  export declare class DataQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Results<T>>, Iterable<Entry<T>> {
package/db/Database.js CHANGED
@@ -3,7 +3,7 @@ import { DataTransform, Transform } from "../transform/index.js";
3
3
  import { Feedback, InvalidFeedback } from "../feedback/index.js";
4
4
  import { Filters, Query, EqualFilter } from "../query/index.js";
5
5
  import { DocumentRequiredError, DocumentValidationError, QueryValidationError } from "./errors.js";
6
- import { DocumentWrite } from "./Write.js";
6
+ import { DocumentWrite, Writes } from "./Write.js";
7
7
  /**
8
8
  * Combines a database model and a provider.
9
9
  *
@@ -25,9 +25,16 @@ export class Database {
25
25
  doc(collection, id) {
26
26
  return new DataDocument(this.provider, this.validators[collection], collection, id);
27
27
  }
28
- /** Perform a write on this database. */
29
- write(write) {
30
- return write.transform(this);
28
+ /** Perform a write on this database and return the `Write` instance representing the changes. */
29
+ async write(write) {
30
+ await write.transform(this);
31
+ return write;
32
+ }
33
+ /** Perform multiple writes on this database by combining them into a single `Writes` instance representing the changes. */
34
+ async writes(...writes) {
35
+ const write = new Writes(...writes);
36
+ await write.transform(this);
37
+ return write;
31
38
  }
32
39
  }
33
40
  /** A documents reference within a specific database. */
package/db/Write.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare class DocumentWrite<T extends Data> extends Write {
20
20
  */
21
21
  export declare class Writes extends Write {
22
22
  readonly writes: ImmutableArray<Write>;
23
- constructor(...writes: Write[]);
23
+ constructor(...writes: (Write | undefined)[]);
24
24
  transform(db: Database): Promise<void>;
25
25
  }
26
26
  /** Set of hydrations for all change classes. */
package/db/Write.js CHANGED
@@ -22,13 +22,14 @@ export class DocumentWrite extends Write {
22
22
  export class Writes extends Write {
23
23
  constructor(...writes) {
24
24
  super();
25
- this.writes = writes;
25
+ this.writes = writes.filter(isWrite);
26
26
  }
27
27
  async transform(db) {
28
28
  for (const writes of this.writes)
29
29
  await transform(db, writes);
30
30
  }
31
31
  }
32
+ const isWrite = (v) => !!v;
32
33
  /** Set of hydrations for all change classes. */
33
34
  export const WRITE_HYDRATIONS = {
34
35
  writes: Writes,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.23.2",
14
+ "version": "1.24.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -24,24 +24,13 @@ export declare function transform<I, O>(input: I, transformer: (v: I) => O): O;
24
24
  export declare function transform<I, O>(input: I, transformer: Transformer<I, O>): O;
25
25
  /**
26
26
  * Apply a transformer to each item in a set of items and yield the transformed item.
27
- *
28
27
  * @yield Transformed items after calling `transformer()` on each.
29
- * @returns Number of items that changed.
30
28
  */
31
29
  export declare function transformItems<I, O>(items: Iterable<I>, transformer: (input: I) => O): Iterable<O>;
32
30
  export declare function transformItems<I, O>(items: Iterable<I>, transformer: Transformer<I, O>): Iterable<O>;
33
31
  /**
34
32
  * Apply a transformer to each item in an array and return the transformed array.
35
- *
36
- * @param arr The input array or map-like object or iterable to iterate over.
37
- * @param mapper Mapping function that receives the value and key and returns the corresponding value.
38
- * - Mapper can return a promise. If it does will return a Promise that resolves once every value has resolved.
39
- * - Return the `SKIP` symbol from the mapper to skip that property and not include it in the output object.
40
- * - `SKIP` is useful because using `filter(Boolean)` doesn't currently filter in TypeScript (and requires another loop anyway).
41
- * - Mapper can be a non-function static value and all the values will be set to that value.
42
- *
43
- * @return The mapped array.
44
- * - Immutable so if the values don't change then the same instance will be returned.
33
+ * @return The transformed array.
45
34
  */
46
35
  export declare function transformArray<T extends ImmutableArray>(arr: T, transformer: Transformer<ArrayType<T>, ArrayType<T>>): T;
47
36
  export declare function transformArray<I, O>(arr: Iterable<I>, transformer: (v: I) => O): ImmutableArray<O>;