gtfs 4.13.0 → 4.13.2

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.
@@ -221,8 +221,6 @@ var model3 = {
221
221
  {
222
222
  name: "attribution_id",
223
223
  type: "text",
224
- primary: true,
225
- required: true,
226
224
  prefix: true
227
225
  },
228
226
  {
@@ -389,7 +387,7 @@ var model5 = {
389
387
  },
390
388
  {
391
389
  name: "date",
392
- type: "integer",
390
+ type: "date",
393
391
  required: true,
394
392
  primary: true
395
393
  },
@@ -473,13 +471,13 @@ var model6 = {
473
471
  },
474
472
  {
475
473
  name: "start_date",
476
- type: "integer",
474
+ type: "date",
477
475
  required: true,
478
476
  index: true
479
477
  },
480
478
  {
481
479
  name: "end_date",
482
- type: "integer",
480
+ type: "date",
483
481
  required: true,
484
482
  index: true
485
483
  }
@@ -775,11 +773,11 @@ var model13 = {
775
773
  },
776
774
  {
777
775
  name: "feed_start_date",
778
- type: "integer"
776
+ type: "date"
779
777
  },
780
778
  {
781
779
  name: "feed_end_date",
782
- type: "integer"
780
+ type: "date"
783
781
  },
784
782
  {
785
783
  name: "feed_version",
@@ -1632,11 +1630,11 @@ var model31 = {
1632
1630
  },
1633
1631
  {
1634
1632
  name: "start_date",
1635
- type: "integer"
1633
+ type: "date"
1636
1634
  },
1637
1635
  {
1638
1636
  name: "end_date",
1639
- type: "integer"
1637
+ type: "date"
1640
1638
  },
1641
1639
  {
1642
1640
  name: "monday",
@@ -2141,7 +2139,7 @@ var model41 = {
2141
2139
  },
2142
2140
  {
2143
2141
  name: "service_date",
2144
- type: "integer",
2142
+ type: "date",
2145
2143
  index: true
2146
2144
  },
2147
2145
  {
@@ -2223,7 +2221,7 @@ var model42 = {
2223
2221
  },
2224
2222
  {
2225
2223
  name: "service_date",
2226
- type: "integer",
2224
+ type: "date",
2227
2225
  index: true
2228
2226
  },
2229
2227
  {
@@ -2307,12 +2305,12 @@ var model43 = {
2307
2305
  },
2308
2306
  {
2309
2307
  name: "ridership_start_date",
2310
- type: "integer",
2308
+ type: "date",
2311
2309
  index: true
2312
2310
  },
2313
2311
  {
2314
2312
  name: "ridership_end_date",
2315
- type: "integer",
2313
+ type: "date",
2316
2314
  index: true
2317
2315
  },
2318
2316
  {
@@ -2435,7 +2433,7 @@ var model44 = {
2435
2433
  },
2436
2434
  {
2437
2435
  name: "service_date",
2438
- type: "integer",
2436
+ type: "date",
2439
2437
  index: true
2440
2438
  },
2441
2439
  {
@@ -2482,17 +2480,17 @@ var model45 = {
2482
2480
  },
2483
2481
  {
2484
2482
  name: "ride_start_date",
2485
- type: "integer",
2483
+ type: "date",
2486
2484
  index: true
2487
2485
  },
2488
2486
  {
2489
2487
  name: "ride_end_date",
2490
- type: "integer",
2488
+ type: "date",
2491
2489
  index: true
2492
2490
  },
2493
2491
  {
2494
2492
  name: "gtfs_feed_date",
2495
- type: "integer",
2493
+ type: "date",
2496
2494
  index: true
2497
2495
  },
2498
2496
  {
@@ -3282,54 +3280,6 @@ var models_default = models;
3282
3280
  // src/lib/db.ts
3283
3281
  import Database from "better-sqlite3";
3284
3282
  import untildify2 from "untildify";
3285
-
3286
- // src/lib/utils.ts
3287
- import sqlString from "sqlstring-sqlite";
3288
- import Long from "long";
3289
- function validateConfigForImport(config) {
3290
- if (!config.agencies || config.agencies.length === 0) {
3291
- throw new Error("No `agencies` specified in config");
3292
- }
3293
- for (const [index, agency] of config.agencies.entries()) {
3294
- if (!agency.path && !agency.url) {
3295
- throw new Error(
3296
- `No Agency \`url\` or \`path\` specified in config for agency index ${index}.`
3297
- );
3298
- }
3299
- }
3300
- return config;
3301
- }
3302
- function setDefaultConfig(initialConfig) {
3303
- const defaults = {
3304
- sqlitePath: ":memory:",
3305
- ignoreDuplicates: false,
3306
- gtfsRealtimeExpirationSeconds: 0
3307
- };
3308
- return {
3309
- ...defaults,
3310
- ...initialConfig
3311
- };
3312
- }
3313
- function convertLongTimeToDate(longDate) {
3314
- const { high, low, unsigned } = longDate;
3315
- return new Date(new Long(low, high, unsigned).toInt() * 1e3).toISOString();
3316
- }
3317
- function calculateSecondsFromMidnight(time) {
3318
- const split = time.split(":").map((d) => Number.parseInt(d, 10));
3319
- if (split.length !== 3) {
3320
- return null;
3321
- }
3322
- return split[0] * 3600 + split[1] * 60 + split[2];
3323
- }
3324
- function padLeadingZeros(time) {
3325
- const split = time.split(":").map((d) => String(Number(d)).padStart(2, "0"));
3326
- if (split.length !== 3) {
3327
- return null;
3328
- }
3329
- return split.join(":");
3330
- }
3331
-
3332
- // src/lib/db.ts
3333
3283
  var dbs = {};
3334
3284
  function setupDb(sqlitePath) {
3335
3285
  const db = new Database(untildify2(sqlitePath));
@@ -3341,7 +3291,7 @@ function setupDb(sqlitePath) {
3341
3291
  }
3342
3292
  function openDb(config = null) {
3343
3293
  if (config) {
3344
- const { sqlitePath, db } = setDefaultConfig(config);
3294
+ const { sqlitePath = ":memory:", db } = config;
3345
3295
  if (db) {
3346
3296
  return db;
3347
3297
  }
@@ -3350,6 +3300,9 @@ function openDb(config = null) {
3350
3300
  }
3351
3301
  return setupDb(sqlitePath);
3352
3302
  }
3303
+ if (Object.keys(dbs).length === 0) {
3304
+ return setupDb(":memory:");
3305
+ }
3353
3306
  if (Object.keys(dbs).length === 1) {
3354
3307
  const filename = Object.keys(dbs)[0];
3355
3308
  return dbs[filename];
@@ -3399,6 +3352,52 @@ function isValidJSON(string) {
3399
3352
  return true;
3400
3353
  }
3401
3354
 
3355
+ // src/lib/utils.ts
3356
+ import sqlString from "sqlstring-sqlite";
3357
+ import Long from "long";
3358
+ function validateConfigForImport(config) {
3359
+ if (!config.agencies || config.agencies.length === 0) {
3360
+ throw new Error("No `agencies` specified in config");
3361
+ }
3362
+ for (const [index, agency] of config.agencies.entries()) {
3363
+ if (!agency.path && !agency.url) {
3364
+ throw new Error(
3365
+ `No Agency \`url\` or \`path\` specified in config for agency index ${index}.`
3366
+ );
3367
+ }
3368
+ }
3369
+ return config;
3370
+ }
3371
+ function setDefaultConfig(initialConfig) {
3372
+ const defaults = {
3373
+ sqlitePath: ":memory:",
3374
+ ignoreDuplicates: false,
3375
+ gtfsRealtimeExpirationSeconds: 0
3376
+ };
3377
+ return {
3378
+ ...defaults,
3379
+ ...initialConfig
3380
+ };
3381
+ }
3382
+ function convertLongTimeToDate(longDate) {
3383
+ const { high, low, unsigned } = longDate;
3384
+ return new Date(new Long(low, high, unsigned).toInt() * 1e3).toISOString();
3385
+ }
3386
+ function calculateSecondsFromMidnight(time) {
3387
+ const split = time.split(":").map((d) => Number.parseInt(d, 10));
3388
+ if (split.length !== 3) {
3389
+ return null;
3390
+ }
3391
+ return split[0] * 3600 + split[1] * 60 + split[2];
3392
+ }
3393
+ function padLeadingZeros(time) {
3394
+ const split = time.split(":").map((d) => String(Number(d)).padStart(2, "0"));
3395
+ if (split.length !== 3) {
3396
+ return null;
3397
+ }
3398
+ return split.join(":");
3399
+ }
3400
+
3402
3401
  // src/lib/import.ts
3403
3402
  var downloadFiles = async (task) => {
3404
3403
  task.log(`Downloading GTFS from ${task.agency_url}`);
@@ -3489,8 +3488,7 @@ var updateRealtimeData = async (task) => {
3489
3488
  return;
3490
3489
  }
3491
3490
  const db = openDb({
3492
- sqlitePath: task.sqlitePath,
3493
- agencies: []
3491
+ sqlitePath: task.sqlitePath
3494
3492
  });
3495
3493
  const vehiclePositionsModel = models_default.find(
3496
3494
  (x) => x.filenameBase === "vehicle_positions"
@@ -3681,7 +3679,17 @@ var formatLine = (line, model56, totalLineCount) => {
3681
3679
  const formattedLine = {};
3682
3680
  for (const columnSchema of model56.schema) {
3683
3681
  const lineValue = line[columnSchema.name];
3684
- if (columnSchema.type === "integer") {
3682
+ if (columnSchema.type === "date") {
3683
+ if (lineValue !== "" && lineValue !== void 0) {
3684
+ const dateValue = lineValue.replace(/-/g, "");
3685
+ if (dateValue.length !== 8) {
3686
+ throw new Error(
3687
+ `Invalid date in ${model56.filenameBase}.${model56.filenameExtension} for ${columnSchema.name} on line ${lineNumber}.`
3688
+ );
3689
+ }
3690
+ formattedLine[columnSchema.name] = Number.parseInt(dateValue, 10);
3691
+ }
3692
+ } else if (columnSchema.type === "integer") {
3685
3693
  formattedLine[columnSchema.name] = Number.parseInt(lineValue, 10);
3686
3694
  } else if (columnSchema.type === "real") {
3687
3695
  formattedLine[columnSchema.name] = Number.parseFloat(lineValue);
@@ -3731,8 +3739,7 @@ var formatLine = (line, model56, totalLineCount) => {
3731
3739
  };
3732
3740
  var importLines = (task, lines, model56, totalLineCount) => {
3733
3741
  const db = openDb({
3734
- sqlitePath: task.sqlitePath,
3735
- agencies: []
3742
+ sqlitePath: task.sqlitePath
3736
3743
  });
3737
3744
  if (lines.length === 0) {
3738
3745
  return;