@trigger.dev/sdk 3.0.0-beta.6 → 3.0.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 (279) hide show
  1. package/dist/commonjs/apiClient.d.ts +737 -0
  2. package/dist/commonjs/apiClient.js +692 -0
  3. package/dist/commonjs/apiClient.js.map +1 -0
  4. package/dist/commonjs/concurrencyLimit.d.ts +10 -0
  5. package/dist/commonjs/concurrencyLimit.js +17 -0
  6. package/dist/commonjs/concurrencyLimit.js.map +1 -0
  7. package/dist/commonjs/errors.d.ts +66 -0
  8. package/dist/commonjs/errors.js +109 -0
  9. package/dist/commonjs/errors.js.map +1 -0
  10. package/dist/commonjs/httpEndpoint.d.ts +87 -0
  11. package/dist/commonjs/httpEndpoint.js +130 -0
  12. package/dist/commonjs/httpEndpoint.js.map +1 -0
  13. package/dist/commonjs/index.d.ts +23 -0
  14. package/dist/commonjs/index.js +55 -0
  15. package/dist/commonjs/index.js.map +1 -0
  16. package/dist/commonjs/integrations.d.ts +11 -0
  17. package/dist/commonjs/integrations.js +3 -0
  18. package/dist/commonjs/integrations.js.map +1 -0
  19. package/dist/commonjs/io.d.ts +453 -0
  20. package/dist/commonjs/io.js +1165 -0
  21. package/dist/commonjs/io.js.map +1 -0
  22. package/dist/commonjs/ioWithIntegrations.d.ts +4 -0
  23. package/dist/commonjs/ioWithIntegrations.js +32 -0
  24. package/dist/commonjs/ioWithIntegrations.js.map +1 -0
  25. package/dist/commonjs/job.d.ts +96 -0
  26. package/dist/commonjs/job.js +210 -0
  27. package/dist/commonjs/job.js.map +1 -0
  28. package/dist/commonjs/package.json +3 -0
  29. package/dist/commonjs/retry.d.ts +20 -0
  30. package/dist/commonjs/retry.js +22 -0
  31. package/dist/commonjs/retry.js.map +1 -0
  32. package/dist/commonjs/runLocalStorage.d.ts +8 -0
  33. package/dist/commonjs/runLocalStorage.js +6 -0
  34. package/dist/commonjs/runLocalStorage.js.map +1 -0
  35. package/dist/commonjs/security.d.ts +18 -0
  36. package/dist/commonjs/security.js +41 -0
  37. package/dist/commonjs/security.js.map +1 -0
  38. package/dist/commonjs/status.d.ts +19 -0
  39. package/dist/commonjs/status.js +38 -0
  40. package/dist/commonjs/status.js.map +1 -0
  41. package/dist/commonjs/store/keyValueStore.d.ts +17 -0
  42. package/dist/commonjs/store/keyValueStore.js +138 -0
  43. package/dist/commonjs/store/keyValueStore.js.map +1 -0
  44. package/dist/commonjs/store/keyValueStoreClient.d.ts +19 -0
  45. package/dist/commonjs/store/keyValueStoreClient.js +65 -0
  46. package/dist/commonjs/store/keyValueStoreClient.js.map +1 -0
  47. package/dist/commonjs/triggerClient.d.ts +300 -0
  48. package/dist/commonjs/triggerClient.js +1366 -0
  49. package/dist/commonjs/triggerClient.js.map +1 -0
  50. package/dist/commonjs/triggers/dynamic.d.ts +56 -0
  51. package/dist/commonjs/triggers/dynamic.js +97 -0
  52. package/dist/commonjs/triggers/dynamic.js.map +1 -0
  53. package/dist/commonjs/triggers/eventTrigger.d.ts +58 -0
  54. package/dist/commonjs/triggers/eventTrigger.js +69 -0
  55. package/dist/commonjs/triggers/eventTrigger.js.map +1 -0
  56. package/dist/commonjs/triggers/externalSource.d.ts +148 -0
  57. package/dist/commonjs/triggers/externalSource.js +106 -0
  58. package/dist/commonjs/triggers/externalSource.js.map +1 -0
  59. package/dist/commonjs/triggers/invokeTrigger.d.ts +39 -0
  60. package/dist/commonjs/triggers/invokeTrigger.js +58 -0
  61. package/dist/commonjs/triggers/invokeTrigger.js.map +1 -0
  62. package/dist/commonjs/triggers/notifications.d.ts +111 -0
  63. package/dist/commonjs/triggers/notifications.js +101 -0
  64. package/dist/commonjs/triggers/notifications.js.map +1 -0
  65. package/dist/commonjs/triggers/scheduled.d.ts +145 -0
  66. package/dist/commonjs/triggers/scheduled.js +208 -0
  67. package/dist/commonjs/triggers/scheduled.js.map +1 -0
  68. package/dist/commonjs/triggers/webhook.d.ts +143 -0
  69. package/dist/commonjs/triggers/webhook.js +133 -0
  70. package/dist/commonjs/triggers/webhook.js.map +1 -0
  71. package/dist/commonjs/typed-emitter.d.ts +37 -0
  72. package/dist/commonjs/typed-emitter.js +3 -0
  73. package/dist/commonjs/typed-emitter.js.map +1 -0
  74. package/dist/commonjs/types.d.ts +204 -0
  75. package/dist/commonjs/types.js +23 -0
  76. package/dist/commonjs/types.js.map +1 -0
  77. package/dist/commonjs/utils/formatSchemaErrors.d.ts +3 -0
  78. package/dist/commonjs/utils/formatSchemaErrors.js +10 -0
  79. package/dist/commonjs/utils/formatSchemaErrors.js.map +1 -0
  80. package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +6 -0
  81. package/dist/commonjs/utils/typedAsyncLocalStorage.js +18 -0
  82. package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +1 -0
  83. package/dist/commonjs/utils.d.ts +1 -0
  84. package/dist/commonjs/utils.js +11 -0
  85. package/dist/commonjs/utils.js.map +1 -0
  86. package/dist/commonjs/v3/cache.d.ts +28 -0
  87. package/dist/commonjs/v3/cache.js +63 -0
  88. package/dist/commonjs/v3/cache.js.map +1 -0
  89. package/dist/commonjs/v3/config.d.ts +4 -0
  90. package/dist/commonjs/v3/config.js +7 -0
  91. package/dist/commonjs/v3/config.js.map +1 -0
  92. package/dist/commonjs/v3/envvars.d.ts +14 -0
  93. package/dist/commonjs/v3/envvars.js +246 -0
  94. package/dist/commonjs/v3/envvars.js.map +1 -0
  95. package/dist/commonjs/v3/idempotencyKeys.d.ts +49 -0
  96. package/dist/commonjs/v3/idempotencyKeys.js +76 -0
  97. package/dist/commonjs/v3/idempotencyKeys.js.map +1 -0
  98. package/dist/commonjs/v3/index.d.ts +36 -0
  99. package/dist/commonjs/v3/index.js +79 -0
  100. package/dist/commonjs/v3/index.js.map +1 -0
  101. package/dist/commonjs/v3/retry.d.ts +15 -0
  102. package/dist/commonjs/v3/retry.js +411 -0
  103. package/dist/commonjs/v3/retry.js.map +1 -0
  104. package/dist/commonjs/v3/runs.d.ts +345 -0
  105. package/dist/commonjs/v3/runs.js +195 -0
  106. package/dist/commonjs/v3/runs.js.map +1 -0
  107. package/dist/commonjs/v3/schedules/api.d.ts +1 -0
  108. package/dist/commonjs/v3/schedules/api.js +3 -0
  109. package/dist/commonjs/v3/schedules/api.js.map +1 -0
  110. package/dist/commonjs/v3/schedules/index.d.ts +87 -0
  111. package/dist/commonjs/v3/schedules/index.js +250 -0
  112. package/dist/commonjs/v3/schedules/index.js.map +1 -0
  113. package/dist/commonjs/v3/shared.d.ts +443 -0
  114. package/dist/commonjs/v3/shared.js +547 -0
  115. package/dist/commonjs/v3/shared.js.map +1 -0
  116. package/dist/commonjs/v3/tags.d.ts +6 -0
  117. package/dist/commonjs/v3/tags.js +50 -0
  118. package/dist/commonjs/v3/tags.js.map +1 -0
  119. package/dist/commonjs/v3/tasks.d.ts +31 -0
  120. package/dist/commonjs/v3/tasks.js +35 -0
  121. package/dist/commonjs/v3/tasks.js.map +1 -0
  122. package/dist/commonjs/v3/tracer.d.ts +2 -0
  123. package/dist/commonjs/v3/tracer.js +7 -0
  124. package/dist/commonjs/v3/tracer.js.map +1 -0
  125. package/dist/commonjs/v3/usage.d.ts +77 -0
  126. package/dist/commonjs/v3/usage.js +115 -0
  127. package/dist/commonjs/v3/usage.js.map +1 -0
  128. package/dist/commonjs/v3/wait.d.ts +22 -0
  129. package/dist/commonjs/v3/wait.js +99 -0
  130. package/dist/commonjs/v3/wait.js.map +1 -0
  131. package/dist/commonjs/version.d.ts +1 -0
  132. package/dist/commonjs/version.js +5 -0
  133. package/dist/commonjs/version.js.map +1 -0
  134. package/dist/esm/apiClient.d.ts +737 -0
  135. package/dist/esm/apiClient.js +687 -0
  136. package/dist/esm/apiClient.js.map +1 -0
  137. package/dist/esm/concurrencyLimit.d.ts +10 -0
  138. package/dist/esm/concurrencyLimit.js +13 -0
  139. package/dist/esm/concurrencyLimit.js.map +1 -0
  140. package/dist/esm/errors.d.ts +66 -0
  141. package/dist/esm/errors.js +95 -0
  142. package/dist/esm/errors.js.map +1 -0
  143. package/dist/esm/httpEndpoint.d.ts +87 -0
  144. package/dist/esm/httpEndpoint.js +125 -0
  145. package/dist/esm/httpEndpoint.js.map +1 -0
  146. package/dist/esm/index.d.ts +23 -0
  147. package/dist/esm/index.js +35 -0
  148. package/dist/esm/index.js.map +1 -0
  149. package/dist/esm/integrations.d.ts +11 -0
  150. package/dist/esm/integrations.js +2 -0
  151. package/dist/esm/integrations.js.map +1 -0
  152. package/dist/esm/io.d.ts +453 -0
  153. package/dist/esm/io.js +1159 -0
  154. package/dist/esm/io.js.map +1 -0
  155. package/dist/esm/ioWithIntegrations.d.ts +4 -0
  156. package/dist/esm/ioWithIntegrations.js +29 -0
  157. package/dist/esm/ioWithIntegrations.js.map +1 -0
  158. package/dist/esm/job.d.ts +96 -0
  159. package/dist/esm/job.js +206 -0
  160. package/dist/esm/job.js.map +1 -0
  161. package/dist/esm/package.json +3 -0
  162. package/dist/esm/retry.d.ts +20 -0
  163. package/dist/esm/retry.js +19 -0
  164. package/dist/esm/retry.js.map +1 -0
  165. package/dist/esm/runLocalStorage.d.ts +8 -0
  166. package/dist/esm/runLocalStorage.js +3 -0
  167. package/dist/esm/runLocalStorage.js.map +1 -0
  168. package/dist/esm/security.d.ts +18 -0
  169. package/dist/esm/security.js +34 -0
  170. package/dist/esm/security.js.map +1 -0
  171. package/dist/esm/status.d.ts +19 -0
  172. package/dist/esm/status.js +34 -0
  173. package/dist/esm/status.js.map +1 -0
  174. package/dist/esm/store/keyValueStore.d.ts +17 -0
  175. package/dist/esm/store/keyValueStore.js +134 -0
  176. package/dist/esm/store/keyValueStore.js.map +1 -0
  177. package/dist/esm/store/keyValueStoreClient.d.ts +19 -0
  178. package/dist/esm/store/keyValueStoreClient.js +61 -0
  179. package/dist/esm/store/keyValueStoreClient.js.map +1 -0
  180. package/dist/esm/triggerClient.d.ts +300 -0
  181. package/dist/esm/triggerClient.js +1359 -0
  182. package/dist/esm/triggerClient.js.map +1 -0
  183. package/dist/esm/triggers/dynamic.d.ts +56 -0
  184. package/dist/esm/triggers/dynamic.js +93 -0
  185. package/dist/esm/triggers/dynamic.js.map +1 -0
  186. package/dist/esm/triggers/eventTrigger.d.ts +58 -0
  187. package/dist/esm/triggers/eventTrigger.js +64 -0
  188. package/dist/esm/triggers/eventTrigger.js.map +1 -0
  189. package/dist/esm/triggers/externalSource.d.ts +148 -0
  190. package/dist/esm/triggers/externalSource.js +100 -0
  191. package/dist/esm/triggers/externalSource.js.map +1 -0
  192. package/dist/esm/triggers/invokeTrigger.d.ts +39 -0
  193. package/dist/esm/triggers/invokeTrigger.js +53 -0
  194. package/dist/esm/triggers/invokeTrigger.js.map +1 -0
  195. package/dist/esm/triggers/notifications.d.ts +111 -0
  196. package/dist/esm/triggers/notifications.js +94 -0
  197. package/dist/esm/triggers/notifications.js.map +1 -0
  198. package/dist/esm/triggers/scheduled.d.ts +145 -0
  199. package/dist/esm/triggers/scheduled.js +197 -0
  200. package/dist/esm/triggers/scheduled.js.map +1 -0
  201. package/dist/esm/triggers/webhook.d.ts +143 -0
  202. package/dist/esm/triggers/webhook.js +128 -0
  203. package/dist/esm/triggers/webhook.js.map +1 -0
  204. package/dist/esm/typed-emitter.d.ts +37 -0
  205. package/dist/esm/typed-emitter.js +2 -0
  206. package/dist/esm/typed-emitter.js.map +1 -0
  207. package/dist/esm/types.d.ts +204 -0
  208. package/dist/esm/types.js +19 -0
  209. package/dist/esm/types.js.map +1 -0
  210. package/dist/esm/utils/formatSchemaErrors.d.ts +3 -0
  211. package/dist/esm/utils/formatSchemaErrors.js +7 -0
  212. package/dist/esm/utils/formatSchemaErrors.js.map +1 -0
  213. package/dist/esm/utils/typedAsyncLocalStorage.d.ts +6 -0
  214. package/dist/esm/utils/typedAsyncLocalStorage.js +14 -0
  215. package/dist/esm/utils/typedAsyncLocalStorage.js.map +1 -0
  216. package/dist/esm/utils.d.ts +1 -0
  217. package/dist/esm/utils.js +8 -0
  218. package/dist/esm/utils.js.map +1 -0
  219. package/dist/esm/v3/cache.d.ts +28 -0
  220. package/dist/esm/v3/cache.js +58 -0
  221. package/dist/esm/v3/cache.js.map +1 -0
  222. package/dist/esm/v3/config.d.ts +4 -0
  223. package/dist/esm/v3/config.js +4 -0
  224. package/dist/esm/v3/config.js.map +1 -0
  225. package/dist/esm/v3/envvars.d.ts +14 -0
  226. package/dist/esm/v3/envvars.js +238 -0
  227. package/dist/esm/v3/envvars.js.map +1 -0
  228. package/dist/esm/v3/idempotencyKeys.d.ts +49 -0
  229. package/dist/esm/v3/idempotencyKeys.js +72 -0
  230. package/dist/esm/v3/idempotencyKeys.js.map +1 -0
  231. package/dist/esm/v3/index.d.ts +36 -0
  232. package/dist/esm/v3/index.js +35 -0
  233. package/dist/esm/v3/index.js.map +1 -0
  234. package/dist/esm/v3/retry.d.ts +15 -0
  235. package/dist/esm/v3/retry.js +408 -0
  236. package/dist/esm/v3/retry.js.map +1 -0
  237. package/dist/esm/v3/runs.d.ts +345 -0
  238. package/dist/esm/v3/runs.js +192 -0
  239. package/dist/esm/v3/runs.js.map +1 -0
  240. package/dist/esm/v3/schedules/api.d.ts +1 -0
  241. package/dist/esm/v3/schedules/api.js +2 -0
  242. package/dist/esm/v3/schedules/api.js.map +1 -0
  243. package/dist/esm/v3/schedules/index.d.ts +87 -0
  244. package/dist/esm/v3/schedules/index.js +239 -0
  245. package/dist/esm/v3/schedules/index.js.map +1 -0
  246. package/dist/esm/v3/shared.d.ts +443 -0
  247. package/dist/esm/v3/shared.js +534 -0
  248. package/dist/esm/v3/shared.js.map +1 -0
  249. package/dist/esm/v3/tags.d.ts +6 -0
  250. package/dist/esm/v3/tags.js +47 -0
  251. package/dist/esm/v3/tags.js.map +1 -0
  252. package/dist/esm/v3/tasks.d.ts +31 -0
  253. package/dist/esm/v3/tasks.js +31 -0
  254. package/dist/esm/v3/tasks.js.map +1 -0
  255. package/dist/esm/v3/tracer.d.ts +2 -0
  256. package/dist/esm/v3/tracer.js +4 -0
  257. package/dist/esm/v3/tracer.js.map +1 -0
  258. package/dist/esm/v3/usage.d.ts +77 -0
  259. package/dist/esm/v3/usage.js +112 -0
  260. package/dist/esm/v3/usage.js.map +1 -0
  261. package/dist/esm/v3/wait.d.ts +22 -0
  262. package/dist/esm/v3/wait.js +96 -0
  263. package/dist/esm/v3/wait.js.map +1 -0
  264. package/dist/esm/version.d.ts +1 -0
  265. package/dist/esm/version.js +2 -0
  266. package/dist/esm/version.js.map +1 -0
  267. package/package.json +62 -47
  268. package/dist/index.d.mts +0 -2704
  269. package/dist/index.d.ts +0 -2704
  270. package/dist/index.js +0 -4886
  271. package/dist/index.js.map +0 -1
  272. package/dist/index.mjs +0 -4847
  273. package/dist/index.mjs.map +0 -1
  274. package/dist/v3/index.d.mts +0 -254
  275. package/dist/v3/index.d.ts +0 -254
  276. package/dist/v3/index.js +0 -892
  277. package/dist/v3/index.js.map +0 -1
  278. package/dist/v3/index.mjs +0 -883
  279. package/dist/v3/index.mjs.map +0 -1
@@ -1,254 +0,0 @@
1
- import { TaskRunContext, InitOutput, RetryOptions, QueueOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions } from '@trigger.dev/core/v3';
2
- export { HandleErrorArgs, HandleErrorFunction, LogLevel, RetryOptions, ProjectConfig as TriggerConfig, logger } from '@trigger.dev/core/v3';
3
- import { HttpHandler } from 'msw';
4
-
5
- type Context = TaskRunContext;
6
- type RequireOne<T, K extends keyof T> = {
7
- [X in Exclude<keyof T, K>]?: T[X];
8
- } & {
9
- [P in K]-?: T[P];
10
- };
11
- type Queue = RequireOne<QueueOptions, "name">;
12
- type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any> = {
13
- /** An id for your task. This must be unique inside your project and not change between versions. */
14
- id: string;
15
- /** The retry settings when an uncaught error is thrown.
16
- *
17
- * If omitted it will use the values in your `trigger.config.ts` file.
18
- *
19
- * @example
20
- *
21
- * ```
22
- * export const taskWithRetries = task({
23
- id: "task-with-retries",
24
- retry: {
25
- maxAttempts: 10,
26
- factor: 1.8,
27
- minTimeoutInMs: 500,
28
- maxTimeoutInMs: 30_000,
29
- randomize: false,
30
- },
31
- run: async ({ payload, ctx }) => {
32
- //...
33
- },
34
- });
35
- * ```
36
- * */
37
- retry?: RetryOptions;
38
- /** Used to configure what should happen when more than one run is triggered at the same time.
39
- *
40
- * @example
41
- * one at a time execution
42
- *
43
- * ```ts
44
- * export const oneAtATime = task({
45
- id: "one-at-a-time",
46
- queue: {
47
- concurrencyLimit: 1,
48
- },
49
- run: async ({ payload, ctx }) => {
50
- //...
51
- },
52
- });
53
- * ```
54
- */
55
- queue?: QueueOptions;
56
- /** Configure the spec of the machine you want your task to run on.
57
- *
58
- * @example
59
- *
60
- * ```ts
61
- * export const heavyTask = task({
62
- id: "heavy-task",
63
- machine: {
64
- cpu: 2,
65
- memory: 4,
66
- },
67
- run: async ({ payload, ctx }) => {
68
- //...
69
- },
70
- });
71
- * ```
72
- */
73
- machine?: {
74
- /** vCPUs. The default is 0.5.
75
- *
76
- * Possible values:
77
- * - 0.25
78
- * - 0.5
79
- * - 1
80
- * - 2
81
- * - 4
82
- */
83
- cpu?: MachineCpu;
84
- /** In GBs of RAM. The default is 1.
85
- *
86
- * Possible values:
87
- * - 0.25
88
- * - 0.5
89
- * - 1
90
- * - 2
91
- * - 4
92
- * - 8
93
- */
94
- memory?: MachineMemory;
95
- };
96
- /** This gets called when a task is triggered. It's where you put the code you want to execute.
97
- *
98
- * @param payload - The payload that is passed to your task when it's triggered. This must be JSON serializable.
99
- * @param params - Metadata about the run.
100
- */
101
- run: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<TOutput>;
102
- init?: (payload: TPayload, params: InitFnParams) => Promise<TInitOutput>;
103
- handleError?: (payload: TPayload, error: unknown, params: HandleErrorFnParams<TInitOutput>) => HandleErrorResult;
104
- cleanup?: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<void>;
105
- middleware?: (payload: TPayload, params: MiddlewareFnParams) => Promise<void>;
106
- onSuccess?: (payload: TPayload, params: SuccessFnParams<TOutput, TInitOutput>) => Promise<void>;
107
- };
108
- type InvokeHandle = {
109
- id: string;
110
- };
111
- type InvokeBatchHandle = {
112
- batchId: string;
113
- runs: string[];
114
- };
115
- type TaskRunResult<TOutput = any> = {
116
- ok: true;
117
- id: string;
118
- output: TOutput;
119
- } | {
120
- ok: false;
121
- id: string;
122
- error: any;
123
- };
124
- type BatchResult<TOutput = any> = {
125
- id: string;
126
- runs: TaskRunResult<TOutput>[];
127
- };
128
- type Task<TInput, TOutput = any> = {
129
- trigger: (params: {
130
- payload: TInput;
131
- options?: TaskRunOptions;
132
- }) => Promise<InvokeHandle>;
133
- batchTrigger: (params: {
134
- items: {
135
- payload: TInput;
136
- options?: TaskRunOptions;
137
- }[];
138
- batchOptions?: BatchRunOptions;
139
- }) => Promise<InvokeBatchHandle>;
140
- triggerAndWait: (params: {
141
- payload: TInput;
142
- options?: TaskRunOptions;
143
- }) => Promise<TOutput>;
144
- batchTriggerAndWait: (params: {
145
- items: {
146
- payload: TInput;
147
- options?: TaskRunOptions;
148
- }[];
149
- batchOptions?: BatchRunOptions;
150
- }) => Promise<BatchResult<TOutput>>;
151
- };
152
- type TaskRunOptions = {
153
- idempotencyKey?: string;
154
- maxAttempts?: number;
155
- startAt?: Date;
156
- startAfter?: number;
157
- queue?: TaskRunConcurrencyOptions;
158
- concurrencyKey?: string;
159
- };
160
- type TaskRunConcurrencyOptions = Queue;
161
- type BatchRunOptions = TaskRunOptions & {
162
- maxConcurrency?: number;
163
- };
164
-
165
- /** Creates a task that can be triggered
166
- * @param options - Task options
167
- * @example
168
- *
169
- * ```ts
170
- * import { task } from "@trigger.dev/sdk/v3";
171
- *
172
- * export const helloWorld = task({
173
- id: "hello-world",
174
- * run: async (payload: { url: string }) => {
175
- * return { hello: "world" };
176
- * },
177
- * });
178
- *
179
- * ```
180
- *
181
- * @returns A task that can be triggered
182
- */
183
- declare function task<TInput, TOutput = any, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
184
-
185
- type WaitOptions = {
186
- seconds: number;
187
- } | {
188
- minutes: number;
189
- } | {
190
- hours: number;
191
- } | {
192
- days: number;
193
- } | {
194
- weeks: number;
195
- } | {
196
- months: number;
197
- } | {
198
- years: number;
199
- };
200
- declare const wait: {
201
- for: (options: WaitOptions) => Promise<void>;
202
- until: (options: {
203
- date: Date;
204
- throwIfInThePast?: boolean;
205
- }) => Promise<void>;
206
- };
207
-
208
- type CacheMetadata = {
209
- createdTime: number;
210
- ttl?: number | null;
211
- };
212
- type CacheEntry<Value = unknown> = {
213
- metadata: CacheMetadata;
214
- value: Value;
215
- };
216
- type Eventually<Value> = Value | null | undefined | Promise<Value | null | undefined>;
217
- type CacheStore<Value = any> = {
218
- name?: string;
219
- get: (key: string) => Eventually<CacheEntry<Value>>;
220
- set: (key: string, value: CacheEntry<Value>) => unknown | Promise<unknown>;
221
- delete: (key: string) => unknown | Promise<unknown>;
222
- };
223
- type CacheFunction = <Value>(cacheKey: string, fn: () => Promise<Value> | Value) => Promise<Value> | Value;
224
- declare class InMemoryCache<Value = any> {
225
- private _cache;
226
- get(key: string): Eventually<CacheEntry<Value>>;
227
- set(key: string, value: CacheEntry<Value>): unknown;
228
- delete(key: string): unknown;
229
- }
230
- /**
231
- * Create a cache function that uses the provided store to cache values. Using InMemoryCache is safe because each task run is isolated.
232
- * @param store
233
- * @returns
234
- */
235
- declare function createCache(store: CacheStore): CacheFunction;
236
-
237
- declare function onThrow<T>(fn: (options: {
238
- attempt: number;
239
- maxAttempts: number;
240
- }) => Promise<T>, options: RetryOptions): Promise<T>;
241
- interface RetryFetchRequestInit extends RequestInit {
242
- retry?: FetchRetryOptions;
243
- timeoutInMs?: number;
244
- }
245
- declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
246
- declare const retry: {
247
- onThrow: typeof onThrow;
248
- fetch: typeof retryFetch;
249
- interceptFetch: (...handlers: Array<HttpHandler>) => {
250
- run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
251
- };
252
- };
253
-
254
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type WaitOptions, createCache, retry, task, wait };
@@ -1,254 +0,0 @@
1
- import { TaskRunContext, InitOutput, RetryOptions, QueueOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions } from '@trigger.dev/core/v3';
2
- export { HandleErrorArgs, HandleErrorFunction, LogLevel, RetryOptions, ProjectConfig as TriggerConfig, logger } from '@trigger.dev/core/v3';
3
- import { HttpHandler } from 'msw';
4
-
5
- type Context = TaskRunContext;
6
- type RequireOne<T, K extends keyof T> = {
7
- [X in Exclude<keyof T, K>]?: T[X];
8
- } & {
9
- [P in K]-?: T[P];
10
- };
11
- type Queue = RequireOne<QueueOptions, "name">;
12
- type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any> = {
13
- /** An id for your task. This must be unique inside your project and not change between versions. */
14
- id: string;
15
- /** The retry settings when an uncaught error is thrown.
16
- *
17
- * If omitted it will use the values in your `trigger.config.ts` file.
18
- *
19
- * @example
20
- *
21
- * ```
22
- * export const taskWithRetries = task({
23
- id: "task-with-retries",
24
- retry: {
25
- maxAttempts: 10,
26
- factor: 1.8,
27
- minTimeoutInMs: 500,
28
- maxTimeoutInMs: 30_000,
29
- randomize: false,
30
- },
31
- run: async ({ payload, ctx }) => {
32
- //...
33
- },
34
- });
35
- * ```
36
- * */
37
- retry?: RetryOptions;
38
- /** Used to configure what should happen when more than one run is triggered at the same time.
39
- *
40
- * @example
41
- * one at a time execution
42
- *
43
- * ```ts
44
- * export const oneAtATime = task({
45
- id: "one-at-a-time",
46
- queue: {
47
- concurrencyLimit: 1,
48
- },
49
- run: async ({ payload, ctx }) => {
50
- //...
51
- },
52
- });
53
- * ```
54
- */
55
- queue?: QueueOptions;
56
- /** Configure the spec of the machine you want your task to run on.
57
- *
58
- * @example
59
- *
60
- * ```ts
61
- * export const heavyTask = task({
62
- id: "heavy-task",
63
- machine: {
64
- cpu: 2,
65
- memory: 4,
66
- },
67
- run: async ({ payload, ctx }) => {
68
- //...
69
- },
70
- });
71
- * ```
72
- */
73
- machine?: {
74
- /** vCPUs. The default is 0.5.
75
- *
76
- * Possible values:
77
- * - 0.25
78
- * - 0.5
79
- * - 1
80
- * - 2
81
- * - 4
82
- */
83
- cpu?: MachineCpu;
84
- /** In GBs of RAM. The default is 1.
85
- *
86
- * Possible values:
87
- * - 0.25
88
- * - 0.5
89
- * - 1
90
- * - 2
91
- * - 4
92
- * - 8
93
- */
94
- memory?: MachineMemory;
95
- };
96
- /** This gets called when a task is triggered. It's where you put the code you want to execute.
97
- *
98
- * @param payload - The payload that is passed to your task when it's triggered. This must be JSON serializable.
99
- * @param params - Metadata about the run.
100
- */
101
- run: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<TOutput>;
102
- init?: (payload: TPayload, params: InitFnParams) => Promise<TInitOutput>;
103
- handleError?: (payload: TPayload, error: unknown, params: HandleErrorFnParams<TInitOutput>) => HandleErrorResult;
104
- cleanup?: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<void>;
105
- middleware?: (payload: TPayload, params: MiddlewareFnParams) => Promise<void>;
106
- onSuccess?: (payload: TPayload, params: SuccessFnParams<TOutput, TInitOutput>) => Promise<void>;
107
- };
108
- type InvokeHandle = {
109
- id: string;
110
- };
111
- type InvokeBatchHandle = {
112
- batchId: string;
113
- runs: string[];
114
- };
115
- type TaskRunResult<TOutput = any> = {
116
- ok: true;
117
- id: string;
118
- output: TOutput;
119
- } | {
120
- ok: false;
121
- id: string;
122
- error: any;
123
- };
124
- type BatchResult<TOutput = any> = {
125
- id: string;
126
- runs: TaskRunResult<TOutput>[];
127
- };
128
- type Task<TInput, TOutput = any> = {
129
- trigger: (params: {
130
- payload: TInput;
131
- options?: TaskRunOptions;
132
- }) => Promise<InvokeHandle>;
133
- batchTrigger: (params: {
134
- items: {
135
- payload: TInput;
136
- options?: TaskRunOptions;
137
- }[];
138
- batchOptions?: BatchRunOptions;
139
- }) => Promise<InvokeBatchHandle>;
140
- triggerAndWait: (params: {
141
- payload: TInput;
142
- options?: TaskRunOptions;
143
- }) => Promise<TOutput>;
144
- batchTriggerAndWait: (params: {
145
- items: {
146
- payload: TInput;
147
- options?: TaskRunOptions;
148
- }[];
149
- batchOptions?: BatchRunOptions;
150
- }) => Promise<BatchResult<TOutput>>;
151
- };
152
- type TaskRunOptions = {
153
- idempotencyKey?: string;
154
- maxAttempts?: number;
155
- startAt?: Date;
156
- startAfter?: number;
157
- queue?: TaskRunConcurrencyOptions;
158
- concurrencyKey?: string;
159
- };
160
- type TaskRunConcurrencyOptions = Queue;
161
- type BatchRunOptions = TaskRunOptions & {
162
- maxConcurrency?: number;
163
- };
164
-
165
- /** Creates a task that can be triggered
166
- * @param options - Task options
167
- * @example
168
- *
169
- * ```ts
170
- * import { task } from "@trigger.dev/sdk/v3";
171
- *
172
- * export const helloWorld = task({
173
- id: "hello-world",
174
- * run: async (payload: { url: string }) => {
175
- * return { hello: "world" };
176
- * },
177
- * });
178
- *
179
- * ```
180
- *
181
- * @returns A task that can be triggered
182
- */
183
- declare function task<TInput, TOutput = any, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
184
-
185
- type WaitOptions = {
186
- seconds: number;
187
- } | {
188
- minutes: number;
189
- } | {
190
- hours: number;
191
- } | {
192
- days: number;
193
- } | {
194
- weeks: number;
195
- } | {
196
- months: number;
197
- } | {
198
- years: number;
199
- };
200
- declare const wait: {
201
- for: (options: WaitOptions) => Promise<void>;
202
- until: (options: {
203
- date: Date;
204
- throwIfInThePast?: boolean;
205
- }) => Promise<void>;
206
- };
207
-
208
- type CacheMetadata = {
209
- createdTime: number;
210
- ttl?: number | null;
211
- };
212
- type CacheEntry<Value = unknown> = {
213
- metadata: CacheMetadata;
214
- value: Value;
215
- };
216
- type Eventually<Value> = Value | null | undefined | Promise<Value | null | undefined>;
217
- type CacheStore<Value = any> = {
218
- name?: string;
219
- get: (key: string) => Eventually<CacheEntry<Value>>;
220
- set: (key: string, value: CacheEntry<Value>) => unknown | Promise<unknown>;
221
- delete: (key: string) => unknown | Promise<unknown>;
222
- };
223
- type CacheFunction = <Value>(cacheKey: string, fn: () => Promise<Value> | Value) => Promise<Value> | Value;
224
- declare class InMemoryCache<Value = any> {
225
- private _cache;
226
- get(key: string): Eventually<CacheEntry<Value>>;
227
- set(key: string, value: CacheEntry<Value>): unknown;
228
- delete(key: string): unknown;
229
- }
230
- /**
231
- * Create a cache function that uses the provided store to cache values. Using InMemoryCache is safe because each task run is isolated.
232
- * @param store
233
- * @returns
234
- */
235
- declare function createCache(store: CacheStore): CacheFunction;
236
-
237
- declare function onThrow<T>(fn: (options: {
238
- attempt: number;
239
- maxAttempts: number;
240
- }) => Promise<T>, options: RetryOptions): Promise<T>;
241
- interface RetryFetchRequestInit extends RequestInit {
242
- retry?: FetchRetryOptions;
243
- timeoutInMs?: number;
244
- }
245
- declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
246
- declare const retry: {
247
- onThrow: typeof onThrow;
248
- fetch: typeof retryFetch;
249
- interceptFetch: (...handlers: Array<HttpHandler>) => {
250
- run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
251
- };
252
- };
253
-
254
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type WaitOptions, createCache, retry, task, wait };