@isograph/react 0.0.0-main-e403ba82 → 0.0.0-main-82cbc3c0
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 +1 -1
- package/dist/core/FragmentReference.d.ts +1 -1
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/FragmentReference.js +2 -2
- package/dist/core/IsographEnvironment.d.ts +7 -5
- package/dist/core/IsographEnvironment.d.ts.map +1 -1
- package/dist/core/IsographEnvironment.js +5 -4
- package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -1
- package/dist/core/areEqualWithDeepComparison.js +2 -5
- package/dist/core/cache.d.ts +5 -18
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +10 -222
- package/dist/core/check.js +5 -5
- package/dist/core/componentCache.d.ts +2 -2
- package/dist/core/componentCache.d.ts.map +1 -1
- package/dist/core/componentCache.js +1 -26
- package/dist/core/entrypoint.d.ts +2 -2
- package/dist/core/entrypoint.d.ts.map +1 -1
- package/dist/core/garbageCollection.d.ts +2 -2
- package/dist/core/garbageCollection.d.ts.map +1 -1
- package/dist/core/garbageCollection.js +3 -3
- package/dist/core/getOrCreateCacheForArtifact.d.ts +8 -0
- package/dist/core/getOrCreateCacheForArtifact.d.ts.map +1 -0
- package/dist/core/getOrCreateCacheForArtifact.js +40 -0
- package/dist/core/logging.d.ts +8 -8
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.d.ts +3 -3
- package/dist/core/makeNetworkRequest.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.js +3 -2
- package/dist/core/optimisticProxy.d.ts.map +1 -1
- package/dist/core/optimisticProxy.js +24 -22
- package/dist/core/read.d.ts +3 -3
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +4 -4
- package/dist/core/startUpdate.d.ts.map +1 -1
- package/dist/core/startUpdate.js +2 -1
- package/dist/core/subscribe.d.ts +8 -0
- package/dist/core/subscribe.d.ts.map +1 -0
- package/dist/core/subscribe.js +127 -0
- package/dist/core/util.d.ts +7 -0
- package/dist/core/util.d.ts.map +1 -1
- package/dist/core/util.js +26 -0
- package/dist/core/writeData.d.ts +7 -0
- package/dist/core/writeData.d.ts.map +1 -0
- package/dist/core/writeData.js +36 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +3 -3
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.js +3 -3
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts +3 -3
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.js +3 -3
- package/dist/react/createIsographEnvironment.d.ts +4 -0
- package/dist/react/createIsographEnvironment.d.ts.map +1 -0
- package/dist/react/createIsographEnvironment.js +8 -0
- package/dist/react/maybeUnwrapNetworkRequest.d.ts +4 -0
- package/dist/react/maybeUnwrapNetworkRequest.d.ts.map +1 -0
- package/dist/react/maybeUnwrapNetworkRequest.js +14 -0
- package/dist/react/useLazyReference.d.ts.map +1 -1
- package/dist/react/useLazyReference.js +2 -2
- package/dist/react/useReadAndSubscribe.d.ts +4 -2
- package/dist/react/useReadAndSubscribe.d.ts.map +1 -1
- package/dist/react/useReadAndSubscribe.js +31 -2
- package/dist/react/useRerenderOnChange.d.ts +2 -2
- package/dist/react/useRerenderOnChange.d.ts.map +1 -1
- package/dist/react/useRerenderOnChange.js +2 -2
- package/dist/react/useResult.d.ts +2 -4
- package/dist/react/useResult.d.ts.map +1 -1
- package/dist/react/useResult.js +3 -13
- package/package.json +4 -4
- package/src/core/FragmentReference.ts +2 -2
- package/src/core/IsographEnvironment.ts +26 -10
- package/src/core/areEqualWithDeepComparison.ts +2 -6
- package/src/core/cache.ts +18 -364
- package/src/core/check.ts +5 -5
- package/src/core/componentCache.ts +8 -43
- package/src/core/entrypoint.ts +2 -2
- package/src/core/garbageCollection.ts +8 -8
- package/src/core/getOrCreateCacheForArtifact.ts +86 -0
- package/src/core/logging.ts +10 -10
- package/src/core/makeNetworkRequest.ts +8 -8
- package/src/core/optimisticProxy.ts +27 -26
- package/src/core/read.ts +17 -17
- package/src/core/startUpdate.ts +1 -1
- package/src/core/subscribe.ts +195 -0
- package/src/core/util.ts +26 -0
- package/src/core/writeData.ts +79 -0
- package/src/index.ts +3 -4
- package/src/loadable-hooks/useConnectionSpecPagination.ts +6 -6
- package/src/loadable-hooks/useSkipLimitPagination.ts +6 -6
- package/src/react/createIsographEnvironment.ts +23 -0
- package/src/react/maybeUnwrapNetworkRequest.ts +17 -0
- package/src/react/useLazyReference.ts +2 -4
- package/src/react/useReadAndSubscribe.ts +53 -5
- package/src/react/useRerenderOnChange.ts +3 -3
- package/src/react/useResult.ts +6 -24
- package/src/tests/garbageCollection.test.ts +3 -6
- package/src/tests/meNameSuccessor.ts +1 -1
- package/src/tests/nodeQuery.ts +1 -1
- 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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/isograph-disposable-types/dist';
|
|
2
|
+
import { callSubscriptions } from './subscribe';
|
|
3
|
+
import {
|
|
4
|
+
type NetworkResponseObject,
|
|
5
|
+
type EncounteredIds,
|
|
6
|
+
normalizeData,
|
|
7
|
+
} from './cache';
|
|
8
|
+
import type { IsographEntrypoint, NormalizationAst } from './entrypoint';
|
|
9
|
+
import type {
|
|
10
|
+
UnknownTReadFromStore,
|
|
11
|
+
ExtractParameters,
|
|
12
|
+
FragmentReference,
|
|
13
|
+
} from './FragmentReference';
|
|
14
|
+
import {
|
|
15
|
+
type IsographEnvironment,
|
|
16
|
+
ROOT_ID,
|
|
17
|
+
getOrLoadReaderWithRefetchQueries,
|
|
18
|
+
} from './IsographEnvironment';
|
|
19
|
+
import { logMessage } from './logging';
|
|
20
|
+
import { retainQueryWithoutMakingNetworkRequest } from './makeNetworkRequest';
|
|
21
|
+
import { addNetworkResponseStoreLayer } from './optimisticProxy';
|
|
22
|
+
|
|
23
|
+
export function writeData<
|
|
24
|
+
TReadFromStore extends UnknownTReadFromStore,
|
|
25
|
+
TRawResponseType extends NetworkResponseObject,
|
|
26
|
+
TClientFieldValue,
|
|
27
|
+
>(
|
|
28
|
+
environment: IsographEnvironment,
|
|
29
|
+
entrypoint: IsographEntrypoint<
|
|
30
|
+
TReadFromStore,
|
|
31
|
+
TClientFieldValue,
|
|
32
|
+
NormalizationAst,
|
|
33
|
+
TRawResponseType
|
|
34
|
+
>,
|
|
35
|
+
data: TRawResponseType,
|
|
36
|
+
variables: ExtractParameters<TReadFromStore>,
|
|
37
|
+
): ItemCleanupPair<FragmentReference<TReadFromStore, TClientFieldValue>> {
|
|
38
|
+
const encounteredIds: EncounteredIds = new Map();
|
|
39
|
+
environment.store = addNetworkResponseStoreLayer(environment.store);
|
|
40
|
+
normalizeData(
|
|
41
|
+
environment,
|
|
42
|
+
environment.store,
|
|
43
|
+
entrypoint.networkRequestInfo.normalizationAst.selections,
|
|
44
|
+
data,
|
|
45
|
+
variables,
|
|
46
|
+
{ __link: ROOT_ID, __typename: entrypoint.concreteType },
|
|
47
|
+
encounteredIds,
|
|
48
|
+
);
|
|
49
|
+
logMessage(environment, () => ({
|
|
50
|
+
kind: 'AfterNormalization',
|
|
51
|
+
store: environment.store,
|
|
52
|
+
encounteredIds,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
callSubscriptions(environment, encounteredIds);
|
|
56
|
+
|
|
57
|
+
const { fieldName, readerArtifactKind, readerWithRefetchQueries } =
|
|
58
|
+
getOrLoadReaderWithRefetchQueries(
|
|
59
|
+
environment,
|
|
60
|
+
entrypoint.readerWithRefetchQueries,
|
|
61
|
+
);
|
|
62
|
+
const [networkRequest, disposeNetworkRequest] =
|
|
63
|
+
retainQueryWithoutMakingNetworkRequest(environment, entrypoint, variables);
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
kind: 'FragmentReference',
|
|
68
|
+
readerWithRefetchQueries,
|
|
69
|
+
fieldName,
|
|
70
|
+
readerArtifactKind,
|
|
71
|
+
root: { __link: ROOT_ID, __typename: entrypoint.concreteType },
|
|
72
|
+
variables,
|
|
73
|
+
networkRequest,
|
|
74
|
+
},
|
|
75
|
+
() => {
|
|
76
|
+
disposeNetworkRequest();
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,15 +18,14 @@ export {
|
|
|
18
18
|
NOT_SET,
|
|
19
19
|
} from './core/PromiseWrapper';
|
|
20
20
|
export {
|
|
21
|
-
callSubscriptions,
|
|
22
|
-
subscribe,
|
|
23
21
|
normalizeData,
|
|
24
|
-
writeData,
|
|
25
22
|
type NetworkResponseObject,
|
|
26
23
|
type NetworkResponseValue,
|
|
27
24
|
type NetworkResponseScalarValue,
|
|
28
25
|
type EncounteredIds,
|
|
29
26
|
} from './core/cache';
|
|
27
|
+
export { callSubscriptions, subscribe } from './core/subscribe';
|
|
28
|
+
export { writeData } from './core/writeData';
|
|
30
29
|
export { makeNetworkRequest } from './core/makeNetworkRequest';
|
|
31
30
|
export {
|
|
32
31
|
ROOT_ID,
|
|
@@ -40,7 +39,6 @@ export {
|
|
|
40
39
|
type Link,
|
|
41
40
|
type StoreRecord,
|
|
42
41
|
type CacheMap,
|
|
43
|
-
createIsographEnvironment,
|
|
44
42
|
createIsographStore,
|
|
45
43
|
type FieldCache,
|
|
46
44
|
type Subscriptions,
|
|
@@ -159,6 +157,7 @@ export {
|
|
|
159
157
|
export { useLazyReference } from './react/useLazyReference';
|
|
160
158
|
export { useRerenderOnChange } from './react/useRerenderOnChange';
|
|
161
159
|
export { RenderAfterCommit__DO_NOT_USE } from './react/RenderAfterCommit__DO_NOT_USE';
|
|
160
|
+
export { createIsographEnvironment } from './react/createIsographEnvironment';
|
|
162
161
|
|
|
163
162
|
export { useClientSideDefer } from './loadable-hooks/useClientSideDefer';
|
|
164
163
|
export {
|
|
@@ -9,21 +9,21 @@ import {
|
|
|
9
9
|
} from '@isograph/reference-counted-pointer';
|
|
10
10
|
import { useState } from 'react';
|
|
11
11
|
import { subscribeToAnyChange } from '../core/cache';
|
|
12
|
-
import { FetchOptions } from '../core/check';
|
|
13
|
-
import {
|
|
12
|
+
import type { FetchOptions } from '../core/check';
|
|
13
|
+
import type {
|
|
14
14
|
FragmentReference,
|
|
15
|
-
|
|
15
|
+
UnknownTReadFromStore,
|
|
16
16
|
} from '../core/FragmentReference';
|
|
17
17
|
import { getPromiseState, readPromise } from '../core/PromiseWrapper';
|
|
18
18
|
import {
|
|
19
19
|
readButDoNotEvaluate,
|
|
20
20
|
type WithEncounteredRecords,
|
|
21
21
|
} from '../core/read';
|
|
22
|
-
import { LoadableField,
|
|
22
|
+
import type { LoadableField, ReaderAst } from '../core/reader';
|
|
23
23
|
import { getOrCreateCachedStartUpdate } from '../core/startUpdate';
|
|
24
24
|
import { useIsographEnvironment } from '../react/IsographEnvironmentProvider';
|
|
25
|
+
import { maybeUnwrapNetworkRequest } from '../react/maybeUnwrapNetworkRequest';
|
|
25
26
|
import { useSubscribeToMultiple } from '../react/useReadAndSubscribe';
|
|
26
|
-
import { maybeUnwrapNetworkRequest } from '../react/useResult';
|
|
27
27
|
|
|
28
28
|
export type UsePaginationReturnValue<
|
|
29
29
|
TReadFromStore extends UnknownTReadFromStore,
|
|
@@ -264,7 +264,7 @@ export function useConnectionSpecPagination<
|
|
|
264
264
|
const mostRecentFragmentReference =
|
|
265
265
|
mostRecentItem?.[0].getItemIfNotDisposed();
|
|
266
266
|
|
|
267
|
-
if (mostRecentItem != null && mostRecentFragmentReference
|
|
267
|
+
if (mostRecentItem != null && mostRecentFragmentReference == null) {
|
|
268
268
|
throw new Error(
|
|
269
269
|
'FragmentReference is unexpectedly disposed. \
|
|
270
270
|
This is indicative of a bug in Isograph.',
|
|
@@ -9,21 +9,21 @@ import {
|
|
|
9
9
|
} from '@isograph/reference-counted-pointer';
|
|
10
10
|
import { useState } from 'react';
|
|
11
11
|
import { subscribeToAnyChange } from '../core/cache';
|
|
12
|
-
import { FetchOptions } from '../core/check';
|
|
13
|
-
import {
|
|
12
|
+
import type { FetchOptions } from '../core/check';
|
|
13
|
+
import type {
|
|
14
14
|
FragmentReference,
|
|
15
|
-
|
|
15
|
+
UnknownTReadFromStore,
|
|
16
16
|
} from '../core/FragmentReference';
|
|
17
17
|
import { getPromiseState, readPromise } from '../core/PromiseWrapper';
|
|
18
18
|
import {
|
|
19
19
|
readButDoNotEvaluate,
|
|
20
20
|
type WithEncounteredRecords,
|
|
21
21
|
} from '../core/read';
|
|
22
|
-
import { LoadableField,
|
|
22
|
+
import type { LoadableField, ReaderAst } from '../core/reader';
|
|
23
23
|
import { getOrCreateCachedStartUpdate } from '../core/startUpdate';
|
|
24
24
|
import { useIsographEnvironment } from '../react/IsographEnvironmentProvider';
|
|
25
|
+
import { maybeUnwrapNetworkRequest } from '../react/maybeUnwrapNetworkRequest';
|
|
25
26
|
import { useSubscribeToMultiple } from '../react/useReadAndSubscribe';
|
|
26
|
-
import { maybeUnwrapNetworkRequest } from '../react/useResult';
|
|
27
27
|
|
|
28
28
|
export type UseSkipLimitReturnValue<
|
|
29
29
|
TReadFromStore extends UnknownTReadFromStore,
|
|
@@ -248,7 +248,7 @@ export function useSkipLimitPagination<
|
|
|
248
248
|
const mostRecentFragmentReference =
|
|
249
249
|
mostRecentItem?.[0].getItemIfNotDisposed();
|
|
250
250
|
|
|
251
|
-
if (mostRecentItem != null && mostRecentFragmentReference
|
|
251
|
+
if (mostRecentItem != null && mostRecentFragmentReference == null) {
|
|
252
252
|
throw new Error(
|
|
253
253
|
'FragmentReference is unexpectedly disposed. \
|
|
254
254
|
This is indicative of a bug in Isograph.',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createIsographEnvironmentCore,
|
|
3
|
+
type BaseStoreLayerData,
|
|
4
|
+
type IsographNetworkFunction,
|
|
5
|
+
type MissingFieldHandler,
|
|
6
|
+
} from '../core/IsographEnvironment';
|
|
7
|
+
import type { LogFunction } from '../core/logging';
|
|
8
|
+
import { componentFunction } from './useReadAndSubscribe';
|
|
9
|
+
|
|
10
|
+
export function createIsographEnvironment(
|
|
11
|
+
baseStoreLayerData: BaseStoreLayerData,
|
|
12
|
+
networkFunction: IsographNetworkFunction,
|
|
13
|
+
missingFieldHandler?: MissingFieldHandler | null,
|
|
14
|
+
logFunction?: LogFunction | null,
|
|
15
|
+
) {
|
|
16
|
+
return createIsographEnvironmentCore(
|
|
17
|
+
baseStoreLayerData,
|
|
18
|
+
networkFunction,
|
|
19
|
+
componentFunction,
|
|
20
|
+
missingFieldHandler,
|
|
21
|
+
logFunction,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PromiseWrapper, getPromiseState } from '../core/PromiseWrapper';
|
|
2
|
+
import type { NetworkRequestReaderOptions } from '../core/read';
|
|
3
|
+
|
|
4
|
+
export function maybeUnwrapNetworkRequest(
|
|
5
|
+
networkRequest: PromiseWrapper<void, any>,
|
|
6
|
+
networkRequestOptions: NetworkRequestReaderOptions,
|
|
7
|
+
) {
|
|
8
|
+
const state = getPromiseState(networkRequest);
|
|
9
|
+
if (state.kind === 'Err' && networkRequestOptions.throwOnNetworkError) {
|
|
10
|
+
throw state.error;
|
|
11
|
+
} else if (
|
|
12
|
+
state.kind === 'Pending' &&
|
|
13
|
+
networkRequestOptions.suspendIfInFlight
|
|
14
|
+
) {
|
|
15
|
+
throw state.promise;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { useLazyDisposableState } from '@isograph/react-disposable-state';
|
|
2
|
-
import {
|
|
3
|
-
getOrCreateCacheForArtifact,
|
|
4
|
-
type NetworkResponseObject,
|
|
5
|
-
} from '../core/cache';
|
|
2
|
+
import { type NetworkResponseObject } from '../core/cache';
|
|
6
3
|
import { FetchOptions, type RequiredFetchOptions } from '../core/check';
|
|
7
4
|
import {
|
|
8
5
|
IsographEntrypoint,
|
|
@@ -16,6 +13,7 @@ import {
|
|
|
16
13
|
} from '../core/FragmentReference';
|
|
17
14
|
import { logMessage } from '../core/logging';
|
|
18
15
|
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
|
16
|
+
import { getOrCreateCacheForArtifact } from '../core/getOrCreateCacheForArtifact';
|
|
19
17
|
|
|
20
18
|
export function useLazyReference<
|
|
21
19
|
TReadFromStore extends UnknownTReadFromStore,
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { subscribe } from '../core/cache';
|
|
3
2
|
import {
|
|
4
|
-
ExtractData,
|
|
5
|
-
FragmentReference,
|
|
3
|
+
type ExtractData,
|
|
4
|
+
type FragmentReference,
|
|
6
5
|
stableIdForFragmentReference,
|
|
7
6
|
type UnknownTReadFromStore,
|
|
8
7
|
} from '../core/FragmentReference';
|
|
8
|
+
import type { IsographComponentFunction } from '../core/IsographEnvironment';
|
|
9
|
+
import { logMessage } from '../core/logging';
|
|
10
|
+
import { readPromise } from '../core/PromiseWrapper';
|
|
9
11
|
import {
|
|
10
|
-
NetworkRequestReaderOptions,
|
|
12
|
+
type NetworkRequestReaderOptions,
|
|
11
13
|
readButDoNotEvaluate,
|
|
12
|
-
WithEncounteredRecords,
|
|
14
|
+
type WithEncounteredRecords,
|
|
13
15
|
} from '../core/read';
|
|
14
16
|
import type { ReaderAst } from '../core/reader';
|
|
17
|
+
import { subscribe } from '../core/subscribe';
|
|
15
18
|
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
|
19
|
+
import { maybeUnwrapNetworkRequest } from './maybeUnwrapNetworkRequest';
|
|
16
20
|
import { useRerenderOnChange } from './useRerenderOnChange';
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -80,3 +84,47 @@ export function useSubscribeToMultiple<
|
|
|
80
84
|
],
|
|
81
85
|
);
|
|
82
86
|
}
|
|
87
|
+
|
|
88
|
+
export const componentFunction: IsographComponentFunction = (
|
|
89
|
+
environment,
|
|
90
|
+
fragmentReference,
|
|
91
|
+
networkRequestOptions,
|
|
92
|
+
startUpdate,
|
|
93
|
+
) => {
|
|
94
|
+
function Component(additionalRuntimeProps: { [key: string]: any }) {
|
|
95
|
+
maybeUnwrapNetworkRequest(
|
|
96
|
+
fragmentReference.networkRequest,
|
|
97
|
+
networkRequestOptions,
|
|
98
|
+
);
|
|
99
|
+
const readerWithRefetchQueries = readPromise(
|
|
100
|
+
fragmentReference.readerWithRefetchQueries,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const data = useReadAndSubscribe(
|
|
104
|
+
fragmentReference,
|
|
105
|
+
networkRequestOptions,
|
|
106
|
+
readerWithRefetchQueries.readerArtifact.readerAst,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
logMessage(environment, () => ({
|
|
110
|
+
kind: 'ComponentRerendered',
|
|
111
|
+
componentName: fragmentReference.fieldName,
|
|
112
|
+
rootLink: fragmentReference.root,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
return readerWithRefetchQueries.readerArtifact.resolver(
|
|
116
|
+
// @ts-expect-error
|
|
117
|
+
{
|
|
118
|
+
data,
|
|
119
|
+
parameters: fragmentReference.variables,
|
|
120
|
+
startUpdate: readerWithRefetchQueries.readerArtifact.hasUpdatable
|
|
121
|
+
? startUpdate
|
|
122
|
+
: undefined,
|
|
123
|
+
},
|
|
124
|
+
additionalRuntimeProps,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const idString = `(type: ${fragmentReference.root.__typename}, id: ${fragmentReference.root.__link})`;
|
|
128
|
+
Component.displayName = `${fragmentReference.fieldName} ${idString} @component`;
|
|
129
|
+
return Component;
|
|
130
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { WithEncounteredRecords } from '../core/read';
|
|
2
|
+
import type { FragmentReference } from '../core/FragmentReference';
|
|
3
|
+
import type { WithEncounteredRecords } from '../core/read';
|
|
5
4
|
import type { ReaderAst } from '../core/reader';
|
|
5
|
+
import { subscribe } from '../core/subscribe';
|
|
6
6
|
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
|
7
7
|
|
|
8
8
|
// TODO add unit tests for this. Add integration tests that test
|
package/src/react/useResult.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { getOrCreateCachedComponent } from '../core/componentCache';
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
3
|
FragmentReference,
|
|
4
|
-
|
|
4
|
+
UnknownTReadFromStore,
|
|
5
5
|
} from '../core/FragmentReference';
|
|
6
|
+
import { readPromise } from '../core/PromiseWrapper';
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
PromiseWrapper,
|
|
9
|
-
readPromise,
|
|
10
|
-
} from '../core/PromiseWrapper';
|
|
11
|
-
import {
|
|
8
|
+
type NetworkRequestReaderOptions,
|
|
12
9
|
getNetworkRequestOptionsWithDefaults,
|
|
13
|
-
NetworkRequestReaderOptions,
|
|
14
10
|
} from '../core/read';
|
|
15
11
|
import { getOrCreateCachedStartUpdate } from '../core/startUpdate';
|
|
16
|
-
import { useIsographEnvironment } from '
|
|
12
|
+
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
|
13
|
+
import { maybeUnwrapNetworkRequest } from './maybeUnwrapNetworkRequest';
|
|
17
14
|
import { useReadAndSubscribe } from './useReadAndSubscribe';
|
|
18
15
|
|
|
19
16
|
export function useResult<
|
|
@@ -68,18 +65,3 @@ export function useResult<
|
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
|
|
72
|
-
export function maybeUnwrapNetworkRequest(
|
|
73
|
-
networkRequest: PromiseWrapper<void, any>,
|
|
74
|
-
networkRequestOptions: NetworkRequestReaderOptions,
|
|
75
|
-
) {
|
|
76
|
-
const state = getPromiseState(networkRequest);
|
|
77
|
-
if (state.kind === 'Err' && networkRequestOptions.throwOnNetworkError) {
|
|
78
|
-
throw state.error;
|
|
79
|
-
} else if (
|
|
80
|
-
state.kind === 'Pending' &&
|
|
81
|
-
networkRequestOptions.suspendIfInFlight
|
|
82
|
-
) {
|
|
83
|
-
throw state.promise;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
+
import { iso } from '@iso';
|
|
1
2
|
import { describe, expect, test } from 'vitest';
|
|
2
3
|
import {
|
|
3
4
|
garbageCollectEnvironment,
|
|
4
5
|
retainQuery,
|
|
5
6
|
type RetainedQuery,
|
|
6
7
|
} from '../core/garbageCollection';
|
|
7
|
-
import {
|
|
8
|
-
createIsographEnvironment,
|
|
9
|
-
ROOT_ID,
|
|
10
|
-
type BaseStoreLayerData,
|
|
11
|
-
} from '../core/IsographEnvironment';
|
|
8
|
+
import { ROOT_ID, type BaseStoreLayerData } from '../core/IsographEnvironment';
|
|
12
9
|
import { wrapResolvedValue } from '../core/PromiseWrapper';
|
|
13
|
-
import { iso } from './__isograph/iso';
|
|
14
10
|
import { meNameSuccessorRetainedQuery } from './meNameSuccessor';
|
|
15
11
|
import { nodeFieldRetainedQuery } from './nodeQuery';
|
|
12
|
+
import { createIsographEnvironment } from '../react/createIsographEnvironment';
|
|
16
13
|
|
|
17
14
|
const getDefaultStore = (): BaseStoreLayerData => ({
|
|
18
15
|
Query: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RetainedQuery } from '../core/garbageCollection';
|
|
2
2
|
import { ROOT_ID } from '../core/IsographEnvironment';
|
|
3
3
|
import { wrapResolvedValue } from '../core/PromiseWrapper';
|
|
4
|
-
import { iso } from '
|
|
4
|
+
import { iso } from '@iso';
|
|
5
5
|
|
|
6
6
|
export const meNameField = iso(`
|
|
7
7
|
field Query.meNameSuccessor {
|
package/src/tests/nodeQuery.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RetainedQuery } from '../core/garbageCollection';
|
|
2
2
|
import { ROOT_ID } from '../core/IsographEnvironment';
|
|
3
3
|
import { wrapResolvedValue } from '../core/PromiseWrapper';
|
|
4
|
-
import { iso } from '
|
|
4
|
+
import { iso } from '@iso';
|
|
5
5
|
|
|
6
6
|
// TODO investigate why this can't be in garbageCollection.test.ts without
|
|
7
7
|
// typescript incorrectly thinking it is referenced in its own initializer
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { iso } from '@iso';
|
|
1
2
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import {
|
|
4
|
-
createIsographEnvironment,
|
|
5
5
|
createIsographStore,
|
|
6
6
|
ROOT_ID,
|
|
7
7
|
type BaseStoreLayerData,
|
|
8
8
|
} from '../core/IsographEnvironment';
|
|
9
|
+
import { normalizeData } from '../core/cache';
|
|
10
|
+
import { getOrCreateCacheForArtifact } from '../core/getOrCreateCacheForArtifact';
|
|
9
11
|
import {
|
|
10
12
|
readButDoNotEvaluate,
|
|
11
13
|
type WithEncounteredRecords,
|
|
12
14
|
} from '../core/read';
|
|
13
|
-
import {
|
|
15
|
+
import { createIsographEnvironment } from '../react/createIsographEnvironment';
|
|
14
16
|
import type { Query__subquery__param } from './__isograph/Query/subquery/param_type';
|
|
15
17
|
|
|
16
18
|
let store: ReturnType<typeof createIsographStore>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { type EncounteredIds } from '../core/cache';
|
|
3
4
|
import {
|
|
4
|
-
createIsographEnvironment,
|
|
5
5
|
createIsographStore,
|
|
6
6
|
type IsographEnvironment,
|
|
7
7
|
type StoreLayerData,
|
|
@@ -15,8 +15,10 @@ import {
|
|
|
15
15
|
type OptimisticStoreLayer,
|
|
16
16
|
type StoreLayer,
|
|
17
17
|
} from '../core/optimisticProxy';
|
|
18
|
+
import { callSubscriptions } from '../core/subscribe';
|
|
19
|
+
import { createIsographEnvironment } from '../react/createIsographEnvironment';
|
|
18
20
|
|
|
19
|
-
vi.mock(import('../core/
|
|
21
|
+
vi.mock(import('../core/subscribe'), { spy: true });
|
|
20
22
|
|
|
21
23
|
const CHANGES = new Map([['Query', new Set(['__ROOT'])]]);
|
|
22
24
|
const NO_CHANGES = new Map();
|
|
@@ -813,7 +815,7 @@ describe('optimisticLayer', () => {
|
|
|
813
815
|
return revertOptimisticStoreLayerAndMaybeReplace(
|
|
814
816
|
environment,
|
|
815
817
|
node,
|
|
816
|
-
counter
|
|
818
|
+
counter == null
|
|
817
819
|
? counter
|
|
818
820
|
: (storeLayer) => update(storeLayer, () => counter),
|
|
819
821
|
);
|
|
@@ -851,7 +853,7 @@ describe('optimisticLayer', () => {
|
|
|
851
853
|
},
|
|
852
854
|
};
|
|
853
855
|
|
|
854
|
-
return counter
|
|
856
|
+
return counter !== nextCounter ? CHANGES : NO_CHANGES;
|
|
855
857
|
};
|
|
856
858
|
|
|
857
859
|
function ignoreReadonly(value: StoreLayer): { data: StoreLayerData } {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { iso } from '@iso';
|
|
1
2
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import type { ExtractUpdatableData } from '../core/FragmentReference';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
ROOT_ID,
|
|
7
|
-
type BaseStoreLayerData,
|
|
8
|
-
} from '../core/IsographEnvironment';
|
|
5
|
+
import { getOrCreateCacheForArtifact } from '../core/getOrCreateCacheForArtifact';
|
|
6
|
+
import { ROOT_ID, type BaseStoreLayerData } from '../core/IsographEnvironment';
|
|
9
7
|
import { createUpdatableProxy } from '../core/startUpdate';
|
|
10
|
-
import {
|
|
8
|
+
import { createIsographEnvironment } from '../react/createIsographEnvironment';
|
|
11
9
|
import type { Query__linkedUpdate__param } from './__isograph/Query/linkedUpdate/param_type';
|
|
12
10
|
import type { Query__startUpdate__param } from './__isograph/Query/startUpdate/param_type';
|
|
13
11
|
|