shelving 1.21.0 → 1.22.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/api/Resource.d.ts CHANGED
@@ -6,20 +6,11 @@ import { Validator, Validatable } from "../util/index.js";
6
6
  * @param returns The `Validator` the function's returned value must conform to (defaults to `undefined` if not specified).
7
7
  */
8
8
  export declare class Resource<P = unknown, R = void> implements Validatable<R> {
9
- static create<X, Y>(payload: Validator<X>, result: Validator<Y>): Resource<X, Y>;
10
- static create<Y>(payload: undefined, result: Y): Resource<undefined, Y>;
11
- static create<X>(payload: Validator<X>, result?: undefined): Resource<X, void>;
12
- static create(payload?: undefined, result?: undefined): Resource<undefined, void>;
13
9
  /** Payload validator. */
14
10
  readonly payload: Validator<P>;
15
11
  /** Result validator. */
16
12
  readonly result: Validator<R>;
17
- protected constructor(payload: Validator<P>, result: Validator<R>);
18
- /**
19
- * Validate a payload for this resource.
20
- *
21
- */
22
- validatePayload(unsafePayload: unknown): P;
13
+ constructor(payload: Validator<P>, result: Validator<R>);
23
14
  /**
24
15
  * Validate a result for this resource.
25
16
  *
@@ -32,3 +23,11 @@ export declare class Resource<P = unknown, R = void> implements Validatable<R> {
32
23
  export declare type PayloadType<X extends Resource> = X extends Resource<infer Y, unknown> ? Y : never;
33
24
  /** Extract the result type from a `Resource`. */
34
25
  export declare type ResourceType<X extends Resource> = X extends Resource<unknown, infer Y> ? Y : never;
26
+ /**
27
+ * Shortcut to create a new `Resource` (consistent with `Schema` shortcuts.
28
+ * - Sets `undefined` as the default type for payload and result.
29
+ */
30
+ export declare function RESOURCE<X, Y>(payload: Validator<X>, result: Validator<Y>): Resource<X, Y>;
31
+ export declare function RESOURCE<Y>(payload: undefined, result: Y): Resource<undefined, Y>;
32
+ export declare function RESOURCE<X>(payload: Validator<X>, result?: undefined): Resource<X, void>;
33
+ export declare function RESOURCE(payload?: undefined, result?: undefined): Resource<undefined, void>;
package/api/Resource.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import { UNDEFINED, validate } from "../util/index.js";
2
- import { Feedback, throwFeedback } from "../feedback/index.js";
2
+ import { Feedback } from "../feedback/index.js";
3
3
  import { ResourceValidationError } from "./errors.js";
4
- /** Validator that always returns void/undefined. */
5
- const UNDEFINED_VALIDATOR = UNDEFINED;
6
4
  /**
7
5
  * An abstract API resource definition, used to specify types for e.g. serverless functions..
8
6
  *
@@ -15,16 +13,6 @@ export class Resource {
15
13
  this.payload = payload;
16
14
  this.result = result;
17
15
  }
18
- static create(payload = UNDEFINED_VALIDATOR, result = UNDEFINED_VALIDATOR) {
19
- return new Resource(payload, result);
20
- }
21
- /**
22
- * Validate a payload for this resource.
23
- *
24
- */
25
- validatePayload(unsafePayload) {
26
- return throwFeedback(validate(unsafePayload, this.payload));
27
- }
28
16
  /**
29
17
  * Validate a result for this resource.
30
18
  *
@@ -40,3 +28,6 @@ export class Resource {
40
28
  }
41
29
  }
42
30
  }
31
+ export function RESOURCE(payload = UNDEFINED, result = UNDEFINED) {
32
+ return new Resource(payload, result);
33
+ }
@@ -4,4 +4,3 @@ export * from "./WarningFeedback.js";
4
4
  export * from "./ErrorFeedback.js";
5
5
  export * from "./InvalidFeedback.js";
6
6
  export * from "./hydrations.js";
7
- export * from "./util.js";
package/feedback/index.js CHANGED
@@ -4,4 +4,3 @@ export * from "./WarningFeedback.js";
4
4
  export * from "./ErrorFeedback.js";
5
5
  export * from "./InvalidFeedback.js";
6
6
  export * from "./hydrations.js";
7
- export * from "./util.js";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.21.0",
14
+ "version": "1.22.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,6 +1,5 @@
1
1
  import { validate, ValidateObserver, callAsync } from "../util/index.js";
2
2
  import { Transform, validateTransform } from "../transform/index.js";
3
- import { throwFeedback } from "../feedback/index.js";
4
3
  import { ThroughProvider } from "./ThroughProvider.js";
5
4
  /** Validates any values that are read from or written to a source provider. */
6
5
  export class ValidationProvider extends ThroughProvider {
@@ -11,7 +10,7 @@ export class ValidationProvider extends ThroughProvider {
11
10
  return super.subscribe(ref, new ValidateObserver(ref, observer));
12
11
  }
13
12
  add(ref, data) {
14
- return super.add(ref, throwFeedback(validate(data, ref.validator)));
13
+ return super.add(ref, validate(data, ref.validator));
15
14
  }
16
15
  write(ref, value) {
17
16
  return super.write(ref, value ? _validateWrite(value, ref.validator) : value);
@@ -28,5 +27,5 @@ export class ValidationProvider extends ThroughProvider {
28
27
  }
29
28
  /** Validate data or a transform for a path. */
30
29
  function _validateWrite(value, validator) {
31
- return throwFeedback(value instanceof Transform ? validateTransform(value, validator) : validate(value, validator));
30
+ return value instanceof Transform ? validateTransform(value, validator) : validate(value, validator);
32
31
  }
@@ -1,3 +0,0 @@
1
- import { Feedback } from "./Feedback.js";
2
- /** Throw the value if it's an instance of `Feedback` */
3
- export declare function throwFeedback<T>(value: T | Feedback): T;
package/feedback/util.js DELETED
@@ -1,7 +0,0 @@
1
- import { Feedback } from "./Feedback.js";
2
- /** Throw the value if it's an instance of `Feedback` */
3
- export function throwFeedback(value) {
4
- if (value instanceof Feedback)
5
- throw value;
6
- return value;
7
- }