@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.
Files changed (182) hide show
  1. package/README.md +4 -0
  2. package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
  3. package/lib/authModeStrategies/index.js +3 -3
  4. package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
  5. package/lib/datastore/datastore.d.ts +3 -4
  6. package/lib/datastore/datastore.js +361 -227
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.js +25 -12
  9. package/lib/predicates/index.js +46 -12
  10. package/lib/predicates/next.d.ts +2 -2
  11. package/lib/predicates/next.js +172 -74
  12. package/lib/predicates/sort.js +3 -4
  13. package/lib/ssr/index.js +1 -1
  14. package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
  15. package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
  16. package/lib/storage/adapter/InMemoryStore.js +68 -17
  17. package/lib/storage/adapter/InMemoryStore.native.js +5 -3
  18. package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
  19. package/lib/storage/adapter/StorageAdapterBase.js +154 -85
  20. package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
  21. package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
  22. package/lib/storage/adapter/index.js +0 -1
  23. package/lib/storage/relationship.js +31 -21
  24. package/lib/storage/storage.d.ts +3 -3
  25. package/lib/storage/storage.js +143 -61
  26. package/lib/sync/datastoreConnectivity.d.ts +1 -1
  27. package/lib/sync/datastoreConnectivity.js +57 -9
  28. package/lib/sync/datastoreReachability/index.js +3 -3
  29. package/lib/sync/datastoreReachability/index.native.js +7 -5
  30. package/lib/sync/index.d.ts +1 -1
  31. package/lib/sync/index.js +193 -125
  32. package/lib/sync/merger.js +81 -10
  33. package/lib/sync/outbox.js +101 -30
  34. package/lib/sync/processors/errorMaps.d.ts +1 -1
  35. package/lib/sync/processors/errorMaps.js +41 -6
  36. package/lib/sync/processors/mutation.d.ts +1 -1
  37. package/lib/sync/processors/mutation.js +192 -101
  38. package/lib/sync/processors/subscription.d.ts +4 -1
  39. package/lib/sync/processors/subscription.js +190 -178
  40. package/lib/sync/processors/sync.d.ts +1 -1
  41. package/lib/sync/processors/sync.js +113 -47
  42. package/lib/sync/utils.d.ts +4 -4
  43. package/lib/sync/utils.js +162 -81
  44. package/lib/tsconfig.tsbuildinfo +1 -0
  45. package/lib/types.d.ts +138 -140
  46. package/lib/types.js +40 -5
  47. package/lib/util.d.ts +9 -17
  48. package/lib/util.js +216 -100
  49. package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
  50. package/lib-esm/authModeStrategies/index.js +0 -1
  51. package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
  52. package/lib-esm/datastore/datastore.d.ts +3 -4
  53. package/lib-esm/datastore/datastore.js +206 -77
  54. package/lib-esm/index.d.ts +1 -1
  55. package/lib-esm/index.js +0 -1
  56. package/lib-esm/predicates/index.js +40 -7
  57. package/lib-esm/predicates/next.d.ts +2 -2
  58. package/lib-esm/predicates/next.js +148 -52
  59. package/lib-esm/predicates/sort.js +2 -4
  60. package/lib-esm/ssr/index.js +0 -1
  61. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
  62. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
  63. package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
  64. package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
  65. package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
  66. package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
  67. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
  68. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
  69. package/lib-esm/storage/adapter/index.js +1 -1
  70. package/lib-esm/storage/relationship.js +27 -18
  71. package/lib-esm/storage/storage.d.ts +3 -3
  72. package/lib-esm/storage/storage.js +87 -9
  73. package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
  74. package/lib-esm/sync/datastoreConnectivity.js +48 -3
  75. package/lib-esm/sync/datastoreReachability/index.js +1 -2
  76. package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
  77. package/lib-esm/sync/index.d.ts +1 -1
  78. package/lib-esm/sync/index.js +136 -72
  79. package/lib-esm/sync/merger.js +73 -3
  80. package/lib-esm/sync/outbox.js +75 -5
  81. package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
  82. package/lib-esm/sync/processors/errorMaps.js +39 -5
  83. package/lib-esm/sync/processors/mutation.d.ts +1 -1
  84. package/lib-esm/sync/processors/mutation.js +130 -44
  85. package/lib-esm/sync/processors/subscription.d.ts +4 -1
  86. package/lib-esm/sync/processors/subscription.js +134 -126
  87. package/lib-esm/sync/processors/sync.d.ts +1 -1
  88. package/lib-esm/sync/processors/sync.js +74 -12
  89. package/lib-esm/sync/utils.d.ts +4 -4
  90. package/lib-esm/sync/utils.js +135 -55
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  92. package/lib-esm/types.d.ts +138 -140
  93. package/lib-esm/types.js +36 -2
  94. package/lib-esm/util.d.ts +9 -17
  95. package/lib-esm/util.js +96 -16
  96. package/package.json +139 -132
  97. package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
  98. package/src/datastore/datastore.ts +32 -25
  99. package/src/predicates/sort.ts +3 -1
  100. package/src/storage/adapter/InMemoryStore.ts +1 -1
  101. package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
  102. package/src/storage/adapter/StorageAdapterBase.ts +1 -1
  103. package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
  104. package/src/storage/storage.ts +1 -1
  105. package/src/sync/datastoreConnectivity.ts +2 -2
  106. package/src/sync/datastoreReachability/index.native.ts +1 -1
  107. package/src/sync/datastoreReachability/index.ts +1 -1
  108. package/src/sync/index.ts +69 -78
  109. package/src/sync/processors/mutation.ts +16 -10
  110. package/src/sync/processors/subscription.ts +55 -127
  111. package/src/sync/processors/sync.ts +8 -4
  112. package/src/sync/utils.ts +7 -8
  113. package/src/types.ts +4 -8
  114. package/src/util.ts +5 -6
  115. package/lib/.tsbuildinfo +0 -3
  116. package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  117. package/lib/authModeStrategies/index.js.map +0 -1
  118. package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
  119. package/lib/datastore/datastore.js.map +0 -1
  120. package/lib/index.js.map +0 -1
  121. package/lib/predicates/index.js.map +0 -1
  122. package/lib/predicates/next.js.map +0 -1
  123. package/lib/predicates/sort.js.map +0 -1
  124. package/lib/ssr/index.js.map +0 -1
  125. package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  126. package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  127. package/lib/storage/adapter/InMemoryStore.js.map +0 -1
  128. package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
  129. package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
  130. package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
  131. package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  132. package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  133. package/lib/storage/adapter/index.js.map +0 -1
  134. package/lib/storage/relationship.js.map +0 -1
  135. package/lib/storage/storage.js.map +0 -1
  136. package/lib/sync/datastoreConnectivity.js.map +0 -1
  137. package/lib/sync/datastoreReachability/index.js.map +0 -1
  138. package/lib/sync/datastoreReachability/index.native.js.map +0 -1
  139. package/lib/sync/index.js.map +0 -1
  140. package/lib/sync/merger.js.map +0 -1
  141. package/lib/sync/outbox.js.map +0 -1
  142. package/lib/sync/processors/errorMaps.js.map +0 -1
  143. package/lib/sync/processors/mutation.js.map +0 -1
  144. package/lib/sync/processors/subscription.js.map +0 -1
  145. package/lib/sync/processors/sync.js.map +0 -1
  146. package/lib/sync/utils.js.map +0 -1
  147. package/lib/types.js.map +0 -1
  148. package/lib/util.js.map +0 -1
  149. package/lib-esm/.tsbuildinfo +0 -3
  150. package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  151. package/lib-esm/authModeStrategies/index.js.map +0 -1
  152. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
  153. package/lib-esm/datastore/datastore.js.map +0 -1
  154. package/lib-esm/index.js.map +0 -1
  155. package/lib-esm/predicates/index.js.map +0 -1
  156. package/lib-esm/predicates/next.js.map +0 -1
  157. package/lib-esm/predicates/sort.js.map +0 -1
  158. package/lib-esm/ssr/index.js.map +0 -1
  159. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  160. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  161. package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
  162. package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
  163. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
  164. package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
  165. package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  166. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  167. package/lib-esm/storage/adapter/index.js.map +0 -1
  168. package/lib-esm/storage/relationship.js.map +0 -1
  169. package/lib-esm/storage/storage.js.map +0 -1
  170. package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
  171. package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
  172. package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
  173. package/lib-esm/sync/index.js.map +0 -1
  174. package/lib-esm/sync/merger.js.map +0 -1
  175. package/lib-esm/sync/outbox.js.map +0 -1
  176. package/lib-esm/sync/processors/errorMaps.js.map +0 -1
  177. package/lib-esm/sync/processors/mutation.js.map +0 -1
  178. package/lib-esm/sync/processors/subscription.js.map +0 -1
  179. package/lib-esm/sync/processors/sync.js.map +0 -1
  180. package/lib-esm/sync/utils.js.map +0 -1
  181. package/lib-esm/types.js.map +0 -1
  182. package/lib-esm/util.js.map +0 -1
package/lib/sync/utils.js CHANGED
@@ -1,14 +1,96 @@
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 __values = (this && this.__values) || function(o) {
75
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
76
+ if (m) return m.call(o);
77
+ if (o && typeof o.length === "number") return {
78
+ next: function () {
79
+ if (o && i >= o.length) o = void 0;
80
+ return { value: o && o[i++], done: !o };
81
+ }
82
+ };
83
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
84
+ };
2
85
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
86
+ exports.getIdentifierValue = exports.getTokenForCustomAuth = exports.getClientSideAuthError = exports.getForbiddenError = exports.getModelAuthModes = exports.getUserGroupsFromToken = exports.generateRTFRemediation = exports.RTFError = exports.repeatedFieldInGroup = exports.countFilterCombinations = exports.dynamicAuthFields = exports.filterFields = exports.predicateToGraphQLFilter = exports.predicateToGraphQLCondition = exports.createMutationInstanceFromModelOperation = exports.buildGraphQLOperation = exports.buildSubscriptionGraphQLOperation = exports.getAuthorizationRules = exports.generateSelectionSet = exports.getMetadataFields = exports.TransformerMutationType = void 0;
4
87
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
88
  // SPDX-License-Identifier: Apache-2.0
6
- var api_graphql_1 = require("@aws-amplify/api-graphql");
7
89
  var api_1 = require("@aws-amplify/api");
8
- var core_1 = require("@aws-amplify/core");
90
+ var utils_1 = require("@aws-amplify/core/internals/utils");
9
91
  var types_1 = require("../types");
10
92
  var util_1 = require("../util");
11
- var logger = new core_1.Logger('DataStore');
93
+ var logger = new utils_1.Logger('DataStore');
12
94
  var GraphQLOperationType;
13
95
  (function (GraphQLOperationType) {
14
96
  GraphQLOperationType["LIST"] = "query";
@@ -45,7 +127,7 @@ function generateSelectionSet(namespace, modelDefinition) {
45
127
  })
46
128
  .concat(implicitOwnerField)
47
129
  .concat(nonModelFields);
48
- if (types_1.isSchemaModel(modelDefinition)) {
130
+ if ((0, types_1.isSchemaModel)(modelDefinition)) {
49
131
  scalarAndMetadataFields = scalarAndMetadataFields
50
132
  .concat(getMetadataFields())
51
133
  .concat(getConnectionFields(modelDefinition, namespace));
@@ -63,7 +145,7 @@ function getImplicitOwnerField(modelDefinition, scalarFields) {
63
145
  }
64
146
  function getOwnerFields(modelDefinition) {
65
147
  var ownerFields = [];
66
- if (types_1.isSchemaModelWithAttributes(modelDefinition)) {
148
+ if ((0, types_1.isSchemaModelWithAttributes)(modelDefinition)) {
67
149
  modelDefinition.attributes.forEach(function (attr) {
68
150
  if (attr.properties && attr.properties.rules) {
69
151
  var rule = attr.properties.rules.find(function (rule) { return rule.allow === 'owner'; });
@@ -79,7 +161,7 @@ function getScalarFields(modelDefinition) {
79
161
  var fields = modelDefinition.fields;
80
162
  var result = Object.values(fields)
81
163
  .filter(function (field) {
82
- if (types_1.isGraphQLScalarType(field.type) || types_1.isEnumFieldType(field.type)) {
164
+ if ((0, types_1.isGraphQLScalarType)(field.type) || (0, types_1.isEnumFieldType)(field.type)) {
83
165
  return true;
84
166
  }
85
167
  return false;
@@ -107,29 +189,29 @@ function getConnectionFields(modelDefinition, namespace) {
107
189
  // Intentionally blank
108
190
  break;
109
191
  case 'BELONGS_TO':
110
- if (types_1.isTargetNameAssociation(association)) {
192
+ if ((0, types_1.isTargetNameAssociation)(association)) {
111
193
  // New codegen (CPK)
112
194
  if (association.targetNames && association.targetNames.length > 0) {
113
195
  // Need to retrieve relations in order to get connected model keys
114
- var _b = tslib_1.__read(util_1.establishRelationAndKeys(namespace), 1), relations = _b[0];
196
+ var _b = __read((0, util_1.establishRelationAndKeys)(namespace), 1), relations = _b[0];
115
197
  var connectedModelName = modelDefinition.fields[name].type['model'];
116
198
  var byPkIndex = relations[connectedModelName].indexes.find(function (_a) {
117
- var _b = tslib_1.__read(_a, 1), name = _b[0];
199
+ var _b = __read(_a, 1), name = _b[0];
118
200
  return name === 'byPk';
119
201
  });
120
202
  var keyFields = byPkIndex && byPkIndex[1];
121
203
  var keyFieldSelectionSet = keyFields === null || keyFields === void 0 ? void 0 : keyFields.join(' ');
122
204
  // We rely on `_deleted` when we process the sync query (e.g. in batchSave in the adapters)
123
- result.push(name + " { " + keyFieldSelectionSet + " _deleted }");
205
+ result.push("".concat(name, " { ").concat(keyFieldSelectionSet, " _deleted }"));
124
206
  }
125
207
  else {
126
208
  // backwards-compatability for schema generated prior to custom primary key support
127
- result.push(name + " { id _deleted }");
209
+ result.push("".concat(name, " { id _deleted }"));
128
210
  }
129
211
  }
130
212
  break;
131
213
  default:
132
- throw new Error("Invalid connection type " + connectionType);
214
+ throw new Error("Invalid connection type ".concat(connectionType));
133
215
  }
134
216
  });
135
217
  return result;
@@ -138,7 +220,7 @@ function getNonModelFields(namespace, modelDefinition) {
138
220
  var result = [];
139
221
  Object.values(modelDefinition.fields).forEach(function (_a) {
140
222
  var name = _a.name, type = _a.type;
141
- if (types_1.isNonModelFieldType(type)) {
223
+ if ((0, types_1.isNonModelFieldType)(type)) {
142
224
  var typeDefinition = namespace.nonModels[type.nonModel];
143
225
  var scalarFields = Object.values(getScalarFields(typeDefinition)).map(function (_a) {
144
226
  var name = _a.name;
@@ -147,12 +229,12 @@ function getNonModelFields(namespace, modelDefinition) {
147
229
  var nested_1 = [];
148
230
  Object.values(typeDefinition.fields).forEach(function (field) {
149
231
  var type = field.type, name = field.name;
150
- if (types_1.isNonModelFieldType(type)) {
232
+ if ((0, types_1.isNonModelFieldType)(type)) {
151
233
  var typeDefinition_1 = namespace.nonModels[type.nonModel];
152
- nested_1.push(name + " { " + generateSelectionSet(namespace, typeDefinition_1) + " }");
234
+ nested_1.push("".concat(name, " { ").concat(generateSelectionSet(namespace, typeDefinition_1), " }"));
153
235
  }
154
236
  });
155
- result.push(name + " { " + scalarFields.join(' ') + " " + nested_1.join(' ') + " }");
237
+ result.push("".concat(name, " { ").concat(scalarFields.join(' '), " ").concat(nested_1.join(' '), " }"));
156
238
  }
157
239
  });
158
240
  return result;
@@ -162,7 +244,7 @@ function getAuthorizationRules(modelDefinition) {
162
244
  var authConfig = []
163
245
  .concat(modelDefinition.attributes || [])
164
246
  .find(function (attr) { return attr && attr.type === 'auth'; });
165
- var _a = (authConfig || {}).properties, _b = (_a === void 0 ? {} : _a).rules, rules = _b === void 0 ? [] : _b;
247
+ var _a = (authConfig || {}).properties, _b = _a === void 0 ? {} : _a, _c = _b.rules, rules = _c === void 0 ? [] : _c;
166
248
  var resultRules = [];
167
249
  // Multiple rules can be declared for allow: owner
168
250
  rules.forEach(function (rule) {
@@ -190,7 +272,7 @@ function getAuthorizationRules(modelDefinition) {
190
272
  .concat(modelDefinition.attributes || [])
191
273
  .find(function (attr) { return attr && attr.type === 'model'; });
192
274
  // find the subscriptions level. ON is default
193
- var _j = (modelConfig || {}).properties, _k = (_j === void 0 ? {} : _j).subscriptions, _l = (_k === void 0 ? {} : _k).level, level = _l === void 0 ? 'on' : _l;
275
+ 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;
194
276
  // treat subscriptions as public for owner auth with unprotected reads
195
277
  // when `read` is omitted from `operations`
196
278
  authRule.areSubscriptionsPublic =
@@ -210,23 +292,23 @@ function buildSubscriptionGraphQLOperation(namespace, modelDefinition, transform
210
292
  if (filterArg === void 0) { filterArg = false; }
211
293
  var selectionSet = generateSelectionSet(namespace, modelDefinition);
212
294
  var typeName = modelDefinition.name;
213
- var opName = "on" + transformerMutationType + typeName;
295
+ var opName = "on".concat(transformerMutationType).concat(typeName);
214
296
  var docArgs = [];
215
297
  var opArgs = [];
216
298
  if (filterArg) {
217
- docArgs.push("$filter: ModelSubscription" + typeName + "FilterInput");
299
+ docArgs.push("$filter: ModelSubscription".concat(typeName, "FilterInput"));
218
300
  opArgs.push('filter: $filter');
219
301
  }
220
302
  if (isOwnerAuthorization) {
221
- docArgs.push("$" + ownerField + ": String!");
222
- opArgs.push(ownerField + ": $" + ownerField);
303
+ docArgs.push("$".concat(ownerField, ": String!"));
304
+ opArgs.push("".concat(ownerField, ": $").concat(ownerField));
223
305
  }
224
- var docStr = docArgs.length ? "(" + docArgs.join(',') + ")" : '';
225
- var opStr = opArgs.length ? "(" + opArgs.join(',') + ")" : '';
306
+ var docStr = docArgs.length ? "(".concat(docArgs.join(','), ")") : '';
307
+ var opStr = opArgs.length ? "(".concat(opArgs.join(','), ")") : '';
226
308
  return [
227
309
  transformerMutationType,
228
310
  opName,
229
- "subscription operation" + docStr + "{\n\t\t\t" + opName + opStr + "{\n\t\t\t\t" + selectionSet + "\n\t\t\t}\n\t\t}",
311
+ "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}"),
230
312
  ];
231
313
  }
232
314
  exports.buildSubscriptionGraphQLOperation = buildSubscriptionGraphQLOperation;
@@ -239,44 +321,44 @@ function buildGraphQLOperation(namespace, modelDefinition, graphQLOpType) {
239
321
  var transformerMutationType;
240
322
  switch (graphQLOpType) {
241
323
  case 'LIST':
242
- operation = "sync" + pluralTypeName;
243
- documentArgs = "($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: Model" + typeName + "FilterInput)";
324
+ operation = "sync".concat(pluralTypeName);
325
+ documentArgs = "($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: Model".concat(typeName, "FilterInput)");
244
326
  operationArgs =
245
327
  '(limit: $limit, nextToken: $nextToken, lastSync: $lastSync, filter: $filter)';
246
- selectionSet = "items {\n\t\t\t\t\t\t\t" + selectionSet + "\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnextToken\n\t\t\t\t\t\tstartedAt";
328
+ 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");
247
329
  break;
248
330
  case 'CREATE':
249
- operation = "create" + typeName;
250
- documentArgs = "($input: Create" + typeName + "Input!)";
331
+ operation = "create".concat(typeName);
332
+ documentArgs = "($input: Create".concat(typeName, "Input!)");
251
333
  operationArgs = '(input: $input)';
252
334
  transformerMutationType = TransformerMutationType.CREATE;
253
335
  break;
254
336
  case 'UPDATE':
255
- operation = "update" + typeName;
256
- documentArgs = "($input: Update" + typeName + "Input!, $condition: Model" + typeName + "ConditionInput)";
337
+ operation = "update".concat(typeName);
338
+ documentArgs = "($input: Update".concat(typeName, "Input!, $condition: Model").concat(typeName, "ConditionInput)");
257
339
  operationArgs = '(input: $input, condition: $condition)';
258
340
  transformerMutationType = TransformerMutationType.UPDATE;
259
341
  break;
260
342
  case 'DELETE':
261
- operation = "delete" + typeName;
262
- documentArgs = "($input: Delete" + typeName + "Input!, $condition: Model" + typeName + "ConditionInput)";
343
+ operation = "delete".concat(typeName);
344
+ documentArgs = "($input: Delete".concat(typeName, "Input!, $condition: Model").concat(typeName, "ConditionInput)");
263
345
  operationArgs = '(input: $input, condition: $condition)';
264
346
  transformerMutationType = TransformerMutationType.DELETE;
265
347
  break;
266
348
  case 'GET':
267
- operation = "get" + typeName;
349
+ operation = "get".concat(typeName);
268
350
  documentArgs = "($id: ID!)";
269
351
  operationArgs = '(id: $id)';
270
352
  transformerMutationType = TransformerMutationType.GET;
271
353
  break;
272
354
  default:
273
- throw new Error("Invalid graphQlOpType " + graphQLOpType);
355
+ throw new Error("Invalid graphQlOpType ".concat(graphQLOpType));
274
356
  }
275
357
  return [
276
358
  [
277
359
  transformerMutationType,
278
360
  operation,
279
- GraphQLOperationType[graphQLOpType] + " operation" + documentArgs + "{\n\t\t" + operation + operationArgs + "{\n\t\t\t" + selectionSet + "\n\t\t}\n\t}",
361
+ "".concat(GraphQLOperationType[graphQLOpType], " operation").concat(documentArgs, "{\n\t\t").concat(operation).concat(operationArgs, "{\n\t\t\t").concat(selectionSet, "\n\t\t}\n\t}"),
280
362
  ],
281
363
  ];
282
364
  }
@@ -294,7 +376,7 @@ function createMutationInstanceFromModelOperation(relationships, modelDefinition
294
376
  operation = TransformerMutationType.DELETE;
295
377
  break;
296
378
  default:
297
- throw new Error("Invalid opType " + opType);
379
+ throw new Error("Invalid opType ".concat(opType));
298
380
  }
299
381
  // stringify nested objects of type AWSJSON
300
382
  // this allows us to return parsed JSON to users (see `castInstanceType()` in datastore.ts),
@@ -312,7 +394,7 @@ function createMutationInstanceFromModelOperation(relationships, modelDefinition
312
394
  };
313
395
  var modelId = getIdentifierValue(modelDefinition, element);
314
396
  var optionalId = types_1.OpType.INSERT && id ? { id: id } : {};
315
- var mutationEvent = modelInstanceCreator(MutationEventConstructor, tslib_1.__assign(tslib_1.__assign({}, optionalId), { data: JSON.stringify(element, replacer), modelId: modelId, model: model.name, operation: operation, condition: JSON.stringify(condition) }));
397
+ var mutationEvent = modelInstanceCreator(MutationEventConstructor, __assign(__assign({}, optionalId), { data: JSON.stringify(element, replacer), modelId: modelId, model: model.name, operation: operation, condition: JSON.stringify(condition) }));
316
398
  return mutationEvent;
317
399
  }
318
400
  exports.createMutationInstanceFromModelOperation = createMutationInstanceFromModelOperation;
@@ -328,7 +410,7 @@ function predicateToGraphQLCondition(predicate, modelDefinition) {
328
410
  // Or all records where PK = some value but SKs are different values
329
411
  // TODO: if the Transform gets updated we'll need to modify this logic to only omit
330
412
  // key fields from the predicate/condition when ALL of the keyFields are present and using `eq` operators
331
- var keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
413
+ var keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
332
414
  return predicateToGraphQLFilter(predicate, keyFields);
333
415
  }
334
416
  exports.predicateToGraphQLCondition = predicateToGraphQLCondition;
@@ -360,7 +442,7 @@ function predicateToGraphQLFilter(predicatesGroup, fieldsToOmit, root) {
360
442
  var children = [];
361
443
  predicates.forEach(function (predicate) {
362
444
  var _a, _b;
363
- if (types_1.isPredicateObj(predicate)) {
445
+ if ((0, types_1.isPredicateObj)(predicate)) {
364
446
  var field = predicate.field, operator = predicate.operator, operand = predicate.operand;
365
447
  if (fieldsToOmit.includes(field))
366
448
  return;
@@ -377,7 +459,7 @@ function predicateToGraphQLFilter(predicatesGroup, fieldsToOmit, root) {
377
459
  });
378
460
  // flatten redundant list predicates
379
461
  if (children.length === 1) {
380
- var _a = tslib_1.__read(children, 1), child = _a[0];
462
+ var _a = __read(children, 1), child = _a[0];
381
463
  if (
382
464
  // any nested list node
383
465
  (isList && !root) ||
@@ -417,14 +499,14 @@ function filterFields(group) {
417
499
  if (!group || !Array.isArray(group.predicates))
418
500
  return fields;
419
501
  var predicates = group.predicates;
420
- var stack = tslib_1.__spread(predicates);
502
+ var stack = __spreadArray([], __read(predicates), false);
421
503
  while (stack.length > 0) {
422
504
  var current = stack.pop();
423
- if (types_1.isPredicateObj(current)) {
505
+ if ((0, types_1.isPredicateObj)(current)) {
424
506
  fields.add(current.field);
425
507
  }
426
- else if (types_1.isPredicateGroup(current)) {
427
- stack.push.apply(stack, tslib_1.__spread(current.predicates));
508
+ else if ((0, types_1.isPredicateGroup)(current)) {
509
+ stack.push.apply(stack, __spreadArray([], __read(current.predicates), false));
428
510
  }
429
511
  }
430
512
  return fields;
@@ -440,7 +522,7 @@ function dynamicAuthFields(modelDefinition) {
440
522
  var rules = getAuthorizationRules(modelDefinition);
441
523
  var fields = new Set();
442
524
  try {
443
- for (var rules_1 = tslib_1.__values(rules), rules_1_1 = rules_1.next(); !rules_1_1.done; rules_1_1 = rules_1.next()) {
525
+ for (var rules_1 = __values(rules), rules_1_1 = rules_1.next(); !rules_1_1.done; rules_1_1 = rules_1.next()) {
444
526
  var rule = rules_1_1.value;
445
527
  if (rule.groupsField && !rule.groups.length) {
446
528
  // dynamic group rule will have no values in `rule.groups`
@@ -481,13 +563,13 @@ function countFilterCombinations(group) {
481
563
  var stack = [group];
482
564
  while (stack.length > 0) {
483
565
  var current = stack.pop();
484
- if (types_1.isPredicateGroup(current)) {
566
+ if ((0, types_1.isPredicateGroup)(current)) {
485
567
  var predicates = current.predicates, type = current.type;
486
568
  // ignore length = 1; groups with 1 predicate will get flattened when converted to gqlFilter
487
569
  if (type === 'or' && predicates.length > 1) {
488
570
  count += predicates.length;
489
571
  }
490
- stack.push.apply(stack, tslib_1.__spread(predicates));
572
+ stack.push.apply(stack, __spreadArray([], __read(predicates), false));
491
573
  }
492
574
  }
493
575
  // if we didn't encounter any OR groups, default to 1
@@ -517,9 +599,9 @@ function repeatedFieldInGroup(group) {
517
599
  var e_2, _a;
518
600
  var seen = {};
519
601
  try {
520
- for (var fields_1 = tslib_1.__values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) {
602
+ for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) {
521
603
  var f = fields_1_1.value;
522
- var _b = tslib_1.__read(Object.keys(f), 1), fieldName = _b[0];
604
+ var _b = __read(Object.keys(f), 1), fieldName = _b[0];
523
605
  if (seen[fieldName]) {
524
606
  return fieldName;
525
607
  }
@@ -537,7 +619,7 @@ function repeatedFieldInGroup(group) {
537
619
  };
538
620
  while (stack.length > 0) {
539
621
  var current = stack.pop();
540
- var _a = tslib_1.__read(Object.keys(current), 1), key = _a[0];
622
+ var _a = __read(Object.keys(current), 1), key = _a[0];
541
623
  var values = current[key];
542
624
  if (!Array.isArray(values)) {
543
625
  return null;
@@ -554,7 +636,7 @@ function repeatedFieldInGroup(group) {
554
636
  return repeatedField;
555
637
  }
556
638
  }
557
- stack.push.apply(stack, tslib_1.__spread(predicateGroups));
639
+ stack.push.apply(stack, __spreadArray([], __read(predicateGroups), false));
558
640
  }
559
641
  return null;
560
642
  }
@@ -570,9 +652,9 @@ var RTFError;
570
652
  })(RTFError = exports.RTFError || (exports.RTFError = {}));
571
653
  function generateRTFRemediation(errorType, modelDefinition, predicatesGroup) {
572
654
  var selSyncFields = filterFields(predicatesGroup);
573
- var selSyncFieldStr = tslib_1.__spread(selSyncFields).join(', ');
655
+ var selSyncFieldStr = __spreadArray([], __read(selSyncFields), false).join(', ');
574
656
  var dynamicAuthModeFields = dynamicAuthFields(modelDefinition);
575
- var dynamicAuthFieldsStr = tslib_1.__spread(dynamicAuthModeFields).join(', ');
657
+ var dynamicAuthFieldsStr = __spreadArray([], __read(dynamicAuthModeFields), false).join(', ');
576
658
  var filterCombinations = countFilterCombinations(predicatesGroup);
577
659
  var repeatedField = repeatedFieldInGroup(predicatesGroup);
578
660
  switch (errorType) {
@@ -580,29 +662,29 @@ function generateRTFRemediation(errorType, modelDefinition, predicatesGroup) {
580
662
  return ("Your API was generated with an older version of the CLI that doesn't support backend subscription filtering." +
581
663
  '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`');
582
664
  case RTFError.MaxAttributes: {
583
- var message = "Your selective sync expression for " + modelDefinition.name + " contains " + selSyncFields.size + " different model fields: " + selSyncFieldStr + ".\n\n";
665
+ var message = "Your selective sync expression for ".concat(modelDefinition.name, " contains ").concat(selSyncFields.size, " different model fields: ").concat(selSyncFieldStr, ".\n\n");
584
666
  if (dynamicAuthModeFields.size > 0) {
585
667
  message +=
586
668
  "Note: the number of fields you can use with selective sync is affected by @auth rules configured on the model.\n\n" +
587
669
  "Dynamic auth modes, such as owner auth and dynamic group auth each utilize 1 field.\n" +
588
- ("You currently have " + dynamicAuthModeFields.size + " dynamic auth mode(s) configured on this model: " + dynamicAuthFieldsStr + ".");
670
+ "You currently have ".concat(dynamicAuthModeFields.size, " dynamic auth mode(s) configured on this model: ").concat(dynamicAuthFieldsStr, ".");
589
671
  }
590
672
  return message;
591
673
  }
592
674
  case RTFError.MaxCombinations: {
593
- var message = "Your selective sync expression for " + modelDefinition.name + " contains " + filterCombinations + " field combinations (total number of predicates in an OR expression).\n\n";
675
+ 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");
594
676
  if (dynamicAuthModeFields.size > 0) {
595
677
  message +=
596
678
  "Note: the number of fields you can use with selective sync is affected by @auth rules configured on the model.\n\n" +
597
679
  "Dynamic auth modes, such as owner auth and dynamic group auth factor in to the number of combinations you're using.\n" +
598
- ("You currently have " + dynamicAuthModeFields.size + " dynamic auth mode(s) configured on this model: " + dynamicAuthFieldsStr + ".");
680
+ "You currently have ".concat(dynamicAuthModeFields.size, " dynamic auth mode(s) configured on this model: ").concat(dynamicAuthFieldsStr, ".");
599
681
  }
600
682
  return message;
601
683
  }
602
684
  case RTFError.RepeatedFieldname:
603
- return "Your selective sync expression for " + modelDefinition.name + " contains multiple entries for " + repeatedField + " in the same AND group.";
685
+ return "Your selective sync expression for ".concat(modelDefinition.name, " contains multiple entries for ").concat(repeatedField, " in the same AND group.");
604
686
  case RTFError.NotGroup:
605
- return ("Your selective sync expression for " + modelDefinition.name + " uses a `not` group. If you'd like to filter subscriptions in the backend, " +
687
+ return ("Your selective sync expression for ".concat(modelDefinition.name, " uses a `not` group. If you'd like to filter subscriptions in the backend, ") +
606
688
  "rewrite your expression using `ne` or `notContains` operators.");
607
689
  case RTFError.FieldNotInType:
608
690
  // no remediation instructions. We'll surface the message directly
@@ -628,10 +710,10 @@ function getUserGroupsFromToken(token, rule) {
628
710
  exports.getUserGroupsFromToken = getUserGroupsFromToken;
629
711
  function getModelAuthModes(_a) {
630
712
  var authModeStrategy = _a.authModeStrategy, defaultAuthMode = _a.defaultAuthMode, modelName = _a.modelName, schema = _a.schema;
631
- return tslib_1.__awaiter(this, void 0, void 0, function () {
713
+ return __awaiter(this, void 0, void 0, function () {
632
714
  var operations, modelAuthModes, error_1;
633
715
  var _this = this;
634
- return tslib_1.__generator(this, function (_b) {
716
+ return __generator(this, function (_b) {
635
717
  switch (_b.label) {
636
718
  case 0:
637
719
  operations = Object.values(types_1.ModelOperation);
@@ -644,9 +726,9 @@ function getModelAuthModes(_a) {
644
726
  _b.label = 1;
645
727
  case 1:
646
728
  _b.trys.push([1, 3, , 4]);
647
- return [4 /*yield*/, Promise.all(operations.map(function (operation) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
729
+ return [4 /*yield*/, Promise.all(operations.map(function (operation) { return __awaiter(_this, void 0, void 0, function () {
648
730
  var authModes;
649
- return tslib_1.__generator(this, function (_a) {
731
+ return __generator(this, function (_a) {
650
732
  switch (_a.label) {
651
733
  case 0: return [4 /*yield*/, authModeStrategy({
652
734
  schema: schema,
@@ -674,7 +756,7 @@ function getModelAuthModes(_a) {
674
756
  return [3 /*break*/, 4];
675
757
  case 3:
676
758
  error_1 = _b.sent();
677
- logger.debug("Error getting auth modes for model: " + modelName, error_1);
759
+ logger.debug("Error getting auth modes for model: ".concat(modelName), error_1);
678
760
  return [3 /*break*/, 4];
679
761
  case 4: return [2 /*return*/, modelAuthModes];
680
762
  }
@@ -714,28 +796,28 @@ function getClientSideAuthError(error) {
714
796
  exports.getClientSideAuthError = getClientSideAuthError;
715
797
  function getTokenForCustomAuth(authMode, amplifyConfig) {
716
798
  if (amplifyConfig === void 0) { amplifyConfig = {}; }
717
- return tslib_1.__awaiter(this, void 0, void 0, function () {
718
- var _a, functionAuthProvider, token, error_2;
719
- return tslib_1.__generator(this, function (_b) {
720
- switch (_b.label) {
799
+ return __awaiter(this, void 0, void 0, function () {
800
+ var _a, _b, functionAuthProvider, token, error_2;
801
+ return __generator(this, function (_c) {
802
+ switch (_c.label) {
721
803
  case 0:
722
- if (!(authMode === api_graphql_1.GRAPHQL_AUTH_MODE.AWS_LAMBDA)) return [3 /*break*/, 6];
723
- _a = amplifyConfig.authProviders, functionAuthProvider = (_a === void 0 ? { functionAuthProvider: null } : _a).functionAuthProvider;
804
+ if (!(authMode === 'lambda')) return [3 /*break*/, 6];
805
+ _a = amplifyConfig.authProviders, _b = _a === void 0 ? { functionAuthProvider: null } : _a, functionAuthProvider = _b.functionAuthProvider;
724
806
  if (!(functionAuthProvider && typeof functionAuthProvider === 'function')) return [3 /*break*/, 5];
725
- _b.label = 1;
807
+ _c.label = 1;
726
808
  case 1:
727
- _b.trys.push([1, 3, , 4]);
809
+ _c.trys.push([1, 3, , 4]);
728
810
  return [4 /*yield*/, functionAuthProvider()];
729
811
  case 2:
730
- token = (_b.sent()).token;
812
+ token = (_c.sent()).token;
731
813
  return [2 /*return*/, token];
732
814
  case 3:
733
- error_2 = _b.sent();
734
- throw new Error("Error retrieving token from `functionAuthProvider`: " + error_2);
815
+ error_2 = _c.sent();
816
+ throw new Error("Error retrieving token from `functionAuthProvider`: ".concat(error_2));
735
817
  case 4: return [3 /*break*/, 6];
736
818
  case 5:
737
819
  // TODO: add docs link once available
738
- throw new Error("You must provide a `functionAuthProvider` function to `DataStore.configure` when using " + api_graphql_1.GRAPHQL_AUTH_MODE.AWS_LAMBDA);
820
+ throw new Error('You must provide a `functionAuthProvider` function to `DataStore.configure` when using lambda');
739
821
  case 6: return [2 /*return*/];
740
822
  }
741
823
  });
@@ -744,9 +826,8 @@ function getTokenForCustomAuth(authMode, amplifyConfig) {
744
826
  exports.getTokenForCustomAuth = getTokenForCustomAuth;
745
827
  // Util that takes a modelDefinition and model and returns either the id value(s) or the custom primary key value(s)
746
828
  function getIdentifierValue(modelDefinition, model) {
747
- var pkFieldNames = util_1.extractPrimaryKeyFieldNames(modelDefinition);
829
+ var pkFieldNames = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
748
830
  var idOrPk = pkFieldNames.map(function (f) { return model[f]; }).join(util_1.IDENTIFIER_KEY_SEPARATOR);
749
831
  return idOrPk;
750
832
  }
751
833
  exports.getIdentifierValue = getIdentifierValue;
752
- //# sourceMappingURL=utils.js.map