@sphereon/ssi-sdk.data-store 0.15.2-next.5 → 0.15.2-next.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contact/AbstractContactStore.d.ts +21 -11
- package/dist/contact/AbstractContactStore.d.ts.map +1 -1
- package/dist/contact/AbstractContactStore.js.map +1 -1
- package/dist/contact/ContactStore.d.ts +25 -21
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +216 -136
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.d.ts +2 -0
- package/dist/entities/contact/BaseConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.js +10 -2
- package/dist/entities/contact/BaseConfigEntity.js.map +1 -1
- package/dist/entities/contact/BaseContactEntity.d.ts +10 -0
- package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -0
- package/dist/entities/contact/BaseContactEntity.js +54 -0
- package/dist/entities/contact/BaseContactEntity.js.map +1 -0
- package/dist/entities/contact/ConnectionEntity.d.ts +1 -2
- package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
- package/dist/entities/contact/ConnectionEntity.js +2 -21
- package/dist/entities/contact/ConnectionEntity.js.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -3
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -11
- package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.d.ts +0 -4
- package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.js +1 -17
- package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.d.ts +14 -0
- package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -0
- package/dist/entities/contact/ElectronicAddressEntity.js +92 -0
- package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -0
- package/dist/entities/contact/IdentityEntity.d.ts +5 -6
- package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityEntity.js +15 -20
- package/dist/entities/contact/IdentityEntity.js.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +1 -3
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.js +7 -10
- package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
- package/dist/entities/contact/NaturalPersonEntity.d.ts +9 -0
- package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -0
- package/dist/entities/contact/NaturalPersonEntity.js +72 -0
- package/dist/entities/contact/NaturalPersonEntity.js.map +1 -0
- package/dist/entities/contact/OpenIdConfigEntity.d.ts +0 -4
- package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/OpenIdConfigEntity.js +1 -22
- package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
- package/dist/entities/contact/OrganizationEntity.d.ts +9 -0
- package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -0
- package/dist/entities/contact/OrganizationEntity.js +67 -0
- package/dist/entities/contact/OrganizationEntity.js.map +1 -0
- package/dist/entities/contact/PartyEntity.d.ts +21 -0
- package/dist/entities/contact/PartyEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyEntity.js +155 -0
- package/dist/entities/contact/PartyEntity.js.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts +13 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.js +95 -0
- package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts +15 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts.map +1 -0
- package/dist/entities/contact/{ContactEntity.js → PartyTypeEntity.js} +35 -36
- package/dist/entities/contact/PartyTypeEntity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts +19 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js +115 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts +11 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js +51 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.js +36 -32
- package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
- package/dist/migrations/generic/2-CreateContacts.d.ts +7 -0
- package/dist/migrations/generic/2-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateContacts.js +76 -0
- package/dist/migrations/generic/2-CreateContacts.js.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.d.ts → 2-CreateIssuanceBranding.d.ts} +1 -1
- package/dist/migrations/generic/2-CreateIssuanceBranding.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js +76 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts +7 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.js → 3-CreateStatusList.js} +11 -11
- package/dist/migrations/generic/3-CreateStatusList.js.map +1 -0
- package/dist/migrations/generic/index.d.ts +5 -0
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +10 -3
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts +2 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.js +0 -2
- package/dist/migrations/internal-migrations-ormconfig.js.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.js +4 -2
- package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -0
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts +7 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js +69 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts +7 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js +32 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +1 -0
- package/dist/migrations/postgres/uuid.d.ts +3 -0
- package/dist/migrations/postgres/uuid.d.ts.map +1 -0
- package/dist/migrations/postgres/uuid.js +25 -0
- package/dist/migrations/postgres/uuid.js.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts +7 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js +108 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts +7 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +32 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js.map +1 -0
- package/dist/statusList/IStatusListStore.d.ts +20 -0
- package/dist/statusList/IStatusListStore.d.ts.map +1 -0
- package/dist/statusList/IStatusListStore.js +3 -0
- package/dist/statusList/IStatusListStore.js.map +1 -0
- package/dist/statusList/StatusListStore.d.ts +36 -0
- package/dist/statusList/StatusListStore.d.ts.map +1 -0
- package/dist/statusList/StatusListStore.js +213 -0
- package/dist/statusList/StatusListStore.js.map +1 -0
- package/dist/types/contact/IAbstractContactStore.d.ts +70 -36
- package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
- package/dist/types/contact/contact.d.ts +139 -56
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js +6 -1
- package/dist/types/contact/contact.js.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/statusList/IAbstractStatusListStore.d.ts +38 -0
- package/dist/types/statusList/IAbstractStatusListStore.d.ts.map +1 -0
- package/dist/types/statusList/IAbstractStatusListStore.js +3 -0
- package/dist/types/statusList/IAbstractStatusListStore.js.map +1 -0
- package/dist/types/statusList/statusList.d.ts +25 -0
- package/dist/types/statusList/statusList.d.ts.map +1 -0
- package/dist/types/statusList/statusList.js +3 -0
- package/dist/types/statusList/statusList.js.map +1 -0
- package/dist/types/validation/validation.d.ts +4 -0
- package/dist/types/validation/validation.d.ts.map +1 -0
- package/dist/types/validation/validation.js +3 -0
- package/dist/types/validation/validation.js.map +1 -0
- package/dist/utils/ValidatorUtils.d.ts +4 -0
- package/dist/utils/ValidatorUtils.d.ts.map +1 -0
- package/dist/utils/ValidatorUtils.js +13 -0
- package/dist/utils/ValidatorUtils.js.map +1 -0
- package/dist/utils/contact/MappingUtils.d.ts +47 -0
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -0
- package/dist/utils/contact/MappingUtils.js +291 -0
- package/dist/utils/contact/MappingUtils.js.map +1 -0
- package/package.json +5 -4
- package/src/__tests__/contact.entities.test.ts +1457 -195
- package/src/__tests__/contact.store.test.ts +1302 -266
- package/src/contact/AbstractContactStore.ts +44 -22
- package/src/contact/ContactStore.ts +328 -204
- package/src/entities/contact/BaseConfigEntity.ts +10 -2
- package/src/entities/contact/BaseContactEntity.ts +30 -0
- package/src/entities/contact/ConnectionEntity.ts +4 -23
- package/src/entities/contact/CorrelationIdentifierEntity.ts +9 -13
- package/src/entities/contact/DidAuthConfigEntity.ts +1 -18
- package/src/entities/contact/ElectronicAddressEntity.ts +60 -0
- package/src/entities/contact/IdentityEntity.ts +18 -25
- package/src/entities/contact/IdentityMetadataItemEntity.ts +8 -12
- package/src/entities/contact/NaturalPersonEntity.ts +38 -0
- package/src/entities/contact/OpenIdConfigEntity.ts +1 -23
- package/src/entities/contact/OrganizationEntity.ts +34 -0
- package/src/entities/contact/PartyEntity.ts +118 -0
- package/src/entities/contact/PartyRelationshipEntity.ts +61 -0
- package/src/entities/contact/PartyTypeEntity.ts +59 -0
- package/src/entities/statusList2021/StatusList2021Entity.ts +95 -0
- package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -0
- package/src/index.ts +36 -17
- package/src/migrations/generic/1-CreateContacts.ts +46 -36
- package/src/migrations/generic/2-CreateContacts.ts +64 -0
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +62 -0
- package/src/migrations/generic/{1-CreateIssuanceBranding.ts → 3-CreateStatusList.ts} +9 -9
- package/src/migrations/generic/index.ts +11 -2
- package/src/migrations/internal-migrations-ormconfig.ts +2 -4
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +4 -2
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -0
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +94 -0
- package/src/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.ts +24 -0
- package/src/migrations/postgres/uuid.ts +12 -0
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +163 -0
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -0
- package/src/statusList/IStatusListStore.ts +44 -0
- package/src/statusList/StatusListStore.ts +237 -0
- package/src/types/contact/IAbstractContactStore.ts +84 -27
- package/src/types/contact/contact.ts +144 -50
- package/src/types/index.ts +4 -0
- package/src/types/statusList/IAbstractStatusListStore.ts +47 -0
- package/src/types/statusList/statusList.ts +39 -0
- package/src/types/validation/validation.ts +3 -0
- package/src/utils/ValidatorUtils.ts +10 -0
- package/src/utils/contact/MappingUtils.ts +344 -0
- package/dist/entities/contact/ContactEntity.d.ts +0 -16
- package/dist/entities/contact/ContactEntity.d.ts.map +0 -1
- package/dist/entities/contact/ContactEntity.js.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +0 -1
- package/src/entities/contact/ContactEntity.ts +0 -74
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { BaseEntity, Entity, PrimaryGeneratedColumn, TableInheritance } from 'typeorm'
|
|
1
|
+
import { BaseEntity, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn, TableInheritance } from 'typeorm'
|
|
2
|
+
import { ConnectionEntity } from './ConnectionEntity'
|
|
2
3
|
|
|
3
|
-
@Entity('
|
|
4
|
+
@Entity('BaseConfig')
|
|
4
5
|
@TableInheritance({ column: { type: 'varchar', name: 'type' } })
|
|
5
6
|
export abstract class BaseConfigEntity extends BaseEntity {
|
|
6
7
|
@PrimaryGeneratedColumn('uuid')
|
|
7
8
|
id!: string
|
|
9
|
+
|
|
10
|
+
@OneToOne(() => ConnectionEntity, (connection: ConnectionEntity) => connection.config, {
|
|
11
|
+
cascade: ['insert', 'update'],
|
|
12
|
+
onDelete: 'CASCADE',
|
|
13
|
+
})
|
|
14
|
+
@JoinColumn({ name: 'connection_id' })
|
|
15
|
+
connection?: ConnectionEntity
|
|
8
16
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseEntity,
|
|
2
|
+
BeforeInsert,
|
|
3
|
+
BeforeUpdate, CreateDateColumn, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn, TableInheritance, UpdateDateColumn } from 'typeorm'
|
|
4
|
+
import { PartyEntity } from './PartyEntity'
|
|
5
|
+
|
|
6
|
+
@Entity('BaseContact')
|
|
7
|
+
@TableInheritance({ column: { type: 'varchar', name: 'type' } })
|
|
8
|
+
export abstract class BaseContactEntity extends BaseEntity {
|
|
9
|
+
@PrimaryGeneratedColumn('uuid')
|
|
10
|
+
id!: string
|
|
11
|
+
|
|
12
|
+
@CreateDateColumn({ name: 'created_at', nullable: false })
|
|
13
|
+
createdAt!: Date
|
|
14
|
+
|
|
15
|
+
@UpdateDateColumn({ name: 'last_updated_at', nullable: false })
|
|
16
|
+
lastUpdatedAt!: Date
|
|
17
|
+
|
|
18
|
+
@OneToOne(() => PartyEntity, (party: PartyEntity) => party.contact, {
|
|
19
|
+
onDelete: 'CASCADE',
|
|
20
|
+
})
|
|
21
|
+
@JoinColumn({ name: 'party_id' })
|
|
22
|
+
party!: PartyEntity
|
|
23
|
+
|
|
24
|
+
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
25
|
+
@BeforeInsert()
|
|
26
|
+
@BeforeUpdate()
|
|
27
|
+
updateUpdatedDate(): void {
|
|
28
|
+
this.lastUpdatedAt = new Date()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, BaseEntity } from 'typeorm'
|
|
2
2
|
import { BaseConfigEntity } from './BaseConfigEntity'
|
|
3
|
-
import {
|
|
3
|
+
import { ConnectionTypeEnum } from '../../types'
|
|
4
4
|
import { IdentityEntity } from './IdentityEntity'
|
|
5
|
-
import { OpenIdConfigEntity
|
|
6
|
-
import { DidAuthConfigEntity
|
|
5
|
+
import { OpenIdConfigEntity } from './OpenIdConfigEntity'
|
|
6
|
+
import { DidAuthConfigEntity } from './DidAuthConfigEntity'
|
|
7
7
|
|
|
8
8
|
@Entity('Connection')
|
|
9
9
|
export class ConnectionEntity extends BaseEntity {
|
|
@@ -24,25 +24,6 @@ export class ConnectionEntity extends BaseEntity {
|
|
|
24
24
|
@OneToOne(() => IdentityEntity, (identity: IdentityEntity) => identity.connection, {
|
|
25
25
|
onDelete: 'CASCADE',
|
|
26
26
|
})
|
|
27
|
-
@JoinColumn({ name: '
|
|
27
|
+
@JoinColumn({ name: 'identity_id' })
|
|
28
28
|
identity!: IdentityEntity
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
export const connectionEntityFrom = (connection: IBasicConnection): ConnectionEntity => {
|
|
32
|
-
const connectionEntity = new ConnectionEntity()
|
|
33
|
-
connectionEntity.type = connection.type
|
|
34
|
-
connectionEntity.config = configEntityFrom(connection.type, connection.config)
|
|
35
|
-
|
|
36
|
-
return connectionEntity
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const configEntityFrom = (type: ConnectionTypeEnum, config: BasicConnectionConfig): BaseConfigEntity => {
|
|
40
|
-
switch (type) {
|
|
41
|
-
case ConnectionTypeEnum.OPENID_CONNECT:
|
|
42
|
-
return openIdConfigEntityFrom(config as IOpenIdConfig)
|
|
43
|
-
case ConnectionTypeEnum.SIOPv2:
|
|
44
|
-
return didAuthConfigEntityFrom(config as IDidAuthConfig)
|
|
45
|
-
default:
|
|
46
|
-
throw new Error('Connection type not supported')
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity, OneToOne, JoinColumn, BeforeInsert, BeforeUpdate } from 'typeorm'
|
|
2
|
-
import { CorrelationIdentifierEnum,
|
|
2
|
+
import { CorrelationIdentifierEnum, ValidationConstraint } from '../../types'
|
|
3
3
|
import { IdentityEntity } from './IdentityEntity'
|
|
4
4
|
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
|
|
5
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
5
6
|
|
|
6
7
|
@Entity('CorrelationIdentifier')
|
|
7
8
|
export class CorrelationIdentifierEntity extends BaseEntity {
|
|
@@ -18,24 +19,19 @@ export class CorrelationIdentifierEntity extends BaseEntity {
|
|
|
18
19
|
@OneToOne(() => IdentityEntity, (identity: IdentityEntity) => identity.identifier, {
|
|
19
20
|
onDelete: 'CASCADE',
|
|
20
21
|
})
|
|
21
|
-
@JoinColumn({ name: '
|
|
22
|
+
@JoinColumn({ name: 'identity_id' })
|
|
22
23
|
identity!: IdentityEntity
|
|
23
24
|
|
|
24
25
|
@BeforeInsert()
|
|
25
26
|
@BeforeUpdate()
|
|
26
|
-
async validate() {
|
|
27
|
+
async validate(): Promise<void> {
|
|
27
28
|
const validation: Array<ValidationError> = await validate(this)
|
|
28
29
|
if (validation.length > 0) {
|
|
29
|
-
|
|
30
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
31
|
+
if (constraint) {
|
|
32
|
+
const message: string = Object.values(constraint!)[0]
|
|
33
|
+
return Promise.reject(Error(message))
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
|
-
return
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
export const correlationIdentifierEntityFrom = (identifier: BasicCorrelationIdentifier): CorrelationIdentifierEntity => {
|
|
36
|
-
const identifierEntity = new CorrelationIdentifierEntity()
|
|
37
|
-
identifierEntity.type = identifier.type
|
|
38
|
-
identifierEntity.correlationId = identifier.correlationId
|
|
39
|
-
|
|
40
|
-
return identifierEntity
|
|
41
|
-
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ChildEntity, Column
|
|
1
|
+
import { ChildEntity, Column } from 'typeorm'
|
|
2
2
|
import { BaseConfigEntity } from './BaseConfigEntity'
|
|
3
|
-
import { BasicDidAuthConfig } from '../../types'
|
|
4
|
-
import { ConnectionEntity } from './ConnectionEntity'
|
|
5
3
|
|
|
6
4
|
@ChildEntity('DidAuthConfig')
|
|
7
5
|
export class DidAuthConfigEntity extends BaseConfigEntity {
|
|
@@ -13,19 +11,4 @@ export class DidAuthConfigEntity extends BaseConfigEntity {
|
|
|
13
11
|
|
|
14
12
|
@Column({ name: 'session_id', length: 255, nullable: false })
|
|
15
13
|
sessionId!: string
|
|
16
|
-
|
|
17
|
-
@OneToOne(() => ConnectionEntity, (connection: ConnectionEntity) => connection.config, {
|
|
18
|
-
onDelete: 'CASCADE',
|
|
19
|
-
})
|
|
20
|
-
@JoinColumn({ name: 'connectionId' })
|
|
21
|
-
connection?: ConnectionEntity
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const didAuthConfigEntityFrom = (config: BasicDidAuthConfig): DidAuthConfigEntity => {
|
|
25
|
-
const didAuthConfig = new DidAuthConfigEntity()
|
|
26
|
-
didAuthConfig.identifier = config.identifier.did
|
|
27
|
-
didAuthConfig.redirectUrl = config.redirectUrl
|
|
28
|
-
didAuthConfig.sessionId = config.sessionId
|
|
29
|
-
|
|
30
|
-
return didAuthConfig
|
|
31
14
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
|
|
2
|
+
import {
|
|
3
|
+
Entity,
|
|
4
|
+
Column,
|
|
5
|
+
PrimaryGeneratedColumn,
|
|
6
|
+
BaseEntity,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
BeforeInsert,
|
|
9
|
+
BeforeUpdate,
|
|
10
|
+
CreateDateColumn,
|
|
11
|
+
UpdateDateColumn,
|
|
12
|
+
} from 'typeorm'
|
|
13
|
+
import { PartyEntity } from './PartyEntity'
|
|
14
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
15
|
+
import { ElectronicAddressType, ValidationConstraint } from '../../types'
|
|
16
|
+
|
|
17
|
+
@Entity('ElectronicAddress')
|
|
18
|
+
export class ElectronicAddressEntity extends BaseEntity {
|
|
19
|
+
@PrimaryGeneratedColumn('uuid')
|
|
20
|
+
id!: string
|
|
21
|
+
|
|
22
|
+
@Column({ name: 'type', length: 255, nullable: false })
|
|
23
|
+
@IsNotEmpty({ message: 'Blank electronic address types are not allowed' })
|
|
24
|
+
type!: ElectronicAddressType
|
|
25
|
+
|
|
26
|
+
@Column({ name: 'electronic_address', length: 255, nullable: false })
|
|
27
|
+
@IsNotEmpty({ message: 'Blank electronic addresses are not allowed' })
|
|
28
|
+
electronicAddress!: string
|
|
29
|
+
|
|
30
|
+
@ManyToOne(() => PartyEntity, (party: PartyEntity) => party.electronicAddresses, {
|
|
31
|
+
onDelete: 'CASCADE',
|
|
32
|
+
})
|
|
33
|
+
party!: PartyEntity
|
|
34
|
+
|
|
35
|
+
@CreateDateColumn({ name: 'created_at', nullable: false })
|
|
36
|
+
createdAt!: Date
|
|
37
|
+
|
|
38
|
+
@UpdateDateColumn({ name: 'last_updated_at', nullable: false })
|
|
39
|
+
lastUpdatedAt!: Date
|
|
40
|
+
|
|
41
|
+
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
42
|
+
@BeforeInsert()
|
|
43
|
+
@BeforeUpdate()
|
|
44
|
+
updateUpdatedDate(): void {
|
|
45
|
+
this.lastUpdatedAt = new Date()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@BeforeInsert()
|
|
49
|
+
@BeforeUpdate()
|
|
50
|
+
async validate(): Promise<void> {
|
|
51
|
+
const validation: Array<ValidationError> = await validate(this)
|
|
52
|
+
if (validation.length > 0) {
|
|
53
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
54
|
+
if (constraint) {
|
|
55
|
+
const message: string = Object.values(constraint!)[0]
|
|
56
|
+
return Promise.reject(Error(message))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -13,11 +13,12 @@ import {
|
|
|
13
13
|
BeforeUpdate,
|
|
14
14
|
} from 'typeorm'
|
|
15
15
|
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
|
|
16
|
-
import {
|
|
17
|
-
import { ConnectionEntity
|
|
18
|
-
import { IdentityMetadataItemEntity
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
16
|
+
import { CorrelationIdentifierEntity } from './CorrelationIdentifierEntity'
|
|
17
|
+
import { ConnectionEntity } from './ConnectionEntity'
|
|
18
|
+
import { IdentityMetadataItemEntity } from './IdentityMetadataItemEntity'
|
|
19
|
+
import { IdentityRoleEnum, ValidationConstraint } from '../../types'
|
|
20
|
+
import { PartyEntity } from './PartyEntity'
|
|
21
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
21
22
|
|
|
22
23
|
@Entity('Identity')
|
|
23
24
|
export class IdentityEntity extends BaseEntity {
|
|
@@ -57,7 +58,7 @@ export class IdentityEntity extends BaseEntity {
|
|
|
57
58
|
eager: true,
|
|
58
59
|
nullable: false,
|
|
59
60
|
})
|
|
60
|
-
@JoinColumn({ name: '
|
|
61
|
+
@JoinColumn({ name: 'metadata_id' }) // TODO check in db file
|
|
61
62
|
metadata!: Array<IdentityMetadataItemEntity>
|
|
62
63
|
|
|
63
64
|
@CreateDateColumn({ name: 'created_at', nullable: false })
|
|
@@ -66,39 +67,31 @@ export class IdentityEntity extends BaseEntity {
|
|
|
66
67
|
@UpdateDateColumn({ name: 'last_updated_at', nullable: false })
|
|
67
68
|
lastUpdatedAt!: Date
|
|
68
69
|
|
|
69
|
-
@ManyToOne(() =>
|
|
70
|
+
@ManyToOne(() => PartyEntity, (party: PartyEntity) => party.identities, {
|
|
70
71
|
onDelete: 'CASCADE',
|
|
71
72
|
})
|
|
72
|
-
|
|
73
|
+
party!: PartyEntity
|
|
73
74
|
|
|
74
|
-
@Column({ name: '
|
|
75
|
-
|
|
75
|
+
@Column({ name: 'partyId', nullable: true })
|
|
76
|
+
partyId!: string
|
|
76
77
|
|
|
77
78
|
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
78
79
|
@BeforeInsert()
|
|
79
80
|
@BeforeUpdate()
|
|
80
|
-
updateUpdatedDate() {
|
|
81
|
+
updateUpdatedDate(): void {
|
|
81
82
|
this.lastUpdatedAt = new Date()
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
@BeforeInsert()
|
|
85
86
|
@BeforeUpdate()
|
|
86
|
-
async validate() {
|
|
87
|
+
async validate(): Promise<void> {
|
|
87
88
|
const validation: Array<ValidationError> = await validate(this)
|
|
88
89
|
if (validation.length > 0) {
|
|
89
|
-
|
|
90
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
91
|
+
if (constraint) {
|
|
92
|
+
const message: string = Object.values(constraint!)[0]
|
|
93
|
+
return Promise.reject(Error(message))
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
|
-
return
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
|
-
|
|
95
|
-
export const identityEntityFrom = (args: IBasicIdentity): IdentityEntity => {
|
|
96
|
-
const identityEntity = new IdentityEntity()
|
|
97
|
-
identityEntity.alias = args.alias
|
|
98
|
-
identityEntity.roles = args.roles
|
|
99
|
-
identityEntity.identifier = correlationIdentifierEntityFrom(args.identifier)
|
|
100
|
-
identityEntity.connection = args.connection ? connectionEntityFrom(args.connection) : undefined
|
|
101
|
-
identityEntity.metadata = args.metadata ? args.metadata.map((item: BasicMetadataItem) => metadataItemEntityFrom(item)) : []
|
|
102
|
-
|
|
103
|
-
return identityEntity
|
|
104
|
-
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity, ManyToOne, BeforeInsert, BeforeUpdate } from 'typeorm'
|
|
2
|
-
import {
|
|
2
|
+
import { ValidationConstraint } from '../../types'
|
|
3
3
|
import { IdentityEntity } from './IdentityEntity'
|
|
4
4
|
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
|
|
5
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
5
6
|
|
|
6
7
|
@Entity('IdentityMetadata')
|
|
7
8
|
export class IdentityMetadataItemEntity extends BaseEntity {
|
|
@@ -21,19 +22,14 @@ export class IdentityMetadataItemEntity extends BaseEntity {
|
|
|
21
22
|
|
|
22
23
|
@BeforeInsert()
|
|
23
24
|
@BeforeUpdate()
|
|
24
|
-
async validate() {
|
|
25
|
+
async validate(): Promise<void> {
|
|
25
26
|
const validation: Array<ValidationError> = await validate(this)
|
|
26
27
|
if (validation.length > 0) {
|
|
27
|
-
|
|
28
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
29
|
+
if (constraint) {
|
|
30
|
+
const message: string = Object.values(constraint!)[0]
|
|
31
|
+
return Promise.reject(Error(message))
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
|
-
return
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
export const metadataItemEntityFrom = (item: BasicMetadataItem): IdentityMetadataItemEntity => {
|
|
34
|
-
const metadataItem = new IdentityMetadataItemEntity()
|
|
35
|
-
metadataItem.label = item.label
|
|
36
|
-
metadataItem.value = item.value
|
|
37
|
-
|
|
38
|
-
return metadataItem
|
|
39
|
-
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Column, ChildEntity, BeforeInsert, BeforeUpdate } from 'typeorm'
|
|
2
|
+
import { BaseContactEntity } from './BaseContactEntity'
|
|
3
|
+
import { ValidationConstraint } from '../../types'
|
|
4
|
+
import { validate, IsNotEmpty, ValidationError, Validate } from 'class-validator'
|
|
5
|
+
import { IsNonEmptyStringConstraint } from '../validators'
|
|
6
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
7
|
+
|
|
8
|
+
@ChildEntity('NaturalPerson')
|
|
9
|
+
export class NaturalPersonEntity extends BaseContactEntity {
|
|
10
|
+
@Column({ name: 'first_name', length: 255, nullable: false, unique: false })
|
|
11
|
+
@IsNotEmpty({ message: 'Blank first names are not allowed' })
|
|
12
|
+
firstName!: string
|
|
13
|
+
|
|
14
|
+
@Column({ name: 'middle_name', length: 255, nullable: true, unique: false })
|
|
15
|
+
@Validate(IsNonEmptyStringConstraint, { message: 'Blank middle names are not allowed' })
|
|
16
|
+
middleName?: string
|
|
17
|
+
|
|
18
|
+
@Column({ name: 'last_name', length: 255, nullable: false, unique: false })
|
|
19
|
+
@IsNotEmpty({ message: 'Blank last names are not allowed' })
|
|
20
|
+
lastName!: string
|
|
21
|
+
|
|
22
|
+
@Column({ name: 'display_name', length: 255, nullable: false, unique: false })
|
|
23
|
+
@IsNotEmpty({ message: 'Blank display names are not allowed' })
|
|
24
|
+
displayName!: string
|
|
25
|
+
|
|
26
|
+
@BeforeInsert()
|
|
27
|
+
@BeforeUpdate()
|
|
28
|
+
async validate(): Promise<void> {
|
|
29
|
+
const validation: Array<ValidationError> = await validate(this)
|
|
30
|
+
if (validation.length > 0) {
|
|
31
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
32
|
+
if (constraint) {
|
|
33
|
+
const message: string = Object.values(constraint!)[0]
|
|
34
|
+
return Promise.reject(Error(message))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ChildEntity, Column
|
|
1
|
+
import { ChildEntity, Column } from 'typeorm'
|
|
2
2
|
import { BaseConfigEntity } from './BaseConfigEntity'
|
|
3
|
-
import { BasicOpenIdConfig } from '../../types'
|
|
4
|
-
import { ConnectionEntity } from './ConnectionEntity'
|
|
5
3
|
|
|
6
4
|
@ChildEntity('OpenIdConfig')
|
|
7
5
|
export class OpenIdConfigEntity extends BaseConfigEntity {
|
|
@@ -25,24 +23,4 @@ export class OpenIdConfigEntity extends BaseConfigEntity {
|
|
|
25
23
|
|
|
26
24
|
@Column('text', { name: 'client_auth_method', nullable: false })
|
|
27
25
|
clientAuthMethod!: 'basic' | 'post' | undefined
|
|
28
|
-
|
|
29
|
-
@OneToOne(() => ConnectionEntity, (connection: ConnectionEntity) => connection.config, {
|
|
30
|
-
cascade: ['insert', 'update'],
|
|
31
|
-
onDelete: 'CASCADE',
|
|
32
|
-
})
|
|
33
|
-
@JoinColumn({ name: 'connectionId' })
|
|
34
|
-
connection?: ConnectionEntity
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const openIdConfigEntityFrom = (config: BasicOpenIdConfig): OpenIdConfigEntity => {
|
|
38
|
-
const openIdConfig = new OpenIdConfigEntity()
|
|
39
|
-
openIdConfig.clientId = config.clientId
|
|
40
|
-
openIdConfig.clientSecret = config.clientSecret
|
|
41
|
-
openIdConfig.scopes = config.scopes
|
|
42
|
-
openIdConfig.issuer = config.issuer
|
|
43
|
-
openIdConfig.redirectUrl = config.redirectUrl
|
|
44
|
-
openIdConfig.dangerouslyAllowInsecureHttpRequests = config.dangerouslyAllowInsecureHttpRequests
|
|
45
|
-
openIdConfig.clientAuthMethod = config.clientAuthMethod
|
|
46
|
-
|
|
47
|
-
return openIdConfig
|
|
48
26
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { JoinColumn, OneToOne, Column, ChildEntity, BeforeInsert, BeforeUpdate } from 'typeorm'
|
|
2
|
+
import { PartyEntity } from './PartyEntity'
|
|
3
|
+
import { BaseContactEntity } from './BaseContactEntity'
|
|
4
|
+
import { ValidationConstraint } from '../../types'
|
|
5
|
+
import { validate, IsNotEmpty, ValidationError } from 'class-validator'
|
|
6
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
7
|
+
|
|
8
|
+
@ChildEntity('Organization')
|
|
9
|
+
export class OrganizationEntity extends BaseContactEntity {
|
|
10
|
+
@Column({ name: 'legal_name', length: 255, nullable: false, unique: true })
|
|
11
|
+
@IsNotEmpty({ message: 'Blank legal names are not allowed' })
|
|
12
|
+
legalName!: string
|
|
13
|
+
|
|
14
|
+
@Column({ name: 'display_name', length: 255, nullable: false, unique: false })
|
|
15
|
+
@IsNotEmpty({ message: 'Blank display names are not allowed' })
|
|
16
|
+
displayName!: string
|
|
17
|
+
|
|
18
|
+
@OneToOne(() => PartyEntity)
|
|
19
|
+
@JoinColumn({ name: 'party_id' })
|
|
20
|
+
party!: PartyEntity
|
|
21
|
+
|
|
22
|
+
@BeforeInsert()
|
|
23
|
+
@BeforeUpdate()
|
|
24
|
+
async validate(): Promise<void> {
|
|
25
|
+
const validation: Array<ValidationError> = await validate(this)
|
|
26
|
+
if (validation.length > 0) {
|
|
27
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
28
|
+
if (constraint) {
|
|
29
|
+
const message: string = Object.values(constraint!)[0]
|
|
30
|
+
return Promise.reject(Error(message))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseEntity,
|
|
3
|
+
BeforeInsert,
|
|
4
|
+
BeforeUpdate,
|
|
5
|
+
Column,
|
|
6
|
+
CreateDateColumn,
|
|
7
|
+
Entity,
|
|
8
|
+
JoinColumn,
|
|
9
|
+
ManyToOne,
|
|
10
|
+
OneToMany,
|
|
11
|
+
OneToOne,
|
|
12
|
+
PrimaryGeneratedColumn,
|
|
13
|
+
UpdateDateColumn,
|
|
14
|
+
} from 'typeorm'
|
|
15
|
+
import { ValidationConstraint } from '../../types'
|
|
16
|
+
import { IdentityEntity } from './IdentityEntity'
|
|
17
|
+
import { validate, ValidationError } from 'class-validator'
|
|
18
|
+
import { PartyTypeEntity } from './PartyTypeEntity'
|
|
19
|
+
import { BaseContactEntity } from './BaseContactEntity'
|
|
20
|
+
import { PartyRelationshipEntity } from './PartyRelationshipEntity'
|
|
21
|
+
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
22
|
+
import { ElectronicAddressEntity } from './ElectronicAddressEntity'
|
|
23
|
+
|
|
24
|
+
@Entity('Party')
|
|
25
|
+
export class PartyEntity extends BaseEntity {
|
|
26
|
+
@PrimaryGeneratedColumn('uuid')
|
|
27
|
+
id!: string
|
|
28
|
+
|
|
29
|
+
@Column({ name: 'uri', length: 255 })
|
|
30
|
+
uri?: string
|
|
31
|
+
|
|
32
|
+
@OneToMany(() => IdentityEntity, (identity: IdentityEntity) => identity.party, {
|
|
33
|
+
cascade: true,
|
|
34
|
+
onDelete: 'CASCADE',
|
|
35
|
+
eager: true,
|
|
36
|
+
nullable: false,
|
|
37
|
+
})
|
|
38
|
+
@JoinColumn({ name: 'identity_id' })
|
|
39
|
+
identities!: Array<IdentityEntity>
|
|
40
|
+
|
|
41
|
+
@OneToMany(() => ElectronicAddressEntity, (electronicAddress: ElectronicAddressEntity) => electronicAddress.party, {
|
|
42
|
+
cascade: true,
|
|
43
|
+
onDelete: 'CASCADE',
|
|
44
|
+
eager: true,
|
|
45
|
+
nullable: false,
|
|
46
|
+
})
|
|
47
|
+
@JoinColumn({ name: 'electronic_address_id' })
|
|
48
|
+
electronicAddresses!: Array<ElectronicAddressEntity>
|
|
49
|
+
|
|
50
|
+
@ManyToOne(() => PartyTypeEntity, (contactType: PartyTypeEntity) => contactType.parties, {
|
|
51
|
+
cascade: true,
|
|
52
|
+
nullable: false,
|
|
53
|
+
eager: true,
|
|
54
|
+
})
|
|
55
|
+
@JoinColumn({ name: 'party_type_id' })
|
|
56
|
+
partyType!: PartyTypeEntity
|
|
57
|
+
|
|
58
|
+
@OneToOne(() => BaseContactEntity, (contact: BaseContactEntity) => contact.party, {
|
|
59
|
+
cascade: true,
|
|
60
|
+
onDelete: 'CASCADE',
|
|
61
|
+
eager: true,
|
|
62
|
+
nullable: false,
|
|
63
|
+
})
|
|
64
|
+
contact!: BaseContactEntity
|
|
65
|
+
|
|
66
|
+
@OneToMany(() => PartyRelationshipEntity, (relationship: PartyRelationshipEntity) => relationship.left, {
|
|
67
|
+
cascade: true,
|
|
68
|
+
onDelete: 'CASCADE',
|
|
69
|
+
eager: true,
|
|
70
|
+
nullable: false,
|
|
71
|
+
})
|
|
72
|
+
@JoinColumn({ name: 'relationship_id' })
|
|
73
|
+
relationships!: Array<PartyRelationshipEntity>
|
|
74
|
+
|
|
75
|
+
@CreateDateColumn({ name: 'created_at', nullable: false })
|
|
76
|
+
createdAt!: Date
|
|
77
|
+
|
|
78
|
+
@UpdateDateColumn({ name: 'last_updated_at', nullable: false })
|
|
79
|
+
lastUpdatedAt!: Date
|
|
80
|
+
|
|
81
|
+
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
82
|
+
@BeforeInsert()
|
|
83
|
+
@BeforeUpdate()
|
|
84
|
+
updateUpdatedDate(): void {
|
|
85
|
+
this.lastUpdatedAt = new Date()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@BeforeInsert()
|
|
89
|
+
@BeforeUpdate()
|
|
90
|
+
async checkUniqueTenantId(): Promise<undefined> {
|
|
91
|
+
const result: Array<PartyEntity> = await PartyEntity.find({
|
|
92
|
+
where: {
|
|
93
|
+
partyType: {
|
|
94
|
+
tenantId: this.partyType.tenantId,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
if (result?.length > 0) {
|
|
100
|
+
return Promise.reject(Error('Tenant id already in use'))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@BeforeInsert()
|
|
107
|
+
@BeforeUpdate()
|
|
108
|
+
async validate(): Promise<void> {
|
|
109
|
+
const validation: Array<ValidationError> = await validate(this)
|
|
110
|
+
if (validation.length > 0) {
|
|
111
|
+
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
|
|
112
|
+
if (constraint) {
|
|
113
|
+
const message: string = Object.values(constraint!)[0]
|
|
114
|
+
return Promise.reject(Error(message))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Entity,
|
|
3
|
+
PrimaryGeneratedColumn,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
UpdateDateColumn,
|
|
6
|
+
ManyToOne,
|
|
7
|
+
Column,
|
|
8
|
+
Index,
|
|
9
|
+
BeforeInsert,
|
|
10
|
+
BeforeUpdate,
|
|
11
|
+
JoinColumn,
|
|
12
|
+
} from 'typeorm'
|
|
13
|
+
import { PartyEntity } from './PartyEntity'
|
|
14
|
+
|
|
15
|
+
@Entity('PartyRelationship')
|
|
16
|
+
@Index('IDX_PartyRelationship_left_right', ['left', 'right'], { unique: true })
|
|
17
|
+
export class PartyRelationshipEntity {
|
|
18
|
+
@PrimaryGeneratedColumn('uuid')
|
|
19
|
+
id!: string
|
|
20
|
+
|
|
21
|
+
@ManyToOne(() => PartyEntity, {
|
|
22
|
+
nullable: false,
|
|
23
|
+
onDelete: 'CASCADE',
|
|
24
|
+
})
|
|
25
|
+
@JoinColumn({ name: 'left_id' })
|
|
26
|
+
left!: PartyEntity
|
|
27
|
+
|
|
28
|
+
@Column({ name: 'left_id', nullable: false })
|
|
29
|
+
leftId!: string
|
|
30
|
+
|
|
31
|
+
@ManyToOne(() => PartyEntity, {
|
|
32
|
+
nullable: false,
|
|
33
|
+
onDelete: 'CASCADE',
|
|
34
|
+
})
|
|
35
|
+
@JoinColumn({ name: 'right_id' })
|
|
36
|
+
right!: PartyEntity
|
|
37
|
+
|
|
38
|
+
@Column({ name: 'right_id', nullable: false })
|
|
39
|
+
rightId!: string
|
|
40
|
+
|
|
41
|
+
@CreateDateColumn({ name: 'created_at', nullable: false })
|
|
42
|
+
createdAt!: Date
|
|
43
|
+
|
|
44
|
+
@UpdateDateColumn({ name: 'last_updated_at', nullable: false })
|
|
45
|
+
lastUpdatedAt!: Date
|
|
46
|
+
|
|
47
|
+
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
48
|
+
@BeforeInsert()
|
|
49
|
+
@BeforeUpdate()
|
|
50
|
+
updateUpdatedDate(): void {
|
|
51
|
+
this.lastUpdatedAt = new Date()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@BeforeInsert()
|
|
55
|
+
@BeforeUpdate()
|
|
56
|
+
async checkRelationshipSides(): Promise<void> {
|
|
57
|
+
if ((this.left?.id ?? this.leftId) === (this.right?.id ?? this.rightId)) {
|
|
58
|
+
return Promise.reject(Error('Cannot use the same id for both sides of the relationship'))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|