@t4h.framework/core 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai/skills/framework-core/SKILL.md +5 -7
- package/.ai/skills/framework-workflow-creation/SKILL.md +4 -6
- package/.ai/skills/framework-workflow-testing/SKILL.md +1 -9
- package/CHANGELOG.md +68 -0
- package/README.md +77 -8
- package/dist/core.d.ts +2 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -1
- package/dist/core.js.map +1 -1
- package/dist/exceptions/AsyncActivityCallbackException.d.ts +13 -0
- package/dist/exceptions/AsyncActivityCallbackException.d.ts.map +1 -0
- package/dist/exceptions/AsyncActivityCallbackException.js +20 -0
- package/dist/exceptions/AsyncActivityCallbackException.js.map +1 -0
- package/dist/models/AsyncActivity.d.ts +2 -0
- package/dist/models/AsyncActivity.d.ts.map +1 -1
- package/dist/models/AsyncActivity.js.map +1 -1
- package/dist/models/AsyncActivityAdvanceResult.d.ts +3 -1
- package/dist/models/AsyncActivityAdvanceResult.d.ts.map +1 -1
- package/dist/models/AsyncActivityAdvanceResult.js +3 -1
- package/dist/models/AsyncActivityAdvanceResult.js.map +1 -1
- package/dist/models/AsyncActivityAwaitable.d.ts +1 -1
- package/dist/models/AsyncActivityAwaitable.d.ts.map +1 -1
- package/dist/models/AsyncActivityAwaitable.js +0 -2
- package/dist/models/AsyncActivityAwaitable.js.map +1 -1
- package/dist/models/History.d.ts +2 -17
- package/dist/models/History.d.ts.map +1 -1
- package/dist/models/History.js +8 -26
- package/dist/models/History.js.map +1 -1
- package/dist/models/Logger.d.ts.map +1 -1
- package/dist/models/Logger.js +1 -2
- package/dist/models/Logger.js.map +1 -1
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +35 -6
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestWorkflowEnvironment.d.ts.map +1 -1
- package/dist/testing/TestWorkflowEnvironment.js +4 -6
- package/dist/testing/TestWorkflowEnvironment.js.map +1 -1
- package/dist/testing/tools/resolve-activity.d.ts.map +1 -1
- package/dist/testing/tools/resolve-activity.js +1 -4
- package/dist/testing/tools/resolve-activity.js.map +1 -1
- package/dist/testing/tools/resolve-async-activity.d.ts +2 -3
- package/dist/testing/tools/resolve-async-activity.d.ts.map +1 -1
- package/dist/testing/tools/resolve-async-activity.js +36 -17
- package/dist/testing/tools/resolve-async-activity.js.map +1 -1
- package/dist/testing/tools/run-workflow-ticks.d.ts.map +1 -1
- package/dist/testing/tools/run-workflow-ticks.js +0 -6
- package/dist/testing/tools/run-workflow-ticks.js.map +1 -1
- package/dist/testing/tools/run-workflow.d.ts +0 -4
- package/dist/testing/tools/run-workflow.d.ts.map +1 -1
- package/dist/testing/tools/run-workflow.js +7 -17
- package/dist/testing/tools/run-workflow.js.map +1 -1
- package/dist/tools/AsyncActivityCallback.d.ts +32 -0
- package/dist/tools/AsyncActivityCallback.d.ts.map +1 -0
- package/dist/tools/AsyncActivityCallback.js +137 -0
- package/dist/tools/AsyncActivityCallback.js.map +1 -0
- package/dist/tools/Internals.d.ts +0 -2
- package/dist/tools/Internals.d.ts.map +1 -1
- package/dist/tools/Internals.js +1 -5
- package/dist/tools/Internals.js.map +1 -1
- package/package.json +1 -1
- package/dist/exceptions/TimerNotAllowedException.d.ts +0 -5
- package/dist/exceptions/TimerNotAllowedException.d.ts.map +0 -1
- package/dist/exceptions/TimerNotAllowedException.js +0 -9
- package/dist/exceptions/TimerNotAllowedException.js.map +0 -1
- package/dist/tools/Deterministic.d.ts +0 -7
- package/dist/tools/Deterministic.d.ts.map +0 -1
- package/dist/tools/Deterministic.js +0 -107
- package/dist/tools/Deterministic.js.map +0 -1
- package/dist/tools/clock.d.ts +0 -3
- package/dist/tools/clock.d.ts.map +0 -1
- package/dist/tools/clock.js +0 -11
- package/dist/tools/clock.js.map +0 -1
- package/dist/tools/random.d.ts +0 -3
- package/dist/tools/random.d.ts.map +0 -1
- package/dist/tools/random.js +0 -29
- package/dist/tools/random.js.map +0 -1
|
@@ -36,8 +36,7 @@ Node `>=22`. Schemas use TypeBox (`typebox`). See [README.md](../../../README.md
|
|
|
36
36
|
|
|
37
37
|
- **Workflow** — an orchestration entrypoint: a plain async function wrapped in `new Workflow(...)`. It coordinates steps; it does not implement the steps.
|
|
38
38
|
- **App** — registers workflows so the runtime can discover and run them.
|
|
39
|
-
- **Replay & determinism** — the runtime re-
|
|
40
|
-
- **Time & randomness** — inside a workflow, `Date.now()`, `new Date()`, `Math.random()` and `crypto.randomUUID()` are deterministic and safe to use. The clock follows the history: it starts when the run was created and only moves forward as steps are recorded (a step's request time, or the moment an awaited step settled), so it stands still between two steps. Randomness is seeded by the run id. `setTimeout`/`setInterval` throw `TimerNotAllowedException` — use `sleep` to wait.
|
|
39
|
+
- **Replay & determinism** — the runtime may re-run a workflow from its recorded history. Keep the body deterministic: branch on inputs and on the results of the steps you call, never on `Date.now()`, `Math.random()`, or ambient state. Use framework primitives (e.g. `sleep`) when you need time to pass.
|
|
41
40
|
- **env** — configuration values supplied by the runtime; the single source for URLs, tokens, and tenants.
|
|
42
41
|
- **Composition** — external work is performed by calling primitives from the other framework packages inside the workflow body.
|
|
43
42
|
|
|
@@ -168,7 +167,7 @@ const output = await env.execute(workflow, input, {
|
|
|
168
167
|
|
|
169
168
|
| Option | Default | Purpose |
|
|
170
169
|
|--------|---------|---------|
|
|
171
|
-
| `now` | `0` |
|
|
170
|
+
| `now` | `0` | Pins `Date.now()` to this value at run start |
|
|
172
171
|
| `resolveActivityTimeouts` | `true` | Auto-advances the clock through time-based steps (e.g. `sleep`) and resolves them |
|
|
173
172
|
|
|
174
173
|
`execute()` options:
|
|
@@ -202,8 +201,7 @@ Do **not** import `@t4h.framework/core/testing` in production app code.
|
|
|
202
201
|
- Reading `process.env` directly, or reading the raw `env` proxy when the project should declare an `EnvDesign` in `constants/environments.ts`.
|
|
203
202
|
- Inlining URLs/secrets/tenants in workflow code instead of pulling them from the shared `EnvDesign`.
|
|
204
203
|
- Accessing an `EnvDesign` key at module top level (throws — no env storage outside a run); read keys inside the workflow body/functions.
|
|
205
|
-
-
|
|
206
|
-
- Branching on ambient state (`process.env`, module-level mutable variables) or measuring elapsed time between steps — the workflow clock stands still between steps, so such measurements are always `0`.
|
|
204
|
+
- Non-deterministic workflow bodies (`Date.now()`, `Math.random()`, ambient state) — they break replay.
|
|
207
205
|
- Non-`Serializable` workflow input, output, or step values.
|
|
208
206
|
- Duplicate `workflow.id` within an `App`.
|
|
209
207
|
- Importing `@t4h.framework/core/testing` from production code.
|
|
@@ -213,8 +211,8 @@ Do **not** import `@t4h.framework/core/testing` in production app code.
|
|
|
213
211
|
|
|
214
212
|
## Exports
|
|
215
213
|
|
|
216
|
-
**Main (`@t4h.framework/core`):** `Workflow`, `App`, `startWorkflow`, `WorkflowRef`, `env`, `EnvDesign`, `Authorization`, `Binary`, `Serializable
|
|
214
|
+
**Main (`@t4h.framework/core`):** `Workflow`, `App`, `startWorkflow`, `WorkflowRef`, `env`, `EnvDesign`, `Authorization`, `Binary`, `Serializable`.
|
|
217
215
|
|
|
218
216
|
**Testing (`@t4h.framework/core/testing`):** `TestWorkflowEnvironment`, `TestClock`, `createTestEnv`, `createTestEnvEntries`, `NonDeterministicWorkflowError`.
|
|
219
217
|
|
|
220
|
-
> Core also exports lower-level building blocks used to **author framework packages** themselves. Those are out of scope for building workflows and are not covered here — reach for the primitives above and the companion packages instead.
|
|
218
|
+
> Core also exports lower-level building blocks used to **author framework packages** and **hosts** themselves (e.g. the `AsyncActivityCallback` namespace with the callbacks route helpers `deriveToken`, `isTokenValid`, `authorize`, `parseBody`, `toEvent`, `flattenHeaders`; `pending({ correlationKey })` plus the optional `toCorrelationKey(event)` on `AsyncActivity` for third parties that emit to a fixed URL). Those are out of scope for building workflows and are not covered here — reach for the primitives above and the companion packages instead.
|
|
@@ -39,7 +39,7 @@ Create workflows that:
|
|
|
39
39
|
| Configuration | `environments.MY_KEY` from a shared `EnvDesign` | `@t4h.framework/core` |
|
|
40
40
|
| Branching / mapping | plain TypeScript | — |
|
|
41
41
|
|
|
42
|
-
Keep the body **deterministic** so it replays safely: branch on inputs and step results, never on
|
|
42
|
+
Keep the body **deterministic** so it replays safely: branch on inputs and step results, never on `Date.now()`, `Math.random()`, or ambient state. Use `sleep` when you need time to pass.
|
|
43
43
|
|
|
44
44
|
## Expected project shape
|
|
45
45
|
|
|
@@ -106,7 +106,7 @@ One `environments` object is the single source of configuration for the whole pr
|
|
|
106
106
|
3. Define workflow metadata with a stable `id`.
|
|
107
107
|
4. Add a `schema` when input validation is needed.
|
|
108
108
|
5. Import all configuration from the shared `EnvDesign` in `constants/environments.ts` — never raw `env` or `process.env`.
|
|
109
|
-
6. Keep the body deterministic so replay produces the same result.
|
|
109
|
+
6. Keep the body deterministic so replay produces the same result.
|
|
110
110
|
7. Obtain a `Binary` from the framework — an HTTP response body, `sftp.get`, `write`, `join` — never by implementing one.
|
|
111
111
|
|
|
112
112
|
## Hard constraints
|
|
@@ -114,9 +114,7 @@ One `environments` object is the single source of configuration for the whole pr
|
|
|
114
114
|
- Do not hardcode URLs, client IDs, client secrets, API keys, tenants, or tokens.
|
|
115
115
|
- Do not initialize third-party clients with inline credentials inside workflow files.
|
|
116
116
|
- Do not read `process.env` or the raw `env` proxy directly — declare configuration in the shared `EnvDesign` (`constants/environments.ts`).
|
|
117
|
-
- Do not call `fetch`/`axios` or other non-framework I/O directly — that breaks replay safety
|
|
118
|
-
- Do not call `setTimeout` / `setInterval` inside a workflow — it throws `TimerNotAllowedException`. Wait with `sleep` from `@t4h.framework/sleep`.
|
|
119
|
-
- Do not measure elapsed time between steps with `Date.now()` — the workflow clock only moves when a step is recorded, so the difference is always `0`.
|
|
117
|
+
- Do not call `fetch`/`axios` or other non-framework I/O directly — that breaks replay safety.
|
|
120
118
|
- **Do not declare a class that extends `Binary`** (`BufferBinary`, `StringBinary`, `stringToBinary` helpers, …). To hand content to a primitive that takes a `Binary` — `sftp.put`, `sftp.append`, an HTTP body — build it with `write` from `@t4h.framework/fs`:
|
|
121
119
|
|
|
122
120
|
```ts
|
|
@@ -153,7 +151,7 @@ Required keys declared in the `EnvDesign` fail fast automatically: accessing an
|
|
|
153
151
|
|
|
154
152
|
### Step 4: make it test-friendly
|
|
155
153
|
|
|
156
|
-
- Keep outputs deterministic
|
|
154
|
+
- Keep outputs deterministic.
|
|
157
155
|
- Avoid hidden global state.
|
|
158
156
|
- Drive external effects through package primitives so tests can supply their providers (see **framework-core** testing and each package's skill).
|
|
159
157
|
|
|
@@ -66,7 +66,7 @@ env.clock.set(now) // set pinned clock to a Date | number
|
|
|
66
66
|
|
|
67
67
|
| Option | Default | Purpose |
|
|
68
68
|
|--------|---------|---------|
|
|
69
|
-
| `now` | `0` |
|
|
69
|
+
| `now` | `0` | Pins `Date.now()` to this value at start |
|
|
70
70
|
| `resolveActivityTimeouts` | `true` | Auto-advances clock to each activity's `timeoutAt` and resolves it via `onTimeout` |
|
|
71
71
|
|
|
72
72
|
`execute()` options:
|
|
@@ -80,14 +80,6 @@ env.clock.set(now) // set pinned clock to a Date | number
|
|
|
80
80
|
After `execute()` returns, the clock is advanced to wherever the run left it.
|
|
81
81
|
Subsequent `env.clock.advance()` calls build on that value between tests.
|
|
82
82
|
|
|
83
|
-
Inside the workflow, `Date.now()` is the history clock, not the virtual clock
|
|
84
|
-
directly: it equals `now` until the first step is recorded, then moves to each
|
|
85
|
-
step's stamp (request time, or settle time for an awaited async step). It never
|
|
86
|
-
moves backwards and stands still between steps. `Math.random()` and
|
|
87
|
-
`crypto.randomUUID()` are seeded by the run and replay identically, so asserting
|
|
88
|
-
on them is safe. A workflow that calls `setTimeout` / `setInterval` rejects with
|
|
89
|
-
`TimerNotAllowedException`.
|
|
90
|
-
|
|
91
83
|
Async activities are resolved in tests through `mockAsyncActivity` (which returns
|
|
92
84
|
a final outcome directly). Workflow tests never drive an activity's internal
|
|
93
85
|
`advance` method — you only assert the workflow's observable output and effects.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# @t4h.framework/core
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#167](https://github.com/tech4humans-brasil/framework/pull/167) [`1b1509f`](https://github.com/tech4humans-brasil/framework/commit/1b1509f9b6d2554dfab1f7633c3d022249e4fa01) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Lets a third party that emits to a fixed URL advance a waiting async activity,
|
|
8
|
+
without the callback URL the activity would otherwise hand out.
|
|
9
|
+
|
|
10
|
+
**core**: `pending({ correlationKey })` declares the key a wait answers to, and
|
|
11
|
+
the optional `toCorrelationKey(event)` on `AsyncActivity` maps an incoming event
|
|
12
|
+
(`AsyncActivityCallback.Event`: method, flattened headers, parsed body, raw body)
|
|
13
|
+
to that key, or `undefined` when the event is not for the activity. It runs on a
|
|
14
|
+
bare instance, outside any run. `AsyncActivityCallback.toEvent(request)` builds
|
|
15
|
+
the event for hosts.
|
|
16
|
+
|
|
17
|
+
**dev**: new public route `POST /projects/:projectId/workflows/:workflowId/events`.
|
|
18
|
+
Every registered activity implementing `toCorrelationKey` is asked for a key;
|
|
19
|
+
the pending of that type waiting on the key inside the workflow has its `auth`
|
|
20
|
+
verified and receives the event as a callback, through the same path as the
|
|
21
|
+
callback URL route. Answers `202 { id, activity }` with the stored callback,
|
|
22
|
+
`202` with an empty body when no activity claims the event or nothing is
|
|
23
|
+
waiting, `401` when the matched pending refused the auth, and `409` when the key
|
|
24
|
+
matches more than one pending, since a correlation key must identify one wait.
|
|
25
|
+
|
|
26
|
+
- [#167](https://github.com/tech4humans-brasil/framework/pull/167) [`1b1509f`](https://github.com/tech4humans-brasil/framework/commit/1b1509f9b6d2554dfab1f7633c3d022249e4fa01) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Moves the callbacks route helpers from `@t4h.framework/webhook` to
|
|
27
|
+
`@t4h.framework/core`. The route advances any pending async activity, not only
|
|
28
|
+
`webhook()`, and the core already owned its contract (`AsyncActivityCallbackAuth`,
|
|
29
|
+
`GetActivityCallbackUrlClaim`, `AsyncActivityAdvanceContext`).
|
|
30
|
+
|
|
31
|
+
**core**: new `AsyncActivityCallback` namespace with `deriveToken`, `isTokenValid`,
|
|
32
|
+
`parseBody`, `getHeader`, `getBearerToken`, `flattenHeaders`, `authorize` and
|
|
33
|
+
the types `AsyncActivityCallback.Delivery`, `AsyncActivityCallback.Headers`, `AsyncActivityCallback.Json`,
|
|
34
|
+
`AsyncActivityCallback.AuthType`, `AsyncActivityCallback.Authorizer`, `AsyncActivityCallback.Authorizers`.
|
|
35
|
+
`AsyncActivityCallback.authorize(auth, request, authorizers?)` ships `basic`, `header` and
|
|
36
|
+
`bearer`; `hmac` and `jwt` are authorizers the host passes in, so the core does not
|
|
37
|
+
depend on `@t4h.framework/hmac` or `@t4h.framework/jwks`. A declared type without
|
|
38
|
+
a authorizer throws `AsyncActivityCallbackAuthorizerMissingException`; an unknown type throws
|
|
39
|
+
`AsyncActivityCallbackAuthUnsupportedException`.
|
|
40
|
+
|
|
41
|
+
**hmac**: new `@t4h.framework/hmac/callback` entry whose default export is the
|
|
42
|
+
`hmac` callback authorizer, `hmacCallback`.
|
|
43
|
+
|
|
44
|
+
**jwks**: new `@t4h.framework/jwks/callback` entry whose default export is the
|
|
45
|
+
`jwt` callback authorizer, `jwksCallback`.
|
|
46
|
+
|
|
47
|
+
**webhook**: no longer exports `deriveCallbackToken`, `isCallbackTokenValid`,
|
|
48
|
+
`verifyCallbackAuth`, `parseCallbackBody`, `getHeader`, `flattenHeaders` nor
|
|
49
|
+
`CallbackRequest`/`CallbackHeaders`, and no longer depends on `hmac` and `jwks`;
|
|
50
|
+
`WebhookJson` is now an alias of the core `AsyncActivityCallback.Json`. Hosts import the
|
|
51
|
+
helpers from the core `AsyncActivityCallback` namespace and the authorizers from the two entries.
|
|
52
|
+
|
|
53
|
+
**dev**: `@t4h.framework/webhook` becomes an optional peer like the other
|
|
54
|
+
integrations. Only `@t4h.framework/core` is required again, which fixes
|
|
55
|
+
`ERR_MODULE_NOT_FOUND: Cannot find package '@t4h.framework/webhook'` on
|
|
56
|
+
projects that never call `webhook()`. `hmac` and `jwt` callback authorizers are
|
|
57
|
+
loaded from the project when `@t4h.framework/hmac` / `@t4h.framework/jwks` are
|
|
58
|
+
installed; a callback whose declared `auth` needs a missing package answers 500
|
|
59
|
+
naming the package to install.
|
|
60
|
+
|
|
61
|
+
## 0.12.0
|
|
62
|
+
|
|
63
|
+
### Minor Changes
|
|
64
|
+
|
|
65
|
+
- [#165](https://github.com/tech4humans-brasil/framework/pull/165) [`72e08ff`](https://github.com/tech4humans-brasil/framework/commit/72e08ff86e0ce735ef73ccdf33b0dc01cdb8b6f5) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Revert deterministic time, randomness and timers in workflow code ([#155](https://github.com/tech4humans-brasil/framework/issues/155)).
|
|
66
|
+
- `Date`, `Math.random`, `crypto.randomUUID` and the timer functions are no longer patched. Workflow code must not call `Date.now()` / `Math.random()`; wait with `@t4h.framework/sleep`.
|
|
67
|
+
- `TimerNotAllowedException` is removed.
|
|
68
|
+
- **Hosts:** `Internals.runWorkflow` no longer takes `id` / `createdAt`, and `HistoryItem` no longer carries `createdAt` / `settledAt`.
|
|
69
|
+
- Testing: `runWorkflow` no longer accepts or returns `seed` / `createdAt`; `TestClock` patches `Date` itself again.
|
|
70
|
+
|
|
3
71
|
## 0.11.0
|
|
4
72
|
|
|
5
73
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -256,6 +256,83 @@ class WaitForApprovalActivity extends AsyncActivity<
|
|
|
256
256
|
}
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
+
### Callbacks (host side)
|
|
260
|
+
|
|
261
|
+
Every pending async activity can be advanced from outside through the host's
|
|
262
|
+
callbacks route (`POST .../activities/:activityId/callbacks?token=…`). The
|
|
263
|
+
route is the host's, but the pieces are core exports so every host behaves the
|
|
264
|
+
same:
|
|
265
|
+
|
|
266
|
+
| Export | What it's for |
|
|
267
|
+
| ------------------------------------------------ | ----------------------------------------------------------------------------- |
|
|
268
|
+
| `AsyncActivityCallback.deriveToken` | `HMAC-SHA256(secret, activityId)` as base64url: the token of a callback URL. |
|
|
269
|
+
| `AsyncActivityCallback.isTokenValid` | Constant-time check of a token against the derived one. |
|
|
270
|
+
| `AsyncActivityCallback.authorize` | Checks a delivery against the `auth` declared in `pending({ auth })`. |
|
|
271
|
+
| `AsyncActivityCallback.parseBody` | Turns content type + raw body into the payload `advance` receives. |
|
|
272
|
+
| `AsyncActivityCallback.getHeader` / `AsyncActivityCallback.flattenHeaders` | Case-insensitive lookup; lower-cased, joined headers for the advance context. |
|
|
273
|
+
| `GetActivityCallbackUrlClaim` | The claim an activity uses to learn its own callback URL. |
|
|
274
|
+
|
|
275
|
+
The namespace also carries the types `AsyncActivityCallback.Delivery`, `AsyncActivityCallback.Headers`,
|
|
276
|
+
`AsyncActivityCallback.Json`, `AsyncActivityCallback.Authorizer` and `AsyncActivityCallback.Authorizers`.
|
|
277
|
+
|
|
278
|
+
`AsyncActivityCallback.authorize` ships `basic`, `header` and `bearer`. `hmac` and `jwt`
|
|
279
|
+
are authorizers the host passes in, so the core never depends on the packages
|
|
280
|
+
that implement them:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { AsyncActivityCallback } from '@t4h.framework/core'
|
|
284
|
+
import hmac from '@t4h.framework/hmac/callback'
|
|
285
|
+
import jwt from '@t4h.framework/jwks/callback'
|
|
286
|
+
|
|
287
|
+
const ok = await AsyncActivityCallback.authorize(
|
|
288
|
+
pending.auth,
|
|
289
|
+
{ method, headers, rawBody },
|
|
290
|
+
{ hmac, jwt },
|
|
291
|
+
)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
A declared type without a authorizer throws `AsyncActivityCallbackAuthorizerMissingException`.
|
|
295
|
+
|
|
296
|
+
### Correlating events from a fixed URL
|
|
297
|
+
|
|
298
|
+
Some third parties cannot call a URL handed to them per request: they emit
|
|
299
|
+
every event to one URL configured on their side. For those, the host exposes a
|
|
300
|
+
fixed events route per workflow (`POST .../projects/:projectId/workflows/:workflowId/events`)
|
|
301
|
+
and the activity tells the host how to match an event to a wait:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
class TransferTicketActivity extends AsyncActivity<...> {
|
|
305
|
+
public async bootstrap(input: { ticketId: string }) {
|
|
306
|
+
// ...asks the partner to transfer the ticket...
|
|
307
|
+
return this.pending({
|
|
308
|
+
schema,
|
|
309
|
+
correlationKey: input.ticketId,
|
|
310
|
+
auth: { type: 'hmac', secret: input.secret, header: 'x-signature' },
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public override toCorrelationKey(event: AsyncActivityCallback.Event) {
|
|
315
|
+
const body = event.body as { type?: string; ticket?: { id?: string } }
|
|
316
|
+
|
|
317
|
+
if (body?.type !== 'ticket.transferred') return undefined
|
|
318
|
+
|
|
319
|
+
return body.ticket?.id
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// toInput, advance, toOutput as usual
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
On every event the host calls `toCorrelationKey` on each registered activity
|
|
327
|
+
that implements it, then looks up the pending of that activity type waiting on
|
|
328
|
+
the returned key inside the workflow, verifies its `auth` and delivers the
|
|
329
|
+
event as a callback, exactly as the callback URL route would. An event no
|
|
330
|
+
activity claims, or that nothing is waiting for, is accepted and dropped. A key
|
|
331
|
+
must identify one wait: when it matches more than one pending the host refuses
|
|
332
|
+
the event (409) and delivers to none, so compose the key (`ticketId:transferId`)
|
|
333
|
+
when one external id can have several waits. `toCorrelationKey` runs on a bare
|
|
334
|
+
instance, outside any run: no claims, no history, only the event.
|
|
335
|
+
|
|
259
336
|
### Activities with Claims (dependencies)
|
|
260
337
|
|
|
261
338
|
A Claim is an abstract dependency that an Activity declares. For example, an activity that saves files declares it needs a "file storage" claim -- it doesn't know whether the implementation uses S3, local disk, or anything else. The runtime must provide a concrete implementation for each declared claim via `ClaimProvider`. This decouples the activity definition from the infrastructure.
|
|
@@ -302,8 +379,6 @@ The runtime is responsible for executing workflows and activities by providing t
|
|
|
302
379
|
import { Internals } from '@t4h.framework/core'
|
|
303
380
|
|
|
304
381
|
Internals.runWorkflow(myWorkflow, {
|
|
305
|
-
id: run.id, // seeds Math.random / randomUUID inside the workflow
|
|
306
|
-
createdAt: run.createdAt.getTime(), // where the workflow clock starts
|
|
307
382
|
input: { userId: '123', amount: 100 },
|
|
308
383
|
env: { API_URL: 'https://api.example.com' },
|
|
309
384
|
claims: [
|
|
@@ -346,8 +421,6 @@ Env.run → Claim.run → fn(activity)
|
|
|
346
421
|
|
|
347
422
|
**History** handles reconciliation: when an activity has been executed before, the previous result is returned directly (deterministic replay). When there is no history, the activity runs and the result is stored.
|
|
348
423
|
|
|
349
|
-
**History** also owns the workflow clock. Each `HistoryItem` carries `createdAt` (when the activity was requested) and async items `settledAt` (when they settled); `Date.now()` inside the workflow reads the last of those the replay walked past, starting from the run's `createdAt`. `History.run` also patches `Date`, `Math.random` and `randomUUID` for workflow code and forbids `setTimeout` / `setInterval` there (`TimerNotAllowedException`). Hosts must stamp those fields when building the history.
|
|
350
|
-
|
|
351
424
|
---
|
|
352
425
|
|
|
353
426
|
## Testing
|
|
@@ -482,10 +555,6 @@ await TestClock.run({ now: 0 }, async () => {
|
|
|
482
555
|
})
|
|
483
556
|
```
|
|
484
557
|
|
|
485
|
-
`TestClock` acts as the host clock: activities are stamped with it and the
|
|
486
|
-
workflow reads those stamps back through `Date.now()`, exactly as in
|
|
487
|
-
production.
|
|
488
|
-
|
|
489
558
|
### Activity-level tests
|
|
490
559
|
|
|
491
560
|
The real `advance` logic is intentionally **not** exercised by `execute()`.
|
package/dist/core.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './activities/StartWorkflowActivity.js';
|
|
2
2
|
export * from './exceptions/ActivityException.js';
|
|
3
|
+
export * from './exceptions/AsyncActivityCallbackException.js';
|
|
3
4
|
export * from './exceptions/ClaimException.js';
|
|
4
|
-
export * from './exceptions/TimerNotAllowedException.js';
|
|
5
5
|
export * from './models/Activity.js';
|
|
6
6
|
export * from './models/Authorization.js';
|
|
7
7
|
export * from './models/App.js';
|
|
@@ -23,6 +23,7 @@ export * from './models/Workflow.js';
|
|
|
23
23
|
export * from './models/WorkflowBatchClaim.js';
|
|
24
24
|
export * from './models/WorkflowBatchRef.js';
|
|
25
25
|
export * from './models/WorkflowRef.js';
|
|
26
|
+
export * from './tools/AsyncActivityCallback.js';
|
|
26
27
|
export * from './tools/Internals.js';
|
|
27
28
|
export * from './typings/PromiseLikeType.js';
|
|
28
29
|
export * from './typings/Serializable.js';
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AAErD,cAAc,mCAAmC,CAAA;AACjD,cAAc,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AAErD,cAAc,mCAAmC,CAAA;AACjD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,gCAAgC,CAAA;AAE9C,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA;AACzC,cAAc,wCAAwC,CAAA;AACtD,cAAc,oCAAoC,CAAA;AAClD,cAAc,oBAAoB,CAAA;AAClC,cAAc,uCAAuC,CAAA;AACrD,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,yBAAyB,CAAA;AAEvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,sBAAsB,CAAA;AAEpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
|
package/dist/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './activities/StartWorkflowActivity.js';
|
|
2
2
|
export * from './exceptions/ActivityException.js';
|
|
3
|
+
export * from './exceptions/AsyncActivityCallbackException.js';
|
|
3
4
|
export * from './exceptions/ClaimException.js';
|
|
4
|
-
export * from './exceptions/TimerNotAllowedException.js';
|
|
5
5
|
export * from './models/Activity.js';
|
|
6
6
|
export * from './models/Authorization.js';
|
|
7
7
|
export * from './models/App.js';
|
|
@@ -23,6 +23,7 @@ export * from './models/Workflow.js';
|
|
|
23
23
|
export * from './models/WorkflowBatchClaim.js';
|
|
24
24
|
export * from './models/WorkflowBatchRef.js';
|
|
25
25
|
export * from './models/WorkflowRef.js';
|
|
26
|
+
export * from './tools/AsyncActivityCallback.js';
|
|
26
27
|
export * from './tools/Internals.js';
|
|
27
28
|
export * from './typings/PromiseLikeType.js';
|
|
28
29
|
export * from './typings/Serializable.js';
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AAErD,cAAc,mCAAmC,CAAA;AACjD,cAAc,
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AAErD,cAAc,mCAAmC,CAAA;AACjD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,gCAAgC,CAAA;AAE9C,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA;AACzC,cAAc,wCAAwC,CAAA;AACtD,cAAc,oCAAoC,CAAA;AAClD,cAAc,oBAAoB,CAAA;AAClC,cAAc,uCAAuC,CAAA;AACrD,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,yBAAyB,CAAA;AAEvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,sBAAsB,CAAA;AAEpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AsyncActivityCallbackAuth } from '../models/AsyncActivityCallbackAuth.js';
|
|
2
|
+
export declare class AsyncActivityCallbackException extends Error {
|
|
3
|
+
constructor(message: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare class AsyncActivityCallbackAuthorizerMissingException extends AsyncActivityCallbackException {
|
|
6
|
+
readonly type: AsyncActivityCallbackAuth['type'];
|
|
7
|
+
constructor(type: AsyncActivityCallbackAuth['type']);
|
|
8
|
+
}
|
|
9
|
+
export declare class AsyncActivityCallbackAuthUnsupportedException extends AsyncActivityCallbackException {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
constructor(type: string);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=AsyncActivityCallbackException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncActivityCallbackException.d.ts","sourceRoot":"","sources":["../../src/exceptions/AsyncActivityCallbackException.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAA;AAEvF,qBAAa,8BAA+B,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAG3D;AAED,qBAAa,+CAAgD,SAAQ,8BAA8B;IACjG,SAAgB,IAAI,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;gBAEpC,IAAI,EAAE,yBAAyB,CAAC,MAAM,CAAC;CAI3D;AAED,qBAAa,6CAA8C,SAAQ,8BAA8B;IAC/F,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAET,IAAI,EAAE,MAAM;CAIhC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class AsyncActivityCallbackException extends Error {
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message, options);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export class AsyncActivityCallbackAuthorizerMissingException extends AsyncActivityCallbackException {
|
|
7
|
+
type;
|
|
8
|
+
constructor(type) {
|
|
9
|
+
super(`No authorizer registered for callback auth type "${type}"`);
|
|
10
|
+
this.type = type;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class AsyncActivityCallbackAuthUnsupportedException extends AsyncActivityCallbackException {
|
|
14
|
+
type;
|
|
15
|
+
constructor(type) {
|
|
16
|
+
super(`Unsupported callback auth type: ${type}`);
|
|
17
|
+
this.type = type;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=AsyncActivityCallbackException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncActivityCallbackException.js","sourceRoot":"","sources":["../../src/exceptions/AsyncActivityCallbackException.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD,YAAmB,OAAe,EAAE,OAAsB;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC;CACF;AAED,MAAM,OAAO,+CAAgD,SAAQ,8BAA8B;IACjF,IAAI,CAAmC;IAEvD,YAAmB,IAAuC;QACxD,KAAK,CAAC,oDAAoD,IAAI,GAAG,CAAC,CAAA;QAClE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,MAAM,OAAO,6CAA8C,SAAQ,8BAA8B;IAC/E,IAAI,CAAQ;IAE5B,YAAmB,IAAY;QAC7B,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAA;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -2,6 +2,7 @@ import type Type from 'typebox';
|
|
|
2
2
|
import { AsyncActivityResultFulfilled, AsyncActivityResultPending, AsyncActivityResultRejected, type AsyncActivityResult, type AsyncActivityResultPendingOptions } from './AsyncActivityAdvanceResult.js';
|
|
3
3
|
import { AsyncActivityAwaitable } from './AsyncActivityAwaitable.js';
|
|
4
4
|
import type { IHistoryItemAsync } from './History.js';
|
|
5
|
+
import type { AsyncActivityCallback } from '../tools/AsyncActivityCallback.js';
|
|
5
6
|
import type { Serializable } from '../typings/Serializable.js';
|
|
6
7
|
export type AsyncActivityAdvanceContext = {
|
|
7
8
|
method: string;
|
|
@@ -14,6 +15,7 @@ export declare abstract class AsyncActivity<TArgs extends readonly any[], TInput
|
|
|
14
15
|
abstract bootstrap(input: TInput): AsyncActivityResult<TBootstrap, TSchema, TSerializableOutput> | Promise<AsyncActivityResult<TBootstrap, TSchema, TSerializableOutput>>;
|
|
15
16
|
abstract advance(payload: Type.Static<TSchema>, bootstrap: AsyncActivityResultPending, context?: AsyncActivityAdvanceContext): AsyncActivityResult<Serializable, TSchema, TSerializableOutput> | Promise<AsyncActivityResult<Serializable, TSchema, TSerializableOutput>>;
|
|
16
17
|
abstract toOutput(output: TSerializableOutput, ...args: TArgs): TOutput;
|
|
18
|
+
toCorrelationKey?(event: AsyncActivityCallback.Event): string | undefined | Promise<string | undefined>;
|
|
17
19
|
onTimeout?(payload: AsyncActivityResultPending): AsyncActivityResult<Serializable, TSchema, TSerializableOutput> | Promise<AsyncActivityResult<Serializable, TSchema, TSerializableOutput>>;
|
|
18
20
|
protected pending(options?: AsyncActivityResultPendingOptions<TBootstrap, TSchema>): AsyncActivityResultPending<TBootstrap, TSchema>;
|
|
19
21
|
protected done(payload?: TSerializableOutput): AsyncActivityResultFulfilled<TSerializableOutput | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivity.d.ts","sourceRoot":"","sources":["../../src/models/AsyncActivity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAE/B,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,KAAK,iCAAiC,EACvC,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAC1C,SAAS,GAAG,EAAE,EACd,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACJ,CAAA;AAED,8BAAsB,aAAa,CACjC,KAAK,SAAS,SAAS,GAAG,EAAE,EAC5B,MAAM,SAAS,YAAY,EAC3B,mBAAmB,SAAS,YAAY,GAAG,IAAI,EAC/C,OAAO,EACP,UAAU,SAAS,YA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OAAO,EAAE,mBAAmB,CAAC,GAC/D,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAM5E,SAAS,CAAC,OAAO,CACf,OAAO,CAAC,EAAE,iCAAiC,CAAC,UAAU,EAAE,OAAO,CAAC;IAKlE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB;IAI5C,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI;IAIzC,WAAW,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE;CAGjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivity.js","sourceRoot":"","sources":["../../src/models/AsyncActivity.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAG5B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"AsyncActivity.js","sourceRoot":"","sources":["../../src/models/AsyncActivity.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAG5B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAmBpE,MAAM,OAAgB,aAAa;IAQ1B,EAAE,CAAS;IAuBX,SAAS;IACd,6DAA6D;IAC7D,OAAmC;QAInC,OAAO,IAAI,CAAC,QAAQ,CAAC;YACnB,MAAM,EAAE,SAAS;SAClB,CAAC,CAAA;IACJ,CAAC;IAES,OAAO,CACf,OAAgE;QAEhE,OAAO,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;IAES,IAAI,CAAC,OAA6B;QAC1C,OAAO,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;IAES,QAAQ,CAAC,OAA6B;QAC9C,OAAO,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAA;IACjD,CAAC;IAEM,WAAW,CAAC,IAAuB,EAAE,IAAoB;QAC9D,OAAO,IAAI,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACrD,CAAC;CACF"}
|
|
@@ -6,6 +6,7 @@ export interface AsyncActivityResultPendingOptions<TPayload extends Serializable
|
|
|
6
6
|
schema?: TSchema;
|
|
7
7
|
timeoutAt?: Date | undefined;
|
|
8
8
|
auth?: AsyncActivityCallbackAuth;
|
|
9
|
+
correlationKey?: string;
|
|
9
10
|
}
|
|
10
11
|
export type AsyncActivityResult<P extends Serializable, S extends Type.TSchema, O extends Serializable | void> = AsyncActivityResultPending<P, S> | AsyncActivityResultFulfilled<O> | AsyncActivityResultRejected<Serializable | void>;
|
|
11
12
|
export declare class AsyncActivityResultPending<TPayload extends Serializable = Serializable, TSchema extends Type.TSchema = Type.TSchema> {
|
|
@@ -13,7 +14,8 @@ export declare class AsyncActivityResultPending<TPayload extends Serializable =
|
|
|
13
14
|
readonly schema?: TSchema;
|
|
14
15
|
readonly timeoutAt?: Date | undefined;
|
|
15
16
|
readonly auth?: AsyncActivityCallbackAuth;
|
|
16
|
-
|
|
17
|
+
readonly correlationKey?: string;
|
|
18
|
+
constructor({ payload, schema, timeoutAt, auth, correlationKey, }?: AsyncActivityResultPendingOptions<TPayload, TSchema>);
|
|
17
19
|
}
|
|
18
20
|
export declare class AsyncActivityResultFulfilled<T extends Serializable | void = void> {
|
|
19
21
|
readonly payload: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivityAdvanceResult.d.ts","sourceRoot":"","sources":["../../src/models/AsyncActivityAdvanceResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAE/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E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S,YAAY,GAAG,YAAY,EAC5C,OAAO,SAAS,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO;IAE3C,SAAgB,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClC,SAAgB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChC,SAAgB,SAAS,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IAC5C,SAAgB,IAAI,CAAC,EAAE,yBAAyB,CAAA;IAChD,SAAgB,cAAc,CAAC,EAAE,MAAM,CAAA;gBAE3B,EACV,OAAO,EACP,MAAM,EACN,SAAS,EACT,IAAI,EACJ,cAAc,GACf,GAAE,iCAAiC,CAAC,QAAQ,EAAE,OAAO,CAAM;CAO7D;AAED,qBAAa,4BAA4B,CACvC,CAAC,SAAS,YAAY,GAAG,IAAI,GAAG,IAAI;aAER,OAAO,EAAE,CAAC;gBAAV,OAAO,EAAE,CAAC;CACvC;AAED,qBAAa,2BAA2B,CAAC,CAAC,SAAS,YAAY,GAAG,IAAI,GAAG,IAAI;aAC/C,OAAO,EAAE,CAAC;gBAAV,OAAO,EAAE,CAAC;CACvC"}
|
|
@@ -3,11 +3,13 @@ export class AsyncActivityResultPending {
|
|
|
3
3
|
schema;
|
|
4
4
|
timeoutAt;
|
|
5
5
|
auth;
|
|
6
|
-
|
|
6
|
+
correlationKey;
|
|
7
|
+
constructor({ payload, schema, timeoutAt, auth, correlationKey, } = {}) {
|
|
7
8
|
this.payload = payload;
|
|
8
9
|
this.schema = schema;
|
|
9
10
|
this.timeoutAt = timeoutAt;
|
|
10
11
|
this.auth = auth;
|
|
12
|
+
this.correlationKey = correlationKey;
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
export class AsyncActivityResultFulfilled {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivityAdvanceResult.js","sourceRoot":"","sources":["../../src/models/AsyncActivityAdvanceResult.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AsyncActivityAdvanceResult.js","sourceRoot":"","sources":["../../src/models/AsyncActivityAdvanceResult.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,0BAA0B;IAIrB,OAAO,CAAW;IAClB,MAAM,CAAU;IAChB,SAAS,CAAmB;IAC5B,IAAI,CAA4B;IAChC,cAAc,CAAS;IAEvC,YAAY,EACV,OAAO,EACP,MAAM,EACN,SAAS,EACT,IAAI,EACJ,cAAc,MAC0C,EAAE;QAC1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;CACF;AAED,MAAM,OAAO,4BAA4B;IAGX;IAA5B,YAA4B,OAAU;QAAV,YAAO,GAAP,OAAO,CAAG;IAAG,CAAC;CAC3C;AAED,MAAM,OAAO,2BAA2B;IACV;IAA5B,YAA4B,OAAU;QAAV,YAAO,GAAP,OAAO,CAAG;IAAG,CAAC;CAC3C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Activity } from './Activity.js';
|
|
2
2
|
import type { AnyAsyncActivity } from './AsyncActivity.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { IHistoryItemAsync } from './History.js';
|
|
4
4
|
export declare class AsyncActivityAwaitable<T extends AnyAsyncActivity> {
|
|
5
5
|
private readonly activity;
|
|
6
6
|
private readonly item;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivityAwaitable.d.ts","sourceRoot":"","sources":["../../src/models/AsyncActivityAwaitable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"AsyncActivityAwaitable.d.ts","sourceRoot":"","sources":["../../src/models/AsyncActivityAwaitable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGrD,qBAAa,sBAAsB,CAAC,CAAC,SAAS,gBAAgB;IAE1D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,QAAQ,EAAE,CAAC,EACX,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,SAAS,GAAG,EAAE;IAG1B,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAMjD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {} from './Activity.js';
|
|
2
|
-
import { History } from './History.js';
|
|
3
2
|
import { PushWaitAsyncActivity } from './PushWaitAsyncActivity.js';
|
|
4
3
|
export class AsyncActivityAwaitable {
|
|
5
4
|
activity;
|
|
@@ -13,7 +12,6 @@ export class AsyncActivityAwaitable {
|
|
|
13
12
|
async wait() {
|
|
14
13
|
if (this.item.status === 'pending')
|
|
15
14
|
throw new PushWaitAsyncActivity(this.activity, this.item.timeoutAt);
|
|
16
|
-
History.advanceClock(this.item.settledAt);
|
|
17
15
|
return this.activity.toOutput(this.item.output, ...this.args);
|
|
18
16
|
}
|
|
19
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncActivityAwaitable.js","sourceRoot":"","sources":["../../src/models/AsyncActivityAwaitable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"AsyncActivityAwaitable.js","sourceRoot":"","sources":["../../src/models/AsyncActivityAwaitable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,eAAe,CAAA;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE,MAAM,OAAO,sBAAsB;IAEd;IACA;IACA;IAHnB,YACmB,QAAW,EACX,IAAuB,EACvB,IAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAG;QACX,SAAI,GAAJ,IAAI,CAAmB;QACvB,SAAI,GAAJ,IAAI,CAAgB;IACpC,CAAC;IAEG,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;YAChC,MAAM,IAAI,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAErE,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
package/dist/models/History.d.ts
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
import { type Activity } from './Activity.js';
|
|
2
2
|
import { type AnyAsyncActivity } from './AsyncActivity.js';
|
|
3
|
-
import
|
|
3
|
+
import { AsyncActivityAwaitable } from './AsyncActivityAwaitable.js';
|
|
4
4
|
export type HistoryItemType = 'sync' | 'async';
|
|
5
5
|
interface IHistoryItem<T extends HistoryItemType> {
|
|
6
6
|
id: string;
|
|
7
7
|
type: T;
|
|
8
8
|
output: any;
|
|
9
|
-
createdAt: number;
|
|
10
9
|
}
|
|
11
10
|
export interface IHistoryItemSync extends IHistoryItem<'sync'> {
|
|
12
11
|
}
|
|
13
12
|
export interface IHistoryItemAsync extends IHistoryItem<'async'> {
|
|
14
13
|
status: 'pending' | 'fulfilled' | 'rejected';
|
|
15
14
|
timeoutAt?: Date | null;
|
|
16
|
-
settledAt?: number;
|
|
17
15
|
}
|
|
18
16
|
export type HistoryItem = IHistoryItemSync | IHistoryItemAsync;
|
|
19
|
-
export interface HistoryRunOptions {
|
|
20
|
-
history: readonly HistoryItem[];
|
|
21
|
-
seed: string;
|
|
22
|
-
createdAt: number;
|
|
23
|
-
}
|
|
24
|
-
export interface HistoryStore {
|
|
25
|
-
readonly items: HistoryItem[];
|
|
26
|
-
readonly seed: string;
|
|
27
|
-
clock: number;
|
|
28
|
-
randomCalls: number;
|
|
29
|
-
}
|
|
30
17
|
export declare namespace History {
|
|
31
18
|
type ReconcilerOutput<T extends Activity> = T extends AnyAsyncActivity ? AsyncActivityAwaitable<T> : Activity.Output<T>;
|
|
32
19
|
function bind<T extends Activity>(Activity: new () => T): (...args: Activity.Args<T>) => Promise<ReconcilerOutput<T>>;
|
|
33
20
|
function reconciler<T extends Activity>(Activity: new () => T, ...args: Activity.Args<T>): Promise<ReconcilerOutput<T>>;
|
|
34
21
|
function isReplaying(): boolean;
|
|
35
|
-
function
|
|
36
|
-
function advanceClock(at: number | undefined): void;
|
|
37
|
-
function run<T>(options: HistoryRunOptions, fn: () => T): T;
|
|
22
|
+
function run<T>(history: readonly HistoryItem[], fn: () => T): T;
|
|
38
23
|
}
|
|
39
24
|
export {};
|
|
40
25
|
//# sourceMappingURL=History.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"History.d.ts","sourceRoot":"","sources":["../../src/models/History.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"History.d.ts","sourceRoot":"","sources":["../../src/models/History.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,sBAAsB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