@pi-r/azure 0.6.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
@@ -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,14 +168,14 @@ 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
172
  if (ignoreCache !== 1) {
174
- cacheValue.renewCache = renewCache;
173
+ cacheValue.renewCache = ignoreCache === 0;
175
174
  return this.getQueryResult(service, credential, value, cacheValue);
176
175
  }
177
176
  };
178
- 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 + '_' : '';
179
179
  if (storedProcedureId && params) {
180
180
  const { options } = item;
181
181
  if (queryString && (rows = getCache(queryString += Module.asString(partitionKey, true) + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
@@ -202,20 +202,26 @@ async function executeBatchQuery(credential, batch, sessionKey) {
202
202
  rows = [resource];
203
203
  }
204
204
  }
205
- else if (query) {
205
+ else {
206
206
  let { options } = item;
207
+ if (partitionKey) {
208
+ (options || (options = {})).partitionKey = partitionKey;
209
+ }
207
210
  if (limit > 0) {
208
211
  (options || (options = {})).maxItemCount = limit;
209
212
  }
210
- if (queryString && (rows = getCache(queryString += Module.asString(query, true) + Module.asString(options, true)))) {
211
- result[i] = rows;
212
- 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 */);
213
224
  }
214
- rows = (await createClient(name, table).items.query(query, options).fetchAll()).resources;
215
- }
216
- else {
217
- closeClient();
218
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
219
225
  }
220
226
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
221
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.6.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.8.0",
24
- "@e-mc/module": "^0.8.0",
25
- "@e-mc/types": "^0.8.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");
@@ -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;