@sincpro/client-framework 1.2.0 → 1.4.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/AGENTS.md +57 -27
- package/MANIFESTO.md +5 -4
- package/README.md +225 -157
- package/dist/client/services/propagation.js +4 -3
- package/dist/codegen/services/scaffold.d.ts +12 -10
- package/dist/codegen/services/scaffold.js +23 -40
- package/dist/core/domain/bus.d.ts +5 -3
- package/dist/core/domain/bus.js +8 -1
- package/dist/core/domain/consumers.d.ts +19 -0
- package/dist/core/domain/consumers.js +1 -0
- package/dist/core/domain/dto.d.ts +68 -6
- package/dist/core/domain/dto.js +22 -2
- package/dist/core/domain/pipeline.d.ts +7 -3
- package/dist/core/domain/services.d.ts +97 -14
- package/dist/core/domain/services.js +65 -6
- package/dist/core/entrypoint/bounded-context.d.ts +86 -35
- package/dist/core/entrypoint/bounded-context.js +224 -71
- package/dist/core/entrypoint/screens.js +0 -5
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +4 -3
- package/dist/core/infrastructure/listeners.d.ts +5 -4
- package/dist/core/infrastructure/listeners.js +1 -1
- package/dist/core/services/dto-keys.d.ts +44 -0
- package/dist/core/services/dto-keys.js +97 -0
- package/dist/core/services/event-handlers.d.ts +57 -0
- package/dist/core/services/event-handlers.js +114 -0
- package/dist/core/services/execution.d.ts +15 -21
- package/dist/core/services/execution.js +38 -32
- package/dist/core/services/interceptors.d.ts +2 -2
- package/dist/core/services/interceptors.js +5 -5
- package/dist/core/services/listening.d.ts +6 -8
- package/dist/core/services/listening.js +3 -2
- package/dist/event_driven/adapters/stored-queue.d.ts +5 -5
- package/dist/event_driven/adapters/stored-queue.js +5 -10
- package/dist/event_driven/domain/envelope.d.ts +2 -2
- package/dist/event_driven/domain/envelope.js +7 -1
- package/dist/event_driven/domain/messages.d.ts +34 -0
- package/dist/event_driven/domain/messages.js +1 -0
- package/dist/event_driven/domain/queue.d.ts +9 -5
- package/dist/event_driven/entrypoint/publisher.d.ts +2 -2
- package/dist/event_driven/entrypoint/publisher.js +4 -0
- package/dist/event_driven/entrypoint/subscriber.d.ts +122 -29
- package/dist/event_driven/entrypoint/subscriber.js +277 -33
- package/dist/event_driven/index.d.ts +11 -10
- package/dist/event_driven/index.js +9 -9
- package/dist/event_driven/services/messages.d.ts +41 -0
- package/dist/event_driven/services/messages.js +147 -0
- package/dist/observability/domain/logging.d.ts +4 -8
- package/dist/observability/services/logging.d.ts +3 -3
- package/dist/observability/services/logging.js +1 -1
- package/dist/observability/services/trace-context.d.ts +10 -0
- package/dist/observability/services/trace-context.js +29 -0
- package/package.json +2 -2
- package/dist/event_driven/entrypoint/subscriptions.d.ts +0 -110
- package/dist/event_driven/entrypoint/subscriptions.js +0 -184
package/AGENTS.md
CHANGED
|
@@ -33,7 +33,7 @@ module has only the layers it needs, and says what it offers in its own `index.t
|
|
|
33
33
|
| `src/client/` | `Transport`, `entity()`, the contract (domain); REST, memory, Parquet; discovery, propagation |
|
|
34
34
|
| `src/model/` | Model definitions: `defineMeta`, from a JSON Schema, the store of known ones |
|
|
35
35
|
| `src/core/` | DTOs and events, bus, services, handlers, extension points; pipeline; `BoundedContext`; process |
|
|
36
|
-
| `src/event_driven/` | `Envelope`, `EventQueue`/`Subscribes` ports; queues; `Publisher`, `Subscriber
|
|
36
|
+
| `src/event_driven/` | `Envelope`, messages, `EventQueue`/`Subscribes` ports; queues; `Publisher`, `Subscriber` |
|
|
37
37
|
| `src/codegen/` | The generator and its CLI (`sincpro-client generate`) — the only place Node is allowed |
|
|
38
38
|
| `src/testing/` | The public entry of the in-memory observability adapters |
|
|
39
39
|
| `tests/` | vitest in Node, one folder per module; `tests/support/` holds fakes and forge's contracts |
|
|
@@ -70,27 +70,58 @@ module has only the layers it needs, and says what it offers in its own `index.t
|
|
|
70
70
|
- **A service is a singleton of its generation.** What a method writes on `this` lands on the
|
|
71
71
|
instance, shared by the next call, the call beside it and every `scoped` variant — as in
|
|
72
72
|
sincpro_framework. What belongs to one request goes in its arguments or its context.
|
|
73
|
-
- **A
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
- **A service's name is the framework's, taken at registration.** A standard decorator hands it
|
|
74
|
+
the class's name as the code wrote it (`context.name`, untouched by a minifier); otherwise the
|
|
75
|
+
class's `name` — so a production build keeps class names (`keep_classnames`, `keepNames`).
|
|
76
|
+
`class Cancel` gives `project/Cancel`, identity `project.Cancel`. Nothing on a service declares
|
|
77
|
+
it. Commands and events route by exact constructor identity — a generated one by its identity
|
|
78
|
+
or wire name.
|
|
79
|
+
- **An event's name is declared; a Command's identity is the framework's.** `static eventName` is
|
|
80
|
+
required and dotted (`<context>.<aggregate>.vN.<fact>`); `name` is reserved for it. A Command's
|
|
81
|
+
identity is given when a bounded context registers it — `<context>.<Command>`, the backend's
|
|
82
|
+
`registered_name`, the key a generated contract carries —; `static commandName` fixes another.
|
|
77
83
|
- **A replacement names what it replaces.** `feature(dto, { replaces: Service })` is refused
|
|
78
|
-
unless `Service` is registered now for
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
unless `Service` is registered now for each DTO listed — all of them or none; its spans carry
|
|
85
|
+
`sincpro.replaces`.
|
|
86
|
+
- **A service takes N DTOs; a DTO has one service.** `feature([CommandX, EventY])`, as the
|
|
87
|
+
backend's `DTORegistration`; one instance per service and generation.
|
|
88
|
+
- **Dependencies are the context's.** `servicesWith<Dependencies>()` gives the bases every
|
|
89
|
+
dependency typed — the backend's `class Feature(_Feature, DependencyContextType)` —; a service
|
|
90
|
+
never declares one. A scaffold writes `dependencies.ts` and `framework.ts`; the instance lives in
|
|
91
|
+
`framework.ts` because ES modules run their imports first.
|
|
92
|
+
- **How events are carried is here; where they are kept is the platform's.** An event's
|
|
93
|
+
consumers are acknowledged apart: a bounded context's use case for it (one per bounded context,
|
|
94
|
+
keyed by its name), its event handlers and a subscriber's (`<owner>/<Handler>`). `storedQueue`
|
|
95
|
+
holds the rules — store first, deliver in order, retry what may succeed, set aside what never
|
|
96
|
+
will, never run one consumer twice — over an `EventStore` the platform plugs (SQLite,
|
|
97
|
+
IndexedDB, memory). A store only keeps records; it never decides.
|
|
98
|
+
- **The Subscriber is the queue's entrypoint, and it is composite.** One per queue — never one
|
|
99
|
+
per handler —, created once like a bounded context (`new Subscriber<D>("app")`,
|
|
100
|
+
`handlersWith<D>()`). It pulls what the queue delivers, rebuilds it (an event by name, a Command
|
|
101
|
+
by identity) and hands it to every consumer subscribed to it: its own event handlers, and the
|
|
102
|
+
buses added to it — each with its use case for the event and its own handlers. Two levels, never
|
|
103
|
+
mixed: `addDependency("x", value)` is what its handlers find on `this` (a bus they call is a
|
|
104
|
+
dependency); `addBus(bus)` — no name, the bus's namespace — is a bus it delivers to. The same
|
|
105
|
+
bus added again changes nothing; another bus of the same name is delivered to as well
|
|
106
|
+
(`sales#2`). A Command from a queue runs only when declared (`commands`), in the one bus that
|
|
107
|
+
registered it; `CommandNotConsumed` otherwise.
|
|
108
|
+
- **An event has three kinds of consumers, one API.** Its use case on a bus
|
|
109
|
+
(`@bus.feature([CommandX, Event])`, the event is its input); an event handler of a bus
|
|
110
|
+
(`@bus.handler([EventA, EventB])`, a layer above its use cases: the bus's dependencies and
|
|
111
|
+
`this.boundedContext`); an event handler of a subscriber (`@subscriber.handler([...])`, its
|
|
112
|
+
explicit dependencies). A handler decides nothing — it executes Commands —; it runs in the
|
|
113
|
+
pipeline of a use case, in its own layer (`event_handler`), and is registered with or without a
|
|
114
|
+
decorator.
|
|
115
|
+
- **Messages are the backend's: CloudEvents 1.0.** One shape for Commands and events — `type` is
|
|
116
|
+
the event's name or the Command's identity —; the route differs (N buses, or the one that
|
|
117
|
+
registered it, when declared). `readMessage` reads structured and binary mode (`ce_` headers),
|
|
118
|
+
as `Envelope.of`. A delivered message's `correlationid`, `causationid` and `traceparent` become
|
|
119
|
+
the run's `Cause`: its flow and its trace continue. Written and read only through
|
|
120
|
+
`eventMessageOf`/`commandMessageOf`, `readMessage` and `eventFrom`/`commandFrom`.
|
|
121
|
+
- **A cron is a platform's, and not every platform has one.** Mobile's scheduler wakes a closed
|
|
122
|
+
app (`CronWorker`, its job a Command); a browser runs nothing in a closed tab, so on the web a
|
|
123
|
+
refresh is a screen's and scheduled work is the backend's. No cron piece lives here until web
|
|
124
|
+
needs one — then a registry and a `Scheduler` port.
|
|
94
125
|
- **A bounded context injected into a run is bound to it** (`BIND`): what it executes is a child
|
|
95
126
|
of the caller — span, flow, cause, signal, one report — with its own dependencies, context and
|
|
96
127
|
handlers. A failure keeps the outcome where it first failed, so a caller does not report what
|
|
@@ -101,10 +132,8 @@ module has only the layers it needs, and says what it offers in its own `index.t
|
|
|
101
132
|
backend's semantics: `COUNTED_KINDS`, half-open with one probe) guards a transport
|
|
102
133
|
(`guardedTransport`) or an adapter; its `CircuitOpen` declares `unavailable` and a wait, so
|
|
103
134
|
nothing else needs to know a circuit exists.
|
|
104
|
-
- **Delivery is at least once.** A stored
|
|
105
|
-
|
|
106
|
-
finds the same id in its own run and hands it in the Command it executes — the use case's
|
|
107
|
-
`causationId` is the subscriber's run —, or the effect is keyed by the entity the event names.
|
|
135
|
+
- **Delivery is at least once.** A stored message may run twice after a crash. The use case keys
|
|
136
|
+
its effect by `this.execution.causationId` (the message's id) or by the entity the event names.
|
|
108
137
|
`maxAttempts` sets aside what keeps failing. One process drains a store. `execution` is
|
|
109
138
|
reserved.
|
|
110
139
|
- **A failure says its kind, whatever the wire.** `failureOf` reads a declared `failureKind`, the
|
|
@@ -196,5 +225,6 @@ make test
|
|
|
196
225
|
make build
|
|
197
226
|
```
|
|
198
227
|
|
|
199
|
-
Never bump `version` in `package.json` — the release pipeline does.
|
|
200
|
-
|
|
228
|
+
Never bump `version` in `package.json` — the release pipeline does. Commit on a working branch,
|
|
229
|
+
never on `main`: a change reaches `main` through a pull request, and further changes of the same
|
|
230
|
+
work go into that one pull request.
|
package/MANIFESTO.md
CHANGED
|
@@ -34,7 +34,7 @@ server-side render, in a script and in a test, unchanged.**
|
|
|
34
34
|
`bus_pipeline`: interceptors control a run (look, veto, adjust, answer); listeners hear it
|
|
35
35
|
start, answer or fail, and never change it; an extension wires a component in one place.
|
|
36
36
|
3. **Observability, as ports.** `Tracer`, `ErrorReporter` and `Logger` are the contracts: one span per use
|
|
37
|
-
case, named `<bounded context>/<
|
|
37
|
+
case, named `<bounded context>/<Service>`; the unexpected reported
|
|
38
38
|
with its trace id; what the server already explained (a validation, a conflict), or what a
|
|
39
39
|
bounded context declares expected, not reported.
|
|
40
40
|
The platform plugs the implementation — OpenTelemetry, GlitchTip, a queue on the phone, memory
|
|
@@ -73,9 +73,10 @@ server-side render, in a script and in a test, unchanged.**
|
|
|
73
73
|
the injected process ports. Remote clients and mapping remain distinct.
|
|
74
74
|
11. **Event-driven, as ports (`event_driven`).** How every platform publishes domain events and
|
|
75
75
|
subscribes to them the same way: the envelope that travels beside an event (its flow and
|
|
76
|
-
its cause),
|
|
77
|
-
`
|
|
78
|
-
|
|
76
|
+
its cause), how a Command and an event are written and read (each its own way), the
|
|
77
|
+
`EventQueue` and `Subscribes` ports, a `Publisher` a Feature holds, the `Subscriber` — the
|
|
78
|
+
queue's composite entrypoint: its event handlers and the buses added to it, Commands
|
|
79
|
+
consumed only when declared —, the queue that
|
|
79
80
|
delivers in the call, and the stored queue's rules over an `EventStore` the platform plugs.
|
|
80
81
|
The guidelines, the rules and the contracts are here; where events are kept is the
|
|
81
82
|
platform's.
|