@sincpro/client-framework 1.6.0 → 1.7.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.
Files changed (36) hide show
  1. package/AGENTS.md +21 -6
  2. package/README.md +46 -28
  3. package/dist/client/adapters/json-rpc.js +3 -2
  4. package/dist/client/adapters/memory.js +3 -2
  5. package/dist/client/adapters/rest-operations.js +3 -2
  6. package/dist/client/adapters/rest.js +3 -2
  7. package/dist/client/index.d.ts +1 -1
  8. package/dist/client/index.js +1 -1
  9. package/dist/client/services/guarded.js +4 -3
  10. package/dist/client/services/propagation.d.ts +21 -9
  11. package/dist/client/services/propagation.js +60 -3
  12. package/dist/core/entrypoint/screens.js +2 -1
  13. package/dist/core/services/binding.d.ts +5 -2
  14. package/dist/core/services/binding.js +5 -8
  15. package/dist/event_driven/adapters/memory-message-store.d.ts +10 -0
  16. package/dist/event_driven/adapters/{memory-event-store.js → memory-message-store.js} +3 -3
  17. package/dist/event_driven/adapters/stored-queue.d.ts +51 -42
  18. package/dist/event_driven/adapters/stored-queue.js +137 -89
  19. package/dist/event_driven/adapters/sync-queue.d.ts +4 -3
  20. package/dist/event_driven/adapters/sync-queue.js +11 -5
  21. package/dist/event_driven/domain/queue.d.ts +19 -10
  22. package/dist/event_driven/domain/store.d.ts +26 -21
  23. package/dist/event_driven/domain/verdict.d.ts +86 -0
  24. package/dist/event_driven/domain/verdict.js +80 -0
  25. package/dist/event_driven/entrypoint/publisher.d.ts +14 -8
  26. package/dist/event_driven/entrypoint/publisher.js +16 -5
  27. package/dist/event_driven/entrypoint/subscriber.d.ts +9 -1
  28. package/dist/event_driven/entrypoint/subscriber.js +16 -5
  29. package/dist/event_driven/index.d.ts +13 -12
  30. package/dist/event_driven/index.js +11 -10
  31. package/dist/event_driven/services/messages.d.ts +7 -0
  32. package/dist/event_driven/services/messages.js +22 -0
  33. package/dist/observability/adapters/console.d.ts +0 -4
  34. package/dist/observability/adapters/console.js +12 -4
  35. package/package.json +1 -1
  36. package/dist/event_driven/adapters/memory-event-store.d.ts +0 -10
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`, messages, `EventQueue`/`Subscribes` ports; queues; `Publisher`, `Subscriber` |
36
+ | `src/event_driven/` | `Envelope`, messages, `MessageQueue`/`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 |
@@ -92,8 +92,8 @@ module has only the layers it needs, and says what it offers in its own `index.t
92
92
  - **How events are carried is here; where they are kept is the platform's.** An event's
93
93
  consumers are acknowledged apart: a bounded context's use case for it (one per bounded context,
94
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,
95
+ holds the rules — store first, deliver in order, decide by the verdict (`verdictOf`), never
96
+ run one consumer twice — over a `MessageStore` the platform plugs (SQLite,
97
97
  IndexedDB, memory). A store only keeps records; it never decides.
98
98
  - **The Subscriber is the queue's entrypoint, and it is composite.** One per queue — never one
99
99
  per handler —, created once like a bounded context (`new Subscriber<D>("app")`,
@@ -134,7 +134,12 @@ module has only the layers it needs, and says what it offers in its own `index.t
134
134
  nothing else needs to know a circuit exists.
135
135
  - **Delivery is at least once.** A stored message may run twice after a crash. The use case keys
136
136
  its effect by `this.execution.causationId` (the message's id) or by the entity the event names.
137
- `maxAttempts` sets aside what keeps failing. One process drains a store. `execution` is
137
+ A message is sent once (`retries: 0`) and a failure is set aside; what goes over the network
138
+ (`requiresNetwork`) waits while the other side is not there (`WAITING_KINDS`), until
139
+ `maxAttempts`. A platform extends the rules by wrapping `verdictOf`, never in the queue.
140
+ - **A Command can travel too.** `publisher.send(command)` stores an intention; the bus that
141
+ consumes it (the subscriber's `commands`) runs it when it can, and its answer is kept. Its
142
+ envelope id is its key: the use case sends it as the `Idempotency-Key`. One process drains a store. `execution` is
138
143
  reserved.
139
144
  - **A failure says its kind, whatever the wire.** `failureOf` reads a declared `failureKind`, the
140
145
  `Problem` (the same over REST, JSON-RPC and gRPC), then a REST status. A transport of another
@@ -158,9 +163,19 @@ module has only the layers it needs, and says what it offers in its own `index.t
158
163
  - **Decorators are optional.** Function registration must work without any decorator
159
164
  transform. Standard and legacy (`experimentalDecorators`) fixtures are compiled explicitly in
160
165
  tests; do not claim Metro (Babel) or web bundler support without testing those configurations.
166
+ - **A run binds what says it can be bound, never what looks like a transport.** A dependency is
167
+ bound only when it carries `BIND`: a generated client, `restOperations`, `jsonRpcOperations`,
168
+ `restTransport`, `memoryTransport`, `guardedTransport`, `screensTransport`, and what a
169
+ platform marks with `bindableOperations(…)` / `bindableTransport(…)`. Nothing else — not an
170
+ object with `list`/`one`/`send`, not one with a `call` — is ever wrapped: an application's
171
+ abstraction reaches its use cases as it is.
172
+ An object is never taken for an `OperationTransport` because it has a `call`: an Odoo client's
173
+ is `call(service, method, args)`, and binding it hid `setServer` and rewrote its `args` — only
174
+ with a trace to carry, so never in a test without a tracer. Binding wraps only the wire's
175
+ methods; the dependency's state, methods and getters stay its own (`keeping`).
161
176
  - **The trace reaches the wire through the dependencies.** A dependency is bound to the run when it
162
- is a `Transport` or carries `BIND` (every generated client does, through `bindable`); anything
163
- else is handed as it is. A client built elsewhere and closed over sends no trace.
177
+ carries `BIND` (every generated client does, through `bindable`; the framework's transports do);
178
+ anything else is handed as it is. A client built elsewhere and closed over sends no trace.
164
179
  - **The process is read on every call, never at import.** `project` is defined when its module
165
180
  loads, before `main` runs `configureProcess`; nothing may capture the tracer, the reporter or the
166
181
  store at definition time. `configureProcess` replaces everything at once — a test calls it in
package/README.md CHANGED
@@ -290,44 +290,59 @@ that hears it continues that flow.
290
290
 
291
291
  What is defined here, and what each platform plugs behind the ports:
292
292
 
293
- | Piece | Here | The platform's |
294
- | ----------------- | -------------------------------------------------------------- | -------------------------------------- |
295
- | `DomainEvent` | the class, its `eventName`, its messages | — |
296
- | `Command` | its identity (given at registration), its messages | — |
297
- | `Envelope` | `name`, `id`, `correlationId`, `causationId`, `publishedAt` | storing it beside the event |
298
- | `EventQueue` port | `syncQueue` (in the call); `storedQueue` (store, then deliver) | a broker's queue, `BroadcastChannel` |
299
- | `EventStore` port | `memoryEventStore()` | mobile: a SQLite table; web: IndexedDB |
300
- | `Subscriber` | pull, rebuild, deliver to every consumer; Commands declared | where messages come from (a socket) |
293
+ | Piece | Here | The platform's |
294
+ | ------------------- | -------------------------------------------------------------- | -------------------------------------- |
295
+ | `DomainEvent` | the class, its `eventName`, its messages | — |
296
+ | `Command` | its identity (given at registration), its messages | — |
297
+ | `Envelope` | `name`, `id`, `correlationId`, `causationId`, `publishedAt` | storing it beside the event |
298
+ | `MessageQueue` port | `syncQueue` (in the call); `storedQueue` (store, then deliver) | a broker's queue, `BroadcastChannel` |
299
+ | `MessageStore` port | `memoryMessageStore()` | mobile: a SQLite table; web: IndexedDB |
300
+ | `Subscriber` | pull, rebuild, deliver to every consumer; Commands declared | where messages come from (a socket) |
301
301
 
302
- ### Stored events: one way to carry them, any store
302
+ ### Stored messages: events and Commands, one way to carry them, any store
303
303
 
304
304
  ```ts
305
305
  const queue = storedQueue({
306
- store: sqliteEventStore(db), // the platform's EventStore; memoryEventStore() in a tab or a test
306
+ store: sqliteMessageStore(db), // the platform's MessageStore; memoryMessageStore() in a tab or a test
307
307
  subscriber: new Subscriber(
308
308
  salesBoundedContext,
309
309
  stockBoundedContext,
310
310
  printingBoundedContext,
311
311
  ),
312
312
  ready: (stored) => connectivity.online || !needsNetwork(stored.envelope.name),
313
+ policyOf: (stored) => policies[stored.envelope.name], // what its class or the app says
313
314
  onSettled: (stored) => activity.show(stored.envelope.name, stored.state),
314
315
  });
315
316
  shopBoundedContext.addDependency("publisher", new Publisher(queue));
316
317
  connectivity.onBack(() => queue.drain()); // and on coming back to the foreground
317
- ```
318
318
 
319
- `publish` returns once the event is stored. Then the queue delivers what waits, one at a time,
320
- in the order stored — the backend's store-and-forward, over whatever store the platform plugs:
319
+ await publisher.publish(new OrderPaid(order.id)); // a fact: every bounded context that hears it
320
+ await publisher.send(new CommandSendMessage(chat, text)); // an intention: the bus that consumes it
321
+ ```
321
322
 
322
- - It is rebuilt as its class — `static fromJSON` when it has one — and executed by everyone who
323
- hears it and does not have it yet: a retry never runs one twice.
324
- - A failure a retry may fix (`failureOf`: unavailable, no answer, a conflict…) is tried again
325
- after the backoff or the wait it asks for, and what follows waits, so the order holds.
326
- - A failure every attempt would repeat (`PERMANENT_KINDS`: a refusal, invalid, not found) sets
327
- it aside — the dead-letter queue — and never holds back what follows.
328
- - One that is not `ready` (no connection, no session) waits while the rest go on.
329
- - After `maxAttempts` (10) a failure a retry might still fix is set aside too: a bug of the
330
- process (`internal`) never holds the line forever.
323
+ `publish` and `send` return once the message is stored. Then the queue delivers what waits, in
324
+ the order stored — the backend's store-and-forward, over whatever store the platform plugs. An
325
+ event goes to everyone who hears it and does not have it yet; a Command, to the bus that
326
+ consumes it (named in the subscriber's `commands`), and its answer is kept. What follows each
327
+ delivery is its verdict (`verdictOf`, the backend's queue verdicts), with its policy:
328
+
329
+ | What happened | Verdict |
330
+ | ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
331
+ | every consumer has it | `delivered` |
332
+ | it is not `ready` (no connection, no session) | waits |
333
+ | it goes over the network and the other side is not there now (`WAITING_KINDS`: unavailable, out of quota, an open circuit, sent with no answer) | `wait` — as long as it takes, until `maxAttempts` |
334
+ | a failure every attempt would repeat (`PERMANENT_KINDS`) | `set_aside` |
335
+ | any other failure (a bug, a device that did not answer) | `retry` while it has `retries`, else `set_aside` |
336
+
337
+ - **Sent once by default** (`DEFAULT_DELIVERY_POLICY`: `retries: 0`, `maxAttempts: Infinity`,
338
+ `requiresNetwork: false`): a failure is set aside — the dead-letter queue — for a person.
339
+ - **A message waiting never holds the line**: what is due goes on.
340
+ - **Sent again with the same key.** A Command's envelope id is its key: its use case sends it as
341
+ the `Idempotency-Key` (`this.execution.causationId`), so one that went out with no answer is
342
+ sent again and the backend runs it once. A server without keys is verified by the use case.
343
+ - **Open for extension.** `policy` and `policyOf` set the rules per queue and per message; a
344
+ platform adds its own by wrapping the verdict —
345
+ `verdict: (delivery) => mine(delivery) ?? verdictOf(delivery)` —, never by changing the queue.
331
346
 
332
347
  The port only keeps records — `add`, `next(skip)`, `save` — so a SQLite table, IndexedDB or
333
348
  memory carry events the same way, with the same rules.
@@ -506,9 +521,12 @@ are its children, on the same trace. Each span, log record and report says who w
506
521
  sincpro_framework's keys: `release` (`<name>:<version>`, the backend's `APP_RELEASE`) and, when
507
522
  there is one, `tenant` — the run's context's, else the deployment's. `processIdentity()` gives
508
523
  `release`, `serviceName` and `serviceVersion` (read out of the release with the backend's rules)
509
- to a platform's tracer resource and log labels; nothing else of the context is copied. A dependency that is a `Transport` or a generated client is
510
- bound to the run, so each request carries `traceparent` (and `tracestate`) and
511
- `sincpro-context` — the backend continues the trace. A tracer, reporter or logger that fails is
524
+ to a platform's tracer resource and log labels; nothing else of the context is copied. A dependency that says it can be bound — a generated
525
+ client, or one of the framework's transports (`restTransport`, `restOperations`,
526
+ `jsonRpcOperations`, `guardedTransport`; `bindableTransport`/`bindableOperations` for a
527
+ platform's own) — is bound to the run, so each request carries `traceparent` (and `tracestate`)
528
+ and `sincpro-context` — the backend continues the trace. Nothing is guessed from a method's
529
+ name: an application's own object (an Odoo client with a `call`) reaches its use cases as it is. A tracer, reporter or logger that fails is
512
530
  ignored: telling about a use case never changes its answer.
513
531
 
514
532
  The vendor entries wrap what the application built — they initialize nothing, read no
@@ -820,10 +838,10 @@ src/
820
838
  entrypoint/ BoundedContext, screensTransport
821
839
  infrastructure/ configureProcess, configureLogger, processListeners
822
840
  event_driven/
823
- domain/ Envelope, the messages (an event's, a Command's), the EventQueue,
824
- Subscribes and EventStore ports
841
+ domain/ Envelope, the messages (an event's, a Command's), the MessageQueue,
842
+ Subscribes and MessageStore ports
825
843
  services/ writing and reading messages
826
- adapters/ syncQueue, storedQueue, memoryEventStore
844
+ adapters/ syncQueue, storedQueue, memoryMessageStore
827
845
  entrypoint/ Publisher, Subscriber (the queue's composite entrypoint)
828
846
  codegen/ the generator and its CLI — the only place Node is allowed
829
847
  testing/ memoryTracer, memoryReporter, memoryLogger
@@ -1,4 +1,5 @@
1
1
  import { OperationNotPublished, } from "../domain/operation.js";
2
+ import { bindableOperations } from "../services/propagation.js";
2
3
  import { kindOfJsonRpcCode } from "../../common/failures.js";
3
4
  import { readProblem } from "@sincpro/criteria";
4
5
  /**
@@ -49,7 +50,7 @@ let next = 0;
49
50
  export function jsonRpcOperations(options) {
50
51
  const send = options.fetch ?? ((...args) => fetch(...args));
51
52
  const own = () => typeof options.headers === "function" ? options.headers() : options.headers;
52
- return {
53
+ return bindableOperations({
53
54
  async call(operation, input, call = {}) {
54
55
  const method = operation.rpc?.method;
55
56
  if (method === undefined)
@@ -93,5 +94,5 @@ export function jsonRpcOperations(options) {
93
94
  }
94
95
  return answer.result;
95
96
  },
96
- };
97
+ });
97
98
  }
@@ -1,4 +1,5 @@
1
1
  import { TransportError, } from "../domain/transport.js";
2
+ import { bindableTransport } from "../services/propagation.js";
2
3
  import { pack, readValues } from "../../common/serialization.js";
3
4
  import { answer, answerGroups } from "@sincpro/criteria/engine";
4
5
  /**
@@ -44,7 +45,7 @@ export function memoryTransport(tables, options = {}) {
44
45
  });
45
46
  return table;
46
47
  }
47
- return {
48
+ return bindableTransport({
48
49
  async list(route, criteria, signal) {
49
50
  options.observe?.(route, criteria);
50
51
  await check(route, signal);
@@ -116,5 +117,5 @@ export function memoryTransport(tables, options = {}) {
116
117
  return copyOf(await options.read(route));
117
118
  },
118
119
  }),
119
- };
120
+ });
120
121
  }
@@ -1,5 +1,6 @@
1
1
  import { OperationNotPublished, } from "../domain/operation.js";
2
2
  import { downloadRoute, readRoute, } from "../domain/transport.js";
3
+ import { bindableOperations } from "../services/propagation.js";
3
4
  const PATH_KEY = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
4
5
  /** What a value is in a query string: text as it is, anything else as JSON (`criteria`). */
5
6
  function queryValue(value) {
@@ -41,7 +42,7 @@ function withQuery(route, fields) {
41
42
  * Final: the operation's answer, as the contract describes it.
42
43
  */
43
44
  export function restOperations(transport) {
44
- return {
45
+ return bindableOperations({
45
46
  call(operation, input, options = {}) {
46
47
  const rest = operation.rest;
47
48
  if (rest === undefined)
@@ -62,5 +63,5 @@ export function restOperations(transport) {
62
63
  return Promise.reject(error);
63
64
  }
64
65
  },
65
- };
66
+ });
66
67
  }
@@ -1,5 +1,6 @@
1
1
  import { TransportError, } from "../domain/transport.js";
2
2
  import { definitionOf, modelAt, } from "../services/discovery.js";
3
+ import { bindableTransport } from "../services/propagation.js";
3
4
  import { readProblem } from "@sincpro/criteria";
4
5
  import { RestError, restSource } from "@sincpro/criteria/rest";
5
6
  /** The keys of an answer that are not the record: what is left is the record's own field. */
@@ -130,7 +131,7 @@ export function restTransport(options = {}) {
130
131
  throw new TransportError(route, response.status, readProblem(text), undefined);
131
132
  return text ? JSON.parse(text) : null;
132
133
  }
133
- return {
134
+ return bindableTransport({
134
135
  async list(route, criteria, signal, call) {
135
136
  const source = restSource(`${base}${route}`, {
136
137
  // Only a page may come in another format: the decoders are said here, and nowhere else.
@@ -184,5 +185,5 @@ export function restTransport(options = {}) {
184
185
  async send(method, route, body, signal, sending) {
185
186
  return (await get(route, urlOf(base, route), signal, { method, body, key: sending?.idempotencyKey }, sending));
186
187
  },
187
- };
188
+ });
188
189
  }
@@ -16,5 +16,5 @@ export { bodyFor, type CommandAnswers, type CommandBodies, type CommandRoute, ty
16
16
  export { OperationNotPublished, type OperationOptions, type OperationTransport, type RemoteOperation, } from "./domain/operation.js";
17
17
  export { type CallOptions, type Decoder, type Download, downloadRoute, type Draft, type Method, type One, readRoute, type SendOptions, type Transport, TransportError, } from "./domain/transport.js";
18
18
  export { guardedTransport } from "./services/guarded.js";
19
- export { bindable, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
19
+ export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
20
20
  export { type RetryKeys, retryKeys, unanswered, } from "./services/retry.js";
@@ -16,5 +16,5 @@ export { bodyFor, entity, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM
16
16
  export { OperationNotPublished, } from "./domain/operation.js";
17
17
  export { downloadRoute, readRoute, TransportError, } from "./domain/transport.js";
18
18
  export { guardedTransport } from "./services/guarded.js";
19
- export { bindable, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
19
+ export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
20
20
  export { retryKeys, unanswered, } from "./services/retry.js";
@@ -1,9 +1,10 @@
1
1
  import { isOperationTransport, } from "../domain/operation.js";
2
+ import { bindableOperations, bindableTransport, } from "./propagation.js";
2
3
  export function guardedTransport(transport, breaker) {
3
4
  if (isOperationTransport(transport))
4
- return {
5
+ return bindableOperations({
5
6
  call: (operation, input, options) => breaker.call(() => transport.call(operation, input, options)),
6
- };
7
+ });
7
8
  const guarded = {
8
9
  list: (route, criteria, signal, options) => breaker.call(() => transport.list(route, criteria, signal, options)),
9
10
  one: (route, signal, options) => breaker.call(() => transport.one(route, signal, options)),
@@ -15,5 +16,5 @@ export function guardedTransport(transport, breaker) {
15
16
  const download = transport.download;
16
17
  if (download !== undefined)
17
18
  guarded.download = (route, signal, options) => breaker.call(() => download.call(transport, route, signal, options));
18
- return guarded;
19
+ return bindableTransport(guarded);
19
20
  }
@@ -9,15 +9,6 @@ export declare function isTransport(value: unknown): value is Transport;
9
9
  * Nothing when there is no trace and no context that travels.
10
10
  */
11
11
  export declare function headersOf(execution: Execution): Record<string, string>;
12
- /**
13
- * The transport, writing the execution's headers on every call — the caller's own headers of a
14
- * call still win.
15
- *
16
- * Context: the transport's own headers (`restTransport({ headers })`) are the session's — the
17
- * token, the tenant — the same for every call; these are the use case's, different for two use
18
- * cases running at once, so they travel per call (`CallOptions`). A call that gives no signal of
19
- * its own is cancelled with the run.
20
- */
21
12
  export declare function bindTransport(transport: Transport, execution: Execution): Transport;
22
13
  /**
23
14
  * The operation transport, calling as `execution`: every call carries the run's trace and
@@ -25,6 +16,27 @@ export declare function bindTransport(transport: Transport, execution: Execution
25
16
  * win.
26
17
  */
27
18
  export declare function bindOperations(transport: OperationTransport, execution: Execution): OperationTransport;
19
+ /**
20
+ * A REST `Transport` a run binds to itself when it is a dependency: its requests carry the run's
21
+ * trace, context and signal. `restTransport`, `memoryTransport`, `guardedTransport` and
22
+ * `screensTransport` answer one; a platform's own marks itself with it.
23
+ *
24
+ * Context: a run binds only what says it can be bound — never an object because it has `list`,
25
+ * `one` and `send`: an application's own object with those names is the application's.
26
+ */
27
+ export declare function bindableTransport<T extends Transport>(transport: T): T;
28
+ /**
29
+ * An `OperationTransport` a run binds to itself when it is a dependency: its `call` carries the
30
+ * run's trace, context and signal. `restOperations`, `jsonRpcOperations` and `guardedTransport`
31
+ * answer one; a platform's own (gRPC) marks itself with it.
32
+ *
33
+ * boundedContext.addDependency("operations", bindableOperations(grpcOperations(channel)));
34
+ *
35
+ * Context: an object is not taken for a transport because it has a `call` — an Odoo client's is
36
+ * `call(service, method, args)`, and binding it rewrote its arguments and hid its other methods.
37
+ * A run binds what says it can be bound (`BIND`) and a REST `Transport`; nothing else.
38
+ */
39
+ export declare function bindableOperations<T extends OperationTransport>(transport: T): T;
28
40
  /** A transport of either kind, bound to `execution`. */
29
41
  export declare function bound<W extends Transport | OperationTransport>(wire: W, execution: Execution): W;
30
42
  /**
@@ -39,6 +39,28 @@ export function headersOf(execution) {
39
39
  * cases running at once, so they travel per call (`CallOptions`). A call that gives no signal of
40
40
  * its own is cancelled with the run.
41
41
  */
42
+ /**
43
+ * The dependency as it is — its state, its own methods, its getters —, with only its wire's
44
+ * methods carrying the run. Binding a transport never takes away what the dependency is: an
45
+ * Odoo client that happens to have a `call` is still the Odoo client, and `setServer` still sets
46
+ * the server of the one the app holds.
47
+ *
48
+ * Context: it used to answer a new object with only the wire's methods, and only when the run had
49
+ * something to carry (a trace, a context, a signal): with tracing on, every other method vanished
50
+ * — `this.odoo.setServer is not a function` on a phone, never in a test without a tracer.
51
+ */
52
+ function keeping(original, wire) {
53
+ return new Proxy(original, {
54
+ get(target, property) {
55
+ if (Object.hasOwn(wire, property))
56
+ return wire[property];
57
+ const value = Reflect.get(target, property, target);
58
+ return typeof value === "function" ? value.bind(target) : value;
59
+ },
60
+ set: (target, property, value) => Reflect.set(target, property, value, target),
61
+ has: (target, property) => Object.hasOwn(wire, property) || property in target,
62
+ });
63
+ }
42
64
  export function bindTransport(transport, execution) {
43
65
  const own = headersOf(execution);
44
66
  const cancels = execution.signal;
@@ -56,7 +78,7 @@ export function bindTransport(transport, execution) {
56
78
  const download = transport.download;
57
79
  if (download !== undefined)
58
80
  bound.download = (route, signal, options) => download.call(transport, route, signal ?? cancels, call(options));
59
- return bound;
81
+ return keeping(transport, bound);
60
82
  }
61
83
  /**
62
84
  * The operation transport, calling as `execution`: every call carries the run's trace and
@@ -68,13 +90,48 @@ export function bindOperations(transport, execution) {
68
90
  const cancels = execution.signal;
69
91
  if (Object.keys(own).length === 0 && cancels === undefined)
70
92
  return transport;
71
- return {
93
+ return keeping(transport, {
72
94
  call: (operation, input, options) => transport.call(operation, input, {
73
95
  ...options,
74
96
  headers: { ...own, ...options?.headers },
75
97
  ...((options?.signal ?? cancels) ? { signal: options?.signal ?? cancels } : {}),
76
98
  }),
77
- };
99
+ });
100
+ }
101
+ /**
102
+ * A REST `Transport` a run binds to itself when it is a dependency: its requests carry the run's
103
+ * trace, context and signal. `restTransport`, `memoryTransport`, `guardedTransport` and
104
+ * `screensTransport` answer one; a platform's own marks itself with it.
105
+ *
106
+ * Context: a run binds only what says it can be bound — never an object because it has `list`,
107
+ * `one` and `send`: an application's own object with those names is the application's.
108
+ */
109
+ export function bindableTransport(transport) {
110
+ Object.defineProperty(transport, BIND, {
111
+ value: (execution) => bindTransport(transport, execution),
112
+ enumerable: false,
113
+ configurable: true,
114
+ });
115
+ return transport;
116
+ }
117
+ /**
118
+ * An `OperationTransport` a run binds to itself when it is a dependency: its `call` carries the
119
+ * run's trace, context and signal. `restOperations`, `jsonRpcOperations` and `guardedTransport`
120
+ * answer one; a platform's own (gRPC) marks itself with it.
121
+ *
122
+ * boundedContext.addDependency("operations", bindableOperations(grpcOperations(channel)));
123
+ *
124
+ * Context: an object is not taken for a transport because it has a `call` — an Odoo client's is
125
+ * `call(service, method, args)`, and binding it rewrote its arguments and hid its other methods.
126
+ * A run binds what says it can be bound (`BIND`) and a REST `Transport`; nothing else.
127
+ */
128
+ export function bindableOperations(transport) {
129
+ Object.defineProperty(transport, BIND, {
130
+ value: (execution) => bindOperations(transport, execution),
131
+ enumerable: false,
132
+ configurable: true,
133
+ });
134
+ return transport;
78
135
  }
79
136
  /** A transport of either kind, bound to `execution`. */
80
137
  export function bound(wire, execution) {
@@ -1,3 +1,4 @@
1
+ import { bindableTransport } from "../../client/services/propagation.js";
1
2
  import { Command } from "../domain/dto.js";
2
3
  import { Feature } from "../domain/services.js";
3
4
  import { BoundedContext } from "./bounded-context.js";
@@ -127,5 +128,5 @@ export function screensTransport(transport, name = "screens") {
127
128
  through.download = (route, signal, options) => screens.execute(new Export(route, signal, options));
128
129
  }
129
130
  MADE.add(through);
130
- return through;
131
+ return bindableTransport(through);
131
132
  }
@@ -1,6 +1,9 @@
1
1
  import { type Execution } from "../../context/domain/execution.js";
2
2
  /**
3
- * A dependency as the execution should see it: bound when it can be (`BIND`, a `Transport`, an
4
- * `OperationTransport`), as it is otherwise.
3
+ * A dependency as the execution should see it: bound when it says it can be (`BIND` — a
4
+ * generated client, `restOperations`, `jsonRpcOperations`, `restTransport`, `memoryTransport`,
5
+ * `guardedTransport`, `bindableOperations(…)`, `bindableTransport(…)`); as it is otherwise.
6
+ * Never guessed from a method's name: an application's object — an Odoo client with a `call`,
7
+ * a repository with a `list` — is the application's, untouched.
5
8
  */
6
9
  export declare function bindDependency<T>(value: T, execution: Execution): T;
@@ -1,16 +1,13 @@
1
- import { isOperationTransport } from "../../client/domain/operation.js";
2
- import { bindOperations, bindTransport, isTransport, } from "../../client/services/propagation.js";
3
1
  import { BIND, isBindable, } from "../../context/domain/execution.js";
4
2
  /**
5
- * A dependency as the execution should see it: bound when it can be (`BIND`, a `Transport`, an
6
- * `OperationTransport`), as it is otherwise.
3
+ * A dependency as the execution should see it: bound when it says it can be (`BIND` — a
4
+ * generated client, `restOperations`, `jsonRpcOperations`, `restTransport`, `memoryTransport`,
5
+ * `guardedTransport`, `bindableOperations(…)`, `bindableTransport(…)`); as it is otherwise.
6
+ * Never guessed from a method's name: an application's object — an Odoo client with a `call`,
7
+ * a repository with a `list` — is the application's, untouched.
7
8
  */
8
9
  export function bindDependency(value, execution) {
9
10
  if (isBindable(value))
10
11
  return value[BIND](execution);
11
- if (isTransport(value))
12
- return bindTransport(value, execution);
13
- if (isOperationTransport(value))
14
- return bindOperations(value, execution);
15
12
  return value;
16
13
  }
@@ -0,0 +1,10 @@
1
+ import type { MessageStore, StoredMessage } from "../domain/store.js";
2
+ /** A memory store, and what it holds — in the order added — for whoever inspects it. */
3
+ export type MemoryMessageStore = MessageStore & {
4
+ readonly messages: readonly StoredMessage[];
5
+ };
6
+ /**
7
+ * The messages of a stored queue in this process's memory: what a browser tab or a test keeps.
8
+ * Gone with the process — a phone's store is a table.
9
+ */
10
+ export declare function memoryMessageStore(): MemoryMessageStore;
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The events of a stored queue in this process's memory: what a browser tab or a test keeps.
2
+ * The messages of a stored queue in this process's memory: what a browser tab or a test keeps.
3
3
  * Gone with the process — a phone's store is a table.
4
4
  */
5
- export function memoryEventStore() {
5
+ export function memoryMessageStore() {
6
6
  const held = [];
7
7
  return {
8
- get events() {
8
+ get messages() {
9
9
  return [...held];
10
10
  },
11
11
  add(stored) {