@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,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>;
@@ -7,4 +7,4 @@ export var GraphQLAuthError;
7
7
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
8
8
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
9
9
  })(GraphQLAuthError || (GraphQLAuthError = {}));
10
- export var __amplify = Symbol('amplify');
10
+ export const __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;
@@ -1,10 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { __assign } from "tslib";
4
3
  import { Observable, map, filter } from 'rxjs';
5
4
  import { ConnectionState } from '../types/PubSub';
6
5
  import { ReachabilityMonitor } from './ReachabilityMonitor';
7
- export var CONNECTION_CHANGE = {
6
+ export const CONNECTION_CHANGE = {
8
7
  KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
9
8
  KEEP_ALIVE: { keepAliveState: 'healthy' },
10
9
  CONNECTION_ESTABLISHED: { connectionState: 'connected' },
@@ -21,9 +20,8 @@ export var CONNECTION_CHANGE = {
21
20
  ONLINE: { networkState: 'connected' },
22
21
  OFFLINE: { networkState: 'disconnected' },
23
22
  };
24
- var ConnectionStateMonitor = /** @class */ (function () {
25
- function ConnectionStateMonitor() {
26
- var _this = this;
23
+ export class ConnectionStateMonitor {
24
+ constructor() {
27
25
  this._networkMonitoringSubscription = undefined;
28
26
  this._linkedConnectionState = {
29
27
  networkState: 'connected',
@@ -32,73 +30,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
32
30
  keepAliveState: 'healthy',
33
31
  };
34
32
  // Attempt to update the state with the current actual network state
35
- this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(function (_a) {
36
- var _b;
37
- var online = _a.online;
38
- _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
39
- (_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
33
+ this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(({ online }) => {
34
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
35
+ this._initialNetworkStateSubscription?.unsubscribe();
40
36
  });
41
37
  this._linkedConnectionStateObservable =
42
- new Observable(function (connectionStateObserver) {
43
- connectionStateObserver.next(_this._linkedConnectionState);
44
- _this._linkedConnectionStateObserver = connectionStateObserver;
38
+ new Observable(connectionStateObserver => {
39
+ connectionStateObserver.next(this._linkedConnectionState);
40
+ this._linkedConnectionStateObserver = connectionStateObserver;
45
41
  });
46
42
  }
47
43
  /**
48
44
  * Turn network state monitoring on if it isn't on already
49
45
  */
50
- ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
51
- var _this = this;
52
- var _a;
46
+ enableNetworkMonitoring() {
53
47
  // If no initial network state was discovered, stop trying
54
- (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
48
+ this._initialNetworkStateSubscription?.unsubscribe();
55
49
  // Maintain the network state based on the reachability monitor
56
50
  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);
51
+ this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(({ online }) => {
52
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
60
53
  });
61
54
  }
62
- };
55
+ }
63
56
  /**
64
57
  * Turn network state monitoring off if it isn't off already
65
58
  */
66
- ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
67
- var _a;
68
- (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
59
+ disableNetworkMonitoring() {
60
+ this._networkMonitoringSubscription?.unsubscribe();
69
61
  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
- .pipe(map(function (value) {
86
- return _this.connectionStatesTranslator(value);
87
- }))
88
- .pipe(filter(function (current) {
89
- var toInclude = current !== previous;
90
- previous = current;
91
- return toInclude;
92
- }));
93
- },
94
- enumerable: false,
95
- configurable: true
96
- });
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
+ }
97
84
  /*
98
85
  * Updates local connection state and emits the full state to the observer.
99
86
  */
100
- ConnectionStateMonitor.prototype.record = function (statusUpdates) {
101
- var _a;
87
+ record(statusUpdates) {
102
88
  // Maintain the network monitor
103
89
  if (statusUpdates.intendedConnectionState === 'connected') {
104
90
  this.enableNetworkMonitoring();
@@ -107,15 +93,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
107
93
  this.disableNetworkMonitoring();
108
94
  }
109
95
  // Maintain the socket state
110
- var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
111
- this._linkedConnectionState = __assign({}, newSocketStatus);
112
- (_a = this._linkedConnectionStateObserver) === null || _a === void 0 ? void 0 : _a.next(this._linkedConnectionState);
113
- };
96
+ const newSocketStatus = {
97
+ ...this._linkedConnectionState,
98
+ ...statusUpdates,
99
+ };
100
+ this._linkedConnectionState = { ...newSocketStatus };
101
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
102
+ }
114
103
  /*
115
104
  * Translate the ConnectionState structure into a specific ConnectionState string literal union
116
105
  */
117
- ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
118
- var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
106
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
119
107
  if (connectionState === 'connected' && networkState === 'disconnected')
120
108
  return ConnectionState.ConnectedPendingNetwork;
121
109
  if (connectionState === 'connected' &&
@@ -136,7 +124,5 @@ var ConnectionStateMonitor = /** @class */ (function () {
136
124
  if (connectionState === 'disconnected')
137
125
  return ConnectionState.Disconnected;
138
126
  return ConnectionState.Connected;
139
- };
140
- return ConnectionStateMonitor;
141
- }());
142
- export { ConnectionStateMonitor };
127
+ }
128
+ }
@@ -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,4 +1,4 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Reachability } from '@aws-amplify/core/internals/utils';
4
- export var ReachabilityMonitor = function () { return new Reachability().networkMonitor(); };
4
+ export const ReachabilityMonitor = () => new 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;
@@ -2,6 +2,4 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Reachability } from '@aws-amplify/core/internals/utils';
4
4
  import { default as NetInfo } from '@react-native-community/netinfo';
5
- export var ReachabilityMonitor = function () {
6
- return new Reachability().networkMonitor(NetInfo);
7
- };
5
+ export const ReachabilityMonitor = () => new Reachability().networkMonitor(NetInfo);
@@ -10,31 +10,30 @@ export var ReconnectEvent;
10
10
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
11
11
  * supported by the browser, so this keeps retrying every minute until halted.
12
12
  */
13
- var ReconnectionMonitor = /** @class */ (function () {
14
- function ReconnectionMonitor() {
13
+ export class ReconnectionMonitor {
14
+ constructor() {
15
15
  this.reconnectObservers = [];
16
16
  }
17
17
  /**
18
18
  * Add reconnect observer to the list of observers to alert on reconnect
19
19
  */
20
- ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
20
+ addObserver(reconnectObserver) {
21
21
  this.reconnectObservers.push(reconnectObserver);
22
- };
22
+ }
23
23
  /**
24
24
  * Given a reconnect event, start the appropriate behavior
25
25
  */
26
- ReconnectionMonitor.prototype.record = function (event) {
27
- var _this = this;
26
+ record(event) {
28
27
  if (event === ReconnectEvent.START_RECONNECT) {
29
28
  // If the reconnection hasn't been started
30
29
  if (this.reconnectSetTimeoutId === undefined &&
31
30
  this.reconnectIntervalId === undefined) {
32
- this.reconnectSetTimeoutId = setTimeout(function () {
31
+ this.reconnectSetTimeoutId = setTimeout(() => {
33
32
  // Reconnect now
34
- _this._triggerReconnect();
33
+ this._triggerReconnect();
35
34
  // Retry reconnect every periodically until it works
36
- _this.reconnectIntervalId = setInterval(function () {
37
- _this._triggerReconnect();
35
+ this.reconnectIntervalId = setInterval(() => {
36
+ this._triggerReconnect();
38
37
  }, RECONNECT_INTERVAL);
39
38
  }, RECONNECT_DELAY);
40
39
  }
@@ -49,22 +48,18 @@ var ReconnectionMonitor = /** @class */ (function () {
49
48
  this.reconnectSetTimeoutId = undefined;
50
49
  }
51
50
  }
52
- };
51
+ }
53
52
  /**
54
53
  * Complete all reconnect observers
55
54
  */
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);
55
+ close() {
56
+ this.reconnectObservers.forEach(reconnectObserver => {
57
+ reconnectObserver.complete?.();
60
58
  });
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);
59
+ }
60
+ _triggerReconnect() {
61
+ this.reconnectObservers.forEach(reconnectObserver => {
62
+ reconnectObserver.next?.();
66
63
  });
67
- };
68
- return ReconnectionMonitor;
69
- }());
70
- export { ReconnectionMonitor };
64
+ }
65
+ }
@@ -1,20 +1,15 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { __extends } from "tslib";
4
3
  import { AmplifyError, } from '@aws-amplify/core/internals/utils';
5
4
  /**
6
5
  * @internal
7
6
  */
8
- var APIError = /** @class */ (function (_super) {
9
- __extends(APIError, _super);
10
- function APIError(params) {
11
- var _this = _super.call(this, params) || this;
7
+ export class APIError extends AmplifyError {
8
+ constructor(params) {
9
+ super(params);
12
10
  // Hack for making the custom error class work when transpiled to es5
13
11
  // 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;
12
+ this.constructor = APIError;
13
+ Object.setPrototypeOf(this, APIError.prototype);
17
14
  }
18
- return APIError;
19
- }(AmplifyError));
20
- export { APIError };
15
+ }
@@ -6,8 +6,8 @@ import { validationErrorMap } from './validation';
6
6
  * @internal
7
7
  */
8
8
  export function assertValidationError(assertion, name) {
9
- var _a = validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
9
+ const { message, recoverySuggestion } = validationErrorMap[name];
10
10
  if (!assertion) {
11
- throw new APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
11
+ throw new APIError({ name, message, recoverySuggestion });
12
12
  }
13
13
  }
@@ -1,24 +1,23 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- var _a;
4
3
  export var APIValidationErrorCode;
5
4
  (function (APIValidationErrorCode) {
6
5
  APIValidationErrorCode["NoAuthSession"] = "NoAuthSession";
7
6
  APIValidationErrorCode["NoRegion"] = "NoRegion";
8
7
  APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
9
8
  })(APIValidationErrorCode || (APIValidationErrorCode = {}));
10
- export var validationErrorMap = (_a = {},
11
- _a[APIValidationErrorCode.NoAuthSession] = {
9
+ export const validationErrorMap = {
10
+ [APIValidationErrorCode.NoAuthSession]: {
12
11
  message: 'Auth session should not be empty.',
13
12
  },
14
13
  // TODO: re-enable when working in all test environments:
15
14
  // [APIValidationErrorCode.NoEndpoint]: {
16
15
  // message: 'Missing endpoint',
17
16
  // },
18
- _a[APIValidationErrorCode.NoRegion] = {
17
+ [APIValidationErrorCode.NoRegion]: {
19
18
  message: 'Missing region.',
20
19
  },
21
- _a[APIValidationErrorCode.NoCustomEndpoint] = {
20
+ [APIValidationErrorCode.NoCustomEndpoint]: {
22
21
  message: 'Custom endpoint region is present without custom endpoint.',
23
22
  },
24
- _a);
23
+ };
@@ -6,7 +6,7 @@ export declare const resolveConfig: (amplify: AmplifyClassV6) => {
6
6
  apiKey: string | undefined;
7
7
  customEndpoint: string | undefined;
8
8
  customEndpointRegion: string | undefined;
9
- defaultAuthMode: import("@aws-amplify/core/lib-esm/libraryUtils").GraphQLAuthMode | undefined;
9
+ defaultAuthMode: "apiKey" | "oidc" | "userPool" | "iam" | "lambda" | "none" | undefined;
10
10
  endpoint: string | undefined;
11
11
  region: string | undefined;
12
12
  };
@@ -4,18 +4,17 @@ import { APIValidationErrorCode, assertValidationError } from './errors';
4
4
  /**
5
5
  * @internal
6
6
  */
7
- export var resolveConfig = function (amplify) {
8
- var _a, _b;
9
- var _c = (_b = (_a = amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, apiKey = _c.apiKey, customEndpoint = _c.customEndpoint, customEndpointRegion = _c.customEndpointRegion, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint, region = _c.region;
7
+ export const resolveConfig = (amplify) => {
8
+ const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = amplify.getConfig().API?.GraphQL ?? {};
10
9
  // TODO: re-enable when working in all test environments:
11
10
  // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
12
11
  assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);
13
12
  return {
14
- apiKey: apiKey,
15
- customEndpoint: customEndpoint,
16
- customEndpointRegion: customEndpointRegion,
17
- defaultAuthMode: defaultAuthMode,
18
- endpoint: endpoint,
19
- region: region,
13
+ apiKey,
14
+ customEndpoint,
15
+ customEndpointRegion,
16
+ defaultAuthMode,
17
+ endpoint,
18
+ region,
20
19
  };
21
20
  };
@@ -6,6 +6,6 @@ export declare const resolveLibraryOptions: (amplify: AmplifyClassV6) => {
6
6
  headers: ((options: {
7
7
  query: string;
8
8
  variables?: Record<string, import("@aws-amplify/core/lib-esm/libraryUtils").DocumentType> | undefined;
9
- }) => Promise<import("@aws-amplify/core/lib-esm/clients").Headers>) | undefined;
9
+ }) => Promise<Record<string, string>>) | undefined;
10
10
  withCredentials: boolean | undefined;
11
11
  };
@@ -3,9 +3,8 @@
3
3
  /**
4
4
  * @internal
5
5
  */
6
- export var resolveLibraryOptions = function (amplify) {
7
- var _a, _b, _c, _d, _e, _f;
8
- var headers = (_c = (_b = (_a = amplify.libraryOptions) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.GraphQL) === null || _c === void 0 ? void 0 : _c.headers;
9
- var withCredentials = (_f = (_e = (_d = amplify.libraryOptions) === null || _d === void 0 ? void 0 : _d.API) === null || _e === void 0 ? void 0 : _e.GraphQL) === null || _f === void 0 ? void 0 : _f.withCredentials;
10
- return { headers: headers, withCredentials: withCredentials };
6
+ export const resolveLibraryOptions = (amplify) => {
7
+ const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
8
+ const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
9
+ return { headers, withCredentials };
11
10
  };