@dooor-ai/cortexdb 0.1.2 → 0.2.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
@@ -96,24 +96,32 @@ main();
96
96
  ```typescript
97
97
  import { CortexClient } from '@dooor-ai/cortexdb';
98
98
 
99
- // Local development
100
- const client = new CortexClient({
101
- baseUrl: 'http://localhost:8000'
102
- });
99
+ // Using connection string (recommended)
100
+ const client = new CortexClient('cortexdb://localhost:8000');
103
101
 
104
- // Production with API key
105
- const client = new CortexClient({
106
- baseUrl: 'https://api.cortexdb.com',
107
- apiKey: 'your-api-key'
108
- });
102
+ // With API key
103
+ const client = new CortexClient('cortexdb://my-api-key@localhost:8000');
109
104
 
110
- // Custom timeout
105
+ // Production (HTTPS auto-detected)
106
+ const client = new CortexClient('cortexdb://my-key@api.cortexdb.com');
107
+
108
+ // Using options object (alternative)
111
109
  const client = new CortexClient({
112
110
  baseUrl: 'http://localhost:8000',
111
+ apiKey: 'your-api-key',
113
112
  timeout: 60000 // 60 seconds
114
113
  });
115
114
  ```
116
115
 
116
+ **Connection String Format:**
117
+ `cortexdb://[api_key@]host[:port]`
118
+
119
+ Benefits:
120
+ - Single string configuration
121
+ - Easy to store in environment variables
122
+ - Familiar pattern (like PostgreSQL, MongoDB, Redis)
123
+ - Auto-detects HTTP vs HTTPS
124
+
117
125
  ### Collections
118
126
 
119
127
  Collections define the schema for your data. Each collection can have multiple fields with different types and storage options.
@@ -10,7 +10,24 @@ export declare class CortexClient {
10
10
  private http;
11
11
  collections: CollectionsAPI;
12
12
  records: RecordsAPI;
13
- constructor(options?: CortexClientOptions);
13
+ /**
14
+ * Create a new CortexDB client
15
+ *
16
+ * @param options - Configuration options or connection string
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Using options object
21
+ * const client = new CortexClient({
22
+ * baseUrl: 'http://localhost:8000',
23
+ * apiKey: 'my-key'
24
+ * });
25
+ *
26
+ * // Using connection string
27
+ * const client = new CortexClient('cortexdb://my-key@localhost:8000');
28
+ * ```
29
+ */
30
+ constructor(options?: CortexClientOptions | string);
14
31
  /**
15
32
  * Check if the connection to CortexDB is working
16
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAa;IAClB,WAAW,EAAE,cAAc,CAAC;IAC5B,OAAO,EAAE,UAAU,CAAC;gBAEf,OAAO,GAAE,mBAAwB;IAY7C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAa;IAClB,WAAW,EAAE,cAAc,CAAC;IAC5B,OAAO,EAAE,UAAU,CAAC;IAE3B;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,GAAE,mBAAmB,GAAG,MAAW;IAuBtD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -5,9 +5,42 @@ exports.CortexClient = void 0;
5
5
  const client_1 = require("../http/client");
6
6
  const api_1 = require("../collections/api");
7
7
  const api_2 = require("../records/api");
8
+ const connection_string_1 = require("../utils/connection-string");
8
9
  class CortexClient {
10
+ /**
11
+ * Create a new CortexDB client
12
+ *
13
+ * @param options - Configuration options or connection string
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Using options object
18
+ * const client = new CortexClient({
19
+ * baseUrl: 'http://localhost:8000',
20
+ * apiKey: 'my-key'
21
+ * });
22
+ *
23
+ * // Using connection string
24
+ * const client = new CortexClient('cortexdb://my-key@localhost:8000');
25
+ * ```
26
+ */
9
27
  constructor(options = {}) {
10
- const { baseUrl = "http://localhost:8000", apiKey, timeout = 30000, } = options;
28
+ let baseUrl;
29
+ let apiKey;
30
+ let timeout;
31
+ // Handle connection string
32
+ if (typeof options === 'string') {
33
+ const parsed = (0, connection_string_1.parseConnectionString)(options);
34
+ baseUrl = parsed.baseUrl;
35
+ apiKey = parsed.apiKey;
36
+ timeout = 30000;
37
+ }
38
+ else {
39
+ // Handle options object
40
+ baseUrl = options.baseUrl || "http://localhost:8000";
41
+ apiKey = options.apiKey;
42
+ timeout = options.timeout || 30000;
43
+ }
11
44
  this.http = new client_1.HTTPClient(baseUrl, apiKey, timeout);
12
45
  this.collections = new api_1.CollectionsAPI(this.http);
13
46
  this.records = new api_2.RecordsAPI(this.http);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names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ortexdb://localhost:8000
8
+ * - cortexdb://my_key@localhost:8000
9
+ * - cortexdb://my_key@api.cortexdb.com
10
+ */
11
+ export interface ParsedConnection {
12
+ baseUrl: string;
13
+ apiKey?: string;
14
+ }
15
+ /**
16
+ * Parse a CortexDB connection string
17
+ *
18
+ * @param connectionString - Connection string in format cortexdb://[api_key@]host[:port]
19
+ * @returns Parsed connection options
20
+ * @throws Error if connection string is invalid
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * parseConnectionString('cortexdb://localhost:8000')
25
+ * // { baseUrl: 'http://localhost:8000' }
26
+ *
27
+ * parseConnectionString('cortexdb://my_key@localhost:8000')
28
+ * // { baseUrl: 'http://localhost:8000', apiKey: 'my_key' }
29
+ *
30
+ * parseConnectionString('cortexdb://key@api.cortexdb.com:443')
31
+ * // { baseUrl: 'https://api.cortexdb.com:443', apiKey: 'key' }
32
+ * ```
33
+ */
34
+ export declare function parseConnectionString(connectionString: string): ParsedConnection;
35
+ //# sourceMappingURL=connection-string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-string.d.ts","sourceRoot":"","sources":["../../src/utils/connection-string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,CAoDhF"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Parse CortexDB connection strings
4
+ *
5
+ * Format: cortexdb://[api_key@]host[:port]
6
+ *
7
+ * Examples:
8
+ * - cortexdb://localhost:8000
9
+ * - cortexdb://my_key@localhost:8000
10
+ * - cortexdb://my_key@api.cortexdb.com
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.parseConnectionString = parseConnectionString;
14
+ /**
15
+ * Parse a CortexDB connection string
16
+ *
17
+ * @param connectionString - Connection string in format cortexdb://[api_key@]host[:port]
18
+ * @returns Parsed connection options
19
+ * @throws Error if connection string is invalid
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * parseConnectionString('cortexdb://localhost:8000')
24
+ * // { baseUrl: 'http://localhost:8000' }
25
+ *
26
+ * parseConnectionString('cortexdb://my_key@localhost:8000')
27
+ * // { baseUrl: 'http://localhost:8000', apiKey: 'my_key' }
28
+ *
29
+ * parseConnectionString('cortexdb://key@api.cortexdb.com:443')
30
+ * // { baseUrl: 'https://api.cortexdb.com:443', apiKey: 'key' }
31
+ * ```
32
+ */
33
+ function parseConnectionString(connectionString) {
34
+ // Remove cortexdb:// prefix
35
+ if (!connectionString.startsWith('cortexdb://')) {
36
+ throw new Error('Connection string must start with "cortexdb://"');
37
+ }
38
+ const withoutProtocol = connectionString.slice('cortexdb://'.length);
39
+ // Split by @ to separate api_key from host
40
+ let apiKey;
41
+ let hostPart;
42
+ if (withoutProtocol.includes('@')) {
43
+ const parts = withoutProtocol.split('@');
44
+ if (parts.length !== 2) {
45
+ throw new Error('Invalid connection string format');
46
+ }
47
+ apiKey = parts[0];
48
+ hostPart = parts[1];
49
+ }
50
+ else {
51
+ hostPart = withoutProtocol;
52
+ }
53
+ // Parse host and port
54
+ let host;
55
+ let port;
56
+ if (hostPart.includes(':')) {
57
+ const hostPortParts = hostPart.split(':');
58
+ host = hostPortParts[0];
59
+ port = hostPortParts[1];
60
+ }
61
+ else {
62
+ host = hostPart;
63
+ }
64
+ // Determine protocol (https for port 443 or production domains, http otherwise)
65
+ const isSecure = port === '443' ||
66
+ host.includes('cortexdb.com') ||
67
+ (!host.includes('localhost') && !host.startsWith('127.'));
68
+ const protocol = isSecure ? 'https' : 'http';
69
+ // Build base URL
70
+ let baseUrl = `${protocol}://${host}`;
71
+ if (port && !(port === '443' && isSecure) && !(port === '80' && !isSecure)) {
72
+ baseUrl += `:${port}`;
73
+ }
74
+ return {
75
+ baseUrl,
76
+ apiKey
77
+ };
78
+ }
79
+ //# sourceMappingURL=connection-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-string.js","sourceRoot":"","sources":["../../src/utils/connection-string.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA0BH,sDAoDC;AAvED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,qBAAqB,CAAC,gBAAwB;IAC5D,4BAA4B;IAC5B,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,eAAe,GAAG,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAErE,2CAA2C;IAC3C,IAAI,MAA0B,CAAC;IAC/B,IAAI,QAAgB,CAAC;IAErB,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,eAAe,CAAC;IAC7B,CAAC;IAED,sBAAsB;IACtB,IAAI,IAAY,CAAC;IACjB,IAAI,IAAwB,CAAC;IAE7B,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,QAAQ,CAAC;IAClB,CAAC;IAED,gFAAgF;IAChF,MAAM,QAAQ,GAAG,IAAI,KAAK,KAAK;QACd,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;QAC7B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3E,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAE7C,iBAAiB;IACjB,IAAI,OAAO,GAAG,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;IACtC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3E,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACL,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooor-ai/cortexdb",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Official TypeScript/JavaScript SDK for CortexDB - Multi-modal RAG Platform with advanced document processing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",