dyno-table 2.5.1 → 2.6.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.
Files changed (58) hide show
  1. package/dist/builders/batch-builder.d.ts +249 -0
  2. package/dist/builders/builder-types.d.ts +123 -0
  3. package/dist/builders/condition-check-builder.d.ts +149 -0
  4. package/dist/builders/delete-builder.d.ts +208 -0
  5. package/dist/builders/entity-aware-builders.d.ts +127 -0
  6. package/dist/builders/filter-builder.d.ts +294 -0
  7. package/dist/builders/get-builder.d.ts +191 -0
  8. package/dist/builders/index.d.ts +14 -0
  9. package/dist/builders/paginator.d.ts +151 -0
  10. package/dist/builders/put-builder.d.ts +317 -0
  11. package/dist/builders/query-builder.d.ts +218 -0
  12. package/dist/builders/result-iterator.d.ts +55 -0
  13. package/dist/builders/scan-builder.d.ts +109 -0
  14. package/dist/builders/transaction-builder.d.ts +462 -0
  15. package/dist/builders/types.d.ts +25 -0
  16. package/dist/builders/update-builder.d.ts +372 -0
  17. package/dist/builders.d.ts +1 -4
  18. package/dist/{chunk-U6MQGB6Y.js → chunk-JZB6TYST.js} +133 -136
  19. package/dist/{chunk-ZXM6LPRV.cjs → chunk-Z334X72N.cjs} +133 -136
  20. package/dist/conditions.d.ts +705 -3
  21. package/dist/entity/ddb-indexing.d.ts +45 -0
  22. package/dist/entity/entity.d.ts +188 -0
  23. package/dist/entity/index-utils.d.ts +24 -0
  24. package/dist/entity.cjs +4 -4
  25. package/dist/entity.d.ts +1 -261
  26. package/dist/entity.js +1 -1
  27. package/dist/errors.d.ts +212 -0
  28. package/dist/expression.d.ts +9 -0
  29. package/dist/index-definition.d.ts +10 -0
  30. package/dist/index.cjs +25 -25
  31. package/dist/index.d.ts +16 -273
  32. package/dist/index.js +1 -1
  33. package/dist/operation-types.d.ts +8 -0
  34. package/dist/standard-schema.d.ts +2 -4
  35. package/dist/table.d.ts +13 -8
  36. package/dist/types.d.ts +6 -9
  37. package/dist/utils/chunk-array.d.ts +9 -0
  38. package/dist/utils/debug-expression.d.ts +32 -0
  39. package/dist/utils/debug-transaction.d.ts +17 -0
  40. package/dist/utils/error-factory.d.ts +162 -0
  41. package/dist/utils/error-utils.d.ts +170 -0
  42. package/dist/utils/index.d.ts +7 -0
  43. package/dist/utils/partition-key-template.d.ts +30 -0
  44. package/dist/utils/sort-key-template.d.ts +33 -0
  45. package/dist/utils.d.ts +1 -66
  46. package/package.json +12 -10
  47. package/dist/builders.d.cts +0 -4
  48. package/dist/conditions-BSAcZswY.d.ts +0 -731
  49. package/dist/conditions-C8bM__Pn.d.cts +0 -731
  50. package/dist/conditions.d.cts +0 -3
  51. package/dist/entity.d.cts +0 -261
  52. package/dist/index-Bc-ra0im.d.ts +0 -3042
  53. package/dist/index-CPCmWsEv.d.cts +0 -3042
  54. package/dist/index.d.cts +0 -273
  55. package/dist/standard-schema.d.cts +0 -57
  56. package/dist/table.d.cts +0 -165
  57. package/dist/types.d.cts +0 -29
  58. package/dist/utils.d.cts +0 -66
@@ -0,0 +1,8 @@
1
+ import type { PrimaryKeyWithoutExpression } from "./conditions";
2
+ export type BatchWriteOperation<T extends Record<string, unknown>> = {
3
+ type: "put";
4
+ item: T;
5
+ } | {
6
+ type: "delete";
7
+ key: PrimaryKeyWithoutExpression;
8
+ };
@@ -1,9 +1,9 @@
1
1
  /** The Standard Schema interface. */
2
- interface StandardSchemaV1<Input = unknown, Output = Input> {
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
3
  /** The Standard Schema properties. */
4
4
  readonly "~standard": StandardSchemaV1.Props<Input, Output>;
5
5
  }
6
- declare namespace StandardSchemaV1 {
6
+ export declare namespace StandardSchemaV1 {
7
7
  /** The Standard Schema properties interface. */
8
8
  interface Props<Input = unknown, Output = Input> {
9
9
  /** The version number of the standard. */
@@ -53,5 +53,3 @@ declare namespace StandardSchemaV1 {
53
53
  /** Infers the output type of a Standard Schema. */
54
54
  type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
55
55
  }
56
-
57
- export { StandardSchemaV1 };
package/dist/table.d.ts CHANGED
@@ -1,9 +1,16 @@
1
- import { P as PutBuilder, G as GetBuilder, Q as QueryBuilder, S as ScanBuilder, D as DeleteBuilder, U as UpdateBuilder, T as TransactionBuilder, B as BatchBuilder, a as TransactionOptions, C as ConditionCheckBuilder, b as BatchWriteOperation } from './index-Bc-ra0im.js';
2
- import { P as PrimaryKeyWithoutExpression, a as PrimaryKey } from './conditions-BSAcZswY.js';
3
- import { TableConfig, Index, DynamoItem } from './types.js';
4
- import '@aws-sdk/lib-dynamodb';
5
-
6
- declare class Table<TConfig extends TableConfig = TableConfig> {
1
+ import { BatchBuilder } from "./builders/batch-builder";
2
+ import { ConditionCheckBuilder } from "./builders/condition-check-builder";
3
+ import { DeleteBuilder } from "./builders/delete-builder";
4
+ import { GetBuilder } from "./builders/get-builder";
5
+ import { PutBuilder } from "./builders/put-builder";
6
+ import { QueryBuilder } from "./builders/query-builder";
7
+ import { ScanBuilder } from "./builders/scan-builder";
8
+ import { TransactionBuilder, type TransactionOptions } from "./builders/transaction-builder";
9
+ import { UpdateBuilder } from "./builders/update-builder";
10
+ import { type PrimaryKey, type PrimaryKeyWithoutExpression } from "./conditions";
11
+ import type { BatchWriteOperation } from "./operation-types";
12
+ import type { DynamoItem, Index, TableConfig } from "./types";
13
+ export declare class Table<TConfig extends TableConfig = TableConfig> {
7
14
  private readonly dynamoClient;
8
15
  readonly tableName: string;
9
16
  /**
@@ -161,5 +168,3 @@ declare class Table<TConfig extends TableConfig = TableConfig> {
161
168
  unprocessedItems: Array<BatchWriteOperation<T>>;
162
169
  }>;
163
170
  }
164
-
165
- export { Table };
package/dist/types.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
2
-
3
- type DynamoItem = {
1
+ import type { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
2
+ export type DynamoItem = {
4
3
  [key: string]: unknown;
5
4
  };
6
- interface Index<T extends DynamoItem = DynamoItem> {
5
+ export interface Index<T extends DynamoItem = DynamoItem> {
7
6
  partitionKey: string;
8
7
  sortKey?: string;
9
8
  /** Function to generate the index key from an item */
@@ -14,16 +13,14 @@ interface Index<T extends DynamoItem = DynamoItem> {
14
13
  /** Whether the index is read-only */
15
14
  isReadOnly?: boolean;
16
15
  }
17
- interface IndexConfig {
16
+ export interface IndexConfig {
18
17
  partitionKey: string;
19
18
  sortKey?: string;
20
19
  gsis?: Record<string, Index>;
21
20
  }
22
- interface TableConfig {
21
+ export interface TableConfig {
23
22
  client: DynamoDBDocument;
24
23
  tableName: string;
25
24
  indexes: IndexConfig;
26
25
  }
27
- type GSINames<T extends TableConfig> = keyof NonNullable<T["indexes"]["gsis"]>;
28
-
29
- export type { DynamoItem, GSINames, Index, IndexConfig, TableConfig };
26
+ export type GSINames<T extends TableConfig> = keyof NonNullable<T["indexes"]["gsis"]>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generator function to create chunks of an array on-demand
3
+ * This is more memory-efficient than creating all chunks at once
4
+ *
5
+ * @param array The array to chunk
6
+ * @param size The size of each chunk
7
+ * @returns A generator that yields chunks of the array
8
+ */
9
+ export declare function chunkArray<T>(array: T[], size: number): Generator<T[], void, unknown>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Interface for DynamoDB command objects that can contain expressions
3
+ */
4
+ export interface DynamoCommandWithExpressions {
5
+ conditionExpression?: string;
6
+ updateExpression?: string;
7
+ filterExpression?: string;
8
+ keyConditionExpression?: string;
9
+ projectionExpression?: string;
10
+ expressionAttributeNames?: Record<string, string>;
11
+ expressionAttributeValues?: Record<string, unknown>;
12
+ [key: string]: unknown;
13
+ }
14
+ type ReadableDynamoCommand = {
15
+ conditionExpression?: string;
16
+ updateExpression?: string;
17
+ filterExpression?: string;
18
+ keyConditionExpression?: string;
19
+ projectionExpression?: string;
20
+ };
21
+ /**
22
+ * Utility function to debug a DynamoDB command by replacing all placeholders
23
+ * in expressions with their actual values.
24
+ *
25
+ * @param command Any DynamoDB command with expressions and attribute maps
26
+ * @returns An object with the same structure but with readable expressions
27
+ */
28
+ export declare function debugCommand<T extends DynamoCommandWithExpressions>(command: T): {
29
+ raw: T;
30
+ readable: ReadableDynamoCommand;
31
+ };
32
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { TransactionItem } from "../builders/builder-types";
2
+ /**
3
+ * Utility function to create a human-readable representation of a transaction item
4
+ * by replacing all expression placeholders with their actual values.
5
+ *
6
+ * @param item The transaction item to debug
7
+ * @returns A readable representation of the transaction item
8
+ */
9
+ export declare function debugTransactionItem(item: TransactionItem): Record<string, unknown>;
10
+ /**
11
+ * Utility function to create a human-readable representation of all transaction items
12
+ * in a transaction by replacing all expression placeholders with their actual values.
13
+ *
14
+ * @param items Array of transaction items to debug
15
+ * @returns An array of readable representations of the transaction items
16
+ */
17
+ export declare function debugTransaction(items: TransactionItem[]): Record<string, unknown>[];
@@ -0,0 +1,162 @@
1
+ import { BatchError, ConfigurationError, EntityValidationError, ExpressionError, IndexGenerationError, KeyGenerationError, OperationError, TransactionError, ValidationError } from "../errors";
2
+ /**
3
+ * Factory functions for Expression errors
4
+ */
5
+ export declare const ExpressionErrors: {
6
+ missingAttribute: (conditionType: string, condition: unknown) => ExpressionError;
7
+ missingValue: (conditionType: string, condition: unknown) => ExpressionError;
8
+ invalidCondition: (conditionType: string, condition: unknown, suggestion?: string) => ExpressionError;
9
+ emptyArray: (conditionType: string, providedValue: unknown) => ExpressionError;
10
+ unknownType: (conditionType: string, condition: unknown) => ExpressionError;
11
+ };
12
+ /**
13
+ * Factory functions for Validation errors
14
+ */
15
+ export declare const ValidationErrors: {
16
+ indexSchemaValidationFailed: (validationIssues: unknown, keyType: "partition" | "sort" | "both") => ValidationError;
17
+ noUpdateActions: (tableName: string, key: Record<string, unknown>) => ValidationError;
18
+ conditionRequired: (tableName: string, key: Record<string, unknown>) => ValidationError;
19
+ queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => ValidationError;
20
+ undefinedValue: (path: string, tableName: string, key: Record<string, unknown>) => ValidationError;
21
+ };
22
+ /**
23
+ * Factory functions for Configuration errors
24
+ */
25
+ export declare const ConfigurationErrors: {
26
+ invalidChunkSize: (size: number) => ConfigurationError;
27
+ sortKeyRequired: (tableName: string, partitionKey: string, sortKey?: string) => ConfigurationError;
28
+ sortKeyNotDefined: (tableName: string, partitionKey: string, indexName?: string) => ConfigurationError;
29
+ gsiNotFound: (indexName: string, tableName: string, availableIndexes: string[]) => ConfigurationError;
30
+ primaryKeyMissing: (tableName: string, partitionKeyName: string, providedItem: unknown) => ConfigurationError;
31
+ pkExtractionFailed: (tableName: string, indexName: string, item: unknown, cause?: Error) => ConfigurationError;
32
+ conditionGenerationFailed: (condition: unknown, suggestion?: string) => ExpressionError;
33
+ };
34
+ /**
35
+ * Factory functions for Operation errors
36
+ */
37
+ export declare const OperationErrors: {
38
+ queryFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
39
+ scanFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
40
+ getFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
41
+ putFailed: (tableName: string, item: unknown, cause?: Error) => OperationError;
42
+ updateFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
43
+ deleteFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
44
+ batchGetFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
45
+ batchWriteFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
46
+ };
47
+ /**
48
+ * Factory functions for Transaction errors
49
+ */
50
+ export declare const TransactionErrors: {
51
+ transactionFailed: (itemCount: number, context: Record<string, unknown>, cause?: Error) => TransactionError;
52
+ duplicateItem: (tableName: string, partitionKey: {
53
+ name: string;
54
+ value: unknown;
55
+ }, sortKey?: {
56
+ name: string;
57
+ value: unknown;
58
+ }) => TransactionError;
59
+ transactionEmpty: () => TransactionError;
60
+ unsupportedType: (item: unknown) => TransactionError;
61
+ };
62
+ /**
63
+ * Factory functions for Batch errors
64
+ */
65
+ export declare const BatchErrors: {
66
+ batchEmpty: (operation: "write" | "read") => BatchError;
67
+ unsupportedType: (operation: "write" | "read", item: unknown) => BatchError;
68
+ batchWriteFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
69
+ batchGetFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
70
+ };
71
+ /**
72
+ * Factory functions for Entity errors
73
+ */
74
+ export declare const EntityErrors: {
75
+ validationFailed: (entityName: string, operation: string, validationIssues: unknown, providedData: unknown) => EntityValidationError;
76
+ queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => EntityValidationError;
77
+ asyncValidationNotSupported: (entityName: string, operation: string) => EntityValidationError;
78
+ keyGenerationFailed: (entityName: string, operation: string, providedData: unknown, requiredAttributes?: string[], cause?: Error) => KeyGenerationError;
79
+ keyInvalidFormat: (entityName: string, operation: string, providedData: unknown, generatedKey: unknown) => KeyGenerationError;
80
+ keyMissingAttributes: (entityName: string, operation: string, missingAttributes: string[], providedData: unknown) => KeyGenerationError;
81
+ };
82
+ /**
83
+ * Factory functions for Index errors
84
+ */
85
+ export declare const IndexErrors: {
86
+ generationFailed: (indexName: string, operation: string, providedItem: unknown, partitionKeyAttribute?: string, sortKeyAttribute?: string, cause?: Error) => IndexGenerationError;
87
+ missingAttributes: (indexName: string, operation: string, missingAttributes: string[], providedData: unknown, isReadOnly: boolean) => IndexGenerationError;
88
+ undefinedValues: (indexName: string, operation: string, generatedKey: unknown, providedItem: unknown) => IndexGenerationError;
89
+ notFound: (requestedIndexes: string[], availableIndexes: string[], entityName?: string, tableName?: string) => IndexGenerationError;
90
+ readonlyUpdateFailed: (indexName: string, operation: string, providedData: unknown) => IndexGenerationError;
91
+ };
92
+ /**
93
+ * Combined error factory - provides access to all error factories
94
+ */
95
+ export declare const ErrorFactory: {
96
+ expression: {
97
+ missingAttribute: (conditionType: string, condition: unknown) => ExpressionError;
98
+ missingValue: (conditionType: string, condition: unknown) => ExpressionError;
99
+ invalidCondition: (conditionType: string, condition: unknown, suggestion?: string) => ExpressionError;
100
+ emptyArray: (conditionType: string, providedValue: unknown) => ExpressionError;
101
+ unknownType: (conditionType: string, condition: unknown) => ExpressionError;
102
+ };
103
+ validation: {
104
+ indexSchemaValidationFailed: (validationIssues: unknown, keyType: "partition" | "sort" | "both") => ValidationError;
105
+ noUpdateActions: (tableName: string, key: Record<string, unknown>) => ValidationError;
106
+ conditionRequired: (tableName: string, key: Record<string, unknown>) => ValidationError;
107
+ queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => ValidationError;
108
+ undefinedValue: (path: string, tableName: string, key: Record<string, unknown>) => ValidationError;
109
+ };
110
+ configuration: {
111
+ invalidChunkSize: (size: number) => ConfigurationError;
112
+ sortKeyRequired: (tableName: string, partitionKey: string, sortKey?: string) => ConfigurationError;
113
+ sortKeyNotDefined: (tableName: string, partitionKey: string, indexName?: string) => ConfigurationError;
114
+ gsiNotFound: (indexName: string, tableName: string, availableIndexes: string[]) => ConfigurationError;
115
+ primaryKeyMissing: (tableName: string, partitionKeyName: string, providedItem: unknown) => ConfigurationError;
116
+ pkExtractionFailed: (tableName: string, indexName: string, item: unknown, cause?: Error) => ConfigurationError;
117
+ conditionGenerationFailed: (condition: unknown, suggestion?: string) => ExpressionError;
118
+ };
119
+ operation: {
120
+ queryFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
121
+ scanFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
122
+ getFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
123
+ putFailed: (tableName: string, item: unknown, cause?: Error) => OperationError;
124
+ updateFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
125
+ deleteFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
126
+ batchGetFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
127
+ batchWriteFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
128
+ };
129
+ transaction: {
130
+ transactionFailed: (itemCount: number, context: Record<string, unknown>, cause?: Error) => TransactionError;
131
+ duplicateItem: (tableName: string, partitionKey: {
132
+ name: string;
133
+ value: unknown;
134
+ }, sortKey?: {
135
+ name: string;
136
+ value: unknown;
137
+ }) => TransactionError;
138
+ transactionEmpty: () => TransactionError;
139
+ unsupportedType: (item: unknown) => TransactionError;
140
+ };
141
+ batch: {
142
+ batchEmpty: (operation: "write" | "read") => BatchError;
143
+ unsupportedType: (operation: "write" | "read", item: unknown) => BatchError;
144
+ batchWriteFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
145
+ batchGetFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
146
+ };
147
+ entity: {
148
+ validationFailed: (entityName: string, operation: string, validationIssues: unknown, providedData: unknown) => EntityValidationError;
149
+ queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => EntityValidationError;
150
+ asyncValidationNotSupported: (entityName: string, operation: string) => EntityValidationError;
151
+ keyGenerationFailed: (entityName: string, operation: string, providedData: unknown, requiredAttributes?: string[], cause?: Error) => KeyGenerationError;
152
+ keyInvalidFormat: (entityName: string, operation: string, providedData: unknown, generatedKey: unknown) => KeyGenerationError;
153
+ keyMissingAttributes: (entityName: string, operation: string, missingAttributes: string[], providedData: unknown) => KeyGenerationError;
154
+ };
155
+ index: {
156
+ generationFailed: (indexName: string, operation: string, providedItem: unknown, partitionKeyAttribute?: string, sortKeyAttribute?: string, cause?: Error) => IndexGenerationError;
157
+ missingAttributes: (indexName: string, operation: string, missingAttributes: string[], providedData: unknown, isReadOnly: boolean) => IndexGenerationError;
158
+ undefinedValues: (indexName: string, operation: string, generatedKey: unknown, providedItem: unknown) => IndexGenerationError;
159
+ notFound: (requestedIndexes: string[], availableIndexes: string[], entityName?: string, tableName?: string) => IndexGenerationError;
160
+ readonlyUpdateFailed: (indexName: string, operation: string, providedData: unknown) => IndexGenerationError;
161
+ };
162
+ };
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Utility functions for error handling
3
+ *
4
+ * This module provides helper functions for wrapping AWS SDK errors,
5
+ * extracting information from errors, and formatting error context.
6
+ */
7
+ import type { BatchError, ConfigurationError, DynoTableError, EntityError, EntityValidationError, ExpressionError, IndexGenerationError, KeyGenerationError, OperationError, TransactionError, ValidationError } from "../errors";
8
+ /**
9
+ * Checks if an error is a DynamoDB conditional check failure
10
+ *
11
+ * @param error - The error to check
12
+ * @returns true if the error is a conditional check failure
13
+ */
14
+ export declare function isConditionalCheckFailed(error: unknown): boolean;
15
+ /**
16
+ * Checks if an error is a DynamoDB transaction cancellation
17
+ *
18
+ * @param error - The error to check
19
+ * @returns true if the error is a transaction cancellation
20
+ */
21
+ export declare function isTransactionCanceled(error: unknown): boolean;
22
+ /**
23
+ * Checks if an error is a DynamoDB validation exception
24
+ *
25
+ * @param error - The error to check
26
+ * @returns true if the error is a validation exception
27
+ */
28
+ export declare function isValidationException(error: unknown): boolean;
29
+ /**
30
+ * Checks if an error is a DynamoDB provisioned throughput exceeded exception
31
+ *
32
+ * @param error - The error to check
33
+ * @returns true if the error is a throughput exceeded exception
34
+ */
35
+ export declare function isProvisionedThroughputExceeded(error: unknown): boolean;
36
+ /**
37
+ * Checks if an error is a retryable error
38
+ *
39
+ * Retryable errors include:
40
+ * - ProvisionedThroughputExceededException
41
+ * - ThrottlingException
42
+ * - RequestLimitExceeded
43
+ * - InternalServerError
44
+ * - ServiceUnavailable
45
+ *
46
+ * @param error - The error to check
47
+ * @returns true if the error is retryable
48
+ */
49
+ export declare function isRetryableError(error: unknown): boolean;
50
+ /**
51
+ * Extracts the AWS error code from an error
52
+ *
53
+ * @param error - The error to extract the code from
54
+ * @returns The error code, or undefined if not found
55
+ */
56
+ export declare function getAwsErrorCode(error: unknown): string | undefined;
57
+ /**
58
+ * Extracts the AWS error message from an error
59
+ *
60
+ * @param error - The error to extract the message from
61
+ * @returns The error message, or undefined if not found
62
+ */
63
+ export declare function getAwsErrorMessage(error: unknown): string | undefined;
64
+ /**
65
+ * Attempts to extract required attribute names from an error message
66
+ *
67
+ * This is a best-effort function that looks for common patterns in error
68
+ * messages to identify which attributes are missing or required.
69
+ *
70
+ * @param error - The error to extract attributes from
71
+ * @returns Array of attribute names, or undefined if none found
72
+ */
73
+ export declare function extractRequiredAttributes(error: unknown): string[] | undefined;
74
+ /**
75
+ * Formats error context for logging
76
+ *
77
+ * Converts the error context object to a readable string format,
78
+ * handling special types like arrays and nested objects.
79
+ *
80
+ * @param context - The error context to format
81
+ * @param indent - The indentation level (for nested objects)
82
+ * @returns Formatted context string
83
+ */
84
+ export declare function formatErrorContext(context: Record<string, unknown>, indent?: number): string;
85
+ /**
86
+ * Creates a detailed error summary including context
87
+ *
88
+ * Useful for logging or displaying error information to developers.
89
+ *
90
+ * @param error - The DynoTableError to summarize
91
+ * @returns Formatted error summary
92
+ */
93
+ export declare function getErrorSummary(error: DynoTableError): string;
94
+ /**
95
+ * Type guard to check if an error is a DynoTableError
96
+ *
97
+ * @param error - The error to check
98
+ * @returns true if the error is a DynoTableError
99
+ */
100
+ export declare function isDynoTableError(error: unknown): error is DynoTableError;
101
+ /**
102
+ * Type guard to check if an error is a ValidationError
103
+ *
104
+ * @param error - The error to check
105
+ * @returns true if the error is a ValidationError
106
+ */
107
+ export declare function isValidationError(error: unknown): error is ValidationError;
108
+ /**
109
+ * Type guard to check if an error is an OperationError
110
+ *
111
+ * @param error - The error to check
112
+ * @returns true if the error is an OperationError
113
+ */
114
+ export declare function isOperationError(error: unknown): error is OperationError;
115
+ /**
116
+ * Type guard to check if an error is a TransactionError
117
+ *
118
+ * @param error - The error to check
119
+ * @returns true if the error is a TransactionError
120
+ */
121
+ export declare function isTransactionError(error: unknown): error is TransactionError;
122
+ /**
123
+ * Type guard to check if an error is a BatchError
124
+ *
125
+ * @param error - The error to check
126
+ * @returns true if the error is a BatchError
127
+ */
128
+ export declare function isBatchError(error: unknown): error is BatchError;
129
+ /**
130
+ * Type guard to check if an error is an ExpressionError
131
+ *
132
+ * @param error - The error to check
133
+ * @returns true if the error is an ExpressionError
134
+ */
135
+ export declare function isExpressionError(error: unknown): error is ExpressionError;
136
+ /**
137
+ * Type guard to check if an error is a ConfigurationError
138
+ *
139
+ * @param error - The error to check
140
+ * @returns true if the error is a ConfigurationError
141
+ */
142
+ export declare function isConfigurationError(error: unknown): error is ConfigurationError;
143
+ /**
144
+ * Type guard to check if an error is an EntityError
145
+ *
146
+ * @param error - The error to check
147
+ * @returns true if the error is an EntityError
148
+ */
149
+ export declare function isEntityError(error: unknown): error is EntityError;
150
+ /**
151
+ * Type guard to check if an error is a KeyGenerationError
152
+ *
153
+ * @param error - The error to check
154
+ * @returns true if the error is a KeyGenerationError
155
+ */
156
+ export declare function isKeyGenerationError(error: unknown): error is KeyGenerationError;
157
+ /**
158
+ * Type guard to check if an error is an IndexGenerationError
159
+ *
160
+ * @param error - The error to check
161
+ * @returns true if the error is an IndexGenerationError
162
+ */
163
+ export declare function isIndexGenerationError(error: unknown): error is IndexGenerationError;
164
+ /**
165
+ * Type guard to check if an error is an EntityValidationError
166
+ *
167
+ * @param error - The error to check
168
+ * @returns true if the error is an EntityValidationError
169
+ */
170
+ export declare function isEntityValidationError(error: unknown): error is EntityValidationError;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Utilities for working with DynamoDB keys.
3
+ *
4
+ * @module
5
+ */
6
+ export { partitionKey } from "./partition-key-template";
7
+ export { sortKey } from "./sort-key-template";
@@ -0,0 +1,30 @@
1
+ export type StrictGenerateType<T extends readonly string[]> = {
2
+ [K in T[number]]: string;
3
+ };
4
+ /**
5
+ * Creates a template function for generating DynamoDB partition keys with dynamic values.
6
+ * Use this function when you need to:
7
+ * - Create consistent partition key patterns with variable parts
8
+ * - Generate partition keys that follow a specific format
9
+ * - Ensure type safety for partition key parameters
10
+ * - Require all parameters to be provided
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Define a partition key template
15
+ * const pk = partitionKey`country#${"country"}#enclosure#${"enclosure"}`;
16
+ *
17
+ * // Generate a partition key (all parameters required)
18
+ * const key = pk({ country: "NZ", enclosure: "A1" });
19
+ * // Result: "country#NZ#enclosure#A1"
20
+ *
21
+ * // Type checking ensures all parameters are provided
22
+ * const invalidKey = pk({ country: "NZ" }); // TypeScript error
23
+ * ```
24
+ *
25
+ * @param strings - The static parts of the template string
26
+ * @param keys - The dynamic parts of the template string that will be replaced with values
27
+ *
28
+ * @returns A function that accepts an object with the dynamic values and returns the formatted partition key
29
+ */
30
+ export declare function partitionKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: StrictGenerateType<T>) => string;
@@ -0,0 +1,33 @@
1
+ export type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R] ? F extends string ? R extends string[] ? ({
2
+ [K in F | U]: string | number;
3
+ } & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U> : never : never : never;
4
+ /**
5
+ * Creates a template function for generating DynamoDB sort keys with dynamic values.
6
+ * Use this function when you need to:
7
+ * - Create consistent sort key patterns with variable parts
8
+ * - Generate sort keys that follow a specific format
9
+ * - Ensure type safety for sort key parameters
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Define a sort key template
14
+ * const sk = sortKey`country#${"country"}#enclosure#${"enclosure"}#diet#${"diet"}`;
15
+ *
16
+ * // Generate a sort key with partial parameters
17
+ * const templatedString = sk({ country: "NZ", enclosure: "A1" });
18
+ * // Result: "country#NZ#enclosure#A1#diet#"
19
+ *
20
+ * // Generate a complete sort key
21
+ * const fullKey = sk({ country: "NZ", enclosure: "A1", diet: "carnivore" });
22
+ * // Result: "country#NZ#enclosure#A1#diet#carnivore"
23
+ *
24
+ * // Type checking ensures only valid parameters are used
25
+ * const invalidKey = sk({ country: "NZ", invalid: "value" }); // TypeScript error
26
+ * ```
27
+ *
28
+ * @param strings - The static parts of the template string
29
+ * @param keys - The dynamic parts of the template string that will be replaced with values
30
+ *
31
+ * @returns A function that accepts an object with the dynamic values and returns the formatted sort key
32
+ */
33
+ export declare function sortKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: GenerateType<T>) => string;
package/dist/utils.d.ts CHANGED
@@ -1,66 +1 @@
1
- type StrictGenerateType<T extends readonly string[]> = {
2
- [K in T[number]]: string;
3
- };
4
- /**
5
- * Creates a template function for generating DynamoDB partition keys with dynamic values.
6
- * Use this function when you need to:
7
- * - Create consistent partition key patterns with variable parts
8
- * - Generate partition keys that follow a specific format
9
- * - Ensure type safety for partition key parameters
10
- * - Require all parameters to be provided
11
- *
12
- * @example
13
- * ```ts
14
- * // Define a partition key template
15
- * const pk = partitionKey`country#${"country"}#enclosure#${"enclosure"}`;
16
- *
17
- * // Generate a partition key (all parameters required)
18
- * const key = pk({ country: "NZ", enclosure: "A1" });
19
- * // Result: "country#NZ#enclosure#A1"
20
- *
21
- * // Type checking ensures all parameters are provided
22
- * const invalidKey = pk({ country: "NZ" }); // TypeScript error
23
- * ```
24
- *
25
- * @param strings - The static parts of the template string
26
- * @param keys - The dynamic parts of the template string that will be replaced with values
27
- *
28
- * @returns A function that accepts an object with the dynamic values and returns the formatted partition key
29
- */
30
- declare function partitionKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: StrictGenerateType<T>) => string;
31
-
32
- type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R] ? F extends string ? R extends string[] ? ({
33
- [K in F | U]: string | number;
34
- } & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U> : never : never : never;
35
- /**
36
- * Creates a template function for generating DynamoDB sort keys with dynamic values.
37
- * Use this function when you need to:
38
- * - Create consistent sort key patterns with variable parts
39
- * - Generate sort keys that follow a specific format
40
- * - Ensure type safety for sort key parameters
41
- *
42
- * @example
43
- * ```ts
44
- * // Define a sort key template
45
- * const sk = sortKey`country#${"country"}#enclosure#${"enclosure"}#diet#${"diet"}`;
46
- *
47
- * // Generate a sort key with partial parameters
48
- * const templatedString = sk({ country: "NZ", enclosure: "A1" });
49
- * // Result: "country#NZ#enclosure#A1#diet#"
50
- *
51
- * // Generate a complete sort key
52
- * const fullKey = sk({ country: "NZ", enclosure: "A1", diet: "carnivore" });
53
- * // Result: "country#NZ#enclosure#A1#diet#carnivore"
54
- *
55
- * // Type checking ensures only valid parameters are used
56
- * const invalidKey = sk({ country: "NZ", invalid: "value" }); // TypeScript error
57
- * ```
58
- *
59
- * @param strings - The static parts of the template string
60
- * @param keys - The dynamic parts of the template string that will be replaced with values
61
- *
62
- * @returns A function that accepts an object with the dynamic values and returns the formatted sort key
63
- */
64
- declare function sortKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: GenerateType<T>) => string;
65
-
66
- export { partitionKey, sortKey };
1
+ export * from "./utils/index";