@pi-r/oci 0.8.1 → 0.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
- ### @pi-r/oci
2
-
3
- https://e-mc.readthedocs.io/en/latest/cloud/oci.html
4
-
5
- ### LICENSE
6
-
1
+ ### @pi-r/oci
2
+
3
+ https://e-mc.readthedocs.io/en/latest/cloud/oci.html
4
+
5
+ ### LICENSE
6
+
7
7
  MIT
package/client/index.js CHANGED
@@ -79,7 +79,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
79
79
  };
80
80
  for (let i = 0; i < length; ++i) {
81
81
  const item = batch[i];
82
- const { service, table = '', id, query, ignoreCache } = item;
82
+ const { service, table = '', id, query, updateType = 0, ignoreCache } = item;
83
83
  cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
84
84
  let rows, queryString = caching && ignoreCache !== true ? table + '_' : '';
85
85
  invalid: {
@@ -96,17 +96,38 @@ async function executeBatchQuery(credential, batch, sessionKey) {
96
96
  continue;
97
97
  }
98
98
  }
99
- const db = await (client ||= await createClient()).getSodaDatabase().openCollection(table);
99
+ const soda = (client ||= await createClient()).getSodaDatabase();
100
+ const db = await soda.openCollection(table);
100
101
  if (!db) {
101
102
  closeClient();
102
103
  throw (0, util_1.formatError)(item, "Missing database table");
103
104
  }
104
- const row = db.find().key(id);
105
- let document = await row.getOne();
106
- if (document) {
107
- rows = [document.getContent()];
105
+ if (update && updateType === 1) {
106
+ if (update._id) {
107
+ const document = soda.createDocument(update);
108
+ await db.insertOne(document);
109
+ }
110
+ else {
111
+ void await db.insertOneAndGet(update);
112
+ }
113
+ }
114
+ let target, document;
115
+ if (typeof id === 'string') {
116
+ target = db.find().key(id);
117
+ document = await target.getOne();
118
+ if (document) {
119
+ rows = [document.getContent()];
120
+ }
121
+ }
122
+ else {
123
+ rows = [];
124
+ const row = await db.find().keys(id).getCursor();
125
+ while (document = await row.getNext()) {
126
+ rows.push(document.getContent());
127
+ }
128
+ await row.close();
108
129
  }
109
- if (update) {
130
+ if (update && updateType !== 1) {
110
131
  const failed = (message, fatal) => {
111
132
  if (fatal) {
112
133
  item.transactionFail = true;
@@ -114,22 +135,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
114
135
  else {
115
136
  delete item.update;
116
137
  }
117
- this.addLog(types_1.STATUS_TYPE.WARN, message + ` (_id=${id})`, service, 'replaceOne');
138
+ this.addLog(types_1.STATUS_TYPE.WARN, message + ` (_id=${id.toString()})`, service, 'replaceOne');
118
139
  };
119
- if (rows) {
120
- const status = await row.replaceOne({ ...rows[0], ...update });
121
- if (status.replaced) {
122
- rows = undefined;
123
- if (document = await row.getOne()) {
124
- rows = [document.getContent()];
125
- }
126
- else {
127
- failed('Update success (GET failed)');
128
- }
129
- }
130
- else {
131
- failed('Update failed');
132
- }
140
+ if ((0, types_1.isArray)(id)) {
141
+ target = db.find().key(id[0]);
142
+ }
143
+ if (rows && target) {
144
+ document = await target.replaceOneAndGet(updateType === 0 ? { ...rows[0], ...update } : update);
145
+ rows[0] = document.getContent();
133
146
  }
134
147
  else {
135
148
  failed('Row does not exist', true);
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@pi-r/oci",
3
- "version": "0.8.1",
4
- "description": "Oracle (OCI) cloud functions for E-mc.",
5
- "main": "client/index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/cloud/oci"
13
- },
14
- "keywords": [
15
- "squared",
16
- "e-mc",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
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
- }
31
- }
1
+ {
2
+ "name": "@pi-r/oci",
3
+ "version": "0.8.3",
4
+ "description": "Oracle (OCI) cloud functions for E-mc.",
5
+ "main": "client/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
+ "directory": "src/cloud/oci"
13
+ },
14
+ "keywords": [
15
+ "squared",
16
+ "e-mc",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "^0.10.3",
24
+ "@e-mc/module": "^0.10.3",
25
+ "@e-mc/types": "^0.10.3",
26
+ "@pi-r/aws": "^0.8.3",
27
+ "@pi-r/oracle": "^0.8.3",
28
+ "aws-sdk": "^2.1691.0",
29
+ "oracledb": "^6.6.0"
30
+ }
31
+ }
package/types/index.d.ts CHANGED
@@ -1,19 +1,21 @@
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
-
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 Omit<CloudDatabase<PlainObject | string, ExecuteOptions, StandardMap, BindParameters, OCIDatabaseCredential>, "id"> {
14
+ source: "cloud";
15
+ service: "oci";
16
+ id?: ArrayOf<string>;
17
+ updateType?: 0 | 1 | 2;
18
+ streamRow?: boolean;
19
+ }
20
+
19
21
  export interface OCIDatabaseCredential extends ConnectionAttributes, InitialiseOptions {}