@twin.org/entity-storage-connector-file 0.0.1-next.8 → 0.0.1
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/cjs/index.cjs +64 -18
- package/dist/esm/index.mjs +63 -17
- package/dist/types/fileEntityStorageConnector.d.ts +17 -10
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/IFileEntityStorageConnectorConstructorOptions.d.ts +14 -0
- package/docs/changelog.md +105 -1
- package/docs/reference/classes/FileEntityStorageConnector.md +65 -43
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IFileEntityStorageConnectorConstructorOptions.md +19 -0
- package/package.json +9 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -39,8 +39,6 @@ class FileEntityStorageConnector {
|
|
|
39
39
|
/**
|
|
40
40
|
* Create a new instance of FileEntityStorageConnector.
|
|
41
41
|
* @param options The options for the connector.
|
|
42
|
-
* @param options.entitySchema The name of the entity schema.
|
|
43
|
-
* @param options.config The configuration for the connector.
|
|
44
42
|
*/
|
|
45
43
|
constructor(options) {
|
|
46
44
|
core.Guards.object(this.CLASS_NAME, "options", options);
|
|
@@ -114,48 +112,48 @@ class FileEntityStorageConnector {
|
|
|
114
112
|
* Get an entity.
|
|
115
113
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
116
114
|
* @param secondaryIndex Get the item using a secondary index.
|
|
115
|
+
* @param conditions The optional conditions to match for the entities.
|
|
117
116
|
* @returns The object if it can be found or undefined.
|
|
118
117
|
*/
|
|
119
|
-
async get(id, secondaryIndex) {
|
|
118
|
+
async get(id, secondaryIndex, conditions) {
|
|
120
119
|
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
121
|
-
const lookupKey = secondaryIndex ?? this._primaryKey.property;
|
|
122
120
|
const store = await this.readStore();
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
return found;
|
|
126
|
-
}
|
|
127
|
-
return undefined;
|
|
121
|
+
const foundIndex = this.findItem(store, id, secondaryIndex, conditions);
|
|
122
|
+
return foundIndex === -1 ? undefined : store[foundIndex];
|
|
128
123
|
}
|
|
129
124
|
/**
|
|
130
125
|
* Set an entity.
|
|
131
126
|
* @param entity The entity to set.
|
|
127
|
+
* @param conditions The optional conditions to match for the entities.
|
|
132
128
|
* @returns The id of the entity.
|
|
133
129
|
*/
|
|
134
|
-
async set(entity) {
|
|
135
|
-
core.Guards.object(this.CLASS_NAME, "entity", entity);
|
|
130
|
+
async set(entity$1, conditions) {
|
|
131
|
+
core.Guards.object(this.CLASS_NAME, "entity", entity$1);
|
|
132
|
+
entity.EntitySchemaHelper.validateEntity(entity$1, this.getSchema());
|
|
136
133
|
const store = await this.readStore();
|
|
137
|
-
const existingIndex =
|
|
134
|
+
const existingIndex = this.findItem(store, entity$1[this._primaryKey.property], undefined, conditions);
|
|
138
135
|
if (existingIndex >= 0) {
|
|
139
|
-
store[existingIndex] = entity;
|
|
136
|
+
store[existingIndex] = entity$1;
|
|
140
137
|
}
|
|
141
138
|
else {
|
|
142
|
-
store.push(entity);
|
|
139
|
+
store.push(entity$1);
|
|
143
140
|
}
|
|
144
141
|
await this.writeStore(store);
|
|
145
142
|
}
|
|
146
143
|
/**
|
|
147
144
|
* Remove the entity.
|
|
148
145
|
* @param id The id of the entity to remove.
|
|
146
|
+
* @param conditions The optional conditions to match for the entities.
|
|
149
147
|
* @returns Nothing.
|
|
150
148
|
*/
|
|
151
|
-
async remove(id) {
|
|
149
|
+
async remove(id, conditions) {
|
|
152
150
|
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
153
151
|
const store = await this.readStore();
|
|
154
|
-
const index =
|
|
152
|
+
const index = this.findItem(store, id, undefined, conditions);
|
|
155
153
|
if (index >= 0) {
|
|
156
154
|
store.splice(index, 1);
|
|
155
|
+
await this.writeStore(store);
|
|
157
156
|
}
|
|
158
|
-
await this.writeStore(store);
|
|
159
157
|
}
|
|
160
158
|
/**
|
|
161
159
|
* Find all the entities which match the conditions.
|
|
@@ -180,7 +178,10 @@ class FileEntityStorageConnector {
|
|
|
180
178
|
if (entity.EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
|
|
181
179
|
entities.push(core.ObjectHelper.pick(allEntities[i], properties));
|
|
182
180
|
if (entities.length >= finalPageSize) {
|
|
183
|
-
|
|
181
|
+
if (i < allEntities.length - 1) {
|
|
182
|
+
nextCursor = (i + 1).toString();
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
}
|
|
@@ -233,6 +234,51 @@ class FileEntityStorageConnector {
|
|
|
233
234
|
return false;
|
|
234
235
|
}
|
|
235
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Find the item in the store.
|
|
239
|
+
* @param store The store to search.
|
|
240
|
+
* @param id The id to search for.
|
|
241
|
+
* @param secondaryIndex The secondary index to search for.
|
|
242
|
+
* @param conditions The optional conditions to match for the entities.
|
|
243
|
+
* @returns The index of the item if found or -1.
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
findItem(store, id, secondaryIndex, conditions) {
|
|
247
|
+
const finalConditions = [];
|
|
248
|
+
if (!core.Is.empty(secondaryIndex)) {
|
|
249
|
+
finalConditions.push({
|
|
250
|
+
property: secondaryIndex,
|
|
251
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
252
|
+
value: id
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (core.Is.arrayValue(conditions)) {
|
|
256
|
+
// If we haven't added a secondary index condition we need to add the primary key condition.
|
|
257
|
+
if (finalConditions.length === 0) {
|
|
258
|
+
finalConditions.push({
|
|
259
|
+
property: this._primaryKey.property,
|
|
260
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
261
|
+
value: id
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
finalConditions.push(...conditions.map(c => ({
|
|
265
|
+
property: c.property,
|
|
266
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
267
|
+
value: c.value
|
|
268
|
+
})));
|
|
269
|
+
}
|
|
270
|
+
if (finalConditions.length > 0) {
|
|
271
|
+
for (let i = 0; i < store.length; i++) {
|
|
272
|
+
if (entity.EntityConditions.check(store[i], { conditions: finalConditions })) {
|
|
273
|
+
return i;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return store.findIndex(e => e[this._primaryKey.property] === id);
|
|
279
|
+
}
|
|
280
|
+
return -1;
|
|
281
|
+
}
|
|
236
282
|
}
|
|
237
283
|
|
|
238
284
|
exports.FileEntityStorageConnector = FileEntityStorageConnector;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { Guards, BaseError, Coerce, ObjectHelper } from '@twin.org/core';
|
|
4
|
-
import { EntitySchemaFactory, EntitySchemaHelper, EntitySorter, EntityConditions } from '@twin.org/entity';
|
|
3
|
+
import { Guards, BaseError, Coerce, ObjectHelper, Is } from '@twin.org/core';
|
|
4
|
+
import { EntitySchemaFactory, EntitySchemaHelper, EntitySorter, EntityConditions, ComparisonOperator } from '@twin.org/entity';
|
|
5
5
|
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
6
6
|
|
|
7
7
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -37,8 +37,6 @@ class FileEntityStorageConnector {
|
|
|
37
37
|
/**
|
|
38
38
|
* Create a new instance of FileEntityStorageConnector.
|
|
39
39
|
* @param options The options for the connector.
|
|
40
|
-
* @param options.entitySchema The name of the entity schema.
|
|
41
|
-
* @param options.config The configuration for the connector.
|
|
42
40
|
*/
|
|
43
41
|
constructor(options) {
|
|
44
42
|
Guards.object(this.CLASS_NAME, "options", options);
|
|
@@ -112,27 +110,26 @@ class FileEntityStorageConnector {
|
|
|
112
110
|
* Get an entity.
|
|
113
111
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
114
112
|
* @param secondaryIndex Get the item using a secondary index.
|
|
113
|
+
* @param conditions The optional conditions to match for the entities.
|
|
115
114
|
* @returns The object if it can be found or undefined.
|
|
116
115
|
*/
|
|
117
|
-
async get(id, secondaryIndex) {
|
|
116
|
+
async get(id, secondaryIndex, conditions) {
|
|
118
117
|
Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
119
|
-
const lookupKey = secondaryIndex ?? this._primaryKey.property;
|
|
120
118
|
const store = await this.readStore();
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
return found;
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
119
|
+
const foundIndex = this.findItem(store, id, secondaryIndex, conditions);
|
|
120
|
+
return foundIndex === -1 ? undefined : store[foundIndex];
|
|
126
121
|
}
|
|
127
122
|
/**
|
|
128
123
|
* Set an entity.
|
|
129
124
|
* @param entity The entity to set.
|
|
125
|
+
* @param conditions The optional conditions to match for the entities.
|
|
130
126
|
* @returns The id of the entity.
|
|
131
127
|
*/
|
|
132
|
-
async set(entity) {
|
|
128
|
+
async set(entity, conditions) {
|
|
133
129
|
Guards.object(this.CLASS_NAME, "entity", entity);
|
|
130
|
+
EntitySchemaHelper.validateEntity(entity, this.getSchema());
|
|
134
131
|
const store = await this.readStore();
|
|
135
|
-
const existingIndex =
|
|
132
|
+
const existingIndex = this.findItem(store, entity[this._primaryKey.property], undefined, conditions);
|
|
136
133
|
if (existingIndex >= 0) {
|
|
137
134
|
store[existingIndex] = entity;
|
|
138
135
|
}
|
|
@@ -144,16 +141,17 @@ class FileEntityStorageConnector {
|
|
|
144
141
|
/**
|
|
145
142
|
* Remove the entity.
|
|
146
143
|
* @param id The id of the entity to remove.
|
|
144
|
+
* @param conditions The optional conditions to match for the entities.
|
|
147
145
|
* @returns Nothing.
|
|
148
146
|
*/
|
|
149
|
-
async remove(id) {
|
|
147
|
+
async remove(id, conditions) {
|
|
150
148
|
Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
151
149
|
const store = await this.readStore();
|
|
152
|
-
const index =
|
|
150
|
+
const index = this.findItem(store, id, undefined, conditions);
|
|
153
151
|
if (index >= 0) {
|
|
154
152
|
store.splice(index, 1);
|
|
153
|
+
await this.writeStore(store);
|
|
155
154
|
}
|
|
156
|
-
await this.writeStore(store);
|
|
157
155
|
}
|
|
158
156
|
/**
|
|
159
157
|
* Find all the entities which match the conditions.
|
|
@@ -178,7 +176,10 @@ class FileEntityStorageConnector {
|
|
|
178
176
|
if (EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
|
|
179
177
|
entities.push(ObjectHelper.pick(allEntities[i], properties));
|
|
180
178
|
if (entities.length >= finalPageSize) {
|
|
181
|
-
|
|
179
|
+
if (i < allEntities.length - 1) {
|
|
180
|
+
nextCursor = (i + 1).toString();
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
}
|
|
@@ -231,6 +232,51 @@ class FileEntityStorageConnector {
|
|
|
231
232
|
return false;
|
|
232
233
|
}
|
|
233
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Find the item in the store.
|
|
237
|
+
* @param store The store to search.
|
|
238
|
+
* @param id The id to search for.
|
|
239
|
+
* @param secondaryIndex The secondary index to search for.
|
|
240
|
+
* @param conditions The optional conditions to match for the entities.
|
|
241
|
+
* @returns The index of the item if found or -1.
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
findItem(store, id, secondaryIndex, conditions) {
|
|
245
|
+
const finalConditions = [];
|
|
246
|
+
if (!Is.empty(secondaryIndex)) {
|
|
247
|
+
finalConditions.push({
|
|
248
|
+
property: secondaryIndex,
|
|
249
|
+
comparison: ComparisonOperator.Equals,
|
|
250
|
+
value: id
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (Is.arrayValue(conditions)) {
|
|
254
|
+
// If we haven't added a secondary index condition we need to add the primary key condition.
|
|
255
|
+
if (finalConditions.length === 0) {
|
|
256
|
+
finalConditions.push({
|
|
257
|
+
property: this._primaryKey.property,
|
|
258
|
+
comparison: ComparisonOperator.Equals,
|
|
259
|
+
value: id
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
finalConditions.push(...conditions.map(c => ({
|
|
263
|
+
property: c.property,
|
|
264
|
+
comparison: ComparisonOperator.Equals,
|
|
265
|
+
value: c.value
|
|
266
|
+
})));
|
|
267
|
+
}
|
|
268
|
+
if (finalConditions.length > 0) {
|
|
269
|
+
for (let i = 0; i < store.length; i++) {
|
|
270
|
+
if (EntityConditions.check(store[i], { conditions: finalConditions })) {
|
|
271
|
+
return i;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
return store.findIndex(e => e[this._primaryKey.property] === id);
|
|
277
|
+
}
|
|
278
|
+
return -1;
|
|
279
|
+
}
|
|
234
280
|
}
|
|
235
281
|
|
|
236
282
|
export { FileEntityStorageConnector };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type EntityCondition, type IEntitySchema, type SortDirection } from "@twin.org/entity";
|
|
2
2
|
import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IFileEntityStorageConnectorConstructorOptions } from "./models/IFileEntityStorageConnectorConstructorOptions";
|
|
4
4
|
/**
|
|
5
5
|
* Class for performing entity storage operations in file.
|
|
6
6
|
*/
|
|
@@ -12,13 +12,8 @@ export declare class FileEntityStorageConnector<T = unknown> implements IEntityS
|
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of FileEntityStorageConnector.
|
|
14
14
|
* @param options The options for the connector.
|
|
15
|
-
* @param options.entitySchema The name of the entity schema.
|
|
16
|
-
* @param options.config The configuration for the connector.
|
|
17
15
|
*/
|
|
18
|
-
constructor(options:
|
|
19
|
-
entitySchema: string;
|
|
20
|
-
config: IFileEntityStorageConnectorConfig;
|
|
21
|
-
});
|
|
16
|
+
constructor(options: IFileEntityStorageConnectorConstructorOptions);
|
|
22
17
|
/**
|
|
23
18
|
* Bootstrap the connector by creating and initializing any resources it needs.
|
|
24
19
|
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
@@ -34,21 +29,33 @@ export declare class FileEntityStorageConnector<T = unknown> implements IEntityS
|
|
|
34
29
|
* Get an entity.
|
|
35
30
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
36
31
|
* @param secondaryIndex Get the item using a secondary index.
|
|
32
|
+
* @param conditions The optional conditions to match for the entities.
|
|
37
33
|
* @returns The object if it can be found or undefined.
|
|
38
34
|
*/
|
|
39
|
-
get(id: string, secondaryIndex?: keyof T
|
|
35
|
+
get(id: string, secondaryIndex?: keyof T, conditions?: {
|
|
36
|
+
property: keyof T;
|
|
37
|
+
value: unknown;
|
|
38
|
+
}[]): Promise<T | undefined>;
|
|
40
39
|
/**
|
|
41
40
|
* Set an entity.
|
|
42
41
|
* @param entity The entity to set.
|
|
42
|
+
* @param conditions The optional conditions to match for the entities.
|
|
43
43
|
* @returns The id of the entity.
|
|
44
44
|
*/
|
|
45
|
-
set(entity: T
|
|
45
|
+
set(entity: T, conditions?: {
|
|
46
|
+
property: keyof T;
|
|
47
|
+
value: unknown;
|
|
48
|
+
}[]): Promise<void>;
|
|
46
49
|
/**
|
|
47
50
|
* Remove the entity.
|
|
48
51
|
* @param id The id of the entity to remove.
|
|
52
|
+
* @param conditions The optional conditions to match for the entities.
|
|
49
53
|
* @returns Nothing.
|
|
50
54
|
*/
|
|
51
|
-
remove(id: string
|
|
55
|
+
remove(id: string, conditions?: {
|
|
56
|
+
property: keyof T;
|
|
57
|
+
value: unknown;
|
|
58
|
+
}[]): Promise<void>;
|
|
52
59
|
/**
|
|
53
60
|
* Find all the entities which match the conditions.
|
|
54
61
|
* @param conditions The conditions to match for the entities.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IFileEntityStorageConnectorConfig } from "./IFileEntityStorageConnectorConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the File Entity Storage Connector constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IFileEntityStorageConnectorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the entity schema.
|
|
8
|
+
*/
|
|
9
|
+
entitySchema: string;
|
|
10
|
+
/**
|
|
11
|
+
* The configuration for the connector.
|
|
12
|
+
*/
|
|
13
|
+
config: IFileEntityStorageConnectorConfig;
|
|
14
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,109 @@
|
|
|
1
1
|
# @twin.org/entity-storage-connector-file - Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.0.1 (2025-07-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
9
|
+
* release to production ([a309051](https://github.com/twinfoundation/entity-storage/commit/a3090519adebf7943232b4df12e4c6bd5afe7eed))
|
|
10
|
+
* update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
11
|
+
* use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
* The following workspace dependencies were updated
|
|
22
|
+
* dependencies
|
|
23
|
+
* @twin.org/entity-storage-models bumped from ^0.0.0 to ^0.0.1
|
|
24
|
+
* devDependencies
|
|
25
|
+
* @twin.org/entity-storage-connector-memory bumped from ^0.0.0 to ^0.0.1
|
|
26
|
+
|
|
27
|
+
## [0.0.1-next.31](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.1-next.30...entity-storage-connector-file-v0.0.1-next.31) (2025-06-20)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Dependencies
|
|
36
|
+
|
|
37
|
+
* The following workspace dependencies were updated
|
|
38
|
+
* dependencies
|
|
39
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
40
|
+
* devDependencies
|
|
41
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
42
|
+
|
|
43
|
+
## [0.0.1-next.30](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.1-next.29...entity-storage-connector-file-v0.0.1-next.30) (2025-06-12)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
* update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Dependencies
|
|
52
|
+
|
|
53
|
+
* The following workspace dependencies were updated
|
|
54
|
+
* dependencies
|
|
55
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
56
|
+
* devDependencies
|
|
57
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
58
|
+
|
|
59
|
+
## [0.0.1-next.29](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.1-next.28...entity-storage-connector-file-v0.0.1-next.29) (2025-04-17)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* The following workspace dependencies were updated
|
|
70
|
+
* dependencies
|
|
71
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
|
|
72
|
+
* devDependencies
|
|
73
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.28 to 0.0.1-next.29
|
|
74
|
+
|
|
75
|
+
## [0.0.1-next.28](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.1-next.27...entity-storage-connector-file-v0.0.1-next.28) (2025-04-09)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Miscellaneous Chores
|
|
79
|
+
|
|
80
|
+
* **entity-storage-connector-file:** Synchronize repo versions
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Dependencies
|
|
84
|
+
|
|
85
|
+
* The following workspace dependencies were updated
|
|
86
|
+
* dependencies
|
|
87
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.27 to 0.0.1-next.28
|
|
88
|
+
* devDependencies
|
|
89
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.27 to 0.0.1-next.28
|
|
90
|
+
|
|
91
|
+
## [0.0.1-next.27](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.1-next.26...entity-storage-connector-file-v0.0.1-next.27) (2025-03-28)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### Miscellaneous Chores
|
|
95
|
+
|
|
96
|
+
* **entity-storage-connector-file:** Synchronize repo versions
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Dependencies
|
|
100
|
+
|
|
101
|
+
* The following workspace dependencies were updated
|
|
102
|
+
* dependencies
|
|
103
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.26 to 0.0.1-next.27
|
|
104
|
+
* devDependencies
|
|
105
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.26 to 0.0.1-next.27
|
|
106
|
+
|
|
107
|
+
## v0.0.1-next.26
|
|
4
108
|
|
|
5
109
|
- Initial Release
|
|
@@ -4,7 +4,9 @@ Class for performing entity storage operations in file.
|
|
|
4
4
|
|
|
5
5
|
## Type Parameters
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### T
|
|
8
|
+
|
|
9
|
+
`T` = `unknown`
|
|
8
10
|
|
|
9
11
|
## Implements
|
|
10
12
|
|
|
@@ -12,29 +14,23 @@ Class for performing entity storage operations in file.
|
|
|
12
14
|
|
|
13
15
|
## Constructors
|
|
14
16
|
|
|
15
|
-
###
|
|
17
|
+
### Constructor
|
|
16
18
|
|
|
17
|
-
> **new FileEntityStorageConnector**\<`T`\>(`options`):
|
|
19
|
+
> **new FileEntityStorageConnector**\<`T`\>(`options`): `FileEntityStorageConnector`\<`T`\>
|
|
18
20
|
|
|
19
21
|
Create a new instance of FileEntityStorageConnector.
|
|
20
22
|
|
|
21
23
|
#### Parameters
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
The options for the connector.
|
|
26
|
-
|
|
27
|
-
• **options.entitySchema**: `string`
|
|
28
|
-
|
|
29
|
-
The name of the entity schema.
|
|
25
|
+
##### options
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
[`IFileEntityStorageConnectorConstructorOptions`](../interfaces/IFileEntityStorageConnectorConstructorOptions.md)
|
|
32
28
|
|
|
33
|
-
The
|
|
29
|
+
The options for the connector.
|
|
34
30
|
|
|
35
31
|
#### Returns
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
`FileEntityStorageConnector`\<`T`\>
|
|
38
34
|
|
|
39
35
|
## Properties
|
|
40
36
|
|
|
@@ -52,13 +48,15 @@ Runtime name for the class.
|
|
|
52
48
|
|
|
53
49
|
### bootstrap()
|
|
54
50
|
|
|
55
|
-
> **bootstrap**(`nodeLoggingConnectorType
|
|
51
|
+
> **bootstrap**(`nodeLoggingConnectorType?`): `Promise`\<`boolean`\>
|
|
56
52
|
|
|
57
53
|
Bootstrap the connector by creating and initializing any resources it needs.
|
|
58
54
|
|
|
59
55
|
#### Parameters
|
|
60
56
|
|
|
61
|
-
|
|
57
|
+
##### nodeLoggingConnectorType?
|
|
58
|
+
|
|
59
|
+
`string`
|
|
62
60
|
|
|
63
61
|
The node logging connector type, defaults to "node-logging".
|
|
64
62
|
|
|
@@ -76,13 +74,13 @@ True if the bootstrapping process was successful.
|
|
|
76
74
|
|
|
77
75
|
### getSchema()
|
|
78
76
|
|
|
79
|
-
> **getSchema**(): `IEntitySchema
|
|
77
|
+
> **getSchema**(): `IEntitySchema`
|
|
80
78
|
|
|
81
79
|
Get the schema for the entities.
|
|
82
80
|
|
|
83
81
|
#### Returns
|
|
84
82
|
|
|
85
|
-
`IEntitySchema
|
|
83
|
+
`IEntitySchema`
|
|
86
84
|
|
|
87
85
|
The schema for the entities.
|
|
88
86
|
|
|
@@ -94,20 +92,30 @@ The schema for the entities.
|
|
|
94
92
|
|
|
95
93
|
### get()
|
|
96
94
|
|
|
97
|
-
> **get**(`id`, `secondaryIndex
|
|
95
|
+
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`undefined` \| `T`\>
|
|
98
96
|
|
|
99
97
|
Get an entity.
|
|
100
98
|
|
|
101
99
|
#### Parameters
|
|
102
100
|
|
|
103
|
-
|
|
101
|
+
##### id
|
|
102
|
+
|
|
103
|
+
`string`
|
|
104
104
|
|
|
105
105
|
The id of the entity to get, or the index value if secondaryIndex is set.
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
##### secondaryIndex?
|
|
108
|
+
|
|
109
|
+
keyof `T`
|
|
108
110
|
|
|
109
111
|
Get the item using a secondary index.
|
|
110
112
|
|
|
113
|
+
##### conditions?
|
|
114
|
+
|
|
115
|
+
`object`[]
|
|
116
|
+
|
|
117
|
+
The optional conditions to match for the entities.
|
|
118
|
+
|
|
111
119
|
#### Returns
|
|
112
120
|
|
|
113
121
|
`Promise`\<`undefined` \| `T`\>
|
|
@@ -122,16 +130,24 @@ The object if it can be found or undefined.
|
|
|
122
130
|
|
|
123
131
|
### set()
|
|
124
132
|
|
|
125
|
-
> **set**(`entity`): `Promise`\<`void`\>
|
|
133
|
+
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
126
134
|
|
|
127
135
|
Set an entity.
|
|
128
136
|
|
|
129
137
|
#### Parameters
|
|
130
138
|
|
|
131
|
-
|
|
139
|
+
##### entity
|
|
140
|
+
|
|
141
|
+
`T`
|
|
132
142
|
|
|
133
143
|
The entity to set.
|
|
134
144
|
|
|
145
|
+
##### conditions?
|
|
146
|
+
|
|
147
|
+
`object`[]
|
|
148
|
+
|
|
149
|
+
The optional conditions to match for the entities.
|
|
150
|
+
|
|
135
151
|
#### Returns
|
|
136
152
|
|
|
137
153
|
`Promise`\<`void`\>
|
|
@@ -146,16 +162,24 @@ The id of the entity.
|
|
|
146
162
|
|
|
147
163
|
### remove()
|
|
148
164
|
|
|
149
|
-
> **remove**(`id`): `Promise`\<`void`\>
|
|
165
|
+
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
150
166
|
|
|
151
167
|
Remove the entity.
|
|
152
168
|
|
|
153
169
|
#### Parameters
|
|
154
170
|
|
|
155
|
-
|
|
171
|
+
##### id
|
|
172
|
+
|
|
173
|
+
`string`
|
|
156
174
|
|
|
157
175
|
The id of the entity to remove.
|
|
158
176
|
|
|
177
|
+
##### conditions?
|
|
178
|
+
|
|
179
|
+
`object`[]
|
|
180
|
+
|
|
181
|
+
The optional conditions to match for the entities.
|
|
182
|
+
|
|
159
183
|
#### Returns
|
|
160
184
|
|
|
161
185
|
`Promise`\<`void`\>
|
|
@@ -170,51 +194,49 @@ Nothing.
|
|
|
170
194
|
|
|
171
195
|
### query()
|
|
172
196
|
|
|
173
|
-
> **query**(`conditions
|
|
197
|
+
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `pageSize?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
174
198
|
|
|
175
199
|
Find all the entities which match the conditions.
|
|
176
200
|
|
|
177
201
|
#### Parameters
|
|
178
202
|
|
|
179
|
-
|
|
203
|
+
##### conditions?
|
|
204
|
+
|
|
205
|
+
`EntityCondition`\<`T`\>
|
|
180
206
|
|
|
181
207
|
The conditions to match for the entities.
|
|
182
208
|
|
|
183
|
-
|
|
209
|
+
##### sortProperties?
|
|
210
|
+
|
|
211
|
+
`object`[]
|
|
184
212
|
|
|
185
213
|
The optional sort order.
|
|
186
214
|
|
|
187
|
-
|
|
215
|
+
##### properties?
|
|
216
|
+
|
|
217
|
+
keyof `T`[]
|
|
188
218
|
|
|
189
219
|
The optional properties to return, defaults to all.
|
|
190
220
|
|
|
191
|
-
|
|
221
|
+
##### cursor?
|
|
222
|
+
|
|
223
|
+
`string`
|
|
192
224
|
|
|
193
225
|
The cursor to request the next page of entities.
|
|
194
226
|
|
|
195
|
-
|
|
227
|
+
##### pageSize?
|
|
228
|
+
|
|
229
|
+
`number`
|
|
196
230
|
|
|
197
231
|
The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
198
232
|
|
|
199
233
|
#### Returns
|
|
200
234
|
|
|
201
|
-
`Promise`\<`
|
|
235
|
+
`Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
202
236
|
|
|
203
237
|
All the entities for the storage matching the conditions,
|
|
204
238
|
and a cursor which can be used to request more entities.
|
|
205
239
|
|
|
206
|
-
##### entities
|
|
207
|
-
|
|
208
|
-
> **entities**: `Partial`\<`T`\>[]
|
|
209
|
-
|
|
210
|
-
The entities, which can be partial if a limited keys list was provided.
|
|
211
|
-
|
|
212
|
-
##### cursor?
|
|
213
|
-
|
|
214
|
-
> `optional` **cursor**: `string`
|
|
215
|
-
|
|
216
|
-
An optional cursor, when defined can be used to call find to get more entities.
|
|
217
|
-
|
|
218
240
|
#### Implementation of
|
|
219
241
|
|
|
220
242
|
`IEntityStorageConnector.query`
|
package/docs/reference/index.md
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Interface: IFileEntityStorageConnectorConstructorOptions
|
|
2
|
+
|
|
3
|
+
Options for the File Entity Storage Connector constructor.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### entitySchema
|
|
8
|
+
|
|
9
|
+
> **entitySchema**: `string`
|
|
10
|
+
|
|
11
|
+
The name of the entity schema.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### config
|
|
16
|
+
|
|
17
|
+
> **config**: [`IFileEntityStorageConnectorConfig`](IFileEntityStorageConnectorConfig.md)
|
|
18
|
+
|
|
19
|
+
The configuration for the connector.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-file",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "Entity Storage connector implementation using file storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "
|
|
18
|
-
"@twin.org/entity": "
|
|
19
|
-
"@twin.org/entity-storage-models": "0.0.1
|
|
20
|
-
"@twin.org/logging-models": "
|
|
21
|
-
"@twin.org/nameof": "
|
|
17
|
+
"@twin.org/core": "^0.0.1",
|
|
18
|
+
"@twin.org/entity": "^0.0.1",
|
|
19
|
+
"@twin.org/entity-storage-models": "^0.0.1",
|
|
20
|
+
"@twin.org/logging-models": "^0.0.1",
|
|
21
|
+
"@twin.org/nameof": "^0.0.1"
|
|
22
22
|
},
|
|
23
23
|
"main": "./dist/cjs/index.cjs",
|
|
24
24
|
"module": "./dist/esm/index.mjs",
|
|
25
25
|
"types": "./dist/types/index.d.ts",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
28
29
|
"require": "./dist/cjs/index.cjs",
|
|
29
|
-
"import": "./dist/esm/index.mjs"
|
|
30
|
-
"types": "./dist/types/index.d.ts"
|
|
30
|
+
"import": "./dist/esm/index.mjs"
|
|
31
31
|
},
|
|
32
|
-
"./locales": "./locales"
|
|
32
|
+
"./locales/*.json": "./locales/*.json"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist/cjs",
|