From 65c2d4bc814daa9a3a89f4f7b8e8c6973b8ce2f0 Mon Sep 17 00:00:00 2001 From: Mirko Mollik Date: Wed, 24 Jan 2024 14:33:28 +0100 Subject: [PATCH] refactor: generate plugin schemas as TS instead of JSON (#1315) fixes #1254 BREAKING CHANGE: The `plugin.schema.json` files are now generated as `plugin.schema.ts`. --- packages/cli/src/dev.ts | 4 ++-- packages/core-types/package.json | 5 ++--- .../src/{plugin.schema.json => plugin.schema.ts} | 8 ++++---- packages/core/package.json | 6 ++---- packages/credential-eip712/package.json | 4 +--- packages/credential-eip712/src/agent/CredentialEIP712.ts | 6 ++++-- .../src/{plugin.schema.json => plugin.schema.ts} | 2 +- packages/credential-ld/package.json | 1 - packages/credential-ld/src/action-handler.ts | 2 +- .../src/{plugin.schema.json => plugin.schema.ts} | 2 +- packages/credential-status/package.json | 1 - packages/credential-w3c/package.json | 1 - packages/credential-w3c/src/action-handler.ts | 2 +- packages/data-store-json/package.json | 1 - packages/data-store-json/src/data-store-json.ts | 2 +- packages/data-store/src/data-store-orm.ts | 2 +- packages/data-store/src/data-store.ts | 2 +- packages/did-comm/package.json | 1 - packages/did-comm/src/didcomm.ts | 2 +- .../did-comm/src/{plugin.schema.json => plugin.schema.ts} | 4 ++-- packages/did-discovery/package.json | 1 - packages/did-discovery/src/action-handler.ts | 2 +- .../src/{plugin.schema.json => plugin.schema.ts} | 2 +- packages/did-manager/src/id-manager.ts | 2 +- packages/did-resolver/src/resolver.ts | 2 +- packages/key-manager/src/key-manager.ts | 4 ++-- packages/message-handler/src/message-handler.ts | 2 +- packages/selective-disclosure/package.json | 1 - packages/selective-disclosure/src/action-handler.ts | 2 +- .../src/{plugin.schema.json => plugin.schema.ts} | 2 +- 30 files changed, 34 insertions(+), 44 deletions(-) rename packages/core-types/src/{plugin.schema.json => plugin.schema.ts} (99%) rename packages/credential-eip712/src/{plugin.schema.json => plugin.schema.ts} (99%) rename packages/credential-ld/src/{plugin.schema.json => plugin.schema.ts} (99%) rename packages/did-comm/src/{plugin.schema.json => plugin.schema.ts} (99%) rename packages/did-discovery/src/{plugin.schema.json => plugin.schema.ts} (99%) rename packages/selective-disclosure/src/{plugin.schema.json => plugin.schema.ts} (99%) diff --git a/packages/cli/src/dev.ts b/packages/cli/src/dev.ts index 27a6b2974..2da1406aa 100644 --- a/packages/cli/src/dev.ts +++ b/packages/cli/src/dev.ts @@ -95,7 +95,7 @@ dev 'package.json file containing a Veramo plugin interface config', './package.json', ) - .option('-o, --output ', 'Output file of the schema', './src/plugin.schema.json') + .option('-o, --output ', 'Output file of the schema', './src/plugin.schema.ts') .action(async (options) => { const apiExtractorJsonPath: string = resolve(options.extractorConfig) @@ -186,7 +186,7 @@ dev interfaces[pluginInterfaceName] = api } - writeFileSync(resolve(outPutPath), JSON.stringify(interfaces, null, 2)) + writeFileSync(resolve(outPutPath), `export default ${JSON.stringify(interfaces, null, 2)}`) }) dev diff --git a/packages/core-types/package.json b/packages/core-types/package.json index 4f4c2802a..bf2239ef3 100644 --- a/packages/core-types/package.json +++ b/packages/core-types/package.json @@ -8,8 +8,8 @@ "types": "./build/index.d.ts", "require": "./build/index.js", "import": "./build/index.js" - }, - "./build/plugin.schema.json": "./build/plugin.schema.json" + }, + "./build/plugin.schema": "./build/plugin.schema.js" }, "types": "build/index.d.ts", "scripts": { @@ -45,7 +45,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/core-types/src/plugin.schema.json b/packages/core-types/src/plugin.schema.ts similarity index 99% rename from packages/core-types/src/plugin.schema.json rename to packages/core-types/src/plugin.schema.ts index 81b0be3dd..73aafb0db 100644 --- a/packages/core-types/src/plugin.schema.json +++ b/packages/core-types/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "IResolver": { "components": { "schemas": { @@ -3821,7 +3821,7 @@ "save": { "type": "boolean", "description": "Optional. If set to `true`, the message will be saved using\n {@link @veramo/core-types#IDataStore.dataStoreSaveMessage | dataStoreSaveMessage } \n

", - "deprecated": "Please call {@link @veramo/core-types#IDataStore.dataStoreSaveMessage | dataStoreSaveMessage()} after\nhandling the message and determining that it must be saved." + "deprecated": "Please call {@link @veramo/core-types#IDataStore.dataStoreSaveMessage | dataStoreSaveMessage()} after\r\nhandling the message and determining that it must be saved." } }, "required": [ @@ -4225,7 +4225,7 @@ "save": { "type": "boolean", "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core-types#IDataStore | storage plugin } to be saved.", - "deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to\nsave the credential after creating it." + "deprecated": "Please call\r\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to\r\nsave the credential after creating it." }, "proofFormat": { "$ref": "#/components/schemas/ProofFormat", @@ -4439,7 +4439,7 @@ "save": { "type": "boolean", "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core-types#IDataStore | storage plugin } to be saved.

", - "deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiablePresentation |} * dataStoreSaveVerifiablePresentation()} to save the credential after creating it." + "deprecated": "Please call\r\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiablePresentation |} * dataStoreSaveVerifiablePresentation()} to save the credential after creating it." }, "challenge": { "type": "string", diff --git a/packages/core/package.json b/packages/core/package.json index f3822c2f4..81f84d4b1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -4,8 +4,7 @@ "version": "5.6.0", "main": "build/index.js", "exports": { - ".": "./build/index.js", - "./build/plugin.schema.json": "./build/plugin.schema.json" + ".": "./build/index.js" }, "types": "build/index.d.ts", "scripts": { @@ -25,8 +24,7 @@ }, "files": [ "build/**/*", - "src/**/*", - "plugin.schema.json", + "src/**/*", "README.md", "LICENSE" ], diff --git a/packages/credential-eip712/package.json b/packages/credential-eip712/package.json index 049311973..ce5ba1e80 100644 --- a/packages/credential-eip712/package.json +++ b/packages/credential-eip712/package.json @@ -4,8 +4,7 @@ "version": "5.6.0", "main": "build/index.js", "exports": { - ".": "./build/index.js", - "./build/plugin.schema.json": "./build/plugin.schema.json" + ".": "./build/index.js" }, "types": "build/index.d.ts", "scripts": { @@ -31,7 +30,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/credential-eip712/src/agent/CredentialEIP712.ts b/packages/credential-eip712/src/agent/CredentialEIP712.ts index 086be920b..3c7c06012 100644 --- a/packages/credential-eip712/src/agent/CredentialEIP712.ts +++ b/packages/credential-eip712/src/agent/CredentialEIP712.ts @@ -19,7 +19,7 @@ import { removeDIDParameters, resolveDidOrThrow, } from '@veramo/utils' -import schema from '../plugin.schema.json' assert { type: 'json' } +import schema from '../plugin.schema' import { recoverTypedSignature, SignTypedDataVersion } from '@metamask/eth-sig-util' import { @@ -356,6 +356,8 @@ export class CredentialIssuerEIP712 implements IAgentPlugin { * @internal */ async matchKeyForEIP712(k: IKey): Promise { - return intersect(k.meta?.algorithms ?? [], ['eth_signTypedData', 'EthereumEip712Signature2021']).length > 0 + return ( + intersect(k.meta?.algorithms ?? [], ['eth_signTypedData', 'EthereumEip712Signature2021']).length > 0 + ) } } diff --git a/packages/credential-eip712/src/plugin.schema.json b/packages/credential-eip712/src/plugin.schema.ts similarity index 99% rename from packages/credential-eip712/src/plugin.schema.json rename to packages/credential-eip712/src/plugin.schema.ts index b727f7301..21a547ebc 100644 --- a/packages/credential-eip712/src/plugin.schema.json +++ b/packages/credential-eip712/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "ICredentialIssuerEIP712": { "components": { "schemas": { diff --git a/packages/credential-ld/package.json b/packages/credential-ld/package.json index ff7802771..85de3fd84 100644 --- a/packages/credential-ld/package.json +++ b/packages/credential-ld/package.json @@ -46,7 +46,6 @@ "build/**/*", "src/**/*", "contexts/**/*.json", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/credential-ld/src/action-handler.ts b/packages/credential-ld/src/action-handler.ts index f7b788576..1de36723e 100644 --- a/packages/credential-ld/src/action-handler.ts +++ b/packages/credential-ld/src/action-handler.ts @@ -10,7 +10,7 @@ import { VerifiablePresentation, } from '@veramo/core-types' import { VeramoLdSignature } from './index.js' -import schema from './plugin.schema.json' assert { type: 'json' } +import schema from './plugin.schema.js' import Debug from 'debug' import { LdContextLoader } from './ld-context-loader.js' import { diff --git a/packages/credential-ld/src/plugin.schema.json b/packages/credential-ld/src/plugin.schema.ts similarity index 99% rename from packages/credential-ld/src/plugin.schema.json rename to packages/credential-ld/src/plugin.schema.ts index cec6cf026..bdeae9361 100644 --- a/packages/credential-ld/src/plugin.schema.json +++ b/packages/credential-ld/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "ICredentialIssuerLD": { "components": { "schemas": { diff --git a/packages/credential-status/package.json b/packages/credential-status/package.json index f47d37e34..0cfae1f20 100644 --- a/packages/credential-status/package.json +++ b/packages/credential-status/package.json @@ -23,7 +23,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/credential-w3c/package.json b/packages/credential-w3c/package.json index 530873f85..b3be34308 100644 --- a/packages/credential-w3c/package.json +++ b/packages/credential-w3c/package.json @@ -34,7 +34,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/credential-w3c/src/action-handler.ts b/packages/credential-w3c/src/action-handler.ts index 8866c5de5..42bd99148 100644 --- a/packages/credential-w3c/src/action-handler.ts +++ b/packages/credential-w3c/src/action-handler.ts @@ -20,7 +20,7 @@ import { W3CVerifiablePresentation, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { createVerifiableCredentialJwt, diff --git a/packages/data-store-json/package.json b/packages/data-store-json/package.json index 05d37c23d..335da2d88 100644 --- a/packages/data-store-json/package.json +++ b/packages/data-store-json/package.json @@ -28,7 +28,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/data-store-json/src/data-store-json.ts b/packages/data-store-json/src/data-store-json.ts index 0aa92ac46..2a91c4cc1 100644 --- a/packages/data-store-json/src/data-store-json.ts +++ b/packages/data-store-json/src/data-store-json.ts @@ -25,7 +25,7 @@ import { VerifiablePresentation, W3CVerifiableCredential, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { asArray, computeEntryHash, extractIssuer } from '@veramo/utils' import { deserialize, serialize } from '@ungap/structured-clone' import { diff --git a/packages/data-store/src/data-store-orm.ts b/packages/data-store/src/data-store-orm.ts index 959b98704..2fd13f5f2 100644 --- a/packages/data-store/src/data-store-orm.ts +++ b/packages/data-store/src/data-store-orm.ts @@ -15,7 +15,7 @@ import { UniqueVerifiablePresentation, Where, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { createMessage, Message } from './entities/message.js' import { Claim } from './entities/claim.js' import { Credential } from './entities/credential.js' diff --git a/packages/data-store/src/data-store.ts b/packages/data-store/src/data-store.ts index 845797910..d35ae1e83 100644 --- a/packages/data-store/src/data-store.ts +++ b/packages/data-store/src/data-store.ts @@ -13,7 +13,7 @@ import { VerifiableCredential, VerifiablePresentation, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { createMessage, createMessageEntity, Message } from './entities/message.js' import { createCredentialEntity, Credential } from './entities/credential.js' import { Claim } from './entities/claim.js' diff --git a/packages/did-comm/package.json b/packages/did-comm/package.json index d8ded8c2f..edcae018c 100644 --- a/packages/did-comm/package.json +++ b/packages/did-comm/package.json @@ -45,7 +45,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/did-comm/src/didcomm.ts b/packages/did-comm/src/didcomm.ts index 4d7ca5467..7e36bff5a 100644 --- a/packages/did-comm/src/didcomm.ts +++ b/packages/did-comm/src/didcomm.ts @@ -54,7 +54,7 @@ import { xc20pAuthEncrypterEcdh1PuV3x25519WithXC20PKW, } from './encryption/xc20pkw-encrypters.js' -import schema from './plugin.schema.json' assert { type: 'json' } +import schema from './plugin.schema.js' import { v4 as uuidv4 } from 'uuid' diff --git a/packages/did-comm/src/plugin.schema.json b/packages/did-comm/src/plugin.schema.ts similarity index 99% rename from packages/did-comm/src/plugin.schema.json rename to packages/did-comm/src/plugin.schema.ts index 7af1fa346..cbe41178a 100644 --- a/packages/did-comm/src/plugin.schema.json +++ b/packages/did-comm/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "IDIDComm": { "components": { "schemas": { @@ -660,7 +660,7 @@ "required": [ "data" ], - "deprecated": "Please use {@link IDIDComm.sendDIDCommMessage } instead. This will be removed in Veramo 4.0.\nInput arguments for {@link IDIDComm.sendMessageDIDCommAlpha1 }" + "deprecated": "Please use {@link IDIDComm.sendDIDCommMessage } instead. This will be removed in Veramo 4.0.\r\nInput arguments for {@link IDIDComm.sendMessageDIDCommAlpha1 }" }, "IUnpackDIDCommMessageArgs": { "$ref": "#/components/schemas/IPackedDIDCommMessage", diff --git a/packages/did-discovery/package.json b/packages/did-discovery/package.json index f8e1ce661..f2389b750 100644 --- a/packages/did-discovery/package.json +++ b/packages/did-discovery/package.json @@ -28,7 +28,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/did-discovery/src/action-handler.ts b/packages/did-discovery/src/action-handler.ts index 1f6c1c016..2b47ff718 100644 --- a/packages/did-discovery/src/action-handler.ts +++ b/packages/did-discovery/src/action-handler.ts @@ -7,7 +7,7 @@ import { IDIDDiscoveryDiscoverDidResult, } from './types' import { AbstractDidDiscoveryProvider } from './abstract-did-discovery-provider.js' -import schema from './plugin.schema.json' assert { type: 'json' } +import schema from './plugin.schema.js' import Debug from 'debug' const debug = Debug('veramo:did-discovery') diff --git a/packages/did-discovery/src/plugin.schema.json b/packages/did-discovery/src/plugin.schema.ts similarity index 99% rename from packages/did-discovery/src/plugin.schema.json rename to packages/did-discovery/src/plugin.schema.ts index abc8aadcd..a5b5f4d07 100644 --- a/packages/did-discovery/src/plugin.schema.json +++ b/packages/did-discovery/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "IDIDDiscovery": { "components": { "schemas": { diff --git a/packages/did-manager/src/id-manager.ts b/packages/did-manager/src/id-manager.ts index 116b5e303..d9a64d9cc 100644 --- a/packages/did-manager/src/id-manager.ts +++ b/packages/did-manager/src/id-manager.ts @@ -21,7 +21,7 @@ import { IKey, IService, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { AbstractDIDStore } from './abstract-identifier-store.js' /** diff --git a/packages/did-resolver/src/resolver.ts b/packages/did-resolver/src/resolver.ts index 9e6af2c66..7a384a2ed 100644 --- a/packages/did-resolver/src/resolver.ts +++ b/packages/did-resolver/src/resolver.ts @@ -1,5 +1,5 @@ import { DIDDocumentSection, IAgentPlugin, IResolver } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { isDefined } from '@veramo/utils' import { DIDDocument, diff --git a/packages/key-manager/src/key-manager.ts b/packages/key-manager/src/key-manager.ts index 21088ff3b..dbf311ec9 100644 --- a/packages/key-manager/src/key-manager.ts +++ b/packages/key-manager/src/key-manager.ts @@ -17,12 +17,12 @@ import { MinimalImportableKey, TKeyType, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import * as u8a from 'uint8arrays' import { createAnonDecrypter, createAnonEncrypter, createJWE, decryptJWE, type ECDH, type JWE } from 'did-jwt' import { convertEd25519PublicKeyToX25519 } from '@veramo/utils' import Debug from 'debug' -import {getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction} from "ethers"; +import { getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction } from 'ethers' const debug = Debug('veramo:key-manager') diff --git a/packages/message-handler/src/message-handler.ts b/packages/message-handler/src/message-handler.ts index 207d07b08..4f68386cc 100644 --- a/packages/message-handler/src/message-handler.ts +++ b/packages/message-handler/src/message-handler.ts @@ -7,7 +7,7 @@ import { CoreEvents, IMessage, } from '@veramo/core-types' -import schema from '@veramo/core-types/build/plugin.schema.json' assert { type: 'json' } +import schema from '@veramo/core-types/build/plugin.schema' import { Message } from './message.js' import { AbstractMessageHandler } from './abstract-message-handler.js' diff --git a/packages/selective-disclosure/package.json b/packages/selective-disclosure/package.json index 457654994..4fe327116 100644 --- a/packages/selective-disclosure/package.json +++ b/packages/selective-disclosure/package.json @@ -33,7 +33,6 @@ "files": [ "build/**/*", "src/**/*", - "plugin.schema.json", "README.md", "LICENSE" ], diff --git a/packages/selective-disclosure/src/action-handler.ts b/packages/selective-disclosure/src/action-handler.ts index c9c978753..345c1305b 100644 --- a/packages/selective-disclosure/src/action-handler.ts +++ b/packages/selective-disclosure/src/action-handler.ts @@ -24,7 +24,7 @@ import { ISelectiveDisclosureRequest, IValidatePresentationAgainstSdrArgs, } from './types.js' -import schema from './plugin.schema.json' assert { type: 'json' } +import schema from './plugin.schema.js' import { createJWT } from 'did-jwt' import Debug from 'debug' import { diff --git a/packages/selective-disclosure/src/plugin.schema.json b/packages/selective-disclosure/src/plugin.schema.ts similarity index 99% rename from packages/selective-disclosure/src/plugin.schema.json rename to packages/selective-disclosure/src/plugin.schema.ts index 8e74ca6e2..8ae652925 100644 --- a/packages/selective-disclosure/src/plugin.schema.json +++ b/packages/selective-disclosure/src/plugin.schema.ts @@ -1,4 +1,4 @@ -{ +export default { "ISelectiveDisclosure": { "components": { "schemas": {