dolphindb 0.0.12 → 0.0.15
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 +25 -3
- package/browser.js +91 -31
- package/browser.js.map +1 -1
- package/index.d.ts +29 -4
- package/index.js +108 -32
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = 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"));
|
|
@@ -152,7 +152,7 @@ class DdbObj {
|
|
|
152
152
|
le,
|
|
153
153
|
form,
|
|
154
154
|
type,
|
|
155
|
-
length:
|
|
155
|
+
length: i_data + length,
|
|
156
156
|
value,
|
|
157
157
|
});
|
|
158
158
|
}
|
|
@@ -160,7 +160,7 @@ class DdbObj {
|
|
|
160
160
|
case DdbForm.pair:
|
|
161
161
|
case DdbForm.set: {
|
|
162
162
|
let vector = this.parse_vector(buf_data, le, type);
|
|
163
|
-
vector.length +=
|
|
163
|
+
vector.length += i_data;
|
|
164
164
|
vector.form = form;
|
|
165
165
|
return vector;
|
|
166
166
|
}
|
|
@@ -191,17 +191,17 @@ class DdbObj {
|
|
|
191
191
|
let i_start = i_items_start + len_items;
|
|
192
192
|
for (let i = 0; i < cols; i++) {
|
|
193
193
|
const type = buf_data[i_start];
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
let col = this.parse_vector(buf_data.subarray(i_start + 2), le, type);
|
|
195
|
+
col.length += 2;
|
|
196
196
|
col.name = colnames[i];
|
|
197
197
|
value[i] = col;
|
|
198
|
-
i_start
|
|
198
|
+
i_start += col.length;
|
|
199
199
|
}
|
|
200
200
|
return new this({
|
|
201
201
|
le,
|
|
202
202
|
form,
|
|
203
203
|
type,
|
|
204
|
-
length: i_start,
|
|
204
|
+
length: i_data + i_start,
|
|
205
205
|
name,
|
|
206
206
|
rows,
|
|
207
207
|
cols,
|
|
@@ -224,7 +224,7 @@ class DdbObj {
|
|
|
224
224
|
le,
|
|
225
225
|
form,
|
|
226
226
|
type,
|
|
227
|
-
length:
|
|
227
|
+
length: i_data + keys.length + values.length,
|
|
228
228
|
rows: keys.rows,
|
|
229
229
|
cols: 2,
|
|
230
230
|
value: [
|
|
@@ -257,7 +257,7 @@ class DdbObj {
|
|
|
257
257
|
le,
|
|
258
258
|
form,
|
|
259
259
|
type,
|
|
260
|
-
length: 11 + len_items,
|
|
260
|
+
length: i_data + 11 + len_items,
|
|
261
261
|
rows,
|
|
262
262
|
cols,
|
|
263
263
|
datatype,
|
|
@@ -269,7 +269,7 @@ class DdbObj {
|
|
|
269
269
|
le,
|
|
270
270
|
form,
|
|
271
271
|
type,
|
|
272
|
-
length: buf_data.length,
|
|
272
|
+
length: i_data + buf_data.length,
|
|
273
273
|
value: buf_data
|
|
274
274
|
});
|
|
275
275
|
}
|
|
@@ -810,7 +810,7 @@ class DdbObj {
|
|
|
810
810
|
throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
|
|
811
811
|
}
|
|
812
812
|
}
|
|
813
|
-
[utils_js_1.inspect.custom]() {
|
|
813
|
+
[utils_js_1.inspect.custom](depth, options, _inspect) {
|
|
814
814
|
const type = (() => {
|
|
815
815
|
const tname = DdbType[this.type];
|
|
816
816
|
switch (this.form) {
|
|
@@ -825,7 +825,7 @@ class DdbObj {
|
|
|
825
825
|
case DdbForm.pair:
|
|
826
826
|
return `pair<${tname}>`;
|
|
827
827
|
case DdbForm.set:
|
|
828
|
-
return `set<${tname}
|
|
828
|
+
return `set<${tname}>[${this.rows}]`;
|
|
829
829
|
case DdbForm.table:
|
|
830
830
|
return `table[${this.rows} rows][${this.cols} cols]`;
|
|
831
831
|
case DdbForm.dict:
|
|
@@ -838,14 +838,42 @@ class DdbObj {
|
|
|
838
838
|
})();
|
|
839
839
|
const data = (() => {
|
|
840
840
|
if (this.form === DdbForm.pair)
|
|
841
|
-
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)}`;
|
|
842
842
|
if (this.form === DdbForm.scalar && this.type === DdbType.functiondef)
|
|
843
|
-
return (0, utils_js_1.inspect)(this.value.name);
|
|
843
|
+
return (0, utils_js_1.inspect)(this.value.name, options);
|
|
844
844
|
if (this.value instanceof Uint8Array)
|
|
845
|
-
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value));
|
|
846
|
-
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);
|
|
847
847
|
})();
|
|
848
|
-
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
|
+
case DdbType.symbol_extended: {
|
|
866
|
+
const { base, data } = value;
|
|
867
|
+
row[name] = base[data[i]];
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
default:
|
|
871
|
+
row[name] = value[i];
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
rows[i] = row;
|
|
875
|
+
}
|
|
876
|
+
return rows;
|
|
849
877
|
}
|
|
850
878
|
to_dict() {
|
|
851
879
|
if (this.form !== DdbForm.dict)
|
|
@@ -1067,34 +1095,79 @@ function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
|
1067
1095
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1068
1096
|
}
|
|
1069
1097
|
exports.datetime2str = datetime2str;
|
|
1070
|
-
|
|
1098
|
+
/** format timestamp (bigint) to string
|
|
1099
|
+
- timestamp: bigint value
|
|
1100
|
+
- format?:
|
|
1101
|
+
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1102
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1103
|
+
*/
|
|
1104
|
+
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1071
1105
|
return timestamp === exports.nulls.int64 ?
|
|
1072
1106
|
''
|
|
1073
1107
|
:
|
|
1074
|
-
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(
|
|
1108
|
+
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1075
1109
|
}
|
|
1076
1110
|
exports.timestamp2str = timestamp2str;
|
|
1077
|
-
|
|
1078
|
-
return
|
|
1079
|
-
|
|
1080
|
-
:
|
|
1081
|
-
|
|
1111
|
+
/** parse timestamp string to bigint value
|
|
1112
|
+
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1113
|
+
- format?:
|
|
1114
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1115
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1116
|
+
*/
|
|
1117
|
+
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1118
|
+
if (!str)
|
|
1119
|
+
return exports.nulls.int64;
|
|
1120
|
+
if (str.length !== format.length)
|
|
1121
|
+
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
1122
|
+
return BigInt(-exports.timezone_offset +
|
|
1123
|
+
(0, dayjs_1.default)(str, format).valueOf());
|
|
1124
|
+
}
|
|
1125
|
+
exports.str2timestamp = str2timestamp;
|
|
1126
|
+
/** format nanotimestamp value (bigint) to string
|
|
1127
|
+
- nanotimestamp: bigint value
|
|
1128
|
+
- format?:
|
|
1129
|
+
format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1130
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1131
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1132
|
+
*/
|
|
1133
|
+
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1134
|
+
if (nanotimestamp === exports.nulls.int64)
|
|
1135
|
+
return '';
|
|
1136
|
+
const i_second_start = format.indexOf('ss');
|
|
1137
|
+
if (i_second_start === -1)
|
|
1138
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1139
|
+
const i_second_end = i_second_start + 2;
|
|
1140
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1141
|
+
if (i_nanosecond_start === -1)
|
|
1142
|
+
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1143
|
+
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1144
|
+
format.slice(i_second_end, i_nanosecond_start) +
|
|
1145
|
+
String(nanotimestamp % 1000000000n));
|
|
1082
1146
|
}
|
|
1083
1147
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1084
1148
|
/** parse nano timestamp string to bigint value
|
|
1085
|
-
- str: nano timestamp string,
|
|
1086
|
-
- format?:
|
|
1149
|
+
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1150
|
+
- format?:
|
|
1151
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1152
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1087
1153
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1088
1154
|
*/
|
|
1089
|
-
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1155
|
+
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1090
1156
|
if (!str)
|
|
1091
1157
|
return exports.nulls.int64;
|
|
1092
|
-
if (str.length
|
|
1093
|
-
throw new Error('nanotimestamp
|
|
1158
|
+
if (str.length !== format.length)
|
|
1159
|
+
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
1160
|
+
const i_second_start = format.indexOf('ss');
|
|
1161
|
+
if (i_second_start === -1)
|
|
1162
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1163
|
+
const i_second_end = i_second_start + 2;
|
|
1164
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1165
|
+
if (i_nanosecond_start === -1)
|
|
1166
|
+
throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
|
|
1094
1167
|
return (BigInt(-exports.timezone_offset +
|
|
1095
|
-
(0, dayjs_1.default)(str.slice(0, format.
|
|
1168
|
+
(0, dayjs_1.default)(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
|
|
1096
1169
|
+
|
|
1097
|
-
BigInt(str.slice(
|
|
1170
|
+
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1098
1171
|
}
|
|
1099
1172
|
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1100
1173
|
class DDB {
|
|
@@ -1189,7 +1262,10 @@ class DDB {
|
|
|
1189
1262
|
' )\n' +
|
|
1190
1263
|
'}\n', { urgent: true });
|
|
1191
1264
|
if (login)
|
|
1192
|
-
|
|
1265
|
+
if (this.python)
|
|
1266
|
+
await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
|
|
1267
|
+
else
|
|
1268
|
+
await this.call('login', [username, password], { urgent: true });
|
|
1193
1269
|
}
|
|
1194
1270
|
get_rpc_options({ urgent = false, secondary = false, async: _async = false, pickle = false, clear = false, api = false, compress = false, cancellable = true, priority = urgent ? 8 : 4, parallelism = 8, root_id = '', limit, } = {}) {
|
|
1195
1271
|
let flag = 0;
|