@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.
Files changed (114) hide show
  1. package/README.md +3 -0
  2. package/lib/GraphQLAPI.js +0 -5
  3. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +817 -0
  5. package/lib/Providers/constants.d.ts +95 -0
  6. package/lib/Providers/constants.js +103 -0
  7. package/lib/index.d.ts +0 -3
  8. package/lib/index.js +3 -9
  9. package/lib/internals/InternalGraphQLAPI.d.ts +4 -40
  10. package/lib/internals/InternalGraphQLAPI.js +89 -243
  11. package/lib/internals/index.d.ts +1 -0
  12. package/lib/internals/index.js +2 -1
  13. package/lib/internals/v6.d.ts +89 -0
  14. package/lib/internals/v6.js +99 -0
  15. package/lib/tsconfig.tsbuildinfo +5790 -0
  16. package/lib/types/PubSub.d.ts +27 -0
  17. package/lib/types/PubSub.js +46 -0
  18. package/lib/types/index.d.ts +184 -4
  19. package/lib/types/index.js +0 -3
  20. package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
  21. package/lib/utils/ConnectionStateMonitor.js +143 -0
  22. package/lib/utils/ReachabilityMonitor/index.d.ts +3 -0
  23. package/lib/utils/ReachabilityMonitor/index.js +6 -0
  24. package/lib/utils/ReachabilityMonitor/index.native.d.ts +3 -0
  25. package/lib/utils/ReachabilityMonitor/index.native.js +10 -0
  26. package/lib/utils/ReconnectionMonitor.d.ts +29 -0
  27. package/lib/utils/ReconnectionMonitor.js +72 -0
  28. package/lib/utils/errors/APIError.d.ts +7 -0
  29. package/lib/utils/errors/APIError.js +22 -0
  30. package/lib/utils/errors/assertValidationError.d.ts +5 -0
  31. package/lib/utils/errors/assertValidationError.js +16 -0
  32. package/lib/utils/errors/index.d.ts +3 -0
  33. package/lib/utils/errors/index.js +11 -0
  34. package/lib/utils/errors/validation.d.ts +8 -0
  35. package/lib/utils/errors/validation.js +26 -0
  36. package/lib/utils/index.d.ts +2 -0
  37. package/lib/utils/index.js +8 -0
  38. package/lib/utils/resolveConfig.d.ts +8 -0
  39. package/lib/utils/resolveConfig.js +17 -0
  40. package/lib/utils/resolveCredentials.d.ts +12 -0
  41. package/lib/utils/resolveCredentials.js +22 -0
  42. package/lib-esm/GraphQLAPI.js +0 -5
  43. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
  44. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +815 -0
  45. package/lib-esm/Providers/constants.d.ts +95 -0
  46. package/lib-esm/Providers/constants.js +100 -0
  47. package/lib-esm/index.d.ts +0 -3
  48. package/lib-esm/index.js +0 -4
  49. package/lib-esm/internals/InternalGraphQLAPI.d.ts +4 -40
  50. package/lib-esm/internals/InternalGraphQLAPI.js +90 -244
  51. package/lib-esm/internals/index.d.ts +1 -0
  52. package/lib-esm/internals/index.js +1 -1
  53. package/lib-esm/internals/v6.d.ts +89 -0
  54. package/lib-esm/internals/v6.js +96 -0
  55. package/lib-esm/tsconfig.tsbuildinfo +5790 -0
  56. package/lib-esm/types/PubSub.d.ts +27 -0
  57. package/lib-esm/types/PubSub.js +44 -0
  58. package/lib-esm/types/index.d.ts +184 -4
  59. package/lib-esm/types/index.js +0 -3
  60. package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
  61. package/lib-esm/utils/ConnectionStateMonitor.js +141 -0
  62. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +3 -0
  63. package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
  64. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +3 -0
  65. package/lib-esm/utils/ReachabilityMonitor/index.native.js +7 -0
  66. package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
  67. package/lib-esm/utils/ReconnectionMonitor.js +70 -0
  68. package/lib-esm/utils/errors/APIError.d.ts +7 -0
  69. package/lib-esm/utils/errors/APIError.js +20 -0
  70. package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
  71. package/lib-esm/utils/errors/assertValidationError.js +13 -0
  72. package/lib-esm/utils/errors/index.d.ts +3 -0
  73. package/lib-esm/utils/errors/index.js +5 -0
  74. package/lib-esm/utils/errors/validation.d.ts +8 -0
  75. package/lib-esm/utils/errors/validation.js +24 -0
  76. package/lib-esm/utils/index.d.ts +2 -0
  77. package/lib-esm/utils/index.js +4 -0
  78. package/lib-esm/utils/resolveConfig.d.ts +8 -0
  79. package/lib-esm/utils/resolveConfig.js +15 -0
  80. package/lib-esm/utils/resolveCredentials.d.ts +12 -0
  81. package/lib-esm/utils/resolveCredentials.js +20 -0
  82. package/package.json +114 -114
  83. package/src/GraphQLAPI.ts +0 -2
  84. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +1003 -0
  85. package/src/Providers/constants.ts +110 -0
  86. package/src/index.ts +0 -3
  87. package/src/internals/InternalGraphQLAPI.ts +62 -221
  88. package/src/internals/index.ts +2 -0
  89. package/src/internals/v6.ts +106 -0
  90. package/src/types/PubSub.ts +58 -0
  91. package/src/types/index.ts +234 -7
  92. package/src/utils/ConnectionStateMonitor.ts +195 -0
  93. package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
  94. package/src/utils/ReachabilityMonitor/index.ts +4 -0
  95. package/src/utils/ReconnectionMonitor.ts +76 -0
  96. package/src/utils/errors/APIError.ts +18 -0
  97. package/src/utils/errors/assertValidationError.ts +19 -0
  98. package/src/utils/errors/index.ts +6 -0
  99. package/src/utils/errors/validation.ts +26 -0
  100. package/src/utils/index.ts +5 -0
  101. package/src/utils/resolveConfig.ts +20 -0
  102. package/src/utils/resolveCredentials.ts +14 -0
  103. package/lib/.tsbuildinfo +0 -3
  104. package/lib/GraphQLAPI.js.map +0 -1
  105. package/lib/index.js.map +0 -1
  106. package/lib/internals/InternalGraphQLAPI.js.map +0 -1
  107. package/lib/internals/index.js.map +0 -1
  108. package/lib/types/index.js.map +0 -1
  109. package/lib-esm/.tsbuildinfo +0 -3
  110. package/lib-esm/GraphQLAPI.js.map +0 -1
  111. package/lib-esm/index.js.map +0 -1
  112. package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
  113. package/lib-esm/internals/index.js.map +0 -1
  114. 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,44 @@
1
+ export var CONTROL_MSG;
2
+ (function (CONTROL_MSG) {
3
+ CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
4
+ CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
5
+ CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
6
+ CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
7
+ CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
8
+ })(CONTROL_MSG || (CONTROL_MSG = {}));
9
+ /** @enum {string} */
10
+ export var ConnectionState;
11
+ (function (ConnectionState) {
12
+ /*
13
+ * The connection is alive and healthy
14
+ */
15
+ ConnectionState["Connected"] = "Connected";
16
+ /*
17
+ * The connection is alive, but the connection is offline
18
+ */
19
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
20
+ /*
21
+ * The connection has been disconnected while in use
22
+ */
23
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
24
+ /*
25
+ * The connection has been disconnected and the network is offline
26
+ */
27
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
28
+ /*
29
+ * The connection is in the process of connecting
30
+ */
31
+ ConnectionState["Connecting"] = "Connecting";
32
+ /*
33
+ * The connection is not in use and is being disconnected
34
+ */
35
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
36
+ /*
37
+ * The connection is not in use and has been disconnected
38
+ */
39
+ ConnectionState["Disconnected"] = "Disconnected";
40
+ /*
41
+ * The connection is alive, but a keep alive message has been missed
42
+ */
43
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
44
+ })(ConnectionState || (ConnectionState = {}));
@@ -1,11 +1,15 @@
1
1
  import { Source, DocumentNode, GraphQLError } from 'graphql';
2
2
  export { OperationTypeNode } from 'graphql';
3
- import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
4
- export { GRAPHQL_AUTH_MODE };
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?: object;
8
- authMode?: keyof typeof GRAPHQL_AUTH_MODE;
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
+ };
@@ -1,5 +1,3 @@
1
- import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
2
- export { GRAPHQL_AUTH_MODE };
3
1
  export var GraphQLAuthError;
4
2
  (function (GraphQLAuthError) {
5
3
  GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
@@ -8,4 +6,3 @@ export var GraphQLAuthError;
8
6
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
9
7
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
10
8
  })(GraphQLAuthError || (GraphQLAuthError = {}));
11
- //# 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,141 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { __assign } from "tslib";
4
+ import Observable from 'zen-observable-ts';
5
+ import { ConnectionState } from '../types/PubSub';
6
+ import { ReachabilityMonitor } from './ReachabilityMonitor';
7
+ export var CONNECTION_CHANGE = {
8
+ KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
9
+ KEEP_ALIVE: { keepAliveState: 'healthy' },
10
+ CONNECTION_ESTABLISHED: { connectionState: 'connected' },
11
+ CONNECTION_FAILED: {
12
+ intendedConnectionState: 'disconnected',
13
+ connectionState: 'disconnected',
14
+ },
15
+ CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
16
+ OPENING_CONNECTION: {
17
+ intendedConnectionState: 'connected',
18
+ connectionState: 'connecting',
19
+ },
20
+ CLOSED: { connectionState: 'disconnected' },
21
+ ONLINE: { networkState: 'connected' },
22
+ OFFLINE: { networkState: 'disconnected' },
23
+ };
24
+ var ConnectionStateMonitor = /** @class */ (function () {
25
+ function ConnectionStateMonitor() {
26
+ var _this = this;
27
+ this._networkMonitoringSubscription = undefined;
28
+ this._linkedConnectionState = {
29
+ networkState: 'connected',
30
+ connectionState: 'disconnected',
31
+ intendedConnectionState: 'disconnected',
32
+ keepAliveState: 'healthy',
33
+ };
34
+ // Attempt to update the state with the current actual network state
35
+ this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(function (_a) {
36
+ var online = _a.online;
37
+ var _b;
38
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
39
+ (_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
40
+ });
41
+ this._linkedConnectionStateObservable =
42
+ new Observable(function (connectionStateObserver) {
43
+ connectionStateObserver.next(_this._linkedConnectionState);
44
+ _this._linkedConnectionStateObserver = connectionStateObserver;
45
+ });
46
+ }
47
+ /**
48
+ * Turn network state monitoring on if it isn't on already
49
+ */
50
+ ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
51
+ var _this = this;
52
+ var _a;
53
+ // If no initial network state was discovered, stop trying
54
+ (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
55
+ // Maintain the network state based on the reachability monitor
56
+ if (this._networkMonitoringSubscription === undefined) {
57
+ this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(function (_a) {
58
+ var online = _a.online;
59
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
60
+ });
61
+ }
62
+ };
63
+ /**
64
+ * Turn network state monitoring off if it isn't off already
65
+ */
66
+ ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
67
+ var _a;
68
+ (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
69
+ this._networkMonitoringSubscription = undefined;
70
+ };
71
+ Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
72
+ /**
73
+ * Get the observable that allows us to monitor the connection state
74
+ *
75
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
76
+ */
77
+ get: function () {
78
+ var _this = this;
79
+ var previous;
80
+ // The linked state aggregates state changes to any of the network, connection,
81
+ // intendedConnection and keepAliveHealth. Some states will change these independent
82
+ // states without changing the overall connection state.
83
+ // After translating from linked states to ConnectionState, then remove any duplicates
84
+ return this._linkedConnectionStateObservable
85
+ .map(function (value) {
86
+ return _this.connectionStatesTranslator(value);
87
+ })
88
+ .filter(function (current) {
89
+ var toInclude = current !== previous;
90
+ previous = current;
91
+ return toInclude;
92
+ });
93
+ },
94
+ enumerable: true,
95
+ configurable: true
96
+ });
97
+ /*
98
+ * Updates local connection state and emits the full state to the observer.
99
+ */
100
+ ConnectionStateMonitor.prototype.record = function (statusUpdates) {
101
+ // Maintain the network monitor
102
+ if (statusUpdates.intendedConnectionState === 'connected') {
103
+ this.enableNetworkMonitoring();
104
+ }
105
+ else if (statusUpdates.intendedConnectionState === 'disconnected') {
106
+ this.disableNetworkMonitoring();
107
+ }
108
+ // Maintain the socket state
109
+ var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
110
+ this._linkedConnectionState = __assign({}, newSocketStatus);
111
+ this._linkedConnectionStateObserver.next(this._linkedConnectionState);
112
+ };
113
+ /*
114
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
115
+ */
116
+ ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
117
+ var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
118
+ if (connectionState === 'connected' && networkState === 'disconnected')
119
+ return ConnectionState.ConnectedPendingNetwork;
120
+ if (connectionState === 'connected' &&
121
+ intendedConnectionState === 'disconnected')
122
+ return ConnectionState.ConnectedPendingDisconnect;
123
+ if (connectionState === 'disconnected' &&
124
+ intendedConnectionState === 'connected' &&
125
+ networkState === 'disconnected')
126
+ return ConnectionState.ConnectionDisruptedPendingNetwork;
127
+ if (connectionState === 'disconnected' &&
128
+ intendedConnectionState === 'connected')
129
+ return ConnectionState.ConnectionDisrupted;
130
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy')
131
+ return ConnectionState.ConnectedPendingKeepAlive;
132
+ // All remaining states directly correspond to the connection state
133
+ if (connectionState === 'connecting')
134
+ return ConnectionState.Connecting;
135
+ if (connectionState === 'disconnected')
136
+ return ConnectionState.Disconnected;
137
+ return ConnectionState.Connected;
138
+ };
139
+ return ConnectionStateMonitor;
140
+ }());
141
+ export { ConnectionStateMonitor };
@@ -0,0 +1,3 @@
1
+ export declare const ReachabilityMonitor: () => import("zen-observable-ts").default<{
2
+ online: boolean;
3
+ }>;
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Reachability } from '@aws-amplify/core/internals/utils';
4
+ export var ReachabilityMonitor = function () { return new Reachability().networkMonitor(); };
@@ -0,0 +1,3 @@
1
+ export declare const ReachabilityMonitor: () => import("zen-observable-ts").default<{
2
+ online: boolean;
3
+ }>;
@@ -0,0 +1,7 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Reachability } from '@aws-amplify/core/internals/utils';
4
+ import { default as NetInfo } from '@react-native-community/netinfo';
5
+ export var ReachabilityMonitor = function () {
6
+ return new Reachability().networkMonitor(NetInfo);
7
+ };
@@ -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,70 @@
1
+ import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
2
+ export var ReconnectEvent;
3
+ (function (ReconnectEvent) {
4
+ ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
5
+ ReconnectEvent["HALT_RECONNECT"] = "HALT_RECONNECT";
6
+ })(ReconnectEvent || (ReconnectEvent = {}));
7
+ /**
8
+ * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
9
+ * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
10
+ * Attempting to reconnect only once creates unrecoverable states when the network state isn't
11
+ * supported by the browser, so this keeps retrying every minute until halted.
12
+ */
13
+ var ReconnectionMonitor = /** @class */ (function () {
14
+ function ReconnectionMonitor() {
15
+ this.reconnectObservers = [];
16
+ }
17
+ /**
18
+ * Add reconnect observer to the list of observers to alert on reconnect
19
+ */
20
+ ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
21
+ this.reconnectObservers.push(reconnectObserver);
22
+ };
23
+ /**
24
+ * Given a reconnect event, start the appropriate behavior
25
+ */
26
+ ReconnectionMonitor.prototype.record = function (event) {
27
+ var _this = this;
28
+ if (event === ReconnectEvent.START_RECONNECT) {
29
+ // If the reconnection hasn't been started
30
+ if (this.reconnectSetTimeoutId === undefined &&
31
+ this.reconnectIntervalId === undefined) {
32
+ this.reconnectSetTimeoutId = setTimeout(function () {
33
+ // Reconnect now
34
+ _this._triggerReconnect();
35
+ // Retry reconnect every periodically until it works
36
+ _this.reconnectIntervalId = setInterval(function () {
37
+ _this._triggerReconnect();
38
+ }, RECONNECT_INTERVAL);
39
+ }, RECONNECT_DELAY);
40
+ }
41
+ }
42
+ if (event === ReconnectEvent.HALT_RECONNECT) {
43
+ if (this.reconnectIntervalId) {
44
+ clearInterval(this.reconnectIntervalId);
45
+ this.reconnectIntervalId = undefined;
46
+ }
47
+ if (this.reconnectSetTimeoutId) {
48
+ clearTimeout(this.reconnectSetTimeoutId);
49
+ this.reconnectSetTimeoutId = undefined;
50
+ }
51
+ }
52
+ };
53
+ /**
54
+ * Complete all reconnect observers
55
+ */
56
+ ReconnectionMonitor.prototype.close = function () {
57
+ this.reconnectObservers.forEach(function (reconnectObserver) {
58
+ var _a;
59
+ (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
60
+ });
61
+ };
62
+ ReconnectionMonitor.prototype._triggerReconnect = function () {
63
+ this.reconnectObservers.forEach(function (reconnectObserver) {
64
+ var _a;
65
+ (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
66
+ });
67
+ };
68
+ return ReconnectionMonitor;
69
+ }());
70
+ export { ReconnectionMonitor };
@@ -0,0 +1,7 @@
1
+ import { AmplifyError, ErrorParams } from '@aws-amplify/core/internals/utils';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class APIError extends AmplifyError {
6
+ constructor(params: ErrorParams);
7
+ }
@@ -0,0 +1,20 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { __extends } from "tslib";
4
+ import { AmplifyError } from '@aws-amplify/core/internals/utils';
5
+ /**
6
+ * @internal
7
+ */
8
+ var APIError = /** @class */ (function (_super) {
9
+ __extends(APIError, _super);
10
+ function APIError(params) {
11
+ var _this = _super.call(this, params) || this;
12
+ // Hack for making the custom error class work when transpiled to es5
13
+ // TODO: Delete the following 2 lines after we change the build target to >= es2015
14
+ _this.constructor = APIError;
15
+ Object.setPrototypeOf(_this, APIError.prototype);
16
+ return _this;
17
+ }
18
+ return APIError;
19
+ }(AmplifyError));
20
+ export { APIError };
@@ -0,0 +1,5 @@
1
+ import { APIValidationErrorCode } from './validation';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function assertValidationError(assertion: boolean, name: APIValidationErrorCode): asserts assertion;
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { APIError } from './APIError';
4
+ import { validationErrorMap } from './validation';
5
+ /**
6
+ * @internal
7
+ */
8
+ export function assertValidationError(assertion, name) {
9
+ var _a = validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
10
+ if (!assertion) {
11
+ throw new APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ export { APIError } from './APIError';
2
+ export { assertValidationError } from './assertValidationError';
3
+ export { APIValidationErrorCode, validationErrorMap } from './validation';
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { APIError } from './APIError';
4
+ export { assertValidationError } from './assertValidationError';
5
+ export { APIValidationErrorCode, validationErrorMap } from './validation';
@@ -0,0 +1,8 @@
1
+ import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
+ export declare enum APIValidationErrorCode {
3
+ NoAppId = "NoAppId",
4
+ NoCredentials = "NoCredentials",
5
+ NoRegion = "NoRegion",
6
+ NoDefaultAuthMode = "NoDefaultAuthMode"
7
+ }
8
+ export declare const validationErrorMap: AmplifyErrorMap<APIValidationErrorCode>;