{"version":3,"file":"ServiceTransformer.mjs","names":[],"sources":["../../../../../src/modules/dids/domain/service/ServiceTransformer.ts"],"sourcesContent":["import type { ClassConstructor } from 'class-transformer'\n\nimport { Transform } from 'class-transformer'\n\nimport { JsonTransformer } from '../../../../utils'\n\nimport { DidCommV1Service } from './DidCommV1Service'\nimport { DidCommV2Service } from './DidCommV2Service'\nimport { DidDocumentService } from './DidDocumentService'\nimport { IndyAgentService } from './IndyAgentService'\nimport { LegacyDidCommV2Service } from './LegacyDidCommV2Service'\n\nexport const serviceTypes: { [key: string]: unknown | undefined } = {\n  [IndyAgentService.type]: IndyAgentService,\n  [DidCommV1Service.type]: DidCommV1Service,\n  [DidCommV2Service.type]: DidCommV2Service,\n  [LegacyDidCommV2Service.type]: LegacyDidCommV2Service,\n}\n\n/**\n * Decorator that transforms service json to corresponding class instances. See {@link serviceTypes}\n *\n * @example\n * class Example {\n *   ServiceTransformer()\n *   private service: Service\n * }\n */\nexport function ServiceTransformer() {\n  return Transform(\n    ({ value }: { value?: Array<{ type: string }> }) => {\n      return value?.map((serviceJson) => {\n        let serviceClass = (serviceTypes[serviceJson.type] ??\n          DidDocumentService) as ClassConstructor<DidDocumentService>\n\n        // NOTE: deal with `DIDCommMessaging` type but using `serviceEndpoint` string value, parse it using the\n        // legacy class type\n        if (\n          serviceJson.type === DidCommV2Service.type &&\n          'serviceEndpoint' in serviceJson &&\n          typeof serviceJson.serviceEndpoint === 'string'\n        ) {\n          serviceClass = LegacyDidCommV2Service\n        }\n\n        const service = JsonTransformer.fromJSON(serviceJson, serviceClass)\n\n        return service\n      })\n    },\n    {\n      toClassOnly: true,\n    }\n  )\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,eAAuD;EACjE,iBAAiB,OAAO;EACxB,iBAAiB,OAAO;EACxB,iBAAiB,OAAO;EACxB,uBAAuB,OAAO;CAChC;;;;;;;;;;AAWD,SAAgB,qBAAqB;AACnC,QAAO,WACJ,EAAE,YAAiD;AAClD,SAAO,OAAO,KAAK,gBAAgB;GACjC,IAAI,eAAgB,aAAa,YAAY,SAC3C;AAIF,OACE,YAAY,SAAS,iBAAiB,QACtC,qBAAqB,eACrB,OAAO,YAAY,oBAAoB,SAEvC,gBAAe;AAKjB,UAFgB,gBAAgB,SAAS,aAAa,aAAa;IAGnE;IAEJ,EACE,aAAa,MACd,CACF"}