kitedb 0.2.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/LICENSE +21 -0
- package/README.md +174 -0
- package/browser.js +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +210 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +193 -0
- package/dist/schema.js.map +1 -0
- package/index.d.ts +1412 -0
- package/index.js +613 -0
- package/package.json +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 N-API for Rust
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# kitedb
|
|
2
|
+
|
|
3
|
+
KiteDB native bindings for Node.js (and WASI/browser builds), powered by Rust + N-API.
|
|
4
|
+
|
|
5
|
+
Docs: https://ray-kwaf.vercel.app/docs
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install kitedb
|
|
11
|
+
# or
|
|
12
|
+
pnpm add kitedb
|
|
13
|
+
# or
|
|
14
|
+
yarn add kitedb
|
|
15
|
+
```
|
|
16
|
+
|
|
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.
|
|
18
|
+
|
|
19
|
+
## Quickstart (fluent API)
|
|
20
|
+
|
|
21
|
+
The fluent API provides a high-level, type-safe interface for schema-driven workflows:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { ray, node, edge, prop, optional } from 'kitedb'
|
|
25
|
+
|
|
26
|
+
// Define your schema
|
|
27
|
+
const User = node('user', {
|
|
28
|
+
key: (id: string) => `user:${id}`,
|
|
29
|
+
props: {
|
|
30
|
+
name: prop.string('name'),
|
|
31
|
+
email: prop.string('email'),
|
|
32
|
+
age: optional(prop.int('age')),
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const Knows = edge('knows', {
|
|
37
|
+
since: prop.int('since'),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Open database (async)
|
|
41
|
+
const db = await ray('./social.kitedb', {
|
|
42
|
+
nodes: [User],
|
|
43
|
+
edges: [Knows],
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Insert nodes
|
|
47
|
+
const alice = db.insert(User).values({ key: 'alice', name: 'Alice', email: 'alice@example.com' }).returning()
|
|
48
|
+
const bob = db.insert(User).values({ key: 'bob', name: 'Bob', email: 'bob@example.com' }).returning()
|
|
49
|
+
|
|
50
|
+
// Create edges
|
|
51
|
+
db.link(alice, Knows, bob, { since: 2024 })
|
|
52
|
+
|
|
53
|
+
// Traverse
|
|
54
|
+
const friends = db.from(alice).out(Knows).toArray()
|
|
55
|
+
|
|
56
|
+
// Pathfinding
|
|
57
|
+
const path = db.shortestPath(alice).via(Knows).to(bob).dijkstra()
|
|
58
|
+
|
|
59
|
+
db.close()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quickstart (low-level API)
|
|
63
|
+
|
|
64
|
+
For direct control, use the low-level `Database` class:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { Database, JsTraversalDirection, PropType, pathConfig, traversalStep } from 'kitedb'
|
|
68
|
+
|
|
69
|
+
const db = Database.open('example.kitedb', { createIfMissing: true })
|
|
70
|
+
|
|
71
|
+
// Transactions are explicit for write operations
|
|
72
|
+
db.begin()
|
|
73
|
+
const alice = db.createNode('user:alice')
|
|
74
|
+
const bob = db.createNode('user:bob')
|
|
75
|
+
|
|
76
|
+
const knows = db.getOrCreateEtype('knows')
|
|
77
|
+
const weight = db.getOrCreatePropkey('weight')
|
|
78
|
+
|
|
79
|
+
db.addEdge(alice, knows, bob)
|
|
80
|
+
|
|
81
|
+
// Set a typed edge property
|
|
82
|
+
db.setEdgeProp(alice, knows, bob, weight, {
|
|
83
|
+
propType: PropType.Int,
|
|
84
|
+
intValue: 1,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
db.commit()
|
|
88
|
+
|
|
89
|
+
// Traverse
|
|
90
|
+
const oneHop = db.traverseSingle([alice], JsTraversalDirection.Out, knows)
|
|
91
|
+
console.log(oneHop)
|
|
92
|
+
|
|
93
|
+
// Multi-hop traversal
|
|
94
|
+
const steps = [traversalStep(JsTraversalDirection.Out, knows), traversalStep(JsTraversalDirection.Out, knows)]
|
|
95
|
+
const twoHop = db.traverse([alice], steps)
|
|
96
|
+
console.log(twoHop)
|
|
97
|
+
|
|
98
|
+
// Pathfinding
|
|
99
|
+
const config = pathConfig(alice, bob)
|
|
100
|
+
config.allowedEdgeTypes = [knows]
|
|
101
|
+
const shortest = db.bfs(config)
|
|
102
|
+
console.log(shortest)
|
|
103
|
+
|
|
104
|
+
db.close()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Backups and health checks
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { createBackup, restoreBackup, healthCheck } from 'kitedb'
|
|
111
|
+
|
|
112
|
+
const backup = createBackup(db, 'backups/graph')
|
|
113
|
+
const restoredPath = restoreBackup(backup.path, 'restored/graph')
|
|
114
|
+
|
|
115
|
+
const health = healthCheck(db)
|
|
116
|
+
console.log(health.healthy)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Vector search
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { createVectorIndex } from 'kitedb'
|
|
123
|
+
|
|
124
|
+
const index = createVectorIndex({ dimensions: 3 })
|
|
125
|
+
index.set(1, [0.1, 0.2, 0.3])
|
|
126
|
+
index.set(2, [0.1, 0.25, 0.35])
|
|
127
|
+
index.buildIndex()
|
|
128
|
+
|
|
129
|
+
const hits = index.search([0.1, 0.2, 0.3], { k: 5 })
|
|
130
|
+
console.log(hits)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Browser/WASI builds
|
|
134
|
+
|
|
135
|
+
This package exposes a WASI-compatible build via the `browser` export for bundlers, backed by `kitedb-wasm32-wasi`. If you need to import it directly:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { Database } from 'kitedb-wasm32-wasi'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Concurrent Access
|
|
142
|
+
|
|
143
|
+
KiteDB supports concurrent read operations. Multiple async calls can read from the database simultaneously without blocking each other:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// These execute concurrently - reads don't block each other
|
|
147
|
+
const [user1, user2, user3] = await Promise.all([db.get(User, 'alice'), db.get(User, 'bob'), db.get(User, 'charlie')])
|
|
148
|
+
|
|
149
|
+
// Traversals can also run concurrently
|
|
150
|
+
const [aliceFriends, bobFriends] = await Promise.all([
|
|
151
|
+
db.from(alice).out(Knows).toArray(),
|
|
152
|
+
db.from(bob).out(Knows).toArray(),
|
|
153
|
+
])
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Concurrency model:**
|
|
157
|
+
|
|
158
|
+
- **Reads are concurrent**: Multiple `get()`, `from()`, `traverse()`, etc. can run in parallel
|
|
159
|
+
- **Writes are exclusive**: Write operations (`insert()`, `link()`, `update()`) require exclusive access
|
|
160
|
+
- **Read-write interaction**: A write will wait for in-progress reads to complete, then block new reads until done
|
|
161
|
+
|
|
162
|
+
This is implemented using a read-write lock (RwLock) internally, providing good read scalability while maintaining data consistency.
|
|
163
|
+
|
|
164
|
+
## API surface
|
|
165
|
+
|
|
166
|
+
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:
|
|
167
|
+
|
|
168
|
+
https://ray-kwaf.vercel.app/docs
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|
|
173
|
+
|
|
174
|
+
# trigger
|
package/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'kitedb-wasm32-wasi'
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RayDB - A fast, lightweight, embedded graph database for Node.js
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { ray, defineNode, defineEdge, prop, optional } from '@ray-db/core'
|
|
7
|
+
*
|
|
8
|
+
* // Define schema
|
|
9
|
+
* const User = defineNode('user', {
|
|
10
|
+
* key: (id: string) => `user:${id}`,
|
|
11
|
+
* props: {
|
|
12
|
+
* name: prop.string('name'),
|
|
13
|
+
* email: prop.string('email'),
|
|
14
|
+
* },
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* const knows = defineEdge('knows', {
|
|
18
|
+
* since: prop.int('since'),
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* // Open database
|
|
22
|
+
* const db = await ray('./my.raydb', {
|
|
23
|
+
* nodes: [User],
|
|
24
|
+
* edges: [knows],
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // Insert nodes
|
|
28
|
+
* const alice = db.insert('user').values('alice', { name: 'Alice' }).returning()
|
|
29
|
+
*
|
|
30
|
+
* // Close when done
|
|
31
|
+
* db.close()
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @packageDocumentation
|
|
35
|
+
*/
|
|
36
|
+
export { node, edge, prop, optional, withDefault, defineNode, defineEdge } from './schema';
|
|
37
|
+
export type { PropType, PropSpec, KeySpec, NodeSpec, NodeConfig, EdgeSpec } from './schema';
|
|
38
|
+
import { Ray as NativeRay } from '../index';
|
|
39
|
+
import type { NodeSpec, EdgeSpec } from './schema';
|
|
40
|
+
export { Ray } from '../index';
|
|
41
|
+
export { Database, VectorIndex, RayInsertBuilder, RayInsertExecutorSingle, RayInsertExecutorMany, RayUpdateBuilder, RayUpdateEdgeBuilder, RayTraversal, RayPath, } from '../index';
|
|
42
|
+
export { JsTraversalDirection as TraversalDirection, JsDistanceMetric as DistanceMetric, JsAggregation as Aggregation, JsSyncMode as SyncMode, JsCompressionType as CompressionType, PropType as PropValueType, } from '../index';
|
|
43
|
+
export { openDatabase, createBackup, restoreBackup, getBackupInfo, createOfflineBackup, collectMetrics, healthCheck, createVectorIndex, bruteForceSearch, pathConfig, traversalStep, version, } from '../index';
|
|
44
|
+
export type { DbStats, CheckResult, OpenOptions, ExportOptions, ExportResult, ImportOptions, ImportResult, BackupOptions, BackupResult, RestoreOptions, OfflineBackupOptions, StreamOptions, PaginationOptions, NodePage, EdgePage, NodeWithProps, EdgeWithProps, DatabaseMetrics, DataMetrics, CacheMetrics, CacheLayerMetrics, MemoryMetrics, MvccMetrics, MvccStats, HealthCheckResult, HealthCheckEntry, JsTraverseOptions as TraverseOptions, JsTraversalStep as TraversalStep, JsTraversalResult as TraversalResult, JsPathConfig as PathConfig, JsPathResult as PathResult, JsPathEdge as PathEdge, VectorIndexOptions, VectorIndexStats, VectorSearchHit, SimilarOptions, JsIvfConfig as IvfConfig, JsIvfStats as IvfStats, JsPqConfig as PqConfig, JsSearchOptions as SearchOptions, JsSearchResult as SearchResult, JsBruteForceResult as BruteForceResult, CompressionOptions, SingleFileOptimizeOptions, VacuumOptions, JsCacheStats as CacheStats, JsEdge as Edge, JsFullEdge as FullEdge, JsNodeProp as NodeProp, JsPropValue as PropValue, JsEdgeInput as EdgeInput, } from '../index';
|
|
45
|
+
/** Options for opening a Ray database */
|
|
46
|
+
export interface RayOptions {
|
|
47
|
+
/** Node type definitions */
|
|
48
|
+
nodes: NodeSpec[];
|
|
49
|
+
/** Edge type definitions */
|
|
50
|
+
edges: EdgeSpec[];
|
|
51
|
+
/** Open in read-only mode (default: false) */
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
/** Create database if it doesn't exist (default: true) */
|
|
54
|
+
createIfMissing?: boolean;
|
|
55
|
+
/** Acquire file lock (default: true) */
|
|
56
|
+
lockFile?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Open a Ray database asynchronously.
|
|
60
|
+
*
|
|
61
|
+
* This is the recommended way to open a database as it doesn't block
|
|
62
|
+
* the Node.js event loop during file I/O.
|
|
63
|
+
*
|
|
64
|
+
* @param path - Path to the database file
|
|
65
|
+
* @param options - Database options including schema
|
|
66
|
+
* @returns Promise resolving to a Ray database instance
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const db = await ray('./my.raydb', {
|
|
71
|
+
* nodes: [User, Post],
|
|
72
|
+
* edges: [follows, authored],
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function ray(path: string, options: RayOptions): Promise<NativeRay>;
|
|
77
|
+
/**
|
|
78
|
+
* Open a Ray database synchronously.
|
|
79
|
+
*
|
|
80
|
+
* Use this when you need synchronous initialization (e.g., at module load time).
|
|
81
|
+
* For most cases, prefer the async `ray()` function.
|
|
82
|
+
*
|
|
83
|
+
* @param path - Path to the database file
|
|
84
|
+
* @param options - Database options including schema
|
|
85
|
+
* @returns A Ray database instance
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const db = raySync('./my.raydb', {
|
|
90
|
+
* nodes: [User],
|
|
91
|
+
* edges: [knows],
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function raySync(path: string, options: RayOptions): NativeRay;
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAMH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1F,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAO3F,OAAO,EAA8C,GAAG,IAAI,SAAS,EAAE,MAAM,UAAU,CAAA;AAIvF,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAY,MAAM,UAAU,CAAA;AAO5D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,OA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,WAAW,IAAI,SAAS,EACxB,WAAW,IAAI,SAAS,GACzB,MAAM,UAAU,CAAA;AAMjB,yCAAyC;AACzC,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,4BAA4B;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AA6DD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAI/E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,CAGpE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RayDB - A fast, lightweight, embedded graph database for Node.js
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { ray, defineNode, defineEdge, prop, optional } from '@ray-db/core'
|
|
8
|
+
*
|
|
9
|
+
* // Define schema
|
|
10
|
+
* const User = defineNode('user', {
|
|
11
|
+
* key: (id: string) => `user:${id}`,
|
|
12
|
+
* props: {
|
|
13
|
+
* name: prop.string('name'),
|
|
14
|
+
* email: prop.string('email'),
|
|
15
|
+
* },
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* const knows = defineEdge('knows', {
|
|
19
|
+
* since: prop.int('since'),
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Open database
|
|
23
|
+
* const db = await ray('./my.raydb', {
|
|
24
|
+
* nodes: [User],
|
|
25
|
+
* edges: [knows],
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Insert nodes
|
|
29
|
+
* const alice = db.insert('user').values('alice', { name: 'Alice' }).returning()
|
|
30
|
+
*
|
|
31
|
+
* // Close when done
|
|
32
|
+
* db.close()
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.version = exports.traversalStep = exports.pathConfig = exports.bruteForceSearch = exports.createVectorIndex = exports.healthCheck = exports.collectMetrics = exports.createOfflineBackup = exports.getBackupInfo = exports.restoreBackup = exports.createBackup = exports.openDatabase = exports.PropValueType = exports.CompressionType = exports.SyncMode = exports.Aggregation = exports.DistanceMetric = exports.TraversalDirection = exports.RayPath = exports.RayTraversal = exports.RayUpdateEdgeBuilder = exports.RayUpdateBuilder = exports.RayInsertExecutorMany = exports.RayInsertExecutorSingle = exports.RayInsertBuilder = exports.VectorIndex = exports.Database = exports.Ray = exports.defineEdge = exports.defineNode = exports.withDefault = exports.optional = exports.prop = exports.edge = exports.node = void 0;
|
|
39
|
+
exports.ray = ray;
|
|
40
|
+
exports.raySync = raySync;
|
|
41
|
+
// =============================================================================
|
|
42
|
+
// Schema Builders (clean API)
|
|
43
|
+
// =============================================================================
|
|
44
|
+
var schema_1 = require("./schema");
|
|
45
|
+
Object.defineProperty(exports, "node", { enumerable: true, get: function () { return schema_1.node; } });
|
|
46
|
+
Object.defineProperty(exports, "edge", { enumerable: true, get: function () { return schema_1.edge; } });
|
|
47
|
+
Object.defineProperty(exports, "prop", { enumerable: true, get: function () { return schema_1.prop; } });
|
|
48
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return schema_1.optional; } });
|
|
49
|
+
Object.defineProperty(exports, "withDefault", { enumerable: true, get: function () { return schema_1.withDefault; } });
|
|
50
|
+
Object.defineProperty(exports, "defineNode", { enumerable: true, get: function () { return schema_1.defineNode; } });
|
|
51
|
+
Object.defineProperty(exports, "defineEdge", { enumerable: true, get: function () { return schema_1.defineEdge; } });
|
|
52
|
+
// =============================================================================
|
|
53
|
+
// Native Bindings
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// Import native bindings
|
|
56
|
+
const index_1 = require("../index");
|
|
57
|
+
// =============================================================================
|
|
58
|
+
// Clean Type Aliases (no Js prefix)
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// Re-export Ray class
|
|
61
|
+
var index_2 = require("../index");
|
|
62
|
+
Object.defineProperty(exports, "Ray", { enumerable: true, get: function () { return index_2.Ray; } });
|
|
63
|
+
// Re-export other classes with clean names
|
|
64
|
+
var index_3 = require("../index");
|
|
65
|
+
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return index_3.Database; } });
|
|
66
|
+
Object.defineProperty(exports, "VectorIndex", { enumerable: true, get: function () { return index_3.VectorIndex; } });
|
|
67
|
+
Object.defineProperty(exports, "RayInsertBuilder", { enumerable: true, get: function () { return index_3.RayInsertBuilder; } });
|
|
68
|
+
Object.defineProperty(exports, "RayInsertExecutorSingle", { enumerable: true, get: function () { return index_3.RayInsertExecutorSingle; } });
|
|
69
|
+
Object.defineProperty(exports, "RayInsertExecutorMany", { enumerable: true, get: function () { return index_3.RayInsertExecutorMany; } });
|
|
70
|
+
Object.defineProperty(exports, "RayUpdateBuilder", { enumerable: true, get: function () { return index_3.RayUpdateBuilder; } });
|
|
71
|
+
Object.defineProperty(exports, "RayUpdateEdgeBuilder", { enumerable: true, get: function () { return index_3.RayUpdateEdgeBuilder; } });
|
|
72
|
+
Object.defineProperty(exports, "RayTraversal", { enumerable: true, get: function () { return index_3.RayTraversal; } });
|
|
73
|
+
Object.defineProperty(exports, "RayPath", { enumerable: true, get: function () { return index_3.RayPath; } });
|
|
74
|
+
// Re-export enums with clean names
|
|
75
|
+
var index_4 = require("../index");
|
|
76
|
+
Object.defineProperty(exports, "TraversalDirection", { enumerable: true, get: function () { return index_4.JsTraversalDirection; } });
|
|
77
|
+
Object.defineProperty(exports, "DistanceMetric", { enumerable: true, get: function () { return index_4.JsDistanceMetric; } });
|
|
78
|
+
Object.defineProperty(exports, "Aggregation", { enumerable: true, get: function () { return index_4.JsAggregation; } });
|
|
79
|
+
Object.defineProperty(exports, "SyncMode", { enumerable: true, get: function () { return index_4.JsSyncMode; } });
|
|
80
|
+
Object.defineProperty(exports, "CompressionType", { enumerable: true, get: function () { return index_4.JsCompressionType; } });
|
|
81
|
+
Object.defineProperty(exports, "PropValueType", { enumerable: true, get: function () { return index_4.PropType; } });
|
|
82
|
+
// Re-export utility functions
|
|
83
|
+
var index_5 = require("../index");
|
|
84
|
+
Object.defineProperty(exports, "openDatabase", { enumerable: true, get: function () { return index_5.openDatabase; } });
|
|
85
|
+
Object.defineProperty(exports, "createBackup", { enumerable: true, get: function () { return index_5.createBackup; } });
|
|
86
|
+
Object.defineProperty(exports, "restoreBackup", { enumerable: true, get: function () { return index_5.restoreBackup; } });
|
|
87
|
+
Object.defineProperty(exports, "getBackupInfo", { enumerable: true, get: function () { return index_5.getBackupInfo; } });
|
|
88
|
+
Object.defineProperty(exports, "createOfflineBackup", { enumerable: true, get: function () { return index_5.createOfflineBackup; } });
|
|
89
|
+
Object.defineProperty(exports, "collectMetrics", { enumerable: true, get: function () { return index_5.collectMetrics; } });
|
|
90
|
+
Object.defineProperty(exports, "healthCheck", { enumerable: true, get: function () { return index_5.healthCheck; } });
|
|
91
|
+
Object.defineProperty(exports, "createVectorIndex", { enumerable: true, get: function () { return index_5.createVectorIndex; } });
|
|
92
|
+
Object.defineProperty(exports, "bruteForceSearch", { enumerable: true, get: function () { return index_5.bruteForceSearch; } });
|
|
93
|
+
Object.defineProperty(exports, "pathConfig", { enumerable: true, get: function () { return index_5.pathConfig; } });
|
|
94
|
+
Object.defineProperty(exports, "traversalStep", { enumerable: true, get: function () { return index_5.traversalStep; } });
|
|
95
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return index_5.version; } });
|
|
96
|
+
// =============================================================================
|
|
97
|
+
// Type Conversion Helpers
|
|
98
|
+
// =============================================================================
|
|
99
|
+
function propSpecToNative(spec) {
|
|
100
|
+
return {
|
|
101
|
+
type: spec.type,
|
|
102
|
+
optional: spec.optional,
|
|
103
|
+
default: spec.default,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function nodeSpecToNative(spec) {
|
|
107
|
+
let props;
|
|
108
|
+
if (spec.props) {
|
|
109
|
+
props = {};
|
|
110
|
+
for (const [k, v] of Object.entries(spec.props)) {
|
|
111
|
+
props[k] = propSpecToNative(v);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
name: spec.name,
|
|
116
|
+
key: spec.key,
|
|
117
|
+
props,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function edgeSpecToNative(spec) {
|
|
121
|
+
let props;
|
|
122
|
+
if (spec.props) {
|
|
123
|
+
props = {};
|
|
124
|
+
for (const [k, v] of Object.entries(spec.props)) {
|
|
125
|
+
props[k] = propSpecToNative(v);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
name: spec.name,
|
|
130
|
+
props,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function optionsToNative(options) {
|
|
134
|
+
return {
|
|
135
|
+
nodes: options.nodes.map(nodeSpecToNative),
|
|
136
|
+
edges: options.edges.map(edgeSpecToNative),
|
|
137
|
+
readOnly: options.readOnly,
|
|
138
|
+
createIfMissing: options.createIfMissing,
|
|
139
|
+
lockFile: options.lockFile,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// =============================================================================
|
|
143
|
+
// Main Entry Points
|
|
144
|
+
// =============================================================================
|
|
145
|
+
/**
|
|
146
|
+
* Open a Ray database asynchronously.
|
|
147
|
+
*
|
|
148
|
+
* This is the recommended way to open a database as it doesn't block
|
|
149
|
+
* the Node.js event loop during file I/O.
|
|
150
|
+
*
|
|
151
|
+
* @param path - Path to the database file
|
|
152
|
+
* @param options - Database options including schema
|
|
153
|
+
* @returns Promise resolving to a Ray database instance
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const db = await ray('./my.raydb', {
|
|
158
|
+
* nodes: [User, Post],
|
|
159
|
+
* edges: [follows, authored],
|
|
160
|
+
* })
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async function ray(path, options) {
|
|
164
|
+
const nativeOptions = optionsToNative(options);
|
|
165
|
+
// Cast through unknown because NAPI-RS generates Promise<unknown> for async tasks
|
|
166
|
+
return (await (0, index_1.ray)(path, nativeOptions));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Open a Ray database synchronously.
|
|
170
|
+
*
|
|
171
|
+
* Use this when you need synchronous initialization (e.g., at module load time).
|
|
172
|
+
* For most cases, prefer the async `ray()` function.
|
|
173
|
+
*
|
|
174
|
+
* @param path - Path to the database file
|
|
175
|
+
* @param options - Database options including schema
|
|
176
|
+
* @returns A Ray database instance
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const db = raySync('./my.raydb', {
|
|
181
|
+
* nodes: [User],
|
|
182
|
+
* edges: [knows],
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
function raySync(path, options) {
|
|
187
|
+
const nativeOptions = optionsToNative(options);
|
|
188
|
+
return (0, index_1.raySync)(path, nativeOptions);
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAmOH,kBAIC;AAoBD,0BAGC;AA5PD,gFAAgF;AAChF,8BAA8B;AAC9B,gFAAgF;AAEhF,mCAA0F;AAAjF,8F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