@pylonts/dsl 1.1.6 → 1.1.12

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.
Files changed (88) hide show
  1. package/README.md +4 -0
  2. package/dist/action.d.ts +32 -0
  3. package/dist/action.js +14 -0
  4. package/dist/aggregate.d.ts +38 -0
  5. package/dist/aggregate.js +46 -0
  6. package/dist/business-flow.d.ts +9 -0
  7. package/dist/business-flow.js +72 -0
  8. package/dist/controller.d.ts +17 -9
  9. package/dist/controller.js +8 -2
  10. package/dist/convert.d.ts +28 -10
  11. package/dist/convert.js +16 -5
  12. package/dist/curd.d.ts +7 -10
  13. package/dist/curd.js +3 -1
  14. package/dist/dao.d.ts +81 -53
  15. package/dist/dao.js +291 -12
  16. package/dist/db.d.ts +6 -0
  17. package/dist/db.js +10 -0
  18. package/dist/domain-event.d.ts +48 -0
  19. package/dist/domain-event.js +24 -0
  20. package/dist/dsl.d.ts +17 -2
  21. package/dist/dsl.js +7 -0
  22. package/dist/dto.d.ts +6 -4
  23. package/dist/dto.js +5 -4
  24. package/dist/entity.d.ts +29 -0
  25. package/dist/entity.js +13 -0
  26. package/dist/exception.d.ts +9 -3
  27. package/dist/exception.js +25 -1
  28. package/dist/expr.d.ts +45 -0
  29. package/dist/expr.js +32 -0
  30. package/dist/filter.d.ts +45 -0
  31. package/dist/filter.js +21 -0
  32. package/dist/flow-script.d.ts +108 -0
  33. package/dist/flow-script.js +505 -0
  34. package/dist/flow.d.ts +294 -17
  35. package/dist/flow.js +803 -18
  36. package/dist/index.d.ts +6 -2
  37. package/dist/index.js +6 -2
  38. package/dist/mermaid-driver.js +264 -24
  39. package/dist/mysql-driver.js +3 -0
  40. package/dist/project.d.ts +10 -6
  41. package/dist/project.js +35 -4
  42. package/dist/repository.d.ts +26 -0
  43. package/dist/repository.js +8 -0
  44. package/dist/service.d.ts +14 -2
  45. package/dist/service.js +49 -0
  46. package/dist/third-service.d.ts +5 -0
  47. package/dist/third-service.js +1 -0
  48. package/dist/typebox-driver.js +4 -0
  49. package/dist/utils.d.ts +9 -2
  50. package/dist/utils.js +4 -0
  51. package/docs/aggregate.md +110 -0
  52. package/docs/curd.md +146 -111
  53. package/docs/dao-generation.md +478 -0
  54. package/docs/ddd-principles.md +75 -0
  55. package/docs/domain-event.md +137 -0
  56. package/docs/keyword-matcher.md +182 -0
  57. package/docs/project.md +17 -9
  58. package/docs/token.md +327 -0
  59. package/docs/trans-reentrant.md +85 -0
  60. package/package.json +25 -6
  61. package/src/action.ts +51 -10
  62. package/src/aggregate.ts +104 -0
  63. package/src/business-flow.ts +80 -0
  64. package/src/controller.ts +25 -11
  65. package/src/convert.ts +51 -15
  66. package/src/curd.ts +12 -6
  67. package/src/dao.ts +377 -63
  68. package/src/db.ts +13 -0
  69. package/src/domain-event.ts +74 -0
  70. package/src/dsl.ts +23 -2
  71. package/src/dto.ts +9 -6
  72. package/src/entity.ts +43 -0
  73. package/src/exception.ts +30 -5
  74. package/src/expr.ts +65 -0
  75. package/src/filter.ts +70 -0
  76. package/src/flow-script.ts +696 -0
  77. package/src/flow.ts +1129 -46
  78. package/src/index.ts +6 -2
  79. package/src/mermaid-driver.ts +256 -29
  80. package/src/mysql-driver.ts +3 -0
  81. package/src/project.ts +138 -97
  82. package/src/repository.ts +35 -0
  83. package/src/service.ts +68 -3
  84. package/src/third-service.ts +6 -0
  85. package/src/typebox-driver.ts +4 -0
  86. package/src/utils.ts +13 -2
  87. package/src/endpoint.ts +0 -18
  88. package/src/provider.ts +0 -68
package/dist/flow.d.ts CHANGED
@@ -1,50 +1,327 @@
1
- import { SchemaBase } from './dsl.js';
1
+ import type { EnumDef, EnumValue, SchemaBase } from './dsl.js';
2
+ import type { DtoMessage } from './dto.js';
3
+ import type { DomainEventSchema } from './domain-event.js';
4
+ import type { ExceptionSchema } from './exception.js';
2
5
  import type { MethodSchema } from './method.js';
3
- import type { ConvertSchema } from './convert.js';
6
+ import type { ConvertMethodSchema } from './convert.js';
4
7
  import type { DaoMethodSchema } from './dao.js';
5
8
  import type { ServiceMethodSchema } from './service.js';
6
9
  import type { ThirdServiceMethodSchema } from './third-service.js';
7
10
  import type { UtilsMethodSchema } from './utils.js';
8
- /** A method a flow node can invoke: contract references, or a pure descriptor
11
+ /** A method a flow step can invoke: contract references, or a pure descriptor
9
12
  * (MethodSchema) for the period before the contract file exists. */
10
- export type FlowMethodRef = MethodSchema | ConvertSchema | DaoMethodSchema | ServiceMethodSchema | ThirdServiceMethodSchema | UtilsMethodSchema;
13
+ export type FlowMethodRef = MethodSchema | ConvertMethodSchema | DaoMethodSchema | ServiceMethodSchema | ThirdServiceMethodSchema | UtilsMethodSchema;
14
+ /** One named data slot of a flow — a register holding a whole object (like a
15
+ * compiler's register file). The built-in args slot carries the flow input
16
+ * (flow.args) and needs no registration: parameters exist in every flow.
17
+ * Named slots carry derived objects and are declared by binding a method's
18
+ * args/results message. The declared type is documentation — passing a slot
19
+ * to a method with a different contract converts implicitly. Slots are scoped
20
+ * to their flow: they cross into a sub-flow only through the shared input
21
+ * (flow.args) and out of it only through the wrapping node's reads/writes
22
+ * declarations. */
23
+ export interface FlowSlot {
24
+ name: string;
25
+ /** The contract message this slot was declared with (documentation only —
26
+ * call sites convert implicitly). */
27
+ type?: unknown;
28
+ description?: string;
29
+ /** Field access (e.g. slots.args.amt): resolved at access time against the
30
+ * slot's declared message fields, returning a SlotFieldRef for the
31
+ * comparison builders. Unknown fields throw with the declared field list. */
32
+ [field: string]: unknown;
33
+ }
34
+ /** A field access on a slot (slots.args.amt): the slot plus the resolved
35
+ * field object from the slot's declared message. */
36
+ export interface SlotFieldRef {
37
+ slot: FlowSlot;
38
+ /** The resolved field (DtoField | Field) — carries its schema for codegen. */
39
+ field: unknown;
40
+ }
41
+ /** A flow's slot registers: the built-in args slot plus named slots. */
42
+ export type FlowSlots = {
43
+ args: FlowSlot;
44
+ } & Record<string, FlowSlot>;
45
+ /** Declare a flow's named slots — each bound to the message of a method's
46
+ * args/results (the slot's type). The built-in args slot (the flow input)
47
+ * is added automatically: parameters need no registration. To make its
48
+ * fields accessible (slots.args.amt), declare its input message via the
49
+ * `args` key — that declares the slot's type, not a new slot. */
50
+ export declare function defineSlots<T extends Record<string, unknown>>(slots: T): {
51
+ [K in keyof T]: FlowSlot & {
52
+ name: K;
53
+ };
54
+ } & {
55
+ args: FlowSlot;
56
+ };
57
+ /** A method call with slot bindings: the arg slots are passed to the method
58
+ * (converted implicitly when the contract differs), the result is assigned
59
+ * to the result slot. A plain method ref (or an invoke with no bindings) is
60
+ * a call with args = [slots.args] and no result — the common case. */
61
+ export interface FlowCall {
62
+ method: FlowMethodRef;
63
+ /** Slots passed as the method's args — the input slot or derived slots.
64
+ * A single-message contract takes the one slot; multiple slots are for
65
+ * multi-param signatures (not modeled yet). */
66
+ args?: FlowSlot[];
67
+ /** Slot assigned from the method's results. */
68
+ result?: FlowSlot;
69
+ }
70
+ export declare function invoke(method: FlowMethodRef, options?: {
71
+ args?: FlowSlot[];
72
+ result?: FlowSlot;
73
+ }): FlowCall;
74
+ /** A node method: a plain contract reference or a call with slot bindings. */
75
+ export type FlowNodeMethodRef = FlowMethodRef | FlowCall;
76
+ export declare function isCall(m: FlowNodeMethodRef | GuardCondition): m is FlowCall;
77
+ /** The underlying method of a (possibly bound) reference. */
78
+ export declare function methodOf(m: FlowNodeMethodRef): FlowMethodRef;
79
+ /** Comparison operators of a structured condition: ordering, (in)equality
80
+ * against a literal or enum value, and null checks. */
81
+ export type CompareOp = 'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne' | 'isNull' | 'isNotNull';
82
+ /** A field comparison: a slot field (slots.args.amt) against a literal or an
83
+ * enum value — the machine-readable form of a when text. isNull/isNotNull
84
+ * take no value; the others require one. */
85
+ export interface Comparison {
86
+ kind: 'comparison';
87
+ op: CompareOp;
88
+ field: SlotFieldRef;
89
+ /** Compared-against value; null checks take none. */
90
+ value?: string | number | EnumValue;
91
+ }
92
+ /** The machine-readable condition behind a guard check or a branch edge
93
+ * (optional): a utils predicate call (its boolean result decides) or a field
94
+ * comparison. */
95
+ export type GuardCondition = FlowCall | Comparison;
96
+ export declare function lt(field: unknown, value: string | number): Comparison;
97
+ export declare function le(field: unknown, value: string | number): Comparison;
98
+ export declare function gt(field: unknown, value: string | number): Comparison;
99
+ export declare function ge(field: unknown, value: string | number): Comparison;
100
+ export declare function eq(field: unknown, value: string | number | EnumValue): Comparison;
101
+ export declare function ne(field: unknown, value: string | number | EnumValue): Comparison;
102
+ export declare function isNull(field: unknown): Comparison;
103
+ export declare function isNotNull(field: unknown): Comparison;
104
+ /** An enum value referenced by symbol — the compared-against target of eq/ne
105
+ * (e.g. eq(slots.args.state, enumValue(PayState, 'success'))). */
106
+ export declare function enumValue(def: EnumDef, symbol: string): EnumValue;
107
+ /** Event publication: a flow node may publish one domain event. The outbox
108
+ * write joins the node's surrounding transaction — the event is durable with
109
+ * the node's other side effects. The payload slot defaults to the flow input
110
+ * (slots.args) when omitted. */
111
+ export interface FlowPublish {
112
+ event: DomainEventSchema;
113
+ /** The slot carrying the event payload. */
114
+ payload?: FlowSlot;
115
+ }
11
116
  export interface FlowNode extends SchemaBase {
12
117
  /** Optional sub-flow. When present, entering this node runs the sub-flow;
13
118
  * after the sub-flow reaches any terminal node, the outer flow continues
14
- * via this node's outgoing edges. Sub-flows nest recursively. */
119
+ * via this node's outgoing edges. Sub-flows nest recursively. A plain
120
+ * sub-flow may not declare exception ends — it is structure only; use a
121
+ * tryNode for a protected region. */
15
122
  flow?: FlowSchema;
16
- /** Methods this node invokes contract references or pure descriptors
17
- * (rendered under the node label). */
18
- methods?: FlowMethodRef[];
123
+ /** Ordered execution sequence (basic block): methods run in order; if one
124
+ * throws, the remaining methods are skipped. A plain reference is a call
125
+ * receiving the input slot (slots.args) — the common case. */
126
+ methods?: FlowNodeMethodRef[];
127
+ /** A domain event published by this node (same transaction as its methods). */
128
+ publish?: FlowPublish;
129
+ /** Slots this node reads to decide its outgoing branches — a semantic
130
+ * declaration, not enforced per branch. */
131
+ reads?: FlowSlot[];
132
+ /** Slots this node assigns without a method call (constructions). */
133
+ writes?: FlowSlot[];
134
+ }
135
+ /** One gate check: when the condition holds, either return (early return to
136
+ * the flow's returnEnd) or throw the given exception (routed implicitly to
137
+ * the flow's exception end carrying the same name). Exactly one of
138
+ * return/exception must be set. */
139
+ export interface GuardCheck {
140
+ /** Condition description shown on the branch edge. */
141
+ when: string;
142
+ /** The check returns early (to the flow's returnEnd) — no edge needed. */
143
+ return?: boolean;
144
+ /** The check throws this exception — routed implicitly to the flow's
145
+ * exception end carrying the same name (no edge needed). */
146
+ exception?: ExceptionSchema;
147
+ /** Slots the check reads to decide. */
148
+ reads?: FlowSlot[];
149
+ /** Machine-readable condition behind `when` (optional): a utils predicate
150
+ * call or a field comparison. Omitted when the condition stays descriptive. */
151
+ check?: GuardCondition;
152
+ }
153
+ /** Gate executor: an ordered set of checks. The first check whose condition
154
+ * holds routes out implicitly (return to the flow's return end, throw to the
155
+ * matching exception end); when none holds, the guard falls through its
156
+ * normal outgoing edges (linked with edge like any node). A guard is the
157
+ * graph form of a run of `if (bad) throw / return` guards. */
158
+ export interface GuardNode extends SchemaBase {
159
+ type: 'guard';
160
+ /** Ordered decision sequence: methods run in order; if one throws, the
161
+ * remaining methods are skipped. */
162
+ methods?: FlowNodeMethodRef[];
163
+ /** Ordered checks — first hit wins. */
164
+ checks: GuardCheck[];
165
+ }
166
+ /** One catch route of a TryNode: body exception type → handler sub-flow.
167
+ * First match wins, UnexpectedException is the catch-all and must come
168
+ * last. The handler's exception ends rethrow out of the TryNode. */
169
+ export interface TryCatch {
170
+ /** Exception this catch handles — must match a body exception end. */
171
+ exception: ExceptionSchema;
172
+ /** Handler sub-flow: its return end falls through, its exception ends
173
+ * rethrow (declared as the TryNode's own throws). */
174
+ handler: FlowSchema;
175
+ description?: string;
176
+ }
177
+ /** Protected region: body, catch handlers, and optional finally are all
178
+ * sub-flows. Entering the TryNode runs the body; the body's exception ends
179
+ * are matched against the catches, every catch handler and the body's normal
180
+ * completion pass through finally (when present), then continue via the
181
+ * TryNode's outgoing edges. Handler exception ends rethrow out of the region. */
182
+ export interface TryNode extends SchemaBase {
183
+ type: 'try';
184
+ /** The protected region. Its exception ends are the region's throw sites. */
185
+ body: FlowSchema;
186
+ /** Ordered catch routes; UnexpectedException (catch-all) must be last. */
187
+ catches: TryCatch[];
188
+ /** Cleanup sub-flow: may not declare exception ends (Java finally rules). */
189
+ finally?: FlowSchema;
190
+ }
191
+ /** One branch of an ifNode: when the check holds, control moves to `to`. */
192
+ export interface IfCase {
193
+ /** Branch label (rendered on the branch line). */
194
+ when: string;
195
+ /** Machine-readable condition — required (the ifNode's whole purpose). */
196
+ check: GuardCondition;
197
+ /** Jump target: a step (node/guard/tryNode/ifNode). Flow exits — return
198
+ * and throw — belong to guard checks, so ends are rejected. */
199
+ to: FlowNodeOrEnd;
19
200
  }
201
+ /** Decision node — the jump twin of a guard: ordered cases evaluated
202
+ * first-hit, the first check that holds routes to its target; when none
203
+ * holds, control goes to `else`. All exits are internal (cases and else),
204
+ * so the node has no outgoing edges. A guard decides exits (return/throw),
205
+ * an ifNode decides where control goes next (steps only). */
206
+ export interface IfNode extends SchemaBase {
207
+ type: 'if';
208
+ /** Ordered branches — first hit wins. */
209
+ cases: IfCase[];
210
+ /** Default branch: a step (never a flow exit). */
211
+ else: FlowNodeOrEnd;
212
+ }
213
+ /** Decision node: ordered cases (check → target) plus a default branch. */
214
+ export declare function ifNode(name: string, options: {
215
+ cases: IfCase[];
216
+ else: FlowNodeOrEnd;
217
+ description?: string;
218
+ }): IfNode;
219
+ /** Any node an edge can start from. */
220
+ export type FlowStep = FlowNode | GuardNode | TryNode | IfNode;
221
+ /** Any node an edge can point at: a step or a flow exit. */
222
+ export type FlowNodeOrEnd = FlowStep | FlowEnd;
223
+ /** A flow exit: normal return or uncaught exception. Never an edge start. */
224
+ export interface FlowEnd extends SchemaBase {
225
+ type: 'return' | 'exception';
226
+ /** Uncaught exception this exit throws — set when type='exception'. */
227
+ exception?: ExceptionSchema;
228
+ }
229
+ /** The flow's exception end carrying the given exception name — the implicit
230
+ * target of a guard check throwing it. Undefined when the flow has no such
231
+ * end (guard checks synthesize one at definition time, so this only happens
232
+ * for hand-assembled flows). */
233
+ export declare function findExceptionEnd(schema: FlowSchema, exceptionName: string): FlowEnd | undefined;
234
+ /** Where a throw of `exceptionName` from step `n` lands: the target of a typed
235
+ * throws edge (first match), or an untyped exception edge as catch-all.
236
+ * Undefined when no route exists (validation error). Guards route implicitly
237
+ * — see findExceptionEnd.
238
+ * @deprecated no internal use remains; kept for API compatibility. */
239
+ export declare function resolveThrowTarget(schema: FlowSchema, n: FlowStep, exceptionName: string): FlowNodeOrEnd | undefined;
20
240
  export interface FlowEdge extends SchemaBase {
21
241
  /** Trigger condition; undefined = default path (success/normal). */
22
242
  when?: string;
23
- start: FlowNode;
24
- end: FlowNode;
25
- /** Exception path (rendered dashed); defaults to normal. */
243
+ start: FlowStep;
244
+ end: FlowNodeOrEnd;
245
+ /** Exception path (rendered dashed); without `throws` it is a catch-all. */
26
246
  exception?: boolean;
247
+ /** Typed exception propagation: this edge carries the named exception
248
+ * (rendered dashed with a `throw X` label). Must target an exception end.
249
+ * Carrying one of a guard's own check exceptions is rejected — guards
250
+ * route those implicitly. */
251
+ throws?: ExceptionSchema;
252
+ /** Machine-readable condition behind `when` (optional): a utils predicate
253
+ * call or a field comparison. */
254
+ check?: GuardCondition;
27
255
  }
28
256
  export interface FlowSchema extends SchemaBase {
29
257
  /** Entry node. */
30
- start: FlowNode;
258
+ start: FlowStep;
259
+ /** Default exit — every flow has one; edge(node, flow.returnEnd) is a return. */
260
+ returnEnd: FlowEnd;
31
261
  /** All nodes, collected from edges (deduplicated by object identity). */
32
- nodes: FlowNode[];
262
+ nodes: FlowNodeOrEnd[];
33
263
  /** Independent edges; a node may be start of many edges, so cycles are expressible. */
34
264
  edges: FlowEdge[];
265
+ /** Input contract — mirrors a service method's args. */
266
+ args?: DtoMessage;
267
+ /** Output contract — mirrors a service method's results. */
268
+ results?: DtoMessage;
269
+ /** Declared slot registers of this flow (named slots + the built-in args
270
+ * slot). Sub-flows analyze their own slots; sharing happens through the
271
+ * same input object (args) or the wrapping node's reads/writes. */
272
+ slots?: FlowSlots;
273
+ /** Slots the enclosing flow has already produced before this sub-flow's
274
+ * entry (input inheritance). Only meaningful for sub-flows (try bodies,
275
+ * catch handlers, named sub-flows) — a top-level flow has none. */
276
+ entrySlots?: FlowSlot[];
35
277
  }
278
+ /** Executor node: an ordered sequence of method invocations (and optionally
279
+ * one event publication). */
36
280
  export declare function node(name: string, options?: {
37
281
  flow?: FlowSchema;
38
282
  description?: string;
39
- methods?: FlowMethodRef[];
283
+ methods?: FlowNodeMethodRef[];
284
+ publish?: FlowPublish;
285
+ reads?: FlowSlot[];
286
+ writes?: FlowSlot[];
40
287
  }): FlowNode;
41
- export declare function edge(start: FlowNode, end: FlowNode, options?: {
288
+ /** Guard node: a gate executor — ordered checks, first hit routes out;
289
+ * all misses fall through the guard's normal outgoing edges. */
290
+ export declare function guard(name: string, options: {
291
+ checks: GuardCheck[];
292
+ methods?: FlowNodeMethodRef[];
293
+ description?: string;
294
+ }): GuardNode;
295
+ /** Try node: a protected region whose body, catch handlers, and optional
296
+ * finally are sub-flows. */
297
+ export declare function tryNode(name: string, options: {
298
+ body: FlowSchema;
299
+ catches: TryCatch[];
300
+ finally?: FlowSchema;
301
+ description?: string;
302
+ }): TryNode;
303
+ export declare function defineExceptionEnd(exception: ExceptionSchema, description?: string): FlowEnd;
304
+ export declare function edge(start: FlowStep, end: FlowNodeOrEnd, options?: {
42
305
  when?: string;
43
306
  description?: string;
44
307
  exception?: boolean;
308
+ throws?: ExceptionSchema;
309
+ check?: GuardCondition;
45
310
  }): FlowEdge;
46
311
  export declare function defineFlow(name: string, schema: {
47
- start: FlowNode;
48
- edges: FlowEdge[];
312
+ start: FlowStep;
313
+ edges: (flow: FlowSchema) => FlowEdge[];
314
+ args?: DtoMessage;
315
+ results?: DtoMessage;
316
+ slots?: FlowSlots;
317
+ entrySlots?: FlowSlot[];
49
318
  description?: string;
50
319
  }): FlowSchema;
320
+ /** Exception names declared by a flow's exception ends — the flow's escape
321
+ * set (throws that reach the caller unless caught by an outer tryNode). */
322
+ export declare function exceptionEndNames(flow: FlowSchema): Set<string>;
323
+ export declare function isEnd(n: FlowNodeOrEnd): n is FlowEnd;
324
+ export declare function isFlowNode(n: FlowNodeOrEnd): n is FlowNode;
325
+ export declare function isGuard(n: FlowNodeOrEnd): n is GuardNode;
326
+ export declare function isTryNode(n: FlowNodeOrEnd): n is TryNode;
327
+ export declare function isIfNode(n: FlowNodeOrEnd): n is IfNode;