import { Table as BaseTable, AttributeType, StreamViewType, TableProps as BaseTableProps } from "aws-cdk-lib/aws-dynamodb"; import { Construct } from "constructs"; import { F } from "ts-toolbelt"; import { ValueType } from "../core/value-type.js"; import { OpaqueType } from "../opaque-type/index.js"; type DynamodbPrimitiveValues = string | number | bigint | Uint8Array | boolean | string[] | (number | bigint)[] | Uint8Array[] | boolean[]; export interface DynamodbItem { [name: string]: DynamodbPrimitiveValues | DynamodbItem | DynamodbItem[]; } type KeyDefinition = { name: string; type: AttributeType; }; type TypeFromAttributeType = T extends AttributeType.STRING ? string : T extends AttributeType.NUMBER ? number | bigint : T extends AttributeType.BINARY ? Uint8Array : never; type AttributeFromKeyDefinition = { [name in T["name"]]: TypeFromAttributeType; }; export type AccessPattern = DynamodbItem & AttributeFromKeyDefinition & AttributeFromKeyDefinition>; export interface TableProps | undefined, Stream extends StreamViewType | undefined> extends BaseTableProps { partitionKey: PartitionKey; sortKey?: SortKey; itemType?: ValueType; stream?: Stream; } type ResolveValueType = T extends ValueType ? V : T; export interface MaterializedTableProps { partitionKey: keyof T; sortKey: keyof T | never; itemType: T; stream: StreamViewType | never; } export type MaterializeTableProps> = { partitionKey: T["partitionKey"]["name"] extends string ? T["partitionKey"]["name"] : never; sortKey: T["sortKey"] extends infer SortKey ? SortKey extends KeyDefinition ? SortKey["name"] : never : never; itemType: ResolveValueType extends infer ItemType ? unknown extends ItemType ? AccessPattern : ItemType extends undefined ? AccessPattern : ItemType : AccessPattern; stream: T["stream"] extends infer Stream ? Stream extends StreamViewType ? Stream : never : never; }; export type TableName = OpaqueType; /** * Defines a type-safe DynamoDB table. * * @example * ```ts * type User = { * pk: string; * sk: number; * }; * const table = new cloudy.aws_dynamodb.Table(this, "table", { * partitionKey: { * name: "pk", * type: cloudy.AttributeType.STRING, * }, * sortKey: { * name: "sk", * type: cloudy.AttributeType.NUMBER, * }, * itemType: cloudy.ValueType.as(), * }); * ``` */ export declare class Table = AccessPattern, Stream extends StreamViewType | undefined = undefined> extends BaseTable { /** * Name of the dynamodb table. * * @attribute */ readonly tableName: TableName>>; constructor(scope: Construct, id: string, properties: F.Narrow>); } export {};