@googlemaps/routing 2.2.1 → 3.0.0

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.
@@ -96,17 +96,26 @@ class RoutesClient {
96
96
  constructor(opts, gaxInstance) {
97
97
  // Ensure that options include all the required fields.
98
98
  const staticMembers = this.constructor;
99
- if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) {
99
+ if (opts?.universe_domain &&
100
+ opts?.universeDomain &&
101
+ opts?.universe_domain !== opts?.universeDomain) {
100
102
  throw new Error('Please set either universe_domain or universeDomain, but not both.');
101
103
  }
102
- const universeDomainEnvVar = (typeof process === 'object' && typeof process.env === 'object') ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] : undefined;
103
- this._universeDomain = opts?.universeDomain ?? opts?.universe_domain ?? universeDomainEnvVar ?? 'googleapis.com';
104
+ const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
105
+ ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
106
+ : undefined;
107
+ this._universeDomain =
108
+ opts?.universeDomain ??
109
+ opts?.universe_domain ??
110
+ universeDomainEnvVar ??
111
+ 'googleapis.com';
104
112
  this._servicePath = 'routes.' + this._universeDomain;
105
113
  const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath;
106
114
  this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint);
107
115
  const port = opts?.port || staticMembers.port;
108
116
  const clientConfig = opts?.clientConfig ?? {};
109
- const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function');
117
+ const fallback = opts?.fallback ??
118
+ (typeof window !== 'undefined' && typeof window?.fetch === 'function');
110
119
  opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
111
120
  // Request numeric enum values if REST transport is used.
112
121
  opts.numericEnums = true;
@@ -135,10 +144,7 @@ class RoutesClient {
135
144
  this.auth.defaultScopes = staticMembers.scopes;
136
145
  }
137
146
  // Determine the client header string.
138
- const clientHeader = [
139
- `gax/${this._gaxModule.version}`,
140
- `gapic/${version}`,
141
- ];
147
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
142
148
  if (typeof process === 'object' && 'versions' in process) {
143
149
  clientHeader.push(`gl-node/${process.versions.node}`);
144
150
  }
@@ -159,7 +165,7 @@ class RoutesClient {
159
165
  // Some of the methods on this service provide streaming responses.
160
166
  // Provide descriptors for these.
161
167
  this.descriptors.stream = {
162
- computeRouteMatrix: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
168
+ computeRouteMatrix: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
163
169
  };
164
170
  // Put together the default options sent with requests.
165
171
  this._defaults = this._gaxGrpc.constructSettings('google.maps.routing.v2.Routes', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
@@ -188,15 +194,15 @@ class RoutesClient {
188
194
  }
189
195
  // Put together the "service stub" for
190
196
  // google.maps.routing.v2.Routes.
191
- this.routesStub = this._gaxGrpc.createStub(this._opts.fallback ?
192
- this._protos.lookupService('google.maps.routing.v2.Routes') :
193
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
- this._protos.google.maps.routing.v2.Routes, this._opts, this._providedCustomServicePath);
197
+ this.routesStub = this._gaxGrpc.createStub(this._opts.fallback
198
+ ? this._protos.lookupService('google.maps.routing.v2.Routes')
199
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ this._protos.google.maps.routing.v2.Routes, this._opts, this._providedCustomServicePath);
195
201
  // Iterate over each of the methods that the service provides
196
202
  // and create an API call method for each.
197
203
  const routesStubMethods = ['computeRoutes', 'computeRouteMatrix'];
198
204
  for (const methodName of routesStubMethods) {
199
- const callPromise = this.routesStub.then(stub => (...args) => {
205
+ const callPromise = this.routesStub.then((stub) => (...args) => {
200
206
  if (this._terminated) {
201
207
  if (methodName in this.descriptors.stream) {
202
208
  const stream = new stream_1.PassThrough({ objectMode: true });
@@ -212,8 +218,7 @@ class RoutesClient {
212
218
  }, (err) => () => {
213
219
  throw err;
214
220
  });
215
- const descriptor = this.descriptors.stream[methodName] ||
216
- undefined;
221
+ const descriptor = this.descriptors.stream[methodName] || undefined;
217
222
  const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
218
223
  this.innerApiCalls[methodName] = apiCall;
219
224
  }
@@ -225,7 +230,8 @@ class RoutesClient {
225
230
  * @returns {string} The DNS address for this service.
226
231
  */
227
232
  static get servicePath() {
228
- if (typeof process === 'object' && typeof process.emitWarning === 'function') {
233
+ if (typeof process === 'object' &&
234
+ typeof process.emitWarning === 'function') {
229
235
  process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
230
236
  }
231
237
  return 'routes.googleapis.com';
@@ -236,7 +242,8 @@ class RoutesClient {
236
242
  * @returns {string} The DNS address for this service.
237
243
  */
238
244
  static get apiEndpoint() {
239
- if (typeof process === 'object' && typeof process.emitWarning === 'function') {
245
+ if (typeof process === 'object' &&
246
+ typeof process.emitWarning === 'function') {
240
247
  process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
241
248
  }
242
249
  return 'routes.googleapis.com';
@@ -290,7 +297,9 @@ class RoutesClient {
290
297
  options = options || {};
291
298
  options.otherArgs = options.otherArgs || {};
292
299
  options.otherArgs.headers = options.otherArgs.headers || {};
293
- this.initialize().catch(err => { throw err; });
300
+ this.initialize().catch((err) => {
301
+ throw err;
302
+ });
294
303
  this._log.info('computeRoutes request %j', request);
295
304
  const wrappedCallback = callback
296
305
  ? (error, response, options, rawResponse) => {
@@ -298,12 +307,16 @@ class RoutesClient {
298
307
  callback(error, response, options, rawResponse); // We verified callback above.
299
308
  }
300
309
  : undefined;
301
- return this.innerApiCalls.computeRoutes(request, options, wrappedCallback)
310
+ return this.innerApiCalls
311
+ .computeRoutes(request, options, wrappedCallback)
302
312
  ?.then(([response, options, rawResponse]) => {
303
313
  this._log.info('computeRoutes response %j', response);
304
314
  return [response, options, rawResponse];
305
- }).catch((error) => {
306
- if (error && 'statusDetails' in error && error.statusDetails instanceof Array) {
315
+ })
316
+ .catch((error) => {
317
+ if (error &&
318
+ 'statusDetails' in error &&
319
+ error.statusDetails instanceof Array) {
307
320
  const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
308
321
  error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
309
322
  }
@@ -434,7 +447,9 @@ class RoutesClient {
434
447
  options = options || {};
435
448
  options.otherArgs = options.otherArgs || {};
436
449
  options.otherArgs.headers = options.otherArgs.headers || {};
437
- this.initialize().catch(err => { throw err; });
450
+ this.initialize().catch((err) => {
451
+ throw err;
452
+ });
438
453
  this._log.info('computeRouteMatrix stream %j', options);
439
454
  return this.innerApiCalls.computeRouteMatrix(request, options);
440
455
  }
@@ -446,7 +461,7 @@ class RoutesClient {
446
461
  */
447
462
  close() {
448
463
  if (this.routesStub && !this._terminated) {
449
- return this.routesStub.then(stub => {
464
+ return this.routesStub.then((stub) => {
450
465
  this._log.info('ending gRPC channel');
451
466
  this._terminated = true;
452
467
  stub.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@googlemaps/routing",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "description": " client for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,39 +34,36 @@
34
34
  "compile": "tsc -p . && cp -r protos build/",
35
35
  "compile-protos": "compileProtos src",
36
36
  "docs": "jsdoc -c .jsdoc.js",
37
- "predocs-test": "npm run docs",
38
- "docs-test": "linkinator docs",
39
37
  "fix": "gts fix",
40
38
  "lint": "gts check",
41
39
  "prepare": "npm run compile",
42
40
  "prelint": "cd samples; npm link ../; npm i",
43
41
  "postpack": "minifyProtoJson",
44
42
  "samples-test": "cd samples/ && npm link ../ && npm i && npm test",
45
- "system-test": "c8 mocha build/system-test",
46
- "test": "c8 mocha build/test"
43
+ "system-test": "c8 mocha --config ../../.mocharc.cjs --no-parallel build/system-test",
44
+ "test": "c8 mocha --config ../../.mocharc.cjs build/test"
47
45
  },
48
46
  "dependencies": {
49
- "google-gax": "^5.0.0"
47
+ "google-gax": "^6.0.0"
50
48
  },
51
49
  "devDependencies": {
52
50
  "@types/mocha": "^10.0.10",
53
51
  "@types/node": "^22.13.9",
54
52
  "@types/sinon": "^17.0.4",
55
53
  "c8": "^10.1.3",
56
- "gapic-tools": "^1.0.0",
54
+ "gapic-tools": "^2.0.0",
57
55
  "gts": "^6.0.2",
58
56
  "jsdoc": "^4.0.4",
59
- "jsdoc-fresh": "^4.0.0",
60
- "jsdoc-region-tag": "^3.0.0",
61
- "linkinator": "^6.1.2",
57
+ "jsdoc-fresh": "^6.0.0",
58
+ "jsdoc-region-tag": "^5.0.0",
62
59
  "long": "^5.3.1",
63
60
  "mocha": "^11.1.0",
64
- "pack-n-play": "^3.0.0",
61
+ "pack-n-play": "^5.0.0",
65
62
  "sinon": "21.0.3",
66
63
  "typescript": "^5.8.2"
67
64
  },
68
65
  "engines": {
69
- "node": ">=18"
66
+ "node": ">=22"
70
67
  },
71
68
  "overrides": {
72
69
  "@sinonjs/fake-timers": "15.2.1"