Skip to content

Commit

Permalink
fix: Remove daf-data-store from packages
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 16, 2020
1 parent 6c8e263 commit f3bc819
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 956 deletions.
1 change: 0 additions & 1 deletion packages/daf-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"commander": "^4.0.1",
"console-table-printer": "^1.1.15",
"daf-core": "^4.0.0-beta.45",
"daf-data-store": "^4.0.0-beta.45",
"daf-did-comm": "^4.0.0-beta.45",
"daf-did-jwt": "^4.0.0-beta.45",
"daf-ethr-did": "^4.0.0-beta.45",
Expand Down
26 changes: 14 additions & 12 deletions packages/daf-cli/src/credential.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Daf from 'daf-core'
import * as W3c from 'daf-w3c'
import * as DIDComm from 'daf-did-comm'
import { agent, dataStore } from './setup'
import { agent } from './setup'
import program from 'commander'
import inquirer from 'inquirer'
import qrcode from 'qrcode-terminal'
Expand Down Expand Up @@ -98,19 +98,19 @@ program
process.exit()
}

const dids = await dataStore.allIdentities()
const ids = await Daf.Identity.find()

const identities = [
{
name: 'Enter manualy',
value: 'manual',
},
]
for (const did of dids) {
const shortId = await dataStore.shortId(did.did)
for (const id of ids) {
const name = await id.getLatestClaimValue(agent.dbConnection, { type: 'name'})
identities.push({
value: did.did,
name: `${did.did} - ${shortId}`,
value: id.did,
name: `${id.did} - ${name}`,
})
}

Expand Down Expand Up @@ -148,19 +148,21 @@ program
aud = answers.aud
}

const credentials = await dataStore.findCredentials({ sub: answers.iss })
const credentials = await Daf.Credential.find({
where: { subject: answers.iss},
relations: ['claims']
})
const list: any = []
if (credentials.length > 0) {
for (const credential of credentials) {
const fields = await dataStore.credentialsFieldsForClaimHash(credential.hash)
const issuer = await dataStore.shortId(credential.iss.did)
const issuer = credential.issuer.shortDid()
const claims = []
for (const field of fields) {
claims.push(field.type + ' = ' + field.value)
for (const claim of credential.claims) {
claims.push(claim.type + ' = ' + claim.value)
}
list.push({
name: claims.join(', ') + ' | Issuer: ' + issuer,
value: credential.jwt,
value: credential.raw,
})
}

Expand Down
69 changes: 38 additions & 31 deletions packages/daf-cli/src/data-explorer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { agent, dataStore } from './setup'
import * as Daf from 'daf-core'
import { agent } from './setup'
import program from 'commander'
import inquirer from 'inquirer'
import { formatDistanceToNow } from 'date-fns'
Expand All @@ -11,18 +12,19 @@ program
.option('-m, --messages', 'List messages')
.action(async cmd => {
if (cmd.identities) {
const dids = await dataStore.allIdentities()
if (dids.length === 0) {
const dbConnection = await agent.dbConnection
const ids = await dbConnection.getRepository(Daf.Identity).find()
if (ids.length === 0) {
console.error('No dids')
process.exit()
}

const identities = []
for (const did of dids) {
const shortId = await dataStore.shortId(did.did)
for (const id of ids) {
const name = await id.getLatestClaimValue(agent.dbConnection, {type: 'name'})
identities.push({
value: did.did,
name: `${did.did} - ${shortId}`,
value: id.did,
name: `${id.did} - ${name || id.shortDid()}`,
})
}

Expand All @@ -43,10 +45,10 @@ program

switch (answers.type) {
case 'Sent Messages':
showMessageList(await dataStore.findMessages({ sender: answers.did }))
showMessageList(await Daf.Message.find({ where: { from: answers.did } }))
break
case 'Received Messages':
showMessageList(await dataStore.findMessages({ receiver: answers.did }))
showMessageList(await Daf.Message.find({ where: { to: answers.did } }))
break
case 'Credentials':
showCredentials(answers.did)
Expand All @@ -55,11 +57,12 @@ program
}

if (cmd.messages) {
showMessageList(await dataStore.findMessages({}))
const dbConnection = await agent.dbConnection
showMessageList(await dbConnection.getRepository(Daf.Message).find())
}
})

const showMessageList = async (messages: any) => {
const showMessageList = async (messages: Daf.Message[]) => {
if (messages.length === 0) {
console.error('No messages')
process.exit()
Expand All @@ -69,9 +72,9 @@ const showMessageList = async (messages: any) => {
{
type: 'list',
name: 'id',
choices: messages.map((item: any) => ({
name: `${formatDistanceToNow(item.timestamp * 1000)} ${item.type} from: ${item.sender?.did} to: ${
item.receiver?.did
choices: messages.map((item: Daf.Message) => ({
name: `${formatDistanceToNow(item.createdAt)} ${item.type} from: ${item.from?.did} to: ${
item.to?.did
}`,
value: item.id,
})),
Expand All @@ -82,22 +85,23 @@ const showMessageList = async (messages: any) => {
}

const showMessage = async (id: string) => {
const message = await dataStore.findMessage(id)
const dbConnection = await agent.dbConnection
const message = await dbConnection.getRepository(Daf.Message)
.findOne(id, {relations: ['credentials', 'credentials.claims']})
console.log(message)

const table = []
const credentials = await dataStore.credentialsForMessageId(id)
if (credentials.length > 0) {
for (const credential of credentials) {
const fields = await dataStore.credentialsFieldsForClaimHash(credential.hash)
const issuer = await dataStore.shortId(credential.iss.did)
const subject = await dataStore.shortId(credential.sub.did)
for (const field of fields) {

if (message.credentials.length > 0) {
for (const credential of message.credentials) {
const issuer = credential.issuer.shortDid()
const subject = credential.subject.shortDid()
for (const claim of credential.claims) {
table.push({
from: issuer,
to: subject,
type: field.type,
value: field.value,
type: claim.type,
value: claim.value,
})
}
}
Expand All @@ -108,18 +112,21 @@ const showMessage = async (id: string) => {

const showCredentials = async (did: string) => {
const table = []
const credentials = await dataStore.findCredentials({ sub: did })
const dbConnection = await agent.dbConnection

const credentials = await dbConnection.getRepository(Daf.Credential)
.find({ where: { subject: did } })

if (credentials.length > 0) {
for (const credential of credentials) {
const fields = await dataStore.credentialsFieldsForClaimHash(credential.hash)
const issuer = await dataStore.shortId(credential.iss.did)
const subject = await dataStore.shortId(credential.sub.did)
for (const field of fields) {
const issuer = credential.issuer.shortDid()
const subject = credential.subject.shortDid()
for (const claim of credential.claims) {
table.push({
from: issuer,
to: subject,
type: field.type,
value: field.value,
type: claim.type,
value: claim.value,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/daf-cli/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TrustGraphGql } from 'daf-trust-graph'
import { DIDCommGql } from 'daf-did-comm'
import { SdrGql } from 'daf-selective-disclosure'
import merge from 'lodash.merge'
import { agent, dataStore } from './setup'
import { agent } from './setup'
import { listen } from './services'
program
.command('graphql')
Expand All @@ -33,7 +33,7 @@ program
W3cGql.resolvers,
SdrGql.resolvers,
),
context: () => ({ dataStore, agent }),
context: () => ({ agent }),
introspection: true,
})
// await core.setupServices()
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-cli/src/msg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Daf from 'daf-core'
import { agent, dataStore } from './setup'
import { agent } from './setup'
import program from 'commander'

program
Expand Down
6 changes: 3 additions & 3 deletions packages/daf-cli/src/services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventTypes, Message } from 'daf-core'
import { agent, dataStore } from './setup'
import { agent } from './setup'
import program from 'commander'
import { setInterval } from 'timers'

Expand All @@ -18,11 +18,11 @@ export const listen = async (pollSeconds?: number) => {

await agent.setupServices()
await agent.listen()
await agent.getMessagesSince(await dataStore.latestMessageTimestamps())
await agent.getMessagesSince([])

if (pollSeconds) {
setInterval(async () => {
await agent.getMessagesSince(await dataStore.latestMessageTimestamps())
await agent.getMessagesSince([])
}, pollSeconds * 1000)
}
}
3 changes: 0 additions & 3 deletions packages/daf-cli/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { DIDCommActionHandler, DIDCommMessageHandler } from 'daf-did-comm'
import { UrlMessageHandler } from 'daf-url'
import { createConnection } from 'typeorm'

import { DataStore } from 'daf-data-store'
import ws from 'ws'

const defaultPath = process.env.HOME + '/.daf/'
Expand Down Expand Up @@ -82,5 +81,3 @@ export const agent = new Daf.Agent({
messageHandler,
actionHandler,
})

export const dataStore = new DataStore()
1 change: 0 additions & 1 deletion packages/daf-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"references": [
{ "path": "../daf-core" },
{ "path": "../daf-data-store" },
{ "path": "../daf-did-comm" },
{ "path": "../daf-did-jwt" },
{ "path": "../daf-ethr-did" },
Expand Down
Loading

0 comments on commit f3bc819

Please sign in to comment.