@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.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/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,21 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
74
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
|
+
};
|
|
2
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
var api_1 = require("@aws-amplify/api");
|
|
78
|
+
exports.SubscriptionProcessor = exports.USER_CREDENTIALS = exports.CONTROL_MSG = void 0;
|
|
7
79
|
var internals_1 = require("@aws-amplify/api/internals");
|
|
8
|
-
var auth_1 = require("@aws-amplify/auth");
|
|
9
|
-
var cache_1 = require("@aws-amplify/cache");
|
|
10
80
|
var core_1 = require("@aws-amplify/core");
|
|
11
|
-
var
|
|
12
|
-
var zen_observable_ts_1 =
|
|
81
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
82
|
+
var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
|
|
13
83
|
var types_1 = require("../../types");
|
|
14
|
-
var
|
|
84
|
+
var utils_2 = require("../utils");
|
|
15
85
|
var predicates_1 = require("../../predicates");
|
|
16
86
|
var util_1 = require("../../util");
|
|
17
87
|
var errorMaps_1 = require("./errorMaps");
|
|
18
|
-
var
|
|
88
|
+
var api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
89
|
+
var logger = new utils_1.Logger('DataStore');
|
|
19
90
|
var CONTROL_MSG;
|
|
20
91
|
(function (CONTROL_MSG) {
|
|
21
92
|
CONTROL_MSG["CONNECTED"] = "CONNECTED";
|
|
@@ -30,9 +101,7 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
30
101
|
function SubscriptionProcessor(schema, syncPredicates, amplifyConfig, authModeStrategy, errorHandler, amplifyContext) {
|
|
31
102
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
32
103
|
if (amplifyContext === void 0) { amplifyContext = {
|
|
33
|
-
Auth: auth_1.Auth,
|
|
34
104
|
InternalAPI: internals_1.InternalAPI,
|
|
35
|
-
Cache: cache_1.Cache,
|
|
36
105
|
}; }
|
|
37
106
|
this.schema = schema;
|
|
38
107
|
this.syncPredicates = syncPredicates;
|
|
@@ -42,21 +111,19 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
42
111
|
this.amplifyContext = amplifyContext;
|
|
43
112
|
this.typeQuery = new WeakMap();
|
|
44
113
|
this.buffer = [];
|
|
45
|
-
this.runningProcesses = new
|
|
114
|
+
this.runningProcesses = new utils_1.BackgroundProcessManager();
|
|
46
115
|
}
|
|
47
|
-
SubscriptionProcessor.prototype.buildSubscription = function (namespace, model, transformerMutationType, userCredentials,
|
|
116
|
+
SubscriptionProcessor.prototype.buildSubscription = function (namespace, model, transformerMutationType, userCredentials, oidcTokenPayload, authMode, filterArg) {
|
|
48
117
|
if (filterArg === void 0) { filterArg = false; }
|
|
49
118
|
var aws_appsync_authenticationType = this.amplifyConfig.aws_appsync_authenticationType;
|
|
50
|
-
var _a = this.getAuthorizationInfo(model, userCredentials, aws_appsync_authenticationType,
|
|
51
|
-
var _b =
|
|
119
|
+
var _a = this.getAuthorizationInfo(model, userCredentials, aws_appsync_authenticationType, oidcTokenPayload, authMode) || {}, isOwner = _a.isOwner, ownerField = _a.ownerField, ownerValue = _a.ownerValue;
|
|
120
|
+
var _b = __read((0, utils_2.buildSubscriptionGraphQLOperation)(namespace, model, transformerMutationType, isOwner, ownerField, filterArg), 3), opType = _b[0], opName = _b[1], query = _b[2];
|
|
52
121
|
return { authMode: authMode, opType: opType, opName: opName, query: query, isOwner: isOwner, ownerField: ownerField, ownerValue: ownerValue };
|
|
53
122
|
};
|
|
54
|
-
SubscriptionProcessor.prototype.getAuthorizationInfo = function (model, userCredentials, defaultAuthType,
|
|
55
|
-
|
|
56
|
-
if (oidcTokenPayload === void 0) { oidcTokenPayload = {}; }
|
|
57
|
-
var rules = utils_1.getAuthorizationRules(model);
|
|
123
|
+
SubscriptionProcessor.prototype.getAuthorizationInfo = function (model, userCredentials, defaultAuthType, oidcTokenPayload, authMode) {
|
|
124
|
+
var rules = (0, utils_2.getAuthorizationRules)(model);
|
|
58
125
|
// Return null if user doesn't have proper credentials for private API with IAM auth
|
|
59
|
-
var iamPrivateAuth = authMode ===
|
|
126
|
+
var iamPrivateAuth = authMode === 'iam' &&
|
|
60
127
|
rules.find(function (rule) { return rule.authStrategy === 'private' && rule.provider === 'iam'; });
|
|
61
128
|
if (iamPrivateAuth && userCredentials === USER_CREDENTIALS.unauth) {
|
|
62
129
|
return null;
|
|
@@ -69,15 +136,15 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
69
136
|
return rule.authStrategy === 'groups' &&
|
|
70
137
|
['userPools', 'oidc'].includes(rule.provider);
|
|
71
138
|
});
|
|
72
|
-
var validGroup =
|
|
73
|
-
authMode === api_1.GRAPHQL_AUTH_MODE.OPENID_CONNECT) &&
|
|
139
|
+
var validGroup = authMode === 'jwt' &&
|
|
74
140
|
groupAuthRules.find(function (groupAuthRule) {
|
|
75
141
|
// validate token against groupClaim
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
142
|
+
if (oidcTokenPayload) {
|
|
143
|
+
var oidcUserGroups = (0, utils_2.getUserGroupsFromToken)(oidcTokenPayload, groupAuthRule);
|
|
144
|
+
return __spreadArray([], __read(oidcUserGroups), false).find(function (userGroup) {
|
|
145
|
+
return groupAuthRule.groups.find(function (group) { return group === userGroup; });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
81
148
|
});
|
|
82
149
|
if (validGroup) {
|
|
83
150
|
return {
|
|
@@ -85,40 +152,18 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
85
152
|
isOwner: false,
|
|
86
153
|
};
|
|
87
154
|
}
|
|
88
|
-
// Owner auth needs additional values to be returned in order to create the subscription with
|
|
89
|
-
// the correct parameters so we are getting the owner value from the Cognito token via the
|
|
90
|
-
// identityClaim from the auth rule.
|
|
91
|
-
var cognitoOwnerAuthRules = authMode === api_1.GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS
|
|
92
|
-
? rules.filter(function (rule) {
|
|
93
|
-
return rule.authStrategy === 'owner' && rule.provider === 'userPools';
|
|
94
|
-
})
|
|
95
|
-
: [];
|
|
96
155
|
var ownerAuthInfo;
|
|
97
|
-
cognitoOwnerAuthRules.forEach(function (ownerAuthRule) {
|
|
98
|
-
var _a;
|
|
99
|
-
var ownerValue = cognitoTokenPayload[ownerAuthRule.identityClaim];
|
|
100
|
-
// AuthZ for "list of owners" is handled dynamically in the subscription auth request
|
|
101
|
-
// resolver. It doesn't rely on a subscription arg.
|
|
102
|
-
// Only pass a subscription arg for single owner auth
|
|
103
|
-
var singleOwner = ((_a = model.fields[ownerAuthRule.ownerField]) === null || _a === void 0 ? void 0 : _a.isArray) !== true;
|
|
104
|
-
var isOwnerArgRequired = singleOwner && !ownerAuthRule.areSubscriptionsPublic;
|
|
105
|
-
if (ownerValue) {
|
|
106
|
-
ownerAuthInfo = {
|
|
107
|
-
authMode: api_1.GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS,
|
|
108
|
-
isOwner: isOwnerArgRequired,
|
|
109
|
-
ownerField: ownerAuthRule.ownerField,
|
|
110
|
-
ownerValue: ownerValue,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
156
|
if (ownerAuthInfo) {
|
|
115
157
|
return ownerAuthInfo;
|
|
116
158
|
}
|
|
117
159
|
// Owner auth needs additional values to be returned in order to create the subscription with
|
|
118
160
|
// the correct parameters so we are getting the owner value from the OIDC token via the
|
|
119
161
|
// identityClaim from the auth rule.
|
|
120
|
-
var oidcOwnerAuthRules = authMode ===
|
|
121
|
-
? rules.filter(function (rule) {
|
|
162
|
+
var oidcOwnerAuthRules = authMode === 'jwt'
|
|
163
|
+
? rules.filter(function (rule) {
|
|
164
|
+
return rule.authStrategy === 'owner' &&
|
|
165
|
+
(rule.provider === 'oidc' || rule.provider === 'userPools');
|
|
166
|
+
})
|
|
122
167
|
: [];
|
|
123
168
|
oidcOwnerAuthRules.forEach(function (ownerAuthRule) {
|
|
124
169
|
var _a;
|
|
@@ -127,10 +172,10 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
127
172
|
var isOwnerArgRequired = singleOwner && !ownerAuthRule.areSubscriptionsPublic;
|
|
128
173
|
if (ownerValue) {
|
|
129
174
|
ownerAuthInfo = {
|
|
130
|
-
authMode:
|
|
175
|
+
authMode: 'jwt',
|
|
131
176
|
isOwner: isOwnerArgRequired,
|
|
132
177
|
ownerField: ownerAuthRule.ownerField,
|
|
133
|
-
ownerValue: ownerValue,
|
|
178
|
+
ownerValue: String(ownerValue),
|
|
134
179
|
};
|
|
135
180
|
}
|
|
136
181
|
});
|
|
@@ -145,79 +190,51 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
145
190
|
};
|
|
146
191
|
SubscriptionProcessor.prototype.hubQueryCompletionListener = function (completed, capsule) {
|
|
147
192
|
var event = capsule.payload.event;
|
|
148
|
-
if (event ===
|
|
193
|
+
if (event === api_graphql_1.CONTROL_MSG.SUBSCRIPTION_ACK) {
|
|
149
194
|
completed();
|
|
150
195
|
}
|
|
151
196
|
};
|
|
152
197
|
SubscriptionProcessor.prototype.start = function () {
|
|
153
198
|
var _this = this;
|
|
154
199
|
this.runningProcesses =
|
|
155
|
-
this.runningProcesses || new
|
|
200
|
+
this.runningProcesses || new utils_1.BackgroundProcessManager();
|
|
156
201
|
var ctlObservable = new zen_observable_ts_1.default(function (observer) {
|
|
157
202
|
var promises = [];
|
|
158
203
|
// Creating subs for each model/operation combo so they can be unsubscribed
|
|
159
204
|
// independently, since the auth retry behavior is asynchronous.
|
|
160
205
|
var subscriptions = {};
|
|
161
|
-
var
|
|
206
|
+
var oidcTokenPayload;
|
|
162
207
|
var userCredentials = USER_CREDENTIALS.none;
|
|
163
|
-
_this.runningProcesses.add(function () { return
|
|
164
|
-
var credentials, err_1, session, err_2
|
|
208
|
+
_this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
209
|
+
var credentials, err_1, session, err_2;
|
|
165
210
|
var _this = this;
|
|
166
|
-
|
|
167
|
-
|
|
211
|
+
var _a, _b, _c;
|
|
212
|
+
return __generator(this, function (_d) {
|
|
213
|
+
switch (_d.label) {
|
|
168
214
|
case 0:
|
|
169
|
-
|
|
170
|
-
return [4 /*yield*/,
|
|
215
|
+
_d.trys.push([0, 2, , 3]);
|
|
216
|
+
return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
|
|
171
217
|
case 1:
|
|
172
|
-
credentials =
|
|
173
|
-
userCredentials = credentials
|
|
218
|
+
credentials = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken;
|
|
219
|
+
userCredentials = credentials
|
|
174
220
|
? USER_CREDENTIALS.auth
|
|
175
221
|
: USER_CREDENTIALS.unauth;
|
|
176
222
|
return [3 /*break*/, 3];
|
|
177
223
|
case 2:
|
|
178
|
-
err_1 =
|
|
224
|
+
err_1 = _d.sent();
|
|
179
225
|
return [3 /*break*/, 3];
|
|
180
226
|
case 3:
|
|
181
|
-
|
|
182
|
-
return [4 /*yield*/,
|
|
183
|
-
case 4:
|
|
184
|
-
session = _b.sent();
|
|
185
|
-
cognitoTokenPayload = session.getIdToken().decodePayload();
|
|
186
|
-
return [3 /*break*/, 6];
|
|
227
|
+
_d.trys.push([3, 6, , 7]);
|
|
228
|
+
return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
|
|
229
|
+
case 4: return [4 /*yield*/, _d.sent()];
|
|
187
230
|
case 5:
|
|
188
|
-
|
|
189
|
-
|
|
231
|
+
session = _d.sent();
|
|
232
|
+
oidcTokenPayload = (_c = (_b = session.tokens) === null || _b === void 0 ? void 0 : _b.idToken) === null || _c === void 0 ? void 0 : _c.payload;
|
|
233
|
+
return [3 /*break*/, 7];
|
|
190
234
|
case 6:
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (!aws_cognito_region || (AuthConfig && !AuthConfig.region)) {
|
|
194
|
-
throw 'Auth is not configured';
|
|
195
|
-
}
|
|
196
|
-
token = void 0;
|
|
197
|
-
return [4 /*yield*/, this.amplifyContext.Cache.getItem('federatedInfo')];
|
|
235
|
+
err_2 = _d.sent();
|
|
236
|
+
return [3 /*break*/, 7];
|
|
198
237
|
case 7:
|
|
199
|
-
federatedInfo = _b.sent();
|
|
200
|
-
if (!federatedInfo) return [3 /*break*/, 8];
|
|
201
|
-
token = federatedInfo.token;
|
|
202
|
-
return [3 /*break*/, 10];
|
|
203
|
-
case 8: return [4 /*yield*/, this.amplifyContext.Auth.currentAuthenticatedUser()];
|
|
204
|
-
case 9:
|
|
205
|
-
currentUser = _b.sent();
|
|
206
|
-
if (currentUser) {
|
|
207
|
-
token = currentUser.token;
|
|
208
|
-
}
|
|
209
|
-
_b.label = 10;
|
|
210
|
-
case 10:
|
|
211
|
-
if (token) {
|
|
212
|
-
payload = token.split('.')[1];
|
|
213
|
-
oidcTokenPayload = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
|
|
214
|
-
}
|
|
215
|
-
return [3 /*break*/, 12];
|
|
216
|
-
case 11:
|
|
217
|
-
err_3 = _b.sent();
|
|
218
|
-
logger.debug('error getting OIDC JWT', err_3);
|
|
219
|
-
return [3 /*break*/, 12];
|
|
220
|
-
case 12:
|
|
221
238
|
Object.values(this.schema.namespaces).forEach(function (namespace) {
|
|
222
239
|
Object.values(namespace.models)
|
|
223
240
|
.filter(function (_a) {
|
|
@@ -226,13 +243,13 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
226
243
|
})
|
|
227
244
|
.forEach(function (modelDefinition) {
|
|
228
245
|
return _this.runningProcesses.isOpen &&
|
|
229
|
-
_this.runningProcesses.add(function () { return
|
|
246
|
+
_this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
230
247
|
var modelAuthModes, readAuthModes, operations, operationAuthModeAttempts, predicatesGroup, addFilterArg, subscriptionRetry;
|
|
231
248
|
var _a, _b, _c;
|
|
232
249
|
var _this = this;
|
|
233
|
-
return
|
|
250
|
+
return __generator(this, function (_d) {
|
|
234
251
|
switch (_d.label) {
|
|
235
|
-
case 0: return [4 /*yield*/,
|
|
252
|
+
case 0: return [4 /*yield*/, (0, utils_2.getModelAuthModes)({
|
|
236
253
|
authModeStrategy: this.authModeStrategy,
|
|
237
254
|
defaultAuthMode: this.amplifyConfig.aws_appsync_authenticationType,
|
|
238
255
|
modelName: modelDefinition.name,
|
|
@@ -241,43 +258,43 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
241
258
|
case 1:
|
|
242
259
|
modelAuthModes = _d.sent();
|
|
243
260
|
readAuthModes = modelAuthModes.READ;
|
|
244
|
-
subscriptions =
|
|
245
|
-
_b[
|
|
246
|
-
_b[
|
|
247
|
-
_b[
|
|
261
|
+
subscriptions = __assign(__assign({}, subscriptions), (_a = {}, _a[modelDefinition.name] = (_b = {},
|
|
262
|
+
_b[utils_2.TransformerMutationType.CREATE] = [],
|
|
263
|
+
_b[utils_2.TransformerMutationType.UPDATE] = [],
|
|
264
|
+
_b[utils_2.TransformerMutationType.DELETE] = [],
|
|
248
265
|
_b), _a));
|
|
249
266
|
operations = [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
267
|
+
utils_2.TransformerMutationType.CREATE,
|
|
268
|
+
utils_2.TransformerMutationType.UPDATE,
|
|
269
|
+
utils_2.TransformerMutationType.DELETE,
|
|
253
270
|
];
|
|
254
271
|
operationAuthModeAttempts = (_c = {},
|
|
255
|
-
_c[
|
|
256
|
-
_c[
|
|
257
|
-
_c[
|
|
272
|
+
_c[utils_2.TransformerMutationType.CREATE] = 0,
|
|
273
|
+
_c[utils_2.TransformerMutationType.UPDATE] = 0,
|
|
274
|
+
_c[utils_2.TransformerMutationType.DELETE] = 0,
|
|
258
275
|
_c);
|
|
259
276
|
predicatesGroup = predicates_1.ModelPredicateCreator.getPredicates(this.syncPredicates.get(modelDefinition), false);
|
|
260
277
|
addFilterArg = predicatesGroup !== undefined;
|
|
261
278
|
subscriptionRetry = function (operation, addFilter) {
|
|
262
279
|
if (addFilter === void 0) { addFilter = addFilterArg; }
|
|
263
|
-
return
|
|
280
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
264
281
|
var _a, transformerMutationType, opName, query, isOwner, ownerField, ownerValue, authMode, authToken, variables, customUserAgentDetails, queryObservable, subscriptionReadyCallback;
|
|
265
282
|
var _this = this;
|
|
266
|
-
return
|
|
283
|
+
return __generator(this, function (_b) {
|
|
267
284
|
switch (_b.label) {
|
|
268
285
|
case 0:
|
|
269
|
-
_a = this.buildSubscription(namespace, modelDefinition, operation, userCredentials,
|
|
270
|
-
return [4 /*yield*/,
|
|
286
|
+
_a = this.buildSubscription(namespace, modelDefinition, operation, userCredentials, oidcTokenPayload, readAuthModes[operationAuthModeAttempts[operation]], addFilter), transformerMutationType = _a.opType, opName = _a.opName, query = _a.query, isOwner = _a.isOwner, ownerField = _a.ownerField, ownerValue = _a.ownerValue, authMode = _a.authMode;
|
|
287
|
+
return [4 /*yield*/, (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
|
|
271
288
|
case 1:
|
|
272
289
|
authToken = _b.sent();
|
|
273
290
|
variables = {};
|
|
274
291
|
customUserAgentDetails = {
|
|
275
|
-
category:
|
|
276
|
-
action:
|
|
292
|
+
category: utils_1.Category.DataStore,
|
|
293
|
+
action: utils_1.DataStoreAction.Subscribe,
|
|
277
294
|
};
|
|
278
295
|
if (addFilter && predicatesGroup) {
|
|
279
296
|
variables['filter'] =
|
|
280
|
-
|
|
297
|
+
(0, utils_2.predicateToGraphQLFilter)(predicatesGroup);
|
|
281
298
|
}
|
|
282
299
|
if (isOwner) {
|
|
283
300
|
if (!ownerValue) {
|
|
@@ -286,30 +303,26 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
286
303
|
}
|
|
287
304
|
variables[ownerField] = ownerValue;
|
|
288
305
|
}
|
|
289
|
-
logger.debug("Attempting "
|
|
290
|
-
queryObservable = this.amplifyContext.InternalAPI.graphql(
|
|
291
|
-
variables: variables }, { authMode: authMode }), { authToken: authToken }), undefined, customUserAgentDetails);
|
|
306
|
+
logger.debug("Attempting ".concat(operation, " subscription with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation]]));
|
|
307
|
+
queryObservable = this.amplifyContext.InternalAPI.graphql(__assign(__assign({ query: query, variables: variables }, { authMode: authMode }), { authToken: authToken }), undefined, customUserAgentDetails);
|
|
292
308
|
// TODO: consider onTerminate.then(() => API.cancel(...))
|
|
293
309
|
subscriptions[modelDefinition.name][transformerMutationType].push(queryObservable
|
|
294
|
-
.
|
|
295
|
-
var value = _a.value;
|
|
296
|
-
return value;
|
|
297
|
-
})
|
|
310
|
+
.filter(function () { return true; }) // to make change more readable
|
|
298
311
|
.subscribe({
|
|
299
|
-
next: function (
|
|
300
|
-
var data =
|
|
312
|
+
next: function (result) {
|
|
313
|
+
var data = result.data, errors = result.errors;
|
|
301
314
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
302
315
|
var messages = errors.map(function (_a) {
|
|
303
316
|
var message = _a.message;
|
|
304
317
|
return message;
|
|
305
318
|
});
|
|
306
|
-
logger.warn("Skipping incoming subscription. Messages: "
|
|
319
|
+
logger.warn("Skipping incoming subscription. Messages: ".concat(messages.join('\n')));
|
|
307
320
|
_this.drainBuffer();
|
|
308
321
|
return;
|
|
309
322
|
}
|
|
310
323
|
var predicatesGroup = predicates_1.ModelPredicateCreator.getPredicates(_this.syncPredicates.get(modelDefinition), false);
|
|
311
324
|
// @ts-ignore
|
|
312
|
-
var
|
|
325
|
+
var _a = data, _b = opName, record = _a[_b];
|
|
313
326
|
// checking incoming subscription against syncPredicate.
|
|
314
327
|
// once AppSync implements filters on subscriptions, we'll be
|
|
315
328
|
// able to set these when establishing the subscription instead.
|
|
@@ -319,14 +332,14 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
319
332
|
}
|
|
320
333
|
_this.drainBuffer();
|
|
321
334
|
},
|
|
322
|
-
error: function (subscriptionError) { return
|
|
323
|
-
var _a, _b, _c, _d, message, isRTFError, e_1;
|
|
324
|
-
return
|
|
325
|
-
switch (
|
|
335
|
+
error: function (subscriptionError) { return __awaiter(_this, void 0, void 0, function () {
|
|
336
|
+
var _a, _b, _c, _d, _e, _f, message, isRTFError, e_1;
|
|
337
|
+
return __generator(this, function (_g) {
|
|
338
|
+
switch (_g.label) {
|
|
326
339
|
case 0:
|
|
327
|
-
_a = subscriptionError.error, _b =
|
|
340
|
+
_a = subscriptionError.error, _b = _a === void 0 ? {
|
|
328
341
|
errors: [],
|
|
329
|
-
} : _a
|
|
342
|
+
} : _a, _c = __read(_b.errors, 1), _d = _c[0], _e = _d === void 0 ? {} : _d, _f = _e.message, message = _f === void 0 ? '' : _f;
|
|
330
343
|
isRTFError =
|
|
331
344
|
// only attempt catch if a filter variable was added to the subscription query
|
|
332
345
|
addFilter &&
|
|
@@ -342,8 +355,8 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
342
355
|
subscriptionRetry(operation, false);
|
|
343
356
|
return [2 /*return*/];
|
|
344
357
|
}
|
|
345
|
-
if (message.includes(
|
|
346
|
-
message.includes(
|
|
358
|
+
if (message.includes(api_graphql_1.CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR) ||
|
|
359
|
+
message.includes(api_graphql_1.CONTROL_MSG.CONNECTION_FAILED)) {
|
|
347
360
|
// Unsubscribe and clear subscription array for model/operation
|
|
348
361
|
subscriptions[modelDefinition.name][transformerMutationType].forEach(function (subscription) {
|
|
349
362
|
return subscription.unsubscribe();
|
|
@@ -353,36 +366,36 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
353
366
|
if (operationAuthModeAttempts[operation] >=
|
|
354
367
|
readAuthModes.length) {
|
|
355
368
|
// last auth mode retry. Continue with error
|
|
356
|
-
logger.debug(operation
|
|
369
|
+
logger.debug("".concat(operation, " subscription failed with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation] - 1]));
|
|
357
370
|
}
|
|
358
371
|
else {
|
|
359
372
|
// retry with different auth mode. Do not trigger
|
|
360
373
|
// observer error or error handler
|
|
361
|
-
logger.debug(operation
|
|
374
|
+
logger.debug("".concat(operation, " subscription failed with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation] - 1], ". Retrying with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation]]));
|
|
362
375
|
subscriptionRetry(operation);
|
|
363
376
|
return [2 /*return*/];
|
|
364
377
|
}
|
|
365
378
|
}
|
|
366
379
|
logger.warn('subscriptionError', message);
|
|
367
|
-
|
|
380
|
+
_g.label = 1;
|
|
368
381
|
case 1:
|
|
369
|
-
|
|
382
|
+
_g.trys.push([1, 3, , 4]);
|
|
370
383
|
return [4 /*yield*/, this.errorHandler({
|
|
371
384
|
recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
|
|
372
385
|
localModel: null,
|
|
373
386
|
message: message,
|
|
374
387
|
model: modelDefinition.name,
|
|
375
388
|
operation: operation,
|
|
376
|
-
errorType: errorMaps_1.getSubscriptionErrorType(subscriptionError),
|
|
389
|
+
errorType: (0, errorMaps_1.getSubscriptionErrorType)(subscriptionError),
|
|
377
390
|
process: types_1.ProcessName.subscribe,
|
|
378
391
|
remoteModel: null,
|
|
379
392
|
cause: subscriptionError,
|
|
380
393
|
})];
|
|
381
394
|
case 2:
|
|
382
|
-
|
|
395
|
+
_g.sent();
|
|
383
396
|
return [3 /*break*/, 4];
|
|
384
397
|
case 3:
|
|
385
|
-
e_1 =
|
|
398
|
+
e_1 = _g.sent();
|
|
386
399
|
logger.error('Subscription error handler failed with:', e_1);
|
|
387
400
|
return [3 /*break*/, 4];
|
|
388
401
|
case 4:
|
|
@@ -399,19 +412,19 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
399
412
|
});
|
|
400
413
|
}); },
|
|
401
414
|
}));
|
|
402
|
-
promises.push((function () { return
|
|
403
|
-
var boundFunction;
|
|
415
|
+
promises.push((function () { return __awaiter(_this, void 0, void 0, function () {
|
|
416
|
+
var boundFunction, removeBoundFunctionListener;
|
|
404
417
|
var _this = this;
|
|
405
|
-
return
|
|
418
|
+
return __generator(this, function (_a) {
|
|
406
419
|
switch (_a.label) {
|
|
407
420
|
case 0: return [4 /*yield*/, new Promise(function (res) {
|
|
408
421
|
subscriptionReadyCallback = res;
|
|
409
422
|
boundFunction = _this.hubQueryCompletionListener.bind(_this, res);
|
|
410
|
-
core_1.Hub.listen('api', boundFunction);
|
|
423
|
+
removeBoundFunctionListener = core_1.Hub.listen('api', boundFunction);
|
|
411
424
|
})];
|
|
412
425
|
case 1:
|
|
413
426
|
_a.sent();
|
|
414
|
-
|
|
427
|
+
removeBoundFunctionListener();
|
|
415
428
|
return [2 /*return*/];
|
|
416
429
|
}
|
|
417
430
|
});
|
|
@@ -438,12 +451,12 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
438
451
|
}
|
|
439
452
|
});
|
|
440
453
|
}); }, 'subscription processor new subscriber');
|
|
441
|
-
return _this.runningProcesses.addCleaner(function () { return
|
|
442
|
-
return
|
|
454
|
+
return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
455
|
+
return __generator(this, function (_a) {
|
|
443
456
|
Object.keys(subscriptions).forEach(function (modelName) {
|
|
444
|
-
subscriptions[modelName][
|
|
445
|
-
subscriptions[modelName][
|
|
446
|
-
subscriptions[modelName][
|
|
457
|
+
subscriptions[modelName][utils_2.TransformerMutationType.CREATE].forEach(function (subscription) { return subscription.unsubscribe(); });
|
|
458
|
+
subscriptions[modelName][utils_2.TransformerMutationType.UPDATE].forEach(function (subscription) { return subscription.unsubscribe(); });
|
|
459
|
+
subscriptions[modelName][utils_2.TransformerMutationType.DELETE].forEach(function (subscription) { return subscription.unsubscribe(); });
|
|
447
460
|
});
|
|
448
461
|
return [2 /*return*/];
|
|
449
462
|
});
|
|
@@ -452,8 +465,8 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
452
465
|
var dataObservable = new zen_observable_ts_1.default(function (observer) {
|
|
453
466
|
_this.dataObserver = observer;
|
|
454
467
|
_this.drainBuffer();
|
|
455
|
-
return _this.runningProcesses.addCleaner(function () { return
|
|
456
|
-
return
|
|
468
|
+
return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
469
|
+
return __generator(this, function (_a) {
|
|
457
470
|
this.dataObserver = null;
|
|
458
471
|
return [2 /*return*/];
|
|
459
472
|
});
|
|
@@ -462,8 +475,8 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
462
475
|
return [ctlObservable, dataObservable];
|
|
463
476
|
};
|
|
464
477
|
SubscriptionProcessor.prototype.stop = function () {
|
|
465
|
-
return
|
|
466
|
-
return
|
|
478
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
479
|
+
return __generator(this, function (_a) {
|
|
467
480
|
switch (_a.label) {
|
|
468
481
|
case 0: return [4 /*yield*/, this.runningProcesses.close()];
|
|
469
482
|
case 1:
|
|
@@ -481,7 +494,7 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
481
494
|
return true;
|
|
482
495
|
}
|
|
483
496
|
var predicates = predicatesGroup.predicates, type = predicatesGroup.type;
|
|
484
|
-
return util_1.validatePredicate(record, type, predicates);
|
|
497
|
+
return (0, util_1.validatePredicate)(record, type, predicates);
|
|
485
498
|
};
|
|
486
499
|
SubscriptionProcessor.prototype.pushToBuffer = function (transformerMutationType, modelDefinition, data) {
|
|
487
500
|
this.buffer.push([transformerMutationType, modelDefinition, data]);
|
|
@@ -502,20 +515,20 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
502
515
|
var header = 'Backend subscriptions filtering error.\n' +
|
|
503
516
|
'Subscriptions filtering will be applied clientside.\n';
|
|
504
517
|
var messageErrorTypeMap = {
|
|
505
|
-
'UnknownArgument: Unknown field argument filter':
|
|
506
|
-
'Filters exceed maximum attributes limit':
|
|
507
|
-
'Filters combination exceed maximum limit':
|
|
508
|
-
'filter uses same fieldName multiple time':
|
|
509
|
-
"The variables input contains a field name 'not'":
|
|
510
|
-
'The variables input contains a field that is not defined for input object type':
|
|
518
|
+
'UnknownArgument: Unknown field argument filter': utils_2.RTFError.UnknownField,
|
|
519
|
+
'Filters exceed maximum attributes limit': utils_2.RTFError.MaxAttributes,
|
|
520
|
+
'Filters combination exceed maximum limit': utils_2.RTFError.MaxCombinations,
|
|
521
|
+
'filter uses same fieldName multiple time': utils_2.RTFError.RepeatedFieldname,
|
|
522
|
+
"The variables input contains a field name 'not'": utils_2.RTFError.NotGroup,
|
|
523
|
+
'The variables input contains a field that is not defined for input object type': utils_2.RTFError.FieldNotInType,
|
|
511
524
|
};
|
|
512
|
-
var _a =
|
|
513
|
-
var _b =
|
|
525
|
+
var _a = __read(Object.entries(messageErrorTypeMap).find(function (_a) {
|
|
526
|
+
var _b = __read(_a, 1), errorMsg = _b[0];
|
|
514
527
|
return message.includes(errorMsg);
|
|
515
528
|
}) || [], 2), _errorMsg = _a[0], errorType = _a[1];
|
|
516
529
|
if (errorType !== undefined) {
|
|
517
|
-
var remediationMessage =
|
|
518
|
-
logger.warn(header
|
|
530
|
+
var remediationMessage = (0, utils_2.generateRTFRemediation)(errorType, modelDefinition, predicatesGroup);
|
|
531
|
+
logger.warn("".concat(header, "\n").concat(message, "\n").concat(remediationMessage));
|
|
519
532
|
return true;
|
|
520
533
|
}
|
|
521
534
|
return false;
|
|
@@ -523,4 +536,3 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
523
536
|
return SubscriptionProcessor;
|
|
524
537
|
}());
|
|
525
538
|
exports.SubscriptionProcessor = SubscriptionProcessor;
|
|
526
|
-
//# sourceMappingURL=subscription.js.map
|