@types/relay-runtime
Advanced tools
Comparing version 1.3.13 to 4.0.0
@@ -1,209 +0,370 @@ | ||
// Type definitions for relay-runtime 1.3 | ||
// Type definitions for relay-runtime 4.0 | ||
// Project: https://github.com/facebook/relay, https://facebook.github.io/relay | ||
// Definitions by: Matt Martin <https://github.com/voxmatt> | ||
// Eloy Durán <https://github.com/alloy> | ||
// Cameron Knight <https://github.com/ckknight> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.9 | ||
// TypeScript Version: 3.0 | ||
// Prettified with: | ||
// $ prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 --write --print-width 120 \ | ||
// types/{react-relay,relay-runtime}/{,*}/*.ts* | ||
// ./handlers/connection/RelayConnectionHandler | ||
export interface ConnectionMetadata { | ||
path: ReadonlyArray<string> | null | undefined; | ||
direction: string | null | undefined; // 'forward' | 'backward' | 'bidirectional' | null | undefined; | ||
cursor: string | null | undefined; | ||
count: string | null | undefined; | ||
} | ||
/** | ||
* SOURCE: | ||
* Relay 1.3.0 | ||
* https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js | ||
*/ | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Maybe Fix | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type RelayConcreteNode = any; | ||
export type RelayMutationTransaction = any; | ||
export type RelayMutationRequest = any; | ||
export type RelayQueryRequest = any; | ||
export type ConcreteFragmentDefinition = object; | ||
export type ConcreteOperationDefinition = object; | ||
export type ReaderFragment = object; | ||
// ./handlers/connection/RelayConnectionInterface | ||
export interface Record { | ||
[key: string]: unknown; | ||
} | ||
/** | ||
* FIXME: RelayContainer used to be typed with ReactClass<any>, but | ||
* ReactClass is broken and allows for access to any property. For example | ||
* ReactClass<any>.getFragment('foo') is valid even though ReactClass has no | ||
* such getFragment() type definition. When ReactClass is fixed this causes a | ||
* lot of errors in Relay code since methods like getFragment() are used often | ||
* but have no definition in Relay's types. Suppressing for now. | ||
*/ | ||
export type RelayContainer = any; | ||
export interface EdgeRecord extends Record { | ||
cursor: unknown; | ||
node: Record; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Used in artifacts | ||
// emitted by | ||
// relay-compiler | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface PageInfo { | ||
endCursor: string | null | undefined; | ||
hasNextPage: boolean; | ||
hasPreviousPage: boolean; | ||
startCursor: string | null | undefined; | ||
} | ||
// File: https://github.com/facebook/relay/blob/fe0e70f10bbcba1fff89911313ea69f24569464b/packages/relay-runtime/util/RelayConcreteNode.js | ||
export type ConcreteFragment = any; | ||
export type ConcreteRequest = any; | ||
export type ConcreteBatchRequest = any; | ||
// ./mutations/RelayDeclarativeMutationConfig | ||
interface RangeAddConfig { | ||
type: 'RANGE_ADD'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionInfo?: ReadonlyArray<{ | ||
key: string; | ||
filters?: Variables; | ||
rangeBehavior: string; | ||
}>; | ||
connectionName?: string; | ||
edgeName: string; | ||
rangeBehaviors?: RangeBehaviors; | ||
} | ||
export function getRequest(taggedNode: GraphQLTaggedNode): ConcreteRequest; | ||
interface RangeDeleteConfig { | ||
type: 'RANGE_DELETE'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionKeys?: ReadonlyArray<{ | ||
key: string; | ||
filters?: Variables; | ||
}>; | ||
connectionName?: string; | ||
deletedIDFieldName: string | ReadonlyArray<string>; | ||
pathToConnection: ReadonlyArray<string>; | ||
} | ||
export type RequestNode = ConcreteRequest | ConcreteBatchRequest; | ||
interface NodeDeleteConfig { | ||
type: 'NODE_DELETE'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionName?: string; | ||
deletedIDFieldName: string; | ||
} | ||
export interface OperationBase { | ||
variables: object; | ||
response: object; | ||
// Unused in Relay Modern | ||
interface LegacyFieldsChangeConfig { | ||
type: 'FIELDS_CHANGE'; | ||
fieldIDs: { [fieldName: string]: DataID | ReadonlyArray<DataID> }; | ||
} | ||
export interface OperationDefaults { | ||
// Unused in Relay Modern | ||
interface LegacyRequiredChildrenConfig { | ||
type: 'REQUIRED_CHILDREN'; | ||
children: ReadonlyArray<unknown>; | ||
} | ||
export type DeclarativeMutationConfig = | ||
| RangeAddConfig | ||
| RangeDeleteConfig | ||
| NodeDeleteConfig | ||
| LegacyFieldsChangeConfig | ||
| LegacyRequiredChildrenConfig; | ||
export type MutationType = 'RANGE_ADD' | 'RANGE_DELETE' | 'NODE_DELETE' | 'FIELDS_CHANGE' | 'REQUIRED_CHILDREN'; | ||
export type RangeOperation = 'append' | 'ignore' | 'prepend' | 'refetch' | 'remove'; | ||
export type RangeBehaviors = | ||
| ((connectionArgs: { [name: string]: unknown }) => RangeOperation) | ||
| { | ||
[key: string]: RangeOperation; | ||
}; | ||
// ./mutations/applyRelayModernOptimisticMutation | ||
export interface OptimisticMutationConfig { | ||
configs?: ReadonlyArray<DeclarativeMutationConfig> | null; | ||
mutation: GraphQLTaggedNode; | ||
variables: Variables; | ||
response: Variables; | ||
optimisticUpdater?: SelectorStoreUpdater | null; | ||
optimisticResponse?: object; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Constants | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export const ROOT_ID: string; | ||
// ./mutations/commitRelayModernMutation | ||
export interface MutationConfig<TOperation extends OperationType> { | ||
configs?: ReadonlyArray<DeclarativeMutationConfig>; | ||
mutation: GraphQLTaggedNode; | ||
variables: TOperation['variables']; | ||
uploadables?: UploadableMap; | ||
onCompleted?: | ||
| ((response: TOperation['response'], errors: ReadonlyArray<PayloadError> | null | undefined) => void) | ||
| null; | ||
onError?: ((error: Error) => void) | null; | ||
optimisticUpdater?: SelectorStoreUpdater | null; | ||
optimisticResponse?: TOperation['response'] | null; | ||
updater?: SelectorStoreUpdater<TOperation['response']> | null; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayQL | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type RelayQL = (strings: string[], ...substitutions: any[]) => RelayConcreteNode; | ||
// ./network/RelayNetworkLoggerTransaction | ||
export interface RelayNetworkLog { | ||
label: string; | ||
values: ReadonlyArray<unknown>; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayModernGraphQLTag | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface GeneratedNodeMap { | ||
[key: string]: GraphQLTaggedNode; | ||
} | ||
export type GraphQLTaggedNode = | ||
| (() => ConcreteFragment | RequestNode) | ||
// ./network/RelayNetworkTypes | ||
export type ExecuteFunction = ( | ||
request: RequestParameters, | ||
variables: Variables, | ||
cacheConfig: CacheConfig, | ||
uploadables?: UploadableMap | null | ||
) => RelayObservable<GraphQLResponse>; | ||
export type FetchFunction = ( | ||
request: RequestParameters, | ||
variables: Variables, | ||
cacheConfig: CacheConfig, | ||
uploadables?: UploadableMap | null | ||
) => ObservableFromValue<GraphQLResponse>; | ||
export type GraphQLResponse = | ||
| { | ||
modern(): ConcreteFragment | RequestNode; | ||
classic(relayQL: RelayQL): ConcreteFragmentDefinition | ConcreteOperationDefinition; | ||
data: PayloadData; | ||
errors?: ReadonlyArray<PayloadError>; | ||
extensions?: PayloadExtensions; | ||
} | ||
| { | ||
data?: PayloadData | null; | ||
errors: ReadonlyArray<PayloadError>; | ||
extensions?: PayloadExtensions; | ||
}; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// General Usage | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type DataID = string; | ||
export interface Variables { | ||
[name: string]: any; | ||
export interface LegacyObserver<T> { | ||
onCompleted?: () => void; | ||
onError?: (error: Error) => void; | ||
onNext?: (data: T) => void; | ||
} | ||
export type Uploadable = File | Blob; | ||
export interface UploadableMap { | ||
[key: string]: Uploadable; | ||
interface Network { | ||
execute: ExecuteFunction; | ||
} | ||
export { Network as INetwork }; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayNetworkTypes | ||
// Version: Relay 1.3.0 | ||
// File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayNetworkTypes.js | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface PayloadData { | ||
[key: string]: unknown; | ||
} | ||
export interface LegacyObserver<T> { | ||
onCompleted?(): void; | ||
onError?(error: Error): void; | ||
onNext?(data: T): void; | ||
} | ||
export interface PayloadError { | ||
message: string; | ||
locations?: Array<{ | ||
locations?: ReadonlyArray<{ | ||
line: number; | ||
column: number; | ||
}>; | ||
severity?: 'CRITICAL' | 'ERROR' | 'WARNING'; // Not officially part of the spec, but used at Facebook | ||
} | ||
/** | ||
* A function that executes a GraphQL operation with request/response semantics. | ||
* | ||
* May return an Observable or Promise of a raw server response. | ||
*/ | ||
export type FetchFunction = ( | ||
operation: RequestNode, | ||
variables: Variables, | ||
cacheConfig: CacheConfig, | ||
uploadables?: UploadableMap | ||
) => ObservableFromValue<QueryPayload>; | ||
/** | ||
* A function that executes a GraphQL subscription operation, returning one or | ||
* more raw server responses over time. | ||
* | ||
* May return an Observable, otherwise must call the callbacks found in the | ||
* fourth parameter. | ||
*/ | ||
export type SubscribeFunction = ( | ||
operation: RequestNode, | ||
request: RequestParameters, | ||
variables: Variables, | ||
cacheConfig: CacheConfig, | ||
observer: LegacyObserver<QueryPayload> | ||
) => RelayObservable<QueryPayload> | Disposable; | ||
observer?: LegacyObserver<GraphQLResponse> | ||
) => RelayObservable<GraphQLResponse> | Disposable; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayQueryResponseCache | ||
// Version: Relay 1.3.0 | ||
// File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayQueryResponseCache.js | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type Uploadable = File | Blob; | ||
export interface UploadableMap { | ||
[key: string]: Uploadable; | ||
} | ||
/** | ||
* A cache for storing query responses, featuring: | ||
* - `get` with TTL | ||
* - cache size limiting, with least-recently *updated* entries purged first | ||
*/ | ||
export class QueryResponseCache { | ||
constructor(options: { size: number; ttl: number }); | ||
clear(): void; | ||
get(queryID: string, variables: Variables): QueryPayload | null; | ||
set(queryID: string, variables: Variables, payload: QueryPayload): void; | ||
interface PayloadExtensions { | ||
[key: string]: unknown; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayStoreTypes | ||
// Version: Relay 1.3.0 | ||
// File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/store/RelayStoreTypes.js | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
/** | ||
* A function that receives a proxy over the store and may trigger side-effects | ||
* (indirectly) by calling `set*` methods on the store or its record proxies. | ||
*/ | ||
export type StoreUpdater = (store: RecordSourceProxy) => void; | ||
// ./network/RelayObservable | ||
export type ObservableFromValue<T> = Subscribable<T> | Promise<T> | T; | ||
/** | ||
* Similar to StoreUpdater, but accepts a proxy tied to a specific selector in | ||
* order to easily access the root fields of a query/mutation as well as a | ||
* second argument of the response object of the mutation. | ||
*/ | ||
export type SelectorStoreUpdater<T = any> = ( | ||
store: RecordSourceSelectorProxy, | ||
// Actually RelayCombinedEnvironmentTypes#SelectorData, but mixed is | ||
// inconvenient to access deeply in product code. | ||
data: T | ||
) => void; | ||
export interface Observer<T> { | ||
readonly start?: (subscription: Subscription) => void; | ||
readonly next?: (value: T) => void; | ||
readonly error?: (error: Error) => void; | ||
readonly complete?: () => void; | ||
readonly unsubscribe?: (subscription: Subscription) => void; | ||
} | ||
/** | ||
* Extends the RecordSourceProxy interface with methods for accessing the root | ||
* fields of a Selector. | ||
*/ | ||
export interface RecordSourceSelectorProxy { | ||
create(dataID: DataID, typeName: string): RecordProxy; | ||
delete(dataID: DataID): void; | ||
get(dataID: DataID): RecordProxy | null; | ||
getRoot(): RecordProxy; | ||
getRootField(fieldName: string): RecordProxy | null; | ||
getPluralRootField(fieldName: string): RecordProxy[] | null; | ||
export interface Subscribable<T> { | ||
subscribe(observer: Observer<T> | Sink<T>): Subscription; | ||
} | ||
interface Sink<T> { | ||
next(value: T): void; | ||
error(error: Error, isUncaughtThrownError?: boolean): void; | ||
complete(): void; | ||
readonly closed: boolean; | ||
} | ||
type Source<T> = (sink: Sink<T>) => void | Subscription | (() => unknown); | ||
export interface Subscription { | ||
unsubscribe(): void; | ||
readonly closed: boolean; | ||
} | ||
// ./network/createRelayNetworkLogger | ||
export type GraphiQLPrinter = (request: RequestParameters, variables: Variables) => string; | ||
// ./query/RelayModernGraphQLTag | ||
export type GraphQLTaggedNode = | ||
| ReaderFragment | ||
| ConcreteRequest | ||
| (() => ReaderFragment | ConcreteRequest) | ||
| { | ||
modern: () => ReaderFragment | ConcreteRequest; | ||
}; | ||
// ./store/RelayRecordState | ||
export type RecordState = 'EXISTENT' | 'NONEXISTENT' | 'UNKNOWN'; | ||
// ./store/RelayStoreTypes | ||
interface Environment | ||
extends CEnvironment< | ||
Environment, | ||
ReaderFragment, | ||
GraphQLTaggedNode, | ||
ReaderSelectableNode, | ||
NormalizationSelectableNode, | ||
ConcreteRequest, | ||
GraphQLResponse, | ||
OwnedReaderSelector | ||
> { | ||
applyUpdate(optimisticUpdate: OptimisticUpdate): Disposable; | ||
commitUpdate(updater: StoreUpdater): void; | ||
commitPayload(operationDescriptor: OperationDescriptor, payload: PayloadData): void; | ||
getStore(): Store; | ||
lookup(selector: ReaderSelector, owner?: OperationDescriptor): CSnapshot<ReaderSelectableNode, OperationDescriptor>; | ||
executeMutation(data: { | ||
operation: OperationDescriptor; | ||
optimisticUpdater?: SelectorStoreUpdater | null; | ||
optimisticResponse?: object | null; | ||
updater?: SelectorStoreUpdater | null; | ||
uploadables?: UploadableMap | null; | ||
}): RelayObservable<GraphQLResponse>; | ||
} | ||
export { Environment as IEnvironment }; | ||
export type FragmentMap = CFragmentMap<ReaderFragment>; | ||
export type FragmentReference = never & { __tag: 'FragmentReference' }; | ||
export interface FragmentPointer { | ||
__id: DataID; | ||
__fragments: { [fragmentName: string]: Variables }; | ||
__fragmentOwner: OperationDescriptor | null; | ||
} | ||
export interface HandleFieldPayload { | ||
readonly args: Variables; | ||
readonly dataID: DataID; | ||
readonly fieldKey: string; | ||
readonly handle: string; | ||
readonly handleKey: string; | ||
} | ||
export interface MatchPointer { | ||
__id: DataID; | ||
__fragments: { [fragmentName: string]: Variables }; | ||
__fragmentPropName: string; | ||
__module: unknown; | ||
} | ||
export type MissingFieldHandler = | ||
| { | ||
kind: 'scalar'; | ||
handle: ( | ||
field: NormalizationScalarField, | ||
record: Record | null | undefined, | ||
args: Variables, | ||
store: ReadonlyRecordSourceProxy | ||
) => unknown; | ||
} | ||
| { | ||
kind: 'linked'; | ||
handle: ( | ||
field: NormalizationLinkedField, | ||
record: Record | null | undefined, | ||
args: Variables, | ||
store: ReadonlyRecordSourceProxy | ||
) => DataID | null | undefined; | ||
} | ||
| { | ||
kind: 'pluralLinked'; | ||
handle: ( | ||
field: NormalizationLinkedField, | ||
record: Record | null | undefined, | ||
args: Variables, | ||
store: ReadonlyRecordSourceProxy | ||
) => ReadonlyArray<DataID | null | undefined> | null | undefined; | ||
}; | ||
export interface OperationLoader { | ||
get(reference: unknown): NormalizationSplitOperation | null | undefined; | ||
load(reference: unknown): Promise<NormalizationSplitOperation | null | undefined>; | ||
} | ||
export type OperationDescriptor = COperationDescriptor< | ||
ReaderSelectableNode, | ||
NormalizationSelectableNode, | ||
ConcreteRequest | ||
>; | ||
export type OptimisticUpdate = | ||
| { | ||
storeUpdater: StoreUpdater; | ||
} | ||
| { | ||
selectorStoreUpdater: SelectorStoreUpdater | null | undefined; | ||
operation: OperationDescriptor; | ||
response: object | null | undefined; | ||
} | ||
| { | ||
source: RecordSource; | ||
fieldPayloads?: ReadonlyArray<HandleFieldPayload> | null; | ||
}; | ||
export interface OwnedReaderSelector { | ||
owner: OperationDescriptor | null; | ||
selector: ReaderSelector; | ||
} | ||
export interface RecordProxy { | ||
copyFieldsFrom(source: RecordProxy): void; | ||
getDataID(): DataID; | ||
getLinkedRecord(name: string, args?: Variables): RecordProxy | null; | ||
getLinkedRecords(name: string, args?: Variables): ReadonlyArray<RecordProxy | null> | null; | ||
getOrCreateLinkedRecord(name: string, typeName: string, args?: Variables): RecordProxy; | ||
getLinkedRecord(name: string, args?: Variables | null): RecordProxy | null | undefined; | ||
getLinkedRecords( | ||
name: string, | ||
args?: Variables | null | ||
): ReadonlyArray<RecordProxy | null | undefined> | null | undefined; | ||
getOrCreateLinkedRecord(name: string, typeName: string, args?: Variables | null): RecordProxy; | ||
getType(): string; | ||
getValue(name: string, args?: Variables): any; | ||
setLinkedRecord(record: RecordProxy, name: string, args?: Variables): RecordProxy; | ||
getValue(name: string, args?: Variables | null): unknown; | ||
setLinkedRecord(record: RecordProxy, name: string, args?: Variables | null): RecordProxy; | ||
setLinkedRecords( | ||
records: Array<RecordProxy | null> | undefined | null, | ||
records: Array<RecordProxy | null | undefined>, | ||
name: string, | ||
args?: Variables | ||
args?: Variables | null | ||
): RecordProxy; | ||
setValue(value: any, name: string, args?: Variables): RecordProxy; | ||
setValue(value: unknown, name: string, args?: Variables | null): RecordProxy; | ||
} | ||
@@ -214,889 +375,871 @@ | ||
delete(dataID: DataID): void; | ||
get(dataID: DataID): RecordProxy | null; | ||
get(dataID: DataID): RecordProxy | null | undefined; | ||
getRoot(): RecordProxy; | ||
} | ||
export interface HandleFieldPayload { | ||
// The arguments that were fetched. | ||
args: Variables; | ||
// The __id of the record containing the source/handle field. | ||
dataID: DataID; | ||
// The (storage) key at which the original server data was written. | ||
fieldKey: string; | ||
// The name of the handle | ||
handle: string; | ||
// The (storage) key at which the handle's data should be written by the | ||
// handler | ||
handleKey: string; | ||
export interface RecordSourceSelectorProxy { | ||
create(dataID: DataID, typeName: string): RecordProxy; | ||
delete(dataID: DataID): void; | ||
get(dataID: DataID): RecordProxy | null | undefined; | ||
getRoot(): RecordProxy; | ||
getRootField(fieldName: string): RecordProxy | null | undefined; | ||
getPluralRootField(fieldName: string): ReadonlyArray<RecordProxy | null | undefined> | null | undefined; | ||
} | ||
export interface HandlerInterface { | ||
update(store: RecordSourceProxy, fieldPayload: HandleFieldPayload): void; | ||
[functionName: string]: (...args: any[]) => any; | ||
export type RelayContext = CRelayContext<Environment>; | ||
export type ReaderSelector = CReaderSelector<ReaderSelectableNode>; | ||
export type NormalizationSelector = CNormalizationSelector<NormalizationSelectableNode>; | ||
export type SelectorStoreUpdater<TData = unknown> = (store: RecordSourceSelectorProxy, data: TData) => void; | ||
export type Snapshot = CSnapshot<ReaderSelectableNode, OperationDescriptor>; | ||
export type StoreUpdater = (store: RecordSourceProxy) => void; | ||
interface ReadonlyRecordSourceProxy { | ||
get(dataID: DataID): ReadonlyRecordProxy | null | undefined; | ||
getRoot(): ReadonlyRecordProxy; | ||
} | ||
export const ConnectionHandler: HandlerInterface; | ||
export const ViewerHandler: HandlerInterface; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayCombinedEnvironmentTypes | ||
// Version: Relay 1.3.0 | ||
// File: https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
/** | ||
* Settings for how a query response may be cached. | ||
* | ||
* - `force`: causes a query to be issued unconditionally, irrespective of the | ||
* state of any configured response cache. | ||
* - `poll`: causes a query to live update by polling at the specified interval | ||
* in milliseconds. (This value will be passed to setTimeout.) | ||
*/ | ||
export interface CacheConfig { | ||
force?: boolean; | ||
poll?: number; | ||
interface ReadonlyRecordProxy { | ||
getDataID(): DataID; | ||
getLinkedRecord(name: string, args?: Variables | null): RecordProxy | null | undefined; | ||
getLinkedRecords( | ||
name: string, | ||
args?: Variables | null | ||
): ReadonlyArray<RecordProxy | null | undefined> | null | undefined; | ||
getType(): string; | ||
getValue(name: string, args?: Variables | null): unknown; | ||
} | ||
/** | ||
* Represents any resource that must be explicitly disposed of. The most common | ||
* use-case is as a return value for subscriptions, where calling `dispose()` | ||
* would cancel the subscription. | ||
*/ | ||
export interface Disposable { | ||
dispose(): void; | ||
interface RecordSource { | ||
get(dataID: DataID): Record | null | undefined; | ||
getRecordIDs(): ReadonlyArray<DataID>; | ||
getStatus(dataID: DataID): RecordState; | ||
has(dataID: DataID): boolean; | ||
load(dataID: DataID, callback: (error: Error | null | undefined, record: Record | null | undefined) => void): void; | ||
size(): number; | ||
} | ||
export { RecordSource as IRecordSource }; | ||
/** | ||
* Arbitrary data e.g. received by a container as props. | ||
*/ | ||
export interface Props { | ||
[key: string]: any; | ||
interface Store { | ||
getSource(): RecordSource; | ||
check(selector: NormalizationSelector): boolean; | ||
lookup(selector: ReaderSelector, owner?: OperationDescriptor): Snapshot; | ||
notify(): void; | ||
publish(source: RecordSource): void; | ||
retain(selector: NormalizationSelector): Disposable; | ||
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable; | ||
holdGC(): Disposable; | ||
} | ||
/** | ||
* A selector defines the starting point for a traversal into the graph for the | ||
* purposes of targeting a subgraph. | ||
*/ | ||
export interface CSelector<TNode> { | ||
dataID: DataID; | ||
node: TNode; | ||
variables: Variables; | ||
export interface MutableRecordSource extends RecordSource { | ||
clear(): void; | ||
delete(dataID: DataID): void; | ||
remove(dataID: DataID): void; | ||
set(dataID: DataID, record: Record): void; | ||
} | ||
/** | ||
* A representation of a selector and its results at a particular point in time. | ||
*/ | ||
export type CSnapshot<TNode> = CSelector<TNode> & { | ||
data: SelectorData | null | undefined; | ||
seenRecords: RecordMap; | ||
}; | ||
type Scheduler = (callback: () => void) => void; | ||
/** | ||
* The results of a selector given a store/RecordSource. | ||
*/ | ||
export interface SelectorData { | ||
[key: string]: any; | ||
// ./subscription/requestRelaySubscription | ||
export interface GraphQLSubscriptionConfig<TSubscriptionPayload> { | ||
configs?: ReadonlyArray<DeclarativeMutationConfig>; | ||
subscription: GraphQLTaggedNode; | ||
variables: Variables; | ||
onCompleted?: () => void; | ||
onError?: (error: Error) => void; | ||
onNext?: (response: TSubscriptionPayload | null | undefined) => void; | ||
updater?: SelectorStoreUpdater; | ||
} | ||
/** | ||
* The results of reading the results of a FragmentMap given some input | ||
* `Props`. | ||
*/ | ||
export interface FragmentSpecResults { | ||
[key: string]: any; | ||
// ./util/NormalizationNode | ||
export type NormalizationArgument = NormalizationLiteral | NormalizationVariable; | ||
export type NormalizationArgumentDefinition = NormalizationLocalArgument | NormalizationRootArgument; | ||
export interface NormalizationDefer { | ||
readonly if: string | null; | ||
readonly kind: 'Defer'; | ||
readonly label: string; | ||
readonly metadata: { readonly [key: string]: unknown } | null | undefined; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
/** | ||
* A utility for resolving and subscribing to the results of a fragment spec | ||
* (key -> fragment mapping) given some "props" that determine the root ID | ||
* and variables to use when reading each fragment. When props are changed via | ||
* `setProps()`, the resolver will update its results and subscriptions | ||
* accordingly. Internally, the resolver: | ||
* - Converts the fragment map & props map into a map of `Selector`s. | ||
* - Removes any resolvers for any props that became null. | ||
* - Creates resolvers for any props that became non-null. | ||
* - Updates resolvers with the latest props. | ||
*/ | ||
export interface FragmentSpecResolver { | ||
/** | ||
* Stop watching for changes to the results of the fragments. | ||
*/ | ||
dispose(): void; | ||
export type NormalizationField = NormalizationScalarField | NormalizationLinkedField | NormalizationMatchField; | ||
/** | ||
* Get the current results. | ||
*/ | ||
resolve(): FragmentSpecResults; | ||
export interface NormalizationLinkedField { | ||
readonly kind: string; // 'LinkedField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly storageKey: string | null | undefined; | ||
readonly args: ReadonlyArray<NormalizationArgument>; | ||
readonly concreteType: string | null | undefined; | ||
readonly plural: boolean; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
/** | ||
* Update the resolver with new inputs. Call `resolve()` to get the updated | ||
* results. | ||
*/ | ||
setProps(props: Props): void; | ||
export interface NormalizationMatchField { | ||
readonly kind: string; // 'MatchField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly storageKey: string | null | undefined; | ||
readonly args: ReadonlyArray<NormalizationArgument>; | ||
readonly matchesByType: { | ||
readonly [key: string]: { | ||
readonly fragmentPropName: string; | ||
readonly fragmentName: string; | ||
}; | ||
}; | ||
} | ||
/** | ||
* Override the variables used to read the results of the fragments. Call | ||
* `resolve()` to get the updated results. | ||
*/ | ||
setVariables(variables: Variables): void; | ||
export interface NormalizationOperation { | ||
readonly kind: string; // 'Operation'; | ||
readonly name: string; | ||
readonly argumentDefinitions: ReadonlyArray<NormalizationLocalArgument>; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
export interface CFragmentMap<TFragment> { | ||
[key: string]: TFragment; | ||
export interface NormalizationScalarField { | ||
readonly kind: string; // 'ScalarField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly args: ReadonlyArray<NormalizationArgument> | null | undefined; | ||
readonly storageKey: string | null | undefined; | ||
} | ||
/** | ||
* An operation selector describes a specific instance of a GraphQL operation | ||
* with variables applied. | ||
* | ||
* - `root`: a selector intended for processing server results or retaining | ||
* response data in the store. | ||
* - `fragment`: a selector intended for use in reading or subscribing to | ||
* the results of the the operation. | ||
*/ | ||
export interface COperationSelector<TNode, TOperation> { | ||
fragment: CSelector<TNode>; | ||
node: TOperation; | ||
root: CSelector<TNode>; | ||
variables: Variables; | ||
export type NormalizationSelection = | ||
| NormalizationCondition | ||
| NormalizationField | ||
| NormalizationHandle | ||
| NormalizationInlineFragment | ||
| NormalizationMatchField; | ||
export interface NormalizationSplitOperation { | ||
readonly kind: string; // 'SplitOperation'; | ||
readonly name: string; | ||
readonly metadata: { readonly [key: string]: unknown } | null | undefined; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
/** | ||
* The public API of Relay core. Represents an encapsulated environment with its | ||
* own in-memory cache. | ||
*/ | ||
export interface CEnvironment<TEnvironment, TFragment, TGraphQLTaggedNode, TNode, TOperation, TPayload> { | ||
/** | ||
* Read the results of a selector from in-memory records in the store. | ||
*/ | ||
lookup(selector: CSelector<TNode>): CSnapshot<TNode>; | ||
export interface NormalizationStream { | ||
readonly if: string | null; | ||
readonly kind: string; // 'Stream'; | ||
readonly label: string; | ||
readonly metadata: { readonly [key: string]: unknown } | null | undefined; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
/** | ||
* Subscribe to changes to the results of a selector. The callback is called | ||
* when data has been committed to the store that would cause the results of | ||
* the snapshot's selector to change. | ||
*/ | ||
subscribe(snapshot: CSnapshot<TNode>, callback: (snapshot: CSnapshot<TNode>) => void): Disposable; | ||
interface NormalizationLiteral { | ||
readonly kind: string; // 'Literal'; | ||
readonly name: string; | ||
readonly value: unknown; | ||
} | ||
/** | ||
* Ensure that all the records necessary to fulfill the given selector are | ||
* retained in-memory. The records will not be eligible for garbage collection | ||
* until the returned reference is disposed. | ||
* | ||
* Note: This is a no-op in the classic core. | ||
*/ | ||
retain(selector: CSelector<TNode>): Disposable; | ||
interface NormalizationVariable { | ||
readonly kind: string; // 'Variable'; | ||
readonly name: string; | ||
readonly variableName: string; | ||
} | ||
/** | ||
* Send a query to the server with request/response semantics: the query will | ||
* either complete successfully (calling `onNext` and `onCompleted`) or fail | ||
* (calling `onError`). | ||
* | ||
* Note: Most applications should use `streamQuery` in order to | ||
* optionally receive updated information over time, should that feature be | ||
* supported by the network/server. A good rule of thumb is to use this method | ||
* if you would otherwise immediately dispose the `streamQuery()` | ||
* after receving the first `onNext` result. | ||
*/ | ||
sendQuery(config: { | ||
cacheConfig?: CacheConfig; | ||
onCompleted?(): void; | ||
onError?(error: Error): void; | ||
onNext?(payload: TPayload): void; | ||
operation: COperationSelector<TNode, TOperation>; | ||
}): Disposable; | ||
interface NormalizationLocalArgument { | ||
readonly kind: string; // 'LocalArgument'; | ||
readonly name: string; | ||
readonly type: string; | ||
readonly defaultValue: unknown; | ||
} | ||
/** | ||
* Send a query to the server with request/subscription semantics: one or more | ||
* responses may be returned (via `onNext`) over time followed by either | ||
* the request completing (`onCompleted`) or an error (`onError`). | ||
* | ||
* Networks/servers that support subscriptions may choose to hold the | ||
* subscription open indefinitely such that `onCompleted` is not called. | ||
*/ | ||
streamQuery(config: { | ||
cacheConfig?: CacheConfig; | ||
onCompleted?(): void; | ||
onError?(error: Error): void; | ||
onNext?(payload: TPayload): void; | ||
operation: COperationSelector<TNode, TOperation>; | ||
}): Disposable; | ||
interface NormalizationRootArgument { | ||
readonly kind: string; // 'RootArgument'; | ||
readonly name: string; | ||
readonly type: string | null | undefined; | ||
} | ||
unstable_internal: CUnstableEnvironmentCore<TEnvironment, TFragment, TGraphQLTaggedNode, TNode, TOperation>; | ||
interface NormalizationCondition { | ||
readonly kind: string; // 'Condition'; | ||
readonly passingValue: boolean; | ||
readonly condition: string; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
} | ||
export interface CUnstableEnvironmentCore<TEnvironment, TFragment, TGraphQLTaggedNode, TNode, TOperation> { | ||
/** | ||
* Create an instance of a FragmentSpecResolver. | ||
* | ||
* TODO: The FragmentSpecResolver *can* be implemented via the other methods | ||
* defined here, so this could be moved out of core. It's convenient to have | ||
* separate implementations until the experimental core is in OSS. | ||
*/ | ||
createFragmentSpecResolver( | ||
context: CRelayContext<TEnvironment>, | ||
containerName: string, | ||
fragments: CFragmentMap<TFragment>, | ||
props: Props, | ||
callback: () => void | ||
): FragmentSpecResolver; | ||
type NormalizationHandle = NormalizationScalarHandle | NormalizationLinkedHandle; | ||
/** | ||
* Creates an instance of an OperationSelector given an operation definition | ||
* (see `getOperation`) and the variables to apply. The input variables are | ||
* filtered to exclude variables that do not matche defined arguments on the | ||
* operation, and default values are populated for null values. | ||
*/ | ||
createOperationSelector(operation: TOperation, variables: Variables): COperationSelector<TNode, TOperation>; | ||
interface NormalizationLinkedHandle { | ||
readonly kind: string; // 'LinkedHandle'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly args: ReadonlyArray<NormalizationArgument> | null | undefined; | ||
readonly handle: string; | ||
readonly key: string; | ||
readonly filters: ReadonlyArray<string> | null | undefined; | ||
} | ||
/** | ||
* Given a graphql`...` tagged template, extract a fragment definition usable | ||
* by this version of Relay core. Throws if the value is not a fragment. | ||
*/ | ||
getFragment(node: TGraphQLTaggedNode): TFragment; | ||
interface NormalizationScalarHandle { | ||
readonly kind: string; // 'ScalarHandle'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly args: ReadonlyArray<NormalizationArgument> | null | undefined; | ||
readonly handle: string; | ||
readonly key: string; | ||
readonly filters: ReadonlyArray<string> | null | undefined; | ||
} | ||
/** | ||
* Given a graphql`...` tagged template, extract an operation definition | ||
* usable by this version of Relay core. Throws if the value is not an | ||
* operation. | ||
*/ | ||
getOperation(node: TGraphQLTaggedNode): TOperation; | ||
interface NormalizationInlineFragment { | ||
readonly kind: string; // 'InlineFragment'; | ||
readonly selections: ReadonlyArray<NormalizationSelection>; | ||
readonly type: string; | ||
} | ||
/** | ||
* Determine if two selectors are equal (represent the same selection). Note | ||
* that this function returns `false` when the two queries/fragments are | ||
* different objects, even if they select the same fields. | ||
*/ | ||
areEqualSelectors(a: CSelector<TNode>, b: CSelector<TNode>): boolean; | ||
type NormalizationSelectableNode = | ||
| NormalizationDefer | ||
| NormalizationOperation | ||
| NormalizationSplitOperation | ||
| NormalizationStream; | ||
/** | ||
* Given the result `item` from a parent that fetched `fragment`, creates a | ||
* selector that can be used to read the results of that fragment for that item. | ||
* | ||
* Example: | ||
* | ||
* Given two fragments as follows: | ||
* | ||
* ``` | ||
* fragment Parent on User { | ||
* id | ||
* ...Child | ||
* } | ||
* fragment Child on User { | ||
* name | ||
* } | ||
* ``` | ||
* | ||
* And given some object `parent` that is the results of `Parent` for id "4", | ||
* the results of `Child` can be accessed by first getting a selector and then | ||
* using that selector to `lookup()` the results against the environment: | ||
* | ||
* ``` | ||
* const childSelector = getSelector(queryVariables, Child, parent); | ||
* const childData = environment.lookup(childSelector).data; | ||
* ``` | ||
*/ | ||
getSelector(operationVariables: Variables, fragment: TFragment, prop: any): CSelector<TNode> | null; | ||
// ./util/ReaderNode | ||
export type ReaderArgument = ReaderLiteral | ReaderVariable; | ||
/** | ||
* Given the result `items` from a parent that fetched `fragment`, creates a | ||
* selector that can be used to read the results of that fragment on those | ||
* items. This is similar to `getSelector` but for "plural" fragments that | ||
* expect an array of results and therefore return an array of selectors. | ||
*/ | ||
getSelectorList(operationVariables: Variables, fragment: TFragment, props: any[]): Array<CSelector<TNode>> | null; | ||
export type ReaderArgumentDefinition = ReaderLocalArgument | ReaderRootArgument; | ||
/** | ||
* Given a mapping of keys -> results and a mapping of keys -> fragments, | ||
* extracts the selectors for those fragments from the results. | ||
* | ||
* The canonical use-case for this function are Relay Containers, which | ||
* use this function to convert (props, fragments) into selectors so that they | ||
* can read the results to pass to the inner component. | ||
*/ | ||
getSelectorsFromObject( | ||
operationVariables: Variables, | ||
fragments: CFragmentMap<TFragment>, | ||
props: Props | ||
): { | ||
[key: string]: CSelector<TNode> | Array<CSelector<TNode>> | null | undefined; | ||
}; | ||
export type ReaderField = ReaderScalarField | ReaderLinkedField | ReaderMatchField; | ||
/** | ||
* Given a mapping of keys -> results and a mapping of keys -> fragments, | ||
* extracts a mapping of keys -> id(s) of the results. | ||
* | ||
* Similar to `getSelectorsFromObject()`, this function can be useful in | ||
* determining the "identity" of the props passed to a component. | ||
*/ | ||
getDataIDsFromObject( | ||
fragments: CFragmentMap<TFragment>, | ||
props: Props | ||
): { [key: string]: DataID | DataID[] | null | undefined }; | ||
export interface ReaderFragment { | ||
readonly kind: string; // 'Fragment'; | ||
readonly name: string; | ||
readonly type: string; | ||
readonly metadata: | ||
| { | ||
readonly connection?: ReadonlyArray<ConnectionMetadata>; | ||
readonly mask?: boolean; | ||
readonly plural?: boolean; | ||
readonly refetch?: ReaderRefetchMetadata; | ||
} | ||
| null | ||
| undefined; | ||
readonly argumentDefinitions: ReadonlyArray<ReaderArgumentDefinition>; | ||
readonly selections: ReadonlyArray<ReaderSelection>; | ||
} | ||
/** | ||
* Given a mapping of keys -> results and a mapping of keys -> fragments, | ||
* extracts the merged variables that would be in scope for those | ||
* fragments/results. | ||
* | ||
* This can be useful in determing what varaibles were used to fetch the data | ||
* for a Relay container, for example. | ||
*/ | ||
getVariablesFromObject(operationVariables: Variables, fragments: CFragmentMap<TFragment>, props: Props): Variables; | ||
export interface ReaderLinkedField { | ||
readonly kind: string; // 'LinkedField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly storageKey: string | null | undefined; | ||
readonly args: ReadonlyArray<ReaderArgument>; | ||
readonly concreteType: string | null | undefined; | ||
readonly plural: boolean; | ||
readonly selections: ReadonlyArray<ReaderSelection>; | ||
} | ||
/** | ||
* The type of the `relay` property set on React context by the React/Relay | ||
* integration layer (e.g. QueryRenderer, FragmentContainer, etc). | ||
*/ | ||
export interface CRelayContext<TEnvironment> { | ||
environment: TEnvironment; | ||
variables: Variables; | ||
export interface ReaderMatchField { | ||
readonly kind: string; // 'MatchField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly storageKey: string | null | undefined; | ||
readonly args: ReadonlyArray<ReaderArgument> | null | undefined; | ||
readonly matchesByType: { | ||
readonly [key: string]: { | ||
readonly fragmentPropName: string; | ||
readonly fragmentName: string; | ||
}; | ||
}; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayTypes | ||
/** | ||
* Version: Relay 1.3.0 | ||
* File: | ||
* https://github.com/facebook/relay/blob/fa9f48ea209ee2402d433b59a84d1cbc046574e2/packages/react-relay/classic/tools/RelayTypes.js | ||
*/ | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface RerunParam { | ||
param: string; | ||
import: string; | ||
max_runs: number; | ||
export interface ReaderPaginationMetadata { | ||
readonly backward: { | ||
readonly count: string; | ||
readonly cursor: string; | ||
} | null; | ||
readonly forward: { | ||
readonly count: string; | ||
readonly cursor: string; | ||
} | null; | ||
readonly path: ReadonlyArray<string>; | ||
} | ||
export interface FIELDS_CHANGE { | ||
type: 'FIELDS_CHANGE'; | ||
fieldIDs: { [fieldName: string]: DataID | DataID[] }; | ||
export interface ReaderRefetchableFragment extends ReaderFragment { | ||
readonly metadata: { | ||
readonly connection?: [ConnectionMetadata]; | ||
readonly refetch: ReaderRefetchMetadata; | ||
}; | ||
} | ||
export interface RANGE_ADD { | ||
type: 'RANGE_ADD'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionInfo?: Array<{ | ||
key: string; | ||
filters?: Variables; | ||
rangeBehavior: string; | ||
}>; | ||
connectionName?: string; | ||
edgeName: string; | ||
rangeBehaviors?: RangeBehaviors; | ||
export interface ReaderScalarField { | ||
readonly kind: string; // 'ScalarField'; | ||
readonly alias: string | null | undefined; | ||
readonly name: string; | ||
readonly args: ReadonlyArray<ReaderArgument> | null | undefined; | ||
readonly storageKey: string | null | undefined; | ||
} | ||
export interface NODE_DELETE { | ||
type: 'NODE_DELETE'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionName?: string; | ||
deletedIDFieldName: string; | ||
export type ReaderSelection = | ||
| ReaderCondition | ||
| ReaderField | ||
| ReaderFragmentSpread | ||
| ReaderInlineFragment | ||
| ReaderMatchField; | ||
export interface ReaderSplitOperation { | ||
readonly kind: string; // 'SplitOperation'; | ||
readonly name: string; | ||
readonly metadata: { readonly [key: string]: unknown } | null | undefined; | ||
readonly selections: ReadonlyArray<ReaderSelection>; | ||
} | ||
export interface RANGE_DELETE { | ||
type: 'RANGE_DELETE'; | ||
parentName?: string; | ||
parentID?: string; | ||
connectionKeys?: Array<{ | ||
key: string; | ||
filters?: Variables; | ||
}>; | ||
connectionName?: string; | ||
deletedIDFieldName: string | string[]; | ||
pathToConnection: string[]; | ||
interface ReaderLiteral { | ||
readonly kind: string; // 'Literal'; | ||
readonly name: string; | ||
readonly value: unknown; | ||
} | ||
export interface REQUIRED_CHILDREN { | ||
type: 'REQUIRED_CHILDREN'; | ||
children: RelayConcreteNode[]; | ||
interface ReaderVariable { | ||
readonly kind: string; // 'Variable'; | ||
readonly name: string; | ||
readonly variableName: string; | ||
} | ||
export type RelayMutationConfig = FIELDS_CHANGE | RANGE_ADD | NODE_DELETE | RANGE_DELETE | REQUIRED_CHILDREN; | ||
export interface RelayMutationTransactionCommitCallbacks { | ||
onFailure?: RelayMutationTransactionCommitFailureCallback; | ||
onSuccess?: RelayMutationTransactionCommitSuccessCallback; | ||
interface ReaderLocalArgument { | ||
readonly kind: string; // 'LocalArgument'; | ||
readonly name: string; | ||
readonly type: string; | ||
readonly defaultValue: unknown; | ||
} | ||
export type RelayMutationTransactionCommitFailureCallback = ( | ||
transaction: RelayMutationTransaction, | ||
preventAutoRollback: () => void | ||
) => void; | ||
export type RelayMutationTransactionCommitSuccessCallback = (response: { [key: string]: any }) => void; | ||
export interface NetworkLayer { | ||
sendMutation(request: RelayMutationRequest): Promise<any> | null; | ||
sendQueries(requests: RelayQueryRequest[]): Promise<any> | null; | ||
supports(...options: string[]): boolean; | ||
interface ReaderRootArgument { | ||
readonly kind: string; // 'RootArgument'; | ||
readonly name: string; | ||
readonly type: string | null | undefined; | ||
} | ||
export interface QueryResult { | ||
error?: Error; | ||
ref_params?: { [name: string]: any }; | ||
response: QueryPayload; | ||
interface ReaderRefetchMetadata { | ||
readonly connection: ReaderPaginationMetadata | null | undefined; | ||
readonly operation: string | ConcreteRequest; | ||
readonly fragmentPathInResult: ReadonlyArray<string>; | ||
} | ||
export interface ReadyState { | ||
aborted: boolean; | ||
done: boolean; | ||
error: Error | null; | ||
events: ReadyStateEvent[]; | ||
ready: boolean; | ||
stale: boolean; | ||
interface ReaderCondition { | ||
readonly kind: string; // 'Condition'; | ||
readonly passingValue: boolean; | ||
readonly condition: string; | ||
readonly selections: ReadonlyArray<ReaderSelection>; | ||
} | ||
export type RelayContainerErrorEventType = 'CACHE_RESTORE_FAILED' | 'NETWORK_QUERY_ERROR'; | ||
export type RelayContainerLoadingEventType = | ||
| 'ABORT' | ||
| 'CACHE_RESTORED_REQUIRED' | ||
| 'CACHE_RESTORE_START' | ||
| 'NETWORK_QUERY_RECEIVED_ALL' | ||
| 'NETWORK_QUERY_RECEIVED_REQUIRED' | ||
| 'NETWORK_QUERY_START' | ||
| 'STORE_FOUND_ALL' | ||
| 'STORE_FOUND_REQUIRED'; | ||
export type ReadyStateChangeCallback = (readyState: ReadyState) => void; | ||
export interface ReadyStateEvent { | ||
type: RelayContainerLoadingEventType | RelayContainerErrorEventType; | ||
error?: Error; | ||
interface ReaderFragmentSpread { | ||
readonly kind: string; // 'FragmentSpread'; | ||
readonly name: string; | ||
readonly args: ReadonlyArray<ReaderArgument> | null | undefined; | ||
} | ||
export interface Abortable { | ||
abort(): void; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayInternalTypes | ||
/** | ||
* Version: Relay 1.3.0 | ||
* File: | ||
* https://github.com/facebook/relay/blob/master/packages/react-relay/classic/tools/RelayInternalTypes.js | ||
*/ | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface QueryPayload { | ||
[key: string]: any; | ||
interface ReaderInlineFragment { | ||
readonly kind: string; // 'InlineFragment'; | ||
readonly selections: ReadonlyArray<ReaderSelection>; | ||
readonly type: string; | ||
} | ||
export interface RelayQuerySet { | ||
[queryName: string]: any; | ||
} | ||
export type RangeBehaviorsFunction = (connectionArgs: { | ||
[argName: string]: any; | ||
}) => 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; | ||
export interface RangeBehaviorsObject { | ||
[key: string]: 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; | ||
} | ||
export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Maybe Fix | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type RelayDebugger = any; | ||
export type OptimisticUpdate = any; | ||
export type OperationSelector = COperationSelector<any, any>; | ||
export type Selector = CSelector<any>; | ||
export type PayloadData = any; | ||
export type Snapshot = CSnapshot<any>; | ||
export type RelayResponsePayload = any; | ||
export type MutableRecordSource = RecordSource; | ||
type ReaderSelectableNode = ReaderFragment | ReaderSplitOperation; | ||
/** | ||
* A function that returns an Observable representing the response of executing | ||
* a GraphQL operation. | ||
*/ | ||
export type ExecuteFunction = ( | ||
operation: object, | ||
variables: Variables, | ||
cacheConfig: CacheConfig, | ||
uploadables?: UploadableMap | ||
) => Promise<any>; | ||
export interface RelayNetwork { | ||
execute: ExecuteFunction; | ||
interface ReaderPaginationFragment extends ReaderFragment { | ||
readonly metadata: { | ||
readonly connection: [ConnectionMetadata]; | ||
readonly refetch: ReaderRefetchMetadata & { | ||
connection: ReaderPaginationMetadata; | ||
}; | ||
}; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayDefaultHandlerProvider | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export type HandlerProvider = (name: string) => HandlerInterface | null; | ||
// ./util/RelayCombinedEnvironmentTypes | ||
export interface CEnvironment< | ||
TEnvironment, | ||
TFragment, | ||
TGraphQLTaggedNode, | ||
TReaderNode, | ||
TNormalizationNode, | ||
TRequest, | ||
TPayload, | ||
TReaderSelector | ||
> { | ||
check(selector: CNormalizationSelector<TNormalizationNode>): boolean; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayModernEnvironment | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface EnvironmentConfig { | ||
configName?: string; | ||
handlerProvider?: HandlerProvider; | ||
network: Network; | ||
store: Store; | ||
} | ||
export class Environment { | ||
constructor(config: EnvironmentConfig); | ||
getStore(): Store; | ||
getDebugger(): RelayDebugger; | ||
applyUpdate(optimisticUpdate: OptimisticUpdate): Disposable; | ||
revertUpdate(update: OptimisticUpdate): void; | ||
replaceUpdate(update: OptimisticUpdate, newUpdate: OptimisticUpdate): void; | ||
applyMutation(config: { | ||
operation: OperationSelector; | ||
optimisticUpdater?: SelectorStoreUpdater; | ||
optimisticResponse?: object; | ||
}): Disposable; | ||
check(readSelector: Selector): boolean; | ||
commitPayload(operationSelector: OperationSelector, payload: PayloadData): void; | ||
commitUpdate(updater: StoreUpdater): void; | ||
lookup(readSelector: Selector): Snapshot; | ||
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable; | ||
retain(selector: Selector): Disposable; | ||
lookup( | ||
selector: CReaderSelector<TReaderNode> | ||
): CSnapshot<TReaderNode, COperationDescriptor<TReaderNode, TNormalizationNode, TRequest>>; | ||
subscribe( | ||
snapshot: CSnapshot<TReaderNode, COperationDescriptor<TReaderNode, TNormalizationNode, TRequest>>, | ||
callback: ( | ||
snapshot: CSnapshot<TReaderNode, COperationDescriptor<TReaderNode, TNormalizationNode, TRequest>> | ||
) => void | ||
): Disposable; | ||
retain(selector: CNormalizationSelector<TNormalizationNode>): Disposable; | ||
execute(config: { | ||
operation: OperationSelector; | ||
cacheConfig?: CacheConfig; | ||
updater?: SelectorStoreUpdater; | ||
}): RelayObservable<RelayResponsePayload>; | ||
executeMutation(config: { | ||
operation: OperationSelector; | ||
optimisticUpdater?: SelectorStoreUpdater; | ||
optimisticResponse?: object; | ||
updater?: SelectorStoreUpdater; | ||
uploadables?: UploadableMap; | ||
}): RelayObservable<RelayResponsePayload>; | ||
operation: COperationDescriptor<TReaderNode, TNormalizationNode, TRequest>; | ||
cacheConfig?: CacheConfig | null; | ||
updater?: SelectorStoreUpdater | null; | ||
}): RelayObservable<TPayload>; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayInMemoryRecordSource | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface RelayInMemoryRecordSource { | ||
[key: string]: any; | ||
export interface CFragmentMap<TFragment> { | ||
[key: string]: TFragment; | ||
} | ||
export interface RecordMap { | ||
[dataID: string]: RelayInMemoryRecordSource | null | undefined; | ||
export interface CNormalizationSelector<TNormalizationNode> { | ||
dataID: DataID; | ||
node: TNormalizationNode; | ||
variables: Variables; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Network | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export class Network { | ||
/** | ||
* Creates an implementation of the `Network` interface defined in | ||
* `RelayNetworkTypes` given `fetch` and `subscribe` functions. | ||
*/ | ||
static create(fetchFn: FetchFunction, subscribeFn?: SubscribeFunction): RelayNetwork; | ||
export interface COperationDescriptor<TReaderNode, TNormalizationNode, TRequest> { | ||
fragment: CReaderSelector<TReaderNode>; | ||
node: TRequest; | ||
root: CNormalizationSelector<TNormalizationNode>; | ||
variables: Variables; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// Network | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export class RecordSource { | ||
constructor(records?: RecordMap); | ||
clear(): void; | ||
delete(dataID: DataID): void; | ||
get(dataID: DataID): RelayInMemoryRecordSource | null; | ||
getRecordIDs(): DataID[]; | ||
getStatus(dataID: DataID): 'EXISTENT' | 'NONEXISTENT' | 'UNKNOWN'; | ||
has(dataID: DataID): boolean; | ||
load(dataID: DataID, callback: (error: Error | null, record: RelayInMemoryRecordSource | null) => void): void; | ||
remove(dataID: DataID): void; | ||
set(dataID: DataID, record: RelayInMemoryRecordSource): void; | ||
size(): number; | ||
toJSON(): RecordMap; | ||
export interface CReaderSelector<TReaderNode> { | ||
dataID: DataID; | ||
node: TReaderNode; | ||
variables: Variables; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// ModernStore | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export class Store { | ||
constructor(source: RecordSource); | ||
getSource(): MutableRecordSource; | ||
check(selector: Selector): boolean; | ||
retain(selector: Selector): Disposable; | ||
lookup(selector: Selector): Snapshot; | ||
notify(): void; | ||
publish(source: RecordSource): void; | ||
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable; | ||
export interface CRelayContext<TEnvironment> { | ||
environment: TEnvironment; | ||
variables: Variables; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayRecordSourceInspector | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
/** | ||
* An internal class to provide a console-friendly string representation of a | ||
* RelayInMemoryRecordSource. | ||
*/ | ||
export class RecordSummary { | ||
id: DataID; | ||
type: string | null | undefined; | ||
static createFromRecord(id: DataID, record: any): RecordSummary; | ||
constructor(id: DataID, type: string | null | undefined); | ||
toString(): string; | ||
export interface CSnapshot<TReaderNode, TOwner> extends CReaderSelector<TReaderNode> { | ||
data: SelectorData | null | undefined; | ||
seenRecords: RecordMap; | ||
isMissingData: boolean; | ||
owner: TOwner | null; | ||
} | ||
/** | ||
* Internal class for inspecting a single RelayInMemoryRecordSource. | ||
*/ | ||
export class RecordInspector { | ||
constructor(sourceInspector: RelayRecordSourceInspector, record: RelayInMemoryRecordSource); | ||
/** | ||
* Get the cache id of the given record. For types that implement the `Node` | ||
* interface (or that have an `id`) this will be `id`, for other types it will be | ||
* a synthesized identifier based on the field path from the nearest ancestor | ||
* record that does have an `id`. | ||
*/ | ||
getDataID(): DataID; | ||
export interface FragmentSpecResolver { | ||
/** | ||
* Returns a list of the fields that have been fetched on the current record. | ||
* Stop watching for changes to the results of the fragments. | ||
*/ | ||
getFields(): string[]; | ||
dispose(): void; | ||
/** | ||
* Returns the type of the record. | ||
* Get the current results. | ||
*/ | ||
getType(): string; | ||
resolve(): FragmentSpecResults; | ||
/** | ||
* Returns a copy of the internal representation of the record. | ||
* Update the resolver with new inputs. Call `resolve()` to get the updated | ||
* results. | ||
*/ | ||
inspect(): any; | ||
setProps(props: Props): void; | ||
/** | ||
* Returns the value of a scalar field. May throw if the given field is | ||
* present but not actually scalar. | ||
* Override the variables used to read the results of the fragments. Call | ||
* `resolve()` to get the updated results. | ||
*/ | ||
getValue(name: string, args?: Variables): any; | ||
setVariables(variables: Variables, request?: ConcreteRequest): void; | ||
/** | ||
* Returns an inspector for the given scalar "linked" field (a field whose | ||
* value is another RelayInMemoryRecordSource instead of a scalar). May throw if the field is | ||
* present but not a scalar linked record. | ||
* Subscribe to resolver updates. | ||
* Overrides existing callback (if one has been specified). | ||
*/ | ||
getLinkedRecord(name: string, args?: Variables): RecordInspector | null; | ||
setCallback(callback: () => void): void; | ||
} | ||
/** | ||
* Returns an array of inspectors for the given plural "linked" field (a field | ||
* whose value is an array of Records instead of a scalar). May throw if the | ||
* field is present but not a plural linked record. | ||
*/ | ||
getLinkedRecords(name: string, args?: Variables): RecordInspector[] | null; | ||
export interface FragmentSpecResults { | ||
[key: string]: unknown; | ||
} | ||
export class RelayRecordSourceInspector { | ||
constructor(source: RecordSource); | ||
static getForEnvironment(environment: Environment): RelayRecordSourceInspector; | ||
/** | ||
* Returns an inspector for the record with the given id, or null/undefined if | ||
* that record is deleted/unfetched. | ||
*/ | ||
get(dataID: DataID): RecordInspector | null; | ||
/** | ||
* Returns a list of "<id>: <type>" for each record in the store that has an | ||
* `id`. | ||
*/ | ||
getNodes(): RecordSummary[]; | ||
/** | ||
* Returns a list of "<id>: <type>" for all records in the store including | ||
* those that do not have an `id`. | ||
*/ | ||
getRecords(): RecordSummary[]; | ||
export interface Props { | ||
[key: string]: unknown; | ||
} | ||
/** | ||
* Returns an inspector for the synthesized "root" object, allowing access to | ||
* e.g. the `viewer` object or the results of other fields on the "Query" | ||
* type. | ||
*/ | ||
getRoot(): RecordInspector; | ||
interface RecordMap { | ||
// theoretically, this should be `[dataID: DataID]`, but `DataID` is a string. | ||
[dataID: string]: Record | undefined; | ||
} | ||
export interface SelectorData { | ||
[key: string]: unknown; | ||
} | ||
// note RecordSourceInspector is only available in dev environment | ||
export class RecordSourceInspector extends RelayRecordSourceInspector {} | ||
// ./util/RelayConcreteNode | ||
export interface ConcreteRequest { | ||
readonly kind: string; // 'Request'; | ||
readonly fragment: ReaderFragment; | ||
readonly operation: NormalizationOperation; | ||
readonly params: RequestParameters; | ||
} | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// RelayObservable | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
export interface Subscription { | ||
unsubscribe(): void; | ||
readonly closed: boolean; | ||
export type GeneratedNode = ConcreteRequest | ReaderFragment | NormalizationSplitOperation; | ||
export interface RequestParameters { | ||
readonly name: string; | ||
readonly operationKind: string; // 'mutation' | 'query' | 'subscription'; | ||
readonly id: string | null | undefined; | ||
readonly text: string | null | undefined; | ||
readonly metadata: { [key: string]: unknown }; | ||
} | ||
export interface Observer<T> { | ||
start?(subscription: Subscription): any; | ||
next?(nextThing: T): any; | ||
error?(error: Error): any; | ||
complete?(): any; | ||
unsubscribe?(subscription: Subscription): any; | ||
// ./util/RelayRuntimeTypes | ||
export interface CacheConfig { | ||
force?: boolean | null; | ||
poll?: number | null; | ||
liveConfigId?: string | null; | ||
metadata?: { [key: string]: unknown }; | ||
transactionId?: string | null; | ||
} | ||
export type Source<T> = <T>() => any; // tslint:disable-line:no-unnecessary-generics | ||
export interface Subscribable<T> { | ||
subscribe(observer: Observer<T>): Subscription; | ||
export type DataID = string; | ||
export interface Disposable { | ||
dispose(): void; | ||
} | ||
export type ObservableFromValue<T> = RelayObservable<T> | Promise<T> | T; | ||
export class RelayObservable<T> implements Subscribable<T> { | ||
_source: Source<T>; | ||
constructor(source: Source<T>); | ||
export interface OperationType { | ||
readonly variables: Variables; | ||
readonly response: unknown; | ||
} | ||
/** | ||
* When an unhandled error is detected, it is reported to the host environment | ||
* (the ESObservable spec refers to this method as "HostReportErrors()"). | ||
* | ||
* The default implementation in development builds re-throws errors in a | ||
* separate frame, and from production builds does nothing (swallowing | ||
* uncaught errors). | ||
* | ||
* Called during application initialization, this method allows | ||
* application-specific handling of uncaught errors. Allowing, for example, | ||
* integration with error logging or developer tools. | ||
*/ | ||
static onUnhandledError(callback: (error: Error) => any): void; | ||
export interface Variables { | ||
[name: string]: any; | ||
} | ||
/** | ||
* Accepts various kinds of data sources, and always returns a RelayObservable | ||
* useful for accepting the result of a user-provided FetchFunction. | ||
*/ | ||
// Core API | ||
// ./RelayModernEnvironment | ||
interface EnvironmentConfig { | ||
readonly configName?: string; | ||
readonly handlerProvider?: HandlerProvider; | ||
readonly operationLoader?: OperationLoader; | ||
readonly network: Network; | ||
readonly store: Store; | ||
readonly missingFieldHandlers?: ReadonlyArray<MissingFieldHandler>; | ||
} | ||
declare class RelayModernEnvironment implements Environment { | ||
readonly configName: string | null | undefined; | ||
constructor(config: EnvironmentConfig); | ||
getStore(): Store; | ||
getNetwork(): Network; | ||
applyUpdate(optimisticUpdate: OptimisticUpdate): Disposable; | ||
revertUpdate(update: OptimisticUpdate): void; | ||
replaceUpdate(update: OptimisticUpdate, newUpdate: OptimisticUpdate): void; | ||
applyMutation(data: { | ||
operation: OperationDescriptor; | ||
optimisticUpdater?: SelectorStoreUpdater | null; | ||
optimisticResponse?: object; | ||
}): Disposable; | ||
check(readSelector: NormalizationSelector): boolean; | ||
commitPayload(operationDescriptor: OperationDescriptor, payload: PayloadData): void; | ||
commitUpdate(updater: StoreUpdater): void; | ||
lookup(readSelector: ReaderSelector, owner?: OperationDescriptor): Snapshot; | ||
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable; | ||
retain(selector: NormalizationSelector): Disposable; | ||
execute(data: { | ||
operation: OperationDescriptor; | ||
cacheConfig?: CacheConfig | null; | ||
updater?: SelectorStoreUpdater | null; | ||
}): RelayObservable<GraphQLResponse>; | ||
executeMutation({ | ||
operation, | ||
optimisticResponse, | ||
optimisticUpdater, | ||
updater, | ||
uploadables, | ||
}: { | ||
operation: OperationDescriptor; | ||
optimisticUpdater?: SelectorStoreUpdater | null; | ||
optimisticResponse?: object | null; | ||
updater?: SelectorStoreUpdater | null; | ||
uploadables?: UploadableMap | null; | ||
}): RelayObservable<GraphQLResponse>; | ||
} | ||
export { RelayModernEnvironment as Environment }; | ||
type HandlerProvider = (name: string) => Handler | null | undefined; | ||
// ./network/RelayNetwork | ||
declare const RelayNetwork: { | ||
create(fetchFn: FetchFunction, subscribeFn?: SubscribeFunction): Network; | ||
}; | ||
export { RelayNetwork as Network }; | ||
// ./network/RelayObservable | ||
declare class RelayObservable<T> implements Subscribable<T> { | ||
// Use RelayObservable.create(source); | ||
private constructor(source: never); | ||
static create<V>(source: Source<V>): RelayObservable<V>; | ||
static onUnhandledError(callback: (error: Error, isUncaughtThrownError: boolean) => void): void; | ||
static from<V>(obj: ObservableFromValue<V>): RelayObservable<V>; | ||
/** | ||
* Creates a RelayObservable, given a function which expects a legacy | ||
* Relay Observer as the last argument and which returns a Disposable. | ||
* | ||
* To support migration to Observable, the function may ignore the | ||
* legacy Relay observer and directly return an Observable instead. | ||
*/ | ||
static fromLegacy<V>( | ||
callback: (legacyObserver: LegacyObserver<V>) => Disposable | RelayObservable<V> | ||
callback: (observer: LegacyObserver<V>) => Disposable | RelayObservable<V> | ||
): RelayObservable<V>; | ||
/** | ||
* Returns a new Observable which returns the same values as this one, but | ||
* modified so that the provided Observer is called to perform a side-effects | ||
* for all events emitted by the source. | ||
* | ||
* Any errors that are thrown in the side-effect Observer are unhandled, and | ||
* do not affect the source Observable or its Observer. | ||
* | ||
* This is useful for when debugging your Observables or performing other | ||
* side-effects such as logging or performance monitoring. | ||
*/ | ||
catch<U>(fn: (error: Error) => RelayObservable<U>): RelayObservable<T | U>; | ||
do(observer: Observer<T>): RelayObservable<T>; | ||
/** | ||
* Returns a new Observable which returns the same values as this one, but | ||
* modified so that the finally callback is performed after completion, | ||
* whether normal or due to error or unsubscription. | ||
* | ||
* This is useful for cleanup such as resource finalization. | ||
*/ | ||
finally(fn: () => any): RelayObservable<T>; | ||
finally(fn: () => unknown): RelayObservable<T>; | ||
/** | ||
* Returns a new Observable which is identical to this one, unless this | ||
* Observable completes before yielding any values, in which case the new | ||
* Observable will yield the values from the alternate Observable. | ||
* | ||
* If this Observable does yield values, the alternate is never subscribed to. | ||
* | ||
* This is useful for scenarios where values may come from multiple sources | ||
* which should be tried in order, i.e. from a cache before a network. | ||
*/ | ||
ifEmpty<U>(alternate: RelayObservable<U>): RelayObservable<T | U>; | ||
/** | ||
* Observable's primary API: returns an unsubscribable Subscription to the | ||
* source of this Observable. | ||
*/ | ||
subscribe(observer: Observer<T>): Subscription; | ||
subscribe(observer: Observer<T> | Sink<T>): Subscription; | ||
/** | ||
* Supports subscription of a legacy Relay Observer, returning a Disposable. | ||
*/ | ||
subscribeLegacy(legacyObserver: LegacyObserver<T>): Disposable; | ||
/** | ||
* Returns a new Observerable where each value has been transformed by | ||
* the mapping function. | ||
*/ | ||
map<U>(fn: (thing: T) => U): RelayObservable<U>; | ||
map<U>(fn: (value: T) => U): RelayObservable<U>; | ||
/** | ||
* Returns a new Observable where each value is replaced with a new Observable | ||
* by the mapping function, the results of which returned as a single | ||
* concattenated Observable. | ||
*/ | ||
concatMap<U>(fn: (thing: T) => ObservableFromValue<U>): RelayObservable<U>; | ||
mergeMap<U>(fn: (value: T) => ObservableFromValue<U>): RelayObservable<U>; | ||
/** | ||
* Returns a new Observable which first mirrors this Observable, then when it | ||
* completes, waits for `pollInterval` milliseconds before re-subscribing to | ||
* this Observable again, looping in this manner until unsubscribed. | ||
* | ||
* The returned Observable never completes. | ||
*/ | ||
poll(pollInterval: number): RelayObservable<T>; | ||
/** | ||
* Returns a Promise which resolves when this Observable yields a first value | ||
* or when it completes with no value. | ||
*/ | ||
toPromise(): Promise<T | null | undefined>; | ||
toPromise(): Promise<T | undefined>; | ||
} | ||
export { RelayObservable as Observable }; | ||
export type Observable<T> = RelayObservable<T>; | ||
// ./networks/RelayQueryResponseCache | ||
declare class RelayQueryResponseCache { | ||
constructor(config: { size: number; ttl: number }); | ||
clear(): void; | ||
get(queryID: string, variables: Variables): GraphQLResponse | null; | ||
set(queryID: string, variables: Variables, payload: GraphQLResponse): void; | ||
} | ||
export { RelayQueryResponseCache as QueryResponseCache }; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// commitLocalUpdate | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// exposed through RelayModern, not Runtime directly | ||
export function commitLocalUpdate(environment: Environment, updater: StoreUpdater): void; | ||
// ./store/RelayInMemoryRecordSource | ||
declare class RelayInMemoryRecordSource implements MutableRecordSource { | ||
constructor(records?: RecordMap); | ||
clear(): void; | ||
delete(dataID: DataID): void; | ||
get(dataID: DataID): Record | null | undefined; | ||
getRecordIDs(): ReadonlyArray<DataID>; | ||
getStatus(dataID: DataID): RecordState; | ||
has(dataID: DataID): boolean; | ||
load(dataID: DataID, callback: (error: Error | null | undefined, record: Record | null | undefined) => void): void; | ||
remove(dataID: DataID): void; | ||
set(dataID: DataID, record: Record): void; | ||
size(): number; | ||
} | ||
export { RelayInMemoryRecordSource as RecordSource }; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// commitRelayModernMutation | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// exposed through RelayModern, not Runtime directly | ||
export interface MutationConfig<T extends OperationBase> { | ||
configs?: RelayMutationConfig[]; | ||
mutation: GraphQLTaggedNode; | ||
variables: T['variables']; | ||
uploadables?: UploadableMap; | ||
onCompleted?(response: T['response'], errors: PayloadError[] | null | undefined): void; | ||
onError?(error?: Error): void; | ||
optimisticUpdater?: SelectorStoreUpdater<T['response']>; | ||
optimisticResponse?: T['response']; | ||
updater?: SelectorStoreUpdater<T['response']>; | ||
// ./store/RelayModernStore | ||
declare class RelayModernStore implements Store { | ||
constructor(source: MutableRecordSource, gcScheduler?: Scheduler, operationLoader?: OperationLoader | null); | ||
getSource(): RecordSource; | ||
check(selector: NormalizationSelector): boolean; | ||
retain(selector: NormalizationSelector): Disposable; | ||
lookup(selector: ReaderSelector, owner?: OperationDescriptor): Snapshot; | ||
notify(): void; | ||
publish(source: RecordSource): void; | ||
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable; | ||
holdGC(): Disposable; | ||
} | ||
export function commitRelayModernMutation<T extends OperationBase = OperationDefaults>( | ||
export { RelayModernStore as Store }; | ||
// ./store/RelayModernSelector via ./store/RelayCore | ||
export function areEqualSelectors(thisSelector: OwnedReaderSelector, thatSelector: OwnedReaderSelector): boolean; | ||
export function getDataIDsFromObject( | ||
fragments: { [key: string]: ReaderFragment }, | ||
object: { [key: string]: unknown } | ||
): { [key: string]: DataID | ReadonlyArray<DataID> | null | undefined }; | ||
export function getSelector( | ||
operationVariables: Variables, | ||
fragment: ReaderFragment, | ||
item: unknown | ||
): OwnedReaderSelector | null | undefined; | ||
export function getSelectorList( | ||
operationVariables: Variables, | ||
fragment: ReaderFragment, | ||
items: ReadonlyArray<unknown> | ||
): ReadonlyArray<OwnedReaderSelector> | null | undefined; | ||
export function getSelectorsFromObject( | ||
operationVariables: Variables, | ||
fragments: { [key: string]: ReaderFragment }, | ||
object: { [key: string]: unknown } | ||
): { | ||
[key: string]: OwnedReaderSelector | ReadonlyArray<OwnedReaderSelector> | null | undefined; | ||
}; | ||
export function getVariablesFromObject( | ||
operationVariables: Variables, | ||
fragments: { [key: string]: ReaderFragment }, | ||
object: { [key: string]: unknown } | ||
): Variables; | ||
// ./store/RelayModernOperationDescriptor via ./store/RelayCore | ||
export function createOperationDescriptor(request: ConcreteRequest, variables: Variables): OperationDescriptor; | ||
// ./store/RelayCore | ||
export function createFragmentSpecResolver( | ||
context: RelayContext, | ||
containerName: string, | ||
fragments: FragmentMap, | ||
props: Props, | ||
callback?: () => void | ||
): FragmentSpecResolver; | ||
// ./query/RelayModernGraphQLTag | ||
export function getFragment(taggedNode: GraphQLTaggedNode): ReaderFragment; | ||
export function getFragmentOwner( | ||
fragmentNode: ReaderFragment, | ||
fragmentRef: FragmentPointer | ReadonlyArray<FragmentPointer | null | undefined> | null | undefined | ||
): OperationDescriptor | null; | ||
export function getFragmentOwners( | ||
fragmentNodes: { [key: string]: ReaderFragment }, | ||
fragmentRefs: { | ||
[key: string]: FragmentPointer | ReadonlyArray<FragmentPointer | null | undefined> | null | undefined; | ||
} | ||
): { [key: string]: OperationDescriptor | null }; | ||
export function getPaginationFragment(taggedNode: GraphQLTaggedNode): ReaderPaginationFragment | null; | ||
export function getRefetchableFragment(taggedNode: GraphQLTaggedNode): ReaderRefetchableFragment | null; | ||
export function getRequest(taggedNode: GraphQLTaggedNode): ConcreteRequest; | ||
export function graphql(strings: ReadonlyArray<string>): GraphQLTaggedNode; | ||
// ./store/RelayStoreUtils | ||
export function getStorageKey( | ||
field: NormalizationField | NormalizationHandle | ReaderField, | ||
variables: Variables | ||
): string; | ||
// Declarative mutation API | ||
// ./mutations/RelayDeclarativeMutationConfig | ||
export const MutationTypes: { | ||
RANGE_ADD: 'RANGE_ADD'; | ||
RANGE_DELETE: 'RANGE_DELETE'; | ||
NODE_DELETE: 'NODE_DELETE'; | ||
FIELDS_CHANGE: 'FIELDS_CHANGE'; | ||
REQUIRED_CHILDREN: 'REQUIRED_CHILDREN'; | ||
}; | ||
export const RangeOperations: { | ||
APPEND: 'append'; | ||
IGNORE: 'ignore'; | ||
PREPEND: 'prepend'; | ||
REFETCH: 'refetch'; // legacy only | ||
REMOVE: 'remove'; // legacy only | ||
}; | ||
export const FRAGMENTS_KEY: string; | ||
export const FRAGMENT_OWNER_KEY: string; | ||
export const ID_KEY: string; | ||
export const REF_KEY: string; | ||
export const REFS_KEY: string; | ||
export const ROOT_ID: string; | ||
export const ROOT_TYPE: string; | ||
export const TYPENAME_KEY: string; | ||
// Extensions | ||
// ./handlers/RelayDefaultHandlerProvider | ||
declare function RelayDefaultHandlerProvider(handle: string): Handler; | ||
export { RelayDefaultHandlerProvider as DefaultHandlerProvider }; | ||
// ./handlers/connection/RelayConnectionHandler | ||
interface RelayConnectionHandler { | ||
buildConnectionEdge( | ||
store: RecordSourceProxy, | ||
connection: RecordProxy, | ||
edge: RecordProxy | null | undefined | ||
): RecordProxy | null | undefined; | ||
createEdge(store: RecordSourceProxy, record: RecordProxy, node: RecordProxy, edgeType: string): RecordProxy; | ||
deleteNode(record: RecordProxy, nodeID: DataID): void; | ||
getConnection(record: ReadonlyRecordProxy, key: string, filters?: Variables | null): RecordProxy | null | undefined; | ||
insertEdgeAfter(record: RecordProxy, newEdge: RecordProxy, cursor?: string | null): void; | ||
insertEdgeBefore(record: RecordProxy, newEdge: RecordProxy, cursor?: string | null): void; | ||
update(store: RecordSourceProxy, payload: HandleFieldPayload): void; | ||
} | ||
declare const RelayConnectionHandler: RelayConnectionHandler; | ||
export { RelayConnectionHandler as ConnectionHandler }; | ||
// ./handlers/viewer/RelayViewerHandler | ||
interface RelayViewerHandler { | ||
readonly VIEWER_ID: string; | ||
update(store: RecordSourceProxy, payload: HandleFieldPayload): void; | ||
} | ||
declare const RelayViewerHandler: RelayViewerHandler; | ||
export { RelayViewerHandler as ViewerHandler }; | ||
// Helpers (can be implemented via the above API) | ||
// ./mutations/applyRelayModernOptimisticMutation | ||
declare function applyRelayModernOptimisticMutation( | ||
environment: Environment, | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
config: MutationConfig<T> | ||
config: OptimisticMutationConfig | ||
): Disposable; | ||
export { applyRelayModernOptimisticMutation as applyOptimisticMutation }; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// applyRelayModernOptimisticMutation | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// exposed through RelayModern, not Runtime directly | ||
export interface OptimisticMutationConfig { | ||
configs?: RelayMutationConfig[]; | ||
mutation: GraphQLTaggedNode; | ||
variables: Variables; | ||
optimisticUpdater?: SelectorStoreUpdater; | ||
optimisticResponse?: object; | ||
} | ||
// ./mutations/commitLocalUpdate | ||
export function commitLocalUpdate(environment: Environment, updater: StoreUpdater): void; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// fetchRelayModernQuery | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// exposed through RelayModern, not Runtime directly | ||
/** | ||
* A helper function to fetch the results of a query. Note that results for | ||
* fragment spreads are masked: fields must be explicitly listed in the query in | ||
* order to be accessible in the result object. | ||
* | ||
* NOTE: This module is primarily intended for integrating with classic APIs. | ||
* Most product code should use a Renderer or Container. | ||
* | ||
* TODO(t16875667): The return type should be `Promise<?SelectorData>`, but | ||
* that's not really helpful as `SelectorData` is essentially just `mixed`. We | ||
* can probably leverage generated flow types here to return the real expected | ||
* shape. | ||
*/ | ||
export function fetchRelayModernQuery( | ||
environment: any, // FIXME - $FlowFixMe in facebook source code | ||
// ./mutations/commitRelayModernMutation | ||
declare function commitRelayModernMutation<TOperation extends OperationType = OperationType>( | ||
environment: Environment, | ||
// tslint:disable-next-line no-unnecessary-generics | ||
config: MutationConfig<TOperation> | ||
): Disposable; | ||
export { commitRelayModernMutation as commitMutation }; | ||
// ./query/fetchRelayModernQuery | ||
declare function fetchRelayModernQuery<T extends OperationType>( | ||
environment: RelayModernEnvironment, | ||
taggedNode: GraphQLTaggedNode, | ||
variables: Variables, | ||
cacheConfig?: CacheConfig | ||
): Promise<any>; // FIXME - $FlowFixMe in facebook source code | ||
variables: T['variables'], | ||
cacheConfig?: CacheConfig | null | ||
): Promise<T['response']>; | ||
export { fetchRelayModernQuery as fetchQuery }; | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// requestRelaySubscription | ||
// ~~~~~~~~~~~~~~~~~~~~~ | ||
// exposed through RelayModern, not Runtime directly | ||
export interface GraphQLSubscriptionConfig { | ||
configs?: RelayMutationConfig[]; | ||
subscription: GraphQLTaggedNode; | ||
variables: Variables; | ||
onCompleted?(): void; | ||
onError?(error: Error): void; | ||
onNext?(response: object | null | undefined): void; | ||
updater?(store: RecordSourceSelectorProxy): void; | ||
// ./store/isRelayModernEnvironment | ||
export function isRelayModernEnvironment(environment: any): environment is RelayModernEnvironment; | ||
// ./subscription/requestRelaySubscription | ||
declare function requestRelaySubscription(environment: Environment, config: GraphQLSubscriptionConfig<{}>): Disposable; | ||
export { requestRelaySubscription as requestSubscription }; | ||
// Configuration interface for legacy or special uses | ||
// ./handlers/connection/RelayConnectionInterface | ||
export const ConnectionInterface: { | ||
get(): { | ||
CLIENT_MUTATION_ID: 'clientMutationId'; | ||
CURSOR: 'cursor'; | ||
EDGES_HAVE_SOURCE_FIELD: boolean; | ||
EDGES: 'edges'; | ||
END_CURSOR: 'endCursor'; | ||
HAS_NEXT_PAGE: 'hasNextPage'; | ||
HAS_PREV_PAGE: 'hasPreviousPage'; | ||
NODE: 'node'; | ||
PAGE_INFO_TYPE: 'PageInfo'; | ||
PAGE_INFO: 'pageInfo'; | ||
START_CURSOR: 'startCursor'; | ||
}; | ||
}; | ||
// Utilities | ||
interface Handler { | ||
update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void; | ||
} | ||
export function requestRelaySubscription(environment: Environment, config: GraphQLSubscriptionConfig): Disposable; | ||
type ProfileHandler = (name: string, state?: any) => (error?: Error) => void; | ||
export interface RelayProfiler { | ||
instrumentMethods(object: object, names: { [key: string]: string }): void; | ||
instrument<T extends (...args: any[]) => any>(name: string, originalFunction: T): T; | ||
attachAggregateHandler(name: string, handler: Handler): void; | ||
detachAggregateHandler(name: string, handler: Handler): void; | ||
profile(name: string, state?: any): { stop: (error?: Error) => void }; | ||
attachProfileHandler(name: string, handler: ProfileHandler): void; | ||
detachProfileHandler(name: string, handler: ProfileHandler): void; | ||
} | ||
export const RelayProfiler: RelayProfiler; | ||
// Internal API | ||
export function deepFreeze<T extends object>(value: T): T; | ||
export const RelayFeatureFlags: { | ||
MERGE_FETCH_AND_FRAGMENT_VARS: boolean; | ||
PREFER_FRAGMENT_OWNER_OVER_CONTEXT: boolean; | ||
}; |
{ | ||
"name": "@types/relay-runtime", | ||
"version": "1.3.13", | ||
"version": "4.0.0", | ||
"description": "TypeScript definitions for relay-runtime", | ||
@@ -16,2 +16,7 @@ "license": "MIT", | ||
"githubUsername": "alloy" | ||
}, | ||
{ | ||
"name": "Cameron Knight", | ||
"url": "https://github.com/ckknight", | ||
"githubUsername": "ckknight" | ||
} | ||
@@ -28,4 +33,4 @@ ], | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "4d89beb3c9cd5716eb88a0eb41a1fa2758ffea1d77131a6b8f4cf6937693158a", | ||
"typeScriptVersion": "2.9" | ||
"typesPublisherContentHash": "a583b3ed22737d91bfa99f23940ccd0c529b682208d8ca1e54feda9a9772899d", | ||
"typeScriptVersion": "3.0" | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
Additional Details | ||
* Last updated: Fri, 14 Jun 2019 15:43:33 GMT | ||
* Last updated: Tue, 18 Jun 2019 14:54:27 GMT | ||
* Dependencies: none | ||
@@ -17,2 +17,2 @@ * Global values: none | ||
# Credits | ||
These definitions were written by Matt Martin <https://github.com/voxmatt>, Eloy Durán <https://github.com/alloy>. | ||
These definitions were written by Matt Martin <https://github.com/voxmatt>, Eloy Durán <https://github.com/alloy>, Cameron Knight <https://github.com/ckknight>. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43079
1063
1