shelving 1.24.0 → 1.25.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/Write.js CHANGED
@@ -1,4 +1,4 @@
1
- import { transform } from "../util/index.js";
1
+ import { transform, IS_DEFINED } from "../util/index.js";
2
2
  /** Write to a database. */
3
3
  export class Write {
4
4
  }
@@ -22,14 +22,13 @@ export class DocumentWrite extends Write {
22
22
  export class Writes extends Write {
23
23
  constructor(...writes) {
24
24
  super();
25
- this.writes = writes.filter(isWrite);
25
+ this.writes = writes.filter(IS_DEFINED);
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;
33
32
  /** Set of hydrations for all change classes. */
34
33
  export const WRITE_HYDRATIONS = {
35
34
  writes: Writes,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.24.0",
14
+ "version": "1.25.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -13,10 +13,13 @@ export declare type Transforms<T extends Data> = {
13
13
  /** Set of transforms that can be appled to an object's properties. */
14
14
  export declare class DataTransform<T extends Data> extends Transform<T> implements Iterable<Prop<Transforms<T>>> {
15
15
  readonly transforms: Transforms<T>;
16
- constructor(transforms: Transforms<T>);
16
+ constructor(transforms?: Transforms<T>);
17
17
  transform(existing: T): T;
18
- /** Return a new object with the specified additional transform. */
19
- prop<K extends Key<T>>(key: K, transform: T[K] | Transform<T[K]>): this;
18
+ /**
19
+ * Return a new object with the specified additional transform.
20
+ * - If `key` is `undefined` the prop is skipped to make it easy to make conditional data transforms.
21
+ */
22
+ prop<K extends Key<T>>(key: K | undefined, transform: T[K] | Transform<T[K]>): this;
20
23
  /** Return a new object with the specified additional transforms. */
21
24
  props(transforms: Transforms<T>): this;
22
25
  /** Iterate over the transforms in this object. */
@@ -2,15 +2,20 @@ import { transformData } from "../util/index.js";
2
2
  import { Transform } from "./Transform.js";
3
3
  /** Set of transforms that can be appled to an object's properties. */
4
4
  export class DataTransform extends Transform {
5
- constructor(transforms) {
5
+ constructor(transforms = {}) {
6
6
  super();
7
7
  this.transforms = transforms;
8
8
  }
9
9
  transform(existing) {
10
10
  return transformData(existing, this.transforms);
11
11
  }
12
- /** Return a new object with the specified additional transform. */
12
+ /**
13
+ * Return a new object with the specified additional transform.
14
+ * - If `key` is `undefined` the prop is skipped to make it easy to make conditional data transforms.
15
+ */
13
16
  prop(key, transform) {
17
+ if (key === undefined)
18
+ return this;
14
19
  return { __proto__: Object.getPrototypeOf(this), ...this, transforms: { ...this.transforms, [key]: transform } };
15
20
  }
16
21
  /** Return a new object with the specified additional transforms. */