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 +9 -10
- package/api/Resource.js +4 -13
- package/feedback/index.d.ts +0 -1
- package/feedback/index.js +0 -1
- package/package.json +1 -1
- package/provider/ValidationProvider.js +2 -3
- package/feedback/util.d.ts +0 -3
- package/feedback/util.js +0 -7
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
|
-
|
|
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
|
|
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
|
+
}
|
package/feedback/index.d.ts
CHANGED
package/feedback/index.js
CHANGED
package/package.json
CHANGED
|
@@ -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,
|
|
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
|
|
30
|
+
return value instanceof Transform ? validateTransform(value, validator) : validate(value, validator);
|
|
32
31
|
}
|
package/feedback/util.d.ts
DELETED