@reventlessdev/reventless-core 3.0.0-alpha.213 → 3.0.0-alpha.215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
- package/src/adapter/EventLogProvisioning/EventLogProvisioning.res +165 -0
- package/src/adapter/EventLogProvisioning/EventLogProvisioning.res.mjs +49 -0
- package/src/adapter/RuntimeExtension/RuntimeExtension.res +194 -0
- package/src/adapter/RuntimeExtension/RuntimeExtension.res.mjs +60 -0
- package/src/components/DcbEventLog/DcbEventLog_Builder.res +17 -4
- package/src/components/DcbEventLog/DcbEventLog_Builder.res.mjs +9 -5
- package/src/components/EventLog/EventLog_Builder.res +10 -2
- package/src/components/EventLog/EventLog_Builder.res.mjs +4 -1
- package/tests/adapter/EventLogProvisioningTest.res +207 -0
- package/tests/adapter/EventLogProvisioningTest.res.mjs +150 -0
- package/tests/adapter/RuntimeExtensionHookReachTest.res +84 -0
- package/tests/adapter/RuntimeExtensionHookReachTest.res.mjs +95 -0
- package/tests/adapter/RuntimeExtensionTest.res +127 -0
- package/tests/adapter/RuntimeExtensionTest.res.mjs +111 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.0.0-alpha.215 (2026-08-08)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **core,aws,local:** add the RuntimeExtension cold-start seam ([143e30e](https://github.com/ReventlessDev/reventless-core/commit/143e30eeded6232ce7f0fcc18328939b2917bb31))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# 3.0.0-alpha.214 (2026-08-07)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **core,aws:** add the EventLogProvisioning seam for out-of-tree consumers ([82477b3](https://github.com/ReventlessDev/reventless-core/commit/82477b38c1ef90fbe3a6f4a114a9798770329470))
|
|
18
|
+
|
|
19
|
+
|
|
6
20
|
# 3.0.0-alpha.213 (2026-08-05)
|
|
7
21
|
|
|
8
22
|
### Bug Fixes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.215",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"sury": "11.0.0-alpha.4",
|
|
30
30
|
"uuid": "^13.0.0",
|
|
31
|
+
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.14",
|
|
31
32
|
"@reventlessdev/rescript-effect": "0.1.0-alpha.32",
|
|
32
33
|
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.2",
|
|
33
34
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.10",
|
|
34
|
-
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.14",
|
|
35
35
|
"@reventlessdev/rescript-node": "2.0.0-alpha.2",
|
|
36
36
|
"@reventlessdev/rescript-pulumi-pulumi": "2.3.0-alpha.18",
|
|
37
37
|
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.2",
|
|
38
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.127",
|
|
38
39
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.30",
|
|
39
40
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.0",
|
|
40
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.127",
|
|
41
41
|
"@reventlessdev/reventless-spec": "3.0.0-alpha.101"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Deploy-time hook: every event log announces itself as it is provisioned, so an
|
|
3
|
+
extension can attach behaviour to it inside the program that owns it.
|
|
4
|
+
|
|
5
|
+
No-op by default. Zero behavioral change unless an extension registers a backend
|
|
6
|
+
via `use` before the platform/plugin build. The seam fires once per log at
|
|
7
|
+
provisioning time (inside the deploy program) — never at invocation, and it runs
|
|
8
|
+
no code in production.
|
|
9
|
+
|
|
10
|
+
What a backend does with a log is deliberately NOT a framework concern.
|
|
11
|
+
Aggregation, CDC export, external indexing, replication and archival all want to
|
|
12
|
+
react to an event log's changes; none of them belong in core, and each one added
|
|
13
|
+
to core is maintenance its users pay for whether or not they use it. This only
|
|
14
|
+
exposes the choke point through which the framework says "I just provisioned an
|
|
15
|
+
event log, here is everything I know about it" and leaves the reaction to the
|
|
16
|
+
listener.
|
|
17
|
+
|
|
18
|
+
The alternative — discovering a log's resources from outside the owning program —
|
|
19
|
+
is impractical on AWS: a DynamoDB stream ARN ends in a creation-time stream
|
|
20
|
+
label, so it cannot be synthesised, and exporting it per plugin pushes framework
|
|
21
|
+
internals into every deployment's stack outputs.
|
|
22
|
+
|
|
23
|
+
See `docs/plans/done/event-log-provisioned-seam.md`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
Which event-log family provisioned the log. The two differ in what a reader finds
|
|
28
|
+
on the wire — a classic log is per-aggregate and its rows carry an aggregate id;
|
|
29
|
+
a DCB log is per-plugin and its rows carry tags — so a backend that decodes
|
|
30
|
+
records needs to know which it is looking at before it looks.
|
|
31
|
+
*/
|
|
32
|
+
type logStyle =
|
|
33
|
+
| /** per-aggregate log behind `EventLog_Builder` */ Classic
|
|
34
|
+
| /** per-plugin tagged log behind `DcbEventLog_Builder` */ Dcb
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
An event-log backend, registered by an extension (a deploy program) before the
|
|
38
|
+
platform builds. `onProvisioned` is called once per event log.
|
|
39
|
+
|
|
40
|
+
`~name` is the log's STATIC logical name — the suffixed component name the
|
|
41
|
+
builder passed to its storage maker (`ProductEventLog`, `CatalogDcbEventLog`). A
|
|
42
|
+
Pulumi-based backend derives logical resource names from it, which must be stable
|
|
43
|
+
and known at graph-construction time.
|
|
44
|
+
|
|
45
|
+
`~owner` is the model element the log belongs to: `{kind: Aggregate, name:
|
|
46
|
+
"Product"}` for a classic log, `{kind: Plugin, name: "Catalog"}` for a DCB log
|
|
47
|
+
(the plugin owns it, not any one slice). `~plugin` / `~platform` come from the
|
|
48
|
+
ambient `ResourceAttribution` context the plugin builder publishes during
|
|
49
|
+
construction — the same source `AWS_Tags` and `Monitoring.notify` use. Both are
|
|
50
|
+
`None` for a log provisioned outside any plugin construct.
|
|
51
|
+
|
|
52
|
+
`~resources` is the adapter's deploy-time resources, not a stream: a stream is a
|
|
53
|
+
DynamoDB-shaped idea and SQL-backed adapters have none. A backend derives
|
|
54
|
+
whatever its store supports and does nothing for the rest — a Postgres log
|
|
55
|
+
arrives with `resources: []`, and an in-memory one with nothing attachable. The
|
|
56
|
+
contract is uniform on purpose; filtering belongs in the backend.
|
|
57
|
+
|
|
58
|
+
`~opts` carries the log component's parent options. A backend that provisions
|
|
59
|
+
anything needs them, or its resources land outside the component tree.
|
|
60
|
+
|
|
61
|
+
Because `onProvisioned` fires during resource creation inside the deploy program,
|
|
62
|
+
a Pulumi-based backend can create its resources in the same stack, parented
|
|
63
|
+
naturally.
|
|
64
|
+
|
|
65
|
+
**The reader budget.** A DynamoDB table has exactly one stream, and DynamoDB
|
|
66
|
+
Streams throttles beyond two processes reading the same shard. Core already
|
|
67
|
+
spends one slot: `EventCollectorChannel_Helpers` maps every event-log stream onto
|
|
68
|
+
the plugin's event-collector Lambda. A backend that subscribes through this seam
|
|
69
|
+
is therefore reader #2 — the ceiling. A second stream consumer would throttle the
|
|
70
|
+
first, which is why registration is single-slot and loud (see `use`). If several
|
|
71
|
+
consumers are ever needed the answer is a fan-out — routing through the existing
|
|
72
|
+
collector, or a stream type that supports more readers — not more subscriptions.
|
|
73
|
+
|
|
74
|
+
**Snapshots share the log's table.** Classic aggregate snapshots are written to
|
|
75
|
+
the event-log table under `position = "SNAPSHOT"`, so a stream consumer sees them
|
|
76
|
+
alongside events. The seam does not filter; a backend that only wants events must
|
|
77
|
+
skip those rows itself.
|
|
78
|
+
|
|
79
|
+
**No ordering guarantee against other seams.** This and `Monitoring.notify` both
|
|
80
|
+
fire during provisioning, from different builders, in whatever order the graph is
|
|
81
|
+
constructed. A backend must not depend on having seen one before the other.
|
|
82
|
+
*/
|
|
83
|
+
module type Backend = {
|
|
84
|
+
let onProvisioned: (
|
|
85
|
+
~logStyle: logStyle,
|
|
86
|
+
~name: string,
|
|
87
|
+
~owner: option<ResourceAttribution.owner>,
|
|
88
|
+
~plugin: option<string>,
|
|
89
|
+
~platform: option<string>,
|
|
90
|
+
~resources: array<ReventlessInfra.Adapter.resource>,
|
|
91
|
+
~opts: Pulumi.CustomResourceOptions.t,
|
|
92
|
+
) => unit
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Default backend: does nothing. Active unless an extension calls `use`. */
|
|
96
|
+
module Noop: Backend = {
|
|
97
|
+
let onProvisioned = (
|
|
98
|
+
~logStyle as _,
|
|
99
|
+
~name as _,
|
|
100
|
+
~owner as _,
|
|
101
|
+
~plugin as _,
|
|
102
|
+
~platform as _,
|
|
103
|
+
~resources as _,
|
|
104
|
+
~opts as _,
|
|
105
|
+
) => ()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let backend: ref<module(Backend)> = ref(module(Noop: Backend))
|
|
109
|
+
let registered = ref(false)
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
Register the event-log backend. Must run before the platform/plugin build in the
|
|
113
|
+
deploy program (plain statement order — the registry is consulted lazily at each
|
|
114
|
+
provisioning site). Called once, by the extension, first.
|
|
115
|
+
|
|
116
|
+
Single-slot and loud: a second `use` raises rather than silently winning, because
|
|
117
|
+
the reader budget documented on `Backend` means two registered backends is not a
|
|
118
|
+
last-writer-wins configuration question but two consumers competing for one
|
|
119
|
+
stream slot — a defect that otherwise surfaces in production as iterator-age
|
|
120
|
+
alarms on whichever one lost. `reset` clears the slot for tests.
|
|
121
|
+
*/
|
|
122
|
+
let use = (b: module(Backend)) => {
|
|
123
|
+
if registered.contents {
|
|
124
|
+
JsError.throwWithMessage(
|
|
125
|
+
"EventLogProvisioning.use called twice: only one event-log backend can be registered. " ++
|
|
126
|
+
"A DynamoDB stream supports two readers per shard and core's event collector already holds one, " ++
|
|
127
|
+
"so a second backend would throttle the first. Compose the two backends into one, or fan out " ++
|
|
128
|
+
"behind a single registration.",
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
registered := true
|
|
132
|
+
backend := b
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
Restore the default `Noop` backend and clear the registration slot. Test-support
|
|
137
|
+
only — deploy programs never call this.
|
|
138
|
+
*/
|
|
139
|
+
let reset = () => {
|
|
140
|
+
backend := module(Noop: Backend)
|
|
141
|
+
registered := false
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
Announce a provisioned event log to the registered backend. Called by the
|
|
146
|
+
`EventLog` and `DcbEventLog` builders at their storage-provisioning sites (once
|
|
147
|
+
per log). Firing from the builders rather than from each storage adapter is what
|
|
148
|
+
makes the contract uniform: every adapter — DynamoDB, Postgres, SQLite,
|
|
149
|
+
in-memory, and any future one — is covered by construction, with nothing to
|
|
150
|
+
remember when a new one is written. No-op until an extension registers a backend.
|
|
151
|
+
*/
|
|
152
|
+
let notify = (
|
|
153
|
+
~logStyle: logStyle,
|
|
154
|
+
~name: string,
|
|
155
|
+
~owner: option<ResourceAttribution.owner>,
|
|
156
|
+
~resources: array<ReventlessInfra.Adapter.resource>,
|
|
157
|
+
~opts: Pulumi.CustomResourceOptions.t,
|
|
158
|
+
) => {
|
|
159
|
+
module B = unpack(backend.contents)
|
|
160
|
+
// The owning plugin/platform come from the ambient context the plugin builder publishes
|
|
161
|
+
// (ResourceAttribution.enter) — populated exactly when this fires, so the call sites need not
|
|
162
|
+
// thread the names. `None` outside a plugin construct.
|
|
163
|
+
let {ResourceAttribution.plugin: plugin, platform} = ResourceAttribution.current.contents
|
|
164
|
+
B.onProvisioned(~logStyle, ~name, ~owner, ~plugin, ~platform, ~resources, ~opts)
|
|
165
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
4
|
+
import * as ResourceAttribution$ReventlessCore from "../../ResourceAttribution.res.mjs";
|
|
5
|
+
|
|
6
|
+
function onProvisioned(param, param$1, param$2, param$3, param$4, param$5, param$6) {
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let Noop = {
|
|
11
|
+
onProvisioned: onProvisioned
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let backend = {
|
|
15
|
+
contents: Noop
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let registered = {
|
|
19
|
+
contents: false
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function use(b) {
|
|
23
|
+
if (registered.contents) {
|
|
24
|
+
Stdlib_JsError.throwWithMessage("EventLogProvisioning.use called twice: only one event-log backend can be registered. A DynamoDB stream supports two readers per shard and core's event collector already holds one, so a second backend would throttle the first. Compose the two backends into one, or fan out behind a single registration.");
|
|
25
|
+
}
|
|
26
|
+
registered.contents = true;
|
|
27
|
+
backend.contents = b;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function reset() {
|
|
31
|
+
backend.contents = Noop;
|
|
32
|
+
registered.contents = false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function notify(logStyle, name, owner, resources, opts) {
|
|
36
|
+
let B = backend.contents;
|
|
37
|
+
let match = ResourceAttribution$ReventlessCore.current.contents;
|
|
38
|
+
B.onProvisioned(logStyle, name, owner, match.plugin, match.platform, resources, opts);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
Noop,
|
|
43
|
+
backend,
|
|
44
|
+
registered,
|
|
45
|
+
use,
|
|
46
|
+
reset,
|
|
47
|
+
notify,
|
|
48
|
+
}
|
|
49
|
+
/* No side effect */
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Runtime hook: every provisioned runtime announces its cold start, so an extension
|
|
3
|
+
can register the runtime callback hooks the framework already ships — before the
|
|
4
|
+
runtime handles its first request.
|
|
5
|
+
|
|
6
|
+
No-op by default. Zero behavioral change unless an extension registers one via
|
|
7
|
+
`use` before the platform/plugin build: nothing is bundled, no env var is set, and
|
|
8
|
+
no code runs.
|
|
9
|
+
|
|
10
|
+
`Monitoring` and `EventLogProvisioning` are the deploy-time half of this shape —
|
|
11
|
+
they let an extension attach behaviour to *what gets provisioned*. This is the
|
|
12
|
+
runtime half: *what runs inside it*. Without it,
|
|
13
|
+
`CommandGenerator_Callback.registerCommandInterceptor`,
|
|
14
|
+
`QueryDb_Callback.registerQueryInterceptor` and the two
|
|
15
|
+
`EventPublish_Callback` publish hooks are unreachable in a deployed runtime —
|
|
16
|
+
each is a module-level `ref` consulted on the hot path, so it is useless unless
|
|
17
|
+
something calls the registrar in the same process first, and the framework-owned
|
|
18
|
+
entry shells import only framework and domain modules. Per-command authorisation,
|
|
19
|
+
request tracing, rate limiting and request accounting are all built from those
|
|
20
|
+
hooks, and each one is otherwise a change to the framework itself.
|
|
21
|
+
|
|
22
|
+
What an extension does at cold start is deliberately NOT a framework concern.
|
|
23
|
+
This only exposes the choke point through which the framework says "a runtime of
|
|
24
|
+
this kind just started, here is who it is" and leaves the reaction to the
|
|
25
|
+
listener.
|
|
26
|
+
|
|
27
|
+
See `docs/plans/done/runtime-extension-seam.md`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
What every registered extension is handed at cold start. Kept to the runtime's
|
|
32
|
+
IDENTITY on purpose: an extension registering a command interceptor needs to know
|
|
33
|
+
which runtime it is inside, not that runtime's storage ops or specs. Widening this
|
|
34
|
+
to internals would make it a second, informal handler API — and the four hooks it
|
|
35
|
+
exists to reach already receive their own per-request payloads
|
|
36
|
+
(`commandInterceptor` gets `~componentName` / `~tag` / `~args` on every call).
|
|
37
|
+
|
|
38
|
+
`~runtimeKind` is the modelling kind of the component the runtime runs — the same
|
|
39
|
+
`ComponentType.t` every AWS runtime builder already passes to
|
|
40
|
+
`RuntimeEnvironment_Lambda.makeFromCodeAsset`, so there is no third taxonomy to
|
|
41
|
+
keep in step with `Monitoring.unitKind` and `ResourceAttribution.Role`.
|
|
42
|
+
|
|
43
|
+
`~component` is the runtime's STATIC logical name — the shared Lambda's name where
|
|
44
|
+
several components of one kind share a runtime (`AllAggregatesCmdHandler`), the
|
|
45
|
+
component's own name where it does not. It identifies the runtime, not a single
|
|
46
|
+
model element; use the per-request `~componentName` on the interception hooks to
|
|
47
|
+
tell hosted components apart.
|
|
48
|
+
|
|
49
|
+
`~plugin` / `~platform` are the owning plugin and platform, taken at provisioning
|
|
50
|
+
time from the ambient `ResourceAttribution` context (the same source `AWS_Tags`,
|
|
51
|
+
`Monitoring.notify` and `EventLogProvisioning.notify` use) and carried into the
|
|
52
|
+
runtime as configuration — the runtime has no ambient deploy context of its own.
|
|
53
|
+
Both are `None` for a runtime provisioned outside any plugin construct.
|
|
54
|
+
*/
|
|
55
|
+
type coldStartHook = (
|
|
56
|
+
~runtimeKind: ComponentType.t,
|
|
57
|
+
~component: string,
|
|
58
|
+
~plugin: option<string>,
|
|
59
|
+
~platform: option<string>,
|
|
60
|
+
) => unit
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
A runtime extension, registered by an extension (a deploy program) before the
|
|
64
|
+
platform builds. `onColdStart` is called once per runtime process, before that
|
|
65
|
+
runtime handles its first request.
|
|
66
|
+
|
|
67
|
+
`moduleUrl` is the extension module's own `import.meta.url`. It is what makes the
|
|
68
|
+
seam reachable in a *deployed* runtime: registering a first-class module only
|
|
69
|
+
populates the deploy program's process, and the Lambda is a different one, so the
|
|
70
|
+
framework bundles the module's package into the code archive and names the module
|
|
71
|
+
in the runtime's config for the entry shell to import. Spec and behavior modules
|
|
72
|
+
are carried into runtimes the same way. The convention matches
|
|
73
|
+
`@@reventless.spec`'s injected `let moduleUrl`, so a ReScript extension can lift
|
|
74
|
+
it from there.
|
|
75
|
+
|
|
76
|
+
**Synchronous.** An async hook would have to be awaited before the first request
|
|
77
|
+
and would put extension latency on every cold path. An extension needing I/O can
|
|
78
|
+
start it here and not block on it.
|
|
79
|
+
|
|
80
|
+
**Fired once, in registration order.** Unlike `EventLogProvisioning` there is no
|
|
81
|
+
scarce resource here (no stream-reader budget), so several extensions compose —
|
|
82
|
+
tracing and accounting are independent concerns. They run in the order they were
|
|
83
|
+
registered; an extension that depends on another having run first is relying on
|
|
84
|
+
its host's statement order, which is the only ordering the framework can promise.
|
|
85
|
+
|
|
86
|
+
**A throwing extension does not take the runtime down.** Each hook is isolated:
|
|
87
|
+
the failure is logged at ERROR and the remaining extensions still run. Failing the
|
|
88
|
+
runtime instead would turn a broken extension into an outage, which is a worse
|
|
89
|
+
trade than a loud, skipped hook.
|
|
90
|
+
*/
|
|
91
|
+
module type Extension = {
|
|
92
|
+
let moduleUrl: string
|
|
93
|
+
let onColdStart: coldStartHook
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let extensions: ref<array<module(Extension)>> = ref([])
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
Register a runtime extension. Must run before the platform/plugin build in the
|
|
100
|
+
deploy program (plain statement order — the registry is read when each runtime's
|
|
101
|
+
code archive and config are built). Additive: call once per extension.
|
|
102
|
+
|
|
103
|
+
There is no `Noop` default to register. The neutral state is the empty registry,
|
|
104
|
+
which is also the state that bundles nothing and sets no env var; a registered
|
|
105
|
+
do-nothing extension would still cost a package in every runtime's archive.
|
|
106
|
+
*/
|
|
107
|
+
let use = (e: module(Extension)) => extensions := extensions.contents->Array.concat([e])
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
Drop every registration. Test-support only — deploy programs never call this.
|
|
111
|
+
*/
|
|
112
|
+
let reset = () => extensions := []
|
|
113
|
+
|
|
114
|
+
/** True when no extension is registered — the default. Deploy-time backends use
|
|
115
|
+
this to skip bundling and config emission entirely, so a deployment that
|
|
116
|
+
registers nothing produces a byte-identical archive. */
|
|
117
|
+
let isEmpty = () => extensions.contents->Array.length == 0
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
The `import.meta.url` of every registered extension, in registration order. Read
|
|
121
|
+
by the provider's code-archive builder to bundle each extension's package and to
|
|
122
|
+
name the modules a deployed runtime imports at cold start.
|
|
123
|
+
*/
|
|
124
|
+
let moduleUrls = (): array<string> =>
|
|
125
|
+
extensions.contents->Array.map(e => {
|
|
126
|
+
module E = unpack(e)
|
|
127
|
+
E.moduleUrl
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
let log = Logger.fromEnv()
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
Run one hook, isolated. A throwing extension is logged at ERROR and skipped; the
|
|
134
|
+
caller keeps going. See the failure-policy note on `Extension`.
|
|
135
|
+
*/
|
|
136
|
+
let runHook = (
|
|
137
|
+
hook: coldStartHook,
|
|
138
|
+
~index: int,
|
|
139
|
+
~runtimeKind: ComponentType.t,
|
|
140
|
+
~component: string,
|
|
141
|
+
~plugin: option<string>,
|
|
142
|
+
~platform: option<string>,
|
|
143
|
+
) =>
|
|
144
|
+
try hook(~runtimeKind, ~component, ~plugin, ~platform) catch {
|
|
145
|
+
| exn =>
|
|
146
|
+
let message =
|
|
147
|
+
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown error")
|
|
148
|
+
log.error(
|
|
149
|
+
~comp="RuntimeExtension",
|
|
150
|
+
`extension ${index->Int.toString} threw at cold start of ${runtimeKind->ComponentType.toString}(${component}); skipped: ${message}`,
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
Fire the given cold-start hooks, in order, each isolated from the others. Used by
|
|
156
|
+
runtimes that resolve their extensions themselves — a deployed entry point loads
|
|
157
|
+
its extension modules dynamically, so it holds hooks rather than first-class
|
|
158
|
+
modules.
|
|
159
|
+
*/
|
|
160
|
+
let notifyColdStartHooks = (
|
|
161
|
+
~hooks: array<coldStartHook>,
|
|
162
|
+
~runtimeKind: ComponentType.t,
|
|
163
|
+
~component: string,
|
|
164
|
+
~plugin: option<string>,
|
|
165
|
+
~platform: option<string>,
|
|
166
|
+
) =>
|
|
167
|
+
hooks->Array.forEachWithIndex((hook, index) =>
|
|
168
|
+
hook->runHook(~index, ~runtimeKind, ~component, ~plugin, ~platform)
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
Announce a runtime's cold start to every extension registered in THIS process.
|
|
173
|
+
Called by in-process runtimes (the local platform), where the deploy program and
|
|
174
|
+
the runtime share a process so the registry is already populated. A deployed
|
|
175
|
+
runtime cannot use this — its registry is empty until it imports the extension
|
|
176
|
+
modules named in its config — and calls `notifyColdStartHooks` instead. No-op
|
|
177
|
+
until an extension registers.
|
|
178
|
+
*/
|
|
179
|
+
let notifyColdStart = (
|
|
180
|
+
~runtimeKind: ComponentType.t,
|
|
181
|
+
~component: string,
|
|
182
|
+
~plugin: option<string>,
|
|
183
|
+
~platform: option<string>,
|
|
184
|
+
) =>
|
|
185
|
+
notifyColdStartHooks(
|
|
186
|
+
~hooks=extensions.contents->Array.map(e => {
|
|
187
|
+
module E = unpack(e)
|
|
188
|
+
E.onColdStart
|
|
189
|
+
}),
|
|
190
|
+
~runtimeKind,
|
|
191
|
+
~component,
|
|
192
|
+
~plugin,
|
|
193
|
+
~platform,
|
|
194
|
+
)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
6
|
+
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
7
|
+
import * as ComponentType$ReventlessCore from "../../ComponentType.res.mjs";
|
|
8
|
+
|
|
9
|
+
let extensions = {
|
|
10
|
+
contents: []
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function use(e) {
|
|
14
|
+
extensions.contents = extensions.contents.concat([e]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function reset() {
|
|
18
|
+
extensions.contents = [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isEmpty() {
|
|
22
|
+
return extensions.contents.length === 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function moduleUrls() {
|
|
26
|
+
return extensions.contents.map(e => e.moduleUrl);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let log = Logger$ReventlessCore.fromEnv();
|
|
30
|
+
|
|
31
|
+
function runHook(hook, index, runtimeKind, component, plugin, platform) {
|
|
32
|
+
try {
|
|
33
|
+
return hook(runtimeKind, component, plugin, platform);
|
|
34
|
+
} catch (raw_exn) {
|
|
35
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
36
|
+
let message = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown error");
|
|
37
|
+
return log.error("RuntimeExtension", undefined, `extension ` + index.toString() + ` threw at cold start of ` + ComponentType$ReventlessCore.toString(runtimeKind) + `(` + component + `); skipped: ` + message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function notifyColdStartHooks(hooks, runtimeKind, component, plugin, platform) {
|
|
42
|
+
hooks.forEach((hook, index) => runHook(hook, index, runtimeKind, component, plugin, platform));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function notifyColdStart(runtimeKind, component, plugin, platform) {
|
|
46
|
+
notifyColdStartHooks(extensions.contents.map(e => e.onColdStart), runtimeKind, component, plugin, platform);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
extensions,
|
|
51
|
+
use,
|
|
52
|
+
reset,
|
|
53
|
+
isEmpty,
|
|
54
|
+
moduleUrls,
|
|
55
|
+
log,
|
|
56
|
+
runHook,
|
|
57
|
+
notifyColdStartHooks,
|
|
58
|
+
notifyColdStart,
|
|
59
|
+
}
|
|
60
|
+
/* log Not a pure module */
|
|
@@ -16,21 +16,34 @@ module Make = (
|
|
|
16
16
|
let construct = (indexes, partitionTag, crossPartitionTagKeys, self, name) => {
|
|
17
17
|
let opts = {Pulumi.CustomResourceOptions.parent: self->Component.toPulumiResource}
|
|
18
18
|
|
|
19
|
+
let logName = name->ComponentType.name(DcbEventLog.componentType)
|
|
20
|
+
// The DCB event log is shared across the plugin's slices, so the plugin owns
|
|
21
|
+
// it — not any one component.
|
|
22
|
+
let owner: ResourceAttribution.owner = {kind: ComponentType.Plugin, name}
|
|
19
23
|
let storage = Storage.make(
|
|
20
|
-
~name=
|
|
24
|
+
~name=logName,
|
|
21
25
|
~indexes,
|
|
22
26
|
~partitionTag,
|
|
23
27
|
~crossPartitionTagKeys,
|
|
24
28
|
~opts,
|
|
25
29
|
)
|
|
26
30
|
|
|
31
|
+
// Announce the log to any registered extension. No-op unless a deploy program
|
|
32
|
+
// registered a backend via EventLogProvisioning.use — see
|
|
33
|
+
// src/adapter/EventLogProvisioning/EventLogProvisioning.res.
|
|
34
|
+
EventLogProvisioning.notify(
|
|
35
|
+
~logStyle=Dcb,
|
|
36
|
+
~name=logName,
|
|
37
|
+
~owner=Some(owner),
|
|
38
|
+
~resources=storage.resources,
|
|
39
|
+
~opts,
|
|
40
|
+
)
|
|
41
|
+
|
|
27
42
|
module SpecificEventTopic = EventTopic_Builder.Make(EventTopicSpec, EventTopicPublisher)
|
|
28
43
|
let eventTopic = SpecificEventTopic.make(
|
|
29
44
|
~name,
|
|
30
45
|
~storageResources=storage.resources,
|
|
31
|
-
|
|
32
|
-
// owns it — not any one component.
|
|
33
|
-
~owner={kind: ComponentType.Plugin, name},
|
|
46
|
+
~owner,
|
|
34
47
|
~opts=opts->Util.Pulumi.ComponentResourceOptions.ofCustomResourceOptions,
|
|
35
48
|
)
|
|
36
49
|
|
|
@@ -8,6 +8,7 @@ import * as DcbEventLog$ReventlessCore from "./DcbEventLog.res.mjs";
|
|
|
8
8
|
import * as Util_Pulumi$ReventlessCore from "../../util/Util_Pulumi.res.mjs";
|
|
9
9
|
import * as ComponentType$ReventlessCore from "../../ComponentType.res.mjs";
|
|
10
10
|
import * as EventTopic_Builder$ReventlessCore from "../EventTopic/EventTopic_Builder.res.mjs";
|
|
11
|
+
import * as EventLogProvisioning$ReventlessCore from "../../adapter/EventLogProvisioning/EventLogProvisioning.res.mjs";
|
|
11
12
|
import * as DcbEventLog_Operations$ReventlessCore from "./DcbEventLog_Operations.res.mjs";
|
|
12
13
|
|
|
13
14
|
function Make(Storage) {
|
|
@@ -20,16 +21,19 @@ function Make(Storage) {
|
|
|
20
21
|
let opts = {
|
|
21
22
|
parent: opts_parent
|
|
22
23
|
};
|
|
23
|
-
let
|
|
24
|
+
let logName = ComponentType$ReventlessCore.name(extra$1, DcbEventLog$ReventlessCore.componentType);
|
|
25
|
+
let owner = {
|
|
26
|
+
kind: "Plugin",
|
|
27
|
+
name: extra$1
|
|
28
|
+
};
|
|
29
|
+
let storage = Storage.make(logName, indexes, partitionTag, crossPartitionTagKeys, opts);
|
|
30
|
+
EventLogProvisioning$ReventlessCore.notify("Dcb", logName, owner, storage.resources, opts);
|
|
24
31
|
let SpecificEventTopic = EventTopic_Builder$ReventlessCore.Make({
|
|
25
32
|
Id: Id$Reventless.$$String,
|
|
26
33
|
name: "DcbEventLog",
|
|
27
34
|
eventSchema: S.json
|
|
28
35
|
})(EventTopicPublisher);
|
|
29
|
-
let eventTopic = SpecificEventTopic.make(extra$1, storage.resources,
|
|
30
|
-
kind: "Plugin",
|
|
31
|
-
name: extra$1
|
|
32
|
-
}, Util_Pulumi$ReventlessCore.ComponentResourceOptions.ofCustomResourceOptions(opts));
|
|
36
|
+
let eventTopic = SpecificEventTopic.make(extra$1, storage.resources, owner, Util_Pulumi$ReventlessCore.ComponentResourceOptions.ofCustomResourceOptions(opts));
|
|
33
37
|
Component$ReventlessCore.setOperations(extra, Pulumi.all([
|
|
34
38
|
storage.operations,
|
|
35
39
|
Component$ReventlessCore.operations(eventTopic)
|
|
@@ -18,9 +18,17 @@ module Make = (
|
|
|
18
18
|
let construct = (~owner=?, self, name) => {
|
|
19
19
|
let opts = {Pulumi.CustomResourceOptions.parent: self->Component.toPulumiResource}
|
|
20
20
|
|
|
21
|
-
let
|
|
22
|
-
|
|
21
|
+
let logName = name->ComponentType.name(EventLog.componentType)
|
|
22
|
+
let storage = Storage.make(~name=logName, ~owner, ~opts)
|
|
23
|
+
|
|
24
|
+
// Announce the log to any registered extension. No-op unless a deploy program
|
|
25
|
+
// registered a backend via EventLogProvisioning.use — see
|
|
26
|
+
// src/adapter/EventLogProvisioning/EventLogProvisioning.res.
|
|
27
|
+
EventLogProvisioning.notify(
|
|
28
|
+
~logStyle=Classic,
|
|
29
|
+
~name=logName,
|
|
23
30
|
~owner,
|
|
31
|
+
~resources=storage.resources,
|
|
24
32
|
~opts,
|
|
25
33
|
)
|
|
26
34
|
|
|
@@ -7,6 +7,7 @@ import * as Util_Pulumi$ReventlessCore from "../../util/Util_Pulumi.res.mjs";
|
|
|
7
7
|
import * as ComponentType$ReventlessCore from "../../ComponentType.res.mjs";
|
|
8
8
|
import * as EventTopic_Builder$ReventlessCore from "../EventTopic/EventTopic_Builder.res.mjs";
|
|
9
9
|
import * as EventLog_Operations$ReventlessCore from "./EventLog_Operations.res.mjs";
|
|
10
|
+
import * as EventLogProvisioning$ReventlessCore from "../../adapter/EventLogProvisioning/EventLogProvisioning.res.mjs";
|
|
10
11
|
|
|
11
12
|
function Make(Spec) {
|
|
12
13
|
return Storage => (EventTopicPublisher => {
|
|
@@ -15,7 +16,9 @@ function Make(Spec) {
|
|
|
15
16
|
let opts = {
|
|
16
17
|
parent: opts_parent
|
|
17
18
|
};
|
|
18
|
-
let
|
|
19
|
+
let logName = ComponentType$ReventlessCore.name(extra$1, EventLog$ReventlessCore.componentType);
|
|
20
|
+
let storage = Storage.make(logName, owner, opts);
|
|
21
|
+
EventLogProvisioning$ReventlessCore.notify("Classic", logName, owner, storage.resources, opts);
|
|
19
22
|
let SpecificEventTopic = EventTopic_Builder$ReventlessCore.Make(Spec)(EventTopicPublisher);
|
|
20
23
|
let eventTopic = SpecificEventTopic.make(extra$1, storage.resources, owner, Util_Pulumi$ReventlessCore.ComponentResourceOptions.ofCustomResourceOptions(opts));
|
|
21
24
|
Component$ReventlessCore.setOperations(extra, Pulumi.all([
|