@yaks/workerd 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +273 -2
- package/_dist/cache.d.ts +67 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/compose.d.ts +69 -0
- package/_dist/compose.d.ts.map +1 -0
- package/_dist/deferred.d.ts +10 -0
- package/_dist/deferred.d.ts.map +1 -0
- package/_dist/door.d.ts +36 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/fetch.d.ts +27 -0
- package/_dist/fetch.d.ts.map +1 -0
- package/_dist/gen.d.ts +65 -0
- package/_dist/gen.d.ts.map +1 -0
- package/_dist/mod.d.ts +53 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plugin.d.ts +15 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/purge.d.ts +104 -0
- package/_dist/purge.d.ts.map +1 -0
- package/_dist/rate.d.ts +65 -0
- package/_dist/rate.d.ts.map +1 -0
- package/_dist/stub.d.ts +20 -0
- package/_dist/stub.d.ts.map +1 -0
- package/_dist/upgrade.d.ts +25 -0
- package/_dist/upgrade.d.ts.map +1 -0
- package/_dist/version.d.ts +2 -0
- package/_dist/version.d.ts.map +1 -0
- package/_dist/worker.d.ts +40 -0
- package/_dist/worker.d.ts.map +1 -0
- package/cache.js +199 -0
- package/cache.js.map +1 -0
- package/cache.ts +254 -0
- package/compose.js +126 -0
- package/compose.js.map +1 -0
- package/compose.ts +236 -0
- package/deferred.js +39 -0
- package/deferred.js.map +1 -0
- package/deferred.ts +64 -0
- package/deno.json +1 -0
- package/door.js +64 -0
- package/door.js.map +1 -0
- package/door.ts +89 -0
- package/fetch.js +228 -0
- package/fetch.js.map +1 -0
- package/fetch.ts +231 -0
- package/gen.js +153 -0
- package/gen.js.map +1 -0
- package/gen.ts +189 -0
- package/mod.js +53 -0
- package/mod.js.map +1 -0
- package/mod.ts +69 -0
- package/package.json +52 -4
- package/plugin.js +16 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +19 -0
- package/purge.js +200 -0
- package/purge.js.map +1 -0
- package/purge.ts +245 -0
- package/rate.js +84 -0
- package/rate.js.map +1 -0
- package/rate.ts +110 -0
- package/stub.js +23 -0
- package/stub.js.map +1 -0
- package/stub.ts +42 -0
- package/upgrade.js +82 -0
- package/upgrade.js.map +1 -0
- package/upgrade.ts +96 -0
- package/version.js +24 -0
- package/version.js.map +1 -0
- package/version.ts +30 -0
- package/worker.js +62 -0
- package/worker.js.map +1 -0
- package/worker.ts +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,274 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/workerd
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cloudflare Workers integration. It makes a Worker from a plugin config: its
|
|
4
|
+
routes, letters and queue batches, and the Durable Object and entrypoint classes
|
|
5
|
+
it defines, each loaded on its first call. For [@yaks/api](../api/README.md) it
|
|
6
|
+
provides a Worker fetch entrypoint, WebSocket upgrades through `WebSocketPair`,
|
|
7
|
+
request authentication helpers, and request forwarding to Durable Objects. For
|
|
8
|
+
an entrypoint behind Cloudflare's cache it asks it through its binding and
|
|
9
|
+
purges it by tag. Applications provide the graph, storage adapter, and
|
|
10
|
+
authorization policy, and what their caches may keep.
|
|
11
|
+
|
|
12
|
+
This package creates no database, component tables, or persistent records.
|
|
13
|
+
`worker()` caches API handlers in memory; each graph's storage adapter
|
|
14
|
+
determines where its data is kept. For example, [@yaks/d1](../d1/README.md) uses
|
|
15
|
+
D1 and [@yaks/durable-object](../durable-object/README.md) uses a Durable
|
|
16
|
+
Object's SQLite storage.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
deno add jsr:@yaks/workerd
|
|
22
|
+
# or: npx jsr add @yaks/workerd
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Exports
|
|
26
|
+
|
|
27
|
+
All exports are available from `@yaks/workerd`:
|
|
28
|
+
|
|
29
|
+
| Exports | Purpose |
|
|
30
|
+
| ----------------------------------------------- | ----------------------------------------------------------- |
|
|
31
|
+
| `compose`, `WorkerFacet`, `Deferred`, `Entry` | Make a Worker module from a config's `./worker` facets |
|
|
32
|
+
| `deferred`, `Made`, `Around` | A class made at once whose object loads on its first call |
|
|
33
|
+
| `VERSION` | The path a composed Worker says its deploy at |
|
|
34
|
+
| `worker`, `Options`, `Worker`, `Env`, `Context` | Build and type a Worker fetch entrypoint |
|
|
35
|
+
| `door`, `Door` | Build an authentication callback from a credential verifier |
|
|
36
|
+
| `cookies`, `bearer` | Read cookies or a bearer token from a request |
|
|
37
|
+
| `workerUpgrade`, `Accepting` | Accept a Workers WebSocket and return the upgrade response |
|
|
38
|
+
| `forward`, `Namespace`, `Stub` | Forward a request to a named Durable Object |
|
|
39
|
+
|
|
40
|
+
Six subpaths serve a Worker made from a config:
|
|
41
|
+
|
|
42
|
+
| Subpath | Purpose |
|
|
43
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
44
|
+
| `@yaks/workerd/compose` | `compose` alone, importing nothing of `@yaks/api` but its route matching |
|
|
45
|
+
| `@yaks/workerd/worker` | this package's own `./worker` facet: the deploy's version route |
|
|
46
|
+
| `@yaks/workerd/gen` | `written`, the module of a config and its plugins' facets; `loader` and `imports`, the module its stores load their facets from |
|
|
47
|
+
| `@yaks/workerd/rate` | `within`, `source`, `tooMany`: a door's per-source ceiling, a Rate Limiting binding |
|
|
48
|
+
| `@yaks/workerd/cache` | `stored`: local Cache API reads with detached fills, read around past 500 ms; `through`, `hit`, `purging`: a cached entrypoint's service hop, bounded fallback, cache status and tag purge |
|
|
49
|
+
| `@yaks/workerd/purge` | `purge`, `Purger`, `purger`, `SPREAD`: purges by tag through one Durable Object that keeps the account's purge bucket, and how long one takes to reach every colo |
|
|
50
|
+
|
|
51
|
+
## A Worker from a config
|
|
52
|
+
|
|
53
|
+
A Worker's config is the shape `yak` reads from `yak.json`: a list of plugins,
|
|
54
|
+
each with options. Each plugin contributes a `./worker` facet (`WorkerFacet`):
|
|
55
|
+
|
|
56
|
+
- `routes(options, env)`: the paths it answers. The router asks the plugins in
|
|
57
|
+
the config's order, and a request takes the first route that matches it and
|
|
58
|
+
answers. A route that answers `null` passes the request to the next one, so a
|
|
59
|
+
route can serve one hostname and leave the others. A request no route answers
|
|
60
|
+
is answered 404.
|
|
61
|
+
- `wrap(options, env)`: what stands around the plugin's own routes and every
|
|
62
|
+
later plugin's. It is handed the request and `next`, which asks those routes,
|
|
63
|
+
and may hand `next` another request or answer without asking.
|
|
64
|
+
- `email(options, env)` and `queue(options, env)`: what handles a letter Email
|
|
65
|
+
Routing hands the Worker, and a batch a queue delivers. At most one plugin
|
|
66
|
+
gives each.
|
|
67
|
+
- `classes`: the Durable Object and entrypoint classes it defines, by the name
|
|
68
|
+
`wrangler.toml` binds. Each is made at once and loads its code on its first
|
|
69
|
+
call, so a cold isolate evaluates only what woke it. A class marked `entered`
|
|
70
|
+
runs each call inside the Worker's entry as `<Name> <method>`.
|
|
71
|
+
- `entry`: the boundary every invocation enters (a tracker's), loaded with the
|
|
72
|
+
first. At most one plugin gives it.
|
|
73
|
+
|
|
74
|
+
Options are read from the Worker's env the way a host reads them:
|
|
75
|
+
`{"binding":
|
|
76
|
+
"AI"}` is the binding and `{"secret": "KEY"}` the secret, read each
|
|
77
|
+
time they are accessed. What a factory builds from one env object is kept for as
|
|
78
|
+
long as that object is.
|
|
79
|
+
|
|
80
|
+
A Worker resolves no module at run time, so a build step writes the facets'
|
|
81
|
+
imports out (`@yaks/workerd/gen` `written`), with the config beside them as
|
|
82
|
+
data, and the entry hands both to `compose`:
|
|
83
|
+
|
|
84
|
+
```ts ignore
|
|
85
|
+
// worker.ts
|
|
86
|
+
import { compose } from '@yaks/workerd/compose'
|
|
87
|
+
import { config, facets } from './worker-facets.ts' // written from the config
|
|
88
|
+
|
|
89
|
+
let shop = compose(config, facets)
|
|
90
|
+
export default shop.default
|
|
91
|
+
export let { Shop } = shop.classes
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A config naming this package first answers `/_yak/version` with the deploy
|
|
95
|
+
before any other plugin loads:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"plugins": [
|
|
100
|
+
{
|
|
101
|
+
"use": "@yaks/workerd",
|
|
102
|
+
"with": {
|
|
103
|
+
"name": "shop",
|
|
104
|
+
"version": { "binding": "CF_VERSION_METADATA" }
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"@acme/shop"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Worker entrypoint
|
|
113
|
+
|
|
114
|
+
This example assumes `shop.ts` initializes a graph from the Worker's bindings
|
|
115
|
+
and verifies a token, returning an actor or `null`:
|
|
116
|
+
|
|
117
|
+
```ts ignore
|
|
118
|
+
import { door, worker } from '@yaks/workerd'
|
|
119
|
+
import { memberFor, shopGraph } from './shop.ts'
|
|
120
|
+
|
|
121
|
+
type Env = { SHOP: unknown; SHOP_SECRET: string }
|
|
122
|
+
|
|
123
|
+
export default worker({
|
|
124
|
+
api: async (env: Env) => ({
|
|
125
|
+
graph: await shopGraph(env.SHOP),
|
|
126
|
+
authenticate: door({
|
|
127
|
+
cookie: 'shop_session',
|
|
128
|
+
verify: (token) => memberFor(token, env.SHOP_SECRET),
|
|
129
|
+
required: true,
|
|
130
|
+
}),
|
|
131
|
+
}),
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This serves `POST /apply`, `GET|POST /query`, and `/ws` with the behavior and
|
|
136
|
+
errors described by [@yaks/api](../api/README.md). The `api` callback accepts
|
|
137
|
+
bindings and may return its options synchronously or asynchronously.
|
|
138
|
+
|
|
139
|
+
The handler is cached by the identity of the `env` object. Concurrent requests
|
|
140
|
+
using that object share initialization and the same subscription registry. A
|
|
141
|
+
different bindings object gets a different handler. Failed initialization is not
|
|
142
|
+
retained, so later requests can retry. This cache is local to a Worker isolate;
|
|
143
|
+
it does not coordinate subscriptions between isolates.
|
|
144
|
+
|
|
145
|
+
For a D1-backed application, the binding configuration might be:
|
|
146
|
+
|
|
147
|
+
```toml
|
|
148
|
+
# wrangler.toml
|
|
149
|
+
name = "shop"
|
|
150
|
+
main = "worker.ts"
|
|
151
|
+
compatibility_date = "2025-05-08"
|
|
152
|
+
|
|
153
|
+
[[d1_databases]]
|
|
154
|
+
binding = "SHOP"
|
|
155
|
+
database_name = "shop"
|
|
156
|
+
database_id = "replace-with-your-database-id"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`shopGraph` is application code that opens the corresponding storage adapter;
|
|
160
|
+
`worker()` does not open D1 or install a schema. Supply `SHOP_SECRET` through
|
|
161
|
+
your Worker's secret configuration.
|
|
162
|
+
|
|
163
|
+
## Request authentication
|
|
164
|
+
|
|
165
|
+
`door()` reads a configured cookie, or a bearer token when that cookie is
|
|
166
|
+
absent, and passes the credential and request to `verify`:
|
|
167
|
+
|
|
168
|
+
```ts ignore
|
|
169
|
+
let authenticate = door({
|
|
170
|
+
cookie: 'shop_session',
|
|
171
|
+
verify: async (token, request) => {
|
|
172
|
+
let member = await verifyToken(token, request)
|
|
173
|
+
return member ? { by: member } : null
|
|
174
|
+
},
|
|
175
|
+
required: true,
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`verifyToken` above is application code returning a member entity ID or `null`.
|
|
180
|
+
`verify` must return an actor such as `{ by: memberId, via: sessionId }`, or
|
|
181
|
+
`null`. The bearer token is not retried if a present cookie is empty or fails
|
|
182
|
+
verification. Omit `cookie` to read only the bearer token. Bearer scheme
|
|
183
|
+
matching is case-insensitive; cookie values are percent-decoded where possible.
|
|
184
|
+
|
|
185
|
+
With `required: true`, missing or rejected credentials result in HTTP 401.
|
|
186
|
+
Without it, requests with no verified actor are allowed and writes are
|
|
187
|
+
unattributed. `@yaks/api` invokes the callback for reads, writes, and socket
|
|
188
|
+
upgrades and replaces client-supplied `$actor` values with the verified actor.
|
|
189
|
+
The application and graph plugins still need to enforce authorization.
|
|
190
|
+
|
|
191
|
+
Use the separate `cookies(request)` and `bearer(request)` helpers to implement a
|
|
192
|
+
different credential-selection policy.
|
|
193
|
+
|
|
194
|
+
## WebSocket upgrades
|
|
195
|
+
|
|
196
|
+
`worker()` supplies `workerUpgrade` unless the API options include another
|
|
197
|
+
`upgrade`. When building a handler directly, pass it explicitly:
|
|
198
|
+
|
|
199
|
+
```ts ignore
|
|
200
|
+
import { api } from '@yaks/api'
|
|
201
|
+
import { workerUpgrade } from '@yaks/workerd'
|
|
202
|
+
|
|
203
|
+
let handler = api({ graph, authenticate, upgrade: workerUpgrade })
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
It creates a `WebSocketPair`, accepts the server half, and returns
|
|
207
|
+
`{ socket, response }`, with HTTP 101 and the client half on the response. It
|
|
208
|
+
throws if the runtime does not provide `WebSocketPair`.
|
|
209
|
+
|
|
210
|
+
## When the graph lives in a Durable Object
|
|
211
|
+
|
|
212
|
+
A Durable Object can keep a graph's SQLite storage and subscriptions in one
|
|
213
|
+
instance. The outer Worker selects an object and forwards the request:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { forward, type Namespace } from '@yaks/workerd'
|
|
217
|
+
|
|
218
|
+
type Env = { SHOPS: Namespace }
|
|
219
|
+
|
|
220
|
+
export default {
|
|
221
|
+
fetch: (request: Request, env: Env) => {
|
|
222
|
+
let shop = new URL(request.url).hostname.split('.')[0]
|
|
223
|
+
return forward(env.SHOPS, shop, request)
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`forward(namespace, name, request)` calls `idFromName(name)`, gets the object's
|
|
229
|
+
stub, and passes the original request to `stub.fetch()`. It does not read the
|
|
230
|
+
body, change the path, or remove the upgrade header. The object implements its
|
|
231
|
+
own fetch handler, typically `api()` with `workerUpgrade` over its graph.
|
|
232
|
+
|
|
233
|
+
The application must implement and export the Durable Object class. A binding
|
|
234
|
+
for an application class named `Shop` might be:
|
|
235
|
+
|
|
236
|
+
```toml
|
|
237
|
+
# wrangler.toml
|
|
238
|
+
name = "shops"
|
|
239
|
+
main = "worker.ts"
|
|
240
|
+
compatibility_date = "2025-05-08"
|
|
241
|
+
|
|
242
|
+
[[durable_objects.bindings]]
|
|
243
|
+
name = "SHOPS"
|
|
244
|
+
class_name = "Shop"
|
|
245
|
+
|
|
246
|
+
[[migrations]]
|
|
247
|
+
tag = "v1"
|
|
248
|
+
new_sqlite_classes = ["Shop"]
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The same name selects the same object within the namespace. Validate the
|
|
252
|
+
selected name and authorize the caller's access to that graph. A subdomain, path
|
|
253
|
+
segment, or client header identifies a destination; it does not prove access
|
|
254
|
+
rights.
|
|
255
|
+
|
|
256
|
+
## Compatibility
|
|
257
|
+
|
|
258
|
+
The WebSocket integration requires Cloudflare Workers APIs. Other interfaces are
|
|
259
|
+
structurally typed, so importing the package does not require a Cloudflare
|
|
260
|
+
global or package import. `conform.ts` checks those interfaces against
|
|
261
|
+
`@cloudflare/workers-types`. Runtime dependencies are `@yaks/api`, `@yaks/graph`
|
|
262
|
+
and `@yaks/host`.
|
|
263
|
+
|
|
264
|
+
## Related packages
|
|
265
|
+
|
|
266
|
+
[@yaks/api](../api/README.md) defines routes, errors, and subscriptions;
|
|
267
|
+
[@yaks/graph](../graph/README.md) defines entities and write processing. Storage
|
|
268
|
+
adapters include [@yaks/durable-object](../durable-object/README.md),
|
|
269
|
+
[@yaks/d1](../d1/README.md), and [@yaks/ram](../ram/README.md). See the
|
|
270
|
+
[graph architecture](../graph/ARCHITECTURE.md) for adapter responsibilities.
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
Apache-2.0
|
package/_dist/cache.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Clock } from "@yaks/fp";
|
|
2
|
+
import type { Purged } from "./purge.js";
|
|
3
|
+
/** Whether Cloudflare's cache answered this, and not the entrypoint behind
|
|
4
|
+
* it. */ export declare let hit: (res: Response) => boolean;
|
|
5
|
+
/** A service binding to an entrypoint. */ export type Bound = {
|
|
6
|
+
fetch(req: Request): Promise<Response>;
|
|
7
|
+
};
|
|
8
|
+
/** A local response cache. A miss never starts an origin request or waits
|
|
9
|
+
* for another request's fill. Cloudflare's Cache API supplies this boundary. */ export type Stored = {
|
|
10
|
+
match(req: Request): Promise<Response | undefined>;
|
|
11
|
+
put(req: Request, res: Response): Promise<unknown>;
|
|
12
|
+
};
|
|
13
|
+
/** How {@link stored} waits on its cache, and hears of one that failed. */ export type Shelving = {
|
|
14
|
+
/** keeps a fill going behind the answer (`ctx.waitUntil`) */ hold: (work: Promise<void>) => void;
|
|
15
|
+
/** told of a cache that could not be opened, matched or filled */ failed: (error: unknown) => void;
|
|
16
|
+
/** the clock `patience` is heard on */ clock?: Clock;
|
|
17
|
+
/** how long opening and matching may take, in ms; 500 unless said */ patience?: number;
|
|
18
|
+
};
|
|
19
|
+
/** Read a local cache, drawing a miss immediately and retaining its fill
|
|
20
|
+
* behind the answer. Only explicitly public, whole GET responses are stored;
|
|
21
|
+
* HEAD and Range can read an existing entry without replacing it. A cache
|
|
22
|
+
* that has not answered within `patience` is read around: the answer is
|
|
23
|
+
* drawn, and nothing is filled into a cache that is not keeping up. That is
|
|
24
|
+
* not a failure, since the read costs no more than a miss. */ export declare let stored: (cache: Stored | (() => Promise<Stored>), req: Request, draw: (req: Request) => Promise<Response>, {}: Shelving) => Promise<Response>;
|
|
25
|
+
/** Keep immutable bytes under an internal cache key. Missing bytes are read
|
|
26
|
+
* again on the next request. */ export declare let storedBytes: (cache: Stored | (() => Promise<Stored>), key: string, read: () => Promise<Uint8Array<ArrayBuffer> | null>, options: Shelving) => Promise<Uint8Array<ArrayBuffer> | null>;
|
|
27
|
+
/** How {@link through} waits between tries and on the cache, and hears of a
|
|
28
|
+
* cache that failed it. */ export type Through = {
|
|
29
|
+
/** the clock the backoff between tries, and the patience, wait on */ clock?: Clock;
|
|
30
|
+
/** told of a status Cloudflare's cache answered for want of an answer */ failed?: (res: Response, req: Request) => void;
|
|
31
|
+
/** how long a read waits on the cache, in ms; 5 s unless said. Infinity
|
|
32
|
+
* waits the hop out, for a read only the entrypoint's origin can answer,
|
|
33
|
+
* which answering in-process would ask a second time. */ patience?: number;
|
|
34
|
+
/** told of a read the cache did not answer within `patience`, whose
|
|
35
|
+
* in-process answer then came back whole */ held?: (req: Request, ms: number) => void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The entrypoint bound as `cache`'s answer to `req`, or `local`'s, made
|
|
39
|
+
* in-process from the same request, where there is no binding or the
|
|
40
|
+
* runtime refuses or fails the hop:
|
|
41
|
+
*
|
|
42
|
+
* - Inside an invocation that may not serialize a service stub (a dispatched
|
|
43
|
+
* Worker's call back into its platform), the runtime refuses the hop with
|
|
44
|
+
* `DataCloneError` (T-44804), and no header says beforehand that it will.
|
|
45
|
+
* - A status from 520 to 530 is Cloudflare's cache saying it got no answer
|
|
46
|
+
* from the entrypoint behind it, which `failed` is told of.
|
|
47
|
+
* - A reset or a dropped connection fails the hop retryably; a read carries
|
|
48
|
+
* no body, so each try sends a copy of it with a store call's backoff
|
|
49
|
+
* (`@yaks/durable-object/resets` `retried`). Anything with a body is its
|
|
50
|
+
* caller's to send again.
|
|
51
|
+
* - A read the cache has not answered within `patience` is given up on and
|
|
52
|
+
* answered in-process: the cache can hold a burst of misses back for a
|
|
53
|
+
* minute while the entrypoint behind it has long answered. `held` is told
|
|
54
|
+
* only when that answer comes back whole, which says the cache held back
|
|
55
|
+
* what could be given. One that fails too, or is a server error, says the
|
|
56
|
+
* origin was slow, not the cache (a bucket retrying through a blip), and
|
|
57
|
+
* that failure is what reports it, once, where it happened.
|
|
58
|
+
*/ export declare let through: (cache: Bound | undefined, req: Request, local: (req: Request) => Promise<Response>, _dts_1: never) => Promise<Response>;
|
|
59
|
+
/** What the runtime lends an entrypoint whose cache is on: `ctx.cache`. */ export type EntryCache = {
|
|
60
|
+
purge(o: {
|
|
61
|
+
tags: string[];
|
|
62
|
+
}): Promise<Purged>;
|
|
63
|
+
};
|
|
64
|
+
/** The `purge(tags)` an entrypoint behind the cache answers, through the
|
|
65
|
+
* cache the runtime lent it. An entrypoint asked to purge with no cache in
|
|
66
|
+
* front is bound where it shouldn't be, so that is a refusal, not a no-op. */ export declare let purging: (cache?: EntryCache) => any;
|
|
67
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sources":["../cache.ts"],"names":[],"mappings":"AAmCA,SAAS,KAAK,KAAK,wBAAqC;AACxD,cAAc,MAAM,qBAAoB;AAMxC;OACO,GACP,OAAO,YAAI,MAAO,KAAK,aAAW,OAAO,CACgB;AAEzD,wCAAwC,GACxC,YAAY;EAAU,MAAM,KAAK,UAAU,QAAQ;;AAEnD;8EAC8E,GAC9E,YAAY;EACV,MAAM,KAAK,UAAU,QAAQ,WAAW,SAAS;EACjD,IAAI,KAAK,SAAS,KAAK,WAAW,QAAQ,OAAO;;AASnD,yEAAyE,GACzE,YAAY;EACV,2DAA2D,GAC3D,OAAO,MAAM,QAAQ,IAAI,MAAM,IAAI;EACnC,gEAAgE,GAChE,SAAS,OAAO,OAAO,KAAK,IAAI;EAChC,qCAAqC,GACrC,QAAQ;EACR,mEAAmE,GACnE,WAAW,MAAM;;AAGnB;;;;;4DAK4D,GAC5D,OAAO,YAAI,SACT,OAAO,gBAAgB,QAAQ,UAC/B,KAAK,SACL,OAAO,KAAK,YAAY,QAAQ,WAChC,IAA4C,QAAQ,KACnD,QAAQ,UAwCV;AAUD;8BAC8B,GAC9B,OAAO,YAAI,cACT,OAAO,gBAAgB,QAAQ,UAC/B,KAAK,MAAM,EACX,YAAY,QAAQ,WAAW,eAAe,IAAI,GAClD,SAAS,aACR,QAAQ,WAAW,eAAe,IAAI,EAUxC;AAOD;yBACyB,GACzB,YAAY;EACV,mEAAmE,GACnE,QAAQ;EACR,uEAAuE,GACvE,UAAU,KAAK,UAAU,KAAK,YAAY,IAAI;EAC9C;;yDAEuD,GACvD,WAAW,MAAM;EACjB;4CAC0C,GAC1C,QAAQ,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;;AAG3C;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,YAAI,UACT,OAAO,QAAQ,SAAS,EACxB,KAAK,SACL,QAAQ,KAAK,YAAY,QAAQ,WACjC,kBACC,QAAQ,UA6BV;AAED,yEAAyE,GACzE,YAAY;EAAe,MAAM;IAAK,MAAM,MAAM;MAAO,QAAQ;;AAEjE;;4EAE4E,GAC5E,OAAO,YAAI,UACR,QAAQ,mBAYR"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Route } from "@yaks/api/routed";
|
|
2
|
+
import { type Config, type Options } from "@yaks/host/config";
|
|
3
|
+
import { type Made } from "./deferred.js";
|
|
4
|
+
import type { Context, Env } from "./worker.js";
|
|
5
|
+
/** The boundary every invocation enters: the Worker's own handlers, and each
|
|
6
|
+
* call of a class whose calls are {@link Deferred.entered}, given the state or
|
|
7
|
+
* context the runtime made it with, so a Durable Object's boundary can ask
|
|
8
|
+
* whether the runtime moved it. It runs `run` and answers what it answers; a
|
|
9
|
+
* tracker reports what escapes it. */ export type Entry = <T>(env: Env, name: string, run: () => Promise<T>, request?: Request, state?: unknown) => Promise<T>;
|
|
10
|
+
/** A class the runtime constructs by its name (a Durable Object, an
|
|
11
|
+
* entrypoint), made at once and loaded on its first call. */ export type Deferred = {
|
|
12
|
+
/** the runtime's class it extends: `DurableObject` or `WorkerEntrypoint`
|
|
13
|
+
* from `cloudflare:workers`, or `Object` for one called only by `fetch`
|
|
14
|
+
* and the runtime's own callbacks */ base: abstract new(...args: never[]) => object;
|
|
15
|
+
/** the methods it answers; each is the loaded object's own */ methods: readonly string[];
|
|
16
|
+
/** what makes the object, from the runtime's arguments: its state or
|
|
17
|
+
* context, and the env */ load: () => Promise<Made>;
|
|
18
|
+
/** whether each call enters {@link Entry} as `<Name> <method>` */ entered?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** A route a plugin adds to a Worker. Its answer may be `null`: the request
|
|
21
|
+
* is not its after all (a hostname it does not serve, a door it does not
|
|
22
|
+
* know), and the router asks the next route. */ export type WorkerRoute = Omit<Route, 'handle'> & {
|
|
23
|
+
handle: (request: Request) => Response | null | Promise<Response | null>;
|
|
24
|
+
};
|
|
25
|
+
/** What a plugin puts around the routes from its own on: it is handed each
|
|
26
|
+
* request and `next`, which asks those routes, and answers what it decides.
|
|
27
|
+
* A wrap may hand `next` another request, or answer without asking it. */ export type Wrap = (request: Request, next: (request: Request) => Promise<Response>) => Promise<Response>;
|
|
28
|
+
/** A handler of the Worker's default export other than `fetch`: one letter
|
|
29
|
+
* Email Routing handed it, or one batch a queue delivered. */ export type Handling = (given: never, ctx: Context) => Promise<void>;
|
|
30
|
+
/** `<plugin>/worker` — what a plugin adds to a Worker. Every field is
|
|
31
|
+
* optional. A factory is given the plugin's options, read from the env, and
|
|
32
|
+
* the env itself, for code that is not yet given its bindings as options. */ export type WorkerFacet = {
|
|
33
|
+
/** the classes it defines, by the name wrangler.toml binds */ classes?: Record<string, Deferred>;
|
|
34
|
+
/** the paths it answers. The router asks each plugin in the config's
|
|
35
|
+
* order, and a request takes the first route that matches it and answers. */ routes?: (options: Options, env: Env) => WorkerRoute[];
|
|
36
|
+
/** what it puts around its own routes and every later plugin's */ wrap?: (options: Options, env: Env) => Wrap;
|
|
37
|
+
/** the letters handed to the Worker; at most one plugin answers them */ email?: (options: Options, env: Env) => Handling;
|
|
38
|
+
/** the batches a queue delivers; at most one plugin answers them */ queue?: (options: Options, env: Env) => Handling;
|
|
39
|
+
/** the boundary every invocation enters; at most one plugin gives it */ entry?: () => Promise<Entry>;
|
|
40
|
+
};
|
|
41
|
+
/** A Worker module: its default export, and its classes by name. */ export type Composed = {
|
|
42
|
+
default: {
|
|
43
|
+
fetch: (request: Request, env: Env, ctx?: Context) => Promise<Response>;
|
|
44
|
+
email?: (message: unknown, env: Env, ctx: Context) => Promise<void>;
|
|
45
|
+
queue?: (batch: unknown, env: Env, ctx: Context) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
classes: Record<string, new(...args: unknown[]) => object>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The Worker `config` names, from each plugin's `./worker` facet in `facets`.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { compose } from '@yaks/workerd'
|
|
54
|
+
* import { equal } from '@yaks/testing'
|
|
55
|
+
*
|
|
56
|
+
* let yak = compose({ plugins: ['hello'] }, {
|
|
57
|
+
* hello: {
|
|
58
|
+
* routes: () => [{
|
|
59
|
+
* method: 'GET',
|
|
60
|
+
* path: '/',
|
|
61
|
+
* handle: () => new Response('hello'),
|
|
62
|
+
* }],
|
|
63
|
+
* },
|
|
64
|
+
* })
|
|
65
|
+
* let res = await yak.default.fetch(new Request('https://x.test/'), {})
|
|
66
|
+
* equal(await res.text(), 'hello')
|
|
67
|
+
* ```
|
|
68
|
+
*/ export declare let compose: (config: Config, facets: Record<string, WorkerFacet>) => Composed;
|
|
69
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sources":["../compose.ts"],"names":[],"mappings":"AAgBA,SAAS,KAAK,KAAK,gCAA6C;AAEhE,SACE,KAAK,MAAM,EAGX,KAAK,OAAO,iCAGuB;AACrC,SAAmB,KAAK,IAAI,wBAAuB;AACnD,cAAc,OAAO,EAAE,GAAG,sBAAqB;AAE/C;;;;oCAIoC,GACpC,YAAY,SAAS,GACnB,KAAK,KACL,MAAM,MAAM,EACZ,WAAW,QAAQ,IACnB,UAAU,SACV,QAAQ,OAAO,KACZ,QAAQ;AAEb;2DAC2D,GAC3D,YAAY;EACV;;qCAEmC,GACnC,mBAAoB,GAAG,MAAM,KAAK,OAAO,MAAM;EAC/C,4DAA4D,GAC5D,kBAAkB,MAAM;EACxB;0BACwB,GACxB,YAAY,QAAQ;EACpB,gEAAgE,GAChE,UAAU,OAAO;;AAGnB;;8CAE8C,GAC9C,YAAY,cAAc,KAAK,OAAO;EACpC,SAAS,SAAS,YAAY,WAAW,IAAI,GAAG,QAAQ,WAAW,IAAI;;AAGzE;;wEAEwE,GACxE,YAAY,QACV,SAAS,SACT,OAAO,SAAS,YAAY,QAAQ,cACjC,QAAQ;AAEb;4DAC4D,GAC5D,YAAY,YAAY,OAAO,KAAK,EAAE,KAAK,YAAY,QAAQ,IAAI;AAEnE;;2EAE2E,GAC3E,YAAY;EACV,4DAA4D,GAC5D,UAAU,OAAO,MAAM,EAAE;EACzB;6EAC2E,GAC3E,UAAU,SAAS,SAAS,KAAK,QAAQ;EACzC,gEAAgE,GAChE,QAAQ,SAAS,SAAS,KAAK,QAAQ;EACvC,sEAAsE,GACtE,SAAS,SAAS,SAAS,KAAK,QAAQ;EACxC,kEAAkE,GAClE,SAAS,SAAS,SAAS,KAAK,QAAQ;EACxC,sEAAsE,GACtE,cAAc,QAAQ;;AAGxB,kEAAkE,GAClE,YAAY;EACV;IACE,QAAQ,SAAS,SAAS,KAAK,KAAK,MAAM,YAAY,QAAQ;IAC9D,SAAS,SAAS,OAAO,EAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,IAAI;IAClE,SAAS,OAAO,OAAO,EAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,IAAI;;EAElE,SAAS,OAAO,MAAM,MAAO,GAAG,MAAM,OAAO,OAAO,MAAM;;AA2B5D;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,UACT,QAAQ,QACR,QAAQ,OAAO,MAAM,EAAE,iBACtB,SAkFF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** What makes the object a deferred class answers through, from the
|
|
2
|
+
* arguments the runtime constructed the class with (its state or context,
|
|
3
|
+
* and its bindings). A class is one: `(...args) => new C(...args)`. */ export type Made = (...args: never[]) => object;
|
|
4
|
+
/** How each call is run: around the deferred object's own answer, given the
|
|
5
|
+
* constructor's arguments, the method's name and its arguments. */ export type Around = (args: unknown[], method: string, call: () => Promise<unknown>, given: unknown[]) => Promise<unknown>;
|
|
6
|
+
/** `Base` with `methods`, each of which loads what `load` gives, makes one
|
|
7
|
+
* object with it from the constructor's arguments, and answers through it.
|
|
8
|
+
* A load that fails is tried again by the next call, and so is a factory
|
|
9
|
+
* that throws. `around`, when given, runs each call. */ export declare let deferred: (Base: abstract new(...args: never[]) => object, load: () => Promise<Made>, methods: readonly string[], around?: Around) => new(...args: unknown[]) => object;
|
|
10
|
+
//# sourceMappingURL=deferred.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferred.d.ts","sources":["../deferred.ts"],"names":[],"mappings":"AAQA;;qEAEqE,GACrE,YAAY,QAAQ,GAAG,MAAM,KAAK,OAAO,MAAM;AAE/C;iEACiE,GACjE,YAAY,UACV,MAAM,OAAO,IACb,QAAQ,MAAM,EACd,YAAY,QAAQ,OAAO,GAC3B,OAAO,OAAO,OACX,QAAQ,OAAO;AAIpB;;;sDAGsD,GACtD,OAAO,YAAI,WACT,mBAAoB,GAAG,MAAM,KAAK,OAAO,MAAM,EAC/C,YAAY,QAAQ,OACpB,kBAAkB,MAAM,IACxB,SAAS,eACH,GAAG,MAAM,OAAO,OAAO,MAAM,CA8BpC"}
|