@aws-amplify/data-schema 1.20.4 → 1.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/data-schema",
3
- "version": "1.20.4",
3
+ "version": "1.21.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "docs:temp": "api-extractor run && api-documenter markdown --input-folder temp --output-folder temp/docs",
19
19
  "check:api": "rimraf temp && npm run docs:temp && tsx ../../scripts/shallow-dir-diff.ts docs temp/docs",
20
20
  "lint": "eslint .",
21
- "test": "jest"
21
+ "test": "jest --coverage"
22
22
  },
23
23
  "exports": {
24
24
  ".": {
package/src/ModelIndex.ts CHANGED
@@ -6,7 +6,7 @@ export type ModelIndexData = {
6
6
  partitionKey: string;
7
7
  sortKeys: readonly unknown[];
8
8
  indexName: string;
9
- queryField: string;
9
+ queryField: string | null;
10
10
  };
11
11
 
12
12
  export type InternalModelIndexType = ModelIndexType<any, any, any, any> & {
@@ -31,7 +31,7 @@ export type ModelIndexType<
31
31
  name: string,
32
32
  ): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, K | 'name'>;
33
33
  queryField<
34
- QF extends string = never,
34
+ QF extends string | null = never,
35
35
  MF extends ModelFieldKeys = ModelFieldKeys,
36
36
  >(
37
37
  field: QF,
@@ -217,7 +217,7 @@ function scalarFieldToGql(
217
217
  for (const index of secondaryIndexes) {
218
218
  field += ` ${index}`;
219
219
  }
220
-
220
+
221
221
  // Add validation directives for each validation rule
222
222
  for (const validationRule of validation) {
223
223
  const valueStr = typeof validationRule.value === 'number' ? validationRule.value.toString() : validationRule.value;
@@ -227,7 +227,7 @@ function scalarFieldToGql(
227
227
  field += ` @validate(type: ${validationRule.type}, value: "${valueStr}")`;
228
228
  }
229
229
  }
230
-
230
+
231
231
  return field;
232
232
  }
233
233
 
@@ -897,6 +897,7 @@ function mapToNativeAppSyncAuthDirectives(
897
897
  const rules = new Set<string>();
898
898
 
899
899
  const groupProvider: Map<string, Set<string>> = new Map();
900
+ const generalProviderUsed = new Set<string>();
900
901
 
901
902
  for (const entry of authorization) {
902
903
  const rule = accessData(entry);
@@ -911,17 +912,20 @@ function mapToNativeAppSyncAuthDirectives(
911
912
  };
912
913
  rule.groups.forEach((group) => groupProvider.get(provider)?.add(group));
913
914
  } else {
915
+ generalProviderUsed.add(provider);
914
916
  rules.add(provider);
915
917
  }
916
918
  }
917
919
 
918
920
  groupProvider.forEach((groups, provider) => {
919
- rules.add(
920
- `${provider}(cognito_groups: [${Array.from(groups)
921
- .map((group) => `"${group}"`)
922
- .join(', ')}])`,
923
- );
924
- // example: (cognito_groups: ["Bloggers", "Readers"])
921
+ if(!generalProviderUsed.has(provider)) {
922
+ rules.add(
923
+ `${provider}(cognito_groups: [${Array.from(groups).reduce((acc, group) =>
924
+ acc == "" ? `"${group}"` : `${acc}, "${group}"`
925
+ , "")}])`
926
+ );
927
+ // example: (cognito_groups: ["Bloggers", "Readers"])
928
+ }
925
929
  })
926
930
 
927
931
  const authString = [...rules].join(' ');
@@ -1112,7 +1116,7 @@ const transformedSecondaryIndexesForModel = (
1112
1116
  partitionKey: string,
1113
1117
  sortKeys: readonly string[],
1114
1118
  indexName: string,
1115
- queryField: string,
1119
+ queryField: string | null,
1116
1120
  ): string => {
1117
1121
  for (const keyName of [partitionKey, ...sortKeys]) {
1118
1122
  const field = modelFields[keyName];
@@ -1127,7 +1131,7 @@ const transformedSecondaryIndexesForModel = (
1127
1131
  }
1128
1132
  }
1129
1133
 
1130
- if (!sortKeys.length && !indexName && !queryField) {
1134
+ if (!sortKeys.length && !indexName && !queryField && queryField !== null) {
1131
1135
  return `@index(queryField: "${secondaryIndexDefaultQueryField(
1132
1136
  modelName,
1133
1137
  partitionKey,
@@ -1146,7 +1150,10 @@ const transformedSecondaryIndexesForModel = (
1146
1150
  );
1147
1151
  }
1148
1152
 
1149
- if (queryField) {
1153
+ if(queryField === null) {
1154
+ attributes.push(`queryField: null`);
1155
+ }
1156
+ else if (queryField) {
1150
1157
  attributes.push(`queryField: "${queryField}"`);
1151
1158
  } else {
1152
1159
  attributes.push(