UNPKG

@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

53 lines (49 loc) • 1.86 kB
import { IsUri, isUri } from "../../../../utils/validators.mjs"; import "../../../../utils/index.mjs"; import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs"; import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs"; import { Transform, TransformationType, instanceToPlain, plainToClassFromExist, plainToInstance } from "class-transformer"; import { ValidateBy, buildMessage, isInstance, isString } from "class-validator"; //#region src/modules/vc/models/credential/W3cV2Issuer.ts /** * Represents a credential issuer. * * @see https://www.w3.org/TR/vc-data-model-2.0/#issuer */ var W3cV2Issuer = class { constructor(options) { if (options) { const { id, ...rest } = options; plainToClassFromExist(this, rest); this.id = id; } } }; __decorate([IsUri(), __decorateMetadata("design:type", String)], W3cV2Issuer.prototype, "id", void 0); function W3cV2IssuerTransformer() { return Transform(({ value, type }) => { if (type === TransformationType.PLAIN_TO_CLASS) { if (isString(value)) return value; return plainToInstance(W3cV2Issuer, value); } if (type === TransformationType.CLASS_TO_PLAIN) { if (isString(value)) return value; return instanceToPlain(value); } return value; }); } function IsW3cV2Issuer(validationOptions) { return ValidateBy({ name: "IsW3cV2Issuer", validator: { validate: (value) => { return typeof value === "string" && isUri(value) || isInstance(value, W3cV2Issuer) && isUri(value.id); }, defaultMessage: buildMessage((eachPrefix) => `${eachPrefix}$property must be an URL or a valid W3cV2Issuer instance`, validationOptions) } }, validationOptions); } //#endregion export { IsW3cV2Issuer, W3cV2Issuer, W3cV2IssuerTransformer }; //# sourceMappingURL=W3cV2Issuer.mjs.map