oracledb 5.5.0 → 6.0.0

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +1 -1875
  2. package/LICENSE.txt +8 -222
  3. package/NOTICE.txt +1 -1
  4. package/README.md +38 -30
  5. package/SECURITY.md +38 -0
  6. package/build/Release/oracledb-6.0.0-darwin-x64.node +0 -0
  7. package/build/Release/oracledb-6.0.0-darwin-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-6.0.0-js-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-6.0.0-linux-arm64.node +0 -0
  10. package/build/Release/oracledb-6.0.0-linux-arm64.node-buildinfo.txt +1 -0
  11. package/build/Release/oracledb-6.0.0-linux-x64.node +0 -0
  12. package/build/Release/oracledb-6.0.0-linux-x64.node-buildinfo.txt +1 -0
  13. package/build/Release/oracledb-6.0.0-win32-x64.node +0 -0
  14. package/build/Release/oracledb-6.0.0-win32-x64.node-buildinfo.txt +1 -0
  15. package/examples/README.md +113 -0
  16. package/examples/dbconfig.js +100 -0
  17. package/examples/example.js +156 -0
  18. package/index.js +26 -0
  19. package/lib/aqDeqOptions.js +146 -7
  20. package/lib/aqEnqOptions.js +59 -7
  21. package/lib/aqMessage.js +118 -7
  22. package/lib/aqQueue.js +242 -53
  23. package/lib/connection.js +1324 -465
  24. package/lib/constants.js +203 -0
  25. package/lib/dbObject.js +346 -32
  26. package/lib/errors.js +781 -0
  27. package/lib/impl/aqDeqOptions.js +197 -0
  28. package/lib/impl/aqEnqOptions.js +89 -0
  29. package/lib/impl/aqMessage.js +134 -0
  30. package/lib/impl/aqQueue.js +81 -0
  31. package/lib/impl/connection.js +529 -0
  32. package/lib/impl/dbObject.js +159 -0
  33. package/lib/impl/index.js +59 -0
  34. package/lib/impl/lob.js +85 -0
  35. package/lib/impl/pool.js +195 -0
  36. package/lib/impl/resultset.js +223 -0
  37. package/lib/impl/sodaCollection.js +174 -0
  38. package/lib/impl/sodaDatabase.js +81 -0
  39. package/lib/impl/sodaDocCursor.js +63 -0
  40. package/lib/impl/sodaDocument.js +98 -0
  41. package/lib/impl/sodaOperation.js +109 -0
  42. package/lib/lob.js +156 -68
  43. package/lib/oracledb.js +1047 -345
  44. package/lib/pool.js +654 -465
  45. package/lib/poolStatistics.js +23 -9
  46. package/lib/queryStream.js +14 -7
  47. package/lib/resultset.js +291 -183
  48. package/lib/settings.js +191 -0
  49. package/lib/sodaCollection.js +214 -201
  50. package/lib/sodaDatabase.js +107 -71
  51. package/lib/sodaDocCursor.js +44 -32
  52. package/lib/sodaDocument.js +76 -14
  53. package/lib/sodaOperation.js +131 -118
  54. package/lib/thin/connection.js +1038 -0
  55. package/lib/thin/dbObject.js +629 -0
  56. package/lib/thin/index.js +40 -0
  57. package/lib/thin/lob.js +188 -0
  58. package/lib/thin/pool.js +481 -0
  59. package/lib/thin/protocol/buffer.js +1040 -0
  60. package/lib/thin/protocol/capabilities.js +116 -0
  61. package/lib/thin/protocol/constants.js +764 -0
  62. package/lib/thin/protocol/encryptDecrypt.js +185 -0
  63. package/lib/thin/protocol/messages/auth.js +348 -0
  64. package/lib/thin/protocol/messages/base.js +475 -0
  65. package/lib/thin/protocol/messages/commit.js +56 -0
  66. package/lib/thin/protocol/messages/dataType.js +382 -0
  67. package/lib/thin/protocol/messages/execute.js +312 -0
  68. package/lib/thin/protocol/messages/fetch.js +60 -0
  69. package/lib/thin/protocol/messages/index.js +53 -0
  70. package/lib/thin/protocol/messages/lobOp.js +200 -0
  71. package/lib/thin/protocol/messages/logOff.js +53 -0
  72. package/lib/thin/protocol/messages/ping.js +56 -0
  73. package/lib/thin/protocol/messages/protocol.js +78 -0
  74. package/lib/thin/protocol/messages/rollback.js +56 -0
  75. package/lib/thin/protocol/messages/sessionRelease.js +60 -0
  76. package/lib/thin/protocol/messages/withData.js +811 -0
  77. package/lib/thin/protocol/oson.js +660 -0
  78. package/lib/thin/protocol/packet.js +520 -0
  79. package/lib/thin/protocol/protocol.js +202 -0
  80. package/lib/thin/protocol/utils.js +88 -0
  81. package/lib/thin/resultSet.js +122 -0
  82. package/lib/thin/sqlnet/connStrategy.js +175 -0
  83. package/lib/thin/sqlnet/constants.js +199 -0
  84. package/lib/thin/sqlnet/ezConnectResolver.js +488 -0
  85. package/lib/thin/sqlnet/navNodes.js +870 -0
  86. package/lib/thin/sqlnet/networkSession.js +620 -0
  87. package/lib/thin/sqlnet/ntTcp.js +525 -0
  88. package/lib/thin/sqlnet/nvStrToNvPair.js +783 -0
  89. package/lib/thin/sqlnet/packet.js +405 -0
  90. package/lib/thin/sqlnet/paramParser.js +205 -0
  91. package/lib/thin/sqlnet/sessionAtts.js +160 -0
  92. package/lib/thin/statement.js +301 -0
  93. package/lib/thin/util.js +289 -0
  94. package/lib/transformer.js +250 -0
  95. package/lib/types.js +357 -0
  96. package/lib/util.js +194 -110
  97. package/lib/version.js +36 -0
  98. package/package/README.md +33 -30
  99. package/package/install.js +89 -64
  100. package/package/prunebinaries.js +60 -12
  101. package/package.json +3 -3
  102. package/build/Release/oracledb-5.5.0-darwin-x64.node +0 -0
  103. package/build/Release/oracledb-5.5.0-darwin-x64.node-buildinfo.txt +0 -1
  104. package/build/Release/oracledb-5.5.0-linux-x64.node +0 -0
  105. package/build/Release/oracledb-5.5.0-linux-x64.node-buildinfo.txt +0 -1
  106. package/build/Release/oracledb-5.5.0-win32-x64.node +0 -0
  107. package/build/Release/oracledb-5.5.0-win32-x64.node-buildinfo.txt +0 -1
@@ -0,0 +1,191 @@
1
+ // Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // This software is dual-licensed to you under the Universal Permissive License
6
+ // (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7
+ // 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8
+ // either license.
9
+ //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
12
+ //
13
+ // Licensed under the Apache License, Version 2.0 (the "License");
14
+ // you may not use this file except in compliance with the License.
15
+ // You may obtain a copy of the License at
16
+ //
17
+ // https://www.apache.org/licenses/LICENSE-2.0
18
+ //
19
+ // Unless required by applicable law or agreed to in writing, software
20
+ // distributed under the License is distributed on an "AS IS" BASIS,
21
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ // See the License for the specific language governing permissions and
23
+ // limitations under the License.
24
+ //
25
+ //-----------------------------------------------------------------------------
26
+
27
+ 'use strict';
28
+
29
+ const constants = require('./constants.js');
30
+ const errors = require('./errors.js');
31
+ const types = require('./types.js');
32
+
33
+ class Settings {
34
+
35
+ constructor() {
36
+ this.autoCommit = false;
37
+ this.connectionClass = '';
38
+ this.dbObjectAsPojo = false;
39
+ this.edition = '';
40
+ this.errorOnConcurrentExecute = false;
41
+ this.events = false;
42
+ this.externalAuth = false;
43
+ this.fetchArraySize = 100;
44
+ this.fetchAsBuffer = [];
45
+ this.fetchAsString = [];
46
+ this.lobPrefetchSize = 16384;
47
+ this.maxRows = 0;
48
+ this.outFormat = constants.OUT_FORMAT_ARRAY;
49
+ this.poolIncrement = 1;
50
+ this.poolMax = 4;
51
+ this.poolMaxPerShard = 0;
52
+ this.poolMin = 0;
53
+ this.poolPingInterval = 60;
54
+ this.poolTimeout = 60;
55
+ this.prefetchRows = 2;
56
+ this.queueTimeout = 60000;
57
+ this.queueMax = 500;
58
+ this.stmtCacheSize = 30;
59
+ this.thin = true;
60
+ this.thinDriverInitialized = false;
61
+ this.createFetchTypeMap(this.fetchAsString, this.fetchAsBuffer);
62
+ this.fetchTypeHandler = undefined;
63
+ }
64
+
65
+ //---------------------------------------------------------------------------
66
+ // _getDateComponents()
67
+ //
68
+ // Returns the components of a date. DATE and TIMESTAMP data from the
69
+ // database are returned as though they used the JavaScript time zone
70
+ // setting. TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE data
71
+ // are returned in native JavaScript format (since they contain time zone
72
+ // information).
73
+ //---------------------------------------------------------------------------
74
+ _getDateComponents(useLocal, date) {
75
+ if (useLocal) {
76
+ return [
77
+ date.getFullYear(),
78
+ date.getMonth() + 1,
79
+ date.getDate(),
80
+ date.getHours(),
81
+ date.getMinutes(),
82
+ date.getSeconds(),
83
+ date.getMilliseconds() * 1000 * 1000
84
+ ];
85
+ } else {
86
+ return [
87
+ date.getUTCFullYear(),
88
+ date.getUTCMonth() + 1,
89
+ date.getUTCDate(),
90
+ date.getUTCHours(),
91
+ date.getUTCMinutes(),
92
+ date.getUTCSeconds(),
93
+ date.getUTCMilliseconds() * 1000 * 1000
94
+ ];
95
+ }
96
+ }
97
+
98
+ //---------------------------------------------------------------------------
99
+ // _makeDate()
100
+ //
101
+ // Returns a date from the given components. DATE and TIMESTAMP data from the
102
+ // database are returned as though they used the JavaScript time zone
103
+ // setting. TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE data
104
+ // are returned in native JavaScript format (since they contain time zone
105
+ // information).
106
+ //---------------------------------------------------------------------------
107
+ _makeDate(useLocal, year, month, day, hour, minute, second, fseconds, offset) {
108
+ if (useLocal) {
109
+ return new Date(year, month - 1, day, hour, minute, second, fseconds);
110
+ }
111
+ return new Date(Date.UTC(year, month - 1, day, hour, minute, second,
112
+ fseconds) - offset * 60000);
113
+ }
114
+
115
+ //---------------------------------------------------------------------------
116
+ // addToOptions()
117
+ //
118
+ // Adds the named settingsto the options, if no option has already been
119
+ // specified.
120
+ //---------------------------------------------------------------------------
121
+ addToOptions(options) {
122
+ for (let i = 1; i < arguments.length; i++) {
123
+ const key = arguments[i];
124
+ if (options[key] === undefined)
125
+ options[key] = this[key];
126
+ }
127
+ }
128
+
129
+ //---------------------------------------------------------------------------
130
+ // createFetchTypeMap()
131
+ //
132
+ // Creates the fetch type map. This overrides the default fetch type mapping
133
+ // used by the driver with the contents of the fetchAsString and
134
+ // fetchAsBuffer arrays. The error checking is performed here as well in
135
+ // order to eliminate repeated code.
136
+ // ---------------------------------------------------------------------------
137
+ createFetchTypeMap(fetchAsString, fetchAsBuffer) {
138
+
139
+ // create a copy of the default fetch type map
140
+ const map = new Map(types.DB_TYPE_FETCH_TYPE_MAP);
141
+
142
+ // adjust map for fetchAsString settings
143
+ for (const element of fetchAsString) {
144
+ switch (element) {
145
+ case types.DB_TYPE_NUMBER:
146
+ map.set(types.DB_TYPE_BINARY_DOUBLE, types.DB_TYPE_VARCHAR);
147
+ map.set(types.DB_TYPE_BINARY_FLOAT, types.DB_TYPE_VARCHAR);
148
+ map.set(types.DB_TYPE_BINARY_INTEGER, types.DB_TYPE_VARCHAR);
149
+ map.set(types.DB_TYPE_NUMBER, types.DB_TYPE_VARCHAR);
150
+ break;
151
+ case types.DB_TYPE_TIMESTAMP:
152
+ map.set(types.DB_TYPE_DATE, types.DB_TYPE_VARCHAR);
153
+ map.set(types.DB_TYPE_TIMESTAMP, types.DB_TYPE_VARCHAR);
154
+ map.set(types.DB_TYPE_TIMESTAMP_TZ, types.DB_TYPE_VARCHAR);
155
+ map.set(types.DB_TYPE_TIMESTAMP_LTZ, types.DB_TYPE_VARCHAR);
156
+ break;
157
+ case types.DB_TYPE_CLOB:
158
+ case types.DB_TYPE_NCLOB:
159
+ map.set(types.DB_TYPE_CLOB, types.DB_TYPE_LONG);
160
+ map.set(types.DB_TYPE_NCLOB, types.DB_TYPE_LONG_NVARCHAR);
161
+ break;
162
+ case types.DB_TYPE_RAW:
163
+ map.set(types.DB_TYPE_RAW, types.DB_TYPE_VARCHAR);
164
+ break;
165
+ case types.DB_TYPE_JSON:
166
+ map.set(types.DB_TYPE_JSON, types.DB_TYPE_VARCHAR);
167
+ break;
168
+ default:
169
+ errors.throwErr(errors.ERR_INVALID_TYPE_FOR_CONVERSION);
170
+ }
171
+ }
172
+
173
+ // adjust map for fetchAsBuffer settings
174
+ for (const element of fetchAsBuffer) {
175
+ switch (element) {
176
+ case types.DB_TYPE_BLOB:
177
+ map.set(types.DB_TYPE_BLOB, types.DB_TYPE_LONG_RAW);
178
+ break;
179
+ default:
180
+ errors.throwErr(errors.ERR_INVALID_TYPE_FOR_CONVERSION);
181
+ }
182
+ }
183
+
184
+ // assign calculated fetchTypeMap for later use
185
+ this.fetchTypeMap = map;
186
+
187
+ }
188
+
189
+ }
190
+
191
+ module.exports = new Settings();
@@ -1,17 +1,24 @@
1
- // Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1
+ // Copyright (c) 2018, 2023, Oracle and/or its affiliates.
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
5
- // You may not use the identified files except in compliance with the Apache
6
- // License, Version 2.0 (the "License.")
5
+ // This software is dual-licensed to you under the Universal Permissive License
6
+ // (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7
+ // 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8
+ // either license.
7
9
  //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
12
+ //
13
+ // Licensed under the Apache License, Version 2.0 (the "License");
14
+ // you may not use this file except in compliance with the License.
8
15
  // You may obtain a copy of the License at
9
- // http://www.apache.org/licenses/LICENSE-2.0.
10
16
  //
11
- // Unless required by applicable law or agreed to in writing, software
12
- // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ // https://www.apache.org/licenses/LICENSE-2.0
14
18
  //
19
+ // Unless required by applicable law or agreed to in writing, software
20
+ // distributed under the License is distributed on an "AS IS" BASIS,
21
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
22
  // See the License for the specific language governing permissions and
16
23
  // limitations under the License.
17
24
  //
@@ -19,238 +26,244 @@
19
26
 
20
27
  'use strict';
21
28
 
29
+ const SodaDocument = require('./sodaDocument.js');
30
+ const SodaOperation = require('./sodaOperation.js');
31
+ const errors = require('./errors.js');
22
32
  const nodbUtil = require('./util.js');
33
+ const settings = require('./settings.js');
23
34
 
24
- //-----------------------------------------------------------------------------
25
- // drop()
26
- // Drop the collection.
27
- //-----------------------------------------------------------------------------
28
- async function drop() {
29
- nodbUtil.checkArgCount(arguments, 0, 0);
30
- return await this._drop();
31
- }
32
-
35
+ class SodaCollection {
33
36
 
34
- //-----------------------------------------------------------------------------
35
- // insertMany()
36
- // Insert an array of documents into the collection in a single round-trip.
37
- //-----------------------------------------------------------------------------
38
- async function insertMany(docs) {
39
- nodbUtil.checkArgCount(arguments, 1, 1);
40
- nodbUtil.assert(Array.isArray(docs), 'NJS-005', 1);
37
+ //---------------------------------------------------------------------------
38
+ // createIndex()
39
+ //
40
+ // Create an index on the collection.
41
+ //---------------------------------------------------------------------------
42
+ async createIndex(spec) {
43
+ errors.assertArgCount(arguments, 1, 1);
44
+ errors.assertParamValue(nodbUtil.isObject(spec), 1);
45
+ const options = {autoCommit: settings.autoCommit};
46
+ return await this._impl.createIndex(JSON.stringify(spec), options);
47
+ }
41
48
 
42
- if (docs.length == 0) {
43
- throw new Error(nodbUtil.getErrorMessage('NJS-005', 1));
49
+ //---------------------------------------------------------------------------
50
+ // drop()
51
+ //
52
+ // Drop the collection.
53
+ //---------------------------------------------------------------------------
54
+ async drop() {
55
+ errors.assertArgCount(arguments, 0, 0);
56
+ const options = {autoCommit: settings.autoCommit};
57
+ return await this._impl.drop(options);
44
58
  }
45
59
 
46
- let actualDocs = Array(docs.length);
47
- for (let i = 0; i < docs.length; i++) {
48
- let content = docs[i];
49
- if (!nodbUtil.isSodaDocument(content)) {
50
- content = Buffer.from(JSON.stringify(content));
60
+ //---------------------------------------------------------------------------
61
+ // dropIndex()
62
+ //
63
+ // Drop an index on the collection.
64
+ //---------------------------------------------------------------------------
65
+ async dropIndex(indexName, a2) {
66
+ const options = {autoCommit: settings.autoCommit};
67
+
68
+ errors.assertArgCount(arguments, 1, 2);
69
+ errors.assertParamValue(typeof indexName === 'string', 1);
70
+ if (arguments.length == 2) {
71
+ errors.assertParamValue(typeof a2 === 'object', 2);
72
+ if (a2.force !== undefined) {
73
+ errors.assertParamPropValue(typeof a2.force === 'boolean', 2, "force");
74
+ options.force = a2.force;
75
+ }
51
76
  }
52
- actualDocs[i] = content;
77
+ return await this._impl.dropIndex(indexName, options);
53
78
  }
54
79
 
55
- await this._insertMany(actualDocs);
56
- }
57
-
58
-
59
- //-----------------------------------------------------------------------------
60
- // insertManyAndGet()
61
- // Insert an array of documents into the collection in a single round-trip
62
- // and return a set of result documents containing metadata.
63
- //-----------------------------------------------------------------------------
64
- async function insertManyAndGet(docs, a2) {
65
- let options = {};
66
-
67
- nodbUtil.checkArgCount(arguments, 1, 2);
68
- nodbUtil.assert(Array.isArray(docs), 'NJS-005', 1);
69
-
70
- if (arguments.length == 2) {
71
- nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-005', 2);
72
- options = a2;
80
+ //---------------------------------------------------------------------------
81
+ // find()
82
+ //
83
+ // Returns a SODA operation associated with the collection.
84
+ //---------------------------------------------------------------------------
85
+ find() {
86
+ errors.assertArgCount(arguments, 0, 0);
87
+ const op = new SodaOperation();
88
+ op._impl = this._impl.find();
89
+ return op;
73
90
  }
74
91
 
75
- if (docs.length == 0) {
76
- throw new Error(nodbUtil.getErrorMessage('NJS-005', 1));
92
+ //---------------------------------------------------------------------------
93
+ // getDataGuide()
94
+ // Return the data guide for the collection.
95
+ //---------------------------------------------------------------------------
96
+ async getDataGuide() {
97
+ errors.assertArgCount(arguments, 0, 0);
98
+ const doc = new SodaDocument();
99
+ doc._impl = await this._impl.getDataGuide();
100
+ return doc;
77
101
  }
78
102
 
79
- let actualDocs = Array(docs.length);
80
- for (let i = 0; i < docs.length; i++) {
81
- let content = docs[i];
82
- if (!nodbUtil.isSodaDocument(content)) {
83
- content = Buffer.from(JSON.stringify(content));
103
+ //---------------------------------------------------------------------------
104
+ // insertMany()
105
+ //
106
+ // Insert an array of documents into the collection in a single round-trip.
107
+ //---------------------------------------------------------------------------
108
+ async insertMany(docs) {
109
+ errors.assertArgCount(arguments, 1, 1);
110
+ errors.assertParamValue(Array.isArray(docs) && docs.length > 0, 1);
111
+
112
+ let actualDocs = Array(docs.length);
113
+ for (let i = 0; i < docs.length; i++) {
114
+ actualDocs[i] = nodbUtil.verifySodaDoc(docs[i]);
84
115
  }
85
- actualDocs[i] = content;
86
- }
87
116
 
88
- return await this._insertManyAndGet(actualDocs, options);
89
- }
90
-
91
-
92
- //-----------------------------------------------------------------------------
93
- // insertOne()
94
- // Inserts a single document into the collection.
95
- //-----------------------------------------------------------------------------
96
- async function insertOne(content) {
97
- nodbUtil.checkArgCount(arguments, 1, 1);
98
- nodbUtil.assert(nodbUtil.isObject(content) ||
99
- nodbUtil.isSodaDocument(content), 'NJS-005', 1);
100
-
101
- if (!nodbUtil.isSodaDocument(content)) {
102
- content = Buffer.from(JSON.stringify(content));
117
+ const options = {autoCommit: settings.autoCommit};
118
+ await this._impl.insertMany(actualDocs, options);
103
119
  }
104
120
 
105
- await this._insertOne(content);
106
- }
107
-
121
+ //---------------------------------------------------------------------------
122
+ // insertManyAndGet()
123
+ //
124
+ // Insert an array of documents into the collection in a single round-trip
125
+ // and return a set of result documents containing metadata.
126
+ //---------------------------------------------------------------------------
127
+ async insertManyAndGet(docs, a2) {
128
+ const options = {autoCommit: settings.autoCommit};
129
+
130
+ errors.assertArgCount(arguments, 1, 2);
131
+ errors.assertParamValue(Array.isArray(docs) && docs.length > 0, 1);
132
+
133
+ if (arguments.length == 2) {
134
+ errors.assertParamValue(nodbUtil.isObject(a2), 2);
135
+ if (a2.hint !== undefined) {
136
+ errors.assertParamPropValue(typeof a2.hint === 'string', 2, "hint");
137
+ options.hint = a2.hint;
138
+ }
139
+ }
108
140
 
109
- //-----------------------------------------------------------------------------
110
- // insertOneAndGet()
111
- // Inserts a single document into the collection and returns a result
112
- // document containing metadata.
113
- //-----------------------------------------------------------------------------
114
- async function insertOneAndGet(content, a2) {
115
- let options = {};
141
+ const actualDocs = Array(docs.length);
142
+ for (let i = 0; i < docs.length; i++) {
143
+ actualDocs[i] = nodbUtil.verifySodaDoc(docs[i]);
144
+ }
116
145
 
117
- nodbUtil.checkArgCount(arguments, 1, 2);
118
- nodbUtil.assert(nodbUtil.isObject(content) ||
119
- nodbUtil.isSodaDocument(content), 'NJS-005', 1);
146
+ const docImpls = await this._impl.insertManyAndGet(actualDocs, options);
147
+ for (let i = 0; i < docs.length; i++) {
148
+ const doc = actualDocs[i] = new SodaDocument();
149
+ doc._impl = docImpls[i];
150
+ }
120
151
 
121
- if (arguments.length == 2) {
122
- nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-005', 2);
123
- options = a2;
152
+ return actualDocs;
124
153
  }
125
154
 
126
- if (!nodbUtil.isSodaDocument(content)) {
127
- content = Buffer.from(JSON.stringify(content));
155
+ //---------------------------------------------------------------------------
156
+ // insertOne()
157
+ //
158
+ // Inserts a single document into the collection.
159
+ //---------------------------------------------------------------------------
160
+ async insertOne(content) {
161
+ errors.assertArgCount(arguments, 1, 1);
162
+ content = nodbUtil.verifySodaDoc(content);
163
+ const options = {autoCommit: settings.autoCommit};
164
+ await this._impl.insertOne(content, options);
128
165
  }
129
166
 
130
- return await this._insertOneAndGet(content, options);
131
- }
132
-
133
-
134
- //-----------------------------------------------------------------------------
135
- // createIndex()
136
- // Create an index on the collection.
137
- //-----------------------------------------------------------------------------
138
- async function createIndex(spec) {
139
- nodbUtil.checkArgCount(arguments, 1, 1);
140
- nodbUtil.assert(nodbUtil.isObject(spec), 'NJS-005', 1);
141
- return await this._createIndex(JSON.stringify(spec));
142
- }
143
-
144
-
145
- //-----------------------------------------------------------------------------
146
- // dropIndex()
147
- // Drop an index on the collection.
148
- //-----------------------------------------------------------------------------
149
- async function dropIndex(indexName, a2) {
150
- let options = {};
151
-
152
- nodbUtil.checkArgCount(arguments, 1, 2);
153
- nodbUtil.assert(typeof indexName === 'string', 'NJS-005', 1);
154
- if (arguments.length == 2) {
155
- nodbUtil.assert(typeof a2 === 'object', 'NJS-005', 2);
156
- options = a2;
157
- }
158
-
159
- return await this._dropIndex(indexName, options);
160
- }
161
-
162
-
163
- //-----------------------------------------------------------------------------
164
- // getDataGuide()
165
- // Return the data guide for the collection.
166
- //-----------------------------------------------------------------------------
167
- async function getDataGuide() {
168
- nodbUtil.checkArgCount(arguments, 0, 0);
169
- return await this._getDataGuide();
170
- }
171
-
172
-
173
- //-----------------------------------------------------------------------------
174
- // save()
175
- // Saves a single document into the collection.
176
- //-----------------------------------------------------------------------------
177
- async function save(content) {
178
- nodbUtil.checkArgCount(arguments, 1, 1);
179
- nodbUtil.assert(nodbUtil.isObject(content) ||
180
- nodbUtil.isSodaDocument(content), 'NJS-005', 1);
167
+ //---------------------------------------------------------------------------
168
+ // insertOneAndGet()
169
+ //
170
+ // Inserts a single document into the collection and returns a result
171
+ // document containing metadata.
172
+ //---------------------------------------------------------------------------
173
+ async insertOneAndGet(content, a2) {
174
+ const options = {autoCommit: settings.autoCommit};
175
+
176
+ errors.assertArgCount(arguments, 1, 2);
177
+ content = nodbUtil.verifySodaDoc(content);
178
+ if (arguments.length == 2) {
179
+ errors.assertParamValue(nodbUtil.isObject(a2), 2);
180
+ if (a2.hint !== undefined) {
181
+ errors.assertParamPropValue(typeof a2.hint === 'string', 2, "hint");
182
+ options.hint = a2.hint;
183
+ }
184
+ }
181
185
 
182
- if (!nodbUtil.isSodaDocument(content)) {
183
- content = Buffer.from(JSON.stringify(content));
186
+ const doc = new SodaDocument();
187
+ doc._impl = await this._impl.insertOneAndGet(content, options);
188
+ return doc;
184
189
  }
185
190
 
186
- await this._save(content);
187
- }
188
-
189
-
190
- //-----------------------------------------------------------------------------
191
- // saveAndGet()
192
- // Saves a single document into the collection and returns a result
193
- // document containing metadata.
194
- //-----------------------------------------------------------------------------
195
- async function saveAndGet(content, a2) {
196
- let options = {};
197
-
198
- nodbUtil.checkArgCount(arguments, 1, 2);
199
- nodbUtil.assert(nodbUtil.isObject(content) ||
200
- nodbUtil.isSodaDocument(content), 'NJS-005', 1);
201
-
202
- if (arguments.length == 2) {
203
- nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-005', 2);
204
- options = a2;
191
+ //---------------------------------------------------------------------------
192
+ // metaData()
193
+ //
194
+ // Property for the metadata associated with the collection.
195
+ //---------------------------------------------------------------------------
196
+ get metaData() {
197
+ return JSON.parse(this._impl.getMetaData());
205
198
  }
206
199
 
207
- if (!nodbUtil.isSodaDocument(content)) {
208
- content = Buffer.from(JSON.stringify(content));
200
+ //---------------------------------------------------------------------------
201
+ // name()
202
+ //
203
+ // Property for the name of the collection.
204
+ //---------------------------------------------------------------------------
205
+ get name() {
206
+ return this._impl.getName();
209
207
  }
210
208
 
211
- return await this._saveAndGet(content, options);
212
- }
213
-
214
-
215
- //-----------------------------------------------------------------------------
216
- // truncate()
217
- // Remove all of the documents from a collection.
218
- //-----------------------------------------------------------------------------
219
- async function truncate() {
220
- nodbUtil.checkArgCount(arguments, 0, 0);
221
- await this._truncate();
222
- }
223
-
224
-
225
- class SodaCollection {
226
-
227
- _extend() {
228
- this.createIndex = nodbUtil.callbackify(nodbUtil.serialize(createIndex));
229
- this.drop = nodbUtil.callbackify(nodbUtil.serialize(drop));
230
- this.dropIndex = nodbUtil.callbackify(nodbUtil.serialize(dropIndex));
231
- this.getDataGuide = nodbUtil.callbackify(nodbUtil.serialize(getDataGuide));
232
- this.insertMany = nodbUtil.callbackify(nodbUtil.serialize(insertMany));
233
- this.insertManyAndGet = nodbUtil.callbackify(nodbUtil.serialize(insertManyAndGet));
234
- this.insertOne = nodbUtil.callbackify(nodbUtil.serialize(insertOne));
235
- this.insertOneAndGet = nodbUtil.callbackify(nodbUtil.serialize(insertOneAndGet));
236
- this.save = nodbUtil.callbackify(nodbUtil.serialize(save));
237
- this.saveAndGet = nodbUtil.callbackify(nodbUtil.serialize(saveAndGet));
238
- this.truncate = nodbUtil.callbackify(nodbUtil.serialize(truncate));
209
+ //---------------------------------------------------------------------------
210
+ // save()
211
+ //
212
+ // Saves a single document into the collection.
213
+ //---------------------------------------------------------------------------
214
+ async save(content) {
215
+ errors.assertArgCount(arguments, 1, 1);
216
+ content = nodbUtil.verifySodaDoc(content);
217
+ const options = {autoCommit: settings.autoCommit};
218
+ await this._impl.save(content, options);
239
219
  }
240
220
 
241
- _getConnection() {
242
- return this._database._connection;
243
- }
221
+ //---------------------------------------------------------------------------
222
+ // saveAndGet()
223
+ //
224
+ // Saves a single document into the collection and returns a result document
225
+ // containing metadata.
226
+ //---------------------------------------------------------------------------
227
+ async saveAndGet(content, a2) {
228
+ errors.assertArgCount(arguments, 1, 2);
229
+ content = nodbUtil.verifySodaDoc(content);
230
+ const options = {autoCommit: settings.autoCommit};
231
+ if (arguments.length == 2) {
232
+ errors.assertParamValue(nodbUtil.isObject(a2), 2);
233
+ if (a2.hint !== undefined) {
234
+ errors.assertParamPropValue(typeof a2.hint === 'string', 2, "hint");
235
+ options.hint = a2.hint;
236
+ }
237
+ }
244
238
 
245
- find() {
246
- nodbUtil.checkArgCount(arguments, 0, 0);
247
- return this._find();
239
+ const doc = new SodaDocument();
240
+ doc._impl = await this._impl.saveAndGet(content, options);
241
+ return doc;
248
242
  }
249
243
 
250
- get metaData() {
251
- return JSON.parse(this._metaData);
244
+ //---------------------------------------------------------------------------
245
+ // truncate()
246
+ //
247
+ // Remove all of the documents from a collection.
248
+ //---------------------------------------------------------------------------
249
+ async truncate() {
250
+ errors.assertArgCount(arguments, 0, 0);
251
+ await this._impl.truncate();
252
252
  }
253
253
 
254
254
  }
255
255
 
256
+ nodbUtil.wrapFns(SodaCollection.prototype,
257
+ "createIndex",
258
+ "drop",
259
+ "dropIndex",
260
+ "getDataGuide",
261
+ "insertMany",
262
+ "insertManyAndGet",
263
+ "insertOne",
264
+ "insertOneAndGet",
265
+ "save",
266
+ "saveAndGet",
267
+ "truncate");
268
+
256
269
  module.exports = SodaCollection;