@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 2.34 kB
Source Map (JSON)
{"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"}