@tmlmobilidade/databases 20260323.400.54
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/dist/clients/go-clickhouse.d.ts +30 -0
- package/dist/clients/go-clickhouse.js +110 -0
- package/dist/clients/go-mongo.d.ts +30 -0
- package/dist/clients/go-mongo.js +117 -0
- package/dist/clients/index.d.ts +5 -0
- package/dist/clients/index.js +5 -0
- package/dist/clients/pcgidb-ticketing.d.ts +30 -0
- package/dist/clients/pcgidb-ticketing.js +117 -0
- package/dist/clients/pcgidb-validations.d.ts +29 -0
- package/dist/clients/pcgidb-validations.js +116 -0
- package/dist/clients/rawdb.d.ts +29 -0
- package/dist/clients/rawdb.js +116 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/simplified-apex/index.d.ts +4 -0
- package/dist/interfaces/simplified-apex/index.js +4 -0
- package/dist/interfaces/simplified-apex/simplified-apex-locations.d.ts +38 -0
- package/dist/interfaces/simplified-apex/simplified-apex-locations.js +57 -0
- package/dist/interfaces/simplified-apex/simplified-apex-on-board-refunds.d.ts +48 -0
- package/dist/interfaces/simplified-apex/simplified-apex-on-board-refunds.js +67 -0
- package/dist/interfaces/simplified-apex/simplified-apex-on-board-sales.d.ts +49 -0
- package/dist/interfaces/simplified-apex/simplified-apex-on-board-sales.js +68 -0
- package/dist/interfaces/simplified-apex/simplified-apex-validations.d.ts +47 -0
- package/dist/interfaces/simplified-apex/simplified-apex-validations.js +67 -0
- package/dist/interfaces/simplified-vehicle-events/index.d.ts +1 -0
- package/dist/interfaces/simplified-vehicle-events/index.js +1 -0
- package/dist/interfaces/simplified-vehicle-events/simplified-vehicle-events.d.ts +39 -0
- package/dist/interfaces/simplified-vehicle-events/simplified-vehicle-events.js +61 -0
- package/dist/templates/clickhouse.d.ts +107 -0
- package/dist/templates/clickhouse.js +201 -0
- package/dist/types/clickhouse/column.d.ts +36 -0
- package/dist/types/clickhouse/column.js +2 -0
- package/dist/types/clickhouse/data-types.d.ts +5 -0
- package/dist/types/clickhouse/data-types.js +1 -0
- package/dist/types/clickhouse/index.d.ts +3 -0
- package/dist/types/clickhouse/index.js +3 -0
- package/dist/types/clickhouse/table-engines.d.ts +7 -0
- package/dist/types/clickhouse/table-engines.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/get-clickhouse-param-type.d.ts +7 -0
- package/dist/utils/get-clickhouse-param-type.js +16 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/prepare-named-query-params.d.ts +16 -0
- package/dist/utils/prepare-named-query-params.js +47 -0
- package/dist/utils/prepare-positional-query-params.d.ts +13 -0
- package/dist/utils/prepare-positional-query-params.js +36 -0
- package/dist/utils/query-from-file.d.ts +17 -0
- package/dist/utils/query-from-file.js +42 -0
- package/dist/utils/query-from-string.d.ts +14 -0
- package/dist/utils/query-from-string.js +31 -0
- package/dist/utils/validate-sql-param.d.ts +12 -0
- package/dist/utils/validate-sql-param.js +23 -0
- package/package.json +53 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
+
import { SshTunnelService } from '@tmlmobilidade/ssh';
|
|
4
|
+
import { MongoClient } from 'mongodb';
|
|
5
|
+
/* * */
|
|
6
|
+
export class RAWDBService {
|
|
7
|
+
//
|
|
8
|
+
static _instance = null;
|
|
9
|
+
client;
|
|
10
|
+
tunnel = null;
|
|
11
|
+
/**
|
|
12
|
+
* Disallow direct instantiation of the service.
|
|
13
|
+
* Use getInstance() instead to ensure singleton behavior.
|
|
14
|
+
*/
|
|
15
|
+
constructor() { }
|
|
16
|
+
/**
|
|
17
|
+
* Returns the singleton instance of the subclass.
|
|
18
|
+
*/
|
|
19
|
+
static async getInstance() {
|
|
20
|
+
// If no instance exists, create one and store the promise.
|
|
21
|
+
// This ensures that if multiple calls to getInstance() happen concurrently,
|
|
22
|
+
// they will all await the same initialization process.
|
|
23
|
+
if (!this._instance) {
|
|
24
|
+
this._instance = (async () => {
|
|
25
|
+
const instance = new RAWDBService();
|
|
26
|
+
// This behaves like the constructor,
|
|
27
|
+
// but allows for async initialization.
|
|
28
|
+
await instance.connect();
|
|
29
|
+
return instance;
|
|
30
|
+
})();
|
|
31
|
+
}
|
|
32
|
+
// Await the instance if it's still initializing,
|
|
33
|
+
// or return it immediately if ready.
|
|
34
|
+
return this._instance;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Connects to Mongo, setting up the client instance.
|
|
38
|
+
* If SSH tunneling is required, it establishes the tunnel first.
|
|
39
|
+
* This method is called internally by the service and should not be used directly.
|
|
40
|
+
*/
|
|
41
|
+
async connect() {
|
|
42
|
+
Logger.info('Connecting to RAWDBService...');
|
|
43
|
+
const connectionString = await this.getConnectionString();
|
|
44
|
+
this.client = new MongoClient(connectionString);
|
|
45
|
+
this.client.on('close', () => {
|
|
46
|
+
console.warn('[RAWDBService] Database connection closed unexpectedly.');
|
|
47
|
+
});
|
|
48
|
+
this.client.on('reconnect', () => {
|
|
49
|
+
console.log('[RAWDBService] Database reconnected.');
|
|
50
|
+
});
|
|
51
|
+
await this.client.connect();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Constructs the connection string based on environment variables
|
|
55
|
+
* and SSH tunneling configuration, and handles both direct connections and SSH-tunneled
|
|
56
|
+
* connections, validating the necessary environment variables for each case.
|
|
57
|
+
* This method is called internally by the service and should not be used directly.
|
|
58
|
+
* @throws Will throw an error if required environment variables are missing or if the SSH tunnel setup fails.
|
|
59
|
+
* @returns A promise that resolves to the Mongo connection string.
|
|
60
|
+
*/
|
|
61
|
+
async getConnectionString() {
|
|
62
|
+
//
|
|
63
|
+
//
|
|
64
|
+
// Validate required environment variables
|
|
65
|
+
if (process.env.RAW_MONGO_DB_TUNNEL_ENABLED !== 'true' && process.env.RAW_MONGO_DB_TUNNEL_ENABLED !== 'false') {
|
|
66
|
+
throw new Error('Missing RAW_MONGO_DB_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting RAW_MONGO_DB_TUNNEL_ENABLED to "true" or "false".');
|
|
67
|
+
}
|
|
68
|
+
if (!process.env.RAW_MONGO_DB_HOST || !process.env.RAW_MONGO_DB_PORT) {
|
|
69
|
+
throw new Error('Missing RAW_MONGO_DB_HOST or RAW_MONGO_DB_PORT');
|
|
70
|
+
}
|
|
71
|
+
if (process.env.RAW_MONGO_DB_TUNNEL_ENABLED === 'false') {
|
|
72
|
+
return `http://${process.env.RAW_MONGO_DB_USER}:${process.env.RAW_MONGO_DB_PASSWORD}@${process.env.RAW_MONGO_DB_HOST}:${process.env.RAW_MONGO_DB_PORT}`;
|
|
73
|
+
}
|
|
74
|
+
// SSH required
|
|
75
|
+
if (!process.env.RAW_MONGO_DB_TUNNEL_LOCAL_PORT) {
|
|
76
|
+
throw new Error('Missing RAW_MONGO_DB_TUNNEL_LOCAL_PORT');
|
|
77
|
+
}
|
|
78
|
+
if (!process.env.RAW_MONGO_DB_TUNNEL_SSH_HOST || !process.env.RAW_MONGO_DB_TUNNEL_SSH_USERNAME) {
|
|
79
|
+
throw new Error('Missing SSH config');
|
|
80
|
+
}
|
|
81
|
+
const sshConfig = {
|
|
82
|
+
forwardOptions: {
|
|
83
|
+
dstAddr: process.env.RAW_MONGO_DB_HOST,
|
|
84
|
+
dstPort: Number(process.env.RAW_MONGO_DB_PORT),
|
|
85
|
+
srcAddr: 'localhost',
|
|
86
|
+
srcPort: Number(process.env.RAW_MONGO_DB_TUNNEL_LOCAL_PORT),
|
|
87
|
+
},
|
|
88
|
+
serverOptions: {
|
|
89
|
+
port: Number(process.env.RAW_MONGO_DB_TUNNEL_LOCAL_PORT),
|
|
90
|
+
},
|
|
91
|
+
sshOptions: {
|
|
92
|
+
agent: process.env.SSH_AUTH_SOCK,
|
|
93
|
+
host: process.env.RAW_MONGO_DB_TUNNEL_SSH_HOST,
|
|
94
|
+
keepaliveCountMax: 3,
|
|
95
|
+
keepaliveInterval: 10_000,
|
|
96
|
+
port: 22,
|
|
97
|
+
username: process.env.RAW_MONGO_DB_TUNNEL_SSH_USERNAME,
|
|
98
|
+
},
|
|
99
|
+
tunnelOptions: {
|
|
100
|
+
autoClose: false,
|
|
101
|
+
reconnectOnError: true,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
const sshOptions = {
|
|
105
|
+
maxRetries: 3,
|
|
106
|
+
};
|
|
107
|
+
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
108
|
+
Logger.info('[RAWDBService] Setting up SSH Tunnel...');
|
|
109
|
+
const connection = await this.tunnel.connect();
|
|
110
|
+
const addr = connection.address();
|
|
111
|
+
if (!addr || typeof addr !== 'object') {
|
|
112
|
+
throw new Error('[RAWDBService] Failed to retrieve SSH tunnel address.');
|
|
113
|
+
}
|
|
114
|
+
return `http://${process.env.RAW_MONGO_DB_USER}:${process.env.RAW_MONGO_DB_PASSWORD}@localhost:${addr.port}`;
|
|
115
|
+
}
|
|
116
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
+
import { type ClickHouseColumn } from '../../types/index.js';
|
|
3
|
+
import { type SimplifiedApexLocation } from '@tmlmobilidade/types';
|
|
4
|
+
declare class SimplifiedApexLocationsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexLocation> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
readonly databaseName = "operation";
|
|
7
|
+
readonly schema: ClickHouseColumn<{
|
|
8
|
+
_id: string;
|
|
9
|
+
created_at: number & {
|
|
10
|
+
__brand: "UnixTimestamp";
|
|
11
|
+
};
|
|
12
|
+
updated_at: number & {
|
|
13
|
+
__brand: "UnixTimestamp";
|
|
14
|
+
};
|
|
15
|
+
agency_id: string;
|
|
16
|
+
apex_version: string;
|
|
17
|
+
device_id: string;
|
|
18
|
+
line_id: string;
|
|
19
|
+
mac_ase_counter_value: number;
|
|
20
|
+
mac_sam_serial_number: number;
|
|
21
|
+
pattern_id: string;
|
|
22
|
+
received_at: number & {
|
|
23
|
+
__brand: "UnixTimestamp";
|
|
24
|
+
};
|
|
25
|
+
stop_id: string;
|
|
26
|
+
trip_id: string;
|
|
27
|
+
vehicle_id: number;
|
|
28
|
+
}>[];
|
|
29
|
+
readonly tableName = "simplified_apex_locations";
|
|
30
|
+
/**
|
|
31
|
+
* Returns the singleton instance of the subclass.
|
|
32
|
+
*/
|
|
33
|
+
static getInstance(): Promise<SimplifiedApexLocationsNewClass>;
|
|
34
|
+
protected connectToClient(): Promise<import("@clickhouse/client").ClickHouseClient>;
|
|
35
|
+
protected postInit(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export declare const simplifiedApexLocationsNew: SimplifiedApexLocationsNewClass;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
|
|
3
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
4
|
+
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
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
|
+
];
|
|
22
|
+
/* * */
|
|
23
|
+
class SimplifiedApexLocationsNewClass extends ClickHouseInterfaceTemplate {
|
|
24
|
+
//
|
|
25
|
+
static _instance = null;
|
|
26
|
+
databaseName = 'operation';
|
|
27
|
+
schema = tableSchema;
|
|
28
|
+
tableName = 'simplified_apex_locations';
|
|
29
|
+
/**
|
|
30
|
+
* Returns the singleton instance of the subclass.
|
|
31
|
+
*/
|
|
32
|
+
static async getInstance() {
|
|
33
|
+
// If no instance exists, create one and store the promise.
|
|
34
|
+
// This ensures that if multiple calls to getInstance() happen concurrently,
|
|
35
|
+
// they will all await the same initialization process.
|
|
36
|
+
if (!this._instance) {
|
|
37
|
+
this._instance = (async () => {
|
|
38
|
+
const instance = new SimplifiedApexLocationsNewClass();
|
|
39
|
+
// This behaves like the constructor,
|
|
40
|
+
// but allows for async initialization.
|
|
41
|
+
await instance.init();
|
|
42
|
+
return instance;
|
|
43
|
+
})();
|
|
44
|
+
}
|
|
45
|
+
// Await the instance if it's still initializing,
|
|
46
|
+
// or return it immediately if ready.
|
|
47
|
+
return await this._instance;
|
|
48
|
+
}
|
|
49
|
+
connectToClient() {
|
|
50
|
+
return GOClickHouseClient.getClient();
|
|
51
|
+
}
|
|
52
|
+
async postInit() {
|
|
53
|
+
console.log('Post init ClickHouse service for Simplified Apex Locations...');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/* * */
|
|
57
|
+
export const simplifiedApexLocationsNew = asyncSingletonProxy(SimplifiedApexLocationsNewClass);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
+
import { type ClickHouseColumn } from '../../types/index.js';
|
|
3
|
+
import { type SimplifiedApexOnBoardRefund } from '@tmlmobilidade/types';
|
|
4
|
+
declare class SimplifiedApexOnBoardRefundsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexOnBoardRefund> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
readonly databaseName = "operation";
|
|
7
|
+
readonly schema: ClickHouseColumn<{
|
|
8
|
+
_id: string;
|
|
9
|
+
created_at: number & {
|
|
10
|
+
__brand: "UnixTimestamp";
|
|
11
|
+
};
|
|
12
|
+
updated_at: number & {
|
|
13
|
+
__brand: "UnixTimestamp";
|
|
14
|
+
};
|
|
15
|
+
agency_id: string;
|
|
16
|
+
apex_version: string;
|
|
17
|
+
device_id: string;
|
|
18
|
+
line_id: string | null;
|
|
19
|
+
mac_ase_counter_value: number;
|
|
20
|
+
mac_sam_serial_number: number;
|
|
21
|
+
pattern_id: string | null;
|
|
22
|
+
received_at: number & {
|
|
23
|
+
__brand: "UnixTimestamp";
|
|
24
|
+
};
|
|
25
|
+
stop_id: string | null;
|
|
26
|
+
trip_id: string | null;
|
|
27
|
+
vehicle_id: number | null;
|
|
28
|
+
block_id: string | null;
|
|
29
|
+
card_physical_type: number;
|
|
30
|
+
card_serial_number: string;
|
|
31
|
+
duty_id: string | null;
|
|
32
|
+
on_board_sale_id: string | null;
|
|
33
|
+
payment_method: number;
|
|
34
|
+
price: number;
|
|
35
|
+
product_long_id: string;
|
|
36
|
+
product_quantity: number;
|
|
37
|
+
validation_id: string | null;
|
|
38
|
+
}>[];
|
|
39
|
+
readonly tableName = "simplified_apex_on_board_refunds";
|
|
40
|
+
/**
|
|
41
|
+
* Returns the singleton instance of the subclass.
|
|
42
|
+
*/
|
|
43
|
+
static getInstance(): Promise<SimplifiedApexOnBoardRefundsNewClass>;
|
|
44
|
+
protected connectToClient(): Promise<import("@clickhouse/client").ClickHouseClient>;
|
|
45
|
+
protected postInit(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare const simplifiedApexOnBoardRefundsNew: SimplifiedApexOnBoardRefundsNewClass;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
|
|
3
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
4
|
+
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
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
|
+
];
|
|
32
|
+
/* * */
|
|
33
|
+
class SimplifiedApexOnBoardRefundsNewClass extends ClickHouseInterfaceTemplate {
|
|
34
|
+
//
|
|
35
|
+
static _instance = null;
|
|
36
|
+
databaseName = 'operation';
|
|
37
|
+
schema = tableSchema;
|
|
38
|
+
tableName = 'simplified_apex_on_board_refunds';
|
|
39
|
+
/**
|
|
40
|
+
* Returns the singleton instance of the subclass.
|
|
41
|
+
*/
|
|
42
|
+
static async getInstance() {
|
|
43
|
+
// If no instance exists, create one and store the promise.
|
|
44
|
+
// This ensures that if multiple calls to getInstance() happen concurrently,
|
|
45
|
+
// they will all await the same initialization process.
|
|
46
|
+
if (!this._instance) {
|
|
47
|
+
this._instance = (async () => {
|
|
48
|
+
const instance = new SimplifiedApexOnBoardRefundsNewClass();
|
|
49
|
+
// This behaves like the constructor,
|
|
50
|
+
// but allows for async initialization.
|
|
51
|
+
await instance.init();
|
|
52
|
+
return instance;
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
55
|
+
// Await the instance if it's still initializing,
|
|
56
|
+
// or return it immediately if ready.
|
|
57
|
+
return await this._instance;
|
|
58
|
+
}
|
|
59
|
+
connectToClient() {
|
|
60
|
+
return GOClickHouseClient.getClient();
|
|
61
|
+
}
|
|
62
|
+
async postInit() {
|
|
63
|
+
console.log('Post init ClickHouse service for Simplified Apex OnBoardRefunds...');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/* * */
|
|
67
|
+
export const simplifiedApexOnBoardRefundsNew = asyncSingletonProxy(SimplifiedApexOnBoardRefundsNewClass);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
+
import { type ClickHouseColumn } from '../../types/index.js';
|
|
3
|
+
import { type SimplifiedApexOnBoardSale } from '@tmlmobilidade/types';
|
|
4
|
+
declare class SimplifiedApexOnBoardSalesNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexOnBoardSale> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
readonly databaseName = "operation";
|
|
7
|
+
readonly schema: ClickHouseColumn<{
|
|
8
|
+
_id: string;
|
|
9
|
+
created_at: number & {
|
|
10
|
+
__brand: "UnixTimestamp";
|
|
11
|
+
};
|
|
12
|
+
updated_at: number & {
|
|
13
|
+
__brand: "UnixTimestamp";
|
|
14
|
+
};
|
|
15
|
+
agency_id: string;
|
|
16
|
+
apex_version: string;
|
|
17
|
+
device_id: string;
|
|
18
|
+
line_id: string | null;
|
|
19
|
+
mac_ase_counter_value: number;
|
|
20
|
+
mac_sam_serial_number: number;
|
|
21
|
+
pattern_id: string | null;
|
|
22
|
+
received_at: number & {
|
|
23
|
+
__brand: "UnixTimestamp";
|
|
24
|
+
};
|
|
25
|
+
stop_id: string | null;
|
|
26
|
+
trip_id: string | null;
|
|
27
|
+
vehicle_id: number | null;
|
|
28
|
+
block_id: string | null;
|
|
29
|
+
card_physical_type: number;
|
|
30
|
+
card_serial_number: string;
|
|
31
|
+
duty_id: string | null;
|
|
32
|
+
payment_method: number;
|
|
33
|
+
price: number;
|
|
34
|
+
product_long_id: string;
|
|
35
|
+
product_quantity: number;
|
|
36
|
+
validation_id: string | null;
|
|
37
|
+
is_passenger: boolean;
|
|
38
|
+
on_board_refund_id: string | null;
|
|
39
|
+
}>[];
|
|
40
|
+
readonly tableName = "simplified_apex_on_board_sales";
|
|
41
|
+
/**
|
|
42
|
+
* Returns the singleton instance of the subclass.
|
|
43
|
+
*/
|
|
44
|
+
static getInstance(): Promise<SimplifiedApexOnBoardSalesNewClass>;
|
|
45
|
+
protected connectToClient(): Promise<import("@clickhouse/client").ClickHouseClient>;
|
|
46
|
+
protected postInit(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare const simplifiedApexOnBoardSalesNew: SimplifiedApexOnBoardSalesNewClass;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
|
|
3
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
4
|
+
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
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
|
+
];
|
|
33
|
+
/* * */
|
|
34
|
+
class SimplifiedApexOnBoardSalesNewClass extends ClickHouseInterfaceTemplate {
|
|
35
|
+
//
|
|
36
|
+
static _instance = null;
|
|
37
|
+
databaseName = 'operation';
|
|
38
|
+
schema = tableSchema;
|
|
39
|
+
tableName = 'simplified_apex_on_board_sales';
|
|
40
|
+
/**
|
|
41
|
+
* Returns the singleton instance of the subclass.
|
|
42
|
+
*/
|
|
43
|
+
static async getInstance() {
|
|
44
|
+
// If no instance exists, create one and store the promise.
|
|
45
|
+
// This ensures that if multiple calls to getInstance() happen concurrently,
|
|
46
|
+
// they will all await the same initialization process.
|
|
47
|
+
if (!this._instance) {
|
|
48
|
+
this._instance = (async () => {
|
|
49
|
+
const instance = new SimplifiedApexOnBoardSalesNewClass();
|
|
50
|
+
// This behaves like the constructor,
|
|
51
|
+
// but allows for async initialization.
|
|
52
|
+
await instance.init();
|
|
53
|
+
return instance;
|
|
54
|
+
})();
|
|
55
|
+
}
|
|
56
|
+
// Await the instance if it's still initializing,
|
|
57
|
+
// or return it immediately if ready.
|
|
58
|
+
return await this._instance;
|
|
59
|
+
}
|
|
60
|
+
connectToClient() {
|
|
61
|
+
return GOClickHouseClient.getClient();
|
|
62
|
+
}
|
|
63
|
+
async postInit() {
|
|
64
|
+
console.log('Post init ClickHouse service for Simplified Apex OnBoardSales...');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/* * */
|
|
68
|
+
export const simplifiedApexOnBoardSalesNew = asyncSingletonProxy(SimplifiedApexOnBoardSalesNewClass);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
+
import { type ClickHouseColumn } from '../../types/index.js';
|
|
3
|
+
import { type SimplifiedApexValidation } from '@tmlmobilidade/types';
|
|
4
|
+
declare class SimplifiedApexValidationsNewClass extends ClickHouseInterfaceTemplate<SimplifiedApexValidation> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
readonly databaseName = "operation";
|
|
7
|
+
readonly schema: ClickHouseColumn<{
|
|
8
|
+
_id: string;
|
|
9
|
+
created_at: number & {
|
|
10
|
+
__brand: "UnixTimestamp";
|
|
11
|
+
};
|
|
12
|
+
updated_at: number & {
|
|
13
|
+
__brand: "UnixTimestamp";
|
|
14
|
+
};
|
|
15
|
+
agency_id: string;
|
|
16
|
+
apex_version: string;
|
|
17
|
+
device_id: string;
|
|
18
|
+
line_id: string;
|
|
19
|
+
mac_ase_counter_value: number;
|
|
20
|
+
mac_sam_serial_number: number;
|
|
21
|
+
pattern_id: string;
|
|
22
|
+
received_at: number & {
|
|
23
|
+
__brand: "UnixTimestamp";
|
|
24
|
+
};
|
|
25
|
+
stop_id: string;
|
|
26
|
+
trip_id: string;
|
|
27
|
+
vehicle_id: number;
|
|
28
|
+
card_serial_number: string;
|
|
29
|
+
on_board_sale_id: string | null;
|
|
30
|
+
is_passenger: boolean;
|
|
31
|
+
on_board_refund_id: string | null;
|
|
32
|
+
category: "on_board_sale" | "prepaid" | "subscription";
|
|
33
|
+
event_type: number;
|
|
34
|
+
product_id: string;
|
|
35
|
+
units_qty: number | null;
|
|
36
|
+
validation_status: 0 | 1 | 2 | 12 | 4 | 3 | 5 | 6 | 11 | 10 | 7 | 8 | 9 | 13;
|
|
37
|
+
}>[];
|
|
38
|
+
readonly tableName = "simplified_apex_validations";
|
|
39
|
+
/**
|
|
40
|
+
* Returns the singleton instance of the subclass.
|
|
41
|
+
*/
|
|
42
|
+
static getInstance(): Promise<SimplifiedApexValidationsNewClass>;
|
|
43
|
+
protected connectToClient(): Promise<import("@clickhouse/client").ClickHouseClient>;
|
|
44
|
+
protected postInit(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare const simplifiedApexValidationsNew: SimplifiedApexValidationsNewClass;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
|
|
3
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
4
|
+
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
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
|
+
];
|
|
31
|
+
/* * */
|
|
32
|
+
class SimplifiedApexValidationsNewClass extends ClickHouseInterfaceTemplate {
|
|
33
|
+
//
|
|
34
|
+
static _instance = null;
|
|
35
|
+
databaseName = 'operation';
|
|
36
|
+
schema = tableSchema;
|
|
37
|
+
tableName = 'simplified_apex_validations';
|
|
38
|
+
/**
|
|
39
|
+
* Returns the singleton instance of the subclass.
|
|
40
|
+
*/
|
|
41
|
+
static async getInstance() {
|
|
42
|
+
// If no instance exists, create one and store the promise.
|
|
43
|
+
// This ensures that if multiple calls to getInstance() happen concurrently,
|
|
44
|
+
// they will all await the same initialization process.
|
|
45
|
+
if (!this._instance) {
|
|
46
|
+
console.log('create instance here');
|
|
47
|
+
this._instance = (async () => {
|
|
48
|
+
const instance = new SimplifiedApexValidationsNewClass();
|
|
49
|
+
// This behaves like the constructor,
|
|
50
|
+
// but allows for async initialization.
|
|
51
|
+
await instance.init();
|
|
52
|
+
return instance;
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
55
|
+
// Await the instance if it's still initializing,
|
|
56
|
+
// or return it immediately if ready.
|
|
57
|
+
return await this._instance;
|
|
58
|
+
}
|
|
59
|
+
connectToClient() {
|
|
60
|
+
return GOClickHouseClient.getClient();
|
|
61
|
+
}
|
|
62
|
+
async postInit() {
|
|
63
|
+
console.log('Post init ClickHouse service for Simplified Apex Validations...');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/* * */
|
|
67
|
+
export const simplifiedApexValidationsNew = asyncSingletonProxy(SimplifiedApexValidationsNewClass);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './simplified-vehicle-events.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './simplified-vehicle-events.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
+
import { type ClickHouseColumn } from '../../types/index.js';
|
|
3
|
+
import { type SimplifiedVehicleEvent } from '@tmlmobilidade/types';
|
|
4
|
+
declare class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate<SimplifiedVehicleEvent> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
readonly databaseName = "operation";
|
|
7
|
+
readonly schema: ClickHouseColumn<{
|
|
8
|
+
_id: string;
|
|
9
|
+
created_at: number & {
|
|
10
|
+
__brand: "UnixTimestamp";
|
|
11
|
+
};
|
|
12
|
+
latitude: number;
|
|
13
|
+
longitude: number;
|
|
14
|
+
agency_id: string;
|
|
15
|
+
pattern_id: string | null;
|
|
16
|
+
received_at: number & {
|
|
17
|
+
__brand: "UnixTimestamp";
|
|
18
|
+
};
|
|
19
|
+
stop_id: string | null;
|
|
20
|
+
trip_id: string;
|
|
21
|
+
vehicle_id: string;
|
|
22
|
+
bearing: number | null;
|
|
23
|
+
odometer: number | null;
|
|
24
|
+
speed: number | null;
|
|
25
|
+
current_status: "INCOMING_AT" | "STOPPED_AT" | "IN_TRANSIT_TO" | null;
|
|
26
|
+
door: string | null;
|
|
27
|
+
driver_id: string | null;
|
|
28
|
+
extra_trip_id: string | null;
|
|
29
|
+
}>[];
|
|
30
|
+
readonly tableName = "simplified_vehicle_events";
|
|
31
|
+
/**
|
|
32
|
+
* Returns the singleton instance of the subclass.
|
|
33
|
+
*/
|
|
34
|
+
static getInstance(): Promise<SimplifiedVehicleEventsNewClass>;
|
|
35
|
+
protected connectToClient(): Promise<import("@clickhouse/client").ClickHouseClient>;
|
|
36
|
+
protected postInit(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare const simplifiedVehicleEventsNew: SimplifiedVehicleEventsNewClass;
|
|
39
|
+
export {};
|