@aws-amplify/data-schema 1.22.2 → 1.24.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/ModelIndex.js +9 -0
- package/dist/cjs/ModelIndex.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +14 -4
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/ai/ModelType.js +4 -0
- package/dist/cjs/ai/ModelType.js.map +1 -1
- package/dist/esm/ModelIndex.d.ts +15 -0
- package/dist/esm/ModelIndex.mjs +9 -0
- package/dist/esm/ModelIndex.mjs.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +14 -4
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/ai/ModelType.d.ts +3 -0
- package/dist/esm/ai/ModelType.mjs +4 -0
- package/dist/esm/ai/ModelType.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ModelIndex.ts +32 -0
- package/src/SchemaProcessor.ts +16 -2
- package/src/ai/ModelType.ts +4 -0
package/package.json
CHANGED
package/src/ModelIndex.ts
CHANGED
|
@@ -2,11 +2,26 @@ import { Brand, brand } from './util';
|
|
|
2
2
|
|
|
3
3
|
const brandName = 'modelIndexType';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* DynamoDB Global Secondary Index (GSI) projection types.
|
|
7
|
+
* - `KEYS_ONLY`: Only the index and primary keys are projected into the index.
|
|
8
|
+
* - `INCLUDE`: In addition to the attributes in KEYS_ONLY, includes specified non-key attributes.
|
|
9
|
+
* - `ALL`: All attributes from the base table are projected into the index.
|
|
10
|
+
*/
|
|
11
|
+
export type GSIProjectionType = 'KEYS_ONLY' | 'INCLUDE' | 'ALL';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration data for a model's secondary index.
|
|
15
|
+
*/
|
|
5
16
|
export type ModelIndexData = {
|
|
6
17
|
partitionKey: string;
|
|
7
18
|
sortKeys: readonly unknown[];
|
|
8
19
|
indexName: string;
|
|
9
20
|
queryField: string | null;
|
|
21
|
+
/** The projection type for the GSI. Defaults to 'ALL' if not specified. */
|
|
22
|
+
projectionType?: GSIProjectionType;
|
|
23
|
+
/** Non-key attributes to include when projectionType is 'INCLUDE'. */
|
|
24
|
+
nonKeyAttributes?: readonly string[];
|
|
10
25
|
};
|
|
11
26
|
|
|
12
27
|
export type InternalModelIndexType = ModelIndexType<any, any, any, any> & {
|
|
@@ -36,6 +51,13 @@ export type ModelIndexType<
|
|
|
36
51
|
>(
|
|
37
52
|
field: QF,
|
|
38
53
|
): ModelIndexType<MF, PK, SK, QF, K | 'queryField'>;
|
|
54
|
+
projection<
|
|
55
|
+
PT extends GSIProjectionType,
|
|
56
|
+
NKA extends PT extends 'INCLUDE' ? readonly string[] : never = never,
|
|
57
|
+
>(
|
|
58
|
+
type: PT,
|
|
59
|
+
...args: PT extends 'INCLUDE' ? [nonKeyAttributes: NKA] : []
|
|
60
|
+
): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, K | 'projection'>;
|
|
39
61
|
},
|
|
40
62
|
K
|
|
41
63
|
> &
|
|
@@ -52,6 +74,8 @@ function _modelIndex<
|
|
|
52
74
|
sortKeys: [],
|
|
53
75
|
indexName: '',
|
|
54
76
|
queryField: '',
|
|
77
|
+
projectionType: 'ALL',
|
|
78
|
+
nonKeyAttributes: undefined,
|
|
55
79
|
};
|
|
56
80
|
|
|
57
81
|
const builder = {
|
|
@@ -70,6 +94,14 @@ function _modelIndex<
|
|
|
70
94
|
|
|
71
95
|
return this;
|
|
72
96
|
},
|
|
97
|
+
projection(type, ...args) {
|
|
98
|
+
data.projectionType = type;
|
|
99
|
+
if (type === 'INCLUDE') {
|
|
100
|
+
data.nonKeyAttributes = args[0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this;
|
|
104
|
+
},
|
|
73
105
|
...brand(brandName),
|
|
74
106
|
} as ModelIndexType<ModelFieldKeys, PK, SK, QueryField>;
|
|
75
107
|
|
package/src/SchemaProcessor.ts
CHANGED
|
@@ -1117,6 +1117,8 @@ const transformedSecondaryIndexesForModel = (
|
|
|
1117
1117
|
sortKeys: readonly string[],
|
|
1118
1118
|
indexName: string,
|
|
1119
1119
|
queryField: string | null,
|
|
1120
|
+
projectionType?: string,
|
|
1121
|
+
nonKeyAttributes?: readonly string[],
|
|
1120
1122
|
): string => {
|
|
1121
1123
|
for (const keyName of [partitionKey, ...sortKeys]) {
|
|
1122
1124
|
const field = modelFields[keyName];
|
|
@@ -1131,7 +1133,7 @@ const transformedSecondaryIndexesForModel = (
|
|
|
1131
1133
|
}
|
|
1132
1134
|
}
|
|
1133
1135
|
|
|
1134
|
-
if (!sortKeys.length && !indexName && !queryField && queryField !== null) {
|
|
1136
|
+
if (!sortKeys.length && !indexName && !queryField && queryField !== null && !projectionType) {
|
|
1135
1137
|
return `@index(queryField: "${secondaryIndexDefaultQueryField(
|
|
1136
1138
|
modelName,
|
|
1137
1139
|
partitionKey,
|
|
@@ -1165,13 +1167,23 @@ const transformedSecondaryIndexesForModel = (
|
|
|
1165
1167
|
);
|
|
1166
1168
|
}
|
|
1167
1169
|
|
|
1170
|
+
// Add projection attributes if specified
|
|
1171
|
+
if (projectionType && projectionType !== 'ALL') {
|
|
1172
|
+
if (projectionType === 'KEYS_ONLY') {
|
|
1173
|
+
attributes.push(`projection: { type: KEYS_ONLY }`);
|
|
1174
|
+
} else if (projectionType === 'INCLUDE' && nonKeyAttributes?.length) {
|
|
1175
|
+
const nonKeyAttrsStr = nonKeyAttributes.map(attr => `"${attr}"`).join(', ');
|
|
1176
|
+
attributes.push(`projection: { type: INCLUDE, nonKeyAttributes: [${nonKeyAttrsStr}] }`);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1168
1180
|
return `@index(${attributes.join(', ')})`;
|
|
1169
1181
|
};
|
|
1170
1182
|
|
|
1171
1183
|
return secondaryIndexes.reduce(
|
|
1172
1184
|
(
|
|
1173
1185
|
acc: TransformedSecondaryIndexes,
|
|
1174
|
-
{ data: { partitionKey, sortKeys, indexName, queryField } },
|
|
1186
|
+
{ data: { partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes } },
|
|
1175
1187
|
) => {
|
|
1176
1188
|
acc[partitionKey] = acc[partitionKey] || [];
|
|
1177
1189
|
acc[partitionKey].push(
|
|
@@ -1180,6 +1192,8 @@ const transformedSecondaryIndexesForModel = (
|
|
|
1180
1192
|
sortKeys as readonly string[],
|
|
1181
1193
|
indexName,
|
|
1182
1194
|
queryField,
|
|
1195
|
+
projectionType,
|
|
1196
|
+
nonKeyAttributes,
|
|
1183
1197
|
),
|
|
1184
1198
|
);
|
|
1185
1199
|
|
package/src/ai/ModelType.ts
CHANGED
|
@@ -18,6 +18,10 @@ const supportedModelsLookup = {
|
|
|
18
18
|
'Claude 3.7 Sonnet': 'anthropic.claude-3-7-sonnet-20250219-v1:0',
|
|
19
19
|
'Claude Opus 4': 'anthropic.claude-opus-4-20250514-v1:0',
|
|
20
20
|
'Claude Sonnet 4': 'anthropic.claude-sonnet-4-20250514-v1:0',
|
|
21
|
+
// Claude 4.5 models (require global inference profiles)
|
|
22
|
+
'Claude Haiku 4.5': 'global.anthropic.claude-haiku-4-5-20251001-v1:0',
|
|
23
|
+
'Claude Sonnet 4.5': 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
24
|
+
'Claude Opus 4.5': 'global.anthropic.claude-opus-4-5-20251101-v1:0',
|
|
21
25
|
// Cohere models
|
|
22
26
|
'Cohere Command R': 'cohere.command-r-v1:0',
|
|
23
27
|
'Cohere Command R+': 'cohere.command-r-plus-v1:0',
|