dolphindb 2.0.507 → 2.0.510
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 +18 -6
- package/browser.js +78 -40
- package/browser.js.map +1 -1
- package/index.d.ts +18 -6
- package/index.js +78 -40
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -78,8 +78,22 @@ export interface DdbArrayVectorBlock {
|
|
|
78
78
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
79
79
|
data: DdbVectorValue;
|
|
80
80
|
}
|
|
81
|
-
export
|
|
82
|
-
|
|
81
|
+
export interface DdbMatrixValue {
|
|
82
|
+
rows: DdbObj<DdbVectorValue>;
|
|
83
|
+
cols: DdbObj<DdbVectorValue>;
|
|
84
|
+
data: DdbVectorValue;
|
|
85
|
+
}
|
|
86
|
+
export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
|
|
87
|
+
[
|
|
88
|
+
number,
|
|
89
|
+
number
|
|
90
|
+
] | // complex, point
|
|
91
|
+
DdbFunctionDefValue;
|
|
92
|
+
export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
|
|
93
|
+
Uint8Array[] | // blob
|
|
94
|
+
DdbObj[] | // any
|
|
95
|
+
DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
96
|
+
export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
|
|
83
97
|
export declare const nulls: {
|
|
84
98
|
readonly int8: -128;
|
|
85
99
|
readonly int16: -32768;
|
|
@@ -123,8 +137,6 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
123
137
|
rows?: number;
|
|
124
138
|
/** 第 2 维 */
|
|
125
139
|
cols?: number;
|
|
126
|
-
/** matrix 中值的类型,仅 matrix 才有 */
|
|
127
|
-
datatype?: DdbType;
|
|
128
140
|
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
|
|
129
141
|
value: T;
|
|
130
142
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
@@ -134,11 +146,11 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
134
146
|
type: DdbType;
|
|
135
147
|
});
|
|
136
148
|
static parse(buf: Uint8Array, le: boolean): DdbObj<DdbValue>;
|
|
137
|
-
static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number,
|
|
149
|
+
static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbScalarValue];
|
|
138
150
|
/** parse: rows, cols, items
|
|
139
151
|
返回的 ddbobj.length 不包括 vector 的 type 和 form
|
|
140
152
|
*/
|
|
141
|
-
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj
|
|
153
|
+
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj<DdbVectorValue>;
|
|
142
154
|
/** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
|
|
143
155
|
static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
|
|
144
156
|
number,
|
package/index.js
CHANGED
|
@@ -239,34 +239,60 @@ class DdbObj {
|
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
case DdbForm.matrix: {
|
|
242
|
-
//
|
|
242
|
+
// rename!(
|
|
243
|
+
// 1..9$3:3,
|
|
243
244
|
// [1, 2, 3],
|
|
244
|
-
// [
|
|
245
|
-
//
|
|
246
|
-
// <Buffer
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
// 01
|
|
245
|
+
// ['c1', 'c2', 'c3']
|
|
246
|
+
// )
|
|
247
|
+
// <Buffer 04 03 type = int, form = matrix
|
|
248
|
+
// 03 has_row_label (& 0x01) = 1, has_col_label (& 0x02) = 1
|
|
249
|
+
// row labels
|
|
250
|
+
// 04 01 type = int, form = vector
|
|
251
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
252
|
+
// 01 00 00 00 02 00 00 00 03 00 00 00 vector values
|
|
253
|
+
// col labels
|
|
254
|
+
// 12 01 type = string, form = vector
|
|
255
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
256
|
+
// 63 31 00 63 32 00 63 33 00
|
|
257
|
+
// matrix data
|
|
258
|
+
// 04 03 type = matrix.type, form = matrix
|
|
259
|
+
// 03 00 00 00 03 00 00 00 rows = 3, cols = 3
|
|
250
260
|
const dv = new DataView(buf.buffer, buf.byteOffset + i_data);
|
|
251
261
|
const label_flags = buf_data[0];
|
|
252
262
|
const has_row_labels = Boolean(label_flags & 0x01);
|
|
253
263
|
const has_col_labels = Boolean(label_flags & 0x02);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
264
|
+
let row_labels = null;
|
|
265
|
+
let col_labels = null;
|
|
266
|
+
let offset = 1;
|
|
267
|
+
if (has_row_labels) {
|
|
268
|
+
row_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
269
|
+
row_labels.length += 2;
|
|
270
|
+
offset += row_labels.length;
|
|
271
|
+
}
|
|
272
|
+
if (has_col_labels) {
|
|
273
|
+
col_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
274
|
+
col_labels.length += 2;
|
|
275
|
+
offset += col_labels.length;
|
|
276
|
+
}
|
|
277
|
+
if (buf_data[offset] !== type)
|
|
278
|
+
throw new Error('matrix.datatype !== matrix.type');
|
|
279
|
+
const rows = dv.getUint32(offset + 2, le);
|
|
280
|
+
const cols = dv.getUint32(offset + 6, le);
|
|
281
|
+
const [len_items, data] = this.parse_vector_items(buf_data.subarray(offset + 10), le, type, rows * cols // 假设小于 2**32
|
|
260
282
|
);
|
|
283
|
+
offset += 10 + len_items;
|
|
261
284
|
return new this({
|
|
262
285
|
le,
|
|
263
286
|
form,
|
|
264
287
|
type,
|
|
265
|
-
length: i_data +
|
|
288
|
+
length: i_data + offset,
|
|
266
289
|
rows,
|
|
267
290
|
cols,
|
|
268
|
-
|
|
269
|
-
|
|
291
|
+
value: {
|
|
292
|
+
rows: row_labels,
|
|
293
|
+
cols: col_labels,
|
|
294
|
+
data,
|
|
295
|
+
},
|
|
270
296
|
});
|
|
271
297
|
}
|
|
272
298
|
default:
|
|
@@ -494,6 +520,7 @@ class DdbObj {
|
|
|
494
520
|
case DdbType.minute:
|
|
495
521
|
case DdbType.second:
|
|
496
522
|
case DdbType.datetime:
|
|
523
|
+
case DdbType.datehour:
|
|
497
524
|
return [
|
|
498
525
|
4 * length,
|
|
499
526
|
new Int32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + 4 * length))
|
|
@@ -618,7 +645,7 @@ class DdbObj {
|
|
|
618
645
|
}
|
|
619
646
|
pack() {
|
|
620
647
|
const { form, type, value } = this;
|
|
621
|
-
let header = new Uint8Array(
|
|
648
|
+
let header = new Uint8Array(2);
|
|
622
649
|
header[0] = type;
|
|
623
650
|
header[1] = form;
|
|
624
651
|
const body = (() => {
|
|
@@ -759,12 +786,17 @@ class DdbObj {
|
|
|
759
786
|
value[0].pack(),
|
|
760
787
|
value[1].pack(),
|
|
761
788
|
];
|
|
762
|
-
case DdbForm.matrix:
|
|
789
|
+
case DdbForm.matrix: {
|
|
790
|
+
const { rows, cols, data } = value;
|
|
763
791
|
return [
|
|
764
|
-
Uint8Array.of(
|
|
792
|
+
Uint8Array.of((rows && 0x01) | (cols && 0x02)),
|
|
793
|
+
...rows ? [rows.pack()] : [],
|
|
794
|
+
...cols ? [cols.pack()] : [],
|
|
795
|
+
Uint8Array.of(this.type, this.form),
|
|
765
796
|
Uint32Array.of(this.rows, this.cols),
|
|
766
|
-
...DdbObj.pack_vector_body(
|
|
797
|
+
...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
|
|
767
798
|
];
|
|
799
|
+
}
|
|
768
800
|
default:
|
|
769
801
|
throw new Error(`${DdbForm[form]} 暂不支持序列化`);
|
|
770
802
|
}
|
|
@@ -792,6 +824,7 @@ class DdbObj {
|
|
|
792
824
|
case DdbType.minute:
|
|
793
825
|
case DdbType.second:
|
|
794
826
|
case DdbType.datetime:
|
|
827
|
+
case DdbType.datehour:
|
|
795
828
|
return [value];
|
|
796
829
|
case DdbType.float:
|
|
797
830
|
return [value];
|
|
@@ -878,7 +911,7 @@ class DdbObj {
|
|
|
878
911
|
case DdbForm.dict:
|
|
879
912
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
880
913
|
case DdbForm.matrix:
|
|
881
|
-
return `matrix<${DdbType[this.
|
|
914
|
+
return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
|
|
882
915
|
default:
|
|
883
916
|
return `${DdbForm[this.form]} ${tname}`;
|
|
884
917
|
}
|
|
@@ -1552,25 +1585,30 @@ class DDB {
|
|
|
1552
1585
|
catch { }
|
|
1553
1586
|
// 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
|
|
1554
1587
|
this.on_message = ({ data: buffer }) => {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1588
|
+
try {
|
|
1589
|
+
const buf = new Uint8Array(buffer);
|
|
1590
|
+
if (this.print_message_buffer)
|
|
1591
|
+
console.log((0, utils_js_1.typed_array_to_buffer)(buf));
|
|
1592
|
+
const message = this.parse_message(buf, parse_object);
|
|
1593
|
+
listener?.(message, this);
|
|
1594
|
+
for (const listener of _handlers)
|
|
1595
|
+
listener(message, this);
|
|
1596
|
+
const { type, data } = message;
|
|
1597
|
+
switch (type) {
|
|
1598
|
+
case 'print':
|
|
1599
|
+
if (this.print_message)
|
|
1600
|
+
console.log(data);
|
|
1601
|
+
return;
|
|
1602
|
+
case 'object':
|
|
1603
|
+
resolve(data);
|
|
1604
|
+
return;
|
|
1605
|
+
case 'error':
|
|
1606
|
+
reject(data);
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
catch (error) {
|
|
1611
|
+
reject(error);
|
|
1574
1612
|
}
|
|
1575
1613
|
};
|
|
1576
1614
|
args = this.to_ddbobjs(args);
|