@aws-amplify/datastore 4.7.22 → 4.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/.tsbuildinfo +1 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -1
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +1 -1
- package/lib/authModeStrategies/index.js +3 -2
- package/lib/authModeStrategies/index.js.map +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +33 -33
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +4 -4
- package/lib/datastore/datastore.js +143 -131
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/datastore/loadGetRandomValues.d.ts +1 -0
- package/lib/datastore/loadGetRandomValues.js +11 -0
- package/lib/datastore/loadGetRandomValues.js.map +1 -0
- package/lib/datastore/loadGetRandomValues.native.d.ts +1 -0
- package/lib/datastore/loadGetRandomValues.native.js +26 -0
- package/lib/datastore/loadGetRandomValues.native.js.map +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +11 -9
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +8 -7
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/next.d.ts +3 -3
- package/lib/predicates/next.js +53 -47
- package/lib/predicates/next.js.map +1 -1
- package/lib/predicates/sort.js +2 -1
- package/lib/predicates/sort.js.map +1 -1
- package/lib/ssr/index.js +2 -2
- package/lib/ssr/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +110 -83
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +7 -7
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +2 -1
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +152 -126
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/StorageAdapterBase.js +62 -53
- package/lib/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +2 -2
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/relationship.d.ts +4 -4
- package/lib/storage/relationship.js +19 -18
- package/lib/storage/relationship.js.map +1 -1
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +22 -24
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.js +1 -0
- package/lib/sync/datastoreReachability/index.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +1 -0
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +402 -408
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +3 -2
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +5 -6
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +8 -7
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +52 -50
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +36 -32
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +28 -27
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +96 -95
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +139 -133
- package/lib/types.js +30 -29
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +12 -20
- package/lib/util.js +115 -80
- package/lib/util.js.map +1 -1
- package/lib-esm/.tsbuildinfo +1 -3
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +31 -33
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +4 -4
- package/lib-esm/datastore/datastore.js +67 -57
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/datastore/loadGetRandomValues.d.ts +1 -0
- package/lib-esm/datastore/loadGetRandomValues.js +7 -0
- package/lib-esm/datastore/loadGetRandomValues.js.map +1 -0
- package/lib-esm/datastore/loadGetRandomValues.native.d.ts +1 -0
- package/lib-esm/datastore/loadGetRandomValues.native.js +22 -0
- package/lib-esm/datastore/loadGetRandomValues.native.js.map +1 -0
- package/lib-esm/index.d.ts +3 -3
- package/lib-esm/index.js +1 -0
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.js +4 -4
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/next.d.ts +3 -3
- package/lib-esm/predicates/next.js +45 -41
- package/lib-esm/predicates/next.js.map +1 -1
- package/lib-esm/predicates/sort.js +1 -1
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/ssr/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +103 -77
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +4 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +142 -116
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js +47 -39
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/adapter/index.js +1 -0
- package/lib-esm/storage/relationship.d.ts +4 -4
- package/lib-esm/storage/relationship.js +17 -17
- package/lib-esm/storage/relationship.js.map +1 -1
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +10 -13
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +400 -407
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +2 -2
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +1 -3
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +4 -4
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +35 -35
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +24 -21
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +17 -17
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.js +62 -62
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +139 -133
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +12 -20
- package/lib-esm/util.js +9 -9
- package/lib-esm/util.js.map +1 -1
- package/package.json +41 -30
- package/src/datastore/datastore.ts +6 -0
- package/src/datastore/loadGetRandomValues.native.ts +24 -0
- package/src/datastore/loadGetRandomValues.ts +7 -0
- package/src/index.ts +2 -0
- package/src/predicates/next.ts +1 -1
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/relationship.ts +9 -4
- package/src/sync/processors/subscription.ts +1 -1
- package/src/sync/processors/sync.ts +1 -1
- package/src/types.ts +2 -2
- package/src/util.ts +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataStore = exports.initSchema = exports.DataStoreClass = exports.AsyncCollection = exports.AsyncItem = exports.getAttachment = exports.syncClasses = void 0;
|
|
4
|
+
exports.attached = attached;
|
|
3
5
|
var tslib_1 = require("tslib");
|
|
4
6
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
7
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -19,11 +21,16 @@ var types_1 = require("../types");
|
|
|
19
21
|
var util_1 = require("../util");
|
|
20
22
|
var next_1 = require("../predicates/next");
|
|
21
23
|
var utils_1 = require("../sync/utils");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
var loadGetRandomValues_1 = require("./loadGetRandomValues");
|
|
25
|
+
// `uuid` v4 (used below to mint model ids) requires `crypto.getRandomValues`,
|
|
26
|
+
// which is not available in React Native. On RN this loads the
|
|
27
|
+
// `react-native-get-random-values` polyfill; on web/Node it is a no-op.
|
|
28
|
+
(0, loadGetRandomValues_1.loadGetRandomValues)();
|
|
29
|
+
(0, immer_1.setAutoFreeze)(true);
|
|
30
|
+
(0, immer_1.enablePatches)();
|
|
24
31
|
var logger = new core_1.ConsoleLogger('DataStore');
|
|
25
|
-
var ulid = util_1.monotonicUlidFactory(Date.now());
|
|
26
|
-
var isNode = core_1.browserOrNode().isNode;
|
|
32
|
+
var ulid = (0, util_1.monotonicUlidFactory)(Date.now());
|
|
33
|
+
var isNode = (0, core_1.browserOrNode)().isNode;
|
|
27
34
|
var SETTING_SCHEMA_VERSION = 'schemaVersion';
|
|
28
35
|
var schema;
|
|
29
36
|
var modelNamespaceMap = new WeakMap();
|
|
@@ -48,12 +55,12 @@ var getModelDefinition = function (modelConstructor) {
|
|
|
48
55
|
* @param obj The object to test.
|
|
49
56
|
*/
|
|
50
57
|
var isValidModelConstructor = function (obj) {
|
|
51
|
-
return util_1.isModelConstructor(obj) && modelNamespaceMap.has(obj);
|
|
58
|
+
return (0, util_1.isModelConstructor)(obj) && modelNamespaceMap.has(obj);
|
|
52
59
|
};
|
|
53
60
|
var namespaceResolver = function (modelConstructor) {
|
|
54
61
|
var resolver = modelNamespaceMap.get(modelConstructor);
|
|
55
62
|
if (!resolver) {
|
|
56
|
-
throw new Error("Namespace Resolver for '"
|
|
63
|
+
throw new Error("Namespace Resolver for '".concat(modelConstructor.name, "' not found! This is probably a bug in '@amplify-js/datastore'."));
|
|
57
64
|
}
|
|
58
65
|
return resolver;
|
|
59
66
|
};
|
|
@@ -82,10 +89,10 @@ var buildSeedPredicate = function (modelConstructor) {
|
|
|
82
89
|
var modelSchema = getModelDefinition(modelConstructor);
|
|
83
90
|
if (!modelSchema)
|
|
84
91
|
throw new Error('Missing modelSchema');
|
|
85
|
-
var pks = util_1.extractPrimaryKeyFieldNames(modelSchema);
|
|
92
|
+
var pks = (0, util_1.extractPrimaryKeyFieldNames)(modelSchema);
|
|
86
93
|
if (!pks)
|
|
87
94
|
throw new Error('Could not determine PK');
|
|
88
|
-
return next_1.recursivePredicateFor({
|
|
95
|
+
return (0, next_1.recursivePredicateFor)({
|
|
89
96
|
builder: modelConstructor,
|
|
90
97
|
schema: modelSchema,
|
|
91
98
|
pkField: pks,
|
|
@@ -146,7 +153,6 @@ function attached(result, attachment) {
|
|
|
146
153
|
}
|
|
147
154
|
return result;
|
|
148
155
|
}
|
|
149
|
-
exports.attached = attached;
|
|
150
156
|
/**
|
|
151
157
|
* Determines what source a model instance should lazy load from.
|
|
152
158
|
*
|
|
@@ -154,11 +160,12 @@ exports.attached = attached;
|
|
|
154
160
|
*
|
|
155
161
|
* @param instance A model instance
|
|
156
162
|
*/
|
|
157
|
-
|
|
163
|
+
var getAttachment = function (instance) {
|
|
158
164
|
return attachedModelInstances.has(instance)
|
|
159
165
|
? attachedModelInstances.get(instance)
|
|
160
166
|
: ModelAttachment.Detached;
|
|
161
167
|
};
|
|
168
|
+
exports.getAttachment = getAttachment;
|
|
162
169
|
var initSchema = function (userSchema) {
|
|
163
170
|
var _a;
|
|
164
171
|
if (schema !== undefined) {
|
|
@@ -189,7 +196,7 @@ var initSchema = function (userSchema) {
|
|
|
189
196
|
};
|
|
190
197
|
Object.keys(schema.namespaces).forEach(function (namespace) {
|
|
191
198
|
var e_1, _a;
|
|
192
|
-
var _b = tslib_1.__read(util_1.establishRelationAndKeys(schema.namespaces[namespace]), 2), relations = _b[0], keys = _b[1];
|
|
199
|
+
var _b = tslib_1.__read((0, util_1.establishRelationAndKeys)(schema.namespaces[namespace]), 2), relations = _b[0], keys = _b[1];
|
|
193
200
|
schema.namespaces[namespace].relationships = relations;
|
|
194
201
|
schema.namespaces[namespace].keys = keys;
|
|
195
202
|
var modelAssociations = new Map();
|
|
@@ -211,16 +218,16 @@ var initSchema = function (userSchema) {
|
|
|
211
218
|
// to go looking for it.
|
|
212
219
|
Object.values(model.fields).forEach(function (field) {
|
|
213
220
|
var relatedModel = userClasses[field.type.model];
|
|
214
|
-
if (util_1.isModelConstructor(relatedModel)) {
|
|
221
|
+
if ((0, util_1.isModelConstructor)(relatedModel)) {
|
|
215
222
|
Object.defineProperty(field.type, 'modelConstructor', {
|
|
216
223
|
get: function () {
|
|
217
224
|
var relatedModelDefinition = getModelDefinition(relatedModel);
|
|
218
225
|
if (!relatedModelDefinition)
|
|
219
|
-
throw new Error("Could not find model definition for "
|
|
226
|
+
throw new Error("Could not find model definition for ".concat(relatedModel.name));
|
|
220
227
|
return {
|
|
221
228
|
builder: relatedModel,
|
|
222
229
|
schema: relatedModelDefinition,
|
|
223
|
-
pkField: util_1.extractPrimaryKeyFieldNames(relatedModelDefinition),
|
|
230
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(relatedModelDefinition),
|
|
224
231
|
};
|
|
225
232
|
},
|
|
226
233
|
});
|
|
@@ -256,7 +263,7 @@ var initSchema = function (userSchema) {
|
|
|
256
263
|
}
|
|
257
264
|
finally { if (e_2) throw e_2.error; }
|
|
258
265
|
}
|
|
259
|
-
model.allFields = tslib_1.__assign(tslib_1.__assign({}, Object.fromEntries(tslib_1.
|
|
266
|
+
model.allFields = tslib_1.__assign(tslib_1.__assign({}, Object.fromEntries(tslib_1.__spreadArray([], tslib_1.__read(indexFields.values()), false).map(function (name) { return [
|
|
260
267
|
name,
|
|
261
268
|
{
|
|
262
269
|
name: name,
|
|
@@ -342,10 +349,10 @@ var checkSchemaCodegenVersion = function (codegenVersion) {
|
|
|
342
349
|
isValid = Number(major) === majorVersion && Number(minor) >= minorVersion;
|
|
343
350
|
}
|
|
344
351
|
catch (err) {
|
|
345
|
-
console.log("Error parsing codegen version: "
|
|
352
|
+
console.log("Error parsing codegen version: ".concat(codegenVersion, "\n").concat(err));
|
|
346
353
|
}
|
|
347
354
|
if (!isValid) {
|
|
348
|
-
var message = "Models were generated with an unsupported version of codegen. Codegen artifacts are from "
|
|
355
|
+
var message = "Models were generated with an unsupported version of codegen. Codegen artifacts are from ".concat(codegenVersion || 'an unknown version', ", whereas ^").concat(majorVersion, ".").concat(minorVersion, ".0 is required. ") +
|
|
349
356
|
"Update to the latest CLI and run 'amplify codegen models'.";
|
|
350
357
|
logger.error(message);
|
|
351
358
|
throw new Error(message);
|
|
@@ -380,24 +387,24 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
380
387
|
var fieldDefinition = modelDefinition.fields[k];
|
|
381
388
|
if (fieldDefinition !== undefined) {
|
|
382
389
|
var type_1 = fieldDefinition.type, isRequired_1 = fieldDefinition.isRequired, isArrayNullable = fieldDefinition.isArrayNullable, name_1 = fieldDefinition.name, isArray = fieldDefinition.isArray;
|
|
383
|
-
var timestamps = types_1.isSchemaModelWithAttributes(modelDefinition)
|
|
384
|
-
? util_1.getTimestampFields(modelDefinition)
|
|
390
|
+
var timestamps = (0, types_1.isSchemaModelWithAttributes)(modelDefinition)
|
|
391
|
+
? (0, util_1.getTimestampFields)(modelDefinition)
|
|
385
392
|
: {};
|
|
386
393
|
var isTimestampField = !!timestamps[name_1];
|
|
387
394
|
if (((!isArray && isRequired_1) || (isArray && !isArrayNullable)) &&
|
|
388
395
|
!isTimestampField &&
|
|
389
396
|
(v === null || v === undefined)) {
|
|
390
|
-
throw new Error("Field "
|
|
397
|
+
throw new Error("Field ".concat(name_1, " is required"));
|
|
391
398
|
}
|
|
392
|
-
if (types_1.isSchemaModelWithAttributes(modelDefinition) &&
|
|
393
|
-
!util_1.isIdManaged(modelDefinition)) {
|
|
394
|
-
var keys = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
399
|
+
if ((0, types_1.isSchemaModelWithAttributes)(modelDefinition) &&
|
|
400
|
+
!(0, util_1.isIdManaged)(modelDefinition)) {
|
|
401
|
+
var keys = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
395
402
|
if (keys.includes(k) && v === '') {
|
|
396
403
|
logger.error(util_1.errorMessages.idEmptyString, { k: k, value: v });
|
|
397
404
|
throw new Error(util_1.errorMessages.idEmptyString);
|
|
398
405
|
}
|
|
399
406
|
}
|
|
400
|
-
if (types_1.isGraphQLScalarType(type_1)) {
|
|
407
|
+
if ((0, types_1.isGraphQLScalarType)(type_1)) {
|
|
401
408
|
var jsType_1 = types_1.GraphQLScalarType.getJSType(type_1);
|
|
402
409
|
var validateScalar_1 = types_1.GraphQLScalarType.getValidationFunction(type_1);
|
|
403
410
|
if (type_1 === 'AWSJSON') {
|
|
@@ -410,33 +417,33 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
410
417
|
return;
|
|
411
418
|
}
|
|
412
419
|
catch (error) {
|
|
413
|
-
throw new Error("Field "
|
|
420
|
+
throw new Error("Field ".concat(name_1, " is an invalid JSON object. ").concat(v));
|
|
414
421
|
}
|
|
415
422
|
}
|
|
416
423
|
}
|
|
417
424
|
if (isArray) {
|
|
418
425
|
var errorTypeText = jsType_1;
|
|
419
426
|
if (!isRequired_1) {
|
|
420
|
-
errorTypeText = jsType_1
|
|
427
|
+
errorTypeText = "".concat(jsType_1, " | null | undefined");
|
|
421
428
|
}
|
|
422
429
|
if (!Array.isArray(v) && !isArrayNullable) {
|
|
423
|
-
throw new Error("Field "
|
|
430
|
+
throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
|
|
424
431
|
}
|
|
425
|
-
if (!util_1.isNullOrUndefined(v) &&
|
|
432
|
+
if (!(0, util_1.isNullOrUndefined)(v) &&
|
|
426
433
|
v.some(function (e) {
|
|
427
|
-
return util_1.isNullOrUndefined(e) ? isRequired_1 : typeof e !== jsType_1;
|
|
434
|
+
return (0, util_1.isNullOrUndefined)(e) ? isRequired_1 : typeof e !== jsType_1;
|
|
428
435
|
})) {
|
|
429
436
|
var elemTypes = v
|
|
430
437
|
.map(function (e) { return (e === null ? 'null' : typeof e); })
|
|
431
438
|
.join(',');
|
|
432
|
-
throw new Error("All elements in the "
|
|
439
|
+
throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(errorTypeText, ", [").concat(elemTypes, "] received. ").concat(v));
|
|
433
440
|
}
|
|
434
|
-
if (validateScalar_1 && !util_1.isNullOrUndefined(v)) {
|
|
441
|
+
if (validateScalar_1 && !(0, util_1.isNullOrUndefined)(v)) {
|
|
435
442
|
var validationStatus = v.map(function (e) {
|
|
436
|
-
if (!util_1.isNullOrUndefined(e)) {
|
|
443
|
+
if (!(0, util_1.isNullOrUndefined)(e)) {
|
|
437
444
|
return validateScalar_1(e);
|
|
438
445
|
}
|
|
439
|
-
else if (util_1.isNullOrUndefined(e) && !isRequired_1) {
|
|
446
|
+
else if ((0, util_1.isNullOrUndefined)(e) && !isRequired_1) {
|
|
440
447
|
return true;
|
|
441
448
|
}
|
|
442
449
|
else {
|
|
@@ -444,7 +451,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
444
451
|
}
|
|
445
452
|
});
|
|
446
453
|
if (!validationStatus.every(function (s) { return s; })) {
|
|
447
|
-
throw new Error("All elements in the "
|
|
454
|
+
throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(type_1, ", validation failed for one or more elements. ").concat(v));
|
|
448
455
|
}
|
|
449
456
|
}
|
|
450
457
|
}
|
|
@@ -452,34 +459,34 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
452
459
|
return;
|
|
453
460
|
}
|
|
454
461
|
else if (typeof v !== jsType_1 && v !== null) {
|
|
455
|
-
throw new Error("Field "
|
|
462
|
+
throw new Error("Field ".concat(name_1, " should be of type ").concat(jsType_1, ", ").concat(typeof v, " received. ").concat(v));
|
|
456
463
|
}
|
|
457
|
-
else if (!util_1.isNullOrUndefined(v) &&
|
|
464
|
+
else if (!(0, util_1.isNullOrUndefined)(v) &&
|
|
458
465
|
validateScalar_1 &&
|
|
459
466
|
!validateScalar_1(v) // TODO: why never, TS ... why ...
|
|
460
467
|
) {
|
|
461
|
-
throw new Error("Field "
|
|
468
|
+
throw new Error("Field ".concat(name_1, " should be of type ").concat(type_1, ", validation failed. ").concat(v));
|
|
462
469
|
}
|
|
463
470
|
}
|
|
464
|
-
else if (types_1.isNonModelFieldType(type_1)) {
|
|
471
|
+
else if ((0, types_1.isNonModelFieldType)(type_1)) {
|
|
465
472
|
// do not check non model fields if undefined or null
|
|
466
|
-
if (!util_1.isNullOrUndefined(v)) {
|
|
473
|
+
if (!(0, util_1.isNullOrUndefined)(v)) {
|
|
467
474
|
var subNonModelDefinition_1 = schema.namespaces.user.nonModels[type_1.nonModel];
|
|
468
475
|
var modelValidator_1 = validateModelFields(subNonModelDefinition_1);
|
|
469
476
|
if (isArray) {
|
|
470
477
|
var errorTypeText = type_1.nonModel;
|
|
471
478
|
if (!isRequired_1) {
|
|
472
|
-
errorTypeText = type_1.nonModel
|
|
479
|
+
errorTypeText = "".concat(type_1.nonModel, " | null | undefined");
|
|
473
480
|
}
|
|
474
481
|
if (!Array.isArray(v)) {
|
|
475
|
-
throw new Error("Field "
|
|
482
|
+
throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
|
|
476
483
|
}
|
|
477
484
|
v.forEach(function (item) {
|
|
478
|
-
if ((util_1.isNullOrUndefined(item) && isRequired_1) ||
|
|
485
|
+
if (((0, util_1.isNullOrUndefined)(item) && isRequired_1) ||
|
|
479
486
|
(typeof item !== 'object' && typeof item !== 'undefined')) {
|
|
480
|
-
throw new Error("All elements in the "
|
|
487
|
+
throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(type_1.nonModel, ", [").concat(typeof item, "] received. ").concat(item));
|
|
481
488
|
}
|
|
482
|
-
if (!util_1.isNullOrUndefined(item)) {
|
|
489
|
+
if (!(0, util_1.isNullOrUndefined)(item)) {
|
|
483
490
|
Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
|
|
484
491
|
modelValidator_1(subKey, item[subKey]);
|
|
485
492
|
});
|
|
@@ -488,7 +495,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
488
495
|
}
|
|
489
496
|
else {
|
|
490
497
|
if (typeof v !== 'object') {
|
|
491
|
-
throw new Error("Field "
|
|
498
|
+
throw new Error("Field ".concat(name_1, " should be of type ").concat(type_1.nonModel, ", ").concat(typeof v, " recieved. ").concat(v));
|
|
492
499
|
}
|
|
493
500
|
Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
|
|
494
501
|
modelValidator_1(subKey, v[subKey]);
|
|
@@ -504,8 +511,8 @@ var castInstanceType = function (modelDefinition, k, v) {
|
|
|
504
511
|
if (typeof v === 'string' &&
|
|
505
512
|
(isArray ||
|
|
506
513
|
type === 'AWSJSON' ||
|
|
507
|
-
types_1.isNonModelFieldType(type) ||
|
|
508
|
-
types_1.isModelFieldType(type))) {
|
|
514
|
+
(0, types_1.isNonModelFieldType)(type) ||
|
|
515
|
+
(0, types_1.isModelFieldType)(type))) {
|
|
509
516
|
try {
|
|
510
517
|
return JSON.parse(v);
|
|
511
518
|
}
|
|
@@ -586,7 +593,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
586
593
|
// set by customer code versus those set by normalization. only those fields
|
|
587
594
|
// which are explicitly set by customers should be part of create mutations.
|
|
588
595
|
var patches = [];
|
|
589
|
-
var baseInstance = immer_1.produce(this, function (draft) {
|
|
596
|
+
var baseInstance = (0, immer_1.produce)(this, function (draft) {
|
|
590
597
|
initializeInstance(init, modelDefinition, draft);
|
|
591
598
|
// model is initialized inside a DataStore component (e.g. by Sync Engine, Storage Engine, etc.)
|
|
592
599
|
var isInternallyInitialized = instancesMetadata.has(init);
|
|
@@ -594,18 +601,18 @@ var createModelClass = function (modelDefinition) {
|
|
|
594
601
|
? init
|
|
595
602
|
: {};
|
|
596
603
|
var _id = modelInstanceMetadata.id;
|
|
597
|
-
if (util_1.isIdManaged(modelDefinition)) {
|
|
604
|
+
if ((0, util_1.isIdManaged)(modelDefinition)) {
|
|
598
605
|
var isInternalModel = _id !== null && _id !== undefined;
|
|
599
606
|
var id = isInternalModel
|
|
600
607
|
? _id
|
|
601
608
|
: modelDefinition.syncable
|
|
602
|
-
? uuid_1.v4()
|
|
609
|
+
? (0, uuid_1.v4)()
|
|
603
610
|
: ulid();
|
|
604
611
|
draft.id = id;
|
|
605
612
|
}
|
|
606
|
-
else if (util_1.isIdOptionallyManaged(modelDefinition)) {
|
|
613
|
+
else if ((0, util_1.isIdOptionallyManaged)(modelDefinition)) {
|
|
607
614
|
// only auto-populate if the id was not provided
|
|
608
|
-
draft.id = draft.id || uuid_1.v4();
|
|
615
|
+
draft.id = draft.id || (0, uuid_1.v4)();
|
|
609
616
|
}
|
|
610
617
|
if (!isInternallyInitialized) {
|
|
611
618
|
checkReadOnlyPropertyOnCreate(draft, modelDefinition);
|
|
@@ -622,7 +629,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
622
629
|
// are only create to provide a consistent view of the data for fields pre/post sync
|
|
623
630
|
// where possible. (not all fields can be normalized pre-sync, because they're generally
|
|
624
631
|
// "cloud managed" fields, like createdAt and updatedAt.)
|
|
625
|
-
var normalized = immer_1.produce(baseInstance, function (draft) {
|
|
632
|
+
var normalized = (0, immer_1.produce)(baseInstance, function (draft) {
|
|
626
633
|
return normalize(modelDefinition, draft);
|
|
627
634
|
});
|
|
628
635
|
initPatches.set(normalized, patches);
|
|
@@ -636,13 +643,13 @@ var createModelClass = function (modelDefinition) {
|
|
|
636
643
|
throw new Error(msg);
|
|
637
644
|
}
|
|
638
645
|
var patches = [];
|
|
639
|
-
var model = immer_1.produce(source, function (draft) {
|
|
646
|
+
var model = (0, immer_1.produce)(source, function (draft) {
|
|
640
647
|
fn(draft);
|
|
641
|
-
var keyNames = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
648
|
+
var keyNames = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
642
649
|
// Keys are immutable
|
|
643
650
|
keyNames.forEach(function (key) {
|
|
644
651
|
if (draft[key] !== source[key]) {
|
|
645
|
-
logger.warn("copyOf() does not update PK fields. The '"
|
|
652
|
+
logger.warn("copyOf() does not update PK fields. The '".concat(key, "' update is being ignored."), { source: source });
|
|
646
653
|
}
|
|
647
654
|
draft[key] = source[key];
|
|
648
655
|
});
|
|
@@ -658,7 +665,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
658
665
|
if (patches.length || hasExistingPatches) {
|
|
659
666
|
if (hasExistingPatches) {
|
|
660
667
|
var _a = tslib_1.__read(modelPatchesMap.get(source), 2), existingPatches = _a[0], existingSource = _a[1];
|
|
661
|
-
var mergedPatches = util_1.mergePatches(existingSource, existingPatches, patches);
|
|
668
|
+
var mergedPatches = (0, util_1.mergePatches)(existingSource, existingPatches, patches);
|
|
662
669
|
modelPatchesMap.set(model, [mergedPatches, existingSource]);
|
|
663
670
|
checkReadOnlyPropertyOnUpdate(mergedPatches, modelDefinition);
|
|
664
671
|
}
|
|
@@ -703,7 +710,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
703
710
|
var allModelRelationships = relationship_1.ModelRelationship.allFrom({
|
|
704
711
|
builder: clazz,
|
|
705
712
|
schema: modelDefinition,
|
|
706
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
713
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
707
714
|
});
|
|
708
715
|
var _loop_1 = function (relationship) {
|
|
709
716
|
var field = relationship.field;
|
|
@@ -720,13 +727,13 @@ var createModelClass = function (modelDefinition) {
|
|
|
720
727
|
var modelConstructor = Object.getPrototypeOf(model || {})
|
|
721
728
|
.constructor;
|
|
722
729
|
if (!isValidModelConstructor(modelConstructor)) {
|
|
723
|
-
var msg = "Value passed to "
|
|
730
|
+
var msg = "Value passed to ".concat(modelDefinition.name, ".").concat(field, " is not a valid instance of a model");
|
|
724
731
|
logger.error(msg, { model: model });
|
|
725
732
|
throw new Error(msg);
|
|
726
733
|
}
|
|
727
734
|
if (modelConstructor.name.toLowerCase() !==
|
|
728
735
|
relationship.remoteModelConstructor.name.toLowerCase()) {
|
|
729
|
-
var msg = "Value passed to "
|
|
736
|
+
var msg = "Value passed to ".concat(modelDefinition.name, ".").concat(field, " is not an instance of ").concat(relationship.remoteModelConstructor.name);
|
|
730
737
|
logger.error(msg, { model: model });
|
|
731
738
|
throw new Error(msg);
|
|
732
739
|
}
|
|
@@ -735,7 +742,8 @@ var createModelClass = function (modelDefinition) {
|
|
|
735
742
|
// if the relationship can be managed automagically, set the FK's
|
|
736
743
|
if (relationship.isComplete) {
|
|
737
744
|
for (var i = 0; i < relationship.localJoinFields.length; i++) {
|
|
738
|
-
this[relationship.localJoinFields[i]] =
|
|
745
|
+
this[relationship.localJoinFields[i]] =
|
|
746
|
+
model === null || model === void 0 ? void 0 : model[relationship.remoteJoinFields[i]];
|
|
739
747
|
}
|
|
740
748
|
var instanceMemos = modelInstanceAssociationsMap.has(this)
|
|
741
749
|
? modelInstanceAssociationsMap.get(this)
|
|
@@ -757,7 +765,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
757
765
|
if (!instanceMemos.hasOwnProperty(field)) {
|
|
758
766
|
// before we populate the memo, we need to know where to look for relatives.
|
|
759
767
|
// today, this only supports DataStore. Models aren't managed elsewhere in Amplify.
|
|
760
|
-
if (exports.getAttachment(this) === ModelAttachment.DataStore) {
|
|
768
|
+
if ((0, exports.getAttachment)(this) === ModelAttachment.DataStore) {
|
|
761
769
|
// when we fetch the results using a query constructed under the guidance
|
|
762
770
|
// of the relationship metadata, we DO NOT AWAIT resolution. we want to
|
|
763
771
|
// drop the promise into the memo's synchronously, eliminating the chance
|
|
@@ -783,7 +791,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
783
791
|
instanceMemos[field] = resultPromise.then(function (rows) {
|
|
784
792
|
if (rows.length > 1) {
|
|
785
793
|
// should never happen for a HAS_ONE or BELONGS_TO.
|
|
786
|
-
var err = new Error("\n\t\t\t\t\t\t\t\t\tData integrity error.\n\t\t\t\t\t\t\t\t\tToo many records found for a HAS_ONE/BELONGS_TO field '"
|
|
794
|
+
var err = new Error("\n\t\t\t\t\t\t\t\t\tData integrity error.\n\t\t\t\t\t\t\t\t\tToo many records found for a HAS_ONE/BELONGS_TO field '".concat(modelDefinition.name, ".").concat(field, "'\n\t\t\t\t\t\t\t\t"));
|
|
787
795
|
console.error(err);
|
|
788
796
|
throw err;
|
|
789
797
|
}
|
|
@@ -793,7 +801,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
793
801
|
});
|
|
794
802
|
}
|
|
795
803
|
}
|
|
796
|
-
else if (exports.getAttachment(this) === ModelAttachment.API) {
|
|
804
|
+
else if ((0, exports.getAttachment)(this) === ModelAttachment.API) {
|
|
797
805
|
throw new Error('Lazy loading from API is not yet supported!');
|
|
798
806
|
}
|
|
799
807
|
else {
|
|
@@ -896,25 +904,27 @@ var AsyncCollection = /** @class */ (function () {
|
|
|
896
904
|
* const first100 = await collection.toArray({max: 100});
|
|
897
905
|
* ```
|
|
898
906
|
*/
|
|
899
|
-
AsyncCollection.prototype.toArray = function (
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
var
|
|
904
|
-
return tslib_1.__generator(this, function (
|
|
905
|
-
switch (
|
|
907
|
+
AsyncCollection.prototype.toArray = function () {
|
|
908
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (_a) {
|
|
909
|
+
var output, i, _b, _c, _d, element, e_6_1;
|
|
910
|
+
var _e, e_6, _f, _g;
|
|
911
|
+
var _h = _a === void 0 ? {} : _a, _j = _h.max, max = _j === void 0 ? Number.MAX_SAFE_INTEGER : _j;
|
|
912
|
+
return tslib_1.__generator(this, function (_k) {
|
|
913
|
+
switch (_k.label) {
|
|
906
914
|
case 0:
|
|
907
915
|
output = [];
|
|
908
916
|
i = 0;
|
|
909
|
-
|
|
917
|
+
_k.label = 1;
|
|
910
918
|
case 1:
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
case 2: return [4 /*yield*/,
|
|
919
|
+
_k.trys.push([1, 6, 7, 12]);
|
|
920
|
+
_b = true, _c = tslib_1.__asyncValues(this);
|
|
921
|
+
_k.label = 2;
|
|
922
|
+
case 2: return [4 /*yield*/, _c.next()];
|
|
915
923
|
case 3:
|
|
916
|
-
if (!(
|
|
917
|
-
|
|
924
|
+
if (!(_d = _k.sent(), _e = _d.done, !_e)) return [3 /*break*/, 5];
|
|
925
|
+
_g = _d.value;
|
|
926
|
+
_b = false;
|
|
927
|
+
element = _g;
|
|
918
928
|
if (i < max) {
|
|
919
929
|
output.push(element);
|
|
920
930
|
i++;
|
|
@@ -922,20 +932,22 @@ var AsyncCollection = /** @class */ (function () {
|
|
|
922
932
|
else {
|
|
923
933
|
return [3 /*break*/, 5];
|
|
924
934
|
}
|
|
925
|
-
|
|
926
|
-
case 4:
|
|
935
|
+
_k.label = 4;
|
|
936
|
+
case 4:
|
|
937
|
+
_b = true;
|
|
938
|
+
return [3 /*break*/, 2];
|
|
927
939
|
case 5: return [3 /*break*/, 12];
|
|
928
940
|
case 6:
|
|
929
|
-
e_6_1 =
|
|
941
|
+
e_6_1 = _k.sent();
|
|
930
942
|
e_6 = { error: e_6_1 };
|
|
931
943
|
return [3 /*break*/, 12];
|
|
932
944
|
case 7:
|
|
933
|
-
|
|
934
|
-
if (!(
|
|
935
|
-
return [4 /*yield*/,
|
|
945
|
+
_k.trys.push([7, , 10, 11]);
|
|
946
|
+
if (!(!_b && !_e && (_f = _c.return))) return [3 /*break*/, 9];
|
|
947
|
+
return [4 /*yield*/, _f.call(_c)];
|
|
936
948
|
case 8:
|
|
937
|
-
|
|
938
|
-
|
|
949
|
+
_k.sent();
|
|
950
|
+
_k.label = 9;
|
|
939
951
|
case 9: return [3 /*break*/, 11];
|
|
940
952
|
case 10:
|
|
941
953
|
if (e_6) throw e_6.error;
|
|
@@ -954,7 +966,7 @@ var checkReadOnlyPropertyOnCreate = function (draft, modelDefinition) {
|
|
|
954
966
|
var fields = modelDefinition.fields;
|
|
955
967
|
modelKeys.forEach(function (key) {
|
|
956
968
|
if (fields[key] && fields[key].isReadOnly) {
|
|
957
|
-
throw new Error(key
|
|
969
|
+
throw new Error("".concat(key, " is read-only."));
|
|
958
970
|
}
|
|
959
971
|
});
|
|
960
972
|
};
|
|
@@ -966,14 +978,14 @@ var checkReadOnlyPropertyOnUpdate = function (patches, modelDefinition) {
|
|
|
966
978
|
if (!val || !fields[key])
|
|
967
979
|
return;
|
|
968
980
|
if (fields[key].isReadOnly) {
|
|
969
|
-
throw new Error(key
|
|
981
|
+
throw new Error("".concat(key, " is read-only."));
|
|
970
982
|
}
|
|
971
983
|
});
|
|
972
984
|
};
|
|
973
985
|
var createNonModelClass = function (typeDefinition) {
|
|
974
986
|
var clazz = /** @class */ (function () {
|
|
975
987
|
function Model(init) {
|
|
976
|
-
var instance = immer_1.produce(this, function (draft) {
|
|
988
|
+
var instance = (0, immer_1.produce)(this, function (draft) {
|
|
977
989
|
initializeInstance(init, typeDefinition, draft);
|
|
978
990
|
});
|
|
979
991
|
return instance;
|
|
@@ -982,7 +994,7 @@ var createNonModelClass = function (typeDefinition) {
|
|
|
982
994
|
}());
|
|
983
995
|
clazz[immer_1.immerable] = true;
|
|
984
996
|
Object.defineProperty(clazz, 'name', { value: typeDefinition.name });
|
|
985
|
-
util_1.registerNonModelClass(clazz);
|
|
997
|
+
(0, util_1.registerNonModelClass)(clazz);
|
|
986
998
|
return clazz;
|
|
987
999
|
};
|
|
988
1000
|
function isQueryOne(obj) {
|
|
@@ -1012,13 +1024,13 @@ function getModelConstructorByModelName(namespaceName, modelName) {
|
|
|
1012
1024
|
result = storageClasses[modelName];
|
|
1013
1025
|
break;
|
|
1014
1026
|
default:
|
|
1015
|
-
throw new Error("Invalid namespace: "
|
|
1027
|
+
throw new Error("Invalid namespace: ".concat(namespaceName));
|
|
1016
1028
|
}
|
|
1017
1029
|
if (isValidModelConstructor(result)) {
|
|
1018
1030
|
return result;
|
|
1019
1031
|
}
|
|
1020
1032
|
else {
|
|
1021
|
-
var msg = "Model name is not valid for namespace. modelName: "
|
|
1033
|
+
var msg = "Model name is not valid for namespace. modelName: ".concat(modelName, ", namespace: ").concat(namespaceName);
|
|
1022
1034
|
logger.error(msg);
|
|
1023
1035
|
throw new Error(msg);
|
|
1024
1036
|
}
|
|
@@ -1307,7 +1319,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1307
1319
|
throw new Error('Invalid model definition provided!');
|
|
1308
1320
|
}
|
|
1309
1321
|
pagination = this.processPagination(modelDefinition, paginationProducer);
|
|
1310
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1322
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1311
1323
|
if (!isQueryOne(identifierOrCriteria)) return [3 /*break*/, 3];
|
|
1312
1324
|
if (keyFields.length > 1) {
|
|
1313
1325
|
msg = util_1.errorMessages.queryByPkWithCompositeKeyPresent;
|
|
@@ -1320,7 +1332,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1320
1332
|
result = _c.sent();
|
|
1321
1333
|
return [3 /*break*/, 9];
|
|
1322
1334
|
case 3:
|
|
1323
|
-
if (!types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
|
|
1335
|
+
if (!(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
|
|
1324
1336
|
predicate = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
|
|
1325
1337
|
return [4 /*yield*/, this.storage.query(modelConstructor, predicate, pagination)];
|
|
1326
1338
|
case 4:
|
|
@@ -1328,26 +1340,26 @@ var DataStore = /** @class */ (function () {
|
|
|
1328
1340
|
return [3 /*break*/, 9];
|
|
1329
1341
|
case 5:
|
|
1330
1342
|
if (!(!identifierOrCriteria ||
|
|
1331
|
-
predicates_1.isPredicatesAll(identifierOrCriteria))) return [3 /*break*/, 7];
|
|
1343
|
+
(0, predicates_1.isPredicatesAll)(identifierOrCriteria))) return [3 /*break*/, 7];
|
|
1332
1344
|
return [4 /*yield*/, ((_b = this.storage) === null || _b === void 0 ? void 0 : _b.query(modelConstructor, undefined, pagination))];
|
|
1333
1345
|
case 6:
|
|
1334
1346
|
result = _c.sent();
|
|
1335
1347
|
return [3 /*break*/, 9];
|
|
1336
1348
|
case 7:
|
|
1337
|
-
seedPredicate = next_1.recursivePredicateFor({
|
|
1349
|
+
seedPredicate = (0, next_1.recursivePredicateFor)({
|
|
1338
1350
|
builder: modelConstructor,
|
|
1339
1351
|
schema: modelDefinition,
|
|
1340
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1352
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1341
1353
|
});
|
|
1342
|
-
predicate = next_1.internals(identifierOrCriteria(seedPredicate));
|
|
1354
|
+
predicate = (0, next_1.internals)(identifierOrCriteria(seedPredicate));
|
|
1343
1355
|
return [4 /*yield*/, predicate.fetch(this.storage)];
|
|
1344
1356
|
case 8:
|
|
1345
1357
|
result = (_c.sent());
|
|
1346
|
-
result = util_1.inMemoryPagination(result, pagination);
|
|
1358
|
+
result = (0, util_1.inMemoryPagination)(result, pagination);
|
|
1347
1359
|
_c.label = 9;
|
|
1348
1360
|
case 9:
|
|
1349
1361
|
returnOne = isQueryOne(identifierOrCriteria) ||
|
|
1350
|
-
types_1.isIdentifierObject(identifierOrCriteria, modelDefinition);
|
|
1362
|
+
(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition);
|
|
1351
1363
|
return [2 /*return*/, attached(returnOne ? result[0] : result, ModelAttachment.DataStore)];
|
|
1352
1364
|
}
|
|
1353
1365
|
});
|
|
@@ -1388,7 +1400,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1388
1400
|
modelMeta = {
|
|
1389
1401
|
builder: modelConstructor,
|
|
1390
1402
|
schema: modelDefinition,
|
|
1391
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1403
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1392
1404
|
};
|
|
1393
1405
|
return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1394
1406
|
var nonHasManyRelationships, nonHasManyRelationships_1, nonHasManyRelationships_1_1, relationship, queryObject, related, e_7_1;
|
|
@@ -1413,10 +1425,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1413
1425
|
related = _c.sent();
|
|
1414
1426
|
if (related.length === 0) {
|
|
1415
1427
|
throw new Error([
|
|
1416
|
-
"Data integrity error. You tried to save a "
|
|
1417
|
-
"but the instance assigned to the \""
|
|
1428
|
+
"Data integrity error. You tried to save a ".concat(modelDefinition.name, " (").concat(JSON.stringify(model), ")"),
|
|
1429
|
+
"but the instance assigned to the \"".concat(relationship.field, "\" property"),
|
|
1418
1430
|
"does not exist in the local database. If you're trying to create the related",
|
|
1419
|
-
"\""
|
|
1431
|
+
"\"".concat((_b = relationship.remoteDefinition) === null || _b === void 0 ? void 0 : _b.name, "\", you must save it independently first."),
|
|
1420
1432
|
].join(' '));
|
|
1421
1433
|
}
|
|
1422
1434
|
_c.label = 4;
|
|
@@ -1441,7 +1453,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1441
1453
|
case 2:
|
|
1442
1454
|
_b.sent();
|
|
1443
1455
|
producedCondition = condition
|
|
1444
|
-
? next_1.internals(condition(next_1.predicateFor(modelMeta))).toStoragePredicate()
|
|
1456
|
+
? (0, next_1.internals)(condition((0, next_1.predicateFor)(modelMeta))).toStoragePredicate()
|
|
1445
1457
|
: undefined;
|
|
1446
1458
|
return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1447
1459
|
var saved;
|
|
@@ -1521,7 +1533,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1521
1533
|
throw new Error('Could not find model definition for modelConstructor.');
|
|
1522
1534
|
}
|
|
1523
1535
|
if (typeof identifierOrCriteria === 'string') {
|
|
1524
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1536
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1525
1537
|
if (keyFields.length > 1) {
|
|
1526
1538
|
msg = util_1.errorMessages.deleteByPkWithCompositeKeyPresent;
|
|
1527
1539
|
logger.error(msg, { keyFields: keyFields });
|
|
@@ -1530,14 +1542,14 @@ var DataStore = /** @class */ (function () {
|
|
|
1530
1542
|
condition = predicates_1.ModelPredicateCreator.createFromFlatEqualities(modelDefinition, (_d = {}, _d[keyFields[0]] = identifierOrCriteria, _d));
|
|
1531
1543
|
}
|
|
1532
1544
|
else {
|
|
1533
|
-
if (types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) {
|
|
1545
|
+
if ((0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) {
|
|
1534
1546
|
condition = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
|
|
1535
1547
|
}
|
|
1536
1548
|
else {
|
|
1537
|
-
condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
|
|
1549
|
+
condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
|
|
1538
1550
|
builder: modelConstructor,
|
|
1539
1551
|
schema: modelDefinition,
|
|
1540
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1552
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1541
1553
|
}))).toStoragePredicate();
|
|
1542
1554
|
}
|
|
1543
1555
|
if (!condition ||
|
|
@@ -1571,10 +1583,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1571
1583
|
logger.error(msg, { identifierOrCriteria: identifierOrCriteria });
|
|
1572
1584
|
throw new Error(msg);
|
|
1573
1585
|
}
|
|
1574
|
-
condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
|
|
1586
|
+
condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
|
|
1575
1587
|
builder: modelConstructor,
|
|
1576
1588
|
schema: modelDefinition,
|
|
1577
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1589
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1578
1590
|
}))).toStoragePredicate();
|
|
1579
1591
|
}
|
|
1580
1592
|
else {
|
|
@@ -1616,7 +1628,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1616
1628
|
// observe should not accept object literal syntax
|
|
1617
1629
|
if (identifierOrCriteria &&
|
|
1618
1630
|
modelConstructor &&
|
|
1619
|
-
types_1.isIdentifierObject(identifierOrCriteria, getModelDefinition(modelConstructor))) {
|
|
1631
|
+
(0, types_1.isIdentifierObject)(identifierOrCriteria, getModelDefinition(modelConstructor))) {
|
|
1620
1632
|
var msg = util_1.errorMessages.observeWithObjectLiteral;
|
|
1621
1633
|
logger.error(msg, { objectLiteral: identifierOrCriteria });
|
|
1622
1634
|
throw new Error(msg);
|
|
@@ -1633,10 +1645,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1633
1645
|
}
|
|
1634
1646
|
if (modelConstructor && typeof identifierOrCriteria === 'string') {
|
|
1635
1647
|
var buildIdPredicate = function (seed) { return seed.id.eq(identifierOrCriteria); };
|
|
1636
|
-
executivePredicate = next_1.internals(buildIdPredicate(buildSeedPredicate(modelConstructor)));
|
|
1648
|
+
executivePredicate = (0, next_1.internals)(buildIdPredicate(buildSeedPredicate(modelConstructor)));
|
|
1637
1649
|
}
|
|
1638
1650
|
else if (modelConstructor && typeof identifierOrCriteria === 'function') {
|
|
1639
|
-
executivePredicate = next_1.internals(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
|
|
1651
|
+
executivePredicate = (0, next_1.internals)(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
|
|
1640
1652
|
}
|
|
1641
1653
|
return new zen_observable_ts_1.default(function (observer) {
|
|
1642
1654
|
var source;
|
|
@@ -1666,8 +1678,8 @@ var DataStore = /** @class */ (function () {
|
|
|
1666
1678
|
message = item;
|
|
1667
1679
|
if (!(item.opType !== 'DELETE')) return [3 /*break*/, 2];
|
|
1668
1680
|
modelDefinition = getModelDefinition(item.model);
|
|
1669
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1670
|
-
primaryKeysAndValues = util_1.extractPrimaryKeysAndValues(item.element, keyFields);
|
|
1681
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1682
|
+
primaryKeysAndValues = (0, util_1.extractPrimaryKeysAndValues)(item.element, keyFields);
|
|
1671
1683
|
return [4 /*yield*/, this.query(item.model, primaryKeysAndValues)];
|
|
1672
1684
|
case 1:
|
|
1673
1685
|
freshElement = _b.sent();
|
|
@@ -1749,9 +1761,9 @@ var DataStore = /** @class */ (function () {
|
|
|
1749
1761
|
throw new Error('Could not find model definition.');
|
|
1750
1762
|
}
|
|
1751
1763
|
if (model && typeof criteria === 'function') {
|
|
1752
|
-
executivePredicate = next_1.internals(criteria(buildSeedPredicate(model)));
|
|
1764
|
+
executivePredicate = (0, next_1.internals)(criteria(buildSeedPredicate(model)));
|
|
1753
1765
|
}
|
|
1754
|
-
else if (predicates_1.isPredicatesAll(criteria)) {
|
|
1766
|
+
else if ((0, predicates_1.isPredicatesAll)(criteria)) {
|
|
1755
1767
|
executivePredicate = undefined;
|
|
1756
1768
|
}
|
|
1757
1769
|
_this.runningProcesses
|
|
@@ -1767,7 +1779,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1767
1779
|
// first, query and return any locally-available records
|
|
1768
1780
|
(_a.sent()).forEach(function (item) {
|
|
1769
1781
|
var itemModelDefinition = getModelDefinition(model);
|
|
1770
|
-
var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
|
|
1782
|
+
var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
|
|
1771
1783
|
items.set(idOrPk, item);
|
|
1772
1784
|
});
|
|
1773
1785
|
// Observe the model and send a stream of updates (debounced).
|
|
@@ -1784,7 +1796,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1784
1796
|
switch (_d.label) {
|
|
1785
1797
|
case 0:
|
|
1786
1798
|
itemModelDefinition = getModelDefinition(model);
|
|
1787
|
-
idOrPk = utils_1.getIdentifierValue(itemModelDefinition, element);
|
|
1799
|
+
idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, element);
|
|
1788
1800
|
_a = executivePredicate;
|
|
1789
1801
|
if (!_a) return [3 /*break*/, 2];
|
|
1790
1802
|
return [4 /*yield*/, executivePredicate.matches(element)];
|
|
@@ -1853,11 +1865,11 @@ var DataStore = /** @class */ (function () {
|
|
|
1853
1865
|
var generateSnapshot = function () {
|
|
1854
1866
|
var _a, _b;
|
|
1855
1867
|
var isSynced = (_b = (_a = _this.sync) === null || _a === void 0 ? void 0 : _a.getModelSyncedStatus(model)) !== null && _b !== void 0 ? _b : false;
|
|
1856
|
-
var itemsArray = tslib_1.
|
|
1868
|
+
var itemsArray = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(Array.from(items.values())), false), tslib_1.__read(Array.from(itemsChanged.values())), false);
|
|
1857
1869
|
items.clear();
|
|
1858
1870
|
itemsArray.forEach(function (item) {
|
|
1859
1871
|
var itemModelDefinition = getModelDefinition(model);
|
|
1860
|
-
var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
|
|
1872
|
+
var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
|
|
1861
1873
|
items.set(idOrPk, item);
|
|
1862
1874
|
});
|
|
1863
1875
|
// remove deleted items from the final result set
|
|
@@ -1900,7 +1912,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1900
1912
|
var pagination = _this.processPagination(modelDefinition, options);
|
|
1901
1913
|
var sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
1902
1914
|
if (sortPredicates.length) {
|
|
1903
|
-
var compareFn = util_1.sortCompareFunction(sortPredicates);
|
|
1915
|
+
var compareFn = (0, util_1.sortCompareFunction)(sortPredicates);
|
|
1904
1916
|
itemsToSort.sort(compareFn);
|
|
1905
1917
|
}
|
|
1906
1918
|
};
|
|
@@ -1913,8 +1925,8 @@ var DataStore = /** @class */ (function () {
|
|
|
1913
1925
|
* @param payload The payload from the Hub event.
|
|
1914
1926
|
*/
|
|
1915
1927
|
var hubCallback = function (_a) {
|
|
1916
|
-
var payload = _a.payload;
|
|
1917
1928
|
var _b;
|
|
1929
|
+
var payload = _a.payload;
|
|
1918
1930
|
var event = payload.event, data = payload.data;
|
|
1919
1931
|
if (event === sync_1.ControlMessage.SYNC_ENGINE_MODEL_SYNCED &&
|
|
1920
1932
|
((_b = data === null || data === void 0 ? void 0 : data.model) === null || _b === void 0 ? void 0 : _b.name) === model.name) {
|
|
@@ -1947,7 +1959,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1947
1959
|
types_1.AuthModeStrategyType.DEFAULT;
|
|
1948
1960
|
switch (authModeStrategyType) {
|
|
1949
1961
|
case types_1.AuthModeStrategyType.MULTI_AUTH:
|
|
1950
|
-
_this.authModeStrategy = authModeStrategies_1.multiAuthStrategy(_this.amplifyContext);
|
|
1962
|
+
_this.authModeStrategy = (0, authModeStrategies_1.multiAuthStrategy)(_this.amplifyContext);
|
|
1951
1963
|
break;
|
|
1952
1964
|
case types_1.AuthModeStrategyType.DEFAULT:
|
|
1953
1965
|
_this.authModeStrategy = authModeStrategies_1.defaultAuthStrategy;
|
|
@@ -2011,7 +2023,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2011
2023
|
var handler = function (err) {
|
|
2012
2024
|
if (err.message.startsWith('BackgroundManagerNotOpenError')) {
|
|
2013
2025
|
throw new Error([
|
|
2014
|
-
"DataStoreStateError: Tried to execute `"
|
|
2026
|
+
"DataStoreStateError: Tried to execute `".concat(operation, "` while DataStore was \"").concat(_this.state, "\"."),
|
|
2015
2027
|
"This can only be done while DataStore is \"Started\" or \"Stopped\". To remedy:",
|
|
2016
2028
|
'Ensure all calls to `stop()` and `clear()` have completed first.',
|
|
2017
2029
|
'If this is not possible, retry the operation until it succeeds.',
|
|
@@ -2174,13 +2186,13 @@ var DataStore = /** @class */ (function () {
|
|
|
2174
2186
|
return [4 /*yield*/, this.unwrapPromise(conditionProducer)];
|
|
2175
2187
|
case 2:
|
|
2176
2188
|
condition = _b.sent();
|
|
2177
|
-
if (predicates_1.isPredicatesAll(condition)) {
|
|
2189
|
+
if ((0, predicates_1.isPredicatesAll)(condition)) {
|
|
2178
2190
|
return [2 /*return*/, [modelDefinition, null]];
|
|
2179
2191
|
}
|
|
2180
|
-
predicate = next_1.internals(condition(next_1.predicateFor({
|
|
2192
|
+
predicate = (0, next_1.internals)(condition((0, next_1.predicateFor)({
|
|
2181
2193
|
builder: modelConstructor,
|
|
2182
2194
|
schema: modelDefinition,
|
|
2183
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
2195
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
2184
2196
|
}))).toStoragePredicate();
|
|
2185
2197
|
return [2 /*return*/, [modelDefinition, predicate]];
|
|
2186
2198
|
}
|
|
@@ -2220,7 +2232,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2220
2232
|
var _b = tslib_1.__read(_a, 2), modelDefinition = _b[0], predicate = _b[1];
|
|
2221
2233
|
if (map.has(modelDefinition)) {
|
|
2222
2234
|
var name_2 = modelDefinition.name;
|
|
2223
|
-
logger.warn("You can only utilize one Sync Expression per model.\n Subsequent sync expressions for the "
|
|
2235
|
+
logger.warn("You can only utilize one Sync Expression per model.\n Subsequent sync expressions for the ".concat(name_2, " model will be ignored."));
|
|
2224
2236
|
return map;
|
|
2225
2237
|
}
|
|
2226
2238
|
if (predicate) {
|
|
@@ -2240,7 +2252,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2240
2252
|
var aws_appsync_graphqlEndpoint = this.amplifyConfig.aws_appsync_graphqlEndpoint;
|
|
2241
2253
|
var appSyncUrl = aws_appsync_graphqlEndpoint.split('/')[2];
|
|
2242
2254
|
var _a = tslib_1.__read(appSyncUrl.split('.'), 1), appSyncId = _a[0];
|
|
2243
|
-
return sessionId
|
|
2255
|
+
return "".concat(sessionId, "-").concat(appSyncId);
|
|
2244
2256
|
}
|
|
2245
2257
|
}
|
|
2246
2258
|
catch (_b) { }
|