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,115 @@
1
+ /**
2
+ * Unified expression operator type definitions.
3
+ * @module types/expression
4
+ * @since v1.0.9
5
+ */
6
+
7
+ /**
8
+ * All 122 expression operators supported by the MonSQLize expression system
9
+ * (100% MongoDB coverage).
10
+ *
11
+ * @since v1.0.9
12
+ */
13
+ export namespace UnifiedExpressionOperators {
14
+ /** Ternary conditional operator. */
15
+ export type TernaryOperator = '? :';
16
+
17
+ /** Nullish coalescing operator. */
18
+ export type NullishCoalescing = '??';
19
+
20
+ /** Comparison operators. */
21
+ export type ComparisonOperators = '>' | '>=' | '<' | '<=' | '===' | '!==';
22
+
23
+ /** Logical operators. */
24
+ export type LogicalOperators = '&&' | '||' | 'NOT';
25
+
26
+ /** Arithmetic operators. */
27
+ export type ArithmeticOperators = '+' | '-' | '*' | '/' | '%';
28
+
29
+ /** Math functions (8). */
30
+ export type MathFunctions = 'ABS' | 'CEIL' | 'FLOOR' | 'ROUND' | 'SQRT' | 'POW' | 'LOG' | 'LOG10';
31
+
32
+ /** Basic string functions (12). */
33
+ export type StringBasicFunctions =
34
+ | 'CONCAT' | 'UPPER' | 'LOWER' | 'TRIM' | 'SUBSTR' | 'LENGTH'
35
+ | 'SPLIT' | 'REPLACE' | 'INDEX_OF_STR' | 'LTRIM' | 'RTRIM' | 'SUBSTR_CP';
36
+
37
+ /** Extended string functions (3). @since v1.1.0 */
38
+ export type StringExtendedFunctions = 'STR_LEN_BYTES' | 'STR_LEN_CP' | 'SUBSTR_BYTES';
39
+
40
+ /** Basic array functions (10). */
41
+ export type ArrayBasicFunctions =
42
+ | 'SIZE' | 'ARRAY_ELEM_AT' | 'IN' | 'SLICE' | 'FIRST' | 'LAST'
43
+ | 'FILTER' | 'MAP' | 'INDEX_OF' | 'CONCAT_ARRAYS';
44
+
45
+ /** Extended array functions (4). @since v1.1.0 */
46
+ export type ArrayExtendedFunctions = 'REDUCE' | 'ZIP' | 'REVERSE_ARRAY' | 'RANGE';
47
+
48
+ /** Basic date functions (6). */
49
+ export type DateBasicFunctions = 'YEAR' | 'MONTH' | 'DAY_OF_MONTH' | 'HOUR' | 'MINUTE' | 'SECOND';
50
+
51
+ /** Advanced date functions (5). @since v1.1.0 */
52
+ export type DateAdvancedFunctions =
53
+ | 'DATE_ADD' | 'DATE_SUBTRACT' | 'DATE_DIFF' | 'DATE_TO_STRING' | 'DATE_FROM_STRING';
54
+
55
+ /** Extended date functions (8). @since v1.1.0 */
56
+ export type DateExtendedFunctions =
57
+ | 'DATE_FROM_PARTS' | 'DATE_TO_PARTS' | 'ISO_WEEK' | 'ISO_WEEK_YEAR'
58
+ | 'ISO_DAY_OF_WEEK' | 'DAY_OF_WEEK' | 'DAY_OF_YEAR' | 'WEEK';
59
+
60
+ /** Type inspection functions (5). */
61
+ export type TypeCheckFunctions = 'TYPE' | 'IS_NUMBER' | 'IS_ARRAY' | 'EXISTS' | 'NOT';
62
+
63
+ /** Basic type conversion functions. */
64
+ export type TypeConversionBasicFunctions = 'TO_INT' | 'TO_STRING' | 'OBJECT_TO_ARRAY' | 'ARRAY_TO_OBJECT';
65
+
66
+ /** Extended type conversion functions (7). @since v1.1.0 */
67
+ export type TypeConversionExtendedFunctions =
68
+ | 'TO_BOOL' | 'TO_DATE' | 'TO_DOUBLE' | 'TO_DECIMAL'
69
+ | 'TO_LONG' | 'TO_OBJECT_ID' | 'CONVERT';
70
+
71
+ /** Logical extended functions (2). @since v1.1.0 */
72
+ export type LogicalExtendedFunctions = 'ALL_ELEMENTS_TRUE' | 'ANY_ELEMENT_TRUE';
73
+
74
+ /** Conditional functions (3). */
75
+ export type ConditionalFunctions = 'SWITCH' | 'COND' | 'IF_NULL';
76
+
77
+ /** Object manipulation functions (5). */
78
+ export type ObjectOperationFunctions =
79
+ | 'MERGE_OBJECTS' | 'SET_FIELD' | 'UNSET_FIELD' | 'GET_FIELD' | 'OBJECT_TO_ARRAY';
80
+
81
+ /** Set operation functions (5). */
82
+ export type SetOperationFunctions =
83
+ | 'SET_UNION' | 'SET_DIFFERENCE' | 'SET_EQUALS' | 'SET_INTERSECTION' | 'SET_IS_SUBSET';
84
+
85
+ /** Advanced operation functions (5). @since v1.1.0 */
86
+ export type AdvancedOperationFunctions = 'LET' | 'LITERAL' | 'RAND' | 'SAMPLE_RATE' | 'REGEX';
87
+
88
+ /** Aggregate accumulator functions (7). */
89
+ export type AggregateFunctions = 'SUM' | 'AVG' | 'MAX' | 'MIN' | 'COUNT' | 'PUSH' | 'ADD_TO_SET';
90
+
91
+ /** Union of all supported operator strings. */
92
+ export type AllOperators =
93
+ | TernaryOperator
94
+ | NullishCoalescing
95
+ | ComparisonOperators
96
+ | LogicalOperators
97
+ | ArithmeticOperators
98
+ | MathFunctions
99
+ | StringBasicFunctions
100
+ | StringExtendedFunctions
101
+ | ArrayBasicFunctions
102
+ | ArrayExtendedFunctions
103
+ | DateBasicFunctions
104
+ | DateAdvancedFunctions
105
+ | DateExtendedFunctions
106
+ | TypeCheckFunctions
107
+ | TypeConversionBasicFunctions
108
+ | TypeConversionExtendedFunctions
109
+ | LogicalExtendedFunctions
110
+ | ConditionalFunctions
111
+ | ObjectOperationFunctions
112
+ | SetOperationFunctions
113
+ | AdvancedOperationFunctions
114
+ | AggregateFunctions;
115
+ }
@@ -0,0 +1,23 @@
1
+ export * from './base';
2
+ export * from './collection';
3
+ export * from './expression';
4
+ export * from './lock';
5
+ export * from './model';
6
+ export * from './mongodb';
7
+ export * from './pool';
8
+ export * from './runtime';
9
+ export * from './saga';
10
+ export * from './slow-query-log';
11
+ export * from './sync';
12
+ export * from './transaction';
13
+ export * from './monsqlize';
14
+
15
+ export { default, MonSQLize } from './monsqlize';
16
+ export { Model, generateQueryHash, validateSyncConfig } from './runtime';
17
+
18
+ export type { Lock as LockContract } from './lock';
19
+ export type { ModelInstance as ModelAccessor, ModelInstance } from './model';
20
+ export type { SyncTargetConfig as SyncTarget } from './sync';
21
+ export type { Transaction as TransactionContract } from './transaction';
22
+ export type { MonSQLizeOptions as BaseOptions } from './monsqlize';
23
+
@@ -0,0 +1,74 @@
1
+ /** Options for acquiring or configuring a distributed lock. */
2
+ export interface LockOptions {
3
+ /** Lock TTL in milliseconds; the lock auto-releases after this duration. */
4
+ ttl?: number;
5
+ /** Number of retry attempts on acquire failure. */
6
+ retryTimes?: number;
7
+ /** Base delay between retries in milliseconds. */
8
+ retryDelay?: number;
9
+ /** Backoff multiplier applied to `retryDelay` on each successive retry. */
10
+ retryBackoff?: number;
11
+ /** When `true`, the callback is executed without a lock if acquisition fails (no-lock fallback). */
12
+ fallbackToNoLock?: boolean;
13
+ }
14
+
15
+ /** Aggregate statistics for a `LockManager` instance. */
16
+ export interface LockStats {
17
+ locksAcquired: number;
18
+ locksReleased: number;
19
+ lockChecks: number;
20
+ errors: number;
21
+ lockKeyPrefix: string;
22
+ maxDuration: number;
23
+ activeLocks: number;
24
+ }
25
+
26
+ /** Thrown when a lock cannot be acquired after all retry attempts are exhausted. */
27
+ export declare class LockAcquireError extends Error {
28
+ readonly code: 'LOCK_ACQUIRE_FAILED';
29
+ }
30
+
31
+ /** Thrown when a lock acquisition attempt times out. */
32
+ export declare class LockTimeoutError extends Error {
33
+ readonly code: 'LOCK_TIMEOUT';
34
+ }
35
+
36
+ /** Represents an acquired distributed lock; call `release()` to free it. */
37
+ export declare class Lock {
38
+ readonly key: string;
39
+ readonly lockId: string;
40
+ readonly ttl: number;
41
+ /** `true` after the lock has been released. v1 compat — exposed as readonly to prevent external mutation. */
42
+ readonly released: boolean;
43
+ /** Release the lock; returns `true` on success. */
44
+ release(): Promise<boolean>;
45
+ /** Extend the lock's TTL; returns `true` on success. */
46
+ renew(ttl?: number): Promise<boolean>;
47
+ /** Return `true` if the lock is still held (not yet released or expired). */
48
+ isHeld(): boolean;
49
+ /** Return the elapsed hold time in milliseconds since the lock was acquired. */
50
+ getHoldTime(): number;
51
+ }
52
+
53
+ /** Manages distributed locks backed by the in-memory cache or a Redis store. */
54
+ export declare class LockManager {
55
+ constructor(options?: { logger?: unknown; lockKeyPrefix?: string; maxDuration?: number; });
56
+ /** Execute `callback` while holding the lock for `key`; the lock is released automatically on completion. */
57
+ withLock<T>(key: string, callback: () => Promise<T>, options?: LockOptions): Promise<T>;
58
+ /** Acquire the lock for `key`, blocking until available or timeout/retries are exhausted. */
59
+ acquireLock(key: string, options?: LockOptions): Promise<Lock>;
60
+ /** Try to acquire the lock for `key` without blocking; returns `null` if already held. */
61
+ tryAcquireLock(key: string, options?: Omit<LockOptions, 'retryTimes'>): Promise<Lock | null>;
62
+ /** Return `true` if `key` is currently locked. */
63
+ isLocked(key: string): boolean;
64
+ /** Release the lock identified by `key` + `lockId`. */
65
+ releaseLock(key: string, lockId: string): Promise<boolean>;
66
+ /** Extend the TTL for the lock identified by `key` + `lockId`. */
67
+ renewLock(key: string, lockId: string, ttl: number): Promise<boolean>;
68
+ /** Return aggregate lock statistics. */
69
+ getStats(): LockStats;
70
+ /** Clear all active locks immediately. */
71
+ clear(): void;
72
+ /** Shut down the lock manager and release internal resources. */
73
+ close(): void;
74
+ }