@ember-data/request-utils 5.6.0-beta.0 → 5.6.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/addon-main.cjs +1 -1
- package/dist/deprecation-support.js +9 -8
- package/dist/handlers.js +1 -147
- package/dist/index.js +7 -936
- package/dist/string.js +1 -2
- package/package.json +5 -17
- package/unstable-preview-types/deprecation-support.d.ts +2 -2
- package/unstable-preview-types/handlers.d.ts +8 -9
- package/unstable-preview-types/index.d.ts +10 -685
- package/unstable-preview-types/string.d.ts +13 -15
- package/dist/deprecation-support.js.map +0 -1
- package/dist/handlers.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/inflect-CwI_k2it.js +0 -305
- package/dist/inflect-CwI_k2it.js.map +0 -1
- package/dist/string.js.map +0 -1
- package/dist/transform-1PDozfHr.js +0 -192
- package/dist/transform-1PDozfHr.js.map +0 -1
- package/unstable-preview-types/-private/handlers/auto-compress.d.ts +0 -168
- package/unstable-preview-types/-private/handlers/auto-compress.d.ts.map +0 -1
- package/unstable-preview-types/-private/string/inflect.d.ts +0 -140
- package/unstable-preview-types/-private/string/inflect.d.ts.map +0 -1
- package/unstable-preview-types/-private/string/inflections.d.ts +0 -12
- package/unstable-preview-types/-private/string/inflections.d.ts.map +0 -1
- package/unstable-preview-types/-private/string/transform.d.ts +0 -117
- package/unstable-preview-types/-private/string/transform.d.ts.map +0 -1
- package/unstable-preview-types/deprecation-support.d.ts.map +0 -1
- package/unstable-preview-types/handlers.d.ts.map +0 -1
- package/unstable-preview-types/index.d.ts.map +0 -1
- package/unstable-preview-types/string.d.ts.map +0 -1
package/addon-main.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
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
|
-
|
|
29
|
+
InflectionRuleDefaults.plurals.forEach(([regex]) => {
|
|
29
30
|
defaultPluralKeys.add(regex.toString());
|
|
30
31
|
});
|
|
31
|
-
|
|
32
|
+
InflectionRuleDefaults.singular.forEach(([regex]) => {
|
|
32
33
|
defaultSingularKeys.add(regex.toString());
|
|
33
34
|
});
|
|
34
35
|
const {
|
|
35
|
-
defaultRules
|
|
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
|
|
43
|
-
defaultRules
|
|
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,147 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @module @ember-data/request-utils/handlers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
function isCompressibleMethod(method) {
|
|
6
|
-
return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
|
|
7
|
-
}
|
|
8
|
-
const SupportsRequestStreams = (() => {
|
|
9
|
-
let duplexAccessed = false;
|
|
10
|
-
const hasContentType = new Request('', {
|
|
11
|
-
body: new ReadableStream(),
|
|
12
|
-
method: 'POST',
|
|
13
|
-
// @ts-expect-error untyped
|
|
14
|
-
get duplex() {
|
|
15
|
-
duplexAccessed = true;
|
|
16
|
-
return 'half';
|
|
17
|
-
}
|
|
18
|
-
}).headers.has('Content-Type');
|
|
19
|
-
return duplexAccessed && !hasContentType;
|
|
20
|
-
})();
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Options for configuring the AutoCompress handler.
|
|
24
|
-
*
|
|
25
|
-
* @typedoc
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const DEFAULT_CONSTRAINTS = {
|
|
29
|
-
Blob: 1000,
|
|
30
|
-
ArrayBuffer: 1000,
|
|
31
|
-
TypedArray: 1000,
|
|
32
|
-
DataView: 1000,
|
|
33
|
-
String: 1000
|
|
34
|
-
};
|
|
35
|
-
const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A request handler that automatically compresses the request body
|
|
39
|
-
* if the request body is a string, array buffer, blob, or form data.
|
|
40
|
-
*
|
|
41
|
-
* This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
42
|
-
*
|
|
43
|
-
* The compression format as well as the kinds of data to compress can be
|
|
44
|
-
* configured using the `format` and `constraints` options.
|
|
45
|
-
*
|
|
46
|
-
* ```diff
|
|
47
|
-
* +import { AutoCompress } from '@ember-data/request-utils/handlers';
|
|
48
|
-
* import Fetch from '@ember-data/request/fetch';
|
|
49
|
-
* import RequestManager from '@ember-data/request';
|
|
50
|
-
* import Store from '@ember-data/store';
|
|
51
|
-
*
|
|
52
|
-
* class AppStore extends Store {
|
|
53
|
-
* requestManager = new RequestManager()
|
|
54
|
-
* .use([
|
|
55
|
-
* + new AutoCompress(),
|
|
56
|
-
* Fetch
|
|
57
|
-
* ]);
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @class AutoCompress
|
|
62
|
-
* @extends Handler
|
|
63
|
-
* @public
|
|
64
|
-
* @since 5.5.0
|
|
65
|
-
*/
|
|
66
|
-
class AutoCompress {
|
|
67
|
-
constructor(options = {}) {
|
|
68
|
-
const opts = {
|
|
69
|
-
format: options.format ?? 'gzip',
|
|
70
|
-
constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),
|
|
71
|
-
allowStreaming: options.allowStreaming ?? false,
|
|
72
|
-
forceStreaming: options.forceStreaming ?? false
|
|
73
|
-
};
|
|
74
|
-
this.options = opts;
|
|
75
|
-
}
|
|
76
|
-
request({
|
|
77
|
-
request
|
|
78
|
-
}, next) {
|
|
79
|
-
const {
|
|
80
|
-
constraints
|
|
81
|
-
} = this.options;
|
|
82
|
-
const {
|
|
83
|
-
body
|
|
84
|
-
} = request;
|
|
85
|
-
const shouldCompress = isCompressibleMethod(request.method) && request.options?.compress !== false && (
|
|
86
|
-
// prettier-ignore
|
|
87
|
-
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);
|
|
88
|
-
if (!shouldCompress) return next(request);
|
|
89
|
-
|
|
90
|
-
// A convenient way to convert all of the supported body types to a readable
|
|
91
|
-
// stream is to use a `Response` object body
|
|
92
|
-
const response = new Response(request.body);
|
|
93
|
-
const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));
|
|
94
|
-
const headers = new Headers(request.headers);
|
|
95
|
-
headers.set('Content-Encoding', encodingForFormat(this.options.format));
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
// For browsers that support it, `fetch` can receive a `ReadableStream` as
|
|
99
|
-
// the body, so all we need to do is to create a new `ReadableStream` and
|
|
100
|
-
// compress it on the fly
|
|
101
|
-
//
|
|
102
|
-
const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;
|
|
103
|
-
const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;
|
|
104
|
-
if (forceStreaming || SupportsRequestStreams && allowStreaming) {
|
|
105
|
-
const req = Object.assign({}, request, {
|
|
106
|
-
body: stream
|
|
107
|
-
});
|
|
108
|
-
if (SupportsRequestStreams) {
|
|
109
|
-
// @ts-expect-error untyped
|
|
110
|
-
req.duplex = 'half';
|
|
111
|
-
}
|
|
112
|
-
return next(req);
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
// For non-chromium browsers, we have to "pull" the stream to get the final
|
|
116
|
-
// bytes and supply the final byte array as the new request body.
|
|
117
|
-
//
|
|
118
|
-
} else {
|
|
119
|
-
// we need to pull the stream to get the final bytes
|
|
120
|
-
const resp = new Response(stream);
|
|
121
|
-
return resp.blob().then(blob => {
|
|
122
|
-
const req = Object.assign({}, request, {
|
|
123
|
-
body: blob,
|
|
124
|
-
headers
|
|
125
|
-
});
|
|
126
|
-
return next(req);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function canCompress(type, constraints, size) {
|
|
132
|
-
// if we have a value of 0, we can compress anything
|
|
133
|
-
if (constraints[type] === 0) return true;
|
|
134
|
-
if (constraints[type] === -1) return false;
|
|
135
|
-
return size >= constraints[type];
|
|
136
|
-
}
|
|
137
|
-
function encodingForFormat(format) {
|
|
138
|
-
switch (format) {
|
|
139
|
-
case 'gzip':
|
|
140
|
-
case 'deflate':
|
|
141
|
-
case 'deflate-raw':
|
|
142
|
-
return format;
|
|
143
|
-
default:
|
|
144
|
-
throw new Error(`Unsupported compression format: ${format}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
export { AutoCompress, SupportsRequestStreams };
|
|
1
|
+
export * from '@warp-drive/utilities/handlers';
|