@abasisltd/gtfs-guru-wasm 0.9.3 → 1.0.0

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.
@@ -5,6 +5,18 @@ export class ValidationResult {
5
5
  private constructor();
6
6
  free(): void;
7
7
  [Symbol.dispose](): void;
8
+ /**
9
+ * Move the timing report into JavaScript without cloning it in Rust.
10
+ */
11
+ take_timings_json(): string;
12
+ /**
13
+ * Move the HTML report into JavaScript without cloning it in Rust.
14
+ */
15
+ take_html(): string;
16
+ /**
17
+ * Move the JSON report into JavaScript without cloning it in Rust.
18
+ */
19
+ take_json(): string;
8
20
  /**
9
21
  * Get the number of info notices
10
22
  */
@@ -13,6 +25,10 @@ export class ValidationResult {
13
25
  * Get the number of errors
14
26
  */
15
27
  readonly error_count: number;
28
+ /**
29
+ * Get the loading and per-validator timing breakdown as JSON.
30
+ */
31
+ readonly timings_json: string;
16
32
  /**
17
33
  * Get the number of warnings
18
34
  */
@@ -29,8 +45,18 @@ export class ValidationResult {
29
45
  * Check if validation passed (no errors)
30
46
  */
31
47
  readonly is_valid: boolean;
48
+ /**
49
+ * True when the notice list in `json` was capped per issue type to keep
50
+ * memory bounded. Counts (`error_count` etc.) are always exact.
51
+ */
52
+ readonly truncated: boolean;
32
53
  }
33
54
 
55
+ /**
56
+ * Validate and compare two GTFS ZIP files, returning a semantic diff as JSON.
57
+ */
58
+ export function diff_gtfs(old_zip_bytes: Uint8Array, new_zip_bytes: Uint8Array, country_code?: string | null, date?: string | null): string;
59
+
34
60
  /**
35
61
  * Initialize the WASM module (call once on page load)
36
62
  */
@@ -48,7 +74,8 @@ export function init(): void;
48
74
  * A ValidationResult containing the JSON report and summary counts
49
75
  *
50
76
  * # Errors
51
- * Throws a JavaScript error if the file exceeds 50 MB
77
+ * Throws a JavaScript error if the feed exceeds the browser size limits
78
+ * (150 MB zipped / 700 MB uncompressed)
52
79
  */
53
80
  export function validate_gtfs(zip_bytes: Uint8Array, country_code?: string | null, date?: string | null): ValidationResult;
54
81
 
@@ -67,22 +94,27 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
67
94
  export interface InitOutput {
68
95
  readonly memory: WebAssembly.Memory;
69
96
  readonly __wbg_validationresult_free: (a: number, b: number) => void;
70
- readonly validate_gtfs: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
71
- readonly validate_gtfs_json: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
97
+ readonly diff_gtfs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
98
+ readonly validate_gtfs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
99
+ readonly validate_gtfs_json: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
72
100
  readonly validationresult_error_count: (a: number) => number;
73
- readonly validationresult_html: (a: number) => [number, number];
101
+ readonly validationresult_html: (a: number, b: number) => void;
74
102
  readonly validationresult_info_count: (a: number) => number;
75
103
  readonly validationresult_is_valid: (a: number) => number;
76
- readonly validationresult_json: (a: number) => [number, number];
104
+ readonly validationresult_json: (a: number, b: number) => void;
105
+ readonly validationresult_take_html: (a: number, b: number) => void;
106
+ readonly validationresult_take_json: (a: number, b: number) => void;
107
+ readonly validationresult_take_timings_json: (a: number, b: number) => void;
108
+ readonly validationresult_timings_json: (a: number, b: number) => void;
109
+ readonly validationresult_truncated: (a: number) => number;
77
110
  readonly validationresult_warning_count: (a: number) => number;
78
- readonly version: () => [number, number];
111
+ readonly version: (a: number) => void;
79
112
  readonly init: () => void;
80
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
81
- readonly __wbindgen_malloc: (a: number, b: number) => number;
82
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
83
- readonly __wbindgen_externrefs: WebAssembly.Table;
84
- readonly __externref_table_dealloc: (a: number) => void;
85
- readonly __wbindgen_start: () => void;
113
+ readonly __wbindgen_export: (a: number) => void;
114
+ readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
115
+ readonly __wbindgen_export3: (a: number, b: number) => number;
116
+ readonly __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
117
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
86
118
  }
87
119
 
88
120
  export type SyncInitInput = BufferSource | WebAssembly.Module;
package/gtfs_guru_wasm.js CHANGED
@@ -1,5 +1,20 @@
1
1
  let wasm;
2
2
 
3
+ function addHeapObject(obj) {
4
+ if (heap_next === heap.length) heap.push(heap.length + 1);
5
+ const idx = heap_next;
6
+ heap_next = heap[idx];
7
+
8
+ heap[idx] = obj;
9
+ return idx;
10
+ }
11
+
12
+ function dropObject(idx) {
13
+ if (idx < 132) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
3
18
  let cachedDataViewMemory0 = null;
4
19
  function getDataViewMemory0() {
5
20
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -21,6 +36,21 @@ function getUint8ArrayMemory0() {
21
36
  return cachedUint8ArrayMemory0;
22
37
  }
23
38
 
39
+ function getObject(idx) { return heap[idx]; }
40
+
41
+ function handleError(f, args) {
42
+ try {
43
+ return f.apply(this, args);
44
+ } catch (e) {
45
+ wasm.__wbindgen_export(addHeapObject(e));
46
+ }
47
+ }
48
+
49
+ let heap = new Array(128).fill(undefined);
50
+ heap.push(undefined, null, true, false);
51
+
52
+ let heap_next = heap.length;
53
+
24
54
  function isLikeNone(x) {
25
55
  return x === undefined || x === null;
26
56
  }
@@ -69,10 +99,10 @@ function passStringToWasm0(arg, malloc, realloc) {
69
99
  return ptr;
70
100
  }
71
101
 
72
- function takeFromExternrefTable0(idx) {
73
- const value = wasm.__wbindgen_externrefs.get(idx);
74
- wasm.__externref_table_dealloc(idx);
75
- return value;
102
+ function takeObject(idx) {
103
+ const ret = getObject(idx);
104
+ dropObject(idx);
105
+ return ret;
76
106
  }
77
107
 
78
108
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -145,6 +175,26 @@ export class ValidationResult {
145
175
  const ret = wasm.validationresult_error_count(this.__wbg_ptr);
146
176
  return ret >>> 0;
147
177
  }
178
+ /**
179
+ * Get the loading and per-validator timing breakdown as JSON.
180
+ * @returns {string}
181
+ */
182
+ get timings_json() {
183
+ let deferred1_0;
184
+ let deferred1_1;
185
+ try {
186
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
187
+ wasm.validationresult_timings_json(retptr, this.__wbg_ptr);
188
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
189
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
190
+ deferred1_0 = r0;
191
+ deferred1_1 = r1;
192
+ return getStringFromWasm0(r0, r1);
193
+ } finally {
194
+ wasm.__wbindgen_add_to_stack_pointer(16);
195
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
196
+ }
197
+ }
148
198
  /**
149
199
  * Get the number of warnings
150
200
  * @returns {number}
@@ -153,6 +203,26 @@ export class ValidationResult {
153
203
  const ret = wasm.validationresult_warning_count(this.__wbg_ptr);
154
204
  return ret >>> 0;
155
205
  }
206
+ /**
207
+ * Move the timing report into JavaScript without cloning it in Rust.
208
+ * @returns {string}
209
+ */
210
+ take_timings_json() {
211
+ let deferred1_0;
212
+ let deferred1_1;
213
+ try {
214
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
215
+ wasm.validationresult_take_timings_json(retptr, this.__wbg_ptr);
216
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
217
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
218
+ deferred1_0 = r0;
219
+ deferred1_1 = r1;
220
+ return getStringFromWasm0(r0, r1);
221
+ } finally {
222
+ wasm.__wbindgen_add_to_stack_pointer(16);
223
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
224
+ }
225
+ }
156
226
  /**
157
227
  * Get the full validation report as HTML
158
228
  * @returns {string}
@@ -161,12 +231,16 @@ export class ValidationResult {
161
231
  let deferred1_0;
162
232
  let deferred1_1;
163
233
  try {
164
- const ret = wasm.validationresult_html(this.__wbg_ptr);
165
- deferred1_0 = ret[0];
166
- deferred1_1 = ret[1];
167
- return getStringFromWasm0(ret[0], ret[1]);
234
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
235
+ wasm.validationresult_html(retptr, this.__wbg_ptr);
236
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
237
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
238
+ deferred1_0 = r0;
239
+ deferred1_1 = r1;
240
+ return getStringFromWasm0(r0, r1);
168
241
  } finally {
169
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
242
+ wasm.__wbindgen_add_to_stack_pointer(16);
243
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
170
244
  }
171
245
  }
172
246
  /**
@@ -177,12 +251,16 @@ export class ValidationResult {
177
251
  let deferred1_0;
178
252
  let deferred1_1;
179
253
  try {
180
- const ret = wasm.validationresult_json(this.__wbg_ptr);
181
- deferred1_0 = ret[0];
182
- deferred1_1 = ret[1];
183
- return getStringFromWasm0(ret[0], ret[1]);
254
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
255
+ wasm.validationresult_json(retptr, this.__wbg_ptr);
256
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
257
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
258
+ deferred1_0 = r0;
259
+ deferred1_1 = r1;
260
+ return getStringFromWasm0(r0, r1);
184
261
  } finally {
185
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
262
+ wasm.__wbindgen_add_to_stack_pointer(16);
263
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
186
264
  }
187
265
  }
188
266
  /**
@@ -193,9 +271,99 @@ export class ValidationResult {
193
271
  const ret = wasm.validationresult_is_valid(this.__wbg_ptr);
194
272
  return ret !== 0;
195
273
  }
274
+ /**
275
+ * Move the HTML report into JavaScript without cloning it in Rust.
276
+ * @returns {string}
277
+ */
278
+ take_html() {
279
+ let deferred1_0;
280
+ let deferred1_1;
281
+ try {
282
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
283
+ wasm.validationresult_take_html(retptr, this.__wbg_ptr);
284
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
285
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
286
+ deferred1_0 = r0;
287
+ deferred1_1 = r1;
288
+ return getStringFromWasm0(r0, r1);
289
+ } finally {
290
+ wasm.__wbindgen_add_to_stack_pointer(16);
291
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
292
+ }
293
+ }
294
+ /**
295
+ * Move the JSON report into JavaScript without cloning it in Rust.
296
+ * @returns {string}
297
+ */
298
+ take_json() {
299
+ let deferred1_0;
300
+ let deferred1_1;
301
+ try {
302
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
303
+ wasm.validationresult_take_json(retptr, this.__wbg_ptr);
304
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
305
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
306
+ deferred1_0 = r0;
307
+ deferred1_1 = r1;
308
+ return getStringFromWasm0(r0, r1);
309
+ } finally {
310
+ wasm.__wbindgen_add_to_stack_pointer(16);
311
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
312
+ }
313
+ }
314
+ /**
315
+ * True when the notice list in `json` was capped per issue type to keep
316
+ * memory bounded. Counts (`error_count` etc.) are always exact.
317
+ * @returns {boolean}
318
+ */
319
+ get truncated() {
320
+ const ret = wasm.validationresult_truncated(this.__wbg_ptr);
321
+ return ret !== 0;
322
+ }
196
323
  }
197
324
  if (Symbol.dispose) ValidationResult.prototype[Symbol.dispose] = ValidationResult.prototype.free;
198
325
 
326
+ /**
327
+ * Validate and compare two GTFS ZIP files, returning a semantic diff as JSON.
328
+ * @param {Uint8Array} old_zip_bytes
329
+ * @param {Uint8Array} new_zip_bytes
330
+ * @param {string | null} [country_code]
331
+ * @param {string | null} [date]
332
+ * @returns {string}
333
+ */
334
+ export function diff_gtfs(old_zip_bytes, new_zip_bytes, country_code, date) {
335
+ let deferred6_0;
336
+ let deferred6_1;
337
+ try {
338
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
339
+ const ptr0 = passArray8ToWasm0(old_zip_bytes, wasm.__wbindgen_export3);
340
+ const len0 = WASM_VECTOR_LEN;
341
+ const ptr1 = passArray8ToWasm0(new_zip_bytes, wasm.__wbindgen_export3);
342
+ const len1 = WASM_VECTOR_LEN;
343
+ var ptr2 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
344
+ var len2 = WASM_VECTOR_LEN;
345
+ var ptr3 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
346
+ var len3 = WASM_VECTOR_LEN;
347
+ wasm.diff_gtfs(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
348
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
349
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
350
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
351
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
352
+ var ptr5 = r0;
353
+ var len5 = r1;
354
+ if (r3) {
355
+ ptr5 = 0; len5 = 0;
356
+ throw takeObject(r2);
357
+ }
358
+ deferred6_0 = ptr5;
359
+ deferred6_1 = len5;
360
+ return getStringFromWasm0(ptr5, len5);
361
+ } finally {
362
+ wasm.__wbindgen_add_to_stack_pointer(16);
363
+ wasm.__wbindgen_export2(deferred6_0, deferred6_1, 1);
364
+ }
365
+ }
366
+
199
367
  /**
200
368
  * Initialize the WASM module (call once on page load)
201
369
  */
@@ -215,24 +383,33 @@ export function init() {
215
383
  * A ValidationResult containing the JSON report and summary counts
216
384
  *
217
385
  * # Errors
218
- * Throws a JavaScript error if the file exceeds 50 MB
386
+ * Throws a JavaScript error if the feed exceeds the browser size limits
387
+ * (150 MB zipped / 700 MB uncompressed)
219
388
  * @param {Uint8Array} zip_bytes
220
389
  * @param {string | null} [country_code]
221
390
  * @param {string | null} [date]
222
391
  * @returns {ValidationResult}
223
392
  */
224
393
  export function validate_gtfs(zip_bytes, country_code, date) {
225
- const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_malloc);
226
- const len0 = WASM_VECTOR_LEN;
227
- var ptr1 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
228
- var len1 = WASM_VECTOR_LEN;
229
- var ptr2 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
230
- var len2 = WASM_VECTOR_LEN;
231
- const ret = wasm.validate_gtfs(ptr0, len0, ptr1, len1, ptr2, len2);
232
- if (ret[2]) {
233
- throw takeFromExternrefTable0(ret[1]);
234
- }
235
- return ValidationResult.__wrap(ret[0]);
394
+ try {
395
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
396
+ const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_export3);
397
+ const len0 = WASM_VECTOR_LEN;
398
+ var ptr1 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
399
+ var len1 = WASM_VECTOR_LEN;
400
+ var ptr2 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
401
+ var len2 = WASM_VECTOR_LEN;
402
+ wasm.validate_gtfs(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
403
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
404
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
405
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
406
+ if (r2) {
407
+ throw takeObject(r1);
408
+ }
409
+ return ValidationResult.__wrap(r0);
410
+ } finally {
411
+ wasm.__wbindgen_add_to_stack_pointer(16);
412
+ }
236
413
  }
237
414
 
238
415
  /**
@@ -246,24 +423,30 @@ export function validate_gtfs_json(zip_bytes, country_code, date) {
246
423
  let deferred5_0;
247
424
  let deferred5_1;
248
425
  try {
249
- const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_malloc);
426
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
427
+ const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_export3);
250
428
  const len0 = WASM_VECTOR_LEN;
251
- var ptr1 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
429
+ var ptr1 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
252
430
  var len1 = WASM_VECTOR_LEN;
253
- var ptr2 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
431
+ var ptr2 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
254
432
  var len2 = WASM_VECTOR_LEN;
255
- const ret = wasm.validate_gtfs_json(ptr0, len0, ptr1, len1, ptr2, len2);
256
- var ptr4 = ret[0];
257
- var len4 = ret[1];
258
- if (ret[3]) {
433
+ wasm.validate_gtfs_json(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
434
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
435
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
436
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
437
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
438
+ var ptr4 = r0;
439
+ var len4 = r1;
440
+ if (r3) {
259
441
  ptr4 = 0; len4 = 0;
260
- throw takeFromExternrefTable0(ret[2]);
442
+ throw takeObject(r2);
261
443
  }
262
444
  deferred5_0 = ptr4;
263
445
  deferred5_1 = len4;
264
446
  return getStringFromWasm0(ptr4, len4);
265
447
  } finally {
266
- wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
448
+ wasm.__wbindgen_add_to_stack_pointer(16);
449
+ wasm.__wbindgen_export2(deferred5_0, deferred5_1, 1);
267
450
  }
268
451
  }
269
452
 
@@ -275,12 +458,16 @@ export function version() {
275
458
  let deferred1_0;
276
459
  let deferred1_1;
277
460
  try {
278
- const ret = wasm.version();
279
- deferred1_0 = ret[0];
280
- deferred1_1 = ret[1];
281
- return getStringFromWasm0(ret[0], ret[1]);
461
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
462
+ wasm.version(retptr);
463
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
464
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
465
+ deferred1_0 = r0;
466
+ deferred1_1 = r1;
467
+ return getStringFromWasm0(r0, r1);
282
468
  } finally {
283
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
469
+ wasm.__wbindgen_add_to_stack_pointer(16);
470
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
284
471
  }
285
472
  }
286
473
 
@@ -319,9 +506,17 @@ async function __wbg_load(module, imports) {
319
506
  function __wbg_get_imports() {
320
507
  const imports = {};
321
508
  imports.wbg = {};
509
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
510
+ const ret = getObject(arg0) === undefined;
511
+ return ret;
512
+ };
322
513
  imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
323
514
  throw new Error(getStringFromWasm0(arg0, arg1));
324
515
  };
516
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
517
+ const ret = getObject(arg0).call(getObject(arg1));
518
+ return addHeapObject(ret);
519
+ }, arguments) };
325
520
  imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
326
521
  let deferred0_0;
327
522
  let deferred0_1;
@@ -330,54 +525,80 @@ function __wbg_get_imports() {
330
525
  deferred0_1 = arg1;
331
526
  console.error(getStringFromWasm0(arg0, arg1));
332
527
  } finally {
333
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
528
+ wasm.__wbindgen_export2(deferred0_0, deferred0_1, 1);
334
529
  }
335
530
  };
336
531
  imports.wbg.__wbg_getTime_ad1e9878a735af08 = function(arg0) {
337
- const ret = arg0.getTime();
532
+ const ret = getObject(arg0).getTime();
338
533
  return ret;
339
534
  };
340
535
  imports.wbg.__wbg_getTimezoneOffset_45389e26d6f46823 = function(arg0) {
341
- const ret = arg0.getTimezoneOffset();
536
+ const ret = getObject(arg0).getTimezoneOffset();
342
537
  return ret;
343
538
  };
344
539
  imports.wbg.__wbg_new_0_23cedd11d9b40c9d = function() {
345
540
  const ret = new Date();
346
- return ret;
541
+ return addHeapObject(ret);
347
542
  };
348
543
  imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
349
544
  const ret = new Error();
350
- return ret;
545
+ return addHeapObject(ret);
351
546
  };
352
547
  imports.wbg.__wbg_new_b2db8aa2650f793a = function(arg0) {
353
- const ret = new Date(arg0);
548
+ const ret = new Date(getObject(arg0));
549
+ return addHeapObject(ret);
550
+ };
551
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
552
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
553
+ return addHeapObject(ret);
554
+ };
555
+ imports.wbg.__wbg_now_2c95c9de01293173 = function(arg0) {
556
+ const ret = getObject(arg0).now();
354
557
  return ret;
355
558
  };
559
+ imports.wbg.__wbg_performance_7a3ffd0b17f663ad = function(arg0) {
560
+ const ret = getObject(arg0).performance;
561
+ return addHeapObject(ret);
562
+ };
356
563
  imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
357
- const ret = arg1.stack;
358
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
564
+ const ret = getObject(arg1).stack;
565
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
359
566
  const len1 = WASM_VECTOR_LEN;
360
567
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
361
568
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
362
569
  };
570
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
571
+ const ret = typeof global === 'undefined' ? null : global;
572
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
573
+ };
574
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
575
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
576
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
577
+ };
578
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
579
+ const ret = typeof self === 'undefined' ? null : self;
580
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
581
+ };
582
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
583
+ const ret = typeof window === 'undefined' ? null : window;
584
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
585
+ };
363
586
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
364
587
  // Cast intrinsic for `Ref(String) -> Externref`.
365
588
  const ret = getStringFromWasm0(arg0, arg1);
366
- return ret;
589
+ return addHeapObject(ret);
367
590
  };
368
591
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
369
592
  // Cast intrinsic for `F64 -> Externref`.
370
593
  const ret = arg0;
371
- return ret;
594
+ return addHeapObject(ret);
372
595
  };
373
- imports.wbg.__wbindgen_init_externref_table = function() {
374
- const table = wasm.__wbindgen_externrefs;
375
- const offset = table.grow(4);
376
- table.set(0, undefined);
377
- table.set(offset + 0, undefined);
378
- table.set(offset + 1, null);
379
- table.set(offset + 2, true);
380
- table.set(offset + 3, false);
596
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
597
+ const ret = getObject(arg0);
598
+ return addHeapObject(ret);
599
+ };
600
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
601
+ takeObject(arg0);
381
602
  };
382
603
 
383
604
  return imports;
@@ -390,7 +611,7 @@ function __wbg_finalize_init(instance, module) {
390
611
  cachedUint8ArrayMemory0 = null;
391
612
 
392
613
 
393
- wasm.__wbindgen_start();
614
+
394
615
  return wasm;
395
616
  }
396
617
 
Binary file
@@ -0,0 +1,25 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_validationresult_free: (a: number, b: number) => void;
5
+ export const diff_gtfs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
6
+ export const validate_gtfs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
7
+ export const validate_gtfs_json: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
8
+ export const validationresult_error_count: (a: number) => number;
9
+ export const validationresult_html: (a: number, b: number) => void;
10
+ export const validationresult_info_count: (a: number) => number;
11
+ export const validationresult_is_valid: (a: number) => number;
12
+ export const validationresult_json: (a: number, b: number) => void;
13
+ export const validationresult_take_html: (a: number, b: number) => void;
14
+ export const validationresult_take_json: (a: number, b: number) => void;
15
+ export const validationresult_take_timings_json: (a: number, b: number) => void;
16
+ export const validationresult_timings_json: (a: number, b: number) => void;
17
+ export const validationresult_truncated: (a: number) => number;
18
+ export const validationresult_warning_count: (a: number) => number;
19
+ export const version: (a: number) => void;
20
+ export const init: () => void;
21
+ export const __wbindgen_export: (a: number) => void;
22
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
23
+ export const __wbindgen_export3: (a: number, b: number) => number;
24
+ export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
25
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
package/index.d.ts ADDED
@@ -0,0 +1,271 @@
1
+ /**
2
+ * GTFS Validator WASM - TypeScript Type Definitions
3
+ */
4
+
5
+ /**
6
+ * Severity level for validation notices
7
+ */
8
+ export type NoticeSeverity = 'ERROR' | 'WARNING' | 'INFO';
9
+
10
+ export interface NoticeGeometryPoint {
11
+ latitude: number;
12
+ longitude: number;
13
+ }
14
+
15
+ export type NoticeGeometry =
16
+ | { type: 'point'; point: NoticeGeometryPoint }
17
+ | { type: 'line'; points: NoticeGeometryPoint[] }
18
+ | {
19
+ type: 'pointAndLine';
20
+ point: NoticeGeometryPoint;
21
+ line: NoticeGeometryPoint[];
22
+ nearestPoint?: NoticeGeometryPoint;
23
+ }
24
+ | {
25
+ type: 'boundingBox';
26
+ southWest: NoticeGeometryPoint;
27
+ northEast: NoticeGeometryPoint;
28
+ };
29
+
30
+ /**
31
+ * A validation notice (error, warning, or info)
32
+ */
33
+ export interface ValidationNotice {
34
+ /** Notice code (e.g., "missing_required_file", "invalid_color") */
35
+ code: string;
36
+ /** Severity level */
37
+ severity: NoticeSeverity;
38
+ /** Human-readable description */
39
+ title: string;
40
+ /** Name of the affected file (e.g., "stops.txt") */
41
+ filename?: string;
42
+ /** CSV row number (1-indexed) */
43
+ csvRowNumber?: number;
44
+ /** Affected field name */
45
+ fieldName?: string;
46
+ /** Renderer-neutral geographic context for map-capable notices */
47
+ geometry?: NoticeGeometry;
48
+ /** Additional context as key-value pairs */
49
+ [key: string]: unknown;
50
+ }
51
+
52
+ /**
53
+ * Validation result returned by the WASM module
54
+ */
55
+ export interface ValidationResult {
56
+ /** Full validation report as JSON string */
57
+ readonly json: string;
58
+ /** Full validation report as HTML string */
59
+ readonly html: string;
60
+ /** Loading and per-validator timing breakdown as JSON string */
61
+ readonly timings_json: string;
62
+ /** Number of errors found */
63
+ readonly error_count: number;
64
+ /** Number of warnings found */
65
+ readonly warning_count: number;
66
+ /** Number of info notices */
67
+ readonly info_count: number;
68
+ /** True if no errors were found (warnings/info don't affect validity) */
69
+ readonly is_valid: boolean;
70
+ /** Move the JSON report out of WASM without a Rust-side clone. */
71
+ take_json(): string;
72
+ /** Move the HTML report out of WASM without a Rust-side clone. */
73
+ take_html(): string;
74
+ /** Move the timing breakdown out of WASM without a Rust-side clone. */
75
+ take_timings_json(): string;
76
+ }
77
+
78
+ export interface TimingItem {
79
+ name: string;
80
+ duration_ms: number;
81
+ duration_s: number;
82
+ }
83
+
84
+ export interface TimingCategory {
85
+ total_ms: number;
86
+ total_s: number;
87
+ items: TimingItem[];
88
+ }
89
+
90
+ export type TimingBreakdown = Partial<Record<
91
+ 'loading' | 'parsing' | 'indexing' | 'validation',
92
+ TimingCategory
93
+ >>;
94
+
95
+ /**
96
+ * Parsed validation result with typed notices
97
+ */
98
+ export interface ParsedValidationResult {
99
+ json: string;
100
+ html: string;
101
+ errorCount: number;
102
+ warningCount: number;
103
+ infoCount: number;
104
+ isValid: boolean;
105
+ validationTimeMs: number;
106
+ timings: TimingBreakdown;
107
+ runtime: 'single-threaded' | 'multi-threaded';
108
+ }
109
+
110
+ /**
111
+ * Options for validation
112
+ */
113
+ export interface ValidationOptions {
114
+ /** ISO 3166-1 alpha-2 country code (e.g., "US", "DE", "RU") */
115
+ countryCode?: string;
116
+ /** Validation date in YYYY-MM-DD format */
117
+ date?: string;
118
+ }
119
+
120
+ export interface EntityDiff {
121
+ added: string[];
122
+ removed: string[];
123
+ changed: string[];
124
+ }
125
+
126
+ export interface FeedDiff {
127
+ files: { added: string[]; removed: string[] };
128
+ feedInfo: {
129
+ changed: boolean;
130
+ oldVersion?: string;
131
+ newVersion?: string;
132
+ oldServiceRange?: string;
133
+ newServiceRange?: string;
134
+ };
135
+ agencies: EntityDiff;
136
+ routes: EntityDiff;
137
+ stops: EntityDiff & {
138
+ renamed: string[];
139
+ moved: Array<{ stopId: string; distanceMeters: number }>;
140
+ };
141
+ tripsByRoute: Array<{ routeId: string; oldCount: number; newCount: number }>;
142
+ frequenciesByRoute: Array<{
143
+ routeId: string;
144
+ oldWindows: string[];
145
+ newWindows: string[];
146
+ }>;
147
+ notices: {
148
+ newErrors: number;
149
+ resolvedErrors: number;
150
+ changes: Array<{
151
+ code: string;
152
+ severity: NoticeSeverity;
153
+ oldCount: number;
154
+ newCount: number;
155
+ }>;
156
+ };
157
+ }
158
+
159
+ export interface ParsedDiffResult {
160
+ json: string;
161
+ diff: FeedDiff;
162
+ comparisonTimeMs: number;
163
+ runtime: 'single-threaded' | 'multi-threaded';
164
+ }
165
+
166
+ /**
167
+ * Initialize the WASM module. Must be called once before using other functions.
168
+ */
169
+ export function init(): Promise<void>;
170
+
171
+ /**
172
+ * Get the validator version string
173
+ */
174
+ export function version(): string;
175
+
176
+ /**
177
+ * Validate a GTFS ZIP file from raw bytes
178
+ *
179
+ * @param zipBytes - Raw bytes of the GTFS ZIP file
180
+ * @param countryCode - Optional ISO 3166-1 alpha-2 country code
181
+ * @returns ValidationResult with counts and JSON report
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const bytes = new Uint8Array(await file.arrayBuffer());
186
+ * const result = validate_gtfs(bytes, 'US');
187
+ * console.log(result.is_valid, result.error_count);
188
+ * const notices = JSON.parse(result.json) as ValidationNotice[];
189
+ * ```
190
+ */
191
+ export function validate_gtfs(
192
+ zipBytes: Uint8Array,
193
+ countryCode?: string | null,
194
+ date?: string | null
195
+ ): ValidationResult;
196
+
197
+ /**
198
+ * Validate a GTFS ZIP file and return only the JSON report
199
+ *
200
+ * @param zipBytes - Raw bytes of the GTFS ZIP file
201
+ * @param countryCode - Optional ISO 3166-1 alpha-2 country code
202
+ * @returns JSON string containing array of notices
203
+ */
204
+ export function validate_gtfs_json(
205
+ zipBytes: Uint8Array,
206
+ countryCode?: string | null,
207
+ date?: string | null
208
+ ): string;
209
+
210
+ /** Validate and compare a previous and new GTFS ZIP file. */
211
+ export function diff_gtfs(
212
+ oldZipBytes: Uint8Array,
213
+ newZipBytes: Uint8Array,
214
+ countryCode?: string | null,
215
+ date?: string | null
216
+ ): string;
217
+
218
+ /**
219
+ * GTFS Validator using Web Worker for non-blocking validation
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const validator = new GtfsValidator();
224
+ * await validator.waitUntilReady();
225
+ *
226
+ * const result = await validator.validate(file, { countryCode: 'US' });
227
+ * console.log(result.isValid, result.errorCount);
228
+ *
229
+ * validator.terminate();
230
+ * ```
231
+ */
232
+ export class GtfsValidator {
233
+ /**
234
+ * Create a new validator instance
235
+ * @param workerUrl - Optional custom URL to the worker script
236
+ */
237
+ constructor(workerUrl?: string);
238
+
239
+ /**
240
+ * Wait for the validator to be ready
241
+ */
242
+ waitUntilReady(): Promise<void>;
243
+
244
+ /**
245
+ * Validate a GTFS ZIP file
246
+ * @param input - The GTFS ZIP file (File, Blob, ArrayBuffer, or Uint8Array)
247
+ * @param options - Validation options
248
+ * @returns Validation result with counts and JSON report
249
+ */
250
+ validate(
251
+ input: File | Blob | ArrayBuffer | Uint8Array,
252
+ options?: ValidationOptions
253
+ ): Promise<ParsedValidationResult>;
254
+
255
+ /** Validate both feeds and return their semantic comparison. */
256
+ diff(
257
+ oldInput: File | Blob | ArrayBuffer | Uint8Array,
258
+ newInput: File | Blob | ArrayBuffer | Uint8Array,
259
+ options?: ValidationOptions
260
+ ): Promise<ParsedDiffResult>;
261
+
262
+ /**
263
+ * Get the validator version
264
+ */
265
+ version(): Promise<string>;
266
+
267
+ /**
268
+ * Terminate the worker and release resources
269
+ */
270
+ terminate(): void;
271
+ }
package/index.js ADDED
@@ -0,0 +1,203 @@
1
+ /**
2
+ * GTFS Validator - Main Thread Wrapper
3
+ *
4
+ * Provides a Promise-based API for validating GTFS feeds using a Web Worker.
5
+ *
6
+ * Usage:
7
+ * import { GtfsValidator } from '@abasisltd/gtfs-guru-wasm/index.js';
8
+ *
9
+ * const validator = new GtfsValidator();
10
+ * const result = await validator.validate(file, { countryCode: 'US' });
11
+ * console.log(result.isValid, result.errorCount);
12
+ * validator.terminate();
13
+ */
14
+
15
+ /**
16
+ * @typedef {Object} ValidationResult
17
+ * @property {string} json - Full validation report as JSON string
18
+ * @property {number} errorCount - Number of errors found
19
+ * @property {number} warningCount - Number of warnings found
20
+ * @property {number} infoCount - Number of info notices
21
+ * @property {boolean} isValid - True if no errors were found
22
+ * @property {number} validationTimeMs - Time taken for validation in milliseconds
23
+ */
24
+
25
+ /**
26
+ * @typedef {Object} ValidationOptions
27
+ * @property {string} [countryCode] - ISO 3166-1 alpha-2 country code (e.g., "US", "DE")
28
+ * @property {string} [date] - Validation date in YYYY-MM-DD format
29
+ */
30
+
31
+ /**
32
+ * GTFS Validator using Web Worker for non-blocking validation
33
+ */
34
+ export class GtfsValidator {
35
+ /**
36
+ * Create a new validator instance
37
+ * @param {string} [workerUrl] - Custom URL to the worker script
38
+ */
39
+ constructor(workerUrl) {
40
+ this.worker = new Worker(
41
+ workerUrl || new URL('./worker.js', import.meta.url),
42
+ { type: 'module' }
43
+ );
44
+ this.pending = new Map();
45
+ this.nextId = 0;
46
+ this.ready = false;
47
+
48
+ this.readyPromise = new Promise((resolve, reject) => {
49
+ const handler = (event) => {
50
+ if (event.data.type === 'ready') {
51
+ this.ready = true;
52
+ this.worker.removeEventListener('message', handler);
53
+ resolve();
54
+ } else if (event.data.type === 'error' && event.data.id == null) {
55
+ this.worker.removeEventListener('message', handler);
56
+ reject(new Error(event.data.payload));
57
+ }
58
+ };
59
+ this.worker.addEventListener('message', handler);
60
+ });
61
+
62
+ this.worker.onmessage = (event) => {
63
+ const { id, type, payload } = event.data;
64
+
65
+ // Skip 'ready' messages in main handler
66
+ if (type === 'ready') return;
67
+
68
+ const handler = this.pending.get(id);
69
+ if (handler) {
70
+ this.pending.delete(id);
71
+ if (type === 'error') {
72
+ handler.reject(new Error(payload));
73
+ } else {
74
+ handler.resolve(payload);
75
+ }
76
+ }
77
+ };
78
+
79
+ this.worker.onerror = (error) => {
80
+ // Reject all pending promises on worker error
81
+ for (const [id, handler] of this.pending) {
82
+ handler.reject(error);
83
+ this.pending.delete(id);
84
+ }
85
+ };
86
+ }
87
+
88
+ /**
89
+ * Wait for the validator to be ready
90
+ * @returns {Promise<void>}
91
+ */
92
+ async waitUntilReady() {
93
+ return this.readyPromise;
94
+ }
95
+
96
+ /**
97
+ * Validate a GTFS ZIP file
98
+ * @param {File|Blob|ArrayBuffer|Uint8Array} input - The GTFS ZIP file
99
+ * @param {ValidationOptions} [options] - Validation options
100
+ * @returns {Promise<ValidationResult>}
101
+ */
102
+ async validate(input, options = {}) {
103
+ await this.readyPromise;
104
+
105
+ let zipBytes;
106
+
107
+ if (input instanceof Uint8Array) {
108
+ zipBytes = input.buffer;
109
+ } else if (input instanceof ArrayBuffer) {
110
+ zipBytes = input;
111
+ } else if (input instanceof Blob || input instanceof File) {
112
+ zipBytes = await input.arrayBuffer();
113
+ } else {
114
+ throw new Error('Input must be a File, Blob, ArrayBuffer, or Uint8Array');
115
+ }
116
+
117
+ return this._send('validate', {
118
+ zipBytes,
119
+ countryCode: options.countryCode,
120
+ date: options.date,
121
+ });
122
+ }
123
+
124
+ /**
125
+ * Validate and compare two GTFS ZIP files
126
+ * @param {File|Blob|ArrayBuffer|Uint8Array} oldInput - Previous feed
127
+ * @param {File|Blob|ArrayBuffer|Uint8Array} newInput - New feed
128
+ * @param {ValidationOptions} [options] - Validation options
129
+ * @returns {Promise<Object>} Semantic feed diff
130
+ */
131
+ async diff(oldInput, newInput, options = {}) {
132
+ await this.readyPromise;
133
+ const [oldZipBytes, newZipBytes] = await Promise.all([
134
+ this._toArrayBuffer(oldInput),
135
+ this._toArrayBuffer(newInput),
136
+ ]);
137
+ const result = await this._send('diff', {
138
+ oldZipBytes,
139
+ newZipBytes,
140
+ countryCode: options.countryCode,
141
+ date: options.date,
142
+ });
143
+ return {
144
+ ...result,
145
+ diff: JSON.parse(result.json),
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Get the validator version
151
+ * @returns {Promise<string>}
152
+ */
153
+ async version() {
154
+ await this.readyPromise;
155
+ return this._send('version');
156
+ }
157
+
158
+ /**
159
+ * Terminate the worker
160
+ */
161
+ terminate() {
162
+ this.worker.terminate();
163
+ // Reject any pending promises
164
+ for (const [id, handler] of this.pending) {
165
+ handler.reject(new Error('Validator terminated'));
166
+ this.pending.delete(id);
167
+ }
168
+ }
169
+
170
+ async _toArrayBuffer(input) {
171
+ if (input instanceof Uint8Array) {
172
+ return input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength);
173
+ }
174
+ if (input instanceof ArrayBuffer) {
175
+ return input;
176
+ }
177
+ if (input instanceof Blob || input instanceof File) {
178
+ return input.arrayBuffer();
179
+ }
180
+ throw new Error('Input must be a File, Blob, ArrayBuffer, or Uint8Array');
181
+ }
182
+
183
+ /**
184
+ * Send a message to the worker and return a promise
185
+ * @private
186
+ */
187
+ _send(type, payload) {
188
+ return new Promise((resolve, reject) => {
189
+ const id = this.nextId++;
190
+ this.pending.set(id, { resolve, reject });
191
+ this.worker.postMessage({ type, payload, id });
192
+ });
193
+ }
194
+ }
195
+
196
+ // Re-export direct WASM functions for synchronous usage
197
+ export {
198
+ default as init,
199
+ diff_gtfs,
200
+ validate_gtfs,
201
+ validate_gtfs_json,
202
+ version,
203
+ } from './gtfs_guru_wasm.js';
package/package.json CHANGED
@@ -1,22 +1,42 @@
1
1
  {
2
2
  "name": "@abasisltd/gtfs-guru-wasm",
3
+ "version": "1.0.0",
4
+ "description": "GTFS feed validator - WebAssembly build. Validate GTFS feeds entirely in the browser.",
3
5
  "type": "module",
4
- "description": "GTFS validator compiled to WebAssembly for browser-based validation",
5
- "version": "0.9.3",
6
+ "main": "gtfs_guru_wasm.js",
7
+ "types": "gtfs_guru_wasm.d.ts",
8
+ "module": "gtfs_guru_wasm.js",
9
+ "sideEffects": [
10
+ "./snippets/*"
11
+ ],
12
+ "files": [
13
+ "gtfs_guru_wasm.js",
14
+ "gtfs_guru_wasm.d.ts",
15
+ "gtfs_guru_wasm_bg.wasm",
16
+ "gtfs_guru_wasm_bg.wasm.d.ts",
17
+ "worker.js",
18
+ "index.js",
19
+ "index.d.ts"
20
+ ],
21
+ "keywords": [
22
+ "gtfs",
23
+ "transit",
24
+ "validator",
25
+ "wasm",
26
+ "webassembly",
27
+ "public-transit",
28
+ "transportation"
29
+ ],
6
30
  "license": "Apache-2.0",
7
31
  "repository": {
8
32
  "type": "git",
9
33
  "url": "https://github.com/abasis-ltd/gtfs.guru"
10
34
  },
11
- "files": [
12
- "gtfs_guru_wasm_bg.wasm",
13
- "gtfs_guru_wasm.js",
14
- "gtfs_guru_wasm.d.ts"
15
- ],
16
- "main": "gtfs_guru_wasm.js",
17
- "homepage": "https://github.com/abasis-ltd/gtfs.guru",
18
- "types": "gtfs_guru_wasm.d.ts",
19
- "sideEffects": [
20
- "./snippets/*"
21
- ]
22
- }
35
+ "homepage": "https://github.com/abasis-ltd/gtfs.guru#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/abasis-ltd/gtfs.guru/issues"
38
+ },
39
+ "engines": {
40
+ "node": ">=16"
41
+ }
42
+ }
package/worker.js ADDED
@@ -0,0 +1,168 @@
1
+ /**
2
+ * GTFS Validator Web Worker
3
+ *
4
+ * This worker runs the WASM validator in a separate thread to avoid blocking the main UI.
5
+ *
6
+ * Usage:
7
+ * const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
8
+ * worker.postMessage({ type: 'validate', payload: { zipBytes, countryCode }, id: 1 });
9
+ * worker.postMessage({ type: 'diff', payload: { oldZipBytes, newZipBytes }, id: 2 });
10
+ * worker.onmessage = (e) => console.log(e.data);
11
+ */
12
+
13
+ let wasm;
14
+ let runtime = 'single-threaded';
15
+ let initializationPromise;
16
+
17
+ function canUseThreads() {
18
+ // Diagnostic override for golden comparisons and benchmarks. It never
19
+ // enables threads when the browser or hosting environment cannot support
20
+ // them; it only forces the portable fallback.
21
+ if (new URL(self.location.href).searchParams.get('threads') === 'off') {
22
+ return false;
23
+ }
24
+
25
+ // iOS has a much tighter WASM memory budget and nested-worker support varies
26
+ // across versions, so keep the conservative single-threaded path there.
27
+ const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent)
28
+ || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
29
+
30
+ return !isIOS
31
+ && self.crossOriginIsolated === true
32
+ && typeof SharedArrayBuffer !== 'undefined'
33
+ && typeof WebAssembly.Memory === 'function';
34
+ }
35
+
36
+ /**
37
+ * Initialize the WASM module
38
+ * @returns {Promise<void>}
39
+ */
40
+ async function ensureInitialized() {
41
+ if (!initializationPromise) {
42
+ initializationPromise = (async () => {
43
+ if (canUseThreads()) {
44
+ try {
45
+ const threaded = await import('../pkg-mt/gtfs_guru_wasm.js');
46
+ await threaded.default();
47
+ const hardwareThreads = navigator.hardwareConcurrency || 2;
48
+ await threaded.initThreadPool(Math.min(Math.max(hardwareThreads, 1), 8));
49
+ wasm = threaded;
50
+ runtime = 'multi-threaded';
51
+ } catch (error) {
52
+ console.warn('Multi-threaded WASM initialization failed; using fallback.', error);
53
+ }
54
+ }
55
+
56
+ if (!wasm) {
57
+ const singleThreaded = await import('./gtfs_guru_wasm.js');
58
+ await singleThreaded.default();
59
+ wasm = singleThreaded;
60
+ }
61
+ })();
62
+ }
63
+ return initializationPromise;
64
+ }
65
+
66
+ /**
67
+ * Handle incoming messages from the main thread
68
+ */
69
+ self.onmessage = async (event) => {
70
+ const { type, payload, id } = event.data;
71
+
72
+ try {
73
+ await ensureInitialized();
74
+
75
+ switch (type) {
76
+ case 'validate': {
77
+ const { zipBytes, countryCode, date, includeHtml = true } = payload;
78
+ const startTime = performance.now();
79
+
80
+ const result = wasm.validate_gtfs(
81
+ new Uint8Array(zipBytes),
82
+ countryCode || null,
83
+ date || null,
84
+ );
85
+
86
+ const elapsed = performance.now() - startTime;
87
+ try {
88
+ const json = result.take_json();
89
+ const html = includeHtml ? result.take_html() : '';
90
+ const timingsJson = result.take_timings_json();
91
+ self.postMessage({
92
+ id,
93
+ type: 'result',
94
+ payload: {
95
+ json,
96
+ html,
97
+ errorCount: result.error_count,
98
+ warningCount: result.warning_count,
99
+ infoCount: result.info_count,
100
+ isValid: result.is_valid,
101
+ truncated: result.truncated,
102
+ validationTimeMs: elapsed,
103
+ timings: JSON.parse(timingsJson),
104
+ runtime,
105
+ },
106
+ });
107
+ } finally {
108
+ // Release Rust-owned strings immediately instead of waiting for JS
109
+ // finalization, which is important after large-feed validation.
110
+ result.free();
111
+ }
112
+ break;
113
+ }
114
+
115
+ case 'diff': {
116
+ const { oldZipBytes, newZipBytes, countryCode, date } = payload;
117
+ const startTime = performance.now();
118
+ const json = wasm.diff_gtfs(
119
+ new Uint8Array(oldZipBytes),
120
+ new Uint8Array(newZipBytes),
121
+ countryCode || null,
122
+ date || null,
123
+ );
124
+ self.postMessage({
125
+ id,
126
+ type: 'diff-result',
127
+ payload: {
128
+ json,
129
+ comparisonTimeMs: performance.now() - startTime,
130
+ runtime,
131
+ },
132
+ });
133
+ break;
134
+ }
135
+
136
+ case 'version': {
137
+ self.postMessage({
138
+ id,
139
+ type: 'version',
140
+ payload: wasm.version(),
141
+ });
142
+ break;
143
+ }
144
+
145
+ default:
146
+ self.postMessage({
147
+ id,
148
+ type: 'error',
149
+ payload: `Unknown message type: ${type}`,
150
+ });
151
+ }
152
+ } catch (error) {
153
+ self.postMessage({
154
+ id,
155
+ type: 'error',
156
+ payload: error instanceof Error ? error.message : String(error),
157
+ });
158
+ }
159
+ };
160
+
161
+ // Initialize eagerly. Consumers only receive "ready" after the WASM module and
162
+ // (when available) its Rayon worker pool are ready for validation.
163
+ ensureInitialized()
164
+ .then(() => self.postMessage({ type: 'ready', payload: { runtime } }))
165
+ .catch((error) => self.postMessage({
166
+ type: 'error',
167
+ payload: error instanceof Error ? error.message : String(error),
168
+ }));