wolbarg 0.5.6 → 0.5.7

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/dist/index.d.cts CHANGED
@@ -371,6 +371,10 @@ interface ConcurrencyConfig$1 {
371
371
  baseBackoffMs?: number;
372
372
  maxBackoffMs?: number;
373
373
  lockTimeoutMs?: number;
374
+ /** Total lock-wait + retry budget in ms. */
375
+ lockDeadlineMs?: number;
376
+ /** Use multi-process-oriented defaults when many OS processes share one DB file. */
377
+ multiProcess?: boolean;
374
378
  }
375
379
  /** Transparent embedding cache configuration. */
376
380
  interface EmbeddingCacheConfig {
@@ -2149,7 +2153,7 @@ interface WolbargOptionsBase {
2149
2153
  organization: string;
2150
2154
  /**
2151
2155
  * Storage provider instance or config.
2152
- * Prefer `database` in docs; `storage` remains fully supported.
2156
+ * Prefer `storage: sqlite(...)` / `postgres(...)` in docs; `database` remains supported.
2153
2157
  */
2154
2158
  storage?: StorageInput;
2155
2159
  /**
@@ -2896,10 +2900,6 @@ declare class GraphCheckpointNotSupportedError extends WolbargError {
2896
2900
  */
2897
2901
  declare function wrapOperationError(operation: string, error: unknown): WolbargError;
2898
2902
 
2899
- /**
2900
- * Public factory helpers for storage, telemetry, checkpoints, and graph providers (v0.5.5).
2901
- */
2902
-
2903
2903
  /**
2904
2904
  * Create a SQLite {@link StorageProvider} from a filesystem path or `:memory:`.
2905
2905
  *
@@ -2911,7 +2911,9 @@ declare function wrapOperationError(operation: string, error: unknown): WolbargE
2911
2911
  * wolbarg({ organization: "acme", storage: sqlite("./memory.db"), embedding: ... })
2912
2912
  * ```
2913
2913
  */
2914
- declare function sqlite(connectionString: string): StorageProvider;
2914
+ declare function sqlite(connectionString: string, options?: {
2915
+ concurrency?: ConcurrencyConfig$1;
2916
+ }): StorageProvider;
2915
2917
  /**
2916
2918
  * Create a SQLite storage **config object** (for `database` / `init` options).
2917
2919
  *
@@ -3046,6 +3048,16 @@ interface ConcurrencyConfig {
3046
3048
  maxBackoffMs?: number;
3047
3049
  /** SQLite busy_timeout pragma in ms. Default: 5000 */
3048
3050
  lockTimeoutMs?: number;
3051
+ /**
3052
+ * Hard ceiling for total lock-wait + retry budget in ms.
3053
+ * Default: lockTimeoutMs * (maxRetries + 1).
3054
+ */
3055
+ lockDeadlineMs?: number;
3056
+ /**
3057
+ * When true, use multi-process-oriented defaults (higher busy_timeout / retries)
3058
+ * unless the caller overrides individual fields.
3059
+ */
3060
+ multiProcess?: boolean;
3049
3061
  }
3050
3062
 
3051
3063
  /**
@@ -3082,6 +3094,20 @@ declare class SqliteStorageProvider implements StorageProvider {
3082
3094
  private transactionDepth;
3083
3095
  /** Incrementing counter for deterministic savepoint names. */
3084
3096
  private savepointCounter;
3097
+ /**
3098
+ * Serializes top-level write transactions on the single SQLite connection.
3099
+ * SQLite is single-writer; serializing in-process avoids SQLITE_BUSY churn
3100
+ * AND prevents interleaved BEGIN/SAVEPOINT state corruption when many async
3101
+ * callers share one connection (see "no such savepoint" class of bugs).
3102
+ */
3103
+ private readonly writeMutex;
3104
+ /**
3105
+ * Async-context flag: true while executing inside a top-level write
3106
+ * transaction held by this provider. Used so writes issued from within an
3107
+ * ambient transaction (e.g. compress()) join that ACID unit, WITHOUT
3108
+ * mistaking the coalescer's own flush window for an ambient transaction.
3109
+ */
3110
+ private readonly txContext;
3085
3111
  /** Hot in-process ANN for blob backend (sqlite-vec unavailable platforms). */
3086
3112
  private memoryIndex;
3087
3113
  private memoryIndexDirty;
@@ -3115,6 +3141,8 @@ declare class SqliteStorageProvider implements StorageProvider {
3115
3141
  setRetryLogger(fn: ((msg: string) => void) | null): void;
3116
3142
  /** Open the database, run migrations, and prepare statements. */
3117
3143
  open(): Promise<void>;
3144
+ /** Single open attempt — connect, apply pragmas, migrate, prepare. */
3145
+ private openOnce;
3118
3146
  /** Drain pending inserts, optimize, and close the SQLite connection. */
3119
3147
  close(): Promise<void>;
3120
3148
  /**
@@ -3320,6 +3348,8 @@ declare class PostgresStorageProvider implements StorageProvider {
3320
3348
  private insertFlushScheduled;
3321
3349
  private insertFlushTimer;
3322
3350
  private insertFlushInFlight;
3351
+ /** Per-provider TX context — never share across PostgresStorageProvider instances. */
3352
+ private readonly txStore;
3323
3353
  /**
3324
3354
  * @param options - Connection string, pool size, and durability flags.
3325
3355
  */
package/dist/index.d.ts CHANGED
@@ -371,6 +371,10 @@ interface ConcurrencyConfig$1 {
371
371
  baseBackoffMs?: number;
372
372
  maxBackoffMs?: number;
373
373
  lockTimeoutMs?: number;
374
+ /** Total lock-wait + retry budget in ms. */
375
+ lockDeadlineMs?: number;
376
+ /** Use multi-process-oriented defaults when many OS processes share one DB file. */
377
+ multiProcess?: boolean;
374
378
  }
375
379
  /** Transparent embedding cache configuration. */
376
380
  interface EmbeddingCacheConfig {
@@ -2149,7 +2153,7 @@ interface WolbargOptionsBase {
2149
2153
  organization: string;
2150
2154
  /**
2151
2155
  * Storage provider instance or config.
2152
- * Prefer `database` in docs; `storage` remains fully supported.
2156
+ * Prefer `storage: sqlite(...)` / `postgres(...)` in docs; `database` remains supported.
2153
2157
  */
2154
2158
  storage?: StorageInput;
2155
2159
  /**
@@ -2896,10 +2900,6 @@ declare class GraphCheckpointNotSupportedError extends WolbargError {
2896
2900
  */
2897
2901
  declare function wrapOperationError(operation: string, error: unknown): WolbargError;
2898
2902
 
2899
- /**
2900
- * Public factory helpers for storage, telemetry, checkpoints, and graph providers (v0.5.5).
2901
- */
2902
-
2903
2903
  /**
2904
2904
  * Create a SQLite {@link StorageProvider} from a filesystem path or `:memory:`.
2905
2905
  *
@@ -2911,7 +2911,9 @@ declare function wrapOperationError(operation: string, error: unknown): WolbargE
2911
2911
  * wolbarg({ organization: "acme", storage: sqlite("./memory.db"), embedding: ... })
2912
2912
  * ```
2913
2913
  */
2914
- declare function sqlite(connectionString: string): StorageProvider;
2914
+ declare function sqlite(connectionString: string, options?: {
2915
+ concurrency?: ConcurrencyConfig$1;
2916
+ }): StorageProvider;
2915
2917
  /**
2916
2918
  * Create a SQLite storage **config object** (for `database` / `init` options).
2917
2919
  *
@@ -3046,6 +3048,16 @@ interface ConcurrencyConfig {
3046
3048
  maxBackoffMs?: number;
3047
3049
  /** SQLite busy_timeout pragma in ms. Default: 5000 */
3048
3050
  lockTimeoutMs?: number;
3051
+ /**
3052
+ * Hard ceiling for total lock-wait + retry budget in ms.
3053
+ * Default: lockTimeoutMs * (maxRetries + 1).
3054
+ */
3055
+ lockDeadlineMs?: number;
3056
+ /**
3057
+ * When true, use multi-process-oriented defaults (higher busy_timeout / retries)
3058
+ * unless the caller overrides individual fields.
3059
+ */
3060
+ multiProcess?: boolean;
3049
3061
  }
3050
3062
 
3051
3063
  /**
@@ -3082,6 +3094,20 @@ declare class SqliteStorageProvider implements StorageProvider {
3082
3094
  private transactionDepth;
3083
3095
  /** Incrementing counter for deterministic savepoint names. */
3084
3096
  private savepointCounter;
3097
+ /**
3098
+ * Serializes top-level write transactions on the single SQLite connection.
3099
+ * SQLite is single-writer; serializing in-process avoids SQLITE_BUSY churn
3100
+ * AND prevents interleaved BEGIN/SAVEPOINT state corruption when many async
3101
+ * callers share one connection (see "no such savepoint" class of bugs).
3102
+ */
3103
+ private readonly writeMutex;
3104
+ /**
3105
+ * Async-context flag: true while executing inside a top-level write
3106
+ * transaction held by this provider. Used so writes issued from within an
3107
+ * ambient transaction (e.g. compress()) join that ACID unit, WITHOUT
3108
+ * mistaking the coalescer's own flush window for an ambient transaction.
3109
+ */
3110
+ private readonly txContext;
3085
3111
  /** Hot in-process ANN for blob backend (sqlite-vec unavailable platforms). */
3086
3112
  private memoryIndex;
3087
3113
  private memoryIndexDirty;
@@ -3115,6 +3141,8 @@ declare class SqliteStorageProvider implements StorageProvider {
3115
3141
  setRetryLogger(fn: ((msg: string) => void) | null): void;
3116
3142
  /** Open the database, run migrations, and prepare statements. */
3117
3143
  open(): Promise<void>;
3144
+ /** Single open attempt — connect, apply pragmas, migrate, prepare. */
3145
+ private openOnce;
3118
3146
  /** Drain pending inserts, optimize, and close the SQLite connection. */
3119
3147
  close(): Promise<void>;
3120
3148
  /**
@@ -3320,6 +3348,8 @@ declare class PostgresStorageProvider implements StorageProvider {
3320
3348
  private insertFlushScheduled;
3321
3349
  private insertFlushTimer;
3322
3350
  private insertFlushInFlight;
3351
+ /** Per-provider TX context — never share across PostgresStorageProvider instances. */
3352
+ private readonly txStore;
3323
3353
  /**
3324
3354
  * @param options - Connection string, pool size, and durability flags.
3325
3355
  */