dyno-table 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/builders/entity-aware-builders.ts","../src/conditions.ts","../src/entity/ddb-indexing.ts","../src/entity/index-utils.ts","../src/entity/entity.ts"],"names":["buildIndexes","key"],"mappings":";;;AAUA,SAAS,wBAAA,CACP,SACA,UACqC,EAAA;AACrC,EAAO,OAAA,IAAI,MAAM,OAAS,EAAA;AAAA,IACxB,GAAA,CAAI,MAAQ,EAAA,IAAA,EAAM,QAAU,EAAA;AAE1B,MAAA,IAAI,SAAS,YAAc,EAAA;AACzB,QAAO,OAAA,UAAA;AAAA;AAIT,MAAA,IAAI,SAAS,WAAe,IAAA,OAAQ,MAAmC,CAAA,IAAI,MAAM,UAAY,EAAA;AAC3F,QAAO,OAAA,CAIL,OACA,UACG,KAAA;AAEH,UAAA,MAAM,YAAY,UAAe,IAAA,UAAA;AACjC,UAAM,MAAA,EAAA,GAAM,OAAmC,IAAI,CAAA;AAKnD,UAAA,OAAO,EAAG,CAAA,IAAA,CAAK,MAAQ,EAAA,KAAA,EAAO,SAAS,CAAA;AAAA,SACzC;AAAA;AAIF,MAAA,OAAO,OAAQ,CAAA,GAAA,CAAI,MAAQ,EAAA,IAAA,EAAM,QAAQ,CAAA;AAAA;AAC3C,GACD,CAAA;AACH;AAYO,SAAS,2BAAA,CACd,SACA,UAC0B,EAAA;AAC1B,EAAO,OAAA,wBAAA,CAAyB,SAAS,UAAU,CAAA;AACrD;AAYO,SAAS,2BAAA,CACd,SACA,UAC0B,EAAA;AAC1B,EAAO,OAAA,wBAAA,CAAyB,SAAS,UAAU,CAAA;AACrD;AAYO,SAAS,8BAAA,CAA+B,SAAwB,UAA8C,EAAA;AACnH,EAAO,OAAA,wBAAA,CAAyB,SAAS,UAAU,CAAA;AACrD;;;ACIO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,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A,gBACH,UAAY,EAAA;AAAA,eACd;AAAA,aACH,CAAA;AAAA,WACH;AAAA,UAEA,gBAAgB,MAAM;AACpB,YAAA,MAAM,KAAQ,GAAA;AAAA,cACZ,IAAM,EAAA,QAAA;AAAA,cACN,YAAc,EAAA,IAAA;AAAA,cACd,UAAA;AAAA,cACA,WAAA,EAAa,CAAC,IAAY,KAAA;AACxB,gBAAA,MAAM,IAAO,GAAA,MAAA,CAAO,WAAW,CAAA,CAAE,SAAS,IAAI,CAAA;AAC9C,gBAAI,IAAA,QAAA,IAAY,IAAQ,IAAA,IAAA,CAAK,MAAQ,EAAA;AACnC,kBAAA,MAAM,IAAI,KAAA,CAAM,CAA4B,yBAAA,EAAA,IAAA,CAAK,OAAO,GAAI,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,OAAO,CAAA,CAAE,IAAK,CAAA,IAAI,CAAC,CAAE,CAAA,CAAA;AAAA;AAE5F,gBAAA,MAAM,SAAY,GAAA,OAAA,IAAW,IAAO,GAAA,IAAA,CAAK,KAAQ,GAAA,IAAA;AACjD,gBAAA,OAAO,EAAE,EAAA,EAAI,IAAK,CAAA,SAAS,CAAE,EAAA;AAAA;AAC/B,aACF;AAEA,YAAO,OAAA,MAAA,CAAO,OAAO,KAAO,EAAA;AAAA,cAC1B,QAAA,EAAU,CAAC,KAAA,GAAQ,IAChB,MAAA;AAAA,gBACC,GAAG,KAAA;AAAA,gBACH,UAAY,EAAA;AAAA,eACd;AAAA,aACH,CAAA;AAAA;AACH,SACF,CAAA;AAAA,QAEA,QAAU,EAAA,CAAC,KAAQ,GAAA,IAAA,KAAS,mBAAmB,KAAK;AAAA,OACtD,CAAA;AAEA,MAAA,OAAO,mBAAmB,KAAK,CAAA;AAAA;AACjC,GACF;AACF","file":"entity.cjs","sourcesContent":["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 { 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// Helper types that allow string paths and unknown values when strict typing can't be resolved\ntype FlexiblePath<T> = Path<T> extends never ? string : Path<T>;\n// biome-ignore lint: Using any as we don't really know if it's not provided\ntype FlexiblePathType<T, K extends keyof any> = PathType<T, K> extends never ? unknown : PathType<T, K>;\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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(\n attr: K,\n lower: FlexiblePathType<T, K>,\n upper: FlexiblePathType<T, K>,\n ) => 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 FlexiblePath<T>>(attr: K, values: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<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 FlexiblePath<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, Index } from \"../types\";\nimport type { Table } from \"../table\";\nimport type { IndexDefinition } from \"./entity\";\n\n/**\n * Represents a generated key for a DynamoDB index\n */\ninterface IndexKey {\n /** The partition key value */\n pk: string;\n /** The sort key value (optional) */\n sk?: string;\n}\n\n/**\n * Helper class for building indexes for DynamoDB operations\n */\nexport class IndexBuilder<T extends DynamoItem> {\n /**\n * Creates a new IndexBuilder instance\n *\n * @param table - The DynamoDB table instance\n * @param indexes - The index definitions\n */\n constructor(\n private readonly table: Table,\n private readonly indexes: Record<string, IndexDefinition<T>> = {},\n ) {}\n\n /**\n * Build index attributes for item creation\n *\n * @param item - The item to generate indexes for\n * @param options - Options for building indexes\n * @returns Record of GSI attribute names to their values\n */\n buildForCreate(item: T, options: { excludeReadOnly?: boolean } = {}): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n for (const [indexName, indexDef] of Object.entries(this.indexes)) {\n // Skip read-only indexes if requested\n if (options.excludeReadOnly && indexDef.isReadOnly) {\n continue;\n }\n\n const key = indexDef.generateKey(item);\n const gsiConfig = this.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 attributes[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n attributes[gsiConfig.sortKey] = key.sk;\n }\n }\n\n return attributes;\n }\n\n /**\n * Build index attributes for item updates\n *\n * @param currentData - The current data before update\n * @param updates - The update data\n * @param options - Options for building indexes\n * @returns Record of GSI attribute names to their updated values\n */\n buildForUpdate(currentData: T, updates: Partial<T>): Record<string, string> {\n const attributes: Record<string, string> = {};\n const updatedItem = { ...currentData, ...updates } as T;\n\n for (const [indexName, indexDef] of Object.entries(this.indexes)) {\n // Skip read-only indexes - they should never be updated\n if (indexDef.isReadOnly) {\n continue;\n }\n\n // Check if this index uses any fields from the update data\n // We test this by generating keys with and without the update fields\n let shouldUpdateIndex = false;\n\n try {\n // Generate key with current data only\n const currentKey = indexDef.generateKey(currentData);\n\n // Generate key with merged data\n const updatedKey = indexDef.generateKey(updatedItem);\n\n // If the keys are different, this index is affected by the update\n if (currentKey.pk !== updatedKey.pk || currentKey.sk !== updatedKey.sk) {\n shouldUpdateIndex = true;\n }\n } catch {\n // If we can't generate both keys for comparison, assume the index needs updating\n // This happens when we don't have all the required data\n shouldUpdateIndex = true;\n }\n\n if (!shouldUpdateIndex) {\n continue;\n }\n\n // Now generate the full key and validate it\n try {\n const key = indexDef.generateKey(updatedItem);\n\n // Validate the generated keys\n if (this.hasUndefinedValues(key)) {\n throw new Error(\n `Cannot update entity: insufficient data to regenerate index \"${indexName}\". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`,\n );\n }\n\n const gsiConfig = this.table.gsis[indexName];\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n attributes[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n attributes[gsiConfig.sortKey] = key.sk;\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"insufficient data\")) {\n throw error;\n }\n // If we can't generate the key due to missing data, throw a descriptive error\n throw new Error(\n `Cannot update entity: insufficient data to regenerate index \"${indexName}\". All attributes required by the index must be provided in the update operation, or the index must be readOnly.`,\n );\n }\n }\n\n return attributes;\n }\n\n /**\n * Check if a key has undefined values\n *\n * @param key - The index key to check\n * @returns True if the key contains undefined values, false otherwise\n */\n private hasUndefinedValues(key: { pk: string; sk?: string }): boolean {\n return (key.pk?.includes(\"undefined\") ?? false) || (key.sk?.includes(\"undefined\") ?? false);\n }\n}\n","import type { Table } from \"../table\";\nimport type { DynamoItem } from \"../types\";\nimport { IndexBuilder } from \"./ddb-indexing\";\nimport type { IndexDefinition } from \"./entity\";\n\n/**\n * Builds secondary indexes for an item based on the configured indexes\n *\n * @param dataForKeyGeneration - The validated data to generate keys from\n * @param table - The DynamoDB table instance containing GSI configurations\n * @param indexes - The index definitions\n * @param excludeReadOnly - Whether to exclude read-only indexes\n * @returns Record of GSI attribute names to their values\n */\nexport function buildIndexes<T extends DynamoItem>(\n dataForKeyGeneration: T,\n table: Table,\n indexes: Record<string, IndexDefinition<T>> | undefined,\n excludeReadOnly = false,\n): Record<string, string> {\n if (!indexes) {\n return {};\n }\n\n const indexBuilder = new IndexBuilder(table, indexes);\n return indexBuilder.buildForCreate(dataForKeyGeneration, { excludeReadOnly });\n}\n\n/**\n * Builds index updates for an item based on the configured indexes\n *\n * @param currentData - The current data before update\n * @param updates - The update data\n * @param table - The DynamoDB table instance containing GSI configurations\n * @param indexes - The index definitions\n * @returns Record of GSI attribute names to their updated values\n */\nexport function buildIndexUpdates<T extends DynamoItem>(\n currentData: T,\n updates: Partial<T>,\n table: Table,\n indexes: Record<string, IndexDefinition<T>> | undefined,\n): Record<string, string> {\n if (!indexes) {\n return {};\n }\n\n const indexBuilder = new IndexBuilder(table, indexes);\n return indexBuilder.buildForUpdate(currentData, updates);\n}\n","import type { GetBuilder } from \"../builders/get-builder\";\nimport type { ScanBuilder } from \"../builders/scan-builder\";\nimport type { UpdateBuilder } from \"../builders/update-builder\";\nimport type { StandardSchemaV1 } from \"../standard-schema\";\nimport type { StandardSchemaV1 as StandardSchemaV1Namespace } from \"../standard-schema\";\nimport {\n createEntityAwareDeleteBuilder,\n createEntityAwareGetBuilder,\n createEntityAwarePutBuilder,\n} from \"../builders/entity-aware-builders\";\nimport type {\n EntityAwareDeleteBuilder,\n EntityAwareGetBuilder,\n EntityAwarePutBuilder,\n} from \"../builders/entity-aware-builders\";\nimport type { QueryBuilder } from \"../builders/query-builder\";\nimport { type PrimaryKey, type PrimaryKeyWithoutExpression, eq } from \"../conditions\";\nimport type { Table } from \"../table\";\nimport type { DynamoItem, Index, TableConfig } from \"../types\";\nimport { IndexBuilder } from \"./ddb-indexing\";\nimport { buildIndexes as buildEntityIndexes, buildIndexUpdates } from \"./index-utils\";\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, IndexDefinition<T>>;\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 * Builds secondary indexes for an item based on the configured indexes\n *\n * @param dataForKeyGeneration The validated data to generate keys from\n * @param table The DynamoDB table instance containing GSI configurations\n * @returns Record of GSI attribute names to their values\n */\n const buildIndexes = <TData extends T>(\n dataForKeyGeneration: TData,\n table: Table,\n excludeReadOnly = false,\n ): Record<string, string> => {\n return buildEntityIndexes(dataForKeyGeneration, table, config.indexes, excludeReadOnly);\n };\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\">} timestampsToGenerate - Array of timestamp types to generate.\n * @param {Partial<T>} data - Data object to check for existing timestamps.\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 const generateTimestamps = (\n timestampsToGenerate: Array<\"createdAt\" | \"updatedAt\">,\n data: Partial<T>,\n ): 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 /**\n * If the data object already has a createdAt value, skip generating it.\n */\n if (createdAt && timestampsToGenerate.includes(\"createdAt\") && !data.createdAt) {\n const name = createdAt.attributeName ?? \"createdAt\";\n timestamps[name] = createdAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n /**\n * If the data object already has an updatedAt value, skip generating it.\n */\n if (updatedAt && timestampsToGenerate.includes(\"updatedAt\") && !data.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 validatedData = await config.schema[\"~standard\"].validate(data);\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 dataForKeyGeneration = {\n ...validatedData.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validatedData.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n ...(dataForKeyGeneration as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\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 withBatch or withTransaction. The schema must support synchronous validation for 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 const dataForKeyGeneration = {\n ...validationResult.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validationResult.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n ...(dataForKeyGeneration as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\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 validatedData = await config.schema[\"~standard\"].validate(data);\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 dataForKeyGeneration = {\n ...validatedData.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validatedData.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as TInput & I);\n\n const indexes = buildIndexes(dataForKeyGeneration, table, false);\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...dataForKeyGeneration,\n [entityTypeAttributeName]: config.name,\n ...indexes,\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(\n \"Async validation is not supported in withTransaction or withBatch. Use execute() instead.\",\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 const dataForKeyGeneration = {\n ...validationResult.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validationResult.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as TInput & I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...dataForKeyGeneration,\n [entityTypeAttributeName]: config.name,\n ...indexes,\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 return createEntityAwareGetBuilder(table.get<T>(config.primaryKey.generateKey(key)), config.name);\n },\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\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Use only updatedAt timestamp for updates\n const timestamps = generateTimestamps([\"updatedAt\"], data);\n\n // Use the index builder for updates\n const indexUpdates = buildIndexUpdates(\n { ...key } as unknown as T,\n { ...data, ...timestamps },\n table,\n config.indexes,\n );\n\n builder.set({ ...data, ...timestamps, ...indexUpdates });\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/**\n * Defines a DynamoDB index configuration\n */\nexport interface IndexDefinition<T extends DynamoItem> extends Index<T> {\n /** The name of the index */\n name: string;\n /** Whether the index is read-only */\n isReadOnly: boolean;\n /** Function to generate the index key from an item */\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\ntype Result<T> = StandardSchemaV1Namespace.Result<T>;\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => {\n const createIndexBuilder = (isReadOnly = false) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) => {\n const index = {\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n isReadOnly: isReadOnly,\n generateKey: (item: T) => {\n const data = schema[\"~standard\"].validate(item) as Result<T>;\n if (\"issues\" in data && data.issues) {\n throw new Error(`Index validation failed: ${data.issues.map((i) => i.message).join(\", \")}`);\n }\n const validData = \"value\" in data ? data.value : item;\n return { pk: pkFn(validData), sk: skFn(validData) };\n },\n } as IndexDefinition<T>;\n\n return Object.assign(index, {\n readOnly: (value = false) =>\n ({\n ...index,\n isReadOnly: value,\n }) as IndexDefinition<T>,\n });\n },\n\n withoutSortKey: () => {\n const index = {\n name: \"custom\",\n partitionKey: \"pk\",\n isReadOnly: isReadOnly,\n generateKey: (item: T) => {\n const data = schema[\"~standard\"].validate(item) as Result<T>;\n if (\"issues\" in data && data.issues) {\n throw new Error(`Index validation failed: ${data.issues.map((i) => i.message).join(\", \")}`);\n }\n const validData = \"value\" in data ? data.value : item;\n return { pk: pkFn(validData) };\n },\n } as IndexDefinition<T>;\n\n return Object.assign(index, {\n readOnly: (value = true) =>\n ({\n ...index,\n isReadOnly: value,\n }) as IndexDefinition<T>,\n });\n },\n }),\n\n readOnly: (value = true) => createIndexBuilder(value),\n });\n\n return createIndexBuilder(false);\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/builders/entity-aware-builders.ts","../src/conditions.ts","../src/entity/ddb-indexing.ts","../src/entity/index-utils.ts","../src/entity/entity.ts"],"names":["buildIndexes","key"],"mappings":";;;AAUA,SAAS,wBAAA,CACP,SACA,UACqC,EAAA;AACrC,EAA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QAAA,IAAY,IAAQ,IAAA,IAAA,CAAK,MAAQ,EAAA;AACnC,kBAAA,MAAM,IAAI,KAAA,CAAM,CAA4B,yBAAA,EAAA,IAAA,CAAK,OAAO,GAAI,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,OAAO,CAAA,CAAE,IAAK,CAAA,IAAI,CAAC,CAAE,CAAA,CAAA;AAAA;AAE5F,gBAAA,MAAM,SAAY,GAAA,OAAA,IAAW,IAAO,GAAA,IAAA,CAAK,KAAQ,GAAA,IAAA;AACjD,gBAAA,OAAO,EAAE,EAAA,EAAI,IAAK,CAAA,SAAS,CAAE,EAAA;AAAA;AAC/B,aACF;AAEA,YAAO,OAAA,MAAA,CAAO,OAAO,KAAO,EAAA;AAAA,cAC1B,QAAA,EAAU,CAAC,KAAA,GAAQ,IAChB,MAAA;AAAA,gBACC,GAAG,KAAA;AAAA,gBACH,UAAY,EAAA;AAAA,eACd;AAAA,aACH,CAAA;AAAA;AACH,SACF,CAAA;AAAA,QAEA,QAAU,EAAA,CAAC,KAAQ,GAAA,IAAA,KAAS,mBAAmB,KAAK;AAAA,OACtD,CAAA;AAEA,MAAA,OAAO,mBAAmB,KAAK,CAAA;AAAA;AACjC,GACF;AACF","file":"entity.cjs","sourcesContent":["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 { 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// Helper types that allow string paths and unknown values when strict typing can't be resolved\ntype FlexiblePath<T> = Path<T> extends never ? string : Path<T>;\n// biome-ignore lint: Using any as we don't really know if it's not provided\ntype FlexiblePathType<T, K extends keyof any> = PathType<T, K> extends never ? unknown : PathType<T, K>;\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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(\n attr: K,\n lower: FlexiblePathType<T, K>,\n upper: FlexiblePathType<T, K>,\n ) => 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 FlexiblePath<T>>(attr: K, values: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<T>>(attr: K, value: FlexiblePathType<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 FlexiblePath<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 FlexiblePath<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, Index } from \"../types\";\nimport type { Table } from \"../table\";\nimport type { IndexDefinition } from \"./entity\";\n\n/**\n * Represents a generated key for a DynamoDB index\n */\ninterface IndexKey {\n /** The partition key value */\n pk: string;\n /** The sort key value (optional) */\n sk?: string;\n}\n\n/**\n * Helper class for building indexes for DynamoDB operations\n */\nexport class IndexBuilder<T extends DynamoItem> {\n /**\n * Creates a new IndexBuilder instance\n *\n * @param table - The DynamoDB table instance\n * @param indexes - The index definitions\n */\n constructor(\n private readonly table: Table,\n private readonly indexes: Record<string, IndexDefinition<T>> = {},\n ) {}\n\n /**\n * Build index attributes for item creation\n *\n * @param item - The item to generate indexes for\n * @param options - Options for building indexes\n * @returns Record of GSI attribute names to their values\n */\n buildForCreate(item: T, options: { excludeReadOnly?: boolean } = {}): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n for (const [indexName, indexDef] of Object.entries(this.indexes)) {\n // Skip read-only indexes if requested\n if (options.excludeReadOnly && indexDef.isReadOnly) {\n continue;\n }\n\n const key = indexDef.generateKey(item);\n const gsiConfig = this.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 attributes[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n attributes[gsiConfig.sortKey] = key.sk;\n }\n }\n\n return attributes;\n }\n\n /**\n * Build index attributes for item updates\n *\n * @param currentData - The current data before update\n * @param updates - The update data\n * @param options - Options for building indexes\n * @returns Record of GSI attribute names to their updated values\n */\n buildForUpdate(currentData: T, updates: Partial<T>): Record<string, string> {\n const attributes: Record<string, string> = {};\n const updatedItem = { ...currentData, ...updates } as T;\n\n for (const [indexName, indexDef] of Object.entries(this.indexes)) {\n // Skip read-only indexes - they should never be updated\n if (indexDef.isReadOnly) {\n continue;\n }\n\n // Check if this index uses any fields from the update data\n // We test this by generating keys with and without the update fields\n let shouldUpdateIndex = false;\n\n try {\n // Generate key with current data only\n const currentKey = indexDef.generateKey(currentData);\n\n // Generate key with merged data\n const updatedKey = indexDef.generateKey(updatedItem);\n\n // If the keys are different, this index is affected by the update\n if (currentKey.pk !== updatedKey.pk || currentKey.sk !== updatedKey.sk) {\n shouldUpdateIndex = true;\n }\n } catch {\n // If we can't generate both keys for comparison, assume the index needs updating\n // This happens when we don't have all the required data\n shouldUpdateIndex = true;\n }\n\n if (!shouldUpdateIndex) {\n continue;\n }\n\n // Now generate the full key and validate it\n let key: IndexKey;\n try {\n key = indexDef.generateKey(updatedItem);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Missing attributes: ${error.message}`);\n }\n throw error;\n }\n\n // Validate the generated keys\n if (this.hasUndefinedValues(key)) {\n throw new Error(\n `Missing attributes: Cannot update entity: insufficient data to regenerate index \"${indexName}\". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`,\n );\n }\n\n const gsiConfig = this.table.gsis[indexName];\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n attributes[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n attributes[gsiConfig.sortKey] = key.sk;\n }\n }\n\n return attributes;\n }\n\n /**\n * Check if a key has undefined values\n *\n * @param key - The index key to check\n * @returns True if the key contains undefined values, false otherwise\n */\n private hasUndefinedValues(key: { pk: string; sk?: string }): boolean {\n return (key.pk?.includes(\"undefined\") ?? false) || (key.sk?.includes(\"undefined\") ?? false);\n }\n}\n","import type { Table } from \"../table\";\nimport type { DynamoItem } from \"../types\";\nimport { IndexBuilder } from \"./ddb-indexing\";\nimport type { IndexDefinition } from \"./entity\";\n\n/**\n * Builds secondary indexes for an item based on the configured indexes\n *\n * @param dataForKeyGeneration - The validated data to generate keys from\n * @param table - The DynamoDB table instance containing GSI configurations\n * @param indexes - The index definitions\n * @param excludeReadOnly - Whether to exclude read-only indexes\n * @returns Record of GSI attribute names to their values\n */\nexport function buildIndexes<T extends DynamoItem>(\n dataForKeyGeneration: T,\n table: Table,\n indexes: Record<string, IndexDefinition<T>> | undefined,\n excludeReadOnly = false,\n): Record<string, string> {\n if (!indexes) {\n return {};\n }\n\n const indexBuilder = new IndexBuilder(table, indexes);\n return indexBuilder.buildForCreate(dataForKeyGeneration, { excludeReadOnly });\n}\n\n/**\n * Builds index updates for an item based on the configured indexes\n *\n * @param currentData - The current data before update\n * @param updates - The update data\n * @param table - The DynamoDB table instance containing GSI configurations\n * @param indexes - The index definitions\n * @returns Record of GSI attribute names to their updated values\n */\nexport function buildIndexUpdates<T extends DynamoItem>(\n currentData: T,\n updates: Partial<T>,\n table: Table,\n indexes: Record<string, IndexDefinition<T>> | undefined,\n): Record<string, string> {\n if (!indexes) {\n return {};\n }\n\n const indexBuilder = new IndexBuilder(table, indexes);\n return indexBuilder.buildForUpdate(currentData, updates);\n}\n","import type { GetBuilder } from \"../builders/get-builder\";\nimport type { ScanBuilder } from \"../builders/scan-builder\";\nimport type { UpdateBuilder } from \"../builders/update-builder\";\nimport type { StandardSchemaV1 } from \"../standard-schema\";\nimport type { StandardSchemaV1 as StandardSchemaV1Namespace } from \"../standard-schema\";\nimport {\n createEntityAwareDeleteBuilder,\n createEntityAwareGetBuilder,\n createEntityAwarePutBuilder,\n} from \"../builders/entity-aware-builders\";\nimport type {\n EntityAwareDeleteBuilder,\n EntityAwareGetBuilder,\n EntityAwarePutBuilder,\n} from \"../builders/entity-aware-builders\";\nimport type { QueryBuilder } from \"../builders/query-builder\";\nimport { type PrimaryKey, type PrimaryKeyWithoutExpression, eq } from \"../conditions\";\nimport type { Table } from \"../table\";\nimport type { DynamoItem, Index, TableConfig } from \"../types\";\nimport { IndexBuilder } from \"./ddb-indexing\";\nimport { buildIndexes as buildEntityIndexes, buildIndexUpdates } from \"./index-utils\";\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, IndexDefinition<T>>;\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 * Builds secondary indexes for an item based on the configured indexes\n *\n * @param dataForKeyGeneration The validated data to generate keys from\n * @param table The DynamoDB table instance containing GSI configurations\n * @returns Record of GSI attribute names to their values\n */\n const buildIndexes = <TData extends T>(\n dataForKeyGeneration: TData,\n table: Table,\n excludeReadOnly = false,\n ): Record<string, string> => {\n return buildEntityIndexes(dataForKeyGeneration, table, config.indexes, excludeReadOnly);\n };\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\">} timestampsToGenerate - Array of timestamp types to generate.\n * @param {Partial<T>} data - Data object to check for existing timestamps.\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 const generateTimestamps = (\n timestampsToGenerate: Array<\"createdAt\" | \"updatedAt\">,\n data: Partial<T>,\n ): 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 /**\n * If the data object already has a createdAt value, skip generating it.\n */\n if (createdAt && timestampsToGenerate.includes(\"createdAt\") && !data.createdAt) {\n const name = createdAt.attributeName ?? \"createdAt\";\n timestamps[name] = createdAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n /**\n * If the data object already has an updatedAt value, skip generating it.\n */\n if (updatedAt && timestampsToGenerate.includes(\"updatedAt\") && !data.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 validatedData = await config.schema[\"~standard\"].validate(data);\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 dataForKeyGeneration = {\n ...validatedData.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validatedData.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n ...(dataForKeyGeneration as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\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 withBatch or withTransaction. The schema must support synchronous validation for 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 const dataForKeyGeneration = {\n ...validationResult.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validationResult.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n ...(dataForKeyGeneration as unknown as T),\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\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 validatedData = await config.schema[\"~standard\"].validate(data);\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 dataForKeyGeneration = {\n ...validatedData.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validatedData.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as TInput & I);\n\n const indexes = buildIndexes(dataForKeyGeneration, table, false);\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...dataForKeyGeneration,\n [entityTypeAttributeName]: config.name,\n ...indexes,\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(\n \"Async validation is not supported in withTransaction or withBatch. Use execute() instead.\",\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 const dataForKeyGeneration = {\n ...validationResult.value,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"], validationResult.value),\n };\n\n // Generate the primary key using validated data (with defaults applied)\n const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration as unknown as TInput & I);\n\n const indexes = buildEntityIndexes(dataForKeyGeneration, table, config.indexes, false);\n\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...dataForKeyGeneration,\n [entityTypeAttributeName]: config.name,\n ...indexes,\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 return createEntityAwareGetBuilder(table.get<T>(config.primaryKey.generateKey(key)), config.name);\n },\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\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Use only updatedAt timestamp for updates\n const timestamps = generateTimestamps([\"updatedAt\"], data);\n\n // Use the index builder for updates\n const indexUpdates = buildIndexUpdates(\n { ...key } as unknown as T,\n { ...data, ...timestamps },\n table,\n config.indexes,\n );\n\n builder.set({ ...data, ...timestamps, ...indexUpdates });\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/**\n * Defines a DynamoDB index configuration\n */\nexport interface IndexDefinition<T extends DynamoItem> extends Index<T> {\n /** The name of the index */\n name: string;\n /** Whether the index is read-only */\n isReadOnly: boolean;\n /** Function to generate the index key from an item */\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\ntype Result<T> = StandardSchemaV1Namespace.Result<T>;\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => {\n const createIndexBuilder = (isReadOnly = false) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) => {\n const index = {\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n isReadOnly: isReadOnly,\n generateKey: (item: T) => {\n const data = schema[\"~standard\"].validate(item) as Result<T>;\n if (\"issues\" in data && data.issues) {\n throw new Error(`Index validation failed: ${data.issues.map((i) => i.message).join(\", \")}`);\n }\n const validData = \"value\" in data ? data.value : item;\n return { pk: pkFn(validData), sk: skFn(validData) };\n },\n } as IndexDefinition<T>;\n\n return Object.assign(index, {\n readOnly: (value = false) =>\n ({\n ...index,\n isReadOnly: value,\n }) as IndexDefinition<T>,\n });\n },\n\n withoutSortKey: () => {\n const index = {\n name: \"custom\",\n partitionKey: \"pk\",\n isReadOnly: isReadOnly,\n generateKey: (item: T) => {\n const data = schema[\"~standard\"].validate(item) as Result<T>;\n if (\"issues\" in data && data.issues) {\n throw new Error(`Index validation failed: ${data.issues.map((i) => i.message).join(\", \")}`);\n }\n const validData = \"value\" in data ? data.value : item;\n return { pk: pkFn(validData) };\n },\n } as IndexDefinition<T>;\n\n return Object.assign(index, {\n readOnly: (value = true) =>\n ({\n ...index,\n isReadOnly: value,\n }) as IndexDefinition<T>,\n });\n },\n }),\n\n readOnly: (value = true) => createIndexBuilder(value),\n });\n\n return createIndexBuilder(false);\n },\n };\n}\n"]}
package/dist/entity.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { G as GetBuilder } from './batch-builder-CcxFDKhe.cjs';
2
- import { S as ScanBuilder, T as Table } from './table-BpNOboD9.cjs';
2
+ import { S as ScanBuilder, T as Table } from './table-D-xNCVFa.cjs';
3
3
  import { UpdateBuilder } from './builders/update-builder.cjs';
4
4
  import { StandardSchemaV1 } from './standard-schema.cjs';
5
5
  import { DynamoItem, TableConfig, Index } from './types.cjs';
6
6
  import { PutBuilder } from './builders/put-builder.cjs';
7
7
  import { DeleteBuilder } from './builders/delete-builder.cjs';
8
- import { Q as QueryBuilder } from './query-builder-DZ9JKgBN.cjs';
8
+ import { Q as QueryBuilder } from './query-builder-DoZzZz_c.cjs';
9
9
  import { r as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-CC3NDfUU.cjs';
10
10
  import './builder-types-BTVhQSHI.cjs';
11
11
  import './builders/transaction-builder.cjs';
package/dist/entity.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { G as GetBuilder } from './batch-builder-BytHNL_u.js';
2
- import { S as ScanBuilder, T as Table } from './table-BhEeYauU.js';
2
+ import { S as ScanBuilder, T as Table } from './table-4UxlW_wD.js';
3
3
  import { UpdateBuilder } from './builders/update-builder.js';
4
4
  import { StandardSchemaV1 } from './standard-schema.js';
5
5
  import { DynamoItem, TableConfig, Index } from './types.js';
6
6
  import { PutBuilder } from './builders/put-builder.js';
7
7
  import { DeleteBuilder } from './builders/delete-builder.js';
8
- import { Q as QueryBuilder } from './query-builder-BNWRCrJW.js';
8
+ import { Q as QueryBuilder } from './query-builder-CUWdavZw.js';
9
9
  import { r as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-DD0bvyHm.js';
10
10
  import './builder-types-CzuLR4Th.js';
11
11
  import './builders/transaction-builder.js';
package/dist/entity.js CHANGED
@@ -101,31 +101,30 @@ var IndexBuilder = class {
101
101
  if (!shouldUpdateIndex) {
102
102
  continue;
103
103
  }
104
+ let key;
104
105
  try {
105
- const key = indexDef.generateKey(updatedItem);
106
- if (this.hasUndefinedValues(key)) {
107
- throw new Error(
108
- `Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`
109
- );
110
- }
111
- const gsiConfig = this.table.gsis[indexName];
112
- if (!gsiConfig) {
113
- throw new Error(`GSI configuration not found for index: ${indexName}`);
114
- }
115
- if (key.pk) {
116
- attributes[gsiConfig.partitionKey] = key.pk;
117
- }
118
- if (key.sk && gsiConfig.sortKey) {
119
- attributes[gsiConfig.sortKey] = key.sk;
120
- }
106
+ key = indexDef.generateKey(updatedItem);
121
107
  } catch (error) {
122
- if (error instanceof Error && error.message.includes("insufficient data")) {
123
- throw error;
108
+ if (error instanceof Error) {
109
+ throw new Error(`Missing attributes: ${error.message}`);
124
110
  }
111
+ throw error;
112
+ }
113
+ if (this.hasUndefinedValues(key)) {
125
114
  throw new Error(
126
- `Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be readOnly.`
115
+ `Missing attributes: Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`
127
116
  );
128
117
  }
118
+ const gsiConfig = this.table.gsis[indexName];
119
+ if (!gsiConfig) {
120
+ throw new Error(`GSI configuration not found for index: ${indexName}`);
121
+ }
122
+ if (key.pk) {
123
+ attributes[gsiConfig.partitionKey] = key.pk;
124
+ }
125
+ if (key.sk && gsiConfig.sortKey) {
126
+ attributes[gsiConfig.sortKey] = key.sk;
127
+ }
129
128
  }
130
129
  return attributes;
131
130
  }