monsqlize 2.0.5 → 2.0.6
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 +8 -5
- package/README.md +8 -2
- package/changelogs/v2.0.6.md +16 -0
- package/dist/types/base.d.mts +81 -0
- package/dist/types/collection.d.mts +1077 -0
- package/dist/types/collection.d.ts +46 -2
- package/dist/types/expression.d.mts +115 -0
- package/dist/types/index.d.mts +23 -0
- package/dist/types/lock.d.mts +74 -0
- package/dist/types/model.d.mts +634 -0
- package/dist/types/mongodb.d.mts +56 -0
- package/dist/types/monsqlize.d.mts +524 -0
- package/dist/types/pool.d.mts +84 -0
- package/dist/types/runtime.d.mts +387 -0
- package/dist/types/runtime.d.ts +4 -4
- package/dist/types/saga.d.mts +143 -0
- package/dist/types/slow-query-log.d.mts +126 -0
- package/dist/types/sync.d.mts +103 -0
- package/dist/types/transaction.d.mts +144 -0
- package/package.json +8 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChangeStream, Document, FindOptions, Sort } from 'mongodb';
|
|
1
|
+
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb';
|
|
2
2
|
|
|
3
3
|
/** Meta options for controlling timing/cache info in query results. */
|
|
4
4
|
export interface MetaOptions {
|
|
@@ -8,6 +8,50 @@ export interface MetaOptions {
|
|
|
8
8
|
includeCache?: boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** v1-compatible find options exported from the root package. */
|
|
12
|
+
export interface FindOptions {
|
|
13
|
+
projection?: Record<string, any> | string[];
|
|
14
|
+
sort?: Record<string, 1 | -1>;
|
|
15
|
+
limit?: number;
|
|
16
|
+
skip?: number;
|
|
17
|
+
cache?: number;
|
|
18
|
+
maxTimeMS?: number;
|
|
19
|
+
hint?: any;
|
|
20
|
+
collation?: any;
|
|
21
|
+
comment?: string;
|
|
22
|
+
meta?: boolean | MetaOptions;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** v1-compatible count options exported from the root package. */
|
|
26
|
+
export interface CountOptions {
|
|
27
|
+
cache?: number;
|
|
28
|
+
maxTimeMS?: number;
|
|
29
|
+
hint?: any;
|
|
30
|
+
collation?: any;
|
|
31
|
+
comment?: string;
|
|
32
|
+
meta?: boolean | MetaOptions;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** v1-compatible aggregate options exported from the root package. */
|
|
36
|
+
export interface AggregateOptions {
|
|
37
|
+
cache?: number;
|
|
38
|
+
maxTimeMS?: number;
|
|
39
|
+
allowDiskUse?: boolean;
|
|
40
|
+
collation?: any;
|
|
41
|
+
hint?: string | object;
|
|
42
|
+
comment?: string;
|
|
43
|
+
meta?: boolean | MetaOptions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** v1-compatible distinct options exported from the root package. */
|
|
47
|
+
export interface DistinctOptions {
|
|
48
|
+
cache?: number;
|
|
49
|
+
maxTimeMS?: number;
|
|
50
|
+
collation?: any;
|
|
51
|
+
hint?: string | object;
|
|
52
|
+
meta?: boolean | MetaOptions;
|
|
53
|
+
}
|
|
54
|
+
|
|
11
55
|
/** Query options that request the v1 `{ data, meta }` wrapper. */
|
|
12
56
|
export interface QueryMetaOption extends Record<string, unknown> {
|
|
13
57
|
/** Include operation timing metadata in the resolved query result. */
|
|
@@ -213,7 +257,7 @@ export interface FindPageOptions<TSchema = any> {
|
|
|
213
257
|
explain?: boolean | string;
|
|
214
258
|
/** Query comment for server-side profiling. v1 compat — top-level shortcut for `options.comment`. */
|
|
215
259
|
comment?: string;
|
|
216
|
-
options?:
|
|
260
|
+
options?: MongoFindOptions;
|
|
217
261
|
/** Cursor-walking bookmark jump configuration */
|
|
218
262
|
jump?: JumpOptions;
|
|
219
263
|
/** Offset-based fallback for small page ranges */
|
|
@@ -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.mjs';
|
|
2
|
+
export * from './collection.mjs';
|
|
3
|
+
export * from './expression.mjs';
|
|
4
|
+
export * from './lock.mjs';
|
|
5
|
+
export * from './model.mjs';
|
|
6
|
+
export * from './mongodb.mjs';
|
|
7
|
+
export * from './pool.mjs';
|
|
8
|
+
export * from './runtime.mjs';
|
|
9
|
+
export * from './saga.mjs';
|
|
10
|
+
export * from './slow-query-log.mjs';
|
|
11
|
+
export * from './sync.mjs';
|
|
12
|
+
export * from './transaction.mjs';
|
|
13
|
+
export * from './monsqlize.mjs';
|
|
14
|
+
|
|
15
|
+
export { default, MonSQLize } from './monsqlize.mjs';
|
|
16
|
+
export { Model, generateQueryHash, validateSyncConfig } from './runtime.mjs';
|
|
17
|
+
|
|
18
|
+
export type { Lock as LockContract } from './lock.mjs';
|
|
19
|
+
export type { ModelInstance as ModelAccessor, ModelInstance } from './model.mjs';
|
|
20
|
+
export type { SyncTargetConfig as SyncTarget } from './sync.mjs';
|
|
21
|
+
export type { Transaction as TransactionContract } from './transaction.mjs';
|
|
22
|
+
export type { MonSQLizeOptions as BaseOptions } from './monsqlize.mjs';
|
|
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
|
+
}
|