@anvailabs/proximadb-client 0.4.1 → 0.5.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.
@@ -1,761 +0,0 @@
1
- /**
2
- * ProximaDB TypeScript SDK - Client
3
- *
4
- * Main entry point for connecting to ProximaDB servers.
5
- *
6
- * Copyright 2025 ProximaDB Contributors
7
- * Licensed under the Apache License, Version 2.0
8
- */
9
- import { ProximaDBError, ErrorCode, } from "./types";
10
- import { CollectionBuilder, CollectionHandle, } from "./collection";
11
- import { GraphBuilder, GraphHandle } from "./graph";
12
- import { createTransport } from "./transport";
13
- /**
14
- * Default client configuration
15
- */
16
- const DEFAULT_CONFIG = {
17
- url: "http://localhost:5678",
18
- timeoutMs: 30000,
19
- maxRetries: 3,
20
- apiKey: "",
21
- poolConnections: true,
22
- maxIdleConnections: 10,
23
- };
24
- function graphInfoFromWire(value) {
25
- const graph = typeof value === "object" && value !== null
26
- ? value
27
- : {};
28
- const displayName = typeof graph.name === "string" ? graph.name : "";
29
- const graphId = typeof graph.graph_id === "string" ? graph.graph_id : "";
30
- const description = typeof graph.description === "string" ? graph.description : undefined;
31
- const topLevelNodeCount = typeof graph.node_count === "number" ? graph.node_count : undefined;
32
- const topLevelEdgeCount = typeof graph.edge_count === "number" ? graph.edge_count : undefined;
33
- const nestedNodeCount = typeof graph.stats?.total_nodes === "number"
34
- ? graph.stats.total_nodes
35
- : undefined;
36
- const nestedEdgeCount = typeof graph.stats?.total_edges === "number"
37
- ? graph.stats.total_edges
38
- : undefined;
39
- return {
40
- name: displayName.trim().length > 0 ? displayName : graphId,
41
- nodeCount: topLevelNodeCount ?? nestedNodeCount ?? 0,
42
- edgeCount: topLevelEdgeCount ?? nestedEdgeCount ?? 0,
43
- ...(description === undefined ? {} : { description }),
44
- };
45
- }
46
- function objectFromWire(value) {
47
- return typeof value === "object" && value !== null
48
- ? value
49
- : {};
50
- }
51
- /**
52
- * Wave-6 envelope truth: a 2xx graph body carries the canonical
53
- * `{success, data}` envelope. A 200 whose `data` member is absent is a
54
- * server-contract violation — a pre-wave-6 flat body or a `{success:false}`
55
- * body that slipped through as 200. Lowering such a body would fabricate an
56
- * empty node / traversal / list out of a real failure (the repo's
57
- * silent-Ok(failure) anti-pattern), so throw instead.
58
- */
59
- function requireEnvelopeData(body, operation) {
60
- const data = objectFromWire(body).data;
61
- if (data === undefined) {
62
- throw new ProximaDBError(`${operation}: 2xx response is missing the canonical {success, data} envelope` +
63
- " (server version mismatch or success:false body)", ErrorCode.ServerError);
64
- }
65
- return data;
66
- }
67
- function graphNodeFromWire(value) {
68
- const node = objectFromWire(value);
69
- const labels = Array.isArray(node.labels) ? node.labels : [];
70
- const embedding = objectFromWire(node.embedding);
71
- const vector = Array.isArray(embedding.vector)
72
- ? embedding.vector.filter((entry) => typeof entry === "number")
73
- : undefined;
74
- const label = labels.find((entry) => typeof entry === "string");
75
- return {
76
- id: typeof node.id === "string" ? node.id : "",
77
- ...(label === undefined ? {} : { label }),
78
- properties: objectFromWire(node.properties),
79
- ...(vector === undefined ? {} : { vector }),
80
- };
81
- }
82
- function graphEdgeFromWire(value) {
83
- const edge = objectFromWire(value);
84
- const weight = typeof edge.weight === "number" ? edge.weight : undefined;
85
- return {
86
- source: typeof edge.from_node_id === "string" ? edge.from_node_id : "",
87
- target: typeof edge.to_node_id === "string" ? edge.to_node_id : "",
88
- relationship: typeof edge.edge_type === "string" ? edge.edge_type : "",
89
- properties: objectFromWire(edge.properties),
90
- ...(weight === undefined ? {} : { weight }),
91
- };
92
- }
93
- function traversalResultFromWire(value) {
94
- const result = objectFromWire(value);
95
- const paths = Array.isArray(result.paths)
96
- ? result.paths.filter((path) => Array.isArray(path) &&
97
- path.every((entry) => typeof entry === "string"))
98
- : [];
99
- return {
100
- nodes: (Array.isArray(result.nodes) ? result.nodes : []).map(graphNodeFromWire),
101
- edges: (Array.isArray(result.edges) ? result.edges : []).map(graphEdgeFromWire),
102
- paths,
103
- };
104
- }
105
- /**
106
- * Get the global fetch function
107
- */
108
- function getFetch() {
109
- if (typeof globalThis.fetch === "function") {
110
- return globalThis.fetch.bind(globalThis);
111
- }
112
- throw new Error("No fetch implementation available. " +
113
- "Node.js 18+ includes fetch natively. " +
114
- "For older versions, install node-fetch.");
115
- }
116
- /**
117
- * ProximaDB client for connecting to a remote server
118
- */
119
- export class ProximaDBClient {
120
- config;
121
- fetchFn;
122
- /**
123
- * Generated typed REST transport (TD-126 Phase 4). Core collection / record
124
- * / search operations route through this; it owns URL/path/query/body
125
- * encoding per the OpenAPI spec. Auth, retries, and error mapping are
126
- * injected via the facade's own fetch (see `transportFetch`).
127
- */
128
- gen;
129
- /**
130
- * Create a new client with the given URL
131
- */
132
- static connect(url) {
133
- return new ProximaDBClient({ url });
134
- }
135
- /**
136
- * Create a new client builder
137
- */
138
- static builder() {
139
- return new ClientBuilder();
140
- }
141
- /**
142
- * Create a client with configuration
143
- */
144
- constructor(config = {}) {
145
- this.config = { ...DEFAULT_CONFIG, ...config };
146
- this.fetchFn = getFetch();
147
- // Validate URL
148
- try {
149
- new URL(this.config.url);
150
- }
151
- catch {
152
- throw new ProximaDBError("Invalid URL: " + this.config.url, ErrorCode.InvalidConfig);
153
- }
154
- // Wire the generated typed transport. Every request the generated client
155
- // issues is funneled through `transportFetch`, the facade's own fetch that
156
- // applies bearer auth, retries, and error mapping — exactly as the legacy
157
- // generic `request<T>` path does.
158
- this.gen = createTransport(this.config.url, (req) => this.transportFetch(req));
159
- }
160
- /**
161
- * Transport `fetch` handed to the generated client.
162
- *
163
- * The generated client assembles a resolved `Request` (URL + method + body);
164
- * this normalizes it back to the facade's `(url, init)` retry/auth/error
165
- * pipeline so the wire plumbing and transport policy compose. The returned
166
- * value is a `Response`-shaped object the generated client parses; on an
167
- * unsuccessful response a `ProximaDBError` is thrown (matching the generic
168
- * path), so callers never see a non-2xx body.
169
- */
170
- async transportFetch(req) {
171
- const method = (req.method || "GET").toUpperCase();
172
- let body = undefined;
173
- if (method !== "GET" && method !== "DELETE") {
174
- const text = await req.clone().text();
175
- if (text.length > 0) {
176
- body = JSON.parse(text);
177
- }
178
- }
179
- const data = await this.request(method, req.url, body);
180
- // Re-wrap the already-parsed, validated body as a Response so the
181
- // generated client can read `.json()`/`.ok` without re-issuing I/O.
182
- return new Response(JSON.stringify(data ?? null), {
183
- status: 200,
184
- headers: { "Content-Type": "application/json" },
185
- });
186
- }
187
- /**
188
- * Get the server URL
189
- */
190
- url() {
191
- return this.config.url;
192
- }
193
- /**
194
- * Get the client configuration
195
- */
196
- getConfig() {
197
- return { ...this.config };
198
- }
199
- // =========================================================================
200
- // HTTP Methods
201
- // =========================================================================
202
- /**
203
- * Make a GET request
204
- */
205
- async get(requestUrl) {
206
- return this.request("GET", requestUrl);
207
- }
208
- /**
209
- * Make a POST request
210
- */
211
- async post(requestUrl, body) {
212
- return this.request("POST", requestUrl, body);
213
- }
214
- /**
215
- * Make a PUT request
216
- */
217
- async put(requestUrl, body) {
218
- return this.request("PUT", requestUrl, body);
219
- }
220
- /**
221
- * Make a DELETE request
222
- */
223
- async delete(requestUrl) {
224
- return this.request("DELETE", requestUrl);
225
- }
226
- /**
227
- * Make an HTTP request with retry logic
228
- */
229
- async request(method, requestUrl, body) {
230
- const headers = {
231
- "Content-Type": "application/json",
232
- Accept: "application/json",
233
- };
234
- if (this.config.apiKey) {
235
- headers["Authorization"] = "Bearer " + this.config.apiKey;
236
- }
237
- const buildInit = (signal) => {
238
- const init = {
239
- method,
240
- headers,
241
- signal,
242
- };
243
- if (body !== undefined) {
244
- init.body = JSON.stringify(body);
245
- }
246
- return init;
247
- };
248
- let lastError = null;
249
- for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
250
- const controller = new AbortController();
251
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);
252
- try {
253
- const response = await this.fetchFn(requestUrl, buildInit(controller.signal));
254
- return await this.handleResponse(response);
255
- }
256
- catch (e) {
257
- lastError = e instanceof Error ? e : new Error(String(e));
258
- // Don't retry on client errors (4xx)
259
- if (lastError instanceof ProximaDBError) {
260
- if (lastError.statusCode &&
261
- lastError.statusCode >= 400 &&
262
- lastError.statusCode < 500) {
263
- throw lastError;
264
- }
265
- }
266
- // Wait before retry with exponential backoff
267
- if (attempt < this.config.maxRetries) {
268
- const delay = Math.min(1000 * Math.pow(2, attempt), 10000);
269
- await new Promise((resolve) => setTimeout(resolve, delay));
270
- }
271
- }
272
- finally {
273
- clearTimeout(timeoutId);
274
- }
275
- }
276
- throw lastError ?? new Error("Request failed after retries");
277
- }
278
- /**
279
- * Handle HTTP response
280
- */
281
- async handleResponse(response) {
282
- if (response.ok) {
283
- try {
284
- return (await response.json());
285
- }
286
- catch {
287
- throw new ProximaDBError("Failed to parse response JSON", ErrorCode.ServerError, response.status);
288
- }
289
- }
290
- const statusCode = response.status;
291
- let message = response.statusText;
292
- try {
293
- message = await response.text();
294
- }
295
- catch {
296
- // Use statusText if text() fails
297
- }
298
- switch (statusCode) {
299
- case 401:
300
- throw new ProximaDBError(message, ErrorCode.AuthenticationFailed, statusCode);
301
- case 403:
302
- throw new ProximaDBError(message, ErrorCode.AuthorizationDenied, statusCode);
303
- case 404:
304
- throw new ProximaDBError(message, ErrorCode.CollectionNotFound, statusCode);
305
- case 409:
306
- throw new ProximaDBError(message, ErrorCode.CollectionExists, statusCode);
307
- case 429:
308
- throw new ProximaDBError(message, ErrorCode.RateLimited, statusCode);
309
- default:
310
- throw new ProximaDBError(message, ErrorCode.ServerError, statusCode);
311
- }
312
- }
313
- // =========================================================================
314
- // Collection Operations
315
- // =========================================================================
316
- /**
317
- * Get a handle to a collection for fluent operations
318
- */
319
- collection(name) {
320
- return new CollectionHandle(this, name);
321
- }
322
- /**
323
- * Create a collection builder
324
- */
325
- createCollection(name) {
326
- return new CollectionBuilder(this, name);
327
- }
328
- /**
329
- * Delete a collection
330
- *
331
- * Routed through the generated typed transport (TD-126 Phase 4).
332
- * Wire endpoint: DELETE /api/v2/collections/{collection_id}
333
- * OpenAPI operationId: deleteCollection
334
- */
335
- async deleteCollection(name) {
336
- await this.gen.DELETE("/api/v2/collections/{collection_id}", {
337
- params: { path: { collection_id: name } },
338
- });
339
- }
340
- /**
341
- * List all collections
342
- *
343
- * Routed through the generated typed transport (TD-126 Phase 4).
344
- * Wire endpoint: GET /api/v2/collections
345
- * OpenAPI operationId: listCollections
346
- */
347
- async listCollections() {
348
- const { data } = await this.gen.GET("/api/v2/collections", {});
349
- return (data?.collections ?? []);
350
- }
351
- /**
352
- * Get the schema for a collection
353
- *
354
- * Routed through the generated typed transport (TD-126 Phase 4).
355
- * Wire endpoint: GET /api/v2/collections/{collection_id}/schema
356
- * OpenAPI operationId: getCollectionSchema
357
- */
358
- async getCollectionSchema(collectionId) {
359
- const { data } = await this.gen.GET("/api/v2/collections/{collection_id}/schema", { params: { path: { collection_id: collectionId } } });
360
- return data;
361
- }
362
- /**
363
- * Update the schema for a collection
364
- *
365
- * Routed through the generated typed transport (TD-126 Phase 4).
366
- * Wire endpoint: PUT /api/v2/collections/{collection_id}/schema
367
- * OpenAPI operationId: updateCollectionSchema
368
- */
369
- async updateCollectionSchema(collectionId, schema) {
370
- const { data } = await this.gen.PUT("/api/v2/collections/{collection_id}/schema", {
371
- params: { path: { collection_id: collectionId } },
372
- body: schema,
373
- });
374
- return data;
375
- }
376
- // =========================================================================
377
- // Query Facade (AQL / UQL)
378
- // =========================================================================
379
- /**
380
- * Execute an AQL or UQL query through the shared query facade
381
- *
382
- * Wire endpoint: POST /api/v2/query
383
- * OpenAPI operationId: executeQuery
384
- */
385
- async executeQuery(req) {
386
- const { data } = await this.gen.POST("/api/v2/query", {
387
- body: req,
388
- });
389
- return data;
390
- }
391
- /**
392
- * Explain an AQL or UQL query through the shared query facade
393
- *
394
- * Wire endpoint: POST /api/v2/query/explain
395
- * OpenAPI operationId: explainQuery
396
- */
397
- async explainQuery(req) {
398
- const { data } = await this.gen.POST("/api/v2/query/explain", {
399
- body: req,
400
- });
401
- return data;
402
- }
403
- // =========================================================================
404
- // Typed transport for core collection / record / search ops (TD-126 Phase 4)
405
- //
406
- // These route the builders' wire calls through the generated typed client.
407
- // The builders (collection.ts / search.ts) call these instead of hand-building
408
- // URL strings, so the core CRUD + search paths are spec-generated end to end.
409
- // =========================================================================
410
- /**
411
- * Create a collection.
412
- * Wire endpoint: POST /api/v2/collections (createCollection)
413
- */
414
- async createCollectionRequest(body) {
415
- const { data } = await this.gen.POST("/api/v2/collections", {
416
- body: body,
417
- });
418
- return data;
419
- }
420
- /**
421
- * Get collection details.
422
- * Wire endpoint: GET /api/v2/collections/{collection_id} (getCollection)
423
- */
424
- async getCollectionRequest(collectionId) {
425
- const { data } = await this.gen.GET("/api/v2/collections/{collection_id}", {
426
- params: { path: { collection_id: collectionId } },
427
- });
428
- return data;
429
- }
430
- /**
431
- * Insert / upsert records in a batch.
432
- * Wire endpoint: POST /api/v2/collections/{collection_id}/records/batch (insertRecords)
433
- */
434
- async insertRecordsRequest(collectionId, body) {
435
- const { data } = await this.gen.POST("/api/v2/collections/{collection_id}/records/batch", {
436
- params: { path: { collection_id: collectionId } },
437
- body: body,
438
- });
439
- return data;
440
- }
441
- /**
442
- * Get a single record by ID.
443
- * Wire endpoint: GET /api/v2/collections/{collection_id}/records/{record_id} (getRecord)
444
- */
445
- async getRecordRequest(collectionId, recordId, includeVector, includeText) {
446
- const { data } = await this.gen.GET("/api/v2/collections/{collection_id}/records/{record_id}", {
447
- params: {
448
- path: { collection_id: collectionId, record_id: recordId },
449
- query: { include_vector: includeVector, include_text: includeText },
450
- },
451
- });
452
- return data;
453
- }
454
- /**
455
- * Delete a single record by ID.
456
- * Wire endpoint: DELETE /api/v2/collections/{collection_id}/records/{record_id} (deleteRecord)
457
- */
458
- async deleteRecordRequest(collectionId, recordId) {
459
- await this.gen.DELETE("/api/v2/collections/{collection_id}/records/{record_id}", {
460
- params: { path: { collection_id: collectionId, record_id: recordId } },
461
- });
462
- }
463
- /**
464
- * Vector similarity search.
465
- * Wire endpoint: POST /api/v2/collections/{collection_id}/search (searchRecords)
466
- */
467
- async searchRecordsRequest(collectionId, body) {
468
- const { data } = await this.gen.POST("/api/v2/collections/{collection_id}/search", {
469
- params: { path: { collection_id: collectionId } },
470
- body: body,
471
- });
472
- return data;
473
- }
474
- // =========================================================================
475
- // Graph Operations
476
- // =========================================================================
477
- /**
478
- * Get a handle to a graph for fluent operations
479
- */
480
- graph(name) {
481
- return new GraphHandle(this, name);
482
- }
483
- /**
484
- * Create a graph builder.
485
- *
486
- * Wire endpoint: POST /api/v2/graphs
487
- * OpenAPI operationId: createGraph
488
- *
489
- * The argument is the server-true `graph_id` (unique identifier). Use
490
- * `.name(...)` on the returned builder to set the optional display name.
491
- */
492
- createGraph(graphId) {
493
- return new GraphBuilder(this, graphId);
494
- }
495
- /**
496
- * Delete a graph
497
- *
498
- * Routed through the generated typed transport (TD-126 Phase 4).
499
- * Wire endpoint: DELETE /api/v2/graphs/{graph_id}
500
- * OpenAPI operationId: deleteGraph
501
- */
502
- async deleteGraph(name) {
503
- await this.gen.DELETE("/api/v2/graphs/{graph_id}", {
504
- params: { path: { graph_id: name } },
505
- });
506
- }
507
- /**
508
- * List all graphs
509
- *
510
- * Routed through the generated typed transport (TD-126 Phase 4).
511
- * Wire endpoint: GET /api/v2/graphs
512
- * OpenAPI operationId: listGraphs
513
- */
514
- async listGraphs() {
515
- const { data } = await this.gen.GET("/api/v2/graphs", {});
516
- // Wave-6 envelope truth: the wire body is {success, data} — the
517
- // collection array rides `data.data` (the old flat `.graphs` field
518
- // never existed on the wire). A body without the envelope throws
519
- // rather than fabricating an empty list.
520
- return requireEnvelopeData(data, "listGraphs").map(graphInfoFromWire);
521
- }
522
- // =========================================================================
523
- // Typed transport for graph ops (TD-126 Phase 4)
524
- //
525
- // Seam methods routing the graph builders' / handle's wire calls through the
526
- // generated typed client, mirroring the core collection / record / search
527
- // seams above. The public graph API (graph.ts builders + handle) is
528
- // unchanged; only the wire dispatch moves off hand-built URL strings.
529
- // =========================================================================
530
- /**
531
- * Create a graph collection.
532
- * Wire endpoint: POST /api/v2/graphs (createGraph)
533
- */
534
- async createGraphRequest(body) {
535
- const { data } = await this.gen.POST("/api/v2/graphs", {
536
- body: body,
537
- });
538
- return data;
539
- }
540
- /**
541
- * Get a graph collection by id.
542
- * Wire endpoint: GET /api/v2/graphs/{graph_id} (getGraph)
543
- */
544
- async getGraphRequest(graphId) {
545
- const { data } = await this.gen.GET("/api/v2/graphs/{graph_id}", {
546
- params: { path: { graph_id: graphId } },
547
- });
548
- return graphInfoFromWire(requireEnvelopeData(data, "getGraph"));
549
- }
550
- /**
551
- * Get graph statistics.
552
- * Wire endpoint: GET /api/v2/graphs/{graph_id}/stats (getGraphStats)
553
- */
554
- async getGraphStatsRequest(graphId) {
555
- const { data } = await this.gen.GET("/api/v2/graphs/{graph_id}/stats", {
556
- params: { path: { graph_id: graphId } },
557
- });
558
- return data;
559
- }
560
- /**
561
- * Create a node in a graph.
562
- * Wire endpoint: POST /api/v2/graphs/{graph_id}/nodes (createNode)
563
- */
564
- async createNodeRequest(graphId, body) {
565
- const { data } = await this.gen.POST("/api/v2/graphs/{graph_id}/nodes", {
566
- params: { path: { graph_id: graphId } },
567
- body: body,
568
- });
569
- return data;
570
- }
571
- /**
572
- * Create multiple nodes in a single call.
573
- * Wire endpoint: POST /api/v2/graphs/{graph_id}/nodes/batch (batchCreateNodes)
574
- */
575
- async batchCreateNodesRequest(graphId, body) {
576
- const { data } = await this.gen.POST("/api/v2/graphs/{graph_id}/nodes/batch", {
577
- params: { path: { graph_id: graphId } },
578
- body: body,
579
- });
580
- return data;
581
- }
582
- /**
583
- * Get a node by id.
584
- * Wire endpoint: GET /api/v2/graphs/{graph_id}/nodes/{node_id} (getNode)
585
- */
586
- async getNodeRequest(graphId, nodeId) {
587
- const { data } = await this.gen.GET("/api/v2/graphs/{graph_id}/nodes/{node_id}", {
588
- params: { path: { graph_id: graphId, node_id: nodeId } },
589
- });
590
- return graphNodeFromWire(requireEnvelopeData(data, "getNode"));
591
- }
592
- /**
593
- * Delete a node by id.
594
- * Wire endpoint: DELETE /api/v2/graphs/{graph_id}/nodes/{node_id} (deleteNode)
595
- */
596
- async deleteNodeRequest(graphId, nodeId) {
597
- await this.gen.DELETE("/api/v2/graphs/{graph_id}/nodes/{node_id}", {
598
- params: { path: { graph_id: graphId, node_id: nodeId } },
599
- });
600
- }
601
- /**
602
- * Create an edge in a graph.
603
- * Wire endpoint: POST /api/v2/graphs/{graph_id}/edges (createEdge)
604
- */
605
- async createEdgeRequest(graphId, body) {
606
- const { data } = await this.gen.POST("/api/v2/graphs/{graph_id}/edges", {
607
- params: { path: { graph_id: graphId } },
608
- body: body,
609
- });
610
- return data;
611
- }
612
- /**
613
- * Create multiple edges in a single call.
614
- * Wire endpoint: POST /api/v2/graphs/{graph_id}/edges/batch (batchCreateEdges)
615
- */
616
- async batchCreateEdgesRequest(graphId, body) {
617
- const { data } = await this.gen.POST("/api/v2/graphs/{graph_id}/edges/batch", {
618
- params: { path: { graph_id: graphId } },
619
- body: body,
620
- });
621
- return data;
622
- }
623
- /**
624
- * Traverse a graph from a start node.
625
- * Wire endpoint: POST /api/v2/graphs/{graph_id}/traverse (traverseGraph)
626
- */
627
- async traverseGraphRequest(graphId, body) {
628
- const { data } = await this.gen.POST("/api/v2/graphs/{graph_id}/traverse", {
629
- params: { path: { graph_id: graphId } },
630
- body: body,
631
- });
632
- return traversalResultFromWire(requireEnvelopeData(data, "traverseGraph"));
633
- }
634
- // =========================================================================
635
- // Health and Monitoring
636
- // =========================================================================
637
- /**
638
- * Check if the server is healthy
639
- *
640
- * Routed through the generated typed transport (TD-126 Phase 4).
641
- * Wire endpoint: GET /health
642
- * OpenAPI operationId: getHealth
643
- */
644
- async health() {
645
- const { data } = await this.gen.GET("/health", {});
646
- return data;
647
- }
648
- /**
649
- * Kubernetes-style liveness probe
650
- *
651
- * Routed through the generated typed transport (TD-126 Phase 4).
652
- * Wire endpoint: GET /health/live
653
- * OpenAPI operationId: getLiveness
654
- */
655
- async healthLive() {
656
- const { data } = await this.gen.GET("/health/live", {});
657
- return data;
658
- }
659
- /**
660
- * Kubernetes-style readiness probe
661
- *
662
- * Routed through the generated typed transport (TD-126 Phase 4).
663
- * Wire endpoint: GET /health/ready
664
- * OpenAPI operationId: getReadiness
665
- */
666
- async healthReady() {
667
- const { data } = await this.gen.GET("/health/ready", {});
668
- return data;
669
- }
670
- /**
671
- * Check if the server is reachable
672
- */
673
- async ping() {
674
- try {
675
- await this.health();
676
- return true;
677
- }
678
- catch {
679
- return false;
680
- }
681
- }
682
- }
683
- // ============================================================================
684
- // CLIENT BUILDER
685
- // ============================================================================
686
- /**
687
- * Builder for creating a ProximaDB client with custom configuration
688
- */
689
- export class ClientBuilder {
690
- config = {};
691
- /**
692
- * Set the server URL
693
- */
694
- url(serverUrl) {
695
- this.config.url = serverUrl;
696
- return this;
697
- }
698
- /**
699
- * Set the request timeout in milliseconds
700
- */
701
- timeoutMs(timeout) {
702
- this.config.timeoutMs = timeout;
703
- return this;
704
- }
705
- /**
706
- * Set the maximum number of retries
707
- */
708
- maxRetries(retries) {
709
- this.config.maxRetries = retries;
710
- return this;
711
- }
712
- /**
713
- * Set the API key for authentication
714
- */
715
- apiKey(key) {
716
- this.config.apiKey = key;
717
- return this;
718
- }
719
- /**
720
- * Enable or disable connection pooling
721
- */
722
- poolConnections(enable) {
723
- this.config.poolConnections = enable;
724
- return this;
725
- }
726
- /**
727
- * Set maximum idle connections in pool
728
- */
729
- maxIdleConnections(max) {
730
- this.config.maxIdleConnections = max;
731
- return this;
732
- }
733
- /**
734
- * Build the ProximaDB client
735
- */
736
- build() {
737
- return new ProximaDBClient(this.config);
738
- }
739
- /**
740
- * Connect to the server (alias for build)
741
- */
742
- connect() {
743
- return this.build();
744
- }
745
- }
746
- // ============================================================================
747
- // CONVENIENCE FUNCTIONS
748
- // ============================================================================
749
- /**
750
- * Create a ProximaDB client connected to the given URL
751
- */
752
- export function connect(url = "http://localhost:5678") {
753
- return ProximaDBClient.connect(url);
754
- }
755
- /**
756
- * Create a ProximaDB client with REST protocol
757
- */
758
- export function connectRest(url = "http://localhost:5678") {
759
- return ProximaDBClient.connect(url);
760
- }
761
- //# sourceMappingURL=client.js.map