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