@event-driven-platform/reader 0.0.3
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 +201 -0
- package/README.md +102 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cache/cached-read-executor.d.ts +20 -0
- package/dist/lib/cache/cached-read-executor.d.ts.map +1 -0
- package/dist/lib/cache/cached-read-executor.js +69 -0
- package/dist/lib/cache/cached-read-executor.js.map +1 -0
- package/dist/lib/cache/read-cache-traversal.d.ts +10 -0
- package/dist/lib/cache/read-cache-traversal.d.ts.map +1 -0
- package/dist/lib/cache/read-cache-traversal.js +30 -0
- package/dist/lib/cache/read-cache-traversal.js.map +1 -0
- package/dist/lib/control/default-read-timeout.d.ts +5 -0
- package/dist/lib/control/default-read-timeout.d.ts.map +1 -0
- package/dist/lib/control/default-read-timeout.js +30 -0
- package/dist/lib/control/default-read-timeout.js.map +1 -0
- package/dist/lib/control/read-execution-control.d.ts +12 -0
- package/dist/lib/control/read-execution-control.d.ts.map +1 -0
- package/dist/lib/control/read-execution-control.js +43 -0
- package/dist/lib/control/read-execution-control.js.map +1 -0
- package/dist/lib/control/read-timeout.d.ts +10 -0
- package/dist/lib/control/read-timeout.d.ts.map +1 -0
- package/dist/lib/control/read-timeout.js +2 -0
- package/dist/lib/control/read-timeout.js.map +1 -0
- package/dist/lib/errors/read-cancelled.error.d.ts +4 -0
- package/dist/lib/errors/read-cancelled.error.d.ts.map +1 -0
- package/dist/lib/errors/read-cancelled.error.js +7 -0
- package/dist/lib/errors/read-cancelled.error.js.map +1 -0
- package/dist/lib/errors/read-execution-coordination-not-configured.error.d.ts +4 -0
- package/dist/lib/errors/read-execution-coordination-not-configured.error.d.ts.map +1 -0
- package/dist/lib/errors/read-execution-coordination-not-configured.error.js +7 -0
- package/dist/lib/errors/read-execution-coordination-not-configured.error.js.map +1 -0
- package/dist/lib/errors/read-execution-coordinator-unavailable.error.d.ts +4 -0
- package/dist/lib/errors/read-execution-coordinator-unavailable.error.d.ts.map +1 -0
- package/dist/lib/errors/read-execution-coordinator-unavailable.error.js +7 -0
- package/dist/lib/errors/read-execution-coordinator-unavailable.error.js.map +1 -0
- package/dist/lib/errors/read-execution-ownership-lost.error.d.ts +4 -0
- package/dist/lib/errors/read-execution-ownership-lost.error.d.ts.map +1 -0
- package/dist/lib/errors/read-execution-ownership-lost.error.js +7 -0
- package/dist/lib/errors/read-execution-ownership-lost.error.js.map +1 -0
- package/dist/lib/errors/read-handler-ambiguous.error.d.ts +5 -0
- package/dist/lib/errors/read-handler-ambiguous.error.d.ts.map +1 -0
- package/dist/lib/errors/read-handler-ambiguous.error.js +9 -0
- package/dist/lib/errors/read-handler-ambiguous.error.js.map +1 -0
- package/dist/lib/errors/read-handler-not-found.error.d.ts +4 -0
- package/dist/lib/errors/read-handler-not-found.error.d.ts.map +1 -0
- package/dist/lib/errors/read-handler-not-found.error.js +7 -0
- package/dist/lib/errors/read-handler-not-found.error.js.map +1 -0
- package/dist/lib/errors/read-timed-out.error.d.ts +5 -0
- package/dist/lib/errors/read-timed-out.error.d.ts.map +1 -0
- package/dist/lib/errors/read-timed-out.error.js +9 -0
- package/dist/lib/errors/read-timed-out.error.js.map +1 -0
- package/dist/lib/inflight/distributed-read-flight.d.ts +26 -0
- package/dist/lib/inflight/distributed-read-flight.d.ts.map +1 -0
- package/dist/lib/inflight/distributed-read-flight.js +122 -0
- package/dist/lib/inflight/distributed-read-flight.js.map +1 -0
- package/dist/lib/inflight/local-read-in-flight.d.ts +7 -0
- package/dist/lib/inflight/local-read-in-flight.d.ts.map +1 -0
- package/dist/lib/inflight/local-read-in-flight.js +21 -0
- package/dist/lib/inflight/local-read-in-flight.js.map +1 -0
- package/dist/lib/reader/default-reader-dependencies.d.ts +10 -0
- package/dist/lib/reader/default-reader-dependencies.d.ts.map +1 -0
- package/dist/lib/reader/default-reader-dependencies.js +2 -0
- package/dist/lib/reader/default-reader-dependencies.js.map +1 -0
- package/dist/lib/reader/default-reader.d.ts +13 -0
- package/dist/lib/reader/default-reader.d.ts.map +1 -0
- package/dist/lib/reader/default-reader.js +27 -0
- package/dist/lib/reader/default-reader.js.map +1 -0
- package/dist/lib/reader/reader.d.ts +6 -0
- package/dist/lib/reader/reader.d.ts.map +1 -0
- package/dist/lib/reader/reader.js +2 -0
- package/dist/lib/reader/reader.js.map +1 -0
- package/dist/lib/source/read-source-executor.d.ts +9 -0
- package/dist/lib/source/read-source-executor.d.ts.map +1 -0
- package/dist/lib/source/read-source-executor.js +24 -0
- package/dist/lib/source/read-source-executor.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 [yyyy] [name of copyright owner]
|
|
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/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @event-driven-platform/reader
|
|
2
|
+
|
|
3
|
+
Central execution engine for the stable `Read -> Query -> Reader` pipeline.
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
|
|
7
|
+
Reader interprets Query execution configuration while keeping Read and ReadHandler infrastructure-agnostic.
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
Query -> Reader
|
|
11
|
+
|
|
|
12
|
+
+-> cache traversal / population
|
|
13
|
+
+-> local in-flight coalescing
|
|
14
|
+
+-> optional distributed coordination
|
|
15
|
+
+-> ReadHandlerResolver -> ReadHandler
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Basic usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { DefaultReader } from '@event-driven-platform/reader';
|
|
22
|
+
|
|
23
|
+
const reader = new DefaultReader({
|
|
24
|
+
readHandlerResolver,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const result = await reader.execute({
|
|
28
|
+
read: {
|
|
29
|
+
name: 'user.get',
|
|
30
|
+
actor,
|
|
31
|
+
parameters: { userId: 'user-42' },
|
|
32
|
+
},
|
|
33
|
+
context: {
|
|
34
|
+
correlationId: 'request-123',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`DefaultReader` requires a `ReadHandlerResolver`. `readTimeout`, `readExecutionCoordinator`, and `readExecutionOwnerIdFactory` are optional composition dependencies.
|
|
40
|
+
|
|
41
|
+
## Cached composition
|
|
42
|
+
|
|
43
|
+
Cache topology belongs to Query. For example, a process-local L1 followed by shared L2:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const result = await reader.execute({
|
|
47
|
+
read,
|
|
48
|
+
context: { correlationId },
|
|
49
|
+
options: {
|
|
50
|
+
timeoutMs: 2_000,
|
|
51
|
+
cache: {
|
|
52
|
+
key: {
|
|
53
|
+
namespace: 'user.get',
|
|
54
|
+
version: '1',
|
|
55
|
+
partition: 'tenant:tenant-1',
|
|
56
|
+
value: 'user:user-42',
|
|
57
|
+
},
|
|
58
|
+
levels: [
|
|
59
|
+
{ scope: 'local', reader: l1, writer: l1 },
|
|
60
|
+
{ scope: 'shared', reader: l2Reader, writer: l2Writer },
|
|
61
|
+
],
|
|
62
|
+
coordination: {
|
|
63
|
+
leaseDurationMs: 1_000,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
When `coordination` is present, `DefaultReader` must also receive a `ReadExecutionCoordinator`, and the plan must contain shared cache. The coordinator transports ownership only; successful distributed rendezvous happens through shared cache.
|
|
71
|
+
|
|
72
|
+
## Execution semantics
|
|
73
|
+
|
|
74
|
+
Reader traverses cache levels in declared order and stops on the first hit. Lower-level hits are promoted only into preceding writable levels. Full misses execute the resolved source handler and backfill writable levels in reverse order.
|
|
75
|
+
|
|
76
|
+
Cache IO is fail-open for result correctness: unavailable reads continue traversal and failed cache writes cannot replace a successful result. Distributed coordination is fail-closed because bypassing a configured coordinator could create uncontrolled duplicate source work.
|
|
77
|
+
|
|
78
|
+
Cached Queries use deterministic `ReadCacheKey` identity for process-local single-flight. Distributed plans extend that coalescing across instances with ownership-safe leases and shared-cache rendezvous.
|
|
79
|
+
|
|
80
|
+
## Handler resolution
|
|
81
|
+
|
|
82
|
+
`DefaultReader` resolves the Read through `ReadHandlerResolver`. `not-found` and `ambiguous` outcomes become typed Reader errors. The current source contract executes the first handler in a resolved deterministic handler set; `ReadHandler` has no fallback `miss` outcome.
|
|
83
|
+
|
|
84
|
+
## Timeout and cancellation
|
|
85
|
+
|
|
86
|
+
`QueryOptions.timeoutMs` bounds one caller's complete Reader wait. `QueryOptions.signal` lets that caller stop waiting. A timed-out or cancelled follower does not cancel healthy shared work serving other callers.
|
|
87
|
+
|
|
88
|
+
## Public API
|
|
89
|
+
|
|
90
|
+
The package exports `Reader`, `DefaultReader`, `DefaultReaderDependencies`, `ReadTimeout`, and typed errors for handler resolution, timeout/cancellation, missing/unavailable coordination, and ownership loss.
|
|
91
|
+
|
|
92
|
+
Internal services implementing source execution, cache traversal, local in-flight behavior, distributed-flight orchestration, and the default timeout are deliberately not exported. Consumers should import only from the package root.
|
|
93
|
+
|
|
94
|
+
## Verification
|
|
95
|
+
|
|
96
|
+
Infrastructure-backed load/recovery verification and the invariant-to-test map are documented in [`VERIFICATION.md`](VERIFICATION.md).
|
|
97
|
+
|
|
98
|
+
## Related documentation
|
|
99
|
+
|
|
100
|
+
- [`docs/architecture/README.md`](../../docs/architecture/README.md)
|
|
101
|
+
- [`docs/read-public-api.md`](../../docs/read-public-api.md)
|
|
102
|
+
- [`docs/read-release-readiness.md`](../../docs/read-release-readiness.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { ReadTimeout } from './lib/control/read-timeout.js';
|
|
2
|
+
export { ReadCancelledError } from './lib/errors/read-cancelled.error.js';
|
|
3
|
+
export { ReadExecutionCoordinationNotConfiguredError } from './lib/errors/read-execution-coordination-not-configured.error.js';
|
|
4
|
+
export { ReadExecutionCoordinatorUnavailableError } from './lib/errors/read-execution-coordinator-unavailable.error.js';
|
|
5
|
+
export { ReadExecutionOwnershipLostError } from './lib/errors/read-execution-ownership-lost.error.js';
|
|
6
|
+
export { ReadHandlerAmbiguousError } from './lib/errors/read-handler-ambiguous.error.js';
|
|
7
|
+
export { ReadHandlerNotFoundError } from './lib/errors/read-handler-not-found.error.js';
|
|
8
|
+
export { ReadTimedOutError } from './lib/errors/read-timed-out.error.js';
|
|
9
|
+
export { DefaultReader } from './lib/reader/default-reader.js';
|
|
10
|
+
export type { DefaultReaderDependencies } from './lib/reader/default-reader.js';
|
|
11
|
+
export type { Reader } from './lib/reader/reader.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,2CAA2C,EAAE,MAAM,kEAAkE,CAAC;AAC/H,OAAO,EAAE,wCAAwC,EAAE,MAAM,8DAA8D,CAAC;AACxH,OAAO,EAAE,+BAA+B,EAAE,MAAM,qDAAqD,CAAC;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,YAAY,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ReadCancelledError } from './lib/errors/read-cancelled.error.js';
|
|
2
|
+
export { ReadExecutionCoordinationNotConfiguredError } from './lib/errors/read-execution-coordination-not-configured.error.js';
|
|
3
|
+
export { ReadExecutionCoordinatorUnavailableError } from './lib/errors/read-execution-coordinator-unavailable.error.js';
|
|
4
|
+
export { ReadExecutionOwnershipLostError } from './lib/errors/read-execution-ownership-lost.error.js';
|
|
5
|
+
export { ReadHandlerAmbiguousError } from './lib/errors/read-handler-ambiguous.error.js';
|
|
6
|
+
export { ReadHandlerNotFoundError } from './lib/errors/read-handler-not-found.error.js';
|
|
7
|
+
export { ReadTimedOutError } from './lib/errors/read-timed-out.error.js';
|
|
8
|
+
export { DefaultReader } from './lib/reader/default-reader.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,2CAA2C,EAAE,MAAM,kEAAkE,CAAC;AAC/H,OAAO,EAAE,wCAAwC,EAAE,MAAM,8DAA8D,CAAC;AACxH,OAAO,EAAE,+BAA+B,EAAE,MAAM,qDAAqD,CAAC;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReadExecutionCoordinator } from '@event-driven-platform/read-execution-coordinator';
|
|
2
|
+
import type { Query, QueryCachePlan } from '@event-driven-platform/query';
|
|
3
|
+
import type { AnyRead, ReadResultOf } from '@event-driven-platform/read';
|
|
4
|
+
import type { ReadSourceExecutor } from '../source/read-source-executor.js';
|
|
5
|
+
export interface CachedReadExecutorDependencies {
|
|
6
|
+
readonly sourceExecutor: ReadSourceExecutor;
|
|
7
|
+
readonly readExecutionCoordinator?: ReadExecutionCoordinator;
|
|
8
|
+
readonly ownerIdFactory: () => string;
|
|
9
|
+
}
|
|
10
|
+
export declare class CachedReadExecutor {
|
|
11
|
+
private readonly dependencies;
|
|
12
|
+
private readonly localReadInFlight;
|
|
13
|
+
private readonly cacheTraversal;
|
|
14
|
+
constructor(dependencies: CachedReadExecutorDependencies);
|
|
15
|
+
execute<TRead extends AnyRead>(query: Query<TRead>, cachePlan: QueryCachePlan<ReadResultOf<TRead>>): Promise<ReadResultOf<TRead>>;
|
|
16
|
+
private executeLocalLeader;
|
|
17
|
+
private findSharedCacheResult;
|
|
18
|
+
private executeSourceAndBackfill;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=cached-read-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached-read-executor.d.ts","sourceRoot":"","sources":["../../../src/lib/cache/cached-read-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAClG,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAKzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAG5E,MAAM,WAAW,8BAA8B;IAC3C,QAAQ,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAC5C,QAAQ,CAAC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IAC7D,QAAQ,CAAC,cAAc,EAAE,MAAM,MAAM,CAAC;CACzC;AAMD,qBAAa,kBAAkB;IAIR,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHhD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA2B;IAC7D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;gBAEvB,YAAY,EAAE,8BAA8B;IAEnE,OAAO,CAAC,KAAK,SAAS,OAAO,EACtC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EACnB,SAAS,EAAE,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,GAC/C,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAsBjB,kBAAkB;YA6DlB,qBAAqB;YAuBrB,wBAAwB;CAQzC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ReadExecutionCoordinationNotConfiguredError } from '../errors/read-execution-coordination-not-configured.error.js';
|
|
2
|
+
import { DistributedReadFlight } from '../inflight/distributed-read-flight.js';
|
|
3
|
+
import { LocalReadInFlight } from '../inflight/local-read-in-flight.js';
|
|
4
|
+
import { ReadCacheTraversal } from './read-cache-traversal.js';
|
|
5
|
+
export class CachedReadExecutor {
|
|
6
|
+
dependencies;
|
|
7
|
+
localReadInFlight = new LocalReadInFlight();
|
|
8
|
+
cacheTraversal = new ReadCacheTraversal();
|
|
9
|
+
constructor(dependencies) {
|
|
10
|
+
this.dependencies = dependencies;
|
|
11
|
+
}
|
|
12
|
+
async execute(query, cachePlan) {
|
|
13
|
+
const firstSharedIndex = cachePlan.levels.findIndex((level) => level.scope === 'shared');
|
|
14
|
+
const localEndIndex = firstSharedIndex === -1 ? cachePlan.levels.length : firstSharedIndex;
|
|
15
|
+
const localHit = await this.cacheTraversal.findHit(cachePlan.levels.slice(0, localEndIndex), cachePlan.key);
|
|
16
|
+
if (localHit !== undefined) {
|
|
17
|
+
await this.cacheTraversal.populate(cachePlan.levels.slice(0, localHit.index), cachePlan.key, localHit.value);
|
|
18
|
+
return localHit.value;
|
|
19
|
+
}
|
|
20
|
+
return this.localReadInFlight.run(cachePlan.key, () => this.executeLocalLeader(query, cachePlan, localEndIndex));
|
|
21
|
+
}
|
|
22
|
+
async executeLocalLeader(query, cachePlan, localEndIndex) {
|
|
23
|
+
const localHit = await this.cacheTraversal.findHit(cachePlan.levels.slice(0, localEndIndex), cachePlan.key);
|
|
24
|
+
if (localHit !== undefined) {
|
|
25
|
+
await this.cacheTraversal.populate(cachePlan.levels.slice(0, localHit.index), cachePlan.key, localHit.value);
|
|
26
|
+
return localHit.value;
|
|
27
|
+
}
|
|
28
|
+
const shared = await this.findSharedCacheResult(cachePlan, localEndIndex);
|
|
29
|
+
if (shared.status === 'hit') {
|
|
30
|
+
return shared.value;
|
|
31
|
+
}
|
|
32
|
+
if (cachePlan.coordination === undefined) {
|
|
33
|
+
return this.executeSourceAndBackfill(query, cachePlan);
|
|
34
|
+
}
|
|
35
|
+
if (localEndIndex === cachePlan.levels.length) {
|
|
36
|
+
throw new ReadExecutionCoordinationNotConfiguredError('a shared cache level is required as the distributed rendezvous point');
|
|
37
|
+
}
|
|
38
|
+
if (!Number.isFinite(cachePlan.coordination.leaseDurationMs) ||
|
|
39
|
+
cachePlan.coordination.leaseDurationMs <= 0) {
|
|
40
|
+
throw new ReadExecutionCoordinationNotConfiguredError('leaseDurationMs must be a positive finite number');
|
|
41
|
+
}
|
|
42
|
+
const coordinator = this.dependencies.readExecutionCoordinator;
|
|
43
|
+
if (coordinator === undefined) {
|
|
44
|
+
throw new ReadExecutionCoordinationNotConfiguredError('ReadExecutionCoordinator dependency is required when coordination is enabled');
|
|
45
|
+
}
|
|
46
|
+
return new DistributedReadFlight(coordinator).run({
|
|
47
|
+
key: cachePlan.key,
|
|
48
|
+
ownerId: this.dependencies.ownerIdFactory(),
|
|
49
|
+
leaseDurationMs: cachePlan.coordination.leaseDurationMs,
|
|
50
|
+
readShared: () => this.findSharedCacheResult(cachePlan, localEndIndex),
|
|
51
|
+
executeSource: () => this.dependencies.sourceExecutor.execute(query.read),
|
|
52
|
+
publishSourceResult: (result) => this.cacheTraversal.populate(cachePlan.levels, cachePlan.key, result),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async findSharedCacheResult(cachePlan, firstSharedIndex) {
|
|
56
|
+
const hit = await this.cacheTraversal.findHit(cachePlan.levels.slice(firstSharedIndex), cachePlan.key, firstSharedIndex);
|
|
57
|
+
if (hit === undefined) {
|
|
58
|
+
return { status: 'miss' };
|
|
59
|
+
}
|
|
60
|
+
await this.cacheTraversal.populate(cachePlan.levels.slice(0, hit.index), cachePlan.key, hit.value);
|
|
61
|
+
return { status: 'hit', value: hit.value };
|
|
62
|
+
}
|
|
63
|
+
async executeSourceAndBackfill(query, cachePlan) {
|
|
64
|
+
const sourceResult = await this.dependencies.sourceExecutor.execute(query.read);
|
|
65
|
+
await this.cacheTraversal.populate(cachePlan.levels, cachePlan.key, sourceResult);
|
|
66
|
+
return sourceResult;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=cached-read-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached-read-executor.js","sourceRoot":"","sources":["../../../src/lib/cache/cached-read-executor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,2CAA2C,EAAE,MAAM,+DAA+D,CAAC;AAC5H,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAY/D,MAAM,OAAO,kBAAkB;IAIS;IAHnB,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC5C,cAAc,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE3D,YAAoC,YAA4C;QAA5C,iBAAY,GAAZ,YAAY,CAAg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AM,EAAE,SAAS,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAClF,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { QueryCacheLevel, ReadCacheKey } from '@event-driven-platform/query';
|
|
2
|
+
export interface ReadCacheHit<TResult> {
|
|
3
|
+
readonly index: number;
|
|
4
|
+
readonly value: TResult;
|
|
5
|
+
}
|
|
6
|
+
export declare class ReadCacheTraversal {
|
|
7
|
+
findHit<TResult>(levels: readonly QueryCacheLevel<TResult>[], key: ReadCacheKey, offset?: number): Promise<ReadCacheHit<TResult> | undefined>;
|
|
8
|
+
populate<TResult>(levels: readonly QueryCacheLevel<TResult>[], key: ReadCacheKey, value: TResult): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=read-cache-traversal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-cache-traversal.d.ts","sourceRoot":"","sources":["../../../src/lib/cache/read-cache-traversal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAElF,MAAM,WAAW,YAAY,CAAC,OAAO;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B;AAED,qBAAa,kBAAkB;IACd,OAAO,CAAC,OAAO,EACxB,MAAM,EAAE,SAAS,eAAe,CAAC,OAAO,CAAC,EAAE,EAC3C,GAAG,EAAE,YAAY,EACjB,MAAM,SAAI,GACX,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAehC,QAAQ,CAAC,OAAO,EACzB,MAAM,EAAE,SAAS,eAAe,CAAC,OAAO,CAAC,EAAE,EAC3C,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;CAanB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ReadCacheTraversal {
|
|
2
|
+
async findHit(levels, key, offset = 0) {
|
|
3
|
+
for (const [index, level] of levels.entries()) {
|
|
4
|
+
try {
|
|
5
|
+
const result = await level.reader.read(key);
|
|
6
|
+
if (result.status === 'hit') {
|
|
7
|
+
return { index: offset + index, value: result.value };
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
// Cache read failure degrades to a miss for traversal purposes.
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
async populate(levels, key, value) {
|
|
17
|
+
for (const level of [...levels].reverse()) {
|
|
18
|
+
if (level.writer === undefined) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
await level.writer.write(key, value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Cache population must never replace a successful read result.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=read-cache-traversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-cache-traversal.js","sourceRoot":"","sources":["../../../src/lib/cache/read-cache-traversal.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAC,OAAO,CAChB,MAA2C,EAC3C,GAAiB,EACjB,MAAM,GAAG,CAAC;QAEV,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5C,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;oBAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC1D,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACL,gEAAgE;YACpE,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,QAAQ,CACjB,MAA2C,EAC3C,GAAiB,EACjB,KAAc;QAEd,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC7B,SAAS;YACb,CAAC;YAED,IAAI,CAAC;gBACD,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;YAAC,MAAM,CAAC;gBACL,gEAAgE;YACpE,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReadTimeout, ReadTimeoutResult } from './read-timeout.js';
|
|
2
|
+
export declare class DefaultReadTimeout implements ReadTimeout {
|
|
3
|
+
execute<TResult>(work: () => Promise<TResult>, timeoutMs: number): Promise<ReadTimeoutResult<TResult>>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=default-read-timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-read-timeout.d.ts","sourceRoot":"","sources":["../../../src/lib/control/default-read-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAExE,qBAAa,kBAAmB,YAAW,WAAW;IAClD,OAAO,CAAC,OAAO,EACX,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC5B,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAmCzC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class DefaultReadTimeout {
|
|
2
|
+
execute(work, timeoutMs) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
let settled = false;
|
|
5
|
+
const timeout = setTimeout(() => {
|
|
6
|
+
if (settled) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
settled = true;
|
|
10
|
+
resolve({ type: 'timed-out' });
|
|
11
|
+
}, timeoutMs);
|
|
12
|
+
void work().then((result) => {
|
|
13
|
+
if (settled) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
settled = true;
|
|
17
|
+
clearTimeout(timeout);
|
|
18
|
+
resolve({ type: 'completed', result });
|
|
19
|
+
}, (error) => {
|
|
20
|
+
if (settled) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
settled = true;
|
|
24
|
+
clearTimeout(timeout);
|
|
25
|
+
reject(error);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=default-read-timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-read-timeout.js","sourceRoot":"","sources":["../../../src/lib/control/default-read-timeout.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IAC3B,OAAO,CACH,IAA4B,EAC5B,SAAiB;QAEjB,OAAO,IAAI,OAAO,CAA6B,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC/D,IAAI,OAAO,GAAG,KAAK,CAAC;YAEpB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO;gBACX,CAAC;gBAED,OAAO,GAAG,IAAI,CAAC;gBACf,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;YACnC,CAAC,EAAE,SAAS,CAAC,CAAC;YAEd,KAAK,IAAI,EAAE,CAAC,IAAI,CACZ,CAAC,MAAM,EAAE,EAAE;gBACP,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO;gBACX,CAAC;gBAED,OAAO,GAAG,IAAI,CAAC;gBACf,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3C,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;gBACf,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO;gBACX,CAAC;gBAED,OAAO,GAAG,IAAI,CAAC;gBACf,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CACJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReadTimeout } from './read-timeout.js';
|
|
2
|
+
export interface ReadExecutionControls {
|
|
3
|
+
readonly timeoutMs?: number;
|
|
4
|
+
readonly signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
export declare class ReadExecutionControl {
|
|
7
|
+
private readonly readTimeout;
|
|
8
|
+
constructor(readTimeout: ReadTimeout);
|
|
9
|
+
execute<TResult>(work: () => Promise<TResult>, controls?: ReadExecutionControls): Promise<TResult>;
|
|
10
|
+
private awaitWithCancellation;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=read-execution-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-execution-control.d.ts","sourceRoot":"","sources":["../../../src/lib/control/read-execution-control.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CACjC;AAED,qBAAa,oBAAoB;IACV,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAE/C,OAAO,CAAC,OAAO,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC5B,QAAQ,GAAE,qBAA0B,GACrC,OAAO,CAAC,OAAO,CAAC;YAqBL,qBAAqB;CA+BtC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ReadCancelledError } from '../errors/read-cancelled.error.js';
|
|
2
|
+
import { ReadTimedOutError } from '../errors/read-timed-out.error.js';
|
|
3
|
+
export class ReadExecutionControl {
|
|
4
|
+
readTimeout;
|
|
5
|
+
constructor(readTimeout) {
|
|
6
|
+
this.readTimeout = readTimeout;
|
|
7
|
+
}
|
|
8
|
+
async execute(work, controls = {}) {
|
|
9
|
+
if (controls.signal?.aborted === true) {
|
|
10
|
+
throw new ReadCancelledError();
|
|
11
|
+
}
|
|
12
|
+
if (controls.timeoutMs === undefined) {
|
|
13
|
+
return this.awaitWithCancellation(work(), controls.signal);
|
|
14
|
+
}
|
|
15
|
+
const timedExecution = await this.awaitWithCancellation(this.readTimeout.execute(work, controls.timeoutMs), controls.signal);
|
|
16
|
+
if (timedExecution.type === 'timed-out') {
|
|
17
|
+
throw new ReadTimedOutError(controls.timeoutMs);
|
|
18
|
+
}
|
|
19
|
+
return timedExecution.result;
|
|
20
|
+
}
|
|
21
|
+
async awaitWithCancellation(work, signal) {
|
|
22
|
+
if (signal === undefined) {
|
|
23
|
+
return work;
|
|
24
|
+
}
|
|
25
|
+
if (signal.aborted) {
|
|
26
|
+
throw new ReadCancelledError();
|
|
27
|
+
}
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const onAbort = () => {
|
|
30
|
+
reject(new ReadCancelledError());
|
|
31
|
+
};
|
|
32
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
33
|
+
void work.then((result) => {
|
|
34
|
+
signal.removeEventListener('abort', onAbort);
|
|
35
|
+
resolve(result);
|
|
36
|
+
}, (error) => {
|
|
37
|
+
signal.removeEventListener('abort', onAbort);
|
|
38
|
+
reject(error);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=read-execution-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-execution-control.js","sourceRoot":"","sources":["../../../src/lib/control/read-execution-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAQtE,MAAM,OAAO,oBAAoB;IACO;IAApC,YAAoC,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAEzD,KAAK,CAAC,OAAO,CAChB,IAA4B,EAC5B,WAAkC,EAAE;QAEpC,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,qBAAqB,CACnD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,EAClD,QAAQ,CAAC,MAAM,CAClB,CAAC;QAEF,IAAI,cAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACtC,MAAM,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,cAAc,CAAC,MAAM,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAC/B,IAAsB,EACtB,MAA+B;QAE/B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACnC,CAAC;QAED,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,GAAS,EAAE;gBACvB,MAAM,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC;YACrC,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAE1D,KAAK,IAAI,CAAC,IAAI,CACV,CAAC,MAAM,EAAE,EAAE;gBACP,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;gBACf,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CACJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ReadTimeoutResult<TResult> = {
|
|
2
|
+
readonly type: 'completed';
|
|
3
|
+
readonly result: TResult;
|
|
4
|
+
} | {
|
|
5
|
+
readonly type: 'timed-out';
|
|
6
|
+
};
|
|
7
|
+
export interface ReadTimeout {
|
|
8
|
+
execute<TResult>(work: () => Promise<TResult>, timeoutMs: number): Promise<ReadTimeoutResult<TResult>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=read-timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-timeout.d.ts","sourceRoot":"","sources":["../../../src/lib/control/read-timeout.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,CAAC,OAAO,IAC/B;IACI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC5B,GACD;IACI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC9B,CAAC;AAER,MAAM,WAAW,WAAW;IACxB,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;CAC1G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-timeout.js","sourceRoot":"","sources":["../../../src/lib/control/read-timeout.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-cancelled.error.d.ts","sourceRoot":"","sources":["../../../src/lib/errors/read-cancelled.error.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;;CAK5C"}
|