{
  "version": 3,
  "sources": ["../../../../src/tables/templates/indexes.ts"],
  "sourcesContent": ["import type {\n  PrimaryKeyConfig,\n  SecondaryIndex,\n} from '@code-like-a-carpenter/foundation-intermediate-representation';\n\nimport type {Config} from '../../config.ts';\n\nimport {makeKeyTemplate} from './helpers.ts';\n\n/** Indicates if an index contains a particular field name */\nexport function indexHasField(\n  name: string,\n  primaryKey: PrimaryKeyConfig,\n  index: SecondaryIndex\n) {\n  if (index.type === 'lsi') {\n    return (\n      primaryKey.partitionKeyFields.some((field) => field.fieldName === name) ||\n      index.sortKeyFields.some((field) => field.fieldName === name)\n    );\n  }\n\n  if (index.isComposite) {\n    return (\n      index.partitionKeyFields.some((field) => field.fieldName === name) ||\n      index.sortKeyFields.some((field) => field.fieldName === name)\n    );\n  }\n\n  return index.partitionKeyFields.some((field) => field.fieldName === name);\n}\n\nexport function indexToUpdateExpressionPart(index: SecondaryIndex) {\n  const fields = [];\n  const {type} = index;\n  if (type === 'gsi') {\n    const {isComposite} = index;\n    if (index.name !== index.partitionKeyName) {\n      fields.push(index.partitionKeyName);\n    }\n    if (isComposite) {\n      if (index.name !== index.sortKeyName) {\n        fields.push(index.sortKeyName);\n      }\n    }\n  }\n  if (type === 'lsi') {\n    if (index.name !== index.sortKeyName) {\n      fields.push(index.sortKeyName);\n    }\n  }\n  return fields.map((field) => `'#${field} = :${field}',`);\n}\n\nexport function indexToEAVPart(\n  mode: 'blind' | 'create' | 'read',\n  index: SecondaryIndex\n) {\n  const fields = [];\n  const {type} = index;\n  if (type === 'gsi') {\n    const {isComposite} = index;\n    if (index.name !== index.partitionKeyName) {\n      fields.push(\n        `':${index.partitionKeyName}': ${makeKeyTemplate(\n          index.partitionKeyPrefix,\n          index.partitionKeyFields,\n          mode\n        )},`\n      );\n    }\n    if (isComposite) {\n      if (index.name !== index.sortKeyName) {\n        fields.push(\n          `':${index.sortKeyName}': ${makeKeyTemplate(\n            index.sortKeyPrefix,\n            index.sortKeyFields,\n            mode\n          )},`\n        );\n      }\n    }\n  }\n\n  if (type === 'lsi') {\n    fields.push(\n      `':${index.sortKeyName}': ${makeKeyTemplate(\n        index.sortKeyPrefix,\n        index.sortKeyFields,\n        mode\n      )},`\n    );\n  }\n  return fields;\n}\n\nexport function indexToEANPart(config: Config, index: SecondaryIndex) {\n  const fields = [];\n  const {type} = index;\n  if (type === 'gsi') {\n    const {isComposite} = index;\n    if (index.name !== index.partitionKeyName) {\n      fields.push(index.partitionKeyName);\n    }\n    if (isComposite) {\n      if (index.name !== index.sortKeyName) {\n        fields.push(index.sortKeyName);\n      }\n    }\n  }\n  if (type === 'lsi') {\n    if (index.name !== index.sortKeyName) {\n      fields.push(index.sortKeyName);\n    }\n  }\n  return fields.map((field) => `'#${field}': '${field}',`);\n}\n"],
  "mappings": ";AAOA,SAAQ,uBAAsB;AAGvB,SAAS,cACd,MACA,YACA,OACA;AACA,MAAI,MAAM,SAAS,OAAO;AACxB,WACE,WAAW,mBAAmB,KAAK,CAAC,UAAU,MAAM,cAAc,IAAI,KACtE,MAAM,cAAc,KAAK,CAAC,UAAU,MAAM,cAAc,IAAI;AAAA,EAEhE;AAEA,MAAI,MAAM,aAAa;AACrB,WACE,MAAM,mBAAmB,KAAK,CAAC,UAAU,MAAM,cAAc,IAAI,KACjE,MAAM,cAAc,KAAK,CAAC,UAAU,MAAM,cAAc,IAAI;AAAA,EAEhE;AAEA,SAAO,MAAM,mBAAmB,KAAK,CAAC,UAAU,MAAM,cAAc,IAAI;AAC1E;AAEO,SAAS,4BAA4B,OAAuB;AACjE,QAAM,SAAS,CAAC;AAChB,QAAM,EAAC,KAAI,IAAI;AACf,MAAI,SAAS,OAAO;AAClB,UAAM,EAAC,YAAW,IAAI;AACtB,QAAI,MAAM,SAAS,MAAM,kBAAkB;AACzC,aAAO,KAAK,MAAM,gBAAgB;AAAA,IACpC;AACA,QAAI,aAAa;AACf,UAAI,MAAM,SAAS,MAAM,aAAa;AACpC,eAAO,KAAK,MAAM,WAAW;AAAA,MAC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