@workflow/core 4.0.1-beta.4 → 4.0.1-beta.40
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/LICENSE.md +201 -21
- package/dist/builtins.js +1 -1
- package/dist/class-serialization.d.ts +26 -0
- package/dist/class-serialization.d.ts.map +1 -0
- package/dist/class-serialization.js +66 -0
- package/dist/create-hook.js +1 -1
- package/dist/define-hook.d.ts +40 -25
- package/dist/define-hook.d.ts.map +1 -1
- package/dist/define-hook.js +22 -27
- package/dist/events-consumer.js +1 -1
- package/dist/flushable-stream.d.ts +82 -0
- package/dist/flushable-stream.d.ts.map +1 -0
- package/dist/flushable-stream.js +214 -0
- package/dist/global.d.ts +12 -2
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +32 -8
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/logger.js +1 -1
- package/dist/observability.d.ts +60 -0
- package/dist/observability.d.ts.map +1 -1
- package/dist/observability.js +175 -19
- package/dist/parse-name.d.ts +12 -0
- package/dist/parse-name.d.ts.map +1 -1
- package/dist/parse-name.js +28 -3
- package/dist/private.d.ts +10 -1
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +6 -1
- package/dist/runtime/helpers.d.ts +64 -0
- package/dist/runtime/helpers.d.ts.map +1 -0
- package/dist/runtime/helpers.js +243 -0
- package/dist/runtime/resume-hook.d.ts +16 -11
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +76 -64
- package/dist/runtime/start.d.ts +10 -0
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +56 -45
- package/dist/runtime/step-handler.d.ts +7 -0
- package/dist/runtime/step-handler.d.ts.map +1 -0
- package/dist/runtime/step-handler.js +353 -0
- package/dist/runtime/suspension-handler.d.ts +20 -0
- package/dist/runtime/suspension-handler.d.ts.map +1 -0
- package/dist/runtime/suspension-handler.js +179 -0
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +22 -21
- package/dist/runtime.d.ts +3 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +76 -334
- package/dist/schemas.d.ts +1 -15
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +2 -15
- package/dist/serialization.d.ts +74 -10
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +295 -56
- package/dist/sleep.d.ts +33 -0
- package/dist/sleep.d.ts.map +1 -0
- package/dist/sleep.js +10 -0
- package/dist/source-map.d.ts +10 -0
- package/dist/source-map.d.ts.map +1 -0
- package/dist/source-map.js +56 -0
- package/dist/step/context-storage.d.ts +2 -0
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +1 -1
- package/dist/step/get-closure-vars.d.ts +9 -0
- package/dist/step/get-closure-vars.d.ts.map +1 -0
- package/dist/step/get-closure-vars.js +16 -0
- package/dist/step/get-step-metadata.js +1 -1
- package/dist/step/get-workflow-metadata.js +1 -1
- package/dist/step/writable-stream.d.ts +14 -0
- package/dist/step/writable-stream.d.ts.map +1 -0
- package/dist/step/writable-stream.js +30 -0
- package/dist/step.d.ts +1 -1
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +51 -11
- package/dist/symbols.d.ts +7 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +8 -1
- package/dist/telemetry/semantic-conventions.d.ts +66 -38
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +16 -3
- package/dist/telemetry.d.ts +8 -4
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +39 -6
- package/dist/types.d.ts +0 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -26
- package/dist/util.d.ts +9 -27
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +37 -44
- package/dist/vm/index.js +2 -2
- package/dist/vm/uuid.js +1 -1
- package/dist/workflow/create-hook.js +1 -1
- package/dist/workflow/define-hook.d.ts +3 -3
- package/dist/workflow/define-hook.d.ts.map +1 -1
- package/dist/workflow/define-hook.js +1 -1
- package/dist/workflow/get-workflow-metadata.js +1 -1
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +6 -9
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +2 -1
- package/dist/workflow/sleep.d.ts +4 -0
- package/dist/workflow/sleep.d.ts.map +1 -0
- package/dist/workflow/sleep.js +54 -0
- package/dist/workflow/writable-stream.js +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +60 -9
- package/dist/writable-stream.d.ts +5 -4
- package/dist/writable-stream.d.ts.map +1 -1
- package/dist/writable-stream.js +7 -6
- package/package.json +23 -18
- package/dist/builtins.js.map +0 -1
- package/dist/create-hook.js.map +0 -1
- package/dist/define-hook.js.map +0 -1
- package/dist/events-consumer.js.map +0 -1
- package/dist/global.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/observability.js.map +0 -1
- package/dist/parse-name.js.map +0 -1
- package/dist/private.js.map +0 -1
- package/dist/runtime/resume-hook.js.map +0 -1
- package/dist/runtime/start.js.map +0 -1
- package/dist/runtime/world.js.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/schemas.js.map +0 -1
- package/dist/serialization.js.map +0 -1
- package/dist/step/context-storage.js.map +0 -1
- package/dist/step/get-step-metadata.js.map +0 -1
- package/dist/step/get-workflow-metadata.js.map +0 -1
- package/dist/step.js.map +0 -1
- package/dist/symbols.js.map +0 -1
- package/dist/telemetry/semantic-conventions.js.map +0 -1
- package/dist/telemetry.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/util.js.map +0 -1
- package/dist/vm/index.js.map +0 -1
- package/dist/vm/uuid.js.map +0 -1
- package/dist/workflow/create-hook.js.map +0 -1
- package/dist/workflow/define-hook.js.map +0 -1
- package/dist/workflow/get-workflow-metadata.js.map +0 -1
- package/dist/workflow/hook.js.map +0 -1
- package/dist/workflow/index.js.map +0 -1
- package/dist/workflow/writable-stream.js.map +0 -1
- package/dist/workflow.js.map +0 -1
- package/dist/writable-stream.js.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
<http://www.apache.org/licenses/>
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Vercel Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/builtins.js
CHANGED
|
@@ -10,4 +10,4 @@ export async function __builtin_response_text(res) {
|
|
|
10
10
|
'use step';
|
|
11
11
|
return res.text();
|
|
12
12
|
}
|
|
13
|
-
//# sourceMappingURL=
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbHRpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYnVpbHRpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxDQUFDLEtBQUssVUFBVSwrQkFBK0IsQ0FBQyxHQUFhO0lBQ2pFLFVBQVUsQ0FBQztJQUNYLE9BQU8sR0FBRyxDQUFDLFdBQVcsRUFBRSxDQUFDO0FBQzNCLENBQUM7QUFFRCxNQUFNLENBQUMsS0FBSyxVQUFVLHVCQUF1QixDQUFDLEdBQWE7SUFDekQsVUFBVSxDQUFDO0lBQ1gsT0FBTyxHQUFHLENBQUMsSUFBSSxFQUFFLENBQUM7QUFDcEIsQ0FBQztBQUVELE1BQU0sQ0FBQyxLQUFLLFVBQVUsdUJBQXVCLENBQUMsR0FBYTtJQUN6RCxVQUFVLENBQUM7SUFDWCxPQUFPLEdBQUcsQ0FBQyxJQUFJLEVBQUUsQ0FBQztBQUNwQixDQUFDIn0=
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class serialization utilities.
|
|
3
|
+
*
|
|
4
|
+
* This module is separate from private.ts to avoid pulling in Node.js-only
|
|
5
|
+
* dependencies (like async_hooks via get-closure-vars.ts) when used in
|
|
6
|
+
* workflow bundles.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Register a class constructor for serialization.
|
|
10
|
+
* This allows class constructors to be deserialized by looking up the classId.
|
|
11
|
+
* Called by the SWC plugin in both step mode and workflow mode.
|
|
12
|
+
*
|
|
13
|
+
* Also sets the `classId` property on the class so the serializer can find it
|
|
14
|
+
* when serializing instances (e.g., step return values).
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerSerializationClass(classId: string, cls: Function): void;
|
|
17
|
+
/**
|
|
18
|
+
* Find a registered class constructor by ID (used during deserialization)
|
|
19
|
+
*
|
|
20
|
+
* @param classId - The class ID to look up
|
|
21
|
+
* @param global - The global object to check first. Defaults to globalThis.
|
|
22
|
+
* If the class is not found and `global` differs from `globalThis`,
|
|
23
|
+
* it will also check `globalThis` as a fallback.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getSerializationClass(classId: string, global?: Record<string, any>): Function | undefined;
|
|
26
|
+
//# sourceMappingURL=class-serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-serialization.d.ts","sourceRoot":"","sources":["../src/class-serialization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH;;;;;;;GAOG;AAEH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,QASxE;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAc,GAEvC,QAAQ,GAAG,SAAS,CAatB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class serialization utilities.
|
|
3
|
+
*
|
|
4
|
+
* This module is separate from private.ts to avoid pulling in Node.js-only
|
|
5
|
+
* dependencies (like async_hooks via get-closure-vars.ts) when used in
|
|
6
|
+
* workflow bundles.
|
|
7
|
+
*/
|
|
8
|
+
import { WORKFLOW_CLASS_REGISTRY } from './symbols.js';
|
|
9
|
+
/**
|
|
10
|
+
* Get or create the class registry on the given global object.
|
|
11
|
+
* This works isomorphically in both step mode (main context) and workflow mode (VM context).
|
|
12
|
+
*
|
|
13
|
+
* @param global - The global object to use. Defaults to globalThis, but can be a VM's global.
|
|
14
|
+
*/
|
|
15
|
+
function getRegistry(global = globalThis) {
|
|
16
|
+
const g = global;
|
|
17
|
+
let registry = g[WORKFLOW_CLASS_REGISTRY];
|
|
18
|
+
if (!registry) {
|
|
19
|
+
registry = new Map();
|
|
20
|
+
g[WORKFLOW_CLASS_REGISTRY] = registry;
|
|
21
|
+
}
|
|
22
|
+
return registry;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register a class constructor for serialization.
|
|
26
|
+
* This allows class constructors to be deserialized by looking up the classId.
|
|
27
|
+
* Called by the SWC plugin in both step mode and workflow mode.
|
|
28
|
+
*
|
|
29
|
+
* Also sets the `classId` property on the class so the serializer can find it
|
|
30
|
+
* when serializing instances (e.g., step return values).
|
|
31
|
+
*/
|
|
32
|
+
// biome-ignore lint/complexity/noBannedTypes: We need to use Function to represent class constructors
|
|
33
|
+
export function registerSerializationClass(classId, cls) {
|
|
34
|
+
getRegistry().set(classId, cls);
|
|
35
|
+
// Set classId on the class for serialization
|
|
36
|
+
Object.defineProperty(cls, 'classId', {
|
|
37
|
+
value: classId,
|
|
38
|
+
writable: false,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
configurable: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Find a registered class constructor by ID (used during deserialization)
|
|
45
|
+
*
|
|
46
|
+
* @param classId - The class ID to look up
|
|
47
|
+
* @param global - The global object to check first. Defaults to globalThis.
|
|
48
|
+
* If the class is not found and `global` differs from `globalThis`,
|
|
49
|
+
* it will also check `globalThis` as a fallback.
|
|
50
|
+
*/
|
|
51
|
+
export function getSerializationClass(classId, global = globalThis
|
|
52
|
+
// biome-ignore lint/complexity/noBannedTypes: We need to use Function to represent class constructors
|
|
53
|
+
) {
|
|
54
|
+
// Check the provided global first
|
|
55
|
+
const cls = getRegistry(global).get(classId);
|
|
56
|
+
if (cls)
|
|
57
|
+
return cls;
|
|
58
|
+
// Fallback: check globalThis if it differs from the provided global
|
|
59
|
+
// This handles the case where classes are registered in the host context
|
|
60
|
+
// but deserialization happens in a VM context
|
|
61
|
+
if (global !== globalThis) {
|
|
62
|
+
return getRegistry(globalThis).get(classId);
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Mtc2VyaWFsaXphdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jbGFzcy1zZXJpYWxpemF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBRSx1QkFBdUIsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUt2RDs7Ozs7R0FLRztBQUNILFNBQVMsV0FBVy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0lBQzlDLElBQUksTUFBTSxLQUFLLFVBQVUsRUFBRSxDQUFDO1FBQzFCLE9BQU8sV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBRUQsT0FBTyxTQUFTLENBQUM7QUFDbkIsQ0FBQyJ9
|
package/dist/create-hook.js
CHANGED
|
@@ -29,4 +29,4 @@ export function createWebhook(
|
|
|
29
29
|
options) {
|
|
30
30
|
throw new Error('`createWebhook()` can only be called inside a workflow function');
|
|
31
31
|
}
|
|
32
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLWhvb2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY3JlYXRlLWhvb2sudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBK0ZBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FxQkc7QUFDSCxvREFBb0Q7QUFDcEQsTUFBTSxVQUFVLFVBQVUsQ0FBVSxPQUFxQjtJQUN2RCxNQUFNLElBQUksS0FBSyxDQUNiLDhEQUE4RCxDQUMvRCxDQUFDO0FBQ0osQ0FBQztBQWFELE1BQU0sVUFBVSxhQUFhO0FBQzNCLG9EQUFvRDtBQUNwRCxPQUF3QjtJQUV4QixNQUFNLElBQUksS0FBSyxDQUNiLGlFQUFpRSxDQUNsRSxDQUFDO0FBQ0osQ0FBQyJ9
|
package/dist/define-hook.d.ts
CHANGED
|
@@ -1,12 +1,44 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1
2
|
import type { Hook as HookEntity } from '@workflow/world';
|
|
2
3
|
import type { Hook, HookOptions } from './create-hook.js';
|
|
4
|
+
/**
|
|
5
|
+
* A typed hook interface for type-safe hook creation and resumption.
|
|
6
|
+
*/
|
|
7
|
+
export interface TypedHook<TInput, TOutput> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new hook with the defined output type.
|
|
10
|
+
*
|
|
11
|
+
* Note: This method is not available in runtime bundles. Use it from workflow contexts only.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Optional hook configuration
|
|
14
|
+
* @returns A Hook that resolves to the defined output type
|
|
15
|
+
*/
|
|
16
|
+
create(options?: HookOptions): Hook<TOutput>;
|
|
17
|
+
/**
|
|
18
|
+
* Resumes a hook by sending a payload with the defined input type.
|
|
19
|
+
* This is a type-safe wrapper around the `resumeHook` runtime function.
|
|
20
|
+
*
|
|
21
|
+
* @param token - The unique token identifying the hook
|
|
22
|
+
* @param payload - The payload to send; if a `schema` is configured it is validated/transformed before resuming
|
|
23
|
+
* @returns Promise resolving to the hook entity
|
|
24
|
+
* @throws Error if the hook is not found or if there's an error during the process
|
|
25
|
+
*/
|
|
26
|
+
resume(token: string, payload: TInput): Promise<HookEntity>;
|
|
27
|
+
}
|
|
28
|
+
export declare namespace TypedHook {
|
|
29
|
+
/**
|
|
30
|
+
* Extracts the input type from a {@link TypedHook}
|
|
31
|
+
*/
|
|
32
|
+
type Input<T extends TypedHook<any, any>> = T extends TypedHook<infer I, any> ? I : never;
|
|
33
|
+
}
|
|
3
34
|
/**
|
|
4
35
|
* Defines a typed hook for type-safe hook creation and resumption.
|
|
5
36
|
*
|
|
6
|
-
* This helper provides type safety by allowing you to define the
|
|
7
|
-
*
|
|
37
|
+
* This helper provides type safety by allowing you to define the input and output types
|
|
38
|
+
* for the hook's payload, with optional validation and transformation via a schema.
|
|
8
39
|
*
|
|
9
|
-
* @
|
|
40
|
+
* @param schema - Schema used to validate and transform the input payload before resuming
|
|
41
|
+
* @returns An object with `create` and `resume` functions pre-typed with the input and output types
|
|
10
42
|
*
|
|
11
43
|
* @example
|
|
12
44
|
*
|
|
@@ -19,35 +51,18 @@ import type { Hook, HookOptions } from './create-hook.js';
|
|
|
19
51
|
* "use workflow";
|
|
20
52
|
*
|
|
21
53
|
* const hook = approvalHook.create();
|
|
22
|
-
* const result = await hook; // Fully typed as { approved: boolean; comment: string }
|
|
54
|
+
* const result = await hook; // Fully typed as { approved: boolean; comment: string; }
|
|
23
55
|
* }
|
|
24
56
|
*
|
|
25
57
|
* // In an API route
|
|
26
58
|
* export async function POST(request: Request) {
|
|
27
59
|
* const { token, approved, comment } = await request.json();
|
|
28
|
-
* await approvalHook.resume(token, { approved, comment });
|
|
60
|
+
* await approvalHook.resume(token, { approved, comment }); // Input type
|
|
29
61
|
* return Response.json({ success: true });
|
|
30
62
|
* }
|
|
31
63
|
* ```
|
|
32
64
|
*/
|
|
33
|
-
export declare function defineHook<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* Note: This method is not available in runtime bundles. Use it from workflow contexts only.
|
|
38
|
-
*
|
|
39
|
-
* @param _options - Optional hook configuration
|
|
40
|
-
* @returns A Hook that resolves to the defined payload type
|
|
41
|
-
*/
|
|
42
|
-
create(options?: HookOptions): Hook<T>;
|
|
43
|
-
/**
|
|
44
|
-
* Resumes a hook by sending a payload with the defined type.
|
|
45
|
-
* This is a type-safe wrapper around the `resumeHook` runtime function.
|
|
46
|
-
*
|
|
47
|
-
* @param token - The unique token identifying the hook
|
|
48
|
-
* @param payload - The payload to send (must match the defined type)
|
|
49
|
-
* @returns Promise resolving to the hook entity, or null if the hook doesn't exist
|
|
50
|
-
*/
|
|
51
|
-
resume(token: string, payload: T): Promise<HookEntity | null>;
|
|
52
|
-
};
|
|
65
|
+
export declare function defineHook<TInput, TOutput = TInput>({ schema, }?: {
|
|
66
|
+
schema?: StandardSchemaV1<TInput, TOutput>;
|
|
67
|
+
}): TypedHook<TInput, TOutput>;
|
|
53
68
|
//# sourceMappingURL=define-hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-hook.d.ts","sourceRoot":"","sources":["../src/define-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG1D
|
|
1
|
+
{"version":3,"file":"define-hook.d.ts","sourceRoot":"","sources":["../src/define-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG1D;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,MAAM,EAAE,OAAO;IACxC;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7D;AAED,yBAAiB,SAAS,CAAC;IACzB;;OAEG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,SAAS,CACpE,MAAM,CAAC,EACP,GAAG,CACJ,GACG,CAAC,GACD,KAAK,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,EACnD,MAAM,GACP,GAAE;IACD,MAAM,CAAC,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,GAAG,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBlC"}
|
package/dist/define-hook.js
CHANGED
|
@@ -2,10 +2,11 @@ import { resumeHook } from './runtime/resume-hook.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Defines a typed hook for type-safe hook creation and resumption.
|
|
4
4
|
*
|
|
5
|
-
* This helper provides type safety by allowing you to define the
|
|
6
|
-
*
|
|
5
|
+
* This helper provides type safety by allowing you to define the input and output types
|
|
6
|
+
* for the hook's payload, with optional validation and transformation via a schema.
|
|
7
7
|
*
|
|
8
|
-
* @
|
|
8
|
+
* @param schema - Schema used to validate and transform the input payload before resuming
|
|
9
|
+
* @returns An object with `create` and `resume` functions pre-typed with the input and output types
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
*
|
|
@@ -18,42 +19,36 @@ import { resumeHook } from './runtime/resume-hook.js';
|
|
|
18
19
|
* "use workflow";
|
|
19
20
|
*
|
|
20
21
|
* const hook = approvalHook.create();
|
|
21
|
-
* const result = await hook; // Fully typed as { approved: boolean; comment: string }
|
|
22
|
+
* const result = await hook; // Fully typed as { approved: boolean; comment: string; }
|
|
22
23
|
* }
|
|
23
24
|
*
|
|
24
25
|
* // In an API route
|
|
25
26
|
* export async function POST(request: Request) {
|
|
26
27
|
* const { token, approved, comment } = await request.json();
|
|
27
|
-
* await approvalHook.resume(token, { approved, comment });
|
|
28
|
+
* await approvalHook.resume(token, { approved, comment }); // Input type
|
|
28
29
|
* return Response.json({ success: true });
|
|
29
30
|
* }
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export function defineHook() {
|
|
33
|
+
export function defineHook({ schema, } = {}) {
|
|
33
34
|
return {
|
|
34
|
-
|
|
35
|
-
* Creates a new hook with the defined payload type.
|
|
36
|
-
*
|
|
37
|
-
* Note: This method is not available in runtime bundles. Use it from workflow contexts only.
|
|
38
|
-
*
|
|
39
|
-
* @param _options - Optional hook configuration
|
|
40
|
-
* @returns A Hook that resolves to the defined payload type
|
|
41
|
-
*/
|
|
42
|
-
// @ts-expect-error `options` is here for types/docs
|
|
43
|
-
create(options) {
|
|
35
|
+
create(_options) {
|
|
44
36
|
throw new Error('`defineHook().create()` can only be called inside a workflow function.');
|
|
45
37
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
async resume(token, payload) {
|
|
39
|
+
if (!schema?.['~standard']) {
|
|
40
|
+
return await resumeHook(token, payload);
|
|
41
|
+
}
|
|
42
|
+
let result = schema['~standard'].validate(payload);
|
|
43
|
+
if (result instanceof Promise) {
|
|
44
|
+
result = await result;
|
|
45
|
+
}
|
|
46
|
+
// if the `issues` field exists, the validation failed
|
|
47
|
+
if (result.issues) {
|
|
48
|
+
throw new Error(JSON.stringify(result.issues, null, 2));
|
|
49
|
+
}
|
|
50
|
+
return await resumeHook(token, result.value);
|
|
56
51
|
},
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
|
-
//# sourceMappingURL=
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmaW5lLWhvb2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVmaW5lLWhvb2sudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBdUN0RDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBOEJHO0FBQ0gsTUFBTSxVQUFVLFVBQVUsQ0FBMkIsRUFDbkQsTUFBTSxNQUdKLEVBQUU7SUFDSixPQUFPO1FBQ0wsTUFBTSxDQUFDLFFBQXNCO1lBQzNCLE1BQU0sSUFBSSxLQUFLLENBQ2Isd0VBQXdFLENBQ3pFLENBQUM7UUFDSixDQUFDO1FBQ0QsS0FBSyxDQUFDLE1BQU0sQ0FBQyxLQUFhLEVBQUUsT0FBZTtZQUN6QyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUMsV0FBVyxDQUFDLEVBQUUsQ0FBQztnQkFDM0IsT0FBTyxNQUFNLFVBQVUsQ0FBQyxLQUFLLEVBQUUsT0FBTyxDQUFDLENBQUM7WUFDMUMsQ0FBQztZQUVELElBQUksTUFBTSxHQUFHLE1BQU0sQ0FBQyxXQUFXLENBQUMsQ0FBQyxRQUFRLENBQUMsT0FBTyxDQUFDLENBQUM7WUFDbkQsSUFBSSxNQUFNLFlBQVksT0FBTyxFQUFFLENBQUM7Z0JBQzlCLE1BQU0sR0FBRyxNQUFNLE1BQU0sQ0FBQztZQUN4QixDQUFDO1lBRUQsc0RBQXNEO1lBQ3RELElBQUksTUFBTSxDQUFDLE1BQU0sRUFBRSxDQUFDO2dCQUNsQixNQUFNLElBQUksS0FBSyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLE1BQU0sRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUMxRCxDQUFDO1lBRUQsT0FBTyxNQUFNLFVBQVUsQ0FBVSxLQUFLLEVBQUUsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ3hELENBQUM7S0FDRixDQUFDO0FBQ0osQ0FBQyJ9
|
package/dist/events-consumer.js
CHANGED
|
@@ -69,4 +69,4 @@ export class EventsConsumer {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
//# sourceMappingURL=
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRzLWNvbnN1bWVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2V2ZW50cy1jb25zdW1lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRTNDLE1BQU0sQ0FBTixJQUFZLG1CQWFYO0FBYkQsV0FBWSxtQkFBbUI7SUFDN0I7O09BRUc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DQUFDLENBQUM7Q0FDSCJ9
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type PromiseWithResolvers } from '@workflow/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Polling interval (in ms) for lock release detection.
|
|
4
|
+
*
|
|
5
|
+
* The Web Streams API does not expose an event for "lock released but stream
|
|
6
|
+
* still open"; we can only distinguish that state by periodically attempting
|
|
7
|
+
* to acquire a reader/writer. For that reason we use polling instead of a
|
|
8
|
+
* fully event-driven approach here.
|
|
9
|
+
*
|
|
10
|
+
* 100ms is a compromise between:
|
|
11
|
+
* - Latency: how quickly we notice that the user has released their lock, and
|
|
12
|
+
* - Cost/CPU usage: how often timers fire, especially with many concurrent
|
|
13
|
+
* streams or in serverless environments where billed time matters.
|
|
14
|
+
*
|
|
15
|
+
* This value should only be changed with care, as decreasing it will
|
|
16
|
+
* increase polling frequency (and thus potential cost), while increasing it
|
|
17
|
+
* will add worst-case delay before the `done` promise resolves after a lock
|
|
18
|
+
* is released.
|
|
19
|
+
*/
|
|
20
|
+
export declare const LOCK_POLL_INTERVAL_MS = 100;
|
|
21
|
+
/**
|
|
22
|
+
* State tracker for flushable stream operations.
|
|
23
|
+
* Resolves when either:
|
|
24
|
+
* 1. Stream completes (close/error), OR
|
|
25
|
+
* 2. Lock is released AND all pending operations are flushed
|
|
26
|
+
*
|
|
27
|
+
* Note: `doneResolved` and `streamEnded` are separate:
|
|
28
|
+
* - `doneResolved`: The `done` promise has been resolved (step can complete)
|
|
29
|
+
* - `streamEnded`: The underlying stream has actually closed/errored
|
|
30
|
+
*
|
|
31
|
+
* Once `doneResolved` is set to true, the `done` promise will not resolve
|
|
32
|
+
* again. Re-acquiring locks after release is not supported as a way to
|
|
33
|
+
* trigger additional completion signaling.
|
|
34
|
+
*/
|
|
35
|
+
export interface FlushableStreamState extends PromiseWithResolvers<void> {
|
|
36
|
+
/** Number of write operations currently in flight to the server */
|
|
37
|
+
pendingOps: number;
|
|
38
|
+
/** Whether the `done` promise has been resolved */
|
|
39
|
+
doneResolved: boolean;
|
|
40
|
+
/** Whether the underlying stream has actually closed/errored */
|
|
41
|
+
streamEnded: boolean;
|
|
42
|
+
/** Interval ID for writable lock polling (if active) */
|
|
43
|
+
writablePollingInterval?: ReturnType<typeof setInterval>;
|
|
44
|
+
/** Interval ID for readable lock polling (if active) */
|
|
45
|
+
readablePollingInterval?: ReturnType<typeof setInterval>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createFlushableState(): FlushableStreamState;
|
|
48
|
+
/**
|
|
49
|
+
* Polls a WritableStream to check if the user has released their lock.
|
|
50
|
+
* Resolves the done promise when lock is released and no pending ops remain.
|
|
51
|
+
*
|
|
52
|
+
* Note: Only resolves if stream is unlocked but NOT closed. If the user closes
|
|
53
|
+
* the stream, the pump will handle resolution via the stream ending naturally.
|
|
54
|
+
*
|
|
55
|
+
* Protection: If polling is already active on this state, the existing interval
|
|
56
|
+
* is used to avoid creating multiple simultaneous polling operations.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pollWritableLock(writable: WritableStream, state: FlushableStreamState): void;
|
|
59
|
+
/**
|
|
60
|
+
* Polls a ReadableStream to check if the user has released their lock.
|
|
61
|
+
* Resolves the done promise when lock is released and no pending ops remain.
|
|
62
|
+
*
|
|
63
|
+
* Note: Only resolves if stream is unlocked but NOT closed. If the user closes
|
|
64
|
+
* the stream, the pump will handle resolution via the stream ending naturally.
|
|
65
|
+
*
|
|
66
|
+
* Protection: If polling is already active on this state, the existing interval
|
|
67
|
+
* is used to avoid creating multiple simultaneous polling operations.
|
|
68
|
+
*/
|
|
69
|
+
export declare function pollReadableLock(readable: ReadableStream, state: FlushableStreamState): void;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a flushable pipe from a ReadableStream to a WritableStream.
|
|
72
|
+
* Unlike pipeTo(), this resolves when:
|
|
73
|
+
* 1. The source stream completes (close/error), OR
|
|
74
|
+
* 2. The user releases their lock on userStream AND all pending writes are flushed
|
|
75
|
+
*
|
|
76
|
+
* @param source - The readable stream to read from (e.g., transform's readable)
|
|
77
|
+
* @param sink - The writable stream to write to (e.g., server writable)
|
|
78
|
+
* @param state - The flushable state tracker
|
|
79
|
+
* @returns Promise that resolves when stream ends (not when done promise resolves)
|
|
80
|
+
*/
|
|
81
|
+
export declare function flushablePipe(source: ReadableStream, sink: WritableStream, state: FlushableStreamState): Promise<void>;
|
|
82
|
+
//# sourceMappingURL=flushable-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushable-stream.d.ts","sourceRoot":"","sources":["../src/flushable-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,iBAAiB,CAAC;AAE3E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB,CAAC,IAAI,CAAC;IACtE,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAAC;IACtB,gEAAgE;IAChE,WAAW,EAAE,OAAO,CAAC;IACrB,wDAAwD;IACxD,uBAAuB,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;IACzD,wDAAwD;IACxD,uBAAuB,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CAC1D;AAED,wBAAgB,oBAAoB,IAAI,oBAAoB,CAO3D;AA2DD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,oBAAoB,GAC1B,IAAI,CAwBN;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,oBAAoB,GAC1B,IAAI,CAwBN;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAwDf"}
|