@twin.org/entity-storage-connector-file 0.0.1-next.9 → 0.0.2-next.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.
@@ -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);
@@ -129,15 +127,16 @@ class FileEntityStorageConnector {
129
127
  * @param conditions The optional conditions to match for the entities.
130
128
  * @returns The id of the entity.
131
129
  */
132
- async set(entity, conditions) {
133
- 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());
134
133
  const store = await this.readStore();
135
- const existingIndex = this.findItem(store, entity[this._primaryKey.property], undefined, conditions);
134
+ const existingIndex = this.findItem(store, entity$1[this._primaryKey.property], undefined, conditions);
136
135
  if (existingIndex >= 0) {
137
- store[existingIndex] = entity;
136
+ store[existingIndex] = entity$1;
138
137
  }
139
138
  else {
140
- store.push(entity);
139
+ store.push(entity$1);
141
140
  }
142
141
  await this.writeStore(store);
143
142
  }
@@ -179,7 +178,10 @@ class FileEntityStorageConnector {
179
178
  if (entity.EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
180
179
  entities.push(core.ObjectHelper.pick(allEntities[i], properties));
181
180
  if (entities.length >= finalPageSize) {
182
- nextCursor = (i + 1).toString();
181
+ if (i < allEntities.length - 1) {
182
+ nextCursor = (i + 1).toString();
183
+ }
184
+ break;
183
185
  }
184
186
  }
185
187
  }
@@ -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);
@@ -129,6 +127,7 @@ class FileEntityStorageConnector {
129
127
  */
130
128
  async set(entity, conditions) {
131
129
  Guards.object(this.CLASS_NAME, "entity", entity);
130
+ EntitySchemaHelper.validateEntity(entity, this.getSchema());
132
131
  const store = await this.readStore();
133
132
  const existingIndex = this.findItem(store, entity[this._primaryKey.property], undefined, conditions);
134
133
  if (existingIndex >= 0) {
@@ -177,7 +176,10 @@ class FileEntityStorageConnector {
177
176
  if (EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
178
177
  entities.push(ObjectHelper.pick(allEntities[i], properties));
179
178
  if (entities.length >= finalPageSize) {
180
- nextCursor = (i + 1).toString();
179
+ if (i < allEntities.length - 1) {
180
+ nextCursor = (i + 1).toString();
181
+ }
182
+ break;
181
183
  }
182
184
  }
183
185
  }
@@ -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 { IFileEntityStorageConnectorConfig } from "./models/IFileEntityStorageConnectorConfig";
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".
@@ -1,2 +1,3 @@
1
1
  export * from "./fileEntityStorageConnector";
2
2
  export * from "./models/IFileEntityStorageConnectorConfig";
3
+ export * from "./models/IFileEntityStorageConnectorConstructorOptions";
@@ -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,132 @@
1
1
  # @twin.org/entity-storage-connector-file - Changelog
2
2
 
3
- ## v0.0.1-next.9
3
+ ## [0.0.2-next.1](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-file-v0.0.2-next.0...entity-storage-connector-file-v0.0.2-next.1) (2025-07-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
9
+ * update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
10
+ * use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.0 to 0.0.2-next.1
23
+ * devDependencies
24
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.0 to 0.0.2-next.1
25
+
26
+ ## 0.0.1 (2025-07-04)
27
+
28
+
29
+ ### Features
30
+
31
+ * add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
32
+ * release to production ([a309051](https://github.com/twinfoundation/entity-storage/commit/a3090519adebf7943232b4df12e4c6bd5afe7eed))
33
+ * update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
34
+ * use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
35
+
36
+
37
+ ### Bug Fixes
38
+
39
+ * query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
40
+
41
+
42
+ ### Dependencies
43
+
44
+ * The following workspace dependencies were updated
45
+ * dependencies
46
+ * @twin.org/entity-storage-models bumped from ^0.0.0 to ^0.0.1
47
+ * devDependencies
48
+ * @twin.org/entity-storage-connector-memory bumped from ^0.0.0 to ^0.0.1
49
+
50
+ ## [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)
51
+
52
+
53
+ ### Bug Fixes
54
+
55
+ * query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
56
+
57
+
58
+ ### Dependencies
59
+
60
+ * The following workspace dependencies were updated
61
+ * dependencies
62
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
63
+ * devDependencies
64
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.30 to 0.0.1-next.31
65
+
66
+ ## [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)
67
+
68
+
69
+ ### Features
70
+
71
+ * update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
72
+
73
+
74
+ ### Dependencies
75
+
76
+ * The following workspace dependencies were updated
77
+ * dependencies
78
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
79
+ * devDependencies
80
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.29 to 0.0.1-next.30
81
+
82
+ ## [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)
83
+
84
+
85
+ ### Features
86
+
87
+ * use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
88
+
89
+
90
+ ### Dependencies
91
+
92
+ * The following workspace dependencies were updated
93
+ * dependencies
94
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
95
+ * devDependencies
96
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.28 to 0.0.1-next.29
97
+
98
+ ## [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)
99
+
100
+
101
+ ### Miscellaneous Chores
102
+
103
+ * **entity-storage-connector-file:** Synchronize repo versions
104
+
105
+
106
+ ### Dependencies
107
+
108
+ * The following workspace dependencies were updated
109
+ * dependencies
110
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.27 to 0.0.1-next.28
111
+ * devDependencies
112
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.27 to 0.0.1-next.28
113
+
114
+ ## [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)
115
+
116
+
117
+ ### Miscellaneous Chores
118
+
119
+ * **entity-storage-connector-file:** Synchronize repo versions
120
+
121
+
122
+ ### Dependencies
123
+
124
+ * The following workspace dependencies were updated
125
+ * dependencies
126
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.26 to 0.0.1-next.27
127
+ * devDependencies
128
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.26 to 0.0.1-next.27
129
+
130
+ ## v0.0.1-next.26
4
131
 
5
132
  - Initial Release
@@ -4,7 +4,9 @@ Class for performing entity storage operations in file.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `unknown`
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
- ### new FileEntityStorageConnector()
17
+ ### Constructor
16
18
 
17
- > **new FileEntityStorageConnector**\<`T`\>(`options`): [`FileEntityStorageConnector`](FileEntityStorageConnector.md)\<`T`\>
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
- **options**
24
-
25
- The options for the connector.
26
-
27
- • **options.entitySchema**: `string`
25
+ ##### options
28
26
 
29
- The name of the entity schema.
27
+ [`IFileEntityStorageConnectorConstructorOptions`](../interfaces/IFileEntityStorageConnectorConstructorOptions.md)
30
28
 
31
- **options.config**: [`IFileEntityStorageConnectorConfig`](../interfaces/IFileEntityStorageConnectorConfig.md)
32
-
33
- The configuration for the connector.
29
+ The options for the connector.
34
30
 
35
31
  #### Returns
36
32
 
37
- [`FileEntityStorageConnector`](FileEntityStorageConnector.md)\<`T`\>
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`?): `Promise`\<`boolean`\>
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
- **nodeLoggingConnectorType?**: `string`
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`\<`unknown`\>
77
+ > **getSchema**(): `IEntitySchema`
80
78
 
81
79
  Get the schema for the entities.
82
80
 
83
81
  #### Returns
84
82
 
85
- `IEntitySchema`\<`unknown`\>
83
+ `IEntitySchema`
86
84
 
87
85
  The schema for the entities.
88
86
 
@@ -94,21 +92,27 @@ The schema for the entities.
94
92
 
95
93
  ### get()
96
94
 
97
- > **get**(`id`, `secondaryIndex`?, `conditions`?): `Promise`\<`undefined` \| `T`\>
95
+ > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`undefined` \| `T`\>
98
96
 
99
97
  Get an entity.
100
98
 
101
99
  #### Parameters
102
100
 
103
- **id**: `string`
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
- **secondaryIndex?**: keyof `T`
107
+ ##### secondaryIndex?
108
+
109
+ keyof `T`
108
110
 
109
111
  Get the item using a secondary index.
110
112
 
111
- **conditions?**: `object`[]
113
+ ##### conditions?
114
+
115
+ `object`[]
112
116
 
113
117
  The optional conditions to match for the entities.
114
118
 
@@ -126,17 +130,21 @@ The object if it can be found or undefined.
126
130
 
127
131
  ### set()
128
132
 
129
- > **set**(`entity`, `conditions`?): `Promise`\<`void`\>
133
+ > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
130
134
 
131
135
  Set an entity.
132
136
 
133
137
  #### Parameters
134
138
 
135
- **entity**: `T`
139
+ ##### entity
140
+
141
+ `T`
136
142
 
137
143
  The entity to set.
138
144
 
139
- **conditions?**: `object`[]
145
+ ##### conditions?
146
+
147
+ `object`[]
140
148
 
141
149
  The optional conditions to match for the entities.
142
150
 
@@ -154,17 +162,21 @@ The id of the entity.
154
162
 
155
163
  ### remove()
156
164
 
157
- > **remove**(`id`, `conditions`?): `Promise`\<`void`\>
165
+ > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
158
166
 
159
167
  Remove the entity.
160
168
 
161
169
  #### Parameters
162
170
 
163
- **id**: `string`
171
+ ##### id
172
+
173
+ `string`
164
174
 
165
175
  The id of the entity to remove.
166
176
 
167
- **conditions?**: `object`[]
177
+ ##### conditions?
178
+
179
+ `object`[]
168
180
 
169
181
  The optional conditions to match for the entities.
170
182
 
@@ -182,51 +194,49 @@ Nothing.
182
194
 
183
195
  ### query()
184
196
 
185
- > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
197
+ > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `pageSize?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
186
198
 
187
199
  Find all the entities which match the conditions.
188
200
 
189
201
  #### Parameters
190
202
 
191
- **conditions?**: `EntityCondition`\<`T`\>
203
+ ##### conditions?
204
+
205
+ `EntityCondition`\<`T`\>
192
206
 
193
207
  The conditions to match for the entities.
194
208
 
195
- **sortProperties?**: `object`[]
209
+ ##### sortProperties?
210
+
211
+ `object`[]
196
212
 
197
213
  The optional sort order.
198
214
 
199
- **properties?**: keyof `T`[]
215
+ ##### properties?
216
+
217
+ keyof `T`[]
200
218
 
201
219
  The optional properties to return, defaults to all.
202
220
 
203
- **cursor?**: `string`
221
+ ##### cursor?
222
+
223
+ `string`
204
224
 
205
225
  The cursor to request the next page of entities.
206
226
 
207
- **pageSize?**: `number`
227
+ ##### pageSize?
228
+
229
+ `number`
208
230
 
209
231
  The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
210
232
 
211
233
  #### Returns
212
234
 
213
- `Promise`\<`object`\>
235
+ `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
214
236
 
215
237
  All the entities for the storage matching the conditions,
216
238
  and a cursor which can be used to request more entities.
217
239
 
218
- ##### entities
219
-
220
- > **entities**: `Partial`\<`T`\>[]
221
-
222
- The entities, which can be partial if a limited keys list was provided.
223
-
224
- ##### cursor?
225
-
226
- > `optional` **cursor**: `string`
227
-
228
- An optional cursor, when defined can be used to call find to get more entities.
229
-
230
240
  #### Implementation of
231
241
 
232
242
  `IEntityStorageConnector.query`
@@ -7,3 +7,4 @@
7
7
  ## Interfaces
8
8
 
9
9
  - [IFileEntityStorageConnectorConfig](interfaces/IFileEntityStorageConnectorConfig.md)
10
+ - [IFileEntityStorageConnectorConstructorOptions](interfaces/IFileEntityStorageConnectorConstructorOptions.md)
@@ -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.9",
3
+ "version": "0.0.2-next.1",
4
4
  "description": "Entity Storage connector implementation using file storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/entity": "next",
19
- "@twin.org/entity-storage-models": "0.0.1-next.9",
19
+ "@twin.org/entity-storage-models": "0.0.2-next.1",
20
20
  "@twin.org/logging-models": "next",
21
21
  "@twin.org/nameof": "next"
22
22
  },
@@ -25,11 +25,11 @@
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",