@pi-r/oci 0.6.7 → 0.7.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/README.md +3 -6
- package/client/index.js +12 -14
- package/package.json +8 -8
- package/types/index.d.ts +19 -0
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -11,27 +11,25 @@ function validateStorage(credential) {
|
|
|
11
11
|
}
|
|
12
12
|
exports.validateStorage = validateStorage;
|
|
13
13
|
function validateDatabase(credential, data) {
|
|
14
|
-
return !!(data.table && (credential.
|
|
14
|
+
return !!(data.table && (credential.user && credential.password && (credential.connectString || credential.connectionString) || credential.poolAlias));
|
|
15
15
|
}
|
|
16
16
|
exports.validateDatabase = validateDatabase;
|
|
17
17
|
function setStorageCredential(credential) {
|
|
18
|
-
var _a;
|
|
19
18
|
const { endpoint, namespace, region } = credential;
|
|
20
19
|
if (endpoint) {
|
|
21
|
-
credential.region
|
|
20
|
+
credential.region ||= /([^.]+)\.oraclecloud\.com$/.exec(endpoint)?.[1];
|
|
22
21
|
}
|
|
23
22
|
else if (namespace && region) {
|
|
24
|
-
credential.endpoint
|
|
23
|
+
credential.endpoint ||= `https://${namespace}.compat.objectstorage.${region}.oraclecloud.com`;
|
|
24
|
+
}
|
|
25
|
+
if (namespace) {
|
|
26
|
+
delete credential.namespace;
|
|
25
27
|
}
|
|
26
28
|
credential.s3ForcePathStyle = true;
|
|
27
29
|
credential.signatureVersion = 'v4';
|
|
28
30
|
}
|
|
29
31
|
exports.setStorageCredential = setStorageCredential;
|
|
30
32
|
async function createDatabaseClient(credential) {
|
|
31
|
-
if (credential.username) {
|
|
32
|
-
credential.user || (credential.user = credential.username);
|
|
33
|
-
delete credential.username;
|
|
34
|
-
}
|
|
35
33
|
oracle_1.initOracleClient.call(this, credential, this.logType.CLOUD);
|
|
36
34
|
return oracledb.getConnection(credential);
|
|
37
35
|
}
|
|
@@ -72,7 +70,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
72
70
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
73
71
|
let client;
|
|
74
72
|
const createClient = async () => createDatabaseClient.call(this, credential);
|
|
75
|
-
const closeClient = async () => client
|
|
73
|
+
const closeClient = async () => client?.close();
|
|
76
74
|
for (let i = 0; i < length; ++i) {
|
|
77
75
|
const item = batch[i];
|
|
78
76
|
const { service, table = '', id, query, ignoreCache } = item;
|
|
@@ -98,7 +96,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
98
96
|
continue;
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
|
-
const db = await (client
|
|
99
|
+
const db = await (client ||= await createClient()).getSodaDatabase().openCollection(table);
|
|
102
100
|
if (!db) {
|
|
103
101
|
closeClient();
|
|
104
102
|
throw (0, util_1.formatError)(item, "Missing database table");
|
|
@@ -150,7 +148,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
150
148
|
result[i] = rows;
|
|
151
149
|
continue;
|
|
152
150
|
}
|
|
153
|
-
const db = await (client
|
|
151
|
+
const db = await (client ||= await createClient()).getSodaDatabase().openCollection(table);
|
|
154
152
|
if (!db) {
|
|
155
153
|
closeClient();
|
|
156
154
|
throw (0, util_1.formatError)(item, "Missing database table");
|
|
@@ -185,14 +183,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
185
183
|
}
|
|
186
184
|
else {
|
|
187
185
|
const { params, options } = item;
|
|
188
|
-
if (
|
|
186
|
+
if (options?.maxRows && isNaN(maxRows)) {
|
|
189
187
|
maxRows = options.maxRows;
|
|
190
188
|
}
|
|
191
189
|
if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows > 0 ? maxRows : '')))) {
|
|
192
190
|
result[i] = rows;
|
|
193
191
|
continue;
|
|
194
192
|
}
|
|
195
|
-
client
|
|
193
|
+
client ||= await createClient();
|
|
196
194
|
const executeOptions = { ...options, outFormat: 4002, maxRows, resultSet: false, autoCommit: true };
|
|
197
195
|
if (item.streamRow) {
|
|
198
196
|
rows = [];
|
|
@@ -216,7 +214,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
216
214
|
stream.destroy();
|
|
217
215
|
});
|
|
218
216
|
})
|
|
219
|
-
.catch(err => {
|
|
217
|
+
.catch((err) => {
|
|
220
218
|
closeClient();
|
|
221
219
|
throw (0, util_1.formatError)(item, err instanceof Error ? err.message : "Missing database query");
|
|
222
220
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oci",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Oracle (OCI) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -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.
|
|
24
|
-
"@e-mc/module": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"@pi-r/aws": "^0.
|
|
27
|
-
"@pi-r/oracle": "^0.
|
|
28
|
-
"aws-sdk": "^2.
|
|
29
|
-
"oracledb": "^6.
|
|
23
|
+
"@e-mc/cloud": "^0.9.2",
|
|
24
|
+
"@e-mc/module": "^0.9.2",
|
|
25
|
+
"@e-mc/types": "^0.9.2",
|
|
26
|
+
"@pi-r/aws": "^0.7.1",
|
|
27
|
+
"@pi-r/oracle": "^0.7.1",
|
|
28
|
+
"aws-sdk": "^2.1628.0",
|
|
29
|
+
"oracledb": "^6.5.1"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
+
|
|
3
|
+
import type { BindParameters, ConnectionAttributes, ExecuteOptions, InitialiseOptions } from 'oracledb';
|
|
4
|
+
import type { ConfigurationOptions } from 'aws-sdk/lib/core';
|
|
5
|
+
|
|
6
|
+
export type OCIStorage = CloudStorage<OCIStorageCredential, "oci">;
|
|
7
|
+
|
|
8
|
+
export interface OCIStorageCredential extends ConfigurationOptions {
|
|
9
|
+
namespace?: string;
|
|
10
|
+
endpoint?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OCIDatabaseQuery extends CloudDatabase<PlainObject | string, ExecuteOptions, StandardMap, BindParameters, OCIDatabaseCredential> {
|
|
14
|
+
source: "cloud";
|
|
15
|
+
service: "oci";
|
|
16
|
+
streamRow?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface OCIDatabaseCredential extends ConnectionAttributes, InitialiseOptions {}
|