relay-runtime 21.0.0 → 21.0.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.
Files changed (107) hide show
  1. package/experimental.d.ts +34 -0
  2. package/experimental.js +1 -1
  3. package/experimental.js.flow +4 -4
  4. package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
  5. package/handlers/connection/ConnectionHandler.d.ts +51 -0
  6. package/handlers/connection/ConnectionInterface.d.ts +40 -0
  7. package/handlers/connection/MutationHandlers.d.ts +17 -0
  8. package/index.d.ts +274 -0
  9. package/index.js +1 -1
  10. package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +5 -0
  11. package/llm-docs/getting-started/compiler.mdx +19 -3
  12. package/llm-docs/getting-started/quick-start.mdx +15 -12
  13. package/llm-docs/guides/codemods.mdx +14 -1
  14. package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
  15. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +9 -9
  16. package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
  17. package/multi-actor-environment/MultiActorEnvironment.js.flow +22 -18
  18. package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
  19. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
  20. package/multi-actor-environment/index.d.ts +14 -0
  21. package/multi-actor-environment.d.ts +8 -0
  22. package/mutations/RelayDeclarativeMutationConfig.d.ts +70 -0
  23. package/mutations/applyOptimisticMutation.d.ts +25 -0
  24. package/mutations/commitLocalUpdate.d.ts +10 -0
  25. package/mutations/commitMutation.d.ts +48 -0
  26. package/mutations/commitMutation.js.flow +1 -1
  27. package/network/RelayNetwork.d.ts +12 -0
  28. package/network/RelayNetworkTypes.d.ts +145 -0
  29. package/network/RelayNetworkTypes.js.flow +15 -15
  30. package/network/RelayObservable.d.ts +197 -0
  31. package/network/RelayObservable.js.flow +21 -21
  32. package/network/RelayQueryResponseCache.d.ts +16 -0
  33. package/package.json +1 -1
  34. package/query/GraphQLTag.d.ts +45 -0
  35. package/query/fetchQuery.d.ts +21 -0
  36. package/query/fetchQueryInternal.d.ts +26 -0
  37. package/query/fetchQueryInternal.js.flow +4 -4
  38. package/query/fetchQuery_DEPRECATED.d.ts +17 -0
  39. package/store/ClientID.d.ts +14 -0
  40. package/store/DataChecker.js.flow +8 -6
  41. package/store/NormalizationEngine.js.flow +4 -1
  42. package/store/OperationExecutor.d.ts +51 -0
  43. package/store/OperationExecutor.js.flow +33 -30
  44. package/store/RelayModernEnvironment.d.ts +97 -0
  45. package/store/RelayModernEnvironment.js.flow +21 -21
  46. package/store/RelayModernOperationDescriptor.d.ts +28 -0
  47. package/store/RelayModernRecord.d.ts +92 -0
  48. package/store/RelayModernSelector.d.ts +123 -0
  49. package/store/RelayModernStore.d.ts +57 -0
  50. package/store/RelayOperationTracker.d.ts +29 -0
  51. package/store/RelayPublishQueue.js.flow +8 -8
  52. package/store/RelayRecordSource.d.ts +26 -0
  53. package/store/RelayRecordState.d.ts +28 -0
  54. package/store/RelayResponseNormalizer.d.ts +28 -0
  55. package/store/RelayResponseNormalizer.js.flow +8 -8
  56. package/store/RelayStoreTypes.d.ts +1327 -0
  57. package/store/RelayStoreTypes.js.flow +284 -280
  58. package/store/RelayStoreUtils.d.ts +86 -0
  59. package/store/RelayStoreUtils.js.flow +2 -2
  60. package/store/ResolverFragments.d.ts +43 -0
  61. package/store/ResolverFragments.js.flow +14 -6
  62. package/store/StoreInspector.js.flow +2 -2
  63. package/store/ViewerPattern.d.ts +11 -0
  64. package/store/createFragmentSpecResolver.d.ts +16 -0
  65. package/store/defaultGetDataID.js.flow +1 -1
  66. package/store/isRelayModernEnvironment.d.ts +8 -0
  67. package/store/live-resolvers/LiveResolverCache.js.flow +1 -1
  68. package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
  69. package/store/observeFragmentExperimental.d.ts +46 -0
  70. package/store/observeFragmentExperimental.js.flow +1 -1
  71. package/store/observeQueryExperimental.d.ts +30 -0
  72. package/store/readInlineData.d.ts +19 -0
  73. package/store/readInlineData.js.flow +1 -1
  74. package/store/waitForFragmentExperimental.d.ts +49 -0
  75. package/subscription/requestSubscription.d.ts +27 -0
  76. package/subscription/requestSubscription.js.flow +3 -3
  77. package/util/JSResourceTypes.flow.js.flow +4 -4
  78. package/util/NormalizationNode.d.ts +235 -0
  79. package/util/NormalizationNode.js.flow +124 -122
  80. package/util/ReaderNode.d.ts +264 -0
  81. package/util/ReaderNode.js.flow +152 -149
  82. package/util/RelayConcreteNode.d.ts +120 -0
  83. package/util/RelayConcreteNode.js.flow +31 -31
  84. package/util/RelayError.d.ts +13 -0
  85. package/util/RelayFeatureFlags.d.ts +40 -0
  86. package/util/RelayProfiler.d.ts +121 -0
  87. package/util/RelayReplaySubject.d.ts +25 -0
  88. package/util/RelayRuntimeTypes.d.ts +59 -0
  89. package/util/RelayRuntimeTypes.js.flow +33 -30
  90. package/util/createPayloadFor3DField.d.ts +17 -0
  91. package/util/createPayloadFor3DField.js.flow +4 -4
  92. package/util/deepFreeze.d.ts +8 -0
  93. package/util/getFragmentIdentifier.d.ts +10 -0
  94. package/util/getPaginationMetadata.d.ts +20 -0
  95. package/util/getPaginationVariables.d.ts +20 -0
  96. package/util/getPendingOperationsForFragment.d.ts +18 -0
  97. package/util/getRefetchMetadata.d.ts +19 -0
  98. package/util/getRelayHandleKey.d.ts +8 -0
  99. package/util/getRequestIdentifier.d.ts +17 -0
  100. package/util/getValueAtPath.d.ts +8 -0
  101. package/util/handlePotentialSnapshotErrors.d.ts +14 -0
  102. package/util/isEmptyObject.js.flow +1 -1
  103. package/util/isPromise.d.ts +8 -0
  104. package/util/isScalarAndEqual.d.ts +8 -0
  105. package/util/recycleNodesInto.d.ts +8 -0
  106. package/util/stableCopy.d.ts +8 -0
  107. package/util/withProvidedVariables.d.ts +19 -0
@@ -46,8 +46,8 @@ const {TYPE_SCHEMA_TYPE, generateTypeID} = require('./TypeID');
46
46
  const invariant = require('invariant');
47
47
 
48
48
  export type Availability = {
49
- +status: 'available' | 'missing',
50
- +mostRecentlyInvalidatedAt: ?number,
49
+ readonly status: 'available' | 'missing',
50
+ readonly mostRecentlyInvalidatedAt: ?number,
51
51
  };
52
52
 
53
53
  const {getModuleOperationKey, getStorageKey, getArgumentValues} =
@@ -118,12 +118,14 @@ class DataChecker {
118
118
  _useExecTimeResolvers: boolean;
119
119
  _variables: Variables;
120
120
  _shouldProcessClientComponents: ?boolean;
121
- +_getSourceForActor: (actorIdentifier: ActorIdentifier) => RecordSource;
122
- +_getTargetForActor: (
121
+ readonly _getSourceForActor: (
122
+ actorIdentifier: ActorIdentifier,
123
+ ) => RecordSource;
124
+ readonly _getTargetForActor: (
123
125
  actorIdentifier: ActorIdentifier,
124
126
  ) => MutableRecordSource;
125
- +_getDataID: GetDataID;
126
- +_mutatorRecordSourceProxyCache: Map<
127
+ readonly _getDataID: GetDataID;
128
+ readonly _mutatorRecordSourceProxyCache: Map<
127
129
  ActorIdentifier,
128
130
  [RelayRecordSourceMutator, RelayRecordSourceProxy],
129
131
  >;
@@ -62,7 +62,10 @@ export type NormalizationResult = Readonly<{
62
62
  }>;
63
63
 
64
64
  type Config = Readonly<{
65
- getDataID?: (fieldValue: {+[string]: unknown}, typeName: string) => unknown,
65
+ getDataID?: (
66
+ fieldValue: {readonly [string]: unknown},
67
+ typeName: string,
68
+ ) => unknown,
66
69
  normalizeResponse: NormalizeResponseFunction,
67
70
  operation: NormalizationOperation,
68
71
  operationLoader?: ?OperationLoader,
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { GraphQLResponse } from '../network/RelayNetworkTypes';
9
+ import {RelayObservable, Sink} from '../network/RelayObservable';
10
+ import { GetDataID } from './RelayResponseNormalizer';
11
+ import {
12
+ OperationDescriptor,
13
+ OperationLoader,
14
+ OperationTracker,
15
+ OptimisticResponseConfig,
16
+ PublishQueue,
17
+ ReactFlightPayloadDeserializer,
18
+ SelectorStoreUpdater,
19
+ Store,
20
+ } from './RelayStoreTypes';
21
+
22
+ export type ActiveState = 'active' | 'inactive';
23
+
24
+ export interface ExecuteConfig {
25
+ readonly getDataID: GetDataID;
26
+ readonly treatMissingFieldsAsNull: boolean;
27
+ readonly operation: OperationDescriptor;
28
+ readonly operationExecutions: Map<string, ActiveState>;
29
+ readonly operationLoader: OperationLoader | null | undefined;
30
+ readonly operationTracker?: OperationTracker | null | undefined;
31
+ readonly optimisticConfig: OptimisticResponseConfig | null | undefined;
32
+ readonly publishQueue: PublishQueue;
33
+ readonly reactFlightPayloadDeserializer?: ReactFlightPayloadDeserializer | null | undefined;
34
+ readonly scheduler?: TaskScheduler | null | undefined;
35
+ readonly sink: Sink<GraphQLResponse>;
36
+ readonly source: RelayObservable<GraphQLResponse>;
37
+ readonly store: Store;
38
+ readonly updater?: SelectorStoreUpdater | null | undefined;
39
+ readonly isClientPayload?: boolean | undefined;
40
+ }
41
+
42
+ export interface TaskScheduler {
43
+ cancel: (id: string) => void;
44
+ schedule: (fn: () => void) => string;
45
+ }
46
+
47
+ export interface Executor {
48
+ cancel: () => void;
49
+ }
50
+
51
+ export function execute(config: ExecuteConfig): Executor;
@@ -77,25 +77,25 @@ const warning = require('warning');
77
77
  type NetworkResponse = GraphQLResponse | RelayResponsePayload;
78
78
 
79
79
  export type ExecuteConfig<TMutation extends MutationParameters> = {
80
- +actorIdentifier: ActorIdentifier,
81
- +getDataID: GetDataID,
82
- +getPublishQueue: (actorIdentifier: ActorIdentifier) => PublishQueue,
83
- +getStore: (actorIdentifier: ActorIdentifier) => Store,
84
- +normalizeResponse: NormalizeResponseFunction,
85
- +isClientPayload?: boolean,
86
- +operation: OperationDescriptor,
87
- +operationExecutions: Map<string, ActiveState>,
88
- +operationLoader: ?OperationLoader,
89
- +operationTracker: OperationTracker,
90
- +optimisticConfig: ?OptimisticResponseConfig<TMutation>,
91
- +scheduler?: ?TaskScheduler,
92
- +shouldProcessClientComponents?: ?boolean,
93
- +sink: Sink<GraphQLResponse>,
94
- +source: RelayObservable<NetworkResponse>,
95
- +treatMissingFieldsAsNull: boolean,
96
- +deferDeduplicatedFields: boolean,
97
- +updater?: ?SelectorStoreUpdater<TMutation['response']>,
98
- +log: LogFunction,
80
+ readonly actorIdentifier: ActorIdentifier,
81
+ readonly getDataID: GetDataID,
82
+ readonly getPublishQueue: (actorIdentifier: ActorIdentifier) => PublishQueue,
83
+ readonly getStore: (actorIdentifier: ActorIdentifier) => Store,
84
+ readonly normalizeResponse: NormalizeResponseFunction,
85
+ readonly isClientPayload?: boolean,
86
+ readonly operation: OperationDescriptor,
87
+ readonly operationExecutions: Map<string, ActiveState>,
88
+ readonly operationLoader: ?OperationLoader,
89
+ readonly operationTracker: OperationTracker,
90
+ readonly optimisticConfig: ?OptimisticResponseConfig<TMutation>,
91
+ readonly scheduler?: ?TaskScheduler,
92
+ readonly shouldProcessClientComponents?: ?boolean,
93
+ readonly sink: Sink<GraphQLResponse>,
94
+ readonly source: RelayObservable<NetworkResponse>,
95
+ readonly treatMissingFieldsAsNull: boolean,
96
+ readonly deferDeduplicatedFields: boolean,
97
+ readonly updater?: ?SelectorStoreUpdater<TMutation['response']>,
98
+ readonly log: LogFunction,
99
99
  };
100
100
 
101
101
  export type ActiveState = 'active' | 'inactive';
@@ -104,12 +104,12 @@ type Label = string;
104
104
  type PathKey = string;
105
105
  type IncrementalResults =
106
106
  | {
107
- +kind: 'placeholder',
108
- +placeholder: IncrementalDataPlaceholder,
107
+ readonly kind: 'placeholder',
108
+ readonly placeholder: IncrementalDataPlaceholder,
109
109
  }
110
110
  | {
111
- +kind: 'response',
112
- +responses: Array<IncrementalGraphQLResponse>,
111
+ readonly kind: 'response',
112
+ readonly responses: Array<IncrementalGraphQLResponse>,
113
113
  };
114
114
 
115
115
  type IncrementalGraphQLResponse = {
@@ -147,24 +147,27 @@ class Executor<TMutation extends MutationParameters> {
147
147
  _optimisticUpdates: null | Array<OptimisticUpdate<TMutation>>;
148
148
  _useExecTimeResolvers: boolean;
149
149
  _pendingModulePayloadsCount: number;
150
- +_getPublishQueue: (actorIdentifier: ActorIdentifier) => PublishQueue;
150
+ readonly _getPublishQueue: (actorIdentifier: ActorIdentifier) => PublishQueue;
151
151
  _shouldProcessClientComponents: ?boolean;
152
152
  _scheduler: ?TaskScheduler;
153
153
  _sink: Sink<GraphQLResponse>;
154
154
  _source: Map<
155
155
  string,
156
- {+record: Record, +fieldPayloads: Array<HandleFieldPayload>},
156
+ {
157
+ readonly record: Record,
158
+ readonly fieldPayloads: Array<HandleFieldPayload>,
159
+ },
157
160
  >;
158
161
  _state: 'started' | 'loading_incremental' | 'loading_final' | 'completed';
159
- +_getStore: (actorIdentifier: ActorIdentifier) => Store;
162
+ readonly _getStore: (actorIdentifier: ActorIdentifier) => Store;
160
163
  _subscriptions: Map<number, Subscription>;
161
164
  _updater: ?SelectorStoreUpdater<TMutation['response']>;
162
165
  _asyncStoreUpdateDisposable: ?Disposable;
163
166
  _completeFns: Array<() => void>;
164
- +_retainDisposables: Map<ActorIdentifier, Disposable>;
165
- +_isClientPayload: boolean;
166
- +_isSubscriptionOperation: boolean;
167
- +_seenActors: Set<ActorIdentifier>;
167
+ readonly _retainDisposables: Map<ActorIdentifier, Disposable>;
168
+ readonly _isClientPayload: boolean;
169
+ readonly _isSubscriptionOperation: boolean;
170
+ readonly _seenActors: Set<ActorIdentifier>;
168
171
  _normalizeResponse: NormalizeResponseFunction;
169
172
  _execTimeResolverResponseComplete: boolean;
170
173
  _isClientQuery: boolean;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type { GetDataID } from './RelayResponseNormalizer';
9
+
10
+ import { HandlerProvider } from '../handlers/RelayDefaultHandlerProvider';
11
+ import {GraphQLResponse, Network, PayloadData, UploadableMap} from '../network/RelayNetworkTypes';
12
+ import { RelayObservable } from '../network/RelayObservable';
13
+ import {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
14
+ import { TaskScheduler } from './OperationExecutor';
15
+ import { RelayOperationTracker } from './RelayOperationTracker';
16
+ import {
17
+ Environment,
18
+ LogFunction,
19
+ MissingFieldHandler,
20
+ OperationAvailability,
21
+ OperationDescriptor,
22
+ OperationLoader,
23
+ OperationTracker,
24
+ OptimisticResponseConfig,
25
+ OptimisticUpdateFunction,
26
+ RelayFieldLogger,
27
+ SelectorStoreUpdater,
28
+ SingularReaderSelector,
29
+ Snapshot,
30
+ Store,
31
+ StoreUpdater,
32
+ } from './RelayStoreTypes';
33
+
34
+ export interface EnvironmentConfig {
35
+ readonly configName?: string | undefined;
36
+ readonly handlerProvider?: HandlerProvider | null | undefined;
37
+ readonly treatMissingFieldsAsNull?: boolean | undefined;
38
+ readonly log?: LogFunction | null | undefined;
39
+ readonly operationLoader?: OperationLoader | null | undefined;
40
+ readonly network: Network;
41
+ readonly scheduler?: TaskScheduler | null | undefined;
42
+ readonly store?: Store;
43
+ readonly missingFieldHandlers?: readonly MissingFieldHandler[] | null | undefined;
44
+ readonly operationTracker?: OperationTracker | null | undefined;
45
+ readonly getDataID?: GetDataID | null | undefined;
46
+ readonly UNSTABLE_defaultRenderPolicy?: RenderPolicy | null | undefined;
47
+ readonly options?: unknown | undefined;
48
+ readonly isServer?: boolean | undefined;
49
+ readonly relayFieldLogger?: RelayFieldLogger | null | undefined;
50
+ readonly shouldProcessClientComponents?: boolean | null | undefined;
51
+ }
52
+
53
+ export default class RelayModernEnvironment implements Environment {
54
+ options: unknown;
55
+ configName: string | null | undefined;
56
+ relayFieldLogger: RelayFieldLogger;
57
+ constructor(config: EnvironmentConfig);
58
+ getStore(): Store;
59
+ getNetwork(): Network;
60
+ getOperationTracker(): RelayOperationTracker;
61
+ isRequestActive(requestIdentifier: string): boolean;
62
+ applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable;
63
+ revertUpdate(update: OptimisticUpdateFunction): void;
64
+ replaceUpdate(update: OptimisticUpdateFunction, newUpdate: OptimisticUpdateFunction): void;
65
+ applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable;
66
+ check(operation: OperationDescriptor): OperationAvailability;
67
+ commitPayload(operationDescriptor: OperationDescriptor, payload: PayloadData): void;
68
+ commitUpdate(updater: StoreUpdater): void;
69
+ lookup(readSelector: SingularReaderSelector): Snapshot;
70
+ subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
71
+ retain(operation: OperationDescriptor): Disposable;
72
+ isServer(): boolean;
73
+ execute(data: {
74
+ operation: OperationDescriptor;
75
+ updater?: SelectorStoreUpdater | null | undefined;
76
+ }): RelayObservable<GraphQLResponse>;
77
+ executeMutation({
78
+ operation,
79
+ optimisticResponse,
80
+ optimisticUpdater,
81
+ updater,
82
+ uploadables,
83
+ }: {
84
+ operation: OperationDescriptor;
85
+ optimisticUpdater?: SelectorStoreUpdater | null | undefined;
86
+ optimisticResponse?: { [key: string]: any } | null | undefined;
87
+ updater?: SelectorStoreUpdater | null | undefined;
88
+ uploadables?: UploadableMap | null | undefined;
89
+ }): RelayObservable<GraphQLResponse>;
90
+ executeWithSource({
91
+ operation,
92
+ source,
93
+ }: {
94
+ operation: OperationDescriptor;
95
+ source: RelayObservable<GraphQLResponse>;
96
+ }): RelayObservable<GraphQLResponse>;
97
+ }
@@ -64,29 +64,29 @@ const RelayRecordSource = require('./RelayRecordSource');
64
64
  const invariant = require('invariant');
65
65
 
66
66
  export type EnvironmentConfig = {
67
- +configName?: string,
68
- +handlerProvider?: ?HandlerProvider,
69
- +treatMissingFieldsAsNull?: boolean,
70
- +deferDeduplicatedFields?: boolean,
71
- +log?: ?LogFunction,
72
- +operationLoader?: ?OperationLoader,
73
- +network: INetwork,
74
- +normalizeResponse?: ?NormalizeResponseFunction,
75
- +scheduler?: ?TaskScheduler,
76
- +store?: Store,
77
- +missingFieldHandlers?: ?ReadonlyArray<MissingFieldHandler>,
78
- +operationTracker?: ?OperationTracker,
79
- +getDataID?: ?GetDataID,
80
- +UNSTABLE_defaultRenderPolicy?: ?RenderPolicy,
81
- +options?: unknown,
82
- +isServer?: boolean,
83
- +relayFieldLogger?: ?RelayFieldLogger,
84
- +shouldProcessClientComponents?: ?boolean,
67
+ readonly configName?: string,
68
+ readonly handlerProvider?: ?HandlerProvider,
69
+ readonly treatMissingFieldsAsNull?: boolean,
70
+ readonly deferDeduplicatedFields?: boolean,
71
+ readonly log?: ?LogFunction,
72
+ readonly operationLoader?: ?OperationLoader,
73
+ readonly network: INetwork,
74
+ readonly normalizeResponse?: ?NormalizeResponseFunction,
75
+ readonly scheduler?: ?TaskScheduler,
76
+ readonly store?: Store,
77
+ readonly missingFieldHandlers?: ?ReadonlyArray<MissingFieldHandler>,
78
+ readonly operationTracker?: ?OperationTracker,
79
+ readonly getDataID?: ?GetDataID,
80
+ readonly UNSTABLE_defaultRenderPolicy?: ?RenderPolicy,
81
+ readonly options?: unknown,
82
+ readonly isServer?: boolean,
83
+ readonly relayFieldLogger?: ?RelayFieldLogger,
84
+ readonly shouldProcessClientComponents?: ?boolean,
85
85
  };
86
86
 
87
87
  class RelayModernEnvironment implements IEnvironment {
88
88
  __log: LogFunction;
89
- +_defaultRenderPolicy: RenderPolicy;
89
+ readonly _defaultRenderPolicy: RenderPolicy;
90
90
  _operationLoader: ?OperationLoader;
91
91
  _shouldProcessClientComponents: ?boolean;
92
92
  _network: INetwork;
@@ -100,8 +100,8 @@ class RelayModernEnvironment implements IEnvironment {
100
100
  _treatMissingFieldsAsNull: boolean;
101
101
  _deferDeduplicatedFields: boolean;
102
102
  _operationExecutions: Map<string, ActiveState>;
103
- +options: unknown;
104
- +_isServer: boolean;
103
+ readonly options: unknown;
104
+ readonly _isServer: boolean;
105
105
  relayFieldLogger: RelayFieldLogger;
106
106
  _normalizeResponse: NormalizeResponseFunction;
107
107
 
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { ConcreteRequest } from '../util/RelayConcreteNode';
9
+ import {CacheConfig, DataID, Variables} from '../util/RelayRuntimeTypes';
10
+ import {OperationDescriptor, RequestDescriptor} from './RelayStoreTypes';
11
+ /**
12
+ * Creates an instance of the `OperationDescriptor` type defined in
13
+ * `RelayStoreTypes` given an operation and some variables. The input variables
14
+ * are filtered to exclude variables that do not match defined arguments on the
15
+ * operation, and default values are populated for null values.
16
+ */
17
+ export function createOperationDescriptor(
18
+ request: ConcreteRequest,
19
+ variables: Variables,
20
+ cacheConfig?: CacheConfig | null,
21
+ dataID?: DataID,
22
+ ): OperationDescriptor;
23
+
24
+ export function createRequestDescriptor(
25
+ request: ConcreteRequest,
26
+ variables: Variables,
27
+ cacheConfig?: CacheConfig | null,
28
+ ): RequestDescriptor;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { DataID } from '../util/RelayRuntimeTypes';
9
+ import { Record } from './RelayStoreTypes';
10
+
11
+ export class RelayModernRecord {
12
+ /**
13
+ * Clone a record.
14
+ */
15
+ clone(record: Record): Record;
16
+
17
+ /**
18
+ * Copies all fields from `source` to `sink`, excluding `__id` and `__typename`.
19
+ *
20
+ * NOTE: This function does not treat `id` specially. To preserve the id,
21
+ * manually reset it after calling this function. Also note that values are
22
+ * copied by reference and not value; callers should ensure that values are
23
+ * copied on write.
24
+ */
25
+ copyFields(source: Record, sink: Record): void;
26
+
27
+ /**
28
+ * Create a new record.
29
+ */
30
+ create(dataID: DataID, typeName: string): Record;
31
+
32
+ /**
33
+ * Get the record's `id` if available or the client-generated identifier.
34
+ */
35
+ getDataID(record: Record): DataID;
36
+
37
+ /**
38
+ * Get the concrete type of the record.
39
+ */
40
+ getType(record: Record): string;
41
+
42
+ /**
43
+ * Get a scalar (non-link) field value.
44
+ */
45
+ getValue(record: Record, storageKey: string): unknown;
46
+
47
+ /**
48
+ * Get the value of a field as a reference to another record. Throws if the
49
+ * field has a different type.
50
+ */
51
+ getLinkedRecordID(record: Record, storageKey: string): DataID | null;
52
+
53
+ /**
54
+ * Get the value of a field as a list of references to other records. Throws if
55
+ * the field has a different type.
56
+ */
57
+ getLinkedRecordIDs(record: Record, storageKey: string): DataID[] | null;
58
+
59
+ /**
60
+ * Compares the fields of a previous and new record, returning either the
61
+ * previous record if all fields are equal or a new record (with merged fields)
62
+ * if any fields have changed.
63
+ */
64
+ update(prevRecord: Record, nextRecord: Record): Record;
65
+
66
+ /**
67
+ * Returns a new record with the contents of the given records. Fields in the
68
+ * second record will overwrite identical fields in the first record.
69
+ */
70
+ merge(record1: Record, record2: Record): Record;
71
+
72
+ /**
73
+ * Prevent modifications to the record. Attempts to call `set*` functions on a
74
+ * frozen record will fatal at runtime.
75
+ */
76
+ freeze(record: Record): void;
77
+
78
+ /**
79
+ * Set the value of a storageKey to a scalar.
80
+ */
81
+ setValue(record: Record, storageKey: string, value: any): void;
82
+
83
+ /**
84
+ * Set the value of a field to a reference to another record.
85
+ */
86
+ setLinkedRecordID(record: Record, storageKey: string, linkedID: DataID): void;
87
+
88
+ /**
89
+ * Set the value of a field to a list of references other records.
90
+ */
91
+ setLinkedRecordIDs(record: Record, storageKey: string, linkedIDs: DataID[] | null): void;
92
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { NormalizationSelectableNode } from '../util/NormalizationNode';
9
+ import { ReaderFragment } from '../util/ReaderNode';
10
+ import {DataID, Variables} from '../util/RelayRuntimeTypes';
11
+ import {
12
+ NormalizationSelector,
13
+ PluralReaderSelector,
14
+ ReaderSelector,
15
+ RequestDescriptor,
16
+ SingularReaderSelector,
17
+ } from './RelayStoreTypes';
18
+
19
+ /**
20
+ * Given the result `item` from a parent that fetched `fragment`, creates a
21
+ * selector that can be used to read the results of that fragment for that item.
22
+ *
23
+ * Example:
24
+ *
25
+ * Given two fragments as follows:
26
+ *
27
+ * ```
28
+ * fragment Parent on User {
29
+ * id
30
+ * ...Child
31
+ * }
32
+ * fragment Child on User {
33
+ * name
34
+ * }
35
+ * ```
36
+ *
37
+ * And given some object `parent` that is the results of `Parent` for id "4",
38
+ * the results of `Child` can be accessed by first getting a selector and then
39
+ * using that selector to `lookup()` the results against the environment:
40
+ *
41
+ * ```
42
+ * const childSelector = getSingularSelector(queryVariables, Child, parent);
43
+ * const childData = environment.lookup(childSelector).data;
44
+ * ```
45
+ */
46
+ export function getSingularSelector(fragment: ReaderFragment, item: unknown): SingularReaderSelector;
47
+
48
+ /**
49
+ * Given the result `items` from a parent that fetched `fragment`, creates a
50
+ * selector that can be used to read the results of that fragment on those
51
+ * items. This is similar to `getSingularSelector` but for "plural" fragments that
52
+ * expect an array of results and therefore return an array of selectors.
53
+ */
54
+ export function getPluralSelector(fragment: ReaderFragment, items: unknown[]): PluralReaderSelector;
55
+
56
+ export function getSelector(fragment: ReaderFragment, item: unknown | unknown[]): ReaderSelector;
57
+
58
+ /**
59
+ * Given a mapping of keys -> results and a mapping of keys -> fragments,
60
+ * extracts the selectors for those fragments from the results.
61
+ *
62
+ * The canonical use-case for this function is ReactRelayFragmentContainer, which
63
+ * uses this function to convert (props, fragments) into selectors so that it
64
+ * can read the results to pass to the inner component.
65
+ */
66
+ export function getSelectorsFromObject(
67
+ fragments: { [key: string]: ReaderFragment },
68
+ object: { [key: string]: any },
69
+ ): { [key: string]: ReaderSelector };
70
+
71
+ /**
72
+ * Given a mapping of keys -> results and a mapping of keys -> fragments,
73
+ * extracts a mapping of keys -> id(s) of the results.
74
+ *
75
+ * Similar to `getSelectorsFromObject()`, this function can be useful in
76
+ * determining the "identity" of the props passed to a component.
77
+ */
78
+ export function getDataIDsFromObject(
79
+ fragments: { [key: string]: ReaderFragment },
80
+ object: { [key: string]: any },
81
+ ): { [key: string]: DataID | DataID[] };
82
+
83
+ export function getDataIDsFromFragment(fragment: ReaderFragment, item: unknown | unknown[]): DataID | DataID[];
84
+
85
+ /**
86
+ * Given a mapping of keys -> results and a mapping of keys -> fragments,
87
+ * extracts the merged variables that would be in scope for those
88
+ * fragments/results.
89
+ *
90
+ * This can be useful in determing what varaibles were used to fetch the data
91
+ * for a Relay container, for example.
92
+ */
93
+ export function getVariablesFromObject(
94
+ fragments: { [key: string]: ReaderFragment },
95
+ object: { [key: string]: any },
96
+ ): Variables;
97
+
98
+ export function getVariablesFromFragment(fragment: ReaderFragment, item: unknown | unknown[]): Variables;
99
+
100
+ export function getVariablesFromSingularFragment(fragment: ReaderFragment, item: unknown): Variables;
101
+
102
+ export function getVariablesFromPluralFragment(fragment: ReaderFragment, items: unknown[]): Variables;
103
+
104
+ /**
105
+ * Determine if two selectors are equal (represent the same selection). Note
106
+ * that this function returns `false` when the two queries/fragments are
107
+ * different objects, even if they select the same fields.
108
+ */
109
+ export function areEqualSelectors(thisSelector: SingularReaderSelector, thatSelector: SingularReaderSelector): boolean;
110
+
111
+ export function createReaderSelector(
112
+ fragment: ReaderFragment,
113
+ dataID: DataID,
114
+ variables: Variables,
115
+ request: RequestDescriptor,
116
+ isWithinUnmatchedTypeRefinement?: boolean, // default: `false`
117
+ ): SingularReaderSelector;
118
+
119
+ export function createNormalizationSelector(
120
+ node: NormalizationSelectableNode,
121
+ dataID: DataID,
122
+ variables: Variables,
123
+ ): NormalizationSelector;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {DataID, Disposable} from '../util/RelayRuntimeTypes';
9
+ import {
10
+ CheckOptions,
11
+ LogFunction,
12
+ MutableRecordSource,
13
+ OperationAvailability,
14
+ OperationDescriptor,
15
+ OperationLoader,
16
+ RecordSource,
17
+ RequestDescriptor,
18
+ ResolverContext,
19
+ Scheduler,
20
+ SingularReaderSelector,
21
+ Snapshot,
22
+ Store,
23
+ } from './RelayStoreTypes';
24
+
25
+ export interface InvalidationState {
26
+ dataIDs: readonly DataID[];
27
+ invalidations: Map<DataID, number | undefined | null>;
28
+ }
29
+
30
+ export default class RelayModernStore implements Store {
31
+ constructor(
32
+ source: MutableRecordSource,
33
+ options?: {
34
+ gcScheduler?: Scheduler | null | undefined;
35
+ log?: LogFunction | null | undefined;
36
+ operationLoader?: OperationLoader | null | undefined;
37
+ gcReleaseBufferSize?: number | null | undefined;
38
+ queryCacheExpirationTime?: number | null | undefined;
39
+ resolverContext?: ResolverContext;
40
+ },
41
+ );
42
+ getSource(): RecordSource;
43
+ check(operation: OperationDescriptor, options?: CheckOptions): OperationAvailability;
44
+ retain(operation: OperationDescriptor): Disposable;
45
+ lookup(selector: SingularReaderSelector): Snapshot;
46
+ notify(sourceOperation?: OperationDescriptor, invalidateStore?: boolean): readonly RequestDescriptor[];
47
+ publish(source: RecordSource, idsMarkedForInvalidation?: Set<DataID>): void;
48
+ subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
49
+ holdGC(): Disposable;
50
+ lookupInvalidationState(dataIDs: readonly DataID[]): InvalidationState;
51
+ checkInvalidationState(previousInvalidationState: InvalidationState): boolean;
52
+ subscribeToInvalidationState(invalidationState: InvalidationState, callback: () => void): Disposable;
53
+ toJSON(): unknown;
54
+ snapshot(): void;
55
+ restore(): void;
56
+ scheduleGC(): void;
57
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { RequestDescriptor } from './RelayStoreTypes';
9
+
10
+ export class RelayOperationTracker {
11
+ /**
12
+ * Update the map of current processing operations with the set of
13
+ * affected owners and notify subscribers
14
+ */
15
+ update(pendingOperation: RequestDescriptor, affectedOwners: Set<RequestDescriptor>): void;
16
+
17
+ /**
18
+ * Once pending operation is completed we need to remove it
19
+ * from all tracking maps
20
+ */
21
+ complete(pendingOperation: RequestDescriptor): void;
22
+
23
+ _resolveOwnerResolvers(owner: RequestDescriptor): void;
24
+
25
+ getPendingOperationsAffectingOwner(owner: RequestDescriptor): {
26
+ promise: Promise<void>;
27
+ pendingOperations: readonly RequestDescriptor[];
28
+ } | null;
29
+ }