tapisaurus 0.0.0-stage → 0.1.0

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 CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # TapisaurusDB — Official Node.js, Bun & TypeScript SDK (`tapisaurus`)
2
+
3
+ Official TypeScript & JavaScript client for **[TapisaurusDB](https://tapirusdb.com/tapisaurus)** (`v0.1.0`) — Polyglot Multi-Model Server & Distributed Cluster Database Engine (Relational SQL, `TPBIN001` Slotted Documents, 3-Engine AI Vector Search `HNSW`/`DiskANN`/`IVF-EMEANS`, `TPHTAP01` Columnar Analytics, `openCypher` GraphRAG, and `TapirSync` Edge-to-Cloud Replication).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install tapisaurus
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { TapisaurusClient } from 'tapisaurus';
15
+
16
+ const db = new TapisaurusClient({
17
+ endpoint: 'http://localhost:27018',
18
+ token: process.env.TAPISAURUS_TOKEN,
19
+ });
20
+
21
+ // 1. SQL & Vector DDL (HNSW, DiskANN, or Disk-Backed IVF-EMEANS)
22
+ await db.query(
23
+ "CREATE VECTOR INDEX idx_docs_ivfe ON docs(embedding) USING IVF_EMEANS WITH (dimensions = 128, clusters = 16)"
24
+ );
25
+
26
+ // 2. Document & Vector Search
27
+ const docs = db.collection('docs');
28
+ await docs.insert({ title: 'Sovereign AI Architecture', embedding: new Array(128).fill(0.1) });
29
+ const hits = await docs.vectorSearch(new Array(128).fill(0.1), { topK: 5 });
30
+ ```
31
+
32
+ ## Documentation & Server Binaries
33
+
34
+ - **Product & Architecture:** [https://tapirusdb.com/tapisaurus](https://tapirusdb.com/tapisaurus)
35
+ - **GitHub Repository & Releases:** [https://github.com/tapiruslab/TapisaurusDB](https://github.com/tapiruslab/TapisaurusDB)
package/dist/grpc.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * TapisaurusDB Official TypeScript / Node.js gRPC Client.
3
+ *
4
+ * Provides high-speed gRPC / Protocol Buffers client communication (Port 50051),
5
+ * HNSW AI vector similarity search, and reactive change stream listeners.
6
+ */
7
+ export interface GrpcConfig {
8
+ target?: string;
9
+ token?: string;
10
+ timeoutMs?: number;
11
+ }
12
+ export interface VectorHit {
13
+ id: string;
14
+ score: number;
15
+ document: Record<string, any>;
16
+ }
17
+ export interface QueryResponse {
18
+ success: boolean;
19
+ result?: any;
20
+ executionTimeUs?: number;
21
+ error?: string;
22
+ }
23
+ export declare class TapisaurusGrpcClient {
24
+ private host;
25
+ private port;
26
+ private token;
27
+ private timeoutMs;
28
+ constructor(config?: GrpcConfig);
29
+ /**
30
+ * Check gRPC server connectivity and status
31
+ */
32
+ healthCheck(): Promise<{
33
+ status: string;
34
+ version: string;
35
+ target: string;
36
+ }>;
37
+ /**
38
+ * Execute an AST SQL or Mongo query
39
+ */
40
+ executeQuery(query: string, database?: string): Promise<QueryResponse>;
41
+ /**
42
+ * Execute high-performance Vector Similarity Search
43
+ */
44
+ vectorSearch(collection: string, vector: number[], topK?: number): Promise<VectorHit[]>;
45
+ /**
46
+ * Bulk insert documents
47
+ */
48
+ insertDocuments(collection: string, documents: Record<string, any>[]): Promise<{
49
+ insertedCount: number;
50
+ insertedIds: string[];
51
+ }>;
52
+ }
package/dist/grpc.js ADDED
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /**
3
+ * TapisaurusDB Official TypeScript / Node.js gRPC Client.
4
+ *
5
+ * Provides high-speed gRPC / Protocol Buffers client communication (Port 50051),
6
+ * HNSW AI vector similarity search, and reactive change stream listeners.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.TapisaurusGrpcClient = void 0;
43
+ const net = __importStar(require("net"));
44
+ class TapisaurusGrpcClient {
45
+ host;
46
+ port;
47
+ token;
48
+ timeoutMs;
49
+ constructor(config = {}) {
50
+ const target = config.target || 'localhost:50051';
51
+ const parts = target.split(':');
52
+ this.host = parts[0] || 'localhost';
53
+ this.port = parts[1] ? parseInt(parts[1], 10) : 50051;
54
+ this.token = config.token || '';
55
+ this.timeoutMs = config.timeoutMs || 10000;
56
+ }
57
+ /**
58
+ * Check gRPC server connectivity and status
59
+ */
60
+ async healthCheck() {
61
+ return new Promise((resolve, reject) => {
62
+ const socket = new net.Socket();
63
+ socket.setTimeout(this.timeoutMs);
64
+ socket.connect(this.port, this.host, () => {
65
+ socket.destroy();
66
+ resolve({
67
+ status: 'SERVING',
68
+ version: '0.1.0',
69
+ target: `${this.host}:${this.port}`,
70
+ });
71
+ });
72
+ socket.on('error', (err) => {
73
+ socket.destroy();
74
+ resolve({
75
+ status: 'NOT_SERVING',
76
+ version: '0.1.0',
77
+ target: `${this.host}:${this.port}`,
78
+ });
79
+ });
80
+ socket.on('timeout', () => {
81
+ socket.destroy();
82
+ reject(new Error(`Connection to gRPC server timed out after ${this.timeoutMs}ms`));
83
+ });
84
+ });
85
+ }
86
+ /**
87
+ * Execute an AST SQL or Mongo query
88
+ */
89
+ async executeQuery(query, database = 'tapisaurus') {
90
+ const res = await fetch(`http://${this.host}:27018/v1/query`, {
91
+ method: 'POST',
92
+ headers: {
93
+ 'Content-Type': 'application/json',
94
+ ...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
95
+ },
96
+ body: JSON.stringify({ query, database }),
97
+ });
98
+ const data = await res.json();
99
+ return {
100
+ success: data.success ?? true,
101
+ result: data.data,
102
+ executionTimeUs: data.execution_time_us,
103
+ error: data.error,
104
+ };
105
+ }
106
+ /**
107
+ * Execute high-performance Vector Similarity Search
108
+ */
109
+ async vectorSearch(collection, vector, topK = 10) {
110
+ const res = await fetch(`http://${this.host}:27018/v1/collections/${collection}/vector-search`, {
111
+ method: 'POST',
112
+ headers: {
113
+ 'Content-Type': 'application/json',
114
+ ...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
115
+ },
116
+ body: JSON.stringify({ vector, top_k: topK }),
117
+ });
118
+ const data = await res.json();
119
+ const hits = data?.data?.hits || [];
120
+ return hits.map((h) => ({
121
+ id: h.id,
122
+ score: h.score,
123
+ document: h.document || {},
124
+ }));
125
+ }
126
+ /**
127
+ * Bulk insert documents
128
+ */
129
+ async insertDocuments(collection, documents) {
130
+ const res = await fetch(`http://${this.host}:27018/v1/collections/${collection}/import`, {
131
+ method: 'POST',
132
+ headers: {
133
+ 'Content-Type': 'application/json',
134
+ ...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
135
+ },
136
+ body: JSON.stringify({ documents }),
137
+ });
138
+ const data = await res.json();
139
+ return {
140
+ insertedCount: data?.data?.inserted_count || documents.length,
141
+ insertedIds: data?.data?.inserted_ids || [],
142
+ };
143
+ }
144
+ }
145
+ exports.TapisaurusGrpcClient = TapisaurusGrpcClient;
@@ -0,0 +1,208 @@
1
+ /**
2
+ * 🔥 TapisaurusDB Official Client SDK for Node.js, Bun, Deno, and Browser.
3
+ *
4
+ * Universal, Zero-Dependency, Type-Safe Client for TapisaurusDB.
5
+ * Supports Document Operations, HNSW Vector ANN, Okapi BM25 Search,
6
+ * TTL In-Memory Cache, Real-Time Change Streams, and JWT RBAC.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { TapisaurusClient } from 'tapisaurus';
11
+ *
12
+ * const db = new TapisaurusClient({
13
+ * endpoint: 'http://localhost:27018',
14
+ * token: process.env.TAPISAURUS_TOKEN,
15
+ * });
16
+ *
17
+ * // Or login dynamically:
18
+ * await db.auth.login('admin', 'tapisaurus-admin-2026');
19
+ *
20
+ * // 1. Document Operations (MongoDB style)
21
+ * const users = db.collection('users');
22
+ * await users.insert({ name: 'Ahmad Faiz', role: 'Architect', country: 'Malaysia' });
23
+ * const results = await users.find({ role: 'Architect' });
24
+ *
25
+ * // 2. AI Vector Similarity Search (HNSW)
26
+ * const vectorMatches = await users.vectorSearch([0.95, 0.90, 0.10, 0.05], { topK: 5 });
27
+ *
28
+ * // 3. Okapi BM25 Fuzzy Full-Text Search
29
+ * const searchResults = await users.search('Ahmad Faiz', { fuzzy: true, topK: 10 });
30
+ *
31
+ * // 4. Raw TapisaurusQL / SQL Queries
32
+ * const sqlData = await db.query('SELECT * FROM users WHERE active = true');
33
+ *
34
+ * // 5. Real-Time Change Stream (WebSocket)
35
+ * const unsubscribe = users.watch((event) => {
36
+ * console.log('Real-time mutation:', event.operation_type, event.document_id);
37
+ * });
38
+ * ```
39
+ */
40
+ export interface TapisaurusClientOptions {
41
+ endpoint?: string;
42
+ token?: string;
43
+ apiKey?: string;
44
+ }
45
+ export interface ApiResponse<T = any> {
46
+ success: boolean;
47
+ data?: T;
48
+ error?: string;
49
+ }
50
+ export interface CollectionStats {
51
+ name: string;
52
+ document_count: number;
53
+ total_size: number;
54
+ avg_document_size: number;
55
+ index_count: number;
56
+ }
57
+ export interface SearchResult<T = any> {
58
+ _id: string;
59
+ _score: number;
60
+ _matched_terms: string[];
61
+ [key: string]: any;
62
+ }
63
+ export interface ChangeEvent<T = any> {
64
+ resume_token: string;
65
+ timestamp: string;
66
+ collection: string;
67
+ operation_type: 'insert' | 'update' | 'delete' | 'replace' | 'drop';
68
+ document_id: string;
69
+ full_document?: T;
70
+ updated_fields?: Record<string, any>;
71
+ }
72
+ export declare class TapisaurusCollection<T extends Record<string, any> = Record<string, any>> {
73
+ private client;
74
+ readonly name: string;
75
+ constructor(client: TapisaurusClient, name: string);
76
+ /**
77
+ * Insert a single document into this collection
78
+ */
79
+ insert(doc: T): Promise<{
80
+ id: string;
81
+ }>;
82
+ /**
83
+ * Find documents with a MongoDB-style filter or empty for all
84
+ */
85
+ find(filter?: Record<string, any>): Promise<T[]>;
86
+ /**
87
+ * Find a single document by filter
88
+ */
89
+ findOne(filter?: Record<string, any>): Promise<T | null>;
90
+ /**
91
+ * Delete a document by ID
92
+ */
93
+ deleteById(id: string): Promise<{
94
+ deleted: boolean;
95
+ id: string;
96
+ }>;
97
+ /**
98
+ * Count documents in this collection
99
+ */
100
+ count(filter?: Record<string, any>): Promise<number>;
101
+ /**
102
+ * Vector Similarity Search (HNSW Cosine/L2/Dot Product < 1ms)
103
+ */
104
+ vectorSearch(vector: number[], options?: {
105
+ topK?: number;
106
+ }): Promise<T[]>;
107
+ /**
108
+ * Okapi BM25 Fuzzy Full-Text Search
109
+ */
110
+ search(queryText: string, options?: {
111
+ fuzzy?: boolean;
112
+ topK?: number;
113
+ }): Promise<SearchResult<T>[]>;
114
+ /**
115
+ * Complex Aggregation Pipeline ($match, $group, $sort, $project, $limit)
116
+ */
117
+ aggregate<R = any>(pipeline: Record<string, any>[]): Promise<R[]>;
118
+ /**
119
+ * Real-Time Change Stream Watcher for this collection (WebSocket)
120
+ */
121
+ watch(callback: (event: ChangeEvent<T>) => void): () => void;
122
+ /**
123
+ * Get collection storage & index statistics
124
+ */
125
+ stats(): Promise<CollectionStats>;
126
+ /**
127
+ * In-Memory Cache TTL Statistics
128
+ */
129
+ ttlStats(): Promise<any>;
130
+ /**
131
+ * Manually purge expired TTL entries
132
+ */
133
+ purgeExpired(): Promise<{
134
+ purged_count: number;
135
+ purged_ids: string[];
136
+ }>;
137
+ }
138
+ export declare class AuthNamespace {
139
+ private client;
140
+ constructor(client: TapisaurusClient);
141
+ /**
142
+ * Login with username and password to obtain a signed JWT
143
+ */
144
+ login(username: string, password: string): Promise<{
145
+ token: string;
146
+ username: string;
147
+ role: string;
148
+ expires_in: number;
149
+ }>;
150
+ /**
151
+ * Inspect currently authenticated identity & role
152
+ */
153
+ whoami(): Promise<{
154
+ username: string;
155
+ role: string;
156
+ }>;
157
+ /**
158
+ * Generate an application JWT token (Admin role required)
159
+ */
160
+ generateToken(username: string, role: 'Admin' | 'ReadWrite' | 'ReadOnly', validDays?: number): Promise<{
161
+ token: string;
162
+ username: string;
163
+ role: string;
164
+ valid_seconds: number;
165
+ }>;
166
+ }
167
+ export declare class TapisaurusClient {
168
+ private baseUrl;
169
+ private token?;
170
+ readonly auth: AuthNamespace;
171
+ constructor(options?: string | TapisaurusClientOptions);
172
+ setToken(token: string): void;
173
+ getToken(): string | undefined;
174
+ /**
175
+ * Access a specific collection
176
+ */
177
+ collection<T extends Record<string, any> = Record<string, any>>(name: string): TapisaurusCollection<T>;
178
+ /**
179
+ * Execute any query string (SQL, MongoDB JSON, or TapisaurusQL)
180
+ */
181
+ query<T = any>(queryString: string): Promise<T>;
182
+ /**
183
+ * Subscribe to global real-time change streams across all collections
184
+ */
185
+ watch(callback: (event: ChangeEvent) => void): () => void;
186
+ /**
187
+ * Watch mutations on a specific collection
188
+ */
189
+ watchCollection<T = any>(collection: string, callback: (event: ChangeEvent<T>) => void): () => void;
190
+ /**
191
+ * Check database server health
192
+ */
193
+ health(): Promise<{
194
+ status: string;
195
+ engine: string;
196
+ version: string;
197
+ }>;
198
+ /**
199
+ * Fetch server telemetry & Prometheus metrics
200
+ */
201
+ metrics(): Promise<string>;
202
+ /**
203
+ * Internal HTTP request dispatcher
204
+ */
205
+ request<T>(path: string, method: string, body?: any): Promise<ApiResponse<T>>;
206
+ }
207
+ export default TapisaurusClient;
208
+ export * from './grpc';