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