@sincpro/client-framework 2.9.0 → 3.0.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 (51) hide show
  1. package/AGENTS.md +16 -7
  2. package/README.md +83 -45
  3. package/dist/client/adapters/json-rpc.d.ts +4 -0
  4. package/dist/client/adapters/json-rpc.js +44 -38
  5. package/dist/client/adapters/memory.d.ts +5 -7
  6. package/dist/client/adapters/memory.js +82 -62
  7. package/dist/client/adapters/rest-operations.d.ts +6 -2
  8. package/dist/client/adapters/rest-operations.js +8 -5
  9. package/dist/client/adapters/rest.d.ts +2 -7
  10. package/dist/client/adapters/rest.js +12 -18
  11. package/dist/client/domain/answer.d.ts +28 -0
  12. package/dist/client/domain/answer.js +52 -0
  13. package/dist/client/domain/changes.d.ts +24 -19
  14. package/dist/client/domain/changes.js +18 -9
  15. package/dist/client/domain/entity.d.ts +74 -212
  16. package/dist/client/domain/entity.js +39 -117
  17. package/dist/client/domain/operation.d.ts +22 -1
  18. package/dist/client/domain/operation.js +4 -0
  19. package/dist/client/domain/transport.d.ts +8 -6
  20. package/dist/client/domain/transport.js +3 -3
  21. package/dist/client/index.d.ts +13 -7
  22. package/dist/client/index.js +13 -7
  23. package/dist/client/services/api.d.ts +39 -0
  24. package/dist/client/services/api.js +38 -0
  25. package/dist/client/services/changes.d.ts +13 -12
  26. package/dist/client/services/changes.js +14 -13
  27. package/dist/client/services/guarded.js +3 -3
  28. package/dist/client/services/propagation.d.ts +9 -11
  29. package/dist/client/services/propagation.js +9 -11
  30. package/dist/client/services/reads.d.ts +38 -0
  31. package/dist/client/services/reads.js +46 -0
  32. package/dist/client/services/selection.d.ts +7 -6
  33. package/dist/client/services/selection.js +6 -5
  34. package/dist/codegen/domain/names.d.ts +16 -1
  35. package/dist/codegen/domain/names.js +43 -0
  36. package/dist/codegen/services/check.d.ts +2 -1
  37. package/dist/codegen/services/check.js +10 -5
  38. package/dist/codegen/services/client.d.ts +7 -7
  39. package/dist/codegen/services/client.js +120 -52
  40. package/dist/codegen/services/entities.d.ts +9 -12
  41. package/dist/codegen/services/entities.js +76 -130
  42. package/dist/codegen/services/rest.d.ts +1 -6
  43. package/dist/codegen/services/rest.js +0 -11
  44. package/dist/codegen/services/scaffold.js +5 -2
  45. package/dist/core/domain/services.d.ts +1 -1
  46. package/dist/core/domain/services.js +1 -1
  47. package/dist/core/entrypoint/screens.d.ts +14 -4
  48. package/dist/core/entrypoint/screens.js +33 -141
  49. package/dist/core/index.d.ts +2 -2
  50. package/dist/core/index.js +1 -1
  51. package/package.json +1 -1
@@ -7,7 +7,7 @@
7
7
  * class CancelIssue extends Feature<CommandCancelIssue, ResponseCancelIssue> {
8
8
  * async execute(command: CommandCancelIssue) {
9
9
  * this.logger.info("Cancelling"); // bound to this run
10
- * return new ResponseCancelIssue(await this.client.cancelIssue(command));
10
+ * return new ResponseCancelIssue(await this.client.issue.cancel(command));
11
11
  * }
12
12
  * }
13
13
  *
@@ -1,6 +1,16 @@
1
- import { type Transport } from "../../client/domain/transport.js";
1
+ import { type OperationTransport } from "../../client/domain/operation.js";
2
2
  /**
3
- * Screen requests enter the same command pipeline as application services. A generated
4
- * client injected into a Feature uses its raw transport instead, continuing that execution.
3
+ * The operations a screen calls, each a use case of `screens`: traced and reported as any other
4
+ * — its span says which operation (`sincpro.operation`) —, its request carrying the run's trace,
5
+ * context and signal, over whatever wire `transport` speaks.
6
+ *
7
+ * const operations = screensOperations(restOperations(restTransport({ base: "/v1" })), "web");
8
+ * await readPage(operations, issues, criteria);
9
+ *
10
+ * Context: one pipeline for screens and Features — what a screen reads and writes are the same
11
+ * operations a use case calls through its generated client, so one Feature runs them all, never
12
+ * one per route or per verb. A use case's client is not made over this: injected into a Feature,
13
+ * it continues that run instead. Given a screens transport again — or one a wrapper marked
14
+ * (`markedAs`) —, it answers it as it is: one use case per call, however many wrappers.
5
15
  */
6
- export declare function screensTransport(transport: Transport, name?: string): Transport;
16
+ export declare function screensOperations(transport: OperationTransport, name?: string): OperationTransport;
@@ -1,161 +1,53 @@
1
- import { SCREENS, } from "../../client/domain/transport.js";
2
- import { bindableTransport } from "../../client/services/propagation.js";
1
+ import {} from "../../client/domain/operation.js";
2
+ import { SCREENS } from "../../client/domain/transport.js";
3
+ import { bindableOperations } from "../../client/services/propagation.js";
3
4
  import { Command } from "../domain/dto.js";
4
5
  import { Feature } from "../domain/services.js";
5
6
  import { BoundedContext } from "./bounded-context.js";
6
- class List extends Command {
7
- route;
8
- criteria;
9
- signal;
7
+ /** One operation a screen calls — a search, a record, an edit, a Command —, as it is. */
8
+ class CallOperation extends Command {
9
+ operation;
10
+ input;
10
11
  options;
11
- constructor(route, criteria, signal, options) {
12
+ constructor(operation, input, options) {
12
13
  super();
13
- this.route = route;
14
- this.criteria = criteria;
15
- this.signal = signal;
14
+ this.operation = operation;
15
+ this.input = input;
16
16
  this.options = options;
17
17
  }
18
18
  }
19
- class Get extends Command {
20
- route;
21
- signal;
22
- options;
23
- constructor(route, signal, options) {
24
- super();
25
- this.route = route;
26
- this.signal = signal;
27
- this.options = options;
28
- }
29
- }
30
- class Read extends Command {
31
- route;
32
- signal;
33
- options;
34
- constructor(route, signal, options) {
35
- super();
36
- this.route = route;
37
- this.signal = signal;
38
- this.options = options;
39
- }
40
- }
41
- class Export extends Command {
42
- route;
43
- signal;
44
- options;
45
- constructor(route, signal, options) {
46
- super();
47
- this.route = route;
48
- this.signal = signal;
49
- this.options = options;
50
- }
51
- }
52
- class Upload extends Command {
53
- link;
54
- file;
55
- signal;
56
- options;
57
- constructor(link, file, signal, options) {
58
- super();
59
- this.link = link;
60
- this.file = file;
61
- this.signal = signal;
62
- this.options = options;
63
- }
64
- }
65
- class Send extends Command {
66
- method;
67
- route;
68
- body;
69
- signal;
70
- options;
71
- constructor(method, route, body, signal, options) {
72
- super();
73
- this.method = method;
74
- this.route = route;
75
- this.body = body;
76
- this.signal = signal;
77
- this.options = options;
78
- }
79
- }
80
- class EntityList extends Feature {
81
- execute(dto) {
82
- this.span.set({ "http.route": dto.route });
83
- return this.transport.list(dto.route, dto.criteria, dto.signal, dto.options);
84
- }
85
- }
86
- class EntityGet extends Feature {
19
+ class OperationCalled extends Feature {
87
20
  execute(dto) {
88
- this.span.set({ "http.route": dto.route });
89
- return this.transport.one(dto.route, dto.signal, dto.options);
90
- }
91
- }
92
- class EntityRead extends Feature {
93
- execute(dto) {
94
- this.span.set({ "http.route": dto.route });
95
- const transport = this.transport;
96
- if (!transport.read) {
97
- return Promise.reject(new Error(`this transport cannot read ${dto.route}: it has no read()`));
98
- }
99
- return transport.read(dto.route, dto.signal, dto.options);
100
- }
101
- }
102
- class EntityExport extends Feature {
103
- execute(dto) {
104
- this.span.set({ "http.route": dto.route });
105
- const transport = this.transport;
106
- if (!transport.download) {
107
- return Promise.reject(new Error(`this transport cannot download ${dto.route}: it has no download()`));
108
- }
109
- return transport.download(dto.route, dto.signal, dto.options);
110
- }
111
- }
112
- class EntityUpload extends Feature {
113
- execute(dto) {
114
- // The link holds the upload's id — a capability —, so the span names the route, not the id.
115
- const path = dto.link.split("?")[0] ?? dto.link;
116
- this.span.set({ "http.method": "PUT", "http.route": path.replace(/[^/]+$/, "{id}") });
117
- const transport = this.transport;
118
- if (!transport.upload) {
119
- return Promise.reject(new Error(`this transport cannot upload to ${dto.link}: it has no upload()`));
120
- }
121
- return transport.upload(dto.link, dto.file, dto.signal, dto.options);
122
- }
123
- }
124
- class EntitySend extends Feature {
125
- execute(dto) {
126
- this.span.set({ "http.method": dto.method, "http.route": dto.route });
127
- return this.transport.send(dto.method, dto.route, dto.body, dto.signal, dto.options);
21
+ this.span.set({ "sincpro.operation": dto.operation.identity });
22
+ return this.transport.call(dto.operation, dto.input, dto.options);
128
23
  }
129
24
  }
130
25
  /**
131
- * Screen requests enter the same command pipeline as application services. A generated
132
- * client injected into a Feature uses its raw transport instead, continuing that execution.
26
+ * The operations a screen calls, each a use case of `screens`: traced and reported as any other
27
+ * — its span says which operation (`sincpro.operation`) —, its request carrying the run's trace,
28
+ * context and signal, over whatever wire `transport` speaks.
29
+ *
30
+ * const operations = screensOperations(restOperations(restTransport({ base: "/v1" })), "web");
31
+ * await readPage(operations, issues, criteria);
32
+ *
33
+ * Context: one pipeline for screens and Features — what a screen reads and writes are the same
34
+ * operations a use case calls through its generated client, so one Feature runs them all, never
35
+ * one per route or per verb. A use case's client is not made over this: injected into a Feature,
36
+ * it continues that run instead. Given a screens transport again — or one a wrapper marked
37
+ * (`markedAs`) —, it answers it as it is: one use case per call, however many wrappers.
133
38
  */
134
- export function screensTransport(transport, name = "screens") {
39
+ export function screensOperations(transport, name = "screens") {
135
40
  if (transport[SCREENS] === true)
136
41
  return transport;
137
42
  const screens = new BoundedContext(name);
138
43
  screens.addDependency("transport", transport);
139
- screens.feature(List)(EntityList);
140
- screens.feature(Get)(EntityGet);
141
- screens.feature(Read)(EntityRead);
142
- screens.feature(Export)(EntityExport);
143
- screens.feature(Send)(EntitySend);
144
- screens.feature(Upload)(EntityUpload);
44
+ screens.feature(CallOperation)(OperationCalled);
145
45
  const through = {
146
- list: (route, criteria, signal, options) => screens.execute(new List(route, criteria, signal, options)),
147
- one: (route, signal, options) => screens.execute(new Get(route, signal, options)),
148
- send: (method, route, body, signal, options) => screens.execute(new Send(method, route, body, signal, options)),
46
+ call: (operation, input, options = {}) => {
47
+ const { signal, ...rest } = options;
48
+ return screens.execute(new CallOperation(operation, input, rest), signal === undefined ? {} : { signal });
49
+ },
50
+ [SCREENS]: true,
149
51
  };
150
- if (transport.read) {
151
- through.read = (route, signal, options) => screens.execute(new Read(route, signal, options));
152
- }
153
- if (transport.download) {
154
- through.download = (route, signal, options) => screens.execute(new Export(route, signal, options));
155
- }
156
- if (transport.upload) {
157
- through.upload = (link, file, signal, options) => screens.execute(new Upload(link, file, signal, options));
158
- }
159
- through[SCREENS] = true;
160
- return bindableTransport(through);
52
+ return bindableOperations(through);
161
53
  }
@@ -7,7 +7,7 @@
7
7
  * bases (`servicesWith`: typed with a context's dependencies), the error
8
8
  * handlers, a batch's outcomes (`BatchResult`)
9
9
  * services/ the execution pipeline, dependency binding, the handler chain
10
- * entrypoint/ `BoundedContext`, `screensTransport`, `runBatch`
10
+ * entrypoint/ `BoundedContext`, `screensOperations`, `runBatch`
11
11
  * infrastructure/ `configureProcess`, `configureLogger`
12
12
  */
13
13
  export type { BatchResult, ItemOutcome } from "./domain/batch.js";
@@ -19,7 +19,7 @@ export type { CallNext, Cause, ExecuteOptions, ExecutionCompleted, ExecutionFail
19
19
  export { ApplicationService, type ApplicationServiceWith, type BoundedContextHandlerWith, EventHandler, type EventHandlerWith, Feature, type FeatureWith, type HandledEvent, handlersWith, type ServiceInput, servicesWith, } from "./domain/services.js";
20
20
  export { type BatchOptions, type BatchStep, runBatch, } from "./entrypoint/batch.js";
21
21
  export { BoundedContext, type Registrar, type RegistrationOptions, } from "./entrypoint/bounded-context.js";
22
- export { screensTransport } from "./entrypoint/screens.js";
22
+ export { screensOperations } from "./entrypoint/screens.js";
23
23
  export { processListeners } from "./infrastructure/listeners.js";
24
24
  export { configureLogger, configureProcess, type LoggerConfiguration, processIdentity, type ProcessOptions, } from "./infrastructure/process.js";
25
25
  export type { HandlerOptions, HandlerRegistrar, } from "./services/event-handlers.js";
@@ -3,6 +3,6 @@ export { Command, COMMAND_IDENTITY, commandOf, DataTransferObject, DomainEvent,
3
3
  export { ApplicationService, EventHandler, Feature, handlersWith, servicesWith, } from "./domain/services.js";
4
4
  export { runBatch, } from "./entrypoint/batch.js";
5
5
  export { BoundedContext, } from "./entrypoint/bounded-context.js";
6
- export { screensTransport } from "./entrypoint/screens.js";
6
+ export { screensOperations } from "./entrypoint/screens.js";
7
7
  export { processListeners } from "./infrastructure/listeners.js";
8
8
  export { configureLogger, configureProcess, processIdentity, } from "./infrastructure/process.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "2.9.0",
3
+ "version": "3.0.0",
4
4
  "description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",