digitaltwin-core 0.6.0 → 0.7.1

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.
Files changed (75) hide show
  1. package/README.md +216 -0
  2. package/dist/auth/apisix_parser.d.ts +122 -0
  3. package/dist/auth/apisix_parser.d.ts.map +1 -0
  4. package/dist/auth/apisix_parser.js +157 -0
  5. package/dist/auth/apisix_parser.js.map +1 -0
  6. package/dist/auth/auth_config.d.ts +95 -0
  7. package/dist/auth/auth_config.d.ts.map +1 -0
  8. package/dist/auth/auth_config.js +125 -0
  9. package/dist/auth/auth_config.js.map +1 -0
  10. package/dist/auth/index.d.ts +5 -0
  11. package/dist/auth/index.d.ts.map +1 -0
  12. package/dist/auth/index.js +4 -0
  13. package/dist/auth/index.js.map +1 -0
  14. package/dist/auth/types.d.ts +100 -0
  15. package/dist/auth/types.d.ts.map +1 -0
  16. package/dist/auth/types.js +2 -0
  17. package/dist/auth/types.js.map +1 -0
  18. package/dist/auth/user_service.d.ts +86 -0
  19. package/dist/auth/user_service.d.ts.map +1 -0
  20. package/dist/auth/user_service.js +240 -0
  21. package/dist/auth/user_service.js.map +1 -0
  22. package/dist/components/assets_manager.d.ts +42 -5
  23. package/dist/components/assets_manager.d.ts.map +1 -1
  24. package/dist/components/assets_manager.js +199 -7
  25. package/dist/components/assets_manager.js.map +1 -1
  26. package/dist/components/custom_table_manager.d.ts +344 -0
  27. package/dist/components/custom_table_manager.d.ts.map +1 -0
  28. package/dist/components/custom_table_manager.js +525 -0
  29. package/dist/components/custom_table_manager.js.map +1 -0
  30. package/dist/components/index.d.ts +4 -1
  31. package/dist/components/index.d.ts.map +1 -1
  32. package/dist/components/index.js +3 -0
  33. package/dist/components/index.js.map +1 -1
  34. package/dist/components/map_manager.d.ts +61 -0
  35. package/dist/components/map_manager.d.ts.map +1 -0
  36. package/dist/components/map_manager.js +233 -0
  37. package/dist/components/map_manager.js.map +1 -0
  38. package/dist/components/tileset_manager.d.ts +55 -0
  39. package/dist/components/tileset_manager.d.ts.map +1 -0
  40. package/dist/components/tileset_manager.js +212 -0
  41. package/dist/components/tileset_manager.js.map +1 -0
  42. package/dist/components/types.d.ts +22 -0
  43. package/dist/components/types.d.ts.map +1 -1
  44. package/dist/database/adapters/knex_database_adapter.d.ts +3 -0
  45. package/dist/database/adapters/knex_database_adapter.d.ts.map +1 -1
  46. package/dist/database/adapters/knex_database_adapter.js +130 -2
  47. package/dist/database/adapters/knex_database_adapter.js.map +1 -1
  48. package/dist/database/database_adapter.d.ts +22 -1
  49. package/dist/database/database_adapter.d.ts.map +1 -1
  50. package/dist/database/database_adapter.js.map +1 -1
  51. package/dist/engine/digital_twin_engine.d.ts +4 -1
  52. package/dist/engine/digital_twin_engine.d.ts.map +1 -1
  53. package/dist/engine/digital_twin_engine.js +69 -3
  54. package/dist/engine/digital_twin_engine.js.map +1 -1
  55. package/dist/engine/endpoints.d.ts +2 -2
  56. package/dist/engine/endpoints.d.ts.map +1 -1
  57. package/dist/engine/endpoints.js.map +1 -1
  58. package/dist/env/env.d.ts +8 -0
  59. package/dist/env/env.d.ts.map +1 -1
  60. package/dist/env/env.js +22 -1
  61. package/dist/env/env.js.map +1 -1
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +3 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/types/data_record.d.ts +1 -1
  67. package/dist/utils/index.d.ts +5 -0
  68. package/dist/utils/index.d.ts.map +1 -0
  69. package/dist/utils/index.js +5 -0
  70. package/dist/utils/index.js.map +1 -0
  71. package/dist/utils/zip_utils.d.ts +24 -0
  72. package/dist/utils/zip_utils.d.ts.map +1 -0
  73. package/dist/utils/zip_utils.js +77 -0
  74. package/dist/utils/zip_utils.js.map +1 -0
  75. package/package.json +3 -1
@@ -0,0 +1,344 @@
1
+ import type { Servable } from './interfaces.js';
2
+ import type { StoreConfiguration, DataResponse } from './types.js';
3
+ import type { DatabaseAdapter } from '../database/database_adapter.js';
4
+ import type { HttpMethod } from '../engine/endpoints.js';
5
+ /**
6
+ * Record representing a row in the custom table
7
+ */
8
+ export interface CustomTableRecord {
9
+ id: number;
10
+ created_at: Date;
11
+ updated_at: Date;
12
+ [key: string]: any;
13
+ }
14
+ /**
15
+ * Query validation options
16
+ */
17
+ export interface QueryValidationOptions {
18
+ /** Required fields that must have non-empty values */
19
+ required?: string[];
20
+ /** Custom validation function */
21
+ validate?: (conditions: Record<string, any>) => void;
22
+ }
23
+ /**
24
+ * Abstract base class for Custom Table Manager components in the Digital Twin framework.
25
+ *
26
+ * A CustomTableManager is responsible for:
27
+ * - Managing structured data in database tables with custom columns
28
+ * - Providing CRUD operations for the data with validation
29
+ * - Exposing HTTP endpoints for data manipulation
30
+ * - Creating and managing database schema automatically
31
+ *
32
+ * Unlike other components, CustomTableManager does NOT handle files - only structured data.
33
+ *
34
+ * @abstract
35
+ * @class CustomTableManager
36
+ * @implements {Component}
37
+ * @implements {Servable}
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * class WMSManager extends CustomTableManager {
42
+ * getConfiguration(): StoreConfiguration {
43
+ * return {
44
+ * name: 'wms_layers',
45
+ * description: 'Manage WMS layers for mapping',
46
+ * columns: {
47
+ * 'wms_url': 'text not null',
48
+ * 'layer_name': 'text not null',
49
+ * 'description': 'text',
50
+ * 'active': 'boolean default true'
51
+ * },
52
+ * endpoints: [
53
+ * { path: '/add-layers', method: 'post', handler: 'addLayers' }
54
+ * ]
55
+ * }
56
+ * }
57
+ *
58
+ * async addLayers(req: any): Promise<DataResponse> {
59
+ * // Custom endpoint implementation
60
+ * }
61
+ * }
62
+ * ```
63
+ */
64
+ /**
65
+ * Base component interface for CustomTableManager (doesn't extend ComponentConfiguration)
66
+ */
67
+ export interface CustomTableComponent {
68
+ getConfiguration(): StoreConfiguration;
69
+ }
70
+ export declare abstract class CustomTableManager implements CustomTableComponent, Servable {
71
+ /** Database adapter for data operations */
72
+ protected db: DatabaseAdapter;
73
+ /** Cached table name from configuration */
74
+ protected tableName: string;
75
+ /**
76
+ * Injects required dependencies into the custom table manager instance.
77
+ *
78
+ * Called by the Digital Twin Engine during component initialization.
79
+ *
80
+ * @param {DatabaseAdapter} db - Database adapter for data operations
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const customTableManager = new MyCustomTableManager()
85
+ * customTableManager.setDependencies(databaseAdapter)
86
+ * ```
87
+ */
88
+ setDependencies(db: DatabaseAdapter): void;
89
+ /**
90
+ * Returns the static configuration defining this custom table manager's behavior.
91
+ *
92
+ * The configuration includes the table name, description,
93
+ * custom columns definition, and optional custom endpoints.
94
+ *
95
+ * @abstract
96
+ * @returns {StoreConfiguration} The table configuration
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * getConfiguration(): StoreConfiguration {
101
+ * return {
102
+ * name: 'sensors',
103
+ * description: 'IoT sensors data store',
104
+ * columns: {
105
+ * 'sensor_id': 'text unique not null',
106
+ * 'type': 'text not null',
107
+ * 'location': 'text',
108
+ * 'active': 'boolean default true',
109
+ * 'last_ping': 'timestamp'
110
+ * }
111
+ * }
112
+ * }
113
+ * ```
114
+ */
115
+ abstract getConfiguration(): StoreConfiguration;
116
+ /**
117
+ * Initialize the database table with custom columns.
118
+ *
119
+ * Creates the table if it doesn't exist, with standard columns (id, created_at, updated_at)
120
+ * plus the custom columns defined in the configuration.
121
+ *
122
+ * @returns {Promise<void>}
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Called automatically by the framework
127
+ * await customTableManager.initializeTable()
128
+ * ```
129
+ */
130
+ initializeTable(): Promise<void>;
131
+ /**
132
+ * Validate query conditions against requirements.
133
+ *
134
+ * @private
135
+ * @param {Record<string, any>} conditions - Conditions to validate
136
+ * @param {QueryValidationOptions} options - Validation options
137
+ * @throws {Error} If validation fails
138
+ */
139
+ private validateQuery;
140
+ /**
141
+ * Create a new record in the custom table.
142
+ *
143
+ * @param {Record<string, any>} data - Data to insert (excluding id, created_at, updated_at)
144
+ * @returns {Promise<number>} The ID of the created record
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const id = await customTableManager.create({
149
+ * sensor_id: 'TEMP001',
150
+ * type: 'temperature',
151
+ * location: 'Building A - Floor 1',
152
+ * active: true
153
+ * })
154
+ * console.log(`Created sensor with ID: ${id}`)
155
+ * ```
156
+ */
157
+ create(data: Record<string, any>): Promise<number>;
158
+ /**
159
+ * Find all records in the custom table.
160
+ *
161
+ * @returns {Promise<CustomTableRecord[]>} Array of all records
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const allSensors = await customTableManager.findAll()
166
+ * console.log(`Found ${allSensors.length} sensors`)
167
+ * ```
168
+ */
169
+ findAll(): Promise<CustomTableRecord[]>;
170
+ /**
171
+ * Find a record by its ID.
172
+ *
173
+ * @param {number} id - The record ID to find
174
+ * @returns {Promise<CustomTableRecord | null>} The record or null if not found
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const sensor = await customTableManager.findById(123)
179
+ * if (sensor) {
180
+ * console.log(`Sensor: ${sensor.sensor_id}`)
181
+ * }
182
+ * ```
183
+ */
184
+ findById(id: number): Promise<CustomTableRecord | null>;
185
+ /**
186
+ * Find records by a single column value with optional validation.
187
+ *
188
+ * @param {string} columnName - Name of the column to search by
189
+ * @param {any} value - Value to search for
190
+ * @param {boolean} required - Whether the value is required (default: true)
191
+ * @returns {Promise<CustomTableRecord[]>} Array of matching records
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const wmsLayers = await wmsManager.findByColumn('wms_url', 'https://example.com/wms')
196
+ * const activeLayers = await wmsManager.findByColumn('active', true)
197
+ *
198
+ * // Optional value (won't throw if empty)
199
+ * const layers = await wmsManager.findByColumn('description', '', false)
200
+ * ```
201
+ */
202
+ findByColumn(columnName: string, value: any, required?: boolean): Promise<CustomTableRecord[]>;
203
+ /**
204
+ * Find records by multiple column values with validation support.
205
+ *
206
+ * @param {Record<string, any>} conditions - Key-value pairs to match
207
+ * @param {QueryValidationOptions} options - Validation options
208
+ * @returns {Promise<CustomTableRecord[]>} Array of matching records
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * // Simple query
213
+ * const layers = await wmsManager.findByColumns({
214
+ * wms_url: 'https://example.com/wms',
215
+ * active: true
216
+ * })
217
+ *
218
+ * // With validation
219
+ * const layers = await wmsManager.findByColumns(
220
+ * { wms_url: wmsUrl, projection: projection },
221
+ * {
222
+ * required: ['wms_url', 'projection'],
223
+ * validate: (conditions) => {
224
+ * if (!conditions.wms_url.startsWith('http')) {
225
+ * throw new Error('WMS URL must start with http or https')
226
+ * }
227
+ * }
228
+ * }
229
+ * )
230
+ * ```
231
+ */
232
+ findByColumns(conditions: Record<string, any>, options?: QueryValidationOptions): Promise<CustomTableRecord[]>;
233
+ /**
234
+ * Find records matching specific conditions (base method).
235
+ *
236
+ * @param {Record<string, any>} conditions - Key-value pairs to match
237
+ * @returns {Promise<CustomTableRecord[]>} Array of matching records
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const activeSensors = await customTableManager.findByCondition({ active: true })
242
+ * const tempSensors = await customTableManager.findByCondition({ type: 'temperature' })
243
+ * ```
244
+ */
245
+ findByCondition(conditions: Record<string, any>): Promise<CustomTableRecord[]>;
246
+ /**
247
+ * Update a record by its ID.
248
+ *
249
+ * @param {number} id - The record ID to update
250
+ * @param {Record<string, any>} data - Data to update (excluding id, created_at)
251
+ * @returns {Promise<void>}
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * await customTableManager.update(123, {
256
+ * active: false,
257
+ * last_ping: new Date()
258
+ * })
259
+ * ```
260
+ */
261
+ update(id: number, data: Record<string, any>): Promise<void>;
262
+ /**
263
+ * Delete a record by its ID.
264
+ *
265
+ * @param {number} id - The record ID to delete
266
+ * @returns {Promise<void>}
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * await customTableManager.delete(123)
271
+ * console.log('Sensor deleted successfully')
272
+ * ```
273
+ */
274
+ delete(id: number): Promise<void>;
275
+ /**
276
+ * Delete records by a single column value.
277
+ *
278
+ * @param {string} columnName - Name of the column to match for deletion
279
+ * @param {any} value - Value to match for deletion
280
+ * @returns {Promise<number>} Number of records deleted
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const deleted = await wmsManager.deleteByColumn('active', false)
285
+ * console.log(`Deleted ${deleted} inactive layers`)
286
+ * ```
287
+ */
288
+ deleteByColumn(columnName: string, value: any): Promise<number>;
289
+ /**
290
+ * Delete records matching specific conditions.
291
+ *
292
+ * @param {Record<string, any>} conditions - Key-value pairs to match for deletion
293
+ * @returns {Promise<number>} Number of records deleted
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const deleted = await customTableManager.deleteByCondition({ active: false })
298
+ * console.log(`Deleted ${deleted} inactive sensors`)
299
+ * ```
300
+ */
301
+ deleteByCondition(conditions: Record<string, any>): Promise<number>;
302
+ /**
303
+ * Extract custom fields from a database record, excluding framework fields.
304
+ *
305
+ * @private
306
+ * @param {any} record - Database record
307
+ * @returns {Record<string, any>} Custom fields only
308
+ */
309
+ private extractCustomFields;
310
+ /**
311
+ * Get HTTP endpoints exposed by this custom table manager.
312
+ *
313
+ * Returns both standard CRUD endpoints and custom endpoints defined in configuration.
314
+ *
315
+ * @returns {Array} Array of endpoint descriptors with methods, paths, and handlers
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // Standard endpoints for a table named 'sensors':
320
+ * GET /sensors - Get all records
321
+ * POST /sensors - Create new record
322
+ * GET /sensors/:id - Get specific record
323
+ * PUT /sensors/:id - Update specific record
324
+ * DELETE /sensors/:id - Delete specific record
325
+ *
326
+ * // Plus any custom endpoints defined in configuration
327
+ * ```
328
+ */
329
+ getEndpoints(): Array<{
330
+ method: HttpMethod;
331
+ path: string;
332
+ handler: (...args: any[]) => any;
333
+ responseType?: string;
334
+ }>;
335
+ /**
336
+ * Standard endpoint handlers for CRUD operations
337
+ */
338
+ handleGetAll(req: any): Promise<DataResponse>;
339
+ handleCreate(req: any): Promise<DataResponse>;
340
+ handleGetById(req: any): Promise<DataResponse>;
341
+ handleUpdate(req: any): Promise<DataResponse>;
342
+ handleDelete(req: any): Promise<DataResponse>;
343
+ }
344
+ //# sourceMappingURL=custom_table_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom_table_manager.d.ts","sourceRoot":"","sources":["../../src/components/custom_table_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAsB,YAAY,EAAE,MAAM,YAAY,CAAA;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;CACvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,gBAAgB,IAAI,kBAAkB,CAAA;CACzC;AAED,8BAAsB,kBAAmB,YAAW,oBAAoB,EAAE,QAAQ;IAC9E,2CAA2C;IAC3C,SAAS,CAAC,EAAE,EAAG,eAAe,CAAA;IAE9B,2CAA2C;IAC3C,SAAS,CAAC,SAAS,EAAG,MAAM,CAAA;IAE5B;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,IAAI;IAK1C;;;;;;;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