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.
- package/CHANGELOG.md +34 -0
- package/README.md +1 -1
- package/docs/http.md +1 -1
- package/docs/reference.md +4 -2
- package/docs/tasks.md +19 -2
- package/package.json +4 -5
- package/public.d.ts +112 -0
- package/src/attempt.js +17 -7
- package/src/durable/context.js +107 -64
- package/src/durable/error.js +39 -15
- package/src/durable/index.js +18 -10
- package/src/durable/journal.js +29 -14
- package/src/durable/json.js +26 -9
- package/src/durable/lease.js +15 -5
- package/src/durable/persist.js +60 -22
- package/src/durable/run.js +103 -41
- package/src/durable/send.js +30 -13
- package/src/durable/serve.js +30 -24
- package/src/durable/state.js +28 -13
- package/src/durable/store.js +19 -10
- package/src/durable/watch.js +31 -11
- package/src/errors.js +9 -3
- package/src/flow/attempts.js +49 -29
- package/src/flow/builder.js +260 -161
- package/src/flow/compile.js +86 -66
- package/src/flow/graph.js +108 -42
- package/src/flow/index.js +13 -7
- package/src/flow/items.js +79 -46
- package/src/flow/nodes.js +267 -117
- package/src/flow/refs.js +27 -13
- package/src/flow/resources.js +9 -3
- package/src/flow/run.js +287 -114
- package/src/flow/streams.js +44 -19
- package/src/flow/subflows.js +93 -53
- package/src/http/config.js +11 -5
- package/src/http/index.js +25 -14
- package/src/http/refresh.js +29 -12
- package/src/http/request.js +246 -151
- package/src/http/response.js +105 -50
- package/src/http/retry.js +52 -27
- package/src/http/socket.js +220 -172
- package/src/http/sse.js +113 -74
- package/src/http/throttle.js +9 -4
- package/src/http/url.js +58 -35
- package/src/http/xhr.js +29 -24
- package/src/index.js +1 -0
- package/src/key.js +3 -5
- package/src/limiter.js +146 -65
- package/src/offload.js +116 -85
- package/src/offload_module.js +594 -0
- package/src/options.js +8 -4
- package/src/redial.js +129 -0
- package/src/signal.js +14 -4
- package/src/stream.js +353 -198
- package/types/attempt.d.ts.map +1 -1
- package/types/durable/index.d.ts.map +1 -1
- package/types/durable/state.d.ts.map +1 -1
- package/types/durable/store.d.ts.map +1 -1
- package/types/errors.d.ts.map +1 -1
- package/types/http/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/limiter.d.ts +5 -1
- package/types/limiter.d.ts.map +1 -1
- package/types/offload.d.ts +2 -16
- package/types/offload.d.ts.map +1 -1
- package/types/redial.d.ts +28 -0
- package/types/redial.d.ts.map +1 -0
- package/types/stream.d.ts +2 -0
- 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")
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
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")
|
|
79
|
-
|
|
80
|
-
|
|
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)))
|
|
125
|
-
|
|
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
|
package/src/flow/resources.js
CHANGED
|
@@ -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)
|
|
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)
|
|
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
|
-
))
|
|
61
|
+
)) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
58
64
|
record.released = { error: void 0 }
|
|
59
65
|
release_quietly(
|
|
60
66
|
record,
|