@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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019 Consensys AG
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,132 @@
1
+ # Veramo Key Value store
2
+
3
+ A simple typed Key Value store with out of the box support for in memory/maps, sqlite and typeorm implementations for
4
+ usage in browser, NodeJS and React-Native.
5
+ It includes a tiered local/remote implementation that support all environments.
6
+
7
+ # Usage in your application or module
8
+
9
+ ## setup
10
+
11
+ Veramo provides 3 store adapters out of the box. The first is an in memory Map based store, the second is a TypeORM
12
+ based store, meaning we support multiple databases. Lastly there is a tiered store, which allows you to use a local and
13
+ remote store together.
14
+
15
+ You should also be able to use store adapters from the [keyv](https://github.com/jaredwray/keyv) project. Be aware that
16
+ Veramo uses an internal fork of that project, as we have several constraints not present in the upstream project. As a
17
+ result the adapters are not guaranteed to work in your environment.
18
+ See [Keyv project relationship](#keyv-project-relationship) for more information.
19
+
20
+ ### Map based in memory store
21
+
22
+ This is the simplest implementation where a Map is being used to store the Keys and Values
23
+
24
+ ```typescript
25
+ import { IKeyValueStore, IKeyValueStoreOptions, KeyValueStore } from '@veramo/key-value-store'
26
+
27
+ const options: IKeyValueStoreOptions<MyValueType> = {
28
+ namespace: 'example',
29
+ store: new Map<string, MyValueType>(),
30
+ }
31
+ const kvStore: IKeyValueStore<MyValueType> = new KeyValueStore({ options })
32
+ ```
33
+
34
+ ### TypeORM store
35
+
36
+ This implementation uses TypeORM using a simple entity to store the namespace prefixed key, an expiration value and the
37
+ value itself. It supports multiple database backends.
38
+
39
+ ```typescript
40
+ import { IKeyValueStore, IKeyValueStoreOptions, KeyValueStore, KeyValueStoreEntity, KeyValueTypeORMStoreAdapter } from '@veramo/key-value-store'
41
+ import { DataSource } from 'typeorm'
42
+
43
+ const dbConnection: DataSource = await new DataSource({
44
+ type: 'sqlite',
45
+ database: ':memory:',
46
+ logging: 'all',
47
+ migrationsRun: true,
48
+ synchronize: false,
49
+ entities: [KeyValueStoreEntity],
50
+ }).initialize()
51
+
52
+ const options: IKeyValueStoreOptions<MyValueType> = {
53
+ namespace: 'example',
54
+ store: new KeyValueTypeORMStoreAdapter({ dbConnection }),
55
+ }
56
+ const kvStore: IKeyValueStore<MyValueType> = new KeyValueStore({ options })
57
+ ```
58
+
59
+ ### Tiered store
60
+
61
+ The tiered store expects a local store and a remote store. Obviously it makes most sense to have a memory based local
62
+ store and potentially more expensive/slower remote store
63
+
64
+ ```typescript
65
+ import {
66
+ kvStoreMigrations,
67
+ IKeyValueStore,
68
+ IKeyValueStoreOptions,
69
+ KeyValueStore,
70
+ KeyValueStoreEntity,
71
+ KeyValueTieredStoreAdapter,
72
+ KeyValueTypeORMStoreAdapter,
73
+ } from '@veramo/key-value-store'
74
+ import { DataSource } from 'typeorm'
75
+
76
+ dbConnection = await new DataSource({
77
+ type: 'sqlite',
78
+ database: ':memory:',
79
+ logging: 'all',
80
+ migrationsRun: true,
81
+ synchronize: false,
82
+ migrations: [...kvStoreMigrations],
83
+ entities: [KeyValueStoreEntity],
84
+ }).initialize()
85
+
86
+ const local: Map<string, MyValueType> = new Map()
87
+ const remote = new KeyValueTypeORMStoreAdapter({ dbConnection })
88
+
89
+ const options: IKeyValueStoreOptions<MyValueType> = {
90
+ namespace: 'example',
91
+ store: new KeyValueTieredStoreAdapter({ local, remote }),
92
+ }
93
+ const kvStore: IKeyValueStore<MyValueType> = new KeyValueStore<MyValueType>({ options })
94
+ ```
95
+
96
+ ## Usage
97
+
98
+ After you have setup the Key Value Store as described above in your agent, it will be available in your agent.
99
+
100
+ ```typescript
101
+ kvStore.set('hello', { example: world }) // Stores the value object by key untill deleted
102
+ kvStore.set('expiring', { example: 'expiration' }, 1000) // Stores the value object by key for 1 second
103
+ const value = await kvStore.get('hello') // { example: world }
104
+ const values = await kvStore.getMany(['hello', 'expiring']) // [{ example: world }, {example: expiring}]
105
+
106
+ if (await kvStore.has('hello')) {
107
+ await kvStore.delete('hello') // return a boolean for success. You can also call it on non existing keys, which will return false
108
+ }
109
+
110
+ await kvStore.clear() // Removes all keys/values from the store
111
+ kvStore.disconnect() // disconnects the store from it backing adapter. You cannot reuse the store afterwards unlesss you initialize a new store.
112
+ ```
113
+
114
+ # Keyv project relationship
115
+
116
+ Please note that a large portion of the Veramo Key Value Store code is a port of
117
+ the [keyv](https://github.com/jaredwray/keyv) project, adding support for Typescript and ESM, so it can be used Veramo
118
+
119
+ The ported code should support the storage plugins available for the keyv project, although testing has been limited
120
+ Veramo itself has a requirement to support NodeJS, Browser and React-Native environments. The port and the store
121
+ adapters included in Veramo run in these environments.
122
+ Please be aware that these requirements probably aren't true for any keyv storage plugins.
123
+
124
+ One of the big changes compared to the upstream project is that this port does not have dynamic loading of adapters
125
+ based on URIs. We believe that any Veramo Key Value store should use explicit defined adapters.
126
+
127
+ The keyv port is part of the Veramo Key Value Store module code itself, as we do not want to make an official maintained port at this point.
128
+
129
+ Veramo exposes its own API/interfaces for the Key Value store, meaning we could also support any other implementation in
130
+ the future
131
+
132
+ We welcome any new storage modules
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Provides a {@link @veramo/kv-store#KeyValueStore} for the
3
+ * {@link @veramo/core#Agent} plugin that implements {@link @veramo/kv-store#IKeyValueStore} interface
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ export { KeyValueStore } from './key-value-store'
8
+ export * from './store-adapters/tiered/index'
9
+ export * from './store-adapters/typeorm/index'
10
+ export * from './key-value-types'
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,45 @@
1
+ 'use strict'
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k
7
+ var desc = Object.getOwnPropertyDescriptor(m, k)
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k]
13
+ },
14
+ }
15
+ }
16
+ Object.defineProperty(o, k2, desc)
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k
20
+ o[k2] = m[k]
21
+ })
22
+ var __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
26
+ }
27
+ Object.defineProperty(exports, '__esModule', { value: true })
28
+ exports.KeyValueStore = void 0
29
+ /**
30
+ * Provides a {@link @veramo/kv-store#KeyValueStore} for the
31
+ * {@link @veramo/core#Agent} plugin that implements {@link @veramo/kv-store#IKeyValueStore} interface
32
+ *
33
+ * @packageDocumentation
34
+ */
35
+ var key_value_store_1 = require('./key-value-store')
36
+ Object.defineProperty(exports, 'KeyValueStore', {
37
+ enumerable: true,
38
+ get: function () {
39
+ return key_value_store_1.KeyValueStore
40
+ },
41
+ })
42
+ __exportStar(require('./store-adapters/tiered/index'), exports)
43
+ __exportStar(require('./store-adapters/typeorm/index'), exports)
44
+ __exportStar(require('./key-value-types'), exports)
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,27 @@
1
+ import { IKeyValueStore, IKeyValueStoreOnArgs, IKeyValueStoreOptions, IValueData } from './key-value-types'
2
+ /**
3
+ * Agent plugin that implements {@link @veramo/kv-store#IKeyValueStore} interface
4
+ * @public
5
+ */
6
+ export declare class KeyValueStore<ValueType> implements IKeyValueStore<ValueType> {
7
+ /**
8
+ * The main keyv typescript port which delegates to the storage adapters and takes care of some common functionality
9
+ *
10
+ * @private
11
+ */
12
+ private readonly keyv
13
+ constructor(options: IKeyValueStoreOptions<ValueType>)
14
+ get(key: string): Promise<ValueType | undefined>
15
+ getAsValueData(key: string): Promise<IValueData<ValueType>>
16
+ getMany(keys: string[]): Promise<Array<ValueType | undefined>>
17
+ getManyAsValueData(keys: string[]): Promise<Array<IValueData<ValueType>>>
18
+ set(key: string, value: ValueType, ttl?: number): Promise<IValueData<ValueType>>
19
+ has(key: string): Promise<boolean>
20
+ delete(key: string): Promise<boolean>
21
+ deleteMany(keys: string[]): Promise<boolean[]>
22
+ clear(): Promise<IKeyValueStore<ValueType>>
23
+ disconnect(): Promise<void>
24
+ kvStoreOn(args: IKeyValueStoreOnArgs): Promise<IKeyValueStore<ValueType>>
25
+ private toDeserializedValueData
26
+ }
27
+ //# sourceMappingURL=key-value-store.d.ts.map
@@ -0,0 +1,143 @@
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
+ Object.defineProperty(exports, '__esModule', { value: true })
34
+ exports.KeyValueStore = void 0
35
+ const keyv_1 = require('./keyv/keyv')
36
+ /**
37
+ * Agent plugin that implements {@link @veramo/kv-store#IKeyValueStore} interface
38
+ * @public
39
+ */
40
+ class KeyValueStore {
41
+ constructor(options) {
42
+ this.keyv = new keyv_1.Keyv(options.uri, options)
43
+ }
44
+ get(key) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const result = yield this.keyv.get(key, { raw: false })
47
+ if (result === null || result === undefined) {
48
+ return undefined
49
+ }
50
+ return result
51
+ })
52
+ }
53
+ getAsValueData(key) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const result = yield this.keyv.get(key, { raw: true })
56
+ if (result === null || result === undefined) {
57
+ // We always return a ValueData object for this method
58
+ return { value: undefined, expires: undefined }
59
+ }
60
+ return this.toDeserializedValueData(result)
61
+ })
62
+ }
63
+ getMany(keys) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (!keys || keys.length === 0) {
66
+ return []
67
+ }
68
+ let result = yield this.keyv.getMany(keys, { raw: false })
69
+ // Making sure we return the same array length as the amount of key(s) passed in
70
+ if (result === null || result === undefined || result.length === 0) {
71
+ result = new Array()
72
+ keys.forEach(() => result.push(undefined))
73
+ }
74
+ return result.map((v) => (!!v ? v : undefined))
75
+ })
76
+ }
77
+ getManyAsValueData(keys) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ if (!keys || keys.length === 0) {
80
+ return []
81
+ }
82
+ let result = yield this.keyv.getMany(keys, { raw: true })
83
+ // Making sure we return the same array length as the amount of key(s) passed in
84
+ if (result === null || result === undefined || result.length === 0) {
85
+ result = new Array()
86
+ keys.forEach(() => result.push({ value: undefined, expires: undefined }))
87
+ }
88
+ return result.map((v) => (!!v ? this.toDeserializedValueData(v) : { value: undefined, expires: undefined }))
89
+ })
90
+ }
91
+ set(key, value, ttl) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ return this.keyv.set(key, value, ttl).then(() => this.getAsValueData(key))
94
+ })
95
+ }
96
+ has(key) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ return this.keyv.has(key)
99
+ })
100
+ }
101
+ delete(key) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ return this.keyv.delete(key)
104
+ })
105
+ }
106
+ deleteMany(keys) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return Promise.all(keys.map((key) => this.keyv.delete(key)))
109
+ })
110
+ }
111
+ clear() {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ return this.keyv.clear().then(() => this)
114
+ })
115
+ }
116
+ disconnect() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ return this.keyv.disconnect()
119
+ })
120
+ }
121
+ // Public so parties using the kv store directly can add listeners if they want
122
+ kvStoreOn(args) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ this.keyv.on(args.eventName, args.listener)
125
+ return this
126
+ })
127
+ }
128
+ toDeserializedValueData(result) {
129
+ if (result === null || result === undefined) {
130
+ throw Error(`Result cannot be undefined or null at this this point`)
131
+ } else if (typeof result !== 'object') {
132
+ return { value: result, expires: undefined }
133
+ } else if (!('value' in result)) {
134
+ return { value: result, expires: undefined }
135
+ }
136
+ if (!('expires' in result)) {
137
+ result.expires = undefined
138
+ }
139
+ return result
140
+ }
141
+ }
142
+ exports.KeyValueStore = KeyValueStore
143
+ //# sourceMappingURL=key-value-store.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * This is how the store will actually store the value.
3
+ * It contains an optional `expires` property, which indicates when the value would expire
4
+ */
5
+ export interface IValueData<ValueType> {
6
+ value: ValueType | undefined
7
+ expires: number | undefined
8
+ }
9
+ export interface IKeyValueStoreOnArgs {
10
+ eventName: string | symbol
11
+ listener: (...args: any[]) => void
12
+ }
13
+ export interface IKeyValueStoreOptions<ValueType> {
14
+ [key: string]: any
15
+ /** Namespace for the current instance. */
16
+ namespace?: string | undefined
17
+ /** A custom serialization function. */
18
+ /** The connection string URI. */
19
+ uri?: string | undefined
20
+ /** The storage adapter instance to be used by Keyv. or any other implementation */
21
+ store: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>
22
+ /** Default TTL. Can be overridden by specifying a TTL on `.set()`. */
23
+ ttl?: number | undefined
24
+ /** Enable compression option **/
25
+ emitErrors?: boolean
26
+ }
27
+ export interface IKeyValueStoreAdapter<ValueType> {
28
+ namespace?: string | undefined
29
+ }
30
+ export interface IKeyValueStore<ValueType> {
31
+ /**
32
+ * Get a single value by key. Can be undefined as the underlying store typically will not throw an error for a non existing key
33
+ *
34
+ * @param key Contains the key to search for
35
+ */
36
+ get(key: string): Promise<ValueType | undefined>
37
+ /**
38
+ * Get a single item as Value Data from the store. Will always return a Value Data Object, but the value in it can be undefined in case the actual store does not contain the value
39
+ * @param key Contains the key to search for
40
+ */
41
+ getAsValueData(key: string): Promise<IValueData<ValueType>>
42
+ getMany(keys: string[]): Promise<Array<ValueType | undefined>>
43
+ getManyAsValueData(keys: string[]): Promise<Array<IValueData<ValueType>>>
44
+ set(key: string, value: ValueType, ttl?: number): Promise<IValueData<ValueType>>
45
+ delete(key: string): Promise<boolean>
46
+ deleteMany(keys: string[]): Promise<boolean[]>
47
+ clear(): Promise<IKeyValueStore<ValueType>>
48
+ has(key: string): Promise<boolean>
49
+ disconnect(): Promise<void>
50
+ }
51
+ //# sourceMappingURL=key-value-types.d.ts.map
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ //# sourceMappingURL=key-value-types.js.map
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Please be aware these types are compatible with the keyv package, to ensure we can use its store-adapters for free.
3
+ *
4
+ * Be very careful when extending/changing!. Normally you will want to create an adapter or decorator for your additional behaviour or requirements
5
+ */
6
+ import { OrPromise } from '@veramo/utils'
7
+ export interface KeyvOptions<Value> {
8
+ [key: string]: any
9
+ /** Namespace for the current instance. */
10
+ namespace?: string | undefined
11
+ /** A custom serialization function. */
12
+ serialize?: (data: KeyvDeserializedData<Value>) => OrPromise<string | undefined>
13
+ /** A custom deserialization function. */
14
+ deserialize?: (data: any) => OrPromise<KeyvDeserializedData<Value> | undefined>
15
+ /** The connection string URI. */
16
+ uri?: string | undefined
17
+ /** The storage adapter instance to be used by Keyv. */
18
+ store?: KeyvStore<Value | undefined> | undefined
19
+ /** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
20
+ ttl?: number | undefined
21
+ /** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
22
+ adapter?: 'redis' | 'mongodb' | 'mongo' | 'sqlite' | 'postgresql' | 'postgres' | 'mysql' | object | string | undefined
23
+ /** Enable compression option **/
24
+ compression?: KeyvCompressionAdapter | undefined
25
+ emitErrors?: boolean
26
+ }
27
+ export interface KeyvCompressionAdapter {
28
+ compress(value: any, options?: any): OrPromise<any>
29
+ decompress(value: any, options?: any): OrPromise<any>
30
+ serialize(value: any): OrPromise<string>
31
+ deserialize(value: any): OrPromise<any>
32
+ }
33
+ export interface KeyvDeserializedData<Value> {
34
+ value: Value
35
+ expires: number | undefined
36
+ }
37
+ export type KeyvStoredData<Value> = KeyvDeserializedData<Value> | string | Value | undefined
38
+ export interface KeyvStore<Value> {
39
+ namespace?: string | undefined
40
+ opts: KeyvOptions<Value>
41
+ on?(eventName: string | symbol, listener: (...args: any[]) => void): void
42
+ get(
43
+ key: string | string[],
44
+ options?: {
45
+ raw?: boolean
46
+ }
47
+ ): OrPromise<KeyvStoredData<Value> | Array<KeyvStoredData<Value>>>
48
+ getMany?(
49
+ keys: string[],
50
+ options?: {
51
+ raw?: boolean
52
+ }
53
+ ): OrPromise<Array<KeyvStoredData<Value>>> | undefined
54
+ iterator?(namespace?: string | undefined): AsyncGenerator<any, void, any>
55
+ set(key: string, value: Value, ttl?: number): any
56
+ delete(key: string | string[]): OrPromise<boolean>
57
+ deleteMany?(keys: string[]): OrPromise<boolean>
58
+ clear(): OrPromise<void>
59
+ has?(key: string): OrPromise<boolean>
60
+ disconnect?(): void
61
+ }
62
+ //# sourceMappingURL=keyv-types.d.ts.map