@twin.org/entity-storage-connector-memory 0.0.3-next.2 → 0.0.3-next.21
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/README.md +2 -2
- package/dist/es/memoryEntityStorageConnector.js +207 -15
- package/dist/es/memoryEntityStorageConnector.js.map +1 -1
- package/dist/types/memoryEntityStorageConnector.d.ts +65 -2
- package/docs/changelog.md +370 -41
- package/docs/examples.md +78 -1
- package/docs/reference/classes/MemoryEntityStorageConnector.md +287 -8
- package/docs/reference/interfaces/IMemoryEntityStorageConnectorConstructorOptions.md +3 -3
- package/locales/en.json +13 -1
- package/package.json +6 -5
package/docs/examples.md
CHANGED
|
@@ -1 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage Connector Memory Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to perform fast in-memory storage operations during development and unit testing.
|
|
4
|
+
|
|
5
|
+
## MemoryEntityStorageConnector
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
9
|
+
import {
|
|
10
|
+
ComparisonOperator,
|
|
11
|
+
LogicalOperator,
|
|
12
|
+
SortDirection,
|
|
13
|
+
type EntityCondition
|
|
14
|
+
} from '@twin.org/entity';
|
|
15
|
+
|
|
16
|
+
interface Profile {
|
|
17
|
+
id: string;
|
|
18
|
+
email: string;
|
|
19
|
+
status: 'active' | 'inactive';
|
|
20
|
+
createdAt: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const connector = new MemoryEntityStorageConnector<Profile>({
|
|
24
|
+
entitySchema: 'Profile',
|
|
25
|
+
partitionContextIds: ['tenantId']
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const className = connector.className();
|
|
29
|
+
const schema = connector.getSchema();
|
|
30
|
+
|
|
31
|
+
await connector.set({
|
|
32
|
+
id: 'profile-1',
|
|
33
|
+
email: 'ada@example.com',
|
|
34
|
+
status: 'active',
|
|
35
|
+
createdAt: '2026-03-09T10:30:00.000Z'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const byPrimaryKey = await connector.get('profile-1');
|
|
39
|
+
const bySecondaryIndex = await connector.get('ada@example.com', 'email');
|
|
40
|
+
|
|
41
|
+
const activeCondition: EntityCondition<Profile> = {
|
|
42
|
+
logicalOperator: LogicalOperator.And,
|
|
43
|
+
conditions: [
|
|
44
|
+
{
|
|
45
|
+
property: 'status',
|
|
46
|
+
comparison: ComparisonOperator.Equals,
|
|
47
|
+
value: 'active'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = await connector.query(
|
|
53
|
+
activeCondition,
|
|
54
|
+
[{ property: 'createdAt', sortDirection: SortDirection.Descending }],
|
|
55
|
+
['id', 'email', 'status'],
|
|
56
|
+
undefined,
|
|
57
|
+
25
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
await connector.remove('profile-1');
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
65
|
+
|
|
66
|
+
interface Profile {
|
|
67
|
+
id: string;
|
|
68
|
+
email: string;
|
|
69
|
+
status: 'active' | 'inactive';
|
|
70
|
+
createdAt: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const connector = new MemoryEntityStorageConnector<Profile>({
|
|
74
|
+
entitySchema: 'Profile'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const store = connector.getStore();
|
|
78
|
+
```
|
|
@@ -11,6 +11,7 @@ Class for performing entity storage operations in-memory.
|
|
|
11
11
|
## Implements
|
|
12
12
|
|
|
13
13
|
- `IEntityStorageConnector`\<`T`\>
|
|
14
|
+
- `IEntityStorageMigrationConnector`
|
|
14
15
|
|
|
15
16
|
## Constructors
|
|
16
17
|
|
|
@@ -34,7 +35,7 @@ The options for the connector.
|
|
|
34
35
|
|
|
35
36
|
## Properties
|
|
36
37
|
|
|
37
|
-
### CLASS\_NAME
|
|
38
|
+
### CLASS\_NAME {#class_name}
|
|
38
39
|
|
|
39
40
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
40
41
|
|
|
@@ -42,7 +43,7 @@ Runtime name for the class.
|
|
|
42
43
|
|
|
43
44
|
## Methods
|
|
44
45
|
|
|
45
|
-
### className()
|
|
46
|
+
### className() {#classname}
|
|
46
47
|
|
|
47
48
|
> **className**(): `string`
|
|
48
49
|
|
|
@@ -60,7 +61,25 @@ The class name of the component.
|
|
|
60
61
|
|
|
61
62
|
***
|
|
62
63
|
|
|
63
|
-
###
|
|
64
|
+
### health() {#health}
|
|
65
|
+
|
|
66
|
+
> **health**(): `Promise`\<`IHealth`[]\>
|
|
67
|
+
|
|
68
|
+
Returns the health status of the component.
|
|
69
|
+
|
|
70
|
+
#### Returns
|
|
71
|
+
|
|
72
|
+
`Promise`\<`IHealth`[]\>
|
|
73
|
+
|
|
74
|
+
The health status of the component.
|
|
75
|
+
|
|
76
|
+
#### Implementation of
|
|
77
|
+
|
|
78
|
+
`IEntityStorageConnector.health`
|
|
79
|
+
|
|
80
|
+
***
|
|
81
|
+
|
|
82
|
+
### getSchema() {#getschema}
|
|
64
83
|
|
|
65
84
|
> **getSchema**(): `IEntitySchema`
|
|
66
85
|
|
|
@@ -78,7 +97,7 @@ The schema for the entities.
|
|
|
78
97
|
|
|
79
98
|
***
|
|
80
99
|
|
|
81
|
-
### get()
|
|
100
|
+
### get() {#get}
|
|
82
101
|
|
|
83
102
|
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
|
|
84
103
|
|
|
@@ -116,7 +135,7 @@ The object if it can be found or undefined.
|
|
|
116
135
|
|
|
117
136
|
***
|
|
118
137
|
|
|
119
|
-
### set()
|
|
138
|
+
### set() {#set}
|
|
120
139
|
|
|
121
140
|
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
122
141
|
|
|
@@ -148,7 +167,33 @@ The id of the entity.
|
|
|
148
167
|
|
|
149
168
|
***
|
|
150
169
|
|
|
151
|
-
###
|
|
170
|
+
### setBatch() {#setbatch}
|
|
171
|
+
|
|
172
|
+
> **setBatch**(`entities`): `Promise`\<`void`\>
|
|
173
|
+
|
|
174
|
+
Set multiple entities in a batch.
|
|
175
|
+
|
|
176
|
+
#### Parameters
|
|
177
|
+
|
|
178
|
+
##### entities
|
|
179
|
+
|
|
180
|
+
`T`[]
|
|
181
|
+
|
|
182
|
+
The entities to set.
|
|
183
|
+
|
|
184
|
+
#### Returns
|
|
185
|
+
|
|
186
|
+
`Promise`\<`void`\>
|
|
187
|
+
|
|
188
|
+
Nothing.
|
|
189
|
+
|
|
190
|
+
#### Implementation of
|
|
191
|
+
|
|
192
|
+
`IEntityStorageConnector.setBatch`
|
|
193
|
+
|
|
194
|
+
***
|
|
195
|
+
|
|
196
|
+
### remove() {#remove}
|
|
152
197
|
|
|
153
198
|
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
154
199
|
|
|
@@ -180,7 +225,7 @@ Nothing.
|
|
|
180
225
|
|
|
181
226
|
***
|
|
182
227
|
|
|
183
|
-
### query()
|
|
228
|
+
### query() {#query}
|
|
184
229
|
|
|
185
230
|
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
186
231
|
|
|
@@ -231,7 +276,103 @@ and a cursor which can be used to request more entities.
|
|
|
231
276
|
|
|
232
277
|
***
|
|
233
278
|
|
|
234
|
-
###
|
|
279
|
+
### empty() {#empty}
|
|
280
|
+
|
|
281
|
+
> **empty**(): `Promise`\<`void`\>
|
|
282
|
+
|
|
283
|
+
Remove all entities from the storage.
|
|
284
|
+
|
|
285
|
+
#### Returns
|
|
286
|
+
|
|
287
|
+
`Promise`\<`void`\>
|
|
288
|
+
|
|
289
|
+
Nothing.
|
|
290
|
+
|
|
291
|
+
#### Implementation of
|
|
292
|
+
|
|
293
|
+
`IEntityStorageConnector.empty`
|
|
294
|
+
|
|
295
|
+
***
|
|
296
|
+
|
|
297
|
+
### removeBatch() {#removebatch}
|
|
298
|
+
|
|
299
|
+
> **removeBatch**(`ids`): `Promise`\<`void`\>
|
|
300
|
+
|
|
301
|
+
Remove multiple entities by id.
|
|
302
|
+
|
|
303
|
+
#### Parameters
|
|
304
|
+
|
|
305
|
+
##### ids
|
|
306
|
+
|
|
307
|
+
`string`[]
|
|
308
|
+
|
|
309
|
+
The ids of the entities to remove.
|
|
310
|
+
|
|
311
|
+
#### Returns
|
|
312
|
+
|
|
313
|
+
`Promise`\<`void`\>
|
|
314
|
+
|
|
315
|
+
Nothing.
|
|
316
|
+
|
|
317
|
+
#### Implementation of
|
|
318
|
+
|
|
319
|
+
`IEntityStorageConnector.removeBatch`
|
|
320
|
+
|
|
321
|
+
***
|
|
322
|
+
|
|
323
|
+
### teardown() {#teardown}
|
|
324
|
+
|
|
325
|
+
> **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
326
|
+
|
|
327
|
+
Teardown the storage by clearing the underlying store.
|
|
328
|
+
|
|
329
|
+
#### Parameters
|
|
330
|
+
|
|
331
|
+
##### nodeLoggingComponentType?
|
|
332
|
+
|
|
333
|
+
`string`
|
|
334
|
+
|
|
335
|
+
The node logging component type.
|
|
336
|
+
|
|
337
|
+
#### Returns
|
|
338
|
+
|
|
339
|
+
`Promise`\<`boolean`\>
|
|
340
|
+
|
|
341
|
+
True if the teardown process was successful.
|
|
342
|
+
|
|
343
|
+
#### Implementation of
|
|
344
|
+
|
|
345
|
+
`IEntityStorageConnector.teardown`
|
|
346
|
+
|
|
347
|
+
***
|
|
348
|
+
|
|
349
|
+
### count() {#count}
|
|
350
|
+
|
|
351
|
+
> **count**(`conditions?`): `Promise`\<`number`\>
|
|
352
|
+
|
|
353
|
+
Count all the entities which match the conditions.
|
|
354
|
+
|
|
355
|
+
#### Parameters
|
|
356
|
+
|
|
357
|
+
##### conditions?
|
|
358
|
+
|
|
359
|
+
`EntityCondition`\<`T`\>
|
|
360
|
+
|
|
361
|
+
The optional conditions to match for the entities.
|
|
362
|
+
|
|
363
|
+
#### Returns
|
|
364
|
+
|
|
365
|
+
`Promise`\<`number`\>
|
|
366
|
+
|
|
367
|
+
The total count of entities in the storage.
|
|
368
|
+
|
|
369
|
+
#### Implementation of
|
|
370
|
+
|
|
371
|
+
`IEntityStorageConnector.count`
|
|
372
|
+
|
|
373
|
+
***
|
|
374
|
+
|
|
375
|
+
### getStore() {#getstore}
|
|
235
376
|
|
|
236
377
|
> **getStore**(): `T`[]
|
|
237
378
|
|
|
@@ -242,3 +383,141 @@ Get the memory store.
|
|
|
242
383
|
`T`[]
|
|
243
384
|
|
|
244
385
|
The store.
|
|
386
|
+
|
|
387
|
+
***
|
|
388
|
+
|
|
389
|
+
### getPartitionContextIds() {#getpartitioncontextids}
|
|
390
|
+
|
|
391
|
+
> **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
|
|
392
|
+
|
|
393
|
+
Get a unique list of all the context ids from the storage.
|
|
394
|
+
|
|
395
|
+
#### Returns
|
|
396
|
+
|
|
397
|
+
`Promise`\<`IContextIds`[]\>
|
|
398
|
+
|
|
399
|
+
The list of unique context ids.
|
|
400
|
+
|
|
401
|
+
#### Implementation of
|
|
402
|
+
|
|
403
|
+
`IEntityStorageMigrationConnector.getPartitionContextIds`
|
|
404
|
+
|
|
405
|
+
***
|
|
406
|
+
|
|
407
|
+
### createTargetConnector() {#createtargetconnector}
|
|
408
|
+
|
|
409
|
+
> **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
410
|
+
|
|
411
|
+
Create the target connector for performing the migration it will use a temporary storage location.
|
|
412
|
+
|
|
413
|
+
#### Type Parameters
|
|
414
|
+
|
|
415
|
+
##### U
|
|
416
|
+
|
|
417
|
+
`U`
|
|
418
|
+
|
|
419
|
+
#### Parameters
|
|
420
|
+
|
|
421
|
+
##### newEntitySchema
|
|
422
|
+
|
|
423
|
+
`string`
|
|
424
|
+
|
|
425
|
+
The name of the new entity schema to create the connector for.
|
|
426
|
+
|
|
427
|
+
#### Returns
|
|
428
|
+
|
|
429
|
+
`Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
430
|
+
|
|
431
|
+
Connector for performing the migration.
|
|
432
|
+
|
|
433
|
+
#### Implementation of
|
|
434
|
+
|
|
435
|
+
`IEntityStorageMigrationConnector.createTargetConnector`
|
|
436
|
+
|
|
437
|
+
***
|
|
438
|
+
|
|
439
|
+
### finalizeMigration() {#finalizemigration}
|
|
440
|
+
|
|
441
|
+
> **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
442
|
+
|
|
443
|
+
Finalize the migration by tearing down the old connector and replacing it with the target connector.
|
|
444
|
+
|
|
445
|
+
#### Type Parameters
|
|
446
|
+
|
|
447
|
+
##### U
|
|
448
|
+
|
|
449
|
+
`U`
|
|
450
|
+
|
|
451
|
+
#### Parameters
|
|
452
|
+
|
|
453
|
+
##### targetConnector
|
|
454
|
+
|
|
455
|
+
`IEntityStorageConnector`\<`U`\>
|
|
456
|
+
|
|
457
|
+
The target connector to finalize the migration with.
|
|
458
|
+
|
|
459
|
+
##### options?
|
|
460
|
+
|
|
461
|
+
`IMigrationOptions`\<`T`, `U`\>
|
|
462
|
+
|
|
463
|
+
The options to control how the migration is finalized.
|
|
464
|
+
|
|
465
|
+
##### loggingComponentType?
|
|
466
|
+
|
|
467
|
+
`string`
|
|
468
|
+
|
|
469
|
+
The optional component type to use for logging the migration progress.
|
|
470
|
+
|
|
471
|
+
#### Returns
|
|
472
|
+
|
|
473
|
+
`Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
474
|
+
|
|
475
|
+
A promise that resolves when the migration is finalized.
|
|
476
|
+
|
|
477
|
+
#### Implementation of
|
|
478
|
+
|
|
479
|
+
`IEntityStorageMigrationConnector.finalizeMigration`
|
|
480
|
+
|
|
481
|
+
***
|
|
482
|
+
|
|
483
|
+
### cleanupMigration() {#cleanupmigration}
|
|
484
|
+
|
|
485
|
+
> **cleanupMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
486
|
+
|
|
487
|
+
Cleanup the migration if a migration fails or needs to be aborted.
|
|
488
|
+
|
|
489
|
+
#### Type Parameters
|
|
490
|
+
|
|
491
|
+
##### U
|
|
492
|
+
|
|
493
|
+
`U`
|
|
494
|
+
|
|
495
|
+
#### Parameters
|
|
496
|
+
|
|
497
|
+
##### targetConnector
|
|
498
|
+
|
|
499
|
+
`IEntityStorageConnector`\<`U`\> \| `undefined`
|
|
500
|
+
|
|
501
|
+
The target connector to cleanup the migration with.
|
|
502
|
+
|
|
503
|
+
##### options?
|
|
504
|
+
|
|
505
|
+
`IMigrationOptions`\<`T`, `U`\>
|
|
506
|
+
|
|
507
|
+
The options to control how the migration is cleaned up.
|
|
508
|
+
|
|
509
|
+
##### loggingComponentType?
|
|
510
|
+
|
|
511
|
+
`string`
|
|
512
|
+
|
|
513
|
+
The optional component type to use for logging the migration progress.
|
|
514
|
+
|
|
515
|
+
#### Returns
|
|
516
|
+
|
|
517
|
+
`Promise`\<`void`\>
|
|
518
|
+
|
|
519
|
+
A promise that resolves when the migration is cleaned up.
|
|
520
|
+
|
|
521
|
+
#### Implementation of
|
|
522
|
+
|
|
523
|
+
`IEntityStorageMigrationConnector.cleanupMigration`
|
|
@@ -4,7 +4,7 @@ Options for the Memory Entity Storage Connector constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### entitySchema
|
|
7
|
+
### entitySchema {#entityschema}
|
|
8
8
|
|
|
9
9
|
> **entitySchema**: `string`
|
|
10
10
|
|
|
@@ -12,8 +12,8 @@ The schema for the entity.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### partitionContextIds?
|
|
15
|
+
### partitionContextIds? {#partitioncontextids}
|
|
16
16
|
|
|
17
|
-
> `optional` **partitionContextIds
|
|
17
|
+
> `optional` **partitionContextIds?**: `string`[]
|
|
18
18
|
|
|
19
19
|
The keys to use from the context ids to create partitions.
|
package/locales/en.json
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"info": {
|
|
3
|
+
"memoryEntityStorageConnector": {
|
|
4
|
+
"storeTearingDown": "Tearing down entity storage",
|
|
5
|
+
"storeTornDown": "Entity storage torn down"
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
"health": {
|
|
9
|
+
"memoryEntityStorageConnector": {
|
|
10
|
+
"healthDescription": "Memory entity storage for \"{entityType}\" is always available"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-memory",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.21",
|
|
4
|
+
"description": "In-memory connector for local development, testing and short-lived workloads.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-entity-storage.git",
|
|
8
8
|
"directory": "packages/entity-storage-connector-memory"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"@twin.org/context": "next",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
|
-
"@twin.org/entity-storage-models": "0.0.3-next.
|
|
20
|
+
"@twin.org/entity-storage-models": "0.0.3-next.21",
|
|
21
|
+
"@twin.org/logging-models": "next",
|
|
21
22
|
"@twin.org/nameof": "next"
|
|
22
23
|
},
|
|
23
24
|
"main": "./dist/es/index.js",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"testing"
|
|
56
57
|
],
|
|
57
58
|
"bugs": {
|
|
58
|
-
"url": "git+https://github.com/
|
|
59
|
+
"url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
|
|
59
60
|
},
|
|
60
61
|
"homepage": "https://twindev.org"
|
|
61
62
|
}
|