digitaltwin-core 0.13.3 → 0.14.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.
- package/package.json +101 -106
- package/dist/auth/apisix_parser.d.ts +0 -146
- package/dist/auth/apisix_parser.d.ts.map +0 -1
- package/dist/auth/apisix_parser.js +0 -185
- package/dist/auth/apisix_parser.js.map +0 -1
- package/dist/auth/auth_config.d.ts +0 -126
- package/dist/auth/auth_config.d.ts.map +0 -1
- package/dist/auth/auth_config.js +0 -169
- package/dist/auth/auth_config.js.map +0 -1
- package/dist/auth/index.d.ts +0 -5
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -4
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.d.ts +0 -100
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/auth/user_service.d.ts +0 -86
- package/dist/auth/user_service.d.ts.map +0 -1
- package/dist/auth/user_service.js +0 -237
- package/dist/auth/user_service.js.map +0 -1
- package/dist/components/assets_manager.d.ts +0 -662
- package/dist/components/assets_manager.d.ts.map +0 -1
- package/dist/components/assets_manager.js +0 -1529
- package/dist/components/assets_manager.js.map +0 -1
- package/dist/components/async_upload.d.ts +0 -20
- package/dist/components/async_upload.d.ts.map +0 -1
- package/dist/components/async_upload.js +0 -10
- package/dist/components/async_upload.js.map +0 -1
- package/dist/components/collector.d.ts +0 -203
- package/dist/components/collector.d.ts.map +0 -1
- package/dist/components/collector.js +0 -202
- package/dist/components/collector.js.map +0 -1
- package/dist/components/custom_table_manager.d.ts +0 -503
- package/dist/components/custom_table_manager.d.ts.map +0 -1
- package/dist/components/custom_table_manager.js +0 -1052
- package/dist/components/custom_table_manager.js.map +0 -1
- package/dist/components/global_assets_handler.d.ts +0 -63
- package/dist/components/global_assets_handler.d.ts.map +0 -1
- package/dist/components/global_assets_handler.js +0 -127
- package/dist/components/global_assets_handler.js.map +0 -1
- package/dist/components/handler.d.ts +0 -104
- package/dist/components/handler.d.ts.map +0 -1
- package/dist/components/handler.js +0 -110
- package/dist/components/handler.js.map +0 -1
- package/dist/components/harvester.d.ts +0 -182
- package/dist/components/harvester.d.ts.map +0 -1
- package/dist/components/harvester.js +0 -393
- package/dist/components/harvester.js.map +0 -1
- package/dist/components/index.d.ts +0 -11
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -9
- package/dist/components/index.js.map +0 -1
- package/dist/components/interfaces.d.ts +0 -126
- package/dist/components/interfaces.d.ts.map +0 -1
- package/dist/components/interfaces.js +0 -8
- package/dist/components/interfaces.js.map +0 -1
- package/dist/components/map_manager.d.ts +0 -61
- package/dist/components/map_manager.d.ts.map +0 -1
- package/dist/components/map_manager.js +0 -242
- package/dist/components/map_manager.js.map +0 -1
- package/dist/components/tileset_manager.d.ts +0 -125
- package/dist/components/tileset_manager.d.ts.map +0 -1
- package/dist/components/tileset_manager.js +0 -618
- package/dist/components/tileset_manager.js.map +0 -1
- package/dist/components/types.d.ts +0 -226
- package/dist/components/types.d.ts.map +0 -1
- package/dist/components/types.js +0 -8
- package/dist/components/types.js.map +0 -1
- package/dist/database/adapters/knex_database_adapter.d.ts +0 -92
- package/dist/database/adapters/knex_database_adapter.d.ts.map +0 -1
- package/dist/database/adapters/knex_database_adapter.js +0 -647
- package/dist/database/adapters/knex_database_adapter.js.map +0 -1
- package/dist/database/database_adapter.d.ts +0 -251
- package/dist/database/database_adapter.d.ts.map +0 -1
- package/dist/database/database_adapter.js +0 -46
- package/dist/database/database_adapter.js.map +0 -1
- package/dist/engine/digital_twin_engine.d.ts +0 -253
- package/dist/engine/digital_twin_engine.d.ts.map +0 -1
- package/dist/engine/digital_twin_engine.js +0 -790
- package/dist/engine/digital_twin_engine.js.map +0 -1
- package/dist/engine/endpoints.d.ts +0 -47
- package/dist/engine/endpoints.d.ts.map +0 -1
- package/dist/engine/endpoints.js +0 -56
- package/dist/engine/endpoints.js.map +0 -1
- package/dist/engine/events.d.ts +0 -93
- package/dist/engine/events.d.ts.map +0 -1
- package/dist/engine/events.js +0 -71
- package/dist/engine/events.js.map +0 -1
- package/dist/engine/initializer.d.ts +0 -62
- package/dist/engine/initializer.d.ts.map +0 -1
- package/dist/engine/initializer.js +0 -108
- package/dist/engine/initializer.js.map +0 -1
- package/dist/engine/queue_manager.d.ts +0 -87
- package/dist/engine/queue_manager.d.ts.map +0 -1
- package/dist/engine/queue_manager.js +0 -196
- package/dist/engine/queue_manager.js.map +0 -1
- package/dist/engine/scheduler.d.ts +0 -30
- package/dist/engine/scheduler.d.ts.map +0 -1
- package/dist/engine/scheduler.js +0 -370
- package/dist/engine/scheduler.js.map +0 -1
- package/dist/engine/upload_processor.d.ts +0 -36
- package/dist/engine/upload_processor.d.ts.map +0 -1
- package/dist/engine/upload_processor.js +0 -101
- package/dist/engine/upload_processor.js.map +0 -1
- package/dist/env/env.d.ts +0 -134
- package/dist/env/env.d.ts.map +0 -1
- package/dist/env/env.js +0 -177
- package/dist/env/env.js.map +0 -1
- package/dist/index.d.ts +0 -49
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -57
- package/dist/index.js.map +0 -1
- package/dist/openapi/generator.d.ts +0 -93
- package/dist/openapi/generator.d.ts.map +0 -1
- package/dist/openapi/generator.js +0 -293
- package/dist/openapi/generator.js.map +0 -1
- package/dist/openapi/index.d.ts +0 -9
- package/dist/openapi/index.d.ts.map +0 -1
- package/dist/openapi/index.js +0 -9
- package/dist/openapi/index.js.map +0 -1
- package/dist/openapi/types.d.ts +0 -182
- package/dist/openapi/types.d.ts.map +0 -1
- package/dist/openapi/types.js +0 -16
- package/dist/openapi/types.js.map +0 -1
- package/dist/storage/adapters/local_storage_service.d.ts +0 -51
- package/dist/storage/adapters/local_storage_service.d.ts.map +0 -1
- package/dist/storage/adapters/local_storage_service.js +0 -110
- package/dist/storage/adapters/local_storage_service.js.map +0 -1
- package/dist/storage/adapters/ovh_storage_service.d.ts +0 -61
- package/dist/storage/adapters/ovh_storage_service.d.ts.map +0 -1
- package/dist/storage/adapters/ovh_storage_service.js +0 -172
- package/dist/storage/adapters/ovh_storage_service.js.map +0 -1
- package/dist/storage/storage_factory.d.ts +0 -14
- package/dist/storage/storage_factory.d.ts.map +0 -1
- package/dist/storage/storage_factory.js +0 -36
- package/dist/storage/storage_factory.js.map +0 -1
- package/dist/storage/storage_service.d.ts +0 -163
- package/dist/storage/storage_service.d.ts.map +0 -1
- package/dist/storage/storage_service.js +0 -54
- package/dist/storage/storage_service.js.map +0 -1
- package/dist/types/data_record.d.ts +0 -123
- package/dist/types/data_record.d.ts.map +0 -1
- package/dist/types/data_record.js +0 -8
- package/dist/types/data_record.js.map +0 -1
- package/dist/utils/http_responses.d.ts +0 -155
- package/dist/utils/http_responses.d.ts.map +0 -1
- package/dist/utils/http_responses.js +0 -190
- package/dist/utils/http_responses.js.map +0 -1
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -74
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -92
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/map_to_data_record.d.ts +0 -10
- package/dist/utils/map_to_data_record.d.ts.map +0 -1
- package/dist/utils/map_to_data_record.js +0 -36
- package/dist/utils/map_to_data_record.js.map +0 -1
- package/dist/utils/servable_endpoint.d.ts +0 -63
- package/dist/utils/servable_endpoint.d.ts.map +0 -1
- package/dist/utils/servable_endpoint.js +0 -67
- package/dist/utils/servable_endpoint.js.map +0 -1
- package/dist/utils/zip_utils.d.ts +0 -66
- package/dist/utils/zip_utils.d.ts.map +0 -1
- package/dist/utils/zip_utils.js +0 -169
- package/dist/utils/zip_utils.js.map +0 -1
|
@@ -1,503 +0,0 @@
|
|
|
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
|
-
import type { UserRecord } from '../auth/types.js';
|
|
6
|
-
import type { OpenAPIDocumentable, OpenAPIComponentSpec } from '../openapi/types.js';
|
|
7
|
-
import { UserService } from '../auth/user_service.js';
|
|
8
|
-
/**
|
|
9
|
-
* Record representing a row in the custom table
|
|
10
|
-
*/
|
|
11
|
-
export interface CustomTableRecord {
|
|
12
|
-
id: number;
|
|
13
|
-
owner_id?: number;
|
|
14
|
-
created_at: Date;
|
|
15
|
-
updated_at: Date;
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Query validation options
|
|
20
|
-
*/
|
|
21
|
-
export interface QueryValidationOptions {
|
|
22
|
-
/** Required fields that must have non-empty values */
|
|
23
|
-
required?: string[];
|
|
24
|
-
/** Custom validation function */
|
|
25
|
-
validate?: (conditions: Record<string, any>) => void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Abstract base class for Custom Table Manager components in the Digital Twin framework.
|
|
29
|
-
*
|
|
30
|
-
* A CustomTableManager is responsible for:
|
|
31
|
-
* - Managing structured data in database tables with custom columns
|
|
32
|
-
* - Providing CRUD operations for the data with validation
|
|
33
|
-
* - Exposing HTTP endpoints for data manipulation
|
|
34
|
-
* - Creating and managing database schema automatically
|
|
35
|
-
*
|
|
36
|
-
* Unlike other components, CustomTableManager does NOT handle files - only structured data.
|
|
37
|
-
*
|
|
38
|
-
* @abstract
|
|
39
|
-
* @class CustomTableManager
|
|
40
|
-
* @implements {Component}
|
|
41
|
-
* @implements {Servable}
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* class WMSManager extends CustomTableManager {
|
|
46
|
-
* getConfiguration(): StoreConfiguration {
|
|
47
|
-
* return {
|
|
48
|
-
* name: 'wms_layers',
|
|
49
|
-
* description: 'Manage WMS layers for mapping',
|
|
50
|
-
* columns: {
|
|
51
|
-
* 'wms_url': 'text not null',
|
|
52
|
-
* 'layer_name': 'text not null',
|
|
53
|
-
* 'description': 'text',
|
|
54
|
-
* 'active': 'boolean default true'
|
|
55
|
-
* },
|
|
56
|
-
* endpoints: [
|
|
57
|
-
* { path: '/add-layers', method: 'post', handler: 'addLayers' }
|
|
58
|
-
* ]
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* async addLayers(req: any): Promise<DataResponse> {
|
|
63
|
-
* // Custom endpoint implementation
|
|
64
|
-
* }
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* Base component interface for CustomTableManager (doesn't extend ComponentConfiguration)
|
|
70
|
-
*/
|
|
71
|
-
export interface CustomTableComponent {
|
|
72
|
-
getConfiguration(): StoreConfiguration;
|
|
73
|
-
}
|
|
74
|
-
export declare abstract class CustomTableManager implements CustomTableComponent, Servable, OpenAPIDocumentable {
|
|
75
|
-
/** Database adapter for data operations */
|
|
76
|
-
protected db: DatabaseAdapter;
|
|
77
|
-
/** User service for authentication and authorization */
|
|
78
|
-
protected userService: UserService;
|
|
79
|
-
/** Cached table name from configuration */
|
|
80
|
-
protected tableName: string;
|
|
81
|
-
/**
|
|
82
|
-
* Injects required dependencies into the custom table manager instance.
|
|
83
|
-
*
|
|
84
|
-
* Called by the Digital Twin Engine during component initialization.
|
|
85
|
-
*
|
|
86
|
-
* @param {DatabaseAdapter} db - Database adapter for data operations
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const customTableManager = new MyCustomTableManager()
|
|
91
|
-
* customTableManager.setDependencies(databaseAdapter)
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
setDependencies(db: DatabaseAdapter): void;
|
|
95
|
-
/**
|
|
96
|
-
* Returns the static configuration defining this custom table manager's behavior.
|
|
97
|
-
*
|
|
98
|
-
* The configuration includes the table name, description,
|
|
99
|
-
* custom columns definition, and optional custom endpoints.
|
|
100
|
-
*
|
|
101
|
-
* @abstract
|
|
102
|
-
* @returns {StoreConfiguration} The table configuration
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* getConfiguration(): StoreConfiguration {
|
|
107
|
-
* return {
|
|
108
|
-
* name: 'sensors',
|
|
109
|
-
* description: 'IoT sensors data store',
|
|
110
|
-
* columns: {
|
|
111
|
-
* 'sensor_id': 'text unique not null',
|
|
112
|
-
* 'type': 'text not null',
|
|
113
|
-
* 'location': 'text',
|
|
114
|
-
* 'active': 'boolean default true',
|
|
115
|
-
* 'last_ping': 'timestamp'
|
|
116
|
-
* }
|
|
117
|
-
* }
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
abstract getConfiguration(): StoreConfiguration;
|
|
122
|
-
/**
|
|
123
|
-
* Initialize the database table with custom columns.
|
|
124
|
-
*
|
|
125
|
-
* Creates the table if it doesn't exist, with standard columns (id, created_at, updated_at)
|
|
126
|
-
* plus the custom columns defined in the configuration.
|
|
127
|
-
* Automatically adds an 'owner_id' column for user ownership tracking.
|
|
128
|
-
*
|
|
129
|
-
* @returns {Promise<void>}
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* // Called automatically by the framework
|
|
134
|
-
* await customTableManager.initializeTable()
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
initializeTable(): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Validate query conditions against requirements.
|
|
140
|
-
*
|
|
141
|
-
* @private
|
|
142
|
-
* @param {Record<string, any>} conditions - Conditions to validate
|
|
143
|
-
* @param {QueryValidationOptions} options - Validation options
|
|
144
|
-
* @throws {Error} If validation fails
|
|
145
|
-
*/
|
|
146
|
-
private validateQuery;
|
|
147
|
-
/**
|
|
148
|
-
* Create a new record in the custom table.
|
|
149
|
-
*
|
|
150
|
-
* @param {Record<string, any>} data - Data to insert (excluding id, created_at, updated_at)
|
|
151
|
-
* @returns {Promise<number>} The ID of the created record
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* const id = await customTableManager.create({
|
|
156
|
-
* sensor_id: 'TEMP001',
|
|
157
|
-
* type: 'temperature',
|
|
158
|
-
* location: 'Building A - Floor 1',
|
|
159
|
-
* active: true
|
|
160
|
-
* })
|
|
161
|
-
* console.log(`Created sensor with ID: ${id}`)
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
create(data: Record<string, any>): Promise<number>;
|
|
165
|
-
/**
|
|
166
|
-
* Find all records in the custom table.
|
|
167
|
-
*
|
|
168
|
-
* @returns {Promise<CustomTableRecord[]>} Array of all records
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* const allSensors = await customTableManager.findAll()
|
|
173
|
-
* console.log(`Found ${allSensors.length} sensors`)
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
findAll(): Promise<CustomTableRecord[]>;
|
|
177
|
-
/**
|
|
178
|
-
* Find a record by its ID.
|
|
179
|
-
*
|
|
180
|
-
* @param {number} id - The record ID to find
|
|
181
|
-
* @returns {Promise<CustomTableRecord | null>} The record or null if not found
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const sensor = await customTableManager.findById(123)
|
|
186
|
-
* if (sensor) {
|
|
187
|
-
* console.log(`Sensor: ${sensor.sensor_id}`)
|
|
188
|
-
* }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
findById(id: number): Promise<CustomTableRecord | null>;
|
|
192
|
-
/**
|
|
193
|
-
* Find records by a single column value with optional validation.
|
|
194
|
-
*
|
|
195
|
-
* @param {string} columnName - Name of the column to search by
|
|
196
|
-
* @param {any} value - Value to search for
|
|
197
|
-
* @param {boolean} required - Whether the value is required (default: true)
|
|
198
|
-
* @returns {Promise<CustomTableRecord[]>} Array of matching records
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```typescript
|
|
202
|
-
* const wmsLayers = await wmsManager.findByColumn('wms_url', 'https://example.com/wms')
|
|
203
|
-
* const activeLayers = await wmsManager.findByColumn('active', true)
|
|
204
|
-
*
|
|
205
|
-
* // Optional value (won't throw if empty)
|
|
206
|
-
* const layers = await wmsManager.findByColumn('description', '', false)
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
findByColumn(columnName: string, value: any, required?: boolean): Promise<CustomTableRecord[]>;
|
|
210
|
-
/**
|
|
211
|
-
* Find records by multiple column values with validation support.
|
|
212
|
-
*
|
|
213
|
-
* @param {Record<string, any>} conditions - Key-value pairs to match
|
|
214
|
-
* @param {QueryValidationOptions} options - Validation options
|
|
215
|
-
* @returns {Promise<CustomTableRecord[]>} Array of matching records
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* // Simple query
|
|
220
|
-
* const layers = await wmsManager.findByColumns({
|
|
221
|
-
* wms_url: 'https://example.com/wms',
|
|
222
|
-
* active: true
|
|
223
|
-
* })
|
|
224
|
-
*
|
|
225
|
-
* // With validation
|
|
226
|
-
* const layers = await wmsManager.findByColumns(
|
|
227
|
-
* { wms_url: wmsUrl, projection: projection },
|
|
228
|
-
* {
|
|
229
|
-
* required: ['wms_url', 'projection'],
|
|
230
|
-
* validate: (conditions) => {
|
|
231
|
-
* if (!conditions.wms_url.startsWith('http')) {
|
|
232
|
-
* throw new Error('WMS URL must start with http or https')
|
|
233
|
-
* }
|
|
234
|
-
* }
|
|
235
|
-
* }
|
|
236
|
-
* )
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
findByColumns(conditions: Record<string, any>, options?: QueryValidationOptions): Promise<CustomTableRecord[]>;
|
|
240
|
-
/**
|
|
241
|
-
* Find records matching specific conditions (base method).
|
|
242
|
-
*
|
|
243
|
-
* @param {Record<string, any>} conditions - Key-value pairs to match
|
|
244
|
-
* @returns {Promise<CustomTableRecord[]>} Array of matching records
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```typescript
|
|
248
|
-
* const activeSensors = await customTableManager.findByCondition({ active: true })
|
|
249
|
-
* const tempSensors = await customTableManager.findByCondition({ type: 'temperature' })
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
findByCondition(conditions: Record<string, any>): Promise<CustomTableRecord[]>;
|
|
253
|
-
/**
|
|
254
|
-
* Update a record by its ID.
|
|
255
|
-
*
|
|
256
|
-
* @param {number} id - The record ID to update
|
|
257
|
-
* @param {Record<string, any>} data - Data to update (excluding id, created_at)
|
|
258
|
-
* @returns {Promise<void>}
|
|
259
|
-
*
|
|
260
|
-
* @example
|
|
261
|
-
* ```typescript
|
|
262
|
-
* await customTableManager.update(123, {
|
|
263
|
-
* active: false,
|
|
264
|
-
* last_ping: new Date()
|
|
265
|
-
* })
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
update(id: number, data: Record<string, any>): Promise<void>;
|
|
269
|
-
/**
|
|
270
|
-
* Delete a record by its ID.
|
|
271
|
-
*
|
|
272
|
-
* @param {number} id - The record ID to delete
|
|
273
|
-
* @returns {Promise<void>}
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```typescript
|
|
277
|
-
* await customTableManager.delete(123)
|
|
278
|
-
* console.log('Sensor deleted successfully')
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
delete(id: number): Promise<void>;
|
|
282
|
-
/**
|
|
283
|
-
* Delete records by a single column value.
|
|
284
|
-
*
|
|
285
|
-
* @param {string} columnName - Name of the column to match for deletion
|
|
286
|
-
* @param {any} value - Value to match for deletion
|
|
287
|
-
* @returns {Promise<number>} Number of records deleted
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```typescript
|
|
291
|
-
* const deleted = await wmsManager.deleteByColumn('active', false)
|
|
292
|
-
* console.log(`Deleted ${deleted} inactive layers`)
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
deleteByColumn(columnName: string, value: any): Promise<number>;
|
|
296
|
-
/**
|
|
297
|
-
* Delete records matching specific conditions.
|
|
298
|
-
*
|
|
299
|
-
* @param {Record<string, any>} conditions - Key-value pairs to match for deletion
|
|
300
|
-
* @returns {Promise<number>} Number of records deleted
|
|
301
|
-
*
|
|
302
|
-
* @example
|
|
303
|
-
* ```typescript
|
|
304
|
-
* const deleted = await customTableManager.deleteByCondition({ active: false })
|
|
305
|
-
* console.log(`Deleted ${deleted} inactive sensors`)
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
deleteByCondition(conditions: Record<string, any>): Promise<number>;
|
|
309
|
-
/**
|
|
310
|
-
* Extract custom fields from a database record, excluding framework fields.
|
|
311
|
-
*
|
|
312
|
-
* @private
|
|
313
|
-
* @param {any} record - Database record
|
|
314
|
-
* @returns {Record<string, any>} Custom fields only (including owner_id)
|
|
315
|
-
*/
|
|
316
|
-
private extractCustomFields;
|
|
317
|
-
/**
|
|
318
|
-
* AUTHENTICATION HELPERS
|
|
319
|
-
* These methods help custom endpoints implement authentication and authorization.
|
|
320
|
-
*/
|
|
321
|
-
/**
|
|
322
|
-
* Authenticate a request and return the user record.
|
|
323
|
-
*
|
|
324
|
-
* Use this for endpoints that require authentication but don't need ownership checks.
|
|
325
|
-
*
|
|
326
|
-
* @protected
|
|
327
|
-
* @param {any} req - HTTP request object
|
|
328
|
-
* @returns {Promise<UserRecord | null>} User record if authenticated, null otherwise
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```typescript
|
|
332
|
-
* async myCustomEndpoint(req: any): Promise<DataResponse> {
|
|
333
|
-
* const userRecord = await this.authenticateRequest(req)
|
|
334
|
-
* if (!userRecord) {
|
|
335
|
-
* return this.authErrorResponse()
|
|
336
|
-
* }
|
|
337
|
-
*
|
|
338
|
-
* // Use userRecord.id for your logic
|
|
339
|
-
* console.log(`User ${userRecord.id} is authenticated`)
|
|
340
|
-
* }
|
|
341
|
-
* ```
|
|
342
|
-
*/
|
|
343
|
-
protected authenticateRequest(req: any): Promise<UserRecord | null>;
|
|
344
|
-
/**
|
|
345
|
-
* Authenticate a request and verify the user owns the specified record.
|
|
346
|
-
*
|
|
347
|
-
* Use this for endpoints that modify or delete specific records.
|
|
348
|
-
*
|
|
349
|
-
* @protected
|
|
350
|
-
* @param {any} req - HTTP request object
|
|
351
|
-
* @param {number} recordId - ID of the record to check ownership for
|
|
352
|
-
* @returns {Promise<{ userRecord: UserRecord; record: CustomTableRecord } | null>}
|
|
353
|
-
* Both user and record if authenticated and owns the record, null otherwise
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* ```typescript
|
|
357
|
-
* async deleteMyRecord(req: any): Promise<DataResponse> {
|
|
358
|
-
* const recordId = parseInt(req.params.id)
|
|
359
|
-
* const auth = await this.authenticateAndCheckOwnership(req, recordId)
|
|
360
|
-
*
|
|
361
|
-
* if (!auth) {
|
|
362
|
-
* return this.authErrorResponse()
|
|
363
|
-
* }
|
|
364
|
-
*
|
|
365
|
-
* if (auth.record.owner_id !== auth.userRecord.id) {
|
|
366
|
-
* return this.forbiddenErrorResponse()
|
|
367
|
-
* }
|
|
368
|
-
*
|
|
369
|
-
* await this.delete(recordId)
|
|
370
|
-
* return { status: 200, content: JSON.stringify({ message: 'Deleted' }) }
|
|
371
|
-
* }
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
|
-
protected authenticateAndCheckOwnership(req: any, recordId: number): Promise<{
|
|
375
|
-
userRecord: UserRecord;
|
|
376
|
-
record: CustomTableRecord;
|
|
377
|
-
} | null>;
|
|
378
|
-
/**
|
|
379
|
-
* Get authenticated user from request, throwing an error response if not authenticated.
|
|
380
|
-
*
|
|
381
|
-
* Use this when authentication is required and you want to fail fast.
|
|
382
|
-
*
|
|
383
|
-
* @protected
|
|
384
|
-
* @param {any} req - HTTP request object
|
|
385
|
-
* @returns {Promise<UserRecord | DataResponse>} User record if authenticated, error response otherwise
|
|
386
|
-
*
|
|
387
|
-
* @example
|
|
388
|
-
* ```typescript
|
|
389
|
-
* async myProtectedEndpoint(req: any): Promise<DataResponse> {
|
|
390
|
-
* const userOrError = await this.requireAuthentication(req)
|
|
391
|
-
* if ('status' in userOrError) {
|
|
392
|
-
* return userOrError // Return error response
|
|
393
|
-
* }
|
|
394
|
-
*
|
|
395
|
-
* const userRecord = userOrError
|
|
396
|
-
* // Continue with authenticated user
|
|
397
|
-
* }
|
|
398
|
-
* ```
|
|
399
|
-
*/
|
|
400
|
-
protected requireAuthentication(req: any): Promise<UserRecord | DataResponse>;
|
|
401
|
-
/**
|
|
402
|
-
* Helper to return a 401 Unauthorized error response.
|
|
403
|
-
*
|
|
404
|
-
* @protected
|
|
405
|
-
* @param {string} message - Custom error message (default: "Authentication required")
|
|
406
|
-
* @returns {DataResponse} 401 error response
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
* ```typescript
|
|
410
|
-
* if (!userRecord) {
|
|
411
|
-
* return this.authErrorResponse()
|
|
412
|
-
* }
|
|
413
|
-
* ```
|
|
414
|
-
*/
|
|
415
|
-
protected authErrorResponse(message?: string): DataResponse;
|
|
416
|
-
/**
|
|
417
|
-
* Helper to return a 403 Forbidden error response.
|
|
418
|
-
*
|
|
419
|
-
* @protected
|
|
420
|
-
* @param {string} message - Custom error message (default: "You don't have permission to access this resource")
|
|
421
|
-
* @returns {DataResponse} 403 error response
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* ```typescript
|
|
425
|
-
* if (record.owner_id !== userRecord.id) {
|
|
426
|
-
* return this.forbiddenErrorResponse('You can only modify your own records')
|
|
427
|
-
* }
|
|
428
|
-
* ```
|
|
429
|
-
*/
|
|
430
|
-
protected forbiddenErrorResponse(message?: string): DataResponse;
|
|
431
|
-
/**
|
|
432
|
-
* Helper to check if a user owns a specific record.
|
|
433
|
-
*
|
|
434
|
-
* Returns false if the record doesn't have an owner_id (legacy records without ownership).
|
|
435
|
-
*
|
|
436
|
-
* @protected
|
|
437
|
-
* @param {CustomTableRecord} record - The record to check
|
|
438
|
-
* @param {UserRecord} userRecord - The user to check against
|
|
439
|
-
* @returns {boolean} True if user owns the record, false otherwise
|
|
440
|
-
*
|
|
441
|
-
* @example
|
|
442
|
-
* ```typescript
|
|
443
|
-
* const record = await this.findById(recordId)
|
|
444
|
-
* const userRecord = await this.authenticateRequest(req)
|
|
445
|
-
*
|
|
446
|
-
* if (!this.userOwnsRecord(record, userRecord)) {
|
|
447
|
-
* return this.forbiddenErrorResponse()
|
|
448
|
-
* }
|
|
449
|
-
* ```
|
|
450
|
-
*/
|
|
451
|
-
protected userOwnsRecord(record: CustomTableRecord, userRecord: UserRecord): boolean;
|
|
452
|
-
/**
|
|
453
|
-
* Get HTTP endpoints exposed by this custom table manager.
|
|
454
|
-
*
|
|
455
|
-
* Returns both standard CRUD endpoints and custom endpoints defined in configuration.
|
|
456
|
-
*
|
|
457
|
-
* @returns {Array} Array of endpoint descriptors with methods, paths, and handlers
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```typescript
|
|
461
|
-
* // Standard endpoints for a table named 'sensors':
|
|
462
|
-
* GET /sensors - Get all records
|
|
463
|
-
* POST /sensors - Create new record
|
|
464
|
-
* GET /sensors/:id - Get specific record
|
|
465
|
-
* PUT /sensors/:id - Update specific record
|
|
466
|
-
* DELETE /sensors/:id - Delete specific record
|
|
467
|
-
*
|
|
468
|
-
* // Plus any custom endpoints defined in configuration
|
|
469
|
-
* ```
|
|
470
|
-
*/
|
|
471
|
-
getEndpoints(): Array<{
|
|
472
|
-
method: HttpMethod;
|
|
473
|
-
path: string;
|
|
474
|
-
handler: (...args: any[]) => any;
|
|
475
|
-
responseType?: string;
|
|
476
|
-
}>;
|
|
477
|
-
/**
|
|
478
|
-
* Returns the OpenAPI specification for this custom table manager's endpoints.
|
|
479
|
-
*
|
|
480
|
-
* Generates documentation for all CRUD endpoints and custom endpoints.
|
|
481
|
-
* Can be overridden by subclasses for more detailed specifications.
|
|
482
|
-
*
|
|
483
|
-
* @returns {OpenAPIComponentSpec} OpenAPI paths, tags, and schemas for this custom table manager
|
|
484
|
-
*/
|
|
485
|
-
getOpenAPISpec(): OpenAPIComponentSpec;
|
|
486
|
-
/**
|
|
487
|
-
* Convert SQL column definition to OpenAPI schema type.
|
|
488
|
-
*
|
|
489
|
-
* @private
|
|
490
|
-
* @param {string} columnDef - SQL column definition (e.g., 'text not null', 'integer default 0')
|
|
491
|
-
* @returns {object} OpenAPI schema object
|
|
492
|
-
*/
|
|
493
|
-
private columnDefToOpenAPISchema;
|
|
494
|
-
/**
|
|
495
|
-
* Standard endpoint handlers for CRUD operations
|
|
496
|
-
*/
|
|
497
|
-
handleGetAll(_req: any): Promise<DataResponse>;
|
|
498
|
-
handleCreate(req: any): Promise<DataResponse>;
|
|
499
|
-
handleGetById(req: any): Promise<DataResponse>;
|
|
500
|
-
handleUpdate(req: any): Promise<DataResponse>;
|
|
501
|
-
handleDelete(req: any): Promise<DataResponse>;
|
|
502
|
-
}
|
|
503
|
-
//# sourceMappingURL=custom_table_manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom_table_manager.d.ts","sourceRoot":"","sources":["../../src/components/custom_table_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,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