@aws-amplify/api-graphql 4.0.1-server-generate-client.1e317a1.0 → 4.0.1-ssr-api.df60e41.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 (91) hide show
  1. package/lib/GraphQLAPI.d.ts +1 -1
  2. package/lib/GraphQLAPI.js +25 -30
  3. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
  5. package/lib/Providers/constants.js +4 -5
  6. package/lib/index.js +5 -6
  7. package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
  8. package/lib/internals/InternalGraphQLAPI.js +203 -263
  9. package/lib/internals/index.d.ts +0 -1
  10. package/lib/internals/index.js +5 -8
  11. package/lib/internals/v6.js +3 -4
  12. package/lib/tsconfig.tsbuildinfo +6798 -1
  13. package/lib/types/PubSub.d.ts +2 -2
  14. package/lib/types/PubSub.js +2 -3
  15. package/lib/types/index.d.ts +39 -28
  16. package/lib/types/index.js +3 -4
  17. package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
  18. package/lib/utils/ConnectionStateMonitor.js +51 -65
  19. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
  20. package/lib/utils/ReachabilityMonitor/index.js +2 -4
  21. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
  22. package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
  23. package/lib/utils/ReconnectionMonitor.js +21 -26
  24. package/lib/utils/errors/APIError.js +7 -12
  25. package/lib/utils/errors/assertValidationError.js +4 -5
  26. package/lib/utils/errors/index.js +4 -5
  27. package/lib/utils/errors/validation.js +6 -8
  28. package/lib/utils/index.js +2 -3
  29. package/lib/utils/resolveConfig.d.ts +1 -1
  30. package/lib/utils/resolveConfig.js +10 -13
  31. package/lib/utils/resolveLibraryOptions.d.ts +1 -1
  32. package/lib/utils/resolveLibraryOptions.js +4 -7
  33. package/lib-esm/GraphQLAPI.d.ts +1 -1
  34. package/lib-esm/GraphQLAPI.js +25 -29
  35. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
  36. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
  37. package/lib-esm/Providers/constants.js +10 -10
  38. package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
  39. package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
  40. package/lib-esm/internals/index.d.ts +0 -1
  41. package/lib-esm/internals/index.js +0 -1
  42. package/lib-esm/internals/v6.js +1 -1
  43. package/lib-esm/tsconfig.tsbuildinfo +6798 -1
  44. package/lib-esm/types/PubSub.d.ts +2 -2
  45. package/lib-esm/types/index.d.ts +39 -28
  46. package/lib-esm/types/index.js +1 -1
  47. package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
  48. package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
  49. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
  50. package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
  51. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
  52. package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
  53. package/lib-esm/utils/ReconnectionMonitor.js +19 -24
  54. package/lib-esm/utils/errors/APIError.js +6 -11
  55. package/lib-esm/utils/errors/assertValidationError.js +2 -2
  56. package/lib-esm/utils/errors/validation.js +5 -6
  57. package/lib-esm/utils/resolveConfig.d.ts +1 -1
  58. package/lib-esm/utils/resolveConfig.js +8 -9
  59. package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
  60. package/lib-esm/utils/resolveLibraryOptions.js +4 -5
  61. package/package.json +6 -12
  62. package/src/GraphQLAPI.ts +6 -1
  63. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
  64. package/src/internals/InternalGraphQLAPI.ts +7 -8
  65. package/src/internals/index.ts +0 -1
  66. package/src/types/index.ts +39 -15
  67. package/lib/internals/APIClient.d.ts +0 -101
  68. package/lib/internals/APIClient.js +0 -443
  69. package/lib/internals/generateClient.d.ts +0 -12
  70. package/lib/internals/generateClient.js +0 -30
  71. package/lib/internals/generateModelsProperty.d.ts +0 -4
  72. package/lib/internals/generateModelsProperty.js +0 -169
  73. package/lib/internals/types.d.ts +0 -10
  74. package/lib/internals/types.js +0 -2
  75. package/lib/utils/resolveOwnerFields.d.ts +0 -12
  76. package/lib/utils/resolveOwnerFields.js +0 -63
  77. package/lib-esm/internals/APIClient.d.ts +0 -101
  78. package/lib-esm/internals/APIClient.js +0 -432
  79. package/lib-esm/internals/generateClient.d.ts +0 -12
  80. package/lib-esm/internals/generateClient.js +0 -26
  81. package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
  82. package/lib-esm/internals/generateModelsProperty.js +0 -165
  83. package/lib-esm/internals/types.d.ts +0 -10
  84. package/lib-esm/internals/types.js +0 -1
  85. package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
  86. package/lib-esm/utils/resolveOwnerFields.js +0 -59
  87. package/src/internals/APIClient.ts +0 -583
  88. package/src/internals/generateClient.ts +0 -30
  89. package/src/internals/generateModelsProperty.ts +0 -192
  90. package/src/internals/types.ts +0 -15
  91. package/src/utils/resolveOwnerFields.ts +0 -65
@@ -23,5 +23,5 @@ export declare enum ConnectionState {
23
23
  Disconnected = "Disconnected",
24
24
  ConnectedPendingKeepAlive = "ConnectedPendingKeepAlive"
25
25
  }
26
- export type PubSubContent = Record<string, unknown>;
27
- export type PubSubContentObserver = Observer<PubSubContent>;
26
+ export declare type PubSubContent = Record<string, unknown>;
27
+ export declare type PubSubContentObserver = Observer<PubSubContent>;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionState = exports.CONTROL_MSG = void 0;
4
3
  var CONTROL_MSG;
5
4
  (function (CONTROL_MSG) {
6
5
  CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
@@ -8,7 +7,7 @@ var CONTROL_MSG;
8
7
  CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
9
8
  CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
10
9
  CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
11
- })(CONTROL_MSG || (exports.CONTROL_MSG = CONTROL_MSG = {}));
10
+ })(CONTROL_MSG = exports.CONTROL_MSG || (exports.CONTROL_MSG = {}));
12
11
  /** @enum {string} */
13
12
  var ConnectionState;
14
13
  (function (ConnectionState) {
@@ -44,4 +43,4 @@ var ConnectionState;
44
43
  * The connection is alive, but a keep alive message has been missed
45
44
  */
46
45
  ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
47
- })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
46
+ })(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
@@ -1,11 +1,10 @@
1
1
  import { AmplifyClassV6 } from '@aws-amplify/core';
2
- import { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
3
2
  import { Source, DocumentNode, GraphQLError } from 'graphql';
4
3
  export { OperationTypeNode } from 'graphql';
5
4
  import { Observable } from 'rxjs';
6
5
  import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
6
+ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
7
7
  export { CONTROL_MSG, ConnectionState } from './PubSub';
8
- export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
9
8
  /**
10
9
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
11
10
  */
@@ -27,10 +26,10 @@ export interface GraphQLResult<T = object> {
27
26
  };
28
27
  }
29
28
  declare const queryType: unique symbol;
30
- export type GraphQLQuery<T> = T & {
29
+ export declare type GraphQLQuery<T> = T & {
31
30
  readonly [queryType]: 'query';
32
31
  };
33
- export type GraphQLSubscription<T> = T & {
32
+ export declare type GraphQLSubscription<T> = T & {
34
33
  readonly [queryType]: 'subscription';
35
34
  };
36
35
  /**
@@ -54,14 +53,14 @@ export type GraphQLSubscription<T> = T & {
54
53
  *
55
54
  * This util simply makes related model properties optional recursively.
56
55
  */
57
- export type GraphQLReturnType<T> = T extends {} ? {
56
+ export declare type GraphQLReturnType<T> = T extends {} ? {
58
57
  [K in keyof T]?: GraphQLReturnType<T[K]>;
59
58
  } : T;
60
59
  /**
61
60
  * Describes a paged list result from AppSync, which can either
62
61
  * live at the top query or property (e.g., related model) level.
63
62
  */
64
- type PagedList<T, TYPENAME> = {
63
+ declare type PagedList<T, TYPENAME> = {
65
64
  __typename: TYPENAME;
66
65
  nextToken?: string | null | undefined;
67
66
  items: Array<T>;
@@ -74,13 +73,13 @@ type PagedList<T, TYPENAME> = {
74
73
  * array, this will only be the case when we also have errors,
75
74
  * which will then be *thrown*.
76
75
  */
77
- type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
76
+ declare type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
78
77
  [K in keyof T]: WithListsFixed<T[K]>;
79
78
  } : T;
80
79
  /**
81
80
  * Returns an updated response type to always return a value.
82
81
  */
83
- type NeverEmpty<T> = {
82
+ declare type NeverEmpty<T> = {
84
83
  [K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
85
84
  };
86
85
  /**
@@ -90,7 +89,7 @@ type NeverEmpty<T> = {
90
89
  * If empty members are present, there will also be errors present,
91
90
  * and the response will instead be *thrown*.
92
91
  */
93
- type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
92
+ declare type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
94
93
  [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
95
94
  } : T;
96
95
  /**
@@ -113,7 +112,7 @@ type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedLi
113
112
  * })
114
113
  * ```
115
114
  */
116
- export type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
115
+ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
117
116
  /**
118
117
  * The shape of messages passed to `next()` from a graphql subscription. E.g.,
119
118
  *
@@ -130,7 +129,7 @@ export type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage
130
129
  * })
131
130
  * ```
132
131
  */
133
- export type GraphqlSubscriptionMessage<T> = {
132
+ export declare type GraphqlSubscriptionMessage<T> = {
134
133
  data: T;
135
134
  };
136
135
  export interface AWSAppSyncRealTimeProviderOptions {
@@ -145,7 +144,7 @@ export interface AWSAppSyncRealTimeProviderOptions {
145
144
  [key: string]: string;
146
145
  };
147
146
  }
148
- export type AWSAppSyncRealTimeProvider = {
147
+ export declare type AWSAppSyncRealTimeProvider = {
149
148
  subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
150
149
  };
151
150
  export declare enum GraphQLAuthError {
@@ -159,7 +158,7 @@ export declare enum GraphQLAuthError {
159
158
  * GraphQLSource or string, the type of the parameter for calling graphql.parse
160
159
  * @see: https://graphql.org/graphql-js/language/#parse
161
160
  */
162
- export type GraphQLOperation = Source | string;
161
+ export declare type GraphQLOperation = Source | string;
163
162
  /**
164
163
  * API V6 `graphql({options})` type that can leverage branded graphql `query`
165
164
  * objects and fallback types.
@@ -181,17 +180,17 @@ export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING ext
181
180
  * Invoking code should either cast the result or use `?` and `!` operators to
182
181
  * navigate the result objects.
183
182
  */
184
- export type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
183
+ export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
185
184
  /**
186
185
  * The expected type for `variables` in a V6 `graphql()` operation with
187
186
  * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
188
187
  */
189
- export 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;
188
+ 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;
190
189
  /**
191
190
  * The expected return type with respect to the given `FALLBACK_TYPE`
192
191
  * and `TYPED_GQL_STRING`.
193
192
  */
194
- export 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;
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;
195
194
  /**
196
195
  * The shape customers can use to provide `T` to `graphql<T>()` to specify both
197
196
  * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
@@ -210,7 +209,7 @@ export type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends
210
209
  * })
211
210
  * ```
212
211
  */
213
- export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
212
+ export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
214
213
  variables: IN;
215
214
  result: OUT;
216
215
  };
@@ -230,7 +229,7 @@ export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
230
229
  * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
231
230
  * assign types to the `variables` and result objects.
232
231
  */
233
- export type GeneratedQuery<InputType, OutputType> = string & {
232
+ export declare type GeneratedQuery<InputType, OutputType> = string & {
234
233
  __generatedQueryInput: InputType;
235
234
  __generatedQueryOutput: OutputType;
236
235
  };
@@ -250,7 +249,7 @@ export type GeneratedQuery<InputType, OutputType> = string & {
250
249
  * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
251
250
  * assign types to the `variables` and result objects.
252
251
  */
253
- export type GeneratedMutation<InputType, OutputType> = string & {
252
+ export declare type GeneratedMutation<InputType, OutputType> = string & {
254
253
  __generatedMutationInput: InputType;
255
254
  __generatedMutationOutput: OutputType;
256
255
  };
@@ -270,23 +269,35 @@ export type GeneratedMutation<InputType, OutputType> = string & {
270
269
  * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
271
270
  * assign types to the `variables` and result objects.
272
271
  */
273
- export type GeneratedSubscription<InputType, OutputType> = string & {
272
+ export declare type GeneratedSubscription<InputType, OutputType> = string & {
274
273
  __generatedSubscriptionInput: InputType;
275
274
  __generatedSubscriptionOutput: OutputType;
276
275
  };
277
- type FilteredKeys<T> = {
276
+ declare type FilteredKeys<T> = {
278
277
  [P in keyof T]: T[P] extends never ? never : P;
279
278
  }[keyof T];
280
- type ExcludeNeverFields<O> = {
279
+ declare type ExcludeNeverFields<O> = {
281
280
  [K in FilteredKeys<O>]: O[K];
282
281
  };
283
282
  export declare const __amplify: unique symbol;
284
- export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
285
- [__amplify]: AmplifyClassV6 | (() => Promise<AmplifyClassV6>);
286
- graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
287
- [key: string]: string;
288
- } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
283
+ /**
284
+ * TODO: Refactor these 2. Pull out `graphQL` into its own type
285
+ */
286
+ export declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
287
+ [__amplify]: AmplifyClassV6;
288
+ graphql: GraphQLMethod;
289
+ cancel: (promise: Promise<any>, message?: string) => boolean;
290
+ isCancelError: (error: any) => boolean;
291
+ }>;
292
+ export declare type V6ClientSSR<T extends Record<any, any> = never> = ExcludeNeverFields<{
293
+ [__amplify]: AmplifyClassV6;
294
+ graphql: GraphQLMethodSSR;
289
295
  cancel: (promise: Promise<any>, message?: string) => boolean;
290
296
  isCancelError: (error: any) => boolean;
291
- models: ModelTypes<T>;
292
297
  }>;
298
+ export declare type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
299
+ [key: string]: string;
300
+ } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
301
+ export declare type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
302
+ [key: string]: string;
303
+ } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__amplify = exports.GraphQLAuthError = exports.ConnectionState = exports.CONTROL_MSG = void 0;
4
3
  var PubSub_1 = require("./PubSub");
5
- Object.defineProperty(exports, "CONTROL_MSG", { enumerable: true, get: function () { return PubSub_1.CONTROL_MSG; } });
6
- Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return PubSub_1.ConnectionState; } });
4
+ exports.CONTROL_MSG = PubSub_1.CONTROL_MSG;
5
+ exports.ConnectionState = PubSub_1.ConnectionState;
7
6
  var GraphQLAuthError;
8
7
  (function (GraphQLAuthError) {
9
8
  GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
@@ -11,5 +10,5 @@ var GraphQLAuthError;
11
10
  GraphQLAuthError["NO_CREDENTIALS"] = "No credentials";
12
11
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
13
12
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
14
- })(GraphQLAuthError || (exports.GraphQLAuthError = GraphQLAuthError = {}));
13
+ })(GraphQLAuthError = exports.GraphQLAuthError || (exports.GraphQLAuthError = {}));
15
14
  exports.__amplify = Symbol('amplify');
@@ -1,8 +1,8 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { ConnectionState } from '../types/PubSub';
3
- type LinkedConnectionState = 'connected' | 'disconnected';
4
- type LinkedHealthState = 'healthy' | 'unhealthy';
5
- type LinkedConnectionStates = {
3
+ declare type LinkedConnectionState = 'connected' | 'disconnected';
4
+ declare type LinkedHealthState = 'healthy' | 'unhealthy';
5
+ declare type LinkedConnectionStates = {
6
6
  networkState: LinkedConnectionState;
7
7
  connectionState: LinkedConnectionState | 'connecting';
8
8
  intendedConnectionState: LinkedConnectionState;
@@ -2,11 +2,9 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.ConnectionStateMonitor = exports.CONNECTION_CHANGE = void 0;
6
- var tslib_1 = require("tslib");
7
- var rxjs_1 = require("rxjs");
8
- var PubSub_1 = require("../types/PubSub");
9
- var ReachabilityMonitor_1 = require("./ReachabilityMonitor");
5
+ const rxjs_1 = require("rxjs");
6
+ const PubSub_1 = require("../types/PubSub");
7
+ const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
10
8
  exports.CONNECTION_CHANGE = {
11
9
  KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
12
10
  KEEP_ALIVE: { keepAliveState: 'healthy' },
@@ -24,9 +22,8 @@ exports.CONNECTION_CHANGE = {
24
22
  ONLINE: { networkState: 'connected' },
25
23
  OFFLINE: { networkState: 'disconnected' },
26
24
  };
27
- var ConnectionStateMonitor = /** @class */ (function () {
28
- function ConnectionStateMonitor() {
29
- var _this = this;
25
+ class ConnectionStateMonitor {
26
+ constructor() {
30
27
  this._networkMonitoringSubscription = undefined;
31
28
  this._linkedConnectionState = {
32
29
  networkState: 'connected',
@@ -35,73 +32,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
35
32
  keepAliveState: 'healthy',
36
33
  };
37
34
  // Attempt to update the state with the current actual network state
38
- this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(function (_a) {
39
- var _b;
40
- var online = _a.online;
41
- _this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
42
- (_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
35
+ this._initialNetworkStateSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(({ online }) => {
36
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
37
+ this._initialNetworkStateSubscription?.unsubscribe();
43
38
  });
44
39
  this._linkedConnectionStateObservable =
45
- new rxjs_1.Observable(function (connectionStateObserver) {
46
- connectionStateObserver.next(_this._linkedConnectionState);
47
- _this._linkedConnectionStateObserver = connectionStateObserver;
40
+ new rxjs_1.Observable(connectionStateObserver => {
41
+ connectionStateObserver.next(this._linkedConnectionState);
42
+ this._linkedConnectionStateObserver = connectionStateObserver;
48
43
  });
49
44
  }
50
45
  /**
51
46
  * Turn network state monitoring on if it isn't on already
52
47
  */
53
- ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
54
- var _this = this;
55
- var _a;
48
+ enableNetworkMonitoring() {
56
49
  // If no initial network state was discovered, stop trying
57
- (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
50
+ this._initialNetworkStateSubscription?.unsubscribe();
58
51
  // Maintain the network state based on the reachability monitor
59
52
  if (this._networkMonitoringSubscription === undefined) {
60
- this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(function (_a) {
61
- var online = _a.online;
62
- _this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
53
+ this._networkMonitoringSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(({ online }) => {
54
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
63
55
  });
64
56
  }
65
- };
57
+ }
66
58
  /**
67
59
  * Turn network state monitoring off if it isn't off already
68
60
  */
69
- ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
70
- var _a;
71
- (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
61
+ disableNetworkMonitoring() {
62
+ this._networkMonitoringSubscription?.unsubscribe();
72
63
  this._networkMonitoringSubscription = undefined;
73
- };
74
- Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
75
- /**
76
- * Get the observable that allows us to monitor the connection state
77
- *
78
- * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
79
- */
80
- get: function () {
81
- var _this = this;
82
- var previous;
83
- // The linked state aggregates state changes to any of the network, connection,
84
- // intendedConnection and keepAliveHealth. Some states will change these independent
85
- // states without changing the overall connection state.
86
- // After translating from linked states to ConnectionState, then remove any duplicates
87
- return this._linkedConnectionStateObservable
88
- .pipe((0, rxjs_1.map)(function (value) {
89
- return _this.connectionStatesTranslator(value);
90
- }))
91
- .pipe((0, rxjs_1.filter)(function (current) {
92
- var toInclude = current !== previous;
93
- previous = current;
94
- return toInclude;
95
- }));
96
- },
97
- enumerable: false,
98
- configurable: true
99
- });
64
+ }
65
+ /**
66
+ * Get the observable that allows us to monitor the connection state
67
+ *
68
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
69
+ */
70
+ get connectionStateObservable() {
71
+ let previous;
72
+ // The linked state aggregates state changes to any of the network, connection,
73
+ // intendedConnection and keepAliveHealth. Some states will change these independent
74
+ // states without changing the overall connection state.
75
+ // After translating from linked states to ConnectionState, then remove any duplicates
76
+ return this._linkedConnectionStateObservable
77
+ .pipe(rxjs_1.map(value => {
78
+ return this.connectionStatesTranslator(value);
79
+ }))
80
+ .pipe(rxjs_1.filter(current => {
81
+ const toInclude = current !== previous;
82
+ previous = current;
83
+ return toInclude;
84
+ }));
85
+ }
100
86
  /*
101
87
  * Updates local connection state and emits the full state to the observer.
102
88
  */
103
- ConnectionStateMonitor.prototype.record = function (statusUpdates) {
104
- var _a;
89
+ record(statusUpdates) {
105
90
  // Maintain the network monitor
106
91
  if (statusUpdates.intendedConnectionState === 'connected') {
107
92
  this.enableNetworkMonitoring();
@@ -110,15 +95,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
110
95
  this.disableNetworkMonitoring();
111
96
  }
112
97
  // Maintain the socket state
113
- var newSocketStatus = tslib_1.__assign(tslib_1.__assign({}, this._linkedConnectionState), statusUpdates);
114
- this._linkedConnectionState = tslib_1.__assign({}, newSocketStatus);
115
- (_a = this._linkedConnectionStateObserver) === null || _a === void 0 ? void 0 : _a.next(this._linkedConnectionState);
116
- };
98
+ const newSocketStatus = {
99
+ ...this._linkedConnectionState,
100
+ ...statusUpdates,
101
+ };
102
+ this._linkedConnectionState = { ...newSocketStatus };
103
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
104
+ }
117
105
  /*
118
106
  * Translate the ConnectionState structure into a specific ConnectionState string literal union
119
107
  */
120
- ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
121
- var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
108
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
122
109
  if (connectionState === 'connected' && networkState === 'disconnected')
123
110
  return PubSub_1.ConnectionState.ConnectedPendingNetwork;
124
111
  if (connectionState === 'connected' &&
@@ -139,7 +126,6 @@ var ConnectionStateMonitor = /** @class */ (function () {
139
126
  if (connectionState === 'disconnected')
140
127
  return PubSub_1.ConnectionState.Disconnected;
141
128
  return PubSub_1.ConnectionState.Connected;
142
- };
143
- return ConnectionStateMonitor;
144
- }());
129
+ }
130
+ }
145
131
  exports.ConnectionStateMonitor = ConnectionStateMonitor;
@@ -1 +1 @@
1
- export declare const ReachabilityMonitor: () => import("rxjs").Observable<import("@aws-amplify/core/lib-esm/Reachability/types").NetworkStatus>;
1
+ export declare const ReachabilityMonitor: () => any;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReachabilityMonitor = void 0;
4
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
4
  // SPDX-License-Identifier: Apache-2.0
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var ReachabilityMonitor = function () { return new utils_1.Reachability().networkMonitor(); };
8
- exports.ReachabilityMonitor = ReachabilityMonitor;
5
+ const utils_1 = require("@aws-amplify/core/internals/utils");
6
+ exports.ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor();
@@ -1 +1 @@
1
- export declare const ReachabilityMonitor: () => import("rxjs").Observable<import("@aws-amplify/core/lib-esm/Reachability/types").NetworkStatus>;
1
+ export declare const ReachabilityMonitor: () => any;
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReachabilityMonitor = void 0;
4
- var tslib_1 = require("tslib");
3
+ const tslib_1 = require("tslib");
5
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
5
  // SPDX-License-Identifier: Apache-2.0
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
9
- var ReachabilityMonitor = function () {
10
- return new utils_1.Reachability().networkMonitor(netinfo_1.default);
11
- };
12
- exports.ReachabilityMonitor = ReachabilityMonitor;
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
8
+ exports.ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor(netinfo_1.default);
@@ -1,43 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReconnectionMonitor = exports.ReconnectEvent = void 0;
4
- var constants_1 = require("../Providers/constants");
3
+ const constants_1 = require("../Providers/constants");
5
4
  var ReconnectEvent;
6
5
  (function (ReconnectEvent) {
7
6
  ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
8
7
  ReconnectEvent["HALT_RECONNECT"] = "HALT_RECONNECT";
9
- })(ReconnectEvent || (exports.ReconnectEvent = ReconnectEvent = {}));
8
+ })(ReconnectEvent = exports.ReconnectEvent || (exports.ReconnectEvent = {}));
10
9
  /**
11
10
  * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
12
11
  * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
13
12
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
14
13
  * supported by the browser, so this keeps retrying every minute until halted.
15
14
  */
16
- var ReconnectionMonitor = /** @class */ (function () {
17
- function ReconnectionMonitor() {
15
+ class ReconnectionMonitor {
16
+ constructor() {
18
17
  this.reconnectObservers = [];
19
18
  }
20
19
  /**
21
20
  * Add reconnect observer to the list of observers to alert on reconnect
22
21
  */
23
- ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
22
+ addObserver(reconnectObserver) {
24
23
  this.reconnectObservers.push(reconnectObserver);
25
- };
24
+ }
26
25
  /**
27
26
  * Given a reconnect event, start the appropriate behavior
28
27
  */
29
- ReconnectionMonitor.prototype.record = function (event) {
30
- var _this = this;
28
+ record(event) {
31
29
  if (event === ReconnectEvent.START_RECONNECT) {
32
30
  // If the reconnection hasn't been started
33
31
  if (this.reconnectSetTimeoutId === undefined &&
34
32
  this.reconnectIntervalId === undefined) {
35
- this.reconnectSetTimeoutId = setTimeout(function () {
33
+ this.reconnectSetTimeoutId = setTimeout(() => {
36
34
  // Reconnect now
37
- _this._triggerReconnect();
35
+ this._triggerReconnect();
38
36
  // Retry reconnect every periodically until it works
39
- _this.reconnectIntervalId = setInterval(function () {
40
- _this._triggerReconnect();
37
+ this.reconnectIntervalId = setInterval(() => {
38
+ this._triggerReconnect();
41
39
  }, constants_1.RECONNECT_INTERVAL);
42
40
  }, constants_1.RECONNECT_DELAY);
43
41
  }
@@ -52,22 +50,19 @@ var ReconnectionMonitor = /** @class */ (function () {
52
50
  this.reconnectSetTimeoutId = undefined;
53
51
  }
54
52
  }
55
- };
53
+ }
56
54
  /**
57
55
  * Complete all reconnect observers
58
56
  */
59
- ReconnectionMonitor.prototype.close = function () {
60
- this.reconnectObservers.forEach(function (reconnectObserver) {
61
- var _a;
62
- (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
57
+ close() {
58
+ this.reconnectObservers.forEach(reconnectObserver => {
59
+ reconnectObserver.complete?.();
63
60
  });
64
- };
65
- ReconnectionMonitor.prototype._triggerReconnect = function () {
66
- this.reconnectObservers.forEach(function (reconnectObserver) {
67
- var _a;
68
- (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
61
+ }
62
+ _triggerReconnect() {
63
+ this.reconnectObservers.forEach(reconnectObserver => {
64
+ reconnectObserver.next?.();
69
65
  });
70
- };
71
- return ReconnectionMonitor;
72
- }());
66
+ }
67
+ }
73
68
  exports.ReconnectionMonitor = ReconnectionMonitor;
@@ -2,22 +2,17 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.APIError = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
5
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
6
  /**
9
7
  * @internal
10
8
  */
11
- var APIError = /** @class */ (function (_super) {
12
- tslib_1.__extends(APIError, _super);
13
- function APIError(params) {
14
- var _this = _super.call(this, params) || this;
9
+ class APIError extends utils_1.AmplifyError {
10
+ constructor(params) {
11
+ super(params);
15
12
  // Hack for making the custom error class work when transpiled to es5
16
13
  // TODO: Delete the following 2 lines after we change the build target to >= es2015
17
- _this.constructor = APIError;
18
- Object.setPrototypeOf(_this, APIError.prototype);
19
- return _this;
14
+ this.constructor = APIError;
15
+ Object.setPrototypeOf(this, APIError.prototype);
20
16
  }
21
- return APIError;
22
- }(utils_1.AmplifyError));
17
+ }
23
18
  exports.APIError = APIError;
@@ -2,16 +2,15 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.assertValidationError = void 0;
6
- var APIError_1 = require("./APIError");
7
- var validation_1 = require("./validation");
5
+ const APIError_1 = require("./APIError");
6
+ const validation_1 = require("./validation");
8
7
  /**
9
8
  * @internal
10
9
  */
11
10
  function assertValidationError(assertion, name) {
12
- var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
11
+ const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
13
12
  if (!assertion) {
14
- throw new APIError_1.APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
13
+ throw new APIError_1.APIError({ name, message, recoverySuggestion });
15
14
  }
16
15
  }
17
16
  exports.assertValidationError = assertValidationError;
@@ -2,11 +2,10 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.validationErrorMap = exports.APIValidationErrorCode = exports.assertValidationError = exports.APIError = void 0;
6
5
  var APIError_1 = require("./APIError");
7
- Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return APIError_1.APIError; } });
6
+ exports.APIError = APIError_1.APIError;
8
7
  var assertValidationError_1 = require("./assertValidationError");
9
- Object.defineProperty(exports, "assertValidationError", { enumerable: true, get: function () { return assertValidationError_1.assertValidationError; } });
8
+ exports.assertValidationError = assertValidationError_1.assertValidationError;
10
9
  var validation_1 = require("./validation");
11
- Object.defineProperty(exports, "APIValidationErrorCode", { enumerable: true, get: function () { return validation_1.APIValidationErrorCode; } });
12
- Object.defineProperty(exports, "validationErrorMap", { enumerable: true, get: function () { return validation_1.validationErrorMap; } });
10
+ exports.APIValidationErrorCode = validation_1.APIValidationErrorCode;
11
+ exports.validationErrorMap = validation_1.validationErrorMap;