@mountainpass/waychaser 5.0.47 → 5.0.48
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/README.md +1 -1
- package/dist/augment-options.js +20 -57
- package/dist/augment-options.js.map +1 -1
- package/dist/expand-operation.js +18 -53
- package/dist/expand-operation.js.map +1 -1
- package/dist/handlers/hal/de-curie.js +6 -25
- package/dist/handlers/hal/de-curie.js.map +1 -1
- package/dist/handlers/hal/hal-handler.js +16 -65
- package/dist/handlers/hal/hal-handler.js.map +1 -1
- package/dist/handlers/hal/map-hal-link-to-operation.js +5 -30
- package/dist/handlers/hal/map-hal-link-to-operation.js.map +1 -1
- package/dist/handlers/link-header/link-header-handler.js +20 -63
- package/dist/handlers/link-header/link-header-handler.js.map +1 -1
- package/dist/handlers/location-header/location-header-handler.js +4 -7
- package/dist/handlers/location-header/location-header-handler.js.map +1 -1
- package/dist/handlers/siren/map-siren-action-to-operation.js +12 -53
- package/dist/handlers/siren/map-siren-action-to-operation.js.map +1 -1
- package/dist/handlers/siren/map-siren-link-to-operation.js +4 -29
- package/dist/handlers/siren/map-siren-link-to-operation.js.map +1 -1
- package/dist/handlers/siren/siren-action-handler.js +7 -32
- package/dist/handlers/siren/siren-action-handler.js.map +1 -1
- package/dist/handlers/siren/siren-handler.js +10 -39
- package/dist/handlers/siren/siren-handler.js.map +1 -1
- package/dist/handlers/siren/siren-link-handler.js +8 -43
- package/dist/handlers/siren/siren-link-handler.js.map +1 -1
- package/dist/operation-array.d.ts +1 -0
- package/dist/operation-array.js +27 -70
- package/dist/operation-array.js.map +1 -1
- package/dist/operation.js +128 -272
- package/dist/operation.js.map +1 -1
- package/dist/src/augment-options.d.ts +30 -0
- package/dist/src/expand-operation.d.ts +5 -0
- package/dist/src/handlers/hal/de-curie.d.ts +9 -0
- package/dist/src/handlers/hal/hal-handler.d.ts +6 -0
- package/dist/src/handlers/hal/map-hal-link-to-operation.d.ts +7 -0
- package/dist/src/handlers/link-header/link-header-handler.d.ts +7 -0
- package/dist/src/handlers/location-header/location-header-handler.d.ts +5 -0
- package/dist/src/handlers/siren/map-siren-action-to-operation.d.ts +6 -0
- package/dist/src/handlers/siren/map-siren-link-to-operation.d.ts +13 -0
- package/dist/src/handlers/siren/siren-action-handler.d.ts +5 -0
- package/dist/src/handlers/siren/siren-handler.d.ts +6 -0
- package/dist/src/handlers/siren/siren-link-handler.d.ts +6 -0
- package/dist/src/operation-array.d.ts +13 -0
- package/dist/src/operation.d.ts +24 -0
- package/dist/src/util/media-types.d.ts +5 -0
- package/dist/src/util/method-can-have-body.d.ts +4 -0
- package/dist/src/util/parse-accept.d.ts +6 -0
- package/dist/src/util/parse-operations.d.ts +14 -0
- package/dist/src/util/preferred-content-type.d.ts +6 -0
- package/dist/src/util/uri-template-lite.d.ts +5 -0
- package/dist/src/waychaser.d.ts +131 -0
- package/dist/util/media-types.js +2 -4
- package/dist/util/media-types.js.map +1 -1
- package/dist/util/method-can-have-body.js +1 -4
- package/dist/util/method-can-have-body.js.map +1 -1
- package/dist/util/parse-accept.js +17 -42
- package/dist/util/parse-accept.js.map +1 -1
- package/dist/util/parse-operations.js +22 -78
- package/dist/util/parse-operations.js.map +1 -1
- package/dist/util/preferred-content-type.js +4 -7
- package/dist/util/preferred-content-type.js.map +1 -1
- package/dist/util/uri-template-lite.js +6 -42
- package/dist/util/uri-template-lite.js.map +1 -1
- package/dist/waychaser.es.js +475 -922
- package/dist/waychaser.es.min.js +1 -1
- package/dist/waychaser.js +212 -480
- package/dist/waychaser.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InvocableOperation } from './operation';
|
|
2
|
+
import { WayChaserOptions, WayChaserResponse } from './waychaser';
|
|
3
|
+
export declare class OperationArray extends Array<InvocableOperation> {
|
|
4
|
+
private constructor();
|
|
5
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
6
|
+
static create(): OperationArray;
|
|
7
|
+
find(query: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), thisArgument?: unknown): InvocableOperation | undefined;
|
|
8
|
+
filter(query: string | Record<string, unknown> | ((value: InvocableOperation, index: number, array: InvocableOperation[]) => unknown), thisArgument?: unknown): OperationArray;
|
|
9
|
+
invoke(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions>): Promise<WayChaserResponse<unknown>> | undefined;
|
|
10
|
+
invoke<Content>(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions<Content>>): Promise<WayChaserResponse<Content>> | undefined;
|
|
11
|
+
invokeAll(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions>): Promise<Array<WayChaserResponse<unknown>>>;
|
|
12
|
+
invokeAll<Content>(relationship: string | Record<string, unknown> | ((this: void, value: InvocableOperation, index: number, object: InvocableOperation[]) => unknown), options?: Partial<WayChaserOptions<Content>>): Promise<Array<WayChaserResponse<Content>>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WayChaserOptions, WayChaserResponse } from './waychaser';
|
|
2
|
+
export declare class Operation {
|
|
3
|
+
rel: string;
|
|
4
|
+
uri: string;
|
|
5
|
+
method?: string;
|
|
6
|
+
parameters: Record<string, unknown> | Array<string>;
|
|
7
|
+
accept?: string;
|
|
8
|
+
anchor?: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
constructor({ rel, uri, method, parameters, accept, anchor, ...otherProperties }: Partial<Operation> & Pick<Operation, 'rel' | 'uri'>);
|
|
11
|
+
}
|
|
12
|
+
export declare class InvocableOperation extends Operation {
|
|
13
|
+
defaultOptions: WayChaserOptions;
|
|
14
|
+
response: WayChaserResponse<unknown>;
|
|
15
|
+
constructor(operation: Operation, response: WayChaserResponse<unknown>, defaultOptions: WayChaserOptions, thisContext: Record<string, string | number | bigint | boolean | undefined>);
|
|
16
|
+
private invokeAsFragment;
|
|
17
|
+
invokeAll(options?: Partial<WayChaserOptions>): Promise<Array<WayChaserResponse<unknown> | undefined>>;
|
|
18
|
+
invokeAll<Content>(options?: Partial<WayChaserOptions<Content>>): Promise<Array<WayChaserResponse<Content> | undefined>>;
|
|
19
|
+
private doInvokeAll;
|
|
20
|
+
invoke(options?: Partial<WayChaserOptions>): Promise<WayChaserResponse<unknown>>;
|
|
21
|
+
invoke<Content>(options?: Partial<WayChaserOptions<Content>>): Promise<WayChaserResponse<Content>>;
|
|
22
|
+
private url;
|
|
23
|
+
private expandUrl;
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Operation } from '../operation';
|
|
2
|
+
import { HandlerSpec } from '../waychaser';
|
|
3
|
+
/**
|
|
4
|
+
* @param root0
|
|
5
|
+
* @param root0.handlers
|
|
6
|
+
* @param root0.response
|
|
7
|
+
* @param root0.baseResponse
|
|
8
|
+
* @param root0.content
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseOperations({ handlers, baseResponse, content }: {
|
|
11
|
+
handlers: HandlerSpec[];
|
|
12
|
+
baseResponse: Response;
|
|
13
|
+
content?: unknown;
|
|
14
|
+
}): Record<string, Array<Operation>>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { InvocableOperation, Operation } from './operation';
|
|
2
|
+
import { OperationArray } from './operation-array';
|
|
3
|
+
import { ProblemDocument } from '@mountainpass/problem-document';
|
|
4
|
+
export type ValidationSuccess<Content> = {
|
|
5
|
+
success: true;
|
|
6
|
+
content: Content;
|
|
7
|
+
};
|
|
8
|
+
export type ValidationError = {
|
|
9
|
+
success: false;
|
|
10
|
+
problem: ProblemDocument;
|
|
11
|
+
};
|
|
12
|
+
export type ValidationResult<Content> = ValidationSuccess<Content> | ValidationError;
|
|
13
|
+
export 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 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 type Stopper = () => void;
|
|
75
|
+
export type ContentParser = (response: Response, contentParser?: ContentParser) => Promise<unknown | ProblemDocument | undefined>;
|
|
76
|
+
export type WayChaserOptions<ValidatorContent = null> = RequestInit & {
|
|
77
|
+
fetch: typeof fetch;
|
|
78
|
+
handlers: Array<HandlerSpec>;
|
|
79
|
+
defaultHandlers: Array<HandlerSpec>;
|
|
80
|
+
preInterceptors: Array<(uriOrRequest: any, updateOptions: any, stopper: any) => void>;
|
|
81
|
+
postInterceptors: Array<(<InterceptorContent>(response: (WayChaserResponse<InterceptorContent>), stop: Stopper) => void)>;
|
|
82
|
+
postErrorInterceptors: Array<(error: WayChaserProblem | Error, stopper: Stopper) => void>;
|
|
83
|
+
contentParser: ContentParser;
|
|
84
|
+
parameters?: Record<string, unknown>;
|
|
85
|
+
validator?: Validator<ValidatorContent>;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* @param handlers
|
|
89
|
+
*/
|
|
90
|
+
export declare function sortHandlers(handlers: Array<HandlerSpec>): Array<HandlerSpec>;
|
|
91
|
+
export declare function _waychaser(uriOrRequest: string | Request, defaults: WayChaserOptions, options?: Partial<WayChaserOptions>): Promise<WayChaserResponse<unknown>>;
|
|
92
|
+
export declare function _waychaser<Content>(uriOrRequest: string | Request, defaults: WayChaserOptions, options?: Partial<WayChaserOptions<Content>>): Promise<WayChaserResponse<Content>>;
|
|
93
|
+
/**
|
|
94
|
+
* calls fetch on the passed in uriOrRequest and parses the response
|
|
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>>) => Promise<WayChaserResponse<Content>>) & {
|
|
101
|
+
currentDefaults: WayChaserOptions<null>;
|
|
102
|
+
defaults: (newDefaults: Partial<WayChaserOptions>) => {
|
|
103
|
+
<Content>(uriOrRequest: string | Request, options?: Partial<WayChaserOptions<Content>>): Promise<WayChaserResponse<Content>>;
|
|
104
|
+
currentDefaults: {
|
|
105
|
+
defaultHandlers: HandlerSpec[];
|
|
106
|
+
handlers: never[];
|
|
107
|
+
headers: {};
|
|
108
|
+
contentParser: ContentParser;
|
|
109
|
+
body?: BodyInit | null;
|
|
110
|
+
cache?: RequestCache;
|
|
111
|
+
credentials?: RequestCredentials;
|
|
112
|
+
integrity?: string;
|
|
113
|
+
keepalive?: boolean;
|
|
114
|
+
method?: string;
|
|
115
|
+
mode?: RequestMode;
|
|
116
|
+
priority?: RequestPriority;
|
|
117
|
+
redirect?: RequestRedirect;
|
|
118
|
+
referrer?: string;
|
|
119
|
+
referrerPolicy?: ReferrerPolicy;
|
|
120
|
+
signal?: AbortSignal | null;
|
|
121
|
+
window?: null;
|
|
122
|
+
fetch: typeof fetch;
|
|
123
|
+
preInterceptors: Array<(uriOrRequest: any, updateOptions: any, stopper: any) => void>;
|
|
124
|
+
postInterceptors: Array<(<InterceptorContent>(response: (WayChaserResponse<InterceptorContent>), stop: Stopper) => void)>;
|
|
125
|
+
postErrorInterceptors: Array<(error: WayChaserProblem | Error, stopper: Stopper) => void>;
|
|
126
|
+
parameters?: Record<string, unknown>;
|
|
127
|
+
validator?: Validator<null> | undefined;
|
|
128
|
+
};
|
|
129
|
+
defaults(newDefaults: Partial<WayChaserOptions>): /*elided*/ any;
|
|
130
|
+
};
|
|
131
|
+
};
|
package/dist/util/media-types.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var MediaTypes = {
|
|
1
|
+
const MediaTypes = {
|
|
4
2
|
HAL: 'application/hal+json',
|
|
5
3
|
SIREN: 'application/vnd.siren+json'
|
|
6
4
|
};
|
|
7
|
-
|
|
5
|
+
export default MediaTypes;
|
|
8
6
|
//# sourceMappingURL=media-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-types.js","sourceRoot":"","sources":["../../src/util/media-types.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"media-types.js","sourceRoot":"","sources":["../../src/util/media-types.js"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,sBAAsB;IAC3B,KAAK,EAAE,4BAA4B;CACpC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.methodCanHaveBody = methodCanHaveBody;
|
|
4
1
|
/**
|
|
5
2
|
* @param method
|
|
6
3
|
*/
|
|
7
|
-
function methodCanHaveBody(method) {
|
|
4
|
+
export function methodCanHaveBody(method) {
|
|
8
5
|
return !['GET', 'DELETE', 'TRACE', 'OPTIONS', 'HEAD'].includes(method);
|
|
9
6
|
}
|
|
10
7
|
//# sourceMappingURL=method-can-have-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"method-can-have-body.js","sourceRoot":"","sources":["../../src/util/method-can-have-body.js"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"method-can-have-body.js","sourceRoot":"","sources":["../../src/util/method-can-have-body.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,MAAM;IACvC,OAAO,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -1,55 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// negotiated (https://www.npmjs.com/package/negotiated) doesn't working in IE 11 due to missing regex polyfill stuff
|
|
3
2
|
// @hapi/accept https://www.npmjs.com/package/@hapi/accept is too big (with all it's dependencies)
|
|
4
|
-
var __values = (this && this.__values) || function(o) {
|
|
5
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
6
|
-
if (m) return m.call(o);
|
|
7
|
-
if (o && typeof o.length === "number") return {
|
|
8
|
-
next: function () {
|
|
9
|
-
if (o && i >= o.length) o = void 0;
|
|
10
|
-
return { value: o && o[i++], done: !o };
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.parseAccept = parseAccept;
|
|
17
3
|
/**
|
|
18
4
|
* @param {string} accept
|
|
19
5
|
*/
|
|
20
|
-
function parseAccept(accept) {
|
|
21
|
-
|
|
6
|
+
export function parseAccept(accept) {
|
|
7
|
+
const entries = accept.split(',');
|
|
22
8
|
return entries
|
|
23
|
-
.map(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
subType: types === null || types === void 0 ? void 0 : types[1],
|
|
9
|
+
.map(entry => {
|
|
10
|
+
const fields = entry.split(';');
|
|
11
|
+
const type = fields.shift();
|
|
12
|
+
const types = type?.split('/');
|
|
13
|
+
const parsedEntry = {
|
|
14
|
+
type,
|
|
15
|
+
parentType: types?.[0],
|
|
16
|
+
subType: types?.[1],
|
|
32
17
|
q: 1
|
|
33
18
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (field[0] === 'q') {
|
|
39
|
-
parsedEntry[parsedFields[0]] = Number.parseFloat(parsedFields[1]);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
44
|
-
finally {
|
|
45
|
-
try {
|
|
46
|
-
if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
|
|
19
|
+
for (const field of fields) {
|
|
20
|
+
const parsedFields = field.split('=');
|
|
21
|
+
if (field[0] === 'q') {
|
|
22
|
+
parsedEntry[parsedFields[0]] = Number.parseFloat(parsedFields[1]);
|
|
47
23
|
}
|
|
48
|
-
finally { if (e_1) throw e_1.error; }
|
|
49
24
|
}
|
|
50
25
|
return parsedEntry;
|
|
51
26
|
})
|
|
52
|
-
.sort(
|
|
27
|
+
.sort((first, second) => {
|
|
53
28
|
// It is expected to return a negative value if first argument is less than second argument, zero if they're
|
|
54
29
|
// equal and a positive value otherwise
|
|
55
30
|
if (first.q > second.q) {
|
|
@@ -74,11 +49,11 @@ function parseAccept(accept) {
|
|
|
74
49
|
return 0;
|
|
75
50
|
}
|
|
76
51
|
})
|
|
77
|
-
.map(
|
|
52
|
+
.map(entry => {
|
|
78
53
|
return {
|
|
79
54
|
type: entry.type || ''
|
|
80
55
|
};
|
|
81
56
|
})
|
|
82
|
-
.filter(
|
|
57
|
+
.filter(entry => entry.type !== '');
|
|
83
58
|
}
|
|
84
59
|
//# sourceMappingURL=parse-accept.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-accept.js","sourceRoot":"","sources":["../../src/util/parse-accept.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-accept.js","sourceRoot":"","sources":["../../src/util/parse-accept.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,kGAAkG;AAElG;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,OAAO;SACX,GAAG,CAAC,KAAK,CAAC,EAAE;QACX,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;QAC3B,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,WAAW,GAAG;YAClB,IAAI;YACJ,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACtB,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACnB,CAAC,EAAE,CAAC;SACL,CAAA;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACrC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACrB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;QACD,OAAO,WAAW,CAAA;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACtB,4GAA4G;QAC5G,uCAAuC;QACvC,IAAI,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,CAAA;QACX,CAAC;aAAM,IAAI,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,CAAA;QACV,CAAC;aAAM,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,IAAI,MAAM,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YACjE,OAAO,CAAC,CAAA;QACV,CAAC;aAAM,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,IAAI,MAAM,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YACjE,OAAO,CAAC,CAAC,CAAA;QACX,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;YAC3D,OAAO,CAAC,CAAA;QACV,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;YAC3D,OAAO,CAAC,CAAC,CAAA;QACX,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,CAAA;QACV,CAAC;IACH,CAAC,CAAC;SACD,GAAG,CAAC,KAAK,CAAC,EAAE;QACX,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE;SACvB,CAAA;IACH,CAAC,CAAC;SACD,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.parseOperations = parseOperations;
|
|
15
|
-
var expand_operation_1 = require("../expand-operation");
|
|
1
|
+
import { expandOperation } from '../expand-operation';
|
|
16
2
|
/**
|
|
17
3
|
* @param root0
|
|
18
4
|
* @param root0.handlers
|
|
@@ -20,75 +6,33 @@ var expand_operation_1 = require("../expand-operation");
|
|
|
20
6
|
* @param root0.baseResponse
|
|
21
7
|
* @param root0.content
|
|
22
8
|
*/
|
|
23
|
-
function parseOperations(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
if (handledOperations) {
|
|
36
|
-
try {
|
|
37
|
-
for (var handledOperations_1 = (e_2 = void 0, __values(handledOperations)), handledOperations_1_1 = handledOperations_1.next(); !handledOperations_1_1.done; handledOperations_1_1 = handledOperations_1.next()) {
|
|
38
|
-
var operation = handledOperations_1_1.value;
|
|
39
|
-
operations.push(operation);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
43
|
-
finally {
|
|
44
|
-
try {
|
|
45
|
-
if (handledOperations_1_1 && !handledOperations_1_1.done && (_c = handledOperations_1.return)) _c.call(handledOperations_1);
|
|
46
|
-
}
|
|
47
|
-
finally { if (e_2) throw e_2.error; }
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (stop) {
|
|
51
|
-
break;
|
|
9
|
+
export function parseOperations({ handlers, baseResponse, content }) {
|
|
10
|
+
const operations = [];
|
|
11
|
+
let stop = false;
|
|
12
|
+
for (const handler of handlers) {
|
|
13
|
+
// TODO only call handers for the current media type
|
|
14
|
+
const handledOperations = handler.handler(baseResponse, content, () => {
|
|
15
|
+
stop = true;
|
|
16
|
+
});
|
|
17
|
+
if (handledOperations) {
|
|
18
|
+
for (const operation of handledOperations) {
|
|
19
|
+
operations.push(operation);
|
|
52
20
|
}
|
|
53
21
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
finally {
|
|
57
|
-
try {
|
|
58
|
-
if (handlers_1_1 && !handlers_1_1.done && (_b = handlers_1.return)) _b.call(handlers_1);
|
|
22
|
+
if (stop) {
|
|
23
|
+
break;
|
|
59
24
|
}
|
|
60
|
-
finally { if (e_1) throw e_1.error; }
|
|
61
25
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var operation_1 = expanded_1_1.value;
|
|
70
|
-
var anchor = operation_1.anchor || '';
|
|
71
|
-
if (!expandedOperations[anchor]) {
|
|
72
|
-
expandedOperations[anchor] = [];
|
|
73
|
-
}
|
|
74
|
-
expandedOperations[anchor].push(operation_1);
|
|
75
|
-
}
|
|
26
|
+
const expandedOperations = {};
|
|
27
|
+
for (const operation of operations) {
|
|
28
|
+
const expanded = expandOperation(operation);
|
|
29
|
+
for (const operation of expanded) {
|
|
30
|
+
const anchor = operation.anchor || '';
|
|
31
|
+
if (!expandedOperations[anchor]) {
|
|
32
|
+
expandedOperations[anchor] = [];
|
|
76
33
|
}
|
|
77
|
-
|
|
78
|
-
finally {
|
|
79
|
-
try {
|
|
80
|
-
if (expanded_1_1 && !expanded_1_1.done && (_e = expanded_1.return)) _e.call(expanded_1);
|
|
81
|
-
}
|
|
82
|
-
finally { if (e_4) throw e_4.error; }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
87
|
-
finally {
|
|
88
|
-
try {
|
|
89
|
-
if (operations_1_1 && !operations_1_1.done && (_d = operations_1.return)) _d.call(operations_1);
|
|
34
|
+
expandedOperations[anchor].push(operation);
|
|
90
35
|
}
|
|
91
|
-
finally { if (e_3) throw e_3.error; }
|
|
92
36
|
}
|
|
93
37
|
return expandedOperations;
|
|
94
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-operations.js","sourceRoot":"","sources":["../../src/util/parse-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-operations.js","sourceRoot":"","sources":["../../src/util/parse-operations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAIhE;IACC,MAAM,UAAU,GAAqB,EAAE,CAAA;IACvC,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,oDAAoD;QACpD,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE;YACpE,IAAI,GAAG,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;QACF,IAAI,iBAAiB,EAAE,CAAC;YACtB,KAAK,MAAM,SAAS,IAAI,iBAAiB,EAAE,CAAC;gBAC1C,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;QACD,IAAI,IAAI,EAAE,CAAC;YACT,MAAK;QACP,CAAC;IACH,CAAC;IAED,MAAM,kBAAkB,GAAqC,EAAE,CAAA;IAC/D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;QAC3C,KAAK,MAAM,SAAS,IAAI,QAAQ,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAA;YACrC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;YAAC,CAAC;YACpE,kBAAkB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAGD,OAAO,kBAAkB,CAAA;AAC3B,CAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preferredContentType = preferredContentType;
|
|
4
|
-
var parse_accept_1 = require("./parse-accept");
|
|
1
|
+
import { parseAccept } from './parse-accept';
|
|
5
2
|
/**
|
|
6
3
|
* @param accept
|
|
7
4
|
* @param supportedContentTypes
|
|
8
5
|
* @param defaultType
|
|
9
6
|
*/
|
|
10
|
-
function preferredContentType(accept, supportedContentTypes, defaultType) {
|
|
7
|
+
export function preferredContentType(accept, supportedContentTypes, defaultType) {
|
|
11
8
|
if (accept) {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const acceptable = parseAccept(accept);
|
|
10
|
+
const acceptableMediaTypes = acceptable.find(row => {
|
|
14
11
|
return supportedContentTypes.includes(row.type);
|
|
15
12
|
});
|
|
16
13
|
return acceptableMediaTypes.type;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preferred-content-type.js","sourceRoot":"","sources":["../../src/util/preferred-content-type.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preferred-content-type.js","sourceRoot":"","sources":["../../src/util/preferred-content-type.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAM,EACN,qBAAqB,EACrB,WAAW;IAEX,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QAEtC,MAAM,oBAAoB,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACjD,OAAO,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;QAEF,OAAO,oBAAoB,CAAC,IAAI,CAAA;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,WAAW,CAAA;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -1,45 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.URI = void 0;
|
|
37
|
-
var uri_template_lite_1 = __importStar(require("uri-template-lite"));
|
|
38
|
-
exports.URI = {
|
|
39
|
-
Template: uri_template_lite_1.default,
|
|
40
|
-
expand: uri_template_lite_1.expand,
|
|
41
|
-
parameters: function (url) {
|
|
42
|
-
var template = new uri_template_lite_1.default(url);
|
|
1
|
+
import Template, { expand } from 'uri-template-lite';
|
|
2
|
+
export const URI = {
|
|
3
|
+
Template,
|
|
4
|
+
expand,
|
|
5
|
+
parameters(url) {
|
|
6
|
+
const template = new Template(url);
|
|
43
7
|
return template.match(url);
|
|
44
8
|
}
|
|
45
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uri-template-lite.js","sourceRoot":"","sources":["../../src/util/uri-template-lite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uri-template-lite.js","sourceRoot":"","sources":["../../src/util/uri-template-lite.js"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAEpD,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,QAAQ;IACR,MAAM;IACN,UAAU,CAAC,GAAG;QACZ,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAA;QAClC,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;CACF,CAAA"}
|