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
package/dist/types/saga.d.ts
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
import type { LoggerLike } from './base';
|
|
2
|
-
|
|
1
|
+
import type { LoggerLike } from './base';
|
|
2
|
+
|
|
3
3
|
export interface SagaMetadataCache {
|
|
4
4
|
set(key: string, value: any, ttl?: number): void | Promise<void>;
|
|
5
5
|
keys?(pattern?: string): string[] | Promise<string[]>;
|
|
6
6
|
publish?(channel: string, message: string): void | Promise<unknown>;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
/** Execution context passed to each Saga step; provides data sharing between steps. */
|
|
8
|
+
|
|
9
|
+
/** Execution context passed to each Saga step; provides data sharing between steps. */
|
|
10
10
|
export interface SagaContext {
|
|
11
|
-
/** Unique ID for this Saga execution run. */
|
|
12
|
-
readonly executionId: string;
|
|
13
|
-
/** @deprecated Use `executionId` — v1 compatibility alias. */
|
|
14
|
-
readonly sagaId?: string;
|
|
15
|
-
/** Initial data passed to `executeSaga`. */
|
|
11
|
+
/** Unique ID for this Saga execution run. */
|
|
12
|
+
readonly executionId: string;
|
|
13
|
+
/** @deprecated Use `executionId` — v1 compatibility alias. */
|
|
14
|
+
readonly sagaId?: string;
|
|
15
|
+
/** Initial data passed to `executeSaga`. */
|
|
16
16
|
readonly data: any;
|
|
17
17
|
/** Store a value in the shared step context. */
|
|
18
18
|
set(key: string, value: any): void;
|
|
19
19
|
/** Retrieve a previously stored value. v1 compat — default generic is `any` to match v1 callers that did not annotate. */
|
|
20
20
|
get<T = any>(key: string): T | undefined;
|
|
21
|
-
/** Return `true` if a value exists for `key`. */
|
|
22
|
-
has(key: string): boolean;
|
|
23
|
-
/** Return all stored key-value pairs. */
|
|
21
|
+
/** Return `true` if a value exists for `key`. */
|
|
22
|
+
has(key: string): boolean;
|
|
23
|
+
/** Return all stored key-value pairs. */
|
|
24
24
|
getAll(): Record<string, any>;
|
|
25
|
-
/**
|
|
26
|
-
* Ordered list of completed step names.
|
|
27
|
-
* @deprecated v1 compat — populated automatically by the orchestrator.
|
|
28
|
-
*/
|
|
29
|
-
readonly completedSteps: string[];
|
|
30
|
-
/**
|
|
31
|
-
* Mark a step as completed and record its result.
|
|
32
|
-
* @deprecated v1 compat — called automatically by the orchestrator. Use `ctx.get(stepName)` to retrieve step results.
|
|
33
|
-
*/
|
|
34
|
-
markStepCompleted(stepName: string, result: unknown): void;
|
|
35
|
-
/**
|
|
36
|
-
* Return the result of a previously completed step.
|
|
37
|
-
* @deprecated v1 compat — use `ctx.get(stepName)` instead.
|
|
38
|
-
*/
|
|
39
|
-
getStepResult(stepName: string): unknown;
|
|
40
|
-
/**
|
|
41
|
-
* Return an ordered copy of completed step names.
|
|
42
|
-
* @deprecated v1 compat — use `ctx.getAll()` instead.
|
|
43
|
-
*/
|
|
44
|
-
getCompletedSteps(): string[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** A single step within a Saga, consisting of a forward action and an optional compensation handler. */
|
|
25
|
+
/**
|
|
26
|
+
* Ordered list of completed step names.
|
|
27
|
+
* @deprecated v1 compat — populated automatically by the orchestrator.
|
|
28
|
+
*/
|
|
29
|
+
readonly completedSteps: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Mark a step as completed and record its result.
|
|
32
|
+
* @deprecated v1 compat — called automatically by the orchestrator. Use `ctx.get(stepName)` to retrieve step results.
|
|
33
|
+
*/
|
|
34
|
+
markStepCompleted(stepName: string, result: unknown): void;
|
|
35
|
+
/**
|
|
36
|
+
* Return the result of a previously completed step.
|
|
37
|
+
* @deprecated v1 compat — use `ctx.get(stepName)` instead.
|
|
38
|
+
*/
|
|
39
|
+
getStepResult(stepName: string): unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Return an ordered copy of completed step names.
|
|
42
|
+
* @deprecated v1 compat — use `ctx.getAll()` instead.
|
|
43
|
+
*/
|
|
44
|
+
getCompletedSteps(): string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A single step within a Saga, consisting of a forward action and an optional compensation handler. */
|
|
48
48
|
export interface SagaStep {
|
|
49
49
|
name: string;
|
|
50
50
|
execute: (context: SagaContext) => Promise<any>;
|
|
51
51
|
/** Compensation handler — receives the context and the step's own execute result. v1 compat — required so callers may invoke `step.compensate(ctx)` without optional-chaining. */
|
|
52
52
|
compensate: (context: SagaContext, result?: any) => Promise<void>;
|
|
53
|
-
/** Per-step timeout in milliseconds (overrides Saga-level timeout). */
|
|
54
|
-
timeout?: number;
|
|
55
|
-
/** Number of retry attempts on step failure. */
|
|
56
|
-
retries?: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Definition of a Saga, including its ordered steps and execution configuration. */
|
|
60
|
-
export interface SagaDefinition {
|
|
61
|
-
name: string;
|
|
62
|
-
steps: SagaStep[];
|
|
63
|
-
/** Overall Saga timeout in milliseconds. */
|
|
64
|
-
timeout?: number;
|
|
65
|
-
/** Whether to emit detailed execution logs. */
|
|
66
|
-
logging?: boolean;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Result returned after a Saga execution (success or failure). */
|
|
53
|
+
/** Per-step timeout in milliseconds (overrides Saga-level timeout). */
|
|
54
|
+
timeout?: number;
|
|
55
|
+
/** Number of retry attempts on step failure. */
|
|
56
|
+
retries?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Definition of a Saga, including its ordered steps and execution configuration. */
|
|
60
|
+
export interface SagaDefinition {
|
|
61
|
+
name: string;
|
|
62
|
+
steps: SagaStep[];
|
|
63
|
+
/** Overall Saga timeout in milliseconds. */
|
|
64
|
+
timeout?: number;
|
|
65
|
+
/** Whether to emit detailed execution logs. */
|
|
66
|
+
logging?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Result returned after a Saga execution (success or failure). */
|
|
70
70
|
export interface SagaResult {
|
|
71
|
-
/** v2 field — present when emitted by v2 runtime; v1 fixtures may omit. */
|
|
72
|
-
sagaId?: string;
|
|
73
|
-
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
74
|
-
executionId: string;
|
|
75
|
-
/** v2 field — present when emitted by v2 runtime; v1 fixtures may omit. */
|
|
76
|
-
sagaName?: string;
|
|
77
|
-
success: boolean;
|
|
78
|
-
/** The return value of the last completed step (success path). */
|
|
71
|
+
/** v2 field — present when emitted by v2 runtime; v1 fixtures may omit. */
|
|
72
|
+
sagaId?: string;
|
|
73
|
+
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
74
|
+
executionId: string;
|
|
75
|
+
/** v2 field — present when emitted by v2 runtime; v1 fixtures may omit. */
|
|
76
|
+
sagaName?: string;
|
|
77
|
+
success: boolean;
|
|
78
|
+
/** The return value of the last completed step (success path). */
|
|
79
79
|
result?: any;
|
|
80
|
-
/** v1-compatible Error object (set when success is false). */
|
|
81
|
-
error?: Error;
|
|
82
|
-
/** v2 compatibility alias for message-only consumers. */
|
|
83
|
-
errorMessage?: string;
|
|
84
|
-
/** Ordered list of completed step names. */
|
|
85
|
-
completedSteps: string[];
|
|
86
|
-
/** v2 compatibility alias for count-only consumers. */
|
|
87
|
-
completedStepCount?: number;
|
|
88
|
-
/** @deprecated Alias of `completedSteps` retained for v2 callers. */
|
|
89
|
-
completedStepNames?: string[];
|
|
90
|
-
/** Names of steps whose compensation handlers were invoked. v1 compat — runtime always populates an array (empty on success). */
|
|
91
|
-
compensatedSteps: string[];
|
|
92
|
-
/** Total execution duration in milliseconds. */
|
|
93
|
-
duration: number;
|
|
94
|
-
/** Original Error object (failure path only). v1 compat — `error` field is a string in v2. */
|
|
80
|
+
/** v1-compatible Error object (set when success is false). */
|
|
81
|
+
error?: Error;
|
|
82
|
+
/** v2 compatibility alias for message-only consumers. */
|
|
83
|
+
errorMessage?: string;
|
|
84
|
+
/** Ordered list of completed step names. */
|
|
85
|
+
completedSteps: string[];
|
|
86
|
+
/** v2 compatibility alias for count-only consumers. */
|
|
87
|
+
completedStepCount?: number;
|
|
88
|
+
/** @deprecated Alias of `completedSteps` retained for v2 callers. */
|
|
89
|
+
completedStepNames?: string[];
|
|
90
|
+
/** Names of steps whose compensation handlers were invoked. v1 compat — runtime always populates an array (empty on success). */
|
|
91
|
+
compensatedSteps: string[];
|
|
92
|
+
/** Total execution duration in milliseconds. */
|
|
93
|
+
duration: number;
|
|
94
|
+
/** Original Error object (failure path only). v1 compat — `error` field is a string in v2. */
|
|
95
95
|
errorCause?: any;
|
|
96
|
-
/** Present on the failure path when at least one completed step has a compensate function. */
|
|
97
|
-
compensation?: {
|
|
98
|
-
success: boolean;
|
|
99
|
-
results: Array<{ stepName: string; success: boolean; reason?: string; error?: string; duration?: number; }>;
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Options for constructing a `SagaOrchestrator`. */
|
|
104
|
-
export interface SagaOrchestratorOptions {
|
|
105
|
-
logger?: LoggerLike | null;
|
|
106
|
-
cache?: SagaMetadataCache | null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Aggregate statistics for a `SagaOrchestrator` instance. */
|
|
110
|
-
export interface SagaStats {
|
|
111
|
-
totalExecutions: number;
|
|
112
|
-
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
113
|
-
successfulExecutions?: number;
|
|
114
|
-
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
115
|
-
failedExecutions?: number;
|
|
116
|
-
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
117
|
-
compensatedExecutions?: number;
|
|
118
|
-
successRate?: string;
|
|
119
|
-
storageMode?: string;
|
|
120
|
-
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
121
|
-
successCount: number;
|
|
122
|
-
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
123
|
-
failureCount: number;
|
|
124
|
-
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
125
|
-
compensationCount: number;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Orchestrates the execution and compensation of multi-step Saga workflows. */
|
|
96
|
+
/** Present on the failure path when at least one completed step has a compensate function. */
|
|
97
|
+
compensation?: {
|
|
98
|
+
success: boolean;
|
|
99
|
+
results: Array<{ stepName: string; success: boolean; reason?: string; error?: string; duration?: number; }>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Options for constructing a `SagaOrchestrator`. */
|
|
104
|
+
export interface SagaOrchestratorOptions {
|
|
105
|
+
logger?: LoggerLike | null;
|
|
106
|
+
cache?: SagaMetadataCache | null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Aggregate statistics for a `SagaOrchestrator` instance. */
|
|
110
|
+
export interface SagaStats {
|
|
111
|
+
totalExecutions: number;
|
|
112
|
+
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
113
|
+
successfulExecutions?: number;
|
|
114
|
+
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
115
|
+
failedExecutions?: number;
|
|
116
|
+
/** @since v1.0.8 — v2 extension; v1 fixtures may omit. */
|
|
117
|
+
compensatedExecutions?: number;
|
|
118
|
+
successRate?: string;
|
|
119
|
+
storageMode?: string;
|
|
120
|
+
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
121
|
+
successCount: number;
|
|
122
|
+
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
123
|
+
failureCount: number;
|
|
124
|
+
/** Primary v1 field — always present in both v1 and v2 runtime output. */
|
|
125
|
+
compensationCount: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Orchestrates the execution and compensation of multi-step Saga workflows. */
|
|
129
129
|
export declare class SagaOrchestrator {
|
|
130
|
-
constructor(options?: SagaOrchestratorOptions);
|
|
131
|
-
/** Register a Saga definition (sync). */
|
|
132
|
-
define(definition: SagaDefinition): void;
|
|
133
|
-
/** Register a Saga definition (async; returns the registered definition). */
|
|
134
|
-
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
135
|
-
/** Execute the named Saga with the given initial data. */
|
|
130
|
+
constructor(options?: SagaOrchestratorOptions);
|
|
131
|
+
/** Register a Saga definition (sync). */
|
|
132
|
+
define(definition: SagaDefinition): void;
|
|
133
|
+
/** Register a Saga definition (async; returns the registered definition). */
|
|
134
|
+
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
135
|
+
/** Execute the named Saga with the given initial data. */
|
|
136
136
|
execute(name: string, data: any): Promise<SagaResult>;
|
|
137
|
-
/** Return the definition for a registered Saga by name. */
|
|
138
|
-
getSaga(name: string): SagaDefinition | undefined;
|
|
139
|
-
/** Return the names of all registered Sagas. */
|
|
140
|
-
listSagas(): string[];
|
|
141
|
-
/** Return aggregate execution statistics. */
|
|
142
|
-
getStats(): SagaStats;
|
|
143
|
-
}
|
|
137
|
+
/** Return the definition for a registered Saga by name. */
|
|
138
|
+
getSaga(name: string): SagaDefinition | undefined;
|
|
139
|
+
/** Return the names of all registered Sagas. */
|
|
140
|
+
listSagas(): string[];
|
|
141
|
+
/** Return aggregate execution statistics. */
|
|
142
|
+
getStats(): SagaStats;
|
|
143
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import type { LoggerLike } from './base';
|
|
2
|
-
|
|
3
|
-
export interface SlowQueryLogEntry {
|
|
4
|
-
database: string;
|
|
5
|
-
collection: string;
|
|
6
|
-
operation: string;
|
|
7
|
-
durationMs: number;
|
|
8
|
-
query?: unknown;
|
|
9
|
-
timestamp?: Date;
|
|
10
|
-
queryHash?: string;
|
|
11
|
-
metadata?: Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface SlowQueryLogRecord {
|
|
15
|
-
queryHash: string;
|
|
16
|
-
database: string;
|
|
17
|
-
collection: string;
|
|
18
|
-
operation: string;
|
|
19
|
-
count: number;
|
|
20
|
-
totalTimeMs: number;
|
|
21
|
-
avgTimeMs: number;
|
|
22
|
-
maxTimeMs: number;
|
|
23
|
-
minTimeMs: number;
|
|
24
|
-
firstSeen: Date;
|
|
25
|
-
lastSeen: Date;
|
|
26
|
-
sampleQuery?: unknown;
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface SlowQueryLogFilter {
|
|
31
|
-
database?: string;
|
|
32
|
-
collection?: string;
|
|
33
|
-
operation?: string;
|
|
34
|
-
queryHash?: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface SlowQueryLogQueryOptions {
|
|
38
|
-
sort?: Record<string, 1 | -1>;
|
|
39
|
-
limit?: number;
|
|
40
|
-
skip?: number;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface SlowQueryLogStorageConfig {
|
|
44
|
-
type?: 'memory' | 'mongodb';
|
|
45
|
-
useBusinessConnection?: boolean;
|
|
46
|
-
uri?: string | null;
|
|
47
|
-
database?: string;
|
|
48
|
-
collection?: string;
|
|
49
|
-
ttl?: number;
|
|
50
|
-
options?: Record<string, unknown>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface SlowQueryLogConfig {
|
|
54
|
-
enabled: boolean;
|
|
55
|
-
storage: SlowQueryLogStorageConfig;
|
|
56
|
-
batch: {
|
|
57
|
-
enabled: boolean;
|
|
58
|
-
size: number;
|
|
59
|
-
interval: number;
|
|
60
|
-
maxBufferSize: number;
|
|
61
|
-
};
|
|
62
|
-
filter: {
|
|
63
|
-
excludeDatabases: string[];
|
|
64
|
-
excludeCollections: string[];
|
|
65
|
-
excludeOperations: string[];
|
|
66
|
-
minExecutionTimeMs: number;
|
|
67
|
-
};
|
|
68
|
-
advanced: {
|
|
69
|
-
errorHandling: 'log' | 'throw' | 'silent';
|
|
70
|
-
autoCreateIndexes: boolean;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type SlowQueryLogConfigInput = boolean | Partial<SlowQueryLogConfig>;
|
|
75
|
-
|
|
76
|
-
export interface SlowQueryLogStorage {
|
|
77
|
-
initialize(): Promise<void>;
|
|
78
|
-
save(log: SlowQueryLogEntry): Promise<void>;
|
|
79
|
-
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
80
|
-
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
81
|
-
close(): Promise<void>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export declare const DEFAULT_SLOW_QUERY_LOG_CONFIG: SlowQueryLogConfig;
|
|
85
|
-
export declare function generateQueryHash(input: unknown): string;
|
|
86
|
-
|
|
87
|
-
export declare class BatchQueue {
|
|
88
|
-
constructor(storage: Pick<SlowQueryLogStorage, 'saveBatch'>, options?: Partial<SlowQueryLogConfig['batch']>, logger?: LoggerLike | null);
|
|
89
|
-
add(log: SlowQueryLogEntry): Promise<void>;
|
|
90
|
-
flush(): Promise<void>;
|
|
91
|
-
close(): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export declare class SlowQueryLogMemoryStorage implements SlowQueryLogStorage {
|
|
95
|
-
initialize(): Promise<void>;
|
|
96
|
-
save(log: SlowQueryLogEntry): Promise<void>;
|
|
97
|
-
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
98
|
-
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
99
|
-
close(): Promise<void>;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export declare class MongoDBSlowQueryLogStorage implements SlowQueryLogStorage {
|
|
103
|
-
constructor(config?: SlowQueryLogStorageConfig, businessClient?: unknown, logger?: LoggerLike | null);
|
|
104
|
-
initialize(): Promise<void>;
|
|
105
|
-
save(log: SlowQueryLogEntry): Promise<void>;
|
|
106
|
-
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
107
|
-
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
108
|
-
close(): Promise<void>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export declare class SlowQueryLogConfigManager {
|
|
112
|
-
static mergeConfig(userConfig?: SlowQueryLogConfigInput, businessType?: string): SlowQueryLogConfig;
|
|
113
|
-
static validate(config: SlowQueryLogConfig, businessType?: string): boolean;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export declare class SlowQueryLogManager {
|
|
117
|
-
readonly config: SlowQueryLogConfig;
|
|
118
|
-
readonly storage: SlowQueryLogStorage;
|
|
119
|
-
readonly queue: BatchQueue | null;
|
|
120
|
-
constructor(userConfig?: SlowQueryLogConfigInput, businessClient?: unknown, businessType?: string, logger?: LoggerLike | null);
|
|
121
|
-
initialize(): Promise<void>;
|
|
122
|
-
save(log: SlowQueryLogEntry): Promise<void>;
|
|
123
|
-
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
124
|
-
close(): Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
|
|
1
|
+
import type { LoggerLike } from './base';
|
|
2
|
+
|
|
3
|
+
export interface SlowQueryLogEntry {
|
|
4
|
+
database: string;
|
|
5
|
+
collection: string;
|
|
6
|
+
operation: string;
|
|
7
|
+
durationMs: number;
|
|
8
|
+
query?: unknown;
|
|
9
|
+
timestamp?: Date;
|
|
10
|
+
queryHash?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SlowQueryLogRecord {
|
|
15
|
+
queryHash: string;
|
|
16
|
+
database: string;
|
|
17
|
+
collection: string;
|
|
18
|
+
operation: string;
|
|
19
|
+
count: number;
|
|
20
|
+
totalTimeMs: number;
|
|
21
|
+
avgTimeMs: number;
|
|
22
|
+
maxTimeMs: number;
|
|
23
|
+
minTimeMs: number;
|
|
24
|
+
firstSeen: Date;
|
|
25
|
+
lastSeen: Date;
|
|
26
|
+
sampleQuery?: unknown;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SlowQueryLogFilter {
|
|
31
|
+
database?: string;
|
|
32
|
+
collection?: string;
|
|
33
|
+
operation?: string;
|
|
34
|
+
queryHash?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SlowQueryLogQueryOptions {
|
|
38
|
+
sort?: Record<string, 1 | -1>;
|
|
39
|
+
limit?: number;
|
|
40
|
+
skip?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SlowQueryLogStorageConfig {
|
|
44
|
+
type?: 'memory' | 'mongodb';
|
|
45
|
+
useBusinessConnection?: boolean;
|
|
46
|
+
uri?: string | null;
|
|
47
|
+
database?: string;
|
|
48
|
+
collection?: string;
|
|
49
|
+
ttl?: number;
|
|
50
|
+
options?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SlowQueryLogConfig {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
storage: SlowQueryLogStorageConfig;
|
|
56
|
+
batch: {
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
size: number;
|
|
59
|
+
interval: number;
|
|
60
|
+
maxBufferSize: number;
|
|
61
|
+
};
|
|
62
|
+
filter: {
|
|
63
|
+
excludeDatabases: string[];
|
|
64
|
+
excludeCollections: string[];
|
|
65
|
+
excludeOperations: string[];
|
|
66
|
+
minExecutionTimeMs: number;
|
|
67
|
+
};
|
|
68
|
+
advanced: {
|
|
69
|
+
errorHandling: 'log' | 'throw' | 'silent';
|
|
70
|
+
autoCreateIndexes: boolean;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type SlowQueryLogConfigInput = boolean | Partial<SlowQueryLogConfig>;
|
|
75
|
+
|
|
76
|
+
export interface SlowQueryLogStorage {
|
|
77
|
+
initialize(): Promise<void>;
|
|
78
|
+
save(log: SlowQueryLogEntry): Promise<void>;
|
|
79
|
+
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
80
|
+
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare const DEFAULT_SLOW_QUERY_LOG_CONFIG: SlowQueryLogConfig;
|
|
85
|
+
export declare function generateQueryHash(input: unknown): string;
|
|
86
|
+
|
|
87
|
+
export declare class BatchQueue {
|
|
88
|
+
constructor(storage: Pick<SlowQueryLogStorage, 'saveBatch'>, options?: Partial<SlowQueryLogConfig['batch']>, logger?: LoggerLike | null);
|
|
89
|
+
add(log: SlowQueryLogEntry): Promise<void>;
|
|
90
|
+
flush(): Promise<void>;
|
|
91
|
+
close(): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare class SlowQueryLogMemoryStorage implements SlowQueryLogStorage {
|
|
95
|
+
initialize(): Promise<void>;
|
|
96
|
+
save(log: SlowQueryLogEntry): Promise<void>;
|
|
97
|
+
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
98
|
+
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export declare class MongoDBSlowQueryLogStorage implements SlowQueryLogStorage {
|
|
103
|
+
constructor(config?: SlowQueryLogStorageConfig, businessClient?: unknown, logger?: LoggerLike | null);
|
|
104
|
+
initialize(): Promise<void>;
|
|
105
|
+
save(log: SlowQueryLogEntry): Promise<void>;
|
|
106
|
+
saveBatch(logs: SlowQueryLogEntry[]): Promise<void>;
|
|
107
|
+
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
108
|
+
close(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export declare class SlowQueryLogConfigManager {
|
|
112
|
+
static mergeConfig(userConfig?: SlowQueryLogConfigInput, businessType?: string): SlowQueryLogConfig;
|
|
113
|
+
static validate(config: SlowQueryLogConfig, businessType?: string): boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export declare class SlowQueryLogManager {
|
|
117
|
+
readonly config: SlowQueryLogConfig;
|
|
118
|
+
readonly storage: SlowQueryLogStorage;
|
|
119
|
+
readonly queue: BatchQueue | null;
|
|
120
|
+
constructor(userConfig?: SlowQueryLogConfigInput, businessClient?: unknown, businessType?: string, logger?: LoggerLike | null);
|
|
121
|
+
initialize(): Promise<void>;
|
|
122
|
+
save(log: SlowQueryLogEntry): Promise<void>;
|
|
123
|
+
query(filter?: SlowQueryLogFilter, options?: SlowQueryLogQueryOptions): Promise<SlowQueryLogRecord[]>;
|
|
124
|
+
close(): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
|