@aws-amplify/api-graphql 3.4.12-api-v6-models.b3abc9b.0 → 4.0.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 (118) hide show
  1. package/README.md +3 -0
  2. package/lib/GraphQLAPI.d.ts +17 -4
  3. package/lib/GraphQLAPI.js +33 -27
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  5. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +690 -0
  6. package/lib/Providers/constants.d.ts +95 -0
  7. package/lib/Providers/constants.js +103 -0
  8. package/lib/index.d.ts +1 -3
  9. package/lib/index.js +6 -10
  10. package/lib/internals/InternalGraphQLAPI.d.ts +11 -34
  11. package/lib/internals/InternalGraphQLAPI.js +219 -345
  12. package/lib/internals/index.d.ts +1 -1
  13. package/lib/internals/index.js +2 -1
  14. package/lib/internals/v6.d.ts +14 -2
  15. package/lib/internals/v6.js +21 -3
  16. package/lib/tsconfig.tsbuildinfo +6813 -0
  17. package/lib/types/PubSub.d.ts +27 -0
  18. package/lib/types/PubSub.js +46 -0
  19. package/lib/types/index.d.ts +119 -12
  20. package/lib/types/index.js +4 -3
  21. package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
  22. package/lib/utils/ConnectionStateMonitor.js +131 -0
  23. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -0
  24. package/lib/utils/ReachabilityMonitor/index.js +6 -0
  25. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  26. package/lib/utils/ReachabilityMonitor/index.native.js +8 -0
  27. package/lib/utils/ReconnectionMonitor.d.ts +29 -0
  28. package/lib/utils/ReconnectionMonitor.js +68 -0
  29. package/lib/utils/errors/APIError.d.ts +7 -0
  30. package/lib/utils/errors/APIError.js +18 -0
  31. package/lib/utils/errors/assertValidationError.d.ts +5 -0
  32. package/lib/utils/errors/assertValidationError.js +16 -0
  33. package/lib/utils/errors/index.d.ts +3 -0
  34. package/lib/utils/errors/index.js +11 -0
  35. package/lib/utils/errors/validation.d.ts +7 -0
  36. package/lib/utils/errors/validation.js +25 -0
  37. package/lib/utils/index.d.ts +2 -0
  38. package/lib/utils/index.js +8 -0
  39. package/lib/utils/resolveConfig.d.ts +12 -0
  40. package/lib/utils/resolveConfig.js +22 -0
  41. package/lib/utils/resolveLibraryOptions.d.ts +11 -0
  42. package/lib/utils/resolveLibraryOptions.js +12 -0
  43. package/lib-esm/GraphQLAPI.d.ts +17 -4
  44. package/lib-esm/GraphQLAPI.js +33 -28
  45. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  46. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +687 -0
  47. package/lib-esm/Providers/constants.d.ts +95 -0
  48. package/lib-esm/Providers/constants.js +100 -0
  49. package/lib-esm/index.d.ts +1 -3
  50. package/lib-esm/index.js +1 -4
  51. package/lib-esm/internals/InternalGraphQLAPI.d.ts +11 -34
  52. package/lib-esm/internals/InternalGraphQLAPI.js +218 -345
  53. package/lib-esm/internals/index.d.ts +1 -1
  54. package/lib-esm/internals/index.js +1 -2
  55. package/lib-esm/internals/v6.d.ts +14 -2
  56. package/lib-esm/internals/v6.js +18 -2
  57. package/lib-esm/tsconfig.tsbuildinfo +6813 -0
  58. package/lib-esm/types/PubSub.d.ts +27 -0
  59. package/lib-esm/types/PubSub.js +44 -0
  60. package/lib-esm/types/index.d.ts +119 -12
  61. package/lib-esm/types/index.js +2 -3
  62. package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
  63. package/lib-esm/utils/ConnectionStateMonitor.js +128 -0
  64. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -0
  65. package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
  66. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  67. package/lib-esm/utils/ReachabilityMonitor/index.native.js +5 -0
  68. package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
  69. package/lib-esm/utils/ReconnectionMonitor.js +65 -0
  70. package/lib-esm/utils/errors/APIError.d.ts +7 -0
  71. package/lib-esm/utils/errors/APIError.js +15 -0
  72. package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
  73. package/lib-esm/utils/errors/assertValidationError.js +13 -0
  74. package/lib-esm/utils/errors/index.d.ts +3 -0
  75. package/lib-esm/utils/errors/index.js +5 -0
  76. package/lib-esm/utils/errors/validation.d.ts +7 -0
  77. package/lib-esm/utils/errors/validation.js +23 -0
  78. package/lib-esm/utils/index.d.ts +2 -0
  79. package/lib-esm/utils/index.js +4 -0
  80. package/lib-esm/utils/resolveConfig.d.ts +12 -0
  81. package/lib-esm/utils/resolveConfig.js +20 -0
  82. package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
  83. package/lib-esm/utils/resolveLibraryOptions.js +10 -0
  84. package/package.json +122 -118
  85. package/src/GraphQLAPI.ts +26 -4
  86. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +998 -0
  87. package/src/Providers/constants.ts +110 -0
  88. package/src/index.ts +2 -3
  89. package/src/internals/InternalGraphQLAPI.ts +181 -218
  90. package/src/internals/index.ts +1 -1
  91. package/src/internals/v6.ts +34 -2
  92. package/src/types/PubSub.ts +56 -0
  93. package/src/types/index.ts +175 -15
  94. package/src/utils/ConnectionStateMonitor.ts +199 -0
  95. package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
  96. package/src/utils/ReachabilityMonitor/index.ts +4 -0
  97. package/src/utils/ReconnectionMonitor.ts +76 -0
  98. package/src/utils/errors/APIError.ts +21 -0
  99. package/src/utils/errors/assertValidationError.ts +19 -0
  100. package/src/utils/errors/index.ts +6 -0
  101. package/src/utils/errors/validation.ts +26 -0
  102. package/src/utils/index.ts +5 -0
  103. package/src/utils/resolveConfig.ts +35 -0
  104. package/src/utils/resolveLibraryOptions.ts +13 -0
  105. package/lib/.tsbuildinfo +0 -3
  106. package/lib/GraphQLAPI.js.map +0 -1
  107. package/lib/index.js.map +0 -1
  108. package/lib/internals/InternalGraphQLAPI.js.map +0 -1
  109. package/lib/internals/index.js.map +0 -1
  110. package/lib/internals/v6.js.map +0 -1
  111. package/lib/types/index.js.map +0 -1
  112. package/lib-esm/.tsbuildinfo +0 -3
  113. package/lib-esm/GraphQLAPI.js.map +0 -1
  114. package/lib-esm/index.js.map +0 -1
  115. package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
  116. package/lib-esm/internals/index.js.map +0 -1
  117. package/lib-esm/internals/v6.js.map +0 -1
  118. package/lib-esm/types/index.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ import { Observer } from 'rxjs';
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>;
27
+ export declare type PubSubContentObserver = Observer<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,16 +1,17 @@
1
+ import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
1
2
  import { Source, DocumentNode, GraphQLError } from 'graphql';
2
3
  export { OperationTypeNode } from 'graphql';
3
- import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
4
- export { GRAPHQL_AUTH_MODE };
5
- import { Observable } from 'zen-observable-ts';
6
- import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
4
+ import { Observable } from 'rxjs';
5
+ import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
6
+ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
7
+ export { CONTROL_MSG, ConnectionState } from './PubSub';
7
8
  /**
8
9
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
9
10
  */
10
11
  export interface GraphQLOptions {
11
12
  query: string | DocumentNode;
12
- variables?: object;
13
- authMode?: keyof typeof GRAPHQL_AUTH_MODE;
13
+ variables?: Record<string, DocumentType>;
14
+ authMode?: GraphQLAuthMode;
14
15
  authToken?: string;
15
16
  /**
16
17
  * @deprecated This property should not be used
@@ -18,7 +19,7 @@ export interface GraphQLOptions {
18
19
  userAgentSuffix?: string;
19
20
  }
20
21
  export interface GraphQLResult<T = object> {
21
- data?: T;
22
+ data: T;
22
23
  errors?: GraphQLError[];
23
24
  extensions?: {
24
25
  [key: string]: any;
@@ -31,6 +32,66 @@ export declare type GraphQLQuery<T> = T & {
31
32
  export declare type GraphQLSubscription<T> = T & {
32
33
  readonly [queryType]: 'subscription';
33
34
  };
35
+ /**
36
+ * Accepts a code generated model type and returns a supertype that
37
+ * can accept return values from the relevant graphql operations.
38
+ *
39
+ * For example:
40
+ *
41
+ * ```typescript
42
+ * import { GraphQLReturnType } from 'aws-amplify/api';
43
+ * import { MyModel } from './API';
44
+ * import { getMyModel } from './graphql/queries';
45
+ *
46
+ * const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
47
+ * setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
48
+ * ```
49
+ *
50
+ * Trying to assign the result of a `getMyModel` operation directly to a
51
+ * `MyModel` variables won't necessarily work, because normally-required related
52
+ * models might not be part of the selection set.
53
+ *
54
+ * This util simply makes related model properties optional recursively.
55
+ */
56
+ export declare type GraphQLReturnType<T> = T extends {} ? {
57
+ [K in keyof T]?: GraphQLReturnType<T[K]>;
58
+ } : T;
59
+ /**
60
+ * Describes a paged list result from AppSync, which can either
61
+ * live at the top query or property (e.g., related model) level.
62
+ */
63
+ declare type PagedList<T, TYPENAME> = {
64
+ __typename: TYPENAME;
65
+ nextToken?: string | null | undefined;
66
+ items: Array<T>;
67
+ };
68
+ /**
69
+ * Recursively looks through a result type and removes nulls and
70
+ * and undefined from `PagedList` types.
71
+ *
72
+ * Although a graphql response might contain empty values in an
73
+ * array, this will only be the case when we also have errors,
74
+ * which will then be *thrown*.
75
+ */
76
+ declare type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
77
+ [K in keyof T]: WithListsFixed<T[K]>;
78
+ } : T;
79
+ /**
80
+ * Returns an updated response type to always return a value.
81
+ */
82
+ declare type NeverEmpty<T> = {
83
+ [K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
84
+ };
85
+ /**
86
+ * Replaces all list result types in a query result with types to exclude
87
+ * nulls and undefined from list member unions.
88
+ *
89
+ * If empty members are present, there will also be errors present,
90
+ * and the response will instead be *thrown*.
91
+ */
92
+ declare type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
93
+ [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
94
+ } : T;
34
95
  /**
35
96
  * The return value from a `graphql({query})` call when `query` is a subscription.
36
97
  *
@@ -69,10 +130,22 @@ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptio
69
130
  * ```
70
131
  */
71
132
  export declare type GraphqlSubscriptionMessage<T> = {
72
- provider: AWSAppSyncRealTimeProvider;
73
- value: {
74
- data?: T;
133
+ data: T;
134
+ };
135
+ export interface AWSAppSyncRealTimeProviderOptions {
136
+ appSyncGraphqlEndpoint?: string;
137
+ authenticationType?: GraphQLAuthMode;
138
+ query?: string;
139
+ variables?: Record<string, unknown>;
140
+ apiKey?: string;
141
+ region?: string;
142
+ graphql_headers?: () => {} | (() => Promise<{}>);
143
+ additionalHeaders?: {
144
+ [key: string]: string;
75
145
  };
146
+ }
147
+ export declare type AWSAppSyncRealTimeProvider = {
148
+ subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
76
149
  };
77
150
  export declare enum GraphQLAuthError {
78
151
  NO_API_KEY = "No api-key configured",
@@ -93,7 +166,7 @@ export declare type GraphQLOperation = Source | string;
93
166
  export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
94
167
  query: TYPED_GQL_STRING | DocumentNode;
95
168
  variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
96
- authMode?: keyof typeof GRAPHQL_AUTH_MODE;
169
+ authMode?: GraphQLAuthMode;
97
170
  authToken?: string;
98
171
  /**
99
172
  * @deprecated This property should not be used
@@ -117,7 +190,7 @@ export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRIN
117
190
  * The expected return type with respect to the given `FALLBACK_TYPE`
118
191
  * and `TYPED_GQL_STRING`.
119
192
  */
120
- 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;
193
+ 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<FixedQueryResult<QUERY_OUT>>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<NeverEmpty<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;
121
194
  /**
122
195
  * The shape customers can use to provide `T` to `graphql<T>()` to specify both
123
196
  * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
@@ -200,3 +273,37 @@ export declare type GeneratedSubscription<InputType, OutputType> = string & {
200
273
  __generatedSubscriptionInput: InputType;
201
274
  __generatedSubscriptionOutput: OutputType;
202
275
  };
276
+ declare type FilteredKeys<T> = {
277
+ [P in keyof T]: T[P] extends never ? never : P;
278
+ }[keyof T];
279
+ declare type ExcludeNeverFields<O> = {
280
+ [K in FilteredKeys<O>]: O[K];
281
+ };
282
+ export declare const __amplify: unique symbol;
283
+ export declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
284
+ [__amplify]: AmplifyClassV6;
285
+ graphql: GraphQLMethod;
286
+ cancel: (promise: Promise<any>, message?: string) => boolean;
287
+ isCancelError: (error: any) => boolean;
288
+ }>;
289
+ export declare type V6ClientSSR<T extends Record<any, any> = never> = ExcludeNeverFields<{
290
+ [__amplify]: AmplifyClassV6;
291
+ graphql: GraphQLMethodSSR;
292
+ cancel: (promise: Promise<any>, message?: string) => boolean;
293
+ isCancelError: (error: any) => boolean;
294
+ }>;
295
+ export declare type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
296
+ [key: string]: string;
297
+ } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
298
+ export declare type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
299
+ [key: string]: string;
300
+ } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
301
+ /**
302
+ * @private
303
+ *
304
+ * The knobs available for configuring `server/generateClient` internally.
305
+ */
306
+ export declare type ServerClientGenerationParams = {
307
+ amplify: null | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>);
308
+ config: ResourcesConfig;
309
+ };
@@ -1,5 +1,4 @@
1
- import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
2
- export { GRAPHQL_AUTH_MODE };
1
+ export { CONTROL_MSG, ConnectionState } from './PubSub';
3
2
  export var GraphQLAuthError;
4
3
  (function (GraphQLAuthError) {
5
4
  GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
@@ -8,4 +7,4 @@ export var GraphQLAuthError;
8
7
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
9
8
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
10
9
  })(GraphQLAuthError || (GraphQLAuthError = {}));
11
- //# sourceMappingURL=index.js.map
10
+ export const __amplify = Symbol('amplify');
@@ -0,0 +1,41 @@
1
+ import { Observable } from 'rxjs';
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,128 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Observable, map, filter } from 'rxjs';
4
+ import { ConnectionState } from '../types/PubSub';
5
+ import { ReachabilityMonitor } from './ReachabilityMonitor';
6
+ export const CONNECTION_CHANGE = {
7
+ KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
8
+ KEEP_ALIVE: { keepAliveState: 'healthy' },
9
+ CONNECTION_ESTABLISHED: { connectionState: 'connected' },
10
+ CONNECTION_FAILED: {
11
+ intendedConnectionState: 'disconnected',
12
+ connectionState: 'disconnected',
13
+ },
14
+ CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
15
+ OPENING_CONNECTION: {
16
+ intendedConnectionState: 'connected',
17
+ connectionState: 'connecting',
18
+ },
19
+ CLOSED: { connectionState: 'disconnected' },
20
+ ONLINE: { networkState: 'connected' },
21
+ OFFLINE: { networkState: 'disconnected' },
22
+ };
23
+ export class ConnectionStateMonitor {
24
+ constructor() {
25
+ this._networkMonitoringSubscription = undefined;
26
+ this._linkedConnectionState = {
27
+ networkState: 'connected',
28
+ connectionState: 'disconnected',
29
+ intendedConnectionState: 'disconnected',
30
+ keepAliveState: 'healthy',
31
+ };
32
+ // Attempt to update the state with the current actual network state
33
+ this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(({ online }) => {
34
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
35
+ this._initialNetworkStateSubscription?.unsubscribe();
36
+ });
37
+ this._linkedConnectionStateObservable =
38
+ new Observable(connectionStateObserver => {
39
+ connectionStateObserver.next(this._linkedConnectionState);
40
+ this._linkedConnectionStateObserver = connectionStateObserver;
41
+ });
42
+ }
43
+ /**
44
+ * Turn network state monitoring on if it isn't on already
45
+ */
46
+ enableNetworkMonitoring() {
47
+ // If no initial network state was discovered, stop trying
48
+ this._initialNetworkStateSubscription?.unsubscribe();
49
+ // Maintain the network state based on the reachability monitor
50
+ if (this._networkMonitoringSubscription === undefined) {
51
+ this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(({ online }) => {
52
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
53
+ });
54
+ }
55
+ }
56
+ /**
57
+ * Turn network state monitoring off if it isn't off already
58
+ */
59
+ disableNetworkMonitoring() {
60
+ this._networkMonitoringSubscription?.unsubscribe();
61
+ this._networkMonitoringSubscription = undefined;
62
+ }
63
+ /**
64
+ * Get the observable that allows us to monitor the connection state
65
+ *
66
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
67
+ */
68
+ get connectionStateObservable() {
69
+ let previous;
70
+ // The linked state aggregates state changes to any of the network, connection,
71
+ // intendedConnection and keepAliveHealth. Some states will change these independent
72
+ // states without changing the overall connection state.
73
+ // After translating from linked states to ConnectionState, then remove any duplicates
74
+ return this._linkedConnectionStateObservable
75
+ .pipe(map(value => {
76
+ return this.connectionStatesTranslator(value);
77
+ }))
78
+ .pipe(filter(current => {
79
+ const toInclude = current !== previous;
80
+ previous = current;
81
+ return toInclude;
82
+ }));
83
+ }
84
+ /*
85
+ * Updates local connection state and emits the full state to the observer.
86
+ */
87
+ record(statusUpdates) {
88
+ // Maintain the network monitor
89
+ if (statusUpdates.intendedConnectionState === 'connected') {
90
+ this.enableNetworkMonitoring();
91
+ }
92
+ else if (statusUpdates.intendedConnectionState === 'disconnected') {
93
+ this.disableNetworkMonitoring();
94
+ }
95
+ // Maintain the socket state
96
+ const newSocketStatus = {
97
+ ...this._linkedConnectionState,
98
+ ...statusUpdates,
99
+ };
100
+ this._linkedConnectionState = { ...newSocketStatus };
101
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
102
+ }
103
+ /*
104
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
105
+ */
106
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
107
+ if (connectionState === 'connected' && networkState === 'disconnected')
108
+ return ConnectionState.ConnectedPendingNetwork;
109
+ if (connectionState === 'connected' &&
110
+ intendedConnectionState === 'disconnected')
111
+ return ConnectionState.ConnectedPendingDisconnect;
112
+ if (connectionState === 'disconnected' &&
113
+ intendedConnectionState === 'connected' &&
114
+ networkState === 'disconnected')
115
+ return ConnectionState.ConnectionDisruptedPendingNetwork;
116
+ if (connectionState === 'disconnected' &&
117
+ intendedConnectionState === 'connected')
118
+ return ConnectionState.ConnectionDisrupted;
119
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy')
120
+ return ConnectionState.ConnectedPendingKeepAlive;
121
+ // All remaining states directly correspond to the connection state
122
+ if (connectionState === 'connecting')
123
+ return ConnectionState.Connecting;
124
+ if (connectionState === 'disconnected')
125
+ return ConnectionState.Disconnected;
126
+ return ConnectionState.Connected;
127
+ }
128
+ }
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => any;
@@ -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 const ReachabilityMonitor = () => new Reachability().networkMonitor();
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => any;
@@ -0,0 +1,5 @@
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 const ReachabilityMonitor = () => new Reachability().networkMonitor(NetInfo);
@@ -0,0 +1,29 @@
1
+ import { Observer } from 'rxjs';
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,65 @@
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
+ export class ReconnectionMonitor {
14
+ constructor() {
15
+ this.reconnectObservers = [];
16
+ }
17
+ /**
18
+ * Add reconnect observer to the list of observers to alert on reconnect
19
+ */
20
+ addObserver(reconnectObserver) {
21
+ this.reconnectObservers.push(reconnectObserver);
22
+ }
23
+ /**
24
+ * Given a reconnect event, start the appropriate behavior
25
+ */
26
+ record(event) {
27
+ if (event === ReconnectEvent.START_RECONNECT) {
28
+ // If the reconnection hasn't been started
29
+ if (this.reconnectSetTimeoutId === undefined &&
30
+ this.reconnectIntervalId === undefined) {
31
+ this.reconnectSetTimeoutId = setTimeout(() => {
32
+ // Reconnect now
33
+ this._triggerReconnect();
34
+ // Retry reconnect every periodically until it works
35
+ this.reconnectIntervalId = setInterval(() => {
36
+ this._triggerReconnect();
37
+ }, RECONNECT_INTERVAL);
38
+ }, RECONNECT_DELAY);
39
+ }
40
+ }
41
+ if (event === ReconnectEvent.HALT_RECONNECT) {
42
+ if (this.reconnectIntervalId) {
43
+ clearInterval(this.reconnectIntervalId);
44
+ this.reconnectIntervalId = undefined;
45
+ }
46
+ if (this.reconnectSetTimeoutId) {
47
+ clearTimeout(this.reconnectSetTimeoutId);
48
+ this.reconnectSetTimeoutId = undefined;
49
+ }
50
+ }
51
+ }
52
+ /**
53
+ * Complete all reconnect observers
54
+ */
55
+ close() {
56
+ this.reconnectObservers.forEach(reconnectObserver => {
57
+ reconnectObserver.complete?.();
58
+ });
59
+ }
60
+ _triggerReconnect() {
61
+ this.reconnectObservers.forEach(reconnectObserver => {
62
+ reconnectObserver.next?.();
63
+ });
64
+ }
65
+ }
@@ -0,0 +1,7 @@
1
+ import { AmplifyError, AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class APIError extends AmplifyError {
6
+ constructor(params: AmplifyErrorParams);
7
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AmplifyError, } from '@aws-amplify/core/internals/utils';
4
+ /**
5
+ * @internal
6
+ */
7
+ export class APIError extends AmplifyError {
8
+ constructor(params) {
9
+ super(params);
10
+ // Hack for making the custom error class work when transpiled to es5
11
+ // TODO: Delete the following 2 lines after we change the build target to >= es2015
12
+ this.constructor = APIError;
13
+ Object.setPrototypeOf(this, APIError.prototype);
14
+ }
15
+ }
@@ -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
+ const { message, recoverySuggestion } = validationErrorMap[name];
10
+ if (!assertion) {
11
+ throw new APIError({ name, message, 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,7 @@
1
+ import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
+ export declare enum APIValidationErrorCode {
3
+ NoAuthSession = "NoAuthSession",
4
+ NoRegion = "NoRegion",
5
+ NoCustomEndpoint = "NoCustomEndpoint"
6
+ }
7
+ export declare const validationErrorMap: AmplifyErrorMap<APIValidationErrorCode>;
@@ -0,0 +1,23 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export var APIValidationErrorCode;
4
+ (function (APIValidationErrorCode) {
5
+ APIValidationErrorCode["NoAuthSession"] = "NoAuthSession";
6
+ APIValidationErrorCode["NoRegion"] = "NoRegion";
7
+ APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
8
+ })(APIValidationErrorCode || (APIValidationErrorCode = {}));
9
+ export const validationErrorMap = {
10
+ [APIValidationErrorCode.NoAuthSession]: {
11
+ message: 'Auth session should not be empty.',
12
+ },
13
+ // TODO: re-enable when working in all test environments:
14
+ // [APIValidationErrorCode.NoEndpoint]: {
15
+ // message: 'Missing endpoint',
16
+ // },
17
+ [APIValidationErrorCode.NoRegion]: {
18
+ message: 'Missing region.',
19
+ },
20
+ [APIValidationErrorCode.NoCustomEndpoint]: {
21
+ message: 'Custom endpoint region is present without custom endpoint.',
22
+ },
23
+ };
@@ -0,0 +1,2 @@
1
+ export { resolveConfig } from './resolveConfig';
2
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { resolveConfig } from './resolveConfig';
4
+ export { resolveLibraryOptions } from './resolveLibraryOptions';