@aws-amplify/api-graphql 4.0.1-api-v6-models.9351bcf.0 → 4.0.1-api-v6-models.891fe0d.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/internals/server/package.json +8 -0
- package/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +23 -28
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +467 -582
- package/lib/index.js +1 -1
- package/lib/internals/APIClient.d.ts +16 -1
- package/lib/internals/APIClient.js +232 -206
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +205 -247
- package/lib/internals/generateClient.js +14 -13
- package/lib/internals/generateModelsProperty.js +19 -312
- package/lib/internals/operations/get.d.ts +2 -0
- package/lib/internals/operations/get.js +59 -0
- package/lib/internals/operations/list.d.ts +2 -0
- package/lib/internals/operations/list.js +71 -0
- package/lib/internals/operations/observeQuery.d.ts +2 -0
- package/lib/internals/operations/observeQuery.js +119 -0
- package/lib/internals/operations/subscription.d.ts +1 -0
- package/lib/internals/operations/subscription.js +27 -0
- package/lib/internals/server/generateClient.d.ts +11 -0
- package/lib/internals/server/generateClient.js +30 -0
- package/lib/internals/server/generateModelsProperty.d.ts +3 -0
- package/lib/internals/server/generateModelsProperty.js +45 -0
- package/lib/internals/server/index.d.ts +1 -0
- package/lib/internals/server/index.js +7 -0
- package/lib/internals/v6.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +36 -4
- package/lib/utils/ConnectionStateMonitor.js +51 -64
- package/lib/utils/ReachabilityMonitor/index.js +2 -2
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
- package/lib/utils/ReconnectionMonitor.js +20 -24
- package/lib/utils/errors/APIError.js +7 -11
- package/lib/utils/errors/assertValidationError.js +4 -4
- package/lib/utils/errors/validation.js +5 -6
- package/lib/utils/findIndexByFields.js +4 -9
- package/lib/utils/resolveConfig.js +9 -10
- package/lib/utils/resolveLibraryOptions.js +4 -5
- package/lib/utils/resolveOwnerFields.js +10 -33
- package/lib/utils/resolvePKFields.js +2 -3
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +23 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/APIClient.d.ts +16 -1
- package/lib-esm/internals/APIClient.js +230 -205
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +201 -244
- package/lib-esm/internals/generateClient.js +11 -10
- package/lib-esm/internals/generateModelsProperty.js +19 -312
- package/lib-esm/internals/operations/get.d.ts +2 -0
- package/lib-esm/internals/operations/get.js +55 -0
- package/lib-esm/internals/operations/list.d.ts +2 -0
- package/lib-esm/internals/operations/list.js +67 -0
- package/lib-esm/internals/operations/observeQuery.d.ts +2 -0
- package/lib-esm/internals/operations/observeQuery.js +115 -0
- package/lib-esm/internals/operations/subscription.d.ts +1 -0
- package/lib-esm/internals/operations/subscription.js +23 -0
- package/lib-esm/internals/server/generateClient.d.ts +11 -0
- package/lib-esm/internals/server/generateClient.js +26 -0
- package/lib-esm/internals/server/generateModelsProperty.d.ts +3 -0
- package/lib-esm/internals/server/generateModelsProperty.js +41 -0
- package/lib-esm/internals/server/index.d.ts +1 -0
- package/lib-esm/internals/server/index.js +3 -0
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +36 -4
- package/lib-esm/types/index.js +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.js +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/findIndexByFields.js +4 -9
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/lib-esm/utils/resolveOwnerFields.js +10 -33
- package/lib-esm/utils/resolvePKFields.js +2 -3
- package/package.json +8 -7
- package/src/GraphQLAPI.ts +6 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/APIClient.ts +122 -35
- package/src/internals/InternalGraphQLAPI.ts +35 -10
- package/src/internals/generateClient.ts +0 -1
- package/src/internals/generateModelsProperty.ts +27 -340
- package/src/internals/operations/get.ts +121 -0
- package/src/internals/operations/list.ts +111 -0
- package/src/internals/operations/observeQuery.ts +140 -0
- package/src/internals/operations/subscription.ts +59 -0
- package/src/internals/server/generateClient.ts +45 -0
- package/src/internals/server/generateModelsProperty.ts +70 -0
- package/src/internals/server/index.ts +4 -0
- package/src/types/index.ts +65 -9
package/lib/types/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
1
|
+
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
2
|
import { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
3
3
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
4
4
|
export { OperationTypeNode } from 'graphql';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
7
8
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
8
9
|
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
9
10
|
export { CommonPublicClientOptions } from '../internals/types';
|
|
@@ -288,10 +289,41 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
288
289
|
[__amplify]: AmplifyClassV6;
|
|
289
290
|
[__authMode]?: GraphQLAuthMode;
|
|
290
291
|
[__authToken]?: string;
|
|
291
|
-
graphql:
|
|
292
|
-
[key: string]: string;
|
|
293
|
-
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
292
|
+
graphql: GraphQLMethod;
|
|
294
293
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
295
294
|
isCancelError: (error: any) => boolean;
|
|
296
295
|
models: ModelTypes<T>;
|
|
297
296
|
}>;
|
|
297
|
+
export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
298
|
+
[__amplify]: AmplifyClassV6;
|
|
299
|
+
[__authMode]?: GraphQLAuthMode;
|
|
300
|
+
[__authToken]?: string;
|
|
301
|
+
graphql: GraphQLMethodSSR;
|
|
302
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
303
|
+
isCancelError: (error: any) => boolean;
|
|
304
|
+
models: ModelTypes<T, 'REQUEST'>;
|
|
305
|
+
}>;
|
|
306
|
+
export type V6ClientSSRCookies<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
307
|
+
[__amplify]: AmplifyClassV6;
|
|
308
|
+
[__authMode]?: GraphQLAuthMode;
|
|
309
|
+
[__authToken]?: string;
|
|
310
|
+
graphql: GraphQLMethod;
|
|
311
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
312
|
+
isCancelError: (error: any) => boolean;
|
|
313
|
+
models: ModelTypes<T, 'COOKIES'>;
|
|
314
|
+
}>;
|
|
315
|
+
export type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
316
|
+
[key: string]: string;
|
|
317
|
+
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
318
|
+
export type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
319
|
+
[key: string]: string;
|
|
320
|
+
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
321
|
+
/**
|
|
322
|
+
* @private
|
|
323
|
+
*
|
|
324
|
+
* The knobs available for configuring `server/generateClient` internally.
|
|
325
|
+
*/
|
|
326
|
+
export type ServerClientGenerationParams = {
|
|
327
|
+
amplify: null | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
|
|
328
|
+
config: ResourcesConfig;
|
|
329
|
+
};
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ConnectionStateMonitor = exports.CONNECTION_CHANGE = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var ReachabilityMonitor_1 = require("./ReachabilityMonitor");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
const PubSub_1 = require("../types/PubSub");
|
|
8
|
+
const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
|
|
10
9
|
exports.CONNECTION_CHANGE = {
|
|
11
10
|
KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
|
|
12
11
|
KEEP_ALIVE: { keepAliveState: 'healthy' },
|
|
@@ -24,9 +23,8 @@ exports.CONNECTION_CHANGE = {
|
|
|
24
23
|
ONLINE: { networkState: 'connected' },
|
|
25
24
|
OFFLINE: { networkState: 'disconnected' },
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _this = this;
|
|
26
|
+
class ConnectionStateMonitor {
|
|
27
|
+
constructor() {
|
|
30
28
|
this._networkMonitoringSubscription = undefined;
|
|
31
29
|
this._linkedConnectionState = {
|
|
32
30
|
networkState: 'connected',
|
|
@@ -35,73 +33,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
35
33
|
keepAliveState: 'healthy',
|
|
36
34
|
};
|
|
37
35
|
// Attempt to update the state with the current actual network state
|
|
38
|
-
this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
42
|
-
(_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
36
|
+
this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
|
|
37
|
+
this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
38
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
43
39
|
});
|
|
44
40
|
this._linkedConnectionStateObservable =
|
|
45
|
-
new rxjs_1.Observable(
|
|
46
|
-
connectionStateObserver.next(
|
|
47
|
-
|
|
41
|
+
new rxjs_1.Observable(connectionStateObserver => {
|
|
42
|
+
connectionStateObserver.next(this._linkedConnectionState);
|
|
43
|
+
this._linkedConnectionStateObserver = connectionStateObserver;
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* Turn network state monitoring on if it isn't on already
|
|
52
48
|
*/
|
|
53
|
-
|
|
54
|
-
var _this = this;
|
|
55
|
-
var _a;
|
|
49
|
+
enableNetworkMonitoring() {
|
|
56
50
|
// If no initial network state was discovered, stop trying
|
|
57
|
-
|
|
51
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
58
52
|
// Maintain the network state based on the reachability monitor
|
|
59
53
|
if (this._networkMonitoringSubscription === undefined) {
|
|
60
|
-
this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(
|
|
61
|
-
|
|
62
|
-
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
54
|
+
this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
|
|
55
|
+
this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
63
56
|
});
|
|
64
57
|
}
|
|
65
|
-
}
|
|
58
|
+
}
|
|
66
59
|
/**
|
|
67
60
|
* Turn network state monitoring off if it isn't off already
|
|
68
61
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
62
|
+
disableNetworkMonitoring() {
|
|
63
|
+
this._networkMonitoringSubscription?.unsubscribe();
|
|
72
64
|
this._networkMonitoringSubscription = undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}));
|
|
96
|
-
},
|
|
97
|
-
enumerable: false,
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the observable that allows us to monitor the connection state
|
|
68
|
+
*
|
|
69
|
+
* @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
|
|
70
|
+
*/
|
|
71
|
+
get connectionStateObservable() {
|
|
72
|
+
let previous;
|
|
73
|
+
// The linked state aggregates state changes to any of the network, connection,
|
|
74
|
+
// intendedConnection and keepAliveHealth. Some states will change these independent
|
|
75
|
+
// states without changing the overall connection state.
|
|
76
|
+
// After translating from linked states to ConnectionState, then remove any duplicates
|
|
77
|
+
return this._linkedConnectionStateObservable
|
|
78
|
+
.pipe((0, rxjs_1.map)(value => {
|
|
79
|
+
return this.connectionStatesTranslator(value);
|
|
80
|
+
}))
|
|
81
|
+
.pipe((0, rxjs_1.filter)(current => {
|
|
82
|
+
const toInclude = current !== previous;
|
|
83
|
+
previous = current;
|
|
84
|
+
return toInclude;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
100
87
|
/*
|
|
101
88
|
* Updates local connection state and emits the full state to the observer.
|
|
102
89
|
*/
|
|
103
|
-
|
|
104
|
-
var _a;
|
|
90
|
+
record(statusUpdates) {
|
|
105
91
|
// Maintain the network monitor
|
|
106
92
|
if (statusUpdates.intendedConnectionState === 'connected') {
|
|
107
93
|
this.enableNetworkMonitoring();
|
|
@@ -110,15 +96,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
110
96
|
this.disableNetworkMonitoring();
|
|
111
97
|
}
|
|
112
98
|
// Maintain the socket state
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
const newSocketStatus = {
|
|
100
|
+
...this._linkedConnectionState,
|
|
101
|
+
...statusUpdates,
|
|
102
|
+
};
|
|
103
|
+
this._linkedConnectionState = { ...newSocketStatus };
|
|
104
|
+
this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
|
|
105
|
+
}
|
|
117
106
|
/*
|
|
118
107
|
* Translate the ConnectionState structure into a specific ConnectionState string literal union
|
|
119
108
|
*/
|
|
120
|
-
|
|
121
|
-
var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
|
|
109
|
+
connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
|
|
122
110
|
if (connectionState === 'connected' && networkState === 'disconnected')
|
|
123
111
|
return PubSub_1.ConnectionState.ConnectedPendingNetwork;
|
|
124
112
|
if (connectionState === 'connected' &&
|
|
@@ -139,7 +127,6 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
139
127
|
if (connectionState === 'disconnected')
|
|
140
128
|
return PubSub_1.ConnectionState.Disconnected;
|
|
141
129
|
return PubSub_1.ConnectionState.Connected;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
145
132
|
exports.ConnectionStateMonitor = ConnectionStateMonitor;
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReachabilityMonitor = void 0;
|
|
4
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor();
|
|
8
8
|
exports.ReachabilityMonitor = ReachabilityMonitor;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReachabilityMonitor = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return new utils_1.Reachability().networkMonitor(netinfo_1.default);
|
|
11
|
-
};
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
|
|
9
|
+
const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor(netinfo_1.default);
|
|
12
10
|
exports.ReachabilityMonitor = ReachabilityMonitor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReconnectionMonitor = exports.ReconnectEvent = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_1 = require("../Providers/constants");
|
|
5
5
|
var ReconnectEvent;
|
|
6
6
|
(function (ReconnectEvent) {
|
|
7
7
|
ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
|
|
@@ -13,31 +13,30 @@ var ReconnectEvent;
|
|
|
13
13
|
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
14
14
|
* supported by the browser, so this keeps retrying every minute until halted.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
class ReconnectionMonitor {
|
|
17
|
+
constructor() {
|
|
18
18
|
this.reconnectObservers = [];
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Add reconnect observer to the list of observers to alert on reconnect
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
addObserver(reconnectObserver) {
|
|
24
24
|
this.reconnectObservers.push(reconnectObserver);
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
/**
|
|
27
27
|
* Given a reconnect event, start the appropriate behavior
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
var _this = this;
|
|
29
|
+
record(event) {
|
|
31
30
|
if (event === ReconnectEvent.START_RECONNECT) {
|
|
32
31
|
// If the reconnection hasn't been started
|
|
33
32
|
if (this.reconnectSetTimeoutId === undefined &&
|
|
34
33
|
this.reconnectIntervalId === undefined) {
|
|
35
|
-
this.reconnectSetTimeoutId = setTimeout(
|
|
34
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
36
35
|
// Reconnect now
|
|
37
|
-
|
|
36
|
+
this._triggerReconnect();
|
|
38
37
|
// Retry reconnect every periodically until it works
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
this.reconnectIntervalId = setInterval(() => {
|
|
39
|
+
this._triggerReconnect();
|
|
41
40
|
}, constants_1.RECONNECT_INTERVAL);
|
|
42
41
|
}, constants_1.RECONNECT_DELAY);
|
|
43
42
|
}
|
|
@@ -52,22 +51,19 @@ var ReconnectionMonitor = /** @class */ (function () {
|
|
|
52
51
|
this.reconnectSetTimeoutId = undefined;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
}
|
|
54
|
+
}
|
|
56
55
|
/**
|
|
57
56
|
* Complete all reconnect observers
|
|
58
57
|
*/
|
|
59
|
-
|
|
60
|
-
this.reconnectObservers.forEach(
|
|
61
|
-
|
|
62
|
-
(_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
58
|
+
close() {
|
|
59
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
60
|
+
reconnectObserver.complete?.();
|
|
63
61
|
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.reconnectObservers.forEach(
|
|
67
|
-
|
|
68
|
-
(_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
62
|
+
}
|
|
63
|
+
_triggerReconnect() {
|
|
64
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
65
|
+
reconnectObserver.next?.();
|
|
69
66
|
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
73
69
|
exports.ReconnectionMonitor = ReconnectionMonitor;
|
|
@@ -3,21 +3,17 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.APIError = void 0;
|
|
6
|
-
|
|
7
|
-
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
7
|
/**
|
|
9
8
|
* @internal
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _this = _super.call(this, params) || this;
|
|
10
|
+
class APIError extends utils_1.AmplifyError {
|
|
11
|
+
constructor(params) {
|
|
12
|
+
super(params);
|
|
15
13
|
// Hack for making the custom error class work when transpiled to es5
|
|
16
14
|
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
17
|
-
|
|
18
|
-
Object.setPrototypeOf(
|
|
19
|
-
return _this;
|
|
15
|
+
this.constructor = APIError;
|
|
16
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
}(utils_1.AmplifyError));
|
|
18
|
+
}
|
|
23
19
|
exports.APIError = APIError;
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.assertValidationError = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const APIError_1 = require("./APIError");
|
|
7
|
+
const validation_1 = require("./validation");
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
function assertValidationError(assertion, name) {
|
|
12
|
-
|
|
12
|
+
const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
13
13
|
if (!assertion) {
|
|
14
|
-
throw new APIError_1.APIError({ name
|
|
14
|
+
throw new APIError_1.APIError({ name, message, recoverySuggestion });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.assertValidationError = assertValidationError;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
var _a;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
5
|
exports.validationErrorMap = exports.APIValidationErrorCode = void 0;
|
|
7
6
|
var APIValidationErrorCode;
|
|
@@ -10,18 +9,18 @@ var APIValidationErrorCode;
|
|
|
10
9
|
APIValidationErrorCode["NoRegion"] = "NoRegion";
|
|
11
10
|
APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
|
|
12
11
|
})(APIValidationErrorCode || (exports.APIValidationErrorCode = APIValidationErrorCode = {}));
|
|
13
|
-
exports.validationErrorMap =
|
|
14
|
-
|
|
12
|
+
exports.validationErrorMap = {
|
|
13
|
+
[APIValidationErrorCode.NoAuthSession]: {
|
|
15
14
|
message: 'Auth session should not be empty.',
|
|
16
15
|
},
|
|
17
16
|
// TODO: re-enable when working in all test environments:
|
|
18
17
|
// [APIValidationErrorCode.NoEndpoint]: {
|
|
19
18
|
// message: 'Missing endpoint',
|
|
20
19
|
// },
|
|
21
|
-
|
|
20
|
+
[APIValidationErrorCode.NoRegion]: {
|
|
22
21
|
message: 'Missing region.',
|
|
23
22
|
},
|
|
24
|
-
|
|
23
|
+
[APIValidationErrorCode.NoCustomEndpoint]: {
|
|
25
24
|
message: 'Custom endpoint region is present without custom endpoint.',
|
|
26
25
|
},
|
|
27
|
-
|
|
26
|
+
};
|
|
@@ -12,16 +12,11 @@ exports.findIndexByFields = void 0;
|
|
|
12
12
|
* @returns Index of `needle` in `haystack`, otherwise -1 if not found.
|
|
13
13
|
*/
|
|
14
14
|
function findIndexByFields(needle, haystack, keyFields) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (Object.keys(searchObject).every(
|
|
18
|
-
return
|
|
15
|
+
const searchObject = Object.fromEntries(keyFields.map(fieldName => [fieldName, needle[fieldName]]));
|
|
16
|
+
for (let i = 0; i < haystack.length; i++) {
|
|
17
|
+
if (Object.keys(searchObject).every(k => searchObject[k] === haystack[i][k])) {
|
|
18
|
+
return i;
|
|
19
19
|
}
|
|
20
|
-
};
|
|
21
|
-
for (var i = 0; i < haystack.length; i++) {
|
|
22
|
-
var state_1 = _loop_1(i);
|
|
23
|
-
if (typeof state_1 === "object")
|
|
24
|
-
return state_1.value;
|
|
25
20
|
}
|
|
26
21
|
return -1;
|
|
27
22
|
}
|
|
@@ -3,23 +3,22 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveConfig = void 0;
|
|
6
|
-
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
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;
|
|
10
|
+
const resolveConfig = (amplify) => {
|
|
11
|
+
const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = amplify.getConfig().API?.GraphQL ?? {};
|
|
13
12
|
// TODO: re-enable when working in all test environments:
|
|
14
13
|
// assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
|
|
15
14
|
(0, errors_1.assertValidationError)(!(!customEndpoint && customEndpointRegion), errors_1.APIValidationErrorCode.NoCustomEndpoint);
|
|
16
15
|
return {
|
|
17
|
-
apiKey
|
|
18
|
-
customEndpoint
|
|
19
|
-
customEndpointRegion
|
|
20
|
-
defaultAuthMode
|
|
21
|
-
endpoint
|
|
22
|
-
region
|
|
16
|
+
apiKey,
|
|
17
|
+
customEndpoint,
|
|
18
|
+
customEndpointRegion,
|
|
19
|
+
defaultAuthMode,
|
|
20
|
+
endpoint,
|
|
21
|
+
region,
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
24
|
exports.resolveConfig = resolveConfig;
|
|
@@ -6,10 +6,9 @@ exports.resolveLibraryOptions = void 0;
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return { headers: headers, withCredentials: withCredentials };
|
|
9
|
+
const resolveLibraryOptions = (amplify) => {
|
|
10
|
+
const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
|
|
11
|
+
const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
|
|
12
|
+
return { headers, withCredentials };
|
|
14
13
|
};
|
|
15
14
|
exports.resolveLibraryOptions = resolveLibraryOptions;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveOwnerFields = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
4
|
/**
|
|
6
5
|
* Given an introspection schema model, returns all owner fields.
|
|
7
6
|
*
|
|
@@ -9,37 +8,16 @@ var tslib_1 = require("tslib");
|
|
|
9
8
|
* @returns List of owner field names
|
|
10
9
|
*/
|
|
11
10
|
function resolveOwnerFields(model) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
for (var _e = (e_2 = void 0, tslib_1.__values(attr.properties.rules)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
20
|
-
var rule = _f.value;
|
|
21
|
-
if (rule.allow === 'owner') {
|
|
22
|
-
ownerFields.add(rule.ownerField || 'owner');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
27
|
-
finally {
|
|
28
|
-
try {
|
|
29
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
30
|
-
}
|
|
31
|
-
finally { if (e_2) throw e_2.error; }
|
|
11
|
+
const ownerFields = new Set();
|
|
12
|
+
for (const attr of model.attributes || []) {
|
|
13
|
+
if (isAuthAttribute(attr)) {
|
|
14
|
+
for (const rule of attr.properties.rules) {
|
|
15
|
+
if (rule.allow === 'owner') {
|
|
16
|
+
ownerFields.add(rule.ownerField || 'owner');
|
|
32
17
|
}
|
|
33
18
|
}
|
|
34
19
|
}
|
|
35
20
|
}
|
|
36
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
37
|
-
finally {
|
|
38
|
-
try {
|
|
39
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
40
|
-
}
|
|
41
|
-
finally { if (e_1) throw e_1.error; }
|
|
42
|
-
}
|
|
43
21
|
return Array.from(ownerFields);
|
|
44
22
|
}
|
|
45
23
|
exports.resolveOwnerFields = resolveOwnerFields;
|
|
@@ -51,11 +29,10 @@ exports.resolveOwnerFields = resolveOwnerFields;
|
|
|
51
29
|
* @returns True if given object is an auth attribute
|
|
52
30
|
*/
|
|
53
31
|
function isAuthAttribute(attribute) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return ((_b = attribute === null || attribute === void 0 ? void 0 : attribute.properties) === null || _b === void 0 ? void 0 : _b.rules).every(function (rule) { return !!rule.allow; });
|
|
32
|
+
if (attribute?.type === 'auth') {
|
|
33
|
+
if (typeof attribute?.properties === 'object') {
|
|
34
|
+
if (Array.isArray(attribute?.properties?.rules)) {
|
|
35
|
+
return (attribute?.properties?.rules).every(rule => !!rule.allow);
|
|
59
36
|
}
|
|
60
37
|
}
|
|
61
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvePKFields = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
4
|
/**
|
|
6
5
|
* Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key
|
|
7
6
|
* as an array of field names.
|
|
@@ -10,7 +9,7 @@ var tslib_1 = require("tslib");
|
|
|
10
9
|
* @returns Array of field names
|
|
11
10
|
*/
|
|
12
11
|
function resolvePKFields(model) {
|
|
13
|
-
|
|
14
|
-
return
|
|
12
|
+
const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;
|
|
13
|
+
return [primaryKeyFieldName, ...sortKeyFieldNames];
|
|
15
14
|
}
|
|
16
15
|
exports.resolvePKFields = resolvePKFields;
|
package/lib-esm/GraphQLAPI.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
19
19
|
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
20
20
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
21
21
|
*/
|
|
22
|
-
graphql<T = any>(amplify: AmplifyClassV6, options: GraphQLOptions, additionalHeaders?: {
|
|
22
|
+
graphql<T = any>(amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>), options: GraphQLOptions, additionalHeaders?: {
|
|
23
23
|
[key: string]: string;
|
|
24
24
|
}): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
25
25
|
/**
|