dolphindb 0.0.10 → 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/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) {
@@ -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,6 +940,39 @@ class DdbDouble extends DdbObj {
927
940
  }
928
941
  }
929
942
  exports.DdbDouble = DdbDouble;
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 {
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;
930
976
  class DdbVectorInt extends DdbObj {
931
977
  constructor(value, name) {
932
978
  super({
@@ -1007,13 +1053,20 @@ class DdbFunction extends DdbObj {
1007
1053
  }
1008
1054
  }
1009
1055
  exports.DdbFunction = DdbFunction;
1010
- function date2str(date) {
1056
+ function date2str(date, format = 'YYYY.MM.DD') {
1011
1057
  return date === exports.nulls.int32 ?
1012
1058
  ''
1013
1059
  :
1014
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format('YYYY.MM.DD');
1060
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1015
1061
  }
1016
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;
1017
1070
  function timestamp2str(timestamp) {
1018
1071
  return timestamp === exports.nulls.int64 ?
1019
1072
  ''
@@ -1021,6 +1074,29 @@ function timestamp2str(timestamp) {
1021
1074
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format('YYYY.MM.DD HH:mm:ss.SSS');
1022
1075
  }
1023
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;
1024
1100
  class DDB {
1025
1101
  /**
1026
1102
  Initialize an instance of DolphinDB Client using the WebSocket URL