@sphereon/ssi-sdk.data-store 0.24.0 → 0.24.1-next.42

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.
Files changed (143) hide show
  1. package/dist/contact/ContactStore.d.ts +3 -0
  2. package/dist/contact/ContactStore.d.ts.map +1 -1
  3. package/dist/contact/ContactStore.js +84 -48
  4. package/dist/contact/ContactStore.js.map +1 -1
  5. package/dist/entities/contact/BaseContactEntity.d.ts +2 -0
  6. package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -1
  7. package/dist/entities/contact/BaseContactEntity.js +12 -3
  8. package/dist/entities/contact/BaseContactEntity.js.map +1 -1
  9. package/dist/entities/contact/ConnectionEntity.d.ts +2 -0
  10. package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
  11. package/dist/entities/contact/ConnectionEntity.js +8 -0
  12. package/dist/entities/contact/ConnectionEntity.js.map +1 -1
  13. package/dist/entities/contact/ContactMetadataItemEntity.d.ts +14 -0
  14. package/dist/entities/contact/ContactMetadataItemEntity.d.ts.map +1 -0
  15. package/dist/entities/contact/ContactMetadataItemEntity.js +88 -0
  16. package/dist/entities/contact/ContactMetadataItemEntity.js.map +1 -0
  17. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -0
  18. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
  19. package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -0
  20. package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
  21. package/dist/entities/contact/DidAuthConfigEntity.d.ts +2 -0
  22. package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
  23. package/dist/entities/contact/DidAuthConfigEntity.js +8 -0
  24. package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
  25. package/dist/entities/contact/ElectronicAddressEntity.d.ts +2 -0
  26. package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
  27. package/dist/entities/contact/ElectronicAddressEntity.js +8 -0
  28. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
  29. package/dist/entities/contact/IMetadataEntity.d.ts +8 -0
  30. package/dist/entities/contact/IMetadataEntity.d.ts.map +1 -0
  31. package/dist/entities/contact/IMetadataEntity.js +2 -0
  32. package/dist/entities/contact/IMetadataEntity.js.map +1 -0
  33. package/dist/entities/contact/IdentityEntity.d.ts +5 -2
  34. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
  35. package/dist/entities/contact/IdentityEntity.js +13 -0
  36. package/dist/entities/contact/IdentityEntity.js.map +1 -1
  37. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +6 -2
  38. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
  39. package/dist/entities/contact/IdentityMetadataItemEntity.js +19 -3
  40. package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
  41. package/dist/entities/contact/NaturalPersonEntity.d.ts +2 -0
  42. package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -1
  43. package/dist/entities/contact/NaturalPersonEntity.js +8 -0
  44. package/dist/entities/contact/NaturalPersonEntity.js.map +1 -1
  45. package/dist/entities/contact/OpenIdConfigEntity.d.ts +2 -0
  46. package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
  47. package/dist/entities/contact/OpenIdConfigEntity.js +8 -0
  48. package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
  49. package/dist/entities/contact/OrganizationEntity.d.ts +2 -0
  50. package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -1
  51. package/dist/entities/contact/OrganizationEntity.js +8 -0
  52. package/dist/entities/contact/OrganizationEntity.js.map +1 -1
  53. package/dist/entities/contact/PartyEntity.d.ts +2 -0
  54. package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
  55. package/dist/entities/contact/PartyEntity.js +8 -0
  56. package/dist/entities/contact/PartyEntity.js.map +1 -1
  57. package/dist/entities/contact/PartyRelationshipEntity.d.ts +2 -0
  58. package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -1
  59. package/dist/entities/contact/PartyRelationshipEntity.js +8 -0
  60. package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -1
  61. package/dist/entities/contact/PartyTypeEntity.js +4 -4
  62. package/dist/entities/contact/PartyTypeEntity.js.map +1 -1
  63. package/dist/entities/contact/PhysicalAddressEntity.d.ts +2 -0
  64. package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -1
  65. package/dist/entities/contact/PhysicalAddressEntity.js +8 -0
  66. package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -1
  67. package/dist/index.d.ts +4 -3
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +4 -1
  70. package/dist/index.js.map +1 -1
  71. package/dist/migrations/generic/8-CreateContacts.d.ts +7 -0
  72. package/dist/migrations/generic/8-CreateContacts.d.ts.map +1 -0
  73. package/dist/migrations/generic/8-CreateContacts.js +78 -0
  74. package/dist/migrations/generic/8-CreateContacts.js.map +1 -0
  75. package/dist/migrations/generic/9-CreateContacts.d.ts +7 -0
  76. package/dist/migrations/generic/9-CreateContacts.d.ts.map +1 -0
  77. package/dist/migrations/generic/9-CreateContacts.js +78 -0
  78. package/dist/migrations/generic/9-CreateContacts.js.map +1 -0
  79. package/dist/migrations/generic/index.d.ts.map +1 -1
  80. package/dist/migrations/generic/index.js +8 -1
  81. package/dist/migrations/generic/index.js.map +1 -1
  82. package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -1
  83. package/dist/migrations/postgres/1690925872592-CreateContacts.js +40 -3
  84. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
  85. package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts +7 -0
  86. package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts.map +1 -0
  87. package/dist/migrations/postgres/1710438363001-CreateContacts.js +63 -0
  88. package/dist/migrations/postgres/1710438363001-CreateContacts.js.map +1 -0
  89. package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts +7 -0
  90. package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts.map +1 -0
  91. package/dist/migrations/postgres/1715761125001-CreateContacts.js +74 -0
  92. package/dist/migrations/postgres/1715761125001-CreateContacts.js.map +1 -0
  93. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
  94. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +40 -3
  95. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  96. package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts +7 -0
  97. package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts.map +1 -0
  98. package/dist/migrations/sqlite/1710438363002-CreateContacts.js +79 -0
  99. package/dist/migrations/sqlite/1710438363002-CreateContacts.js.map +1 -0
  100. package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts +7 -0
  101. package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts.map +1 -0
  102. package/dist/migrations/sqlite/1715761125002-CreateContacts.js +73 -0
  103. package/dist/migrations/sqlite/1715761125002-CreateContacts.js.map +1 -0
  104. package/dist/types/contact/contact.d.ts +51 -15
  105. package/dist/types/contact/contact.d.ts.map +1 -1
  106. package/dist/types/contact/contact.js +12 -7
  107. package/dist/types/contact/contact.js.map +1 -1
  108. package/dist/utils/contact/MappingUtils.d.ts +6 -4
  109. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  110. package/dist/utils/contact/MappingUtils.js +128 -18
  111. package/dist/utils/contact/MappingUtils.js.map +1 -1
  112. package/package.json +4 -4
  113. package/src/__tests__/contact.entities.test.ts +129 -44
  114. package/src/__tests__/contact.store.test.ts +205 -29
  115. package/src/contact/ContactStore.ts +74 -30
  116. package/src/entities/contact/BaseContactEntity.ts +11 -0
  117. package/src/entities/contact/ConnectionEntity.ts +6 -0
  118. package/src/entities/contact/ContactMetadataItemEntity.ts +50 -0
  119. package/src/entities/contact/CorrelationIdentifierEntity.ts +6 -0
  120. package/src/entities/contact/DidAuthConfigEntity.ts +6 -0
  121. package/src/entities/contact/ElectronicAddressEntity.ts +6 -0
  122. package/src/entities/contact/IMetadataEntity.ts +7 -0
  123. package/src/entities/contact/IdentityEntity.ts +11 -2
  124. package/src/entities/contact/IdentityMetadataItemEntity.ts +16 -4
  125. package/src/entities/contact/NaturalPersonEntity.ts +6 -0
  126. package/src/entities/contact/OpenIdConfigEntity.ts +6 -0
  127. package/src/entities/contact/OrganizationEntity.ts +6 -0
  128. package/src/entities/contact/PartyEntity.ts +6 -0
  129. package/src/entities/contact/PartyRelationshipEntity.ts +6 -0
  130. package/src/entities/contact/PartyTypeEntity.ts +4 -4
  131. package/src/entities/contact/PhysicalAddressEntity.ts +6 -0
  132. package/src/index.ts +3 -0
  133. package/src/migrations/generic/8-CreateContacts.ts +66 -0
  134. package/src/migrations/generic/9-CreateContacts.ts +66 -0
  135. package/src/migrations/generic/index.ts +8 -1
  136. package/src/migrations/postgres/1690925872592-CreateContacts.ts +59 -5
  137. package/src/migrations/postgres/1710438363001-CreateContacts.ts +63 -0
  138. package/src/migrations/postgres/1715761125001-CreateContacts.ts +60 -0
  139. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +70 -3
  140. package/src/migrations/sqlite/1710438363002-CreateContacts.ts +83 -0
  141. package/src/migrations/sqlite/1715761125002-CreateContacts.ts +59 -0
  142. package/src/types/contact/contact.ts +56 -15
  143. package/src/utils/contact/MappingUtils.ts +134 -18
@@ -0,0 +1,50 @@
1
+ import { Entity, Column, PrimaryGeneratedColumn, BaseEntity, ManyToOne, BeforeInsert, BeforeUpdate } from 'typeorm'
2
+ import { ValidationConstraint } from '../../types'
3
+ import { BaseContactEntity } from './BaseContactEntity'
4
+ import { IsNotEmpty, validate, ValidationError } from 'class-validator'
5
+ import { getConstraint } from '../../utils/ValidatorUtils'
6
+
7
+ @Entity('ContactMetadata')
8
+ export class ContactMetadataItemEntity extends BaseEntity implements IMetadataEntity {
9
+ @PrimaryGeneratedColumn('uuid')
10
+ id!: string
11
+
12
+ @Column({ name: 'label', length: 255, nullable: false })
13
+ @IsNotEmpty({ message: 'Blank metadata labels are not allowed' })
14
+ label!: string
15
+
16
+ @Column({ name: 'valueType', nullable: false })
17
+ @IsNotEmpty({ message: 'valueType must not be empty' })
18
+ valueType!: string
19
+
20
+ @Column({ name: 'stringValue', length: 255, nullable: true })
21
+ stringValue?: string
22
+
23
+ @Column({ name: 'numberValue', nullable: true })
24
+ numberValue?: number
25
+
26
+ @Column({ name: 'dateValue', nullable: true })
27
+ dateValue?: Date
28
+
29
+ @Column({ name: 'boolValue', nullable: true })
30
+ boolValue?: boolean
31
+
32
+ @ManyToOne(() => BaseContactEntity, (contact: BaseContactEntity) => contact.metadata, {
33
+ cascade: ['insert', 'update'],
34
+ onDelete: 'CASCADE',
35
+ })
36
+ contact!: BaseContactEntity
37
+
38
+ @BeforeInsert()
39
+ @BeforeUpdate()
40
+ async validate(): Promise<void> {
41
+ const validation: Array<ValidationError> = await validate(this)
42
+ if (validation.length > 0) {
43
+ const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
44
+ if (constraint) {
45
+ const message: string = Object.values(constraint!)[0]
46
+ return Promise.reject(Error(message))
47
+ }
48
+ }
49
+ }
50
+ }
@@ -16,6 +16,12 @@ export class CorrelationIdentifierEntity extends BaseEntity {
16
16
  @IsNotEmpty({ message: 'Blank correlation ids are not allowed' })
17
17
  correlationId!: string
18
18
 
19
+ @Column({name: 'owner_id', nullable: true})
20
+ ownerId?: string
21
+
22
+ @Column({name: 'tenant_id', nullable: true})
23
+ tenantId?: string
24
+
19
25
  @OneToOne(() => IdentityEntity, (identity: IdentityEntity) => identity.identifier, {
20
26
  onDelete: 'CASCADE',
21
27
  })
@@ -11,4 +11,10 @@ export class DidAuthConfigEntity extends BaseConfigEntity {
11
11
 
12
12
  @Column({ name: 'session_id', length: 255, nullable: false })
13
13
  sessionId!: string
14
+
15
+ @Column({name: 'owner_id', nullable: true})
16
+ ownerId?: string
17
+
18
+ @Column({name: 'tenant_id', nullable: true})
19
+ tenantId?: string
14
20
  }
@@ -35,6 +35,12 @@ export class ElectronicAddressEntity extends BaseEntity {
35
35
  @Column({ name: 'partyId', nullable: true })
36
36
  partyId?: string
37
37
 
38
+ @Column({name: 'owner_id', nullable: true})
39
+ ownerId?: string
40
+
41
+ @Column({name: 'tenant_id', nullable: true})
42
+ tenantId?: string
43
+
38
44
  @CreateDateColumn({ name: 'created_at', nullable: false })
39
45
  createdAt!: Date
40
46
 
@@ -0,0 +1,7 @@
1
+ interface IMetadataEntity {
2
+ label: string
3
+ stringValue?: string
4
+ numberValue?: number
5
+ dateValue?: Date
6
+ boolValue?: boolean
7
+ }
@@ -16,7 +16,7 @@ import { IsNotEmpty, validate, ValidationError } from 'class-validator'
16
16
  import { CorrelationIdentifierEntity } from './CorrelationIdentifierEntity'
17
17
  import { ConnectionEntity } from './ConnectionEntity'
18
18
  import { IdentityMetadataItemEntity } from './IdentityMetadataItemEntity'
19
- import { IdentityRole, ValidationConstraint } from '../../types'
19
+ import { CredentialRole, IdentityOrigin, ValidationConstraint } from '../../types'
20
20
  import { PartyEntity } from './PartyEntity'
21
21
  import { getConstraint } from '../../utils/ValidatorUtils'
22
22
 
@@ -34,8 +34,17 @@ export class IdentityEntity extends BaseEntity {
34
34
  @IsNotEmpty({ message: 'Blank aliases are not allowed' })
35
35
  alias!: string
36
36
 
37
+ @Column('simple-enum', { name: 'origin', enum: IdentityOrigin, nullable: false })
38
+ origin!: IdentityOrigin
39
+
40
+ @Column({ name: 'owner_id', nullable: true })
41
+ ownerId?: string
42
+
43
+ @Column({ name: 'tenant_id', nullable: true })
44
+ tenantId?: string
45
+
37
46
  @Column('simple-array', { name: 'roles', nullable: false })
38
- roles!: Array<IdentityRole>
47
+ roles!: Array<CredentialRole>
39
48
 
40
49
  @OneToOne(() => CorrelationIdentifierEntity, (identifier: CorrelationIdentifierEntity) => identifier.identity, {
41
50
  cascade: true,
@@ -5,7 +5,7 @@ import { IsNotEmpty, validate, ValidationError } from 'class-validator'
5
5
  import { getConstraint } from '../../utils/ValidatorUtils'
6
6
 
7
7
  @Entity('IdentityMetadata')
8
- export class IdentityMetadataItemEntity extends BaseEntity {
8
+ export class IdentityMetadataItemEntity extends BaseEntity implements IMetadataEntity {
9
9
  @PrimaryGeneratedColumn('uuid')
10
10
  id!: string
11
11
 
@@ -13,9 +13,21 @@ export class IdentityMetadataItemEntity extends BaseEntity {
13
13
  @IsNotEmpty({ message: 'Blank metadata labels are not allowed' })
14
14
  label!: string
15
15
 
16
- @Column({ name: 'value', length: 255, nullable: false })
17
- @IsNotEmpty({ message: 'Blank metadata values are not allowed' })
18
- value!: string
16
+ @Column({ name: 'valueType', nullable: false })
17
+ @IsNotEmpty({ message: 'valueType must not be empty' })
18
+ valueType!: string
19
+
20
+ @Column({ name: 'stringValue', length: 255, nullable: true })
21
+ stringValue?: string
22
+
23
+ @Column({ name: 'numberValue', nullable: true })
24
+ numberValue?: number
25
+
26
+ @Column({ name: 'dateValue', nullable: true })
27
+ dateValue?: Date
28
+
29
+ @Column({ name: 'boolValue', nullable: true })
30
+ boolValue?: boolean
19
31
 
20
32
  @ManyToOne(() => IdentityEntity, (identity: IdentityEntity) => identity.metadata, { cascade: ['insert', 'update'], onDelete: 'CASCADE' })
21
33
  identity!: IdentityEntity
@@ -23,6 +23,12 @@ export class NaturalPersonEntity extends BaseContactEntity {
23
23
  @IsNotEmpty({ message: 'Blank display names are not allowed' })
24
24
  displayName!: string
25
25
 
26
+ @Column({name: 'owner_id', nullable: true})
27
+ ownerId?: string
28
+
29
+ @Column({name: 'tenant_id', nullable: true})
30
+ tenantId?: string
31
+
26
32
  @BeforeInsert()
27
33
  @BeforeUpdate()
28
34
  async validate(): Promise<void> {
@@ -23,4 +23,10 @@ export class OpenIdConfigEntity extends BaseConfigEntity {
23
23
 
24
24
  @Column('text', { name: 'client_auth_method', nullable: false })
25
25
  clientAuthMethod!: 'basic' | 'post' | undefined
26
+
27
+ @Column({name: 'owner_id', nullable: true})
28
+ ownerId?: string
29
+
30
+ @Column({name: 'tenant_id', nullable: true})
31
+ tenantId?: string
26
32
  }
@@ -15,6 +15,12 @@ export class OrganizationEntity extends BaseContactEntity {
15
15
  @IsNotEmpty({ message: 'Blank display names are not allowed' })
16
16
  displayName!: string
17
17
 
18
+ @Column({name: 'owner_id', nullable: true})
19
+ ownerId?: string
20
+
21
+ @Column({name: 'tenant_id', nullable: true})
22
+ tenantId?: string
23
+
18
24
  @OneToOne(() => PartyEntity)
19
25
  @JoinColumn({ name: 'party_id' })
20
26
  party!: PartyEntity
@@ -30,6 +30,12 @@ export class PartyEntity extends BaseEntity {
30
30
  @Column({ name: 'uri', length: 255, nullable: true })
31
31
  uri?: string
32
32
 
33
+ @Column({name: 'owner_id', nullable: true})
34
+ ownerId?: string
35
+
36
+ @Column({name: 'tenant_id', nullable: true})
37
+ tenantId?: string
38
+
33
39
  @OneToMany(() => IdentityEntity, (identity: IdentityEntity) => identity.party, {
34
40
  cascade: true,
35
41
  onDelete: 'CASCADE',
@@ -38,6 +38,12 @@ export class PartyRelationshipEntity {
38
38
  @Column({ name: 'right_id', nullable: false })
39
39
  rightId!: string
40
40
 
41
+ @Column({name: 'owner_id', nullable: true})
42
+ ownerId?: string
43
+
44
+ @Column({name: 'tenant_id', nullable: true})
45
+ tenantId?: string
46
+
41
47
  @CreateDateColumn({ name: 'created_at', nullable: false })
42
48
  createdAt!: Date
43
49
 
@@ -11,21 +11,21 @@ export class PartyTypeEntity {
11
11
  @PrimaryGeneratedColumn('uuid')
12
12
  id!: string
13
13
 
14
- @Column('simple-enum', { name: 'type', enum: PartyTypeType, nullable: false, unique: false })
14
+ @Column('simple-enum', { name: 'type', enum: PartyTypeType, nullable: false })
15
15
  type!: PartyTypeType
16
16
 
17
- @Column('simple-enum', { name: 'origin', enum: PartyOrigin, default: 'EXTERNAL', nullable: false, unique: false })
17
+ @Column('simple-enum', { name: 'origin', enum: PartyOrigin, nullable: false, unique: false })
18
18
  origin!: PartyOrigin
19
19
 
20
20
  @Column({ name: 'name', length: 255, nullable: false, unique: true })
21
21
  @IsNotEmpty({ message: 'Blank names are not allowed' })
22
22
  name!: string
23
23
 
24
- @Column({ name: 'description', length: 255, nullable: true, unique: false })
24
+ @Column({ name: 'description', length: 255, nullable: true })
25
25
  @Validate(IsNonEmptyStringConstraint, { message: 'Blank descriptions are not allowed' })
26
26
  description?: string
27
27
 
28
- @Column({ name: 'tenant_id', length: 255, nullable: false, unique: false })
28
+ @Column({ name: 'tenant_id', length: 255, nullable: true })
29
29
  @IsNotEmpty({ message: "Blank tenant id's are not allowed" })
30
30
  tenantId!: string
31
31
 
@@ -51,6 +51,12 @@ export class PhysicalAddressEntity extends BaseEntity {
51
51
  @IsNotEmpty({ message: 'Blank building names are not allowed' })
52
52
  buildingName?: string
53
53
 
54
+ @Column({name: 'owner_id', nullable: true})
55
+ ownerId?: string
56
+
57
+ @Column({name: 'tenant_id', nullable: true})
58
+ tenantId?: string
59
+
54
60
  @ManyToOne(() => PartyEntity, (party: PartyEntity) => party.physicalAddresses, {
55
61
  onDelete: 'CASCADE',
56
62
  })
package/src/index.ts CHANGED
@@ -34,6 +34,7 @@ export { StatusListStore } from './statusList/StatusListStore'
34
34
  import { AuditEventEntity, auditEventEntityFrom } from './entities/eventLogger/AuditEventEntity'
35
35
  import { DigitalCredentialEntity } from './entities/digitalCredential/DigitalCredentialEntity'
36
36
  import { digitalCredentialFrom, digitalCredentialsFrom, nonPersistedDigitalCredentialEntityFromAddArgs } from './utils/digitalCredential/MappingUtils'
37
+ import { ContactMetadataItemEntity } from './entities/contact/ContactMetadataItemEntity'
37
38
  export { AbstractEventLoggerStore } from './eventLogger/AbstractEventLoggerStore'
38
39
  export { EventLoggerStore } from './eventLogger/EventLoggerStore'
39
40
  export { IAbstractMachineStateStore } from './machineState/IAbstractMachineStateStore'
@@ -66,6 +67,7 @@ export const DataStoreContactEntities = [
66
67
  NaturalPersonEntity,
67
68
  ElectronicAddressEntity,
68
69
  PhysicalAddressEntity,
70
+ ContactMetadataItemEntity,
69
71
  ]
70
72
 
71
73
  export const DataStoreIssuanceBrandingEntities = [
@@ -138,4 +140,5 @@ export {
138
140
  digitalCredentialsFrom,
139
141
  nonPersistedDigitalCredentialEntityFromAddArgs,
140
142
  MachineStateInfoEntity,
143
+ ContactMetadataItemEntity,
141
144
  }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug from 'debug'
3
+ import {CreateContacts1710438363001} from "../postgres/1710438363001-CreateContacts";
4
+ import {CreateContacts1710438363002} from "../sqlite/1710438363002-CreateContacts";
5
+
6
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreateContacts1708525189000 implements MigrationInterface {
9
+ name = 'CreateContacts1708525189000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: updating contact tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreateContacts1710438363001 = new CreateContacts1710438363001()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreateContacts1710438363002 = new CreateContacts1710438363002()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting machine state tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreateContacts1710438363001 = new CreateContacts1710438363001()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreateContacts1710438363002 = new CreateContacts1710438363002()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
63
+ )
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug from 'debug'
3
+ import { CreateContacts1715761125001 } from '../postgres/1715761125001-CreateContacts'
4
+ import { CreateContacts1715761125002 } from '../sqlite/1715761125002-CreateContacts'
5
+
6
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreateContacts1715761125000 implements MigrationInterface {
9
+ name = 'CreateContacts1715761125000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: updating contact tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreateContacts1715761125001 = new CreateContacts1715761125001()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreateContacts1715761125002 = new CreateContacts1715761125002()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting machine state tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreateContacts1715761125001 = new CreateContacts1715761125001()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreateContacts1715761125002 = new CreateContacts1715761125002()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
63
+ )
64
+ }
65
+ }
66
+ }
@@ -5,6 +5,8 @@ import { CreateStatusList1693866470000 } from './4-CreateStatusList'
5
5
  import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents'
6
6
  import { CreateDigitalCredential1708525189000 } from './6-CreateDigitalCredential'
7
7
  import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStore'
8
+ import { CreateContacts1708525189000 } from './8-CreateContacts'
9
+ import { CreateContacts1715761125000 } from './9-CreateContacts'
8
10
 
9
11
  /**
10
12
  * The migrations array that SHOULD be used when initializing a TypeORM database connection.
@@ -15,7 +17,12 @@ import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStor
15
17
  */
16
18
 
17
19
  // Individual migrations per purpose. Allows parties to not run migrations and thus create/update tables if they are not using a particular feature (yet)
18
- export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318]
20
+ export const DataStoreContactMigrations = [
21
+ CreateContacts1659463079429,
22
+ CreateContacts1690925872318,
23
+ CreateContacts1708525189000,
24
+ CreateContacts1715761125000,
25
+ ]
19
26
  export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429]
20
27
  export const DataStoreStatusListMigrations = [CreateStatusList1693866470000]
21
28
  export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330]
@@ -15,7 +15,7 @@ export class CreateContacts1690925872592 implements MigrationInterface {
15
15
  await queryRunner.query(`CREATE TYPE "public"."PartyType_type_enum" AS ENUM('naturalPerson', 'organization')`)
16
16
  await queryRunner.query(`CREATE TYPE "public"."PartyOrigin_type_enum" AS ENUM('INTERNAL', 'EXTERNAL')`)
17
17
  await queryRunner.query(
18
- `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "origin" "public"."PartyOrigin_type_enum" NOT NULL DEFAULT 'EXTERNAL', "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`,
18
+ `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "origin" "public"."PartyOrigin_type_enum" NOT NULL, "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`,
19
19
  )
20
20
  await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`)
21
21
  await queryRunner.query(
@@ -30,8 +30,8 @@ export class CreateContacts1690925872592 implements MigrationInterface {
30
30
  `CREATE TABLE "ElectronicAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "electronic_address" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "partyId" uuid, CONSTRAINT "PK_ElectronicAddress_id" PRIMARY KEY ("id"))`,
31
31
  )
32
32
  await queryRunner.query(
33
- `CREATE TABLE "PhysicalAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "street_name" character varying(255) NOT NULL, "street_number" character varying(255) NOT NULL, "postal_code" character varying(255) NOT NULL, "city_name" character varying(255) NOT NULL, "province_name" character varying(255) NOT NULL, "country_code" character varying(2) NOT NULL, "building_name" character varying(255), "partyId" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_PhysicalAddress_id" PRIMARY KEY ("id"))`
34
- );
33
+ `CREATE TABLE "PhysicalAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "street_name" character varying(255) NOT NULL, "street_number" character varying(255) NOT NULL, "postal_code" character varying(255) NOT NULL, "city_name" character varying(255) NOT NULL, "province_name" character varying(255) NOT NULL, "country_code" character varying(2) NOT NULL, "building_name" character varying(255), "partyId" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_PhysicalAddress_id" PRIMARY KEY ("id"))`,
34
+ )
35
35
  await queryRunner.query(
36
36
  `CREATE TABLE "Party" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "party_type_id" uuid NOT NULL, CONSTRAINT "PK_Party_id" PRIMARY KEY ("id"))`,
37
37
  )
@@ -41,6 +41,10 @@ export class CreateContacts1690925872592 implements MigrationInterface {
41
41
  await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
42
42
  await queryRunner.query(`ALTER TABLE "Identity" RENAME COLUMN "contactId" TO "partyId"`)
43
43
  await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "roles" SET NOT NULL`)
44
+ await queryRunner.query(`CREATE TYPE "public"."IdentityOrigin_type_enum" AS ENUM('INTERNAL', 'EXTERNAL')`)
45
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "origin" "public"."IdentityOrigin_type_enum" DEFAULT 'EXTERNAL' NOT NULL`)
46
+ await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "origin" DROP DEFAULT`)
47
+
44
48
  await queryRunner.query(
45
49
  `ALTER TABLE "CorrelationIdentifier" ADD CONSTRAINT "FK_CorrelationIdentifier_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
46
50
  )
@@ -98,7 +102,57 @@ export class CreateContacts1690925872592 implements MigrationInterface {
98
102
  }
99
103
 
100
104
  public async down(queryRunner: QueryRunner): Promise<void> {
101
- // TODO DPP-27 implement downgrade
102
- return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`))
105
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP CONSTRAINT "FK_BaseConfig_connection_id"`)
106
+ await queryRunner.query(`ALTER TABLE "Connection" DROP CONSTRAINT "FK_Connection_identity_id"`)
107
+ await queryRunner.query(`ALTER TABLE "Identity" DROP CONSTRAINT "FK_Identity_partyId"`)
108
+ await queryRunner.query(`ALTER TABLE "Party" DROP CONSTRAINT "FK_Party_party_type_id"`)
109
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP CONSTRAINT "FK_PhysicalAddress_partyId"`)
110
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP CONSTRAINT "FK_ElectronicAddress_partyId"`)
111
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP CONSTRAINT "FK_PartyRelationship_right_id"`)
112
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP CONSTRAINT "FK_PartyRelationship_left_id"`)
113
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP CONSTRAINT "FK_BaseContact_party_id"`)
114
+ await queryRunner.query(`ALTER TABLE "IdentityMetadata" DROP CONSTRAINT "FK_IdentityMetadata_identityId"`)
115
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP CONSTRAINT "FK_CorrelationIdentifier_identity_id"`)
116
+
117
+ await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "roles" DROP NOT NULL`)
118
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "origin"`)
119
+ await queryRunner.query(`DROP TYPE "public"."IdentityOrigin_type_enum"`)
120
+ await queryRunner.query(`ALTER TABLE "Identity" RENAME COLUMN "partyId" TO "contactId"`)
121
+ await queryRunner.query(`ALTER TABLE "Connection" RENAME COLUMN "identity_id" TO "identityId"`)
122
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" RENAME COLUMN "identity_id" TO "identityId"`)
123
+
124
+ await queryRunner.query(`DROP INDEX "IDX_BaseConfig_type"`)
125
+ await queryRunner.query(`DROP TABLE "BaseConfig"`)
126
+ await queryRunner.query(`DROP TABLE "Party"`)
127
+ await queryRunner.query(`DROP INDEX "IDX_PartyRelationship_left_right"`)
128
+ await queryRunner.query(`DROP TABLE "PartyRelationship"`)
129
+ await queryRunner.query(`DROP INDEX "IDX_BaseContact_type"`)
130
+ await queryRunner.query(`DROP TABLE "BaseContact"`)
131
+ await queryRunner.query(`DROP TABLE "ElectronicAddress"`)
132
+ await queryRunner.query(`DROP TABLE "PhysicalAddress"`)
133
+ await queryRunner.query(`DROP INDEX "IDX_PartyType_type_tenant_id"`)
134
+ await queryRunner.query(`DROP TABLE "PartyType"`)
135
+ await queryRunner.query(`DROP TYPE "public"."PartyOrigin_type_enum"`)
136
+ await queryRunner.query(`DROP TYPE "public"."PartyType_type_enum"`)
137
+
138
+ await queryRunner.query(
139
+ `ALTER TABLE "Connection" ADD CONSTRAINT "FK_Connection_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
140
+ )
141
+ await queryRunner.query(
142
+ `ALTER TABLE "Identity" ADD CONSTRAINT "FK_Identity_contactId" FOREIGN KEY ("contactId") REFERENCES "Contact"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
143
+ )
144
+ await queryRunner.query(
145
+ `ALTER TABLE "IdentityMetadata" ADD CONSTRAINT "FK_IdentityMetadata_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
146
+ )
147
+ await queryRunner.query(
148
+ `ALTER TABLE "CorrelationIdentifier" ADD CONSTRAINT "FK_CorrelationIdentifier_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
149
+ )
150
+
151
+ await queryRunner.query(
152
+ `CREATE TABLE "Contact" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying(255), "alias" character varying(255), CONSTRAINT "PK_Contact_id" PRIMARY KEY ("id"))`,
153
+ )
154
+ await queryRunner.query(
155
+ `INSERT INTO "Contact"(id, uri, created_at, last_updated_at, name, alias) SELECT id, uri, created_at, last_updated_at, (SELECT legal_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id"), (SELECT display_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id") FROM "Party" WHERE party_type_id = '3875c12e-fdaa-4ef6-a340-c936e054b627'`,
156
+ )
103
157
  }
104
158
  }
@@ -0,0 +1,63 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+
3
+ export class CreateContacts1710438363001 implements MigrationInterface {
4
+ name = 'CreateContacts1710438363001'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "owner_id" uuid`)
8
+ await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "tenant_id" uuid`)
9
+
10
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "owner_id" uuid`)
11
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "tenant_id" uuid`)
12
+
13
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "owner_id" uuid`)
14
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "tenant_id" uuid`)
15
+
16
+ await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "owner_id" uuid`)
17
+ await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "tenant_id" uuid`)
18
+
19
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "owner_id" uuid`)
20
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "tenant_id" uuid`)
21
+
22
+ await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "owner_id" uuid`)
23
+ await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "tenant_id" uuid`)
24
+
25
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "owner_id" uuid`)
26
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "tenant_id" uuid`)
27
+
28
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "owner_id" uuid`)
29
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "tenant_id" uuid`)
30
+
31
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "owner_id" uuid`)
32
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "tenant_id" uuid`)
33
+ }
34
+
35
+ public async down(queryRunner: QueryRunner): Promise<void> {
36
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "tenant_id"`)
37
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "owner_id"`)
38
+
39
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "tenant_id"`)
40
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "owner_id"`)
41
+
42
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "tenant_id"`)
43
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "owner_id"`)
44
+
45
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "tenant_id"`)
46
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "owner_id"`)
47
+
48
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "tenant_id"`)
49
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "owner_id"`)
50
+
51
+ await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "tenant_id"`)
52
+ await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "owner_id"`)
53
+
54
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "tenant_id"`)
55
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "owner_id"`)
56
+
57
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "tenant_id"`)
58
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "owner_id"`)
59
+
60
+ await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "tenant_id"`)
61
+ await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "owner_id"`)
62
+ }
63
+ }