@mokronos/wfkit 0.1.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/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +8 -0
- package/dist/authoring.js.map +1 -0
- package/dist/cli/integrations.d.ts +3 -0
- package/dist/cli/integrations.d.ts.map +1 -0
- package/dist/cli/integrations.js +40 -0
- package/dist/cli/integrations.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +591 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/core.d.ts +198 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1061 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +154 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +24 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/replay.d.ts +3 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +28 -0
- package/dist/replay.js.map +1 -0
- package/dist/runtime.d.ts +70 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +183 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +18 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +19 -0
- package/dist/schema.js.map +1 -0
- package/dist/schemas.d.ts +1198 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +383 -0
- package/dist/schemas.js.map +1 -0
- package/dist/sdk/artifact.d.ts +41 -0
- package/dist/sdk/artifact.d.ts.map +1 -0
- package/dist/sdk/artifact.js +94 -0
- package/dist/sdk/artifact.js.map +1 -0
- package/dist/sdk/graph.d.ts +15 -0
- package/dist/sdk/graph.d.ts.map +1 -0
- package/dist/sdk/graph.js +388 -0
- package/dist/sdk/graph.js.map +1 -0
- package/dist/sdk/index.d.ts +14 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +8 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/integrations.d.ts +18 -0
- package/dist/sdk/integrations.d.ts.map +1 -0
- package/dist/sdk/integrations.js +20 -0
- package/dist/sdk/integrations.js.map +1 -0
- package/dist/sdk/json.d.ts +4 -0
- package/dist/sdk/json.d.ts.map +1 -0
- package/dist/sdk/json.js +31 -0
- package/dist/sdk/json.js.map +1 -0
- package/dist/sdk/loader.d.ts +10 -0
- package/dist/sdk/loader.d.ts.map +1 -0
- package/dist/sdk/loader.js +75 -0
- package/dist/sdk/loader.js.map +1 -0
- package/dist/sdk/sdk.d.ts +102 -0
- package/dist/sdk/sdk.d.ts.map +1 -0
- package/dist/sdk/sdk.js +669 -0
- package/dist/sdk/sdk.js.map +1 -0
- package/dist/sdk/sqlite.d.ts +8 -0
- package/dist/sdk/sqlite.d.ts.map +1 -0
- package/dist/sdk/sqlite.js +288 -0
- package/dist/sdk/sqlite.js.map +1 -0
- package/dist/signal.d.ts +17 -0
- package/dist/signal.d.ts.map +1 -0
- package/dist/signal.js +78 -0
- package/dist/signal.js.map +1 -0
- package/dist/testing/index.d.ts +35 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +244 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +67 -0
- package/src/authoring.ts +32 -0
- package/src/cli/integrations.ts +75 -0
- package/src/cli/main.ts +793 -0
- package/src/core.ts +1515 -0
- package/src/errors.ts +19 -0
- package/src/events.ts +37 -0
- package/src/index.ts +109 -0
- package/src/replay.ts +29 -0
- package/src/runtime.ts +314 -0
- package/src/schema.ts +34 -0
- package/src/schemas.ts +473 -0
- package/src/sdk/artifact.ts +176 -0
- package/src/sdk/graph.ts +486 -0
- package/src/sdk/index.ts +64 -0
- package/src/sdk/integrations.ts +49 -0
- package/src/sdk/json.ts +40 -0
- package/src/sdk/loader.ts +99 -0
- package/src/sdk/sdk.ts +911 -0
- package/src/sdk/sqlite.ts +405 -0
- package/src/signal.ts +116 -0
- package/src/testing/index.ts +341 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { DefinedWorkflowTypeId, type DefinedWorkflow } from "../core.ts"
|
|
2
|
+
import type { WorkflowArtifact } from "./artifact.ts"
|
|
3
|
+
|
|
4
|
+
export interface LoadedWorkflow {
|
|
5
|
+
readonly artifact: WorkflowArtifact
|
|
6
|
+
readonly exportName: string
|
|
7
|
+
readonly workflow: DefinedWorkflow
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const isDefinedWorkflow = (value: unknown): value is DefinedWorkflow => {
|
|
11
|
+
if ((typeof value !== "object" && typeof value !== "function") || value === null) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
return DefinedWorkflowTypeId in value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface WorkflowModule {
|
|
18
|
+
readonly default?: unknown
|
|
19
|
+
readonly [exportName: string]: unknown
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const importArtifactModule = async (
|
|
23
|
+
artifact: WorkflowArtifact
|
|
24
|
+
): Promise<WorkflowModule> => {
|
|
25
|
+
const compiled = await compileWorkflowSource(artifact)
|
|
26
|
+
const url = `data:text/javascript;base64,${Buffer.from(compiled).toString("base64")}`
|
|
27
|
+
return await import(url)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const compileWorkflowSource = async (artifact: WorkflowArtifact): Promise<string> => {
|
|
31
|
+
const source = rewriteWfImports(artifact.source)
|
|
32
|
+
|
|
33
|
+
if (typeof Bun !== "undefined" && Bun.Transpiler !== undefined) {
|
|
34
|
+
const transpiler = new Bun.Transpiler({
|
|
35
|
+
loader: "ts",
|
|
36
|
+
target: "bun"
|
|
37
|
+
})
|
|
38
|
+
return `${transpiler.transformSync(source)}\n//# sourceURL=wf:${artifact.id}@${artifact.version}\n`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ts = await import("typescript")
|
|
42
|
+
return `${ts.transpileModule(source, {
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
module: ts.ModuleKind.ESNext,
|
|
45
|
+
target: ts.ScriptTarget.ESNext,
|
|
46
|
+
verbatimModuleSyntax: true
|
|
47
|
+
}
|
|
48
|
+
}).outputText}\n//# sourceURL=wf:${artifact.id}@${artifact.version}\n`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rewriteWfImports = (source: string): string => {
|
|
52
|
+
const wfModuleUrl = new URL("../authoring.ts", import.meta.url).href
|
|
53
|
+
return source
|
|
54
|
+
.replaceAll(`from "@mokronos/wfkit"`, `from "${wfModuleUrl}"`)
|
|
55
|
+
.replaceAll(`from '@mokronos/wfkit'`, `from '${wfModuleUrl}'`)
|
|
56
|
+
.replaceAll(`import("@mokronos/wfkit")`, `import("${wfModuleUrl}")`)
|
|
57
|
+
.replaceAll(`import('@mokronos/wfkit')`, `import('${wfModuleUrl}')`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const loadWorkflowArtifact = async (
|
|
61
|
+
artifact: WorkflowArtifact
|
|
62
|
+
): Promise<LoadedWorkflow> => {
|
|
63
|
+
const module = await importArtifactModule(artifact)
|
|
64
|
+
|
|
65
|
+
if (artifact.exportName !== undefined) {
|
|
66
|
+
const exported = module[artifact.exportName]
|
|
67
|
+
if (isDefinedWorkflow(exported)) {
|
|
68
|
+
return { artifact, exportName: artifact.exportName, workflow: exported }
|
|
69
|
+
}
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Workflow ${artifact.id} expected export ${artifact.exportName}, but it was not a wf workflow`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isDefinedWorkflow(module.default)) {
|
|
76
|
+
return { artifact, exportName: "default", workflow: module.default }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const candidates: Array<readonly [string, DefinedWorkflow]> = []
|
|
80
|
+
for (const [name, value] of Object.entries(module)) {
|
|
81
|
+
if (isDefinedWorkflow(value)) {
|
|
82
|
+
candidates.push([name, value])
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (candidates.length === 1) {
|
|
87
|
+
const [exportName, workflow] = candidates[0]!
|
|
88
|
+
return { artifact, exportName, workflow }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (candidates.length > 1) {
|
|
92
|
+
const names = candidates.map(([name]) => name).join(", ")
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Workflow ${artifact.id} exports multiple workflows (${names}); set exportName in the manifest`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw new Error(`Workflow ${artifact.id} did not export a wf workflow`)
|
|
99
|
+
}
|