-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
108 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# Graph | ||
|
||
npm run -s transmute -- graph assist ./tests/fixtures/issuer-claims.json --credential-type application/vc --output ./tests/fixtures/issuer-claims.graph.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'fs' | ||
|
||
import { Arguments } from "../types" | ||
import { setOutput, debug } from '@actions/core' | ||
import { env } from '../action' | ||
import { jsongraph } from './graph/jsongraph' | ||
import { query, injection } from './graph/gql' | ||
import { driver, push } from './graph/driver' | ||
|
||
export const handler = async function ({ positionals, values }: Arguments) { | ||
positionals = positionals.slice(1) | ||
const operation = positionals.shift() | ||
switch (operation) { | ||
case 'assist': { | ||
const graphType = values['graph-type'] || 'application/vnd.jgf+json' | ||
const output = values.output | ||
const contentType: any = values['credential-type'] || values['presentation-type'] | ||
const verbose = values.verbose || false | ||
const [pathToContent] = positionals | ||
const content = new Uint8Array(fs.readFileSync(pathToContent)) | ||
const graph = await jsongraph.graph(content, contentType) | ||
let graphText = JSON.stringify(graph, null, 2) | ||
if (verbose) { | ||
const message = `🕸️ ${graphType}` | ||
debug(message) | ||
} | ||
if (graphType === 'application/gql') { | ||
const components = await query(graph) | ||
const dangerousQuery = await injection(components) | ||
graphText = dangerousQuery | ||
if (values.push) { | ||
const d = await driver() | ||
const session = d.session() | ||
await push(session, components) | ||
await d.close() | ||
} | ||
} | ||
if (output) { | ||
fs.writeFileSync(output, JSON.stringify(graphText, null, 2)) | ||
} | ||
if (env.github()) { | ||
if (graphType === 'application/gql') { | ||
setOutput('gql', graphText) | ||
} | ||
if (graphType === 'application/vnd.jgf+json') { | ||
setOutput('json', graph) | ||
} | ||
} else { | ||
if (!output) { | ||
console.log(graphText) | ||
} | ||
} | ||
break | ||
} | ||
default: { | ||
const message = `😕 Unknown Command` | ||
console.error(message) | ||
throw new Error(message) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './handler' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as core from '@actions/core' | ||
|
||
import { facade } from '../src' | ||
|
||
let debug: jest.SpiedFunction<typeof core.debug> | ||
let output: jest.SpiedFunction<typeof core.setOutput> | ||
let secret: jest.SpiedFunction<typeof core.setSecret> | ||
|
||
beforeEach(() => { | ||
process.env.GITHUB_ACTION = 'jest-mock' | ||
jest.clearAllMocks() | ||
debug = jest.spyOn(core, 'debug').mockImplementation() | ||
output = jest.spyOn(core, 'setOutput').mockImplementation() | ||
secret = jest.spyOn(core, 'setSecret').mockImplementation() | ||
}) | ||
|
||
// Graph | ||
|
||
it('graph json', async () => { | ||
await facade(`graph assist ./tests/fixtures/issuer-claims.json --verbose --credential-type application/vc --graph-type application/vnd.jgf+json`) | ||
expect(debug).toHaveBeenCalledTimes(1) | ||
expect(output).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('graph gql', async () => { | ||
await facade(`graph assist ./tests/fixtures/issuer-claims.json --verbose --credential-type application/vc --graph-type application/gql`) | ||
expect(debug).toHaveBeenCalledTimes(1) | ||
expect(output).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it.skip('graph gql neo4j', async () => { | ||
await facade(`graph assist ./tests/fixtures/issuer-claims.json --verbose --credential-type application/vc --graph-type application/gql --push`) | ||
expect(debug).toHaveBeenCalledTimes(1) | ||
expect(output).toHaveBeenCalledTimes(1) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters