@azure-rest/agrifood-farming 1.0.0-alpha.20231207.1 → 1.0.0-alpha.20240115.1

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.
package/dist/index.js CHANGED
@@ -15,19 +15,24 @@ var coreLro = require('@azure/core-lro');
15
15
  * @param options type: ClientOptions, the parameter for all optional parameters
16
16
  */
17
17
  function createClient($host, credentials, options = {}) {
18
- var _a, _b;
19
- const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${$host}`;
20
- options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2022-11-01-preview";
21
- options = Object.assign(Object.assign({}, options), { credentials: {
18
+ const baseUrl = options.baseUrl ?? `${$host}`;
19
+ options.apiVersion = options.apiVersion ?? "2022-11-01-preview";
20
+ options = {
21
+ ...options,
22
+ credentials: {
22
23
  scopes: ["https://farmbeats.azure.net/.default"],
23
- } });
24
+ },
25
+ };
24
26
  const userAgentInfo = `azsdk-js-agrifood-farming-rest/1.0.0-beta.2`;
25
27
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
26
28
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
27
29
  : `${userAgentInfo}`;
28
- options = Object.assign(Object.assign({}, options), { userAgentOptions: {
30
+ options = {
31
+ ...options,
32
+ userAgentOptions: {
29
33
  userAgentPrefix,
30
- } });
34
+ },
35
+ };
31
36
  const client = coreClient.getClient(baseUrl, credentials, options);
32
37
  return client;
33
38
  }
@@ -238,7 +243,7 @@ const responseMap = {
238
243
  };
239
244
  function isUnexpected(response) {
240
245
  const lroOriginal = response.headers["x-ms-original-url"];
241
- const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
246
+ const url = new URL(lroOriginal ?? response.request.url);
242
247
  const method = response.request.method;
243
248
  let pathDetails = responseMap[`${method} ${url.pathname}`];
244
249
  if (!pathDetails) {
@@ -247,7 +252,6 @@ function isUnexpected(response) {
247
252
  return !pathDetails.includes(response.status);
248
253
  }
249
254
  function getParametrizedPathSuccess(method, path) {
250
- var _a, _b, _c, _d;
251
255
  const pathParts = path.split("/");
252
256
  // Traverse list to match the longest candidate
253
257
  // matchedLen: the length of candidate path
@@ -266,13 +270,13 @@ function getParametrizedPathSuccess(method, path) {
266
270
  // track if we have found a match to return the values found.
267
271
  let found = true;
268
272
  for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
269
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
270
- const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
273
+ if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
274
+ const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
271
275
  // If the current part of the candidate is a "template" part
272
276
  // Try to use the suffix of pattern to match the path
273
277
  // {guid} ==> $
274
278
  // {guid}:export ==> :export$
275
- const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
279
+ const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
276
280
  if (!isMatched) {
277
281
  found = false;
278
282
  break;
@@ -357,7 +361,7 @@ function getElements(body, itemName) {
357
361
  if (!Array.isArray(value)) {
358
362
  throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
359
363
  }
360
- return value !== null && value !== void 0 ? value : [];
364
+ return value ?? [];
361
365
  }
362
366
  /**
363
367
  * Checks if a request failed
@@ -379,7 +383,6 @@ function checkPagingRequest(response) {
379
383
  * @returns - A poller object to poll for operation state updates and eventually get the final response.
380
384
  */
381
385
  async function getLongRunningPoller(client, initialResponse, options = {}) {
382
- var _a;
383
386
  const poller = {
384
387
  requestMethod: initialResponse.request.method,
385
388
  requestPath: initialResponse.request.url,
@@ -394,13 +397,13 @@ async function getLongRunningPoller(client, initialResponse, options = {}) {
394
397
  // to get the latest status. We use the client provided and the polling path
395
398
  // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
396
399
  // depending on the lro pattern that the service implements. If non is provided we default to the initial path.
397
- const response = await client.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url).get();
400
+ const response = await client.pathUnchecked(path ?? initialResponse.request.url).get();
398
401
  const lroResponse = getLroResponse(response);
399
402
  lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
400
403
  return lroResponse;
401
404
  },
402
405
  };
403
- options.resolveOnUnsuccessful = (_a = options.resolveOnUnsuccessful) !== null && _a !== void 0 ? _a : true;
406
+ options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
404
407
  return coreLro.createHttpPoller(poller, options);
405
408
  }
406
409
  /**
@@ -414,7 +417,11 @@ function getLroResponse(response) {
414
417
  }
415
418
  return {
416
419
  flatResponse: response,
417
- rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body }),
420
+ rawResponse: {
421
+ ...response,
422
+ statusCode: Number.parseInt(response.status),
423
+ body: response.body,
424
+ },
418
425
  };
419
426
  }
420
427