@azure/data-tables 13.0.0-alpha.20211109.5 → 13.0.1-alpha.20211206.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/README.md +39 -8
  3. package/dist/index.js +45 -17
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/TableClient.js +3 -8
  6. package/dist-esm/src/TableClient.js.map +1 -1
  7. package/dist-esm/src/TablePolicies.js.map +1 -1
  8. package/dist-esm/src/TableServiceClient.js +3 -8
  9. package/dist-esm/src/TableServiceClient.js.map +1 -1
  10. package/dist-esm/src/TableTransaction.js +3 -3
  11. package/dist-esm/src/TableTransaction.js.map +1 -1
  12. package/dist-esm/src/generated/generatedClientContext.js +1 -1
  13. package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
  14. package/dist-esm/src/index.js +1 -0
  15. package/dist-esm/src/index.js.map +1 -1
  16. package/dist-esm/src/logger.js.map +1 -1
  17. package/dist-esm/src/models.js.map +1 -1
  18. package/dist-esm/src/sas/accountSasSignatureValues.js.map +1 -1
  19. package/dist-esm/src/sas/generateAccountSas.js.map +1 -1
  20. package/dist-esm/src/sas/generateTableSas.js.map +1 -1
  21. package/dist-esm/src/sas/sasQueryParameters.js.map +1 -1
  22. package/dist-esm/src/sas/tableSasSignatureValues.js.map +1 -1
  23. package/dist-esm/src/serialization.js +1 -1
  24. package/dist-esm/src/serialization.js.map +1 -1
  25. package/dist-esm/src/tablesNamedCredentialPolicy.js.map +1 -1
  26. package/dist-esm/src/tablesSASTokenPolicy.js.map +1 -1
  27. package/dist-esm/src/utils/continuationToken.js +1 -1
  28. package/dist-esm/src/utils/continuationToken.js.map +1 -1
  29. package/dist-esm/src/utils/errorHelpers.js +36 -0
  30. package/dist-esm/src/utils/errorHelpers.js.map +1 -0
  31. package/dist-esm/src/utils/internalModels.js.map +1 -1
  32. package/dist-esm/src/utils/isCredential.js.map +1 -1
  33. package/package.json +1 -1
  34. package/types/3.1/data-tables.d.ts +3 -1
  35. package/types/latest/data-tables.d.ts +4 -1
  36. package/types/latest/tsdoc-metadata.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Release History
2
2
 
3
- ## 13.0.0 (2021-11-09)
3
+ ## 13.0.1 (Unreleased)
4
+
5
+ ### Features Added
6
+
7
+ ### Breaking Changes
8
+
9
+ ### Bugs Fixed
10
+
11
+ ### Other Changes
12
+
13
+ ## 13.0.0 (2021-11-11)
14
+
15
+ ### Acknowledgments
16
+
17
+ Thank you to our developer community members who helped to make the Azure Tables client library better with their contributions to this release:
18
+
19
+ - Daniel Hensby _([GitHub](https://github.com/dhensby))_
4
20
 
5
21
  ### Features Added
6
22
 
@@ -21,7 +37,7 @@
21
37
  - Issue #18521 - `upsertEntity` doesn't work with "" for partition or row keys. [#18586](https://github.com/Azure/azure-sdk-for-js/pull/18586)
22
38
 
23
39
  ### Other Changes
24
-
40
+ - Export RestError [#18635](https://github.com/Azure/azure-sdk-for-js/pull/18635). (A community contribution, courtesy of _[dhensby](https://github.com/dhensby))_
25
41
  ## 12.1.2 (2021-09-07)
26
42
 
27
43
  ### Bugs Fixed
package/README.md CHANGED
@@ -17,6 +17,7 @@ Azure Cosmos DB provides a Table API for applications that are written for Azure
17
17
  - The Azure Tables client library can seamlessly target either Azure table storage or Azure Cosmos DB table service endpoints with no code changes.
18
18
 
19
19
  Key links:
20
+
20
21
  - [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/)
21
22
  - [Package (NPM)](https://www.npmjs.com/package/@azure/data-tables)
22
23
  - [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/data-tables)
@@ -123,6 +124,7 @@ const { TableServiceClient, AzureNamedKeyCredential } = require("@azure/data-tab
123
124
  The `TableServiceClient` requires a URL to the table service and an access credential. It also optionally accepts some settings in the `options` parameter.
124
125
 
125
126
  #### `TableServiceClient` with TokenCredential (AAD)
127
+
126
128
  Azure Tables provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests
127
129
  to the Table service when targeting a Storage endpoint. With Azure AD, you can use role-based access control (RBAC) to
128
130
  grant access to your Azure Table resources to users, groups, or applications.
@@ -202,6 +204,7 @@ main();
202
204
  #### Create a new table
203
205
 
204
206
  You can create a table through a `TableServiceClient` instance calling the `createTable` function. This function takes the name of the table to create as a parameter.
207
+ Note that `createTable` won't throw an error when the table already exists.
205
208
 
206
209
  ```javascript
207
210
  const { TableServiceClient, AzureNamedKeyCredential } = require("@azure/data-tables");
@@ -216,13 +219,42 @@ const serviceClient = new TableServiceClient(
216
219
  );
217
220
 
218
221
  async function main() {
219
- const tableName = `newtable${new Date().getTime()}`;
222
+ const tableName = `newtable`;
223
+ // If the table 'newTable' already exists, createTable doesn' throw
220
224
  await serviceClient.createTable(tableName);
221
225
  }
222
226
 
223
227
  main();
224
228
  ```
225
229
 
230
+ Here is a sample that demonstrates how to test if the table already exists when attempting to create it:
231
+
232
+ ```javascript
233
+ const { TableServiceClient, AzureNamedKeyCredential } = require("@azure/data-tables");
234
+
235
+ const account = "<account>";
236
+ const accountKey = "<accountkey>";
237
+
238
+ const credential = new AzureNamedKeyCredential(account, accountKey);
239
+ const serviceClient = new TableServiceClient(
240
+ `https://${account}.table.core.windows.net`,
241
+ credential
242
+ );
243
+
244
+ async function main() {
245
+ const tableName = `newtable${new Date().getTime()}`;
246
+ await serviceClient.createTable(tableName, {
247
+ onResponse: (response) => {
248
+ if (response.status === 409) {
249
+ console.log(`Table ${tableName} already exists`);
250
+ }
251
+ }
252
+ });
253
+ }
254
+
255
+ main();
256
+ ```
257
+
226
258
  ### Create the table client
227
259
 
228
260
  The `TableClient` is created in a similar way as the `TableServiceClient` with the difference that `TableClient` takes a table name as a parameter
@@ -247,6 +279,7 @@ const client = new TableClient(`https://${account}.table.core.windows.net`, tabl
247
279
  ```
248
280
 
249
281
  #### `TableClient` with `TokenCredential` (Azure Active Directory)
282
+
250
283
  Azure Tables provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests
251
284
  to the Table service when targeting a Storage endpoint. With Azure AD, you can use role-based access control (RBAC) to
252
285
  grant access to your Azure Table resources to users, groups, or applications.
@@ -356,33 +389,31 @@ main();
356
389
  The Azure Tables Client SDK also works with Azurite, an Azure Storage and Tables API compatible server emulator. Please refer to the ([Azurite repository](https://github.com/Azure/Azurite#azurite-v3)) on how to get started using it.
357
390
 
358
391
  ### Connecting to Azurite with Connection String shortcut
392
+
359
393
  The easiest way to connect to Azurite from your application is to configure a connection string that references the shortcut `UseDevelopmentStorage=true`. The shortcut is equivalent to the full connection string for the emulator, which specifies the account name, the account key, and the emulator endpoints for each of the Azure Storage services: ([see more](https://github.com/Azure/Azurite#http-connection-strings)). Using this shortcut, the Azure Tables Client SDK would setup the default connection string and `allowInsecureConnection` in the client options.
360
394
 
361
395
  ```typescript
362
- import { TableClient } from "@azure/data-tables"
396
+ import { TableClient } from "@azure/data-tables";
363
397
 
364
398
  const connectionString = "UseDevelopmentStorage=true";
365
399
  const client = TableClient.fromConnectionString(connectionString, "myTable");
366
400
  ```
367
401
 
368
402
  ### Connecting to Azurite without Connection String shortcut
403
+
369
404
  You can connect to azurite manually without using the connection string shortcut by specifying the service URL and `AzureNamedKeyCredential` or a custom connection string. However, `allowInsecureConnection` will need to be set manually in case Azurite runs in an `http` endpoint.
370
405
 
371
406
  ```typescript
372
- import { TableClient, AzureNamedKeyCredential } from "@azure/data-tables"
407
+ import { TableClient, AzureNamedKeyCredential } from "@azure/data-tables";
373
408
 
374
409
  const client = new TableClient(
375
410
  "<Azurite-http-table-endpoint>",
376
411
  "myTable",
377
- new AzureNamedKeyCredential(
378
- "<Azurite-account-name>",
379
- "<Azurite-account-key>"
380
- ),
412
+ new AzureNamedKeyCredential("<Azurite-account-name>", "<Azurite-account-key>"),
381
413
  { allowInsecureConnection: true }
382
414
  );
383
415
  ```
384
416
 
385
-
386
417
  ## Troubleshooting
387
418
 
388
419
  ### General
package/dist/index.js CHANGED
@@ -3068,7 +3068,7 @@ class GeneratedClientContext extends coreClient.ServiceClient {
3068
3068
  const defaults = {
3069
3069
  requestContentType: "application/json; charset=utf-8"
3070
3070
  };
3071
- const packageDetails = `azsdk-js-data-tables/13.0.0`;
3071
+ const packageDetails = `azsdk-js-data-tables/13.0.1`;
3072
3072
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
3073
3073
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
3074
3074
  : `${packageDetails}`;
@@ -3382,6 +3382,40 @@ function signURLWithSAS(request, credential) {
3382
3382
  request.url = url.toString();
3383
3383
  }
3384
3384
 
3385
+ // Copyright (c) Microsoft Corporation.
3386
+ function handleTableAlreadyExists(error, options = {}) {
3387
+ var _a, _b, _c;
3388
+ const responseError = getErrorResponse(error);
3389
+ if (responseError &&
3390
+ responseError.status === 409 &&
3391
+ ((_a = responseError.parsedBody.odataError) === null || _a === void 0 ? void 0 : _a.code) === "TableAlreadyExists") {
3392
+ (_b = options.logger) === null || _b === void 0 ? void 0 : _b.info(`Table ${options.tableName} already Exists`);
3393
+ if (options.onResponse) {
3394
+ options.onResponse(responseError, {});
3395
+ }
3396
+ }
3397
+ else {
3398
+ options === null || options === void 0 ? void 0 : options.span.setStatus({ code: coreTracing.SpanStatusCode.ERROR, message: (_c = error) === null || _c === void 0 ? void 0 : _c.message });
3399
+ throw error;
3400
+ }
3401
+ }
3402
+ function getErrorResponse(error) {
3403
+ if (!isRestError(error)) {
3404
+ return undefined;
3405
+ }
3406
+ const errorResponse = error.response;
3407
+ if (!errorResponse || !isTableServiceErrorResponse(errorResponse.parsedBody)) {
3408
+ return undefined;
3409
+ }
3410
+ return errorResponse;
3411
+ }
3412
+ function isRestError(error) {
3413
+ return error.name === "RestError";
3414
+ }
3415
+ function isTableServiceErrorResponse(errorResponseBody) {
3416
+ return Boolean(errorResponseBody === null || errorResponseBody === void 0 ? void 0 : errorResponseBody.odataError);
3417
+ }
3418
+
3385
3419
  // Copyright (c) Microsoft Corporation.
3386
3420
  /**
3387
3421
  * A TableServiceClient represents a Client to the Azure Tables service allowing you
@@ -3479,16 +3513,10 @@ class TableServiceClient {
3479
3513
  async createTable(name, options = {}) {
3480
3514
  const { span, updatedOptions } = createSpan("TableServiceClient-createTable", options);
3481
3515
  try {
3482
- await this.table.create({ name }, Object.assign(Object.assign({}, updatedOptions), { responsePreference: "return-content" }));
3516
+ await this.table.create({ name }, Object.assign({}, updatedOptions));
3483
3517
  }
3484
3518
  catch (e) {
3485
- if (e.statusCode === 409) {
3486
- logger.info("TableServiceClient-createTable: Table Already Exists");
3487
- }
3488
- else {
3489
- span.setStatus({ code: coreTracing.SpanStatusCode.ERROR, message: e.message });
3490
- throw e;
3491
- }
3519
+ handleTableAlreadyExists(e, Object.assign(Object.assign({}, updatedOptions), { span, logger, tableName: name }));
3492
3520
  }
3493
3521
  finally {
3494
3522
  span.end();
@@ -4453,7 +4481,7 @@ class TableClient {
4453
4481
  * // calling create table will create the table used
4454
4482
  * // to instantiate the TableClient.
4455
4483
  * // Note: If the table already
4456
- * // exists this function doesn't fail.
4484
+ * // exists this function doesn't throw.
4457
4485
  * await client.createTable();
4458
4486
  * ```
4459
4487
  */
@@ -4464,13 +4492,7 @@ class TableClient {
4464
4492
  await this.table.create({ name: this.tableName }, updatedOptions);
4465
4493
  }
4466
4494
  catch (e) {
4467
- if (e.statusCode === 409) {
4468
- logger.info("TableClient-createTable: Table Already Exists");
4469
- }
4470
- else {
4471
- span.setStatus({ code: coreTracing.SpanStatusCode.ERROR, message: e.message });
4472
- throw e;
4473
- }
4495
+ handleTableAlreadyExists(e, Object.assign(Object.assign({}, updatedOptions), { span, logger, tableName: this.tableName }));
4474
4496
  }
4475
4497
  finally {
4476
4498
  span.end();
@@ -4989,6 +5011,12 @@ Object.defineProperty(exports, 'AzureSASCredential', {
4989
5011
  return coreAuth.AzureSASCredential;
4990
5012
  }
4991
5013
  });
5014
+ Object.defineProperty(exports, 'RestError', {
5015
+ enumerable: true,
5016
+ get: function () {
5017
+ return coreRestPipeline.RestError;
5018
+ }
5019
+ });
4992
5020
  exports.TableClient = TableClient;
4993
5021
  exports.TableServiceClient = TableServiceClient;
4994
5022
  exports.TableTransaction = TableTransaction;