sutradb-core 5.6.0 → 5.6.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/client.js +40 -19
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -7,7 +7,7 @@ Native `napi-rs` bindings for **SutraDB** (embedded Rust SIMD vector + BM25 + WA
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install sutradb-core
10
+ npm install sutradb-core@5.6.1
11
11
  ```
12
12
 
13
13
  ---
package/client.js CHANGED
@@ -31,13 +31,32 @@ function normalizeDocument(doc) {
31
31
  return out;
32
32
  }
33
33
 
34
+ function requirePathSegment(value, label) {
35
+ if (typeof value !== "string" || value.trim().length === 0) {
36
+ throw new SutraClientError(`${label} must be a non-empty string`);
37
+ }
38
+ return encodeURIComponent(value);
39
+ }
40
+
34
41
  class SutraClient {
35
42
  constructor(optionsOrUrl = "http://localhost:8765") {
36
43
  const opts =
37
44
  typeof optionsOrUrl === "string"
38
45
  ? { baseUrl: optionsOrUrl }
39
46
  : optionsOrUrl || {};
40
- this.baseUrl = (opts.baseUrl || "http://localhost:8765").replace(/\/+$/, "");
47
+ const rawBaseUrl = (opts.baseUrl || "http://localhost:8765").replace(/\/+$/, "");
48
+ let parsedUrl;
49
+ try {
50
+ parsedUrl = new URL(rawBaseUrl);
51
+ } catch {
52
+ throw new SutraClientError(`Invalid SutraDB baseUrl: ${rawBaseUrl}`);
53
+ }
54
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
55
+ throw new SutraClientError(
56
+ `Unsupported baseUrl protocol '${parsedUrl.protocol}'; expected http: or https:`
57
+ );
58
+ }
59
+ this.baseUrl = rawBaseUrl;
41
60
  this.apiKey = opts.apiKey;
42
61
  this.timeoutMs = typeof opts.timeoutMs === "number" ? opts.timeoutMs : 30000;
43
62
  this.defaultHeaders = Object.assign({}, opts.headers || {});
@@ -129,20 +148,20 @@ class SutraClient {
129
148
  }
130
149
 
131
150
  async dropCollection(name) {
132
- return this._request("DELETE", `/collections/${encodeURIComponent(name)}`);
151
+ return this._request("DELETE", `/collections/${requirePathSegment(name, "collection")}`);
133
152
  }
134
153
 
135
154
  async stats(collection) {
136
155
  return this._request(
137
156
  "GET",
138
- `/collections/${encodeURIComponent(collection)}/stats`
157
+ `/collections/${requirePathSegment(collection, "collection")}/stats`
139
158
  );
140
159
  }
141
160
 
142
161
  async insert(collection, documents) {
143
162
  return this._request(
144
163
  "POST",
145
- `/collections/${encodeURIComponent(collection)}/insert`,
164
+ `/collections/${requirePathSegment(collection, "collection")}/insert`,
146
165
  { documents: documents.map(normalizeDocument) }
147
166
  );
148
167
  }
@@ -150,7 +169,7 @@ class SutraClient {
150
169
  async upsert(collection, documents) {
151
170
  return this._request(
152
171
  "POST",
153
- `/collections/${encodeURIComponent(collection)}/upsert`,
172
+ `/collections/${requirePathSegment(collection, "collection")}/upsert`,
154
173
  { documents: documents.map(normalizeDocument) }
155
174
  );
156
175
  }
@@ -159,8 +178,9 @@ class SutraClient {
159
178
  try {
160
179
  return await this._request(
161
180
  "GET",
162
- `/collections/${encodeURIComponent(collection)}/documents/${encodeURIComponent(
163
- docId
181
+ `/collections/${requirePathSegment(collection, "collection")}/documents/${requirePathSegment(
182
+ docId,
183
+ "docId"
164
184
  )}`
165
185
  );
166
186
  } catch (err) {
@@ -181,15 +201,16 @@ class SutraClient {
181
201
  const suffix = qs ? `?${qs}` : "";
182
202
  return this._request(
183
203
  "GET",
184
- `/collections/${encodeURIComponent(collection)}/documents${suffix}`
204
+ `/collections/${requirePathSegment(collection, "collection")}/documents${suffix}`
185
205
  );
186
206
  }
187
207
 
188
208
  async updateMetadata(collection, docId, metadata) {
189
209
  return this._request(
190
210
  "PATCH",
191
- `/collections/${encodeURIComponent(collection)}/documents/${encodeURIComponent(
192
- docId
211
+ `/collections/${requirePathSegment(collection, "collection")}/documents/${requirePathSegment(
212
+ docId,
213
+ "docId"
193
214
  )}/metadata`,
194
215
  { metadata }
195
216
  );
@@ -199,7 +220,7 @@ class SutraClient {
199
220
  const idList = Array.isArray(ids) ? ids : [ids];
200
221
  return this._request(
201
222
  "DELETE",
202
- `/collections/${encodeURIComponent(collection)}/documents`,
223
+ `/collections/${requirePathSegment(collection, "collection")}/documents`,
203
224
  { ids: idList }
204
225
  );
205
226
  }
@@ -241,7 +262,7 @@ class SutraClient {
241
262
 
242
263
  const data = await this._request(
243
264
  "POST",
244
- `/collections/${encodeURIComponent(collection)}/query`,
265
+ `/collections/${requirePathSegment(collection, "collection")}/query`,
245
266
  payload
246
267
  );
247
268
  const raw = (data && data.results) || [];
@@ -261,7 +282,7 @@ class SutraClient {
261
282
  async buildHnsw(collection, options = {}) {
262
283
  return this._request(
263
284
  "POST",
264
- `/collections/${encodeURIComponent(collection)}/hnsw`,
285
+ `/collections/${requirePathSegment(collection, "collection")}/hnsw`,
265
286
  {
266
287
  m: options.m ?? 16,
267
288
  ef_construction: options.efConstruction ?? 200,
@@ -273,7 +294,7 @@ class SutraClient {
273
294
  async enableBq(collection) {
274
295
  return this._request(
275
296
  "POST",
276
- `/collections/${encodeURIComponent(collection)}/bq`,
297
+ `/collections/${requirePathSegment(collection, "collection")}/bq`,
277
298
  {}
278
299
  );
279
300
  }
@@ -281,7 +302,7 @@ class SutraClient {
281
302
  async enableSq8(collection) {
282
303
  return this._request(
283
304
  "POST",
284
- `/collections/${encodeURIComponent(collection)}/sq8`,
305
+ `/collections/${requirePathSegment(collection, "collection")}/sq8`,
285
306
  {}
286
307
  );
287
308
  }
@@ -289,7 +310,7 @@ class SutraClient {
289
310
  async trainPq(collection, options = {}) {
290
311
  return this._request(
291
312
  "POST",
292
- `/collections/${encodeURIComponent(collection)}/pq/train`,
313
+ `/collections/${requirePathSegment(collection, "collection")}/pq/train`,
293
314
  {
294
315
  m: options.m ?? null,
295
316
  max_samples: options.maxSamples ?? null,
@@ -300,7 +321,7 @@ class SutraClient {
300
321
  async enablePq(collection) {
301
322
  return this._request(
302
323
  "POST",
303
- `/collections/${encodeURIComponent(collection)}/pq`,
324
+ `/collections/${requirePathSegment(collection, "collection")}/pq`,
304
325
  {}
305
326
  );
306
327
  }
@@ -308,7 +329,7 @@ class SutraClient {
308
329
  async compact(collection) {
309
330
  return this._request(
310
331
  "POST",
311
- `/collections/${encodeURIComponent(collection)}/compact`,
332
+ `/collections/${requirePathSegment(collection, "collection")}/compact`,
312
333
  {}
313
334
  );
314
335
  }
@@ -316,7 +337,7 @@ class SutraClient {
316
337
  async save(collection) {
317
338
  return this._request(
318
339
  "POST",
319
- `/collections/${encodeURIComponent(collection)}/save`,
340
+ `/collections/${requirePathSegment(collection, "collection")}/save`,
320
341
  {}
321
342
  );
322
343
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sutradb-core",
3
- "version": "5.6.0",
3
+ "version": "5.6.1",
4
4
  "description": "Embedded Rust + Node.js hybrid vector database (HNSW, BM25, WAND sparse, ColBERT) with zero-copy Float32Array SIMD, 32x BQ, and sub-ms Roaring filtering, plus zero-dependency SutraClient.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -81,10 +81,10 @@
81
81
  "@napi-rs/cli": "^2.18.4"
82
82
  },
83
83
  "optionalDependencies": {
84
- "sutradb-core-darwin-arm64": "5.6.0",
85
- "sutradb-core-darwin-x64": "5.6.0",
86
- "sutradb-core-linux-arm64-gnu": "5.6.0",
87
- "sutradb-core-linux-x64-gnu": "5.6.0",
88
- "sutradb-core-win32-x64-msvc": "5.6.0"
84
+ "sutradb-core-darwin-arm64": "5.6.1",
85
+ "sutradb-core-darwin-x64": "5.6.1",
86
+ "sutradb-core-linux-arm64-gnu": "5.6.1",
87
+ "sutradb-core-linux-x64-gnu": "5.6.1",
88
+ "sutradb-core-win32-x64-msvc": "5.6.1"
89
89
  }
90
90
  }