@mountainpass/waychaser 4.0.38 → 5.0.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.
- package/CHANGELOG.md +18 -0
- package/README.md +37 -26
- package/dist/augment-options.d.ts +29 -0
- package/dist/augment-options.js +70 -0
- package/dist/augment-options.js.map +1 -0
- package/dist/expand-operation.d.ts +5 -0
- package/dist/expand-operation.js +78 -0
- package/dist/expand-operation.js.map +1 -0
- package/dist/handlers/hal/de-curie.d.ts +9 -0
- package/dist/handlers/hal/de-curie.js +50 -0
- package/dist/handlers/hal/de-curie.js.map +1 -0
- package/dist/handlers/hal/hal-handler.d.ts +6 -0
- package/dist/handlers/hal/hal-handler.js +91 -0
- package/dist/handlers/hal/hal-handler.js.map +1 -0
- package/dist/handlers/hal/map-hal-link-to-operation.d.ts +7 -0
- package/dist/handlers/hal/map-hal-link-to-operation.js +40 -0
- package/dist/handlers/hal/map-hal-link-to-operation.js.map +1 -0
- package/dist/handlers/link-header/link-header-handler.d.ts +7 -0
- package/dist/handlers/link-header/link-header-handler.js +83 -0
- package/dist/handlers/link-header/link-header-handler.js.map +1 -0
- package/dist/handlers/location-header/location-header-handler.d.ts +5 -0
- package/dist/handlers/location-header/location-header-handler.js +16 -0
- package/dist/handlers/location-header/location-header-handler.js.map +1 -0
- package/dist/handlers/siren/map-siren-action-to-operation.d.ts +6 -0
- package/dist/handlers/siren/map-siren-action-to-operation.js +63 -0
- package/dist/handlers/siren/map-siren-action-to-operation.js.map +1 -0
- package/dist/handlers/siren/map-siren-link-to-operation.d.ts +13 -0
- package/dist/handlers/siren/map-siren-link-to-operation.js +43 -0
- package/dist/handlers/siren/map-siren-link-to-operation.js.map +1 -0
- package/dist/handlers/siren/siren-action-handler.d.ts +5 -0
- package/dist/handlers/siren/siren-action-handler.js +46 -0
- package/dist/handlers/siren/siren-action-handler.js.map +1 -0
- package/dist/handlers/siren/siren-handler.d.ts +6 -0
- package/dist/handlers/siren/siren-handler.js +48 -0
- package/dist/handlers/siren/siren-handler.js.map +1 -0
- package/dist/handlers/siren/siren-link-handler.d.ts +6 -0
- package/dist/handlers/siren/siren-link-handler.js +59 -0
- package/dist/handlers/siren/siren-link-handler.js.map +1 -0
- package/dist/operation-array.d.ts +12 -0
- package/dist/operation-array.js +110 -0
- package/dist/operation-array.js.map +1 -0
- package/dist/operation.d.ts +24 -0
- package/dist/operation.js +304 -0
- package/dist/operation.js.map +1 -0
- package/dist/util/media-types.d.ts +5 -0
- package/dist/util/media-types.js +8 -0
- package/dist/util/media-types.js.map +1 -0
- package/dist/util/method-can-have-body.d.ts +4 -0
- package/dist/util/method-can-have-body.js +11 -0
- package/dist/util/method-can-have-body.js.map +1 -0
- package/dist/util/parse-accept.d.ts +6 -0
- package/dist/util/parse-accept.js +85 -0
- package/dist/util/parse-accept.js.map +1 -0
- package/dist/util/parse-operations.d.ts +14 -0
- package/dist/util/parse-operations.js +94 -0
- package/dist/util/parse-operations.js.map +1 -0
- package/dist/util/preferred-content-type.d.ts +6 -0
- package/dist/util/preferred-content-type.js +23 -0
- package/dist/util/preferred-content-type.js.map +1 -0
- package/dist/util/uri-template-lite.d.ts +1 -0
- package/dist/util/uri-template-lite.js +31 -0
- package/dist/util/uri-template-lite.js.map +1 -0
- package/dist/waychaser.d.ts +130 -0
- package/dist/waychaser.es.js +2331 -0
- package/dist/waychaser.es.min.js +15 -0
- package/dist/waychaser.js +582 -4527
- package/dist/waychaser.js.map +1 -1
- package/package.json +36 -63
- package/dist/waychaser.cjs +0 -14
- package/dist/waychaser.cjs.map +0 -1
- package/dist/waychaser.min.js +0 -7
- package/dist/waychaser.min.js.map +0 -1
- package/dist/waychaser.mjs +0 -14
- package/dist/waychaser.mjs.map +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { InvocableOperation, Operation } from './operation';
|
|
2
|
+
import { OperationArray } from './operation-array';
|
|
3
|
+
import { ProblemDocument } from '@mountainpass/problem-document';
|
|
4
|
+
export declare type ValidationSuccess<Content> = {
|
|
5
|
+
success: true;
|
|
6
|
+
content: Content;
|
|
7
|
+
};
|
|
8
|
+
export declare type ValidationError = {
|
|
9
|
+
success: false;
|
|
10
|
+
problem: ProblemDocument;
|
|
11
|
+
};
|
|
12
|
+
export declare type ValidationResult<Content> = ValidationSuccess<Content> | ValidationError;
|
|
13
|
+
export declare type Validator<Content> = (content: unknown) => ValidationResult<Content>;
|
|
14
|
+
/**
|
|
15
|
+
* @param result
|
|
16
|
+
*/
|
|
17
|
+
export declare function isValidationSuccess<Content>(result: ValidationResult<Content>): result is ValidationSuccess<Content>;
|
|
18
|
+
export declare class WayChaserResponse<Content> {
|
|
19
|
+
content: Content;
|
|
20
|
+
allOperations: Record<string, Array<Operation>>;
|
|
21
|
+
operations: OperationArray;
|
|
22
|
+
anchor?: string;
|
|
23
|
+
response: Response;
|
|
24
|
+
fullContent?: unknown;
|
|
25
|
+
parameters: Record<string, unknown>;
|
|
26
|
+
constructor({ handlers, defaultOptions, baseResponse, content, fullContent, anchor, parentOperations, parameters }: {
|
|
27
|
+
handlers?: HandlerSpec[];
|
|
28
|
+
defaultOptions?: WayChaserOptions;
|
|
29
|
+
baseResponse: Response;
|
|
30
|
+
content: Content;
|
|
31
|
+
fullContent?: unknown;
|
|
32
|
+
parameters?: Record<string, unknown>;
|
|
33
|
+
anchor?: string;
|
|
34
|
+
parentOperations?: Record<string, Array<Operation>>;
|
|
35
|
+
});
|
|
36
|
+
static create(baseResponse: Response, content: unknown, defaultOptions: WayChaserOptions, mergedOptions: WayChaserOptions): WayChaserResponse<unknown>;
|
|
37
|
+
static create<Content>(baseResponse: Response, content: unknown, defaultOptions: WayChaserOptions, mergedOptions: WayChaserOptions<Content>): WayChaserResponse<Content>;
|
|
38
|
+
get ops(): OperationArray;
|
|
39
|
+
invoke(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions>): Promise<WayChaserResponse<unknown>> | undefined;
|
|
40
|
+
invoke<RelatedContent>(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions<RelatedContent>>): Promise<WayChaserResponse<RelatedContent>> | undefined;
|
|
41
|
+
invokeAll(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions>): Promise<Array<WayChaserResponse<unknown>>>;
|
|
42
|
+
invokeAll<RelatedContent>(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions<RelatedContent>>): Promise<Array<WayChaserResponse<RelatedContent>>>;
|
|
43
|
+
get body(): ReadableStream;
|
|
44
|
+
get bodyUsed(): boolean;
|
|
45
|
+
get headers(): Headers;
|
|
46
|
+
get ok(): boolean;
|
|
47
|
+
get redirected(): boolean;
|
|
48
|
+
get status(): number;
|
|
49
|
+
get statusText(): string;
|
|
50
|
+
get type(): ResponseType;
|
|
51
|
+
get url(): string;
|
|
52
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
53
|
+
blob(): Promise<Blob>;
|
|
54
|
+
clone(): Response;
|
|
55
|
+
formData(): Promise<FormData>;
|
|
56
|
+
text(): Promise<string>;
|
|
57
|
+
}
|
|
58
|
+
export declare class WayChaserProblem extends Error {
|
|
59
|
+
readonly problem: ProblemDocument;
|
|
60
|
+
readonly response: WayChaserResponse<unknown>;
|
|
61
|
+
constructor({ response, problem }: {
|
|
62
|
+
response: WayChaserResponse<unknown>;
|
|
63
|
+
problem: ProblemDocument;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export declare type HandlerSpec = {
|
|
67
|
+
handler: (baseResponse: Response, content: unknown, stopper: () => void) => Array<Operation> | undefined;
|
|
68
|
+
mediaRanges: Array<string | {
|
|
69
|
+
mediaType: string;
|
|
70
|
+
q?: number;
|
|
71
|
+
}>;
|
|
72
|
+
q?: number;
|
|
73
|
+
};
|
|
74
|
+
export declare type Stopper = () => void;
|
|
75
|
+
export declare type WayChaserOptions<ValidatorContent = null> = RequestInit & {
|
|
76
|
+
fetch: typeof fetch;
|
|
77
|
+
handlers: Array<HandlerSpec>;
|
|
78
|
+
defaultHandlers: Array<HandlerSpec>;
|
|
79
|
+
preInterceptors: Array<(uriOrRequest: any, updateOptions: any, stopper: any) => void>;
|
|
80
|
+
postInterceptors: Array<(<InterceptorContent>(response: (WayChaserResponse<InterceptorContent>), stop: Stopper) => void)>;
|
|
81
|
+
postErrorInterceptors: Array<(error: WayChaserProblem | Error, stopper: Stopper) => void>;
|
|
82
|
+
contentParser: (response: Response) => Promise<unknown | ProblemDocument | undefined>;
|
|
83
|
+
parameters?: Record<string, unknown>;
|
|
84
|
+
validator?: Validator<ValidatorContent>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* @param handlers
|
|
88
|
+
*/
|
|
89
|
+
export declare function sortHandlers(handlers: Array<HandlerSpec>): Array<HandlerSpec>;
|
|
90
|
+
export declare function _waychaser(uriOrRequest: string | Request, defaults: WayChaserOptions, options?: Partial<WayChaserOptions>): Promise<WayChaserResponse<unknown>>;
|
|
91
|
+
export declare function _waychaser<Content>(uriOrRequest: string | Request, defaults: WayChaserOptions, options?: Partial<WayChaserOptions<Content>>): Promise<WayChaserResponse<Content>>;
|
|
92
|
+
/**
|
|
93
|
+
* calls fetch on the passed in uriOrRequest and parses the response
|
|
94
|
+
*
|
|
95
|
+
* @param uriOrRequest see RequestInit
|
|
96
|
+
* @param options see WayChaserOptions
|
|
97
|
+
* @returns WayChaserResponse<Content>
|
|
98
|
+
* @throws TypeError | AbortError | WayChaserResponseProblem | Error
|
|
99
|
+
*/
|
|
100
|
+
export declare const waychaser: (<Content>(uriOrRequest: string | Request, options?: Partial<WayChaserOptions<Content>> | undefined) => Promise<WayChaserResponse<Content>>) & {
|
|
101
|
+
currentDefaults: WayChaserOptions<null>;
|
|
102
|
+
defaults: (newDefaults: Partial<WayChaserOptions>) => {
|
|
103
|
+
<Content_1>(uriOrRequest: string | Request, options?: Partial<WayChaserOptions<Content_1>> | undefined): Promise<WayChaserResponse<Content_1>>;
|
|
104
|
+
currentDefaults: {
|
|
105
|
+
defaultHandlers: HandlerSpec[];
|
|
106
|
+
handlers: never[];
|
|
107
|
+
headers: {};
|
|
108
|
+
body?: BodyInit | null | undefined;
|
|
109
|
+
cache?: RequestCache | undefined;
|
|
110
|
+
credentials?: RequestCredentials | undefined;
|
|
111
|
+
integrity?: string | undefined;
|
|
112
|
+
keepalive?: boolean | undefined;
|
|
113
|
+
method?: string | undefined;
|
|
114
|
+
mode?: RequestMode | undefined;
|
|
115
|
+
redirect?: RequestRedirect | undefined;
|
|
116
|
+
referrer?: string | undefined;
|
|
117
|
+
referrerPolicy?: ReferrerPolicy | undefined;
|
|
118
|
+
signal?: AbortSignal | null | undefined;
|
|
119
|
+
window?: null | undefined;
|
|
120
|
+
fetch: typeof fetch;
|
|
121
|
+
preInterceptors: ((uriOrRequest: any, updateOptions: any, stopper: any) => void)[];
|
|
122
|
+
postInterceptors: (<InterceptorContent>(response: WayChaserResponse<InterceptorContent>, stop: Stopper) => void)[];
|
|
123
|
+
postErrorInterceptors: ((error: WayChaserProblem | Error, stopper: Stopper) => void)[];
|
|
124
|
+
contentParser: (response: Response) => Promise<unknown | ProblemDocument | undefined>;
|
|
125
|
+
parameters?: Record<string, unknown> | undefined;
|
|
126
|
+
validator?: Validator<null> | undefined;
|
|
127
|
+
};
|
|
128
|
+
defaults(newDefaults: Partial<WayChaserOptions>): any;
|
|
129
|
+
};
|
|
130
|
+
};
|