@warp-drive/core 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 +23 -36
- package/declarations/build-config.d.ts +18 -1
- package/declarations/configure.d.ts +1 -1
- package/declarations/graph/-private/-edge-definition.d.ts +12 -2
- package/declarations/index.d.ts +90 -8
- package/declarations/reactive/-private/default-mode.d.ts +1 -1
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/fields/extension.d.ts +1 -1
- package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
- package/declarations/reactive/-private/fields/managed-object.d.ts +1 -1
- package/declarations/reactive/-private/record.d.ts +10 -1
- package/declarations/reactive/-private/schema.d.ts +77 -4
- package/declarations/reactive/-private.d.ts +1 -0
- package/declarations/reactive.d.ts +13 -8
- package/declarations/request/-private/types.d.ts +1 -1
- package/declarations/request.d.ts +47 -0
- package/declarations/signals/-leaked.d.ts +2 -0
- package/declarations/signals/-private.d.ts +6 -0
- package/declarations/{store/-private/new-core-tmp → signals}/promise-state.d.ts +2 -1
- package/declarations/{store/-private/new-core-tmp → signals}/request-state.d.ts +6 -6
- package/declarations/{store/-private/new-core-tmp → signals}/request-subscription.d.ts +4 -4
- package/declarations/store/-private/cache-handler/types.d.ts +2 -16
- package/declarations/store/-private/caches/instance-cache.d.ts +5 -6
- package/declarations/store/-private/default-cache-policy.d.ts +147 -129
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/managers/cache-key-manager.d.ts +26 -8
- package/declarations/store/-private/managers/cache-manager.d.ts +7 -18
- package/declarations/store/-private/managers/notification-manager.d.ts +1 -1
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +1 -1
- package/declarations/store/-private/record-arrays/resource-array.d.ts +1 -1
- package/declarations/store/-private/store-service.d.ts +43 -64
- package/declarations/store/-private.d.ts +0 -6
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/-private.d.ts +2 -2
- package/declarations/store/deprecated/store.d.ts +33 -32
- package/declarations/store.d.ts +1 -0
- package/declarations/types/cache.d.ts +8 -6
- package/declarations/types/record.d.ts +132 -0
- package/declarations/types/request.d.ts +26 -14
- package/declarations/types/schema/fields.d.ts +37 -13
- package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +15 -13
- package/declarations/types/spec/document.d.ts +34 -0
- package/declarations/types/symbols.d.ts +2 -2
- package/declarations/types.d.ts +1 -1
- package/dist/build-config.js +1 -1
- package/dist/configure-DPUFCemT.js +1940 -0
- package/dist/configure.js +2 -1
- package/dist/default-cache-policy-D7_u4YRH.js +572 -0
- package/dist/{context-C_7OLieY.js → future-BKkJJkj7.js} +174 -174
- package/dist/graph/-private.js +16 -6
- package/dist/{request-state-C955e0AL.js → index-CQP2NSqg.js} +8830 -9427
- package/dist/index.js +6 -382
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +4 -903
- package/dist/request.js +49 -1
- package/dist/signals/-leaked.js +1 -0
- package/dist/store/-private.js +1 -2
- package/dist/store.js +1 -533
- package/dist/symbols-3C1OkYtZ.js +39 -0
- package/dist/types/-private.js +1 -1
- package/dist/types/record.js +127 -0
- package/dist/types/request.js +14 -12
- package/dist/types/runtime.js +1 -1
- package/dist/types/schema/fields.js +14 -0
- package/dist/types/schema/schema-service.js +0 -0
- package/dist/types/symbols.js +2 -2
- package/dist/unpkg/dev/-leaked-Co0EI6Go.js +1939 -0
- package/dist/unpkg/dev/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev/build-config/debugging.js +1 -0
- package/dist/unpkg/dev/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev/build-config/env.js +1 -0
- package/dist/unpkg/dev/build-config/macros.js +1 -0
- package/dist/unpkg/dev/build-config.js +1 -0
- package/dist/unpkg/dev/configure.js +1 -0
- package/dist/unpkg/dev/future-DFfOzSoe.js +672 -0
- package/dist/unpkg/dev/graph/-private.js +3132 -0
- package/dist/unpkg/dev/index-BzcBOnw9.js +9392 -0
- package/dist/unpkg/dev/index.js +6 -0
- package/dist/unpkg/dev/reactive/-private.js +1 -0
- package/dist/unpkg/dev/reactive.js +3 -0
- package/dist/unpkg/dev/request.js +49 -0
- package/dist/unpkg/dev/runtime-E1M51_-O.js +135 -0
- package/dist/unpkg/dev/signals/-leaked.js +1 -0
- package/dist/unpkg/dev/store/-private.js +55 -0
- package/dist/unpkg/dev/store.js +558 -0
- package/dist/unpkg/dev/types/-private.js +69 -0
- package/dist/unpkg/dev/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev/types/cache/change.js +0 -0
- package/dist/unpkg/dev/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev/types/cache/operations.js +0 -0
- package/dist/unpkg/dev/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev/types/cache.js +0 -0
- package/dist/unpkg/dev/types/graph.js +0 -0
- package/dist/unpkg/dev/types/identifier.js +61 -0
- package/dist/unpkg/dev/types/json/raw.js +0 -0
- package/dist/unpkg/dev/types/params.js +0 -0
- package/dist/unpkg/dev/types/record.js +191 -0
- package/dist/unpkg/dev/types/request.js +77 -0
- package/dist/unpkg/dev/types/runtime.js +34 -0
- package/dist/unpkg/dev/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev/types/schema/fields.js +505 -0
- package/dist/unpkg/dev/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev/types/spec/document.js +0 -0
- package/dist/unpkg/dev/types/spec/error.js +0 -0
- package/dist/unpkg/dev/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev/types/symbols.js +84 -0
- package/dist/unpkg/dev/types/utils.js +0 -0
- package/dist/unpkg/dev/types.js +0 -0
- package/dist/unpkg/dev/utils/string.js +91 -0
- package/dist/unpkg/dev-deprecated/-leaked-DjMeRqdU.js +1939 -0
- package/dist/unpkg/dev-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/dev-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config.js +1 -0
- package/dist/unpkg/dev-deprecated/configure.js +1 -0
- package/dist/unpkg/dev-deprecated/future-DFfOzSoe.js +672 -0
- package/dist/unpkg/dev-deprecated/graph/-private.js +3327 -0
- package/dist/unpkg/dev-deprecated/index-6TnTv-WG.js +10007 -0
- package/dist/unpkg/dev-deprecated/index.js +5 -0
- package/dist/unpkg/dev-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/reactive.js +3 -0
- package/dist/unpkg/dev-deprecated/request.js +49 -0
- package/dist/unpkg/dev-deprecated/runtime-DAu5b0IR.js +135 -0
- package/dist/unpkg/dev-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/dev-deprecated/store/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/store.js +558 -0
- package/dist/unpkg/dev-deprecated/types/-private.js +69 -0
- package/dist/unpkg/dev-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache.js +0 -0
- package/dist/unpkg/dev-deprecated/types/graph.js +0 -0
- package/dist/unpkg/dev-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/dev-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/params.js +0 -0
- package/dist/unpkg/dev-deprecated/types/record.js +191 -0
- package/dist/unpkg/dev-deprecated/types/request.js +77 -0
- package/dist/unpkg/dev-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/dev-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/dev-deprecated/types/utils.js +0 -0
- package/dist/unpkg/dev-deprecated/types.js +0 -0
- package/dist/unpkg/dev-deprecated/utils/string.js +91 -0
- package/dist/unpkg/prod/-leaked-DUONXQDB.js +1676 -0
- package/dist/unpkg/prod/-private-sql1_mdx.js +39 -0
- package/dist/unpkg/prod/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod/build-config/debugging.js +1 -0
- package/dist/unpkg/prod/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod/build-config/env.js +1 -0
- package/dist/unpkg/prod/build-config/macros.js +1 -0
- package/dist/unpkg/prod/build-config.js +1 -0
- package/dist/unpkg/prod/configure.js +2 -0
- package/dist/unpkg/prod/graph/-private.js +2235 -0
- package/dist/unpkg/prod/handler-EU_8ncB2.js +1619 -0
- package/dist/unpkg/prod/index.js +483 -0
- package/dist/unpkg/prod/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod/reactive/-private.js +1 -0
- package/dist/unpkg/prod/reactive.js +30 -0
- package/dist/unpkg/prod/request-BrJSCG6r.js +421 -0
- package/dist/unpkg/prod/request.js +2 -0
- package/dist/unpkg/prod/schema-BSkHyoWz.js +5219 -0
- package/dist/unpkg/prod/signals/-leaked.js +1 -0
- package/dist/unpkg/prod/store/-private.js +126 -0
- package/dist/unpkg/prod/store.js +437 -0
- package/dist/unpkg/prod/types/-private.js +49 -0
- package/dist/unpkg/prod/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod/types/cache/change.js +0 -0
- package/dist/unpkg/prod/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod/types/cache/operations.js +0 -0
- package/dist/unpkg/prod/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod/types/cache.js +0 -0
- package/dist/unpkg/prod/types/graph.js +0 -0
- package/dist/unpkg/prod/types/identifier.js +61 -0
- package/dist/unpkg/prod/types/json/raw.js +0 -0
- package/dist/unpkg/prod/types/params.js +0 -0
- package/dist/unpkg/prod/types/record.js +191 -0
- package/dist/unpkg/prod/types/request.js +77 -0
- package/dist/unpkg/prod/types/runtime.js +34 -0
- package/dist/unpkg/prod/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod/types/schema/fields.js +505 -0
- package/dist/unpkg/prod/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod/types/spec/document.js +0 -0
- package/dist/unpkg/prod/types/spec/error.js +0 -0
- package/dist/unpkg/prod/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod/types/symbols.js +84 -0
- package/dist/unpkg/prod/types/utils.js +0 -0
- package/dist/unpkg/prod/types.js +0 -0
- package/dist/unpkg/prod/utils/string.js +72 -0
- package/dist/unpkg/prod-deprecated/-leaked-DRNv9VIX.js +1676 -0
- package/dist/unpkg/prod-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/prod-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config.js +1 -0
- package/dist/unpkg/prod-deprecated/configure.js +2 -0
- package/dist/unpkg/prod-deprecated/graph/-private.js +2408 -0
- package/dist/unpkg/prod-deprecated/handler-CCIu4sQ3.js +334 -0
- package/dist/unpkg/prod-deprecated/hooks-Dv4Np0MY.js +26 -0
- package/dist/unpkg/prod-deprecated/index.js +483 -0
- package/dist/unpkg/prod-deprecated/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/reactive.js +5 -0
- package/dist/unpkg/prod-deprecated/request-BrJSCG6r.js +421 -0
- package/dist/unpkg/prod-deprecated/request.js +2 -0
- package/dist/unpkg/prod-deprecated/schema-CJcjHv0E.js +6939 -0
- package/dist/unpkg/prod-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/prod-deprecated/store/-private.js +88 -0
- package/dist/unpkg/prod-deprecated/store.js +437 -0
- package/dist/unpkg/prod-deprecated/types/-private.js +49 -0
- package/dist/unpkg/prod-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache.js +0 -0
- package/dist/unpkg/prod-deprecated/types/graph.js +0 -0
- package/dist/unpkg/prod-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/prod-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/params.js +0 -0
- package/dist/unpkg/prod-deprecated/types/record.js +191 -0
- package/dist/unpkg/prod-deprecated/types/request.js +77 -0
- package/dist/unpkg/prod-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/prod-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/prod-deprecated/types/utils.js +0 -0
- package/dist/unpkg/prod-deprecated/types.js +0 -0
- package/dist/unpkg/prod-deprecated/utils/string.js +72 -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 +12 -4
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +0 -24
- package/dist/configure-C3x8YXzL.js +0 -181
- 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
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/configure.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/internal.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/signal.d.ts +0 -0
- /package/dist/{symbols-sql1_mdx.js → unpkg/dev/-private-sql1_mdx.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,384 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { EnableHydration } from './types/request.js';
|
|
7
|
-
export { C as CacheHandler, S as Store, r as recordIdentifierFor, U as setIdentifierForgetMethod, Q as setIdentifierGenerationMethod, V as setIdentifierResetMethod, T as setIdentifierUpdateMethod, W as setKeyInfoForResource, s as storeFor } from "./request-state-C955e0AL.js";
|
|
1
|
+
export { C as CacheHandler, F as Fetch, z as RequestManager, S as Store, r as cacheKeyFor, r as recordIdentifierFor, E as setIdentifierForgetMethod, B as setIdentifierGenerationMethod, G as setIdentifierResetMethod, D as setIdentifierUpdateMethod, H as setKeyInfoForResource, s as storeFor, A as useRecommendedStore } from "./index-CQP2NSqg.js";
|
|
2
|
+
import "./symbols-3C1OkYtZ.js";
|
|
3
|
+
import "./configure-DPUFCemT.js";
|
|
4
|
+
import '@embroider/macros';
|
|
5
|
+
import "./default-cache-policy-D7_u4YRH.js";
|
|
8
6
|
import '@ember/debug';
|
|
9
7
|
import './utils/string.js';
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
// Lazily close over fetch to avoid breaking Mirage
|
|
13
|
-
const _fetch = typeof fetch !== 'undefined' ? (...args) => fetch(...args) : typeof FastBoot !== 'undefined' ? (...args) => FastBoot.require('node-fetch')(...args) : () => {
|
|
14
|
-
throw new Error('No Fetch Implementation Found');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// clones a response in a way that should still
|
|
18
|
-
// allow it to stream
|
|
19
|
-
function cloneResponse(response, overrides) {
|
|
20
|
-
const props = cloneResponseProperties(response);
|
|
21
|
-
return new Response(response.body, Object.assign(props, overrides));
|
|
22
|
-
}
|
|
23
|
-
let IS_MAYBE_MIRAGE = () => false;
|
|
24
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
25
|
-
IS_MAYBE_MIRAGE = () => Boolean(typeof window !== 'undefined' && (window.server?.pretender || window.fetch.toString().replace(/\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\s+/g, '')));
|
|
26
|
-
}
|
|
27
|
-
const MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);
|
|
28
|
-
const ERROR_STATUS_CODE_FOR = new Map([[400, 'Bad Request'], [401, 'Unauthorized'], [402, 'Payment Required'], [403, 'Forbidden'], [404, 'Not Found'], [405, 'Method Not Allowed'], [406, 'Not Acceptable'], [407, 'Proxy Authentication Required'], [408, 'Request Timeout'], [409, 'Conflict'], [410, 'Gone'], [411, 'Length Required'], [412, 'Precondition Failed'], [413, 'Payload Too Large'], [414, 'URI Too Long'], [415, 'Unsupported Media Type'], [416, 'Range Not Satisfiable'], [417, 'Expectation Failed'], [419, 'Page Expired'], [420, 'Enhance Your Calm'], [421, 'Misdirected Request'], [422, 'Unprocessable Entity'], [423, 'Locked'], [424, 'Failed Dependency'], [425, 'Too Early'], [426, 'Upgrade Required'], [428, 'Precondition Required'], [429, 'Too Many Requests'], [430, 'Request Header Fields Too Large'], [431, 'Request Header Fields Too Large'], [450, 'Blocked By Windows Parental Controls'], [451, 'Unavailable For Legal Reasons'], [500, 'Internal Server Error'], [501, 'Not Implemented'], [502, 'Bad Gateway'], [503, 'Service Unavailable'], [504, 'Gateway Timeout'], [505, 'HTTP Version Not Supported'], [506, 'Variant Also Negotiates'], [507, 'Insufficient Storage'], [508, 'Loop Detected'], [509, 'Bandwidth Limit Exceeded'], [510, 'Not Extended'], [511, 'Network Authentication Required']]);
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { Fetch } from '@warp-drive/core';
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* A basic Fetch Handler which converts a request into a
|
|
36
|
-
* `fetch` call presuming the response to be `json`.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* import { RequestManager, Fetch } from '@warp-drive/core';
|
|
40
|
-
*
|
|
41
|
-
* const manager = new RequestManager()
|
|
42
|
-
* .use([Fetch]);
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
const Fetch = {
|
|
48
|
-
async request(context) {
|
|
49
|
-
let response;
|
|
50
|
-
try {
|
|
51
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
52
|
-
if (!test) {
|
|
53
|
-
throw new Error('The Fetch handler expects the request to have a URL, none was provided.');
|
|
54
|
-
}
|
|
55
|
-
})(context.request.url && typeof context.request.url === 'string') : {};
|
|
56
|
-
response = await _fetch(context.request.url, context.request);
|
|
57
|
-
} catch (e) {
|
|
58
|
-
if (e instanceof DOMException && e.name === 'AbortError') {
|
|
59
|
-
e.statusText = 'Aborted';
|
|
60
|
-
e.status = 20;
|
|
61
|
-
e.isRequestError = true;
|
|
62
|
-
} else {
|
|
63
|
-
e.statusText = 'Unknown Network Error';
|
|
64
|
-
e.status = 0;
|
|
65
|
-
if (!(e instanceof DOMException)) {
|
|
66
|
-
e.code = 0;
|
|
67
|
-
}
|
|
68
|
-
e.isRequestError = true;
|
|
69
|
-
}
|
|
70
|
-
throw e;
|
|
71
|
-
}
|
|
72
|
-
const isError = !response.ok || response.status >= 400;
|
|
73
|
-
const op = context.request.op;
|
|
74
|
-
const isMutationOp = Boolean(op && MUTATION_OPS.has(op));
|
|
75
|
-
if (!isError && !isMutationOp && response.status !== 204 && !response.headers.has('date')) {
|
|
76
|
-
if (IS_MAYBE_MIRAGE()) {
|
|
77
|
-
response.headers.set('date', new Date().toUTCString());
|
|
78
|
-
} else {
|
|
79
|
-
const headers = new Headers(response.headers);
|
|
80
|
-
headers.set('date', new Date().toUTCString());
|
|
81
|
-
response = cloneResponse(response, {
|
|
82
|
-
headers
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
context.setResponse(response);
|
|
87
|
-
if (response.status === 204) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
let text = '';
|
|
91
|
-
// if we are in a mirage context, we cannot support streaming
|
|
92
|
-
if (IS_MAYBE_MIRAGE()) {
|
|
93
|
-
text = await response.text();
|
|
94
|
-
} else {
|
|
95
|
-
const reader = response.body.getReader();
|
|
96
|
-
const decoder = new TextDecoder();
|
|
97
|
-
let isStreaming = context.hasRequestedStream;
|
|
98
|
-
let stream = isStreaming ? new TransformStream() : null;
|
|
99
|
-
let writer = stream?.writable.getWriter();
|
|
100
|
-
if (isStreaming) {
|
|
101
|
-
// Listen for the abort event on the AbortSignal
|
|
102
|
-
context.request.signal?.addEventListener('abort', () => {
|
|
103
|
-
if (!isStreaming) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
void stream.writable.abort('Request Aborted');
|
|
107
|
-
void stream.readable.cancel('Request Aborted');
|
|
108
|
-
});
|
|
109
|
-
context.setStream(stream.readable);
|
|
110
|
-
}
|
|
111
|
-
while (true) {
|
|
112
|
-
// we manually read the stream instead of using `response.json()`
|
|
113
|
-
// or `response.text()` because if we need to stream the body
|
|
114
|
-
// we need to be able to pass the stream along efficiently.
|
|
115
|
-
const {
|
|
116
|
-
done,
|
|
117
|
-
value
|
|
118
|
-
} = await reader.read();
|
|
119
|
-
if (done) {
|
|
120
|
-
if (isStreaming) {
|
|
121
|
-
isStreaming = false;
|
|
122
|
-
await writer.ready;
|
|
123
|
-
await writer.close();
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
text += decoder.decode(value, {
|
|
128
|
-
stream: true
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// if we are streaming, we want to pass the stream along
|
|
132
|
-
if (isStreaming) {
|
|
133
|
-
await writer.ready;
|
|
134
|
-
await writer.write(value);
|
|
135
|
-
} else if (context.hasRequestedStream) {
|
|
136
|
-
const encode = new TextEncoder();
|
|
137
|
-
isStreaming = true;
|
|
138
|
-
stream = new TransformStream();
|
|
139
|
-
// Listen for the abort event on the AbortSignal
|
|
140
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
141
|
-
context.request.signal?.addEventListener('abort', () => {
|
|
142
|
-
if (!isStreaming) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
void stream.writable.abort('Request Aborted');
|
|
146
|
-
void stream.readable.cancel('Request Aborted');
|
|
147
|
-
});
|
|
148
|
-
context.setStream(stream.readable);
|
|
149
|
-
writer = stream.writable.getWriter();
|
|
150
|
-
await writer.ready;
|
|
151
|
-
await writer.write(encode.encode(text));
|
|
152
|
-
await writer.ready;
|
|
153
|
-
await writer.write(value);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (isStreaming) {
|
|
157
|
-
isStreaming = false;
|
|
158
|
-
await writer.ready;
|
|
159
|
-
await writer.close();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// if we are an error, we will want to throw
|
|
163
|
-
if (isError) {
|
|
164
|
-
let errorPayload;
|
|
165
|
-
try {
|
|
166
|
-
errorPayload = JSON.parse(text);
|
|
167
|
-
} catch {
|
|
168
|
-
// void;
|
|
169
|
-
}
|
|
170
|
-
// attempt errors discovery
|
|
171
|
-
const errors = Array.isArray(errorPayload) ? errorPayload : isDict(errorPayload) && Array.isArray(errorPayload.errors) ? errorPayload.errors : null;
|
|
172
|
-
const statusText = response.statusText || ERROR_STATUS_CODE_FOR.get(response.status) || 'Unknown Request Error';
|
|
173
|
-
const msg = `[${response.status} ${statusText}] ${context.request.method ?? 'GET'} (${response.type}) - ${response.url}`;
|
|
174
|
-
const error = errors ? new AggregateError(errors, msg) : new Error(msg);
|
|
175
|
-
error.status = response.status;
|
|
176
|
-
error.statusText = statusText;
|
|
177
|
-
error.isRequestError = true;
|
|
178
|
-
error.code = error.status;
|
|
179
|
-
error.name = error.statusText.replaceAll(' ', '') + 'Error';
|
|
180
|
-
error.content = errorPayload;
|
|
181
|
-
throw error;
|
|
182
|
-
} else {
|
|
183
|
-
return JSON.parse(text);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
function isDict(v) {
|
|
188
|
-
return v !== null && typeof v === 'object';
|
|
189
|
-
}
|
|
190
|
-
class RequestManager {
|
|
191
|
-
/** @internal */
|
|
192
|
-
|
|
193
|
-
/** @internal */
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* A map of pending requests from request.id to their
|
|
197
|
-
* associated CacheHandler promise.
|
|
198
|
-
*
|
|
199
|
-
* This queue is managed by the CacheHandler
|
|
200
|
-
*
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
/** @internal */
|
|
205
|
-
|
|
206
|
-
constructor(options) {
|
|
207
|
-
Object.assign(this, options);
|
|
208
|
-
this._pending = new Map();
|
|
209
|
-
this._deduped = new Map();
|
|
210
|
-
this._handlers = [];
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Register a handler to use for primary cache intercept.
|
|
215
|
-
*
|
|
216
|
-
* Only one such handler may exist. If using the same
|
|
217
|
-
* RequestManager as the Store instance the Store
|
|
218
|
-
* registers itself as a Cache handler.
|
|
219
|
-
*
|
|
220
|
-
* @public
|
|
221
|
-
*/
|
|
222
|
-
useCache(cacheHandler) {
|
|
223
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
224
|
-
if (this._hasCacheHandler) {
|
|
225
|
-
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked once.`);
|
|
226
|
-
}
|
|
227
|
-
if (Object.isFrozen(this._handlers)) {
|
|
228
|
-
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked prior to any request having been made.`);
|
|
229
|
-
}
|
|
230
|
-
this._hasCacheHandler = true;
|
|
231
|
-
}
|
|
232
|
-
cacheHandler[IS_CACHE_HANDLER] = true;
|
|
233
|
-
this._handlers.unshift(cacheHandler);
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Register handler(s) to use when a request is issued.
|
|
239
|
-
*
|
|
240
|
-
* Handlers will be invoked in the order they are registered.
|
|
241
|
-
* Each Handler is given the opportunity to handle the request,
|
|
242
|
-
* curry the request, or pass along a modified request.
|
|
243
|
-
*
|
|
244
|
-
* @public
|
|
245
|
-
*/
|
|
246
|
-
use(newHandlers) {
|
|
247
|
-
const handlers = this._handlers;
|
|
248
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
249
|
-
if (Object.isFrozen(handlers)) {
|
|
250
|
-
throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);
|
|
251
|
-
}
|
|
252
|
-
if (!Array.isArray(newHandlers)) {
|
|
253
|
-
throw new Error(`\`RequestManager.use(<Handler[]>)\` expects an array of handlers, but was called with \`${typeof newHandlers}\``);
|
|
254
|
-
}
|
|
255
|
-
newHandlers.forEach((handler, index) => {
|
|
256
|
-
if (!handler || typeof handler !== 'function' && typeof handler !== 'object' || typeof handler.request !== 'function') {
|
|
257
|
-
throw new Error(`\`RequestManager.use(<Handler[]>)\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
handlers.push(...newHandlers);
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Issue a Request.
|
|
267
|
-
*
|
|
268
|
-
* Returns a Future that fulfills with a StructuredDocument
|
|
269
|
-
*
|
|
270
|
-
* @public
|
|
271
|
-
*/
|
|
272
|
-
request(request) {
|
|
273
|
-
const handlers = this._handlers;
|
|
274
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
275
|
-
if (!Object.isFrozen(handlers)) {
|
|
276
|
-
Object.freeze(handlers);
|
|
277
|
-
}
|
|
278
|
-
assertValidRequest(request, true);
|
|
279
|
-
}
|
|
280
|
-
const controller = request.controller || new AbortController();
|
|
281
|
-
if (request.controller) {
|
|
282
|
-
delete request.controller;
|
|
283
|
-
}
|
|
284
|
-
const requestId = peekUniversalTransient('REQ_ID') ?? 0;
|
|
285
|
-
setUniversalTransient('REQ_ID', requestId + 1);
|
|
286
|
-
const context = {
|
|
287
|
-
controller,
|
|
288
|
-
response: null,
|
|
289
|
-
stream: null,
|
|
290
|
-
hasRequestedStream: false,
|
|
291
|
-
id: requestId,
|
|
292
|
-
identifier: null,
|
|
293
|
-
requester: request[EnableHydration] && request.store ? request.store : this
|
|
294
|
-
};
|
|
295
|
-
const promise = executeNextHandler(handlers, request, 0, context);
|
|
296
|
-
|
|
297
|
-
// the cache handler will set the result of the request synchronously
|
|
298
|
-
// if it is able to fulfill the request from the cache
|
|
299
|
-
const cacheResult = getRequestResult(requestId);
|
|
300
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
301
|
-
if (!request.disableTestWaiter) {
|
|
302
|
-
const newPromise = waitFor(promise);
|
|
303
|
-
const finalPromise = upgradePromise(newPromise.then(result => {
|
|
304
|
-
setPromiseResult(finalPromise, {
|
|
305
|
-
isError: false,
|
|
306
|
-
result
|
|
307
|
-
});
|
|
308
|
-
clearRequestResult(requestId);
|
|
309
|
-
return result;
|
|
310
|
-
}, error => {
|
|
311
|
-
setPromiseResult(finalPromise, {
|
|
312
|
-
isError: true,
|
|
313
|
-
result: error
|
|
314
|
-
});
|
|
315
|
-
clearRequestResult(requestId);
|
|
316
|
-
throw error;
|
|
317
|
-
}), promise);
|
|
318
|
-
if (cacheResult) {
|
|
319
|
-
setPromiseResult(finalPromise, cacheResult);
|
|
320
|
-
}
|
|
321
|
-
return finalPromise;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// const promise1 = store.request(myRequest);
|
|
326
|
-
// const promise2 = store.request(myRequest);
|
|
327
|
-
// promise1 === promise2; // false
|
|
328
|
-
// either we need to make promise1 === promise2, or we need to make sure that
|
|
329
|
-
// we need to have a way to key from request to result
|
|
330
|
-
// such that we can lookup the result here and return it if it exists
|
|
331
|
-
const finalPromise = upgradePromise(promise.then(result => {
|
|
332
|
-
setPromiseResult(finalPromise, {
|
|
333
|
-
isError: false,
|
|
334
|
-
result
|
|
335
|
-
});
|
|
336
|
-
clearRequestResult(requestId);
|
|
337
|
-
return result;
|
|
338
|
-
}, error => {
|
|
339
|
-
setPromiseResult(finalPromise, {
|
|
340
|
-
isError: true,
|
|
341
|
-
result: error
|
|
342
|
-
});
|
|
343
|
-
clearRequestResult(requestId);
|
|
344
|
-
throw error;
|
|
345
|
-
}), promise);
|
|
346
|
-
if (cacheResult) {
|
|
347
|
-
setPromiseResult(finalPromise, cacheResult);
|
|
348
|
-
}
|
|
349
|
-
return finalPromise;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* This method exists so that the RequestManager can be created
|
|
354
|
-
* can be created by container/factory systems that expect to
|
|
355
|
-
* call a static `create` method to instantiate the class.
|
|
356
|
-
*
|
|
357
|
-
* Using `new RequestManager()` directly is preferred.
|
|
358
|
-
*
|
|
359
|
-
* @private
|
|
360
|
-
*/
|
|
361
|
-
static create(options) {
|
|
362
|
-
return new this(options);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* This type exists for internal use only for
|
|
368
|
-
* where intimate contracts still exist either for
|
|
369
|
-
* the Test Suite or for Legacy code.
|
|
370
|
-
*
|
|
371
|
-
* @private
|
|
372
|
-
*/
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* @module
|
|
376
|
-
* @mergeModuleWith <project>
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
|
-
// @ts-expect-error adding to globalThis
|
|
380
|
-
globalThis.setWarpDriveLogging = setLogging;
|
|
381
|
-
|
|
382
|
-
// @ts-expect-error adding to globalThis
|
|
383
|
-
globalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;
|
|
384
|
-
export { Fetch, RequestManager };
|
|
8
|
+
import './types/runtime.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as Context } from "../symbols-3C1OkYtZ.js";
|