@isograph/react 0.5.0 → 0.5.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/.turbo/turbo-compile-libs.log +9 -2
- package/dist/_virtual/rolldown_runtime.js +25 -0
- package/dist/core/FragmentReference.d.mts +38 -0
- package/dist/core/FragmentReference.d.mts.map +1 -0
- package/dist/core/FragmentReference.d.ts +31 -29
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/FragmentReference.js +7 -5
- package/dist/core/FragmentReference.mjs +10 -0
- package/dist/core/FragmentReference.mjs.map +1 -0
- package/dist/core/IsographEnvironment.d.mts +89 -0
- package/dist/core/IsographEnvironment.d.mts.map +1 -0
- package/dist/core/IsographEnvironment.d.ts +76 -79
- package/dist/core/IsographEnvironment.d.ts.map +1 -1
- package/dist/core/IsographEnvironment.js +60 -82
- package/dist/core/IsographEnvironment.mjs +67 -0
- package/dist/core/IsographEnvironment.mjs.map +1 -0
- package/dist/core/PromiseWrapper.d.mts +36 -0
- package/dist/core/PromiseWrapper.d.mts.map +1 -0
- package/dist/core/PromiseWrapper.d.ts +26 -23
- package/dist/core/PromiseWrapper.d.ts.map +1 -1
- package/dist/core/PromiseWrapper.js +45 -43
- package/dist/core/PromiseWrapper.mjs +49 -0
- package/dist/core/PromiseWrapper.mjs.map +1 -0
- package/dist/core/areEqualWithDeepComparison.js +56 -108
- package/dist/core/areEqualWithDeepComparison.mjs +62 -0
- package/dist/core/areEqualWithDeepComparison.mjs.map +1 -0
- package/dist/core/brand.d.mts +19 -0
- package/dist/core/brand.d.mts.map +1 -0
- package/dist/core/brand.d.ts +6 -6
- package/dist/core/brand.d.ts.map +1 -1
- package/dist/core/cache.d.mts +20 -0
- package/dist/core/cache.d.mts.map +1 -0
- package/dist/core/cache.d.ts +18 -37
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +203 -537
- package/dist/core/cache.mjs +237 -0
- package/dist/core/cache.mjs.map +1 -0
- package/dist/core/check.d.mts +28 -0
- package/dist/core/check.d.mts.map +1 -0
- package/dist/core/check.d.ts +21 -19
- package/dist/core/check.d.ts.map +1 -1
- package/dist/core/check.js +80 -127
- package/dist/core/check.mjs +84 -0
- package/dist/core/check.mjs.map +1 -0
- package/dist/core/componentCache.js +9 -35
- package/dist/core/componentCache.mjs +12 -0
- package/dist/core/componentCache.mjs.map +1 -0
- package/dist/core/entrypoint.d.mts +99 -0
- package/dist/core/entrypoint.d.mts.map +1 -0
- package/dist/core/entrypoint.d.ts +83 -78
- package/dist/core/entrypoint.d.ts.map +1 -1
- package/dist/core/entrypoint.js +6 -5
- package/dist/core/entrypoint.mjs +8 -0
- package/dist/core/entrypoint.mjs.map +1 -0
- package/dist/core/garbageCollection.d.mts +18 -0
- package/dist/core/garbageCollection.d.mts.map +1 -0
- package/dist/core/garbageCollection.d.ts +15 -16
- package/dist/core/garbageCollection.d.ts.map +1 -1
- package/dist/core/garbageCollection.js +76 -115
- package/dist/core/garbageCollection.mjs +89 -0
- package/dist/core/garbageCollection.mjs.map +1 -0
- package/dist/core/getOrCreateCacheForArtifact.js +37 -0
- package/dist/core/getOrCreateCacheForArtifact.mjs +38 -0
- package/dist/core/getOrCreateCacheForArtifact.mjs.map +1 -0
- package/dist/core/logging.d.mts +95 -0
- package/dist/core/logging.d.mts.map +1 -0
- package/dist/core/logging.d.ts +66 -61
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/logging.js +17 -18
- package/dist/core/logging.mjs +20 -0
- package/dist/core/logging.mjs.map +1 -0
- package/dist/core/makeNetworkRequest.d.mts +13 -0
- package/dist/core/makeNetworkRequest.d.mts.map +1 -0
- package/dist/core/makeNetworkRequest.d.ts +12 -10
- package/dist/core/makeNetworkRequest.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.js +180 -264
- package/dist/core/makeNetworkRequest.mjs +195 -0
- package/dist/core/makeNetworkRequest.mjs.map +1 -0
- package/dist/core/optimisticProxy.d.mts +43 -0
- package/dist/core/optimisticProxy.d.mts.map +1 -0
- package/dist/core/optimisticProxy.d.ts +37 -53
- package/dist/core/optimisticProxy.d.ts.map +1 -1
- package/dist/core/optimisticProxy.js +245 -371
- package/dist/core/optimisticProxy.mjs +268 -0
- package/dist/core/optimisticProxy.mjs.map +1 -0
- package/dist/core/read.d.mts +29 -0
- package/dist/core/read.d.mts.map +1 -0
- package/dist/core/read.d.ts +23 -28
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +435 -650
- package/dist/core/read.mjs +456 -0
- package/dist/core/read.mjs.map +1 -0
- package/dist/core/reader.d.mts +89 -0
- package/dist/core/reader.d.mts.map +1 -0
- package/dist/core/reader.d.ts +78 -77
- package/dist/core/reader.d.ts.map +1 -1
- package/dist/core/startUpdate.js +115 -152
- package/dist/core/startUpdate.mjs +125 -0
- package/dist/core/startUpdate.mjs.map +1 -0
- package/dist/core/subscribe.d.mts +12 -0
- package/dist/core/subscribe.d.mts.map +1 -0
- package/dist/core/subscribe.d.ts +12 -0
- package/dist/core/subscribe.d.ts.map +1 -0
- package/dist/core/subscribe.js +79 -0
- package/dist/core/subscribe.mjs +79 -0
- package/dist/core/subscribe.mjs.map +1 -0
- package/dist/core/util.d.mts +27 -0
- package/dist/core/util.d.mts.map +1 -0
- package/dist/core/util.d.ts +21 -17
- package/dist/core/util.d.ts.map +1 -1
- package/dist/core/util.js +22 -2
- package/dist/core/util.mjs +21 -0
- package/dist/core/util.mjs.map +1 -0
- package/dist/core/writeData.d.mts +11 -0
- package/dist/core/writeData.d.mts.map +1 -0
- package/dist/core/writeData.d.ts +11 -0
- package/dist/core/writeData.d.ts.map +1 -0
- package/dist/core/writeData.js +41 -0
- package/dist/core/writeData.mjs +42 -0
- package/dist/core/writeData.mjs.map +1 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -29
- package/dist/index.js +70 -69
- package/dist/index.mjs +31 -0
- package/dist/loadable-hooks/useClientSideDefer.d.mts +12 -0
- package/dist/loadable-hooks/useClientSideDefer.d.mts.map +1 -0
- package/dist/loadable-hooks/useClientSideDefer.d.ts +9 -12
- package/dist/loadable-hooks/useClientSideDefer.d.ts.map +1 -1
- package/dist/loadable-hooks/useClientSideDefer.js +13 -44
- package/dist/loadable-hooks/useClientSideDefer.mjs +14 -0
- package/dist/loadable-hooks/useClientSideDefer.mjs.map +1 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.d.mts +33 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.d.mts.map +1 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +26 -22
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.js +133 -172
- package/dist/loadable-hooks/useConnectionSpecPagination.mjs +134 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.mjs.map +1 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.mts +8 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.mts.map +1 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +6 -3
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -1
- package/dist/loadable-hooks/useImperativeExposedMutationField.js +9 -12
- package/dist/loadable-hooks/useImperativeExposedMutationField.mjs +11 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.mjs.map +1 -0
- package/dist/loadable-hooks/useImperativeLoadableField.d.mts +19 -0
- package/dist/loadable-hooks/useImperativeLoadableField.d.mts.map +1 -0
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts +15 -11
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts.map +1 -1
- package/dist/loadable-hooks/useImperativeLoadableField.js +16 -12
- package/dist/loadable-hooks/useImperativeLoadableField.mjs +17 -0
- package/dist/loadable-hooks/useImperativeLoadableField.mjs.map +1 -0
- package/dist/loadable-hooks/useSkipLimitPagination.d.mts +24 -0
- package/dist/loadable-hooks/useSkipLimitPagination.d.mts.map +1 -0
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts +19 -15
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.js +118 -160
- package/dist/loadable-hooks/useSkipLimitPagination.mjs +119 -0
- package/dist/loadable-hooks/useSkipLimitPagination.mjs.map +1 -0
- package/dist/react/FragmentReader.d.mts +18 -0
- package/dist/react/FragmentReader.d.mts.map +1 -0
- package/dist/react/FragmentReader.d.ts +16 -8
- package/dist/react/FragmentReader.d.ts.map +1 -1
- package/dist/react/FragmentReader.js +8 -7
- package/dist/react/FragmentReader.mjs +10 -0
- package/dist/react/FragmentReader.mjs.map +1 -0
- package/dist/react/FragmentRenderer.d.mts +20 -0
- package/dist/react/FragmentRenderer.d.mts.map +1 -0
- package/dist/react/FragmentRenderer.d.ts +18 -14
- package/dist/react/FragmentRenderer.d.ts.map +1 -1
- package/dist/react/FragmentRenderer.js +11 -33
- package/dist/react/FragmentRenderer.mjs +12 -0
- package/dist/react/FragmentRenderer.mjs.map +1 -0
- package/dist/react/IsographEnvironmentProvider.d.mts +17 -0
- package/dist/react/IsographEnvironmentProvider.d.mts.map +1 -0
- package/dist/react/IsographEnvironmentProvider.d.ts +15 -9
- package/dist/react/IsographEnvironmentProvider.d.ts.map +1 -1
- package/dist/react/IsographEnvironmentProvider.js +15 -39
- package/dist/react/IsographEnvironmentProvider.mjs +17 -0
- package/dist/react/IsographEnvironmentProvider.mjs.map +1 -0
- package/dist/react/LoadableFieldReader.d.mts +21 -0
- package/dist/react/LoadableFieldReader.d.mts.map +1 -0
- package/dist/react/LoadableFieldReader.d.ts +15 -12
- package/dist/react/LoadableFieldReader.d.ts.map +1 -1
- package/dist/react/LoadableFieldReader.js +13 -47
- package/dist/react/LoadableFieldReader.mjs +14 -0
- package/dist/react/LoadableFieldReader.mjs.map +1 -0
- package/dist/react/LoadableFieldRenderer.d.mts +22 -0
- package/dist/react/LoadableFieldRenderer.d.mts.map +1 -0
- package/dist/react/LoadableFieldRenderer.d.ts +16 -13
- package/dist/react/LoadableFieldRenderer.d.ts.map +1 -1
- package/dist/react/LoadableFieldRenderer.js +13 -70
- package/dist/react/LoadableFieldRenderer.mjs +14 -0
- package/dist/react/LoadableFieldRenderer.mjs.map +1 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.mts +18 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.mts.map +1 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts +11 -3
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts.map +1 -1
- package/dist/react/RenderAfterCommit__DO_NOT_USE.js +17 -13
- package/dist/react/RenderAfterCommit__DO_NOT_USE.mjs +18 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.mjs.map +1 -0
- package/dist/react/createIsographEnvironment.d.mts +9 -0
- package/dist/react/createIsographEnvironment.d.mts.map +1 -0
- package/dist/react/createIsographEnvironment.d.ts +8 -0
- package/dist/react/createIsographEnvironment.d.ts.map +1 -0
- package/dist/react/createIsographEnvironment.js +10 -0
- package/dist/react/createIsographEnvironment.mjs +11 -0
- package/dist/react/createIsographEnvironment.mjs.map +1 -0
- package/dist/react/maybeUnwrapNetworkRequest.js +11 -0
- package/dist/react/maybeUnwrapNetworkRequest.mjs +12 -0
- package/dist/react/maybeUnwrapNetworkRequest.mjs.map +1 -0
- package/dist/react/useImperativeReference.d.mts +15 -0
- package/dist/react/useImperativeReference.d.mts.map +1 -0
- package/dist/react/useImperativeReference.d.ts +13 -8
- package/dist/react/useImperativeReference.d.ts.map +1 -1
- package/dist/react/useImperativeReference.js +34 -30
- package/dist/react/useImperativeReference.mjs +35 -0
- package/dist/react/useImperativeReference.mjs.map +1 -0
- package/dist/react/useLazyReference.d.mts +13 -0
- package/dist/react/useLazyReference.d.mts.map +1 -0
- package/dist/react/useLazyReference.d.ts +11 -6
- package/dist/react/useLazyReference.d.ts.map +1 -1
- package/dist/react/useLazyReference.js +17 -40
- package/dist/react/useLazyReference.mjs +18 -0
- package/dist/react/useLazyReference.mjs.map +1 -0
- package/dist/react/useReadAndSubscribe.d.mts +20 -0
- package/dist/react/useReadAndSubscribe.d.mts.map +1 -0
- package/dist/react/useReadAndSubscribe.d.ts +14 -9
- package/dist/react/useReadAndSubscribe.d.ts.map +1 -1
- package/dist/react/useReadAndSubscribe.js +57 -37
- package/dist/react/useReadAndSubscribe.mjs +59 -0
- package/dist/react/useReadAndSubscribe.mjs.map +1 -0
- package/dist/react/useRerenderOnChange.d.mts +12 -0
- package/dist/react/useRerenderOnChange.d.mts.map +1 -0
- package/dist/react/useRerenderOnChange.d.ts +10 -6
- package/dist/react/useRerenderOnChange.d.ts.map +1 -1
- package/dist/react/useRerenderOnChange.js +16 -20
- package/dist/react/useRerenderOnChange.mjs +17 -0
- package/dist/react/useRerenderOnChange.mjs.map +1 -0
- package/dist/react/useResult.d.mts +8 -0
- package/dist/react/useResult.d.mts.map +1 -0
- package/dist/react/useResult.d.ts +7 -5
- package/dist/react/useResult.d.ts.map +1 -1
- package/dist/react/useResult.js +27 -40
- package/dist/react/useResult.mjs +30 -0
- package/dist/react/useResult.mjs.map +1 -0
- package/package.json +17 -9
- package/src/core/FragmentReference.ts +3 -3
- package/src/core/IsographEnvironment.ts +29 -16
- package/src/core/areEqualWithDeepComparison.ts +2 -18
- package/src/core/cache.ts +18 -383
- package/src/core/check.ts +9 -16
- package/src/core/componentCache.ts +10 -47
- package/src/core/entrypoint.ts +15 -3
- package/src/core/garbageCollection.ts +21 -10
- package/src/core/getOrCreateCacheForArtifact.ts +86 -0
- package/src/core/logging.ts +10 -10
- package/src/core/makeNetworkRequest.ts +16 -23
- package/src/core/optimisticProxy.ts +28 -47
- package/src/core/read.ts +21 -38
- package/src/core/reader.ts +8 -11
- package/src/core/startUpdate.ts +2 -6
- package/src/core/subscribe.ts +189 -0
- package/src/core/util.ts +26 -0
- package/src/core/writeData.ts +79 -0
- package/src/index.ts +5 -4
- package/src/loadable-hooks/useClientSideDefer.ts +4 -4
- package/src/loadable-hooks/useConnectionSpecPagination.ts +20 -18
- package/src/loadable-hooks/useImperativeLoadableField.ts +3 -3
- package/src/loadable-hooks/useSkipLimitPagination.ts +20 -18
- package/src/react/IsographEnvironmentProvider.tsx +2 -1
- package/src/react/LoadableFieldReader.tsx +2 -4
- package/src/react/LoadableFieldRenderer.tsx +2 -4
- package/src/react/createIsographEnvironment.ts +23 -0
- package/src/react/maybeUnwrapNetworkRequest.ts +17 -0
- package/src/react/useImperativeReference.ts +5 -4
- package/src/react/useLazyReference.ts +7 -8
- package/src/react/useReadAndSubscribe.ts +53 -5
- package/src/react/useRerenderOnChange.ts +3 -3
- package/src/react/useResult.ts +6 -24
- package/src/tests/__isograph/Economist/__link/output_type.ts +2 -0
- package/src/tests/garbageCollection.test.ts +3 -6
- package/src/tests/meNameSuccessor.ts +1 -1
- package/src/tests/nodeQuery.ts +2 -2
- package/src/tests/normalizeData.test.ts +5 -3
- package/src/tests/optimisticProxy.test.ts +7 -5
- package/src/tests/startUpdate.test.ts +5 -7
- package/vitest.config.ts +5 -0
- package/dist/core/areEqualWithDeepComparison.d.ts +0 -3
- package/dist/core/areEqualWithDeepComparison.d.ts.map +0 -1
- package/dist/core/brand.js +0 -2
- package/dist/core/componentCache.d.ts +0 -5
- package/dist/core/componentCache.d.ts.map +0 -1
- package/dist/core/reader.js +0 -2
- package/dist/core/startUpdate.d.ts +0 -9
- package/dist/core/startUpdate.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/core/cache.js
CHANGED
|
@@ -1,578 +1,244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.onNextChangeToRecord = onNextChangeToRecord;
|
|
12
|
-
exports.callSubscriptions = callSubscriptions;
|
|
13
|
-
exports.insertEmptySetIfMissing = insertEmptySetIfMissing;
|
|
14
|
-
exports.isArray = isArray;
|
|
15
|
-
exports.getParentRecordKey = getParentRecordKey;
|
|
16
|
-
exports.writeData = writeData;
|
|
17
|
-
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
|
18
|
-
const areEqualWithDeepComparison_1 = require("./areEqualWithDeepComparison");
|
|
19
|
-
const IsographEnvironment_1 = require("./IsographEnvironment");
|
|
20
|
-
const logging_1 = require("./logging");
|
|
21
|
-
const makeNetworkRequest_1 = require("./makeNetworkRequest");
|
|
22
|
-
const optimisticProxy_1 = require("./optimisticProxy");
|
|
23
|
-
const read_1 = require("./read");
|
|
24
|
-
exports.TYPENAME_FIELD_NAME = '__typename';
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_util = require('./util.js');
|
|
3
|
+
const require_IsographEnvironment = require('./IsographEnvironment.js');
|
|
4
|
+
const require_logging = require('./logging.js');
|
|
5
|
+
const require_optimisticProxy = require('./optimisticProxy.js');
|
|
6
|
+
let __isograph_react_disposable_state = require("@isograph/react-disposable-state");
|
|
7
|
+
__isograph_react_disposable_state = require_rolldown_runtime.__toESM(__isograph_react_disposable_state);
|
|
8
|
+
|
|
9
|
+
//#region src/core/cache.ts
|
|
10
|
+
const TYPENAME_FIELD_NAME = "__typename";
|
|
25
11
|
function getOrCreateItemInSuspenseCache(environment, index, factory) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return environment.fragmentCache[index];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a copy of the provided value, ensuring any nested objects have their
|
|
33
|
-
* keys sorted such that equivalent values would have identical JSON.stringify
|
|
34
|
-
* results.
|
|
35
|
-
*/
|
|
36
|
-
function stableCopy(value) {
|
|
37
|
-
if (!value || typeof value !== 'object') {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
if (isArray(value)) {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
return value.map(stableCopy);
|
|
43
|
-
}
|
|
44
|
-
const keys = Object.keys(value).sort();
|
|
45
|
-
const stable = {};
|
|
46
|
-
for (let i = 0; i < keys.length; i++) {
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
stable[keys[i]] = stableCopy(value[keys[i]]);
|
|
49
|
-
}
|
|
50
|
-
return stable;
|
|
51
|
-
}
|
|
52
|
-
function getOrCreateCacheForArtifact(environment, entrypoint, variables, fetchOptions) {
|
|
53
|
-
let cacheKey = '';
|
|
54
|
-
switch (entrypoint.networkRequestInfo.operation.kind) {
|
|
55
|
-
case 'Operation':
|
|
56
|
-
cacheKey =
|
|
57
|
-
entrypoint.networkRequestInfo.operation.text +
|
|
58
|
-
JSON.stringify(stableCopy(variables));
|
|
59
|
-
break;
|
|
60
|
-
case 'PersistedOperation':
|
|
61
|
-
cacheKey =
|
|
62
|
-
entrypoint.networkRequestInfo.operation.operationId +
|
|
63
|
-
JSON.stringify(stableCopy(variables));
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
const factory = () => {
|
|
67
|
-
const { fieldName, readerArtifactKind, readerWithRefetchQueries } = (0, IsographEnvironment_1.getOrLoadReaderWithRefetchQueries)(environment, entrypoint.readerWithRefetchQueries);
|
|
68
|
-
const [networkRequest, disposeNetworkRequest] = (0, makeNetworkRequest_1.maybeMakeNetworkRequest)(environment, entrypoint, variables, readerWithRefetchQueries, fetchOptions !== null && fetchOptions !== void 0 ? fetchOptions : null);
|
|
69
|
-
const itemCleanupPair = [
|
|
70
|
-
{
|
|
71
|
-
kind: 'FragmentReference',
|
|
72
|
-
readerWithRefetchQueries,
|
|
73
|
-
fieldName,
|
|
74
|
-
readerArtifactKind,
|
|
75
|
-
root: { __link: IsographEnvironment_1.ROOT_ID, __typename: entrypoint.concreteType },
|
|
76
|
-
variables,
|
|
77
|
-
networkRequest: networkRequest,
|
|
78
|
-
},
|
|
79
|
-
disposeNetworkRequest,
|
|
80
|
-
];
|
|
81
|
-
return itemCleanupPair;
|
|
82
|
-
};
|
|
83
|
-
return getOrCreateItemInSuspenseCache(environment, cacheKey, factory);
|
|
12
|
+
if (environment.fragmentCache[index] == null) environment.fragmentCache[index] = new __isograph_react_disposable_state.ParentCache(factory);
|
|
13
|
+
return environment.fragmentCache[index];
|
|
84
14
|
}
|
|
85
15
|
function normalizeData(environment, storeLayer, normalizationAst, networkResponse, variables, root, encounteredIds) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return encounteredIds;
|
|
16
|
+
require_logging.logMessage(environment, () => ({
|
|
17
|
+
kind: "AboutToNormalize",
|
|
18
|
+
normalizationAst,
|
|
19
|
+
networkResponse,
|
|
20
|
+
variables
|
|
21
|
+
}));
|
|
22
|
+
normalizeDataIntoRecord(environment, storeLayer, normalizationAst, networkResponse, require_optimisticProxy.getMutableStoreRecordProxy(storeLayer, root), root, variables, encounteredIds);
|
|
23
|
+
return encounteredIds;
|
|
95
24
|
}
|
|
96
25
|
function subscribeToAnyChange(environment, callback) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
26
|
+
const subscription = {
|
|
27
|
+
kind: "AnyRecords",
|
|
28
|
+
callback
|
|
29
|
+
};
|
|
30
|
+
environment.subscriptions.add(subscription);
|
|
31
|
+
return () => environment.subscriptions.delete(subscription);
|
|
103
32
|
}
|
|
104
33
|
function subscribeToAnyChangesToRecord(environment, recordLink, callback) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
function subscribe(environment, encounteredDataAndRecords, fragmentReference, callback, readerAst) {
|
|
114
|
-
const fragmentSubscription = {
|
|
115
|
-
kind: 'FragmentSubscription',
|
|
116
|
-
callback,
|
|
117
|
-
encounteredDataAndRecords,
|
|
118
|
-
fragmentReference,
|
|
119
|
-
readerAst,
|
|
120
|
-
};
|
|
121
|
-
// subscribe is called in an effect. (We should actually subscribe during the
|
|
122
|
-
// initial render.) Because it's called in an effect, we might have missed some
|
|
123
|
-
// changes since the initial render! So, at this point, we re-read and call the
|
|
124
|
-
// subscription (i.e. re-render) if the fragment data has changed.
|
|
125
|
-
callSubscriptionIfDataChanged(environment, fragmentSubscription);
|
|
126
|
-
environment.subscriptions.add(fragmentSubscription);
|
|
127
|
-
return () => environment.subscriptions.delete(fragmentSubscription);
|
|
34
|
+
const subscription = {
|
|
35
|
+
kind: "AnyChangesToRecord",
|
|
36
|
+
recordLink,
|
|
37
|
+
callback
|
|
38
|
+
};
|
|
39
|
+
environment.subscriptions.add(subscription);
|
|
40
|
+
return () => environment.subscriptions.delete(subscription);
|
|
128
41
|
}
|
|
129
42
|
function onNextChangeToRecord(environment, recordLink) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
// Calls to readButDoNotEvaluate can suspend (i.e. throw a promise).
|
|
138
|
-
// Maybe in the future, they will be able to throw errors.
|
|
139
|
-
//
|
|
140
|
-
// That's probably okay to ignore. We don't, however, want to prevent
|
|
141
|
-
// updating other subscriptions if one subscription had missing data.
|
|
142
|
-
function logAnyError(environment, context, f) {
|
|
143
|
-
try {
|
|
144
|
-
f();
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
(0, logging_1.logMessage)(environment, () => ({
|
|
148
|
-
kind: 'ErrorEncounteredInWithErrorHandling',
|
|
149
|
-
error: e,
|
|
150
|
-
context,
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function callSubscriptions(environment, recordsEncounteredWhenNormalizing) {
|
|
155
|
-
environment.subscriptions.forEach((subscription) => logAnyError(environment, { situation: 'calling subscriptions' }, () => {
|
|
156
|
-
var _a;
|
|
157
|
-
switch (subscription.kind) {
|
|
158
|
-
case 'FragmentSubscription': {
|
|
159
|
-
// TODO if there are multiple components subscribed to the same
|
|
160
|
-
// fragment, we will call readButNotEvaluate multiple times. We
|
|
161
|
-
// should fix that.
|
|
162
|
-
if (hasOverlappingIds(recordsEncounteredWhenNormalizing, subscription.encounteredDataAndRecords.encounteredRecords)) {
|
|
163
|
-
callSubscriptionIfDataChanged(environment, subscription);
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
case 'AnyRecords': {
|
|
168
|
-
logAnyError(environment, { situation: 'calling AnyRecords callback' }, () => subscription.callback());
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
case 'AnyChangesToRecord': {
|
|
172
|
-
if ((_a = recordsEncounteredWhenNormalizing
|
|
173
|
-
.get(subscription.recordLink.__typename)) === null || _a === void 0 ? void 0 : _a.has(subscription.recordLink.__link)) {
|
|
174
|
-
logAnyError(environment, { situation: 'calling AnyChangesToRecord callback' }, () => subscription.callback());
|
|
175
|
-
}
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
default: {
|
|
179
|
-
// Ensure we have covered all variants
|
|
180
|
-
const _ = subscription;
|
|
181
|
-
_;
|
|
182
|
-
throw new Error('Unexpected case');
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
187
|
-
function callSubscriptionIfDataChanged(environment, subscription) {
|
|
188
|
-
const newEncounteredDataAndRecords = (0, read_1.readButDoNotEvaluate)(environment, subscription.fragmentReference,
|
|
189
|
-
// Is this wrong?
|
|
190
|
-
// Reasons to think no:
|
|
191
|
-
// - we are only updating the read-out value, and the network
|
|
192
|
-
// options only affect whether we throw.
|
|
193
|
-
// - the component will re-render, and re-throw on its own, anyway.
|
|
194
|
-
//
|
|
195
|
-
// Reasons to think not:
|
|
196
|
-
// - it seems more efficient to suspend here and not update state,
|
|
197
|
-
// if we expect that the component will just throw anyway
|
|
198
|
-
// - consistency
|
|
199
|
-
// - it's also weird, this is called from makeNetworkRequest, where
|
|
200
|
-
// we don't currently pass network request options
|
|
201
|
-
{
|
|
202
|
-
suspendIfInFlight: false,
|
|
203
|
-
throwOnNetworkError: false,
|
|
204
|
-
});
|
|
205
|
-
const mergedItem = (0, areEqualWithDeepComparison_1.mergeObjectsUsingReaderAst)(subscription.readerAst, subscription.encounteredDataAndRecords.item, newEncounteredDataAndRecords.item);
|
|
206
|
-
(0, logging_1.logMessage)(environment, () => ({
|
|
207
|
-
kind: 'DeepEqualityCheck',
|
|
208
|
-
fragmentReference: subscription.fragmentReference,
|
|
209
|
-
old: subscription.encounteredDataAndRecords.item,
|
|
210
|
-
new: newEncounteredDataAndRecords.item,
|
|
211
|
-
deeplyEqual: mergedItem === subscription.encounteredDataAndRecords.item,
|
|
212
|
-
}));
|
|
213
|
-
if (mergedItem !== subscription.encounteredDataAndRecords.item) {
|
|
214
|
-
logAnyError(environment, { situation: 'calling FragmentSubscription callback' }, () => {
|
|
215
|
-
subscription.callback(newEncounteredDataAndRecords);
|
|
216
|
-
});
|
|
217
|
-
subscription.encounteredDataAndRecords = newEncounteredDataAndRecords;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function hasOverlappingIds(ids1, ids2) {
|
|
221
|
-
for (const [typeName, set1] of ids1.entries()) {
|
|
222
|
-
const set2 = ids2.get(typeName);
|
|
223
|
-
if (set2 === undefined) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
if (isNotDisjointFrom(set1, set2)) {
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
// TODO use a polyfill library
|
|
233
|
-
function isNotDisjointFrom(set1, set2) {
|
|
234
|
-
for (const id of set1) {
|
|
235
|
-
if (set2.has(id)) {
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const unsubscribe = subscribeToAnyChangesToRecord(environment, recordLink, () => {
|
|
45
|
+
unsubscribe();
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
240
49
|
}
|
|
241
50
|
/**
|
|
242
|
-
|
|
243
|
-
|
|
51
|
+
* Mutate targetParentRecord according to the normalizationAst and networkResponseParentRecord.
|
|
52
|
+
*/
|
|
244
53
|
function normalizeDataIntoRecord(environment, storeLayer, normalizationAst, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
default: {
|
|
267
|
-
// Ensure we have covered all variants
|
|
268
|
-
let _ = normalizationNode;
|
|
269
|
-
_;
|
|
270
|
-
throw new Error('Unexpected normalization node kind');
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (recordHasBeenUpdated) {
|
|
275
|
-
let encounteredRecordsIds = insertEmptySetIfMissing(mutableEncounteredIds, targetParentRecordLink.__typename);
|
|
276
|
-
encounteredRecordsIds.add(targetParentRecordLink.__link);
|
|
277
|
-
}
|
|
278
|
-
return recordHasBeenUpdated;
|
|
54
|
+
let recordHasBeenUpdated = false;
|
|
55
|
+
for (const normalizationNode of normalizationAst) switch (normalizationNode.kind) {
|
|
56
|
+
case "Scalar": {
|
|
57
|
+
const scalarFieldResultedInChange = normalizeScalarField(normalizationNode, networkResponseParentRecord, targetParentRecord, variables);
|
|
58
|
+
recordHasBeenUpdated = recordHasBeenUpdated || scalarFieldResultedInChange;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "Linked": {
|
|
62
|
+
const linkedFieldResultedInChange = normalizeLinkedField(environment, storeLayer, normalizationNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds);
|
|
63
|
+
recordHasBeenUpdated = recordHasBeenUpdated || linkedFieldResultedInChange;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "InlineFragment": {
|
|
67
|
+
const inlineFragmentResultedInChange = normalizeInlineFragment(environment, storeLayer, normalizationNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds);
|
|
68
|
+
recordHasBeenUpdated = recordHasBeenUpdated || inlineFragmentResultedInChange;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (recordHasBeenUpdated) insertEmptySetIfMissing(mutableEncounteredIds, targetParentRecordLink.__typename).add(targetParentRecordLink.__link);
|
|
73
|
+
return recordHasBeenUpdated;
|
|
279
74
|
}
|
|
280
75
|
function insertEmptySetIfMissing(map, key) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
76
|
+
let result = map.get(key);
|
|
77
|
+
if (result === void 0) {
|
|
78
|
+
result = /* @__PURE__ */ new Set();
|
|
79
|
+
map.set(key, result);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
287
82
|
}
|
|
288
83
|
function normalizeScalarField(astNode, networkResponseParentRecord, targetStoreRecord, variables) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
throw new Error('Unexpected object array when normalizing scalar');
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
function isArray(value) {
|
|
306
|
-
return Array.isArray(value);
|
|
84
|
+
const networkResponseData = networkResponseParentRecord[getNetworkResponseKey(astNode)];
|
|
85
|
+
const parentRecordKey = getParentRecordKey(astNode, variables);
|
|
86
|
+
const existingValue = targetStoreRecord[parentRecordKey];
|
|
87
|
+
if (networkResponseData == null) {
|
|
88
|
+
targetStoreRecord[parentRecordKey] = null;
|
|
89
|
+
return existingValue === void 0 || existingValue != null;
|
|
90
|
+
}
|
|
91
|
+
if (isScalarOrEmptyArray(networkResponseData)) {
|
|
92
|
+
targetStoreRecord[parentRecordKey] = networkResponseData;
|
|
93
|
+
return existingValue !== networkResponseData;
|
|
94
|
+
} else throw new Error("Unexpected object array when normalizing scalar");
|
|
307
95
|
}
|
|
308
96
|
/**
|
|
309
|
-
|
|
310
|
-
|
|
97
|
+
* Mutate targetParentRecord with a given linked field ast node.
|
|
98
|
+
*/
|
|
311
99
|
function normalizeLinkedField(environment, storeLayer, astNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const newStoreRecordId = normalizeNetworkResponseObject(environment, storeLayer, astNode, networkResponseData, targetParentRecordLink, variables, null, mutableEncounteredIds);
|
|
350
|
-
let __typename = (_b = astNode.concreteType) !== null && _b !== void 0 ? _b : networkResponseData[exports.TYPENAME_FIELD_NAME];
|
|
351
|
-
if (__typename == null) {
|
|
352
|
-
throw new Error('Unexpected missing __typename in network response when normalizing a linked field. ' +
|
|
353
|
-
'This is indicative of a bug in Isograph.');
|
|
354
|
-
}
|
|
355
|
-
targetParentRecord[parentRecordKey] = {
|
|
356
|
-
__link: newStoreRecordId,
|
|
357
|
-
__typename,
|
|
358
|
-
};
|
|
359
|
-
const link = (0, IsographEnvironment_1.getLink)(existingValue);
|
|
360
|
-
return (link === null || link === void 0 ? void 0 : link.__link) !== newStoreRecordId || link.__typename !== __typename;
|
|
361
|
-
}
|
|
100
|
+
const networkResponseData = networkResponseParentRecord[getNetworkResponseKey(astNode)];
|
|
101
|
+
const parentRecordKey = getParentRecordKey(astNode, variables);
|
|
102
|
+
const existingValue = targetParentRecord[parentRecordKey];
|
|
103
|
+
if (networkResponseData == null) {
|
|
104
|
+
targetParentRecord[parentRecordKey] = null;
|
|
105
|
+
return existingValue === void 0 || existingValue != null;
|
|
106
|
+
}
|
|
107
|
+
if (isScalarOrEmptyArray(networkResponseData) && !isNullOrEmptyArray(networkResponseData)) throw new Error("Unexpected scalar network response when normalizing a linked field");
|
|
108
|
+
if (require_util.isArray(networkResponseData)) {
|
|
109
|
+
const dataIds = [];
|
|
110
|
+
for (let i = 0; i < networkResponseData.length; i++) {
|
|
111
|
+
const networkResponseObject = networkResponseData[i];
|
|
112
|
+
if (networkResponseObject == null) {
|
|
113
|
+
dataIds.push(null);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const newStoreRecordId = normalizeNetworkResponseObject(environment, storeLayer, astNode, networkResponseObject, targetParentRecordLink, variables, i, mutableEncounteredIds);
|
|
117
|
+
const __typename = astNode.concreteType ?? networkResponseObject[TYPENAME_FIELD_NAME];
|
|
118
|
+
if (__typename == null) throw new Error("Unexpected missing __typename in network response when normalizing a linked field. This is indicative of a bug in Isograph.");
|
|
119
|
+
dataIds.push({
|
|
120
|
+
__link: newStoreRecordId,
|
|
121
|
+
__typename
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
targetParentRecord[parentRecordKey] = dataIds;
|
|
125
|
+
return !dataIdsAreTheSame(existingValue, dataIds);
|
|
126
|
+
} else {
|
|
127
|
+
const newStoreRecordId = normalizeNetworkResponseObject(environment, storeLayer, astNode, networkResponseData, targetParentRecordLink, variables, null, mutableEncounteredIds);
|
|
128
|
+
let __typename = astNode.concreteType ?? networkResponseData[TYPENAME_FIELD_NAME];
|
|
129
|
+
if (__typename == null) throw new Error("Unexpected missing __typename in network response when normalizing a linked field. This is indicative of a bug in Isograph.");
|
|
130
|
+
targetParentRecord[parentRecordKey] = {
|
|
131
|
+
__link: newStoreRecordId,
|
|
132
|
+
__typename
|
|
133
|
+
};
|
|
134
|
+
const link = require_IsographEnvironment.getLink(existingValue);
|
|
135
|
+
return link?.__link !== newStoreRecordId || link.__typename !== __typename;
|
|
136
|
+
}
|
|
362
137
|
}
|
|
363
138
|
/**
|
|
364
|
-
|
|
365
|
-
|
|
139
|
+
* Mutate targetParentRecord with a given linked field ast node.
|
|
140
|
+
*/
|
|
366
141
|
function normalizeInlineFragment(environment, storeLayer, astNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return hasBeenModified;
|
|
371
|
-
}
|
|
372
|
-
return false;
|
|
142
|
+
const typeToRefineTo = astNode.type;
|
|
143
|
+
if (networkResponseParentRecord[TYPENAME_FIELD_NAME] === typeToRefineTo) return normalizeDataIntoRecord(environment, storeLayer, astNode.selections, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, mutableEncounteredIds);
|
|
144
|
+
return false;
|
|
373
145
|
}
|
|
374
146
|
function dataIdsAreTheSame(existingValue, newDataIds) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
((_b = newDataIds[i]) === null || _b === void 0 ? void 0 : _b.__typename) !== (maybeLink === null || maybeLink === void 0 ? void 0 : maybeLink.__typename)) {
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return true;
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
147
|
+
if (require_util.isArray(existingValue)) {
|
|
148
|
+
if (newDataIds.length !== existingValue.length) return false;
|
|
149
|
+
for (let i = 0; i < newDataIds.length; i++) {
|
|
150
|
+
const maybeLink = require_IsographEnvironment.getLink(existingValue[i]);
|
|
151
|
+
if (newDataIds[i]?.__link !== maybeLink?.__link || newDataIds[i]?.__typename !== maybeLink?.__typename) return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
} else return false;
|
|
392
155
|
}
|
|
393
156
|
function normalizeNetworkResponseObject(environment, storeLayer, astNode, networkResponseData, targetParentRecordLink, variables, index, mutableEncounteredIds) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return newStoreRecordId;
|
|
157
|
+
const newStoreRecordId = getDataIdOfNetworkResponse(targetParentRecordLink, networkResponseData, astNode, variables, index);
|
|
158
|
+
const __typename = astNode.concreteType ?? networkResponseData[TYPENAME_FIELD_NAME];
|
|
159
|
+
if (__typename == null) throw new Error("Unexpected missing __typename in network response object. This is indicative of a bug in Isograph.");
|
|
160
|
+
const link = {
|
|
161
|
+
__link: newStoreRecordId,
|
|
162
|
+
__typename
|
|
163
|
+
};
|
|
164
|
+
const newStoreRecord = require_optimisticProxy.getMutableStoreRecordProxy(storeLayer, link);
|
|
165
|
+
normalizeDataIntoRecord(environment, storeLayer, astNode.selections, networkResponseData, newStoreRecord, link, variables, mutableEncounteredIds);
|
|
166
|
+
return newStoreRecordId;
|
|
405
167
|
}
|
|
406
168
|
function isScalarOrEmptyArray(data) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return data.every((x) => isScalarOrEmptyArray(x));
|
|
410
|
-
}
|
|
411
|
-
const isScalarValue = data === null ||
|
|
412
|
-
typeof data === 'string' ||
|
|
413
|
-
typeof data === 'number' ||
|
|
414
|
-
typeof data === 'boolean';
|
|
415
|
-
return isScalarValue;
|
|
169
|
+
if (require_util.isArray(data)) return data.every((x) => isScalarOrEmptyArray(x));
|
|
170
|
+
return data == null || typeof data === "string" || typeof data === "number" || typeof data === "boolean";
|
|
416
171
|
}
|
|
417
172
|
function isNullOrEmptyArray(data) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
return data === null;
|
|
173
|
+
if (require_util.isArray(data)) {
|
|
174
|
+
if (data.length === 0) return true;
|
|
175
|
+
return data.every((x) => isNullOrEmptyArray(x));
|
|
176
|
+
}
|
|
177
|
+
return data == null;
|
|
425
178
|
}
|
|
426
179
|
function getParentRecordKey(astNode, variables) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
parentRecordKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return parentRecordKey;
|
|
180
|
+
let parentRecordKey = astNode.fieldName;
|
|
181
|
+
const fieldParameters = astNode.arguments;
|
|
182
|
+
if (fieldParameters != null) for (const fieldParameter of fieldParameters) parentRecordKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
|
183
|
+
return parentRecordKey;
|
|
435
184
|
}
|
|
436
185
|
function getStoreKeyChunkForArgumentValue(argumentValue, variables) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}));
|
|
447
|
-
}
|
|
448
|
-
case 'Literal': {
|
|
449
|
-
return argumentValue.value;
|
|
450
|
-
}
|
|
451
|
-
case 'Variable': {
|
|
452
|
-
return (_a = variables[argumentValue.name]) !== null && _a !== void 0 ? _a : 'null';
|
|
453
|
-
}
|
|
454
|
-
case 'String': {
|
|
455
|
-
return argumentValue.value;
|
|
456
|
-
}
|
|
457
|
-
case 'Enum': {
|
|
458
|
-
return argumentValue.value;
|
|
459
|
-
}
|
|
460
|
-
default: {
|
|
461
|
-
// TODO configure eslint to allow unused vars starting with _
|
|
462
|
-
// Ensure we have covered all variants
|
|
463
|
-
const _ = argumentValue;
|
|
464
|
-
_;
|
|
465
|
-
throw new Error('Unexpected case');
|
|
466
|
-
}
|
|
467
|
-
}
|
|
186
|
+
switch (argumentValue.kind) {
|
|
187
|
+
case "Object": return Object.fromEntries(argumentValue.value.map(([argumentName, argumentValue$1]) => {
|
|
188
|
+
return [argumentName, getStoreKeyChunkForArgumentValue(argumentValue$1, variables)];
|
|
189
|
+
}));
|
|
190
|
+
case "Literal": return argumentValue.value;
|
|
191
|
+
case "Variable": return variables[argumentValue.name] ?? "null";
|
|
192
|
+
case "String": return argumentValue.value;
|
|
193
|
+
case "Enum": return argumentValue.value;
|
|
194
|
+
}
|
|
468
195
|
}
|
|
469
196
|
function getStoreKeyChunkForArgument(argument, variables) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
return `${exports.FIRST_SPLIT_KEY}${argumentName}${exports.SECOND_SPLIT_KEY}${chunk}`;
|
|
197
|
+
const [argumentName, argumentValue] = argument;
|
|
198
|
+
let chunk = getStoreKeyChunkForArgumentValue(argumentValue, variables);
|
|
199
|
+
if (typeof chunk === "object") chunk = JSON.stringify(require_util.stableCopy(chunk));
|
|
200
|
+
return `${FIRST_SPLIT_KEY}${argumentName}${SECOND_SPLIT_KEY}${chunk}`;
|
|
476
201
|
}
|
|
477
202
|
function getNetworkResponseKey(astNode) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
return networkResponseKey;
|
|
203
|
+
let networkResponseKey = astNode.fieldName;
|
|
204
|
+
const fieldParameters = astNode.arguments;
|
|
205
|
+
if (fieldParameters != null) for (const [argumentName, argumentValue] of fieldParameters) {
|
|
206
|
+
let argumentValueChunk = getArgumentValueChunk(argumentValue);
|
|
207
|
+
networkResponseKey += `${FIRST_SPLIT_KEY}${argumentName}${SECOND_SPLIT_KEY}${argumentValueChunk}`;
|
|
208
|
+
}
|
|
209
|
+
return networkResponseKey;
|
|
487
210
|
}
|
|
488
211
|
function getArgumentValueChunk(argumentValue) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
return 'l_' + argumentValue.value;
|
|
503
|
-
}
|
|
504
|
-
case 'Variable': {
|
|
505
|
-
return 'v_' + argumentValue.name;
|
|
506
|
-
}
|
|
507
|
-
case 'String': {
|
|
508
|
-
// replace all non-word characters (alphanumeric & underscore) with underscores
|
|
509
|
-
return 's_' + argumentValue.value.replaceAll(/\W/g, '_');
|
|
510
|
-
}
|
|
511
|
-
case 'Enum': {
|
|
512
|
-
return 'e_' + argumentValue.value;
|
|
513
|
-
}
|
|
514
|
-
default: {
|
|
515
|
-
// Ensure we have covered all variants
|
|
516
|
-
let _ = argumentValue;
|
|
517
|
-
_;
|
|
518
|
-
throw new Error('Unexpected case');
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
// an alias might be pullRequests____first___first____after___cursor
|
|
523
|
-
exports.FIRST_SPLIT_KEY = '____';
|
|
524
|
-
exports.SECOND_SPLIT_KEY = '___';
|
|
525
|
-
exports.THIRD_SPLIT_KEY = '__';
|
|
526
|
-
// Returns a key to look up an item in the store
|
|
212
|
+
switch (argumentValue.kind) {
|
|
213
|
+
case "Object": return "o_" + argumentValue.value.map(([argumentName, argumentValue$1]) => {
|
|
214
|
+
return argumentName + THIRD_SPLIT_KEY + getArgumentValueChunk(argumentValue$1);
|
|
215
|
+
}).join("_") + "_c";
|
|
216
|
+
case "Literal": return "l_" + argumentValue.value;
|
|
217
|
+
case "Variable": return "v_" + argumentValue.name;
|
|
218
|
+
case "String": return "s_" + argumentValue.value.replaceAll(/\W/g, "_");
|
|
219
|
+
case "Enum": return "e_" + argumentValue.value;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const FIRST_SPLIT_KEY = "____";
|
|
223
|
+
const SECOND_SPLIT_KEY = "___";
|
|
224
|
+
const THIRD_SPLIT_KEY = "__";
|
|
527
225
|
function getDataIdOfNetworkResponse(parentRecordLink, dataToNormalize, astNode, variables, index) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
for (const fieldParameter of fieldParameters) {
|
|
548
|
-
storeKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
|
549
|
-
}
|
|
550
|
-
return storeKey;
|
|
551
|
-
}
|
|
552
|
-
function writeData(environment, entrypoint, data, variables) {
|
|
553
|
-
const encounteredIds = new Map();
|
|
554
|
-
environment.store = (0, optimisticProxy_1.addNetworkResponseStoreLayer)(environment.store);
|
|
555
|
-
normalizeData(environment, environment.store, entrypoint.networkRequestInfo.normalizationAst.selections, data, variables, { __link: IsographEnvironment_1.ROOT_ID, __typename: entrypoint.concreteType }, encounteredIds);
|
|
556
|
-
(0, logging_1.logMessage)(environment, () => ({
|
|
557
|
-
kind: 'AfterNormalization',
|
|
558
|
-
store: environment.store,
|
|
559
|
-
encounteredIds,
|
|
560
|
-
}));
|
|
561
|
-
callSubscriptions(environment, encounteredIds);
|
|
562
|
-
const { fieldName, readerArtifactKind, readerWithRefetchQueries } = (0, IsographEnvironment_1.getOrLoadReaderWithRefetchQueries)(environment, entrypoint.readerWithRefetchQueries);
|
|
563
|
-
const [networkRequest, disposeNetworkRequest] = (0, makeNetworkRequest_1.retainQueryWithoutMakingNetworkRequest)(environment, entrypoint, variables);
|
|
564
|
-
return [
|
|
565
|
-
{
|
|
566
|
-
kind: 'FragmentReference',
|
|
567
|
-
readerWithRefetchQueries,
|
|
568
|
-
fieldName,
|
|
569
|
-
readerArtifactKind,
|
|
570
|
-
root: { __link: IsographEnvironment_1.ROOT_ID, __typename: entrypoint.concreteType },
|
|
571
|
-
variables,
|
|
572
|
-
networkRequest,
|
|
573
|
-
},
|
|
574
|
-
() => {
|
|
575
|
-
disposeNetworkRequest();
|
|
576
|
-
},
|
|
577
|
-
];
|
|
578
|
-
}
|
|
226
|
+
if (astNode.concreteType === "Query") return require_IsographEnvironment.ROOT_ID;
|
|
227
|
+
const dataId = dataToNormalize.id;
|
|
228
|
+
if (dataId != null) return dataId;
|
|
229
|
+
let storeKey = `${parentRecordLink.__typename}:${parentRecordLink.__link}.${astNode.fieldName}`;
|
|
230
|
+
if (index != null) storeKey += `.${index}`;
|
|
231
|
+
const fieldParameters = astNode.arguments;
|
|
232
|
+
if (fieldParameters == null) return storeKey;
|
|
233
|
+
for (const fieldParameter of fieldParameters) storeKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
|
234
|
+
return storeKey;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.TYPENAME_FIELD_NAME = TYPENAME_FIELD_NAME;
|
|
239
|
+
exports.getOrCreateItemInSuspenseCache = getOrCreateItemInSuspenseCache;
|
|
240
|
+
exports.getParentRecordKey = getParentRecordKey;
|
|
241
|
+
exports.insertEmptySetIfMissing = insertEmptySetIfMissing;
|
|
242
|
+
exports.normalizeData = normalizeData;
|
|
243
|
+
exports.onNextChangeToRecord = onNextChangeToRecord;
|
|
244
|
+
exports.subscribeToAnyChange = subscribeToAnyChange;
|