@twin.org/entity-storage-connector-scylladb 0.0.1-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.
@@ -0,0 +1,59 @@
1
+ import { SortDirection, type EntityCondition, type IEntitySchema } from "@twin.org/entity";
2
+ import type { IScyllaDBTableConfig } from "./models/IScyllaDBTableConfig";
3
+ /**
4
+ * Store entities using ScyllaDB.
5
+ */
6
+ export declare abstract class AbstractScyllaDBConnector<T> {
7
+ /**
8
+ * Create a new instance of AbstractScyllaDBConnector.
9
+ * @param options The options for the connector.
10
+ * @param options.loggingConnectorType The type of logging connector to use, defaults to no logging.
11
+ * @param options.entitySchema The name of the entity schema.
12
+ * @param options.config The configuration for the connector.
13
+ * @param className The name of the derived class.
14
+ */
15
+ constructor(options: {
16
+ loggingConnectorType?: string;
17
+ entitySchema: string;
18
+ config: IScyllaDBTableConfig;
19
+ }, className: string);
20
+ /**
21
+ * Get the schema for the entities.
22
+ * @returns The schema for the entities.
23
+ */
24
+ getSchema(): IEntitySchema;
25
+ /**
26
+ * Get an entity.
27
+ * @param id The id of the entity to get.
28
+ * @param secondaryIndex Get the item using a secondary index.
29
+ * @param conditions The optional conditions to match for the entities.
30
+ * @returns The object if it can be found or undefined.
31
+ */
32
+ get(id: string, secondaryIndex?: keyof T, conditions?: {
33
+ property: keyof T;
34
+ value: unknown;
35
+ }[]): Promise<T | undefined>;
36
+ /**
37
+ * Find all the entities which match the conditions.
38
+ * @param conditions The conditions to match for the entities.
39
+ * @param sortProperties The optional sort order.
40
+ * @param properties The optional properties to return, defaults to all.
41
+ * @param cursor The cursor to request the next page of entities.
42
+ * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
43
+ * @returns All the entities for the storage matching the conditions,
44
+ * and a cursor which can be used to request more entities.
45
+ */
46
+ query(conditions?: EntityCondition<T>, sortProperties?: {
47
+ property: keyof T;
48
+ sortDirection: SortDirection;
49
+ }[], properties?: (keyof T)[], cursor?: string, pageSize?: number): Promise<{
50
+ /**
51
+ * The entities, which can be partial if a limited keys list was provided.
52
+ */
53
+ entities: Partial<T>[];
54
+ /**
55
+ * An optional cursor, when defined can be used to call find to get more entities.
56
+ */
57
+ cursor?: string;
58
+ }>;
59
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./scyllaDBTableConnector";
2
+ export * from "./scyllaDBViewConnector";
3
+ export * from "./models/IScyllaDBTableConfig";
4
+ export * from "./models/IScyllaDBViewConfig";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * ScyllaDB Configuration.
3
+ */
4
+ export interface IScyllaDBConfig {
5
+ /**
6
+ * The host to contact to.
7
+ */
8
+ hosts: string[];
9
+ /**
10
+ * The local data center.
11
+ */
12
+ localDataCenter: string;
13
+ /**
14
+ * The keyspace to use.
15
+ */
16
+ keyspace: string;
17
+ }
@@ -0,0 +1,11 @@
1
+ import type { IScyllaDBConfig } from "./IScyllaDBConfig";
2
+ /**
3
+ * Definition of MySQL DB configuration.
4
+ */
5
+ export interface IScyllaDBTableConfig extends IScyllaDBConfig {
6
+ /**
7
+ * The name of the table for the storage.
8
+ * @default To the camel case of the entity name.
9
+ */
10
+ tableName?: string;
11
+ }
@@ -0,0 +1,11 @@
1
+ import type { IScyllaDBTableConfig } from "./IScyllaDBTableConfig";
2
+ /**
3
+ * Definition of MySQL DB configuration.
4
+ */
5
+ export interface IScyllaDBViewConfig extends IScyllaDBTableConfig {
6
+ /**
7
+ * The name of view.
8
+ * @default To the camel case of the entity name with View appended.
9
+ */
10
+ viewName?: string;
11
+ }
@@ -0,0 +1,62 @@
1
+ import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
2
+ import { AbstractScyllaDBConnector } from "./abstractScyllaDBConnector";
3
+ import type { IScyllaDBTableConfig } from "./models/IScyllaDBTableConfig";
4
+ /**
5
+ * Store entities using ScyllaDB.
6
+ */
7
+ export declare class ScyllaDBTableConnector<T = unknown> extends AbstractScyllaDBConnector<T> implements IEntityStorageConnector<T> {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of ScyllaDBTableConnector.
14
+ * @param options The options for the connector.
15
+ * @param options.loggingConnectorType The type of logging connector to use, defaults to "logging".
16
+ * @param options.entitySchema The name of the entity schema.
17
+ * @param options.config The configuration for the connector.
18
+ */
19
+ constructor(options: {
20
+ loggingConnectorType?: string;
21
+ entitySchema: string;
22
+ config: IScyllaDBTableConfig;
23
+ });
24
+ /**
25
+ * Bootstrap the component by creating and initializing any resources it needs.
26
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
27
+ * @returns True if the bootstrapping process was successful.
28
+ */
29
+ bootstrap(nodeLoggingConnectorType?: string): Promise<boolean>;
30
+ /**
31
+ * Set an entity.
32
+ * @param entity The entity to set.
33
+ * @param conditions The optional conditions to match for the entities.
34
+ */
35
+ set(entity: T, conditions?: {
36
+ property: keyof T;
37
+ value: unknown;
38
+ }[]): Promise<void>;
39
+ /**
40
+ * Remove the entity.
41
+ * @param id The id of the entity to remove.
42
+ * @param conditions The optional conditions to match for the entities.
43
+ */
44
+ remove(id: string, conditions?: {
45
+ property: keyof T;
46
+ value: unknown;
47
+ }[]): Promise<void>;
48
+ /**
49
+ * Drops table.
50
+ */
51
+ dropTable(): Promise<void>;
52
+ /**
53
+ * Truncates (clear) table.
54
+ */
55
+ truncateTable(): Promise<void>;
56
+ /**
57
+ * Build the conditions for the query.
58
+ * @param conditions The optional conditions to match for the entities.
59
+ * @returns The SQL conditions and the values.
60
+ */
61
+ private buildConditions;
62
+ }
@@ -0,0 +1,42 @@
1
+ import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
2
+ import { AbstractScyllaDBConnector } from "./abstractScyllaDBConnector";
3
+ import type { IScyllaDBViewConfig } from "./models/IScyllaDBViewConfig";
4
+ /**
5
+ * Manage entities using ScyllaDB Views.
6
+ */
7
+ export declare class ScyllaDBViewConnector<T> extends AbstractScyllaDBConnector<T> implements IEntityStorageConnector<T> {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of ScyllaDBViewConnector.
14
+ * @param options The options for the connector.
15
+ * @param options.loggingConnectorType The type of logging connector to use, defaults to "logging".
16
+ * @param options.entitySchema The name of the entity schema.
17
+ * @param options.viewSchema The name of the view schema.
18
+ * @param options.config The configuration for the connector.
19
+ */
20
+ constructor(options: {
21
+ loggingConnectorType?: string;
22
+ entitySchema: string;
23
+ viewSchema: string;
24
+ config: IScyllaDBViewConfig;
25
+ });
26
+ /**
27
+ * Bootstrap the component by creating and initializing any resources it needs.
28
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
29
+ * @returns True if the bootstrapping process was successful.
30
+ */
31
+ bootstrap(nodeLoggingConnectorType?: string): Promise<boolean>;
32
+ /**
33
+ * Set an entity.
34
+ * @param entity The entity to set.
35
+ */
36
+ set(entity: T): Promise<void>;
37
+ /**
38
+ * Delete the entity.
39
+ * @param id The id of the entity to remove.
40
+ */
41
+ remove(id: string): Promise<void>;
42
+ }
@@ -0,0 +1,5 @@
1
+ # @twin.org/entity-storage-connector-scylladb - Changelog
2
+
3
+ ## v0.0.1-next.10
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/entity-storage-connector-scylladb - Examples
@@ -0,0 +1,280 @@
1
+ # Class: ScyllaDBTableConnector\<T\>
2
+
3
+ Store entities using ScyllaDB.
4
+
5
+ ## Extends
6
+
7
+ - `AbstractScyllaDBConnector`\<`T`\>
8
+
9
+ ## Type Parameters
10
+
11
+ • **T** = `unknown`
12
+
13
+ ## Implements
14
+
15
+ - `IEntityStorageConnector`\<`T`\>
16
+
17
+ ## Constructors
18
+
19
+ ### new ScyllaDBTableConnector()
20
+
21
+ > **new ScyllaDBTableConnector**\<`T`\>(`options`): [`ScyllaDBTableConnector`](ScyllaDBTableConnector.md)\<`T`\>
22
+
23
+ Create a new instance of ScyllaDBTableConnector.
24
+
25
+ #### Parameters
26
+
27
+ • **options**
28
+
29
+ The options for the connector.
30
+
31
+ • **options.loggingConnectorType?**: `string`
32
+
33
+ The type of logging connector to use, defaults to "logging".
34
+
35
+ • **options.entitySchema**: `string`
36
+
37
+ The name of the entity schema.
38
+
39
+ • **options.config**: [`IScyllaDBTableConfig`](../interfaces/IScyllaDBTableConfig.md)
40
+
41
+ The configuration for the connector.
42
+
43
+ #### Returns
44
+
45
+ [`ScyllaDBTableConnector`](ScyllaDBTableConnector.md)\<`T`\>
46
+
47
+ #### Overrides
48
+
49
+ `AbstractScyllaDBConnector<T>.constructor`
50
+
51
+ ## Properties
52
+
53
+ ### CLASS\_NAME
54
+
55
+ > `readonly` **CLASS\_NAME**: `string`
56
+
57
+ Runtime name for the class.
58
+
59
+ #### Implementation of
60
+
61
+ `IEntityStorageConnector.CLASS_NAME`
62
+
63
+ #### Overrides
64
+
65
+ `AbstractScyllaDBConnector.CLASS_NAME`
66
+
67
+ ## Methods
68
+
69
+ ### getSchema()
70
+
71
+ > **getSchema**(): `IEntitySchema`\<`unknown`\>
72
+
73
+ Get the schema for the entities.
74
+
75
+ #### Returns
76
+
77
+ `IEntitySchema`\<`unknown`\>
78
+
79
+ The schema for the entities.
80
+
81
+ #### Implementation of
82
+
83
+ `IEntityStorageConnector.getSchema`
84
+
85
+ #### Inherited from
86
+
87
+ `AbstractScyllaDBConnector.getSchema`
88
+
89
+ ***
90
+
91
+ ### get()
92
+
93
+ > **get**(`id`, `secondaryIndex`?, `conditions`?): `Promise`\<`undefined` \| `T`\>
94
+
95
+ Get an entity.
96
+
97
+ #### Parameters
98
+
99
+ • **id**: `string`
100
+
101
+ The id of the entity to get.
102
+
103
+ • **secondaryIndex?**: keyof `T`
104
+
105
+ Get the item using a secondary index.
106
+
107
+ • **conditions?**: `object`[]
108
+
109
+ The optional conditions to match for the entities.
110
+
111
+ #### Returns
112
+
113
+ `Promise`\<`undefined` \| `T`\>
114
+
115
+ The object if it can be found or undefined.
116
+
117
+ #### Implementation of
118
+
119
+ `IEntityStorageConnector.get`
120
+
121
+ #### Inherited from
122
+
123
+ `AbstractScyllaDBConnector.get`
124
+
125
+ ***
126
+
127
+ ### query()
128
+
129
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
130
+
131
+ Find all the entities which match the conditions.
132
+
133
+ #### Parameters
134
+
135
+ • **conditions?**: `EntityCondition`\<`T`\>
136
+
137
+ The conditions to match for the entities.
138
+
139
+ • **sortProperties?**: `object`[]
140
+
141
+ The optional sort order.
142
+
143
+ • **properties?**: keyof `T`[]
144
+
145
+ The optional properties to return, defaults to all.
146
+
147
+ • **cursor?**: `string`
148
+
149
+ The cursor to request the next page of entities.
150
+
151
+ • **pageSize?**: `number`
152
+
153
+ The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
154
+
155
+ #### Returns
156
+
157
+ `Promise`\<`object`\>
158
+
159
+ All the entities for the storage matching the conditions,
160
+ and a cursor which can be used to request more entities.
161
+
162
+ ##### entities
163
+
164
+ > **entities**: `Partial`\<`T`\>[]
165
+
166
+ The entities, which can be partial if a limited keys list was provided.
167
+
168
+ ##### cursor?
169
+
170
+ > `optional` **cursor**: `string`
171
+
172
+ An optional cursor, when defined can be used to call find to get more entities.
173
+
174
+ #### Implementation of
175
+
176
+ `IEntityStorageConnector.query`
177
+
178
+ #### Inherited from
179
+
180
+ `AbstractScyllaDBConnector.query`
181
+
182
+ ***
183
+
184
+ ### bootstrap()
185
+
186
+ > **bootstrap**(`nodeLoggingConnectorType`?): `Promise`\<`boolean`\>
187
+
188
+ Bootstrap the component by creating and initializing any resources it needs.
189
+
190
+ #### Parameters
191
+
192
+ • **nodeLoggingConnectorType?**: `string`
193
+
194
+ The node logging connector type, defaults to "node-logging".
195
+
196
+ #### Returns
197
+
198
+ `Promise`\<`boolean`\>
199
+
200
+ True if the bootstrapping process was successful.
201
+
202
+ #### Implementation of
203
+
204
+ `IEntityStorageConnector.bootstrap`
205
+
206
+ ***
207
+
208
+ ### set()
209
+
210
+ > **set**(`entity`, `conditions`?): `Promise`\<`void`\>
211
+
212
+ Set an entity.
213
+
214
+ #### Parameters
215
+
216
+ • **entity**: `T`
217
+
218
+ The entity to set.
219
+
220
+ • **conditions?**: `object`[]
221
+
222
+ The optional conditions to match for the entities.
223
+
224
+ #### Returns
225
+
226
+ `Promise`\<`void`\>
227
+
228
+ #### Implementation of
229
+
230
+ `IEntityStorageConnector.set`
231
+
232
+ ***
233
+
234
+ ### remove()
235
+
236
+ > **remove**(`id`, `conditions`?): `Promise`\<`void`\>
237
+
238
+ Remove the entity.
239
+
240
+ #### Parameters
241
+
242
+ • **id**: `string`
243
+
244
+ The id of the entity to remove.
245
+
246
+ • **conditions?**: `object`[]
247
+
248
+ The optional conditions to match for the entities.
249
+
250
+ #### Returns
251
+
252
+ `Promise`\<`void`\>
253
+
254
+ #### Implementation of
255
+
256
+ `IEntityStorageConnector.remove`
257
+
258
+ ***
259
+
260
+ ### dropTable()
261
+
262
+ > **dropTable**(): `Promise`\<`void`\>
263
+
264
+ Drops table.
265
+
266
+ #### Returns
267
+
268
+ `Promise`\<`void`\>
269
+
270
+ ***
271
+
272
+ ### truncateTable()
273
+
274
+ > **truncateTable**(): `Promise`\<`void`\>
275
+
276
+ Truncates (clear) table.
277
+
278
+ #### Returns
279
+
280
+ `Promise`\<`void`\>