@ember-data/request-utils 5.6.0-alpha.5 → 5.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/addon-main.cjs +1 -1
  2. package/dist/deprecation-support.js +9 -8
  3. package/dist/handlers.js +1 -141
  4. package/dist/index.js +6 -909
  5. package/dist/string.js +1 -2
  6. package/package.json +5 -11
  7. package/unstable-preview-types/deprecation-support.d.ts +2 -2
  8. package/unstable-preview-types/handlers.d.ts +8 -8
  9. package/unstable-preview-types/index.d.ts +10 -649
  10. package/unstable-preview-types/string.d.ts +13 -14
  11. package/dist/deprecation-support.js.map +0 -1
  12. package/dist/handlers.js.map +0 -1
  13. package/dist/index.js.map +0 -1
  14. package/dist/inflect-SV-gOUrZ.js +0 -267
  15. package/dist/inflect-SV-gOUrZ.js.map +0 -1
  16. package/dist/string.js.map +0 -1
  17. package/dist/transform-BixPrO0I.js +0 -173
  18. package/dist/transform-BixPrO0I.js.map +0 -1
  19. package/unstable-preview-types/-private/handlers/auto-compress.d.ts +0 -155
  20. package/unstable-preview-types/-private/handlers/auto-compress.d.ts.map +0 -1
  21. package/unstable-preview-types/-private/string/inflect.d.ts +0 -107
  22. package/unstable-preview-types/-private/string/inflect.d.ts.map +0 -1
  23. package/unstable-preview-types/-private/string/inflections.d.ts +0 -12
  24. package/unstable-preview-types/-private/string/inflections.d.ts.map +0 -1
  25. package/unstable-preview-types/-private/string/transform.d.ts +0 -102
  26. package/unstable-preview-types/-private/string/transform.d.ts.map +0 -1
  27. package/unstable-preview-types/deprecation-support.d.ts.map +0 -1
  28. package/unstable-preview-types/handlers.d.ts.map +0 -1
  29. package/unstable-preview-types/index.d.ts.map +0 -1
  30. package/unstable-preview-types/string.d.ts.map +0 -1
package/addon-main.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const { addonShim } = require('@warp-drive/build-config/addon-shim.cjs');
3
+ const { addonShim } = require('@warp-drive/core/addon-shim.cjs');
4
4
 
5
5
  module.exports = addonShim(__dirname);
@@ -1,7 +1,8 @@
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-SV-gOUrZ.js";
4
- import "./transform-BixPrO0I.js";
3
+ import { InflectionRuleDefaults } from '@warp-drive/utilities/-private';
4
+ import { plural, singular, irregular, uncountable } from '@warp-drive/utilities/string';
5
+
5
6
  if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_EMBER_INFLECTOR)) {
6
7
  if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {
7
8
  const Inflector = importSync('ember-inflector').default;
@@ -25,22 +26,22 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_EMBER_INFL
25
26
  // is default via our own list.
26
27
  const defaultPluralKeys = new Set();
27
28
  const defaultSingularKeys = new Set();
28
- defaultRules.plurals.forEach(([regex]) => {
29
+ InflectionRuleDefaults.plurals.forEach(([regex]) => {
29
30
  defaultPluralKeys.add(regex.toString());
30
31
  });
31
- defaultRules.singular.forEach(([regex]) => {
32
+ InflectionRuleDefaults.singular.forEach(([regex]) => {
32
33
  defaultSingularKeys.add(regex.toString());
33
34
  });
34
35
  const {
35
- defaultRules: defaultRules$1
36
+ defaultRules
36
37
  } = Inflector;
37
38
  const {
38
39
  rules
39
40
  } = inflector;
40
41
  const irregularMap = new Map();
41
42
  const toIgnore = new Set();
42
- const uncountableSet = new Set(defaultRules$1.uncountable);
43
- defaultRules$1.irregularPairs.forEach(([single, plur]) => {
43
+ const uncountableSet = new Set(defaultRules.uncountable);
44
+ defaultRules.irregularPairs.forEach(([single, plur]) => {
44
45
  irregularMap.set(single.toLowerCase(), plur);
45
46
  toIgnore.add(plur.toLowerCase());
46
47
  });
@@ -185,4 +186,4 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_EMBER_INFL
185
186
  return originalUncountable.apply(inflector, args);
186
187
  };
187
188
  }
188
- }
189
+ }
package/dist/handlers.js CHANGED
@@ -1,141 +1 @@
1
- function isCompressibleMethod(method) {
2
- return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
3
- }
4
- const SupportsRequestStreams = (() => {
5
- let duplexAccessed = false;
6
- const hasContentType = new Request('', {
7
- body: new ReadableStream(),
8
- method: 'POST',
9
- // @ts-expect-error untyped
10
- get duplex() {
11
- duplexAccessed = true;
12
- return 'half';
13
- }
14
- }).headers.has('Content-Type');
15
- return duplexAccessed && !hasContentType;
16
- })();
17
-
18
- /**
19
- * Options for configuring the AutoCompress handler.
20
- *
21
- */
22
-
23
- const DEFAULT_CONSTRAINTS = {
24
- Blob: 1000,
25
- ArrayBuffer: 1000,
26
- TypedArray: 1000,
27
- DataView: 1000,
28
- String: 1000
29
- };
30
- const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
31
-
32
- /**
33
- * A request handler that automatically compresses the request body
34
- * if the request body is a string, array buffer, blob, or form data.
35
- *
36
- * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
37
- *
38
- * The compression format as well as the kinds of data to compress can be
39
- * configured using the `format` and `constraints` options.
40
- *
41
- * ```diff
42
- * +import { AutoCompress } from '@ember-data/request-utils/handlers';
43
- * import Fetch from '@ember-data/request/fetch';
44
- * import RequestManager from '@ember-data/request';
45
- * import Store from '@ember-data/store';
46
- *
47
- * class AppStore extends Store {
48
- * requestManager = new RequestManager()
49
- * .use([
50
- * + new AutoCompress(),
51
- * Fetch
52
- * ]);
53
- * }
54
- * ```
55
- *
56
- * @class AutoCompress
57
- * @public
58
- * @since 5.5.0
59
- */
60
- class AutoCompress {
61
- constructor(options = {}) {
62
- const opts = {
63
- format: options.format ?? 'gzip',
64
- constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),
65
- allowStreaming: options.allowStreaming ?? false,
66
- forceStreaming: options.forceStreaming ?? false
67
- };
68
- this.options = opts;
69
- }
70
- request({
71
- request
72
- }, next) {
73
- const {
74
- constraints
75
- } = this.options;
76
- const {
77
- body
78
- } = request;
79
- const shouldCompress = isCompressibleMethod(request.method) && request.options?.compress !== false && (
80
- // prettier-ignore
81
- 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);
82
- if (!shouldCompress) return next(request);
83
-
84
- // A convenient way to convert all of the supported body types to a readable
85
- // stream is to use a `Response` object body
86
- const response = new Response(request.body);
87
- const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));
88
- const headers = new Headers(request.headers);
89
- headers.set('Content-Encoding', encodingForFormat(this.options.format));
90
-
91
- //
92
- // For browsers that support it, `fetch` can receive a `ReadableStream` as
93
- // the body, so all we need to do is to create a new `ReadableStream` and
94
- // compress it on the fly
95
- //
96
- const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;
97
- const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;
98
- if (forceStreaming || SupportsRequestStreams && allowStreaming) {
99
- const req = Object.assign({}, request, {
100
- body: stream
101
- });
102
- if (SupportsRequestStreams) {
103
- // @ts-expect-error untyped
104
- req.duplex = 'half';
105
- }
106
- return next(req);
107
-
108
- //
109
- // For non-chromium browsers, we have to "pull" the stream to get the final
110
- // bytes and supply the final byte array as the new request body.
111
- //
112
- } else {
113
- // we need to pull the stream to get the final bytes
114
- const resp = new Response(stream);
115
- return resp.blob().then(blob => {
116
- const req = Object.assign({}, request, {
117
- body: blob,
118
- headers
119
- });
120
- return next(req);
121
- });
122
- }
123
- }
124
- }
125
- function canCompress(type, constraints, size) {
126
- // if we have a value of 0, we can compress anything
127
- if (constraints[type] === 0) return true;
128
- if (constraints[type] === -1) return false;
129
- return size >= constraints[type];
130
- }
131
- function encodingForFormat(format) {
132
- switch (format) {
133
- case 'gzip':
134
- case 'deflate':
135
- case 'deflate-raw':
136
- return format;
137
- default:
138
- throw new Error(`Unsupported compression format: ${format}`);
139
- }
140
- }
141
- export { AutoCompress, SupportsRequestStreams };
1
+ export * from '@warp-drive/utilities/handlers';