shelving 1.185.0 → 1.185.2
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyCaller } from "../../util/function.js";
|
|
2
2
|
import type { RequestHandler, RequestOptions } from "../../util/http.js";
|
|
3
3
|
import type { AnyEndpoint, Endpoint } from "../endpoint/Endpoint.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { APIProvider } from "./APIProvider.js";
|
|
5
5
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
6
6
|
export type MockAPIFetchCall = {
|
|
7
7
|
readonly request: Request;
|
|
@@ -28,7 +28,7 @@ export declare class MockAPIProvider<P = unknown, R = unknown> extends ThroughAP
|
|
|
28
28
|
readonly fetchCalls: MockAPIFetchCall[];
|
|
29
29
|
readonly responseCalls: MockAPIResponseCall[];
|
|
30
30
|
readonly handler: RequestHandler;
|
|
31
|
-
constructor(handler?: RequestHandler, source?:
|
|
31
|
+
constructor(handler?: RequestHandler, source?: APIProvider<P, R>);
|
|
32
32
|
getRequest<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Request;
|
|
33
33
|
parseResponse<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, response: Response, caller?: AnyCaller): Promise<RR>;
|
|
34
34
|
fetch(request: Request): Promise<Response>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { debugRequest } from "../../util/debug.js";
|
|
1
2
|
import { ClientAPIProvider } from "./ClientAPIProvider.js";
|
|
2
3
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
3
4
|
/** Default handler just echoes back the input request as text. */
|
|
4
|
-
async function
|
|
5
|
-
return new Response(
|
|
5
|
+
async function _mockHandler(request) {
|
|
6
|
+
return new Response(`Mocked response to ${debugRequest(request)}`, { status: 200, statusText: "OK" });
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Provider that logs API calls without sending network requests.
|
|
@@ -14,7 +15,7 @@ export class MockAPIProvider extends ThroughAPIProvider {
|
|
|
14
15
|
fetchCalls = [];
|
|
15
16
|
responseCalls = [];
|
|
16
17
|
handler;
|
|
17
|
-
constructor(handler =
|
|
18
|
+
constructor(handler = _mockHandler, source = new ClientAPIProvider({ url: "https://api.mock.com" })) {
|
|
18
19
|
super(source);
|
|
19
20
|
this.handler = handler;
|
|
20
21
|
}
|
package/package.json
CHANGED
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOption
|
|
|
20
20
|
}
|
|
21
21
|
/** Choose from an allowed set of values. */
|
|
22
22
|
export declare class ChoiceSchema<K extends string> extends Schema<K> implements Iterable<ChoiceOption<K>> {
|
|
23
|
-
readonly value: K;
|
|
23
|
+
readonly value: K | undefined;
|
|
24
24
|
readonly options: ChoiceOptions<K>;
|
|
25
25
|
constructor({ one, title, placeholder, options, value, ...rest }: ChoiceSchemaOptions<K>);
|
|
26
26
|
validate(unsafeValue?: unknown): K;
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray
|
|
1
|
+
import { isArray } from "../util/array.js";
|
|
2
2
|
import { getKeys, getProps, isProp } from "../util/object.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Get the options for a choice field as an array. */
|
|
@@ -19,14 +19,14 @@ export function isOption(options, option) {
|
|
|
19
19
|
/** Choose from an allowed set of values. */
|
|
20
20
|
export class ChoiceSchema extends Schema {
|
|
21
21
|
options;
|
|
22
|
-
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value
|
|
22
|
+
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value, ...rest }) {
|
|
23
23
|
super({ one, title, value, placeholder, ...rest });
|
|
24
24
|
this.options = options;
|
|
25
25
|
}
|
|
26
26
|
validate(unsafeValue = this.value) {
|
|
27
27
|
if (typeof unsafeValue === "string" && isOption(this.options, unsafeValue))
|
|
28
28
|
return unsafeValue;
|
|
29
|
-
throw "Unknown value";
|
|
29
|
+
throw unsafeValue ? "Unknown value" : "Required";
|
|
30
30
|
}
|
|
31
31
|
// Implement iterable.
|
|
32
32
|
*[Symbol.iterator]() {
|