@tmlmobilidade/databases 20260326.2139.30 → 20260327.0.15

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,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { PCGIRawClient } from '../../clients/pcgi-raw.js';
2
+ import { PCGIValidationsClient } from '../../clients/pcgi-validations.js';
3
3
  import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
@@ -32,7 +32,7 @@ class PCGILocationsClass extends MongoInterfaceTemplate {
32
32
  return await this._instance;
33
33
  }
34
34
  connectToClient() {
35
- return PCGIRawClient.getClient();
35
+ return PCGIValidationsClient.getClient();
36
36
  }
37
37
  }
38
38
  /* * */
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { PCGIRawClient } from '../../clients/pcgi-raw.js';
2
+ import { PCGITicketingClient } from '../../clients/pcgi-ticketing.js';
3
3
  import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
@@ -32,7 +32,7 @@ class PCGISalesClass extends MongoInterfaceTemplate {
32
32
  return await this._instance;
33
33
  }
34
34
  connectToClient() {
35
- return PCGIRawClient.getClient();
35
+ return PCGITicketingClient.getClient();
36
36
  }
37
37
  }
38
38
  /* * */
@@ -1,5 +1,5 @@
1
1
  /* * */
2
- import { PCGIRawClient } from '../../clients/pcgi-raw.js';
2
+ import { PCGIFileManagerClient } from '../../clients/pcgi-file-manager.js';
3
3
  import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
4
4
  import { RawVehicleEventSchema } from '@tmlmobilidade/types';
5
5
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
@@ -38,7 +38,7 @@ class RawVehicleEventsNewClass extends MongoInterfaceTemplate {
38
38
  return await this._instance;
39
39
  }
40
40
  connectToClient() {
41
- return PCGIRawClient.getClient();
41
+ return PCGIFileManagerClient.getClient();
42
42
  }
43
43
  }
44
44
  /* * */
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { PCGIRawClient } from '../../clients/pcgi-raw.js';
2
+ import { PCGIValidationsClient } from '../../clients/pcgi-validations.js';
3
3
  import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
@@ -32,7 +32,7 @@ class PCGIValidationsClass extends MongoInterfaceTemplate {
32
32
  return await this._instance;
33
33
  }
34
34
  connectToClient() {
35
- return PCGIRawClient.getClient();
35
+ return PCGIValidationsClient.getClient();
36
36
  }
37
37
  }
38
38
  /* * */
@@ -1,10 +1,10 @@
1
1
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
2
- import { type ClickHouseColumn } from '../../types/index.js';
2
+ import { type ClickHouseSchema } from '../../types/index.js';
3
3
  import { type SimplifiedApexLocation } from '@tmlmobilidade/types';
4
4
  declare class SimplifiedApexLocationsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexLocation> {
5
5
  private static _instance;
6
6
  protected readonly databaseName = "operation";
7
- protected readonly schema: ClickHouseColumn<{
7
+ protected readonly schema: ClickHouseSchema<{
8
8
  _id: string;
9
9
  created_at: number & {
10
10
  __brand: "UnixTimestamp";
@@ -25,7 +25,7 @@ declare class SimplifiedApexLocationsNewClass extends ClickHouseInterfaceTemplat
25
25
  stop_id: string;
26
26
  trip_id: string;
27
27
  vehicle_id: number;
28
- }>[];
28
+ }>;
29
29
  protected readonly tableName = "simplified_apex_locations";
30
30
  /**
31
31
  * Returns the singleton instance of the subclass.
@@ -3,22 +3,22 @@ import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
3
3
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
- const tableSchema = [
7
- { name: '_id', primaryKey: true, type: 'String' },
8
- { name: 'created_at', type: 'Int64' },
9
- { name: 'updated_at', type: 'Int64' },
10
- { name: 'agency_id', type: 'String' },
11
- { name: 'apex_version', type: 'String' },
12
- { name: 'device_id', type: 'String' },
13
- { name: 'line_id', type: 'String' },
14
- { name: 'mac_ase_counter_value', type: 'Int64' },
15
- { name: 'mac_sam_serial_number', type: 'Int64' },
16
- { name: 'pattern_id', type: 'String' },
17
- { name: 'received_at', type: 'Int64' },
18
- { name: 'stop_id', type: 'String' },
19
- { name: 'trip_id', type: 'String' },
20
- { name: 'vehicle_id', type: 'Int64' },
21
- ];
6
+ const tableSchema = {
7
+ _id: { primaryKey: true, type: 'String' },
8
+ agency_id: { type: 'String' },
9
+ apex_version: { type: 'String' },
10
+ created_at: { type: 'Int64' },
11
+ device_id: { type: 'String' },
12
+ line_id: { type: 'String' },
13
+ mac_ase_counter_value: { type: 'Int64' },
14
+ mac_sam_serial_number: { type: 'Int64' },
15
+ pattern_id: { type: 'String' },
16
+ received_at: { type: 'Int64' },
17
+ stop_id: { type: 'String' },
18
+ trip_id: { type: 'String' },
19
+ updated_at: { type: 'Int64' },
20
+ vehicle_id: { type: 'String' },
21
+ };
22
22
  /* * */
23
23
  class SimplifiedApexLocationsNewClass extends ClickHouseInterfaceTemplate {
24
24
  //
@@ -1,10 +1,10 @@
1
1
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
2
- import { type ClickHouseColumn } from '../../types/index.js';
2
+ import { type ClickHouseSchema } from '../../types/index.js';
3
3
  import { type SimplifiedApexOnBoardRefund } from '@tmlmobilidade/types';
4
4
  declare class SimplifiedApexOnBoardRefundsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexOnBoardRefund> {
5
5
  private static _instance;
6
6
  protected readonly databaseName = "operation";
7
- protected readonly schema: ClickHouseColumn<{
7
+ protected readonly schema: ClickHouseSchema<{
8
8
  _id: string;
9
9
  created_at: number & {
10
10
  __brand: "UnixTimestamp";
@@ -35,7 +35,7 @@ declare class SimplifiedApexOnBoardRefundsNewClass extends ClickHouseInterfaceTe
35
35
  product_long_id: string;
36
36
  product_quantity: number;
37
37
  validation_id: string | null;
38
- }>[];
38
+ }>;
39
39
  protected readonly tableName = "simplified_apex_on_board_refunds";
40
40
  /**
41
41
  * Returns the singleton instance of the subclass.
@@ -3,32 +3,32 @@ import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
3
3
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
- const tableSchema = [
7
- { name: '_id', type: 'String' },
8
- { name: 'created_at', type: 'String' },
9
- { name: 'updated_at', type: 'String' },
10
- { name: 'agency_id', type: 'String' },
11
- { name: 'apex_version', type: 'String' },
12
- { name: 'device_id', type: 'String' },
13
- { name: 'line_id', type: 'String' },
14
- { name: 'mac_ase_counter_value', type: 'String' },
15
- { name: 'mac_sam_serial_number', type: 'String' },
16
- { name: 'pattern_id', type: 'String' },
17
- { name: 'received_at', type: 'String' },
18
- { name: 'stop_id', type: 'String' },
19
- { name: 'trip_id', type: 'String' },
20
- { name: 'vehicle_id', type: 'String' },
21
- { name: 'block_id', type: 'String' },
22
- { name: 'card_physical_type', type: 'String' },
23
- { name: 'card_serial_number', type: 'String' },
24
- { name: 'duty_id', type: 'String' },
25
- { name: 'on_board_sale_id', type: 'String' },
26
- { name: 'payment_method', type: 'String' },
27
- { name: 'price', type: 'String' },
28
- { name: 'product_long_id', type: 'String' },
29
- { name: 'product_quantity', type: 'String' },
30
- { name: 'validation_id', type: 'String' },
31
- ];
6
+ const tableSchema = {
7
+ _id: { primaryKey: true, type: 'String' },
8
+ agency_id: { type: 'String' },
9
+ apex_version: { type: 'String' },
10
+ block_id: { type: 'String' },
11
+ card_physical_type: { type: 'String' },
12
+ card_serial_number: { type: 'String' },
13
+ created_at: { type: 'Int64' },
14
+ device_id: { type: 'String' },
15
+ duty_id: { type: 'String' },
16
+ line_id: { type: 'String' },
17
+ mac_ase_counter_value: { type: 'Int64' },
18
+ mac_sam_serial_number: { type: 'Int64' },
19
+ on_board_sale_id: { type: 'Nullable(String)' },
20
+ pattern_id: { type: 'String' },
21
+ payment_method: { type: 'String' },
22
+ price: { type: 'Int64' },
23
+ product_long_id: { type: 'String' },
24
+ product_quantity: { type: 'Int64' },
25
+ received_at: { type: 'Int64' },
26
+ stop_id: { type: 'String' },
27
+ trip_id: { type: 'String' },
28
+ updated_at: { type: 'Int64' },
29
+ validation_id: { type: 'Nullable(String)' },
30
+ vehicle_id: { type: 'String' },
31
+ };
32
32
  /* * */
33
33
  class SimplifiedApexOnBoardRefundsNewClass extends ClickHouseInterfaceTemplate {
34
34
  //
@@ -1,10 +1,10 @@
1
1
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
2
- import { type ClickHouseColumn } from '../../types/index.js';
2
+ import { type ClickHouseSchema } from '../../types/index.js';
3
3
  import { type SimplifiedApexOnBoardSale } from '@tmlmobilidade/types';
4
4
  declare class SimplifiedApexOnBoardSalesNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexOnBoardSale> {
5
5
  private static _instance;
6
6
  protected readonly databaseName = "operation";
7
- protected readonly schema: ClickHouseColumn<{
7
+ protected readonly schema: ClickHouseSchema<{
8
8
  _id: string;
9
9
  created_at: number & {
10
10
  __brand: "UnixTimestamp";
@@ -36,7 +36,7 @@ declare class SimplifiedApexOnBoardSalesNewClass extends ClickHouseInterfaceTemp
36
36
  validation_id: string | null;
37
37
  is_passenger: boolean;
38
38
  on_board_refund_id: string | null;
39
- }>[];
39
+ }>;
40
40
  protected readonly tableName = "simplified_apex_on_board_sales";
41
41
  /**
42
42
  * Returns the singleton instance of the subclass.
@@ -3,33 +3,33 @@ import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
3
3
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
- const tableSchema = [
7
- { name: '_id', type: 'String' },
8
- { name: 'created_at', type: 'String' },
9
- { name: 'updated_at', type: 'String' },
10
- { name: 'agency_id', type: 'String' },
11
- { name: 'apex_version', type: 'String' },
12
- { name: 'device_id', type: 'String' },
13
- { name: 'line_id', type: 'String' },
14
- { name: 'mac_ase_counter_value', type: 'String' },
15
- { name: 'mac_sam_serial_number', type: 'String' },
16
- { name: 'pattern_id', type: 'String' },
17
- { name: 'received_at', type: 'String' },
18
- { name: 'stop_id', type: 'String' },
19
- { name: 'trip_id', type: 'String' },
20
- { name: 'vehicle_id', type: 'String' },
21
- { name: 'block_id', type: 'String' },
22
- { name: 'card_physical_type', type: 'String' },
23
- { name: 'card_serial_number', type: 'String' },
24
- { name: 'duty_id', type: 'String' },
25
- { name: 'payment_method', type: 'String' },
26
- { name: 'price', type: 'String' },
27
- { name: 'product_long_id', type: 'String' },
28
- { name: 'product_quantity', type: 'String' },
29
- { name: 'validation_id', type: 'String' },
30
- { name: 'is_passenger', type: 'String' },
31
- { name: 'on_board_refund_id', type: 'String' },
32
- ];
6
+ const tableSchema = {
7
+ _id: { primaryKey: true, type: 'String' },
8
+ agency_id: { type: 'String' },
9
+ apex_version: { type: 'String' },
10
+ block_id: { type: 'String' },
11
+ card_physical_type: { type: 'String' },
12
+ card_serial_number: { type: 'String' },
13
+ created_at: { type: 'Int64' },
14
+ device_id: { type: 'String' },
15
+ duty_id: { type: 'String' },
16
+ is_passenger: { type: 'Bool' },
17
+ line_id: { type: 'String' },
18
+ mac_ase_counter_value: { type: 'Int64' },
19
+ mac_sam_serial_number: { type: 'Int64' },
20
+ on_board_refund_id: { type: 'Nullable(String)' },
21
+ pattern_id: { type: 'String' },
22
+ payment_method: { type: 'String' },
23
+ price: { type: 'Int64' },
24
+ product_long_id: { type: 'String' },
25
+ product_quantity: { type: 'Int64' },
26
+ received_at: { type: 'Int64' },
27
+ stop_id: { type: 'String' },
28
+ trip_id: { type: 'String' },
29
+ updated_at: { type: 'Int64' },
30
+ validation_id: { type: 'Nullable(String)' },
31
+ vehicle_id: { type: 'String' },
32
+ };
33
33
  /* * */
34
34
  class SimplifiedApexOnBoardSalesNewClass extends ClickHouseInterfaceTemplate {
35
35
  //
@@ -1,10 +1,10 @@
1
1
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
2
- import { type ClickHouseColumn } from '../../types/index.js';
2
+ import { type ClickHouseSchema } from '../../types/index.js';
3
3
  import { type SimplifiedApexValidation } from '@tmlmobilidade/types';
4
4
  declare class SimplifiedApexValidationsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexValidation> {
5
5
  private static _instance;
6
6
  protected readonly databaseName = "operation";
7
- protected readonly schema: ClickHouseColumn<{
7
+ protected readonly schema: ClickHouseSchema<{
8
8
  _id: string;
9
9
  created_at: number & {
10
10
  __brand: "UnixTimestamp";
@@ -34,7 +34,7 @@ declare class SimplifiedApexValidationsNewClass extends ClickHouseInterfaceTempl
34
34
  product_id: string;
35
35
  units_qty: number | null;
36
36
  validation_status: 0 | 1 | 2 | 12 | 4 | 3 | 5 | 6 | 11 | 10 | 7 | 8 | 9 | 13;
37
- }>[];
37
+ }>;
38
38
  protected readonly tableName = "simplified_apex_validations";
39
39
  /**
40
40
  * Returns the singleton instance of the subclass.
@@ -3,31 +3,31 @@ import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
3
3
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
- const tableSchema = [
7
- { name: '_id', primaryKey: true, type: 'String' },
8
- { name: 'agency_id', type: 'String' },
9
- { name: 'apex_version', type: 'String' },
10
- { name: 'card_serial_number', type: 'String' },
11
- { name: 'category', type: 'String' },
12
- { name: 'created_at', type: 'Int64' },
13
- { name: 'device_id', type: 'String' },
14
- { name: 'event_type', type: 'Int64' },
15
- { name: 'is_passenger', type: 'Bool' },
16
- { name: 'line_id', type: 'String' },
17
- { name: 'mac_ase_counter_value', type: 'Int64' },
18
- { name: 'mac_sam_serial_number', type: 'Int64' },
19
- { name: 'on_board_refund_id', type: 'Nullable(String)' },
20
- { name: 'on_board_sale_id', type: 'Nullable(String)' },
21
- { name: 'pattern_id', type: 'String' },
22
- { name: 'product_id', type: 'String' },
23
- { name: 'received_at', type: 'Int64' },
24
- { name: 'stop_id', type: 'String' },
25
- { name: 'trip_id', type: 'String' },
26
- { name: 'units_qty', type: 'Nullable(Int64)' },
27
- { name: 'updated_at', type: 'Int64' },
28
- { name: 'validation_status', type: 'Int64' },
29
- { name: 'vehicle_id', type: 'Int64' },
30
- ];
6
+ const tableSchema = {
7
+ _id: { primaryKey: true, type: 'String' },
8
+ agency_id: { type: 'String' },
9
+ apex_version: { type: 'String' },
10
+ card_serial_number: { type: 'String' },
11
+ category: { type: 'String' },
12
+ created_at: { type: 'Int64' },
13
+ device_id: { type: 'String' },
14
+ event_type: { type: 'Int64' },
15
+ is_passenger: { type: 'Bool' },
16
+ line_id: { type: 'String' },
17
+ mac_ase_counter_value: { type: 'Int64' },
18
+ mac_sam_serial_number: { type: 'Int64' },
19
+ on_board_refund_id: { type: 'Nullable(String)' },
20
+ on_board_sale_id: { type: 'Nullable(String)' },
21
+ pattern_id: { type: 'String' },
22
+ product_id: { type: 'String' },
23
+ received_at: { type: 'Int64' },
24
+ stop_id: { type: 'String' },
25
+ trip_id: { type: 'String' },
26
+ units_qty: { type: 'Nullable(Int64)' },
27
+ updated_at: { type: 'Int64' },
28
+ validation_status: { type: 'Int64' },
29
+ vehicle_id: { type: 'String' },
30
+ };
31
31
  /* * */
32
32
  class SimplifiedApexValidationsNewClass extends ClickHouseInterfaceTemplate {
33
33
  //
@@ -1,11 +1,11 @@
1
1
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
2
- import { type ClickHouseColumn } from '../../types/index.js';
2
+ import { type ClickHouseSchema } from '../../types/index.js';
3
3
  import { type SimplifiedVehicleEvent } from '@tmlmobilidade/types';
4
4
  declare class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate<SimplifiedVehicleEvent> {
5
5
  private static _instance;
6
6
  readonly databaseName = "operation";
7
7
  readonly orderBy = "(created_at, trip_id)";
8
- readonly schema: ClickHouseColumn<{
8
+ readonly schema: ClickHouseSchema<{
9
9
  _id: string;
10
10
  created_at: number & {
11
11
  __brand: "UnixTimestamp";
@@ -27,7 +27,7 @@ declare class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplat
27
27
  door: string | null;
28
28
  driver_id: string | null;
29
29
  extra_trip_id: string | null;
30
- }>[];
30
+ }>;
31
31
  readonly tableName = "simplified_vehicle_events";
32
32
  /**
33
33
  * Returns the singleton instance of the subclass.
@@ -3,26 +3,26 @@ import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
3
3
  import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
4
4
  import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
- const tableSchema = [
7
- // Required Fields
8
- { name: '_id', type: 'String' },
9
- { name: 'agency_id', type: 'String' },
10
- { name: 'created_at', type: 'UInt64' },
11
- { name: 'latitude', type: 'Float64' },
12
- { name: 'longitude', type: 'Float64' },
13
- { name: 'received_at', type: 'UInt64' },
14
- { name: 'trip_id', type: 'String' },
15
- { name: 'vehicle_id', type: 'String' },
6
+ const tableSchema = {
7
+ _id: { type: 'String' },
8
+ agency_id: { type: 'String' },
9
+ created_at: { type: 'Int64' },
10
+ latitude: { type: 'Float64' },
11
+ longitude: { type: 'Float64' },
12
+ received_at: { type: 'Int64' },
13
+ trip_id: { type: 'String' },
14
+ vehicle_id: { type: 'String' },
16
15
  // Optional Fields
17
- { name: 'bearing', type: 'Nullable(Float64)' },
18
- { name: 'current_status', type: 'Nullable(String)' },
19
- { name: 'door', type: 'Nullable(String)' },
20
- { name: 'driver_id', type: 'Nullable(String)' },
21
- { name: 'extra_trip_id', type: 'Nullable(String)' },
22
- { name: 'odometer', type: 'Nullable(Float64)' },
23
- { name: 'pattern_id', type: 'Nullable(String)' },
24
- { name: 'stop_id', type: 'Nullable(String)' },
25
- ];
16
+ bearing: { type: 'Nullable(Int64)' },
17
+ current_status: { type: 'Nullable(String)' },
18
+ door: { type: 'Nullable(String)' },
19
+ driver_id: { type: 'Nullable(String)' },
20
+ extra_trip_id: { type: 'Nullable(String)' },
21
+ odometer: { type: 'Nullable(Int64)' },
22
+ pattern_id: { type: 'Nullable(String)' },
23
+ speed: { type: 'Nullable(Int64)' },
24
+ stop_id: { type: 'Nullable(String)' },
25
+ };
26
26
  /* * */
27
27
  class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate {
28
28
  //
@@ -1,8 +1,8 @@
1
- import { type ClickHouseColumn, type ClickHouseTableEngine } from '../types/index.js';
1
+ import { type ClickHouseSchema, type ClickHouseTableEngine } from '../types/index.js';
2
2
  import { type ClickHouseClient, type DataFormat } from '@clickhouse/client';
3
3
  export declare abstract class ClickHouseInterfaceTemplate<T> {
4
4
  protected readonly abstract databaseName: string;
5
- protected readonly abstract schema: ClickHouseColumn<T>[];
5
+ protected readonly abstract schema: ClickHouseSchema<T>;
6
6
  protected readonly abstract tableName: string;
7
7
  protected readonly engine: ClickHouseTableEngine;
8
8
  protected readonly orderBy: string;
@@ -110,7 +110,7 @@ export class ClickHouseInterfaceTemplate {
110
110
  throw new Error('CLICKHOUSE: databaseName is required.');
111
111
  if (!this.tableName)
112
112
  throw new Error('CLICKHOUSE: tableName is required.');
113
- if (!this.schema || this.schema.length === 0)
113
+ if (!this.schema || Object.entries(this.schema).length === 0)
114
114
  throw new Error('CLICKHOUSE: schema is required and cannot be empty.');
115
115
  // Connect to the ClickHouse client
116
116
  this.client = await this.connectToClient();
@@ -161,10 +161,8 @@ export class ClickHouseInterfaceTemplate {
161
161
  throw new Error(`CLICKHOUSE [${this.tableName}]: Unsafe table name provided.`);
162
162
  if (!validateSqlParam(this.engine, false))
163
163
  throw new Error(`CLICKHOUSE [${this.engine}]: Unsafe engine type provided.`);
164
- if (!validateSqlParam(this.orderBy, false))
165
- throw new Error(`CLICKHOUSE [${this.orderBy}]: Unsafe orderBy clause provided.`);
166
164
  // Validate the schema columns are safe identifiers
167
- const unsafeColumns = this.schema.filter(column => !validateSqlParam(column.name, false)).map(column => column.name);
165
+ const unsafeColumns = Object.keys(this.schema).filter(key => !validateSqlParam(key, false));
168
166
  if (unsafeColumns.length > 0)
169
167
  throw new Error(`CLICKHOUSE [${this.tableName}]: Unsafe column names provided: ${unsafeColumns.join(', ')}.`);
170
168
  // Ensure the database exists before creating the table
@@ -172,7 +170,7 @@ export class ClickHouseInterfaceTemplate {
172
170
  // Setup the full CREATE TABLE query
173
171
  const createTableQuery = `
174
172
  CREATE TABLE IF NOT EXISTS "${this.databaseName}"."${this.tableName}" ON CLUSTER default_cluster (
175
- ${this.schema.map(column => `${column.name} ${column.type}`).join(', ')}
173
+ ${Object.entries(this.schema).map(([key, column]) => `${key} ${column.type}`).join(', ')}
176
174
  ) ENGINE = ${this.getEngineString()}
177
175
  ORDER BY ${this.orderBy}
178
176
  `;
@@ -152,8 +152,6 @@ export class MongoInterfaceTemplate {
152
152
  throw new Error('MONGODB: databaseName is required.');
153
153
  if (!this.collectionName)
154
154
  throw new Error('MONGODB: collectionName is required.');
155
- if (!this.indexDescription)
156
- throw new Error('MONGODB: indexDescription is required and cannot be empty.');
157
155
  // Connect to the MongoDB client
158
156
  this.client = await this.connectToClient();
159
157
  this.database = this.client.db(this.databaseName);
@@ -3,7 +3,7 @@ import { type ClickHouseDataType } from './data-types.js';
3
3
  * Definition of a ClickHouse column,
4
4
  * including its name, type, and various optional properties.
5
5
  */
6
- export interface ClickHouseColumn<T> {
6
+ export interface ClickHouseColumn {
7
7
  /** Alias expression (computed on read) */
8
8
  alias?: string;
9
9
  /** Column codec for compression */
@@ -22,7 +22,6 @@ export interface ClickHouseColumn<T> {
22
22
  lowCardinality?: boolean;
23
23
  /** Materialized value expression (computed on insert) */
24
24
  materialized?: string;
25
- name: Extract<keyof T, string>;
26
25
  /** Whether the column can be null (wraps type in Nullable) */
27
26
  nullable?: boolean;
28
27
  /** Include this column in the ORDER BY clause (ClickHouse's primary index) */
@@ -34,3 +33,8 @@ export interface ClickHouseColumn<T> {
34
33
  /** The ClickHouse data type */
35
34
  type: ClickHouseDataType;
36
35
  }
36
+ /**
37
+ * A ClickHouse schema is a mapping of column names to their definitions (ClickHouseColumn).
38
+ * The generic type T represents the shape of the data, and the keys of T are used as column names.
39
+ */
40
+ export type ClickHouseSchema<T> = Record<keyof T, ClickHouseColumn>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/databases",
3
- "version": "20260326.2139.30",
3
+ "version": "20260327.0.15",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"