@yydb/yyds 0.0.0-stage → 0.0.0
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/package.json +61 -4
- package/readme.md +13 -0
- package/src/bindings.ts +5 -0
- package/src/browser/index.ts +7 -0
- package/src/node/cluster.ts +56 -0
- package/src/node/index.ts +20 -0
- package/src/node/load.ts +50 -0
- package/src/node/platform-packages.ts +15 -0
- package/src/node/sqlite-bindings.ts +64 -0
- package/src/node/unsupported.ts +1 -0
- package/src/wasm/index.ts +8 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
|
+
"bugs": {
|
|
3
|
+
"url": "https://github.com/yy-database/yyds/issues"
|
|
4
|
+
},
|
|
5
|
+
"description": "YYDS scripting runtime for TypeScript and Node.js",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@types/node": "^22.15.0",
|
|
8
|
+
"typescript": "^5.9.2"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"default": "./src/node/unsupported.ts",
|
|
16
|
+
"node": "./src/node/index.ts",
|
|
17
|
+
"types": "./src/node/index.ts"
|
|
18
|
+
},
|
|
19
|
+
"./node": {
|
|
20
|
+
"default": "./src/node/unsupported.ts",
|
|
21
|
+
"node": "./src/node/index.ts",
|
|
22
|
+
"types": "./src/node/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"./node/cluster": {
|
|
25
|
+
"default": "./src/node/unsupported.ts",
|
|
26
|
+
"node": "./src/node/cluster.ts",
|
|
27
|
+
"types": "./src/node/cluster.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"homepage": "https://github.com/yy-database/yyds/tree/dev/projects/packages/yyds#readme",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"yyds",
|
|
36
|
+
"scripting",
|
|
37
|
+
"typescript",
|
|
38
|
+
"napi"
|
|
39
|
+
],
|
|
40
|
+
"license": "MPL-2.0",
|
|
2
41
|
"name": "@yydb/yyds",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
42
|
+
"optionalDependencies": {
|
|
43
|
+
"@yydb/yyds-darwin-arm64": "0.0.0",
|
|
44
|
+
"@yydb/yyds-darwin-x64": "0.0.0",
|
|
45
|
+
"@yydb/yyds-linux-x64": "0.0.0",
|
|
46
|
+
"@yydb/yyds-win32-x64": "0.0.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"directory": "projects/packages/yyds",
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/yy-database/yyds.git"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "node --experimental-strip-types --test \"./tests/**/*.test.ts\"",
|
|
58
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"type": "module",
|
|
62
|
+
"version": "0.0.0"
|
|
63
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @yyds/yyds
|
|
2
|
+
|
|
3
|
+
TypeScript facade for the YYDS scripting runtime.
|
|
4
|
+
|
|
5
|
+
- Browser / Worker: default export (`@yyds/yyds`) or `@yyds/yyds/wasm`
|
|
6
|
+
- Node.js: `@yyds/yyds/node`
|
|
7
|
+
|
|
8
|
+
Build native and WASM artifacts from the repo root:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm build:napi
|
|
12
|
+
pnpm build:wasm
|
|
13
|
+
```
|
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@yydb/yyds` default export — browser / Worker facade (WASM inside).
|
|
3
|
+
*
|
|
4
|
+
* Node apps use `@yydb/yyds/node`. Low-level WASM loader: `@yydb/yyds/wasm`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { initWasm, ping, yydsVersion, type InitWasmOptions, type WasmInitInput } from "../wasm/index.ts";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export type YydsProtocol = "redis" | "mysql" | "postgresql";
|
|
4
|
+
|
|
5
|
+
const portFlags: Record<YydsProtocol, string> = {
|
|
6
|
+
redis: "--redis-port",
|
|
7
|
+
mysql: "--mysql-port",
|
|
8
|
+
postgresql: "--pgsql-port",
|
|
9
|
+
};
|
|
10
|
+
const defaultPorts: Partial<Record<YydsProtocol, number>> = { mysql: 3306, postgresql: 5432 };
|
|
11
|
+
|
|
12
|
+
export function yydsStartArguments(protocol: YydsProtocol, args: string[]): string[] {
|
|
13
|
+
const result = ["start"];
|
|
14
|
+
let protocolPortProvided = false;
|
|
15
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
16
|
+
const argument = args[index];
|
|
17
|
+
if (["--port", "-p", "-P"].includes(argument)) {
|
|
18
|
+
const value = args[++index];
|
|
19
|
+
if (value === undefined || value.startsWith("-"))
|
|
20
|
+
throw new Error(`missing port after ${argument}`);
|
|
21
|
+
result.push(portFlags[protocol], value);
|
|
22
|
+
protocolPortProvided = true;
|
|
23
|
+
} else {
|
|
24
|
+
result.push(argument);
|
|
25
|
+
if (argument === portFlags[protocol]) protocolPortProvided = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const defaultPort = defaultPorts[protocol];
|
|
29
|
+
if (!protocolPortProvided && defaultPort !== undefined)
|
|
30
|
+
result.push(portFlags[protocol], String(defaultPort));
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function launchYydsServer(protocol: YydsProtocol, args: string[]): Promise<number> {
|
|
35
|
+
const executable = process.env.YYDS_CLI_PATH || "yyds";
|
|
36
|
+
const child = spawn(executable, yydsStartArguments(protocol, args), {
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
windowsHide: true,
|
|
39
|
+
});
|
|
40
|
+
const forward = (signal: NodeJS.Signals) => child.kill(signal);
|
|
41
|
+
const onInterrupt = () => forward("SIGINT");
|
|
42
|
+
const onTerminate = () => forward("SIGTERM");
|
|
43
|
+
process.once("SIGINT", onInterrupt);
|
|
44
|
+
process.once("SIGTERM", onTerminate);
|
|
45
|
+
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
child.once("error", (error) =>
|
|
48
|
+
reject(new Error(`cannot start '${executable}': ${error.message}`)),
|
|
49
|
+
);
|
|
50
|
+
child.once("close", (code, signal) => {
|
|
51
|
+
process.removeListener("SIGINT", onInterrupt);
|
|
52
|
+
process.removeListener("SIGTERM", onTerminate);
|
|
53
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@yydb/yyds/node` — Node N-API facade.
|
|
3
|
+
*
|
|
4
|
+
* Browser code must use the default `@yydb/yyds` entry or `@yydb/yyds/wasm`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type { YydsBindings } from "../bindings.ts";
|
|
8
|
+
export type { YydsProtocol } from "./cluster.ts";
|
|
9
|
+
export { launchYydsServer, yydsStartArguments } from "./cluster.ts";
|
|
10
|
+
export { isYydsNativeInstalled, loadYydsNative, loadYydsSqliteNative } from "./load.ts";
|
|
11
|
+
export type {
|
|
12
|
+
SqliteConnectionBinding,
|
|
13
|
+
SqliteQueryResultBinding,
|
|
14
|
+
SqliteReadLimits,
|
|
15
|
+
SqliteResultValueBinding,
|
|
16
|
+
SqliteSchemaObject,
|
|
17
|
+
SqliteSnapshotBinding,
|
|
18
|
+
SqliteTableRow,
|
|
19
|
+
YydsSqliteBindings,
|
|
20
|
+
} from "./sqlite-bindings.ts";
|
package/src/node/load.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
import type { YydsBindings } from "../bindings.ts";
|
|
4
|
+
import { resolvePlatformPackage } from "./platform-packages.ts";
|
|
5
|
+
import type { YydsSqliteBindings } from "./sqlite-bindings.ts";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
function normalizeBinding(module: Record<string, unknown>): YydsBindings {
|
|
10
|
+
const binding = (module.default ?? module) as Record<string, unknown>;
|
|
11
|
+
return {
|
|
12
|
+
yydsVersion: () => String((binding.yydsVersion as () => string)()),
|
|
13
|
+
ping: () => String((binding.ping as () => string)()),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Load the platform-specific Node-API binding. */
|
|
18
|
+
export function loadYydsNative(): YydsBindings {
|
|
19
|
+
const specifier = resolvePlatformPackage();
|
|
20
|
+
return normalizeBinding(require(specifier) as Record<string, unknown>);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Load the independent SQLite snapshot reader, not a YYDS execution session. */
|
|
24
|
+
export function loadYydsSqliteNative(): YydsSqliteBindings {
|
|
25
|
+
const module = require(resolvePlatformPackage()) as Record<string, unknown>;
|
|
26
|
+
const binding = (module.default ?? module) as Record<string, unknown>;
|
|
27
|
+
if (
|
|
28
|
+
typeof binding.SqliteSnapshot !== "function" ||
|
|
29
|
+
typeof binding.SqliteConnection !== "function"
|
|
30
|
+
) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"Native addon lacks the SQLite snapshot reader. Rebuild the native package.",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
SqliteSnapshot: binding.SqliteSnapshot as YydsSqliteBindings["SqliteSnapshot"],
|
|
37
|
+
SqliteConnection: binding.SqliteConnection as YydsSqliteBindings["SqliteConnection"],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Whether the current platform optional dependency is installed. */
|
|
42
|
+
export function isYydsNativeInstalled(): boolean {
|
|
43
|
+
try {
|
|
44
|
+
resolvePlatformPackage();
|
|
45
|
+
require.resolve(resolvePlatformPackage());
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const PLATFORM_PACKAGES: Record<string, string> = {
|
|
2
|
+
"win32-x64": "@yydb/yyds-win32-x64",
|
|
3
|
+
"darwin-x64": "@yydb/yyds-darwin-x64",
|
|
4
|
+
"darwin-arm64": "@yydb/yyds-darwin-arm64",
|
|
5
|
+
"linux-x64": "@yydb/yyds-linux-x64",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function resolvePlatformPackage(): string {
|
|
9
|
+
const key = `${process.platform}-${process.arch}`;
|
|
10
|
+
const specifier = PLATFORM_PACKAGES[key];
|
|
11
|
+
if (!specifier) {
|
|
12
|
+
throw new Error(`@yydb/yyds/node: unsupported platform ${key}`);
|
|
13
|
+
}
|
|
14
|
+
return specifier;
|
|
15
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
export interface SqliteSnapshotBinding {
|
|
25
|
+
schema(limits?: SqliteReadLimits): SqliteSchemaObject[];
|
|
26
|
+
table(name: string, limits?: SqliteReadLimits): SqliteTableRow[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** An independent SQLite reader hosted in the same native addon. */
|
|
30
|
+
export interface YydsSqliteBindings {
|
|
31
|
+
SqliteSnapshot: new (bytes: Buffer, maxSnapshotBytes?: number) => SqliteSnapshotBinding;
|
|
32
|
+
SqliteConnection: new (path: string, readOnly?: boolean) => SqliteConnectionBinding;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SqliteConnectionBinding {
|
|
36
|
+
execute(sql: string): SqliteQueryResultBinding;
|
|
37
|
+
executeWithParameters(sql: string, parameters: SqliteParameterBinding[]): SqliteQueryResultBinding;
|
|
38
|
+
executeBatch(sql: string): void;
|
|
39
|
+
sourceId(): string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SqliteParameterBinding {
|
|
43
|
+
kind: "null" | "integer" | "real" | "text" | "blob";
|
|
44
|
+
integer?: string;
|
|
45
|
+
real?: number;
|
|
46
|
+
text?: Buffer;
|
|
47
|
+
blob?: Buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SqliteQueryResultBinding {
|
|
51
|
+
columns: string[];
|
|
52
|
+
rows: SqliteResultValueBinding[][];
|
|
53
|
+
changes: string;
|
|
54
|
+
lastInsertRowid: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SqliteResultValueBinding {
|
|
58
|
+
kind: "null" | "integer" | "real" | "text" | "blob";
|
|
59
|
+
integer?: string;
|
|
60
|
+
real?: number;
|
|
61
|
+
text?: string;
|
|
62
|
+
textBytes?: Buffer;
|
|
63
|
+
blob?: Buffer;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error("@yydb/yyds/node is only available in Node.js runtimes");
|
package/README.md
DELETED