dolphindb 0.0.15 → 2.0.502
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/README.md +36 -7
- package/README.zh.md +35 -6
- package/browser.d.ts +29 -17
- package/browser.js +171 -63
- package/browser.js.map +1 -1
- package/index.d.ts +32 -18
- package/index.js +174 -64
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/test/index.d.ts +1 -0
- package/test/index.js +20 -0
- package/test/index.js.map +1 -0
- package/test/print.d.ts +2 -0
- package/test/print.js +20 -0
- package/test/print.js.map +1 -0
- package/test/types.d.ts +2 -0
- package/test/types.js +24 -0
- package/test/types.js.map +1 -0
package/index.d.ts
CHANGED
|
@@ -81,17 +81,24 @@ export interface DdbArrayVectorBlock {
|
|
|
81
81
|
export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
82
82
|
export declare type DdbVectorValue = string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
83
83
|
export declare const nulls: {
|
|
84
|
+
readonly bool: 128;
|
|
84
85
|
readonly char: "";
|
|
85
86
|
readonly int16: -32768;
|
|
86
87
|
readonly int32: -2147483648;
|
|
87
88
|
readonly int64: -9223372036854775808n;
|
|
89
|
+
readonly float32: -3.4028234663852886e+38;
|
|
90
|
+
/** -Number.MAX_VALUE */
|
|
91
|
+
readonly double: number;
|
|
92
|
+
readonly bytes16: Uint8Array;
|
|
88
93
|
};
|
|
89
94
|
export declare const timezone_offset: number;
|
|
90
95
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
91
96
|
export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
92
97
|
static dec: TextDecoder;
|
|
93
98
|
static enc: TextEncoder;
|
|
94
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base
|
|
99
|
+
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
100
|
+
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
101
|
+
*/
|
|
95
102
|
static symbol_bases: Record<number, string[]>;
|
|
96
103
|
/** little endian (client) */
|
|
97
104
|
static le_client: boolean;
|
|
@@ -147,49 +154,55 @@ export declare class DdbVoid extends DdbObj<undefined> {
|
|
|
147
154
|
constructor();
|
|
148
155
|
}
|
|
149
156
|
export declare class DdbBool extends DdbObj<boolean> {
|
|
150
|
-
constructor(value: boolean);
|
|
157
|
+
constructor(value: boolean | null);
|
|
151
158
|
}
|
|
152
159
|
export declare class DdbChar extends DdbObj<string> {
|
|
153
|
-
constructor(value: string);
|
|
160
|
+
constructor(value: string | null);
|
|
154
161
|
}
|
|
155
162
|
export declare class DdbInt extends DdbObj<number> {
|
|
156
|
-
constructor(value: number);
|
|
163
|
+
constructor(value: number | null);
|
|
157
164
|
}
|
|
158
165
|
export declare class DdbString extends DdbObj<string> {
|
|
159
166
|
constructor(value: string);
|
|
160
167
|
}
|
|
161
168
|
export declare class DdbLong extends DdbObj<bigint> {
|
|
162
|
-
constructor(value: bigint);
|
|
169
|
+
constructor(value: bigint | null);
|
|
163
170
|
}
|
|
164
171
|
export declare class DdbDouble extends DdbObj<number> {
|
|
165
|
-
constructor(value: number);
|
|
172
|
+
constructor(value: number | null);
|
|
166
173
|
}
|
|
167
174
|
export declare class DdbDateTime extends DdbObj<number> {
|
|
168
|
-
constructor(value: number);
|
|
175
|
+
constructor(value: number | null);
|
|
169
176
|
}
|
|
170
177
|
export declare class DdbTimeStamp extends DdbObj<bigint> {
|
|
171
|
-
constructor(value: bigint);
|
|
178
|
+
constructor(value: bigint | null);
|
|
172
179
|
}
|
|
173
180
|
export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
|
|
174
|
-
constructor(value: bigint);
|
|
181
|
+
constructor(value: bigint | null);
|
|
182
|
+
}
|
|
183
|
+
export declare class DdbPair extends DdbObj<Int32Array> {
|
|
184
|
+
constructor(l: number | null, r?: number | null);
|
|
185
|
+
}
|
|
186
|
+
export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
187
|
+
constructor(name: string, type: DdbFunctionType);
|
|
175
188
|
}
|
|
176
189
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
177
|
-
constructor(
|
|
190
|
+
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
178
191
|
}
|
|
179
192
|
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
180
|
-
constructor(
|
|
193
|
+
constructor(strings: string[], name?: string);
|
|
181
194
|
}
|
|
182
195
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
183
|
-
constructor(
|
|
196
|
+
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
184
197
|
}
|
|
185
198
|
export declare class DdbVectorAny extends DdbObj {
|
|
186
|
-
constructor(
|
|
199
|
+
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
187
200
|
}
|
|
188
|
-
export declare class
|
|
189
|
-
constructor(
|
|
201
|
+
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
202
|
+
constructor(strings: string[], name?: string);
|
|
190
203
|
}
|
|
191
|
-
export declare class
|
|
192
|
-
constructor(
|
|
204
|
+
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
205
|
+
constructor(columns: DdbObj[], name?: string);
|
|
193
206
|
}
|
|
194
207
|
export declare function date2str(date: number, format?: string): string;
|
|
195
208
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
@@ -248,6 +261,7 @@ export declare class DDB {
|
|
|
248
261
|
presolver(buf: Uint8Array): void;
|
|
249
262
|
prejector(error: Error): void;
|
|
250
263
|
presult: Promise<Uint8Array>;
|
|
264
|
+
get connected(): boolean;
|
|
251
265
|
/**
|
|
252
266
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
253
267
|
(without establishing an actual network connection)
|
|
@@ -348,7 +362,7 @@ export declare class DDB {
|
|
|
348
362
|
};
|
|
349
363
|
/** 自动转换 js string, boolean 为 DdbObj */
|
|
350
364
|
to_ddbobj(value: DdbObj | string | boolean): DdbObj;
|
|
351
|
-
/** 转换 js 数组为 DdbObj[]
|
|
365
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
352
366
|
to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
353
367
|
}
|
|
354
368
|
export default DDB;
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.
|
|
3
|
+
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = 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.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ws_1 = require("ws");
|
|
6
6
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
@@ -109,10 +109,15 @@ var DdbFunctionType;
|
|
|
109
109
|
DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
|
|
110
110
|
})(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
|
|
111
111
|
exports.nulls = {
|
|
112
|
+
bool: 0x80,
|
|
112
113
|
char: '\x80',
|
|
113
114
|
int16: -32768,
|
|
114
115
|
int32: -2147483648,
|
|
115
|
-
int64: -0x8000000000000000n,
|
|
116
|
+
int64: -0x8000000000000000n,
|
|
117
|
+
float32: -3.4028234663852886e+38,
|
|
118
|
+
/** -Number.MAX_VALUE */
|
|
119
|
+
double: -Number.MAX_VALUE,
|
|
120
|
+
bytes16: Uint8Array.from(new Array(16).fill(0))
|
|
116
121
|
};
|
|
117
122
|
exports.timezone_offset = 1000 * 60 * new Date().getTimezoneOffset();
|
|
118
123
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
@@ -129,7 +134,7 @@ class DdbObj {
|
|
|
129
134
|
form: DdbForm.scalar,
|
|
130
135
|
type: DdbType.void,
|
|
131
136
|
length: 0,
|
|
132
|
-
value:
|
|
137
|
+
value: null
|
|
133
138
|
});
|
|
134
139
|
const type = buf[0];
|
|
135
140
|
const form = buf[1];
|
|
@@ -278,13 +283,18 @@ class DdbObj {
|
|
|
278
283
|
switch (type) {
|
|
279
284
|
case DdbType.void:
|
|
280
285
|
return [1, null];
|
|
281
|
-
case DdbType.bool:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
case DdbType.bool: {
|
|
287
|
+
const value = buf[0];
|
|
288
|
+
return [1, value === exports.nulls.bool ? null : Boolean(value)];
|
|
289
|
+
}
|
|
290
|
+
case DdbType.char: {
|
|
291
|
+
const value = String.fromCharCode(buf[0]);
|
|
292
|
+
return [1, value === exports.nulls.char ? null : value];
|
|
293
|
+
}
|
|
285
294
|
case DdbType.short: {
|
|
286
295
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
287
|
-
|
|
296
|
+
const value = dv.getInt16(0, le);
|
|
297
|
+
return [2, value === exports.nulls.int16 ? null : value];
|
|
288
298
|
}
|
|
289
299
|
case DdbType.int:
|
|
290
300
|
// datetime
|
|
@@ -296,15 +306,18 @@ class DdbObj {
|
|
|
296
306
|
case DdbType.datetime:
|
|
297
307
|
case DdbType.datehour: {
|
|
298
308
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
299
|
-
|
|
309
|
+
const value = dv.getInt32(0, le);
|
|
310
|
+
return [4, value === exports.nulls.int32 ? null : value];
|
|
300
311
|
}
|
|
301
312
|
case DdbType.float: {
|
|
302
313
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
303
|
-
|
|
314
|
+
const value = dv.getFloat32(0, le);
|
|
315
|
+
return [4, value === exports.nulls.float32 ? null : value];
|
|
304
316
|
}
|
|
305
317
|
case DdbType.double: {
|
|
306
318
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
307
|
-
|
|
319
|
+
const value = dv.getFloat64(0, le);
|
|
320
|
+
return [8, value === exports.nulls.double ? null : value];
|
|
308
321
|
}
|
|
309
322
|
case DdbType.long:
|
|
310
323
|
// timestamp
|
|
@@ -312,7 +325,8 @@ class DdbObj {
|
|
|
312
325
|
case DdbType.nanotime:
|
|
313
326
|
case DdbType.nanotimestamp: {
|
|
314
327
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
315
|
-
|
|
328
|
+
const value = dv.getBigInt64(0, le);
|
|
329
|
+
return [8, value === exports.nulls.int64 ? null : value];
|
|
316
330
|
}
|
|
317
331
|
case DdbType.string:
|
|
318
332
|
case DdbType.symbol:
|
|
@@ -613,11 +627,26 @@ class DdbObj {
|
|
|
613
627
|
case DdbType.void:
|
|
614
628
|
return [Uint8Array.of(1)];
|
|
615
629
|
case DdbType.bool:
|
|
616
|
-
return [
|
|
630
|
+
return [
|
|
631
|
+
Uint8Array.of(value === null ?
|
|
632
|
+
exports.nulls.bool
|
|
633
|
+
:
|
|
634
|
+
Number(value))
|
|
635
|
+
];
|
|
617
636
|
case DdbType.char:
|
|
618
|
-
return [
|
|
637
|
+
return [
|
|
638
|
+
Uint8Array.of((value === null ?
|
|
639
|
+
exports.nulls.char
|
|
640
|
+
:
|
|
641
|
+
value).charCodeAt(0))
|
|
642
|
+
];
|
|
619
643
|
case DdbType.short:
|
|
620
|
-
return [
|
|
644
|
+
return [
|
|
645
|
+
Int16Array.of(value === null ?
|
|
646
|
+
exports.nulls.int16
|
|
647
|
+
:
|
|
648
|
+
value)
|
|
649
|
+
];
|
|
621
650
|
case DdbType.int:
|
|
622
651
|
// datetime
|
|
623
652
|
case DdbType.date:
|
|
@@ -627,17 +656,37 @@ class DdbObj {
|
|
|
627
656
|
case DdbType.second:
|
|
628
657
|
case DdbType.datetime:
|
|
629
658
|
case DdbType.datehour:
|
|
630
|
-
return [
|
|
659
|
+
return [
|
|
660
|
+
Int32Array.of(value === null ?
|
|
661
|
+
exports.nulls.int32
|
|
662
|
+
:
|
|
663
|
+
value)
|
|
664
|
+
];
|
|
631
665
|
case DdbType.float:
|
|
632
|
-
return [
|
|
666
|
+
return [
|
|
667
|
+
Float32Array.of(value === null ?
|
|
668
|
+
exports.nulls.float32
|
|
669
|
+
:
|
|
670
|
+
value)
|
|
671
|
+
];
|
|
633
672
|
case DdbType.double:
|
|
634
|
-
return [
|
|
673
|
+
return [
|
|
674
|
+
Float64Array.of(value === null ?
|
|
675
|
+
exports.nulls.double
|
|
676
|
+
:
|
|
677
|
+
value)
|
|
678
|
+
];
|
|
635
679
|
case DdbType.long:
|
|
636
680
|
// timestamp
|
|
637
681
|
case DdbType.timestamp:
|
|
638
682
|
case DdbType.nanotime:
|
|
639
683
|
case DdbType.nanotimestamp:
|
|
640
|
-
return [
|
|
684
|
+
return [
|
|
685
|
+
BigInt64Array.of(value === null ?
|
|
686
|
+
exports.nulls.int64
|
|
687
|
+
:
|
|
688
|
+
value)
|
|
689
|
+
];
|
|
641
690
|
case DdbType.string:
|
|
642
691
|
case DdbType.symbol:
|
|
643
692
|
case DdbType.code:
|
|
@@ -697,15 +746,12 @@ class DdbObj {
|
|
|
697
746
|
case DdbForm.table:
|
|
698
747
|
return [
|
|
699
748
|
Uint32Array.of(this.rows, this.cols),
|
|
700
|
-
DdbObj.enc.encode(this.name),
|
|
749
|
+
DdbObj.enc.encode(this.name || ''),
|
|
750
|
+
// column names
|
|
701
751
|
Uint8Array.of(0),
|
|
702
|
-
...DdbObj.pack_vector_body(this.value.map(col => col.name), DdbType.string, this.cols),
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
for (let i = 0; i < cols.length; i++)
|
|
706
|
-
cols[i] = this.value[i].pack();
|
|
707
|
-
return cols;
|
|
708
|
-
})()
|
|
752
|
+
...DdbObj.pack_vector_body(this.value.map((col, i) => col.name || `col${i}`), DdbType.string, this.cols),
|
|
753
|
+
// column vectors
|
|
754
|
+
...this.value.map(col => col.pack())
|
|
709
755
|
];
|
|
710
756
|
case DdbForm.dict:
|
|
711
757
|
return [
|
|
@@ -801,7 +847,7 @@ class DdbObj {
|
|
|
801
847
|
case DdbType.symbol_extended: {
|
|
802
848
|
const { base_id, base, data } = value;
|
|
803
849
|
return [
|
|
804
|
-
Uint32Array.of(base_id, base.length),
|
|
850
|
+
Uint32Array.of(base_id || 0, base.length),
|
|
805
851
|
...this.pack_vector_body(base, DdbType.string, base.length),
|
|
806
852
|
data
|
|
807
853
|
];
|
|
@@ -888,7 +934,9 @@ class DdbObj {
|
|
|
888
934
|
exports.DdbObj = DdbObj;
|
|
889
935
|
DdbObj.dec = new TextDecoder('utf-8');
|
|
890
936
|
DdbObj.enc = new TextEncoder();
|
|
891
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base
|
|
937
|
+
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
938
|
+
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
939
|
+
*/
|
|
892
940
|
DdbObj.symbol_bases = {};
|
|
893
941
|
/** little endian (client) */
|
|
894
942
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
@@ -898,6 +946,7 @@ class DdbVoid extends DdbObj {
|
|
|
898
946
|
form: DdbForm.scalar,
|
|
899
947
|
type: DdbType.void,
|
|
900
948
|
length: 0,
|
|
949
|
+
value: null,
|
|
901
950
|
});
|
|
902
951
|
}
|
|
903
952
|
}
|
|
@@ -930,7 +979,7 @@ class DdbInt extends DdbObj {
|
|
|
930
979
|
form: DdbForm.scalar,
|
|
931
980
|
type: DdbType.int,
|
|
932
981
|
length: 4,
|
|
933
|
-
value
|
|
982
|
+
value,
|
|
934
983
|
});
|
|
935
984
|
}
|
|
936
985
|
}
|
|
@@ -1001,86 +1050,143 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1001
1050
|
}
|
|
1002
1051
|
}
|
|
1003
1052
|
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
1053
|
+
class DdbPair extends DdbObj {
|
|
1054
|
+
constructor(l, r = null) {
|
|
1055
|
+
super({
|
|
1056
|
+
form: DdbForm.pair,
|
|
1057
|
+
type: DdbType.int,
|
|
1058
|
+
length: 0,
|
|
1059
|
+
rows: 2,
|
|
1060
|
+
cols: 1,
|
|
1061
|
+
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
exports.DdbPair = DdbPair;
|
|
1066
|
+
class DdbFunction extends DdbObj {
|
|
1067
|
+
constructor(name, type) {
|
|
1068
|
+
super({
|
|
1069
|
+
form: DdbForm.scalar,
|
|
1070
|
+
type: DdbType.functiondef,
|
|
1071
|
+
length: 0,
|
|
1072
|
+
value: { type, name }
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
exports.DdbFunction = DdbFunction;
|
|
1004
1077
|
class DdbVectorInt extends DdbObj {
|
|
1005
|
-
constructor(
|
|
1078
|
+
constructor(ints, name) {
|
|
1006
1079
|
super({
|
|
1007
1080
|
form: DdbForm.vector,
|
|
1008
1081
|
type: DdbType.int,
|
|
1009
1082
|
length: 0,
|
|
1010
|
-
rows:
|
|
1083
|
+
rows: ints.length,
|
|
1011
1084
|
cols: 1,
|
|
1012
|
-
value: Int32Array
|
|
1085
|
+
value: ints instanceof Int32Array ?
|
|
1086
|
+
ints
|
|
1087
|
+
:
|
|
1088
|
+
Int32Array.from(ints, v => v === null ?
|
|
1089
|
+
exports.nulls.int32
|
|
1090
|
+
:
|
|
1091
|
+
v),
|
|
1013
1092
|
name,
|
|
1014
1093
|
});
|
|
1015
1094
|
}
|
|
1016
1095
|
}
|
|
1017
1096
|
exports.DdbVectorInt = DdbVectorInt;
|
|
1018
1097
|
class DdbVectorString extends DdbObj {
|
|
1019
|
-
constructor(
|
|
1098
|
+
constructor(strings, name) {
|
|
1020
1099
|
super({
|
|
1021
1100
|
form: DdbForm.vector,
|
|
1022
1101
|
type: DdbType.string,
|
|
1023
1102
|
length: 0,
|
|
1024
|
-
rows:
|
|
1103
|
+
rows: strings.length,
|
|
1025
1104
|
cols: 1,
|
|
1026
|
-
value,
|
|
1105
|
+
value: strings,
|
|
1027
1106
|
name,
|
|
1028
1107
|
});
|
|
1029
1108
|
}
|
|
1030
1109
|
}
|
|
1031
1110
|
exports.DdbVectorString = DdbVectorString;
|
|
1032
1111
|
class DdbVectorDouble extends DdbObj {
|
|
1033
|
-
constructor(
|
|
1112
|
+
constructor(doubles, name) {
|
|
1034
1113
|
super({
|
|
1035
1114
|
form: DdbForm.vector,
|
|
1036
1115
|
type: DdbType.double,
|
|
1037
1116
|
length: 0,
|
|
1038
|
-
rows:
|
|
1117
|
+
rows: doubles.length,
|
|
1039
1118
|
cols: 1,
|
|
1040
|
-
value: Float64Array
|
|
1119
|
+
value: doubles instanceof Float64Array ?
|
|
1120
|
+
doubles
|
|
1121
|
+
:
|
|
1122
|
+
Float64Array.from(doubles, v => v === null ?
|
|
1123
|
+
exports.nulls.double
|
|
1124
|
+
:
|
|
1125
|
+
v),
|
|
1041
1126
|
name,
|
|
1042
1127
|
});
|
|
1043
1128
|
}
|
|
1044
1129
|
}
|
|
1045
1130
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
1046
1131
|
class DdbVectorAny extends DdbObj {
|
|
1047
|
-
constructor(
|
|
1132
|
+
constructor(objs, name) {
|
|
1048
1133
|
super({
|
|
1049
1134
|
form: DdbForm.vector,
|
|
1050
1135
|
type: DdbType.any,
|
|
1051
1136
|
length: 0,
|
|
1052
|
-
rows:
|
|
1137
|
+
rows: objs.length,
|
|
1053
1138
|
cols: 1,
|
|
1054
|
-
value,
|
|
1139
|
+
value: objs,
|
|
1055
1140
|
name,
|
|
1056
1141
|
});
|
|
1057
1142
|
}
|
|
1058
1143
|
}
|
|
1059
1144
|
exports.DdbVectorAny = DdbVectorAny;
|
|
1060
|
-
class
|
|
1061
|
-
constructor(
|
|
1145
|
+
class DdbVectorSymbol extends DdbObj {
|
|
1146
|
+
constructor(strings, name) {
|
|
1147
|
+
let map = new Map([
|
|
1148
|
+
['', 0]
|
|
1149
|
+
]);
|
|
1150
|
+
let data = new Uint32Array(strings.length);
|
|
1151
|
+
for (let i = 0; i < strings.length; i++) {
|
|
1152
|
+
const x = strings[i];
|
|
1153
|
+
let index = map.get(x);
|
|
1154
|
+
if (index === undefined) {
|
|
1155
|
+
index = map.size;
|
|
1156
|
+
map.set(x, index);
|
|
1157
|
+
}
|
|
1158
|
+
data[i] = index;
|
|
1159
|
+
}
|
|
1062
1160
|
super({
|
|
1063
|
-
form: DdbForm.
|
|
1064
|
-
type: DdbType.
|
|
1161
|
+
form: DdbForm.vector,
|
|
1162
|
+
type: DdbType.symbol_extended,
|
|
1065
1163
|
length: 0,
|
|
1066
|
-
rows:
|
|
1164
|
+
rows: strings.length,
|
|
1067
1165
|
cols: 1,
|
|
1068
|
-
value:
|
|
1166
|
+
value: {
|
|
1167
|
+
base: [...map.keys()],
|
|
1168
|
+
base_id: null,
|
|
1169
|
+
data,
|
|
1170
|
+
},
|
|
1171
|
+
name
|
|
1069
1172
|
});
|
|
1070
1173
|
}
|
|
1071
1174
|
}
|
|
1072
|
-
exports.
|
|
1073
|
-
class
|
|
1074
|
-
constructor(
|
|
1175
|
+
exports.DdbVectorSymbol = DdbVectorSymbol;
|
|
1176
|
+
class DdbTable extends DdbObj {
|
|
1177
|
+
constructor(columns, name = '') {
|
|
1075
1178
|
super({
|
|
1076
|
-
form: DdbForm.
|
|
1077
|
-
type: DdbType.
|
|
1179
|
+
form: DdbForm.table,
|
|
1180
|
+
type: DdbType.void,
|
|
1078
1181
|
length: 0,
|
|
1079
|
-
|
|
1182
|
+
rows: columns[0].rows,
|
|
1183
|
+
cols: columns.length,
|
|
1184
|
+
name,
|
|
1185
|
+
value: columns,
|
|
1080
1186
|
});
|
|
1081
1187
|
}
|
|
1082
1188
|
}
|
|
1083
|
-
exports.
|
|
1189
|
+
exports.DdbTable = DdbTable;
|
|
1084
1190
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1085
1191
|
return date === exports.nulls.int32 ?
|
|
1086
1192
|
''
|
|
@@ -1201,12 +1307,14 @@ class DDB {
|
|
|
1201
1307
|
/** resolver, rejector, promise of last rpc */
|
|
1202
1308
|
presolver(buf) { }
|
|
1203
1309
|
prejector(error) { }
|
|
1310
|
+
get connected() {
|
|
1311
|
+
return this.websocket?.readyState === ws_1.WebSocket.OPEN;
|
|
1312
|
+
}
|
|
1204
1313
|
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
|
|
1205
1314
|
async connect({ url = this.url, login = true, username = 'admin', password = '123456', python = false, } = {}) {
|
|
1206
1315
|
this.url = url;
|
|
1207
1316
|
this.python = python;
|
|
1208
|
-
|
|
1209
|
-
this.disconnect();
|
|
1317
|
+
this.disconnect();
|
|
1210
1318
|
let websocket = new ws_1.WebSocket(url, python ? ['python'] : [], {
|
|
1211
1319
|
maxPayload: 2 ** 33 // 8 GB
|
|
1212
1320
|
});
|
|
@@ -1299,7 +1407,11 @@ class DDB {
|
|
|
1299
1407
|
return `/ ${options.join('_')}`;
|
|
1300
1408
|
}
|
|
1301
1409
|
disconnect() {
|
|
1302
|
-
this.
|
|
1410
|
+
if (this.connected)
|
|
1411
|
+
this.websocket.close(1000);
|
|
1412
|
+
this.presolver = buf => { };
|
|
1413
|
+
this.prejector = error => { };
|
|
1414
|
+
this.presult = Promise.resolve(null);
|
|
1303
1415
|
}
|
|
1304
1416
|
/** rpc through websocket (function/script/variable command)
|
|
1305
1417
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
@@ -1310,7 +1422,7 @@ class DDB {
|
|
|
1310
1422
|
async rpc(type, { script, func, args = [], vars = [], urgent, }) {
|
|
1311
1423
|
if (!this.websocket)
|
|
1312
1424
|
await this.connect();
|
|
1313
|
-
if (this.
|
|
1425
|
+
if (!this.connected)
|
|
1314
1426
|
throw new Error(`${this.url} is already disconnected`);
|
|
1315
1427
|
// 临界区:保证多个 rpc 并发时形成 promise 链
|
|
1316
1428
|
// ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
|
|
@@ -1333,7 +1445,7 @@ class DDB {
|
|
|
1333
1445
|
// 临界区结束,只有一个 rpc 请求可以写 WebSocket
|
|
1334
1446
|
if (urgent && type !== 'script' && type !== 'function')
|
|
1335
1447
|
throw new Error('urgent 只适用于 script 和 funciton');
|
|
1336
|
-
this.to_ddbobjs(args);
|
|
1448
|
+
args = this.to_ddbobjs(args);
|
|
1337
1449
|
const command = this.enc.encode((() => {
|
|
1338
1450
|
switch (type) {
|
|
1339
1451
|
case 'function':
|
|
@@ -1479,11 +1591,9 @@ class DDB {
|
|
|
1479
1591
|
throw new Error(`不能自动转换 ${type} 至 DdbObj`);
|
|
1480
1592
|
}
|
|
1481
1593
|
}
|
|
1482
|
-
/** 转换 js 数组为 DdbObj[]
|
|
1594
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
1483
1595
|
to_ddbobjs(values) {
|
|
1484
|
-
|
|
1485
|
-
values[i] = this.to_ddbobj(values[i]);
|
|
1486
|
-
return values;
|
|
1596
|
+
return values.map(value => this.to_ddbobj(value));
|
|
1487
1597
|
}
|
|
1488
1598
|
}
|
|
1489
1599
|
exports.DDB = DDB;
|