monsqlize 2.0.6 → 3.0.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.
@@ -1,4 +1,5 @@
1
1
  import type { LoggerLike } from './base.mjs';
2
+ import type { SchemaDslRuntime, SchemaDslRuntimeOptions } from 'schema-dsl/runtime';
2
3
 
3
4
  /**
4
5
  * SSH tunnel configuration for connecting through a bastion host.
@@ -31,7 +32,8 @@ export interface SSHConfig {
31
32
  localPort?: number;
32
33
  }
33
34
 
34
- import type { Collection, DbAccessor, HealthView } from './collection.mjs';
35
+ import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection.mjs';
36
+ import type { DataTaskJobError } from './data-tasks.mjs';
35
37
  import type { Lock, LockOptions, LockStats } from './lock.mjs';
36
38
  import type { ModelAutoIndexOptions, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model.mjs';
37
39
  import type { MongoConnectConfig } from './mongodb.mjs';
@@ -68,6 +70,61 @@ import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, Sl
68
70
  import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync.mjs';
69
71
  import type { Transaction, TransactionOptions, TransactionStats } from './transaction.mjs';
70
72
 
73
+ /** Write path policy mode. `allow-both` preserves the existing collection and model write behavior. */
74
+ export type WritePathPolicyMode = 'allow-both' | 'model-only';
75
+
76
+ /** Controls whether native raw access is available under a write path policy. */
77
+ export type WritePathPolicyRawMode = 'inherit' | 'allow' | 'block';
78
+
79
+ /** Controls whether collection/database management writes are available under a write path policy. */
80
+ export type WritePathPolicyManagementMode = 'inherit' | 'allow' | 'block';
81
+
82
+ /** Controls violation handling; `warn` logs and allows for migration observation. */
83
+ export type WritePathPolicyViolationAction = 'throw' | 'warn';
84
+
85
+ /** Per-namespace write path policy rule. */
86
+ export interface WritePathPolicyRule {
87
+ /** Write policy mode. Default: `allow-both`. */
88
+ mode?: WritePathPolicyMode;
89
+ /** Raw native access policy. `inherit` allows in `allow-both` and blocks in `model-only`. */
90
+ raw?: WritePathPolicyRawMode;
91
+ /** Management write policy. `inherit` allows model management and blocks external management in `model-only`. */
92
+ management?: WritePathPolicyManagementMode;
93
+ /** Violation action. Default: `throw`. */
94
+ onViolation?: WritePathPolicyViolationAction;
95
+ }
96
+
97
+ /** Runtime write path policy configuration. */
98
+ export interface WritePathPolicyOptions {
99
+ /**
100
+ * Default rule applied when no namespace override matches.
101
+ * Omit this option to preserve existing behavior (`allow-both`).
102
+ */
103
+ default?: WritePathPolicyMode | WritePathPolicyRule;
104
+ /**
105
+ * Namespace overrides matched in this order: `iid`, `pool:db.collection`,
106
+ * `db.collection`, then `collection`.
107
+ */
108
+ namespaces?: Record<string, WritePathPolicyMode | WritePathPolicyRule>;
109
+ }
110
+
111
+ export type MonSQLizeSchemaDslRuntime = Pick<
112
+ SchemaDslRuntime,
113
+ 's' | 'dsl' | 'validate' | 'registerExtensions' | 'dispose'
114
+ >;
115
+
116
+ /** schema-dsl runtime integration. Omit to let monSQLize create one isolated runtime per MonSQLize instance. */
117
+ export interface SchemaDslRuntimeConfig {
118
+ /** Disable model schema-dsl compilation and validation when false. Default: true. */
119
+ enabled?: boolean;
120
+ /** Existing schema-dsl runtime instance. monSQLize will use it but will not dispose it. */
121
+ runtime?: MonSQLizeSchemaDslRuntime;
122
+ /** Options passed to `createRuntime()` when monSQLize owns the runtime. */
123
+ options?: SchemaDslRuntimeOptions;
124
+ /** Extension definitions registered on the selected runtime before model schema compilation. */
125
+ extensions?: readonly unknown[];
126
+ }
127
+
71
128
  export interface MonSQLizeOptions {
72
129
  type?: 'mongodb';
73
130
  databaseName?: string;
@@ -82,7 +139,7 @@ export interface MonSQLizeOptions {
82
139
  * - A plain config object. Recognised fields:
83
140
  * `maxEntries` / `maxSize` (v1 alias), `maxMemory`, `defaultTtl` / `ttl` (v1 alias),
84
141
  * `enableStats`, `enableTags`, `cleanupInterval`, `enabled`,
85
- * `autoInvalidate` (v1 alias for `cacheAutoInvalidate`)
142
+ * `autoInvalidate` (broad write invalidation, disabled by default)
86
143
  */
87
144
  cache?: CacheLike | MemoryCache | MultiLevelCacheOptions | {
88
145
  /** Maximum number of entries; v2 name. Alias: maxSize (v1). */
@@ -103,20 +160,24 @@ export interface MonSQLizeOptions {
103
160
  cleanupInterval?: number;
104
161
  /** Disable cache entirely when false. Default: true. */
105
162
  enabled?: boolean;
106
- /** @deprecated Use top-level `cacheAutoInvalidate`. v1 alias: auto-invalidate on writes. */
163
+ /** Broadly invalidate collection query caches after successful writes. Default: false. */
107
164
  autoInvalidate?: boolean;
108
165
  /**
109
166
  * Distributed cache invalidation via Redis Pub/Sub.
110
167
  * When configured, broadcasts `delPattern` events to all other connected instances.
111
- * `ioredis` is installed with monSQLize; this block only enables and configures Redis usage.
168
+ * Provide `redisUrl` or an existing Redis-like `redis` instance when enabling this block.
112
169
  * @since v2.0.0
113
170
  */
114
171
  distributed?: {
115
- /** Redis URL for the Pub/Sub connection. Defaults to `"redis://localhost:6379"`. */
172
+ /** Redis URL for the Pub/Sub connection. */
116
173
  redisUrl?: string;
174
+ /** Alias for `redisUrl`. */
175
+ url?: string;
176
+ /** Alias for `redisUrl`. */
177
+ uri?: string;
117
178
  /** Existing ioredis `Redis` instance to use for publishing. */
118
179
  redis?: unknown;
119
- /** Pub/Sub channel name shared across instances. Default: `"cache-hub:invalidate"`. */
180
+ /** Pub/Sub channel name shared across instances. Default: `"monsqlize:cache:invalidate"`. */
120
181
  channel?: string;
121
182
  /** Unique ID for this instance; used to filter self-published messages. Auto-generated if omitted. */
122
183
  instanceId?: string;
@@ -126,6 +187,8 @@ export interface MonSQLizeOptions {
126
187
  [key: string]: unknown;
127
188
  };
128
189
  logger?: LoggerLike | null;
190
+ /** Isolated schema-dsl runtime configuration for Model schema compilation and validation. */
191
+ schemaDsl?: false | SchemaDslRuntimeConfig;
129
192
  pools?: PoolConfig[];
130
193
  poolStrategy?: PoolStrategy;
131
194
  poolFallback?: ConnectionPoolManagerOptions['poolFallback'];
@@ -148,12 +211,27 @@ export interface MonSQLizeOptions {
148
211
  lockMaxDuration?: number;
149
212
  lockCleanupInterval?: number;
150
213
  maxStatsSamples?: number;
214
+ /**
215
+ * v1 compatibility placeholder. The current v2 transaction cache lock is process-local
216
+ * and this option is not wired into distributed cache-lock interception.
217
+ *
218
+ * Use `DistributedCacheLockManager` explicitly for business critical sections, pair it
219
+ * with idempotency/fencing, or disable cache where cross-instance strict consistency is
220
+ * required.
221
+ *
222
+ * @deprecated This option is retained for compatibility only and does not enable a
223
+ * distributed transaction cache lock in the v2 runtime.
224
+ */
151
225
  distributedLock?: Record<string, unknown>;
152
226
  };
153
227
  /** Global query timeout in milliseconds applied to all find/aggregate operations. Default: 2000. @since v1.3.0 */
154
228
  maxTimeMS?: number;
155
- /** Default limit for find() when caller does not specify one. Default: 10. @since v1.3.0 */
229
+ /** Default limit for find() when caller does not specify one. Default: 500. @since v1.3.0 */
156
230
  findLimit?: number;
231
+ /** Maximum allowed explicit limit for find(). limit(0) keeps MongoDB's unlimited semantics. Default: 10000. @since v3.0.0 */
232
+ findMaxLimit?: number;
233
+ /** Maximum allowed explicit skip for find() and offsetJump. Default: 50000. @since v3.0.0 */
234
+ findMaxSkip?: number;
157
235
  /** Slow query threshold in milliseconds; populates slowQueryLog.filter.minExecutionTimeMs when slowQueryLog is enabled. Default: 500. @since v1.3.0 */
158
236
  slowQueryMs?: number;
159
237
  /** Maximum allowed limit for findPage() operations. Requests exceeding this cap are silently clamped. Default: 500. @since v1.3.0 */
@@ -162,9 +240,17 @@ export interface MonSQLizeOptions {
162
240
  namespace?: { scope?: 'database' | 'connection'; instanceId?: string; };
163
241
  /** HMAC-SHA256 secret used to sign and verify cursor tokens returned by findPage(). @since v1.3.0 */
164
242
  cursorSecret?: string;
243
+ /** Require cursorSecret before findPage can emit or consume cursor tokens. Default: false. @since v3.0.0 */
244
+ requireCursorSecret?: boolean;
245
+ /** Controls startup warning when cursorSecret is missing. Default: 'production'. @since v3.0.0 */
246
+ cursorSecretWarning?: 'off' | 'production' | 'always';
247
+ /** Global cursor value type hints used when findPage decodes after/before tokens. @since v3.0.0 */
248
+ cursorTypes?: Record<string, CursorValueType>;
249
+ /** Global cursor value normalizer used when findPage decodes after/before tokens. @since v3.0.0 */
250
+ cursorValueNormalizer?: CursorValueNormalizer;
165
251
  /** Logging tag configuration applied to slow-query event payloads. @since v1.3.0 */
166
252
  log?: { slowQueryTag?: { event?: string; code?: string;[key: string]: unknown }; formatSlowQuery?: (meta: unknown) => unknown; };
167
- /** Auto-convert 24-character hex strings to ObjectId in query filters. Pass a field map to selectively enable per field. Default: true for mongodb type (pass `false` to disable). @since v1.3.0 */
253
+ /** Auto-convert valid 24-character hex strings to ObjectId across query/write paths. Pass `false` to disable, or use `excludeFields`, `maxDepth`, or `{ field: false }` escape hatches. Default: true for mongodb type. @since v1.3.0 */
168
254
  autoConvertObjectId?: boolean | {
169
255
  enabled?: boolean;
170
256
  excludeFields?: string[];
@@ -178,8 +264,13 @@ export interface MonSQLizeOptions {
178
264
  models?: string | { path: string; pattern?: string; recursive?: boolean; };
179
265
  /** Global automatic model index creation control. Defaults to true for backward compatibility. */
180
266
  autoIndex?: ModelAutoIndexOptions;
181
- /** Auto-invalidate cache on write operations. @since v1.3.0 */
267
+ /** Compatibility alias for `cache.autoInvalidate`. Prefer the nested cache option. */
182
268
  cacheAutoInvalidate?: boolean;
269
+ /**
270
+ * Optional write path governance. By default both collection and model write APIs remain available.
271
+ * Use `model-only` per default or namespace to require writes through the model API.
272
+ */
273
+ writePathPolicy?: WritePathPolicyOptions;
183
274
  }
184
275
 
185
276
  export interface MonSQLizeInstance {
@@ -276,21 +367,24 @@ export interface MonSQLizeInstance {
276
367
  */
277
368
  withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
278
369
  /**
279
- * Execute a callback while holding a distributed lock; the lock is released automatically on completion.
370
+ * Execute a callback while holding a legacy monSQLize lock; the lock is released automatically on completion.
371
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
280
372
  * @param key Unique lock identifier key.
281
373
  * @param callback Async callback executed while the lock is held.
282
374
  * @param options Optional lock options.
283
375
  */
284
376
  withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
285
377
  /**
286
- * Acquire a distributed lock, blocking until it is available or the timeout is reached.
378
+ * Acquire a legacy monSQLize lock, blocking until it is available or the timeout is reached.
379
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
287
380
  * @param key Unique lock identifier key.
288
381
  * @param options Optional lock options.
289
382
  * @returns The acquired lock instance.
290
383
  */
291
384
  acquireLock(key: string, options?: LockOptions): Promise<Lock>;
292
385
  /**
293
- * Try to acquire a distributed lock without blocking; returns `null` if the lock is already held.
386
+ * Try to acquire a legacy monSQLize lock without blocking; returns `null` if the lock is already held.
387
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
294
388
  * @param key Unique lock identifier key.
295
389
  * @param options Optional lock options (`retryTimes` is not supported).
296
390
  * @returns The acquired lock instance, or `null` if unavailable.
@@ -300,27 +394,29 @@ export interface MonSQLizeInstance {
300
394
  getSyncManager(): ChangeStreamSyncManager | null;
301
395
  /** Return the slow-query log manager; `null` when slow-query logging is not enabled. */
302
396
  getSlowQueryLogManager(): SlowQueryLogManager | null;
303
- /** Return the Saga orchestrator instance. */
397
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
304
398
  getSagaOrchestrator(): SagaOrchestrator;
305
- /** Shorthand alias for `getSagaOrchestrator()`. */
399
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
306
400
  saga(): SagaOrchestrator;
307
401
  /**
308
402
  * Register a Saga definition.
403
+ * @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration.
309
404
  * @param definition Saga definition object containing steps and compensation logic.
310
405
  */
311
406
  defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
312
407
  /**
313
408
  * Execute the named registered Saga.
409
+ * @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration.
314
410
  * @param name Saga name.
315
411
  * @param data Initial data passed into the Saga.
316
412
  * @returns The Saga execution result.
317
413
  */
318
414
  executeSaga(name: string, data: unknown): Promise<SagaResult>;
319
- /** List all registered Saga names. */
415
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
320
416
  listSagas(): string[];
321
417
  /** Return aggregate transaction statistics; `null` before transaction capability initialization. */
322
418
  getTransactionStats(): TransactionStats | null;
323
- /** Return Saga execution statistics (success / failure / compensation counts, etc.). */
419
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
324
420
  getSagaStats(): SagaStats;
325
421
  /** Return distributed cache invalidator statistics; `null` when distributed invalidation is not enabled. */
326
422
  getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
@@ -452,17 +548,26 @@ export default class MonSQLize implements MonSQLizeInstance {
452
548
  ensureModelIndexes(options?: ModelEnsureAllIndexesOptions): Promise<ModelIndexEnsureSummary>;
453
549
  startSession(options?: TransactionOptions): Promise<Transaction>;
454
550
  withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
551
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
455
552
  withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
553
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
456
554
  acquireLock(key: string, options?: LockOptions): Promise<Lock>;
555
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
457
556
  tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
458
557
  getSyncManager(): ChangeStreamSyncManager | null;
459
558
  getSlowQueryLogManager(): SlowQueryLogManager | null;
559
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
460
560
  getSagaOrchestrator(): SagaOrchestrator;
561
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
461
562
  saga(): SagaOrchestrator;
563
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
462
564
  defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
565
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
463
566
  executeSaga(name: string, data: unknown): Promise<SagaResult>;
567
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
464
568
  listSagas(): string[];
465
569
  getTransactionStats(): TransactionStats | null;
570
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
466
571
  getSagaStats(): SagaStats;
467
572
  getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
468
573
  startSync(): Promise<void>;
@@ -505,7 +610,15 @@ export default class MonSQLize implements MonSQLizeInstance {
505
610
  static hasExpressionInObject: typeof hasExpressionInObject;
506
611
  static hasExpressionInPipeline: typeof hasExpressionInPipeline;
507
612
  static createRedisCacheAdapter: typeof createRedisCacheAdapter;
613
+ /**
614
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
615
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
616
+ */
508
617
  static withCache: typeof withCache;
618
+ /**
619
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
620
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
621
+ */
509
622
  static FunctionCache: typeof FunctionCache;
510
623
  static adaptLegacyCacheLike: typeof adaptLegacyCacheLike;
511
624
  static MultiLevelCache: typeof MultiLevelCache;
@@ -517,6 +630,7 @@ export default class MonSQLize implements MonSQLizeInstance {
517
630
  static SlowQueryLogMemoryStorage: typeof SlowQueryLogMemoryStorage;
518
631
  static MongoDBSlowQueryLogStorage: typeof MongoDBSlowQueryLogStorage;
519
632
  static BatchQueue: typeof BatchQueue;
633
+ static DataTaskJobError: typeof DataTaskJobError;
520
634
  static generateQueryHash: typeof generateQueryHash;
521
635
  static SagaOrchestrator: typeof SagaOrchestrator;
522
636
  }
@@ -1,4 +1,5 @@
1
1
  import type { LoggerLike } from './base';
2
+ import type { SchemaDslRuntime, SchemaDslRuntimeOptions } from 'schema-dsl/runtime';
2
3
 
3
4
  /**
4
5
  * SSH tunnel configuration for connecting through a bastion host.
@@ -31,7 +32,8 @@ export interface SSHConfig {
31
32
  localPort?: number;
32
33
  }
33
34
 
34
- import type { Collection, DbAccessor, HealthView } from './collection';
35
+ import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection';
36
+ import type { DataTaskJobError } from './data-tasks';
35
37
  import type { Lock, LockOptions, LockStats } from './lock';
36
38
  import type { ModelAutoIndexOptions, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model';
37
39
  import type { MongoConnectConfig } from './mongodb';
@@ -68,6 +70,61 @@ import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, Sl
68
70
  import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync';
69
71
  import type { Transaction, TransactionOptions, TransactionStats } from './transaction';
70
72
 
73
+ /** Write path policy mode. `allow-both` preserves the existing collection and model write behavior. */
74
+ export type WritePathPolicyMode = 'allow-both' | 'model-only';
75
+
76
+ /** Controls whether native raw access is available under a write path policy. */
77
+ export type WritePathPolicyRawMode = 'inherit' | 'allow' | 'block';
78
+
79
+ /** Controls whether collection/database management writes are available under a write path policy. */
80
+ export type WritePathPolicyManagementMode = 'inherit' | 'allow' | 'block';
81
+
82
+ /** Controls violation handling; `warn` logs and allows for migration observation. */
83
+ export type WritePathPolicyViolationAction = 'throw' | 'warn';
84
+
85
+ /** Per-namespace write path policy rule. */
86
+ export interface WritePathPolicyRule {
87
+ /** Write policy mode. Default: `allow-both`. */
88
+ mode?: WritePathPolicyMode;
89
+ /** Raw native access policy. `inherit` allows in `allow-both` and blocks in `model-only`. */
90
+ raw?: WritePathPolicyRawMode;
91
+ /** Management write policy. `inherit` allows model management and blocks external management in `model-only`. */
92
+ management?: WritePathPolicyManagementMode;
93
+ /** Violation action. Default: `throw`. */
94
+ onViolation?: WritePathPolicyViolationAction;
95
+ }
96
+
97
+ /** Runtime write path policy configuration. */
98
+ export interface WritePathPolicyOptions {
99
+ /**
100
+ * Default rule applied when no namespace override matches.
101
+ * Omit this option to preserve existing behavior (`allow-both`).
102
+ */
103
+ default?: WritePathPolicyMode | WritePathPolicyRule;
104
+ /**
105
+ * Namespace overrides matched in this order: `iid`, `pool:db.collection`,
106
+ * `db.collection`, then `collection`.
107
+ */
108
+ namespaces?: Record<string, WritePathPolicyMode | WritePathPolicyRule>;
109
+ }
110
+
111
+ export type MonSQLizeSchemaDslRuntime = Pick<
112
+ SchemaDslRuntime,
113
+ 's' | 'dsl' | 'validate' | 'registerExtensions' | 'dispose'
114
+ >;
115
+
116
+ /** schema-dsl runtime integration. Omit to let monSQLize create one isolated runtime per MonSQLize instance. */
117
+ export interface SchemaDslRuntimeConfig {
118
+ /** Disable model schema-dsl compilation and validation when false. Default: true. */
119
+ enabled?: boolean;
120
+ /** Existing schema-dsl runtime instance. monSQLize will use it but will not dispose it. */
121
+ runtime?: MonSQLizeSchemaDslRuntime;
122
+ /** Options passed to `createRuntime()` when monSQLize owns the runtime. */
123
+ options?: SchemaDslRuntimeOptions;
124
+ /** Extension definitions registered on the selected runtime before model schema compilation. */
125
+ extensions?: readonly unknown[];
126
+ }
127
+
71
128
  export interface MonSQLizeOptions {
72
129
  type?: 'mongodb';
73
130
  databaseName?: string;
@@ -82,7 +139,7 @@ export interface MonSQLizeOptions {
82
139
  * - A plain config object. Recognised fields:
83
140
  * `maxEntries` / `maxSize` (v1 alias), `maxMemory`, `defaultTtl` / `ttl` (v1 alias),
84
141
  * `enableStats`, `enableTags`, `cleanupInterval`, `enabled`,
85
- * `autoInvalidate` (v1 alias for `cacheAutoInvalidate`)
142
+ * `autoInvalidate` (broad write invalidation, disabled by default)
86
143
  */
87
144
  cache?: CacheLike | MemoryCache | MultiLevelCacheOptions | {
88
145
  /** Maximum number of entries; v2 name. Alias: maxSize (v1). */
@@ -103,20 +160,24 @@ export interface MonSQLizeOptions {
103
160
  cleanupInterval?: number;
104
161
  /** Disable cache entirely when false. Default: true. */
105
162
  enabled?: boolean;
106
- /** @deprecated Use top-level `cacheAutoInvalidate`. v1 alias: auto-invalidate on writes. */
163
+ /** Broadly invalidate collection query caches after successful writes. Default: false. */
107
164
  autoInvalidate?: boolean;
108
165
  /**
109
166
  * Distributed cache invalidation via Redis Pub/Sub.
110
167
  * When configured, broadcasts `delPattern` events to all other connected instances.
111
- * `ioredis` is installed with monSQLize; this block only enables and configures Redis usage.
168
+ * Provide `redisUrl` or an existing Redis-like `redis` instance when enabling this block.
112
169
  * @since v2.0.0
113
170
  */
114
171
  distributed?: {
115
- /** Redis URL for the Pub/Sub connection. Defaults to `"redis://localhost:6379"`. */
172
+ /** Redis URL for the Pub/Sub connection. */
116
173
  redisUrl?: string;
174
+ /** Alias for `redisUrl`. */
175
+ url?: string;
176
+ /** Alias for `redisUrl`. */
177
+ uri?: string;
117
178
  /** Existing ioredis `Redis` instance to use for publishing. */
118
179
  redis?: unknown;
119
- /** Pub/Sub channel name shared across instances. Default: `"cache-hub:invalidate"`. */
180
+ /** Pub/Sub channel name shared across instances. Default: `"monsqlize:cache:invalidate"`. */
120
181
  channel?: string;
121
182
  /** Unique ID for this instance; used to filter self-published messages. Auto-generated if omitted. */
122
183
  instanceId?: string;
@@ -126,6 +187,8 @@ export interface MonSQLizeOptions {
126
187
  [key: string]: unknown;
127
188
  };
128
189
  logger?: LoggerLike | null;
190
+ /** Isolated schema-dsl runtime configuration for Model schema compilation and validation. */
191
+ schemaDsl?: false | SchemaDslRuntimeConfig;
129
192
  pools?: PoolConfig[];
130
193
  poolStrategy?: PoolStrategy;
131
194
  poolFallback?: ConnectionPoolManagerOptions['poolFallback'];
@@ -148,12 +211,27 @@ export interface MonSQLizeOptions {
148
211
  lockMaxDuration?: number;
149
212
  lockCleanupInterval?: number;
150
213
  maxStatsSamples?: number;
214
+ /**
215
+ * v1 compatibility placeholder. The current v2 transaction cache lock is process-local
216
+ * and this option is not wired into distributed cache-lock interception.
217
+ *
218
+ * Use `DistributedCacheLockManager` explicitly for business critical sections, pair it
219
+ * with idempotency/fencing, or disable cache where cross-instance strict consistency is
220
+ * required.
221
+ *
222
+ * @deprecated This option is retained for compatibility only and does not enable a
223
+ * distributed transaction cache lock in the v2 runtime.
224
+ */
151
225
  distributedLock?: Record<string, unknown>;
152
226
  };
153
227
  /** Global query timeout in milliseconds applied to all find/aggregate operations. Default: 2000. @since v1.3.0 */
154
228
  maxTimeMS?: number;
155
- /** Default limit for find() when caller does not specify one. Default: 10. @since v1.3.0 */
229
+ /** Default limit for find() when caller does not specify one. Default: 500. @since v1.3.0 */
156
230
  findLimit?: number;
231
+ /** Maximum allowed explicit limit for find(). limit(0) keeps MongoDB's unlimited semantics. Default: 10000. @since v3.0.0 */
232
+ findMaxLimit?: number;
233
+ /** Maximum allowed explicit skip for find() and offsetJump. Default: 50000. @since v3.0.0 */
234
+ findMaxSkip?: number;
157
235
  /** Slow query threshold in milliseconds; populates slowQueryLog.filter.minExecutionTimeMs when slowQueryLog is enabled. Default: 500. @since v1.3.0 */
158
236
  slowQueryMs?: number;
159
237
  /** Maximum allowed limit for findPage() operations. Requests exceeding this cap are silently clamped. Default: 500. @since v1.3.0 */
@@ -162,9 +240,17 @@ export interface MonSQLizeOptions {
162
240
  namespace?: { scope?: 'database' | 'connection'; instanceId?: string; };
163
241
  /** HMAC-SHA256 secret used to sign and verify cursor tokens returned by findPage(). @since v1.3.0 */
164
242
  cursorSecret?: string;
243
+ /** Require cursorSecret before findPage can emit or consume cursor tokens. Default: false. @since v3.0.0 */
244
+ requireCursorSecret?: boolean;
245
+ /** Controls startup warning when cursorSecret is missing. Default: 'production'. @since v3.0.0 */
246
+ cursorSecretWarning?: 'off' | 'production' | 'always';
247
+ /** Global cursor value type hints used when findPage decodes after/before tokens. @since v3.0.0 */
248
+ cursorTypes?: Record<string, CursorValueType>;
249
+ /** Global cursor value normalizer used when findPage decodes after/before tokens. @since v3.0.0 */
250
+ cursorValueNormalizer?: CursorValueNormalizer;
165
251
  /** Logging tag configuration applied to slow-query event payloads. @since v1.3.0 */
166
252
  log?: { slowQueryTag?: { event?: string; code?: string;[key: string]: unknown }; formatSlowQuery?: (meta: unknown) => unknown; };
167
- /** Auto-convert 24-character hex strings to ObjectId in query filters. Pass a field map to selectively enable per field. Default: true for mongodb type (pass `false` to disable). @since v1.3.0 */
253
+ /** Auto-convert valid 24-character hex strings to ObjectId across query/write paths. Pass `false` to disable, or use `excludeFields`, `maxDepth`, or `{ field: false }` escape hatches. Default: true for mongodb type. @since v1.3.0 */
168
254
  autoConvertObjectId?: boolean | {
169
255
  enabled?: boolean;
170
256
  excludeFields?: string[];
@@ -178,8 +264,13 @@ export interface MonSQLizeOptions {
178
264
  models?: string | { path: string; pattern?: string; recursive?: boolean; };
179
265
  /** Global automatic model index creation control. Defaults to true for backward compatibility. */
180
266
  autoIndex?: ModelAutoIndexOptions;
181
- /** Auto-invalidate cache on write operations. @since v1.3.0 */
267
+ /** Compatibility alias for `cache.autoInvalidate`. Prefer the nested cache option. */
182
268
  cacheAutoInvalidate?: boolean;
269
+ /**
270
+ * Optional write path governance. By default both collection and model write APIs remain available.
271
+ * Use `model-only` per default or namespace to require writes through the model API.
272
+ */
273
+ writePathPolicy?: WritePathPolicyOptions;
183
274
  }
184
275
 
185
276
  export interface MonSQLizeInstance {
@@ -276,21 +367,24 @@ export interface MonSQLizeInstance {
276
367
  */
277
368
  withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
278
369
  /**
279
- * Execute a callback while holding a distributed lock; the lock is released automatically on completion.
370
+ * Execute a callback while holding a legacy monSQLize lock; the lock is released automatically on completion.
371
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
280
372
  * @param key Unique lock identifier key.
281
373
  * @param callback Async callback executed while the lock is held.
282
374
  * @param options Optional lock options.
283
375
  */
284
376
  withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
285
377
  /**
286
- * Acquire a distributed lock, blocking until it is available or the timeout is reached.
378
+ * Acquire a legacy monSQLize lock, blocking until it is available or the timeout is reached.
379
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
287
380
  * @param key Unique lock identifier key.
288
381
  * @param options Optional lock options.
289
382
  * @returns The acquired lock instance.
290
383
  */
291
384
  acquireLock(key: string, options?: LockOptions): Promise<Lock>;
292
385
  /**
293
- * Try to acquire a distributed lock without blocking; returns `null` if the lock is already held.
386
+ * Try to acquire a legacy monSQLize lock without blocking; returns `null` if the lock is already held.
387
+ * @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking.
294
388
  * @param key Unique lock identifier key.
295
389
  * @param options Optional lock options (`retryTimes` is not supported).
296
390
  * @returns The acquired lock instance, or `null` if unavailable.
@@ -300,27 +394,29 @@ export interface MonSQLizeInstance {
300
394
  getSyncManager(): ChangeStreamSyncManager | null;
301
395
  /** Return the slow-query log manager; `null` when slow-query logging is not enabled. */
302
396
  getSlowQueryLogManager(): SlowQueryLogManager | null;
303
- /** Return the Saga orchestrator instance. */
397
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
304
398
  getSagaOrchestrator(): SagaOrchestrator;
305
- /** Shorthand alias for `getSagaOrchestrator()`. */
399
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
306
400
  saga(): SagaOrchestrator;
307
401
  /**
308
402
  * Register a Saga definition.
403
+ * @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration.
309
404
  * @param definition Saga definition object containing steps and compensation logic.
310
405
  */
311
406
  defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
312
407
  /**
313
408
  * Execute the named registered Saga.
409
+ * @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration.
314
410
  * @param name Saga name.
315
411
  * @param data Initial data passed into the Saga.
316
412
  * @returns The Saga execution result.
317
413
  */
318
414
  executeSaga(name: string, data: unknown): Promise<SagaResult>;
319
- /** List all registered Saga names. */
415
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
320
416
  listSagas(): string[];
321
417
  /** Return aggregate transaction statistics; `null` before transaction capability initialization. */
322
418
  getTransactionStats(): TransactionStats | null;
323
- /** Return Saga execution statistics (success / failure / compensation counts, etc.). */
419
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
324
420
  getSagaStats(): SagaStats;
325
421
  /** Return distributed cache invalidator statistics; `null` when distributed invalidation is not enabled. */
326
422
  getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
@@ -452,17 +548,26 @@ export default class MonSQLize implements MonSQLizeInstance {
452
548
  ensureModelIndexes(options?: ModelEnsureAllIndexesOptions): Promise<ModelIndexEnsureSummary>;
453
549
  startSession(options?: TransactionOptions): Promise<Transaction>;
454
550
  withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
551
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
455
552
  withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
553
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
456
554
  acquireLock(key: string, options?: LockOptions): Promise<Lock>;
555
+ /** @deprecated Business locks are retained for compatibility. Prefer application/framework-level locking. */
457
556
  tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
458
557
  getSyncManager(): ChangeStreamSyncManager | null;
459
558
  getSlowQueryLogManager(): SlowQueryLogManager | null;
559
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
460
560
  getSagaOrchestrator(): SagaOrchestrator;
561
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
461
562
  saga(): SagaOrchestrator;
563
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
462
564
  defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
565
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
463
566
  executeSaga(name: string, data: unknown): Promise<SagaResult>;
567
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
464
568
  listSagas(): string[];
465
569
  getTransactionStats(): TransactionStats | null;
570
+ /** @deprecated Saga APIs are retained for compatibility. Prefer application/framework-level workflow orchestration. */
466
571
  getSagaStats(): SagaStats;
467
572
  getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
468
573
  startSync(): Promise<void>;
@@ -505,7 +610,15 @@ export default class MonSQLize implements MonSQLizeInstance {
505
610
  static hasExpressionInObject: typeof hasExpressionInObject;
506
611
  static hasExpressionInPipeline: typeof hasExpressionInPipeline;
507
612
  static createRedisCacheAdapter: typeof createRedisCacheAdapter;
613
+ /**
614
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
615
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
616
+ */
508
617
  static withCache: typeof withCache;
618
+ /**
619
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
620
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
621
+ */
509
622
  static FunctionCache: typeof FunctionCache;
510
623
  static adaptLegacyCacheLike: typeof adaptLegacyCacheLike;
511
624
  static MultiLevelCache: typeof MultiLevelCache;
@@ -517,6 +630,7 @@ export default class MonSQLize implements MonSQLizeInstance {
517
630
  static SlowQueryLogMemoryStorage: typeof SlowQueryLogMemoryStorage;
518
631
  static MongoDBSlowQueryLogStorage: typeof MongoDBSlowQueryLogStorage;
519
632
  static BatchQueue: typeof BatchQueue;
633
+ static DataTaskJobError: typeof DataTaskJobError;
520
634
  static generateQueryHash: typeof generateQueryHash;
521
635
  static SagaOrchestrator: typeof SagaOrchestrator;
522
636
  }
@@ -91,6 +91,10 @@ export interface MultiLevelCacheOptions {
91
91
  }
92
92
 
93
93
  export type MultiLevelInvalidationMessage = {
94
+ type: 'del' | 'delete' | 'invalidateKey';
95
+ key: string;
96
+ ts: number;
97
+ } | {
94
98
  type: 'delPattern';
95
99
  pattern: string;
96
100
  ts: number;
@@ -189,6 +193,7 @@ export type DistributedCacheInvalidatorStats = HubInvalidatorStats;
189
193
  export declare class DistributedCacheInvalidator {
190
194
  constructor(options: DistributedCacheInvalidatorOptions);
191
195
  invalidate(pattern: string): Promise<void>;
196
+ invalidateKey(key: string): Promise<void>;
192
197
  getStats(): HubInvalidatorStats;
193
198
  close(): Promise<void>;
194
199
  }
@@ -253,11 +258,19 @@ export interface FunctionCacheOptions extends HubFunctionCacheOptions {
253
258
  defaultTTL?: number;
254
259
  }
255
260
 
261
+ /**
262
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
263
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
264
+ */
256
265
  export declare function withCache<TArgs extends unknown[], TResult>(
257
266
  fn: (...args: TArgs) => Promise<TResult>,
258
267
  options?: WithCacheOptions<(...args: TArgs) => Promise<TResult>>,
259
268
  ): CachedFunction<TArgs, TResult>;
260
269
 
270
+ /**
271
+ * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path;
272
+ * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage.
273
+ */
261
274
  export declare class FunctionCache {
262
275
  constructor(cacheOrDb?: CacheLike | { getCache(): CacheLike; }, options?: FunctionCacheOptions);
263
276
  register(name: string, fn: (...args: unknown[]) => Promise<unknown>, options?: {
@@ -291,7 +304,7 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
291
304
  readonly dbName: string;
292
305
  readonly poolName?: string;
293
306
  readonly definition: ModelDefinition<TDocument>;
294
- getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
307
+ getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; pool?: string; };
295
308
  getRelations(): Record<string, RelationConfig>;
296
309
  getEnums(): Record<string, string>;
297
310
  raw(): unknown;