thingd-native 0.18.2
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/README.md +40 -0
- package/index.d.ts +28 -0
- package/index.js +31 -0
- package/package.json +28 -0
- package/prebuilds/darwin-arm64/thingd_native.node +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# thingd-native
|
|
2
|
+
|
|
3
|
+
Private native Node.js binding for `thingd`.
|
|
4
|
+
|
|
5
|
+
This package is intentionally private and non-publishable right now. The public package remains `thingd`.
|
|
6
|
+
|
|
7
|
+
Current shape:
|
|
8
|
+
|
|
9
|
+
```txt
|
|
10
|
+
thingd
|
|
11
|
+
TypeScript public API
|
|
12
|
+
ThingStore interface
|
|
13
|
+
loads this package only for driver: "native"
|
|
14
|
+
|
|
15
|
+
thingd-native
|
|
16
|
+
napi-rs binding package
|
|
17
|
+
wraps crates/thingd-core
|
|
18
|
+
exposes low-level JSON bridge methods
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Build locally:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm --filter thingd-native build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then use it through the public SDK:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { ThingD } from "thingd";
|
|
31
|
+
|
|
32
|
+
const db = await ThingD.open({
|
|
33
|
+
path: "./thingd.db",
|
|
34
|
+
driver: "native",
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The native package should not define a separate app-facing API. It should satisfy the same SDK behavior tested in `packages/thingd/test`.
|
|
39
|
+
|
|
40
|
+
Do not publish this package until it has a prebuild strategy, migration story, and CI coverage for supported Node.js/platform combinations.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class NativeThingStore {
|
|
2
|
+
static open(path: string): NativeThingStore;
|
|
3
|
+
|
|
4
|
+
putObjectJson(collection: string, id: string, body: string): string;
|
|
5
|
+
getObjectJson(collection: string, id: string): string | null;
|
|
6
|
+
listObjectsJson(collectionsJson?: string): string;
|
|
7
|
+
deleteObject(collection: string, id: string): boolean;
|
|
8
|
+
appendEventJson(stream: string, body: string): string;
|
|
9
|
+
listEventsJson(stream?: string): string;
|
|
10
|
+
pushJobJson(
|
|
11
|
+
queue: string,
|
|
12
|
+
id: string,
|
|
13
|
+
body: string,
|
|
14
|
+
maxAttempts: number,
|
|
15
|
+
delayMs: number,
|
|
16
|
+
): string;
|
|
17
|
+
claimJobJson(queue: string, leaseMs: number): string | null;
|
|
18
|
+
ackJobJson(queue: string, id: string): string;
|
|
19
|
+
nackJobJson(queue: string, id: string, delayMs: number): string;
|
|
20
|
+
listJobsJson(queue: string): string;
|
|
21
|
+
listDeadJobsJson(queue: string): string;
|
|
22
|
+
countObjectsJson(): Promise<number>;
|
|
23
|
+
countEventsJson(): Promise<number>;
|
|
24
|
+
countActiveJobsJson(): Promise<number>;
|
|
25
|
+
countDeadJobsJson(): Promise<number>;
|
|
26
|
+
listCollectionsJson(): Promise<string>;
|
|
27
|
+
listStreamsJson(): Promise<string>;
|
|
28
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
function resolveBinding() {
|
|
10
|
+
// 1. Try local dev build first (dist/thingd_native.node)
|
|
11
|
+
const devPath = join(__dirname, "dist", "thingd_native.node");
|
|
12
|
+
if (existsSync(devPath)) {
|
|
13
|
+
return { binding: require(devPath), path: devPath };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 2. Try prebuilt binary matching current platform and arch
|
|
17
|
+
const platform = process.platform;
|
|
18
|
+
const arch = process.arch;
|
|
19
|
+
const prebuiltPath = join(__dirname, "prebuilds", `${platform}-${arch}`, "thingd_native.node");
|
|
20
|
+
if (existsSync(prebuiltPath)) {
|
|
21
|
+
return { binding: require(prebuiltPath), path: prebuiltPath };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 3. Fallback to requiring dev path directly (will throw standard error)
|
|
25
|
+
return { binding: require(devPath), path: devPath };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { binding, path } = resolveBinding();
|
|
29
|
+
|
|
30
|
+
export const { NativeThingStore } = binding;
|
|
31
|
+
export const loadedPath = path;
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "thingd-native",
|
|
3
|
+
"version": "0.18.2",
|
|
4
|
+
"description": "Private native Node.js binding for thingd.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"author": "Sayan Mohsin",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/sayanmohsin/thingd.git"
|
|
14
|
+
},
|
|
15
|
+
"main": "./index.js",
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"prebuilds",
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.d.ts",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "cargo build -p thingd-native --release && node scripts/copy-native.mjs",
|
|
25
|
+
"build:prebuild": "node scripts/copy-prebuild.mjs",
|
|
26
|
+
"clean": "node scripts/clean-native.mjs"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
Binary file
|