@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/dist/cjs/SchemaProcessor.js +11 -6
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/esm/ModelIndex.d.ts +2 -2
- package/dist/esm/SchemaProcessor.mjs +11 -6
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ModelIndex.ts +2 -2
- package/src/SchemaProcessor.ts +18 -11
package/dist/esm/ModelIndex.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type ModelIndexData = {
|
|
|
4
4
|
partitionKey: string;
|
|
5
5
|
sortKeys: readonly unknown[];
|
|
6
6
|
indexName: string;
|
|
7
|
-
queryField: string;
|
|
7
|
+
queryField: string | null;
|
|
8
8
|
};
|
|
9
9
|
export type InternalModelIndexType = ModelIndexType<any, any, any, any> & {
|
|
10
10
|
data: ModelIndexData;
|
|
@@ -12,7 +12,7 @@ export type InternalModelIndexType = ModelIndexType<any, any, any, any> & {
|
|
|
12
12
|
export type ModelIndexType<ModelFieldKeys extends string, PK, SK = readonly [], QueryField = never, K extends keyof ModelIndexType<any, any, any, any> = never> = Omit<{
|
|
13
13
|
sortKeys<FieldKeys extends ModelFieldKeys = ModelFieldKeys, const SK extends ReadonlyArray<Exclude<FieldKeys, PK>> = readonly []>(sortKeys: SK): ModelIndexType<FieldKeys, PK, SK, QueryField, K | 'sortKeys'>;
|
|
14
14
|
name(name: string): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, K | 'name'>;
|
|
15
|
-
queryField<QF extends string = never, MF extends ModelFieldKeys = ModelFieldKeys>(field: QF): ModelIndexType<MF, PK, SK, QF, K | 'queryField'>;
|
|
15
|
+
queryField<QF extends string | null = never, MF extends ModelFieldKeys = ModelFieldKeys>(field: QF): ModelIndexType<MF, PK, SK, QF, K | 'queryField'>;
|
|
16
16
|
}, K> & Brand<typeof brandName>;
|
|
17
17
|
export declare function modelIndex<ModelFieldKeys extends string, PK extends ModelFieldKeys, SK = readonly [], QueryField = never>(partitionKeyFieldName: PK): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, never>;
|
|
18
18
|
export {};
|
|
@@ -601,6 +601,7 @@ function getAppSyncAuthDirectiveFromRule(rule) {
|
|
|
601
601
|
function mapToNativeAppSyncAuthDirectives(authorization, isCustomHandler) {
|
|
602
602
|
const rules = new Set();
|
|
603
603
|
const groupProvider = new Map();
|
|
604
|
+
const generalProviderUsed = new Set();
|
|
604
605
|
for (const entry of authorization) {
|
|
605
606
|
const rule = accessData(entry);
|
|
606
607
|
isCustomHandler && validateCustomHandlerAuthRule(rule);
|
|
@@ -612,14 +613,15 @@ function mapToNativeAppSyncAuthDirectives(authorization, isCustomHandler) {
|
|
|
612
613
|
rule.groups.forEach((group) => groupProvider.get(provider)?.add(group));
|
|
613
614
|
}
|
|
614
615
|
else {
|
|
616
|
+
generalProviderUsed.add(provider);
|
|
615
617
|
rules.add(provider);
|
|
616
618
|
}
|
|
617
619
|
}
|
|
618
620
|
groupProvider.forEach((groups, provider) => {
|
|
619
|
-
|
|
620
|
-
.
|
|
621
|
-
|
|
622
|
-
|
|
621
|
+
if (!generalProviderUsed.has(provider)) {
|
|
622
|
+
rules.add(`${provider}(cognito_groups: [${Array.from(groups).reduce((acc, group) => acc == "" ? `"${group}"` : `${acc}, "${group}"`, "")}])`);
|
|
623
|
+
// example: (cognito_groups: ["Bloggers", "Readers"])
|
|
624
|
+
}
|
|
623
625
|
});
|
|
624
626
|
const authString = [...rules].join(' ');
|
|
625
627
|
return { authString };
|
|
@@ -738,7 +740,7 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
|
|
|
738
740
|
}
|
|
739
741
|
}
|
|
740
742
|
}
|
|
741
|
-
if (!sortKeys.length && !indexName && !queryField) {
|
|
743
|
+
if (!sortKeys.length && !indexName && !queryField && queryField !== null) {
|
|
742
744
|
return `@index(queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey)}")`;
|
|
743
745
|
}
|
|
744
746
|
const attributes = [];
|
|
@@ -748,7 +750,10 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
|
|
|
748
750
|
if (sortKeys.length) {
|
|
749
751
|
attributes.push(`sortKeyFields: [${sortKeys.map((sk) => `"${sk}"`).join(', ')}]`);
|
|
750
752
|
}
|
|
751
|
-
if (queryField) {
|
|
753
|
+
if (queryField === null) {
|
|
754
|
+
attributes.push(`queryField: null`);
|
|
755
|
+
}
|
|
756
|
+
else if (queryField) {
|
|
752
757
|
attributes.push(`queryField: "${queryField}"`);
|
|
753
758
|
}
|
|
754
759
|
else {
|