dolphindb 2.0.962 → 2.0.964

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.
@@ -0,0 +1,21 @@
1
+ import { BigInt128Array } from '../shared/bigint-128-array.js';
2
+ export interface DdbDecimal128Value {
3
+ /** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */
4
+ scale: number;
5
+ /** int128, 空值为 null empty value is null */
6
+ data: bigint | null;
7
+ }
8
+ export interface DdbDecimal128VectorValue {
9
+ scale: number;
10
+ data: BigInt128Array;
11
+ }
12
+ export declare const DdbDecimal128Serializor: {
13
+ /** 解析为标量 */
14
+ parse_as_scalar(buf: Uint8Array, le: boolean): [number, DdbDecimal128Value];
15
+ /** 解析为仅由同类数据组成的 vector 的值 */
16
+ parse_as_same_type_vector_values(buf: Uint8Array, byte_offset: number, items_length: number): [number, BigInt128Array];
17
+ /** 解析为 vector 中的单独项 */
18
+ parse_as_vector_items(buf: Uint8Array, length: number, le: boolean): [number, DdbDecimal128VectorValue];
19
+ /** 序列化 */
20
+ pack(value: DdbDecimal128Value): [Int32Array, BigInt128Array];
21
+ };
@@ -0,0 +1,34 @@
1
+ import { BigInt128Array } from '../shared/bigint-128-array.js';
2
+ import { nulls } from '../shared/constants.js';
3
+ import { getBigInt128 } from '../shared/data-view-extends.js';
4
+ export const DdbDecimal128Serializor = {
5
+ /** 解析为标量 */
6
+ parse_as_scalar(buf, le) {
7
+ const dv = new DataView(buf.buffer, buf.byteOffset);
8
+ const data = getBigInt128(dv, 4, le);
9
+ return [20, { scale: dv.getInt32(0, le), data: data === nulls.int128 ? null : data }];
10
+ },
11
+ /** 解析为仅由同类数据组成的 vector 的值 */
12
+ parse_as_same_type_vector_values(buf, byte_offset, items_length) {
13
+ const bytes_length = items_length * 16;
14
+ const data = new BigInt128Array(buf.buffer.slice(buf.byteOffset + byte_offset, buf.byteOffset + byte_offset + bytes_length));
15
+ return [bytes_length, data];
16
+ },
17
+ /** 解析为 vector 中的单独项 */
18
+ parse_as_vector_items(buf, length, le) {
19
+ const dv = new DataView(buf.buffer, buf.byteOffset);
20
+ return [
21
+ 4 + 16 * length,
22
+ {
23
+ scale: dv.getInt32(0, le),
24
+ data: new BigInt128Array(buf.buffer.slice(buf.byteOffset + 4, buf.byteOffset + 4 + 16 * length))
25
+ }
26
+ ];
27
+ },
28
+ /** 序列化 */
29
+ pack(value) {
30
+ const { scale, data } = value;
31
+ return [Int32Array.of(scale), BigInt128Array.of(data === null ? nulls.int128 : data)];
32
+ }
33
+ };
34
+ //# sourceMappingURL=decimal-128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal-128.js","sourceRoot":"","sources":["decimal-128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAiB7D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACnC,YAAY;IACZ,eAAe,CAAE,GAAe,EAAE,EAAW;QACzC,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC,CAAA;QAEnD,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QAEpC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IACzF,CAAC;IAGD,6BAA6B;IAC7B,gCAAgC,CAAE,GAAe,EAAE,WAAmB,EAAE,YAAoB;QACxF,MAAM,YAAY,GAAG,YAAY,GAAG,EAAE,CAAA;QACtC,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,WAAW,EAAE,GAAG,CAAC,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC,CAAA;QAC5H,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;IAC/B,CAAC;IAGD,uBAAuB;IACvB,qBAAqB,CAAE,GAAe,EAAE,MAAc,EAAE,EAAW;QAC/D,MAAM,EAAE,GAAG,IAAI,QAAQ,CACnB,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,UAAU,CACjB,CAAA;QAED,OAAO;YACH,CAAC,GAAG,EAAE,GAAG,MAAM;YACf;gBACI,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;gBACzB,IAAI,EAAE,IAAI,cAAc,CACpB,GAAG,CAAC,MAAM,CAAC,KAAK,CACZ,GAAG,CAAC,UAAU,GAAG,CAAC,EAClB,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CACnC,CACJ;aACwB;SAChC,CAAA;IACL,CAAC;IAGD,UAAU;IACV,IAAI,CAAE,KAAyB;QAC3B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;QAC7B,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IACzF,CAAC;CACJ,CAAA","sourcesContent":["import { BigInt128Array } from '../shared/bigint-128-array.js'\nimport { nulls } from '../shared/constants.js'\nimport { getBigInt128 } from '../shared/data-view-extends.js'\n\nexport interface DdbDecimal128Value {\n /** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */\n scale: number\n \n /** int128, 空值为 null empty value is null */\n data: bigint | null\n}\n\nexport interface DdbDecimal128VectorValue {\n scale: number\n \n data: BigInt128Array\n}\n\n\nexport const DdbDecimal128Serializor = {\n /** 解析为标量 */\n parse_as_scalar (buf: Uint8Array, le: boolean): [number, DdbDecimal128Value] {\n const dv = new DataView(buf.buffer, buf.byteOffset)\n \n const data = getBigInt128(dv, 4, le)\n \n return [20, { scale: dv.getInt32(0, le), data: data === nulls.int128 ? null : data }]\n },\n \n \n /** 解析为仅由同类数据组成的 vector 的值 */\n parse_as_same_type_vector_values (buf: Uint8Array, byte_offset: number, items_length: number): [number, BigInt128Array] {\n const bytes_length = items_length * 16\n const data = new BigInt128Array(buf.buffer.slice(buf.byteOffset + byte_offset, buf.byteOffset + byte_offset + bytes_length))\n return [bytes_length, data]\n },\n \n \n /** 解析为 vector 中的单独项 */\n parse_as_vector_items (buf: Uint8Array, length: number, le: boolean): [number, DdbDecimal128VectorValue] {\n const dv = new DataView(\n buf.buffer,\n buf.byteOffset\n )\n \n return [\n 4 + 16 * length,\n {\n scale: dv.getInt32(0, le),\n data: new BigInt128Array(\n buf.buffer.slice(\n buf.byteOffset + 4,\n buf.byteOffset + 4 + 16 * length\n )\n )\n } as DdbDecimal128VectorValue\n ]\n },\n \n \n /** 序列化 */\n pack (value: DdbDecimal128Value): [Int32Array, BigInt128Array] {\n const { scale, data } = value\n return [Int32Array.of(scale), BigInt128Array.of(data === null ? nulls.int128 : data)]\n }\n}\n"]}
package/index.d.ts CHANGED
@@ -1,92 +1,11 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { InspectOptions as UtilInspectOptions } from 'util';
3
3
  import { inspect, WebSocket, Lock, type WebSocketConnectionError } from 'xshell';
4
- export declare enum DdbForm {
5
- scalar = 0,
6
- vector = 1,
7
- pair = 2,
8
- matrix = 3,
9
- set = 4,
10
- dict = 5,
11
- table = 6,
12
- chart = 7,
13
- /** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
14
- Node internal communication may be used, calling function execution script generally does not return this type */
15
- chunk = 8,
16
- /** sysobj */
17
- object = 9
18
- }
19
- /** DolphinDB DataType
20
- 对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
21
- 对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
22
- */
23
- export declare enum DdbType {
24
- void = 0,
25
- bool = 1,
26
- char = 2,
27
- short = 3,
28
- int = 4,
29
- long = 5,
30
- date = 6,
31
- month = 7,
32
- time = 8,
33
- minute = 9,
34
- second = 10,
35
- datetime = 11,
36
- timestamp = 12,
37
- nanotime = 13,
38
- nanotimestamp = 14,
39
- float = 15,
40
- double = 16,
41
- symbol = 17,
42
- string = 18,
43
- uuid = 19,
44
- functiondef = 20,
45
- handle = 21,
46
- code = 22,
47
- datasource = 23,
48
- resource = 24,
49
- any = 25,
50
- compress = 26,
51
- dict = 27,
52
- datehour = 28,
53
- ipaddr = 30,
54
- int128 = 31,
55
- blob = 32,
56
- complex = 34,
57
- point = 35,
58
- duration = 36,
59
- decimal32 = 37,
60
- decimal64 = 38,
61
- decimal128 = 39,
62
- object = 40,
63
- pynone = 41,
64
- symbol_extended = 145
65
- }
66
- export declare enum DdbFunctionType {
67
- SystemFunc = 0,
68
- SystemProc = 1,
69
- OperatorFunc = 2,
70
- UserDefinedFunc = 3,
71
- PartialFunc = 4,
72
- DynamicFunc = 5,
73
- PiecewiseFunc = 6,
74
- JitFunc = 7,
75
- JitPartialFunc = 8
76
- }
77
- export declare enum DdbDurationUnit {
78
- ns = 0,
79
- us = 1,
80
- ms = 2,
81
- s = 3,
82
- m = 4,
83
- H = 5,
84
- d = 6,
85
- w = 7,
86
- M = 8,
87
- y = 9,
88
- B = 10
89
- }
4
+ import { type DdbDecimal128Value, type DdbDecimal128VectorValue } from './data-types/decimal-128.js';
5
+ import { BigInt128Array } from './shared/bigint-128-array.js';
6
+ import { DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
7
+ export * from './shared/constants.js';
8
+ export type { DdbDecimal128Value, DdbDecimal128VectorValue } from './data-types/decimal-128.js';
90
9
  export interface DdbFunctionDefValue {
91
10
  type: DdbFunctionType;
92
11
  name: string;
@@ -126,9 +45,9 @@ export interface DdbArrayVectorBlock {
126
45
  unit: 1 | 2 | 4;
127
46
  rows: number;
128
47
  lengths: Uint8Array | Uint16Array | Uint32Array;
129
- data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
48
+ data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | BigInt128Array;
130
49
  }
131
- export type DdbArrayVectorValue = DdbArrayVectorBlock[] & /* decimal32, decimal64 会有这个属性 */ {
50
+ export type DdbArrayVectorValue = DdbArrayVectorBlock[] & /* decimal 数据会有这个属性 */ {
132
51
  scale?: number;
133
52
  };
134
53
  export interface DdbMatrixValue {
@@ -137,17 +56,6 @@ export interface DdbMatrixValue {
137
56
  data: DdbVectorValue;
138
57
  }
139
58
  export type DdbDictValue = [DdbVectorObj, DdbVectorObj];
140
- export declare enum DdbChartType {
141
- area = 0,
142
- bar = 1,
143
- column = 2,
144
- histogram = 3,
145
- line = 4,
146
- pie = 5,
147
- scatter = 6,
148
- trend = 7,
149
- kline = 8
150
- }
151
59
  export interface DdbChartValue {
152
60
  /** 原属性 chartType original: chartType */
153
61
  type: DdbChartType;
@@ -176,11 +84,11 @@ export type DdbScalarValue = null | boolean | number | bigint | string | Uint8Ar
176
84
  number,
177
85
  number
178
86
  ] | // complex, point
179
- DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value;
180
- export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
87
+ DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal128Value;
88
+ export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | BigInt128Array | string[] | // string[]
181
89
  Uint8Array[] | // blob
182
90
  DdbObj[] | // any
183
- DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDurationVectorValue;
91
+ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue;
184
92
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
185
93
  export type DdbStringObj = DdbObj<string>;
186
94
  export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
@@ -190,16 +98,6 @@ export type DdbTableObj<TColumns extends DdbVectorObj[] = DdbVectorObj[]> = DdbO
190
98
  export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extends DdbVectorObj = DdbVectorObj> = DdbObj<[TKeys, TValues]>;
191
99
  export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
192
100
  export type DdbChartObj = DdbObj<DdbChartValue>;
193
- export declare const nulls: {
194
- readonly int8: -128;
195
- readonly int16: -32768;
196
- readonly int32: -2147483648;
197
- readonly int64: -9223372036854775808n;
198
- readonly float32: -3.4028234663852886e+38;
199
- /** -Number.MAX_VALUE */
200
- readonly double: number;
201
- readonly bytes16: Uint8Array;
202
- };
203
101
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
204
102
  export declare class DdbObj<TValue extends DdbValue = DdbValue> {
205
103
  static dec: TextDecoder;
@@ -694,4 +592,3 @@ export interface DdbErrorMessage {
694
592
  data: DdbDatabaseError;
695
593
  }
696
594
  export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
697
- export {};
package/index.js CHANGED
@@ -6,117 +6,18 @@ import ipaddrjs from 'ipaddr.js';
6
6
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
7
7
  import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, WebSocket, Lock } from 'xshell';
8
8
  import { t } from './i18n/index.js';
9
- export var DdbForm;
10
- (function (DdbForm) {
11
- DdbForm[DdbForm["scalar"] = 0] = "scalar";
12
- DdbForm[DdbForm["vector"] = 1] = "vector";
13
- DdbForm[DdbForm["pair"] = 2] = "pair";
14
- DdbForm[DdbForm["matrix"] = 3] = "matrix";
15
- DdbForm[DdbForm["set"] = 4] = "set";
16
- DdbForm[DdbForm["dict"] = 5] = "dict";
17
- DdbForm[DdbForm["table"] = 6] = "table";
18
- DdbForm[DdbForm["chart"] = 7] = "chart";
19
- /** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
20
- Node internal communication may be used, calling function execution script generally does not return this type */
21
- DdbForm[DdbForm["chunk"] = 8] = "chunk";
22
- /** sysobj */
23
- DdbForm[DdbForm["object"] = 9] = "object";
24
- })(DdbForm = DdbForm || (DdbForm = {}));
25
- /** DolphinDB DataType
26
- 对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
27
- 对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
28
- */
29
- export var DdbType;
30
- (function (DdbType) {
31
- DdbType[DdbType["void"] = 0] = "void";
32
- DdbType[DdbType["bool"] = 1] = "bool";
33
- DdbType[DdbType["char"] = 2] = "char";
34
- DdbType[DdbType["short"] = 3] = "short";
35
- DdbType[DdbType["int"] = 4] = "int";
36
- DdbType[DdbType["long"] = 5] = "long";
37
- DdbType[DdbType["date"] = 6] = "date";
38
- DdbType[DdbType["month"] = 7] = "month";
39
- DdbType[DdbType["time"] = 8] = "time";
40
- DdbType[DdbType["minute"] = 9] = "minute";
41
- DdbType[DdbType["second"] = 10] = "second";
42
- DdbType[DdbType["datetime"] = 11] = "datetime";
43
- DdbType[DdbType["timestamp"] = 12] = "timestamp";
44
- DdbType[DdbType["nanotime"] = 13] = "nanotime";
45
- DdbType[DdbType["nanotimestamp"] = 14] = "nanotimestamp";
46
- DdbType[DdbType["float"] = 15] = "float";
47
- DdbType[DdbType["double"] = 16] = "double";
48
- DdbType[DdbType["symbol"] = 17] = "symbol";
49
- DdbType[DdbType["string"] = 18] = "string";
50
- DdbType[DdbType["uuid"] = 19] = "uuid";
51
- DdbType[DdbType["functiondef"] = 20] = "functiondef";
52
- DdbType[DdbType["handle"] = 21] = "handle";
53
- DdbType[DdbType["code"] = 22] = "code";
54
- DdbType[DdbType["datasource"] = 23] = "datasource";
55
- DdbType[DdbType["resource"] = 24] = "resource";
56
- DdbType[DdbType["any"] = 25] = "any";
57
- DdbType[DdbType["compress"] = 26] = "compress";
58
- DdbType[DdbType["dict"] = 27] = "dict";
59
- DdbType[DdbType["datehour"] = 28] = "datehour";
60
- DdbType[DdbType["ipaddr"] = 30] = "ipaddr";
61
- DdbType[DdbType["int128"] = 31] = "int128";
62
- DdbType[DdbType["blob"] = 32] = "blob";
63
- DdbType[DdbType["complex"] = 34] = "complex";
64
- DdbType[DdbType["point"] = 35] = "point";
65
- DdbType[DdbType["duration"] = 36] = "duration";
66
- DdbType[DdbType["decimal32"] = 37] = "decimal32";
67
- DdbType[DdbType["decimal64"] = 38] = "decimal64";
68
- DdbType[DdbType["decimal128"] = 39] = "decimal128";
69
- DdbType[DdbType["object"] = 40] = "object";
70
- DdbType[DdbType["pynone"] = 41] = "pynone";
71
- DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
72
- })(DdbType = DdbType || (DdbType = {}));
73
- export var DdbFunctionType;
74
- (function (DdbFunctionType) {
75
- DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
76
- DdbFunctionType[DdbFunctionType["SystemProc"] = 1] = "SystemProc";
77
- DdbFunctionType[DdbFunctionType["OperatorFunc"] = 2] = "OperatorFunc";
78
- DdbFunctionType[DdbFunctionType["UserDefinedFunc"] = 3] = "UserDefinedFunc";
79
- DdbFunctionType[DdbFunctionType["PartialFunc"] = 4] = "PartialFunc";
80
- DdbFunctionType[DdbFunctionType["DynamicFunc"] = 5] = "DynamicFunc";
81
- DdbFunctionType[DdbFunctionType["PiecewiseFunc"] = 6] = "PiecewiseFunc";
82
- DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
83
- DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
84
- })(DdbFunctionType = DdbFunctionType || (DdbFunctionType = {}));
85
- export var DdbDurationUnit;
86
- (function (DdbDurationUnit) {
87
- DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
88
- DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
89
- DdbDurationUnit[DdbDurationUnit["ms"] = 2] = "ms";
90
- DdbDurationUnit[DdbDurationUnit["s"] = 3] = "s";
91
- DdbDurationUnit[DdbDurationUnit["m"] = 4] = "m";
92
- DdbDurationUnit[DdbDurationUnit["H"] = 5] = "H";
93
- DdbDurationUnit[DdbDurationUnit["d"] = 6] = "d";
94
- DdbDurationUnit[DdbDurationUnit["w"] = 7] = "w";
95
- DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
96
- DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
97
- DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
98
- })(DdbDurationUnit = DdbDurationUnit || (DdbDurationUnit = {}));
99
- export var DdbChartType;
100
- (function (DdbChartType) {
101
- DdbChartType[DdbChartType["area"] = 0] = "area";
102
- DdbChartType[DdbChartType["bar"] = 1] = "bar";
103
- DdbChartType[DdbChartType["column"] = 2] = "column";
104
- DdbChartType[DdbChartType["histogram"] = 3] = "histogram";
105
- DdbChartType[DdbChartType["line"] = 4] = "line";
106
- DdbChartType[DdbChartType["pie"] = 5] = "pie";
107
- DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
108
- DdbChartType[DdbChartType["trend"] = 7] = "trend";
109
- DdbChartType[DdbChartType["kline"] = 8] = "kline";
110
- })(DdbChartType = DdbChartType || (DdbChartType = {}));
111
- export const nulls = {
112
- int8: -0x80,
113
- int16: -0x80_00,
114
- int32: -0x80_00_00_00,
115
- int64: -0x8000000000000000n,
116
- float32: -3.4028234663852886e+38,
117
- /** -Number.MAX_VALUE */
118
- double: -Number.MAX_VALUE,
119
- bytes16: Uint8Array.from(new Array(16).fill(0))
9
+ import { DdbDecimal128Serializor } from './data-types/decimal-128.js';
10
+ import { BigInt128Array } from './shared/bigint-128-array.js';
11
+ import { is_decimal_type, is_decimal_null_value } from './shared/utils/decimal-type.js';
12
+ import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
13
+ export * from './shared/constants.js';
14
+ // Simulate other TypedArray behavior in nodejs
15
+ BigInt128Array.prototype[inspect.custom] = function () {
16
+ const values = [];
17
+ for (const value of this)
18
+ values.push(value);
19
+ const value_str = values.length ? ` ${values.map(v => v.toString() + 'n').join(', ')} ` : '';
20
+ return `${this[Symbol.toStringTag]}(${this.length}) [${value_str}]`;
120
21
  };
121
22
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
122
23
  class DdbObj {
@@ -473,6 +374,9 @@ class DdbObj {
473
374
  const data = dv.getBigInt64(4, le);
474
375
  return [12, { scale: dv.getInt32(0, le), data: data === nulls.int64 ? null : data }];
475
376
  }
377
+ case DdbType.decimal128: {
378
+ return DdbDecimal128Serializor.parse_as_scalar(buf, le);
379
+ }
476
380
  default:
477
381
  throw new Error(String(DdbType[type] || type) + t(' 暂时不支持解析'));
478
382
  }
@@ -541,8 +445,8 @@ class DdbObj {
541
445
  const type_ = type - 64;
542
446
  const cols = dv.getUint32(4, le);
543
447
  let blocks = [];
544
- // decimal32/64 会在所有 blocks 之前多一个 scale
545
- if (type_ === DdbType.decimal32 || type_ === DdbType.decimal64) {
448
+ // decimal 会在所有 blocks 之前多一个 scale
449
+ if (is_decimal_type(type_)) {
546
450
  blocks.scale = dv.getInt32(i_items_start, le);
547
451
  i_items_start += 4;
548
452
  }
@@ -585,6 +489,9 @@ class DdbObj {
585
489
  len_items = total_length * 8;
586
490
  data = new BigInt64Array(buf.buffer.slice(buf.byteOffset + i_data_start, buf.byteOffset + i_data_start + len_items));
587
491
  break;
492
+ case DdbType.decimal128:
493
+ [len_items, data] = DdbDecimal128Serializor.parse_as_same_type_vector_values(buf, i_data_start, total_length);
494
+ break;
588
495
  default:
589
496
  [len_items, data] = this.parse_vector_items(buf.subarray(i_data_start), le, type - 64, total_length);
590
497
  }
@@ -777,6 +684,8 @@ class DdbObj {
777
684
  }
778
685
  ];
779
686
  }
687
+ case DdbType.decimal128:
688
+ return DdbDecimal128Serializor.parse_as_vector_items(buf, length, le);
780
689
  // 以下情况时, DdbType.duration 实际会返回一个 any vector
781
690
  // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
782
691
  // <Buffer 19 01 type = any, form = vector
@@ -913,6 +822,8 @@ class DdbObj {
913
822
  const { scale, data } = this.value;
914
823
  return [Int32Array.of(scale), BigInt64Array.of(data === null ? nulls.int64 : data)];
915
824
  }
825
+ case DdbType.decimal128:
826
+ return DdbDecimal128Serializor.pack(this.value);
916
827
  default:
917
828
  throw new Error(String(DdbType[type] || type) + t(' 暂时不支持序列化'));
918
829
  }
@@ -922,7 +833,7 @@ class DdbObj {
922
833
  if (form === DdbForm.vector && 64 <= type && type < 128)
923
834
  return [
924
835
  Uint32Array.of(this.rows, this.cols),
925
- ...(type - 64 === DdbType.decimal32 || type - 64 === DdbType.decimal64) ?
836
+ ...(is_decimal_type(type - 64)) ?
926
837
  [Int32Array.of(this.value.scale)]
927
838
  :
928
839
  [],
@@ -1069,7 +980,8 @@ class DdbObj {
1069
980
  ];
1070
981
  }
1071
982
  case DdbType.decimal32:
1072
- case DdbType.decimal64: {
983
+ case DdbType.decimal64:
984
+ case DdbType.decimal128: {
1073
985
  const { scale, data } = value;
1074
986
  return [Int32Array.of(scale), data];
1075
987
  }
@@ -1117,9 +1029,9 @@ class DdbObj {
1117
1029
  switch (type_) {
1118
1030
  case DdbType.decimal32:
1119
1031
  case DdbType.decimal64:
1032
+ case DdbType.decimal128:
1120
1033
  const x = data[acc_len + i];
1121
- if (x === nulls.int64 /* && _type === DdbType.decimal64 一定成立 */ ||
1122
- x === nulls.int32 && type_ === DdbType.decimal32)
1034
+ if (is_decimal_null_value(type_, x))
1123
1035
  return '';
1124
1036
  const { scale } = this.value;
1125
1037
  const s = String(x < 0 ? -x : x).padStart(scale, '0');
@@ -1184,7 +1096,8 @@ class DdbObj {
1184
1096
  return format_array(items, len_data > limit);
1185
1097
  }
1186
1098
  case DdbType.decimal32:
1187
- case DdbType.decimal64: {
1099
+ case DdbType.decimal64:
1100
+ case DdbType.decimal128: {
1188
1101
  const limit = 50;
1189
1102
  const { data } = this.value;
1190
1103
  let items = new Array(Math.min(limit, data.length));
@@ -1499,11 +1412,11 @@ export function format(type, value, le, options = {}) {
1499
1412
  return options.colors ? str.magenta : str;
1500
1413
  }
1501
1414
  case DdbType.decimal32:
1502
- case DdbType.decimal64: {
1415
+ case DdbType.decimal64:
1416
+ case DdbType.decimal128: {
1503
1417
  const { scale, data } = value;
1504
1418
  if (data === null ||
1505
- (data === nulls.int64 && type === DdbType.decimal64) ||
1506
- (data === nulls.int32 && type === DdbType.decimal32))
1419
+ is_decimal_null_value(type, data))
1507
1420
  return 'null';
1508
1421
  const s = String(data < 0 ? -data : data).padStart(scale, '0');
1509
1422
  const str = (data < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
@@ -1546,9 +1459,9 @@ export function formati(obj, index, options = {}) {
1546
1459
  switch (type_) {
1547
1460
  case DdbType.decimal32:
1548
1461
  case DdbType.decimal64:
1462
+ case DdbType.decimal128:
1549
1463
  const x = data[acc_len + i];
1550
- if (x === nulls.int64 /* && type_ === DdbType.decimal64 一定成立 */ ||
1551
- x === nulls.int32 && type_ === DdbType.decimal32)
1464
+ if (is_decimal_null_value(type_, x))
1552
1465
  return '';
1553
1466
  const { scale } = obj.value;
1554
1467
  const s = String(x < 0 ? -x : x).padStart(scale, '0');
@@ -1598,11 +1511,11 @@ export function formati(obj, index, options = {}) {
1598
1511
  case DdbType.point:
1599
1512
  return format(obj.type, obj.value.subarray(2 * index, 2 * (index + 1)), obj.le, options);
1600
1513
  case DdbType.decimal32:
1601
- case DdbType.decimal64: {
1514
+ case DdbType.decimal64:
1515
+ case DdbType.decimal128: {
1602
1516
  const { scale, data } = obj.value;
1603
1517
  const x = data[index];
1604
- if (x === nulls.int64 && obj.type === DdbType.decimal64 ||
1605
- x === nulls.int32 && obj.type === DdbType.decimal32)
1518
+ if (is_decimal_null_value(obj.type, x))
1606
1519
  return '';
1607
1520
  const s = String(x < 0 ? -x : x).padStart(scale, '0');
1608
1521
  const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);