dinah 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["T","DynamoDBClient","DynamoDB","Lib","ListTablesCommand","ConditionalCheckFailedException","DeleteTableCommand","CreateTableCommand","UpdateTimeToLiveCommand"],"sources":["../src/expression-builder.ts","../src/repo.ts","../src/util.ts","../src/db.ts","../src/table.ts"],"sourcesContent":["import type { Obj } from \"./types\";\n\nconst attrTypes = [\"S\", \"SS\", \"N\", \"NS\", \"B\", \"BS\", \"BOOL\", \"NULL\", \"L\", \"M\"] as const;\nconst comparatorOps: Obj<string> = {\n $eq: \"=\",\n $ne: \"<>\",\n $gt: \">\",\n $gte: \">=\",\n $lt: \"<\",\n $lte: \"<=\",\n};\n\n// TODO should { $eq: undefined } and { $ne: undefined } be converted into attribute_not_exists and attribute_exists ?\n\nexport const isOperation = (val: unknown): val is Obj => {\n if (!val || typeof val !== \"object\" || Array.isArray(val)) return false;\n return Object.keys(val).every((op) => op.startsWith(\"$\"));\n};\n\nexport class ExpressionBuilder {\n protected readonly attrNames = new Map<string, string>();\n protected readonly attrValues = new Map<unknown, string>();\n\n get attributeNames(): Obj<string> | undefined {\n return this.attrNames.size\n ? Object.fromEntries(\n [...this.attrNames.entries()].map(([name, placeholder]) => [placeholder, name]),\n )\n : undefined;\n }\n\n get attributeValues(): Obj | undefined {\n return this.attrValues.size\n ? Object.fromEntries(\n [...this.attrValues.entries()].map(([value, placeholder]) => [placeholder, value]),\n )\n : undefined;\n }\n\n reset(): void {\n this.attrNames.clear();\n this.attrValues.clear();\n }\n\n getPathSub(path: string): string {\n const segments = path.split(\".\");\n const placeholders: string[] = [];\n\n for (const segment of segments) {\n let placeholder = this.attrNames.get(segment);\n if (!placeholder) {\n placeholder = `#${this.attrNames.size}`;\n this.attrNames.set(segment, placeholder);\n }\n\n placeholders.push(placeholder);\n }\n\n return placeholders.join(\".\");\n }\n\n getValueSub(value: unknown): string {\n let placeholder = this.attrValues.get(value);\n if (!placeholder) {\n placeholder = `:${this.attrValues.size}`;\n this.attrValues.set(value, placeholder);\n }\n\n return placeholder;\n }\n\n getValueOrPathSub(pathOrValue: unknown): string {\n if (isOperation(pathOrValue)) {\n if (pathOrValue.$path) return this.getPathSub(pathOrValue.$path);\n throw new Error(\"Expected $path or operand.\");\n }\n\n return this.getValueSub(pathOrValue);\n }\n\n projection<T extends string[] | undefined>(paths: T): T extends undefined ? undefined : string {\n return paths?.map((path) => this.getPathSub(path)).join(\", \") as never;\n }\n\n condition<T extends Obj | undefined>(expression: T): T extends undefined ? undefined : string {\n if (!expression) return undefined as never;\n\n const expressions: string[] = [];\n for (const [key, val] of Object.entries(expression)) {\n if (key === \"$and\") {\n if (!Array.isArray(val)) throw new Error(\"$and expects an array operand.\");\n expressions.push(`(${val.map((v) => this.condition(v)).join(\" AND \")})`);\n } else if (key === \"$or\" && Array.isArray(val)) {\n if (!Array.isArray(val)) throw new Error(\"$or expects an array operand.\");\n expressions.push(`(${val.map((v) => this.condition(v)).join(\" OR \")})`);\n } else if (key === \"$not\") {\n if (!val || typeof val !== \"object\") throw new Error(\"$not expects an object operand.\");\n expressions.push(`NOT ${this.condition(val)}`);\n } else if (!key.startsWith(\"$\")) {\n expressions.push(this.resolveCondition(key, val));\n } else {\n throw new Error(\n `Unexpected operator \"${key}\". Expected attribute path or compound operator.`,\n );\n }\n }\n\n return expressions.join(\" AND \") as never;\n }\n\n update<T extends Obj | undefined>(expression: T): T extends undefined ? undefined : string {\n if (expression === undefined) return undefined as never;\n\n const setOperations: string[] = [];\n const removeOperations: string[] = [];\n const setAddOperations: string[] = [];\n const setDelOperations: string[] = [];\n\n for (const [path, valOrOperation] of Object.entries(expression)) {\n const placeholder = this.getPathSub(path);\n\n if (valOrOperation === undefined) {\n removeOperations.push(placeholder);\n } else if (isOperation(valOrOperation)) {\n if (valOrOperation.$remove === true) {\n removeOperations.push(placeholder);\n } else if (valOrOperation.$setAdd !== undefined || valOrOperation.$setDel !== undefined) {\n const operations = valOrOperation.$setAdd ? setAddOperations : setDelOperations;\n const operand = valOrOperation.$setAdd ?? valOrOperation.$setDel;\n operations.push(\n `${placeholder} ${this.getValueSub(operand instanceof Set ? operand : new Set([operand].flat()))}`,\n );\n } else {\n setOperations.push(`${placeholder} = ${this.resolveSetOperand(path, valOrOperation)}`);\n }\n } else {\n setOperations.push(`${placeholder} = ${this.getValueSub(valOrOperation)}`);\n }\n }\n\n let updateExpression = \"\";\n if (setOperations.length) {\n updateExpression += `SET ${setOperations.join(\", \")} `;\n }\n\n if (removeOperations.length) {\n updateExpression += `REMOVE ${removeOperations.join(\", \")} `;\n }\n\n if (setAddOperations.length) {\n updateExpression += `ADD ${setAddOperations.join(\", \")} `;\n }\n\n if (setDelOperations.length) {\n updateExpression += `DELETE ${setDelOperations.join(\", \")} `;\n }\n\n return updateExpression as never;\n }\n\n protected resolveCondition(path: string, exp: unknown): string {\n if (!exp || typeof exp !== \"object\" || !Object.keys(exp).at(0)?.startsWith(\"$\")) {\n return this.resolveCondition(path, { $eq: exp });\n }\n\n const placeholder = this.getPathSub(path);\n const [operator, operand] = Object.entries(exp).at(0) ?? [\"\"];\n\n if (comparatorOps[operator]) {\n if (isOperation(operand) && operand.$path) {\n return `${placeholder} ${comparatorOps[operator]} ${this.getPathSub(operand.$path)}`;\n }\n\n if (![\"string\", \"boolean\", \"number\"].includes(typeof operand)) {\n throw new Error(`${operator} expects a primitive/scalar operand.`);\n }\n return `${placeholder} ${comparatorOps[operator]} ${this.getValueSub(operand)}`;\n }\n\n switch (operator) {\n case \"$in\":\n if (!Array.isArray(operand)) {\n throw new Error(\"$in operator expects an array operand.\");\n }\n return `${placeholder} IN (${operand.map((op) => this.getValueSub(op)).join(\", \")})`;\n\n case \"$nin\":\n if (!Array.isArray(operand)) {\n throw new Error(\"$nin operator expects an array operand.\");\n }\n return `${placeholder} NOT IN (${operand.map((op) => this.getValueSub(op)).join(\", \")})`;\n\n case \"$prefix\":\n if (typeof operand !== \"string\") {\n throw new Error(\"$prefix operator expects a string operand.\");\n }\n return `begins_with(${placeholder}, ${this.getValueSub(operand)})`;\n\n case \"$includes\":\n return `contains(${placeholder}, ${this.getValueSub(operand)})`;\n\n case \"$between\":\n if (!Array.isArray(operand) || operand.length !== 2) {\n throw new Error(\"$between operator expects an array operand of exactly two values.\");\n }\n return `${placeholder} BETWEEN ${this.getValueSub(operand[0])} AND ${this.getValueSub(operand[1])}`;\n\n case \"$exists\":\n if (typeof operand !== \"boolean\") {\n throw new Error(\"$exists operator expects a boolean operand.\");\n }\n return operand\n ? `attribute_exists(${placeholder})`\n : `attribute_not_exists(${placeholder})`;\n\n case \"$type\":\n if (!attrTypes.includes(operand as any)) {\n throw new Error(`$type operator expects operand to be one of ${attrTypes.join(\",\")}`);\n }\n return `attribute_type(${placeholder})`;\n\n case \"$size\": {\n const sizeExp = typeof operand === \"number\" ? { $eq: operand } : operand;\n if (\n !sizeExp ||\n typeof sizeExp !== \"object\" ||\n !Object.keys(sizeExp).at(0)?.startsWith(\"$\")\n ) {\n throw new Error(\"$size operator expects a number operand or a comparator object.\");\n }\n const [sizeOperator, sizeOperand] = Object.entries(sizeExp).at(0) ?? [\"\"];\n\n if (!comparatorOps[sizeOperator]) {\n throw new Error(\"$size operator expects a number operand or a comparator object.\");\n }\n\n if (![\"string\", \"boolean\", \"number\"].includes(typeof sizeOperand)) {\n throw new Error(`${operator} expects a primitive/scalar operand.`);\n }\n\n return `size(${placeholder}) ${comparatorOps[sizeOperator]} ${this.getValueSub(sizeOperand)}`;\n }\n\n default:\n throw new Error(`Invalid operator \"${operator}\"`);\n }\n }\n\n protected resolveSetOperand(path: string, operand: unknown): string {\n if (isOperation(operand)) {\n if (operand.$ifNotExists) {\n const params = Array.isArray(operand.$ifNotExists)\n ? operand.$ifNotExists\n : [path, operand.$ifNotExists];\n return `if_not_exists(${this.getPathSub(params[0])}, ${this.resolveSetOperand(path, params[1])})`;\n }\n\n if (operand.$set) {\n return this.resolveSetOperand(path, operand.$set);\n }\n\n if (operand.$plus !== undefined || operand.$minus !== undefined) {\n const mathOperator = operand.$plus ? \"+\" : \"-\";\n const mathOperand = operand.$plus ?? operand.$minus;\n const params = Array.isArray(mathOperand) ? mathOperand : [{ $path: path }, mathOperand];\n return `${params.map((param) => this.resolveSetOperand(path, param)).join(` ${mathOperator} `)}`;\n }\n\n if (operand.$append !== undefined || operand.$prepend !== undefined) {\n const listOperand = operand.$append ?? operand.$prepend;\n const resolvedListOperand = isOperation(listOperand) ? listOperand : [listOperand].flat();\n const params = operand.$append\n ? [{ $path: path }, resolvedListOperand]\n : [resolvedListOperand, { $path: path }];\n return `list_append(${params.map((param) => this.resolveSetOperand(path, param)).join(\", \")})`;\n }\n }\n\n return this.getValueOrPathSub(operand);\n }\n}\n","import type { TSchema } from \"typebox\";\nimport type { Db } from \"./db\";\nimport type { Table } from \"./table\";\nimport type {\n DbTrxGetRequest,\n DbTrxWriteRequest,\n ExtractTableDef,\n GsiNames,\n Obj,\n RepoBatchGet,\n RepoBatchGetOrThrowResult,\n RepoBatchGetResult,\n RepoBatchWrite,\n RepoBatchWriteResult,\n RepoCreate,\n RepoCreateItem,\n RepoCreateResult,\n RepoDelete,\n RepoDeleteOrThrowResult,\n RepoDeleteResult,\n RepoExists,\n RepoGet,\n RepoGetOrThrowResult,\n RepoGetResult,\n RepoKey,\n RepoPut,\n RepoPutItem,\n RepoPutResult,\n RepoQuery,\n RepoQueryGsi,\n RepoQueryGsiPagedResult,\n RepoQueryGsiResult,\n RepoQueryPagedResult,\n RepoQueryResult,\n RepoScan,\n RepoScanGsi,\n RepoScanGsiPagedResult,\n RepoScanGsiResult,\n RepoScanPagedResult,\n RepoScanResult,\n RepoTrxGet,\n RepoTrxGetOrThrowResult,\n RepoTrxGetResult,\n RepoTrxWriteRequest,\n RepoUpdate,\n RepoUpdateData,\n RepoUpdateResult,\n RepoUpsert,\n RepoUpsertResult,\n} from \"./types\";\n\n// TODO: query/queryGsi needs strongly typed \"key\" argument\n// allows =,>,>=,<,<=,begins_with, between on sort key\n// util -> extractExclusiveStartKey(item)\n\nexport class Repository<T extends Table<any, any>> {\n readonly table: Table<TSchema, any>;\n readonly db: Db;\n constructor(table: T, db: Db) {\n this.table = table;\n this.db = db;\n }\n\n get tableName(): string {\n return `${this.db.config?.tableNamePrefix ?? \"\"}${this.table.def.name}`;\n }\n\n get def(): ExtractTableDef<T> {\n return this.table.def as never;\n }\n\n extractKey(item: RepoKey<T>): RepoKey<T> {\n const { partitionKey, sortKey } = this.table.def;\n if (sortKey) {\n return {\n [partitionKey]: item[partitionKey],\n [sortKey]: item[sortKey],\n } as RepoKey<T>;\n }\n\n return { [partitionKey]: item[partitionKey] } as RepoKey<T>;\n }\n\n async get<O extends RepoGet<T>>(key: RepoKey<T>, options?: O): Promise<RepoGetResult<T, O>> {\n return this.db.get({ table: this.tableName, key: this.extractKey(key), ...options });\n }\n\n async getOrThrow<O extends RepoGet<T>>(\n key: RepoKey<T>,\n options?: O,\n ): Promise<RepoGetOrThrowResult<T, O>> {\n return this.db.getOrThrow({ table: this.tableName, key: this.extractKey(key), ...options });\n }\n\n async put<O extends RepoPut<T>>(item: RepoPutItem<T>, options?: O): Promise<RepoPutResult<T, O>> {\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(item), ...item }\n : item;\n return this.db.put({ table: this.tableName, item: itemWithDefaults, ...options });\n }\n\n async update<O extends RepoUpdate<T>>(\n key: RepoKey<T>,\n update: RepoUpdateData<T>,\n options?: O,\n ): Promise<RepoUpdateResult<T, O>> {\n const updateWithDefaults = this.table.def.beforeUpdate\n ? { ...this.table.def.beforeUpdate(update), ...update }\n : update;\n return this.db.update({\n table: this.tableName,\n key: this.extractKey(key),\n update: updateWithDefaults,\n ...options,\n }) as RepoUpdateResult<T, O>;\n }\n\n async create<O extends RepoCreate<T>>(\n item: RepoCreateItem<T>,\n options?: O,\n ): Promise<RepoCreateResult<T, O>> {\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(item), ...item }\n : item;\n return this.db.create({\n table: this.tableName,\n item: itemWithDefaults,\n partitionKeyName: this.table.def.partitionKey,\n ...options,\n });\n }\n\n async upsert(data: RepoUpsert<T>): Promise<RepoUpsertResult<T>> {\n const { update, item, key, ...options } = data;\n const updateWithDefaults = this.table.def.beforeUpdate\n ? { ...this.table.def.beforeUpdate(update), ...update }\n : update;\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(item), ...item }\n : item;\n return this.db.upsert({\n table: this.tableName,\n key: this.extractKey(key),\n update: updateWithDefaults,\n item: itemWithDefaults,\n ...options,\n });\n }\n\n async delete(key: RepoKey<T>, options?: RepoDelete<T>): Promise<RepoDeleteResult<T>> {\n return this.db.delete({ table: this.tableName, key: this.extractKey(key), ...options });\n }\n\n async deleteOrThrow(\n key: RepoKey<T>,\n options?: Omit<RepoDelete<T>, \"return\">,\n ): Promise<RepoDeleteOrThrowResult<T>> {\n return this.db.deleteOrThrow({ table: this.tableName, key: this.extractKey(key), ...options });\n }\n\n async query<O extends RepoQuery<T>>(query: Obj, options?: O): Promise<RepoQueryResult<T, O>> {\n return this.db.query({ table: this.tableName, query, ...options });\n }\n\n async *queryPaged<O extends RepoQuery<T>>(query: Obj, options?: O): RepoQueryPagedResult<T, O> {\n yield* this.db.queryPaged({ table: this.tableName, query, ...options }) as RepoQueryPagedResult<\n T,\n O\n >;\n }\n\n async queryGsi<G extends GsiNames<T>, O extends RepoQueryGsi<T>>(\n gsi: G,\n query: Obj,\n options?: O,\n ): Promise<RepoQueryGsiResult<T, O>> {\n return this.db.query({ table: this.tableName, index: gsi, query, ...options });\n }\n\n async *queryGsiPaged<G extends GsiNames<T>, O extends RepoQueryGsi<T>>(\n gsi: G,\n query: Obj,\n options?: O,\n ): RepoQueryGsiPagedResult<T, O> {\n yield* this.db.queryPaged({\n table: this.tableName,\n index: gsi,\n query,\n ...options,\n }) as RepoQueryGsiPagedResult<T, O>;\n }\n\n async scan<O extends RepoScan<T>>(options?: O): Promise<RepoScanResult<T, O>> {\n return this.db.scan({ table: this.tableName, ...options });\n }\n\n async *scanPaged<O extends RepoScan<T>>(options?: O): RepoScanPagedResult<T, O> {\n yield* this.db.scanPaged({ table: this.tableName, ...options }) as RepoScanPagedResult<T, O>;\n }\n\n async scanGsi<G extends GsiNames<T>, O extends RepoScanGsi<T>>(\n gsi: G,\n options?: O,\n ): Promise<RepoScanGsiResult<T, O>> {\n return this.db.scan({ table: this.tableName, index: gsi, ...options });\n }\n\n async *scanGsiPaged<G extends GsiNames<T>, O extends RepoScanGsi<T>>(\n gsi: G,\n options?: O,\n ): RepoScanGsiPagedResult<T, O> {\n yield* this.db.scanPaged({\n table: this.tableName,\n index: gsi,\n ...options,\n }) as RepoScanGsiPagedResult<T, O>;\n }\n\n async exists(options?: RepoExists<T>): Promise<boolean> {\n return this.db.exists({\n table: this.tableName,\n projection: [this.table.def.partitionKey],\n ...options,\n });\n }\n\n async existsGsi(gsi: GsiNames<T>, options?: RepoExists<T>): Promise<boolean> {\n return this.db.exists({\n table: this.tableName,\n index: gsi,\n projection: [this.table.def.partitionKey],\n ...options,\n });\n }\n\n async batchGet<O extends RepoBatchGet<T>>(\n keys: RepoKey<T>[],\n options?: O,\n ): Promise<RepoBatchGetResult<T, O>> {\n const { items, unprocessed } = await this.db.batchGet({\n [this.tableName]: { keys: keys.map((key) => this.extractKey(key)), ...options },\n });\n return {\n items: items[this.tableName],\n unprocessed: unprocessed?.[this.tableName]?.keys,\n } as RepoBatchGetResult<T, O>;\n }\n\n async batchGetOrThrow<O extends RepoBatchGet<T>>(\n keys: RepoKey<T>[],\n options?: O,\n ): Promise<RepoBatchGetOrThrowResult<T, O>> {\n const result = await this.db.batchGetOrThrow({\n [this.tableName]: { keys: keys.map((key) => this.extractKey(key)), ...options },\n });\n return result[this.tableName] as RepoBatchGetOrThrowResult<T, O>;\n }\n\n async batchWrite(requests: RepoBatchWrite<T>): Promise<RepoBatchWriteResult<T>> {\n const { items, unprocessed } = await this.db.batchWrite({\n [this.tableName]: requests.map((request) => {\n if (request.type === \"DELETE\") {\n return { type: \"DELETE\", key: this.extractKey(request.key) };\n } else {\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(request.item), ...request.item }\n : request.item;\n return { type: \"PUT\", item: itemWithDefaults };\n }\n }),\n });\n\n return {\n items: items[this.tableName],\n unprocessed: unprocessed?.[this.tableName],\n } as RepoBatchWriteResult<T>;\n }\n\n // this can be simplified now\n // also add upsert\n\n async trxGet<O extends RepoTrxGet<T>>(\n keys: RepoKey<T>[],\n options?: O,\n ): Promise<RepoTrxGetResult<T, O>> {\n return this.db.trxGet(\n ...keys.map((key) => ({ table: this.tableName, key: this.extractKey(key), ...options })),\n ) as Promise<RepoTrxGetResult<T, O>>;\n }\n\n async trxGetOrThrow<O extends RepoTrxGet<T>>(\n keys: RepoKey<T>[],\n options?: O,\n ): Promise<RepoTrxGetOrThrowResult<T, O>> {\n return this.db.trxGetOrThrow(\n ...keys.map((key) => ({ table: this.tableName, key: this.extractKey(key), ...options })),\n ) as Promise<RepoTrxGetOrThrowResult<T, O>>;\n }\n\n async trxWrite(...requests: RepoTrxWriteRequest<T>[]): Promise<void> {\n await this.db.trxWrite(\n ...requests.map((request) => {\n switch (request.type) {\n case \"CONDITION\": {\n const { key, condition, ...options } = request;\n return this.trxConditionRequest(key, condition, options);\n }\n\n case \"DELETE\": {\n const { key, ...options } = request;\n return this.trxDeleteRequest(key, options);\n }\n\n case \"PUT\": {\n const { item, ...options } = request;\n return this.trxPutRequest(item, options);\n }\n\n case \"UPDATE\": {\n const { key, update, ...options } = request;\n return this.trxUpdateRequest(key, update, options);\n }\n\n default:\n throw new Error(\"Unexpected request type.\");\n }\n }),\n );\n }\n\n async trxDelete(keys: RepoKey<T>[], options?: Omit<RepoDelete<T>, \"return\">): Promise<void> {\n return this.db.trxWrite(...keys.map((key) => this.trxDeleteRequest(key, options)));\n }\n\n // todo: return items\n async trxPut(items: RepoPutItem<T>[], options?: Omit<RepoPut<T>, \"return\">): Promise<void> {\n return this.db.trxWrite(...items.map((item) => this.trxPutRequest(item, options)));\n }\n\n async trxUpdate(\n keys: RepoKey<T>[],\n update: RepoUpdateData<T>,\n options?: Omit<RepoUpdate<T>, \"return\">,\n ): Promise<void> {\n return this.db.trxWrite(...keys.map((key) => this.trxUpdateRequest(key, update, options)));\n }\n\n // todo: return items\n async trxCreate(items: RepoCreateItem<T>[], options?: RepoCreate<T>): Promise<void> {\n return this.db.trxWrite(...items.map((item) => this.trxCreateRequest(item, options)));\n }\n\n trxGetRequest<O extends RepoGet<T>>(\n key: RepoKey<T>,\n options?: O,\n ): DbTrxGetRequest<RepoGetOrThrowResult<T, O>> {\n return { table: this.tableName, key: this.extractKey(key), ...options };\n }\n\n trxDeleteRequest(key: RepoKey<T>, options?: Omit<RepoDelete<T>, \"return\">): DbTrxWriteRequest {\n return { table: this.tableName, type: \"DELETE\", key: this.extractKey(key), ...options };\n }\n\n trxConditionRequest(\n key: RepoKey<T>,\n condition: Obj,\n options?: Omit<RepoDelete<T>, \"return\" | \"condition\">,\n ): DbTrxWriteRequest {\n return {\n table: this.tableName,\n type: \"CONDITION\",\n key: this.extractKey(key),\n condition,\n ...options,\n };\n }\n\n trxPutRequest(item: RepoPutItem<T>, options?: Omit<RepoPut<T>, \"return\">): DbTrxWriteRequest {\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(item), ...item }\n : item;\n return { table: this.tableName, type: \"PUT\", item: itemWithDefaults, ...options };\n }\n\n trxUpdateRequest(\n key: RepoKey<T>,\n update: RepoUpdateData<T>,\n options?: Omit<RepoUpdate<T>, \"return\">,\n ): DbTrxWriteRequest {\n const updateWithDefaults = this.table.def.beforeUpdate\n ? { ...this.table.def.beforeUpdate(update), ...update }\n : update;\n return {\n table: this.tableName,\n type: \"UPDATE\",\n key: this.extractKey(key),\n update: updateWithDefaults,\n ...options,\n };\n }\n\n trxCreateRequest(item: RepoCreateItem<T>, options?: RepoCreate<T>): DbTrxWriteRequest {\n const { condition: otherCondition, ...otherOptions } = options ?? {};\n\n const condition = { $and: [{ [this.table.def.partitionKey]: { $exists: false } }] };\n\n if (otherCondition) {\n condition.$and.push(otherCondition);\n }\n\n const itemWithDefaults = this.table.def.beforePut\n ? { ...this.table.def.beforePut(item), ...item }\n : item;\n\n return {\n table: this.tableName,\n type: \"PUT\",\n item: itemWithDefaults,\n condition,\n ...otherOptions,\n };\n }\n}\n","import type { AttributeDefinition } from \"@aws-sdk/client-dynamodb\";\nimport { type TSchema } from \"typebox\";\nimport * as T from \"typebox\";\nimport type { Obj, ResolvedAttrType, TableDef, TableDesc, TableGsi, TableKey } from \"./types\";\n\nexport const resolveAttrType = (schema: TSchema, attrName: string): ResolvedAttrType => {\n if (T.IsString(schema) || T.IsLiteralString(schema)) {\n return T.IsOptional(schema) ? [\"S\", undefined] : [\"S\"];\n }\n\n if (T.IsNumber(schema) || T.IsLiteralNumber(schema)) {\n return T.IsOptional(schema) ? [\"N\", undefined] : [\"N\"];\n }\n\n if (T.IsObject(schema)) {\n const attrSchema = schema.properties[attrName];\n if (!attrSchema) return [undefined];\n return resolveAttrType(attrSchema, attrName);\n }\n\n if (T.IsIntersect(schema)) {\n return schema.allOf.flatMap((s) => resolveAttrType(s, attrName));\n }\n\n if (T.IsUnion(schema)) {\n return schema.anyOf.flatMap((s) => resolveAttrType(s, attrName));\n }\n\n return [];\n};\n\nexport const getAttrType = (\n schema: TSchema,\n attrName: string,\n allowedTypes: ResolvedAttrType = [\"S\", \"N\", undefined],\n): \"S\" | \"N\" => {\n const resolvedType = resolveAttrType(schema, attrName);\n if (resolvedType.includes(\"S\") && resolvedType.includes(\"N\")) {\n throw new Error(`Attribute ${attrName} cannot be both a number and a string.`);\n }\n if (!allowedTypes.includes(undefined) && resolvedType.includes(undefined)) {\n throw new Error(`Attribute ${attrName} cannot be optional.`);\n }\n return resolvedType.includes(\"S\") ? \"S\" : \"N\";\n};\n\nexport const extractAttribute = (\n schema: TSchema,\n attrName: string,\n allowedTypes?: ResolvedAttrType,\n): AttributeDefinition => {\n return {\n AttributeName: attrName,\n AttributeType: getAttrType(schema, attrName, allowedTypes),\n };\n};\n\nexport const extractTableKey = (\n schema: TSchema,\n attrName: string,\n allowedTypes?: ResolvedAttrType,\n): TableKey => {\n return {\n name: attrName,\n type: getAttrType(schema, attrName, allowedTypes),\n };\n};\n\nexport const extractTableDesc = (schema: TSchema, def: TableDef): TableDesc => {\n const gsis: TableGsi[] = Object.entries(def.gsis ?? {}).map(([indexName, gsi]) => {\n return {\n indexName,\n partitionKey: extractTableKey(schema, gsi.partitionKey),\n sortKey: gsi.sortKey ? extractTableKey(schema, gsi.sortKey) : undefined,\n projectionType: Array.isArray(gsi.projection) ? \"INCLUDE\" : (gsi.projection ?? \"ALL\"),\n nonKeyAttributes: Array.isArray(gsi.projection) ? gsi.projection : undefined,\n };\n });\n\n return {\n tableName: def.name,\n billingMode: def.billingMode ?? \"PAY_PER_REQUEST\",\n stream: def.stream,\n partitionKey: extractTableKey(schema, def.partitionKey, [\"N\", \"S\"]),\n sortKey: def.sortKey ? extractTableKey(schema, def.sortKey, [\"N\", \"S\"]) : undefined,\n gsis: gsis.length ? gsis : undefined,\n };\n};\n\nexport const chunk = <T = unknown>(arr: T[], chunkSize: number): T[][] => {\n if (chunkSize <= 0) return [];\n\n const chunks: T[][] = [];\n for (let i = 0; i < arr.length; i += chunkSize) {\n chunks.push(arr.slice(i, i + chunkSize));\n }\n\n return chunks;\n};\n\n// this currently creates sparse arrays if an undefined\n// value is found inside an array...not sure if thats valid?\nexport const removeUndefined = (obj: Obj) => {\n const stack = [obj];\n while (stack.length) {\n const currentObj = stack.pop();\n if (currentObj !== undefined) {\n Object.entries(currentObj).forEach(([k, v]) => {\n if (v && v instanceof Object) stack.push(v);\n else if (v === undefined) delete currentObj[k];\n });\n }\n }\n return obj;\n};\n","import {\n type BatchGetItemInput,\n type BatchWriteItemInput,\n ConditionalCheckFailedException,\n DynamoDB,\n DynamoDBClient,\n type DynamoDBClientConfig,\n ListTablesCommand,\n type WriteRequest,\n} from \"@aws-sdk/client-dynamodb\";\n//import { DynamoDBStreams } from '@aws-sdk/client-dynamodb-streams';\nimport type { TransactGetCommandInput, TransactWriteCommandInput } from \"@aws-sdk/lib-dynamodb\";\nimport * as Lib from \"@aws-sdk/lib-dynamodb\";\nimport sift from \"sift\";\nimport { ExpressionBuilder } from \"./expression-builder\";\nimport { Repository } from \"./repo\";\nimport type { Table } from \"./table\";\nimport type {\n DbBatchGet,\n DbBatchGetResponse,\n DbBatchWrite,\n DbBatchWriteResponse,\n DbConfig,\n DbCreate,\n DbDelete,\n DbExists,\n DbGet,\n DbListTables,\n DbPut,\n DbQuery,\n DbScan,\n DbTrxGetOrThrowResult,\n DbTrxGetRequest,\n DbTrxGetResult,\n DbTrxWriteRequest,\n DbUpdate,\n DbUpsert,\n Obj,\n} from \"./types\";\nimport { removeUndefined } from \"./util\";\n\n// TODO\n// - caching support?\n// - consider special \"limit\" handling for paged scans, maybe have \"scanLimit\" too\n// - consider \"sort\" shorthand for methods that return unpaginated collections\n// i.e. sort: { by: 'createdAt', dir: 'ASC' } or sort: (a,b) => a.createdAt - b.createdAt\n// - consider support for batchUpdates leveraging BatchExecute and PartiQL\n// - consider batchPut (batchPutOrThrow) and batchDelete that operate on a single table\n// - getGsi? throws if > 1 result, allows for assert, and filtering\n// - bug $in doesn't handle empty arrays, I imagine other operators are affected\n// - should create and upsert be here? I think not...\n\nexport class Db {\n readonly client: Lib.DynamoDBDocumentClient;\n readonly config: DbConfig | undefined;\n\n //protected streamEventListeners: DbStreamEventListener[] = [];\n\n constructor(\n clientOrConfig: DynamoDBClient | DynamoDB | DynamoDBClientConfig,\n dbConfig?: DbConfig,\n ) {\n if (clientOrConfig instanceof DynamoDBClient || clientOrConfig instanceof DynamoDB) {\n this.client = Lib.DynamoDBDocumentClient.from(new DynamoDBClient(clientOrConfig));\n } else {\n const { endpoint, ...clientConfig } = clientOrConfig;\n // client doesn't interpret an empty string endpoint as falsy so normalize things\n // here so consumers don't have to worry about that quirk\n this.client = Lib.DynamoDBDocumentClient.from(\n new DynamoDBClient({\n endpoint: endpoint || undefined,\n ...clientConfig,\n }),\n );\n }\n\n this.config = dbConfig;\n }\n\n createRepo<T extends Table<any, any>>(table: T): Repository<T> {\n return new Repository(table, this);\n }\n\n async listTables(data?: DbListTables): Promise<string[]> {\n const tables: string[] = [];\n let lastEvaluatedTableName: string | undefined;\n do {\n const output = await this.client.send(\n new ListTablesCommand({\n Limit: data?.limit,\n ExclusiveStartTableName: lastEvaluatedTableName,\n }),\n );\n\n tables.push(...(output.TableNames ?? []));\n lastEvaluatedTableName = output.LastEvaluatedTableName;\n } while (lastEvaluatedTableName);\n return tables;\n }\n\n async get<R = Obj>(data: DbGet): Promise<R | undefined> {\n const exp = new ExpressionBuilder();\n\n const input = new Lib.GetCommand({\n TableName: data.table,\n Key: data.key,\n ConsistentRead: data.consistent,\n ProjectionExpression: exp.projection(data.projection),\n ExpressionAttributeNames: exp.attributeNames,\n });\n\n const output = await this.client.send(input);\n\n if (output.Item && data.condition) {\n if (!sift(data.condition)(output.Item)) {\n return undefined;\n }\n }\n\n return output.Item as R;\n }\n\n async getOrThrow<R = Obj>(data: DbGet): Promise<R> {\n const item = await this.get(data);\n if (!item) {\n throw new Error(`Item not found in \"${data.table}\" table.`);\n }\n return item as R;\n }\n\n async put<R = Obj>(data: DbPut): Promise<R> {\n const exp = new ExpressionBuilder();\n\n const input = new Lib.PutCommand({\n TableName: data.table,\n Item: removeUndefined(data.item),\n ReturnValues: data.return === \"ALL_OLD\" ? \"ALL_OLD\" : undefined,\n ReturnValuesOnConditionCheckFailure: \"ALL_OLD\",\n ConditionExpression: exp.condition(data.condition),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n });\n\n const output = await this.client.send(input);\n\n return (data.return === \"ALL_OLD\" ? output.Attributes : data) as R;\n }\n\n async update<R = Obj>(data: DbUpdate): Promise<R | undefined> {\n const exp = new ExpressionBuilder();\n\n const condition = {\n $and: Object.keys(data.key).map((field) => ({\n [field]: { $exists: true },\n })),\n };\n\n if (data.condition) {\n condition.$and.push(data.condition);\n }\n\n const input = new Lib.UpdateCommand({\n TableName: data.table,\n Key: data.key,\n ReturnValues: data.return ?? \"ALL_NEW\",\n ReturnValuesOnConditionCheckFailure: \"ALL_OLD\",\n UpdateExpression: exp.update(data.update),\n ConditionExpression: exp.condition(condition),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n });\n\n const output = await this.client.send(input);\n\n return output.Attributes as R | undefined;\n }\n\n async create<R = Obj>(data: DbCreate): Promise<R> {\n const { condition: otherCondition, partitionKeyName, ...options } = data;\n\n const condition = { $and: [{ [partitionKeyName]: { $exists: false } }] };\n\n if (otherCondition) {\n condition.$and.push(otherCondition);\n }\n\n return this.put<R>({\n ...options,\n condition,\n return: \"ALL_NEW\",\n });\n }\n\n async upsert<R = Obj>(data: DbUpsert): Promise<R> {\n const { key, item, update, ...options } = data;\n try {\n return (await this.update({\n ...options,\n key,\n update,\n return: \"ALL_NEW\",\n })) as R;\n } catch (e) {\n if (e instanceof ConditionalCheckFailedException && !e.Item) {\n // TODO: deriving the partitionKeyName like this isn't foolproof\n return this.create({\n item,\n partitionKeyName: Object.keys(key)[0] ?? \"\",\n ...options,\n });\n }\n\n throw e;\n }\n }\n\n async delete<R = Obj>(data: DbDelete): Promise<R | undefined> {\n const exp = new ExpressionBuilder();\n\n const input = new Lib.DeleteCommand({\n TableName: data.table,\n Key: data.key,\n ReturnValues: data.return ?? \"ALL_OLD\",\n ConditionExpression: exp.condition(data.condition),\n ReturnValuesOnConditionCheckFailure: \"ALL_OLD\",\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n });\n\n const output = await this.client.send(input);\n\n return output.Attributes as R | undefined;\n }\n\n async deleteOrThrow<R = Obj>(data: Omit<DbDelete, \"return\">): Promise<R> {\n const item = await this.delete<R>(data);\n if (!item) {\n throw new Error(`Item not found in \"${data.table}\" table.`);\n }\n return item;\n }\n\n async *queryPaged<R = Obj>(data: DbQuery): AsyncGenerator<R[]> {\n const exp = new ExpressionBuilder();\n\n let lastEvaluatedKey = data.startKey;\n do {\n const input = new Lib.QueryCommand({\n TableName: data.table,\n IndexName: data.index,\n ExclusiveStartKey: lastEvaluatedKey,\n Limit: data.limit,\n ScanIndexForward: data.sort !== \"DESC\",\n ConsistentRead: data.consistent,\n KeyConditionExpression: exp.condition(data.query),\n ProjectionExpression: exp.projection(data.projection),\n FilterExpression: exp.condition(data.filter),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n });\n\n const output = await this.client.send(input);\n\n if (output.Items?.length) {\n yield output.Items as R[];\n }\n lastEvaluatedKey = output.LastEvaluatedKey;\n } while (lastEvaluatedKey);\n }\n\n async query<R = Obj>(data: DbQuery): Promise<R[]> {\n const items: Obj[] = [];\n\n for await (const page of this.queryPaged(data)) {\n items.push(...page);\n }\n\n return items as R[];\n }\n\n async *scanPaged<R = Obj>(data: DbScan): AsyncGenerator<R[]> {\n const exp = new ExpressionBuilder();\n\n const totalSegments = data.parallel ?? 1;\n const segments = [...Array(totalSegments).keys()];\n\n // undefined: initial value when a start key isn't specified\n // null: scanning a particular segment is finished\n const lastEvaluatedKeys: (Obj | undefined | null)[] = segments.map(() => data.startKey);\n do {\n const results = await Promise.all(\n segments.map(async (segment) => {\n if (lastEvaluatedKeys[segment] === null) return [];\n\n const input = new Lib.ScanCommand({\n ExclusiveStartKey: lastEvaluatedKeys[segment],\n Segment: segment,\n TotalSegments: totalSegments,\n TableName: data.table,\n IndexName: data.index,\n Limit: data.limit,\n ConsistentRead: data.consistent,\n ProjectionExpression: exp.projection(data.projection),\n FilterExpression: exp.condition(data.filter),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n });\n\n const output = await this.client.send(input);\n lastEvaluatedKeys[segment] = output.LastEvaluatedKey ?? null;\n return output.Items ?? [];\n }),\n );\n\n const items = results.flat();\n\n if (items.length) {\n yield items as R[];\n }\n } while (lastEvaluatedKeys.some((key) => key !== null));\n }\n\n async scan<R = Obj>(data: DbScan): Promise<R[]> {\n const items: R[] = [];\n\n for await (const page of this.scanPaged(data)) {\n items.push(...(page as R[]));\n }\n\n return items;\n }\n\n async exists(data: DbExists): Promise<boolean> {\n const { query, ...otherOptions } = data;\n\n // we can't rely on the limit when a filter is being applied, since the filter is\n // applied after the scan/query page, so we only apply a limit of 1 when there is no filter.\n // otherwise, we page through the results and return true as soon as we see a single item\n const sharedOptions = {\n ...otherOptions,\n limit: data.filter ? undefined : 1,\n };\n\n const pagedItems = query\n ? this.queryPaged({ query, ...sharedOptions })\n : this.scanPaged(sharedOptions);\n\n for await (const items of pagedItems) {\n if (items.length) return true;\n }\n\n return false;\n }\n\n // TODO: test wildly different item sizes to make\n // sure retry algorithm works properly\n async batchGet(data: DbBatchGet): Promise<DbBatchGetResponse> {\n const result: DbBatchGetResponse = { items: {} };\n\n const tableData = Object.fromEntries(\n Object.entries(data).map(([table, request]) => {\n const exp = new ExpressionBuilder();\n const sifter = request?.condition ? sift(request?.condition) : undefined;\n\n result.items[table] = [];\n\n return [\n table,\n {\n request: {\n ConsistentRead: request?.consistent,\n ProjectionExpression: exp.projection(request?.projection),\n ExpressionAttributeNames: exp.attributeNames,\n },\n keyNames: Object.keys(request.keys.at(0) ?? {}),\n itemIndexMap: new Map<string, number>(),\n sifter,\n },\n ];\n }),\n );\n\n const flattenedBatches = Object.entries(data).flatMap(([table, request]) => {\n return request.keys.map((key, i) => {\n const itemIndexKey =\n tableData[table]?.keyNames.map((keyName) => key[keyName]).join(\"|\") ?? \"\";\n tableData[table]?.itemIndexMap.set(itemIndexKey, i);\n return [table, key] as const;\n });\n });\n\n let batchSize = 100;\n let retryCount = 0;\n\n while (flattenedBatches.length && retryCount < 5) {\n const batch = flattenedBatches.splice(0, batchSize || 1);\n\n const request: BatchGetItemInput[\"RequestItems\"] = {};\n for (const [table, key] of batch) {\n if (!request[table]) {\n request[table] = { ...tableData[table]?.request, Keys: [] };\n }\n\n request[table].Keys?.push(key);\n }\n\n const input = new Lib.BatchGetCommand({ RequestItems: request });\n const output = await this.client.send(input);\n\n for (const [table, items] of Object.entries(output.Responses ?? {})) {\n //just to appease typescript\n if (!result.items[table]) continue;\n\n for (const item of items) {\n // items that fail the condition are treated the same as non-existent keys,\n // i.e. they are not present in items/unprocessed arrays\n if (tableData[table]?.sifter && !tableData[table].sifter(item)) {\n continue;\n }\n\n result.items[table].push(item);\n }\n }\n\n // handle unprocessed requests\n let unprocessedKeyCount = 0;\n for (const [table, request] of Object.entries(output.UnprocessedKeys ?? {})) {\n const unprocessed = (request.Keys ?? []).map((key) => [table, key] as const);\n flattenedBatches.push(...unprocessed);\n unprocessedKeyCount += unprocessed.length;\n }\n\n //move immediately to next batch if all requests were processed\n if (!unprocessedKeyCount) {\n retryCount = 0;\n continue;\n }\n\n // reduce batch size so we don't continue to overfetch,\n // but do it gradually by only splitting the difference\n batchSize -= Math.floor(unprocessedKeyCount / 2);\n\n retryCount++;\n }\n\n // anything left in flattened batches needs to be returned in unprocessed\n if (flattenedBatches.length) {\n result.unprocessed = {};\n for (const [table, key] of flattenedBatches) {\n if (!result.unprocessed[table]) {\n result.unprocessed[table] = {\n ...tableData[table]?.request,\n keys: [],\n };\n }\n result.unprocessed[table].keys.push(key);\n }\n }\n\n // finally, sort any returned items by their original index to preserve order\n for (const [table, items] of Object.entries(result.items)) {\n const itemIndexMap = tableData[table]?.itemIndexMap;\n const keyNames = tableData[table]?.keyNames;\n\n if (!itemIndexMap || !keyNames) continue;\n\n items.sort((item1, item2) => {\n const item1IndexKey = keyNames.map((keyName) => item1[keyName]).join(\"|\");\n const item2IndexKey = keyNames.map((keyName) => item2[keyName]).join(\"|\");\n\n return (itemIndexMap.get(item1IndexKey) ?? 0) - (itemIndexMap.get(item2IndexKey) ?? 0);\n });\n }\n\n return result;\n }\n\n async batchGetOrThrow(data: DbBatchGet): Promise<DbBatchGetResponse[\"items\"]> {\n const { items, unprocessed } = await this.batchGet(data);\n\n for (const table of Object.keys(data)) {\n if (unprocessed?.[table]) {\n throw new Error(`One or more batch get requests were not processed in \"${table}\" table.`);\n }\n\n if (items[table]?.length !== data[table]?.keys?.length) {\n throw new Error(`One or more items were not found in \"${table}\" table.`);\n }\n }\n\n return items;\n }\n\n // TODO: test wildly different item sizes to make\n // sure retry algorithm works properly\n async batchWrite(data: DbBatchWrite): Promise<DbBatchWriteResponse> {\n const result: DbBatchWriteResponse = { items: {} };\n\n const flattenedBatches = Object.keys(data).flatMap((table) => {\n return (\n data[table]?.map((r) => {\n if (r.type === \"DELETE\") {\n return [table, { DeleteRequest: { Key: r.key } }] as [string, WriteRequest];\n } else {\n return [table, { PutRequest: { Item: r.item } }] as [string, WriteRequest];\n }\n }) ?? []\n );\n });\n\n let batchSize = 25;\n let retryCount = 0;\n\n while (flattenedBatches.length && retryCount < 5) {\n const batch = flattenedBatches.splice(0, batchSize || 1);\n\n const request: BatchWriteItemInput[\"RequestItems\"] = {};\n for (const [table, req] of batch) {\n if (!request[table]) {\n request[table] = [];\n }\n request[table].push(req);\n }\n\n const input = new Lib.BatchWriteCommand({ RequestItems: request });\n const output = await this.client.send(input);\n\n // handle unprocessed requests\n let unprocessedKeyCount = 0;\n for (const [table, requests] of Object.entries(output.UnprocessedItems ?? {})) {\n for (const request of requests) {\n flattenedBatches.push([table, request]);\n unprocessedKeyCount++;\n }\n }\n\n //move immediately to next batch if all requests were processed\n if (!unprocessedKeyCount) {\n retryCount = 0;\n continue;\n }\n\n // reduce batch size so we don't continue to overwrite,\n // but do it gradually by only splitting the difference\n batchSize -= Math.floor(unprocessedKeyCount / 2);\n\n retryCount++;\n }\n\n // anything left in flattened batches needs to be returned in unprocessed\n if (flattenedBatches.length) {\n result.unprocessed = {};\n for (const [table, request] of flattenedBatches) {\n if (!result.unprocessed[table]) {\n result.unprocessed[table] = [];\n }\n\n if (\"DeleteRequest\" in request && request.DeleteRequest?.Key) {\n result.unprocessed[table].push({\n type: \"DELETE\",\n key: request.DeleteRequest.Key,\n });\n } else if (\"PutRequest\" in request && request.PutRequest?.Item) {\n result.unprocessed[table].push({\n type: \"PUT\",\n item: request.PutRequest.Item,\n });\n }\n }\n }\n\n return result;\n }\n\n async trxGet<R extends DbTrxGetRequest[]>(...requests: R): Promise<DbTrxGetResult<R>> {\n const trxItems: TransactGetCommandInput[\"TransactItems\"] = requests.map((request) => {\n const exp = new ExpressionBuilder();\n return {\n Get: {\n Key: request.key,\n TableName: request.table,\n ProjectionExpression: exp.projection(request?.projection),\n ExpressionAttributeNames: exp.attributeNames,\n },\n };\n });\n\n const input = new Lib.TransactGetCommand({ TransactItems: trxItems });\n const output = await this.client.send(input);\n\n return (\n (output.Responses?.map((response, i) => {\n if (requests[i]?.condition && !sift(requests[i].condition)(response.Item)) {\n return undefined;\n }\n\n return response.Item;\n }) as DbTrxGetResult<R>) ?? []\n );\n }\n\n async trxGetOrThrow<R extends DbTrxGetRequest[]>(\n ...requests: R\n ): Promise<DbTrxGetOrThrowResult<R>> {\n const items = await this.trxGet(...requests);\n for (let i = 0; i < items.length; i++) {\n if (!items[i]) {\n throw new Error(`One or more items were not found in \"${requests[i]?.table}\" table.`);\n }\n }\n\n return items as DbTrxGetOrThrowResult<R>;\n }\n\n async trxWrite(...requests: DbTrxWriteRequest[]): Promise<void> {\n const trxItems: TransactWriteCommandInput[\"TransactItems\"] = requests.map((request) => {\n const exp = new ExpressionBuilder();\n\n if (request.type === \"CONDITION\" || request.type === \"DELETE\") {\n return {\n [request.type === \"CONDITION\" ? \"ConditionCheck\" : \"Delete\"]: {\n TableName: request.table,\n Key: request.key,\n ConditionExpression: exp.condition(request.condition),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n },\n };\n }\n\n if (request.type === \"PUT\") {\n return {\n Put: {\n TableName: request.table,\n Item: removeUndefined(request.item),\n ConditionExpression: exp.condition(request.condition),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n },\n };\n }\n\n return {\n Update: {\n Key: request.key,\n TableName: request.table,\n UpdateExpression: exp.update(request.update),\n ConditionExpression: exp.condition(request.condition),\n ExpressionAttributeNames: exp.attributeNames,\n ExpressionAttributeValues: exp.attributeValues,\n },\n };\n });\n\n const input = new Lib.TransactWriteCommand({ TransactItems: trxItems });\n await this.client.send(input);\n }\n\n /* Dynamodb Streams */\n\n /*\n\n\tasync enableStreamEvents(data?: DbEnableEventStreams): Promise<void> {\n\t\tconst tables = data?.tables ?? (await this.listTables());\n\n\t\tconst streamsClient = new DynamoDBStreams({\n\t\t\tendpoint: this.client.config.endpoint,\n\t\t\tcredentials: this.client.config.credentials,\n\t\t\tregion: this.client.config.region,\n\t\t});\n\n\t\tawait Promise.all(\n\t\t\ttables.map(async (table) => {\n\t\t\t\tconst tableDesc = await this.client.send(new DescribeTableCommand({ TableName: table }));\n\n\t\t\t\tconst latestStreamArn = tableDesc.Table?.LatestStreamArn;\n\n\t\t\t\tif (!latestStreamArn) {\n\t\t\t\t\tif (data?.tables) {\n\t\t\t\t\t\tthrow new Error(`Table \"${table}\" does not have streaming enabled.`);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst eventStreamer = new EventStreamer(streamsClient, latestStreamArn);\n\t\t\t\teventStreamer.startPolling();\n\t\t\t}),\n\t\t);\n\t}\n\n\tasync disableStreamEvents(): Promise<void> {}\n\n\tsubscribe(listener: DbStreamEventListener): void {\n\t\tthis.streamEventListeners.push(listener);\n\t}\n\n\tunsubscribe(listener: DbStreamEventListener): void {\n\t\tthis.streamEventListeners = this.streamEventListeners.filter((l) => l !== listener);\n\t}\n\n\tunsubscribeAll(): void {\n\t\tthis.streamEventListeners = [];\n\t}\n\t*/\n}\n\n// respondentRepo.onChange((respondent) => , { filter: (r1, r2) => r1.status !== r2.status } )\n/*\nconst time = new Date(record.dynamodb.ApproximateCreationDateTime).getTime();\nif (time >= startTime) {\n\tfor (const listener of this.streamEventListeners) {\n\t\tlistener({\n\t\t\ttable,\n\t\t\ttime,\n\t\t\tid: record.eventID,\n\t\t\ttype: record.eventName,\n\t\t\tkey: record.dynamodb.Keys,\n\t\t\toldItem: record.dynamodb.OldImage,\n\t\t\tnewItem: record.dynamodb.NewImage,\n\t\t});\n\t}\n}\n*/\n","import {\n type AttributeDefinition,\n CreateTableCommand,\n DeleteTableCommand,\n type KeySchemaElement,\n UpdateTimeToLiveCommand,\n} from \"@aws-sdk/client-dynamodb\";\nimport type { DynamoDBDocumentClient } from \"@aws-sdk/lib-dynamodb\";\nimport type { Static, TSchema } from \"typebox\";\n//import { Table as CdkTable, type GlobalSecondaryIndexProps, type TableProps } from 'aws-cdk-lib/aws-dynamodb';\n//import type { Construct } from 'constructs';\nimport type { TableDef, TableKey } from \"./types\";\nimport { extractTableDesc } from \"./util\";\n\nexport class Table<\n Schema extends TSchema = TSchema,\n Def extends TableDef<Static<Schema>> = TableDef<Static<Schema>>,\n> {\n readonly schema: TSchema;\n readonly def: TableDef;\n\n constructor(schema: Schema, def: Def) {\n this.schema = schema;\n this.def = def;\n }\n\n async drop(client: DynamoDBDocumentClient): Promise<void> {\n await client.send(new DeleteTableCommand({ TableName: this.def.name }));\n }\n\n async createTable(client: DynamoDBDocumentClient): Promise<void> {\n const desc = extractTableDesc(this.schema, this.def);\n\n const attributes = new Map<string, AttributeDefinition>();\n const setAttribute = (tableKey: TableKey) => {\n attributes.set(tableKey.name, { AttributeName: tableKey.name, AttributeType: tableKey.type });\n };\n\n const keySchema: KeySchemaElement[] = [\n { AttributeName: desc.partitionKey.name, KeyType: \"HASH\" },\n ];\n setAttribute(desc.partitionKey);\n\n if (desc.sortKey) {\n keySchema.push({ AttributeName: desc.sortKey.name, KeyType: \"RANGE\" });\n setAttribute(desc.sortKey);\n }\n\n const gsis = desc.gsis?.map((gsi) => {\n const gsiKeySchema: KeySchemaElement[] = [\n { AttributeName: gsi.partitionKey.name, KeyType: \"HASH\" },\n ];\n setAttribute(gsi.partitionKey);\n if (gsi.sortKey) {\n gsiKeySchema.push({ AttributeName: gsi.sortKey.name, KeyType: \"RANGE\" });\n setAttribute(gsi.sortKey);\n }\n return {\n IndexName: gsi.indexName,\n KeySchema: gsiKeySchema,\n Projection: {\n ProjectionType: gsi.projectionType,\n NonKeyAttributes: gsi.nonKeyAttributes,\n },\n };\n });\n\n await client.send(\n new CreateTableCommand({\n TableName: desc.tableName,\n KeySchema: keySchema,\n AttributeDefinitions: [...attributes.values()],\n BillingMode: desc.billingMode,\n GlobalSecondaryIndexes: gsis,\n StreamSpecification: desc.stream\n ? {\n StreamEnabled: true,\n StreamViewType: desc.stream,\n }\n : undefined,\n }),\n );\n\n if (desc.ttlAttribute) {\n await client.send(\n new UpdateTimeToLiveCommand({\n TableName: desc.tableName,\n TimeToLiveSpecification: {\n Enabled: true,\n AttributeName: desc.ttlAttribute,\n },\n }),\n );\n }\n }\n\n /*\n\tcreateCdkTable(construct: Construct): CdkTable {\n\t\tconst { ttlAttribute, gsis = [], ...tableProps } = extractTableDesc(this.schema, this.def);\n\n\t\tconst table = new CdkTable(construct, `${tableProps.tableName}-table`, {\n\t\t\t...(tableProps as TableProps),\n\t\t\ttimeToLiveAttribute: ttlAttribute,\n\t\t});\n\n\t\tfor (const gsi of gsis) {\n\t\t\ttable.addGlobalSecondaryIndex(gsi as GlobalSecondaryIndexProps);\n\t\t}\n\n\t\treturn table;\n\t}\n\t*/\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,YAAY;CAAC;CAAK;CAAM;CAAK;CAAM;CAAK;CAAM;CAAQ;CAAQ;CAAK;CAAI;AAC7E,MAAM,gBAA6B;CACjC,KAAK;CACL,KAAK;CACL,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L,CAAC,CACH;AAED,MAAI,KAAK,aACP,OAAM,OAAO,KACX,IAAIC,yBAAAA,wBAAwB;GAC1B,WAAW,KAAK;GAChB,yBAAyB;IACvB,SAAS;IACT,eAAe,KAAK;IACrB;GACF,CAAC,CACH"}
package/dist/index.d.cts DELETED
@@ -1,454 +0,0 @@
1
- import { AttributeDefinition, DynamoDB, DynamoDBClient, DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
2
- import * as Lib from "@aws-sdk/lib-dynamodb";
3
- import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
4
- import { Static, TSchema } from "typebox";
5
-
6
- //#region src/types.d.ts
7
- type Obj<T = any> = Record<string, T>;
8
- interface DbConfig {
9
- tableNamePrefix?: string;
10
- }
11
- interface DbListTables {
12
- limit?: number;
13
- }
14
- interface DbGet {
15
- table: string;
16
- key: Obj;
17
- consistent?: boolean;
18
- projection?: string[];
19
- condition?: Obj;
20
- }
21
- interface DbPut {
22
- table: string;
23
- item: Obj;
24
- return?: "ALL_OLD" | "ALL_NEW";
25
- condition?: Obj;
26
- }
27
- interface DbUpdate {
28
- table: string;
29
- key: Obj;
30
- update: Obj;
31
- return?: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW";
32
- condition?: Obj;
33
- }
34
- interface DbCreate {
35
- table: string;
36
- partitionKeyName: string;
37
- item: Obj;
38
- condition?: Obj;
39
- }
40
- interface DbUpsert {
41
- table: string;
42
- key: Obj;
43
- update: Obj;
44
- item: Obj;
45
- condition?: Obj;
46
- }
47
- interface DbDelete {
48
- table: string;
49
- key: Obj;
50
- return?: "NONE" | "ALL_OLD";
51
- condition?: Obj;
52
- }
53
- interface DbQuery {
54
- table: string;
55
- query: Obj;
56
- startKey?: Obj;
57
- filter?: Obj;
58
- projection?: string[];
59
- limit?: number;
60
- index?: string;
61
- consistent?: boolean;
62
- sort?: "ASC" | "DESC";
63
- }
64
- interface DbScan {
65
- table: string;
66
- startKey?: Obj;
67
- filter?: Obj;
68
- projection?: string[];
69
- limit?: number;
70
- index?: string;
71
- consistent?: boolean;
72
- parallel?: number;
73
- }
74
- interface DbExists {
75
- table: string;
76
- query?: Obj;
77
- filter?: Obj;
78
- index?: string;
79
- projection?: string[];
80
- consistent?: boolean;
81
- }
82
- interface DbBatchGetRequest {
83
- keys: Obj[];
84
- consistent?: boolean;
85
- projection?: string[];
86
- condition?: Obj;
87
- }
88
- type DbBatchGet = Obj<DbBatchGetRequest>;
89
- interface DbBatchGetResponse {
90
- items: Obj<Obj[]>;
91
- unprocessed?: DbBatchGet;
92
- }
93
- interface DbBatchDeleteRequest {
94
- type: "DELETE";
95
- key: Obj;
96
- }
97
- interface DbBatchPutRequest {
98
- type: "PUT";
99
- item: Obj;
100
- }
101
- type DbBatchWrite = Obj<(DbBatchDeleteRequest | DbBatchPutRequest)[]>;
102
- interface DbBatchWriteResponse {
103
- items: Obj<Obj[]>;
104
- unprocessed?: DbBatchWrite;
105
- }
106
- interface DbTrxGetRequest<T = Obj> {
107
- table: string;
108
- key: Obj;
109
- projection?: string[];
110
- condition?: Obj;
111
- }
112
- type DbTrxGetResult<R extends DbTrxGetRequest[]> = { [K in keyof R]: R[K] extends DbTrxGetRequest<infer T> ? T | undefined : Obj | undefined };
113
- type DbTrxGetOrThrowResult<R extends DbTrxGetRequest[]> = { [K in keyof R]: R[K] extends DbTrxGetRequest<infer T> ? (T extends Obj ? T : Obj) : Obj };
114
- interface DbTrxDeleteRequest {
115
- table: string;
116
- type: "DELETE";
117
- key: Obj;
118
- condition?: Obj;
119
- }
120
- interface DbTrxPutRequest {
121
- table: string;
122
- type: "PUT";
123
- item: Obj;
124
- condition?: Obj;
125
- }
126
- interface DbTrxUpdateRequest {
127
- table: string;
128
- type: "UPDATE";
129
- key: Obj;
130
- update: Obj;
131
- condition?: Obj;
132
- }
133
- interface DbTrxConditionRequest {
134
- table: string;
135
- type: "CONDITION";
136
- key: Obj;
137
- condition: Obj;
138
- }
139
- type DbTrxWriteRequest = DbTrxDeleteRequest | DbTrxPutRequest | DbTrxUpdateRequest | DbTrxConditionRequest;
140
- interface DbEnableEventStreams {
141
- tables?: string[];
142
- startTime?: number;
143
- }
144
- interface DbDisableEventStreams {
145
- tables?: string[];
146
- }
147
- interface DbStreamEvent {
148
- id: string;
149
- time: number;
150
- table: string;
151
- key: Obj;
152
- type: "INSERT" | "MODIFY" | "REMOVE";
153
- oldItem?: Obj;
154
- newItem?: Obj;
155
- }
156
- type DbStreamEventListener = (event: DbStreamEvent) => void;
157
- type AllKeys<T> = Extract<T extends any ? keyof T : never, string>;
158
- type PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
159
- type DistPartialSome<T, K extends AllKeys<T>> = T extends unknown ? PartialSome<T, K> : never;
160
- type ExtractTableDef<T> = T extends Table<any, infer Def> ? Def : never;
161
- type ExtractTableSchema<T> = T extends Table<infer Schema, any> ? Static<Schema> : never;
162
- type ExtractKey<S, D> = D extends {
163
- partitionKey: infer PK;
164
- sortKey?: infer SK;
165
- } ? PK extends keyof S ? SK extends keyof S ? Pick<S, PK | SK> : Pick<S, PK> : never : never;
166
- type Func = (...args: any[]) => any;
167
- type RepoKey<T> = Partial<ExtractTableSchema<T>> & ExtractKey<ExtractTableSchema<T>, ExtractTableDef<T>>;
168
- type Item<T> = ExtractTableDef<T>["beforePut"] extends Func ? keyof ReturnType<ExtractTableDef<T>["beforePut"]> extends AllKeys<ExtractTableSchema<T>> ? DistPartialSome<ExtractTableSchema<T>, keyof ReturnType<ExtractTableDef<T>["beforePut"]>> : ExtractTableSchema<T> : ExtractTableSchema<T>;
169
- type GsiNames<T> = Extract<keyof ExtractTableDef<T>["gsis"], string>;
170
- type GsiKey<T, G extends GsiNames<T>> = ExtractKey<ExtractTableSchema<T>, ExtractTableDef<T>["gsis"][G]>;
171
- type Projection<T> = AllKeys<ExtractTableSchema<T>>[];
172
- type ApplyProjection<T, O> = O extends {
173
- projection: Array<infer P extends keyof ExtractTableSchema<T>>;
174
- } ? Pick<ExtractTableSchema<T>, P> : ExtractTableSchema<T>;
175
- interface RepoGet<T> {
176
- consistent?: boolean;
177
- projection?: Projection<T>;
178
- condition?: Obj;
179
- }
180
- type RepoGetResult<T, O extends RepoGet<T>> = undefined | ApplyProjection<T, O>;
181
- type RepoGetOrThrowResult<T, O extends RepoGet<T>> = ApplyProjection<T, O>;
182
- type RepoPutItem<T> = Item<T>;
183
- interface RepoPut<_T> {
184
- return?: "ALL_OLD" | "ALL_NEW";
185
- condition?: Obj;
186
- }
187
- type RepoPutResult<T, O extends RepoPut<T>> = O["return"] extends "NONE" ? undefined : ExtractTableSchema<T>;
188
- type RepoCreateItem<T> = Item<T>;
189
- interface RepoCreate<_T> {
190
- condition?: Obj;
191
- }
192
- type RepoCreateResult<T, _O extends RepoPut<T>> = ExtractTableSchema<T>;
193
- interface RepoUpsert<T> {
194
- key: RepoKey<T>;
195
- update: Obj;
196
- item: Item<T>;
197
- condition?: Obj;
198
- }
199
- type RepoUpsertResult<T> = ExtractTableSchema<T>;
200
- type RepoUpdateData<_T> = Obj;
201
- interface RepoUpdate<_T> {
202
- return?: "NONE" | "ALL_OLD" | "ALL_NEW";
203
- condition?: Obj;
204
- }
205
- type RepoUpdateResult<T, O extends RepoUpdate<T>> = O["return"] extends "NONE" ? undefined : ExtractTableSchema<T>;
206
- interface RepoDelete<_T> {
207
- return?: "NONE" | "ALL_OLD";
208
- condition?: Obj;
209
- }
210
- type RepoDeleteResult<T> = ExtractTableSchema<T> | undefined;
211
- type RepoDeleteOrThrowResult<T> = ExtractTableSchema<T>;
212
- interface RepoQuery<T> {
213
- startKey?: RepoKey<T>;
214
- filter?: Obj;
215
- projection?: Projection<T>;
216
- limit?: number;
217
- consistent?: boolean;
218
- sort?: "ASC" | "DESC";
219
- }
220
- type RepoQueryResult<T, O extends RepoQuery<T>> = ApplyProjection<T, O>[];
221
- type RepoQueryPagedResult<T, O extends RepoQuery<T>> = AsyncGenerator<ApplyProjection<T, O>[]>;
222
- interface RepoQueryGsi<T> {
223
- startKey?: RepoKey<T>;
224
- filter?: Obj;
225
- projection?: Projection<T>;
226
- limit?: number;
227
- sort?: "ASC" | "DESC";
228
- }
229
- type RepoQueryGsiResult<T, O extends RepoQueryGsi<T>> = ApplyProjection<T, O>[];
230
- type RepoQueryGsiPagedResult<T, O extends RepoQueryGsi<T>> = AsyncGenerator<ApplyProjection<T, O>[]>;
231
- interface RepoScan<T> {
232
- startKey?: RepoKey<T>;
233
- filter?: Obj;
234
- projection?: Projection<T>;
235
- limit?: number;
236
- consistent?: boolean;
237
- parallel?: number;
238
- }
239
- type RepoScanResult<T, O extends RepoScan<T>> = ApplyProjection<T, O>[];
240
- type RepoScanPagedResult<T, O extends RepoScan<T>> = AsyncGenerator<ApplyProjection<T, O>[]>;
241
- interface RepoScanGsi<T> {
242
- startKey?: RepoKey<T>;
243
- filter?: Obj;
244
- projection?: Projection<T>;
245
- limit?: number;
246
- parallel?: number;
247
- }
248
- type RepoScanGsiResult<T, O extends RepoScanGsi<T>> = ApplyProjection<T, O>[];
249
- type RepoScanGsiPagedResult<T, O extends RepoScanGsi<T>> = AsyncGenerator<ApplyProjection<T, O>[]>;
250
- interface RepoExists<_T> {
251
- query?: Obj;
252
- filter?: Obj;
253
- consistent?: boolean;
254
- }
255
- interface RepoTrxGet<T> {
256
- projection?: Projection<T>;
257
- condition?: Obj;
258
- }
259
- type RepoTrxGetResult<T, O extends RepoTrxGet<T>> = (ApplyProjection<T, O> | undefined)[];
260
- type RepoTrxGetOrThrowResult<T, O extends RepoTrxGet<T>> = ApplyProjection<T, O>[];
261
- type RepoTrxGetRequestResult<T> = {
262
- table: string;
263
- };
264
- interface RepoTrxDeleteRequest<T> {
265
- type: "DELETE";
266
- key: RepoKey<T>;
267
- condition?: Obj;
268
- }
269
- interface RepoTrxPutRequest<T> {
270
- type: "PUT";
271
- item: RepoPutItem<T>;
272
- condition?: Obj;
273
- }
274
- interface RepoTrxUpdateRequest<T> {
275
- table: string;
276
- type: "UPDATE";
277
- key: RepoKey<T>;
278
- update: RepoUpdateData<T>;
279
- condition?: Obj;
280
- }
281
- interface RepoTrxConditionRequest<T> {
282
- type: "CONDITION";
283
- key: RepoKey<T>;
284
- condition: Obj;
285
- }
286
- type RepoTrxWriteRequest<T> = RepoTrxDeleteRequest<T> | RepoTrxPutRequest<T> | RepoTrxUpdateRequest<T> | RepoTrxConditionRequest<T>;
287
- interface RepoBatchGet<T> {
288
- consistent?: boolean;
289
- projection?: Projection<T>;
290
- condition?: Obj;
291
- }
292
- type RepoBatchGetResult<T, O extends RepoBatchGet<T>> = {
293
- items: ApplyProjection<T, O>[];
294
- unprocessed?: RepoKey<T>[];
295
- };
296
- type RepoBatchGetOrThrowResult<T, O extends RepoBatchGet<T>> = ApplyProjection<T, O>[];
297
- type RepoBatchWritePutRequest<T> = {
298
- type: "PUT";
299
- item: Item<T>;
300
- };
301
- type RepoBatchWriteDeleteRequest<T> = {
302
- type: "DELETE";
303
- key: RepoKey<T>;
304
- };
305
- type RepoBatchWrite<T> = (RepoBatchWritePutRequest<T> | RepoBatchWriteDeleteRequest<T>)[];
306
- type RepoBatchWriteResult<T> = {
307
- items: Item<T>[];
308
- unprocessed?: RepoBatchWrite<T>;
309
- };
310
- type RepoBatchPut<T> = Item<T>[];
311
- type RepoBatchPutResult<T> = {
312
- items: Item<T>[];
313
- unprocessed?: RepoBatchPut<T>;
314
- };
315
- type RepoBatchDelete<T> = RepoKey<T>[];
316
- type RepoBatchDeleteResponse<T> = RepoBatchDelete<T> | undefined;
317
- type PickTypeOf<T, K extends AllKeys<T>, O> = T extends { [k in K]?: O } ? T[K] : never;
318
- type ExtractKeys<T, O> = { [K in AllKeys<T>]: PickTypeOf<T, K, O> extends never ? never : {
319
- k: K;
320
- v: PickTypeOf<T, K, O>;
321
- } }[AllKeys<T>]["k"];
322
- type ValidPrimaryKeys<T> = { [K in keyof T]: T[K] extends string | number ? K : never }[keyof T];
323
- type ValidTtlKeys<T> = ExtractKeys<T, number>;
324
- type ValidGsiKeys<T> = ExtractKeys<T, string | number>;
325
- interface Gsi<T> {
326
- partitionKey: ValidGsiKeys<T>;
327
- sortKey?: ValidGsiKeys<T>;
328
- projection?: "ALL" | "KEYS_ONLY" | AllKeys<T>[];
329
- }
330
- interface TableDef<T = any> {
331
- name: string;
332
- partitionKey: ValidPrimaryKeys<T>;
333
- sortKey?: ValidPrimaryKeys<T>;
334
- gsis?: Record<string, Gsi<T>>;
335
- ttlAttribute?: ValidTtlKeys<T>;
336
- billingMode?: "PAY_PER_REQUEST" | "PROVISIONED";
337
- stream?: "KEYS_ONLY" | "NEW_IMAGE" | "OLD_IMAGE" | "NEW_AND_OLD_IMAGES";
338
- beforePut?: (data: Partial<T>) => Partial<T>;
339
- beforeUpdate?: (update: Obj) => Partial<T>;
340
- }
341
- interface TableKey {
342
- name: string;
343
- type: "S" | "N";
344
- }
345
- interface TableGsi {
346
- indexName: string;
347
- projectionType: "KEYS_ONLY" | "ALL" | "INCLUDE";
348
- partitionKey: TableKey;
349
- sortKey?: TableKey;
350
- nonKeyAttributes?: string[];
351
- }
352
- interface TableDesc {
353
- tableName: string;
354
- billingMode: "PAY_PER_REQUEST" | "PROVISIONED";
355
- partitionKey: TableKey;
356
- sortKey?: TableKey;
357
- ttlAttribute?: string;
358
- gsis?: TableGsi[];
359
- stream?: "KEYS_ONLY" | "NEW_IMAGE" | "OLD_IMAGE" | "NEW_AND_OLD_IMAGES";
360
- }
361
- type ResolvedAttrType = ("S" | "N" | undefined)[];
362
- //#endregion
363
- //#region src/table.d.ts
364
- declare class Table<Schema extends TSchema = TSchema, Def extends TableDef<Static<Schema>> = TableDef<Static<Schema>>> {
365
- readonly schema: TSchema;
366
- readonly def: TableDef;
367
- constructor(schema: Schema, def: Def);
368
- drop(client: DynamoDBDocumentClient): Promise<void>;
369
- createTable(client: DynamoDBDocumentClient): Promise<void>;
370
- }
371
- //#endregion
372
- //#region src/repo.d.ts
373
- declare class Repository<T extends Table<any, any>> {
374
- readonly table: Table<TSchema, any>;
375
- readonly db: Db;
376
- constructor(table: T, db: Db);
377
- get tableName(): string;
378
- get def(): ExtractTableDef<T>;
379
- extractKey(item: RepoKey<T>): RepoKey<T>;
380
- get<O extends RepoGet<T>>(key: RepoKey<T>, options?: O): Promise<RepoGetResult<T, O>>;
381
- getOrThrow<O extends RepoGet<T>>(key: RepoKey<T>, options?: O): Promise<RepoGetOrThrowResult<T, O>>;
382
- put<O extends RepoPut<T>>(item: RepoPutItem<T>, options?: O): Promise<RepoPutResult<T, O>>;
383
- update<O extends RepoUpdate<T>>(key: RepoKey<T>, update: RepoUpdateData<T>, options?: O): Promise<RepoUpdateResult<T, O>>;
384
- create<O extends RepoCreate<T>>(item: RepoCreateItem<T>, options?: O): Promise<RepoCreateResult<T, O>>;
385
- upsert(data: RepoUpsert<T>): Promise<RepoUpsertResult<T>>;
386
- delete(key: RepoKey<T>, options?: RepoDelete<T>): Promise<RepoDeleteResult<T>>;
387
- deleteOrThrow(key: RepoKey<T>, options?: Omit<RepoDelete<T>, "return">): Promise<RepoDeleteOrThrowResult<T>>;
388
- query<O extends RepoQuery<T>>(query: Obj, options?: O): Promise<RepoQueryResult<T, O>>;
389
- queryPaged<O extends RepoQuery<T>>(query: Obj, options?: O): RepoQueryPagedResult<T, O>;
390
- queryGsi<G extends GsiNames<T>, O extends RepoQueryGsi<T>>(gsi: G, query: Obj, options?: O): Promise<RepoQueryGsiResult<T, O>>;
391
- queryGsiPaged<G extends GsiNames<T>, O extends RepoQueryGsi<T>>(gsi: G, query: Obj, options?: O): RepoQueryGsiPagedResult<T, O>;
392
- scan<O extends RepoScan<T>>(options?: O): Promise<RepoScanResult<T, O>>;
393
- scanPaged<O extends RepoScan<T>>(options?: O): RepoScanPagedResult<T, O>;
394
- scanGsi<G extends GsiNames<T>, O extends RepoScanGsi<T>>(gsi: G, options?: O): Promise<RepoScanGsiResult<T, O>>;
395
- scanGsiPaged<G extends GsiNames<T>, O extends RepoScanGsi<T>>(gsi: G, options?: O): RepoScanGsiPagedResult<T, O>;
396
- exists(options?: RepoExists<T>): Promise<boolean>;
397
- existsGsi(gsi: GsiNames<T>, options?: RepoExists<T>): Promise<boolean>;
398
- batchGet<O extends RepoBatchGet<T>>(keys: RepoKey<T>[], options?: O): Promise<RepoBatchGetResult<T, O>>;
399
- batchGetOrThrow<O extends RepoBatchGet<T>>(keys: RepoKey<T>[], options?: O): Promise<RepoBatchGetOrThrowResult<T, O>>;
400
- batchWrite(requests: RepoBatchWrite<T>): Promise<RepoBatchWriteResult<T>>;
401
- trxGet<O extends RepoTrxGet<T>>(keys: RepoKey<T>[], options?: O): Promise<RepoTrxGetResult<T, O>>;
402
- trxGetOrThrow<O extends RepoTrxGet<T>>(keys: RepoKey<T>[], options?: O): Promise<RepoTrxGetOrThrowResult<T, O>>;
403
- trxWrite(...requests: RepoTrxWriteRequest<T>[]): Promise<void>;
404
- trxDelete(keys: RepoKey<T>[], options?: Omit<RepoDelete<T>, "return">): Promise<void>;
405
- trxPut(items: RepoPutItem<T>[], options?: Omit<RepoPut<T>, "return">): Promise<void>;
406
- trxUpdate(keys: RepoKey<T>[], update: RepoUpdateData<T>, options?: Omit<RepoUpdate<T>, "return">): Promise<void>;
407
- trxCreate(items: RepoCreateItem<T>[], options?: RepoCreate<T>): Promise<void>;
408
- trxGetRequest<O extends RepoGet<T>>(key: RepoKey<T>, options?: O): DbTrxGetRequest<RepoGetOrThrowResult<T, O>>;
409
- trxDeleteRequest(key: RepoKey<T>, options?: Omit<RepoDelete<T>, "return">): DbTrxWriteRequest;
410
- trxConditionRequest(key: RepoKey<T>, condition: Obj, options?: Omit<RepoDelete<T>, "return" | "condition">): DbTrxWriteRequest;
411
- trxPutRequest(item: RepoPutItem<T>, options?: Omit<RepoPut<T>, "return">): DbTrxWriteRequest;
412
- trxUpdateRequest(key: RepoKey<T>, update: RepoUpdateData<T>, options?: Omit<RepoUpdate<T>, "return">): DbTrxWriteRequest;
413
- trxCreateRequest(item: RepoCreateItem<T>, options?: RepoCreate<T>): DbTrxWriteRequest;
414
- }
415
- //#endregion
416
- //#region src/db.d.ts
417
- declare class Db {
418
- readonly client: Lib.DynamoDBDocumentClient;
419
- readonly config: DbConfig | undefined;
420
- constructor(clientOrConfig: DynamoDBClient | DynamoDB | DynamoDBClientConfig, dbConfig?: DbConfig);
421
- createRepo<T extends Table<any, any>>(table: T): Repository<T>;
422
- listTables(data?: DbListTables): Promise<string[]>;
423
- get<R = Obj>(data: DbGet): Promise<R | undefined>;
424
- getOrThrow<R = Obj>(data: DbGet): Promise<R>;
425
- put<R = Obj>(data: DbPut): Promise<R>;
426
- update<R = Obj>(data: DbUpdate): Promise<R | undefined>;
427
- create<R = Obj>(data: DbCreate): Promise<R>;
428
- upsert<R = Obj>(data: DbUpsert): Promise<R>;
429
- delete<R = Obj>(data: DbDelete): Promise<R | undefined>;
430
- deleteOrThrow<R = Obj>(data: Omit<DbDelete, "return">): Promise<R>;
431
- queryPaged<R = Obj>(data: DbQuery): AsyncGenerator<R[]>;
432
- query<R = Obj>(data: DbQuery): Promise<R[]>;
433
- scanPaged<R = Obj>(data: DbScan): AsyncGenerator<R[]>;
434
- scan<R = Obj>(data: DbScan): Promise<R[]>;
435
- exists(data: DbExists): Promise<boolean>;
436
- batchGet(data: DbBatchGet): Promise<DbBatchGetResponse>;
437
- batchGetOrThrow(data: DbBatchGet): Promise<DbBatchGetResponse["items"]>;
438
- batchWrite(data: DbBatchWrite): Promise<DbBatchWriteResponse>;
439
- trxGet<R extends DbTrxGetRequest[]>(...requests: R): Promise<DbTrxGetResult<R>>;
440
- trxGetOrThrow<R extends DbTrxGetRequest[]>(...requests: R): Promise<DbTrxGetOrThrowResult<R>>;
441
- trxWrite(...requests: DbTrxWriteRequest[]): Promise<void>;
442
- }
443
- //#endregion
444
- //#region src/util.d.ts
445
- declare const resolveAttrType: (schema: TSchema, attrName: string) => ResolvedAttrType;
446
- declare const getAttrType: (schema: TSchema, attrName: string, allowedTypes?: ResolvedAttrType) => "S" | "N";
447
- declare const extractAttribute: (schema: TSchema, attrName: string, allowedTypes?: ResolvedAttrType) => AttributeDefinition;
448
- declare const extractTableKey: (schema: TSchema, attrName: string, allowedTypes?: ResolvedAttrType) => TableKey;
449
- declare const extractTableDesc: (schema: TSchema, def: TableDef) => TableDesc;
450
- declare const chunk: <T = unknown>(arr: T[], chunkSize: number) => T[][];
451
- declare const removeUndefined: (obj: Obj) => Obj;
452
- //#endregion
453
- export { AllKeys, ApplyProjection, Db, DbBatchDeleteRequest, DbBatchGet, DbBatchGetRequest, DbBatchGetResponse, DbBatchPutRequest, DbBatchWrite, DbBatchWriteResponse, DbConfig, DbCreate, DbDelete, DbDisableEventStreams, DbEnableEventStreams, DbExists, DbGet, DbListTables, DbPut, DbQuery, DbScan, DbStreamEvent, DbStreamEventListener, DbTrxConditionRequest, DbTrxDeleteRequest, DbTrxGetOrThrowResult, DbTrxGetRequest, DbTrxGetResult, DbTrxPutRequest, DbTrxUpdateRequest, DbTrxWriteRequest, DbUpdate, DbUpsert, DistPartialSome, ExtractKey, ExtractKeys, ExtractTableDef, ExtractTableSchema, Func, Gsi, GsiKey, GsiNames, Item, Obj, PartialSome, PickTypeOf, Projection, RepoBatchDelete, RepoBatchDeleteResponse, RepoBatchGet, RepoBatchGetOrThrowResult, RepoBatchGetResult, RepoBatchPut, RepoBatchPutResult, RepoBatchWrite, RepoBatchWriteResult, RepoCreate, RepoCreateItem, RepoCreateResult, RepoDelete, RepoDeleteOrThrowResult, RepoDeleteResult, RepoExists, RepoGet, RepoGetOrThrowResult, RepoGetResult, RepoKey, RepoPut, RepoPutItem, RepoPutResult, RepoQuery, RepoQueryGsi, RepoQueryGsiPagedResult, RepoQueryGsiResult, RepoQueryPagedResult, RepoQueryResult, RepoScan, RepoScanGsi, RepoScanGsiPagedResult, RepoScanGsiResult, RepoScanPagedResult, RepoScanResult, RepoTrxConditionRequest, RepoTrxDeleteRequest, RepoTrxGet, RepoTrxGetOrThrowResult, RepoTrxGetRequestResult, RepoTrxGetResult, RepoTrxPutRequest, RepoTrxUpdateRequest, RepoTrxWriteRequest, RepoUpdate, RepoUpdateData, RepoUpdateResult, RepoUpsert, RepoUpsertResult, Repository, ResolvedAttrType, Table, TableDef, TableDesc, TableGsi, TableKey, ValidGsiKeys, ValidPrimaryKeys, ValidTtlKeys, chunk, extractAttribute, extractTableDesc, extractTableKey, getAttrType, removeUndefined, resolveAttrType };
454
- //# sourceMappingURL=index.d.cts.map