@twin.org/entity-storage-connector-memory 0.0.3-next.3 → 0.0.3-next.31

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/docs/examples.md CHANGED
@@ -1 +1,78 @@
1
- # @twin.org/entity-storage-connector-memory - Examples
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
+ ```
@@ -1,6 +1,14 @@
1
1
  # Class: MemoryEntityStorageConnector\<T\>
2
2
 
3
- Class for performing entity storage operations in-memory.
3
+ Class for performing entity storage operations in-memory backed by a shared object buffer.
4
+
5
+ All reads and writes are serialised with a per-schema lock so that concurrent async
6
+ access, including across worker threads, never produces torn or lost updates.
7
+
8
+ All connector instances that share the same entity schema name share the same underlying
9
+ buffer, making data written in one instance immediately visible in another, including
10
+ across worker threads when the main thread forwards worker messages to the lock and
11
+ buffer handlers.
4
12
 
5
13
  ## Type Parameters
6
14
 
@@ -11,6 +19,7 @@ Class for performing entity storage operations in-memory.
11
19
  ## Implements
12
20
 
13
21
  - `IEntityStorageConnector`\<`T`\>
22
+ - `IEntityStorageMigrationConnector`\<`T`\>
14
23
 
15
24
  ## Constructors
16
25
 
@@ -34,7 +43,7 @@ The options for the connector.
34
43
 
35
44
  ## Properties
36
45
 
37
- ### CLASS\_NAME
46
+ ### CLASS\_NAME {#class_name}
38
47
 
39
48
  > `readonly` `static` **CLASS\_NAME**: `string`
40
49
 
@@ -42,7 +51,7 @@ Runtime name for the class.
42
51
 
43
52
  ## Methods
44
53
 
45
- ### className()
54
+ ### className() {#classname}
46
55
 
47
56
  > **className**(): `string`
48
57
 
@@ -60,7 +69,25 @@ The class name of the component.
60
69
 
61
70
  ***
62
71
 
63
- ### getSchema()
72
+ ### health() {#health}
73
+
74
+ > **health**(): `Promise`\<`IHealth`[]\>
75
+
76
+ Returns the health status of the component.
77
+
78
+ #### Returns
79
+
80
+ `Promise`\<`IHealth`[]\>
81
+
82
+ The health status of the component.
83
+
84
+ #### Implementation of
85
+
86
+ `IEntityStorageConnector.health`
87
+
88
+ ***
89
+
90
+ ### getSchema() {#getschema}
64
91
 
65
92
  > **getSchema**(): `IEntitySchema`
66
93
 
@@ -78,7 +105,33 @@ The schema for the entities.
78
105
 
79
106
  ***
80
107
 
81
- ### get()
108
+ ### bootstrap() {#bootstrap}
109
+
110
+ > **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
111
+
112
+ Bootstrap the component by creating and initializing any resources it needs.
113
+
114
+ #### Parameters
115
+
116
+ ##### nodeLoggingComponentType?
117
+
118
+ `string`
119
+
120
+ The node logging component type.
121
+
122
+ #### Returns
123
+
124
+ `Promise`\<`boolean`\>
125
+
126
+ True if the bootstrapping process was successful.
127
+
128
+ #### Implementation of
129
+
130
+ `IEntityStorageConnector.bootstrap`
131
+
132
+ ***
133
+
134
+ ### get() {#get}
82
135
 
83
136
  > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
84
137
 
@@ -116,7 +169,7 @@ The object if it can be found or undefined.
116
169
 
117
170
  ***
118
171
 
119
- ### set()
172
+ ### set() {#set}
120
173
 
121
174
  > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
122
175
 
@@ -140,7 +193,7 @@ The optional conditions to match for the entities.
140
193
 
141
194
  `Promise`\<`void`\>
142
195
 
143
- The id of the entity.
196
+ Resolves when the entity has been stored.
144
197
 
145
198
  #### Implementation of
146
199
 
@@ -148,7 +201,33 @@ The id of the entity.
148
201
 
149
202
  ***
150
203
 
151
- ### remove()
204
+ ### setBatch() {#setbatch}
205
+
206
+ > **setBatch**(`entities`): `Promise`\<`void`\>
207
+
208
+ Set multiple entities in a batch.
209
+
210
+ #### Parameters
211
+
212
+ ##### entities
213
+
214
+ `T`[]
215
+
216
+ The entities to set.
217
+
218
+ #### Returns
219
+
220
+ `Promise`\<`void`\>
221
+
222
+ Nothing.
223
+
224
+ #### Implementation of
225
+
226
+ `IEntityStorageConnector.setBatch`
227
+
228
+ ***
229
+
230
+ ### remove() {#remove}
152
231
 
153
232
  > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
154
233
 
@@ -180,7 +259,7 @@ Nothing.
180
259
 
181
260
  ***
182
261
 
183
- ### query()
262
+ ### query() {#query}
184
263
 
185
264
  > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
186
265
 
@@ -231,14 +310,248 @@ and a cursor which can be used to request more entities.
231
310
 
232
311
  ***
233
312
 
234
- ### getStore()
313
+ ### empty() {#empty}
235
314
 
236
- > **getStore**(): `T`[]
315
+ > **empty**(): `Promise`\<`void`\>
237
316
 
238
- Get the memory store.
317
+ Remove all entities from the storage.
239
318
 
240
319
  #### Returns
241
320
 
242
- `T`[]
321
+ `Promise`\<`void`\>
322
+
323
+ Nothing.
324
+
325
+ #### Implementation of
326
+
327
+ `IEntityStorageConnector.empty`
328
+
329
+ ***
330
+
331
+ ### removeBatch() {#removebatch}
332
+
333
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
334
+
335
+ Remove multiple entities by id.
336
+
337
+ #### Parameters
338
+
339
+ ##### ids
340
+
341
+ `string`[]
342
+
343
+ The ids of the entities to remove.
344
+
345
+ #### Returns
346
+
347
+ `Promise`\<`void`\>
348
+
349
+ Nothing.
350
+
351
+ #### Implementation of
352
+
353
+ `IEntityStorageConnector.removeBatch`
354
+
355
+ ***
356
+
357
+ ### teardown() {#teardown}
358
+
359
+ > **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
360
+
361
+ Teardown the storage by clearing the underlying shared buffer for this schema.
362
+
363
+ #### Parameters
364
+
365
+ ##### nodeLoggingComponentType?
366
+
367
+ `string`
368
+
369
+ The node logging component type.
370
+
371
+ #### Returns
372
+
373
+ `Promise`\<`boolean`\>
374
+
375
+ True if the teardown process was successful.
376
+
377
+ #### Implementation of
378
+
379
+ `IEntityStorageConnector.teardown`
380
+
381
+ ***
382
+
383
+ ### count() {#count}
384
+
385
+ > **count**(`conditions?`): `Promise`\<`number`\>
386
+
387
+ Count all the entities which match the conditions.
388
+
389
+ #### Parameters
390
+
391
+ ##### conditions?
392
+
393
+ `EntityCondition`\<`T`\>
394
+
395
+ The optional conditions to match for the entities.
396
+
397
+ #### Returns
398
+
399
+ `Promise`\<`number`\>
400
+
401
+ The total count of entities in the storage.
402
+
403
+ #### Implementation of
404
+
405
+ `IEntityStorageConnector.count`
406
+
407
+ ***
408
+
409
+ ### getStore() {#getstore}
410
+
411
+ > **getStore**(): `Promise`\<`T`[]\>
412
+
413
+ Get all entities in the memory store.
414
+
415
+ #### Returns
416
+
417
+ `Promise`\<`T`[]\>
418
+
419
+ All stored entities with partition keys removed.
420
+
421
+ ***
422
+
423
+ ### getPartitionContextIds() {#getpartitioncontextids}
424
+
425
+ > **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
426
+
427
+ Get a unique list of all the context ids from the storage.
428
+
429
+ #### Returns
430
+
431
+ `Promise`\<`IContextIds`[]\>
432
+
433
+ The list of unique context ids.
434
+
435
+ #### Implementation of
436
+
437
+ `IEntityStorageMigrationConnector.getPartitionContextIds`
438
+
439
+ ***
440
+
441
+ ### createTargetConnector() {#createtargetconnector}
442
+
443
+ > **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
444
+
445
+ Create the target connector for performing the migration it will use a temporary storage location.
446
+
447
+ #### Type Parameters
448
+
449
+ ##### U
450
+
451
+ `U`
452
+
453
+ #### Parameters
454
+
455
+ ##### newEntitySchema
456
+
457
+ `string`
458
+
459
+ The name of the new entity schema to create the connector for.
460
+
461
+ #### Returns
462
+
463
+ `Promise`\<`IEntityStorageConnector`\<`U`\>\>
464
+
465
+ Connector for performing the migration.
466
+
467
+ #### Implementation of
468
+
469
+ `IEntityStorageMigrationConnector.createTargetConnector`
470
+
471
+ ***
472
+
473
+ ### finalizeMigration() {#finalizemigration}
474
+
475
+ > **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
476
+
477
+ Finalize the migration by tearing down the old connector and replacing it with the target connector.
478
+
479
+ #### Type Parameters
480
+
481
+ ##### U
482
+
483
+ `U`
484
+
485
+ #### Parameters
486
+
487
+ ##### targetConnector
488
+
489
+ `IEntityStorageConnector`\<`U`\>
490
+
491
+ The target connector to finalize the migration with.
492
+
493
+ ##### options?
494
+
495
+ `IMigrationOptions`
496
+
497
+ The options to control how the migration is finalized.
498
+
499
+ ##### loggingComponentType?
500
+
501
+ `string`
502
+
503
+ The optional component type to use for logging the migration progress.
504
+
505
+ #### Returns
506
+
507
+ `Promise`\<`IEntityStorageConnector`\<`U`\>\>
508
+
509
+ A promise that resolves when the migration is finalized.
510
+
511
+ #### Implementation of
512
+
513
+ `IEntityStorageMigrationConnector.finalizeMigration`
514
+
515
+ ***
516
+
517
+ ### cleanupMigration() {#cleanupmigration}
518
+
519
+ > **cleanupMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
520
+
521
+ Cleanup the migration if a migration fails or needs to be aborted.
522
+
523
+ #### Type Parameters
524
+
525
+ ##### U
526
+
527
+ `U`
528
+
529
+ #### Parameters
530
+
531
+ ##### targetConnector
532
+
533
+ `IEntityStorageConnector`\<`U`\> \| `undefined`
534
+
535
+ The target connector to cleanup the migration with.
536
+
537
+ ##### options?
538
+
539
+ `IMigrationOptions`
540
+
541
+ The options to control how the migration is cleaned up.
542
+
543
+ ##### loggingComponentType?
544
+
545
+ `string`
546
+
547
+ The optional component type to use for logging the migration progress.
548
+
549
+ #### Returns
550
+
551
+ `Promise`\<`void`\>
552
+
553
+ A promise that resolves when the migration is cleaned up.
554
+
555
+ #### Implementation of
243
556
 
244
- The store.
557
+ `IEntityStorageMigrationConnector.cleanupMigration`
@@ -6,4 +6,5 @@
6
6
 
7
7
  ## Interfaces
8
8
 
9
+ - [IMemoryEntityStorageConnectorConfig](interfaces/IMemoryEntityStorageConnectorConfig.md)
9
10
  - [IMemoryEntityStorageConnectorConstructorOptions](interfaces/IMemoryEntityStorageConnectorConstructorOptions.md)
@@ -0,0 +1,40 @@
1
+ # Interface: IMemoryEntityStorageConnectorConfig
2
+
3
+ Configuration for the Memory Entity Storage Connector.
4
+
5
+ ## Properties
6
+
7
+ ### storageKey {#storagekey}
8
+
9
+ > **storageKey**: `string`
10
+
11
+ Key to use for the shared buffer instead of the entity schema type.
12
+ Use this to give two connectors with the same entitySchema separate storage.
13
+
14
+ ***
15
+
16
+ ### initialCapacityBytes? {#initialcapacitybytes}
17
+
18
+ > `optional` **initialCapacityBytes?**: `number`
19
+
20
+ Initial capacity in bytes for the shared entity buffer.
21
+
22
+ #### Default
23
+
24
+ ```ts
25
+ 16 MiB.
26
+ ```
27
+
28
+ ***
29
+
30
+ ### maxCapacityBytes? {#maxcapacitybytes}
31
+
32
+ > `optional` **maxCapacityBytes?**: `number`
33
+
34
+ Maximum JSON payload size in bytes for the shared entity buffer.
35
+
36
+ #### Default
37
+
38
+ ```ts
39
+ 256 MiB.
40
+ ```
@@ -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,16 @@ The schema for the entity.
12
12
 
13
13
  ***
14
14
 
15
- ### partitionContextIds?
15
+ ### partitionContextIds? {#partitioncontextids}
16
16
 
17
- > `optional` **partitionContextIds**: `string`[]
17
+ > `optional` **partitionContextIds?**: `string`[]
18
18
 
19
19
  The keys to use from the context ids to create partitions.
20
+
21
+ ***
22
+
23
+ ### config {#config}
24
+
25
+ > **config**: [`IMemoryEntityStorageConnectorConfig`](IMemoryEntityStorageConnectorConfig.md)
26
+
27
+ Configuration for storage key and capacity settings.
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.3",
4
- "description": "Entity Storage connector implementation using in-memory storage",
3
+ "version": "0.0.3-next.31",
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/twinfoundation/entity-storage.git",
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.3",
20
+ "@twin.org/entity-storage-models": "0.0.3-next.31",
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/twinfoundation/entity-storage/issues"
59
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
59
60
  },
60
61
  "homepage": "https://twindev.org"
61
62
  }