@resistdesign/voltra 3.0.0-alpha.52 → 3.0.0-alpha.54

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.
@@ -69,6 +69,10 @@ export type RetryStrategy = {
69
69
  * DynamoDB client configuration subset for generated docs.
70
70
  */
71
71
  export type DynamoDBSpecificConfig = {
72
+ /**
73
+ * When true, the first sort field is treated as the DynamoDB index name.
74
+ */
75
+ useFirstSortFieldAsIndexName?: boolean;
72
76
  /**
73
77
  * Custom request handler override.
74
78
  */
@@ -1,14 +1,16 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * DynamoDB-backed data item driver for TypeInfo ORM. Supports CRUD and scan-based
5
- * list operations with SearchCriteria filters.
4
+ * DynamoDB-backed data item driver for TypeInfo ORM. Supports CRUD and list
5
+ * operations using scans by default, with optional GSI-backed queries when the
6
+ * first sort field is configured to act as an index name.
6
7
  */
7
8
  import { DataItemDBDriver, DataItemDBDriverConfig, SupportedDataItemDBDriverEntry } from "./common/Types";
8
9
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
9
10
  import { TypeInfoDataItem } from "../../../common/TypeParsing/TypeInfo";
10
11
  import { TypeInfoORMUpdateConfig } from "../../../common/TypeInfoORM";
11
12
  import { ListItemsConfig, ListItemsResults } from "../../../common/SearchTypes";
13
+ import type { DynamoDBSpecificConfig } from "./DynamoDBDataItemDBDriver/ConfigTypes";
12
14
  /**
13
15
  * A {@link DataItemDBDriver} that uses DynamoDB as its database.
14
16
  * */
@@ -18,6 +20,7 @@ export declare class DynamoDBDataItemDBDriver<ItemType extends TypeInfoDataItem,
18
20
  */
19
21
  protected config: DataItemDBDriverConfig<ItemType, UniquelyIdentifyingFieldName>;
20
22
  protected dynamoDBClient: DynamoDBClient;
23
+ protected specificConfig: DynamoDBSpecificConfig;
21
24
  /**
22
25
  * @param config Driver configuration including DynamoDB client settings.
23
26
  */
package/api/index.js CHANGED
@@ -5429,6 +5429,13 @@ var ConfigTypeInfoMap_default2 = {
5429
5429
  },
5430
5430
  DynamoDBSpecificConfig: {
5431
5431
  fields: {
5432
+ useFirstSortFieldAsIndexName: {
5433
+ type: "boolean",
5434
+ array: false,
5435
+ readonly: false,
5436
+ optional: true,
5437
+ tags: {}
5438
+ },
5432
5439
  requestHandler: {
5433
5440
  type: "string",
5434
5441
  array: false,
@@ -5843,11 +5850,14 @@ var DynamoDBDataItemDBDriver = class {
5843
5850
  constructor(config) {
5844
5851
  this.config = config;
5845
5852
  const { dbSpecificConfig } = config;
5846
- this.dynamoDBClient = new DynamoDBClient(
5847
- dbSpecificConfig
5848
- );
5853
+ const { useFirstSortFieldAsIndexName, ...clientConfig } = dbSpecificConfig ?? {};
5854
+ this.specificConfig = {
5855
+ useFirstSortFieldAsIndexName
5856
+ };
5857
+ this.dynamoDBClient = new DynamoDBClient(clientConfig);
5849
5858
  }
5850
5859
  dynamoDBClient;
5860
+ specificConfig;
5851
5861
  /**
5852
5862
  * Create an item in the database.
5853
5863
  * @returns Generated identifier for the created item.
@@ -5964,6 +5974,8 @@ var DynamoDBDataItemDBDriver = class {
5964
5974
  ExpressionAttributeNames,
5965
5975
  ExpressionAttributeValues
5966
5976
  } = createFilterExpression(fieldCriteria, logicalOperator);
5977
+ const primarySortField = sortFields?.[0];
5978
+ const indexName = this.specificConfig.useFirstSortFieldAsIndexName ? primarySortField?.field : void 0;
5967
5979
  const params = {
5968
5980
  TableName: tableName,
5969
5981
  Select: selectedFields && selectedFields.length > 0 ? "SPECIFIC_ATTRIBUTES" : "ALL_ATTRIBUTES",
@@ -5998,14 +6010,24 @@ var DynamoDBDataItemDBDriver = class {
5998
6010
  };
5999
6011
  }
6000
6012
  }
6001
- const command = new ScanCommand({
6013
+ const commandInput = indexName ? {
6014
+ ...params,
6015
+ IndexName: indexName,
6016
+ KeyConditionExpression: FilterExpression,
6017
+ ExclusiveStartKey: structuredCursor,
6018
+ Limit: itemsPerPage,
6019
+ ScanIndexForward: !primarySortField?.reverse
6020
+ } : {
6002
6021
  ...params,
6003
6022
  ExclusiveStartKey: structuredCursor,
6004
6023
  Limit: itemsPerPage
6005
- });
6006
- const { Items = [], LastEvaluatedKey } = await this.dynamoDBClient.send(command);
6024
+ };
6025
+ const command = indexName ? new QueryCommand(commandInput) : new ScanCommand(commandInput);
6026
+ const { Items = [], LastEvaluatedKey } = await this.dynamoDBClient.send(
6027
+ command
6028
+ );
6007
6029
  const unmarshalledItems = Items.map((item) => unmarshall(item));
6008
- const sortedItems = getSortedItems(sortFields, unmarshalledItems);
6030
+ const sortedItems = indexName ? unmarshalledItems : getSortedItems(sortFields, unmarshalledItems);
6009
6031
  return {
6010
6032
  items: sortedItems,
6011
6033
  cursor: LastEvaluatedKey ? JSON.stringify(unmarshall(LastEvaluatedKey)) : void 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resistdesign/voltra",
3
- "version": "3.0.0-alpha.52",
3
+ "version": "3.0.0-alpha.54",
4
4
  "description": "With our powers combined!",
5
5
  "homepage": "https://voltra.app",
6
6
  "repository": "git@github.com:resistdesign/voltra.git",