@ember-data-mirror/request-utils 5.6.0-alpha.3 → 5.6.0-alpha.4
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/dist/deprecation-support.js +2 -2
- package/dist/handlers.js +0 -6
- package/dist/handlers.js.map +1 -1
- package/dist/index.js +9 -35
- package/dist/index.js.map +1 -1
- package/dist/{inflect-CwI_k2it.js → inflect-SV-gOUrZ.js} +1 -39
- package/dist/inflect-SV-gOUrZ.js.map +1 -0
- package/dist/string.js +2 -2
- package/dist/{transform-1PDozfHr.js → transform-BixPrO0I.js} +0 -19
- package/dist/transform-BixPrO0I.js.map +1 -0
- package/package.json +7 -10
- package/unstable-preview-types/-private/handlers/auto-compress.d.ts +0 -14
- package/unstable-preview-types/-private/handlers/auto-compress.d.ts.map +1 -1
- package/unstable-preview-types/-private/string/inflect.d.ts +0 -33
- package/unstable-preview-types/-private/string/inflect.d.ts.map +1 -1
- package/unstable-preview-types/-private/string/transform.d.ts +0 -15
- package/unstable-preview-types/-private/string/transform.d.ts.map +1 -1
- package/unstable-preview-types/handlers.d.ts +1 -2
- package/unstable-preview-types/handlers.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +10 -45
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/unstable-preview-types/string.d.ts +1 -2
- package/unstable-preview-types/string.d.ts.map +1 -1
- package/dist/inflect-CwI_k2it.js.map +0 -1
- package/dist/transform-1PDozfHr.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
3
|
-
import { f as defaultRules, b as plural, a as singular, i as irregular, u as uncountable } from "./inflect-
|
|
4
|
-
import "./transform-
|
|
3
|
+
import { f as defaultRules, b as plural, a as singular, i as irregular, u as uncountable } from "./inflect-SV-gOUrZ.js";
|
|
4
|
+
import "./transform-BixPrO0I.js";
|
|
5
5
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_EMBER_INFLECTOR)) {
|
|
6
6
|
if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {
|
|
7
7
|
const Inflector = importSync('ember-inflector').default;
|
package/dist/handlers.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @ember-data-mirror/request-utils/handlers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
function isCompressibleMethod(method) {
|
|
6
2
|
return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
|
|
7
3
|
}
|
|
@@ -22,7 +18,6 @@ const SupportsRequestStreams = (() => {
|
|
|
22
18
|
/**
|
|
23
19
|
* Options for configuring the AutoCompress handler.
|
|
24
20
|
*
|
|
25
|
-
* @typedoc
|
|
26
21
|
*/
|
|
27
22
|
|
|
28
23
|
const DEFAULT_CONSTRAINTS = {
|
|
@@ -59,7 +54,6 @@ const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
|
|
|
59
54
|
* ```
|
|
60
55
|
*
|
|
61
56
|
* @class AutoCompress
|
|
62
|
-
* @extends Handler
|
|
63
57
|
* @public
|
|
64
58
|
* @since 5.5.0
|
|
65
59
|
*/
|
package/dist/handlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sources":["../src/-private/handlers/auto-compress.ts"],"sourcesContent":["/**\n * @module @ember-data-mirror/request-utils/handlers\n */\nimport type { Future, Handler, NextFn, RequestContext } from '@ember-data-mirror/request';\nimport type { HTTPMethod } from '@warp-drive-mirror/core-types/request';\n\nfunction isCompressibleMethod(method?: HTTPMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';\n}\n\nexport const SupportsRequestStreams = (() => {\n let duplexAccessed = false;\n\n const hasContentType = new Request('', {\n body: new ReadableStream(),\n method: 'POST',\n // @ts-expect-error untyped\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n\n return duplexAccessed && !hasContentType;\n})();\n\ninterface Constraints {\n /**\n * The minimum size at which to compress blobs\n *\n * @default 1000\n * @typedoc\n */\n Blob?: number;\n /**\n * The minimum size at which to compress array buffers\n *\n * @default 1000\n * @typedoc\n */\n ArrayBuffer?: number;\n /**\n * The minimum size at which to compress typed arrays\n *\n * @default 1000\n * @typedoc\n */\n TypedArray?: number;\n /**\n * The minimum size at which to compress data views\n *\n * @default 1000\n * @typedoc\n */\n DataView?: number;\n /**\n * The minimum size at which to compress strings\n *\n * @default 1000\n * @typedoc\n */\n String?: number;\n}\n\n/**\n * Options for configuring the AutoCompress handler.\n *\n * @typedoc\n */\ninterface CompressionOptions {\n /**\n * The compression format to use. Must be a valid\n * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The default is `gzip`.\n *\n * @typedoc\n */\n format?: CompressionFormat;\n\n /**\n * Some browsers support `ReadableStream` as a request body. This option\n * enables passing the compression stream as the request body instead of\n * the final compressed body when the browser supports doing so.\n *\n * This comes with several caveats:\n *\n * - the request will be put into `duplex: 'half'` mode. This should be\n * transparent to you, but it is worth noting.\n * - the request mode cannot be `no-cors` as requests with a `ReadableStream`\n * have no content length and thus are a new form of request that triggers\n * cors requirements and a preflight request.\n * - http/1.x is not supported.\n *\n * For additional reading about the restrictions of using `ReadableStream`\n * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)\n *\n * Streaming can be enabled per-request in browsers which support it by\n * setting `request.options.allowStreaming` to `true`.\n *\n * Streaming can be forced even when the browser does not support it by setting\n * `request.options.forceStreaming` to `true`. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n * @typedoc\n */\n allowStreaming?: boolean;\n\n /**\n * If `true`, the request will be forced into streaming mode even\n * if the browser does not support it. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n * @typedoc\n */\n forceStreaming?: boolean;\n\n /**\n * The constraints for the request body. This is used to determine\n * whether to compress the request body or not.\n *\n * The defaults are:\n *\n * ```ts\n * {\n * Blob: 1000, // blob.size\n * ArrayBuffer: 1000, // buffer.byteLength\n * TypedArray: 1000, // array.byteLength\n * DataView: 1000, // view.byteLength\n * String: 1000, // string.length\n * }\n * ```\n *\n * The following body types are never compressed unless explicitly\n * configured by the request:\n * - `FormData`\n * - `URLSearchParams`\n * - `ReadableStream`\n *\n * A request.options.compress value of `false` will disable\n * compression for a request body of any type. While a value of\n * `true` will enable compression for the request.\n *\n * An undefined value will use the default, a value of `0` will\n * enable compression for all values, and a value of `-1` will\n * disable compression.\n *\n * @typedoc\n */\n constraints?: Constraints;\n}\n\nconst DEFAULT_CONSTRAINTS = {\n Blob: 1000,\n ArrayBuffer: 1000,\n TypedArray: 1000,\n DataView: 1000,\n String: 1000,\n};\nconst TypedArray = Object.getPrototypeOf(Uint8Array.prototype) as typeof Uint8Array;\n\n/**\n * A request handler that automatically compresses the request body\n * if the request body is a string, array buffer, blob, or form data.\n *\n * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The compression format as well as the kinds of data to compress can be\n * configured using the `format` and `constraints` options.\n *\n * ```diff\n * +import { AutoCompress } from '@ember-data-mirror/request-utils/handlers';\n * import Fetch from '@ember-data-mirror/request/fetch';\n * import RequestManager from '@ember-data-mirror/request';\n * import Store from '@ember-data-mirror/store';\n *\n * class AppStore extends Store {\n * requestManager = new RequestManager()\n * .use([\n * + new AutoCompress(),\n * Fetch\n * ]);\n * }\n * ```\n *\n * @class AutoCompress\n * @extends Handler\n * @public\n * @since 5.5.0\n */\nexport class AutoCompress implements Handler {\n declare options: Required<CompressionOptions> & { constraints: Required<Constraints> };\n\n constructor(options: CompressionOptions = {}) {\n const opts = {\n format: options.format ?? 'gzip',\n constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),\n allowStreaming: options.allowStreaming ?? false,\n forceStreaming: options.forceStreaming ?? false,\n };\n this.options = opts;\n }\n\n request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T> {\n const { constraints } = this.options;\n const { body } = request;\n\n const shouldCompress =\n isCompressibleMethod(request.method) &&\n request.options?.compress !== false &&\n // prettier-ignore\n (request.options?.compress ? true\n : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length)\n : body instanceof Blob ? canCompress('Blob', constraints, body.size)\n : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength)\n : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength)\n : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength)\n : false);\n\n if (!shouldCompress) return next(request);\n\n // A convenient way to convert all of the supported body types to a readable\n // stream is to use a `Response` object body\n const response = new Response(request.body);\n const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));\n const headers = new Headers(request.headers);\n headers.set('Content-Encoding', encodingForFormat(this.options.format));\n\n //\n // For browsers that support it, `fetch` can receive a `ReadableStream` as\n // the body, so all we need to do is to create a new `ReadableStream` and\n // compress it on the fly\n //\n const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;\n const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;\n if (forceStreaming || (SupportsRequestStreams && allowStreaming)) {\n const req = Object.assign({}, request, {\n body: stream,\n });\n if (SupportsRequestStreams) {\n // @ts-expect-error untyped\n req.duplex = 'half';\n }\n\n return next(req);\n\n //\n // For non-chromium browsers, we have to \"pull\" the stream to get the final\n // bytes and supply the final byte array as the new request body.\n //\n } else {\n // we need to pull the stream to get the final bytes\n const resp = new Response(stream);\n return resp.blob().then((blob) => {\n const req = Object.assign({}, request, {\n body: blob,\n headers,\n });\n return next(req);\n }) as Promise<T>;\n }\n }\n}\n\nfunction canCompress(type: keyof Constraints, constraints: Required<Constraints>, size: number): boolean {\n // if we have a value of 0, we can compress anything\n if (constraints[type] === 0) return true;\n if (constraints[type] === -1) return false;\n return size >= constraints[type];\n}\n\nfunction encodingForFormat(format: CompressionFormat): string {\n switch (format) {\n case 'gzip':\n case 'deflate':\n case 'deflate-raw':\n return format;\n default:\n throw new Error(`Unsupported compression format: ${format as unknown as string}`);\n }\n}\n"],"names":["isCompressibleMethod","method","SupportsRequestStreams","duplexAccessed","hasContentType","Request","body","ReadableStream","duplex","headers","has","DEFAULT_CONSTRAINTS","Blob","ArrayBuffer","TypedArray","DataView","String","Object","getPrototypeOf","Uint8Array","prototype","AutoCompress","constructor","options","opts","format","constraints","assign","allowStreaming","forceStreaming","request","next","shouldCompress","compress","canCompress","length","size","byteLength","response","Response","stream","pipeThrough","CompressionStream","Headers","set","encodingForFormat","req","resp","blob","then","type","Error"],"mappings":"AAAA;AACA;AACA;;AAIA,SAASA,oBAAoBA,CAACC,MAAmB,EAAW;AAC1D,EAAA,OAAOA,MAAM,KAAK,MAAM,IAAIA,MAAM,KAAK,KAAK,IAAIA,MAAM,KAAK,OAAO,IAAIA,MAAM,KAAK,QAAQ;AAC3F;AAEaC,MAAAA,sBAAsB,GAAG,CAAC,MAAM;EAC3C,IAAIC,cAAc,GAAG,KAAK;AAE1B,EAAA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAAC,EAAE,EAAE;AACrCC,IAAAA,IAAI,EAAE,IAAIC,cAAc,EAAE;AAC1BN,IAAAA,MAAM,EAAE,MAAM;AACd;IACA,IAAIO,MAAMA,GAAG;AACXL,MAAAA,cAAc,GAAG,IAAI;AACrB,MAAA,OAAO,MAAM;AACf;AACF,GAAC,CAAC,CAACM,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;EAE9B,OAAOP,cAAc,IAAI,CAACC,cAAc;AAC1C,CAAC;;AAwCD;AACA;AACA;AACA;AACA;;AAsFA,MAAMO,mBAAmB,GAAG;AAC1BC,EAAAA,IAAI,EAAE,IAAI;AACVC,EAAAA,WAAW,EAAE,IAAI;AACjBC,EAAAA,UAAU,EAAE,IAAI;AAChBC,EAAAA,QAAQ,EA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G,OAAO,EAAE;AACrCxB,QAAAA,IAAI,EAAEkC;AACR,OAAC,CAAC;AACF,MAAA,IAAItC,sBAAsB,EAAE;AAC1B;QACA4C,GAAG,CAACtC,MAAM,GAAG,MAAM;AACrB;MAEA,OAAOuB,IAAI,CAACe,GAAG,CAAC;;AAEhB;AACA;AACA;AACA;AACF,KAAC,MAAM;AACL;AACA,MAAA,MAAMC,IAAI,GAAG,IAAIR,QAAQ,CAACC,MAAM,CAAC;MACjC,OAAOO,IAAI,CAACC,IAAI,EAAE,CAACC,IAAI,CAAED,IAAI,IAAK;QAChC,MAAMF,GAAG,GAAG7B,MAAM,CAACU,MAAM,CAAC,EAAE,EAAEG,OAAO,EAAE;AACrCxB,UAAAA,IAAI,EAAE0C,IAAI;AACVvC,UAAAA;AACF,SAAC,CAAC;QACF,OAAOsB,IAAI,CAACe,GAAG,CAAC;AAClB,OAAC,CAAC;AACJ;AACF;AACF;AAEA,SAASZ,WAAWA,CAACgB,IAAuB,EAAExB,WAAkC,EAAEU,IAAY,EAAW;AACvG;EACA,IAAIV,WAAW,CAACwB,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,IAAI;EACxC,IAAIxB,WAAW,CAACwB,IAAI,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK;AAC1C,EAAA,OAAOd,IAAI,IAAIV,WAAW,CAACwB,IAAI,CAAC;AAClC;AAEA,SAASL,iBAAiBA,CAACpB,MAAyB,EAAU;AAC5D,EAAA,QAAQA,MAAM;AACZ,IAAA,KAAK,MAAM;AACX,IAAA,KAAK,SAAS;AACd,IAAA,KAAK,aAAa;AAChB,MAAA,OAAOA,MAAM;AACf,IAAA;AACE,MAAA,MAAM,IAAI0B,KAAK,CAAC,CAAmC1B,gCAAAA,EAAAA,MAAM,EAAuB,CAAC;AACrF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"handlers.js","sources":["../src/-private/handlers/auto-compress.ts"],"sourcesContent":["import type { Future, Handler, NextFn, RequestContext } from '@ember-data-mirror/request';\nimport type { HTTPMethod } from '@warp-drive-mirror/core-types/request';\n\nfunction isCompressibleMethod(method?: HTTPMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';\n}\n\nexport const SupportsRequestStreams = (() => {\n let duplexAccessed = false;\n\n const hasContentType = new Request('', {\n body: new ReadableStream(),\n method: 'POST',\n // @ts-expect-error untyped\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n\n return duplexAccessed && !hasContentType;\n})();\n\ninterface Constraints {\n /**\n * The minimum size at which to compress blobs\n *\n * @default 1000\n */\n Blob?: number;\n /**\n * The minimum size at which to compress array buffers\n *\n * @default 1000\n */\n ArrayBuffer?: number;\n /**\n * The minimum size at which to compress typed arrays\n *\n * @default 1000\n */\n TypedArray?: number;\n /**\n * The minimum size at which to compress data views\n *\n * @default 1000\n */\n DataView?: number;\n /**\n * The minimum size at which to compress strings\n *\n * @default 1000\n */\n String?: number;\n}\n\n/**\n * Options for configuring the AutoCompress handler.\n *\n */\ninterface CompressionOptions {\n /**\n * The compression format to use. Must be a valid\n * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The default is `gzip`.\n *\n */\n format?: CompressionFormat;\n\n /**\n * Some browsers support `ReadableStream` as a request body. This option\n * enables passing the compression stream as the request body instead of\n * the final compressed body when the browser supports doing so.\n *\n * This comes with several caveats:\n *\n * - the request will be put into `duplex: 'half'` mode. This should be\n * transparent to you, but it is worth noting.\n * - the request mode cannot be `no-cors` as requests with a `ReadableStream`\n * have no content length and thus are a new form of request that triggers\n * cors requirements and a preflight request.\n * - http/1.x is not supported.\n *\n * For additional reading about the restrictions of using `ReadableStream`\n * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)\n *\n * Streaming can be enabled per-request in browsers which support it by\n * setting `request.options.allowStreaming` to `true`.\n *\n * Streaming can be forced even when the browser does not support it by setting\n * `request.options.forceStreaming` to `true`. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n allowStreaming?: boolean;\n\n /**\n * If `true`, the request will be forced into streaming mode even\n * if the browser does not support it. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n forceStreaming?: boolean;\n\n /**\n * The constraints for the request body. This is used to determine\n * whether to compress the request body or not.\n *\n * The defaults are:\n *\n * ```ts\n * {\n * Blob: 1000, // blob.size\n * ArrayBuffer: 1000, // buffer.byteLength\n * TypedArray: 1000, // array.byteLength\n * DataView: 1000, // view.byteLength\n * String: 1000, // string.length\n * }\n * ```\n *\n * The following body types are never compressed unless explicitly\n * configured by the request:\n * - `FormData`\n * - `URLSearchParams`\n * - `ReadableStream`\n *\n * A request.options.compress value of `false` will disable\n * compression for a request body of any type. While a value of\n * `true` will enable compression for the request.\n *\n * An undefined value will use the default, a value of `0` will\n * enable compression for all values, and a value of `-1` will\n * disable compression.\n *\n */\n constraints?: Constraints;\n}\n\nconst DEFAULT_CONSTRAINTS = {\n Blob: 1000,\n ArrayBuffer: 1000,\n TypedArray: 1000,\n DataView: 1000,\n String: 1000,\n};\nconst TypedArray = Object.getPrototypeOf(Uint8Array.prototype) as typeof Uint8Array;\n\n/**\n * A request handler that automatically compresses the request body\n * if the request body is a string, array buffer, blob, or form data.\n *\n * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The compression format as well as the kinds of data to compress can be\n * configured using the `format` and `constraints` options.\n *\n * ```diff\n * +import { AutoCompress } from '@ember-data-mirror/request-utils/handlers';\n * import Fetch from '@ember-data-mirror/request/fetch';\n * import RequestManager from '@ember-data-mirror/request';\n * import Store from '@ember-data-mirror/store';\n *\n * class AppStore extends Store {\n * requestManager = new RequestManager()\n * .use([\n * + new AutoCompress(),\n * Fetch\n * ]);\n * }\n * ```\n *\n * @class AutoCompress\n * @public\n * @since 5.5.0\n */\nexport class AutoCompress implements Handler {\n declare options: Required<CompressionOptions> & { constraints: Required<Constraints> };\n\n constructor(options: CompressionOptions = {}) {\n const opts = {\n format: options.format ?? 'gzip',\n constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),\n allowStreaming: options.allowStreaming ?? false,\n forceStreaming: options.forceStreaming ?? false,\n };\n this.options = opts;\n }\n\n request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T> {\n const { constraints } = this.options;\n const { body } = request;\n\n const shouldCompress =\n isCompressibleMethod(request.method) &&\n request.options?.compress !== false &&\n // prettier-ignore\n (request.options?.compress ? true\n : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length)\n : body instanceof Blob ? canCompress('Blob', constraints, body.size)\n : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength)\n : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength)\n : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength)\n : false);\n\n if (!shouldCompress) return next(request);\n\n // A convenient way to convert all of the supported body types to a readable\n // stream is to use a `Response` object body\n const response = new Response(request.body);\n const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));\n const headers = new Headers(request.headers);\n headers.set('Content-Encoding', encodingForFormat(this.options.format));\n\n //\n // For browsers that support it, `fetch` can receive a `ReadableStream` as\n // the body, so all we need to do is to create a new `ReadableStream` and\n // compress it on the fly\n //\n const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;\n const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;\n if (forceStreaming || (SupportsRequestStreams && allowStreaming)) {\n const req = Object.assign({}, request, {\n body: stream,\n });\n if (SupportsRequestStreams) {\n // @ts-expect-error untyped\n req.duplex = 'half';\n }\n\n return next(req);\n\n //\n // For non-chromium browsers, we have to \"pull\" the stream to get the final\n // bytes and supply the final byte array as the new request body.\n //\n } else {\n // we need to pull the stream to get the final bytes\n const resp = new Response(stream);\n return resp.blob().then((blob) => {\n const req = Object.assign({}, request, {\n body: blob,\n headers,\n });\n return next(req);\n }) as Promise<T>;\n }\n }\n}\n\nfunction canCompress(type: keyof Constraints, constraints: Required<Constraints>, size: number): boolean {\n // if we have a value of 0, we can compress anything\n if (constraints[type] === 0) return true;\n if (constraints[type] === -1) return false;\n return size >= constraints[type];\n}\n\nfunction encodingForFormat(format: CompressionFormat): string {\n switch (format) {\n case 'gzip':\n case 'deflate':\n case 'deflate-raw':\n return format;\n default:\n throw new Error(`Unsupported compression format: ${format as unknown as string}`);\n }\n}\n"],"names":["isCompressibleMethod","method","SupportsRequestStreams","duplexAccessed","hasContentType","Request","body","ReadableStream","duplex","headers","has","DEFAULT_CONSTRAINTS","Blob","ArrayBuffer","TypedArray","DataView","String","Object","getPrototypeOf","Uint8Array","prototype","AutoCompress","constructor","options","opts","format","constraints","assign","allowStreaming","forceStreaming","request","next","shouldCompress","compress","canCompress","length","size","byteLength","response","Response","stream","pipeThrough","CompressionStream","Headers","set","encodingForFormat","req","resp","blob","then","type","Error"],"mappings":"AAGA,SAASA,oBAAoBA,CAACC,MAAmB,EAAW;AAC1D,EAAA,OAAOA,MAAM,KAAK,MAAM,IAAIA,MAAM,KAAK,KAAK,IAAIA,MAAM,KAAK,OAAO,IAAIA,MAAM,KAAK,QAAQ;AAC3F;AAEaC,MAAAA,sBAAsB,GAAG,CAAC,MAAM;EAC3C,IAAIC,cAAc,GAAG,KAAK;AAE1B,EAAA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAAC,EAAE,EAAE;AACrCC,IAAAA,IAAI,EAAE,IAAIC,cAAc,EAAE;AAC1BN,IAAAA,MAAM,EAAE,MAAM;AACd;IACA,IAAIO,MAAMA,GAAG;AACXL,MAAAA,cAAc,GAAG,IAAI;AACrB,MAAA,OAAO,MAAM;AACf;AACF,GAAC,CAAC,CAACM,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;EAE9B,OAAOP,cAAc,IAAI,CAACC,cAAc;AAC1C,CAAC;;AAmCD;AACA;AACA;AACA;;AAkFA,MAAMO,mBAAmB,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rF;AACF;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';
|
|
3
|
-
import { L as LRUCache } from "./transform-
|
|
3
|
+
import { L as LRUCache } from "./transform-BixPrO0I.js";
|
|
4
4
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -38,8 +38,7 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
38
38
|
* // Note: options will also include other request options like headers, method, etc.
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
|
-
* @module
|
|
42
|
-
* @main @ember-data-mirror/request-utils
|
|
41
|
+
* @module
|
|
43
42
|
* @public
|
|
44
43
|
*/
|
|
45
44
|
// prevents the final constructed object from needing to add
|
|
@@ -83,12 +82,9 @@ const CONFIG = getOrSetGlobal('CONFIG', {
|
|
|
83
82
|
* });
|
|
84
83
|
* ```
|
|
85
84
|
*
|
|
86
|
-
* @method setBuildURLConfig
|
|
87
|
-
* @static
|
|
88
85
|
* @public
|
|
89
|
-
* @for @ember-data-mirror/request-utils
|
|
90
86
|
* @param {BuildURLConfig} config
|
|
91
|
-
* @return void
|
|
87
|
+
* @return {void}
|
|
92
88
|
*/
|
|
93
89
|
function setBuildURLConfig(config) {
|
|
94
90
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
@@ -169,12 +165,9 @@ function resourcePathForType(options) {
|
|
|
169
165
|
* - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
|
|
170
166
|
* - Depending on the value of `op`, `identifier` or `identifiers` will be required.
|
|
171
167
|
*
|
|
172
|
-
* @method buildBaseURL
|
|
173
|
-
* @static
|
|
174
168
|
* @public
|
|
175
|
-
* @for @ember-data-mirror/request-utils
|
|
176
169
|
* @param urlOptions
|
|
177
|
-
* @return
|
|
170
|
+
* @return {String}
|
|
178
171
|
*/
|
|
179
172
|
function buildBaseURL(urlOptions) {
|
|
180
173
|
const options = Object.assign({
|
|
@@ -295,10 +288,7 @@ function handleInclude(include) {
|
|
|
295
288
|
* filter out keys of an object that have falsy values or point to empty arrays
|
|
296
289
|
* returning a new object with only those keys that have truthy values / non-empty arrays
|
|
297
290
|
*
|
|
298
|
-
* @method filterEmpty
|
|
299
|
-
* @static
|
|
300
291
|
* @public
|
|
301
|
-
* @for @ember-data-mirror/request-utils
|
|
302
292
|
* @param {Record<string, Serializable>} source object to filter keys with empty values from
|
|
303
293
|
* @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
|
|
304
294
|
*/
|
|
@@ -330,10 +320,7 @@ function filterEmpty(source) {
|
|
|
330
320
|
* 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
|
|
331
321
|
* 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
|
|
332
322
|
*
|
|
333
|
-
* @method sortQueryParams
|
|
334
|
-
* @static
|
|
335
323
|
* @public
|
|
336
|
-
* @for @ember-data-mirror/request-utils
|
|
337
324
|
* @param {URLSearchParams | object} params
|
|
338
325
|
* @param {Object} options
|
|
339
326
|
* @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
|
|
@@ -407,10 +394,7 @@ function sortQueryParams(params, options) {
|
|
|
407
394
|
* 'repeat': appends the key for every value e.g. `ids=1&ids=2`
|
|
408
395
|
* 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
|
|
409
396
|
*
|
|
410
|
-
* @method buildQueryParams
|
|
411
|
-
* @static
|
|
412
397
|
* @public
|
|
413
|
-
* @for @ember-data-mirror/request-utils
|
|
414
398
|
* @param {URLSearchParams | Object} params
|
|
415
399
|
* @param {Object} [options]
|
|
416
400
|
* @return {String} A sorted query params string without the leading `?`
|
|
@@ -441,10 +425,7 @@ const NUMERIC_KEYS = new Set(['max-age', 's-maxage', 'stale-if-error', 'stale-wh
|
|
|
441
425
|
* 'stale-while-revalidate'?: number;
|
|
442
426
|
* }
|
|
443
427
|
* ```
|
|
444
|
-
* @method parseCacheControl
|
|
445
|
-
* @static
|
|
446
428
|
* @public
|
|
447
|
-
* @for @ember-data-mirror/request-utils
|
|
448
429
|
* @param {String} header
|
|
449
430
|
* @return {CacheControlValue}
|
|
450
431
|
*/
|
|
@@ -659,7 +640,6 @@ function isExpired(identifier, request, config) {
|
|
|
659
640
|
* });
|
|
660
641
|
* ```
|
|
661
642
|
*
|
|
662
|
-
* @typedoc
|
|
663
643
|
*/
|
|
664
644
|
|
|
665
645
|
/**
|
|
@@ -674,11 +654,11 @@ function isExpired(identifier, request, config) {
|
|
|
674
654
|
* In order expiration is determined by:
|
|
675
655
|
*
|
|
676
656
|
* - Is explicitly invalidated
|
|
677
|
-
* - ↳ (if null) isExpired function
|
|
678
|
-
* - ↳ (if null) X-WarpDrive-Expires header
|
|
679
|
-
* - ↳ (if null) Cache-Control header
|
|
680
|
-
* - ↳ (if null) Expires header
|
|
681
|
-
* - ↳ (if null) Date header + apiCacheHardExpires
|
|
657
|
+
* - ↳ (if null) isExpired function \<IF Constraint Active>
|
|
658
|
+
* - ↳ (if null) X-WarpDrive-Expires header \<IF Constraint Active>
|
|
659
|
+
* - ↳ (if null) Cache-Control header \<IF Constraint Active>
|
|
660
|
+
* - ↳ (if null) Expires header \<IF Constraint Active>
|
|
661
|
+
* - ↳ (if null) Date header + apiCacheHardExpires \< current time
|
|
682
662
|
*
|
|
683
663
|
* Invalidates any request for which `cacheOptions.types` was provided when a createRecord
|
|
684
664
|
* request for that type is successful.
|
|
@@ -732,7 +712,6 @@ function isExpired(identifier, request, config) {
|
|
|
732
712
|
*
|
|
733
713
|
* @class CachePolicy
|
|
734
714
|
* @public
|
|
735
|
-
* @module @ember-data-mirror/request-utils
|
|
736
715
|
*/
|
|
737
716
|
class CachePolicy {
|
|
738
717
|
_getStore(store) {
|
|
@@ -787,7 +766,6 @@ class CachePolicy {
|
|
|
787
766
|
* store.lifetimes.invalidateRequest(store, identifier);
|
|
788
767
|
* ```
|
|
789
768
|
*
|
|
790
|
-
* @method invalidateRequest
|
|
791
769
|
* @public
|
|
792
770
|
* @param {StableDocumentIdentifier} identifier
|
|
793
771
|
* @param {Store} store
|
|
@@ -811,7 +789,6 @@ class CachePolicy {
|
|
|
811
789
|
* store.lifetimes.invalidateRequestsForType(store, 'person');
|
|
812
790
|
* ```
|
|
813
791
|
*
|
|
814
|
-
* @method invalidateRequestsForType
|
|
815
792
|
* @public
|
|
816
793
|
* @param {String} type
|
|
817
794
|
* @param {Store} store
|
|
@@ -839,7 +816,6 @@ class CachePolicy {
|
|
|
839
816
|
*
|
|
840
817
|
* This method should not be invoked directly by consumers.
|
|
841
818
|
*
|
|
842
|
-
* @method didRequest
|
|
843
819
|
* @public
|
|
844
820
|
* @param {ImmutableRequestInfo} request
|
|
845
821
|
* @param {ImmutableResponse} response
|
|
@@ -889,7 +865,6 @@ class CachePolicy {
|
|
|
889
865
|
* the request will be fulfilled from the configured request handlers
|
|
890
866
|
* and the cache will be updated before returning the response.
|
|
891
867
|
*
|
|
892
|
-
* @method isHardExpired
|
|
893
868
|
* @public
|
|
894
869
|
* @param {StableDocumentIdentifier} identifier
|
|
895
870
|
* @param {Store} store
|
|
@@ -925,7 +900,6 @@ class CachePolicy {
|
|
|
925
900
|
* If true, the request will be fulfilled from cache while a backgrounded
|
|
926
901
|
* request is made to update the cache via the configured request handlers.
|
|
927
902
|
*
|
|
928
|
-
* @method isSoftExpired
|
|
929
903
|
* @public
|
|
930
904
|
* @param {StableDocumentIdentifier} identifier
|
|
931
905
|
* @param {Store} store
|