@routr/location 2.0.5-alpha.3 → 2.0.5-alpha.6

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,14 @@
1
+ import { AddRouteRequest, FindRoutesRequest, ILocationService, RemoveRoutesRequest } from "./types";
2
+ import { Route } from "@routr/common";
3
+ export default class Location implements ILocationService {
4
+ location: any;
5
+ config: {
6
+ addr: string;
7
+ };
8
+ constructor(config: {
9
+ addr: string;
10
+ });
11
+ addRoute(request: AddRouteRequest): Promise<void>;
12
+ findRoutes(request: FindRoutesRequest): Promise<Route[]>;
13
+ removeRoutes(request: RemoveRoutesRequest): Promise<void>;
14
+ }
package/dist/client.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const common_1 = require("@routr/common");
13
+ const grpc = require("@grpc/grpc-js");
14
+ function container(self, request, name) {
15
+ return new Promise((resolve, reject) => {
16
+ self.location[name](request, (err, response) => {
17
+ if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
18
+ return reject(new common_1.ServiceUnavailableError(this.config.addr));
19
+ }
20
+ resolve(response);
21
+ });
22
+ });
23
+ }
24
+ class Location {
25
+ constructor(config) {
26
+ this.config = config;
27
+ this.location = new common_1.LOCATION_OBJECT_PROTO
28
+ .Location(config.addr, grpc.credentials.createInsecure());
29
+ }
30
+ addRoute(request) {
31
+ return container(this, request, this.addRoute.name);
32
+ }
33
+ findRoutes(request) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return container(this, request, this.findRoutes.name);
36
+ });
37
+ }
38
+ removeRoutes(request) {
39
+ return container(this, request, this.removeRoutes.name);
40
+ }
41
+ }
42
+ exports.default = Location;
@@ -0,0 +1,3 @@
1
+ import { Route } from "@routr/common";
2
+ import { MessageRequest } from "@routr/common";
3
+ export declare const createRoute: (request: MessageRequest) => Route;
package/dist/helper.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRoute = void 0;
4
+ const processor_1 = require("@routr/processor");
5
+ const processor_2 = require("@routr/processor");
6
+ // TODO: Before finalizing this, consider using the old approach of saving the rport
7
+ // and received values (like here:
8
+ // https://github.com/fonoster/routr/blob/59bc98af86078088aede7e658c0d82a19fa18fa4/mod/registrar/utils.js#L87)
9
+ //
10
+ // Also consider: https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L116
11
+ // and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
12
+ const createRoute = (request) => {
13
+ const uri = request.message.contact.address.uri;
14
+ return {
15
+ edgePortRef: request.edge_port_ref,
16
+ user: uri.user,
17
+ host: uri.host,
18
+ port: uri.port,
19
+ transport: uri.transport,
20
+ registeredOn: Date.now(),
21
+ sessionCount: processor_1.Extensions.getHeaderValue(request, "x-session-count") || -1,
22
+ expires: processor_2.Target.getTargetExpires(request)
23
+ };
24
+ };
25
+ exports.createRoute = createRoute;
@@ -0,0 +1,4 @@
1
+ import LocationClient from "./client";
2
+ export * as Helper from "./helper";
3
+ export * as Utils from "./utils";
4
+ export { LocationClient };
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.LocationClient = exports.Utils = exports.Helper = void 0;
26
+ /*
27
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
28
+ * http://github.com/fonoster/routr
29
+ *
30
+ * This file is part of Routr
31
+ *
32
+ * Licensed under the MIT License (the "License")
33
+ * you may not use this file except in compliance with
34
+ * the License. You may obtain a copy of the License at
35
+ *
36
+ * https://opensource.org/licenses/MIT
37
+ *
38
+ * Unless required by applicable law or agreed to in writing, software
39
+ * distributed under the License is distributed on an "AS IS" BASIS,
40
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
+ * See the License for the specific language governing permissions and
42
+ * limitations under the License.
43
+ */
44
+ const client_1 = __importDefault(require("./client"));
45
+ exports.LocationClient = client_1.default;
46
+ exports.Helper = __importStar(require("./helper"));
47
+ exports.Utils = __importStar(require("./utils"));
@@ -1,5 +1,6 @@
1
- import { AddRouteRequest, Backend, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRouteRequest, Route } from "./types";
2
- export default class Locator implements ILocationService {
1
+ import { AddRouteRequest, Backend, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
2
+ import { Route } from "@routr/common";
3
+ export default class Location implements ILocationService {
3
4
  private store;
4
5
  private backends;
5
6
  private rrCount;
@@ -7,7 +8,7 @@ export default class Locator implements ILocationService {
7
8
  constructor(store: ILocatorStore, backends?: Map<string, Backend>);
8
9
  addRoute(request: AddRouteRequest): Promise<void>;
9
10
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
10
- removeRoutes(request: RemoveRouteRequest): Promise<void>;
11
+ removeRoutes(request: RemoveRoutesRequest): Promise<void>;
11
12
  private next;
12
13
  private nextWithAffinity;
13
14
  }
@@ -30,7 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  const errors_1 = require("./errors");
31
31
  const types_1 = require("./types");
32
32
  const utils_1 = require("./utils");
33
- class Locator {
33
+ class Location {
34
34
  // Should fail if any backend has sessionAffinity and round-robin
35
35
  constructor(store, backends = new Map()) {
36
36
  this.store = store;
@@ -98,4 +98,4 @@ class Locator {
98
98
  return route;
99
99
  }
100
100
  }
101
- exports.default = Locator;
101
+ exports.default = Location;
@@ -1,4 +1,5 @@
1
- import { ILocatorStore, Route } from "./types";
1
+ import { Route } from "@routr/common";
2
+ import { ILocatorStore } from "./types";
2
3
  export default class MemoryStore implements ILocatorStore {
3
4
  private collections;
4
5
  private cleanupCount;
@@ -1,4 +1,5 @@
1
- import { ILocatorStore, RedisStoreConfig, Route } from "./types";
1
+ import { Route } from "@routr/common";
2
+ import { ILocatorStore, RedisStoreConfig } from "./types";
2
3
  export default class RedisStore implements ILocatorStore {
3
4
  client: any;
4
5
  constructor(config?: RedisStoreConfig);
package/dist/service.js CHANGED
@@ -24,7 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  const types_1 = require("./types");
25
25
  const common_1 = require("@routr/common");
26
26
  const utils_1 = require("./utils");
27
- const locator_1 = __importDefault(require("./locator"));
27
+ const location_1 = __importDefault(require("./location"));
28
28
  const memory_store_1 = __importDefault(require("./memory_store"));
29
29
  const redis_store_1 = __importDefault(require("./redis_store"));
30
30
  const logger_1 = __importDefault(require("@fonoster/logger"));
@@ -40,7 +40,7 @@ function LocationService(config) {
40
40
  }
41
41
  const backends = new Map();
42
42
  config.backends.forEach(b => backends.set(`backend:${b.ref}`, b));
43
- common_1.createService(utils_1.getServiceInfo(bindAddr, new locator_1.default(store, backends)));
43
+ common_1.createService(utils_1.getServiceInfo(bindAddr, new location_1.default(store, backends)));
44
44
  logger_1.default.info(`using ${cache.provider} as cache provider`);
45
45
  }
46
46
  exports.default = LocationService;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Route } from "@routr/common";
1
2
  export declare enum LB_ALGORITHM {
2
3
  ROUND_ROBIN = "round-robin",
3
4
  LEAST_SESSIONS = "least-sessions"
@@ -9,24 +10,13 @@ export declare enum CACHE_PROVIDER {
9
10
  export interface ILocationService {
10
11
  addRoute(request: AddRouteRequest): Promise<void>;
11
12
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
12
- removeRoutes(request: RemoveRouteRequest): Promise<void>;
13
+ removeRoutes(request: RemoveRoutesRequest): Promise<void>;
13
14
  }
14
15
  export interface ILocatorStore {
15
16
  put(key: string, route: Route): Promise<void>;
16
17
  get(key: string): Promise<Route[]>;
17
18
  delete(key: string): Promise<void>;
18
19
  }
19
- export interface Route {
20
- user: string;
21
- host: string;
22
- port: number;
23
- transport: string;
24
- registeredOn: number;
25
- sessionCount?: number;
26
- expires: number;
27
- edgePortRef: string;
28
- labels?: Map<string, string>;
29
- }
30
20
  export interface AddRouteRequest {
31
21
  aor: string;
32
22
  route: Route;
@@ -39,7 +29,7 @@ export interface FindRoutesRequest {
39
29
  export interface FindRoutesResponse {
40
30
  routes: Array<Route>;
41
31
  }
42
- export interface RemoveRouteRequest {
32
+ export interface RemoveRoutesRequest {
43
33
  aor: string;
44
34
  }
45
35
  export interface Backend {
package/dist/types.js CHANGED
@@ -1,24 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CACHE_PROVIDER = exports.LB_ALGORITHM = void 0;
4
- /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/routr
7
- *
8
- * This file is part of Routr
9
- *
10
- * Licensed under the MIT License (the "License")
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
4
  var LB_ALGORITHM;
23
5
  (function (LB_ALGORITHM) {
24
6
  LB_ALGORITHM["ROUND_ROBIN"] = "round-robin";
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Backend, ILocationService, RedisStoreConfig, Route } from "./types";
1
+ import { Route } from "@routr/common";
2
2
  import { ServiceInfo } from "@routr/common";
3
+ import { Backend, ILocationService, RedisStoreConfig } from "./types";
3
4
  export declare const expiredFilter: (r: Route) => boolean;
4
5
  export declare const duplicateFilter: (r1: Route, r2: Route) => boolean;
5
6
  export declare const mergeKeyValue: (map: Map<string, string>) => string[];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.0.5-alpha.3",
3
+ "version": "2.0.5-alpha.6",
4
4
  "description": "Creates and maintains a list of routes to all registered endpoints",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
7
7
  "license": "MIT",
8
- "main": "dist/location",
9
- "types": "dist/location",
8
+ "main": "dist/index",
9
+ "types": "dist/index",
10
10
  "scripts": {
11
11
  "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
12
12
  "build": "tsc -b tsconfig.json"
@@ -25,7 +25,8 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@routr/common": "^2.0.5-alpha.3",
28
+ "@grpc/grpc-js": "^1.5.9",
29
+ "@routr/processor": "^2.0.5-alpha.6",
29
30
  "ajv": "^6.12.6",
30
31
  "fp-ts": "^2.11.8",
31
32
  "redis": "^4.0.4"
@@ -37,5 +38,5 @@
37
38
  "bugs": {
38
39
  "url": "https://github.com/fonoster/routr/issues"
39
40
  },
40
- "gitHead": "7d942466133a03f4bcfe0dc100f1a922b3ed14ad"
41
+ "gitHead": "ac4963e735fbc4ad3045379463796137e650509c"
41
42
  }