@sincpro/client-framework 1.1.0 → 1.3.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 +51 -17
- package/MANIFESTO.md +9 -7
- package/README.md +261 -131
- package/dist/client/services/guarded.d.ts +1 -1
- package/dist/client/services/propagation.js +4 -3
- package/dist/codegen/services/scaffold.d.ts +12 -10
- package/dist/codegen/services/scaffold.js +29 -51
- package/dist/context/entrypoint/context.d.ts +5 -4
- package/dist/core/domain/bus.d.ts +5 -3
- package/dist/core/domain/bus.js +8 -1
- package/dist/core/domain/dto.d.ts +71 -9
- package/dist/core/domain/dto.js +25 -5
- package/dist/core/domain/errors.d.ts +2 -2
- package/dist/core/domain/pipeline.d.ts +8 -5
- package/dist/core/domain/services.d.ts +40 -13
- package/dist/core/domain/services.js +31 -7
- package/dist/core/entrypoint/bounded-context.d.ts +71 -41
- package/dist/core/entrypoint/bounded-context.js +155 -56
- package/dist/core/entrypoint/screens.js +0 -5
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +4 -3
- package/dist/core/infrastructure/listeners.d.ts +6 -5
- package/dist/core/infrastructure/listeners.js +2 -2
- package/dist/core/services/dto-keys.d.ts +44 -0
- package/dist/core/services/dto-keys.js +97 -0
- package/dist/core/services/execution.d.ts +15 -10
- package/dist/core/services/execution.js +36 -23
- 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 +8 -7
- package/dist/event_driven/adapters/stored-queue.js +8 -12
- 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 +3 -3
- package/dist/event_driven/entrypoint/publisher.js +5 -1
- package/dist/event_driven/entrypoint/subscriber.d.ts +66 -19
- package/dist/event_driven/entrypoint/subscriber.js +122 -15
- package/dist/event_driven/index.d.ts +11 -7
- package/dist/event_driven/index.js +9 -6
- package/dist/event_driven/services/messages.d.ts +41 -0
- package/dist/event_driven/services/messages.js +147 -0
- package/dist/observability/adapters/memory.d.ts +1 -1
- package/dist/observability/domain/logging.d.ts +2 -2
- package/dist/observability/services/logging.d.ts +6 -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/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;
|
|
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,26 +70,60 @@ 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
|
-
|
|
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.** One use case of an
|
|
93
|
+
event per bounded context; the queue's one `Subscriber` executes an event in each. `storedQueue` holds the rules — store first, deliver in order,
|
|
94
|
+
retry what may succeed, set aside what never will, never run one who heard it twice — over an
|
|
95
|
+
`EventStore` the platform plugs (SQLite, IndexedDB, memory). A store only keeps records; it
|
|
96
|
+
never decides.
|
|
97
|
+
- **The Subscriber is the queue's only entrypoint.** It hears a list of events or every event its
|
|
98
|
+
bounded contexts registered, recognizes a message (an event by name, a Command by identity),
|
|
99
|
+
rebuilds and executes it — as the backend's `Subscriber(*buses)` / `QueueGateway`. Nobody
|
|
100
|
+
writes a subscriber per event: registering a use case for the event is the subscription. A
|
|
101
|
+
Command from a queue runs only when declared (`commands`), in the one bus that registered it;
|
|
102
|
+
`CommandNotConsumed` otherwise. Two bounded contexts never share a name.
|
|
103
|
+
- **Messages are the backend's: CloudEvents 1.0.** One shape for Commands and events — `type` is
|
|
104
|
+
the event's name or the Command's identity —; the route differs (N buses, or the one that
|
|
105
|
+
registered it, when declared). `readMessage` reads structured and binary mode (`ce_` headers),
|
|
106
|
+
as `Envelope.of`. A delivered message's `correlationid`, `causationid` and `traceparent` become
|
|
107
|
+
the run's `Cause`: its flow and its trace continue. Written and read only through
|
|
108
|
+
`eventMessageOf`/`commandMessageOf`, `readMessage` and `eventFrom`/`commandFrom`.
|
|
109
|
+
- **A cron is a platform's, and not every platform has one.** Mobile's scheduler wakes a closed
|
|
110
|
+
app (`CronWorker`, its job a Command); a browser runs nothing in a closed tab, so on the web a
|
|
111
|
+
refresh is a screen's and scheduled work is the backend's. No cron piece lives here until web
|
|
112
|
+
needs one — then a registry and a `Scheduler` port.
|
|
113
|
+
- **A bounded context injected into a run is bound to it** (`BIND`): what it executes is a child
|
|
114
|
+
of the caller — span, flow, cause, signal, one report — with its own dependencies, context and
|
|
115
|
+
handlers. A failure keeps the outcome where it first failed, so a caller does not report what
|
|
116
|
+
the callee expected.
|
|
117
|
+
- **A bounded context is named for what it is.** `salesBoundedContext`, never `sales` (an
|
|
118
|
+
entity?) and never `ctx` or `bc`: `context` is already the run's. The scaffold writes it so.
|
|
86
119
|
- **A circuit belongs where the dependency is.** `CircuitBreaker` (in the process's memory, the
|
|
87
120
|
backend's semantics: `COUNTED_KINDS`, half-open with one probe) guards a transport
|
|
88
121
|
(`guardedTransport`) or an adapter; its `CircuitOpen` declares `unavailable` and a wait, so
|
|
89
122
|
nothing else needs to know a circuit exists.
|
|
90
|
-
- **Delivery is at least once.** A stored
|
|
91
|
-
|
|
92
|
-
sets aside what keeps failing. One process drains a store. `execution` is
|
|
123
|
+
- **Delivery is at least once.** A stored message may run twice after a crash. The use case keys
|
|
124
|
+
its effect by `this.execution.causationId` (the message's id) or by the entity the event names.
|
|
125
|
+
`maxAttempts` sets aside what keeps failing. One process drains a store. `execution` is
|
|
126
|
+
reserved.
|
|
93
127
|
- **A failure says its kind, whatever the wire.** `failureOf` reads a declared `failureKind`, the
|
|
94
128
|
`Problem` (the same over REST, JSON-RPC and gRPC), then a REST status. A transport of another
|
|
95
129
|
wire, or another backend's adapter, declares the kind with `kindOfGrpcCode` /
|
|
@@ -153,7 +187,7 @@ options)`: no route, no verb, no RPC method. The contract's bindings (`rest`, `r
|
|
|
153
187
|
- **An error handler answers; it does not observe.** The failure is recorded where it happened —
|
|
154
188
|
span, log line, report — before the layer's handlers run, as in sincpro_framework. A handler
|
|
155
189
|
returns the answer or throws to the next; the global chain wraps only `execute` and `scoped`.
|
|
156
|
-
- **The application layer imports no logger.** A bounded context has `
|
|
190
|
+
- **The application layer imports no logger.** A bounded context has `projectBoundedContext.logger`; a run
|
|
157
191
|
hands `this.logger`, bound to its execution. Only `logger` (infrastructure, the global one) and
|
|
158
192
|
`loggerAdapter` are predefined; injected as a dependency they bind to the run (`BIND`), imported
|
|
159
193
|
at module level they do not. No logger is predefined for an application layer. Console is the
|
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
|
|
@@ -48,7 +48,7 @@ server-side render, in a script and in a test, unchanged.**
|
|
|
48
48
|
in a global stack: two calls at once never mix their parents.
|
|
49
49
|
5. **Bounded contexts.** Set up like the backend's — its dependencies (`addDependency`), its
|
|
50
50
|
Features and ApplicationServices, registered for class DTOs — and called as
|
|
51
|
-
`
|
|
51
|
+
`projectBoundedContext.execute(new Command(...))`. The bounded context is the bus. An application is the set
|
|
52
52
|
of bounded contexts it loads; they never import each other's insides.
|
|
53
53
|
6. **The client.** The `OperationTransport` port — an operation called by who it is, over any
|
|
54
54
|
wire — with its REST and JSON-RPC adapters (a platform adds gRPC or its own); the `Transport`
|
|
@@ -67,16 +67,18 @@ server-side render, in a script and in a test, unchanged.**
|
|
|
67
67
|
10. **The command core (`./core`).** The single model matching the backend's application
|
|
68
68
|
abstractions: class DTOs and Responses, a bounded context that is a bus, Features and
|
|
69
69
|
ApplicationServices registered for DTO classes, attribute-injected dependencies and a
|
|
70
|
-
feature bus for composition, domain events
|
|
70
|
+
feature bus for composition, domain events as the input of a use case, replacements,
|
|
71
71
|
and the backend's error handlers — global, feature and application service — with the
|
|
72
72
|
errors a bounded context expects. The internal engine uses
|
|
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
|
-
|
|
79
|
-
|
|
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 only entrypoint: events heard, Commands consumed only when declared —, the queue that
|
|
79
|
+
delivers in the call, and the stored queue's rules over an `EventStore` the platform plugs.
|
|
80
|
+
The guidelines, the rules and the contracts are here; where events are kept is the
|
|
81
|
+
platform's.
|
|
80
82
|
12. **Resilience.** What a failure is (`failureOf`, the backend's kinds on every wire) and the
|
|
81
83
|
backend's circuit breaker, guarding any transport or adapter.
|
|
82
84
|
|