@pi-r/oci 0.7.3 → 0.8.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 +29 -30
- package/download/index.js +5 -3
- package/package.json +8 -8
- package/upload/index.js +5 -3
package/client/index.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports.
|
|
2
|
+
exports.validateStorage = validateStorage;
|
|
3
|
+
exports.validateDatabase = validateDatabase;
|
|
4
|
+
exports.setStorageCredential = setStorageCredential;
|
|
5
|
+
exports.createDatabaseClient = createDatabaseClient;
|
|
6
|
+
exports.createBucket = createBucket;
|
|
7
|
+
exports.createBucketV2 = createBucketV2;
|
|
8
|
+
exports.setBucketPolicy = setBucketPolicy;
|
|
9
|
+
exports.setBucketWebsite = setBucketWebsite;
|
|
10
|
+
exports.deleteObjects = deleteObjects;
|
|
11
|
+
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
12
|
+
exports.executeQuery = executeQuery;
|
|
13
|
+
exports.executeBatchQuery = executeBatchQuery;
|
|
3
14
|
const oracledb = require("oracledb");
|
|
15
|
+
const Cloud = require("@e-mc/cloud");
|
|
16
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
4
17
|
const types_1 = require("@e-mc/types");
|
|
5
18
|
const aws_1 = require("@pi-r/aws");
|
|
6
19
|
const oracle_1 = require("@pi-r/oracle");
|
|
7
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
8
|
-
const Module = require("@e-mc/module");
|
|
9
20
|
function validateStorage(credential) {
|
|
10
21
|
return !!(credential.accessKeyId && credential.secretAccessKey && (credential.region && credential.namespace || credential.endpoint));
|
|
11
22
|
}
|
|
12
|
-
exports.validateStorage = validateStorage;
|
|
13
23
|
function validateDatabase(credential, data) {
|
|
14
|
-
return !!(data.table && (credential.user && credential.password && (credential.connectString || credential.connectionString) || credential.poolAlias));
|
|
24
|
+
return !!(data.table && (credential.user && credential.password && (credential.connectString || credential.connectionString) || credential.poolAlias || (0, oracle_1.getConfigObject)(credential.connectionString || credential.connectionString)));
|
|
15
25
|
}
|
|
16
|
-
exports.validateDatabase = validateDatabase;
|
|
17
26
|
function setStorageCredential(credential) {
|
|
18
27
|
const { endpoint, namespace, region } = credential;
|
|
19
28
|
if (endpoint) {
|
|
20
|
-
credential.region ||= /([^.]+)\.oraclecloud\.com
|
|
29
|
+
credential.region ||= /([^.]+)\.oraclecloud\.com$/i.exec(endpoint)?.[1];
|
|
21
30
|
}
|
|
22
31
|
else if (namespace && region) {
|
|
23
32
|
credential.endpoint ||= `https://${namespace}.compat.objectstorage.${region}.oraclecloud.com`;
|
|
@@ -28,58 +37,49 @@ function setStorageCredential(credential) {
|
|
|
28
37
|
credential.s3ForcePathStyle = true;
|
|
29
38
|
credential.signatureVersion = 'v4';
|
|
30
39
|
}
|
|
31
|
-
exports.setStorageCredential = setStorageCredential;
|
|
32
40
|
async function createDatabaseClient(credential) {
|
|
33
41
|
oracle_1.initOracleClient.call(this, credential, this.logType.CLOUD);
|
|
34
42
|
return oracledb.getConnection(credential);
|
|
35
43
|
}
|
|
36
|
-
exports.createDatabaseClient = createDatabaseClient;
|
|
37
44
|
async function createBucket(credential, bucket, publicRead) {
|
|
38
45
|
return aws_1.createBucketV2.call(this, credential, bucket, publicRead ? 'public-read' : undefined, undefined, 'oci');
|
|
39
46
|
}
|
|
40
|
-
exports.createBucket = createBucket;
|
|
41
47
|
async function createBucketV2(credential, bucket, ACL, options) {
|
|
42
48
|
return aws_1.createBucketV2.call(this, credential, bucket, ACL, options, 'oci');
|
|
43
49
|
}
|
|
44
|
-
exports.createBucketV2 = createBucketV2;
|
|
45
50
|
async function setBucketPolicy(credential, bucket, options) {
|
|
46
51
|
return aws_1.setBucketPolicy.call(this, credential, bucket, options, 'oci');
|
|
47
52
|
}
|
|
48
|
-
exports.setBucketPolicy = setBucketPolicy;
|
|
49
53
|
async function setBucketWebsite(credential, bucket, options) {
|
|
50
54
|
return aws_1.setBucketWebsite.call(this, credential, bucket, options, 'oci');
|
|
51
55
|
}
|
|
52
|
-
exports.setBucketWebsite = setBucketWebsite;
|
|
53
56
|
async function deleteObjects(credential, bucket) {
|
|
54
57
|
return deleteObjectsV2.call(this, credential, bucket, true);
|
|
55
58
|
}
|
|
56
|
-
exports.deleteObjects = deleteObjects;
|
|
57
59
|
async function deleteObjectsV2(credential, bucket, recursive = true) {
|
|
58
60
|
setStorageCredential(credential);
|
|
59
61
|
return aws_1.deleteObjectsV2.call(this, credential, bucket, recursive, 'oci');
|
|
60
62
|
}
|
|
61
|
-
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
62
63
|
async function executeQuery(credential, data, sessionKey) {
|
|
63
64
|
return (await executeBatchQuery.call(this, credential, [data], sessionKey))[0] || [];
|
|
64
65
|
}
|
|
65
|
-
exports.executeQuery = executeQuery;
|
|
66
66
|
async function executeBatchQuery(credential, batch, sessionKey) {
|
|
67
67
|
const length = batch.length;
|
|
68
68
|
const result = new Array(length);
|
|
69
69
|
const caching = length > 0 && this.hasCache(batch[0].service, sessionKey);
|
|
70
70
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
71
71
|
let client;
|
|
72
|
-
const createClient = async () =>
|
|
73
|
-
|
|
72
|
+
const createClient = async () => {
|
|
73
|
+
return createDatabaseClient.call(this, credential);
|
|
74
|
+
};
|
|
75
|
+
const closeClient = () => {
|
|
76
|
+
if (client) {
|
|
77
|
+
void client.close();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
74
80
|
for (let i = 0; i < length; ++i) {
|
|
75
81
|
const item = batch[i];
|
|
76
82
|
const { service, table = '', id, query, ignoreCache } = item;
|
|
77
|
-
const getCache = (value) => {
|
|
78
|
-
if (ignoreCache !== 1) {
|
|
79
|
-
cacheValue.renewCache = ignoreCache === 0;
|
|
80
|
-
return this.getQueryResult(service, credential, value, cacheValue);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
83
|
cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
|
|
84
84
|
let rows, queryString = caching && ignoreCache !== true ? table + '_' : '';
|
|
85
85
|
invalid: {
|
|
@@ -91,7 +91,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
91
91
|
const update = item.update;
|
|
92
92
|
if (queryString) {
|
|
93
93
|
queryString += id;
|
|
94
|
-
if (!update && (rows =
|
|
94
|
+
if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
|
|
95
95
|
result[i] = rows;
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
@@ -114,7 +114,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
114
114
|
else {
|
|
115
115
|
delete item.update;
|
|
116
116
|
}
|
|
117
|
-
this.addLog(types_1.STATUS_TYPE.WARN,
|
|
117
|
+
this.addLog(types_1.STATUS_TYPE.WARN, message + ` (_id=${id})`, service, 'replaceOne');
|
|
118
118
|
};
|
|
119
119
|
if (rows) {
|
|
120
120
|
const status = await row.replaceOne({ ...rows[0], ...update });
|
|
@@ -144,7 +144,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
144
144
|
closeClient();
|
|
145
145
|
throw (0, util_1.formatError)(item, "Missing database table");
|
|
146
146
|
}
|
|
147
|
-
if (queryString && (rows =
|
|
147
|
+
if (queryString && (rows = this.getCacheResult(service, credential, queryString += Cloud.asString(query, true) + (maxRows > 0 ? maxRows : ''), cacheValue, ignoreCache))) {
|
|
148
148
|
result[i] = rows;
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
@@ -173,7 +173,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
173
173
|
if (limit > rows.length) {
|
|
174
174
|
rows = rows.slice(0, limit);
|
|
175
175
|
}
|
|
176
|
-
this.addLog(types_1.STATUS_TYPE.WARN, err, service,
|
|
176
|
+
this.addLog(types_1.STATUS_TYPE.WARN, err, service, 'getDocuments');
|
|
177
177
|
break;
|
|
178
178
|
}
|
|
179
179
|
default:
|
|
@@ -186,7 +186,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
186
186
|
if (options?.maxRows && isNaN(maxRows)) {
|
|
187
187
|
maxRows = options.maxRows;
|
|
188
188
|
}
|
|
189
|
-
if (queryString && (rows =
|
|
189
|
+
if (queryString && (rows = this.getCacheResult(service, credential, queryString += query + Cloud.asString(params, true) + Cloud.asString(options, true) + (maxRows > 0 ? maxRows : ''), cacheValue, ignoreCache))) {
|
|
190
190
|
result[i] = rows;
|
|
191
191
|
continue;
|
|
192
192
|
}
|
|
@@ -234,4 +234,3 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
234
234
|
closeClient();
|
|
235
235
|
return result;
|
|
236
236
|
}
|
|
237
|
-
exports.executeBatchQuery = executeBatchQuery;
|
package/download/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const client_1 = require("@pi-r/oci");
|
|
3
|
-
|
|
3
|
+
const aws = require("@pi-r/aws/download");
|
|
4
|
+
function download(credential, service = 'oci') {
|
|
4
5
|
(0, client_1.setStorageCredential)(credential);
|
|
5
|
-
return
|
|
6
|
-
}
|
|
6
|
+
return aws.call(this, credential, service);
|
|
7
|
+
}
|
|
8
|
+
module.exports = download;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oci",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.10.0",
|
|
24
|
+
"@e-mc/module": "^0.10.0",
|
|
25
|
+
"@e-mc/types": "^0.10.0",
|
|
26
|
+
"@pi-r/aws": "^0.8.1",
|
|
27
|
+
"@pi-r/oracle": "^0.8.1",
|
|
28
|
+
"aws-sdk": "^2.1682.0",
|
|
29
|
+
"oracledb": "^6.6.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/upload/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const client_1 = require("@pi-r/oci");
|
|
3
|
-
|
|
3
|
+
const aws = require("@pi-r/aws/upload");
|
|
4
|
+
function upload(credential, service = 'oci') {
|
|
4
5
|
(0, client_1.setStorageCredential)(credential);
|
|
5
|
-
return
|
|
6
|
-
}
|
|
6
|
+
return aws.call(this, credential, service);
|
|
7
|
+
}
|
|
8
|
+
module.exports = upload;
|