@aws-amplify/datastore 5.0.1-api-v6-models.c1977f8.0 → 5.0.1-api-v6-models.891fe0d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +29 -105
- package/lib/datastore/datastore.js +887 -1370
- package/lib/index.js +1 -1
- package/lib/predicates/index.js +53 -102
- package/lib/predicates/next.js +310 -557
- package/lib/predicates/sort.js +24 -27
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +115 -449
- package/lib/storage/adapter/AsyncStorageDatabase.js +215 -480
- package/lib/storage/adapter/InMemoryStore.js +27 -101
- package/lib/storage/adapter/InMemoryStore.native.js +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +441 -1002
- package/lib/storage/adapter/StorageAdapterBase.js +177 -396
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -6
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -2
- package/lib/storage/relationship.js +174 -260
- package/lib/storage/storage.js +244 -507
- package/lib/sync/datastoreConnectivity.js +29 -84
- package/lib/sync/datastoreReachability/index.js +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -2
- package/lib/sync/index.js +512 -885
- package/lib/sync/merger.js +30 -133
- package/lib/sync/outbox.js +147 -302
- package/lib/sync/processors/errorMaps.js +30 -80
- package/lib/sync/processors/mutation.js +331 -579
- package/lib/sync/processors/subscription.js +268 -428
- package/lib/sync/processors/sync.js +276 -464
- package/lib/sync/utils.js +248 -393
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.js +16 -58
- package/lib/util.js +335 -575
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +27 -103
- package/lib-esm/datastore/datastore.js +874 -1359
- package/lib-esm/index.js +6 -6
- package/lib-esm/predicates/index.js +54 -104
- package/lib-esm/predicates/next.js +306 -555
- package/lib-esm/predicates/sort.js +24 -27
- package/lib-esm/ssr/index.js +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -446
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -477
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -102
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +436 -997
- package/lib-esm/storage/adapter/StorageAdapterBase.js +172 -392
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -3
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -1
- package/lib-esm/storage/relationship.js +173 -260
- package/lib-esm/storage/storage.js +236 -499
- package/lib-esm/sync/datastoreConnectivity.js +26 -82
- package/lib-esm/sync/datastoreReachability/index.js +1 -1
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -1
- package/lib-esm/sync/index.js +498 -872
- package/lib-esm/sync/merger.js +28 -131
- package/lib-esm/sync/outbox.js +143 -298
- package/lib-esm/sync/processors/errorMaps.js +32 -82
- package/lib-esm/sync/processors/mutation.js +324 -572
- package/lib-esm/sync/processors/subscription.js +258 -418
- package/lib-esm/sync/processors/sync.js +269 -457
- package/lib-esm/sync/utils.js +245 -390
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types.js +16 -59
- package/lib-esm/util.js +335 -577
- package/package.json +12 -12
- package/src/datastore/datastore.ts +4 -3
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -3
- package/src/sync/processors/mutation.ts +1 -1
- package/src/sync/processors/sync.ts +1 -1
- package/src/sync/utils.ts +1 -1
- package/src/util.ts +44 -6
package/lib/util.js
CHANGED
|
@@ -1,97 +1,14 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
66
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
67
|
-
if (m) return m.call(o);
|
|
68
|
-
if (o && typeof o.length === "number") return {
|
|
69
|
-
next: function () {
|
|
70
|
-
if (o && i >= o.length) o = void 0;
|
|
71
|
-
return { value: o && o[i++], done: !o };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
75
|
-
};
|
|
76
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
77
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
-
if (ar || !(i in from)) {
|
|
79
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
-
ar[i] = from[i];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
-
};
|
|
85
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
3
|
exports.getIndexFromAssociation = exports.getIndex = exports.establishRelationAndKeys = exports.isIdOptionallyManaged = exports.isIdManaged = exports.extractPrimaryKeysAndValues = exports.extractPrimaryKeyValues = exports.extractPrimaryKeyFieldNames = exports.extractKeyIfExists = exports.processCompositeKeys = exports.getStorename = exports.mergePatches = exports.DeferredCallbackResolver = exports.DeferredPromise = exports.isAWSIPAddress = exports.isAWSPhone = exports.isAWSURL = exports.isAWSJSON = exports.isAWSEmail = exports.isAWSTimestamp = exports.isAWSDateTime = exports.isAWSTime = exports.isAWSDate = exports.asyncFilter = exports.asyncEvery = exports.asyncSome = exports.inMemoryPagination = exports.valuesEqual = exports.sortCompareFunction = exports.getNow = exports.monotonicUlidFactory = exports.isSafariCompatabilityMode = exports.isPrivateMode = exports.traverseModel = exports.isNonModelConstructor = exports.registerNonModelClass = exports.isModelConstructor = exports.validatePredicateField = exports.validatePredicate = exports.isNullOrUndefined = exports.exhaustiveCheck = exports.DATASTORE = exports.STORAGE = exports.SYNC = exports.USER = exports.NAMESPACES = exports.errorMessages = exports.IDENTIFIER_KEY_SEPARATOR = exports.DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR = exports.ID = void 0;
|
|
87
4
|
exports.getTimestampFields = exports.getIndexKeys = exports.keysEqual = exports.indexNameFromKeys = exports.extractTargetNamesFromSrc = void 0;
|
|
88
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
89
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
7
|
+
const ulid_1 = require("ulid");
|
|
8
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
9
|
+
const immer_1 = require("immer");
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const predicates_1 = require("./predicates");
|
|
95
12
|
exports.ID = 'id';
|
|
96
13
|
/**
|
|
97
14
|
* Used by the Async Storage Adapter to concatenate key values
|
|
@@ -120,28 +37,27 @@ var NAMESPACES;
|
|
|
120
37
|
NAMESPACES["SYNC"] = "sync";
|
|
121
38
|
NAMESPACES["STORAGE"] = "storage";
|
|
122
39
|
})(NAMESPACES = exports.NAMESPACES || (exports.NAMESPACES = {}));
|
|
123
|
-
|
|
40
|
+
const DATASTORE = NAMESPACES.DATASTORE;
|
|
124
41
|
exports.DATASTORE = DATASTORE;
|
|
125
|
-
|
|
42
|
+
const USER = NAMESPACES.USER;
|
|
126
43
|
exports.USER = USER;
|
|
127
|
-
|
|
44
|
+
const SYNC = NAMESPACES.SYNC;
|
|
128
45
|
exports.SYNC = SYNC;
|
|
129
|
-
|
|
46
|
+
const STORAGE = NAMESPACES.STORAGE;
|
|
130
47
|
exports.STORAGE = STORAGE;
|
|
131
|
-
|
|
132
|
-
if (throwOnError === void 0) { throwOnError = true; }
|
|
48
|
+
const exhaustiveCheck = (obj, throwOnError = true) => {
|
|
133
49
|
if (throwOnError) {
|
|
134
|
-
throw new Error(
|
|
50
|
+
throw new Error(`Invalid ${obj}`);
|
|
135
51
|
}
|
|
136
52
|
};
|
|
137
53
|
exports.exhaustiveCheck = exhaustiveCheck;
|
|
138
|
-
|
|
54
|
+
const isNullOrUndefined = (val) => {
|
|
139
55
|
return typeof val === 'undefined' || val === undefined || val === null;
|
|
140
56
|
};
|
|
141
57
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
58
|
+
const validatePredicate = (model, groupType, predicatesOrGroups) => {
|
|
59
|
+
let filterType;
|
|
60
|
+
let isNegation = false;
|
|
145
61
|
if (predicatesOrGroups.length === 0) {
|
|
146
62
|
return true;
|
|
147
63
|
}
|
|
@@ -157,16 +73,16 @@ var validatePredicate = function (model, groupType, predicatesOrGroups) {
|
|
|
157
73
|
filterType = 'some';
|
|
158
74
|
break;
|
|
159
75
|
default:
|
|
160
|
-
throw new Error(
|
|
76
|
+
throw new Error(`Invalid ${groupType}`);
|
|
161
77
|
}
|
|
162
|
-
|
|
78
|
+
const result = predicatesOrGroups[filterType](predicateOrGroup => {
|
|
163
79
|
if ((0, types_1.isPredicateObj)(predicateOrGroup)) {
|
|
164
|
-
|
|
165
|
-
|
|
80
|
+
const { field, operator, operand } = predicateOrGroup;
|
|
81
|
+
const value = model[field];
|
|
166
82
|
return (0, exports.validatePredicateField)(value, operator, operand);
|
|
167
83
|
}
|
|
168
84
|
if ((0, types_1.isPredicateGroup)(predicateOrGroup)) {
|
|
169
|
-
|
|
85
|
+
const { type, predicates } = predicateOrGroup;
|
|
170
86
|
return (0, exports.validatePredicate)(model, type, predicates);
|
|
171
87
|
}
|
|
172
88
|
throw new Error('Not a predicate or group');
|
|
@@ -174,7 +90,7 @@ var validatePredicate = function (model, groupType, predicatesOrGroups) {
|
|
|
174
90
|
return isNegation ? !result : result;
|
|
175
91
|
};
|
|
176
92
|
exports.validatePredicate = validatePredicate;
|
|
177
|
-
|
|
93
|
+
const validatePredicateField = (value, operator, operand) => {
|
|
178
94
|
switch (operator) {
|
|
179
95
|
case 'ne':
|
|
180
96
|
return value !== operand;
|
|
@@ -189,7 +105,7 @@ var validatePredicateField = function (value, operator, operand) {
|
|
|
189
105
|
case 'gt':
|
|
190
106
|
return value > operand;
|
|
191
107
|
case 'between':
|
|
192
|
-
|
|
108
|
+
const [min, max] = operand;
|
|
193
109
|
return value >= min && value <= max;
|
|
194
110
|
case 'beginsWith':
|
|
195
111
|
return (!(0, exports.isNullOrUndefined)(value) &&
|
|
@@ -205,24 +121,24 @@ var validatePredicateField = function (value, operator, operand) {
|
|
|
205
121
|
}
|
|
206
122
|
};
|
|
207
123
|
exports.validatePredicateField = validatePredicateField;
|
|
208
|
-
|
|
124
|
+
const isModelConstructor = (obj) => {
|
|
209
125
|
return (obj && typeof obj.copyOf === 'function');
|
|
210
126
|
};
|
|
211
127
|
exports.isModelConstructor = isModelConstructor;
|
|
212
|
-
|
|
128
|
+
const nonModelClasses = new WeakSet();
|
|
213
129
|
function registerNonModelClass(clazz) {
|
|
214
130
|
nonModelClasses.add(clazz);
|
|
215
131
|
}
|
|
216
132
|
exports.registerNonModelClass = registerNonModelClass;
|
|
217
|
-
|
|
133
|
+
const isNonModelConstructor = (obj) => {
|
|
218
134
|
return nonModelClasses.has(obj);
|
|
219
135
|
};
|
|
220
136
|
exports.isNonModelConstructor = isNonModelConstructor;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
137
|
+
const topologicallySortedModels = new WeakMap();
|
|
138
|
+
const traverseModel = (srcModelName, instance, namespace, modelInstanceCreator, getModelConstructorByModelName) => {
|
|
139
|
+
const modelConstructor = getModelConstructorByModelName(namespace.name, srcModelName);
|
|
140
|
+
const result = [];
|
|
141
|
+
const newInstance = modelConstructor.copyOf(instance, () => { });
|
|
226
142
|
result.unshift({
|
|
227
143
|
modelName: srcModelName,
|
|
228
144
|
item: newInstance,
|
|
@@ -231,39 +147,30 @@ var traverseModel = function (srcModelName, instance, namespace, modelInstanceCr
|
|
|
231
147
|
if (!topologicallySortedModels.has(namespace)) {
|
|
232
148
|
topologicallySortedModels.set(namespace, Array.from(namespace.modelTopologicalOrdering.keys()));
|
|
233
149
|
}
|
|
234
|
-
|
|
235
|
-
result.sort(
|
|
150
|
+
const sortedModels = topologicallySortedModels.get(namespace);
|
|
151
|
+
result.sort((a, b) => {
|
|
236
152
|
return (sortedModels.indexOf(a.modelName) - sortedModels.indexOf(b.modelName));
|
|
237
153
|
});
|
|
238
154
|
return result;
|
|
239
155
|
};
|
|
240
156
|
exports.traverseModel = traverseModel;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return new Promise(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
157
|
+
let privateModeCheckResult;
|
|
158
|
+
const isPrivateMode = () => {
|
|
159
|
+
return new Promise(resolve => {
|
|
160
|
+
const dbname = (0, utils_1.amplifyUuid)();
|
|
161
|
+
let db;
|
|
162
|
+
const isPrivate = () => {
|
|
247
163
|
privateModeCheckResult = false;
|
|
248
164
|
resolve(true);
|
|
249
165
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
_c.label = 2;
|
|
259
|
-
case 2: return [4 /*yield*/, indexedDB.deleteDatabase(dbname)];
|
|
260
|
-
case 3:
|
|
261
|
-
_c.sent();
|
|
262
|
-
privateModeCheckResult = true;
|
|
263
|
-
return [2 /*return*/, resolve(false)];
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}); };
|
|
166
|
+
const isNotPrivate = async () => {
|
|
167
|
+
if (db && db.result && typeof db.result.close === 'function') {
|
|
168
|
+
await db.result.close();
|
|
169
|
+
}
|
|
170
|
+
await indexedDB.deleteDatabase(dbname);
|
|
171
|
+
privateModeCheckResult = true;
|
|
172
|
+
return resolve(false);
|
|
173
|
+
};
|
|
267
174
|
if (privateModeCheckResult === true) {
|
|
268
175
|
return isNotPrivate();
|
|
269
176
|
}
|
|
@@ -278,7 +185,7 @@ var isPrivateMode = function () {
|
|
|
278
185
|
});
|
|
279
186
|
};
|
|
280
187
|
exports.isPrivateMode = isPrivateMode;
|
|
281
|
-
|
|
188
|
+
let safariCompatabilityModeResult;
|
|
282
189
|
/**
|
|
283
190
|
* Whether the browser's implementation of IndexedDB breaks on array lookups
|
|
284
191
|
* against composite indexes whose keypath contains a single column.
|
|
@@ -289,93 +196,100 @@ var safariCompatabilityModeResult;
|
|
|
289
196
|
* In all known, modern Safari browsers as of Q4 2022, the query against an index like
|
|
290
197
|
* this will *always* return `undefined`. So, the index needs to be created as a scalar.
|
|
291
198
|
*/
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
var _c;
|
|
315
|
-
var db = (_c = event === null || event === void 0 ? void 0 : event.target) === null || _c === void 0 ? void 0 : _c.result;
|
|
316
|
-
db.onerror = function () { return resolve(false); };
|
|
317
|
-
var store = db.createObjectStore(storeName_1, {
|
|
318
|
-
autoIncrement: true,
|
|
319
|
-
});
|
|
320
|
-
store.createIndex(indexName_1, ['id']);
|
|
321
|
-
};
|
|
322
|
-
})];
|
|
323
|
-
case 1:
|
|
324
|
-
db_1 = _c.sent();
|
|
325
|
-
if (!db_1) {
|
|
326
|
-
throw new Error('Could not open probe DB');
|
|
327
|
-
}
|
|
328
|
-
rwTx = db_1.transaction(storeName_1, 'readwrite');
|
|
329
|
-
rwStore = rwTx.objectStore(storeName_1);
|
|
330
|
-
rwStore.add({
|
|
331
|
-
id: 1,
|
|
199
|
+
const isSafariCompatabilityMode = async () => {
|
|
200
|
+
try {
|
|
201
|
+
const dbName = (0, utils_1.amplifyUuid)();
|
|
202
|
+
const storeName = 'indexedDBFeatureProbeStore';
|
|
203
|
+
const indexName = 'idx';
|
|
204
|
+
if (indexedDB === null)
|
|
205
|
+
return false;
|
|
206
|
+
if (safariCompatabilityModeResult !== undefined) {
|
|
207
|
+
return safariCompatabilityModeResult;
|
|
208
|
+
}
|
|
209
|
+
const db = await new Promise(resolve => {
|
|
210
|
+
const dbOpenRequest = indexedDB.open(dbName);
|
|
211
|
+
dbOpenRequest.onerror = () => resolve(false);
|
|
212
|
+
dbOpenRequest.onsuccess = () => {
|
|
213
|
+
const db = dbOpenRequest.result;
|
|
214
|
+
resolve(db);
|
|
215
|
+
};
|
|
216
|
+
dbOpenRequest.onupgradeneeded = (event) => {
|
|
217
|
+
const db = event?.target?.result;
|
|
218
|
+
db.onerror = () => resolve(false);
|
|
219
|
+
const store = db.createObjectStore(storeName, {
|
|
220
|
+
autoIncrement: true,
|
|
332
221
|
});
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
var getRequest = index.get([1]);
|
|
339
|
-
getRequest.onerror = function () { return resolve(false); };
|
|
340
|
-
getRequest.onsuccess = function (event) {
|
|
341
|
-
var _c;
|
|
342
|
-
resolve((_c = event === null || event === void 0 ? void 0 : event.target) === null || _c === void 0 ? void 0 : _c.result);
|
|
343
|
-
};
|
|
344
|
-
})];
|
|
345
|
-
case 2:
|
|
346
|
-
result = _c.sent();
|
|
347
|
-
if (!(db_1 && typeof db_1.close === 'function')) return [3 /*break*/, 4];
|
|
348
|
-
return [4 /*yield*/, db_1.close()];
|
|
349
|
-
case 3:
|
|
350
|
-
_c.sent();
|
|
351
|
-
_c.label = 4;
|
|
352
|
-
case 4: return [4 /*yield*/, indexedDB.deleteDatabase(dbName_1)];
|
|
353
|
-
case 5:
|
|
354
|
-
_c.sent();
|
|
355
|
-
if (result === undefined) {
|
|
356
|
-
safariCompatabilityModeResult = true;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
safariCompatabilityModeResult = false;
|
|
360
|
-
}
|
|
361
|
-
return [3 /*break*/, 7];
|
|
362
|
-
case 6:
|
|
363
|
-
error_1 = _c.sent();
|
|
364
|
-
safariCompatabilityModeResult = false;
|
|
365
|
-
return [3 /*break*/, 7];
|
|
366
|
-
case 7: return [2 /*return*/, safariCompatabilityModeResult];
|
|
222
|
+
store.createIndex(indexName, ['id']);
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
if (!db) {
|
|
226
|
+
throw new Error('Could not open probe DB');
|
|
367
227
|
}
|
|
368
|
-
|
|
369
|
-
|
|
228
|
+
const rwTx = db.transaction(storeName, 'readwrite');
|
|
229
|
+
const rwStore = rwTx.objectStore(storeName);
|
|
230
|
+
rwStore.add({
|
|
231
|
+
id: 1,
|
|
232
|
+
});
|
|
233
|
+
rwTx.commit();
|
|
234
|
+
const result = await new Promise(resolve => {
|
|
235
|
+
const tx = db.transaction(storeName, 'readonly');
|
|
236
|
+
const store = tx.objectStore(storeName);
|
|
237
|
+
const index = store.index(indexName);
|
|
238
|
+
const getRequest = index.get([1]);
|
|
239
|
+
getRequest.onerror = () => resolve(false);
|
|
240
|
+
getRequest.onsuccess = (event) => {
|
|
241
|
+
resolve(event?.target?.result);
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
if (db && typeof db.close === 'function') {
|
|
245
|
+
await db.close();
|
|
246
|
+
}
|
|
247
|
+
await indexedDB.deleteDatabase(dbName);
|
|
248
|
+
if (result === undefined) {
|
|
249
|
+
safariCompatabilityModeResult = true;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
safariCompatabilityModeResult = false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
safariCompatabilityModeResult = false;
|
|
257
|
+
}
|
|
258
|
+
return safariCompatabilityModeResult;
|
|
259
|
+
};
|
|
370
260
|
exports.isSafariCompatabilityMode = isSafariCompatabilityMode;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
261
|
+
const HEX_TO_SHORT = {};
|
|
262
|
+
for (let i = 0; i < 256; i++) {
|
|
263
|
+
let encodedByte = i.toString(16).toLowerCase();
|
|
264
|
+
if (encodedByte.length === 1) {
|
|
265
|
+
encodedByte = `0${encodedByte}`;
|
|
266
|
+
}
|
|
267
|
+
HEX_TO_SHORT[encodedByte] = i;
|
|
268
|
+
}
|
|
269
|
+
const getBytesFromHex = (encoded) => {
|
|
270
|
+
if (encoded.length % 2 !== 0) {
|
|
271
|
+
throw new Error('Hex encoded strings must have an even number length');
|
|
272
|
+
}
|
|
273
|
+
const out = new Uint8Array(encoded.length / 2);
|
|
274
|
+
for (let i = 0; i < encoded.length; i += 2) {
|
|
275
|
+
const encodedByte = encoded.slice(i, i + 2).toLowerCase();
|
|
276
|
+
if (encodedByte in HEX_TO_SHORT) {
|
|
277
|
+
out[i / 2] = HEX_TO_SHORT[encodedByte];
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw new Error(`Cannot decode unrecognized sequence ${encodedByte} as hexadecimal`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return out;
|
|
284
|
+
};
|
|
285
|
+
const randomBytes = (nBytes) => {
|
|
286
|
+
const str = new utils_1.WordArray().random(nBytes).toString();
|
|
287
|
+
return getBytesFromHex(str);
|
|
288
|
+
};
|
|
289
|
+
const prng = () => randomBytes(1)[0] / 0xff;
|
|
376
290
|
function monotonicUlidFactory(seed) {
|
|
377
|
-
|
|
378
|
-
return
|
|
291
|
+
const ulid = (0, ulid_1.monotonicFactory)(prng);
|
|
292
|
+
return () => {
|
|
379
293
|
return ulid(seed);
|
|
380
294
|
};
|
|
381
295
|
}
|
|
@@ -405,29 +319,18 @@ function getNow() {
|
|
|
405
319
|
exports.getNow = getNow;
|
|
406
320
|
function sortCompareFunction(sortPredicates) {
|
|
407
321
|
return function compareFunction(a, b) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
var sortMultiplier = sortDirection === types_1.SortDirection.ASCENDING ? 1 : -1;
|
|
417
|
-
if (a[field] < b[field]) {
|
|
418
|
-
return -1 * sortMultiplier;
|
|
419
|
-
}
|
|
420
|
-
if (a[field] > b[field]) {
|
|
421
|
-
return 1 * sortMultiplier;
|
|
422
|
-
}
|
|
322
|
+
// enable multi-field sort by iterating over predicates until
|
|
323
|
+
// a comparison returns -1 or 1
|
|
324
|
+
for (const predicate of sortPredicates) {
|
|
325
|
+
const { field, sortDirection } = predicate;
|
|
326
|
+
// reverse result when direction is descending
|
|
327
|
+
const sortMultiplier = sortDirection === types_1.SortDirection.ASCENDING ? 1 : -1;
|
|
328
|
+
if (a[field] < b[field]) {
|
|
329
|
+
return -1 * sortMultiplier;
|
|
423
330
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
finally {
|
|
427
|
-
try {
|
|
428
|
-
if (sortPredicates_1_1 && !sortPredicates_1_1.done && (_c = sortPredicates_1.return)) _c.call(sortPredicates_1);
|
|
331
|
+
if (a[field] > b[field]) {
|
|
332
|
+
return 1 * sortMultiplier;
|
|
429
333
|
}
|
|
430
|
-
finally { if (e_1) throw e_1.error; }
|
|
431
334
|
}
|
|
432
335
|
return 0;
|
|
433
336
|
};
|
|
@@ -438,12 +341,10 @@ exports.sortCompareFunction = sortCompareFunction;
|
|
|
438
341
|
// returns true if equal by value
|
|
439
342
|
// if nullish is true, treat undefined and null values as equal
|
|
440
343
|
// to normalize for GQL response values for undefined fields
|
|
441
|
-
function valuesEqual(valA, valB, nullish) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
var b = valB;
|
|
446
|
-
var nullishCompare = function (_a, _b) {
|
|
344
|
+
function valuesEqual(valA, valB, nullish = false) {
|
|
345
|
+
let a = valA;
|
|
346
|
+
let b = valB;
|
|
347
|
+
const nullishCompare = (_a, _b) => {
|
|
447
348
|
return ((_a === undefined || _a === null) && (_b === undefined || _b === null));
|
|
448
349
|
};
|
|
449
350
|
// if one of the values is a primitive and the other is an object
|
|
@@ -464,15 +365,15 @@ function valuesEqual(valA, valB, nullish) {
|
|
|
464
365
|
return false;
|
|
465
366
|
}
|
|
466
367
|
if (a instanceof Set && b instanceof Set) {
|
|
467
|
-
a =
|
|
468
|
-
b =
|
|
368
|
+
a = [...a];
|
|
369
|
+
b = [...b];
|
|
469
370
|
}
|
|
470
371
|
if (a instanceof Map && b instanceof Map) {
|
|
471
372
|
a = Object.fromEntries(a);
|
|
472
373
|
b = Object.fromEntries(b);
|
|
473
374
|
}
|
|
474
|
-
|
|
475
|
-
|
|
375
|
+
const aKeys = Object.keys(a);
|
|
376
|
+
const bKeys = Object.keys(b);
|
|
476
377
|
// last condition is to ensure that [] !== [null] even if nullish. However [undefined] === [null] when nullish
|
|
477
378
|
if (aKeys.length !== bKeys.length && (!nullish || Array.isArray(a))) {
|
|
478
379
|
return false;
|
|
@@ -480,23 +381,13 @@ function valuesEqual(valA, valB, nullish) {
|
|
|
480
381
|
// iterate through the longer set of keys
|
|
481
382
|
// e.g., for a nullish comparison of a={ a: 1 } and b={ a: 1, b: null }
|
|
482
383
|
// we want to iterate through bKeys
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (!valuesEqual(aVal, bVal, nullish)) {
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
495
|
-
finally {
|
|
496
|
-
try {
|
|
497
|
-
if (keys_1_1 && !keys_1_1.done && (_c = keys_1.return)) _c.call(keys_1);
|
|
384
|
+
const keys = aKeys.length >= bKeys.length ? aKeys : bKeys;
|
|
385
|
+
for (const key of keys) {
|
|
386
|
+
const aVal = a[key];
|
|
387
|
+
const bVal = b[key];
|
|
388
|
+
if (!valuesEqual(aVal, bVal, nullish)) {
|
|
389
|
+
return false;
|
|
498
390
|
}
|
|
499
|
-
finally { if (e_2) throw e_2.error; }
|
|
500
391
|
}
|
|
501
392
|
return true;
|
|
502
393
|
}
|
|
@@ -511,15 +402,15 @@ exports.valuesEqual = valuesEqual;
|
|
|
511
402
|
function inMemoryPagination(records, pagination) {
|
|
512
403
|
if (pagination && records.length > 1) {
|
|
513
404
|
if (pagination.sort) {
|
|
514
|
-
|
|
405
|
+
const sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
515
406
|
if (sortPredicates.length) {
|
|
516
|
-
|
|
407
|
+
const compareFn = sortCompareFunction(sortPredicates);
|
|
517
408
|
records.sort(compareFn);
|
|
518
409
|
}
|
|
519
410
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
411
|
+
const { page = 0, limit = 0 } = pagination;
|
|
412
|
+
const start = Math.max(0, page * limit) || 0;
|
|
413
|
+
const end = limit > 0 ? start + limit : records.length;
|
|
523
414
|
return records.slice(start, end);
|
|
524
415
|
}
|
|
525
416
|
return records;
|
|
@@ -532,43 +423,13 @@ exports.inMemoryPagination = inMemoryPagination;
|
|
|
532
423
|
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
533
424
|
* @returns A `Promise<boolean>`, `true` if "some" items match; `false` otherwise.
|
|
534
425
|
*/
|
|
535
|
-
function asyncSome(items, matches) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
543
|
-
items_1 = __values(items), items_1_1 = items_1.next();
|
|
544
|
-
_d.label = 1;
|
|
545
|
-
case 1:
|
|
546
|
-
if (!!items_1_1.done) return [3 /*break*/, 4];
|
|
547
|
-
item = items_1_1.value;
|
|
548
|
-
return [4 /*yield*/, matches(item)];
|
|
549
|
-
case 2:
|
|
550
|
-
if (_d.sent()) {
|
|
551
|
-
return [2 /*return*/, true];
|
|
552
|
-
}
|
|
553
|
-
_d.label = 3;
|
|
554
|
-
case 3:
|
|
555
|
-
items_1_1 = items_1.next();
|
|
556
|
-
return [3 /*break*/, 1];
|
|
557
|
-
case 4: return [3 /*break*/, 7];
|
|
558
|
-
case 5:
|
|
559
|
-
e_3_1 = _d.sent();
|
|
560
|
-
e_3 = { error: e_3_1 };
|
|
561
|
-
return [3 /*break*/, 7];
|
|
562
|
-
case 6:
|
|
563
|
-
try {
|
|
564
|
-
if (items_1_1 && !items_1_1.done && (_c = items_1.return)) _c.call(items_1);
|
|
565
|
-
}
|
|
566
|
-
finally { if (e_3) throw e_3.error; }
|
|
567
|
-
return [7 /*endfinally*/];
|
|
568
|
-
case 7: return [2 /*return*/, false];
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
});
|
|
426
|
+
async function asyncSome(items, matches) {
|
|
427
|
+
for (const item of items) {
|
|
428
|
+
if (await matches(item)) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
572
433
|
}
|
|
573
434
|
exports.asyncSome = asyncSome;
|
|
574
435
|
/**
|
|
@@ -578,43 +439,13 @@ exports.asyncSome = asyncSome;
|
|
|
578
439
|
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
579
440
|
* @returns A `Promise<boolean>`, `true` if every item matches; `false` otherwise.
|
|
580
441
|
*/
|
|
581
|
-
function asyncEvery(items, matches) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
589
|
-
items_2 = __values(items), items_2_1 = items_2.next();
|
|
590
|
-
_d.label = 1;
|
|
591
|
-
case 1:
|
|
592
|
-
if (!!items_2_1.done) return [3 /*break*/, 4];
|
|
593
|
-
item = items_2_1.value;
|
|
594
|
-
return [4 /*yield*/, matches(item)];
|
|
595
|
-
case 2:
|
|
596
|
-
if (!(_d.sent())) {
|
|
597
|
-
return [2 /*return*/, false];
|
|
598
|
-
}
|
|
599
|
-
_d.label = 3;
|
|
600
|
-
case 3:
|
|
601
|
-
items_2_1 = items_2.next();
|
|
602
|
-
return [3 /*break*/, 1];
|
|
603
|
-
case 4: return [3 /*break*/, 7];
|
|
604
|
-
case 5:
|
|
605
|
-
e_4_1 = _d.sent();
|
|
606
|
-
e_4 = { error: e_4_1 };
|
|
607
|
-
return [3 /*break*/, 7];
|
|
608
|
-
case 6:
|
|
609
|
-
try {
|
|
610
|
-
if (items_2_1 && !items_2_1.done && (_c = items_2.return)) _c.call(items_2);
|
|
611
|
-
}
|
|
612
|
-
finally { if (e_4) throw e_4.error; }
|
|
613
|
-
return [7 /*endfinally*/];
|
|
614
|
-
case 7: return [2 /*return*/, true];
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
});
|
|
442
|
+
async function asyncEvery(items, matches) {
|
|
443
|
+
for (const item of items) {
|
|
444
|
+
if (!(await matches(item))) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return true;
|
|
618
449
|
}
|
|
619
450
|
exports.asyncEvery = asyncEvery;
|
|
620
451
|
/**
|
|
@@ -625,171 +456,125 @@ exports.asyncEvery = asyncEvery;
|
|
|
625
456
|
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
626
457
|
* @returns A `Promise<T>` of matching items.
|
|
627
458
|
*/
|
|
628
|
-
function asyncFilter(items, matches) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
_d.label = 1;
|
|
637
|
-
case 1:
|
|
638
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
639
|
-
items_3 = __values(items), items_3_1 = items_3.next();
|
|
640
|
-
_d.label = 2;
|
|
641
|
-
case 2:
|
|
642
|
-
if (!!items_3_1.done) return [3 /*break*/, 5];
|
|
643
|
-
item = items_3_1.value;
|
|
644
|
-
return [4 /*yield*/, matches(item)];
|
|
645
|
-
case 3:
|
|
646
|
-
if (_d.sent()) {
|
|
647
|
-
results.push(item);
|
|
648
|
-
}
|
|
649
|
-
_d.label = 4;
|
|
650
|
-
case 4:
|
|
651
|
-
items_3_1 = items_3.next();
|
|
652
|
-
return [3 /*break*/, 2];
|
|
653
|
-
case 5: return [3 /*break*/, 8];
|
|
654
|
-
case 6:
|
|
655
|
-
e_5_1 = _d.sent();
|
|
656
|
-
e_5 = { error: e_5_1 };
|
|
657
|
-
return [3 /*break*/, 8];
|
|
658
|
-
case 7:
|
|
659
|
-
try {
|
|
660
|
-
if (items_3_1 && !items_3_1.done && (_c = items_3.return)) _c.call(items_3);
|
|
661
|
-
}
|
|
662
|
-
finally { if (e_5) throw e_5.error; }
|
|
663
|
-
return [7 /*endfinally*/];
|
|
664
|
-
case 8: return [2 /*return*/, results];
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
});
|
|
459
|
+
async function asyncFilter(items, matches) {
|
|
460
|
+
const results = [];
|
|
461
|
+
for (const item of items) {
|
|
462
|
+
if (await matches(item)) {
|
|
463
|
+
results.push(item);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return results;
|
|
668
467
|
}
|
|
669
468
|
exports.asyncFilter = asyncFilter;
|
|
670
|
-
|
|
469
|
+
const isAWSDate = (val) => {
|
|
671
470
|
return !!/^\d{4}-\d{2}-\d{2}(Z|[+-]\d{2}:\d{2}($|:\d{2}))?$/.exec(val);
|
|
672
471
|
};
|
|
673
472
|
exports.isAWSDate = isAWSDate;
|
|
674
|
-
|
|
473
|
+
const isAWSTime = (val) => {
|
|
675
474
|
return !!/^\d{2}:\d{2}(:\d{2}(.\d+)?)?(Z|[+-]\d{2}:\d{2}($|:\d{2}))?$/.exec(val);
|
|
676
475
|
};
|
|
677
476
|
exports.isAWSTime = isAWSTime;
|
|
678
|
-
|
|
477
|
+
const isAWSDateTime = (val) => {
|
|
679
478
|
return !!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(.\d+)?)?(Z|[+-]\d{2}:\d{2}($|:\d{2}))?$/.exec(val);
|
|
680
479
|
};
|
|
681
480
|
exports.isAWSDateTime = isAWSDateTime;
|
|
682
|
-
|
|
481
|
+
const isAWSTimestamp = (val) => {
|
|
683
482
|
return !!/^\d+$/.exec(String(val));
|
|
684
483
|
};
|
|
685
484
|
exports.isAWSTimestamp = isAWSTimestamp;
|
|
686
|
-
|
|
485
|
+
const isAWSEmail = (val) => {
|
|
687
486
|
return !!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.exec(val);
|
|
688
487
|
};
|
|
689
488
|
exports.isAWSEmail = isAWSEmail;
|
|
690
|
-
|
|
489
|
+
const isAWSJSON = (val) => {
|
|
691
490
|
try {
|
|
692
491
|
JSON.parse(val);
|
|
693
492
|
return true;
|
|
694
493
|
}
|
|
695
|
-
catch
|
|
494
|
+
catch {
|
|
696
495
|
return false;
|
|
697
496
|
}
|
|
698
497
|
};
|
|
699
498
|
exports.isAWSJSON = isAWSJSON;
|
|
700
|
-
|
|
499
|
+
const isAWSURL = (val) => {
|
|
701
500
|
try {
|
|
702
501
|
return !!new utils_1.AmplifyUrl(val);
|
|
703
502
|
}
|
|
704
|
-
catch
|
|
503
|
+
catch {
|
|
705
504
|
return false;
|
|
706
505
|
}
|
|
707
506
|
};
|
|
708
507
|
exports.isAWSURL = isAWSURL;
|
|
709
|
-
|
|
508
|
+
const isAWSPhone = (val) => {
|
|
710
509
|
return !!/^\+?\d[\d\s-]+$/.exec(val);
|
|
711
510
|
};
|
|
712
511
|
exports.isAWSPhone = isAWSPhone;
|
|
713
|
-
|
|
512
|
+
const isAWSIPAddress = (val) => {
|
|
714
513
|
return !!/((^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$)|(^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?$))$/.exec(val);
|
|
715
514
|
};
|
|
716
515
|
exports.isAWSIPAddress = isAWSIPAddress;
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
this.promise = new Promise(
|
|
516
|
+
class DeferredPromise {
|
|
517
|
+
constructor() {
|
|
518
|
+
const self = this;
|
|
519
|
+
this.promise = new Promise((resolve, reject) => {
|
|
721
520
|
self.resolve = resolve;
|
|
722
521
|
self.reject = reject;
|
|
723
522
|
});
|
|
724
523
|
}
|
|
725
|
-
|
|
726
|
-
}());
|
|
524
|
+
}
|
|
727
525
|
exports.DeferredPromise = DeferredPromise;
|
|
728
|
-
|
|
729
|
-
|
|
526
|
+
class DeferredCallbackResolver {
|
|
527
|
+
constructor(options) {
|
|
730
528
|
this.limitPromise = new DeferredPromise();
|
|
731
529
|
this.raceInFlight = false;
|
|
732
|
-
this.callback =
|
|
733
|
-
this.defaultErrorHandler =
|
|
734
|
-
if (msg === void 0) { msg = 'DeferredCallbackResolver error'; }
|
|
530
|
+
this.callback = () => { };
|
|
531
|
+
this.defaultErrorHandler = (msg = 'DeferredCallbackResolver error') => {
|
|
735
532
|
throw new Error(msg);
|
|
736
533
|
};
|
|
737
534
|
this.callback = options.callback;
|
|
738
535
|
this.errorHandler = options.errorHandler || this.defaultErrorHandler;
|
|
739
536
|
this.maxInterval = options.maxInterval || 2000;
|
|
740
537
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
_this.timer = setTimeout(function () {
|
|
538
|
+
startTimer() {
|
|
539
|
+
this.timerPromise = new Promise((resolve, reject) => {
|
|
540
|
+
this.timer = setTimeout(() => {
|
|
745
541
|
resolve(types_1.LimitTimerRaceResolvedValues.TIMER);
|
|
746
|
-
},
|
|
542
|
+
}, this.maxInterval);
|
|
747
543
|
});
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
this.clear();
|
|
773
|
-
this.raceInFlight = false;
|
|
774
|
-
this.limitPromise = new DeferredPromise();
|
|
775
|
-
return [2 /*return*/, winner];
|
|
776
|
-
case 4: return [2 /*return*/];
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
};
|
|
781
|
-
DeferredCallbackResolver.prototype.start = function () {
|
|
544
|
+
}
|
|
545
|
+
async racePromises() {
|
|
546
|
+
let winner;
|
|
547
|
+
try {
|
|
548
|
+
this.raceInFlight = true;
|
|
549
|
+
this.startTimer();
|
|
550
|
+
winner = await Promise.race([
|
|
551
|
+
this.timerPromise,
|
|
552
|
+
this.limitPromise.promise,
|
|
553
|
+
]);
|
|
554
|
+
this.callback();
|
|
555
|
+
}
|
|
556
|
+
catch (err) {
|
|
557
|
+
this.errorHandler(err);
|
|
558
|
+
}
|
|
559
|
+
finally {
|
|
560
|
+
// reset for the next race
|
|
561
|
+
this.clear();
|
|
562
|
+
this.raceInFlight = false;
|
|
563
|
+
this.limitPromise = new DeferredPromise();
|
|
564
|
+
return winner;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
start() {
|
|
782
568
|
if (!this.raceInFlight)
|
|
783
569
|
this.racePromises();
|
|
784
|
-
}
|
|
785
|
-
|
|
570
|
+
}
|
|
571
|
+
clear() {
|
|
786
572
|
clearTimeout(this.timer);
|
|
787
|
-
}
|
|
788
|
-
|
|
573
|
+
}
|
|
574
|
+
resolve() {
|
|
789
575
|
this.limitPromise.resolve(types_1.LimitTimerRaceResolvedValues.LIMIT);
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
}());
|
|
576
|
+
}
|
|
577
|
+
}
|
|
793
578
|
exports.DeferredCallbackResolver = DeferredCallbackResolver;
|
|
794
579
|
/**
|
|
795
580
|
* merge two sets of patches created by immer produce.
|
|
@@ -809,18 +594,18 @@ exports.DeferredCallbackResolver = DeferredCallbackResolver;
|
|
|
809
594
|
* @return merged patches
|
|
810
595
|
*/
|
|
811
596
|
function mergePatches(originalSource, oldPatches, newPatches) {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
(0, immer_1.produce)(originalSource,
|
|
597
|
+
const patchesToMerge = oldPatches.concat(newPatches);
|
|
598
|
+
let patches;
|
|
599
|
+
(0, immer_1.produce)(originalSource, draft => {
|
|
815
600
|
(0, immer_1.applyPatches)(draft, patchesToMerge);
|
|
816
|
-
},
|
|
601
|
+
}, p => {
|
|
817
602
|
patches = p;
|
|
818
603
|
});
|
|
819
604
|
return patches;
|
|
820
605
|
}
|
|
821
606
|
exports.mergePatches = mergePatches;
|
|
822
|
-
|
|
823
|
-
|
|
607
|
+
const getStorename = (namespace, modelName) => {
|
|
608
|
+
const storeName = `${namespace}_${modelName}`;
|
|
824
609
|
return storeName;
|
|
825
610
|
};
|
|
826
611
|
exports.getStorename = getStorename;
|
|
@@ -857,78 +642,75 @@ exports.getStorename = getStorename;
|
|
|
857
642
|
|
|
858
643
|
See 'processCompositeKeys' test in util.test.ts for more examples
|
|
859
644
|
*/
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return sortKeyFields;
|
|
866
|
-
};
|
|
867
|
-
var compositeKeyFields = attributes
|
|
645
|
+
const processCompositeKeys = (attributes) => {
|
|
646
|
+
const extractCompositeSortKey = ({ properties: {
|
|
647
|
+
// ignore the HK (fields[0]) we only need to include the composite sort key fields[1...n]
|
|
648
|
+
fields: [, ...sortKeyFields], }, }) => sortKeyFields;
|
|
649
|
+
const compositeKeyFields = attributes
|
|
868
650
|
.filter(types_1.isModelAttributeCompositeKey)
|
|
869
651
|
.map(extractCompositeSortKey);
|
|
870
652
|
/*
|
|
871
653
|
if 2 sets of fields have any intersecting fields => combine them into 1 union set
|
|
872
654
|
e.g., ['a', 'b', 'c'] and ['a', 'b', 'd'] => ['a', 'b', 'c', 'd']
|
|
873
655
|
*/
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
combined.push(sortKeyFieldsSet);
|
|
879
|
-
return combined;
|
|
880
|
-
}
|
|
881
|
-
// does the current set share values with another set we've already added to `combined`?
|
|
882
|
-
var intersectingSetIdx = combined.findIndex(function (existingSet) {
|
|
883
|
-
return __spreadArray([], __read(existingSet), false).some(function (f) { return sortKeyFieldsSet.has(f); });
|
|
884
|
-
});
|
|
885
|
-
if (intersectingSetIdx > -1) {
|
|
886
|
-
var union = new Set(__spreadArray(__spreadArray([], __read(combined[intersectingSetIdx]), false), __read(sortKeyFieldsSet), false));
|
|
887
|
-
// combine the current set with the intersecting set we found above
|
|
888
|
-
combined[intersectingSetIdx] = union;
|
|
889
|
-
}
|
|
890
|
-
else {
|
|
891
|
-
// none of the sets in `combined` have intersecting values with the current set
|
|
892
|
-
combined.push(sortKeyFieldsSet);
|
|
893
|
-
}
|
|
656
|
+
const combineIntersecting = (fields) => fields.reduce((combined, sortKeyFields) => {
|
|
657
|
+
const sortKeyFieldsSet = new Set(sortKeyFields);
|
|
658
|
+
if (combined.length === 0) {
|
|
659
|
+
combined.push(sortKeyFieldsSet);
|
|
894
660
|
return combined;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
|
|
661
|
+
}
|
|
662
|
+
// does the current set share values with another set we've already added to `combined`?
|
|
663
|
+
const intersectingSetIdx = combined.findIndex(existingSet => {
|
|
664
|
+
return [...existingSet].some(f => sortKeyFieldsSet.has(f));
|
|
665
|
+
});
|
|
666
|
+
if (intersectingSetIdx > -1) {
|
|
667
|
+
const union = new Set([
|
|
668
|
+
...combined[intersectingSetIdx],
|
|
669
|
+
...sortKeyFieldsSet,
|
|
670
|
+
]);
|
|
671
|
+
// combine the current set with the intersecting set we found above
|
|
672
|
+
combined[intersectingSetIdx] = union;
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
// none of the sets in `combined` have intersecting values with the current set
|
|
676
|
+
combined.push(sortKeyFieldsSet);
|
|
677
|
+
}
|
|
678
|
+
return combined;
|
|
679
|
+
}, []);
|
|
680
|
+
const initial = combineIntersecting(compositeKeyFields);
|
|
898
681
|
// a single pass pay not be enough to correctly combine all the fields
|
|
899
682
|
// call the function once more to get a final merged list of sets
|
|
900
|
-
|
|
683
|
+
const combined = combineIntersecting(initial);
|
|
901
684
|
return combined;
|
|
902
685
|
};
|
|
903
686
|
exports.processCompositeKeys = processCompositeKeys;
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
var keyAttribute = (_c = modelDefinition === null || modelDefinition === void 0 ? void 0 : modelDefinition.attributes) === null || _c === void 0 ? void 0 : _c.find(types_1.isModelAttributeKey);
|
|
687
|
+
const extractKeyIfExists = (modelDefinition) => {
|
|
688
|
+
const keyAttribute = modelDefinition?.attributes?.find(types_1.isModelAttributeKey);
|
|
907
689
|
return keyAttribute;
|
|
908
690
|
};
|
|
909
691
|
exports.extractKeyIfExists = extractKeyIfExists;
|
|
910
|
-
|
|
911
|
-
|
|
692
|
+
const extractPrimaryKeyFieldNames = (modelDefinition) => {
|
|
693
|
+
const keyAttribute = (0, exports.extractKeyIfExists)(modelDefinition);
|
|
912
694
|
if (keyAttribute && (0, types_1.isModelAttributePrimaryKey)(keyAttribute)) {
|
|
913
695
|
return keyAttribute.properties.fields;
|
|
914
696
|
}
|
|
915
697
|
return [exports.ID];
|
|
916
698
|
};
|
|
917
699
|
exports.extractPrimaryKeyFieldNames = extractPrimaryKeyFieldNames;
|
|
918
|
-
|
|
919
|
-
return keyFields.map(
|
|
700
|
+
const extractPrimaryKeyValues = (model, keyFields) => {
|
|
701
|
+
return keyFields.map(key => model[key]);
|
|
920
702
|
};
|
|
921
703
|
exports.extractPrimaryKeyValues = extractPrimaryKeyValues;
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
keyFields.forEach(
|
|
704
|
+
const extractPrimaryKeysAndValues = (model, keyFields) => {
|
|
705
|
+
const primaryKeysAndValues = {};
|
|
706
|
+
keyFields.forEach(key => (primaryKeysAndValues[key] = model[key]));
|
|
925
707
|
return primaryKeysAndValues;
|
|
926
708
|
};
|
|
927
709
|
exports.extractPrimaryKeysAndValues = extractPrimaryKeysAndValues;
|
|
928
710
|
// IdentifierFields<ManagedIdentifier>
|
|
929
711
|
// Default behavior without explicit @primaryKey defined
|
|
930
|
-
|
|
931
|
-
|
|
712
|
+
const isIdManaged = (modelDefinition) => {
|
|
713
|
+
const keyAttribute = (0, exports.extractKeyIfExists)(modelDefinition);
|
|
932
714
|
if (keyAttribute && (0, types_1.isModelAttributePrimaryKey)(keyAttribute)) {
|
|
933
715
|
return false;
|
|
934
716
|
}
|
|
@@ -937,27 +719,26 @@ var isIdManaged = function (modelDefinition) {
|
|
|
937
719
|
exports.isIdManaged = isIdManaged;
|
|
938
720
|
// IdentifierFields<OptionallyManagedIdentifier>
|
|
939
721
|
// @primaryKey with explicit `id` in the PK. Single key or composite
|
|
940
|
-
|
|
941
|
-
|
|
722
|
+
const isIdOptionallyManaged = (modelDefinition) => {
|
|
723
|
+
const keyAttribute = (0, exports.extractKeyIfExists)(modelDefinition);
|
|
942
724
|
if (keyAttribute && (0, types_1.isModelAttributePrimaryKey)(keyAttribute)) {
|
|
943
725
|
return keyAttribute.properties.fields[0] === exports.ID;
|
|
944
726
|
}
|
|
945
727
|
return false;
|
|
946
728
|
};
|
|
947
729
|
exports.isIdOptionallyManaged = isIdOptionallyManaged;
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
Object.keys(namespace.models).forEach(
|
|
952
|
-
var e_6, _c;
|
|
730
|
+
const establishRelationAndKeys = (namespace) => {
|
|
731
|
+
const relationship = {};
|
|
732
|
+
const keys = {};
|
|
733
|
+
Object.keys(namespace.models).forEach((mKey) => {
|
|
953
734
|
relationship[mKey] = { indexes: [], relationTypes: [] };
|
|
954
735
|
keys[mKey] = {};
|
|
955
|
-
|
|
956
|
-
Object.keys(model.fields).forEach(
|
|
957
|
-
|
|
736
|
+
const model = namespace.models[mKey];
|
|
737
|
+
Object.keys(model.fields).forEach((attr) => {
|
|
738
|
+
const fieldAttribute = model.fields[attr];
|
|
958
739
|
if (typeof fieldAttribute.type === 'object' &&
|
|
959
740
|
'model' in fieldAttribute.type) {
|
|
960
|
-
|
|
741
|
+
const connectionType = fieldAttribute.association.connectionType;
|
|
961
742
|
relationship[mKey].relationTypes.push({
|
|
962
743
|
fieldName: fieldAttribute.name,
|
|
963
744
|
modelName: fieldAttribute.type.model,
|
|
@@ -967,15 +748,12 @@ var establishRelationAndKeys = function (namespace) {
|
|
|
967
748
|
associatedWith: fieldAttribute.association['associatedWith'],
|
|
968
749
|
});
|
|
969
750
|
if (connectionType === 'BELONGS_TO') {
|
|
970
|
-
|
|
751
|
+
const targetNames = (0, exports.extractTargetNamesFromSrc)(fieldAttribute.association);
|
|
971
752
|
if (targetNames) {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
var _d = __read(_c, 1), index = _d[0];
|
|
975
|
-
return index === idxName_1;
|
|
976
|
-
});
|
|
753
|
+
const idxName = (0, exports.indexNameFromKeys)(targetNames);
|
|
754
|
+
const idxExists = relationship[mKey].indexes.find(([index]) => index === idxName);
|
|
977
755
|
if (!idxExists) {
|
|
978
|
-
relationship[mKey].indexes.push([
|
|
756
|
+
relationship[mKey].indexes.push([idxName, targetNames]);
|
|
979
757
|
}
|
|
980
758
|
}
|
|
981
759
|
}
|
|
@@ -983,37 +761,21 @@ var establishRelationAndKeys = function (namespace) {
|
|
|
983
761
|
});
|
|
984
762
|
if (model.attributes) {
|
|
985
763
|
keys[mKey].compositeKeys = (0, exports.processCompositeKeys)(model.attributes);
|
|
986
|
-
|
|
764
|
+
for (const attribute of model.attributes) {
|
|
987
765
|
if (!(0, types_1.isModelAttributeKey)(attribute)) {
|
|
988
|
-
|
|
766
|
+
continue;
|
|
989
767
|
}
|
|
990
|
-
|
|
768
|
+
const { fields } = attribute.properties;
|
|
991
769
|
if ((0, types_1.isModelAttributePrimaryKey)(attribute)) {
|
|
992
770
|
keys[mKey].primaryKey = fields;
|
|
993
|
-
|
|
771
|
+
continue;
|
|
994
772
|
}
|
|
995
773
|
// create indexes for all other keys
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
var _d = __read(_c, 1), index = _d[0];
|
|
999
|
-
return index === idxName;
|
|
1000
|
-
});
|
|
774
|
+
const idxName = (0, exports.indexNameFromKeys)(fields);
|
|
775
|
+
const idxExists = relationship[mKey].indexes.find(([index]) => index === idxName);
|
|
1001
776
|
if (!idxExists) {
|
|
1002
777
|
relationship[mKey].indexes.push([idxName, fields]);
|
|
1003
778
|
}
|
|
1004
|
-
};
|
|
1005
|
-
try {
|
|
1006
|
-
for (var _d = __values(model.attributes), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1007
|
-
var attribute = _e.value;
|
|
1008
|
-
_loop_1(attribute);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1012
|
-
finally {
|
|
1013
|
-
try {
|
|
1014
|
-
if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
|
|
1015
|
-
}
|
|
1016
|
-
finally { if (e_6) throw e_6.error; }
|
|
1017
779
|
}
|
|
1018
780
|
}
|
|
1019
781
|
// set 'id' as the PK for models without a custom PK explicitly defined
|
|
@@ -1030,11 +792,11 @@ var establishRelationAndKeys = function (namespace) {
|
|
|
1030
792
|
return [relationship, keys];
|
|
1031
793
|
};
|
|
1032
794
|
exports.establishRelationAndKeys = establishRelationAndKeys;
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
rel.some(
|
|
795
|
+
const getIndex = (rel, src) => {
|
|
796
|
+
let indexName;
|
|
797
|
+
rel.some((relItem) => {
|
|
1036
798
|
if (relItem.modelName === src) {
|
|
1037
|
-
|
|
799
|
+
const targetNames = (0, exports.extractTargetNamesFromSrc)(relItem);
|
|
1038
800
|
indexName = targetNames && (0, exports.indexNameFromKeys)(targetNames);
|
|
1039
801
|
return true;
|
|
1040
802
|
}
|
|
@@ -1042,18 +804,15 @@ var getIndex = function (rel, src) {
|
|
|
1042
804
|
return indexName;
|
|
1043
805
|
};
|
|
1044
806
|
exports.getIndex = getIndex;
|
|
1045
|
-
|
|
1046
|
-
|
|
807
|
+
const getIndexFromAssociation = (indexes, src) => {
|
|
808
|
+
let indexName;
|
|
1047
809
|
if (Array.isArray(src)) {
|
|
1048
810
|
indexName = (0, exports.indexNameFromKeys)(src);
|
|
1049
811
|
}
|
|
1050
812
|
else {
|
|
1051
813
|
indexName = src;
|
|
1052
814
|
}
|
|
1053
|
-
|
|
1054
|
-
var _d = __read(_c, 1), idxName = _d[0];
|
|
1055
|
-
return idxName === indexName;
|
|
1056
|
-
});
|
|
815
|
+
const associationIndex = indexes.find(([idxName]) => idxName === indexName);
|
|
1057
816
|
return associationIndex && associationIndex[0];
|
|
1058
817
|
};
|
|
1059
818
|
exports.getIndexFromAssociation = getIndexFromAssociation;
|
|
@@ -1064,9 +823,9 @@ the single field `targetName` has been replaced with an array of `targetNames`.
|
|
|
1064
823
|
* @param src {RelationType | ModelAssociation | undefined}
|
|
1065
824
|
* @returns array of targetNames, or `undefined`
|
|
1066
825
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
826
|
+
const extractTargetNamesFromSrc = (src) => {
|
|
827
|
+
const targetName = src?.targetName;
|
|
828
|
+
const targetNames = src?.targetNames;
|
|
1070
829
|
if (Array.isArray(targetNames)) {
|
|
1071
830
|
return targetNames;
|
|
1072
831
|
}
|
|
@@ -1080,26 +839,25 @@ var extractTargetNamesFromSrc = function (src) {
|
|
|
1080
839
|
exports.extractTargetNamesFromSrc = extractTargetNamesFromSrc;
|
|
1081
840
|
// Generates spinal-cased index name from an array of key field names
|
|
1082
841
|
// E.g. for keys `[id, title]` => 'id-title'
|
|
1083
|
-
|
|
1084
|
-
return keys.reduce(
|
|
842
|
+
const indexNameFromKeys = (keys) => {
|
|
843
|
+
return keys.reduce((prev, cur, idx) => {
|
|
1085
844
|
if (idx === 0) {
|
|
1086
845
|
return cur;
|
|
1087
846
|
}
|
|
1088
|
-
return
|
|
847
|
+
return `${prev}${exports.IDENTIFIER_KEY_SEPARATOR}${cur}`;
|
|
1089
848
|
}, '');
|
|
1090
849
|
};
|
|
1091
850
|
exports.indexNameFromKeys = indexNameFromKeys;
|
|
1092
|
-
|
|
851
|
+
const keysEqual = (keysA, keysB) => {
|
|
1093
852
|
if (keysA.length !== keysB.length) {
|
|
1094
853
|
return false;
|
|
1095
854
|
}
|
|
1096
|
-
return keysA.every(
|
|
855
|
+
return keysA.every((key, idx) => key === keysB[idx]);
|
|
1097
856
|
};
|
|
1098
857
|
exports.keysEqual = keysEqual;
|
|
1099
858
|
// Returns primary keys for a model
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
var keyPath = (_d = (_c = namespace === null || namespace === void 0 ? void 0 : namespace.keys) === null || _c === void 0 ? void 0 : _c[modelName]) === null || _d === void 0 ? void 0 : _d.primaryKey;
|
|
859
|
+
const getIndexKeys = (namespace, modelName) => {
|
|
860
|
+
const keyPath = namespace?.keys?.[modelName]?.primaryKey;
|
|
1103
861
|
if (keyPath) {
|
|
1104
862
|
return keyPath;
|
|
1105
863
|
}
|
|
@@ -1119,15 +877,17 @@ exports.getIndexKeys = getIndexKeys;
|
|
|
1119
877
|
* @param definition modelDefinition to inspect.
|
|
1120
878
|
* @returns An object mapping `createdAt` and `updatedAt` to their field names.
|
|
1121
879
|
*/
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
var defaultFields = {
|
|
880
|
+
const getTimestampFields = (definition) => {
|
|
881
|
+
const modelAttributes = definition.attributes?.find(attr => attr.type === 'model');
|
|
882
|
+
const timestampFieldsMap = modelAttributes?.properties?.timestamps;
|
|
883
|
+
const defaultFields = {
|
|
1127
884
|
createdAt: 'createdAt',
|
|
1128
885
|
updatedAt: 'updatedAt',
|
|
1129
886
|
};
|
|
1130
|
-
|
|
1131
|
-
return
|
|
887
|
+
const customFields = timestampFieldsMap || {};
|
|
888
|
+
return {
|
|
889
|
+
...defaultFields,
|
|
890
|
+
...customFields,
|
|
891
|
+
};
|
|
1132
892
|
};
|
|
1133
893
|
exports.getTimestampFields = getTimestampFields;
|