@ray-db/core 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/README.md +77 -51
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,87 +1,113 @@
1
- # `@napi-rs/package-template`
1
+ # @ray-db/core
2
2
 
3
- ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
3
+ RayDB native bindings for Node.js (and WASI/browser builds), powered by Rust + N-API.
4
4
 
5
- > Template project for writing node packages with napi-rs.
5
+ Docs: https://ray-kwaf.vercel.app/docs
6
6
 
7
- # Usage
8
-
9
- 1. Click **Use this template**.
10
- 2. **Clone** your project.
11
- 3. Run `yarn install` to install dependencies.
12
- 4. Run `yarn napi rename -n [@your-scope/package-name] -b [binary-name]` command under the project folder to rename your package.
13
-
14
- ## Install this test package
7
+ ## Install
15
8
 
16
9
  ```bash
17
- yarn add @napi-rs/package-template
10
+ npm install @ray-db/core
11
+ # or
12
+ pnpm add @ray-db/core
13
+ # or
14
+ yarn add @ray-db/core
18
15
  ```
19
16
 
20
- ## Ability
17
+ This package ships prebuilt binaries for major platforms. If a prebuild isn't available for your target, you'll need a Rust toolchain to build from source.
21
18
 
22
- ### Build
19
+ ## Quickstart (graph basics)
23
20
 
24
- After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
21
+ ```ts
22
+ import {
23
+ Database,
24
+ JsTraversalDirection,
25
+ PropType,
26
+ pathConfig,
27
+ traversalStep,
28
+ } from '@ray-db/core'
25
29
 
26
- ### Test
30
+ const db = Database.open('example.raydb', { createIfMissing: true })
27
31
 
28
- With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
32
+ // Transactions are explicit for write operations
33
+ db.begin()
34
+ const alice = db.createNode('user:alice')
35
+ const bob = db.createNode('user:bob')
29
36
 
30
- ### CI
37
+ const knows = db.getOrCreateEtype('knows')
38
+ const weight = db.getOrCreatePropkey('weight')
31
39
 
32
- With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@20`, `@node22`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
40
+ db.addEdge(alice, knows, bob)
33
41
 
34
- ### Release
42
+ // Set a typed edge property
43
+ db.setEdgeProp(alice, knows, bob, weight, {
44
+ propType: PropType.Int,
45
+ intValue: 1,
46
+ })
35
47
 
36
- Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
48
+ db.commit()
37
49
 
38
- With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
50
+ // Traverse
51
+ const oneHop = db.traverseSingle([alice], JsTraversalDirection.Out, knows)
52
+ console.log(oneHop)
39
53
 
40
- The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
54
+ // Multi-hop traversal
55
+ const steps = [
56
+ traversalStep(JsTraversalDirection.Out, knows),
57
+ traversalStep(JsTraversalDirection.Out, knows),
58
+ ]
59
+ const twoHop = db.traverse([alice], steps)
60
+ console.log(twoHop)
41
61
 
42
- In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
62
+ // Pathfinding
63
+ const config = pathConfig(alice, bob)
64
+ config.allowedEdgeTypes = [knows]
65
+ const shortest = db.bfs(config)
66
+ console.log(shortest)
43
67
 
44
- `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
68
+ db.close()
69
+ ```
45
70
 
46
- ## Develop requirements
71
+ ## Backups and health checks
47
72
 
48
- - Install the latest `Rust`
49
- - Install `Node.js@10+` which fully supported `Node-API`
50
- - Install `yarn@1.x`
73
+ ```ts
74
+ import { createBackup, restoreBackup, healthCheck } from '@ray-db/core'
51
75
 
52
- ## Test in local
76
+ const backup = createBackup(db, 'backups/graph')
77
+ const restoredPath = restoreBackup(backup.path, 'restored/graph')
53
78
 
54
- - yarn
55
- - yarn build
56
- - yarn test
79
+ const health = healthCheck(db)
80
+ console.log(health.healthy)
81
+ ```
57
82
 
58
- And you will see:
83
+ ## Vector search
59
84
 
60
- ```bash
61
- $ ava --verbose
85
+ ```ts
86
+ import { createVectorIndex } from '@ray-db/core'
62
87
 
63
- sync function from native code
64
- sleep function from native code (201ms)
65
-
88
+ const index = createVectorIndex({ dimensions: 3 })
89
+ index.set(1, [0.1, 0.2, 0.3])
90
+ index.set(2, [0.1, 0.25, 0.35])
91
+ index.buildIndex()
66
92
 
67
- 2 tests passed
68
- ✨ Done in 1.12s.
93
+ const hits = index.search([0.1, 0.2, 0.3], { k: 5 })
94
+ console.log(hits)
69
95
  ```
70
96
 
71
- ## Release package
97
+ ## Browser/WASI builds
72
98
 
73
- Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
99
+ This package exposes a WASI-compatible build via the `browser` export for bundlers, backed by `@ray-db/core-wasm32-wasi`. If you need to import it directly:
74
100
 
75
- In `Settings -> Secrets`, add **NPM_TOKEN** into it.
101
+ ```ts
102
+ import { Database } from '@ray-db/core-wasm32-wasi'
103
+ ```
76
104
 
77
- When you want to release the package:
105
+ ## API surface
78
106
 
79
- ```bash
80
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
107
+ The Node bindings expose both low-level graph primitives (`Database`) and higher-level APIs (Ray) for schema-driven workflows, plus metrics, backups, traversal, and vector search. For full API details and guides, see the docs:
81
108
 
82
- git push
83
- ```
109
+ https://ray-kwaf.vercel.app/docs
84
110
 
85
- GitHub actions will do the rest job for you.
111
+ ## License
86
112
 
87
- > WARN: Don't run `npm publish` manually.
113
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-db/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Template project for writing node package with napi-rs",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -117,10 +117,10 @@
117
117
  },
118
118
  "packageManager": "yarn@4.12.0",
119
119
  "optionalDependencies": {
120
- "@ray-db/core-win32-x64-msvc": "0.1.5",
121
- "@ray-db/core-darwin-x64": "0.1.5",
122
- "@ray-db/core-linux-x64-gnu": "0.1.5",
123
- "@ray-db/core-darwin-arm64": "0.1.5",
124
- "@ray-db/core-wasm32-wasi": "0.1.5"
120
+ "@ray-db/core-win32-x64-msvc": "0.1.6",
121
+ "@ray-db/core-darwin-x64": "0.1.6",
122
+ "@ray-db/core-linux-x64-gnu": "0.1.6",
123
+ "@ray-db/core-darwin-arm64": "0.1.6",
124
+ "@ray-db/core-wasm32-wasi": "0.1.6"
125
125
  }
126
126
  }