@soulcraft/brainy 5.7.4 → 5.7.5

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.
@@ -238,6 +238,11 @@ export class BaseStorage extends BaseStorageAdapter {
238
238
  if (Buffer.isBuffer(data)) {
239
239
  return data;
240
240
  }
241
+ // v5.7.5: Unwrap binary data stored as {_binary: true, data: "base64..."}
242
+ // Fixes "Blob integrity check failed" - hash must be calculated on original content
243
+ if (data._binary && typeof data.data === 'string') {
244
+ return Buffer.from(data.data, 'base64');
245
+ }
241
246
  return Buffer.from(JSON.stringify(data));
242
247
  }
243
248
  catch (error) {
@@ -84,6 +84,7 @@ export declare class BlobStorage {
84
84
  private stats;
85
85
  private zstdCompress?;
86
86
  private zstdDecompress?;
87
+ private compressionReady;
87
88
  private readonly CACHE_MAX_SIZE;
88
89
  private readonly MULTIPART_THRESHOLD;
89
90
  private readonly COMPRESSION_THRESHOLD;
@@ -96,6 +97,11 @@ export declare class BlobStorage {
96
97
  * (Avoids loading if not needed)
97
98
  */
98
99
  private initCompression;
100
+ /**
101
+ * v5.7.5: Ensure compression is ready before write operations
102
+ * Fixes race condition where write happens before async compression init completes
103
+ */
104
+ private ensureCompressionReady;
99
105
  /**
100
106
  * Compute SHA-256 hash of data
101
107
  *
@@ -29,6 +29,7 @@ import { NULL_HASH, isNullHash } from './constants.js';
29
29
  */
30
30
  export class BlobStorage {
31
31
  constructor(adapter, options) {
32
+ this.compressionReady = false;
32
33
  // Configuration
33
34
  this.CACHE_MAX_SIZE = 100 * 1024 * 1024; // 100MB default
34
35
  this.MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5MB
@@ -74,6 +75,16 @@ export class BlobStorage {
74
75
  this.zstdDecompress = undefined;
75
76
  }
76
77
  }
78
+ /**
79
+ * v5.7.5: Ensure compression is ready before write operations
80
+ * Fixes race condition where write happens before async compression init completes
81
+ */
82
+ async ensureCompressionReady() {
83
+ if (this.compressionReady)
84
+ return;
85
+ await this.initCompression();
86
+ this.compressionReady = true;
87
+ }
77
88
  /**
78
89
  * Compute SHA-256 hash of data
79
90
  *
@@ -107,6 +118,9 @@ export class BlobStorage {
107
118
  this.stats.dedupSavings += data.length;
108
119
  return hash;
109
120
  }
121
+ // v5.7.5: Ensure compression is initialized before writing
122
+ // Fixes race condition where write happens before async init completes
123
+ await this.ensureCompressionReady();
110
124
  // Determine compression strategy
111
125
  const compression = this.selectCompression(data, options);
112
126
  // Compress if needed
@@ -117,11 +131,14 @@ export class BlobStorage {
117
131
  compressedSize = finalData.length;
118
132
  }
119
133
  // Create metadata
134
+ // v5.7.5: Store ACTUAL compression state, not intended
135
+ // Prevents corruption if compression failed to initialize
136
+ const actualCompression = finalData === data ? 'none' : compression;
120
137
  const metadata = {
121
138
  hash,
122
139
  size: data.length,
123
140
  compressedSize,
124
- compression,
141
+ compression: actualCompression,
125
142
  type: options.type || 'blob', // CRITICAL FIX: Use 'blob' default to match storage prefix
126
143
  createdAt: Date.now(),
127
144
  refCount: 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "5.7.4",
3
+ "version": "5.7.5",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. Stage 3 CANONICAL: 42 nouns × 127 verbs covering 96-97% of all human knowledge.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",