@warp-drive/legacy 5.8.0-beta.0 → 5.8.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/README.md +16 -26
- package/declarations/adapter/error.d.ts +7 -7
- package/declarations/adapter/json-api.d.ts +6 -8
- package/declarations/adapter/rest.d.ts +26 -112
- package/declarations/adapter.d.ts +6 -8
- package/declarations/compat/-private.d.ts +1 -1
- package/declarations/compat/builders/find-all.d.ts +6 -6
- package/declarations/compat/builders/find-record.d.ts +8 -8
- package/declarations/compat/builders/query.d.ts +12 -12
- package/declarations/compat/extensions.d.ts +1 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
- package/declarations/compat/utils.d.ts +17 -17
- package/declarations/compat.d.ts +35 -11
- package/declarations/index.d.ts +102 -0
- package/declarations/model/-private/attr.d.ts +5 -6
- package/declarations/model/-private/belongs-to.d.ts +4 -5
- package/declarations/model/-private/has-many.d.ts +4 -5
- package/declarations/model/-private/hooks.d.ts +1 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +18 -59
- package/declarations/model/-private/promise-many-array.d.ts +0 -18
- package/declarations/model/-private/record-state.d.ts +1 -1
- package/declarations/model/-private/references/belongs-to.d.ts +19 -29
- package/declarations/model/-private/references/has-many.d.ts +14 -16
- package/declarations/model/migration-support.d.ts +46 -21
- package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
- package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
- package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
- package/declarations/model-fragments/index.d.ts +5 -0
- package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
- package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
- package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
- package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
- package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
- package/declarations/model-fragments.d.ts +9 -0
- package/declarations/model.d.ts +2 -2
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
- package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
- package/declarations/serializer/-private/transforms/date.d.ts +2 -2
- package/declarations/serializer/-private/transforms/number.d.ts +1 -1
- package/declarations/serializer/-private/transforms/string.d.ts +1 -1
- package/declarations/serializer/json-api.d.ts +11 -12
- package/declarations/serializer/json.d.ts +9 -11
- package/declarations/serializer/rest.d.ts +4 -6
- package/declarations/serializer.d.ts +9 -12
- package/dist/{-private-8UmnAf9J.js → -private-BG3bMiKp.js} +3 -2
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +14 -15
- package/dist/adapter/json-api.js +4 -1
- package/dist/adapter/rest.js +38 -125
- package/dist/adapter.js +6 -8
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +26 -26
- package/dist/compat/utils.js +17 -18
- package/dist/compat.js +61 -43
- package/dist/{errors-8kD2mSe_.js → errors-Cz5KrzBk.js} +115 -122
- package/dist/hooks-D6diaM34.js +74 -0
- package/dist/index.js +195 -0
- package/dist/{json-Et4mt_LM.js → json-ChdEfB0X.js} +18 -35
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +59 -27
- package/dist/model-for-CqXsIKws.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +18 -90
- package/dist/{schema-provider-DQu4Rjco.js → schema-provider-DJCV_6AF.js} +50 -95
- package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-DPZYoF-i.js} +1 -1
- package/dist/serializer/json-api.js +18 -45
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +14 -21
- package/dist/serializer/transform.js +15 -6
- package/dist/serializer.js +9 -13
- package/dist/store.js +5 -1
- package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev/adapter/-private.js +1 -0
- package/dist/unpkg/dev/adapter/error.js +335 -0
- package/dist/unpkg/dev/adapter/json-api.js +271 -0
- package/dist/unpkg/dev/adapter/rest.js +1171 -0
- package/dist/unpkg/dev/adapter.js +1252 -0
- package/dist/unpkg/dev/compat/-private.js +1 -0
- package/dist/unpkg/dev/compat/builders.js +275 -0
- package/dist/unpkg/dev/compat/extensions.js +242 -0
- package/dist/unpkg/dev/compat/utils.js +223 -0
- package/dist/unpkg/dev/compat.js +1147 -0
- package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
- package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
- package/dist/unpkg/dev/index.js +197 -0
- package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev/model/-private.js +1 -0
- package/dist/unpkg/dev/model/migration-support.js +553 -0
- package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev/model-fragments.js +76 -0
- package/dist/unpkg/dev/model.js +678 -0
- package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +2186 -0
- package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev/serializer/json-api.js +649 -0
- package/dist/unpkg/dev/serializer/json.js +4 -0
- package/dist/unpkg/dev/serializer/rest.js +1242 -0
- package/dist/unpkg/dev/serializer/transform.js +278 -0
- package/dist/unpkg/dev/serializer.js +248 -0
- package/dist/unpkg/dev/store.js +637 -0
- package/dist/unpkg/dev/util-DvanW33H.js +20 -0
- package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
- package/dist/unpkg/dev-deprecated/adapter/rest.js +1171 -0
- package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
- package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
- package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
- package/dist/unpkg/dev-deprecated/compat.js +1147 -0
- package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
- package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
- package/dist/unpkg/dev-deprecated/index.js +196 -0
- package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -0
- package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/dev-deprecated/model.js +682 -0
- package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +2211 -0
- package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -0
- package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
- package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/dev-deprecated/serializer.js +248 -0
- package/dist/unpkg/dev-deprecated/store.js +637 -0
- package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
- package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
- package/dist/unpkg/prod/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -0
- package/dist/unpkg/prod/adapter/error.js +330 -0
- package/dist/unpkg/prod/adapter/json-api.js +266 -0
- package/dist/unpkg/prod/adapter/rest.js +1134 -0
- package/dist/unpkg/prod/adapter.js +1219 -0
- package/dist/unpkg/prod/compat/-private.js +1 -0
- package/dist/unpkg/prod/compat/builders.js +210 -0
- package/dist/unpkg/prod/compat/extensions.js +232 -0
- package/dist/unpkg/prod/compat/utils.js +218 -0
- package/dist/unpkg/prod/compat.js +727 -0
- package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
- package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
- package/dist/unpkg/prod/index.js +151 -0
- package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod/model/-private.js +1 -0
- package/dist/unpkg/prod/model/migration-support.js +546 -0
- package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod/model-fragments.js +76 -0
- package/dist/unpkg/prod/model.js +593 -0
- package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +1861 -0
- package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod/serializer/json-api.js +592 -0
- package/dist/unpkg/prod/serializer/json.js +4 -0
- package/dist/unpkg/prod/serializer/rest.js +1210 -0
- package/dist/unpkg/prod/serializer/transform.js +278 -0
- package/dist/unpkg/prod/serializer.js +248 -0
- package/dist/unpkg/prod/store.js +505 -0
- package/dist/unpkg/prod/util-DvanW33H.js +20 -0
- package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
- package/dist/unpkg/prod-deprecated/adapter/rest.js +1134 -0
- package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
- package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
- package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
- package/dist/unpkg/prod-deprecated/compat.js +727 -0
- package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
- package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
- package/dist/unpkg/prod-deprecated/index.js +150 -0
- package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -0
- package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/prod-deprecated/model.js +596 -0
- package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +1904 -0
- package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -0
- package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
- package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/prod-deprecated/serializer.js +248 -0
- package/dist/unpkg/prod-deprecated/store.js +505 -0
- package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
- package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +15 -7
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import '@warp-drive/core/reactive/-private';
|
|
2
|
+
import "./-private-DtjBbEgy.js";
|
|
3
|
+
import '@warp-drive/core/store/-private';
|
|
4
|
+
const newline = /\r?\n/;
|
|
5
|
+
function parseResponseHeaders(headersString) {
|
|
6
|
+
const headers = Object.create(null);
|
|
7
|
+
if (!headersString) {
|
|
8
|
+
return headers;
|
|
9
|
+
}
|
|
10
|
+
const headerPairs = headersString.split(newline);
|
|
11
|
+
for (let i = 0; i < headerPairs.length; i++) {
|
|
12
|
+
const header = headerPairs[i];
|
|
13
|
+
let j = 0;
|
|
14
|
+
let foundSep = false;
|
|
15
|
+
for (; j < header.length; j++) {
|
|
16
|
+
if (header.charCodeAt(j) === 58 /* ':' */) {
|
|
17
|
+
foundSep = true;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (foundSep === false) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const field = header.substring(0, j).trim();
|
|
25
|
+
const value = header.substring(j + 1, header.length).trim();
|
|
26
|
+
if (value) {
|
|
27
|
+
const lowerCasedField = field.toLowerCase();
|
|
28
|
+
headers[lowerCasedField] = value;
|
|
29
|
+
headers[field] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return headers;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A utility function that returns a promise that resolves
|
|
37
|
+
* even when the source promise rejects.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
function continueOnReject(promise) {
|
|
42
|
+
return Promise.resolve(promise).catch(e => e);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Function that always attempts to parse the response as json, and if an error is thrown,
|
|
47
|
+
* returns `undefined` if the response is successful and has a status code of 204 (No Content),
|
|
48
|
+
* or 205 (Reset Content) or if the request method was 'HEAD', and the plain payload otherwise.
|
|
49
|
+
*/
|
|
50
|
+
function _determineContent(response, requestData, payload) {
|
|
51
|
+
let ret = payload;
|
|
52
|
+
let error = null;
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
return payload;
|
|
55
|
+
}
|
|
56
|
+
const status = response.status;
|
|
57
|
+
const payloadIsEmpty = payload === '' || payload === null;
|
|
58
|
+
const statusIndicatesEmptyResponse = status === 204 || status === 205 || requestData.method === 'HEAD';
|
|
59
|
+
{
|
|
60
|
+
if (payloadIsEmpty && !statusIndicatesEmptyResponse) {
|
|
61
|
+
const message = `The server returned an empty string for ${requestData.method} ${requestData.url}, which cannot be parsed into a valid JSON. Return either null or {}.`;
|
|
62
|
+
if (payload === '') {
|
|
63
|
+
console.warn(message, {
|
|
64
|
+
id: 'ds.adapter.returned-empty-string-as-JSON'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (response.ok && (statusIndicatesEmptyResponse || payloadIsEmpty)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
ret = JSON.parse(payload);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (!(e instanceof SyntaxError)) {
|
|
76
|
+
return e;
|
|
77
|
+
}
|
|
78
|
+
e.payload = payload;
|
|
79
|
+
error = e;
|
|
80
|
+
}
|
|
81
|
+
if (error) {
|
|
82
|
+
{
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.warn('This response was unable to be parsed as json.', payload);
|
|
85
|
+
}
|
|
86
|
+
return error;
|
|
87
|
+
}
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
function determineBodyPromise(response, requestData) {
|
|
91
|
+
// response.text() may resolve or reject
|
|
92
|
+
// it is a native promise, may not have finally
|
|
93
|
+
return continueOnReject(response.text()).then(payload => _determineContent(response, requestData, payload));
|
|
94
|
+
}
|
|
95
|
+
const RBRACKET = /\[\]$/;
|
|
96
|
+
function isPlainObject(obj) {
|
|
97
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
98
|
+
}
|
|
99
|
+
function isPrimitiveArray(obj) {
|
|
100
|
+
return Array.isArray(obj);
|
|
101
|
+
}
|
|
102
|
+
function isParamsArray(obj) {
|
|
103
|
+
return Array.isArray(obj);
|
|
104
|
+
}
|
|
105
|
+
function buildParams(prefix, obj, s) {
|
|
106
|
+
let i, len, key;
|
|
107
|
+
if (prefix) {
|
|
108
|
+
if (isPrimitiveArray(obj)) {
|
|
109
|
+
for (i = 0, len = obj.length; i < len; i++) {
|
|
110
|
+
if (RBRACKET.test(prefix)) {
|
|
111
|
+
add(s, prefix, obj[i]);
|
|
112
|
+
} else {
|
|
113
|
+
buildParams(prefix + '[' + (typeof obj[i] === 'object' && obj[i] !== null ? i : '') + ']', obj[i], s);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} else if (isPlainObject(obj)) {
|
|
117
|
+
for (key in obj) {
|
|
118
|
+
buildParams(prefix + '[' + key + ']', obj[key], s);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
(test => {
|
|
122
|
+
if (!test) {
|
|
123
|
+
throw new Error(`query params cannot be a { name, value } pair if prefix is present`);
|
|
124
|
+
}
|
|
125
|
+
})(obj === null || typeof obj !== 'object');
|
|
126
|
+
add(s, prefix, obj);
|
|
127
|
+
}
|
|
128
|
+
} else if (isParamsArray(obj)) {
|
|
129
|
+
for (i = 0, len = obj.length; i < len; i++) {
|
|
130
|
+
add(s, obj[i].name, obj[i].value);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
(test => {
|
|
134
|
+
if (!test) {
|
|
135
|
+
throw new Error(`query params cannot be a string if no prefix is present`);
|
|
136
|
+
}
|
|
137
|
+
})(typeof obj !== 'string');
|
|
138
|
+
(test => {
|
|
139
|
+
if (!test) {
|
|
140
|
+
throw new Error(`query params should not be an array if no prefix is present`);
|
|
141
|
+
}
|
|
142
|
+
})(!Array.isArray(obj));
|
|
143
|
+
(test => {
|
|
144
|
+
if (!test) {
|
|
145
|
+
throw new Error(`query params should not be a { name, value } pair if no prefix is present`);
|
|
146
|
+
}
|
|
147
|
+
})(isPlainObject(obj));
|
|
148
|
+
for (key in obj) {
|
|
149
|
+
buildParams(key, obj[key], s);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return s;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
* Helper function that turns the data/body of a request into a query param string.
|
|
157
|
+
* This is directly copied from jQuery.param.
|
|
158
|
+
*/
|
|
159
|
+
function serializeQueryParams(queryParamsObject) {
|
|
160
|
+
return buildParams('', queryParamsObject, []).join('&');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* Part of the `serializeQueryParams` helper function.
|
|
165
|
+
*/
|
|
166
|
+
function add(s, k, v) {
|
|
167
|
+
// Strip out keys with undefined value and replace null values with
|
|
168
|
+
// empty strings (mimics jQuery.ajax)
|
|
169
|
+
if (v === undefined) {
|
|
170
|
+
return;
|
|
171
|
+
} else if (v === null) {
|
|
172
|
+
v = '';
|
|
173
|
+
}
|
|
174
|
+
v = typeof v === 'function' ? v() : v;
|
|
175
|
+
s[s.length] = `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
|
|
176
|
+
}
|
|
177
|
+
let _fetch = null;
|
|
178
|
+
let REQUEST = null;
|
|
179
|
+
function getFetchFunction() {
|
|
180
|
+
// return cached fetch function
|
|
181
|
+
if (_fetch !== null) {
|
|
182
|
+
return _fetch();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// grab browser native fetch if available, or global fetch if otherwise configured
|
|
186
|
+
if (typeof fetch === 'function') {
|
|
187
|
+
// fallback to using global fetch
|
|
188
|
+
_fetch = () => fetch;
|
|
189
|
+
|
|
190
|
+
/* global FastBoot */
|
|
191
|
+
// grab fetch from node-fetch
|
|
192
|
+
} else if (typeof FastBoot !== 'undefined') {
|
|
193
|
+
try {
|
|
194
|
+
const nodeFetch = FastBoot.require('node-fetch');
|
|
195
|
+
const httpRegex = /^https?:\/\//;
|
|
196
|
+
const protocolRelativeRegex = /^\/\//;
|
|
197
|
+
function parseRequest(request) {
|
|
198
|
+
if (request === null) {
|
|
199
|
+
throw new Error("Trying to fetch with relative url but the application hasn't finished loading FastBootInfo, see details at https://github.com/ember-cli/ember-fetch#relative-url");
|
|
200
|
+
}
|
|
201
|
+
// Old Prember version is not sending protocol
|
|
202
|
+
const protocol = request.protocol === 'undefined:' ? 'http:' : request.protocol;
|
|
203
|
+
return [request.get('host'), protocol];
|
|
204
|
+
}
|
|
205
|
+
function buildAbsoluteUrl(url) {
|
|
206
|
+
if (protocolRelativeRegex.test(url)) {
|
|
207
|
+
const [host] = parseRequest(REQUEST);
|
|
208
|
+
url = host + url;
|
|
209
|
+
} else if (!httpRegex.test(url)) {
|
|
210
|
+
const [host, protocol] = parseRequest(REQUEST);
|
|
211
|
+
url = protocol + '//' + host + url;
|
|
212
|
+
}
|
|
213
|
+
return url;
|
|
214
|
+
}
|
|
215
|
+
function patchedFetch(input, options) {
|
|
216
|
+
if (input && typeof input === 'object' && 'href' in input) {
|
|
217
|
+
const url = buildAbsoluteUrl(input.href);
|
|
218
|
+
const info = Object.assign({}, input, {
|
|
219
|
+
url
|
|
220
|
+
});
|
|
221
|
+
return nodeFetch(info, options);
|
|
222
|
+
} else if (typeof input === 'string') {
|
|
223
|
+
const url = buildAbsoluteUrl(input);
|
|
224
|
+
return nodeFetch(url, options);
|
|
225
|
+
}
|
|
226
|
+
return nodeFetch(input, options);
|
|
227
|
+
}
|
|
228
|
+
_fetch = () => patchedFetch;
|
|
229
|
+
} catch {
|
|
230
|
+
throw new Error(`Unable to create a compatible 'fetch' for FastBoot with node-fetch`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
(test => {
|
|
234
|
+
if (!test) {
|
|
235
|
+
throw new Error(`Cannot find a 'fetch' global and did not detect FastBoot.`);
|
|
236
|
+
}
|
|
237
|
+
})(_fetch);
|
|
238
|
+
return _fetch();
|
|
239
|
+
}
|
|
240
|
+
function setupFastboot(fastBootRequest) {
|
|
241
|
+
REQUEST = fastBootRequest;
|
|
242
|
+
}
|
|
243
|
+
function serializeIntoHash(store, modelClass, snapshot, options = {
|
|
244
|
+
includeId: true
|
|
245
|
+
}) {
|
|
246
|
+
const serializer = store.serializerFor(modelClass.modelName);
|
|
247
|
+
(test => {
|
|
248
|
+
if (!test) {
|
|
249
|
+
throw new Error(`Cannot serialize record, no serializer defined`);
|
|
250
|
+
}
|
|
251
|
+
})(serializer);
|
|
252
|
+
if (typeof serializer.serializeIntoHash === 'function') {
|
|
253
|
+
const data = {};
|
|
254
|
+
serializer.serializeIntoHash(data, modelClass, snapshot, options);
|
|
255
|
+
return data;
|
|
256
|
+
}
|
|
257
|
+
return serializer.serialize(snapshot, options);
|
|
258
|
+
}
|
|
259
|
+
export { setupFastboot as a, serializeIntoHash as b, determineBodyPromise as d, getFetchFunction as g, parseResponseHeaders as p, serializeQueryParams as s };
|