@azure/data-tables 13.0.2-alpha.20220125.1 → 13.1.0-alpha.20220216.2

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.
@@ -6,14 +6,13 @@ import { isNamedKeyCredential, isSASCredential, isTokenCredential, } from "@azur
6
6
  import { STORAGE_SCOPE, TablesLoggingAllowedHeaderNames } from "./utils/constants";
7
7
  import { parseXML, stringifyXML } from "@azure/core-xml";
8
8
  import { GeneratedClient } from "./generated/generatedClient";
9
- import { SpanStatusCode } from "@azure/core-tracing";
10
- import { createSpan } from "./utils/tracing";
11
9
  import { getClientParamsFromConnectionString } from "./utils/connectionString";
12
10
  import { handleTableAlreadyExists } from "./utils/errorHelpers";
13
11
  import { isCredential } from "./utils/isCredential";
14
12
  import { logger } from "./logger";
15
13
  import { tablesNamedKeyCredentialPolicy } from "./tablesNamedCredentialPolicy";
16
14
  import { tablesSASTokenPolicy } from "./tablesSASTokenPolicy";
15
+ import { tracingClient } from "./utils/tracing";
17
16
  /**
18
17
  * A TableServiceClient represents a Client to the Azure Tables service allowing you
19
18
  * to perform operations on the tables and the entities.
@@ -52,36 +51,16 @@ export class TableServiceClient {
52
51
  * secondary location endpoint when read-access geo-redundant replication is enabled for the account.
53
52
  * @param options - The options parameters.
54
53
  */
55
- async getStatistics(options = {}) {
56
- const { span, updatedOptions } = createSpan("TableServiceClient-getStatistics", options);
57
- try {
58
- return await this.service.getStatistics(updatedOptions);
59
- }
60
- catch (e) {
61
- span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
62
- throw e;
63
- }
64
- finally {
65
- span.end();
66
- }
54
+ getStatistics(options = {}) {
55
+ return tracingClient.withSpan("TableServiceClient.getStatistics", options, (updatedOptions) => this.service.getStatistics(updatedOptions));
67
56
  }
68
57
  /**
69
58
  * Gets the properties of an account's Table service, including properties for Analytics and CORS
70
59
  * (Cross-Origin Resource Sharing) rules.
71
60
  * @param options - The options parameters.
72
61
  */
73
- async getProperties(options = {}) {
74
- const { span, updatedOptions } = createSpan("TableServiceClient-getProperties", options);
75
- try {
76
- return await this.service.getProperties(updatedOptions);
77
- }
78
- catch (e) {
79
- span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
80
- throw e;
81
- }
82
- finally {
83
- span.end();
84
- }
62
+ getProperties(options = {}) {
63
+ return tracingClient.withSpan("TableServiceClient.getProperties", options, (updatedOptions) => this.service.getProperties(updatedOptions));
85
64
  }
86
65
  /**
87
66
  * Sets properties for an account's Table service endpoint, including properties for Analytics and CORS
@@ -89,58 +68,43 @@ export class TableServiceClient {
89
68
  * @param properties - The Table Service properties.
90
69
  * @param options - The options parameters.
91
70
  */
92
- async setProperties(properties, options = {}) {
93
- const { span, updatedOptions } = createSpan("TableServiceClient-setProperties", options);
94
- try {
95
- return await this.service.setProperties(properties, updatedOptions);
96
- }
97
- catch (e) {
98
- span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
99
- throw e;
100
- }
101
- finally {
102
- span.end();
103
- }
71
+ setProperties(properties, options = {}) {
72
+ return tracingClient.withSpan("TableServiceClient.setProperties", options, (updatedOptions) => this.service.setProperties(properties, updatedOptions));
104
73
  }
105
74
  /**
106
75
  * Creates a new table under the given account.
107
76
  * @param name - The name of the table.
108
77
  * @param options - The options parameters.
109
78
  */
110
- async createTable(name, options = {}) {
111
- const { span, updatedOptions } = createSpan("TableServiceClient-createTable", options);
112
- try {
113
- await this.table.create({ name }, Object.assign({}, updatedOptions));
114
- }
115
- catch (e) {
116
- handleTableAlreadyExists(e, Object.assign(Object.assign({}, updatedOptions), { span, logger, tableName: name }));
117
- }
118
- finally {
119
- span.end();
120
- }
79
+ createTable(name, options = {}) {
80
+ return tracingClient.withSpan("TableServiceClient.createTable", options, async (updatedOptions) => {
81
+ try {
82
+ await this.table.create({ name }, updatedOptions);
83
+ }
84
+ catch (e) {
85
+ handleTableAlreadyExists(e, Object.assign(Object.assign({}, updatedOptions), { logger, tableName: name }));
86
+ }
87
+ });
121
88
  }
122
89
  /**
123
90
  * Operation permanently deletes the specified table.
124
91
  * @param name - The name of the table.
125
92
  * @param options - The options parameters.
126
93
  */
127
- async deleteTable(name, options = {}) {
128
- const { span, updatedOptions } = createSpan("TableServiceClient-deleteTable", options);
129
- try {
130
- await this.table.delete(name, updatedOptions);
131
- }
132
- catch (e) {
133
- if (e.statusCode === 404) {
134
- logger.info("TableServiceClient-deleteTable: Table doesn't exist");
94
+ deleteTable(name, options = {}) {
95
+ return tracingClient.withSpan("TableServiceClient.deleteTable", options, async (updatedOptions) => {
96
+ try {
97
+ await this.table.delete(name, updatedOptions);
135
98
  }
136
- else {
137
- span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
138
- throw e;
99
+ catch (e) {
100
+ if (e.statusCode === 404) {
101
+ logger.info("TableServiceClient-deleteTable: Table doesn't exist");
102
+ }
103
+ else {
104
+ throw e;
105
+ }
139
106
  }
140
- }
141
- finally {
142
- span.end();
143
- }
107
+ });
144
108
  }
145
109
  /**
146
110
  * Queries tables under the given account.
@@ -192,22 +156,15 @@ export class TableServiceClient {
192
156
  }
193
157
  listTablesPage(options = {}) {
194
158
  return __asyncGenerator(this, arguments, function* listTablesPage_1() {
195
- const { span, updatedOptions } = createSpan("TableServiceClient-listTablesPage", options);
196
- try {
197
- let result = yield __await(this._listTables(updatedOptions));
159
+ let result = yield __await(tracingClient.withSpan("TableServiceClient.listTablesPage", options, (updatedOptions) => this._listTables(updatedOptions)));
160
+ yield yield __await(result);
161
+ while (result.continuationToken) {
162
+ const optionsWithContinuation = Object.assign(Object.assign({}, options), { continuationToken: result.continuationToken });
163
+ result = yield __await(tracingClient.withSpan("TableServiceClient.listTablesPage", optionsWithContinuation, async (updatedOptions, span) => {
164
+ span.setAttribute("continuationToken", updatedOptions.continuationToken);
165
+ return this._listTables(updatedOptions);
166
+ }));
198
167
  yield yield __await(result);
199
- while (result.continuationToken) {
200
- const optionsWithContinuation = Object.assign(Object.assign({}, updatedOptions), { continuationToken: result.continuationToken });
201
- result = yield __await(this._listTables(optionsWithContinuation));
202
- yield yield __await(result);
203
- }
204
- }
205
- catch (e) {
206
- span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
207
- throw e;
208
- }
209
- finally {
210
- span.end();
211
168
  }
212
169
  });
213
170
  }
@@ -1 +1 @@
1
- {"version":3,"file":"TableServiceClient.js","sourceRoot":"","sources":["../../src/TableServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,oBAAoB,CAAC;AAe5B,OAAO,EAIL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAgG7B,YACE,GAAW,EACX,mBAI6B,EAC7B,OAAmC;QAEnC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,MAAM,UAAU,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;Q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EnE,IAAI,UAAU,EAAE;YACd,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;SAC/D;aAAM;YACL,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;SACnD;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport \"@azure/core-paging\";\nimport {\n GetPropertiesResponse,\n GetStatisticsResponse,\n ServiceProperties,\n SetPropertiesOptions,\n SetPropertiesResponse,\n} from \"./generatedModels\";\nimport { InternalClientPipelineOptions, OperationOptions } from \"@azure/core-client\";\nimport {\n ListTableItemsOptions,\n TableItem,\n TableQueryOptions,\n TableServiceClientOptions,\n} from \"./models\";\nimport {\n NamedKeyCredential,\n SASCredential,\n TokenCredential,\n isNamedKeyCredential,\n isSASCredential,\n isTokenCredential,\n} from \"@azure/core-auth\";\nimport { STORAGE_SCOPE, TablesLoggingAllowedHeaderNames } from \"./utils/constants\";\nimport { Service, Table } from \"./generated\";\nimport { parseXML, stringifyXML } from \"@azure/core-xml\";\nimport { GeneratedClient } from \"./generated/generatedClient\";\nimport { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { Pipeline } from \"@azure/core-rest-pipeline\";\nimport { SpanStatusCode } from \"@azure/core-tracing\";\nimport { TableItemResultPage } from \"./models\";\nimport { createSpan } from \"./utils/tracing\";\nimport { getClientParamsFromConnectionString } from \"./utils/connectionString\";\nimport { handleTableAlreadyExists } from \"./utils/errorHelpers\";\nimport { isCredential } from \"./utils/isCredential\";\nimport { logger } from \"./logger\";\nimport { tablesNamedKeyCredentialPolicy } from \"./tablesNamedCredentialPolicy\";\nimport { tablesSASTokenPolicy } from \"./tablesSASTokenPolicy\";\n\n/**\n * A TableServiceClient represents a Client to the Azure Tables service allowing you\n * to perform operations on the tables and the entities.\n */\nexport class TableServiceClient {\n /**\n * Table Account URL\n */\n public url: string;\n /**\n * Represents a pipeline for making a HTTP request to a URL.\n * Pipelines can have multiple policies to manage manipulating each request before and after it is made to the server.\n */\n public pipeline: Pipeline;\n private table: Table;\n private service: Service;\n\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - NamedKeyCredential | SASCredential used to authenticate requests. Only Supported for Node\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using an account name/key:\n *\n * ```js\n * const { AzureNamedKeyCredential, TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const sharedKeyCredential = new AzureNamedKeyCredential(account, \"<account key>\");\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * sharedKeyCredential\n * );\n * ```\n */\n constructor(url: string, credential: NamedKeyCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - SASCredential used to authenticate requests\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using a SAS Token.\n *\n * ```js\n * const { AzureSASCredential, TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const sasCredential = new AzureSASCredential(account, \"<account key>\");\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * sasCredential\n * );\n * ```\n */\n constructor(url: string, credential: SASCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - Azure Active Directory credential used to authenticate requests\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using an Azure Active Directory credential:\n *\n * ```js\n * cons { DefaultAzureCredential } = require(\"@azure/identity\");\n * const { TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const credential = new DefaultAzureCredential();\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * credential\n * );\n * ```\n */\n constructor(url: string, credential: TokenCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as\n * \"https://myaccount.table.core.windows.net\". You can append a SAS,\n * such as \"https://myaccount.table.core.windows.net?sasString\".\n * @param options - Options to configure the HTTP pipeline.\n * Example appending a SAS token:\n *\n * ```js\n * const account = \"<storage account name>\";\n * const sasToken = \"<SAS token>\";\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net?${sasToken}`,\n * );\n * ```\n */\n constructor(url: string, options?: TableServiceClientOptions);\n constructor(\n url: string,\n credentialOrOptions?:\n | NamedKeyCredential\n | SASCredential\n | TokenCredential\n | TableServiceClientOptions,\n options?: TableServiceClientOptions\n ) {\n this.url = url;\n const credential = isCredential(credentialOrOptions) ? credentialOrOptions : undefined;\n const clientOptions =\n (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};\n\n clientOptions.endpoint = clientOptions.endpoint || this.url;\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...clientOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames],\n },\n deserializationOptions: {\n parseXML,\n },\n serializationOptions: {\n stringifyXML,\n },\n },\n ...(isTokenCredential(credential) && { credential, credentialScopes: STORAGE_SCOPE }),\n };\n const client = new GeneratedClient(this.url, internalPipelineOptions);\n if (isNamedKeyCredential(credential)) {\n client.pipeline.addPolicy(tablesNamedKeyCredentialPolicy(credential));\n } else if (isSASCredential(credential)) {\n client.pipeline.addPolicy(tablesSASTokenPolicy(credential));\n }\n\n this.pipeline = client.pipeline;\n this.table = client.table;\n this.service = client.service;\n }\n\n /**\n * Retrieves statistics related to replication for the Table service. It is only available on the\n * secondary location endpoint when read-access geo-redundant replication is enabled for the account.\n * @param options - The options parameters.\n */\n public async getStatistics(options: OperationOptions = {}): Promise<GetStatisticsResponse> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-getStatistics\", options);\n try {\n return await this.service.getStatistics(updatedOptions);\n } catch (e) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n throw e;\n } finally {\n span.end();\n }\n }\n\n /**\n * Gets the properties of an account's Table service, including properties for Analytics and CORS\n * (Cross-Origin Resource Sharing) rules.\n * @param options - The options parameters.\n */\n public async getProperties(options: OperationOptions = {}): Promise<GetPropertiesResponse> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-getProperties\", options);\n try {\n return await this.service.getProperties(updatedOptions);\n } catch (e) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n throw e;\n } finally {\n span.end();\n }\n }\n\n /**\n * Sets properties for an account's Table service endpoint, including properties for Analytics and CORS\n * (Cross-Origin Resource Sharing) rules.\n * @param properties - The Table Service properties.\n * @param options - The options parameters.\n */\n public async setProperties(\n properties: ServiceProperties,\n options: SetPropertiesOptions = {}\n ): Promise<SetPropertiesResponse> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-setProperties\", options);\n try {\n return await this.service.setProperties(properties, updatedOptions);\n } catch (e) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n throw e;\n } finally {\n span.end();\n }\n }\n\n /**\n * Creates a new table under the given account.\n * @param name - The name of the table.\n * @param options - The options parameters.\n */\n public async createTable(name: string, options: OperationOptions = {}): Promise<void> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-createTable\", options);\n try {\n await this.table.create({ name }, { ...updatedOptions });\n } catch (e) {\n handleTableAlreadyExists(e, { ...updatedOptions, span, logger, tableName: name });\n } finally {\n span.end();\n }\n }\n\n /**\n * Operation permanently deletes the specified table.\n * @param name - The name of the table.\n * @param options - The options parameters.\n */\n public async deleteTable(name: string, options: OperationOptions = {}): Promise<void> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-deleteTable\", options);\n try {\n await this.table.delete(name, updatedOptions);\n } catch (e) {\n if (e.statusCode === 404) {\n logger.info(\"TableServiceClient-deleteTable: Table doesn't exist\");\n } else {\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n throw e;\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Queries tables under the given account.\n * @param options - The options parameters.\n */\n public listTables(\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options?: ListTableItemsOptions\n ): PagedAsyncIterableIterator<TableItem, TableItemResultPage> {\n const iter = this.listTablesAll(options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings) => {\n const pageOptions: InternalListTablesOptions = {\n ...options,\n queryOptions: { top: settings?.maxPageSize },\n };\n\n if (settings?.continuationToken) {\n pageOptions.continuationToken = settings.continuationToken;\n }\n\n return this.listTablesPage(pageOptions);\n },\n };\n }\n\n private async *listTablesAll(\n options?: InternalListTablesOptions\n ): AsyncIterableIterator<TableItem> {\n const firstPage = await this._listTables(options);\n const { continuationToken } = firstPage;\n yield* firstPage;\n if (continuationToken) {\n const optionsWithContinuation: InternalListTablesOptions = {\n ...options,\n continuationToken,\n };\n for await (const page of this.listTablesPage(optionsWithContinuation)) {\n yield* page;\n }\n }\n }\n\n private async *listTablesPage(\n options: InternalListTablesOptions = {}\n ): AsyncIterableIterator<TableItemResultPage> {\n const { span, updatedOptions } = createSpan(\"TableServiceClient-listTablesPage\", options);\n\n try {\n let result = await this._listTables(updatedOptions);\n\n yield result;\n\n while (result.continuationToken) {\n const optionsWithContinuation: InternalListTablesOptions = {\n ...updatedOptions,\n continuationToken: result.continuationToken,\n };\n result = await this._listTables(optionsWithContinuation);\n yield result;\n }\n } catch (e) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n throw e;\n } finally {\n span.end();\n }\n }\n\n private async _listTables(options: InternalListTablesOptions = {}): Promise<TableItemResultPage> {\n const { continuationToken: nextTableName, ...listOptions } = options;\n const { xMsContinuationNextTableName: continuationToken, value = [] } = await this.table.query({\n ...listOptions,\n nextTableName,\n });\n return Object.assign([...value], { continuationToken });\n }\n\n /**\n *\n * Creates an instance of TableServiceClient from connection string.\n *\n * @param connectionString - Account connection string or a SAS connection string of an Azure storage account.\n * [ Note - Account connection string can only be used in NODE.JS runtime. ]\n * Account connection string example -\n * `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`\n * SAS connection string example -\n * `BlobEndpoint=https://myaccount.table.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`\n * @param options - Options to configure the HTTP pipeline.\n * @returns A new TableServiceClient from the given connection string.\n */\n public static fromConnectionString(\n connectionString: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options?: TableServiceClientOptions\n ): TableServiceClient {\n const {\n url,\n options: clientOptions,\n credential,\n } = getClientParamsFromConnectionString(connectionString, options);\n\n if (credential) {\n return new TableServiceClient(url, credential, clientOptions);\n } else {\n return new TableServiceClient(url, clientOptions);\n }\n }\n}\n\ntype InternalListTablesOptions = ListTableItemsOptions & {\n queryOptions?: TableQueryOptions & { top?: number };\n /**\n * A table query continuation token from a previous call.\n */\n continuationToken?: string;\n};\n"]}
1
+ {"version":3,"file":"TableServiceClient.js","sourceRoot":"","sources":["../../src/TableServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,oBAAoB,CAAC;AAe5B,OAAO,EAIL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAI9D,OAAO,EAAE,m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AAmB,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC;oBACzE,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;gBAC1C,CAAC,CACF,CAAA,CAAC;gBACF,oBAAM,MAAM,CAAA,CAAC;aACd;QACH,CAAC;KAAA;IAEO,KAAK,CAAC,WAAW,CAAC,UAAqC,EAAE;QAC/D,MAAM,EAAE,iBAAiB,EAAE,aAAa,KAAqB,OAAO,EAAvB,WAAW,UAAK,OAAO,EAA9D,qBAAoD,CAAU,CAAC;QACrE,MAAM,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,iCACzF,WAAW,KACd,aAAa,IACb,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,oBAAoB,CAChC,gBAAwB;IACxB,8DAA8D;IAC9D,OAAmC;QAEnC,MAAM,EACJ,GAAG,EACH,OAAO,EAAE,aAAa,EACtB,UAAU,GACX,GAAG,mCAAmC,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEnE,IAAI,UAAU,EAAE;YACd,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;SAC/D;aAAM;YACL,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;SACnD;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport \"@azure/core-paging\";\nimport {\n GetPropertiesResponse,\n GetStatisticsResponse,\n ServiceProperties,\n SetPropertiesOptions,\n SetPropertiesResponse,\n} from \"./generatedModels\";\nimport { InternalClientPipelineOptions, OperationOptions } from \"@azure/core-client\";\nimport {\n ListTableItemsOptions,\n TableItem,\n TableQueryOptions,\n TableServiceClientOptions,\n} from \"./models\";\nimport {\n NamedKeyCredential,\n SASCredential,\n TokenCredential,\n isNamedKeyCredential,\n isSASCredential,\n isTokenCredential,\n} from \"@azure/core-auth\";\nimport { STORAGE_SCOPE, TablesLoggingAllowedHeaderNames } from \"./utils/constants\";\nimport { Service, Table } from \"./generated\";\nimport { parseXML, stringifyXML } from \"@azure/core-xml\";\nimport { GeneratedClient } from \"./generated/generatedClient\";\nimport { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { Pipeline } from \"@azure/core-rest-pipeline\";\nimport { TableItemResultPage } from \"./models\";\nimport { getClientParamsFromConnectionString } from \"./utils/connectionString\";\nimport { handleTableAlreadyExists } from \"./utils/errorHelpers\";\nimport { isCredential } from \"./utils/isCredential\";\nimport { logger } from \"./logger\";\nimport { tablesNamedKeyCredentialPolicy } from \"./tablesNamedCredentialPolicy\";\nimport { tablesSASTokenPolicy } from \"./tablesSASTokenPolicy\";\nimport { tracingClient } from \"./utils/tracing\";\n\n/**\n * A TableServiceClient represents a Client to the Azure Tables service allowing you\n * to perform operations on the tables and the entities.\n */\nexport class TableServiceClient {\n /**\n * Table Account URL\n */\n public url: string;\n /**\n * Represents a pipeline for making a HTTP request to a URL.\n * Pipelines can have multiple policies to manage manipulating each request before and after it is made to the server.\n */\n public pipeline: Pipeline;\n private table: Table;\n private service: Service;\n\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - NamedKeyCredential | SASCredential used to authenticate requests. Only Supported for Node\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using an account name/key:\n *\n * ```js\n * const { AzureNamedKeyCredential, TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const sharedKeyCredential = new AzureNamedKeyCredential(account, \"<account key>\");\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * sharedKeyCredential\n * );\n * ```\n */\n constructor(url: string, credential: NamedKeyCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - SASCredential used to authenticate requests\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using a SAS Token.\n *\n * ```js\n * const { AzureSASCredential, TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const sasCredential = new AzureSASCredential(account, \"<account key>\");\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * sasCredential\n * );\n * ```\n */\n constructor(url: string, credential: SASCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as \"https://myaccount.table.core.windows.net\".\n * @param credential - Azure Active Directory credential used to authenticate requests\n * @param options - Options to configure the HTTP pipeline.\n *\n * ### Example using an Azure Active Directory credential:\n *\n * ```js\n * cons { DefaultAzureCredential } = require(\"@azure/identity\");\n * const { TableServiceClient } = require(\"@azure/data-tables\")\n * const account = \"<storage account name>\"\n * const credential = new DefaultAzureCredential();\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net`,\n * credential\n * );\n * ```\n */\n constructor(url: string, credential: TokenCredential, options?: TableServiceClientOptions);\n /**\n * Creates a new instance of the TableServiceClient class.\n *\n * @param url - The URL of the service account that is the target of the desired operation., such as\n * \"https://myaccount.table.core.windows.net\". You can append a SAS,\n * such as \"https://myaccount.table.core.windows.net?sasString\".\n * @param options - Options to configure the HTTP pipeline.\n * Example appending a SAS token:\n *\n * ```js\n * const account = \"<storage account name>\";\n * const sasToken = \"<SAS token>\";\n *\n * const tableServiceClient = new TableServiceClient(\n * `https://${account}.table.core.windows.net?${sasToken}`,\n * );\n * ```\n */\n constructor(url: string, options?: TableServiceClientOptions);\n constructor(\n url: string,\n credentialOrOptions?:\n | NamedKeyCredential\n | SASCredential\n | TokenCredential\n | TableServiceClientOptions,\n options?: TableServiceClientOptions\n ) {\n this.url = url;\n const credential = isCredential(credentialOrOptions) ? credentialOrOptions : undefined;\n const clientOptions =\n (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};\n\n clientOptions.endpoint = clientOptions.endpoint || this.url;\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...clientOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames],\n },\n deserializationOptions: {\n parseXML,\n },\n serializationOptions: {\n stringifyXML,\n },\n },\n ...(isTokenCredential(credential) && { credential, credentialScopes: STORAGE_SCOPE }),\n };\n const client = new GeneratedClient(this.url, internalPipelineOptions);\n if (isNamedKeyCredential(credential)) {\n client.pipeline.addPolicy(tablesNamedKeyCredentialPolicy(credential));\n } else if (isSASCredential(credential)) {\n client.pipeline.addPolicy(tablesSASTokenPolicy(credential));\n }\n\n this.pipeline = client.pipeline;\n this.table = client.table;\n this.service = client.service;\n }\n\n /**\n * Retrieves statistics related to replication for the Table service. It is only available on the\n * secondary location endpoint when read-access geo-redundant replication is enabled for the account.\n * @param options - The options parameters.\n */\n public getStatistics(options: OperationOptions = {}): Promise<GetStatisticsResponse> {\n return tracingClient.withSpan(\"TableServiceClient.getStatistics\", options, (updatedOptions) =>\n this.service.getStatistics(updatedOptions)\n );\n }\n\n /**\n * Gets the properties of an account's Table service, including properties for Analytics and CORS\n * (Cross-Origin Resource Sharing) rules.\n * @param options - The options parameters.\n */\n public getProperties(options: OperationOptions = {}): Promise<GetPropertiesResponse> {\n return tracingClient.withSpan(\"TableServiceClient.getProperties\", options, (updatedOptions) =>\n this.service.getProperties(updatedOptions)\n );\n }\n\n /**\n * Sets properties for an account's Table service endpoint, including properties for Analytics and CORS\n * (Cross-Origin Resource Sharing) rules.\n * @param properties - The Table Service properties.\n * @param options - The options parameters.\n */\n public setProperties(\n properties: ServiceProperties,\n options: SetPropertiesOptions = {}\n ): Promise<SetPropertiesResponse> {\n return tracingClient.withSpan(\"TableServiceClient.setProperties\", options, (updatedOptions) =>\n this.service.setProperties(properties, updatedOptions)\n );\n }\n\n /**\n * Creates a new table under the given account.\n * @param name - The name of the table.\n * @param options - The options parameters.\n */\n public createTable(name: string, options: OperationOptions = {}): Promise<void> {\n return tracingClient.withSpan(\n \"TableServiceClient.createTable\",\n options,\n async (updatedOptions) => {\n try {\n await this.table.create({ name }, updatedOptions);\n } catch (e) {\n handleTableAlreadyExists(e, { ...updatedOptions, logger, tableName: name });\n }\n }\n );\n }\n\n /**\n * Operation permanently deletes the specified table.\n * @param name - The name of the table.\n * @param options - The options parameters.\n */\n public deleteTable(name: string, options: OperationOptions = {}): Promise<void> {\n return tracingClient.withSpan(\n \"TableServiceClient.deleteTable\",\n options,\n async (updatedOptions) => {\n try {\n await this.table.delete(name, updatedOptions);\n } catch (e) {\n if (e.statusCode === 404) {\n logger.info(\"TableServiceClient-deleteTable: Table doesn't exist\");\n } else {\n throw e;\n }\n }\n }\n );\n }\n\n /**\n * Queries tables under the given account.\n * @param options - The options parameters.\n */\n public listTables(\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options?: ListTableItemsOptions\n ): PagedAsyncIterableIterator<TableItem, TableItemResultPage> {\n const iter = this.listTablesAll(options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings) => {\n const pageOptions: InternalListTablesOptions = {\n ...options,\n queryOptions: { top: settings?.maxPageSize },\n };\n\n if (settings?.continuationToken) {\n pageOptions.continuationToken = settings.continuationToken;\n }\n\n return this.listTablesPage(pageOptions);\n },\n };\n }\n\n private async *listTablesAll(\n options?: InternalListTablesOptions\n ): AsyncIterableIterator<TableItem> {\n const firstPage = await this._listTables(options);\n const { continuationToken } = firstPage;\n yield* firstPage;\n if (continuationToken) {\n const optionsWithContinuation: InternalListTablesOptions = {\n ...options,\n continuationToken,\n };\n for await (const page of this.listTablesPage(optionsWithContinuation)) {\n yield* page;\n }\n }\n }\n\n private async *listTablesPage(\n options: InternalListTablesOptions = {}\n ): AsyncIterableIterator<TableItemResultPage> {\n let result = await tracingClient.withSpan(\n \"TableServiceClient.listTablesPage\",\n options,\n (updatedOptions) => this._listTables(updatedOptions)\n );\n\n yield result;\n\n while (result.continuationToken) {\n const optionsWithContinuation: InternalListTablesOptions = {\n ...options,\n continuationToken: result.continuationToken,\n };\n result = await tracingClient.withSpan(\n \"TableServiceClient.listTablesPage\",\n optionsWithContinuation,\n async (updatedOptions, span) => {\n span.setAttribute(\"continuationToken\", updatedOptions.continuationToken);\n return this._listTables(updatedOptions);\n }\n );\n yield result;\n }\n }\n\n private async _listTables(options: InternalListTablesOptions = {}): Promise<TableItemResultPage> {\n const { continuationToken: nextTableName, ...listOptions } = options;\n const { xMsContinuationNextTableName: continuationToken, value = [] } = await this.table.query({\n ...listOptions,\n nextTableName,\n });\n return Object.assign([...value], { continuationToken });\n }\n\n /**\n *\n * Creates an instance of TableServiceClient from connection string.\n *\n * @param connectionString - Account connection string or a SAS connection string of an Azure storage account.\n * [ Note - Account connection string can only be used in NODE.JS runtime. ]\n * Account connection string example -\n * `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`\n * SAS connection string example -\n * `BlobEndpoint=https://myaccount.table.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`\n * @param options - Options to configure the HTTP pipeline.\n * @returns A new TableServiceClient from the given connection string.\n */\n public static fromConnectionString(\n connectionString: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options?: TableServiceClientOptions\n ): TableServiceClient {\n const {\n url,\n options: clientOptions,\n credential,\n } = getClientParamsFromConnectionString(connectionString, options);\n\n if (credential) {\n return new TableServiceClient(url, credential, clientOptions);\n } else {\n return new TableServiceClient(url, clientOptions);\n }\n }\n}\n\ntype InternalListTablesOptions = ListTableItemsOptions & {\n queryOptions?: TableQueryOptions & { top?: number };\n /**\n * A table query continuation token from a previous call.\n */\n continuationToken?: string;\n};\n"]}
@@ -1,18 +1,13 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { isNamedKeyCredential, isSASCredential, isTokenCredential, } from "@azure/core-auth";
4
- import { ServiceClient, serializationPolicy, serializationPolicyName, } from "@azure/core-client";
3
+ import { serializationPolicy, serializationPolicyName, } from "@azure/core-client";
5
4
  import { RestError, createHttpHeaders, createPipelineRequest, } from "@azure/core-rest-pipeline";
6
5
  import { getInitialTransactionBody, getTransactionHttpRequestBody, } from "./utils/transactionHelpers";
7
6
  import { transactionHeaderFilterPolicy, transactionHeaderFilterPolicyName, transactionRequestAssemblePolicy, transactionRequestAssemblePolicyName, } from "./TablePolicies";
8
- import { STORAGE_SCOPE } from "./utils/constants";
9
- import { SpanStatusCode } from "@azure/core-tracing";
10
7
  import { cosmosPatchPolicy } from "./cosmosPathPolicy";
11
- import { createSpan } from "./utils/tracing";
12
- import { getAuthorizationHeader } from "./tablesNamedCredentialPolicy";
13
8
  import { getTransactionHeaders } from "./utils/transactionHeaders";
14
9
  import { isCosmosEndpoint } from "./utils/isCosmosEndpoint";
15
- import { signURLWithSAS } from "./tablesSASTokenPolicy";
10
+ import { tracingClient } from "./utils/tracing";
16
11
  /**
17
12
  * Helper to build a list of transaction actions
18
13
  */
@@ -61,9 +56,8 @@ export class InternalTableTransaction {
61
56
  * @param partitionKey - partition key
62
57
  * @param credential - credential to authenticate the transaction request
63
58
  */
64
- constructor(url, partitionKey, transactionId, changesetId, clientOptions, interceptClient, credential, allowInsecureConnection = false) {
65
- this.clientOptions = clientOptions;
66
- this.credential = credential;
59
+ constructor(url, partitionKey, transactionId, changesetId, client, interceptClient, credential, allowInsecureConnection = false) {
60
+ this.client = client;
67
61
  this.url = url;
68
62
  this.interceptClient = interceptClient;
69
63
  this.allowInsecureConnection = allowInsecureConnection;
@@ -157,43 +151,19 @@ export class InternalTableTransaction {
157
151
  async submitTransaction() {
158
152
  await Promise.all(this.resetableState.pendingOperations);
159
153
  const body = getTransactionHttpRequestBody(this.resetableState.bodyParts, this.resetableState.transactionId, this.resetableState.changesetId);
160
- const options = this.clientOptions;
161
- if (isTokenCredential(this.credential)) {
162
- options.credentialScopes = STORAGE_SCOPE;
163
- options.credential = this.credential;
164
- }
165
- const client = new ServiceClient(options);
166
154
  const headers = getTransactionHeaders(this.resetableState.transactionId);
167
- const { span, updatedOptions } = createSpan("TableTransaction-submitTransaction", {});
168
- const request = createPipelineRequest({
169
- url: this.url,
170
- method: "POST",
171
- body,
172
- headers: createHttpHeaders(headers),
173
- tracingOptions: updatedOptions.tracingOptions,
174
- allowInsecureConnection: this.allowInsecureConnection,
175
- });
176
- if (isNamedKeyCredential(this.credential)) {
177
- const authHeader = getAuthorizationHeader(request, this.credential);
178
- request.headers.set("Authorization", authHeader);
179
- }
180
- else if (isSASCredential(this.credential)) {
181
- signURLWithSAS(request, this.credential);
182
- }
183
- try {
184
- const rawTransactionResponse = await client.sendRequest(request);
185
- return parseTransactionResponse(rawTransactionResponse);
186
- }
187
- catch (error) {
188
- span.setStatus({
189
- code: SpanStatusCode.ERROR,
190
- message: error.message,
155
+ return tracingClient.withSpan("TableTransaction.submitTransaction", {}, async (updatedOptions) => {
156
+ const request = createPipelineRequest({
157
+ url: this.url,
158
+ method: "POST",
159
+ body,
160
+ headers: createHttpHeaders(headers),
161
+ tracingOptions: updatedOptions.tracingOptions,
162
+ allowInsecureConnection: this.allowInsecureConnection,
191
163
  });
192
- throw error;
193
- }
194
- finally {
195
- span.end();
196
- }
164
+ const rawTransactionResponse = await this.client.sendRequest(request);
165
+ return parseTransactionResponse(rawTransactionResponse);
166
+ });
197
167
  }
198
168
  checkPartitionKey(partitionKey) {
199
169
  if (this.resetableState.partitionKey !== partitionKey) {
@@ -1 +1 @@
1
-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,CAAC;IAClE,QAAQ,CAAC,SAAS,CAAC,6BAA6B,EAAE,CAAC,CAAC;IACpD,QAAQ,CAAC,SAAS,CAAC,gCAAgC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7E,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE;YACtC,aAAa,EAAE,CAAC,iCAAiC,CAAC;YAClD,cAAc,EAAE,CAAC,uBAAuB,EAAE,oCAAoC,CAAC;SAChF,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n DeleteTableEntityOptions,\n TableEntity,\n TableServiceClientOptions,\n TableTransactionEntityResponse,\n TableTransactionResponse,\n TransactionAction,\n UpdateMode,\n UpdateTableEntityOptions,\n} from \"./models\";\nimport {\n NamedKeyCredential,\n SASCredential,\n TokenCredential,\n isNamedKeyCredential,\n isSASCredential,\n isTokenCredential,\n} from \"@azure/core-auth\";\nimport {\n OperationOptions,\n ServiceClient,\n ServiceClientOptions,\n serializationPolicy,\n serializationPolicyName,\n} from \"@azure/core-client\";\nimport {\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n RestError,\n createHttpHeaders,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport {\n getInitialTransactionBody,\n getTransactionHttpRequestBody,\n} from \"./utils/transactionHelpers\";\nimport {\n transactionHeaderFilterPolicy,\n transactionHeaderFilterPolicyName,\n transactionRequestAssemblePolicy,\n transactionRequestAssemblePolicyName,\n} from \"./TablePolicies\";\nimport { STORAGE_SCOPE } from \"./utils/constants\";\nimport { SpanStatusCode } from \"@azure/core-tracing\";\nimport { TableClientLike } from \"./utils/internalModels\";\nimport { TableServiceErrorOdataError } from \"./generated\";\nimport { cosmosPatchPolicy } from \"./cosmosPathPolicy\";\nimport { createSpan } from \"./utils/tracing\";\nimport { getAuthorizationHeader } from \"./tablesNamedCredentialPolicy\";\nimport { getTransactionHeaders } from \"./utils/transactionHeaders\";\nimport { isCosmosEndpoint } from \"./utils/isCosmosEndpoint\";\nimport { signURLWithSAS } from \"./tablesSASTokenPolicy\";\n\n/**\n * Helper to build a list of transaction actions\n */\nexport class TableTransaction {\n /**\n * List of actions to perform in a transaction\n */\n public actions: TransactionAction[];\n\n constructor(actions?: TransactionAction[]) {\n this.actions = actions ?? [];\n }\n\n /**\n * Adds a create action to the transaction\n * @param entity - entity to create\n */\n createEntity<T extends object = Record<string, unknown>>(entity: TableEntity<T>): void {\n this.actions.push([\"create\", entity]);\n }\n\n /**\n * Adds a delete action to the transaction\n * @param partitionKey - partition key of the entity to delete\n * @param rowKey - rowKey of the entity to delete\n */\n deleteEntity(partitionKey: string, rowKey: string): void {\n this.actions.push([\"delete\", { partitionKey, rowKey }]);\n }\n\n /**\n * Adds an update action to the transaction\n * @param entity - entity to update\n * @param updateMode - update mode\n */\n updateEntity<T extends object = Record<string, unknown>>(\n entity: TableEntity<T>,\n updateMode: UpdateMode = \"Merge\"\n ): void {\n this.actions.push([\"update\", entity, updateMode]);\n }\n\n /**\n * Adds an upsert action to the transaction, which inserts if the entity doesn't exist or updates the existing one\n * @param entity - entity to upsert\n * @param updateMode - update mode\n */\n upsertEntity<T extends object = Record<string, unknown>>(\n entity: TableEntity<T>,\n updateMode: UpdateMode = \"Merge\"\n ): void {\n this.actions.push([\"upsert\", entity, updateMode]);\n }\n}\n\n/**\n * TableTransaction collects sub-operations that can be submitted together via submitTransaction\n */\nexport class InternalTableTransaction {\n /**\n * Table Account URL\n */\n public url: string;\n /**\n * This part of the state can be reset by\n * calling the reset function. Other parts of the state\n * such as the credentials remain the same throughout the life\n * of the instance.\n */\n private resetableState: {\n transactionId: string;\n changesetId: string;\n pendingOperations: Promise<any>[];\n bodyParts: string[];\n partitionKey: string;\n };\n private clientOptions: TableServiceClientOptions;\n private interceptClient: TableClientLike;\n private credential?: NamedKeyCredential | SASCredential | TokenCredential;\n private allowInsecureConnection: boolean;\n\n /**\n * @param url - Tables account url\n * @param partitionKey - partition key\n * @param credential - credential to authenticate the transaction request\n */\n constructor(\n url: string,\n partitionKey: string,\n transactionId: string,\n changesetId: string,\n clientOptions: TableServiceClientOptions,\n interceptClient: TableClientLike,\n credential?: NamedKeyCredential | SASCredential | TokenCredential,\n allowInsecureConnection: boolean = false\n ) {\n this.clientOptions = clientOptions;\n this.credential = credential;\n this.url = url;\n this.interceptClient = interceptClient;\n this.allowInsecureConnection = allowInsecureConnection;\n\n // Initialize Reset-able properties\n this.resetableState = this.initializeSharedState(transactionId, changesetId, partitionKey);\n\n // Depending on the auth method used we need to build the url\n if (!credential) {\n // When the SAS token is provided as part of the URL we need to move it after $batch\n const urlParts = url.split(\"?\");\n this.url = urlParts[0];\n const sas = urlParts.length > 1 ? `?${urlParts[1]}` : \"\";\n this.url = `${this.getUrlWithSlash()}$batch${sas}`;\n } else {\n // When using a SharedKey credential no SAS token is needed\n this.url = `${this.getUrlWithSlash()}$batch`;\n }\n }\n\n /**\n * Resets the state of the Transaction.\n */\n reset(transactionId: string, changesetId: string, partitionKey: string): void {\n this.resetableState = this.initializeSharedState(transactionId, changesetId, partitionKey);\n }\n\n private initializeSharedState(transactionId: string, changesetId: string, partitionKey: string) {\n const pendingOperations: Promise<any>[] = [];\n const bodyParts = getInitialTransactionBody(transactionId, changesetId);\n const isCosmos = isCosmosEndpoint(this.url);\n prepateTransactionPipeline(this.interceptClient.pipeline, bodyParts, changesetId, isCosmos);\n\n return {\n transactionId,\n changesetId,\n partitionKey,\n pendingOperations,\n bodyParts,\n };\n }\n\n /**\n * Adds a createEntity operation to the transaction\n * @param entity - Entity to create\n */\n public createEntity<T extends object>(entity: TableEntity<T>): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(this.interceptClient.createEntity(entity));\n }\n\n /**\n * Adds a createEntity operation to the transaction per each entity in the entities array\n * @param entities - Array of entities to create\n */\n public createEntities<T extends object>(entities: TableEntity<T>[]): void {\n for (const entity of entities) {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(this.interceptClient.createEntity(entity));\n }\n }\n\n /**\n * Adds a deleteEntity operation to the transaction\n * @param partitionKey - Partition key of the entity to delete\n * @param rowKey - Row key of the entity to delete\n * @param options - Options for the delete operation\n */\n public deleteEntity(\n partitionKey: string,\n rowKey: string,\n options?: DeleteTableEntityOptions\n ): void {\n this.checkPartitionKey(partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.deleteEntity(partitionKey, rowKey, options)\n );\n }\n\n /**\n * Adds an updateEntity operation to the transaction\n * @param entity - Entity to update\n * @param mode - Update mode (Merge or Replace)\n * @param options - Options for the update operation\n */\n public updateEntity<T extends object>(\n entity: TableEntity<T>,\n mode: UpdateMode,\n options?: UpdateTableEntityOptions\n ): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.updateEntity(entity, mode, options)\n );\n }\n\n /**\n * Adds an upsertEntity operation to the transaction\n * @param entity - The properties for the table entity.\n * @param mode - The different modes for updating the entity:\n * - Merge: Updates an entity by updating the entity's properties without replacing the existing entity.\n * - Replace: Updates an existing entity by replacing the entire entity.\n * @param options - The options parameters.\n */\n public upsertEntity<T extends object>(\n entity: TableEntity<T>,\n mode: UpdateMode,\n options?: OperationOptions\n ): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.upsertEntity(entity, mode, options)\n );\n }\n\n /**\n * Submits the operations in the transaction\n */\n public async submitTransaction(): Promise<TableTransactionResponse> {\n await Promise.all(this.resetableState.pendingOperations);\n const body = getTransactionHttpRequestBody(\n this.resetableState.bodyParts,\n this.resetableState.transactionId,\n this.resetableState.changesetId\n );\n\n const options: ServiceClientOptions = this.clientOptions;\n\n if (isTokenCredential(this.credential)) {\n options.credentialScopes = STORAGE_SCOPE;\n options.credential = this.credential;\n }\n\n const client = new ServiceClient(options);\n\n const headers = getTransactionHeaders(this.resetableState.transactionId);\n\n const { span, updatedOptions } = createSpan(\n \"TableTransaction-submitTransaction\",\n {} as OperationOptions\n );\n const request = createPipelineRequest({\n url: this.url,\n method: \"POST\",\n body,\n headers: createHttpHeaders(headers),\n tracingOptions: updatedOptions.tracingOptions,\n allowInsecureConnection: this.allowInsecureConnection,\n });\n\n if (isNamedKeyCredential(this.credential)) {\n const authHeader = getAuthorizationHeader(request, this.credential);\n request.headers.set(\"Authorization\", authHeader);\n } else if (isSASCredential(this.credential)) {\n signURLWithSAS(request, this.credential);\n }\n\n try {\n const rawTransactionResponse = await client.sendRequest(request);\n return parseTransactionResponse(rawTransactionResponse);\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n throw error;\n } finally {\n span.end();\n }\n }\n\n private checkPartitionKey(partitionKey: string): void {\n if (this.resetableState.partitionKey !== partitionKey) {\n throw new Error(\"All operations in a transaction must target the same partitionKey\");\n }\n }\n\n private getUrlWithSlash(): string {\n return this.url.endsWith(\"/\") ? this.url : `${this.url}/`;\n }\n}\n\nexport function parseTransactionResponse(\n transactionResponse: PipelineResponse\n): TableTransactionResponse {\n const subResponsePrefix = `--changesetresponse_`;\n const status = transactionResponse.status;\n const rawBody = transactionResponse.bodyAsText || \"\";\n const splitBody = rawBody.split(subResponsePrefix);\n const isSuccessByStatus = 200 <= status && status < 300;\n\n if (!isSuccessByStatus) {\n handleBodyError(rawBody, status, transactionResponse.request, transactionResponse);\n }\n\n // Dropping the first and last elements as they are the boundaries\n // we just care about sub request content\n const subResponses = splitBody.slice(1, splitBody.length - 1);\n\n const responses: TableTransactionEntityResponse[] = subResponses.map((subResponse) => {\n const statusMatch = subResponse.match(/HTTP\\/1.1 ([0-9]*)/);\n if (statusMatch?.length !== 2) {\n throw new Error(`Couldn't extract status from sub-response:\\n ${subResponse}`);\n }\n const subResponseStatus = Number.parseInt(statusMatch[1]);\n if (!Number.isInteger(subResponseStatus)) {\n throw new Error(`Expected sub-response status to be an integer ${subResponseStatus}`);\n }\n\n const bodyMatch = subResponse.match(/\\{(.*)\\}/);\n if (bodyMatch?.length === 2) {\n handleBodyError(\n bodyMatch[0],\n subResponseStatus,\n transactionResponse.request,\n transactionResponse\n );\n }\n\n const etagMatch = subResponse.match(/ETag: (.*)/);\n const rowKeyMatch = subResponse.match(/RowKey='(.*)'/);\n\n return {\n status: subResponseStatus,\n ...(rowKeyMatch?.length === 2 && { rowKey: rowKeyMatch[1] }),\n ...(etagMatch?.length === 2 && { etag: etagMatch[1] }),\n };\n });\n\n return {\n status,\n subResponses: responses,\n getResponseForEntity: (rowKey: string) => responses.find((r) => r.rowKey === rowKey),\n };\n}\n\nfunction handleBodyError(\n bodyAsText: string,\n statusCode: number,\n request: PipelineRequest,\n response: PipelineResponse\n) {\n let parsedError;\n\n try {\n parsedError = JSON.parse(bodyAsText);\n } catch {\n parsedError = {};\n }\n\n let message = \"Transaction Failed\";\n let code: string | undefined;\n // Only transaction sub-responses return body\n if (parsedError && parsedError[\"odata.error\"]) {\n const error: TableServiceErrorOdataError = parsedError[\"odata.error\"];\n message = error.message?.value ?? message;\n code = error.code;\n }\n\n throw new RestError(message, {\n code,\n statusCode,\n request,\n response,\n });\n}\n\n/**\n * Prepares the transaction pipeline to intercept operations\n * @param pipeline - Client pipeline\n */\nexport function prepateTransactionPipeline(\n pipeline: Pipeline,\n bodyParts: string[],\n changesetId: string,\n isCosmos: boolean\n): void {\n // Fist, we need to clear all the existing policies to make sure we start\n // with a fresh state.\n const policies = pipeline.getOrderedPolicies();\n for (const policy of policies) {\n pipeline.removePolicy({\n name: policy.name,\n });\n }\n\n // With the clear state we now initialize the pipelines required for intercepting the requests.\n // Use transaction assemble policy to assemble request and intercept request from going to wire\n\n pipeline.addPolicy(serializationPolicy(), { phase: \"Serialize\" });\n pipeline.addPolicy(transactionHeaderFilterPolicy());\n pipeline.addPolicy(transactionRequestAssemblePolicy(bodyParts, changesetId));\n if (isCosmos) {\n pipeline.addPolicy(cosmosPatchPolicy(), {\n afterPolicies: [transactionHeaderFilterPolicyName],\n beforePolicies: [serializationPolicyName, transactionRequestAssemblePolicyName],\n });\n }\n}\n"]}
1
+ {"version":3,"file":"TableTransaction.js","sourceRoot":"","sources":["../../src/TableTransaction.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAYlC,OAAO,EAGL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAIL,SAAS,EACT,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,EACjC,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAM3B,YAAY,OAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,YAAY,CAA6C,MAAsB;QAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,YAAoB,EAAE,MAAc;QAC/C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACH,YAAY,CACV,MAAsB,EACtB,aAAyB,OAAO;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,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC,CAAC;KACJ;IAED,+FAA+F;IAC/F,+FAA+F;IAE/F,QAAQ,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAClE,QAAQ,CAAC,SAAS,CAAC,6BAA6B,EAAE,CAAC,CAAC;IACpD,QAAQ,CAAC,SAAS,CAAC,gCAAgC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7E,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE;YACtC,aAAa,EAAE,CAAC,iCAAiC,CAAC;YAClD,cAAc,EAAE,CAAC,uBAAuB,EAAE,oCAAoC,CAAC;SAChF,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n DeleteTableEntityOptions,\n TableEntity,\n TableTransactionEntityResponse,\n TableTransactionResponse,\n TransactionAction,\n UpdateMode,\n UpdateTableEntityOptions,\n} from \"./models\";\nimport { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport {\n OperationOptions,\n ServiceClient,\n serializationPolicy,\n serializationPolicyName,\n} from \"@azure/core-client\";\nimport {\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n RestError,\n createHttpHeaders,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport {\n getInitialTransactionBody,\n getTransactionHttpRequestBody,\n} from \"./utils/transactionHelpers\";\nimport {\n transactionHeaderFilterPolicy,\n transactionHeaderFilterPolicyName,\n transactionRequestAssemblePolicy,\n transactionRequestAssemblePolicyName,\n} from \"./TablePolicies\";\n\nimport { TableClientLike } from \"./utils/internalModels\";\nimport { TableServiceErrorOdataError } from \"./generated\";\nimport { cosmosPatchPolicy } from \"./cosmosPathPolicy\";\nimport { getTransactionHeaders } from \"./utils/transactionHeaders\";\nimport { isCosmosEndpoint } from \"./utils/isCosmosEndpoint\";\nimport { tracingClient } from \"./utils/tracing\";\n\n/**\n * Helper to build a list of transaction actions\n */\nexport class TableTransaction {\n /**\n * List of actions to perform in a transaction\n */\n public actions: TransactionAction[];\n\n constructor(actions?: TransactionAction[]) {\n this.actions = actions ?? [];\n }\n\n /**\n * Adds a create action to the transaction\n * @param entity - entity to create\n */\n createEntity<T extends object = Record<string, unknown>>(entity: TableEntity<T>): void {\n this.actions.push([\"create\", entity]);\n }\n\n /**\n * Adds a delete action to the transaction\n * @param partitionKey - partition key of the entity to delete\n * @param rowKey - rowKey of the entity to delete\n */\n deleteEntity(partitionKey: string, rowKey: string): void {\n this.actions.push([\"delete\", { partitionKey, rowKey }]);\n }\n\n /**\n * Adds an update action to the transaction\n * @param entity - entity to update\n * @param updateMode - update mode\n */\n updateEntity<T extends object = Record<string, unknown>>(\n entity: TableEntity<T>,\n updateMode: UpdateMode = \"Merge\"\n ): void {\n this.actions.push([\"update\", entity, updateMode]);\n }\n\n /**\n * Adds an upsert action to the transaction, which inserts if the entity doesn't exist or updates the existing one\n * @param entity - entity to upsert\n * @param updateMode - update mode\n */\n upsertEntity<T extends object = Record<string, unknown>>(\n entity: TableEntity<T>,\n updateMode: UpdateMode = \"Merge\"\n ): void {\n this.actions.push([\"upsert\", entity, updateMode]);\n }\n}\n\n/**\n * TableTransaction collects sub-operations that can be submitted together via submitTransaction\n */\nexport class InternalTableTransaction {\n /**\n * Table Account URL\n */\n public url: string;\n /**\n * This part of the state can be reset by\n * calling the reset function. Other parts of the state\n * such as the credentials remain the same throughout the life\n * of the instance.\n */\n private resetableState: {\n transactionId: string;\n changesetId: string;\n pendingOperations: Promise<any>[];\n bodyParts: string[];\n partitionKey: string;\n };\n private interceptClient: TableClientLike;\n private allowInsecureConnection: boolean;\n private client: ServiceClient;\n\n /**\n * @param url - Tables account url\n * @param partitionKey - partition key\n * @param credential - credential to authenticate the transaction request\n */\n constructor(\n url: string,\n partitionKey: string,\n transactionId: string,\n changesetId: string,\n client: ServiceClient,\n interceptClient: TableClientLike,\n credential?: NamedKeyCredential | SASCredential | TokenCredential,\n allowInsecureConnection: boolean = false\n ) {\n this.client = client;\n this.url = url;\n this.interceptClient = interceptClient;\n this.allowInsecureConnection = allowInsecureConnection;\n\n // Initialize Reset-able properties\n this.resetableState = this.initializeSharedState(transactionId, changesetId, partitionKey);\n\n // Depending on the auth method used we need to build the url\n if (!credential) {\n // When the SAS token is provided as part of the URL we need to move it after $batch\n const urlParts = url.split(\"?\");\n this.url = urlParts[0];\n const sas = urlParts.length > 1 ? `?${urlParts[1]}` : \"\";\n this.url = `${this.getUrlWithSlash()}$batch${sas}`;\n } else {\n // When using a SharedKey credential no SAS token is needed\n this.url = `${this.getUrlWithSlash()}$batch`;\n }\n }\n\n /**\n * Resets the state of the Transaction.\n */\n reset(transactionId: string, changesetId: string, partitionKey: string): void {\n this.resetableState = this.initializeSharedState(transactionId, changesetId, partitionKey);\n }\n\n private initializeSharedState(transactionId: string, changesetId: string, partitionKey: string) {\n const pendingOperations: Promise<any>[] = [];\n const bodyParts = getInitialTransactionBody(transactionId, changesetId);\n const isCosmos = isCosmosEndpoint(this.url);\n prepateTransactionPipeline(this.interceptClient.pipeline, bodyParts, changesetId, isCosmos);\n\n return {\n transactionId,\n changesetId,\n partitionKey,\n pendingOperations,\n bodyParts,\n };\n }\n\n /**\n * Adds a createEntity operation to the transaction\n * @param entity - Entity to create\n */\n public createEntity<T extends object>(entity: TableEntity<T>): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(this.interceptClient.createEntity(entity));\n }\n\n /**\n * Adds a createEntity operation to the transaction per each entity in the entities array\n * @param entities - Array of entities to create\n */\n public createEntities<T extends object>(entities: TableEntity<T>[]): void {\n for (const entity of entities) {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(this.interceptClient.createEntity(entity));\n }\n }\n\n /**\n * Adds a deleteEntity operation to the transaction\n * @param partitionKey - Partition key of the entity to delete\n * @param rowKey - Row key of the entity to delete\n * @param options - Options for the delete operation\n */\n public deleteEntity(\n partitionKey: string,\n rowKey: string,\n options?: DeleteTableEntityOptions\n ): void {\n this.checkPartitionKey(partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.deleteEntity(partitionKey, rowKey, options)\n );\n }\n\n /**\n * Adds an updateEntity operation to the transaction\n * @param entity - Entity to update\n * @param mode - Update mode (Merge or Replace)\n * @param options - Options for the update operation\n */\n public updateEntity<T extends object>(\n entity: TableEntity<T>,\n mode: UpdateMode,\n options?: UpdateTableEntityOptions\n ): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.updateEntity(entity, mode, options)\n );\n }\n\n /**\n * Adds an upsertEntity operation to the transaction\n * @param entity - The properties for the table entity.\n * @param mode - The different modes for updating the entity:\n * - Merge: Updates an entity by updating the entity's properties without replacing the existing entity.\n * - Replace: Updates an existing entity by replacing the entire entity.\n * @param options - The options parameters.\n */\n public upsertEntity<T extends object>(\n entity: TableEntity<T>,\n mode: UpdateMode,\n options?: OperationOptions\n ): void {\n this.checkPartitionKey(entity.partitionKey);\n this.resetableState.pendingOperations.push(\n this.interceptClient.upsertEntity(entity, mode, options)\n );\n }\n\n /**\n * Submits the operations in the transaction\n */\n public async submitTransaction(): Promise<TableTransactionResponse> {\n await Promise.all(this.resetableState.pendingOperations);\n const body = getTransactionHttpRequestBody(\n this.resetableState.bodyParts,\n this.resetableState.transactionId,\n this.resetableState.changesetId\n );\n\n const headers = getTransactionHeaders(this.resetableState.transactionId);\n\n return tracingClient.withSpan(\n \"TableTransaction.submitTransaction\",\n {} as OperationOptions,\n async (updatedOptions) => {\n const request = createPipelineRequest({\n url: this.url,\n method: \"POST\",\n body,\n headers: createHttpHeaders(headers),\n tracingOptions: updatedOptions.tracingOptions,\n allowInsecureConnection: this.allowInsecureConnection,\n });\n\n const rawTransactionResponse = await this.client.sendRequest(request);\n return parseTransactionResponse(rawTransactionResponse);\n }\n );\n }\n\n private checkPartitionKey(partitionKey: string): void {\n if (this.resetableState.partitionKey !== partitionKey) {\n throw new Error(\"All operations in a transaction must target the same partitionKey\");\n }\n }\n\n private getUrlWithSlash(): string {\n return this.url.endsWith(\"/\") ? this.url : `${this.url}/`;\n }\n}\n\nexport function parseTransactionResponse(\n transactionResponse: PipelineResponse\n): TableTransactionResponse {\n const subResponsePrefix = `--changesetresponse_`;\n const status = transactionResponse.status;\n const rawBody = transactionResponse.bodyAsText || \"\";\n const splitBody = rawBody.split(subResponsePrefix);\n const isSuccessByStatus = 200 <= status && status < 300;\n\n if (!isSuccessByStatus) {\n handleBodyError(rawBody, status, transactionResponse.request, transactionResponse);\n }\n\n // Dropping the first and last elements as they are the boundaries\n // we just care about sub request content\n const subResponses = splitBody.slice(1, splitBody.length - 1);\n\n const responses: TableTransactionEntityResponse[] = subResponses.map((subResponse) => {\n const statusMatch = subResponse.match(/HTTP\\/1.1 ([0-9]*)/);\n if (statusMatch?.length !== 2) {\n throw new Error(`Couldn't extract status from sub-response:\\n ${subResponse}`);\n }\n const subResponseStatus = Number.parseInt(statusMatch[1]);\n if (!Number.isInteger(subResponseStatus)) {\n throw new Error(`Expected sub-response status to be an integer ${subResponseStatus}`);\n }\n\n const bodyMatch = subResponse.match(/\\{(.*)\\}/);\n if (bodyMatch?.length === 2) {\n handleBodyError(\n bodyMatch[0],\n subResponseStatus,\n transactionResponse.request,\n transactionResponse\n );\n }\n\n const etagMatch = subResponse.match(/ETag: (.*)/);\n const rowKeyMatch = subResponse.match(/RowKey='(.*)'/);\n\n return {\n status: subResponseStatus,\n ...(rowKeyMatch?.length === 2 && { rowKey: rowKeyMatch[1] }),\n ...(etagMatch?.length === 2 && { etag: etagMatch[1] }),\n };\n });\n\n return {\n status,\n subResponses: responses,\n getResponseForEntity: (rowKey: string) => responses.find((r) => r.rowKey === rowKey),\n };\n}\n\nfunction handleBodyError(\n bodyAsText: string,\n statusCode: number,\n request: PipelineRequest,\n response: PipelineResponse\n) {\n let parsedError;\n\n try {\n parsedError = JSON.parse(bodyAsText);\n } catch {\n parsedError = {};\n }\n\n let message = \"Transaction Failed\";\n let code: string | undefined;\n // Only transaction sub-responses return body\n if (parsedError && parsedError[\"odata.error\"]) {\n const error: TableServiceErrorOdataError = parsedError[\"odata.error\"];\n message = error.message?.value ?? message;\n code = error.code;\n }\n\n throw new RestError(message, {\n code,\n statusCode,\n request,\n response,\n });\n}\n\n/**\n * Prepares the transaction pipeline to intercept operations\n * @param pipeline - Client pipeline\n */\nexport function prepateTransactionPipeline(\n pipeline: Pipeline,\n bodyParts: string[],\n changesetId: string,\n isCosmos: boolean\n): void {\n // Fist, we need to clear all the existing policies to make sure we start\n // with a fresh state.\n const policies = pipeline.getOrderedPolicies();\n for (const policy of policies) {\n pipeline.removePolicy({\n name: policy.name,\n });\n }\n\n // With the clear state we now initialize the pipelines required for intercepting the requests.\n // Use transaction assemble policy to assemble request and intercept request from going to wire\n\n pipeline.addPolicy(serializationPolicy(), { phase: \"Serialize\" });\n pipeline.addPolicy(transactionHeaderFilterPolicy());\n pipeline.addPolicy(transactionRequestAssemblePolicy(bodyParts, changesetId));\n if (isCosmos) {\n pipeline.addPolicy(cosmosPatchPolicy(), {\n afterPolicies: [transactionHeaderFilterPolicyName],\n beforePolicies: [serializationPolicyName, transactionRequestAssemblePolicyName],\n });\n }\n}\n"]}
@@ -24,7 +24,7 @@ export class GeneratedClientContext extends coreClient.ServiceClient {
24
24
  const defaults = {
25
25
  requestContentType: "application/json; charset=utf-8"
26
26
  };
27
- const packageDetails = `azsdk-js-data-tables/13.0.2`;
27
+ const packageDetails = `azsdk-js-data-tables/13.1.0`;
28
28
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
29
29
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
30
30
  : `${packageDetails}`;
@@ -1 +1 @@
1
- {"version":3,"file":"generatedClientContext.js","sourceRoot":"","sources":["../../../src/generated/generatedClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,gBAAgB;AAChB,MAAM,OAAO,sBAAuB,SAAQ,UAAU,CAAC,aAAa;IAIlE;;;;OAIG;IACH,YAAY,GAAW,EAAE,OAAuC;QAC9D,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;QAED,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAAkC;YAC9C,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,6BAA6B,CAAC;QACrD,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,GACrC,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,wBAAwB;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,0CAA0C;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC;IACjD,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { GeneratedClientOptionalParams } from \"./models\";\n\n/** @internal */\nexport class GeneratedClientContext extends coreClient.ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the GeneratedClientContext class.\n * @param url The URL of the service account or table that is the target of the desired operation.\n * @param options The parameter options\n */\n constructor(url: string, options?: GeneratedClientOptionalParams) {\n if (url === undefined) {\n throw new Error(\"'url' cannot be null\");\n }\n\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: GeneratedClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-data-tables/13.0.2`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{url}\"\n };\n super(optionsWithDefaults);\n // Parameter assignments\n this.url = url;\n\n // Assigning values to Constant parameters\n this.version = options.version || \"2019-02-02\";\n }\n}\n"]}
1
+ {"version":3,"file":"generatedClientContext.js","sourceRoot":"","sources":["../../../src/generated/generatedClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,gBAAgB;AAChB,MAAM,OAAO,sBAAuB,SAAQ,UAAU,CAAC,aAAa;IAIlE;;;;OAIG;IACH,YAAY,GAAW,EAAE,OAAuC;QAC9D,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;QAED,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAAkC;YAC9C,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,6BAA6B,CAAC;QACrD,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,GACrC,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,wBAAwB;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,0CAA0C;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC;IACjD,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { GeneratedClientOptionalParams } from \"./models\";\n\n/** @internal */\nexport class GeneratedClientContext extends coreClient.ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the GeneratedClientContext class.\n * @param url The URL of the service account or table that is the target of the desired operation.\n * @param options The parameter options\n */\n constructor(url: string, options?: GeneratedClientOptionalParams) {\n if (url === undefined) {\n throw new Error(\"'url' cannot be null\");\n }\n\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: GeneratedClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-data-tables/13.1.0`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{url}\"\n };\n super(optionsWithDefaults);\n // Parameter assignments\n this.url = url;\n\n // Assigning values to Constant parameters\n this.version = options.version || \"2019-02-02\";\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { SpanStatusCode } from "@azure/core-tracing";
4
3
  export function handleTableAlreadyExists(error, options = {}) {
5
- var _a, _b, _c;
4
+ var _a, _b;
6
5
  const responseError = getErrorResponse(error);
7
6
  if (responseError &&
8
7
  responseError.status === 409 &&
@@ -13,7 +12,6 @@ export function handleTableAlreadyExists(error, options = {}) {
13
12
  }
14
13
  }
15
14
  else {
16
- options === null || options === void 0 ? void 0 : options.span.setStatus({ code: SpanStatusCode.ERROR, message: (_c = error) === null || _c === void 0 ? void 0 : _c.message });
17
15
  throw error;
18
16
  }
19
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errorHelpers.js","sourceRoot":"","sources":["../../../src/utils/errorHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAkBrD,MAAM,UAAU,wBAAwB,CACtC,KAAc,EACd,UAAuF,EAAE;;IAEzF,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,IACE,aAAa;QACb,aAAa,CAAC,MAAM,KAAK,GAAG;QAC5B,CAAA,MAAA,aAAa,CAAC,UAAU,CAAC,UAAU,0CAAE,IAAI,MAAK,oBAAoB,EAClE;QACA,MAAA,OAAO,CAAC,MAAM,0CAAE,IAAI,CAAC,SAAS,OAAO,CAAC,SAAS,iBAAiB,CAAC,CAAC;QAElE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;SACvC;KACF;SAAM;QACL,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAC,KAAe,0CAAE,OAAO,EAAE,CAAC,CAAC;QAC5F,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,aAAa,GAA8B,KAAK,CAAC,QAAqC,CAAC;IAE7F,IAAI,CAAC,aAAa,IAAI,CAAC,2BAA2B,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;QAC5E,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAQ,KAAmB,CAAC,IAAI,KAAK,WAAW,CAAC;AACnD,CAAC;AAED,SAAS,2BAA2B,CAClC,iBAAsB;IAEtB,OAAO,OAAO,CAAC,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,UAAU,CAAC,CAAC;AAChD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationOptions, OperationRequest } from \"@azure/core-client\";\nimport { PipelineResponse, RestError } from \"@azure/core-rest-pipeline\";\nimport { AzureLogger } from \"@azure/logger\";\nimport { SpanStatusCode } from \"@azure/core-tracing\";\nimport { TableServiceError } from \"../generated\";\n\nexport type TableServiceErrorResponse = PipelineResponse & {\n /**\n * The parsed HTTP response headers.\n */\n parsedHeaders?: Record<string, unknown>;\n /**\n * The response body as parsed JSON or XML.\n */\n parsedBody: TableServiceError;\n /**\n * The request that generated the response.\n */\n request: OperationRequest;\n};\n\nexport function handleTableAlreadyExists(\n error: unknown,\n options: OperationOptions & { tableName?: string; span?: any; logger?: AzureLogger } = {}\n): void {\n const responseError = getErrorResponse(error);\n if (\n responseError &&\n responseError.status === 409 &&\n responseError.parsedBody.odataError?.code === \"TableAlreadyExists\"\n ) {\n options.logger?.info(`Table ${options.tableName} already Exists`);\n\n if (options.onResponse) {\n options.onResponse(responseError, {});\n }\n } else {\n options?.span.setStatus({ code: SpanStatusCode.ERROR, message: (error as Error)?.message });\n throw error;\n }\n}\n\nfunction getErrorResponse(error: unknown): TableServiceErrorResponse | undefined {\n if (!isRestError(error)) {\n return undefined;\n }\n\n const errorResponse: TableServiceErrorResponse = error.response as TableServiceErrorResponse;\n\n if (!errorResponse || !isTableServiceErrorResponse(errorResponse.parsedBody)) {\n return undefined;\n }\n\n return errorResponse;\n}\n\nfunction isRestError(error: unknown): error is RestError {\n return (error as RestError).name === \"RestError\";\n}\n\nfunction isTableServiceErrorResponse(\n errorResponseBody: any\n): errorResponseBody is TableServiceError {\n return Boolean(errorResponseBody?.odataError);\n}\n"]}
1
+ {"version":3,"file":"errorHelpers.js","sourceRoot":"","sources":["../../../src/utils/errorHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAsBlC,MAAM,UAAU,wBAAwB,CACtC,KAAc,EACd,UAA2E,EAAE;;IAE7E,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,IACE,aAAa;QACb,aAAa,CAAC,MAAM,KAAK,GAAG;QAC5B,CAAA,MAAA,aAAa,CAAC,UAAU,CAAC,UAAU,0CAAE,IAAI,MAAK,oBAAoB,EAClE;QACA,MAAA,OAAO,CAAC,MAAM,0CAAE,IAAI,CAAC,SAAS,OAAO,CAAC,SAAS,iBAAiB,CAAC,CAAC;QAElE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;SACvC;KACF;SAAM;QACL,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,aAAa,GAA8B,KAAK,CAAC,QAAqC,CAAC;IAE7F,IAAI,CAAC,aAAa,IAAI,CAAC,2BAA2B,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;QAC5E,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAQ,KAAmB,CAAC,IAAI,KAAK,WAAW,CAAC;AACnD,CAAC;AAED,SAAS,2BAA2B,CAClC,iBAAsB;IAEtB,OAAO,OAAO,CAAC,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,UAAU,CAAC,CAAC;AAChD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationOptions, OperationRequest } from \"@azure/core-client\";\nimport { PipelineResponse, RestError } from \"@azure/core-rest-pipeline\";\nimport { AzureLogger } from \"@azure/logger\";\nimport { TableServiceError } from \"../generated\";\n\nexport type TableServiceErrorResponse = PipelineResponse & {\n /**\n * The parsed HTTP response headers.\n */\n parsedHeaders?: Record<string, unknown>;\n /**\n * The response body as parsed JSON or XML.\n */\n parsedBody: TableServiceError;\n /**\n * The request that generated the response.\n */\n request: OperationRequest;\n};\n\nexport function handleTableAlreadyExists(\n error: unknown,\n options: OperationOptions & { tableName?: string; logger?: AzureLogger } = {}\n): void {\n const responseError = getErrorResponse(error);\n if (\n responseError &&\n responseError.status === 409 &&\n responseError.parsedBody.odataError?.code === \"TableAlreadyExists\"\n ) {\n options.logger?.info(`Table ${options.tableName} already Exists`);\n\n if (options.onResponse) {\n options.onResponse(responseError, {});\n }\n } else {\n throw error;\n }\n}\n\nfunction getErrorResponse(error: unknown): TableServiceErrorResponse | undefined {\n if (!isRestError(error)) {\n return undefined;\n }\n\n const errorResponse: TableServiceErrorResponse = error.response as TableServiceErrorResponse;\n\n if (!errorResponse || !isTableServiceErrorResponse(errorResponse.parsedBody)) {\n return undefined;\n }\n\n return errorResponse;\n}\n\nfunction isRestError(error: unknown): error is RestError {\n return (error as RestError).name === \"RestError\";\n}\n\nfunction isTableServiceErrorResponse(\n errorResponseBody: any\n): errorResponseBody is TableServiceError {\n return Boolean(errorResponseBody?.odataError);\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { createSpanFunction } from "@azure/core-tracing";
3
+ import { createTracingClient } from "@azure/core-tracing";
4
4
  /**
5
- * Creates a span using the global tracer.
5
+ * A tracing client that can be used to manage spans.
6
6
  * @internal
7
7
  */
8
- export const createSpan = createSpanFunction({
9
- packagePrefix: "Azure.Data.Tables",
8
+ export const tracingClient = createTracingClient({
10
9
  namespace: "Microsoft.Data.Tables",
10
+ packageName: "@azure/data-tables",
11
+ packageVersion: "13.1.0",
11
12
  });
12
13
  //# sourceMappingURL=tracing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/utils/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC;IAC3C,aAAa,EAAE,mBAAmB;IAClC,SAAS,EAAE,uBAAuB;CACnC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createSpanFunction } from \"@azure/core-tracing\";\n\n/**\n * Creates a span using the global tracer.\n * @internal\n */\nexport const createSpan = createSpanFunction({\n packagePrefix: \"Azure.Data.Tables\",\n namespace: \"Microsoft.Data.Tables\",\n});\n"]}
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/utils/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;IAC/C,SAAS,EAAE,uBAAuB;IAClC,WAAW,EAAE,oBAAoB;IACjC,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createTracingClient } from \"@azure/core-tracing\";\n\n/**\n * A tracing client that can be used to manage spans.\n * @internal\n */\nexport const tracingClient = createTracingClient({\n namespace: \"Microsoft.Data.Tables\",\n packageName: \"@azure/data-tables\",\n packageVersion: \"13.1.0\",\n});\n"]}