@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.
@@ -19,6 +19,10 @@ const supportedModelsLookup = {
19
19
  'Claude 3.7 Sonnet': 'anthropic.claude-3-7-sonnet-20250219-v1:0',
20
20
  'Claude Opus 4': 'anthropic.claude-opus-4-20250514-v1:0',
21
21
  'Claude Sonnet 4': 'anthropic.claude-sonnet-4-20250514-v1:0',
22
+ // Claude 4.5 models (require global inference profiles)
23
+ 'Claude Haiku 4.5': 'global.anthropic.claude-haiku-4-5-20251001-v1:0',
24
+ 'Claude Sonnet 4.5': 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',
25
+ 'Claude Opus 4.5': 'global.anthropic.claude-opus-4-5-20251101-v1:0',
22
26
  // Cohere models
23
27
  'Cohere Command R': 'cohere.command-r-v1:0',
24
28
  'Cohere Command R+': 'cohere.command-r-plus-v1:0',
@@ -1 +1 @@
1
- {"version":3,"file":"ModelType.js","sources":["../../../src/ai/ModelType.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.model = model;\nconst supportedModelsLookup = {\n // Amazon Nova models\n 'Amazon Nova Pro': 'amazon.nova-pro-v1:0',\n 'Amazon Nova Lite': 'amazon.nova-lite-v1:0',\n 'Amazon Nova Micro': 'amazon.nova-micro-v1:0',\n // Anthropic models\n 'Claude 3 Haiku': 'anthropic.claude-3-haiku-20240307-v1:0',\n 'Claude 3 Opus': 'anthropic.claude-3-opus-20240229-v1:0',\n 'Claude 3 Sonnet': 'anthropic.claude-3-sonnet-20240229-v1:0',\n 'Claude 3.5 Haiku': 'anthropic.claude-3-5-haiku-20241022-v1:0',\n 'Claude 3.5 Sonnet': 'anthropic.claude-3-5-sonnet-20240620-v1:0',\n 'Claude 3.5 Sonnet v2': 'anthropic.claude-3-5-sonnet-20241022-v2:0',\n 'Claude 3.7 Sonnet': 'anthropic.claude-3-7-sonnet-20250219-v1:0',\n 'Claude Opus 4': 'anthropic.claude-opus-4-20250514-v1:0',\n 'Claude Sonnet 4': 'anthropic.claude-sonnet-4-20250514-v1:0',\n // Cohere models\n 'Cohere Command R': 'cohere.command-r-v1:0',\n 'Cohere Command R+': 'cohere.command-r-plus-v1:0',\n // Meta models\n 'Llama 3.1 8B Instruct': 'meta.llama3-1-8b-instruct-v1:0',\n 'Llama 3.1 70B Instruct': 'meta.llama3-1-70b-instruct-v1:0',\n 'Llama 3.1 405B Instruct': 'meta.llama3-1-405b-instruct-v1:0',\n // Mistral AI models\n 'Mistral Large': 'mistral.mistral-large-2402-v1:0',\n 'Mistral Large 2': 'mistral.mistral-large-2407-v1:0',\n 'Mistral Small': 'mistral.mistral-small-2402-v1:0',\n};\n/**\n * Bedrock models currently supporting Converse API and Tool use\n * @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#conversation-inference-supported-models-features}\n */\nfunction model(modelName) {\n return {\n resourcePath: supportedModelsLookup[modelName],\n };\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,KAAK;AACrB,MAAM,qBAAqB,GAAG;AAC9B;AACA,IAAI,iBAAiB,EAAE,sBAAsB;AAC7C,IAAI,kBAAkB,EAAE,uBAAuB;AAC/C,IAAI,mBAAmB,EAAE,wBAAwB;AACjD;AACA,IAAI,gBAAgB,EAAE,wCAAwC;AAC9D,IAAI,eAAe,EAAE,uCAAuC;AAC5D,IAAI,iBAAiB,EAAE,yCAAyC;AAChE,IAAI,kBAAkB,EAAE,0CAA0C;AAClE,IAAI,mBAAmB,EAAE,2CAA2C;AACpE,IAAI,sBAAsB,EAAE,2CAA2C;AACvE,IAAI,mBAAmB,EAAE,2CAA2C;AACpE,IAAI,eAAe,EAAE,uCAAuC;AAC5D,IAAI,iBAAiB,EAAE,yCAAyC;AAChE;AACA,IAAI,kBAAkB,EAAE,uBAAuB;AAC/C,IAAI,mBAAmB,EAAE,4BAA4B;AACrD;AACA,IAAI,uBAAuB,EAAE,gCAAgC;AAC7D,IAAI,wBAAwB,EAAE,iCAAiC;AAC/D,IAAI,yBAAyB,EAAE,kCAAkC;AACjE;AACA,IAAI,eAAe,EAAE,iCAAiC;AACtD,IAAI,iBAAiB,EAAE,iCAAiC;AACxD,IAAI,eAAe,EAAE,iCAAiC;AACtD,CAAC;AACD;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,SAAS,EAAE;AAC1B,IAAI,OAAO;AACX,QAAQ,YAAY,EAAE,qBAAqB,CAAC,SAAS,CAAC;AACtD,KAAK;AACL;;"}
1
+ {"version":3,"file":"ModelType.js","sources":["../../../src/ai/ModelType.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.model = model;\nconst supportedModelsLookup = {\n // Amazon Nova models\n 'Amazon Nova Pro': 'amazon.nova-pro-v1:0',\n 'Amazon Nova Lite': 'amazon.nova-lite-v1:0',\n 'Amazon Nova Micro': 'amazon.nova-micro-v1:0',\n // Anthropic models\n 'Claude 3 Haiku': 'anthropic.claude-3-haiku-20240307-v1:0',\n 'Claude 3 Opus': 'anthropic.claude-3-opus-20240229-v1:0',\n 'Claude 3 Sonnet': 'anthropic.claude-3-sonnet-20240229-v1:0',\n 'Claude 3.5 Haiku': 'anthropic.claude-3-5-haiku-20241022-v1:0',\n 'Claude 3.5 Sonnet': 'anthropic.claude-3-5-sonnet-20240620-v1:0',\n 'Claude 3.5 Sonnet v2': 'anthropic.claude-3-5-sonnet-20241022-v2:0',\n 'Claude 3.7 Sonnet': 'anthropic.claude-3-7-sonnet-20250219-v1:0',\n 'Claude Opus 4': 'anthropic.claude-opus-4-20250514-v1:0',\n 'Claude Sonnet 4': 'anthropic.claude-sonnet-4-20250514-v1:0',\n // Claude 4.5 models (require global inference profiles)\n 'Claude Haiku 4.5': 'global.anthropic.claude-haiku-4-5-20251001-v1:0',\n 'Claude Sonnet 4.5': 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',\n 'Claude Opus 4.5': 'global.anthropic.claude-opus-4-5-20251101-v1:0',\n // Cohere models\n 'Cohere Command R': 'cohere.command-r-v1:0',\n 'Cohere Command R+': 'cohere.command-r-plus-v1:0',\n // Meta models\n 'Llama 3.1 8B Instruct': 'meta.llama3-1-8b-instruct-v1:0',\n 'Llama 3.1 70B Instruct': 'meta.llama3-1-70b-instruct-v1:0',\n 'Llama 3.1 405B Instruct': 'meta.llama3-1-405b-instruct-v1:0',\n // Mistral AI models\n 'Mistral Large': 'mistral.mistral-large-2402-v1:0',\n 'Mistral Large 2': 'mistral.mistral-large-2407-v1:0',\n 'Mistral Small': 'mistral.mistral-small-2402-v1:0',\n};\n/**\n * Bedrock models currently supporting Converse API and Tool use\n * @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#conversation-inference-supported-models-features}\n */\nfunction model(modelName) {\n return {\n resourcePath: supportedModelsLookup[modelName],\n };\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,KAAK;AACrB,MAAM,qBAAqB,GAAG;AAC9B;AACA,IAAI,iBAAiB,EAAE,sBAAsB;AAC7C,IAAI,kBAAkB,EAAE,uBAAuB;AAC/C,IAAI,mBAAmB,EAAE,wBAAwB;AACjD;AACA,IAAI,gBAAgB,EAAE,wCAAwC;AAC9D,IAAI,eAAe,EAAE,uCAAuC;AAC5D,IAAI,iBAAiB,EAAE,yCAAyC;AAChE,IAAI,kBAAkB,EAAE,0CAA0C;AAClE,IAAI,mBAAmB,EAAE,2CAA2C;AACpE,IAAI,sBAAsB,EAAE,2CAA2C;AACvE,IAAI,mBAAmB,EAAE,2CAA2C;AACpE,IAAI,eAAe,EAAE,uCAAuC;AAC5D,IAAI,iBAAiB,EAAE,yCAAyC;AAChE;AACA,IAAI,kBAAkB,EAAE,iDAAiD;AACzE,IAAI,mBAAmB,EAAE,kDAAkD;AAC3E,IAAI,iBAAiB,EAAE,gDAAgD;AACvE;AACA,IAAI,kBAAkB,EAAE,uBAAuB;AAC/C,IAAI,mBAAmB,EAAE,4BAA4B;AACrD;AACA,IAAI,uBAAuB,EAAE,gCAAgC;AAC7D,IAAI,wBAAwB,EAAE,iCAAiC;AAC/D,IAAI,yBAAyB,EAAE,kCAAkC;AACjE;AACA,IAAI,eAAe,EAAE,iCAAiC;AACtD,IAAI,iBAAiB,EAAE,iCAAiC;AACxD,IAAI,eAAe,EAAE,iCAAiC;AACtD,CAAC;AACD;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,SAAS,EAAE;AAC1B,IAAI,OAAO;AACX,QAAQ,YAAY,EAAE,qBAAqB,CAAC,SAAS,CAAC;AACtD,KAAK;AACL;;"}
@@ -1,10 +1,24 @@
1
1
  import { Brand } from './util';
2
2
  declare const brandName = "modelIndexType";
3
+ /**
4
+ * DynamoDB Global Secondary Index (GSI) projection types.
5
+ * - `KEYS_ONLY`: Only the index and primary keys are projected into the index.
6
+ * - `INCLUDE`: In addition to the attributes in KEYS_ONLY, includes specified non-key attributes.
7
+ * - `ALL`: All attributes from the base table are projected into the index.
8
+ */
9
+ export type GSIProjectionType = 'KEYS_ONLY' | 'INCLUDE' | 'ALL';
10
+ /**
11
+ * Configuration data for a model's secondary index.
12
+ */
3
13
  export type ModelIndexData = {
4
14
  partitionKey: string;
5
15
  sortKeys: readonly unknown[];
6
16
  indexName: string;
7
17
  queryField: string | null;
18
+ /** The projection type for the GSI. Defaults to 'ALL' if not specified. */
19
+ projectionType?: GSIProjectionType;
20
+ /** Non-key attributes to include when projectionType is 'INCLUDE'. */
21
+ nonKeyAttributes?: readonly string[];
8
22
  };
9
23
  export type InternalModelIndexType = ModelIndexType<any, any, any, any> & {
10
24
  data: ModelIndexData;
@@ -13,6 +27,7 @@ export type ModelIndexType<ModelFieldKeys extends string, PK, SK = readonly [],
13
27
  sortKeys<FieldKeys extends ModelFieldKeys = ModelFieldKeys, const SK extends ReadonlyArray<Exclude<FieldKeys, PK>> = readonly []>(sortKeys: SK): ModelIndexType<FieldKeys, PK, SK, QueryField, K | 'sortKeys'>;
14
28
  name(name: string): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, K | 'name'>;
15
29
  queryField<QF extends string | null = never, MF extends ModelFieldKeys = ModelFieldKeys>(field: QF): ModelIndexType<MF, PK, SK, QF, K | 'queryField'>;
30
+ projection<PT extends GSIProjectionType, NKA extends PT extends 'INCLUDE' ? readonly string[] : never = never>(type: PT, ...args: PT extends 'INCLUDE' ? [nonKeyAttributes: NKA] : []): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, K | 'projection'>;
16
31
  }, K> & Brand<typeof brandName>;
17
32
  export declare function modelIndex<ModelFieldKeys extends string, PK extends ModelFieldKeys, SK = readonly [], QueryField = never>(partitionKeyFieldName: PK): ModelIndexType<ModelFieldKeys, PK, SK, QueryField, never>;
18
33
  export {};
@@ -7,6 +7,8 @@ function _modelIndex(partitionKeyFieldName) {
7
7
  sortKeys: [],
8
8
  indexName: '',
9
9
  queryField: '',
10
+ projectionType: 'ALL',
11
+ nonKeyAttributes: undefined,
10
12
  };
11
13
  const builder = {
12
14
  sortKeys(sortKeys) {
@@ -21,6 +23,13 @@ function _modelIndex(partitionKeyFieldName) {
21
23
  data.queryField = field;
22
24
  return this;
23
25
  },
26
+ projection(type, ...args) {
27
+ data.projectionType = type;
28
+ if (type === 'INCLUDE') {
29
+ data.nonKeyAttributes = args[0];
30
+ }
31
+ return this;
32
+ },
24
33
  ...brand(brandName),
25
34
  };
26
35
  return { ...builder, data };
@@ -1 +1 @@
1
- {"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACO,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAClD,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;;;"}
1
+ {"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n projectionType: 'ALL',\n nonKeyAttributes: undefined,\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n projection(type, ...args) {\n data.projectionType = type;\n if (type === 'INCLUDE') {\n data.nonKeyAttributes = args[0];\n }\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,QAAQ,cAAc,EAAE,KAAK;AAC7B,QAAQ,gBAAgB,EAAE,SAAS;AACnC,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE;AAClC,YAAY,IAAI,CAAC,cAAc,GAAG,IAAI;AACtC,YAAY,IAAI,IAAI,KAAK,SAAS,EAAE;AACpC,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC;AAC/C;AACA,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACO,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAClD,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;;;"}
@@ -730,7 +730,7 @@ const secondaryIndexDefaultQueryField = (modelName, pk, sk) => {
730
730
  * and the value is an array of transformed Amplify @index directives with all supplied attributes
731
731
  */
732
732
  const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelFields, getRefType) => {
733
- const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField) => {
733
+ const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes) => {
734
734
  for (const keyName of [partitionKey, ...sortKeys]) {
735
735
  const field = modelFields[keyName];
736
736
  if (isRefField(field)) {
@@ -740,7 +740,7 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
740
740
  }
741
741
  }
742
742
  }
743
- if (!sortKeys.length && !indexName && !queryField && queryField !== null) {
743
+ if (!sortKeys.length && !indexName && !queryField && queryField !== null && !projectionType) {
744
744
  return `@index(queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey)}")`;
745
745
  }
746
746
  const attributes = [];
@@ -759,11 +759,21 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
759
759
  else {
760
760
  attributes.push(`queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey, sortKeys)}"`);
761
761
  }
762
+ // Add projection attributes if specified
763
+ if (projectionType && projectionType !== 'ALL') {
764
+ if (projectionType === 'KEYS_ONLY') {
765
+ attributes.push(`projection: { type: KEYS_ONLY }`);
766
+ }
767
+ else if (projectionType === 'INCLUDE' && nonKeyAttributes?.length) {
768
+ const nonKeyAttrsStr = nonKeyAttributes.map(attr => `"${attr}"`).join(', ');
769
+ attributes.push(`projection: { type: INCLUDE, nonKeyAttributes: [${nonKeyAttrsStr}] }`);
770
+ }
771
+ }
762
772
  return `@index(${attributes.join(', ')})`;
763
773
  };
764
- return secondaryIndexes.reduce((acc, { data: { partitionKey, sortKeys, indexName, queryField } }) => {
774
+ return secondaryIndexes.reduce((acc, { data: { partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes } }) => {
765
775
  acc[partitionKey] = acc[partitionKey] || [];
766
- acc[partitionKey].push(indexDirectiveWithAttributes(partitionKey, sortKeys, indexName, queryField));
776
+ acc[partitionKey].push(indexDirectiveWithAttributes(partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes));
767
777
  return acc;
768
778
  }, {});
769
779
  };