@soulcraft/brainy 5.3.2 → 5.3.3

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.
@@ -132,10 +132,12 @@ export class BlobStorage {
132
132
  }
133
133
  else {
134
134
  // Small blob: single write
135
- await this.adapter.put(`blob:${hash}`, finalData);
135
+ const prefix = options.type || 'blob';
136
+ await this.adapter.put(`${prefix}:${hash}`, finalData);
136
137
  }
137
138
  // Write metadata
138
- await this.adapter.put(`blob-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
139
+ const prefix = options.type || 'blob';
140
+ await this.adapter.put(`${prefix}-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
139
141
  // Update cache (write-through)
140
142
  this.addToCache(hash, data, metadata);
141
143
  // Update stats
@@ -169,17 +171,27 @@ export class BlobStorage {
169
171
  }
170
172
  this.stats.cacheMisses++;
171
173
  }
172
- // Read from storage
173
- const data = await this.adapter.get(`blob:${hash}`);
174
- if (!data) {
175
- throw new Error(`Blob not found: ${hash}`);
174
+ // Try to read metadata to determine type (for backward compatibility)
175
+ // Try commit, tree, then blob prefixes
176
+ let prefix = null;
177
+ let metadataBuffer;
178
+ let metadata;
179
+ for (const tryPrefix of ['commit', 'tree', 'blob']) {
180
+ metadataBuffer = await this.adapter.get(`${tryPrefix}-meta:${hash}`);
181
+ if (metadataBuffer) {
182
+ prefix = tryPrefix;
183
+ metadata = JSON.parse(metadataBuffer.toString());
184
+ break;
185
+ }
176
186
  }
177
- // Read metadata
178
- const metadataBuffer = await this.adapter.get(`blob-meta:${hash}`);
179
- if (!metadataBuffer) {
187
+ if (!prefix || !metadata) {
180
188
  throw new Error(`Blob metadata not found: ${hash}`);
181
189
  }
182
- const metadata = JSON.parse(metadataBuffer.toString());
190
+ // Read from storage using determined prefix
191
+ const data = await this.adapter.get(`${prefix}:${hash}`);
192
+ if (!data) {
193
+ throw new Error(`Blob not found: ${hash}`);
194
+ }
183
195
  // Decompress if needed
184
196
  let finalData = data;
185
197
  if (metadata.compression === 'zstd' && !options.skipDecompression) {
@@ -209,9 +221,14 @@ export class BlobStorage {
209
221
  if (this.cache.has(hash)) {
210
222
  return true;
211
223
  }
212
- // Check storage
213
- const exists = await this.adapter.get(`blob:${hash}`);
214
- return exists !== undefined;
224
+ // Check storage - try all prefixes for backward compatibility
225
+ for (const prefix of ['commit', 'tree', 'blob']) {
226
+ const exists = await this.adapter.get(`${prefix}:${hash}`);
227
+ if (exists !== undefined) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
215
232
  }
216
233
  /**
217
234
  * Delete a blob from storage
@@ -230,10 +247,19 @@ export class BlobStorage {
230
247
  if (refCount > 0) {
231
248
  return;
232
249
  }
250
+ // Determine prefix by checking which one exists
251
+ let prefix = 'blob';
252
+ for (const tryPrefix of ['commit', 'tree', 'blob']) {
253
+ const exists = await this.adapter.get(`${tryPrefix}:${hash}`);
254
+ if (exists !== undefined) {
255
+ prefix = tryPrefix;
256
+ break;
257
+ }
258
+ }
233
259
  // Delete blob data
234
- await this.adapter.delete(`blob:${hash}`);
260
+ await this.adapter.delete(`${prefix}:${hash}`);
235
261
  // Delete metadata
236
- await this.adapter.delete(`blob-meta:${hash}`);
262
+ await this.adapter.delete(`${prefix}-meta:${hash}`);
237
263
  // Remove from cache
238
264
  this.removeFromCache(hash);
239
265
  // Update stats
@@ -246,11 +272,15 @@ export class BlobStorage {
246
272
  * @returns Blob metadata
247
273
  */
248
274
  async getMetadata(hash) {
249
- const data = await this.adapter.get(`blob-meta:${hash}`);
250
- if (!data) {
251
- return undefined;
275
+ // Try to read metadata with type-aware prefix (backward compatible)
276
+ // Try commit, tree, then blob prefixes
277
+ for (const prefix of ['commit', 'tree', 'blob']) {
278
+ const data = await this.adapter.get(`${prefix}-meta:${hash}`);
279
+ if (data) {
280
+ return JSON.parse(data.toString());
281
+ }
252
282
  }
253
- return JSON.parse(data.toString());
283
+ return undefined;
254
284
  }
255
285
  /**
256
286
  * Batch write multiple blobs in parallel
@@ -277,8 +307,16 @@ export class BlobStorage {
277
307
  * @returns Array of blob hashes
278
308
  */
279
309
  async listBlobs() {
280
- const keys = await this.adapter.list('blob:');
281
- return keys.map((key) => key.replace(/^blob:/, ''));
310
+ // List all types of blobs
311
+ const hashes = new Set();
312
+ for (const prefix of ['commit', 'tree', 'blob']) {
313
+ const keys = await this.adapter.list(`${prefix}:`);
314
+ keys.forEach((key) => {
315
+ const hash = key.replace(new RegExp(`^${prefix}:`), '');
316
+ hashes.add(hash);
317
+ });
318
+ }
319
+ return Array.from(hashes);
282
320
  }
283
321
  /**
284
322
  * Get storage statistics
@@ -349,7 +387,8 @@ export class BlobStorage {
349
387
  async writeMultipart(hash, data, metadata) {
350
388
  // For now, just write as single blob
351
389
  // TODO: Implement actual multipart upload for S3/R2/GCS
352
- await this.adapter.put(`blob:${hash}`, data);
390
+ const prefix = metadata.type || 'blob';
391
+ await this.adapter.put(`${prefix}:${hash}`, data);
353
392
  }
354
393
  /**
355
394
  * Increment reference count for a blob
@@ -360,7 +399,8 @@ export class BlobStorage {
360
399
  throw new Error(`Cannot increment ref count, blob not found: ${hash}`);
361
400
  }
362
401
  metadata.refCount++;
363
- await this.adapter.put(`blob-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
402
+ const prefix = metadata.type || 'blob';
403
+ await this.adapter.put(`${prefix}-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
364
404
  return metadata.refCount;
365
405
  }
366
406
  /**
@@ -372,7 +412,8 @@ export class BlobStorage {
372
412
  return 0;
373
413
  }
374
414
  metadata.refCount = Math.max(0, metadata.refCount - 1);
375
- await this.adapter.put(`blob-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
415
+ const prefix = metadata.type || 'blob';
416
+ await this.adapter.put(`${prefix}-meta:${hash}`, Buffer.from(JSON.stringify(metadata)));
376
417
  return metadata.refCount;
377
418
  }
378
419
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "5.3.2",
3
+ "version": "5.3.3",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",