@twin.org/entity-storage-connector-file 0.0.1-next.2 → 0.0.1-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/dist/cjs/index.cjs +67 -15
- package/dist/esm/index.mjs +69 -17
- package/dist/types/fileEntityStorageConnector.d.ts +23 -11
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/IFileEntityStorageConnectorConstructorOptions.d.ts +14 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/FileEntityStorageConnector.md +74 -36
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IFileEntityStorageConnectorConstructorOptions.md +19 -0
- package/package.json +5 -36
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);
|
|
@@ -103,31 +101,36 @@ class FileEntityStorageConnector {
|
|
|
103
101
|
}
|
|
104
102
|
return true;
|
|
105
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the schema for the entities.
|
|
106
|
+
* @returns The schema for the entities.
|
|
107
|
+
*/
|
|
108
|
+
getSchema() {
|
|
109
|
+
return this._entitySchema;
|
|
110
|
+
}
|
|
106
111
|
/**
|
|
107
112
|
* Get an entity.
|
|
108
113
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
109
114
|
* @param secondaryIndex Get the item using a secondary index.
|
|
115
|
+
* @param conditions The optional conditions to match for the entities.
|
|
110
116
|
* @returns The object if it can be found or undefined.
|
|
111
117
|
*/
|
|
112
|
-
async get(id, secondaryIndex) {
|
|
118
|
+
async get(id, secondaryIndex, conditions) {
|
|
113
119
|
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
114
|
-
const lookupKey = secondaryIndex ?? this._primaryKey.property;
|
|
115
120
|
const store = await this.readStore();
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
return found;
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
+
const foundIndex = this.findItem(store, id, secondaryIndex, conditions);
|
|
122
|
+
return foundIndex === -1 ? undefined : store[foundIndex];
|
|
121
123
|
}
|
|
122
124
|
/**
|
|
123
125
|
* Set an entity.
|
|
124
126
|
* @param entity The entity to set.
|
|
127
|
+
* @param conditions The optional conditions to match for the entities.
|
|
125
128
|
* @returns The id of the entity.
|
|
126
129
|
*/
|
|
127
|
-
async set(entity) {
|
|
130
|
+
async set(entity, conditions) {
|
|
128
131
|
core.Guards.object(this.CLASS_NAME, "entity", entity);
|
|
129
132
|
const store = await this.readStore();
|
|
130
|
-
const existingIndex =
|
|
133
|
+
const existingIndex = this.findItem(store, entity[this._primaryKey.property], undefined, conditions);
|
|
131
134
|
if (existingIndex >= 0) {
|
|
132
135
|
store[existingIndex] = entity;
|
|
133
136
|
}
|
|
@@ -139,16 +142,17 @@ class FileEntityStorageConnector {
|
|
|
139
142
|
/**
|
|
140
143
|
* Remove the entity.
|
|
141
144
|
* @param id The id of the entity to remove.
|
|
145
|
+
* @param conditions The optional conditions to match for the entities.
|
|
142
146
|
* @returns Nothing.
|
|
143
147
|
*/
|
|
144
|
-
async remove(id) {
|
|
148
|
+
async remove(id, conditions) {
|
|
145
149
|
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
146
150
|
const store = await this.readStore();
|
|
147
|
-
const index =
|
|
151
|
+
const index = this.findItem(store, id, undefined, conditions);
|
|
148
152
|
if (index >= 0) {
|
|
149
153
|
store.splice(index, 1);
|
|
154
|
+
await this.writeStore(store);
|
|
150
155
|
}
|
|
151
|
-
await this.writeStore(store);
|
|
152
156
|
}
|
|
153
157
|
/**
|
|
154
158
|
* Find all the entities which match the conditions.
|
|
@@ -173,7 +177,10 @@ class FileEntityStorageConnector {
|
|
|
173
177
|
if (entity.EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
|
|
174
178
|
entities.push(core.ObjectHelper.pick(allEntities[i], properties));
|
|
175
179
|
if (entities.length >= finalPageSize) {
|
|
176
|
-
|
|
180
|
+
if (i < allEntities.length - 1) {
|
|
181
|
+
nextCursor = (i + 1).toString();
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
177
184
|
}
|
|
178
185
|
}
|
|
179
186
|
}
|
|
@@ -226,6 +233,51 @@ class FileEntityStorageConnector {
|
|
|
226
233
|
return false;
|
|
227
234
|
}
|
|
228
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Find the item in the store.
|
|
238
|
+
* @param store The store to search.
|
|
239
|
+
* @param id The id to search for.
|
|
240
|
+
* @param secondaryIndex The secondary index to search for.
|
|
241
|
+
* @param conditions The optional conditions to match for the entities.
|
|
242
|
+
* @returns The index of the item if found or -1.
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
findItem(store, id, secondaryIndex, conditions) {
|
|
246
|
+
const finalConditions = [];
|
|
247
|
+
if (!core.Is.empty(secondaryIndex)) {
|
|
248
|
+
finalConditions.push({
|
|
249
|
+
property: secondaryIndex,
|
|
250
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
251
|
+
value: id
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (core.Is.arrayValue(conditions)) {
|
|
255
|
+
// If we haven't added a secondary index condition we need to add the primary key condition.
|
|
256
|
+
if (finalConditions.length === 0) {
|
|
257
|
+
finalConditions.push({
|
|
258
|
+
property: this._primaryKey.property,
|
|
259
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
260
|
+
value: id
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
finalConditions.push(...conditions.map(c => ({
|
|
264
|
+
property: c.property,
|
|
265
|
+
comparison: entity.ComparisonOperator.Equals,
|
|
266
|
+
value: c.value
|
|
267
|
+
})));
|
|
268
|
+
}
|
|
269
|
+
if (finalConditions.length > 0) {
|
|
270
|
+
for (let i = 0; i < store.length; i++) {
|
|
271
|
+
if (entity.EntityConditions.check(store[i], { conditions: finalConditions })) {
|
|
272
|
+
return i;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return store.findIndex(e => e[this._primaryKey.property] === id);
|
|
278
|
+
}
|
|
279
|
+
return -1;
|
|
280
|
+
}
|
|
229
281
|
}
|
|
230
282
|
|
|
231
283
|
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);
|
|
@@ -101,31 +99,36 @@ class FileEntityStorageConnector {
|
|
|
101
99
|
}
|
|
102
100
|
return true;
|
|
103
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the schema for the entities.
|
|
104
|
+
* @returns The schema for the entities.
|
|
105
|
+
*/
|
|
106
|
+
getSchema() {
|
|
107
|
+
return this._entitySchema;
|
|
108
|
+
}
|
|
104
109
|
/**
|
|
105
110
|
* Get an entity.
|
|
106
111
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
107
112
|
* @param secondaryIndex Get the item using a secondary index.
|
|
113
|
+
* @param conditions The optional conditions to match for the entities.
|
|
108
114
|
* @returns The object if it can be found or undefined.
|
|
109
115
|
*/
|
|
110
|
-
async get(id, secondaryIndex) {
|
|
116
|
+
async get(id, secondaryIndex, conditions) {
|
|
111
117
|
Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
112
|
-
const lookupKey = secondaryIndex ?? this._primaryKey.property;
|
|
113
118
|
const store = await this.readStore();
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
return found;
|
|
117
|
-
}
|
|
118
|
-
return undefined;
|
|
119
|
+
const foundIndex = this.findItem(store, id, secondaryIndex, conditions);
|
|
120
|
+
return foundIndex === -1 ? undefined : store[foundIndex];
|
|
119
121
|
}
|
|
120
122
|
/**
|
|
121
123
|
* Set an entity.
|
|
122
124
|
* @param entity The entity to set.
|
|
125
|
+
* @param conditions The optional conditions to match for the entities.
|
|
123
126
|
* @returns The id of the entity.
|
|
124
127
|
*/
|
|
125
|
-
async set(entity) {
|
|
128
|
+
async set(entity, conditions) {
|
|
126
129
|
Guards.object(this.CLASS_NAME, "entity", entity);
|
|
127
130
|
const store = await this.readStore();
|
|
128
|
-
const existingIndex =
|
|
131
|
+
const existingIndex = this.findItem(store, entity[this._primaryKey.property], undefined, conditions);
|
|
129
132
|
if (existingIndex >= 0) {
|
|
130
133
|
store[existingIndex] = entity;
|
|
131
134
|
}
|
|
@@ -137,16 +140,17 @@ class FileEntityStorageConnector {
|
|
|
137
140
|
/**
|
|
138
141
|
* Remove the entity.
|
|
139
142
|
* @param id The id of the entity to remove.
|
|
143
|
+
* @param conditions The optional conditions to match for the entities.
|
|
140
144
|
* @returns Nothing.
|
|
141
145
|
*/
|
|
142
|
-
async remove(id) {
|
|
146
|
+
async remove(id, conditions) {
|
|
143
147
|
Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
144
148
|
const store = await this.readStore();
|
|
145
|
-
const index =
|
|
149
|
+
const index = this.findItem(store, id, undefined, conditions);
|
|
146
150
|
if (index >= 0) {
|
|
147
151
|
store.splice(index, 1);
|
|
152
|
+
await this.writeStore(store);
|
|
148
153
|
}
|
|
149
|
-
await this.writeStore(store);
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
152
156
|
* Find all the entities which match the conditions.
|
|
@@ -171,7 +175,10 @@ class FileEntityStorageConnector {
|
|
|
171
175
|
if (EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
|
|
172
176
|
entities.push(ObjectHelper.pick(allEntities[i], properties));
|
|
173
177
|
if (entities.length >= finalPageSize) {
|
|
174
|
-
|
|
178
|
+
if (i < allEntities.length - 1) {
|
|
179
|
+
nextCursor = (i + 1).toString();
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
175
182
|
}
|
|
176
183
|
}
|
|
177
184
|
}
|
|
@@ -224,6 +231,51 @@ class FileEntityStorageConnector {
|
|
|
224
231
|
return false;
|
|
225
232
|
}
|
|
226
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Find the item in the store.
|
|
236
|
+
* @param store The store to search.
|
|
237
|
+
* @param id The id to search for.
|
|
238
|
+
* @param secondaryIndex The secondary index to search for.
|
|
239
|
+
* @param conditions The optional conditions to match for the entities.
|
|
240
|
+
* @returns The index of the item if found or -1.
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
243
|
+
findItem(store, id, secondaryIndex, conditions) {
|
|
244
|
+
const finalConditions = [];
|
|
245
|
+
if (!Is.empty(secondaryIndex)) {
|
|
246
|
+
finalConditions.push({
|
|
247
|
+
property: secondaryIndex,
|
|
248
|
+
comparison: ComparisonOperator.Equals,
|
|
249
|
+
value: id
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (Is.arrayValue(conditions)) {
|
|
253
|
+
// If we haven't added a secondary index condition we need to add the primary key condition.
|
|
254
|
+
if (finalConditions.length === 0) {
|
|
255
|
+
finalConditions.push({
|
|
256
|
+
property: this._primaryKey.property,
|
|
257
|
+
comparison: ComparisonOperator.Equals,
|
|
258
|
+
value: id
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
finalConditions.push(...conditions.map(c => ({
|
|
262
|
+
property: c.property,
|
|
263
|
+
comparison: ComparisonOperator.Equals,
|
|
264
|
+
value: c.value
|
|
265
|
+
})));
|
|
266
|
+
}
|
|
267
|
+
if (finalConditions.length > 0) {
|
|
268
|
+
for (let i = 0; i < store.length; i++) {
|
|
269
|
+
if (EntityConditions.check(store[i], { conditions: finalConditions })) {
|
|
270
|
+
return i;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
return store.findIndex(e => e[this._primaryKey.property] === id);
|
|
276
|
+
}
|
|
277
|
+
return -1;
|
|
278
|
+
}
|
|
227
279
|
}
|
|
228
280
|
|
|
229
281
|
export { FileEntityStorageConnector };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type EntityCondition, type SortDirection } from "@twin.org/entity";
|
|
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,38 +12,50 @@ 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".
|
|
25
20
|
* @returns True if the bootstrapping process was successful.
|
|
26
21
|
*/
|
|
27
22
|
bootstrap(nodeLoggingConnectorType?: string): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the schema for the entities.
|
|
25
|
+
* @returns The schema for the entities.
|
|
26
|
+
*/
|
|
27
|
+
getSchema(): IEntitySchema;
|
|
28
28
|
/**
|
|
29
29
|
* Get an entity.
|
|
30
30
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
31
31
|
* @param secondaryIndex Get the item using a secondary index.
|
|
32
|
+
* @param conditions The optional conditions to match for the entities.
|
|
32
33
|
* @returns The object if it can be found or undefined.
|
|
33
34
|
*/
|
|
34
|
-
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>;
|
|
35
39
|
/**
|
|
36
40
|
* Set an entity.
|
|
37
41
|
* @param entity The entity to set.
|
|
42
|
+
* @param conditions The optional conditions to match for the entities.
|
|
38
43
|
* @returns The id of the entity.
|
|
39
44
|
*/
|
|
40
|
-
set(entity: T
|
|
45
|
+
set(entity: T, conditions?: {
|
|
46
|
+
property: keyof T;
|
|
47
|
+
value: unknown;
|
|
48
|
+
}[]): Promise<void>;
|
|
41
49
|
/**
|
|
42
50
|
* Remove the entity.
|
|
43
51
|
* @param id The id of the entity to remove.
|
|
52
|
+
* @param conditions The optional conditions to match for the entities.
|
|
44
53
|
* @returns Nothing.
|
|
45
54
|
*/
|
|
46
|
-
remove(id: string
|
|
55
|
+
remove(id: string, conditions?: {
|
|
56
|
+
property: keyof T;
|
|
57
|
+
value: unknown;
|
|
58
|
+
}[]): Promise<void>;
|
|
47
59
|
/**
|
|
48
60
|
* Find all the entities which match the conditions.
|
|
49
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
|
@@ -20,17 +20,11 @@ Create a new instance of FileEntityStorageConnector.
|
|
|
20
20
|
|
|
21
21
|
#### Parameters
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
##### options
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
• **options.entitySchema**: `string`
|
|
28
|
-
|
|
29
|
-
The name of the entity schema.
|
|
25
|
+
[`IFileEntityStorageConnectorConstructorOptions`](../interfaces/IFileEntityStorageConnectorConstructorOptions.md)
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
The configuration for the connector.
|
|
27
|
+
The options for the connector.
|
|
34
28
|
|
|
35
29
|
#### Returns
|
|
36
30
|
|
|
@@ -58,7 +52,9 @@ Bootstrap the connector by creating and initializing any resources it needs.
|
|
|
58
52
|
|
|
59
53
|
#### Parameters
|
|
60
54
|
|
|
61
|
-
|
|
55
|
+
##### nodeLoggingConnectorType?
|
|
56
|
+
|
|
57
|
+
`string`
|
|
62
58
|
|
|
63
59
|
The node logging connector type, defaults to "node-logging".
|
|
64
60
|
|
|
@@ -74,22 +70,50 @@ True if the bootstrapping process was successful.
|
|
|
74
70
|
|
|
75
71
|
***
|
|
76
72
|
|
|
73
|
+
### getSchema()
|
|
74
|
+
|
|
75
|
+
> **getSchema**(): `IEntitySchema`
|
|
76
|
+
|
|
77
|
+
Get the schema for the entities.
|
|
78
|
+
|
|
79
|
+
#### Returns
|
|
80
|
+
|
|
81
|
+
`IEntitySchema`
|
|
82
|
+
|
|
83
|
+
The schema for the entities.
|
|
84
|
+
|
|
85
|
+
#### Implementation of
|
|
86
|
+
|
|
87
|
+
`IEntityStorageConnector.getSchema`
|
|
88
|
+
|
|
89
|
+
***
|
|
90
|
+
|
|
77
91
|
### get()
|
|
78
92
|
|
|
79
|
-
> **get**(`id`, `secondaryIndex`?): `Promise`\<`undefined` \| `T`\>
|
|
93
|
+
> **get**(`id`, `secondaryIndex`?, `conditions`?): `Promise`\<`undefined` \| `T`\>
|
|
80
94
|
|
|
81
95
|
Get an entity.
|
|
82
96
|
|
|
83
97
|
#### Parameters
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
##### id
|
|
100
|
+
|
|
101
|
+
`string`
|
|
86
102
|
|
|
87
103
|
The id of the entity to get, or the index value if secondaryIndex is set.
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
##### secondaryIndex?
|
|
106
|
+
|
|
107
|
+
keyof `T`
|
|
90
108
|
|
|
91
109
|
Get the item using a secondary index.
|
|
92
110
|
|
|
111
|
+
##### conditions?
|
|
112
|
+
|
|
113
|
+
`object`[]
|
|
114
|
+
|
|
115
|
+
The optional conditions to match for the entities.
|
|
116
|
+
|
|
93
117
|
#### Returns
|
|
94
118
|
|
|
95
119
|
`Promise`\<`undefined` \| `T`\>
|
|
@@ -104,16 +128,24 @@ The object if it can be found or undefined.
|
|
|
104
128
|
|
|
105
129
|
### set()
|
|
106
130
|
|
|
107
|
-
> **set**(`entity`): `Promise`\<`void`\>
|
|
131
|
+
> **set**(`entity`, `conditions`?): `Promise`\<`void`\>
|
|
108
132
|
|
|
109
133
|
Set an entity.
|
|
110
134
|
|
|
111
135
|
#### Parameters
|
|
112
136
|
|
|
113
|
-
|
|
137
|
+
##### entity
|
|
138
|
+
|
|
139
|
+
`T`
|
|
114
140
|
|
|
115
141
|
The entity to set.
|
|
116
142
|
|
|
143
|
+
##### conditions?
|
|
144
|
+
|
|
145
|
+
`object`[]
|
|
146
|
+
|
|
147
|
+
The optional conditions to match for the entities.
|
|
148
|
+
|
|
117
149
|
#### Returns
|
|
118
150
|
|
|
119
151
|
`Promise`\<`void`\>
|
|
@@ -128,16 +160,24 @@ The id of the entity.
|
|
|
128
160
|
|
|
129
161
|
### remove()
|
|
130
162
|
|
|
131
|
-
> **remove**(`id`): `Promise`\<`void`\>
|
|
163
|
+
> **remove**(`id`, `conditions`?): `Promise`\<`void`\>
|
|
132
164
|
|
|
133
165
|
Remove the entity.
|
|
134
166
|
|
|
135
167
|
#### Parameters
|
|
136
168
|
|
|
137
|
-
|
|
169
|
+
##### id
|
|
170
|
+
|
|
171
|
+
`string`
|
|
138
172
|
|
|
139
173
|
The id of the entity to remove.
|
|
140
174
|
|
|
175
|
+
##### conditions?
|
|
176
|
+
|
|
177
|
+
`object`[]
|
|
178
|
+
|
|
179
|
+
The optional conditions to match for the entities.
|
|
180
|
+
|
|
141
181
|
#### Returns
|
|
142
182
|
|
|
143
183
|
`Promise`\<`void`\>
|
|
@@ -152,51 +192,49 @@ Nothing.
|
|
|
152
192
|
|
|
153
193
|
### query()
|
|
154
194
|
|
|
155
|
-
> **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`
|
|
195
|
+
> **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor`: `string`; \}\>
|
|
156
196
|
|
|
157
197
|
Find all the entities which match the conditions.
|
|
158
198
|
|
|
159
199
|
#### Parameters
|
|
160
200
|
|
|
161
|
-
|
|
201
|
+
##### conditions?
|
|
202
|
+
|
|
203
|
+
`EntityCondition`\<`T`\>
|
|
162
204
|
|
|
163
205
|
The conditions to match for the entities.
|
|
164
206
|
|
|
165
|
-
|
|
207
|
+
##### sortProperties?
|
|
208
|
+
|
|
209
|
+
`object`[]
|
|
166
210
|
|
|
167
211
|
The optional sort order.
|
|
168
212
|
|
|
169
|
-
|
|
213
|
+
##### properties?
|
|
214
|
+
|
|
215
|
+
keyof `T`[]
|
|
170
216
|
|
|
171
217
|
The optional properties to return, defaults to all.
|
|
172
218
|
|
|
173
|
-
|
|
219
|
+
##### cursor?
|
|
220
|
+
|
|
221
|
+
`string`
|
|
174
222
|
|
|
175
223
|
The cursor to request the next page of entities.
|
|
176
224
|
|
|
177
|
-
|
|
225
|
+
##### pageSize?
|
|
226
|
+
|
|
227
|
+
`number`
|
|
178
228
|
|
|
179
229
|
The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
180
230
|
|
|
181
231
|
#### Returns
|
|
182
232
|
|
|
183
|
-
`Promise`\<`
|
|
233
|
+
`Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor`: `string`; \}\>
|
|
184
234
|
|
|
185
235
|
All the entities for the storage matching the conditions,
|
|
186
236
|
and a cursor which can be used to request more entities.
|
|
187
237
|
|
|
188
|
-
##### entities
|
|
189
|
-
|
|
190
|
-
> **entities**: `Partial`\<`T`\>[]
|
|
191
|
-
|
|
192
|
-
The entities, which can be partial if a limited keys list was provided.
|
|
193
|
-
|
|
194
|
-
##### cursor?
|
|
195
|
-
|
|
196
|
-
> `optional` **cursor**: `string`
|
|
197
|
-
|
|
198
|
-
An optional cursor, when defined can be used to call find to get more entities.
|
|
199
|
-
|
|
200
238
|
#### Implementation of
|
|
201
239
|
|
|
202
240
|
`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-next.
|
|
3
|
+
"version": "0.0.1-next.21",
|
|
4
4
|
"description": "Entity Storage connector implementation using file storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,54 +13,23 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"clean": "rimraf dist coverage docs/reference",
|
|
18
|
-
"build": "tspc",
|
|
19
|
-
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
-
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
-
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
-
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
-
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
-
"docs:clean": "rimraf docs/reference",
|
|
25
|
-
"docs:generate": "typedoc",
|
|
26
|
-
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
-
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
-
},
|
|
29
16
|
"dependencies": {
|
|
30
17
|
"@twin.org/core": "next",
|
|
31
18
|
"@twin.org/entity": "next",
|
|
32
|
-
"@twin.org/entity-storage-models": "0.0.1-next.
|
|
19
|
+
"@twin.org/entity-storage-models": "0.0.1-next.21",
|
|
33
20
|
"@twin.org/logging-models": "next",
|
|
34
21
|
"@twin.org/nameof": "next"
|
|
35
22
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@twin.org/entity-storage-connector-memory": "0.0.1-next.2",
|
|
38
|
-
"@twin.org/logging-connector-entity-storage": "next",
|
|
39
|
-
"@twin.org/nameof-transformer": "next",
|
|
40
|
-
"@types/node": "22.5.5",
|
|
41
|
-
"@vitest/coverage-v8": "2.1.1",
|
|
42
|
-
"copyfiles": "2.4.1",
|
|
43
|
-
"dotenv": "16.4.5",
|
|
44
|
-
"rimraf": "6.0.1",
|
|
45
|
-
"rollup": "4.21.3",
|
|
46
|
-
"rollup-plugin-copy": "3.5.0",
|
|
47
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
48
|
-
"ts-patch": "3.2.1",
|
|
49
|
-
"typedoc": "0.26.7",
|
|
50
|
-
"typedoc-plugin-markdown": "4.2.7",
|
|
51
|
-
"typescript": "5.6.2",
|
|
52
|
-
"vitest": "2.1.1"
|
|
53
|
-
},
|
|
54
23
|
"main": "./dist/cjs/index.cjs",
|
|
55
24
|
"module": "./dist/esm/index.mjs",
|
|
56
25
|
"types": "./dist/types/index.d.ts",
|
|
57
26
|
"exports": {
|
|
58
27
|
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
59
29
|
"require": "./dist/cjs/index.cjs",
|
|
60
|
-
"import": "./dist/esm/index.mjs"
|
|
61
|
-
"types": "./dist/types/index.d.ts"
|
|
30
|
+
"import": "./dist/esm/index.mjs"
|
|
62
31
|
},
|
|
63
|
-
"./locales": "./locales"
|
|
32
|
+
"./locales/*.json": "./locales/*.json"
|
|
64
33
|
},
|
|
65
34
|
"files": [
|
|
66
35
|
"dist/cjs",
|