{
  "version": 3,
  "sources": ["../../../../src/tables/templates/delete-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 deleteItem function for a table\n */\nexport function deleteItemTemplate(config: Config, model: Model) {\n  const {\n    table: {tableName},\n    typeName,\n  } = model;\n  const key = makeKeyForRead(config, model.primaryKey);\n\n  const outputTypeName = `Delete${typeName}Output`;\n  const primaryKeyType = `${typeName}PrimaryKey`;\n\n  return `\nexport type ${outputTypeName} = ResultType<void>;\n\n/**  */\nexport async function delete${typeName}(input: ${primaryKeyType}): Promise<${outputTypeName}> {\n${ensureTableTemplate(tableName)}\n\n  try {\n    const commandInput: DeleteCommandInput = {\n      ConditionExpression: 'attribute_exists(#pk)',\n      ExpressionAttributeNames: {\n        \"#pk\": \"pk\",\n      },\n      Key: ${objectToString(key)},\n      ReturnConsumedCapacity: 'INDEXES',\n      ReturnItemCollectionMetrics: 'SIZE',\n      ReturnValues: 'NONE',\n      TableName: tableName,\n    };\n\n    const {ConsumedCapacity: capacity, ItemCollectionMetrics: metrics} = await ddbDocClient.send(new DeleteCommand(commandInput));\n\n    assert(capacity, 'Expected ConsumedCapacity to be returned. This is a bug in codegen.');\n\n    return {\n      capacity,\n      item: undefined,\n      metrics,\n    }\n  }\n  catch (err) {\n    if (err instanceof ConditionalCheckFailedException) {\n      throw new NotFoundError('${typeName}', input);\n    }\n    ${handleCommonErrors()}\n  }\n}\n`;\n}\n"],
  "mappings": ";AAIA,SAAQ,2BAA0B;AAClC,SAAQ,oBAAoB,gBAAgB,sBAAqB;AAK1D,SAAS,mBAAmB,QAAgB,OAAc;AAC/D,QAAM;AAAA,IACJ,OAAO,EAAC,UAAS;AAAA,IACjB;AAAA,EACF,IAAI;AACJ,QAAM,MAAM,eAAe,QAAQ,MAAM,UAAU;AAEnD,QAAM,iBAAiB,SAAS,QAAQ;AACxC,QAAM,iBAAiB,GAAG,QAAQ;AAElC,SAAO;AAAA,cACK,cAAc;AAAA;AAAA;AAAA,8BAGE,QAAQ,WAAW,cAAc,cAAc,cAAc;AAAA,EACzF,oBAAoB,SAAS,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAQnB,eAAe,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAmBC,QAAQ;AAAA;AAAA,MAEnC,mBAAmB,CAAC;AAAA;AAAA;AAAA;AAI1B;",
  "names": []
}
