@tstdl/base 0.93.119 → 0.93.121
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/notification/server/modules/index.d.ts +1 -0
- package/notification/server/modules/index.js +1 -0
- package/notification/server/modules/notification-delivery-worker.module.d.ts +8 -0
- package/notification/server/modules/notification-delivery-worker.module.js +26 -0
- package/notification/server/services/notification-delivery.worker.d.ts +1 -1
- package/notification/server/services/notification-delivery.worker.js +2 -2
- package/notification/server/services/notification.service.d.ts +1 -3
- package/notification/server/services/notification.service.js +2 -9
- package/package.json +1 -1
- package/task-queue/task-queue.d.ts +10 -1
- package/task-queue/task-queue.js +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification-delivery-worker.module.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification-delivery-worker.module.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CancellationSignal } from '../../../cancellation/token.js';
|
|
2
|
+
import { afterResolve } from '../../../injector/index.js';
|
|
3
|
+
import { Module } from '../../../module/module.js';
|
|
4
|
+
export declare class NotificationDeliveryWorkerModule extends Module {
|
|
5
|
+
#private;
|
|
6
|
+
[afterResolve](): void;
|
|
7
|
+
_run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { CancellationSignal } from '../../../cancellation/token.js';
|
|
8
|
+
import { afterResolve, inject, Singleton } from '../../../injector/index.js';
|
|
9
|
+
import { Module } from '../../../module/module.js';
|
|
10
|
+
import { NotificationChannel } from '../../../notification/models/index.js';
|
|
11
|
+
import { InAppChannelProvider } from '../providers/index.js';
|
|
12
|
+
import { NotificationDeliveryWorker } from '../services/index.js';
|
|
13
|
+
let NotificationDeliveryWorkerModule = class NotificationDeliveryWorkerModule extends Module {
|
|
14
|
+
#notificationDeliveryWorker = inject(NotificationDeliveryWorker);
|
|
15
|
+
#inAppChannelProvider = inject(InAppChannelProvider);
|
|
16
|
+
[afterResolve]() {
|
|
17
|
+
this.#notificationDeliveryWorker.registerProvider(NotificationChannel.InApp, this.#inAppChannelProvider);
|
|
18
|
+
}
|
|
19
|
+
async _run(cancellationSignal) {
|
|
20
|
+
await this.#notificationDeliveryWorker.run(cancellationSignal);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
NotificationDeliveryWorkerModule = __decorate([
|
|
24
|
+
Singleton()
|
|
25
|
+
], NotificationDeliveryWorkerModule);
|
|
26
|
+
export { NotificationDeliveryWorkerModule };
|
|
@@ -12,7 +12,7 @@ export type NotificationTaskDefinitions = TaskDefinitionMap<{
|
|
|
12
12
|
export declare class NotificationDeliveryWorker extends Transactional {
|
|
13
13
|
#private;
|
|
14
14
|
registerProvider(channel: NotificationChannel, provider: ChannelProvider): void;
|
|
15
|
-
run(cancellationSignal: CancellationSignal): void
|
|
15
|
+
run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
16
16
|
deliver(notificationId: string): Promise<TaskProcessResult<void>>;
|
|
17
17
|
private sendToChannel;
|
|
18
18
|
}
|
|
@@ -27,8 +27,8 @@ let NotificationDeliveryWorker = class NotificationDeliveryWorker extends Transa
|
|
|
27
27
|
registerProvider(channel, provider) {
|
|
28
28
|
this.#providers.set(channel, provider);
|
|
29
29
|
}
|
|
30
|
-
run(cancellationSignal) {
|
|
31
|
-
this.#taskQueue.
|
|
30
|
+
async run(cancellationSignal) {
|
|
31
|
+
await this.#taskQueue.processWorker(cancellationSignal, async (context) => {
|
|
32
32
|
const { notificationId } = context.data;
|
|
33
33
|
try {
|
|
34
34
|
const result = await this.deliver(notificationId);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { afterResolve } from '../../../injector/index.js';
|
|
2
1
|
import { type NewEntity } from '../../../orm/index.js';
|
|
3
2
|
import { Transactional, type Transaction } from '../../../orm/server/index.js';
|
|
4
3
|
import type { TypedOmit } from '../../../types/types.js';
|
|
5
|
-
import { NotificationPreference, type InAppNotificationView, type
|
|
4
|
+
import { NotificationChannel, NotificationPreference, type InAppNotificationView, type NotificationDefinitionMap, type NotificationLog } from '../../models/index.js';
|
|
6
5
|
export type NewNotificationData<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> = TypedOmit<NewEntity<NotificationLog<Definitions>>, 'tenantId' | 'id' | 'userId' | 'timestamp' | 'status' | 'currentStep' | 'priority'> & Partial<Pick<NotificationLog<Definitions>, 'priority'>>;
|
|
7
6
|
export declare class NotificationService<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> extends Transactional {
|
|
8
7
|
#private;
|
|
9
|
-
[afterResolve](): void;
|
|
10
8
|
send(tenantId: string, userId: string, notification: NewNotificationData<Definitions>, options?: {
|
|
11
9
|
transaction: Transaction;
|
|
12
10
|
}): Promise<void>;
|
|
@@ -7,19 +7,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var _a;
|
|
8
8
|
var NotificationService_1;
|
|
9
9
|
import { and, desc, eq, isNull, lt, or } from 'drizzle-orm';
|
|
10
|
-
import { CancellationSignal } from '../../../cancellation/token.js';
|
|
11
10
|
import { BadRequestError } from '../../../errors/bad-request.error.js';
|
|
12
|
-
import {
|
|
11
|
+
import { inject, Singleton } from '../../../injector/index.js';
|
|
13
12
|
import { Logger } from '../../../logger/logger.js';
|
|
14
13
|
import { TRANSACTION_TIMESTAMP } from '../../../orm/index.js';
|
|
15
14
|
import { injectRepository, Transactional } from '../../../orm/server/index.js';
|
|
16
15
|
import { TaskQueue } from '../../../task-queue/task-queue.js';
|
|
17
16
|
import { tryIgnoreLogAsync } from '../../../utils/try-ignore.js';
|
|
18
17
|
import { isDefined } from '../../../utils/type-guards.js';
|
|
19
|
-
import { InAppNotification, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
|
|
18
|
+
import { InAppNotification, NotificationChannel, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
|
|
20
19
|
import { inAppNotification, notificationLog } from '../schemas.js';
|
|
21
20
|
import { NotificationAncillaryService } from './notification-ancillary.service.js';
|
|
22
|
-
import { NotificationDeliveryWorker } from './notification-delivery.worker.js';
|
|
23
21
|
import { NotificationSseService } from './notification-sse.service.js';
|
|
24
22
|
let NotificationService = NotificationService_1 = class NotificationService extends Transactional {
|
|
25
23
|
#notificationLogRepository = injectRepository(NotificationLogEntity);
|
|
@@ -27,14 +25,9 @@ let NotificationService = NotificationService_1 = class NotificationService exte
|
|
|
27
25
|
#preferenceRepository = injectRepository(NotificationPreference);
|
|
28
26
|
#webPushSubscriptionRepository = injectRepository(WebPushSubscription);
|
|
29
27
|
#notificationAncillaryService = inject(NotificationAncillaryService);
|
|
30
|
-
#deliveryWorker = inject(NotificationDeliveryWorker);
|
|
31
28
|
#taskQueue = inject((TaskQueue), 'notification');
|
|
32
29
|
#sseService = inject(NotificationSseService);
|
|
33
30
|
#logger = inject(Logger, NotificationService_1.name);
|
|
34
|
-
#cancellationSignal = inject(CancellationSignal);
|
|
35
|
-
[afterResolve]() {
|
|
36
|
-
this.#deliveryWorker.run(this.#cancellationSignal);
|
|
37
|
-
}
|
|
38
31
|
async send(tenantId, userId, notification, options) {
|
|
39
32
|
await this.useTransaction(options?.transaction, async (tx) => {
|
|
40
33
|
const notificationToInsert = {
|
package/package.json
CHANGED
|
@@ -300,6 +300,9 @@ export declare abstract class TaskQueue<Definitions extends TaskDefinitionMap =
|
|
|
300
300
|
forceDequeue?: boolean;
|
|
301
301
|
types?: Type[];
|
|
302
302
|
}): AsyncIterableIterator<TaskOfType<Definitions, Type>[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Starts processing tasks with the provided worker function in the background until the cancellation signal is triggered.
|
|
305
|
+
*/
|
|
303
306
|
process<Type extends TaskTypes<Definitions>>({ concurrency, cancellationSignal, types, forceDequeue }: {
|
|
304
307
|
concurrency?: number;
|
|
305
308
|
cancellationSignal: CancellationSignal;
|
|
@@ -309,5 +312,11 @@ export declare abstract class TaskQueue<Definitions extends TaskDefinitionMap =
|
|
|
309
312
|
protected getTransactionalContextData(): QueueConfig & {
|
|
310
313
|
namespace: string;
|
|
311
314
|
};
|
|
312
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Starts processing tasks with the provided worker function in the foreground until the cancellation signal is triggered.
|
|
317
|
+
*/
|
|
318
|
+
processWorker<Type extends TaskTypes<Definitions>>(cancellationSignal: CancellationSignal, handler: ProcessWorker<Definitions, Type>, options?: {
|
|
319
|
+
types?: Type[];
|
|
320
|
+
forceDequeue?: boolean;
|
|
321
|
+
}): Promise<void>;
|
|
313
322
|
}
|
package/task-queue/task-queue.js
CHANGED
|
@@ -83,6 +83,9 @@ export class TaskQueue extends Transactional {
|
|
|
83
83
|
batch() {
|
|
84
84
|
return new TaskQueueEnqueueBatch(this);
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Starts processing tasks with the provided worker function in the background until the cancellation signal is triggered.
|
|
88
|
+
*/
|
|
86
89
|
process({ concurrency = 1, cancellationSignal, types, forceDequeue }, handler) {
|
|
87
90
|
for (let i = 0; i < concurrency; i++) {
|
|
88
91
|
void this.processWorker(cancellationSignal, handler, { types, forceDequeue });
|
|
@@ -91,6 +94,9 @@ export class TaskQueue extends Transactional {
|
|
|
91
94
|
getTransactionalContextData() {
|
|
92
95
|
return this.config;
|
|
93
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Starts processing tasks with the provided worker function in the foreground until the cancellation signal is triggered.
|
|
99
|
+
*/
|
|
94
100
|
async processWorker(cancellationSignal, handler, options) {
|
|
95
101
|
for await (const task of this.getConsumer(cancellationSignal, options)) {
|
|
96
102
|
const taskToken = cancellationSignal.createChild();
|