@porulle/jobs-trigger 0.63.0 → 0.65.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.
Files changed (3) hide show
  1. package/dist/index.js +11 -17
  2. package/package.json +4 -4
  3. package/src/index.ts +11 -21
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { task as createTriggerTask, tasks as triggerTasks, } from "@trigger.dev/sdk";
2
+ import { prepareEnqueue } from "@porulle/core/jobs";
2
3
  export class TriggerExecutionEngine {
3
4
  execution = { mode: "push" };
4
5
  tasks = [];
@@ -17,32 +18,25 @@ export class TriggerExecutionEngine {
17
18
  }
18
19
  }
19
20
  async enqueue(taskSlug, input, options) {
20
- const definition = this.requireSetup().tasks.get(taskSlug);
21
- if (!definition)
22
- throw new Error(`Unknown task slug: ${taskSlug}`);
23
- const organizationId = options.organizationId.trim();
24
- if (!organizationId)
25
- throw new Error("Jobs enqueue requires a non-empty organizationId.");
26
- const concurrencyKey = options.concurrencyKey ?? definition.concurrency?.key(input);
27
- const exclusive = Boolean(definition.concurrency && definition.concurrency.exclusive !== false);
28
- const supersedes = options.supersedes ?? definition.concurrency?.supersedes;
29
- const maxAttempts = options.maxAttempts ?? definition.retries?.attempts ?? 1;
21
+ const prepared = prepareEnqueue(this.requireSetup().tasks, taskSlug, input, options);
30
22
  const payload = {
31
23
  input,
32
- organizationId,
33
- maxAttempts,
34
- ...(concurrencyKey ? { concurrencyKey } : {}),
24
+ organizationId: prepared.organizationId,
25
+ maxAttempts: prepared.maxAttempts,
26
+ ...(prepared.concurrencyKey ? { concurrencyKey: prepared.concurrencyKey } : {}),
35
27
  };
36
28
  const handle = await triggerTasks.trigger(taskSlug, payload, {
37
- maxAttempts,
38
- ...(exclusive && concurrencyKey ? { concurrencyKey } : {}),
29
+ maxAttempts: prepared.maxAttempts,
30
+ ...(prepared.exclusive && prepared.concurrencyKey
31
+ ? { concurrencyKey: prepared.concurrencyKey }
32
+ : {}),
39
33
  ...(options.delayMs !== undefined
40
34
  ? { delay: new Date(Date.now() + options.delayMs) }
41
35
  : {}),
42
- ...(supersedes && concurrencyKey
36
+ ...(prepared.supersedes && prepared.concurrencyKey
43
37
  ? {
44
38
  debounce: {
45
- key: concurrencyKey,
39
+ key: prepared.concurrencyKey,
46
40
  delay: this.supersedesDebounce,
47
41
  mode: "trailing",
48
42
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/jobs-trigger",
3
- "version": "0.63.0",
3
+ "version": "0.65.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -12,15 +12,15 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@trigger.dev/sdk": "^4.5.4",
15
- "@porulle/core": "0.63.0"
15
+ "@porulle/core": "0.65.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^24.5.2",
19
19
  "eslint": "^9.39.1",
20
20
  "typescript": "5.9.2",
21
21
  "vitest": "^3.2.4",
22
- "@porulle/eslint-config": "0.1.0",
23
- "@porulle/typescript-config": "0.1.0"
22
+ "@porulle/typescript-config": "0.1.0",
23
+ "@porulle/eslint-config": "0.1.0"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  task as createTriggerTask,
3
3
  tasks as triggerTasks,
4
4
  } from "@trigger.dev/sdk";
5
+ import { prepareEnqueue } from "@porulle/core/jobs";
5
6
  import type { AnyTask } from "@trigger.dev/sdk";
6
7
  import type {
7
8
  EnqueueOptions,
@@ -50,36 +51,25 @@ export class TriggerExecutionEngine implements ExecutionEngine {
50
51
  input: Record<string, unknown>,
51
52
  options: EnqueueOptions,
52
53
  ): Promise<string> {
53
- const definition = this.requireSetup().tasks.get(taskSlug);
54
- if (!definition) throw new Error(`Unknown task slug: ${taskSlug}`);
55
- const organizationId = options.organizationId.trim();
56
- if (!organizationId)
57
- throw new Error("Jobs enqueue requires a non-empty organizationId.");
58
-
59
- const concurrencyKey =
60
- options.concurrencyKey ?? definition.concurrency?.key(input);
61
- const exclusive = Boolean(
62
- definition.concurrency && definition.concurrency.exclusive !== false,
63
- );
64
- const supersedes = options.supersedes ?? definition.concurrency?.supersedes;
65
- const maxAttempts =
66
- options.maxAttempts ?? definition.retries?.attempts ?? 1;
54
+ const prepared = prepareEnqueue(this.requireSetup().tasks, taskSlug, input, options);
67
55
  const payload: TriggerJobPayload = {
68
56
  input,
69
- organizationId,
70
- maxAttempts,
71
- ...(concurrencyKey ? { concurrencyKey } : {}),
57
+ organizationId: prepared.organizationId,
58
+ maxAttempts: prepared.maxAttempts,
59
+ ...(prepared.concurrencyKey ? { concurrencyKey: prepared.concurrencyKey } : {}),
72
60
  };
73
61
  const handle = await triggerTasks.trigger(taskSlug, payload, {
74
- maxAttempts,
75
- ...(exclusive && concurrencyKey ? { concurrencyKey } : {}),
62
+ maxAttempts: prepared.maxAttempts,
63
+ ...(prepared.exclusive && prepared.concurrencyKey
64
+ ? { concurrencyKey: prepared.concurrencyKey }
65
+ : {}),
76
66
  ...(options.delayMs !== undefined
77
67
  ? { delay: new Date(Date.now() + options.delayMs) }
78
68
  : {}),
79
- ...(supersedes && concurrencyKey
69
+ ...(prepared.supersedes && prepared.concurrencyKey
80
70
  ? {
81
71
  debounce: {
82
- key: concurrencyKey,
72
+ key: prepared.concurrencyKey,
83
73
  delay: this.supersedesDebounce,
84
74
  mode: "trailing" as const,
85
75
  },