@sphereon/ssi-sdk.pd-manager 0.34.1-next.91 → 0.36.1-feat.SSISDK.83.3
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 +1092 -1089
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2151 -25
- package/dist/index.d.ts +2151 -25
- package/dist/index.js +1084 -1082
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/plugin.schema.json +19 -25
- package/src/agent/PDManager.ts +107 -89
- package/src/index.ts +3 -1
- package/src/types/IPDManager.ts +17 -18
package/src/agent/PDManager.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { IAgentPlugin } from '@veramo/core'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
DeleteDcqlQueryItemArgs,
|
|
4
|
+
DeleteDcqlQueryItemsArgs,
|
|
5
|
+
GetDcqlQueryItemArgs,
|
|
6
|
+
GetDcqlQueryItemsArgs,
|
|
7
7
|
HasDefinitionItemArgs,
|
|
8
|
-
|
|
8
|
+
HasDcqlQueryItemsArgs,
|
|
9
9
|
IPDManager,
|
|
10
|
-
|
|
10
|
+
PersistDcqlQueryArgs,
|
|
11
11
|
schema,
|
|
12
12
|
} from '../index'
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
NonPersistedPresentationDefinitionItem,
|
|
17
|
-
PresentationDefinitionItem,
|
|
18
|
-
} from '@sphereon/ssi-sdk.data-store'
|
|
19
|
-
import semver from 'semver/preload'
|
|
13
|
+
import { AbstractPDStore, NonPersistedDcqlQueryItem, DcqlQueryItem, AddDefinitionArgs } from '@sphereon/ssi-sdk.data-store-types'
|
|
14
|
+
import { isPresentationDefinitionEqual } from '@sphereon/ssi-sdk.data-store'
|
|
15
|
+
import semver from 'semver/preload.js'
|
|
20
16
|
import { ReleaseType } from 'semver'
|
|
21
17
|
|
|
22
18
|
// Exposing the methods here for any REST implementation
|
|
@@ -58,32 +54,32 @@ export class PDManager implements IAgentPlugin {
|
|
|
58
54
|
}
|
|
59
55
|
|
|
60
56
|
/** {@inheritDoc IPDManager.pdmHasDefinitions} */
|
|
61
|
-
private async pdmHasDefinitions(args:
|
|
57
|
+
private async pdmHasDefinitions(args: HasDcqlQueryItemsArgs): Promise<boolean> {
|
|
62
58
|
const { filter } = args
|
|
63
59
|
return this.store.hasDefinitions({ filter })
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
/** {@inheritDoc IPDManager.pdmGetDefinition} */
|
|
67
|
-
private async pdmGetDefinition(args:
|
|
63
|
+
private async pdmGetDefinition(args: GetDcqlQueryItemArgs): Promise<DcqlQueryItem> {
|
|
68
64
|
const { itemId } = args
|
|
69
65
|
return this.store.getDefinition({ itemId })
|
|
70
66
|
}
|
|
71
67
|
|
|
72
68
|
/** {@inheritDoc IPDManager.pdmGetDefinitions} */
|
|
73
|
-
private async pdmGetDefinitions(args:
|
|
69
|
+
private async pdmGetDefinitions(args: GetDcqlQueryItemsArgs): Promise<Array<DcqlQueryItem>> {
|
|
74
70
|
const { filter, opts } = args
|
|
75
71
|
const allDefinitions = await this.store.getDefinitions({ filter })
|
|
76
|
-
let definitions:
|
|
72
|
+
let definitions: DcqlQueryItem[] = []
|
|
77
73
|
if (opts == undefined || opts.showVersionHistory !== true) {
|
|
78
74
|
const groupedByDefinitionId = allDefinitions.reduce(
|
|
79
75
|
(acc, entity) => {
|
|
80
|
-
if (!acc[entity.
|
|
81
|
-
acc[entity.
|
|
76
|
+
if (!acc[entity.queryId]) {
|
|
77
|
+
acc[entity.queryId] = []
|
|
82
78
|
}
|
|
83
|
-
acc[entity.
|
|
79
|
+
acc[entity.queryId].push(entity)
|
|
84
80
|
return acc
|
|
85
81
|
},
|
|
86
|
-
{} as Record<string,
|
|
82
|
+
{} as Record<string, DcqlQueryItem[]>,
|
|
87
83
|
)
|
|
88
84
|
definitions = Object.values(groupedByDefinitionId).map((entities) =>
|
|
89
85
|
entities.reduce((highestVersionItem, baseItem) => {
|
|
@@ -99,111 +95,123 @@ export class PDManager implements IAgentPlugin {
|
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
/** {@inheritDoc IPDManager.pdmDeleteDefinition} */
|
|
102
|
-
private async pdmDeleteDefinition(args:
|
|
98
|
+
private async pdmDeleteDefinition(args: DeleteDcqlQueryItemArgs): Promise<boolean> {
|
|
103
99
|
return this.store.deleteDefinition(args).then((value) => true)
|
|
104
100
|
}
|
|
105
101
|
|
|
106
102
|
/** {@inheritDoc IPDManager.pdmDeleteDefinitions} */
|
|
107
|
-
private async pdmDeleteDefinitions(args:
|
|
103
|
+
private async pdmDeleteDefinitions(args: DeleteDcqlQueryItemsArgs): Promise<number> {
|
|
108
104
|
return this.store.deleteDefinitions(args)
|
|
109
105
|
}
|
|
110
106
|
|
|
111
107
|
/** {@inheritDoc IPDManager.pdmPersistDefinition} */
|
|
112
|
-
private async pdmPersistDefinition(args:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
id
|
|
121
|
-
|
|
108
|
+
private async pdmPersistDefinition(args: PersistDcqlQueryArgs): Promise<DcqlQueryItem> {
|
|
109
|
+
try {
|
|
110
|
+
const { definitionItem, opts } = args
|
|
111
|
+
const { versionControlMode, versionIncrementReleaseType } = opts ?? { versionControlMode: 'AutoIncrement' }
|
|
112
|
+
const { version, tenantId } = definitionItem
|
|
113
|
+
const definitionId = definitionItem.queryId
|
|
114
|
+
|
|
115
|
+
let { id } = definitionItem
|
|
116
|
+
if (id !== undefined && versionControlMode !== 'Overwrite') {
|
|
117
|
+
id = undefined
|
|
118
|
+
}
|
|
122
119
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
120
|
+
const nonPersistedDefinitionItem: NonPersistedDcqlQueryItem = {
|
|
121
|
+
...definitionItem,
|
|
122
|
+
version: version ?? '1',
|
|
123
|
+
}
|
|
128
124
|
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
const existing = await this.store.getDefinitions({ filter: [{ id, queryId: definitionId, tenantId, version }] })
|
|
126
|
+
const existingItem = existing[0]
|
|
131
127
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
// Always fetch all definitions for the definitionId/tenantId and determine the truly latest version
|
|
129
|
+
const allDefinitions = await this.store.getDefinitions({ filter: [{ queryId: definitionId, tenantId }] })
|
|
130
|
+
allDefinitions.sort((a, b) => semver.compare(this.normalizeToSemverVersionFormat(a.version), this.normalizeToSemverVersionFormat(b.version)))
|
|
131
|
+
const trulyLatestVersionItem = allDefinitions[allDefinitions.length - 1]
|
|
136
132
|
|
|
137
|
-
|
|
133
|
+
let latestVersionItem: DcqlQueryItem | undefined = trulyLatestVersionItem
|
|
138
134
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
// If a specific version exists and matches existingItem, we keep that as a base.
|
|
136
|
+
// Otherwise we use the trulyLatestVersionItem
|
|
137
|
+
if (existingItem && version) {
|
|
138
|
+
latestVersionItem = trulyLatestVersionItem ?? existingItem
|
|
139
|
+
}
|
|
144
140
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
141
|
+
const isPayloadModified = !existingItem || !isPresentationDefinitionEqual(existingItem, definitionItem)
|
|
142
|
+
if (!isPayloadModified) return existingItem
|
|
143
|
+
|
|
144
|
+
switch (versionControlMode) {
|
|
145
|
+
case 'Overwrite':
|
|
146
|
+
return this.handleOverwriteMode(existingItem, nonPersistedDefinitionItem, version)
|
|
147
|
+
case 'OverwriteLatest':
|
|
148
|
+
return this.handleOverwriteLatestMode(latestVersionItem, nonPersistedDefinitionItem)
|
|
149
|
+
case 'Manual':
|
|
150
|
+
return this.handleManualMode(existingItem, nonPersistedDefinitionItem, tenantId, version)
|
|
151
|
+
case 'AutoIncrement':
|
|
152
|
+
return this.handleAutoIncrementMode(latestVersionItem, nonPersistedDefinitionItem, versionIncrementReleaseType ?? 'major')
|
|
153
|
+
default:
|
|
154
|
+
throw new Error(`Unknown version control mode: ${versionControlMode}`)
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.log('pdmPersistDefinition failed', e)
|
|
158
|
+
throw e
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
private async handleOverwriteMode(
|
|
163
|
-
existingItem:
|
|
164
|
-
definitionItem:
|
|
163
|
+
existingItem: DcqlQueryItem | undefined,
|
|
164
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
165
165
|
version: string | undefined,
|
|
166
|
-
): Promise<
|
|
166
|
+
): Promise<DcqlQueryItem> {
|
|
167
167
|
if (existingItem) {
|
|
168
|
-
existingItem.
|
|
168
|
+
existingItem.queryId = definitionItem.queryId
|
|
169
169
|
existingItem.version = version ?? existingItem.version ?? '1'
|
|
170
170
|
existingItem.tenantId = definitionItem.tenantId
|
|
171
|
-
existingItem.name = definitionItem.
|
|
172
|
-
existingItem.purpose = definitionItem.
|
|
173
|
-
existingItem.
|
|
171
|
+
existingItem.name = definitionItem.name
|
|
172
|
+
existingItem.purpose = definitionItem.purpose
|
|
173
|
+
existingItem.query = definitionItem.query
|
|
174
174
|
|
|
175
175
|
return await this.store.updateDefinition(existingItem)
|
|
176
176
|
} else {
|
|
177
|
-
|
|
177
|
+
// Apply the same field extraction logic for new items
|
|
178
|
+
const newDefinitionItem = {
|
|
179
|
+
...definitionItem,
|
|
180
|
+
} satisfies AddDefinitionArgs
|
|
181
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
private async handleOverwriteLatestMode(
|
|
182
|
-
latestVersionItem:
|
|
183
|
-
definitionItem:
|
|
184
|
-
): Promise<
|
|
186
|
+
latestVersionItem: DcqlQueryItem | undefined,
|
|
187
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
188
|
+
): Promise<DcqlQueryItem> {
|
|
185
189
|
if (latestVersionItem) {
|
|
186
|
-
latestVersionItem.
|
|
190
|
+
latestVersionItem.queryId = definitionItem.queryId
|
|
187
191
|
latestVersionItem.tenantId = definitionItem.tenantId
|
|
188
192
|
latestVersionItem.name = definitionItem.name
|
|
189
193
|
latestVersionItem.purpose = definitionItem.purpose
|
|
190
|
-
latestVersionItem.
|
|
194
|
+
latestVersionItem.query = definitionItem.query
|
|
191
195
|
|
|
192
196
|
return await this.store.updateDefinition(latestVersionItem)
|
|
193
197
|
} else {
|
|
194
|
-
|
|
198
|
+
// Apply the same field extraction logic for new items
|
|
199
|
+
const newDefinitionItem = {
|
|
200
|
+
...definitionItem,
|
|
201
|
+
} satisfies AddDefinitionArgs
|
|
202
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
private async handleManualMode(
|
|
199
|
-
existingItem:
|
|
200
|
-
definitionItem:
|
|
207
|
+
existingItem: DcqlQueryItem | undefined,
|
|
208
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
201
209
|
tenantId: string | undefined,
|
|
202
210
|
version: string | undefined,
|
|
203
|
-
): Promise<
|
|
211
|
+
): Promise<DcqlQueryItem> {
|
|
204
212
|
if (existingItem && !isPresentationDefinitionEqual(existingItem, definitionItem)) {
|
|
205
213
|
throw Error(
|
|
206
|
-
`Cannot update definition ${definitionItem.
|
|
214
|
+
`Cannot update definition ${definitionItem.queryId} for tenant ${tenantId} version ${version} because definition exists and manual version control is enabled.`,
|
|
207
215
|
)
|
|
208
216
|
} else {
|
|
209
217
|
return await this.store.addDefinition(definitionItem)
|
|
@@ -211,10 +219,10 @@ export class PDManager implements IAgentPlugin {
|
|
|
211
219
|
}
|
|
212
220
|
|
|
213
221
|
private async handleAutoIncrementMode(
|
|
214
|
-
latestVersionItem:
|
|
215
|
-
definitionItem:
|
|
222
|
+
latestVersionItem: DcqlQueryItem | undefined,
|
|
223
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
216
224
|
releaseType: ReleaseType,
|
|
217
|
-
): Promise<
|
|
225
|
+
): Promise<DcqlQueryItem> {
|
|
218
226
|
const defaultVersion = '1'
|
|
219
227
|
let currentVersion = latestVersionItem?.version ?? definitionItem.version ?? defaultVersion
|
|
220
228
|
let resultVersion: string
|
|
@@ -230,7 +238,7 @@ export class PDManager implements IAgentPlugin {
|
|
|
230
238
|
let fullVersionToIncrement = preReleaseIdentifier ? `${normalizedBaseVersion}-${preReleaseSuffix}` : normalizedBaseVersion
|
|
231
239
|
|
|
232
240
|
// Use semver to increment the version
|
|
233
|
-
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, preReleaseIdentifier)
|
|
241
|
+
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, undefined, preReleaseIdentifier)
|
|
234
242
|
if (!incrementedVersion) {
|
|
235
243
|
throw new Error(`Could not increment ${releaseType} version on ${currentVersion} ${preReleaseSuffix}`)
|
|
236
244
|
}
|
|
@@ -248,10 +256,20 @@ export class PDManager implements IAgentPlugin {
|
|
|
248
256
|
}
|
|
249
257
|
}
|
|
250
258
|
|
|
251
|
-
|
|
252
|
-
|
|
259
|
+
// Apply field extraction logic before adding
|
|
260
|
+
const newDefinitionItem = {
|
|
261
|
+
...definitionItem,
|
|
262
|
+
version: resultVersion,
|
|
263
|
+
} satisfies AddDefinitionArgs
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
const dcqlQueryItem = await this.store.addDefinition(newDefinitionItem)
|
|
267
|
+
return dcqlQueryItem
|
|
268
|
+
} catch (e) {
|
|
269
|
+
console.log(e)
|
|
270
|
+
throw e
|
|
271
|
+
}
|
|
253
272
|
}
|
|
254
|
-
|
|
255
273
|
private normalizeToSemverVersionFormat(version: string): string {
|
|
256
274
|
const defaultVersion = '1.0.0'
|
|
257
275
|
let [baseVersion, preReleaseSuffix] = version.split(/-(.+)/)
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @public
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import schema from '../plugin.schema.json'
|
|
5
5
|
export { schema }
|
|
6
6
|
export { PDManager, pdManagerMethods } from './agent/PDManager'
|
|
7
7
|
export * from './types/IPDManager'
|
|
8
8
|
|
|
9
9
|
export type { ReleaseType } from 'semver'
|
|
10
|
+
export type { ImportDcqlQueryItem } from '@sphereon/ssi-sdk.data-store-types'
|
|
11
|
+
export type { DcqlQuery } from 'dcql'
|
package/src/types/IPDManager.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAgentContext, IPluginMethodMap } from '@veramo/core'
|
|
2
|
-
import {
|
|
2
|
+
import { FindDcqlQueryArgs, NonPersistedDcqlQueryItem, DcqlQueryItem } from '@sphereon/ssi-sdk.data-store-types'
|
|
3
3
|
import { ReleaseType } from 'semver'
|
|
4
4
|
|
|
5
5
|
export interface IPDManager extends IPluginMethodMap {
|
|
@@ -7,13 +7,13 @@ export interface IPDManager extends IPluginMethodMap {
|
|
|
7
7
|
* Get a single presentation definition records by primary key
|
|
8
8
|
* @param args
|
|
9
9
|
*/
|
|
10
|
-
pdmGetDefinition(args:
|
|
10
|
+
pdmGetDefinition(args: GetDcqlQueryItemArgs): Promise<DcqlQueryItem>
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Find one or more presentation definition records using filters
|
|
14
14
|
* @param args
|
|
15
15
|
*/
|
|
16
|
-
pdmGetDefinitions(args:
|
|
16
|
+
pdmGetDefinitions(args: GetDcqlQueryItemsArgs): Promise<Array<DcqlQueryItem>>
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Checks whether a presentation definition record exists by primary key
|
|
@@ -25,56 +25,55 @@ export interface IPDManager extends IPluginMethodMap {
|
|
|
25
25
|
* Checks whether one or more presentation definition records exist using filters
|
|
26
26
|
* @param args
|
|
27
27
|
*/
|
|
28
|
-
pdmHasDefinitions(args:
|
|
28
|
+
pdmHasDefinitions(args: HasDcqlQueryItemsArgs): Promise<boolean>
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Delete a single presentation definition records by primary key
|
|
32
32
|
* @param args
|
|
33
33
|
*/
|
|
34
|
-
pdmDeleteDefinition(args:
|
|
34
|
+
pdmDeleteDefinition(args: DeleteDcqlQueryItemArgs): Promise<boolean>
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Delete multiple presentation definitions records using filters
|
|
38
38
|
* @param args
|
|
39
39
|
*/
|
|
40
|
-
pdmDeleteDefinitions(args:
|
|
40
|
+
pdmDeleteDefinitions(args: DeleteDcqlQueryItemsArgs): Promise<number>
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Check in a presentation definition.
|
|
44
44
|
* It has version control logic which will add or update presentation definition records and has settings for automatic version numbering.
|
|
45
45
|
* @param args
|
|
46
46
|
*/
|
|
47
|
-
pdmPersistDefinition(args:
|
|
47
|
+
pdmPersistDefinition(args: PersistDcqlQueryArgs): Promise<DcqlQueryItem>
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export type VersionControlMode = 'AutoIncrement' | 'Manual' | 'Overwrite' | 'OverwriteLatest'
|
|
51
51
|
|
|
52
|
-
export type
|
|
52
|
+
export type GetDcqlQueryItemArgs = {
|
|
53
53
|
itemId: string
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export type HasDefinitionItemArgs =
|
|
56
|
+
export type HasDefinitionItemArgs = GetDcqlQueryItemArgs
|
|
57
57
|
|
|
58
58
|
export type FetchOptions = {
|
|
59
59
|
showVersionHistory?: boolean
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export type
|
|
63
|
-
filter?:
|
|
62
|
+
export type GetDcqlQueryItemsArgs = {
|
|
63
|
+
filter?: FindDcqlQueryArgs
|
|
64
64
|
opts?: FetchOptions
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export type
|
|
67
|
+
export type HasDcqlQueryItemsArgs = GetDcqlQueryItemsArgs
|
|
68
68
|
|
|
69
|
-
export type
|
|
69
|
+
export type DeleteDcqlQueryItemArgs = {
|
|
70
70
|
itemId: string
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export type
|
|
73
|
+
export type DeleteDcqlQueryItemsArgs = GetDcqlQueryItemsArgs
|
|
74
74
|
|
|
75
|
-
export type
|
|
75
|
+
export type PersistDcqlQueryItem = Omit<NonPersistedDcqlQueryItem, 'version'> & {
|
|
76
76
|
id?: string
|
|
77
|
-
definitionId?: string
|
|
78
77
|
version?: string
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -83,8 +82,8 @@ export type PersistOptions = {
|
|
|
83
82
|
versionIncrementReleaseType?: ReleaseType
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
export type
|
|
87
|
-
definitionItem:
|
|
85
|
+
export type PersistDcqlQueryArgs = {
|
|
86
|
+
definitionItem: PersistDcqlQueryItem
|
|
88
87
|
opts?: PersistOptions
|
|
89
88
|
}
|
|
90
89
|
|