@sphereon/ssi-sdk.pd-manager 0.34.1-feat.SSISDK.35.64 → 0.34.1-feat.SSISDK.55.243
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 +1032 -1040
- 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 +1024 -1033
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/plugin.schema.json +20 -26
- package/src/agent/PDManager.ts +62 -55
- 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,42 +95,41 @@ 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:
|
|
108
|
+
private async pdmPersistDefinition(args: PersistDcqlQueryArgs): Promise<DcqlQueryItem> {
|
|
113
109
|
const { definitionItem, opts } = args
|
|
114
110
|
const { versionControlMode, versionIncrementReleaseType } = opts ?? { versionControlMode: 'AutoIncrement' }
|
|
115
111
|
const { version, tenantId } = definitionItem
|
|
116
|
-
const definitionId = definitionItem.
|
|
112
|
+
const definitionId = definitionItem.queryId
|
|
117
113
|
|
|
118
114
|
let { id } = definitionItem
|
|
119
115
|
if (id !== undefined && versionControlMode !== 'Overwrite') {
|
|
120
116
|
id = undefined
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
const nonPersistedDefinitionItem:
|
|
119
|
+
const nonPersistedDefinitionItem: NonPersistedDcqlQueryItem = {
|
|
124
120
|
...definitionItem,
|
|
125
|
-
definitionId: definitionId,
|
|
126
121
|
version: version ?? '1',
|
|
127
122
|
}
|
|
128
123
|
|
|
129
|
-
const existing = await this.store.getDefinitions({ filter: [{ id, definitionId, tenantId, version }] })
|
|
124
|
+
const existing = await this.store.getDefinitions({ filter: [{ id, queryId: definitionId, tenantId, version }] })
|
|
130
125
|
const existingItem = existing[0]
|
|
131
126
|
|
|
132
127
|
// Always fetch all definitions for the definitionId/tenantId and determine the truly latest version
|
|
133
|
-
const allDefinitions = await this.store.getDefinitions({ filter: [{ definitionId, tenantId }] })
|
|
128
|
+
const allDefinitions = await this.store.getDefinitions({ filter: [{ queryId: definitionId, tenantId }] })
|
|
134
129
|
allDefinitions.sort((a, b) => semver.compare(this.normalizeToSemverVersionFormat(a.version), this.normalizeToSemverVersionFormat(b.version)))
|
|
135
130
|
const trulyLatestVersionItem = allDefinitions[allDefinitions.length - 1]
|
|
136
131
|
|
|
137
|
-
let latestVersionItem:
|
|
132
|
+
let latestVersionItem: DcqlQueryItem | undefined = trulyLatestVersionItem
|
|
138
133
|
|
|
139
134
|
// If a specific version exists and matches existingItem, we keep that as a base.
|
|
140
135
|
// Otherwise we use the trulyLatestVersionItem
|
|
@@ -160,50 +155,58 @@ export class PDManager implements IAgentPlugin {
|
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
private async handleOverwriteMode(
|
|
163
|
-
existingItem:
|
|
164
|
-
definitionItem:
|
|
158
|
+
existingItem: DcqlQueryItem | undefined,
|
|
159
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
165
160
|
version: string | undefined,
|
|
166
|
-
): Promise<
|
|
161
|
+
): Promise<DcqlQueryItem> {
|
|
167
162
|
if (existingItem) {
|
|
168
|
-
existingItem.
|
|
163
|
+
existingItem.queryId = definitionItem.queryId
|
|
169
164
|
existingItem.version = version ?? existingItem.version ?? '1'
|
|
170
165
|
existingItem.tenantId = definitionItem.tenantId
|
|
171
|
-
existingItem.name = definitionItem.
|
|
172
|
-
existingItem.purpose = definitionItem.
|
|
173
|
-
existingItem.
|
|
166
|
+
existingItem.name = definitionItem.name
|
|
167
|
+
existingItem.purpose = definitionItem.purpose
|
|
168
|
+
existingItem.query = definitionItem.query
|
|
174
169
|
|
|
175
170
|
return await this.store.updateDefinition(existingItem)
|
|
176
171
|
} else {
|
|
177
|
-
|
|
172
|
+
// Apply the same field extraction logic for new items
|
|
173
|
+
const newDefinitionItem = {
|
|
174
|
+
...definitionItem,
|
|
175
|
+
} satisfies AddDefinitionArgs
|
|
176
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
private async handleOverwriteLatestMode(
|
|
182
|
-
latestVersionItem:
|
|
183
|
-
definitionItem:
|
|
184
|
-
): Promise<
|
|
181
|
+
latestVersionItem: DcqlQueryItem | undefined,
|
|
182
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
183
|
+
): Promise<DcqlQueryItem> {
|
|
185
184
|
if (latestVersionItem) {
|
|
186
|
-
latestVersionItem.
|
|
185
|
+
latestVersionItem.queryId = definitionItem.queryId
|
|
187
186
|
latestVersionItem.tenantId = definitionItem.tenantId
|
|
188
187
|
latestVersionItem.name = definitionItem.name
|
|
189
188
|
latestVersionItem.purpose = definitionItem.purpose
|
|
190
|
-
latestVersionItem.
|
|
189
|
+
latestVersionItem.query = definitionItem.query
|
|
191
190
|
|
|
192
191
|
return await this.store.updateDefinition(latestVersionItem)
|
|
193
192
|
} else {
|
|
194
|
-
|
|
193
|
+
// Apply the same field extraction logic for new items
|
|
194
|
+
const newDefinitionItem = {
|
|
195
|
+
...definitionItem,
|
|
196
|
+
} satisfies AddDefinitionArgs
|
|
197
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
private async handleManualMode(
|
|
199
|
-
existingItem:
|
|
200
|
-
definitionItem:
|
|
202
|
+
existingItem: DcqlQueryItem | undefined,
|
|
203
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
201
204
|
tenantId: string | undefined,
|
|
202
205
|
version: string | undefined,
|
|
203
|
-
): Promise<
|
|
206
|
+
): Promise<DcqlQueryItem> {
|
|
204
207
|
if (existingItem && !isPresentationDefinitionEqual(existingItem, definitionItem)) {
|
|
205
208
|
throw Error(
|
|
206
|
-
`Cannot update definition ${definitionItem.
|
|
209
|
+
`Cannot update definition ${definitionItem.queryId} for tenant ${tenantId} version ${version} because definition exists and manual version control is enabled.`,
|
|
207
210
|
)
|
|
208
211
|
} else {
|
|
209
212
|
return await this.store.addDefinition(definitionItem)
|
|
@@ -211,10 +214,10 @@ export class PDManager implements IAgentPlugin {
|
|
|
211
214
|
}
|
|
212
215
|
|
|
213
216
|
private async handleAutoIncrementMode(
|
|
214
|
-
latestVersionItem:
|
|
215
|
-
definitionItem:
|
|
217
|
+
latestVersionItem: DcqlQueryItem | undefined,
|
|
218
|
+
definitionItem: NonPersistedDcqlQueryItem,
|
|
216
219
|
releaseType: ReleaseType,
|
|
217
|
-
): Promise<
|
|
220
|
+
): Promise<DcqlQueryItem> {
|
|
218
221
|
const defaultVersion = '1'
|
|
219
222
|
let currentVersion = latestVersionItem?.version ?? definitionItem.version ?? defaultVersion
|
|
220
223
|
let resultVersion: string
|
|
@@ -230,7 +233,7 @@ export class PDManager implements IAgentPlugin {
|
|
|
230
233
|
let fullVersionToIncrement = preReleaseIdentifier ? `${normalizedBaseVersion}-${preReleaseSuffix}` : normalizedBaseVersion
|
|
231
234
|
|
|
232
235
|
// Use semver to increment the version
|
|
233
|
-
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, preReleaseIdentifier)
|
|
236
|
+
let incrementedVersion = semver.inc(fullVersionToIncrement, releaseType, undefined, preReleaseIdentifier)
|
|
234
237
|
if (!incrementedVersion) {
|
|
235
238
|
throw new Error(`Could not increment ${releaseType} version on ${currentVersion} ${preReleaseSuffix}`)
|
|
236
239
|
}
|
|
@@ -248,10 +251,14 @@ export class PDManager implements IAgentPlugin {
|
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
// Apply field extraction logic before adding
|
|
255
|
+
const newDefinitionItem = {
|
|
256
|
+
...definitionItem,
|
|
257
|
+
version: resultVersion,
|
|
258
|
+
} satisfies AddDefinitionArgs
|
|
254
259
|
|
|
260
|
+
return await this.store.addDefinition(newDefinitionItem)
|
|
261
|
+
}
|
|
255
262
|
private normalizeToSemverVersionFormat(version: string): string {
|
|
256
263
|
const defaultVersion = '1.0.0'
|
|
257
264
|
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
|
|