@sincpro/web-framework 2.2.0 → 2.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/README.md CHANGED
@@ -92,7 +92,7 @@ flowchart LR
92
92
  subgraph cf["@sincpro/client-framework · every platform"]
93
93
  direction TB
94
94
  wire["Transport · restTransport · entity()<br/>client contract · model definitions"]
95
- services["UseBoundedContext · Feature · ApplicationService<br/>configureProcess · processContext · ContextStore<br/>a span, a report, a context per run"]
95
+ services["BoundedContext · Feature · ApplicationService · EventHandler<br/>configureProcess · processContext · ContextStore<br/>a span, a report, a context per run"]
96
96
  generator["sincpro-client generate<br/>domain · client · entities"]
97
97
  end
98
98
  subgraph fw["@sincpro/web-framework · the web"]
@@ -225,7 +225,7 @@ export const invoices = entity<Invoice>("sales:invoice", {
225
225
  create: "POST /invoices",
226
226
  save: "PUT /invoices/{id}",
227
227
  commands: { post: "POST /invoices/{id}/post" },
228
- history: { route: "/sales-events", type: "Invoice" },
228
+ history: "/invoices/{id}/events", // its DomainEvents: a record's facts
229
229
  });
230
230
  ```
231
231
 
@@ -15,8 +15,8 @@ import { type Entity, type Transport } from "@sincpro/client-framework";
15
15
  *
16
16
  * A write forgets every collection its route NAMES, not only the first: «leave a tenant»
17
17
  * (`POST /users/{email}/tenants/{tenant}/leave`) changes the tenant's members as much as the
18
- * user. And an entity's business events live on a route of their own (`/project-events`): with
19
- * `entities`, a write under an entity's list also forgets its history.
18
+ * user. And a record's business events live on a route of their own (`/issues/{id}/events`):
19
+ * with `entities`, a write under an entity's list also forgets its history, wherever it lives.
20
20
  *
21
21
  * const transport = cachedTransport(restTransport({ base: "/v1" }), { ttl: 30_000 });
22
22
  * transport.invalidate("/facturas"); // forget an entity by hand (a push from the server)
@@ -14,7 +14,8 @@ function touchedBy(route, entities) {
14
14
  const segments = path.split("/").filter((one) => one !== "");
15
15
  const history = entities
16
16
  .filter((one) => one.history !== undefined && under(path, pathOf(one.list)))
17
- .map((one) => pathOf(one.history?.route ?? ""));
17
+ // The route up to its first key: `/issue-events/{id}` forgets `/issue-events`.
18
+ .map((one) => pathOf(one.history ?? "").split("/{")[0] ?? "");
18
19
  return [...segments.map((one) => `/${one}`), ...history];
19
20
  }
20
21
  export function cachedTransport(transport, options = {}) {
@@ -2,9 +2,10 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
2
2
  /**
3
3
  * A record's history as people read it — its business events, newest first.
4
4
  *
5
- * Context: sincpro_framework keeps every context's facts in one event table, read over
6
- * `GET /<context>-events`, each fact naming the record it is about (`entity_type`,
7
- * `entity_id`) and carrying a `label` in every language — the framework's `history_of`.
5
+ * Context: sincpro_framework keeps every context's facts in one event table, and answers a
6
+ * record's own with `DomainEvents` (`GET /issues/{id}/events`, the entity's `history`), each
7
+ * fact naming the record it is about (`entity_type`, `entity_id`) and carrying a `label` in
8
+ * every language.
8
9
  * forge's console read it with a dictionary of field names written by hand; here the words for
9
10
  * the rest of a fact come from the events' own model definition, like any other field.
10
11
  *
@@ -1,16 +1,17 @@
1
1
  "use client";
2
- import {} from "@sincpro/client-framework";
2
+ import { listRoute } from "@sincpro/client-framework";
3
3
  import { historyOf } from "../core/history.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useEffect, useState } from "react";
6
6
  /**
7
7
  * A record's business events, newest first — what `Record.Activity` draws.
8
8
  *
9
- * Context: the history of a record is a criteria over its context's events — `entity_type`
10
- * and `entity_id` — so it is read like any list, with the same transport. `undefined` while it
11
- * is not read, or when it cannot be: an empty history says «nothing happened», which is a
12
- * different claim from «you may not see it». Pass the record among `deps` so a write that
13
- * reloads it reads its new facts too.
9
+ * Context: the backend answers a record's events itself — sincpro_framework's `DomainEvents`,
10
+ * the entity's `history` route (`/issues/{id}/events`), which the generator writes from the
11
+ * contract — so it is read like any list, with the same transport, newest first. `undefined`
12
+ * while it is not read, for a record not saved yet, or when it cannot be read: an empty history
13
+ * says «nothing happened», which is a different claim from «you may not see it». Pass the
14
+ * record among `deps` so a write that reloads it reads its new facts too.
14
15
  *
15
16
  * Named after sincpro_framework's `history_of`; web-ui's `useActivity` is something else (the
16
17
  * panel's open state).
@@ -21,20 +22,16 @@ export function useHistory(entity, id, deps = []) {
21
22
  const [entries, setEntries] = useState(undefined);
22
23
  const history = entity.history;
23
24
  useEffect(() => {
24
- if (history === undefined)
25
+ if (history === undefined || id === "") {
26
+ setEntries(undefined);
25
27
  return;
28
+ }
26
29
  const aborter = new AbortController();
27
30
  const criteria = {
28
- selection: {
29
- all: [
30
- { field: "entity_type", operator: "=", value: history.type },
31
- { field: "entity_id", operator: "=", value: id },
32
- ],
33
- },
34
31
  order: [{ field: "created_at", descending: true }],
35
32
  pagination: { limit: SHOWN },
36
33
  };
37
- transport.list(history.route, criteria, aborter.signal).then((page) => aborter.signal.aborted || setEntries(historyOf(page.rows, page.meta, locale)), () => aborter.signal.aborted || setEntries(undefined));
34
+ transport.list(listRoute(history, { id }), criteria, aborter.signal).then((page) => aborter.signal.aborted || setEntries(historyOf(page.rows, page.meta, locale)), () => aborter.signal.aborted || setEntries(undefined));
38
35
  return () => aborter.abort();
39
36
  // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller names what reloads it
40
37
  }, [transport, history, id, locale, context, ...deps]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@opentelemetry/resources": "^3.1.0",
41
41
  "@opentelemetry/sdk-trace": "^3.1.0",
42
42
  "@sentry/browser": "^11.11.0",
43
- "@sincpro/client-framework": "^0.6.0",
43
+ "@sincpro/client-framework": "^1.4.0",
44
44
  "@sincpro/criteria": "^2.1.0",
45
45
  "@sincpro/criteria-react": "^2.1.0",
46
46
  "@sincpro/web-composer": "^1.6.0",
@@ -72,7 +72,7 @@
72
72
  "@opentelemetry/resources": "3.1.0",
73
73
  "@opentelemetry/sdk-trace": "3.1.0",
74
74
  "@sentry/browser": "11.11.0",
75
- "@sincpro/client-framework": "^0.6.0",
75
+ "@sincpro/client-framework": "^1.4.0",
76
76
  "@sincpro/criteria": "^2.1.0",
77
77
  "@sincpro/criteria-react": "^2.1.0",
78
78
  "@sincpro/web-composer": "^1.6.0",