@sincpro/client-framework 2.0.0 → 2.2.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/README.md CHANGED
@@ -813,6 +813,17 @@ function subjectOf(event: remote.DomainEvent): string {
813
813
  `events` in `adapters/generated/client.ts` says, per event, its wire name and whether the bounded context records it
814
814
  (its aggregates' own) or handles it (a Feature subscribes).
815
815
 
816
+ The words of each event's fields are in the contract too (sincpro_framework 3.37.1 or later):
817
+ `eventMetasOf(contract)` reads the snapshot (`domain/generated/contract.json`) into one
818
+ definition per event, by its wire name, as `metasOf` does for the entities. What one occurrence
819
+ says — what happened, the record, who — travels in the event itself (`label`, `entity_display`,
820
+ `actor`).
821
+
822
+ ```ts
823
+ const metas = eventMetasOf(contract);
824
+ labelOf(metas["project.issue.v1.closed"], "reason", "es"); // "Motivo"
825
+ ```
826
+
816
827
  ### Types, not classes
817
828
 
818
829
  What is generated is the remote service's contract and an adapter over it, so it is written as
@@ -3,7 +3,7 @@ import { announced, processChanges } from "../services/changes.js";
3
3
  import { definitionOf, modelAt, } from "../services/discovery.js";
4
4
  import { bindableTransport } from "../services/propagation.js";
5
5
  import { valuesOf } from "../../common/serialization.js";
6
- import { readProblem } from "@sincpro/criteria";
6
+ import { readProblem, } from "@sincpro/criteria";
7
7
  import { RestError, restSource } from "@sincpro/criteria/rest";
8
8
  /** The keys of an answer that are not the record: what is left is the record's own field. */
9
9
  const ENVELOPE = new Set(["cursor", "count", "model_version", "dropped", "draft", "missing"]);
@@ -188,7 +188,12 @@ export function restTransport(options = {}) {
188
188
  ...(decoders.length === 0 ? {} : { decode }),
189
189
  });
190
190
  try {
191
- const page = await source.read(criteria, signal);
191
+ // A grouped question is answered with the groups, as sincpro_framework's `Search`
192
+ // answers it on the same route (3.37.2) and `memoryTransport` does: read by name.
193
+ const grouped = (criteria.grouping?.group_by?.length ?? 0) > 0;
194
+ const page = grouped
195
+ ? (await source.group(criteria, signal))
196
+ : await source.read(criteria, signal);
192
197
  return {
193
198
  ...page,
194
199
  meta: page.meta ?? (await definitionAt(`${base}${route}`, "get", page.version)),
@@ -1,8 +1,9 @@
1
1
  import { type Contract, type Meta } from "@sincpro/criteria";
2
2
  /**
3
3
  * A bounded context's client contract, as the application keeps it: the snapshot
4
- * `sincpro-web generate` writes (`contract.json`), or the document a service serves
5
- * (`GET /client-contract/<context>.json`). Only its models are read here.
4
+ * `sincpro-client generate` writes (`contract.json`), or the document a service serves
5
+ * (`GET /client-contract/<context>.json`). Its models are read here, and its events when it
6
+ * carries them.
6
7
  *
7
8
  * Context: the generated entities are keyed `<domain>:<kind>` (`project:issue`) — the key the
8
9
  * workspace refers to them by and the meta store keeps their definitions under —, so the rule
@@ -12,6 +13,10 @@ import { type Contract, type Meta } from "@sincpro/criteria";
12
13
  export type ClientContract = {
13
14
  models: Readonly<Record<string, Contract>>;
14
15
  $defs?: Readonly<Record<string, Contract>>;
16
+ /** Its domain events by wire name, when it was exported with them (`--events`). */
17
+ events?: Readonly<Record<string, {
18
+ schema: Contract;
19
+ }>>;
15
20
  };
16
21
  /** `ProjectEvent` → `project_event`: the kind in an entity's key. */
17
22
  export declare function kindOf(model: string): string;
@@ -32,3 +37,14 @@ export declare function versionsOf(contract: ClientContract): Record<string, str
32
37
  * <FrameworkProvider transport={transport} metas={metasOf(contract, "project")}>
33
38
  */
34
39
  export declare function metasOf(contract: ClientContract, domain: string): Record<string, Meta>;
40
+ /**
41
+ * The definition of every domain event of `contract`, by its wire name: what each field it
42
+ * carries is called, for a history to draw it. Empty for a contract exported without its events.
43
+ *
44
+ * labelOf(eventMetasOf(contract)["desk.ticket.v1.closed"], "reason", "es") -> "Motivo"
45
+ *
46
+ * Context: what one occurrence says — what happened, the record, who — travels in the event
47
+ * itself (`label`, `entity_display`, `actor`), in the words of its day. The words of its fields
48
+ * are the contract's, as sincpro_framework publishes them since 3.37.1.
49
+ */
50
+ export declare function eventMetasOf(contract: ClientContract): Record<string, Meta>;
@@ -24,6 +24,10 @@ export function versionsOf(contract) {
24
24
  : [];
25
25
  }));
26
26
  }
27
+ /** What a definition points at by name (`#/models/Run`): a related model, a value it holds. */
28
+ function relatedOf(contract) {
29
+ return { ...(contract.$defs ?? {}), ...contract.models };
30
+ }
27
31
  /**
28
32
  * The definition of every model of `contract`, by its entity's key — what `FrameworkProvider
29
33
  * metas` preloads, so the first screen draws its labels with no request at all. The transport
@@ -32,10 +36,26 @@ export function versionsOf(contract) {
32
36
  * <FrameworkProvider transport={transport} metas={metasOf(contract, "project")}>
33
37
  */
34
38
  export function metasOf(contract, domain) {
35
- // A related model, or a value a record holds, is pointed at by its name (`#/models/Run`).
36
- const related = { ...(contract.$defs ?? {}), ...contract.models };
39
+ const related = relatedOf(contract);
37
40
  return Object.fromEntries(Object.entries(contract.models)
38
41
  // Only an entity has a key of its own; a value it holds is described inside it.
39
42
  .filter(([, model]) => model["x-sincpro"]?.identity != null)
40
43
  .map(([name, model]) => [entityKeyOf(domain, name), metaFromContract(model, related)]));
41
44
  }
45
+ /**
46
+ * The definition of every domain event of `contract`, by its wire name: what each field it
47
+ * carries is called, for a history to draw it. Empty for a contract exported without its events.
48
+ *
49
+ * labelOf(eventMetasOf(contract)["desk.ticket.v1.closed"], "reason", "es") -> "Motivo"
50
+ *
51
+ * Context: what one occurrence says — what happened, the record, who — travels in the event
52
+ * itself (`label`, `entity_display`, `actor`), in the words of its day. The words of its fields
53
+ * are the contract's, as sincpro_framework publishes them since 3.37.1.
54
+ */
55
+ export function eventMetasOf(contract) {
56
+ const related = relatedOf(contract);
57
+ return Object.fromEntries(Object.entries(contract.events ?? {}).map(([name, event]) => [
58
+ name,
59
+ metaFromContract(event.schema, related),
60
+ ]));
61
+ }
@@ -13,7 +13,7 @@ export { type AssignableOptions, assignableValues, type MemoryOptions, type Memo
13
13
  export { type RestOptions, restTransport, urlOf, type VersionDrift, } from "./adapters/rest.js";
14
14
  export { restOperations } from "./adapters/rest-operations.js";
15
15
  export { type Change, type ChangeFeed, changeOf, } from "./domain/changes.js";
16
- export { type ClientContract, entityKeyOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
16
+ export { type ClientContract, entityKeyOf, eventMetasOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
17
17
  export { bodyFor, type CommandAnswers, type CommandBodies, type CommandRoute, type Entity, entity, type EntityRoutes, type ExportFormat, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, type ResourceRef, SCOPE_NAME_PARAM, SCOPE_PARAM, scopeNameOf, scopeOfRef, startingValuesOf, type SummaryFields, type SummaryPart, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./domain/entity.js";
18
18
  export { OperationNotPublished, type OperationOptions, type OperationTransport, type RemoteOperation, } from "./domain/operation.js";
19
19
  export { type CallOptions, type Decoder, type Download, downloadRoute, type Draft, markedAs, type Method, type One, readRoute, SCREENS, type SendOptions, type Transport, TransportError, } from "./domain/transport.js";
@@ -13,7 +13,7 @@ export { assignableValues, memoryTransport, } from "./adapters/memory.js";
13
13
  export { restTransport, urlOf, } from "./adapters/rest.js";
14
14
  export { restOperations } from "./adapters/rest-operations.js";
15
15
  export { changeOf, } from "./domain/changes.js";
16
- export { entityKeyOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
16
+ export { entityKeyOf, eventMetasOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
17
17
  export { bodyFor, entity, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_NAME_PARAM, SCOPE_PARAM, scopeNameOf, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./domain/entity.js";
18
18
  export { OperationNotPublished, } from "./domain/operation.js";
19
19
  export { downloadRoute, markedAs, readRoute, SCREENS, TransportError, } from "./domain/transport.js";
@@ -16,7 +16,8 @@ import { scaffoldFilesOf } from "../services/scaffold.js";
16
16
  * - `domain/generated/events.ts`: the domain events and `DomainEvent`, their union — when the
17
17
  * contract was exported with them (`export-client-contract --events`);
18
18
  * - `domain/generated/index.ts`: the three, re-exported;
19
- * - `domain/generated/contract.json`: the snapshot they were written from, for `metasOf`;
19
+ * - `domain/generated/contract.json`: the snapshot they were written from, for `metasOf` and
20
+ * `eventMetasOf`;
20
21
  * - `adapters/generated/client.ts`: every operation (and event) as data, and
21
22
  * `clientOf(operations)` over any wire;
22
23
  * - `adapters/generated/entities.ts`: an `entity<T, C>()` per model a screen can list.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "2.0.0",
3
+ "version": "2.2.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",