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