From 51909b754f68abcb1859c4da048ccb9ceef9e346 Mon Sep 17 00:00:00 2001 From: Arpit-Mahajan09 Date: Tue, 27 Oct 2026 11:50:48 +0530 Subject: [PATCH] added fatbuffers generation script --- eslint.config.js | 2 +- features/step_definitions/distance_matrix.js | 2 +- features/step_definitions/nearest.js | 2 +- features/support/fbresult.js | 28 + features/support/fbresult_generated.js | 1507 ------------------ package.json | 2 +- scripts/regenerate_fbresult_js.sh | 77 +- test/nodejs/constants.js | 2 +- test/nodejs/constants.js.orig | 29 + 9 files changed, 129 insertions(+), 1522 deletions(-) create mode 100644 features/support/fbresult.js delete mode 100644 features/support/fbresult_generated.js create mode 100644 test/nodejs/constants.js.orig diff --git a/eslint.config.js b/eslint.config.js index aae0bdf8020..72a43b8ab85 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -25,7 +25,7 @@ const config = [ 'prefer-template': 'error', 'prefer-arrow-callback': 'error', }, - ignores: ['node_modules/', 'build/', 'dist/', 'coverage/', 'features/support/fbresult_generated.js'], + ignores: ['node_modules/', 'build/', 'dist/', 'coverage/', 'features/generated/**'], }, ]; diff --git a/features/step_definitions/distance_matrix.js b/features/step_definitions/distance_matrix.js index 86a15924ea9..a6f78879c0a 100644 --- a/features/step_definitions/distance_matrix.js +++ b/features/step_definitions/distance_matrix.js @@ -2,7 +2,7 @@ import util from 'util'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../support/fbresult_generated.js'; +import { osrm } from '../support/fbresult.js'; const FBResult = osrm.engine.api.fbresult.FBResult; import { When } from '@cucumber/cucumber'; diff --git a/features/step_definitions/nearest.js b/features/step_definitions/nearest.js index 3a5655a5ca3..c961fbce9fc 100644 --- a/features/step_definitions/nearest.js +++ b/features/step_definitions/nearest.js @@ -2,7 +2,7 @@ import util from 'util'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../support/fbresult_generated.js'; +import { osrm } from '../support/fbresult.js'; const FBResult = osrm.engine.api.fbresult.FBResult; import assert from 'node:assert'; import { When } from '@cucumber/cucumber'; diff --git a/features/support/fbresult.js b/features/support/fbresult.js new file mode 100644 index 00000000000..d3d373dbe84 --- /dev/null +++ b/features/support/fbresult.js @@ -0,0 +1,28 @@ +// Loads the flatbuffers JavaScript bundle used to decode `format=flatbuffers` +// responses, generating it first from include/engine/api/flatbuffers/*.fbs. +// +// The bundle is not committed: a stale copy silently decodes the old field +// layout, so it is rebuilt whenever the schemas change. The script returns +// immediately when the bundle is already up to date. +import { execFileSync } from 'node:child_process'; +import path from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); + +try { + execFileSync('bash', [path.join(root, 'scripts/regenerate_fbresult_js.sh')], { + cwd: root, + // Keep stdout quiet so it does not interleave with cucumber's formatter, + // but let errors (such as "no flatc found") through. + stdio: ['ignore', 'ignore', 'inherit'], + }); +} catch { + throw new Error( + 'Failed to generate features/generated/fbresult.js from the flatbuffers ' + + 'schemas (see the message above). Run `npm run regenerate-fbresult` for details.' + ); +} + +const bundle = pathToFileURL(path.join(root, 'features/generated/fbresult.js')).href; +export const { osrm } = await import(bundle); diff --git a/features/support/fbresult_generated.js b/features/support/fbresult_generated.js deleted file mode 100644 index ec39e1a3933..00000000000 --- a/features/support/fbresult_generated.js +++ /dev/null @@ -1,1507 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify -// Generated from TypeScript using flatc --ts and esbuild -// Regenerate with: npm run regenerate-fbresult - -var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; - -// osrm/engine/api/fbresult.ts -var fbresult_exports = {}; -__export(fbresult_exports, { - Annotation: () => Annotation, - Error: () => Error2, - FBResult: () => FBResult, - Intersection: () => Intersection, - Lane: () => Lane, - Leg: () => Leg, - ManeuverType: () => ManeuverType, - Metadata: () => Metadata, - Position: () => Position, - RouteObject: () => RouteObject, - Step: () => Step, - StepManeuver: () => StepManeuver, - TableResult: () => TableResult, - Turn: () => Turn, - Uint64Pair: () => Uint64Pair, - Waypoint: () => Waypoint, - WaypointGroup: () => WaypointGroup -}); - -// osrm/engine/api/fbresult/annotation.ts -import * as flatbuffers2 from "flatbuffers"; - -// osrm/engine/api/fbresult/metadata.ts -import * as flatbuffers from "flatbuffers"; -var Metadata = class _Metadata { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsMetadata(bb, obj) { - return (obj || new _Metadata()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsMetadata(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new _Metadata()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - datasourceNames(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; - } - datasourceNamesLength() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static startMetadata(builder) { - builder.startObject(1); - } - static addDatasourceNames(builder, datasourceNamesOffset) { - builder.addFieldOffset(0, datasourceNamesOffset, 0); - } - static createDatasourceNamesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startDatasourceNamesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endMetadata(builder) { - const offset = builder.endObject(); - return offset; - } - static createMetadata(builder, datasourceNamesOffset) { - _Metadata.startMetadata(builder); - _Metadata.addDatasourceNames(builder, datasourceNamesOffset); - return _Metadata.endMetadata(builder); - } -}; - -// osrm/engine/api/fbresult/annotation.ts -var Annotation = class _Annotation { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsAnnotation(bb, obj) { - return (obj || new _Annotation()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsAnnotation(bb, obj) { - bb.setPosition(bb.position() + flatbuffers2.SIZE_PREFIX_LENGTH); - return (obj || new _Annotation()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - distance(index) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - distanceLength() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - distanceArray() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - duration(index) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - durationLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - durationArray() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - datasources(index) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - datasourcesLength() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - datasourcesArray() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - nodes(index) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0); - } - nodesLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - weight(index) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - weightLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - weightArray() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - speed(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - speedLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - speedArray() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Float32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - metadata(obj) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? (obj || new Metadata()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - static startAnnotation(builder) { - builder.startObject(7); - } - static addDistance(builder, distanceOffset) { - builder.addFieldOffset(0, distanceOffset, 0); - } - static createDistanceVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); - } - static startDistanceVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDuration(builder, durationOffset) { - builder.addFieldOffset(1, durationOffset, 0); - } - static createDurationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); - } - static startDurationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDatasources(builder, datasourcesOffset) { - builder.addFieldOffset(2, datasourcesOffset, 0); - } - static createDatasourcesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); - } - static startDatasourcesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addNodes(builder, nodesOffset) { - builder.addFieldOffset(3, nodesOffset, 0); - } - static createNodesVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt64(data[i]); - } - return builder.endVector(); - } - static startNodesVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addWeight(builder, weightOffset) { - builder.addFieldOffset(4, weightOffset, 0); - } - static createWeightVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); - } - static startWeightVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addSpeed(builder, speedOffset) { - builder.addFieldOffset(5, speedOffset, 0); - } - static createSpeedVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addFloat32(data[i]); - } - return builder.endVector(); - } - static startSpeedVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addMetadata(builder, metadataOffset) { - builder.addFieldOffset(6, metadataOffset, 0); - } - static endAnnotation(builder) { - const offset = builder.endObject(); - return offset; - } -}; - -// osrm/engine/api/fbresult/error.ts -import * as flatbuffers3 from "flatbuffers"; -var Error2 = class _Error { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsError(bb, obj) { - return (obj || new _Error()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsError(bb, obj) { - bb.setPosition(bb.position() + flatbuffers3.SIZE_PREFIX_LENGTH); - return (obj || new _Error()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - code(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - message(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - static startError(builder) { - builder.startObject(2); - } - static addCode(builder, codeOffset) { - builder.addFieldOffset(0, codeOffset, 0); - } - static addMessage(builder, messageOffset) { - builder.addFieldOffset(1, messageOffset, 0); - } - static endError(builder) { - const offset = builder.endObject(); - return offset; - } - static createError(builder, codeOffset, messageOffset) { - _Error.startError(builder); - _Error.addCode(builder, codeOffset); - _Error.addMessage(builder, messageOffset); - return _Error.endError(builder); - } -}; - -// osrm/engine/api/fbresult/fbresult.ts -import * as flatbuffers13 from "flatbuffers"; - -// osrm/engine/api/fbresult/route-object.ts -import * as flatbuffers9 from "flatbuffers"; - -// osrm/engine/api/fbresult/leg.ts -import * as flatbuffers8 from "flatbuffers"; - -// osrm/engine/api/fbresult/position.ts -var Position = class { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - longitude() { - return this.bb.readFloat32(this.bb_pos); - } - latitude() { - return this.bb.readFloat32(this.bb_pos + 4); - } - static sizeOf() { - return 8; - } - static createPosition(builder, longitude, latitude) { - builder.prep(4, 8); - builder.writeFloat32(latitude); - builder.writeFloat32(longitude); - return builder.offset(); - } -}; - -// osrm/engine/api/fbresult/step.ts -import * as flatbuffers7 from "flatbuffers"; - -// osrm/engine/api/fbresult/intersection.ts -import * as flatbuffers5 from "flatbuffers"; - -// osrm/engine/api/fbresult/lane.ts -import * as flatbuffers4 from "flatbuffers"; -var Lane = class _Lane { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsLane(bb, obj) { - return (obj || new _Lane()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsLane(bb, obj) { - bb.setPosition(bb.position() + flatbuffers4.SIZE_PREFIX_LENGTH); - return (obj || new _Lane()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - indications(index) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : null; - } - indicationsLength() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - indicationsArray() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - valid() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - static startLane(builder) { - builder.startObject(2); - } - static addIndications(builder, indicationsOffset) { - builder.addFieldOffset(0, indicationsOffset, 0); - } - static createIndicationsVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); - } - static startIndicationsVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addValid(builder, valid) { - builder.addFieldInt8(1, +valid, 0); - } - static endLane(builder) { - const offset = builder.endObject(); - return offset; - } - static createLane(builder, indicationsOffset, valid) { - _Lane.startLane(builder); - _Lane.addIndications(builder, indicationsOffset); - _Lane.addValid(builder, valid); - return _Lane.endLane(builder); - } -}; - -// osrm/engine/api/fbresult/intersection.ts -var Intersection = class _Intersection { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsIntersection(bb, obj) { - return (obj || new _Intersection()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsIntersection(bb, obj) { - bb.setPosition(bb.position() + flatbuffers5.SIZE_PREFIX_LENGTH); - return (obj || new _Intersection()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - location(obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? (obj || new Position()).__init(this.bb_pos + offset, this.bb) : null; - } - bearings(index) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt16(this.bb.__vector(this.bb_pos + offset) + index * 2) : 0; - } - bearingsLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - bearingsArray() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Int16Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - classes(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; - } - classesLength() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - entry(index) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? !!this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : false; - } - entryLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - entryArray() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - inBearing() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - outBearing() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - lanes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? (obj || new Lane()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - lanesLength() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static startIntersection(builder) { - builder.startObject(7); - } - static addLocation(builder, locationOffset) { - builder.addFieldStruct(0, locationOffset, 0); - } - static addBearings(builder, bearingsOffset) { - builder.addFieldOffset(1, bearingsOffset, 0); - } - static createBearingsVector(builder, data) { - builder.startVector(2, data.length, 2); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt16(data[i]); - } - return builder.endVector(); - } - static startBearingsVector(builder, numElems) { - builder.startVector(2, numElems, 2); - } - static addClasses(builder, classesOffset) { - builder.addFieldOffset(2, classesOffset, 0); - } - static createClassesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startClassesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addEntry(builder, entryOffset) { - builder.addFieldOffset(3, entryOffset, 0); - } - static createEntryVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(+data[i]); - } - return builder.endVector(); - } - static startEntryVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addInBearing(builder, inBearing) { - builder.addFieldInt32(4, inBearing, 0); - } - static addOutBearing(builder, outBearing) { - builder.addFieldInt32(5, outBearing, 0); - } - static addLanes(builder, lanesOffset) { - builder.addFieldOffset(6, lanesOffset, 0); - } - static createLanesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startLanesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endIntersection(builder) { - const offset = builder.endObject(); - return offset; - } - static createIntersection(builder, locationOffset, bearingsOffset, classesOffset, entryOffset, inBearing, outBearing, lanesOffset) { - _Intersection.startIntersection(builder); - _Intersection.addLocation(builder, locationOffset); - _Intersection.addBearings(builder, bearingsOffset); - _Intersection.addClasses(builder, classesOffset); - _Intersection.addEntry(builder, entryOffset); - _Intersection.addInBearing(builder, inBearing); - _Intersection.addOutBearing(builder, outBearing); - _Intersection.addLanes(builder, lanesOffset); - return _Intersection.endIntersection(builder); - } -}; - -// osrm/engine/api/fbresult/step-maneuver.ts -import * as flatbuffers6 from "flatbuffers"; - -// osrm/engine/api/fbresult/maneuver-type.ts -var ManeuverType = /* @__PURE__ */ ((ManeuverType2) => { - ManeuverType2[ManeuverType2["Turn"] = 0] = "Turn"; - ManeuverType2[ManeuverType2["NewName"] = 1] = "NewName"; - ManeuverType2[ManeuverType2["Depart"] = 2] = "Depart"; - ManeuverType2[ManeuverType2["Arrive"] = 3] = "Arrive"; - ManeuverType2[ManeuverType2["Merge"] = 4] = "Merge"; - ManeuverType2[ManeuverType2["OnRamp"] = 5] = "OnRamp"; - ManeuverType2[ManeuverType2["OffRamp"] = 6] = "OffRamp"; - ManeuverType2[ManeuverType2["Fork"] = 7] = "Fork"; - ManeuverType2[ManeuverType2["EndOfRoad"] = 8] = "EndOfRoad"; - ManeuverType2[ManeuverType2["Continue"] = 9] = "Continue"; - ManeuverType2[ManeuverType2["Roundabout"] = 10] = "Roundabout"; - ManeuverType2[ManeuverType2["Rotary"] = 11] = "Rotary"; - ManeuverType2[ManeuverType2["RoundaboutTurn"] = 12] = "RoundaboutTurn"; - ManeuverType2[ManeuverType2["Notification"] = 13] = "Notification"; - ManeuverType2[ManeuverType2["ExitRoundabout"] = 14] = "ExitRoundabout"; - ManeuverType2[ManeuverType2["ExitRotary"] = 15] = "ExitRotary"; - return ManeuverType2; -})(ManeuverType || {}); - -// osrm/engine/api/fbresult/turn.ts -var Turn = /* @__PURE__ */ ((Turn2) => { - Turn2[Turn2["None"] = 0] = "None"; - Turn2[Turn2["UTurn"] = 1] = "UTurn"; - Turn2[Turn2["SharpRight"] = 2] = "SharpRight"; - Turn2[Turn2["Right"] = 3] = "Right"; - Turn2[Turn2["SlightRight"] = 4] = "SlightRight"; - Turn2[Turn2["Straight"] = 5] = "Straight"; - Turn2[Turn2["SlightLeft"] = 6] = "SlightLeft"; - Turn2[Turn2["Left"] = 7] = "Left"; - Turn2[Turn2["SharpLeft"] = 8] = "SharpLeft"; - return Turn2; -})(Turn || {}); - -// osrm/engine/api/fbresult/step-maneuver.ts -var StepManeuver = class _StepManeuver { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsStepManeuver(bb, obj) { - return (obj || new _StepManeuver()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsStepManeuver(bb, obj) { - bb.setPosition(bb.position() + flatbuffers6.SIZE_PREFIX_LENGTH); - return (obj || new _StepManeuver()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - location(obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? (obj || new Position()).__init(this.bb_pos + offset, this.bb) : null; - } - bearingBefore() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - bearingAfter() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - type() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readInt8(this.bb_pos + offset) : 0 /* Turn */; - } - modifier() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readInt8(this.bb_pos + offset) : 0 /* None */; - } - exit() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; - } - static startStepManeuver(builder) { - builder.startObject(6); - } - static addLocation(builder, locationOffset) { - builder.addFieldStruct(0, locationOffset, 0); - } - static addBearingBefore(builder, bearingBefore) { - builder.addFieldInt16(1, bearingBefore, 0); - } - static addBearingAfter(builder, bearingAfter) { - builder.addFieldInt16(2, bearingAfter, 0); - } - static addType(builder, type) { - builder.addFieldInt8(3, type, 0 /* Turn */); - } - static addModifier(builder, modifier) { - builder.addFieldInt8(4, modifier, 0 /* None */); - } - static addExit(builder, exit) { - builder.addFieldInt8(5, exit, 0); - } - static endStepManeuver(builder) { - const offset = builder.endObject(); - return offset; - } - static createStepManeuver(builder, locationOffset, bearingBefore, bearingAfter, type, modifier, exit) { - _StepManeuver.startStepManeuver(builder); - _StepManeuver.addLocation(builder, locationOffset); - _StepManeuver.addBearingBefore(builder, bearingBefore); - _StepManeuver.addBearingAfter(builder, bearingAfter); - _StepManeuver.addType(builder, type); - _StepManeuver.addModifier(builder, modifier); - _StepManeuver.addExit(builder, exit); - return _StepManeuver.endStepManeuver(builder); - } -}; - -// osrm/engine/api/fbresult/step.ts -var Step = class _Step { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsStep(bb, obj) { - return (obj || new _Step()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsStep(bb, obj) { - bb.setPosition(bb.position() + flatbuffers7.SIZE_PREFIX_LENGTH); - return (obj || new _Step()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - distance() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - duration() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - polyline(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - coordinates(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? (obj || new Position()).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null; - } - coordinatesLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - weight() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - ref(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - pronunciation(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - destinations(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - exits(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - mode(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - maneuver(obj) { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? (obj || new StepManeuver()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - intersections(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 28); - return offset ? (obj || new Intersection()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - intersectionsLength() { - const offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - rotaryName(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - rotaryPronunciation(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 32); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - drivingSide() { - const offset = this.bb.__offset(this.bb_pos, 34); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - static startStep(builder) { - builder.startObject(16); - } - static addDistance(builder, distance) { - builder.addFieldFloat32(0, distance, 0); - } - static addDuration(builder, duration) { - builder.addFieldFloat32(1, duration, 0); - } - static addPolyline(builder, polylineOffset) { - builder.addFieldOffset(2, polylineOffset, 0); - } - static addCoordinates(builder, coordinatesOffset) { - builder.addFieldOffset(3, coordinatesOffset, 0); - } - static startCoordinatesVector(builder, numElems) { - builder.startVector(8, numElems, 4); - } - static addWeight(builder, weight) { - builder.addFieldFloat32(4, weight, 0); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(5, nameOffset, 0); - } - static addRef(builder, refOffset) { - builder.addFieldOffset(6, refOffset, 0); - } - static addPronunciation(builder, pronunciationOffset) { - builder.addFieldOffset(7, pronunciationOffset, 0); - } - static addDestinations(builder, destinationsOffset) { - builder.addFieldOffset(8, destinationsOffset, 0); - } - static addExits(builder, exitsOffset) { - builder.addFieldOffset(9, exitsOffset, 0); - } - static addMode(builder, modeOffset) { - builder.addFieldOffset(10, modeOffset, 0); - } - static addManeuver(builder, maneuverOffset) { - builder.addFieldOffset(11, maneuverOffset, 0); - } - static addIntersections(builder, intersectionsOffset) { - builder.addFieldOffset(12, intersectionsOffset, 0); - } - static createIntersectionsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startIntersectionsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addRotaryName(builder, rotaryNameOffset) { - builder.addFieldOffset(13, rotaryNameOffset, 0); - } - static addRotaryPronunciation(builder, rotaryPronunciationOffset) { - builder.addFieldOffset(14, rotaryPronunciationOffset, 0); - } - static addDrivingSide(builder, drivingSide) { - builder.addFieldInt8(15, +drivingSide, 0); - } - static endStep(builder) { - const offset = builder.endObject(); - return offset; - } -}; - -// osrm/engine/api/fbresult/leg.ts -var Leg = class _Leg { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsLeg(bb, obj) { - return (obj || new _Leg()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsLeg(bb, obj) { - bb.setPosition(bb.position() + flatbuffers8.SIZE_PREFIX_LENGTH); - return (obj || new _Leg()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - distance() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0; - } - duration() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0; - } - weight() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0; - } - summary(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - annotations(obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? (obj || new Annotation()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - steps(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? (obj || new Step()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - stepsLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - polyline(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - coordinates(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? (obj || new Position()).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null; - } - coordinatesLength() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static startLeg(builder) { - builder.startObject(8); - } - static addDistance(builder, distance) { - builder.addFieldFloat64(0, distance, 0); - } - static addDuration(builder, duration) { - builder.addFieldFloat64(1, duration, 0); - } - static addWeight(builder, weight) { - builder.addFieldFloat64(2, weight, 0); - } - static addSummary(builder, summaryOffset) { - builder.addFieldOffset(3, summaryOffset, 0); - } - static addAnnotations(builder, annotationsOffset) { - builder.addFieldOffset(4, annotationsOffset, 0); - } - static addSteps(builder, stepsOffset) { - builder.addFieldOffset(5, stepsOffset, 0); - } - static createStepsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startStepsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addPolyline(builder, polylineOffset) { - builder.addFieldOffset(6, polylineOffset, 0); - } - static addCoordinates(builder, coordinatesOffset) { - builder.addFieldOffset(7, coordinatesOffset, 0); - } - static startCoordinatesVector(builder, numElems) { - builder.startVector(8, numElems, 4); - } - static endLeg(builder) { - const offset = builder.endObject(); - return offset; - } -}; - -// osrm/engine/api/fbresult/route-object.ts -var RouteObject = class _RouteObject { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsRouteObject(bb, obj) { - return (obj || new _RouteObject()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsRouteObject(bb, obj) { - bb.setPosition(bb.position() + flatbuffers9.SIZE_PREFIX_LENGTH); - return (obj || new _RouteObject()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - distance() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - duration() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - weight() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - weightName(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - confidence() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - polyline(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - coordinates(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? (obj || new Position()).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null; - } - coordinatesLength() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - legs(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? (obj || new Leg()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - legsLength() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static startRouteObject(builder) { - builder.startObject(8); - } - static addDistance(builder, distance) { - builder.addFieldFloat32(0, distance, 0); - } - static addDuration(builder, duration) { - builder.addFieldFloat32(1, duration, 0); - } - static addWeight(builder, weight) { - builder.addFieldFloat32(2, weight, 0); - } - static addWeightName(builder, weightNameOffset) { - builder.addFieldOffset(3, weightNameOffset, 0); - } - static addConfidence(builder, confidence) { - builder.addFieldFloat32(4, confidence, 0); - } - static addPolyline(builder, polylineOffset) { - builder.addFieldOffset(5, polylineOffset, 0); - } - static addCoordinates(builder, coordinatesOffset) { - builder.addFieldOffset(6, coordinatesOffset, 0); - } - static startCoordinatesVector(builder, numElems) { - builder.startVector(8, numElems, 4); - } - static addLegs(builder, legsOffset) { - builder.addFieldOffset(7, legsOffset, 0); - } - static createLegsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startLegsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endRouteObject(builder) { - const offset = builder.endObject(); - return offset; - } - static createRouteObject(builder, distance, duration, weight, weightNameOffset, confidence, polylineOffset, coordinatesOffset, legsOffset) { - _RouteObject.startRouteObject(builder); - _RouteObject.addDistance(builder, distance); - _RouteObject.addDuration(builder, duration); - _RouteObject.addWeight(builder, weight); - _RouteObject.addWeightName(builder, weightNameOffset); - _RouteObject.addConfidence(builder, confidence); - _RouteObject.addPolyline(builder, polylineOffset); - _RouteObject.addCoordinates(builder, coordinatesOffset); - _RouteObject.addLegs(builder, legsOffset); - return _RouteObject.endRouteObject(builder); - } -}; - -// osrm/engine/api/fbresult/table-result.ts -import * as flatbuffers11 from "flatbuffers"; - -// osrm/engine/api/fbresult/waypoint.ts -import * as flatbuffers10 from "flatbuffers"; - -// osrm/engine/api/fbresult/uint64-pair.ts -var Uint64Pair = class { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - first() { - return this.bb.readUint64(this.bb_pos); - } - second() { - return this.bb.readUint64(this.bb_pos + 8); - } - static sizeOf() { - return 16; - } - static createUint64Pair(builder, first, second) { - builder.prep(8, 16); - builder.writeInt64(BigInt(second ?? 0)); - builder.writeInt64(BigInt(first ?? 0)); - return builder.offset(); - } -}; - -// osrm/engine/api/fbresult/waypoint.ts -var Waypoint = class _Waypoint { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsWaypoint(bb, obj) { - return (obj || new _Waypoint()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsWaypoint(bb, obj) { - bb.setPosition(bb.position() + flatbuffers10.SIZE_PREFIX_LENGTH); - return (obj || new _Waypoint()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - hint(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - distance() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0; - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - location(obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? (obj || new Position()).__init(this.bb_pos + offset, this.bb) : null; - } - nodes(obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? (obj || new Uint64Pair()).__init(this.bb_pos + offset, this.bb) : null; - } - matchingsIndex() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - waypointIndex() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - alternativesCount() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - tripsIndex() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - static startWaypoint(builder) { - builder.startObject(9); - } - static addHint(builder, hintOffset) { - builder.addFieldOffset(0, hintOffset, 0); - } - static addDistance(builder, distance) { - builder.addFieldFloat32(1, distance, 0); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(2, nameOffset, 0); - } - static addLocation(builder, locationOffset) { - builder.addFieldStruct(3, locationOffset, 0); - } - static addNodes(builder, nodesOffset) { - builder.addFieldStruct(4, nodesOffset, 0); - } - static addMatchingsIndex(builder, matchingsIndex) { - builder.addFieldInt32(5, matchingsIndex, 0); - } - static addWaypointIndex(builder, waypointIndex) { - builder.addFieldInt32(6, waypointIndex, 0); - } - static addAlternativesCount(builder, alternativesCount) { - builder.addFieldInt32(7, alternativesCount, 0); - } - static addTripsIndex(builder, tripsIndex) { - builder.addFieldInt32(8, tripsIndex, 0); - } - static endWaypoint(builder) { - const offset = builder.endObject(); - return offset; - } -}; - -// osrm/engine/api/fbresult/table-result.ts -var TableResult = class _TableResult { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsTableResult(bb, obj) { - return (obj || new _TableResult()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsTableResult(bb, obj) { - bb.setPosition(bb.position() + flatbuffers11.SIZE_PREFIX_LENGTH); - return (obj || new _TableResult()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - durations(index) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - durationsLength() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - durationsArray() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Float32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - rows() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - cols() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - distances(index) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - distancesLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - distancesArray() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? new Float32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - destinations(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? (obj || new Waypoint()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - destinationsLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - fallbackSpeedCells(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; - } - fallbackSpeedCellsLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - fallbackSpeedCellsArray() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; - } - static startTableResult(builder) { - builder.startObject(6); - } - static addDurations(builder, durationsOffset) { - builder.addFieldOffset(0, durationsOffset, 0); - } - static createDurationsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addFloat32(data[i]); - } - return builder.endVector(); - } - static startDurationsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addRows(builder, rows) { - builder.addFieldInt16(1, rows, 0); - } - static addCols(builder, cols) { - builder.addFieldInt16(2, cols, 0); - } - static addDistances(builder, distancesOffset) { - builder.addFieldOffset(3, distancesOffset, 0); - } - static createDistancesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addFloat32(data[i]); - } - return builder.endVector(); - } - static startDistancesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDestinations(builder, destinationsOffset) { - builder.addFieldOffset(4, destinationsOffset, 0); - } - static createDestinationsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startDestinationsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addFallbackSpeedCells(builder, fallbackSpeedCellsOffset) { - builder.addFieldOffset(5, fallbackSpeedCellsOffset, 0); - } - static createFallbackSpeedCellsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); - } - static startFallbackSpeedCellsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endTableResult(builder) { - const offset = builder.endObject(); - return offset; - } - static createTableResult(builder, durationsOffset, rows, cols, distancesOffset, destinationsOffset, fallbackSpeedCellsOffset) { - _TableResult.startTableResult(builder); - _TableResult.addDurations(builder, durationsOffset); - _TableResult.addRows(builder, rows); - _TableResult.addCols(builder, cols); - _TableResult.addDistances(builder, distancesOffset); - _TableResult.addDestinations(builder, destinationsOffset); - _TableResult.addFallbackSpeedCells(builder, fallbackSpeedCellsOffset); - return _TableResult.endTableResult(builder); - } -}; - -// osrm/engine/api/fbresult/waypoint-group.ts -import * as flatbuffers12 from "flatbuffers"; -var WaypointGroup = class _WaypointGroup { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsWaypointGroup(bb, obj) { - return (obj || new _WaypointGroup()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsWaypointGroup(bb, obj) { - bb.setPosition(bb.position() + flatbuffers12.SIZE_PREFIX_LENGTH); - return (obj || new _WaypointGroup()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - matched() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - waypoints(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? (obj || new Waypoint()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - waypointsLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - error(obj) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? (obj || new Error2()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - static startWaypointGroup(builder) { - builder.startObject(3); - } - static addMatched(builder, matched) { - builder.addFieldInt8(0, +matched, 0); - } - static addWaypoints(builder, waypointsOffset) { - builder.addFieldOffset(1, waypointsOffset, 0); - } - static createWaypointsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startWaypointsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addError(builder, errorOffset) { - builder.addFieldOffset(2, errorOffset, 0); - } - static endWaypointGroup(builder) { - const offset = builder.endObject(); - return offset; - } -}; - -// osrm/engine/api/fbresult/fbresult.ts -var FBResult = class _FBResult { - bb = null; - bb_pos = 0; - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsFBResult(bb, obj) { - return (obj || new _FBResult()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsFBResult(bb, obj) { - bb.setPosition(bb.position() + flatbuffers13.SIZE_PREFIX_LENGTH); - return (obj || new _FBResult()).__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - error() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - code(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? (obj || new Error2()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - dataVersion(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; - } - waypoints(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? (obj || new Waypoint()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - waypointsLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - routes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? (obj || new RouteObject()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - routesLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - table(obj) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? (obj || new TableResult()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; - } - waypointsGrouped(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? (obj || new WaypointGroup()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; - } - waypointsGroupedLength() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static startFBResult(builder) { - builder.startObject(7); - } - static addError(builder, error) { - builder.addFieldInt8(0, +error, 0); - } - static addCode(builder, codeOffset) { - builder.addFieldOffset(1, codeOffset, 0); - } - static addDataVersion(builder, dataVersionOffset) { - builder.addFieldOffset(2, dataVersionOffset, 0); - } - static addWaypoints(builder, waypointsOffset) { - builder.addFieldOffset(3, waypointsOffset, 0); - } - static createWaypointsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startWaypointsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addRoutes(builder, routesOffset) { - builder.addFieldOffset(4, routesOffset, 0); - } - static createRoutesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startRoutesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addTable(builder, tableOffset) { - builder.addFieldOffset(5, tableOffset, 0); - } - static addWaypointsGrouped(builder, waypointsGroupedOffset) { - builder.addFieldOffset(6, waypointsGroupedOffset, 0); - } - static createWaypointsGroupedVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); - } - static startWaypointsGroupedVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endFBResult(builder) { - const offset = builder.endObject(); - return offset; - } - static finishFBResultBuffer(builder, offset) { - builder.finish(offset); - } - static finishSizePrefixedFBResultBuffer(builder, offset) { - builder.finish(offset, void 0, true); - } -}; - -// entry.ts -var osrm = { engine: { api: { fbresult: fbresult_exports } } }; -export { - osrm -}; diff --git a/package.json b/package.json index a72bed164dd..0b56b01aa87 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "clean": "rm -rf test/cache", "docs": "./scripts/build_api_docs.sh", "docs:dev": "vitepress dev docs", - "regenerate-fbresult": "./scripts/regenerate_fbresult_js.sh", + "regenerate-fbresult": "./scripts/regenerate_fbresult_js.sh --force", "install": "node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh", "nodejs-tests": "make -C test/data && ./lib/binding_napi_v8/osrm-datastore test/data/ch/monaco.osrm && node test/nodejs/index.js | tap-spec", "prepare": "husky" diff --git a/scripts/regenerate_fbresult_js.sh b/scripts/regenerate_fbresult_js.sh index f3390b53d63..48925bf0900 100755 --- a/scripts/regenerate_fbresult_js.sh +++ b/scripts/regenerate_fbresult_js.sh @@ -4,32 +4,81 @@ set -o errexit set -o pipefail set -o nounset -# Regenerates features/support/fbresult_generated.js from the flatbuffers schemas. +# Generates the flatbuffers JavaScript bundle the cucumber steps and node tests +# import, from include/engine/api/flatbuffers/*.fbs. # -# The C++ headers are generated at build time by CMake, so they never need this. -# The JavaScript bundle the cucumber steps import is committed to the repository, -# so it has to be rebuilt by hand whenever include/engine/api/flatbuffers/*.fbs -# changes. Forgetting leaves the steps decoding the old field layout. +# The output is gitignored and built on demand: features/support/fbresult.js +# runs this script before loading the bundle, so it cannot drift from the +# schemas the way a committed copy could. The C++ headers get the same +# treatment from flatbuffers_generate_headers in CMakeLists.txt. +# +# The output lives outside the directories cucumber.mjs imports, so cucumber +# never loads it before this script has had a chance to refresh it. +# +# The bundle records a hash of its inputs (the schemas and this script). When +# the hash still matches, the script exits without touching flatc, so calling +# it at the start of every test run costs almost nothing. +# +# Usage: regenerate_fbresult_js.sh [--force] +# FLATC path to flatc (default: the one vcpkg installed into the +# build directory, then flatc on PATH) +# OSRM_BUILD_DIR build directory to search for flatc first ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) cd "$ROOT" SCHEMA_DIR=include/engine/api/flatbuffers -OUTPUT=features/support/fbresult_generated.js +OUTPUT=features/generated/fbresult.js + +FORCE=0 +if [ "${1:-}" = "--force" ]; then + FORCE=1 +fi + +sha256() { + if command -v sha256sum > /dev/null 2>&1; then + sha256sum | cut -d' ' -f1 + else + shasum -a 256 | cut -d' ' -f1 + fi +} + +# Sorted so the hash does not depend on glob order. +INPUT_HASH=$( + for f in $(printf '%s\n' "$SCHEMA_DIR"/*.fbs | LC_ALL=C sort) scripts/regenerate_fbresult_js.sh; do + echo "$f" + cat "$f" + done | sha256 +) +HASH_LINE="// inputs-sha256: $INPUT_HASH" + +if [ "$FORCE" = 0 ] && [ -f "$OUTPUT" ] && grep -qxF "$HASH_LINE" "$OUTPUT"; then + exit 0 +fi # flatc ships with the vcpkg flatbuffers port, so any configured build has one. if [ -z "${FLATC:-}" ]; then - FLATC=$(find build* -path '*tools/flatbuffers/flatc' -type f 2>/dev/null | head -1) + for dir in "${OSRM_BUILD_DIR:-}" build*; do + [ -n "$dir" ] && [ -d "$dir" ] || continue + FLATC=$(find "$dir" -path '*tools/flatbuffers/flatc' -type f 2>/dev/null | head -1) + [ -n "$FLATC" ] && break + done fi if [ -z "${FLATC:-}" ] && command -v flatc > /dev/null 2>&1; then FLATC=flatc fi if [ -z "${FLATC:-}" ]; then - echo "No flatc found. Configure a build so vcpkg installs it, or set FLATC." >&2 + cat >&2 < "$OUTPUT" +} > "$TMP_OUTPUT" +mv -f "$TMP_OUTPUT" "$OUTPUT" echo "Wrote $OUTPUT" diff --git a/test/nodejs/constants.js b/test/nodejs/constants.js index 95d381addad..58a691bdd8c 100644 --- a/test/nodejs/constants.js +++ b/test/nodejs/constants.js @@ -1,6 +1,6 @@ import path from 'node:path'; import { pathToFileURL } from 'node:url'; -import { osrm } from '../../features/support/fbresult_generated.js'; +import { osrm } from '../../features/support/fbresult.js'; // Somewhere in Monaco // http://www.openstreetmap.org/#map=18/43.73185/7.41772 diff --git a/test/nodejs/constants.js.orig b/test/nodejs/constants.js.orig new file mode 100644 index 00000000000..95d381addad --- /dev/null +++ b/test/nodejs/constants.js.orig @@ -0,0 +1,29 @@ +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { osrm } from '../../features/support/fbresult_generated.js'; + +// Somewhere in Monaco +// http://www.openstreetmap.org/#map=18/43.73185/7.41772 +export const three_test_coordinates = [[7.41337, 43.72956], + [7.41546, 43.73077], + [7.41862, 43.73216]]; + +export const two_test_coordinates = three_test_coordinates.slice(0, 2); + +export const test_tile = {'at': [17059, 11948, 15], 'size': 159260}; + +const install_dir = process.env.OSRM_NODEJS_INSTALL_DIR || '.'; +const test_data_dir = process.env.OSRM_DATA_PATH || process.env.OSRM_TEST_DATA_DIR || 'test/data'; + +console.log(`# Setting installation path to: ${test_data_dir}`); +console.log(`# Setting custom data path to: ${test_data_dir}`); + +const data_path = path.resolve(path.join(test_data_dir, 'ch', 'monaco.osrm')); +const mld_data_path = path.resolve(path.join(test_data_dir, 'mld', 'monaco.osrm')); +const test_memory_path = path.resolve(path.join(test_data_dir, 'test_memory')); + +const { default: OSRM, version } = await import(pathToFileURL(path.join(install_dir, 'lib', 'index.js')).href); + +const FBResult = osrm.engine.api.fbresult.FBResult; + +export { OSRM, FBResult, version, data_path, mld_data_path, test_memory_path };