@pi-r/azure 0.2.9 → 0.2.11
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/LICENSE +1 -1
- package/README.md +1 -1
- package/client/index.js +4 -3
- package/package.json +4 -4
- package/types/index.d.ts +24 -0
- package/upload/index.js +4 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -19,16 +19,17 @@ function validateDatabase(credential, data) {
|
|
|
19
19
|
}
|
|
20
20
|
exports.validateDatabase = validateDatabase;
|
|
21
21
|
function createStorageClient(credential) {
|
|
22
|
+
var _a, _b;
|
|
22
23
|
let packageName = '';
|
|
23
24
|
try {
|
|
24
25
|
const { BlobServiceClient, StorageSharedKeyCredential } = require(packageName = '@azure/storage-blob');
|
|
25
26
|
const { accountName, accountKey, connectionString, sharedAccessSignature } = credential;
|
|
26
27
|
if (connectionString) {
|
|
27
|
-
credential.accountName || (credential.accountName = /AccountName=([^;]+);/.exec(connectionString)
|
|
28
|
+
credential.accountName || (credential.accountName = (_a = /AccountName=([^;]+);/.exec(connectionString)) === null || _a === void 0 ? void 0 : _a[1]);
|
|
28
29
|
return BlobServiceClient.fromConnectionString(connectionString);
|
|
29
30
|
}
|
|
30
31
|
if (sharedAccessSignature) {
|
|
31
|
-
credential.accountName || (credential.accountName = /^https:\/\/([a-z\d]+)\./.exec(sharedAccessSignature)
|
|
32
|
+
credential.accountName || (credential.accountName = (_b = /^https:\/\/([a-z\d]+)\./.exec(sharedAccessSignature)) === null || _b === void 0 ? void 0 : _b[1]);
|
|
32
33
|
return new BlobServiceClient(sharedAccessSignature);
|
|
33
34
|
}
|
|
34
35
|
let azureCredential;
|
|
@@ -170,7 +171,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
170
171
|
client || (client = createDatabaseClient.call(this, length === 1 ? credential : { ...credential }));
|
|
171
172
|
return client.database(name).container(table);
|
|
172
173
|
};
|
|
173
|
-
const closeClient = () => client
|
|
174
|
+
const closeClient = () => client === null || client === void 0 ? void 0 : client.dispose();
|
|
174
175
|
for (let i = 0; i < length; ++i) {
|
|
175
176
|
const item = batch[i];
|
|
176
177
|
const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Azure cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.5.
|
|
24
|
-
"@e-mc/module": "^0.5.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
23
|
+
"@e-mc/cloud": "^0.5.6",
|
|
24
|
+
"@e-mc/module": "^0.5.6",
|
|
25
|
+
"@e-mc/types": "^0.5.6",
|
|
26
26
|
"@azure/cosmos": "^3.17.3",
|
|
27
27
|
"@azure/identity": "^3.4.2",
|
|
28
28
|
"@azure/storage-blob": "^12.17.0"
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
+
|
|
3
|
+
import type { CosmosClientOptions, FeedOptions, PartitionKey, PatchRequestBody, RequestOptions, SqlQuerySpec } from '@azure/cosmos';
|
|
4
|
+
|
|
5
|
+
export type AzureStorage = CloudStorage<AzureStorageCredential, "azure" | "az">;
|
|
6
|
+
|
|
7
|
+
export interface AzureStorageCredential {
|
|
8
|
+
accountName?: string;
|
|
9
|
+
accountKey?: string;
|
|
10
|
+
connectionString?: string;
|
|
11
|
+
sharedAccessSignature?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AzureDatabaseQuery<T = FeedOptions | RequestOptions> extends CloudDatabase<string | SqlQuerySpec, T, PatchRequestBody, unknown[], AzureDatabaseCredential> {
|
|
15
|
+
source: "cloud";
|
|
16
|
+
service: "azure" | "az";
|
|
17
|
+
partitionKey?: PartitionKey;
|
|
18
|
+
storedProcedureId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AzureDatabaseCredential extends AuthValue, CosmosClientOptions {
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
clientId?: string;
|
|
24
|
+
}
|
package/upload/index.js
CHANGED
|
@@ -12,7 +12,8 @@ const getBucketKey = (credential, bucket, acl = '') => Module.asString(credentia
|
|
|
12
12
|
function upload(credential, service = 'azure') {
|
|
13
13
|
const blobServiceClient = client_1.createStorageClient.call(this, credential);
|
|
14
14
|
return async (data, callback) => {
|
|
15
|
-
var _a
|
|
15
|
+
var _a;
|
|
16
|
+
var _b, _c;
|
|
16
17
|
const { bucket, localUri } = data;
|
|
17
18
|
const { pathname = '', fileGroup, contentType, metadata, endpoint, admin = {}, overwrite, options } = data.upload;
|
|
18
19
|
const containerClient = blobServiceClient.getContainerClient(bucket);
|
|
@@ -29,7 +30,7 @@ function upload(credential, service = 'azure') {
|
|
|
29
30
|
};
|
|
30
31
|
if (!BUCKET_SESSION.has(bucket)) {
|
|
31
32
|
const bucketAcl = admin.publicRead ? 'blob' : admin.acl;
|
|
32
|
-
const response = BUCKET_RESPONSE[
|
|
33
|
+
const response = BUCKET_RESPONSE[_b = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_b] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, (_a = admin.configBucket) === null || _a === void 0 ? void 0 : _a.create));
|
|
33
34
|
if (!await response) {
|
|
34
35
|
errorResponse(null);
|
|
35
36
|
return;
|
|
@@ -93,7 +94,7 @@ function upload(credential, service = 'azure') {
|
|
|
93
94
|
if (first && metadata) {
|
|
94
95
|
params.metadata = metadata;
|
|
95
96
|
}
|
|
96
|
-
(
|
|
97
|
+
(_c = (params.blobHTTPHeaders || (params.blobHTTPHeaders = {}))).blobContentType || (_c.blobContentType = ContentType[i]);
|
|
97
98
|
containerClient.getBlockBlobClient(blobName).upload(Body[i], Body[i].byteLength, params)
|
|
98
99
|
.then(result => {
|
|
99
100
|
let requestUrl = result._response.request.url;
|