dyno-table 2.5.2 → 2.6.1

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 (76) 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.cjs +3648 -43
  18. package/dist/builders.d.ts +1 -4
  19. package/dist/builders.js +3648 -3
  20. package/dist/conditions.cjs +60 -67
  21. package/dist/conditions.d.ts +705 -3
  22. package/dist/conditions.js +46 -1
  23. package/dist/entity/ddb-indexing.d.ts +45 -0
  24. package/dist/entity/entity.d.ts +188 -0
  25. package/dist/entity/index-utils.d.ts +24 -0
  26. package/dist/entity.cjs +1126 -15
  27. package/dist/entity.d.ts +1 -261
  28. package/dist/entity.js +1127 -3
  29. package/dist/errors.d.ts +212 -0
  30. package/dist/expression.d.ts +9 -0
  31. package/dist/index-definition.d.ts +10 -0
  32. package/dist/index.cjs +5388 -270
  33. package/dist/index.d.ts +16 -273
  34. package/dist/index.js +5332 -6
  35. package/dist/operation-types.d.ts +8 -0
  36. package/dist/standard-schema.d.ts +2 -4
  37. package/dist/table.cjs +4311 -7
  38. package/dist/table.d.ts +13 -8
  39. package/dist/table.js +4315 -4
  40. package/dist/types.d.ts +6 -9
  41. package/dist/utils/chunk-array.d.ts +9 -0
  42. package/dist/utils/debug-expression.d.ts +32 -0
  43. package/dist/utils/debug-transaction.d.ts +17 -0
  44. package/dist/utils/error-factory.d.ts +162 -0
  45. package/dist/utils/error-utils.d.ts +170 -0
  46. package/dist/utils/index.d.ts +7 -0
  47. package/dist/utils/partition-key-template.d.ts +30 -0
  48. package/dist/utils/sort-key-template.d.ts +33 -0
  49. package/dist/utils.cjs +28 -10
  50. package/dist/utils.d.ts +1 -66
  51. package/dist/utils.js +29 -1
  52. package/package.json +53 -66
  53. package/dist/builders.d.cts +0 -4
  54. package/dist/chunk-2WIBY7PZ.js +0 -46
  55. package/dist/chunk-3DR6VOFW.cjs +0 -3349
  56. package/dist/chunk-42LH2UEM.js +0 -577
  57. package/dist/chunk-7UJJ7JXM.cjs +0 -63
  58. package/dist/chunk-ELULXDSB.cjs +0 -564
  59. package/dist/chunk-FF7FYGDH.js +0 -543
  60. package/dist/chunk-G5ERTQFX.cjs +0 -843
  61. package/dist/chunk-NYJGW3XH.js +0 -3334
  62. package/dist/chunk-PB7BBCZO.cjs +0 -32
  63. package/dist/chunk-QVRMYGC4.js +0 -29
  64. package/dist/chunk-RNX2DAHA.js +0 -818
  65. package/dist/chunk-ZUBCW3LA.cjs +0 -579
  66. package/dist/conditions-BSAcZswY.d.ts +0 -731
  67. package/dist/conditions-C8bM__Pn.d.cts +0 -731
  68. package/dist/conditions.d.cts +0 -3
  69. package/dist/entity.d.cts +0 -261
  70. package/dist/index-Bc-ra0im.d.ts +0 -3042
  71. package/dist/index-CPCmWsEv.d.cts +0 -3042
  72. package/dist/index.d.cts +0 -273
  73. package/dist/standard-schema.d.cts +0 -57
  74. package/dist/table.d.cts +0 -165
  75. package/dist/types.d.cts +0 -29
  76. package/dist/utils.d.cts +0 -66
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Base error class for all dyno-table errors
3
+ *
4
+ * All custom errors in the library extend this class, allowing consumers
5
+ * to catch all library errors with a single catch block if needed.
6
+ */
7
+ export declare class DynoTableError extends Error {
8
+ /**
9
+ * Machine-readable error code for programmatic error handling
10
+ * @example "KEY_GENERATION_FAILED", "VALIDATION_ERROR", etc.
11
+ */
12
+ readonly code: string;
13
+ /**
14
+ * Additional context about the error
15
+ * Contains operation-specific details like entity names, table names,
16
+ * expressions, conditions, and other relevant debugging information
17
+ */
18
+ readonly context: Record<string, unknown>;
19
+ /**
20
+ * The original error that caused this error (if wrapping another error)
21
+ * Useful for preserving AWS SDK errors or other underlying errors
22
+ */
23
+ readonly cause?: Error;
24
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
25
+ }
26
+ /**
27
+ * Error for schema validation and input validation failures
28
+ *
29
+ * Thrown when user-provided data doesn't match the expected schema
30
+ * or when required fields are missing.
31
+ */
32
+ export declare class ValidationError extends DynoTableError {
33
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
34
+ }
35
+ /**
36
+ * Error for DynamoDB operation failures
37
+ *
38
+ * Wraps AWS SDK errors and adds library-specific context like
39
+ * the operation type, table name, and generated expressions.
40
+ */
41
+ export declare class OperationError extends DynoTableError {
42
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
43
+ }
44
+ /**
45
+ * Error for transaction-specific failures
46
+ *
47
+ * Thrown when transaction operations fail, including duplicate item
48
+ * detection, transaction cancellation, and other transaction-related issues.
49
+ */
50
+ export declare class TransactionError extends DynoTableError {
51
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
52
+ }
53
+ /**
54
+ * Error for batch operation failures
55
+ *
56
+ * Thrown when batch operations fail or when batch limits are exceeded.
57
+ * Includes information about unprocessed items and operation details.
58
+ */
59
+ export declare class BatchError extends DynoTableError {
60
+ /**
61
+ * The type of batch operation that failed
62
+ */
63
+ readonly operation: "write" | "read";
64
+ /**
65
+ * The items that were not processed during the batch operation
66
+ */
67
+ readonly unprocessedItems: unknown[];
68
+ constructor(message: string, code: string, operation: "write" | "read", unprocessedItems?: unknown[], context?: Record<string, unknown>, cause?: Error);
69
+ }
70
+ /**
71
+ * Error for expression building failures
72
+ *
73
+ * Thrown when building DynamoDB expressions (condition, filter, update, etc.)
74
+ * fails due to invalid conditions or missing required fields.
75
+ */
76
+ export declare class ExpressionError extends DynoTableError {
77
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
78
+ }
79
+ /**
80
+ * Error for table/index configuration issues
81
+ *
82
+ * Thrown when there are problems with table configuration,
83
+ * such as missing GSIs or invalid index references.
84
+ */
85
+ export declare class ConfigurationError extends DynoTableError {
86
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
87
+ }
88
+ /**
89
+ * Base error for all entity-related errors
90
+ *
91
+ * Parent class for entity-specific errors like key generation
92
+ * and index generation failures.
93
+ */
94
+ export declare class EntityError extends DynoTableError {
95
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
96
+ }
97
+ /**
98
+ * Error for primary key generation failures
99
+ *
100
+ * Thrown when generating entity primary keys fails due to missing
101
+ * attributes or invalid key formats.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * try {
106
+ * await userRepo.create({ name: "John" }).execute();
107
+ * } catch (error) {
108
+ * if (error instanceof KeyGenerationError) {
109
+ * console.error("Failed to generate key");
110
+ * console.error("Entity:", error.context.entityName);
111
+ * console.error("Required attributes:", error.context.requiredAttributes);
112
+ * }
113
+ * }
114
+ * ```
115
+ */
116
+ export declare class KeyGenerationError extends EntityError {
117
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
118
+ }
119
+ /**
120
+ * Error for index key generation failures
121
+ *
122
+ * Thrown when generating secondary index keys fails due to missing
123
+ * attributes or when trying to update readonly indexes without forcing.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * try {
128
+ * await orderRepo.update({ id: "123" }, { status: "shipped" }).execute();
129
+ * } catch (error) {
130
+ * if (error instanceof IndexGenerationError) {
131
+ * console.error("Index failed:", error.context.indexName);
132
+ * console.error("Suggestion:", error.context.suggestion);
133
+ * }
134
+ * }
135
+ * ```
136
+ */
137
+ export declare class IndexGenerationError extends EntityError {
138
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
139
+ }
140
+ /**
141
+ * Error for entity schema validation failures
142
+ *
143
+ * Thrown when entity data doesn't pass schema validation.
144
+ * Includes validation issues and the entity context.
145
+ */
146
+ export declare class EntityValidationError extends ValidationError {
147
+ constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
148
+ }
149
+ /**
150
+ * Error codes used throughout the library
151
+ *
152
+ * These codes allow for programmatic error handling and can be used
153
+ * to implement retry logic, user-friendly error messages, etc.
154
+ */
155
+ export declare const ErrorCodes: {
156
+ readonly KEY_GENERATION_FAILED: "KEY_GENERATION_FAILED";
157
+ readonly KEY_MISSING_ATTRIBUTES: "KEY_MISSING_ATTRIBUTES";
158
+ readonly KEY_INVALID_FORMAT: "KEY_INVALID_FORMAT";
159
+ readonly INDEX_GENERATION_FAILED: "INDEX_GENERATION_FAILED";
160
+ readonly INDEX_MISSING_ATTRIBUTES: "INDEX_MISSING_ATTRIBUTES";
161
+ readonly INDEX_NOT_FOUND: "INDEX_NOT_FOUND";
162
+ readonly INDEX_READONLY_UPDATE_FAILED: "INDEX_READONLY_UPDATE_FAILED";
163
+ readonly INDEX_UNDEFINED_VALUES: "INDEX_UNDEFINED_VALUES";
164
+ readonly ENTITY_VALIDATION_FAILED: "ENTITY_VALIDATION_FAILED";
165
+ readonly ASYNC_VALIDATION_NOT_SUPPORTED: "ASYNC_VALIDATION_NOT_SUPPORTED";
166
+ readonly QUERY_INPUT_VALIDATION_FAILED: "QUERY_INPUT_VALIDATION_FAILED";
167
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
168
+ readonly VALIDATION_FAILED: "VALIDATION_FAILED";
169
+ readonly SCHEMA_VALIDATION_FAILED: "SCHEMA_VALIDATION_FAILED";
170
+ readonly INVALID_PARAMETER: "INVALID_PARAMETER";
171
+ readonly MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD";
172
+ readonly UNDEFINED_VALUE: "UNDEFINED_VALUE";
173
+ readonly EXPRESSION_MISSING_ATTRIBUTE: "EXPRESSION_MISSING_ATTRIBUTE";
174
+ readonly EXPRESSION_MISSING_VALUE: "EXPRESSION_MISSING_VALUE";
175
+ readonly EXPRESSION_INVALID_CONDITION: "EXPRESSION_INVALID_CONDITION";
176
+ readonly EXPRESSION_EMPTY_ARRAY: "EXPRESSION_EMPTY_ARRAY";
177
+ readonly EXPRESSION_UNKNOWN_TYPE: "EXPRESSION_UNKNOWN_TYPE";
178
+ readonly EXPRESSION_INVALID: "EXPRESSION_INVALID";
179
+ readonly EXPRESSION_INVALID_OPERATOR: "EXPRESSION_INVALID_OPERATOR";
180
+ readonly QUERY_FAILED: "QUERY_FAILED";
181
+ readonly SCAN_FAILED: "SCAN_FAILED";
182
+ readonly GET_FAILED: "GET_FAILED";
183
+ readonly PUT_FAILED: "PUT_FAILED";
184
+ readonly DELETE_FAILED: "DELETE_FAILED";
185
+ readonly UPDATE_FAILED: "UPDATE_FAILED";
186
+ readonly BATCH_GET_FAILED: "BATCH_GET_FAILED";
187
+ readonly BATCH_WRITE_FAILED: "BATCH_WRITE_FAILED";
188
+ readonly NO_UPDATE_ACTIONS: "NO_UPDATE_ACTIONS";
189
+ readonly CONDITIONAL_CHECK_FAILED: "CONDITIONAL_CHECK_FAILED";
190
+ readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
191
+ readonly TRANSACTION_DUPLICATE_ITEM: "TRANSACTION_DUPLICATE_ITEM";
192
+ readonly TRANSACTION_EMPTY: "TRANSACTION_EMPTY";
193
+ readonly TRANSACTION_UNSUPPORTED_TYPE: "TRANSACTION_UNSUPPORTED_TYPE";
194
+ readonly TRANSACTION_ITEM_LIMIT: "TRANSACTION_ITEM_LIMIT";
195
+ readonly TRANSACTION_CANCELLED: "TRANSACTION_CANCELLED";
196
+ readonly BATCH_EMPTY: "BATCH_EMPTY";
197
+ readonly BATCH_UNSUPPORTED_TYPE: "BATCH_UNSUPPORTED_TYPE";
198
+ readonly BATCH_UNPROCESSED_ITEMS: "BATCH_UNPROCESSED_ITEMS";
199
+ readonly BATCH_SIZE_EXCEEDED: "BATCH_SIZE_EXCEEDED";
200
+ readonly GSI_NOT_FOUND: "GSI_NOT_FOUND";
201
+ readonly SORT_KEY_REQUIRED: "SORT_KEY_REQUIRED";
202
+ readonly SORT_KEY_NOT_DEFINED: "SORT_KEY_NOT_DEFINED";
203
+ readonly PRIMARY_KEY_MISSING: "PRIMARY_KEY_MISSING";
204
+ readonly INVALID_CHUNK_SIZE: "INVALID_CHUNK_SIZE";
205
+ readonly CONDITION_REQUIRED: "CONDITION_REQUIRED";
206
+ readonly CONDITION_GENERATION_FAILED: "CONDITION_GENERATION_FAILED";
207
+ readonly PK_EXTRACTION_FAILED: "PK_EXTRACTION_FAILED";
208
+ readonly CONFIGURATION_INVALID: "CONFIGURATION_INVALID";
209
+ readonly CONFIGURATION_MISSING_SORT_KEY: "CONFIGURATION_MISSING_SORT_KEY";
210
+ readonly CONFIGURATION_INVALID_GSI: "CONFIGURATION_INVALID_GSI";
211
+ };
212
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
@@ -0,0 +1,9 @@
1
+ import type { Condition, ExpressionParams } from "./conditions";
2
+ export declare const generateAttributeName: (params: ExpressionParams, attr: string) => string;
3
+ export declare const generateValueName: (params: ExpressionParams, value: unknown) => string;
4
+ export declare const buildExpression: (condition: Condition, params: ExpressionParams) => string;
5
+ export declare const prepareExpressionParams: (condition?: Condition) => {
6
+ expression?: string;
7
+ names?: Record<string, string>;
8
+ values?: Record<string, unknown>;
9
+ };
@@ -0,0 +1,10 @@
1
+ import type { DynamoItem } from "./types";
2
+ export interface IndexDefinition<T extends DynamoItem, P extends (item: T) => string, S extends ((item: T) => string) | undefined = undefined> {
3
+ name: string;
4
+ partitionKey: P;
5
+ sortKey?: S;
6
+ generateKey: (item: T) => {
7
+ pk: string;
8
+ sk?: string;
9
+ };
10
+ }