@sphereon/ssi-sdk.kv-store-temp 0.33.1-next.3 → 0.33.1-next.73
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 +709 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +324 -0
- package/dist/index.d.ts +321 -8
- package/dist/index.js +676 -27
- package/dist/index.js.map +1 -1
- package/package.json +25 -12
- package/src/__tests__/keyv.test.ts +3 -3
- package/src/__tests__/kvstore.test.ts +1 -0
- package/src/store-adapters/typeorm/entities/keyValueStoreEntity.ts +3 -5
- package/src/store-adapters/typeorm/index.ts +1 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/key-value-store.d.ts +0 -27
- package/dist/key-value-store.d.ts.map +0 -1
- package/dist/key-value-store.js +0 -123
- package/dist/key-value-store.js.map +0 -1
- package/dist/key-value-types.d.ts +0 -118
- package/dist/key-value-types.d.ts.map +0 -1
- package/dist/key-value-types.js +0 -3
- package/dist/key-value-types.js.map +0 -1
- package/dist/keyv/keyv-types.d.ts +0 -56
- package/dist/keyv/keyv-types.d.ts.map +0 -1
- package/dist/keyv/keyv-types.js +0 -3
- package/dist/keyv/keyv-types.js.map +0 -1
- package/dist/keyv/keyv.d.ts +0 -48
- package/dist/keyv/keyv.d.ts.map +0 -1
- package/dist/keyv/keyv.js +0 -302
- package/dist/keyv/keyv.js.map +0 -1
- package/dist/store-adapters/index.d.ts +0 -3
- package/dist/store-adapters/index.d.ts.map +0 -1
- package/dist/store-adapters/index.js +0 -19
- package/dist/store-adapters/index.js.map +0 -1
- package/dist/store-adapters/tiered/index.d.ts +0 -29
- package/dist/store-adapters/tiered/index.d.ts.map +0 -1
- package/dist/store-adapters/tiered/index.js +0 -198
- package/dist/store-adapters/tiered/index.js.map +0 -1
- package/dist/store-adapters/tiered/types.d.ts +0 -14
- package/dist/store-adapters/tiered/types.d.ts.map +0 -1
- package/dist/store-adapters/tiered/types.js +0 -3
- package/dist/store-adapters/tiered/types.js.map +0 -1
- package/dist/store-adapters/typeorm/entities/keyValueStoreEntity.d.ts +0 -11
- package/dist/store-adapters/typeorm/entities/keyValueStoreEntity.d.ts.map +0 -1
- package/dist/store-adapters/typeorm/entities/keyValueStoreEntity.js +0 -38
- package/dist/store-adapters/typeorm/entities/keyValueStoreEntity.js.map +0 -1
- package/dist/store-adapters/typeorm/index.d.ts +0 -39
- package/dist/store-adapters/typeorm/index.d.ts.map +0 -1
- package/dist/store-adapters/typeorm/index.js +0 -141
- package/dist/store-adapters/typeorm/index.js.map +0 -1
- package/dist/store-adapters/typeorm/migrations/1.createKVDatabase.d.ts +0 -14
- package/dist/store-adapters/typeorm/migrations/1.createKVDatabase.d.ts.map +0 -1
- package/dist/store-adapters/typeorm/migrations/1.createKVDatabase.js +0 -59
- package/dist/store-adapters/typeorm/migrations/1.createKVDatabase.js.map +0 -1
- package/dist/store-adapters/typeorm/migrations/index.d.ts +0 -10
- package/dist/store-adapters/typeorm/migrations/index.d.ts.map +0 -1
- package/dist/store-adapters/typeorm/migrations/index.js +0 -13
- package/dist/store-adapters/typeorm/migrations/index.js.map +0 -1
- package/dist/store-adapters/typeorm/types.d.ts +0 -22
- package/dist/store-adapters/typeorm/types.d.ts.map +0 -1
- package/dist/store-adapters/typeorm/types.js +0 -3
- package/dist/store-adapters/typeorm/types.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,324 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { OrPromise } from '@veramo/utils';
|
|
3
|
+
import { DataSource, BaseEntity, MigrationInterface, QueryRunner } from 'typeorm';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
6
|
+
* This is how the store will actually store the value.
|
|
7
|
+
* It contains an optional `expires` property, which indicates when the value would expire
|
|
4
8
|
*
|
|
5
|
-
* @
|
|
9
|
+
* @beta
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
interface IValueData<ValueType> {
|
|
12
|
+
value: ValueType | undefined;
|
|
13
|
+
expires: number | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Event listener arguments
|
|
17
|
+
*
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
interface IKeyValueStoreOnArgs {
|
|
21
|
+
eventName: string | symbol;
|
|
22
|
+
listener: (...args: any[]) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for the Key Value store
|
|
26
|
+
*
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
interface IKeyValueStoreOptions<ValueType> {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
/** Namespace for the current instance. */
|
|
32
|
+
namespace?: string | undefined;
|
|
33
|
+
/** A custom serialization function. */
|
|
34
|
+
/** The connection string URI. */
|
|
35
|
+
uri?: string | undefined;
|
|
36
|
+
/** The storage adapter instance to be used by Keyv. or any other implementation */
|
|
37
|
+
store: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>;
|
|
38
|
+
/** Default TTL. Can be overridden by specifying a TTL on `.set()`. */
|
|
39
|
+
ttl?: number | undefined;
|
|
40
|
+
/** Enable compression option **/
|
|
41
|
+
emitErrors?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A store adapter implementation needs to provide namespace support
|
|
45
|
+
*
|
|
46
|
+
* @beta
|
|
47
|
+
*/
|
|
48
|
+
interface IKeyValueStoreAdapter<ValueType> {
|
|
49
|
+
namespace?: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The types that can be stored by a store adapter
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
type ValueStoreType = object | string | number | boolean;
|
|
57
|
+
/**
|
|
58
|
+
* A Key Value store is responsible for managing Values identified by keys.
|
|
59
|
+
*
|
|
60
|
+
* @beta
|
|
61
|
+
*/
|
|
62
|
+
interface IKeyValueStore<ValueType extends ValueStoreType> {
|
|
63
|
+
/**
|
|
64
|
+
* Get a single value by key. Can be undefined as the underlying store typically will not throw an error for a non existing key
|
|
65
|
+
*
|
|
66
|
+
* @param key - Contains the key to search for
|
|
67
|
+
*/
|
|
68
|
+
get(key: string): Promise<ValueType | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* 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
|
|
71
|
+
*
|
|
72
|
+
* @param key - Contains the key to search for
|
|
73
|
+
*/
|
|
74
|
+
getAsValueData(key: string): Promise<IValueData<ValueType>>;
|
|
75
|
+
/**
|
|
76
|
+
* Get multiple values from the store. Will always return an array with values, but the values can be undefined in case the actual store does not contain the value for the respective key
|
|
77
|
+
*
|
|
78
|
+
* @param keys - Contains the keys to search for
|
|
79
|
+
*/
|
|
80
|
+
getMany(keys: string[]): Promise<Array<ValueType | undefined>>;
|
|
81
|
+
/**
|
|
82
|
+
* Get multiple items as Value Data from the store. Will always return an array with Value Data Object, but the value in it can be undefined in case the actual store does not contain the value
|
|
83
|
+
*
|
|
84
|
+
* @param keys - Contains the keys to search for
|
|
85
|
+
*/
|
|
86
|
+
getManyAsValueData(keys: string[]): Promise<Array<IValueData<ValueType>>>;
|
|
87
|
+
/**
|
|
88
|
+
* Store a single value
|
|
89
|
+
*
|
|
90
|
+
* @param key - The key
|
|
91
|
+
* @param value - The value
|
|
92
|
+
* @param ttl - An optional number how long to store the value in milliseconds. If not provided will be stored indefinitely
|
|
93
|
+
*/
|
|
94
|
+
set(key: string, value: ValueType, ttl?: number): Promise<IValueData<ValueType>>;
|
|
95
|
+
/**
|
|
96
|
+
* Delete a value from the store by key
|
|
97
|
+
*
|
|
98
|
+
* @param key - The key to delete the value for
|
|
99
|
+
*/
|
|
100
|
+
delete(key: string): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Delete multiple values by provided keys
|
|
103
|
+
*
|
|
104
|
+
* @param keys - The keys to delete the values for
|
|
105
|
+
*/
|
|
106
|
+
deleteMany(keys: string[]): Promise<boolean[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Clear the whole store (delete all values)
|
|
109
|
+
*/
|
|
110
|
+
clear(): Promise<IKeyValueStore<ValueType>>;
|
|
111
|
+
/**
|
|
112
|
+
* Determine whether the store has the value belonging to the provided key
|
|
113
|
+
*
|
|
114
|
+
* @param key The key to search for
|
|
115
|
+
*/
|
|
116
|
+
has(key: string): Promise<boolean>;
|
|
117
|
+
/**
|
|
118
|
+
* Disconnect the backing store. After this operation the store typically cannot be reused, unless the store object is re-instantiated
|
|
119
|
+
*/
|
|
120
|
+
disconnect(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Agent plugin that implements {@link @sphereon/ssi-sdk.kv-store-temp#IKeyValueStore} interface
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
declare class KeyValueStore<ValueType extends ValueStoreType> implements IKeyValueStore<ValueType> {
|
|
128
|
+
/**
|
|
129
|
+
* The main keyv typescript port which delegates to the storage adapters and takes care of some common functionality
|
|
130
|
+
*
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
private readonly keyv;
|
|
134
|
+
constructor(options: IKeyValueStoreOptions<ValueType>);
|
|
135
|
+
get(key: string): Promise<ValueType | undefined>;
|
|
136
|
+
getAsValueData(key: string): Promise<IValueData<ValueType>>;
|
|
137
|
+
getMany(keys: string[]): Promise<Array<ValueType | undefined>>;
|
|
138
|
+
getManyAsValueData(keys: string[]): Promise<Array<IValueData<ValueType>>>;
|
|
139
|
+
set(key: string, value: ValueType, ttl?: number): Promise<IValueData<ValueType>>;
|
|
140
|
+
has(key: string): Promise<boolean>;
|
|
141
|
+
delete(key: string): Promise<boolean>;
|
|
142
|
+
deleteMany(keys: string[]): Promise<boolean[]>;
|
|
143
|
+
clear(): Promise<IKeyValueStore<ValueType>>;
|
|
144
|
+
disconnect(): Promise<void>;
|
|
145
|
+
kvStoreOn(args: IKeyValueStoreOnArgs): Promise<IKeyValueStore<ValueType>>;
|
|
146
|
+
private toDeserializedValueData;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type Options<ValueType> = {
|
|
150
|
+
local: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>;
|
|
151
|
+
remote: IKeyValueStoreAdapter<ValueType> | Map<string, ValueType>;
|
|
152
|
+
localOnly?: boolean;
|
|
153
|
+
iterationLimit?: number | string;
|
|
154
|
+
};
|
|
155
|
+
type Options_$1 = {
|
|
156
|
+
validator: (value: any, key: string) => boolean;
|
|
157
|
+
dialect: string;
|
|
158
|
+
iterationLimit?: number | string;
|
|
159
|
+
localOnly?: boolean;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Please be aware these types are compatible with the keyv package, to ensure we can use its store-adapters for free.
|
|
164
|
+
*
|
|
165
|
+
* Be very careful when extending/changing!. Normally you will want to create an adapter or decorator for your additional behaviour or requirements
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
interface KeyvOptions<Value> {
|
|
169
|
+
[key: string]: any;
|
|
170
|
+
/** Namespace for the current instance. */
|
|
171
|
+
namespace?: string | undefined;
|
|
172
|
+
/** A custom serialization function. */
|
|
173
|
+
serialize?: (data: KeyvDeserializedData<Value>) => OrPromise<string | undefined>;
|
|
174
|
+
/** A custom deserialization function. */
|
|
175
|
+
deserialize?: (data: any) => OrPromise<KeyvDeserializedData<Value> | undefined>;
|
|
176
|
+
/** The connection string URI. */
|
|
177
|
+
uri?: string | undefined;
|
|
178
|
+
/** The storage adapter instance to be used by Keyv. */
|
|
179
|
+
store?: KeyvStore<Value | undefined> | undefined;
|
|
180
|
+
/** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
|
|
181
|
+
ttl?: number | undefined;
|
|
182
|
+
/** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
|
|
183
|
+
adapter?: 'redis' | 'mongodb' | 'mongo' | 'sqlite' | 'postgresql' | 'postgres' | 'mysql' | object | string | undefined;
|
|
184
|
+
/** Enable compression option **/
|
|
185
|
+
compression?: KeyvCompressionAdapter | undefined;
|
|
186
|
+
emitErrors?: boolean;
|
|
187
|
+
}
|
|
188
|
+
interface KeyvCompressionAdapter {
|
|
189
|
+
compress(value: any, options?: any): OrPromise<any>;
|
|
190
|
+
decompress(value: any, options?: any): OrPromise<any>;
|
|
191
|
+
serialize(value: any): OrPromise<string>;
|
|
192
|
+
deserialize(value: any): OrPromise<any>;
|
|
193
|
+
}
|
|
194
|
+
interface KeyvDeserializedData<Value> {
|
|
195
|
+
value: Value;
|
|
196
|
+
expires: number | undefined;
|
|
197
|
+
}
|
|
198
|
+
type KeyvStoredData<Value> = KeyvDeserializedData<Value> | string | Value | undefined;
|
|
199
|
+
interface KeyvStore<Value> {
|
|
200
|
+
namespace?: string | undefined;
|
|
201
|
+
opts: KeyvOptions<Value>;
|
|
202
|
+
on?(eventName: string | symbol, listener: (...args: any[]) => void): void;
|
|
203
|
+
get(key: string | string[], options?: {
|
|
204
|
+
raw?: boolean;
|
|
205
|
+
}): OrPromise<KeyvStoredData<Value> | Array<KeyvStoredData<Value>>>;
|
|
206
|
+
getMany?(keys: string[], options?: {
|
|
207
|
+
raw?: boolean;
|
|
208
|
+
}): OrPromise<Array<KeyvStoredData<Value>>> | undefined;
|
|
209
|
+
iterator?(namespace?: string | undefined): AsyncGenerator<any, void, any>;
|
|
210
|
+
set(key: string, value: Value, ttl?: number): any;
|
|
211
|
+
delete(key: string | string[]): OrPromise<boolean>;
|
|
212
|
+
deleteMany?(keys: string[]): OrPromise<boolean>;
|
|
213
|
+
clear(): OrPromise<void>;
|
|
214
|
+
has?(key: string): OrPromise<boolean>;
|
|
215
|
+
disconnect?(): void;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Tiered keyv store adapter, combining 2 adapters/stores into one
|
|
220
|
+
* @alpha
|
|
221
|
+
*/
|
|
222
|
+
declare class KeyValueTieredStoreAdapter<Value> extends EventEmitter implements KeyvStore<Value>, IKeyValueStoreAdapter<Value> {
|
|
223
|
+
opts: Options_$1;
|
|
224
|
+
remote: KeyvStore<Value>;
|
|
225
|
+
local: KeyvStore<Value>;
|
|
226
|
+
iterationLimit?: string | number;
|
|
227
|
+
namespace?: string | undefined;
|
|
228
|
+
constructor({ remote, local, ...options }: Options<Value>);
|
|
229
|
+
get(key: string | string[], options?: {
|
|
230
|
+
raw?: boolean;
|
|
231
|
+
}): Promise<KeyvStoredData<Value> | Array<KeyvStoredData<Value>>>;
|
|
232
|
+
getMany(keys: string[], options?: {
|
|
233
|
+
raw?: boolean;
|
|
234
|
+
}): Promise<Array<KeyvStoredData<Value>>>;
|
|
235
|
+
set(key: string, value: any, ttl?: number): Promise<any[]>;
|
|
236
|
+
clear(): Promise<undefined>;
|
|
237
|
+
delete(key: string): Promise<boolean>;
|
|
238
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
239
|
+
has(key: string): Promise<boolean>;
|
|
240
|
+
iterator(namespace?: string): AsyncGenerator<any, void, any>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
type KeyValueTypeORMOptions = {
|
|
247
|
+
dbConnection: OrPromise<DataSource>;
|
|
248
|
+
namespace?: string;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Internal options for the TypeORM adapter
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
type Options_<Value> = {
|
|
255
|
+
validator: (value: any, key: string) => boolean;
|
|
256
|
+
dialect: string;
|
|
257
|
+
serialize: (data: KeyvDeserializedData<Value>) => OrPromise<string | undefined>;
|
|
258
|
+
/** A custom deserialization function. */
|
|
259
|
+
deserialize: (data: any) => OrPromise<KeyvDeserializedData<Value> | undefined>;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
*
|
|
264
|
+
* @beta This API may change without a BREAKING CHANGE notice.
|
|
265
|
+
*/
|
|
266
|
+
declare class KeyValueStoreEntity extends BaseEntity {
|
|
267
|
+
key: string;
|
|
268
|
+
data: string;
|
|
269
|
+
expires?: number;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Create the database layout for Veramo 3.0
|
|
274
|
+
*
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
declare class CreateKVDatabaseMigration implements MigrationInterface {
|
|
278
|
+
private readonly _tableName;
|
|
279
|
+
readonly name: string;
|
|
280
|
+
constructor(tableName?: string);
|
|
281
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
282
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The migrations array that SHOULD be used when initializing a TypeORM database connection.
|
|
287
|
+
*
|
|
288
|
+
* These ensure the correct creation of tables and the proper migrations of data when tables change between versions.
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
declare const kvStoreMigrations: (typeof CreateKVDatabaseMigration)[];
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* TypeORM based key value store adapter
|
|
296
|
+
* @beta
|
|
297
|
+
*/
|
|
298
|
+
declare class KeyValueTypeORMStoreAdapter extends EventEmitter implements KeyvStore<string>, IKeyValueStoreAdapter<string> {
|
|
299
|
+
private readonly dbConnection;
|
|
300
|
+
readonly namespace: string;
|
|
301
|
+
opts: Options_<string>;
|
|
302
|
+
constructor(options: KeyValueTypeORMOptions);
|
|
303
|
+
get(key: string | string[], options?: {
|
|
304
|
+
raw?: boolean;
|
|
305
|
+
}): Promise<KeyvStoredData<string> | Array<KeyvStoredData<string>>>;
|
|
306
|
+
getMany(keys: string[], options?: {
|
|
307
|
+
raw?: boolean;
|
|
308
|
+
}): Promise<Array<KeyvStoredData<string>>>;
|
|
309
|
+
set(key: string, value: string, ttl?: number): Promise<KeyvStoredData<string>>;
|
|
310
|
+
delete(key: string | string[]): Promise<boolean>;
|
|
311
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
312
|
+
clear(): Promise<void>;
|
|
313
|
+
has(key: string): Promise<boolean>;
|
|
314
|
+
disconnect(): Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Ensures that the provided DataSource is connected.
|
|
318
|
+
*
|
|
319
|
+
* @param dbConnection - a TypeORM DataSource or a Promise that resolves to a DataSource
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
declare function _getConnectedDb(dbConnection: OrPromise<DataSource>): Promise<DataSource>;
|
|
323
|
+
|
|
324
|
+
export { type IKeyValueStore, type IKeyValueStoreAdapter, type IKeyValueStoreOnArgs, type IKeyValueStoreOptions, type IValueData, KeyValueStore, KeyValueStoreEntity, KeyValueTieredStoreAdapter, KeyValueTypeORMStoreAdapter, type ValueStoreType, _getConnectedDb, kvStoreMigrations };
|