@lokascript/domain-flow 2.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/README.md +120 -0
- package/dist/index.cjs +2251 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +643 -0
- package/dist/index.d.ts +643 -0
- package/dist/index.js +2169 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
- package/src/__test__/flow-domain.test.ts +696 -0
- package/src/__test__/hateoas-commands.test.ts +520 -0
- package/src/__test__/htmx-generator.test.ts +100 -0
- package/src/__test__/mcp-workflow-server.test.ts +317 -0
- package/src/__test__/pipeline-parser.test.ts +188 -0
- package/src/__test__/route-extractor.test.ts +94 -0
- package/src/generators/flow-generator.ts +338 -0
- package/src/generators/flow-renderer.ts +262 -0
- package/src/generators/htmx-generator.ts +129 -0
- package/src/generators/route-extractor.ts +105 -0
- package/src/generators/workflow-generator.ts +129 -0
- package/src/index.ts +210 -0
- package/src/parser/pipeline-parser.ts +151 -0
- package/src/profiles/index.ts +186 -0
- package/src/runtime/mcp-workflow-server.ts +409 -0
- package/src/runtime/workflow-executor.ts +171 -0
- package/src/schemas/hateoas-schemas.ts +152 -0
- package/src/schemas/index.ts +320 -0
- package/src/siren-agent.d.ts +14 -0
- package/src/tokenizers/index.ts +592 -0
- package/src/types.ts +108 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @lokascript/domain-flow
|
|
2
|
+
|
|
3
|
+
Multilingual reactive data flow DSL built on `@lokascript/framework`. Describe fetch, polling, streaming, form submission, and data transformation pipelines in 8 natural languages and compile to vanilla JS or HTMX attributes.
|
|
4
|
+
|
|
5
|
+
## Supported Languages
|
|
6
|
+
|
|
7
|
+
| Language | Code | Word Order | Example |
|
|
8
|
+
| -------- | ---- | ---------- | -------------------------------------------- |
|
|
9
|
+
| English | `en` | SVO | `fetch /api/users as json into #list` |
|
|
10
|
+
| Spanish | `es` | SVO | `obtener /api/users como json en #list` |
|
|
11
|
+
| Japanese | `ja` | SOV | `/api/users json で 取得 #list に` |
|
|
12
|
+
| Arabic | `ar` | VSO | `جلب /api/users ك json في #list` |
|
|
13
|
+
| Korean | `ko` | SOV | `/api/users json 로 가져오기` |
|
|
14
|
+
| Chinese | `zh` | SVO | `获取 /api/users 以 json 到 #list` |
|
|
15
|
+
| Turkish | `tr` | SOV | `/api/users json olarak getir` |
|
|
16
|
+
| French | `fr` | SVO | `récupérer /api/users comme json dans #list` |
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
| Command | Description | Example |
|
|
21
|
+
| ----------- | ------------------------------- | ------------------------------------------------ |
|
|
22
|
+
| `fetch` | HTTP GET, parse response | `fetch /api/users as json into #list` |
|
|
23
|
+
| `poll` | Repeated fetch on interval | `poll /api/status every 5s as json into #status` |
|
|
24
|
+
| `stream` | Server-Sent Events (SSE) | `stream /api/events as sse into #feed` |
|
|
25
|
+
| `submit` | POST form data | `submit #login-form to /api/login` |
|
|
26
|
+
| `transform` | Client-side data transformation | `transform data with uppercase` |
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { createFlowDSL } from '@lokascript/domain-flow';
|
|
32
|
+
|
|
33
|
+
const flow = createFlowDSL();
|
|
34
|
+
|
|
35
|
+
// Parse
|
|
36
|
+
const node = flow.parse('fetch /api/users as json into #list', 'en');
|
|
37
|
+
|
|
38
|
+
// Compile to vanilla JS
|
|
39
|
+
const result = flow.compile('fetch /api/users as json into #list', 'en');
|
|
40
|
+
// → fetch('/api/users').then(r => r.json()).then(data => { ... })
|
|
41
|
+
|
|
42
|
+
// Validate
|
|
43
|
+
const validation = flow.validate('poll /api/status every 5s', 'en');
|
|
44
|
+
// → { valid: true }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Pipelines
|
|
48
|
+
|
|
49
|
+
Chain commands with `→` or `->`:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { compilePipeline } from '@lokascript/domain-flow';
|
|
53
|
+
|
|
54
|
+
const result = compilePipeline(
|
|
55
|
+
flow,
|
|
56
|
+
'fetch /api/data as json → transform data with uppercase into #output',
|
|
57
|
+
'en'
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### HTMX Generation
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { toFlowSpec, generateHTMX } from '@lokascript/domain-flow';
|
|
65
|
+
|
|
66
|
+
const node = flow.parse('fetch /api/users as json into #list', 'en');
|
|
67
|
+
const spec = toFlowSpec(node, 'en');
|
|
68
|
+
const htmx = generateHTMX(spec);
|
|
69
|
+
// → { attrs: { 'hx-get': '/api/users', 'hx-target': '#list', 'hx-swap': 'innerHTML' }, notes: [...] }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Route Extraction
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { toFlowSpec, extractRoute } from '@lokascript/domain-flow';
|
|
76
|
+
|
|
77
|
+
const spec = toFlowSpec(flow.parse('submit #form to /api/orders', 'en'), 'en');
|
|
78
|
+
const route = extractRoute(spec);
|
|
79
|
+
// → { path: '/api/orders', method: 'POST', handlerName: 'createOrders', ... }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Translation
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { renderFlow } from '@lokascript/domain-flow';
|
|
86
|
+
|
|
87
|
+
const node = flow.parse('fetch /api/users as json into #list', 'en');
|
|
88
|
+
renderFlow(node, 'ja'); // → /api/users json で 取得 #list に
|
|
89
|
+
renderFlow(node, 'es'); // → obtener /api/users como json en #list
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API
|
|
93
|
+
|
|
94
|
+
### `createFlowDSL(): MultilingualDSL`
|
|
95
|
+
|
|
96
|
+
Create a DSL instance with all 8 languages.
|
|
97
|
+
|
|
98
|
+
### `toFlowSpec(node, language): FlowSpec`
|
|
99
|
+
|
|
100
|
+
Convert a parsed semantic node to a structured `FlowSpec`.
|
|
101
|
+
|
|
102
|
+
### `renderFlow(node, language): string`
|
|
103
|
+
|
|
104
|
+
Render a semantic node back to natural-language DSL text.
|
|
105
|
+
|
|
106
|
+
### `generateHTMX(spec): HTMXAttributes | null`
|
|
107
|
+
|
|
108
|
+
Generate HTMX attributes from a `FlowSpec`. Returns null for `transform`.
|
|
109
|
+
|
|
110
|
+
### `extractRoute(spec): FlowRouteDescriptor | null`
|
|
111
|
+
|
|
112
|
+
Extract a server route descriptor from a `FlowSpec`.
|
|
113
|
+
|
|
114
|
+
### `parseFlowPipeline(dsl, input, language): PipelineParseResult`
|
|
115
|
+
|
|
116
|
+
Parse arrow-delimited multi-step pipelines.
|
|
117
|
+
|
|
118
|
+
### `compilePipeline(dsl, input, language): { ok, code, errors }`
|
|
119
|
+
|
|
120
|
+
Parse and compile a pipeline to JS.
|