@pi-r/azure 0.8.0 → 0.8.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.
- package/client/index.js +22 -13
- package/package.json +30 -30
- package/types/index.d.ts +2 -1
package/client/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const util_1 = require("@e-mc/cloud/util");
|
|
|
20
20
|
const types_1 = require("@e-mc/types");
|
|
21
21
|
function validateStorage(credential) {
|
|
22
22
|
const env = process.env;
|
|
23
|
-
if (credential.accountName && credential.accountKey || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
|
|
23
|
+
if (credential.accountName && (credential.accountKey || credential.accountSas) || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
return Cloud.enabled("process.env.apply") && !!((credential.connectionString = env.AZURE_STORAGE_CONNECTION_STRING) || (credential.sharedAccessSignature = env.AZURE_STORAGE_SAS_TOKEN) || (credential.accountName = env.AZURE_STORAGE_ACCOUNT) && (credential.accountKey = env.AZURE_STORAGE_KEY));
|
|
@@ -29,14 +29,17 @@ function validateDatabase(credential, data) {
|
|
|
29
29
|
return !!(data.name && data.table && (credential.endpoint && credential.key || credential.username && credential.password && (credential.tenantId && credential.clientId || (credential.tenantId = process.env.AZURE_TENANT_ID) && (credential.clientId = process.env.AZURE_CLIENT_ID)) || Cloud.enabled("process.env.apply") && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
|
|
30
30
|
}
|
|
31
31
|
function createStorageClient(credential) {
|
|
32
|
-
let { accountName, accountKey, connectionString, sharedAccessSignature } = credential;
|
|
32
|
+
let { accountName, accountKey, accountSas = '', connectionString, sharedAccessSignature } = credential;
|
|
33
33
|
if (connectionString) {
|
|
34
34
|
if (!accountName) {
|
|
35
35
|
credential.accountName = /AccountName=([^;]+);/.exec(connectionString)?.[1];
|
|
36
36
|
}
|
|
37
37
|
return storage.BlobServiceClient.fromConnectionString(connectionString);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
if (accountSas && !accountSas.startsWith('?')) {
|
|
40
|
+
accountSas = '?' + accountSas;
|
|
41
|
+
}
|
|
42
|
+
const url = `https://${accountName || process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net${accountSas}`;
|
|
40
43
|
if (sharedAccessSignature) {
|
|
41
44
|
if (accountName) {
|
|
42
45
|
if (!Cloud.isURL(sharedAccessSignature)) {
|
|
@@ -48,7 +51,7 @@ function createStorageClient(credential) {
|
|
|
48
51
|
}
|
|
49
52
|
return new storage.BlobServiceClient(sharedAccessSignature);
|
|
50
53
|
}
|
|
51
|
-
return new storage.BlobServiceClient(url, accountName && accountKey ? new storage.StorageSharedKeyCredential(accountName, accountKey) : new identity.DefaultAzureCredential());
|
|
54
|
+
return new storage.BlobServiceClient(url, accountName && accountSas ? new storage.AnonymousCredential() : accountName && accountKey ? new storage.StorageSharedKeyCredential(accountName, accountKey) : new identity.DefaultAzureCredential());
|
|
52
55
|
}
|
|
53
56
|
function createDatabaseClient(credential) {
|
|
54
57
|
if (credential.username && credential.password && credential.tenantId && credential.clientId) {
|
|
@@ -183,7 +186,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
183
186
|
const closeClient = () => client?.dispose();
|
|
184
187
|
for (let i = 0; i < length; ++i) {
|
|
185
188
|
const item = batch[i];
|
|
186
|
-
const { service, name, table, id, query, storedProcedureId, partitionKey = null, params, limit = 0,
|
|
189
|
+
const { service, name, table, id, query, storedProcedureId, partitionKey = null, params, limit = 0, ignoreCache } = item;
|
|
187
190
|
if (!name || !table) {
|
|
188
191
|
closeClient();
|
|
189
192
|
throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
|
|
@@ -202,7 +205,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
else if (id) {
|
|
205
|
-
const { options } = item;
|
|
208
|
+
const { update, options } = item;
|
|
206
209
|
if (queryString) {
|
|
207
210
|
queryString += (partitionKey ? Cloud.asString(partitionKey, true) : '') + '_' + id + '_' + Cloud.asString(options, true);
|
|
208
211
|
if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
|
|
@@ -217,19 +220,25 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
222
|
else {
|
|
220
|
-
|
|
223
|
+
const { update, options = {} } = item;
|
|
221
224
|
if (partitionKey) {
|
|
222
|
-
|
|
225
|
+
options.partitionKey = partitionKey;
|
|
223
226
|
}
|
|
224
227
|
if (limit > 0) {
|
|
225
|
-
|
|
228
|
+
options.maxItemCount = limit;
|
|
226
229
|
}
|
|
227
|
-
if (query ||
|
|
228
|
-
if (queryString
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
if (query || Object.keys(options).length > 0) {
|
|
231
|
+
if (queryString) {
|
|
232
|
+
queryString += (query ? Cloud.asString(query, true) : '') + Cloud.asString(options, true);
|
|
233
|
+
if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
|
|
234
|
+
result[i] = rows;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
231
237
|
}
|
|
232
238
|
const items = createClient(name, table).items;
|
|
239
|
+
if (update) {
|
|
240
|
+
await items.upsert(update, { accessCondition: options.accessCondition, sessionToken: options.sessionToken, initialHeaders: options.initialHeaders, priorityLevel: options.priorityLevel });
|
|
241
|
+
}
|
|
233
242
|
({ resources: rows } = await (query ? items.query(query, options).fetchAll() : items.readAll(options).fetchAll()));
|
|
234
243
|
}
|
|
235
244
|
else {
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Azure cloud functions for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/cloud/azure"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.10.
|
|
24
|
-
"@e-mc/module": "^0.10.
|
|
25
|
-
"@e-mc/types": "^0.10.
|
|
26
|
-
"@azure/cosmos": "^4.
|
|
27
|
-
"@azure/identity": "^4.4.1",
|
|
28
|
-
"@azure/storage-blob": "^12.24.0"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/azure",
|
|
3
|
+
"version": "0.8.2",
|
|
4
|
+
"description": "Azure cloud functions for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/cloud/azure"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/cloud": "^0.10.2",
|
|
24
|
+
"@e-mc/module": "^0.10.2",
|
|
25
|
+
"@e-mc/types": "^0.10.2",
|
|
26
|
+
"@azure/cosmos": "^4.1.1",
|
|
27
|
+
"@azure/identity": "^4.4.1",
|
|
28
|
+
"@azure/storage-blob": "^12.24.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ export type AzureStorage = CloudStorage<AzureStorageCredential, "azure" | "az">;
|
|
|
7
7
|
export interface AzureStorageCredential {
|
|
8
8
|
accountName?: string;
|
|
9
9
|
accountKey?: string;
|
|
10
|
+
accountSas?: string;
|
|
10
11
|
connectionString?: string;
|
|
11
12
|
sharedAccessSignature?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export interface AzureDatabaseQuery<T = FeedOptions | RequestOptions> extends CloudDatabase<string | SqlQuerySpec, T,
|
|
15
|
+
export interface AzureDatabaseQuery<T = FeedOptions | RequestOptions, U = PatchRequestBody | PlainObject> extends CloudDatabase<string | SqlQuerySpec, T, U, unknown[], AzureDatabaseCredential> {
|
|
15
16
|
source: "cloud";
|
|
16
17
|
service: "azure" | "az";
|
|
17
18
|
partitionKey?: PartitionKey;
|