@pi-r/oci 0.6.2 → 0.6.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
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
@@ -1,7 +1,10 @@
1
- ### @pi-r/oci
1
+ # @pi-r/oci
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/cloud/oci.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/cloud/oci.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -88,7 +88,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
88
88
  if (id) {
89
89
  if (!table) {
90
90
  closeClient();
91
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
91
+ throw (0, util_1.formatError)(item, "Missing database table");
92
92
  }
93
93
  const update = item.update;
94
94
  if (queryString) {
@@ -101,7 +101,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
101
101
  const db = await (client || (client = await createClient())).getSodaDatabase().openCollection(table);
102
102
  if (!db) {
103
103
  closeClient();
104
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
104
+ throw (0, util_1.formatError)(item, "Missing database table");
105
105
  }
106
106
  const row = db.find().key(id);
107
107
  let document = await row.getOne();
@@ -140,36 +140,60 @@ async function executeBatchQuery(credential, batch, sessionKey) {
140
140
  }
141
141
  }
142
142
  else if (query) {
143
- let maxRows = typeof item.limit === 'number' ? Math.max(item.limit, 0) : undefined;
143
+ let maxRows = typeof item.limit === 'number' ? item.limit : NaN;
144
144
  if ((0, types_1.isPlainObject)(query)) {
145
145
  if (!table) {
146
146
  closeClient();
147
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
147
+ throw (0, util_1.formatError)(item, "Missing database table");
148
148
  }
149
- if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows ? maxRows : '')))) {
149
+ if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows > 0 ? maxRows : '')))) {
150
150
  result[i] = rows;
151
151
  continue;
152
152
  }
153
153
  const db = await (client || (client = await createClient())).getSodaDatabase().openCollection(table);
154
154
  if (!db) {
155
155
  closeClient();
156
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
156
+ throw (0, util_1.formatError)(item, "Missing database table");
157
157
  }
158
- let operation = db.find().filter(query);
159
- if (maxRows) {
160
- operation = operation.limit(maxRows);
158
+ const tryQuery = async () => {
159
+ let operation = db.find().filter(query);
160
+ if (maxRows > 0) {
161
+ operation = operation.limit(maxRows);
162
+ }
163
+ return (await operation.getDocuments()).map(doc => doc.getContent());
164
+ };
165
+ try {
166
+ rows = await tryQuery();
167
+ }
168
+ catch (err) {
169
+ switch (err instanceof Error && err.code) {
170
+ case 'ORA-40820':
171
+ if (maxRows > 0) {
172
+ const limit = maxRows;
173
+ maxRows = 0;
174
+ rows = await tryQuery();
175
+ if (limit > rows.length) {
176
+ rows = rows.slice(0, limit);
177
+ }
178
+ this.addLog(types_1.STATUS_TYPE.WARN, err, service, Module.asString(query, true));
179
+ break;
180
+ }
181
+ default:
182
+ throw err;
183
+ }
161
184
  }
162
- rows = (await operation.getDocuments()).map(doc => doc.getContent());
163
185
  }
164
186
  else {
165
187
  const { params, options } = item;
166
- maxRows || (maxRows = options?.maxRows);
167
- if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows ? maxRows : '')))) {
188
+ if (options?.maxRows && isNaN(maxRows)) {
189
+ maxRows = options.maxRows;
190
+ }
191
+ if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows > 0 ? maxRows : '')))) {
168
192
  result[i] = rows;
169
193
  continue;
170
194
  }
171
195
  client || (client = await createClient());
172
- const executeOptions = { ...options, outFormat: 4002 /* OUT_FORMAT.OBJECT */, maxRows, resultSet: false, autoCommit: true };
196
+ const executeOptions = { ...options, outFormat: 4002, maxRows, resultSet: false, autoCommit: true };
173
197
  if (item.streamRow) {
174
198
  rows = [];
175
199
  await new Promise((resolve, reject) => {
@@ -194,7 +218,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
194
218
  })
195
219
  .catch(err => {
196
220
  closeClient();
197
- throw (0, util_1.formatError)(item, err instanceof Error ? err.message : "Missing database query" /* ERR_DB.QUERY */);
221
+ throw (0, util_1.formatError)(item, err instanceof Error ? err.message : "Missing database query");
198
222
  });
199
223
  }
200
224
  else {
@@ -204,7 +228,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
204
228
  }
205
229
  else {
206
230
  closeClient();
207
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
231
+ throw (0, util_1.formatError)(item, "Missing database query");
208
232
  }
209
233
  }
210
234
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
package/download/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../client");
2
+ const client_1 = require("@pi-r/oci");
4
3
  function download(credential, service = 'oci') {
5
4
  (0, client_1.setStorageCredential)(credential);
6
- return require('../../aws/download').call(this, credential, service);
5
+ return require("@pi-r/aws/download").call(this, credential, service);
7
6
  }
8
7
 
9
8
  module.exports = download;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oci",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "Oracle (OCI) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/cloud/oci"
13
13
  },
14
14
  "keywords": [
@@ -20,12 +20,12 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.8.2",
24
- "@e-mc/module": "^0.8.2",
25
- "@e-mc/types": "^0.8.2",
26
- "@pi-r/aws": "^0.6.2",
27
- "@pi-r/oracle": "^0.6.2",
28
- "aws-sdk": "^2.1545.0",
23
+ "@e-mc/cloud": "^0.8.6",
24
+ "@e-mc/module": "^0.8.6",
25
+ "@e-mc/types": "^0.8.6",
26
+ "@pi-r/aws": "^0.6.5",
27
+ "@pi-r/oracle": "^0.6.5",
28
+ "aws-sdk": "^2.1570.0",
29
29
  "oracledb": "^6.3.0"
30
30
  }
31
31
  }
package/upload/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../client");
2
+ const client_1 = require("@pi-r/oci");
4
3
  function upload(credential, service = 'oci') {
5
4
  (0, client_1.setStorageCredential)(credential);
6
- return require('../../aws/upload').call(this, credential, service);
5
+ return require("@pi-r/aws/upload").call(this, credential, service);
7
6
  }
8
7
 
9
8
  module.exports = upload;