@aws-amplify/api-graphql 3.4.11 → 4.0.1-console-preview.047a1dd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/GraphQLAPI.js +0 -5
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +817 -0
- package/lib/Providers/constants.d.ts +95 -0
- package/lib/Providers/constants.js +103 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +3 -9
- package/lib/internals/InternalGraphQLAPI.d.ts +4 -40
- package/lib/internals/InternalGraphQLAPI.js +89 -243
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +2 -1
- package/lib/internals/v6.d.ts +89 -0
- package/lib/internals/v6.js +99 -0
- package/lib/tsconfig.tsbuildinfo +5790 -0
- package/lib/types/PubSub.d.ts +27 -0
- package/lib/types/PubSub.js +46 -0
- package/lib/types/index.d.ts +184 -4
- package/lib/types/index.js +0 -3
- package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib/utils/ConnectionStateMonitor.js +143 -0
- package/lib/utils/ReachabilityMonitor/index.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.js +6 -0
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.native.js +10 -0
- package/lib/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib/utils/ReconnectionMonitor.js +72 -0
- package/lib/utils/errors/APIError.d.ts +7 -0
- package/lib/utils/errors/APIError.js +22 -0
- package/lib/utils/errors/assertValidationError.d.ts +5 -0
- package/lib/utils/errors/assertValidationError.js +16 -0
- package/lib/utils/errors/index.d.ts +3 -0
- package/lib/utils/errors/index.js +11 -0
- package/lib/utils/errors/validation.d.ts +8 -0
- package/lib/utils/errors/validation.js +26 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +8 -0
- package/lib/utils/resolveConfig.d.ts +8 -0
- package/lib/utils/resolveConfig.js +17 -0
- package/lib/utils/resolveCredentials.d.ts +12 -0
- package/lib/utils/resolveCredentials.js +22 -0
- package/lib-esm/GraphQLAPI.js +0 -5
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +815 -0
- package/lib-esm/Providers/constants.d.ts +95 -0
- package/lib-esm/Providers/constants.js +100 -0
- package/lib-esm/index.d.ts +0 -3
- package/lib-esm/index.js +0 -4
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +4 -40
- package/lib-esm/internals/InternalGraphQLAPI.js +90 -244
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +1 -1
- package/lib-esm/internals/v6.d.ts +89 -0
- package/lib-esm/internals/v6.js +96 -0
- package/lib-esm/tsconfig.tsbuildinfo +5790 -0
- package/lib-esm/types/PubSub.d.ts +27 -0
- package/lib-esm/types/PubSub.js +44 -0
- package/lib-esm/types/index.d.ts +184 -4
- package/lib-esm/types/index.js +0 -3
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib-esm/utils/ConnectionStateMonitor.js +141 -0
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +3 -0
- package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +3 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +7 -0
- package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib-esm/utils/ReconnectionMonitor.js +70 -0
- package/lib-esm/utils/errors/APIError.d.ts +7 -0
- package/lib-esm/utils/errors/APIError.js +20 -0
- package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
- package/lib-esm/utils/errors/assertValidationError.js +13 -0
- package/lib-esm/utils/errors/index.d.ts +3 -0
- package/lib-esm/utils/errors/index.js +5 -0
- package/lib-esm/utils/errors/validation.d.ts +8 -0
- package/lib-esm/utils/errors/validation.js +24 -0
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +4 -0
- package/lib-esm/utils/resolveConfig.d.ts +8 -0
- package/lib-esm/utils/resolveConfig.js +15 -0
- package/lib-esm/utils/resolveCredentials.d.ts +12 -0
- package/lib-esm/utils/resolveCredentials.js +20 -0
- package/package.json +114 -114
- package/src/GraphQLAPI.ts +0 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +1003 -0
- package/src/Providers/constants.ts +110 -0
- package/src/index.ts +0 -3
- package/src/internals/InternalGraphQLAPI.ts +62 -221
- package/src/internals/index.ts +2 -0
- package/src/internals/v6.ts +106 -0
- package/src/types/PubSub.ts +58 -0
- package/src/types/index.ts +234 -7
- package/src/utils/ConnectionStateMonitor.ts +195 -0
- package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
- package/src/utils/ReachabilityMonitor/index.ts +4 -0
- package/src/utils/ReconnectionMonitor.ts +76 -0
- package/src/utils/errors/APIError.ts +18 -0
- package/src/utils/errors/assertValidationError.ts +19 -0
- package/src/utils/errors/index.ts +6 -0
- package/src/utils/errors/validation.ts +26 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/resolveConfig.ts +20 -0
- package/src/utils/resolveCredentials.ts +14 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/GraphQLAPI.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib/internals/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/GraphQLAPI.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib-esm/internals/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ZenObservable } from 'zen-observable-ts';
|
|
2
|
+
export interface SubscriptionObserver<T> {
|
|
3
|
+
closed: boolean;
|
|
4
|
+
next(value: T): void;
|
|
5
|
+
error(errorValue: any): void;
|
|
6
|
+
complete(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare enum CONTROL_MSG {
|
|
9
|
+
CONNECTION_CLOSED = "Connection closed",
|
|
10
|
+
CONNECTION_FAILED = "Connection failed",
|
|
11
|
+
REALTIME_SUBSCRIPTION_INIT_ERROR = "AppSync Realtime subscription init error",
|
|
12
|
+
SUBSCRIPTION_ACK = "Subscription ack",
|
|
13
|
+
TIMEOUT_DISCONNECT = "Timeout disconnect"
|
|
14
|
+
}
|
|
15
|
+
/** @enum {string} */
|
|
16
|
+
export declare enum ConnectionState {
|
|
17
|
+
Connected = "Connected",
|
|
18
|
+
ConnectedPendingNetwork = "ConnectedPendingNetwork",
|
|
19
|
+
ConnectionDisrupted = "ConnectionDisrupted",
|
|
20
|
+
ConnectionDisruptedPendingNetwork = "ConnectionDisruptedPendingNetwork",
|
|
21
|
+
Connecting = "Connecting",
|
|
22
|
+
ConnectedPendingDisconnect = "ConnectedPendingDisconnect",
|
|
23
|
+
Disconnected = "Disconnected",
|
|
24
|
+
ConnectedPendingKeepAlive = "ConnectedPendingKeepAlive"
|
|
25
|
+
}
|
|
26
|
+
export declare type PubSubContent = Record<string, unknown> | string;
|
|
27
|
+
export declare type PubSubContentObserver = ZenObservable.SubscriptionObserver<PubSubContent>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var CONTROL_MSG;
|
|
4
|
+
(function (CONTROL_MSG) {
|
|
5
|
+
CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
|
|
6
|
+
CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
|
|
7
|
+
CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
|
|
8
|
+
CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
|
|
9
|
+
CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
|
|
10
|
+
})(CONTROL_MSG = exports.CONTROL_MSG || (exports.CONTROL_MSG = {}));
|
|
11
|
+
/** @enum {string} */
|
|
12
|
+
var ConnectionState;
|
|
13
|
+
(function (ConnectionState) {
|
|
14
|
+
/*
|
|
15
|
+
* The connection is alive and healthy
|
|
16
|
+
*/
|
|
17
|
+
ConnectionState["Connected"] = "Connected";
|
|
18
|
+
/*
|
|
19
|
+
* The connection is alive, but the connection is offline
|
|
20
|
+
*/
|
|
21
|
+
ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
|
|
22
|
+
/*
|
|
23
|
+
* The connection has been disconnected while in use
|
|
24
|
+
*/
|
|
25
|
+
ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
|
|
26
|
+
/*
|
|
27
|
+
* The connection has been disconnected and the network is offline
|
|
28
|
+
*/
|
|
29
|
+
ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
|
|
30
|
+
/*
|
|
31
|
+
* The connection is in the process of connecting
|
|
32
|
+
*/
|
|
33
|
+
ConnectionState["Connecting"] = "Connecting";
|
|
34
|
+
/*
|
|
35
|
+
* The connection is not in use and is being disconnected
|
|
36
|
+
*/
|
|
37
|
+
ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
|
|
38
|
+
/*
|
|
39
|
+
* The connection is not in use and has been disconnected
|
|
40
|
+
*/
|
|
41
|
+
ConnectionState["Disconnected"] = "Disconnected";
|
|
42
|
+
/*
|
|
43
|
+
* The connection is alive, but a keep alive message has been missed
|
|
44
|
+
*/
|
|
45
|
+
ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
|
|
46
|
+
})(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
2
2
|
export { OperationTypeNode } from 'graphql';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { Observable } from 'zen-observable-ts';
|
|
4
|
+
import { DocumentType } from '@aws-amplify/api-rest';
|
|
5
|
+
export declare type GraphQLAuthMode = 'AWS_IAM' | 'COGNITO_USERPOOLS' | 'API_KEY';
|
|
6
|
+
/**
|
|
7
|
+
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
8
|
+
*/
|
|
5
9
|
export interface GraphQLOptions {
|
|
6
10
|
query: string | DocumentNode;
|
|
7
|
-
variables?:
|
|
8
|
-
authMode?:
|
|
11
|
+
variables?: Record<string, DocumentType>;
|
|
12
|
+
authMode?: string;
|
|
9
13
|
authToken?: string;
|
|
10
14
|
/**
|
|
11
15
|
* @deprecated This property should not be used
|
|
@@ -19,6 +23,68 @@ export interface GraphQLResult<T = object> {
|
|
|
19
23
|
[key: string]: any;
|
|
20
24
|
};
|
|
21
25
|
}
|
|
26
|
+
declare const queryType: unique symbol;
|
|
27
|
+
export declare type GraphQLQuery<T> = T & {
|
|
28
|
+
readonly [queryType]: 'query';
|
|
29
|
+
};
|
|
30
|
+
export declare type GraphQLSubscription<T> = T & {
|
|
31
|
+
readonly [queryType]: 'subscription';
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // |-- You are here
|
|
38
|
+
* // v
|
|
39
|
+
* const subResult: GraphqlSubscriptionResult<T> = client.graphql({
|
|
40
|
+
* query: onCreateWidget
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const sub = subResult.subscribe({
|
|
44
|
+
* //
|
|
45
|
+
* // |-- You are here
|
|
46
|
+
* // v
|
|
47
|
+
* next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
|
|
48
|
+
* handle(message.value); // <-- type OnCreateWidgetSubscription
|
|
49
|
+
* }
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* The shape of messages passed to `next()` from a graphql subscription. E.g.,
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* const sub = client.graphql({
|
|
59
|
+
* query: onCreateWidget,
|
|
60
|
+
* }).subscribe({
|
|
61
|
+
* //
|
|
62
|
+
* // |-- You are here
|
|
63
|
+
* // v
|
|
64
|
+
* next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
|
|
65
|
+
* handle(message.value); // <-- type OnCreateWidgetSubscription
|
|
66
|
+
* }
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare type GraphqlSubscriptionMessage<T> = {
|
|
71
|
+
data?: T;
|
|
72
|
+
};
|
|
73
|
+
export interface AWSAppSyncRealTimeProviderOptions {
|
|
74
|
+
appSyncGraphqlEndpoint?: string;
|
|
75
|
+
authenticationType?: GraphQLAuthMode;
|
|
76
|
+
query?: string;
|
|
77
|
+
variables?: Record<string, unknown>;
|
|
78
|
+
apiKey?: string;
|
|
79
|
+
region?: string;
|
|
80
|
+
graphql_headers?: () => {} | (() => Promise<{}>);
|
|
81
|
+
additionalHeaders?: {
|
|
82
|
+
[key: string]: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export declare type AWSAppSyncRealTimeProvider = {
|
|
86
|
+
subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
|
|
87
|
+
};
|
|
22
88
|
export declare enum GraphQLAuthError {
|
|
23
89
|
NO_API_KEY = "No api-key configured",
|
|
24
90
|
NO_CURRENT_USER = "No current user",
|
|
@@ -31,3 +97,117 @@ export declare enum GraphQLAuthError {
|
|
|
31
97
|
* @see: https://graphql.org/graphql-js/language/#parse
|
|
32
98
|
*/
|
|
33
99
|
export declare type GraphQLOperation = Source | string;
|
|
100
|
+
/**
|
|
101
|
+
* API V6 `graphql({options})` type that can leverage branded graphql `query`
|
|
102
|
+
* objects and fallback types.
|
|
103
|
+
*/
|
|
104
|
+
export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
|
|
105
|
+
query: TYPED_GQL_STRING | DocumentNode;
|
|
106
|
+
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
107
|
+
authMode?: GraphQLAuthMode;
|
|
108
|
+
authToken?: string;
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated This property should not be used
|
|
111
|
+
*/
|
|
112
|
+
userAgentSuffix?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Result type for `graphql()` operations that don't include any specific
|
|
116
|
+
* type information. The result could be either a `Promise` or `Subscription`.
|
|
117
|
+
*
|
|
118
|
+
* Invoking code should either cast the result or use `?` and `!` operators to
|
|
119
|
+
* navigate the result objects.
|
|
120
|
+
*/
|
|
121
|
+
export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
|
|
122
|
+
/**
|
|
123
|
+
* The expected type for `variables` in a V6 `graphql()` operation with
|
|
124
|
+
* respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
|
|
125
|
+
*/
|
|
126
|
+
export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any> ? IN : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any> ? IN : any;
|
|
127
|
+
/**
|
|
128
|
+
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
129
|
+
* and `TYPED_GQL_STRING`.
|
|
130
|
+
*/
|
|
131
|
+
export declare type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT> ? Promise<GraphQLResult<QUERY_OUT>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<MUTATION_OUT>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<SUB_OUT> : FALLBACK_TYPE extends GraphQLQuery<infer T> ? Promise<GraphQLResult<FALLBACK_TYPE>> : FALLBACK_TYPE extends GraphQLSubscription<infer T> ? GraphqlSubscriptionResult<FALLBACK_TYPE> : FALLBACK_TYPE extends GraphQLOperationType<infer IN, infer CUSTOM_OUT> ? CUSTOM_OUT : UnknownGraphQLResponse;
|
|
132
|
+
/**
|
|
133
|
+
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
134
|
+
* `IN` and `OUT` types (the type of `variables` and the return type, respectively).
|
|
135
|
+
*
|
|
136
|
+
* I.E.,
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* type MyVariablesType = { ... };
|
|
140
|
+
* type MyResultType = { ... };
|
|
141
|
+
* type MyOperationType = { variables: MyVariablesType, result: MyResultType };
|
|
142
|
+
*
|
|
143
|
+
* const result: MyResultType = graphql<MyOperationType>("graphql string", {
|
|
144
|
+
* variables: {
|
|
145
|
+
* // MyVariablesType
|
|
146
|
+
* }
|
|
147
|
+
* })
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
|
|
151
|
+
variables: IN;
|
|
152
|
+
result: OUT;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Nominal type for branding generated graphql query operation strings with
|
|
156
|
+
* input and output types.
|
|
157
|
+
*
|
|
158
|
+
* E.g.,
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* export const getWidget = `...` as GeneratedQuery<
|
|
162
|
+
* GetWidgetQueryVariables,
|
|
163
|
+
* GetWidgetQuery
|
|
164
|
+
* >;
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
168
|
+
* assign types to the `variables` and result objects.
|
|
169
|
+
*/
|
|
170
|
+
export declare type GeneratedQuery<InputType, OutputType> = string & {
|
|
171
|
+
__generatedQueryInput: InputType;
|
|
172
|
+
__generatedQueryOutput: OutputType;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
176
|
+
* input and output types.
|
|
177
|
+
*
|
|
178
|
+
* E.g.,
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* export const createWidget = `...` as GeneratedQuery<
|
|
182
|
+
* CreateWidgetMutationVariables,
|
|
183
|
+
* CreateWidgetMutation
|
|
184
|
+
* >;
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
188
|
+
* assign types to the `variables` and result objects.
|
|
189
|
+
*/
|
|
190
|
+
export declare type GeneratedMutation<InputType, OutputType> = string & {
|
|
191
|
+
__generatedMutationInput: InputType;
|
|
192
|
+
__generatedMutationOutput: OutputType;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
196
|
+
* input and output types.
|
|
197
|
+
*
|
|
198
|
+
* E.g.,
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* export const createWidget = `...` as GeneratedMutation<
|
|
202
|
+
* CreateWidgetMutationVariables,
|
|
203
|
+
* CreateWidgetMutation
|
|
204
|
+
* >;
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
208
|
+
* assign types to the `variables` and result objects.
|
|
209
|
+
*/
|
|
210
|
+
export declare type GeneratedSubscription<InputType, OutputType> = string & {
|
|
211
|
+
__generatedSubscriptionInput: InputType;
|
|
212
|
+
__generatedSubscriptionOutput: OutputType;
|
|
213
|
+
};
|
package/lib/types/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var auth_1 = require("@aws-amplify/auth");
|
|
4
|
-
exports.GRAPHQL_AUTH_MODE = auth_1.GRAPHQL_AUTH_MODE;
|
|
5
3
|
var GraphQLAuthError;
|
|
6
4
|
(function (GraphQLAuthError) {
|
|
7
5
|
GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
|
|
@@ -10,4 +8,3 @@ var GraphQLAuthError;
|
|
|
10
8
|
GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
|
|
11
9
|
GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
|
|
12
10
|
})(GraphQLAuthError = exports.GraphQLAuthError || (exports.GraphQLAuthError = {}));
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Observable from 'zen-observable-ts';
|
|
2
|
+
import { ConnectionState } from '../types/PubSub';
|
|
3
|
+
declare type LinkedConnectionState = 'connected' | 'disconnected';
|
|
4
|
+
declare type LinkedHealthState = 'healthy' | 'unhealthy';
|
|
5
|
+
declare type LinkedConnectionStates = {
|
|
6
|
+
networkState: LinkedConnectionState;
|
|
7
|
+
connectionState: LinkedConnectionState | 'connecting';
|
|
8
|
+
intendedConnectionState: LinkedConnectionState;
|
|
9
|
+
keepAliveState: LinkedHealthState;
|
|
10
|
+
};
|
|
11
|
+
export declare const CONNECTION_CHANGE: {
|
|
12
|
+
[key in 'KEEP_ALIVE_MISSED' | 'KEEP_ALIVE' | 'CONNECTION_ESTABLISHED' | 'CONNECTION_FAILED' | 'CLOSING_CONNECTION' | 'OPENING_CONNECTION' | 'CLOSED' | 'ONLINE' | 'OFFLINE']: Partial<LinkedConnectionStates>;
|
|
13
|
+
};
|
|
14
|
+
export declare class ConnectionStateMonitor {
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
private _linkedConnectionState;
|
|
19
|
+
private _linkedConnectionStateObservable;
|
|
20
|
+
private _linkedConnectionStateObserver;
|
|
21
|
+
private _networkMonitoringSubscription?;
|
|
22
|
+
private _initialNetworkStateSubscription?;
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Turn network state monitoring on if it isn't on already
|
|
26
|
+
*/
|
|
27
|
+
private enableNetworkMonitoring;
|
|
28
|
+
/**
|
|
29
|
+
* Turn network state monitoring off if it isn't off already
|
|
30
|
+
*/
|
|
31
|
+
private disableNetworkMonitoring;
|
|
32
|
+
/**
|
|
33
|
+
* Get the observable that allows us to monitor the connection state
|
|
34
|
+
*
|
|
35
|
+
* @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
|
|
36
|
+
*/
|
|
37
|
+
get connectionStateObservable(): Observable<ConnectionState>;
|
|
38
|
+
record(statusUpdates: Partial<LinkedConnectionStates>): void;
|
|
39
|
+
private connectionStatesTranslator;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var zen_observable_ts_1 = tslib_1.__importDefault(require("zen-observable-ts"));
|
|
7
|
+
var PubSub_1 = require("../types/PubSub");
|
|
8
|
+
var ReachabilityMonitor_1 = require("./ReachabilityMonitor");
|
|
9
|
+
exports.CONNECTION_CHANGE = {
|
|
10
|
+
KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
|
|
11
|
+
KEEP_ALIVE: { keepAliveState: 'healthy' },
|
|
12
|
+
CONNECTION_ESTABLISHED: { connectionState: 'connected' },
|
|
13
|
+
CONNECTION_FAILED: {
|
|
14
|
+
intendedConnectionState: 'disconnected',
|
|
15
|
+
connectionState: 'disconnected',
|
|
16
|
+
},
|
|
17
|
+
CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
|
|
18
|
+
OPENING_CONNECTION: {
|
|
19
|
+
intendedConnectionState: 'connected',
|
|
20
|
+
connectionState: 'connecting',
|
|
21
|
+
},
|
|
22
|
+
CLOSED: { connectionState: 'disconnected' },
|
|
23
|
+
ONLINE: { networkState: 'connected' },
|
|
24
|
+
OFFLINE: { networkState: 'disconnected' },
|
|
25
|
+
};
|
|
26
|
+
var ConnectionStateMonitor = /** @class */ (function () {
|
|
27
|
+
function ConnectionStateMonitor() {
|
|
28
|
+
var _this = this;
|
|
29
|
+
this._networkMonitoringSubscription = undefined;
|
|
30
|
+
this._linkedConnectionState = {
|
|
31
|
+
networkState: 'connected',
|
|
32
|
+
connectionState: 'disconnected',
|
|
33
|
+
intendedConnectionState: 'disconnected',
|
|
34
|
+
keepAliveState: 'healthy',
|
|
35
|
+
};
|
|
36
|
+
// Attempt to update the state with the current actual network state
|
|
37
|
+
this._initialNetworkStateSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(function (_a) {
|
|
38
|
+
var online = _a.online;
|
|
39
|
+
var _b;
|
|
40
|
+
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
41
|
+
(_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
42
|
+
});
|
|
43
|
+
this._linkedConnectionStateObservable =
|
|
44
|
+
new zen_observable_ts_1.default(function (connectionStateObserver) {
|
|
45
|
+
connectionStateObserver.next(_this._linkedConnectionState);
|
|
46
|
+
_this._linkedConnectionStateObserver = connectionStateObserver;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Turn network state monitoring on if it isn't on already
|
|
51
|
+
*/
|
|
52
|
+
ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
|
|
53
|
+
var _this = this;
|
|
54
|
+
var _a;
|
|
55
|
+
// If no initial network state was discovered, stop trying
|
|
56
|
+
(_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
57
|
+
// Maintain the network state based on the reachability monitor
|
|
58
|
+
if (this._networkMonitoringSubscription === undefined) {
|
|
59
|
+
this._networkMonitoringSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(function (_a) {
|
|
60
|
+
var online = _a.online;
|
|
61
|
+
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Turn network state monitoring off if it isn't off already
|
|
67
|
+
*/
|
|
68
|
+
ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
71
|
+
this._networkMonitoringSubscription = undefined;
|
|
72
|
+
};
|
|
73
|
+
Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
|
|
74
|
+
/**
|
|
75
|
+
* Get the observable that allows us to monitor the connection state
|
|
76
|
+
*
|
|
77
|
+
* @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
|
|
78
|
+
*/
|
|
79
|
+
get: function () {
|
|
80
|
+
var _this = this;
|
|
81
|
+
var previous;
|
|
82
|
+
// The linked state aggregates state changes to any of the network, connection,
|
|
83
|
+
// intendedConnection and keepAliveHealth. Some states will change these independent
|
|
84
|
+
// states without changing the overall connection state.
|
|
85
|
+
// After translating from linked states to ConnectionState, then remove any duplicates
|
|
86
|
+
return this._linkedConnectionStateObservable
|
|
87
|
+
.map(function (value) {
|
|
88
|
+
return _this.connectionStatesTranslator(value);
|
|
89
|
+
})
|
|
90
|
+
.filter(function (current) {
|
|
91
|
+
var toInclude = current !== previous;
|
|
92
|
+
previous = current;
|
|
93
|
+
return toInclude;
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true
|
|
98
|
+
});
|
|
99
|
+
/*
|
|
100
|
+
* Updates local connection state and emits the full state to the observer.
|
|
101
|
+
*/
|
|
102
|
+
ConnectionStateMonitor.prototype.record = function (statusUpdates) {
|
|
103
|
+
// Maintain the network monitor
|
|
104
|
+
if (statusUpdates.intendedConnectionState === 'connected') {
|
|
105
|
+
this.enableNetworkMonitoring();
|
|
106
|
+
}
|
|
107
|
+
else if (statusUpdates.intendedConnectionState === 'disconnected') {
|
|
108
|
+
this.disableNetworkMonitoring();
|
|
109
|
+
}
|
|
110
|
+
// Maintain the socket state
|
|
111
|
+
var newSocketStatus = tslib_1.__assign(tslib_1.__assign({}, this._linkedConnectionState), statusUpdates);
|
|
112
|
+
this._linkedConnectionState = tslib_1.__assign({}, newSocketStatus);
|
|
113
|
+
this._linkedConnectionStateObserver.next(this._linkedConnectionState);
|
|
114
|
+
};
|
|
115
|
+
/*
|
|
116
|
+
* Translate the ConnectionState structure into a specific ConnectionState string literal union
|
|
117
|
+
*/
|
|
118
|
+
ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
|
|
119
|
+
var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
|
|
120
|
+
if (connectionState === 'connected' && networkState === 'disconnected')
|
|
121
|
+
return PubSub_1.ConnectionState.ConnectedPendingNetwork;
|
|
122
|
+
if (connectionState === 'connected' &&
|
|
123
|
+
intendedConnectionState === 'disconnected')
|
|
124
|
+
return PubSub_1.ConnectionState.ConnectedPendingDisconnect;
|
|
125
|
+
if (connectionState === 'disconnected' &&
|
|
126
|
+
intendedConnectionState === 'connected' &&
|
|
127
|
+
networkState === 'disconnected')
|
|
128
|
+
return PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork;
|
|
129
|
+
if (connectionState === 'disconnected' &&
|
|
130
|
+
intendedConnectionState === 'connected')
|
|
131
|
+
return PubSub_1.ConnectionState.ConnectionDisrupted;
|
|
132
|
+
if (connectionState === 'connected' && keepAliveState === 'unhealthy')
|
|
133
|
+
return PubSub_1.ConnectionState.ConnectedPendingKeepAlive;
|
|
134
|
+
// All remaining states directly correspond to the connection state
|
|
135
|
+
if (connectionState === 'connecting')
|
|
136
|
+
return PubSub_1.ConnectionState.Connecting;
|
|
137
|
+
if (connectionState === 'disconnected')
|
|
138
|
+
return PubSub_1.ConnectionState.Disconnected;
|
|
139
|
+
return PubSub_1.ConnectionState.Connected;
|
|
140
|
+
};
|
|
141
|
+
return ConnectionStateMonitor;
|
|
142
|
+
}());
|
|
143
|
+
exports.ConnectionStateMonitor = ConnectionStateMonitor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
|
+
exports.ReachabilityMonitor = function () { return new utils_1.Reachability().networkMonitor(); };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
var netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
|
|
8
|
+
exports.ReachabilityMonitor = function () {
|
|
9
|
+
return new utils_1.Reachability().networkMonitor(netinfo_1.default);
|
|
10
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Observer } from 'zen-observable-ts';
|
|
2
|
+
export declare enum ReconnectEvent {
|
|
3
|
+
START_RECONNECT = "START_RECONNECT",
|
|
4
|
+
HALT_RECONNECT = "HALT_RECONNECT"
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
|
|
8
|
+
* Reconnnect attempts are delayed by 5 seconds to let the interface settle.
|
|
9
|
+
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
10
|
+
* supported by the browser, so this keeps retrying every minute until halted.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ReconnectionMonitor {
|
|
13
|
+
private reconnectObservers;
|
|
14
|
+
private reconnectIntervalId?;
|
|
15
|
+
private reconnectSetTimeoutId?;
|
|
16
|
+
/**
|
|
17
|
+
* Add reconnect observer to the list of observers to alert on reconnect
|
|
18
|
+
*/
|
|
19
|
+
addObserver(reconnectObserver: Observer<void>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Given a reconnect event, start the appropriate behavior
|
|
22
|
+
*/
|
|
23
|
+
record(event: ReconnectEvent): void;
|
|
24
|
+
/**
|
|
25
|
+
* Complete all reconnect observers
|
|
26
|
+
*/
|
|
27
|
+
close(): void;
|
|
28
|
+
private _triggerReconnect;
|
|
29
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var constants_1 = require("../Providers/constants");
|
|
4
|
+
var ReconnectEvent;
|
|
5
|
+
(function (ReconnectEvent) {
|
|
6
|
+
ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
|
|
7
|
+
ReconnectEvent["HALT_RECONNECT"] = "HALT_RECONNECT";
|
|
8
|
+
})(ReconnectEvent = exports.ReconnectEvent || (exports.ReconnectEvent = {}));
|
|
9
|
+
/**
|
|
10
|
+
* Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
|
|
11
|
+
* Reconnnect attempts are delayed by 5 seconds to let the interface settle.
|
|
12
|
+
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
13
|
+
* supported by the browser, so this keeps retrying every minute until halted.
|
|
14
|
+
*/
|
|
15
|
+
var ReconnectionMonitor = /** @class */ (function () {
|
|
16
|
+
function ReconnectionMonitor() {
|
|
17
|
+
this.reconnectObservers = [];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Add reconnect observer to the list of observers to alert on reconnect
|
|
21
|
+
*/
|
|
22
|
+
ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
|
|
23
|
+
this.reconnectObservers.push(reconnectObserver);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Given a reconnect event, start the appropriate behavior
|
|
27
|
+
*/
|
|
28
|
+
ReconnectionMonitor.prototype.record = function (event) {
|
|
29
|
+
var _this = this;
|
|
30
|
+
if (event === ReconnectEvent.START_RECONNECT) {
|
|
31
|
+
// If the reconnection hasn't been started
|
|
32
|
+
if (this.reconnectSetTimeoutId === undefined &&
|
|
33
|
+
this.reconnectIntervalId === undefined) {
|
|
34
|
+
this.reconnectSetTimeoutId = setTimeout(function () {
|
|
35
|
+
// Reconnect now
|
|
36
|
+
_this._triggerReconnect();
|
|
37
|
+
// Retry reconnect every periodically until it works
|
|
38
|
+
_this.reconnectIntervalId = setInterval(function () {
|
|
39
|
+
_this._triggerReconnect();
|
|
40
|
+
}, constants_1.RECONNECT_INTERVAL);
|
|
41
|
+
}, constants_1.RECONNECT_DELAY);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (event === ReconnectEvent.HALT_RECONNECT) {
|
|
45
|
+
if (this.reconnectIntervalId) {
|
|
46
|
+
clearInterval(this.reconnectIntervalId);
|
|
47
|
+
this.reconnectIntervalId = undefined;
|
|
48
|
+
}
|
|
49
|
+
if (this.reconnectSetTimeoutId) {
|
|
50
|
+
clearTimeout(this.reconnectSetTimeoutId);
|
|
51
|
+
this.reconnectSetTimeoutId = undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Complete all reconnect observers
|
|
57
|
+
*/
|
|
58
|
+
ReconnectionMonitor.prototype.close = function () {
|
|
59
|
+
this.reconnectObservers.forEach(function (reconnectObserver) {
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
ReconnectionMonitor.prototype._triggerReconnect = function () {
|
|
65
|
+
this.reconnectObservers.forEach(function (reconnectObserver) {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return ReconnectionMonitor;
|
|
71
|
+
}());
|
|
72
|
+
exports.ReconnectionMonitor = ReconnectionMonitor;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
var APIError = /** @class */ (function (_super) {
|
|
11
|
+
tslib_1.__extends(APIError, _super);
|
|
12
|
+
function APIError(params) {
|
|
13
|
+
var _this = _super.call(this, params) || this;
|
|
14
|
+
// Hack for making the custom error class work when transpiled to es5
|
|
15
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
16
|
+
_this.constructor = APIError;
|
|
17
|
+
Object.setPrototypeOf(_this, APIError.prototype);
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
return APIError;
|
|
21
|
+
}(utils_1.AmplifyError));
|
|
22
|
+
exports.APIError = APIError;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var APIError_1 = require("./APIError");
|
|
6
|
+
var validation_1 = require("./validation");
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
function assertValidationError(assertion, name) {
|
|
11
|
+
var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
|
|
12
|
+
if (!assertion) {
|
|
13
|
+
throw new APIError_1.APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.assertValidationError = assertValidationError;
|