@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.
- package/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +25 -30
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
- package/lib/Providers/constants.js +4 -5
- package/lib/index.js +5 -6
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +203 -263
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +5 -8
- package/lib/internals/v6.js +3 -4
- package/lib/tsconfig.tsbuildinfo +6798 -1
- package/lib/types/PubSub.d.ts +2 -2
- package/lib/types/PubSub.js +2 -3
- package/lib/types/index.d.ts +39 -28
- package/lib/types/index.js +3 -4
- package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib/utils/ConnectionStateMonitor.js +51 -65
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.js +2 -4
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
- package/lib/utils/ReconnectionMonitor.js +21 -26
- package/lib/utils/errors/APIError.js +7 -12
- package/lib/utils/errors/assertValidationError.js +4 -5
- package/lib/utils/errors/index.js +4 -5
- package/lib/utils/errors/validation.js +6 -8
- package/lib/utils/index.js +2 -3
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +10 -13
- package/lib/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib/utils/resolveLibraryOptions.js +4 -7
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +25 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js +0 -1
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +6798 -1
- package/lib-esm/types/PubSub.d.ts +2 -2
- package/lib-esm/types/index.d.ts +39 -28
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/lib-esm/utils/errors/APIError.js +6 -11
- package/lib-esm/utils/errors/assertValidationError.js +2 -2
- package/lib-esm/utils/errors/validation.js +5 -6
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/package.json +6 -12
- package/src/GraphQLAPI.ts +6 -1
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/InternalGraphQLAPI.ts +7 -8
- package/src/internals/index.ts +0 -1
- package/src/types/index.ts +39 -15
- package/lib/internals/APIClient.d.ts +0 -101
- package/lib/internals/APIClient.js +0 -443
- package/lib/internals/generateClient.d.ts +0 -12
- package/lib/internals/generateClient.js +0 -30
- package/lib/internals/generateModelsProperty.d.ts +0 -4
- package/lib/internals/generateModelsProperty.js +0 -169
- package/lib/internals/types.d.ts +0 -10
- package/lib/internals/types.js +0 -2
- package/lib/utils/resolveOwnerFields.d.ts +0 -12
- package/lib/utils/resolveOwnerFields.js +0 -63
- package/lib-esm/internals/APIClient.d.ts +0 -101
- package/lib-esm/internals/APIClient.js +0 -432
- package/lib-esm/internals/generateClient.d.ts +0 -12
- package/lib-esm/internals/generateClient.js +0 -26
- package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
- package/lib-esm/internals/generateModelsProperty.js +0 -165
- package/lib-esm/internals/types.d.ts +0 -10
- package/lib-esm/internals/types.js +0 -1
- package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
- package/lib-esm/utils/resolveOwnerFields.js +0 -59
- package/src/internals/APIClient.ts +0 -583
- package/src/internals/generateClient.ts +0 -30
- package/src/internals/generateModelsProperty.ts +0 -192
- package/src/internals/types.ts +0 -15
- 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>;
|
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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>;
|
package/lib-esm/types/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
25
|
-
|
|
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(
|
|
36
|
-
|
|
37
|
-
|
|
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(
|
|
43
|
-
connectionStateObserver.next(
|
|
44
|
-
|
|
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
|
-
|
|
51
|
-
var _this = this;
|
|
52
|
-
var _a;
|
|
46
|
+
enableNetworkMonitoring() {
|
|
53
47
|
// If no initial network state was discovered, stop trying
|
|
54
|
-
|
|
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(
|
|
58
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
141
|
-
}());
|
|
142
|
-
export { ConnectionStateMonitor };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ReachabilityMonitor: () =>
|
|
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
|
|
4
|
+
export const ReachabilityMonitor = () => new Reachability().networkMonitor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ReachabilityMonitor: () =>
|
|
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
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
31
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
33
32
|
// Reconnect now
|
|
34
|
-
|
|
33
|
+
this._triggerReconnect();
|
|
35
34
|
// Retry reconnect every periodically until it works
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
57
|
-
this.reconnectObservers.forEach(
|
|
58
|
-
|
|
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
|
-
|
|
63
|
-
this.reconnectObservers.forEach(
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
Object.setPrototypeOf(
|
|
16
|
-
return _this;
|
|
12
|
+
this.constructor = APIError;
|
|
13
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
17
14
|
}
|
|
18
|
-
|
|
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
|
-
|
|
9
|
+
const { message, recoverySuggestion } = validationErrorMap[name];
|
|
10
10
|
if (!assertion) {
|
|
11
|
-
throw new APIError({ name
|
|
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
|
|
11
|
-
|
|
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
|
-
|
|
17
|
+
[APIValidationErrorCode.NoRegion]: {
|
|
19
18
|
message: 'Missing region.',
|
|
20
19
|
},
|
|
21
|
-
|
|
20
|
+
[APIValidationErrorCode.NoCustomEndpoint]: {
|
|
22
21
|
message: 'Custom endpoint region is present without custom endpoint.',
|
|
23
22
|
},
|
|
24
|
-
|
|
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:
|
|
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
|
|
8
|
-
|
|
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
|
|
15
|
-
customEndpoint
|
|
16
|
-
customEndpointRegion
|
|
17
|
-
defaultAuthMode
|
|
18
|
-
endpoint
|
|
19
|
-
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<
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
};
|