@tstdl/base 0.93.120 → 0.93.122

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.
@@ -1,5 +1,6 @@
1
1
  export * from './api/index.js';
2
2
  export * from './module.js';
3
+ export * from './modules/index.js';
3
4
  export * from './providers/index.js';
4
5
  export * from './schemas.js';
5
6
  export * from './services/index.js';
@@ -1,5 +1,6 @@
1
1
  export * from './api/index.js';
2
2
  export * from './module.js';
3
+ export * from './modules/index.js';
3
4
  export * from './providers/index.js';
4
5
  export * from './schemas.js';
5
6
  export * from './services/index.js';
@@ -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,9 @@
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
+ constructor();
7
+ [afterResolve](): void;
8
+ _run(cancellationSignal: CancellationSignal): Promise<void>;
9
+ }
@@ -0,0 +1,37 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { CancellationSignal } from '../../../cancellation/token.js';
11
+ import { afterResolve, inject, Singleton } from '../../../injector/index.js';
12
+ import { Module } from '../../../module/module.js';
13
+ import { NotificationChannel } from '../../../notification/models/index.js';
14
+ import { EmailChannelProvider, InAppChannelProvider, WebPushChannelProvider } from '../providers/index.js';
15
+ import { NotificationDeliveryWorker } from '../services/index.js';
16
+ let NotificationDeliveryWorkerModule = class NotificationDeliveryWorkerModule extends Module {
17
+ #notificationDeliveryWorker = inject(NotificationDeliveryWorker);
18
+ #inAppChannelProvider = inject(InAppChannelProvider);
19
+ #emailChannelProvider = inject(EmailChannelProvider);
20
+ #webPushChannelProvider = inject(WebPushChannelProvider);
21
+ constructor() {
22
+ super('NotificationDeliveryWorker');
23
+ }
24
+ [afterResolve]() {
25
+ this.#notificationDeliveryWorker.registerProvider(NotificationChannel.InApp, this.#inAppChannelProvider);
26
+ this.#notificationDeliveryWorker.registerProvider(NotificationChannel.Email, this.#emailChannelProvider);
27
+ this.#notificationDeliveryWorker.registerProvider(NotificationChannel.WebPush, this.#webPushChannelProvider);
28
+ }
29
+ async _run(cancellationSignal) {
30
+ await this.#notificationDeliveryWorker.run(cancellationSignal);
31
+ }
32
+ };
33
+ NotificationDeliveryWorkerModule = __decorate([
34
+ Singleton(),
35
+ __metadata("design:paramtypes", [])
36
+ ], NotificationDeliveryWorkerModule);
37
+ 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.process({ cancellationSignal }, async (context) => {
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,4 +1,3 @@
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';
@@ -6,7 +5,6 @@ import { NotificationChannel, NotificationPreference, type InAppNotificationView
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,9 +7,8 @@ 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 { afterResolve, inject, Singleton } from '../../../injector/index.js';
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';
@@ -17,10 +16,8 @@ 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
18
  import { InAppNotification, NotificationChannel, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
20
- import { InAppChannelProvider } from '../providers/index.js';
21
19
  import { inAppNotification, notificationLog } from '../schemas.js';
22
20
  import { NotificationAncillaryService } from './notification-ancillary.service.js';
23
- import { NotificationDeliveryWorker } from './notification-delivery.worker.js';
24
21
  import { NotificationSseService } from './notification-sse.service.js';
25
22
  let NotificationService = NotificationService_1 = class NotificationService extends Transactional {
26
23
  #notificationLogRepository = injectRepository(NotificationLogEntity);
@@ -28,16 +25,9 @@ let NotificationService = NotificationService_1 = class NotificationService exte
28
25
  #preferenceRepository = injectRepository(NotificationPreference);
29
26
  #webPushSubscriptionRepository = injectRepository(WebPushSubscription);
30
27
  #notificationAncillaryService = inject(NotificationAncillaryService);
31
- #deliveryWorker = inject(NotificationDeliveryWorker);
32
- #inAppChannelProvider = inject(InAppChannelProvider);
33
28
  #taskQueue = inject((TaskQueue), 'notification');
34
29
  #sseService = inject(NotificationSseService);
35
30
  #logger = inject(Logger, NotificationService_1.name);
36
- #cancellationSignal = inject(CancellationSignal);
37
- [afterResolve]() {
38
- this.#deliveryWorker.registerProvider(NotificationChannel.InApp, this.#inAppChannelProvider);
39
- this.#deliveryWorker.run(this.#cancellationSignal);
40
- }
41
31
  async send(tenantId, userId, notification, options) {
42
32
  await this.useTransaction(options?.transaction, async (tx) => {
43
33
  const notificationToInsert = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.120",
3
+ "version": "0.93.122",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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
- private processWorker;
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
  }
@@ -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();