@abasisltd/gtfs-guru-wasm 0.1.1

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.
@@ -0,0 +1,108 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class ValidationResult {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ /**
9
+ * Get the number of info notices
10
+ */
11
+ readonly info_count: number;
12
+ /**
13
+ * Get the number of errors
14
+ */
15
+ readonly error_count: number;
16
+ /**
17
+ * Get the number of warnings
18
+ */
19
+ readonly warning_count: number;
20
+ /**
21
+ * Get the full validation report as HTML
22
+ */
23
+ readonly html: string;
24
+ /**
25
+ * Get the full validation report as JSON
26
+ */
27
+ readonly json: string;
28
+ /**
29
+ * Check if validation passed (no errors)
30
+ */
31
+ readonly is_valid: boolean;
32
+ }
33
+
34
+ /**
35
+ * Initialize the WASM module (call once on page load)
36
+ */
37
+ export function init(): void;
38
+
39
+ /**
40
+ * Validate a GTFS ZIP file from bytes
41
+ *
42
+ * # Arguments
43
+ * * `zip_bytes` - The raw bytes of a GTFS ZIP file
44
+ * * `country_code` - Optional ISO 3166-1 alpha-2 country code for country-specific validation
45
+ * * `date` - Optional validation date in YYYY-MM-DD format
46
+ *
47
+ * # Returns
48
+ * A ValidationResult containing the JSON report and summary counts
49
+ *
50
+ * # Errors
51
+ * Throws a JavaScript error if the file exceeds 50 MB
52
+ */
53
+ export function validate_gtfs(zip_bytes: Uint8Array, country_code?: string | null, date?: string | null): ValidationResult;
54
+
55
+ /**
56
+ * Validate GTFS and return only the JSON report (simpler API)
57
+ */
58
+ export function validate_gtfs_json(zip_bytes: Uint8Array, country_code?: string | null, date?: string | null): string;
59
+
60
+ /**
61
+ * Get the validator version
62
+ */
63
+ export function version(): string;
64
+
65
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
66
+
67
+ export interface InitOutput {
68
+ readonly memory: WebAssembly.Memory;
69
+ 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];
72
+ readonly validationresult_error_count: (a: number) => number;
73
+ readonly validationresult_html: (a: number) => [number, number];
74
+ readonly validationresult_info_count: (a: number) => number;
75
+ readonly validationresult_is_valid: (a: number) => number;
76
+ readonly validationresult_json: (a: number) => [number, number];
77
+ readonly validationresult_warning_count: (a: number) => number;
78
+ readonly version: () => [number, number];
79
+ 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;
86
+ }
87
+
88
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
89
+
90
+ /**
91
+ * Instantiates the given `module`, which can either be bytes or
92
+ * a precompiled `WebAssembly.Module`.
93
+ *
94
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
95
+ *
96
+ * @returns {InitOutput}
97
+ */
98
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
99
+
100
+ /**
101
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
102
+ * for everything else, calls `WebAssembly.instantiate` directly.
103
+ *
104
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
105
+ *
106
+ * @returns {Promise<InitOutput>}
107
+ */
108
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,444 @@
1
+ let wasm;
2
+
3
+ let cachedDataViewMemory0 = null;
4
+ function getDataViewMemory0() {
5
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
6
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
7
+ }
8
+ return cachedDataViewMemory0;
9
+ }
10
+
11
+ function getStringFromWasm0(ptr, len) {
12
+ ptr = ptr >>> 0;
13
+ return decodeText(ptr, len);
14
+ }
15
+
16
+ let cachedUint8ArrayMemory0 = null;
17
+ function getUint8ArrayMemory0() {
18
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
19
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
20
+ }
21
+ return cachedUint8ArrayMemory0;
22
+ }
23
+
24
+ function isLikeNone(x) {
25
+ return x === undefined || x === null;
26
+ }
27
+
28
+ function passArray8ToWasm0(arg, malloc) {
29
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
30
+ getUint8ArrayMemory0().set(arg, ptr / 1);
31
+ WASM_VECTOR_LEN = arg.length;
32
+ return ptr;
33
+ }
34
+
35
+ function passStringToWasm0(arg, malloc, realloc) {
36
+ if (realloc === undefined) {
37
+ const buf = cachedTextEncoder.encode(arg);
38
+ const ptr = malloc(buf.length, 1) >>> 0;
39
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
40
+ WASM_VECTOR_LEN = buf.length;
41
+ return ptr;
42
+ }
43
+
44
+ let len = arg.length;
45
+ let ptr = malloc(len, 1) >>> 0;
46
+
47
+ const mem = getUint8ArrayMemory0();
48
+
49
+ let offset = 0;
50
+
51
+ for (; offset < len; offset++) {
52
+ const code = arg.charCodeAt(offset);
53
+ if (code > 0x7F) break;
54
+ mem[ptr + offset] = code;
55
+ }
56
+ if (offset !== len) {
57
+ if (offset !== 0) {
58
+ arg = arg.slice(offset);
59
+ }
60
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
61
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
62
+ const ret = cachedTextEncoder.encodeInto(arg, view);
63
+
64
+ offset += ret.written;
65
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
66
+ }
67
+
68
+ WASM_VECTOR_LEN = offset;
69
+ return ptr;
70
+ }
71
+
72
+ function takeFromExternrefTable0(idx) {
73
+ const value = wasm.__wbindgen_externrefs.get(idx);
74
+ wasm.__externref_table_dealloc(idx);
75
+ return value;
76
+ }
77
+
78
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
79
+ cachedTextDecoder.decode();
80
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
81
+ let numBytesDecoded = 0;
82
+ function decodeText(ptr, len) {
83
+ numBytesDecoded += len;
84
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
85
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
86
+ cachedTextDecoder.decode();
87
+ numBytesDecoded = len;
88
+ }
89
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
90
+ }
91
+
92
+ const cachedTextEncoder = new TextEncoder();
93
+
94
+ if (!('encodeInto' in cachedTextEncoder)) {
95
+ cachedTextEncoder.encodeInto = function (arg, view) {
96
+ const buf = cachedTextEncoder.encode(arg);
97
+ view.set(buf);
98
+ return {
99
+ read: arg.length,
100
+ written: buf.length
101
+ };
102
+ }
103
+ }
104
+
105
+ let WASM_VECTOR_LEN = 0;
106
+
107
+ const ValidationResultFinalization = (typeof FinalizationRegistry === 'undefined')
108
+ ? { register: () => {}, unregister: () => {} }
109
+ : new FinalizationRegistry(ptr => wasm.__wbg_validationresult_free(ptr >>> 0, 1));
110
+
111
+ /**
112
+ * Validation result returned to JavaScript
113
+ */
114
+ export class ValidationResult {
115
+ static __wrap(ptr) {
116
+ ptr = ptr >>> 0;
117
+ const obj = Object.create(ValidationResult.prototype);
118
+ obj.__wbg_ptr = ptr;
119
+ ValidationResultFinalization.register(obj, obj.__wbg_ptr, obj);
120
+ return obj;
121
+ }
122
+ __destroy_into_raw() {
123
+ const ptr = this.__wbg_ptr;
124
+ this.__wbg_ptr = 0;
125
+ ValidationResultFinalization.unregister(this);
126
+ return ptr;
127
+ }
128
+ free() {
129
+ const ptr = this.__destroy_into_raw();
130
+ wasm.__wbg_validationresult_free(ptr, 0);
131
+ }
132
+ /**
133
+ * Get the number of info notices
134
+ * @returns {number}
135
+ */
136
+ get info_count() {
137
+ const ret = wasm.validationresult_info_count(this.__wbg_ptr);
138
+ return ret >>> 0;
139
+ }
140
+ /**
141
+ * Get the number of errors
142
+ * @returns {number}
143
+ */
144
+ get error_count() {
145
+ const ret = wasm.validationresult_error_count(this.__wbg_ptr);
146
+ return ret >>> 0;
147
+ }
148
+ /**
149
+ * Get the number of warnings
150
+ * @returns {number}
151
+ */
152
+ get warning_count() {
153
+ const ret = wasm.validationresult_warning_count(this.__wbg_ptr);
154
+ return ret >>> 0;
155
+ }
156
+ /**
157
+ * Get the full validation report as HTML
158
+ * @returns {string}
159
+ */
160
+ get html() {
161
+ let deferred1_0;
162
+ let deferred1_1;
163
+ 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]);
168
+ } finally {
169
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
170
+ }
171
+ }
172
+ /**
173
+ * Get the full validation report as JSON
174
+ * @returns {string}
175
+ */
176
+ get json() {
177
+ let deferred1_0;
178
+ let deferred1_1;
179
+ 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]);
184
+ } finally {
185
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
186
+ }
187
+ }
188
+ /**
189
+ * Check if validation passed (no errors)
190
+ * @returns {boolean}
191
+ */
192
+ get is_valid() {
193
+ const ret = wasm.validationresult_is_valid(this.__wbg_ptr);
194
+ return ret !== 0;
195
+ }
196
+ }
197
+ if (Symbol.dispose) ValidationResult.prototype[Symbol.dispose] = ValidationResult.prototype.free;
198
+
199
+ /**
200
+ * Initialize the WASM module (call once on page load)
201
+ */
202
+ export function init() {
203
+ wasm.init();
204
+ }
205
+
206
+ /**
207
+ * Validate a GTFS ZIP file from bytes
208
+ *
209
+ * # Arguments
210
+ * * `zip_bytes` - The raw bytes of a GTFS ZIP file
211
+ * * `country_code` - Optional ISO 3166-1 alpha-2 country code for country-specific validation
212
+ * * `date` - Optional validation date in YYYY-MM-DD format
213
+ *
214
+ * # Returns
215
+ * A ValidationResult containing the JSON report and summary counts
216
+ *
217
+ * # Errors
218
+ * Throws a JavaScript error if the file exceeds 50 MB
219
+ * @param {Uint8Array} zip_bytes
220
+ * @param {string | null} [country_code]
221
+ * @param {string | null} [date]
222
+ * @returns {ValidationResult}
223
+ */
224
+ 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]);
236
+ }
237
+
238
+ /**
239
+ * Validate GTFS and return only the JSON report (simpler API)
240
+ * @param {Uint8Array} zip_bytes
241
+ * @param {string | null} [country_code]
242
+ * @param {string | null} [date]
243
+ * @returns {string}
244
+ */
245
+ export function validate_gtfs_json(zip_bytes, country_code, date) {
246
+ let deferred5_0;
247
+ let deferred5_1;
248
+ try {
249
+ const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_malloc);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ var ptr1 = isLikeNone(country_code) ? 0 : passStringToWasm0(country_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
252
+ var len1 = WASM_VECTOR_LEN;
253
+ var ptr2 = isLikeNone(date) ? 0 : passStringToWasm0(date, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
254
+ 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]) {
259
+ ptr4 = 0; len4 = 0;
260
+ throw takeFromExternrefTable0(ret[2]);
261
+ }
262
+ deferred5_0 = ptr4;
263
+ deferred5_1 = len4;
264
+ return getStringFromWasm0(ptr4, len4);
265
+ } finally {
266
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Get the validator version
272
+ * @returns {string}
273
+ */
274
+ export function version() {
275
+ let deferred1_0;
276
+ let deferred1_1;
277
+ try {
278
+ const ret = wasm.version();
279
+ deferred1_0 = ret[0];
280
+ deferred1_1 = ret[1];
281
+ return getStringFromWasm0(ret[0], ret[1]);
282
+ } finally {
283
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
284
+ }
285
+ }
286
+
287
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
288
+
289
+ async function __wbg_load(module, imports) {
290
+ if (typeof Response === 'function' && module instanceof Response) {
291
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
292
+ try {
293
+ return await WebAssembly.instantiateStreaming(module, imports);
294
+ } catch (e) {
295
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
296
+
297
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
298
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
299
+
300
+ } else {
301
+ throw e;
302
+ }
303
+ }
304
+ }
305
+
306
+ const bytes = await module.arrayBuffer();
307
+ return await WebAssembly.instantiate(bytes, imports);
308
+ } else {
309
+ const instance = await WebAssembly.instantiate(module, imports);
310
+
311
+ if (instance instanceof WebAssembly.Instance) {
312
+ return { instance, module };
313
+ } else {
314
+ return instance;
315
+ }
316
+ }
317
+ }
318
+
319
+ function __wbg_get_imports() {
320
+ const imports = {};
321
+ imports.wbg = {};
322
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
323
+ throw new Error(getStringFromWasm0(arg0, arg1));
324
+ };
325
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
326
+ let deferred0_0;
327
+ let deferred0_1;
328
+ try {
329
+ deferred0_0 = arg0;
330
+ deferred0_1 = arg1;
331
+ console.error(getStringFromWasm0(arg0, arg1));
332
+ } finally {
333
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
334
+ }
335
+ };
336
+ imports.wbg.__wbg_getTime_ad1e9878a735af08 = function(arg0) {
337
+ const ret = arg0.getTime();
338
+ return ret;
339
+ };
340
+ imports.wbg.__wbg_getTimezoneOffset_45389e26d6f46823 = function(arg0) {
341
+ const ret = arg0.getTimezoneOffset();
342
+ return ret;
343
+ };
344
+ imports.wbg.__wbg_new_0_23cedd11d9b40c9d = function() {
345
+ const ret = new Date();
346
+ return ret;
347
+ };
348
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
349
+ const ret = new Error();
350
+ return ret;
351
+ };
352
+ imports.wbg.__wbg_new_b2db8aa2650f793a = function(arg0) {
353
+ const ret = new Date(arg0);
354
+ return ret;
355
+ };
356
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
357
+ const ret = arg1.stack;
358
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
359
+ const len1 = WASM_VECTOR_LEN;
360
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
361
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
362
+ };
363
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
364
+ // Cast intrinsic for `Ref(String) -> Externref`.
365
+ const ret = getStringFromWasm0(arg0, arg1);
366
+ return ret;
367
+ };
368
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
369
+ // Cast intrinsic for `F64 -> Externref`.
370
+ const ret = arg0;
371
+ return ret;
372
+ };
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);
381
+ };
382
+
383
+ return imports;
384
+ }
385
+
386
+ function __wbg_finalize_init(instance, module) {
387
+ wasm = instance.exports;
388
+ __wbg_init.__wbindgen_wasm_module = module;
389
+ cachedDataViewMemory0 = null;
390
+ cachedUint8ArrayMemory0 = null;
391
+
392
+
393
+ wasm.__wbindgen_start();
394
+ return wasm;
395
+ }
396
+
397
+ function initSync(module) {
398
+ if (wasm !== undefined) return wasm;
399
+
400
+
401
+ if (typeof module !== 'undefined') {
402
+ if (Object.getPrototypeOf(module) === Object.prototype) {
403
+ ({module} = module)
404
+ } else {
405
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
406
+ }
407
+ }
408
+
409
+ const imports = __wbg_get_imports();
410
+ if (!(module instanceof WebAssembly.Module)) {
411
+ module = new WebAssembly.Module(module);
412
+ }
413
+ const instance = new WebAssembly.Instance(module, imports);
414
+ return __wbg_finalize_init(instance, module);
415
+ }
416
+
417
+ async function __wbg_init(module_or_path) {
418
+ if (wasm !== undefined) return wasm;
419
+
420
+
421
+ if (typeof module_or_path !== 'undefined') {
422
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
423
+ ({module_or_path} = module_or_path)
424
+ } else {
425
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
426
+ }
427
+ }
428
+
429
+ if (typeof module_or_path === 'undefined') {
430
+ module_or_path = new URL('gtfs_guru_wasm_bg.wasm', import.meta.url);
431
+ }
432
+ const imports = __wbg_get_imports();
433
+
434
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
435
+ module_or_path = fetch(module_or_path);
436
+ }
437
+
438
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
439
+
440
+ return __wbg_finalize_init(instance, module);
441
+ }
442
+
443
+ export { initSync };
444
+ export default __wbg_init;
Binary file
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@abasisltd/gtfs-guru-wasm",
3
+ "description": "GTFS validator compiled to WebAssembly for browser-based validation",
4
+ "version": "0.1.1",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/abasis-ltd/gtfs.guru"
9
+ },
10
+ "files": [
11
+ "gtfs_guru_wasm_bg.wasm",
12
+ "gtfs_guru_wasm.js",
13
+ "gtfs_guru_wasm.d.ts"
14
+ ],
15
+ "module": "gtfs_guru_wasm.js",
16
+ "homepage": "https://github.com/abasis-ltd/gtfs.guru",
17
+ "types": "gtfs_guru_wasm.d.ts",
18
+ "sideEffects": false
19
+ }