{
  "version": 3,
  "sources": ["../../src/aws-sns/topic.ts"],
  "sourcesContent": ["import * as cdk from \"aws-cdk-lib\";\nimport { Construct } from \"constructs\";\nimport { F } from \"ts-toolbelt\";\n\nimport { ITopicSubscription } from \"./subscription.js\";\nimport { ValueType } from \"../core/value-type.js\";\nimport { OpaqueType } from \"../opaque-type/index.js\";\n\ntype MessageAttribute =\n  | {\n      DataType: \"String\" | \"Number\" | \"String.Array\";\n      StringValue: ValueType<string>;\n    }\n  | {\n      DataType: \"Binary\";\n      BinaryValue: ValueType<Uint8Array>;\n    };\n\nexport interface TopicProps extends cdk.aws_sns.TopicProps {\n  // fifo?: boolean;\n  messageType?: ValueType<string>;\n  messageGroupIdType?: ValueType<string>;\n  messageDeduplicationIdType?: ValueType<string>;\n  messageAttributesType?: {\n    [name: string]: MessageAttribute;\n  };\n}\n\nexport interface MaterializedTopicProps {\n  message: string;\n  messageGroupId: string | never;\n  messageDeduplicationId: string | never;\n  messageAttributes:\n    | {\n        [name: string]:\n          | {\n              DataType: \"String\" | \"Number\" | \"String.Array\";\n              StringValue: string;\n            }\n          | {\n              DataType: \"Binary\";\n              BinaryValue: Uint8Array;\n            };\n      }\n    | never;\n}\n\nexport type TopicArn<T extends MaterializedTopicProps> = OpaqueType<string, T>;\n\ntype RecursivelyMapValueType<T> = T extends ValueType<infer V>\n  ? V\n  : T extends { [name: string]: any }\n    ? { [name in keyof T]: RecursivelyMapValueType<T[name]> }\n    : T;\n\ntype DefaultTo<T, Default> = T extends ValueType<infer U>\n  ? unknown extends U\n    ? Default\n    : T\n  : Default;\nexport type MaterializeTopicProps<T extends TopicProps> =\n  RecursivelyMapValueType<{\n    message: DefaultTo<T[\"messageType\"], string>;\n    messageGroupId: T[\"fifo\"] extends true\n      ? DefaultTo<T[\"messageGroupIdType\"], string>\n      : never;\n    messageDeduplicationId: T[\"fifo\"] extends true\n      ? DefaultTo<T[\"messageDeduplicationIdType\"], string>\n      : never;\n    messageAttributes: T[\"messageAttributesType\"] extends {\n      [name: string]: MessageAttribute;\n    }\n      ? T[\"messageAttributesType\"]\n      : never;\n  }>;\n\nexport class Topic<T extends TopicProps = TopicProps> extends cdk.aws_sns\n  .Topic {\n  public declare readonly topicArn: TopicArn<MaterializeTopicProps<T>>;\n\n  public constructor(\n    scope: Construct,\n    id: string,\n    private readonly properties?: F.Exact<T, TopicProps>,\n  ) {\n    super(scope, id, {\n      topicName: properties?.fifo ? buildFifoName(scope, id) : undefined,\n      ...(properties as cdk.aws_sns.TopicProps),\n    });\n  }\n\n  public get messageType(): T[\"messageType\"] {\n    return this.properties?.messageType;\n  }\n\n  addSubscription(\n    // subscription: ITopicSubscription<Message> | cdk.aws_sns.ITopicSubscription,\n    // subscription: ITopicSubscription<Message>,\n    // subscription: ITopicSubscription<MapValueType<T[\"messageType\"], string>>,\n    subscription: ITopicSubscription<MaterializeTopicProps<T>[\"message\"]>,\n  ) {\n    return super.addSubscription(subscription);\n  }\n}\n\nfunction buildFifoName(construct: Construct, id: string) {\n  const uniqueId = cdk.Names.uniqueId(construct);\n  const suffix = `${id}.fifo`;\n  // Make sure that the name fits within the CFN's resource name character limit (must be between 1 and 256 characters long).\n  return `${uniqueId.slice(0, Math.max(0, 255 - suffix.length))}${suffix}`;\n}\n"],
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAqB,4BA4Ed,MAAMF,UAAiDE,EAAI,QAC/D,KAAM,CAGA,YACLC,EACAC,EACiBC,EACjB,CACA,MAAMF,EAAOC,EAAI,CACf,UAAWC,GAAY,KAAOC,EAAcH,EAAOC,CAAE,EAAI,OACzD,GAAIC,CACN,CAAC,EALgB,gBAAAA,CAMnB,CAEA,IAAW,aAAgC,CACzC,OAAO,KAAK,YAAY,WAC1B,CAEA,gBAIEE,EACA,CACA,OAAO,MAAM,gBAAgBA,CAAY,CAC3C,CACF,CAEA,SAASD,EAAcE,EAAsBJ,EAAY,CACvD,MAAMK,EAAWP,EAAI,MAAM,SAASM,CAAS,EACvCE,EAAS,GAAGN,CAAE,QAEpB,MAAO,GAAGK,EAAS,MAAM,EAAG,KAAK,IAAI,EAAG,IAAMC,EAAO,MAAM,CAAC,CAAC,GAAGA,CAAM,EACxE",
  "names": ["topic_exports", "__export", "Topic", "__toCommonJS", "cdk", "scope", "id", "properties", "buildFifoName", "subscription", "construct", "uniqueId", "suffix"]
}
