@warp-drive/core 5.8.0-alpha.9 → 5.8.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.
- package/README.md +22 -38
- package/declarations/configure.d.ts +1 -1
- package/declarations/graph/-private/-edge-definition.d.ts +12 -2
- package/declarations/index.d.ts +14 -9
- package/declarations/reactive/-private/default-mode.d.ts +1 -1
- 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.d.ts +1 -0
- package/declarations/reactive.d.ts +11 -7
- package/declarations/request/-private/types.d.ts +1 -1
- 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 +1 -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 +1 -1
- package/declarations/store/-private/managers/cache-manager.d.ts +1 -14
- 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 +2 -2
- package/declarations/store/-private.d.ts +0 -6
- package/declarations/store/deprecated/-private.d.ts +2 -2
- package/declarations/store/deprecated/store.d.ts +1 -1
- package/declarations/store.d.ts +1 -0
- package/declarations/types/cache.d.ts +2 -2
- package/declarations/types/record.d.ts +132 -0
- package/declarations/types/request.d.ts +22 -8
- package/declarations/types/schema/fields.d.ts +26 -13
- package/declarations/types/schema/schema-service.d.ts +4 -4
- package/declarations/types/spec/document.d.ts +34 -0
- package/dist/configure-DPUFCemT.js +1940 -0
- package/dist/configure.js +2 -1
- package/dist/{request-oqoLC9rz.js → future-BKkJJkj7.js} +1 -48
- package/dist/graph/-private.js +15 -5
- package/dist/{index-B1cSRj-N.js → index-CQP2NSqg.js} +63 -1812
- package/dist/index.js +5 -5
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +4 -129
- package/dist/request.js +49 -1
- package/dist/signals/-leaked.js +1 -0
- package/dist/store/-private.js +1 -2
- 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 +11 -7
- 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 +11 -3
- 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
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { SkipCache, STRUCTURED, IS_FUTURE } from './types/request.js';
|
|
2
|
+
import { getOrSetGlobal, getOrSetUniversal } from './types/-private.js';
|
|
3
|
+
const BODY_TYPES = {
|
|
4
|
+
type: 'string',
|
|
5
|
+
klass: ['Blob', 'ArrayBuffer', 'TypedArray', 'DataView', 'FormData', 'URLSearchParams', 'ReadableStream']
|
|
6
|
+
};
|
|
7
|
+
const ValidKeys = new Map([['duplex', ['half']], ['records', 'array'], ['data', 'json'], ['body', BODY_TYPES], ['disableTestWaiter', 'boolean'], ['options', 'object'], ['cacheOptions', 'object'], ['op', 'string'], ['store', 'object'], ['url', 'string'], ['cache', ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload']], ['credentials', ['include', 'omit', 'same-origin']], ['destination', ['', 'object', 'audio', 'audioworklet', 'document', 'embed', 'font', 'frame', 'iframe', 'image', 'manifest', 'paintworklet', 'report', 'script', 'sharedworker', 'style', 'track', 'video', 'worker', 'xslt']], ['headers', 'headers'], ['integrity', 'string'], ['keepalive', 'boolean'], ['method', ['QUERY', 'GET', 'PUT', 'PATCH', 'DELETE', 'POST', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE']], ['mode', ['same-origin', 'cors', 'navigate', 'no-cors']], ['redirect', ['error', 'follow', 'manual']], ['referrer', 'string'], ['signal', 'AbortSignal'], ['controller', 'AbortController'], ['referrerPolicy', ['', 'same-origin', 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url']]]);
|
|
8
|
+
const IS_FROZEN = getOrSetGlobal('IS_FROZEN', Symbol('FROZEN'));
|
|
9
|
+
const IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));
|
|
10
|
+
function freezeHeaders(headers) {
|
|
11
|
+
headers.delete = headers.set = headers.append = () => {
|
|
12
|
+
throw new Error(`Cannot Mutate Immutatable Headers, use headers.clone to get a copy`);
|
|
13
|
+
};
|
|
14
|
+
upgradeHeaders(headers);
|
|
15
|
+
return headers;
|
|
16
|
+
}
|
|
17
|
+
function deepFreeze(value) {
|
|
18
|
+
if (value && value[IS_FROZEN]) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
const _type = typeof value;
|
|
22
|
+
switch (_type) {
|
|
23
|
+
case 'boolean':
|
|
24
|
+
case 'string':
|
|
25
|
+
case 'number':
|
|
26
|
+
case 'symbol':
|
|
27
|
+
case 'undefined':
|
|
28
|
+
case 'bigint':
|
|
29
|
+
return value;
|
|
30
|
+
case 'function':
|
|
31
|
+
throw new Error(`Cannot deep-freeze a function`);
|
|
32
|
+
case 'object':
|
|
33
|
+
{
|
|
34
|
+
const _niceType = niceTypeOf(value);
|
|
35
|
+
switch (_niceType) {
|
|
36
|
+
case 'array':
|
|
37
|
+
{
|
|
38
|
+
if (value[IS_COLLECTION]) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
const arr = value.map(deepFreeze);
|
|
42
|
+
arr[IS_FROZEN] = true;
|
|
43
|
+
return Object.freeze(arr);
|
|
44
|
+
}
|
|
45
|
+
case 'null':
|
|
46
|
+
return value;
|
|
47
|
+
case 'object':
|
|
48
|
+
Object.keys(value).forEach(key => {
|
|
49
|
+
try {
|
|
50
|
+
value[key] = deepFreeze(value[key]);
|
|
51
|
+
} catch {
|
|
52
|
+
// continue
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
value[IS_FROZEN] = true;
|
|
56
|
+
return Object.freeze(value);
|
|
57
|
+
case 'headers':
|
|
58
|
+
return freezeHeaders(value);
|
|
59
|
+
case 'Collection':
|
|
60
|
+
case 'Store':
|
|
61
|
+
case 'AbortSignal':
|
|
62
|
+
return value;
|
|
63
|
+
case 'date':
|
|
64
|
+
case 'map':
|
|
65
|
+
case 'set':
|
|
66
|
+
case 'error':
|
|
67
|
+
case 'stream':
|
|
68
|
+
default:
|
|
69
|
+
// console.log(`Cannot deep-freeze ${_niceType}`);
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isMaybeContext(request) {
|
|
76
|
+
if (request && typeof request === 'object') {
|
|
77
|
+
const keys = Object.keys(request);
|
|
78
|
+
if (keys.length === 1 && keys[0] === 'request') {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function niceTypeOf(v) {
|
|
85
|
+
if (v === null) {
|
|
86
|
+
return 'null';
|
|
87
|
+
}
|
|
88
|
+
if (typeof v === 'string') {
|
|
89
|
+
return v ? 'non-empty-string' : 'empty-string';
|
|
90
|
+
}
|
|
91
|
+
if (!v) {
|
|
92
|
+
return typeof v;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(v)) {
|
|
95
|
+
return 'array';
|
|
96
|
+
}
|
|
97
|
+
if (v instanceof Date) {
|
|
98
|
+
return 'date';
|
|
99
|
+
}
|
|
100
|
+
if (v instanceof Map) {
|
|
101
|
+
return 'map';
|
|
102
|
+
}
|
|
103
|
+
if (v instanceof Set) {
|
|
104
|
+
return 'set';
|
|
105
|
+
}
|
|
106
|
+
if (v instanceof Error) {
|
|
107
|
+
return 'error';
|
|
108
|
+
}
|
|
109
|
+
if (v instanceof ReadableStream || v instanceof WritableStream || v instanceof TransformStream) {
|
|
110
|
+
return 'stream';
|
|
111
|
+
}
|
|
112
|
+
if (v instanceof Headers) {
|
|
113
|
+
return 'headers';
|
|
114
|
+
}
|
|
115
|
+
if (typeof v === 'object' && v.constructor && v.constructor.name !== 'Object') {
|
|
116
|
+
return v.constructor.name;
|
|
117
|
+
}
|
|
118
|
+
return typeof v;
|
|
119
|
+
}
|
|
120
|
+
function validateKey(key, value, errors) {
|
|
121
|
+
const schema = ValidKeys.get(key);
|
|
122
|
+
if (!schema && !IgnoredKeys.has(key)) {
|
|
123
|
+
errors.push(`InvalidKey: '${key}'`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (schema) {
|
|
127
|
+
if (schema === BODY_TYPES) {
|
|
128
|
+
if (typeof value === 'string' || value instanceof ReadableStream) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const type = niceTypeOf(value);
|
|
132
|
+
if (schema.klass.includes(type)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
errors.push(`InvalidValue: key 'body' should be a string or one of '${schema.klass.join("', '")}', received ${'<a value of type ' + niceTypeOf(value) + '>'}`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(schema)) {
|
|
139
|
+
if (!schema.includes(value)) {
|
|
140
|
+
errors.push(`InvalidValue: key ${key} should be one of '${schema.join("', '")}', received ${typeof value === 'string' ? value : '<a value of type ' + niceTypeOf(value) + '>'}`);
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
} else if (schema === 'json') {
|
|
144
|
+
try {
|
|
145
|
+
JSON.stringify(value);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
errors.push(`InvalidValue: key ${key} should be a JSON serializable value, but failed to serialize with Error - ${e.message}`);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
} else if (schema === 'headers') {
|
|
151
|
+
if (!(value instanceof Headers)) {
|
|
152
|
+
errors.push(`InvalidValue: key ${key} should be an instance of Headers, received ${niceTypeOf(value)}`);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
} else if (schema === 'record') {
|
|
156
|
+
const _type = typeof value;
|
|
157
|
+
// record must extend plain object or Object.create(null)
|
|
158
|
+
if (!value || _type !== 'object' || value.constructor && value.constructor !== Object) {
|
|
159
|
+
errors.push(`InvalidValue: key ${key} should be a dictionary of string keys to string values, received ${niceTypeOf(value)}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const keys = Object.keys(value);
|
|
163
|
+
keys.forEach(k => {
|
|
164
|
+
const v = value[k];
|
|
165
|
+
if (typeof k !== 'string') {
|
|
166
|
+
errors.push(`\tThe key ${String(k)} on ${key} should be a string key`);
|
|
167
|
+
} else if (typeof v !== 'string') {
|
|
168
|
+
errors.push(`\tThe value of ${key}.${k} should be a string not ${niceTypeOf(v)}`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
} else if (schema === 'string') {
|
|
173
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
174
|
+
errors.push(`InvalidValue: key ${key} should be a non-empty string, received ${typeof value === 'string' ? "''" : typeof value}`);
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
} else if (schema === 'object') {
|
|
178
|
+
if (!value || Array.isArray(value) || typeof value !== 'object') {
|
|
179
|
+
errors.push(`InvalidValue: key ${key} should be an object`);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
} else if (schema === 'boolean') {
|
|
183
|
+
if (typeof value !== 'boolean') {
|
|
184
|
+
errors.push(`InvalidValue: key ${key} should be a boolean, received ${typeof value}`);
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
} else if (schema === 'array') {
|
|
188
|
+
if (!Array.isArray(value)) {
|
|
189
|
+
errors.push(`InvalidValue: key ${key} should be an array, received ${typeof value}`);
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const IgnoredKeys = new Set([]);
|
|
196
|
+
function assertValidRequest(request, isTopLevel) {
|
|
197
|
+
{
|
|
198
|
+
// handle basic shape
|
|
199
|
+
if (!request) {
|
|
200
|
+
throw new Error(`Expected ${isTopLevel ? 'RequestManager.request' : 'next'}(<request>) to be called with a request, but none was provided.`);
|
|
201
|
+
}
|
|
202
|
+
if (Array.isArray(request) || typeof request !== 'object') {
|
|
203
|
+
throw new Error(`The \`request\` passed to \`${isTopLevel ? 'RequestManager.request' : 'next'}(<request>)\` should be an object, received \`${niceTypeOf(request)}\``);
|
|
204
|
+
}
|
|
205
|
+
if (Object.keys(request).length === 0) {
|
|
206
|
+
throw new Error(`The \`request\` passed to \`${isTopLevel ? 'RequestManager.request' : 'next'}(<request>)\` was empty (\`{}\`). Requests need at least one valid key.`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// handle accidentally passing context entirely
|
|
210
|
+
if (request instanceof Context) {
|
|
211
|
+
throw new Error(`Expected a request passed to \`${isTopLevel ? 'RequestManager.request' : 'next'}(<request>)\` but received the previous handler's context instead`);
|
|
212
|
+
}
|
|
213
|
+
// handle Object.assign({}, context);
|
|
214
|
+
if (isMaybeContext(request)) {
|
|
215
|
+
throw new Error(`Expected a request passed to \`${isTopLevel ? 'RequestManager.request' : 'next'}(<request>)\` but received an object with a request key instead.`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// handle schema
|
|
219
|
+
const keys = Object.keys(request);
|
|
220
|
+
const validationErrors = [];
|
|
221
|
+
const isLegacyRequest = Boolean('op' in request && !request.url);
|
|
222
|
+
keys.forEach(key => {
|
|
223
|
+
if (isLegacyRequest && key === 'data') {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
validateKey(key, request[key], validationErrors);
|
|
227
|
+
});
|
|
228
|
+
if (validationErrors.length) {
|
|
229
|
+
const error = new Error(`Invalid Request passed to \`${isTopLevel ? 'RequestManager.request' : 'next'}(<request>)\`.\n\nThe following issues were found:\n\n\t${validationErrors.join('\n\t')}`);
|
|
230
|
+
error.errors = validationErrors;
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function upgradeHeaders(headers) {
|
|
236
|
+
headers.clone = () => {
|
|
237
|
+
return new Headers(headers);
|
|
238
|
+
};
|
|
239
|
+
headers.toJSON = () => {
|
|
240
|
+
return Array.from(headers);
|
|
241
|
+
};
|
|
242
|
+
return headers;
|
|
243
|
+
}
|
|
244
|
+
function cloneResponseProperties(response) {
|
|
245
|
+
const {
|
|
246
|
+
headers,
|
|
247
|
+
ok,
|
|
248
|
+
redirected,
|
|
249
|
+
status,
|
|
250
|
+
statusText,
|
|
251
|
+
type,
|
|
252
|
+
url
|
|
253
|
+
} = response;
|
|
254
|
+
upgradeHeaders(headers);
|
|
255
|
+
return {
|
|
256
|
+
headers: headers,
|
|
257
|
+
ok,
|
|
258
|
+
redirected,
|
|
259
|
+
status,
|
|
260
|
+
statusText,
|
|
261
|
+
type,
|
|
262
|
+
url
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
class ContextOwner {
|
|
266
|
+
hasSetStream = false;
|
|
267
|
+
hasSetResponse = false;
|
|
268
|
+
hasSubscribers = false;
|
|
269
|
+
stream = createDeferred();
|
|
270
|
+
response = null;
|
|
271
|
+
nextCalled = 0;
|
|
272
|
+
constructor(request, god, isRoot = false) {
|
|
273
|
+
this.isRoot = isRoot;
|
|
274
|
+
this.requestId = god.id;
|
|
275
|
+
this.controller = request.controller || god.controller;
|
|
276
|
+
this.stream.promise.sizeHint = 0;
|
|
277
|
+
if (request.controller) {
|
|
278
|
+
if (request.controller !== god.controller) {
|
|
279
|
+
god.controller.signal.addEventListener('abort', () => {
|
|
280
|
+
this.controller.abort(god.controller.signal.reason);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
delete request.controller;
|
|
284
|
+
}
|
|
285
|
+
let enhancedRequest = Object.assign({
|
|
286
|
+
signal: this.controller.signal
|
|
287
|
+
}, request);
|
|
288
|
+
{
|
|
289
|
+
if (!request?.cacheOptions?.[SkipCache]) {
|
|
290
|
+
request = deepFreeze(request);
|
|
291
|
+
enhancedRequest = deepFreeze(enhancedRequest);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
this.enhancedRequest = enhancedRequest;
|
|
295
|
+
this.request = request;
|
|
296
|
+
this.god = god;
|
|
297
|
+
this.stream.promise = this.stream.promise.then(stream => {
|
|
298
|
+
if (this.god.stream === stream && this.hasSubscribers) {
|
|
299
|
+
this.god.stream = null;
|
|
300
|
+
}
|
|
301
|
+
return stream;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
get hasRequestedStream() {
|
|
305
|
+
return this.god.hasRequestedStream;
|
|
306
|
+
}
|
|
307
|
+
getResponse() {
|
|
308
|
+
if (this.hasSetResponse) {
|
|
309
|
+
return this.response;
|
|
310
|
+
}
|
|
311
|
+
if (this.nextCalled === 1) {
|
|
312
|
+
return this.god.response;
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
getStream() {
|
|
317
|
+
if (this.isRoot) {
|
|
318
|
+
this.god.hasRequestedStream = true;
|
|
319
|
+
}
|
|
320
|
+
if (!this.hasSetResponse) {
|
|
321
|
+
const hint = this.god.response?.headers?.get('content-length');
|
|
322
|
+
this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;
|
|
323
|
+
}
|
|
324
|
+
this.hasSubscribers = true;
|
|
325
|
+
return this.stream.promise;
|
|
326
|
+
}
|
|
327
|
+
abort(reason) {
|
|
328
|
+
this.controller.abort(reason);
|
|
329
|
+
}
|
|
330
|
+
setStream(stream) {
|
|
331
|
+
if (!this.hasSetStream) {
|
|
332
|
+
this.hasSetStream = true;
|
|
333
|
+
if (!(stream instanceof Promise)) {
|
|
334
|
+
this.god.stream = stream;
|
|
335
|
+
}
|
|
336
|
+
// @ts-expect-error
|
|
337
|
+
this.stream.resolve(stream);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
resolveStream() {
|
|
341
|
+
this.setStream(this.nextCalled === 1 ? this.god.stream : null);
|
|
342
|
+
}
|
|
343
|
+
setResponse(response) {
|
|
344
|
+
if (this.hasSetResponse) {
|
|
345
|
+
{
|
|
346
|
+
throw new Error(`Cannot setResponse when a response has already been set`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
this.hasSetResponse = true;
|
|
350
|
+
if (response instanceof Response) {
|
|
351
|
+
// TODO potentially avoid cloning in prod
|
|
352
|
+
let responseData = cloneResponseProperties(response);
|
|
353
|
+
{
|
|
354
|
+
responseData = deepFreeze(responseData);
|
|
355
|
+
}
|
|
356
|
+
this.response = responseData;
|
|
357
|
+
this.god.response = responseData;
|
|
358
|
+
const sizeHint = response.headers?.get('content-length');
|
|
359
|
+
this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;
|
|
360
|
+
} else {
|
|
361
|
+
this.response = response;
|
|
362
|
+
this.god.response = response;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
class Context {
|
|
367
|
+
/** @internal */
|
|
368
|
+
|
|
369
|
+
/** @internal */
|
|
370
|
+
|
|
371
|
+
/** @internal */
|
|
372
|
+
|
|
373
|
+
constructor(owner, isCacheHandler) {
|
|
374
|
+
this.id = owner.requestId;
|
|
375
|
+
this.___owner = owner;
|
|
376
|
+
this.request = owner.enhancedRequest;
|
|
377
|
+
this._isCacheHandler = isCacheHandler;
|
|
378
|
+
this._finalized = false;
|
|
379
|
+
}
|
|
380
|
+
setStream(stream) {
|
|
381
|
+
this.___owner.setStream(stream);
|
|
382
|
+
}
|
|
383
|
+
setResponse(response) {
|
|
384
|
+
this.___owner.setResponse(response);
|
|
385
|
+
}
|
|
386
|
+
setIdentifier(identifier) {
|
|
387
|
+
(test => {
|
|
388
|
+
if (!test) {
|
|
389
|
+
throw new Error(`setIdentifier may only be used synchronously from a CacheHandler`);
|
|
390
|
+
}
|
|
391
|
+
})(identifier && this._isCacheHandler && !this._finalized);
|
|
392
|
+
this.___owner.god.identifier = identifier;
|
|
393
|
+
}
|
|
394
|
+
get hasRequestedStream() {
|
|
395
|
+
return this.___owner.hasRequestedStream;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** @private */
|
|
399
|
+
_finalize() {
|
|
400
|
+
this._finalized = true;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap());
|
|
404
|
+
const RequestMap = getOrSetUniversal('RequestMap', new Map());
|
|
405
|
+
function setRequestResult(requestId, result) {
|
|
406
|
+
RequestMap.set(requestId, result);
|
|
407
|
+
}
|
|
408
|
+
function clearRequestResult(requestId) {
|
|
409
|
+
RequestMap.delete(requestId);
|
|
410
|
+
}
|
|
411
|
+
function getRequestResult(requestId) {
|
|
412
|
+
return RequestMap.get(requestId);
|
|
413
|
+
}
|
|
414
|
+
function setPromiseResult(promise, result) {
|
|
415
|
+
PromiseCache.set(promise, result);
|
|
416
|
+
}
|
|
417
|
+
function getPromiseResult(promise) {
|
|
418
|
+
return PromiseCache.get(promise);
|
|
419
|
+
}
|
|
420
|
+
const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));
|
|
421
|
+
function curryFuture(owner, inbound, outbound) {
|
|
422
|
+
owner.setStream(inbound.getStream());
|
|
423
|
+
inbound.then(doc => {
|
|
424
|
+
const document = {
|
|
425
|
+
[STRUCTURED]: true,
|
|
426
|
+
request: owner.request,
|
|
427
|
+
response: doc.response,
|
|
428
|
+
content: doc.content
|
|
429
|
+
};
|
|
430
|
+
outbound.resolve(document);
|
|
431
|
+
}, error => {
|
|
432
|
+
if (isDoc(error)) {
|
|
433
|
+
owner.setStream(owner.god.stream);
|
|
434
|
+
}
|
|
435
|
+
if (!error || !(error instanceof Error)) {
|
|
436
|
+
try {
|
|
437
|
+
throw new Error(error ? error : `Request Rejected with an Unknown Error`);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
if (error && typeof error === 'object') {
|
|
440
|
+
Object.assign(e, error);
|
|
441
|
+
e.message = error.message || `Request Rejected with an Unknown Error`;
|
|
442
|
+
}
|
|
443
|
+
error = e;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
error[STRUCTURED] = true;
|
|
447
|
+
error.request = owner.request;
|
|
448
|
+
error.response = owner.getResponse();
|
|
449
|
+
error.error = error.error || error.message;
|
|
450
|
+
outbound.reject(error);
|
|
451
|
+
});
|
|
452
|
+
return outbound.promise;
|
|
453
|
+
}
|
|
454
|
+
function isDoc(doc) {
|
|
455
|
+
return doc && doc[STRUCTURED] === true;
|
|
456
|
+
}
|
|
457
|
+
function ensureDoc(owner, content, isError) {
|
|
458
|
+
if (isDoc(content)) {
|
|
459
|
+
return content;
|
|
460
|
+
}
|
|
461
|
+
if (isError) {
|
|
462
|
+
return {
|
|
463
|
+
[STRUCTURED]: true,
|
|
464
|
+
request: owner.request,
|
|
465
|
+
response: owner.getResponse(),
|
|
466
|
+
error: content
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
[STRUCTURED]: true,
|
|
471
|
+
request: owner.request,
|
|
472
|
+
response: owner.getResponse(),
|
|
473
|
+
content: content
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Additional properties exposed on errors thrown by the
|
|
479
|
+
* {@link Fetch | Fetch Handler}.
|
|
480
|
+
*
|
|
481
|
+
* In the case of an Abort or system/browser level issue,
|
|
482
|
+
* this extends {@link DOMException}.
|
|
483
|
+
*
|
|
484
|
+
* Else it extends from {@link AggregateError} if the
|
|
485
|
+
* response includes an array of errors, falling back
|
|
486
|
+
* to {@link Error} as its base.
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
function enhanceReason(reason) {
|
|
490
|
+
return new DOMException(reason || 'The user aborted a request.', 'AbortError');
|
|
491
|
+
}
|
|
492
|
+
function handleOutcome(owner, inbound, outbound) {
|
|
493
|
+
inbound.then(content => {
|
|
494
|
+
if (owner.controller.signal.aborted) {
|
|
495
|
+
// the next function did not respect the signal, we handle it here
|
|
496
|
+
outbound.reject(enhanceReason(owner.controller.signal.reason));
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (isDoc(content)) {
|
|
500
|
+
owner.setStream(owner.god.stream);
|
|
501
|
+
content = content.content;
|
|
502
|
+
}
|
|
503
|
+
const document = {
|
|
504
|
+
[STRUCTURED]: true,
|
|
505
|
+
request: owner.request,
|
|
506
|
+
response: owner.getResponse(),
|
|
507
|
+
content
|
|
508
|
+
};
|
|
509
|
+
outbound.resolve(document);
|
|
510
|
+
}, error => {
|
|
511
|
+
if (isDoc(error)) {
|
|
512
|
+
owner.setStream(owner.god.stream);
|
|
513
|
+
}
|
|
514
|
+
if (!error || !(error instanceof Error)) {
|
|
515
|
+
try {
|
|
516
|
+
throw new Error(error ? error : `Request Rejected with an Unknown Error`);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
if (error && typeof error === 'object') {
|
|
519
|
+
Object.assign(e, error);
|
|
520
|
+
e.message = error.message || `Request Rejected with an Unknown Error`;
|
|
521
|
+
}
|
|
522
|
+
error = e;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
error[STRUCTURED] = true;
|
|
526
|
+
error.request = owner.request;
|
|
527
|
+
error.response = owner.getResponse();
|
|
528
|
+
error.error = error.error || error.message;
|
|
529
|
+
outbound.reject(error);
|
|
530
|
+
});
|
|
531
|
+
return outbound.promise;
|
|
532
|
+
}
|
|
533
|
+
function isCacheHandler(handler, index) {
|
|
534
|
+
return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);
|
|
535
|
+
}
|
|
536
|
+
function executeNextHandler(wares, request, i, god) {
|
|
537
|
+
{
|
|
538
|
+
if (i === wares.length) {
|
|
539
|
+
throw new Error(`No handler was able to handle this request.`);
|
|
540
|
+
}
|
|
541
|
+
assertValidRequest(request, false);
|
|
542
|
+
}
|
|
543
|
+
const owner = new ContextOwner(request, god, i === 0);
|
|
544
|
+
function next(r) {
|
|
545
|
+
owner.nextCalled++;
|
|
546
|
+
return executeNextHandler(wares, r, i + 1, god);
|
|
547
|
+
}
|
|
548
|
+
const _isCacheHandler = isCacheHandler(wares[i], i);
|
|
549
|
+
const context = new Context(owner, _isCacheHandler);
|
|
550
|
+
let outcome;
|
|
551
|
+
try {
|
|
552
|
+
outcome = wares[i].request(context, next);
|
|
553
|
+
if (_isCacheHandler) {
|
|
554
|
+
context._finalize();
|
|
555
|
+
}
|
|
556
|
+
if (!!outcome && _isCacheHandler) {
|
|
557
|
+
if (!(outcome instanceof Promise)) {
|
|
558
|
+
setRequestResult(owner.requestId, {
|
|
559
|
+
isError: false,
|
|
560
|
+
result: ensureDoc(owner, outcome, false)
|
|
561
|
+
});
|
|
562
|
+
outcome = Promise.resolve(outcome);
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
if (!outcome || !(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome)) {
|
|
566
|
+
// eslint-disable-next-line no-console
|
|
567
|
+
console.log({
|
|
568
|
+
request,
|
|
569
|
+
handler: wares[i],
|
|
570
|
+
outcome
|
|
571
|
+
});
|
|
572
|
+
if (outcome === undefined) {
|
|
573
|
+
throw new Error(`Expected handler.request to return a promise, instead received undefined.`);
|
|
574
|
+
}
|
|
575
|
+
throw new Error(`Expected handler.request to return a promise, instead received a synchronous value.`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
} catch (e) {
|
|
579
|
+
if (_isCacheHandler) {
|
|
580
|
+
setRequestResult(owner.requestId, {
|
|
581
|
+
isError: true,
|
|
582
|
+
result: ensureDoc(owner, e, true)
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
586
|
+
outcome = Promise.reject(e);
|
|
587
|
+
}
|
|
588
|
+
const future = createFuture(owner);
|
|
589
|
+
if (isFuture(outcome)) {
|
|
590
|
+
return curryFuture(owner, outcome, future);
|
|
591
|
+
}
|
|
592
|
+
return handleOutcome(owner, outcome, future);
|
|
593
|
+
}
|
|
594
|
+
function isFuture(maybe) {
|
|
595
|
+
return Boolean(maybe && maybe instanceof Promise && maybe[IS_FUTURE] === true);
|
|
596
|
+
}
|
|
597
|
+
function createDeferred() {
|
|
598
|
+
let resolve;
|
|
599
|
+
let reject;
|
|
600
|
+
const promise = new Promise((res, rej) => {
|
|
601
|
+
resolve = res;
|
|
602
|
+
reject = rej;
|
|
603
|
+
});
|
|
604
|
+
return {
|
|
605
|
+
resolve,
|
|
606
|
+
reject,
|
|
607
|
+
promise
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function upgradePromise(promise, future) {
|
|
611
|
+
promise[IS_FUTURE] = true;
|
|
612
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
613
|
+
promise.getStream = future.getStream;
|
|
614
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
615
|
+
promise.abort = future.abort;
|
|
616
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
617
|
+
promise.onFinalize = future.onFinalize;
|
|
618
|
+
promise.id = future.id;
|
|
619
|
+
promise.lid = future.lid;
|
|
620
|
+
promise.requester = future.requester;
|
|
621
|
+
{
|
|
622
|
+
// @ts-expect-error
|
|
623
|
+
promise.toJSON = () => {
|
|
624
|
+
const id = 'Future<' + promise.id + '>';
|
|
625
|
+
if (promise.lid) {
|
|
626
|
+
return `${id} (${promise.lid.lid})`;
|
|
627
|
+
}
|
|
628
|
+
return id;
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
return promise;
|
|
632
|
+
}
|
|
633
|
+
function createFuture(owner) {
|
|
634
|
+
const deferred = createDeferred();
|
|
635
|
+
let {
|
|
636
|
+
promise
|
|
637
|
+
} = deferred;
|
|
638
|
+
let cbs;
|
|
639
|
+
promise = promise.finally(() => {
|
|
640
|
+
owner.resolveStream();
|
|
641
|
+
if (cbs) {
|
|
642
|
+
cbs.forEach(cb => cb());
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
promise.onFinalize = fn => {
|
|
646
|
+
cbs = cbs || [];
|
|
647
|
+
cbs.push(fn);
|
|
648
|
+
};
|
|
649
|
+
promise[IS_FUTURE] = true;
|
|
650
|
+
promise.getStream = () => {
|
|
651
|
+
return owner.getStream();
|
|
652
|
+
};
|
|
653
|
+
promise.abort = reason => {
|
|
654
|
+
owner.abort(enhanceReason(reason));
|
|
655
|
+
};
|
|
656
|
+
promise.id = owner.requestId;
|
|
657
|
+
promise.lid = owner.god.identifier;
|
|
658
|
+
promise.requester = owner.god.requester;
|
|
659
|
+
{
|
|
660
|
+
// @ts-expect-error
|
|
661
|
+
promise.toJSON = () => {
|
|
662
|
+
const id = 'Future<' + promise.id + '>';
|
|
663
|
+
if (promise.lid) {
|
|
664
|
+
return `${id} (${promise.lid.lid})`;
|
|
665
|
+
}
|
|
666
|
+
return id;
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
deferred.promise = promise;
|
|
670
|
+
return deferred;
|
|
671
|
+
}
|
|
672
|
+
export { IS_CACHE_HANDLER as I, cloneResponseProperties as a, assertValidRequest as b, createDeferred as c, getRequestResult as d, executeNextHandler as e, clearRequestResult as f, getPromiseResult as g, setPromiseResult as s, upgradePromise as u };
|