@aws-amplify/datastore 4.7.24 → 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 +139 -132
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/datastore/loadGetRandomValues.js +3 -1
- package/lib/datastore/loadGetRandomValues.js.map +1 -1
- package/lib/datastore/loadGetRandomValues.native.js +3 -1
- package/lib/datastore/loadGetRandomValues.native.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +10 -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 +62 -57
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/datastore/loadGetRandomValues.native.js.map +1 -1
- package/lib-esm/index.d.ts +3 -3
- 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 +31 -28
- 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
|
|
@@ -23,12 +25,12 @@ var loadGetRandomValues_1 = require("./loadGetRandomValues");
|
|
|
23
25
|
// `uuid` v4 (used below to mint model ids) requires `crypto.getRandomValues`,
|
|
24
26
|
// which is not available in React Native. On RN this loads the
|
|
25
27
|
// `react-native-get-random-values` polyfill; on web/Node it is a no-op.
|
|
26
|
-
loadGetRandomValues_1.loadGetRandomValues();
|
|
27
|
-
immer_1.setAutoFreeze(true);
|
|
28
|
-
immer_1.enablePatches();
|
|
28
|
+
(0, loadGetRandomValues_1.loadGetRandomValues)();
|
|
29
|
+
(0, immer_1.setAutoFreeze)(true);
|
|
30
|
+
(0, immer_1.enablePatches)();
|
|
29
31
|
var logger = new core_1.ConsoleLogger('DataStore');
|
|
30
|
-
var ulid = util_1.monotonicUlidFactory(Date.now());
|
|
31
|
-
var isNode = core_1.browserOrNode().isNode;
|
|
32
|
+
var ulid = (0, util_1.monotonicUlidFactory)(Date.now());
|
|
33
|
+
var isNode = (0, core_1.browserOrNode)().isNode;
|
|
32
34
|
var SETTING_SCHEMA_VERSION = 'schemaVersion';
|
|
33
35
|
var schema;
|
|
34
36
|
var modelNamespaceMap = new WeakMap();
|
|
@@ -53,12 +55,12 @@ var getModelDefinition = function (modelConstructor) {
|
|
|
53
55
|
* @param obj The object to test.
|
|
54
56
|
*/
|
|
55
57
|
var isValidModelConstructor = function (obj) {
|
|
56
|
-
return util_1.isModelConstructor(obj) && modelNamespaceMap.has(obj);
|
|
58
|
+
return (0, util_1.isModelConstructor)(obj) && modelNamespaceMap.has(obj);
|
|
57
59
|
};
|
|
58
60
|
var namespaceResolver = function (modelConstructor) {
|
|
59
61
|
var resolver = modelNamespaceMap.get(modelConstructor);
|
|
60
62
|
if (!resolver) {
|
|
61
|
-
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'."));
|
|
62
64
|
}
|
|
63
65
|
return resolver;
|
|
64
66
|
};
|
|
@@ -87,10 +89,10 @@ var buildSeedPredicate = function (modelConstructor) {
|
|
|
87
89
|
var modelSchema = getModelDefinition(modelConstructor);
|
|
88
90
|
if (!modelSchema)
|
|
89
91
|
throw new Error('Missing modelSchema');
|
|
90
|
-
var pks = util_1.extractPrimaryKeyFieldNames(modelSchema);
|
|
92
|
+
var pks = (0, util_1.extractPrimaryKeyFieldNames)(modelSchema);
|
|
91
93
|
if (!pks)
|
|
92
94
|
throw new Error('Could not determine PK');
|
|
93
|
-
return next_1.recursivePredicateFor({
|
|
95
|
+
return (0, next_1.recursivePredicateFor)({
|
|
94
96
|
builder: modelConstructor,
|
|
95
97
|
schema: modelSchema,
|
|
96
98
|
pkField: pks,
|
|
@@ -151,7 +153,6 @@ function attached(result, attachment) {
|
|
|
151
153
|
}
|
|
152
154
|
return result;
|
|
153
155
|
}
|
|
154
|
-
exports.attached = attached;
|
|
155
156
|
/**
|
|
156
157
|
* Determines what source a model instance should lazy load from.
|
|
157
158
|
*
|
|
@@ -159,11 +160,12 @@ exports.attached = attached;
|
|
|
159
160
|
*
|
|
160
161
|
* @param instance A model instance
|
|
161
162
|
*/
|
|
162
|
-
|
|
163
|
+
var getAttachment = function (instance) {
|
|
163
164
|
return attachedModelInstances.has(instance)
|
|
164
165
|
? attachedModelInstances.get(instance)
|
|
165
166
|
: ModelAttachment.Detached;
|
|
166
167
|
};
|
|
168
|
+
exports.getAttachment = getAttachment;
|
|
167
169
|
var initSchema = function (userSchema) {
|
|
168
170
|
var _a;
|
|
169
171
|
if (schema !== undefined) {
|
|
@@ -194,7 +196,7 @@ var initSchema = function (userSchema) {
|
|
|
194
196
|
};
|
|
195
197
|
Object.keys(schema.namespaces).forEach(function (namespace) {
|
|
196
198
|
var e_1, _a;
|
|
197
|
-
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];
|
|
198
200
|
schema.namespaces[namespace].relationships = relations;
|
|
199
201
|
schema.namespaces[namespace].keys = keys;
|
|
200
202
|
var modelAssociations = new Map();
|
|
@@ -216,16 +218,16 @@ var initSchema = function (userSchema) {
|
|
|
216
218
|
// to go looking for it.
|
|
217
219
|
Object.values(model.fields).forEach(function (field) {
|
|
218
220
|
var relatedModel = userClasses[field.type.model];
|
|
219
|
-
if (util_1.isModelConstructor(relatedModel)) {
|
|
221
|
+
if ((0, util_1.isModelConstructor)(relatedModel)) {
|
|
220
222
|
Object.defineProperty(field.type, 'modelConstructor', {
|
|
221
223
|
get: function () {
|
|
222
224
|
var relatedModelDefinition = getModelDefinition(relatedModel);
|
|
223
225
|
if (!relatedModelDefinition)
|
|
224
|
-
throw new Error("Could not find model definition for "
|
|
226
|
+
throw new Error("Could not find model definition for ".concat(relatedModel.name));
|
|
225
227
|
return {
|
|
226
228
|
builder: relatedModel,
|
|
227
229
|
schema: relatedModelDefinition,
|
|
228
|
-
pkField: util_1.extractPrimaryKeyFieldNames(relatedModelDefinition),
|
|
230
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(relatedModelDefinition),
|
|
229
231
|
};
|
|
230
232
|
},
|
|
231
233
|
});
|
|
@@ -261,7 +263,7 @@ var initSchema = function (userSchema) {
|
|
|
261
263
|
}
|
|
262
264
|
finally { if (e_2) throw e_2.error; }
|
|
263
265
|
}
|
|
264
|
-
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 [
|
|
265
267
|
name,
|
|
266
268
|
{
|
|
267
269
|
name: name,
|
|
@@ -347,10 +349,10 @@ var checkSchemaCodegenVersion = function (codegenVersion) {
|
|
|
347
349
|
isValid = Number(major) === majorVersion && Number(minor) >= minorVersion;
|
|
348
350
|
}
|
|
349
351
|
catch (err) {
|
|
350
|
-
console.log("Error parsing codegen version: "
|
|
352
|
+
console.log("Error parsing codegen version: ".concat(codegenVersion, "\n").concat(err));
|
|
351
353
|
}
|
|
352
354
|
if (!isValid) {
|
|
353
|
-
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. ") +
|
|
354
356
|
"Update to the latest CLI and run 'amplify codegen models'.";
|
|
355
357
|
logger.error(message);
|
|
356
358
|
throw new Error(message);
|
|
@@ -385,24 +387,24 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
385
387
|
var fieldDefinition = modelDefinition.fields[k];
|
|
386
388
|
if (fieldDefinition !== undefined) {
|
|
387
389
|
var type_1 = fieldDefinition.type, isRequired_1 = fieldDefinition.isRequired, isArrayNullable = fieldDefinition.isArrayNullable, name_1 = fieldDefinition.name, isArray = fieldDefinition.isArray;
|
|
388
|
-
var timestamps = types_1.isSchemaModelWithAttributes(modelDefinition)
|
|
389
|
-
? util_1.getTimestampFields(modelDefinition)
|
|
390
|
+
var timestamps = (0, types_1.isSchemaModelWithAttributes)(modelDefinition)
|
|
391
|
+
? (0, util_1.getTimestampFields)(modelDefinition)
|
|
390
392
|
: {};
|
|
391
393
|
var isTimestampField = !!timestamps[name_1];
|
|
392
394
|
if (((!isArray && isRequired_1) || (isArray && !isArrayNullable)) &&
|
|
393
395
|
!isTimestampField &&
|
|
394
396
|
(v === null || v === undefined)) {
|
|
395
|
-
throw new Error("Field "
|
|
397
|
+
throw new Error("Field ".concat(name_1, " is required"));
|
|
396
398
|
}
|
|
397
|
-
if (types_1.isSchemaModelWithAttributes(modelDefinition) &&
|
|
398
|
-
!util_1.isIdManaged(modelDefinition)) {
|
|
399
|
-
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);
|
|
400
402
|
if (keys.includes(k) && v === '') {
|
|
401
403
|
logger.error(util_1.errorMessages.idEmptyString, { k: k, value: v });
|
|
402
404
|
throw new Error(util_1.errorMessages.idEmptyString);
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
|
-
if (types_1.isGraphQLScalarType(type_1)) {
|
|
407
|
+
if ((0, types_1.isGraphQLScalarType)(type_1)) {
|
|
406
408
|
var jsType_1 = types_1.GraphQLScalarType.getJSType(type_1);
|
|
407
409
|
var validateScalar_1 = types_1.GraphQLScalarType.getValidationFunction(type_1);
|
|
408
410
|
if (type_1 === 'AWSJSON') {
|
|
@@ -415,33 +417,33 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
415
417
|
return;
|
|
416
418
|
}
|
|
417
419
|
catch (error) {
|
|
418
|
-
throw new Error("Field "
|
|
420
|
+
throw new Error("Field ".concat(name_1, " is an invalid JSON object. ").concat(v));
|
|
419
421
|
}
|
|
420
422
|
}
|
|
421
423
|
}
|
|
422
424
|
if (isArray) {
|
|
423
425
|
var errorTypeText = jsType_1;
|
|
424
426
|
if (!isRequired_1) {
|
|
425
|
-
errorTypeText = jsType_1
|
|
427
|
+
errorTypeText = "".concat(jsType_1, " | null | undefined");
|
|
426
428
|
}
|
|
427
429
|
if (!Array.isArray(v) && !isArrayNullable) {
|
|
428
|
-
throw new Error("Field "
|
|
430
|
+
throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
|
|
429
431
|
}
|
|
430
|
-
if (!util_1.isNullOrUndefined(v) &&
|
|
432
|
+
if (!(0, util_1.isNullOrUndefined)(v) &&
|
|
431
433
|
v.some(function (e) {
|
|
432
|
-
return util_1.isNullOrUndefined(e) ? isRequired_1 : typeof e !== jsType_1;
|
|
434
|
+
return (0, util_1.isNullOrUndefined)(e) ? isRequired_1 : typeof e !== jsType_1;
|
|
433
435
|
})) {
|
|
434
436
|
var elemTypes = v
|
|
435
437
|
.map(function (e) { return (e === null ? 'null' : typeof e); })
|
|
436
438
|
.join(',');
|
|
437
|
-
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));
|
|
438
440
|
}
|
|
439
|
-
if (validateScalar_1 && !util_1.isNullOrUndefined(v)) {
|
|
441
|
+
if (validateScalar_1 && !(0, util_1.isNullOrUndefined)(v)) {
|
|
440
442
|
var validationStatus = v.map(function (e) {
|
|
441
|
-
if (!util_1.isNullOrUndefined(e)) {
|
|
443
|
+
if (!(0, util_1.isNullOrUndefined)(e)) {
|
|
442
444
|
return validateScalar_1(e);
|
|
443
445
|
}
|
|
444
|
-
else if (util_1.isNullOrUndefined(e) && !isRequired_1) {
|
|
446
|
+
else if ((0, util_1.isNullOrUndefined)(e) && !isRequired_1) {
|
|
445
447
|
return true;
|
|
446
448
|
}
|
|
447
449
|
else {
|
|
@@ -449,7 +451,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
449
451
|
}
|
|
450
452
|
});
|
|
451
453
|
if (!validationStatus.every(function (s) { return s; })) {
|
|
452
|
-
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));
|
|
453
455
|
}
|
|
454
456
|
}
|
|
455
457
|
}
|
|
@@ -457,34 +459,34 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
457
459
|
return;
|
|
458
460
|
}
|
|
459
461
|
else if (typeof v !== jsType_1 && v !== null) {
|
|
460
|
-
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));
|
|
461
463
|
}
|
|
462
|
-
else if (!util_1.isNullOrUndefined(v) &&
|
|
464
|
+
else if (!(0, util_1.isNullOrUndefined)(v) &&
|
|
463
465
|
validateScalar_1 &&
|
|
464
466
|
!validateScalar_1(v) // TODO: why never, TS ... why ...
|
|
465
467
|
) {
|
|
466
|
-
throw new Error("Field "
|
|
468
|
+
throw new Error("Field ".concat(name_1, " should be of type ").concat(type_1, ", validation failed. ").concat(v));
|
|
467
469
|
}
|
|
468
470
|
}
|
|
469
|
-
else if (types_1.isNonModelFieldType(type_1)) {
|
|
471
|
+
else if ((0, types_1.isNonModelFieldType)(type_1)) {
|
|
470
472
|
// do not check non model fields if undefined or null
|
|
471
|
-
if (!util_1.isNullOrUndefined(v)) {
|
|
473
|
+
if (!(0, util_1.isNullOrUndefined)(v)) {
|
|
472
474
|
var subNonModelDefinition_1 = schema.namespaces.user.nonModels[type_1.nonModel];
|
|
473
475
|
var modelValidator_1 = validateModelFields(subNonModelDefinition_1);
|
|
474
476
|
if (isArray) {
|
|
475
477
|
var errorTypeText = type_1.nonModel;
|
|
476
478
|
if (!isRequired_1) {
|
|
477
|
-
errorTypeText = type_1.nonModel
|
|
479
|
+
errorTypeText = "".concat(type_1.nonModel, " | null | undefined");
|
|
478
480
|
}
|
|
479
481
|
if (!Array.isArray(v)) {
|
|
480
|
-
throw new Error("Field "
|
|
482
|
+
throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
|
|
481
483
|
}
|
|
482
484
|
v.forEach(function (item) {
|
|
483
|
-
if ((util_1.isNullOrUndefined(item) && isRequired_1) ||
|
|
485
|
+
if (((0, util_1.isNullOrUndefined)(item) && isRequired_1) ||
|
|
484
486
|
(typeof item !== 'object' && typeof item !== 'undefined')) {
|
|
485
|
-
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));
|
|
486
488
|
}
|
|
487
|
-
if (!util_1.isNullOrUndefined(item)) {
|
|
489
|
+
if (!(0, util_1.isNullOrUndefined)(item)) {
|
|
488
490
|
Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
|
|
489
491
|
modelValidator_1(subKey, item[subKey]);
|
|
490
492
|
});
|
|
@@ -493,7 +495,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
|
|
|
493
495
|
}
|
|
494
496
|
else {
|
|
495
497
|
if (typeof v !== 'object') {
|
|
496
|
-
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));
|
|
497
499
|
}
|
|
498
500
|
Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
|
|
499
501
|
modelValidator_1(subKey, v[subKey]);
|
|
@@ -509,8 +511,8 @@ var castInstanceType = function (modelDefinition, k, v) {
|
|
|
509
511
|
if (typeof v === 'string' &&
|
|
510
512
|
(isArray ||
|
|
511
513
|
type === 'AWSJSON' ||
|
|
512
|
-
types_1.isNonModelFieldType(type) ||
|
|
513
|
-
types_1.isModelFieldType(type))) {
|
|
514
|
+
(0, types_1.isNonModelFieldType)(type) ||
|
|
515
|
+
(0, types_1.isModelFieldType)(type))) {
|
|
514
516
|
try {
|
|
515
517
|
return JSON.parse(v);
|
|
516
518
|
}
|
|
@@ -591,7 +593,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
591
593
|
// set by customer code versus those set by normalization. only those fields
|
|
592
594
|
// which are explicitly set by customers should be part of create mutations.
|
|
593
595
|
var patches = [];
|
|
594
|
-
var baseInstance = immer_1.produce(this, function (draft) {
|
|
596
|
+
var baseInstance = (0, immer_1.produce)(this, function (draft) {
|
|
595
597
|
initializeInstance(init, modelDefinition, draft);
|
|
596
598
|
// model is initialized inside a DataStore component (e.g. by Sync Engine, Storage Engine, etc.)
|
|
597
599
|
var isInternallyInitialized = instancesMetadata.has(init);
|
|
@@ -599,18 +601,18 @@ var createModelClass = function (modelDefinition) {
|
|
|
599
601
|
? init
|
|
600
602
|
: {};
|
|
601
603
|
var _id = modelInstanceMetadata.id;
|
|
602
|
-
if (util_1.isIdManaged(modelDefinition)) {
|
|
604
|
+
if ((0, util_1.isIdManaged)(modelDefinition)) {
|
|
603
605
|
var isInternalModel = _id !== null && _id !== undefined;
|
|
604
606
|
var id = isInternalModel
|
|
605
607
|
? _id
|
|
606
608
|
: modelDefinition.syncable
|
|
607
|
-
? uuid_1.v4()
|
|
609
|
+
? (0, uuid_1.v4)()
|
|
608
610
|
: ulid();
|
|
609
611
|
draft.id = id;
|
|
610
612
|
}
|
|
611
|
-
else if (util_1.isIdOptionallyManaged(modelDefinition)) {
|
|
613
|
+
else if ((0, util_1.isIdOptionallyManaged)(modelDefinition)) {
|
|
612
614
|
// only auto-populate if the id was not provided
|
|
613
|
-
draft.id = draft.id || uuid_1.v4();
|
|
615
|
+
draft.id = draft.id || (0, uuid_1.v4)();
|
|
614
616
|
}
|
|
615
617
|
if (!isInternallyInitialized) {
|
|
616
618
|
checkReadOnlyPropertyOnCreate(draft, modelDefinition);
|
|
@@ -627,7 +629,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
627
629
|
// are only create to provide a consistent view of the data for fields pre/post sync
|
|
628
630
|
// where possible. (not all fields can be normalized pre-sync, because they're generally
|
|
629
631
|
// "cloud managed" fields, like createdAt and updatedAt.)
|
|
630
|
-
var normalized = immer_1.produce(baseInstance, function (draft) {
|
|
632
|
+
var normalized = (0, immer_1.produce)(baseInstance, function (draft) {
|
|
631
633
|
return normalize(modelDefinition, draft);
|
|
632
634
|
});
|
|
633
635
|
initPatches.set(normalized, patches);
|
|
@@ -641,13 +643,13 @@ var createModelClass = function (modelDefinition) {
|
|
|
641
643
|
throw new Error(msg);
|
|
642
644
|
}
|
|
643
645
|
var patches = [];
|
|
644
|
-
var model = immer_1.produce(source, function (draft) {
|
|
646
|
+
var model = (0, immer_1.produce)(source, function (draft) {
|
|
645
647
|
fn(draft);
|
|
646
|
-
var keyNames = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
648
|
+
var keyNames = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
647
649
|
// Keys are immutable
|
|
648
650
|
keyNames.forEach(function (key) {
|
|
649
651
|
if (draft[key] !== source[key]) {
|
|
650
|
-
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 });
|
|
651
653
|
}
|
|
652
654
|
draft[key] = source[key];
|
|
653
655
|
});
|
|
@@ -663,7 +665,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
663
665
|
if (patches.length || hasExistingPatches) {
|
|
664
666
|
if (hasExistingPatches) {
|
|
665
667
|
var _a = tslib_1.__read(modelPatchesMap.get(source), 2), existingPatches = _a[0], existingSource = _a[1];
|
|
666
|
-
var mergedPatches = util_1.mergePatches(existingSource, existingPatches, patches);
|
|
668
|
+
var mergedPatches = (0, util_1.mergePatches)(existingSource, existingPatches, patches);
|
|
667
669
|
modelPatchesMap.set(model, [mergedPatches, existingSource]);
|
|
668
670
|
checkReadOnlyPropertyOnUpdate(mergedPatches, modelDefinition);
|
|
669
671
|
}
|
|
@@ -708,7 +710,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
708
710
|
var allModelRelationships = relationship_1.ModelRelationship.allFrom({
|
|
709
711
|
builder: clazz,
|
|
710
712
|
schema: modelDefinition,
|
|
711
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
713
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
712
714
|
});
|
|
713
715
|
var _loop_1 = function (relationship) {
|
|
714
716
|
var field = relationship.field;
|
|
@@ -725,13 +727,13 @@ var createModelClass = function (modelDefinition) {
|
|
|
725
727
|
var modelConstructor = Object.getPrototypeOf(model || {})
|
|
726
728
|
.constructor;
|
|
727
729
|
if (!isValidModelConstructor(modelConstructor)) {
|
|
728
|
-
var msg = "Value passed to "
|
|
730
|
+
var msg = "Value passed to ".concat(modelDefinition.name, ".").concat(field, " is not a valid instance of a model");
|
|
729
731
|
logger.error(msg, { model: model });
|
|
730
732
|
throw new Error(msg);
|
|
731
733
|
}
|
|
732
734
|
if (modelConstructor.name.toLowerCase() !==
|
|
733
735
|
relationship.remoteModelConstructor.name.toLowerCase()) {
|
|
734
|
-
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);
|
|
735
737
|
logger.error(msg, { model: model });
|
|
736
738
|
throw new Error(msg);
|
|
737
739
|
}
|
|
@@ -740,7 +742,8 @@ var createModelClass = function (modelDefinition) {
|
|
|
740
742
|
// if the relationship can be managed automagically, set the FK's
|
|
741
743
|
if (relationship.isComplete) {
|
|
742
744
|
for (var i = 0; i < relationship.localJoinFields.length; i++) {
|
|
743
|
-
this[relationship.localJoinFields[i]] =
|
|
745
|
+
this[relationship.localJoinFields[i]] =
|
|
746
|
+
model === null || model === void 0 ? void 0 : model[relationship.remoteJoinFields[i]];
|
|
744
747
|
}
|
|
745
748
|
var instanceMemos = modelInstanceAssociationsMap.has(this)
|
|
746
749
|
? modelInstanceAssociationsMap.get(this)
|
|
@@ -762,7 +765,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
762
765
|
if (!instanceMemos.hasOwnProperty(field)) {
|
|
763
766
|
// before we populate the memo, we need to know where to look for relatives.
|
|
764
767
|
// today, this only supports DataStore. Models aren't managed elsewhere in Amplify.
|
|
765
|
-
if (exports.getAttachment(this) === ModelAttachment.DataStore) {
|
|
768
|
+
if ((0, exports.getAttachment)(this) === ModelAttachment.DataStore) {
|
|
766
769
|
// when we fetch the results using a query constructed under the guidance
|
|
767
770
|
// of the relationship metadata, we DO NOT AWAIT resolution. we want to
|
|
768
771
|
// drop the promise into the memo's synchronously, eliminating the chance
|
|
@@ -788,7 +791,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
788
791
|
instanceMemos[field] = resultPromise.then(function (rows) {
|
|
789
792
|
if (rows.length > 1) {
|
|
790
793
|
// should never happen for a HAS_ONE or BELONGS_TO.
|
|
791
|
-
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"));
|
|
792
795
|
console.error(err);
|
|
793
796
|
throw err;
|
|
794
797
|
}
|
|
@@ -798,7 +801,7 @@ var createModelClass = function (modelDefinition) {
|
|
|
798
801
|
});
|
|
799
802
|
}
|
|
800
803
|
}
|
|
801
|
-
else if (exports.getAttachment(this) === ModelAttachment.API) {
|
|
804
|
+
else if ((0, exports.getAttachment)(this) === ModelAttachment.API) {
|
|
802
805
|
throw new Error('Lazy loading from API is not yet supported!');
|
|
803
806
|
}
|
|
804
807
|
else {
|
|
@@ -901,25 +904,27 @@ var AsyncCollection = /** @class */ (function () {
|
|
|
901
904
|
* const first100 = await collection.toArray({max: 100});
|
|
902
905
|
* ```
|
|
903
906
|
*/
|
|
904
|
-
AsyncCollection.prototype.toArray = function (
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
var
|
|
909
|
-
return tslib_1.__generator(this, function (
|
|
910
|
-
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) {
|
|
911
914
|
case 0:
|
|
912
915
|
output = [];
|
|
913
916
|
i = 0;
|
|
914
|
-
|
|
917
|
+
_k.label = 1;
|
|
915
918
|
case 1:
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
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()];
|
|
920
923
|
case 3:
|
|
921
|
-
if (!(
|
|
922
|
-
|
|
924
|
+
if (!(_d = _k.sent(), _e = _d.done, !_e)) return [3 /*break*/, 5];
|
|
925
|
+
_g = _d.value;
|
|
926
|
+
_b = false;
|
|
927
|
+
element = _g;
|
|
923
928
|
if (i < max) {
|
|
924
929
|
output.push(element);
|
|
925
930
|
i++;
|
|
@@ -927,20 +932,22 @@ var AsyncCollection = /** @class */ (function () {
|
|
|
927
932
|
else {
|
|
928
933
|
return [3 /*break*/, 5];
|
|
929
934
|
}
|
|
930
|
-
|
|
931
|
-
case 4:
|
|
935
|
+
_k.label = 4;
|
|
936
|
+
case 4:
|
|
937
|
+
_b = true;
|
|
938
|
+
return [3 /*break*/, 2];
|
|
932
939
|
case 5: return [3 /*break*/, 12];
|
|
933
940
|
case 6:
|
|
934
|
-
e_6_1 =
|
|
941
|
+
e_6_1 = _k.sent();
|
|
935
942
|
e_6 = { error: e_6_1 };
|
|
936
943
|
return [3 /*break*/, 12];
|
|
937
944
|
case 7:
|
|
938
|
-
|
|
939
|
-
if (!(
|
|
940
|
-
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)];
|
|
941
948
|
case 8:
|
|
942
|
-
|
|
943
|
-
|
|
949
|
+
_k.sent();
|
|
950
|
+
_k.label = 9;
|
|
944
951
|
case 9: return [3 /*break*/, 11];
|
|
945
952
|
case 10:
|
|
946
953
|
if (e_6) throw e_6.error;
|
|
@@ -959,7 +966,7 @@ var checkReadOnlyPropertyOnCreate = function (draft, modelDefinition) {
|
|
|
959
966
|
var fields = modelDefinition.fields;
|
|
960
967
|
modelKeys.forEach(function (key) {
|
|
961
968
|
if (fields[key] && fields[key].isReadOnly) {
|
|
962
|
-
throw new Error(key
|
|
969
|
+
throw new Error("".concat(key, " is read-only."));
|
|
963
970
|
}
|
|
964
971
|
});
|
|
965
972
|
};
|
|
@@ -971,14 +978,14 @@ var checkReadOnlyPropertyOnUpdate = function (patches, modelDefinition) {
|
|
|
971
978
|
if (!val || !fields[key])
|
|
972
979
|
return;
|
|
973
980
|
if (fields[key].isReadOnly) {
|
|
974
|
-
throw new Error(key
|
|
981
|
+
throw new Error("".concat(key, " is read-only."));
|
|
975
982
|
}
|
|
976
983
|
});
|
|
977
984
|
};
|
|
978
985
|
var createNonModelClass = function (typeDefinition) {
|
|
979
986
|
var clazz = /** @class */ (function () {
|
|
980
987
|
function Model(init) {
|
|
981
|
-
var instance = immer_1.produce(this, function (draft) {
|
|
988
|
+
var instance = (0, immer_1.produce)(this, function (draft) {
|
|
982
989
|
initializeInstance(init, typeDefinition, draft);
|
|
983
990
|
});
|
|
984
991
|
return instance;
|
|
@@ -987,7 +994,7 @@ var createNonModelClass = function (typeDefinition) {
|
|
|
987
994
|
}());
|
|
988
995
|
clazz[immer_1.immerable] = true;
|
|
989
996
|
Object.defineProperty(clazz, 'name', { value: typeDefinition.name });
|
|
990
|
-
util_1.registerNonModelClass(clazz);
|
|
997
|
+
(0, util_1.registerNonModelClass)(clazz);
|
|
991
998
|
return clazz;
|
|
992
999
|
};
|
|
993
1000
|
function isQueryOne(obj) {
|
|
@@ -1017,13 +1024,13 @@ function getModelConstructorByModelName(namespaceName, modelName) {
|
|
|
1017
1024
|
result = storageClasses[modelName];
|
|
1018
1025
|
break;
|
|
1019
1026
|
default:
|
|
1020
|
-
throw new Error("Invalid namespace: "
|
|
1027
|
+
throw new Error("Invalid namespace: ".concat(namespaceName));
|
|
1021
1028
|
}
|
|
1022
1029
|
if (isValidModelConstructor(result)) {
|
|
1023
1030
|
return result;
|
|
1024
1031
|
}
|
|
1025
1032
|
else {
|
|
1026
|
-
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);
|
|
1027
1034
|
logger.error(msg);
|
|
1028
1035
|
throw new Error(msg);
|
|
1029
1036
|
}
|
|
@@ -1312,7 +1319,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1312
1319
|
throw new Error('Invalid model definition provided!');
|
|
1313
1320
|
}
|
|
1314
1321
|
pagination = this.processPagination(modelDefinition, paginationProducer);
|
|
1315
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1322
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1316
1323
|
if (!isQueryOne(identifierOrCriteria)) return [3 /*break*/, 3];
|
|
1317
1324
|
if (keyFields.length > 1) {
|
|
1318
1325
|
msg = util_1.errorMessages.queryByPkWithCompositeKeyPresent;
|
|
@@ -1325,7 +1332,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1325
1332
|
result = _c.sent();
|
|
1326
1333
|
return [3 /*break*/, 9];
|
|
1327
1334
|
case 3:
|
|
1328
|
-
if (!types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
|
|
1335
|
+
if (!(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
|
|
1329
1336
|
predicate = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
|
|
1330
1337
|
return [4 /*yield*/, this.storage.query(modelConstructor, predicate, pagination)];
|
|
1331
1338
|
case 4:
|
|
@@ -1333,26 +1340,26 @@ var DataStore = /** @class */ (function () {
|
|
|
1333
1340
|
return [3 /*break*/, 9];
|
|
1334
1341
|
case 5:
|
|
1335
1342
|
if (!(!identifierOrCriteria ||
|
|
1336
|
-
predicates_1.isPredicatesAll(identifierOrCriteria))) return [3 /*break*/, 7];
|
|
1343
|
+
(0, predicates_1.isPredicatesAll)(identifierOrCriteria))) return [3 /*break*/, 7];
|
|
1337
1344
|
return [4 /*yield*/, ((_b = this.storage) === null || _b === void 0 ? void 0 : _b.query(modelConstructor, undefined, pagination))];
|
|
1338
1345
|
case 6:
|
|
1339
1346
|
result = _c.sent();
|
|
1340
1347
|
return [3 /*break*/, 9];
|
|
1341
1348
|
case 7:
|
|
1342
|
-
seedPredicate = next_1.recursivePredicateFor({
|
|
1349
|
+
seedPredicate = (0, next_1.recursivePredicateFor)({
|
|
1343
1350
|
builder: modelConstructor,
|
|
1344
1351
|
schema: modelDefinition,
|
|
1345
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1352
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1346
1353
|
});
|
|
1347
|
-
predicate = next_1.internals(identifierOrCriteria(seedPredicate));
|
|
1354
|
+
predicate = (0, next_1.internals)(identifierOrCriteria(seedPredicate));
|
|
1348
1355
|
return [4 /*yield*/, predicate.fetch(this.storage)];
|
|
1349
1356
|
case 8:
|
|
1350
1357
|
result = (_c.sent());
|
|
1351
|
-
result = util_1.inMemoryPagination(result, pagination);
|
|
1358
|
+
result = (0, util_1.inMemoryPagination)(result, pagination);
|
|
1352
1359
|
_c.label = 9;
|
|
1353
1360
|
case 9:
|
|
1354
1361
|
returnOne = isQueryOne(identifierOrCriteria) ||
|
|
1355
|
-
types_1.isIdentifierObject(identifierOrCriteria, modelDefinition);
|
|
1362
|
+
(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition);
|
|
1356
1363
|
return [2 /*return*/, attached(returnOne ? result[0] : result, ModelAttachment.DataStore)];
|
|
1357
1364
|
}
|
|
1358
1365
|
});
|
|
@@ -1393,7 +1400,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1393
1400
|
modelMeta = {
|
|
1394
1401
|
builder: modelConstructor,
|
|
1395
1402
|
schema: modelDefinition,
|
|
1396
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1403
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1397
1404
|
};
|
|
1398
1405
|
return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1399
1406
|
var nonHasManyRelationships, nonHasManyRelationships_1, nonHasManyRelationships_1_1, relationship, queryObject, related, e_7_1;
|
|
@@ -1418,10 +1425,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1418
1425
|
related = _c.sent();
|
|
1419
1426
|
if (related.length === 0) {
|
|
1420
1427
|
throw new Error([
|
|
1421
|
-
"Data integrity error. You tried to save a "
|
|
1422
|
-
"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"),
|
|
1423
1430
|
"does not exist in the local database. If you're trying to create the related",
|
|
1424
|
-
"\""
|
|
1431
|
+
"\"".concat((_b = relationship.remoteDefinition) === null || _b === void 0 ? void 0 : _b.name, "\", you must save it independently first."),
|
|
1425
1432
|
].join(' '));
|
|
1426
1433
|
}
|
|
1427
1434
|
_c.label = 4;
|
|
@@ -1446,7 +1453,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1446
1453
|
case 2:
|
|
1447
1454
|
_b.sent();
|
|
1448
1455
|
producedCondition = condition
|
|
1449
|
-
? next_1.internals(condition(next_1.predicateFor(modelMeta))).toStoragePredicate()
|
|
1456
|
+
? (0, next_1.internals)(condition((0, next_1.predicateFor)(modelMeta))).toStoragePredicate()
|
|
1450
1457
|
: undefined;
|
|
1451
1458
|
return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1452
1459
|
var saved;
|
|
@@ -1526,7 +1533,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1526
1533
|
throw new Error('Could not find model definition for modelConstructor.');
|
|
1527
1534
|
}
|
|
1528
1535
|
if (typeof identifierOrCriteria === 'string') {
|
|
1529
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1536
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1530
1537
|
if (keyFields.length > 1) {
|
|
1531
1538
|
msg = util_1.errorMessages.deleteByPkWithCompositeKeyPresent;
|
|
1532
1539
|
logger.error(msg, { keyFields: keyFields });
|
|
@@ -1535,14 +1542,14 @@ var DataStore = /** @class */ (function () {
|
|
|
1535
1542
|
condition = predicates_1.ModelPredicateCreator.createFromFlatEqualities(modelDefinition, (_d = {}, _d[keyFields[0]] = identifierOrCriteria, _d));
|
|
1536
1543
|
}
|
|
1537
1544
|
else {
|
|
1538
|
-
if (types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) {
|
|
1545
|
+
if ((0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) {
|
|
1539
1546
|
condition = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
|
|
1540
1547
|
}
|
|
1541
1548
|
else {
|
|
1542
|
-
condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
|
|
1549
|
+
condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
|
|
1543
1550
|
builder: modelConstructor,
|
|
1544
1551
|
schema: modelDefinition,
|
|
1545
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1552
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1546
1553
|
}))).toStoragePredicate();
|
|
1547
1554
|
}
|
|
1548
1555
|
if (!condition ||
|
|
@@ -1576,10 +1583,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1576
1583
|
logger.error(msg, { identifierOrCriteria: identifierOrCriteria });
|
|
1577
1584
|
throw new Error(msg);
|
|
1578
1585
|
}
|
|
1579
|
-
condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
|
|
1586
|
+
condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
|
|
1580
1587
|
builder: modelConstructor,
|
|
1581
1588
|
schema: modelDefinition,
|
|
1582
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
1589
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
1583
1590
|
}))).toStoragePredicate();
|
|
1584
1591
|
}
|
|
1585
1592
|
else {
|
|
@@ -1621,7 +1628,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1621
1628
|
// observe should not accept object literal syntax
|
|
1622
1629
|
if (identifierOrCriteria &&
|
|
1623
1630
|
modelConstructor &&
|
|
1624
|
-
types_1.isIdentifierObject(identifierOrCriteria, getModelDefinition(modelConstructor))) {
|
|
1631
|
+
(0, types_1.isIdentifierObject)(identifierOrCriteria, getModelDefinition(modelConstructor))) {
|
|
1625
1632
|
var msg = util_1.errorMessages.observeWithObjectLiteral;
|
|
1626
1633
|
logger.error(msg, { objectLiteral: identifierOrCriteria });
|
|
1627
1634
|
throw new Error(msg);
|
|
@@ -1638,10 +1645,10 @@ var DataStore = /** @class */ (function () {
|
|
|
1638
1645
|
}
|
|
1639
1646
|
if (modelConstructor && typeof identifierOrCriteria === 'string') {
|
|
1640
1647
|
var buildIdPredicate = function (seed) { return seed.id.eq(identifierOrCriteria); };
|
|
1641
|
-
executivePredicate = next_1.internals(buildIdPredicate(buildSeedPredicate(modelConstructor)));
|
|
1648
|
+
executivePredicate = (0, next_1.internals)(buildIdPredicate(buildSeedPredicate(modelConstructor)));
|
|
1642
1649
|
}
|
|
1643
1650
|
else if (modelConstructor && typeof identifierOrCriteria === 'function') {
|
|
1644
|
-
executivePredicate = next_1.internals(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
|
|
1651
|
+
executivePredicate = (0, next_1.internals)(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
|
|
1645
1652
|
}
|
|
1646
1653
|
return new zen_observable_ts_1.default(function (observer) {
|
|
1647
1654
|
var source;
|
|
@@ -1671,8 +1678,8 @@ var DataStore = /** @class */ (function () {
|
|
|
1671
1678
|
message = item;
|
|
1672
1679
|
if (!(item.opType !== 'DELETE')) return [3 /*break*/, 2];
|
|
1673
1680
|
modelDefinition = getModelDefinition(item.model);
|
|
1674
|
-
keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
1675
|
-
primaryKeysAndValues = util_1.extractPrimaryKeysAndValues(item.element, keyFields);
|
|
1681
|
+
keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
1682
|
+
primaryKeysAndValues = (0, util_1.extractPrimaryKeysAndValues)(item.element, keyFields);
|
|
1676
1683
|
return [4 /*yield*/, this.query(item.model, primaryKeysAndValues)];
|
|
1677
1684
|
case 1:
|
|
1678
1685
|
freshElement = _b.sent();
|
|
@@ -1754,9 +1761,9 @@ var DataStore = /** @class */ (function () {
|
|
|
1754
1761
|
throw new Error('Could not find model definition.');
|
|
1755
1762
|
}
|
|
1756
1763
|
if (model && typeof criteria === 'function') {
|
|
1757
|
-
executivePredicate = next_1.internals(criteria(buildSeedPredicate(model)));
|
|
1764
|
+
executivePredicate = (0, next_1.internals)(criteria(buildSeedPredicate(model)));
|
|
1758
1765
|
}
|
|
1759
|
-
else if (predicates_1.isPredicatesAll(criteria)) {
|
|
1766
|
+
else if ((0, predicates_1.isPredicatesAll)(criteria)) {
|
|
1760
1767
|
executivePredicate = undefined;
|
|
1761
1768
|
}
|
|
1762
1769
|
_this.runningProcesses
|
|
@@ -1772,7 +1779,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1772
1779
|
// first, query and return any locally-available records
|
|
1773
1780
|
(_a.sent()).forEach(function (item) {
|
|
1774
1781
|
var itemModelDefinition = getModelDefinition(model);
|
|
1775
|
-
var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
|
|
1782
|
+
var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
|
|
1776
1783
|
items.set(idOrPk, item);
|
|
1777
1784
|
});
|
|
1778
1785
|
// Observe the model and send a stream of updates (debounced).
|
|
@@ -1789,7 +1796,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1789
1796
|
switch (_d.label) {
|
|
1790
1797
|
case 0:
|
|
1791
1798
|
itemModelDefinition = getModelDefinition(model);
|
|
1792
|
-
idOrPk = utils_1.getIdentifierValue(itemModelDefinition, element);
|
|
1799
|
+
idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, element);
|
|
1793
1800
|
_a = executivePredicate;
|
|
1794
1801
|
if (!_a) return [3 /*break*/, 2];
|
|
1795
1802
|
return [4 /*yield*/, executivePredicate.matches(element)];
|
|
@@ -1858,11 +1865,11 @@ var DataStore = /** @class */ (function () {
|
|
|
1858
1865
|
var generateSnapshot = function () {
|
|
1859
1866
|
var _a, _b;
|
|
1860
1867
|
var isSynced = (_b = (_a = _this.sync) === null || _a === void 0 ? void 0 : _a.getModelSyncedStatus(model)) !== null && _b !== void 0 ? _b : false;
|
|
1861
|
-
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);
|
|
1862
1869
|
items.clear();
|
|
1863
1870
|
itemsArray.forEach(function (item) {
|
|
1864
1871
|
var itemModelDefinition = getModelDefinition(model);
|
|
1865
|
-
var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
|
|
1872
|
+
var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
|
|
1866
1873
|
items.set(idOrPk, item);
|
|
1867
1874
|
});
|
|
1868
1875
|
// remove deleted items from the final result set
|
|
@@ -1905,7 +1912,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1905
1912
|
var pagination = _this.processPagination(modelDefinition, options);
|
|
1906
1913
|
var sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
1907
1914
|
if (sortPredicates.length) {
|
|
1908
|
-
var compareFn = util_1.sortCompareFunction(sortPredicates);
|
|
1915
|
+
var compareFn = (0, util_1.sortCompareFunction)(sortPredicates);
|
|
1909
1916
|
itemsToSort.sort(compareFn);
|
|
1910
1917
|
}
|
|
1911
1918
|
};
|
|
@@ -1918,8 +1925,8 @@ var DataStore = /** @class */ (function () {
|
|
|
1918
1925
|
* @param payload The payload from the Hub event.
|
|
1919
1926
|
*/
|
|
1920
1927
|
var hubCallback = function (_a) {
|
|
1921
|
-
var payload = _a.payload;
|
|
1922
1928
|
var _b;
|
|
1929
|
+
var payload = _a.payload;
|
|
1923
1930
|
var event = payload.event, data = payload.data;
|
|
1924
1931
|
if (event === sync_1.ControlMessage.SYNC_ENGINE_MODEL_SYNCED &&
|
|
1925
1932
|
((_b = data === null || data === void 0 ? void 0 : data.model) === null || _b === void 0 ? void 0 : _b.name) === model.name) {
|
|
@@ -1952,7 +1959,7 @@ var DataStore = /** @class */ (function () {
|
|
|
1952
1959
|
types_1.AuthModeStrategyType.DEFAULT;
|
|
1953
1960
|
switch (authModeStrategyType) {
|
|
1954
1961
|
case types_1.AuthModeStrategyType.MULTI_AUTH:
|
|
1955
|
-
_this.authModeStrategy = authModeStrategies_1.multiAuthStrategy(_this.amplifyContext);
|
|
1962
|
+
_this.authModeStrategy = (0, authModeStrategies_1.multiAuthStrategy)(_this.amplifyContext);
|
|
1956
1963
|
break;
|
|
1957
1964
|
case types_1.AuthModeStrategyType.DEFAULT:
|
|
1958
1965
|
_this.authModeStrategy = authModeStrategies_1.defaultAuthStrategy;
|
|
@@ -2016,7 +2023,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2016
2023
|
var handler = function (err) {
|
|
2017
2024
|
if (err.message.startsWith('BackgroundManagerNotOpenError')) {
|
|
2018
2025
|
throw new Error([
|
|
2019
|
-
"DataStoreStateError: Tried to execute `"
|
|
2026
|
+
"DataStoreStateError: Tried to execute `".concat(operation, "` while DataStore was \"").concat(_this.state, "\"."),
|
|
2020
2027
|
"This can only be done while DataStore is \"Started\" or \"Stopped\". To remedy:",
|
|
2021
2028
|
'Ensure all calls to `stop()` and `clear()` have completed first.',
|
|
2022
2029
|
'If this is not possible, retry the operation until it succeeds.',
|
|
@@ -2179,13 +2186,13 @@ var DataStore = /** @class */ (function () {
|
|
|
2179
2186
|
return [4 /*yield*/, this.unwrapPromise(conditionProducer)];
|
|
2180
2187
|
case 2:
|
|
2181
2188
|
condition = _b.sent();
|
|
2182
|
-
if (predicates_1.isPredicatesAll(condition)) {
|
|
2189
|
+
if ((0, predicates_1.isPredicatesAll)(condition)) {
|
|
2183
2190
|
return [2 /*return*/, [modelDefinition, null]];
|
|
2184
2191
|
}
|
|
2185
|
-
predicate = next_1.internals(condition(next_1.predicateFor({
|
|
2192
|
+
predicate = (0, next_1.internals)(condition((0, next_1.predicateFor)({
|
|
2186
2193
|
builder: modelConstructor,
|
|
2187
2194
|
schema: modelDefinition,
|
|
2188
|
-
pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
|
|
2195
|
+
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
2189
2196
|
}))).toStoragePredicate();
|
|
2190
2197
|
return [2 /*return*/, [modelDefinition, predicate]];
|
|
2191
2198
|
}
|
|
@@ -2225,7 +2232,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2225
2232
|
var _b = tslib_1.__read(_a, 2), modelDefinition = _b[0], predicate = _b[1];
|
|
2226
2233
|
if (map.has(modelDefinition)) {
|
|
2227
2234
|
var name_2 = modelDefinition.name;
|
|
2228
|
-
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."));
|
|
2229
2236
|
return map;
|
|
2230
2237
|
}
|
|
2231
2238
|
if (predicate) {
|
|
@@ -2245,7 +2252,7 @@ var DataStore = /** @class */ (function () {
|
|
|
2245
2252
|
var aws_appsync_graphqlEndpoint = this.amplifyConfig.aws_appsync_graphqlEndpoint;
|
|
2246
2253
|
var appSyncUrl = aws_appsync_graphqlEndpoint.split('/')[2];
|
|
2247
2254
|
var _a = tslib_1.__read(appSyncUrl.split('.'), 1), appSyncId = _a[0];
|
|
2248
|
-
return sessionId
|
|
2255
|
+
return "".concat(sessionId, "-").concat(appSyncId);
|
|
2249
2256
|
}
|
|
2250
2257
|
}
|
|
2251
2258
|
catch (_b) { }
|