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
package/src/flow/refs.js CHANGED
@@ -33,10 +33,18 @@ export const settled_statuses = new Set(
33
33
  * @returns {string}
34
34
  */
35
35
  export function describe(ref) {
36
- if (typeof ref == "string") return `"${ref}"`
37
- if (typeof ref == "function") return `function "${ref.name || "anonymous"}"`
38
- if (/** @type {RefProbe} */(ref)/**/?.[INPUT]) return `input "${/** @type {InputRef} */(ref)/**/.name}"`
39
- if (is_stream(ref)) return "a stream"
36
+ if (typeof ref == "string") {
37
+ return `"${ref}"`
38
+ }
39
+ if (typeof ref == "function") {
40
+ return `function "${ref.name || "anonymous"}"`
41
+ }
42
+ if (/** @type {RefProbe} */(ref)/**/?.[INPUT]) {
43
+ return `input "${/** @type {InputRef} */(ref)/**/.name}"`
44
+ }
45
+ if (is_stream(ref)) {
46
+ return "a stream"
47
+ }
40
48
  return /** @type {RefProbe} */(ref)/**/?.[DEFINITION] ? "a flow" : String(ref)
41
49
  }
42
50
  /**
@@ -75,9 +83,15 @@ export function is_ref(value) {
75
83
  * @returns {boolean}
76
84
  */
77
85
  export function is_retry(value) {
78
- if (typeof value == "number") return Number.isInteger(value) && value >= 0
79
- if (!value || typeof value != "object" || !Number.isInteger(value.count) || value.count < 0) return false
80
- if (value.when != null && typeof value.when != "function") return false
86
+ if (typeof value == "number") {
87
+ return Number.isInteger(value) && value >= 0
88
+ }
89
+ if (!value || typeof value != "object" || !Number.isInteger(value.count) || value.count < 0) {
90
+ return false
91
+ }
92
+ if (value.when != null && typeof value.when != "function") {
93
+ return false
94
+ }
81
95
  return value.delay == null || typeof value.delay == "function" || typeof value.delay == "number" && value.delay >= 0
82
96
  }
83
97
  /**
@@ -98,9 +112,7 @@ export function is_stream(value) {
98
112
  && !/** @type {RefProbe} */(value)/**/?.[INPUT]
99
113
  && typeof /** @type {Partial<AsyncIterable<unknown>>} */(value)/**/[Symbol.asyncIterator] == "function"
100
114
  }
101
- /**
102
- * @returns {typeof SKIP}
103
- */
115
+ /** @returns {typeof SKIP} */
104
116
  export function skip() {
105
117
  return SKIP
106
118
  }
@@ -121,9 +133,11 @@ export function to_array(value) {
121
133
  * @returns {NodeRef}
122
134
  */
123
135
  export function to_arriving(dependency, policy) {
124
- if (!is_ref(to_ref(dependency))) throw TypeError(
125
- `flow.${policy}() needs a function, an input, a flow or a stream`
126
- )
136
+ if (!is_ref(to_ref(dependency))) {
137
+ throw TypeError(
138
+ `flow.${policy}() needs a function, an input, a flow or a stream`
139
+ )
140
+ }
127
141
  return /** @type {NodeRef} */(/** @type {unknown} */({
128
142
  [ARRIVE]: to_ref(dependency),
129
143
  policy
@@ -9,7 +9,9 @@ import { clear_record, get_record } from "./nodes.js"
9
9
  */
10
10
  export function discard(record, value) {
11
11
  const dispose = record.node.options.release
12
- if (!dispose || record.node.each) return
12
+ if (!dispose || record.node.each) {
13
+ return
14
+ }
13
15
  void Promise.resolve()
14
16
  .then(
15
17
  () => dispose(
@@ -28,7 +30,9 @@ export function discard(record, value) {
28
30
  */
29
31
  export function release_all(c, error) {
30
32
  for (const record of c.records.values()) {
31
- if (!record.node.options.release || record.status != "done" || record.released) continue
33
+ if (!record.node.options.release || record.status != "done" || record.released) {
34
+ continue
35
+ }
32
36
  release_quietly(record, error)
33
37
  record.released = { error }
34
38
  }
@@ -54,7 +58,9 @@ export function release_unused(c, name, error) {
54
58
  const record = get_record(c, name)
55
59
  if (!record.node.options.release || record.status != "done" || record.released || record.node.dependents.some(
56
60
  dependent => get_record(c, dependent).status != "skipped"
57
- )) return
61
+ )) {
62
+ return
63
+ }
58
64
  record.released = { error: void 0 }
59
65
  release_quietly(
60
66
  record,