@tsed/pulse 8.38.8 → 8.39.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.
@@ -1,4 +1,10 @@
1
1
  import { Store } from "@tsed/core";
2
+ /**
3
+ * Register the decorated method as a Pulse job processor.
4
+ *
5
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
6
+ * Use `Define` from `@tsed/agenda` instead.
7
+ */
2
8
  export function Define(options = {}) {
3
9
  return (target, propertyKey) => {
4
10
  const store = {
@@ -1,5 +1,11 @@
1
1
  import { Store, useDecorators } from "@tsed/core";
2
2
  import { Define } from "./define.js";
3
+ /**
4
+ * Schedule the decorated method as a recurring Pulse job.
5
+ *
6
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
7
+ * Use `Every` from `@tsed/agenda` instead.
8
+ */
3
9
  export function Every(interval, options = {}) {
4
10
  return useDecorators(Define(options), (target, propertyKey) => {
5
11
  const store = {
@@ -1,12 +1,19 @@
1
1
  import { StoreMerge, useDecorators } from "@tsed/core";
2
2
  import { Injectable } from "@tsed/di";
3
3
  import { PROVIDER_TYPE_PULSE } from "../constants/constants.js";
4
+ /**
5
+ * Declare a class as a Pulse jobs controller.
6
+ *
7
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
8
+ * Use `JobsController` from `@tsed/agenda` instead.
9
+ */
4
10
  export function JobsController(options) {
5
11
  return useDecorators(options?.namespace && StoreMerge("pulse", options), Injectable({
6
12
  type: PROVIDER_TYPE_PULSE
7
13
  }));
8
14
  }
9
15
  /**
10
- * @deprecated Use `JobsController` instead.
16
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
17
+ * Use `JobsController` from `@tsed/agenda` instead.
11
18
  */
12
19
  export const Pulse = JobsController;
@@ -77,6 +77,10 @@ async function onDestroy(pulse) {
77
77
  logger().info({ event: "PULSE_STOP", message: "Pulse stopped" });
78
78
  }
79
79
  }
80
+ /**
81
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
82
+ * Inject `Agenda` from `agenda` instead.
83
+ */
80
84
  export const PulseService = injectable(Pulse)
81
85
  .factory(() => {
82
86
  const opts = getOpts();
@@ -116,6 +120,7 @@ export const PulseService = injectable(Pulse)
116
120
  })
117
121
  .token();
118
122
  /**
119
- * @deprecated Use `Pulse` from `pulse` instead.
123
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
124
+ * Inject `Agenda` from `agenda` instead.
120
125
  */
121
126
  export const PulseModule = Pulse;
@@ -1,2 +1,8 @@
1
1
  import { DefineOptions } from "../interfaces/PulseStore.js";
2
+ /**
3
+ * Register the decorated method as a Pulse job processor.
4
+ *
5
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
6
+ * Use `Define` from `@tsed/agenda` instead.
7
+ */
2
8
  export declare function Define(options?: DefineOptions): MethodDecorator;
@@ -1,2 +1,8 @@
1
1
  import { EveryOptions } from "../interfaces/PulseStore.js";
2
+ /**
3
+ * Schedule the decorated method as a recurring Pulse job.
4
+ *
5
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
6
+ * Use `Every` from `@tsed/agenda` instead.
7
+ */
2
8
  export declare function Every(interval: string, options?: EveryOptions): MethodDecorator;
@@ -1,9 +1,16 @@
1
1
  interface PulseOptions {
2
2
  namespace?: string;
3
3
  }
4
+ /**
5
+ * Declare a class as a Pulse jobs controller.
6
+ *
7
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
8
+ * Use `JobsController` from `@tsed/agenda` instead.
9
+ */
4
10
  export declare function JobsController(options?: PulseOptions): ClassDecorator;
5
11
  /**
6
- * @deprecated Use `JobsController` instead.
12
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
13
+ * Use `JobsController` from `@tsed/agenda` instead.
7
14
  */
8
15
  export declare const Pulse: typeof JobsController;
9
16
  export {};
@@ -1,4 +1,8 @@
1
1
  import { PulseConfig } from "@pulsecron/pulse";
2
+ /**
3
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
4
+ * Use `AgendaSettings` from `@tsed/agenda` with `agenda.backend: new MongoBackend(...)` instead.
5
+ */
2
6
  export type PulseSettings = PulseConfig & {
3
7
  enabled?: boolean;
4
8
  disableJobProcessing?: boolean;
@@ -7,6 +11,10 @@ export type PulseSettings = PulseConfig & {
7
11
  declare global {
8
12
  namespace TsED {
9
13
  interface Configuration {
14
+ /**
15
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
16
+ * Use the `agenda` configuration key from `@tsed/agenda` instead.
17
+ */
10
18
  pulse?: PulseSettings;
11
19
  }
12
20
  }
@@ -1,13 +1,23 @@
1
1
  import { Pulse } from "@pulsecron/pulse";
2
+ /**
3
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
4
+ * Inject `Agenda` from `agenda` instead.
5
+ */
2
6
  export declare const PulseService: {
3
7
  readonly __type: "token_factory";
4
8
  };
5
9
  /**
6
- * @deprecated Use `Pulse` from `pulse` instead.
10
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
11
+ * Inject `Agenda` from `agenda` instead.
7
12
  */
8
13
  export type PulseService = Pulse;
9
14
  /**
10
- * @deprecated Use `Pulse` from `pulse` instead.
15
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
16
+ * Inject `Agenda` from `agenda` instead.
11
17
  */
12
18
  export declare const PulseModule: typeof Pulse;
19
+ /**
20
+ * @deprecated `@tsed/pulse` is deprecated and will be removed in a future major release. Migrate to `@tsed/agenda` (Agenda v6). See https://tsed.dev/tutorials/pulse.html#migrate-to-tsed-agenda
21
+ * Inject `Agenda` from `agenda` instead.
22
+ */
13
23
  export type PulseModule = Pulse;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/pulse",
3
- "version": "8.38.8",
4
- "description": "@pulsecron/pulse package for Ts.ED framework",
3
+ "version": "8.39.0",
4
+ "description": "[DEPRECATED] @pulsecron/pulse package for Ts.ED framework. Use @tsed/agenda with Agenda v6 instead.",
5
5
  "source": "./src/index.ts",
6
6
  "type": "module",
7
7
  "main": "./lib/esm/index.js",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@pulsecron/pulse": "^1.6.3",
30
- "@tsed/barrels": "8.38.8",
31
- "@tsed/core": "8.38.8",
32
- "@tsed/di": "8.38.8",
33
- "@tsed/platform-http": "8.38.8",
34
- "@tsed/typescript": "8.38.8",
30
+ "@tsed/barrels": "8.39.0",
31
+ "@tsed/core": "8.39.0",
32
+ "@tsed/di": "8.39.0",
33
+ "@tsed/platform-http": "8.39.0",
34
+ "@tsed/typescript": "8.39.0",
35
35
  "typescript": "6.0.2",
36
36
  "vitest": "4.1.4"
37
37
  },
package/readme.md CHANGED
@@ -30,35 +30,59 @@
30
30
 
31
31
  A package of Ts.ED framework. See website: https://tsed.dev
32
32
 
33
- > [!WARNING] > `@tsed/pulse` is deprecated and will be removed in a future major release.
34
- > This package won't receive any future updates.
35
- > For new projects, use `@tsed/agenda` with Agenda v6.
36
- > Existing consumers should plan a migration to `@tsed/agenda` + `agenda` + `@agendajs/mongo-backend`.
33
+ > [!WARNING]
34
+ > `@tsed/pulse` is deprecated and will be removed in a future major release.
35
+ > This package won't receive any future updates. Do not start new projects on `@tsed/pulse`.
37
36
  >
38
- > The legacy Pulse examples below are kept only to help existing consumers maintain or migrate old code.
37
+ > For new projects, use [`@tsed/agenda`](https://tsed.dev/tutorials/agenda.html) with Agenda v6.
38
+ > Existing `@tsed/pulse` users should plan a migration to `@tsed/agenda` + `agenda` + `@agendajs/mongo-backend`
39
+ > by following the [migration guide](#migrate-to-tsedagenda) below.
40
+ >
41
+ > The legacy Pulse examples at the end of this page are kept only to help existing consumers maintain or migrate old code.
39
42
 
40
43
  ## Feature
41
44
 
42
- `@pulsecron/pulse` is maintained fork of the Agenda.
43
-
44
- Currently, `@tsed/pulse` allows you to decorate classes with `@Pulse` and
45
- corresponding methods to have them picked up by the @pulsecron/pulse library to be
45
+ `@pulsecron/pulse` is a fork of Agenda. `@tsed/pulse` allowed you to decorate classes with `@Pulse` and
46
+ corresponding methods to have them picked up by the `@pulsecron/pulse` library to be
46
47
  scheduled automatically (`@Every`) or programmatically (`@Define`) via the PulseService.
47
48
 
48
- For more information about Pulse look at the documentation [here](https://github.com/pulsecron/pulse);
49
+ The same features are available in `@tsed/agenda` on top of Agenda v6, which is the recommended and maintained
50
+ scheduling integration for Ts.ED. See the [Agenda documentation](https://tsed.dev/tutorials/agenda.html).
49
51
 
50
52
  ## Installation
51
53
 
52
- To begin, install the Pulse module for Ts.ED:
54
+ Do not install `@tsed/pulse` for new projects. Install the recommended Agenda v6 stack instead:
53
55
 
54
56
  ```bash
55
- npm install --save @tsed/pulse
56
- npm install --save @pulsecron/pulse
57
+ npm install --save @tsed/agenda agenda @agendajs/mongo-backend
57
58
  ```
58
59
 
59
- ## Migration note
60
+ Then follow the [Agenda documentation](https://tsed.dev/tutorials/agenda.html) to configure your server.
61
+
62
+ > [!NOTE]
63
+ > Only if you maintain an existing project that cannot migrate yet:
64
+ > `npm install --save @tsed/pulse @pulsecron/pulse`.
65
+
66
+ ## Migrate to `@tsed/agenda`
60
67
 
61
- Prefer `@tsed/agenda` over `@tsed/pulse`.
68
+ The target stack is `@tsed/agenda` + `agenda` (v6) + `@agendajs/mongo-backend`.
69
+
70
+ ### 1. Replace dependencies
71
+
72
+ | Remove | Add |
73
+ | ------------------ | ------------------------- |
74
+ | `@tsed/pulse` | `@tsed/agenda` |
75
+ | `@pulsecron/pulse` | `agenda` |
76
+ | | `@agendajs/mongo-backend` |
77
+
78
+ ```bash
79
+ npm uninstall @tsed/pulse @pulsecron/pulse
80
+ npm install --save @tsed/agenda agenda @agendajs/mongo-backend
81
+ ```
82
+
83
+ ### 2. Update the server configuration
84
+
85
+ The `pulse` configuration key becomes `agenda`, and the legacy `db` options move into a `MongoBackend` instance.
62
86
 
63
87
  ```diff
64
88
  import {Configuration} from "@tsed/di";
@@ -81,10 +105,19 @@ Prefer `@tsed/agenda` over `@tsed/pulse`.
81
105
  export class Server {}
82
106
  ```
83
107
 
108
+ The Ts.ED specific flags (`enabled`, `disableJobProcessing`, `drainJobsBeforeClose`) keep the same names and
109
+ behavior in `@tsed/agenda`.
110
+
111
+ ### 3. Update decorators, injection and lifecycle hooks
112
+
113
+ `@tsed/agenda` exposes the same `@Every` and `@Define` decorators. The class decorator is `@JobsController`
114
+ and the scheduler instance is the `Agenda` class from `agenda` (there is no `AgendaModule`).
115
+
84
116
  ```diff
85
117
  -import {Pulse, Every, Define, PulseModule} from "@tsed/pulse";
118
+ -import {Job} from "@pulsecron/pulse";
86
119
  +import {JobsController, Every, Define} from "@tsed/agenda";
87
- +import {Agenda} from "agenda";
120
+ +import {Agenda, Job} from "agenda";
88
121
 
89
122
  -@Pulse({namespace: "email"})
90
123
  +@JobsController({namespace: "email"})
@@ -92,10 +125,89 @@ Prefer `@tsed/agenda` over `@tsed/pulse`.
92
125
  @Inject()
93
126
  - pulse: PulseModule;
94
127
  + agenda: Agenda;
128
+
129
+ @Every("60 minutes", {name: "maintenanceJob"})
130
+ async sendAdminStatistics(job: Job) {}
131
+
132
+ @Define({name: "sendWelcomeEmail"})
133
+ async sendWelcomeEmail(job: Job) {}
134
+
135
+ - async $beforePulseStart() {}
136
+ - async $afterPulseStart() {}
137
+ + async $beforeAgendaStart() {}
138
+ + async $afterAgendaStart() {}
139
+ }
140
+ ```
141
+
142
+ Scheduling APIs keep the same shape (`now()`, `schedule()`, `every()`, `create()`), so call sites only need the
143
+ injected instance to be renamed:
144
+
145
+ ```diff
146
+ @Service()
147
+ export class UsersService {
148
+ @Inject()
149
+ - private pulse: PulseModule;
150
+ + private agenda: Agenda;
151
+
152
+ async create(user: User) {
153
+ - await this.pulse.now("email.sendWelcomeEmail", {user});
154
+ - await this.pulse.schedule("in 2 hours", "email.sendFollowUpEmail", {user});
155
+ + await this.agenda.now("email.sendWelcomeEmail", {user});
156
+ + await this.agenda.schedule("in 2 hours", "email.sendFollowUpEmail", {user});
157
+ }
95
158
  }
96
159
  ```
97
160
 
98
- ## Configure your server
161
+ ### AI migration note
162
+
163
+ Apply these deterministic rewrites when migrating a codebase with a coding agent:
164
+
165
+ ```text
166
+ Migrate from @tsed/pulse to @tsed/agenda (Agenda v6):
167
+
168
+ Dependencies
169
+ - remove `@tsed/pulse` → add `@tsed/agenda`
170
+ - remove `@pulsecron/pulse` → add `agenda` + `@agendajs/mongo-backend`
171
+
172
+ Imports
173
+ - `import "@tsed/pulse"` → `import "@tsed/agenda"`
174
+ - `import {Pulse, JobsController, Every, Define, PulseModule, PulseService} from "@tsed/pulse"` → `import {JobsController, Every, Define} from "@tsed/agenda"`
175
+ - `import {Job} from "@pulsecron/pulse"` → `import {Job} from "agenda"`
176
+ - add `import {Agenda} from "agenda"` where `PulseModule` / `PulseService` was injected
177
+ - add `import {MongoBackend} from "@agendajs/mongo-backend"` in the server configuration file
178
+
179
+ Configuration (@Configuration / TsED.Configuration)
180
+ - `pulse: {...}` config key → `agenda: {...}`
181
+ - `pulse.db.address` → `agenda.backend: new MongoBackend({address})`
182
+ - `pulse.db.collection` / `pulse.db.options` → `agenda.backend: new MongoBackend({collection, options})`
183
+ - `pulse.mongo` → `agenda.backend: new MongoBackend({mongo})`
184
+ - `pulse.ensureIndex` / `pulse.sort` → move inside `new MongoBackend({ensureIndex, sort})`, sort directions use `"asc"` / `"desc"`
185
+ - `pulse.enabled`, `pulse.disableJobProcessing`, `pulse.drainJobsBeforeClose` → keep the same names under `agenda`
186
+ - `PulseSettings` type → `AgendaSettings`
187
+
188
+ Decorators and injection
189
+ - `@Pulse(...)` → `@JobsController(...)`
190
+ - `@JobsController(...)` (from `@tsed/pulse`) → `@JobsController(...)` (from `@tsed/agenda`)
191
+ - `@Every(...)` / `@Define(...)` → unchanged (import them from `@tsed/agenda`)
192
+ - `PulseModule` / `PulseService` injected type → `Agenda` (from `agenda`)
193
+ - `pulse.now(...)`, `pulse.schedule(...)`, `pulse.every(...)`, `pulse.create(...)`, `pulse.define(...)` → same methods on the injected `Agenda`
194
+ - `pulse.jobs(...)` → `agenda.queryJobs(...)`
195
+
196
+ Lifecycle hooks
197
+ - `$beforePulseStart()` → `$beforeAgendaStart()`
198
+ - `$afterPulseStart()` → `$afterAgendaStart()`
199
+ ```
200
+
201
+ For more details about `@tsed/agenda`, see [Agenda for Ts.ED](https://tsed.dev/tutorials/agenda.html)
202
+ (LLM-friendly version: https://tsed.dev/tutorials/agenda.md).
203
+
204
+ ## Legacy usage (existing projects only)
205
+
206
+ > [!WARNING]
207
+ > The following sections document the deprecated `@tsed/pulse` API. They are kept for reference only.
208
+ > Do not use them for new code.
209
+
210
+ ### Configure your server
99
211
 
100
212
  Import `@tsed/pulse` in your Server:
101
213
 
@@ -108,7 +220,7 @@ const mongoConnectionString = "mongodb://127.0.0.1/pulse";
108
220
  @Configuration({
109
221
  pulse: {
110
222
  enabled: true, // Enable Pulse jobs for this instance.
111
- // drainJobsBeforeStop: true, // Wait for jobs to finish before stopping the pulse process.
223
+ // drainJobsBeforeClose: true, // Wait for jobs to finish before stopping the pulse process.
112
224
  // disableJobProcessing: true, // Prevents jobs from being processed.
113
225
  // pass any options that you would normally pass to new Pulse(), e.g.
114
226
  db: {
@@ -119,7 +231,7 @@ const mongoConnectionString = "mongodb://127.0.0.1/pulse";
119
231
  export class Server {}
120
232
  ```
121
233
 
122
- ## Create a new Service
234
+ ### Create a new Service
123
235
 
124
236
  Decorate the class with `@Pulse`. The `namespace` option is optional and will
125
237
  prefix the job name with `namespace.`
@@ -160,7 +272,7 @@ export class EmailJobService {
160
272
  }
161
273
  ```
162
274
 
163
- ## Define a job processor manually
275
+ ### Define a job processor manually
164
276
 
165
277
  PulseModule exposes methods to manually define a job processor. It can be useful to define a job processor when you need to fetch data beforehand and dynamically build job name / options.
166
278
 
@@ -206,7 +318,7 @@ export class EmailJobService {
206
318
  }
207
319
  ```
208
320
 
209
- ## Inject Pulse
321
+ ### Inject Pulse
210
322
 
211
323
  Inject the PulseService instance to interact with it directly, e.g. to schedule
212
324
  a job manually.