@yydb/yydb 0.0.2 → 0.0.3
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/dist/native.js
CHANGED
|
@@ -1,66 +1,32 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function existsFile(filePath) {
|
|
7
|
-
try {
|
|
8
|
-
fs.accessSync(filePath, fs.constants.F_OK);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function loadFromPath(bindingPath) {
|
|
4
|
+
import { platformKey } from './resolve-bin.js';
|
|
5
|
+
function loadModule(specifier) {
|
|
16
6
|
const require = createRequire(import.meta.url);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function monorepoBindingPath(key) {
|
|
20
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
const repoRoot = path.resolve(here, '../../..');
|
|
22
|
-
const profile = process.env.YYDB_NATIVE_PROFILE === 'debug' ? 'debug' : 'release';
|
|
23
|
-
const base = path.join(repoRoot, 'target', profile);
|
|
24
|
-
const candidates = process.platform === 'win32'
|
|
25
|
-
? [path.join(base, 'yydb_napi.dll'), path.join(base, 'yydb_napi.node')]
|
|
26
|
-
: [path.join(base, 'libyydb_napi.so'), path.join(base, 'libyydb_napi.dylib'), path.join(base, 'yydb_napi.node')];
|
|
27
|
-
for (const candidate of candidates) {
|
|
28
|
-
if (existsFile(candidate)) {
|
|
29
|
-
return candidate;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const staged = path.join(repoRoot, 'projects', 'packages', `yydb-${key}`, nativeBindingName(key));
|
|
33
|
-
return existsFile(staged) ? staged : null;
|
|
7
|
+
const loaded = require(specifier);
|
|
8
|
+
return (loaded.default ?? loaded);
|
|
34
9
|
}
|
|
35
10
|
/** Load the platform native binding used by the `yydb` CLI. */
|
|
36
11
|
export function loadNative() {
|
|
37
12
|
const fromEnv = process.env.YYDB_NATIVE?.trim();
|
|
38
13
|
if (fromEnv) {
|
|
39
|
-
|
|
14
|
+
const bindingPath = path.resolve(fromEnv);
|
|
15
|
+
if (!fs.existsSync(bindingPath)) {
|
|
40
16
|
throw new Error(`YYDB_NATIVE points to missing binding: ${fromEnv}`);
|
|
41
17
|
}
|
|
42
|
-
return
|
|
18
|
+
return loadModule(bindingPath);
|
|
43
19
|
}
|
|
44
20
|
const key = platformKey();
|
|
45
|
-
if (key) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
// optionalDependency not installed for this platform
|
|
57
|
-
}
|
|
58
|
-
const local = monorepoBindingPath(key);
|
|
59
|
-
if (local) {
|
|
60
|
-
return loadFromPath(local);
|
|
61
|
-
}
|
|
21
|
+
if (!key) {
|
|
22
|
+
throw new Error(`YYDB native binding not available for ${process.platform}-${process.arch}`);
|
|
23
|
+
}
|
|
24
|
+
const pkg = `@yydb/yydb-${key}`;
|
|
25
|
+
try {
|
|
26
|
+
return loadModule(pkg);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
30
|
+
throw new Error(`YYDB native binding not found. Reinstall @yydb/yydb with optional dependencies, set YYDB_NATIVE, or stage ${pkg}. ${message}`);
|
|
62
31
|
}
|
|
63
|
-
throw new Error('YYDB native binding not found. Install the matching optionalDependency ' +
|
|
64
|
-
`(@yydb/yydb-${key ?? '<platform>'}), set YYDB_NATIVE, or build ` +
|
|
65
|
-
'`cargo build -p yydb-napi --release` in this repo.');
|
|
66
32
|
}
|
package/dist/resolve-bin.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export type PlatformKey = 'win32-x64' | 'linux-x64' | 'darwin-x64' | 'darwin-arm64';
|
|
3
3
|
/** Map Node platform/arch to optionalDependency package suffix. */
|
|
4
4
|
export declare function platformKey(platform?: NodeJS.Platform, arch?: NodeJS.Architecture): PlatformKey | null;
|
|
5
|
-
/** Native binding filename inside each `@yydb/yydb-<platform>` package
|
|
5
|
+
/** Native binding filename inside each `@yydb/yydb-<platform>` package `lib/`. */
|
|
6
6
|
export declare function nativeBindingName(key: PlatformKey): string;
|
|
7
7
|
/**
|
|
8
8
|
* Resolve the TypeScript `yydb` CLI entry script.
|
package/dist/resolve-bin.js
CHANGED
|
@@ -13,9 +13,18 @@ export function platformKey(platform = process.platform, arch = process.arch) {
|
|
|
13
13
|
return 'darwin-arm64';
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
/** Native binding filename inside each `@yydb/yydb-<platform>` package
|
|
16
|
+
/** Native binding filename inside each `@yydb/yydb-<platform>` package `lib/`. */
|
|
17
17
|
export function nativeBindingName(key) {
|
|
18
|
-
|
|
18
|
+
switch (key) {
|
|
19
|
+
case 'win32-x64':
|
|
20
|
+
return 'yydb-win32-x64-msvc.node';
|
|
21
|
+
case 'linux-x64':
|
|
22
|
+
return 'yydb-linux-x64-gnu.node';
|
|
23
|
+
case 'darwin-x64':
|
|
24
|
+
return 'yydb-darwin-x64.node';
|
|
25
|
+
case 'darwin-arm64':
|
|
26
|
+
return 'yydb-darwin-arm64.node';
|
|
27
|
+
}
|
|
19
28
|
}
|
|
20
29
|
function existsFile(filePath) {
|
|
21
30
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yydb/yydb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "YYDB all-in-one for Node: embedded engine, CLI, and local serve",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@vmz/commander": "^0.2.0",
|
|
55
|
-
"@yydb/yydb-client": "0.0.
|
|
55
|
+
"@yydb/yydb-client": "0.0.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/node": "^20.10.0",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"node": ">=18"
|
|
63
63
|
},
|
|
64
64
|
"optionalDependencies": {
|
|
65
|
-
"@yydb/yydb-win32-x64": "0.0.
|
|
66
|
-
"@yydb/yydb-linux-x64": "0.0.
|
|
67
|
-
"@yydb/yydb-darwin-x64": "0.0.
|
|
68
|
-
"@yydb/yydb-darwin-arm64": "0.0.
|
|
65
|
+
"@yydb/yydb-win32-x64": "0.0.3",
|
|
66
|
+
"@yydb/yydb-linux-x64": "0.0.3",
|
|
67
|
+
"@yydb/yydb-darwin-x64": "0.0.3",
|
|
68
|
+
"@yydb/yydb-darwin-arm64": "0.0.3"
|
|
69
69
|
}
|
|
70
70
|
}
|