@aws-amplify/api-graphql 3.4.12-unstable.7762f1a.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 (116) 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 -0
  13. package/lib/internals/index.js +4 -1
  14. package/lib/internals/v6.d.ts +101 -0
  15. package/lib/internals/v6.js +118 -0
  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 +281 -5
  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 -0
  54. package/lib-esm/internals/index.js +1 -1
  55. package/lib-esm/internals/v6.d.ts +101 -0
  56. package/lib-esm/internals/v6.js +113 -0
  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 +281 -5
  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 -114
  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 +2 -0
  91. package/src/internals/v6.ts +138 -0
  92. package/src/types/PubSub.ts +56 -0
  93. package/src/types/index.ts +378 -8
  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/types/index.js.map +0 -1
  111. package/lib-esm/.tsbuildinfo +0 -3
  112. package/lib-esm/GraphQLAPI.js.map +0 -1
  113. package/lib-esm/index.js.map +0 -1
  114. package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
  115. package/lib-esm/internals/index.js.map +0 -1
  116. 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,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var CONTROL_MSG;
4
+ (function (CONTROL_MSG) {
5
+ CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
6
+ CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
7
+ CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
8
+ CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
9
+ CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
10
+ })(CONTROL_MSG = exports.CONTROL_MSG || (exports.CONTROL_MSG = {}));
11
+ /** @enum {string} */
12
+ var ConnectionState;
13
+ (function (ConnectionState) {
14
+ /*
15
+ * The connection is alive and healthy
16
+ */
17
+ ConnectionState["Connected"] = "Connected";
18
+ /*
19
+ * The connection is alive, but the connection is offline
20
+ */
21
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
22
+ /*
23
+ * The connection has been disconnected while in use
24
+ */
25
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
26
+ /*
27
+ * The connection has been disconnected and the network is offline
28
+ */
29
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
30
+ /*
31
+ * The connection is in the process of connecting
32
+ */
33
+ ConnectionState["Connecting"] = "Connecting";
34
+ /*
35
+ * The connection is not in use and is being disconnected
36
+ */
37
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
38
+ /*
39
+ * The connection is not in use and has been disconnected
40
+ */
41
+ ConnectionState["Disconnected"] = "Disconnected";
42
+ /*
43
+ * The connection is alive, but a keep alive message has been missed
44
+ */
45
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
46
+ })(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
@@ -1,11 +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 };
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';
8
+ /**
9
+ * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
10
+ */
5
11
  export interface GraphQLOptions {
6
12
  query: string | DocumentNode;
7
- variables?: object;
8
- authMode?: keyof typeof GRAPHQL_AUTH_MODE;
13
+ variables?: Record<string, DocumentType>;
14
+ authMode?: GraphQLAuthMode;
9
15
  authToken?: string;
10
16
  /**
11
17
  * @deprecated This property should not be used
@@ -13,12 +19,134 @@ export interface GraphQLOptions {
13
19
  userAgentSuffix?: string;
14
20
  }
15
21
  export interface GraphQLResult<T = object> {
16
- data?: T;
22
+ data: T;
17
23
  errors?: GraphQLError[];
18
24
  extensions?: {
19
25
  [key: string]: any;
20
26
  };
21
27
  }
28
+ declare const queryType: unique symbol;
29
+ export declare type GraphQLQuery<T> = T & {
30
+ readonly [queryType]: 'query';
31
+ };
32
+ export declare type GraphQLSubscription<T> = T & {
33
+ readonly [queryType]: 'subscription';
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;
95
+ /**
96
+ * The return value from a `graphql({query})` call when `query` is a subscription.
97
+ *
98
+ * ```ts
99
+ * // |-- You are here
100
+ * // v
101
+ * const subResult: GraphqlSubscriptionResult<T> = client.graphql({
102
+ * query: onCreateWidget
103
+ * });
104
+ *
105
+ * const sub = subResult.subscribe({
106
+ * //
107
+ * // |-- You are here
108
+ * // v
109
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
110
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
111
+ * }
112
+ * })
113
+ * ```
114
+ */
115
+ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
116
+ /**
117
+ * The shape of messages passed to `next()` from a graphql subscription. E.g.,
118
+ *
119
+ * ```ts
120
+ * const sub = client.graphql({
121
+ * query: onCreateWidget,
122
+ * }).subscribe({
123
+ * //
124
+ * // |-- You are here
125
+ * // v
126
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
127
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
128
+ * }
129
+ * })
130
+ * ```
131
+ */
132
+ export declare type GraphqlSubscriptionMessage<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;
145
+ };
146
+ }
147
+ export declare type AWSAppSyncRealTimeProvider = {
148
+ subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
149
+ };
22
150
  export declare enum GraphQLAuthError {
23
151
  NO_API_KEY = "No api-key configured",
24
152
  NO_CURRENT_USER = "No current user",
@@ -31,3 +159,151 @@ export declare enum GraphQLAuthError {
31
159
  * @see: https://graphql.org/graphql-js/language/#parse
32
160
  */
33
161
  export declare type GraphQLOperation = Source | string;
162
+ /**
163
+ * API V6 `graphql({options})` type that can leverage branded graphql `query`
164
+ * objects and fallback types.
165
+ */
166
+ export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
167
+ query: TYPED_GQL_STRING | DocumentNode;
168
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
169
+ authMode?: GraphQLAuthMode;
170
+ authToken?: string;
171
+ /**
172
+ * @deprecated This property should not be used
173
+ */
174
+ userAgentSuffix?: string;
175
+ }
176
+ /**
177
+ * Result type for `graphql()` operations that don't include any specific
178
+ * type information. The result could be either a `Promise` or `Subscription`.
179
+ *
180
+ * Invoking code should either cast the result or use `?` and `!` operators to
181
+ * navigate the result objects.
182
+ */
183
+ export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
184
+ /**
185
+ * The expected type for `variables` in a V6 `graphql()` operation with
186
+ * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
187
+ */
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;
189
+ /**
190
+ * The expected return type with respect to the given `FALLBACK_TYPE`
191
+ * and `TYPED_GQL_STRING`.
192
+ */
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;
194
+ /**
195
+ * The shape customers can use to provide `T` to `graphql<T>()` to specify both
196
+ * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
197
+ *
198
+ * I.E.,
199
+ *
200
+ * ```ts
201
+ * type MyVariablesType = { ... };
202
+ * type MyResultType = { ... };
203
+ * type MyOperationType = { variables: MyVariablesType, result: MyResultType };
204
+ *
205
+ * const result: MyResultType = graphql<MyOperationType>("graphql string", {
206
+ * variables: {
207
+ * // MyVariablesType
208
+ * }
209
+ * })
210
+ * ```
211
+ */
212
+ export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
213
+ variables: IN;
214
+ result: OUT;
215
+ };
216
+ /**
217
+ * Nominal type for branding generated graphql query operation strings with
218
+ * input and output types.
219
+ *
220
+ * E.g.,
221
+ *
222
+ * ```ts
223
+ * export const getWidget = `...` as GeneratedQuery<
224
+ * GetWidgetQueryVariables,
225
+ * GetWidgetQuery
226
+ * >;
227
+ * ```
228
+ *
229
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
230
+ * assign types to the `variables` and result objects.
231
+ */
232
+ export declare type GeneratedQuery<InputType, OutputType> = string & {
233
+ __generatedQueryInput: InputType;
234
+ __generatedQueryOutput: OutputType;
235
+ };
236
+ /**
237
+ * Nominal type for branding generated graphql mutation operation strings with
238
+ * input and output types.
239
+ *
240
+ * E.g.,
241
+ *
242
+ * ```ts
243
+ * export const createWidget = `...` as GeneratedQuery<
244
+ * CreateWidgetMutationVariables,
245
+ * CreateWidgetMutation
246
+ * >;
247
+ * ```
248
+ *
249
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
250
+ * assign types to the `variables` and result objects.
251
+ */
252
+ export declare type GeneratedMutation<InputType, OutputType> = string & {
253
+ __generatedMutationInput: InputType;
254
+ __generatedMutationOutput: OutputType;
255
+ };
256
+ /**
257
+ * Nominal type for branding generated graphql mutation operation strings with
258
+ * input and output types.
259
+ *
260
+ * E.g.,
261
+ *
262
+ * ```ts
263
+ * export const createWidget = `...` as GeneratedMutation<
264
+ * CreateWidgetMutationVariables,
265
+ * CreateWidgetMutation
266
+ * >;
267
+ * ```
268
+ *
269
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
270
+ * assign types to the `variables` and result objects.
271
+ */
272
+ export declare type GeneratedSubscription<InputType, OutputType> = string & {
273
+ __generatedSubscriptionInput: InputType;
274
+ __generatedSubscriptionOutput: OutputType;
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,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var auth_1 = require("@aws-amplify/auth");
4
- exports.GRAPHQL_AUTH_MODE = auth_1.GRAPHQL_AUTH_MODE;
3
+ var PubSub_1 = require("./PubSub");
4
+ exports.CONTROL_MSG = PubSub_1.CONTROL_MSG;
5
+ exports.ConnectionState = PubSub_1.ConnectionState;
5
6
  var GraphQLAuthError;
6
7
  (function (GraphQLAuthError) {
7
8
  GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
@@ -10,4 +11,4 @@ var GraphQLAuthError;
10
11
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
11
12
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
12
13
  })(GraphQLAuthError = exports.GraphQLAuthError || (exports.GraphQLAuthError = {}));
13
- //# sourceMappingURL=index.js.map
14
+ exports.__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,131 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const rxjs_1 = require("rxjs");
6
+ const PubSub_1 = require("../types/PubSub");
7
+ const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
8
+ exports.CONNECTION_CHANGE = {
9
+ KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
10
+ KEEP_ALIVE: { keepAliveState: 'healthy' },
11
+ CONNECTION_ESTABLISHED: { connectionState: 'connected' },
12
+ CONNECTION_FAILED: {
13
+ intendedConnectionState: 'disconnected',
14
+ connectionState: 'disconnected',
15
+ },
16
+ CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
17
+ OPENING_CONNECTION: {
18
+ intendedConnectionState: 'connected',
19
+ connectionState: 'connecting',
20
+ },
21
+ CLOSED: { connectionState: 'disconnected' },
22
+ ONLINE: { networkState: 'connected' },
23
+ OFFLINE: { networkState: 'disconnected' },
24
+ };
25
+ class ConnectionStateMonitor {
26
+ constructor() {
27
+ this._networkMonitoringSubscription = undefined;
28
+ this._linkedConnectionState = {
29
+ networkState: 'connected',
30
+ connectionState: 'disconnected',
31
+ intendedConnectionState: 'disconnected',
32
+ keepAliveState: 'healthy',
33
+ };
34
+ // Attempt to update the state with the current actual network state
35
+ this._initialNetworkStateSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(({ online }) => {
36
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
37
+ this._initialNetworkStateSubscription?.unsubscribe();
38
+ });
39
+ this._linkedConnectionStateObservable =
40
+ new rxjs_1.Observable(connectionStateObserver => {
41
+ connectionStateObserver.next(this._linkedConnectionState);
42
+ this._linkedConnectionStateObserver = connectionStateObserver;
43
+ });
44
+ }
45
+ /**
46
+ * Turn network state monitoring on if it isn't on already
47
+ */
48
+ enableNetworkMonitoring() {
49
+ // If no initial network state was discovered, stop trying
50
+ this._initialNetworkStateSubscription?.unsubscribe();
51
+ // Maintain the network state based on the reachability monitor
52
+ if (this._networkMonitoringSubscription === undefined) {
53
+ this._networkMonitoringSubscription = ReachabilityMonitor_1.ReachabilityMonitor().subscribe(({ online }) => {
54
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
55
+ });
56
+ }
57
+ }
58
+ /**
59
+ * Turn network state monitoring off if it isn't off already
60
+ */
61
+ disableNetworkMonitoring() {
62
+ this._networkMonitoringSubscription?.unsubscribe();
63
+ this._networkMonitoringSubscription = undefined;
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
+ }
86
+ /*
87
+ * Updates local connection state and emits the full state to the observer.
88
+ */
89
+ record(statusUpdates) {
90
+ // Maintain the network monitor
91
+ if (statusUpdates.intendedConnectionState === 'connected') {
92
+ this.enableNetworkMonitoring();
93
+ }
94
+ else if (statusUpdates.intendedConnectionState === 'disconnected') {
95
+ this.disableNetworkMonitoring();
96
+ }
97
+ // Maintain the socket state
98
+ const newSocketStatus = {
99
+ ...this._linkedConnectionState,
100
+ ...statusUpdates,
101
+ };
102
+ this._linkedConnectionState = { ...newSocketStatus };
103
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
104
+ }
105
+ /*
106
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
107
+ */
108
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
109
+ if (connectionState === 'connected' && networkState === 'disconnected')
110
+ return PubSub_1.ConnectionState.ConnectedPendingNetwork;
111
+ if (connectionState === 'connected' &&
112
+ intendedConnectionState === 'disconnected')
113
+ return PubSub_1.ConnectionState.ConnectedPendingDisconnect;
114
+ if (connectionState === 'disconnected' &&
115
+ intendedConnectionState === 'connected' &&
116
+ networkState === 'disconnected')
117
+ return PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork;
118
+ if (connectionState === 'disconnected' &&
119
+ intendedConnectionState === 'connected')
120
+ return PubSub_1.ConnectionState.ConnectionDisrupted;
121
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy')
122
+ return PubSub_1.ConnectionState.ConnectedPendingKeepAlive;
123
+ // All remaining states directly correspond to the connection state
124
+ if (connectionState === 'connecting')
125
+ return PubSub_1.ConnectionState.Connecting;
126
+ if (connectionState === 'disconnected')
127
+ return PubSub_1.ConnectionState.Disconnected;
128
+ return PubSub_1.ConnectionState.Connected;
129
+ }
130
+ }
131
+ exports.ConnectionStateMonitor = ConnectionStateMonitor;
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => any;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const utils_1 = require("@aws-amplify/core/internals/utils");
6
+ exports.ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor();
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
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);
@@ -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
+ }