@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.
Files changed (74) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +37 -26
  3. package/dist/augment-options.d.ts +29 -0
  4. package/dist/augment-options.js +70 -0
  5. package/dist/augment-options.js.map +1 -0
  6. package/dist/expand-operation.d.ts +5 -0
  7. package/dist/expand-operation.js +78 -0
  8. package/dist/expand-operation.js.map +1 -0
  9. package/dist/handlers/hal/de-curie.d.ts +9 -0
  10. package/dist/handlers/hal/de-curie.js +50 -0
  11. package/dist/handlers/hal/de-curie.js.map +1 -0
  12. package/dist/handlers/hal/hal-handler.d.ts +6 -0
  13. package/dist/handlers/hal/hal-handler.js +91 -0
  14. package/dist/handlers/hal/hal-handler.js.map +1 -0
  15. package/dist/handlers/hal/map-hal-link-to-operation.d.ts +7 -0
  16. package/dist/handlers/hal/map-hal-link-to-operation.js +40 -0
  17. package/dist/handlers/hal/map-hal-link-to-operation.js.map +1 -0
  18. package/dist/handlers/link-header/link-header-handler.d.ts +7 -0
  19. package/dist/handlers/link-header/link-header-handler.js +83 -0
  20. package/dist/handlers/link-header/link-header-handler.js.map +1 -0
  21. package/dist/handlers/location-header/location-header-handler.d.ts +5 -0
  22. package/dist/handlers/location-header/location-header-handler.js +16 -0
  23. package/dist/handlers/location-header/location-header-handler.js.map +1 -0
  24. package/dist/handlers/siren/map-siren-action-to-operation.d.ts +6 -0
  25. package/dist/handlers/siren/map-siren-action-to-operation.js +63 -0
  26. package/dist/handlers/siren/map-siren-action-to-operation.js.map +1 -0
  27. package/dist/handlers/siren/map-siren-link-to-operation.d.ts +13 -0
  28. package/dist/handlers/siren/map-siren-link-to-operation.js +43 -0
  29. package/dist/handlers/siren/map-siren-link-to-operation.js.map +1 -0
  30. package/dist/handlers/siren/siren-action-handler.d.ts +5 -0
  31. package/dist/handlers/siren/siren-action-handler.js +46 -0
  32. package/dist/handlers/siren/siren-action-handler.js.map +1 -0
  33. package/dist/handlers/siren/siren-handler.d.ts +6 -0
  34. package/dist/handlers/siren/siren-handler.js +48 -0
  35. package/dist/handlers/siren/siren-handler.js.map +1 -0
  36. package/dist/handlers/siren/siren-link-handler.d.ts +6 -0
  37. package/dist/handlers/siren/siren-link-handler.js +59 -0
  38. package/dist/handlers/siren/siren-link-handler.js.map +1 -0
  39. package/dist/operation-array.d.ts +12 -0
  40. package/dist/operation-array.js +110 -0
  41. package/dist/operation-array.js.map +1 -0
  42. package/dist/operation.d.ts +24 -0
  43. package/dist/operation.js +304 -0
  44. package/dist/operation.js.map +1 -0
  45. package/dist/util/media-types.d.ts +5 -0
  46. package/dist/util/media-types.js +8 -0
  47. package/dist/util/media-types.js.map +1 -0
  48. package/dist/util/method-can-have-body.d.ts +4 -0
  49. package/dist/util/method-can-have-body.js +11 -0
  50. package/dist/util/method-can-have-body.js.map +1 -0
  51. package/dist/util/parse-accept.d.ts +6 -0
  52. package/dist/util/parse-accept.js +85 -0
  53. package/dist/util/parse-accept.js.map +1 -0
  54. package/dist/util/parse-operations.d.ts +14 -0
  55. package/dist/util/parse-operations.js +94 -0
  56. package/dist/util/parse-operations.js.map +1 -0
  57. package/dist/util/preferred-content-type.d.ts +6 -0
  58. package/dist/util/preferred-content-type.js +23 -0
  59. package/dist/util/preferred-content-type.js.map +1 -0
  60. package/dist/util/uri-template-lite.d.ts +1 -0
  61. package/dist/util/uri-template-lite.js +31 -0
  62. package/dist/util/uri-template-lite.js.map +1 -0
  63. package/dist/waychaser.d.ts +130 -0
  64. package/dist/waychaser.es.js +2331 -0
  65. package/dist/waychaser.es.min.js +15 -0
  66. package/dist/waychaser.js +582 -4527
  67. package/dist/waychaser.js.map +1 -1
  68. package/package.json +36 -63
  69. package/dist/waychaser.cjs +0 -14
  70. package/dist/waychaser.cjs.map +0 -1
  71. package/dist/waychaser.min.js +0 -7
  72. package/dist/waychaser.min.js.map +0 -1
  73. package/dist/waychaser.mjs +0 -14
  74. 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
+ };