omniql 0.5.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 ADDED
@@ -0,0 +1,18 @@
1
+ # OmniQL for TypeScript / Node.js
2
+
3
+ A standardized, multi-database query language (OQL) for TypeScript/Node.js.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install omniql
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { OmniEngine } from 'omniql';
15
+
16
+ const engine = new OmniEngine();
17
+ // ...
18
+ ```
Binary file
Binary file
@@ -0,0 +1,121 @@
1
+ /**
2
+ * OmniQL TypeScript / Node.js Binding
3
+ * =====================================
4
+ *
5
+ * A Node.js addon using N-API that wraps the OmniQL shared library and exposes
6
+ * a fully type-safe, Promise-based API with generated TypeScript definitions.
7
+ *
8
+ * Build the native library first:
9
+ * go build -buildmode=c-shared -o libomniql.so ../../pkg/ffi
10
+ *
11
+ * Install:
12
+ * npm install
13
+ *
14
+ * Example usage:
15
+ * import { OmniEngine, Query } from 'omniql';
16
+ *
17
+ * const engine = new OmniEngine();
18
+ *
19
+ * // 1. Register a driver and route a target to it.
20
+ * const driverName = engine.registerSQLiteDriver(':memory:');
21
+ * engine.route('analytics_data', driverName);
22
+ *
23
+ * // 2. Execute a query.
24
+ * const result = await engine.execute({
25
+ * target: 'analytics_data',
26
+ * action: 'FIND',
27
+ * filter: {
28
+ * category: { $in: ['electronics', 'books'] },
29
+ * price: { $lt: 500 },
30
+ * },
31
+ * options: { limit: 20 },
32
+ * });
33
+ *
34
+ * console.log(result.data);
35
+ * engine.close();
36
+ */
37
+ export type Action = 'FIND' | 'INSERT' | 'UPDATE' | 'DELETE' | 'COUNT';
38
+ export interface Filter {
39
+ [field: string]: unknown;
40
+ }
41
+ export interface QueryOptions {
42
+ limit?: number;
43
+ skip?: number;
44
+ sort?: Record<string, 1 | -1>;
45
+ fields?: Record<string, unknown>;
46
+ }
47
+ export interface Query {
48
+ target: string;
49
+ action?: Action;
50
+ filter?: Filter;
51
+ document?: Record<string, unknown>;
52
+ options?: QueryOptions;
53
+ }
54
+ export interface OmniMeta {
55
+ total: number;
56
+ returned: number;
57
+ driver: string;
58
+ target: string;
59
+ }
60
+ export interface OmniError {
61
+ code: string;
62
+ message: string;
63
+ }
64
+ export interface OmniResult<T = Record<string, unknown>> {
65
+ data: T[];
66
+ meta: OmniMeta;
67
+ error?: OmniError;
68
+ }
69
+ export interface CollectionSchema {
70
+ name: string;
71
+ fields: Record<string, {
72
+ type: string;
73
+ required?: boolean;
74
+ }>;
75
+ }
76
+ /**
77
+ * OmniEngine is the main entry-point for the OmniQL TypeScript binding.
78
+ *
79
+ * All `execute` calls are async and safe to use with `await`.
80
+ */
81
+ export declare class OmniEngine {
82
+ private readonly handle;
83
+ constructor();
84
+ /**
85
+ * Executes an OQL query and returns the OmniJSON result.
86
+ */
87
+ execute<T = Record<string, unknown>>(query: Query): Promise<OmniResult<T>>;
88
+ /**
89
+ * Registers a collection schema with the engine.
90
+ */
91
+ registerSchema(schema: CollectionSchema): void;
92
+ /**
93
+ * Binds a collection/table target name to a driver name.
94
+ * Must be called after registering a driver.
95
+ *
96
+ * @param target The collection or table name.
97
+ * @param driverName The driver name returned by a registerXxxDriver call.
98
+ */
99
+ route(target: string, driverName: string): void;
100
+ /**
101
+ * Registers a SQLite driver using the given DSN (file path or ":memory:").
102
+ * Returns the driver name ("sqlite") to use with {@link route}.
103
+ */
104
+ registerSQLiteDriver(dsn: string): string;
105
+ /**
106
+ * Registers a PostgreSQL driver using the given connection string.
107
+ * e.g. "host=localhost user=pg password=pg dbname=mydb sslmode=disable"
108
+ * Returns the driver name ("postgres") to use with {@link route}.
109
+ */
110
+ registerPostgresDriver(connStr: string): string;
111
+ /**
112
+ * Registers a MongoDB driver using the given URI and database name.
113
+ * e.g. uri = "mongodb://localhost:27017", dbName = "mydb"
114
+ * Returns the driver name ("mongo") to use with {@link route}.
115
+ */
116
+ registerMongoDriver(uri: string, dbName: string): string;
117
+ /**
118
+ * Releases the native engine handle. Call when done.
119
+ */
120
+ close(): void;
121
+ }
Binary file
package/dist/omniql.js ADDED
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ /**
3
+ * OmniQL TypeScript / Node.js Binding
4
+ * =====================================
5
+ *
6
+ * A Node.js addon using N-API that wraps the OmniQL shared library and exposes
7
+ * a fully type-safe, Promise-based API with generated TypeScript definitions.
8
+ *
9
+ * Build the native library first:
10
+ * go build -buildmode=c-shared -o libomniql.so ../../pkg/ffi
11
+ *
12
+ * Install:
13
+ * npm install
14
+ *
15
+ * Example usage:
16
+ * import { OmniEngine, Query } from 'omniql';
17
+ *
18
+ * const engine = new OmniEngine();
19
+ *
20
+ * // 1. Register a driver and route a target to it.
21
+ * const driverName = engine.registerSQLiteDriver(':memory:');
22
+ * engine.route('analytics_data', driverName);
23
+ *
24
+ * // 2. Execute a query.
25
+ * const result = await engine.execute({
26
+ * target: 'analytics_data',
27
+ * action: 'FIND',
28
+ * filter: {
29
+ * category: { $in: ['electronics', 'books'] },
30
+ * price: { $lt: 500 },
31
+ * },
32
+ * options: { limit: 20 },
33
+ * });
34
+ *
35
+ * console.log(result.data);
36
+ * engine.close();
37
+ */
38
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
39
+ if (k2 === undefined) k2 = k;
40
+ var desc = Object.getOwnPropertyDescriptor(m, k);
41
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
42
+ desc = { enumerable: true, get: function() { return m[k]; } };
43
+ }
44
+ Object.defineProperty(o, k2, desc);
45
+ }) : (function(o, m, k, k2) {
46
+ if (k2 === undefined) k2 = k;
47
+ o[k2] = m[k];
48
+ }));
49
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
50
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
51
+ }) : function(o, v) {
52
+ o["default"] = v;
53
+ });
54
+ var __importStar = (this && this.__importStar) || (function () {
55
+ var ownKeys = function(o) {
56
+ ownKeys = Object.getOwnPropertyNames || function (o) {
57
+ var ar = [];
58
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
59
+ return ar;
60
+ };
61
+ return ownKeys(o);
62
+ };
63
+ return function (mod) {
64
+ if (mod && mod.__esModule) return mod;
65
+ var result = {};
66
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
67
+ __setModuleDefault(result, mod);
68
+ return result;
69
+ };
70
+ })();
71
+ Object.defineProperty(exports, "__esModule", { value: true });
72
+ exports.OmniEngine = void 0;
73
+ const ffi = __importStar(require("ffi-napi"));
74
+ const path = __importStar(require("path"));
75
+ const fs = __importStar(require("fs"));
76
+ // ---------------------------------------------------------------------------
77
+ // Native library loader
78
+ // ---------------------------------------------------------------------------
79
+ const LIB_SEARCH_PATHS = [
80
+ path.join(__dirname, 'libomniql.so'),
81
+ path.join(__dirname, 'libomniql.dylib'),
82
+ path.join(__dirname, 'omniql.dll'),
83
+ 'libomniql',
84
+ ];
85
+ function loadLib() {
86
+ for (const p of LIB_SEARCH_PATHS) {
87
+ if (fs.existsSync(p)) {
88
+ return ffi.Library(p, {
89
+ OmniQL_NewEngine: ['int', []],
90
+ OmniQL_FreeEngine: ['void', ['int']],
91
+ OmniQL_Execute: ['string', ['int', 'string']],
92
+ OmniQL_RegisterSchema: ['string', ['int', 'string']],
93
+ OmniQL_Route: ['string', ['int', 'string', 'string']],
94
+ OmniQL_RegisterSQLiteDriver: ['string', ['int', 'string']],
95
+ OmniQL_RegisterPostgresDriver: ['string', ['int', 'string']],
96
+ OmniQL_RegisterMongoDriver: ['string', ['int', 'string', 'string']],
97
+ OmniQL_Free: ['void', ['pointer']],
98
+ });
99
+ }
100
+ }
101
+ throw new Error('OmniQL native library not found. ' +
102
+ 'Build it with: go build -buildmode=c-shared -o libomniql.so ../../pkg/ffi');
103
+ }
104
+ const lib = loadLib();
105
+ // ---------------------------------------------------------------------------
106
+ // OmniEngine class
107
+ // ---------------------------------------------------------------------------
108
+ /**
109
+ * OmniEngine is the main entry-point for the OmniQL TypeScript binding.
110
+ *
111
+ * All `execute` calls are async and safe to use with `await`.
112
+ */
113
+ class OmniEngine {
114
+ handle;
115
+ constructor() {
116
+ this.handle = lib.OmniQL_NewEngine();
117
+ }
118
+ /**
119
+ * Executes an OQL query and returns the OmniJSON result.
120
+ */
121
+ async execute(query) {
122
+ const queryWithDefaults = { action: 'FIND', ...query };
123
+ const json = JSON.stringify(queryWithDefaults);
124
+ return new Promise((resolve, reject) => {
125
+ try {
126
+ const raw = lib.OmniQL_Execute(this.handle, json);
127
+ resolve(JSON.parse(raw));
128
+ }
129
+ catch (err) {
130
+ reject(err);
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * Registers a collection schema with the engine.
136
+ */
137
+ registerSchema(schema) {
138
+ lib.OmniQL_RegisterSchema(this.handle, JSON.stringify(schema));
139
+ }
140
+ /**
141
+ * Binds a collection/table target name to a driver name.
142
+ * Must be called after registering a driver.
143
+ *
144
+ * @param target The collection or table name.
145
+ * @param driverName The driver name returned by a registerXxxDriver call.
146
+ */
147
+ route(target, driverName) {
148
+ lib.OmniQL_Route(this.handle, target, driverName);
149
+ }
150
+ /**
151
+ * Registers a SQLite driver using the given DSN (file path or ":memory:").
152
+ * Returns the driver name ("sqlite") to use with {@link route}.
153
+ */
154
+ registerSQLiteDriver(dsn) {
155
+ const raw = lib.OmniQL_RegisterSQLiteDriver(this.handle, dsn);
156
+ return JSON.parse(raw).driver ?? 'sqlite';
157
+ }
158
+ /**
159
+ * Registers a PostgreSQL driver using the given connection string.
160
+ * e.g. "host=localhost user=pg password=pg dbname=mydb sslmode=disable"
161
+ * Returns the driver name ("postgres") to use with {@link route}.
162
+ */
163
+ registerPostgresDriver(connStr) {
164
+ const raw = lib.OmniQL_RegisterPostgresDriver(this.handle, connStr);
165
+ return JSON.parse(raw).driver ?? 'postgres';
166
+ }
167
+ /**
168
+ * Registers a MongoDB driver using the given URI and database name.
169
+ * e.g. uri = "mongodb://localhost:27017", dbName = "mydb"
170
+ * Returns the driver name ("mongo") to use with {@link route}.
171
+ */
172
+ registerMongoDriver(uri, dbName) {
173
+ const raw = lib.OmniQL_RegisterMongoDriver(this.handle, uri, dbName);
174
+ return JSON.parse(raw).driver ?? 'mongo';
175
+ }
176
+ /**
177
+ * Releases the native engine handle. Call when done.
178
+ */
179
+ close() {
180
+ lib.OmniQL_FreeEngine(this.handle);
181
+ }
182
+ }
183
+ exports.OmniEngine = OmniEngine;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "omniql",
3
+ "version": "0.5.2",
4
+ "description": "A standardized, multi-database query language (OQL) for TypeScript/Node.js.",
5
+ "main": "dist/omniql.js",
6
+ "types": "dist/omniql.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "*.so",
10
+ "*.dll",
11
+ "*.dylib"
12
+ ],
13
+ "author": "Uttam Mahata <uttam-mahata-cs@outlook.com>",
14
+ "license": "Apache-2.0",
15
+ "dependencies": {
16
+ "ffi-napi": "^4.0.3",
17
+ "ref-napi": "^3.0.3"
18
+ },
19
+ "devDependencies": {
20
+ "@types/ffi-napi": "^4.0.10",
21
+ "@types/node": "^20.0.0",
22
+ "@types/ref-napi": "^3.0.12",
23
+ "typescript": "^5.0.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc"
27
+ }
28
+ }