@pi-r/azure 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/index.js CHANGED
@@ -60,7 +60,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
60
60
  break;
61
61
  }
62
62
  const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
63
- const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure container" /* ERR_AZURE.CONFIGURE_CONTAINER */, bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
63
+ const setAccessPolicy = async () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure container" /* ERR_AZURE.CONFIGURE_CONTAINER */, bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
64
64
  if (await containerClient.exists().catch(() => false)) {
65
65
  if (access) {
66
66
  await setAccessPolicy();
@@ -95,7 +95,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
95
95
  });
96
96
  }
97
97
  exports.createBucketV2 = createBucketV2;
98
- function setBucketWebsite(credential, bucket, options, service = 'azure') {
98
+ async function setBucketWebsite(credential, bucket, options, service = 'azure') {
99
99
  const staticWebsite = { enabled: true };
100
100
  const { indexPage, indexPath, errorPath } = options;
101
101
  if ((0, types_1.isString)(indexPage)) {
@@ -118,7 +118,7 @@ function setBucketWebsite(credential, bucket, options, service = 'azure') {
118
118
  });
119
119
  }
120
120
  exports.setBucketWebsite = setBucketWebsite;
121
- function deleteObjects(credential, Bucket, service) {
121
+ async function deleteObjects(credential, Bucket, service) {
122
122
  return deleteObjectsV2.call(this, credential, Bucket, true, service);
123
123
  }
124
124
  exports.deleteObjects = deleteObjects;
@@ -129,7 +129,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
129
129
  const tasks = [];
130
130
  let fileCount = 0;
131
131
  for await (const blob of containerClient.listBlobsFlat({ includeUncommitedBlobs: true })) {
132
- if (!recursive && blob.name.indexOf('/') !== -1) {
132
+ if (!recursive && blob.name.includes('/')) {
133
133
  continue;
134
134
  }
135
135
  tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => { --fileCount; }));
@@ -157,7 +157,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
157
157
  const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
158
158
  let client;
159
159
  const createClient = (name, table) => {
160
- client || (client = createDatabaseClient.call(this, length === 1 ? credential : { ...credential }));
160
+ client || (client = createDatabaseClient.call(this, credential));
161
161
  return client.database(name).container(table);
162
162
  };
163
163
  const closeClient = () => client?.dispose();
@@ -168,18 +168,17 @@ async function executeBatchQuery(credential, batch, sessionKey) {
168
168
  closeClient();
169
169
  throw (0, util_1.formatError)(item, name ? "Missing database table" /* ERR_DB.TABLE */ : "Missing database name" /* ERR_DB.NAME */);
170
170
  }
171
- const renewCache = ignoreCache === 0;
172
171
  const getCache = (value) => {
173
- if (ignoreCache === 1) {
174
- return;
172
+ if (ignoreCache !== 1) {
173
+ cacheValue.renewCache = ignoreCache === 0;
174
+ return this.getQueryResult(service, credential, value, cacheValue);
175
175
  }
176
- cacheValue.renewCache = renewCache;
177
- return this.getQueryResult(service, credential, value, cacheValue);
178
176
  };
179
- let rows, queryString = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache ? name + '_' + table + '_' : '';
177
+ cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
178
+ let rows, queryString = caching && ignoreCache !== true ? name + '_' + table + '_' : '';
180
179
  if (storedProcedureId && params) {
181
180
  const { options } = item;
182
- if (queryString && (rows = getCache(queryString += Module.asString(partitionKey) + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
181
+ if (queryString && (rows = getCache(queryString += Module.asString(partitionKey, true) + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
183
182
  result[i] = rows;
184
183
  continue;
185
184
  }
@@ -191,7 +190,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
191
190
  else if (id) {
192
191
  const { options } = item;
193
192
  if (queryString) {
194
- queryString += Module.asString(partitionKey) + '_' + id + Module.asString(options, true);
193
+ queryString += Module.asString(partitionKey, true) + '_' + id + Module.asString(options, true);
195
194
  if (!update && (rows = getCache(queryString))) {
196
195
  result[i] = rows;
197
196
  continue;
@@ -203,20 +202,26 @@ async function executeBatchQuery(credential, batch, sessionKey) {
203
202
  rows = [resource];
204
203
  }
205
204
  }
206
- else if (query) {
205
+ else {
207
206
  let { options } = item;
207
+ if (partitionKey) {
208
+ (options || (options = {})).partitionKey = partitionKey;
209
+ }
208
210
  if (limit > 0) {
209
211
  (options || (options = {})).maxItemCount = limit;
210
212
  }
211
- if (queryString && (rows = getCache(queryString += Module.asString(query) + Module.asString(options, true)))) {
212
- result[i] = rows;
213
- continue;
213
+ if (query || (0, types_1.isPlainObject)(options)) {
214
+ if (queryString && (rows = getCache(queryString += (query ? Module.asString(query, true) : '') + Module.asString(options, true)))) {
215
+ result[i] = rows;
216
+ continue;
217
+ }
218
+ const items = createClient(name, table).items;
219
+ ({ resources: rows } = await (query ? items.query(query, options).fetchAll() : items.readAll(options).fetchAll()));
220
+ }
221
+ else {
222
+ closeClient();
223
+ throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
214
224
  }
215
- rows = (await createClient(name, table).items.query(query, options).fetchAll()).resources;
216
- }
217
- else {
218
- closeClient();
219
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
220
225
  }
221
226
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
222
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
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.7.0",
24
- "@e-mc/module": "^0.7.0",
25
- "@e-mc/types": "^0.7.0",
23
+ "@e-mc/cloud": "^0.8.1",
24
+ "@e-mc/module": "^0.8.1",
25
+ "@e-mc/types": "^0.8.1",
26
26
  "@azure/cosmos": "^4.0.0",
27
27
  "@azure/identity": "^4.0.0",
28
28
  "@azure/storage-blob": "^12.17.0"
package/upload/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
- const fs = require("fs");
5
4
  const util_1 = require("@e-mc/cloud/util");
6
5
  const types_1 = require("@e-mc/types");
7
6
  const Module = require("@e-mc/module");
@@ -28,7 +27,7 @@ function upload(credential, service = 'azure') {
28
27
  cleanup();
29
28
  callback(err);
30
29
  };
31
- const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
30
+ const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err, service, bucket);
32
31
  const configBucket = admin.configBucket;
33
32
  if (!BUCKET_SESSION.has(bucket)) {
34
33
  const bucketAcl = admin.publicRead ? 'blob' : admin.acl;
@@ -84,15 +83,10 @@ function upload(credential, service = 'azure') {
84
83
  const Body = [data.buffer];
85
84
  const ContentType = [contentType];
86
85
  if (fileGroup) {
87
- for (const [content, ext, localFile] of fileGroup) {
88
- try {
89
- Body.push(typeof content === 'string' ? fs.readFileSync(content) : content);
90
- Key.push(ext === '.map' && localFile ? path.basename(localFile) : filename + ext);
91
- }
92
- catch (err) {
93
- addLog(err);
94
- }
95
- }
86
+ const [key, body, type] = (0, util_1.createKeyAndBody)(filename, fileGroup, addLog);
87
+ Key.push(...key);
88
+ Body.push(...body);
89
+ ContentType.push(...type);
96
90
  }
97
91
  for (let i = 0; i < Key.length; ++i) {
98
92
  const first = i === 0;