dolphindb 3.0.205 → 3.0.208

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
@@ -1,3 +1,4 @@
1
+ import { type Dayjs } from 'dayjs';
1
2
  import 'xshell/prototype.browser.js';
2
3
  import { Lock } from 'xshell/utils.browser.js';
3
4
  import { type WebSocketConnectionError } from 'xshell/net.browser.js';
@@ -417,7 +418,7 @@ export interface ConvertOptions {
417
418
  /** `'ms'` timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
418
419
  timestamp?: 's' | 'ms';
419
420
  }
420
- export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | string[] | DdbArrayVectorValue | DdbMatrixValue | Uint8Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbDurationVectorValue | number[] | DdbTensorValue | DdbChartValue;
421
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | number[] | Uint8Array<ArrayBufferLike> | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | string[] | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue;
421
422
  /** 转换一个向量到 js 原生数组 */
422
423
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[] | Uint8Array;
423
424
  export declare class DdbVoid extends DdbObj<undefined> {
@@ -442,16 +443,16 @@ export declare class DdbDouble extends DdbObj<number> {
442
443
  constructor(value: number | null);
443
444
  }
444
445
  export declare class DdbDateTime extends DdbObj<number> {
445
- constructor(value: number | null);
446
+ constructor(value?: null | number | string | Date | Dayjs);
446
447
  }
447
448
  export declare class DdbTimeStamp extends DdbObj<bigint> {
448
- /** @example
449
- new DdbTimeStamp(new Date().getTime())
450
- new DdbTimeStamp(dayjs().valueOf()) */
451
- constructor(value?: bigint | null | number);
449
+ constructor(value?: null | number | string | Date | Dayjs);
452
450
  }
453
451
  export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
454
- constructor(value: bigint | null);
452
+ constructor(value?: null | number | string | Date | Dayjs);
453
+ }
454
+ export declare class DdbDate extends DdbObj<number> {
455
+ constructor(value?: null | number | string | Date | Dayjs);
455
456
  }
456
457
  export declare class DdbBlob extends DdbObj<Uint8Array> {
457
458
  constructor(value: Uint8Array | ArrayBuffer);
package/browser.js CHANGED
@@ -1,11 +1,11 @@
1
- import dayjs from 'dayjs';
1
+ import { default as dayjs } from 'dayjs';
2
2
  import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
3
3
  dayjs.extend(DayjsCustomParseFormat);
4
4
  import ipaddrjs from 'ipaddr.js';
5
5
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
6
6
  import 'xshell/prototype.browser.js';
7
7
  import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
8
- import { concat, assert, Lock, genid, seq, zip_object, decode, delay } from 'xshell/utils.browser.js';
8
+ import { concat, assert, Lock, genid, seq, zip_object, decode, delay, check } from 'xshell/utils.browser.js';
9
9
  import { connect_websocket } from 'xshell/net.browser.js';
10
10
  import { t } from "./i18n/index.js";
11
11
  export const nulls = {
@@ -2221,24 +2221,16 @@ export class DdbDateTime extends DdbObj {
2221
2221
  super({
2222
2222
  form: DdbForm.scalar,
2223
2223
  type: DdbType.datetime,
2224
- value
2224
+ value: get_ddb_time_value('DdbDateTime', value)
2225
2225
  });
2226
2226
  }
2227
2227
  }
2228
2228
  export class DdbTimeStamp extends DdbObj {
2229
- /** @example
2230
- new DdbTimeStamp(new Date().getTime())
2231
- new DdbTimeStamp(dayjs().valueOf()) */
2232
2229
  constructor(value) {
2233
- if (value === undefined)
2234
- value = new Date().getTime();
2235
- if (typeof value === 'number')
2236
- value = BigInt(-(1000 * 60 * new Date(value).getTimezoneOffset()) +
2237
- value);
2238
2230
  super({
2239
2231
  form: DdbForm.scalar,
2240
2232
  type: DdbType.timestamp,
2241
- value
2233
+ value: get_ddb_time_value('DdbTimeStamp', value)
2242
2234
  });
2243
2235
  }
2244
2236
  }
@@ -2247,10 +2239,46 @@ export class DdbNanoTimeStamp extends DdbObj {
2247
2239
  super({
2248
2240
  form: DdbForm.scalar,
2249
2241
  type: DdbType.nanotimestamp,
2250
- value
2242
+ value: get_ddb_time_value('DdbNanoTimeStamp', value)
2251
2243
  });
2252
2244
  }
2253
2245
  }
2246
+ export class DdbDate extends DdbObj {
2247
+ constructor(value) {
2248
+ super({
2249
+ form: DdbForm.scalar,
2250
+ type: DdbType.date,
2251
+ value: get_ddb_time_value('DdbDate', value)
2252
+ });
2253
+ }
2254
+ }
2255
+ function get_ddb_time_value(classname, value) {
2256
+ if (value === null)
2257
+ return null;
2258
+ if (classname === 'DdbNanoTimeStamp' && typeof value === 'string')
2259
+ return str2nanotimestamp(value);
2260
+ let date;
2261
+ if (value === undefined)
2262
+ date = new Date();
2263
+ else if (typeof value === 'number' || typeof value === 'string')
2264
+ date = new Date(value);
2265
+ else if (value instanceof Date)
2266
+ date = value;
2267
+ else if (dayjs.isDayjs(value))
2268
+ date = new Date(value.valueOf());
2269
+ else
2270
+ throw new Error(t('value 不能转换为 {{classname}}', { classname }));
2271
+ switch (classname) {
2272
+ case 'DdbDateTime':
2273
+ return (date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / 1000;
2274
+ case 'DdbTimeStamp':
2275
+ return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset());
2276
+ case 'DdbNanoTimeStamp':
2277
+ return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset()) * 1000000n;
2278
+ case 'DdbDate':
2279
+ return Math.floor((date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / (1000 * 3600 * 24));
2280
+ }
2281
+ }
2254
2282
  export class DdbBlob extends DdbObj {
2255
2283
  constructor(value) {
2256
2284
  assert(value, t('new DdbBlob 不能传空的 value'));
@@ -2673,12 +2701,12 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2673
2701
  export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
2674
2702
  if (!str || str === 'null')
2675
2703
  return nulls.int64;
2676
- assert(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'));
2704
+ check(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'));
2677
2705
  const i_second_start = format.indexOf('ss');
2678
- assert(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
2706
+ check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
2679
2707
  const i_second_end = i_second_start + 2;
2680
2708
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
2681
- assert(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
2709
+ check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
2682
2710
  const ms = dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf();
2683
2711
  return (BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
2684
2712
  ms) * 1000000n