@twin.org/entity-storage-models 0.0.1-next.4 → 0.0.1-next.6

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.
@@ -1,2 +1,9 @@
1
1
  export * from "./factories/entityStorageConnectorFactory";
2
+ export * from "./models/api/IEntityStorageGetRequest";
3
+ export * from "./models/api/IEntityStorageGetResponse";
4
+ export * from "./models/api/IEntityStorageListRequest";
5
+ export * from "./models/api/IEntityStorageListResponse";
6
+ export * from "./models/api/IEntityStorageRemoveRequest";
7
+ export * from "./models/api/IEntityStorageSetRequest";
8
+ export * from "./models/IEntityStorageComponent";
2
9
  export * from "./models/IEntityStorageConnector";
@@ -0,0 +1,57 @@
1
+ import type { IComponent } from "@twin.org/core";
2
+ import type { EntityCondition, SortDirection } from "@twin.org/entity";
3
+ /**
4
+ * Interface describing an entity storage component.
5
+ */
6
+ export interface IEntityStorageComponent<T = unknown> extends IComponent {
7
+ /**
8
+ * Set an entity.
9
+ * @param entity The entity to set.
10
+ * @param userIdentity The user identity to use with storage operations.
11
+ * @param nodeIdentity The node identity to use with storage operations.
12
+ * @returns The id of the entity.
13
+ */
14
+ set(entity: T, userIdentity?: string, nodeIdentity?: string): Promise<void>;
15
+ /**
16
+ * Get an entity.
17
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
18
+ * @param secondaryIndex Get the item using a secondary index.
19
+ * @param userIdentity The user identity to use with storage operations.
20
+ * @param nodeIdentity The node identity to use with storage operations.
21
+ * @returns The object if it can be found or undefined.
22
+ */
23
+ get(id: string, secondaryIndex?: keyof T, userIdentity?: string, nodeIdentity?: string): Promise<T | undefined>;
24
+ /**
25
+ * Remove the entity.
26
+ * @param id The id of the entity to remove.
27
+ * @param userIdentity The user identity to use with storage operations.
28
+ * @param nodeIdentity The node identity to use with storage operations.
29
+ * @returns Nothing.
30
+ */
31
+ remove(id: string, userIdentity?: string, nodeIdentity?: string): Promise<void>;
32
+ /**
33
+ * Query all the entities which match the conditions.
34
+ * @param conditions The conditions to match for the entities.
35
+ * @param sortProperties The optional sort order.
36
+ * @param properties The optional properties to return, defaults to all.
37
+ * @param cursor The cursor to request the next page of entities.
38
+ * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
39
+ * @param userIdentity The user identity to use with storage operations.
40
+ * @param nodeIdentity The node identity to use with storage operations.
41
+ * @returns All the entities for the storage matching the conditions,
42
+ * and a cursor which can be used to request more entities.
43
+ */
44
+ query(conditions?: EntityCondition<T>, sortProperties?: {
45
+ property: keyof T;
46
+ sortDirection: SortDirection;
47
+ }[], properties?: (keyof T)[], cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<{
48
+ /**
49
+ * The entities, which can be partial if a limited keys list was provided.
50
+ */
51
+ entities: Partial<T>[];
52
+ /**
53
+ * An optional cursor, when defined can be used to call find to get more entities.
54
+ */
55
+ cursor?: string;
56
+ }>;
57
+ }
@@ -1,22 +1,27 @@
1
1
  import type { IComponent } from "@twin.org/core";
2
- import type { EntityCondition, SortDirection } from "@twin.org/entity";
2
+ import type { EntityCondition, IEntitySchema, SortDirection } from "@twin.org/entity";
3
3
  /**
4
4
  * Interface describing an entity storage connector.
5
5
  */
6
6
  export interface IEntityStorageConnector<T = unknown> extends IComponent {
7
7
  /**
8
- * Get an entity.
9
- * @param id The id of the entity to get, or the index value if secondaryIndex is set.
10
- * @param secondaryIndex Get the item using a secondary index.
11
- * @returns The object if it can be found or undefined.
8
+ * Get the schema for the entities.
9
+ * @returns The schema for the entities.
12
10
  */
13
- get(id: string, secondaryIndex?: keyof T): Promise<T | undefined>;
11
+ getSchema(): IEntitySchema;
14
12
  /**
15
13
  * Set an entity.
16
14
  * @param entity The entity to set.
17
15
  * @returns The id of the entity.
18
16
  */
19
17
  set(entity: T): Promise<void>;
18
+ /**
19
+ * Get an entity.
20
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
21
+ * @param secondaryIndex Get the item using a secondary index.
22
+ * @returns The object if it can be found or undefined.
23
+ */
24
+ get(id: string, secondaryIndex?: keyof T): Promise<T | undefined>;
20
25
  /**
21
26
  * Remove the entity.
22
27
  * @param id The id of the entity to remove.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Get an entry from entity storage.
3
+ */
4
+ export interface IEntityStorageGetRequest {
5
+ /**
6
+ * The parameters from the path.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The id of the entity to get.
11
+ */
12
+ id: string;
13
+ };
14
+ /**
15
+ * The query parameters.
16
+ */
17
+ query?: {
18
+ /**
19
+ * The secondary index to query with the id.
20
+ */
21
+ secondaryIndex?: string;
22
+ };
23
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get an entry from entity storage.
3
+ */
4
+ export interface IEntityStorageGetResponse {
5
+ /**
6
+ * The data for the requested entity.
7
+ */
8
+ body: unknown;
9
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Query the entries from entity storage.
3
+ */
4
+ export interface IEntityStorageListRequest {
5
+ /**
6
+ * The parameters from the query.
7
+ */
8
+ query?: {
9
+ /**
10
+ * The condition for the query as JSON version of EntityCondition type.
11
+ */
12
+ conditions?: string;
13
+ /**
14
+ * The sort property array as JSON serialization of {property,direction}[].
15
+ */
16
+ sortProperties?: string;
17
+ /**
18
+ * The properties to return in the response as a comma separated list, by default returns all properties.
19
+ */
20
+ properties?: string;
21
+ /**
22
+ * The number of entries to return per page.
23
+ */
24
+ pageSize?: number;
25
+ /**
26
+ * The cursor to get next chunk of data, returned in previous response.
27
+ */
28
+ cursor?: string;
29
+ };
30
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Response to getting the list of entries from a query.
3
+ */
4
+ export interface IEntityStorageListResponse {
5
+ /**
6
+ * The list of entries from the query.
7
+ */
8
+ body: {
9
+ /**
10
+ * The entities from the query.
11
+ */
12
+ entities?: unknown[];
13
+ /**
14
+ * The cursor for the next page.
15
+ */
16
+ cursor?: string;
17
+ };
18
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Remove an entry from entity storage.
3
+ */
4
+ export interface IEntityStorageRemoveRequest {
5
+ /**
6
+ * The parameters from the path.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The id of the entity to remove.
11
+ */
12
+ id: string;
13
+ };
14
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Set an entry in entity storage.
3
+ */
4
+ export interface IEntityStorageSetRequest {
5
+ /**
6
+ * The data to be used in the entity.
7
+ */
8
+ body: unknown;
9
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/entity-storage-models - Changelog
2
2
 
3
- ## v0.0.1-next.4
3
+ ## v0.0.1-next.6
4
4
 
5
5
  - Initial Release
@@ -2,7 +2,14 @@
2
2
 
3
3
  ## Interfaces
4
4
 
5
+ - [IEntityStorageComponent](interfaces/IEntityStorageComponent.md)
5
6
  - [IEntityStorageConnector](interfaces/IEntityStorageConnector.md)
7
+ - [IEntityStorageGetRequest](interfaces/IEntityStorageGetRequest.md)
8
+ - [IEntityStorageGetResponse](interfaces/IEntityStorageGetResponse.md)
9
+ - [IEntityStorageListRequest](interfaces/IEntityStorageListRequest.md)
10
+ - [IEntityStorageListResponse](interfaces/IEntityStorageListResponse.md)
11
+ - [IEntityStorageRemoveRequest](interfaces/IEntityStorageRemoveRequest.md)
12
+ - [IEntityStorageSetRequest](interfaces/IEntityStorageSetRequest.md)
6
13
 
7
14
  ## Variables
8
15
 
@@ -0,0 +1,156 @@
1
+ # Interface: IEntityStorageComponent\<T\>
2
+
3
+ Interface describing an entity storage component.
4
+
5
+ ## Extends
6
+
7
+ - `IComponent`
8
+
9
+ ## Type Parameters
10
+
11
+ • **T** = `unknown`
12
+
13
+ ## Methods
14
+
15
+ ### set()
16
+
17
+ > **set**(`entity`, `userIdentity`?, `nodeIdentity`?): `Promise`\<`void`\>
18
+
19
+ Set an entity.
20
+
21
+ #### Parameters
22
+
23
+ • **entity**: `T`
24
+
25
+ The entity to set.
26
+
27
+ • **userIdentity?**: `string`
28
+
29
+ The user identity to use with storage operations.
30
+
31
+ • **nodeIdentity?**: `string`
32
+
33
+ The node identity to use with storage operations.
34
+
35
+ #### Returns
36
+
37
+ `Promise`\<`void`\>
38
+
39
+ The id of the entity.
40
+
41
+ ***
42
+
43
+ ### get()
44
+
45
+ > **get**(`id`, `secondaryIndex`?, `userIdentity`?, `nodeIdentity`?): `Promise`\<`undefined` \| `T`\>
46
+
47
+ Get an entity.
48
+
49
+ #### Parameters
50
+
51
+ • **id**: `string`
52
+
53
+ The id of the entity to get, or the index value if secondaryIndex is set.
54
+
55
+ • **secondaryIndex?**: keyof `T`
56
+
57
+ Get the item using a secondary index.
58
+
59
+ • **userIdentity?**: `string`
60
+
61
+ The user identity to use with storage operations.
62
+
63
+ • **nodeIdentity?**: `string`
64
+
65
+ The node identity to use with storage operations.
66
+
67
+ #### Returns
68
+
69
+ `Promise`\<`undefined` \| `T`\>
70
+
71
+ The object if it can be found or undefined.
72
+
73
+ ***
74
+
75
+ ### remove()
76
+
77
+ > **remove**(`id`, `userIdentity`?, `nodeIdentity`?): `Promise`\<`void`\>
78
+
79
+ Remove the entity.
80
+
81
+ #### Parameters
82
+
83
+ • **id**: `string`
84
+
85
+ The id of the entity to remove.
86
+
87
+ • **userIdentity?**: `string`
88
+
89
+ The user identity to use with storage operations.
90
+
91
+ • **nodeIdentity?**: `string`
92
+
93
+ The node identity to use with storage operations.
94
+
95
+ #### Returns
96
+
97
+ `Promise`\<`void`\>
98
+
99
+ Nothing.
100
+
101
+ ***
102
+
103
+ ### query()
104
+
105
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?, `userIdentity`?, `nodeIdentity`?): `Promise`\<`object`\>
106
+
107
+ Query all the entities which match the conditions.
108
+
109
+ #### Parameters
110
+
111
+ • **conditions?**: `EntityCondition`\<`T`\>
112
+
113
+ The conditions to match for the entities.
114
+
115
+ • **sortProperties?**: `object`[]
116
+
117
+ The optional sort order.
118
+
119
+ • **properties?**: keyof `T`[]
120
+
121
+ The optional properties to return, defaults to all.
122
+
123
+ • **cursor?**: `string`
124
+
125
+ The cursor to request the next page of entities.
126
+
127
+ • **pageSize?**: `number`
128
+
129
+ The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
130
+
131
+ • **userIdentity?**: `string`
132
+
133
+ The user identity to use with storage operations.
134
+
135
+ • **nodeIdentity?**: `string`
136
+
137
+ The node identity to use with storage operations.
138
+
139
+ #### Returns
140
+
141
+ `Promise`\<`object`\>
142
+
143
+ All the entities for the storage matching the conditions,
144
+ and a cursor which can be used to request more entities.
145
+
146
+ ##### entities
147
+
148
+ > **entities**: `Partial`\<`T`\>[]
149
+
150
+ The entities, which can be partial if a limited keys list was provided.
151
+
152
+ ##### cursor?
153
+
154
+ > `optional` **cursor**: `string`
155
+
156
+ An optional cursor, when defined can be used to call find to get more entities.
@@ -12,27 +12,17 @@ Interface describing an entity storage connector.
12
12
 
13
13
  ## Methods
14
14
 
15
- ### get()
16
-
17
- > **get**(`id`, `secondaryIndex`?): `Promise`\<`undefined` \| `T`\>
18
-
19
- Get an entity.
20
-
21
- #### Parameters
22
-
23
- • **id**: `string`
24
-
25
- The id of the entity to get, or the index value if secondaryIndex is set.
15
+ ### getSchema()
26
16
 
27
- **secondaryIndex?**: keyof `T`
17
+ > **getSchema**(): `IEntitySchema`\<`unknown`\>
28
18
 
29
- Get the item using a secondary index.
19
+ Get the schema for the entities.
30
20
 
31
21
  #### Returns
32
22
 
33
- `Promise`\<`undefined` \| `T`\>
23
+ `IEntitySchema`\<`unknown`\>
34
24
 
35
- The object if it can be found or undefined.
25
+ The schema for the entities.
36
26
 
37
27
  ***
38
28
 
@@ -56,6 +46,30 @@ The id of the entity.
56
46
 
57
47
  ***
58
48
 
49
+ ### get()
50
+
51
+ > **get**(`id`, `secondaryIndex`?): `Promise`\<`undefined` \| `T`\>
52
+
53
+ Get an entity.
54
+
55
+ #### Parameters
56
+
57
+ • **id**: `string`
58
+
59
+ The id of the entity to get, or the index value if secondaryIndex is set.
60
+
61
+ • **secondaryIndex?**: keyof `T`
62
+
63
+ Get the item using a secondary index.
64
+
65
+ #### Returns
66
+
67
+ `Promise`\<`undefined` \| `T`\>
68
+
69
+ The object if it can be found or undefined.
70
+
71
+ ***
72
+
59
73
  ### remove()
60
74
 
61
75
  > **remove**(`id`): `Promise`\<`void`\>
@@ -0,0 +1,31 @@
1
+ # Interface: IEntityStorageGetRequest
2
+
3
+ Get an entry from entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### pathParams
8
+
9
+ > **pathParams**: `object`
10
+
11
+ The parameters from the path.
12
+
13
+ #### id
14
+
15
+ > **id**: `string`
16
+
17
+ The id of the entity to get.
18
+
19
+ ***
20
+
21
+ ### query?
22
+
23
+ > `optional` **query**: `object`
24
+
25
+ The query parameters.
26
+
27
+ #### secondaryIndex?
28
+
29
+ > `optional` **secondaryIndex**: `string`
30
+
31
+ The secondary index to query with the id.
@@ -0,0 +1,11 @@
1
+ # Interface: IEntityStorageGetResponse
2
+
3
+ Get an entry from entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### body
8
+
9
+ > **body**: `unknown`
10
+
11
+ The data for the requested entity.
@@ -0,0 +1,41 @@
1
+ # Interface: IEntityStorageListRequest
2
+
3
+ Query the entries from entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### query?
8
+
9
+ > `optional` **query**: `object`
10
+
11
+ The parameters from the query.
12
+
13
+ #### conditions?
14
+
15
+ > `optional` **conditions**: `string`
16
+
17
+ The condition for the query as JSON version of EntityCondition type.
18
+
19
+ #### sortProperties?
20
+
21
+ > `optional` **sortProperties**: `string`
22
+
23
+ The sort property array as JSON serialization of {property,direction}[].
24
+
25
+ #### properties?
26
+
27
+ > `optional` **properties**: `string`
28
+
29
+ The properties to return in the response as a comma separated list, by default returns all properties.
30
+
31
+ #### pageSize?
32
+
33
+ > `optional` **pageSize**: `number`
34
+
35
+ The number of entries to return per page.
36
+
37
+ #### cursor?
38
+
39
+ > `optional` **cursor**: `string`
40
+
41
+ The cursor to get next chunk of data, returned in previous response.
@@ -0,0 +1,23 @@
1
+ # Interface: IEntityStorageListResponse
2
+
3
+ Response to getting the list of entries from a query.
4
+
5
+ ## Properties
6
+
7
+ ### body
8
+
9
+ > **body**: `object`
10
+
11
+ The list of entries from the query.
12
+
13
+ #### entities?
14
+
15
+ > `optional` **entities**: `unknown`[]
16
+
17
+ The entities from the query.
18
+
19
+ #### cursor?
20
+
21
+ > `optional` **cursor**: `string`
22
+
23
+ The cursor for the next page.
@@ -0,0 +1,17 @@
1
+ # Interface: IEntityStorageRemoveRequest
2
+
3
+ Remove an entry from entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### pathParams
8
+
9
+ > **pathParams**: `object`
10
+
11
+ The parameters from the path.
12
+
13
+ #### id
14
+
15
+ > **id**: `string`
16
+
17
+ The id of the entity to remove.
@@ -0,0 +1,11 @@
1
+ # Interface: IEntityStorageSetRequest
2
+
3
+ Set an entry in entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### body
8
+
9
+ > **body**: `unknown`
10
+
11
+ The data to be used in the entity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-models",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.6",
4
4
  "description": "Models which define the structure of the entity storage contracts and connectors",
5
5
  "repository": {
6
6
  "type": "git",