@warp-drive/utilities 5.9.0-beta.0 → 5.9.0-beta.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/cjs-dist/string.cjs +448 -0
- package/cjs-dist/string.cjs.map +1 -0
- package/dist/-private.d.ts +12 -0
- package/dist/-private.d.ts.map +1 -0
- package/dist/-private.js +2 -6
- package/dist/active-record.d.ts +260 -0
- package/dist/active-record.d.ts.map +1 -0
- package/dist/active-record.js +254 -379
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-BkXwUT0x.js +16 -0
- package/dist/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/derivations.d.ts +30 -0
- package/dist/derivations.d.ts.map +1 -0
- package/dist/derivations.js +26 -26
- package/dist/derivations.js.map +1 -0
- package/dist/handlers.d.ts +283 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +240 -283
- package/dist/handlers.js.map +1 -0
- package/dist/index-BeMAuqgZ.d.ts +462 -0
- package/dist/index-BeMAuqgZ.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +357 -335
- package/dist/index.js.map +1 -0
- package/dist/inflections-DzBsjJqj.js +80 -0
- package/dist/inflections-DzBsjJqj.js.map +1 -0
- package/dist/json-api.d.ts +496 -0
- package/dist/json-api.d.ts.map +1 -0
- package/dist/json-api.js +470 -706
- package/dist/json-api.js.map +1 -0
- package/dist/rest.d.ts +258 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +254 -377
- package/dist/rest.js.map +1 -0
- package/dist/string-CWmAluxh.js +290 -0
- package/dist/string-CWmAluxh.js.map +1 -0
- package/dist/string.d.ts +165 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +2 -427
- package/dist/unpkg/dev/-private.js +2 -6
- package/dist/unpkg/dev/active-record.js +253 -378
- package/dist/unpkg/dev/active-record.js.map +1 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev/derivations.js +26 -26
- package/dist/unpkg/dev/derivations.js.map +1 -0
- package/dist/unpkg/dev/handlers.js +238 -282
- package/dist/unpkg/dev/handlers.js.map +1 -0
- package/dist/unpkg/dev/index.js +356 -336
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev/json-api.js +469 -706
- package/dist/unpkg/dev/json-api.js.map +1 -0
- package/dist/unpkg/dev/rest.js +253 -376
- package/dist/unpkg/dev/rest.js.map +1 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev/string.js +3 -1
- package/dist/unpkg/dev-deprecated/-private.js +2 -6
- package/dist/unpkg/dev-deprecated/active-record.js +253 -378
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev-deprecated/derivations.js +26 -26
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/dev-deprecated/handlers.js +238 -282
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +356 -336
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev-deprecated/json-api.js +469 -706
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/dev-deprecated/rest.js +253 -376
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +3 -1
- package/dist/unpkg/prod/-private.js +2 -6
- package/dist/unpkg/prod/active-record.js +236 -351
- package/dist/unpkg/prod/active-record.js.map +1 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod/derivations.js +26 -26
- package/dist/unpkg/prod/derivations.js.map +1 -0
- package/dist/unpkg/prod/handlers.js +231 -272
- package/dist/unpkg/prod/handlers.js.map +1 -0
- package/dist/unpkg/prod/index.js +265 -215
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod/json-api.js +446 -669
- package/dist/unpkg/prod/json-api.js.map +1 -0
- package/dist/unpkg/prod/rest.js +236 -349
- package/dist/unpkg/prod/rest.js.map +1 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod/string.js +3 -1
- package/dist/unpkg/prod-deprecated/-private.js +2 -6
- package/dist/unpkg/prod-deprecated/active-record.js +236 -351
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod-deprecated/derivations.js +26 -26
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/prod-deprecated/handlers.js +231 -272
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +265 -215
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/json-api.js +446 -669
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/prod-deprecated/rest.js +236 -349
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +3 -1
- package/package.json +20 -23
- package/declarations/-private/active-record/find-record.d.ts +0 -64
- package/declarations/-private/active-record/query.d.ts +0 -53
- package/declarations/-private/active-record/save-record.d.ts +0 -146
- package/declarations/-private/builder-utils.d.ts +0 -4
- package/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/declarations/-private/handlers/gated.d.ts +0 -19
- package/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/declarations/-private/handlers/utils.d.ts +0 -41
- package/declarations/-private/json-api/-utils.d.ts +0 -109
- package/declarations/-private/json-api/find-record.d.ts +0 -84
- package/declarations/-private/json-api/query.d.ts +0 -100
- package/declarations/-private/json-api/save-record.d.ts +0 -228
- package/declarations/-private/json-api/serialize.d.ts +0 -70
- package/declarations/-private/rest/find-record.d.ts +0 -62
- package/declarations/-private/rest/query.d.ts +0 -53
- package/declarations/-private/rest/save-record.d.ts +0 -146
- package/declarations/-private/string/inflect.d.ts +0 -82
- package/declarations/-private/string/inflections.d.ts +0 -9
- package/declarations/-private/string/transform.d.ts +0 -77
- package/declarations/-private.d.ts +0 -1
- package/declarations/active-record.d.ts +0 -3
- package/declarations/derivations.d.ts +0 -27
- package/declarations/handlers.d.ts +0 -10
- package/declarations/index.d.ts +0 -208
- package/declarations/json-api.d.ts +0 -5
- package/declarations/rest.d.ts +0 -3
- package/declarations/string.d.ts +0 -14
- package/dist/builder-utils-Donkk-BZ.js +0 -22
- package/dist/inflect-BSG696t-.js +0 -344
- package/dist/string.cjs +0 -430
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/-private/builder-utils.ts
|
|
2
|
+
function copyForwardUrlOptions(urlOptions, options) {
|
|
3
|
+
if ("host" in options) urlOptions.host = options.host;
|
|
4
|
+
if ("namespace" in options) urlOptions.namespace = options.namespace;
|
|
5
|
+
if ("resourcePath" in options) urlOptions.resourcePath = options.resourcePath;
|
|
6
|
+
}
|
|
7
|
+
function extractCacheOptions(options) {
|
|
8
|
+
const cacheOptions = {};
|
|
9
|
+
if ("reload" in options) cacheOptions.reload = options.reload;
|
|
10
|
+
if ("backgroundReload" in options) cacheOptions.backgroundReload = options.backgroundReload;
|
|
11
|
+
return cacheOptions;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { extractCacheOptions as n, copyForwardUrlOptions as t };
|
|
16
|
+
//# sourceMappingURL=builder-utils-BkXwUT0x.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-utils-BkXwUT0x.js","names":[],"sources":["../../../src/-private/builder-utils.ts"],"sourcesContent":["import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core/types/request';\n\nimport type { UrlOptions } from '../index.ts';\n\nexport function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void {\n if ('host' in options) {\n urlOptions.host = options.host;\n }\n if ('namespace' in options) {\n urlOptions.namespace = options.namespace;\n }\n if ('resourcePath' in options) {\n urlOptions.resourcePath = options.resourcePath;\n }\n}\n\nexport function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions {\n const cacheOptions: CacheOptions = {};\n if ('reload' in options) {\n cacheOptions.reload = options.reload;\n }\n if ('backgroundReload' in options) {\n cacheOptions.backgroundReload = options.backgroundReload;\n }\n return cacheOptions;\n}\n"],"mappings":";AAIA,SAAgB,sBAAsB,YAAwB,SAA0C;CACtG,IAAI,UAAU,SACZ,WAAW,OAAO,QAAQ;CAE5B,IAAI,eAAe,SACjB,WAAW,YAAY,QAAQ;CAEjC,IAAI,kBAAkB,SACpB,WAAW,eAAe,QAAQ;AAEtC;AAEA,SAAgB,oBAAoB,SAAkD;CACpF,MAAM,eAA6B,CAAC;CACpC,IAAI,YAAY,SACd,aAAa,SAAS,QAAQ;CAEhC,IAAI,sBAAsB,SACxB,aAAa,mBAAmB,QAAQ;CAE1C,OAAO;AACT"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from "@warp-drive/core/types/symbols";
|
|
2
2
|
|
|
3
|
+
//#region src/derivations.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
* A derivation for use by {@link ReactiveResource} that joins the given fields
|
|
6
|
+
* with the optional separator (or '' if no separator is provided).
|
|
7
|
+
*
|
|
8
|
+
* Generally you should not need to import and use this function directly.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* {
|
|
12
|
+
* name: 'fullName',
|
|
13
|
+
* kind: 'derived',
|
|
14
|
+
* type: 'concat',
|
|
15
|
+
* options: {
|
|
16
|
+
* fields: ['firstName', 'lastName'],
|
|
17
|
+
* separator: ' ',
|
|
18
|
+
* },
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
20
21
|
const concat = (record, options, _prop) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// SAFETY: we cast internally to a more specific type, for our own use
|
|
25
|
-
// SAFETY: but provide the more general signature to the schema service
|
|
26
|
-
const opts = options;
|
|
27
|
-
return opts.fields.map(field => record[field]).join(opts.separator ?? '');
|
|
22
|
+
if (!options) throw new Error(`options is required`);
|
|
23
|
+
const opts = options;
|
|
24
|
+
return opts.fields.map((field) => record[field]).join(opts.separator ?? "");
|
|
28
25
|
};
|
|
29
|
-
concat[Type] =
|
|
30
|
-
|
|
26
|
+
concat[Type] = "concat";
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { concat };
|
|
30
|
+
//# sourceMappingURL=derivations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivations.js","names":["Type","concat","record","options","_prop","Error","opts","fields","map","field","join","separator"],"sources":["../../../src/derivations.ts"],"sourcesContent":["import type { ReactiveResource } from '@warp-drive/core/reactive';\nimport { Type } from '@warp-drive/core/types/symbols';\n\ninterface ConcatDerivation {\n (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n ): string;\n [Type]: 'concat';\n}\n\n/**\n * A derivation for use by {@link ReactiveResource} that joins the given fields\n * with the optional separator (or '' if no separator is provided).\n *\n * Generally you should not need to import and use this function directly.\n *\n * @example\n * {\n * name: 'fullName',\n * kind: 'derived',\n * type: 'concat',\n * options: {\n * fields: ['firstName', 'lastName'],\n * separator: ' ',\n * },\n * }\n */\nexport const concat: ConcatDerivation = (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n) => {\n if (!options) {\n throw new Error(`options is required`);\n }\n // SAFETY: we cast internally to a more specific type, for our own use\n // SAFETY: but provide the more general signature to the schema service\n const opts = options as { fields: string[]; separator?: string };\n return opts.fields.map((field) => record[field]).join(opts.separator ?? '');\n};\nconcat[Type] = 'concat';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,MAAaC,UACXC,QACAC,SACAC,UACG;CACH,IAAI,CAACD,SACH,MAAM,IAAIE,MAAM,qBAAqB;CAIvC,MAAMC,OAAOH;CACb,OAAOG,KAAKC,OAAOC,KAAKC,UAAUP,OAAOO,MAAM,CAAC,CAACC,KAAKJ,KAAKK,aAAa,EAAE;AAC5E;AACAV,OAAOD,QAAQ"}
|
|
@@ -1,305 +1,264 @@
|
|
|
1
|
+
//#region src/-private/handlers/auto-compress.ts
|
|
1
2
|
function isCompressibleMethod(method) {
|
|
2
|
-
|
|
3
|
+
return method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE";
|
|
3
4
|
}
|
|
4
|
-
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
* Whether the browser supports `ReadableStream` as a request body
|
|
7
|
+
* in a `POST` request.
|
|
8
|
+
*
|
|
9
|
+
* @group Constants
|
|
10
|
+
*/
|
|
11
11
|
const SupportsRequestStreams = (() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return duplexAccessed && !hasContentType;
|
|
12
|
+
let duplexAccessed = false;
|
|
13
|
+
const hasContentType = new Request("", {
|
|
14
|
+
body: new ReadableStream(),
|
|
15
|
+
method: "POST",
|
|
16
|
+
get duplex() {
|
|
17
|
+
duplexAccessed = true;
|
|
18
|
+
return "half";
|
|
19
|
+
}
|
|
20
|
+
}).headers.has("Content-Type");
|
|
21
|
+
return duplexAccessed && !hasContentType;
|
|
23
22
|
})();
|
|
24
|
-
|
|
25
23
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
* Options for configuring the AutoCompress handler.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
30
27
|
const DEFAULT_CONSTRAINTS = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
Blob: 1e3,
|
|
29
|
+
ArrayBuffer: 1e3,
|
|
30
|
+
TypedArray: 1e3,
|
|
31
|
+
DataView: 1e3,
|
|
32
|
+
String: 1e3
|
|
36
33
|
};
|
|
37
34
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
38
|
-
|
|
39
35
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const req = Object.assign({}, request, {
|
|
107
|
-
body: stream,
|
|
108
|
-
headers
|
|
109
|
-
});
|
|
110
|
-
if (SupportsRequestStreams) {
|
|
111
|
-
// @ts-expect-error untyped
|
|
112
|
-
req.duplex = 'half';
|
|
113
|
-
}
|
|
114
|
-
return next(req);
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
// For non-chromium browsers, we have to "pull" the stream to get the final
|
|
118
|
-
// bytes and supply the final byte array as the new request body.
|
|
119
|
-
//
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// we need to pull the stream to get the final bytes
|
|
123
|
-
const resp = new Response(stream);
|
|
124
|
-
return resp.blob().then(blob => {
|
|
125
|
-
const req = Object.assign({}, request, {
|
|
126
|
-
body: blob,
|
|
127
|
-
headers
|
|
128
|
-
});
|
|
129
|
-
return next(req);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
36
|
+
* A request handler that automatically compresses the request body
|
|
37
|
+
* if the request body is a string, array buffer, blob, or form data.
|
|
38
|
+
*
|
|
39
|
+
* This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
40
|
+
*
|
|
41
|
+
* The compression format as well as the kinds of data to compress can be
|
|
42
|
+
* configured using the `format` and `constraints` options.
|
|
43
|
+
*
|
|
44
|
+
* ```diff
|
|
45
|
+
* +import { AutoCompress } from '@ember-data/request-utils/handlers';
|
|
46
|
+
* import Fetch from '@ember-data/request/fetch';
|
|
47
|
+
* import RequestManager from '@ember-data/request';
|
|
48
|
+
* import Store from '@ember-data/store';
|
|
49
|
+
*
|
|
50
|
+
* class AppStore extends Store {
|
|
51
|
+
* requestManager = new RequestManager()
|
|
52
|
+
* .use([
|
|
53
|
+
* + new AutoCompress(),
|
|
54
|
+
* Fetch
|
|
55
|
+
* ]);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @group Handlers
|
|
60
|
+
* @public
|
|
61
|
+
* @since 5.5.0
|
|
62
|
+
*/
|
|
63
|
+
var AutoCompress = class {
|
|
64
|
+
/**
|
|
65
|
+
* The resolved options this handler was configured with, with all
|
|
66
|
+
* defaults (including `constraints` defaults) applied.
|
|
67
|
+
*/
|
|
68
|
+
constructor(options = {}) {
|
|
69
|
+
const opts = {
|
|
70
|
+
format: options.format ?? "gzip",
|
|
71
|
+
constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),
|
|
72
|
+
allowStreaming: options.allowStreaming ?? false,
|
|
73
|
+
forceStreaming: options.forceStreaming ?? false
|
|
74
|
+
};
|
|
75
|
+
this.options = opts;
|
|
76
|
+
}
|
|
77
|
+
request({ request }, next) {
|
|
78
|
+
const { constraints } = this.options;
|
|
79
|
+
const { body } = request;
|
|
80
|
+
if (!(!!body && isCompressibleMethod(request.method) && request.options?.compress !== false && (request.options?.compress ? true : typeof body === "string" || body instanceof String ? canCompress("String", constraints, body.length) : body instanceof Blob ? canCompress("Blob", constraints, body.size) : body instanceof ArrayBuffer ? canCompress("ArrayBuffer", constraints, body.byteLength) : body instanceof DataView ? canCompress("DataView", constraints, body.byteLength) : body instanceof TypedArray ? canCompress("TypedArray", constraints, body.byteLength) : false))) return next(request);
|
|
81
|
+
const stream = new Response(request.body).body?.pipeThrough(new CompressionStream(this.options.format));
|
|
82
|
+
const headers = new Headers(request.headers);
|
|
83
|
+
headers.set("Content-Encoding", encodingForFormat(this.options.format));
|
|
84
|
+
const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;
|
|
85
|
+
const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;
|
|
86
|
+
if (forceStreaming || SupportsRequestStreams && allowStreaming) {
|
|
87
|
+
const req = Object.assign({}, request, {
|
|
88
|
+
body: stream,
|
|
89
|
+
headers
|
|
90
|
+
});
|
|
91
|
+
if (SupportsRequestStreams) req.duplex = "half";
|
|
92
|
+
return next(req);
|
|
93
|
+
}
|
|
94
|
+
return new Response(stream).blob().then((blob) => {
|
|
95
|
+
return next(Object.assign({}, request, {
|
|
96
|
+
body: blob,
|
|
97
|
+
headers
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
133
102
|
function canCompress(type, constraints, size) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return size >= constraints[type];
|
|
103
|
+
if (constraints[type] === 0) return true;
|
|
104
|
+
if (constraints[type] === -1) return false;
|
|
105
|
+
return size >= constraints[type];
|
|
138
106
|
}
|
|
139
107
|
function encodingForFormat(format) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// @ts-expect-error - unreachable code is reachable in production
|
|
147
|
-
return format;
|
|
148
|
-
}
|
|
108
|
+
switch (format) {
|
|
109
|
+
case "gzip":
|
|
110
|
+
case "deflate":
|
|
111
|
+
case "deflate-raw": return format;
|
|
112
|
+
default: return format;
|
|
113
|
+
}
|
|
149
114
|
}
|
|
150
115
|
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/-private/handlers/gated.ts
|
|
151
118
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
119
|
+
* If CheckFn returns true, the wrapped handler will be used.
|
|
120
|
+
* If CheckFn returns false, the wrapped handler will be skipped.
|
|
121
|
+
*/
|
|
156
122
|
/**
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
123
|
+
*
|
|
124
|
+
* @group Handlers
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
var Gate = class {
|
|
128
|
+
/**
|
|
129
|
+
* The wrapped handler to invoke when {@link Gate.checkFn | checkFn} returns `true`.
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* The predicate used to decide whether {@link Gate.handler | handler} should run for a given request.
|
|
133
|
+
*/
|
|
134
|
+
constructor(handler, checkFn) {
|
|
135
|
+
this.handler = handler;
|
|
136
|
+
this.checkFn = checkFn;
|
|
137
|
+
}
|
|
138
|
+
request(context, next) {
|
|
139
|
+
if (this.checkFn(context)) return this.handler.request(context, next);
|
|
140
|
+
return next(context.request);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
173
143
|
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/-private/handlers/meta-doc.ts
|
|
174
146
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const MetaDocHandler = {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return processResponse(response);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
};
|
|
147
|
+
* MetaDocHandler processes requests that are marked as meta requests.
|
|
148
|
+
*
|
|
149
|
+
* It treats the response body as "entirely meta" transforming
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* {
|
|
153
|
+
* some: "key",
|
|
154
|
+
* another: "thing"
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* into
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* {
|
|
162
|
+
* meta: {
|
|
163
|
+
* some: "key",
|
|
164
|
+
* another: "thing"
|
|
165
|
+
* }
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* To activate this handler, a request should specify
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* options.isMetaRequest = true
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* For instance
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* store.request({
|
|
179
|
+
* url: '/example',
|
|
180
|
+
* options: {
|
|
181
|
+
* isMetaRequest: true
|
|
182
|
+
* }
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* Errors are not processed by this handler, so if the request fails and the error response
|
|
187
|
+
* is not in {json:api} format additional processing may be needed.
|
|
188
|
+
*
|
|
189
|
+
* @group Handlers
|
|
190
|
+
*/
|
|
191
|
+
const MetaDocHandler = { request(context, next) {
|
|
192
|
+
if (!context.request.options?.isMetaRequest) return next(context.request);
|
|
193
|
+
return next(context.request).then((response) => {
|
|
194
|
+
return processResponse(response);
|
|
195
|
+
});
|
|
196
|
+
} };
|
|
229
197
|
function processResponse(response) {
|
|
230
|
-
|
|
231
|
-
meta: response.content
|
|
232
|
-
};
|
|
198
|
+
return { meta: response.content };
|
|
233
199
|
}
|
|
234
|
-
if (typeof FastBoot === 'undefined') {
|
|
235
|
-
globalThis.addEventListener('beforeunload', function () {
|
|
236
|
-
sessionStorage.setItem('tab-closed', 'true');
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function getTabId() {
|
|
240
|
-
if (typeof sessionStorage === 'undefined') {
|
|
241
|
-
return crypto.randomUUID();
|
|
242
|
-
}
|
|
243
|
-
const tabId = sessionStorage.getItem('tab-id');
|
|
244
|
-
if (tabId) {
|
|
245
|
-
const tabClosed = sessionStorage.getItem('tab-closed');
|
|
246
|
-
if (tabClosed === 'true') {
|
|
247
|
-
return tabId;
|
|
248
|
-
}
|
|
249
200
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/-private/handlers/utils.ts
|
|
203
|
+
if (typeof FastBoot === "undefined") globalThis.addEventListener("beforeunload", function() {
|
|
204
|
+
sessionStorage.setItem("tab-closed", "true");
|
|
205
|
+
});
|
|
206
|
+
function getTabId() {
|
|
207
|
+
if (typeof sessionStorage === "undefined") return crypto.randomUUID();
|
|
208
|
+
const tabId = sessionStorage.getItem("tab-id");
|
|
209
|
+
if (tabId) {
|
|
210
|
+
if (sessionStorage.getItem("tab-closed") === "true") return tabId;
|
|
211
|
+
}
|
|
212
|
+
const newTabId = crypto.randomUUID();
|
|
213
|
+
sessionStorage.setItem("tab-id", newTabId);
|
|
214
|
+
return newTabId;
|
|
255
215
|
}
|
|
256
|
-
|
|
257
216
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
217
|
+
* A unique identifier for the current browser tab
|
|
218
|
+
* useful for observability/tracing and deduping
|
|
219
|
+
* across multiple tabs.
|
|
220
|
+
*
|
|
221
|
+
* @group Constants
|
|
222
|
+
*/
|
|
264
223
|
const TAB_ID = getTabId();
|
|
265
224
|
/**
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const TAB_ASSIGNED = Math.floor(Date.now() /
|
|
271
|
-
|
|
225
|
+
* The epoch seconds at which the tab id was generated
|
|
226
|
+
*
|
|
227
|
+
* @group Constants
|
|
228
|
+
*/
|
|
229
|
+
const TAB_ASSIGNED = Math.floor(Date.now() / 1e3);
|
|
272
230
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
231
|
+
* Adds the `X-Amzn-Trace-Id` header to support observability
|
|
232
|
+
* tooling around request routing.
|
|
233
|
+
*
|
|
234
|
+
* This makes use of the {@link TAB_ID} and {@link TAB_ASSIGNED}
|
|
235
|
+
* to enable tracking the browser tab of origin across multiple requests.
|
|
236
|
+
*
|
|
237
|
+
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
238
|
+
*
|
|
239
|
+
* @group Utility Functions
|
|
240
|
+
*/
|
|
283
241
|
function addTraceHeader(headers) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
242
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
243
|
+
headers.set("X-Amzn-Trace-Id", `Root=1-${now}-${crypto.randomUUID()};TabId=1-${TAB_ASSIGNED}-${TAB_ID}`);
|
|
244
|
+
return headers;
|
|
287
245
|
}
|
|
288
|
-
|
|
289
246
|
/**
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
247
|
+
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
248
|
+
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
249
|
+
*
|
|
250
|
+
* @group Constants
|
|
251
|
+
*/
|
|
295
252
|
const MAX_URL_LENGTH = 8192;
|
|
296
|
-
|
|
297
253
|
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
254
|
+
* This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
|
|
255
|
+
*
|
|
256
|
+
* See also {@link MAX_URL_LENGTH}
|
|
257
|
+
*
|
|
258
|
+
* @group Utility Functions
|
|
259
|
+
*/
|
|
304
260
|
function assertInvalidUrlLength(url) {}
|
|
305
|
-
|
|
261
|
+
|
|
262
|
+
//#endregion
|
|
263
|
+
export { AutoCompress, Gate, MAX_URL_LENGTH, MetaDocHandler, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
|
|
264
|
+
//# sourceMappingURL=handlers.js.map
|