@tmlmobilidade/import-gtfs 20251009.1435.7 → 20251010.756.34
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/index.d.ts +2 -9
- package/dist/index.js +2 -65
- package/dist/src/main.d.ts +9 -0
- package/dist/src/main.js +65 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Imports GTFS data into the database for a given plan.
|
|
5
|
-
* @param plan The plan containing GTFS feed information.
|
|
6
|
-
* @param config Optional configuration for the import process.
|
|
7
|
-
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
8
|
-
*/
|
|
9
|
-
export declare function importGtfsToDatabase(plan: Plan, config?: ImportGtfsToDatabaseConfig): Promise<GtfsSQLTables>;
|
|
1
|
+
export * from './src/main.js';
|
|
2
|
+
export * from './src/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { processCalendarDatesFile } from './src/processors/calendar_dates.js';
|
|
4
|
-
import { processRoutesFile } from './src/processors/routes.js';
|
|
5
|
-
import { processShapesFile } from './src/processors/shapes.js';
|
|
6
|
-
import { processStopTimesFile } from './src/processors/stop_times.js';
|
|
7
|
-
import { processStopsFile } from './src/processors/stops.js';
|
|
8
|
-
import { processTripsFile } from './src/processors/trips.js';
|
|
9
|
-
import { downloadAndExtractGtfs } from './src/utils/extract-file.js';
|
|
10
|
-
import { initGtfsSqlTables } from './src/utils/init-tables.js';
|
|
11
|
-
import TIMETRACKER from '@helperkits/timer';
|
|
12
|
-
import { Logs } from '@tmlmobilidade/utils';
|
|
13
|
-
/**
|
|
14
|
-
* Imports GTFS data into the database for a given plan.
|
|
15
|
-
* @param plan The plan containing GTFS feed information.
|
|
16
|
-
* @param config Optional configuration for the import process.
|
|
17
|
-
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
18
|
-
*/
|
|
19
|
-
export async function importGtfsToDatabase(plan, config = {}) {
|
|
20
|
-
try {
|
|
21
|
-
//
|
|
22
|
-
const globalTimer = new TIMETRACKER();
|
|
23
|
-
Logs.info(`Importing ${plan._id} GTFS to database...`);
|
|
24
|
-
//
|
|
25
|
-
// Initialize context for the current plan
|
|
26
|
-
const context = {
|
|
27
|
-
counters: {
|
|
28
|
-
calendar_dates: 0,
|
|
29
|
-
hashed_shapes: 0,
|
|
30
|
-
hashed_trips: 0,
|
|
31
|
-
shapes: 0,
|
|
32
|
-
stop_times: 0,
|
|
33
|
-
trips: 0,
|
|
34
|
-
},
|
|
35
|
-
gtfs: initGtfsSqlTables(),
|
|
36
|
-
plan: plan,
|
|
37
|
-
referenced_route_ids: new Set(),
|
|
38
|
-
referenced_shape_ids: new Set(),
|
|
39
|
-
workdir: await downloadAndExtractGtfs(plan),
|
|
40
|
-
};
|
|
41
|
-
//
|
|
42
|
-
// Validate GTFS feed info
|
|
43
|
-
if (!plan.gtfs_feed_info?.feed_start_date || !plan.gtfs_feed_info?.feed_end_date) {
|
|
44
|
-
throw new Error(`Plan "${plan._id}" is missing GTFS feed start and/or end date.`);
|
|
45
|
-
}
|
|
46
|
-
//
|
|
47
|
-
// Process GTFS files in the correct order
|
|
48
|
-
await processCalendarFile(context, config);
|
|
49
|
-
await processCalendarDatesFile(context, config);
|
|
50
|
-
await processTripsFile(context);
|
|
51
|
-
await processRoutesFile(context);
|
|
52
|
-
await processShapesFile(context);
|
|
53
|
-
await processStopsFile(context);
|
|
54
|
-
await processStopTimesFile(context);
|
|
55
|
-
Logs.success(`Finished importing GTFS to database for plan "${plan._id}" in ${globalTimer.get()}.`, 0);
|
|
56
|
-
Logs.divider();
|
|
57
|
-
Logs.terminate(`Finished importing GTFS to database in ${globalTimer.get()}.`);
|
|
58
|
-
return context.gtfs;
|
|
59
|
-
//
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
Logs.error('Error parsing plan.', error);
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
export * from './src/main.js';
|
|
2
|
+
export * from './src/types.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GtfsSQLTables, type ImportGtfsToDatabaseConfig } from './types.js';
|
|
2
|
+
import { type Plan } from '@tmlmobilidade/types';
|
|
3
|
+
/**
|
|
4
|
+
* Imports GTFS data into the database for a given plan.
|
|
5
|
+
* @param plan The plan containing GTFS feed information.
|
|
6
|
+
* @param config Optional configuration for the import process.
|
|
7
|
+
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
8
|
+
*/
|
|
9
|
+
export declare function importGtfsToDatabase(plan: Plan, config?: ImportGtfsToDatabaseConfig): Promise<GtfsSQLTables>;
|
package/dist/src/main.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { processCalendarFile } from './processors/calendar.js';
|
|
3
|
+
import { processCalendarDatesFile } from './processors/calendar_dates.js';
|
|
4
|
+
import { processRoutesFile } from './processors/routes.js';
|
|
5
|
+
import { processShapesFile } from './processors/shapes.js';
|
|
6
|
+
import { processStopTimesFile } from './processors/stop_times.js';
|
|
7
|
+
import { processStopsFile } from './processors/stops.js';
|
|
8
|
+
import { processTripsFile } from './processors/trips.js';
|
|
9
|
+
import { downloadAndExtractGtfs } from './utils/extract-file.js';
|
|
10
|
+
import { initGtfsSqlTables } from './utils/init-tables.js';
|
|
11
|
+
import TIMETRACKER from '@helperkits/timer';
|
|
12
|
+
import { Logs } from '@tmlmobilidade/utils';
|
|
13
|
+
/**
|
|
14
|
+
* Imports GTFS data into the database for a given plan.
|
|
15
|
+
* @param plan The plan containing GTFS feed information.
|
|
16
|
+
* @param config Optional configuration for the import process.
|
|
17
|
+
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
18
|
+
*/
|
|
19
|
+
export async function importGtfsToDatabase(plan, config = {}) {
|
|
20
|
+
try {
|
|
21
|
+
//
|
|
22
|
+
const globalTimer = new TIMETRACKER();
|
|
23
|
+
Logs.info(`Importing ${plan._id} GTFS to database...`);
|
|
24
|
+
//
|
|
25
|
+
// Initialize context for the current plan
|
|
26
|
+
const context = {
|
|
27
|
+
counters: {
|
|
28
|
+
calendar_dates: 0,
|
|
29
|
+
hashed_shapes: 0,
|
|
30
|
+
hashed_trips: 0,
|
|
31
|
+
shapes: 0,
|
|
32
|
+
stop_times: 0,
|
|
33
|
+
trips: 0,
|
|
34
|
+
},
|
|
35
|
+
gtfs: initGtfsSqlTables(),
|
|
36
|
+
plan: plan,
|
|
37
|
+
referenced_route_ids: new Set(),
|
|
38
|
+
referenced_shape_ids: new Set(),
|
|
39
|
+
workdir: await downloadAndExtractGtfs(plan),
|
|
40
|
+
};
|
|
41
|
+
//
|
|
42
|
+
// Validate GTFS feed info
|
|
43
|
+
if (!plan.gtfs_feed_info?.feed_start_date || !plan.gtfs_feed_info?.feed_end_date) {
|
|
44
|
+
throw new Error(`Plan "${plan._id}" is missing GTFS feed start and/or end date.`);
|
|
45
|
+
}
|
|
46
|
+
//
|
|
47
|
+
// Process GTFS files in the correct order
|
|
48
|
+
await processCalendarFile(context, config);
|
|
49
|
+
await processCalendarDatesFile(context, config);
|
|
50
|
+
await processTripsFile(context);
|
|
51
|
+
await processRoutesFile(context);
|
|
52
|
+
await processShapesFile(context);
|
|
53
|
+
await processStopsFile(context);
|
|
54
|
+
await processStopTimesFile(context);
|
|
55
|
+
Logs.success(`Finished importing GTFS to database for plan "${plan._id}" in ${globalTimer.get()}.`, 0);
|
|
56
|
+
Logs.divider();
|
|
57
|
+
Logs.terminate(`Finished importing GTFS to database in ${globalTimer.get()}.`);
|
|
58
|
+
return context.gtfs;
|
|
59
|
+
//
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
Logs.error('Error parsing plan.', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
package/package.json
CHANGED