async-lube 2.0.0 → 2.1.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 (70) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +1 -1
  3. package/docs/http.md +1 -1
  4. package/docs/reference.md +4 -2
  5. package/docs/tasks.md +19 -2
  6. package/package.json +4 -5
  7. package/public.d.ts +112 -0
  8. package/src/attempt.js +17 -7
  9. package/src/durable/context.js +107 -64
  10. package/src/durable/error.js +39 -15
  11. package/src/durable/index.js +18 -10
  12. package/src/durable/journal.js +29 -14
  13. package/src/durable/json.js +26 -9
  14. package/src/durable/lease.js +15 -5
  15. package/src/durable/persist.js +60 -22
  16. package/src/durable/run.js +103 -41
  17. package/src/durable/send.js +30 -13
  18. package/src/durable/serve.js +30 -24
  19. package/src/durable/state.js +28 -13
  20. package/src/durable/store.js +19 -10
  21. package/src/durable/watch.js +31 -11
  22. package/src/errors.js +9 -3
  23. package/src/flow/attempts.js +49 -29
  24. package/src/flow/builder.js +260 -161
  25. package/src/flow/compile.js +86 -66
  26. package/src/flow/graph.js +108 -42
  27. package/src/flow/index.js +13 -7
  28. package/src/flow/items.js +79 -46
  29. package/src/flow/nodes.js +267 -117
  30. package/src/flow/refs.js +27 -13
  31. package/src/flow/resources.js +9 -3
  32. package/src/flow/run.js +287 -114
  33. package/src/flow/streams.js +44 -19
  34. package/src/flow/subflows.js +93 -53
  35. package/src/http/config.js +11 -5
  36. package/src/http/index.js +25 -14
  37. package/src/http/refresh.js +29 -12
  38. package/src/http/request.js +246 -151
  39. package/src/http/response.js +105 -50
  40. package/src/http/retry.js +52 -27
  41. package/src/http/socket.js +220 -172
  42. package/src/http/sse.js +113 -74
  43. package/src/http/throttle.js +9 -4
  44. package/src/http/url.js +58 -35
  45. package/src/http/xhr.js +29 -24
  46. package/src/index.js +1 -0
  47. package/src/key.js +3 -5
  48. package/src/limiter.js +146 -65
  49. package/src/offload.js +116 -85
  50. package/src/offload_module.js +594 -0
  51. package/src/options.js +8 -4
  52. package/src/redial.js +129 -0
  53. package/src/signal.js +14 -4
  54. package/src/stream.js +353 -198
  55. package/types/attempt.d.ts.map +1 -1
  56. package/types/durable/index.d.ts.map +1 -1
  57. package/types/durable/state.d.ts.map +1 -1
  58. package/types/durable/store.d.ts.map +1 -1
  59. package/types/errors.d.ts.map +1 -1
  60. package/types/http/index.d.ts.map +1 -1
  61. package/types/index.d.ts +1 -0
  62. package/types/index.d.ts.map +1 -1
  63. package/types/limiter.d.ts +5 -1
  64. package/types/limiter.d.ts.map +1 -1
  65. package/types/offload.d.ts +2 -16
  66. package/types/offload.d.ts.map +1 -1
  67. package/types/redial.d.ts +28 -0
  68. package/types/redial.d.ts.map +1 -0
  69. package/types/stream.d.ts +2 -0
  70. package/types/stream.d.ts.map +1 -1
@@ -43,7 +43,9 @@ export function make_context(
43
43
  goto,
44
44
  index: index ?? c.item_index,
45
45
  get key() {
46
- if (!run_state) return ""
46
+ if (!run_state) {
47
+ return ""
48
+ }
47
49
  return `${c.run_id}:${record.node.name}${index == null ? "" : "#" + index}:${run_state.serial}`
48
50
  },
49
51
  name: record.node.name,
@@ -52,7 +54,9 @@ export function make_context(
52
54
  skip,
53
55
  /** @param {number} ms */
54
56
  sleep: ms => {
55
- if (!run_state) return sleep_until(Date.now() + ms, signal)
57
+ if (!run_state) {
58
+ return sleep_until(Date.now() + ms, signal)
59
+ }
56
60
  const deadline = run_state.waits[run_state.wait++] ??= Date.now() + ms
57
61
  return sleep_until(deadline, signal)
58
62
  },
@@ -79,7 +83,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
79
83
  } catch {
80
84
  return { kind: "stale" }
81
85
  }
82
- if (token != record.token) return { kind: "stale" }
86
+ if (token != record.token) {
87
+ return { kind: "stale" }
88
+ }
83
89
  run_state.delay = void 0
84
90
  }
85
91
  const index = unit ? Number(unit) : c.item_index
@@ -95,7 +101,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
95
101
  * @returns {void}
96
102
  */
97
103
  function end(type, error, again) {
98
- if (!c.trace) return
104
+ if (!c.trace) {
105
+ return
106
+ }
99
107
  const time = Date.now()
100
108
  const base = {
101
109
  attempt,
@@ -109,16 +117,18 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
109
117
  type == "fail" ? { ...base, error, retry: !!again, type } : { ...base, type }
110
118
  )
111
119
  }
112
- if (c.trace) emit(
113
- c,
114
- {
115
- attempt,
116
- index,
117
- node: record.node.name,
118
- time: started,
119
- type: "start"
120
- }
121
- )
120
+ if (c.trace) {
121
+ emit(
122
+ c,
123
+ {
124
+ attempt,
125
+ index,
126
+ node: record.node.name,
127
+ time: started,
128
+ type: "start"
129
+ }
130
+ )
131
+ }
122
132
  const controller = timeout ? new AbortController() : void 0
123
133
  const signal = controller ? controller.signal : parent
124
134
  const unlink = controller ? link_signal(controller, parent) : noop
@@ -133,7 +143,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
133
143
  const pending = Promise.resolve()
134
144
  .then(
135
145
  () => {
136
- if (signal.aborted) throw signal.reason
146
+ if (signal.aborted) {
147
+ throw signal.reason
148
+ }
137
149
  return run_once(signal, run_state, first)
138
150
  }
139
151
  )
@@ -203,7 +215,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
203
215
  } finally {
204
216
  record.delaying--
205
217
  }
206
- if (token != record.token) return { kind: "stale" }
218
+ if (token != record.token) {
219
+ return { kind: "stale" }
220
+ }
207
221
  run_state.delay = void 0
208
222
  }
209
223
  } finally {
@@ -229,7 +243,7 @@ export function run_single(c, record, token) {
229
243
  /** @type {AbortController} */(record.controller)/**/.signal,
230
244
  "",
231
245
  (signal, run_state, first) => {
232
- const values = args_of(c, record)
246
+ const values = args_of(record)
233
247
  const gate = record.gate
234
248
  if (gate) {
235
249
  if (gate !== true) {
@@ -242,17 +256,19 @@ export function run_single(c, record, token) {
242
256
  }
243
257
  record.gate = void 0
244
258
  }
245
- if (!node.sub) return /** @type {Task} */(node.run)/**/(
246
- ...values,
247
- make_context(
248
- c,
249
- record,
250
- signal,
251
- run_state.attempt,
252
- void 0,
253
- run_state
259
+ if (!node.sub) {
260
+ return /** @type {Task} */(node.run)/**/(
261
+ ...values,
262
+ make_context(
263
+ c,
264
+ record,
265
+ signal,
266
+ run_state.attempt,
267
+ void 0,
268
+ run_state
269
+ )
254
270
  )
255
- )
271
+ }
256
272
  const sub_state = values.length > 1
257
273
  ? values
258
274
  : values.length
@@ -277,9 +293,13 @@ export function run_single(c, record, token) {
277
293
  */
278
294
  function take_run(record, unit) {
279
295
  const current = record.runs.get(unit)
280
- if (current) return current
296
+ if (current) {
297
+ return current
298
+ }
281
299
  const saved = record.resume_runs?.[unit]
282
- if (saved && record.resume_runs) delete record.resume_runs[unit]
300
+ if (saved && record.resume_runs) {
301
+ delete record.resume_runs[unit]
302
+ }
283
303
  /** @type {RunState} */
284
304
  const run_state = {
285
305
  attempt: saved?.attempt ?? 1,