@sphereon/ssi-sdk.data-store 0.36.1-feature.SSISDK.82.and.SSISDK.70.37 → 0.36.1-next.11
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 +126 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -16
- package/dist/index.d.ts +5 -16
- package/dist/index.js +112 -349
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/digitalCredential.store.test.ts +7 -349
- package/src/digitalCredential/DigitalCredentialStore.ts +15 -73
- package/src/entities/digitalCredential/DigitalCredentialEntity.ts +0 -9
- package/src/migrations/generic/index.ts +1 -2
- package/src/utils/digitalCredential/MappingUtils.ts +2 -69
- package/src/migrations/generic/14-AddLinkedVpFields.ts +0 -66
- package/src/migrations/postgres/1763387280001-AddLinkedVpFields.ts +0 -39
- package/src/migrations/sqlite/1763387280002-AddLinkedVpFields.ts +0 -39
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
DigitalCredential,
|
|
5
|
-
NonPersistedDigitalCredential,
|
|
6
|
-
UpdateCredentialStateArgs,
|
|
7
|
-
} from '@sphereon/ssi-sdk.data-store-types'
|
|
8
|
-
import { CredentialDocumentFormat, CredentialStateType, DocumentType, RegulationType } from '@sphereon/ssi-sdk.data-store-types'
|
|
2
|
+
import type { AddCredentialArgs, DigitalCredential, NonPersistedDigitalCredential } from '@sphereon/ssi-sdk.data-store-types'
|
|
3
|
+
import { CredentialDocumentFormat, DocumentType, RegulationType } from '@sphereon/ssi-sdk.data-store-types'
|
|
9
4
|
import {
|
|
10
5
|
CredentialMapper,
|
|
11
6
|
DocumentFormat,
|
|
@@ -71,20 +66,6 @@ function determineCredentialDocumentFormat(documentFormat: DocumentFormat): Cred
|
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
/**
|
|
75
|
-
* Normalizes nullable fields by converting undefined to null.
|
|
76
|
-
* This ensures TypeORM actually clears the database fields instead of ignoring them.
|
|
77
|
-
*/
|
|
78
|
-
export function normalizeNullableFields<T extends Record<string, any>>(obj: T, nullableKeys: Array<keyof T>): T {
|
|
79
|
-
const normalized = { ...obj }
|
|
80
|
-
for (const key of nullableKeys) {
|
|
81
|
-
if (normalized[key] === undefined) {
|
|
82
|
-
normalized[key] = null as any
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return normalized
|
|
86
|
-
}
|
|
87
|
-
|
|
88
69
|
function getValidUntil(uniformDocument: IVerifiableCredential | IVerifiablePresentation | SdJwtDecodedVerifiableCredentialPayload): Date | undefined {
|
|
89
70
|
if ('expirationDate' in uniformDocument && uniformDocument.expirationDate) {
|
|
90
71
|
return new Date(uniformDocument.expirationDate)
|
|
@@ -146,54 +127,6 @@ export const nonPersistedDigitalCredentialEntityFromAddArgs = (addCredentialArgs
|
|
|
146
127
|
}
|
|
147
128
|
}
|
|
148
129
|
|
|
149
|
-
export const persistedDigitalCredentialEntityFromUpdateArgs = (
|
|
150
|
-
existingCredential: DigitalCredentialEntity,
|
|
151
|
-
updates: Partial<DigitalCredential>,
|
|
152
|
-
): DigitalCredentialEntity => {
|
|
153
|
-
const entity = new DigitalCredentialEntity()
|
|
154
|
-
|
|
155
|
-
// Copy all fields from existing credential
|
|
156
|
-
Object.assign(entity, existingCredential)
|
|
157
|
-
|
|
158
|
-
// Normalize nullable fields before applying updates
|
|
159
|
-
const normalizedUpdates = normalizeNullableFields(updates, ['linkedVpId', 'linkedVpFrom', 'linkedVpUntil'])
|
|
160
|
-
|
|
161
|
-
// Apply updates
|
|
162
|
-
Object.assign(entity, normalizedUpdates)
|
|
163
|
-
|
|
164
|
-
// Ensure these fields are never overwritten
|
|
165
|
-
entity.id = existingCredential.id
|
|
166
|
-
entity.hash = existingCredential.hash
|
|
167
|
-
entity.createdAt = existingCredential.createdAt
|
|
168
|
-
entity.lastUpdatedAt = new Date()
|
|
169
|
-
|
|
170
|
-
return entity
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const persistedDigitalCredentialEntityFromStateArgs = (
|
|
174
|
-
existingCredential: DigitalCredentialEntity,
|
|
175
|
-
args: UpdateCredentialStateArgs,
|
|
176
|
-
): DigitalCredentialEntity => {
|
|
177
|
-
const entity = new DigitalCredentialEntity()
|
|
178
|
-
|
|
179
|
-
// Copy all fields from existing credential
|
|
180
|
-
Object.assign(entity, existingCredential)
|
|
181
|
-
|
|
182
|
-
// Apply state updates
|
|
183
|
-
entity.verifiedState = args.verifiedState
|
|
184
|
-
entity.lastUpdatedAt = new Date()
|
|
185
|
-
|
|
186
|
-
if (args.verifiedState === CredentialStateType.REVOKED && args.revokedAt) {
|
|
187
|
-
entity.revokedAt = args.revokedAt
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (args.verifiedState !== CredentialStateType.REVOKED && args.verifiedAt) {
|
|
191
|
-
entity.verifiedAt = args.verifiedAt
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return entity
|
|
195
|
-
}
|
|
196
|
-
|
|
197
130
|
export const digitalCredentialFrom = (credentialEntity: DigitalCredentialEntity): DigitalCredential => {
|
|
198
131
|
const result: DigitalCredential = {
|
|
199
132
|
...credentialEntity,
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import Debug, { Debugger } from 'debug'
|
|
2
|
-
import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
|
|
3
|
-
import { AddLinkedVpFields1763387280001 } from '../postgres/1763387280001-AddLinkedVpFields'
|
|
4
|
-
import { AddLinkedVpFields1763387280002 } from '../sqlite/1763387280002-AddLinkedVpFields'
|
|
5
|
-
|
|
6
|
-
const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
|
|
7
|
-
|
|
8
|
-
export class AddLinkedVpFields1763387280000 implements MigrationInterface {
|
|
9
|
-
name: string = 'AddLinkedVpFields1763387280000'
|
|
10
|
-
|
|
11
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
12
|
-
debug('migration: adding linked VP fields to DigitalCredential table')
|
|
13
|
-
const dbType: DatabaseType = queryRunner.connection.driver.options.type
|
|
14
|
-
|
|
15
|
-
switch (dbType) {
|
|
16
|
-
case 'postgres': {
|
|
17
|
-
debug('using postgres migration file for AddLinkedVpFields')
|
|
18
|
-
const mig: AddLinkedVpFields1763387280001 = new AddLinkedVpFields1763387280001()
|
|
19
|
-
await mig.up(queryRunner)
|
|
20
|
-
debug('Postgres migration statements for AddLinkedVpFields executed')
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
case 'sqlite':
|
|
24
|
-
case 'expo':
|
|
25
|
-
case 'react-native': {
|
|
26
|
-
debug('using sqlite/react-native migration file for AddLinkedVpFields')
|
|
27
|
-
const mig: AddLinkedVpFields1763387280002 = new AddLinkedVpFields1763387280002()
|
|
28
|
-
await mig.up(queryRunner)
|
|
29
|
-
debug('SQLite migration statements for AddLinkedVpFields executed')
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
default:
|
|
33
|
-
return Promise.reject(
|
|
34
|
-
`Migrations are currently only supported for sqlite, react-native, expo, and postgres for AddLinkedVpFields. 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 linked VP fields from DigitalCredential table')
|
|
41
|
-
const dbType: DatabaseType = queryRunner.connection.driver.options.type
|
|
42
|
-
|
|
43
|
-
switch (dbType) {
|
|
44
|
-
case 'postgres': {
|
|
45
|
-
debug('using postgres migration file for AddLinkedVpFields')
|
|
46
|
-
const mig: AddLinkedVpFields1763387280001 = new AddLinkedVpFields1763387280001()
|
|
47
|
-
await mig.down(queryRunner)
|
|
48
|
-
debug('Postgres migration statements for AddLinkedVpFields reverted')
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
case 'sqlite':
|
|
52
|
-
case 'expo':
|
|
53
|
-
case 'react-native': {
|
|
54
|
-
debug('using sqlite/react-native migration file for AddLinkedVpFields')
|
|
55
|
-
const mig: AddLinkedVpFields1763387280002 = new AddLinkedVpFields1763387280002()
|
|
56
|
-
await mig.down(queryRunner)
|
|
57
|
-
debug('SQLite migration statements for AddLinkedVpFields reverted')
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
return Promise.reject(
|
|
62
|
-
`Migrations are currently only supported for sqlite, react-native, expo, and postgres for AddLinkedVpFields. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
export class AddLinkedVpFields1763387280001 implements MigrationInterface {
|
|
4
|
-
name = 'AddLinkedVpFields1763387280001'
|
|
5
|
-
|
|
6
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
-
await queryRunner.query(`
|
|
8
|
-
ALTER TABLE "DigitalCredential"
|
|
9
|
-
ADD COLUMN "linked_vp_id" text
|
|
10
|
-
`)
|
|
11
|
-
|
|
12
|
-
await queryRunner.query(`
|
|
13
|
-
ALTER TABLE "DigitalCredential"
|
|
14
|
-
ADD COLUMN "linked_vp_from" TIMESTAMP
|
|
15
|
-
`)
|
|
16
|
-
|
|
17
|
-
await queryRunner.query(`
|
|
18
|
-
ALTER TABLE "DigitalCredential"
|
|
19
|
-
ADD COLUMN "linked_vp_until" TIMESTAMP
|
|
20
|
-
`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
24
|
-
await queryRunner.query(`
|
|
25
|
-
ALTER TABLE "DigitalCredential"
|
|
26
|
-
DROP COLUMN "linked_vp_until"
|
|
27
|
-
`)
|
|
28
|
-
|
|
29
|
-
await queryRunner.query(`
|
|
30
|
-
ALTER TABLE "DigitalCredential"
|
|
31
|
-
DROP COLUMN "linked_vp_from"
|
|
32
|
-
`)
|
|
33
|
-
|
|
34
|
-
await queryRunner.query(`
|
|
35
|
-
ALTER TABLE "DigitalCredential"
|
|
36
|
-
DROP COLUMN "linked_vp_id"
|
|
37
|
-
`)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
export class AddLinkedVpFields1763387280002 implements MigrationInterface {
|
|
4
|
-
name = 'AddLinkedVpFields1763387280002'
|
|
5
|
-
|
|
6
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
-
await queryRunner.query(`
|
|
8
|
-
ALTER TABLE "DigitalCredential"
|
|
9
|
-
ADD COLUMN "linked_vp_id" text
|
|
10
|
-
`)
|
|
11
|
-
|
|
12
|
-
await queryRunner.query(`
|
|
13
|
-
ALTER TABLE "DigitalCredential"
|
|
14
|
-
ADD COLUMN "linked_vp_from" datetime
|
|
15
|
-
`)
|
|
16
|
-
|
|
17
|
-
await queryRunner.query(`
|
|
18
|
-
ALTER TABLE "DigitalCredential"
|
|
19
|
-
ADD COLUMN "linked_vp_until" datetime
|
|
20
|
-
`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
24
|
-
await queryRunner.query(`
|
|
25
|
-
ALTER TABLE "DigitalCredential"
|
|
26
|
-
DROP COLUMN "linked_vp_from"
|
|
27
|
-
`)
|
|
28
|
-
|
|
29
|
-
await queryRunner.query(`
|
|
30
|
-
ALTER TABLE "DigitalCredential"
|
|
31
|
-
DROP COLUMN "linked_vp_until"
|
|
32
|
-
`)
|
|
33
|
-
|
|
34
|
-
await queryRunner.query(`
|
|
35
|
-
ALTER TABLE "DigitalCredential"
|
|
36
|
-
DROP COLUMN "linked_vp_id"
|
|
37
|
-
`)
|
|
38
|
-
}
|
|
39
|
-
}
|