@sphereon/ssi-sdk.pd-manager 0.34.1-feature.SSISDK.50.98 → 0.34.1-feature.SSISDK.50.type.refactor.148
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 +27 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -18
- package/dist/index.d.ts +19 -18
- package/dist/index.js +27 -20
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/agent/PDManager.ts +62 -51
- package/src/index.ts +1 -0
- package/src/types/IPDManager.ts +17 -17
package/src/agent/PDManager.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
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
13
|
import {
|
|
14
14
|
AbstractPDStore,
|
|
15
15
|
isPresentationDefinitionEqual,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
NonPersistedDcqlQueryItem,
|
|
17
|
+
DcqlQueryItem,
|
|
18
|
+
AddDefinitionArgs,
|
|
18
19
|
} from '@sphereon/ssi-sdk.data-store'
|
|
19
20
|
import semver from 'semver/preload'
|
|
20
21
|
import { ReleaseType } from 'semver'
|
|
@@ -58,32 +59,32 @@ export class PDManager implements IAgentPlugin {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/** {@inheritDoc IPDManager.pdmHasDefinitions} */
|
|
61
|
-
private async pdmHasDefinitions(args:
|
|
62
|
+
private async pdmHasDefinitions(args: HasDcqlQueryItemsArgs): Promise<boolean> {
|
|
62
63
|
const { filter } = args
|
|
63
64
|
return this.store.hasDefinitions({ filter })
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/** {@inheritDoc IPDManager.pdmGetDefinition} */
|
|
67
|
-
private async pdmGetDefinition(args:
|
|
68
|
+
private async pdmGetDefinition(args: GetDcqlQueryItemArgs): Promise<DcqlQueryItem> {
|
|
68
69
|
const { itemId } = args
|
|
69
70
|
return this.store.getDefinition({ itemId })
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/** {@inheritDoc IPDManager.pdmGetDefinitions} */
|
|
73
|
-
private async pdmGetDefinitions(args:
|
|
74
|
+
private async pdmGetDefinitions(args: GetDcqlQueryItemsArgs): Promise<Array<DcqlQueryItem>> {
|
|
74
75
|
const { filter, opts } = args
|
|
75
76
|
const allDefinitions = await this.store.getDefinitions({ filter })
|
|
76
|
-
let definitions:
|
|
77
|
+
let definitions: DcqlQueryItem[] = []
|
|
77
78
|
if (opts == undefined || opts.showVersionHistory !== true) {
|
|
78
79
|
const groupedByDefinitionId = allDefinitions.reduce(
|
|
79
80
|
(acc, entity) => {
|
|
80
|
-
if (!acc[entity.
|
|
81
|
-
acc[entity.
|
|
81
|
+
if (!acc[entity.queryId]) {
|
|
82
|
+
acc[entity.queryId] = []
|
|
82
83
|
}
|
|
83
|
-
acc[entity.
|
|
84
|
+
acc[entity.queryId].push(entity)
|
|
84
85
|
return acc
|
|
85
86
|
},
|
|
86
|
-
{} as Record<string,
|
|
87
|
+
{} as Record<string, DcqlQueryItem[]>,
|
|
87
88
|
)
|
|
88
89
|
definitions = Object.values(groupedByDefinitionId).map((entities) =>
|
|
89
90
|
entities.reduce((highestVersionItem, baseItem) => {
|
|
@@ -99,41 +100,41 @@ export class PDManager implements IAgentPlugin {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
/** {@inheritDoc IPDManager.pdmDeleteDefinition} */
|
|
102
|
-
private async pdmDeleteDefinition(args:
|
|
103
|
+
private async pdmDeleteDefinition(args: DeleteDcqlQueryItemArgs): Promise<boolean> {
|
|
103
104
|
return this.store.deleteDefinition(args).then((value) => true)
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
/** {@inheritDoc IPDManager.pdmDeleteDefinitions} */
|
|
107
|
-
private async pdmDeleteDefinitions(args:
|
|
108
|
+
private async pdmDeleteDefinitions(args: DeleteDcqlQueryItemsArgs): Promise<number> {
|
|
108
109
|
return this.store.deleteDefinitions(args)
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
/** {@inheritDoc IPDManager.pdmPersistDefinition} */
|
|
112
|
-
private async pdmPersistDefinition(args:
|
|
113
|
+
private async pdmPersistDefinition(args: PersistDcqlQueryArgs): Promise<DcqlQueryItem> {
|
|
113
114
|
const { definitionItem, opts } = args
|
|
114
115
|
const { versionControlMode, versionIncrementReleaseType } = opts ?? { versionControlMode: 'AutoIncrement' }
|
|
115
116
|
const { version, tenantId } = definitionItem
|
|
116
|
-
const definitionId = definitionItem.
|
|
117
|
+
const definitionId = definitionItem.queryId
|
|
117
118
|
|
|
118
119
|
let { id } = definitionItem
|
|
119
120
|
if (id !== undefined && versionControlMode !== 'Overwrite') {
|
|
120
121
|
id = undefined
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
const nonPersistedDefinitionItem:
|
|
124
|
+
const nonPersistedDefinitionItem: NonPersistedDcqlQueryItem = {
|
|
124
125
|
...definitionItem,
|
|
125
126
|
version: version ?? '1',
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
const existing = await this.store.getDefinitions({ filter: [{ id, definitionId, tenantId, version }] })
|
|
129
|
+
const existing = await this.store.getDefinitions({ filter: [{ id, queryId: definitionId, tenantId, version }] })
|
|
129
130
|
const existingItem = existing[0]
|
|
130
131
|
|
|
131
132
|
// Always fetch all definitions for the definitionId/tenantId and determine the truly latest version
|
|
132
|
-
const allDefinitions = await this.store.getDefinitions({ filter: [{ definitionId, tenantId }] })
|
|
133
|
+
const allDefinitions = await this.store.getDefinitions({ filter: [{ queryId: definitionId, tenantId }] })
|
|
133
134
|
allDefinitions.sort((a, b) => semver.compare(this.normalizeToSemverVersionFormat(a.version), this.normalizeToSemverVersionFormat(b.version)))
|
|
134
135
|
const trulyLatestVersionItem = allDefinitions[allDefinitions.length - 1]
|
|
135
136
|
|
|
136
|
-
let latestVersionItem:
|
|
137
|
+
let latestVersionItem: DcqlQueryItem | undefined = trulyLatestVersionItem
|
|
137
138
|
|
|
138
139
|
// If a specific version exists and matches existingItem, we keep that as a base.
|
|
139
140
|
// Otherwise we use the trulyLatestVersionItem
|
|
@@ -159,52 +160,58 @@ export class PDManager implements IAgentPlugin {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
private async handleOverwriteMode(
|
|
162
|
-
existingItem:
|
|
163
|
-
definitionItem:
|
|
163
|
+
existingItem: DcqlQueryItem | undefined,
|
|
164
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
164
165
|
version: string | undefined,
|
|
165
|
-
): Promise<
|
|
166
|
+
): Promise<DcqlQueryItem> {
|
|
166
167
|
if (existingItem) {
|
|
167
|
-
existingItem.
|
|
168
|
+
existingItem.queryId = definitionItem.queryId
|
|
168
169
|
existingItem.version = version ?? existingItem.version ?? '1'
|
|
169
170
|
existingItem.tenantId = definitionItem.tenantId
|
|
170
|
-
existingItem.name = definitionItem.
|
|
171
|
-
existingItem.purpose = definitionItem.
|
|
172
|
-
existingItem.
|
|
173
|
-
existingItem.definitionPayload = definitionItem.definitionPayload
|
|
171
|
+
existingItem.name = definitionItem.name
|
|
172
|
+
existingItem.purpose = definitionItem.purpose
|
|
173
|
+
existingItem.dcqlQuery = definitionItem.dcqlQuery
|
|
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.
|
|
191
|
-
latestVersionItem.dcqlPayload = definitionItem.dcqlPayload
|
|
194
|
+
latestVersionItem.dcqlQuery = definitionItem.dcqlQuery
|
|
192
195
|
|
|
193
196
|
return await this.store.updateDefinition(latestVersionItem)
|
|
194
197
|
} else {
|
|
195
|
-
|
|
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)
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
private async handleManualMode(
|
|
200
|
-
existingItem:
|
|
201
|
-
definitionItem:
|
|
207
|
+
existingItem: DcqlQueryItem | undefined,
|
|
208
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
202
209
|
tenantId: string | undefined,
|
|
203
210
|
version: string | undefined,
|
|
204
|
-
): Promise<
|
|
211
|
+
): Promise<DcqlQueryItem> {
|
|
205
212
|
if (existingItem && !isPresentationDefinitionEqual(existingItem, definitionItem)) {
|
|
206
213
|
throw Error(
|
|
207
|
-
`Cannot update definition ${definitionItem.
|
|
214
|
+
`Cannot update definition ${definitionItem.queryId} for tenant ${tenantId} version ${version} because definition exists and manual version control is enabled.`,
|
|
208
215
|
)
|
|
209
216
|
} else {
|
|
210
217
|
return await this.store.addDefinition(definitionItem)
|
|
@@ -212,10 +219,10 @@ export class PDManager implements IAgentPlugin {
|
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
private async handleAutoIncrementMode(
|
|
215
|
-
latestVersionItem:
|
|
216
|
-
definitionItem:
|
|
222
|
+
latestVersionItem: DcqlQueryItem | undefined,
|
|
223
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
217
224
|
releaseType: ReleaseType,
|
|
218
|
-
): Promise<
|
|
225
|
+
): Promise<DcqlQueryItem> {
|
|
219
226
|
const defaultVersion = '1'
|
|
220
227
|
let currentVersion = latestVersionItem?.version ?? definitionItem.version ?? defaultVersion
|
|
221
228
|
let resultVersion: string
|
|
@@ -231,7 +238,7 @@ export class PDManager implements IAgentPlugin {
|
|
|
231
238
|
let fullVersionToIncrement = preReleaseIdentifier ? `${normalizedBaseVersion}-${preReleaseSuffix}` : normalizedBaseVersion
|
|
232
239
|
|
|
233
240
|
// Use semver to increment the version
|
|
234
|
-
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, preReleaseIdentifier)
|
|
241
|
+
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, undefined, preReleaseIdentifier)
|
|
235
242
|
if (!incrementedVersion) {
|
|
236
243
|
throw new Error(`Could not increment ${releaseType} version on ${currentVersion} ${preReleaseSuffix}`)
|
|
237
244
|
}
|
|
@@ -249,10 +256,14 @@ export class PDManager implements IAgentPlugin {
|
|
|
249
256
|
}
|
|
250
257
|
}
|
|
251
258
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
259
|
+
// Apply field extraction logic before adding
|
|
260
|
+
const newDefinitionItem = {
|
|
261
|
+
...definitionItem,
|
|
262
|
+
version: resultVersion,
|
|
263
|
+
} satisfies AddDefinitionArgs
|
|
255
264
|
|
|
265
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
266
|
+
}
|
|
256
267
|
private normalizeToSemverVersionFormat(version: string): string {
|
|
257
268
|
const defaultVersion = '1.0.0'
|
|
258
269
|
let [baseVersion, preReleaseSuffix] = version.split(/-(.+)/)
|
package/src/index.ts
CHANGED
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'
|
|
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,54 +25,54 @@ 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
77
|
version?: string
|
|
78
78
|
}
|
|
@@ -82,8 +82,8 @@ export type PersistOptions = {
|
|
|
82
82
|
versionIncrementReleaseType?: ReleaseType
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export type
|
|
86
|
-
definitionItem:
|
|
85
|
+
export type PersistDcqlQueryArgs = {
|
|
86
|
+
definitionItem: PersistDcqlQueryItem
|
|
87
87
|
opts?: PersistOptions
|
|
88
88
|
}
|
|
89
89
|
|