dolphindb 2.0.1102 → 2.0.1130

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.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { InspectOptions as UtilInspectOptions } from 'util';
3
3
  import { inspect, Lock, type WebSocket, type WebSocketConnectionError } from 'xshell';
4
4
  import { type DdbDecimal128Value, type DdbDecimal128VectorValue } from './data-types/decimal-128.js';
5
5
  import { BigInt128Array } from './shared/bigint-128-array.js';
6
- import { DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
6
+ import { DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType } from './shared/constants.js';
7
7
  export * from './shared/constants.js';
8
8
  export type { DdbDecimal128Value, DdbDecimal128VectorValue } from './data-types/decimal-128.js';
9
9
  export interface DdbFunctionDefValue {
@@ -188,7 +188,7 @@ export declare function format(type: DdbType, value: DdbValue, le: boolean, opti
188
188
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
189
189
  export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
190
190
  export declare class DdbVoid extends DdbObj<undefined> {
191
- constructor();
191
+ constructor(value?: DdbVoidType);
192
192
  }
193
193
  export declare class DdbBool extends DdbObj<boolean> {
194
194
  constructor(value: boolean | null);
@@ -277,13 +277,13 @@ export declare function second2ms(second: number | null): number | null;
277
277
  export declare function second2str(second: number | null, format?: string): string;
278
278
  export declare function datetime2ms(datetime: number | null): number | null;
279
279
  export declare function datetime2str(datetime: number | null, format?: string): string;
280
+ /** _datetime_formatter.format 会在 date 为 Invalid Date 时抛出错误 */
280
281
  export declare function timestamp2ms(timestamp: bigint | null): number | null;
281
282
  /** format timestamp (bigint) to string
282
283
  - timestamp: bigint value
283
284
  - format?:
284
285
  格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
285
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
286
- */
286
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
287
287
  export declare function timestamp2str(timestamp: bigint | null, format?: string): string;
288
288
  export declare function datehour2ms(datehour: number | null): number | null;
289
289
  export declare function datehour2str(datehour: number | null, format?: string): string;
@@ -293,8 +293,7 @@ export declare function datehour2str(datehour: number | null, format?: string):
293
293
  - format?:
294
294
  对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
295
295
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
296
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
297
- */
296
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
298
297
  export declare function str2timestamp(str: string, format?: string): bigint;
299
298
  export declare function nanotime2ns(nanotime: bigint | null): bigint | null;
300
299
  export declare function nanotime2str(nanotime: bigint | null, format?: string): string;
package/index.js CHANGED
@@ -9,7 +9,7 @@ import { t } from './i18n/index.js';
9
9
  import { DdbDecimal128Serializor } from './data-types/decimal-128.js';
10
10
  import { BigInt128Array } from './shared/bigint-128-array.js';
11
11
  import { is_decimal_type, is_decimal_null_value, get_duration_unit } from './shared/utils.js';
12
- import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
12
+ import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType } from './shared/constants.js';
13
13
  export * from './shared/constants.js';
14
14
  // Simulate other TypedArray behavior in nodejs
15
15
  BigInt128Array.prototype[inspect.custom] = function () {
@@ -268,13 +268,12 @@ export class DdbObj {
268
268
  }
269
269
  static parse_scalar(buf, le, type) {
270
270
  switch (type) {
271
- case DdbType.void:
272
- return [1, null];
273
271
  case DdbType.bool: {
274
272
  const dv = new DataView(buf.buffer, buf.byteOffset);
275
273
  const value = dv.getInt8(0);
276
274
  return [1, value === nulls.int8 ? null : Boolean(value)];
277
275
  }
276
+ case DdbType.void:
278
277
  case DdbType.char: {
279
278
  const dv = new DataView(buf.buffer, buf.byteOffset);
280
279
  const value = dv.getInt8(0);
@@ -723,10 +722,7 @@ export class DdbObj {
723
722
  case DdbForm.scalar:
724
723
  switch (type) {
725
724
  case DdbType.void:
726
- // Server 实现中区分了 explicitNull
727
- // Void::serialize()
728
- // isNothing() ? 0 : 1;
729
- return [Uint8Array.of(0)];
725
+ return [Uint8Array.of(Number(value))];
730
726
  case DdbType.bool:
731
727
  return [
732
728
  Int8Array.of(value === null ?
@@ -905,7 +901,6 @@ export class DdbObj {
905
901
  case DdbType.void:
906
902
  return [];
907
903
  case DdbType.bool:
908
- return [value];
909
904
  case DdbType.char:
910
905
  return [value];
911
906
  case DdbType.short:
@@ -1299,7 +1294,27 @@ export function format(type, value, le, options = {}) {
1299
1294
  }
1300
1295
  return options.decimals === undefined || options.decimals === null ? default_formatter : _formatter;
1301
1296
  })();
1297
+ function format_time(formatter, _null) {
1298
+ if (value === null || value === _null)
1299
+ return inspect(null, options);
1300
+ let str;
1301
+ // formatter 可能会在 value 不属于 new Date() 有效值时,调用 抛出错误,这里统一处理
1302
+ try {
1303
+ str = formatter(value);
1304
+ }
1305
+ catch (error) {
1306
+ if (error instanceof RangeError)
1307
+ str = 'Invalid Date';
1308
+ else
1309
+ throw error;
1310
+ }
1311
+ return options.colors ? str.magenta : str;
1312
+ }
1302
1313
  switch (type) {
1314
+ case DdbType.void: {
1315
+ const str = value === DdbVoidType.default ? 'default' : 'null';
1316
+ return options.colors ? str.grey : str;
1317
+ }
1303
1318
  case DdbType.bool:
1304
1319
  return inspect((value === null || value === nulls.int8) ?
1305
1320
  null
@@ -1340,77 +1355,23 @@ export function format(type, value, le, options = {}) {
1340
1355
  :
1341
1356
  default_formatter.format(value);
1342
1357
  case DdbType.date:
1343
- return (value === null || value === nulls.int32) ?
1344
- inspect(null, options)
1345
- :
1346
- options.colors ?
1347
- date2str(value).magenta
1348
- :
1349
- date2str(value);
1358
+ return format_time(date2str, nulls.int32);
1350
1359
  case DdbType.month:
1351
- return (value === null || value === nulls.int32) ?
1352
- inspect(null, options)
1353
- :
1354
- options.colors ?
1355
- month2str(value).magenta
1356
- :
1357
- month2str(value);
1360
+ return format_time(month2str, nulls.int32);
1358
1361
  case DdbType.time:
1359
- return (value === null || value === nulls.int32) ?
1360
- inspect(null, options)
1361
- :
1362
- options.colors ?
1363
- time2str(value).magenta
1364
- :
1365
- time2str(value);
1362
+ return format_time(time2str, nulls.int32);
1366
1363
  case DdbType.minute:
1367
- return (value === null || value === nulls.int32) ?
1368
- inspect(null, options)
1369
- :
1370
- options.colors ?
1371
- minute2str(value).magenta
1372
- :
1373
- minute2str(value);
1364
+ return format_time(minute2str, nulls.int32);
1374
1365
  case DdbType.second:
1375
- return (value === null || value === nulls.int32) ?
1376
- inspect(null, options)
1377
- :
1378
- options.colors ?
1379
- second2str(value).magenta
1380
- :
1381
- second2str(value);
1366
+ return format_time(second2str, nulls.int32);
1382
1367
  case DdbType.datetime:
1383
- return (value === null || value === nulls.int32) ?
1384
- inspect(null, options)
1385
- :
1386
- options.colors ?
1387
- datetime2str(value).magenta
1388
- :
1389
- datetime2str(value);
1368
+ return format_time(datetime2str, nulls.int32);
1390
1369
  case DdbType.timestamp:
1391
- return (value === null || value === nulls.int64) ?
1392
- inspect(null, options)
1393
- :
1394
- options.colors ?
1395
- timestamp2str(value).magenta
1396
- :
1397
- timestamp2str(value);
1370
+ return format_time(timestamp2str, nulls.int64);
1398
1371
  case DdbType.nanotime:
1399
- return (value === null || value === nulls.int64) ?
1400
- inspect(null, options)
1401
- :
1402
- options.colors ?
1403
- nanotime2str(value).magenta
1404
- :
1405
- nanotime2str(value);
1372
+ return format_time(nanotime2str, nulls.int64);
1406
1373
  case DdbType.nanotimestamp:
1407
- return (value === null || value === nulls.int64) ?
1408
- inspect(null, options)
1409
- :
1410
- options.colors ?
1411
- nanotimestamp2str(value).magenta
1412
- :
1413
- nanotimestamp2str(value);
1374
+ return format_time(nanotimestamp2str, nulls.int64);
1414
1375
  case DdbType.float:
1415
1376
  return (value === null || value === nulls.float32) ?
1416
1377
  inspect(null, options)
@@ -1443,13 +1404,7 @@ export function format(type, value, le, options = {}) {
1443
1404
  case DdbType.resource:
1444
1405
  return inspect(value, options);
1445
1406
  case DdbType.datehour:
1446
- return (value === null || value === nulls.int32) ?
1447
- 'null'
1448
- :
1449
- options.colors ?
1450
- datehour2str(value).magenta
1451
- :
1452
- datehour2str(value);
1407
+ return format_time(datehour2str, nulls.int32);
1453
1408
  case DdbType.ipaddr:
1454
1409
  return options.colors ?
1455
1410
  ipaddr2str(value, le).cyan
@@ -1596,11 +1551,11 @@ export function formati(obj, index, options = {}) {
1596
1551
  }
1597
1552
  }
1598
1553
  export class DdbVoid extends DdbObj {
1599
- constructor() {
1554
+ constructor(value = DdbVoidType.undefined) {
1600
1555
  super({
1601
1556
  form: DdbForm.scalar,
1602
1557
  type: DdbType.void,
1603
- value: null,
1558
+ value,
1604
1559
  });
1605
1560
  }
1606
1561
  }
@@ -1998,6 +1953,7 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1998
1953
  :
1999
1954
  dayjs(datetime2ms(datetime)).format(format);
2000
1955
  }
1956
+ /** _datetime_formatter.format 会在 date 为 Invalid Date 时抛出错误 */
2001
1957
  export function timestamp2ms(timestamp) {
2002
1958
  if (timestamp === null || timestamp === nulls.int64)
2003
1959
  return null;
@@ -2008,8 +1964,7 @@ export function timestamp2ms(timestamp) {
2008
1964
  - timestamp: bigint value
2009
1965
  - format?:
2010
1966
  格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
2011
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
2012
- */
1967
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
2013
1968
  export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
2014
1969
  return (timestamp === null || timestamp === nulls.int64) ?
2015
1970
  'null'
@@ -2034,8 +1989,7 @@ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
2034
1989
  - format?:
2035
1990
  对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
2036
1991
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
2037
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
2038
- */
1992
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
2039
1993
  export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
2040
1994
  if (!str || str === 'null')
2041
1995
  return nulls.int64;