oracledb 5.5.0 → 6.0.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.
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.1-darwin-x64.node +0 -0
  7. package/build/Release/oracledb-6.0.1-darwin-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-6.0.1-js-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-6.0.1-linux-arm64.node +0 -0
  10. package/build/Release/oracledb-6.0.1-linux-arm64.node-buildinfo.txt +1 -0
  11. package/build/Release/oracledb-6.0.1-linux-x64.node +0 -0
  12. package/build/Release/oracledb-6.0.1-linux-x64.node-buildinfo.txt +1 -0
  13. package/build/Release/oracledb-6.0.1-win32-x64.node +0 -0
  14. package/build/Release/oracledb-6.0.1-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 +148 -8
  20. package/lib/aqEnqOptions.js +59 -7
  21. package/lib/aqMessage.js +118 -7
  22. package/lib/aqQueue.js +243 -53
  23. package/lib/connection.js +1326 -465
  24. package/lib/constants.js +203 -0
  25. package/lib/dbObject.js +346 -32
  26. package/lib/errors.js +785 -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 +157 -68
  43. package/lib/oracledb.js +1047 -345
  44. package/lib/pool.js +654 -465
  45. package/lib/poolStatistics.js +24 -9
  46. package/lib/queryStream.js +16 -8
  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 +108 -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 +1043 -0
  55. package/lib/thin/dbObject.js +630 -0
  56. package/lib/thin/index.js +40 -0
  57. package/lib/thin/lob.js +189 -0
  58. package/lib/thin/pool.js +481 -0
  59. package/lib/thin/protocol/buffer.js +1043 -0
  60. package/lib/thin/protocol/capabilities.js +121 -0
  61. package/lib/thin/protocol/constants.js +765 -0
  62. package/lib/thin/protocol/encryptDecrypt.js +185 -0
  63. package/lib/thin/protocol/messages/auth.js +349 -0
  64. package/lib/thin/protocol/messages/base.js +476 -0
  65. package/lib/thin/protocol/messages/commit.js +56 -0
  66. package/lib/thin/protocol/messages/dataType.js +391 -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 +201 -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 +812 -0
  77. package/lib/thin/protocol/oson.js +661 -0
  78. package/lib/thin/protocol/packet.js +519 -0
  79. package/lib/thin/protocol/protocol.js +202 -0
  80. package/lib/thin/protocol/utils.js +89 -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 +621 -0
  87. package/lib/thin/sqlnet/ntTcp.js +527 -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 +206 -0
  91. package/lib/thin/sqlnet/sessionAtts.js +160 -0
  92. package/lib/thin/statement.js +300 -0
  93. package/lib/thin/util.js +289 -0
  94. package/lib/transformer.js +252 -0
  95. package/lib/types.js +357 -0
  96. package/lib/util.js +196 -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,203 @@
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
+ // This file contains values for implementation and public constants.
28
+ //
29
+ // All public constants are later exposed to node-oracledb apps via the exports
30
+ // of oracledb.js.
31
+
32
+ 'use strict';
33
+
34
+ const version = require('./version.js');
35
+
36
+ const VERSION_STRING =
37
+ version.VERSION_MAJOR + '.' +
38
+ version.VERSION_MINOR + '.' +
39
+ version.VERSION_PATCH +
40
+ version.VERSION_SUFFIX;
41
+
42
+ module.exports = {
43
+
44
+ // version information
45
+ VERSION_MAJOR: version.VERSION_MAJOR,
46
+ VERSION_MINOR: version.VERSION_MINOR,
47
+ VERSION_PATCH: version.VERSION_PATCH,
48
+ VERSION_SUFFIX: version.VERSION_SUFFIX,
49
+ VERSION_STRING: VERSION_STRING,
50
+
51
+ // defaults for initOracleClient()
52
+ DEFAULT_DRIVER_NAME: "node-oracledb : " + VERSION_STRING,
53
+ DEFAULT_ERROR_URL: "https://node-oracledb.readthedocs.io/en/latest/user_guide/installation.html",
54
+
55
+ // default for maxSize for OUT and IN/OUT binds
56
+ DEFAULT_MAX_SIZE_FOR_OUT_BINDS: 200,
57
+
58
+ // character set forms (internal use)
59
+ CSFRM_IMPLICIT: 1,
60
+ CSFRM_NCHAR: 2,
61
+
62
+ // CQN operation codes
63
+ CQN_OPCODE_ALL_OPS: 0,
64
+ CQN_OPCODE_ALL_ROWS: 1,
65
+ CQN_OPCODE_ALTER: 16,
66
+ CQN_OPCODE_DELETE: 8,
67
+ CQN_OPCODE_DROP: 32,
68
+ CQN_OPCODE_INSERT: 2,
69
+ CQN_OPCODE_UPDATE: 4,
70
+
71
+ // fetchInfo type defaulting
72
+ DEFAULT: 0,
73
+
74
+ // statement types
75
+ STMT_TYPE_UNKNOWN: 0,
76
+ STMT_TYPE_SELECT: 1,
77
+ STMT_TYPE_UPDATE: 2,
78
+ STMT_TYPE_DELETE: 3,
79
+ STMT_TYPE_INSERT: 4,
80
+ STMT_TYPE_CREATE: 5,
81
+ STMT_TYPE_DROP: 6,
82
+ STMT_TYPE_ALTER: 7,
83
+ STMT_TYPE_BEGIN: 8,
84
+ STMT_TYPE_DECLARE: 9,
85
+ STMT_TYPE_CALL: 10,
86
+ STMT_TYPE_EXPLAIN_PLAN: 15,
87
+ STMT_TYPE_MERGE: 16,
88
+ STMT_TYPE_ROLLBACK: 17,
89
+ STMT_TYPE_COMMIT: 21,
90
+
91
+ // shutdown modes
92
+ SHUTDOWN_MODE_DEFAULT: 0,
93
+ SHUTDOWN_MODE_TRANSACTIONAL: 1,
94
+ SHUTDOWN_MODE_TRANSACTIONAL_LOCAL: 2,
95
+ SHUTDOWN_MODE_IMMEDIATE: 3,
96
+ SHUTDOWN_MODE_ABORT: 4,
97
+ SHUTDOWN_MODE_FINAL: 5,
98
+
99
+ // startup modes
100
+ STARTUP_MODE_DEFAULT: 0,
101
+ STARTUP_MODE_FORCE: 1,
102
+ STARTUP_MODE_RESTRICT: 2,
103
+
104
+ // subscription event types
105
+ SUBSCR_EVENT_TYPE_SHUTDOWN: 2,
106
+ SUBSCR_EVENT_TYPE_SHUTDOWN_ANY: 3,
107
+ SUBSCR_EVENT_TYPE_STARTUP: 1,
108
+ SUBSCR_EVENT_TYPE_DEREG: 5,
109
+ SUBSCR_EVENT_TYPE_OBJ_CHANGE: 6,
110
+ SUBSCR_EVENT_TYPE_QUERY_CHANGE: 7,
111
+ SUBSCR_EVENT_TYPE_AQ: 100,
112
+
113
+ // subscription grouping classes
114
+ SUBSCR_GROUPING_CLASS_TIME: 1,
115
+
116
+ // subscription grouping types
117
+ SUBSCR_GROUPING_TYPE_SUMMARY: 1,
118
+ SUBSCR_GROUPING_TYPE_LAST: 2,
119
+
120
+ // subscription namespaces
121
+ SUBSCR_NAMESPACE_AQ: 1,
122
+ SUBSCR_NAMESPACE_DBCHANGE: 2,
123
+
124
+ // subscription quality of service flags
125
+ SUBSCR_QOS_BEST_EFFORT: 0x10,
126
+ SUBSCR_QOS_DEREG_NFY: 0x02,
127
+ SUBSCR_QOS_QUERY: 0x08,
128
+ SUBSCR_QOS_RELIABLE: 0x01,
129
+ SUBSCR_QOS_ROWIDS: 0x04,
130
+
131
+ // privileges
132
+ SYSASM: 0x00008000,
133
+ SYSBACKUP: 0x00020000,
134
+ SYSDBA: 0x00000002,
135
+ SYSDG: 0x00040000,
136
+ SYSKM: 0x00080000,
137
+ SYSOPER: 0x00000004,
138
+ SYSPRELIM: 0x00000008,
139
+ SYSRAC: 0x00100000,
140
+
141
+ // bind directions
142
+ BIND_IN: 3001,
143
+ BIND_INOUT: 3002,
144
+ BIND_OUT: 3003,
145
+
146
+ // outFormat values
147
+ OUT_FORMAT_ARRAY: 4001,
148
+ OUT_FORMAT_OBJECT: 4002,
149
+
150
+ // SODA collection creation modes
151
+ SODA_COLL_MAP_MODE: 5001,
152
+
153
+ // pool statuses
154
+ POOL_STATUS_OPEN: 6000,
155
+ POOL_STATUS_DRAINING: 6001,
156
+ POOL_STATUS_CLOSED: 6002,
157
+ POOL_STATUS_RECONFIGURING: 6003,
158
+
159
+ // purity values
160
+ PURITY_DEFAULT: 0,
161
+ PURITY_NEW: 1,
162
+ PURITY_SELF: 2,
163
+
164
+ // AQ dequeue wait options
165
+ AQ_DEQ_NO_WAIT: 0,
166
+ AQ_DEQ_WAIT_FOREVER: 4294967295,
167
+
168
+ // AQ dequeue modes
169
+ AQ_DEQ_MODE_BROWSE: 1,
170
+ AQ_DEQ_MODE_LOCKED: 2,
171
+ AQ_DEQ_MODE_REMOVE: 3,
172
+ AQ_DEQ_MODE_REMOVE_NO_DATA: 4,
173
+
174
+ // AQ dequeue navigation flags
175
+ AQ_DEQ_NAV_FIRST_MSG: 1,
176
+ AQ_DEQ_NAV_NEXT_TRANSACTION: 2,
177
+ AQ_DEQ_NAV_NEXT_MSG: 3,
178
+
179
+ // AQ message delivery modes
180
+ AQ_MSG_DELIV_MODE_PERSISTENT: 1,
181
+ AQ_MSG_DELIV_MODE_BUFFERED: 2,
182
+ AQ_MSG_DELIV_MODE_PERSISTENT_OR_BUFFERED: 3,
183
+
184
+ // AQ message states
185
+ AQ_MSG_STATE_READY: 0,
186
+ AQ_MSG_STATE_WAITING: 1,
187
+ AQ_MSG_STATE_PROCESSED: 2,
188
+ AQ_MSG_STATE_EXPIRED: 3,
189
+
190
+ // AQ visibility flags
191
+ AQ_VISIBILITY_IMMEDIATE: 1,
192
+ AQ_VISIBILITY_ON_COMMIT: 2,
193
+
194
+ // TPC/XA begin flags Constants
195
+ TPC_BEGIN_JOIN: 0x00000002,
196
+ TPC_BEGIN_NEW: 0x00000001,
197
+ TPC_BEGIN_PROMOTE: 0x00000008,
198
+ TPC_BEGIN_RESUME: 0x00000004,
199
+
200
+ // TPC/XA two-phase commit flags
201
+ TPC_END_NORMAL: 0,
202
+ TPC_END_SUSPEND: 0x00100000,
203
+ };
package/lib/dbObject.js CHANGED
@@ -1,17 +1,24 @@
1
- // Copyright (c) 2019, 2022, Oracle and/or its affiliates.
2
- //
1
+ // Copyright (c) 2019, 2023, Oracle and/or its affiliates.
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.
9
+ //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
7
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,6 +26,10 @@
19
26
 
20
27
  'use strict';
21
28
 
29
+ const Lob = require('./lob.js');
30
+ const impl = require('./impl');
31
+ const errors = require('./errors.js');
32
+ const types = require('./types.js');
22
33
  const util = require('util');
23
34
 
24
35
  // define base database object class; instances of this class are never
@@ -26,27 +37,42 @@ const util = require('util');
26
37
  // instantiated; a cache of these classes are maintained on each connection
27
38
  class BaseDbObject {
28
39
 
29
- // extend class with promisified functions
30
- _extend(oracledb) {
31
- this._oracledb = oracledb;
40
+ //---------------------------------------------------------------------------
41
+ // _getAttrValue()
42
+ //
43
+ // Returns the value of the given attribute on the object.
44
+ //---------------------------------------------------------------------------
45
+ _getAttrValue(attr) {
46
+ const value = this._impl.getAttrValue(attr);
47
+ return this._transformValueOut(value, attr.typeClass);
32
48
  }
33
49
 
34
- // initialize object with value
35
- _initialize(initialValue) {
36
- if (this.isCollection) {
37
- for (let i = 0; i < initialValue.length; i++) {
38
- this.append(initialValue[i]);
39
- }
40
- } else {
41
- Object.assign(this, initialValue);
42
- }
50
+ //---------------------------------------------------------------------------
51
+ // _setAttrValue()
52
+ //
53
+ // Sets the value of the attribute on the object to the given value.
54
+ //---------------------------------------------------------------------------
55
+ _setAttrValue(attr, value) {
56
+ const info = {
57
+ fqn: this._objType.fqn,
58
+ attrName: attr.name,
59
+ type: attr.type,
60
+ typeClass: attr.typeClass
61
+ };
62
+ const options = {allowArray: false};
63
+ value = transformer.transformValueIn(info, value, options);
64
+ this._impl.setAttrValue(attr, value);
43
65
  }
44
66
 
45
- // return as a plain object
67
+ //---------------------------------------------------------------------------
68
+ // _toPojo()
69
+ //
70
+ // Returns the database object as a plain Javascript object.
71
+ //---------------------------------------------------------------------------
46
72
  _toPojo() {
47
73
  if (this.isCollection) {
48
74
  const result = this.getValues();
49
- if (this.elementType == this._oracledb.DB_TYPE_OBJECT) {
75
+ if (this.elementType === types.DB_TYPE_OBJECT) {
50
76
  for (let i = 0; i < result.length; i++) {
51
77
  result[i] = result[i]._toPojo();
52
78
  }
@@ -54,7 +80,7 @@ class BaseDbObject {
54
80
  return (result);
55
81
  }
56
82
  const result = {};
57
- for (let name in this.attributes) {
83
+ for (const name in this.attributes) {
58
84
  let value = this[name];
59
85
  if (value instanceof BaseDbObject) {
60
86
  value = value._toPojo();
@@ -64,6 +90,265 @@ class BaseDbObject {
64
90
  return (result);
65
91
  }
66
92
 
93
+ //---------------------------------------------------------------------------
94
+ // _transformValueOut()
95
+ //
96
+ // Transforms a value going out to the caller from the implementation.
97
+ //---------------------------------------------------------------------------
98
+ _transformValueOut(value, cls) {
99
+ let outValue = value;
100
+ if (value instanceof impl.LobImpl) {
101
+ outValue = new Lob();
102
+ outValue._setup(value, true);
103
+ } else if (value instanceof impl.DbObjectImpl) {
104
+ outValue = Object.create(cls.prototype);
105
+ outValue._impl = value;
106
+ if (outValue.isCollection) {
107
+ outValue = new Proxy(outValue, BaseDbObject._collectionProxyHandler);
108
+ }
109
+ }
110
+ return outValue;
111
+ }
112
+
113
+ //---------------------------------------------------------------------------
114
+ // append()
115
+ //
116
+ // Appends an element to the collection.
117
+ //---------------------------------------------------------------------------
118
+ append(value) {
119
+ errors.assertArgCount(arguments, 1, 1);
120
+ const info = {
121
+ fqn: this._objType.fqn,
122
+ type: this._objType.elementType,
123
+ typeClass: this._objType.elementTypeClass
124
+ };
125
+ const options = {allowArray: false};
126
+ value = transformer.transformValueIn(info, value, options);
127
+ this._impl.append(value);
128
+ }
129
+
130
+ //---------------------------------------------------------------------------
131
+ // attributes
132
+ //
133
+ // Property for the attributes stored on the object type.
134
+ //---------------------------------------------------------------------------
135
+ get attributes() {
136
+ if (!this._attributes) {
137
+ const implAttrs = this._objType.attributes || [];
138
+ const attrs = {};
139
+ for (let i = 0; i < implAttrs.length; i++) {
140
+ const implAttr = implAttrs[i];
141
+ const attr = {
142
+ type: implAttr.type,
143
+ typeName: implAttr.typeName
144
+ };
145
+ if (implAttr.typeClass) {
146
+ attr.typeClass = implAttr.typeClass;
147
+ }
148
+ attrs[implAttr.name] = attr;
149
+ }
150
+ this._attributes = attrs;
151
+ }
152
+ return this._attributes;
153
+ }
154
+
155
+ //---------------------------------------------------------------------------
156
+ // deleteElement()
157
+ //
158
+ // Deletes the element in a collection at the specified index.
159
+ //---------------------------------------------------------------------------
160
+ deleteElement(index) {
161
+ errors.assertArgCount(arguments, 1, 1);
162
+ errors.assertParamValue(Number.isInteger(index), 1);
163
+ return this._impl.deleteElement(index);
164
+ }
165
+
166
+ //---------------------------------------------------------------------------
167
+ // elementType
168
+ //
169
+ // Property for the element type, if the database object type is a
170
+ // collection. It will be one of the DB_TYPE_ constants.
171
+ //---------------------------------------------------------------------------
172
+ get elementType() {
173
+ return this._objType.elementType;
174
+ }
175
+
176
+ //---------------------------------------------------------------------------
177
+ // elementTypeClass
178
+ //
179
+ // Property for the element type class, if the database object type is a
180
+ // collection and the elements in the collection refer to database objects.
181
+ //---------------------------------------------------------------------------
182
+ get elementTypeClass() {
183
+ return this._objType.elementTypeClass;
184
+ }
185
+
186
+ //---------------------------------------------------------------------------
187
+ // elementTypeName
188
+ //
189
+ // Property for the element type name, if the database object type is a
190
+ // collection.
191
+ //---------------------------------------------------------------------------
192
+ get elementTypeName() {
193
+ return this._objType.elementTypeName;
194
+ }
195
+
196
+ //---------------------------------------------------------------------------
197
+ // fqn
198
+ //
199
+ // Property for the fully qualified name of the database object type in the
200
+ // form: <schema>.<name>.
201
+ //---------------------------------------------------------------------------
202
+ get fqn() {
203
+ return this._objType.fqn;
204
+ }
205
+
206
+ //---------------------------------------------------------------------------
207
+ // getElement()
208
+ //
209
+ // Returns the element in a collection at the specified index.
210
+ //---------------------------------------------------------------------------
211
+ getElement(index) {
212
+ errors.assertArgCount(arguments, 1, 1);
213
+ errors.assertParamValue(Number.isInteger(index), 1);
214
+ const value = this._impl.getElement(index);
215
+ return this._transformValueOut(value, this.elementTypeClass);
216
+ }
217
+
218
+ //---------------------------------------------------------------------------
219
+ // getKeys()
220
+ //
221
+ // Returns an array of the keys of the collection.
222
+ //---------------------------------------------------------------------------
223
+ getKeys() {
224
+ errors.assertArgCount(arguments, 0, 0);
225
+ return this._impl.getKeys();
226
+ }
227
+
228
+ //---------------------------------------------------------------------------
229
+ // getFirstIndex()
230
+ //
231
+ // Returns the first index in the collection.
232
+ //---------------------------------------------------------------------------
233
+ getFirstIndex() {
234
+ errors.assertArgCount(arguments, 0, 0);
235
+ return this._impl.getFirstIndex();
236
+ }
237
+
238
+ //---------------------------------------------------------------------------
239
+ // getLastIndex()
240
+ //
241
+ // Returns the last index in the collection.
242
+ //---------------------------------------------------------------------------
243
+ getLastIndex() {
244
+ errors.assertArgCount(arguments, 0, 0);
245
+ return this._impl.getLastIndex();
246
+ }
247
+
248
+ //---------------------------------------------------------------------------
249
+ // getNextIndex()
250
+ //
251
+ // Returns the next index in the collection.
252
+ //---------------------------------------------------------------------------
253
+ getNextIndex(index) {
254
+ errors.assertArgCount(arguments, 1, 1);
255
+ errors.assertParamValue(Number.isInteger(index), 1);
256
+ return this._impl.getNextIndex(index);
257
+ }
258
+
259
+ //---------------------------------------------------------------------------
260
+ // getPrevIndex()
261
+ //
262
+ // Returns the previous index in the collection.
263
+ //---------------------------------------------------------------------------
264
+ getPrevIndex(index) {
265
+ errors.assertArgCount(arguments, 1, 1);
266
+ errors.assertParamValue(Number.isInteger(index), 1);
267
+ return this._impl.getPrevIndex(index);
268
+ }
269
+
270
+ //---------------------------------------------------------------------------
271
+ // getValues()
272
+ //
273
+ // Returns the elements in a collection.
274
+ //---------------------------------------------------------------------------
275
+ getValues() {
276
+ errors.assertArgCount(arguments, 0, 0);
277
+ const values = this._impl.getValues();
278
+ for (let i = 0; i < values.length; i++) {
279
+ values[i] = this._transformValueOut(values[i], this.elementTypeClass);
280
+ }
281
+ return values;
282
+ }
283
+
284
+ //---------------------------------------------------------------------------
285
+ // hasElement()
286
+ //
287
+ // Returns a boolean indicating if an element exists at the specified index.
288
+ //---------------------------------------------------------------------------
289
+ hasElement(index) {
290
+ errors.assertArgCount(arguments, 1, 1);
291
+ errors.assertParamValue(Number.isInteger(index), 1);
292
+ return this._impl.hasElement(index);
293
+ }
294
+
295
+ //---------------------------------------------------------------------------
296
+ // isCollection
297
+ //
298
+ // Property indicating if the object is a collection or not.
299
+ //---------------------------------------------------------------------------
300
+ get isCollection() {
301
+ return this._objType.isCollection;
302
+ }
303
+
304
+ //---------------------------------------------------------------------------
305
+ // name
306
+ //
307
+ // Property for the name of the database object type.
308
+ //---------------------------------------------------------------------------
309
+ get name() {
310
+ return this._objType.name;
311
+ }
312
+
313
+ //---------------------------------------------------------------------------
314
+ // schema
315
+ //
316
+ // Property for the schema of the database object type.
317
+ //---------------------------------------------------------------------------
318
+ get schema() {
319
+ return this._objType.schema;
320
+ }
321
+
322
+ //---------------------------------------------------------------------------
323
+ // setElement()
324
+ //
325
+ // Sets the element in the collection at the specified index to the given
326
+ // value.
327
+ //---------------------------------------------------------------------------
328
+ setElement(index, value) {
329
+ errors.assertArgCount(arguments, 2, 2);
330
+ errors.assertParamValue(Number.isInteger(index), 1);
331
+ const info = {
332
+ fqn: this._objType.fqn,
333
+ type: this._objType.elementType,
334
+ typeClass: this._objType.elementTypeClass
335
+ };
336
+ const options = {allowArray: false};
337
+ value = transformer.transformValueIn(info, value, options);
338
+ this._impl.setElement(index, value);
339
+ }
340
+
341
+ //---------------------------------------------------------------------------
342
+ // trim()
343
+ //
344
+ // Trims the specified number of elements from the end of the collection.
345
+ //---------------------------------------------------------------------------
346
+ trim(numToTrim) {
347
+ errors.assertArgCount(arguments, 1, 1);
348
+ errors.assertParamValue(Number.isInteger(numToTrim) && numToTrim >= 0, 1);
349
+ this._impl.trim(numToTrim);
350
+ }
351
+
67
352
  // custom inspection routine
68
353
  [util.inspect.custom](depth, options) {
69
354
  return ('[' + this.fqn + '] ' + util.inspect(this._toPojo(), options));
@@ -96,6 +381,41 @@ class BaseDbObject {
96
381
 
97
382
  }
98
383
 
384
+ // method for transforming the error
385
+ function transformErr(func) {
386
+ return function() {
387
+ try {
388
+ return func.apply(this, arguments);
389
+ } catch (err) {
390
+ throw errors.transformErr(err, errors.transformErr);
391
+ }
392
+ };
393
+ }
394
+
395
+ // method for wrapping the functions so that any errors thrown are transformed
396
+ function wrapFns(proto) {
397
+ for (let i = 1; i < arguments.length; i++) {
398
+ const name = arguments[i];
399
+ proto[name] = transformErr(proto[name]);
400
+ }
401
+ }
402
+
403
+ wrapFns(BaseDbObject.prototype,
404
+ "_getAttrValue",
405
+ "_setAttrValue",
406
+ "append",
407
+ "deleteElement",
408
+ "getElement",
409
+ "getKeys",
410
+ "getFirstIndex",
411
+ "getLastIndex",
412
+ "getNextIndex",
413
+ "getPrevIndex",
414
+ "getValues",
415
+ "hasElement",
416
+ "setElement",
417
+ "trim"
418
+ );
99
419
 
100
420
  // define proxy handler used for collections
101
421
  BaseDbObject._collectionProxyHandler = {
@@ -112,14 +432,6 @@ BaseDbObject._collectionProxyHandler = {
112
432
 
113
433
  get(target, prop) {
114
434
  if (typeof prop === 'string') {
115
-
116
- // when binding collections, we must be consistent in getting the target
117
- // of the proxy, since napi_wrap() called on the proxy will not be
118
- // available when calling napi_unwrap() on the target; this property
119
- // forces the target to get returned
120
- if (prop === '_target') {
121
- return (target);
122
- }
123
435
  const index = +prop;
124
436
  if (!isNaN(index)) {
125
437
  return (target.getElement(index));
@@ -146,5 +458,7 @@ BaseDbObject._collectionProxyHandler = {
146
458
 
147
459
  };
148
460
 
149
-
150
461
  module.exports = BaseDbObject;
462
+
463
+ // load this after the module exports are set so that it is available
464
+ const transformer = require('./transformer.js');