dyno-table 1.6.0 → 1.7.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 (72) hide show
  1. package/README.md +52 -139
  2. package/dist/batch-builder-DNsz6zvh.d.cts +398 -0
  3. package/dist/batch-builder-Dz1yPGrJ.d.ts +398 -0
  4. package/dist/builders/condition-check-builder.cjs +0 -13
  5. package/dist/builders/condition-check-builder.cjs.map +1 -1
  6. package/dist/builders/condition-check-builder.d.cts +0 -13
  7. package/dist/builders/condition-check-builder.d.ts +0 -13
  8. package/dist/builders/condition-check-builder.js +0 -13
  9. package/dist/builders/condition-check-builder.js.map +1 -1
  10. package/dist/builders/delete-builder.cjs +38 -0
  11. package/dist/builders/delete-builder.cjs.map +1 -1
  12. package/dist/builders/delete-builder.d.cts +36 -0
  13. package/dist/builders/delete-builder.d.ts +36 -0
  14. package/dist/builders/delete-builder.js +38 -0
  15. package/dist/builders/delete-builder.js.map +1 -1
  16. package/dist/builders/paginator.cjs +0 -24
  17. package/dist/builders/paginator.cjs.map +1 -1
  18. package/dist/builders/paginator.d.cts +0 -24
  19. package/dist/builders/paginator.d.ts +0 -24
  20. package/dist/builders/paginator.js +0 -24
  21. package/dist/builders/paginator.js.map +1 -1
  22. package/dist/builders/put-builder.cjs +39 -8
  23. package/dist/builders/put-builder.cjs.map +1 -1
  24. package/dist/builders/put-builder.d.cts +37 -8
  25. package/dist/builders/put-builder.d.ts +37 -8
  26. package/dist/builders/put-builder.js +39 -8
  27. package/dist/builders/put-builder.js.map +1 -1
  28. package/dist/builders/query-builder.cjs +0 -53
  29. package/dist/builders/query-builder.cjs.map +1 -1
  30. package/dist/builders/query-builder.d.cts +1 -1
  31. package/dist/builders/query-builder.d.ts +1 -1
  32. package/dist/builders/query-builder.js +0 -53
  33. package/dist/builders/query-builder.js.map +1 -1
  34. package/dist/builders/transaction-builder.cjs +0 -47
  35. package/dist/builders/transaction-builder.cjs.map +1 -1
  36. package/dist/builders/transaction-builder.d.cts +0 -47
  37. package/dist/builders/transaction-builder.d.ts +0 -47
  38. package/dist/builders/transaction-builder.js +0 -47
  39. package/dist/builders/transaction-builder.js.map +1 -1
  40. package/dist/builders/update-builder.cjs +2 -2
  41. package/dist/builders/update-builder.cjs.map +1 -1
  42. package/dist/builders/update-builder.d.cts +2 -2
  43. package/dist/builders/update-builder.d.ts +2 -2
  44. package/dist/builders/update-builder.js +2 -2
  45. package/dist/builders/update-builder.js.map +1 -1
  46. package/dist/conditions.cjs.map +1 -1
  47. package/dist/conditions.js.map +1 -1
  48. package/dist/entity.cjs +69 -37
  49. package/dist/entity.cjs.map +1 -1
  50. package/dist/entity.d.cts +30 -10
  51. package/dist/entity.d.ts +30 -10
  52. package/dist/entity.js +69 -37
  53. package/dist/entity.js.map +1 -1
  54. package/dist/index.cjs +530 -182
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +3 -2
  57. package/dist/index.d.ts +3 -2
  58. package/dist/index.js +529 -183
  59. package/dist/index.js.map +1 -1
  60. package/dist/{query-builder-CbHvimBk.d.cts → query-builder-BDuHHrb-.d.cts} +0 -34
  61. package/dist/{query-builder-BhrR31oO.d.ts → query-builder-C6XjVEFH.d.ts} +0 -34
  62. package/dist/{table-Des8C2od.d.ts → table-BWa4tx63.d.ts} +39 -151
  63. package/dist/{table-CY9byPEg.d.cts → table-DAKlzQsK.d.cts} +39 -151
  64. package/dist/table.cjs +459 -145
  65. package/dist/table.cjs.map +1 -1
  66. package/dist/table.d.cts +3 -2
  67. package/dist/table.d.ts +3 -2
  68. package/dist/table.js +459 -145
  69. package/dist/table.js.map +1 -1
  70. package/dist/utils.cjs.map +1 -1
  71. package/dist/utils.js.map +1 -1
  72. package/package.json +1 -1
package/dist/entity.js CHANGED
@@ -6,9 +6,55 @@ var createComparisonCondition = (type) => (attr, value) => ({
6
6
  });
7
7
  var eq = createComparisonCondition("eq");
8
8
 
9
+ // src/builders/entity-aware-builders.ts
10
+ function createEntityAwareBuilder(builder, entityName) {
11
+ return new Proxy(builder, {
12
+ get(target, prop, receiver) {
13
+ if (prop === "entityName") {
14
+ return entityName;
15
+ }
16
+ if (prop === "withBatch" && typeof target[prop] === "function") {
17
+ return (batch, entityType) => {
18
+ const typeToUse = entityType ?? entityName;
19
+ const fn = target[prop];
20
+ return fn.call(target, batch, typeToUse);
21
+ };
22
+ }
23
+ return Reflect.get(target, prop, receiver);
24
+ }
25
+ });
26
+ }
27
+ function createEntityAwarePutBuilder(builder, entityName) {
28
+ return createEntityAwareBuilder(builder, entityName);
29
+ }
30
+ function createEntityAwareGetBuilder(builder, entityName) {
31
+ return createEntityAwareBuilder(builder, entityName);
32
+ }
33
+ function createEntityAwareDeleteBuilder(builder, entityName) {
34
+ return createEntityAwareBuilder(builder, entityName);
35
+ }
36
+
9
37
  // src/entity.ts
10
38
  function defineEntity(config) {
11
39
  const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? "entityType";
40
+ const wrapMethodWithPreparation = (originalMethod, prepareFn, context) => {
41
+ const wrappedMethod = (...args) => {
42
+ prepareFn();
43
+ return originalMethod.call(context, ...args);
44
+ };
45
+ Object.setPrototypeOf(wrappedMethod, originalMethod);
46
+ const propertyNames = Object.getOwnPropertyNames(originalMethod);
47
+ for (let i = 0; i < propertyNames.length; i++) {
48
+ const prop = propertyNames[i];
49
+ if (prop !== "length" && prop !== "name" && prop !== "prototype") {
50
+ const descriptor = Object.getOwnPropertyDescriptor(originalMethod, prop);
51
+ if (descriptor && descriptor.writable !== false && !descriptor.get) {
52
+ wrappedMethod[prop] = originalMethod[prop];
53
+ }
54
+ }
55
+ }
56
+ return wrappedMethod;
57
+ };
12
58
  const generateTimestamps = (timestampTypes) => {
13
59
  if (!config.settings?.timestamps) return {};
14
60
  const timestamps = {};
@@ -113,24 +159,17 @@ function defineEntity(config) {
113
159
  };
114
160
  const originalWithTransaction = builder.withTransaction;
115
161
  if (originalWithTransaction) {
116
- const wrappedWithTransaction = (transaction) => {
117
- prepareValidatedItemSync();
118
- return originalWithTransaction.call(builder, transaction);
119
- };
120
- Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);
121
- const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);
122
- for (let i = 0; i < propertyNames.length; i++) {
123
- const prop = propertyNames[i];
124
- if (prop !== "length" && prop !== "name" && prop !== "prototype") {
125
- try {
126
- wrappedWithTransaction[prop] = originalWithTransaction[prop];
127
- } catch (e) {
128
- }
129
- }
130
- }
131
- builder.withTransaction = wrappedWithTransaction;
162
+ builder.withTransaction = wrapMethodWithPreparation(
163
+ originalWithTransaction,
164
+ prepareValidatedItemSync,
165
+ builder
166
+ );
132
167
  }
133
- return builder;
168
+ const originalWithBatch = builder.withBatch;
169
+ if (originalWithBatch) {
170
+ builder.withBatch = wrapMethodWithPreparation(originalWithBatch, prepareValidatedItemSync, builder);
171
+ }
172
+ return createEntityAwarePutBuilder(builder, config.name);
134
173
  },
135
174
  upsert: (data) => {
136
175
  const builder = table.put({});
@@ -217,26 +256,19 @@ function defineEntity(config) {
217
256
  };
218
257
  const originalWithTransaction = builder.withTransaction;
219
258
  if (originalWithTransaction) {
220
- const wrappedWithTransaction = (transaction) => {
221
- prepareValidatedItemSync();
222
- return originalWithTransaction.call(builder, transaction);
223
- };
224
- Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);
225
- const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);
226
- for (let i = 0; i < propertyNames.length; i++) {
227
- const prop = propertyNames[i];
228
- if (prop !== "length" && prop !== "name" && prop !== "prototype") {
229
- try {
230
- wrappedWithTransaction[prop] = originalWithTransaction[prop];
231
- } catch (e) {
232
- }
233
- }
234
- }
235
- builder.withTransaction = wrappedWithTransaction;
259
+ builder.withTransaction = wrapMethodWithPreparation(
260
+ originalWithTransaction,
261
+ prepareValidatedItemSync,
262
+ builder
263
+ );
236
264
  }
237
- return builder;
265
+ const originalWithBatch = builder.withBatch;
266
+ if (originalWithBatch) {
267
+ builder.withBatch = wrapMethodWithPreparation(originalWithBatch, prepareValidatedItemSync, builder);
268
+ }
269
+ return createEntityAwarePutBuilder(builder, config.name);
238
270
  },
239
- get: (key) => table.get(config.primaryKey.generateKey(key)),
271
+ get: (key) => createEntityAwareGetBuilder(table.get(config.primaryKey.generateKey(key)), config.name),
240
272
  update: (key, data) => {
241
273
  const primaryKeyObj = config.primaryKey.generateKey(key);
242
274
  const builder = table.update(primaryKeyObj);
@@ -248,13 +280,13 @@ function defineEntity(config) {
248
280
  delete: (key) => {
249
281
  const builder = table.delete(config.primaryKey.generateKey(key));
250
282
  builder.condition(eq(entityTypeAttributeName, config.name));
251
- return builder;
283
+ return createEntityAwareDeleteBuilder(builder, config.name);
252
284
  },
253
285
  query: Object.entries(config.queries || {}).reduce((acc, [key, inputCallback]) => {
254
286
  acc[key] = (input) => {
255
287
  const queryEntity = {
256
288
  scan: repository.scan,
257
- get: (key2) => table.get(key2),
289
+ get: (key2) => createEntityAwareGetBuilder(table.get(key2), config.name),
258
290
  query: (keyCondition) => {
259
291
  return table.query(keyCondition);
260
292
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/conditions.ts","../src/entity.ts"],"names":["key"],"mappings":";AAiGO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,CAAC,MAAc,KAA+B,MAAA;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,CAAA;AAQK,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;;;AC4BzC,SAAS,aAKd,MAAuC,EAAA;AACvC,EAAM,MAAA,uBAAA,GAA0B,MAAO,CAAA,QAAA,EAAU,uBAA2B,IAAA,YAAA;AAmB5E,EAAM,MAAA,kBAAA,GAAqB,CAAC,cAAuF,KAAA;AACjH,IAAA,IAAI,CAAC,MAAA,CAAO,QAAU,EAAA,UAAA,SAAmB,EAAC;AAE1C,IAAA,MAAM,aAA8C,EAAC;AACrD,IAAM,MAAA,GAAA,uBAAU,IAAK,EAAA;AACrB,IAAA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,GACF;AACF;AAEO,SAAS,aAAsC,GAAA;AACpD,EAAO,OAAA;AAAA,IACL,KAAA,EAAO,CAAI,MAAiC,MAAA;AAAA,MAC1C,KAAA,EAAO,CAIL,OACG,KAAA;AACH,QAAM,MAAA,OAAA,GAAU,CAAC,KAAa,KAAA,CAAC,WAA2B,OAAQ,CAAA,EAAE,KAAO,EAAA,MAAA,EAAQ,CAAA;AACnF,QAAA,OAAA,CAAQ,MAAS,GAAA,MAAA;AACjB,QAAO,OAAA,OAAA;AAAA;AACT,KACF;AAAA,GACF;AACF;AAOO,SAAS,WAAc,GAAA;AAC5B,EAAO,OAAA;AAAA,IACL,KAAA,EAAO,CAAuB,MAAiC,MAAA;AAAA,MAC7D,YAAA,EAAc,CAAgC,IAAa,MAAA;AAAA,QACzD,OAAA,EAAS,CAAgC,IACtC,MAAA;AAAA,UACC,IAAM,EAAA,QAAA;AAAA,UACN,YAAc,EAAA,IAAA;AAAA,UACd,OAAS,EAAA,IAAA;AAAA,UACT,WAAA,EAAa,CAAC,IAAA,MAAa,EAAE,EAAA,EAAI,IAAK,CAAA,IAAI,CAAG,EAAA,EAAA,EAAI,IAAK,CAAA,IAAI,CAAE,EAAA;AAAA,SAC9D,CAAA;AAAA,QAEF,gBAAgB,OACb;AAAA,UACC,IAAM,EAAA,QAAA;AAAA,UACN,YAAc,EAAA,IAAA;AAAA,UACd,aAAa,CAAC,IAAA,MAAa,EAAE,EAAI,EAAA,IAAA,CAAK,IAAI,CAAE,EAAA;AAAA,SAC9C;AAAA,OACJ;AAAA,KACF;AAAA,GACF;AACF","file":"entity.js","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - in: Checks if attribute value is in a list of values\n * - beginsWith: Checks if string attribute begins with specified substring\n * - contains: Checks if string/set attribute contains specified value\n * - attributeExists: Checks if attribute exists\n * - attributeNotExists: Checks if attribute does not exist\n */\nexport type ComparisonOperator =\n | \"eq\"\n | \"ne\"\n | \"lt\"\n | \"lte\"\n | \"gt\"\n | \"gte\"\n | \"between\"\n | \"in\"\n | \"beginsWith\"\n | \"contains\"\n | \"attributeExists\"\n | \"attributeNotExists\";\n\n/**\n * Logical operators for combining multiple conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}\n *\n * - and: Evaluates to true if all conditions are true\n * - or: Evaluates to true if any condition is true\n * - not: Negate the result of a condition\n */\nexport type LogicalOperator = \"and\" | \"or\" | \"not\";\n\n/**\n * Represents a DynamoDB condition expression.\n * Can be either a comparison condition or a logical combination of conditions.\n *\n * @example\n * // Simple comparison condition\n * const condition: Condition = {\n * type: \"eq\",\n * attr: \"status\",\n * value: \"ACTIVE\"\n * };\n *\n * @example\n * // Logical combination of conditions\n * const condition: Condition = {\n * type: \"and\",\n * conditions: [\n * { type: \"eq\", attr: \"status\", value: \"ACTIVE\" },\n * { type: \"gt\", attr: \"age\", value: 5 }\n * ]\n * };\n */\nexport interface Condition {\n /** The type of condition (comparison or logical operator) */\n type: ComparisonOperator | LogicalOperator;\n /** The attribute name for comparison conditions */\n attr?: string;\n /** The value to compare against for comparison conditions */\n value?: unknown;\n /** Array of conditions for logical operators (and/or) */\n conditions?: Condition[];\n /** Single condition for the 'not' operator */\n condition?: Condition;\n}\n\n/**\n * Parameters used to build DynamoDB expression strings.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}\n */\nexport interface ExpressionParams {\n /** Map of attribute name placeholders to actual attribute names */\n expressionAttributeNames: Record<string, string>;\n /** Map of value placeholders to actual values */\n expressionAttributeValues: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates an in condition that checks if a value is in a list of values\n * @example\n * inArray(\"status\", [\"ACTIVE\", \"PENDING\", \"PROCESSING\"]) // status IN (\"ACTIVE\", \"PENDING\", \"PROCESSING\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}\n */\nexport const inArray = (attr: string, values: unknown[]): Condition => ({\n type: \"in\",\n attr,\n value: values,\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n /**\n * Creates an equals (=) condition for type-safe attribute comparison.\n * Tests if the specified attribute equals the provided value.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr equals value\n *\n * @example\n * ```typescript\n * interface User { status: string; age: number; }\n *\n * // String comparison\n * op.eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n *\n * // Numeric comparison\n * op.eq(\"age\", 25) // age = 25\n *\n * // Nested attribute\n * op.eq(\"profile.role\", \"admin\") // profile.role = \"admin\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a not equals (≠ / <>) condition for type-safe attribute comparison.\n * Tests if the specified attribute does not equal the provided value.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr does not equal value\n *\n * @example\n * ```typescript\n * interface User { status: string; priority: number; }\n *\n * // String comparison\n * op.ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n *\n * // Numeric comparison\n * op.ne(\"priority\", 0) // priority <> 0\n *\n * // Useful for filtering out specific values\n * op.ne(\"category\", \"ARCHIVED\") // category <> \"ARCHIVED\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a less than (<) condition for type-safe attribute comparison.\n * Tests if the specified attribute is less than the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is less than value\n *\n * @example\n * ```typescript\n * interface Product { price: number; name: string; createdAt: string; }\n *\n * // Numeric comparison\n * op.lt(\"price\", 100) // price < 100\n *\n * // String comparison (lexicographic)\n * op.lt(\"name\", \"M\") // name < \"M\" (names starting with A-L)\n *\n * // Date comparison (ISO strings)\n * op.lt(\"createdAt\", \"2024-01-01\") // createdAt < \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a less than or equal to (≤) condition for type-safe attribute comparison.\n * Tests if the specified attribute is less than or equal to the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is less than or equal to value\n *\n * @example\n * ```typescript\n * interface Order { total: number; priority: number; dueDate: string; }\n *\n * // Numeric comparison\n * op.lte(\"total\", 1000) // total <= 1000\n *\n * // Priority levels\n * op.lte(\"priority\", 3) // priority <= 3 (low to medium priority)\n *\n * // Date deadlines\n * op.lte(\"dueDate\", \"2024-12-31\") // dueDate <= \"2024-12-31\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a greater than (>) condition for type-safe attribute comparison.\n * Tests if the specified attribute is greater than the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is greater than value\n *\n * @example\n * ```typescript\n * interface User { age: number; score: number; lastLogin: string; }\n *\n * // Age restrictions\n * op.gt(\"age\", 18) // age > 18 (adults only)\n *\n * // Performance thresholds\n * op.gt(\"score\", 85) // score > 85 (high performers)\n *\n * // Recent activity\n * op.gt(\"lastLogin\", \"2024-01-01\") // lastLogin > \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a greater than or equal to (≥) condition for type-safe attribute comparison.\n * Tests if the specified attribute is greater than or equal to the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is greater than or equal to value\n *\n * @example\n * ```typescript\n * interface Product { rating: number; version: string; releaseDate: string; }\n *\n * // Minimum ratings\n * op.gte(\"rating\", 4.0) // rating >= 4.0 (highly rated)\n *\n * // Version requirements\n * op.gte(\"version\", \"2.0.0\") // version >= \"2.0.0\"\n *\n * // Release date filters\n * op.gte(\"releaseDate\", \"2024-01-01\") // releaseDate >= \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a between condition for type-safe range comparison.\n * Tests if the specified attribute value falls within the inclusive range [lower, upper].\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param lower - The lower bound of the range (inclusive, must match attribute type)\n * @param upper - The upper bound of the range (inclusive, must match attribute type)\n * @returns A condition that evaluates to true when lower ≤ attr ≤ upper\n *\n * @example\n * ```typescript\n * interface Event { price: number; date: string; priority: number; }\n *\n * // Price range\n * op.between(\"price\", 50, 200) // price BETWEEN 50 AND 200\n *\n * // Date range\n * op.between(\"date\", \"2024-01-01\", \"2024-12-31\") // date BETWEEN \"2024-01-01\" AND \"2024-12-31\"\n *\n * // Priority levels\n * op.between(\"priority\", 1, 5) // priority BETWEEN 1 AND 5\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n\n /**\n * Creates an IN condition for type-safe list membership testing.\n * Tests if the specified attribute value matches any value in the provided list.\n * Supports up to 100 values in the list as per DynamoDB limitations.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param values - Array of values to test against (must match attribute type, max 100 items)\n * @returns A condition that evaluates to true when attr matches any value in the list\n *\n * @example\n * ```typescript\n * interface User { status: string; role: string; priority: number; }\n *\n * // Status filtering\n * op.inArray(\"status\", [\"ACTIVE\", \"PENDING\", \"PROCESSING\"]) // status IN (\"ACTIVE\", \"PENDING\", \"PROCESSING\")\n *\n * // Role-based access\n * op.inArray(\"role\", [\"admin\", \"moderator\", \"editor\"]) // role IN (\"admin\", \"moderator\", \"editor\")\n *\n * // Priority levels\n * op.inArray(\"priority\", [1, 2, 3]) // priority IN (1, 2, 3)\n * ```\n *\n * @throws {Error} When values array is empty or contains more than 100 items\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}\n */\n inArray: <K extends Path<T>>(attr: K, values: PathType<T, K>[]) => Condition;\n\n /**\n * Creates a begins_with condition for type-safe string prefix testing.\n * Tests if the specified string attribute starts with the provided substring.\n * Only works with string attributes - will fail on other data types.\n *\n * @param attr - The string attribute path to test (with full type safety)\n * @param value - The prefix string to test for (must match attribute type)\n * @returns A condition that evaluates to true when attr starts with value\n *\n * @example\n * ```typescript\n * interface User { email: string; name: string; id: string; }\n *\n * // Email domain filtering\n * op.beginsWith(\"email\", \"admin@\") // begins_with(email, \"admin@\")\n *\n * // Name prefix search\n * op.beginsWith(\"name\", \"John\") // begins_with(name, \"John\")\n *\n * // ID pattern matching\n * op.beginsWith(\"id\", \"USER#\") // begins_with(id, \"USER#\")\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a contains condition for type-safe substring or set membership testing.\n * For strings: tests if the attribute contains the specified substring.\n * For sets: tests if the set contains the specified element.\n *\n * @param attr - The attribute path to test (with full type safety)\n * @param value - The substring or element to search for (must match attribute type)\n * @returns A condition that evaluates to true when attr contains value\n *\n * @example\n * ```typescript\n * interface Post { content: string; tags: Set<string>; categories: string[]; }\n *\n * // Substring search in content\n * op.contains(\"content\", \"important\") // contains(content, \"important\")\n *\n * // Tag membership (for DynamoDB String Sets)\n * op.contains(\"tags\", \"featured\") // contains(tags, \"featured\")\n *\n * // Category search (for string arrays stored as lists)\n * op.contains(\"categories\", \"technology\") // contains(categories, \"technology\")\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates an attribute_exists condition for type-safe attribute presence testing.\n * Tests if the specified attribute exists in the item, regardless of its value.\n * Useful for filtering items that have optional attributes populated.\n *\n * @param attr - The attribute path to test for existence (with full type safety)\n * @returns A condition that evaluates to true when the attribute exists\n *\n * @example\n * ```typescript\n * interface User { email: string; phone?: string; profile?: { avatar?: string; }; }\n *\n * // Check for optional fields\n * op.attributeExists(\"phone\") // attribute_exists(phone)\n *\n * // Check for nested optional attributes\n * op.attributeExists(\"profile.avatar\") // attribute_exists(profile.avatar)\n *\n * // Useful in combination with other conditions\n * op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.attributeExists(\"email\") // Only active users with email\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n\n /**\n * Creates an attribute_not_exists condition for type-safe attribute absence testing.\n * Tests if the specified attribute does not exist in the item.\n * Useful for conditional writes to prevent overwriting existing data.\n *\n * @param attr - The attribute path to test for absence (with full type safety)\n * @returns A condition that evaluates to true when the attribute does not exist\n *\n * @example\n * ```typescript\n * interface User { id: string; email: string; deletedAt?: string; }\n *\n * // Ensure item hasn't been soft-deleted\n * op.attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n *\n * // Prevent duplicate creation\n * op.attributeNotExists(\"id\") // attribute_not_exists(id)\n *\n * // Conditional updates\n * op.and(\n * op.eq(\"status\", \"PENDING\"),\n * op.attributeNotExists(\"processedAt\") // Only unprocessed items\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n\n /**\n * Combines multiple conditions with logical AND operator.\n * All provided conditions must evaluate to true for the AND condition to be true.\n * Supports any number of conditions as arguments.\n *\n * @param conditions - Variable number of conditions to combine with AND\n * @returns A condition that evaluates to true when all input conditions are true\n *\n * @example\n * ```typescript\n * interface User { status: string; age: number; role: string; verified: boolean; }\n *\n * // Multiple criteria\n * op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.eq(\"verified\", true)\n * ) // status = \"ACTIVE\" AND age > 18 AND verified = true\n *\n * // Complex business logic\n * op.and(\n * op.inArray(\"role\", [\"admin\", \"moderator\"]),\n * op.attributeExists(\"permissions\"),\n * op.ne(\"status\", \"SUSPENDED\")\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\n and: (...conditions: Condition[]) => Condition;\n\n /**\n * Combines multiple conditions with logical OR operator.\n * At least one of the provided conditions must evaluate to true for the OR condition to be true.\n * Supports any number of conditions as arguments.\n *\n * @param conditions - Variable number of conditions to combine with OR\n * @returns A condition that evaluates to true when any input condition is true\n *\n * @example\n * ```typescript\n * interface Order { status: string; priority: string; urgent: boolean; }\n *\n * // Alternative statuses\n * op.or(\n * op.eq(\"status\", \"PENDING\"),\n * op.eq(\"status\", \"PROCESSING\"),\n * op.eq(\"status\", \"SHIPPED\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\" OR status = \"SHIPPED\"\n *\n * // High priority items\n * op.or(\n * op.eq(\"priority\", \"HIGH\"),\n * op.eq(\"urgent\", true)\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\n or: (...conditions: Condition[]) => Condition;\n\n /**\n * Negates a condition with logical NOT operator.\n * Inverts the boolean result of the provided condition.\n *\n * @param condition - The condition to negate\n * @returns A condition that evaluates to true when the input condition is false\n *\n * @example\n * ```typescript\n * interface User { status: string; role: string; banned: boolean; }\n *\n * // Exclude specific status\n * op.not(op.eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n *\n * // Complex negation\n * op.not(\n * op.and(\n * op.eq(\"role\", \"guest\"),\n * op.eq(\"banned\", true)\n * )\n * ) // NOT (role = \"guest\" AND banned = true)\n *\n * // Exclude multiple values\n * op.not(op.inArray(\"status\", [\"DELETED\", \"ARCHIVED\"]))\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\n not: (condition: Condition) => Condition;\n};\n\n/**\n * Primary key type for QUERY operations.\n * Allows building complex key conditions for the sort key.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}\n *\n * @example\n * // Query items with a specific partition key and sort key prefix\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#2023\")\n * })\n *\n * @example\n * // Query items within a specific sort key range\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.between(\"ORDER#2023-01\", \"ORDER#2023-12\")\n * })\n */\nexport type PrimaryKey = {\n /** Partition key value */\n pk: string;\n /** Optional sort key condition builder */\n sk?: (op: KeyConditionOperator) => Condition;\n};\n\n/**\n * Primary key type for GET and DELETE operations.\n * Used when you need to specify exact key values without conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}\n *\n * @example\n * // Get a specific item by its complete primary key\n * table.get({\n * pk: \"USER#123\",\n * sk: \"PROFILE#123\"\n * })\n *\n * @example\n * // Delete a specific item by its complete primary key\n * table.delete({\n * pk: \"USER#123\",\n * sk: \"ORDER#456\"\n * })\n */\nexport type PrimaryKeyWithoutExpression = {\n /** Partition key value */\n pk: string;\n /** Optional sort key value */\n sk?: string;\n};\n","import type { DeleteBuilder } from \"./builders/delete-builder\";\nimport type { GetBuilder } from \"./builders/get-builder\";\nimport type { PutBuilder } from \"./builders/put-builder\";\nimport type { ScanBuilder } from \"./builders/scan-builder\";\nimport type { UpdateBuilder } from \"./builders/update-builder\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type { Table } from \"./table\";\nimport type { DynamoItem, Index, TableConfig } from \"./types\";\nimport { eq, type PrimaryKey, type PrimaryKeyWithoutExpression } from \"./conditions\";\nimport type { QueryBuilder } from \"./builders/query-builder\";\nimport type { TransactionBuilder } from \"./builders/transaction-builder\";\n\n// Define the QueryFunction type with a generic return type\nexport type QueryFunction<T extends DynamoItem, I, R> = (input: I) => R;\n\n// Define a type for the query record that preserves the input type for each query function\nexport type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {\n schema?: StandardSchemaV1<I>;\n};\n\nexport type QueryRecord<T extends DynamoItem> = {\n // biome-ignore lint/suspicious/noExplicitAny: This is for flexibility\n [K: string]: QueryFunctionWithSchema<T, any, ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>;\n};\n\n// Define a type for entity with only scan, get and query methods\nexport type QueryEntity<T extends DynamoItem> = {\n scan: () => ScanBuilder<T>;\n get: (key: PrimaryKeyWithoutExpression) => GetBuilder<T>;\n query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;\n};\n\ninterface Settings {\n /**\n * Defaults to \"entityType\"\n */\n entityTypeAttributeName?: string;\n timestamps?: {\n createdAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"createdAt\"\n */\n attributeName?: string;\n };\n updatedAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"updatedAt\"\n */\n attributeName?: string;\n };\n };\n}\n\nexport interface EntityConfig<\n T extends DynamoItem,\n TInput extends DynamoItem = T,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n name: string;\n schema: StandardSchemaV1<TInput, T>;\n primaryKey: IndexDefinition<I>;\n indexes?: Record<string, Index>;\n queries: Q;\n settings?: Settings;\n}\n\nexport interface EntityRepository<\n /**\n * The Entity Type (output type)\n */\n T extends DynamoItem,\n /**\n * The Input Type (for create operations)\n */\n TInput extends DynamoItem = T,\n /**\n * The Primary Index (Partition index) Type\n */\n I extends DynamoItem = T,\n /**\n * The Queries object\n */\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n create: (data: TInput) => PutBuilder<T>;\n upsert: (data: TInput & I) => PutBuilder<T>;\n get: (key: I) => GetBuilder<T>;\n update: (key: I, data: Partial<T>) => UpdateBuilder<T>;\n delete: (key: I) => DeleteBuilder;\n query: Q;\n scan: () => ScanBuilder<T>;\n}\n\n/**\n * Creates an entity definition with type-safe operations\n *\n * @example\n * ```typescript\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * const UserEntity = defineEntity<User>({\n * name: \"User\",\n * schema: userSchema,\n * primaryKey: primaryKey,\n * });\n * ```\n */\nexport function defineEntity<\n T extends DynamoItem,\n TInput extends DynamoItem = T,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n>(config: EntityConfig<T, TInput, I, Q>) {\n const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? \"entityType\";\n\n /**\n * Generates an object containing timestamp attributes based on the given configuration settings.\n * The function determines the presence and format of \"createdAt\" and \"updatedAt\" timestamps dynamically.\n *\n * @param {Array<\"createdAt\" | \"updatedAt\">} [timestampTypes] - Optional array of timestamp types to generate. If not provided, all configured timestamps will be generated.\n * @returns {Record<string, string | number>} An object containing one or both of the \"createdAt\" and \"updatedAt\" timestamp attributes, depending on the configuration and requested types. Each timestamp can be formatted as either an ISO string or a UNIX timestamp.\n *\n * @throws Will not throw errors but depends on `config.settings?.timestamps` to be properly defined.\n * - If `createdAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.createdAt.attributeName` or defaults to \"createdAt\".\n * - If `updatedAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.updatedAt.attributeName` or defaults to \"updatedAt\".\n *\n * Configuration Details:\n * - `config.settings.timestamps.createdAt.format`: Determines the format of the \"createdAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n * - `config.settings.timestamps.updatedAt.format`: Determines the format of the \"updatedAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n *\n * The returned object keys and values depend on the provided configuration and requested timestamp types.\n */\n const generateTimestamps = (timestampTypes?: Array<\"createdAt\" | \"updatedAt\">): Record<string, string | number> => {\n if (!config.settings?.timestamps) return {};\n\n const timestamps: Record<string, string | number> = {};\n const now = new Date();\n const unixTime = Math.floor(Date.now() / 1000);\n\n const { createdAt, updatedAt } = config.settings.timestamps;\n\n // If no specific types are provided, generate all configured timestamps\n const typesToGenerate = timestampTypes || [\"createdAt\", \"updatedAt\"];\n\n if (createdAt && typesToGenerate.includes(\"createdAt\")) {\n const name = createdAt.attributeName ?? \"createdAt\";\n timestamps[name] = createdAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n if (updatedAt && typesToGenerate.includes(\"updatedAt\")) {\n const name = updatedAt.attributeName ?? \"updatedAt\";\n timestamps[name] = updatedAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n return timestamps;\n };\n\n return {\n name: config.name,\n createRepository: (table: Table): EntityRepository<T, TInput, I, Q> => {\n // Create a repository\n const repository = {\n create: (data: TInput) => {\n // Create a minimal builder without validation or key generation\n // We'll defer all processing until execute() or withTransaction() is called\n const builder = table.create<T>({} as T);\n\n // Core function that handles validation, key generation, and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\n // Validate data to ensure defaults are applied before key generation\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case\n const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;\n\n if (\"issues\" in validatedData && validatedData.issues) {\n throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(validatedData.value as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validatedData.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n ...(validatedData.value as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation, key generation, and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen for most schemas, but we need to handle it\n if (validationResult instanceof Promise) {\n throw new Error(\n \"Async validation is not supported in create method. The schema must support synchronous validation for transaction compatibility.\",\n );\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(validationResult.value as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validationResult.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n ...(validationResult.value as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n return await originalExecute.call(builder);\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const wrappedWithTransaction = (transaction: any) => {\n prepareValidatedItemSync();\n return originalWithTransaction.call(builder, transaction);\n };\n\n // Copy all properties from the original function to preserve mock functionality\n Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);\n const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);\n for (let i = 0; i < propertyNames.length; i++) {\n const prop = propertyNames[i] as string;\n if (prop !== \"length\" && prop !== \"name\" && prop !== \"prototype\") {\n try {\n // biome-ignore lint/suspicious/noExplicitAny: Make it work\n (wrappedWithTransaction as any)[prop] = (originalWithTransaction as any)[prop];\n } catch (e) {\n // Ignore errors for non-configurable properties\n }\n }\n }\n\n builder.withTransaction = wrappedWithTransaction;\n }\n\n return builder;\n },\n\n upsert: (data: TInput & I) => {\n // Create a minimal builder without validation or key generation\n // We'll defer all processing until execute() or withTransaction() is called\n const builder = table.put<T>({} as T);\n\n // Core function that handles validation, key generation, and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case\n const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;\n\n if (\"issues\" in validatedData && validatedData.issues) {\n throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const primaryKey = config.primaryKey.generateKey(validatedData.value as unknown as TInput & I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validatedData.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validatedData.value,\n [entityTypeAttributeName]: config.name,\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation, key generation, and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen in withTransaction but we need to handle it for type safety\n if (validationResult instanceof Promise) {\n throw new Error(\"Async validation is not supported in withTransaction. Use execute() instead.\");\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const primaryKey = config.primaryKey.generateKey(validationResult.value as unknown as TInput & I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validationResult.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to upsert item\");\n }\n return result;\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n const wrappedWithTransaction = (transaction: TransactionBuilder) => {\n prepareValidatedItemSync();\n return originalWithTransaction.call(builder, transaction);\n };\n\n // Copy all properties from the original function to preserve mock functionality\n Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);\n const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);\n for (let i = 0; i < propertyNames.length; i++) {\n const prop = propertyNames[i] as string;\n if (prop !== \"length\" && prop !== \"name\" && prop !== \"prototype\") {\n try {\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n (wrappedWithTransaction as any)[prop] = (originalWithTransaction as any)[prop];\n } catch (e) {\n // Ignore errors for non-configurable properties\n }\n }\n }\n\n builder.withTransaction = wrappedWithTransaction;\n }\n\n return builder;\n },\n\n get: <K extends I>(key: K) => table.get<T>(config.primaryKey.generateKey(key)),\n\n update: <K extends I>(key: K, data: Partial<T>) => {\n const primaryKeyObj = config.primaryKey.generateKey(key);\n const builder = table.update<T>(primaryKeyObj);\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Use only updatedAt timestamp for updates\n const timestamps = generateTimestamps([\"updatedAt\"]);\n\n builder.set({ ...data, ...timestamps });\n return builder;\n },\n\n delete: <K extends I>(key: K) => {\n const builder = table.delete(config.primaryKey.generateKey(key));\n builder.condition(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n\n query: Object.entries(config.queries || {}).reduce((acc, [key, inputCallback]) => {\n // @ts-expect-error - We need to cast the queryFn to a function that takes an unknown input\n acc[key] = (input: unknown) => {\n // Create a QueryEntity object with only the necessary methods\n const queryEntity: QueryEntity<T> = {\n scan: repository.scan,\n get: (key: PrimaryKeyWithoutExpression) => table.get<T>(key),\n query: (keyCondition: PrimaryKey) => {\n return table.query<T>(keyCondition);\n },\n };\n\n // Execute the query function to get the builder - This type is incorrect and needs to be fixed\n const queryBuilderCallback = inputCallback(input);\n\n // Run the inner handler which allows the user to apply their desired contraints\n // to the query builder of their choice\n // @ts-expect-error - We need to cast the queryBuilderCallback to a function that takes a QueryEntity\n const builder = queryBuilderCallback(queryEntity);\n\n // Add entity type filter if the builder has filter method\n if (builder && typeof builder === \"object\" && \"filter\" in builder && typeof builder.filter === \"function\") {\n builder.filter(eq(entityTypeAttributeName, config.name));\n }\n\n // Wrap the builder's execute method if it exists\n if (builder && typeof builder === \"object\" && \"execute\" in builder) {\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate the input before executing the query\n const queryFn = (\n config.queries as unknown as Record<string, QueryFunctionWithSchema<T, I, typeof builder>>\n )[key];\n\n if (queryFn && typeof queryFn === \"function\") {\n // Get the schema from the query function\n const schema = queryFn.schema;\n if (schema?.[\"~standard\"]?.validate && typeof schema[\"~standard\"].validate === \"function\") {\n const validationResult = schema[\"~standard\"].validate(input);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(\n `Validation failed: ${validationResult.issues.map((issue) => issue.message).join(\", \")}`,\n );\n }\n }\n }\n\n // Execute the original builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to execute query\");\n }\n return result;\n };\n }\n\n return builder;\n };\n return acc;\n }, {} as Q),\n\n scan: () => {\n const builder = table.scan<T>();\n builder.filter(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n };\n\n return repository;\n },\n };\n}\n\nexport function createQueries<T extends DynamoItem>() {\n return {\n input: <I>(schema: StandardSchemaV1<I>) => ({\n query: <\n Q extends QueryRecord<T> = QueryRecord<T>,\n R = ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>,\n >(\n handler: (params: { input: I; entity: QueryEntity<T> }) => R,\n ) => {\n const queryFn = (input: I) => (entity: QueryEntity<T>) => handler({ input, entity });\n queryFn.schema = schema;\n return queryFn as unknown as QueryFunctionWithSchema<T, I, R>;\n },\n }),\n };\n}\n\nexport interface IndexDefinition<T extends DynamoItem> extends Index {\n name: string;\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n generateKey: (item: T) => ({ pk: pkFn(item), sk: skFn(item) }),\n }) as IndexDefinition<T>,\n\n withoutSortKey: () =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n generateKey: (item: T) => ({ pk: pkFn(item) }),\n }) as IndexDefinition<T>,\n }),\n }),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/conditions.ts","../src/builders/entity-aware-builders.ts","../src/entity.ts"],"names":["key"],"mappings":";AAiGO,IAAM,yBAAA,GACX,CAAC,IAAA,KACD,CAAC,MAAc,KAAA,MAA+B;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,CAAA;AAQK,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;;;ACrGhD,SAAS,wBAAA,CACP,SACA,UAAA,EACqC;AACrC,EAAA,OAAO,IAAI,MAAM,OAAA,EAAS;AAAA,IACxB,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,QAAA,EAAU;AAE1B,MAAA,IAAI,SAAS,YAAA,EAAc;AACzB,QAAA,OAAO,UAAA;AAAA,MACT;AAGA,MAAA,IAAI,SAAS,WAAA,IAAe,OAAQ,MAAA,CAAmC,IAAI,MAAM,UAAA,EAAY;AAC3F,QAAA,OAAO,CAIL,OACA,UAAA,KACG;AAEH,UAAA,MAAM,YAAY,UAAA,IAAe,UAAA;AACjC,UAAA,MAAM,EAAA,GAAM,OAAmC,IAAI,CAAA;AAKnD,UAAA,OAAO,EAAA,CAAG,IAAA,CAAK,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA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,EAAyB,MAAA,CAAO,IAAI,CAAC,CAAA;AACvD,UAAA,OAAO,OAAA;AAAA,QACT;AAAA,OACF;AAEA,MAAA,OAAO,UAAA;AAAA,IACT;AAAA,GACF;AACF;AAEO,SAAS,aAAA,GAAsC;AACpD,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,CAAI,MAAA,MAAiC;AAAA,MAC1C,KAAA,EAAO,CAIL,OAAA,KACG;AACH,QAAA,MAAM,OAAA,GAAU,CAAC,KAAA,KAAa,CAAC,WAA2B,OAAA,CAAQ,EAAE,KAAA,EAAO,MAAA,EAAQ,CAAA;AACnF,QAAA,OAAA,CAAQ,MAAA,GAAS,MAAA;AACjB,QAAA,OAAO,OAAA;AAAA,MACT;AAAA,KACF;AAAA,GACF;AACF;AAOO,SAAS,WAAA,GAAc;AAC5B,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,CAAuB,MAAA,MAAiC;AAAA,MAC7D,YAAA,EAAc,CAAgC,IAAA,MAAa;AAAA,QACzD,OAAA,EAAS,CAAgC,IAAA,MACtC;AAAA,UACC,IAAA,EAAM,QAAA;AAAA,UACN,YAAA,EAAc,IAAA;AAAA,UACd,OAAA,EAAS,IAAA;AAAA,UACT,WAAA,EAAa,CAAC,IAAA,MAAa,EAAE,EAAA,EAAI,IAAA,CAAK,IAAI,CAAA,EAAG,EAAA,EAAI,IAAA,CAAK,IAAI,CAAA,EAAE;AAAA,SAC9D,CAAA;AAAA,QAEF,gBAAgB,OACb;AAAA,UACC,IAAA,EAAM,QAAA;AAAA,UACN,YAAA,EAAc,IAAA;AAAA,UACd,aAAa,CAAC,IAAA,MAAa,EAAE,EAAA,EAAI,IAAA,CAAK,IAAI,CAAA,EAAE;AAAA,SAC9C;AAAA,OACJ;AAAA,KACF;AAAA,GACF;AACF","file":"entity.js","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - in: Checks if attribute value is in a list of values\n * - beginsWith: Checks if string attribute begins with specified substring\n * - contains: Checks if string/set attribute contains specified value\n * - attributeExists: Checks if attribute exists\n * - attributeNotExists: Checks if attribute does not exist\n */\nexport type ComparisonOperator =\n | \"eq\"\n | \"ne\"\n | \"lt\"\n | \"lte\"\n | \"gt\"\n | \"gte\"\n | \"between\"\n | \"in\"\n | \"beginsWith\"\n | \"contains\"\n | \"attributeExists\"\n | \"attributeNotExists\";\n\n/**\n * Logical operators for combining multiple conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}\n *\n * - and: Evaluates to true if all conditions are true\n * - or: Evaluates to true if any condition is true\n * - not: Negate the result of a condition\n */\nexport type LogicalOperator = \"and\" | \"or\" | \"not\";\n\n/**\n * Represents a DynamoDB condition expression.\n * Can be either a comparison condition or a logical combination of conditions.\n *\n * @example\n * // Simple comparison condition\n * const condition: Condition = {\n * type: \"eq\",\n * attr: \"status\",\n * value: \"ACTIVE\"\n * };\n *\n * @example\n * // Logical combination of conditions\n * const condition: Condition = {\n * type: \"and\",\n * conditions: [\n * { type: \"eq\", attr: \"status\", value: \"ACTIVE\" },\n * { type: \"gt\", attr: \"age\", value: 5 }\n * ]\n * };\n */\nexport interface Condition {\n /** The type of condition (comparison or logical operator) */\n type: ComparisonOperator | LogicalOperator;\n /** The attribute name for comparison conditions */\n attr?: string;\n /** The value to compare against for comparison conditions */\n value?: unknown;\n /** Array of conditions for logical operators (and/or) */\n conditions?: Condition[];\n /** Single condition for the 'not' operator */\n condition?: Condition;\n}\n\n/**\n * Parameters used to build DynamoDB expression strings.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}\n */\nexport interface ExpressionParams {\n /** Map of attribute name placeholders to actual attribute names */\n expressionAttributeNames: Record<string, string>;\n /** Map of value placeholders to actual values */\n expressionAttributeValues: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates an in condition that checks if a value is in a list of values\n * @example\n * inArray(\"status\", [\"ACTIVE\", \"PENDING\", \"PROCESSING\"]) // status IN (\"ACTIVE\", \"PENDING\", \"PROCESSING\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}\n */\nexport const inArray = (attr: string, values: unknown[]): Condition => ({\n type: \"in\",\n attr,\n value: values,\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n /**\n * Creates an equals (=) condition for type-safe attribute comparison.\n * Tests if the specified attribute equals the provided value.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr equals value\n *\n * @example\n * ```typescript\n * interface User { status: string; age: number; }\n *\n * // String comparison\n * op.eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n *\n * // Numeric comparison\n * op.eq(\"age\", 25) // age = 25\n *\n * // Nested attribute\n * op.eq(\"profile.role\", \"admin\") // profile.role = \"admin\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a not equals (≠ / <>) condition for type-safe attribute comparison.\n * Tests if the specified attribute does not equal the provided value.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr does not equal value\n *\n * @example\n * ```typescript\n * interface User { status: string; priority: number; }\n *\n * // String comparison\n * op.ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n *\n * // Numeric comparison\n * op.ne(\"priority\", 0) // priority <> 0\n *\n * // Useful for filtering out specific values\n * op.ne(\"category\", \"ARCHIVED\") // category <> \"ARCHIVED\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a less than (<) condition for type-safe attribute comparison.\n * Tests if the specified attribute is less than the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is less than value\n *\n * @example\n * ```typescript\n * interface Product { price: number; name: string; createdAt: string; }\n *\n * // Numeric comparison\n * op.lt(\"price\", 100) // price < 100\n *\n * // String comparison (lexicographic)\n * op.lt(\"name\", \"M\") // name < \"M\" (names starting with A-L)\n *\n * // Date comparison (ISO strings)\n * op.lt(\"createdAt\", \"2024-01-01\") // createdAt < \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a less than or equal to (≤) condition for type-safe attribute comparison.\n * Tests if the specified attribute is less than or equal to the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is less than or equal to value\n *\n * @example\n * ```typescript\n * interface Order { total: number; priority: number; dueDate: string; }\n *\n * // Numeric comparison\n * op.lte(\"total\", 1000) // total <= 1000\n *\n * // Priority levels\n * op.lte(\"priority\", 3) // priority <= 3 (low to medium priority)\n *\n * // Date deadlines\n * op.lte(\"dueDate\", \"2024-12-31\") // dueDate <= \"2024-12-31\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a greater than (>) condition for type-safe attribute comparison.\n * Tests if the specified attribute is greater than the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is greater than value\n *\n * @example\n * ```typescript\n * interface User { age: number; score: number; lastLogin: string; }\n *\n * // Age restrictions\n * op.gt(\"age\", 18) // age > 18 (adults only)\n *\n * // Performance thresholds\n * op.gt(\"score\", 85) // score > 85 (high performers)\n *\n * // Recent activity\n * op.gt(\"lastLogin\", \"2024-01-01\") // lastLogin > \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a greater than or equal to (≥) condition for type-safe attribute comparison.\n * Tests if the specified attribute is greater than or equal to the provided value.\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param value - The value to compare against (must match attribute type)\n * @returns A condition that evaluates to true when attr is greater than or equal to value\n *\n * @example\n * ```typescript\n * interface Product { rating: number; version: string; releaseDate: string; }\n *\n * // Minimum ratings\n * op.gte(\"rating\", 4.0) // rating >= 4.0 (highly rated)\n *\n * // Version requirements\n * op.gte(\"version\", \"2.0.0\") // version >= \"2.0.0\"\n *\n * // Release date filters\n * op.gte(\"releaseDate\", \"2024-01-01\") // releaseDate >= \"2024-01-01\"\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}\n */\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a between condition for type-safe range comparison.\n * Tests if the specified attribute value falls within the inclusive range [lower, upper].\n * Works with numbers, strings (lexicographic), and dates.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param lower - The lower bound of the range (inclusive, must match attribute type)\n * @param upper - The upper bound of the range (inclusive, must match attribute type)\n * @returns A condition that evaluates to true when lower ≤ attr ≤ upper\n *\n * @example\n * ```typescript\n * interface Event { price: number; date: string; priority: number; }\n *\n * // Price range\n * op.between(\"price\", 50, 200) // price BETWEEN 50 AND 200\n *\n * // Date range\n * op.between(\"date\", \"2024-01-01\", \"2024-12-31\") // date BETWEEN \"2024-01-01\" AND \"2024-12-31\"\n *\n * // Priority levels\n * op.between(\"priority\", 1, 5) // priority BETWEEN 1 AND 5\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n\n /**\n * Creates an IN condition for type-safe list membership testing.\n * Tests if the specified attribute value matches any value in the provided list.\n * Supports up to 100 values in the list as per DynamoDB limitations.\n *\n * @param attr - The attribute path to compare (with full type safety)\n * @param values - Array of values to test against (must match attribute type, max 100 items)\n * @returns A condition that evaluates to true when attr matches any value in the list\n *\n * @example\n * ```typescript\n * interface User { status: string; role: string; priority: number; }\n *\n * // Status filtering\n * op.inArray(\"status\", [\"ACTIVE\", \"PENDING\", \"PROCESSING\"]) // status IN (\"ACTIVE\", \"PENDING\", \"PROCESSING\")\n *\n * // Role-based access\n * op.inArray(\"role\", [\"admin\", \"moderator\", \"editor\"]) // role IN (\"admin\", \"moderator\", \"editor\")\n *\n * // Priority levels\n * op.inArray(\"priority\", [1, 2, 3]) // priority IN (1, 2, 3)\n * ```\n *\n * @throws {Error} When values array is empty or contains more than 100 items\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}\n */\n inArray: <K extends Path<T>>(attr: K, values: PathType<T, K>[]) => Condition;\n\n /**\n * Creates a begins_with condition for type-safe string prefix testing.\n * Tests if the specified string attribute starts with the provided substring.\n * Only works with string attributes - will fail on other data types.\n *\n * @param attr - The string attribute path to test (with full type safety)\n * @param value - The prefix string to test for (must match attribute type)\n * @returns A condition that evaluates to true when attr starts with value\n *\n * @example\n * ```typescript\n * interface User { email: string; name: string; id: string; }\n *\n * // Email domain filtering\n * op.beginsWith(\"email\", \"admin@\") // begins_with(email, \"admin@\")\n *\n * // Name prefix search\n * op.beginsWith(\"name\", \"John\") // begins_with(name, \"John\")\n *\n * // ID pattern matching\n * op.beginsWith(\"id\", \"USER#\") // begins_with(id, \"USER#\")\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates a contains condition for type-safe substring or set membership testing.\n * For strings: tests if the attribute contains the specified substring.\n * For sets: tests if the set contains the specified element.\n *\n * @param attr - The attribute path to test (with full type safety)\n * @param value - The substring or element to search for (must match attribute type)\n * @returns A condition that evaluates to true when attr contains value\n *\n * @example\n * ```typescript\n * interface Post { content: string; tags: Set<string>; categories: string[]; }\n *\n * // Substring search in content\n * op.contains(\"content\", \"important\") // contains(content, \"important\")\n *\n * // Tag membership (for DynamoDB String Sets)\n * op.contains(\"tags\", \"featured\") // contains(tags, \"featured\")\n *\n * // Category search (for string arrays stored as lists)\n * op.contains(\"categories\", \"technology\") // contains(categories, \"technology\")\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n\n /**\n * Creates an attribute_exists condition for type-safe attribute presence testing.\n * Tests if the specified attribute exists in the item, regardless of its value.\n * Useful for filtering items that have optional attributes populated.\n *\n * @param attr - The attribute path to test for existence (with full type safety)\n * @returns A condition that evaluates to true when the attribute exists\n *\n * @example\n * ```typescript\n * interface User { email: string; phone?: string; profile?: { avatar?: string; }; }\n *\n * // Check for optional fields\n * op.attributeExists(\"phone\") // attribute_exists(phone)\n *\n * // Check for nested optional attributes\n * op.attributeExists(\"profile.avatar\") // attribute_exists(profile.avatar)\n *\n * // Useful in combination with other conditions\n * op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.attributeExists(\"email\") // Only active users with email\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n\n /**\n * Creates an attribute_not_exists condition for type-safe attribute absence testing.\n * Tests if the specified attribute does not exist in the item.\n * Useful for conditional writes to prevent overwriting existing data.\n *\n * @param attr - The attribute path to test for absence (with full type safety)\n * @returns A condition that evaluates to true when the attribute does not exist\n *\n * @example\n * ```typescript\n * interface User { id: string; email: string; deletedAt?: string; }\n *\n * // Ensure item hasn't been soft-deleted\n * op.attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n *\n * // Prevent duplicate creation\n * op.attributeNotExists(\"id\") // attribute_not_exists(id)\n *\n * // Conditional updates\n * op.and(\n * op.eq(\"status\", \"PENDING\"),\n * op.attributeNotExists(\"processedAt\") // Only unprocessed items\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n\n /**\n * Combines multiple conditions with logical AND operator.\n * All provided conditions must evaluate to true for the AND condition to be true.\n * Supports any number of conditions as arguments.\n *\n * @param conditions - Variable number of conditions to combine with AND\n * @returns A condition that evaluates to true when all input conditions are true\n *\n * @example\n * ```typescript\n * interface User { status: string; age: number; role: string; verified: boolean; }\n *\n * // Multiple criteria\n * op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.eq(\"verified\", true)\n * ) // status = \"ACTIVE\" AND age > 18 AND verified = true\n *\n * // Complex business logic\n * op.and(\n * op.inArray(\"role\", [\"admin\", \"moderator\"]),\n * op.attributeExists(\"permissions\"),\n * op.ne(\"status\", \"SUSPENDED\")\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\n and: (...conditions: Condition[]) => Condition;\n\n /**\n * Combines multiple conditions with logical OR operator.\n * At least one of the provided conditions must evaluate to true for the OR condition to be true.\n * Supports any number of conditions as arguments.\n *\n * @param conditions - Variable number of conditions to combine with OR\n * @returns A condition that evaluates to true when any input condition is true\n *\n * @example\n * ```typescript\n * interface Order { status: string; priority: string; urgent: boolean; }\n *\n * // Alternative statuses\n * op.or(\n * op.eq(\"status\", \"PENDING\"),\n * op.eq(\"status\", \"PROCESSING\"),\n * op.eq(\"status\", \"SHIPPED\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\" OR status = \"SHIPPED\"\n *\n * // High priority items\n * op.or(\n * op.eq(\"priority\", \"HIGH\"),\n * op.eq(\"urgent\", true)\n * )\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\n or: (...conditions: Condition[]) => Condition;\n\n /**\n * Negates a condition with logical NOT operator.\n * Inverts the boolean result of the provided condition.\n *\n * @param condition - The condition to negate\n * @returns A condition that evaluates to true when the input condition is false\n *\n * @example\n * ```typescript\n * interface User { status: string; role: string; banned: boolean; }\n *\n * // Exclude specific status\n * op.not(op.eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n *\n * // Complex negation\n * op.not(\n * op.and(\n * op.eq(\"role\", \"guest\"),\n * op.eq(\"banned\", true)\n * )\n * ) // NOT (role = \"guest\" AND banned = true)\n *\n * // Exclude multiple values\n * op.not(op.inArray(\"status\", [\"DELETED\", \"ARCHIVED\"]))\n * ```\n *\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\n not: (condition: Condition) => Condition;\n};\n\n/**\n * Primary key type for QUERY operations.\n * Allows building complex key conditions for the sort key.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}\n *\n * @example\n * // Query items with a specific partition key and sort key prefix\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#2023\")\n * })\n *\n * @example\n * // Query items within a specific sort key range\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.between(\"ORDER#2023-01\", \"ORDER#2023-12\")\n * })\n */\nexport type PrimaryKey = {\n /** Partition key value */\n pk: string;\n /** Optional sort key condition builder */\n sk?: (op: KeyConditionOperator) => Condition;\n};\n\n/**\n * Primary key type for GET and DELETE operations.\n * Used when you need to specify exact key values without conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}\n *\n * @example\n * // Get a specific item by its complete primary key\n * table.get({\n * pk: \"USER#123\",\n * sk: \"PROFILE#123\"\n * })\n *\n * @example\n * // Delete a specific item by its complete primary key\n * table.delete({\n * pk: \"USER#123\",\n * sk: \"ORDER#456\"\n * })\n */\nexport type PrimaryKeyWithoutExpression = {\n /** Partition key value */\n pk: string;\n /** Optional sort key value */\n sk?: string;\n};\n","import type { DynamoItem } from \"../types\";\nimport type { BatchBuilder } from \"./batch-builder\";\nimport type { PutBuilder } from \"./put-builder\";\nimport type { GetBuilder } from \"./get-builder\";\nimport type { DeleteBuilder } from \"./delete-builder\";\n\n/**\n * Creates an entity-aware wrapper that automatically provides entity names to batch operations\n * while transparently delegating all other method calls to the underlying builder.\n */\nfunction createEntityAwareBuilder<T extends object>(\n builder: T,\n entityName: string,\n): T & { readonly entityName: string } {\n return new Proxy(builder, {\n get(target, prop, receiver) {\n // Expose the entity name as a readonly property\n if (prop === \"entityName\") {\n return entityName;\n }\n\n // Intercept withBatch method to provide automatic entity type inference\n if (prop === \"withBatch\" && typeof (target as Record<string, unknown>)[prop] === \"function\") {\n return <\n TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>,\n K extends keyof TEntities = keyof TEntities,\n >(\n batch: BatchBuilder<TEntities>,\n entityType?: K,\n ) => {\n // Use provided entityType or fall back to stored entityName\n const typeToUse = entityType ?? (entityName as K);\n const fn = (target as Record<string, unknown>)[prop] as (\n batch: BatchBuilder<TEntities>,\n entityType?: K,\n ) => unknown;\n // Call the function with the original target as 'this' context\n return fn.call(target, batch, typeToUse);\n };\n }\n\n // For all other properties/methods, delegate to the original builder\n return Reflect.get(target, prop, receiver);\n },\n }) as T & { readonly entityName: string };\n}\n\n/**\n * Entity-aware wrapper for PutBuilder that automatically provides entity name to batch operations\n */\nexport type EntityAwarePutBuilder<T extends DynamoItem> = PutBuilder<T> & {\n readonly entityName: string;\n};\n\n/**\n * Creates an entity-aware PutBuilder\n */\nexport function createEntityAwarePutBuilder<T extends DynamoItem>(\n builder: PutBuilder<T>,\n entityName: string,\n): EntityAwarePutBuilder<T> {\n return createEntityAwareBuilder(builder, entityName);\n}\n\n/**\n * Entity-aware wrapper for GetBuilder that automatically provides entity name to batch operations\n */\nexport type EntityAwareGetBuilder<T extends DynamoItem> = GetBuilder<T> & {\n readonly entityName: string;\n};\n\n/**\n * Creates an entity-aware GetBuilder\n */\nexport function createEntityAwareGetBuilder<T extends DynamoItem>(\n builder: GetBuilder<T>,\n entityName: string,\n): EntityAwareGetBuilder<T> {\n return createEntityAwareBuilder(builder, entityName);\n}\n\n/**\n * Entity-aware wrapper for DeleteBuilder that automatically provides entity name to batch operations\n */\nexport type EntityAwareDeleteBuilder = DeleteBuilder & {\n readonly entityName: string;\n};\n\n/**\n * Creates an entity-aware DeleteBuilder\n */\nexport function createEntityAwareDeleteBuilder(builder: DeleteBuilder, entityName: string): EntityAwareDeleteBuilder {\n return createEntityAwareBuilder(builder, entityName);\n}\n","import type { DeleteBuilder } from \"./builders/delete-builder\";\nimport type { GetBuilder } from \"./builders/get-builder\";\nimport type { PutBuilder } from \"./builders/put-builder\";\nimport type { ScanBuilder } from \"./builders/scan-builder\";\nimport type { UpdateBuilder } from \"./builders/update-builder\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type { Table } from \"./table\";\nimport type { DynamoItem, Index, TableConfig } from \"./types\";\nimport { eq, type PrimaryKey, type PrimaryKeyWithoutExpression } from \"./conditions\";\nimport type { QueryBuilder } from \"./builders/query-builder\";\nimport type { TransactionBuilder } from \"./builders/transaction-builder\";\nimport {\n createEntityAwarePutBuilder,\n createEntityAwareGetBuilder,\n createEntityAwareDeleteBuilder,\n} from \"./builders/entity-aware-builders\";\nimport type {\n EntityAwarePutBuilder,\n EntityAwareGetBuilder,\n EntityAwareDeleteBuilder,\n} from \"./builders/entity-aware-builders\";\n\n// Define the QueryFunction type with a generic return type\nexport type QueryFunction<T extends DynamoItem, I, R> = (input: I) => R;\n\n// Define a type for the query record that preserves the input type for each query function\nexport type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {\n schema?: StandardSchemaV1<I>;\n};\n\nexport type QueryRecord<T extends DynamoItem> = {\n // biome-ignore lint/suspicious/noExplicitAny: This is for flexibility\n [K: string]: QueryFunctionWithSchema<T, any, ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>;\n};\n\n// Define a type for entity with only scan, get and query methods\nexport type QueryEntity<T extends DynamoItem> = {\n scan: () => ScanBuilder<T>;\n get: (key: PrimaryKeyWithoutExpression) => EntityAwareGetBuilder<T>;\n query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;\n};\n\ninterface Settings {\n /**\n * Defaults to \"entityType\"\n */\n entityTypeAttributeName?: string;\n timestamps?: {\n createdAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"createdAt\"\n */\n attributeName?: string;\n };\n updatedAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"updatedAt\"\n */\n attributeName?: string;\n };\n };\n}\n\nexport interface EntityConfig<\n T extends DynamoItem,\n TInput extends DynamoItem = T,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n name: string;\n schema: StandardSchemaV1<TInput, T>;\n primaryKey: IndexDefinition<I>;\n indexes?: Record<string, Index>;\n queries: Q;\n settings?: Settings;\n}\n\nexport interface EntityRepository<\n /**\n * The Entity Type (output type)\n */\n T extends DynamoItem,\n /**\n * The Input Type (for create operations)\n */\n TInput extends DynamoItem = T,\n /**\n * The Primary Index (Partition index) Type\n */\n I extends DynamoItem = T,\n /**\n * The Queries object\n */\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n create: (data: TInput) => EntityAwarePutBuilder<T>;\n upsert: (data: TInput & I) => EntityAwarePutBuilder<T>;\n get: (key: I) => EntityAwareGetBuilder<T>;\n update: (key: I, data: Partial<T>) => UpdateBuilder<T>;\n delete: (key: I) => EntityAwareDeleteBuilder;\n query: Q;\n scan: () => ScanBuilder<T>;\n}\n\n/**\n * Creates an entity definition with type-safe operations\n *\n * @example\n * ```typescript\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * const UserEntity = defineEntity<User>({\n * name: \"User\",\n * schema: userSchema,\n * primaryKey: primaryKey,\n * });\n * ```\n */\nexport function defineEntity<\n T extends DynamoItem,\n TInput extends DynamoItem = T,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n>(config: EntityConfig<T, TInput, I, Q>) {\n const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? \"entityType\";\n\n /**\n * Utility function to wrap a method with preparation logic while preserving all properties\n * for mock compatibility. This reduces boilerplate for withTransaction and withBatch wrappers.\n */\n // biome-ignore lint/suspicious/noExplicitAny: Required for flexible method wrapping\n const wrapMethodWithPreparation = <TMethod extends (...args: any[]) => any>(\n originalMethod: TMethod,\n prepareFn: () => void,\n // biome-ignore lint/suspicious/noExplicitAny: Required for flexible context binding\n context: any,\n ): TMethod => {\n // biome-ignore lint/suspicious/noExplicitAny: Required for flexible argument handling\n const wrappedMethod = (...args: any[]) => {\n prepareFn();\n return originalMethod.call(context, ...args);\n };\n\n // Copy all properties from the original function to preserve mock functionality\n Object.setPrototypeOf(wrappedMethod, originalMethod);\n const propertyNames = Object.getOwnPropertyNames(originalMethod);\n for (let i = 0; i < propertyNames.length; i++) {\n const prop = propertyNames[i] as string;\n if (prop !== \"length\" && prop !== \"name\" && prop !== \"prototype\") {\n // Check if the property is writable before attempting to assign it\n const descriptor = Object.getOwnPropertyDescriptor(originalMethod, prop);\n if (descriptor && descriptor.writable !== false && !descriptor.get) {\n // biome-ignore lint/suspicious/noExplicitAny: meh\n (wrappedMethod as any)[prop] = (originalMethod as any)[prop];\n }\n }\n }\n\n return wrappedMethod as TMethod;\n };\n\n /**\n * Generates an object containing timestamp attributes based on the given configuration settings.\n * The function determines the presence and format of \"createdAt\" and \"updatedAt\" timestamps dynamically.\n *\n * @param {Array<\"createdAt\" | \"updatedAt\">} [timestampTypes] - Optional array of timestamp types to generate. If not provided, all configured timestamps will be generated.\n * @returns {Record<string, string | number>} An object containing one or both of the \"createdAt\" and \"updatedAt\" timestamp attributes, depending on the configuration and requested types. Each timestamp can be formatted as either an ISO string or a UNIX timestamp.\n *\n * @throws Will not throw errors but depends on `config.settings?.timestamps` to be properly defined.\n * - If `createdAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.createdAt.attributeName` or defaults to \"createdAt\".\n * - If `updatedAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.updatedAt.attributeName` or defaults to \"updatedAt\".\n *\n * Configuration Details:\n * - `config.settings.timestamps.createdAt.format`: Determines the format of the \"createdAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n * - `config.settings.timestamps.updatedAt.format`: Determines the format of the \"updatedAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n *\n * The returned object keys and values depend on the provided configuration and requested timestamp types.\n */\n const generateTimestamps = (timestampTypes?: Array<\"createdAt\" | \"updatedAt\">): Record<string, string | number> => {\n if (!config.settings?.timestamps) return {};\n\n const timestamps: Record<string, string | number> = {};\n const now = new Date();\n const unixTime = Math.floor(Date.now() / 1000);\n\n const { createdAt, updatedAt } = config.settings.timestamps;\n\n // If no specific types are provided, generate all configured timestamps\n const typesToGenerate = timestampTypes || [\"createdAt\", \"updatedAt\"];\n\n if (createdAt && typesToGenerate.includes(\"createdAt\")) {\n const name = createdAt.attributeName ?? \"createdAt\";\n timestamps[name] = createdAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n if (updatedAt && typesToGenerate.includes(\"updatedAt\")) {\n const name = updatedAt.attributeName ?? \"updatedAt\";\n timestamps[name] = updatedAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n return timestamps;\n };\n\n return {\n name: config.name,\n createRepository: (table: Table): EntityRepository<T, TInput, I, Q> => {\n // Create a repository\n const repository = {\n create: (data: TInput) => {\n // Create a minimal builder without validation or key generation\n // We'll defer all processing until execute() or withTransaction() is called\n const builder = table.create<T>({} as T);\n\n // Core function that handles validation, key generation, and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\n // Validate data to ensure defaults are applied before key generation\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case\n const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;\n\n if (\"issues\" in validatedData && validatedData.issues) {\n throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(validatedData.value as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validatedData.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n ...(validatedData.value as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation, key generation, and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen for most schemas, but we need to handle it\n if (validationResult instanceof Promise) {\n throw new Error(\n \"Async validation is not supported in create method. The schema must support synchronous validation for transaction compatibility.\",\n );\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(validationResult.value as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validationResult.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n ...(validationResult.value as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n return await originalExecute.call(builder);\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n builder.withTransaction = wrapMethodWithPreparation(\n originalWithTransaction,\n prepareValidatedItemSync,\n builder,\n );\n }\n\n // Wrap the builder's withBatch method\n const originalWithBatch = builder.withBatch;\n if (originalWithBatch) {\n builder.withBatch = wrapMethodWithPreparation(originalWithBatch, prepareValidatedItemSync, builder);\n }\n\n return createEntityAwarePutBuilder(builder, config.name);\n },\n\n upsert: (data: TInput & I) => {\n // Create a minimal builder without validation or key generation\n // We'll defer all processing until execute() or withTransaction() is called\n const builder = table.put<T>({} as T);\n\n // Core function that handles validation, key generation, and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case\n const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;\n\n if (\"issues\" in validatedData && validatedData.issues) {\n throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const primaryKey = config.primaryKey.generateKey(validatedData.value as unknown as TInput & I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validatedData.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validatedData.value,\n [entityTypeAttributeName]: config.name,\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation, key generation, and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen in withTransaction but we need to handle it for type safety\n if (validationResult instanceof Promise) {\n throw new Error(\"Async validation is not supported in withTransaction. Use execute() instead.\");\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const primaryKey = config.primaryKey.generateKey(validationResult.value as unknown as TInput & I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validationResult.value as unknown as T);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to upsert item\");\n }\n return result;\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n builder.withTransaction = wrapMethodWithPreparation(\n originalWithTransaction,\n prepareValidatedItemSync,\n builder,\n );\n }\n\n // Wrap the builder's withBatch method\n const originalWithBatch = builder.withBatch;\n if (originalWithBatch) {\n builder.withBatch = wrapMethodWithPreparation(originalWithBatch, prepareValidatedItemSync, builder);\n }\n\n return createEntityAwarePutBuilder(builder, config.name);\n },\n\n get: <K extends I>(key: K) =>\n createEntityAwareGetBuilder(table.get<T>(config.primaryKey.generateKey(key)), config.name),\n\n update: <K extends I>(key: K, data: Partial<T>) => {\n const primaryKeyObj = config.primaryKey.generateKey(key);\n const builder = table.update<T>(primaryKeyObj);\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Use only updatedAt timestamp for updates\n const timestamps = generateTimestamps([\"updatedAt\"]);\n\n builder.set({ ...data, ...timestamps });\n return builder;\n },\n\n delete: <K extends I>(key: K) => {\n const builder = table.delete(config.primaryKey.generateKey(key));\n builder.condition(eq(entityTypeAttributeName, config.name));\n return createEntityAwareDeleteBuilder(builder, config.name);\n },\n\n query: Object.entries(config.queries || {}).reduce((acc, [key, inputCallback]) => {\n // @ts-expect-error - We need to cast the queryFn to a function that takes an unknown input\n acc[key] = (input: unknown) => {\n // Create a QueryEntity object with only the necessary methods\n const queryEntity: QueryEntity<T> = {\n scan: repository.scan,\n get: (key: PrimaryKeyWithoutExpression) => createEntityAwareGetBuilder(table.get<T>(key), config.name),\n query: (keyCondition: PrimaryKey) => {\n return table.query<T>(keyCondition);\n },\n };\n\n // Execute the query function to get the builder - This type is incorrect and needs to be fixed\n const queryBuilderCallback = inputCallback(input);\n\n // Run the inner handler which allows the user to apply their desired contraints\n // to the query builder of their choice\n // @ts-expect-error - We need to cast the queryBuilderCallback to a function that takes a QueryEntity\n const builder = queryBuilderCallback(queryEntity);\n\n // Add entity type filter if the builder has filter method\n if (builder && typeof builder === \"object\" && \"filter\" in builder && typeof builder.filter === \"function\") {\n builder.filter(eq(entityTypeAttributeName, config.name));\n }\n\n // Wrap the builder's execute method if it exists\n if (builder && typeof builder === \"object\" && \"execute\" in builder) {\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate the input before executing the query\n const queryFn = (\n config.queries as unknown as Record<string, QueryFunctionWithSchema<T, I, typeof builder>>\n )[key];\n\n if (queryFn && typeof queryFn === \"function\") {\n // Get the schema from the query function\n const schema = queryFn.schema;\n if (schema?.[\"~standard\"]?.validate && typeof schema[\"~standard\"].validate === \"function\") {\n const validationResult = schema[\"~standard\"].validate(input);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(\n `Validation failed: ${validationResult.issues.map((issue) => issue.message).join(\", \")}`,\n );\n }\n }\n }\n\n // Execute the original builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to execute query\");\n }\n return result;\n };\n }\n\n return builder;\n };\n return acc;\n }, {} as Q),\n\n scan: () => {\n const builder = table.scan<T>();\n builder.filter(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n };\n\n return repository;\n },\n };\n}\n\nexport function createQueries<T extends DynamoItem>() {\n return {\n input: <I>(schema: StandardSchemaV1<I>) => ({\n query: <\n Q extends QueryRecord<T> = QueryRecord<T>,\n R = ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>,\n >(\n handler: (params: { input: I; entity: QueryEntity<T> }) => R,\n ) => {\n const queryFn = (input: I) => (entity: QueryEntity<T>) => handler({ input, entity });\n queryFn.schema = schema;\n return queryFn as unknown as QueryFunctionWithSchema<T, I, R>;\n },\n }),\n };\n}\n\nexport interface IndexDefinition<T extends DynamoItem> extends Index {\n name: string;\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n generateKey: (item: T) => ({ pk: pkFn(item), sk: skFn(item) }),\n }) as IndexDefinition<T>,\n\n withoutSortKey: () =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n generateKey: (item: T) => ({ pk: pkFn(item) }),\n }) as IndexDefinition<T>,\n }),\n }),\n };\n}\n"]}