Skip to content

Commit

Permalink
feat: Updated entities
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 6, 2020
1 parent 1a5c4c9 commit 00db341
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 36 deletions.
19 changes: 12 additions & 7 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
OneToMany,
ManyToMany,
BeforeInsert,
AfterInsert,
} from 'typeorm'
import { Identity } from './identity'
import { Message } from './message'
Expand Down Expand Up @@ -48,23 +47,29 @@ export class Credential extends BaseEntity {
@ManyToOne(
type => Identity,
identity => identity.issuedCredentials,
{
cascade: ['insert'],
},
)
issuer: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedCredentials,
{
cascade: ['insert'],
},
)
subject: Identity

@Column()
issuedAt: number
@Column({ nullable: true })
issuedAt?: Date

@Column()
notBefore: number
@Column({ nullable: true })
notBefore?: Date

@Column()
expiresAt: number
@Column({ nullable: true })
expiresAt?: Date

@Column()
raw: string
Expand Down
10 changes: 5 additions & 5 deletions packages/daf-core/src/entities/identity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany } from 'typeorm'
import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany, ManyToMany } from 'typeorm'
import { Key } from './key'
import { Action } from './action'
import { Message } from './message'
Expand All @@ -11,7 +11,7 @@ export class Identity extends BaseEntity {
@PrimaryColumn()
did: string

@Column()
@Column({ nullable: true })
controllerKeyId: string

@OneToMany(
Expand All @@ -28,13 +28,13 @@ export class Identity extends BaseEntity {

@OneToMany(
type => Message,
message => message.sender,
message => message.from,
)
sentMessages: Message[]

@OneToMany(
@ManyToMany(
type => Message,
message => message.receiver,
message => message.to,
)
receivedMessages: Message[]

Expand Down
3 changes: 0 additions & 3 deletions packages/daf-core/src/entities/message-meta-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ export class MessageMetaData extends BaseEntity {
message => message.metaData,
)
message: Message

@Column()
timestamp: number
}
65 changes: 51 additions & 14 deletions packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
PrimaryGeneratedColumn,
OneToMany,
JoinTable,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm'
import { Identity } from './identity'
import { MessageMetaData } from './message-meta-data'
Expand All @@ -18,49 +20,84 @@ export class Message extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
threadId: string
@CreateDateColumn()
saveDate: Date

@UpdateDateColumn()
updateDate: Date

@Column({ nullable: true })
createdAt?: Date

@Column({ nullable: true })
expiresAt?: Date

@Column({ nullable: true })
threadId?: string

@Column()
type: string

@Column()
raw: string

@Column('simple-json', { nullable: true })
data?: object

// https://github.com/decentralized-identity/didcomm-messaging/blob/41f35f992275dd71d459504d14eb8d70b4185533/jwm.md#jwm-profile

@Column('simple-array', { nullable: true })
replyTo?: string[]

@Column({ nullable: true })
replyUrl?: string

@ManyToOne(
type => Identity,
identity => identity.sentMessages,
{
nullable: true,
cascade: ['insert'],
},
)
sender: Identity
from?: Identity

@ManyToOne(
@ManyToMany(
type => Identity,
identity => identity.receivedMessages,
{
nullable: true,
cascade: ['insert'],
},
)
receiver: Identity

@Column()
timestamp: number

@Column()
raw: string

@Column()
data: string
@JoinTable()
to?: Identity[]

@OneToMany(
type => MessageMetaData,
messageMetaData => messageMetaData.message,
{
cascade: true,
},
)
metaData: MessageMetaData[]

@ManyToMany(
type => Presentation,
presentation => presentation.messages,
{
cascade: true,
},
)
@JoinTable()
presentations: Presentation[]

@ManyToMany(
type => Credential,
credential => credential.messages,
{
cascade: true,
},
)
@JoinTable()
credentials: Credential[]
Expand Down
28 changes: 21 additions & 7 deletions packages/daf-core/src/entities/presentation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { blake2bHex } from 'blakejs'
import {
Entity,
Column,
BaseEntity,
ManyToOne,
JoinTable,
PrimaryColumn,
OneToMany,
BeforeInsert,
ManyToMany,
} from 'typeorm'
import { Identity } from './identity'
Expand All @@ -17,26 +18,36 @@ export class Presentation extends BaseEntity {
@PrimaryColumn()
hash: string

@BeforeInsert()
async updateHash() {
this.hash = blake2bHex(this.raw)
}
@ManyToOne(
type => Identity,
identity => identity.issuedPresentations,
{
cascade: ['insert'],
},
)
issuer: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedPresentations,
{
cascade: ['insert'],
},
)
audience: Identity

@Column()
issuedAt: number
@Column({ nullable: true })
issuedAt?: Date

@Column()
notBefore: number
@Column({ nullable: true })
notBefore?: Date

@Column()
expiresAt: number
@Column({ nullable: true })
expiresAt?: Date

@Column()
raw: string
Expand All @@ -48,6 +59,9 @@ export class Presentation extends BaseEntity {
@ManyToMany(
type => Credential,
credential => credential.presentations,
{
cascade: true,
},
)
@JoinTable()
credentials: Credential[]
Expand Down

0 comments on commit 00db341

Please sign in to comment.