@sphereon/ssi-sdk.pd-manager 0.34.1-feature.SSISDK.26.RP.58 → 0.34.1-feature.SSISDK.45.189
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 +1037 -1039
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2162 -25
- package/dist/index.d.ts +2162 -25
- package/dist/index.js +1029 -1032
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/plugin.schema.json +1 -1
- package/src/agent/PDManager.ts +62 -50
- package/src/index.ts +2 -1
- package/src/types/IPDManager.ts +17 -18
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,42 +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
|
-
definitionId: definitionId,
|
|
126
126
|
version: version ?? '1',
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const existing = await this.store.getDefinitions({ filter: [{ id, definitionId, tenantId, version }] })
|
|
129
|
+
const existing = await this.store.getDefinitions({ filter: [{ id, queryId: definitionId, tenantId, version }] })
|
|
130
130
|
const existingItem = existing[0]
|
|
131
131
|
|
|
132
132
|
// Always fetch all definitions for the definitionId/tenantId and determine the truly latest version
|
|
133
|
-
const allDefinitions = await this.store.getDefinitions({ filter: [{ definitionId, tenantId }] })
|
|
133
|
+
const allDefinitions = await this.store.getDefinitions({ filter: [{ queryId: definitionId, tenantId }] })
|
|
134
134
|
allDefinitions.sort((a, b) => semver.compare(this.normalizeToSemverVersionFormat(a.version), this.normalizeToSemverVersionFormat(b.version)))
|
|
135
135
|
const trulyLatestVersionItem = allDefinitions[allDefinitions.length - 1]
|
|
136
136
|
|
|
137
|
-
let latestVersionItem:
|
|
137
|
+
let latestVersionItem: DcqlQueryItem | undefined = trulyLatestVersionItem
|
|
138
138
|
|
|
139
139
|
// If a specific version exists and matches existingItem, we keep that as a base.
|
|
140
140
|
// Otherwise we use the trulyLatestVersionItem
|
|
@@ -160,50 +160,58 @@ export class PDManager implements IAgentPlugin {
|
|
|
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,14 @@ export class PDManager implements IAgentPlugin {
|
|
|
248
256
|
}
|
|
249
257
|
}
|
|
250
258
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
259
|
+
// Apply field extraction logic before adding
|
|
260
|
+
const newDefinitionItem = {
|
|
261
|
+
...definitionItem,
|
|
262
|
+
version: resultVersion,
|
|
263
|
+
} satisfies AddDefinitionArgs
|
|
254
264
|
|
|
265
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
266
|
+
}
|
|
255
267
|
private normalizeToSemverVersionFormat(version: string): string {
|
|
256
268
|
const defaultVersion = '1.0.0'
|
|
257
269
|
let [baseVersion, preReleaseSuffix] = version.split(/-(.+)/)
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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'
|
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,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
|
|