dyno-table 0.1.8 → 1.0.0-alpha.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.
- package/README.md +35 -7
- package/package.json +13 -3
- package/dist/builders/condition-check-builder.cjs +0 -394
- package/dist/builders/condition-check-builder.cjs.map +0 -1
- package/dist/builders/condition-check-builder.js +0 -392
- package/dist/builders/condition-check-builder.js.map +0 -1
- package/dist/builders/delete-builder.cjs +0 -422
- package/dist/builders/delete-builder.cjs.map +0 -1
- package/dist/builders/delete-builder.js +0 -420
- package/dist/builders/delete-builder.js.map +0 -1
- package/dist/builders/paginator.cjs +0 -199
- package/dist/builders/paginator.cjs.map +0 -1
- package/dist/builders/paginator.js +0 -197
- package/dist/builders/paginator.js.map +0 -1
- package/dist/builders/put-builder.cjs +0 -468
- package/dist/builders/put-builder.cjs.map +0 -1
- package/dist/builders/put-builder.js +0 -466
- package/dist/builders/put-builder.js.map +0 -1
- package/dist/builders/query-builder.cjs +0 -674
- package/dist/builders/query-builder.cjs.map +0 -1
- package/dist/builders/query-builder.js +0 -672
- package/dist/builders/query-builder.js.map +0 -1
- package/dist/builders/transaction-builder.cjs +0 -876
- package/dist/builders/transaction-builder.cjs.map +0 -1
- package/dist/builders/transaction-builder.js +0 -874
- package/dist/builders/transaction-builder.js.map +0 -1
- package/dist/builders/update-builder.cjs +0 -662
- package/dist/builders/update-builder.cjs.map +0 -1
- package/dist/builders/update-builder.js +0 -660
- package/dist/builders/update-builder.js.map +0 -1
- package/dist/conditions.cjs +0 -59
- package/dist/conditions.cjs.map +0 -1
- package/dist/conditions.js +0 -43
- package/dist/conditions.js.map +0 -1
- package/dist/entity.cjs +0 -169
- package/dist/entity.cjs.map +0 -1
- package/dist/entity.js +0 -165
- package/dist/entity.js.map +0 -1
- package/dist/standard-schema.cjs +0 -4
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.js +0 -3
- package/dist/standard-schema.js.map +0 -1
- package/dist/table.cjs +0 -3265
- package/dist/table.cjs.map +0 -1
- package/dist/table.js +0 -3263
- package/dist/table.js.map +0 -1
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/key-template.cjs +0 -19
- package/dist/utils/key-template.cjs.map +0 -1
- package/dist/utils/key-template.js +0 -17
- package/dist/utils/key-template.js.map +0 -1
- package/dist/utils/sort-key-template.cjs +0 -19
- package/dist/utils/sort-key-template.cjs.map +0 -1
- package/dist/utils/sort-key-template.js +0 -17
- package/dist/utils/sort-key-template.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/conditions.ts","../../src/expression.ts","../../src/utils/debug-expression.ts","../../src/builders/update-builder.ts"],"names":["value"],"mappings":";AA8FO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,CAAC,MAAc,KAA+B,MAAA;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,CAAA;AAQK,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,GAAA,GAAM,0BAA0B,KAAK,CAAA;AAQ3C,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,GAAA,GAAM,0BAA0B,KAAK,CAAA;AAQ3C,IAAM,OAAU,GAAA,CAAC,IAAc,EAAA,KAAA,EAAgB,KAA+B,MAAA;AAAA,EACnF,IAAM,EAAA,SAAA;AAAA,EACN,IAAA;AAAA,EACA,KAAA,EAAO,CAAC,KAAA,EAAO,KAAK;AACtB,CAAA,CAAA;AAQO,IAAM,UAAA,GAAa,0BAA0B,YAAY,CAAA;AAQzD,IAAM,QAAA,GAAW,0BAA0B,UAAU,CAAA;AAQrD,IAAM,eAAA,GAAkB,CAAC,IAA6B,MAAA;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AA;AAAA,EA8CA,MAAM,OAAiC,GAAA;AACrC,IAAM,MAAA,MAAA,GAAS,KAAK,eAAgB,EAAA;AACpC,IAAO,OAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA;AAE/B","file":"update-builder.js","sourcesContent":["import type { Path, PathType } from \"./builders/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 * - 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 | \"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: Record<string, unknown>;\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 a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends Record<string, unknown>> = {\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n and: (...conditions: Condition[]) => Condition;\n or: (...conditions: Condition[]) => Condition;\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 { ComparisonOperator, Condition, ExpressionParams, LogicalOperator } from \"./conditions\";\n\nexport const generateAttributeName = (params: ExpressionParams, attr: string): string => {\n // Check if the attribute already exists in the expressionAttributeNames\n for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {\n if (existingAttr === attr) {\n return existingName;\n }\n }\n\n // If not found, create a new attribute name\n const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;\n params.expressionAttributeNames[attrName] = attr;\n return attrName;\n};\n\nexport const generateValueName = (params: ExpressionParams, value: unknown): string => {\n const valueName = `:${params.valueCounter.count++}`;\n params.expressionAttributeValues[valueName] = value;\n return valueName;\n};\n\nconst validateCondition = (condition: Condition, requiresAttr = true, requiresValue = true): void => {\n if (requiresAttr && !condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (requiresValue && condition.value === undefined) {\n throw new Error(`Value is required for ${condition.type} condition`);\n }\n};\n\nconst buildComparisonExpression = (condition: Condition, operator: string, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${attrName} ${operator} ${valueName}`;\n};\n\nconst buildBetweenExpression = (condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (!Array.isArray(condition.value) || condition.value.length !== 2) {\n throw new Error(\"Between condition requires an array of two values\");\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const lowerName = generateValueName(params, condition.value[0]);\n const upperName = generateValueName(params, condition.value[1]);\n\n return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;\n};\n\nconst buildFunctionExpression = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${functionName}(${attrName}, ${valueName})`;\n};\n\nconst buildAttributeFunction = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition, true, false);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n return `${functionName}(${attrName})`;\n};\n\nconst buildLogicalExpression = (operator: string, conditions: Condition[], params: ExpressionParams): string => {\n if (!conditions || conditions.length === 0) {\n throw new Error(`At least one condition is required for ${operator} expression`);\n }\n\n const expressions = conditions.map((c) => buildExpression(c, params));\n return `(${expressions.join(` ${operator} `)})`;\n};\n\nexport const buildExpression = (condition: Condition, params: ExpressionParams): string => {\n if (!condition) return \"\";\n\n try {\n // Map of condition types to their expression builders\n const expressionBuilders: Record<ComparisonOperator | LogicalOperator, () => string> = {\n eq: () => buildComparisonExpression(condition, \"=\", params),\n ne: () => buildComparisonExpression(condition, \"<>\", params),\n lt: () => buildComparisonExpression(condition, \"<\", params),\n lte: () => buildComparisonExpression(condition, \"<=\", params),\n gt: () => buildComparisonExpression(condition, \">\", params),\n gte: () => buildComparisonExpression(condition, \">=\", params),\n between: () => buildBetweenExpression(condition, params),\n beginsWith: () => buildFunctionExpression(\"begins_with\", condition, params),\n contains: () => buildFunctionExpression(\"contains\", condition, params),\n attributeExists: () => buildAttributeFunction(\"attribute_exists\", condition, params),\n attributeNotExists: () => buildAttributeFunction(\"attribute_not_exists\", condition, params),\n and: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for AND operator\");\n }\n return buildLogicalExpression(\"AND\", condition.conditions, params);\n },\n or: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for OR operator\");\n }\n return buildLogicalExpression(\"OR\", condition.conditions, params);\n },\n not: () => {\n if (!condition.condition) {\n throw new Error(\"Condition is required for NOT operator\");\n }\n return `NOT (${buildExpression(condition.condition, params)})`;\n },\n };\n\n const builder = expressionBuilders[condition.type];\n if (!builder) {\n throw new Error(`Unknown condition type: ${condition.type}`);\n }\n\n return builder();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`Error building expression for condition type ${condition.type}:`, error.message);\n } else {\n console.error(`Error building expression for condition type ${condition.type}:`, error);\n }\n throw error;\n }\n};\n\nexport const prepareExpressionParams = (\n condition?: Condition,\n): {\n expression?: string;\n names?: Record<string, string>;\n values?: Record<string, unknown>;\n} => {\n if (!condition) return {};\n\n const params: ExpressionParams = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n const expression = buildExpression(condition, params);\n\n return {\n expression,\n names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : undefined,\n values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : undefined,\n };\n};\n","/**\n * Interface for DynamoDB command objects that can contain expressions\n */\nexport interface DynamoCommandWithExpressions {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n expressionAttributeNames?: Record<string, string>;\n expressionAttributeValues?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype ReadableDynamoCommand = {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n};\n\n/**\n * Utility function to debug a DynamoDB command by replacing all placeholders\n * in expressions with their actual values.\n *\n * @param command Any DynamoDB command with expressions and attribute maps\n * @returns An object with the same structure but with readable expressions\n */\nexport function debugCommand<T extends DynamoCommandWithExpressions>(\n command: T,\n): {\n raw: T;\n readable: ReadableDynamoCommand;\n} {\n // Create a copy of the command\n const result: ReadableDynamoCommand = {};\n\n function replaceAliases(expressionString: string) {\n if (!expressionString) {\n return expressionString;\n }\n\n let replacedString = expressionString;\n for (const alias in command.expressionAttributeNames) {\n const attributeName = command.expressionAttributeNames[alias];\n const regex = new RegExp(alias, \"g\");\n\n replacedString = replacedString.replace(regex, attributeName as string);\n }\n\n for (const alias in command.expressionAttributeValues) {\n let attributeValue = command.expressionAttributeValues[alias];\n\n // Handle Set objects for better readability\n if (attributeValue instanceof Set) {\n const array = Array.from(attributeValue);\n attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(\", \")}}`;\n } else {\n // Stringify other values for display\n attributeValue = JSON.stringify(attributeValue);\n }\n\n const regex = new RegExp(alias, \"g\");\n replacedString = replacedString.replace(regex, attributeValue as string);\n }\n\n return replacedString;\n }\n\n if (command.updateExpression) {\n result.updateExpression = replaceAliases(command.updateExpression);\n }\n if (command.conditionExpression) {\n result.conditionExpression = replaceAliases(command.conditionExpression);\n }\n if (command.filterExpression) {\n result.filterExpression = replaceAliases(command.filterExpression);\n }\n if (command.keyConditionExpression) {\n result.keyConditionExpression = replaceAliases(command.keyConditionExpression);\n }\n if (command.projectionExpression) {\n result.projectionExpression = replaceAliases(command.projectionExpression);\n }\n\n return {\n raw: command,\n readable: result,\n };\n}\n","import type { Condition, ConditionOperator, PrimaryKeyWithoutExpression } from \"../conditions\";\nimport {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n} from \"../conditions\";\nimport type { Path, PathType } from \"./types\";\nimport type { TransactionBuilder } from \"./transaction-builder\";\nimport { buildExpression, generateAttributeName, generateValueName } from \"../expression\";\nimport { debugCommand, type DynamoCommandWithExpressions } from \"../utils/debug-expression\";\nimport type { UpdateCommandParams } from \"./builder-types\";\n\n/**\n * Configuration options for DynamoDB update operations.\n */\nexport interface UpdateOptions {\n /** Optional condition that must be satisfied for the update to succeed */\n condition?: Condition;\n /** Determines which item attributes to include in the response */\n returnValues?: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\";\n}\n\n/**\n * Function type for executing DynamoDB update operations.\n * @typeParam T - The type of the item being updated\n */\ntype UpdateExecutor<T extends Record<string, unknown>> = (params: UpdateCommandParams) => Promise<{ item?: T }>;\n\n/**\n * Represents a single update action within an update operation.\n * Each action modifies the item in a specific way:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n */\nexport type UpdateAction = {\n /** The type of update action */\n type: \"SET\" | \"REMOVE\" | \"ADD\" | \"DELETE\";\n /** The attribute path to update */\n path: string;\n /** The value to use in the update (not used for REMOVE actions) */\n value?: unknown;\n};\n\n/**\n * Type utility to get the element type of a set.\n * Extracts the element type from either a Set or Array type.\n * @typeParam T - The set or array type\n */\ntype SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;\n\n/**\n * Type utility to get the element type from a path that points to a set.\n * Combines PathType and SetElementType to get the element type at a specific path.\n * @typeParam T - The type of the item\n * @typeParam K - The path within the item\n */\ntype PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;\n\n/**\n * Builder for creating DynamoDB update operations.\n * Use this builder when you need to:\n * - Modify existing items in DynamoDB\n * - Update multiple attributes atomically\n * - Perform conditional updates\n * - Work with nested attributes\n * - Update sets and lists\n *\n * The builder supports all DynamoDB update operations:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n *\n * @example\n * ```typescript\n * // Simple update\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('status', 'HUNTING')\n * .set('lastFed', new Date().toISOString())\n * .execute();\n *\n * // Complex update with multiple operations\n * const result = await new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .set({\n * status: 'OCCUPIED',\n * occupants: 3,\n * 'metadata.lastInspection': new Date().toISOString()\n * })\n * .add('securityBreaches', 1)\n * .deleteElementsFromSet('suitableDinosaurs', ['VELOCIRAPTOR'])\n * .condition(op => op.gt('securityLevel', 8))\n * .returnValues('ALL_NEW')\n * .execute();\n * ```\n *\n * @typeParam T - The type of item being updated\n */\nexport class UpdateBuilder<T extends Record<string, unknown>> {\n private updates: UpdateAction[] = [];\n private options: UpdateOptions = {\n returnValues: \"ALL_NEW\",\n };\n private readonly executor: UpdateExecutor<T>;\n private readonly tableName: string;\n private readonly key: PrimaryKeyWithoutExpression;\n\n constructor(executor: UpdateExecutor<T>, tableName: string, key: PrimaryKeyWithoutExpression) {\n this.executor = executor;\n this.tableName = tableName;\n this.key = key;\n }\n\n /**\n * Sets multiple attributes of an item using an object.\n * Use this method when you need to:\n * - Update multiple attributes at once\n * - Set nested attribute values\n * - Modify complex data structures\n *\n * @example\n * ```typescript\n * // Update multiple attributes\n * builder.set({\n * species: 'Tyrannosaurus Rex',\n * height: 20,\n * diet: 'CARNIVORE',\n * 'stats.threatLevel': 10\n * });\n * ```\n */\n set(values: Partial<T>): UpdateBuilder<T>;\n\n /**\n * Sets a single attribute to a specific value.\n * Use this method when you need to:\n * - Update one attribute at a time\n * - Set values with type safety\n * - Update nested attributes\n *\n * @example\n * ```typescript\n * // Set simple attributes\n * builder\n * .set('status', 'SLEEPING')\n * .set('lastFeeding', new Date().toISOString());\n *\n * // Set nested attributes\n * builder\n * .set('location.zone', 'RESTRICTED')\n * .set('stats.health', 100);\n * ```\n */\n set<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;\n set<K extends Path<T>>(valuesOrPath: K | Partial<T>, value?: PathType<T, K>): UpdateBuilder<T> {\n if (typeof valuesOrPath === \"object\") {\n for (const [key, value] of Object.entries(valuesOrPath)) {\n this.updates.push({\n type: \"SET\",\n path: key,\n value,\n });\n }\n } else {\n this.updates.push({\n type: \"SET\",\n path: valuesOrPath,\n value,\n });\n }\n\n return this;\n }\n\n /**\n * Removes an attribute from the item.\n * Use this method when you need to:\n * - Delete attributes completely\n * - Remove nested attributes\n * - Clean up deprecated fields\n *\n * @example\n * ```typescript\n * // Remove simple attributes\n * builder\n * .remove('temporaryTag')\n * .remove('previousLocation');\n *\n * // Remove nested attributes\n * builder\n * .remove('metadata.testData')\n * .remove('stats.experimentalMetrics');\n * ```\n *\n * @param path - The path to the attribute to remove\n * @returns The builder instance for method chaining\n */\n remove<K extends Path<T>>(path: K): UpdateBuilder<T> {\n this.updates.push({\n type: \"REMOVE\",\n path,\n });\n return this;\n }\n\n /**\n * Adds a value to a number attribute or adds elements to a set.\n * Use this method when you need to:\n * - Increment counters\n * - Add elements to a set atomically\n * - Update numerical statistics\n *\n * @example\n * ```typescript\n * // Increment counters\n * builder\n * .add('escapeAttempts', 1)\n * .add('feedingCount', 1);\n *\n * // Add to sets\n * builder\n * .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))\n * .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));\n * ```\n *\n * @param path - The path to the attribute to update\n * @param value - The value to add (number or set)\n * @returns The builder instance for method chaining\n */\n add<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T> {\n this.updates.push({\n type: \"ADD\",\n path,\n value,\n });\n return this;\n }\n\n /**\n * Removes elements from a set attribute.\n * Use this method when you need to:\n * - Remove specific elements from a set\n * - Update set-based attributes atomically\n * - Maintain set membership\n *\n * @example\n * ```typescript\n * // Remove from sets using arrays\n * builder.deleteElementsFromSet(\n * 'allowedHabitats',\n * ['JUNGLE', 'COASTAL']\n * );\n *\n * // Remove from sets using Set objects\n * builder.deleteElementsFromSet(\n * 'knownBehaviors',\n * new Set(['NOCTURNAL', 'TERRITORIAL'])\n * );\n *\n * // Remove from nested sets\n * builder.deleteElementsFromSet(\n * 'stats.compatibleSpecies',\n * ['VELOCIRAPTOR', 'DILOPHOSAURUS']\n * );\n * ```\n *\n * @param path - The path to the set attribute\n * @param value - Elements to remove (array or Set)\n * @returns The builder instance for method chaining\n */\n deleteElementsFromSet<K extends Path<T>>(\n path: K,\n value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>,\n ): UpdateBuilder<T> {\n let valuesToDelete: Set<PathSetElementType<T, K>>;\n\n if (Array.isArray(value)) {\n valuesToDelete = new Set(value);\n } else {\n valuesToDelete = value;\n }\n\n this.updates.push({\n type: \"DELETE\",\n path,\n value: valuesToDelete,\n });\n return this;\n }\n\n /**\n * Adds a condition that must be satisfied for the update to succeed.\n * Use this method when you need to:\n * - Implement optimistic locking\n * - Ensure item state before update\n * - Validate business rules\n * - Prevent concurrent modifications\n *\n * @example\n * ```typescript\n * // Simple condition\n * builder.condition(op =>\n * op.eq('status', 'ACTIVE')\n * );\n *\n * // Health check condition\n * builder.condition(op =>\n * op.and([\n * op.gt('health', 50),\n * op.eq('status', 'HUNTING')\n * ])\n * );\n *\n * // Complex security condition\n * builder.condition(op =>\n * op.and([\n * op.attributeExists('securitySystem'),\n * op.eq('containmentStatus', 'SECURE'),\n * op.lt('aggressionLevel', 8)\n * ])\n * );\n *\n * // Version check (optimistic locking)\n * builder.condition(op =>\n * op.eq('version', currentVersion)\n * );\n * ```\n *\n * @param condition - Either a Condition object or a callback function that builds the condition\n * @returns The builder instance for method chaining\n */\n condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): UpdateBuilder<T> {\n if (typeof condition === \"function\") {\n const conditionOperator: ConditionOperator<T> = {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n };\n this.options.condition = condition(conditionOperator);\n } else {\n this.options.condition = condition;\n }\n return this;\n }\n\n /**\n * Sets which item attributes to include in the response.\n * Use this method when you need to:\n * - Get the complete updated item\n * - Track changes to specific attributes\n * - Compare old and new values\n * - Monitor attribute modifications\n *\n * Available options:\n * - ALL_NEW: All attributes after the update\n * - UPDATED_NEW: Only updated attributes, new values\n * - ALL_OLD: All attributes before the update\n * - UPDATED_OLD: Only updated attributes, old values\n * - NONE: No attributes returned (default)\n *\n * @example\n * ```typescript\n * // Get complete updated dinosaur\n * const result = await builder\n * .set('status', 'SLEEPING')\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * // Track specific attribute changes\n * const result = await builder\n * .set({\n * 'stats.health': 100,\n * 'stats.energy': 95\n * })\n * .returnValues('UPDATED_OLD')\n * .execute();\n *\n * if (result.item) {\n * console.log('Previous health:', result.item.stats?.health);\n * }\n * ```\n *\n * @param returnValues - Which attributes to return in the response\n * @returns The builder instance for method chaining\n */\n returnValues(returnValues: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\"): UpdateBuilder<T> {\n this.options.returnValues = returnValues;\n return this;\n }\n\n /**\n * Generate the DynamoDB command parameters\n */\n toDynamoCommand(): UpdateCommandParams {\n if (this.updates.length === 0) {\n throw new Error(\"No update actions specified\");\n }\n\n const expressionParams: {\n expressionAttributeNames: Record<string, string>;\n expressionAttributeValues: Record<string, unknown>;\n valueCounter: { count: number };\n } = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n // Build the update expression\n let updateExpression = \"\";\n\n // Group updates by type\n const setUpdates: UpdateAction[] = [];\n const removeUpdates: UpdateAction[] = [];\n const addUpdates: UpdateAction[] = [];\n const deleteUpdates: UpdateAction[] = [];\n\n for (const update of this.updates) {\n switch (update.type) {\n case \"SET\":\n setUpdates.push(update);\n break;\n case \"REMOVE\":\n removeUpdates.push(update);\n break;\n case \"ADD\":\n addUpdates.push(update);\n break;\n case \"DELETE\":\n deleteUpdates.push(update);\n break;\n }\n }\n\n // Build SET clause\n if (setUpdates.length > 0) {\n updateExpression += \"SET \";\n updateExpression += setUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n expressionParams.expressionAttributeValues[valueName] = update.value;\n return `${attrName} = ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build REMOVE clause\n if (removeUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"REMOVE \";\n updateExpression += removeUpdates\n .map((update) => {\n return generateAttributeName(expressionParams, update.path);\n })\n .join(\", \");\n }\n\n // Build ADD clause\n if (addUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"ADD \";\n updateExpression += addUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build DELETE clause\n if (deleteUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n\n updateExpression += \"DELETE \";\n updateExpression += deleteUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build condition expression if provided\n let conditionExpression: string | undefined;\n if (this.options.condition) {\n conditionExpression = buildExpression(this.options.condition, expressionParams);\n }\n\n const { expressionAttributeNames, expressionAttributeValues } = expressionParams;\n\n return {\n tableName: this.tableName,\n key: this.key,\n updateExpression,\n conditionExpression,\n expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : undefined,\n expressionAttributeValues:\n Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : undefined,\n returnValues: this.options.returnValues,\n };\n }\n\n /**\n * Adds this update operation to a transaction.\n * Use this method when you need to:\n * - Update items as part of a larger transaction\n * - Ensure multiple updates are atomic\n * - Coordinate updates across multiple items\n *\n * @example\n * ```typescript\n * const transaction = new TransactionBuilder(executor);\n *\n * // Update dinosaur status and habitat occupancy atomically\n * new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('location', 'PADDOCK_A')\n * .set('status', 'CONTAINED')\n * .withTransaction(transaction);\n *\n * new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .add('occupants', 1)\n * .set('lastOccupied', new Date().toISOString())\n * .withTransaction(transaction);\n *\n * // Execute all operations atomically\n * await transaction.execute();\n * ```\n *\n * @param transaction - The transaction builder to add this operation to\n * @returns The builder instance for method chaining\n */\n withTransaction(transaction: TransactionBuilder) {\n const command = this.toDynamoCommand();\n transaction.updateWithCommand(command);\n }\n\n /**\n * Gets a human-readable representation of the update command.\n * Use this method when you need to:\n * - Debug complex update expressions\n * - Verify attribute names and values\n * - Log update operations\n * - Troubleshoot condition expressions\n *\n * @example\n * ```typescript\n * // Create complex update\n * const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })\n * .set({\n * status: 'HUNTING',\n * 'stats.health': 95,\n * 'behavior.lastObserved': new Date().toISOString()\n * })\n * .add('huntingSuccesses', 1)\n * .condition(op => op.gt('health', 50));\n *\n * // Debug the update\n * const debugInfo = builder.debug();\n * console.log('Update operation:', debugInfo);\n * ```\n *\n * @returns A readable representation of the update command with resolved expressions\n */\n debug(): Record<string, unknown> {\n const command = this.toDynamoCommand();\n return debugCommand(command);\n }\n\n /**\n * Executes the update operation against DynamoDB.\n * Use this method when you need to:\n * - Apply updates immediately\n * - Get the updated item values\n * - Handle conditional update failures\n *\n * @example\n * ```typescript\n * try {\n * // Update dinosaur status with conditions\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set({\n * status: 'FEEDING',\n * lastMeal: new Date().toISOString(),\n * 'stats.hunger': 0\n * })\n * .add('feedingCount', 1)\n * .condition(op =>\n * op.and([\n * op.gt('stats.hunger', 80),\n * op.eq('status', 'HUNTING')\n * ])\n * )\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * if (result.item) {\n * console.log('Updated dinosaur:', result.item);\n * }\n * } catch (error) {\n * // Handle condition check failure\n * console.error('Failed to update dinosaur:', error);\n * // Check if dinosaur wasn't hungry enough\n * if (error.name === 'ConditionalCheckFailedException') {\n * console.log('Dinosaur not ready for feeding');\n * }\n * }\n * ```\n *\n * @returns A promise that resolves to an object containing the updated item (if returnValues is set)\n * @throws {ConditionalCheckFailedException} If the condition check fails\n * @throws {Error} If the update operation fails for other reasons\n */\n async execute(): Promise<{ item?: T }> {\n const params = this.toDynamoCommand();\n return this.executor(params);\n }\n}\n"]}
|
package/dist/conditions.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/conditions.ts
|
|
4
|
-
var createComparisonCondition = (type) => (attr, value) => ({
|
|
5
|
-
type,
|
|
6
|
-
attr,
|
|
7
|
-
value
|
|
8
|
-
});
|
|
9
|
-
var eq = createComparisonCondition("eq");
|
|
10
|
-
var ne = createComparisonCondition("ne");
|
|
11
|
-
var lt = createComparisonCondition("lt");
|
|
12
|
-
var lte = createComparisonCondition("lte");
|
|
13
|
-
var gt = createComparisonCondition("gt");
|
|
14
|
-
var gte = createComparisonCondition("gte");
|
|
15
|
-
var between = (attr, lower, upper) => ({
|
|
16
|
-
type: "between",
|
|
17
|
-
attr,
|
|
18
|
-
value: [lower, upper]
|
|
19
|
-
});
|
|
20
|
-
var beginsWith = createComparisonCondition("beginsWith");
|
|
21
|
-
var contains = createComparisonCondition("contains");
|
|
22
|
-
var attributeExists = (attr) => ({
|
|
23
|
-
type: "attributeExists",
|
|
24
|
-
attr
|
|
25
|
-
});
|
|
26
|
-
var attributeNotExists = (attr) => ({
|
|
27
|
-
type: "attributeNotExists",
|
|
28
|
-
attr
|
|
29
|
-
});
|
|
30
|
-
var and = (...conditions) => ({
|
|
31
|
-
type: "and",
|
|
32
|
-
conditions
|
|
33
|
-
});
|
|
34
|
-
var or = (...conditions) => ({
|
|
35
|
-
type: "or",
|
|
36
|
-
conditions
|
|
37
|
-
});
|
|
38
|
-
var not = (condition) => ({
|
|
39
|
-
type: "not",
|
|
40
|
-
condition
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
exports.and = and;
|
|
44
|
-
exports.attributeExists = attributeExists;
|
|
45
|
-
exports.attributeNotExists = attributeNotExists;
|
|
46
|
-
exports.beginsWith = beginsWith;
|
|
47
|
-
exports.between = between;
|
|
48
|
-
exports.contains = contains;
|
|
49
|
-
exports.createComparisonCondition = createComparisonCondition;
|
|
50
|
-
exports.eq = eq;
|
|
51
|
-
exports.gt = gt;
|
|
52
|
-
exports.gte = gte;
|
|
53
|
-
exports.lt = lt;
|
|
54
|
-
exports.lte = lte;
|
|
55
|
-
exports.ne = ne;
|
|
56
|
-
exports.not = not;
|
|
57
|
-
exports.or = or;
|
|
58
|
-
//# sourceMappingURL=conditions.cjs.map
|
|
59
|
-
//# sourceMappingURL=conditions.cjs.map
|
package/dist/conditions.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/conditions.ts"],"names":[],"mappings":";;;AA8FO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,CAAC,MAAc,KAA+B,MAAA;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA;AAQW,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,GAAA,GAAM,0BAA0B,KAAK;AAQrC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,GAAA,GAAM,0BAA0B,KAAK;AAQ3C,IAAM,OAAU,GAAA,CAAC,IAAc,EAAA,KAAA,EAAgB,KAA+B,MAAA;AAAA,EACnF,IAAM,EAAA,SAAA;AAAA,EACN,IAAA;AAAA,EACA,KAAA,EAAO,CAAC,KAAA,EAAO,KAAK;AACtB,CAAA;AAQa,IAAA,UAAA,GAAa,0BAA0B,YAAY;AAQnD,IAAA,QAAA,GAAW,0BAA0B,UAAU;AAQ/C,IAAA,eAAA,GAAkB,CAAC,IAA6B,MAAA;AAAA,EAC3D,IAAM,EAAA,iBAAA;AAAA,EACN;AACF,CAAA;AAQa,IAAA,kBAAA,GAAqB,CAAC,IAA6B,MAAA;AAAA,EAC9D,IAAM,EAAA,oBAAA;AAAA,EACN;AACF,CAAA;AAaa,IAAA,GAAA,GAAM,IAAI,UAAwC,MAAA;AAAA,EAC7D,IAAM,EAAA,KAAA;AAAA,EACN;AACF,CAAA;AAWa,IAAA,EAAA,GAAK,IAAI,UAAwC,MAAA;AAAA,EAC5D,IAAM,EAAA,IAAA;AAAA,EACN;AACF,CAAA;AAQa,IAAA,GAAA,GAAM,CAAC,SAAqC,MAAA;AAAA,EACvD,IAAM,EAAA,KAAA;AAAA,EACN;AACF,CAAA","file":"conditions.cjs","sourcesContent":["import type { Path, PathType } from \"./builders/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 * - 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 | \"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: Record<string, unknown>;\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 a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends Record<string, unknown>> = {\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n and: (...conditions: Condition[]) => Condition;\n or: (...conditions: Condition[]) => Condition;\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"]}
|
package/dist/conditions.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// src/conditions.ts
|
|
2
|
-
var createComparisonCondition = (type) => (attr, value) => ({
|
|
3
|
-
type,
|
|
4
|
-
attr,
|
|
5
|
-
value
|
|
6
|
-
});
|
|
7
|
-
var eq = createComparisonCondition("eq");
|
|
8
|
-
var ne = createComparisonCondition("ne");
|
|
9
|
-
var lt = createComparisonCondition("lt");
|
|
10
|
-
var lte = createComparisonCondition("lte");
|
|
11
|
-
var gt = createComparisonCondition("gt");
|
|
12
|
-
var gte = createComparisonCondition("gte");
|
|
13
|
-
var between = (attr, lower, upper) => ({
|
|
14
|
-
type: "between",
|
|
15
|
-
attr,
|
|
16
|
-
value: [lower, upper]
|
|
17
|
-
});
|
|
18
|
-
var beginsWith = createComparisonCondition("beginsWith");
|
|
19
|
-
var contains = createComparisonCondition("contains");
|
|
20
|
-
var attributeExists = (attr) => ({
|
|
21
|
-
type: "attributeExists",
|
|
22
|
-
attr
|
|
23
|
-
});
|
|
24
|
-
var attributeNotExists = (attr) => ({
|
|
25
|
-
type: "attributeNotExists",
|
|
26
|
-
attr
|
|
27
|
-
});
|
|
28
|
-
var and = (...conditions) => ({
|
|
29
|
-
type: "and",
|
|
30
|
-
conditions
|
|
31
|
-
});
|
|
32
|
-
var or = (...conditions) => ({
|
|
33
|
-
type: "or",
|
|
34
|
-
conditions
|
|
35
|
-
});
|
|
36
|
-
var not = (condition) => ({
|
|
37
|
-
type: "not",
|
|
38
|
-
condition
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export { and, attributeExists, attributeNotExists, beginsWith, between, contains, createComparisonCondition, eq, gt, gte, lt, lte, ne, not, or };
|
|
42
|
-
//# sourceMappingURL=conditions.js.map
|
|
43
|
-
//# sourceMappingURL=conditions.js.map
|
package/dist/conditions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/conditions.ts"],"names":[],"mappings":";AA8FO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,CAAC,MAAc,KAA+B,MAAA;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA;AAQW,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,GAAA,GAAM,0BAA0B,KAAK;AAQrC,IAAA,EAAA,GAAK,0BAA0B,IAAI;AAQnC,IAAA,GAAA,GAAM,0BAA0B,KAAK;AAQ3C,IAAM,OAAU,GAAA,CAAC,IAAc,EAAA,KAAA,EAAgB,KAA+B,MAAA;AAAA,EACnF,IAAM,EAAA,SAAA;AAAA,EACN,IAAA;AAAA,EACA,KAAA,EAAO,CAAC,KAAA,EAAO,KAAK;AACtB,CAAA;AAQa,IAAA,UAAA,GAAa,0BAA0B,YAAY;AAQnD,IAAA,QAAA,GAAW,0BAA0B,UAAU;AAQ/C,IAAA,eAAA,GAAkB,CAAC,IAA6B,MAAA;AAAA,EAC3D,IAAM,EAAA,iBAAA;AAAA,EACN;AACF,CAAA;AAQa,IAAA,kBAAA,GAAqB,CAAC,IAA6B,MAAA;AAAA,EAC9D,IAAM,EAAA,oBAAA;AAAA,EACN;AACF,CAAA;AAaa,IAAA,GAAA,GAAM,IAAI,UAAwC,MAAA;AAAA,EAC7D,IAAM,EAAA,KAAA;AAAA,EACN;AACF,CAAA;AAWa,IAAA,EAAA,GAAK,IAAI,UAAwC,MAAA;AAAA,EAC5D,IAAM,EAAA,IAAA;AAAA,EACN;AACF,CAAA;AAQa,IAAA,GAAA,GAAM,CAAC,SAAqC,MAAA;AAAA,EACvD,IAAM,EAAA,KAAA;AAAA,EACN;AACF,CAAA","file":"conditions.js","sourcesContent":["import type { Path, PathType } from \"./builders/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 * - 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 | \"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: Record<string, unknown>;\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 a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends Record<string, unknown>> = {\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n and: (...conditions: Condition[]) => Condition;\n or: (...conditions: Condition[]) => Condition;\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"]}
|
package/dist/entity.cjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/entity.ts
|
|
4
|
-
function defineEntity(config) {
|
|
5
|
-
return {
|
|
6
|
-
createRepository: (table) => {
|
|
7
|
-
const repository = {
|
|
8
|
-
_hooks: config.hooks,
|
|
9
|
-
create: (data) => {
|
|
10
|
-
const builder = table.create(data);
|
|
11
|
-
const originalExecute = builder.execute;
|
|
12
|
-
builder.execute = async () => {
|
|
13
|
-
const validationResult = await config.schema["~standard"].validate(data);
|
|
14
|
-
if ("issues" in validationResult && validationResult.issues) {
|
|
15
|
-
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
16
|
-
}
|
|
17
|
-
Object.assign(builder, { item: validationResult.value });
|
|
18
|
-
const result = await originalExecute.call(builder);
|
|
19
|
-
if (!result) {
|
|
20
|
-
throw new Error("Failed to create item");
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
return builder;
|
|
25
|
-
},
|
|
26
|
-
upsert: (data) => {
|
|
27
|
-
const builder = table.put(data);
|
|
28
|
-
const originalExecute = builder.execute;
|
|
29
|
-
builder.execute = async () => {
|
|
30
|
-
const validationResult = await config.schema["~standard"].validate(data);
|
|
31
|
-
if ("issues" in validationResult && validationResult.issues) {
|
|
32
|
-
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
33
|
-
}
|
|
34
|
-
Object.assign(builder, { item: validationResult.value });
|
|
35
|
-
const result = await originalExecute.call(builder);
|
|
36
|
-
if (!result) {
|
|
37
|
-
throw new Error("Failed to upsert item");
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
return builder;
|
|
42
|
-
},
|
|
43
|
-
get: (key) => {
|
|
44
|
-
const builder = table.get(key);
|
|
45
|
-
const originalExecute = builder.execute;
|
|
46
|
-
builder.execute = async () => {
|
|
47
|
-
const result = await originalExecute.call(builder);
|
|
48
|
-
const item = result?.item;
|
|
49
|
-
return {
|
|
50
|
-
item: config.hooks?.afterGet ? await config.hooks.afterGet(item) : item
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
return builder;
|
|
54
|
-
},
|
|
55
|
-
update: (key, data) => {
|
|
56
|
-
const builder = table.update(key);
|
|
57
|
-
const originalExecute = builder.execute;
|
|
58
|
-
builder.execute = async () => {
|
|
59
|
-
const result = await originalExecute.call(builder);
|
|
60
|
-
if (!result?.item) {
|
|
61
|
-
throw new Error("Failed to update item");
|
|
62
|
-
}
|
|
63
|
-
return result.item;
|
|
64
|
-
};
|
|
65
|
-
return builder;
|
|
66
|
-
},
|
|
67
|
-
delete: (key) => {
|
|
68
|
-
return table.delete(key);
|
|
69
|
-
},
|
|
70
|
-
query: {},
|
|
71
|
-
// Add a method to create a query builder
|
|
72
|
-
queryBuilder: (key) => {
|
|
73
|
-
const primaryKey = {
|
|
74
|
-
pk: key.pk,
|
|
75
|
-
...key.sk ? { sk: (op) => op.eq(key.sk) } : {}
|
|
76
|
-
};
|
|
77
|
-
return table.query(primaryKey);
|
|
78
|
-
},
|
|
79
|
-
// Implement findBy method to find entities by their attributes
|
|
80
|
-
findBy: (attribute, value, options) => {
|
|
81
|
-
const scanBuilder = table.scan().filter((op) => op.eq(attribute, value));
|
|
82
|
-
if (options?.limit) {
|
|
83
|
-
scanBuilder.limit(options.limit);
|
|
84
|
-
}
|
|
85
|
-
if (options?.lastEvaluatedKey) {
|
|
86
|
-
scanBuilder.startFrom(options.lastEvaluatedKey);
|
|
87
|
-
}
|
|
88
|
-
return scanBuilder;
|
|
89
|
-
},
|
|
90
|
-
// Implement scan method to scan all entities
|
|
91
|
-
scan: (options) => {
|
|
92
|
-
const scanBuilder = table.scan();
|
|
93
|
-
if (options?.limit) {
|
|
94
|
-
scanBuilder.limit(options.limit);
|
|
95
|
-
}
|
|
96
|
-
if (options?.lastEvaluatedKey) {
|
|
97
|
-
scanBuilder.startFrom(options.lastEvaluatedKey);
|
|
98
|
-
}
|
|
99
|
-
return scanBuilder;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
if (config.queries) {
|
|
103
|
-
for (const [key, queryFn] of Object.entries(config.queries)) {
|
|
104
|
-
repository.query[key] = queryFn.bind(repository);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return repository;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function createQueries() {
|
|
112
|
-
return {
|
|
113
|
-
input: (schema) => ({
|
|
114
|
-
// biome-ignore lint/complexity/noBannedTypes: <explanation>
|
|
115
|
-
query: (handler) => {
|
|
116
|
-
const queryFn = async function(input) {
|
|
117
|
-
const validationResult = await schema["~standard"].validate(input);
|
|
118
|
-
if ("issues" in validationResult && validationResult.issues) {
|
|
119
|
-
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
120
|
-
}
|
|
121
|
-
const queryBuilder = handler({ input: validationResult.value, entity: this });
|
|
122
|
-
const result = await queryBuilder.execute();
|
|
123
|
-
let items = result.items;
|
|
124
|
-
if (this._hooks?.afterGet) {
|
|
125
|
-
const processedItems = await Promise.all(
|
|
126
|
-
// biome-ignore lint/style/noNonNullAssertion: The method will exit as it's confirmed above
|
|
127
|
-
items.map(async (item) => await this._hooks.afterGet(item))
|
|
128
|
-
);
|
|
129
|
-
items = processedItems.filter((item) => item !== null);
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
items,
|
|
133
|
-
lastEvaluatedKey: result.lastEvaluatedKey
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
return queryFn;
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function createIndex() {
|
|
142
|
-
return {
|
|
143
|
-
partitionKey: (pkFn) => ({
|
|
144
|
-
sortKey: (skFn) => ({
|
|
145
|
-
name: "custom",
|
|
146
|
-
partitionKey: "pk",
|
|
147
|
-
sortKey: "sk",
|
|
148
|
-
generateKey: (item) => ({
|
|
149
|
-
pk: pkFn(item),
|
|
150
|
-
sk: skFn(item)
|
|
151
|
-
})
|
|
152
|
-
}),
|
|
153
|
-
// Allow creating an index with only a partition key
|
|
154
|
-
withoutSortKey: () => ({
|
|
155
|
-
name: "custom",
|
|
156
|
-
partitionKey: "pk",
|
|
157
|
-
generateKey: (item) => ({
|
|
158
|
-
pk: pkFn(item)
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
exports.createIndex = createIndex;
|
|
166
|
-
exports.createQueries = createQueries;
|
|
167
|
-
exports.defineEntity = defineEntity;
|
|
168
|
-
//# sourceMappingURL=entity.cjs.map
|
|
169
|
-
//# sourceMappingURL=entity.cjs.map
|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AAa,MAAA;AAAA,UACzB,EAAA,EAAI,KAAK,IAAI;AAAA,SACf;AAAA,OACF;AAAA,KACJ;AAAA,GACF;AACF","file":"entity.cjs","sourcesContent":["import type { Table } from \"./table\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type { PrimaryKeyWithoutExpression } from \"./conditions\";\nimport type { Index } from \"./types\";\nimport type { QueryBuilder } from \"./builders/query-builder\";\nimport type { Path, PathType } from \"./builders/types\";\nimport type { KeyConditionOperator } from \"./conditions\";\nimport type { ScanBuilder } from \"./builders/scan-builder\";\nimport type { DeleteBuilder } from \"./builders/delete-builder\";\nimport type { UpdateBuilder } from \"./builders/update-builder\";\nimport type { GetBuilder } from \"./builders/get-builder\";\nimport type { PutBuilder } from \"./builders/put-builder\";\n\nexport interface EntityHooks<T extends Record<string, unknown>> {\n beforeCreate?: (data: T) => Promise<T> | T;\n afterCreate?: (data: T) => Promise<T> | T;\n beforeUpdate?: (data: Partial<T>) => Promise<Partial<T>> | Partial<T>;\n afterUpdate?: (data: T) => Promise<T> | T;\n afterGet?: (data: T | undefined) => Promise<T | undefined> | T | undefined;\n}\n\n// Define a type for query functions\nexport type QueryFunction<T extends Record<string, unknown>, I, R = T[]> = (input: I) => R;\n\n// Define a type for the query record\nexport type QueryRecord<T extends Record<string, unknown>> = Record<string, QueryBuilder<T>>;\n\n// Define a type for the result of a query builder\nexport type QueryBuilderResult<T extends Record<string, unknown>> = {\n items: T[];\n lastEvaluatedKey?: Record<string, unknown>;\n};\n\nexport interface EntityConfig<T extends Record<string, unknown>, Q extends QueryRecord<T> = {}> {\n name: string;\n schema: StandardSchemaV1<T>;\n primaryKey: Index;\n indexes?: Record<string, Index>;\n queries?: Q;\n hooks?: EntityHooks<T>;\n}\n\nexport interface PaginationOptions {\n limit?: number;\n lastEvaluatedKey?: Record<string, any>;\n}\n\nexport interface PaginatedResult<T> {\n items: T[];\n lastEvaluatedKey?: Record<string, any>;\n hasMore: boolean;\n}\n\nexport interface EntityRepository<T extends Record<string, unknown>, Q extends QueryRecord<T> = {}> {\n _hooks?: EntityHooks<T>;\n create: (data: T) => PutBuilder<T>;\n upsert: (data: T) => PutBuilder<T>;\n get: (key: PrimaryKeyWithoutExpression) => GetBuilder<T>;\n update: (key: PrimaryKeyWithoutExpression, data: Partial<T>) => UpdateBuilder<T>;\n delete: (key: PrimaryKeyWithoutExpression) => DeleteBuilder;\n query: Q;\n // Add a method to create a query builder\n queryBuilder: (key: PrimaryKeyWithoutExpression) => QueryBuilder<T, any>;\n // Add a method to find entities by their attributes\n findBy: <K extends keyof T>(attribute: K, value: T[K], options?: PaginationOptions) => any; // Returns ScanBuilder<T>\n // Add a method to scan all entities\n scan: (options?: PaginationOptions) => ScanBuilder<T>;\n}\n\nexport function defineEntity<T extends Record<string, unknown>, Q extends QueryRecord<T> = {}>(\n config: EntityConfig<T, Q>,\n) {\n return {\n createRepository: (table: Table): EntityRepository<T, Q> => {\n // Create a repository with hooks attached\n const repository = {\n _hooks: config.hooks,\n create: (data: T) => {\n // We need to handle the async operations when the consumer calls execute\n const builder = table.create(data);\n\n // Wrap the builder's execute method to apply validation only (no hooks)\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate data against schema\n const validationResult = await config.schema[\"~standard\"].validate(data);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Update the item in the builder with the validated data\n Object.assign(builder, { item: validationResult.value });\n\n // Execute the builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to create item\");\n }\n\n return result;\n };\n\n return builder;\n },\n\n upsert: (data: T) => {\n // We need to handle the async operations when the consumer calls execute\n const builder = table.put(data);\n\n // Wrap the builder's execute method to apply validation only (no hooks)\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate data against schema\n const validationResult = await config.schema[\"~standard\"].validate(data);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Update the item in the builder with the validated data\n Object.assign(builder, { item: validationResult.value });\n\n // Execute the builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to upsert item\");\n }\n\n return result;\n };\n\n return builder;\n },\n\n get: (key: PrimaryKeyWithoutExpression) => {\n const builder = table.get<T>(key);\n\n // Wrap the builder's execute method to apply afterGet hook\n const originalExecute = builder.execute;\n\n builder.execute = async () => {\n const result = await originalExecute.call(builder);\n const item = result?.item;\n\n // Apply afterGet hook if exists\n return {\n item: config.hooks?.afterGet ? await config.hooks.afterGet(item as T) : item,\n };\n };\n\n return builder;\n },\n\n update: (key: PrimaryKeyWithoutExpression, data: Partial<T>) => {\n // Create a builder without hooks\n const builder = table.update<T>(key);\n\n // Wrap the builder's execute method to handle errors\n const originalExecute = builder.execute;\n builder.execute = async () => {\n const result = await originalExecute.call(builder);\n if (!result?.item) {\n throw new Error(\"Failed to update item\");\n }\n\n // Return the item without applying hooks\n return result.item as T;\n };\n\n return builder;\n },\n\n delete: (key: PrimaryKeyWithoutExpression) => {\n return table.delete(key);\n },\n\n query: {} as Q,\n\n // Add a method to create a query builder\n queryBuilder: (key: PrimaryKeyWithoutExpression) => {\n // Convert PrimaryKeyWithoutExpression to PrimaryKey\n const primaryKey = {\n pk: key.pk,\n ...(key.sk ? { sk: (op: KeyConditionOperator) => op.eq(key.sk as string) } : {}),\n };\n return table.query<T>(primaryKey);\n },\n\n // Implement findBy method to find entities by their attributes\n findBy: <K extends keyof T>(attribute: K, value: T[K], options?: PaginationOptions) => {\n // Use scan with a filter to find entities by attribute\n const scanBuilder = table.scan<T>().filter((op) => op.eq(attribute as string as Path<T>, value as any));\n\n // Apply pagination options if provided\n if (options?.limit) {\n scanBuilder.limit(options.limit);\n }\n\n if (options?.lastEvaluatedKey) {\n scanBuilder.startFrom(options.lastEvaluatedKey);\n }\n\n // Return the builder without applying hooks\n return scanBuilder;\n },\n\n // Implement scan method to scan all entities\n scan: (options?: PaginationOptions) => {\n // Create a scan builder\n const scanBuilder = table.scan<T>();\n\n // Apply pagination options if provided\n if (options?.limit) {\n scanBuilder.limit(options.limit);\n }\n\n if (options?.lastEvaluatedKey) {\n scanBuilder.startFrom(options.lastEvaluatedKey);\n }\n\n // Return the builder without applying hooks\n return scanBuilder;\n },\n };\n\n // Bind query functions to the repository after it's fully defined\n if (config.queries) {\n for (const [key, queryFn] of Object.entries(config.queries)) {\n // biome-ignore lint/suspicious/noExplicitAny: Let the magic happen\n (repository.query as any)[key] = queryFn.bind(repository);\n }\n }\n\n return repository;\n },\n };\n}\n\nexport function createQueries<T extends Record<string, unknown>>() {\n return {\n input: <I, R = QueryBuilderResult<T>>(schema: StandardSchemaV1<I>) => ({\n // biome-ignore lint/complexity/noBannedTypes: <explanation>\n query: <Q extends QueryRecord<T> = {}>(\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n handler: (params: { input: I; entity: EntityRepository<T, Q> }) => QueryBuilder<T, any>,\n ): QueryFunction<T, I, R> => {\n // Return a function that will be bound to the repository when it's created\n const queryFn = async function (this: EntityRepository<T, Q>, input: I): Promise<R> {\n // Validate input against schema\n const validationResult = await schema[\"~standard\"].validate(input);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n // Use 'this' as the entity repository (will be bound when the repository is created)\n const queryBuilder = handler({ input: validationResult.value, entity: this });\n\n // Execute the query\n const result = await queryBuilder.execute();\n\n // Apply afterGet hook to each item if exists\n let items = result.items;\n if (this._hooks?.afterGet) {\n const processedItems = await Promise.all(\n // biome-ignore lint/style/noNonNullAssertion: The method will exit as it's confirmed above\n items.map(async (item) => await this._hooks!.afterGet!(item as T)),\n );\n items = processedItems.filter((item): item is NonNullable<typeof item> => item !== null) as T[];\n }\n\n // Return the full result with processed items\n return {\n items,\n lastEvaluatedKey: result.lastEvaluatedKey,\n } as unknown as R;\n };\n\n return queryFn as unknown as QueryFunction<T, I, R>;\n },\n }),\n };\n}\n\nexport interface IndexDefinition<T extends Record<string, unknown>> extends Index {\n name: string;\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\nexport function createIndex<T extends Record<string, unknown>>() {\n return {\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n generateKey: (item: T) => ({\n pk: pkFn(item),\n sk: skFn(item),\n }),\n }) as IndexDefinition<T>,\n\n // Allow creating an index with only a partition key\n withoutSortKey: () =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n generateKey: (item: T) => ({\n pk: pkFn(item),\n }),\n }) as IndexDefinition<T>,\n }),\n };\n}\n"]}
|