Skip to content

Commit

Permalink
feat: Generating plugin schema
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored and mirceanis committed Nov 23, 2020
1 parent bf1466b commit dc80083
Show file tree
Hide file tree
Showing 42 changed files with 3,812 additions and 3,936 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "daf",
"private": true,
"scripts": {
"build": "yarn lerna run build && yarn extract-api && yarn create-plugin-credential && yarn docs:api && yarn docs:examples && yarn docs:clean-temp && yarn prettier:examples",
"build": "yarn lerna run build && yarn extract-api && yarn generate-plugin-schema && yarn docs:api && yarn docs:examples && yarn docs:clean-temp && yarn prettier:examples",
"publish": "lerna publish",
"bootstrap": "lerna bootstrap",
"extract-api": "lerna run extract-api",
"create-plugin-credential": "lerna run create-plugin-credential",
"generate-plugin-schema": "lerna run generate-plugin-schema",
"docs:examples": "ts-node --project packages/tsconfig.settings.json ./scripts/extract-examples.ts",
"docs:api": "ts-node ./scripts/generate-docs.ts",
"docs:reference": "api-documenter markdown -i ./temp -o ./docs/api",
Expand Down
39 changes: 5 additions & 34 deletions packages/daf-cli/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,16 @@ function getReference(response: string): OpenAPIV3.ReferenceObject | OpenAPIV3.S
}

program
.command('create-plugin-credential')
.description('Create plugin credential')
.command('generate-plugin-schema')
.description('Generate plugin schema')
.option('-c, --extractorConfig <string>', 'API Extractor config file', './api-extractor.json')
.option(
'-p, --packageConfig <string>',
'package.json file containing DAF plugin interface config',
'./package.json',
)
.option('-i, --issuer <string>', 'Schema credential issuer')

.action(async (options) => {
const agent = getAgent(program.config)

const apiExtractorJsonPath: string = resolve(options.extractorConfig)
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath)

Expand All @@ -114,9 +111,7 @@ program
}

const packageConfig = require(resolve(options.packageConfig))
const credentialSubject: any = {
interfaces: {},
}
const interfaces: any = {}

for (const pluginInterfaceName in packageConfig.daf.pluginInterfaces) {
const entryFile = packageConfig.daf.pluginInterfaces[pluginInterfaceName]
Expand Down Expand Up @@ -182,34 +177,10 @@ program
}
}

credentialSubject.interfaces[pluginInterfaceName] = api
}

let issuer: IIdentity
if (options.did) {
issuer = await agent.identityManagerGetIdentity({ did: options.did })
if (!issuer) {
throw Error('DID not found ' + options.did)
}
} else {
issuer = await agent.identityManagerGetOrCreateIdentity({
alias: 'default',
})
interfaces[pluginInterfaceName] = api
}

const verifiableCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: issuer.did },
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential', 'AgentPluginSchema'],
issuanceDate: new Date().toISOString(),
credentialSubject,
},
proofFormat: 'jwt',
save: true,
})

writeFileSync(resolve('./plugin.credential.json'), JSON.stringify(verifiableCredential, null, 2))
writeFileSync(resolve('./plugin.schema.json'), JSON.stringify(interfaces, null, 2))
})

program
Expand Down
42 changes: 21 additions & 21 deletions packages/daf-core/api/daf-core.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5862,27 +5862,6 @@
],
"extendsTokenRanges": []
},
{
"kind": "Variable",
"canonicalReference": "daf-core!pluginCredential:var",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "pluginCredential: "
},
{
"kind": "Content",
"text": "any"
}
],
"releaseTag": "Public",
"name": "pluginCredential",
"variableTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
}
},
{
"kind": "Interface",
"canonicalReference": "daf-core!RemoveContext:interface",
Expand Down Expand Up @@ -6014,6 +5993,27 @@
],
"extendsTokenRanges": []
},
{
"kind": "Variable",
"canonicalReference": "daf-core!schema:var",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "schema: "
},
{
"kind": "Content",
"text": "any"
}
],
"releaseTag": "Public",
"name": "schema",
"variableTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
}
},
{
"kind": "TypeAlias",
"canonicalReference": "daf-core!TAgent:type",
Expand Down
6 changes: 3 additions & 3 deletions packages/daf-core/api/daf-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ export interface IService {
type: string;
}

// @public (undocumented)
export const pluginCredential: any;

// @public
export interface RemoveContext<T extends IPluginMethod> {
// (undocumented)
Expand All @@ -366,6 +363,9 @@ export interface ResolveDidArgs {
didUrl: string;
}

// @public (undocumented)
export const schema: any;

// @public
export type TAgent<T extends IPluginMethodMap> = {
[P in keyof T]: RemoveContext<T[P]>;
Expand Down
4 changes: 2 additions & 2 deletions packages/daf-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "build/index.d.ts",
"scripts": {
"build": "tsc",
"create-plugin-credential": "yarn daf create-plugin-credential --config=../../agent.yml"
"generate-plugin-schema": "yarn daf generate-plugin-schema"
},
"daf": {
"pluginInterfaces": {
Expand All @@ -31,7 +31,7 @@
"files": [
"build/**/*",
"src/**/*",
"plugin.credential.json",
"plugin.schema.json",
"README.md",
"LICENSE"
],
Expand Down
Loading

0 comments on commit dc80083

Please sign in to comment.