@warp-drive-mirror/utilities 5.7.0-alpha.24 → 5.7.0-alpha.25
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/declarations/-private/active-record/query.d.ts +1 -1
- package/declarations/-private/handlers/auto-compress.d.ts +7 -1
- package/declarations/-private/handlers/gated.d.ts +1 -0
- package/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/declarations/-private/handlers/utils.d.ts +9 -0
- package/declarations/-private/rest/query.d.ts +1 -1
- package/declarations/handlers.d.ts +1 -0
- package/dist/handlers.js +80 -2
- package/package.json +4 -4
|
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
|
|
|
49
49
|
* @param query
|
|
50
50
|
* @param options
|
|
51
51
|
*/
|
|
52
|
-
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>>;
|
|
53
53
|
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Future, Handler, NextFn } from "@warp-drive-mirror/core/request";
|
|
2
2
|
import type { RequestContext } from "@warp-drive-mirror/core/types/request";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the browser supports `ReadableStream` as a request body
|
|
5
|
+
* in a `POST` request.
|
|
6
|
+
*
|
|
7
|
+
* @group Constants
|
|
8
|
+
*/
|
|
3
9
|
export declare const SupportsRequestStreams: boolean;
|
|
4
10
|
interface Constraints {
|
|
5
11
|
/**
|
|
@@ -138,7 +144,7 @@ interface CompressionOptions {
|
|
|
138
144
|
* }
|
|
139
145
|
* ```
|
|
140
146
|
*
|
|
141
|
-
* @
|
|
147
|
+
* @group Handlers
|
|
142
148
|
* @public
|
|
143
149
|
* @since 5.5.0
|
|
144
150
|
*/
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Handler } from "@warp-drive-mirror/core/request";
|
|
2
|
+
/**
|
|
3
|
+
* MetaDocHandler processes requests that are marked as meta requests.
|
|
4
|
+
*
|
|
5
|
+
* It treats the response body as "entirely meta" transforming
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* {
|
|
9
|
+
* some: "key",
|
|
10
|
+
* another: "thing"
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* into
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* {
|
|
18
|
+
* meta: {
|
|
19
|
+
* some: "key",
|
|
20
|
+
* another: "thing"
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* To activate this handler, a request should specify
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* options.isMetaRequest = true
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* For instance
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* store.request({
|
|
35
|
+
* url: '/example',
|
|
36
|
+
* options: {
|
|
37
|
+
* isMetaRequest: true
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Errors are not processed by this handler, so if the request fails and the error response
|
|
43
|
+
* is not in {JSON:API} format additional processing may be needed.
|
|
44
|
+
*
|
|
45
|
+
* @group Handlers
|
|
46
|
+
*/
|
|
47
|
+
export declare const MetaDocHandler: Handler;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
* A unique identifier for the current browser tab
|
|
3
3
|
* useful for observability/tracing and deduping
|
|
4
4
|
* across multiple tabs.
|
|
5
|
+
*
|
|
6
|
+
* @group Constants
|
|
5
7
|
*/
|
|
6
8
|
export declare const TAB_ID: string;
|
|
7
9
|
/**
|
|
8
10
|
* The epoch seconds at which the tab id was generated
|
|
11
|
+
*
|
|
12
|
+
* @group Constants
|
|
9
13
|
*/
|
|
10
14
|
export declare const TAB_ASSIGNED: number;
|
|
11
15
|
/**
|
|
@@ -16,17 +20,22 @@ export declare const TAB_ASSIGNED: number;
|
|
|
16
20
|
* to enable tracking the browser tab of origin across multiple requests.
|
|
17
21
|
*
|
|
18
22
|
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
23
|
+
*
|
|
24
|
+
* @group Utility Functions
|
|
19
25
|
*/
|
|
20
26
|
export declare function addTraceHeader(headers: Headers): Headers;
|
|
21
27
|
/**
|
|
22
28
|
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
23
29
|
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
24
30
|
*
|
|
31
|
+
* @group Constants
|
|
25
32
|
*/
|
|
26
33
|
export declare const MAX_URL_LENGTH = 8192;
|
|
27
34
|
/**
|
|
28
35
|
* This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
|
|
29
36
|
*
|
|
30
37
|
* See also {@link MAX_URL_LENGTH}
|
|
38
|
+
*
|
|
39
|
+
* @group Utility Functions
|
|
31
40
|
*/
|
|
32
41
|
export declare function assertInvalidUrlLength(url: string | undefined): void;
|
|
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
|
|
|
49
49
|
* @param query
|
|
50
50
|
* @param options
|
|
51
51
|
*/
|
|
52
|
-
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>>;
|
|
53
53
|
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -6,4 +6,5 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { AutoCompress, SupportsRequestStreams } from "./-private/handlers/auto-compress.js";
|
|
8
8
|
export { Gate } from "./-private/handlers/gated.js";
|
|
9
|
+
export { MetaDocHandler } from "./-private/handlers/meta-doc.js";
|
|
9
10
|
export { addTraceHeader, TAB_ASSIGNED, TAB_ID, assertInvalidUrlLength, MAX_URL_LENGTH } from "./-private/handlers/utils.js";
|
package/dist/handlers.js
CHANGED
|
@@ -2,6 +2,13 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
2
2
|
function isCompressibleMethod(method) {
|
|
3
3
|
return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether the browser supports `ReadableStream` as a request body
|
|
8
|
+
* in a `POST` request.
|
|
9
|
+
*
|
|
10
|
+
* @group Constants
|
|
11
|
+
*/
|
|
5
12
|
const SupportsRequestStreams = (() => {
|
|
6
13
|
let duplexAccessed = false;
|
|
7
14
|
const hasContentType = new Request('', {
|
|
@@ -54,7 +61,7 @@ const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
|
|
|
54
61
|
* }
|
|
55
62
|
* ```
|
|
56
63
|
*
|
|
57
|
-
* @
|
|
64
|
+
* @group Handlers
|
|
58
65
|
* @public
|
|
59
66
|
* @since 5.5.0
|
|
60
67
|
*/
|
|
@@ -154,6 +161,7 @@ function encodingForFormat(format) {
|
|
|
154
161
|
|
|
155
162
|
/**
|
|
156
163
|
*
|
|
164
|
+
* @group Handlers
|
|
157
165
|
* @public
|
|
158
166
|
*/
|
|
159
167
|
class Gate {
|
|
@@ -168,6 +176,67 @@ class Gate {
|
|
|
168
176
|
return next(context.request);
|
|
169
177
|
}
|
|
170
178
|
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* MetaDocHandler processes requests that are marked as meta requests.
|
|
182
|
+
*
|
|
183
|
+
* It treats the response body as "entirely meta" transforming
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* {
|
|
187
|
+
* some: "key",
|
|
188
|
+
* another: "thing"
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* into
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* {
|
|
196
|
+
* meta: {
|
|
197
|
+
* some: "key",
|
|
198
|
+
* another: "thing"
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* To activate this handler, a request should specify
|
|
204
|
+
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* options.isMetaRequest = true
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* For instance
|
|
210
|
+
*
|
|
211
|
+
* ```ts
|
|
212
|
+
* store.request({
|
|
213
|
+
* url: '/example',
|
|
214
|
+
* options: {
|
|
215
|
+
* isMetaRequest: true
|
|
216
|
+
* }
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* Errors are not processed by this handler, so if the request fails and the error response
|
|
221
|
+
* is not in {JSON:API} format additional processing may be needed.
|
|
222
|
+
*
|
|
223
|
+
* @group Handlers
|
|
224
|
+
*/
|
|
225
|
+
const MetaDocHandler = {
|
|
226
|
+
request(context, next) {
|
|
227
|
+
if (!context.request.options?.isMetaRequest) {
|
|
228
|
+
return next(context.request);
|
|
229
|
+
}
|
|
230
|
+
return next(context.request).then(response => {
|
|
231
|
+
return processResponse(response);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
function processResponse(response) {
|
|
236
|
+
return {
|
|
237
|
+
meta: response.content
|
|
238
|
+
};
|
|
239
|
+
}
|
|
171
240
|
if (typeof FastBoot === 'undefined') {
|
|
172
241
|
globalThis.addEventListener('beforeunload', function () {
|
|
173
242
|
sessionStorage.setItem('tab-closed', 'true');
|
|
@@ -195,10 +264,14 @@ function getTabId() {
|
|
|
195
264
|
* A unique identifier for the current browser tab
|
|
196
265
|
* useful for observability/tracing and deduping
|
|
197
266
|
* across multiple tabs.
|
|
267
|
+
*
|
|
268
|
+
* @group Constants
|
|
198
269
|
*/
|
|
199
270
|
const TAB_ID = getTabId();
|
|
200
271
|
/**
|
|
201
272
|
* The epoch seconds at which the tab id was generated
|
|
273
|
+
*
|
|
274
|
+
* @group Constants
|
|
202
275
|
*/
|
|
203
276
|
const TAB_ASSIGNED = Math.floor(Date.now() / 1000);
|
|
204
277
|
|
|
@@ -210,6 +283,8 @@ const TAB_ASSIGNED = Math.floor(Date.now() / 1000);
|
|
|
210
283
|
* to enable tracking the browser tab of origin across multiple requests.
|
|
211
284
|
*
|
|
212
285
|
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
286
|
+
*
|
|
287
|
+
* @group Utility Functions
|
|
213
288
|
*/
|
|
214
289
|
function addTraceHeader(headers) {
|
|
215
290
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -221,6 +296,7 @@ function addTraceHeader(headers) {
|
|
|
221
296
|
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
222
297
|
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
223
298
|
*
|
|
299
|
+
* @group Constants
|
|
224
300
|
*/
|
|
225
301
|
const MAX_URL_LENGTH = 8192;
|
|
226
302
|
|
|
@@ -228,6 +304,8 @@ const MAX_URL_LENGTH = 8192;
|
|
|
228
304
|
* This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
|
|
229
305
|
*
|
|
230
306
|
* See also {@link MAX_URL_LENGTH}
|
|
307
|
+
*
|
|
308
|
+
* @group Utility Functions
|
|
231
309
|
*/
|
|
232
310
|
function assertInvalidUrlLength(url) {
|
|
233
311
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
@@ -236,4 +314,4 @@ function assertInvalidUrlLength(url) {
|
|
|
236
314
|
}
|
|
237
315
|
})(!url || url.length <= MAX_URL_LENGTH) : {};
|
|
238
316
|
}
|
|
239
|
-
export { AutoCompress, Gate, MAX_URL_LENGTH, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
|
|
317
|
+
export { AutoCompress, Gate, MAX_URL_LENGTH, MetaDocHandler, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive-mirror/utilities",
|
|
3
|
-
"version": "5.7.0-alpha.
|
|
3
|
+
"version": "5.7.0-alpha.25",
|
|
4
4
|
"description": "Utilities package for WarpDrive | Things your app might find useful",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@warp-drive-mirror/core": "5.7.0-alpha.
|
|
39
|
+
"@warp-drive-mirror/core": "5.7.0-alpha.25"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@embroider/macros": "^1.16.12"
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@babel/core": "^7.26.10",
|
|
46
46
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
47
47
|
"@babel/preset-typescript": "^7.27.0",
|
|
48
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
49
|
-
"@warp-drive-mirror/core": "5.7.0-alpha.
|
|
48
|
+
"@warp-drive/internal-config": "5.7.0-alpha.25",
|
|
49
|
+
"@warp-drive-mirror/core": "5.7.0-alpha.25",
|
|
50
50
|
"decorator-transforms": "^2.3.0",
|
|
51
51
|
"expect-type": "^1.2.1",
|
|
52
52
|
"typescript": "^5.8.3",
|