{
  "version": 3,
  "sources": ["../../../../src/tables/templates/read-item.ts"],
  "sourcesContent": ["import type {Model} from '@code-like-a-carpenter/foundation-intermediate-representation';\n\nimport type {Config} from '../../config.ts';\n\nimport {ensureTableTemplate} from './ensure-table.ts';\nimport {handleCommonErrors, makeKeyForRead, objectToString} from './helpers.ts';\n\n/**\n * Generates the readItem function for a table\n */\nexport function readItemTemplate(config: Config, model: Model) {\n  const {\n    consistent,\n    primaryKey,\n    table: {tableName},\n    typeName,\n  } = model;\n  const key = makeKeyForRead(config, primaryKey);\n\n  const outputTypeName = `Read${typeName}Output`;\n  const primaryKeyType = `${typeName}PrimaryKey`;\n\n  return `\nexport type ${outputTypeName} = ResultType<${typeName}>;\n\n/**  */\nexport async function read${typeName}(input: ${primaryKeyType}): Promise<Readonly<${outputTypeName}>> {\n${ensureTableTemplate(tableName)}\n\n  const commandInput: GetCommandInput = {\n    ConsistentRead: ${consistent},\n    Key: ${objectToString(key)},\n    ReturnConsumedCapacity: 'INDEXES',\n    TableName: tableName,\n  };\n\n  try {\n    const {ConsumedCapacity: capacity, Item: item} = await ddbDocClient.send(new GetCommand(commandInput));\n\n    assert(capacity, 'Expected ConsumedCapacity to be returned. This is a bug in codegen.');\n\n    assert(item, () => new NotFoundError('${typeName}', input));\n    assert(item._et === '${typeName}', () => new DataIntegrityError(\\`Expected \\${JSON.stringify(input)} to load a ${typeName} but loaded \\${item._et} instead\\`));\n\n    return {\n      capacity,\n      item: unmarshall${typeName}(item),\n      metrics: undefined,\n    }\n  }\n  catch (err) {\n    ${handleCommonErrors()}\n  }\n}`;\n}\n"],
  "mappings": ";AAIA,SAAQ,2BAA0B;AAClC,SAAQ,oBAAoB,gBAAgB,sBAAqB;AAK1D,SAAS,iBAAiB,QAAgB,OAAc;AAC7D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,OAAO,EAAC,UAAS;AAAA,IACjB;AAAA,EACF,IAAI;AACJ,QAAM,MAAM,eAAe,QAAQ,UAAU;AAE7C,QAAM,iBAAiB,OAAO,QAAQ;AACtC,QAAM,iBAAiB,GAAG,QAAQ;AAElC,SAAO;AAAA,cACK,cAAc,iBAAiB,QAAQ;AAAA;AAAA;AAAA,4BAGzB,QAAQ,WAAW,cAAc,uBAAuB,cAAc;AAAA,EAChG,oBAAoB,SAAS,CAAC;AAAA;AAAA;AAAA,sBAGV,UAAU;AAAA,WACrB,eAAe,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4CAUc,QAAQ;AAAA,2BACzB,QAAQ,kFAAkF,QAAQ;AAAA;AAAA;AAAA;AAAA,wBAIrG,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,MAK1B,mBAAmB,CAAC;AAAA;AAAA;AAG1B;",
  "names": []
}
