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