dolphindb 0.0.10 → 0.0.13
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.zh.md +1 -0
- package/browser.d.ts +21 -1
- package/browser.js +101 -18
- package/browser.js.map +1 -1
- package/index.d.ts +25 -2
- package/index.js +118 -19
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DDB = exports.timestamp2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
|
|
3
|
+
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ws_1 = require("ws");
|
|
6
6
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
7
|
+
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
8
|
+
dayjs_1.default.extend(customParseFormat_js_1.default);
|
|
7
9
|
const utils_js_1 = require("xshell/utils.js");
|
|
8
10
|
var DdbForm;
|
|
9
11
|
(function (DdbForm) {
|
|
@@ -150,7 +152,7 @@ class DdbObj {
|
|
|
150
152
|
le,
|
|
151
153
|
form,
|
|
152
154
|
type,
|
|
153
|
-
length:
|
|
155
|
+
length: i_data + length,
|
|
154
156
|
value,
|
|
155
157
|
});
|
|
156
158
|
}
|
|
@@ -158,7 +160,7 @@ class DdbObj {
|
|
|
158
160
|
case DdbForm.pair:
|
|
159
161
|
case DdbForm.set: {
|
|
160
162
|
let vector = this.parse_vector(buf_data, le, type);
|
|
161
|
-
vector.length +=
|
|
163
|
+
vector.length += i_data;
|
|
162
164
|
vector.form = form;
|
|
163
165
|
return vector;
|
|
164
166
|
}
|
|
@@ -189,17 +191,17 @@ class DdbObj {
|
|
|
189
191
|
let i_start = i_items_start + len_items;
|
|
190
192
|
for (let i = 0; i < cols; i++) {
|
|
191
193
|
const type = buf_data[i_start];
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
let col = this.parse_vector(buf_data.subarray(i_start + 2), le, type);
|
|
195
|
+
col.length += 2;
|
|
194
196
|
col.name = colnames[i];
|
|
195
197
|
value[i] = col;
|
|
196
|
-
i_start
|
|
198
|
+
i_start += col.length;
|
|
197
199
|
}
|
|
198
200
|
return new this({
|
|
199
201
|
le,
|
|
200
202
|
form,
|
|
201
203
|
type,
|
|
202
|
-
length: i_start,
|
|
204
|
+
length: i_data + i_start,
|
|
203
205
|
name,
|
|
204
206
|
rows,
|
|
205
207
|
cols,
|
|
@@ -222,7 +224,7 @@ class DdbObj {
|
|
|
222
224
|
le,
|
|
223
225
|
form,
|
|
224
226
|
type,
|
|
225
|
-
length:
|
|
227
|
+
length: i_data + keys.length + values.length,
|
|
226
228
|
rows: keys.rows,
|
|
227
229
|
cols: 2,
|
|
228
230
|
value: [
|
|
@@ -255,7 +257,7 @@ class DdbObj {
|
|
|
255
257
|
le,
|
|
256
258
|
form,
|
|
257
259
|
type,
|
|
258
|
-
length: 11 + len_items,
|
|
260
|
+
length: i_data + 11 + len_items,
|
|
259
261
|
rows,
|
|
260
262
|
cols,
|
|
261
263
|
datatype,
|
|
@@ -267,7 +269,7 @@ class DdbObj {
|
|
|
267
269
|
le,
|
|
268
270
|
form,
|
|
269
271
|
type,
|
|
270
|
-
length: buf_data.length,
|
|
272
|
+
length: i_data + buf_data.length,
|
|
271
273
|
value: buf_data
|
|
272
274
|
});
|
|
273
275
|
}
|
|
@@ -808,7 +810,7 @@ class DdbObj {
|
|
|
808
810
|
throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
|
|
809
811
|
}
|
|
810
812
|
}
|
|
811
|
-
[utils_js_1.inspect.custom]() {
|
|
813
|
+
[utils_js_1.inspect.custom](depth, options, _inspect) {
|
|
812
814
|
const type = (() => {
|
|
813
815
|
const tname = DdbType[this.type];
|
|
814
816
|
switch (this.form) {
|
|
@@ -823,7 +825,7 @@ class DdbObj {
|
|
|
823
825
|
case DdbForm.pair:
|
|
824
826
|
return `pair<${tname}>`;
|
|
825
827
|
case DdbForm.set:
|
|
826
|
-
return `set<${tname}
|
|
828
|
+
return `set<${tname}>[${this.rows}]`;
|
|
827
829
|
case DdbForm.table:
|
|
828
830
|
return `table[${this.rows} rows][${this.cols} cols]`;
|
|
829
831
|
case DdbForm.dict:
|
|
@@ -836,14 +838,37 @@ class DdbObj {
|
|
|
836
838
|
})();
|
|
837
839
|
const data = (() => {
|
|
838
840
|
if (this.form === DdbForm.pair)
|
|
839
|
-
return `${(0, utils_js_1.inspect)(this.value[0])}, ${(0, utils_js_1.inspect)(this.value[1])}`;
|
|
841
|
+
return `${(0, utils_js_1.inspect)(this.value[0], options)}, ${(0, utils_js_1.inspect)(this.value[1], options)}`;
|
|
840
842
|
if (this.form === DdbForm.scalar && this.type === DdbType.functiondef)
|
|
841
|
-
return (0, utils_js_1.inspect)(this.value.name);
|
|
843
|
+
return (0, utils_js_1.inspect)(this.value.name, options);
|
|
842
844
|
if (this.value instanceof Uint8Array)
|
|
843
|
-
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value));
|
|
844
|
-
return (0, utils_js_1.inspect)(this.value);
|
|
845
|
+
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value), options);
|
|
846
|
+
return (0, utils_js_1.inspect)(this.value, options);
|
|
845
847
|
})();
|
|
846
|
-
return `${type.blue}(${this.name ? `${(0, utils_js_1.inspect)(this.name)}, ` : ''}${data})`;
|
|
848
|
+
return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
|
|
849
|
+
}
|
|
850
|
+
to_rows() {
|
|
851
|
+
if (this.form !== DdbForm.table)
|
|
852
|
+
throw new Error('this.form is not DdbForm.table, cannot call to_rows');
|
|
853
|
+
let rows = new Array(this.rows);
|
|
854
|
+
for (let i = 0; i < this.rows; i++) {
|
|
855
|
+
let row = {};
|
|
856
|
+
for (let j = 0; j < this.cols; j++) {
|
|
857
|
+
const { type, name, value } = this.value[j]; // column
|
|
858
|
+
switch (type) {
|
|
859
|
+
case DdbType.bool:
|
|
860
|
+
row[name] = Boolean(value[i]);
|
|
861
|
+
break;
|
|
862
|
+
case DdbType.ipaddr:
|
|
863
|
+
row[name] = value.subarray(16 * i, 16 * (i + 1));
|
|
864
|
+
break;
|
|
865
|
+
default:
|
|
866
|
+
row[name] = value[i];
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
rows[i] = row;
|
|
870
|
+
}
|
|
871
|
+
return rows;
|
|
847
872
|
}
|
|
848
873
|
to_dict() {
|
|
849
874
|
if (this.form !== DdbForm.dict)
|
|
@@ -883,6 +908,17 @@ class DdbBool extends DdbObj {
|
|
|
883
908
|
}
|
|
884
909
|
}
|
|
885
910
|
exports.DdbBool = DdbBool;
|
|
911
|
+
class DdbChar extends DdbObj {
|
|
912
|
+
constructor(value) {
|
|
913
|
+
super({
|
|
914
|
+
form: DdbForm.scalar,
|
|
915
|
+
type: DdbType.char,
|
|
916
|
+
length: 1,
|
|
917
|
+
value,
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
exports.DdbChar = DdbChar;
|
|
886
922
|
class DdbInt extends DdbObj {
|
|
887
923
|
constructor(value) {
|
|
888
924
|
super({
|
|
@@ -927,6 +963,39 @@ class DdbDouble extends DdbObj {
|
|
|
927
963
|
}
|
|
928
964
|
}
|
|
929
965
|
exports.DdbDouble = DdbDouble;
|
|
966
|
+
class DdbDateTime extends DdbObj {
|
|
967
|
+
constructor(value) {
|
|
968
|
+
super({
|
|
969
|
+
form: DdbForm.scalar,
|
|
970
|
+
type: DdbType.datetime,
|
|
971
|
+
length: 4,
|
|
972
|
+
value
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
exports.DdbDateTime = DdbDateTime;
|
|
977
|
+
class DdbTimeStamp extends DdbObj {
|
|
978
|
+
constructor(value) {
|
|
979
|
+
super({
|
|
980
|
+
form: DdbForm.scalar,
|
|
981
|
+
type: DdbType.timestamp,
|
|
982
|
+
length: 8,
|
|
983
|
+
value
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
exports.DdbTimeStamp = DdbTimeStamp;
|
|
988
|
+
class DdbNanoTimeStamp extends DdbObj {
|
|
989
|
+
constructor(value) {
|
|
990
|
+
super({
|
|
991
|
+
form: DdbForm.scalar,
|
|
992
|
+
type: DdbType.nanotimestamp,
|
|
993
|
+
length: 8,
|
|
994
|
+
value
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
930
999
|
class DdbVectorInt extends DdbObj {
|
|
931
1000
|
constructor(value, name) {
|
|
932
1001
|
super({
|
|
@@ -1007,13 +1076,20 @@ class DdbFunction extends DdbObj {
|
|
|
1007
1076
|
}
|
|
1008
1077
|
}
|
|
1009
1078
|
exports.DdbFunction = DdbFunction;
|
|
1010
|
-
function date2str(date) {
|
|
1079
|
+
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1011
1080
|
return date === exports.nulls.int32 ?
|
|
1012
1081
|
''
|
|
1013
1082
|
:
|
|
1014
|
-
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(
|
|
1083
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1015
1084
|
}
|
|
1016
1085
|
exports.date2str = date2str;
|
|
1086
|
+
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1087
|
+
return datetime === exports.nulls.int32 ?
|
|
1088
|
+
''
|
|
1089
|
+
:
|
|
1090
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1091
|
+
}
|
|
1092
|
+
exports.datetime2str = datetime2str;
|
|
1017
1093
|
function timestamp2str(timestamp) {
|
|
1018
1094
|
return timestamp === exports.nulls.int64 ?
|
|
1019
1095
|
''
|
|
@@ -1021,6 +1097,29 @@ function timestamp2str(timestamp) {
|
|
|
1021
1097
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format('YYYY.MM.DD HH:mm:ss.SSS');
|
|
1022
1098
|
}
|
|
1023
1099
|
exports.timestamp2str = timestamp2str;
|
|
1100
|
+
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1101
|
+
return nanotimestamp === exports.nulls.int64 ?
|
|
1102
|
+
''
|
|
1103
|
+
:
|
|
1104
|
+
(0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format) + `.${nanotimestamp % 1000000000n}`;
|
|
1105
|
+
}
|
|
1106
|
+
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1107
|
+
/** parse nano timestamp string to bigint value
|
|
1108
|
+
- str: nano timestamp string, 如果为空字符串会返回对应的空值 (nulls.int64)
|
|
1109
|
+
- format?: 对应传入字符串的到秒之前 (包括) 的格式串,默认是 `YYYY.MM.DD HH:mm:ss`
|
|
1110
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1111
|
+
*/
|
|
1112
|
+
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1113
|
+
if (!str)
|
|
1114
|
+
return exports.nulls.int64;
|
|
1115
|
+
if (str.length - format.length !== 9)
|
|
1116
|
+
throw new Error('nanotimestamp 字符串长度减格式串长度应该等于 9');
|
|
1117
|
+
return (BigInt(-exports.timezone_offset +
|
|
1118
|
+
(0, dayjs_1.default)(str.slice(0, format.length), format).valueOf()) * 1000000n
|
|
1119
|
+
+
|
|
1120
|
+
BigInt(str.slice(format.length)));
|
|
1121
|
+
}
|
|
1122
|
+
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1024
1123
|
class DDB {
|
|
1025
1124
|
/**
|
|
1026
1125
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|