@sphereon/ssi-sdk.data-store 0.37.1 → 0.37.2-next.14
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/index.cjs +1544 -502
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -5
- package/dist/index.d.ts +84 -5
- package/dist/index.js +1457 -415
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/credential-design-store.test.ts +419 -0
- package/src/__tests__/credential-design.entities.test.ts +205 -0
- package/src/__tests__/issuanceBranding.entities.test.ts +1 -1
- package/src/__tests__/issuanceBranding.store.test.ts +1 -1
- package/src/credentialDesign/CredentialDesignStore.ts +201 -0
- package/src/entities/credentialDesign/CredentialDesignBrandingEntity.ts +39 -0
- package/src/entities/credentialDesign/FormStepEntity.ts +32 -0
- package/src/entities/credentialDesign/MetaDataKeyEntity.ts +30 -0
- package/src/entities/credentialDesign/MetaDataSetEntity.ts +39 -0
- package/src/entities/credentialDesign/MetaDataValueEntity.ts +30 -0
- package/src/entities/credentialDesign/SchemaDefinitionEntity.ts +36 -0
- package/src/entities/credentialDesign/index.ts +6 -0
- package/src/index.ts +26 -0
- package/src/migrations/generic/18-AddCredentialDesigns.ts +64 -0
- package/src/migrations/generic/index.ts +5 -2
- package/src/migrations/index.ts +1 -0
- package/src/migrations/postgres/1773657426000-AddCredentialDesigns.ts +208 -0
- package/src/migrations/sqlite/1773657426000-AddCredentialDesigns.ts +55 -0
- package/src/utils/credentialDesign/MappingUtils.ts +147 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractCredentialDesignStore,
|
|
3
|
+
AddCredentialDesignArgs,
|
|
4
|
+
CredentialDesign,
|
|
5
|
+
GetCredentialDesignArgs,
|
|
6
|
+
GetCredentialDesignsArgs,
|
|
7
|
+
NonPersistedCredentialDesignBranding,
|
|
8
|
+
NonPersistedMetaDataKey,
|
|
9
|
+
NonPersistedSchemaDefinition,
|
|
10
|
+
RemoveCredentialDesignArgs,
|
|
11
|
+
UpdateCredentialDesignArgs,
|
|
12
|
+
} from '@sphereon/ssi-sdk.data-store-types'
|
|
13
|
+
import { OrPromise } from '@sphereon/ssi-types'
|
|
14
|
+
import Debug from 'debug'
|
|
15
|
+
import { DataSource, EntityManager, Repository } from 'typeorm'
|
|
16
|
+
import { MetaDataSetEntity, MetaDataKeyEntity, MetaDataValueEntity, SchemaDefinitionEntity, CredentialDesignBrandingEntity } from '../entities/credentialDesign'
|
|
17
|
+
import { ImageAttributesEntity } from '../entities/issuanceBranding/ImageAttributesEntity'
|
|
18
|
+
import { ImageDimensionsEntity } from '../entities/issuanceBranding/ImageDimensionsEntity'
|
|
19
|
+
import {
|
|
20
|
+
credentialDesignBrandingEntityFrom,
|
|
21
|
+
credentialDesignFrom,
|
|
22
|
+
metaDataKeyEntityFrom,
|
|
23
|
+
schemaDefinitionEntityFrom,
|
|
24
|
+
} from '../utils/credentialDesign/MappingUtils'
|
|
25
|
+
|
|
26
|
+
const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:credential-design-store')
|
|
27
|
+
|
|
28
|
+
export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
29
|
+
private readonly dbConnection: OrPromise<DataSource>
|
|
30
|
+
|
|
31
|
+
constructor(dbConnection: OrPromise<DataSource>) {
|
|
32
|
+
super()
|
|
33
|
+
this.dbConnection = dbConnection
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getCredentialDesign = async (args: GetCredentialDesignArgs): Promise<CredentialDesign> => {
|
|
37
|
+
const { credentialDesignId } = args
|
|
38
|
+
debug('getCredentialDesign', credentialDesignId)
|
|
39
|
+
const repo: Repository<MetaDataSetEntity> = (await this.dbConnection).getRepository(MetaDataSetEntity)
|
|
40
|
+
const result = await repo.findOne({
|
|
41
|
+
where: { id: credentialDesignId },
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (!result) {
|
|
45
|
+
return Promise.reject(Error(`No credential design found for id: ${credentialDesignId}`))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return credentialDesignFrom(result)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getCredentialDesigns = async (args?: GetCredentialDesignsArgs): Promise<Array<CredentialDesign>> => {
|
|
52
|
+
debug('getCredentialDesigns', args)
|
|
53
|
+
const repo: Repository<MetaDataSetEntity> = (await this.dbConnection).getRepository(MetaDataSetEntity)
|
|
54
|
+
const where = args?.filter?.tenantId ? { tenantId: args.filter.tenantId } : undefined
|
|
55
|
+
const results = await repo.find({ where })
|
|
56
|
+
return results.map(credentialDesignFrom)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
addCredentialDesign = async (args: AddCredentialDesignArgs): Promise<CredentialDesign> => {
|
|
60
|
+
debug('addCredentialDesign', args)
|
|
61
|
+
const dataSource = await this.dbConnection
|
|
62
|
+
|
|
63
|
+
return dataSource.transaction(async (transactionalEntityManager) => {
|
|
64
|
+
const metaDataSet = new MetaDataSetEntity()
|
|
65
|
+
metaDataSet.name = args.name
|
|
66
|
+
metaDataSet.tenantId = args.tenantId
|
|
67
|
+
metaDataSet.metaDataKeys = []
|
|
68
|
+
metaDataSet.schemaDefinitions = []
|
|
69
|
+
|
|
70
|
+
const { design } = args
|
|
71
|
+
if (design) {
|
|
72
|
+
if (design.metaDataKeys) {
|
|
73
|
+
metaDataSet.metaDataKeys = design.metaDataKeys.map(metaDataKeyEntityFrom)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (design.schemaDefinitions) {
|
|
77
|
+
metaDataSet.schemaDefinitions = design.schemaDefinitions.map(schemaDefinitionEntityFrom)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (design.branding) {
|
|
81
|
+
metaDataSet.credentialDesignBranding = credentialDesignBrandingEntityFrom(design.branding)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const saved = await transactionalEntityManager.save(MetaDataSetEntity, metaDataSet)
|
|
86
|
+
return credentialDesignFrom(saved)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updateCredentialDesign = async (args: UpdateCredentialDesignArgs): Promise<CredentialDesign> => {
|
|
91
|
+
debug('updateCredentialDesign', args)
|
|
92
|
+
const dataSource = await this.dbConnection
|
|
93
|
+
|
|
94
|
+
return dataSource.transaction(async (transactionalEntityManager) => {
|
|
95
|
+
const existing = await transactionalEntityManager.findOne(MetaDataSetEntity, {
|
|
96
|
+
where: { id: args.credentialDesignId },
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
if (!existing) {
|
|
100
|
+
return Promise.reject(Error(`No credential design found for id: ${args.credentialDesignId}`))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (args.name !== undefined) {
|
|
104
|
+
existing.name = args.name
|
|
105
|
+
}
|
|
106
|
+
if (args.tenantId !== undefined) {
|
|
107
|
+
existing.tenantId = args.tenantId
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { design } = args
|
|
111
|
+
if (design) {
|
|
112
|
+
if (design.metaDataKeys !== undefined) {
|
|
113
|
+
await this.replaceMetaDataKeys(transactionalEntityManager, existing, design.metaDataKeys)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (design.schemaDefinitions !== undefined) {
|
|
117
|
+
await this.replaceSchemaDefinitions(transactionalEntityManager, existing, design.schemaDefinitions)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (design.branding !== undefined) {
|
|
121
|
+
await this.replaceBranding(transactionalEntityManager, existing, design.branding)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const saved = await transactionalEntityManager.save(MetaDataSetEntity, existing)
|
|
126
|
+
return credentialDesignFrom(saved)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
removeCredentialDesign = async (args: RemoveCredentialDesignArgs): Promise<void> => {
|
|
131
|
+
debug('removeCredentialDesign', args)
|
|
132
|
+
const repo: Repository<MetaDataSetEntity> = (await this.dbConnection).getRepository(MetaDataSetEntity)
|
|
133
|
+
const existing = await repo.findOne({
|
|
134
|
+
where: { id: args.credentialDesignId },
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
if (!existing) {
|
|
138
|
+
return Promise.reject(Error(`No credential design found for id: ${args.credentialDesignId}`))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await repo.remove(existing)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async replaceMetaDataKeys(
|
|
145
|
+
entityManager: EntityManager,
|
|
146
|
+
existing: MetaDataSetEntity,
|
|
147
|
+
newKeys: Array<NonPersistedMetaDataKey>,
|
|
148
|
+
): Promise<void> {
|
|
149
|
+
if (existing.metaDataKeys?.length) {
|
|
150
|
+
for (const key of existing.metaDataKeys) {
|
|
151
|
+
if (key.metaDataValues?.length) {
|
|
152
|
+
await entityManager.remove(MetaDataValueEntity, key.metaDataValues)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
await entityManager.remove(MetaDataKeyEntity, existing.metaDataKeys)
|
|
156
|
+
}
|
|
157
|
+
existing.metaDataKeys = newKeys.map(metaDataKeyEntityFrom)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private async replaceSchemaDefinitions(
|
|
161
|
+
entityManager: EntityManager,
|
|
162
|
+
existing: MetaDataSetEntity,
|
|
163
|
+
newSchemas: Array<NonPersistedSchemaDefinition>,
|
|
164
|
+
): Promise<void> {
|
|
165
|
+
if (existing.schemaDefinitions?.length) {
|
|
166
|
+
await entityManager.remove(SchemaDefinitionEntity, existing.schemaDefinitions)
|
|
167
|
+
}
|
|
168
|
+
existing.schemaDefinitions = newSchemas.map(schemaDefinitionEntityFrom)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private async replaceBranding(
|
|
172
|
+
entityManager: EntityManager,
|
|
173
|
+
existing: MetaDataSetEntity,
|
|
174
|
+
newBranding: NonPersistedCredentialDesignBranding | undefined,
|
|
175
|
+
): Promise<void> {
|
|
176
|
+
if (existing.credentialDesignBranding) {
|
|
177
|
+
const oldLogo = existing.credentialDesignBranding.logo
|
|
178
|
+
const oldBackgroundImage = existing.credentialDesignBranding.backgroundImage
|
|
179
|
+
await entityManager.remove(CredentialDesignBrandingEntity, existing.credentialDesignBranding)
|
|
180
|
+
await this.removeImageEntity(entityManager, oldLogo)
|
|
181
|
+
await this.removeImageEntity(entityManager, oldBackgroundImage)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (newBranding) {
|
|
185
|
+
existing.credentialDesignBranding = credentialDesignBrandingEntityFrom(newBranding)
|
|
186
|
+
} else {
|
|
187
|
+
existing.credentialDesignBranding = undefined
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private async removeImageEntity(entityManager: EntityManager, image: ImageAttributesEntity | undefined): Promise<void> {
|
|
192
|
+
if (!image) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
const dimensions = image.dimensions
|
|
196
|
+
await entityManager.remove(ImageAttributesEntity, image)
|
|
197
|
+
if (dimensions) {
|
|
198
|
+
await entityManager.remove(ImageDimensionsEntity, dimensions)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { ImageAttributesEntity } from '../issuanceBranding/ImageAttributesEntity'
|
|
3
|
+
import { MetaDataSetEntity } from './MetaDataSetEntity'
|
|
4
|
+
|
|
5
|
+
@Entity('credential_design_branding')
|
|
6
|
+
export class CredentialDesignBrandingEntity extends BaseEntity {
|
|
7
|
+
@PrimaryGeneratedColumn('uuid')
|
|
8
|
+
id!: string
|
|
9
|
+
|
|
10
|
+
@Column('text', { name: 'text_color', nullable: true })
|
|
11
|
+
textColor?: string
|
|
12
|
+
|
|
13
|
+
@Column('text', { name: 'background_color', nullable: true })
|
|
14
|
+
backgroundColor?: string
|
|
15
|
+
|
|
16
|
+
@ManyToOne(() => ImageAttributesEntity, {
|
|
17
|
+
cascade: true,
|
|
18
|
+
eager: true,
|
|
19
|
+
nullable: true,
|
|
20
|
+
onDelete: 'SET NULL',
|
|
21
|
+
})
|
|
22
|
+
@JoinColumn({ name: 'logo' })
|
|
23
|
+
logo?: ImageAttributesEntity
|
|
24
|
+
|
|
25
|
+
@ManyToOne(() => ImageAttributesEntity, {
|
|
26
|
+
cascade: true,
|
|
27
|
+
eager: true,
|
|
28
|
+
nullable: true,
|
|
29
|
+
onDelete: 'SET NULL',
|
|
30
|
+
})
|
|
31
|
+
@JoinColumn({ name: 'background_image' })
|
|
32
|
+
backgroundImage?: ImageAttributesEntity
|
|
33
|
+
|
|
34
|
+
@OneToOne(() => MetaDataSetEntity, (set: MetaDataSetEntity) => set.credentialDesignBranding, {
|
|
35
|
+
onDelete: 'CASCADE',
|
|
36
|
+
})
|
|
37
|
+
@JoinColumn({ name: 'meta_data_set_id' })
|
|
38
|
+
metaDataSet!: MetaDataSetEntity
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseEntity, Column, Entity, Index, JoinTable, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { SchemaDefinitionEntity } from './SchemaDefinitionEntity'
|
|
3
|
+
|
|
4
|
+
@Entity('form_step')
|
|
5
|
+
@Index('formstep_unique_step', ['stepNr', 'formId', 'order'], { unique: true })
|
|
6
|
+
export class FormStepEntity extends BaseEntity {
|
|
7
|
+
@PrimaryGeneratedColumn('uuid')
|
|
8
|
+
id!: string
|
|
9
|
+
|
|
10
|
+
@Column('varchar', { name: 'tenant_id', nullable: true })
|
|
11
|
+
tenantId?: string
|
|
12
|
+
|
|
13
|
+
@Column('text', { name: 'form_id', nullable: true })
|
|
14
|
+
formId?: string
|
|
15
|
+
|
|
16
|
+
@Column('integer', { name: 'step_nr', nullable: true })
|
|
17
|
+
stepNr?: number
|
|
18
|
+
|
|
19
|
+
@Column('integer', { name: 'order', nullable: true })
|
|
20
|
+
order?: number
|
|
21
|
+
|
|
22
|
+
@ManyToMany(() => SchemaDefinitionEntity, (schema: SchemaDefinitionEntity) => schema.formSteps, {
|
|
23
|
+
cascade: true,
|
|
24
|
+
eager: true,
|
|
25
|
+
})
|
|
26
|
+
@JoinTable({
|
|
27
|
+
name: 'form_step_to_schema_definition',
|
|
28
|
+
joinColumn: { name: 'form_step_id', referencedColumnName: 'id' },
|
|
29
|
+
inverseJoinColumn: { name: 'schema_definition_id', referencedColumnName: 'id' },
|
|
30
|
+
})
|
|
31
|
+
schemaDefinitions!: Array<SchemaDefinitionEntity>
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { ValueType } from '@sphereon/ssi-sdk.data-store-types'
|
|
2
|
+
import { ValueType } from '@sphereon/ssi-sdk.data-store-types'
|
|
3
|
+
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm'
|
|
4
|
+
import { MetaDataSetEntity } from './MetaDataSetEntity'
|
|
5
|
+
import { MetaDataValueEntity } from './MetaDataValueEntity'
|
|
6
|
+
|
|
7
|
+
@Entity('meta_data_keys')
|
|
8
|
+
export class MetaDataKeyEntity extends BaseEntity {
|
|
9
|
+
@PrimaryGeneratedColumn('uuid')
|
|
10
|
+
id!: string
|
|
11
|
+
|
|
12
|
+
@Column('simple-enum', { name: 'value_type', enum: ValueType, nullable: false })
|
|
13
|
+
valueType!: ValueType
|
|
14
|
+
|
|
15
|
+
@Column('text', { name: 'key', nullable: false })
|
|
16
|
+
key!: string
|
|
17
|
+
|
|
18
|
+
@ManyToOne(() => MetaDataSetEntity, (set: MetaDataSetEntity) => set.metaDataKeys, {
|
|
19
|
+
onDelete: 'CASCADE',
|
|
20
|
+
})
|
|
21
|
+
@JoinColumn({ name: 'set_id' })
|
|
22
|
+
set!: MetaDataSetEntity
|
|
23
|
+
|
|
24
|
+
@OneToMany(() => MetaDataValueEntity, (value: MetaDataValueEntity) => value.metaDataKey, {
|
|
25
|
+
cascade: true,
|
|
26
|
+
onDelete: 'CASCADE',
|
|
27
|
+
eager: true,
|
|
28
|
+
})
|
|
29
|
+
metaDataValues!: Array<MetaDataValueEntity>
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseEntity, Column, Entity, Index, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { MetaDataKeyEntity } from './MetaDataKeyEntity'
|
|
3
|
+
import { SchemaDefinitionEntity } from './SchemaDefinitionEntity'
|
|
4
|
+
import { CredentialDesignBrandingEntity } from './CredentialDesignBrandingEntity'
|
|
5
|
+
|
|
6
|
+
@Entity('meta_data_set')
|
|
7
|
+
@Index('meta_data_set_unique_tenant', ['name', 'tenantId'], { unique: true })
|
|
8
|
+
export class MetaDataSetEntity extends BaseEntity {
|
|
9
|
+
@PrimaryGeneratedColumn('uuid')
|
|
10
|
+
id!: string
|
|
11
|
+
|
|
12
|
+
@Column('varchar', { name: 'tenant_id', nullable: true })
|
|
13
|
+
tenantId?: string
|
|
14
|
+
|
|
15
|
+
@Column('text', { name: 'name', nullable: false })
|
|
16
|
+
name!: string
|
|
17
|
+
|
|
18
|
+
@OneToMany(() => MetaDataKeyEntity, (key: MetaDataKeyEntity) => key.set, {
|
|
19
|
+
cascade: true,
|
|
20
|
+
onDelete: 'CASCADE',
|
|
21
|
+
eager: true,
|
|
22
|
+
})
|
|
23
|
+
metaDataKeys!: Array<MetaDataKeyEntity>
|
|
24
|
+
|
|
25
|
+
@OneToMany(() => SchemaDefinitionEntity, (schema: SchemaDefinitionEntity) => schema.metaDataSet, {
|
|
26
|
+
cascade: true,
|
|
27
|
+
onDelete: 'CASCADE',
|
|
28
|
+
eager: true,
|
|
29
|
+
})
|
|
30
|
+
schemaDefinitions!: Array<SchemaDefinitionEntity>
|
|
31
|
+
|
|
32
|
+
@OneToOne(() => CredentialDesignBrandingEntity, (branding: CredentialDesignBrandingEntity) => branding.metaDataSet, {
|
|
33
|
+
cascade: true,
|
|
34
|
+
onDelete: 'CASCADE',
|
|
35
|
+
eager: true,
|
|
36
|
+
nullable: true,
|
|
37
|
+
})
|
|
38
|
+
credentialDesignBranding?: CredentialDesignBrandingEntity
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
3
|
+
import { MetaDataKeyEntity } from './MetaDataKeyEntity'
|
|
4
|
+
|
|
5
|
+
@Entity('meta_data_values')
|
|
6
|
+
export class MetaDataValueEntity extends BaseEntity {
|
|
7
|
+
@PrimaryGeneratedColumn('uuid')
|
|
8
|
+
id!: string
|
|
9
|
+
|
|
10
|
+
@Column('integer', { name: 'index', nullable: true })
|
|
11
|
+
index?: number
|
|
12
|
+
|
|
13
|
+
@Column('text', { name: 'text_value', nullable: true })
|
|
14
|
+
textValue?: string
|
|
15
|
+
|
|
16
|
+
@Column('numeric', { name: 'number_value', nullable: true })
|
|
17
|
+
numberValue?: number
|
|
18
|
+
|
|
19
|
+
@Column('boolean', { name: 'boolean_value', nullable: true })
|
|
20
|
+
booleanValue?: boolean
|
|
21
|
+
|
|
22
|
+
@Column({ name: 'timestamp_value', nullable: true, type: typeOrmDateTime() })
|
|
23
|
+
timestampValue?: Date
|
|
24
|
+
|
|
25
|
+
@ManyToOne(() => MetaDataKeyEntity, (key: MetaDataKeyEntity) => key.metaDataValues, {
|
|
26
|
+
onDelete: 'CASCADE',
|
|
27
|
+
})
|
|
28
|
+
@JoinColumn({ name: 'key_id' })
|
|
29
|
+
metaDataKey!: MetaDataKeyEntity
|
|
30
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseEntity, Column, Entity, JoinColumn, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { MetaDataSetEntity } from './MetaDataSetEntity'
|
|
3
|
+
import { FormStepEntity } from './FormStepEntity'
|
|
4
|
+
|
|
5
|
+
@Entity('schema_definition')
|
|
6
|
+
export class SchemaDefinitionEntity extends BaseEntity {
|
|
7
|
+
@PrimaryGeneratedColumn('uuid')
|
|
8
|
+
id!: string
|
|
9
|
+
|
|
10
|
+
@Column('varchar', { name: 'tenant_id', nullable: true })
|
|
11
|
+
tenantId?: string
|
|
12
|
+
|
|
13
|
+
@Column('varchar', { name: 'extends_id', nullable: true })
|
|
14
|
+
extendsId?: string
|
|
15
|
+
|
|
16
|
+
@Column('text', { name: 'correlation_id', nullable: true })
|
|
17
|
+
correlationId?: string
|
|
18
|
+
|
|
19
|
+
@Column('text', { name: 'schema_type', nullable: true })
|
|
20
|
+
schemaType?: string
|
|
21
|
+
|
|
22
|
+
@Column('text', { name: 'entity_type', nullable: true })
|
|
23
|
+
entityType?: string
|
|
24
|
+
|
|
25
|
+
@Column('text', { name: 'schema', nullable: false })
|
|
26
|
+
schema!: string
|
|
27
|
+
|
|
28
|
+
@ManyToOne(() => MetaDataSetEntity, (set: MetaDataSetEntity) => set.schemaDefinitions, {
|
|
29
|
+
onDelete: 'CASCADE',
|
|
30
|
+
})
|
|
31
|
+
@JoinColumn({ name: 'meta_data_set_id' })
|
|
32
|
+
metaDataSet!: MetaDataSetEntity
|
|
33
|
+
|
|
34
|
+
@ManyToMany(() => FormStepEntity, (formStep: FormStepEntity) => formStep.schemaDefinitions)
|
|
35
|
+
formSteps!: Array<FormStepEntity>
|
|
36
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MetaDataSetEntity } from './MetaDataSetEntity'
|
|
2
|
+
export { MetaDataKeyEntity, ValueType } from './MetaDataKeyEntity'
|
|
3
|
+
export { MetaDataValueEntity } from './MetaDataValueEntity'
|
|
4
|
+
export { FormStepEntity } from './FormStepEntity'
|
|
5
|
+
export { SchemaDefinitionEntity } from './SchemaDefinitionEntity'
|
|
6
|
+
export { CredentialDesignBrandingEntity } from './CredentialDesignBrandingEntity'
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,12 @@ import { IssuerBrandingEntity } from './entities/issuanceBranding/IssuerBranding
|
|
|
29
29
|
import { IssuerLocaleBrandingEntity } from './entities/issuanceBranding/IssuerLocaleBrandingEntity'
|
|
30
30
|
import { TextAttributesEntity } from './entities/issuanceBranding/TextAttributesEntity'
|
|
31
31
|
import { MachineStateInfoEntity } from './entities/machineState/MachineStateInfoEntity'
|
|
32
|
+
import { MetaDataSetEntity } from './entities/credentialDesign/MetaDataSetEntity'
|
|
33
|
+
import { MetaDataKeyEntity } from './entities/credentialDesign/MetaDataKeyEntity'
|
|
34
|
+
import { MetaDataValueEntity } from './entities/credentialDesign/MetaDataValueEntity'
|
|
35
|
+
import { FormStepEntity } from './entities/credentialDesign/FormStepEntity'
|
|
36
|
+
import { SchemaDefinitionEntity } from './entities/credentialDesign/SchemaDefinitionEntity'
|
|
37
|
+
import { CredentialDesignBrandingEntity } from './entities/credentialDesign/CredentialDesignBrandingEntity'
|
|
32
38
|
|
|
33
39
|
import { Oid4vcStateEntity } from './entities/oid4vcState/Oid4vcStateEntity'
|
|
34
40
|
import { DcqlQueryItemEntity } from './entities/presentationDefinition/DcqlQueryItemEntity'
|
|
@@ -45,6 +51,7 @@ export { AbstractEventLoggerStore } from '@sphereon/ssi-sdk.data-store-types'
|
|
|
45
51
|
export { EventLoggerStore } from './eventLogger/EventLoggerStore'
|
|
46
52
|
export { MachineStateStore } from './machineState/MachineStateStore'
|
|
47
53
|
export { PDStore } from './presentationDefinition/PDStore'
|
|
54
|
+
export { CredentialDesignStore } from './credentialDesign/CredentialDesignStore'
|
|
48
55
|
export {
|
|
49
56
|
DataStoreMigrations,
|
|
50
57
|
DataStoreEventLoggerMigrations,
|
|
@@ -55,6 +62,7 @@ export {
|
|
|
55
62
|
DataStoreMachineStateMigrations,
|
|
56
63
|
DataStorePresentationDefinitionMigrations,
|
|
57
64
|
DataStoreServiceMigrations,
|
|
65
|
+
DataStoreCredentialDesignMigrations,
|
|
58
66
|
DataStoreMigrationsWithVeramo,
|
|
59
67
|
VeramoDataStoreMigrations,
|
|
60
68
|
VeramoDataStoreEntities,
|
|
@@ -116,6 +124,15 @@ export const DataStoreDigitalCredentialEntities = [DigitalCredentialEntity]
|
|
|
116
124
|
|
|
117
125
|
export const DataStoreMachineStateEntities = [MachineStateInfoEntity]
|
|
118
126
|
|
|
127
|
+
export const DataStoreCredentialDesignEntities = [
|
|
128
|
+
MetaDataSetEntity,
|
|
129
|
+
MetaDataKeyEntity,
|
|
130
|
+
MetaDataValueEntity,
|
|
131
|
+
FormStepEntity,
|
|
132
|
+
SchemaDefinitionEntity,
|
|
133
|
+
CredentialDesignBrandingEntity,
|
|
134
|
+
]
|
|
135
|
+
|
|
119
136
|
// All entities combined if a party wants to enable them all at once
|
|
120
137
|
export const DataStoreEntities = [
|
|
121
138
|
...DataStoreContactEntities,
|
|
@@ -125,6 +142,7 @@ export const DataStoreEntities = [
|
|
|
125
142
|
...DataStoreDigitalCredentialEntities,
|
|
126
143
|
...DataStoreMachineStateEntities,
|
|
127
144
|
...DataStorePresentationDefinitionEntities,
|
|
145
|
+
...DataStoreCredentialDesignEntities,
|
|
128
146
|
// ...DataStoreOid4vcStateEntities,
|
|
129
147
|
]
|
|
130
148
|
|
|
@@ -169,4 +187,12 @@ export {
|
|
|
169
187
|
ContactMetadataItemEntity,
|
|
170
188
|
CredentialClaimsEntity,
|
|
171
189
|
Oid4vcStateEntity,
|
|
190
|
+
MetaDataSetEntity,
|
|
191
|
+
MetaDataKeyEntity,
|
|
192
|
+
MetaDataValueEntity,
|
|
193
|
+
FormStepEntity,
|
|
194
|
+
SchemaDefinitionEntity,
|
|
195
|
+
CredentialDesignBrandingEntity,
|
|
172
196
|
}
|
|
197
|
+
|
|
198
|
+
export { ValueType } from './entities/credentialDesign/MetaDataKeyEntity'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Debug from 'debug'
|
|
2
|
+
import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
|
|
3
|
+
import { AddCredentialDesignsPostgres1773657426000 } from '../postgres/1773657426000-AddCredentialDesigns'
|
|
4
|
+
import { AddCredentialDesignsSqlite1773657426000 } from '../sqlite/1773657426000-AddCredentialDesigns'
|
|
5
|
+
|
|
6
|
+
const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
|
|
7
|
+
|
|
8
|
+
export class AddCredentialDesigns1773657426000 implements MigrationInterface {
|
|
9
|
+
name = 'AddCredentialDesigns1773657426000'
|
|
10
|
+
|
|
11
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
12
|
+
debug('migration: adding credential designs')
|
|
13
|
+
const dbType: DatabaseType = queryRunner.connection.driver.options.type
|
|
14
|
+
switch (dbType) {
|
|
15
|
+
case 'postgres': {
|
|
16
|
+
debug('using postgres migration file')
|
|
17
|
+
const mig: AddCredentialDesigns1773657426000 = new AddCredentialDesignsPostgres1773657426000()
|
|
18
|
+
await mig.up(queryRunner)
|
|
19
|
+
debug('Migration statements executed')
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
case 'sqlite':
|
|
23
|
+
case 'expo':
|
|
24
|
+
case 'react-native': {
|
|
25
|
+
debug('using sqlite/react-native migration file')
|
|
26
|
+
const mig: AddCredentialDesignsSqlite1773657426000 = new AddCredentialDesignsSqlite1773657426000()
|
|
27
|
+
await mig.up(queryRunner)
|
|
28
|
+
debug('Migration statements executed')
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return Promise.reject(
|
|
33
|
+
`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`,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
39
|
+
debug('migration: removing credential designs')
|
|
40
|
+
const dbType: DatabaseType = queryRunner.connection.driver.options.type
|
|
41
|
+
switch (dbType) {
|
|
42
|
+
case 'postgres': {
|
|
43
|
+
debug('using postgres migration file')
|
|
44
|
+
const mig: AddCredentialDesignsPostgres1773657426000 = new AddCredentialDesignsPostgres1773657426000()
|
|
45
|
+
await mig.down(queryRunner)
|
|
46
|
+
debug('Migration statements executed')
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
case 'sqlite':
|
|
50
|
+
case 'expo':
|
|
51
|
+
case 'react-native': {
|
|
52
|
+
debug('using sqlite/react-native migration file')
|
|
53
|
+
const mig: AddCredentialDesignsSqlite1773657426000 = new AddCredentialDesignsSqlite1773657426000()
|
|
54
|
+
await mig.down(queryRunner)
|
|
55
|
+
debug('Migration statements executed')
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return Promise.reject(
|
|
60
|
+
`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`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -17,6 +17,7 @@ import { CreateDigitalCredential1708525189000 } from './6-CreateDigitalCredentia
|
|
|
17
17
|
import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStore'
|
|
18
18
|
import { CreateContacts1708525189000 } from './8-CreateContacts'
|
|
19
19
|
import { CreateContacts1715761125000 } from './9-CreateContacts'
|
|
20
|
+
import { AddCredentialDesigns1773657426000 } from './18-AddCredentialDesigns'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The migrations array that SHOULD be used when initializing a TypeORM database connection.
|
|
@@ -40,6 +41,9 @@ export const DataStoreIssuanceBrandingMigrations = [
|
|
|
40
41
|
AddBrandingState1766000000000,
|
|
41
42
|
AddCredentialClaimOrder1768000000000,
|
|
42
43
|
]
|
|
44
|
+
export const DataStoreCredentialDesignMigrations = [
|
|
45
|
+
AddCredentialDesigns1773657426000,
|
|
46
|
+
]
|
|
43
47
|
export const DataStoreStatusListMigrations = [
|
|
44
48
|
CreateStatusList1693866470000,
|
|
45
49
|
AddBitstringStatusListEnum1741895823000,
|
|
@@ -61,10 +65,9 @@ export const DataStoreMigrations = [
|
|
|
61
65
|
...DataStoreMachineStateMigrations,
|
|
62
66
|
...DataStorePresentationDefinitionMigrations,
|
|
63
67
|
...DataStoreServiceMigrations,
|
|
68
|
+
...DataStoreCredentialDesignMigrations,
|
|
64
69
|
]
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
71
|
// All migrations combined with Veramo migrations first - use this when you need both
|
|
69
72
|
export const DataStoreMigrationsWithVeramo = [
|
|
70
73
|
...VeramoDataStoreMigrations,
|
package/src/migrations/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export {
|
|
|
6
6
|
DataStoreIssuanceBrandingMigrations,
|
|
7
7
|
DataStoreStatusListMigrations,
|
|
8
8
|
DataStoreDigitalCredentialMigrations,
|
|
9
|
+
DataStoreCredentialDesignMigrations,
|
|
9
10
|
DataStoreMachineStateMigrations,
|
|
10
11
|
DataStorePresentationDefinitionMigrations,
|
|
11
12
|
DataStoreServiceMigrations,
|