monsqlize 1.3.0 → 2.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.
Files changed (172) hide show
  1. package/CHANGELOG.md +56 -60
  2. package/LICENSE +201 -21
  3. package/README.md +537 -1828
  4. package/changelogs/README.md +160 -0
  5. package/changelogs/v2.0.0.md +222 -0
  6. package/dist/cjs/index.cjs +10600 -0
  7. package/dist/cjs/mongodb/common/transaction-aware.cjs +10 -0
  8. package/dist/cjs/transaction/CacheLockManager.cjs +100 -0
  9. package/dist/cjs/transaction/Transaction.cjs +158 -0
  10. package/dist/cjs/transaction/TransactionManager.cjs +298 -0
  11. package/dist/esm/index.mjs +10650 -0
  12. package/dist/types/base.d.ts +81 -0
  13. package/dist/types/collection.d.ts +1031 -0
  14. package/dist/types/expression.d.ts +115 -0
  15. package/dist/types/index.d.ts +23 -0
  16. package/dist/types/lock.d.ts +74 -0
  17. package/dist/types/model.d.ts +526 -0
  18. package/dist/types/mongodb.d.ts +49 -0
  19. package/dist/types/monsqlize.d.ts +491 -0
  20. package/dist/types/pool.d.ts +84 -0
  21. package/dist/types/runtime.d.ts +362 -0
  22. package/dist/types/saga.d.ts +143 -0
  23. package/dist/types/slow-query-log.d.ts +126 -0
  24. package/dist/types/sync.d.ts +103 -0
  25. package/dist/types/transaction.d.ts +132 -0
  26. package/package.json +67 -69
  27. package/index.d.ts +0 -206
  28. package/index.mjs +0 -52
  29. package/lib/cache-invalidation.js +0 -279
  30. package/lib/cache.js +0 -530
  31. package/lib/common/cursor.js +0 -59
  32. package/lib/common/docs-urls.js +0 -73
  33. package/lib/common/index-options.js +0 -223
  34. package/lib/common/log.js +0 -61
  35. package/lib/common/namespace.js +0 -22
  36. package/lib/common/normalize.js +0 -34
  37. package/lib/common/page-result.js +0 -43
  38. package/lib/common/runner.js +0 -57
  39. package/lib/common/server-features.js +0 -232
  40. package/lib/common/shape-builders.js +0 -27
  41. package/lib/common/validation.js +0 -113
  42. package/lib/connect.js +0 -99
  43. package/lib/constants.js +0 -55
  44. package/lib/count-queue.js +0 -188
  45. package/lib/distributed-cache-invalidator.js +0 -260
  46. package/lib/errors.js +0 -168
  47. package/lib/expression/cache/ExpressionCache.js +0 -114
  48. package/lib/expression/compiler/ExpressionCompiler.js +0 -1090
  49. package/lib/expression/compiler/ExpressionCompilerExtensions.js +0 -531
  50. package/lib/expression/detector.js +0 -84
  51. package/lib/expression/factory.js +0 -29
  52. package/lib/expression/index.js +0 -19
  53. package/lib/function-cache.js +0 -533
  54. package/lib/index.js +0 -1251
  55. package/lib/infrastructure/ConnectionPoolManager.js +0 -464
  56. package/lib/infrastructure/HealthChecker.js +0 -281
  57. package/lib/infrastructure/PoolConfig.js +0 -199
  58. package/lib/infrastructure/PoolSelector.js +0 -225
  59. package/lib/infrastructure/PoolStats.js +0 -244
  60. package/lib/infrastructure/ssh-tunnel-ssh2.js +0 -212
  61. package/lib/infrastructure/ssh-tunnel.js +0 -41
  62. package/lib/infrastructure/uri-parser.js +0 -36
  63. package/lib/lock/Lock.js +0 -67
  64. package/lib/lock/errors.js +0 -28
  65. package/lib/lock/index.js +0 -13
  66. package/lib/logger.js +0 -225
  67. package/lib/model/examples/test.js +0 -311
  68. package/lib/model/features/defaults.js +0 -161
  69. package/lib/model/features/populate.js +0 -568
  70. package/lib/model/features/relations.js +0 -120
  71. package/lib/model/features/soft-delete.js +0 -349
  72. package/lib/model/features/version.js +0 -157
  73. package/lib/model/features/virtuals.js +0 -219
  74. package/lib/model/index.js +0 -1265
  75. package/lib/mongodb/common/accessor-helpers.js +0 -59
  76. package/lib/mongodb/common/agg-pipeline.js +0 -36
  77. package/lib/mongodb/common/aggregation-validator.js +0 -127
  78. package/lib/mongodb/common/iid.js +0 -28
  79. package/lib/mongodb/common/lexicographic-expr.js +0 -53
  80. package/lib/mongodb/common/shape.js +0 -32
  81. package/lib/mongodb/common/sort.js +0 -39
  82. package/lib/mongodb/common/transaction-aware.js +0 -25
  83. package/lib/mongodb/connect.js +0 -234
  84. package/lib/mongodb/index.js +0 -639
  85. package/lib/mongodb/management/admin-ops.js +0 -200
  86. package/lib/mongodb/management/bookmark-ops.js +0 -167
  87. package/lib/mongodb/management/cache-ops.js +0 -50
  88. package/lib/mongodb/management/collection-ops.js +0 -387
  89. package/lib/mongodb/management/database-ops.js +0 -202
  90. package/lib/mongodb/management/index-ops.js +0 -475
  91. package/lib/mongodb/management/index.js +0 -17
  92. package/lib/mongodb/management/namespace.js +0 -31
  93. package/lib/mongodb/management/validation-ops.js +0 -268
  94. package/lib/mongodb/queries/aggregate.js +0 -172
  95. package/lib/mongodb/queries/chain.js +0 -631
  96. package/lib/mongodb/queries/count.js +0 -99
  97. package/lib/mongodb/queries/distinct.js +0 -78
  98. package/lib/mongodb/queries/find-and-count.js +0 -193
  99. package/lib/mongodb/queries/find-by-ids.js +0 -236
  100. package/lib/mongodb/queries/find-one-by-id.js +0 -171
  101. package/lib/mongodb/queries/find-one.js +0 -71
  102. package/lib/mongodb/queries/find-page.js +0 -618
  103. package/lib/mongodb/queries/find.js +0 -171
  104. package/lib/mongodb/queries/index.js +0 -51
  105. package/lib/mongodb/queries/watch.js +0 -538
  106. package/lib/mongodb/writes/common/batch-retry.js +0 -65
  107. package/lib/mongodb/writes/delete-batch.js +0 -323
  108. package/lib/mongodb/writes/delete-many.js +0 -181
  109. package/lib/mongodb/writes/delete-one.js +0 -173
  110. package/lib/mongodb/writes/find-one-and-delete.js +0 -203
  111. package/lib/mongodb/writes/find-one-and-replace.js +0 -239
  112. package/lib/mongodb/writes/find-one-and-update.js +0 -240
  113. package/lib/mongodb/writes/increment-one.js +0 -259
  114. package/lib/mongodb/writes/index.js +0 -46
  115. package/lib/mongodb/writes/insert-batch.js +0 -508
  116. package/lib/mongodb/writes/insert-many.js +0 -223
  117. package/lib/mongodb/writes/insert-one.js +0 -169
  118. package/lib/mongodb/writes/replace-one.js +0 -226
  119. package/lib/mongodb/writes/result-handler.js +0 -237
  120. package/lib/mongodb/writes/update-batch.js +0 -416
  121. package/lib/mongodb/writes/update-many.js +0 -275
  122. package/lib/mongodb/writes/update-one.js +0 -273
  123. package/lib/mongodb/writes/upsert-one.js +0 -203
  124. package/lib/multi-level-cache.js +0 -244
  125. package/lib/operators.js +0 -330
  126. package/lib/redis-cache-adapter.js +0 -267
  127. package/lib/saga/SagaContext.js +0 -67
  128. package/lib/saga/SagaDefinition.js +0 -32
  129. package/lib/saga/SagaExecutor.js +0 -201
  130. package/lib/saga/SagaOrchestrator.js +0 -186
  131. package/lib/saga/index.js +0 -11
  132. package/lib/slow-query-log/base-storage.js +0 -70
  133. package/lib/slow-query-log/batch-queue.js +0 -97
  134. package/lib/slow-query-log/config-manager.js +0 -196
  135. package/lib/slow-query-log/index.js +0 -238
  136. package/lib/slow-query-log/mongodb-storage.js +0 -324
  137. package/lib/slow-query-log/query-hash.js +0 -39
  138. package/lib/sync/ChangeStreamSyncManager.js +0 -405
  139. package/lib/sync/ResumeTokenStore.js +0 -192
  140. package/lib/sync/SyncConfig.js +0 -127
  141. package/lib/sync/SyncTarget.js +0 -240
  142. package/lib/sync/index.js +0 -20
  143. package/lib/transaction/CacheLockManager.js +0 -162
  144. package/lib/transaction/DistributedCacheLockManager.js +0 -475
  145. package/lib/transaction/Transaction.js +0 -315
  146. package/lib/transaction/TransactionManager.js +0 -267
  147. package/lib/transaction/index.js +0 -11
  148. package/lib/utils/objectid-converter.js +0 -632
  149. package/types/README.md +0 -122
  150. package/types/base.ts +0 -94
  151. package/types/batch.ts +0 -187
  152. package/types/cache.ts +0 -71
  153. package/types/chain.ts +0 -254
  154. package/types/collection.ts +0 -357
  155. package/types/expression.ts +0 -109
  156. package/types/function-cache.d.ts +0 -135
  157. package/types/lock.ts +0 -95
  158. package/types/model/definition.ts +0 -152
  159. package/types/model/index.ts +0 -10
  160. package/types/model/instance.ts +0 -121
  161. package/types/model/relations.ts +0 -121
  162. package/types/model/virtuals.ts +0 -32
  163. package/types/monsqlize.ts +0 -245
  164. package/types/options.ts +0 -192
  165. package/types/pagination.ts +0 -154
  166. package/types/pool.ts +0 -125
  167. package/types/query.ts +0 -71
  168. package/types/saga.ts +0 -125
  169. package/types/stream.ts +0 -64
  170. package/types/sync.ts +0 -79
  171. package/types/transaction.ts +0 -79
  172. package/types/write.ts +0 -77
@@ -0,0 +1,103 @@
1
+ import type { ChangeStreamDocument, Document, MongoClientOptions } from 'mongodb';
2
+
3
+ import type { LoggerLike } from './base';
4
+
5
+ export type SyncChangeEvent<TDocument extends Document = Document> = ChangeStreamDocument<TDocument> & {
6
+ _id?: unknown;
7
+ operationType: 'insert' | 'update' | 'replace' | 'delete';
8
+ ns: {
9
+ db: string;
10
+ coll: string;
11
+ };
12
+ documentKey?: Record<string, unknown>;
13
+ fullDocument?: TDocument;
14
+ };
15
+
16
+ export interface SyncTargetHealthCheckConfig {
17
+ /** Whether to enable health checks; defaults to true. */
18
+ enabled?: boolean;
19
+ /** Health check interval in milliseconds; defaults to 30000. */
20
+ interval?: number;
21
+ /** Timeout for a single health check in milliseconds; defaults to 5000. */
22
+ timeout?: number;
23
+ /** Number of retries after failure; defaults to 3. */
24
+ retries?: number;
25
+ }
26
+
27
+ export interface SyncTargetConfig {
28
+ name: string;
29
+ uri?: string;
30
+ pool?: string;
31
+ databaseName?: string;
32
+ collections?: string[];
33
+ options?: MongoClientOptions;
34
+ apply?: (event: SyncChangeEvent, document: Record<string, unknown> | undefined) => Promise<void>;
35
+ /** Target node health check configuration. @since v1.0.8 */
36
+ healthCheck?: SyncTargetHealthCheckConfig;
37
+ }
38
+
39
+ export interface ResumeTokenRedisLike {
40
+ get(key: string): Promise<string | null> | string | null;
41
+ set(key: string, value: string): Promise<unknown> | unknown;
42
+ del?(key: string): Promise<unknown> | unknown;
43
+ }
44
+
45
+ export interface ResumeTokenConfig {
46
+ storage?: 'file' | 'redis';
47
+ path?: string;
48
+ redis?: ResumeTokenRedisLike;
49
+ key?: string;
50
+ }
51
+
52
+ export interface SyncConfig {
53
+ enabled: boolean;
54
+ targets: SyncTargetConfig[];
55
+ collections?: string[];
56
+ resumeToken?: ResumeTokenConfig;
57
+ filter?: (event: SyncChangeEvent) => boolean;
58
+ /**
59
+ * Transform a change-stream document before forwarding to sync targets.
60
+ * v1 form took a single argument (`doc => ...`); v2 added a second `event` argument.
61
+ * Signature is permissive (`any`) to accept both forms — v1 was never typed.
62
+ */
63
+ transform?: (document: any, event?: SyncChangeEvent) => any;
64
+ }
65
+
66
+ export interface SyncStats {
67
+ isRunning: boolean;
68
+ eventCount: number;
69
+ syncedCount: number;
70
+ errorCount: number;
71
+ startTime: Date | null;
72
+ lastEventTime: Date | null;
73
+ targets: Array<{
74
+ name: string;
75
+ syncCount: number;
76
+ errorCount: number;
77
+ lastSyncTime: Date | null;
78
+ lastError: Error | null;
79
+ successRate: string;
80
+ }>;
81
+ }
82
+
83
+ export declare function validateSyncConfig(config: SyncConfig): void;
84
+
85
+ export declare class ResumeTokenStore {
86
+ constructor(options?: ResumeTokenConfig & { logger?: LoggerLike | null; });
87
+ load(): Promise<unknown | null>;
88
+ save(token: unknown): Promise<void>;
89
+ clear(): Promise<void>;
90
+ }
91
+
92
+ export declare class ChangeStreamSyncManager {
93
+ constructor(options: {
94
+ db: unknown;
95
+ poolManager?: unknown;
96
+ config: SyncConfig;
97
+ logger?: LoggerLike | null;
98
+ });
99
+ start(): Promise<void>;
100
+ stop(): Promise<void>;
101
+ getStats(): SyncStats;
102
+ }
103
+
@@ -0,0 +1,132 @@
1
+ import type { CacheLike } from './runtime';
2
+ import type { LoggerLike } from './base';
3
+
4
+ /** Minimal MongoDB session contract used by the transaction layer. */
5
+ export interface MongoSession {
6
+ id: unknown;
7
+ inTransaction(): boolean;
8
+ startTransaction(options?: Record<string, unknown>): void;
9
+ commitTransaction(): Promise<void>;
10
+ abortTransaction(): Promise<void>;
11
+ endSession(): Promise<void>;
12
+ /** v1 compat — v1 callers read `session.transaction?.state`; populated by the underlying driver. */
13
+ transaction?: { state?: string;[key: string]: unknown };
14
+ }
15
+
16
+ /** Options forwarded to the MongoDB driver when starting a transaction session. */
17
+ export interface TransactionOptions {
18
+ readConcern?: {
19
+ level: 'local' | 'majority' | 'snapshot' | 'linearizable' | 'available';
20
+ };
21
+ readPreference?: 'primary' | 'primaryPreferred' | 'secondary' | 'secondaryPreferred' | 'nearest';
22
+ causalConsistency?: boolean;
23
+ /** Maximum transaction duration in milliseconds before an automatic abort. */
24
+ maxDuration?: number;
25
+ /** @alias maxDuration — v1 compat field */
26
+ timeout?: number;
27
+ enableRetry?: boolean;
28
+ maxRetries?: number;
29
+ retryDelay?: number;
30
+ retryBackoff?: number;
31
+ enableCacheLock?: boolean;
32
+ lockCleanupInterval?: number;
33
+ writeConcern?: Record<string, unknown>;
34
+ }
35
+
36
+ /** Snapshot of a transaction's current state. */
37
+ export interface TransactionInfo {
38
+ id: string;
39
+ status: 'pending' | 'started' | 'committed' | 'aborted';
40
+ duration: number;
41
+ sessionId: string;
42
+ }
43
+
44
+ /** Aggregate statistics for all transactions managed by a `TransactionManager`. */
45
+ export interface TransactionStats {
46
+ totalTransactions: number;
47
+ successfulTransactions: number;
48
+ failedTransactions: number;
49
+ activeTransactions: number;
50
+ averageDuration: number;
51
+ }
52
+
53
+ /**
54
+ * In-memory lock tracker used to serialise cache invalidation across transaction boundaries.
55
+ * Attached to `TransactionManager`; locks are auto-released when a transaction commits or aborts.
56
+ */
57
+ export declare class CacheLockManager {
58
+ constructor(options?: { logger?: LoggerLike | null; maxDuration?: number; cleanupInterval?: number; });
59
+ /** Register a lock for `key` owned by `owner`. */
60
+ addLock(key: string, owner: { id?: unknown; } | string): void;
61
+ /** Return `true` if `key` is currently locked. */
62
+ isLocked(key: string): boolean;
63
+ /** Release all locks held by `owner`. */
64
+ releaseLocks(owner: { id?: unknown; } | string): void;
65
+ /** Return lock usage statistics. */
66
+ getStats(): { totalLocks: number; activeLocks: number; maxDuration: number; };
67
+ /** Release all locks immediately. */
68
+ clear(): void;
69
+ /** Stop the background cleanup timer. */
70
+ stop(): void;
71
+ }
72
+
73
+ /** Represents a single MongoDB transaction session with optional cache-lock integration. */
74
+ export declare class Transaction {
75
+ readonly id: string;
76
+ readonly session: MongoSession;
77
+ readonly state: 'pending' | 'active' | 'committed' | 'aborted';
78
+ constructor(session: MongoSession, options?: {
79
+ cache?: CacheLike | null;
80
+ logger?: LoggerLike | null;
81
+ lockManager?: CacheLockManager | null;
82
+ timeout?: number;
83
+ });
84
+ /** Begin the transaction (starts the MongoDB session transaction). */
85
+ start(): Promise<void>;
86
+ /** Commit the transaction; replays recorded cache invalidations on success. */
87
+ commit(): Promise<void>;
88
+ /** Abort the transaction and discard pending cache invalidations. */
89
+ abort(): Promise<void>;
90
+ /** Alias for `commit()` — v1 compat shorthand. */
91
+ end(): Promise<void>;
92
+ /** Record a cache-invalidation pattern to be replayed on commit. */
93
+ recordInvalidation(pattern: string): Promise<void>;
94
+ /** Return the elapsed duration in milliseconds since the transaction started. */
95
+ getDuration(): number;
96
+ /** Return a snapshot of the transaction's current state and metadata. */
97
+ getInfo(): TransactionInfo;
98
+ /** Return v1-compatible per-transaction statistics. */
99
+ getStats(): {
100
+ id: string;
101
+ state: 'pending' | 'active' | 'committed' | 'aborted';
102
+ duration: number;
103
+ hasWriteOperation: boolean;
104
+ operationCount: number;
105
+ lockedKeysCount: number;
106
+ };
107
+ }
108
+
109
+ /** Manages the lifecycle of MongoDB transactions, including retry and session pooling. */
110
+ export declare class TransactionManager {
111
+ constructor(options: {
112
+ client: unknown;
113
+ cache?: CacheLike | null;
114
+ logger?: LoggerLike | null;
115
+ lockManager?: CacheLockManager | null;
116
+ maxDuration?: number;
117
+ enableRetry?: boolean;
118
+ maxRetries?: number;
119
+ retryDelay?: number;
120
+ retryBackoff?: number;
121
+ });
122
+ /** Open a new transaction session. */
123
+ startSession(options?: TransactionOptions): Promise<Transaction>;
124
+ /** Execute `callback` inside a transaction; commits on success, aborts on failure. */
125
+ withTransaction<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
126
+ /** Return all currently active (uncommitted) transactions. */
127
+ getActiveTransactions(): Transaction[];
128
+ /** Abort all active transactions immediately. */
129
+ abortAll(): Promise<void>;
130
+ /** Return aggregate transaction statistics. */
131
+ getStats(): TransactionStats;
132
+ }
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "monsqlize",
3
- "version": "1.3.0",
4
- "description": "A lightweight MongoDB ORM with multi-level caching, transaction support, distributed features, Saga distributed transactions, unified expression system with 122 operators, and universal function caching (100% MongoDB support)",
5
- "main": "lib/index.js",
6
- "module": "index.mjs",
3
+ "version": "2.0.0",
4
+ "description": "TypeScript-native MongoDB ODM with multi-level caching (cache-hub), distributed locks, Saga orchestration, unified expression system (122 operators), connection pool management, ChangeStream sync, slow-query logging, and full v1 API compatibility",
7
5
  "type": "commonjs",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.mjs",
8
+ "types": "./dist/types/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "require": "./lib/index.js",
11
- "import": "./index.mjs",
12
- "types": "./index.d.ts"
11
+ "types": "./dist/types/index.d.ts",
12
+ "require": "./dist/cjs/index.cjs",
13
+ "import": "./dist/esm/index.mjs"
13
14
  },
14
15
  "./package.json": "./package.json"
15
- },
16
- "types": "./index.d.ts",
17
- "files": [
18
- "lib/",
19
- "types/",
20
- "index.d.ts",
21
- "index.mjs",
22
- "README.md",
23
- "LICENSE",
16
+ },
17
+ "files": [
18
+ "dist/**/*.cjs",
19
+ "dist/**/*.mjs",
20
+ "dist/**/*.d.ts",
21
+ "changelogs/v2.0.0.md",
22
+ "README.md",
23
+ "LICENSE",
24
24
  "CHANGELOG.md"
25
25
  ],
26
26
  "keywords": [
@@ -38,84 +38,82 @@
38
38
  "api"
39
39
  ],
40
40
  "author": "vext.js Team",
41
- "license": "MIT",
41
+ "license": "Apache-2.0",
42
42
  "repository": {
43
43
  "type": "git",
44
- "url": "https://github.com/vextjs/monSQLize.git"
44
+ "url": "git+https://github.com/vextjs/monSQLize.git"
45
45
  },
46
46
  "bugs": {
47
47
  "url": "https://github.com/vextjs/monSQLize/issues"
48
48
  },
49
- "homepage": "https://github.com/vextjs/monSQLize#readme",
49
+ "homepage": "https://vextjs.github.io/monSQLize/",
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "registry": "https://registry.npmjs.org/"
53
+ },
50
54
  "engines": {
51
- "node": ">=16.0.0"
55
+ "node": ">=18.0.0"
52
56
  },
53
57
  "scripts": {
54
- "test": "node test/run-tests.js",
55
- "test:unit": "node test/run-tests.js",
56
- "test:performance": "node test/performance/transaction-benchmark.js",
57
- "test:coverage": "nyc --reporter=text --reporter=lcov node test/run-tests.js",
58
- "coverage": "nyc --reporter=text --reporter=lcov --reporter=html node test/run-tests.js",
59
- "benchmark": "node test/benchmark/run-benchmarks.js",
60
- "test:compatibility": "node test/compatibility/run-node-test.js",
61
- "test:compatibility:node": "node scripts/test-node-versions.js",
62
- "test:compatibility:driver": "node scripts/test-driver-versions-simple.js",
63
- "test:compatibility:driver:full": "node scripts/test-driver-versions-simple.js --drivers=4.17.2,5.9.2,6.17.0,7.0.0",
64
- "test:compatibility:driver:quick": "node test/compatibility/run-driver-test.js",
65
- "test:compatibility:server": "node scripts/test-server-versions.js --use-memory-server",
66
- "test:compatibility:server:quick": "node test/compatibility/run-server-test.js",
67
- "test:compatibility:server:docker": "node scripts/test-server-versions.js",
68
- "lint": "eslint lib/ test/ --ext .js",
69
- "lint:fix": "eslint lib/ test/ --ext .js --fix",
70
- "type-check": "tsc",
71
- "postpublish": "echo '✅ 发布成功!请创建 GitHub Release: https://github.com/vextjs/monSQLize/releases/new?tag=v'$npm_package_version"
72
- },
58
+ "check:sizes": "node scripts/check-file-sizes.cjs",
59
+ "check:sizes:strict": "node scripts/check-file-sizes.cjs --strict",
60
+ "build": "node scripts/build-p1.cjs",
61
+ "build:tests": "node scripts/compile-tests.cjs",
62
+ "lint": "eslint . --ignore-pattern .generated/** --ignore-pattern dist/**",
63
+ "lint:fix": "eslint . --fix --ignore-pattern .generated/** --ignore-pattern dist/**",
64
+ "test:runtime": "npm run build && npm run build:tests && node --test .generated/test-dist/test/smoke/root-cjs.test.js .generated/test-dist/test/smoke/root-esm.test.js .generated/test-dist/test/smoke/pack-artifacts.test.js",
65
+ "test:compatibility": "npm run build && npm run build:tests && node --test .generated/test-dist/test/compatibility/exports/exports.test.js .generated/test-dist/test/compatibility/matrix.test.js",
66
+ "probe:server-matrix": "node scripts/validation/probe-memory-server-matrix.cjs",
67
+ "test:server-matrix": "node scripts/validation/run-memory-server-matrix.cjs",
68
+ "test:real-env:private": "node scripts/validation/run-private-real-env-checks.cjs",
69
+ "test:examples": "npm run build && tsc -p tsconfig.examples.json && node .generated/examples-dist/examples/quick-start/basic-connect.js && node .generated/examples-dist/examples/cache/with-cache.js && node .generated/examples-dist/examples/docs/insert.js && node .generated/examples-dist/examples/docs/insert-many.js && node .generated/examples-dist/examples/docs/update.js && node .generated/examples-dist/examples/docs/update-one.js && node .generated/examples-dist/examples/docs/delete.js && node .generated/examples-dist/examples/docs/delete-many.js && node .generated/examples-dist/examples/docs/upsert.js && node .generated/examples-dist/examples/docs/upsert-one.js && node .generated/examples-dist/examples/docs/find.js && node .generated/examples-dist/examples/docs/find-one.js && node .generated/examples-dist/examples/docs/find-one-by-id.js && node .generated/examples-dist/examples/docs/find-by-ids.js && node .generated/examples-dist/examples/docs/find-page.js && node .generated/examples-dist/examples/docs/find-and-count.js && node .generated/examples-dist/examples/docs/count.js && node .generated/examples-dist/examples/docs/distinct.js && node .generated/examples-dist/examples/docs/explain.js && node .generated/examples-dist/examples/docs/aggregate.js && node .generated/examples-dist/examples/docs/chaining-api.js && node .generated/examples-dist/examples/docs/expression-functions.js && node .generated/examples-dist/examples/docs/model.js && node .generated/examples-dist/examples/docs/collection-management.js && node .generated/examples-dist/examples/docs/bookmarks.js && node .generated/examples-dist/examples/docs/transaction.js && node .generated/examples-dist/examples/docs/transaction-rollback.js && node .generated/examples-dist/examples/docs/slow-query-log.js && node .generated/examples-dist/examples/docs/watch.js && node .generated/examples-dist/examples/docs/aggregate-advanced.js && node .generated/examples-dist/examples/docs/batch-operations.js && node .generated/examples-dist/examples/docs/soft-delete.js && node .generated/examples-dist/examples/docs/increment-one.js && node .generated/examples-dist/examples/docs/populate-relations.js && node .generated/examples-dist/examples/docs/saga.js && node .generated/examples-dist/examples/docs/lock.js && node .generated/examples-dist/examples/docs/lock-timeout.js && node .generated/examples-dist/examples/docs/cache-multilevel.js && node .generated/examples-dist/examples/docs/objectid.js && node .generated/examples-dist/examples/docs/pool.js && node .generated/examples-dist/examples/docs/pool-fallback.js && node .generated/examples-dist/examples/docs/sync.js && node .generated/examples-dist/examples/docs/sync-target-failure.js",
70
+ "test:performance": "npm run build && npm run build:tests && node .generated/test-dist/test/performance/baselines/function-cache.benchmark.js",
71
+ "test:unit": "npm run build && npm run build:tests && node --test .generated/test-dist/test/unit/expression/expression.test.js .generated/test-dist/test/unit/expression/operators.test.js .generated/test-dist/test/unit/errors/errors.test.js .generated/test-dist/test/unit/management/management.test.js .generated/test-dist/test/unit/writes/batch.test.js .generated/test-dist/test/unit/cache/cache.test.js .generated/test-dist/test/unit/cache/cache-refactor-guard.test.js .generated/test-dist/test/unit/coverage/core-helpers.test.js .generated/test-dist/test/unit/function-cache/function-cache.test.js .generated/test-dist/test/unit/model/model-registry.test.js .generated/test-dist/test/unit/lock/lock.test.js .generated/test-dist/test/unit/transaction/transaction.test.js .generated/test-dist/test/unit/pool/pool.test.js .generated/test-dist/test/unit/runtime/runtime-compat.test.js .generated/test-dist/test/unit/sync/sync.test.js .generated/test-dist/test/unit/slow-query-log/slow-query-log.test.js .generated/test-dist/test/unit/slow-query-log/slow-query-log-behavior.test.js .generated/test-dist/test/unit/saga/saga.test.js .generated/test-dist/test/unit/count-queue/count-queue.test.js .generated/test-dist/test/unit/model/model-softdelete-versioning.test.js .generated/test-dist/test/unit/function-cache/function-cache-behavior.test.js .generated/test-dist/test/unit/saga/saga-behavior.test.js .generated/test-dist/test/unit/lock/lock-distributed.test.js .generated/test-dist/test/unit/coverage/capability-wiring.test.js .generated/test-dist/test/unit/pool/pool-stats.test.js .generated/test-dist/test/unit/coverage/pure-functions.test.js",
72
+ "test:integration": "npm run build && npm run build:tests && node --test --test-concurrency=1 .generated/test-dist/test/integration/cache/cache.test.js .generated/test-dist/test/integration/cache/cache-behavior.test.js .generated/test-dist/test/integration/mongodb/connect.test.js .generated/test-dist/test/integration/mongodb/queries.test.js .generated/test-dist/test/integration/mongodb/management.test.js .generated/test-dist/test/integration/mongodb/writes-batch.test.js .generated/test-dist/test/integration/mongodb/find.test.js .generated/test-dist/test/integration/mongodb/find-one.test.js .generated/test-dist/test/integration/mongodb/find-page.test.js .generated/test-dist/test/integration/mongodb/aggregate.test.js .generated/test-dist/test/integration/mongodb/chaining.test.js .generated/test-dist/test/integration/mongodb/insert.test.js .generated/test-dist/test/integration/mongodb/update.test.js .generated/test-dist/test/integration/mongodb/delete.test.js .generated/test-dist/test/integration/mongodb/update-pipeline.test.js .generated/test-dist/test/integration/model/model-features.test.js .generated/test-dist/test/integration/transaction/transaction.test.js .generated/test-dist/test/integration/pool/pool.test.js .generated/test-dist/test/integration/pool/pool-behavior.test.js .generated/test-dist/test/integration/watch/watch-native.test.js .generated/test-dist/test/integration/runtime/runtime-core-regression.test.js .generated/test-dist/test/integration/sync/sync.test.js .generated/test-dist/test/integration/slow-query-log/slow-query-log.test.js .generated/test-dist/test/integration/model/model-crud-extended.test.js .generated/test-dist/test/integration/mongodb/management-complete.test.js .generated/test-dist/test/integration/runtime/runtime-methods-extended.test.js .generated/test-dist/test/integration/mongodb/find-page-advanced.test.js",
73
+ "test:refactor-guard": "npm run build && npm run build:tests && node --test --test-concurrency=1 .generated/test-dist/test/compatibility/exports/exports.test.js .generated/test-dist/test/integration/model/model-features.test.js .generated/test-dist/test/integration/runtime/runtime-core-regression.test.js .generated/test-dist/test/integration/sync/sync.test.js",
74
+ "test:refactor-guard:cache": "npm run build && npm run build:tests && node --test .generated/test-dist/test/unit/cache/cache-refactor-guard.test.js",
75
+ "test:coverage": "npm run build && npm run build:tests && c8 --reporter=text --reporter=lcov --reporter=json-summary --check-coverage --lines 95 --statements 95 --functions 95 --branches 95 node test/run-tests.cjs",
76
+ "test": "npm run build && npm run build:tests && node test/run-tests.cjs",
77
+ "type-check": "npm run build && tsc -p tsconfig.json --noEmit && tsd --files test/types/root-import.test-d.ts --files test/types/cache-usage.test-d.ts --files test/types/model-usage.test-d.ts --files test/types/pool-usage.test-d.ts --files test/types/sync-usage.test-d.ts --files test/types/slow-query-log-usage.test-d.ts --files test/types/saga-usage.test-d.ts",
78
+ "check:test-language": "node scripts/check-test-language.cjs",
79
+ "verify:fast": "npm run lint && npm run type-check && npm run check:sizes:strict && npm run test:runtime && npm run test:compatibility && npm run test:refactor-guard && npm run test:refactor-guard:cache",
80
+ "verify:full": "npm run lint && npm run type-check && npm run check:sizes:strict && npm run test:coverage && npm run test:examples && npm run test:server-matrix",
81
+ "verify:release": "npm run verify:full && npm run test:real-env:private",
82
+ "verify": "npm run verify:full",
83
+ "release:preflight": "node scripts/release-preflight.cjs",
84
+ "prepublishOnly": "npm run release:preflight",
85
+ "release:publish": "npm run release:preflight && npm publish --ignore-scripts",
86
+ "postpublish": "echo '✅ 发布成功!请创建 GitHub Release: https://github.com/vextjs/monSQLize/releases/new?tag=v'$npm_package_version"
87
+ },
73
88
  "peerDependenciesMeta": {
74
89
  "ioredis": {
75
90
  "optional": true
91
+ },
92
+ "ssh2": {
93
+ "optional": true
76
94
  }
77
95
  },
78
96
  "optionalDependencies": {
79
- "ioredis": "^5.8.2"
97
+ "ioredis": "^5.8.2",
98
+ "ssh2": "^1.17.0"
80
99
  },
81
100
  "devDependencies": {
82
101
  "@eslint/js": "^9.39.1",
83
102
  "@types/node": "^25.0.1",
84
- "benchmark": "^2.1.4",
85
- "chai": "^6.2.1",
103
+ "@types/semver": "^7.7.1",
104
+ "c8": "^11.0.0",
105
+ "chai": "^6.2.2",
106
+ "esbuild": "^0.25.5",
86
107
  "eslint": "^9.39.1",
87
- "mocha": "^11.7.5",
88
- "mongodb-memory-server": "^10.1.2",
89
- "nyc": "^15.1.0",
90
- "sinon": "^21.0.0",
108
+ "mongodb-memory-server": "^11.1.0",
109
+ "sinon": "^22.0.0",
91
110
  "tsd": "^0.33.0",
92
111
  "typescript": "^5.9.3"
93
112
  },
94
- "nyc": {
95
- "include": [
96
- "lib/**/*.js"
97
- ],
98
- "exclude": [
99
- "test/**",
100
- "examples/**",
101
- "scripts/**",
102
- "reports/**"
103
- ],
104
- "reporter": [
105
- "text",
106
- "lcov",
107
- "html"
108
- ],
109
- "check-coverage": true,
110
- "lines": 70,
111
- "statements": 70,
112
- "functions": 70,
113
- "branches": 65
114
- },
115
113
  "dependencies": {
116
114
  "async-lock": "^1.4.1",
115
+ "cache-hub": "^1.0.0",
117
116
  "mongodb": "^6.21.0",
118
- "schema-dsl": "^1.2.4",
119
- "ssh2": "^1.17.0"
117
+ "schema-dsl": "^2.0.3"
120
118
  }
121
119
  }
package/index.d.ts DELETED
@@ -1,206 +0,0 @@
1
- declare module 'monsqlize' {
2
- // ========================================
3
- // 导入所有模块
4
- // ========================================
5
- import type * as Base from './types/base';
6
- import type * as Expression from './types/expression';
7
- import type * as Cache from './types/cache';
8
- import type * as Options from './types/options';
9
- import type * as Query from './types/query';
10
- import type * as Write from './types/write';
11
- import type * as Batch from './types/batch';
12
- import type * as Pagination from './types/pagination';
13
- import type * as Stream from './types/stream';
14
- import type * as Transaction from './types/transaction';
15
- import type * as Lock from './types/lock';
16
- import type * as Chain from './types/chain';
17
- import type * as Pool from './types/pool';
18
- import type * as Saga from './types/saga';
19
- import type * as Sync from './types/sync';
20
- import type * as Collection from './types/collection';
21
- import type * as Model from './types/model';
22
- import type * as MonSQLizeModule from './types/monsqlize';
23
- import type * as FunctionCacheTypes from './types/function-cache';
24
-
25
- // ========================================
26
- // 基础类型
27
- // ========================================
28
- export import DbType = Base.DbType;
29
- export import ExpressionObject = Base.ExpressionObject;
30
- export import ExpressionContext = Base.ExpressionContext;
31
- export import ExpressionFunction = Base.ExpressionFunction;
32
- export import LoggerLike = Base.LoggerLike;
33
- export import LoggerOptions = Base.LoggerOptions;
34
- export import ErrorCodes = Base.ErrorCodes;
35
- export import MonSQLizeError = Base.MonSQLizeError;
36
-
37
- // ========================================
38
- // 表达式系统
39
- // ========================================
40
- export import UnifiedExpressionOperators = Expression.UnifiedExpressionOperators;
41
-
42
- // ========================================
43
- // 缓存相关
44
- // ========================================
45
- export import CacheLike = Cache.CacheLike;
46
- export import MemoryCacheOptions = Cache.MemoryCacheOptions;
47
- export import WritePolicy = Cache.WritePolicy;
48
- export import MultiLevelCachePolicy = Cache.MultiLevelCachePolicy;
49
- export import MultiLevelCacheOptions = Cache.MultiLevelCacheOptions;
50
-
51
- // ========================================
52
- // 配置选项
53
- // ========================================
54
- export import SSHConfig = Options.SSHConfig;
55
- export import TransactionOptions = Options.TransactionOptions;
56
- export import BaseOptions = Options.BaseOptions;
57
-
58
- // ========================================
59
- // 查询选项
60
- // ========================================
61
- export import MetaOptions = Query.MetaOptions;
62
- export import FindOptions = Query.FindOptions;
63
- export import CountOptions = Query.CountOptions;
64
- export import AggregateOptions = Query.AggregateOptions;
65
- export import DistinctOptions = Query.DistinctOptions;
66
-
67
- // ========================================
68
- // 写操作
69
- // ========================================
70
- export import WriteConcern = Write.WriteConcern;
71
- export import InsertOneSimplifiedOptions = Write.InsertOneSimplifiedOptions;
72
- export import InsertOneOptions = Write.InsertOneOptions;
73
- export import InsertOneResult = Write.InsertOneResult;
74
- export import InsertManySimplifiedOptions = Write.InsertManySimplifiedOptions;
75
- export import InsertManyOptions = Write.InsertManyOptions;
76
- export import InsertManyResult = Write.InsertManyResult;
77
-
78
- // ========================================
79
- // 批量操作
80
- // ========================================
81
- export import BatchProgress = Batch.BatchProgress;
82
- export import RetryInfo = Batch.RetryInfo;
83
- export import InsertBatchOptions = Batch.InsertBatchOptions;
84
- export import UpdateBatchOptions = Batch.UpdateBatchOptions;
85
- export import DeleteBatchOptions = Batch.DeleteBatchOptions;
86
- export import InsertBatchResult = Batch.InsertBatchResult;
87
- export import UpdateBatchResult = Batch.UpdateBatchResult;
88
- export import DeleteBatchResult = Batch.DeleteBatchResult;
89
-
90
- // ========================================
91
- // 分页系统
92
- // ========================================
93
- export import BookmarkKeyDims = Pagination.BookmarkKeyDims;
94
- export import PrewarmBookmarksResult = Pagination.PrewarmBookmarksResult;
95
- export import ListBookmarksResult = Pagination.ListBookmarksResult;
96
- export import ClearBookmarksResult = Pagination.ClearBookmarksResult;
97
- export import JumpOptions = Pagination.JumpOptions;
98
- export import OffsetJumpOptions = Pagination.OffsetJumpOptions;
99
- export import TotalsOptions = Pagination.TotalsOptions;
100
- export import FindPageOptions = Pagination.FindPageOptions;
101
- export import MetaInfo = Pagination.MetaInfo;
102
- export import TotalsInfo = Pagination.TotalsInfo;
103
- export import PageInfo = Pagination.PageInfo;
104
- export import PageResult = Pagination.PageResult;
105
- export import ResultWithMeta = Pagination.ResultWithMeta;
106
-
107
- // ========================================
108
- // 流式查询
109
- // ========================================
110
- export import StreamOptions = Stream.StreamOptions;
111
- export import ExplainOptions = Stream.ExplainOptions;
112
- export import ExplainResult = Stream.ExplainResult;
113
-
114
- // ========================================
115
- // 事务
116
- // ========================================
117
- export import MongoSession = Transaction.MongoSession;
118
- export import Transaction = Transaction.Transaction;
119
-
120
- // ========================================
121
- // 业务锁
122
- // ========================================
123
- export import LockOptions = Lock.LockOptions;
124
- export import Lock = Lock.Lock;
125
- export import LockStats = Lock.LockStats;
126
- export import LockAcquireError = Lock.LockAcquireError;
127
- export import LockTimeoutError = Lock.LockTimeoutError;
128
-
129
- // ========================================
130
- // 链式调用
131
- // ========================================
132
- export import CollationOptions = Chain.CollationOptions;
133
- export import FindChain = Chain.FindChain;
134
- export import AggregateChain = Chain.AggregateChain;
135
-
136
- // ========================================
137
- // 连接池
138
- // ========================================
139
- export import PoolRole = Pool.PoolRole;
140
- export import PoolStrategy = Pool.PoolStrategy;
141
- export import FallbackStrategy = Pool.FallbackStrategy;
142
- export import PoolConfig = Pool.PoolConfig;
143
- export import ConnectionPoolManagerOptions = Pool.ConnectionPoolManagerOptions;
144
- export import PoolHealthStatus = Pool.PoolHealthStatus;
145
- export import PoolStats = Pool.PoolStats;
146
- export import ConnectionPoolManager = Pool.ConnectionPoolManager;
147
-
148
- // ========================================
149
- // Saga 事务
150
- // ========================================
151
- export import SagaStep = Saga.SagaStep;
152
- export import SagaDefinition = Saga.SagaDefinition;
153
- export import SagaContext = Saga.SagaContext;
154
- export import SagaResult = Saga.SagaResult;
155
- export import SagaOrchestratorOptions = Saga.SagaOrchestratorOptions;
156
- export import SagaOrchestrator = Saga.SagaOrchestrator;
157
-
158
- // ========================================
159
- // 数据同步
160
- // ========================================
161
- export import SyncTarget = Sync.SyncTarget;
162
- export import ResumeTokenConfig = Sync.ResumeTokenConfig;
163
- export import SyncConfig = Sync.SyncConfig;
164
- export import SyncStats = Sync.SyncStats;
165
-
166
- // ========================================
167
- // Collection API
168
- // ========================================
169
- export import HealthView = Collection.HealthView;
170
- export import CollectionAccessor = Collection.CollectionAccessor;
171
- export import Collection = Collection.Collection;
172
- export import DbAccessor = Collection.DbAccessor;
173
-
174
- // ========================================
175
- // Model 层
176
- // ========================================
177
- export import SchemaDSL = Model.SchemaDSL;
178
- export import DefaultValue = Model.DefaultValue;
179
- export import HookContext = Model.HookContext;
180
- export import ValidationResult = Model.ValidationResult;
181
- export import ModelConnection = Model.ModelConnection;
182
- export import ModelDefinition = Model.ModelDefinition;
183
- export import RelationConfig = Model.RelationConfig;
184
- export import PopulateConfig = Model.PopulateConfig;
185
- export import PopulateProxy = Model.PopulateProxy;
186
- export import VirtualConfig = Model.VirtualConfig;
187
- export import ModelInstance = Model.ModelInstance;
188
- export import Model = Model.Model;
189
-
190
- // ========================================
191
- // MonSQLize 主类
192
- // ========================================
193
- export import MonSQLize = MonSQLizeModule.MonSQLize;
194
- export default MonSQLizeModule.MonSQLize;
195
-
196
- // ========================================
197
- // 函数缓存(v1.1.4+)
198
- // ========================================
199
- export import WithCacheOptions = FunctionCacheTypes.WithCacheOptions;
200
- export import CacheStats = FunctionCacheTypes.CacheStats;
201
- export import FunctionCacheOptions = FunctionCacheTypes.FunctionCacheOptions;
202
- export import CachedFunction = FunctionCacheTypes.CachedFunction;
203
- export import withCache = FunctionCacheTypes.withCache;
204
- export import FunctionCache = FunctionCacheTypes.FunctionCache;
205
- }
206
-