@iworkflow/temporal 0.6.0 → 0.6.1
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/README.md +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -3
- package/package.json +3 -2
- package/src/index.ts +5 -2
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@ Temporal для `@iworkflow/core`. Peer: `@temporalio/{client,common,worker,work
|
|
|
11
11
|
- `temporalActivities(activities)` — шаги порта для своего `Worker.create` (слив старой очереди, тестовый
|
|
12
12
|
воркер): `Failure` → `ApplicationFailure`, работают `heartbeat` и `stepAttempt`. Шаги без неё
|
|
13
13
|
в своём воркере `heartbeat`/`stepAttempt` не видят — с 0.6.0 рантайм шага ставится на время шага.
|
|
14
|
+
- `temporalStep(fn)` — тест шага без воркера: `new MockActivityEnvironment().run(() => temporalStep(() => acts.send(x)))`;
|
|
15
|
+
`acts` — сырые шаги (не результат `temporalActivities`), отказ остаётся `Failure`; `@temporalio/testing` ставит сам модуль.
|
|
14
16
|
- `@iworkflow/temporal/workflow` — только для входа песочницы модуля:
|
|
15
17
|
`export const outreach = temporalFlow(flows.outreach, ["send-twice"])`.
|
|
16
18
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Activity, type EngineClient, type EngineRuntime } from "@iworkflow/core";
|
|
2
2
|
import { type TemporalOptions } from "./connection";
|
|
3
3
|
export type { TemporalOptions };
|
|
4
|
+
/** Один вызов шага в рантайме Temporal без обёртки отказов — для тестов в MockActivityEnvironment. */
|
|
5
|
+
export declare const temporalStep: <T>(fn: () => T) => T;
|
|
4
6
|
/**
|
|
5
7
|
* Шаги порта для своего Worker.create (слив старой очереди, тестовый воркер): Failure доезжает
|
|
6
8
|
* как ApplicationFailure, heartbeat и stepAttempt работают. temporalRuntime делает это сам.
|
package/dist/index.js
CHANGED
|
@@ -142,13 +142,13 @@ var TEMPORAL_STEP = {
|
|
|
142
142
|
lastHeartbeat: async () => Context.current().info.heartbeatDetails,
|
|
143
143
|
attempt: () => Context.current().info.attempt
|
|
144
144
|
};
|
|
145
|
+
var temporalStep = (fn) => stepScope(alsScope).run(TEMPORAL_STEP, fn);
|
|
145
146
|
function temporalActivities(activities) {
|
|
146
|
-
const scope = stepScope(alsScope);
|
|
147
147
|
return Object.fromEntries(Object.entries(activities).map(([name, fn]) => [
|
|
148
148
|
name,
|
|
149
149
|
async (...args) => {
|
|
150
150
|
try {
|
|
151
|
-
return await
|
|
151
|
+
return await temporalStep(() => fn(...args));
|
|
152
152
|
} catch (e) {
|
|
153
153
|
throw toTemporal(e, false);
|
|
154
154
|
}
|
|
@@ -286,5 +286,6 @@ async function temporalClient(opts = {}) {
|
|
|
286
286
|
export {
|
|
287
287
|
temporalActivities,
|
|
288
288
|
temporalClient,
|
|
289
|
-
temporalRuntime
|
|
289
|
+
temporalRuntime,
|
|
290
|
+
temporalStep
|
|
290
291
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iworkflow/temporal",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Temporal adapter for @iworkflow/core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"workflow",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prepack": "bun run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@iworkflow/core": "^0.6.
|
|
44
|
+
"@iworkflow/core": "^0.6.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@temporalio/activity": "^1.24.0",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@temporalio/activity": "^1.24.0",
|
|
55
55
|
"@temporalio/client": "^1.24.0",
|
|
56
56
|
"@temporalio/common": "^1.24.0",
|
|
57
|
+
"@temporalio/testing": "^1.24.0",
|
|
57
58
|
"@temporalio/worker": "^1.24.0",
|
|
58
59
|
"@temporalio/workflow": "^1.24.0"
|
|
59
60
|
},
|
package/src/index.ts
CHANGED
|
@@ -79,18 +79,21 @@ const TEMPORAL_STEP: StepRuntime = {
|
|
|
79
79
|
attempt: () => Context.current().info.attempt,
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
/** Один вызов шага в рантайме Temporal без обёртки отказов — для тестов в MockActivityEnvironment. */
|
|
83
|
+
// Область берётся при вызове, а не при импорте: пакет sideEffects: false.
|
|
84
|
+
export const temporalStep = <T>(fn: () => T): T => stepScope(alsScope).run(TEMPORAL_STEP, fn);
|
|
85
|
+
|
|
82
86
|
/**
|
|
83
87
|
* Шаги порта для своего Worker.create (слив старой очереди, тестовый воркер): Failure доезжает
|
|
84
88
|
* как ApplicationFailure, heartbeat и stepAttempt работают. temporalRuntime делает это сам.
|
|
85
89
|
*/
|
|
86
90
|
export function temporalActivities<T extends Record<string, Activity>>(activities: T): T {
|
|
87
|
-
const scope = stepScope(alsScope);
|
|
88
91
|
return Object.fromEntries(
|
|
89
92
|
Object.entries(activities).map(([name, fn]) => [
|
|
90
93
|
name,
|
|
91
94
|
async (...args: unknown[]) => {
|
|
92
95
|
try {
|
|
93
|
-
return await
|
|
96
|
+
return await temporalStep(() => fn(...args));
|
|
94
97
|
} catch (e) {
|
|
95
98
|
throw toTemporal(e, false);
|
|
96
99
|
}
|