monsqlize 1.3.1 → 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.
Files changed (114) hide show
  1. package/CHANGELOG.md +506 -235
  2. package/LICENSE +201 -21
  3. package/README.md +542 -928
  4. package/changelogs/README.md +163 -0
  5. package/changelogs/v2.0.0.md +222 -0
  6. package/changelogs/v2.0.1.md +39 -0
  7. package/dist/cjs/index.cjs +10788 -0
  8. package/dist/cjs/mongodb/common/transaction-aware.cjs +10 -0
  9. package/dist/cjs/transaction/CacheLockManager.cjs +100 -0
  10. package/dist/cjs/transaction/Transaction.cjs +158 -0
  11. package/dist/cjs/transaction/TransactionManager.cjs +298 -0
  12. package/dist/esm/index.mjs +10838 -0
  13. package/dist/types/base.d.ts +81 -0
  14. package/dist/types/collection.d.ts +1031 -0
  15. package/dist/types/expression.d.ts +115 -0
  16. package/dist/types/index.d.ts +23 -0
  17. package/dist/types/lock.d.ts +74 -0
  18. package/dist/types/model.d.ts +530 -0
  19. package/dist/types/mongodb.d.ts +49 -0
  20. package/dist/types/monsqlize.d.ts +491 -0
  21. package/dist/types/pool.d.ts +84 -0
  22. package/dist/types/runtime.d.ts +362 -0
  23. package/dist/types/saga.d.ts +143 -0
  24. package/dist/types/slow-query-log.d.ts +126 -0
  25. package/dist/types/sync.d.ts +103 -0
  26. package/dist/types/transaction.d.ts +132 -0
  27. package/package.json +120 -117
  28. package/index.d.ts +0 -1289
  29. package/lib/cache.js +0 -491
  30. package/lib/common/cursor.js +0 -58
  31. package/lib/common/docs-urls.js +0 -72
  32. package/lib/common/index-options.js +0 -222
  33. package/lib/common/log.js +0 -60
  34. package/lib/common/namespace.js +0 -21
  35. package/lib/common/normalize.js +0 -33
  36. package/lib/common/page-result.js +0 -42
  37. package/lib/common/runner.js +0 -56
  38. package/lib/common/server-features.js +0 -231
  39. package/lib/common/shape-builders.js +0 -26
  40. package/lib/common/validation.js +0 -112
  41. package/lib/connect.js +0 -76
  42. package/lib/constants.js +0 -54
  43. package/lib/count-queue.js +0 -187
  44. package/lib/distributed-cache-invalidator.js +0 -259
  45. package/lib/errors.js +0 -167
  46. package/lib/index.js +0 -461
  47. package/lib/infrastructure/ssh-tunnel-ssh2.js +0 -211
  48. package/lib/infrastructure/ssh-tunnel.js +0 -40
  49. package/lib/infrastructure/uri-parser.js +0 -35
  50. package/lib/lock/Lock.js +0 -66
  51. package/lib/lock/errors.js +0 -27
  52. package/lib/lock/index.js +0 -12
  53. package/lib/logger.js +0 -224
  54. package/lib/model/examples/test.js +0 -114
  55. package/lib/mongodb/common/accessor-helpers.js +0 -58
  56. package/lib/mongodb/common/agg-pipeline.js +0 -32
  57. package/lib/mongodb/common/iid.js +0 -27
  58. package/lib/mongodb/common/lexicographic-expr.js +0 -52
  59. package/lib/mongodb/common/shape.js +0 -31
  60. package/lib/mongodb/common/sort.js +0 -38
  61. package/lib/mongodb/common/transaction-aware.js +0 -24
  62. package/lib/mongodb/connect.js +0 -233
  63. package/lib/mongodb/index.js +0 -591
  64. package/lib/mongodb/management/admin-ops.js +0 -199
  65. package/lib/mongodb/management/bookmark-ops.js +0 -166
  66. package/lib/mongodb/management/cache-ops.js +0 -49
  67. package/lib/mongodb/management/collection-ops.js +0 -386
  68. package/lib/mongodb/management/database-ops.js +0 -201
  69. package/lib/mongodb/management/index-ops.js +0 -474
  70. package/lib/mongodb/management/index.js +0 -16
  71. package/lib/mongodb/management/namespace.js +0 -30
  72. package/lib/mongodb/management/validation-ops.js +0 -267
  73. package/lib/mongodb/queries/aggregate.js +0 -142
  74. package/lib/mongodb/queries/chain.js +0 -630
  75. package/lib/mongodb/queries/count.js +0 -98
  76. package/lib/mongodb/queries/distinct.js +0 -77
  77. package/lib/mongodb/queries/find-and-count.js +0 -192
  78. package/lib/mongodb/queries/find-by-ids.js +0 -235
  79. package/lib/mongodb/queries/find-one-by-id.js +0 -170
  80. package/lib/mongodb/queries/find-one.js +0 -70
  81. package/lib/mongodb/queries/find-page.js +0 -577
  82. package/lib/mongodb/queries/find.js +0 -170
  83. package/lib/mongodb/queries/index.js +0 -50
  84. package/lib/mongodb/queries/watch.js +0 -537
  85. package/lib/mongodb/writes/delete-many.js +0 -190
  86. package/lib/mongodb/writes/delete-one.js +0 -182
  87. package/lib/mongodb/writes/find-one-and-delete.js +0 -202
  88. package/lib/mongodb/writes/find-one-and-replace.js +0 -238
  89. package/lib/mongodb/writes/find-one-and-update.js +0 -239
  90. package/lib/mongodb/writes/increment-one.js +0 -252
  91. package/lib/mongodb/writes/index.js +0 -41
  92. package/lib/mongodb/writes/insert-batch.js +0 -507
  93. package/lib/mongodb/writes/insert-many.js +0 -227
  94. package/lib/mongodb/writes/insert-one.js +0 -180
  95. package/lib/mongodb/writes/replace-one.js +0 -215
  96. package/lib/mongodb/writes/result-handler.js +0 -236
  97. package/lib/mongodb/writes/update-many.js +0 -221
  98. package/lib/mongodb/writes/update-one.js +0 -223
  99. package/lib/mongodb/writes/upsert-one.js +0 -206
  100. package/lib/multi-level-cache.js +0 -189
  101. package/lib/operators.js +0 -330
  102. package/lib/redis-cache-adapter.js +0 -237
  103. package/lib/slow-query-log/base-storage.js +0 -69
  104. package/lib/slow-query-log/batch-queue.js +0 -96
  105. package/lib/slow-query-log/config-manager.js +0 -195
  106. package/lib/slow-query-log/index.js +0 -237
  107. package/lib/slow-query-log/mongodb-storage.js +0 -323
  108. package/lib/slow-query-log/query-hash.js +0 -38
  109. package/lib/transaction/CacheLockManager.js +0 -161
  110. package/lib/transaction/DistributedCacheLockManager.js +0 -474
  111. package/lib/transaction/Transaction.js +0 -314
  112. package/lib/transaction/TransactionManager.js +0 -266
  113. package/lib/transaction/index.js +0 -10
  114. package/lib/utils/objectid-converter.js +0 -566
@@ -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
+ }