@yydb/yyds 0.0.13 → 0.0.14

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/bin/yyds.mjs CHANGED
@@ -3,11 +3,20 @@ import { loadYydsNative } from "../src/node/load.ts";
3
3
  import { parseStartOptions, runNodeStart } from "../src/node/runtime.ts";
4
4
 
5
5
  function usage() {
6
- return "usage: yyds <init|start|status|stop> --data-dir DIR [--cluster-id ID --node-id ID] [--redis-port PORT] [--pgsql-port PORT] [--mysql-port PORT] [--wire-port PORT]";
6
+ return "usage: yyds <init|start|status|stop> --data-dir DIR [--cluster-id ID --node-id ID] [--redis-port PORT] [--pgsql-port PORT] [--mysql-port PORT] [--mongo-port PORT] [--wire-port PORT]";
7
7
  }
8
8
 
9
9
  function parseCommonArgs(command, args) {
10
- const options = { dataDir: "", clusterId: "", nodeId: "", redisPort: 6379, pgsqlPort: undefined, mysqlPort: undefined, wirePort: undefined };
10
+ const options = {
11
+ dataDir: "",
12
+ clusterId: "",
13
+ nodeId: "",
14
+ redisPort: 6379,
15
+ pgsqlPort: undefined,
16
+ mysqlPort: undefined,
17
+ mongoPort: undefined,
18
+ wirePort: undefined,
19
+ };
11
20
  for (let index = 0; index < args.length; index += 1) {
12
21
  const flag = args[index];
13
22
  const value = args[index + 1];
@@ -26,22 +35,32 @@ function parseCommonArgs(command, args) {
26
35
  index += 1;
27
36
  break;
28
37
  case "--redis-port":
29
- if (command !== "start") throw new Error(`option ${flag} is not valid for this command`);
38
+ if (command !== "start")
39
+ throw new Error(`option ${flag} is not valid for this command`);
30
40
  options.redisPort = Number(value);
31
41
  index += 1;
32
42
  break;
33
43
  case "--pgsql-port":
34
- if (command !== "start") throw new Error(`option ${flag} is not valid for this command`);
44
+ if (command !== "start")
45
+ throw new Error(`option ${flag} is not valid for this command`);
35
46
  options.pgsqlPort = Number(value);
36
47
  index += 1;
37
48
  break;
38
49
  case "--mysql-port":
39
- if (command !== "start") throw new Error(`option ${flag} is not valid for this command`);
50
+ if (command !== "start")
51
+ throw new Error(`option ${flag} is not valid for this command`);
40
52
  options.mysqlPort = Number(value);
41
53
  index += 1;
42
54
  break;
55
+ case "--mongo-port":
56
+ if (command !== "start")
57
+ throw new Error(`option ${flag} is not valid for this command`);
58
+ options.mongoPort = Number(value);
59
+ index += 1;
60
+ break;
43
61
  case "--wire-port":
44
- if (command !== "start") throw new Error(`option ${flag} is not valid for this command`);
62
+ if (command !== "start")
63
+ throw new Error(`option ${flag} is not valid for this command`);
45
64
  options.wirePort = Number(value);
46
65
  index += 1;
47
66
  break;
@@ -77,18 +96,21 @@ async function main(args) {
77
96
  redisPort: options.redisPort,
78
97
  pgsqlPort: options.pgsqlPort,
79
98
  mysqlPort: options.mysqlPort,
99
+ mongoPort: options.mongoPort,
80
100
  wirePort: options.wirePort,
81
101
  });
82
102
  return;
83
103
  case "status": {
84
104
  const snapshot = native.nodeInspect(options.dataDir);
85
- console.log(JSON.stringify({
86
- directory: snapshot.directory,
87
- identity: JSON.parse(snapshot.identity),
88
- ownership: snapshot.ownership,
89
- runtime: snapshot.runtime ? JSON.parse(snapshot.runtime) : null,
90
- health: snapshot.health,
91
- }));
105
+ console.log(
106
+ JSON.stringify({
107
+ directory: snapshot.directory,
108
+ identity: JSON.parse(snapshot.identity),
109
+ ownership: snapshot.ownership,
110
+ runtime: snapshot.runtime ? JSON.parse(snapshot.runtime) : null,
111
+ health: snapshot.health,
112
+ }),
113
+ );
92
114
  return;
93
115
  }
94
116
  case "stop": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yydb/yyds",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Node.js facade, CLI, and native bindings for local YYDS nodes.",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",
@@ -41,9 +41,9 @@
41
41
  "repository": {
42
42
  "type": "git",
43
43
  "url": "git+https://github.com/yy-database/yyds.git",
44
- "directory": "projects/packages/yyds"
44
+ "directory": "projects/yyds.ts/packages/yyds"
45
45
  },
46
- "homepage": "https://github.com/yy-database/yyds/tree/dev/projects/packages/yyds#readme",
46
+ "homepage": "https://github.com/yy-database/yyds/tree/dev/projects/yyds.ts/packages/yyds#readme",
47
47
  "bugs": {
48
48
  "url": "https://github.com/yy-database/yyds/issues"
49
49
  },
@@ -57,10 +57,10 @@
57
57
  "access": "public"
58
58
  },
59
59
  "optionalDependencies": {
60
- "@yydb/yyds-win32-x64": "0.0.13",
61
- "@yydb/yyds-linux-x64": "0.0.13",
62
- "@yydb/yyds-darwin-x64": "0.0.13",
63
- "@yydb/yyds-darwin-arm64": "0.0.13"
60
+ "@yydb/yyds-win32-x64": "0.0.14",
61
+ "@yydb/yyds-linux-x64": "0.0.14",
62
+ "@yydb/yyds-darwin-x64": "0.0.14",
63
+ "@yydb/yyds-darwin-arm64": "0.0.14"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "^22.15.0",
package/readme.md CHANGED
@@ -34,6 +34,6 @@ yyds stop --data-dir ./node-data
34
34
 
35
35
  ## Related packages
36
36
 
37
- - [`@yydb/redis`](https://github.com/yy-database/yyds/tree/dev/projects/packages/redis) — Redis protocol disguise
38
- - [`@yydb/mysql`](https://github.com/yy-database/yyds/tree/dev/projects/packages/mysql) — MySQL protocol disguise
39
- - [`@yydb/postgresql`](https://github.com/yy-database/yyds/tree/dev/projects/packages/postgresql) — PostgreSQL protocol disguise
37
+ - [`@yydb/redis`](https://github.com/yy-database/yyds/tree/dev/projects/yyds.ts/packages/redis) �?Redis protocol disguise
38
+ - [`@yydb/mysql`](https://github.com/yy-database/yyds/tree/dev/projects/yyds.ts/packages/mysql) �?MySQL protocol disguise
39
+ - [`@yydb/postgresql`](https://github.com/yy-database/yyds/tree/dev/projects/yyds.ts/packages/postgresql) �?PostgreSQL protocol disguise
package/src/bindings.ts CHANGED
@@ -7,9 +7,18 @@ export interface YydsBindings {
7
7
  acquire(dataDir: string, identity: unknown): unknown;
8
8
  };
9
9
  LocalExecutorHandle: new (dataDir: string) => unknown;
10
- RedisServiceHandle: new (lease: unknown, port: number, executor: unknown) => RedisServiceBinding;
10
+ RedisServiceHandle: new (
11
+ lease: unknown,
12
+ port: number,
13
+ executor: unknown,
14
+ ) => RedisServiceBinding;
11
15
  PgsqlServiceHandle: new (lease: unknown, port: number) => PgsqlServiceBinding;
12
16
  MysqlServiceHandle: new (lease: unknown, port: number) => MysqlServiceBinding;
17
+ MongoServiceHandle: new (
18
+ lease: unknown,
19
+ port: number,
20
+ executor: unknown,
21
+ ) => MongoServiceBinding;
13
22
  WireServerHandle: new (port: number, executor: unknown) => WireServiceBinding;
14
23
  nodeInit(dataDir: string, identity: unknown): void;
15
24
  nodeInspect(dataDir: string): NodeStatusBinding;
@@ -30,6 +39,7 @@ export interface ServiceBinding {
30
39
  export type RedisServiceBinding = ServiceBinding;
31
40
  export type PgsqlServiceBinding = ServiceBinding;
32
41
  export type MysqlServiceBinding = ServiceBinding;
42
+ export type MongoServiceBinding = ServiceBinding;
33
43
  export type WireServiceBinding = ServiceBinding;
34
44
 
35
45
  export interface NodeStatusBinding {
@@ -12,6 +12,7 @@ export interface StartNodeOptions {
12
12
  redisPort?: number;
13
13
  pgsqlPort?: number;
14
14
  mysqlPort?: number;
15
+ mongoPort?: number;
15
16
  wirePort?: number;
16
17
  }
17
18
 
@@ -33,7 +34,8 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
33
34
  const argument = args[index];
34
35
  if (["--port", "-p", "-P"].includes(argument)) {
35
36
  const value = Number(args[++index]);
36
- if (!Number.isInteger(value) || value < 0) throw new Error(`missing port after ${argument}`);
37
+ if (!Number.isInteger(value) || value < 0)
38
+ throw new Error(`missing port after ${argument}`);
37
39
  if (protocol === "redis") options.redisPort = value;
38
40
  if (protocol === "mysql") options.mysqlPort = value;
39
41
  if (protocol === "postgresql") options.pgsqlPort = value;
@@ -63,6 +65,10 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
63
65
  options.mysqlPort = Number(args[++index]);
64
66
  continue;
65
67
  }
68
+ if (argument === "--mongo-port") {
69
+ options.mongoPort = Number(args[++index]);
70
+ continue;
71
+ }
66
72
  if (argument === "--wire-port") {
67
73
  options.wirePort = Number(args[++index]);
68
74
  continue;
@@ -89,10 +95,27 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
89
95
  const identity = new native.NodeIdentityHandle(options.clusterId, options.nodeId);
90
96
  const lease = native.NodeLeaseHandle.acquire(options.dataDir, identity);
91
97
  const executor = new native.LocalExecutorHandle(options.dataDir);
92
- const redis = new native.RedisServiceHandle(lease, options.redisPort ?? DEFAULT_REDIS_PORT, executor);
93
- const pgsql = options.pgsqlPort === undefined ? undefined : new native.PgsqlServiceHandle(lease, options.pgsqlPort);
94
- const mysql = options.mysqlPort === undefined ? undefined : new native.MysqlServiceHandle(lease, options.mysqlPort);
95
- const wire = options.wirePort === undefined ? undefined : new native.WireServerHandle(options.wirePort, executor);
98
+ const redis = new native.RedisServiceHandle(
99
+ lease,
100
+ options.redisPort ?? DEFAULT_REDIS_PORT,
101
+ executor,
102
+ );
103
+ const pgsql =
104
+ options.pgsqlPort === undefined
105
+ ? undefined
106
+ : new native.PgsqlServiceHandle(lease, options.pgsqlPort);
107
+ const mysql =
108
+ options.mysqlPort === undefined
109
+ ? undefined
110
+ : new native.MysqlServiceHandle(lease, options.mysqlPort);
111
+ const mongo =
112
+ options.mongoPort === undefined
113
+ ? undefined
114
+ : new native.MongoServiceHandle(lease, options.mongoPort, executor);
115
+ const wire =
116
+ options.wirePort === undefined
117
+ ? undefined
118
+ : new native.WireServerHandle(options.wirePort, executor);
96
119
 
97
120
  const runtime = {
98
121
  version: 1,
@@ -107,7 +130,7 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
107
130
  native.nodeWriteRuntimeStatus(options.dataDir, JSON.stringify(runtime));
108
131
 
109
132
  process.stdout.write(
110
- `yyds running pid=${runtime.pid} redis=${runtime.redisAddress} pgsql=${runtime.pgsqlAddress ?? "null"} mysql=${runtime.mysqlAddress ?? "null"} wire=${runtime.wireAddress ?? "null"}\n`,
133
+ `yyds running pid=${runtime.pid} redis=${runtime.redisAddress} pgsql=${runtime.pgsqlAddress ?? "null"} mysql=${runtime.mysqlAddress ?? "null"} mongo=${mongo?.address() ?? "null"} wire=${runtime.wireAddress ?? "null"}\n`,
111
134
  );
112
135
 
113
136
  while (true) {
@@ -115,6 +138,7 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
115
138
  if (redis.isFinished()) break;
116
139
  if (pgsql?.isFinished()) break;
117
140
  if (mysql?.isFinished()) break;
141
+ if (mongo?.isFinished()) break;
118
142
  if (wire?.isFinished()) break;
119
143
  await sleep(50);
120
144
  }
@@ -122,6 +146,7 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
122
146
  redis.stop();
123
147
  pgsql?.stop();
124
148
  mysql?.stop();
149
+ mongo?.stop();
125
150
  wire?.stop();
126
151
  native.nodeClearRuntimeArtifacts(options.dataDir, runtime.generation);
127
152
  }