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/browser.d.ts CHANGED
@@ -151,6 +151,9 @@ export declare class DdbVoid extends DdbObj<undefined> {
151
151
  export declare class DdbBool extends DdbObj<boolean> {
152
152
  constructor(value: boolean);
153
153
  }
154
+ export declare class DdbChar extends DdbObj<string> {
155
+ constructor(value: string);
156
+ }
154
157
  export declare class DdbInt extends DdbObj<number> {
155
158
  constructor(value: number);
156
159
  }
@@ -163,6 +166,15 @@ export declare class DdbLong extends DdbObj<bigint> {
163
166
  export declare class DdbDouble extends DdbObj<number> {
164
167
  constructor(value: number);
165
168
  }
169
+ export declare class DdbDateTime extends DdbObj<number> {
170
+ constructor(value: number);
171
+ }
172
+ export declare class DdbTimeStamp extends DdbObj<bigint> {
173
+ constructor(value: bigint);
174
+ }
175
+ export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
176
+ constructor(value: bigint);
177
+ }
166
178
  export declare class DdbVectorInt extends DdbObj<Int32Array> {
167
179
  constructor(value: number[], name?: string);
168
180
  }
@@ -181,8 +193,16 @@ export declare class DdbPair extends DdbObj<Int32Array> {
181
193
  export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
182
194
  constructor(name: string, type: DdbFunctionType);
183
195
  }
184
- export declare function date2str(date: number): string;
196
+ export declare function date2str(date: number, format?: string): string;
197
+ export declare function datetime2str(datetime: number, format?: string): string;
185
198
  export declare function timestamp2str(timestamp: bigint): string;
199
+ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
200
+ /** parse nano timestamp string to bigint value
201
+ - str: nano timestamp string, 如果为空字符串会返回对应的空值 (nulls.int64)
202
+ - format?: Format string up to and including seconds of the passed string, default is `YYYY.MM.DD HH:mm:ss`
203
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
204
+ */
205
+ export declare function str2nanotimestamp(str: string, format?: string): bigint;
186
206
  export declare class DDB {
187
207
  /** 当前的 session id (http 或 tcp) */
188
208
  sid: string;
package/browser.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ddb = 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.DdbType = exports.DdbForm = void 0;
3
+ exports.ddb = 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.DdbType = exports.DdbForm = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
+ const customParseFormat_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat"));
7
+ dayjs_1.default.extend(customParseFormat_1.default);
6
8
  require("xshell/prototype.browser");
7
9
  const utils_browser_1 = require("xshell/utils.browser");
8
10
  var DdbForm;
@@ -880,6 +882,17 @@ class DdbBool extends DdbObj {
880
882
  }
881
883
  }
882
884
  exports.DdbBool = DdbBool;
885
+ class DdbChar extends DdbObj {
886
+ constructor(value) {
887
+ super({
888
+ form: DdbForm.scalar,
889
+ type: DdbType.char,
890
+ length: 1,
891
+ value,
892
+ });
893
+ }
894
+ }
895
+ exports.DdbChar = DdbChar;
883
896
  class DdbInt extends DdbObj {
884
897
  constructor(value) {
885
898
  super({
@@ -924,6 +937,39 @@ class DdbDouble extends DdbObj {
924
937
  }
925
938
  }
926
939
  exports.DdbDouble = DdbDouble;
940
+ class DdbDateTime extends DdbObj {
941
+ constructor(value) {
942
+ super({
943
+ form: DdbForm.scalar,
944
+ type: DdbType.datetime,
945
+ length: 4,
946
+ value
947
+ });
948
+ }
949
+ }
950
+ exports.DdbDateTime = DdbDateTime;
951
+ class DdbTimeStamp extends DdbObj {
952
+ constructor(value) {
953
+ super({
954
+ form: DdbForm.scalar,
955
+ type: DdbType.timestamp,
956
+ length: 8,
957
+ value
958
+ });
959
+ }
960
+ }
961
+ exports.DdbTimeStamp = DdbTimeStamp;
962
+ class DdbNanoTimeStamp extends DdbObj {
963
+ constructor(value) {
964
+ super({
965
+ form: DdbForm.scalar,
966
+ type: DdbType.nanotimestamp,
967
+ length: 8,
968
+ value
969
+ });
970
+ }
971
+ }
972
+ exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
927
973
  class DdbVectorInt extends DdbObj {
928
974
  constructor(value, name) {
929
975
  super({
@@ -1004,13 +1050,20 @@ class DdbFunction extends DdbObj {
1004
1050
  }
1005
1051
  }
1006
1052
  exports.DdbFunction = DdbFunction;
1007
- function date2str(date) {
1053
+ function date2str(date, format = 'YYYY.MM.DD') {
1008
1054
  return date === exports.nulls.int32 ?
1009
1055
  ''
1010
1056
  :
1011
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format('YYYY.MM.DD');
1057
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1012
1058
  }
1013
1059
  exports.date2str = date2str;
1060
+ function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1061
+ return datetime === exports.nulls.int32 ?
1062
+ ''
1063
+ :
1064
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1065
+ }
1066
+ exports.datetime2str = datetime2str;
1014
1067
  function timestamp2str(timestamp) {
1015
1068
  return timestamp === exports.nulls.int64 ?
1016
1069
  ''
@@ -1018,6 +1071,29 @@ function timestamp2str(timestamp) {
1018
1071
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format('YYYY.MM.DD HH:mm:ss.SSS');
1019
1072
  }
1020
1073
  exports.timestamp2str = timestamp2str;
1074
+ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss') {
1075
+ return nanotimestamp === exports.nulls.int64 ?
1076
+ ''
1077
+ :
1078
+ (0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format) + `.${nanotimestamp % 1000000000n}`;
1079
+ }
1080
+ exports.nanotimestamp2str = nanotimestamp2str;
1081
+ /** parse nano timestamp string to bigint value
1082
+ - str: nano timestamp string, 如果为空字符串会返回对应的空值 (nulls.int64)
1083
+ - format?: Format string up to and including seconds of the passed string, default is `YYYY.MM.DD HH:mm:ss`
1084
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1085
+ */
1086
+ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
1087
+ if (!str)
1088
+ return exports.nulls.int64;
1089
+ if (str.length - format.length !== 9)
1090
+ throw new Error('nanotimestamp 字符串长度减格式串长度应该等于 9');
1091
+ return (BigInt(-exports.timezone_offset +
1092
+ (0, dayjs_1.default)(str.slice(0, format.length), format).valueOf()) * 1000000n
1093
+ +
1094
+ BigInt(str.slice(format.length)));
1095
+ }
1096
+ exports.str2nanotimestamp = str2nanotimestamp;
1021
1097
  class DDB {
1022
1098
  /**
1023
1099
  Initialize an instance of DolphinDB Client using the WebSocket URL