dyno-table 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/builders/condition-check-builder.cjs.map +1 -1
- package/dist/builders/condition-check-builder.js.map +1 -1
- package/dist/builders/delete-builder.cjs.map +1 -1
- package/dist/builders/delete-builder.d.cts +1 -1
- package/dist/builders/delete-builder.d.ts +1 -1
- package/dist/builders/delete-builder.js.map +1 -1
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.cjs.map +1 -1
- package/dist/builders/put-builder.d.cts +1 -1
- package/dist/builders/put-builder.d.ts +1 -1
- package/dist/builders/put-builder.js.map +1 -1
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.cjs +33 -9
- package/dist/builders/transaction-builder.cjs.map +1 -1
- package/dist/builders/transaction-builder.js +33 -9
- package/dist/builders/transaction-builder.js.map +1 -1
- package/dist/builders/update-builder.cjs.map +1 -1
- package/dist/builders/update-builder.d.cts +1 -1
- package/dist/builders/update-builder.d.ts +1 -1
- package/dist/builders/update-builder.js.map +1 -1
- package/dist/entity.cjs +152 -84
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +1 -1
- package/dist/entity.d.ts +1 -1
- package/dist/entity.js +152 -84
- package/dist/entity.js.map +1 -1
- package/dist/{table-BW3cmUqr.d.ts → table-BelHPTvr.d.ts} +1 -1
- package/dist/{table-BEhBPy2G.d.cts → table-DIfupG_s.d.cts} +1 -1
- package/dist/table.cjs +34 -13
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.js +34 -13
- package/dist/table.js.map +1 -1
- package/package.json +2 -2
package/dist/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/conditions.ts","../src/ent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ACF;AAAA,GACF;AACF;AAOO,SAAS,WAAc,GAAA;AAC5B,EAAO,OAAA;AAAA,IACL,KAAA,EAAO,CAAuB,MAAiC,MAAA;AAAA,MAC7D,YAAA,EAAc,CAAgC,IAAa,MAAA;AAAA,QACzD,OAAA,EAAS,CAAgC,IACtC,MAAA;AAAA,UACC,IAAM,EAAA,QAAA;AAAA,UACN,YAAc,EAAA,IAAA;AAAA,UACd,OAAS,EAAA,IAAA;AAAA,UACT,WAAA,EAAa,CAAC,IAAa,MAAA;AAAA,YACzB,EAAA,EAAI,KAAK,IAAI,CAAA;AAAA,YACb,EAAA,EAAI,KAAK,IAAI;AAAA,WACf;AAAA,SACF,CAAA;AAAA;AAAA,QAGF,gBAAgB,OACb;AAAA,UACC,IAAM,EAAA,QAAA;AAAA,UACN,YAAc,EAAA,IAAA;AAAA,UACd,WAAA,EAAa,CAAC,IAAa,MAAA;AAAA,YACzB,EAAA,EAAI,KAAK,IAAI;AAAA,WACf;AAAA,SACF;AAAA,OACJ;AAAA,KACF;AAAA,GACF;AACF","file":"entity.js","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - 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: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n 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 { DeleteBuilder } from \"./builders/delete-builder\";\nimport type { GetBuilder } from \"./builders/get-builder\";\nimport type { PutBuilder } from \"./builders/put-builder\";\nimport type { ScanBuilder } from \"./builders/scan-builder\";\nimport type { UpdateBuilder } from \"./builders/update-builder\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type { Table } from \"./table\";\nimport type { DynamoItem, Index, TableConfig } from \"./types\";\nimport { eq, type PrimaryKey, type PrimaryKeyWithoutExpression } from \"./conditions\";\nimport type { QueryBuilder } from \"./builders/query-builder\";\n\n// Define the QueryFunction type with a generic return type\nexport type QueryFunction<T extends DynamoItem, I, R> = (input: I) => R;\n\n// Define a type for the query record that preserves the input type for each query function\nexport type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {\n schema?: StandardSchemaV1<I>;\n};\n\nexport type QueryRecord<T extends DynamoItem> = {\n // biome-ignore lint/suspicious/noExplicitAny: This is for flexibility\n [K: string]: QueryFunctionWithSchema<T, any, ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>;\n};\n\n// Define a type for entity with only scan, get and query methods\nexport type QueryEntity<T extends DynamoItem> = {\n scan: () => ScanBuilder<T>;\n get: (key: PrimaryKeyWithoutExpression) => GetBuilder<T>;\n query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;\n};\n\ninterface Settings {\n /**\n * Defaults to \"entityType\"\n */\n entityTypeAttributeName?: string;\n timestamps?: {\n createdAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"createdAt\"\n */\n attributeName?: string;\n };\n updatedAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"updatedAt\"\n */\n attributeName?: string;\n };\n };\n}\n\nexport interface EntityConfig<\n T extends DynamoItem,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n name: string;\n schema: StandardSchemaV1<T>;\n primaryKey: IndexDefinition<I>;\n indexes?: Record<string, Index>;\n queries: Q;\n settings?: Settings;\n}\n\nexport interface EntityRepository<\n /**\n * The Entity Type\n */\n T extends DynamoItem,\n /**\n * The Primary Index (Partition index) Type\n */\n I extends DynamoItem = T,\n /**\n * The Queries object\n */\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n create: (data: T) => PutBuilder<T>;\n upsert: (data: T & I) => PutBuilder<T>;\n get: (key: I) => GetBuilder<T>;\n update: (key: I, data: Partial<T>) => UpdateBuilder<T>;\n delete: (key: I) => DeleteBuilder;\n query: Q;\n scan: () => ScanBuilder<T>;\n}\n\n/**\n * Creates an entity definition with type-safe operations\n *\n * @example\n * ```typescript\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * const UserEntity = defineEntity<User>({\n * name: \"User\",\n * schema: userSchema,\n * primaryKey: primaryKey,\n * });\n * ```\n */\nexport function defineEntity<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(\n config: EntityConfig<T, I, Q>,\n) {\n const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? \"entityType\";\n\n /**\n * Generates an object containing timestamp attributes based on the given configuration settings.\n * The function determines the presence and format of \"createdAt\" and \"updatedAt\" timestamps dynamically.\n *\n * @returns {Record<string, string | number>} An object containing one or both of the \"createdAt\" and \"updatedAt\" timestamp attributes, depending on the configuration. Each timestamp can be formatted as either an ISO string or a UNIX timestamp.\n *\n * @throws Will not throw errors but depends on `config.settings?.timestamps` to be properly defined.\n * - If `createdAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.createdAt.attributeName` or defaults to \"createdAt\".\n * - If `updatedAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.updatedAt.attributeName` or defaults to \"updatedAt\".\n *\n * Configuration Details:\n * - `config.settings.timestamps.createdAt.format`: Determines the format of the \"createdAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n * - `config.settings.timestamps.updatedAt.format`: Determines the format of the \"updatedAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n *\n * The returned object keys and values depend on the provided configuration.\n */\n const generateTimestamps = (): Record<string, string | number> => {\n const timestamps: Record<string, string | number> = {};\n\n if (config.settings?.timestamps) {\n const now = new Date();\n\n if (config.settings.timestamps.createdAt) {\n const attributeName = config.settings.timestamps.createdAt.attributeName ?? \"createdAt\";\n timestamps[attributeName] =\n config.settings.timestamps.createdAt.format === \"UNIX\" ? Math.floor(Date.now() / 1000) : now.toISOString();\n }\n\n if (config.settings.timestamps.updatedAt) {\n const attributeName = config.settings.timestamps.updatedAt.attributeName ?? \"updatedAt\";\n timestamps[attributeName] =\n config.settings.timestamps.updatedAt.format === \"UNIX\" ? Math.floor(Date.now() / 1000) : now.toISOString();\n }\n }\n\n return timestamps;\n };\n\n return {\n name: config.name,\n createRepository: (table: Table): EntityRepository<T, I, Q> => {\n // Create a repository\n const repository = {\n create: (data: T) => {\n // We need to handle the async operations when the consumer calls execute\n const builder = table.create<T>({\n ...data,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps(),\n });\n\n // Wrap the builder's execute method to apply validation only\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 const primaryKey = config.primaryKey.generateKey(validationResult.value as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(validationResult.value);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n // Update the item in the builder with the validated data, entity type, and timestamps\n Object.assign(builder, {\n item: {\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps(),\n },\n });\n\n // Execute the builder\n return await originalExecute.call(builder);\n };\n\n return builder;\n },\n\n upsert: (data: T & I) => {\n const primaryKey = config.primaryKey.generateKey(data);\n\n // We need to handle the async operations when the consumer calls execute\n const builder = table.put<T>({\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...data,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps(),\n });\n\n // Wrap the builder's execute method to apply validation only\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, entity type, and timestamps\n Object.assign(builder, {\n item: {\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps(),\n },\n });\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: <K extends I>(key: K) => {\n // Transform the input key into a PrimaryKeyWithoutExpression using the primary key definition\n const primaryKeyObj = config.primaryKey.generateKey(key);\n return table.get<T>(primaryKeyObj);\n },\n\n update: <K extends I>(key: K, data: Partial<T>) => {\n // Transform the input key into a PrimaryKeyWithoutExpression using the primary key definition\n const primaryKeyObj = config.primaryKey.generateKey(key);\n const builder = table.update<T>(primaryKeyObj);\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Generate updatedAt timestamp if configured\n const timestamps: Record<string, string | number> = {};\n if (config.settings?.timestamps?.updatedAt) {\n const now = new Date();\n const attributeName = config.settings.timestamps.updatedAt.attributeName ?? \"updatedAt\";\n timestamps[attributeName] =\n config.settings.timestamps.updatedAt.format === \"UNIX\"\n ? Math.floor(Date.now() / 1000)\n : now.toISOString();\n }\n\n // Merge the data with timestamps\n builder.set({\n ...data,\n ...timestamps,\n });\n\n return builder;\n },\n\n delete: <K extends I>(key: K) => {\n // Transform the input key into a PrimaryKeyWithoutExpression using the primary key definition\n const primaryKeyObj = config.primaryKey.generateKey(key);\n const builder = table.delete(primaryKeyObj);\n builder.condition(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n\n query: Object.entries(config.queries || {}).reduce((acc, [key, inputCallback]) => {\n // @ts-expect-error - We need to cast the queryFn to a function that takes an unknown input\n acc[key] = (input: unknown) => {\n // Create a QueryEntity object with only the necessary methods\n const queryEntity: QueryEntity<T> = {\n scan: repository.scan,\n get: (key: PrimaryKeyWithoutExpression) => table.get<T>(key),\n query: (keyCondition: PrimaryKey) => {\n return table.query<T>(keyCondition);\n },\n };\n\n // Execute the query function to get the builder - This type is incorrect and needs to be fixed\n const queryBuilderCallback = inputCallback(input);\n\n // Run the inner handler which allows the user to apply their desired contraints\n // to the query builder of their choice\n // @ts-expect-error - We need to cast the queryBuilderCallback to a function that takes a QueryEntity\n const builder = queryBuilderCallback(queryEntity);\n\n // Add entity type filter if the builder has filter method\n if (builder && typeof builder === \"object\" && \"filter\" in builder && typeof builder.filter === \"function\") {\n builder.filter(eq(entityTypeAttributeName, config.name));\n }\n\n // Wrap the builder's execute method if it exists\n if (builder && typeof builder === \"object\" && \"execute\" in builder) {\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate the input before executing the query\n const queryFn = (\n config.queries as unknown as Record<string, QueryFunctionWithSchema<T, I, typeof builder>>\n )[key];\n\n if (queryFn && typeof queryFn === \"function\") {\n // Get the schema from the query function\n const schema = queryFn.schema;\n if (schema?.[\"~standard\"]?.validate && typeof schema[\"~standard\"].validate === \"function\") {\n const validationResult = schema[\"~standard\"].validate(input);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(\n `Validation failed: ${validationResult.issues.map((issue) => issue.message).join(\", \")}`,\n );\n }\n }\n }\n\n // Execute the original builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to execute query\");\n }\n return result;\n };\n }\n\n return builder;\n };\n return acc;\n }, {} as Q),\n\n scan: () => {\n const scanBuilder = table.scan<T>();\n scanBuilder.filter(eq(entityTypeAttributeName, config.name));\n\n return scanBuilder;\n },\n };\n\n return repository;\n },\n };\n}\n\nexport function createQueries<T extends DynamoItem>() {\n return {\n input: <I>(schema: StandardSchemaV1<I>) => ({\n query: <\n Q extends QueryRecord<T> = QueryRecord<T>,\n R = ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>,\n >(\n handler: (params: { input: I; entity: QueryEntity<T> }) => R,\n ) => {\n // Create a query function that conforms to QueryFunctionWithSchema type\n const queryFn = (input: I) => {\n // This function will be called by the repository later with the real queryEntity\n return (entity: QueryEntity<T>) => {\n return handler({ input, entity });\n };\n };\n\n // Attach the schema to the function for validation purposes\n queryFn.schema = schema;\n\n // Return the query function (this satisfies the QueryFunctionWithSchema type)\n return queryFn as unknown as QueryFunctionWithSchema<T, I, R>;\n },\n }),\n };\n}\n\nexport interface IndexDefinition<T extends DynamoItem> extends Index {\n name: string;\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n generateKey: (item: T) => ({\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}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/conditions.ts","../src/entity.ts"],"names":["primaryKey","key"],"mappings":";AA+FO,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;;;ACyBzC,SAAS,aACd,MACA,EAAA;AACA,EAAM,MAAA,uBAAA,GAA0B,MAAO,CAAA,QAAA,EAAU,uBAA2B,IAAA,YAAA;AAmB5E,EAAM,MAAA,kBAAA,GAAqB,CAAC,cAAuF,KAAA;AACjH,IAAA,IAAI,CAAC,MAAA,CAAO,QAAU,EAAA,UAAA,SAAmB,EAAC;AAE1C,IAAA,MAAM,aAA8C,EAAC;AACr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,OAAS,EAAA,IAAA;AAAA,UACT,WAAA,EAAa,CAAC,IAAA,MAAa,EAAE,EAAA,EAAI,IAAK,CAAA,IAAI,CAAG,EAAA,EAAA,EAAI,IAAK,CAAA,IAAI,CAAE,EAAA;AAAA,SAC9D,CAAA;AAAA,QAEF,gBAAgB,OACb;AAAA,UACC,IAAM,EAAA,QAAA;AAAA,UACN,YAAc,EAAA,IAAA;AAAA,UACd,aAAa,CAAC,IAAA,MAAa,EAAE,EAAI,EAAA,IAAA,CAAK,IAAI,CAAE,EAAA;AAAA,SAC9C;AAAA,OACJ;AAAA,KACF;AAAA,GACF;AACF","file":"entity.js","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - 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: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n 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 { DeleteBuilder } from \"./builders/delete-builder\";\nimport type { GetBuilder } from \"./builders/get-builder\";\nimport type { PutBuilder } from \"./builders/put-builder\";\nimport type { ScanBuilder } from \"./builders/scan-builder\";\nimport type { UpdateBuilder } from \"./builders/update-builder\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type { Table } from \"./table\";\nimport type { DynamoItem, Index, TableConfig } from \"./types\";\nimport { eq, type PrimaryKey, type PrimaryKeyWithoutExpression } from \"./conditions\";\nimport type { QueryBuilder } from \"./builders/query-builder\";\nimport type { TransactionBuilder } from \"./builders/transaction-builder\";\n\n// Define the QueryFunction type with a generic return type\nexport type QueryFunction<T extends DynamoItem, I, R> = (input: I) => R;\n\n// Define a type for the query record that preserves the input type for each query function\nexport type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {\n schema?: StandardSchemaV1<I>;\n};\n\nexport type QueryRecord<T extends DynamoItem> = {\n // biome-ignore lint/suspicious/noExplicitAny: This is for flexibility\n [K: string]: QueryFunctionWithSchema<T, any, ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>;\n};\n\n// Define a type for entity with only scan, get and query methods\nexport type QueryEntity<T extends DynamoItem> = {\n scan: () => ScanBuilder<T>;\n get: (key: PrimaryKeyWithoutExpression) => GetBuilder<T>;\n query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;\n};\n\ninterface Settings {\n /**\n * Defaults to \"entityType\"\n */\n entityTypeAttributeName?: string;\n timestamps?: {\n createdAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"createdAt\"\n */\n attributeName?: string;\n };\n updatedAt?: {\n /**\n * ISO vs Unix trade-offs\n *\n * Both options support between, greater than and less than comparisons.\n *\n * ISO:\n * - Human readable, but requires more storage space\n * - Does not work with DynamoDBs TTL feature.\n *\n * UNIX:\n * - Less readable, but requires less storage space.\n * - Works with DynamoDBs TTL feature.\n */\n format: \"ISO\" | \"UNIX\";\n /**\n * Defaults to \"updatedAt\"\n */\n attributeName?: string;\n };\n };\n}\n\nexport interface EntityConfig<\n T extends DynamoItem,\n I extends DynamoItem = T,\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n name: string;\n schema: StandardSchemaV1<T>;\n primaryKey: IndexDefinition<I>;\n indexes?: Record<string, Index>;\n queries: Q;\n settings?: Settings;\n}\n\nexport interface EntityRepository<\n /**\n * The Entity Type\n */\n T extends DynamoItem,\n /**\n * The Primary Index (Partition index) Type\n */\n I extends DynamoItem = T,\n /**\n * The Queries object\n */\n Q extends QueryRecord<T> = QueryRecord<T>,\n> {\n create: (data: T) => PutBuilder<T>;\n upsert: (data: T & I) => PutBuilder<T>;\n get: (key: I) => GetBuilder<T>;\n update: (key: I, data: Partial<T>) => UpdateBuilder<T>;\n delete: (key: I) => DeleteBuilder;\n query: Q;\n scan: () => ScanBuilder<T>;\n}\n\n/**\n * Creates an entity definition with type-safe operations\n *\n * @example\n * ```typescript\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * const UserEntity = defineEntity<User>({\n * name: \"User\",\n * schema: userSchema,\n * primaryKey: primaryKey,\n * });\n * ```\n */\nexport function defineEntity<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(\n config: EntityConfig<T, I, Q>,\n) {\n const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? \"entityType\";\n\n /**\n * Generates an object containing timestamp attributes based on the given configuration settings.\n * The function determines the presence and format of \"createdAt\" and \"updatedAt\" timestamps dynamically.\n *\n * @param {Array<\"createdAt\" | \"updatedAt\">} [timestampTypes] - Optional array of timestamp types to generate. If not provided, all configured timestamps will be generated.\n * @returns {Record<string, string | number>} An object containing one or both of the \"createdAt\" and \"updatedAt\" timestamp attributes, depending on the configuration and requested types. Each timestamp can be formatted as either an ISO string or a UNIX timestamp.\n *\n * @throws Will not throw errors but depends on `config.settings?.timestamps` to be properly defined.\n * - If `createdAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.createdAt.attributeName` or defaults to \"createdAt\".\n * - If `updatedAt` is configured, the function adds a timestamp using the attribute name specified in `config.settings.timestamps.updatedAt.attributeName` or defaults to \"updatedAt\".\n *\n * Configuration Details:\n * - `config.settings.timestamps.createdAt.format`: Determines the format of the \"createdAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n * - `config.settings.timestamps.updatedAt.format`: Determines the format of the \"updatedAt\" timestamp. Accepts \"UNIX\" or defaults to ISO string.\n *\n * The returned object keys and values depend on the provided configuration and requested timestamp types.\n */\n const generateTimestamps = (timestampTypes?: Array<\"createdAt\" | \"updatedAt\">): Record<string, string | number> => {\n if (!config.settings?.timestamps) return {};\n\n const timestamps: Record<string, string | number> = {};\n const now = new Date();\n const unixTime = Math.floor(Date.now() / 1000);\n\n const { createdAt, updatedAt } = config.settings.timestamps;\n\n // If no specific types are provided, generate all configured timestamps\n const typesToGenerate = timestampTypes || [\"createdAt\", \"updatedAt\"];\n\n if (createdAt && typesToGenerate.includes(\"createdAt\")) {\n const name = createdAt.attributeName ?? \"createdAt\";\n timestamps[name] = createdAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n if (updatedAt && typesToGenerate.includes(\"updatedAt\")) {\n const name = updatedAt.attributeName ?? \"updatedAt\";\n timestamps[name] = updatedAt.format === \"UNIX\" ? unixTime : now.toISOString();\n }\n\n return timestamps;\n };\n\n return {\n name: config.name,\n createRepository: (table: Table): EntityRepository<T, I, Q> => {\n // Create a repository\n const repository = {\n create: (data: T) => {\n // Generate the primary key upfront for transaction compatibility\n // Note: We assume data is valid for key generation, validation happens during execution\n const primaryKey = config.primaryKey.generateKey(data as unknown as I);\n\n const indexes = Object.entries(config.indexes ?? {}).reduce(\n (acc, [indexName, index]) => {\n const key = (index as IndexDefinition<T>).generateKey(data);\n const gsiConfig = table.gsis[indexName];\n\n if (!gsiConfig) {\n throw new Error(`GSI configuration not found for index: ${indexName}`);\n }\n\n if (key.pk) {\n acc[gsiConfig.partitionKey] = key.pk;\n }\n if (key.sk && gsiConfig.sortKey) {\n acc[gsiConfig.sortKey] = key.sk;\n }\n return acc;\n },\n {} as Record<string, string>,\n );\n\n // Create the builder with all keys included upfront\n const builder = table.create<T>({\n ...data,\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n });\n\n // Core function that handles validation and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\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 const validatedItem = {\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen in withTransaction, but we need to handle it for type safety\n if (validationResult instanceof Promise) {\n throw new Error(\"Async validation is not supported in withTransaction. Use execute() instead.\");\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const validatedItem = {\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...indexes,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n return await originalExecute.call(builder);\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const wrappedWithTransaction = (transaction: any) => {\n prepareValidatedItemSync();\n return originalWithTransaction.call(builder, transaction);\n };\n\n // Copy all properties from the original function to preserve mock functionality\n Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);\n const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);\n for (let i = 0; i < propertyNames.length; i++) {\n const prop = propertyNames[i] as string;\n if (prop !== \"length\" && prop !== \"name\" && prop !== \"prototype\") {\n try {\n // biome-ignore lint/suspicious/noExplicitAny: Make it work\n (wrappedWithTransaction as any)[prop] = (originalWithTransaction as any)[prop];\n } catch (e) {\n // Ignore errors for non-configurable properties\n }\n }\n }\n\n builder.withTransaction = wrappedWithTransaction;\n }\n\n return builder;\n },\n\n upsert: (data: T & I) => {\n const primaryKey = config.primaryKey.generateKey(data);\n\n // We need to handle the async operations when the consumer calls execute\n const builder = table.put<T>({\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...data,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n });\n\n // Core function that handles validation and item preparation (async version)\n const prepareValidatedItemAsync = async () => {\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 const primaryKey = config.primaryKey.generateKey(validationResult.value as T & I);\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Core function that handles validation and item preparation (sync version)\n const prepareValidatedItemSync = () => {\n const validationResult = config.schema[\"~standard\"].validate(data);\n\n // Handle Promise case - this shouldn't happen in withTransaction but we need to handle it for type safety\n if (validationResult instanceof Promise) {\n throw new Error(\"Async validation is not supported in withTransaction. Use execute() instead.\");\n }\n\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(\", \")}`);\n }\n\n const primaryKey = config.primaryKey.generateKey(validationResult.value as T & I);\n const validatedItem = {\n [table.partitionKey]: primaryKey.pk,\n ...(table.sortKey ? { [table.sortKey]: primaryKey.sk } : {}),\n ...validationResult.value,\n [entityTypeAttributeName]: config.name,\n ...generateTimestamps([\"createdAt\", \"updatedAt\"]),\n };\n\n Object.assign(builder, { item: validatedItem });\n return validatedItem;\n };\n\n // Wrap the builder's execute method\n const originalExecute = builder.execute;\n builder.execute = async () => {\n await prepareValidatedItemAsync();\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to upsert item\");\n }\n return result;\n };\n\n // Wrap the builder's withTransaction method\n const originalWithTransaction = builder.withTransaction;\n if (originalWithTransaction) {\n const wrappedWithTransaction = (transaction: TransactionBuilder) => {\n prepareValidatedItemSync();\n return originalWithTransaction.call(builder, transaction);\n };\n\n // Copy all properties from the original function to preserve mock functionality\n Object.setPrototypeOf(wrappedWithTransaction, originalWithTransaction);\n const propertyNames = Object.getOwnPropertyNames(originalWithTransaction);\n for (let i = 0; i < propertyNames.length; i++) {\n const prop = propertyNames[i] as string;\n if (prop !== \"length\" && prop !== \"name\" && prop !== \"prototype\") {\n try {\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n (wrappedWithTransaction as any)[prop] = (originalWithTransaction as any)[prop];\n } catch (e) {\n // Ignore errors for non-configurable properties\n }\n }\n }\n\n builder.withTransaction = wrappedWithTransaction;\n }\n\n return builder;\n },\n\n get: <K extends I>(key: K) => table.get<T>(config.primaryKey.generateKey(key)),\n\n update: <K extends I>(key: K, data: Partial<T>) => {\n const primaryKeyObj = config.primaryKey.generateKey(key);\n const builder = table.update<T>(primaryKeyObj);\n builder.condition(eq(entityTypeAttributeName, config.name));\n\n // Use only updatedAt timestamp for updates\n const timestamps = generateTimestamps([\"updatedAt\"]);\n\n builder.set({ ...data, ...timestamps });\n return builder;\n },\n\n delete: <K extends I>(key: K) => {\n const builder = table.delete(config.primaryKey.generateKey(key));\n builder.condition(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n\n query: Object.entries(config.queries || {}).reduce((acc, [key, inputCallback]) => {\n // @ts-expect-error - We need to cast the queryFn to a function that takes an unknown input\n acc[key] = (input: unknown) => {\n // Create a QueryEntity object with only the necessary methods\n const queryEntity: QueryEntity<T> = {\n scan: repository.scan,\n get: (key: PrimaryKeyWithoutExpression) => table.get<T>(key),\n query: (keyCondition: PrimaryKey) => {\n return table.query<T>(keyCondition);\n },\n };\n\n // Execute the query function to get the builder - This type is incorrect and needs to be fixed\n const queryBuilderCallback = inputCallback(input);\n\n // Run the inner handler which allows the user to apply their desired contraints\n // to the query builder of their choice\n // @ts-expect-error - We need to cast the queryBuilderCallback to a function that takes a QueryEntity\n const builder = queryBuilderCallback(queryEntity);\n\n // Add entity type filter if the builder has filter method\n if (builder && typeof builder === \"object\" && \"filter\" in builder && typeof builder.filter === \"function\") {\n builder.filter(eq(entityTypeAttributeName, config.name));\n }\n\n // Wrap the builder's execute method if it exists\n if (builder && typeof builder === \"object\" && \"execute\" in builder) {\n const originalExecute = builder.execute;\n builder.execute = async () => {\n // Validate the input before executing the query\n const queryFn = (\n config.queries as unknown as Record<string, QueryFunctionWithSchema<T, I, typeof builder>>\n )[key];\n\n if (queryFn && typeof queryFn === \"function\") {\n // Get the schema from the query function\n const schema = queryFn.schema;\n if (schema?.[\"~standard\"]?.validate && typeof schema[\"~standard\"].validate === \"function\") {\n const validationResult = schema[\"~standard\"].validate(input);\n if (\"issues\" in validationResult && validationResult.issues) {\n throw new Error(\n `Validation failed: ${validationResult.issues.map((issue) => issue.message).join(\", \")}`,\n );\n }\n }\n }\n\n // Execute the original builder\n const result = await originalExecute.call(builder);\n if (!result) {\n throw new Error(\"Failed to execute query\");\n }\n return result;\n };\n }\n\n return builder;\n };\n return acc;\n }, {} as Q),\n\n scan: () => {\n const builder = table.scan<T>();\n builder.filter(eq(entityTypeAttributeName, config.name));\n return builder;\n },\n };\n\n return repository;\n },\n };\n}\n\nexport function createQueries<T extends DynamoItem>() {\n return {\n input: <I>(schema: StandardSchemaV1<I>) => ({\n query: <\n Q extends QueryRecord<T> = QueryRecord<T>,\n R = ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>,\n >(\n handler: (params: { input: I; entity: QueryEntity<T> }) => R,\n ) => {\n const queryFn = (input: I) => (entity: QueryEntity<T>) => handler({ input, entity });\n queryFn.schema = schema;\n return queryFn as unknown as QueryFunctionWithSchema<T, I, R>;\n },\n }),\n };\n}\n\nexport interface IndexDefinition<T extends DynamoItem> extends Index {\n name: string;\n generateKey: (item: T) => { pk: string; sk?: string };\n}\n\nexport function createIndex() {\n return {\n input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => ({\n partitionKey: <P extends (item: T) => string>(pkFn: P) => ({\n sortKey: <S extends (item: T) => string>(skFn: S) =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n sortKey: \"sk\",\n generateKey: (item: T) => ({ pk: pkFn(item), sk: skFn(item) }),\n }) as IndexDefinition<T>,\n\n withoutSortKey: () =>\n ({\n name: \"custom\",\n partitionKey: \"pk\",\n generateKey: (item: T) => ({ pk: pkFn(item) }),\n }) as IndexDefinition<T>,\n }),\n }),\n };\n}\n"]}
|
|
@@ -330,7 +330,7 @@ declare class Table<TConfig extends TableConfig = TableConfig> {
|
|
|
330
330
|
* @param options Optional transaction options
|
|
331
331
|
* @returns A promise that resolves when the transaction is complete
|
|
332
332
|
*/
|
|
333
|
-
transaction<T>(callback: (tx: TransactionBuilder) => Promise<T
|
|
333
|
+
transaction<T>(callback: (tx: TransactionBuilder) => Promise<T> | T, options?: TransactionOptions): Promise<T>;
|
|
334
334
|
/**
|
|
335
335
|
* Creates a condition check operation for use in transactions
|
|
336
336
|
*
|
|
@@ -330,7 +330,7 @@ declare class Table<TConfig extends TableConfig = TableConfig> {
|
|
|
330
330
|
* @param options Optional transaction options
|
|
331
331
|
* @returns A promise that resolves when the transaction is complete
|
|
332
332
|
*/
|
|
333
|
-
transaction<T>(callback: (tx: TransactionBuilder) => Promise<T
|
|
333
|
+
transaction<T>(callback: (tx: TransactionBuilder) => Promise<T> | T, options?: TransactionOptions): Promise<T>;
|
|
334
334
|
/**
|
|
335
335
|
* Creates a condition check operation for use in transactions
|
|
336
336
|
*
|
package/dist/table.cjs
CHANGED
|
@@ -1980,13 +1980,21 @@ var TransactionBuilder = class {
|
|
|
1980
1980
|
* @see DeleteBuilder for creating delete commands
|
|
1981
1981
|
*/
|
|
1982
1982
|
deleteWithCommand(command) {
|
|
1983
|
-
|
|
1984
|
-
|
|
1983
|
+
let keyForDuplicateCheck;
|
|
1984
|
+
let keyForTransaction;
|
|
1985
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
1986
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
1987
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
1988
|
+
} else {
|
|
1989
|
+
keyForTransaction = command.key;
|
|
1990
|
+
keyForDuplicateCheck = command.key;
|
|
1991
|
+
}
|
|
1992
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
1985
1993
|
const transactionItem = {
|
|
1986
1994
|
type: "Delete",
|
|
1987
1995
|
params: {
|
|
1988
1996
|
...command,
|
|
1989
|
-
key:
|
|
1997
|
+
key: keyForTransaction
|
|
1990
1998
|
}
|
|
1991
1999
|
};
|
|
1992
2000
|
this.items.push(transactionItem);
|
|
@@ -2107,13 +2115,21 @@ var TransactionBuilder = class {
|
|
|
2107
2115
|
* @see UpdateBuilder for creating update commands
|
|
2108
2116
|
*/
|
|
2109
2117
|
updateWithCommand(command) {
|
|
2110
|
-
|
|
2111
|
-
|
|
2118
|
+
let keyForDuplicateCheck;
|
|
2119
|
+
let keyForTransaction;
|
|
2120
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2121
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2122
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2123
|
+
} else {
|
|
2124
|
+
keyForTransaction = command.key;
|
|
2125
|
+
keyForDuplicateCheck = command.key;
|
|
2126
|
+
}
|
|
2127
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2112
2128
|
const transactionItem = {
|
|
2113
2129
|
type: "Update",
|
|
2114
2130
|
params: {
|
|
2115
2131
|
...command,
|
|
2116
|
-
key:
|
|
2132
|
+
key: keyForTransaction
|
|
2117
2133
|
}
|
|
2118
2134
|
};
|
|
2119
2135
|
this.items.push(transactionItem);
|
|
@@ -2221,13 +2237,21 @@ var TransactionBuilder = class {
|
|
|
2221
2237
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2222
2238
|
*/
|
|
2223
2239
|
conditionCheckWithCommand(command) {
|
|
2224
|
-
|
|
2225
|
-
|
|
2240
|
+
let keyForDuplicateCheck;
|
|
2241
|
+
let keyForTransaction;
|
|
2242
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2243
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2244
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2245
|
+
} else {
|
|
2246
|
+
keyForTransaction = command.key;
|
|
2247
|
+
keyForDuplicateCheck = command.key;
|
|
2248
|
+
}
|
|
2249
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2226
2250
|
const transactionItem = {
|
|
2227
2251
|
type: "ConditionCheck",
|
|
2228
2252
|
params: {
|
|
2229
2253
|
...command,
|
|
2230
|
-
key:
|
|
2254
|
+
key: keyForTransaction
|
|
2231
2255
|
}
|
|
2232
2256
|
};
|
|
2233
2257
|
this.items.push(transactionItem);
|
|
@@ -2688,10 +2712,7 @@ var GetBuilder = class {
|
|
|
2688
2712
|
*/
|
|
2689
2713
|
async execute() {
|
|
2690
2714
|
const expressionParams = {
|
|
2691
|
-
expressionAttributeNames: {}
|
|
2692
|
-
expressionAttributeValues: {},
|
|
2693
|
-
valueCounter: { count: 0 }
|
|
2694
|
-
};
|
|
2715
|
+
expressionAttributeNames: {}};
|
|
2695
2716
|
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2696
2717
|
const { expressionAttributeNames } = expressionParams;
|
|
2697
2718
|
return this.executor({
|