dolphindb 2.0.903 → 2.0.904

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/index.d.ts CHANGED
@@ -376,7 +376,7 @@ export declare function timestamp2str(timestamp: bigint | null, format?: string)
376
376
  export declare function datehour2ms(datehour: number | null): number | null;
377
377
  export declare function datehour2str(datehour: number | null, format?: string): string;
378
378
  /** parse timestamp string to bigint value
379
- - str: str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
379
+ - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
380
380
  timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
381
381
  - format?:
382
382
  对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // import { table, getBorderCharacters, type TableUserConfig } from 'table'
1
2
  import { WebSocket } from 'ws';
2
3
  import dayjs from 'dayjs';
3
4
  import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
@@ -1959,7 +1960,7 @@ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1959
1960
  dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1960
1961
  }
1961
1962
  /** parse timestamp string to bigint value
1962
- - str: str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
1963
+ - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
1963
1964
  timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1964
1965
  - format?:
1965
1966
  对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
@@ -2091,6 +2092,11 @@ export class DDB {
2091
2092
  /** utf-8 text decoder */
2092
2093
  dec = new TextDecoder('utf-8');
2093
2094
  enc = new TextEncoder();
2095
+ // port = 8848
2096
+ // /** ddb 连接状态 */
2097
+ // state = '未连接'
2098
+ // socket = null as Socket
2099
+ // clients = new Set<Duplex>()
2094
2100
  /** DolphinDB WebSocket URL
2095
2101
  e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
2096
2102
  */
@@ -2579,4 +2585,157 @@ export class DDB {
2579
2585
  return this.streaming;
2580
2586
  }
2581
2587
  }
2588
+ // const ddb_gateway = {
2589
+ // server: null as SocketServer,
2590
+ // clients: new Set<Socket>(),
2591
+ // port: 8849,
2592
+ // controllers: {
2593
+ // /** alias */
2594
+ // c0: {
2595
+ // hostname: '127.0.0.1',
2596
+ // port: 8850,
2597
+ // },
2598
+ // c1: {
2599
+ // hostname: '127.0.0.1',
2600
+ // port: 8851,
2601
+ // },
2602
+ // c2: {
2603
+ // hostname: '127.0.0.1',
2604
+ // port: 8852,
2605
+ // }
2606
+ // },
2607
+ // master: '',
2608
+ // sids: new Map<string, string>(),
2609
+ // state: 'init',
2610
+ // async start () {
2611
+ // for (const alias in this.controllers) {
2612
+ // this.master = alias
2613
+ // break
2614
+ // }
2615
+ // this.server = create_socket_server(
2616
+ // {
2617
+ // allowHalfOpen: false,
2618
+ // pauseOnConnect: false,
2619
+ // },
2620
+ // this.accept.bind(this)
2621
+ // )
2622
+ // this.server.on('error', error => {
2623
+ // console.log(new Date(), 'gateway 出错:', error)
2624
+ // })
2625
+ // await new Promise<void>(resolve => {
2626
+ // this.server.listen(this.port, resolve)
2627
+ // })
2628
+ // this.auto_switch_master()
2629
+ // console.log(new Date(), 'gateway 成功启动')
2630
+ // },
2631
+ // async stop () {
2632
+ // this.state = 'stopping'
2633
+ // console.log(new Date(), '正在停止 auto_switch_master')
2634
+ // for (const client of this.clients)
2635
+ // client.end()
2636
+ // await new Promise<void>((resolve, reject) => {
2637
+ // this.server.close(error => {
2638
+ // if (error) {
2639
+ // reject(error)
2640
+ // return
2641
+ // }
2642
+ // resolve()
2643
+ // })
2644
+ // })
2645
+ // },
2646
+ // /** 接收到 client tcp 连接 */
2647
+ // async accept (client: Socket) {
2648
+ // this.clients.add(client)
2649
+ // const port = client.remotePort
2650
+ // // ---
2651
+ // console.log(port, new Date(), 'gateway accept client 连接,开始建立管道')
2652
+ // let controller = new Socket({
2653
+ // allowHalfOpen: false,
2654
+ // readable: true,
2655
+ // writable: true,
2656
+ // })
2657
+ // controller.on('lookup', (error, address, family, host) => {
2658
+ // console.log(port, new Date(), 'controller 域名解析 (lookup) 完成', error, address, family, host)
2659
+ // })
2660
+ // controller.on('close', has_error => {
2661
+ // console.log(port, new Date(), 'controller 关闭连接,是否出错:', has_error)
2662
+ // })
2663
+ // controller.on('timeout', () => {
2664
+ // console.log(port, new Date(), 'controller 超时')
2665
+ // })
2666
+ // controller.on('error', error => {
2667
+ // console.log(port, new Date(), 'controller 出错了:', error)
2668
+ // client.end()
2669
+ // })
2670
+ // // --- client 错误处理
2671
+ // client.on('error', error => {
2672
+ // console.log(port, new Date(), 'client 出错,关闭与 controller 的连接', error)
2673
+ // controller.end()
2674
+ // })
2675
+ // client.on('close', has_error => {
2676
+ // this.clients.delete(client)
2677
+ // console.log(port, new Date(), 'client 关闭连接,是否出错:', has_error)
2678
+ // })
2679
+ // // ---
2680
+ // console.log(port, new Date(), 'gateway 开始连接到 controller')
2681
+ // const { hostname, port: master_port } = this.controllers[this.master]
2682
+ // await new Promise<void>(resolve => {
2683
+ // // callback 会被 socket.once('connect', callback)
2684
+ // controller.connect({
2685
+ // port: master_port,
2686
+ // host: hostname,
2687
+ // // host: '127.0.0.1',
2688
+ // family: 0,
2689
+ // }, resolve)
2690
+ // })
2691
+ // console.log(port, new Date(), 'gateway 已连接到 controller')
2692
+ // // ---
2693
+ // console.log(port, new Date(), 'gateway 建立 client <-> controller')
2694
+ // client.pipe(controller)
2695
+ // controller.pipe(client)
2696
+ // },
2697
+ // /** https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/g/getActiveMaster.html?highlight=getactivemaster */
2698
+ // async get_active_master () {
2699
+ // for (const alias in this.controllers) {
2700
+ // const { hostname, port } = this.controllers[alias] as { hostname: string, port: number }
2701
+ // const sid = this.sids.get(alias)
2702
+ // try {
2703
+ // const master = (
2704
+ // await ddb.rpc_json('getActiveMaster()', { hostname, port, sid })
2705
+ // ).value as string
2706
+ // console.log(new Date(), `${alias}.getActiveMaster() -> ${this.master}`)
2707
+ // this.sids.set(alias, sid)
2708
+ // if (!master)
2709
+ // throw new Error(`${new Date().toString()} getActiveMaster 得到的 master 为空`)
2710
+ // return master
2711
+ // } catch (error) {
2712
+ // console.log(new Date(), error)
2713
+ // }
2714
+ // }
2715
+ // return this.master
2716
+ // },
2717
+ // async auto_switch_master () {
2718
+ // if (this.state === 'stopping') {
2719
+ // this.state = 'running'
2720
+ // console.log('gateway 恢复 auto_switch_master')
2721
+ // return
2722
+ // }
2723
+ // this.state = 'running'
2724
+ // for (; this.state === 'running'; ) {
2725
+ // const master = this.master
2726
+ // const master_ = await this.get_active_master()
2727
+ // if (master === master_) {
2728
+ // await delay(10 * 1000)
2729
+ // continue
2730
+ // }
2731
+ // this.master = master_
2732
+ // console.log(new Date(), `master 从 ${master} 切换为 ${master_}, 断开所有 clients`)
2733
+ // for (const client of this.clients)
2734
+ // client.end()
2735
+ // await delay(3 * 1000)
2736
+ // }
2737
+ // console.log(new Date(), `gateway.state === ${this.state}, 停止 auto_switch_master`)
2738
+ // this.state = 'stopped'
2739
+ // }
2740
+ // }
2582
2741
  //# sourceMappingURL=index.js.map