dolphindb 0.0.8 → 0.0.11
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/browser.d.ts +25 -5
- package/browser.js +91 -11
- package/browser.js.map +1 -1
- package/index.d.ts +26 -6
- package/index.js +91 -11
- package/index.js.map +1 -1
- package/package.json +1 -1
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_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat"));
|
|
8
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
7
9
|
const utils_js_1 = require("xshell/utils.js");
|
|
8
10
|
var DdbForm;
|
|
9
11
|
(function (DdbForm) {
|
|
@@ -847,7 +849,7 @@ class DdbObj {
|
|
|
847
849
|
}
|
|
848
850
|
to_dict() {
|
|
849
851
|
if (this.form !== DdbForm.dict)
|
|
850
|
-
throw new Error('this.form
|
|
852
|
+
throw new Error('this.form is not DdbForm.dict, cannot convert to Object');
|
|
851
853
|
const [{ value: keys }, { value: values }] = this.value;
|
|
852
854
|
let obj = {};
|
|
853
855
|
for (let i = 0; i < this.rows; i++)
|
|
@@ -883,6 +885,17 @@ class DdbBool extends DdbObj {
|
|
|
883
885
|
}
|
|
884
886
|
}
|
|
885
887
|
exports.DdbBool = DdbBool;
|
|
888
|
+
class DdbChar extends DdbObj {
|
|
889
|
+
constructor(value) {
|
|
890
|
+
super({
|
|
891
|
+
form: DdbForm.scalar,
|
|
892
|
+
type: DdbType.char,
|
|
893
|
+
length: 1,
|
|
894
|
+
value,
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
exports.DdbChar = DdbChar;
|
|
886
899
|
class DdbInt extends DdbObj {
|
|
887
900
|
constructor(value) {
|
|
888
901
|
super({
|
|
@@ -927,8 +940,41 @@ class DdbDouble extends DdbObj {
|
|
|
927
940
|
}
|
|
928
941
|
}
|
|
929
942
|
exports.DdbDouble = DdbDouble;
|
|
930
|
-
class
|
|
943
|
+
class DdbDateTime extends DdbObj {
|
|
944
|
+
constructor(value) {
|
|
945
|
+
super({
|
|
946
|
+
form: DdbForm.scalar,
|
|
947
|
+
type: DdbType.datetime,
|
|
948
|
+
length: 4,
|
|
949
|
+
value
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
exports.DdbDateTime = DdbDateTime;
|
|
954
|
+
class DdbTimeStamp extends DdbObj {
|
|
931
955
|
constructor(value) {
|
|
956
|
+
super({
|
|
957
|
+
form: DdbForm.scalar,
|
|
958
|
+
type: DdbType.timestamp,
|
|
959
|
+
length: 8,
|
|
960
|
+
value
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
exports.DdbTimeStamp = DdbTimeStamp;
|
|
965
|
+
class DdbNanoTimeStamp extends DdbObj {
|
|
966
|
+
constructor(value) {
|
|
967
|
+
super({
|
|
968
|
+
form: DdbForm.scalar,
|
|
969
|
+
type: DdbType.nanotimestamp,
|
|
970
|
+
length: 8,
|
|
971
|
+
value
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
976
|
+
class DdbVectorInt extends DdbObj {
|
|
977
|
+
constructor(value, name) {
|
|
932
978
|
super({
|
|
933
979
|
form: DdbForm.vector,
|
|
934
980
|
type: DdbType.int,
|
|
@@ -936,45 +982,49 @@ class DdbVectorInt extends DdbObj {
|
|
|
936
982
|
rows: value.length,
|
|
937
983
|
cols: 1,
|
|
938
984
|
value: Int32Array.from(value),
|
|
985
|
+
name,
|
|
939
986
|
});
|
|
940
987
|
}
|
|
941
988
|
}
|
|
942
989
|
exports.DdbVectorInt = DdbVectorInt;
|
|
943
990
|
class DdbVectorString extends DdbObj {
|
|
944
|
-
constructor(value) {
|
|
991
|
+
constructor(value, name) {
|
|
945
992
|
super({
|
|
946
993
|
form: DdbForm.vector,
|
|
947
994
|
type: DdbType.string,
|
|
948
995
|
length: 0,
|
|
949
996
|
rows: value.length,
|
|
950
997
|
cols: 1,
|
|
951
|
-
value
|
|
998
|
+
value,
|
|
999
|
+
name,
|
|
952
1000
|
});
|
|
953
1001
|
}
|
|
954
1002
|
}
|
|
955
1003
|
exports.DdbVectorString = DdbVectorString;
|
|
956
1004
|
class DdbVectorDouble extends DdbObj {
|
|
957
|
-
constructor(value) {
|
|
1005
|
+
constructor(value, name) {
|
|
958
1006
|
super({
|
|
959
1007
|
form: DdbForm.vector,
|
|
960
1008
|
type: DdbType.double,
|
|
961
1009
|
length: 0,
|
|
962
1010
|
rows: value.length,
|
|
963
1011
|
cols: 1,
|
|
964
|
-
value: Float64Array.from(value)
|
|
1012
|
+
value: Float64Array.from(value),
|
|
1013
|
+
name,
|
|
965
1014
|
});
|
|
966
1015
|
}
|
|
967
1016
|
}
|
|
968
1017
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
969
1018
|
class DdbVectorAny extends DdbObj {
|
|
970
|
-
constructor(value) {
|
|
1019
|
+
constructor(value, name) {
|
|
971
1020
|
super({
|
|
972
1021
|
form: DdbForm.vector,
|
|
973
1022
|
type: DdbType.any,
|
|
974
1023
|
length: 0,
|
|
975
1024
|
rows: value.length,
|
|
976
1025
|
cols: 1,
|
|
977
|
-
value
|
|
1026
|
+
value,
|
|
1027
|
+
name,
|
|
978
1028
|
});
|
|
979
1029
|
}
|
|
980
1030
|
}
|
|
@@ -1003,13 +1053,20 @@ class DdbFunction extends DdbObj {
|
|
|
1003
1053
|
}
|
|
1004
1054
|
}
|
|
1005
1055
|
exports.DdbFunction = DdbFunction;
|
|
1006
|
-
function date2str(date) {
|
|
1056
|
+
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1007
1057
|
return date === exports.nulls.int32 ?
|
|
1008
1058
|
''
|
|
1009
1059
|
:
|
|
1010
|
-
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(
|
|
1060
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1011
1061
|
}
|
|
1012
1062
|
exports.date2str = date2str;
|
|
1063
|
+
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1064
|
+
return datetime === exports.nulls.int32 ?
|
|
1065
|
+
''
|
|
1066
|
+
:
|
|
1067
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1068
|
+
}
|
|
1069
|
+
exports.datetime2str = datetime2str;
|
|
1013
1070
|
function timestamp2str(timestamp) {
|
|
1014
1071
|
return timestamp === exports.nulls.int64 ?
|
|
1015
1072
|
''
|
|
@@ -1017,6 +1074,29 @@ function timestamp2str(timestamp) {
|
|
|
1017
1074
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format('YYYY.MM.DD HH:mm:ss.SSS');
|
|
1018
1075
|
}
|
|
1019
1076
|
exports.timestamp2str = timestamp2str;
|
|
1077
|
+
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1078
|
+
return nanotimestamp === exports.nulls.int64 ?
|
|
1079
|
+
''
|
|
1080
|
+
:
|
|
1081
|
+
(0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format) + `.${nanotimestamp % 1000000000n}`;
|
|
1082
|
+
}
|
|
1083
|
+
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1084
|
+
/** parse nano timestamp string to bigint value
|
|
1085
|
+
- str: nano timestamp string, 如果为空字符串会返回对应的空值 (nulls.int64)
|
|
1086
|
+
- format?: 对应传入字符串的到秒之前 (包括) 的格式串,默认是 `YYYY.MM.DD HH:mm:ss`
|
|
1087
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1088
|
+
*/
|
|
1089
|
+
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1090
|
+
if (!str)
|
|
1091
|
+
return exports.nulls.int64;
|
|
1092
|
+
if (str.length - format.length !== 9)
|
|
1093
|
+
throw new Error('nanotimestamp 字符串长度减格式串长度应该等于 9');
|
|
1094
|
+
return (BigInt(-exports.timezone_offset +
|
|
1095
|
+
(0, dayjs_1.default)(str.slice(0, format.length), format).valueOf()) * 1000000n
|
|
1096
|
+
+
|
|
1097
|
+
BigInt(str.slice(format.length)));
|
|
1098
|
+
}
|
|
1099
|
+
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1020
1100
|
class DDB {
|
|
1021
1101
|
/**
|
|
1022
1102
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|