@twin.org/entity-storage-connector-memory 0.0.1 → 0.0.2-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.
@@ -10,14 +10,14 @@ var entity = require('@twin.org/entity');
10
10
  */
11
11
  class MemoryEntityStorageConnector {
12
12
  /**
13
- * Default Page Size for cursor.
14
- * @internal
13
+ * Runtime name for the class.
15
14
  */
16
- static _DEFAULT_PAGE_SIZE = 40;
15
+ static CLASS_NAME = "MemoryEntityStorageConnector";
17
16
  /**
18
- * Runtime name for the class.
17
+ * Default limit for the number of items to return.
18
+ * @internal
19
19
  */
20
- CLASS_NAME = "MemoryEntityStorageConnector";
20
+ static _DEFAULT_LIMIT = 40;
21
21
  /**
22
22
  * The schema for the entity.
23
23
  * @internal
@@ -38,8 +38,8 @@ class MemoryEntityStorageConnector {
38
38
  * @param options The options for the connector.
39
39
  */
40
40
  constructor(options) {
41
- core.Guards.object(this.CLASS_NAME, "options", options);
42
- core.Guards.stringValue(this.CLASS_NAME, "options.entitySchema", options.entitySchema);
41
+ core.Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "options", options);
42
+ core.Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "options.entitySchema", options.entitySchema);
43
43
  this._entitySchema = entity.EntitySchemaFactory.get(options.entitySchema);
44
44
  this._primaryKey = entity.EntitySchemaHelper.getPrimaryKey(this._entitySchema);
45
45
  this._store = [];
@@ -59,7 +59,7 @@ class MemoryEntityStorageConnector {
59
59
  * @returns The object if it can be found or undefined.
60
60
  */
61
61
  async get(id, secondaryIndex, conditions) {
62
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
62
+ core.Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "id", id);
63
63
  const index = this.findItem(id, secondaryIndex, conditions);
64
64
  return index >= 0 ? this._store[index] : undefined;
65
65
  }
@@ -70,7 +70,7 @@ class MemoryEntityStorageConnector {
70
70
  * @returns The id of the entity.
71
71
  */
72
72
  async set(entity$1, conditions) {
73
- core.Guards.object(this.CLASS_NAME, "entity", entity$1);
73
+ core.Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "entity", entity$1);
74
74
  entity.EntitySchemaHelper.validateEntity(entity$1, this.getSchema());
75
75
  const existingIndex = this.findItem(entity$1[this._primaryKey.property], undefined, conditions);
76
76
  if (existingIndex >= 0) {
@@ -87,7 +87,7 @@ class MemoryEntityStorageConnector {
87
87
  * @returns Nothing.
88
88
  */
89
89
  async remove(id, conditions) {
90
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
90
+ core.Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "id", id);
91
91
  const index = this.findItem(id, undefined, conditions);
92
92
  if (index >= 0) {
93
93
  this._store.splice(index, 1);
@@ -98,24 +98,24 @@ class MemoryEntityStorageConnector {
98
98
  * @param conditions The conditions to match for the entities.
99
99
  * @param sortProperties The optional sort order.
100
100
  * @param properties The optional properties to return, defaults to all.
101
- * @param cursor The cursor to request the next page of entities.
102
- * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
101
+ * @param cursor The cursor to request the next chunk of entities.
102
+ * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
103
103
  * @returns All the entities for the storage matching the conditions,
104
104
  * and a cursor which can be used to request more entities.
105
105
  */
106
- async query(conditions, sortProperties, properties, cursor, pageSize) {
106
+ async query(conditions, sortProperties, properties, cursor, limit) {
107
107
  let allEntities = this._store.slice();
108
108
  const entities = [];
109
- const finalPageSize = pageSize ?? MemoryEntityStorageConnector._DEFAULT_PAGE_SIZE;
109
+ const finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;
110
110
  let nextCursor;
111
111
  if (allEntities.length > 0) {
112
112
  const finalSortKeys = entity.EntitySchemaHelper.buildSortProperties(this._entitySchema, sortProperties);
113
113
  allEntities = entity.EntitySorter.sort(allEntities, finalSortKeys);
114
114
  const startIndex = core.Coerce.number(cursor) ?? 0;
115
115
  for (let i = startIndex; i < allEntities.length; i++) {
116
- if (entity.EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
116
+ if (entity.EntityConditions.check(allEntities[i], conditions) && entities.length < finalLimit) {
117
117
  entities.push(core.ObjectHelper.pick(allEntities[i], properties));
118
- if (entities.length >= finalPageSize) {
118
+ if (entities.length >= finalLimit) {
119
119
  if (i < allEntities.length - 1) {
120
120
  nextCursor = (i + 1).toString();
121
121
  }
@@ -8,14 +8,14 @@ import { EntitySchemaFactory, EntitySchemaHelper, EntitySorter, EntityConditions
8
8
  */
9
9
  class MemoryEntityStorageConnector {
10
10
  /**
11
- * Default Page Size for cursor.
12
- * @internal
11
+ * Runtime name for the class.
13
12
  */
14
- static _DEFAULT_PAGE_SIZE = 40;
13
+ static CLASS_NAME = "MemoryEntityStorageConnector";
15
14
  /**
16
- * Runtime name for the class.
15
+ * Default limit for the number of items to return.
16
+ * @internal
17
17
  */
18
- CLASS_NAME = "MemoryEntityStorageConnector";
18
+ static _DEFAULT_LIMIT = 40;
19
19
  /**
20
20
  * The schema for the entity.
21
21
  * @internal
@@ -36,8 +36,8 @@ class MemoryEntityStorageConnector {
36
36
  * @param options The options for the connector.
37
37
  */
38
38
  constructor(options) {
39
- Guards.object(this.CLASS_NAME, "options", options);
40
- Guards.stringValue(this.CLASS_NAME, "options.entitySchema", options.entitySchema);
39
+ Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "options", options);
40
+ Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "options.entitySchema", options.entitySchema);
41
41
  this._entitySchema = EntitySchemaFactory.get(options.entitySchema);
42
42
  this._primaryKey = EntitySchemaHelper.getPrimaryKey(this._entitySchema);
43
43
  this._store = [];
@@ -57,7 +57,7 @@ class MemoryEntityStorageConnector {
57
57
  * @returns The object if it can be found or undefined.
58
58
  */
59
59
  async get(id, secondaryIndex, conditions) {
60
- Guards.stringValue(this.CLASS_NAME, "id", id);
60
+ Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "id", id);
61
61
  const index = this.findItem(id, secondaryIndex, conditions);
62
62
  return index >= 0 ? this._store[index] : undefined;
63
63
  }
@@ -68,7 +68,7 @@ class MemoryEntityStorageConnector {
68
68
  * @returns The id of the entity.
69
69
  */
70
70
  async set(entity, conditions) {
71
- Guards.object(this.CLASS_NAME, "entity", entity);
71
+ Guards.object(MemoryEntityStorageConnector.CLASS_NAME, "entity", entity);
72
72
  EntitySchemaHelper.validateEntity(entity, this.getSchema());
73
73
  const existingIndex = this.findItem(entity[this._primaryKey.property], undefined, conditions);
74
74
  if (existingIndex >= 0) {
@@ -85,7 +85,7 @@ class MemoryEntityStorageConnector {
85
85
  * @returns Nothing.
86
86
  */
87
87
  async remove(id, conditions) {
88
- Guards.stringValue(this.CLASS_NAME, "id", id);
88
+ Guards.stringValue(MemoryEntityStorageConnector.CLASS_NAME, "id", id);
89
89
  const index = this.findItem(id, undefined, conditions);
90
90
  if (index >= 0) {
91
91
  this._store.splice(index, 1);
@@ -96,24 +96,24 @@ class MemoryEntityStorageConnector {
96
96
  * @param conditions The conditions to match for the entities.
97
97
  * @param sortProperties The optional sort order.
98
98
  * @param properties The optional properties to return, defaults to all.
99
- * @param cursor The cursor to request the next page of entities.
100
- * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
99
+ * @param cursor The cursor to request the next chunk of entities.
100
+ * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
101
101
  * @returns All the entities for the storage matching the conditions,
102
102
  * and a cursor which can be used to request more entities.
103
103
  */
104
- async query(conditions, sortProperties, properties, cursor, pageSize) {
104
+ async query(conditions, sortProperties, properties, cursor, limit) {
105
105
  let allEntities = this._store.slice();
106
106
  const entities = [];
107
- const finalPageSize = pageSize ?? MemoryEntityStorageConnector._DEFAULT_PAGE_SIZE;
107
+ const finalLimit = limit ?? MemoryEntityStorageConnector._DEFAULT_LIMIT;
108
108
  let nextCursor;
109
109
  if (allEntities.length > 0) {
110
110
  const finalSortKeys = EntitySchemaHelper.buildSortProperties(this._entitySchema, sortProperties);
111
111
  allEntities = EntitySorter.sort(allEntities, finalSortKeys);
112
112
  const startIndex = Coerce.number(cursor) ?? 0;
113
113
  for (let i = startIndex; i < allEntities.length; i++) {
114
- if (EntityConditions.check(allEntities[i], conditions) && entities.length < finalPageSize) {
114
+ if (EntityConditions.check(allEntities[i], conditions) && entities.length < finalLimit) {
115
115
  entities.push(ObjectHelper.pick(allEntities[i], properties));
116
- if (entities.length >= finalPageSize) {
116
+ if (entities.length >= finalLimit) {
117
117
  if (i < allEntities.length - 1) {
118
118
  nextCursor = (i + 1).toString();
119
119
  }
@@ -8,7 +8,7 @@ export declare class MemoryEntityStorageConnector<T = unknown> implements IEntit
8
8
  /**
9
9
  * Runtime name for the class.
10
10
  */
11
- readonly CLASS_NAME: string;
11
+ static readonly CLASS_NAME: string;
12
12
  /**
13
13
  * Create a new instance of MemoryEntityStorageConnector.
14
14
  * @param options The options for the connector.
@@ -55,15 +55,15 @@ export declare class MemoryEntityStorageConnector<T = unknown> implements IEntit
55
55
  * @param conditions The conditions to match for the entities.
56
56
  * @param sortProperties The optional sort order.
57
57
  * @param properties The optional properties to return, defaults to all.
58
- * @param cursor The cursor to request the next page of entities.
59
- * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
58
+ * @param cursor The cursor to request the next chunk of entities.
59
+ * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
60
60
  * @returns All the entities for the storage matching the conditions,
61
61
  * and a cursor which can be used to request more entities.
62
62
  */
63
63
  query(conditions?: EntityCondition<T>, sortProperties?: {
64
64
  property: keyof T;
65
65
  sortDirection: SortDirection;
66
- }[], properties?: (keyof T)[], cursor?: string, pageSize?: number): Promise<{
66
+ }[], properties?: (keyof T)[], cursor?: string, limit?: number): Promise<{
67
67
  /**
68
68
  * The entities, which can be partial if a limited keys list was provided.
69
69
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,152 @@
1
1
  # @twin.org/entity-storage-connector-memory - Changelog
2
2
 
3
+ ## [0.0.2-next.10](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.9...entity-storage-connector-memory-v0.0.2-next.10) (2025-10-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * add validate-locales ([e66ef0d](https://github.com/twinfoundation/entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.9 to 0.0.2-next.10
16
+
17
+ ## [0.0.2-next.9](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.8...entity-storage-connector-memory-v0.0.2-next.9) (2025-10-02)
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.2-next.8 to 0.0.2-next.9
30
+
31
+ ## [0.0.2-next.8](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.7...entity-storage-connector-memory-v0.0.2-next.8) (2025-08-29)
32
+
33
+
34
+ ### Features
35
+
36
+ * eslint migration to flat config ([f033b64](https://github.com/twinfoundation/entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
37
+
38
+
39
+ ### Dependencies
40
+
41
+ * The following workspace dependencies were updated
42
+ * dependencies
43
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.7 to 0.0.2-next.8
44
+
45
+ ## [0.0.2-next.7](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.6...entity-storage-connector-memory-v0.0.2-next.7) (2025-08-20)
46
+
47
+
48
+ ### Miscellaneous Chores
49
+
50
+ * **entity-storage-connector-memory:** Synchronize repo versions
51
+
52
+
53
+ ### Dependencies
54
+
55
+ * The following workspace dependencies were updated
56
+ * dependencies
57
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.6 to 0.0.2-next.7
58
+
59
+ ## [0.0.2-next.6](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.5...entity-storage-connector-memory-v0.0.2-next.6) (2025-08-19)
60
+
61
+
62
+ ### Features
63
+
64
+ * update framework core ([b59a380](https://github.com/twinfoundation/entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
65
+
66
+
67
+ ### Dependencies
68
+
69
+ * The following workspace dependencies were updated
70
+ * dependencies
71
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.5 to 0.0.2-next.6
72
+
73
+ ## [0.0.2-next.5](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.4...entity-storage-connector-memory-v0.0.2-next.5) (2025-08-11)
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.2-next.4 to 0.0.2-next.5
86
+
87
+ ## [0.0.2-next.4](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.3...entity-storage-connector-memory-v0.0.2-next.4) (2025-08-08)
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.2-next.3 to 0.0.2-next.4
100
+
101
+ ## [0.0.2-next.3](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.2...entity-storage-connector-memory-v0.0.2-next.3) (2025-07-25)
102
+
103
+
104
+ ### Miscellaneous Chores
105
+
106
+ * **entity-storage-connector-memory:** Synchronize repo versions
107
+
108
+
109
+ ### Dependencies
110
+
111
+ * The following workspace dependencies were updated
112
+ * dependencies
113
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
114
+
115
+ ## [0.0.2-next.2](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.1...entity-storage-connector-memory-v0.0.2-next.2) (2025-07-24)
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.2-next.1 to 0.0.2-next.2
128
+
129
+ ## [0.0.2-next.1](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-memory-v0.0.2-next.0...entity-storage-connector-memory-v0.0.2-next.1) (2025-07-17)
130
+
131
+
132
+ ### Features
133
+
134
+ * add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
135
+ * update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
136
+ * use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
137
+
138
+
139
+ ### Bug Fixes
140
+
141
+ * query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
142
+
143
+
144
+ ### Dependencies
145
+
146
+ * The following workspace dependencies were updated
147
+ * dependencies
148
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.0 to 0.0.2-next.1
149
+
3
150
  ## 0.0.1 (2025-07-04)
4
151
 
5
152
 
@@ -36,14 +36,10 @@ The options for the connector.
36
36
 
37
37
  ### CLASS\_NAME
38
38
 
39
- > `readonly` **CLASS\_NAME**: `string`
39
+ > `readonly` `static` **CLASS\_NAME**: `string`
40
40
 
41
41
  Runtime name for the class.
42
42
 
43
- #### Implementation of
44
-
45
- `IEntityStorageConnector.CLASS_NAME`
46
-
47
43
  ## Methods
48
44
 
49
45
  ### getSchema()
@@ -168,7 +164,7 @@ Nothing.
168
164
 
169
165
  ### query()
170
166
 
171
- > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `pageSize?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
167
+ > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
172
168
 
173
169
  Find all the entities which match the conditions.
174
170
 
@@ -196,9 +192,9 @@ The optional properties to return, defaults to all.
196
192
 
197
193
  `string`
198
194
 
199
- The cursor to request the next page of entities.
195
+ The cursor to request the next chunk of entities.
200
196
 
201
- ##### pageSize?
197
+ ##### limit?
202
198
 
203
199
  `number`
204
200
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-memory",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-next.10",
4
4
  "description": "Entity Storage connector implementation using in-memory storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,10 +14,10 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "^0.0.1",
18
- "@twin.org/entity": "^0.0.1",
19
- "@twin.org/entity-storage-models": "^0.0.1",
20
- "@twin.org/nameof": "^0.0.1"
17
+ "@twin.org/core": "next",
18
+ "@twin.org/entity": "next",
19
+ "@twin.org/entity-storage-models": "0.0.2-next.10",
20
+ "@twin.org/nameof": "next"
21
21
  },
22
22
  "main": "./dist/cjs/index.cjs",
23
23
  "module": "./dist/esm/index.mjs",
@@ -36,5 +36,27 @@
36
36
  "dist/types",
37
37
  "locales",
38
38
  "docs"
39
- ]
39
+ ],
40
+ "keywords": [
41
+ "twin",
42
+ "trade",
43
+ "iota",
44
+ "framework",
45
+ "blockchain",
46
+ "entity-storage",
47
+ "entity",
48
+ "storage",
49
+ "persistence",
50
+ "database",
51
+ "connector",
52
+ "adapter",
53
+ "integration",
54
+ "memory",
55
+ "in-memory",
56
+ "testing"
57
+ ],
58
+ "bugs": {
59
+ "url": "git+https://github.com/twinfoundation/entity-storage/issues"
60
+ },
61
+ "homepage": "https://twindev.org"
40
62
  }