{
  "version": 3,
  "sources": ["../../src/aws-dynamodb/table.ts"],
  "sourcesContent": ["import {\n  Table as BaseTable,\n  AttributeType,\n  StreamViewType,\n  TableProps as BaseTableProps,\n} from \"aws-cdk-lib/aws-dynamodb\";\nimport { Construct } from \"constructs\";\nimport { F } from \"ts-toolbelt\";\n\nimport { IsExact, typeAssert } from \"./table.conditional-type-checks.js\";\nimport { ValueType } from \"../core/value-type.js\";\nimport { OpaqueType } from \"../opaque-type/index.js\";\n// // eslint-disable-next-line import/no-extraneous-dependencies\n// export { AttributeValue } from \"@aws-sdk/client-dynamodb\";\n// export {\n//   AttributeType,\n//   StreamViewType,\n//   BillingMode,\n// } from \"aws-cdk-lib/aws-dynamodb\";\n\nimport { staticTest } from \"../static-test.js\";\n\ntype DynamodbPrimitiveValues =\n  | string\n  | number\n  | bigint\n  | Uint8Array\n  | boolean\n  | string[]\n  | (number | bigint)[]\n  | Uint8Array[]\n  | boolean[];\n\nexport interface DynamodbItem {\n  [name: string]: DynamodbPrimitiveValues | DynamodbItem | DynamodbItem[];\n}\n// export type DynamodbItem = {\n//   [name: string]: DynamodbPrimitiveValues | DynamodbItem | DynamodbItem[];\n// };\n\ntype KeyDefinition = {\n  name: string;\n  type: AttributeType;\n};\n\ntype TypeFromAttributeType<T extends AttributeType> =\n  T extends AttributeType.STRING\n    ? string\n    : T extends AttributeType.NUMBER\n      ? number | bigint\n      : T extends AttributeType.BINARY\n        ? Uint8Array\n        : never;\n\ntype AttributeFromKeyDefinition<T extends KeyDefinition> = {\n  [name in T[\"name\"]]: TypeFromAttributeType<T[\"type\"]>;\n};\n\nexport type AccessPattern<\n  PartitionKey extends KeyDefinition,\n  SortKey extends KeyDefinition | undefined,\n> = DynamodbItem &\n  AttributeFromKeyDefinition<PartitionKey> &\n  AttributeFromKeyDefinition<NonNullable<SortKey>>;\n\nexport interface TableProps<\n  PartitionKey extends KeyDefinition,\n  SortKey extends KeyDefinition | undefined,\n  ItemType extends AccessPattern<PartitionKey, SortKey> | undefined,\n  Stream extends StreamViewType | undefined,\n> extends BaseTableProps {\n  partitionKey: PartitionKey;\n  sortKey?: SortKey;\n  itemType?: ValueType<ItemType>;\n  stream?: Stream;\n}\n\ntype ResolveValueType<T> = T extends ValueType<infer V> ? V : T;\n\nexport interface MaterializedTableProps<T extends DynamodbItem = DynamodbItem> {\n  partitionKey: keyof T;\n  sortKey: keyof T | never;\n  itemType: T;\n  stream: StreamViewType | never;\n}\n\nexport type MaterializeTableProps<T extends TableProps<any, any, any, any>> = {\n  partitionKey: T[\"partitionKey\"][\"name\"] extends string\n    ? T[\"partitionKey\"][\"name\"]\n    : never;\n  sortKey: T[\"sortKey\"] extends infer SortKey\n    ? SortKey extends KeyDefinition\n      ? SortKey[\"name\"]\n      : never\n    : never;\n  itemType: ResolveValueType<\n    T[\"itemType\"] extends infer ItemType | undefined ? ItemType : T[\"itemType\"]\n  > extends infer ItemType\n    ? unknown extends ItemType\n      ? AccessPattern<T[\"partitionKey\"], T[\"sortKey\"]>\n      : ItemType extends undefined\n        ? AccessPattern<T[\"partitionKey\"], T[\"sortKey\"]>\n        : ItemType\n    : AccessPattern<T[\"partitionKey\"], T[\"sortKey\"]>;\n  stream: T[\"stream\"] extends infer Stream\n    ? Stream extends StreamViewType\n      ? Stream\n      : never\n    : never;\n};\n\nstaticTest(() => {\n  type p1 = MaterializeTableProps<\n    TableProps<\n      { name: \"id\"; type: AttributeType.STRING },\n      undefined,\n      { id: string },\n      undefined\n    >\n  >;\n  typeAssert<\n    IsExact<\n      p1,\n      {\n        partitionKey: \"id\";\n        sortKey: never;\n        itemType: { id: string };\n        stream: never;\n      }\n    >\n  >(true);\n\n  type p2 = MaterializeTableProps<\n    TableProps<\n      { name: \"id\"; type: AttributeType.STRING },\n      { name: \"sk\"; type: AttributeType.STRING },\n      { id: string; sk: string },\n      undefined\n    >\n  >;\n  typeAssert<\n    IsExact<\n      p2,\n      {\n        partitionKey: \"id\";\n        sortKey: \"sk\";\n        itemType: { id: string; sk: string };\n        stream: never;\n      }\n    >\n  >(true);\n\n  type p3 = MaterializeTableProps<\n    TableProps<\n      { name: \"id\"; type: AttributeType.STRING },\n      { name: \"sk\"; type: AttributeType.NUMBER },\n      { id: string; sk: number; age: number },\n      undefined\n    >\n  >;\n  typeAssert<\n    IsExact<\n      p3,\n      {\n        partitionKey: \"id\";\n        sortKey: \"sk\";\n        itemType: { id: string; sk: number; age: number };\n        stream: never;\n        // exact: true;\n      }\n    >\n  >(true);\n\n  type p4 = TableProps<\n    { name: \"id\"; type: AttributeType.STRING },\n    { name: \"sk\"; type: AttributeType.STRING },\n    // @ts-expect-error: sk is missing.\n    { id: string },\n    undefined\n  >;\n  type p5 = TableProps<\n    { name: \"id\"; type: AttributeType.STRING },\n    { name: \"sk\"; type: AttributeType.STRING },\n    // @ts-expect-error: id is missing.\n    {},\n    undefined\n  >;\n  type p6 = TableProps<\n    { name: \"id\"; type: AttributeType.STRING },\n    undefined,\n    // @ts-expect-error: id is missing.\n    {},\n    undefined\n  >;\n\n  type p7 = MaterializeTableProps<\n    TableProps<\n      { name: \"id\"; type: AttributeType.STRING },\n      undefined,\n      undefined,\n      undefined\n    >\n  >;\n  typeAssert<\n    IsExact<\n      p7,\n      {\n        partitionKey: \"id\";\n        sortKey: never;\n        itemType: { id: string };\n        stream: never;\n        // exact: false;\n      }\n    >\n  >(true);\n\n  type p8 = MaterializeTableProps<\n    TableProps<\n      { name: \"id\"; type: AttributeType.STRING },\n      { name: \"sk\"; type: AttributeType.NUMBER },\n      | { id: \"age\"; sk: number; age: number }\n      | { id: \"name\"; sk: number; name: string },\n      undefined\n    >\n  >;\n  typeAssert<\n    IsExact<\n      p8,\n      {\n        partitionKey: \"id\";\n        sortKey: \"sk\";\n        itemType:\n          | { id: \"age\"; sk: number; age: number }\n          | { id: \"name\"; sk: number; name: string };\n        stream: never;\n        // exact: true;\n      }\n    >\n  >(true);\n});\n\nexport type TableName<T extends MaterializedTableProps> = OpaqueType<string, T>;\n\n/**\n * Defines a type-safe DynamoDB table.\n *\n * @example\n * ```ts\n * type User = {\n *   pk: string;\n *   sk: number;\n * };\n * const table = new cloudy.aws_dynamodb.Table(this, \"table\", {\n *   partitionKey: {\n *     name: \"pk\",\n *     type: cloudy.AttributeType.STRING,\n *   },\n *   sortKey: {\n *     name: \"sk\",\n *     type: cloudy.AttributeType.NUMBER,\n *   },\n *   itemType: cloudy.ValueType.as<User>(),\n * });\n * ```\n */\nexport class Table<\n  // PartitionKey extends KeyDefinition = KeyDefinition,\n  PartitionKey extends KeyDefinition,\n  SortKey extends KeyDefinition | undefined = undefined,\n  ItemType extends AccessPattern<PartitionKey, SortKey> = AccessPattern<\n    PartitionKey,\n    SortKey\n  >,\n  Stream extends StreamViewType | undefined = undefined,\n  // PartitionKey extends KeyDefinition,\n  // SortKey extends KeyDefinition | undefined,\n  // ItemType extends AccessPattern<PartitionKey, SortKey>,\n  // Stream extends StreamViewType | undefined,\n> extends BaseTable {\n  /**\n   * Name of the dynamodb table.\n   *\n   * @attribute\n   */\n  public declare readonly tableName: TableName<\n    MaterializeTableProps<TableProps<PartitionKey, SortKey, ItemType, Stream>>\n  >;\n\n  public constructor(\n    scope: Construct,\n    id: string,\n    properties: F.Narrow<TableProps<PartitionKey, SortKey, ItemType, Stream>>,\n    // properties: TableProps<PartitionKey, SortKey, ItemType, Stream>,\n  ) {\n    super(scope, id, properties as unknown as BaseTableProps);\n  }\n}\n\n() => {\n  const x: ValueType<\n    AccessPattern<{ name: \"streamId\"; type: AttributeType.STRING }, undefined>\n  > = ValueType.as<{\n    streamId: string;\n    events: {\n      id: string;\n      data: string;\n      // metadata: JsonEncoded\n    }[];\n  }>();\n\n  new Table(undefined as unknown as Construct, \"Transactions\", {\n    partitionKey: {\n      name: \"streamId\",\n      type: AttributeType.STRING,\n    },\n    itemType: ValueType.as<{\n      streamId: string;\n      events: {\n        id: string;\n      }[];\n    }>(),\n  });\n\n  new Table(undefined as unknown as Construct, \"Transactions\", {\n    partitionKey: { name: \"pk\", type: AttributeType.STRING },\n    itemType: ValueType.as<\n      | {\n          pk: \"name\";\n          name: string;\n        }\n      | {\n          pk: \"age\";\n          age: number;\n        }\n    >(),\n  });\n};\n"],
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,oCAIPC,EAAoC,8CACpCC,EAA0B,iCAU1BC,EAA2B,gCA2F3B,cAAW,IAAM,IASf,cAUE,EAAI,KAUN,cAUE,EAAI,KAUN,cAWE,EAAI,KAgCN,cAWE,EAAI,KAWN,cAaE,EAAI,CACR,CAAC,EA0BM,MAAML,UAaH,EAAAM,KAAU,CAUX,YACLC,EACAC,EACAC,EAEA,CACA,MAAMF,EAAOC,EAAIC,CAAuC,CAC1D,CACF",
  "names": ["table_exports", "__export", "Table", "__toCommonJS", "import_aws_dynamodb", "import_table_conditional_type_checks", "import_value_type", "import_static_test", "BaseTable", "scope", "id", "properties"]
}
