@ontemper/platform 0.1.0 → 0.1.2
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/dist/index.d.ts +7 -5
- package/dist/index.js +9 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import * as restate from "@restatedev/restate-sdk";
|
|
14
14
|
interface CreateWorkflowOptions {
|
|
15
|
-
name?: string;
|
|
16
15
|
handler: (ctx: TemperContext, input: unknown) => Promise<unknown>;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
@@ -33,8 +32,11 @@ declare class TemperContext {
|
|
|
33
32
|
/** Set a durable state value. */
|
|
34
33
|
set<T>(key: string, value: T): Promise<void>;
|
|
35
34
|
}
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
export interface TemperWorkflow {
|
|
36
|
+
/** Restate service name (wf_{WORKFLOW_ID}) */
|
|
37
|
+
workflowName: string;
|
|
38
|
+
/** Fetch handler — pass requests from your HTTP server to this */
|
|
39
|
+
fetch: (req: Request) => Promise<Response>;
|
|
40
|
+
}
|
|
41
|
+
export declare function createWorkflow({ handler }: CreateWorkflowOptions): TemperWorkflow;
|
|
40
42
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -67,11 +67,13 @@ function writeDualStatus(executionId, status, extra) {
|
|
|
67
67
|
body: JSON.stringify({ execution_id: executionId, status, ...extra }),
|
|
68
68
|
}).catch(() => { }); // best-effort
|
|
69
69
|
}
|
|
70
|
-
export function createWorkflow({
|
|
70
|
+
export function createWorkflow({ handler }) {
|
|
71
|
+
const workflowId = process.env.WORKFLOW_ID;
|
|
72
|
+
if (!workflowId)
|
|
73
|
+
throw new Error("WORKFLOW_ID env var required");
|
|
71
74
|
// Restate service names must match ^([a-zA-Z]|_[a-zA-Z0-9])[a-zA-Z0-9._-]*$
|
|
72
75
|
// UUIDs start with digits, so prefix with "wf_" to make them valid.
|
|
73
|
-
const
|
|
74
|
-
const workflowName = rawName.match(/^[a-zA-Z_]/) ? rawName : `wf_${rawName}`;
|
|
76
|
+
const workflowName = `wf_${workflowId}`;
|
|
75
77
|
const workflow = restate.workflow({
|
|
76
78
|
name: workflowName,
|
|
77
79
|
handlers: {
|
|
@@ -114,24 +116,9 @@ export function createWorkflow({ name, handler }) {
|
|
|
114
116
|
},
|
|
115
117
|
},
|
|
116
118
|
});
|
|
117
|
-
// Start Bun HTTP server with Restate endpoint + health check
|
|
118
|
-
const port = Number(process.env.PORT);
|
|
119
|
-
if (!port)
|
|
120
|
-
throw new Error("PORT env var required");
|
|
121
119
|
const restateHandler = endpoint().bind(workflow).handler();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const url = new URL(req.url);
|
|
127
|
-
if (url.pathname === "/health" || url.pathname === "/healthcheck") {
|
|
128
|
-
return new Response(JSON.stringify({ status: "ok" }), {
|
|
129
|
-
headers: { "Content-Type": "application/json" },
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return restateHandler.fetch(req);
|
|
133
|
-
},
|
|
134
|
-
});
|
|
120
|
+
return {
|
|
121
|
+
workflowName,
|
|
122
|
+
fetch: (req) => restateHandler.fetch(req),
|
|
123
|
+
};
|
|
135
124
|
}
|
|
136
|
-
// Customer-facing API (backward-compatible module shape)
|
|
137
|
-
export const temper = { createWorkflow };
|