gtfs 4.15.3 → 4.15.4

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.js CHANGED
@@ -3563,9 +3563,8 @@ async function fetchGtfsRealtimeData(urlConfig, task) {
3563
3563
  });
3564
3564
  }
3565
3565
  function removeExpiredRealtimeData(config) {
3566
- const log2 = log(config);
3567
3566
  const db = openDb(config);
3568
- log2(`Removing expired GTFS-Realtime data`);
3567
+ log(config)(`Removing expired GTFS-Realtime data`);
3569
3568
  db.prepare(
3570
3569
  `DELETE FROM vehicle_positions WHERE expiration_timestamp <= strftime('%s','now')`
3571
3570
  ).run();
@@ -3581,7 +3580,7 @@ function removeExpiredRealtimeData(config) {
3581
3580
  db.prepare(
3582
3581
  `DELETE FROM service_alert_targets WHERE expiration_timestamp <= strftime('%s','now')`
3583
3582
  ).run();
3584
- log2(`Removed expired GTFS-Realtime data\r`, true);
3583
+ log(config)(`Removed expired GTFS-Realtime data\r`, true);
3585
3584
  }
3586
3585
  function prepareRealtimeFieldValue(entity, column, task) {
3587
3586
  if (column.name === "created_timestamp") {
@@ -3735,13 +3734,10 @@ async function updateGtfsRealtimeData(task) {
3735
3734
  async function updateGtfsRealtime(initialConfig) {
3736
3735
  const config = setDefaultConfig(initialConfig);
3737
3736
  validateConfigForImport(config);
3738
- const log2 = log(config);
3739
- const logError2 = logError(config);
3740
- const logWarning2 = logWarning(config);
3741
3737
  try {
3742
3738
  openDb(config);
3743
3739
  const agencyCount = config.agencies.length;
3744
- log2(
3740
+ log(config)(
3745
3741
  `Starting GTFS-Realtime refresh for ${pluralize(
3746
3742
  "agencies",
3747
3743
  agencyCount,
@@ -3760,20 +3756,20 @@ async function updateGtfsRealtime(initialConfig) {
3760
3756
  ignoreErrors: config.ignoreErrors,
3761
3757
  sqlitePath: config.sqlitePath,
3762
3758
  currentTimestamp: Math.floor(Date.now() / 1e3),
3763
- log: log2,
3764
- logWarning: logWarning2,
3765
- logError: logError2
3759
+ log: log(config),
3760
+ logWarning: logWarning(config),
3761
+ logError: logError(config)
3766
3762
  };
3767
3763
  await updateGtfsRealtimeData(task);
3768
3764
  } catch (error) {
3769
3765
  if (config.ignoreErrors) {
3770
- logError2(error.message);
3766
+ logError(config)(error.message);
3771
3767
  } else {
3772
3768
  throw error;
3773
3769
  }
3774
3770
  }
3775
3771
  });
3776
- log2(
3772
+ log(config)(
3777
3773
  `Completed GTFS-Realtime refresh for ${pluralize(
3778
3774
  "agencies",
3779
3775
  agencyCount,
@@ -3782,16 +3778,13 @@ async function updateGtfsRealtime(initialConfig) {
3782
3778
  `
3783
3779
  );
3784
3780
  } catch (error) {
3785
- handleDatabaseError(error, config, logError2);
3786
- }
3787
- }
3788
- function handleDatabaseError(error, config, logError2) {
3789
- if (error?.code === "SQLITE_CANTOPEN") {
3790
- logError2(
3791
- `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
3792
- );
3781
+ if (error?.code === "SQLITE_CANTOPEN") {
3782
+ logError(config)(
3783
+ `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
3784
+ );
3785
+ }
3786
+ throw error;
3793
3787
  }
3794
- throw error;
3795
3788
  }
3796
3789
 
3797
3790
  // src/lib/import-gtfs.ts
@@ -4137,13 +4130,10 @@ async function importGtfs(initialConfig) {
4137
4130
  timer.start();
4138
4131
  const config = setDefaultConfig(initialConfig);
4139
4132
  validateConfigForImport(config);
4140
- const log2 = log(config);
4141
- const logError2 = logError(config);
4142
- const logWarning2 = logWarning(config);
4143
4133
  try {
4144
4134
  const db = openDb(config);
4145
4135
  const agencyCount = config.agencies.length;
4146
- log2(
4136
+ log(config)(
4147
4137
  `Starting GTFS import for ${pluralize2("file", agencyCount, true)} using SQLite database at ${config.sqlitePath}`
4148
4138
  );
4149
4139
  createGtfsTables(db);
@@ -4167,9 +4157,9 @@ async function importGtfs(initialConfig) {
4167
4157
  sqlitePath: config.sqlitePath,
4168
4158
  prefix: agency2.prefix,
4169
4159
  currentTimestamp: Math.floor(Date.now() / 1e3),
4170
- log: log2,
4171
- logWarning: logWarning2,
4172
- logError: logError2
4160
+ log: log(config),
4161
+ logWarning: logWarning(config),
4162
+ logError: logError(config)
4173
4163
  };
4174
4164
  if (task.url) {
4175
4165
  await downloadGtfsFiles(task);
@@ -4179,36 +4169,30 @@ async function importGtfs(initialConfig) {
4179
4169
  await updateGtfsRealtimeData(task);
4180
4170
  await rm2(tempPath, { recursive: true });
4181
4171
  } catch (error) {
4182
- handleImportError(error, config, logError2);
4172
+ if (config.ignoreErrors) {
4173
+ logError(config)(error.message);
4174
+ } else {
4175
+ throw error;
4176
+ }
4183
4177
  }
4184
4178
  });
4185
- log2(`Creating DB indexes`);
4179
+ log(config)(`Creating DB indexes`);
4186
4180
  createGtfsIndexes(db);
4187
4181
  const seconds = Math.round(timer.time() / 1e3);
4188
4182
  timer.stop();
4189
- log2(
4183
+ log(config)(
4190
4184
  `Completed GTFS import for ${pluralize2("agency", agencyCount, true)} in ${seconds} seconds
4191
4185
  `
4192
4186
  );
4193
4187
  } catch (error) {
4194
- handleDatabaseError2(error, config, logError2);
4195
- }
4196
- }
4197
- function handleImportError(error, config, logError2) {
4198
- if (config.ignoreErrors) {
4199
- logError2(error.message);
4200
- } else {
4188
+ if (error?.code === "SQLITE_CANTOPEN") {
4189
+ logError(config)(
4190
+ `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
4191
+ );
4192
+ }
4201
4193
  throw error;
4202
4194
  }
4203
4195
  }
4204
- function handleDatabaseError2(error, config, logError2) {
4205
- if (error?.code === "SQLITE_CANTOPEN") {
4206
- logError2(
4207
- `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
4208
- );
4209
- }
4210
- throw error;
4211
- }
4212
4196
 
4213
4197
  // src/lib/export.ts
4214
4198
  import path2 from "node:path";
@@ -4235,8 +4219,6 @@ var getAgencies = (db, config) => {
4235
4219
  };
4236
4220
  var exportGtfs = async (initialConfig) => {
4237
4221
  const config = setDefaultConfig(initialConfig);
4238
- const log2 = log(config);
4239
- const logWarning2 = logWarning(config);
4240
4222
  const db = openDb(config);
4241
4223
  const agencies = getAgencies(db, config);
4242
4224
  const agencyCount = agencies.length;
@@ -4245,11 +4227,11 @@ var exportGtfs = async (initialConfig) => {
4245
4227
  "No agencies found in SQLite. Be sure to first import data into SQLite using `gtfs-import` or `importGtfs(config);`"
4246
4228
  );
4247
4229
  } else if (agencyCount > 1) {
4248
- logWarning2(
4230
+ logWarning(config)(
4249
4231
  "More than one agency is defined in config.json. Export will merge all into one GTFS file."
4250
4232
  );
4251
4233
  }
4252
- log2(
4234
+ log(config)(
4253
4235
  `Starting GTFS export for ${pluralize3(
4254
4236
  "agency",
4255
4237
  agencyCount,
@@ -4274,7 +4256,7 @@ var exportGtfs = async (initialConfig) => {
4274
4256
  const lines = db.prepare(`SELECT * FROM ${tableName};`).all();
4275
4257
  if (!lines || lines.length === 0) {
4276
4258
  if (!model.nonstandard) {
4277
- log2(
4259
+ log(config)(
4278
4260
  `Skipping (no data) - ${model.filenameBase}.${model.filenameExtension}\r`
4279
4261
  );
4280
4262
  }
@@ -4316,17 +4298,23 @@ var exportGtfs = async (initialConfig) => {
4316
4298
  `Unexpected filename extension: ${model.filenameExtension}`
4317
4299
  );
4318
4300
  }
4319
- log2(`Exporting - ${model.filenameBase}.${model.filenameExtension}\r`);
4301
+ log(config)(
4302
+ `Exporting - ${model.filenameBase}.${model.filenameExtension}\r`
4303
+ );
4320
4304
  return `${model.filenameBase}.${model.filenameExtension}`;
4321
4305
  }
4322
4306
  );
4323
4307
  if (compact2(exportedFiles).length === 0) {
4324
- log2("No GTFS data exported. Be sure to first import data into SQLite.");
4308
+ log(config)(
4309
+ "No GTFS data exported. Be sure to first import data into SQLite."
4310
+ );
4325
4311
  return;
4326
4312
  }
4327
- log2(`Completed GTFS export to ${exportPath}`);
4328
- log2(`Completed GTFS export for ${pluralize3("agency", agencyCount, true)}
4329
- `);
4313
+ log(config)(`Completed GTFS export to ${exportPath}`);
4314
+ log(config)(
4315
+ `Completed GTFS export for ${pluralize3("agency", agencyCount, true)}
4316
+ `
4317
+ );
4330
4318
  };
4331
4319
 
4332
4320
  // src/lib/advancedQuery.ts