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,630 @@
1
+ // Copyright (c) 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 { Buffer } = require('buffer');
30
+ const constants = require('./protocol/constants.js');
31
+ const errors = require('../errors.js');
32
+ const types = require('../types.js');
33
+ const DbObjectImpl = require('../impl/dbObject.js');
34
+ const { GrowableBuffer } = require('./protocol/buffer.js');
35
+
36
+ class DbObjectPickleBuffer extends GrowableBuffer {
37
+
38
+ //---------------------------------------------------------------------------
39
+ // getIsAtomicNull()
40
+ //
41
+ // Reads the next byte and checks to see if the value is atomically null. If
42
+ // not, the byte is returned to the buffer for further processing.
43
+ //---------------------------------------------------------------------------
44
+ getIsAtomicNull() {
45
+ const value = this.readUInt8();
46
+ if (value === constants.TNS_OBJ_ATOMIC_NULL ||
47
+ value === constants.TNS_NULL_LENGTH_INDICATOR) {
48
+ return true;
49
+ }
50
+ this.pos -= 1;
51
+ return false;
52
+ }
53
+
54
+ //---------------------------------------------------------------------------
55
+ // readHeader()
56
+ //
57
+ // Reads the header of the pickled data.
58
+ //---------------------------------------------------------------------------
59
+ readHeader(obj) {
60
+ obj.imageFlags = this.readUInt8();
61
+ obj.imageVersion = this.readUInt8();
62
+ this.readLength();
63
+ if ((obj.imageFlags & constants.TNS_OBJ_NO_PREFIX_SEG) === 0) {
64
+ const prefixSegLength = this.readLength();
65
+ this.skipBytes(prefixSegLength);
66
+ }
67
+ }
68
+
69
+ //---------------------------------------------------------------------------
70
+ // readLength()
71
+ //
72
+ // Read the length from the buffer. This will be a single byte, unless the
73
+ // value meets or exeeds TNS_LONG_LENGTH_INDICATOR. In that case, the value
74
+ // is stored as a 4-byte integer.
75
+ //---------------------------------------------------------------------------
76
+ readLength() {
77
+ const shortLength = this.readUInt8();
78
+ if (shortLength !== constants.TNS_LONG_LENGTH_INDICATOR) {
79
+ return shortLength;
80
+ }
81
+ return this.readUInt32BE();
82
+ }
83
+
84
+ //---------------------------------------------------------------------------
85
+ // writeHeader()
86
+ //
87
+ // Writes the header of the pickled data. Since the size is unknown at this
88
+ // point, zero is written initially and the actual size is written later.
89
+ //---------------------------------------------------------------------------
90
+ writeHeader(obj) {
91
+ this.writeUInt8(obj.imageFlags);
92
+ this.writeUInt8(obj.imageVersion);
93
+ this.writeUInt8(constants.TNS_LONG_LENGTH_INDICATOR);
94
+ this.writeUInt32BE(0);
95
+ if (obj._objType.isCollection) {
96
+ this.writeUInt8(1); // length of prefix segment
97
+ this.writeUInt8(1); // prefix segment contents
98
+ }
99
+ }
100
+
101
+ //---------------------------------------------------------------------------
102
+ // writeLength()
103
+ //
104
+ // Writes the length to the buffer.
105
+ //---------------------------------------------------------------------------
106
+ writeLength(length) {
107
+ if (length <= constants.TNS_OBJ_MAX_SHORT_LENGTH) {
108
+ this.writeUInt8(length);
109
+ } else {
110
+ this.writeUInt8(constants.TNS_LONG_LENGTH_INDICATOR);
111
+ this.writeUInt32BE(length);
112
+ }
113
+ }
114
+
115
+ }
116
+
117
+ class ThinDbObjectImpl extends DbObjectImpl {
118
+
119
+ constructor(objType, packedData) {
120
+ if (typeof objType === 'function') {
121
+ objType = objType.prototype._objType;
122
+ }
123
+ super(objType);
124
+ this.packedData = packedData;
125
+ this.unpackedAttrs = new Map();
126
+ if (packedData) {
127
+ this.unpackedAssocArray = new Map();
128
+ this.unpackedAssocKeys = undefined;
129
+ } else if (objType) {
130
+ const prefix = Buffer.from([0, 0x22, constants.TNS_OBJ_NON_NULL_OID,
131
+ constants.TNS_OBJ_HAS_EXTENT_OID]);
132
+ this.toid = Buffer.concat([prefix, objType.oid, constants.TNS_EXTENT_OID]);
133
+ this.flags = constants.TNS_OBJ_TOP_LEVEL;
134
+ this.imageFlags = constants.TNS_OBJ_IS_VERSION_81;
135
+ this.imageVersion = constants.TNS_OBJ_IMAGE_VERSION;
136
+ if (objType.isCollection) {
137
+ this.imageFlags |= constants.TNS_OBJ_IS_COLLECTION;
138
+ if (objType.collectionType === constants.TNS_OBJ_PLSQL_INDEX_TABLE) {
139
+ this.unpackedAssocArray = new Map();
140
+ } else {
141
+ this.unpackedArray = [];
142
+ }
143
+ } else {
144
+ this.imageFlags |= constants.TNS_OBJ_NO_PREFIX_SEG;
145
+ }
146
+ }
147
+ }
148
+
149
+ //---------------------------------------------------------------------------
150
+ // _ensureAssocKeys()
151
+ //
152
+ // Ensure that the keys for the associative array have been calculated.
153
+ // PL/SQL associative arrays keep their keys in sorted order so this must be
154
+ // calculated when indices are required.
155
+ //---------------------------------------------------------------------------
156
+ _ensureAssocKeys() {
157
+ if (!this.unpackedAssocKeys) {
158
+ this.unpackedAssocKeys = [...this.unpackedAssocArray.keys()].sort();
159
+ }
160
+ }
161
+
162
+ //---------------------------------------------------------------------------
163
+ // _ensureUnpacked()
164
+ //
165
+ // Ensure that the data has been unpacked.
166
+ //---------------------------------------------------------------------------
167
+ _ensureUnpacked() {
168
+ if (this.packedData) {
169
+ this._unpackData();
170
+ }
171
+ }
172
+
173
+ //---------------------------------------------------------------------------
174
+ // _getPackedData()
175
+ //
176
+ // Returns the packed data for the object. This will either be the value
177
+ // retrieved from the database or generated packed data (for new objects and
178
+ // those that have had their data unpacked already).
179
+ //---------------------------------------------------------------------------
180
+ _getPackedData() {
181
+ if (this.packedData)
182
+ return this.packedData;
183
+ const buf = new DbObjectPickleBuffer();
184
+ buf.writeHeader(this);
185
+ this._packData(buf);
186
+ const size = buf.pos;
187
+ buf.pos = 3;
188
+ buf.writeUInt32BE(size);
189
+ return buf.buf.subarray(0, size);
190
+ }
191
+
192
+ //---------------------------------------------------------------------------
193
+ // _packData()
194
+ //
195
+ // Packs the data from the object into the buffer.
196
+ //---------------------------------------------------------------------------
197
+ _packData(buf) {
198
+ const objType = this._objType;
199
+ if (objType.isCollection) {
200
+ buf.writeUInt8(objType.collectionFlags);
201
+ if (objType.collectionType === constants.TNS_OBJ_PLSQL_INDEX_TABLE) {
202
+ this._ensureAssocKeys();
203
+ buf.writeLength(this.unpackedAssocKeys.length);
204
+ for (const index of this.unpackedAssocKeys) {
205
+ buf.writeInt32BE(index);
206
+ this._packValue(buf, objType.elementType, objType.elementTypeClass,
207
+ this.unpackedAssocArray.get(index));
208
+ }
209
+ } else {
210
+ buf.writeLength(this.unpackedArray.length);
211
+ for (const value of this.unpackedArray) {
212
+ this._packValue(buf, objType.elementType, objType.elementTypeClass,
213
+ value);
214
+ }
215
+ }
216
+ } else {
217
+ for (const attr of objType.attributes) {
218
+ this._packValue(buf, attr.type, attr.typeClass,
219
+ this.unpackedAttrs.get(attr.name));
220
+ }
221
+ }
222
+ }
223
+
224
+ //---------------------------------------------------------------------------
225
+ // _packValue()
226
+ //
227
+ // Packs a value into the buffer. At this point it is assumed that the value
228
+ // matches the correct type.
229
+ //---------------------------------------------------------------------------
230
+ _packValue(buf, type, typeClass, value) {
231
+ if (value === null || value === undefined) {
232
+ if (typeClass && !typeClass.prototype.isCollection) {
233
+ buf.writeUInt8(constants.TNS_OBJ_ATOMIC_NULL);
234
+ } else {
235
+ buf.writeUInt8(constants.TNS_NULL_LENGTH_INDICATOR);
236
+ }
237
+ } else {
238
+ switch (type) {
239
+ case types.DB_TYPE_CHAR:
240
+ case types.DB_TYPE_VARCHAR:
241
+ buf.writeBytesWithLength(Buffer.from(value));
242
+ break;
243
+ case types.DB_TYPE_NCHAR:
244
+ case types.DB_TYPE_NVARCHAR:
245
+ buf.writeBytesWithLength(Buffer.from(value, 'utf16le').swap16());
246
+ break;
247
+ case types.DB_TYPE_NUMBER:
248
+ buf.writeOracleNumber(value.toString());
249
+ break;
250
+ case types.DB_TYPE_BINARY_INTEGER:
251
+ case types.DB_TYPE_BOOLEAN:
252
+ buf.writeUInt8(4);
253
+ buf.writeUInt32BE(value);
254
+ break;
255
+ case types.DB_TYPE_RAW:
256
+ buf.writeBytesWithLength(value);
257
+ break;
258
+ case types.DB_TYPE_BINARY_DOUBLE:
259
+ buf.writeBinaryDouble(value);
260
+ break;
261
+ case types.DB_TYPE_BINARY_FLOAT:
262
+ buf.writeBinaryFloat(value);
263
+ break;
264
+ case types.DB_TYPE_DATE:
265
+ case types.DB_TYPE_TIMESTAMP:
266
+ case types.DB_TYPE_TIMESTAMP_LTZ:
267
+ case types.DB_TYPE_TIMESTAMP_TZ:
268
+ buf.writeOracleDate(value, type);
269
+ break;
270
+ case types.DB_TYPE_OBJECT:
271
+ if (this._objType.isCollection || value._objType.isCollection) {
272
+ buf.writeBytesWithLength(value._getPackedData());
273
+ } else {
274
+ value._packData(buf);
275
+ }
276
+ break;
277
+ default:
278
+ errors.throwErr(errors.ERR_NOT_IMPLEMENTED, type);
279
+ }
280
+ }
281
+ }
282
+
283
+ //---------------------------------------------------------------------------
284
+ // _unpackData()
285
+ //
286
+ // Unpacks the packed data into a map of JavaScript values.
287
+ //---------------------------------------------------------------------------
288
+ _unpackData() {
289
+ const buf = new DbObjectPickleBuffer(this.packedData);
290
+ buf.readHeader(this);
291
+ this._unpackDataFromBuf(buf);
292
+ this.packedData = undefined;
293
+ }
294
+
295
+ //---------------------------------------------------------------------------
296
+ // _unpackDataFromBuf()
297
+ //
298
+ // Unpacks the data in the buffer into a map of JavaScript values.
299
+ //---------------------------------------------------------------------------
300
+ _unpackDataFromBuf(buf) {
301
+ let unpackedArray, unpackedAssocArray, assocIndex, unpackedAttrs;
302
+ const objType = this._objType;
303
+ if (objType.isCollection) {
304
+ if (objType.collectionType === constants.TNS_OBJ_PLSQL_INDEX_TABLE) {
305
+ unpackedAssocArray = new Map();
306
+ } else {
307
+ unpackedArray = [];
308
+ }
309
+ this.collectionFlags = buf.readUInt8();
310
+ const numElements = buf.readLength();
311
+ for (let i = 0; i < numElements; i++) {
312
+ if (objType.collectionType === constants.TNS_OBJ_PLSQL_INDEX_TABLE) {
313
+ assocIndex = buf.readUInt32BE();
314
+ }
315
+ const value = this._unpackValue(buf, objType.elementType,
316
+ objType.elementTypeClass);
317
+ if (objType.collectionType === constants.TNS_OBJ_PLSQL_INDEX_TABLE) {
318
+ unpackedAssocArray.set(assocIndex, value);
319
+ } else {
320
+ unpackedArray.push(value);
321
+ }
322
+ }
323
+ } else {
324
+ unpackedAttrs = new Map();
325
+ for (const attr of objType.attributes) {
326
+ const value = this._unpackValue(buf, attr.type, attr.typeClass);
327
+ unpackedAttrs.set(attr.name, value);
328
+ }
329
+ }
330
+ this.unpackedAttrs = unpackedAttrs;
331
+ this.unpackedArray = unpackedArray;
332
+ this.unpackedAssocArray = unpackedAssocArray;
333
+ }
334
+
335
+ //---------------------------------------------------------------------------
336
+ // _unpackValue()
337
+ //
338
+ // Unpacks a single value and returns it.
339
+ //---------------------------------------------------------------------------
340
+ _unpackValue(buf, type, typeClass) {
341
+ let isNull, obj, value;
342
+ switch (type) {
343
+ case types.DB_TYPE_NUMBER:
344
+ value = buf.readOracleNumber();
345
+ if (value !== null)
346
+ value = parseFloat(value);
347
+ return value;
348
+ case types.DB_TYPE_BINARY_INTEGER:
349
+ return buf.readBinaryInteger();
350
+ case types.DB_TYPE_VARCHAR:
351
+ case types.DB_TYPE_CHAR:
352
+ return buf.readStr(constants.TNS_CS_IMPLICIT);
353
+ case types.DB_TYPE_NVARCHAR:
354
+ case types.DB_TYPE_NCHAR:
355
+ return buf.readStr(constants.TNS_CS_NCHAR);
356
+ case types.DB_TYPE_RAW:
357
+ return buf.readBytesWithLength();
358
+ case types.DB_TYPE_BINARY_DOUBLE:
359
+ return buf.readBinaryDouble();
360
+ case types.DB_TYPE_BINARY_FLOAT:
361
+ return buf.readBinaryFloat();
362
+ case types.DB_TYPE_DATE:
363
+ case types.DB_TYPE_TIMESTAMP:
364
+ return buf.readOracleDate(true);
365
+ case types.DB_TYPE_TIMESTAMP_LTZ:
366
+ case types.DB_TYPE_TIMESTAMP_TZ:
367
+ return buf.readOracleDate(false);
368
+ case types.DB_TYPE_BLOB:
369
+ case types.DB_TYPE_BOOLEAN:
370
+ return buf.readBool();
371
+ case types.DB_TYPE_OBJECT:
372
+ isNull = buf.getIsAtomicNull();
373
+ if (isNull)
374
+ return null;
375
+ obj = new ThinDbObjectImpl(typeClass);
376
+ if (obj._objType.isCollection || this._objType.isCollection) {
377
+ obj.packedData = buf.readBytesWithLength();
378
+ } else {
379
+ obj._unpackDataFromBuf(buf);
380
+ }
381
+ return obj;
382
+ default:
383
+ errors.throwErr(errors.ERR_NOT_IMPLEMENTED, type);
384
+ }
385
+ }
386
+
387
+ //---------------------------------------------------------------------------
388
+ // append()
389
+ //
390
+ // Appends an element to the collection.
391
+ //---------------------------------------------------------------------------
392
+ append(value) {
393
+ this._ensureUnpacked();
394
+ if (this.unpackedArray) {
395
+ const objType = this._objType;
396
+ if (objType.maxNumElements > 0 &&
397
+ this.unpackedArray.length >= objType.maxNumElements) {
398
+ errors.throwErr(errors.ERR_INVALID_COLL_INDEX_SET,
399
+ this.unpackedArray.length, 0, objType.maxNumElements);
400
+ }
401
+ this.unpackedArray.push(value);
402
+ } else {
403
+ this._ensureAssocKeys();
404
+ let newIndex;
405
+ if (this.unpackedAssocKeys.length === 0) {
406
+ newIndex = 0;
407
+ } else {
408
+ const keyIndex = this.unpackedAssocKeys.length - 1;
409
+ newIndex = this.unpackedAssocKeys[keyIndex] + 1;
410
+ }
411
+ this.unpackedAssocArray.set(newIndex, value);
412
+ this.unpackedAssocKeys.push(newIndex);
413
+ }
414
+ }
415
+
416
+ //---------------------------------------------------------------------------
417
+ // deleteElement()
418
+ //
419
+ // Deletes an element from a collection.
420
+ //---------------------------------------------------------------------------
421
+ deleteElement(index) {
422
+ this._ensureUnpacked();
423
+ if (this.unpackedArray) {
424
+ if (this._objType.collectionType == constants.TNS_OBJ_VARRAY) {
425
+ errors.throwErr(errors.ERR_DELETE_ELEMENTS_OF_VARRAY);
426
+ }
427
+ this.unpackedArray.splice(index, 1);
428
+ } else {
429
+ this._unpackedAssocKeys = undefined;
430
+ this.unpackedAssocArray.delete(index);
431
+ }
432
+ }
433
+
434
+ //---------------------------------------------------------------------------
435
+ // getAttrValue()
436
+ //
437
+ // Returns the value of the given attribute on the object.
438
+ //---------------------------------------------------------------------------
439
+ getAttrValue(attr) {
440
+ this._ensureUnpacked();
441
+ const value = this.unpackedAttrs.get(attr.name);
442
+ if (value === undefined)
443
+ return null;
444
+ return value;
445
+ }
446
+
447
+ //---------------------------------------------------------------------------
448
+ // getElement()
449
+ //
450
+ // Returns an element from the collection.
451
+ //---------------------------------------------------------------------------
452
+ getElement(index) {
453
+ let value;
454
+ this._ensureUnpacked();
455
+ if (this.unpackedArray) {
456
+ value = this.unpackedArray[index];
457
+ } else {
458
+ value = this.unpackedAssocArray.get(index);
459
+ }
460
+ if (value === undefined) {
461
+ errors.throwErr(errors.ERR_INVALID_COLL_INDEX_GET, index);
462
+ }
463
+ return value;
464
+ }
465
+
466
+ //---------------------------------------------------------------------------
467
+ // getFirstIndex()
468
+ //
469
+ // Returns the first index in a collection.
470
+ //---------------------------------------------------------------------------
471
+ getFirstIndex() {
472
+ this._ensureUnpacked();
473
+ if (this.unpackedArray) {
474
+ return 0;
475
+ } else if (this.unpackedAssocArray) {
476
+ this._ensureAssocKeys();
477
+ return this.unpackedAssocKeys[0];
478
+ }
479
+ }
480
+
481
+ //---------------------------------------------------------------------------
482
+ // getKeys()
483
+ //
484
+ // Returns the keys of the collection in a JavaScript array.
485
+ //---------------------------------------------------------------------------
486
+ getKeys() {
487
+ this._ensureUnpacked();
488
+ if (this.unpackedArray) {
489
+ return Array.from(this.unpackedArray.keys());
490
+ } else if (this.unpackedAssocArray) {
491
+ this._ensureAssocKeys();
492
+ return Array.from(this.unpackedAssocKeys);
493
+ }
494
+ return [];
495
+ }
496
+
497
+ //---------------------------------------------------------------------------
498
+ // getLastIndex()
499
+ //
500
+ // Returns the last index in a collection.
501
+ //---------------------------------------------------------------------------
502
+ getLastIndex() {
503
+ this._ensureUnpacked();
504
+ if (this.unpackedArray) {
505
+ if (this.unpackedArray.length > 0)
506
+ return this.unpackedArray.length - 1;
507
+ } else if (this.unpackedAssocArray) {
508
+ this._ensureAssocKeys();
509
+ return this.unpackedAssocKeys[this.unpackedAssocKeys.length - 1];
510
+ }
511
+ }
512
+
513
+ //---------------------------------------------------------------------------
514
+ // getNextIndex()
515
+ //
516
+ // Returns the next index in a collection.
517
+ //---------------------------------------------------------------------------
518
+ getNextIndex(index) {
519
+ this._ensureUnpacked();
520
+ if (this.unpackedArray) {
521
+ if (index + 1 < this.unpackedArray.length) {
522
+ return index + 1;
523
+ }
524
+ } else if (this.unpackedAssocArray) {
525
+ this._ensureAssocKeys();
526
+ for (const key of this.unpackedAssocKeys) {
527
+ if (key > index)
528
+ return key;
529
+ }
530
+ }
531
+ }
532
+
533
+ //---------------------------------------------------------------------------
534
+ // getPrevIndex()
535
+ //
536
+ // Returns the previous index in a collection.
537
+ //---------------------------------------------------------------------------
538
+ getPrevIndex(index) {
539
+ this._ensureUnpacked();
540
+ if (this.unpackedArray) {
541
+ if (index > 0) {
542
+ return index - 1;
543
+ }
544
+ } else if (this.unpackedAssocArray) {
545
+ this._ensureAssocKeys();
546
+ for (const key of this.unpackedAssocKeys.reverse()) {
547
+ if (key < index)
548
+ return key;
549
+ }
550
+ }
551
+ }
552
+
553
+ //---------------------------------------------------------------------------
554
+ // getValues()
555
+ //
556
+ // Returns the values of the collection in a JavaScript array.
557
+ //---------------------------------------------------------------------------
558
+ getValues() {
559
+ const result = [];
560
+ this._ensureUnpacked();
561
+ if (this.unpackedArray) {
562
+ return Array.from(this.unpackedArray);
563
+ } else if (this.unpackedAssocArray) {
564
+ this._ensureAssocKeys();
565
+ for (const key of this.unpackedAssocKeys) {
566
+ result.push(this.unpackedAssocArray.get(key));
567
+ }
568
+ }
569
+ return result;
570
+ }
571
+
572
+ //---------------------------------------------------------------------------
573
+ // hasElement()
574
+ //
575
+ // Returns whether an element exists at the given index.
576
+ //---------------------------------------------------------------------------
577
+ hasElement(index) {
578
+ this._ensureUnpacked();
579
+ if (this.unpackedArray) {
580
+ return (index >= 0 && index < this.unpackedArray.length);
581
+ }
582
+ return this.unpackedAssocArray.has(index);
583
+ }
584
+
585
+ //---------------------------------------------------------------------------
586
+ // setAttrValue()
587
+ //
588
+ // Sets the value of the attribute on the object to the given value.
589
+ //---------------------------------------------------------------------------
590
+ setAttrValue(attr, value) {
591
+ this._ensureUnpacked();
592
+ this.unpackedAttrs.set(attr.name, value);
593
+ }
594
+
595
+ //---------------------------------------------------------------------------
596
+ // setElement()
597
+ //
598
+ // Sets an entry in a collection that is indexed by integers.
599
+ //---------------------------------------------------------------------------
600
+ setElement(index, value) {
601
+ this._ensureUnpacked();
602
+ if (this.unpackedArray) {
603
+ const maxIndex = Math.max(this.unpackedArray.length - 1, 0);
604
+ if (index > maxIndex) {
605
+ errors.throwErr(errors.ERR_INVALID_COLL_INDEX_SET, index, 0, maxIndex);
606
+ }
607
+ this.unpackedArray[index] = value;
608
+ } else {
609
+ if (!this.unpackedAssocArray.has(index))
610
+ this.unpackedAssocKeys = undefined;
611
+ this.unpackedAssocArray.set(index, value);
612
+ }
613
+ }
614
+
615
+ //---------------------------------------------------------------------------
616
+ // trim()
617
+ //
618
+ // Trim the specified number of elements from the end of the collection.
619
+ //---------------------------------------------------------------------------
620
+ trim(numToTrim) {
621
+ this._ensureUnpacked();
622
+ if (numToTrim > 0) {
623
+ this.unpackedArray = this.unpackedArray.slice(0,
624
+ this.unpackedArray.length - numToTrim);
625
+ }
626
+ }
627
+
628
+ }
629
+
630
+ module.exports = ThinDbObjectImpl;
@@ -0,0 +1,40 @@
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 ThinConnectionImpl = require('./connection.js');
30
+ const ThinResultSetImpl = require('./resultSet.js');
31
+ const ThinPoolImpl = require('./pool.js');
32
+ const ThinLobImpl = require('./lob.js');
33
+ const ThinDbObjectImpl = require('./dbObject.js');
34
+
35
+ const impl = require('../impl');
36
+ impl.ConnectionImpl = ThinConnectionImpl;
37
+ impl.ResultSetImpl = ThinResultSetImpl;
38
+ impl.PoolImpl = ThinPoolImpl;
39
+ impl.LobImpl = ThinLobImpl;
40
+ impl.DbObjectImpl = ThinDbObjectImpl;