@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
package/src/sync/utils.ts
CHANGED
|
@@ -3,53 +3,55 @@
|
|
|
3
3
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
4
4
|
import type { GraphQLError } from 'graphql';
|
|
5
5
|
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
6
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
7
|
+
|
|
6
8
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
7
9
|
import {
|
|
10
|
+
AuthModeStrategy,
|
|
8
11
|
AuthorizationRule,
|
|
9
12
|
GraphQLCondition,
|
|
10
|
-
GraphQLFilter,
|
|
11
13
|
GraphQLField,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
isSchemaModel,
|
|
16
|
-
isSchemaModelWithAttributes,
|
|
17
|
-
isTargetNameAssociation,
|
|
18
|
-
isNonModelFieldType,
|
|
14
|
+
GraphQLFilter,
|
|
15
|
+
InternalSchema,
|
|
16
|
+
ModelAttributes,
|
|
19
17
|
ModelFields,
|
|
20
18
|
ModelInstanceMetadata,
|
|
19
|
+
ModelOperation,
|
|
21
20
|
OpType,
|
|
22
21
|
PersistentModel,
|
|
23
22
|
PersistentModelConstructor,
|
|
24
|
-
PredicatesGroup,
|
|
25
23
|
PredicateObject,
|
|
24
|
+
PredicatesGroup,
|
|
26
25
|
RelationshipType,
|
|
27
26
|
SchemaModel,
|
|
28
27
|
SchemaNamespace,
|
|
29
28
|
SchemaNonModel,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ModelAttributes,
|
|
29
|
+
isEnumFieldType,
|
|
30
|
+
isGraphQLScalarType,
|
|
31
|
+
isNonModelFieldType,
|
|
34
32
|
isPredicateGroup,
|
|
33
|
+
isPredicateObj,
|
|
34
|
+
isSchemaModel,
|
|
35
|
+
isSchemaModelWithAttributes,
|
|
36
|
+
isTargetNameAssociation,
|
|
35
37
|
} from '../types';
|
|
36
38
|
import {
|
|
37
|
-
extractPrimaryKeyFieldNames,
|
|
38
|
-
establishRelationAndKeys,
|
|
39
39
|
IDENTIFIER_KEY_SEPARATOR,
|
|
40
|
+
establishRelationAndKeys,
|
|
41
|
+
extractPrimaryKeyFieldNames,
|
|
40
42
|
} from '../util';
|
|
43
|
+
|
|
41
44
|
import { MutationEvent } from './';
|
|
42
|
-
import { ConsoleLogger } from '@aws-amplify/core';
|
|
43
45
|
|
|
44
46
|
const logger = new ConsoleLogger('DataStore');
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
LIST
|
|
48
|
-
CREATE
|
|
49
|
-
UPDATE
|
|
50
|
-
DELETE
|
|
51
|
-
GET
|
|
52
|
-
}
|
|
48
|
+
const GraphQLOperationType = {
|
|
49
|
+
LIST: 'query',
|
|
50
|
+
CREATE: 'mutation',
|
|
51
|
+
UPDATE: 'mutation',
|
|
52
|
+
DELETE: 'mutation',
|
|
53
|
+
GET: 'query',
|
|
54
|
+
};
|
|
53
55
|
|
|
54
56
|
export enum TransformerMutationType {
|
|
55
57
|
CREATE = 'Create',
|
|
@@ -64,10 +66,10 @@ const dummyMetadata: ModelInstanceMetadata = {
|
|
|
64
66
|
_deleted: undefined!,
|
|
65
67
|
};
|
|
66
68
|
|
|
67
|
-
const metadataFields =
|
|
68
|
-
|
|
69
|
-
);
|
|
70
|
-
export function getMetadataFields():
|
|
69
|
+
const metadataFields = Object.keys(
|
|
70
|
+
dummyMetadata,
|
|
71
|
+
) as (keyof ModelInstanceMetadata)[];
|
|
72
|
+
export function getMetadataFields(): readonly string[] {
|
|
71
73
|
return metadataFields;
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -107,6 +109,7 @@ function getImplicitOwnerField(
|
|
|
107
109
|
if (!scalarFields.owner && ownerFields.includes('owner')) {
|
|
108
110
|
return ['owner'];
|
|
109
111
|
}
|
|
112
|
+
|
|
110
113
|
return [];
|
|
111
114
|
}
|
|
112
115
|
|
|
@@ -117,13 +120,16 @@ function getOwnerFields(
|
|
|
117
120
|
if (isSchemaModelWithAttributes(modelDefinition)) {
|
|
118
121
|
modelDefinition.attributes!.forEach(attr => {
|
|
119
122
|
if (attr.properties && attr.properties.rules) {
|
|
120
|
-
const rule = attr.properties.rules.find(
|
|
123
|
+
const rule = attr.properties.rules.find(
|
|
124
|
+
currentRule => currentRule.allow === 'owner',
|
|
125
|
+
);
|
|
121
126
|
if (rule && rule.ownerField) {
|
|
122
127
|
ownerFields.push(rule.ownerField);
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
});
|
|
126
131
|
}
|
|
132
|
+
|
|
127
133
|
return ownerFields;
|
|
128
134
|
}
|
|
129
135
|
|
|
@@ -173,11 +179,12 @@ function getConnectionFields(
|
|
|
173
179
|
// Need to retrieve relations in order to get connected model keys
|
|
174
180
|
const [relations] = establishRelationAndKeys(namespace);
|
|
175
181
|
|
|
176
|
-
const connectedModelName =
|
|
177
|
-
modelDefinition.fields[name].type
|
|
182
|
+
const connectedModelName = (
|
|
183
|
+
modelDefinition.fields[name].type as any
|
|
184
|
+
).model;
|
|
178
185
|
|
|
179
186
|
const byPkIndex = relations[connectedModelName].indexes.find(
|
|
180
|
-
([
|
|
187
|
+
([currentName]) => currentName === 'byPk',
|
|
181
188
|
);
|
|
182
189
|
const keyFields = byPkIndex && byPkIndex[1];
|
|
183
190
|
const keyFieldSelectionSet = keyFields?.join(' ');
|
|
@@ -208,17 +215,18 @@ function getNonModelFields(
|
|
|
208
215
|
if (isNonModelFieldType(type)) {
|
|
209
216
|
const typeDefinition = namespace.nonModels![type.nonModel];
|
|
210
217
|
const scalarFields = Object.values(getScalarFields(typeDefinition)).map(
|
|
211
|
-
({ name }) =>
|
|
218
|
+
({ name: currentName }) => currentName,
|
|
212
219
|
);
|
|
213
220
|
|
|
214
221
|
const nested: string[] = [];
|
|
215
222
|
Object.values(typeDefinition.fields).forEach(field => {
|
|
216
|
-
const { type, name } = field;
|
|
223
|
+
const { type: fieldType, name: fieldName } = field;
|
|
217
224
|
|
|
218
|
-
if (isNonModelFieldType(
|
|
219
|
-
const
|
|
225
|
+
if (isNonModelFieldType(fieldType)) {
|
|
226
|
+
const nonModelTypeDefinition =
|
|
227
|
+
namespace.nonModels![fieldType.nonModel];
|
|
220
228
|
nested.push(
|
|
221
|
-
`${
|
|
229
|
+
`${fieldName} { ${generateSelectionSet(namespace, nonModelTypeDefinition)} }`,
|
|
222
230
|
);
|
|
223
231
|
}
|
|
224
232
|
});
|
|
@@ -293,6 +301,7 @@ export function getAuthorizationRules(
|
|
|
293
301
|
if (isOwnerAuth) {
|
|
294
302
|
// owner rules has least priority
|
|
295
303
|
resultRules.push(authRule);
|
|
304
|
+
|
|
296
305
|
return;
|
|
297
306
|
}
|
|
298
307
|
|
|
@@ -308,7 +317,7 @@ export function buildSubscriptionGraphQLOperation(
|
|
|
308
317
|
transformerMutationType: TransformerMutationType,
|
|
309
318
|
isOwnerAuthorization: boolean,
|
|
310
319
|
ownerField: string,
|
|
311
|
-
filterArg
|
|
320
|
+
filterArg = false,
|
|
312
321
|
): [TransformerMutationType, string, string] {
|
|
313
322
|
const selectionSet = generateSelectionSet(namespace, modelDefinition);
|
|
314
323
|
|
|
@@ -453,6 +462,7 @@ export function createMutationInstanceFromModelOperation<
|
|
|
453
462
|
if (isAWSJSON) {
|
|
454
463
|
return JSON.stringify(v);
|
|
455
464
|
}
|
|
465
|
+
|
|
456
466
|
return v;
|
|
457
467
|
};
|
|
458
468
|
|
|
@@ -491,12 +501,13 @@ export function predicateToGraphQLCondition(
|
|
|
491
501
|
// key fields from the predicate/condition when ALL of the keyFields are present and using `eq` operators
|
|
492
502
|
|
|
493
503
|
const keyFields = extractPrimaryKeyFieldNames(modelDefinition);
|
|
504
|
+
|
|
494
505
|
return predicateToGraphQLFilter(predicate, keyFields) as GraphQLCondition;
|
|
495
506
|
}
|
|
496
507
|
/**
|
|
497
508
|
* @param predicatesGroup - Predicate Group
|
|
498
509
|
@returns GQL Filter Expression from Predicate Group
|
|
499
|
-
|
|
510
|
+
|
|
500
511
|
@remarks Flattens redundant list predicates
|
|
501
512
|
@example
|
|
502
513
|
|
|
@@ -537,6 +548,7 @@ export function predicateToGraphQLFilter(
|
|
|
537
548
|
};
|
|
538
549
|
|
|
539
550
|
children.push(gqlField);
|
|
551
|
+
|
|
540
552
|
return;
|
|
541
553
|
}
|
|
542
554
|
|
|
@@ -557,6 +569,7 @@ export function predicateToGraphQLFilter(
|
|
|
557
569
|
) {
|
|
558
570
|
delete result[type];
|
|
559
571
|
Object.assign(result, child);
|
|
572
|
+
|
|
560
573
|
return result;
|
|
561
574
|
}
|
|
562
575
|
}
|
|
@@ -693,6 +706,7 @@ export function repeatedFieldInGroup(
|
|
|
693
706
|
}
|
|
694
707
|
seen[fieldName] = true;
|
|
695
708
|
}
|
|
709
|
+
|
|
696
710
|
return null;
|
|
697
711
|
};
|
|
698
712
|
|
|
@@ -779,6 +793,7 @@ export function generateRTFRemediation(
|
|
|
779
793
|
`Dynamic auth modes, such as owner auth and dynamic group auth factor in to the number of combinations you're using.\n` +
|
|
780
794
|
`You currently have ${dynamicAuthModeFields.size} dynamic auth mode(s) configured on this model: ${dynamicAuthFieldsStr}.`;
|
|
781
795
|
}
|
|
796
|
+
|
|
782
797
|
return message;
|
|
783
798
|
}
|
|
784
799
|
|
|
@@ -796,7 +811,7 @@ export function generateRTFRemediation(
|
|
|
796
811
|
}
|
|
797
812
|
|
|
798
813
|
export function getUserGroupsFromToken(
|
|
799
|
-
token:
|
|
814
|
+
token: Record<string, any>,
|
|
800
815
|
rule: AuthorizationRule,
|
|
801
816
|
): string[] {
|
|
802
817
|
// validate token against groupClaim
|
|
@@ -861,6 +876,7 @@ export async function getModelAuthModes({
|
|
|
861
876
|
} catch (error) {
|
|
862
877
|
logger.debug(`Error getting auth modes for model: ${modelName}`, error);
|
|
863
878
|
}
|
|
879
|
+
|
|
864
880
|
return modelAuthModes;
|
|
865
881
|
}
|
|
866
882
|
|
|
@@ -883,12 +899,13 @@ export function getForbiddenError(error) {
|
|
|
883
899
|
)}`
|
|
884
900
|
);
|
|
885
901
|
}
|
|
902
|
+
|
|
886
903
|
return null;
|
|
887
904
|
}
|
|
888
905
|
|
|
889
906
|
export function resolveServiceErrorStatusCode(error: unknown): number | null {
|
|
890
|
-
if (error
|
|
891
|
-
return Number(error
|
|
907
|
+
if ((error as any)?.$metadata?.httpStatusCode) {
|
|
908
|
+
return Number((error as any)?.$metadata?.httpStatusCode);
|
|
892
909
|
} else if ((error as GraphQLError)?.originalError) {
|
|
893
910
|
return resolveServiceErrorStatusCode(
|
|
894
911
|
(error as GraphQLError)?.originalError,
|
|
@@ -906,6 +923,7 @@ export function getClientSideAuthError(error) {
|
|
|
906
923
|
clientSideAuthErrors.find(clientError =>
|
|
907
924
|
error.message.includes(clientError),
|
|
908
925
|
);
|
|
926
|
+
|
|
909
927
|
return clientSideError || null;
|
|
910
928
|
}
|
|
911
929
|
|
|
@@ -920,6 +938,7 @@ export async function getTokenForCustomAuth(
|
|
|
920
938
|
if (functionAuthProvider && typeof functionAuthProvider === 'function') {
|
|
921
939
|
try {
|
|
922
940
|
const { token } = await functionAuthProvider();
|
|
941
|
+
|
|
923
942
|
return token;
|
|
924
943
|
} catch (error) {
|
|
925
944
|
throw new Error(
|