@twin.org/entity-storage-connector-memory 0.0.3-next.1 → 0.0.3-next.10
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/README.md +2 -2
- package/dist/es/memoryEntityStorageConnector.js +150 -2
- package/dist/es/memoryEntityStorageConnector.js.map +1 -1
- package/dist/types/memoryEntityStorageConnector.d.ts +34 -0
- package/docs/changelog.md +166 -40
- package/docs/examples.md +78 -1
- package/docs/reference/classes/MemoryEntityStorageConnector.md +140 -8
- package/docs/reference/interfaces/IMemoryEntityStorageConnectorConstructorOptions.md +3 -3
- package/locales/en.json +13 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage Connector Memory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides an in-memory backend suited to local development, automated testing and short-lived workloads. It is designed to work with the wider storage ecosystem so applications can keep behaviour consistent across connectors and environments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { ContextIdHelper, ContextIdStore } from "@twin.org/context";
|
|
4
|
-
import { Coerce, Guards, Is, ObjectHelper } from "@twin.org/core";
|
|
4
|
+
import { Coerce, ComponentFactory, Guards, HealthStatus, Is, ObjectHelper } from "@twin.org/core";
|
|
5
5
|
import { ComparisonOperator, EntityConditions, EntitySchemaFactory, EntitySchemaHelper, EntitySorter, LogicalOperator } from "@twin.org/entity";
|
|
6
6
|
/**
|
|
7
7
|
* Class for performing entity storage operations in-memory.
|
|
@@ -53,6 +53,29 @@ export class MemoryEntityStorageConnector {
|
|
|
53
53
|
this._primaryKey = EntitySchemaHelper.getPrimaryKey(this._entitySchema);
|
|
54
54
|
this._store = [];
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Deep-clone condition tree and map `null` to `undefined` on Equals/NotEquals leaves
|
|
58
|
+
* so in-memory evaluation matches SQL-style "IS NULL" / "IS NOT NULL" semantics.
|
|
59
|
+
* @param condition The user-supplied condition (not mutated).
|
|
60
|
+
* @returns A clone safe to pass to {@link EntityConditions.check}.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
static normalizeNullToUndefined(condition) {
|
|
64
|
+
if ("conditions" in condition) {
|
|
65
|
+
return {
|
|
66
|
+
...condition,
|
|
67
|
+
conditions: condition.conditions.map(c => MemoryEntityStorageConnector.normalizeNullToUndefined(c))
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// In the non-group branch, `condition` is the leaf comparator.
|
|
71
|
+
const leaf = condition;
|
|
72
|
+
if ((leaf.comparison === ComparisonOperator.Equals ||
|
|
73
|
+
leaf.comparison === ComparisonOperator.NotEquals) &&
|
|
74
|
+
leaf.value === null) {
|
|
75
|
+
return { ...leaf, value: undefined };
|
|
76
|
+
}
|
|
77
|
+
return { ...leaf };
|
|
78
|
+
}
|
|
56
79
|
/**
|
|
57
80
|
* Returns the class name of the component.
|
|
58
81
|
* @returns The class name of the component.
|
|
@@ -60,6 +83,19 @@ export class MemoryEntityStorageConnector {
|
|
|
60
83
|
className() {
|
|
61
84
|
return MemoryEntityStorageConnector.CLASS_NAME;
|
|
62
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the health status of the component.
|
|
88
|
+
* @returns The health status of the component.
|
|
89
|
+
*/
|
|
90
|
+
async health() {
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
source: MemoryEntityStorageConnector.CLASS_NAME,
|
|
94
|
+
status: HealthStatus.Ok,
|
|
95
|
+
description: "healthDescription"
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
}
|
|
63
99
|
/**
|
|
64
100
|
* Get the schema for the entities.
|
|
65
101
|
* @returns The schema for the entities.
|
|
@@ -120,6 +156,42 @@ export class MemoryEntityStorageConnector {
|
|
|
120
156
|
this._store.push(finalEntity);
|
|
121
157
|
}
|
|
122
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Set multiple entities in a batch.
|
|
161
|
+
* @param entities The entities to set.
|
|
162
|
+
* @returns Nothing.
|
|
163
|
+
*/
|
|
164
|
+
async setBatch(entities) {
|
|
165
|
+
Guards.arrayValue(MemoryEntityStorageConnector.CLASS_NAME, "entities", entities);
|
|
166
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
167
|
+
const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
|
|
168
|
+
for (const entity of entities) {
|
|
169
|
+
EntitySchemaHelper.validateEntity(entity, this.getSchema());
|
|
170
|
+
}
|
|
171
|
+
const indexMap = new Map();
|
|
172
|
+
for (let i = 0; i < this._store.length; i++) {
|
|
173
|
+
const stored = this._store[i];
|
|
174
|
+
const storedPartition = ObjectHelper.propertyGet(stored, MemoryEntityStorageConnector._PARTITION_KEY);
|
|
175
|
+
if (!Is.stringValue(partitionKey) || storedPartition === partitionKey) {
|
|
176
|
+
indexMap.set(stored[this._primaryKey.property], i);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
for (const entity of entities) {
|
|
180
|
+
const finalEntity = ObjectHelper.clone(entity);
|
|
181
|
+
if (Is.stringValue(partitionKey)) {
|
|
182
|
+
ObjectHelper.propertySet(finalEntity, MemoryEntityStorageConnector._PARTITION_KEY, partitionKey);
|
|
183
|
+
}
|
|
184
|
+
const id = finalEntity[this._primaryKey.property];
|
|
185
|
+
const existingIndex = indexMap.get(id);
|
|
186
|
+
if (existingIndex !== undefined) {
|
|
187
|
+
this._store[existingIndex] = finalEntity;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const newIndex = this._store.push(finalEntity) - 1;
|
|
191
|
+
indexMap.set(id, newIndex);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
123
195
|
/**
|
|
124
196
|
* Remove the entity.
|
|
125
197
|
* @param id The id of the entity to remove.
|
|
@@ -168,7 +240,7 @@ export class MemoryEntityStorageConnector {
|
|
|
168
240
|
});
|
|
169
241
|
}
|
|
170
242
|
if (!Is.empty(conditions)) {
|
|
171
|
-
finalConditions.conditions.push(conditions);
|
|
243
|
+
finalConditions.conditions.push(MemoryEntityStorageConnector.normalizeNullToUndefined(conditions));
|
|
172
244
|
}
|
|
173
245
|
const entities = [];
|
|
174
246
|
const finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;
|
|
@@ -197,6 +269,82 @@ export class MemoryEntityStorageConnector {
|
|
|
197
269
|
cursor: nextCursor
|
|
198
270
|
};
|
|
199
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Remove all entities from the storage.
|
|
274
|
+
* @returns Nothing.
|
|
275
|
+
*/
|
|
276
|
+
async empty() {
|
|
277
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
278
|
+
const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
|
|
279
|
+
if (Is.stringValue(partitionKey)) {
|
|
280
|
+
for (let i = this._store.length - 1; i >= 0; i--) {
|
|
281
|
+
if (ObjectHelper.propertyGet(this._store[i], MemoryEntityStorageConnector._PARTITION_KEY) === partitionKey) {
|
|
282
|
+
this._store.splice(i, 1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
this._store.splice(0, this._store.length);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Remove multiple entities by id.
|
|
292
|
+
* @param ids The ids of the entities to remove.
|
|
293
|
+
* @returns Nothing.
|
|
294
|
+
*/
|
|
295
|
+
async removeBatch(ids) {
|
|
296
|
+
Guards.arrayValue(MemoryEntityStorageConnector.CLASS_NAME, "ids", ids);
|
|
297
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
298
|
+
const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
|
|
299
|
+
const finalConditions = [];
|
|
300
|
+
if (Is.stringValue(partitionKey)) {
|
|
301
|
+
finalConditions.push({
|
|
302
|
+
property: MemoryEntityStorageConnector._PARTITION_KEY,
|
|
303
|
+
value: partitionKey
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
for (const id of ids) {
|
|
307
|
+
const index = this.findItem(id, undefined, finalConditions);
|
|
308
|
+
if (index >= 0) {
|
|
309
|
+
this._store.splice(index, 1);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Teardown the storage by clearing the underlying store.
|
|
315
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
316
|
+
* @returns True if the teardown process was successful.
|
|
317
|
+
*/
|
|
318
|
+
async teardown(nodeLoggingComponentType) {
|
|
319
|
+
const nodeLogging = ComponentFactory.getIfExists(nodeLoggingComponentType);
|
|
320
|
+
await nodeLogging?.log({
|
|
321
|
+
level: "info",
|
|
322
|
+
source: MemoryEntityStorageConnector.CLASS_NAME,
|
|
323
|
+
ts: Date.now(),
|
|
324
|
+
message: "storeTearingDown"
|
|
325
|
+
});
|
|
326
|
+
this._store.splice(0, this._store.length);
|
|
327
|
+
await nodeLogging?.log({
|
|
328
|
+
level: "info",
|
|
329
|
+
source: MemoryEntityStorageConnector.CLASS_NAME,
|
|
330
|
+
ts: Date.now(),
|
|
331
|
+
message: "storeTornDown"
|
|
332
|
+
});
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Count all the entities which match the conditions.
|
|
337
|
+
* @returns The total count of entities in the storage.
|
|
338
|
+
*/
|
|
339
|
+
async count() {
|
|
340
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
341
|
+
const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
|
|
342
|
+
if (!Is.stringValue(partitionKey)) {
|
|
343
|
+
return this._store.length;
|
|
344
|
+
}
|
|
345
|
+
return this._store.filter(item => ObjectHelper.propertyGet(item, MemoryEntityStorageConnector._PARTITION_KEY) ===
|
|
346
|
+
partitionKey).length;
|
|
347
|
+
}
|
|
200
348
|
/**
|
|
201
349
|
* Get the memory store.
|
|
202
350
|
* @returns The store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryEntityStorageConnector.js","sourceRoot":"","sources":["../../src/memoryEntityStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EAKf,MAAM,kBAAkB,CAAC;AAK1B;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACxC;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,EAAE,CAAC;IAEpD;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,aAAa,CAAC;IAE/D;;;OAGG;IACc,aAAa,CAAmB;IAEjD;;;OAGG;IACc,oBAAoB,CAAY;IAEjD;;;OAGG;IACc,WAAW,CAA2B;IAEvD;;;OAGG;IACc,MAAM,CAAM;IAE7B;;;OAGG;IACH,YAAY,OAAwD;QACnE,MAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QACjF,MAAM,CAAC,WAAW,CACjB,4BAA4B,CAAC,UAAU,0BAEvC,OAAO,CAAC,YAAY,CACpB,CAAC;QACF,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnE,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,mBAAm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AAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC7C,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;oBAC7E,OAAO,CAAC,CAAC;gBACV,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;IACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, Guards, Is, ObjectHelper } from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\tEntityConditions,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySorter,\n\tLogicalOperator,\n\ttype EntityCondition,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\ttype SortDirection\n} from \"@twin.org/entity\";\nimport type { IEntityStorageConnector } from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMemoryEntityStorageConnectorConstructorOptions } from \"./models/IMemoryEntityStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing entity storage operations in-memory.\n */\nexport class MemoryEntityStorageConnector<T = unknown> implements IEntityStorageConnector<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MemoryEntityStorageConnector>();\n\n\t/**\n\t * Default limit for the number of items to return.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LIMIT: number = 40;\n\n\t/**\n\t * Partition key for the operation.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY: string = \"partitionId\";\n\n\t/**\n\t * The schema for the entity.\n\t * @internal\n\t */\n\tprivate readonly _entitySchema: IEntitySchema<T>;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * The primary key.\n\t * @internal\n\t */\n\tprivate readonly _primaryKey: IEntitySchemaProperty<T>;\n\n\t/**\n\t * The storage for the in-memory items.\n\t * @internal\n\t */\n\tprivate readonly _store: T[];\n\n\t/**\n\t * Create a new instance of MemoryEntityStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMemoryEntityStorageConnectorConstructorOptions) {\n\t\tGuards.object(MemoryEntityStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.stringValue(\n\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.entitySchema),\n\t\t\toptions.entitySchema\n\t\t);\n\t\tthis._entitySchema = EntitySchemaFactory.get(options.entitySchema);\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKey = EntitySchemaHelper.getPrimaryKey<T>(this._entitySchema);\n\t\tthis._store = [];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MemoryEntityStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the schema for the entities.\n\t * @returns The schema for the entities.\n\t */\n\tpublic getSchema(): IEntitySchema {\n\t\treturn this._entitySchema as IEntitySchema;\n\t}\n\n\t/**\n\t * Get an entity.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<T | undefined> {\n\t\tGuards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tconst index = this.findItem(id, secondaryIndex, finalConditions);\n\t\tconst item = index >= 0 ? ObjectHelper.clone(this._store[index]) : undefined;\n\n\t\tif (Is.objectValue(item)) {\n\t\t\tObjectHelper.propertyDelete(item, MemoryEntityStorageConnector._PARTITION_KEY);\n\t\t}\n\n\t\treturn item;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object<T>(MemoryEntityStorageConnector.CLASS_NAME, nameof(entity), entity);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tEntitySchemaHelper.validateEntity(entity, this.getSchema());\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tconst finalEntity = ObjectHelper.clone(entity);\n\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t\tObjectHelper.propertySet(\n\t\t\t\tfinalEntity,\n\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tpartitionKey\n\t\t\t);\n\t\t}\n\n\t\tconst existingIndex = this.findItem(\n\t\t\tfinalEntity[this._primaryKey.property] as string,\n\t\t\tundefined,\n\t\t\tfinalConditions\n\t\t);\n\t\tif (existingIndex >= 0) {\n\t\t\tthis._store[existingIndex] = finalEntity;\n\t\t} else {\n\t\t\tthis._store.push(finalEntity);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tconst index = this.findItem(id, undefined, finalConditions);\n\n\t\tif (index >= 0) {\n\t\t\tthis._store.splice(index, 1);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\tsortProperties?: {\n\t\t\tproperty: keyof T;\n\t\t\tsortDirection: SortDirection;\n\t\t}[],\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<T>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tlet allEntities = this._store.slice();\n\n\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\tconditions: [],\n\t\t\tlogicalOperator: LogicalOperator.And\n\t\t};\n\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.conditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tif (!Is.empty(conditions)) {\n\t\t\tfinalConditions.conditions.push(conditions);\n\t\t}\n\n\t\tconst entities = [];\n\t\tconst finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;\n\t\tlet nextCursor: string | undefined;\n\n\t\tif (allEntities.length > 0) {\n\t\t\tconst finalSortKeys = EntitySchemaHelper.buildSortProperties<T>(\n\t\t\t\tthis._entitySchema,\n\t\t\t\tsortProperties\n\t\t\t);\n\t\t\tallEntities = EntitySorter.sort(allEntities, finalSortKeys);\n\n\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\tfor (let i = startIndex; i < allEntities.length; i++) {\n\t\t\t\tif (\n\t\t\t\t\tEntityConditions.check(allEntities[i], finalConditions) &&\n\t\t\t\t\tentities.length < finalLimit\n\t\t\t\t) {\n\t\t\t\t\tconst entity = ObjectHelper.clone(ObjectHelper.pick(allEntities[i], properties));\n\t\t\t\t\tObjectHelper.propertyDelete(entity, MemoryEntityStorageConnector._PARTITION_KEY);\n\t\t\t\t\tentities.push(entity);\n\t\t\t\t\tif (entities.length >= finalLimit) {\n\t\t\t\t\t\tif (i < allEntities.length - 1) {\n\t\t\t\t\t\t\tnextCursor = (i + 1).toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tentities,\n\t\t\tcursor: nextCursor\n\t\t};\n\t}\n\n\t/**\n\t * Get the memory store.\n\t * @returns The store.\n\t */\n\tpublic getStore(): T[] {\n\t\treturn this._store;\n\t}\n\n\t/**\n\t * Find the item in the store.\n\t * @param id The id to search for.\n\t * @param secondaryIndex The secondary index to search for.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The index of the item if found or -1.\n\t * @internal\n\t */\n\tprivate findItem(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): number {\n\t\tconst finalConditions: EntityCondition<T>[] = [];\n\n\t\tif (!Is.empty(secondaryIndex)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: secondaryIndex as string,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: id\n\t\t\t});\n\t\t}\n\n\t\tif (Is.arrayValue(conditions)) {\n\t\t\t// If we haven't added a secondary index condition we need to add the primary key condition.\n\t\t\tif (finalConditions.length === 0) {\n\t\t\t\tfinalConditions.push({\n\t\t\t\t\tproperty: this._primaryKey.property as string,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: id\n\t\t\t\t});\n\t\t\t}\n\t\t\tfinalConditions.push(\n\t\t\t\t...conditions.map(c => ({\n\t\t\t\t\tproperty: c.property as string,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: c.value\n\t\t\t\t}))\n\t\t\t);\n\t\t}\n\n\t\tif (finalConditions.length > 0) {\n\t\t\tfor (let i = 0; i < this._store.length; i++) {\n\t\t\t\tif (EntityConditions.check(this._store[i], { conditions: finalConditions })) {\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn this._store.findIndex(e => e[this._primaryKey.property] === id);\n\t\t}\n\n\t\treturn -1;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"memoryEntityStorageConnector.js","sourceRoot":"","sources":["../../src/memoryEntityStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,YAAY,EAEZ,EAAE,EACF,YAAY,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EAKf,MAAM,kBAAkB,CAAC;AAM1B;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACxC;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,EAAE,CAAC;IAEpD;;;OAGG;IACK,MAAM,CAAU,cAAc,GAAW,aAAa,CAAC;IAE/D;;;OAGG;IACc,aAAa,CAAmB;IAEjD;;;OAGG;IACc,oBAAoB,CAAY;IAEjD;;;OAGG;IACc,WAAW,CAA2B;IAEvD;;;OAGG;IACc,MAAM,CAAM;IAE7B;;;OAGG;IACH,YAAY,OAAwD;QACnE,MAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QACjF,MAAM,CAAC,WAAW,CACjB,4BAA4B,CAAC,UAAU,0BAEvC,OAAO,CAAC,YAAY,CACpB,CAAC;QACF,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnE,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;QACxD,IAAI,CAAC,WAAW,GA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YACJ,CAAC;YACD,eAAe,CAAC,IAAI,CACnB,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACvB,QAAQ,EAAE,CAAC,CAAC,QAAkB;gBAC9B,UAAU,EAAE,kBAAkB,CAAC,MAAM;gBACrC,KAAK,EAAE,CAAC,CAAC,KAAK;aACd,CAAC,CAAC,CACH,CAAC;QACH,CAAC;QAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC7C,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;oBAC7E,OAAO,CAAC,CAAC;gBACV,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;IACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tCoerce,\n\tComponentFactory,\n\tGuards,\n\tHealthStatus,\n\ttype IHealth,\n\tIs,\n\tObjectHelper\n} from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\tEntityConditions,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySorter,\n\tLogicalOperator,\n\ttype EntityCondition,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\ttype SortDirection\n} from \"@twin.org/entity\";\nimport type { IEntityStorageConnector } from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMemoryEntityStorageConnectorConstructorOptions } from \"./models/IMemoryEntityStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing entity storage operations in-memory.\n */\nexport class MemoryEntityStorageConnector<T = unknown> implements IEntityStorageConnector<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MemoryEntityStorageConnector>();\n\n\t/**\n\t * Default limit for the number of items to return.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LIMIT: number = 40;\n\n\t/**\n\t * Partition key for the operation.\n\t * @internal\n\t */\n\tprivate static readonly _PARTITION_KEY: string = \"partitionId\";\n\n\t/**\n\t * The schema for the entity.\n\t * @internal\n\t */\n\tprivate readonly _entitySchema: IEntitySchema<T>;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * The primary key.\n\t * @internal\n\t */\n\tprivate readonly _primaryKey: IEntitySchemaProperty<T>;\n\n\t/**\n\t * The storage for the in-memory items.\n\t * @internal\n\t */\n\tprivate readonly _store: T[];\n\n\t/**\n\t * Create a new instance of MemoryEntityStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMemoryEntityStorageConnectorConstructorOptions) {\n\t\tGuards.object(MemoryEntityStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.stringValue(\n\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.entitySchema),\n\t\t\toptions.entitySchema\n\t\t);\n\t\tthis._entitySchema = EntitySchemaFactory.get(options.entitySchema);\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKey = EntitySchemaHelper.getPrimaryKey<T>(this._entitySchema);\n\t\tthis._store = [];\n\t}\n\n\t/**\n\t * Deep-clone condition tree and map `null` to `undefined` on Equals/NotEquals leaves\n\t * so in-memory evaluation matches SQL-style \"IS NULL\" / \"IS NOT NULL\" semantics.\n\t * @param condition The user-supplied condition (not mutated).\n\t * @returns A clone safe to pass to {@link EntityConditions.check}.\n\t * @internal\n\t */\n\tprivate static normalizeNullToUndefined<T>(condition: EntityCondition<T>): EntityCondition<T> {\n\t\tif (\"conditions\" in condition) {\n\t\t\treturn {\n\t\t\t\t...condition,\n\t\t\t\tconditions: condition.conditions.map(c =>\n\t\t\t\t\tMemoryEntityStorageConnector.normalizeNullToUndefined(c)\n\t\t\t\t)\n\t\t\t};\n\t\t}\n\n\t\t// In the non-group branch, `condition` is the leaf comparator.\n\t\tconst leaf = condition;\n\t\tif (\n\t\t\t(leaf.comparison === ComparisonOperator.Equals ||\n\t\t\t\tleaf.comparison === ComparisonOperator.NotEquals) &&\n\t\t\tleaf.value === null\n\t\t) {\n\t\t\treturn { ...leaf, value: undefined };\n\t\t}\n\t\treturn { ...leaf };\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MemoryEntityStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component.\n\t */\n\tpublic async health(): Promise<IHealth[]> {\n\t\treturn [\n\t\t\t{\n\t\t\t\tsource: MemoryEntityStorageConnector.CLASS_NAME,\n\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\tdescription: \"healthDescription\"\n\t\t\t}\n\t\t];\n\t}\n\n\t/**\n\t * Get the schema for the entities.\n\t * @returns The schema for the entities.\n\t */\n\tpublic getSchema(): IEntitySchema {\n\t\treturn this._entitySchema as IEntitySchema;\n\t}\n\n\t/**\n\t * Get an entity.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<T | undefined> {\n\t\tGuards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tconst index = this.findItem(id, secondaryIndex, finalConditions);\n\t\tconst item = index >= 0 ? ObjectHelper.clone(this._store[index]) : undefined;\n\n\t\tif (Is.objectValue(item)) {\n\t\t\tObjectHelper.propertyDelete(item, MemoryEntityStorageConnector._PARTITION_KEY);\n\t\t}\n\n\t\treturn item;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object<T>(MemoryEntityStorageConnector.CLASS_NAME, nameof(entity), entity);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tEntitySchemaHelper.validateEntity(entity, this.getSchema());\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tconst finalEntity = ObjectHelper.clone(entity);\n\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t\tObjectHelper.propertySet(\n\t\t\t\tfinalEntity,\n\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tpartitionKey\n\t\t\t);\n\t\t}\n\n\t\tconst existingIndex = this.findItem(\n\t\t\tfinalEntity[this._primaryKey.property] as string,\n\t\t\tundefined,\n\t\t\tfinalConditions\n\t\t);\n\t\tif (existingIndex >= 0) {\n\t\t\tthis._store[existingIndex] = finalEntity;\n\t\t} else {\n\t\t\tthis._store.push(finalEntity);\n\t\t}\n\t}\n\n\t/**\n\t * Set multiple entities in a batch.\n\t * @param entities The entities to set.\n\t * @returns Nothing.\n\t */\n\tpublic async setBatch(entities: T[]): Promise<void> {\n\t\tGuards.arrayValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(entities), entities);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tfor (const entity of entities) {\n\t\t\tEntitySchemaHelper.validateEntity(entity, this.getSchema());\n\t\t}\n\n\t\tconst indexMap = new Map<string, number>();\n\t\tfor (let i = 0; i < this._store.length; i++) {\n\t\t\tconst stored = this._store[i];\n\t\t\tconst storedPartition = ObjectHelper.propertyGet(\n\t\t\t\tstored as object,\n\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t);\n\t\t\tif (!Is.stringValue(partitionKey) || storedPartition === partitionKey) {\n\t\t\t\tindexMap.set(stored[this._primaryKey.property] as string, i);\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of entities) {\n\t\t\tconst finalEntity = ObjectHelper.clone(entity);\n\t\t\tif (Is.stringValue(partitionKey)) {\n\t\t\t\tObjectHelper.propertySet(\n\t\t\t\t\tfinalEntity,\n\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\t\tpartitionKey\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst id = finalEntity[this._primaryKey.property] as string;\n\t\t\tconst existingIndex = indexMap.get(id);\n\t\t\tif (existingIndex !== undefined) {\n\t\t\t\tthis._store[existingIndex] = finalEntity;\n\t\t\t} else {\n\t\t\t\tconst newIndex = this._store.push(finalEntity) - 1;\n\t\t\t\tindexMap.set(id, newIndex);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst finalConditions = conditions ?? [];\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tconst index = this.findItem(id, undefined, finalConditions);\n\n\t\tif (index >= 0) {\n\t\t\tthis._store.splice(index, 1);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\tsortProperties?: {\n\t\t\tproperty: keyof T;\n\t\t\tsortDirection: SortDirection;\n\t\t}[],\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<T>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tlet allEntities = this._store.slice();\n\n\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\tconditions: [],\n\t\t\tlogicalOperator: LogicalOperator.And\n\t\t};\n\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.conditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tif (!Is.empty(conditions)) {\n\t\t\tfinalConditions.conditions.push(\n\t\t\t\tMemoryEntityStorageConnector.normalizeNullToUndefined(conditions)\n\t\t\t);\n\t\t}\n\n\t\tconst entities = [];\n\t\tconst finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;\n\t\tlet nextCursor: string | undefined;\n\n\t\tif (allEntities.length > 0) {\n\t\t\tconst finalSortKeys = EntitySchemaHelper.buildSortProperties<T>(\n\t\t\t\tthis._entitySchema,\n\t\t\t\tsortProperties\n\t\t\t);\n\t\t\tallEntities = EntitySorter.sort(allEntities, finalSortKeys);\n\n\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\tfor (let i = startIndex; i < allEntities.length; i++) {\n\t\t\t\tif (\n\t\t\t\t\tEntityConditions.check(allEntities[i], finalConditions) &&\n\t\t\t\t\tentities.length < finalLimit\n\t\t\t\t) {\n\t\t\t\t\tconst entity = ObjectHelper.clone(ObjectHelper.pick(allEntities[i], properties));\n\t\t\t\t\tObjectHelper.propertyDelete(entity, MemoryEntityStorageConnector._PARTITION_KEY);\n\t\t\t\t\tentities.push(entity);\n\t\t\t\t\tif (entities.length >= finalLimit) {\n\t\t\t\t\t\tif (i < allEntities.length - 1) {\n\t\t\t\t\t\t\tnextCursor = (i + 1).toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tentities,\n\t\t\tcursor: nextCursor\n\t\t};\n\t}\n\n\t/**\n\t * Remove all entities from the storage.\n\t * @returns Nothing.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfor (let i = this._store.length - 1; i >= 0; i--) {\n\t\t\t\tif (\n\t\t\t\t\tObjectHelper.propertyGet(\n\t\t\t\t\t\tthis._store[i] as object,\n\t\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t\t) === partitionKey\n\t\t\t\t) {\n\t\t\t\t\tthis._store.splice(i, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis._store.splice(0, this._store.length);\n\t\t}\n\t}\n\n\t/**\n\t * Remove multiple entities by id.\n\t * @param ids The ids of the entities to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeBatch(ids: string[]): Promise<void> {\n\t\tGuards.arrayValue(MemoryEntityStorageConnector.CLASS_NAME, nameof(ids), ids);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst finalConditions: { property: keyof T; value: unknown }[] = [];\n\t\tif (Is.stringValue(partitionKey)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY as keyof T,\n\t\t\t\tvalue: partitionKey\n\t\t\t});\n\t\t}\n\n\t\tfor (const id of ids) {\n\t\t\tconst index = this.findItem(id, undefined, finalConditions);\n\t\t\tif (index >= 0) {\n\t\t\t\tthis._store.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Teardown the storage by clearing the underlying store.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the teardown process was successful.\n\t */\n\tpublic async teardown(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\tawait nodeLogging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: MemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"storeTearingDown\"\n\t\t});\n\n\t\tthis._store.splice(0, this._store.length);\n\n\t\tawait nodeLogging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: MemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"storeTornDown\"\n\t\t});\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Count all the entities which match the conditions.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(): Promise<number> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (!Is.stringValue(partitionKey)) {\n\t\t\treturn this._store.length;\n\t\t}\n\n\t\treturn this._store.filter(\n\t\t\titem =>\n\t\t\t\tObjectHelper.propertyGet(item as object, MemoryEntityStorageConnector._PARTITION_KEY) ===\n\t\t\t\tpartitionKey\n\t\t).length;\n\t}\n\n\t/**\n\t * Get the memory store.\n\t * @returns The store.\n\t */\n\tpublic getStore(): T[] {\n\t\treturn this._store;\n\t}\n\n\t/**\n\t * Find the item in the store.\n\t * @param id The id to search for.\n\t * @param secondaryIndex The secondary index to search for.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The index of the item if found or -1.\n\t * @internal\n\t */\n\tprivate findItem(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): number {\n\t\tconst finalConditions: EntityCondition<T>[] = [];\n\n\t\tif (!Is.empty(secondaryIndex)) {\n\t\t\tfinalConditions.push({\n\t\t\t\tproperty: secondaryIndex as string,\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: id\n\t\t\t});\n\t\t}\n\n\t\tif (Is.arrayValue(conditions)) {\n\t\t\t// If we haven't added a secondary index condition we need to add the primary key condition.\n\t\t\tif (finalConditions.length === 0) {\n\t\t\t\tfinalConditions.push({\n\t\t\t\t\tproperty: this._primaryKey.property as string,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: id\n\t\t\t\t});\n\t\t\t}\n\t\t\tfinalConditions.push(\n\t\t\t\t...conditions.map(c => ({\n\t\t\t\t\tproperty: c.property as string,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: c.value\n\t\t\t\t}))\n\t\t\t);\n\t\t}\n\n\t\tif (finalConditions.length > 0) {\n\t\t\tfor (let i = 0; i < this._store.length; i++) {\n\t\t\t\tif (EntityConditions.check(this._store[i], { conditions: finalConditions })) {\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn this._store.findIndex(e => e[this._primaryKey.property] === id);\n\t\t}\n\n\t\treturn -1;\n\t}\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type IHealth } from "@twin.org/core";
|
|
1
2
|
import { type EntityCondition, type IEntitySchema, type SortDirection } from "@twin.org/entity";
|
|
2
3
|
import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
|
|
3
4
|
import type { IMemoryEntityStorageConnectorConstructorOptions } from "./models/IMemoryEntityStorageConnectorConstructorOptions.js";
|
|
@@ -19,6 +20,11 @@ export declare class MemoryEntityStorageConnector<T = unknown> implements IEntit
|
|
|
19
20
|
* @returns The class name of the component.
|
|
20
21
|
*/
|
|
21
22
|
className(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the health status of the component.
|
|
25
|
+
* @returns The health status of the component.
|
|
26
|
+
*/
|
|
27
|
+
health(): Promise<IHealth[]>;
|
|
22
28
|
/**
|
|
23
29
|
* Get the schema for the entities.
|
|
24
30
|
* @returns The schema for the entities.
|
|
@@ -45,6 +51,12 @@ export declare class MemoryEntityStorageConnector<T = unknown> implements IEntit
|
|
|
45
51
|
property: keyof T;
|
|
46
52
|
value: unknown;
|
|
47
53
|
}[]): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Set multiple entities in a batch.
|
|
56
|
+
* @param entities The entities to set.
|
|
57
|
+
* @returns Nothing.
|
|
58
|
+
*/
|
|
59
|
+
setBatch(entities: T[]): Promise<void>;
|
|
48
60
|
/**
|
|
49
61
|
* Remove the entity.
|
|
50
62
|
* @param id The id of the entity to remove.
|
|
@@ -78,6 +90,28 @@ export declare class MemoryEntityStorageConnector<T = unknown> implements IEntit
|
|
|
78
90
|
*/
|
|
79
91
|
cursor?: string;
|
|
80
92
|
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Remove all entities from the storage.
|
|
95
|
+
* @returns Nothing.
|
|
96
|
+
*/
|
|
97
|
+
empty(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Remove multiple entities by id.
|
|
100
|
+
* @param ids The ids of the entities to remove.
|
|
101
|
+
* @returns Nothing.
|
|
102
|
+
*/
|
|
103
|
+
removeBatch(ids: string[]): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Teardown the storage by clearing the underlying store.
|
|
106
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
107
|
+
* @returns True if the teardown process was successful.
|
|
108
|
+
*/
|
|
109
|
+
teardown(nodeLoggingComponentType?: string): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Count all the entities which match the conditions.
|
|
112
|
+
* @returns The total count of entities in the storage.
|
|
113
|
+
*/
|
|
114
|
+
count(): Promise<number>;
|
|
81
115
|
/**
|
|
82
116
|
* Get the memory store.
|
|
83
117
|
* @returns The store.
|
package/docs/changelog.md
CHANGED
|
@@ -1,22 +1,148 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.0.3-next.
|
|
3
|
+
## [0.0.3-next.10](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.9...entity-storage-connector-memory-v0.0.3-next.10) (2026-05-07)
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
### Features
|
|
7
7
|
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* entity storage enhancements ([#86](https://github.com/iotaledger/twin-entity-storage/issues/86)) ([1279af4](https://github.com/iotaledger/twin-entity-storage/commit/1279af42615c6497bb06539842cee44842dd1f75))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.9 to 0.0.3-next.10
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.9](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.8...entity-storage-connector-memory-v0.0.3-next.9) (2026-04-22)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* **entity-storage-connector-memory:** Synchronize repo versions
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
30
|
+
|
|
31
|
+
## [0.0.3-next.8](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.7...entity-storage-connector-memory-v0.0.3-next.8) (2026-03-20)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* tests and fixes for the comparisons for null and undefined ([#79](https://github.com/iotaledger/twin-entity-storage/issues/79)) ([e7ffd62](https://github.com/iotaledger/twin-entity-storage/commit/e7ffd62e9ec40ef31498e6e2350bb25d9c84638a))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
44
|
+
|
|
45
|
+
## [0.0.3-next.7](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.6...entity-storage-connector-memory-v0.0.3-next.7) (2026-03-13)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* adding tests and fixes for dot notation ([#76](https://github.com/iotaledger/twin-entity-storage/issues/76)) ([3879337](https://github.com/iotaledger/twin-entity-storage/commit/387933797e33543e4d8b2d49b8beeb792512a4ff))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Dependencies
|
|
54
|
+
|
|
55
|
+
* The following workspace dependencies were updated
|
|
56
|
+
* dependencies
|
|
57
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
58
|
+
|
|
59
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.5...entity-storage-connector-memory-v0.0.3-next.6) (2026-01-21)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Bug Fixes
|
|
63
|
+
|
|
64
|
+
* adding tests and support when neccesary for string include operator when needed ([#72](https://github.com/iotaledger/twin-entity-storage/issues/72)) ([3c723dd](https://github.com/iotaledger/twin-entity-storage/commit/3c723dd5694814398099d9d4594089dc6c66ba97))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* The following workspace dependencies were updated
|
|
70
|
+
* dependencies
|
|
71
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
72
|
+
|
|
73
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.4...entity-storage-connector-memory-v0.0.3-next.5) (2026-01-06)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Miscellaneous Chores
|
|
77
|
+
|
|
78
|
+
* **entity-storage-connector-memory:** Synchronize repo versions
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Dependencies
|
|
82
|
+
|
|
83
|
+
* The following workspace dependencies were updated
|
|
84
|
+
* dependencies
|
|
85
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
86
|
+
|
|
87
|
+
## [0.0.3-next.4](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.3...entity-storage-connector-memory-v0.0.3-next.4) (2025-12-03)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Miscellaneous Chores
|
|
91
|
+
|
|
92
|
+
* **entity-storage-connector-memory:** Synchronize repo versions
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Dependencies
|
|
96
|
+
|
|
97
|
+
* The following workspace dependencies were updated
|
|
98
|
+
* dependencies
|
|
99
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.3 to 0.0.3-next.4
|
|
100
|
+
|
|
101
|
+
## [0.0.3-next.3](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.2...entity-storage-connector-memory-v0.0.3-next.3) (2025-11-26)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Features
|
|
105
|
+
|
|
106
|
+
* add support for object comparison conditions ([eb505a1](https://github.com/iotaledger/twin-entity-storage/commit/eb505a17a3642e95c4e3cf137a77a0a8fb388c97))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Dependencies
|
|
110
|
+
|
|
111
|
+
* The following workspace dependencies were updated
|
|
112
|
+
* dependencies
|
|
113
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
114
|
+
|
|
115
|
+
## [0.0.3-next.2](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.1...entity-storage-connector-memory-v0.0.3-next.2) (2025-11-13)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Miscellaneous Chores
|
|
119
|
+
|
|
120
|
+
* **entity-storage-connector-memory:** Synchronize repo versions
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Dependencies
|
|
124
|
+
|
|
125
|
+
* The following workspace dependencies were updated
|
|
126
|
+
* dependencies
|
|
127
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
128
|
+
|
|
129
|
+
## [0.0.3-next.1](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.0...entity-storage-connector-memory-v0.0.3-next.1) (2025-11-10)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
|
|
134
|
+
* add context id features ([#55](https://github.com/iotaledger/twin-entity-storage/issues/55)) ([99c15a2](https://github.com/iotaledger/twin-entity-storage/commit/99c15a257539b61d9da63649ce573ebf47699fc9))
|
|
135
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
136
|
+
* add validate-locales ([e66ef0d](https://github.com/iotaledger/twin-entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
|
|
137
|
+
* eslint migration to flat config ([f033b64](https://github.com/iotaledger/twin-entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
|
|
138
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
139
|
+
* update framework core ([b59a380](https://github.com/iotaledger/twin-entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
|
|
140
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
15
141
|
|
|
16
142
|
|
|
17
143
|
### Bug Fixes
|
|
18
144
|
|
|
19
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
145
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
20
146
|
|
|
21
147
|
|
|
22
148
|
### Dependencies
|
|
@@ -25,12 +151,12 @@
|
|
|
25
151
|
* dependencies
|
|
26
152
|
* @twin.org/entity-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
27
153
|
|
|
28
|
-
## [0.0.2-next.10](https://github.com/
|
|
154
|
+
## [0.0.2-next.10](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.9...entity-storage-connector-memory-v0.0.2-next.10) (2025-10-09)
|
|
29
155
|
|
|
30
156
|
|
|
31
157
|
### Features
|
|
32
158
|
|
|
33
|
-
* add validate-locales ([e66ef0d](https://github.com/
|
|
159
|
+
* add validate-locales ([e66ef0d](https://github.com/iotaledger/twin-entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
|
|
34
160
|
|
|
35
161
|
|
|
36
162
|
### Dependencies
|
|
@@ -39,7 +165,7 @@
|
|
|
39
165
|
* dependencies
|
|
40
166
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
41
167
|
|
|
42
|
-
## [0.0.2-next.9](https://github.com/
|
|
168
|
+
## [0.0.2-next.9](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.8...entity-storage-connector-memory-v0.0.2-next.9) (2025-10-02)
|
|
43
169
|
|
|
44
170
|
|
|
45
171
|
### Miscellaneous Chores
|
|
@@ -53,12 +179,12 @@
|
|
|
53
179
|
* dependencies
|
|
54
180
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
55
181
|
|
|
56
|
-
## [0.0.2-next.8](https://github.com/
|
|
182
|
+
## [0.0.2-next.8](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.7...entity-storage-connector-memory-v0.0.2-next.8) (2025-08-29)
|
|
57
183
|
|
|
58
184
|
|
|
59
185
|
### Features
|
|
60
186
|
|
|
61
|
-
* eslint migration to flat config ([f033b64](https://github.com/
|
|
187
|
+
* eslint migration to flat config ([f033b64](https://github.com/iotaledger/twin-entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
|
|
62
188
|
|
|
63
189
|
|
|
64
190
|
### Dependencies
|
|
@@ -67,7 +193,7 @@
|
|
|
67
193
|
* dependencies
|
|
68
194
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
69
195
|
|
|
70
|
-
## [0.0.2-next.7](https://github.com/
|
|
196
|
+
## [0.0.2-next.7](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.6...entity-storage-connector-memory-v0.0.2-next.7) (2025-08-20)
|
|
71
197
|
|
|
72
198
|
|
|
73
199
|
### Miscellaneous Chores
|
|
@@ -81,12 +207,12 @@
|
|
|
81
207
|
* dependencies
|
|
82
208
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
83
209
|
|
|
84
|
-
## [0.0.2-next.6](https://github.com/
|
|
210
|
+
## [0.0.2-next.6](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.5...entity-storage-connector-memory-v0.0.2-next.6) (2025-08-19)
|
|
85
211
|
|
|
86
212
|
|
|
87
213
|
### Features
|
|
88
214
|
|
|
89
|
-
* update framework core ([b59a380](https://github.com/
|
|
215
|
+
* update framework core ([b59a380](https://github.com/iotaledger/twin-entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
|
|
90
216
|
|
|
91
217
|
|
|
92
218
|
### Dependencies
|
|
@@ -95,7 +221,7 @@
|
|
|
95
221
|
* dependencies
|
|
96
222
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
97
223
|
|
|
98
|
-
## [0.0.2-next.5](https://github.com/
|
|
224
|
+
## [0.0.2-next.5](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.4...entity-storage-connector-memory-v0.0.2-next.5) (2025-08-11)
|
|
99
225
|
|
|
100
226
|
|
|
101
227
|
### Miscellaneous Chores
|
|
@@ -109,7 +235,7 @@
|
|
|
109
235
|
* dependencies
|
|
110
236
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
111
237
|
|
|
112
|
-
## [0.0.2-next.4](https://github.com/
|
|
238
|
+
## [0.0.2-next.4](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.3...entity-storage-connector-memory-v0.0.2-next.4) (2025-08-08)
|
|
113
239
|
|
|
114
240
|
|
|
115
241
|
### Miscellaneous Chores
|
|
@@ -123,7 +249,7 @@
|
|
|
123
249
|
* dependencies
|
|
124
250
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
125
251
|
|
|
126
|
-
## [0.0.2-next.3](https://github.com/
|
|
252
|
+
## [0.0.2-next.3](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.2...entity-storage-connector-memory-v0.0.2-next.3) (2025-07-25)
|
|
127
253
|
|
|
128
254
|
|
|
129
255
|
### Miscellaneous Chores
|
|
@@ -137,7 +263,7 @@
|
|
|
137
263
|
* dependencies
|
|
138
264
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
139
265
|
|
|
140
|
-
## [0.0.2-next.2](https://github.com/
|
|
266
|
+
## [0.0.2-next.2](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.1...entity-storage-connector-memory-v0.0.2-next.2) (2025-07-24)
|
|
141
267
|
|
|
142
268
|
|
|
143
269
|
### Miscellaneous Chores
|
|
@@ -151,19 +277,19 @@
|
|
|
151
277
|
* dependencies
|
|
152
278
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
153
279
|
|
|
154
|
-
## [0.0.2-next.1](https://github.com/
|
|
280
|
+
## [0.0.2-next.1](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.0...entity-storage-connector-memory-v0.0.2-next.1) (2025-07-17)
|
|
155
281
|
|
|
156
282
|
|
|
157
283
|
### Features
|
|
158
284
|
|
|
159
|
-
* add production release automation ([1eb4c8e](https://github.com/
|
|
160
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
161
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
285
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
286
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
287
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
162
288
|
|
|
163
289
|
|
|
164
290
|
### Bug Fixes
|
|
165
291
|
|
|
166
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
292
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
167
293
|
|
|
168
294
|
|
|
169
295
|
### Dependencies
|
|
@@ -177,15 +303,15 @@
|
|
|
177
303
|
|
|
178
304
|
### Features
|
|
179
305
|
|
|
180
|
-
* add production release automation ([1eb4c8e](https://github.com/
|
|
181
|
-
* release to production ([a309051](https://github.com/
|
|
182
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
183
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
306
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
307
|
+
* release to production ([a309051](https://github.com/iotaledger/twin-entity-storage/commit/a3090519adebf7943232b4df12e4c6bd5afe7eed))
|
|
308
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
309
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
184
310
|
|
|
185
311
|
|
|
186
312
|
### Bug Fixes
|
|
187
313
|
|
|
188
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
314
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
189
315
|
|
|
190
316
|
|
|
191
317
|
### Dependencies
|
|
@@ -194,12 +320,12 @@
|
|
|
194
320
|
* dependencies
|
|
195
321
|
* @twin.org/entity-storage-models bumped from ^0.0.0 to ^0.0.1
|
|
196
322
|
|
|
197
|
-
## [0.0.1-next.31](https://github.com/
|
|
323
|
+
## [0.0.1-next.31](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.1-next.30...entity-storage-connector-memory-v0.0.1-next.31) (2025-06-20)
|
|
198
324
|
|
|
199
325
|
|
|
200
326
|
### Bug Fixes
|
|
201
327
|
|
|
202
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
328
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
203
329
|
|
|
204
330
|
|
|
205
331
|
### Dependencies
|
|
@@ -208,12 +334,12 @@
|
|
|
208
334
|
* dependencies
|
|
209
335
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
210
336
|
|
|
211
|
-
## [0.0.1-next.30](https://github.com/
|
|
337
|
+
## [0.0.1-next.30](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.1-next.29...entity-storage-connector-memory-v0.0.1-next.30) (2025-06-12)
|
|
212
338
|
|
|
213
339
|
|
|
214
340
|
### Features
|
|
215
341
|
|
|
216
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
342
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
217
343
|
|
|
218
344
|
|
|
219
345
|
### Dependencies
|
|
@@ -222,12 +348,12 @@
|
|
|
222
348
|
* dependencies
|
|
223
349
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
224
350
|
|
|
225
|
-
## [0.0.1-next.29](https://github.com/
|
|
351
|
+
## [0.0.1-next.29](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.1-next.28...entity-storage-connector-memory-v0.0.1-next.29) (2025-04-17)
|
|
226
352
|
|
|
227
353
|
|
|
228
354
|
### Features
|
|
229
355
|
|
|
230
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
356
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
231
357
|
|
|
232
358
|
|
|
233
359
|
### Dependencies
|
|
@@ -236,7 +362,7 @@
|
|
|
236
362
|
* dependencies
|
|
237
363
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
|
|
238
364
|
|
|
239
|
-
## [0.0.1-next.28](https://github.com/
|
|
365
|
+
## [0.0.1-next.28](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.1-next.27...entity-storage-connector-memory-v0.0.1-next.28) (2025-04-09)
|
|
240
366
|
|
|
241
367
|
|
|
242
368
|
### Miscellaneous Chores
|
|
@@ -250,7 +376,7 @@
|
|
|
250
376
|
* dependencies
|
|
251
377
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.27 to 0.0.1-next.28
|
|
252
378
|
|
|
253
|
-
## [0.0.1-next.27](https://github.com/
|
|
379
|
+
## [0.0.1-next.27](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.1-next.26...entity-storage-connector-memory-v0.0.1-next.27) (2025-03-28)
|
|
254
380
|
|
|
255
381
|
|
|
256
382
|
### Miscellaneous Chores
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage Connector Memory Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to perform fast in-memory storage operations during development and unit testing.
|
|
4
|
+
|
|
5
|
+
## MemoryEntityStorageConnector
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
9
|
+
import {
|
|
10
|
+
ComparisonOperator,
|
|
11
|
+
LogicalOperator,
|
|
12
|
+
SortDirection,
|
|
13
|
+
type EntityCondition
|
|
14
|
+
} from '@twin.org/entity';
|
|
15
|
+
|
|
16
|
+
interface Profile {
|
|
17
|
+
id: string;
|
|
18
|
+
email: string;
|
|
19
|
+
status: 'active' | 'inactive';
|
|
20
|
+
createdAt: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const connector = new MemoryEntityStorageConnector<Profile>({
|
|
24
|
+
entitySchema: 'Profile',
|
|
25
|
+
partitionContextIds: ['tenantId']
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const className = connector.className();
|
|
29
|
+
const schema = connector.getSchema();
|
|
30
|
+
|
|
31
|
+
await connector.set({
|
|
32
|
+
id: 'profile-1',
|
|
33
|
+
email: 'ada@example.com',
|
|
34
|
+
status: 'active',
|
|
35
|
+
createdAt: '2026-03-09T10:30:00.000Z'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const byPrimaryKey = await connector.get('profile-1');
|
|
39
|
+
const bySecondaryIndex = await connector.get('ada@example.com', 'email');
|
|
40
|
+
|
|
41
|
+
const activeCondition: EntityCondition<Profile> = {
|
|
42
|
+
logicalOperator: LogicalOperator.And,
|
|
43
|
+
conditions: [
|
|
44
|
+
{
|
|
45
|
+
property: 'status',
|
|
46
|
+
comparison: ComparisonOperator.Equals,
|
|
47
|
+
value: 'active'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = await connector.query(
|
|
53
|
+
activeCondition,
|
|
54
|
+
[{ property: 'createdAt', sortDirection: SortDirection.Descending }],
|
|
55
|
+
['id', 'email', 'status'],
|
|
56
|
+
undefined,
|
|
57
|
+
25
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
await connector.remove('profile-1');
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
65
|
+
|
|
66
|
+
interface Profile {
|
|
67
|
+
id: string;
|
|
68
|
+
email: string;
|
|
69
|
+
status: 'active' | 'inactive';
|
|
70
|
+
createdAt: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const connector = new MemoryEntityStorageConnector<Profile>({
|
|
74
|
+
entitySchema: 'Profile'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const store = connector.getStore();
|
|
78
|
+
```
|
|
@@ -34,7 +34,7 @@ The options for the connector.
|
|
|
34
34
|
|
|
35
35
|
## Properties
|
|
36
36
|
|
|
37
|
-
### CLASS\_NAME
|
|
37
|
+
### CLASS\_NAME {#class_name}
|
|
38
38
|
|
|
39
39
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ Runtime name for the class.
|
|
|
42
42
|
|
|
43
43
|
## Methods
|
|
44
44
|
|
|
45
|
-
### className()
|
|
45
|
+
### className() {#classname}
|
|
46
46
|
|
|
47
47
|
> **className**(): `string`
|
|
48
48
|
|
|
@@ -60,7 +60,25 @@ The class name of the component.
|
|
|
60
60
|
|
|
61
61
|
***
|
|
62
62
|
|
|
63
|
-
###
|
|
63
|
+
### health() {#health}
|
|
64
|
+
|
|
65
|
+
> **health**(): `Promise`\<`IHealth`[]\>
|
|
66
|
+
|
|
67
|
+
Returns the health status of the component.
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`Promise`\<`IHealth`[]\>
|
|
72
|
+
|
|
73
|
+
The health status of the component.
|
|
74
|
+
|
|
75
|
+
#### Implementation of
|
|
76
|
+
|
|
77
|
+
`IEntityStorageConnector.health`
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### getSchema() {#getschema}
|
|
64
82
|
|
|
65
83
|
> **getSchema**(): `IEntitySchema`
|
|
66
84
|
|
|
@@ -78,7 +96,7 @@ The schema for the entities.
|
|
|
78
96
|
|
|
79
97
|
***
|
|
80
98
|
|
|
81
|
-
### get()
|
|
99
|
+
### get() {#get}
|
|
82
100
|
|
|
83
101
|
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
|
|
84
102
|
|
|
@@ -116,7 +134,7 @@ The object if it can be found or undefined.
|
|
|
116
134
|
|
|
117
135
|
***
|
|
118
136
|
|
|
119
|
-
### set()
|
|
137
|
+
### set() {#set}
|
|
120
138
|
|
|
121
139
|
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
122
140
|
|
|
@@ -148,7 +166,33 @@ The id of the entity.
|
|
|
148
166
|
|
|
149
167
|
***
|
|
150
168
|
|
|
151
|
-
###
|
|
169
|
+
### setBatch() {#setbatch}
|
|
170
|
+
|
|
171
|
+
> **setBatch**(`entities`): `Promise`\<`void`\>
|
|
172
|
+
|
|
173
|
+
Set multiple entities in a batch.
|
|
174
|
+
|
|
175
|
+
#### Parameters
|
|
176
|
+
|
|
177
|
+
##### entities
|
|
178
|
+
|
|
179
|
+
`T`[]
|
|
180
|
+
|
|
181
|
+
The entities to set.
|
|
182
|
+
|
|
183
|
+
#### Returns
|
|
184
|
+
|
|
185
|
+
`Promise`\<`void`\>
|
|
186
|
+
|
|
187
|
+
Nothing.
|
|
188
|
+
|
|
189
|
+
#### Implementation of
|
|
190
|
+
|
|
191
|
+
`IEntityStorageConnector.setBatch`
|
|
192
|
+
|
|
193
|
+
***
|
|
194
|
+
|
|
195
|
+
### remove() {#remove}
|
|
152
196
|
|
|
153
197
|
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
154
198
|
|
|
@@ -180,7 +224,7 @@ Nothing.
|
|
|
180
224
|
|
|
181
225
|
***
|
|
182
226
|
|
|
183
|
-
### query()
|
|
227
|
+
### query() {#query}
|
|
184
228
|
|
|
185
229
|
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
186
230
|
|
|
@@ -231,7 +275,95 @@ and a cursor which can be used to request more entities.
|
|
|
231
275
|
|
|
232
276
|
***
|
|
233
277
|
|
|
234
|
-
###
|
|
278
|
+
### empty() {#empty}
|
|
279
|
+
|
|
280
|
+
> **empty**(): `Promise`\<`void`\>
|
|
281
|
+
|
|
282
|
+
Remove all entities from the storage.
|
|
283
|
+
|
|
284
|
+
#### Returns
|
|
285
|
+
|
|
286
|
+
`Promise`\<`void`\>
|
|
287
|
+
|
|
288
|
+
Nothing.
|
|
289
|
+
|
|
290
|
+
#### Implementation of
|
|
291
|
+
|
|
292
|
+
`IEntityStorageConnector.empty`
|
|
293
|
+
|
|
294
|
+
***
|
|
295
|
+
|
|
296
|
+
### removeBatch() {#removebatch}
|
|
297
|
+
|
|
298
|
+
> **removeBatch**(`ids`): `Promise`\<`void`\>
|
|
299
|
+
|
|
300
|
+
Remove multiple entities by id.
|
|
301
|
+
|
|
302
|
+
#### Parameters
|
|
303
|
+
|
|
304
|
+
##### ids
|
|
305
|
+
|
|
306
|
+
`string`[]
|
|
307
|
+
|
|
308
|
+
The ids of the entities to remove.
|
|
309
|
+
|
|
310
|
+
#### Returns
|
|
311
|
+
|
|
312
|
+
`Promise`\<`void`\>
|
|
313
|
+
|
|
314
|
+
Nothing.
|
|
315
|
+
|
|
316
|
+
#### Implementation of
|
|
317
|
+
|
|
318
|
+
`IEntityStorageConnector.removeBatch`
|
|
319
|
+
|
|
320
|
+
***
|
|
321
|
+
|
|
322
|
+
### teardown() {#teardown}
|
|
323
|
+
|
|
324
|
+
> **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
325
|
+
|
|
326
|
+
Teardown the storage by clearing the underlying store.
|
|
327
|
+
|
|
328
|
+
#### Parameters
|
|
329
|
+
|
|
330
|
+
##### nodeLoggingComponentType?
|
|
331
|
+
|
|
332
|
+
`string`
|
|
333
|
+
|
|
334
|
+
The node logging component type.
|
|
335
|
+
|
|
336
|
+
#### Returns
|
|
337
|
+
|
|
338
|
+
`Promise`\<`boolean`\>
|
|
339
|
+
|
|
340
|
+
True if the teardown process was successful.
|
|
341
|
+
|
|
342
|
+
#### Implementation of
|
|
343
|
+
|
|
344
|
+
`IEntityStorageConnector.teardown`
|
|
345
|
+
|
|
346
|
+
***
|
|
347
|
+
|
|
348
|
+
### count() {#count}
|
|
349
|
+
|
|
350
|
+
> **count**(): `Promise`\<`number`\>
|
|
351
|
+
|
|
352
|
+
Count all the entities which match the conditions.
|
|
353
|
+
|
|
354
|
+
#### Returns
|
|
355
|
+
|
|
356
|
+
`Promise`\<`number`\>
|
|
357
|
+
|
|
358
|
+
The total count of entities in the storage.
|
|
359
|
+
|
|
360
|
+
#### Implementation of
|
|
361
|
+
|
|
362
|
+
`IEntityStorageConnector.count`
|
|
363
|
+
|
|
364
|
+
***
|
|
365
|
+
|
|
366
|
+
### getStore() {#getstore}
|
|
235
367
|
|
|
236
368
|
> **getStore**(): `T`[]
|
|
237
369
|
|
|
@@ -4,7 +4,7 @@ Options for the Memory Entity Storage Connector constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### entitySchema
|
|
7
|
+
### entitySchema {#entityschema}
|
|
8
8
|
|
|
9
9
|
> **entitySchema**: `string`
|
|
10
10
|
|
|
@@ -12,8 +12,8 @@ The schema for the entity.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### partitionContextIds?
|
|
15
|
+
### partitionContextIds? {#partitioncontextids}
|
|
16
16
|
|
|
17
|
-
> `optional` **partitionContextIds
|
|
17
|
+
> `optional` **partitionContextIds?**: `string`[]
|
|
18
18
|
|
|
19
19
|
The keys to use from the context ids to create partitions.
|
package/locales/en.json
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"info": {
|
|
3
|
+
"memoryEntityStorageConnector": {
|
|
4
|
+
"storeTearingDown": "Tearing down entity storage",
|
|
5
|
+
"storeTornDown": "Entity storage torn down"
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
"health": {
|
|
9
|
+
"memoryEntityStorageConnector": {
|
|
10
|
+
"healthDescription": "Memory entity storage is always available"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-memory",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.10",
|
|
4
|
+
"description": "In-memory connector for local development, testing and short-lived workloads.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/entity-storage.git",
|
|
8
8
|
"directory": "packages/entity-storage-connector-memory"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"@twin.org/context": "next",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
|
-
"@twin.org/entity-storage-models": "0.0.3-next.
|
|
20
|
+
"@twin.org/entity-storage-models": "0.0.3-next.10",
|
|
21
|
+
"@twin.org/logging-models": "next",
|
|
21
22
|
"@twin.org/nameof": "next"
|
|
22
23
|
},
|
|
23
24
|
"main": "./dist/es/index.js",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"testing"
|
|
56
57
|
],
|
|
57
58
|
"bugs": {
|
|
58
|
-
"url": "git+https://github.com/
|
|
59
|
+
"url": "git+https://github.com/iotaledger/entity-storage/issues"
|
|
59
60
|
},
|
|
60
61
|
"homepage": "https://twindev.org"
|
|
61
62
|
}
|