@pylonts/dsl 1.1.5 → 1.1.11
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 +4 -0
- package/dist/action.d.ts +32 -0
- package/dist/action.js +14 -0
- package/dist/aggregate.d.ts +38 -0
- package/dist/aggregate.js +46 -0
- package/dist/business-flow.d.ts +9 -0
- package/dist/business-flow.js +72 -0
- package/dist/controller.d.ts +35 -0
- package/dist/controller.js +17 -0
- package/dist/convert.d.ts +37 -7
- package/dist/convert.js +23 -2
- package/dist/curd.d.ts +7 -12
- package/dist/curd.js +10 -1
- package/dist/dao.d.ts +140 -3
- package/dist/dao.js +307 -2
- package/dist/db.d.ts +6 -0
- package/dist/db.js +13 -0
- package/dist/domain-event.d.ts +48 -0
- package/dist/domain-event.js +24 -0
- package/dist/dsl.d.ts +32 -2
- package/dist/dsl.js +13 -0
- package/dist/dto.d.ts +8 -2
- package/dist/dto.js +21 -9
- package/dist/endpoint.d.ts +15 -0
- package/dist/endpoint.js +3 -0
- package/dist/entity.d.ts +29 -0
- package/dist/entity.js +13 -0
- package/dist/exception.d.ts +20 -0
- package/dist/exception.js +33 -0
- package/dist/expr.d.ts +45 -0
- package/dist/expr.js +32 -0
- package/dist/field-rule.d.ts +20 -0
- package/dist/field-rule.js +19 -0
- package/dist/filter.d.ts +45 -0
- package/dist/filter.js +21 -0
- package/dist/flow-script.d.ts +108 -0
- package/dist/flow-script.js +505 -0
- package/dist/flow.d.ts +309 -10
- package/dist/flow.js +819 -22
- package/dist/index.d.ts +12 -1
- package/dist/index.js +14 -1
- package/dist/mermaid-driver.js +278 -9
- package/dist/method.d.ts +11 -0
- package/dist/method.js +3 -0
- package/dist/mysql-driver.js +7 -0
- package/dist/project.d.ts +5 -4
- package/dist/project.js +14 -2
- package/dist/provider.d.ts +6 -11
- package/dist/provider.js +2 -2
- package/dist/repository.d.ts +26 -0
- package/dist/repository.js +8 -0
- package/dist/service.d.ts +30 -8
- package/dist/service.js +62 -2
- package/dist/third-service.d.ts +80 -0
- package/dist/third-service.js +97 -0
- package/dist/typebox-driver.d.ts +6 -0
- package/dist/typebox-driver.js +77 -12
- package/dist/utils.d.ts +32 -10
- package/dist/utils.js +32 -11
- package/docs/aggregate.md +110 -0
- package/docs/dao-generation.md +478 -0
- package/docs/ddd-principles.md +75 -0
- package/docs/domain-event.md +137 -0
- package/docs/dto.md +73 -66
- package/docs/keyword-matcher.md +182 -0
- package/docs/third-service.md +122 -0
- package/docs/token.md +327 -0
- package/docs/trans-reentrant.md +85 -0
- package/package.json +27 -5
- package/src/action.ts +51 -10
- package/src/aggregate.ts +104 -0
- package/src/business-flow.ts +80 -0
- package/src/controller.ts +54 -0
- package/src/convert.ts +78 -15
- package/src/curd.ts +104 -93
- package/src/dao.ts +486 -13
- package/src/db.ts +199 -181
- package/src/domain-event.ts +74 -0
- package/src/dsl.ts +48 -2
- package/src/dto.ts +266 -247
- package/src/entity.ts +43 -0
- package/src/exception.ts +53 -0
- package/src/expr.ts +65 -0
- package/src/field-rule.ts +47 -0
- package/src/filter.ts +70 -0
- package/src/flow-script.ts +696 -0
- package/src/flow.ts +1226 -103
- package/src/index.ts +47 -33
- package/src/mermaid-driver.ts +339 -84
- package/src/method.ts +20 -0
- package/src/mysql-driver.ts +7 -0
- package/src/project.ts +114 -97
- package/src/repository.ts +35 -0
- package/src/service.ts +107 -20
- package/src/third-service.ts +192 -0
- package/src/typebox-driver.ts +86 -11
- package/src/utils.ts +74 -26
- package/dist/check-inheritance.d.ts +0 -9
- package/dist/check-inheritance.js +0 -58
- package/src/provider.ts +0 -73
package/dist/index.d.ts
CHANGED
|
@@ -22,12 +22,23 @@ export * from './convert.js';
|
|
|
22
22
|
export * from './ref.js';
|
|
23
23
|
export * from './route.js';
|
|
24
24
|
export * from './service.js';
|
|
25
|
+
export * from './controller.js';
|
|
25
26
|
export * from './dao.js';
|
|
27
|
+
export * from './entity.js';
|
|
28
|
+
export * from './expr.js';
|
|
29
|
+
export * from './filter.js';
|
|
30
|
+
export * from './aggregate.js';
|
|
31
|
+
export * from './repository.js';
|
|
32
|
+
export * from './domain-event.js';
|
|
33
|
+
export * from './third-service.js';
|
|
34
|
+
export * from './field-rule.js';
|
|
35
|
+
export * from './exception.js';
|
|
26
36
|
export * from './page.js';
|
|
27
37
|
export * from './curd.js';
|
|
28
38
|
export * from './page-flow.js';
|
|
29
|
-
export * from './provider.js';
|
|
30
39
|
export * from './page-def.js';
|
|
31
40
|
export * from './mermaid-driver.js';
|
|
32
41
|
export * from './navigation.js';
|
|
33
42
|
export * from './popup.js';
|
|
43
|
+
export * from './method.js';
|
|
44
|
+
export { toCamelCase, toPascalCase, toKebabCase } from '@pylonts/core';
|
package/dist/index.js
CHANGED
|
@@ -22,12 +22,25 @@ export * from './convert.js';
|
|
|
22
22
|
export * from './ref.js';
|
|
23
23
|
export * from './route.js';
|
|
24
24
|
export * from './service.js';
|
|
25
|
+
export * from './controller.js';
|
|
25
26
|
export * from './dao.js';
|
|
27
|
+
export * from './entity.js';
|
|
28
|
+
export * from './expr.js';
|
|
29
|
+
export * from './filter.js';
|
|
30
|
+
export * from './aggregate.js';
|
|
31
|
+
export * from './repository.js';
|
|
32
|
+
export * from './domain-event.js';
|
|
33
|
+
export * from './third-service.js';
|
|
34
|
+
export * from './field-rule.js';
|
|
35
|
+
export * from './exception.js';
|
|
26
36
|
export * from './page.js';
|
|
27
37
|
export * from './curd.js';
|
|
28
38
|
export * from './page-flow.js';
|
|
29
|
-
export * from './provider.js';
|
|
30
39
|
export * from './page-def.js';
|
|
31
40
|
export * from './mermaid-driver.js';
|
|
32
41
|
export * from './navigation.js';
|
|
33
42
|
export * from './popup.js';
|
|
43
|
+
export * from './method.js';
|
|
44
|
+
// Naming conversions moved to @pylonts/core; re-exported for compatibility
|
|
45
|
+
// with packages that import them from @pylonts/dsl.
|
|
46
|
+
export { toCamelCase, toPascalCase, toKebabCase } from '@pylonts/core';
|
package/dist/mermaid-driver.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { isCall, methodOf } from './flow.js';
|
|
1
2
|
// Mermaid driver: converts a FlowSchema into a Mermaid flowchart (TD).
|
|
2
3
|
// Node ids are hierarchical (n0, n0_0, n0_0_0, ...) so nested sub-flows stay
|
|
3
4
|
// globally unique. A node with a sub-flow renders as a subgraph block whose
|
|
4
|
-
// internals are rendered recursively.
|
|
5
|
-
//
|
|
5
|
+
// internals are rendered recursively. A TryNode renders as a subgraph for its
|
|
6
|
+
// body plus one per catch handler (and finally): body exception ends route to
|
|
7
|
+
// handlers as dashed `catch X` edges, fall-through paths (body return end and
|
|
8
|
+
// handler return ends, through finally when present) continue via the
|
|
9
|
+
// TryNode's outgoing edges, and handler exception ends rethrow via the
|
|
10
|
+
// TryNode's typed throws edges. Guard nodes render as diamonds, FlowEnd nodes
|
|
11
|
+
// as stadium shapes. Normal edges render as -->, conditional edges as
|
|
12
|
+
// -->|"WHEN"|, typed throws and catch routes as dashed edges.
|
|
6
13
|
function escapeLabel(s) {
|
|
7
|
-
return s.replace(/"/g, '\\"').replace(/\n/g, '<br/>');
|
|
14
|
+
return s.replace(/"/g, '\\"').replace(/\n/g, '<br/>').replace(/\|/g, '|');
|
|
8
15
|
}
|
|
9
16
|
export function renderFlowMermaid(schema) {
|
|
10
17
|
const lines = ['flowchart TD'];
|
|
@@ -17,24 +24,286 @@ export function renderFlowMermaid(schema) {
|
|
|
17
24
|
}
|
|
18
25
|
function renderFlow(schema, prefix, lines, ids) {
|
|
19
26
|
schema.nodes.forEach((n, i) => ids.set(n, `${prefix}${i}`));
|
|
27
|
+
const outgoing = new Map();
|
|
28
|
+
for (const n of schema.nodes)
|
|
29
|
+
outgoing.set(n, []);
|
|
30
|
+
for (const e of schema.edges)
|
|
31
|
+
outgoing.get(e.start).push(e);
|
|
20
32
|
for (const n of schema.nodes) {
|
|
21
33
|
const id = ids.get(n);
|
|
22
|
-
if (n
|
|
34
|
+
if (isTryNode(n)) {
|
|
23
35
|
lines.push(` subgraph ${id}["${escapeLabel(n.name)}"]`);
|
|
36
|
+
renderFlow(n.body, `${id}_b`, lines, ids);
|
|
37
|
+
lines.push(' end');
|
|
38
|
+
const handlers = [];
|
|
39
|
+
const handlerIdx = new Map();
|
|
40
|
+
for (const c of n.catches) {
|
|
41
|
+
if (handlerIdx.has(c.handler))
|
|
42
|
+
continue; // one handler may serve many catches
|
|
43
|
+
handlerIdx.set(c.handler, handlers.length);
|
|
44
|
+
handlers.push(c.handler);
|
|
45
|
+
}
|
|
46
|
+
handlers.forEach((h, i) => {
|
|
47
|
+
lines.push(` subgraph ${id}_h${i}["${escapeLabel(h.name)}"]`);
|
|
48
|
+
renderFlow(h, `${id}_h${i}_`, lines, ids);
|
|
49
|
+
lines.push(' end');
|
|
50
|
+
});
|
|
51
|
+
if (n.finally) {
|
|
52
|
+
lines.push(` subgraph ${id}_f["${escapeLabel(n.finally.name)}"]`);
|
|
53
|
+
renderFlow(n.finally, `${id}_f_`, lines, ids);
|
|
54
|
+
lines.push(' end');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (isFlowNode(n) && n.flow) {
|
|
58
|
+
lines.push(` subgraph ${id}["${escapeLabel(renderNodeLabel(n, outgoing.get(n)))}"]`);
|
|
24
59
|
renderFlow(n.flow, `${id}_`, lines, ids);
|
|
25
60
|
lines.push(' end');
|
|
26
61
|
}
|
|
27
62
|
else {
|
|
28
|
-
|
|
63
|
+
const shape = renderShape(n, schema, outgoing.get(n));
|
|
64
|
+
lines.push(` ${id}${shape.open}${escapeLabel(renderNodeLabel(n, outgoing.get(n)))}${shape.close}`);
|
|
29
65
|
}
|
|
30
66
|
}
|
|
31
67
|
for (const e of schema.edges) {
|
|
32
|
-
|
|
68
|
+
if (isTryNode(e.start))
|
|
69
|
+
continue; // rendered by renderTryRoutes
|
|
70
|
+
if (isTryNode(e.end)) {
|
|
71
|
+
// entering a TryNode means entering its body
|
|
72
|
+
lines.push(renderEdgeLine(e, ids.get(e.start), ids.get(e.end.body.start)));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
lines.push(renderEdgeLine(e, ids.get(e.start), ids.get(e.end)));
|
|
76
|
+
}
|
|
77
|
+
// guard checks: implicit branch edges of the guard itself
|
|
78
|
+
for (const n of schema.nodes) {
|
|
79
|
+
if (!isGuard(n))
|
|
80
|
+
continue;
|
|
81
|
+
const id = ids.get(n);
|
|
82
|
+
for (const c of n.checks) {
|
|
83
|
+
if (c.return) {
|
|
84
|
+
lines.push(` ${id} -->|"${escapeLabel(c.when)}"| ${ids.get(schema.returnEnd)}`);
|
|
85
|
+
}
|
|
86
|
+
else if (c.exception) {
|
|
87
|
+
const t = findExceptionEnd(schema, c.exception.name);
|
|
88
|
+
lines.push(` ${id} -.->|"${escapeLabel(c.when)} · throw ${escapeLabel(c.exception.name)}"| ${ids.get(t)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ifNode cases: implicit branch edges of the decision node
|
|
93
|
+
const branchTarget = (t) => (isTryNode(t) ? t.body.start : t);
|
|
94
|
+
for (const n of schema.nodes) {
|
|
95
|
+
if (!isIfNode(n))
|
|
96
|
+
continue;
|
|
97
|
+
const id = ids.get(n);
|
|
98
|
+
for (const c of n.cases) {
|
|
99
|
+
lines.push(` ${id} -->|"${escapeLabel(c.when)}"| ${ids.get(branchTarget(c.to))}`);
|
|
100
|
+
}
|
|
101
|
+
lines.push(` ${id} -->|"else"| ${ids.get(branchTarget(n.else))}`);
|
|
33
102
|
}
|
|
103
|
+
// TryNode internal routes
|
|
104
|
+
for (const n of schema.nodes) {
|
|
105
|
+
if (isTryNode(n))
|
|
106
|
+
renderTryRoutes(n, schema, ids, lines);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Routes of a TryNode: catch edges, fall-through continuation (through
|
|
110
|
+
* finally when present), and handler rethrows (also through finally). */
|
|
111
|
+
function renderTryRoutes(n, schema, ids, lines) {
|
|
112
|
+
const next = schema.edges.filter((e) => e.start === n && e.throws === undefined && e.exception !== true);
|
|
113
|
+
const rethrows = schema.edges.filter((e) => e.start === n && e.throws !== undefined);
|
|
114
|
+
for (const c of n.catches) {
|
|
115
|
+
const end = findExceptionEnd(n.body, c.exception.name);
|
|
116
|
+
lines.push(` ${ids.get(end)} -.->|"catch ${escapeLabel(c.exception.name)}"| ${ids.get(c.handler.start)}`);
|
|
117
|
+
}
|
|
118
|
+
const continueFrom = (sourceId) => {
|
|
119
|
+
if (n.finally) {
|
|
120
|
+
lines.push(` ${sourceId} --> ${ids.get(n.finally.start)}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
for (const e of next) {
|
|
124
|
+
lines.push(renderEdgeLine(e, sourceId, ids.get(e.end)));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
continueFrom(ids.get(n.body.returnEnd));
|
|
128
|
+
const doneHandlers = new Set();
|
|
129
|
+
for (const c of n.catches) {
|
|
130
|
+
if (doneHandlers.has(c.handler))
|
|
131
|
+
continue; // one handler may serve many catches
|
|
132
|
+
doneHandlers.add(c.handler);
|
|
133
|
+
// A handler whose every path throws has no fall-through — its return end
|
|
134
|
+
// is never targeted and stays out of the handler's node list.
|
|
135
|
+
const handlerReturn = ids.get(c.handler.returnEnd);
|
|
136
|
+
if (handlerReturn !== undefined)
|
|
137
|
+
continueFrom(handlerReturn);
|
|
138
|
+
}
|
|
139
|
+
if (n.finally) {
|
|
140
|
+
for (const e of next) {
|
|
141
|
+
lines.push(renderEdgeLine(e, ids.get(n.finally.returnEnd), ids.get(e.end)));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const rethrown = new Map();
|
|
145
|
+
for (const e of rethrows) {
|
|
146
|
+
for (const c of n.catches) {
|
|
147
|
+
let names = rethrown.get(c.handler);
|
|
148
|
+
if (!names) {
|
|
149
|
+
names = new Set();
|
|
150
|
+
rethrown.set(c.handler, names);
|
|
151
|
+
}
|
|
152
|
+
if (names.has(e.throws.name))
|
|
153
|
+
continue; // one handler may serve many catches
|
|
154
|
+
names.add(e.throws.name);
|
|
155
|
+
const end = findExceptionEnd(c.handler, e.throws.name);
|
|
156
|
+
if (!end)
|
|
157
|
+
continue;
|
|
158
|
+
if (n.finally) {
|
|
159
|
+
lines.push(` ${ids.get(end)} -.->|"rethrow ${escapeLabel(e.throws.name)}"| ${ids.get(n.finally.start)}`);
|
|
160
|
+
lines.push(` ${ids.get(n.finally.returnEnd)} -.->|"rethrow ${escapeLabel(e.throws.name)}"| ${ids.get(e.end)}`);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
lines.push(` ${ids.get(end)} -.->|"rethrow ${escapeLabel(e.throws.name)}"| ${ids.get(e.end)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** The exception end of a flow carrying the given exception name. */
|
|
169
|
+
function findExceptionEnd(flow, exceptionName) {
|
|
170
|
+
const end = flow.nodes.find((n) => isEnd(n) && n.type === 'exception' && n.exception?.name === exceptionName);
|
|
171
|
+
if (!end) {
|
|
172
|
+
throw new Error(`flow ${flow.name}: no exception end for ${exceptionName}`);
|
|
173
|
+
}
|
|
174
|
+
return end;
|
|
175
|
+
}
|
|
176
|
+
/** Node label: name on the first line, method references (including utils
|
|
177
|
+
* predicates of guard checks) on the second, and the data line (slots
|
|
178
|
+
* consumed `r:` / produced `w:`) last. */
|
|
179
|
+
function renderNodeLabel(n, outgoing) {
|
|
180
|
+
if (isEnd(n) || isTryNode(n))
|
|
181
|
+
return n.name;
|
|
182
|
+
const lines = [n.name];
|
|
183
|
+
if (isFlowNode(n) && n.publish) {
|
|
184
|
+
const payload = n.publish.payload ? ` (${n.publish.payload.name})` : '';
|
|
185
|
+
lines.push(`publish ${n.publish.event.name}${payload}`);
|
|
186
|
+
}
|
|
187
|
+
const refs = [];
|
|
188
|
+
if (!isIfNode(n)) {
|
|
189
|
+
refs.push(...(n.methods ?? []));
|
|
190
|
+
if (isGuard(n)) {
|
|
191
|
+
for (const c of n.checks) {
|
|
192
|
+
if (c.check !== undefined && isCall(c.check))
|
|
193
|
+
refs.push(c.check);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (refs.length > 0) {
|
|
198
|
+
const rendered = refs.map((m) => renderMethodRef(methodOf(m))).join(' | ');
|
|
199
|
+
// Script-compiled nodes carry the full method name themselves.
|
|
200
|
+
if (rendered !== n.name)
|
|
201
|
+
lines.push(rendered);
|
|
202
|
+
}
|
|
203
|
+
const data = renderDataLine(n, outgoing);
|
|
204
|
+
if (data !== '')
|
|
205
|
+
lines.push(data);
|
|
206
|
+
return lines.join('\n');
|
|
207
|
+
}
|
|
208
|
+
/** Data line: `r:` lists slots the node consumes (reads, call args, decision
|
|
209
|
+
* condition slots, and branch-edge conditions decided here), `w:` lists
|
|
210
|
+
* slots it produces (writes and call results). */
|
|
211
|
+
function renderDataLine(n, outgoing) {
|
|
212
|
+
const reads = new Set();
|
|
213
|
+
const writes = new Set();
|
|
214
|
+
const addCondition = (c) => {
|
|
215
|
+
if (c === undefined)
|
|
216
|
+
return;
|
|
217
|
+
if (!isCall(c)) {
|
|
218
|
+
reads.add(c.field.slot.name);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
for (const t of c.args ?? [])
|
|
222
|
+
reads.add(t.name);
|
|
223
|
+
};
|
|
224
|
+
if (isGuard(n)) {
|
|
225
|
+
for (const c of n.checks) {
|
|
226
|
+
for (const t of c.reads ?? [])
|
|
227
|
+
reads.add(t.name);
|
|
228
|
+
addCondition(c.check);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (isIfNode(n)) {
|
|
232
|
+
for (const c of n.cases)
|
|
233
|
+
addCondition(c.check);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
for (const t of n.reads ?? [])
|
|
237
|
+
reads.add(t.name);
|
|
238
|
+
for (const t of n.writes ?? [])
|
|
239
|
+
writes.add(t.name);
|
|
240
|
+
if (isFlowNode(n) && n.publish?.payload)
|
|
241
|
+
reads.add(n.publish.payload.name);
|
|
242
|
+
}
|
|
243
|
+
for (const e of outgoing)
|
|
244
|
+
addCondition(e.check);
|
|
245
|
+
if (!isIfNode(n)) {
|
|
246
|
+
for (const ref of n.methods ?? []) {
|
|
247
|
+
if (!isCall(ref))
|
|
248
|
+
continue;
|
|
249
|
+
for (const t of ref.args ?? [])
|
|
250
|
+
reads.add(t.name);
|
|
251
|
+
if (ref.result)
|
|
252
|
+
writes.add(ref.result.name);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const parts = [];
|
|
256
|
+
if (reads.size > 0)
|
|
257
|
+
parts.push(`r:${[...reads].join(',')}`);
|
|
258
|
+
if (writes.size > 0)
|
|
259
|
+
parts.push(`w:${[...writes].join(',')}`);
|
|
260
|
+
return parts.join(' ');
|
|
261
|
+
}
|
|
262
|
+
/** Display form: owner.name for descriptors, schema.name for container methods. */
|
|
263
|
+
function renderMethodRef(m) {
|
|
264
|
+
if ('owner' in m)
|
|
265
|
+
return `${m.owner}.${m.name}`;
|
|
266
|
+
return `${m.schema.name}.${m.name}`;
|
|
267
|
+
}
|
|
268
|
+
/** Shape derived from topology: guards are diamonds, ends rounded, other
|
|
269
|
+
* branching nodes diamonds, else rect. Exception edges (typed or not) do not
|
|
270
|
+
* count as branches. The start keeps its rounded shape unless it branches. */
|
|
271
|
+
function renderShape(n, schema, outgoing) {
|
|
272
|
+
if (isGuard(n))
|
|
273
|
+
return { open: '{"', close: '"}' };
|
|
274
|
+
if (isIfNode(n))
|
|
275
|
+
return { open: '{"', close: '"}' };
|
|
276
|
+
if (isEnd(n) || outgoing.length === 0)
|
|
277
|
+
return { open: '(["', close: '"])' };
|
|
278
|
+
const normal = outgoing.filter((e) => e.exception !== true && e.throws === undefined).length;
|
|
279
|
+
if (normal >= 2)
|
|
280
|
+
return { open: '{"', close: '"}' };
|
|
281
|
+
if (n === schema.start)
|
|
282
|
+
return { open: '(["', close: '"])' };
|
|
283
|
+
return { open: '["', close: '"]' };
|
|
284
|
+
}
|
|
285
|
+
function renderEdgeLine(e, startId, endId) {
|
|
286
|
+
const isException = e.exception === true || e.throws !== undefined;
|
|
287
|
+
const arrow = isException ? '-.->' : '-->';
|
|
288
|
+
const throwLabel = e.throws ? `throw ${escapeLabel(e.throws.name)}` : '';
|
|
289
|
+
const labelParts = [e.when ? escapeLabel(e.when) : '', throwLabel].filter((s) => s !== '');
|
|
290
|
+
const label = labelParts.length > 0 ? `|"${labelParts.join(' · ')}"|` : '';
|
|
291
|
+
return ` ${startId} ${arrow}${label} ${endId}`;
|
|
292
|
+
}
|
|
293
|
+
function isEnd(n) {
|
|
294
|
+
return 'type' in n && (n.type === 'return' || n.type === 'exception');
|
|
295
|
+
}
|
|
296
|
+
function isFlowNode(n) {
|
|
297
|
+
return !('type' in n);
|
|
298
|
+
}
|
|
299
|
+
function isGuard(n) {
|
|
300
|
+
return 'type' in n && n.type === 'guard';
|
|
301
|
+
}
|
|
302
|
+
function isTryNode(n) {
|
|
303
|
+
return 'type' in n && n.type === 'try';
|
|
34
304
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
return ` ${ids.get(e.start)} -->${label} ${ids.get(e.end)}`;
|
|
305
|
+
function isIfNode(n) {
|
|
306
|
+
return 'type' in n && n.type === 'if';
|
|
38
307
|
}
|
|
39
308
|
// Page-driven flow renderer: groups pages by their app into swimlane
|
|
40
309
|
// subgraphs, then renders edges across the whole flow.
|
package/dist/method.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SchemaBase } from './dsl.js';
|
|
2
|
+
export interface MethodSchema extends SchemaBase {
|
|
3
|
+
/** Owning schema name, e.g. 'payDao'. */
|
|
4
|
+
owner: string;
|
|
5
|
+
}
|
|
6
|
+
export type SequenceSchema = MethodSchema[];
|
|
7
|
+
export declare function defineMethod(options: {
|
|
8
|
+
name: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}): MethodSchema;
|
package/dist/method.js
ADDED
package/dist/mysql-driver.js
CHANGED
|
@@ -33,6 +33,13 @@ function columnType(field) {
|
|
|
33
33
|
return field.enum.valueType === 'integer' ? 'TINYINT' : 'VARCHAR(20)';
|
|
34
34
|
case 'json':
|
|
35
35
|
return 'JSON';
|
|
36
|
+
case 'array':
|
|
37
|
+
case 'object':
|
|
38
|
+
// Nested fields are wire-format only (third-party messages); table columns cannot nest.
|
|
39
|
+
throw new Error(`field ${field.name} (${field.type}): nested fields are not supported on table columns`);
|
|
40
|
+
case 'aggregate':
|
|
41
|
+
// Aggregate fields are query outputs, never table columns.
|
|
42
|
+
throw new Error(`field ${field.name} (aggregate): aggregate fields are not supported on table columns`);
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
function renderDefault(field) {
|
package/dist/project.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { SchemaBase } from './dsl.js';
|
|
2
2
|
import type { TableSchema } from './db.js';
|
|
3
3
|
/** Frontend form factor. Closed enum, extend when new form factors appear. */
|
|
4
|
-
export type FrontType = 'admin' | 'wxmini';
|
|
4
|
+
export type FrontType = 'admin' | 'wxmini' | 'mobile';
|
|
5
5
|
/** A frontend application (e.g. admin console, wechat mini program). */
|
|
6
6
|
export interface FrontAppSchema extends SchemaBase {
|
|
7
7
|
type: FrontType;
|
|
8
8
|
/** Source directory relative to project root, e.g. 'web-admin/'. */
|
|
9
9
|
dir: string;
|
|
10
10
|
/**
|
|
11
|
-
* Tenant table for this app.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Tenant table for this app. The tenant column of a business table is
|
|
12
|
+
* deterministic: `{tenant.phrase}_{tenant.pk}` (e.g. shop with pk id →
|
|
13
|
+
* `shop_id`). Tables carrying that column get automatic tenant scoping;
|
|
14
|
+
* tables without it are global tables (e.g. system config) — both valid.
|
|
14
15
|
*/
|
|
15
16
|
tenant?: TableSchema;
|
|
16
17
|
}
|
package/dist/project.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// Instance naming: lowercase letters/digits/dashes only. Underscores belong
|
|
2
|
+
// to table names; the instance export symbol in project.config.ts must equal
|
|
3
|
+
// the kebab-camel of the name, so 'admin_api' cannot map to a valid symbol.
|
|
4
|
+
const INSTANCE_NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
5
|
+
function checkInstanceName(project, kind, name) {
|
|
6
|
+
if (!INSTANCE_NAME_RE.test(name)) {
|
|
7
|
+
throw new Error(`project ${project}: ${kind} name '${name}' must match ${INSTANCE_NAME_RE} (lowercase letters/digits/dashes; underscores are table-only)`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
1
10
|
/**
|
|
2
11
|
* Defines the project topology. FrontAppSchema instances are shared value objects:
|
|
3
12
|
* api.apps references the same instances from project.apps, so an app served
|
|
@@ -12,11 +21,12 @@ export function defineProject(name, schema) {
|
|
|
12
21
|
for (const app of project.apps) {
|
|
13
22
|
if (!app.name)
|
|
14
23
|
throw new Error(`project ${name}: app name is required`);
|
|
24
|
+
checkInstanceName(name, 'app', app.name);
|
|
15
25
|
if (appNames.has(app.name))
|
|
16
26
|
throw new Error(`project ${name}: duplicate app name '${app.name}'`);
|
|
17
27
|
appNames.add(app.name);
|
|
18
|
-
if (app.type !== 'admin' && app.type !== 'wxmini') {
|
|
19
|
-
throw new Error(`project ${name}: app '${app.name}' must be type 'admin' or '
|
|
28
|
+
if (app.type !== 'admin' && app.type !== 'wxmini' && app.type !== 'mobile') {
|
|
29
|
+
throw new Error(`project ${name}: app '${app.name}' must be type 'admin', 'wxmini' or 'mobile' (got '${app.type}')`);
|
|
20
30
|
}
|
|
21
31
|
if (!app.dir)
|
|
22
32
|
throw new Error(`project ${name}: app '${app.name}' dir is required`);
|
|
@@ -25,6 +35,7 @@ export function defineProject(name, schema) {
|
|
|
25
35
|
for (const api of project.apis) {
|
|
26
36
|
if (!api.name)
|
|
27
37
|
throw new Error(`project ${name}: api name is required`);
|
|
38
|
+
checkInstanceName(name, 'api', api.name);
|
|
28
39
|
if (apiNames.has(api.name))
|
|
29
40
|
throw new Error(`project ${name}: duplicate api name '${api.name}'`);
|
|
30
41
|
apiNames.add(api.name);
|
|
@@ -39,6 +50,7 @@ export function defineProject(name, schema) {
|
|
|
39
50
|
for (const third of project.thirdApis) {
|
|
40
51
|
if (!third.name)
|
|
41
52
|
throw new Error(`project ${name}: thirdApi name is required`);
|
|
53
|
+
checkInstanceName(name, 'thirdApi', third.name);
|
|
42
54
|
if (!third.dir)
|
|
43
55
|
throw new Error(`project ${name}: thirdApi '${third.name}' dir is required`);
|
|
44
56
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ImportableSchemaBase } from './dsl.js';
|
|
|
3
3
|
import type { DtoField, DtoMessage, DtoArrayField, DtoObjectField } from './dto.js';
|
|
4
4
|
import type { ActionSchema } from './action.js';
|
|
5
5
|
import type { RefSchema } from './ref.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { EndpointSchema } from './endpoint.js';
|
|
7
7
|
/** Parameter data source for a call argument. */
|
|
8
8
|
export type DataRef = {
|
|
9
9
|
type: 'route';
|
|
@@ -26,19 +26,16 @@ export interface CallAction extends ActionSchema {
|
|
|
26
26
|
}
|
|
27
27
|
export declare function call(func: ProviderSchema, args?: Record<string, DtoField | DtoMessage | DtoArrayField | DtoObjectField | RefSchema | string>): CallAction;
|
|
28
28
|
/** Provider function signature. The generated API client exposes one function
|
|
29
|
-
* per endpoint; ProviderSchema gives that function a name and
|
|
29
|
+
* per endpoint; ProviderSchema gives that function a name and a shared signature. */
|
|
30
30
|
export interface ProviderSchema extends ImportableSchemaBase {
|
|
31
31
|
isAsync: boolean;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
/** Output DTO (buildOutput result) or primitive. */
|
|
35
|
-
results: DtoMessage | number | boolean | string;
|
|
32
|
+
/** Shared API signature — same instance the backend controller method references. */
|
|
33
|
+
signature: EndpointSchema;
|
|
36
34
|
}
|
|
37
35
|
/** Define a provider function. */
|
|
38
36
|
export declare function defineProvider(name: string, schema: {
|
|
39
37
|
isAsync: boolean;
|
|
40
|
-
|
|
41
|
-
results: DtoMessage | number | boolean | string;
|
|
38
|
+
signature: EndpointSchema;
|
|
42
39
|
description?: string;
|
|
43
40
|
importRef?: ImportBase;
|
|
44
41
|
}): ProviderSchema;
|
|
@@ -48,7 +45,5 @@ export interface SetDataAction extends ActionSchema {
|
|
|
48
45
|
type: 'setData';
|
|
49
46
|
call: CallAction;
|
|
50
47
|
field: DtoField;
|
|
51
|
-
/** Optional field-level transform before assignment. */
|
|
52
|
-
convert?: ConvertSchema;
|
|
53
48
|
}
|
|
54
|
-
export declare function setData(call: CallAction, field: DtoField
|
|
49
|
+
export declare function setData(call: CallAction, field: DtoField): SetDataAction;
|
package/dist/provider.js
CHANGED
|
@@ -13,6 +13,6 @@ export function call(func, args) {
|
|
|
13
13
|
export function defineProvider(name, schema) {
|
|
14
14
|
return { name, ...schema };
|
|
15
15
|
}
|
|
16
|
-
export function setData(call, field
|
|
17
|
-
return { name: 'setData', type: 'setData', call, field
|
|
16
|
+
export function setData(call, field) {
|
|
17
|
+
return { name: 'setData', type: 'setData', call, field };
|
|
18
18
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SchemaBase } from './dsl.js';
|
|
2
|
+
import type { DomainAggregate } from './aggregate.js';
|
|
3
|
+
/**
|
|
4
|
+
* Aggregate-grained storage entry. The repository binds one aggregate and
|
|
5
|
+
* exposes the three fixed operation skeletons (load / save / delete) that the
|
|
6
|
+
* generator expands from the aggregate structure:
|
|
7
|
+
*
|
|
8
|
+
* save(order) = tx { rootDao.upsert + memberDao cascade by via FK }
|
|
9
|
+
* load(id) = rootDao.get + memberDao by via FK
|
|
10
|
+
* delete(id) = tx { memberDao delete + rootDao delete }
|
|
11
|
+
*
|
|
12
|
+
* Callers face the domain concept (Order), never the tables. DAO stays
|
|
13
|
+
* single-table; Repository is the multi-table (aggregate) unit; Service is the
|
|
14
|
+
* use-case unit. Inter-aggregate joins are prohibited — repositories only
|
|
15
|
+
* reference each other by root ID.
|
|
16
|
+
*/
|
|
17
|
+
export interface RepositorySchema extends SchemaBase {
|
|
18
|
+
type: 'repository';
|
|
19
|
+
/** The aggregate this repository persists (shared instance). */
|
|
20
|
+
aggregate: DomainAggregate;
|
|
21
|
+
}
|
|
22
|
+
export declare function defineRepository(options: {
|
|
23
|
+
name: string;
|
|
24
|
+
aggregate: DomainAggregate;
|
|
25
|
+
description?: string;
|
|
26
|
+
}): RepositorySchema;
|
package/dist/service.d.ts
CHANGED
|
@@ -1,16 +1,38 @@
|
|
|
1
|
-
import { SchemaBase } from './dsl.js';
|
|
2
|
-
import { FrontAppSchema } from './project.js';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import type { SchemaBase } from './dsl.js';
|
|
2
|
+
import type { FrontAppSchema, ProjectApiSchema } from './project.js';
|
|
3
|
+
import type { DtoMessage } from './dto.js';
|
|
4
|
+
import type { ExceptionSchema } from './exception.js';
|
|
5
|
+
import type { FlowSchema } from './flow.js';
|
|
6
|
+
/** A backend service serving exactly one frontend app (1:1 module). */
|
|
5
7
|
export interface ServiceSchema extends SchemaBase {
|
|
6
8
|
type: 'service';
|
|
7
|
-
/** The
|
|
9
|
+
/** The backend api module this service belongs to (shared instance from
|
|
10
|
+
* project.config.ts apis). Services are always backend-side, so storage is
|
|
11
|
+
* service_schema/{api.name}/{app.name}/service/. */
|
|
12
|
+
api: ProjectApiSchema;
|
|
13
|
+
/** The frontend app this service serves (shared instance from project.config). */
|
|
8
14
|
app: FrontAppSchema;
|
|
15
|
+
/** Methods keyed by name — the map key is written back as the method name. */
|
|
16
|
+
methods: Record<string, ServiceMethodSchema>;
|
|
9
17
|
}
|
|
10
|
-
|
|
18
|
+
/** Method input for defineService: type/schema/name are set by the builder. */
|
|
19
|
+
export type ServiceMethodDef = Omit<ServiceMethodSchema, 'type' | 'schema' | 'name'>;
|
|
20
|
+
export declare function defineService(options: {
|
|
21
|
+
name: string;
|
|
22
|
+
api: ProjectApiSchema;
|
|
23
|
+
app: FrontAppSchema;
|
|
24
|
+
methods: Record<string, ServiceMethodDef>;
|
|
25
|
+
description?: string;
|
|
26
|
+
}): ServiceSchema;
|
|
11
27
|
/** A method exposed by a service. */
|
|
12
28
|
export interface ServiceMethodSchema extends SchemaBase {
|
|
13
29
|
type: 'method';
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
schema: ServiceSchema;
|
|
31
|
+
args: DtoMessage;
|
|
32
|
+
results: DtoMessage;
|
|
33
|
+
/** Exceptions this method may throw (e.g. IOException, CodeException). */
|
|
34
|
+
throws?: ExceptionSchema[];
|
|
35
|
+
/** Implementation flow — the method's logic graph. The method carries the
|
|
36
|
+
* contract (args/results/throws), the flow carries the structure. */
|
|
37
|
+
flow?: FlowSchema;
|
|
16
38
|
}
|