Skip to content

Commit

Permalink
Merge pull request #30 from warerebel/refactoring-for-readability
Browse files Browse the repository at this point in the history
Refactoring for readability
  • Loading branch information
warerebel authored Jan 23, 2023
2 parents e5c612c + 7232da0 commit 6308799
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2023-01-23
### Changed
- Declared a typescript interface for decode results

## [1.1.0] - 2023-01-05
### Changed
- Removed unneeded items from npm package
Expand Down
35 changes: 27 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* istanbul ignore file */
import {decodeOpenLRReference, OpenLRDecodeOptions} from "./src/openLRDecode";
import {configureStorage} from "./src/storage";
import { decodeOpenLRReference, OpenLRDecodeOptions } from "./src/openLRDecode";
import { configureStorage } from "./src/storage";

export{OpenLRDecodeOptions} from "./src/openLRDecode";
export { OpenLRDecodeOptions } from "./src/openLRDecode";

export enum storageBackends {
mongodb = "mongodb"
Expand All @@ -17,12 +17,31 @@ export interface storageOptions {
authMechanism?: string;
}

export interface decodedRoute {
route: Array<{
length: number;
linkid: string;
}>;
routeLength: number;
nodes: string[];
openLRRef: string;
openLRDistance: number;
}

export interface decodeFail {
route: null;
routeLength: null;
nodes: null;
openLRRef: string;
openLRDistance: number;
}

/**
* @function initStorage - Initialise a connection to a backend storage
* @param storageOptions - The storage backend solution to use
* @returns {Promise} - A void Promise to wait for the initialisation to complete
* @returns {Promise} - A Promise to wait for the initialisation to complete - the content is dependent on the storage backend in use
*/
export async function initStorage(storageOptions: storageOptions): Promise<unknown>{
export async function initStorage(storageOptions: storageOptions): Promise<unknown> {
new configureStorage(storageOptions);
return configureStorage.init(storageOptions);
}
Expand All @@ -33,14 +52,14 @@ export async function initStorage(storageOptions: storageOptions): Promise<unkno
* @param options {object} - Options for the OpenLR decoding. The radius to search for candidate nodes in meters. The tolerance for matching link bearings in degrees.
* @returns {Promise} - Returns a promise with the decode result
*/
export async function decodeOpenLR(openLRRef: string, options: OpenLRDecodeOptions): Promise<{route: {length: number;linkid: string;}[]; routeLength: number; nodes: string[]; openLRRef: string; openLRDistance: number} | {route: null; routeLength: null;nodes: null; openLRRef: string; openLRDistance: number}>{
export async function decodeOpenLR(openLRRef: string, options: OpenLRDecodeOptions): Promise<decodedRoute | decodeFail> {
return decodeOpenLRReference(openLRRef, options);
}

/**
* @function closeConnection - Enables client to close connection to backend storage to exit node event loop
* @returns {Promise} - A void Promise to wait for the initialisation to complete
* @returns {Promise} - A Promise to wait for the disconnect to complete - the content is dependent on the storage backend in use
*/
export async function closeConnection(): Promise<unknown>{
export async function closeConnection(): Promise<unknown> {
return configureStorage.close();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openlr_decoder",
"version": "1.1.0",
"version": "1.2.0",
"description": "A general purpose road network OpenLR decoding solution",
"keywords": [
"openlr",
Expand Down

0 comments on commit 6308799

Please sign in to comment.