@autofleet/sheilta 2.3.0 → 2.4.1-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.
- package/lib/index.cjs +115 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +594 -97
- package/lib/index.d.ts +594 -97
- package/lib/index.js +58 -1
- package/lib/index.js.map +1 -1
- package/package.json +12 -34
package/lib/index.d.cts
CHANGED
|
@@ -1,112 +1,609 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Model, ModelStatic, Op, Sequelize, WhereOptions, literal } from "sequelize";
|
|
2
|
+
import { Handler, Router } from "express";
|
|
3
|
+
import { LoggerInstanceManager } from "@autofleet/logger";
|
|
4
|
+
import { RedisClientType, createClient } from "redis";
|
|
5
|
+
import rabbit from "@autofleet/rabbit";
|
|
6
|
+
import { z, z as z$1 } from "zod/v3";
|
|
7
|
+
import { EventEmitter } from "node:events";
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
//#region src/operators/index.d.ts
|
|
5
10
|
|
|
11
|
+
declare const formatOperators: (sequelize?: {
|
|
12
|
+
Op: typeof Op;
|
|
13
|
+
}) => Record<string, symbol>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/formatter/jsonAttributesFormater.d.ts
|
|
16
|
+
declare const ComputedActions: {
|
|
17
|
+
readonly length: "length";
|
|
18
|
+
};
|
|
19
|
+
interface JsonSelectAttribute {
|
|
20
|
+
columnName: string;
|
|
21
|
+
keys: string[];
|
|
22
|
+
alias?: string;
|
|
23
|
+
}
|
|
24
|
+
interface JsonComputedAttribute {
|
|
25
|
+
columnName: string;
|
|
26
|
+
action: keyof typeof ComputedActions;
|
|
27
|
+
alias: string;
|
|
28
|
+
}
|
|
29
|
+
interface JsonAttributes {
|
|
30
|
+
select?: JsonSelectAttribute[];
|
|
31
|
+
computed?: JsonComputedAttribute[];
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/formatter/index.d.ts
|
|
6
35
|
type OrderItem = string | [string, string];
|
|
7
36
|
type SequelizeOrder = string | OrderItem[];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
37
|
+
interface FormatPayloadOptions {
|
|
38
|
+
includeRawPayload?: boolean;
|
|
39
|
+
literalAttributes?: LiteralAttribute[];
|
|
40
|
+
DBFormatter?: typeof literal;
|
|
41
|
+
skipSearchTermFormat?: boolean;
|
|
42
|
+
additionalAllowedAttributes?: string[];
|
|
43
|
+
}
|
|
44
|
+
interface ConditionWithOperator {
|
|
45
|
+
operator: string;
|
|
46
|
+
value: string;
|
|
47
|
+
}
|
|
19
48
|
type ConditionValue = ConditionWithOperator | ConditionWithOperator[] | string | string[];
|
|
20
49
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
* Generates replacements for the given conditions.
|
|
51
|
+
*
|
|
52
|
+
* @param conditions - The conditions to generate replacements for.
|
|
53
|
+
* @returns The replacements object.
|
|
54
|
+
*/
|
|
26
55
|
declare const generateFilterReplacements: (conditions: Record<string, ConditionValue>) => Record<string, string>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
interface Include {
|
|
57
|
+
association?: string;
|
|
58
|
+
model?: string;
|
|
59
|
+
required?: boolean;
|
|
60
|
+
include?: Include[];
|
|
61
|
+
}
|
|
62
|
+
interface FormatPayloadData {
|
|
63
|
+
order?: string[];
|
|
64
|
+
page?: number;
|
|
65
|
+
perPage?: number;
|
|
66
|
+
include?: (string | Include)[];
|
|
67
|
+
query?: Record<string, unknown>;
|
|
68
|
+
attributes?: string[] | null;
|
|
69
|
+
searchTerm?: string | null;
|
|
70
|
+
jsonAttributes?: JsonAttributes;
|
|
71
|
+
}
|
|
72
|
+
type Literal = ReturnType<typeof literal>;
|
|
73
|
+
interface FormattedPayload {
|
|
74
|
+
query: Record<string, unknown>;
|
|
75
|
+
externalQueryValues?: Record<string, unknown>;
|
|
76
|
+
attributes: (SequelizeOrder | (string | Literal)[])[] | {
|
|
77
|
+
include: (SequelizeOrder | (string | Literal)[])[];
|
|
78
|
+
};
|
|
79
|
+
order: (SequelizeOrder | Literal)[];
|
|
80
|
+
page: number;
|
|
81
|
+
perPage: number;
|
|
82
|
+
include: any;
|
|
83
|
+
scopes: (string | {
|
|
84
|
+
method: (string | {
|
|
85
|
+
replacementsMap: Record<string, string>;
|
|
86
|
+
scopeValue: any;
|
|
51
87
|
})[];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
type
|
|
88
|
+
})[];
|
|
89
|
+
}
|
|
90
|
+
declare const formatPayload: ({
|
|
91
|
+
order,
|
|
92
|
+
page,
|
|
93
|
+
perPage,
|
|
94
|
+
include,
|
|
95
|
+
query,
|
|
96
|
+
attributes,
|
|
97
|
+
searchTerm,
|
|
98
|
+
jsonAttributes
|
|
99
|
+
}: FormatPayloadData, model?: any, options?: FormatPayloadOptions) => FormattedPayload;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/middleware/index.d.ts
|
|
102
|
+
type literal$1 = any;
|
|
103
|
+
type LiteralQuery = (literal$1 | string)[] | literal$1;
|
|
104
|
+
interface LiteralAttribute {
|
|
105
|
+
attribute: string;
|
|
106
|
+
literal: LiteralQuery;
|
|
107
|
+
}
|
|
108
|
+
interface MiddlewareValidationOption {
|
|
109
|
+
literalAttributes?: LiteralAttribute[];
|
|
110
|
+
enrichmentAttributes?: string[];
|
|
111
|
+
additionalAllowedAttributes?: string[];
|
|
112
|
+
logger?: LoggerInstanceManager;
|
|
113
|
+
}
|
|
114
|
+
type ReqKeys = "body" | "query";
|
|
67
115
|
/** consider using @see {@link queryHandler} directly */
|
|
68
116
|
declare const queryValidationMiddleware: (model: any, options?: MiddlewareValidationOption, inner?: ReqKeys) => Handler;
|
|
69
117
|
/** consider using @see {@link queryHandler} directly */
|
|
70
118
|
declare const queryFormatMiddleware: (model: any, options?: FormatPayloadOptions, inner?: ReqKeys) => Handler;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/validations/index.d.ts
|
|
121
|
+
interface PayloadValidationData {
|
|
122
|
+
query?: object;
|
|
123
|
+
order?: string[];
|
|
124
|
+
attributes?: string[];
|
|
125
|
+
include?: any[];
|
|
126
|
+
page?: number;
|
|
127
|
+
perPage?: number;
|
|
128
|
+
enrichments?: string[] | {
|
|
129
|
+
[enrichmentName: string]: {
|
|
130
|
+
exclude?: string[];
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
group?: string[];
|
|
134
|
+
jsonAttributes?: {
|
|
135
|
+
select?: {
|
|
136
|
+
columnName: string;
|
|
137
|
+
keys: string[];
|
|
138
|
+
alias?: string;
|
|
139
|
+
}[];
|
|
140
|
+
computed?: {
|
|
141
|
+
columnName: string;
|
|
142
|
+
action: "length";
|
|
143
|
+
alias: string;
|
|
144
|
+
}[];
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
declare const validatePayload: ({
|
|
148
|
+
query,
|
|
149
|
+
order,
|
|
150
|
+
attributes,
|
|
151
|
+
include,
|
|
152
|
+
page,
|
|
153
|
+
perPage,
|
|
154
|
+
enrichments,
|
|
155
|
+
group,
|
|
156
|
+
jsonAttributes
|
|
157
|
+
}: PayloadValidationData, model?: any, options?: MiddlewareValidationOption) => boolean;
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/handler/index.d.ts
|
|
84
160
|
interface QueryValues extends ReturnType<typeof formatPayload> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
161
|
+
enrichments?: string[] | Record<string, {
|
|
162
|
+
exclude: string[];
|
|
163
|
+
}>;
|
|
164
|
+
distinct: boolean;
|
|
165
|
+
searchTerm?: string;
|
|
89
166
|
}
|
|
90
167
|
interface QueryHandlerOptions {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
168
|
+
/** The sequelize model too which querying abilities are added. */
|
|
169
|
+
model: any;
|
|
170
|
+
/** Optional settings for validation. */
|
|
171
|
+
validationOptions?: Omit<MiddlewareValidationOption, "logger">;
|
|
172
|
+
/** Optional settings for payload formatting */
|
|
173
|
+
formatOptions?: FormatPayloadOptions;
|
|
174
|
+
logger: LoggerInstanceManager;
|
|
175
|
+
/** The name of model to be printed in logs. defaults to `model`s constructor name. */
|
|
176
|
+
modelName?: string;
|
|
177
|
+
/** Sequelize scopes of the model to be used within the query. @example ['userScope'] */
|
|
178
|
+
additionalScopes?: string[];
|
|
179
|
+
/** Callback to allow modifying the query values prior to querying the DB */
|
|
180
|
+
modifyQueryValues?: (queryValues: QueryValues) => QueryValues;
|
|
181
|
+
/** Optional callback to modify endpoint's response based on the DBs response. */
|
|
182
|
+
onRowsRetrieved?: (data: {
|
|
183
|
+
rows: any[];
|
|
184
|
+
count: number;
|
|
185
|
+
}, queryValues: QueryValues) => any;
|
|
186
|
+
}
|
|
187
|
+
type Asyncify$1<T extends (...a: any[]) => any> = (...a: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
188
|
+
declare const queryHandler: ({
|
|
189
|
+
model,
|
|
190
|
+
logger,
|
|
191
|
+
validationOptions,
|
|
192
|
+
formatOptions,
|
|
193
|
+
modelName,
|
|
194
|
+
additionalScopes,
|
|
195
|
+
modifyQueryValues,
|
|
196
|
+
onRowsRetrieved
|
|
197
|
+
}: QueryHandlerOptions) => Asyncify$1<Handler>;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/bulker/src/types.d.ts
|
|
200
|
+
type Id = string | number;
|
|
201
|
+
interface JobMetadata {
|
|
202
|
+
status: string;
|
|
203
|
+
total: number;
|
|
204
|
+
action: string;
|
|
205
|
+
}
|
|
206
|
+
interface ConsumeOptions {
|
|
207
|
+
enableRabbitTrace?: boolean;
|
|
208
|
+
[key: string]: any;
|
|
209
|
+
}
|
|
210
|
+
interface JobStatus {
|
|
211
|
+
jobId: string;
|
|
212
|
+
status: string;
|
|
213
|
+
action: string;
|
|
214
|
+
total: number;
|
|
215
|
+
queued: number;
|
|
216
|
+
processed: number;
|
|
217
|
+
succeeded: number;
|
|
218
|
+
failed: number;
|
|
219
|
+
errors: any[];
|
|
220
|
+
createdAt?: string;
|
|
221
|
+
updatedAt?: string;
|
|
222
|
+
duration: {
|
|
223
|
+
startTime: string | null;
|
|
224
|
+
endTime: string | null;
|
|
225
|
+
durationMs: number | null;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
type MessageAck = () => Promise<void>;
|
|
229
|
+
type MessageNack = (err?: Error, requeue?: boolean) => Promise<void>;
|
|
230
|
+
type BulkPerIdHandler<T = any> = (args: {
|
|
231
|
+
jobId?: string;
|
|
232
|
+
id: Id;
|
|
233
|
+
payload: T;
|
|
234
|
+
}, ack: MessageAck, nack: MessageNack) => Promise<void>;
|
|
235
|
+
interface AdditionalIdsHookData<T = any> {
|
|
236
|
+
rawPayload: {
|
|
237
|
+
query: Record<string, any>;
|
|
238
|
+
include?: any[];
|
|
239
|
+
searchTerm: string;
|
|
240
|
+
};
|
|
241
|
+
payload: T;
|
|
242
|
+
}
|
|
243
|
+
interface BulkRouteOptions<T = any> {
|
|
244
|
+
/** e.g. "change-state" - the action identifier sent in request body */
|
|
245
|
+
action: string;
|
|
246
|
+
/** Sequelize model from which to scan IDs */
|
|
247
|
+
model: Model<any, any> | ModelStatic<any> | any;
|
|
248
|
+
modelScopes: string[];
|
|
249
|
+
/** Per-ID handler that performs the operation */
|
|
250
|
+
consumer: BulkPerIdHandler<T>;
|
|
251
|
+
consumerOptions?: ConsumeOptions;
|
|
252
|
+
rabbitQueueName?: string;
|
|
253
|
+
payloadSchema?: z$1.ZodType<T>;
|
|
254
|
+
/** Identity Scopes to be provided and are used and validated from the query.query object */
|
|
255
|
+
identityScopes?: string[];
|
|
256
|
+
queryFunction?: (reqBody: any) => Promise<Record<string, any>[]>;
|
|
257
|
+
idField?: string;
|
|
258
|
+
pageSize?: number;
|
|
259
|
+
workerConcurrency?: number;
|
|
260
|
+
jobAttempts?: number;
|
|
261
|
+
jobBackoffMs?: number;
|
|
262
|
+
removeOnComplete?: boolean | number;
|
|
263
|
+
removeOnFail?: boolean | number;
|
|
264
|
+
/** Inject tenant/RBAC filters (AND-ed with user query) */
|
|
265
|
+
contextWhere?: (payload: T) => WhereOptions;
|
|
266
|
+
/**
|
|
267
|
+
* Hook to provide additional IDs that will be OR-ed with the main query.
|
|
268
|
+
* This is useful when you need to manually fetch additional IDs based on the raw request body.
|
|
269
|
+
* The returned IDs will be included in the where clause using an OR statement.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* additionalIdsHook: async (data) => {
|
|
273
|
+
* const { rawPayload, payload } = reqBody;
|
|
274
|
+
* if (!rawPayload.searchTerm) return [];
|
|
275
|
+
* const filters = rawPayload?.query?.fleetId ? { fleetId: query.query.fleetId } : {};
|
|
276
|
+
* const labelIds = await searchDriversByLabelsValue(rawPayload.searchTerm, filters);
|
|
277
|
+
* const vendorIds = await searchDriversByVendorName(rawPayload.searchTerm, filters);
|
|
278
|
+
* return [...labelIds, ...vendorIds];
|
|
279
|
+
* }
|
|
280
|
+
*/
|
|
281
|
+
additionalIdsHook?: (data: AdditionalIdsHookData) => Promise<Id[]>;
|
|
282
|
+
}
|
|
283
|
+
interface BulkRouterEvents {
|
|
284
|
+
"job:created": (data: {
|
|
285
|
+
jobId: string;
|
|
286
|
+
action: string;
|
|
287
|
+
total: number;
|
|
288
|
+
}) => void;
|
|
289
|
+
"job:started": (data: {
|
|
290
|
+
jobId: string;
|
|
291
|
+
action: string;
|
|
292
|
+
}) => void;
|
|
293
|
+
"job:queued": (data: {
|
|
294
|
+
jobId: string;
|
|
295
|
+
action: string;
|
|
296
|
+
queued: number;
|
|
297
|
+
total: number;
|
|
298
|
+
}) => void;
|
|
299
|
+
"job:completed": (data: {
|
|
300
|
+
jobId: string;
|
|
301
|
+
action: string;
|
|
302
|
+
processed: number;
|
|
303
|
+
failed: number;
|
|
304
|
+
duration: number;
|
|
305
|
+
}) => void;
|
|
306
|
+
"job:canceled": (data: {
|
|
307
|
+
jobId: string;
|
|
308
|
+
action: string;
|
|
309
|
+
}) => void;
|
|
310
|
+
"job:failed": (data: {
|
|
311
|
+
jobId: string;
|
|
312
|
+
action: string;
|
|
313
|
+
error: string;
|
|
314
|
+
}) => void;
|
|
315
|
+
"item:processing": (data: {
|
|
316
|
+
jobId: string;
|
|
317
|
+
action: string;
|
|
318
|
+
id: string | number;
|
|
319
|
+
}) => void;
|
|
320
|
+
"item:processed": (data: {
|
|
321
|
+
jobId: string;
|
|
322
|
+
action: string;
|
|
323
|
+
id: string | number;
|
|
324
|
+
}) => void;
|
|
325
|
+
"item:failed": (data: {
|
|
326
|
+
jobId: string;
|
|
327
|
+
action: string;
|
|
328
|
+
id: string | number;
|
|
329
|
+
error: string;
|
|
330
|
+
}) => void;
|
|
331
|
+
"item:retrying": (data: {
|
|
332
|
+
jobId: string;
|
|
333
|
+
action: string;
|
|
334
|
+
id: string | number;
|
|
335
|
+
}) => void;
|
|
336
|
+
"worker:started": (data: {
|
|
337
|
+
action: string;
|
|
338
|
+
queueName: string;
|
|
339
|
+
}) => void;
|
|
340
|
+
"worker:error": (data: {
|
|
341
|
+
action: string;
|
|
342
|
+
error: string;
|
|
343
|
+
}) => void;
|
|
344
|
+
"scan:page": (data: {
|
|
345
|
+
jobId: string;
|
|
346
|
+
action: string;
|
|
347
|
+
pageNumber: number;
|
|
348
|
+
itemsInPage: number;
|
|
349
|
+
}) => void;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Interface for event emitters with the emitEvent helper method
|
|
353
|
+
*/
|
|
354
|
+
interface IBulkEventEmitter {
|
|
355
|
+
emitEvent<K extends keyof BulkRouterEvents>(event: K, ...args: Parameters<BulkRouterEvents[K]>): void;
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/bulker/src/BulkRoute.d.ts
|
|
359
|
+
type Asyncify<T extends (...a: any[]) => any> = (...a: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
360
|
+
declare class BulkRoute<T = any> {
|
|
361
|
+
private readonly bulker;
|
|
362
|
+
private readonly opts;
|
|
363
|
+
readonly action: string;
|
|
364
|
+
private readonly model;
|
|
365
|
+
private readonly consumer;
|
|
366
|
+
private readonly idField;
|
|
367
|
+
private readonly pageSize;
|
|
368
|
+
private readonly rabbitQueueName;
|
|
369
|
+
private readonly rabbit;
|
|
370
|
+
private readonly consumerOptions;
|
|
371
|
+
private readonly queryFunction?;
|
|
372
|
+
private readonly payloadSchema?;
|
|
373
|
+
private readonly identityScopeSchema;
|
|
374
|
+
private readonly modelScopes;
|
|
375
|
+
constructor(bulker: Bulker, opts: BulkRouteOptions<T>);
|
|
376
|
+
bulkHandler: Asyncify<Handler>;
|
|
377
|
+
/** Get user jobs - public method for BulkRouter to use */
|
|
378
|
+
getUserJobs(userId: string, limit?: number): Promise<(JobStatus | null)[]>;
|
|
379
|
+
private rabbitScanAndEnqueue;
|
|
380
|
+
startRabbitWorker(): Promise<void>;
|
|
381
|
+
}
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/bulker/src/BulkRouter.d.ts
|
|
384
|
+
declare class BulkRouter {
|
|
385
|
+
private readonly bulker;
|
|
386
|
+
private readonly router;
|
|
387
|
+
private routes;
|
|
388
|
+
private actionsToRouteMap;
|
|
389
|
+
private staticRoute;
|
|
390
|
+
constructor(bulker: Bulker, router?: Router, staticRoute?: string);
|
|
391
|
+
private registerStaticRoutes;
|
|
392
|
+
addAction<T = any>(actionName: string, opts: Omit<BulkRouteOptions<T>, "action">): BulkRoute<T>;
|
|
393
|
+
private bulkHandler;
|
|
394
|
+
private getJobHandler;
|
|
395
|
+
private cancelJobHandler;
|
|
396
|
+
private getMyJobsHandler;
|
|
397
|
+
/** Get the configured router instance */
|
|
398
|
+
getRouter(): Router;
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/bulker/src/events.d.ts
|
|
402
|
+
interface BulkRouterEvents$1 {
|
|
403
|
+
"job:created": (data: {
|
|
404
|
+
jobId: string;
|
|
405
|
+
action: string;
|
|
406
|
+
total: number;
|
|
407
|
+
}) => void;
|
|
408
|
+
"job:started": (data: {
|
|
409
|
+
jobId: string;
|
|
410
|
+
action: string;
|
|
411
|
+
}) => void;
|
|
412
|
+
"job:queued": (data: {
|
|
413
|
+
jobId: string;
|
|
414
|
+
action: string;
|
|
415
|
+
queued: number;
|
|
416
|
+
total: number;
|
|
417
|
+
}) => void;
|
|
418
|
+
"job:completed": (data: {
|
|
419
|
+
jobId: string;
|
|
420
|
+
action: string;
|
|
421
|
+
processed: number;
|
|
422
|
+
failed: number;
|
|
423
|
+
duration: number;
|
|
424
|
+
}) => void;
|
|
425
|
+
"job:canceled": (data: {
|
|
426
|
+
jobId: string;
|
|
427
|
+
action: string;
|
|
428
|
+
}) => void;
|
|
429
|
+
"job:failed": (data: {
|
|
430
|
+
jobId: string;
|
|
431
|
+
action: string;
|
|
432
|
+
error: string;
|
|
433
|
+
}) => void;
|
|
434
|
+
"item:processing": (data: {
|
|
435
|
+
jobId: string;
|
|
436
|
+
action: string;
|
|
437
|
+
id: string | number;
|
|
438
|
+
}) => void;
|
|
439
|
+
"item:processed": (data: {
|
|
440
|
+
jobId: string;
|
|
441
|
+
action: string;
|
|
442
|
+
id: string | number;
|
|
443
|
+
}) => void;
|
|
444
|
+
"item:failed": (data: {
|
|
445
|
+
jobId: string;
|
|
446
|
+
action: string;
|
|
447
|
+
id: string | number;
|
|
448
|
+
error: string;
|
|
449
|
+
}) => void;
|
|
450
|
+
"item:retrying": (data: {
|
|
451
|
+
jobId: string;
|
|
452
|
+
action: string;
|
|
453
|
+
id: string | number;
|
|
454
|
+
}) => void;
|
|
455
|
+
"worker:started": (data: {
|
|
456
|
+
action: string;
|
|
457
|
+
queueName: string;
|
|
458
|
+
}) => void;
|
|
459
|
+
"worker:error": (data: {
|
|
460
|
+
action: string;
|
|
461
|
+
error: string;
|
|
462
|
+
}) => void;
|
|
463
|
+
"scan:page": (data: {
|
|
464
|
+
jobId: string;
|
|
465
|
+
action: string;
|
|
466
|
+
pageNumber: number;
|
|
467
|
+
itemsInPage: number;
|
|
468
|
+
}) => void;
|
|
469
|
+
}
|
|
470
|
+
interface BulkEventEmitter extends EventEmitter {
|
|
471
|
+
on<K extends keyof BulkRouterEvents$1>(event: K, listener: BulkRouterEvents$1[K]): this;
|
|
472
|
+
once<K extends keyof BulkRouterEvents$1>(event: K, listener: BulkRouterEvents$1[K]): this;
|
|
473
|
+
off<K extends keyof BulkRouterEvents$1>(event: K, listener: BulkRouterEvents$1[K]): this;
|
|
474
|
+
removeListener<K extends keyof BulkRouterEvents$1>(event: K, listener: BulkRouterEvents$1[K]): this;
|
|
475
|
+
emit<K extends keyof BulkRouterEvents$1>(event: K, ...args: Parameters<BulkRouterEvents$1[K]>): boolean;
|
|
476
|
+
}
|
|
477
|
+
interface EmitsBulkEvents {
|
|
478
|
+
emitEvent<K extends keyof BulkRouterEvents$1>(event: K, ...args: Parameters<BulkRouterEvents$1[K]>): void;
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/bulker/src/JobManager.d.ts
|
|
482
|
+
/**
|
|
483
|
+
* Manages all job-related operations in Redis
|
|
484
|
+
* Centralizes job creation, status updates, cancellation, and user job tracking
|
|
485
|
+
*/
|
|
486
|
+
declare class JobManager {
|
|
487
|
+
private eventEmitter?;
|
|
488
|
+
private readonly redis;
|
|
489
|
+
private readonly defaults;
|
|
490
|
+
constructor(redis: RedisClientType, defaults?: {
|
|
491
|
+
maxJobsPerUser?: number;
|
|
492
|
+
jobTtlSeconds?: number;
|
|
493
|
+
errorLogLimit?: number;
|
|
494
|
+
});
|
|
495
|
+
/** Set event emitter for emitting job events */
|
|
496
|
+
setEventEmitter(emitter: EmitsBulkEvents): void;
|
|
497
|
+
/** Generate Redis key for job */
|
|
498
|
+
static jobKey(jobId: string): string;
|
|
499
|
+
/** Generate Redis key for user jobs list */
|
|
500
|
+
static userJobsKey(userId: string): string;
|
|
501
|
+
/**
|
|
502
|
+
* Initialize a new job in Redis
|
|
503
|
+
*/
|
|
504
|
+
initJob(jobId: string, meta: JobMetadata): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Get job status from Redis
|
|
507
|
+
*/
|
|
508
|
+
getJob(jobId: string): Promise<JobStatus | null>;
|
|
509
|
+
/**
|
|
510
|
+
* Set a single field on a job
|
|
511
|
+
*/
|
|
512
|
+
setJobField(jobId: string, field: string, value: string): Promise<boolean>;
|
|
513
|
+
/**
|
|
514
|
+
* Set multiple fields on a job
|
|
515
|
+
*/
|
|
516
|
+
setJobFields(jobId: string, fields: Record<string, string>): Promise<boolean>;
|
|
517
|
+
/**
|
|
518
|
+
* Increment a counter field on a job
|
|
519
|
+
*/
|
|
520
|
+
incrJobField(jobId: string, field: "queued" | "processed" | "succeeded" | "failed", by?: number): Promise<number>;
|
|
521
|
+
/**
|
|
522
|
+
* Get a single field from a job
|
|
523
|
+
*/
|
|
524
|
+
getJobField(jobId: string, field: string): Promise<string | undefined>;
|
|
525
|
+
/**
|
|
526
|
+
* Cancel a job
|
|
527
|
+
*/
|
|
528
|
+
cancelJob(jobId: string): Promise<boolean>;
|
|
529
|
+
/**
|
|
530
|
+
* Mark job as completed (for jobs with no items to process)
|
|
531
|
+
*/
|
|
532
|
+
completeEmptyJob(jobId: string): Promise<void>;
|
|
533
|
+
/**
|
|
534
|
+
* Handle successful message processing (ack)
|
|
535
|
+
* Uses Redis Lua script for atomic operation
|
|
536
|
+
*/
|
|
537
|
+
ack(jobId: string): Promise<void>;
|
|
538
|
+
/**
|
|
539
|
+
* Handle failed message processing (nack)
|
|
540
|
+
* Uses Redis Lua script for atomic operation
|
|
541
|
+
*/
|
|
542
|
+
nack(jobId: string, errorMsg: string, data: any): Promise<void>;
|
|
543
|
+
/**
|
|
544
|
+
* Add a job to user's job list
|
|
545
|
+
*/
|
|
546
|
+
addUserJob(userId: string, jobId: string): Promise<void>;
|
|
547
|
+
/**
|
|
548
|
+
* Remove a job from user's job list
|
|
549
|
+
*/
|
|
550
|
+
removeUserJob(userId: string, jobId: string): Promise<void>;
|
|
551
|
+
/**
|
|
552
|
+
* Get all jobs for a user
|
|
553
|
+
*/
|
|
554
|
+
getUserJobs(userId: string, limit?: number): Promise<(JobStatus | null)[]>;
|
|
555
|
+
}
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region src/bulker/src/Errors.d.ts
|
|
558
|
+
declare class BulkerError extends Error {
|
|
559
|
+
readonly retryable: boolean;
|
|
560
|
+
constructor(message: string, retryable?: boolean);
|
|
561
|
+
static isBulkerError(err: unknown): err is BulkerError;
|
|
562
|
+
static wrap(err: unknown, message?: string, retryable?: boolean): BulkerError;
|
|
563
|
+
static retryable(message: string): BulkerError;
|
|
564
|
+
static nonRetryable(message: string): BulkerError;
|
|
565
|
+
}
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/bulker/src/index.d.ts
|
|
568
|
+
interface BulkerInit {
|
|
569
|
+
sequelize: Sequelize;
|
|
570
|
+
logger: LoggerInstanceManager;
|
|
571
|
+
rabbit: rabbit;
|
|
572
|
+
redis: RedisClientType | ReturnType<typeof createClient> | {
|
|
573
|
+
host: string;
|
|
574
|
+
port?: number;
|
|
575
|
+
password?: string;
|
|
576
|
+
db?: number;
|
|
577
|
+
};
|
|
578
|
+
getUserId?: () => string | null;
|
|
579
|
+
emitEvents?: boolean;
|
|
580
|
+
defaults?: {
|
|
581
|
+
pageSize?: number;
|
|
582
|
+
maxJobsPerUser?: number;
|
|
583
|
+
idField?: string;
|
|
584
|
+
workerConcurrency?: number;
|
|
585
|
+
jobTtlSeconds?: number;
|
|
586
|
+
errorLogLimit?: number;
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
declare class Bulker extends EventEmitter implements BulkEventEmitter {
|
|
590
|
+
readonly sequelize: Sequelize;
|
|
591
|
+
readonly logger: BulkerInit["logger"];
|
|
592
|
+
readonly redis: RedisClientType;
|
|
593
|
+
readonly rabbit: rabbit;
|
|
594
|
+
readonly defaults: Required<NonNullable<BulkerInit["defaults"]>>;
|
|
595
|
+
readonly jobManager: JobManager;
|
|
596
|
+
private readonly bulkRouters;
|
|
597
|
+
getUserId: BulkerInit["getUserId"];
|
|
598
|
+
readonly eventsEnabled: boolean;
|
|
599
|
+
constructor(init: BulkerInit);
|
|
600
|
+
createBulkRouter(router?: Router, staticRoute?: string): BulkRouter;
|
|
601
|
+
/**
|
|
602
|
+
* Emit event only if events are enabled.
|
|
603
|
+
* Centralizes the eventsEnabled check to avoid repetition.
|
|
604
|
+
*/
|
|
605
|
+
emitEvent<K extends keyof BulkRouterEvents$1>(event: K, ...args: Parameters<BulkRouterEvents$1[K]>): void;
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
export { type BulkRouteOptions, type BulkRouterEvents, Bulker, BulkerError, JobManager as BulkerJobManager, type IBulkEventEmitter, type JobMetadata, type JobStatus, type LiteralAttribute, type MiddlewareValidationOption, formatOperators, generateFilterReplacements, queryFormatMiddleware, queryHandler, queryValidationMiddleware, validatePayload, z };
|
|
609
|
+
//# sourceMappingURL=index.d.cts.map
|