Skip to content

Commit

Permalink
feat: Entities
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 5, 2020
1 parent cca8825 commit 7f1c85f
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/daf-core/src/entities/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Entity, Column, BaseEntity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { Identity } from './identity'

@Entity()
export class Action extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
type: string

@ManyToOne(
type => Identity,
identity => identity.actions,
)
identity: Identity

@Column()
timestamp: number

@Column()
data: string
}
45 changes: 45 additions & 0 deletions packages/daf-core/src/entities/claim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
Entity,
Column,
BaseEntity,
ManyToOne,
JoinTable,
PrimaryGeneratedColumn,
OneToMany,
ManyToMany,
} from 'typeorm'
import { Identity } from './identity'
import { Credential } from './credential'

@Entity()
export class Claim extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@ManyToOne(
type => Identity,
identity => identity.issuedPresentations,
)
issuer: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedPresentations,
)
subject: Identity

@ManyToOne(
type => Credential,
credential => credential.claims,
)
credential: Credential

@Column()
type: string

@Column()
value: string

@Column()
isObj: boolean
}
10 changes: 10 additions & 0 deletions packages/daf-core/src/entities/credential-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm'

@Entity()
export class CredentialContext extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
context: string
}
10 changes: 10 additions & 0 deletions packages/daf-core/src/entities/credential-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm'

@Entity()
export class CredentialType extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
type: string
}
72 changes: 72 additions & 0 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
Entity,
Column,
BaseEntity,
ManyToOne,
JoinTable,
PrimaryColumn,
OneToMany,
ManyToMany,
} from 'typeorm'
import { Identity } from './identity'
import { Message } from './message'
import { Presentation } from './presentation'
import { CredentialContext } from './credential-context'
import { CredentialType } from './credential-type'
import { Claim } from './claim'

@Entity()
export class Credential extends BaseEntity {
@PrimaryColumn()
hash: string

@ManyToOne(
type => Identity,
identity => identity.issuedCredentials,
)
issuer: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedCredentials,
)
subject: Identity

@Column()
issuedAt: number

@Column()
notBefore: number

@Column()
expiresAt: number

@Column()
raw: string

@ManyToMany(type => CredentialContext)
@JoinTable()
context: CredentialContext[]

@ManyToMany(type => CredentialType)
@JoinTable()
type: CredentialType[]

@OneToMany(
type => Claim,
claim => claim.credential,
)
claims: Claim[]

@ManyToMany(
type => Presentation,
presentation => presentation.credentials,
)
presentations: Presentation[]

@ManyToMany(
type => Message,
message => message.presentations,
)
messages: Message[]
}
59 changes: 59 additions & 0 deletions packages/daf-core/src/entities/identity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany } from 'typeorm'
import { Key } from './key'
import { Action } from './action'
import { Message } from './message'
import { Presentation } from './presentation'
import { Credential } from './credential'
import { Claim } from './claim'

@Entity()
export class Identity extends BaseEntity {
Expand All @@ -14,4 +19,58 @@ export class Identity extends BaseEntity {
key => key.identity,
)
keys: Key[]

@OneToMany(
type => Action,
action => action.identity,
)
actions: Action[]

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

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

@OneToMany(
type => Presentation,
presentation => presentation.issuer,
)
issuedPresentations: Presentation[]

@OneToMany(
type => Presentation,
presentation => presentation.audience,
)
receivedPresentations: Presentation[]

@OneToMany(
type => Credential,
credential => credential.issuer,
)
issuedCredentials: Credential[]

@OneToMany(
type => Credential,
credential => credential.subject,
)
receivedCredentials: Credential[]

@OneToMany(
type => Claim,
claim => claim.issuer,
)
issuedClaims: Claim[]

@OneToMany(
type => Claim,
claim => claim.subject,
)
receivedClaims: Claim[]
}
23 changes: 23 additions & 0 deletions packages/daf-core/src/entities/message-meta-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Entity, Column, BaseEntity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { Message } from './message'

@Entity()
export class MessageMetaData extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
type: string

@Column()
value: string

@ManyToOne(
type => Message,
message => message.metaData,
)
message: Message

@Column()
timestamp: number
}
67 changes: 67 additions & 0 deletions packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
Entity,
Column,
BaseEntity,
ManyToOne,
ManyToMany,
PrimaryGeneratedColumn,
OneToMany,
JoinTable,
} from 'typeorm'
import { Identity } from './identity'
import { MessageMetaData } from './message-meta-data'
import { Presentation } from './presentation'
import { Credential } from './credential'

@Entity()
export class Message extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
threadId: string

@Column()
type: string

@ManyToOne(
type => Identity,
identity => identity.sentMessages,
)
sender: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedMessages,
)
receiver: Identity

@Column()
timestamp: number

@Column()
raw: string

@Column()
data: string

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

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

@ManyToMany(
type => Credential,
credential => credential.messages,
)
@JoinTable()
credentials: Credential[]
}
10 changes: 10 additions & 0 deletions packages/daf-core/src/entities/presentation-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm'

@Entity()
export class PresentationContext extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
context: string
}
10 changes: 10 additions & 0 deletions packages/daf-core/src/entities/presentation-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm'

@Entity()
export class PresentationType extends BaseEntity {
@PrimaryGeneratedColumn()
id: string

@Column()
type: string
}
Loading

0 comments on commit 7f1c85f

Please sign in to comment.