Skip to content

Commit

Permalink
refactor: generate plugin schemas as TS instead of JSON (#1315)
Browse files Browse the repository at this point in the history
fixes #1254

BREAKING CHANGE: The `plugin.schema.json` files are now generated as `plugin.schema.ts`.
  • Loading branch information
cre8 committed Jan 24, 2024
1 parent 610ee66 commit 65c2d4b
Show file tree
Hide file tree
Showing 30 changed files with 34 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dev
'package.json file containing a Veramo plugin interface config',
'./package.json',
)
.option('-o, --output <string>', 'Output file of the schema', './src/plugin.schema.json')
.option('-o, --output <string>', 'Output file of the schema', './src/plugin.schema.ts')

.action(async (options) => {
const apiExtractorJsonPath: string = resolve(options.extractorConfig)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/core-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -45,7 +45,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"IResolver": {
"components": {
"schemas": {
Expand Down Expand Up @@ -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<p/><p/>",
"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": [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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. <p/><p/>",
"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",
Expand Down
6 changes: 2 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -25,8 +24,7 @@
},
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"src/**/*",
"README.md",
"LICENSE"
],
Expand Down
4 changes: 1 addition & 3 deletions packages/credential-eip712/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,7 +30,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
6 changes: 4 additions & 2 deletions packages/credential-eip712/src/agent/CredentialEIP712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -356,6 +356,8 @@ export class CredentialIssuerEIP712 implements IAgentPlugin {
* @internal
*/
async matchKeyForEIP712(k: IKey): Promise<boolean> {
return intersect(k.meta?.algorithms ?? [], ['eth_signTypedData', 'EthereumEip712Signature2021']).length > 0
return (
intersect(k.meta?.algorithms ?? [], ['eth_signTypedData', 'EthereumEip712Signature2021']).length > 0
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"ICredentialIssuerEIP712": {
"components": {
"schemas": {
Expand Down
1 change: 0 additions & 1 deletion packages/credential-ld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"build/**/*",
"src/**/*",
"contexts/**/*.json",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-ld/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"ICredentialIssuerLD": {
"components": {
"schemas": {
Expand Down
1 change: 0 additions & 1 deletion packages/credential-status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
1 change: 0 additions & 1 deletion packages/credential-w3c/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-w3c/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/data-store-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store-json/src/data-store-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store/src/data-store-orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion packages/did-comm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/did-comm/src/didcomm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"IDIDComm": {
"components": {
"schemas": {
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/did-discovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/did-discovery/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"IDIDDiscovery": {
"components": {
"schemas": {
Expand Down
2 changes: 1 addition & 1 deletion packages/did-manager/src/id-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/did-resolver/src/resolver.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/key-manager/src/key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion packages/message-handler/src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 0 additions & 1 deletion packages/selective-disclosure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/selective-disclosure/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export default {
"ISelectiveDisclosure": {
"components": {
"schemas": {
Expand Down

0 comments on commit 65c2d4b

Please sign in to comment.