@tmlmobilidade/go-utils-import-gtfs

中文文档
20261102.1501.57发布于 2026/11/02AGPL-3.0-or-laterTypeScriptES Module

TypeScript wrapper for the Go GTFS importer. Imports a local or remote ZIP into SQLite and returns _db, calendar_dates, routes, shapes, stop_times, stops, and trips, without GTFS validation.

原始使用文档

Import GTFS

TypeScript wrapper for the Go GTFS importer. Imports a local or remote ZIP into SQLite and returns _db, calendar_dates, routes, shapes, stop_times, stops, and trips, without GTFS validation.

import { importGtfsToDatabase } from '@tmlmobilidade/go-utils-import-gtfs';

const gtfs = await importGtfsToDatabase({
    source: { path: './gtfs.zip' },
    sqlite_config: { memory: true },
});

try {
    console.log(gtfs.stops?.all());
    console.log(gtfs.trips?.get('trip_id', '001'));
} finally {
    gtfs._db.cleanup();
}

Use source: { url: 'https://example.com/gtfs.zip' } for downloads. Optional sqlite_config accepts instanceName, instancePath, and memory. Live database instances cannot be passed between processes. Set sqlite_config: { memory: true } to receive an in-memory database; instancePath is ignored and no database file is created. Go transfers a binary SQLite image over stdout, which TypeScript opens in memory. Memory addresses cannot be shared between these processes. The transfer temporarily holds database copies in memory. Relative paths use the caller's working directory.

The wrapper passes JSON directly to the CLI without a shell. Import errors reject the promise with the CLI's stderr. Telemetry is forwarded to the parent's stderr as it arrives, in both file and memory modes. ENVIRONMENT=dev selects readable logs; other values produce OpenTelemetry JSON.

_db is a SQLiteDatabase. Each table handle is a SQLiteTableInstance with all, get, has, stream, and the other SQLite client methods. Columns are read from SQLite; empty fields are null and other values remain strings. calendar_dates is a Record<string, OperationalDateInt[]> keyed by service ID, containing distinct numeric dates with exception_type: '1'. It is empty when no calendar-date rows exist. With a nonempty filter, these are resolved active service dates after expanding weekly calendars and applying exceptions. Without that filter, only explicit additions from calendar_dates.txt are included; weekly calendars are not expanded. Raw calendar rows remain available through _db.databaseInstance. Missing or empty source files produce undefined table handles; header-only files produce empty tables. Other imported GTFS tables remain accessible through _db.databaseInstance.

Pass a complete table bundle type to preserve each table's row type:

const gtfs = await importGtfsToDatabase<GtfsHubV1SQLTables>(config);

The generic describes the returned bundle without validating or converting row values. Missing tables still return undefined, so custom bundles must reflect the tables guaranteed by the source archive.

Optional time_range accepts the same dates as the legacy importer:

time_range: {
    date_range: {
        start: OperationalDateIntSchema.parse(20261001),
        end: OperationalDateIntSchema.parse(20261031),
    },
    discrete_dates: [OperationalDateIntSchema.parse(20261027)],
},

Import OperationalDateIntSchema from @tmlmobilidade/go-types-shared. The range includes both endpoints. When both filters are supplied, dates must match both. An omitted filter, {}, or an empty discrete_dates array imports all dates. Invalid configuration dates or reversed ranges reject the import. A nonempty filter expands calendar.txt weekdays, applies calendar_dates.txt additions/removals, and keeps trips with selected active dates. It then keeps only referenced stop times, routes, shapes, and stops (including parent stations). The resolved calendar_dates rows have exception_type: '1'; the imported calendar table is empty. Custom exception fields are preserved; generated weekly dates have null custom fields. Other GTFS tables and existing database rows are retained. An omitted or empty filter preserves raw import behavior.

The caller owns the database connection and any output file. Call _db.cleanup() to close and release its memory or delete its file (including a custom output path), or call _db.databaseInstance.close() to close the connection and retain the file.

From the repository root, build with:

npx turbo run build --filter=@tmlmobilidade/go-utils-import-gtfs
npm run test --workspace=@tmlmobilidade/go-utils-import-gtfs

The build includes the Go CLI in dist/bin/import-gtfs; Go and a C compiler are required at build time. Go is not required at runtime. The resulting package must run on the same OS and architecture as the build machine. The Go workspace is named @tmlmobilidade/go-golang-import-gtfs.

版本与发布记录

@tmlmobilidade/go-utils-import-gtfs 共发布 6 个版本,首次发布于 2026/10/28;过去 12 个月发布了 6 个版本。

版本发布日期距今
20261102.1501.57latest2026/11/02今天
20261030.1350.292026/10/304 天前
20261029.1015.242026/10/295 天前
20261028.1757.522026/10/295 天前
20261028.1202.422026/10/286 天前
0.0.0-stage2026/10/286 天前

关于 @tmlmobilidade/go-utils-import-gtfs 的常见问题

@tmlmobilidade/go-utils-import-gtfs 是什么?

Go GTFS导入器的TypeScript包装器。将本地或远程ZIP导入SQLite并返回 _db, calendar_dates, routes, shapes, stop_times, stops, trips,无需GTFS验证。

如何安装 @tmlmobilidade/go-utils-import-gtfs?

在项目目录运行 npm install @tmlmobilidade/go-utils-import-gtfs,或使用 pnpm add / yarn add / bun add。

@tmlmobilidade/go-utils-import-gtfs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@tmlmobilidade/go-utils-import-gtfs 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@tmlmobilidade/go-utils-import-gtfs 可以商用吗?

@tmlmobilidade/go-utils-import-gtfs 使用 AGPL-3.0-or-later 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@tmlmobilidade/go-utils-import-gtfs 还在维护吗?

最新版本 20261102.1501.57 发布于 2026/11/02(今天);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/10/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。