@twin.org/entity-storage-connector-memory 0.0.3-next.30 → 0.0.3-next.32

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/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2026 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  export * from "./memoryEntityStorageConnector.js";
4
+ export * from "./models/IMemoryEntityStorageConnectorConfig.js";
4
5
  export * from "./models/IMemoryEntityStorageConnectorConstructorOptions.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6DAA6D,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./memoryEntityStorageConnector.js\";\nexport * from \"./models/IMemoryEntityStorageConnectorConstructorOptions.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iDAAiD,CAAC;AAChE,cAAc,6DAA6D,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./memoryEntityStorageConnector.js\";\nexport * from \"./models/IMemoryEntityStorageConnectorConfig.js\";\nexport * from \"./models/IMemoryEntityStorageConnectorConstructorOptions.js\";\n"]}
@@ -46,11 +46,10 @@ export class MemoryEntityStorageConnector {
46
46
  */
47
47
  _primaryKey;
48
48
  /**
49
- * The resolved schema name used as the shared buffer and lock key.
50
- * Stored separately so it is always a plain string rather than string | undefined.
49
+ * The resolved storage key used as the shared buffer and lock key.
51
50
  * @internal
52
51
  */
53
- _schemaName;
52
+ _storageKey;
54
53
  /**
55
54
  * Initial capacity hint in bytes for the shared entity buffer.
56
55
  * @internal
@@ -68,12 +67,14 @@ export class MemoryEntityStorageConnector {
68
67
  constructor(options) {
69
68
  Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "options", options);
70
69
  Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "options.entitySchema", options.entitySchema);
70
+ Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "options.config", options.config);
71
+ Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "options.config.storageKey", options.config.storageKey);
71
72
  this._entitySchema = EntitySchemaFactory.get(options.entitySchema);
72
- this._schemaName = this._entitySchema.type ?? options.entitySchema;
73
+ this._storageKey = options.config.storageKey;
73
74
  this._partitionContextIds = options.partitionContextIds;
74
75
  this._primaryKey = EntitySchemaHelper.getPrimaryKey(this._entitySchema);
75
- this._initialCapacityBytes = options.initialCapacityBytes;
76
- this._maxCapacityBytes = options.maxCapacityBytes;
76
+ this._initialCapacityBytes = options.config?.initialCapacityBytes;
77
+ this._maxCapacityBytes = options.config?.maxCapacityBytes;
77
78
  }
78
79
  /**
79
80
  * Returns the class name of the component.
@@ -92,7 +93,7 @@ export class MemoryEntityStorageConnector {
92
93
  source: MemoryEntityStorageConnector.CLASS_NAME,
93
94
  status: HealthStatus.Ok,
94
95
  description: "healthDescription",
95
- data: { entityType: this._schemaName }
96
+ data: { entityType: this._storageKey }
96
97
  }
97
98
  ];
98
99
  }
@@ -109,7 +110,7 @@ export class MemoryEntityStorageConnector {
109
110
  * @returns True if the bootstrapping process was successful.
110
111
  */
111
112
  async bootstrap(nodeLoggingComponentType) {
112
- await SharedObjectBuffer.create(this._schemaName, {
113
+ await SharedObjectBuffer.create(this._storageKey, {
113
114
  initialCapacityBytes: this._initialCapacityBytes,
114
115
  maxCapacityBytes: this._maxCapacityBytes
115
116
  });
@@ -356,12 +357,12 @@ export class MemoryEntityStorageConnector {
356
357
  ts: Date.now(),
357
358
  message: "storeTearingDown"
358
359
  });
359
- await Mutex.lock(this._schemaName, { throwOnTimeout: true });
360
+ await Mutex.lock(this._storageKey, { throwOnTimeout: true });
360
361
  try {
361
- SharedObjectBuffer.remove(this._schemaName);
362
+ SharedObjectBuffer.remove(this._storageKey);
362
363
  }
363
364
  finally {
364
- Mutex.unlock(this._schemaName);
365
+ Mutex.unlock(this._storageKey);
365
366
  }
366
367
  await nodeLogging?.log({
367
368
  level: "info",
@@ -433,13 +434,13 @@ export class MemoryEntityStorageConnector {
433
434
  * @returns Connector for performing the migration.
434
435
  */
435
436
  async createTargetConnector(newEntitySchema) {
436
- // Resolve the target schema name the same way _schemaName is resolved in the constructor.
437
+ // Resolve the target schema name the same way _storageKey is resolved in the constructor.
437
438
  const targetSchemaEntry = EntitySchemaFactory.get(newEntitySchema);
438
439
  const targetSchemaName = targetSchemaEntry.type ?? newEntitySchema;
439
440
  // When migrating to a different schema, wipe the target buffer so that every
440
441
  // migration starts from an empty store regardless of any previous connector
441
442
  // instances that shared the same schema name.
442
- if (targetSchemaName !== this._schemaName) {
443
+ if (targetSchemaName !== this._storageKey) {
443
444
  await Mutex.lock(targetSchemaName, { throwOnTimeout: true });
444
445
  try {
445
446
  SharedObjectBuffer.remove(targetSchemaName);
@@ -451,8 +452,11 @@ export class MemoryEntityStorageConnector {
451
452
  return new MemoryEntityStorageConnector({
452
453
  entitySchema: newEntitySchema,
453
454
  partitionContextIds: this._partitionContextIds,
454
- initialCapacityBytes: this._initialCapacityBytes,
455
- maxCapacityBytes: this._maxCapacityBytes
455
+ config: {
456
+ storageKey: this._storageKey,
457
+ initialCapacityBytes: this._initialCapacityBytes,
458
+ maxCapacityBytes: this._maxCapacityBytes
459
+ }
456
460
  });
457
461
  }
458
462
  /**
@@ -481,7 +485,7 @@ export class MemoryEntityStorageConnector {
481
485
  * @internal
482
486
  */
483
487
  async withLock(fn) {
484
- const key = this._schemaName;
488
+ const key = this._storageKey;
485
489
  await Mutex.lock(key, { throwOnTimeout: true });
486
490
  try {
487
491
  await SharedObjectBuffer.create(key, {
@@ -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,EAAoB,MAAM,mBAAmB,CAAC;AACtF,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,YAAY,EAEZ,EAAE,EAEF,KAAK,EACL,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,kBAAkB,EAElB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EAGZ,eAAe,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,mBAAmB,EAInB,MAAM,iCAAiC,CAAC;AAKzC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,4BAA4B;IAGxC;;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;;;;OAIG;IACc,WAAW,CAAS;IAErC;;;OAGG;IACc,qBAAqB,CAAU;IAEhD;;;OAGG;IACc,iBAAiB,CAAU;IAE5C;;;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,C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d,CAAC,CAAC,CACH,CAAC;QACH,CAAC;QAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1C,IAAI,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;oBAC1E,OAAO,CAAC,CAAC;gBACV,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;IACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore, type IContextIds } from \"@twin.org/context\";\nimport {\n\tCoerce,\n\tComponentFactory,\n\tGuards,\n\tHealthStatus,\n\ttype IHealth,\n\tIs,\n\ttype IValidationFailure,\n\tMutex,\n\tObjectHelper,\n\tSharedObjectBuffer,\n\tValidation\n} from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\ttype EntityCondition,\n\tEntityConditions,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySorter,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\tLogicalOperator,\n\ttype SortDirection\n} from \"@twin.org/entity\";\nimport {\n\tEntityStorageHelper,\n\ttype IEntityStorageConnector,\n\ttype IEntityStorageMigrationConnector,\n\ttype IMigrationOptions\n} 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 backed by a shared object buffer.\n *\n * All reads and writes are serialised with a per-schema lock so that concurrent async\n * access, including across worker threads, never produces torn or lost updates.\n *\n * All connector instances that share the same entity schema name share the same underlying\n * buffer, making data written in one instance immediately visible in another, including\n * across worker threads when the main thread forwards worker messages to the lock and\n * buffer handlers.\n */\nexport class MemoryEntityStorageConnector<T = unknown>\n\timplements IEntityStorageConnector<T>, IEntityStorageMigrationConnector<T>\n{\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 resolved schema name used as the shared buffer and lock key.\n\t * Stored separately so it is always a plain string rather than string | undefined.\n\t * @internal\n\t */\n\tprivate readonly _schemaName: string;\n\n\t/**\n\t * Initial capacity hint in bytes for the shared entity buffer.\n\t * @internal\n\t */\n\tprivate readonly _initialCapacityBytes?: number;\n\n\t/**\n\t * Maximum capacity in bytes for the shared entity buffer.\n\t * @internal\n\t */\n\tprivate readonly _maxCapacityBytes?: number;\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._schemaName = this._entitySchema.type ?? options.entitySchema;\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKey = EntitySchemaHelper.getPrimaryKey<T>(this._entitySchema);\n\t\tthis._initialCapacityBytes = options.initialCapacityBytes;\n\t\tthis._maxCapacityBytes = options.maxCapacityBytes;\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\tdata: { entityType: this._schemaName }\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 * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tawait SharedObjectBuffer.create(this._schemaName, {\n\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t});\n\n\t\treturn true;\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\treturn this.withLock(entities => {\n\t\t\tconst index = this.findItem(entities, id, secondaryIndex, finalConditions);\n\t\t\tconst item = index >= 0 ? entities[index] : undefined;\n\n\t\t\tif (Is.objectValue(item)) {\n\t\t\t\treturn {\n\t\t\t\t\tresult: EntityStorageHelper.unPrepareEntity<T>(item, [\n\t\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t\t])\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { result: undefined };\n\t\t});\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 Resolves when the entity has been stored.\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\tconst finalConditions = conditions ?? [];\n\n\t\tconst prepared = EntityStorageHelper.prepareEntity(\n\t\t\tentity,\n\t\t\tthis._entitySchema,\n\t\t\tIs.stringValue(partitionKey)\n\t\t\t\t? [{ property: MemoryEntityStorageConnector._PARTITION_KEY, value: partitionKey }]\n\t\t\t\t: undefined,\n\t\t\t{ nullBehavior: \"omit\" }\n\t\t);\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}\n\n\t\treturn this.withLock(entities => {\n\t\t\tconst existingIndex = this.findItem(\n\t\t\t\tentities,\n\t\t\t\tprepared[this._primaryKey.property] as string,\n\t\t\t\tundefined,\n\t\t\t\tfinalConditions\n\t\t\t);\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tentities[existingIndex] = prepared;\n\t\t\t} else {\n\t\t\t\tentities.push(prepared);\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\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\tconst preparedItems = entities.map(entity =>\n\t\t\tEntityStorageHelper.prepareEntity(\n\t\t\t\tentity,\n\t\t\t\tthis._entitySchema,\n\t\t\t\tIs.stringValue(partitionKey)\n\t\t\t\t\t? [{ property: MemoryEntityStorageConnector._PARTITION_KEY, value: partitionKey }]\n\t\t\t\t\t: undefined,\n\t\t\t\t{ nullBehavior: \"omit\" }\n\t\t\t)\n\t\t);\n\n\t\treturn this.withLock(store => {\n\t\t\tconst indexMap = new Map<string, number>();\n\t\t\tfor (let i = 0; i < store.length; i++) {\n\t\t\t\tconst stored = store[i];\n\t\t\t\tconst storedPartition = ObjectHelper.propertyGet(\n\t\t\t\t\tstored,\n\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(partitionKey) || storedPartition === partitionKey) {\n\t\t\t\t\tindexMap.set(stored[this._primaryKey.property] as string, i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const prepared of preparedItems) {\n\t\t\t\tconst id = prepared[this._primaryKey.property] as string;\n\t\t\t\tconst existingIndex = indexMap.get(id);\n\t\t\t\tif (existingIndex !== undefined) {\n\t\t\t\t\tstore[existingIndex] = prepared;\n\t\t\t\t} else {\n\t\t\t\t\tconst newIndex = store.push(prepared) - 1;\n\t\t\t\t\tindexMap.set(id, newIndex);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { updated: store, result: undefined };\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\treturn this.withLock(entities => {\n\t\t\tconst index = this.findItem(entities, id, undefined, finalConditions);\n\t\t\tif (index >= 0) {\n\t\t\t\tentities.splice(index, 1);\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\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\tEntityStorageHelper.validateSortProperties(this._entitySchema, sortProperties);\n\t\tEntityStorageHelper.validateProperties(this._entitySchema, properties);\n\n\t\tif (!Is.empty(limit)) {\n\t\t\tconst validationFailures: IValidationFailure[] = [];\n\t\t\tValidation.integer(nameof(limit), limit, validationFailures, undefined, { minValue: 1 });\n\t\t\tValidation.asValidationError(\n\t\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"query\",\n\t\t\t\tvalidationFailures\n\t\t\t);\n\t\t}\n\n\t\treturn this.withLock(store => {\n\t\t\tlet allEntities = store.slice();\n\n\t\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\t\tconditions: [],\n\t\t\t\tlogicalOperator: LogicalOperator.And\n\t\t\t};\n\n\t\t\tif (Is.stringValue(partitionKey)) {\n\t\t\t\tfinalConditions.conditions.push({\n\t\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: partitionKey\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!Is.empty(conditions)) {\n\t\t\t\tfinalConditions.conditions.push(EntityStorageHelper.normalizeConditionValues(conditions));\n\t\t\t}\n\n\t\t\tconst resultEntities = [];\n\t\t\tconst finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;\n\t\t\tlet nextCursor: string | undefined;\n\n\t\t\tif (allEntities.length > 0) {\n\t\t\t\tconst finalSortKeys = EntitySchemaHelper.buildSortProperties<T>(\n\t\t\t\t\tthis._entitySchema,\n\t\t\t\t\tsortProperties\n\t\t\t\t);\n\t\t\t\tallEntities = EntitySorter.sort(allEntities, finalSortKeys);\n\n\t\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\t\tfor (let i = startIndex; i < allEntities.length; i++) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tEntityConditions.check(allEntities[i], finalConditions) &&\n\t\t\t\t\t\tresultEntities.length < finalLimit\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst entity = Is.arrayValue(properties)\n\t\t\t\t\t\t\t? ObjectHelper.pick(allEntities[i], properties)\n\t\t\t\t\t\t\t: allEntities[i];\n\t\t\t\t\t\tresultEntities.push(\n\t\t\t\t\t\t\tEntityStorageHelper.unPrepareEntity<T>(entity, [\n\t\t\t\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (resultEntities.length >= finalLimit) {\n\t\t\t\t\t\t\tif (i < allEntities.length - 1) {\n\t\t\t\t\t\t\t\tnextCursor = (i + 1).toString();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { result: { entities: resultEntities, cursor: 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\treturn this.withLock(entities => {\n\t\t\tif (Is.stringValue(partitionKey)) {\n\t\t\t\tconst filtered = entities.filter(\n\t\t\t\t\titem =>\n\t\t\t\t\t\tObjectHelper.propertyGet(item, MemoryEntityStorageConnector._PARTITION_KEY) !==\n\t\t\t\t\t\tpartitionKey\n\t\t\t\t);\n\t\t\t\treturn { updated: filtered, result: undefined };\n\t\t\t}\n\t\t\treturn { updated: [], result: undefined };\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\treturn this.withLock(entities => {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst index = this.findItem(entities, id, undefined, finalConditions);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tentities.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\n\t\t});\n\t}\n\n\t/**\n\t * Teardown the storage by clearing the underlying shared buffer for this schema.\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\tawait Mutex.lock(this._schemaName, { throwOnTimeout: true });\n\t\ttry {\n\t\t\tSharedObjectBuffer.remove(this._schemaName);\n\t\t} finally {\n\t\t\tMutex.unlock(this._schemaName);\n\t\t}\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(conditions?: EntityCondition<T>): Promise<number> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\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(EntityStorageHelper.normalizeConditionValues(conditions));\n\t\t}\n\n\t\treturn this.withLock(entities => {\n\t\t\tif (finalConditions.conditions.length === 0) {\n\t\t\t\treturn { result: entities.length };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tresult: entities.filter(item => EntityConditions.check(item, finalConditions)).length\n\t\t\t};\n\t\t});\n\t}\n\n\t/**\n\t * Get all entities in the memory store.\n\t * @returns All stored entities with partition keys removed.\n\t */\n\tpublic async getStore(): Promise<T[]> {\n\t\treturn this.withLock(entities => ({\n\t\t\tresult: entities.map(item =>\n\t\t\t\tEntityStorageHelper.unPrepareEntity<T>(item, [MemoryEntityStorageConnector._PARTITION_KEY])\n\t\t\t)\n\t\t}));\n\t}\n\n\t/**\n\t * Get a unique list of all the context ids from the storage.\n\t * @returns The list of unique context ids.\n\t */\n\tpublic async getPartitionContextIds(): Promise<IContextIds[]> {\n\t\treturn this.withLock(entities => {\n\t\t\tconst contextIds: { [id: string]: IContextIds } = {};\n\t\t\tfor (const entity of entities) {\n\t\t\t\tconst partitionId = ObjectHelper.propertyGet(\n\t\t\t\t\tentity,\n\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t);\n\t\t\t\tif (Is.stringValue(partitionId)) {\n\t\t\t\t\tcontextIds[partitionId] = ContextIdHelper.shortSplit(\n\t\t\t\t\t\tthis._partitionContextIds ?? [],\n\t\t\t\t\t\tpartitionId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { result: Object.values(contextIds) };\n\t\t});\n\t}\n\n\t/**\n\t * Create the target connector for performing the migration it will use a temporary storage location.\n\t * @param newEntitySchema The name of the new entity schema to create the connector for.\n\t * @returns Connector for performing the migration.\n\t */\n\tpublic async createTargetConnector<U>(\n\t\tnewEntitySchema: string\n\t): Promise<IEntityStorageConnector<U>> {\n\t\t// Resolve the target schema name the same way _schemaName is resolved in the constructor.\n\t\tconst targetSchemaEntry = EntitySchemaFactory.get(newEntitySchema);\n\t\tconst targetSchemaName = targetSchemaEntry.type ?? newEntitySchema;\n\n\t\t// When migrating to a different schema, wipe the target buffer so that every\n\t\t// migration starts from an empty store regardless of any previous connector\n\t\t// instances that shared the same schema name.\n\t\tif (targetSchemaName !== this._schemaName) {\n\t\t\tawait Mutex.lock(targetSchemaName, { throwOnTimeout: true });\n\t\t\ttry {\n\t\t\t\tSharedObjectBuffer.remove(targetSchemaName);\n\t\t\t} finally {\n\t\t\t\tMutex.unlock(targetSchemaName);\n\t\t\t}\n\t\t}\n\n\t\treturn new MemoryEntityStorageConnector<U>({\n\t\t\tentitySchema: newEntitySchema,\n\t\t\tpartitionContextIds: this._partitionContextIds,\n\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t});\n\t}\n\n\t/**\n\t * Finalize the migration by tearing down the old connector and replacing it with the target connector.\n\t * @param targetConnector The target connector to finalize the migration with.\n\t * @param options The options to control how the migration is finalized.\n\t * @param loggingComponentType The optional component type to use for logging the migration progress.\n\t * @returns A promise that resolves when the migration is finalized.\n\t */\n\tpublic async finalizeMigration<U>(\n\t\ttargetConnector: IEntityStorageConnector<U>,\n\t\toptions?: IMigrationOptions,\n\t\tloggingComponentType?: string\n\t): Promise<IEntityStorageConnector<U>> {\n\t\treturn targetConnector;\n\t}\n\n\t/**\n\t * Cleanup the migration if a migration fails or needs to be aborted.\n\t * @param targetConnector The target connector to cleanup the migration with.\n\t * @param options The options to control how the migration is cleaned up.\n\t * @param loggingComponentType The optional component type to use for logging the migration progress.\n\t * @returns A promise that resolves when the migration is cleaned up.\n\t */\n\tpublic async cleanupMigration<U>(\n\t\ttargetConnector: IEntityStorageConnector<U> | undefined,\n\t\toptions?: IMigrationOptions,\n\t\tloggingComponentType?: string\n\t): Promise<void> {}\n\n\t/**\n\t * Acquires the schema-keyed lock, runs fn with the current entity array, optionally\n\t * writes back a modified array, then releases the lock.\n\t * @param fn The synchronous function to run while the lock is held.\n\t * @returns The result produced by fn.\n\t * @internal\n\t */\n\tprivate async withLock<R>(fn: (entities: T[]) => { updated?: T[]; result: R }): Promise<R> {\n\t\tconst key = this._schemaName;\n\t\tawait Mutex.lock(key, { throwOnTimeout: true });\n\t\ttry {\n\t\t\tawait SharedObjectBuffer.create(key, {\n\t\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t\t});\n\t\t\tconst entities = (await SharedObjectBuffer.read<T[]>(key)) ?? [];\n\t\t\tconst outcome = fn(entities);\n\t\t\tif (outcome.updated !== undefined) {\n\t\t\t\tawait SharedObjectBuffer.write<T[]>(key, outcome.updated);\n\t\t\t}\n\t\t\treturn outcome.result;\n\t\t} finally {\n\t\t\tMutex.unlock(key);\n\t\t}\n\t}\n\n\t/**\n\t * Find the item in the provided entity array.\n\t * @param entities The current entity array.\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\tentities: T[],\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\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 < entities.length; i++) {\n\t\t\t\tif (EntityConditions.check(entities[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 entities.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,EAAoB,MAAM,mBAAmB,CAAC;AACtF,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,YAAY,EAEZ,EAAE,EAEF,KAAK,EACL,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,kBAAkB,EAElB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EAGZ,eAAe,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,mBAAmB,EAInB,MAAM,iCAAiC,CAAC;AAMzC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,4BAA4B;IAGxC;;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,WAAW,CAAS;IAErC;;;OAGG;IACc,qBAAqB,CAAU;IAEhD;;;OAGG;IACc,iBAAiB,CAAU;IAE5C;;;OAGG;IACH,YAAY,OAAwD;QACnE,MAAM,CAAC,MAAM,CACZ,4BAA4B,CAAC,UAAU,aAEvC,OAAO,CACP,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,4BAA4B,CAAC,UAAU,0BAEvC,OAAO,CAAC,YAAY,CACpB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,4BAA4B,CAAC,UAAU,oBAEvC,OAAO,CAAC,MAAM,CACd,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,4BAA4B,CAA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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,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1C,IAAI,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;oBAC1E,OAAO,CAAC,CAAC;gBACV,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;IACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdStore, type IContextIds } from \"@twin.org/context\";\nimport {\n\tCoerce,\n\tComponentFactory,\n\tGuards,\n\tHealthStatus,\n\ttype IHealth,\n\tIs,\n\ttype IValidationFailure,\n\tMutex,\n\tObjectHelper,\n\tSharedObjectBuffer,\n\tValidation\n} from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\ttype EntityCondition,\n\tEntityConditions,\n\tEntitySchemaFactory,\n\tEntitySchemaHelper,\n\tEntitySorter,\n\ttype IEntitySchema,\n\ttype IEntitySchemaProperty,\n\tLogicalOperator,\n\ttype SortDirection\n} from \"@twin.org/entity\";\nimport {\n\tEntityStorageHelper,\n\ttype IEntityStorageConnector,\n\ttype IEntityStorageMigrationConnector,\n\ttype IMigrationOptions\n} from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMemoryEntityStorageConnectorConfig } from \"./models/IMemoryEntityStorageConnectorConfig.js\";\nimport type { IMemoryEntityStorageConnectorConstructorOptions } from \"./models/IMemoryEntityStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing entity storage operations in-memory backed by a shared object buffer.\n *\n * All reads and writes are serialised with a per-schema lock so that concurrent async\n * access, including across worker threads, never produces torn or lost updates.\n *\n * All connector instances that share the same entity schema name share the same underlying\n * buffer, making data written in one instance immediately visible in another, including\n * across worker threads when the main thread forwards worker messages to the lock and\n * buffer handlers.\n */\nexport class MemoryEntityStorageConnector<T = unknown>\n\timplements IEntityStorageConnector<T>, IEntityStorageMigrationConnector<T>\n{\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 resolved storage key used as the shared buffer and lock key.\n\t * @internal\n\t */\n\tprivate readonly _storageKey: string;\n\n\t/**\n\t * Initial capacity hint in bytes for the shared entity buffer.\n\t * @internal\n\t */\n\tprivate readonly _initialCapacityBytes?: number;\n\n\t/**\n\t * Maximum capacity in bytes for the shared entity buffer.\n\t * @internal\n\t */\n\tprivate readonly _maxCapacityBytes?: number;\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<IMemoryEntityStorageConnectorConstructorOptions>(\n\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options),\n\t\t\toptions\n\t\t);\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\tGuards.object<IMemoryEntityStorageConnectorConfig>(\n\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.storageKey),\n\t\t\toptions.config.storageKey\n\t\t);\n\n\t\tthis._entitySchema = EntitySchemaFactory.get(options.entitySchema);\n\t\tthis._storageKey = options.config.storageKey;\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._primaryKey = EntitySchemaHelper.getPrimaryKey<T>(this._entitySchema);\n\t\tthis._initialCapacityBytes = options.config?.initialCapacityBytes;\n\t\tthis._maxCapacityBytes = options.config?.maxCapacityBytes;\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\tdata: { entityType: this._storageKey }\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 * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tawait SharedObjectBuffer.create(this._storageKey, {\n\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t});\n\n\t\treturn true;\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\treturn this.withLock(entities => {\n\t\t\tconst index = this.findItem(entities, id, secondaryIndex, finalConditions);\n\t\t\tconst item = index >= 0 ? entities[index] : undefined;\n\n\t\t\tif (Is.objectValue(item)) {\n\t\t\t\treturn {\n\t\t\t\t\tresult: EntityStorageHelper.unPrepareEntity<T>(item, [\n\t\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t\t])\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { result: undefined };\n\t\t});\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 Resolves when the entity has been stored.\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\tconst finalConditions = conditions ?? [];\n\n\t\tconst prepared = EntityStorageHelper.prepareEntity(\n\t\t\tentity,\n\t\t\tthis._entitySchema,\n\t\t\tIs.stringValue(partitionKey)\n\t\t\t\t? [{ property: MemoryEntityStorageConnector._PARTITION_KEY, value: partitionKey }]\n\t\t\t\t: undefined,\n\t\t\t{ nullBehavior: \"omit\" }\n\t\t);\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}\n\n\t\treturn this.withLock(entities => {\n\t\t\tconst existingIndex = this.findItem(\n\t\t\t\tentities,\n\t\t\t\tprepared[this._primaryKey.property] as string,\n\t\t\t\tundefined,\n\t\t\t\tfinalConditions\n\t\t\t);\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tentities[existingIndex] = prepared;\n\t\t\t} else {\n\t\t\t\tentities.push(prepared);\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\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\tconst preparedItems = entities.map(entity =>\n\t\t\tEntityStorageHelper.prepareEntity(\n\t\t\t\tentity,\n\t\t\t\tthis._entitySchema,\n\t\t\t\tIs.stringValue(partitionKey)\n\t\t\t\t\t? [{ property: MemoryEntityStorageConnector._PARTITION_KEY, value: partitionKey }]\n\t\t\t\t\t: undefined,\n\t\t\t\t{ nullBehavior: \"omit\" }\n\t\t\t)\n\t\t);\n\n\t\treturn this.withLock(store => {\n\t\t\tconst indexMap = new Map<string, number>();\n\t\t\tfor (let i = 0; i < store.length; i++) {\n\t\t\t\tconst stored = store[i];\n\t\t\t\tconst storedPartition = ObjectHelper.propertyGet(\n\t\t\t\t\tstored,\n\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(partitionKey) || storedPartition === partitionKey) {\n\t\t\t\t\tindexMap.set(stored[this._primaryKey.property] as string, i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const prepared of preparedItems) {\n\t\t\t\tconst id = prepared[this._primaryKey.property] as string;\n\t\t\t\tconst existingIndex = indexMap.get(id);\n\t\t\t\tif (existingIndex !== undefined) {\n\t\t\t\t\tstore[existingIndex] = prepared;\n\t\t\t\t} else {\n\t\t\t\t\tconst newIndex = store.push(prepared) - 1;\n\t\t\t\t\tindexMap.set(id, newIndex);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { updated: store, result: undefined };\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\treturn this.withLock(entities => {\n\t\t\tconst index = this.findItem(entities, id, undefined, finalConditions);\n\t\t\tif (index >= 0) {\n\t\t\t\tentities.splice(index, 1);\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\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\tEntityStorageHelper.validateSortProperties(this._entitySchema, sortProperties);\n\t\tEntityStorageHelper.validateProperties(this._entitySchema, properties);\n\n\t\tif (!Is.empty(limit)) {\n\t\t\tconst validationFailures: IValidationFailure[] = [];\n\t\t\tValidation.integer(nameof(limit), limit, validationFailures, undefined, { minValue: 1 });\n\t\t\tValidation.asValidationError(\n\t\t\t\tMemoryEntityStorageConnector.CLASS_NAME,\n\t\t\t\t\"query\",\n\t\t\t\tvalidationFailures\n\t\t\t);\n\t\t}\n\n\t\treturn this.withLock(store => {\n\t\t\tlet allEntities = store.slice();\n\n\t\t\tconst finalConditions: EntityCondition<T> = {\n\t\t\t\tconditions: [],\n\t\t\t\tlogicalOperator: LogicalOperator.And\n\t\t\t};\n\n\t\t\tif (Is.stringValue(partitionKey)) {\n\t\t\t\tfinalConditions.conditions.push({\n\t\t\t\t\tproperty: MemoryEntityStorageConnector._PARTITION_KEY,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: partitionKey\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!Is.empty(conditions)) {\n\t\t\t\tfinalConditions.conditions.push(EntityStorageHelper.normalizeConditionValues(conditions));\n\t\t\t}\n\n\t\t\tconst resultEntities = [];\n\t\t\tconst finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;\n\t\t\tlet nextCursor: string | undefined;\n\n\t\t\tif (allEntities.length > 0) {\n\t\t\t\tconst finalSortKeys = EntitySchemaHelper.buildSortProperties<T>(\n\t\t\t\t\tthis._entitySchema,\n\t\t\t\t\tsortProperties\n\t\t\t\t);\n\t\t\t\tallEntities = EntitySorter.sort(allEntities, finalSortKeys);\n\n\t\t\t\tconst startIndex = Coerce.number(cursor) ?? 0;\n\n\t\t\t\tfor (let i = startIndex; i < allEntities.length; i++) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tEntityConditions.check(allEntities[i], finalConditions) &&\n\t\t\t\t\t\tresultEntities.length < finalLimit\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst entity = Is.arrayValue(properties)\n\t\t\t\t\t\t\t? ObjectHelper.pick(allEntities[i], properties)\n\t\t\t\t\t\t\t: allEntities[i];\n\t\t\t\t\t\tresultEntities.push(\n\t\t\t\t\t\t\tEntityStorageHelper.unPrepareEntity<T>(entity, [\n\t\t\t\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (resultEntities.length >= finalLimit) {\n\t\t\t\t\t\t\tif (i < allEntities.length - 1) {\n\t\t\t\t\t\t\t\tnextCursor = (i + 1).toString();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { result: { entities: resultEntities, cursor: 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\treturn this.withLock(entities => {\n\t\t\tif (Is.stringValue(partitionKey)) {\n\t\t\t\tconst filtered = entities.filter(\n\t\t\t\t\titem =>\n\t\t\t\t\t\tObjectHelper.propertyGet(item, MemoryEntityStorageConnector._PARTITION_KEY) !==\n\t\t\t\t\t\tpartitionKey\n\t\t\t\t);\n\t\t\t\treturn { updated: filtered, result: undefined };\n\t\t\t}\n\t\t\treturn { updated: [], result: undefined };\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\treturn this.withLock(entities => {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst index = this.findItem(entities, id, undefined, finalConditions);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tentities.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { updated: entities, result: undefined };\n\t\t});\n\t}\n\n\t/**\n\t * Teardown the storage by clearing the underlying shared buffer for this schema.\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\tawait Mutex.lock(this._storageKey, { throwOnTimeout: true });\n\t\ttry {\n\t\t\tSharedObjectBuffer.remove(this._storageKey);\n\t\t} finally {\n\t\t\tMutex.unlock(this._storageKey);\n\t\t}\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(conditions?: EntityCondition<T>): Promise<number> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\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(EntityStorageHelper.normalizeConditionValues(conditions));\n\t\t}\n\n\t\treturn this.withLock(entities => {\n\t\t\tif (finalConditions.conditions.length === 0) {\n\t\t\t\treturn { result: entities.length };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tresult: entities.filter(item => EntityConditions.check(item, finalConditions)).length\n\t\t\t};\n\t\t});\n\t}\n\n\t/**\n\t * Get all entities in the memory store.\n\t * @returns All stored entities with partition keys removed.\n\t */\n\tpublic async getStore(): Promise<T[]> {\n\t\treturn this.withLock(entities => ({\n\t\t\tresult: entities.map(item =>\n\t\t\t\tEntityStorageHelper.unPrepareEntity<T>(item, [MemoryEntityStorageConnector._PARTITION_KEY])\n\t\t\t)\n\t\t}));\n\t}\n\n\t/**\n\t * Get a unique list of all the context ids from the storage.\n\t * @returns The list of unique context ids.\n\t */\n\tpublic async getPartitionContextIds(): Promise<IContextIds[]> {\n\t\treturn this.withLock(entities => {\n\t\t\tconst contextIds: { [id: string]: IContextIds } = {};\n\t\t\tfor (const entity of entities) {\n\t\t\t\tconst partitionId = ObjectHelper.propertyGet(\n\t\t\t\t\tentity,\n\t\t\t\t\tMemoryEntityStorageConnector._PARTITION_KEY\n\t\t\t\t);\n\t\t\t\tif (Is.stringValue(partitionId)) {\n\t\t\t\t\tcontextIds[partitionId] = ContextIdHelper.shortSplit(\n\t\t\t\t\t\tthis._partitionContextIds ?? [],\n\t\t\t\t\t\tpartitionId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { result: Object.values(contextIds) };\n\t\t});\n\t}\n\n\t/**\n\t * Create the target connector for performing the migration it will use a temporary storage location.\n\t * @param newEntitySchema The name of the new entity schema to create the connector for.\n\t * @returns Connector for performing the migration.\n\t */\n\tpublic async createTargetConnector<U>(\n\t\tnewEntitySchema: string\n\t): Promise<IEntityStorageConnector<U>> {\n\t\t// Resolve the target schema name the same way _storageKey is resolved in the constructor.\n\t\tconst targetSchemaEntry = EntitySchemaFactory.get(newEntitySchema);\n\t\tconst targetSchemaName = targetSchemaEntry.type ?? newEntitySchema;\n\n\t\t// When migrating to a different schema, wipe the target buffer so that every\n\t\t// migration starts from an empty store regardless of any previous connector\n\t\t// instances that shared the same schema name.\n\t\tif (targetSchemaName !== this._storageKey) {\n\t\t\tawait Mutex.lock(targetSchemaName, { throwOnTimeout: true });\n\t\t\ttry {\n\t\t\t\tSharedObjectBuffer.remove(targetSchemaName);\n\t\t\t} finally {\n\t\t\t\tMutex.unlock(targetSchemaName);\n\t\t\t}\n\t\t}\n\n\t\treturn new MemoryEntityStorageConnector<U>({\n\t\t\tentitySchema: newEntitySchema,\n\t\t\tpartitionContextIds: this._partitionContextIds,\n\t\t\tconfig: {\n\t\t\t\tstorageKey: this._storageKey,\n\t\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Finalize the migration by tearing down the old connector and replacing it with the target connector.\n\t * @param targetConnector The target connector to finalize the migration with.\n\t * @param options The options to control how the migration is finalized.\n\t * @param loggingComponentType The optional component type to use for logging the migration progress.\n\t * @returns A promise that resolves when the migration is finalized.\n\t */\n\tpublic async finalizeMigration<U>(\n\t\ttargetConnector: IEntityStorageConnector<U>,\n\t\toptions?: IMigrationOptions,\n\t\tloggingComponentType?: string\n\t): Promise<IEntityStorageConnector<U>> {\n\t\treturn targetConnector;\n\t}\n\n\t/**\n\t * Cleanup the migration if a migration fails or needs to be aborted.\n\t * @param targetConnector The target connector to cleanup the migration with.\n\t * @param options The options to control how the migration is cleaned up.\n\t * @param loggingComponentType The optional component type to use for logging the migration progress.\n\t * @returns A promise that resolves when the migration is cleaned up.\n\t */\n\tpublic async cleanupMigration<U>(\n\t\ttargetConnector: IEntityStorageConnector<U> | undefined,\n\t\toptions?: IMigrationOptions,\n\t\tloggingComponentType?: string\n\t): Promise<void> {}\n\n\t/**\n\t * Acquires the schema-keyed lock, runs fn with the current entity array, optionally\n\t * writes back a modified array, then releases the lock.\n\t * @param fn The synchronous function to run while the lock is held.\n\t * @returns The result produced by fn.\n\t * @internal\n\t */\n\tprivate async withLock<R>(fn: (entities: T[]) => { updated?: T[]; result: R }): Promise<R> {\n\t\tconst key = this._storageKey;\n\t\tawait Mutex.lock(key, { throwOnTimeout: true });\n\t\ttry {\n\t\t\tawait SharedObjectBuffer.create(key, {\n\t\t\t\tinitialCapacityBytes: this._initialCapacityBytes,\n\t\t\t\tmaxCapacityBytes: this._maxCapacityBytes\n\t\t\t});\n\t\t\tconst entities = (await SharedObjectBuffer.read<T[]>(key)) ?? [];\n\t\t\tconst outcome = fn(entities);\n\t\t\tif (outcome.updated !== undefined) {\n\t\t\t\tawait SharedObjectBuffer.write<T[]>(key, outcome.updated);\n\t\t\t}\n\t\t\treturn outcome.result;\n\t\t} finally {\n\t\t\tMutex.unlock(key);\n\t\t}\n\t}\n\n\t/**\n\t * Find the item in the provided entity array.\n\t * @param entities The current entity array.\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\tentities: T[],\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\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 < entities.length; i++) {\n\t\t\t\tif (EntityConditions.check(entities[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 entities.findIndex(e => e[this._primaryKey.property] === id);\n\t\t}\n\n\t\treturn -1;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IMemoryEntityStorageConnectorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IMemoryEntityStorageConnectorConfig.js","sourceRoot":"","sources":["../../../src/models/IMemoryEntityStorageConnectorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Memory Entity Storage Connector.\n */\nexport interface IMemoryEntityStorageConnectorConfig {\n\t/**\n\t * Key to use for the shared buffer instead of the entity schema type.\n\t * Use this to give two connectors with the same entitySchema separate storage.\n\t */\n\tstorageKey: string;\n\n\t/**\n\t * Initial capacity in bytes for the shared entity buffer.\n\t * @default 16 MiB.\n\t */\n\tinitialCapacityBytes?: number;\n\n\t/**\n\t * Maximum JSON payload size in bytes for the shared entity buffer.\n\t * @default 256 MiB.\n\t */\n\tmaxCapacityBytes?: number;\n}\n"]}
@@ -1,4 +1,2 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
1
  export {};
4
2
  //# sourceMappingURL=IMemoryEntityStorageConnectorConstructorOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IMemoryEntityStorageConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IMemoryEntityStorageConnectorConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Options for the Memory Entity Storage Connector constructor.\n */\nexport interface IMemoryEntityStorageConnectorConstructorOptions {\n\t/**\n\t * The schema for the entity.\n\t */\n\tentitySchema: string;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t */\n\tpartitionContextIds?: string[];\n\n\t/**\n\t * Initial capacity in bytes for the shared entity buffer.\n\t * @default 16 MiB.\n\t */\n\tinitialCapacityBytes?: number;\n\n\t/**\n\t * Maximum JSON payload size in bytes for the shared entity buffer.\n\t * @default 256 MiB.\n\t */\n\tmaxCapacityBytes?: number;\n}\n"]}
1
+ {"version":3,"file":"IMemoryEntityStorageConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IMemoryEntityStorageConnectorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMemoryEntityStorageConnectorConfig } from \"./IMemoryEntityStorageConnectorConfig.js\";\n\n/**\n * Options for the Memory Entity Storage Connector constructor.\n */\nexport interface IMemoryEntityStorageConnectorConstructorOptions {\n\t/**\n\t * The schema for the entity.\n\t */\n\tentitySchema: string;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t */\n\tpartitionContextIds?: string[];\n\n\t/**\n\t * Configuration for storage key and capacity settings.\n\t */\n\tconfig: IMemoryEntityStorageConnectorConfig;\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  export * from "./memoryEntityStorageConnector.js";
2
+ export * from "./models/IMemoryEntityStorageConnectorConfig.js";
2
3
  export * from "./models/IMemoryEntityStorageConnectorConstructorOptions.js";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Configuration for the Memory Entity Storage Connector.
3
+ */
4
+ export interface IMemoryEntityStorageConnectorConfig {
5
+ /**
6
+ * Key to use for the shared buffer instead of the entity schema type.
7
+ * Use this to give two connectors with the same entitySchema separate storage.
8
+ */
9
+ storageKey: string;
10
+ /**
11
+ * Initial capacity in bytes for the shared entity buffer.
12
+ * @default 16 MiB.
13
+ */
14
+ initialCapacityBytes?: number;
15
+ /**
16
+ * Maximum JSON payload size in bytes for the shared entity buffer.
17
+ * @default 256 MiB.
18
+ */
19
+ maxCapacityBytes?: number;
20
+ }
@@ -1,3 +1,4 @@
1
+ import type { IMemoryEntityStorageConnectorConfig } from "./IMemoryEntityStorageConnectorConfig.js";
1
2
  /**
2
3
  * Options for the Memory Entity Storage Connector constructor.
3
4
  */
@@ -11,13 +12,7 @@ export interface IMemoryEntityStorageConnectorConstructorOptions {
11
12
  */
12
13
  partitionContextIds?: string[];
13
14
  /**
14
- * Initial capacity in bytes for the shared entity buffer.
15
- * @default 16 MiB.
15
+ * Configuration for storage key and capacity settings.
16
16
  */
17
- initialCapacityBytes?: number;
18
- /**
19
- * Maximum JSON payload size in bytes for the shared entity buffer.
20
- * @default 256 MiB.
21
- */
22
- maxCapacityBytes?: number;
17
+ config: IMemoryEntityStorageConnectorConfig;
23
18
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.32](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.31...entity-storage-connector-memory-v0.0.3-next.32) (2026-06-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * dynamodb query gsi ([#140](https://github.com/iotaledger/twin-entity-storage/issues/140)) ([45b56d6](https://github.com/iotaledger/twin-entity-storage/commit/45b56d6260c9876012030cc6c85026ea84aebff5))
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.31 to 0.0.3-next.32
16
+
17
+ ## [0.0.3-next.31](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.30...entity-storage-connector-memory-v0.0.3-next.31) (2026-06-15)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * memory entity storage storageKey for uniqueness ([88597cb](https://github.com/iotaledger/twin-entity-storage/commit/88597cb130b406c2358484c6138a21d439e0d062))
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.30 to 0.0.3-next.31
30
+
3
31
  ## [0.0.3-next.30](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-connector-memory-v0.0.3-next.29...entity-storage-connector-memory-v0.0.3-next.30) (2026-06-15)
4
32
 
5
33
 
@@ -6,4 +6,5 @@
6
6
 
7
7
  ## Interfaces
8
8
 
9
+ - [IMemoryEntityStorageConnectorConfig](interfaces/IMemoryEntityStorageConnectorConfig.md)
9
10
  - [IMemoryEntityStorageConnectorConstructorOptions](interfaces/IMemoryEntityStorageConnectorConstructorOptions.md)
@@ -0,0 +1,40 @@
1
+ # Interface: IMemoryEntityStorageConnectorConfig
2
+
3
+ Configuration for the Memory Entity Storage Connector.
4
+
5
+ ## Properties
6
+
7
+ ### storageKey {#storagekey}
8
+
9
+ > **storageKey**: `string`
10
+
11
+ Key to use for the shared buffer instead of the entity schema type.
12
+ Use this to give two connectors with the same entitySchema separate storage.
13
+
14
+ ***
15
+
16
+ ### initialCapacityBytes? {#initialcapacitybytes}
17
+
18
+ > `optional` **initialCapacityBytes?**: `number`
19
+
20
+ Initial capacity in bytes for the shared entity buffer.
21
+
22
+ #### Default
23
+
24
+ ```ts
25
+ 16 MiB.
26
+ ```
27
+
28
+ ***
29
+
30
+ ### maxCapacityBytes? {#maxcapacitybytes}
31
+
32
+ > `optional` **maxCapacityBytes?**: `number`
33
+
34
+ Maximum JSON payload size in bytes for the shared entity buffer.
35
+
36
+ #### Default
37
+
38
+ ```ts
39
+ 256 MiB.
40
+ ```
@@ -20,28 +20,8 @@ The keys to use from the context ids to create partitions.
20
20
 
21
21
  ***
22
22
 
23
- ### initialCapacityBytes? {#initialcapacitybytes}
23
+ ### config {#config}
24
24
 
25
- > `optional` **initialCapacityBytes?**: `number`
25
+ > **config**: [`IMemoryEntityStorageConnectorConfig`](IMemoryEntityStorageConnectorConfig.md)
26
26
 
27
- Initial capacity in bytes for the shared entity buffer.
28
-
29
- #### Default
30
-
31
- ```ts
32
- 16 MiB.
33
- ```
34
-
35
- ***
36
-
37
- ### maxCapacityBytes? {#maxcapacitybytes}
38
-
39
- > `optional` **maxCapacityBytes?**: `number`
40
-
41
- Maximum JSON payload size in bytes for the shared entity buffer.
42
-
43
- #### Default
44
-
45
- ```ts
46
- 256 MiB.
47
- ```
27
+ Configuration for storage key and capacity settings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-memory",
3
- "version": "0.0.3-next.30",
3
+ "version": "0.0.3-next.32",
4
4
  "description": "In-memory connector for local development, testing and short-lived workloads.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
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.30",
20
+ "@twin.org/entity-storage-models": "0.0.3-next.32",
21
21
  "@twin.org/logging-models": "next",
22
22
  "@twin.org/nameof": "next"
23
23
  },