@sphereon/ssi-sdk.data-store 0.37.2-next.14 → 0.37.2-next.21
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 +153 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +153 -102
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/credential-design-store.test.ts +51 -51
- package/src/__tests__/credential-design.entities.test.ts +44 -44
- package/src/credentialDesign/CredentialDesignStore.ts +74 -34
- package/src/entities/credentialDesign/CredentialDesignBrandingEntity.ts +3 -3
- package/src/entities/credentialDesign/{MetaDataKeyEntity.ts → MetadataKeyEntity.ts} +7 -7
- package/src/entities/credentialDesign/{MetaDataSetEntity.ts → MetadataSetEntity.ts} +6 -6
- package/src/entities/credentialDesign/{MetaDataValueEntity.ts → MetadataValueEntity.ts} +4 -4
- package/src/entities/credentialDesign/SchemaDefinitionEntity.ts +3 -3
- package/src/entities/credentialDesign/index.ts +3 -3
- package/src/index.ts +10 -10
- package/src/migrations/postgres/1773657426000-AddCredentialDesigns.ts +5 -1
- package/src/utils/credentialDesign/MappingUtils.ts +20 -20
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractCredentialDesignStore,
|
|
3
3
|
AddCredentialDesignArgs,
|
|
4
|
+
CountCredentialDesignsArgs,
|
|
4
5
|
CredentialDesign,
|
|
6
|
+
FormStepGetOrCreateArgs,
|
|
5
7
|
GetCredentialDesignArgs,
|
|
6
8
|
GetCredentialDesignsArgs,
|
|
7
9
|
NonPersistedCredentialDesignBranding,
|
|
8
|
-
|
|
10
|
+
NonPersistedMetadataKey,
|
|
9
11
|
NonPersistedSchemaDefinition,
|
|
10
12
|
RemoveCredentialDesignArgs,
|
|
11
13
|
UpdateCredentialDesignArgs,
|
|
@@ -13,13 +15,13 @@ import {
|
|
|
13
15
|
import { OrPromise } from '@sphereon/ssi-types'
|
|
14
16
|
import Debug from 'debug'
|
|
15
17
|
import { DataSource, EntityManager, Repository } from 'typeorm'
|
|
16
|
-
import {
|
|
18
|
+
import { MetadataSetEntity, MetadataKeyEntity, MetadataValueEntity, SchemaDefinitionEntity, CredentialDesignBrandingEntity, FormStepEntity } from '../entities/credentialDesign'
|
|
17
19
|
import { ImageAttributesEntity } from '../entities/issuanceBranding/ImageAttributesEntity'
|
|
18
20
|
import { ImageDimensionsEntity } from '../entities/issuanceBranding/ImageDimensionsEntity'
|
|
19
21
|
import {
|
|
20
22
|
credentialDesignBrandingEntityFrom,
|
|
21
23
|
credentialDesignFrom,
|
|
22
|
-
|
|
24
|
+
metadataKeyEntityFrom,
|
|
23
25
|
schemaDefinitionEntityFrom,
|
|
24
26
|
} from '../utils/credentialDesign/MappingUtils'
|
|
25
27
|
|
|
@@ -36,7 +38,7 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
36
38
|
getCredentialDesign = async (args: GetCredentialDesignArgs): Promise<CredentialDesign> => {
|
|
37
39
|
const { credentialDesignId } = args
|
|
38
40
|
debug('getCredentialDesign', credentialDesignId)
|
|
39
|
-
const repo: Repository<
|
|
41
|
+
const repo: Repository<MetadataSetEntity> = (await this.dbConnection).getRepository(MetadataSetEntity)
|
|
40
42
|
const result = await repo.findOne({
|
|
41
43
|
where: { id: credentialDesignId },
|
|
42
44
|
})
|
|
@@ -50,39 +52,62 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
50
52
|
|
|
51
53
|
getCredentialDesigns = async (args?: GetCredentialDesignsArgs): Promise<Array<CredentialDesign>> => {
|
|
52
54
|
debug('getCredentialDesigns', args)
|
|
53
|
-
const repo: Repository<
|
|
55
|
+
const repo: Repository<MetadataSetEntity> = (await this.dbConnection).getRepository(MetadataSetEntity)
|
|
54
56
|
const where = args?.filter?.tenantId ? { tenantId: args.filter.tenantId } : undefined
|
|
55
|
-
const results = await repo.find({
|
|
57
|
+
const results = await repo.find({
|
|
58
|
+
where,
|
|
59
|
+
order: { name: 'ASC' },
|
|
60
|
+
take: args?.limit,
|
|
61
|
+
skip: args?.offset,
|
|
62
|
+
})
|
|
56
63
|
return results.map(credentialDesignFrom)
|
|
57
64
|
}
|
|
58
65
|
|
|
66
|
+
countCredentialDesigns = async (args?: CountCredentialDesignsArgs): Promise<number> => {
|
|
67
|
+
debug('countCredentialDesigns', args)
|
|
68
|
+
const repo: Repository<MetadataSetEntity> = (await this.dbConnection).getRepository(MetadataSetEntity)
|
|
69
|
+
const where = args?.filter?.tenantId ? { tenantId: args.filter.tenantId } : undefined
|
|
70
|
+
return repo.count({ where })
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
addCredentialDesign = async (args: AddCredentialDesignArgs): Promise<CredentialDesign> => {
|
|
60
74
|
debug('addCredentialDesign', args)
|
|
61
75
|
const dataSource = await this.dbConnection
|
|
62
76
|
|
|
63
77
|
return dataSource.transaction(async (transactionalEntityManager) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
const metadataSet = new MetadataSetEntity()
|
|
79
|
+
metadataSet.name = args.identifier
|
|
80
|
+
metadataSet.tenantId = args.tenantId
|
|
81
|
+
metadataSet.metadataKeys = []
|
|
82
|
+
metadataSet.schemaDefinitions = []
|
|
69
83
|
|
|
70
84
|
const { design } = args
|
|
71
85
|
if (design) {
|
|
72
|
-
if (design.
|
|
73
|
-
|
|
86
|
+
if (design.metadataKeys) {
|
|
87
|
+
metadataSet.metadataKeys = design.metadataKeys.map(metadataKeyEntityFrom)
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
if (design.schemaDefinitions) {
|
|
77
|
-
|
|
91
|
+
metadataSet.schemaDefinitions = design.schemaDefinitions.map(schemaDefinitionEntityFrom)
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
if (design.branding) {
|
|
81
|
-
|
|
95
|
+
metadataSet.credentialDesignBranding = credentialDesignBrandingEntityFrom(design.branding)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const saved = await transactionalEntityManager.save(MetadataSetEntity, metadataSet)
|
|
100
|
+
|
|
101
|
+
if (args.formStepId && saved.schemaDefinitions?.length) {
|
|
102
|
+
const formStep = await transactionalEntityManager.findOne(FormStepEntity, {
|
|
103
|
+
where: { id: args.formStepId },
|
|
104
|
+
})
|
|
105
|
+
if (formStep) {
|
|
106
|
+
formStep.schemaDefinitions = [...(formStep.schemaDefinitions ?? []), ...saved.schemaDefinitions]
|
|
107
|
+
await transactionalEntityManager.save(FormStepEntity, formStep)
|
|
82
108
|
}
|
|
83
109
|
}
|
|
84
110
|
|
|
85
|
-
const saved = await transactionalEntityManager.save(MetaDataSetEntity, metaDataSet)
|
|
86
111
|
return credentialDesignFrom(saved)
|
|
87
112
|
})
|
|
88
113
|
}
|
|
@@ -92,7 +117,7 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
92
117
|
const dataSource = await this.dbConnection
|
|
93
118
|
|
|
94
119
|
return dataSource.transaction(async (transactionalEntityManager) => {
|
|
95
|
-
const existing = await transactionalEntityManager.findOne(
|
|
120
|
+
const existing = await transactionalEntityManager.findOne(MetadataSetEntity, {
|
|
96
121
|
where: { id: args.credentialDesignId },
|
|
97
122
|
})
|
|
98
123
|
|
|
@@ -100,8 +125,8 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
100
125
|
return Promise.reject(Error(`No credential design found for id: ${args.credentialDesignId}`))
|
|
101
126
|
}
|
|
102
127
|
|
|
103
|
-
if (args.
|
|
104
|
-
existing.name = args.
|
|
128
|
+
if (args.identifier !== undefined) {
|
|
129
|
+
existing.name = args.identifier
|
|
105
130
|
}
|
|
106
131
|
if (args.tenantId !== undefined) {
|
|
107
132
|
existing.tenantId = args.tenantId
|
|
@@ -109,8 +134,8 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
109
134
|
|
|
110
135
|
const { design } = args
|
|
111
136
|
if (design) {
|
|
112
|
-
if (design.
|
|
113
|
-
await this.
|
|
137
|
+
if (design.metadataKeys !== undefined) {
|
|
138
|
+
await this.replaceMetadataKeys(transactionalEntityManager, existing, design.metadataKeys)
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
if (design.schemaDefinitions !== undefined) {
|
|
@@ -122,14 +147,29 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
122
147
|
}
|
|
123
148
|
}
|
|
124
149
|
|
|
125
|
-
const saved = await transactionalEntityManager.save(
|
|
150
|
+
const saved = await transactionalEntityManager.save(MetadataSetEntity, existing)
|
|
126
151
|
return credentialDesignFrom(saved)
|
|
127
152
|
})
|
|
128
153
|
}
|
|
129
154
|
|
|
155
|
+
formStepGetOrCreate = async (args: FormStepGetOrCreateArgs): Promise<string> => {
|
|
156
|
+
debug('formStepGetOrCreate', args)
|
|
157
|
+
const repo: Repository<FormStepEntity> = (await this.dbConnection).getRepository(FormStepEntity)
|
|
158
|
+
const existing = await repo.findOne({ where: { formId: args.formStepId } })
|
|
159
|
+
if (existing) {
|
|
160
|
+
return existing.id
|
|
161
|
+
}
|
|
162
|
+
const formStep = new FormStepEntity()
|
|
163
|
+
formStep.formId = args.formStepId
|
|
164
|
+
formStep.stepNr = 1
|
|
165
|
+
formStep.order = 1
|
|
166
|
+
const saved = await repo.save(formStep)
|
|
167
|
+
return saved.id
|
|
168
|
+
}
|
|
169
|
+
|
|
130
170
|
removeCredentialDesign = async (args: RemoveCredentialDesignArgs): Promise<void> => {
|
|
131
171
|
debug('removeCredentialDesign', args)
|
|
132
|
-
const repo: Repository<
|
|
172
|
+
const repo: Repository<MetadataSetEntity> = (await this.dbConnection).getRepository(MetadataSetEntity)
|
|
133
173
|
const existing = await repo.findOne({
|
|
134
174
|
where: { id: args.credentialDesignId },
|
|
135
175
|
})
|
|
@@ -141,25 +181,25 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
141
181
|
await repo.remove(existing)
|
|
142
182
|
}
|
|
143
183
|
|
|
144
|
-
private async
|
|
184
|
+
private async replaceMetadataKeys(
|
|
145
185
|
entityManager: EntityManager,
|
|
146
|
-
existing:
|
|
147
|
-
newKeys: Array<
|
|
186
|
+
existing: MetadataSetEntity,
|
|
187
|
+
newKeys: Array<NonPersistedMetadataKey>,
|
|
148
188
|
): Promise<void> {
|
|
149
|
-
if (existing.
|
|
150
|
-
for (const key of existing.
|
|
151
|
-
if (key.
|
|
152
|
-
await entityManager.remove(
|
|
189
|
+
if (existing.metadataKeys?.length) {
|
|
190
|
+
for (const key of existing.metadataKeys) {
|
|
191
|
+
if (key.metadataValues?.length) {
|
|
192
|
+
await entityManager.remove(MetadataValueEntity, key.metadataValues)
|
|
153
193
|
}
|
|
154
194
|
}
|
|
155
|
-
await entityManager.remove(
|
|
195
|
+
await entityManager.remove(MetadataKeyEntity, existing.metadataKeys)
|
|
156
196
|
}
|
|
157
|
-
existing.
|
|
197
|
+
existing.metadataKeys = newKeys.map(metadataKeyEntityFrom)
|
|
158
198
|
}
|
|
159
199
|
|
|
160
200
|
private async replaceSchemaDefinitions(
|
|
161
201
|
entityManager: EntityManager,
|
|
162
|
-
existing:
|
|
202
|
+
existing: MetadataSetEntity,
|
|
163
203
|
newSchemas: Array<NonPersistedSchemaDefinition>,
|
|
164
204
|
): Promise<void> {
|
|
165
205
|
if (existing.schemaDefinitions?.length) {
|
|
@@ -170,7 +210,7 @@ export class CredentialDesignStore extends AbstractCredentialDesignStore {
|
|
|
170
210
|
|
|
171
211
|
private async replaceBranding(
|
|
172
212
|
entityManager: EntityManager,
|
|
173
|
-
existing:
|
|
213
|
+
existing: MetadataSetEntity,
|
|
174
214
|
newBranding: NonPersistedCredentialDesignBranding | undefined,
|
|
175
215
|
): Promise<void> {
|
|
176
216
|
if (existing.credentialDesignBranding) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
2
|
import { ImageAttributesEntity } from '../issuanceBranding/ImageAttributesEntity'
|
|
3
|
-
import {
|
|
3
|
+
import { MetadataSetEntity } from './MetadataSetEntity'
|
|
4
4
|
|
|
5
5
|
@Entity('credential_design_branding')
|
|
6
6
|
export class CredentialDesignBrandingEntity extends BaseEntity {
|
|
@@ -31,9 +31,9 @@ export class CredentialDesignBrandingEntity extends BaseEntity {
|
|
|
31
31
|
@JoinColumn({ name: 'background_image' })
|
|
32
32
|
backgroundImage?: ImageAttributesEntity
|
|
33
33
|
|
|
34
|
-
@OneToOne(() =>
|
|
34
|
+
@OneToOne(() => MetadataSetEntity, (set: MetadataSetEntity) => set.credentialDesignBranding, {
|
|
35
35
|
onDelete: 'CASCADE',
|
|
36
36
|
})
|
|
37
37
|
@JoinColumn({ name: 'meta_data_set_id' })
|
|
38
|
-
|
|
38
|
+
metadataSet!: MetadataSetEntity
|
|
39
39
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { ValueType } from '@sphereon/ssi-sdk.data-store-types'
|
|
2
2
|
import { ValueType } from '@sphereon/ssi-sdk.data-store-types'
|
|
3
3
|
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { MetadataSetEntity } from './MetadataSetEntity'
|
|
5
|
+
import { MetadataValueEntity } from './MetadataValueEntity'
|
|
6
6
|
|
|
7
7
|
@Entity('meta_data_keys')
|
|
8
|
-
export class
|
|
8
|
+
export class MetadataKeyEntity extends BaseEntity {
|
|
9
9
|
@PrimaryGeneratedColumn('uuid')
|
|
10
10
|
id!: string
|
|
11
11
|
|
|
@@ -15,16 +15,16 @@ export class MetaDataKeyEntity extends BaseEntity {
|
|
|
15
15
|
@Column('text', { name: 'key', nullable: false })
|
|
16
16
|
key!: string
|
|
17
17
|
|
|
18
|
-
@ManyToOne(() =>
|
|
18
|
+
@ManyToOne(() => MetadataSetEntity, (set: MetadataSetEntity) => set.metadataKeys, {
|
|
19
19
|
onDelete: 'CASCADE',
|
|
20
20
|
})
|
|
21
21
|
@JoinColumn({ name: 'set_id' })
|
|
22
|
-
set!:
|
|
22
|
+
set!: MetadataSetEntity
|
|
23
23
|
|
|
24
|
-
@OneToMany(() =>
|
|
24
|
+
@OneToMany(() => MetadataValueEntity, (value: MetadataValueEntity) => value.metadataKey, {
|
|
25
25
|
cascade: true,
|
|
26
26
|
onDelete: 'CASCADE',
|
|
27
27
|
eager: true,
|
|
28
28
|
})
|
|
29
|
-
|
|
29
|
+
metadataValues!: Array<MetadataValueEntity>
|
|
30
30
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseEntity, Column, Entity, Index, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
-
import {
|
|
2
|
+
import { MetadataKeyEntity } from './MetadataKeyEntity'
|
|
3
3
|
import { SchemaDefinitionEntity } from './SchemaDefinitionEntity'
|
|
4
4
|
import { CredentialDesignBrandingEntity } from './CredentialDesignBrandingEntity'
|
|
5
5
|
|
|
6
6
|
@Entity('meta_data_set')
|
|
7
7
|
@Index('meta_data_set_unique_tenant', ['name', 'tenantId'], { unique: true })
|
|
8
|
-
export class
|
|
8
|
+
export class MetadataSetEntity extends BaseEntity {
|
|
9
9
|
@PrimaryGeneratedColumn('uuid')
|
|
10
10
|
id!: string
|
|
11
11
|
|
|
@@ -15,21 +15,21 @@ export class MetaDataSetEntity extends BaseEntity {
|
|
|
15
15
|
@Column('text', { name: 'name', nullable: false })
|
|
16
16
|
name!: string
|
|
17
17
|
|
|
18
|
-
@OneToMany(() =>
|
|
18
|
+
@OneToMany(() => MetadataKeyEntity, (key: MetadataKeyEntity) => key.set, {
|
|
19
19
|
cascade: true,
|
|
20
20
|
onDelete: 'CASCADE',
|
|
21
21
|
eager: true,
|
|
22
22
|
})
|
|
23
|
-
|
|
23
|
+
metadataKeys!: Array<MetadataKeyEntity>
|
|
24
24
|
|
|
25
|
-
@OneToMany(() => SchemaDefinitionEntity, (schema: SchemaDefinitionEntity) => schema.
|
|
25
|
+
@OneToMany(() => SchemaDefinitionEntity, (schema: SchemaDefinitionEntity) => schema.metadataSet, {
|
|
26
26
|
cascade: true,
|
|
27
27
|
onDelete: 'CASCADE',
|
|
28
28
|
eager: true,
|
|
29
29
|
})
|
|
30
30
|
schemaDefinitions!: Array<SchemaDefinitionEntity>
|
|
31
31
|
|
|
32
|
-
@OneToOne(() => CredentialDesignBrandingEntity, (branding: CredentialDesignBrandingEntity) => branding.
|
|
32
|
+
@OneToOne(() => CredentialDesignBrandingEntity, (branding: CredentialDesignBrandingEntity) => branding.metadataSet, {
|
|
33
33
|
cascade: true,
|
|
34
34
|
onDelete: 'CASCADE',
|
|
35
35
|
eager: true,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
|
|
2
2
|
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
3
|
-
import {
|
|
3
|
+
import { MetadataKeyEntity } from './MetadataKeyEntity'
|
|
4
4
|
|
|
5
5
|
@Entity('meta_data_values')
|
|
6
|
-
export class
|
|
6
|
+
export class MetadataValueEntity extends BaseEntity {
|
|
7
7
|
@PrimaryGeneratedColumn('uuid')
|
|
8
8
|
id!: string
|
|
9
9
|
|
|
@@ -22,9 +22,9 @@ export class MetaDataValueEntity extends BaseEntity {
|
|
|
22
22
|
@Column({ name: 'timestamp_value', nullable: true, type: typeOrmDateTime() })
|
|
23
23
|
timestampValue?: Date
|
|
24
24
|
|
|
25
|
-
@ManyToOne(() =>
|
|
25
|
+
@ManyToOne(() => MetadataKeyEntity, (key: MetadataKeyEntity) => key.metadataValues, {
|
|
26
26
|
onDelete: 'CASCADE',
|
|
27
27
|
})
|
|
28
28
|
@JoinColumn({ name: 'key_id' })
|
|
29
|
-
|
|
29
|
+
metadataKey!: MetadataKeyEntity
|
|
30
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseEntity, Column, Entity, JoinColumn, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
-
import {
|
|
2
|
+
import { MetadataSetEntity } from './MetadataSetEntity'
|
|
3
3
|
import { FormStepEntity } from './FormStepEntity'
|
|
4
4
|
|
|
5
5
|
@Entity('schema_definition')
|
|
@@ -25,11 +25,11 @@ export class SchemaDefinitionEntity extends BaseEntity {
|
|
|
25
25
|
@Column('text', { name: 'schema', nullable: false })
|
|
26
26
|
schema!: string
|
|
27
27
|
|
|
28
|
-
@ManyToOne(() =>
|
|
28
|
+
@ManyToOne(() => MetadataSetEntity, (set: MetadataSetEntity) => set.schemaDefinitions, {
|
|
29
29
|
onDelete: 'CASCADE',
|
|
30
30
|
})
|
|
31
31
|
@JoinColumn({ name: 'meta_data_set_id' })
|
|
32
|
-
|
|
32
|
+
metadataSet!: MetadataSetEntity
|
|
33
33
|
|
|
34
34
|
@ManyToMany(() => FormStepEntity, (formStep: FormStepEntity) => formStep.schemaDefinitions)
|
|
35
35
|
formSteps!: Array<FormStepEntity>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { MetadataSetEntity } from './MetadataSetEntity'
|
|
2
|
+
export { MetadataKeyEntity, ValueType } from './MetadataKeyEntity'
|
|
3
|
+
export { MetadataValueEntity } from './MetadataValueEntity'
|
|
4
4
|
export { FormStepEntity } from './FormStepEntity'
|
|
5
5
|
export { SchemaDefinitionEntity } from './SchemaDefinitionEntity'
|
|
6
6
|
export { CredentialDesignBrandingEntity } from './CredentialDesignBrandingEntity'
|
package/src/index.ts
CHANGED
|
@@ -29,9 +29,9 @@ 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 {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
32
|
+
import { MetadataSetEntity } from './entities/credentialDesign/MetadataSetEntity'
|
|
33
|
+
import { MetadataKeyEntity } from './entities/credentialDesign/MetadataKeyEntity'
|
|
34
|
+
import { MetadataValueEntity } from './entities/credentialDesign/MetadataValueEntity'
|
|
35
35
|
import { FormStepEntity } from './entities/credentialDesign/FormStepEntity'
|
|
36
36
|
import { SchemaDefinitionEntity } from './entities/credentialDesign/SchemaDefinitionEntity'
|
|
37
37
|
import { CredentialDesignBrandingEntity } from './entities/credentialDesign/CredentialDesignBrandingEntity'
|
|
@@ -125,9 +125,9 @@ export const DataStoreDigitalCredentialEntities = [DigitalCredentialEntity]
|
|
|
125
125
|
export const DataStoreMachineStateEntities = [MachineStateInfoEntity]
|
|
126
126
|
|
|
127
127
|
export const DataStoreCredentialDesignEntities = [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
MetadataSetEntity,
|
|
129
|
+
MetadataKeyEntity,
|
|
130
|
+
MetadataValueEntity,
|
|
131
131
|
FormStepEntity,
|
|
132
132
|
SchemaDefinitionEntity,
|
|
133
133
|
CredentialDesignBrandingEntity,
|
|
@@ -187,12 +187,12 @@ export {
|
|
|
187
187
|
ContactMetadataItemEntity,
|
|
188
188
|
CredentialClaimsEntity,
|
|
189
189
|
Oid4vcStateEntity,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
MetadataSetEntity,
|
|
191
|
+
MetadataKeyEntity,
|
|
192
|
+
MetadataValueEntity,
|
|
193
193
|
FormStepEntity,
|
|
194
194
|
SchemaDefinitionEntity,
|
|
195
195
|
CredentialDesignBrandingEntity,
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
export { ValueType } from './entities/credentialDesign/
|
|
198
|
+
export { ValueType } from './entities/credentialDesign/MetadataKeyEntity'
|
|
@@ -6,7 +6,11 @@ export class AddCredentialDesignsPostgres1773657426000 implements MigrationInter
|
|
|
6
6
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
7
|
|
|
8
8
|
await queryRunner.query(`
|
|
9
|
-
|
|
9
|
+
DO $$ BEGIN
|
|
10
|
+
CREATE TYPE "value_type" AS ENUM ('Text', 'Number', 'Boolean', 'Date');
|
|
11
|
+
EXCEPTION
|
|
12
|
+
WHEN duplicate_object THEN NULL;
|
|
13
|
+
END $$;
|
|
10
14
|
`)
|
|
11
15
|
|
|
12
16
|
await queryRunner.query(`
|
|
@@ -2,29 +2,29 @@ import type {
|
|
|
2
2
|
CredentialDesign,
|
|
3
3
|
CredentialDesignBranding,
|
|
4
4
|
IImageAttributes,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
MetadataKey,
|
|
6
|
+
MetadataValue,
|
|
7
7
|
NonPersistedCredentialDesignBranding,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
NonPersistedMetadataKey,
|
|
9
|
+
NonPersistedMetadataValue,
|
|
10
10
|
NonPersistedSchemaDefinition,
|
|
11
11
|
SchemaDefinition,
|
|
12
12
|
} from '@sphereon/ssi-sdk.data-store-types'
|
|
13
13
|
import { CredentialDesignBrandingEntity } from '../../entities/credentialDesign'
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
14
|
+
import { MetadataKeyEntity, ValueType } from '../../entities/credentialDesign'
|
|
15
|
+
import { MetadataSetEntity } from '../../entities/credentialDesign'
|
|
16
|
+
import { MetadataValueEntity } from '../../entities/credentialDesign'
|
|
17
17
|
import { SchemaDefinitionEntity } from '../../entities/credentialDesign'
|
|
18
18
|
import { ImageAttributesEntity } from '../../entities/issuanceBranding/ImageAttributesEntity'
|
|
19
19
|
import { replaceNullWithUndefined } from '../FormattingUtils'
|
|
20
20
|
import { imageAttributesEntityFrom } from '../issuanceBranding/MappingUtils'
|
|
21
21
|
|
|
22
|
-
export const credentialDesignFrom = (entity:
|
|
22
|
+
export const credentialDesignFrom = (entity: MetadataSetEntity): CredentialDesign => {
|
|
23
23
|
const result: CredentialDesign = {
|
|
24
24
|
id: entity.id,
|
|
25
|
-
|
|
25
|
+
identifier: entity.name,
|
|
26
26
|
tenantId: entity.tenantId,
|
|
27
|
-
|
|
27
|
+
metadataKeys: entity.metadataKeys?.map((key) => metadataKeyFrom(key)) ?? [],
|
|
28
28
|
schemaDefinitions: entity.schemaDefinitions?.map((schema) => schemaDefinitionFrom(schema)) ?? [],
|
|
29
29
|
branding: entity.credentialDesignBranding ? credentialDesignBrandingFrom(entity.credentialDesignBranding) : undefined,
|
|
30
30
|
}
|
|
@@ -32,19 +32,19 @@ export const credentialDesignFrom = (entity: MetaDataSetEntity): CredentialDesig
|
|
|
32
32
|
return replaceNullWithUndefined(result)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export const
|
|
36
|
-
const result:
|
|
35
|
+
export const metadataKeyFrom = (entity: MetadataKeyEntity): MetadataKey => {
|
|
36
|
+
const result: MetadataKey = {
|
|
37
37
|
id: entity.id,
|
|
38
38
|
key: entity.key,
|
|
39
39
|
valueType: entity.valueType,
|
|
40
|
-
|
|
40
|
+
metadataValues: entity.metadataValues?.map((value) => metadataValueFrom(value)) ?? [],
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
return replaceNullWithUndefined(result)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export const
|
|
47
|
-
const result:
|
|
46
|
+
export const metadataValueFrom = (entity: MetadataValueEntity): MetadataValue => {
|
|
47
|
+
const result: MetadataValue = {
|
|
48
48
|
id: entity.id,
|
|
49
49
|
index: entity.index,
|
|
50
50
|
textValue: entity.textValue,
|
|
@@ -101,16 +101,16 @@ export const imageAttributesFrom = (entity: ImageAttributesEntity): IImageAttrib
|
|
|
101
101
|
return replaceNullWithUndefined(result)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export const
|
|
105
|
-
const keyEntity = new
|
|
104
|
+
export const metadataKeyEntityFrom = (input: NonPersistedMetadataKey): MetadataKeyEntity => {
|
|
105
|
+
const keyEntity = new MetadataKeyEntity()
|
|
106
106
|
keyEntity.key = input.key
|
|
107
107
|
keyEntity.valueType = input.valueType as ValueType
|
|
108
|
-
keyEntity.
|
|
108
|
+
keyEntity.metadataValues = input.metadataValues.map((valInput) => metadataValueEntityFrom(valInput))
|
|
109
109
|
return keyEntity
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
export const
|
|
113
|
-
const valEntity = new
|
|
112
|
+
export const metadataValueEntityFrom = (input: NonPersistedMetadataValue): MetadataValueEntity => {
|
|
113
|
+
const valEntity = new MetadataValueEntity()
|
|
114
114
|
valEntity.index = input.index
|
|
115
115
|
valEntity.textValue = input.textValue
|
|
116
116
|
valEntity.numberValue = input.numberValue
|