monsqlize 2.0.0 → 2.0.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.
- package/CHANGELOG.md +460 -458
- package/README.md +7 -2
- package/changelogs/README.md +141 -138
- package/changelogs/v2.0.0.md +164 -164
- package/changelogs/v2.0.1.md +39 -0
- package/dist/cjs/index.cjs +329 -141
- package/dist/esm/index.mjs +329 -141
- package/dist/types/base.d.ts +81 -81
- package/dist/types/collection.d.ts +973 -973
- package/dist/types/expression.d.ts +115 -115
- package/dist/types/index.d.ts +23 -23
- package/dist/types/model.d.ts +489 -485
- package/dist/types/mongodb.d.ts +49 -49
- package/dist/types/monsqlize.d.ts +429 -429
- package/dist/types/pool.d.ts +84 -84
- package/dist/types/runtime.d.ts +315 -315
- package/dist/types/saga.d.ts +121 -121
- package/dist/types/slow-query-log.d.ts +126 -126
- package/dist/types/sync.d.ts +103 -103
- package/package.json +100 -99
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import type { LoggerLike } from './base';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* SSH tunnel configuration for connecting through a bastion host.
|
|
5
|
-
* @since v1.3.0
|
|
6
|
-
*/
|
|
7
|
-
export interface SSHConfig {
|
|
8
|
-
/** SSH server hostname or IP. */
|
|
9
|
-
host: string;
|
|
10
|
-
/** SSH server port (default: 22). */
|
|
11
|
-
scopedCollection<TSchema = unknown>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
|
|
12
|
-
/** SSH login username. */
|
|
13
|
-
username: string;
|
|
14
|
-
/** SSH password (mutually exclusive with privateKey). */
|
|
15
|
-
password?: string;
|
|
16
|
-
/** SSH private key string or Buffer (mutually exclusive with password and privateKeyPath). */
|
|
17
|
-
privateKey?: string | Buffer;
|
|
18
|
-
/** Path to an SSH private key file; supports ~ for home directory (mutually exclusive with password and privateKey). @since v1.3.0 */
|
|
19
|
-
privateKeyPath?: string;
|
|
20
|
-
/** Passphrase for an encrypted private key. */
|
|
21
|
-
passphrase?: string;
|
|
22
|
-
/** Connection ready timeout in milliseconds (default: 20000). */
|
|
23
|
-
readyTimeout?: number;
|
|
24
|
-
/** Keep-alive interval in milliseconds (default: 30000). */
|
|
25
|
-
keepaliveInterval?: number;
|
|
26
|
-
/** Target database host as seen from the SSH server (default: auto-parsed from URI). */
|
|
27
|
-
dstHost?: string;
|
|
28
|
-
/** Target database port as seen from the SSH server (default: auto-parsed from URI). */
|
|
29
|
-
dstPort?: number;
|
|
30
|
-
/** Fixed local TCP port for the tunnel; omit for a random OS-assigned port. @since v1.3.0 */
|
|
31
|
-
localPort?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
import type { Collection, DbAccessor, HealthView } from './collection';
|
|
35
|
-
import type { Lock, LockOptions, LockStats } from './lock';
|
|
36
|
-
import type { ModelInstance } from './model';
|
|
37
|
-
import type { MongoConnectConfig } from './mongodb';
|
|
38
|
-
import type { ConnectionPoolManagerOptions, PoolConfig, PoolHealthStatus, PoolStats, PoolStrategy } from './pool';
|
|
39
|
-
import type {
|
|
40
|
-
BatchQueue,
|
|
41
|
-
CacheLike,
|
|
42
|
-
CacheLockManager,
|
|
43
|
-
DistributedCacheInvalidator,
|
|
44
|
-
FunctionCache,
|
|
45
|
-
Logger,
|
|
46
|
-
MemoryCache,
|
|
47
|
-
MultiLevelCache,
|
|
48
|
-
MultiLevelCacheOptions,
|
|
49
|
-
SlowQueryLogConfigManager,
|
|
50
|
-
SlowQueryLogMemoryStorage,
|
|
51
|
-
MongoDBSlowQueryLogStorage,
|
|
52
|
-
TransactionManager,
|
|
53
|
-
createExpression,
|
|
54
|
-
compilePipelineExpressions,
|
|
55
|
-
createRedisCacheAdapter,
|
|
56
|
-
expr,
|
|
57
|
-
generateQueryHash,
|
|
58
|
-
hasExpressionInObject,
|
|
59
|
-
hasExpressionInPipeline,
|
|
60
|
-
isExpressionObject,
|
|
61
|
-
validateSyncConfig,
|
|
62
|
-
withCache,
|
|
63
|
-
adaptLegacyCacheLike,
|
|
64
|
-
} from './runtime';
|
|
65
|
-
import type { SagaDefinition, SagaOrchestrator, SagaResult, SagaStats } from './saga';
|
|
66
|
-
import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, SlowQueryLogManager, SlowQueryLogQueryOptions, SlowQueryLogRecord } from './slow-query-log';
|
|
67
|
-
import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync';
|
|
68
|
-
import type { Transaction, TransactionOptions } from './transaction';
|
|
69
|
-
|
|
70
|
-
export interface MonSQLizeOptions {
|
|
71
|
-
type?: 'mongodb';
|
|
72
|
-
databaseName?: string;
|
|
73
|
-
/** @alias databaseName — v1 compatibility */
|
|
74
|
-
database?: string;
|
|
75
|
-
config?: MongoConnectConfig;
|
|
76
|
-
/**
|
|
77
|
-
* Cache configuration. Accepts:
|
|
78
|
-
* - A `MemoryCache` instance (direct injection)
|
|
79
|
-
* - A `CacheLike` instance (v1 compat: custom cache implementation)
|
|
80
|
-
* - A `MultiLevelCacheOptions` object (multi-level cache setup)
|
|
81
|
-
* - A plain config object. Recognised fields:
|
|
82
|
-
* `maxEntries` / `maxSize` (v1 alias), `maxMemory`, `defaultTtl` / `ttl` (v1 alias),
|
|
83
|
-
* `enableStats`, `enableTags`, `cleanupInterval`, `enabled`,
|
|
84
|
-
* `autoInvalidate` (v1 alias for `cacheAutoInvalidate`)
|
|
85
|
-
*/
|
|
86
|
-
cache?: CacheLike | MemoryCache | MultiLevelCacheOptions | {
|
|
87
|
-
/** Maximum number of entries; v2 name. Alias: maxSize (v1). */
|
|
88
|
-
maxEntries?: number;
|
|
89
|
-
/** @deprecated Use `maxEntries`. v1 alias for `maxEntries`. */
|
|
90
|
-
maxSize?: number;
|
|
91
|
-
/** Maximum memory in bytes (0 = unlimited). */
|
|
92
|
-
maxMemory?: number;
|
|
93
|
-
/** Default TTL in milliseconds; v2 name. Alias: ttl (v1). */
|
|
94
|
-
defaultTtl?: number;
|
|
95
|
-
/** @deprecated Use `defaultTtl`. v1 alias for `defaultTtl`. */
|
|
96
|
-
ttl?: number;
|
|
97
|
-
/** Enable cache hit/miss statistics. Default: true. */
|
|
98
|
-
enableStats?: boolean;
|
|
99
|
-
/** Enable tag-based invalidation. Default: false. */
|
|
100
|
-
enableTags?: boolean;
|
|
101
|
-
/** Periodic TTL cleanup interval in milliseconds. */
|
|
102
|
-
cleanupInterval?: number;
|
|
103
|
-
/** Disable cache entirely when false. Default: true. */
|
|
104
|
-
enabled?: boolean;
|
|
105
|
-
/** @deprecated Use top-level `cacheAutoInvalidate`. v1 alias: auto-invalidate on writes. */
|
|
106
|
-
autoInvalidate?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Distributed cache invalidation via Redis Pub/Sub.
|
|
109
|
-
* When configured, broadcasts `delPattern` events to all other connected instances.
|
|
110
|
-
* Requires `ioredis` to be installed separately.
|
|
111
|
-
* @since v2.0.0
|
|
112
|
-
*/
|
|
113
|
-
distributed?: {
|
|
114
|
-
/** Redis URL for the Pub/Sub connection. Defaults to `"redis://localhost:6379"`. */
|
|
115
|
-
redisUrl?: string;
|
|
116
|
-
/** Existing ioredis `Redis` instance to use for publishing. */
|
|
117
|
-
redis?: unknown;
|
|
118
|
-
/** Pub/Sub channel name shared across instances. Default: `"cache-hub:invalidate"`. */
|
|
119
|
-
channel?: string;
|
|
120
|
-
/** Unique ID for this instance; used to filter self-published messages. Auto-generated if omitted. */
|
|
121
|
-
instanceId?: string;
|
|
122
|
-
/** Set to `false` to disable without removing the config block. Default: `true`. */
|
|
123
|
-
enabled?: boolean;
|
|
124
|
-
};
|
|
125
|
-
[key: string]: unknown;
|
|
126
|
-
};
|
|
127
|
-
logger?: LoggerLike | null;
|
|
128
|
-
pools?: PoolConfig[];
|
|
129
|
-
poolStrategy?: PoolStrategy;
|
|
130
|
-
poolFallback?: ConnectionPoolManagerOptions['poolFallback'];
|
|
131
|
-
maxPoolsCount?: number;
|
|
132
|
-
sync?: SyncConfig;
|
|
133
|
-
slowQueryLog?: SlowQueryLogConfigInput;
|
|
134
|
-
/** Global query timeout in milliseconds applied to all find/aggregate operations. Default: 2000. @since v1.3.0 */
|
|
135
|
-
maxTimeMS?: number;
|
|
136
|
-
/** Default limit for find() when caller does not specify one. Default: 10. @since v1.3.0 */
|
|
137
|
-
findLimit?: number;
|
|
138
|
-
/** Slow query threshold in milliseconds; populates slowQueryLog.filter.minExecutionTimeMs when slowQueryLog is enabled. Default: 500. @since v1.3.0 */
|
|
139
|
-
slowQueryMs?: number;
|
|
140
|
-
/** Maximum allowed limit for findPage() operations. Requests exceeding this cap are silently clamped. Default: 500. @since v1.3.0 */
|
|
141
|
-
findPageMaxLimit?: number;
|
|
142
|
-
/** Namespace scope for cursor isolation between multiple MonSQLize instances sharing a cache. @since v1.3.0 */
|
|
143
|
-
namespace?: { scope?: 'database' | 'connection'; instanceId?: string; };
|
|
144
|
-
/** HMAC-SHA256 secret used to sign and verify cursor tokens returned by findPage(). @since v1.3.0 */
|
|
145
|
-
cursorSecret?: string;
|
|
146
|
-
/** Logging tag configuration applied to slow-query event payloads. @since v1.3.0 */
|
|
147
|
-
log?: { slowQueryTag?: { event?: string; code?: string;[key: string]: unknown }; formatSlowQuery?: (meta: unknown) => unknown; };
|
|
148
|
-
/** 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 */
|
|
149
|
-
autoConvertObjectId?: boolean | {
|
|
150
|
-
enabled?: boolean;
|
|
151
|
-
excludeFields?: string[];
|
|
152
|
-
customFieldPatterns?: string[];
|
|
153
|
-
maxDepth?: number;
|
|
154
|
-
logLevel?: 'info' | 'warn' | 'error' | string;
|
|
155
|
-
} | Record<string, boolean>;
|
|
156
|
-
/** Batch count operations to reduce server round-trips. @since v1.3.0 */
|
|
157
|
-
countQueue?: boolean | { enabled?: boolean; concurrency?: number; maxQueueSize?: number; timeout?: number; };
|
|
158
|
-
/** Model definitions to auto-register on connect. Accepts a file path (string) or an object with { path, pattern?, recursive? }. @since v1.3.0 */
|
|
159
|
-
models?: string | { path: string; pattern?: string; recursive?: boolean; };
|
|
160
|
-
/** Auto-invalidate cache on write operations. @since v1.3.0 */
|
|
161
|
-
cacheAutoInvalidate?: boolean;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface MonSQLizeInstance {
|
|
165
|
-
/**
|
|
166
|
-
* Establish the database connection and return the top-level accessor bundle.
|
|
167
|
-
* @returns Object containing `collection`, `db`, `use` shortcuts and the current instance reference.
|
|
168
|
-
*/
|
|
1
|
+
import type { LoggerLike } from './base';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SSH tunnel configuration for connecting through a bastion host.
|
|
5
|
+
* @since v1.3.0
|
|
6
|
+
*/
|
|
7
|
+
export interface SSHConfig {
|
|
8
|
+
/** SSH server hostname or IP. */
|
|
9
|
+
host: string;
|
|
10
|
+
/** SSH server port (default: 22). */
|
|
11
|
+
scopedCollection<TSchema = unknown>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
|
|
12
|
+
/** SSH login username. */
|
|
13
|
+
username: string;
|
|
14
|
+
/** SSH password (mutually exclusive with privateKey). */
|
|
15
|
+
password?: string;
|
|
16
|
+
/** SSH private key string or Buffer (mutually exclusive with password and privateKeyPath). */
|
|
17
|
+
privateKey?: string | Buffer;
|
|
18
|
+
/** Path to an SSH private key file; supports ~ for home directory (mutually exclusive with password and privateKey). @since v1.3.0 */
|
|
19
|
+
privateKeyPath?: string;
|
|
20
|
+
/** Passphrase for an encrypted private key. */
|
|
21
|
+
passphrase?: string;
|
|
22
|
+
/** Connection ready timeout in milliseconds (default: 20000). */
|
|
23
|
+
readyTimeout?: number;
|
|
24
|
+
/** Keep-alive interval in milliseconds (default: 30000). */
|
|
25
|
+
keepaliveInterval?: number;
|
|
26
|
+
/** Target database host as seen from the SSH server (default: auto-parsed from URI). */
|
|
27
|
+
dstHost?: string;
|
|
28
|
+
/** Target database port as seen from the SSH server (default: auto-parsed from URI). */
|
|
29
|
+
dstPort?: number;
|
|
30
|
+
/** Fixed local TCP port for the tunnel; omit for a random OS-assigned port. @since v1.3.0 */
|
|
31
|
+
localPort?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
import type { Collection, DbAccessor, HealthView } from './collection';
|
|
35
|
+
import type { Lock, LockOptions, LockStats } from './lock';
|
|
36
|
+
import type { ModelInstance } from './model';
|
|
37
|
+
import type { MongoConnectConfig } from './mongodb';
|
|
38
|
+
import type { ConnectionPoolManagerOptions, PoolConfig, PoolHealthStatus, PoolStats, PoolStrategy } from './pool';
|
|
39
|
+
import type {
|
|
40
|
+
BatchQueue,
|
|
41
|
+
CacheLike,
|
|
42
|
+
CacheLockManager,
|
|
43
|
+
DistributedCacheInvalidator,
|
|
44
|
+
FunctionCache,
|
|
45
|
+
Logger,
|
|
46
|
+
MemoryCache,
|
|
47
|
+
MultiLevelCache,
|
|
48
|
+
MultiLevelCacheOptions,
|
|
49
|
+
SlowQueryLogConfigManager,
|
|
50
|
+
SlowQueryLogMemoryStorage,
|
|
51
|
+
MongoDBSlowQueryLogStorage,
|
|
52
|
+
TransactionManager,
|
|
53
|
+
createExpression,
|
|
54
|
+
compilePipelineExpressions,
|
|
55
|
+
createRedisCacheAdapter,
|
|
56
|
+
expr,
|
|
57
|
+
generateQueryHash,
|
|
58
|
+
hasExpressionInObject,
|
|
59
|
+
hasExpressionInPipeline,
|
|
60
|
+
isExpressionObject,
|
|
61
|
+
validateSyncConfig,
|
|
62
|
+
withCache,
|
|
63
|
+
adaptLegacyCacheLike,
|
|
64
|
+
} from './runtime';
|
|
65
|
+
import type { SagaDefinition, SagaOrchestrator, SagaResult, SagaStats } from './saga';
|
|
66
|
+
import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, SlowQueryLogManager, SlowQueryLogQueryOptions, SlowQueryLogRecord } from './slow-query-log';
|
|
67
|
+
import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync';
|
|
68
|
+
import type { Transaction, TransactionOptions } from './transaction';
|
|
69
|
+
|
|
70
|
+
export interface MonSQLizeOptions {
|
|
71
|
+
type?: 'mongodb';
|
|
72
|
+
databaseName?: string;
|
|
73
|
+
/** @alias databaseName — v1 compatibility */
|
|
74
|
+
database?: string;
|
|
75
|
+
config?: MongoConnectConfig;
|
|
76
|
+
/**
|
|
77
|
+
* Cache configuration. Accepts:
|
|
78
|
+
* - A `MemoryCache` instance (direct injection)
|
|
79
|
+
* - A `CacheLike` instance (v1 compat: custom cache implementation)
|
|
80
|
+
* - A `MultiLevelCacheOptions` object (multi-level cache setup)
|
|
81
|
+
* - A plain config object. Recognised fields:
|
|
82
|
+
* `maxEntries` / `maxSize` (v1 alias), `maxMemory`, `defaultTtl` / `ttl` (v1 alias),
|
|
83
|
+
* `enableStats`, `enableTags`, `cleanupInterval`, `enabled`,
|
|
84
|
+
* `autoInvalidate` (v1 alias for `cacheAutoInvalidate`)
|
|
85
|
+
*/
|
|
86
|
+
cache?: CacheLike | MemoryCache | MultiLevelCacheOptions | {
|
|
87
|
+
/** Maximum number of entries; v2 name. Alias: maxSize (v1). */
|
|
88
|
+
maxEntries?: number;
|
|
89
|
+
/** @deprecated Use `maxEntries`. v1 alias for `maxEntries`. */
|
|
90
|
+
maxSize?: number;
|
|
91
|
+
/** Maximum memory in bytes (0 = unlimited). */
|
|
92
|
+
maxMemory?: number;
|
|
93
|
+
/** Default TTL in milliseconds; v2 name. Alias: ttl (v1). */
|
|
94
|
+
defaultTtl?: number;
|
|
95
|
+
/** @deprecated Use `defaultTtl`. v1 alias for `defaultTtl`. */
|
|
96
|
+
ttl?: number;
|
|
97
|
+
/** Enable cache hit/miss statistics. Default: true. */
|
|
98
|
+
enableStats?: boolean;
|
|
99
|
+
/** Enable tag-based invalidation. Default: false. */
|
|
100
|
+
enableTags?: boolean;
|
|
101
|
+
/** Periodic TTL cleanup interval in milliseconds. */
|
|
102
|
+
cleanupInterval?: number;
|
|
103
|
+
/** Disable cache entirely when false. Default: true. */
|
|
104
|
+
enabled?: boolean;
|
|
105
|
+
/** @deprecated Use top-level `cacheAutoInvalidate`. v1 alias: auto-invalidate on writes. */
|
|
106
|
+
autoInvalidate?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Distributed cache invalidation via Redis Pub/Sub.
|
|
109
|
+
* When configured, broadcasts `delPattern` events to all other connected instances.
|
|
110
|
+
* Requires `ioredis` to be installed separately.
|
|
111
|
+
* @since v2.0.0
|
|
112
|
+
*/
|
|
113
|
+
distributed?: {
|
|
114
|
+
/** Redis URL for the Pub/Sub connection. Defaults to `"redis://localhost:6379"`. */
|
|
115
|
+
redisUrl?: string;
|
|
116
|
+
/** Existing ioredis `Redis` instance to use for publishing. */
|
|
117
|
+
redis?: unknown;
|
|
118
|
+
/** Pub/Sub channel name shared across instances. Default: `"cache-hub:invalidate"`. */
|
|
119
|
+
channel?: string;
|
|
120
|
+
/** Unique ID for this instance; used to filter self-published messages. Auto-generated if omitted. */
|
|
121
|
+
instanceId?: string;
|
|
122
|
+
/** Set to `false` to disable without removing the config block. Default: `true`. */
|
|
123
|
+
enabled?: boolean;
|
|
124
|
+
};
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
logger?: LoggerLike | null;
|
|
128
|
+
pools?: PoolConfig[];
|
|
129
|
+
poolStrategy?: PoolStrategy;
|
|
130
|
+
poolFallback?: ConnectionPoolManagerOptions['poolFallback'];
|
|
131
|
+
maxPoolsCount?: number;
|
|
132
|
+
sync?: SyncConfig;
|
|
133
|
+
slowQueryLog?: SlowQueryLogConfigInput;
|
|
134
|
+
/** Global query timeout in milliseconds applied to all find/aggregate operations. Default: 2000. @since v1.3.0 */
|
|
135
|
+
maxTimeMS?: number;
|
|
136
|
+
/** Default limit for find() when caller does not specify one. Default: 10. @since v1.3.0 */
|
|
137
|
+
findLimit?: number;
|
|
138
|
+
/** Slow query threshold in milliseconds; populates slowQueryLog.filter.minExecutionTimeMs when slowQueryLog is enabled. Default: 500. @since v1.3.0 */
|
|
139
|
+
slowQueryMs?: number;
|
|
140
|
+
/** Maximum allowed limit for findPage() operations. Requests exceeding this cap are silently clamped. Default: 500. @since v1.3.0 */
|
|
141
|
+
findPageMaxLimit?: number;
|
|
142
|
+
/** Namespace scope for cursor isolation between multiple MonSQLize instances sharing a cache. @since v1.3.0 */
|
|
143
|
+
namespace?: { scope?: 'database' | 'connection'; instanceId?: string; };
|
|
144
|
+
/** HMAC-SHA256 secret used to sign and verify cursor tokens returned by findPage(). @since v1.3.0 */
|
|
145
|
+
cursorSecret?: string;
|
|
146
|
+
/** Logging tag configuration applied to slow-query event payloads. @since v1.3.0 */
|
|
147
|
+
log?: { slowQueryTag?: { event?: string; code?: string;[key: string]: unknown }; formatSlowQuery?: (meta: unknown) => unknown; };
|
|
148
|
+
/** 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 */
|
|
149
|
+
autoConvertObjectId?: boolean | {
|
|
150
|
+
enabled?: boolean;
|
|
151
|
+
excludeFields?: string[];
|
|
152
|
+
customFieldPatterns?: string[];
|
|
153
|
+
maxDepth?: number;
|
|
154
|
+
logLevel?: 'info' | 'warn' | 'error' | string;
|
|
155
|
+
} | Record<string, boolean>;
|
|
156
|
+
/** Batch count operations to reduce server round-trips. @since v1.3.0 */
|
|
157
|
+
countQueue?: boolean | { enabled?: boolean; concurrency?: number; maxQueueSize?: number; timeout?: number; };
|
|
158
|
+
/** Model definitions to auto-register on connect. Accepts a file path (string) or an object with { path, pattern?, recursive? }. @since v1.3.0 */
|
|
159
|
+
models?: string | { path: string; pattern?: string; recursive?: boolean; };
|
|
160
|
+
/** Auto-invalidate cache on write operations. @since v1.3.0 */
|
|
161
|
+
cacheAutoInvalidate?: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface MonSQLizeInstance {
|
|
165
|
+
/**
|
|
166
|
+
* Establish the database connection and return the top-level accessor bundle.
|
|
167
|
+
* @returns Object containing `collection`, `db`, `use` shortcuts and the current instance reference.
|
|
168
|
+
*/
|
|
169
169
|
connect(): Promise<{
|
|
170
170
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
171
171
|
db: (name?: string) => DbAccessor;
|
|
@@ -174,41 +174,41 @@ export interface MonSQLizeInstance {
|
|
|
174
174
|
model: <TDocument = any>(modelName: string) => ModelInstance<TDocument>;
|
|
175
175
|
};
|
|
176
176
|
instance: MonSQLize;
|
|
177
|
-
}>;
|
|
178
|
-
/**
|
|
179
|
-
* Return the active cache instance (MemoryCache, MultiLevelCache, or a custom CacheLike).
|
|
180
|
-
* Can be used to manually read, write, or invalidate cache entries.
|
|
181
|
-
*/
|
|
182
|
-
getCache(): CacheLike;
|
|
183
|
-
/** Return a frozen snapshot of the merged runtime defaults. */
|
|
184
|
-
getDefaults(): Record<string, unknown>;
|
|
185
|
-
/** Close all database connections and release associated resources. */
|
|
186
|
-
close(): Promise<void>;
|
|
187
|
-
/** Return the current connection health status view. */
|
|
188
|
-
health(): Promise<HealthView>;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Return the active cache instance (MemoryCache, MultiLevelCache, or a custom CacheLike).
|
|
180
|
+
* Can be used to manually read, write, or invalidate cache entries.
|
|
181
|
+
*/
|
|
182
|
+
getCache(): CacheLike;
|
|
183
|
+
/** Return a frozen snapshot of the merged runtime defaults. */
|
|
184
|
+
getDefaults(): Record<string, unknown>;
|
|
185
|
+
/** Close all database connections and release associated resources. */
|
|
186
|
+
close(): Promise<void>;
|
|
187
|
+
/** Return the current connection health status view. */
|
|
188
|
+
health(): Promise<HealthView>;
|
|
189
189
|
/**
|
|
190
190
|
* Return a collection accessor for the given collection name.
|
|
191
191
|
* @param name Collection name.
|
|
192
192
|
*/
|
|
193
193
|
collection<TSchema = any>(name: string): Collection<TSchema>;
|
|
194
194
|
collection(name: string): Collection<any>;
|
|
195
|
-
/**
|
|
196
|
-
* Return a database accessor, optionally scoped to a specific database.
|
|
197
|
-
* @param name Target database name; omit to use the default database.
|
|
198
|
-
*/
|
|
199
|
-
db(name?: string): DbAccessor;
|
|
200
|
-
/**
|
|
201
|
-
* Switch to the given database and return its `collection` and `model` accessors.
|
|
202
|
-
* @param name Target database name.
|
|
203
|
-
*/
|
|
195
|
+
/**
|
|
196
|
+
* Return a database accessor, optionally scoped to a specific database.
|
|
197
|
+
* @param name Target database name; omit to use the default database.
|
|
198
|
+
*/
|
|
199
|
+
db(name?: string): DbAccessor;
|
|
200
|
+
/**
|
|
201
|
+
* Switch to the given database and return its `collection` and `model` accessors.
|
|
202
|
+
* @param name Target database name.
|
|
203
|
+
*/
|
|
204
204
|
use(name: string): {
|
|
205
205
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
206
206
|
model: <TDocument = any>(modelName: string) => ModelInstance<TDocument>;
|
|
207
207
|
};
|
|
208
|
-
/**
|
|
209
|
-
* Return collection and model accessors for the named connection pool.
|
|
210
|
-
* @param poolName Connection pool name.
|
|
211
|
-
*/
|
|
208
|
+
/**
|
|
209
|
+
* Return collection and model accessors for the named connection pool.
|
|
210
|
+
* @param poolName Connection pool name.
|
|
211
|
+
*/
|
|
212
212
|
pool(poolName: string): {
|
|
213
213
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
214
214
|
model: <TDocument = any>(name: string) => ModelInstance<TDocument>;
|
|
@@ -217,174 +217,174 @@ export interface MonSQLizeInstance {
|
|
|
217
217
|
model: <TDocument = any>(name: string) => ModelInstance<TDocument>;
|
|
218
218
|
};
|
|
219
219
|
};
|
|
220
|
-
/**
|
|
221
|
-
* Return a collection accessor scoped to the given database.
|
|
222
|
-
* @param name Collection name.
|
|
223
|
-
* @param options Optional database scope options.
|
|
224
|
-
*/
|
|
220
|
+
/**
|
|
221
|
+
* Return a collection accessor scoped to the given database.
|
|
222
|
+
* @param name Collection name.
|
|
223
|
+
* @param options Optional database scope options.
|
|
224
|
+
*/
|
|
225
225
|
scopedCollection<TSchema = any>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
|
|
226
226
|
scopedCollection(name: string, options?: { database?: string; pool?: string; }): Collection<any>;
|
|
227
|
-
/**
|
|
228
|
-
* Return a model instance scoped to the given database or connection pool.
|
|
229
|
-
* @param name Model name.
|
|
230
|
-
* @param options Optional database or pool scope options.
|
|
231
|
-
*/
|
|
227
|
+
/**
|
|
228
|
+
* Return a model instance scoped to the given database or connection pool.
|
|
229
|
+
* @param name Model name.
|
|
230
|
+
* @param options Optional database or pool scope options.
|
|
231
|
+
*/
|
|
232
232
|
scopedModel<TDocument = any>(name: string, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
233
233
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
234
|
-
/**
|
|
235
|
-
* Return the registered model instance for the given model name.
|
|
236
|
-
* @param name Model name used during registration.
|
|
237
|
-
*/
|
|
234
|
+
/**
|
|
235
|
+
* Return the registered model instance for the given model name.
|
|
236
|
+
* @param name Model name used during registration.
|
|
237
|
+
*/
|
|
238
238
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
239
239
|
model(name: string): ModelInstance<any>;
|
|
240
|
-
/**
|
|
241
|
-
* Start a MongoDB transaction session.
|
|
242
|
-
* @param options Optional transaction options.
|
|
243
|
-
* @returns The transaction session object.
|
|
244
|
-
*/
|
|
245
|
-
startSession(options?: TransactionOptions): Promise<Transaction>;
|
|
246
|
-
/**
|
|
247
|
-
* Execute a callback inside a transaction; commits on success, auto-rolls back on failure.
|
|
248
|
-
* @param callback Async callback that receives the transaction session.
|
|
249
|
-
* @param options Optional transaction options.
|
|
250
|
-
*/
|
|
251
|
-
withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
252
|
-
/**
|
|
253
|
-
* Execute a callback while holding a distributed lock; the lock is released automatically on completion.
|
|
254
|
-
* @param key Unique lock identifier key.
|
|
255
|
-
* @param callback Async callback executed while the lock is held.
|
|
256
|
-
* @param options Optional lock options.
|
|
257
|
-
*/
|
|
258
|
-
withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
259
|
-
/**
|
|
260
|
-
* Acquire a distributed lock, blocking until it is available or the timeout is reached.
|
|
261
|
-
* @param key Unique lock identifier key.
|
|
262
|
-
* @param options Optional lock options.
|
|
263
|
-
* @returns The acquired lock instance.
|
|
264
|
-
*/
|
|
265
|
-
acquireLock(key: string, options?: LockOptions): Promise<Lock>;
|
|
266
|
-
/**
|
|
267
|
-
* Try to acquire a distributed lock without blocking; returns `null` if the lock is already held.
|
|
268
|
-
* @param key Unique lock identifier key.
|
|
269
|
-
* @param options Optional lock options (`retryTimes` is not supported).
|
|
270
|
-
* @returns The acquired lock instance, or `null` if unavailable.
|
|
271
|
-
*/
|
|
272
|
-
tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
|
|
273
|
-
/** Return the ChangeStream sync manager; `null` when sync is not enabled. */
|
|
274
|
-
getSyncManager(): ChangeStreamSyncManager | null;
|
|
275
|
-
/** Return the slow-query log manager; `null` when slow-query logging is not enabled. */
|
|
276
|
-
getSlowQueryLogManager(): SlowQueryLogManager | null;
|
|
277
|
-
/** Return the Saga orchestrator instance. */
|
|
278
|
-
getSagaOrchestrator(): SagaOrchestrator;
|
|
279
|
-
/** Shorthand alias for `getSagaOrchestrator()`. */
|
|
280
|
-
saga(): SagaOrchestrator;
|
|
281
|
-
/**
|
|
282
|
-
* Register a Saga definition.
|
|
283
|
-
* @param definition Saga definition object containing steps and compensation logic.
|
|
284
|
-
*/
|
|
285
|
-
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
286
|
-
/**
|
|
287
|
-
* Execute the named registered Saga.
|
|
288
|
-
* @param name Saga name.
|
|
289
|
-
* @param data Initial data passed into the Saga.
|
|
290
|
-
* @returns The Saga execution result.
|
|
291
|
-
*/
|
|
292
|
-
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
293
|
-
/** List all registered Saga names. */
|
|
294
|
-
listSagas(): string[];
|
|
295
|
-
/** Return Saga execution statistics (success / failure / compensation counts, etc.). */
|
|
296
|
-
getSagaStats(): SagaStats;
|
|
297
|
-
/** Start ChangeStream data synchronisation. */
|
|
298
|
-
startSync(): Promise<void>;
|
|
299
|
-
/** Stop ChangeStream data synchronisation. */
|
|
300
|
-
stopSync(): Promise<void>;
|
|
301
|
-
/** Return current data sync statistics; `null` when sync is not enabled. */
|
|
302
|
-
getSyncStats(): SyncStats | null;
|
|
303
|
-
/**
|
|
304
|
-
* Manually record a slow-query log entry.
|
|
305
|
-
* @param log The slow-query log entry object.
|
|
306
|
-
*/
|
|
307
|
-
recordSlowQuery(log: SlowQueryLogEntry): Promise<void>;
|
|
308
|
-
/**
|
|
309
|
-
* Query slow-query log records.
|
|
310
|
-
* @param filter Optional filter criteria.
|
|
311
|
-
* @param options Optional pagination and sort options.
|
|
312
|
-
* @returns Array of matching slow-query log records.
|
|
313
|
-
*/
|
|
314
|
-
getSlowQueryLogs(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
315
|
-
/**
|
|
316
|
-
* Subscribe to an event.
|
|
317
|
-
* @param event Event name.
|
|
318
|
-
* @param handler Event handler callback.
|
|
319
|
-
*/
|
|
320
|
-
on(event: string, handler: (payload: unknown) => void): void;
|
|
321
|
-
/**
|
|
322
|
-
* Subscribe to an event; automatically unsubscribes after the first invocation.
|
|
323
|
-
* @param event Event name.
|
|
324
|
-
* @param handler Event handler callback.
|
|
325
|
-
*/
|
|
326
|
-
once(event: string, handler: (payload: unknown) => void): void;
|
|
327
|
-
/**
|
|
328
|
-
* Unsubscribe from an event.
|
|
329
|
-
* @param event Event name.
|
|
330
|
-
* @param handler The handler to remove.
|
|
331
|
-
*/
|
|
332
|
-
off(event: string, handler: (payload: unknown) => void): void;
|
|
333
|
-
/**
|
|
334
|
-
* Emit an event and dispatch the payload to all subscribers.
|
|
335
|
-
* @param event Event name.
|
|
336
|
-
* @param payload Event payload data.
|
|
337
|
-
*/
|
|
338
|
-
emit(event: string, payload: unknown): void;
|
|
339
|
-
/**
|
|
340
|
-
* Dynamically add a connection pool.
|
|
341
|
-
* @param config Pool configuration object.
|
|
342
|
-
* @since v1.3.0 — v1 pool management parity
|
|
343
|
-
*/
|
|
344
|
-
addPool(config: PoolConfig): Promise<void>;
|
|
345
|
-
/**
|
|
346
|
-
* Remove the named connection pool and close its connections.
|
|
347
|
-
* @param name Connection pool name.
|
|
348
|
-
*/
|
|
349
|
-
removePool(name: string): Promise<void>;
|
|
350
|
-
/** Return the names of all registered connection pools. */
|
|
351
|
-
getPoolNames(): string[];
|
|
352
|
-
/** Return runtime statistics for all connection pools. */
|
|
353
|
-
getPoolStats(): Record<string, PoolStats>;
|
|
354
|
-
/** Return the health status of all connection pools. */
|
|
355
|
-
getPoolHealth(): Record<string, PoolHealthStatus>;
|
|
356
|
-
/** Return distributed lock usage statistics; `null` when locks are not enabled. */
|
|
357
|
-
getLockStats(): LockStats | null;
|
|
358
|
-
/**
|
|
359
|
-
* List all databases accessible on the current connection.
|
|
360
|
-
* @param options Pass `nameOnly: true` to return a plain string array of database names.
|
|
361
|
-
* @since v1.3.0 — v1 database management parity
|
|
362
|
-
*/
|
|
363
|
-
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
364
|
-
/**
|
|
365
|
-
* Drop the current default database; requires explicit confirmation via `confirm: true`.
|
|
366
|
-
* @param options Drop confirmation and safety options.
|
|
367
|
-
* @returns Object containing the operation result, database name, and timestamp.
|
|
368
|
-
*/
|
|
369
|
-
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
370
|
-
/**
|
|
371
|
-
* List all collections in the current database.
|
|
372
|
-
* @param filter Optional collection name filter.
|
|
373
|
-
* @param options Optional driver-level options.
|
|
374
|
-
* @returns Array of objects containing collection name and type.
|
|
375
|
-
*/
|
|
376
|
-
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
377
|
-
/**
|
|
378
|
-
* Execute a raw MongoDB command on the current database.
|
|
379
|
-
* @param command Command document object.
|
|
380
|
-
* @param options Optional driver-level options.
|
|
381
|
-
* @returns The command result document.
|
|
382
|
-
*/
|
|
383
|
-
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export default class MonSQLize implements MonSQLizeInstance {
|
|
387
|
-
constructor(options?: MonSQLizeOptions);
|
|
240
|
+
/**
|
|
241
|
+
* Start a MongoDB transaction session.
|
|
242
|
+
* @param options Optional transaction options.
|
|
243
|
+
* @returns The transaction session object.
|
|
244
|
+
*/
|
|
245
|
+
startSession(options?: TransactionOptions): Promise<Transaction>;
|
|
246
|
+
/**
|
|
247
|
+
* Execute a callback inside a transaction; commits on success, auto-rolls back on failure.
|
|
248
|
+
* @param callback Async callback that receives the transaction session.
|
|
249
|
+
* @param options Optional transaction options.
|
|
250
|
+
*/
|
|
251
|
+
withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
252
|
+
/**
|
|
253
|
+
* Execute a callback while holding a distributed lock; the lock is released automatically on completion.
|
|
254
|
+
* @param key Unique lock identifier key.
|
|
255
|
+
* @param callback Async callback executed while the lock is held.
|
|
256
|
+
* @param options Optional lock options.
|
|
257
|
+
*/
|
|
258
|
+
withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
259
|
+
/**
|
|
260
|
+
* Acquire a distributed lock, blocking until it is available or the timeout is reached.
|
|
261
|
+
* @param key Unique lock identifier key.
|
|
262
|
+
* @param options Optional lock options.
|
|
263
|
+
* @returns The acquired lock instance.
|
|
264
|
+
*/
|
|
265
|
+
acquireLock(key: string, options?: LockOptions): Promise<Lock>;
|
|
266
|
+
/**
|
|
267
|
+
* Try to acquire a distributed lock without blocking; returns `null` if the lock is already held.
|
|
268
|
+
* @param key Unique lock identifier key.
|
|
269
|
+
* @param options Optional lock options (`retryTimes` is not supported).
|
|
270
|
+
* @returns The acquired lock instance, or `null` if unavailable.
|
|
271
|
+
*/
|
|
272
|
+
tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
|
|
273
|
+
/** Return the ChangeStream sync manager; `null` when sync is not enabled. */
|
|
274
|
+
getSyncManager(): ChangeStreamSyncManager | null;
|
|
275
|
+
/** Return the slow-query log manager; `null` when slow-query logging is not enabled. */
|
|
276
|
+
getSlowQueryLogManager(): SlowQueryLogManager | null;
|
|
277
|
+
/** Return the Saga orchestrator instance. */
|
|
278
|
+
getSagaOrchestrator(): SagaOrchestrator;
|
|
279
|
+
/** Shorthand alias for `getSagaOrchestrator()`. */
|
|
280
|
+
saga(): SagaOrchestrator;
|
|
281
|
+
/**
|
|
282
|
+
* Register a Saga definition.
|
|
283
|
+
* @param definition Saga definition object containing steps and compensation logic.
|
|
284
|
+
*/
|
|
285
|
+
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
286
|
+
/**
|
|
287
|
+
* Execute the named registered Saga.
|
|
288
|
+
* @param name Saga name.
|
|
289
|
+
* @param data Initial data passed into the Saga.
|
|
290
|
+
* @returns The Saga execution result.
|
|
291
|
+
*/
|
|
292
|
+
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
293
|
+
/** List all registered Saga names. */
|
|
294
|
+
listSagas(): string[];
|
|
295
|
+
/** Return Saga execution statistics (success / failure / compensation counts, etc.). */
|
|
296
|
+
getSagaStats(): SagaStats;
|
|
297
|
+
/** Start ChangeStream data synchronisation. */
|
|
298
|
+
startSync(): Promise<void>;
|
|
299
|
+
/** Stop ChangeStream data synchronisation. */
|
|
300
|
+
stopSync(): Promise<void>;
|
|
301
|
+
/** Return current data sync statistics; `null` when sync is not enabled. */
|
|
302
|
+
getSyncStats(): SyncStats | null;
|
|
303
|
+
/**
|
|
304
|
+
* Manually record a slow-query log entry.
|
|
305
|
+
* @param log The slow-query log entry object.
|
|
306
|
+
*/
|
|
307
|
+
recordSlowQuery(log: SlowQueryLogEntry): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Query slow-query log records.
|
|
310
|
+
* @param filter Optional filter criteria.
|
|
311
|
+
* @param options Optional pagination and sort options.
|
|
312
|
+
* @returns Array of matching slow-query log records.
|
|
313
|
+
*/
|
|
314
|
+
getSlowQueryLogs(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
315
|
+
/**
|
|
316
|
+
* Subscribe to an event.
|
|
317
|
+
* @param event Event name.
|
|
318
|
+
* @param handler Event handler callback.
|
|
319
|
+
*/
|
|
320
|
+
on(event: string, handler: (payload: unknown) => void): void;
|
|
321
|
+
/**
|
|
322
|
+
* Subscribe to an event; automatically unsubscribes after the first invocation.
|
|
323
|
+
* @param event Event name.
|
|
324
|
+
* @param handler Event handler callback.
|
|
325
|
+
*/
|
|
326
|
+
once(event: string, handler: (payload: unknown) => void): void;
|
|
327
|
+
/**
|
|
328
|
+
* Unsubscribe from an event.
|
|
329
|
+
* @param event Event name.
|
|
330
|
+
* @param handler The handler to remove.
|
|
331
|
+
*/
|
|
332
|
+
off(event: string, handler: (payload: unknown) => void): void;
|
|
333
|
+
/**
|
|
334
|
+
* Emit an event and dispatch the payload to all subscribers.
|
|
335
|
+
* @param event Event name.
|
|
336
|
+
* @param payload Event payload data.
|
|
337
|
+
*/
|
|
338
|
+
emit(event: string, payload: unknown): void;
|
|
339
|
+
/**
|
|
340
|
+
* Dynamically add a connection pool.
|
|
341
|
+
* @param config Pool configuration object.
|
|
342
|
+
* @since v1.3.0 — v1 pool management parity
|
|
343
|
+
*/
|
|
344
|
+
addPool(config: PoolConfig): Promise<void>;
|
|
345
|
+
/**
|
|
346
|
+
* Remove the named connection pool and close its connections.
|
|
347
|
+
* @param name Connection pool name.
|
|
348
|
+
*/
|
|
349
|
+
removePool(name: string): Promise<void>;
|
|
350
|
+
/** Return the names of all registered connection pools. */
|
|
351
|
+
getPoolNames(): string[];
|
|
352
|
+
/** Return runtime statistics for all connection pools. */
|
|
353
|
+
getPoolStats(): Record<string, PoolStats>;
|
|
354
|
+
/** Return the health status of all connection pools. */
|
|
355
|
+
getPoolHealth(): Record<string, PoolHealthStatus>;
|
|
356
|
+
/** Return distributed lock usage statistics; `null` when locks are not enabled. */
|
|
357
|
+
getLockStats(): LockStats | null;
|
|
358
|
+
/**
|
|
359
|
+
* List all databases accessible on the current connection.
|
|
360
|
+
* @param options Pass `nameOnly: true` to return a plain string array of database names.
|
|
361
|
+
* @since v1.3.0 — v1 database management parity
|
|
362
|
+
*/
|
|
363
|
+
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Drop the current default database; requires explicit confirmation via `confirm: true`.
|
|
366
|
+
* @param options Drop confirmation and safety options.
|
|
367
|
+
* @returns Object containing the operation result, database name, and timestamp.
|
|
368
|
+
*/
|
|
369
|
+
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
370
|
+
/**
|
|
371
|
+
* List all collections in the current database.
|
|
372
|
+
* @param filter Optional collection name filter.
|
|
373
|
+
* @param options Optional driver-level options.
|
|
374
|
+
* @returns Array of objects containing collection name and type.
|
|
375
|
+
*/
|
|
376
|
+
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
377
|
+
/**
|
|
378
|
+
* Execute a raw MongoDB command on the current database.
|
|
379
|
+
* @param command Command document object.
|
|
380
|
+
* @param options Optional driver-level options.
|
|
381
|
+
* @returns The command result document.
|
|
382
|
+
*/
|
|
383
|
+
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export default class MonSQLize implements MonSQLizeInstance {
|
|
387
|
+
constructor(options?: MonSQLizeOptions);
|
|
388
388
|
connect(): Promise<{
|
|
389
389
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
390
390
|
db: (name?: string) => DbAccessor;
|
|
@@ -393,10 +393,10 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
393
393
|
model: <TDocument = any>(modelName: string) => ModelInstance<TDocument>;
|
|
394
394
|
};
|
|
395
395
|
instance: MonSQLize;
|
|
396
|
-
}>;
|
|
397
|
-
getCache(): CacheLike;
|
|
398
|
-
getDefaults(): Record<string, unknown>;
|
|
399
|
-
close(): Promise<void>;
|
|
396
|
+
}>;
|
|
397
|
+
getCache(): CacheLike;
|
|
398
|
+
getDefaults(): Record<string, unknown>;
|
|
399
|
+
close(): Promise<void>;
|
|
400
400
|
health(): Promise<HealthView>;
|
|
401
401
|
collection<TSchema = any>(name: string): Collection<TSchema>;
|
|
402
402
|
collection(name: string): Collection<any>;
|
|
@@ -419,73 +419,73 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
419
419
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
420
420
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
421
421
|
model(name: string): ModelInstance<any>;
|
|
422
|
-
startSession(options?: TransactionOptions): Promise<Transaction>;
|
|
423
|
-
withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
424
|
-
withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
425
|
-
acquireLock(key: string, options?: LockOptions): Promise<Lock>;
|
|
426
|
-
tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
|
|
427
|
-
getSyncManager(): ChangeStreamSyncManager | null;
|
|
428
|
-
getSlowQueryLogManager(): SlowQueryLogManager | null;
|
|
429
|
-
getSagaOrchestrator(): SagaOrchestrator;
|
|
430
|
-
saga(): SagaOrchestrator;
|
|
431
|
-
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
432
|
-
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
433
|
-
listSagas(): string[];
|
|
434
|
-
getSagaStats(): SagaStats;
|
|
435
|
-
startSync(): Promise<void>;
|
|
436
|
-
stopSync(): Promise<void>;
|
|
437
|
-
getSyncStats(): SyncStats | null;
|
|
438
|
-
recordSlowQuery(log: SlowQueryLogEntry): Promise<void>;
|
|
439
|
-
getSlowQueryLogs(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
440
|
-
on(event: string, handler: (payload: unknown) => void): void;
|
|
441
|
-
once(event: string, handler: (payload: unknown) => void): void;
|
|
442
|
-
off(event: string, handler: (payload: unknown) => void): void;
|
|
443
|
-
emit(event: string, payload: unknown): void;
|
|
444
|
-
addPool(config: PoolConfig): Promise<void>;
|
|
445
|
-
removePool(name: string): Promise<void>;
|
|
446
|
-
getPoolNames(): string[];
|
|
447
|
-
getPoolStats(): Record<string, PoolStats>;
|
|
448
|
-
getPoolHealth(): Record<string, PoolHealthStatus>;
|
|
449
|
-
getLockStats(): LockStats | null;
|
|
450
|
-
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
451
|
-
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
452
|
-
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
453
|
-
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
454
|
-
|
|
455
|
-
static Logger: typeof Logger;
|
|
456
|
-
static MemoryCache: typeof MemoryCache;
|
|
457
|
-
static Transaction: typeof Transaction;
|
|
458
|
-
static TransactionManager: typeof TransactionManager;
|
|
459
|
-
static CacheLockManager: typeof CacheLockManager;
|
|
460
|
-
static Lock: typeof Lock;
|
|
461
|
-
static LockManager: typeof import('./lock').LockManager;
|
|
462
|
-
static LockAcquireError: typeof import('./lock').LockAcquireError;
|
|
463
|
-
static LockTimeoutError: typeof import('./lock').LockTimeoutError;
|
|
464
|
-
static DistributedCacheInvalidator: typeof DistributedCacheInvalidator;
|
|
465
|
-
static ConnectionPoolManager: typeof import('./pool').ConnectionPoolManager;
|
|
466
|
-
static Model: typeof import('./runtime').Model;
|
|
467
|
-
static ModelInstance: typeof import('./runtime').ModelInstance;
|
|
468
|
-
static expr: typeof expr;
|
|
469
|
-
static createExpression: typeof createExpression;
|
|
470
|
-
static compilePipelineExpressions: typeof compilePipelineExpressions;
|
|
471
|
-
static isExpressionObject: typeof isExpressionObject;
|
|
472
|
-
static hasExpressionInObject: typeof hasExpressionInObject;
|
|
473
|
-
static hasExpressionInPipeline: typeof hasExpressionInPipeline;
|
|
474
|
-
static createRedisCacheAdapter: typeof createRedisCacheAdapter;
|
|
475
|
-
static withCache: typeof withCache;
|
|
476
|
-
static FunctionCache: typeof FunctionCache;
|
|
477
|
-
static adaptLegacyCacheLike: typeof adaptLegacyCacheLike;
|
|
478
|
-
static MultiLevelCache: typeof MultiLevelCache;
|
|
479
|
-
static ChangeStreamSyncManager: typeof ChangeStreamSyncManager;
|
|
480
|
-
static ResumeTokenStore: typeof import('./sync').ResumeTokenStore;
|
|
481
|
-
static validateSyncConfig: typeof validateSyncConfig;
|
|
482
|
-
static SlowQueryLogManager: typeof SlowQueryLogManager;
|
|
483
|
-
static SlowQueryLogConfigManager: typeof SlowQueryLogConfigManager;
|
|
484
|
-
static SlowQueryLogMemoryStorage: typeof SlowQueryLogMemoryStorage;
|
|
485
|
-
static MongoDBSlowQueryLogStorage: typeof MongoDBSlowQueryLogStorage;
|
|
486
|
-
static BatchQueue: typeof BatchQueue;
|
|
487
|
-
static generateQueryHash: typeof generateQueryHash;
|
|
488
|
-
static SagaOrchestrator: typeof SagaOrchestrator;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
export { MonSQLize };
|
|
422
|
+
startSession(options?: TransactionOptions): Promise<Transaction>;
|
|
423
|
+
withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
424
|
+
withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
425
|
+
acquireLock(key: string, options?: LockOptions): Promise<Lock>;
|
|
426
|
+
tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
|
|
427
|
+
getSyncManager(): ChangeStreamSyncManager | null;
|
|
428
|
+
getSlowQueryLogManager(): SlowQueryLogManager | null;
|
|
429
|
+
getSagaOrchestrator(): SagaOrchestrator;
|
|
430
|
+
saga(): SagaOrchestrator;
|
|
431
|
+
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
432
|
+
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
433
|
+
listSagas(): string[];
|
|
434
|
+
getSagaStats(): SagaStats;
|
|
435
|
+
startSync(): Promise<void>;
|
|
436
|
+
stopSync(): Promise<void>;
|
|
437
|
+
getSyncStats(): SyncStats | null;
|
|
438
|
+
recordSlowQuery(log: SlowQueryLogEntry): Promise<void>;
|
|
439
|
+
getSlowQueryLogs(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
440
|
+
on(event: string, handler: (payload: unknown) => void): void;
|
|
441
|
+
once(event: string, handler: (payload: unknown) => void): void;
|
|
442
|
+
off(event: string, handler: (payload: unknown) => void): void;
|
|
443
|
+
emit(event: string, payload: unknown): void;
|
|
444
|
+
addPool(config: PoolConfig): Promise<void>;
|
|
445
|
+
removePool(name: string): Promise<void>;
|
|
446
|
+
getPoolNames(): string[];
|
|
447
|
+
getPoolStats(): Record<string, PoolStats>;
|
|
448
|
+
getPoolHealth(): Record<string, PoolHealthStatus>;
|
|
449
|
+
getLockStats(): LockStats | null;
|
|
450
|
+
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
451
|
+
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
452
|
+
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
453
|
+
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
454
|
+
|
|
455
|
+
static Logger: typeof Logger;
|
|
456
|
+
static MemoryCache: typeof MemoryCache;
|
|
457
|
+
static Transaction: typeof Transaction;
|
|
458
|
+
static TransactionManager: typeof TransactionManager;
|
|
459
|
+
static CacheLockManager: typeof CacheLockManager;
|
|
460
|
+
static Lock: typeof Lock;
|
|
461
|
+
static LockManager: typeof import('./lock').LockManager;
|
|
462
|
+
static LockAcquireError: typeof import('./lock').LockAcquireError;
|
|
463
|
+
static LockTimeoutError: typeof import('./lock').LockTimeoutError;
|
|
464
|
+
static DistributedCacheInvalidator: typeof DistributedCacheInvalidator;
|
|
465
|
+
static ConnectionPoolManager: typeof import('./pool').ConnectionPoolManager;
|
|
466
|
+
static Model: typeof import('./runtime').Model;
|
|
467
|
+
static ModelInstance: typeof import('./runtime').ModelInstance;
|
|
468
|
+
static expr: typeof expr;
|
|
469
|
+
static createExpression: typeof createExpression;
|
|
470
|
+
static compilePipelineExpressions: typeof compilePipelineExpressions;
|
|
471
|
+
static isExpressionObject: typeof isExpressionObject;
|
|
472
|
+
static hasExpressionInObject: typeof hasExpressionInObject;
|
|
473
|
+
static hasExpressionInPipeline: typeof hasExpressionInPipeline;
|
|
474
|
+
static createRedisCacheAdapter: typeof createRedisCacheAdapter;
|
|
475
|
+
static withCache: typeof withCache;
|
|
476
|
+
static FunctionCache: typeof FunctionCache;
|
|
477
|
+
static adaptLegacyCacheLike: typeof adaptLegacyCacheLike;
|
|
478
|
+
static MultiLevelCache: typeof MultiLevelCache;
|
|
479
|
+
static ChangeStreamSyncManager: typeof ChangeStreamSyncManager;
|
|
480
|
+
static ResumeTokenStore: typeof import('./sync').ResumeTokenStore;
|
|
481
|
+
static validateSyncConfig: typeof validateSyncConfig;
|
|
482
|
+
static SlowQueryLogManager: typeof SlowQueryLogManager;
|
|
483
|
+
static SlowQueryLogConfigManager: typeof SlowQueryLogConfigManager;
|
|
484
|
+
static SlowQueryLogMemoryStorage: typeof SlowQueryLogMemoryStorage;
|
|
485
|
+
static MongoDBSlowQueryLogStorage: typeof MongoDBSlowQueryLogStorage;
|
|
486
|
+
static BatchQueue: typeof BatchQueue;
|
|
487
|
+
static generateQueryHash: typeof generateQueryHash;
|
|
488
|
+
static SagaOrchestrator: typeof SagaOrchestrator;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export { MonSQLize };
|