@twin.org/entity-storage-connector-file 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/fileEntityStorageConnector.js +316 -14
- package/dist/es/fileEntityStorageConnector.js.map +1 -1
- package/dist/es/models/IFileEntityStorageConnectorConfig.js.map +1 -1
- package/dist/types/fileEntityStorageConnector.d.ts +64 -1
- package/dist/types/models/IFileEntityStorageConnectorConfig.d.ts +10 -0
- package/docs/changelog.md +416 -43
- package/docs/examples.md +69 -1
- package/docs/reference/classes/FileEntityStorageConnector.md +270 -8
- package/docs/reference/interfaces/IFileEntityStorageConnectorConfig.md +19 -1
- package/docs/reference/interfaces/IFileEntityStorageConnectorConstructorOptions.md +4 -4
- package/locales/en.json +15 -2
- package/package.json +5 -5
package/docs/examples.md
CHANGED
|
@@ -1 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage Connector File Examples
|
|
2
|
+
|
|
3
|
+
Use this page to see local-file storage workflows for bootstrapping, entity lifecycle operations, and filtered querying.
|
|
4
|
+
|
|
5
|
+
## FileEntityStorageConnector
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
FileEntityStorageConnector,
|
|
10
|
+
type IFileEntityStorageConnectorConstructorOptions
|
|
11
|
+
} from '@twin.org/entity-storage-connector-file';
|
|
12
|
+
import {
|
|
13
|
+
ComparisonOperator,
|
|
14
|
+
LogicalOperator,
|
|
15
|
+
SortDirection,
|
|
16
|
+
type EntityCondition
|
|
17
|
+
} from '@twin.org/entity';
|
|
18
|
+
|
|
19
|
+
interface Profile {
|
|
20
|
+
id: string;
|
|
21
|
+
email: string;
|
|
22
|
+
status: 'active' | 'inactive';
|
|
23
|
+
createdAt: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const options: IFileEntityStorageConnectorConstructorOptions = {
|
|
27
|
+
entitySchema: 'Profile',
|
|
28
|
+
config: {
|
|
29
|
+
directory: './data/profiles'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const connector = new FileEntityStorageConnector<Profile>(options);
|
|
34
|
+
await connector.bootstrap();
|
|
35
|
+
|
|
36
|
+
const className = connector.className();
|
|
37
|
+
const schema = connector.getSchema();
|
|
38
|
+
|
|
39
|
+
await connector.set({
|
|
40
|
+
id: 'profile-1',
|
|
41
|
+
email: 'ada@example.com',
|
|
42
|
+
status: 'active',
|
|
43
|
+
createdAt: '2026-03-09T10:30:00.000Z'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const byPrimaryKey = await connector.get('profile-1');
|
|
47
|
+
const bySecondaryIndex = await connector.get('ada@example.com', 'email');
|
|
48
|
+
|
|
49
|
+
const activeCondition: EntityCondition<Profile> = {
|
|
50
|
+
logicalOperator: LogicalOperator.And,
|
|
51
|
+
conditions: [
|
|
52
|
+
{
|
|
53
|
+
property: 'status',
|
|
54
|
+
comparison: ComparisonOperator.Equals,
|
|
55
|
+
value: 'active'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const result = await connector.query(
|
|
61
|
+
activeCondition,
|
|
62
|
+
[{ property: 'createdAt', sortDirection: SortDirection.Descending }],
|
|
63
|
+
['id', 'email', 'status'],
|
|
64
|
+
undefined,
|
|
65
|
+
25
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
await connector.remove('profile-1');
|
|
69
|
+
```
|
|
@@ -34,7 +34,7 @@ The options for the connector.
|
|
|
34
34
|
|
|
35
35
|
## Properties
|
|
36
36
|
|
|
37
|
-
### CLASS\_NAME
|
|
37
|
+
### CLASS\_NAME {#class_name}
|
|
38
38
|
|
|
39
39
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ Runtime name for the class.
|
|
|
42
42
|
|
|
43
43
|
## Methods
|
|
44
44
|
|
|
45
|
-
### bootstrap()
|
|
45
|
+
### bootstrap() {#bootstrap}
|
|
46
46
|
|
|
47
47
|
> **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
48
48
|
|
|
@@ -68,7 +68,7 @@ True if the bootstrapping process was successful.
|
|
|
68
68
|
|
|
69
69
|
***
|
|
70
70
|
|
|
71
|
-
### className()
|
|
71
|
+
### className() {#classname}
|
|
72
72
|
|
|
73
73
|
> **className**(): `string`
|
|
74
74
|
|
|
@@ -86,7 +86,25 @@ The class name of the component.
|
|
|
86
86
|
|
|
87
87
|
***
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### health() {#health}
|
|
90
|
+
|
|
91
|
+
> **health**(): `Promise`\<`IHealth`[]\>
|
|
92
|
+
|
|
93
|
+
Returns the health status of the component.
|
|
94
|
+
|
|
95
|
+
#### Returns
|
|
96
|
+
|
|
97
|
+
`Promise`\<`IHealth`[]\>
|
|
98
|
+
|
|
99
|
+
The health status of the component, can return multiple entries for elements within the component.
|
|
100
|
+
|
|
101
|
+
#### Implementation of
|
|
102
|
+
|
|
103
|
+
`IEntityStorageConnector.health`
|
|
104
|
+
|
|
105
|
+
***
|
|
106
|
+
|
|
107
|
+
### getSchema() {#getschema}
|
|
90
108
|
|
|
91
109
|
> **getSchema**(): `IEntitySchema`
|
|
92
110
|
|
|
@@ -104,7 +122,7 @@ The schema for the entities.
|
|
|
104
122
|
|
|
105
123
|
***
|
|
106
124
|
|
|
107
|
-
### get()
|
|
125
|
+
### get() {#get}
|
|
108
126
|
|
|
109
127
|
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
|
|
110
128
|
|
|
@@ -142,7 +160,7 @@ The object if it can be found or undefined.
|
|
|
142
160
|
|
|
143
161
|
***
|
|
144
162
|
|
|
145
|
-
### set()
|
|
163
|
+
### set() {#set}
|
|
146
164
|
|
|
147
165
|
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
148
166
|
|
|
@@ -174,7 +192,103 @@ The id of the entity.
|
|
|
174
192
|
|
|
175
193
|
***
|
|
176
194
|
|
|
177
|
-
###
|
|
195
|
+
### setBatch() {#setbatch}
|
|
196
|
+
|
|
197
|
+
> **setBatch**(`entities`): `Promise`\<`void`\>
|
|
198
|
+
|
|
199
|
+
Set multiple entities in a batch.
|
|
200
|
+
|
|
201
|
+
#### Parameters
|
|
202
|
+
|
|
203
|
+
##### entities
|
|
204
|
+
|
|
205
|
+
`T`[]
|
|
206
|
+
|
|
207
|
+
The entities to set.
|
|
208
|
+
|
|
209
|
+
#### Returns
|
|
210
|
+
|
|
211
|
+
`Promise`\<`void`\>
|
|
212
|
+
|
|
213
|
+
Nothing.
|
|
214
|
+
|
|
215
|
+
#### Implementation of
|
|
216
|
+
|
|
217
|
+
`IEntityStorageConnector.setBatch`
|
|
218
|
+
|
|
219
|
+
***
|
|
220
|
+
|
|
221
|
+
### empty() {#empty}
|
|
222
|
+
|
|
223
|
+
> **empty**(): `Promise`\<`void`\>
|
|
224
|
+
|
|
225
|
+
Remove all entities from the storage.
|
|
226
|
+
|
|
227
|
+
#### Returns
|
|
228
|
+
|
|
229
|
+
`Promise`\<`void`\>
|
|
230
|
+
|
|
231
|
+
Nothing.
|
|
232
|
+
|
|
233
|
+
#### Implementation of
|
|
234
|
+
|
|
235
|
+
`IEntityStorageConnector.empty`
|
|
236
|
+
|
|
237
|
+
***
|
|
238
|
+
|
|
239
|
+
### removeBatch() {#removebatch}
|
|
240
|
+
|
|
241
|
+
> **removeBatch**(`ids`): `Promise`\<`void`\>
|
|
242
|
+
|
|
243
|
+
Remove multiple entities by id.
|
|
244
|
+
|
|
245
|
+
#### Parameters
|
|
246
|
+
|
|
247
|
+
##### ids
|
|
248
|
+
|
|
249
|
+
`string`[]
|
|
250
|
+
|
|
251
|
+
The ids of the entities to remove.
|
|
252
|
+
|
|
253
|
+
#### Returns
|
|
254
|
+
|
|
255
|
+
`Promise`\<`void`\>
|
|
256
|
+
|
|
257
|
+
Nothing.
|
|
258
|
+
|
|
259
|
+
#### Implementation of
|
|
260
|
+
|
|
261
|
+
`IEntityStorageConnector.removeBatch`
|
|
262
|
+
|
|
263
|
+
***
|
|
264
|
+
|
|
265
|
+
### teardown() {#teardown}
|
|
266
|
+
|
|
267
|
+
> **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
268
|
+
|
|
269
|
+
Teardown the storage by deleting the underlying store file.
|
|
270
|
+
|
|
271
|
+
#### Parameters
|
|
272
|
+
|
|
273
|
+
##### nodeLoggingComponentType?
|
|
274
|
+
|
|
275
|
+
`string`
|
|
276
|
+
|
|
277
|
+
The node logging component type.
|
|
278
|
+
|
|
279
|
+
#### Returns
|
|
280
|
+
|
|
281
|
+
`Promise`\<`boolean`\>
|
|
282
|
+
|
|
283
|
+
True if the teardown process was successful.
|
|
284
|
+
|
|
285
|
+
#### Implementation of
|
|
286
|
+
|
|
287
|
+
`IEntityStorageConnector.teardown`
|
|
288
|
+
|
|
289
|
+
***
|
|
290
|
+
|
|
291
|
+
### remove() {#remove}
|
|
178
292
|
|
|
179
293
|
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
180
294
|
|
|
@@ -206,7 +320,7 @@ Nothing.
|
|
|
206
320
|
|
|
207
321
|
***
|
|
208
322
|
|
|
209
|
-
### query()
|
|
323
|
+
### query() {#query}
|
|
210
324
|
|
|
211
325
|
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
212
326
|
|
|
@@ -254,3 +368,151 @@ and a cursor which can be used to request more entities.
|
|
|
254
368
|
#### Implementation of
|
|
255
369
|
|
|
256
370
|
`IEntityStorageConnector.query`
|
|
371
|
+
|
|
372
|
+
***
|
|
373
|
+
|
|
374
|
+
### count() {#count}
|
|
375
|
+
|
|
376
|
+
> **count**(`conditions?`): `Promise`\<`number`\>
|
|
377
|
+
|
|
378
|
+
Count all the entities which match the conditions.
|
|
379
|
+
|
|
380
|
+
#### Parameters
|
|
381
|
+
|
|
382
|
+
##### conditions?
|
|
383
|
+
|
|
384
|
+
`EntityCondition`\<`T`\>
|
|
385
|
+
|
|
386
|
+
The optional conditions to match for the entities.
|
|
387
|
+
|
|
388
|
+
#### Returns
|
|
389
|
+
|
|
390
|
+
`Promise`\<`number`\>
|
|
391
|
+
|
|
392
|
+
The total count of entities in the storage.
|
|
393
|
+
|
|
394
|
+
#### Implementation of
|
|
395
|
+
|
|
396
|
+
`IEntityStorageConnector.count`
|
|
397
|
+
|
|
398
|
+
***
|
|
399
|
+
|
|
400
|
+
### getPartitionContextIds() {#getpartitioncontextids}
|
|
401
|
+
|
|
402
|
+
> **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
|
|
403
|
+
|
|
404
|
+
Get a unique list of all the context ids from the storage.
|
|
405
|
+
|
|
406
|
+
#### Returns
|
|
407
|
+
|
|
408
|
+
`Promise`\<`IContextIds`[]\>
|
|
409
|
+
|
|
410
|
+
The list of unique context ids.
|
|
411
|
+
|
|
412
|
+
***
|
|
413
|
+
|
|
414
|
+
### createTargetConnector() {#createtargetconnector}
|
|
415
|
+
|
|
416
|
+
> **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
417
|
+
|
|
418
|
+
Create the target connector for performing the migration it will use a temporary storage location.
|
|
419
|
+
|
|
420
|
+
#### Type Parameters
|
|
421
|
+
|
|
422
|
+
##### U
|
|
423
|
+
|
|
424
|
+
`U`
|
|
425
|
+
|
|
426
|
+
#### Parameters
|
|
427
|
+
|
|
428
|
+
##### newEntitySchema
|
|
429
|
+
|
|
430
|
+
`string`
|
|
431
|
+
|
|
432
|
+
The name of the new entity schema to create the connector for.
|
|
433
|
+
|
|
434
|
+
#### Returns
|
|
435
|
+
|
|
436
|
+
`Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
437
|
+
|
|
438
|
+
Connector for performing the migration.
|
|
439
|
+
|
|
440
|
+
***
|
|
441
|
+
|
|
442
|
+
### finalizeMigration() {#finalizemigration}
|
|
443
|
+
|
|
444
|
+
> **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
445
|
+
|
|
446
|
+
Finalize the migration by tearing down the old connector and replacing it with the target connector.
|
|
447
|
+
|
|
448
|
+
#### Type Parameters
|
|
449
|
+
|
|
450
|
+
##### U
|
|
451
|
+
|
|
452
|
+
`U`
|
|
453
|
+
|
|
454
|
+
#### Parameters
|
|
455
|
+
|
|
456
|
+
##### targetConnector
|
|
457
|
+
|
|
458
|
+
`FileEntityStorageConnector`\<`U`\>
|
|
459
|
+
|
|
460
|
+
The target connector to finalize the migration with.
|
|
461
|
+
|
|
462
|
+
##### options?
|
|
463
|
+
|
|
464
|
+
`IMigrationOptions`\<`T`, `U`\>
|
|
465
|
+
|
|
466
|
+
The options to control how the migration is finalized.
|
|
467
|
+
|
|
468
|
+
##### loggingComponentType?
|
|
469
|
+
|
|
470
|
+
`string`
|
|
471
|
+
|
|
472
|
+
The optional component type to use for logging the migration progress.
|
|
473
|
+
|
|
474
|
+
#### Returns
|
|
475
|
+
|
|
476
|
+
`Promise`\<`IEntityStorageConnector`\<`U`\>\>
|
|
477
|
+
|
|
478
|
+
A promise that resolves when the migration is finalized.
|
|
479
|
+
|
|
480
|
+
***
|
|
481
|
+
|
|
482
|
+
### cleanupMigration() {#cleanupmigration}
|
|
483
|
+
|
|
484
|
+
> **cleanupMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
485
|
+
|
|
486
|
+
Cleanup the migration if a migration fails or needs to be aborted.
|
|
487
|
+
|
|
488
|
+
#### Type Parameters
|
|
489
|
+
|
|
490
|
+
##### U
|
|
491
|
+
|
|
492
|
+
`U`
|
|
493
|
+
|
|
494
|
+
#### Parameters
|
|
495
|
+
|
|
496
|
+
##### targetConnector
|
|
497
|
+
|
|
498
|
+
`IEntityStorageConnector`\<`U`\> \| `undefined`
|
|
499
|
+
|
|
500
|
+
The target connector to cleanup the migration with.
|
|
501
|
+
|
|
502
|
+
##### options?
|
|
503
|
+
|
|
504
|
+
`IMigrationOptions`\<`T`, `U`\>
|
|
505
|
+
|
|
506
|
+
The options to control how the migration is cleaned up.
|
|
507
|
+
|
|
508
|
+
##### loggingComponentType?
|
|
509
|
+
|
|
510
|
+
`string`
|
|
511
|
+
|
|
512
|
+
The optional component type to use for logging the migration progress.
|
|
513
|
+
|
|
514
|
+
#### Returns
|
|
515
|
+
|
|
516
|
+
`Promise`\<`void`\>
|
|
517
|
+
|
|
518
|
+
A promise that resolves when the migration is cleaned up.
|
|
@@ -4,8 +4,26 @@ Configuration for the File Entity Storage Connector.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### directory
|
|
7
|
+
### directory {#directory}
|
|
8
8
|
|
|
9
9
|
> **directory**: `string`
|
|
10
10
|
|
|
11
11
|
The directory to use for storage.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### diskErrorThresholdBytes? {#diskerrorthresholdbytes}
|
|
16
|
+
|
|
17
|
+
> `optional` **diskErrorThresholdBytes?**: `number`
|
|
18
|
+
|
|
19
|
+
The number of free bytes below which the health check reports an error.
|
|
20
|
+
Defaults to 100 MB.
|
|
21
|
+
|
|
22
|
+
***
|
|
23
|
+
|
|
24
|
+
### diskWarningThresholdBytes? {#diskwarningthresholdbytes}
|
|
25
|
+
|
|
26
|
+
> `optional` **diskWarningThresholdBytes?**: `number`
|
|
27
|
+
|
|
28
|
+
The number of free bytes below which the health check reports a warning.
|
|
29
|
+
Defaults to 500 MB.
|
|
@@ -4,7 +4,7 @@ Options for the File 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,15 +12,15 @@ The name of the entity schema.
|
|
|
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.
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
-
### config
|
|
23
|
+
### config {#config}
|
|
24
24
|
|
|
25
25
|
> **config**: [`IFileEntityStorageConnectorConfig`](IFileEntityStorageConnectorConfig.md)
|
|
26
26
|
|
package/locales/en.json
CHANGED
|
@@ -3,12 +3,25 @@
|
|
|
3
3
|
"fileEntityStorageConnector": {
|
|
4
4
|
"directoryCreating": "Creating directory \"{directory}\"",
|
|
5
5
|
"directoryCreated": "Created directory \"{directory}\"",
|
|
6
|
-
"directoryExists": "Skipping create directory \"{directory}\" as it already exists"
|
|
6
|
+
"directoryExists": "Skipping create directory \"{directory}\" as it already exists",
|
|
7
|
+
"storeTearingDown": "Tearing down entity storage",
|
|
8
|
+
"storeTornDown": "Entity storage torn down"
|
|
7
9
|
}
|
|
8
10
|
},
|
|
9
11
|
"error": {
|
|
10
12
|
"fileEntityStorageConnector": {
|
|
11
|
-
"directoryCreateFailed": "Creating directory \"{directory}\" failed"
|
|
13
|
+
"directoryCreateFailed": "Creating directory \"{directory}\" failed",
|
|
14
|
+
"emptyFailed": "Unable to empty entity storage",
|
|
15
|
+
"removeBatchFailed": "Unable to remove batch of entities",
|
|
16
|
+
"teardownFailed": "Unable to teardown entity storage"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"health": {
|
|
20
|
+
"fileEntityStorageConnector": {
|
|
21
|
+
"healthDescription": "Checks if there is sufficient disk space in directory \"{directory}\" for the file entity storage connector to operate properly",
|
|
22
|
+
"diskSpaceError": "Disk space critically low in directory \"{directory}\", {freeBytes} bytes free, threshold is {thresholdBytes} bytes",
|
|
23
|
+
"diskSpaceCheckFailed": "Failed to check disk space in directory \"{directory}\"",
|
|
24
|
+
"diskSpaceWarning": "Disk space low in directory \"{directory}\", {freeBytes} bytes free, threshold is {thresholdBytes} bytes"
|
|
12
25
|
}
|
|
13
26
|
}
|
|
14
27
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-file",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.21",
|
|
4
|
+
"description": "File-based connector that stores entities on disk for straightforward deployments.",
|
|
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-file"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -17,7 +17,7 @@
|
|
|
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
21
|
"@twin.org/logging-models": "next",
|
|
22
22
|
"@twin.org/nameof": "next"
|
|
23
23
|
},
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"integration"
|
|
54
54
|
],
|
|
55
55
|
"bugs": {
|
|
56
|
-
"url": "git+https://github.com/
|
|
56
|
+
"url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://twindev.org"
|
|
59
59
|
}
|