@cqlite/node 0.3.1-rc1
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 +252 -0
- package/cqlite-node.darwin-arm64.node +0 -0
- package/index.d.ts +0 -0
- package/index.js +318 -0
- package/lib/error-wrapper.js +375 -0
- package/lib/index.d.ts +874 -0
- package/lib/index.js +102 -0
- package/package.json +68 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CQLite Node.js bindings entry point.
|
|
3
|
+
*
|
|
4
|
+
* This module wraps the native bindings with enhanced error handling
|
|
5
|
+
* that provides structured error properties (code, category, isRecoverable).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* const { Database, version } = require('@cqlite/node');
|
|
10
|
+
*
|
|
11
|
+
* try {
|
|
12
|
+
* const db = await Database.open('/path/to/data', {
|
|
13
|
+
* schema: '/path/to/schema.cql'
|
|
14
|
+
* });
|
|
15
|
+
* const result = await db.execute('SELECT * FROM users LIMIT 10');
|
|
16
|
+
* console.log(`Got ${result.rowCount} rows`);
|
|
17
|
+
* await db.close();
|
|
18
|
+
* } catch (e) {
|
|
19
|
+
* console.log('Error code:', e.code); // e.g., "IO", "SCHEMA", "QUERY"
|
|
20
|
+
* console.log('Category:', e.category); // e.g., "System", "Schema"
|
|
21
|
+
* console.log('Recoverable:', e.isRecoverable);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const nativeBinding = require('../index.js');
|
|
27
|
+
const { createWrappedDatabase } = require('./error-wrapper.js');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* PreparedStatement wraps a native PreparedStatement with type consistency.
|
|
31
|
+
*
|
|
32
|
+
* Ensures estimatedRows in stats() is always BigInt (Issue #351).
|
|
33
|
+
* Users get this via Database.prepare() - direct construction not supported.
|
|
34
|
+
*
|
|
35
|
+
* Issue #351: Stats fields typed as bigint but runtime returns number
|
|
36
|
+
* Issue #352: PreparedStatement not exported at runtime but TypeScript declares it
|
|
37
|
+
*/
|
|
38
|
+
class PreparedStatement {
|
|
39
|
+
/**
|
|
40
|
+
* @private
|
|
41
|
+
* @param {Object} nativeStmt - The native PreparedStatement from Rust
|
|
42
|
+
*/
|
|
43
|
+
constructor(nativeStmt) {
|
|
44
|
+
this._native = nativeStmt;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The original CQL query text. */
|
|
48
|
+
get query() {
|
|
49
|
+
return this._native.query;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Number of parameters in the query. */
|
|
53
|
+
get parameterCount() {
|
|
54
|
+
return this._native.parameterCount;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get statistics about the prepared query.
|
|
59
|
+
* @returns {Object} PreparedStatementStats with estimatedRows as bigint
|
|
60
|
+
*/
|
|
61
|
+
stats() {
|
|
62
|
+
const nativeStats = this._native.stats();
|
|
63
|
+
return {
|
|
64
|
+
parameterCount: nativeStats.parameterCount,
|
|
65
|
+
planType: nativeStats.planType,
|
|
66
|
+
estimatedCost: nativeStats.estimatedCost,
|
|
67
|
+
estimatedRows: BigInt(nativeStats.estimatedRows),
|
|
68
|
+
cacheFriendly: nativeStats.cacheFriendly,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Return a string representation of this prepared statement.
|
|
74
|
+
* @returns {string} String representation
|
|
75
|
+
*/
|
|
76
|
+
toString() {
|
|
77
|
+
return this._native.toString();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Wrap a native PreparedStatement to ensure type consistency.
|
|
83
|
+
*
|
|
84
|
+
* @private
|
|
85
|
+
* @param {Object} nativeStmt - The native PreparedStatement from Rust
|
|
86
|
+
* @returns {PreparedStatement} Wrapped PreparedStatement instance
|
|
87
|
+
*/
|
|
88
|
+
function wrapPreparedStatement(nativeStmt) {
|
|
89
|
+
return new PreparedStatement(nativeStmt);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Create wrapped Database class with enhanced error handling
|
|
93
|
+
const Database = createWrappedDatabase(nativeBinding.Database, wrapPreparedStatement);
|
|
94
|
+
|
|
95
|
+
// Re-export version function
|
|
96
|
+
const { version } = nativeBinding;
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
Database,
|
|
100
|
+
PreparedStatement,
|
|
101
|
+
version,
|
|
102
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cqlite/node",
|
|
3
|
+
"version": "0.3.1-rc1",
|
|
4
|
+
"description": "Node.js bindings for CQLite - read Apache Cassandra 5.0 SSTables without cluster dependencies",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"napi": {
|
|
8
|
+
"binaryName": "cqlite-node",
|
|
9
|
+
"targets": [
|
|
10
|
+
"x86_64-apple-darwin",
|
|
11
|
+
"aarch64-apple-darwin",
|
|
12
|
+
"x86_64-unknown-linux-gnu",
|
|
13
|
+
"aarch64-unknown-linux-gnu",
|
|
14
|
+
"x86_64-pc-windows-msvc"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"lib",
|
|
21
|
+
"*.node",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/",
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "napi build --platform --release",
|
|
31
|
+
"build:debug": "napi build --platform",
|
|
32
|
+
"test": "jest",
|
|
33
|
+
"test:watch": "jest --watch",
|
|
34
|
+
"test:coverage": "jest --coverage",
|
|
35
|
+
"test:parity": "jest parity.test.js --testTimeout=60000",
|
|
36
|
+
"typecheck": "tsc --noEmit -p examples/tsconfig.json",
|
|
37
|
+
"examples": "ts-node examples/basic-query.ts",
|
|
38
|
+
"prepublishOnly": "echo 'Skipping napi prepublish - artifacts handled by CI workflow'"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@napi-rs/cli": "^3.5.1",
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"jest": "^29.7.0",
|
|
44
|
+
"ts-node": "^10.9.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">= 18"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/pmcfadin/cqlite.git",
|
|
53
|
+
"directory": "bindings/node"
|
|
54
|
+
},
|
|
55
|
+
"license": "MIT OR Apache-2.0",
|
|
56
|
+
"keywords": [
|
|
57
|
+
"cassandra",
|
|
58
|
+
"sstable",
|
|
59
|
+
"database",
|
|
60
|
+
"cql",
|
|
61
|
+
"cqlite"
|
|
62
|
+
],
|
|
63
|
+
"author": "CQLite Team",
|
|
64
|
+
"homepage": "https://github.com/pmcfadin/cqlite#readme",
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/pmcfadin/cqlite/issues"
|
|
67
|
+
}
|
|
68
|
+
}
|