Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Unreleased
- Changes from 6.0.0
- Misc:
- ADDED: Add husky pre-commit hook for compiling and linting staged JS files [#7228](https://github.com/Project-OSRM/osrm-backend/issues/7228)
- CHANGED: Standardize linting configuration with ESM-specific rules [#7229](https://github.com/Project-OSRM/osrm-backend/issues/7229)
- CHANGED: Convert scripts from CommonJS to modern ESM format [#7230](https://github.com/Project-OSRM/osrm-backend/pull/7230)
- CHANGED: Convert remaining scripts from CommonJS to ESM format and use flatbuffers npm package [#7227](https://github.com/Project-OSRM/osrm-backend/pull/7227)
- CHANGED: Upgrade Cucumber-js to v12 [#7221](https://github.com/Project-OSRM/osrm-backend/pull/7221)
Expand Down
23 changes: 16 additions & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import { Linter } from 'eslint';
/** @type {Linter.Config} */
const config = [
{
files: ["**/*.js"],
languageOptions: {
ecmaVersion: 2024,
sourceType: "module",
globals: {
es6: true,
node: true,
},
},
rules: {
indent: ['error', 2],
quotes: ['warn', 'single'],
'linebreak-style': ['error', 'unix'],
semi: ['error', 'always'],
'no-console': ['warn'],
'prefer-const': 'error',
'no-var': 'error',
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'object-shorthand': 'error',
'prefer-template': 'error',
'prefer-arrow-callback': 'error',
},
languageOptions: {
globals: {
es6: true,
node: true,
},
},
ignores: ['node_modules/', 'build/', 'dist/', 'coverage/'],
ignores: ['node_modules/', 'build/', 'dist/', 'coverage/', 'features/support/fbresult_generated.js'],
},
];

Expand Down
6 changes: 3 additions & 3 deletions features/lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import d3 from 'd3-queue';

// Computes MD5 hash of multiple files concatenated together
const hashOfFiles = (paths, cb) => {
let queue = d3.queue();
const queue = d3.queue();
for (let i = 0; i < paths.length; ++i) {
queue.defer(fs.readFile, paths[i]);
}
queue.awaitAll((err, results) => {
if (err) return cb(err);
let checksum = crypto.createHash('md5');
const checksum = crypto.createHash('md5');
for (let i = 0; i < results.length; ++i) {
checksum.update(results[i]);
}
Expand All @@ -23,7 +23,7 @@ const hashOfFiles = (paths, cb) => {
const hashOfFile = (path, additional_content, cb) => {
fs.readFile(path, (err, result) => {
if (err) return cb(err);
let checksum = crypto.createHash('md5');
const checksum = crypto.createHash('md5');
checksum.update(result + (additional_content || ''));
cb(null, checksum.digest('hex'));
});
Expand Down
295 changes: 143 additions & 152 deletions features/lib/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,167 +4,158 @@ import { ensureDecimal } from './utils.js';

// OpenStreetMap database for storing nodes, ways, and relations
class DB {
constructor () {
this.nodes = new Array();
this.ways = new Array();
this.relations = new Array();
}

// Adds OSM node to database
addNode (node) {
this.nodes.push(node);
}

// Adds OSM way to database
addWay (way) {
this.ways.push(way);
}

addRelation (relation) {
this.relations.push(relation);
}

clear () {
this.nodes = [];
this.ways = [];
this.relations = [];
}

// Converts database to OSM XML format for OSRM processing
toXML (callback) {
const xml = builder.create('osm', {'encoding':'UTF-8'});
xml.att('generator', 'osrm-test')
.att('version', '0.6');

this.nodes.forEach((n) => {
const node = xml.ele('node', {
id: n.id,
version: 1,
uid: n.OSM_UID,
user: n.OSM_USER,
timestamp: n.OSM_TIMESTAMP,
lon: ensureDecimal(n.lon),
lat: ensureDecimal(n.lat)
});

for (const k in n.tags) {
node.ele('tag')
.att('k', k)
.att('v', n.tags[k]);
}
});

this.ways.forEach((w) => {
const way = xml.ele('way', {
id: w.id,
version: 1,
uid: w.OSM_UID,
user: w.OSM_USER,
timestamp: w.OSM_TIMESTAMP
});

w.nodes.forEach((k) => {

let nd = way.ele('nd')
.att('ref', k.id);
if (w.add_locations) {
nd.att('lon', k.lon);
nd.att('lat', k.lat);
}
});

for (const k in w.tags) {
way.ele('tag')
.att('k', k)
.att('v', w.tags[k]);
}
});

this.relations.forEach((r) => {
const relation = xml.ele('relation', {
id: r.id,
user: r.OSM_USER,
timestamp: r.OSM_TIMESTAMP,
uid: r.OSM_UID
});

r.members.forEach((m) => {
const d = {
type: m.type,
ref: m.id
};
if (m.role) d.role = m.role;
relation.ele('member', d);
});

for (const k in r.tags) {
relation.ele('tag')
.att('k', k)
.att('v', r.tags[k]);
}
});

callback(xml.end({ pretty: true, indent: ' ' }));
}
constructor() {
this.nodes = new Array();
this.ways = new Array();
this.relations = new Array();
}

// Adds OSM node to database
addNode(node) {
this.nodes.push(node);
}

// Adds OSM way to database
addWay(way) {
this.ways.push(way);
}

addRelation(relation) {
this.relations.push(relation);
}

clear() {
this.nodes = [];
this.ways = [];
this.relations = [];
}

// Converts database to OSM XML format for OSRM processing
toXML(callback) {
const xml = builder.create('osm', { encoding: 'UTF-8' });
xml.att('generator', 'osrm-test').att('version', '0.6');

this.nodes.forEach((n) => {
const node = xml.ele('node', {
id: n.id,
version: 1,
uid: n.OSM_UID,
user: n.OSM_USER,
timestamp: n.OSM_TIMESTAMP,
lon: ensureDecimal(n.lon),
lat: ensureDecimal(n.lat),
});

for (const k in n.tags) {
node.ele('tag').att('k', k).att('v', n.tags[k]);
}
});

this.ways.forEach((w) => {
const way = xml.ele('way', {
id: w.id,
version: 1,
uid: w.OSM_UID,
user: w.OSM_USER,
timestamp: w.OSM_TIMESTAMP,
});

w.nodes.forEach((k) => {
const nd = way.ele('nd').att('ref', k.id);
if (w.add_locations) {
nd.att('lon', k.lon);
nd.att('lat', k.lat);
}
});

for (const k in w.tags) {
way.ele('tag').att('k', k).att('v', w.tags[k]);
}
});

this.relations.forEach((r) => {
const relation = xml.ele('relation', {
id: r.id,
user: r.OSM_USER,
timestamp: r.OSM_TIMESTAMP,
uid: r.OSM_UID,
});

r.members.forEach((m) => {
const d = {
type: m.type,
ref: m.id,
};
if (m.role) d.role = m.role;
relation.ele('member', d);
});

for (const k in r.tags) {
relation.ele('tag').att('k', k).att('v', r.tags[k]);
}
});

callback(xml.end({ pretty: true, indent: ' ' }));
}
}

class Node {
constructor (id, OSM_USER, OSM_TIMESTAMP, OSM_UID, lon, lat, tags) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.lon = lon;
this.lat = lat;
this.tags = tags;
}

addTag (k, v) {
this.tags[k] = v;
}

setID (id ) {
this.id = id;
}
constructor(id, OSM_USER, OSM_TIMESTAMP, OSM_UID, lon, lat, tags) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.lon = lon;
this.lat = lat;
this.tags = tags;
}

addTag(k, v) {
this.tags[k] = v;
}

setID(id) {
this.id = id;
}
}

class Way {
constructor (id, OSM_USER, OSM_TIMESTAMP, OSM_UID, add_locations) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.tags = {};
this.nodes = [];
this.add_locations = add_locations;
}

addNode (node) {
this.nodes.push(node);
}

setTags (tags) {
this.tags = tags;
}
constructor(id, OSM_USER, OSM_TIMESTAMP, OSM_UID, add_locations) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.tags = {};
this.nodes = [];
this.add_locations = add_locations;
}

addNode(node) {
this.nodes.push(node);
}

setTags(tags) {
this.tags = tags;
}
}

class Relation {
constructor (id, OSM_USER, OSM_TIMESTAMP, OSM_UID) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.members = [];
this.tags = {};
}

addMember (memberType, id, role) {
this.members.push({type: memberType, id: id, role: role});
}

addTag (k, v) {
this.tags[k] = v;
}
constructor(id, OSM_USER, OSM_TIMESTAMP, OSM_UID) {
this.id = id;
this.OSM_USER = OSM_USER;
this.OSM_TIMESTAMP = OSM_TIMESTAMP;
this.OSM_UID = OSM_UID;
this.members = [];
this.tags = {};
}

addMember(memberType, id, role) {
this.members.push({ type: memberType, id, role });
}

addTag(k, v) {
this.tags[k] = v;
}
}

export { DB, Node, Way, Relation };
Loading
Loading