@yydb/yyds 0.0.12 → 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 +35 -13
- package/package.json +8 -8
- package/readme.md +3 -3
- package/src/bindings.ts +11 -1
- package/src/node/index.ts +1 -11
- package/src/node/load.ts +0 -20
- package/src/node/runtime.ts +31 -6
- package/src/node/sqlite-bindings.ts +0 -70
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 = {
|
|
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")
|
|
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")
|
|
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")
|
|
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")
|
|
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(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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.
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
31
|
-
"yyds": "
|
|
31
|
+
"yyds": "bin/yyds.mjs"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"bin",
|
|
@@ -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.
|
|
61
|
-
"@yydb/yyds-linux-x64": "0.0.
|
|
62
|
-
"@yydb/yyds-darwin-x64": "0.0.
|
|
63
|
-
"@yydb/yyds-darwin-arm64": "0.0.
|
|
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)
|
|
38
|
-
- [`@yydb/mysql`](https://github.com/yy-database/yyds/tree/dev/projects/packages/mysql)
|
|
39
|
-
- [`@yydb/postgresql`](https://github.com/yy-database/yyds/tree/dev/projects/packages/postgresql)
|
|
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 (
|
|
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 {
|
package/src/node/index.ts
CHANGED
|
@@ -7,16 +7,6 @@
|
|
|
7
7
|
export type { YydsBindings, NodeStatusBinding, ServiceBinding } from "../bindings.ts";
|
|
8
8
|
export type { YydsProtocol } from "./cluster.ts";
|
|
9
9
|
export { launchYydsServer, yydsStartArguments } from "./cluster.ts";
|
|
10
|
-
export { isYydsNativeInstalled, loadYydsNative
|
|
10
|
+
export { isYydsNativeInstalled, loadYydsNative } from "./load.ts";
|
|
11
11
|
export type { StartNodeOptions } from "./runtime.ts";
|
|
12
12
|
export { parseStartOptions, runNodeStart } from "./runtime.ts";
|
|
13
|
-
export type {
|
|
14
|
-
SqliteDatabaseBinding,
|
|
15
|
-
SqliteDecodedRow,
|
|
16
|
-
SqliteReadLimits,
|
|
17
|
-
SqliteRecordValue,
|
|
18
|
-
SqliteSchemaObject,
|
|
19
|
-
SqliteSnapshotBinding,
|
|
20
|
-
SqliteTableRow,
|
|
21
|
-
YydsSqliteBindings,
|
|
22
|
-
} from "./sqlite-bindings.ts";
|
package/src/node/load.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
|
|
3
3
|
import type { YydsBindings } from "../bindings.ts";
|
|
4
4
|
import { resolvePlatformPackage } from "./platform-packages.ts";
|
|
5
|
-
import type { YydsSqliteBindings } from "./sqlite-bindings.ts";
|
|
6
5
|
|
|
7
6
|
const require = createRequire(import.meta.url);
|
|
8
7
|
|
|
@@ -17,25 +16,6 @@ export function loadYydsNative(): YydsBindings {
|
|
|
17
16
|
return binding as unknown as YydsBindings;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
/** Load the independent SQLite snapshot reader, not a YYDS execution session. */
|
|
21
|
-
export function loadYydsSqliteNative(): YydsSqliteBindings {
|
|
22
|
-
const binding = bindingModule();
|
|
23
|
-
if (typeof binding.SqliteSnapshot !== "function") {
|
|
24
|
-
throw new Error("Native addon lacks the SQLite snapshot reader. Rebuild the native package.");
|
|
25
|
-
}
|
|
26
|
-
if (typeof binding.SqliteDatabase !== "function") {
|
|
27
|
-
throw new Error("Native addon lacks the SqliteDatabase class. Rebuild the native package.");
|
|
28
|
-
}
|
|
29
|
-
if (typeof binding.decodeRecord !== "function") {
|
|
30
|
-
throw new Error("Native addon lacks decodeRecord. Rebuild the native package.");
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
SqliteSnapshot: binding.SqliteSnapshot as YydsSqliteBindings["SqliteSnapshot"],
|
|
34
|
-
SqliteDatabase: binding.SqliteDatabase as unknown as YydsSqliteBindings["SqliteDatabase"],
|
|
35
|
-
decodeRecord: binding.decodeRecord as YydsSqliteBindings["decodeRecord"],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
19
|
/** Whether the current platform optional dependency is installed. */
|
|
40
20
|
export function isYydsNativeInstalled(): boolean {
|
|
41
21
|
try {
|
package/src/node/runtime.ts
CHANGED
|
@@ -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)
|
|
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(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/** Bounds apply independently to each schema or table scan. */
|
|
2
|
-
export interface SqliteReadLimits {
|
|
3
|
-
maxPages?: number;
|
|
4
|
-
maxRows?: number;
|
|
5
|
-
maxPayloadBytes?: number;
|
|
6
|
-
maxTotalPayloadBytes?: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** SQL source is opaque. No CREATE statement is parsed or executed. */
|
|
10
|
-
export interface SqliteSchemaObject {
|
|
11
|
-
kind: "table" | "index" | "view" | "trigger";
|
|
12
|
-
name: string;
|
|
13
|
-
tableName: string;
|
|
14
|
-
rootPage?: number;
|
|
15
|
-
sql?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Raw storage values, not SQL results or INTEGER PRIMARY KEY expansion. */
|
|
19
|
-
export interface SqliteTableRow {
|
|
20
|
-
rowid: bigint;
|
|
21
|
-
payload: Buffer;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** One decoded SQLite storage-class field. Exactly one `value*` is populated. */
|
|
25
|
-
export interface SqliteRecordValue {
|
|
26
|
-
kind: "null" | "integer" | "real" | "text" | "blob";
|
|
27
|
-
valueInteger?: bigint;
|
|
28
|
-
valueReal?: number;
|
|
29
|
-
valueText?: string;
|
|
30
|
-
valueBlob?: Buffer;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** A decoded SQLite row with storage-class typed columns. */
|
|
34
|
-
export interface SqliteDecodedRow {
|
|
35
|
-
rowid: bigint;
|
|
36
|
-
columns: SqliteRecordValue[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Binding surface for SqliteSnapshot (read-only main-file buffer). */
|
|
40
|
-
export interface SqliteSnapshotBinding {
|
|
41
|
-
schema(limits?: SqliteReadLimits): SqliteSchemaObject[];
|
|
42
|
-
table(name: string, limits?: SqliteReadLimits): SqliteTableRow[];
|
|
43
|
-
tableDecoded(name: string, limits?: SqliteReadLimits): SqliteDecodedRow[];
|
|
44
|
-
sqliteVersion(): string;
|
|
45
|
-
encoding(): string;
|
|
46
|
-
ping(): number;
|
|
47
|
-
pages(): Buffer;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Binding surface for SqliteDatabase (file-backed or in-memory handle). */
|
|
51
|
-
export interface SqliteDatabaseBinding {
|
|
52
|
-
path(): string | null;
|
|
53
|
-
ping(): number;
|
|
54
|
-
sqliteVersion(): string;
|
|
55
|
-
encoding(): string;
|
|
56
|
-
schema(limits?: SqliteReadLimits): SqliteSchemaObject[];
|
|
57
|
-
table(name: string, limits?: SqliteReadLimits): SqliteDecodedRow[];
|
|
58
|
-
tableRaw(name: string, limits?: SqliteReadLimits): SqliteTableRow[];
|
|
59
|
-
pages(): Buffer;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Combined SQLite native addon surface. */
|
|
63
|
-
export interface YydsSqliteBindings {
|
|
64
|
-
SqliteSnapshot: new (bytes: Buffer, maxSnapshotBytes?: number) => SqliteSnapshotBinding;
|
|
65
|
-
SqliteDatabase: {
|
|
66
|
-
openInMemory(): SqliteDatabaseBinding;
|
|
67
|
-
open(path: string): SqliteDatabaseBinding;
|
|
68
|
-
};
|
|
69
|
-
decodeRecord(payload: Buffer, encoding?: string): SqliteRecordValue[];
|
|
70
|
-
}
|