@pi-r/azure 0.3.0 → 0.5.0
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 +4 -4
- package/package.json +7 -7
- package/upload/index.js +23 -5
package/client/index.js
CHANGED
|
@@ -163,7 +163,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
163
163
|
const closeClient = () => client?.dispose();
|
|
164
164
|
for (let i = 0; i < length; ++i) {
|
|
165
165
|
const item = batch[i];
|
|
166
|
-
const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
|
|
166
|
+
const { service, name, table, id, query, storedProcedureId, partitionKey = null, params, limit = 0, update, ignoreCache } = item;
|
|
167
167
|
if (!name || !table) {
|
|
168
168
|
closeClient();
|
|
169
169
|
throw (0, util_1.formatError)(item, name ? "Missing database table" /* ERR_DB.TABLE */ : "Missing database name" /* ERR_DB.NAME */);
|
|
@@ -179,7 +179,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
179
179
|
let rows, queryString = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache ? name + '_' + table + '_' : '';
|
|
180
180
|
if (storedProcedureId && params) {
|
|
181
181
|
const { options } = item;
|
|
182
|
-
if (queryString && (rows = getCache(queryString += (partitionKey
|
|
182
|
+
if (queryString && (rows = getCache(queryString += Module.asString(partitionKey) + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
|
|
183
183
|
result[i] = rows;
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
@@ -191,7 +191,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
191
191
|
else if (id) {
|
|
192
192
|
const { options } = item;
|
|
193
193
|
if (queryString) {
|
|
194
|
-
queryString += (partitionKey
|
|
194
|
+
queryString += Module.asString(partitionKey) + '_' + id + Module.asString(options, true);
|
|
195
195
|
if (!update && (rows = getCache(queryString))) {
|
|
196
196
|
result[i] = rows;
|
|
197
197
|
continue;
|
|
@@ -208,7 +208,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
208
208
|
if (limit > 0) {
|
|
209
209
|
(options || (options = {})).maxItemCount = limit;
|
|
210
210
|
}
|
|
211
|
-
if (queryString && (rows = getCache(queryString += Module.asString(query
|
|
211
|
+
if (queryString && (rows = getCache(queryString += Module.asString(query) + Module.asString(options, true)))) {
|
|
212
212
|
result[i] = rows;
|
|
213
213
|
continue;
|
|
214
214
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Azure cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/module": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"@azure/cosmos": "^
|
|
27
|
-
"@azure/identity": "^
|
|
28
|
-
"@azure/storage-blob": "^12.
|
|
23
|
+
"@e-mc/cloud": "^0.7.0",
|
|
24
|
+
"@e-mc/module": "^0.7.0",
|
|
25
|
+
"@e-mc/types": "^0.7.0",
|
|
26
|
+
"@azure/cosmos": "^4.0.0",
|
|
27
|
+
"@azure/identity": "^4.0.0",
|
|
28
|
+
"@azure/storage-blob": "^12.17.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/upload/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function upload(credential, service = 'azure') {
|
|
|
15
15
|
return async (data, callback) => {
|
|
16
16
|
var _a, _b;
|
|
17
17
|
const { bucket, localUri } = data;
|
|
18
|
-
const { pathname = '', fileGroup, contentType, metadata, endpoint, admin = {}, overwrite, options } = data.upload;
|
|
18
|
+
const { pathname = '', fileGroup, contentType, metadata, tags, endpoint, admin = {}, overwrite, options } = data.upload;
|
|
19
19
|
const containerClient = blobServiceClient.getContainerClient(bucket);
|
|
20
20
|
let filename = data.upload.filename || path.basename(localUri), bucketKey;
|
|
21
21
|
const cleanup = () => {
|
|
@@ -28,15 +28,29 @@ function upload(credential, service = 'azure') {
|
|
|
28
28
|
cleanup();
|
|
29
29
|
callback(err);
|
|
30
30
|
};
|
|
31
|
+
const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
|
|
32
|
+
const configBucket = admin.configBucket;
|
|
31
33
|
if (!BUCKET_SESSION.has(bucket)) {
|
|
32
34
|
const bucketAcl = admin.publicRead ? 'blob' : admin.acl;
|
|
33
|
-
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl,
|
|
35
|
+
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, configBucket?.create));
|
|
34
36
|
if (!await response) {
|
|
35
37
|
errorResponse(null);
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
40
|
BUCKET_SESSION.add(bucket);
|
|
39
41
|
}
|
|
42
|
+
let retentionPolicy = configBucket?.retentionPolicy;
|
|
43
|
+
if (retentionPolicy) {
|
|
44
|
+
if (!Array.isArray(retentionPolicy)) {
|
|
45
|
+
retentionPolicy = [retentionPolicy];
|
|
46
|
+
}
|
|
47
|
+
containerClient.setAccessPolicy('container', retentionPolicy)
|
|
48
|
+
.then(() => {
|
|
49
|
+
const { expiresOn, startsOn, permissions } = retentionPolicy[0].accessPolicy;
|
|
50
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (retention policy)', bucket], expiresOn ? expiresOn.toLocaleString() + ' (expires)' : startsOn ? startsOn.toLocaleString() + ' (starts)' : permissions, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
51
|
+
})
|
|
52
|
+
.catch(err => addLog(err));
|
|
53
|
+
}
|
|
40
54
|
if (!overwrite) {
|
|
41
55
|
try {
|
|
42
56
|
const current = filename;
|
|
@@ -69,7 +83,6 @@ function upload(credential, service = 'azure') {
|
|
|
69
83
|
const Key = [filename];
|
|
70
84
|
const Body = [data.buffer];
|
|
71
85
|
const ContentType = [contentType];
|
|
72
|
-
const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
|
|
73
86
|
if (fileGroup) {
|
|
74
87
|
for (const [content, ext, localFile] of fileGroup) {
|
|
75
88
|
try {
|
|
@@ -91,8 +104,13 @@ function upload(credential, service = 'azure') {
|
|
|
91
104
|
}
|
|
92
105
|
const blobName = Module.joinPath(pathname, Key[i]);
|
|
93
106
|
const params = { ...options, abortSignal: this.signal };
|
|
94
|
-
if (first
|
|
95
|
-
|
|
107
|
+
if (first) {
|
|
108
|
+
if ((0, types_1.isPlainObject)(metadata)) {
|
|
109
|
+
params.metadata = metadata;
|
|
110
|
+
}
|
|
111
|
+
if ((0, types_1.isPlainObject)(tags)) {
|
|
112
|
+
params.tags = tags;
|
|
113
|
+
}
|
|
96
114
|
}
|
|
97
115
|
(_b = (params.blobHTTPHeaders || (params.blobHTTPHeaders = {}))).blobContentType || (_b.blobContentType = ContentType[i]);
|
|
98
116
|
containerClient.getBlockBlobClient(blobName).upload(Body[i], Body[i].byteLength, params)
|