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