@aws-amplify/datastore 5.0.32 → 5.0.33-s-auth.30d0cd2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/authModeStrategies/multiAuthStrategy.js +1 -1
- package/dist/cjs/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/dist/cjs/datastore/datastore.js +46 -41
- package/dist/cjs/datastore/datastore.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/predicates/index.js +1 -0
- package/dist/cjs/predicates/index.js.map +1 -1
- package/dist/cjs/predicates/next.js +13 -12
- package/dist/cjs/predicates/next.js.map +1 -1
- package/dist/cjs/predicates/sort.js +2 -2
- package/dist/cjs/predicates/sort.js.map +1 -1
- package/dist/cjs/storage/adapter/AsyncStorageAdapter.js +21 -18
- package/dist/cjs/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/dist/cjs/storage/adapter/AsyncStorageDatabase.js +10 -9
- package/dist/cjs/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/dist/cjs/storage/adapter/InMemoryStore.js +4 -1
- package/dist/cjs/storage/adapter/InMemoryStore.js.map +1 -1
- package/dist/cjs/storage/adapter/IndexedDBAdapter.js +21 -23
- package/dist/cjs/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/dist/cjs/storage/adapter/StorageAdapterBase.js +7 -7
- package/dist/cjs/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.js +4 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js +1 -0
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/dist/cjs/storage/relationship.js +1 -0
- package/dist/cjs/storage/relationship.js.map +1 -1
- package/dist/cjs/storage/storage.js +14 -14
- package/dist/cjs/storage/storage.js.map +1 -1
- package/dist/cjs/sync/datastoreConnectivity.js +0 -3
- package/dist/cjs/sync/datastoreConnectivity.js.map +1 -1
- package/dist/cjs/sync/index.js +47 -43
- package/dist/cjs/sync/index.js.map +1 -1
- package/dist/cjs/sync/merger.js +1 -1
- package/dist/cjs/sync/merger.js.map +1 -1
- package/dist/cjs/sync/outbox.js +19 -17
- package/dist/cjs/sync/outbox.js.map +1 -1
- package/dist/cjs/sync/processors/errorMaps.js.map +1 -1
- package/dist/cjs/sync/processors/mutation.js +31 -28
- package/dist/cjs/sync/processors/mutation.js.map +1 -1
- package/dist/cjs/sync/processors/subscription.js +21 -12
- package/dist/cjs/sync/processors/subscription.js.map +1 -1
- package/dist/cjs/sync/processors/sync.js +25 -21
- package/dist/cjs/sync/processors/sync.js.map +1 -1
- package/dist/cjs/sync/utils.js +20 -21
- package/dist/cjs/sync/utils.js.map +1 -1
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/util.js +46 -25
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.d.ts +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.mjs +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.mjs.map +1 -1
- package/dist/esm/datastore/datastore.d.ts +4 -6
- package/dist/esm/datastore/datastore.mjs +42 -34
- package/dist/esm/datastore/datastore.mjs.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/predicates/index.mjs +1 -0
- package/dist/esm/predicates/index.mjs.map +1 -1
- package/dist/esm/predicates/next.d.ts +7 -7
- package/dist/esm/predicates/next.mjs +13 -12
- package/dist/esm/predicates/next.mjs.map +1 -1
- package/dist/esm/predicates/sort.d.ts +1 -1
- package/dist/esm/predicates/sort.mjs +2 -2
- package/dist/esm/predicates/sort.mjs.map +1 -1
- package/dist/esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -1
- package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs +21 -18
- package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs.map +1 -1
- package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs +10 -9
- package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs.map +1 -1
- package/dist/esm/storage/adapter/InMemoryStore.mjs +4 -1
- package/dist/esm/storage/adapter/InMemoryStore.mjs.map +1 -1
- package/dist/esm/storage/adapter/IndexedDBAdapter.mjs +21 -23
- package/dist/esm/storage/adapter/IndexedDBAdapter.mjs.map +1 -1
- package/dist/esm/storage/adapter/StorageAdapterBase.d.ts +2 -2
- package/dist/esm/storage/adapter/StorageAdapterBase.mjs +7 -7
- package/dist/esm/storage/adapter/StorageAdapterBase.mjs.map +1 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs +3 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs.map +1 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs +1 -0
- package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs.map +1 -1
- package/dist/esm/storage/adapter/index.d.ts +1 -1
- package/dist/esm/storage/relationship.mjs +1 -0
- package/dist/esm/storage/relationship.mjs.map +1 -1
- package/dist/esm/storage/storage.d.ts +11 -11
- package/dist/esm/storage/storage.mjs +10 -10
- package/dist/esm/storage/storage.mjs.map +1 -1
- package/dist/esm/sync/datastoreConnectivity.d.ts +2 -2
- package/dist/esm/sync/datastoreConnectivity.mjs +0 -3
- package/dist/esm/sync/datastoreConnectivity.mjs.map +1 -1
- package/dist/esm/sync/index.d.ts +3 -3
- package/dist/esm/sync/index.mjs +47 -43
- package/dist/esm/sync/index.mjs.map +1 -1
- package/dist/esm/sync/merger.d.ts +1 -1
- package/dist/esm/sync/merger.mjs +1 -1
- package/dist/esm/sync/merger.mjs.map +1 -1
- package/dist/esm/sync/outbox.d.ts +4 -4
- package/dist/esm/sync/outbox.mjs +19 -17
- package/dist/esm/sync/outbox.mjs.map +1 -1
- package/dist/esm/sync/processors/errorMaps.mjs.map +1 -1
- package/dist/esm/sync/processors/mutation.d.ts +5 -5
- package/dist/esm/sync/processors/mutation.mjs +31 -28
- package/dist/esm/sync/processors/mutation.mjs.map +1 -1
- package/dist/esm/sync/processors/subscription.d.ts +1 -1
- package/dist/esm/sync/processors/subscription.mjs +21 -12
- package/dist/esm/sync/processors/subscription.mjs.map +1 -1
- package/dist/esm/sync/processors/sync.d.ts +3 -3
- package/dist/esm/sync/processors/sync.mjs +13 -9
- package/dist/esm/sync/processors/sync.mjs.map +1 -1
- package/dist/esm/sync/utils.d.ts +11 -13
- package/dist/esm/sync/utils.mjs +20 -21
- package/dist/esm/sync/utils.mjs.map +1 -1
- package/dist/esm/types.d.ts +121 -131
- package/dist/esm/types.mjs +3 -2
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/util.d.ts +5 -5
- package/dist/esm/util.mjs +46 -25
- package/dist/esm/util.mjs.map +1 -1
- package/package.json +74 -73
- package/src/authModeStrategies/multiAuthStrategy.ts +8 -4
- package/src/datastore/datastore.ts +145 -123
- package/src/index.ts +10 -8
- package/src/predicates/index.ts +10 -2
- package/src/predicates/next.ts +39 -28
- package/src/predicates/sort.ts +23 -26
- package/src/storage/adapter/AsyncStorageAdapter.ts +43 -25
- package/src/storage/adapter/AsyncStorageDatabase.ts +18 -10
- package/src/storage/adapter/InMemoryStore.ts +5 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +50 -37
- package/src/storage/adapter/StorageAdapterBase.ts +24 -18
- package/src/storage/adapter/getDefaultAdapter/index.native.ts +1 -0
- package/src/storage/adapter/getDefaultAdapter/index.ts +4 -1
- package/src/storage/adapter/index.ts +2 -2
- package/src/storage/relationship.ts +5 -1
- package/src/storage/storage.ts +38 -30
- package/src/sync/datastoreConnectivity.ts +4 -6
- package/src/sync/index.ts +228 -230
- package/src/sync/merger.ts +4 -3
- package/src/sync/outbox.ts +26 -24
- package/src/sync/processors/errorMaps.ts +5 -0
- package/src/sync/processors/mutation.ts +80 -72
- package/src/sync/processors/subscription.ts +69 -53
- package/src/sync/processors/sync.ts +49 -37
- package/src/sync/utils.ts +60 -41
- package/src/types.ts +165 -165
- package/src/util.ts +89 -53
|
@@ -105,7 +105,7 @@ function getAuthRules({ rules, currentUser, }) {
|
|
|
105
105
|
* @param param0 The `{schema, modelName}` to inspect.
|
|
106
106
|
* @returns A sorted array of auth modes to attempt.
|
|
107
107
|
*/
|
|
108
|
-
const multiAuthStrategy = (
|
|
108
|
+
const multiAuthStrategy = () => async ({ schema, modelName }) => {
|
|
109
109
|
let currentUser;
|
|
110
110
|
try {
|
|
111
111
|
const authSession = await (0, core_1.fetchAuthSession)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiAuthStrategy.js","sources":["../../../src/authModeStrategies/multiAuthStrategy.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.multiAuthStrategy = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst types_1 = require(\"../types\");\nfunction getProviderFromRule(rule) {\n // private with no provider means userPools\n if (rule.allow === 'private' && !rule.provider) {\n return types_1.ModelAttributeAuthProvider.USER_POOLS;\n }\n // public with no provider means apiKey\n if (rule.allow === 'public' && !rule.provider) {\n return types_1.ModelAttributeAuthProvider.API_KEY;\n }\n return rule.provider;\n}\nfunction sortAuthRulesWithPriority(rules) {\n const allowSortPriority = [\n types_1.ModelAttributeAuthAllow.CUSTOM,\n types_1.ModelAttributeAuthAllow.OWNER,\n types_1.ModelAttributeAuthAllow.GROUPS,\n types_1.ModelAttributeAuthAllow.PRIVATE,\n types_1.ModelAttributeAuthAllow.PUBLIC,\n ];\n const providerSortPriority = [\n types_1.ModelAttributeAuthProvider.FUNCTION,\n types_1.ModelAttributeAuthProvider.USER_POOLS,\n types_1.ModelAttributeAuthProvider.OIDC,\n types_1.ModelAttributeAuthProvider.IAM,\n types_1.ModelAttributeAuthProvider.API_KEY,\n ];\n return [...rules].sort((a, b) => {\n if (a.allow === b.allow) {\n return (providerSortPriority.indexOf(getProviderFromRule(a)) -\n providerSortPriority.indexOf(getProviderFromRule(b)));\n }\n return (allowSortPriority.indexOf(a.allow) - allowSortPriority.indexOf(b.allow));\n });\n}\nfunction getAuthRules({ rules, currentUser, }) {\n // Using Set to ensure uniqueness\n const authModes = new Set();\n rules.forEach(rule => {\n switch (rule.allow) {\n case types_1.ModelAttributeAuthAllow.CUSTOM:\n // custom with no provider -> function\n if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.FUNCTION) {\n authModes.add('lambda');\n }\n break;\n case types_1.ModelAttributeAuthAllow.GROUPS:\n case types_1.ModelAttributeAuthAllow.OWNER: {\n // We shouldn't attempt User Pool or OIDC if there isn't an authenticated user\n if (currentUser) {\n if (rule.provider === types_1.ModelAttributeAuthProvider.USER_POOLS) {\n authModes.add('userPool');\n }\n else if (rule.provider === types_1.ModelAttributeAuthProvider.OIDC) {\n authModes.add('oidc');\n }\n }\n break;\n }\n case types_1.ModelAttributeAuthAllow.PRIVATE: {\n // We shouldn't attempt private if there isn't an authenticated user\n if (currentUser) {\n // private with no provider means userPools\n if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.USER_POOLS) {\n authModes.add('userPool');\n }\n else if (rule.provider === types_1.ModelAttributeAuthProvider.IAM) {\n authModes.add('iam');\n }\n }\n break;\n }\n case types_1.ModelAttributeAuthAllow.PUBLIC: {\n if (rule.provider === types_1.ModelAttributeAuthProvider.IAM) {\n authModes.add('iam');\n }\n else if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.API_KEY) {\n // public with no provider means apiKey\n authModes.add('apiKey');\n }\n break;\n }\n default:\n break;\n }\n });\n return Array.from(authModes);\n}\n/**\n * Returns an array of auth modes to try based on the schema, model, and\n * authenticated user (or lack thereof). Rules are sourced from `getAuthRules`\n * and returned in the order they ought to be attempted.\n *\n * @see sortAuthRulesWithPriority\n * @see getAuthRules\n *\n * @param param0 The `{schema, modelName}` to inspect.\n * @returns A sorted array of auth modes to attempt.\n */\nconst multiAuthStrategy = (
|
|
1
|
+
{"version":3,"file":"multiAuthStrategy.js","sources":["../../../src/authModeStrategies/multiAuthStrategy.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.multiAuthStrategy = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst types_1 = require(\"../types\");\nfunction getProviderFromRule(rule) {\n // private with no provider means userPools\n if (rule.allow === 'private' && !rule.provider) {\n return types_1.ModelAttributeAuthProvider.USER_POOLS;\n }\n // public with no provider means apiKey\n if (rule.allow === 'public' && !rule.provider) {\n return types_1.ModelAttributeAuthProvider.API_KEY;\n }\n return rule.provider;\n}\nfunction sortAuthRulesWithPriority(rules) {\n const allowSortPriority = [\n types_1.ModelAttributeAuthAllow.CUSTOM,\n types_1.ModelAttributeAuthAllow.OWNER,\n types_1.ModelAttributeAuthAllow.GROUPS,\n types_1.ModelAttributeAuthAllow.PRIVATE,\n types_1.ModelAttributeAuthAllow.PUBLIC,\n ];\n const providerSortPriority = [\n types_1.ModelAttributeAuthProvider.FUNCTION,\n types_1.ModelAttributeAuthProvider.USER_POOLS,\n types_1.ModelAttributeAuthProvider.OIDC,\n types_1.ModelAttributeAuthProvider.IAM,\n types_1.ModelAttributeAuthProvider.API_KEY,\n ];\n return [...rules].sort((a, b) => {\n if (a.allow === b.allow) {\n return (providerSortPriority.indexOf(getProviderFromRule(a)) -\n providerSortPriority.indexOf(getProviderFromRule(b)));\n }\n return (allowSortPriority.indexOf(a.allow) - allowSortPriority.indexOf(b.allow));\n });\n}\nfunction getAuthRules({ rules, currentUser, }) {\n // Using Set to ensure uniqueness\n const authModes = new Set();\n rules.forEach(rule => {\n switch (rule.allow) {\n case types_1.ModelAttributeAuthAllow.CUSTOM:\n // custom with no provider -> function\n if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.FUNCTION) {\n authModes.add('lambda');\n }\n break;\n case types_1.ModelAttributeAuthAllow.GROUPS:\n case types_1.ModelAttributeAuthAllow.OWNER: {\n // We shouldn't attempt User Pool or OIDC if there isn't an authenticated user\n if (currentUser) {\n if (rule.provider === types_1.ModelAttributeAuthProvider.USER_POOLS) {\n authModes.add('userPool');\n }\n else if (rule.provider === types_1.ModelAttributeAuthProvider.OIDC) {\n authModes.add('oidc');\n }\n }\n break;\n }\n case types_1.ModelAttributeAuthAllow.PRIVATE: {\n // We shouldn't attempt private if there isn't an authenticated user\n if (currentUser) {\n // private with no provider means userPools\n if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.USER_POOLS) {\n authModes.add('userPool');\n }\n else if (rule.provider === types_1.ModelAttributeAuthProvider.IAM) {\n authModes.add('iam');\n }\n }\n break;\n }\n case types_1.ModelAttributeAuthAllow.PUBLIC: {\n if (rule.provider === types_1.ModelAttributeAuthProvider.IAM) {\n authModes.add('iam');\n }\n else if (!rule.provider ||\n rule.provider === types_1.ModelAttributeAuthProvider.API_KEY) {\n // public with no provider means apiKey\n authModes.add('apiKey');\n }\n break;\n }\n default:\n break;\n }\n });\n return Array.from(authModes);\n}\n/**\n * Returns an array of auth modes to try based on the schema, model, and\n * authenticated user (or lack thereof). Rules are sourced from `getAuthRules`\n * and returned in the order they ought to be attempted.\n *\n * @see sortAuthRulesWithPriority\n * @see getAuthRules\n *\n * @param param0 The `{schema, modelName}` to inspect.\n * @returns A sorted array of auth modes to attempt.\n */\nconst multiAuthStrategy = () => async ({ schema, modelName }) => {\n let currentUser;\n try {\n const authSession = await (0, core_1.fetchAuthSession)();\n if (authSession.tokens.accessToken) {\n // the user is authenticated\n currentUser = authSession;\n }\n }\n catch (e) {\n // No current user\n }\n const { attributes } = schema.namespaces.user.models[modelName];\n if (attributes) {\n const authAttribute = attributes.find(attr => attr.type === 'auth');\n if (authAttribute?.properties?.rules) {\n const sortedRules = sortAuthRulesWithPriority(authAttribute.properties.rules);\n return getAuthRules({ currentUser, rules: sortedRules });\n }\n }\n return [];\n};\nexports.multiAuthStrategy = multiAuthStrategy;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,KAAK,CAAC,CAAC;AACnC;AACA;AACA,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,SAAS,mBAAmB,CAAC,IAAI,EAAE;AACnC;AACA,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AACpD,QAAQ,OAAO,OAAO,CAAC,0BAA0B,CAAC,UAAU,CAAC;AAC7D,KAAK;AACL;AACA,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AACnD,QAAQ,OAAO,OAAO,CAAC,0BAA0B,CAAC,OAAO,CAAC;AAC1D,KAAK;AACL,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC;AACzB,CAAC;AACD,SAAS,yBAAyB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,OAAO,CAAC,uBAAuB,CAAC,MAAM;AAC9C,QAAQ,OAAO,CAAC,uBAAuB,CAAC,KAAK;AAC7C,QAAQ,OAAO,CAAC,uBAAuB,CAAC,MAAM;AAC9C,QAAQ,OAAO,CAAC,uBAAuB,CAAC,OAAO;AAC/C,QAAQ,OAAO,CAAC,uBAAuB,CAAC,MAAM;AAC9C,KAAK,CAAC;AACN,IAAI,MAA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,CAAC;AACrE,SAAS;AACT,KAAK;AACL,IAAI,OAAO,EAAE,CAAC;AACd,CAAC,CAAC;AACF,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;;"}
|
|
@@ -15,11 +15,10 @@ const storage_1 = require("../storage/storage");
|
|
|
15
15
|
const relationship_1 = require("../storage/relationship");
|
|
16
16
|
const sync_1 = require("../sync");
|
|
17
17
|
const types_1 = require("../types");
|
|
18
|
-
const utils_2 = require("./utils");
|
|
19
18
|
const util_1 = require("../util");
|
|
20
19
|
const next_1 = require("../predicates/next");
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const utils_2 = require("../sync/utils");
|
|
21
|
+
const utils_3 = require("./utils");
|
|
23
22
|
(0, immer_1.setAutoFreeze)(true);
|
|
24
23
|
(0, immer_1.enablePatches)();
|
|
25
24
|
const logger = new core_1.ConsoleLogger('DataStore');
|
|
@@ -226,7 +225,7 @@ const initSchema = (userSchema) => {
|
|
|
226
225
|
// compatibility with legacy/pre-PK codegen for lazy loading to inject
|
|
227
226
|
// index fields into the model definition.
|
|
228
227
|
// definition.cloudFields = { ...definition.fields };
|
|
229
|
-
const indexes = schema.namespaces[namespace].relationships[model.name]
|
|
228
|
+
const { indexes } = schema.namespaces[namespace].relationships[model.name];
|
|
230
229
|
const indexFields = new Set();
|
|
231
230
|
for (const index of indexes) {
|
|
232
231
|
for (const indexField of index[1]) {
|
|
@@ -308,7 +307,7 @@ const checkSchemaCodegenVersion = (codegenVersion) => {
|
|
|
308
307
|
let isValid = false;
|
|
309
308
|
try {
|
|
310
309
|
const versionParts = codegenVersion.split('.');
|
|
311
|
-
const [major, minor
|
|
310
|
+
const [major, minor] = versionParts;
|
|
312
311
|
isValid = Number(major) === majorVersion && Number(minor) >= minorVersion;
|
|
313
312
|
}
|
|
314
313
|
catch (err) {
|
|
@@ -340,9 +339,9 @@ const createTypeClasses = namespace => {
|
|
|
340
339
|
* metadata fields (_version, _deleted, etc.) exposed on the model itself.
|
|
341
340
|
*/
|
|
342
341
|
const instancesMetadata = new WeakSet();
|
|
343
|
-
function modelInstanceCreator(
|
|
342
|
+
function modelInstanceCreator(ModelConstructor, init) {
|
|
344
343
|
instancesMetadata.add(init);
|
|
345
|
-
return new
|
|
344
|
+
return new ModelConstructor(init);
|
|
346
345
|
}
|
|
347
346
|
const validateModelFields = (modelDefinition) => (k, v) => {
|
|
348
347
|
const fieldDefinition = modelDefinition.fields[k];
|
|
@@ -414,9 +413,7 @@ const validateModelFields = (modelDefinition) => (k, v) => {
|
|
|
414
413
|
}
|
|
415
414
|
}
|
|
416
415
|
}
|
|
417
|
-
else if (!isRequired && v === undefined)
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
416
|
+
else if (!isRequired && v === undefined) ;
|
|
420
417
|
else if (typeof v !== jsType && v !== null) {
|
|
421
418
|
throw new Error(`Field ${name} should be of type ${jsType}, ${typeof v} received. ${v}`);
|
|
422
419
|
}
|
|
@@ -576,7 +573,9 @@ const createModelClass = (modelDefinition) => {
|
|
|
576
573
|
// are only create to provide a consistent view of the data for fields pre/post sync
|
|
577
574
|
// where possible. (not all fields can be normalized pre-sync, because they're generally
|
|
578
575
|
// "cloud managed" fields, like createdAt and updatedAt.)
|
|
579
|
-
const normalized = (0, immer_1.produce)(baseInstance, (draft) =>
|
|
576
|
+
const normalized = (0, immer_1.produce)(baseInstance, (draft) => {
|
|
577
|
+
normalize(modelDefinition, draft);
|
|
578
|
+
});
|
|
580
579
|
initPatches.set(normalized, patches);
|
|
581
580
|
return normalized;
|
|
582
581
|
}
|
|
@@ -654,7 +653,7 @@ const createModelClass = (modelDefinition) => {
|
|
|
654
653
|
pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
|
|
655
654
|
});
|
|
656
655
|
for (const relationship of allModelRelationships) {
|
|
657
|
-
const field = relationship
|
|
656
|
+
const { field } = relationship;
|
|
658
657
|
Object.defineProperty(clazz.prototype, modelDefinition.fields[field].name, {
|
|
659
658
|
set(model) {
|
|
660
659
|
if (!(typeof model === 'object' || typeof model === 'undefined'))
|
|
@@ -664,7 +663,7 @@ const createModelClass = (modelDefinition) => {
|
|
|
664
663
|
// Avoid validation error when processing AppSync response with nested
|
|
665
664
|
// selection set. Nested entitites lack version field and can not be validated
|
|
666
665
|
// TODO: explore a more reliable method to solve this
|
|
667
|
-
if (
|
|
666
|
+
if (Object.prototype.hasOwnProperty.call(model, '_version')) {
|
|
668
667
|
const modelConstructor = Object.getPrototypeOf(model || {})
|
|
669
668
|
.constructor;
|
|
670
669
|
if (!isValidModelConstructor(modelConstructor)) {
|
|
@@ -702,7 +701,7 @@ const createModelClass = (modelDefinition) => {
|
|
|
702
701
|
// if the memos already has a result for this field, we'll use it.
|
|
703
702
|
// there is no "cache" invalidation of any kind; memos are permanent to
|
|
704
703
|
// keep an immutable perception of the instance.
|
|
705
|
-
if (!
|
|
704
|
+
if (!Object.prototype.hasOwnProperty.call(instanceMemos, field)) {
|
|
706
705
|
// before we populate the memo, we need to know where to look for relatives.
|
|
707
706
|
// today, this only supports DataStore. Models aren't managed elsewhere in Amplify.
|
|
708
707
|
if ((0, exports.getAttachment)(this) === ModelAttachment.DataStore) {
|
|
@@ -711,9 +710,9 @@ const createModelClass = (modelDefinition) => {
|
|
|
711
710
|
// drop the promise into the memo's synchronously, eliminating the chance
|
|
712
711
|
// for a race.
|
|
713
712
|
const resultPromise = instance.query(relationship.remoteModelConstructor, base => base.and(q => {
|
|
714
|
-
return relationship.remoteJoinFields.map((
|
|
713
|
+
return relationship.remoteJoinFields.map((joinField, index) => {
|
|
715
714
|
// TODO: anything we can use instead of `any` here?
|
|
716
|
-
return q[
|
|
715
|
+
return q[joinField].eq(this[relationship.localJoinFields[index]]);
|
|
717
716
|
});
|
|
718
717
|
}));
|
|
719
718
|
// results in hand, how we return them to the caller depends on the relationship type.
|
|
@@ -917,10 +916,10 @@ function getModelConstructorByModelName(namespaceName, modelName) {
|
|
|
917
916
|
* @param version The expected schema version.
|
|
918
917
|
*/
|
|
919
918
|
async function checkSchemaVersion(storage, version) {
|
|
920
|
-
const
|
|
919
|
+
const SettingCtor = dataStoreClasses.Setting;
|
|
921
920
|
const modelDefinition = schema.namespaces[util_1.DATASTORE].models.Setting;
|
|
922
921
|
await storage.runExclusive(async (s) => {
|
|
923
|
-
const [schemaVersionSetting] = await s.query(
|
|
922
|
+
const [schemaVersionSetting] = await s.query(SettingCtor, predicates_1.ModelPredicateCreator.createFromAST(modelDefinition, {
|
|
924
923
|
and: { key: { eq: SETTING_SCHEMA_VERSION } },
|
|
925
924
|
}), { page: 0, limit: 1 });
|
|
926
925
|
if (schemaVersionSetting !== undefined &&
|
|
@@ -931,7 +930,7 @@ async function checkSchemaVersion(storage, version) {
|
|
|
931
930
|
}
|
|
932
931
|
}
|
|
933
932
|
else {
|
|
934
|
-
await s.save(modelInstanceCreator(
|
|
933
|
+
await s.save(modelInstanceCreator(SettingCtor, {
|
|
935
934
|
key: SETTING_SCHEMA_VERSION,
|
|
936
935
|
value: JSON.stringify(version),
|
|
937
936
|
}));
|
|
@@ -1033,7 +1032,7 @@ class DataStore {
|
|
|
1033
1032
|
*
|
|
1034
1033
|
* (Reasonable = *seconds*, not minutes.)
|
|
1035
1034
|
*/
|
|
1036
|
-
this.runningProcesses = new
|
|
1035
|
+
this.runningProcesses = new utils_1.BackgroundProcessManager();
|
|
1037
1036
|
/**
|
|
1038
1037
|
* Indicates what state DataStore is in.
|
|
1039
1038
|
*
|
|
@@ -1054,9 +1053,9 @@ class DataStore {
|
|
|
1054
1053
|
this.state = DataStoreState.Starting;
|
|
1055
1054
|
if (this.initialized === undefined) {
|
|
1056
1055
|
logger.debug('Starting DataStore');
|
|
1057
|
-
this.initialized = new Promise((
|
|
1058
|
-
this.initResolve =
|
|
1059
|
-
this.initReject =
|
|
1056
|
+
this.initialized = new Promise((resolve, reject) => {
|
|
1057
|
+
this.initResolve = resolve;
|
|
1058
|
+
this.initReject = reject;
|
|
1060
1059
|
});
|
|
1061
1060
|
}
|
|
1062
1061
|
else {
|
|
@@ -1082,7 +1081,7 @@ class DataStore {
|
|
|
1082
1081
|
* In non-Node environments (the browser or React Native), we can begin returning data
|
|
1083
1082
|
* once subscriptions are in place.
|
|
1084
1083
|
*/
|
|
1085
|
-
const readyType = (0,
|
|
1084
|
+
const readyType = (0, utils_3.isNode)()
|
|
1086
1085
|
? sync_1.ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY
|
|
1087
1086
|
: sync_1.ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED;
|
|
1088
1087
|
if (type === readyType) {
|
|
@@ -1118,7 +1117,7 @@ class DataStore {
|
|
|
1118
1117
|
if (!this.storage) {
|
|
1119
1118
|
throw new Error('No storage to query');
|
|
1120
1119
|
}
|
|
1121
|
-
|
|
1120
|
+
// #region Input validation
|
|
1122
1121
|
if (!isValidModelConstructor(modelConstructor)) {
|
|
1123
1122
|
const msg = 'Constructor is not for a valid model';
|
|
1124
1123
|
logger.error(msg, { modelConstructor });
|
|
@@ -1165,7 +1164,7 @@ class DataStore {
|
|
|
1165
1164
|
result = (0, util_1.inMemoryPagination)(result, pagination);
|
|
1166
1165
|
}
|
|
1167
1166
|
}
|
|
1168
|
-
|
|
1167
|
+
// #endregion
|
|
1169
1168
|
const returnOne = isQueryOne(identifierOrCriteria) ||
|
|
1170
1169
|
(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition);
|
|
1171
1170
|
return attached(returnOne ? result[0] : result, ModelAttachment.DataStore);
|
|
@@ -1192,7 +1191,9 @@ class DataStore {
|
|
|
1192
1191
|
// are ALWAYS present, whereas update patches are only present if copyOf
|
|
1193
1192
|
// was used to create the instance.
|
|
1194
1193
|
const patchesTuple = updatedPatchesTuple || initPatchesTuple;
|
|
1195
|
-
const modelConstructor = model
|
|
1194
|
+
const modelConstructor = model
|
|
1195
|
+
? model.constructor
|
|
1196
|
+
: undefined;
|
|
1196
1197
|
if (!isValidModelConstructor(modelConstructor)) {
|
|
1197
1198
|
const msg = 'Object is not an instance of a valid model';
|
|
1198
1199
|
logger.error(msg, { model });
|
|
@@ -1355,15 +1356,15 @@ class DataStore {
|
|
|
1355
1356
|
: undefined;
|
|
1356
1357
|
if (modelOrConstructor && modelConstructor === undefined) {
|
|
1357
1358
|
const model = modelOrConstructor;
|
|
1358
|
-
const
|
|
1359
|
-
if (isValidModelConstructor(
|
|
1359
|
+
const resolvedModelConstructor = model && Object.getPrototypeOf(model).constructor;
|
|
1360
|
+
if (isValidModelConstructor(resolvedModelConstructor)) {
|
|
1360
1361
|
if (identifierOrCriteria) {
|
|
1361
1362
|
logger.warn('idOrCriteria is ignored when using a model instance', {
|
|
1362
1363
|
model,
|
|
1363
1364
|
identifierOrCriteria,
|
|
1364
1365
|
});
|
|
1365
1366
|
}
|
|
1366
|
-
return this.observe(
|
|
1367
|
+
return this.observe(resolvedModelConstructor, model.id);
|
|
1367
1368
|
}
|
|
1368
1369
|
else {
|
|
1369
1370
|
const msg = 'The model is not an instance of a PersistentModelConstructor';
|
|
@@ -1429,8 +1430,12 @@ class DataStore {
|
|
|
1429
1430
|
observer.next(message);
|
|
1430
1431
|
}
|
|
1431
1432
|
}, 'datastore observe message handler'),
|
|
1432
|
-
error: err =>
|
|
1433
|
-
|
|
1433
|
+
error: err => {
|
|
1434
|
+
observer.error(err);
|
|
1435
|
+
},
|
|
1436
|
+
complete: () => {
|
|
1437
|
+
observer.complete();
|
|
1438
|
+
},
|
|
1434
1439
|
});
|
|
1435
1440
|
}, 'datastore observe observable initialization')
|
|
1436
1441
|
.catch(this.handleAddProcError('DataStore.observe()'))
|
|
@@ -1494,17 +1499,17 @@ class DataStore {
|
|
|
1494
1499
|
// first, query and return any locally-available records
|
|
1495
1500
|
(await this.query(model, criteria, sortOptions)).forEach(item => {
|
|
1496
1501
|
const itemModelDefinition = getModelDefinition(model);
|
|
1497
|
-
const idOrPk = (0,
|
|
1502
|
+
const idOrPk = (0, utils_2.getIdentifierValue)(itemModelDefinition, item);
|
|
1498
1503
|
items.set(idOrPk, item);
|
|
1499
1504
|
});
|
|
1500
1505
|
// Observe the model and send a stream of updates (debounced).
|
|
1501
1506
|
// We need to post-filter results instead of passing criteria through
|
|
1502
1507
|
// to have visibility into items that move from in-set to out-of-set.
|
|
1503
1508
|
// We need to explicitly remove those items from the existing snapshot.
|
|
1504
|
-
handle = this.observe(model).subscribe(({ element, model, opType }) => this.runningProcesses.isOpen &&
|
|
1509
|
+
handle = this.observe(model).subscribe(({ element, model: observedModel, opType }) => this.runningProcesses.isOpen &&
|
|
1505
1510
|
this.runningProcesses.add(async () => {
|
|
1506
|
-
const itemModelDefinition = getModelDefinition(
|
|
1507
|
-
const idOrPk = (0,
|
|
1511
|
+
const itemModelDefinition = getModelDefinition(observedModel);
|
|
1512
|
+
const idOrPk = (0, utils_2.getIdentifierValue)(itemModelDefinition, element);
|
|
1508
1513
|
if (executivePredicate &&
|
|
1509
1514
|
!(await executivePredicate.matches(element))) {
|
|
1510
1515
|
if (opType === 'UPDATE' &&
|
|
@@ -1530,7 +1535,7 @@ class DataStore {
|
|
|
1530
1535
|
else {
|
|
1531
1536
|
itemsChanged.set(idOrPk, element);
|
|
1532
1537
|
}
|
|
1533
|
-
const isSynced = this.sync?.getModelSyncedStatus(
|
|
1538
|
+
const isSynced = this.sync?.getModelSyncedStatus(observedModel) ?? false;
|
|
1534
1539
|
const limit = itemsChanged.size - deletedItemIds.length >=
|
|
1535
1540
|
this.syncPageSize;
|
|
1536
1541
|
if (limit || isSynced) {
|
|
@@ -1565,7 +1570,7 @@ class DataStore {
|
|
|
1565
1570
|
items.clear();
|
|
1566
1571
|
itemsArray.forEach(item => {
|
|
1567
1572
|
const itemModelDefinition = getModelDefinition(model);
|
|
1568
|
-
const idOrPk = (0,
|
|
1573
|
+
const idOrPk = (0, utils_2.getIdentifierValue)(itemModelDefinition, item);
|
|
1569
1574
|
items.set(idOrPk, item);
|
|
1570
1575
|
});
|
|
1571
1576
|
// remove deleted items from the final result set
|
|
@@ -1604,8 +1609,8 @@ class DataStore {
|
|
|
1604
1609
|
* @param itemsToSort A array of model type.
|
|
1605
1610
|
*/
|
|
1606
1611
|
const sortItems = (itemsToSort) => {
|
|
1607
|
-
const
|
|
1608
|
-
const pagination = this.processPagination(
|
|
1612
|
+
const sortingModelDefinition = getModelDefinition(model);
|
|
1613
|
+
const pagination = this.processPagination(sortingModelDefinition, options);
|
|
1609
1614
|
const sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
1610
1615
|
if (sortPredicates.length) {
|
|
1611
1616
|
const compareFn = (0, util_1.sortCompareFunction)(sortPredicates);
|
|
@@ -1638,7 +1643,7 @@ class DataStore {
|
|
|
1638
1643
|
};
|
|
1639
1644
|
this.configure = (config = {}) => {
|
|
1640
1645
|
this.amplifyContext.InternalAPI = this.InternalAPI;
|
|
1641
|
-
const { DataStore: configDataStore, authModeStrategyType: configAuthModeStrategyType,
|
|
1646
|
+
const { DataStore: configDataStore, authModeStrategyType: configAuthModeStrategyType, maxRecordsToSync: configMaxRecordsToSync, syncPageSize: configSyncPageSize, fullSyncInterval: configFullSyncInterval, syncExpressions: configSyncExpressions, authProviders: configAuthProviders, storageAdapter: configStorageAdapter, ...configFromAmplify } = config;
|
|
1642
1647
|
const currentAppSyncConfig = core_1.Amplify.getConfig().API?.GraphQL;
|
|
1643
1648
|
const appSyncConfig = {
|
|
1644
1649
|
aws_appsync_graphqlEndpoint: currentAppSyncConfig?.endpoint,
|