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/README.md
CHANGED
|
@@ -220,6 +220,15 @@ const obj = new DdbObj({
|
|
|
220
220
|
})
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
+
##### NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript
|
|
224
|
+
```ts
|
|
225
|
+
;(await ddb.eval('double()')).value === null
|
|
226
|
+
|
|
227
|
+
// create NULL object
|
|
228
|
+
new DdbInt(null)
|
|
229
|
+
new DdbDouble(null)
|
|
230
|
+
```
|
|
231
|
+
|
|
223
232
|
|
|
224
233
|
#### `call` Method Declaration
|
|
225
234
|
```ts
|
|
@@ -321,18 +330,38 @@ async upload (
|
|
|
321
330
|
```
|
|
322
331
|
|
|
323
332
|
|
|
324
|
-
###
|
|
333
|
+
### Some Examples
|
|
325
334
|
```ts
|
|
326
|
-
import { nulls, DdbInt, timestamp2str } from 'dolphindb'
|
|
335
|
+
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
|
|
327
336
|
|
|
328
|
-
//
|
|
329
|
-
new DdbInt(nulls.int32)
|
|
330
|
-
|
|
331
|
-
// convert DolphinDB timestamp value to string
|
|
337
|
+
// Format timestamp in DolphinDB as string
|
|
332
338
|
timestamp2str(
|
|
333
339
|
(
|
|
334
|
-
await ddb.call
|
|
340
|
+
await ddb.call('now', [false])
|
|
341
|
+
// TypeScript: await ddb.call<DdbObj<bigint>>('now', [false])
|
|
335
342
|
).value
|
|
336
343
|
) === '2022.02.23 17:23:13.494'
|
|
344
|
+
|
|
345
|
+
// create symbol vector
|
|
346
|
+
new DdbVectorSymbol(['aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'bbb'])
|
|
347
|
+
|
|
348
|
+
// Create a double vector with NULL values using JavaScript native arrays
|
|
349
|
+
new DdbVectorDouble([0.1, null, 0.3])
|
|
350
|
+
|
|
351
|
+
// More efficient and memory efficient double vector creation using JavaScript TypedArray
|
|
352
|
+
let av = new Float64Array(3)
|
|
353
|
+
av[0] = 0.1
|
|
354
|
+
av[1] = nulls.double
|
|
355
|
+
av[2] = 0.3
|
|
356
|
+
new DdbVectorDouble(av)
|
|
357
|
+
|
|
358
|
+
// create DdbTable
|
|
359
|
+
new DdbTable(
|
|
360
|
+
[
|
|
361
|
+
new DdbVectorDouble([0.1, 0.2, null], 'col0'),
|
|
362
|
+
new DdbVectorSymbol(['a', 'b', 'c'], 'col1')
|
|
363
|
+
],
|
|
364
|
+
'mytable'
|
|
365
|
+
)
|
|
337
366
|
```
|
|
338
367
|
|
package/README.zh.md
CHANGED
|
@@ -221,6 +221,15 @@ const obj = new DdbObj({
|
|
|
221
221
|
})
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
+
##### scalar 形式的 NULL 对象, 对应 DdbObj 的 value 为 JavaScript 中的 null
|
|
225
|
+
```ts
|
|
226
|
+
;(await ddb.eval('double()')).value === null
|
|
227
|
+
|
|
228
|
+
// 创建 NULL 对象
|
|
229
|
+
new DdbInt(null)
|
|
230
|
+
new DdbDouble(null)
|
|
231
|
+
```
|
|
232
|
+
|
|
224
233
|
|
|
225
234
|
#### `call` 方法声明
|
|
226
235
|
```ts
|
|
@@ -322,17 +331,37 @@ async upload (
|
|
|
322
331
|
```
|
|
323
332
|
|
|
324
333
|
|
|
325
|
-
###
|
|
334
|
+
### 一些例子
|
|
326
335
|
```ts
|
|
327
|
-
import { nulls, DdbInt, timestamp2str } from 'dolphindb'
|
|
328
|
-
|
|
329
|
-
// 创建 DolphinDB 空值 (最小的 32-bit 整数)
|
|
330
|
-
new DdbInt(nulls.int32)
|
|
336
|
+
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
|
|
331
337
|
|
|
332
338
|
// 将 DolphinDB 中的 timestamp 格式化为 string
|
|
333
339
|
timestamp2str(
|
|
334
340
|
(
|
|
335
|
-
await ddb.call
|
|
341
|
+
await ddb.call('now', [false])
|
|
342
|
+
// TypeScript: await ddb.call<DdbObj<bigint>>('now', [false])
|
|
336
343
|
).value
|
|
337
344
|
) === '2022.02.23 17:23:13.494'
|
|
345
|
+
|
|
346
|
+
// 创建 symbol vector
|
|
347
|
+
new DdbVectorSymbol(['aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'bbb'])
|
|
348
|
+
|
|
349
|
+
// 使用 JavaScript 原生数组创建含有 NULL 值的 double vector
|
|
350
|
+
new DdbVectorDouble([0.1, null, 0.3])
|
|
351
|
+
|
|
352
|
+
// 使用 JavaScript TypedArray 更加高效且节约内存的创建 double vector
|
|
353
|
+
let av = new Float64Array(3)
|
|
354
|
+
av[0] = 0.1
|
|
355
|
+
av[1] = nulls.double
|
|
356
|
+
av[2] = 0.3
|
|
357
|
+
new DdbVectorDouble(av)
|
|
358
|
+
|
|
359
|
+
// 创建 DdbTable
|
|
360
|
+
new DdbTable(
|
|
361
|
+
[
|
|
362
|
+
new DdbVectorDouble([0.1, 0.2, null], 'col0'),
|
|
363
|
+
new DdbVectorSymbol(['a', 'b', 'c'], 'col1')
|
|
364
|
+
],
|
|
365
|
+
'mytable'
|
|
366
|
+
)
|
|
338
367
|
```
|
package/browser.d.ts
CHANGED
|
@@ -78,10 +78,15 @@ export interface DdbArrayVectorBlock {
|
|
|
78
78
|
export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
79
79
|
export declare type DdbVectorValue = string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
80
80
|
export declare const nulls: {
|
|
81
|
+
readonly bool: 128;
|
|
81
82
|
readonly char: "";
|
|
82
83
|
readonly int16: -32768;
|
|
83
84
|
readonly int32: -2147483648;
|
|
84
85
|
readonly int64: -9223372036854775808n;
|
|
86
|
+
readonly float32: -3.4028234663852886e+38;
|
|
87
|
+
/** -Number.MAX_VALUE */
|
|
88
|
+
readonly double: number;
|
|
89
|
+
readonly bytes16: Uint8Array;
|
|
85
90
|
};
|
|
86
91
|
export declare const timezone_offset: number;
|
|
87
92
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
@@ -149,49 +154,55 @@ export declare class DdbVoid extends DdbObj<undefined> {
|
|
|
149
154
|
constructor();
|
|
150
155
|
}
|
|
151
156
|
export declare class DdbBool extends DdbObj<boolean> {
|
|
152
|
-
constructor(value: boolean);
|
|
157
|
+
constructor(value: boolean | null);
|
|
153
158
|
}
|
|
154
159
|
export declare class DdbChar extends DdbObj<string> {
|
|
155
|
-
constructor(value: string);
|
|
160
|
+
constructor(value: string | null);
|
|
156
161
|
}
|
|
157
162
|
export declare class DdbInt extends DdbObj<number> {
|
|
158
|
-
constructor(value: number);
|
|
163
|
+
constructor(value: number | null);
|
|
159
164
|
}
|
|
160
165
|
export declare class DdbString extends DdbObj<string> {
|
|
161
166
|
constructor(value: string);
|
|
162
167
|
}
|
|
163
168
|
export declare class DdbLong extends DdbObj<bigint> {
|
|
164
|
-
constructor(value: bigint);
|
|
169
|
+
constructor(value: bigint | null);
|
|
165
170
|
}
|
|
166
171
|
export declare class DdbDouble extends DdbObj<number> {
|
|
167
|
-
constructor(value: number);
|
|
172
|
+
constructor(value: number | null);
|
|
168
173
|
}
|
|
169
174
|
export declare class DdbDateTime extends DdbObj<number> {
|
|
170
|
-
constructor(value: number);
|
|
175
|
+
constructor(value: number | null);
|
|
171
176
|
}
|
|
172
177
|
export declare class DdbTimeStamp extends DdbObj<bigint> {
|
|
173
|
-
constructor(value: bigint);
|
|
178
|
+
constructor(value: bigint | null);
|
|
174
179
|
}
|
|
175
180
|
export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
|
|
176
|
-
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);
|
|
177
188
|
}
|
|
178
189
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
179
|
-
constructor(
|
|
190
|
+
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
180
191
|
}
|
|
181
192
|
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
182
|
-
constructor(
|
|
193
|
+
constructor(strings: string[], name?: string);
|
|
183
194
|
}
|
|
184
195
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
185
|
-
constructor(
|
|
196
|
+
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
186
197
|
}
|
|
187
198
|
export declare class DdbVectorAny extends DdbObj {
|
|
188
|
-
constructor(
|
|
199
|
+
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
189
200
|
}
|
|
190
|
-
export declare class
|
|
191
|
-
constructor(
|
|
201
|
+
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
202
|
+
constructor(strings: string[], name?: string);
|
|
192
203
|
}
|
|
193
|
-
export declare class
|
|
194
|
-
constructor(
|
|
204
|
+
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
205
|
+
constructor(columns: DdbObj[], name?: string);
|
|
195
206
|
}
|
|
196
207
|
export declare function date2str(date: number, format?: string): string;
|
|
197
208
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
@@ -249,6 +260,7 @@ export declare class DDB {
|
|
|
249
260
|
presolver(buf: Uint8Array): void;
|
|
250
261
|
prejector(error: Error): void;
|
|
251
262
|
presult: Promise<Uint8Array>;
|
|
263
|
+
get connected(): boolean;
|
|
252
264
|
/**
|
|
253
265
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
254
266
|
(without establishing an actual network connection)
|
|
@@ -349,7 +361,7 @@ export declare class DDB {
|
|
|
349
361
|
};
|
|
350
362
|
/** 自动转换 js string, boolean 为 DdbObj */
|
|
351
363
|
to_ddbobj(value: DdbObj | string | boolean): DdbObj;
|
|
352
|
-
/** 转换 js 数组为 DdbObj[]
|
|
364
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
353
365
|
to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
354
366
|
}
|
|
355
367
|
export declare let ddb: DDB;
|
package/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.
|
|
3
|
+
exports.ddb = 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.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -72,10 +72,15 @@ var DdbFunctionType;
|
|
|
72
72
|
DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
|
|
73
73
|
})(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
|
|
74
74
|
exports.nulls = {
|
|
75
|
+
bool: 0x80,
|
|
75
76
|
char: '\x80',
|
|
76
77
|
int16: -32768,
|
|
77
78
|
int32: -2147483648,
|
|
78
|
-
int64: -0x8000000000000000n,
|
|
79
|
+
int64: -0x8000000000000000n,
|
|
80
|
+
float32: -3.4028234663852886e+38,
|
|
81
|
+
/** -Number.MAX_VALUE */
|
|
82
|
+
double: -Number.MAX_VALUE,
|
|
83
|
+
bytes16: Uint8Array.from(new Array(16).fill(0))
|
|
79
84
|
};
|
|
80
85
|
exports.timezone_offset = 1000 * 60 * new Date().getTimezoneOffset();
|
|
81
86
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
@@ -92,7 +97,7 @@ class DdbObj {
|
|
|
92
97
|
form: DdbForm.scalar,
|
|
93
98
|
type: DdbType.void,
|
|
94
99
|
length: 0,
|
|
95
|
-
value:
|
|
100
|
+
value: null
|
|
96
101
|
});
|
|
97
102
|
const type = buf[0];
|
|
98
103
|
const form = buf[1];
|
|
@@ -241,13 +246,18 @@ class DdbObj {
|
|
|
241
246
|
switch (type) {
|
|
242
247
|
case DdbType.void:
|
|
243
248
|
return [1, null];
|
|
244
|
-
case DdbType.bool:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
249
|
+
case DdbType.bool: {
|
|
250
|
+
const value = buf[0];
|
|
251
|
+
return [1, value === exports.nulls.bool ? null : Boolean(value)];
|
|
252
|
+
}
|
|
253
|
+
case DdbType.char: {
|
|
254
|
+
const value = String.fromCharCode(buf[0]);
|
|
255
|
+
return [1, value === exports.nulls.char ? null : value];
|
|
256
|
+
}
|
|
248
257
|
case DdbType.short: {
|
|
249
258
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
250
|
-
|
|
259
|
+
const value = dv.getInt16(0, le);
|
|
260
|
+
return [2, value === exports.nulls.int16 ? null : value];
|
|
251
261
|
}
|
|
252
262
|
case DdbType.int:
|
|
253
263
|
// datetime
|
|
@@ -259,15 +269,18 @@ class DdbObj {
|
|
|
259
269
|
case DdbType.datetime:
|
|
260
270
|
case DdbType.datehour: {
|
|
261
271
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
262
|
-
|
|
272
|
+
const value = dv.getInt32(0, le);
|
|
273
|
+
return [4, value === exports.nulls.int32 ? null : value];
|
|
263
274
|
}
|
|
264
275
|
case DdbType.float: {
|
|
265
276
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
266
|
-
|
|
277
|
+
const value = dv.getFloat32(0, le);
|
|
278
|
+
return [4, value === exports.nulls.float32 ? null : value];
|
|
267
279
|
}
|
|
268
280
|
case DdbType.double: {
|
|
269
281
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
270
|
-
|
|
282
|
+
const value = dv.getFloat64(0, le);
|
|
283
|
+
return [8, value === exports.nulls.double ? null : value];
|
|
271
284
|
}
|
|
272
285
|
case DdbType.long:
|
|
273
286
|
// timestamp
|
|
@@ -275,7 +288,8 @@ class DdbObj {
|
|
|
275
288
|
case DdbType.nanotime:
|
|
276
289
|
case DdbType.nanotimestamp: {
|
|
277
290
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
278
|
-
|
|
291
|
+
const value = dv.getBigInt64(0, le);
|
|
292
|
+
return [8, value === exports.nulls.int64 ? null : value];
|
|
279
293
|
}
|
|
280
294
|
case DdbType.string:
|
|
281
295
|
case DdbType.symbol:
|
|
@@ -576,11 +590,26 @@ class DdbObj {
|
|
|
576
590
|
case DdbType.void:
|
|
577
591
|
return [Uint8Array.of(1)];
|
|
578
592
|
case DdbType.bool:
|
|
579
|
-
return [
|
|
593
|
+
return [
|
|
594
|
+
Uint8Array.of(value === null ?
|
|
595
|
+
exports.nulls.bool
|
|
596
|
+
:
|
|
597
|
+
Number(value))
|
|
598
|
+
];
|
|
580
599
|
case DdbType.char:
|
|
581
|
-
return [
|
|
600
|
+
return [
|
|
601
|
+
Uint8Array.of((value === null ?
|
|
602
|
+
exports.nulls.char
|
|
603
|
+
:
|
|
604
|
+
value).charCodeAt(0))
|
|
605
|
+
];
|
|
582
606
|
case DdbType.short:
|
|
583
|
-
return [
|
|
607
|
+
return [
|
|
608
|
+
Int16Array.of(value === null ?
|
|
609
|
+
exports.nulls.int16
|
|
610
|
+
:
|
|
611
|
+
value)
|
|
612
|
+
];
|
|
584
613
|
case DdbType.int:
|
|
585
614
|
// datetime
|
|
586
615
|
case DdbType.date:
|
|
@@ -590,17 +619,37 @@ class DdbObj {
|
|
|
590
619
|
case DdbType.second:
|
|
591
620
|
case DdbType.datetime:
|
|
592
621
|
case DdbType.datehour:
|
|
593
|
-
return [
|
|
622
|
+
return [
|
|
623
|
+
Int32Array.of(value === null ?
|
|
624
|
+
exports.nulls.int32
|
|
625
|
+
:
|
|
626
|
+
value)
|
|
627
|
+
];
|
|
594
628
|
case DdbType.float:
|
|
595
|
-
return [
|
|
629
|
+
return [
|
|
630
|
+
Float32Array.of(value === null ?
|
|
631
|
+
exports.nulls.float32
|
|
632
|
+
:
|
|
633
|
+
value)
|
|
634
|
+
];
|
|
596
635
|
case DdbType.double:
|
|
597
|
-
return [
|
|
636
|
+
return [
|
|
637
|
+
Float64Array.of(value === null ?
|
|
638
|
+
exports.nulls.double
|
|
639
|
+
:
|
|
640
|
+
value)
|
|
641
|
+
];
|
|
598
642
|
case DdbType.long:
|
|
599
643
|
// timestamp
|
|
600
644
|
case DdbType.timestamp:
|
|
601
645
|
case DdbType.nanotime:
|
|
602
646
|
case DdbType.nanotimestamp:
|
|
603
|
-
return [
|
|
647
|
+
return [
|
|
648
|
+
BigInt64Array.of(value === null ?
|
|
649
|
+
exports.nulls.int64
|
|
650
|
+
:
|
|
651
|
+
value)
|
|
652
|
+
];
|
|
604
653
|
case DdbType.string:
|
|
605
654
|
case DdbType.symbol:
|
|
606
655
|
case DdbType.code:
|
|
@@ -660,15 +709,12 @@ class DdbObj {
|
|
|
660
709
|
case DdbForm.table:
|
|
661
710
|
return [
|
|
662
711
|
Uint32Array.of(this.rows, this.cols),
|
|
663
|
-
DdbObj.enc.encode(this.name),
|
|
712
|
+
DdbObj.enc.encode(this.name || ''),
|
|
713
|
+
// column names
|
|
664
714
|
Uint8Array.of(0),
|
|
665
|
-
...DdbObj.pack_vector_body(this.value.map(col => col.name), DdbType.string, this.cols),
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
for (let i = 0; i < cols.length; i++)
|
|
669
|
-
cols[i] = this.value[i].pack();
|
|
670
|
-
return cols;
|
|
671
|
-
})()
|
|
715
|
+
...DdbObj.pack_vector_body(this.value.map((col, i) => col.name || `col${i}`), DdbType.string, this.cols),
|
|
716
|
+
// column vectors
|
|
717
|
+
...this.value.map(col => col.pack())
|
|
672
718
|
];
|
|
673
719
|
case DdbForm.dict:
|
|
674
720
|
return [
|
|
@@ -764,7 +810,7 @@ class DdbObj {
|
|
|
764
810
|
case DdbType.symbol_extended: {
|
|
765
811
|
const { base_id, base, data } = value;
|
|
766
812
|
return [
|
|
767
|
-
Uint32Array.of(base_id, base.length),
|
|
813
|
+
Uint32Array.of(base_id || 0, base.length),
|
|
768
814
|
...this.pack_vector_body(base, DdbType.string, base.length),
|
|
769
815
|
data
|
|
770
816
|
];
|
|
@@ -879,6 +925,7 @@ class DdbVoid extends DdbObj {
|
|
|
879
925
|
form: DdbForm.scalar,
|
|
880
926
|
type: DdbType.void,
|
|
881
927
|
length: 0,
|
|
928
|
+
value: null,
|
|
882
929
|
});
|
|
883
930
|
}
|
|
884
931
|
}
|
|
@@ -911,7 +958,7 @@ class DdbInt extends DdbObj {
|
|
|
911
958
|
form: DdbForm.scalar,
|
|
912
959
|
type: DdbType.int,
|
|
913
960
|
length: 4,
|
|
914
|
-
value
|
|
961
|
+
value,
|
|
915
962
|
});
|
|
916
963
|
}
|
|
917
964
|
}
|
|
@@ -982,86 +1029,143 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
982
1029
|
}
|
|
983
1030
|
}
|
|
984
1031
|
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
1032
|
+
class DdbPair extends DdbObj {
|
|
1033
|
+
constructor(l, r = null) {
|
|
1034
|
+
super({
|
|
1035
|
+
form: DdbForm.pair,
|
|
1036
|
+
type: DdbType.int,
|
|
1037
|
+
length: 0,
|
|
1038
|
+
rows: 2,
|
|
1039
|
+
cols: 1,
|
|
1040
|
+
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
exports.DdbPair = DdbPair;
|
|
1045
|
+
class DdbFunction extends DdbObj {
|
|
1046
|
+
constructor(name, type) {
|
|
1047
|
+
super({
|
|
1048
|
+
form: DdbForm.scalar,
|
|
1049
|
+
type: DdbType.functiondef,
|
|
1050
|
+
length: 0,
|
|
1051
|
+
value: { type, name }
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
exports.DdbFunction = DdbFunction;
|
|
985
1056
|
class DdbVectorInt extends DdbObj {
|
|
986
|
-
constructor(
|
|
1057
|
+
constructor(ints, name) {
|
|
987
1058
|
super({
|
|
988
1059
|
form: DdbForm.vector,
|
|
989
1060
|
type: DdbType.int,
|
|
990
1061
|
length: 0,
|
|
991
|
-
rows:
|
|
1062
|
+
rows: ints.length,
|
|
992
1063
|
cols: 1,
|
|
993
|
-
value: Int32Array
|
|
1064
|
+
value: ints instanceof Int32Array ?
|
|
1065
|
+
ints
|
|
1066
|
+
:
|
|
1067
|
+
Int32Array.from(ints, v => v === null ?
|
|
1068
|
+
exports.nulls.int32
|
|
1069
|
+
:
|
|
1070
|
+
v),
|
|
994
1071
|
name,
|
|
995
1072
|
});
|
|
996
1073
|
}
|
|
997
1074
|
}
|
|
998
1075
|
exports.DdbVectorInt = DdbVectorInt;
|
|
999
1076
|
class DdbVectorString extends DdbObj {
|
|
1000
|
-
constructor(
|
|
1077
|
+
constructor(strings, name) {
|
|
1001
1078
|
super({
|
|
1002
1079
|
form: DdbForm.vector,
|
|
1003
1080
|
type: DdbType.string,
|
|
1004
1081
|
length: 0,
|
|
1005
|
-
rows:
|
|
1082
|
+
rows: strings.length,
|
|
1006
1083
|
cols: 1,
|
|
1007
|
-
value,
|
|
1084
|
+
value: strings,
|
|
1008
1085
|
name,
|
|
1009
1086
|
});
|
|
1010
1087
|
}
|
|
1011
1088
|
}
|
|
1012
1089
|
exports.DdbVectorString = DdbVectorString;
|
|
1013
1090
|
class DdbVectorDouble extends DdbObj {
|
|
1014
|
-
constructor(
|
|
1091
|
+
constructor(doubles, name) {
|
|
1015
1092
|
super({
|
|
1016
1093
|
form: DdbForm.vector,
|
|
1017
1094
|
type: DdbType.double,
|
|
1018
1095
|
length: 0,
|
|
1019
|
-
rows:
|
|
1096
|
+
rows: doubles.length,
|
|
1020
1097
|
cols: 1,
|
|
1021
|
-
value: Float64Array
|
|
1098
|
+
value: doubles instanceof Float64Array ?
|
|
1099
|
+
doubles
|
|
1100
|
+
:
|
|
1101
|
+
Float64Array.from(doubles, v => v === null ?
|
|
1102
|
+
exports.nulls.double
|
|
1103
|
+
:
|
|
1104
|
+
v),
|
|
1022
1105
|
name,
|
|
1023
1106
|
});
|
|
1024
1107
|
}
|
|
1025
1108
|
}
|
|
1026
1109
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
1027
1110
|
class DdbVectorAny extends DdbObj {
|
|
1028
|
-
constructor(
|
|
1111
|
+
constructor(objs, name) {
|
|
1029
1112
|
super({
|
|
1030
1113
|
form: DdbForm.vector,
|
|
1031
1114
|
type: DdbType.any,
|
|
1032
1115
|
length: 0,
|
|
1033
|
-
rows:
|
|
1116
|
+
rows: objs.length,
|
|
1034
1117
|
cols: 1,
|
|
1035
|
-
value,
|
|
1118
|
+
value: objs,
|
|
1036
1119
|
name,
|
|
1037
1120
|
});
|
|
1038
1121
|
}
|
|
1039
1122
|
}
|
|
1040
1123
|
exports.DdbVectorAny = DdbVectorAny;
|
|
1041
|
-
class
|
|
1042
|
-
constructor(
|
|
1124
|
+
class DdbVectorSymbol extends DdbObj {
|
|
1125
|
+
constructor(strings, name) {
|
|
1126
|
+
let map = new Map([
|
|
1127
|
+
['', 0]
|
|
1128
|
+
]);
|
|
1129
|
+
let data = new Uint32Array(strings.length);
|
|
1130
|
+
for (let i = 0; i < strings.length; i++) {
|
|
1131
|
+
const x = strings[i];
|
|
1132
|
+
let index = map.get(x);
|
|
1133
|
+
if (index === undefined) {
|
|
1134
|
+
index = map.size;
|
|
1135
|
+
map.set(x, index);
|
|
1136
|
+
}
|
|
1137
|
+
data[i] = index;
|
|
1138
|
+
}
|
|
1043
1139
|
super({
|
|
1044
|
-
form: DdbForm.
|
|
1045
|
-
type: DdbType.
|
|
1140
|
+
form: DdbForm.vector,
|
|
1141
|
+
type: DdbType.symbol_extended,
|
|
1046
1142
|
length: 0,
|
|
1047
|
-
rows:
|
|
1143
|
+
rows: strings.length,
|
|
1048
1144
|
cols: 1,
|
|
1049
|
-
value:
|
|
1145
|
+
value: {
|
|
1146
|
+
base: [...map.keys()],
|
|
1147
|
+
base_id: null,
|
|
1148
|
+
data,
|
|
1149
|
+
},
|
|
1150
|
+
name
|
|
1050
1151
|
});
|
|
1051
1152
|
}
|
|
1052
1153
|
}
|
|
1053
|
-
exports.
|
|
1054
|
-
class
|
|
1055
|
-
constructor(
|
|
1154
|
+
exports.DdbVectorSymbol = DdbVectorSymbol;
|
|
1155
|
+
class DdbTable extends DdbObj {
|
|
1156
|
+
constructor(columns, name = '') {
|
|
1056
1157
|
super({
|
|
1057
|
-
form: DdbForm.
|
|
1058
|
-
type: DdbType.
|
|
1158
|
+
form: DdbForm.table,
|
|
1159
|
+
type: DdbType.void,
|
|
1059
1160
|
length: 0,
|
|
1060
|
-
|
|
1161
|
+
rows: columns[0].rows,
|
|
1162
|
+
cols: columns.length,
|
|
1163
|
+
name,
|
|
1164
|
+
value: columns,
|
|
1061
1165
|
});
|
|
1062
1166
|
}
|
|
1063
1167
|
}
|
|
1064
|
-
exports.
|
|
1168
|
+
exports.DdbTable = DdbTable;
|
|
1065
1169
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1066
1170
|
return date === exports.nulls.int32 ?
|
|
1067
1171
|
''
|
|
@@ -1187,12 +1291,14 @@ class DDB {
|
|
|
1187
1291
|
/** resolver, rejector, promise of last rpc */
|
|
1188
1292
|
presolver(buf) { }
|
|
1189
1293
|
prejector(error) { }
|
|
1294
|
+
get connected() {
|
|
1295
|
+
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1296
|
+
}
|
|
1190
1297
|
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
|
|
1191
1298
|
async connect({ url = this.url, login = true, username = 'admin', password = '123456', python = false, } = {}) {
|
|
1192
1299
|
this.url = url;
|
|
1193
1300
|
this.python = python;
|
|
1194
|
-
|
|
1195
|
-
this.disconnect();
|
|
1301
|
+
this.disconnect();
|
|
1196
1302
|
let websocket = new WebSocket(url, python ? ['python'] : []);
|
|
1197
1303
|
// https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
|
|
1198
1304
|
websocket.binaryType = 'arraybuffer';
|
|
@@ -1283,7 +1389,11 @@ class DDB {
|
|
|
1283
1389
|
return `/ ${options.join('_')}`;
|
|
1284
1390
|
}
|
|
1285
1391
|
disconnect() {
|
|
1286
|
-
this.
|
|
1392
|
+
if (this.connected)
|
|
1393
|
+
this.websocket.close(1000);
|
|
1394
|
+
this.presolver = buf => { };
|
|
1395
|
+
this.prejector = error => { };
|
|
1396
|
+
this.presult = Promise.resolve(null);
|
|
1287
1397
|
}
|
|
1288
1398
|
/** rpc through websocket (function/script/variable command)
|
|
1289
1399
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
@@ -1294,7 +1404,7 @@ class DDB {
|
|
|
1294
1404
|
async rpc(type, { script, func, args = [], vars = [], urgent, }) {
|
|
1295
1405
|
if (!this.websocket)
|
|
1296
1406
|
await this.connect();
|
|
1297
|
-
if (this.
|
|
1407
|
+
if (!this.connected)
|
|
1298
1408
|
throw new Error(`${this.url} is already disconnected`);
|
|
1299
1409
|
// 临界区:保证多个 rpc 并发时形成 promise 链
|
|
1300
1410
|
// ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
|
|
@@ -1317,7 +1427,7 @@ class DDB {
|
|
|
1317
1427
|
// 临界区结束,只有一个 rpc 请求可以写 WebSocket
|
|
1318
1428
|
if (urgent && type !== 'script' && type !== 'function')
|
|
1319
1429
|
throw new Error('urgent 只适用于 script 和 funciton');
|
|
1320
|
-
this.to_ddbobjs(args);
|
|
1430
|
+
args = this.to_ddbobjs(args);
|
|
1321
1431
|
const command = this.enc.encode((() => {
|
|
1322
1432
|
switch (type) {
|
|
1323
1433
|
case 'function':
|
|
@@ -1459,11 +1569,9 @@ class DDB {
|
|
|
1459
1569
|
throw new Error(`不能自动转换 ${type} 至 DdbObj`);
|
|
1460
1570
|
}
|
|
1461
1571
|
}
|
|
1462
|
-
/** 转换 js 数组为 DdbObj[]
|
|
1572
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
1463
1573
|
to_ddbobjs(values) {
|
|
1464
|
-
|
|
1465
|
-
values[i] = this.to_ddbobj(values[i]);
|
|
1466
|
-
return values;
|
|
1574
|
+
return values.map(value => this.to_ddbobj(value));
|
|
1467
1575
|
}
|
|
1468
1576
|
}
|
|
1469
1577
|
exports.DDB = DDB;
|