@sphereon/ssi-sdk.presentation-exchange 0.11.1-next.65

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.
Files changed (70) hide show
  1. package/.yalc/@veramo/kv-store/LICENSE +201 -0
  2. package/.yalc/@veramo/kv-store/README.md +132 -0
  3. package/.yalc/@veramo/kv-store/build/index.d.ts +11 -0
  4. package/.yalc/@veramo/kv-store/build/index.js +45 -0
  5. package/.yalc/@veramo/kv-store/build/key-value-store.d.ts +27 -0
  6. package/.yalc/@veramo/kv-store/build/key-value-store.js +143 -0
  7. package/.yalc/@veramo/kv-store/build/key-value-types.d.ts +51 -0
  8. package/.yalc/@veramo/kv-store/build/key-value-types.js +3 -0
  9. package/.yalc/@veramo/kv-store/build/keyv/keyv-types.d.ts +62 -0
  10. package/.yalc/@veramo/kv-store/build/keyv/keyv-types.js +3 -0
  11. package/.yalc/@veramo/kv-store/build/keyv/keyv.d.ts +53 -0
  12. package/.yalc/@veramo/kv-store/build/keyv/keyv.js +385 -0
  13. package/.yalc/@veramo/kv-store/build/store-adapters/index.d.ts +3 -0
  14. package/.yalc/@veramo/kv-store/build/store-adapters/index.js +30 -0
  15. package/.yalc/@veramo/kv-store/build/store-adapters/tiered/index.d.ts +32 -0
  16. package/.yalc/@veramo/kv-store/build/store-adapters/tiered/index.js +301 -0
  17. package/.yalc/@veramo/kv-store/build/store-adapters/tiered/types.d.ts +14 -0
  18. package/.yalc/@veramo/kv-store/build/store-adapters/tiered/types.js +3 -0
  19. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/entities/keyValueStoreEntity.d.ts +11 -0
  20. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/entities/keyValueStoreEntity.js +50 -0
  21. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/index.d.ts +41 -0
  22. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/index.js +186 -0
  23. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/migrations/1.createKVDatabase.d.ts +14 -0
  24. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/migrations/1.createKVDatabase.js +90 -0
  25. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/migrations/index.d.ts +10 -0
  26. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/migrations/index.js +13 -0
  27. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/types.d.ts +15 -0
  28. package/.yalc/@veramo/kv-store/build/store-adapters/typeorm/types.js +3 -0
  29. package/.yalc/@veramo/kv-store/build/tsdoc-metadata.json +11 -0
  30. package/.yalc/@veramo/kv-store/package.json +39 -0
  31. package/.yalc/@veramo/kv-store/src/__tests__/keyv.test.ts +204 -0
  32. package/.yalc/@veramo/kv-store/src/__tests__/kvstore.test.ts +93 -0
  33. package/.yalc/@veramo/kv-store/src/index.ts +10 -0
  34. package/.yalc/@veramo/kv-store/src/key-value-store.ts +109 -0
  35. package/.yalc/@veramo/kv-store/src/key-value-types.ts +97 -0
  36. package/.yalc/@veramo/kv-store/src/keyv/keyv-types.ts +71 -0
  37. package/.yalc/@veramo/kv-store/src/keyv/keyv.ts +282 -0
  38. package/.yalc/@veramo/kv-store/src/store-adapters/index.ts +2 -0
  39. package/.yalc/@veramo/kv-store/src/store-adapters/tiered/index.ts +158 -0
  40. package/.yalc/@veramo/kv-store/src/store-adapters/tiered/types.ts +16 -0
  41. package/.yalc/@veramo/kv-store/src/store-adapters/typeorm/entities/keyValueStoreEntity.ts +20 -0
  42. package/.yalc/@veramo/kv-store/src/store-adapters/typeorm/index.ts +122 -0
  43. package/.yalc/@veramo/kv-store/src/store-adapters/typeorm/migrations/1.createKVDatabase.ts +47 -0
  44. package/.yalc/@veramo/kv-store/src/store-adapters/typeorm/migrations/index.ts +10 -0
  45. package/.yalc/@veramo/kv-store/src/store-adapters/typeorm/types.ts +18 -0
  46. package/.yalc/@veramo/kv-store/yalc.sig +1 -0
  47. package/LICENSE +201 -0
  48. package/README.md +56 -0
  49. package/dist/agent/PresentationExchange.d.ts +25 -0
  50. package/dist/agent/PresentationExchange.d.ts.map +1 -0
  51. package/dist/agent/PresentationExchange.js +182 -0
  52. package/dist/agent/PresentationExchange.js.map +1 -0
  53. package/dist/functions.d.ts +12 -0
  54. package/dist/functions.d.ts.map +1 -0
  55. package/dist/functions.js +41 -0
  56. package/dist/functions.js.map +1 -0
  57. package/dist/index.d.ts +9 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +27 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/types/IPresentationExchange.d.ts +81 -0
  62. package/dist/types/IPresentationExchange.d.ts.map +1 -0
  63. package/dist/types/IPresentationExchange.js +3 -0
  64. package/dist/types/IPresentationExchange.js.map +1 -0
  65. package/package.json +67 -0
  66. package/plugin.schema.json +329 -0
  67. package/src/agent/PresentationExchange.ts +204 -0
  68. package/src/functions.ts +56 -0
  69. package/src/index.ts +8 -0
  70. package/src/types/IPresentationExchange.ts +114 -0
@@ -0,0 +1,301 @@
1
+ 'use strict'
2
+ var __awaiter =
3
+ (this && this.__awaiter) ||
4
+ function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) {
6
+ return value instanceof P
7
+ ? value
8
+ : new P(function (resolve) {
9
+ resolve(value)
10
+ })
11
+ }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) {
14
+ try {
15
+ step(generator.next(value))
16
+ } catch (e) {
17
+ reject(e)
18
+ }
19
+ }
20
+ function rejected(value) {
21
+ try {
22
+ step(generator['throw'](value))
23
+ } catch (e) {
24
+ reject(e)
25
+ }
26
+ }
27
+ function step(result) {
28
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
29
+ }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next())
31
+ })
32
+ }
33
+ var __rest =
34
+ (this && this.__rest) ||
35
+ function (s, e) {
36
+ var t = {}
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]
38
+ if (s != null && typeof Object.getOwnPropertySymbols === 'function')
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]
41
+ }
42
+ return t
43
+ }
44
+ var __asyncValues =
45
+ (this && this.__asyncValues) ||
46
+ function (o) {
47
+ if (!Symbol.asyncIterator) throw new TypeError('Symbol.asyncIterator is not defined.')
48
+ var m = o[Symbol.asyncIterator],
49
+ i
50
+ return m
51
+ ? m.call(o)
52
+ : ((o = typeof __values === 'function' ? __values(o) : o[Symbol.iterator]()),
53
+ (i = {}),
54
+ verb('next'),
55
+ verb('throw'),
56
+ verb('return'),
57
+ (i[Symbol.asyncIterator] = function () {
58
+ return this
59
+ }),
60
+ i)
61
+ function verb(n) {
62
+ i[n] =
63
+ o[n] &&
64
+ function (v) {
65
+ return new Promise(function (resolve, reject) {
66
+ ;(v = o[n](v)), settle(resolve, reject, v.done, v.value)
67
+ })
68
+ }
69
+ }
70
+ function settle(resolve, reject, d, v) {
71
+ Promise.resolve(v).then(function (v) {
72
+ resolve({ value: v, done: d })
73
+ }, reject)
74
+ }
75
+ }
76
+ var __await =
77
+ (this && this.__await) ||
78
+ function (v) {
79
+ return this instanceof __await ? ((this.v = v), this) : new __await(v)
80
+ }
81
+ var __asyncGenerator =
82
+ (this && this.__asyncGenerator) ||
83
+ function (thisArg, _arguments, generator) {
84
+ if (!Symbol.asyncIterator) throw new TypeError('Symbol.asyncIterator is not defined.')
85
+ var g = generator.apply(thisArg, _arguments || []),
86
+ i,
87
+ q = []
88
+ return (
89
+ (i = {}),
90
+ verb('next'),
91
+ verb('throw'),
92
+ verb('return'),
93
+ (i[Symbol.asyncIterator] = function () {
94
+ return this
95
+ }),
96
+ i
97
+ )
98
+ function verb(n) {
99
+ if (g[n])
100
+ i[n] = function (v) {
101
+ return new Promise(function (a, b) {
102
+ q.push([n, v, a, b]) > 1 || resume(n, v)
103
+ })
104
+ }
105
+ }
106
+ function resume(n, v) {
107
+ try {
108
+ step(g[n](v))
109
+ } catch (e) {
110
+ settle(q[0][3], e)
111
+ }
112
+ }
113
+ function step(r) {
114
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r)
115
+ }
116
+ function fulfill(value) {
117
+ resume('next', value)
118
+ }
119
+ function reject(value) {
120
+ resume('throw', value)
121
+ }
122
+ function settle(f, v) {
123
+ if ((f(v), q.shift(), q.length)) resume(q[0][0], q[0][1])
124
+ }
125
+ }
126
+ Object.defineProperty(exports, '__esModule', { value: true })
127
+ exports.KeyValueTieredStoreAdapter = void 0
128
+ const events_1 = require('events')
129
+ const keyv_1 = require('../../keyv/keyv')
130
+ class KeyValueTieredStoreAdapter extends events_1.EventEmitter {
131
+ constructor(_a) {
132
+ var { remote, local } = _a,
133
+ options = __rest(_a, ['remote', 'local'])
134
+ super()
135
+ this.opts = Object.assign({ validator: () => true, dialect: 'tiered' }, options)
136
+ // todo: since we are instantiating a new Keyv object in case we encounter a map, the key prefix applied twice, given it will be part of a an outer keyv object as well.
137
+ // Probably wise to simply create a Map Store class. As it is an in memory construct, and will work in terms of resolution it does not have highest priority
138
+ this.local = isMap(local) ? new keyv_1.Keyv(local) : local
139
+ this.remote = isMap(remote) ? new keyv_1.Keyv(remote) : remote
140
+ this.namespace = this.local.namespace
141
+ }
142
+ get(key, options) {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ if (Array.isArray(key)) {
145
+ return yield this.getMany(key, options)
146
+ }
147
+ const localResult = yield this.local.get(key, options)
148
+ if (localResult === undefined || !this.opts.validator(localResult, key)) {
149
+ const remoteResult = yield this.remote.get(key, options)
150
+ if (remoteResult !== localResult) {
151
+ const value = !!remoteResult ? (typeof remoteResult === 'object' && 'value' in remoteResult ? remoteResult.value : remoteResult) : undefined
152
+ const ttl =
153
+ !!remoteResult && typeof remoteResult === 'object' && 'expires' in remoteResult && remoteResult.expires
154
+ ? remoteResult.expires - Date.now()
155
+ : undefined
156
+ if (!ttl || ttl > 0) {
157
+ yield this.local.set(key, value, ttl)
158
+ } else {
159
+ this.local.delete(key)
160
+ }
161
+ }
162
+ return remoteResult
163
+ }
164
+ return localResult
165
+ })
166
+ }
167
+ getMany(keys, options) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ const promises = []
170
+ for (const key of keys) {
171
+ promises.push(this.get(key, options))
172
+ }
173
+ const values = yield Promise.all(promises)
174
+ const data = []
175
+ for (const value of values) {
176
+ data.push(value)
177
+ }
178
+ return data
179
+ })
180
+ }
181
+ set(key, value, ttl) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ const toSet = ['local', 'remote']
184
+ return Promise.all(
185
+ toSet.map((store) =>
186
+ __awaiter(this, void 0, void 0, function* () {
187
+ return this[store].set(key, value, ttl)
188
+ })
189
+ )
190
+ )
191
+ })
192
+ }
193
+ clear() {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const toClear = ['local']
196
+ if (!this.opts.localOnly) {
197
+ toClear.push('remote')
198
+ }
199
+ yield Promise.all(
200
+ toClear.map((store) =>
201
+ __awaiter(this, void 0, void 0, function* () {
202
+ return this[store].clear()
203
+ })
204
+ )
205
+ )
206
+ return undefined
207
+ })
208
+ }
209
+ delete(key) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const toDelete = ['local']
212
+ if (!this.opts.localOnly) {
213
+ toDelete.push('remote')
214
+ }
215
+ const deleted = yield Promise.all(
216
+ toDelete.map((store) =>
217
+ __awaiter(this, void 0, void 0, function* () {
218
+ return this[store].delete(key)
219
+ })
220
+ )
221
+ )
222
+ return deleted.every(Boolean)
223
+ })
224
+ }
225
+ deleteMany(keys) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ const promises = []
228
+ for (const key of keys) {
229
+ promises.push(this.delete(key))
230
+ }
231
+ const values = yield Promise.all(promises)
232
+ return values.every(Boolean)
233
+ })
234
+ }
235
+ has(key) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ let response
238
+ if (typeof this.local.has === 'function') {
239
+ response = this.local.has(key)
240
+ } else {
241
+ const value = yield this.local.get(key)
242
+ response = value !== undefined
243
+ }
244
+ if (!response || !this.opts.validator(response, key)) {
245
+ if (typeof this.remote.has === 'function') {
246
+ response = this.remote.has(key)
247
+ } else {
248
+ const value = yield this.remote.get(key)
249
+ response = value !== undefined
250
+ }
251
+ }
252
+ return response
253
+ })
254
+ }
255
+ iterator(namespace) {
256
+ return __asyncGenerator(this, arguments, function* iterator_1() {
257
+ var _a, e_1, _b, _c
258
+ const limit = Number.parseInt(this.iterationLimit, 10) || 10
259
+ this.remote.opts.iterationLimit = limit
260
+ if (this.remote && typeof this.remote.iterator === 'function') {
261
+ try {
262
+ for (var _d = true, _e = __asyncValues(this.remote.iterator(namespace)), _f; (_f = yield __await(_e.next())), (_a = _f.done), !_a; ) {
263
+ _c = _f.value
264
+ _d = false
265
+ try {
266
+ const entries = _c
267
+ yield yield __await(entries)
268
+ } finally {
269
+ _d = true
270
+ }
271
+ }
272
+ } catch (e_1_1) {
273
+ e_1 = { error: e_1_1 }
274
+ } finally {
275
+ try {
276
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e))
277
+ } finally {
278
+ if (e_1) throw e_1.error
279
+ }
280
+ }
281
+ }
282
+ })
283
+ }
284
+ }
285
+ exports.KeyValueTieredStoreAdapter = KeyValueTieredStoreAdapter
286
+ function isMap(map) {
287
+ if (map instanceof Map) {
288
+ return true
289
+ } else if (
290
+ map &&
291
+ typeof map.clear === 'function' &&
292
+ typeof map.delete === 'function' &&
293
+ typeof map.get === 'function' &&
294
+ typeof map.has === 'function' &&
295
+ typeof map.set === 'function'
296
+ ) {
297
+ return true
298
+ }
299
+ return false
300
+ }
301
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ import { IKeyValueStoreAdapter } from '../../key-value-types'
2
+ export type Options<ValueType> = {
3
+ local: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>
4
+ remote: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>
5
+ localOnly?: boolean
6
+ iterationLimit?: number | string
7
+ }
8
+ export type Options_ = {
9
+ validator: (value: any, key: string) => boolean
10
+ dialect: string
11
+ iterationLimit?: number | string
12
+ localOnly?: boolean
13
+ }
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,11 @@
1
+ import { BaseEntity } from 'typeorm'
2
+ /**
3
+ *
4
+ * @beta This API may change without a BREAKING CHANGE notice.
5
+ */
6
+ export declare class KeyValueStoreEntity extends BaseEntity {
7
+ key: string
8
+ data: string
9
+ expires?: number
10
+ }
11
+ //# sourceMappingURL=keyValueStoreEntity.d.ts.map
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+ var __decorate =
3
+ (this && this.__decorate) ||
4
+ function (decorators, target, key, desc) {
5
+ var c = arguments.length,
6
+ r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
7
+ d
8
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') r = Reflect.decorate(decorators, target, key, desc)
9
+ else
10
+ for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r
11
+ return c > 3 && r && Object.defineProperty(target, key, r), r
12
+ }
13
+ var __metadata =
14
+ (this && this.__metadata) ||
15
+ function (k, v) {
16
+ if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') return Reflect.metadata(k, v)
17
+ }
18
+ Object.defineProperty(exports, '__esModule', { value: true })
19
+ exports.KeyValueStoreEntity = void 0
20
+ const typeorm_1 = require('typeorm')
21
+ /**
22
+ *
23
+ * @beta This API may change without a BREAKING CHANGE notice.
24
+ */
25
+ let KeyValueStoreEntity = class KeyValueStoreEntity extends typeorm_1.BaseEntity {}
26
+ __decorate(
27
+ [
28
+ (0, typeorm_1.PrimaryColumn)(),
29
+ // @ts-ignore
30
+ __metadata('design:type', String),
31
+ ],
32
+ KeyValueStoreEntity.prototype,
33
+ 'key',
34
+ void 0
35
+ )
36
+ __decorate(
37
+ [
38
+ (0, typeorm_1.Column)({
39
+ type: 'text',
40
+ }),
41
+ // @ts-ignore
42
+ __metadata('design:type', String),
43
+ ],
44
+ KeyValueStoreEntity.prototype,
45
+ 'data',
46
+ void 0
47
+ )
48
+ KeyValueStoreEntity = __decorate([(0, typeorm_1.Entity)('keyvaluestore')], KeyValueStoreEntity)
49
+ exports.KeyValueStoreEntity = KeyValueStoreEntity
50
+ //# sourceMappingURL=keyValueStoreEntity.js.map
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events'
3
+ import { OrPromise } from '@veramo/utils'
4
+ import { DataSource } from 'typeorm'
5
+ import { KeyValueTypeORMOptions, Options_ } from './types'
6
+ import { KeyvStore, KeyvStoredData } from '../../keyv/keyv-types'
7
+ import { IKeyValueStoreAdapter } from '../../key-value-types'
8
+ export { KeyValueTypeORMOptions } from './types'
9
+ export { KeyValueStoreEntity } from './entities/keyValueStoreEntity'
10
+ export { kvStoreMigrations } from './migrations'
11
+ export declare class KeyValueTypeORMStoreAdapter extends EventEmitter implements KeyvStore<string>, IKeyValueStoreAdapter<string> {
12
+ private readonly dbConnection
13
+ readonly namespace: string
14
+ opts: Options_<string>
15
+ constructor(options: KeyValueTypeORMOptions)
16
+ get(
17
+ key: string | string[],
18
+ options?: {
19
+ raw?: boolean
20
+ }
21
+ ): Promise<KeyvStoredData<string> | Array<KeyvStoredData<string>>>
22
+ getMany(
23
+ keys: string[],
24
+ options?: {
25
+ raw?: boolean
26
+ }
27
+ ): Promise<Array<KeyvStoredData<string>>>
28
+ set(key: string, value: string, ttl?: number): Promise<KeyvStoredData<string>>
29
+ delete(key: string | string[]): Promise<boolean>
30
+ deleteMany(keys: string[]): Promise<boolean>
31
+ clear(): Promise<void>
32
+ has(key: string): Promise<boolean>
33
+ disconnect(): Promise<void>
34
+ }
35
+ /**
36
+ * Ensures that the provided DataSource is connected.
37
+ *
38
+ * @param dbConnection - a TypeORM DataSource or a Promise that resolves to a DataSource
39
+ */
40
+ export declare function getConnectedDb(dbConnection: OrPromise<DataSource>): Promise<DataSource>
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,186 @@
1
+ 'use strict'
2
+ var __awaiter =
3
+ (this && this.__awaiter) ||
4
+ function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) {
6
+ return value instanceof P
7
+ ? value
8
+ : new P(function (resolve) {
9
+ resolve(value)
10
+ })
11
+ }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) {
14
+ try {
15
+ step(generator.next(value))
16
+ } catch (e) {
17
+ reject(e)
18
+ }
19
+ }
20
+ function rejected(value) {
21
+ try {
22
+ step(generator['throw'](value))
23
+ } catch (e) {
24
+ reject(e)
25
+ }
26
+ }
27
+ function step(result) {
28
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
29
+ }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next())
31
+ })
32
+ }
33
+ var __importDefault =
34
+ (this && this.__importDefault) ||
35
+ function (mod) {
36
+ return mod && mod.__esModule ? mod : { default: mod }
37
+ }
38
+ Object.defineProperty(exports, '__esModule', { value: true })
39
+ exports.getConnectedDb = exports.KeyValueTypeORMStoreAdapter = exports.kvStoreMigrations = exports.KeyValueStoreEntity = void 0
40
+ const events_1 = require('events')
41
+ const typeorm_1 = require('typeorm')
42
+ const keyValueStoreEntity_1 = require('./entities/keyValueStoreEntity')
43
+ const json_buffer_1 = __importDefault(require('json-buffer'))
44
+ var keyValueStoreEntity_2 = require('./entities/keyValueStoreEntity')
45
+ Object.defineProperty(exports, 'KeyValueStoreEntity', {
46
+ enumerable: true,
47
+ get: function () {
48
+ return keyValueStoreEntity_2.KeyValueStoreEntity
49
+ },
50
+ })
51
+ var migrations_1 = require('./migrations')
52
+ Object.defineProperty(exports, 'kvStoreMigrations', {
53
+ enumerable: true,
54
+ get: function () {
55
+ return migrations_1.kvStoreMigrations
56
+ },
57
+ })
58
+ class KeyValueTypeORMStoreAdapter extends events_1.EventEmitter {
59
+ constructor(options) {
60
+ super()
61
+ this.dbConnection = options.dbConnection
62
+ this.namespace = options.namespace || 'keyv'
63
+ this.opts = Object.assign(
64
+ { validator: () => true, dialect: 'typeorm', serialize: json_buffer_1.default.stringify, deserialize: json_buffer_1.default.parse },
65
+ options
66
+ )
67
+ }
68
+ get(key, options) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ if (Array.isArray(key)) {
71
+ return this.getMany(key, options)
72
+ }
73
+ const connection = yield getConnectedDb(this.dbConnection)
74
+ const result = yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).findOneBy({
75
+ key,
76
+ })
77
+ return (options === null || options === void 0 ? void 0 : options.raw) !== true || !result
78
+ ? result === null || result === void 0
79
+ ? void 0
80
+ : result.data
81
+ : {
82
+ value: result === null || result === void 0 ? void 0 : result.data,
83
+ expires: result === null || result === void 0 ? void 0 : result.expires,
84
+ }
85
+ })
86
+ }
87
+ getMany(keys, options) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const connection = yield getConnectedDb(this.dbConnection)
90
+ const results = yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).findBy({
91
+ key: (0, typeorm_1.In)(keys),
92
+ })
93
+ const values = keys.map((key) =>
94
+ __awaiter(this, void 0, void 0, function* () {
95
+ var _a
96
+ const result = results.find((result) => result.key === key)
97
+ return (options === null || options === void 0 ? void 0 : options.raw) !== true || !result
98
+ ? result === null || result === void 0
99
+ ? void 0
100
+ : result.data
101
+ : {
102
+ value: (result === null || result === void 0 ? void 0 : result.data)
103
+ ? (_a = yield this.opts.deserialize(result.data)) === null || _a === void 0
104
+ ? void 0
105
+ : _a.value
106
+ : undefined,
107
+ expires: result === null || result === void 0 ? void 0 : result.expires,
108
+ }
109
+ })
110
+ )
111
+ return Promise.all(values)
112
+ })
113
+ }
114
+ set(key, value, ttl) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const connection = yield getConnectedDb(this.dbConnection)
117
+ const entity = new keyValueStoreEntity_1.KeyValueStoreEntity()
118
+ entity.key = key
119
+ entity.data = value
120
+ entity.expires = ttl
121
+ yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).save(entity)
122
+ return { value: value, expires: ttl }
123
+ })
124
+ }
125
+ delete(key) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ if (Array.isArray(key)) {
128
+ return this.deleteMany(key)
129
+ }
130
+ const connection = yield getConnectedDb(this.dbConnection)
131
+ const result = yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).delete({ key })
132
+ return result.affected === 1
133
+ })
134
+ }
135
+ deleteMany(keys) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const connection = yield getConnectedDb(this.dbConnection)
138
+ const results = yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).delete({
139
+ key: (0, typeorm_1.In)(keys),
140
+ })
141
+ return !!results.affected && results.affected >= 1
142
+ })
143
+ }
144
+ clear() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const connection = yield getConnectedDb(this.dbConnection)
147
+ yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).delete({
148
+ key: (0, typeorm_1.Like)(`${this.namespace}:%`),
149
+ })
150
+ })
151
+ }
152
+ has(key) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const connection = yield getConnectedDb(this.dbConnection)
155
+ const result = yield connection.getRepository(keyValueStoreEntity_1.KeyValueStoreEntity).countBy({
156
+ key,
157
+ })
158
+ return result === 1
159
+ })
160
+ }
161
+ disconnect() {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const connection = yield getConnectedDb(this.dbConnection)
164
+ connection.destroy()
165
+ })
166
+ }
167
+ }
168
+ exports.KeyValueTypeORMStoreAdapter = KeyValueTypeORMStoreAdapter
169
+ /**
170
+ * Ensures that the provided DataSource is connected.
171
+ *
172
+ * @param dbConnection - a TypeORM DataSource or a Promise that resolves to a DataSource
173
+ */
174
+ function getConnectedDb(dbConnection) {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ if (dbConnection instanceof Promise) {
177
+ return yield dbConnection
178
+ } else if (!dbConnection.isInitialized) {
179
+ return yield dbConnection.initialize()
180
+ } else {
181
+ return dbConnection
182
+ }
183
+ })
184
+ }
185
+ exports.getConnectedDb = getConnectedDb
186
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+ /**
3
+ * Create the database layout for Veramo 3.0
4
+ *
5
+ * @public
6
+ */
7
+ export declare class CreateKVDatabaseMigration implements MigrationInterface {
8
+ private readonly _tableName
9
+ readonly name: string
10
+ constructor(tableName?: string)
11
+ up(queryRunner: QueryRunner): Promise<void>
12
+ down(queryRunner: QueryRunner): Promise<void>
13
+ }
14
+ //# sourceMappingURL=1.createKVDatabase.d.ts.map