omniql 0.5.4 → 0.5.8

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/dist/omniql.d.ts CHANGED
@@ -2,17 +2,8 @@
2
2
  * OmniQL TypeScript / Node.js Binding
3
3
  * =====================================
4
4
  *
5
- * A modern, low-friction Node.js binding built with Koffi that wraps the
6
- * OmniQL shared library.
7
- *
8
- * Example usage:
9
- * import { OmniEngine } from 'omniql';
10
- *
11
- * const engine = new OmniEngine();
12
- * const driver = engine.registerSQLiteDriver(':memory:');
13
- * engine.route('data', driver);
14
- * const result = await engine.execute({ target: 'data', action: 'FIND' });
15
- * engine.close();
5
+ * A robust Node.js binding built with a native C++ addon to handle signal
6
+ * masking and FFI stability.
16
7
  */
17
8
  export type Action = 'FIND' | 'INSERT' | 'UPDATE' | 'DELETE' | 'COUNT';
18
9
  export interface Filter {
@@ -56,37 +47,11 @@ export interface CollectionSchema {
56
47
  export declare class OmniEngine {
57
48
  private readonly handle;
58
49
  constructor();
59
- /**
60
- * Internal helper to call native functions that return a JSON string
61
- * and need to be freed.
62
- */
63
- private callNative;
64
- /**
65
- * Executes an OQL query and returns the OmniJSON result.
66
- */
67
50
  execute<T = Record<string, unknown>>(query: Query): Promise<OmniResult<T>>;
68
- /**
69
- * Registers a collection schema with the engine.
70
- */
71
51
  registerSchema(schema: CollectionSchema): void;
72
- /**
73
- * Binds a collection/table target name to a driver name.
74
- */
75
52
  route(target: string, driverName: string): void;
76
- /**
77
- * Registers a SQLite driver.
78
- */
79
53
  registerSQLiteDriver(dsn: string): string;
80
- /**
81
- * Registers a PostgreSQL driver.
82
- */
83
54
  registerPostgresDriver(connStr: string): string;
84
- /**
85
- * Registers a MongoDB driver.
86
- */
87
55
  registerMongoDriver(uri: string, dbName: string): string;
88
- /**
89
- * Releases the native engine handle.
90
- */
91
56
  close(): void;
92
57
  }
package/dist/omniql.js CHANGED
@@ -3,17 +3,8 @@
3
3
  * OmniQL TypeScript / Node.js Binding
4
4
  * =====================================
5
5
  *
6
- * A modern, low-friction Node.js binding built with Koffi that wraps the
7
- * OmniQL shared library.
8
- *
9
- * Example usage:
10
- * import { OmniEngine } from 'omniql';
11
- *
12
- * const engine = new OmniEngine();
13
- * const driver = engine.registerSQLiteDriver(':memory:');
14
- * engine.route('data', driver);
15
- * const result = await engine.execute({ target: 'data', action: 'FIND' });
16
- * engine.close();
6
+ * A robust Node.js binding built with a native C++ addon to handle signal
7
+ * masking and FFI stability.
17
8
  */
18
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
10
  if (k2 === undefined) k2 = k;
@@ -50,12 +41,13 @@ var __importStar = (this && this.__importStar) || (function () {
50
41
  })();
51
42
  Object.defineProperty(exports, "__esModule", { value: true });
52
43
  exports.OmniEngine = void 0;
53
- const koffi = __importStar(require("koffi"));
54
44
  const path = __importStar(require("path"));
55
45
  const fs = __importStar(require("fs"));
56
46
  // ---------------------------------------------------------------------------
57
47
  // Native library loader
58
48
  // ---------------------------------------------------------------------------
49
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
50
+ const bridge = require('bindings')('omniql_bridge');
59
51
  const LIB_SEARCH_PATHS = [
60
52
  path.join(__dirname, 'libomniql.so'),
61
53
  path.join(__dirname, 'libomniql.dylib'),
@@ -63,103 +55,53 @@ const LIB_SEARCH_PATHS = [
63
55
  path.join(process.cwd(), 'libomniql.so'),
64
56
  path.join(process.cwd(), 'libomniql.dylib'),
65
57
  path.join(process.cwd(), 'omniql.dll'),
58
+ './libomniql.so',
59
+ 'libomniql.so',
66
60
  ];
67
61
  function findLibPath() {
68
62
  for (const p of LIB_SEARCH_PATHS) {
69
63
  if (fs.existsSync(p))
70
64
  return p;
71
65
  }
72
- throw new Error('OmniQL native library not found. ' +
73
- 'Please ensure libomniql.so/dylib/dll is present in the package or CWD.');
66
+ throw new Error('OmniQL native library not found. Please ensure libomniql.so/dylib/dll is present.');
74
67
  }
75
- const lib = koffi.load(findLibPath());
76
- // Function definitions
77
- const OmniQL_NewEngine = lib.func('int OmniQL_NewEngine()');
78
- const OmniQL_FreeEngine = lib.func('void OmniQL_FreeEngine(int)');
79
- const OmniQL_Execute = lib.func('void *OmniQL_Execute(int, const char *)');
80
- const OmniQL_RegisterSchema = lib.func('void *OmniQL_RegisterSchema(int, const char *)');
81
- const OmniQL_Route = lib.func('void *OmniQL_Route(int, const char *, const char *)');
82
- const OmniQL_RegisterSQLiteDriver = lib.func('void *OmniQL_RegisterSQLiteDriver(int, const char *)');
83
- const OmniQL_RegisterPostgresDriver = lib.func('void *OmniQL_RegisterPostgresDriver(int, const char *)');
84
- const OmniQL_RegisterMongoDriver = lib.func('void *OmniQL_RegisterMongoDriver(int, const char *, const char *)');
85
- const OmniQL_Free = lib.func('void OmniQL_Free(void *)');
68
+ // Initialize the bridge by loading the shared library.
69
+ // The C++ bridge handles SIGURG masking internally.
70
+ bridge.loadLib(findLibPath());
86
71
  // ---------------------------------------------------------------------------
87
72
  // OmniEngine class
88
73
  // ---------------------------------------------------------------------------
89
74
  class OmniEngine {
90
75
  handle;
91
76
  constructor() {
92
- this.handle = OmniQL_NewEngine();
93
- }
94
- /**
95
- * Internal helper to call native functions that return a JSON string
96
- * and need to be freed.
97
- */
98
- callNative(fn, ...args) {
99
- const raw = fn(this.handle, ...args);
100
- if (!raw || koffi.address(raw) === 0n)
101
- return '{}';
102
- try {
103
- return koffi.decode(raw, 'char *');
104
- }
105
- finally {
106
- OmniQL_Free(raw);
107
- }
77
+ this.handle = bridge.newEngine();
108
78
  }
109
- /**
110
- * Executes an OQL query and returns the OmniJSON result.
111
- */
112
79
  async execute(query) {
113
80
  const queryWithDefaults = { action: 'FIND', ...query };
114
81
  const json = JSON.stringify(queryWithDefaults);
115
- return new Promise((resolve, reject) => {
116
- try {
117
- const rawResponse = this.callNative(OmniQL_Execute, json);
118
- resolve(JSON.parse(rawResponse));
119
- }
120
- catch (err) {
121
- reject(err);
122
- }
123
- });
82
+ const rawResponse = bridge.execute(this.handle, json);
83
+ return JSON.parse(rawResponse);
124
84
  }
125
- /**
126
- * Registers a collection schema with the engine.
127
- */
128
85
  registerSchema(schema) {
129
- this.callNative(OmniQL_RegisterSchema, JSON.stringify(schema));
86
+ bridge.registerSchema(this.handle, JSON.stringify(schema));
130
87
  }
131
- /**
132
- * Binds a collection/table target name to a driver name.
133
- */
134
88
  route(target, driverName) {
135
- this.callNative(OmniQL_Route, target, driverName);
89
+ bridge.route(this.handle, target, driverName);
136
90
  }
137
- /**
138
- * Registers a SQLite driver.
139
- */
140
91
  registerSQLiteDriver(dsn) {
141
- const raw = this.callNative(OmniQL_RegisterSQLiteDriver, dsn);
92
+ const raw = bridge.registerSQLiteDriver(this.handle, dsn);
142
93
  return JSON.parse(raw).driver ?? 'sqlite';
143
94
  }
144
- /**
145
- * Registers a PostgreSQL driver.
146
- */
147
95
  registerPostgresDriver(connStr) {
148
- const raw = this.callNative(OmniQL_RegisterPostgresDriver, connStr);
96
+ const raw = bridge.registerPostgresDriver(this.handle, connStr);
149
97
  return JSON.parse(raw).driver ?? 'postgres';
150
98
  }
151
- /**
152
- * Registers a MongoDB driver.
153
- */
154
99
  registerMongoDriver(uri, dbName) {
155
- const raw = this.callNative(OmniQL_RegisterMongoDriver, uri, dbName);
100
+ const raw = bridge.registerMongoDriver(this.handle, uri, dbName);
156
101
  return JSON.parse(raw).driver ?? 'mongo';
157
102
  }
158
- /**
159
- * Releases the native engine handle.
160
- */
161
103
  close() {
162
- OmniQL_FreeEngine(this.handle);
104
+ bridge.freeEngine(this.handle);
163
105
  }
164
106
  }
165
107
  exports.OmniEngine = OmniEngine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omniql",
3
- "version": "0.5.4",
3
+ "version": "0.5.8",
4
4
  "description": "A standardized, multi-database query language (OQL) for TypeScript/Node.js.",
5
5
  "main": "dist/omniql.js",
6
6
  "types": "dist/omniql.d.ts",
@@ -13,10 +13,12 @@
13
13
  "author": "Uttam Mahata <uttam-mahata-cs@outlook.com>",
14
14
  "license": "Apache-2.0",
15
15
  "dependencies": {
16
- "koffi": "^2.9.0"
16
+ "bindings": "^1.5.0",
17
+ "node-addon-api": "^7.0.0"
17
18
  },
18
19
  "devDependencies": {
19
20
  "@types/node": "^20.0.0",
21
+ "node-gyp": "^10.0.0",
20
22
  "typescript": "^5.0.0"
21
23
  },
22
24
  "scripts": {