@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 • 4.43 kB
Source Map (JSON)
{"version":3,"file":"BaseRecord.mjs","names":[],"sources":["../../src/storage/BaseRecord.ts"],"sourcesContent":["import { Exclude } from 'class-transformer'\n\nimport { JsonTransformer } from '../utils/JsonTransformer'\nimport { DateTransformer, MetadataTransformer } from '../utils/transformers'\n\nimport { Metadata } from './Metadata'\n\nexport type TagValue = string | boolean | undefined | Array<string> | null\nexport type TagsBase = {\n [key: string]: TagValue\n [key: number]: never\n}\n\nexport type Tags<DefaultTags extends TagsBase, CustomTags extends TagsBase> = CustomTags & DefaultTags\n\nexport type RecordTags<Record extends BaseRecord> = ReturnType<Record['getTags']>\n\n// The BaseRecord requires a DefaultTags and CustomTags type, but we want to be\n// able to use the BaseRecord without specifying these types. If we don't specify\n// these types, the default TagsBase will be used, but this is not compatible\n// with records that have specified a custom type.\n// biome-ignore lint/suspicious/noExplicitAny: no explanation\nexport type BaseRecordAny = BaseRecord<any, any, any>\n\nexport abstract class BaseRecord<\n DefaultTags extends TagsBase = TagsBase,\n CustomTags extends TagsBase = TagsBase,\n // We want an empty object, as Record<string, unknown> will make typescript\n // not infer the types correctly\n // biome-ignore lint/complexity/noBannedTypes: no explanation\n MetadataValues = {},\n> {\n protected _tags: CustomTags & TagsBase = {} as CustomTags & TagsBase\n\n public id!: string\n\n @DateTransformer()\n public createdAt!: Date\n\n @DateTransformer()\n public updatedAt?: Date\n\n @Exclude()\n public readonly type = BaseRecord.type\n public static readonly type: string = 'BaseRecord'\n\n @Exclude()\n public readonly allowCache = BaseRecord.allowCache\n public static readonly allowCache: boolean = false\n\n /** @inheritdoc {Metadata#Metadata} */\n @MetadataTransformer()\n public metadata: Metadata<MetadataValues> = new Metadata({})\n\n /**\n * Get all tags. This is includes custom and default tags\n * @returns tags object\n */\n public abstract getTags(): Tags<DefaultTags, CustomTags>\n\n /**\n * Set the value for a tag\n * @param name name of the tag\n * @param value value of the tag\n */\n public setTag(name: keyof CustomTags | (string & {}), value: CustomTags[keyof CustomTags]) {\n this._tags[name] = value as (typeof this._tags)[string]\n }\n\n /**\n * Get the value for a tag\n * @param name name of the tag\n * @returns The tag value, or undefined if not found\n */\n public getTag(name: keyof CustomTags | keyof DefaultTags | (string & {})) {\n return this.getTags()[name]\n }\n\n /**\n * Set custom tags. This will merge the tags object with passed in tag properties\n *\n * @param tags the tags to set\n */\n public setTags(tags: Partial<CustomTags | TagsBase>) {\n this._tags = {\n ...this._tags,\n ...tags,\n } as typeof this._tags\n }\n\n /**\n * Replace tags. This will replace the whole tags object.\n * Default tags will still be overridden when retrieving tags\n *\n * @param tags the tags to set\n */\n public replaceTags(tags: CustomTags & Partial<TagsBase>) {\n this._tags = tags\n }\n\n public toJSON(): Record<string, unknown> {\n return JsonTransformer.toJSON(this)\n }\n\n /**\n * Clones the record.\n */\n public clone() {\n return JsonTransformer.clone(this)\n }\n}\n"],"mappings":";;;;;;;AAwBA,IAAsB,aAAtB,MAAsB,WAOpB;;EACA,KAAU,QAA+B,CAAC;EAU1C,KACgB,OAAO,WAAW;EAGlC,KACgB,aAAa,WAAW;EAIxC,KACO,WAAqC,IAAI,SAAS,CAAC,CAAC;;;;;;;CAa3D,OAAc,MAAwC,OAAqC;EACzF,KAAK,MAAM,QAAQ;CACrB;;;;;;CAOA,OAAc,MAA4D;EACxE,OAAO,KAAK,QAAQ,CAAC,CAAC;CACxB;;;;;;CAOA,QAAe,MAAsC;EACnD,KAAK,QAAQ;GACX,GAAG,KAAK;GACR,GAAG;EACL;CACF;;;;;;;CAQA,YAAmB,MAAsC;EACvD,KAAK,QAAQ;CACf;CAEA,SAAyC;EACvC,OAAO,gBAAgB,OAAO,IAAI;CACpC;;;;CAKA,QAAe;EACb,OAAO,gBAAgB,MAAM,IAAI;CACnC;AACF;AAlEE,WAAuB,OAAe;AAItC,WAAuB,aAAsB;AAZ5C,WAAA,CAAA,gBAAgB,GAAA,mBAAA,eAAA,OAAA,SAAA,cAAA,SAAA,IAAA,CAAA,GAAA,WAAA,WAAA,aAAA,KAAA,CAAA;AAGhB,WAAA,CAAA,gBAAgB,GAAA,mBAAA,eAAA,OAAA,SAAA,cAAA,SAAA,IAAA,CAAA,GAAA,WAAA,WAAA,aAAA,KAAA,CAAA;AAGhB,WAAA,CAAA,QAAQ,GAAA,mBAAA,eAAA,MAAA,CAAA,GAAA,WAAA,WAAA,QAAA,KAAA,CAAA;AAIR,WAAA,CAAA,QAAQ,GAAA,mBAAA,eAAA,MAAA,CAAA,GAAA,WAAA,WAAA,cAAA,KAAA,CAAA;AAKR,WAAA,CAAA,oBAAoB,GAAA,mBAAA,eAAA,OAAA,aAAA,cAAA,SAAA,QAAA,CAAA,GAAA,WAAA,WAAA,YAAA,KAAA,CAAA"}