@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
package/lib-esm/sync/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
2
1
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
2
|
+
import { GraphQLAuthModeKeys } from '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
4
4
|
import { AuthorizationRule, GraphQLCondition, GraphQLFilter, ModelInstanceMetadata, OpType, PersistentModel, PersistentModelConstructor, PredicatesGroup, RelationshipType, SchemaModel, SchemaNamespace, SchemaNonModel, ModelOperation, InternalSchema, AuthModeStrategy } from '../types';
|
|
5
5
|
import { MutationEvent } from './';
|
|
@@ -93,14 +93,14 @@ export declare function getUserGroupsFromToken(token: {
|
|
|
93
93
|
}, rule: AuthorizationRule): string[];
|
|
94
94
|
export declare function getModelAuthModes({ authModeStrategy, defaultAuthMode, modelName, schema, }: {
|
|
95
95
|
authModeStrategy: AuthModeStrategy;
|
|
96
|
-
defaultAuthMode:
|
|
96
|
+
defaultAuthMode: GraphQLAuthModeKeys;
|
|
97
97
|
modelName: string;
|
|
98
98
|
schema: InternalSchema;
|
|
99
99
|
}): Promise<{
|
|
100
|
-
[key in ModelOperation]:
|
|
100
|
+
[key in ModelOperation]: GraphQLAuthModeKeys[];
|
|
101
101
|
}>;
|
|
102
102
|
export declare function getForbiddenError(error: any): any;
|
|
103
103
|
export declare function getClientSideAuthError(error: any): GraphQLAuthError;
|
|
104
|
-
export declare function getTokenForCustomAuth(authMode:
|
|
104
|
+
export declare function getTokenForCustomAuth(authMode: GraphQLAuthModeKeys, amplifyConfig?: Record<string, any>): Promise<string | undefined>;
|
|
105
105
|
export declare function getIdentifierValue(modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel): string;
|
|
106
106
|
export {};
|
package/lib-esm/sync/utils.js
CHANGED
|
@@ -1,9 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
49
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
50
|
+
if (!m) return o;
|
|
51
|
+
var i = m.call(o), r, ar = [], e;
|
|
52
|
+
try {
|
|
53
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
54
|
+
}
|
|
55
|
+
catch (error) { e = { error: error }; }
|
|
56
|
+
finally {
|
|
57
|
+
try {
|
|
58
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
59
|
+
}
|
|
60
|
+
finally { if (e) throw e.error; }
|
|
61
|
+
}
|
|
62
|
+
return ar;
|
|
63
|
+
};
|
|
64
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
65
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
66
|
+
if (ar || !(i in from)) {
|
|
67
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
68
|
+
ar[i] = from[i];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
|
+
};
|
|
73
|
+
var __values = (this && this.__values) || function(o) {
|
|
74
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
75
|
+
if (m) return m.call(o);
|
|
76
|
+
if (o && typeof o.length === "number") return {
|
|
77
|
+
next: function () {
|
|
78
|
+
if (o && i >= o.length) o = void 0;
|
|
79
|
+
return { value: o && o[i++], done: !o };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
83
|
+
};
|
|
2
84
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
85
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
5
86
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
6
|
-
import { Logger } from '@aws-amplify/core';
|
|
87
|
+
import { Logger } from '@aws-amplify/core/internals/utils';
|
|
7
88
|
import { isEnumFieldType, isGraphQLScalarType, isPredicateObj, isSchemaModel, isSchemaModelWithAttributes, isTargetNameAssociation, isNonModelFieldType, OpType, ModelOperation, isPredicateGroup, } from '../types';
|
|
8
89
|
import { extractPrimaryKeyFieldNames, establishRelationAndKeys, IDENTIFIER_KEY_SEPARATOR, } from '../util';
|
|
9
90
|
var logger = new Logger('DataStore');
|
|
@@ -116,16 +197,16 @@ function getConnectionFields(modelDefinition, namespace) {
|
|
|
116
197
|
var keyFields = byPkIndex && byPkIndex[1];
|
|
117
198
|
var keyFieldSelectionSet = keyFields === null || keyFields === void 0 ? void 0 : keyFields.join(' ');
|
|
118
199
|
// We rely on `_deleted` when we process the sync query (e.g. in batchSave in the adapters)
|
|
119
|
-
result.push(name
|
|
200
|
+
result.push("".concat(name, " { ").concat(keyFieldSelectionSet, " _deleted }"));
|
|
120
201
|
}
|
|
121
202
|
else {
|
|
122
203
|
// backwards-compatability for schema generated prior to custom primary key support
|
|
123
|
-
result.push(name
|
|
204
|
+
result.push("".concat(name, " { id _deleted }"));
|
|
124
205
|
}
|
|
125
206
|
}
|
|
126
207
|
break;
|
|
127
208
|
default:
|
|
128
|
-
throw new Error("Invalid connection type "
|
|
209
|
+
throw new Error("Invalid connection type ".concat(connectionType));
|
|
129
210
|
}
|
|
130
211
|
});
|
|
131
212
|
return result;
|
|
@@ -145,10 +226,10 @@ function getNonModelFields(namespace, modelDefinition) {
|
|
|
145
226
|
var type = field.type, name = field.name;
|
|
146
227
|
if (isNonModelFieldType(type)) {
|
|
147
228
|
var typeDefinition_1 = namespace.nonModels[type.nonModel];
|
|
148
|
-
nested_1.push(name
|
|
229
|
+
nested_1.push("".concat(name, " { ").concat(generateSelectionSet(namespace, typeDefinition_1), " }"));
|
|
149
230
|
}
|
|
150
231
|
});
|
|
151
|
-
result.push(name
|
|
232
|
+
result.push("".concat(name, " { ").concat(scalarFields.join(' '), " ").concat(nested_1.join(' '), " }"));
|
|
152
233
|
}
|
|
153
234
|
});
|
|
154
235
|
return result;
|
|
@@ -158,7 +239,7 @@ export function getAuthorizationRules(modelDefinition) {
|
|
|
158
239
|
var authConfig = []
|
|
159
240
|
.concat(modelDefinition.attributes || [])
|
|
160
241
|
.find(function (attr) { return attr && attr.type === 'auth'; });
|
|
161
|
-
var _a = (authConfig || {}).properties, _b =
|
|
242
|
+
var _a = (authConfig || {}).properties, _b = _a === void 0 ? {} : _a, _c = _b.rules, rules = _c === void 0 ? [] : _c;
|
|
162
243
|
var resultRules = [];
|
|
163
244
|
// Multiple rules can be declared for allow: owner
|
|
164
245
|
rules.forEach(function (rule) {
|
|
@@ -186,7 +267,7 @@ export function getAuthorizationRules(modelDefinition) {
|
|
|
186
267
|
.concat(modelDefinition.attributes || [])
|
|
187
268
|
.find(function (attr) { return attr && attr.type === 'model'; });
|
|
188
269
|
// find the subscriptions level. ON is default
|
|
189
|
-
var _j = (modelConfig || {}).properties, _k =
|
|
270
|
+
var _j = (modelConfig || {}).properties, _k = _j === void 0 ? {} : _j, _l = _k.subscriptions, _m = _l === void 0 ? {} : _l, _o = _m.level, level = _o === void 0 ? 'on' : _o;
|
|
190
271
|
// treat subscriptions as public for owner auth with unprotected reads
|
|
191
272
|
// when `read` is omitted from `operations`
|
|
192
273
|
authRule.areSubscriptionsPublic =
|
|
@@ -205,23 +286,23 @@ export function buildSubscriptionGraphQLOperation(namespace, modelDefinition, tr
|
|
|
205
286
|
if (filterArg === void 0) { filterArg = false; }
|
|
206
287
|
var selectionSet = generateSelectionSet(namespace, modelDefinition);
|
|
207
288
|
var typeName = modelDefinition.name;
|
|
208
|
-
var opName = "on"
|
|
289
|
+
var opName = "on".concat(transformerMutationType).concat(typeName);
|
|
209
290
|
var docArgs = [];
|
|
210
291
|
var opArgs = [];
|
|
211
292
|
if (filterArg) {
|
|
212
|
-
docArgs.push("$filter: ModelSubscription"
|
|
293
|
+
docArgs.push("$filter: ModelSubscription".concat(typeName, "FilterInput"));
|
|
213
294
|
opArgs.push('filter: $filter');
|
|
214
295
|
}
|
|
215
296
|
if (isOwnerAuthorization) {
|
|
216
|
-
docArgs.push("$"
|
|
217
|
-
opArgs.push(ownerField
|
|
297
|
+
docArgs.push("$".concat(ownerField, ": String!"));
|
|
298
|
+
opArgs.push("".concat(ownerField, ": $").concat(ownerField));
|
|
218
299
|
}
|
|
219
|
-
var docStr = docArgs.length ? "("
|
|
220
|
-
var opStr = opArgs.length ? "("
|
|
300
|
+
var docStr = docArgs.length ? "(".concat(docArgs.join(','), ")") : '';
|
|
301
|
+
var opStr = opArgs.length ? "(".concat(opArgs.join(','), ")") : '';
|
|
221
302
|
return [
|
|
222
303
|
transformerMutationType,
|
|
223
304
|
opName,
|
|
224
|
-
"subscription operation"
|
|
305
|
+
"subscription operation".concat(docStr, "{\n\t\t\t").concat(opName).concat(opStr, "{\n\t\t\t\t").concat(selectionSet, "\n\t\t\t}\n\t\t}"),
|
|
225
306
|
];
|
|
226
307
|
}
|
|
227
308
|
export function buildGraphQLOperation(namespace, modelDefinition, graphQLOpType) {
|
|
@@ -233,44 +314,44 @@ export function buildGraphQLOperation(namespace, modelDefinition, graphQLOpType)
|
|
|
233
314
|
var transformerMutationType;
|
|
234
315
|
switch (graphQLOpType) {
|
|
235
316
|
case 'LIST':
|
|
236
|
-
operation = "sync"
|
|
237
|
-
documentArgs = "($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: Model"
|
|
317
|
+
operation = "sync".concat(pluralTypeName);
|
|
318
|
+
documentArgs = "($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: Model".concat(typeName, "FilterInput)");
|
|
238
319
|
operationArgs =
|
|
239
320
|
'(limit: $limit, nextToken: $nextToken, lastSync: $lastSync, filter: $filter)';
|
|
240
|
-
selectionSet = "items {\n\t\t\t\t\t\t\t"
|
|
321
|
+
selectionSet = "items {\n\t\t\t\t\t\t\t".concat(selectionSet, "\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnextToken\n\t\t\t\t\t\tstartedAt");
|
|
241
322
|
break;
|
|
242
323
|
case 'CREATE':
|
|
243
|
-
operation = "create"
|
|
244
|
-
documentArgs = "($input: Create"
|
|
324
|
+
operation = "create".concat(typeName);
|
|
325
|
+
documentArgs = "($input: Create".concat(typeName, "Input!)");
|
|
245
326
|
operationArgs = '(input: $input)';
|
|
246
327
|
transformerMutationType = TransformerMutationType.CREATE;
|
|
247
328
|
break;
|
|
248
329
|
case 'UPDATE':
|
|
249
|
-
operation = "update"
|
|
250
|
-
documentArgs = "($input: Update"
|
|
330
|
+
operation = "update".concat(typeName);
|
|
331
|
+
documentArgs = "($input: Update".concat(typeName, "Input!, $condition: Model").concat(typeName, "ConditionInput)");
|
|
251
332
|
operationArgs = '(input: $input, condition: $condition)';
|
|
252
333
|
transformerMutationType = TransformerMutationType.UPDATE;
|
|
253
334
|
break;
|
|
254
335
|
case 'DELETE':
|
|
255
|
-
operation = "delete"
|
|
256
|
-
documentArgs = "($input: Delete"
|
|
336
|
+
operation = "delete".concat(typeName);
|
|
337
|
+
documentArgs = "($input: Delete".concat(typeName, "Input!, $condition: Model").concat(typeName, "ConditionInput)");
|
|
257
338
|
operationArgs = '(input: $input, condition: $condition)';
|
|
258
339
|
transformerMutationType = TransformerMutationType.DELETE;
|
|
259
340
|
break;
|
|
260
341
|
case 'GET':
|
|
261
|
-
operation = "get"
|
|
342
|
+
operation = "get".concat(typeName);
|
|
262
343
|
documentArgs = "($id: ID!)";
|
|
263
344
|
operationArgs = '(id: $id)';
|
|
264
345
|
transformerMutationType = TransformerMutationType.GET;
|
|
265
346
|
break;
|
|
266
347
|
default:
|
|
267
|
-
throw new Error("Invalid graphQlOpType "
|
|
348
|
+
throw new Error("Invalid graphQlOpType ".concat(graphQLOpType));
|
|
268
349
|
}
|
|
269
350
|
return [
|
|
270
351
|
[
|
|
271
352
|
transformerMutationType,
|
|
272
353
|
operation,
|
|
273
|
-
GraphQLOperationType[graphQLOpType]
|
|
354
|
+
"".concat(GraphQLOperationType[graphQLOpType], " operation").concat(documentArgs, "{\n\t\t").concat(operation).concat(operationArgs, "{\n\t\t\t").concat(selectionSet, "\n\t\t}\n\t}"),
|
|
274
355
|
],
|
|
275
356
|
];
|
|
276
357
|
}
|
|
@@ -287,7 +368,7 @@ export function createMutationInstanceFromModelOperation(relationships, modelDef
|
|
|
287
368
|
operation = TransformerMutationType.DELETE;
|
|
288
369
|
break;
|
|
289
370
|
default:
|
|
290
|
-
throw new Error("Invalid opType "
|
|
371
|
+
throw new Error("Invalid opType ".concat(opType));
|
|
291
372
|
}
|
|
292
373
|
// stringify nested objects of type AWSJSON
|
|
293
374
|
// this allows us to return parsed JSON to users (see `castInstanceType()` in datastore.ts),
|
|
@@ -407,14 +488,14 @@ export function filterFields(group) {
|
|
|
407
488
|
if (!group || !Array.isArray(group.predicates))
|
|
408
489
|
return fields;
|
|
409
490
|
var predicates = group.predicates;
|
|
410
|
-
var stack =
|
|
491
|
+
var stack = __spreadArray([], __read(predicates), false);
|
|
411
492
|
while (stack.length > 0) {
|
|
412
493
|
var current = stack.pop();
|
|
413
494
|
if (isPredicateObj(current)) {
|
|
414
495
|
fields.add(current.field);
|
|
415
496
|
}
|
|
416
497
|
else if (isPredicateGroup(current)) {
|
|
417
|
-
stack.push.apply(stack,
|
|
498
|
+
stack.push.apply(stack, __spreadArray([], __read(current.predicates), false));
|
|
418
499
|
}
|
|
419
500
|
}
|
|
420
501
|
return fields;
|
|
@@ -475,7 +556,7 @@ export function countFilterCombinations(group) {
|
|
|
475
556
|
if (type === 'or' && predicates.length > 1) {
|
|
476
557
|
count += predicates.length;
|
|
477
558
|
}
|
|
478
|
-
stack.push.apply(stack,
|
|
559
|
+
stack.push.apply(stack, __spreadArray([], __read(predicates), false));
|
|
479
560
|
}
|
|
480
561
|
}
|
|
481
562
|
// if we didn't encounter any OR groups, default to 1
|
|
@@ -541,7 +622,7 @@ export function repeatedFieldInGroup(group) {
|
|
|
541
622
|
return repeatedField;
|
|
542
623
|
}
|
|
543
624
|
}
|
|
544
|
-
stack.push.apply(stack,
|
|
625
|
+
stack.push.apply(stack, __spreadArray([], __read(predicateGroups), false));
|
|
545
626
|
}
|
|
546
627
|
return null;
|
|
547
628
|
}
|
|
@@ -556,9 +637,9 @@ export var RTFError;
|
|
|
556
637
|
})(RTFError || (RTFError = {}));
|
|
557
638
|
export function generateRTFRemediation(errorType, modelDefinition, predicatesGroup) {
|
|
558
639
|
var selSyncFields = filterFields(predicatesGroup);
|
|
559
|
-
var selSyncFieldStr =
|
|
640
|
+
var selSyncFieldStr = __spreadArray([], __read(selSyncFields), false).join(', ');
|
|
560
641
|
var dynamicAuthModeFields = dynamicAuthFields(modelDefinition);
|
|
561
|
-
var dynamicAuthFieldsStr =
|
|
642
|
+
var dynamicAuthFieldsStr = __spreadArray([], __read(dynamicAuthModeFields), false).join(', ');
|
|
562
643
|
var filterCombinations = countFilterCombinations(predicatesGroup);
|
|
563
644
|
var repeatedField = repeatedFieldInGroup(predicatesGroup);
|
|
564
645
|
switch (errorType) {
|
|
@@ -566,29 +647,29 @@ export function generateRTFRemediation(errorType, modelDefinition, predicatesGro
|
|
|
566
647
|
return ("Your API was generated with an older version of the CLI that doesn't support backend subscription filtering." +
|
|
567
648
|
'To enable backend subscription filtering, upgrade your Amplify CLI to the latest version and push your app by running `amplify upgrade` followed by `amplify push`');
|
|
568
649
|
case RTFError.MaxAttributes: {
|
|
569
|
-
var message = "Your selective sync expression for "
|
|
650
|
+
var message = "Your selective sync expression for ".concat(modelDefinition.name, " contains ").concat(selSyncFields.size, " different model fields: ").concat(selSyncFieldStr, ".\n\n");
|
|
570
651
|
if (dynamicAuthModeFields.size > 0) {
|
|
571
652
|
message +=
|
|
572
653
|
"Note: the number of fields you can use with selective sync is affected by @auth rules configured on the model.\n\n" +
|
|
573
654
|
"Dynamic auth modes, such as owner auth and dynamic group auth each utilize 1 field.\n" +
|
|
574
|
-
|
|
655
|
+
"You currently have ".concat(dynamicAuthModeFields.size, " dynamic auth mode(s) configured on this model: ").concat(dynamicAuthFieldsStr, ".");
|
|
575
656
|
}
|
|
576
657
|
return message;
|
|
577
658
|
}
|
|
578
659
|
case RTFError.MaxCombinations: {
|
|
579
|
-
var message = "Your selective sync expression for "
|
|
660
|
+
var message = "Your selective sync expression for ".concat(modelDefinition.name, " contains ").concat(filterCombinations, " field combinations (total number of predicates in an OR expression).\n\n");
|
|
580
661
|
if (dynamicAuthModeFields.size > 0) {
|
|
581
662
|
message +=
|
|
582
663
|
"Note: the number of fields you can use with selective sync is affected by @auth rules configured on the model.\n\n" +
|
|
583
664
|
"Dynamic auth modes, such as owner auth and dynamic group auth factor in to the number of combinations you're using.\n" +
|
|
584
|
-
|
|
665
|
+
"You currently have ".concat(dynamicAuthModeFields.size, " dynamic auth mode(s) configured on this model: ").concat(dynamicAuthFieldsStr, ".");
|
|
585
666
|
}
|
|
586
667
|
return message;
|
|
587
668
|
}
|
|
588
669
|
case RTFError.RepeatedFieldname:
|
|
589
|
-
return "Your selective sync expression for "
|
|
670
|
+
return "Your selective sync expression for ".concat(modelDefinition.name, " contains multiple entries for ").concat(repeatedField, " in the same AND group.");
|
|
590
671
|
case RTFError.NotGroup:
|
|
591
|
-
return ("Your selective sync expression for "
|
|
672
|
+
return ("Your selective sync expression for ".concat(modelDefinition.name, " uses a `not` group. If you'd like to filter subscriptions in the backend, ") +
|
|
592
673
|
"rewrite your expression using `ne` or `notContains` operators.");
|
|
593
674
|
case RTFError.FieldNotInType:
|
|
594
675
|
// no remediation instructions. We'll surface the message directly
|
|
@@ -658,7 +739,7 @@ export function getModelAuthModes(_a) {
|
|
|
658
739
|
return [3 /*break*/, 4];
|
|
659
740
|
case 3:
|
|
660
741
|
error_1 = _b.sent();
|
|
661
|
-
logger.debug("Error getting auth modes for model: "
|
|
742
|
+
logger.debug("Error getting auth modes for model: ".concat(modelName), error_1);
|
|
662
743
|
return [3 /*break*/, 4];
|
|
663
744
|
case 4: return [2 /*return*/, modelAuthModes];
|
|
664
745
|
}
|
|
@@ -696,27 +777,27 @@ export function getClientSideAuthError(error) {
|
|
|
696
777
|
export function getTokenForCustomAuth(authMode, amplifyConfig) {
|
|
697
778
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
698
779
|
return __awaiter(this, void 0, void 0, function () {
|
|
699
|
-
var _a, functionAuthProvider, token, error_2;
|
|
700
|
-
return __generator(this, function (
|
|
701
|
-
switch (
|
|
780
|
+
var _a, _b, functionAuthProvider, token, error_2;
|
|
781
|
+
return __generator(this, function (_c) {
|
|
782
|
+
switch (_c.label) {
|
|
702
783
|
case 0:
|
|
703
|
-
if (!(authMode ===
|
|
704
|
-
_a = amplifyConfig.authProviders,
|
|
784
|
+
if (!(authMode === 'lambda')) return [3 /*break*/, 6];
|
|
785
|
+
_a = amplifyConfig.authProviders, _b = _a === void 0 ? { functionAuthProvider: null } : _a, functionAuthProvider = _b.functionAuthProvider;
|
|
705
786
|
if (!(functionAuthProvider && typeof functionAuthProvider === 'function')) return [3 /*break*/, 5];
|
|
706
|
-
|
|
787
|
+
_c.label = 1;
|
|
707
788
|
case 1:
|
|
708
|
-
|
|
789
|
+
_c.trys.push([1, 3, , 4]);
|
|
709
790
|
return [4 /*yield*/, functionAuthProvider()];
|
|
710
791
|
case 2:
|
|
711
|
-
token = (
|
|
792
|
+
token = (_c.sent()).token;
|
|
712
793
|
return [2 /*return*/, token];
|
|
713
794
|
case 3:
|
|
714
|
-
error_2 =
|
|
715
|
-
throw new Error("Error retrieving token from `functionAuthProvider`: "
|
|
795
|
+
error_2 = _c.sent();
|
|
796
|
+
throw new Error("Error retrieving token from `functionAuthProvider`: ".concat(error_2));
|
|
716
797
|
case 4: return [3 /*break*/, 6];
|
|
717
798
|
case 5:
|
|
718
799
|
// TODO: add docs link once available
|
|
719
|
-
throw new Error(
|
|
800
|
+
throw new Error('You must provide a `functionAuthProvider` function to `DataStore.configure` when using lambda');
|
|
720
801
|
case 6: return [2 /*return*/];
|
|
721
802
|
}
|
|
722
803
|
});
|
|
@@ -728,4 +809,3 @@ export function getIdentifierValue(modelDefinition, model) {
|
|
|
728
809
|
var idOrPk = pkFieldNames.map(function (f) { return model[f]; }).join(IDENTIFIER_KEY_SEPARATOR);
|
|
729
810
|
return idOrPk;
|
|
730
811
|
}
|
|
731
|
-
//# sourceMappingURL=utils.js.map
|