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