slatedb-node 0.1.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/LICENSE +7 -0
- package/README.md +128 -0
- package/native.cjs +98 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Gadget Software Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# slatedb-node
|
|
2
|
+
|
|
3
|
+
High-performance Node.js bindings for [SlateDB](https://github.com/slatedb/slatedb) implemented as a native Rust extension using `napi-rs`.
|
|
4
|
+
|
|
5
|
+
- Native extension (no subprocess bridge)
|
|
6
|
+
- Async TypeScript API
|
|
7
|
+
- Supports SlateDB DB/Reader/Snapshot/Transaction/Admin primitives
|
|
8
|
+
- Compiled with `slatedb` feature `all` (object store + compression feature set)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add slatedb-node
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { WriteBatch, open } from "slatedb-node";
|
|
20
|
+
|
|
21
|
+
const db = await open({ path: "example-db", url: "memory:///" });
|
|
22
|
+
|
|
23
|
+
await db.put("user:1", "alice");
|
|
24
|
+
console.log((await db.get("user:1"))?.toString());
|
|
25
|
+
|
|
26
|
+
const batch = new WriteBatch();
|
|
27
|
+
batch.put("user:2", "bob");
|
|
28
|
+
batch.delete("user:1");
|
|
29
|
+
await db.write(batch);
|
|
30
|
+
|
|
31
|
+
const iter = await db.scanPrefix("user:");
|
|
32
|
+
for await (const [key, value] of iter) {
|
|
33
|
+
console.log(key.toString(), value.toString());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await db.close();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Opening Databases
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { open } from "slatedb-node";
|
|
43
|
+
|
|
44
|
+
const db = await open({
|
|
45
|
+
path: "my-db",
|
|
46
|
+
url: "file:///tmp/slatedb-store",
|
|
47
|
+
settingsPath: "./SlateDb.toml", // optional
|
|
48
|
+
settings: {
|
|
49
|
+
flush_interval: "50ms",
|
|
50
|
+
manifest_poll_interval: "1s",
|
|
51
|
+
}, // optional object overrides
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Reader and Admin APIs
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { open, openAdmin, openReader } from "slatedb-node";
|
|
59
|
+
|
|
60
|
+
const db = await open({ path: "my-db", url: "file:///tmp/slatedb-store" });
|
|
61
|
+
const checkpoint = await db.createCheckpoint("durable");
|
|
62
|
+
|
|
63
|
+
const reader = await openReader({
|
|
64
|
+
path: "my-db",
|
|
65
|
+
url: "file:///tmp/slatedb-store",
|
|
66
|
+
checkpointId: checkpoint.id,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const admin = await openAdmin({ path: "my-db", url: "file:///tmp/slatedb-store" });
|
|
70
|
+
console.log(await admin.listCheckpoints());
|
|
71
|
+
|
|
72
|
+
await reader.close();
|
|
73
|
+
await db.close();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Errors
|
|
77
|
+
|
|
78
|
+
Errors are mapped to typed classes:
|
|
79
|
+
|
|
80
|
+
- `TransactionError`
|
|
81
|
+
- `ClosedError`
|
|
82
|
+
- `UnavailableError`
|
|
83
|
+
- `InvalidError`
|
|
84
|
+
- `DataError`
|
|
85
|
+
- `InternalError`
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
Requirements:
|
|
90
|
+
|
|
91
|
+
- Node.js 20+
|
|
92
|
+
- Rust toolchain
|
|
93
|
+
- `pnpm`
|
|
94
|
+
|
|
95
|
+
Commands:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pnpm install
|
|
99
|
+
pnpm run build
|
|
100
|
+
pnpm test
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Prebuilt Binaries
|
|
104
|
+
|
|
105
|
+
The package uses `@napi-rs/cli` optional dependency packages (like `esbuild`/`swc`) so the main package stays small and installs only the binary for the current platform.
|
|
106
|
+
|
|
107
|
+
Generated optional packages:
|
|
108
|
+
|
|
109
|
+
- macOS x64 / arm64
|
|
110
|
+
- Linux x64 / arm64 (gnu + musl)
|
|
111
|
+
- Windows x64 / arm64 (msvc)
|
|
112
|
+
|
|
113
|
+
The generated package names are:
|
|
114
|
+
|
|
115
|
+
- `slatedb-node-darwin-x64`
|
|
116
|
+
- `slatedb-node-darwin-arm64`
|
|
117
|
+
- `slatedb-node-linux-x64-gnu`
|
|
118
|
+
- `slatedb-node-linux-x64-musl`
|
|
119
|
+
- `slatedb-node-linux-arm64-gnu`
|
|
120
|
+
- `slatedb-node-linux-arm64-musl`
|
|
121
|
+
- `slatedb-node-win32-x64-msvc`
|
|
122
|
+
- `slatedb-node-win32-arm64-msvc`
|
|
123
|
+
|
|
124
|
+
## Publishing
|
|
125
|
+
|
|
126
|
+
`publish.yml` builds all native targets, downloads artifacts, creates per-platform npm package dirs, and runs `npm publish`.
|
|
127
|
+
|
|
128
|
+
`prepublishOnly` runs `napi pre-publish -t npm`, which updates `optionalDependencies` and publishes the platform packages alongside the main package.
|
package/native.cjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const { createRequire } = require("node:module");
|
|
2
|
+
const { readFileSync } = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
|
|
5
|
+
const requireFromHere = createRequire(__filename);
|
|
6
|
+
|
|
7
|
+
/** @type {Error[]} */
|
|
8
|
+
const loadErrors = [];
|
|
9
|
+
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
if (process.platform !== "linux") return false;
|
|
12
|
+
try {
|
|
13
|
+
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} pathOrPackage
|
|
21
|
+
* @returns {unknown}
|
|
22
|
+
*/
|
|
23
|
+
const tryRequire = (pathOrPackage) => {
|
|
24
|
+
try {
|
|
25
|
+
const loaded = requireFromHere(pathOrPackage);
|
|
26
|
+
return /** @type {unknown} */ (loaded);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
loadErrors.push(/** @type {Error} */ (error));
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** @returns {unknown} */
|
|
34
|
+
const loadNative = () => {
|
|
35
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
36
|
+
const fromEnv = tryRequire(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
37
|
+
if (fromEnv) return fromEnv;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const candidates = [];
|
|
41
|
+
const optionalPackages = [];
|
|
42
|
+
|
|
43
|
+
if (process.platform === "darwin") {
|
|
44
|
+
if (process.arch === "arm64") {
|
|
45
|
+
candidates.push("./slatedb-node.darwin-arm64.node");
|
|
46
|
+
optionalPackages.push("slatedb-node-darwin-arm64");
|
|
47
|
+
} else if (process.arch === "x64") {
|
|
48
|
+
candidates.push("./slatedb-node.darwin-x64.node");
|
|
49
|
+
optionalPackages.push("slatedb-node-darwin-x64");
|
|
50
|
+
}
|
|
51
|
+
} else if (process.platform === "win32") {
|
|
52
|
+
if (process.arch === "arm64") {
|
|
53
|
+
candidates.push("./slatedb-node.win32-arm64-msvc.node");
|
|
54
|
+
optionalPackages.push("slatedb-node-win32-arm64-msvc");
|
|
55
|
+
} else if (process.arch === "x64") {
|
|
56
|
+
candidates.push("./slatedb-node.win32-x64-msvc.node");
|
|
57
|
+
optionalPackages.push("slatedb-node-win32-x64-msvc");
|
|
58
|
+
}
|
|
59
|
+
} else if (process.platform === "linux") {
|
|
60
|
+
if (process.arch === "arm64") {
|
|
61
|
+
if (isMusl()) {
|
|
62
|
+
candidates.push("./slatedb-node.linux-arm64-musl.node");
|
|
63
|
+
optionalPackages.push("slatedb-node-linux-arm64-musl");
|
|
64
|
+
} else {
|
|
65
|
+
candidates.push("./slatedb-node.linux-arm64-gnu.node");
|
|
66
|
+
optionalPackages.push("slatedb-node-linux-arm64-gnu");
|
|
67
|
+
}
|
|
68
|
+
} else if (process.arch === "x64") {
|
|
69
|
+
if (isMusl()) {
|
|
70
|
+
candidates.push("./slatedb-node.linux-x64-musl.node");
|
|
71
|
+
optionalPackages.push("slatedb-node-linux-x64-musl");
|
|
72
|
+
} else {
|
|
73
|
+
candidates.push("./slatedb-node.linux-x64-gnu.node");
|
|
74
|
+
optionalPackages.push("slatedb-node-linux-x64-gnu");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const candidate of candidates) {
|
|
80
|
+
const loaded = tryRequire(path.join(__dirname, candidate));
|
|
81
|
+
if (loaded) return loaded;
|
|
82
|
+
const loadedRelative = tryRequire(candidate);
|
|
83
|
+
if (loadedRelative) return loadedRelative;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const packageName of optionalPackages) {
|
|
87
|
+
const loaded = tryRequire(packageName);
|
|
88
|
+
if (loaded) return loaded;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const error = new Error(
|
|
92
|
+
`Failed to load native binding for ${process.platform}/${process.arch}.\n` + loadErrors.map((entry) => `- ${entry.message}`).join("\n"),
|
|
93
|
+
);
|
|
94
|
+
error.cause = loadErrors;
|
|
95
|
+
throw error;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
module.exports = loadNative();
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "slatedb-node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node.js bindings for SlateDB via napi-rs",
|
|
5
|
+
"homepage": "https://github.com/gadget-inc/slatedb-node",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/gadget-inc/slatedb-node/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "SlateDB Authors"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/gadget-inc/slatedb-node.git"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"native.cjs",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./lib/index.js",
|
|
24
|
+
"types": "./lib/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./lib/index.d.ts",
|
|
28
|
+
"import": "./lib/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"artifacts": "napi artifacts",
|
|
37
|
+
"create-npm-dirs": "napi create-npm-dirs",
|
|
38
|
+
"build": "pnpm run clean && pnpm run build:debug && pnpm run build:ts",
|
|
39
|
+
"build:debug": "napi build --platform --no-js --dts target/napi-rs/index.d.ts",
|
|
40
|
+
"build:release": "napi build --platform --release --no-js --dts target/napi-rs/index.d.ts",
|
|
41
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
42
|
+
"clean": "rimraf *.node",
|
|
43
|
+
"lint": "pnpm run --aggregate-output '/^lint:(?!fix).*/'",
|
|
44
|
+
"lint:cspell": "cspell . --no-progress --show-suggestions --show-context",
|
|
45
|
+
"lint:fix": "oxfmt && oxlint --type-aware --fix",
|
|
46
|
+
"lint:oxfmt": "oxfmt --check",
|
|
47
|
+
"lint:oxlint": "oxlint --type-aware --deny-warnings",
|
|
48
|
+
"prepublishOnly": "napi pre-publish -t npm",
|
|
49
|
+
"release": "pnpm run build:release && pnpm run build:ts",
|
|
50
|
+
"test": "pnpm run build:debug && pnpm run build:ts && vitest run"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@napi-rs/cli": "^3.2.0",
|
|
54
|
+
"@types/node": "^24.5.2",
|
|
55
|
+
"cspell": "^9.6.4",
|
|
56
|
+
"oxfmt": "^0.32.0",
|
|
57
|
+
"oxlint": "^1.49.0",
|
|
58
|
+
"oxlint-tsgolint": "^0.14.1",
|
|
59
|
+
"rimraf": "^6.0.1",
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
61
|
+
"typescript": "^5.9.3",
|
|
62
|
+
"vitest": "^4.0.15"
|
|
63
|
+
},
|
|
64
|
+
"napi": {
|
|
65
|
+
"binaryName": "slatedb-node",
|
|
66
|
+
"targets": [
|
|
67
|
+
"x86_64-apple-darwin",
|
|
68
|
+
"aarch64-apple-darwin",
|
|
69
|
+
"x86_64-pc-windows-msvc",
|
|
70
|
+
"aarch64-pc-windows-msvc",
|
|
71
|
+
"x86_64-unknown-linux-gnu",
|
|
72
|
+
"x86_64-unknown-linux-musl",
|
|
73
|
+
"aarch64-unknown-linux-gnu",
|
|
74
|
+
"aarch64-unknown-linux-musl"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=20.0.0"
|
|
79
|
+
},
|
|
80
|
+
"packageManager": "pnpm@10.11.0",
|
|
81
|
+
"pnpm": {
|
|
82
|
+
"overrides": {
|
|
83
|
+
"diff": "^4.0.4",
|
|
84
|
+
"rollup": "^4.59.0"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"slatedb-node-darwin-x64": "0.1.0",
|
|
89
|
+
"slatedb-node-darwin-arm64": "0.1.0",
|
|
90
|
+
"slatedb-node-win32-x64-msvc": "0.1.0",
|
|
91
|
+
"slatedb-node-win32-arm64-msvc": "0.1.0",
|
|
92
|
+
"slatedb-node-linux-x64-gnu": "0.1.0",
|
|
93
|
+
"slatedb-node-linux-x64-musl": "0.1.0",
|
|
94
|
+
"slatedb-node-linux-arm64-gnu": "0.1.0",
|
|
95
|
+
"slatedb-node-linux-arm64-musl": "0.1.0"
|
|
96
|
+
}
|
|
97
|
+
}
|