@sincpro/web-framework 1.1.0 → 2.1.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 (129) hide show
  1. package/README.md +188 -87
  2. package/dist/core/cache.d.ts +1 -2
  3. package/dist/core/cache.js +8 -5
  4. package/dist/core/explain.d.ts +15 -0
  5. package/dist/core/{transport.js → explain.js} +4 -26
  6. package/dist/core/form.d.ts +1 -1
  7. package/dist/core/form.js +1 -0
  8. package/dist/core/index.d.ts +9 -15
  9. package/dist/core/index.js +8 -14
  10. package/dist/core/list.d.ts +5 -4
  11. package/dist/core/list.js +1 -0
  12. package/dist/core/lookup.d.ts +1 -1
  13. package/dist/core/lookup.js +1 -0
  14. package/dist/core/present.d.ts +1 -0
  15. package/dist/core/present.js +54 -6
  16. package/dist/core/relation.d.ts +1 -1
  17. package/dist/core/relation.js +1 -1
  18. package/dist/core/summary.d.ts +1 -6
  19. package/dist/core/trail.d.ts +1 -1
  20. package/dist/core/trail.js +1 -0
  21. package/dist/errors/index.d.ts +48 -0
  22. package/dist/errors/index.js +56 -0
  23. package/dist/react/context.d.ts +6 -4
  24. package/dist/react/context.js +11 -3
  25. package/dist/react/index.d.ts +2 -0
  26. package/dist/react/index.js +2 -0
  27. package/dist/react/scope.d.ts +1 -1
  28. package/dist/react/scope.js +1 -1
  29. package/dist/react/useCommand.d.ts +1 -1
  30. package/dist/react/useCommand.js +1 -2
  31. package/dist/react/useContextValues.d.ts +15 -0
  32. package/dist/react/useContextValues.js +19 -0
  33. package/dist/react/useGroups.js +2 -2
  34. package/dist/react/useHistory.d.ts +1 -1
  35. package/dist/react/useHistory.js +3 -2
  36. package/dist/react/useListing.d.ts +4 -4
  37. package/dist/react/useListing.js +16 -7
  38. package/dist/react/useLookup.d.ts +1 -1
  39. package/dist/react/useLookup.js +3 -2
  40. package/dist/react/useNameOf.d.ts +1 -1
  41. package/dist/react/useNameOf.js +3 -3
  42. package/dist/react/usePivot.js +2 -2
  43. package/dist/react/useRecord.d.ts +1 -2
  44. package/dist/react/useRecord.js +18 -6
  45. package/dist/react/useRelated.d.ts +1 -1
  46. package/dist/react/useRelated.js +1 -0
  47. package/dist/react/useService.d.ts +38 -0
  48. package/dist/react/useService.js +66 -0
  49. package/dist/react/useSummary.d.ts +1 -1
  50. package/dist/react/useSummary.js +1 -0
  51. package/dist/telemetry/index.d.ts +45 -0
  52. package/dist/telemetry/index.js +55 -0
  53. package/dist/web/Refused.js +1 -1
  54. package/dist/web/index.d.ts +1 -1
  55. package/dist/web/index.js +1 -1
  56. package/dist/web/list/EntityList.d.ts +1 -1
  57. package/dist/web/list/EntityList.js +3 -3
  58. package/dist/web/list/EntitySearchBar.d.ts +2 -1
  59. package/dist/web/list/EntitySearchBar.js +17 -11
  60. package/dist/web/list/presentation.d.ts +1 -1
  61. package/dist/web/list/presentation.js +1 -0
  62. package/dist/web/list/rowCommands.d.ts +1 -1
  63. package/dist/web/list/rowCommands.js +1 -2
  64. package/dist/web/record/CommandButton.d.ts +1 -1
  65. package/dist/web/record/CommandButton.js +1 -0
  66. package/dist/web/record/EntityPicker.d.ts +8 -5
  67. package/dist/web/record/EntityPicker.js +6 -5
  68. package/dist/web/record/EntityTags.d.ts +1 -1
  69. package/dist/web/record/EntityTags.js +1 -0
  70. package/dist/web/record/RelatedList.d.ts +1 -1
  71. package/dist/web/record/RelatedList.js +1 -0
  72. package/dist/web/record/control.d.ts +4 -2
  73. package/dist/web/record/control.js +8 -5
  74. package/dist/web/record/edit.js +21 -1
  75. package/dist/web/record/lines.js +13 -2
  76. package/dist/web/record/opening.d.ts +1 -1
  77. package/dist/web/record/opening.js +1 -0
  78. package/dist/web/record/record.d.ts +12 -2
  79. package/dist/web/record/record.js +10 -2
  80. package/dist/web/workspace/SincproApp.d.ts +9 -20
  81. package/dist/web/workspace/SincproApp.js +17 -4
  82. package/dist/web/workspace/composer.d.ts +1 -2
  83. package/dist/web/workspace/composer.js +2 -2
  84. package/dist/web/workspace/open.d.ts +1 -1
  85. package/dist/web/workspace/open.js +1 -0
  86. package/dist/web/workspace/record.d.ts +60 -13
  87. package/dist/web/workspace/record.js +89 -28
  88. package/dist/web/workspace/workspace.d.ts +1 -1
  89. package/dist/web/workspace/workspace.js +1 -0
  90. package/package.json +45 -15
  91. package/dist/codegen/cli.d.ts +0 -2
  92. package/dist/codegen/cli.js +0 -82
  93. package/dist/codegen/client.d.ts +0 -14
  94. package/dist/codegen/client.js +0 -178
  95. package/dist/codegen/domain.d.ts +0 -14
  96. package/dist/codegen/domain.js +0 -195
  97. package/dist/codegen/entities.d.ts +0 -14
  98. package/dist/codegen/entities.js +0 -158
  99. package/dist/codegen/index.d.ts +0 -11
  100. package/dist/codegen/index.js +0 -9
  101. package/dist/codegen/metamodel.d.ts +0 -89
  102. package/dist/codegen/metamodel.js +0 -1
  103. package/dist/codegen/names.d.ts +0 -40
  104. package/dist/codegen/names.js +0 -114
  105. package/dist/codegen/rest.d.ts +0 -31
  106. package/dist/codegen/rest.js +0 -27
  107. package/dist/core/contract.d.ts +0 -34
  108. package/dist/core/contract.js +0 -41
  109. package/dist/core/discovery.d.ts +0 -47
  110. package/dist/core/discovery.js +0 -68
  111. package/dist/core/entity.d.ts +0 -227
  112. package/dist/core/entity.js +0 -187
  113. package/dist/core/ids.d.ts +0 -17
  114. package/dist/core/ids.js +0 -52
  115. package/dist/core/memory.d.ts +0 -46
  116. package/dist/core/memory.js +0 -108
  117. package/dist/core/meta.d.ts +0 -121
  118. package/dist/core/meta.js +0 -130
  119. package/dist/core/metas.d.ts +0 -17
  120. package/dist/core/metas.js +0 -7
  121. package/dist/core/rest.d.ts +0 -49
  122. package/dist/core/rest.js +0 -143
  123. package/dist/core/retry.d.ts +0 -24
  124. package/dist/core/retry.js +0 -25
  125. package/dist/core/schema.d.ts +0 -39
  126. package/dist/core/schema.js +0 -128
  127. package/dist/core/transport.d.ts +0 -90
  128. package/dist/core/zone.d.ts +0 -27
  129. package/dist/core/zone.js +0 -75
package/README.md CHANGED
@@ -4,17 +4,29 @@
4
4
  [`sincpro_framework`](https://github.com/Sincpro-SRL/sincpro_framework) already resolves on the
5
5
  server — entities, criteria, commands, drafts, events — and puts it on screen with
6
6
  [`@sincpro/web-ui`](https://github.com/Sincpro-SRL/sincpro_web_ui), opened where
7
- [`@sincpro/web-composer`](https://github.com/Sincpro-SRL/sincpro_web_composer) says. An
8
- application declares its entities and names its fields; the rest follows.
7
+ [`@sincpro/web-composer`](https://github.com/Sincpro-SRL/sincpro_web_composer) says. What every
8
+ client shares — the transport, the entities, the generated client, the application's use cases
9
+ traced and reported — is
10
+ [`@sincpro/client-framework`](https://github.com/Sincpro-SRL/sincpro_client_framework)'s; this
11
+ package is the screens. An application declares its entities and names its fields; the rest
12
+ follows. Every Sincpro framework speaks one
13
+ [ubiquitous language](https://github.com/Sincpro-SRL/sincpro_client_framework/blob/main/docs/UBIQUITOUS_LANGUAGE.md):
14
+ a bounded context, a Feature, the process, the context mean the same here, on the phone and on
15
+ the server.
9
16
 
10
17
  ```bash
11
- yarn add @sincpro/web-framework @sincpro/web-ui @sincpro/web-composer @sincpro/criteria @sincpro/criteria-react react react-dom
18
+ yarn add @sincpro/web-framework @sincpro/client-framework @sincpro/web-ui @sincpro/web-composer \
19
+ @sincpro/criteria @sincpro/criteria-react react react-dom
12
20
  ```
13
21
 
14
22
  Requires React 19 or newer.
15
23
 
16
24
  ## What we believe
17
25
 
26
+ > The founding statement is [`MANIFESTO.md`](MANIFESTO.md): what this repository is, what it is
27
+ > not, how it is composed and where it is going. What follows is how those beliefs show in the
28
+ > pieces that exist today.
29
+
18
30
  **An ERP is modular, so its framework must be open.** Somebody will always have the case nobody
19
31
  foresaw — a reconciliation screen, a strange relation, a wizard over three entities. They must
20
32
  be able to build it here, without asking us and without fighting us. So:
@@ -52,44 +64,82 @@ be able to build it here, without asking us and without fighting us. So:
52
64
 
53
65
  ## The stack
54
66
 
55
- | Project | Brings |
56
- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
57
- | `sincpro_framework` | Entities, criteria, reads (`Get`, `LiteralSearch`, `Search`, `Preview`), commands and dry runs, drafts, events, permissions, protocols (REST, JSON-RPC, gRPC, MCP) |
58
- | `@sincpro/criteria` | The contract with the server: `Criteria`, `Meta`, `Page`, `Problem` |
59
- | `@sincpro/web-ui` | What a screen looks like: `List`, `Record`, `SearchBar`, `Picker`, `Activity` |
60
- | `@sincpro/web-composer` | Where it opens and the context: page, peek, window, panels, shared selection, ⌘K, shortcuts |
61
- | **this package** | The glue: entity + model definition + state + actions, drawn with web-ui, opened with composer |
62
- | Your application | What an invoice is |
67
+ | Project | Brings |
68
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
69
+ | `sincpro_framework` | Entities, criteria, reads (`Get`, `LiteralSearch`, `Search`, `Preview`), commands and dry runs, drafts, events, permissions, protocols (REST, JSON-RPC, gRPC, MCP) |
70
+ | `@sincpro/criteria` | The contract with the server: `Criteria`, `Meta`, `Page`, `Problem` |
71
+ | `@sincpro/client-framework` | What every client shares — web, mobile, a server-side render, a script: the transport, `entity()`, the generated client, `Feature` and `ApplicationService` traced and reported by default |
72
+ | `@sincpro/web-ui` | What a screen looks like: `List`, `Record`, `SearchBar`, `Picker`, `Activity` |
73
+ | `@sincpro/web-composer` | Where it opens and the context: page, peek, window, panels, shared selection, ⌘K, shortcuts |
74
+ | **this package** | The screens: state, lists, records, pickers and commands drawn with web-ui, opened with composer; optional browser telemetry and error reporting |
75
+ | Your application | What an invoice is |
63
76
 
64
77
  ## How it fits together
65
78
 
66
- Three packages, one direction. **web-ui draws and tells** («they pressed this name, and asked
67
- for a modal»); it never imports composer and never knows where anything opens. **Composer
68
- decides where** — page, modal, preview, side panel, window, the breadcrumb, the phone — and never
69
- draws a record. **This package connects them**, from what the server publishes about each model.
79
+ Four packages, one direction. **client-framework talks to the server** and runs the
80
+ application's logic — the same on every platform. **web-ui draws and tells** («they pressed this
81
+ name, and asked for a modal»); it never imports composer and never knows where anything opens.
82
+ **Composer decides where** — page, modal, preview, side panel, window, the breadcrumb, the phone —
83
+ and never draws a record. **This package connects them on the web**, from what the server
84
+ publishes about each model.
70
85
 
71
86
  ```mermaid
72
87
  flowchart LR
73
88
  subgraph server["sincpro_framework · the backend"]
74
- api["entities · criteria · commands<br/>drafts · events · model definition"]
89
+ api["entities · criteria · commands · drafts<br/>events · client contract · its traces"]
90
+ end
91
+ criteria["@sincpro/criteria<br/>Criteria · Meta · Page · Problem"]
92
+ subgraph cf["@sincpro/client-framework · every platform"]
93
+ direction TB
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"]
96
+ generator["sincpro-client generate<br/>domain · client · entities"]
75
97
  end
76
- subgraph fw["@sincpro/web-framework · connects"]
98
+ subgraph fw["@sincpro/web-framework · the web"]
77
99
  direction TB
78
- core["core/<br/>Transport · entity() · Meta<br/>textOf · summaryOf"]
79
- react["react/<br/>useListing · useRecord<br/>useLookup · useSummaryOf"]
80
- web["web/<br/>EntityList · EntityPicker · RelatedRecord<br/>openIn · entityView · SincproApp"]
100
+ core["core/<br/>textOf · summaryOf · forms · lines · explain"]
101
+ react["react/<br/>useListing · useRecord · useCommand<br/>useLookup · useService · useContextValues"]
102
+ web["web/<br/>EntityList · EntityRecord · RecordField<br/>EntityPicker · entityView · SincproApp"]
103
+ optional["./telemetry · ./errors<br/>optional: OpenTelemetry · GlitchTip"]
81
104
  core --> react --> web
82
105
  end
83
- ui["@sincpro/web-ui · draws and tells<br/>List · Record · Picker<br/>RelationValue · RecordCard"]
84
- composer["@sincpro/web-composer · decides where<br/>page · modal · preview · side · window<br/>crumbs · ⌘K · phone"]
85
- app["your application<br/>entity() + its screens"]
106
+ ui["@sincpro/web-ui · draws and tells<br/>List · Record · Picker · SearchBar"]
107
+ composer["@sincpro/web-composer · decides where<br/>page · modal · preview · side · window"]
108
+ app["your application<br/>entrypoints · bounded contexts<br/>(generated · services · components)"]
86
109
 
87
- api <-->|"criteria over the wire<br/>(@sincpro/criteria)"| core
110
+ api <-->|"criteria and traceparent<br/>over the wire"| wire
111
+ criteria --> cf
112
+ cf --> fw
88
113
  web -->|"props read from the model"| ui
89
- ui -->|"gestures: onOpenIn(to), onChoose,<br/>onBrowseAll, onCreate"| web
90
- web -->|"api.open · api.pick · api.setTitle"| composer
91
- composer -->|"mounts the entity's view"| web
92
- app -->|"declares"| fw
114
+ ui -->|"gestures"| web
115
+ web -->|"api.open · api.pick"| composer
116
+ composer -->|"mounts the view"| web
117
+ generator -.->|"writes"| app
118
+ app -->|"its services and entities"| cf
119
+ app -->|"its screens"| fw
120
+ ```
121
+
122
+ What happens when a screen runs one of the application's use cases — one trace from the click to
123
+ the database:
124
+
125
+ ```mermaid
126
+ sequenceDiagram
127
+ actor person as Person
128
+ participant screen as Screen<br/>(useService)
129
+ participant service as CloseAndNotify<br/>(ApplicationService)
130
+ participant feature as Issues<br/>(Feature)
131
+ participant client as Generated client<br/>(bound transport)
132
+ participant server as sincpro_framework
133
+
134
+ person->>screen: presses «Close»
135
+ screen->>service: run(input) — busy
136
+ service->>service: interceptor opens project/CloseAndNotify
137
+ service->>feature: this.feature.Issues.close(…)
138
+ feature->>feature: child span project/Issues.close
139
+ feature->>client: this.client.closeIssue(…)
140
+ client->>server: POST … traceparent, sincpro-context
141
+ server-->>client: answer (the server's span is a child of the client's)
142
+ client-->>screen: answer — or a failure: refused (shown) / unexpected (reported once)
93
143
  ```
94
144
 
95
145
  What happens when a person presses the customer of an invoice:
@@ -140,10 +190,12 @@ flowchart LR
140
190
  @source "./";
141
191
  ```
142
192
 
143
- **2. The transport** — the one door to the backend. The session is the application's: it puts
144
- its headers here.
193
+ **2. The transport** — the one door to the backend, from @sincpro/client-framework. The session
194
+ is the application's: it puts its headers here.
145
195
 
146
196
  ```ts
197
+ import { restTransport } from "@sincpro/client-framework";
198
+
147
199
  export const transport = restTransport({
148
200
  base: "/v1",
149
201
  headers: () => ({ Authorization: `Bearer ${session.token}` }),
@@ -157,9 +209,13 @@ document again, revalidated by its `ETag`. A form computes a published formula i
157
209
  server for a preview only when a change reaches something it cannot answer.
158
210
 
159
211
  **3. The entities** — declared once: where each is read and written, and its key in the
160
- workspace (`domain:kind`). `summary` only when its fields are not the conventional ones.
212
+ workspace (`domain:kind`). `summary` only when its fields are not the conventional ones. A service
213
+ on sincpro_framework does not write them: `sincpro-client generate` does, from its contract
214
+ («From the contract», below).
161
215
 
162
216
  ```ts
217
+ import { entity } from "@sincpro/client-framework";
218
+
163
219
  export const customers = entity<Customer>("sales:customer", {
164
220
  list: "/customers",
165
221
  summary: { image: "logo", person: true },
@@ -305,7 +361,40 @@ const summarize = useSummaryOf(customers);
305
361
  />;
306
362
  ```
307
363
 
308
- A domain with no sincpro_framework behind it declares its model by hand and is drawn the same
364
+ **7. The application's logic** lives in its services — `Feature` and `ApplicationService` of
365
+ each bounded context, set up with @sincpro/client-framework the way sincpro_framework sets one up
366
+ (its dependencies, its services, `project.Issues.close(input)`; see its README) — and a screen
367
+ only runs them. The process is where the application injects its telemetry, its error reporting
368
+ and where the context lives, once, in `main`; without them, everything runs the same:
369
+
370
+ ```ts
371
+ // entrypoints/main.tsx
372
+ import { configureProcess, processContext } from "@sincpro/client-framework";
373
+ import { glitchtipReporter } from "@sincpro/web-framework/errors"; // optional
374
+ import { browserTracer } from "@sincpro/web-framework/telemetry"; // optional
375
+
376
+ configureProcess({
377
+ tracer: browserTracer({ endpoint: settings.otlp, service: "my-app", release }),
378
+ reporter: glitchtipReporter({ dsn: settings.glitchtip, release }),
379
+ });
380
+ processContext.set({ tenant_id: session.tenant }); // every use case runs with it and sends it
381
+ ```
382
+
383
+ ```tsx
384
+ function CloseButton({ issueId }: { issueId: string }) {
385
+ const close = useService(project.Issues.close); // run · busy · answer · error
386
+ return (
387
+ <>
388
+ <Button disabled={close.busy} onClick={() => close.run({ issue_id: issueId })}>
389
+ Close
390
+ </Button>
391
+ {close.error ? <Refused error={close.error} /> : null}
392
+ </>
393
+ );
394
+ }
395
+ ```
396
+
397
+ A bounded context with no sincpro_framework behind it declares its model by hand and is drawn the same
309
398
  way:
310
399
 
311
400
  ```ts
@@ -327,30 +416,33 @@ const tickets = defineMeta({
327
416
  Each answers one question, and each comes in the three levels — use the component, drop to the
328
417
  hook and draw your own, or go straight to the loose piece.
329
418
 
330
- | Question | Declarative | Hook | Loose piece |
331
- | -------------------------------- | ------------------------------------------------------- | ------------------------------------- | ------------------------------------ |
332
- | Where is the data? | `entity()` | — | `restTransport`, `memoryTransport` |
333
- | What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
334
- | What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
335
- | How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
336
- | N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
337
- | A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
338
- | A record's whole screen | `EntityRecord`, `entityView` without `record` | — | `formOf` |
339
- | Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
340
- | How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
341
- | One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
342
- | Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
343
- | Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
344
- | Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
345
- | Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
346
- | A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
347
- | Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
348
- | Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
349
- | Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
350
- | Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
351
- | Act on it (with a dry run) | `CommandButton`, `commands` on rows | `useCommand` | `transport.send` |
352
- | What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
353
- | The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
419
+ | Question | Declarative | Hook | Loose piece |
420
+ | -------------------------------- | ----------------------------------------------------------- | ------------------------------------- | ---------------------------------------- |
421
+ | Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
422
+ | The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
423
+ | What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
424
+ | What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
425
+ | What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
426
+ | What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
427
+ | How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
428
+ | N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
429
+ | A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
430
+ | A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
431
+ | Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
432
+ | How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
433
+ | One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
434
+ | Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
435
+ | Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
436
+ | Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
437
+ | Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
438
+ | A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
439
+ | Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
440
+ | Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
441
+ | Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
442
+ | Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
443
+ | Act on it (with a dry run) | `CommandButton`, `commands` on rows | `useCommand` | `transport.send` |
444
+ | What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
445
+ | The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
354
446
 
355
447
  The rules behind them, in short:
356
448
 
@@ -367,46 +459,48 @@ The rules behind them, in short:
367
459
 
368
460
  There is no store of ours to learn: each kind of state already has its owner.
369
461
 
370
- | State | Lives in | Read with |
371
- | -------------------------------------------- | -------------------------------------------------- | ---------------------------------- |
372
- | Who answers, language, known models | `FrameworkProvider` (this package) | the hooks, through context |
373
- | What the backend sees on every request | the transport's `headers` (e.g. `sincpro-context`) | the backend's `use_context()` |
374
- | What an opening carries (company, a default) | composer: the reference's `params` | `api.self.params`, `api.setParams` |
375
- | The record a modal covers | composer: `api.over` | `api.over` |
376
- | What a chooser was asked | composer: `pick(…, { question })` | `api.choosing` |
377
- | What the user is on, what is selected | composer: `api.context` | `useWorkspaceContext(api)` |
378
- | A screen's list, record, groups | the hooks | `useListing`, `useRecord`, … |
462
+ | State | Lives in | Read with |
463
+ | -------------------------------------------- | --------------------------------------------------------- | ---------------------------------- |
464
+ | Who answers, language, known models | `FrameworkProvider` (this package) | the hooks, through context |
465
+ | What the backend sees on every request | `processContext` (client-framework), as `sincpro-context` | the backend's `use_context()` |
466
+ | What an opening carries (company, a default) | composer: the reference's `params` | `api.self.params`, `api.setParams` |
467
+ | The record a modal covers | composer: `api.over` | `api.over` |
468
+ | What a chooser was asked | composer: `pick(…, { question })` | `api.choosing` |
469
+ | What the user is on, what is selected | composer: `api.context` | `useWorkspaceContext(api)` |
470
+ | A screen's list, record, groups | the hooks | `useListing`, `useRecord`, … |
379
471
 
380
472
  Not yet: a new record does not take the `params` it was opened with as its initial values
381
473
  (`ROADMAP.md`, «Estado y contexto»).
382
474
 
383
475
  ### Inside
384
476
 
385
- Three folders, one direction — `make doctor` keeps the arrows:
386
-
387
- | Folder | Knows | Why apart |
388
- | --------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------- |
389
- | `core` | transport, cache, entity, model definition, what a value and a record read as | plain logic, tested in Node in milliseconds |
390
- | `react` | `useListing`, `useRecord`, `useRelated`, `useSummaryOf`…, the provider | state that draws nothing: usable without `EntityList` |
391
- | `web/list` | a collection: `EntityList`, `EntitySearchBar`, `columnsOf` | N records, any size |
392
- | `web/record` | one record: `RecordField`, `factsOf`, `RelatedList`, `EntityPicker`, `cardOf` | works outside a workspace (no composer) |
393
- | `web/workspace` | the composer: `entityView`, `openIn`, `RelatedRecord`, `<SincproApp>` | where it opens, the application context |
477
+ Three levels, one direction, and two optional entries — `make doctor` keeps the arrows:
394
478
 
395
- Everything is imported from `@sincpro/web-framework`. Code that draws nothing — a script, a
396
- test in Node, a generated client — imports `@sincpro/web-framework/core`, which loads no React.
479
+ | Folder | Knows | Why apart |
480
+ | --------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
481
+ | `core` | what a value and a record read as, forms, lines, the trail, `explain`, the cache | plain logic, tested in Node in milliseconds |
482
+ | `react` | `useListing`, `useRecord`, `useRelated`, `useSummaryOf`…, the provider | state that draws nothing: usable without `EntityList` |
483
+ | `web/list` | a collection: `EntityList`, `EntitySearchBar`, `columnsOf` | N records, any size |
484
+ | `web/record` | one record: `RecordField`, `factsOf`, `RelatedList`, `EntityPicker`, `cardOf` | works outside a workspace (no composer) |
485
+ | `web/workspace` | the composer: `entityView`, `openIn`, `RelatedRecord`, `<SincproApp>` | where it opens, the application context |
486
+ | `telemetry`, `errors` | `browserTracer`, `glitchtipReporter`: built from the application's settings | optional peers, loaded after the first render; nothing else imports them |
397
487
 
398
- A fourth folder, `codegen`, is a build step: no screen loads it (`make doctor`).
488
+ Screens import from `@sincpro/web-framework`. What every platform shares — the transport,
489
+ `entity()`, model definitions, `Feature` and `ApplicationService`, the generated client — is
490
+ [@sincpro/client-framework](https://github.com/Sincpro-SRL/sincpro_client_framework)'s, imported
491
+ from there and never re-exported here. `@sincpro/web-framework/core` is the screens' plain logic
492
+ (what a value reads as, a form's defaults, lines), loaded without React.
399
493
 
400
494
  ### From the contract
401
495
 
402
496
  A service built on sincpro_framework exports what it publishes — its models and every operation,
403
497
  what each one is for its entity and how each wire reaches it — as one client contract per
404
- bounded context. `sincpro-web generate` writes, from it, what the screens used to declare by
498
+ bounded context. `sincpro-client generate` (@sincpro/client-framework) writes, from it, what the screens used to declare by
405
499
  hand:
406
500
 
407
501
  ```bash
408
502
  python -m sincpro_framework.entrypoints export-client-contract app.http:gateways contracts/
409
- npx sincpro-web generate contracts/project.contract.json --out src/generated/project --base /v1
503
+ npx sincpro-client generate contracts/project.contract.json --out src/generated/project --base /v1
410
504
  ```
411
505
 
412
506
  | File | What it holds |
@@ -420,14 +514,17 @@ What is generated is never edited; a screen extends it (`presented(issues, { row
420
514
  with `&`). Keep the folder out of prettier and eslint, and let CI regenerate and compare it.
421
515
  At runtime nothing is closed: the transport keeps reading the live definitions. How an
422
516
  application adopts it — where each file goes, what is written by hand, how a hand-written screen
423
- moves to the generated one — is [`docs/ADOPCION.md`](docs/ADOPCION.md) (in Spanish).
517
+ moves to the generated one — is [`docs/ADOPTION.md`](docs/ADOPTION.md).
424
518
 
425
519
  ## Where it stands
426
520
 
427
521
  | Piece | What it solves | Status |
428
522
  | --------------------------------------- | -------------------------------------------------------------------------------------------- | ------ |
429
- | `restTransport`, `memoryTransport` | The backend, or the same engine in memory | ✅ |
430
- | `defineMeta`, `metaFromSchema` | A model by hand, or completed from OpenAPI | ✅ |
523
+ | `restTransport`, `memoryTransport` | The backend, or the same engine in memory (client-framework) | ✅ |
524
+ | `defineMeta`, `metaFromSchema` | A model by hand, or completed from OpenAPI (client-framework) | ✅ |
525
+ | `useService` | A screen runs one of the application's use cases: run, busy, answer, error | ✅ |
526
+ | `./telemetry`, `./errors` | Optional: the application's traces to its OTLP endpoint, its errors to GlitchTip | ✅ |
527
+ | `selection` | Filters named as criteria 2.0 and the backend read them, the search bar's included | ✅ |
431
528
  | `useListing`, `EntityList` | N records: criteria, search bar, builder, paging | ✅ |
432
529
  | `useRecord`, `factsOf`, `RecordLines` | One record: facts, relations with their real total | ✅ |
433
530
  | Preloaded definitions | `FrameworkProvider metas`: the models of the discovery document, or of an exported metamodel | ✅ |
@@ -439,7 +536,7 @@ moves to the generated one — is [`docs/ADOPCION.md`](docs/ADOPCION.md) (in Spa
439
536
  | `readRoute`, `Transport.read` | A GET of the context's own (`/me`), neither a page nor a record | ✅ |
440
537
  | A key alone (`EntityID`), `useNameOf` | A key that names whose record it is, drawn as a many2one: a picker, and the name when read | ✅ |
441
538
  | `versionsOf`, `onVersionDrift` | A snapshot behind the server is told once per model — never an error | ✅ |
442
- | `sincpro-web generate` | A context's DTOs, client and entities out of its exported client contract | ✅ |
539
+ | `sincpro-client generate` | A context's DTOs, client and entities out of its exported client contract | ✅ |
443
540
  | `metasOf`, `bodyFor` (`target`) | Definitions preloaded from that snapshot; a Command's record written where its body names it | ✅ |
444
541
  | `useHistory` | Business events in `Record.Activity` (comments: backend first) | ✅ |
445
542
  | `entityView` | An entity as a composer view: list, record, ⌘K search | ✅ |
@@ -472,13 +569,17 @@ moves to the generated one — is [`docs/ADOPCION.md`](docs/ADOPCION.md) (in Spa
472
569
  | `Trail`, `Record.Pager` | Previous / next from a record, across the server's pages | ✅ |
473
570
  | `EntityList sums` | Each group says how much it adds up, summed by the server over all of it | ✅ |
474
571
 
475
- What it does **not** do: mobile (`sincpro_mobile` has its own core), sessions and login (the
476
- application's), routing (composer's), string-named widget registries, technical logs on a
477
- record's screen, business rules.
572
+ What it does **not** do: mobile screens (`@sincpro/mobile` draws them; what it shares with the
573
+ web is @sincpro/client-framework), sessions and login (the application's), routing (composer's),
574
+ string-named widget registries, technical logs on a record's screen, business rules.
575
+
576
+ **Still to come** (`docs/prd/PRD_02_how-an-application-is-built.md`): the framework's own reads and writes
577
+ as traced Features, so every screen it draws is traced too — today the application's use cases
578
+ are; the levels of context and the bounded contexts; the extension model.
478
579
 
479
580
  The full purpose — literal search, drafts, composer context, several entities per screen — is
480
581
  in [`docs/PURPOSE.md`](docs/PURPOSE.md); what was found while building and what comes next is in
481
- [`docs/ROADMAP.md`](docs/ROADMAP.md) (both in Spanish).
582
+ [`docs/ROADMAP.md`](docs/ROADMAP.md).
482
583
 
483
584
  ## Built for large sets
484
585
 
@@ -1,5 +1,4 @@
1
- import type { Entity } from "./entity.js";
2
- import type { Transport } from "./transport.js";
1
+ import { type Entity, type Transport } from "@sincpro/client-framework";
3
2
  /**
4
3
  * A transport that remembers what it read, for a while, and forgets it when something writes.
5
4
  *
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  function pathOf(route) {
2
3
  return route.split("?")[0] ?? route;
3
4
  }
@@ -46,18 +47,20 @@ export function cachedTransport(transport, options = {}) {
46
47
  forget([path]);
47
48
  };
48
49
  return {
49
- list(route, criteria, signal) {
50
- return remembered(`list ${route} ${JSON.stringify(criteria)}`, () => transport.list(route, criteria, signal));
50
+ // A call's own headers (a use case's trace) never change the answer: they travel, and the
51
+ // answer is kept by the question alone.
52
+ list(route, criteria, signal, options) {
53
+ return remembered(`list ${route} ${JSON.stringify(criteria)}`, () => transport.list(route, criteria, signal, options));
51
54
  },
52
- one(route, signal) {
53
- return remembered(`one ${route}`, () => transport.one(route, signal));
55
+ one(route, signal, options) {
56
+ return remembered(`one ${route}`, () => transport.one(route, signal, options));
54
57
  },
55
58
  // A read of the context's own (`GET /me`) is not an entity's: no write forgets it, so it is
56
59
  // never kept — it goes to the server every time.
57
60
  ...(transport.read === undefined
58
61
  ? {}
59
62
  : {
60
- read: (route, signal) => transport.read(route, signal),
63
+ read: (route, signal, options) => transport.read(route, signal, options),
61
64
  }),
62
65
  async send(method, route, body, signal, sending) {
63
66
  // A preview writes nothing; anything else may have changed what was read.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What a person reads about a failure: a heading, and a sentence with what happened and what
3
+ * to do. The server's own words first; the copy table's when it sent none.
4
+ *
5
+ * explain(new TransportError("/x", 403, { kind: "permission_denied", guidance: "Pedí acceso.", … }))
6
+ * -> { heading: "No tenés acceso", sentence: "Pedí acceso.", retryable: false }
7
+ *
8
+ * Context: the transport is @sincpro/client-framework's and speaks no language; how a refusal
9
+ * reads on a screen is the web's, with the words of its copy table.
10
+ */
11
+ export declare function explain(error: unknown): {
12
+ heading: string;
13
+ sentence: string;
14
+ retryable: boolean;
15
+ };
@@ -1,36 +1,14 @@
1
+ import { TransportError } from "@sincpro/client-framework";
1
2
  import { frameworkCopy } from "./copy.js";
2
- /**
3
- * A read through `transport.read`, or the reason it cannot be: a transport that has no `read`
4
- * is said so by name, never a `TypeError` from somewhere inside a screen.
5
- */
6
- export function readRoute(transport, route, signal) {
7
- if (transport.read === undefined)
8
- return Promise.reject(new Error(`this transport has no read(): it cannot ask GET ${route} — give it one`));
9
- return transport.read(route, signal);
10
- }
11
- /**
12
- * A refusal, from any wire. `problem` is what the server said about it (RFC 9457 plus the
13
- * engine's `kind`, `next_step`, `guidance`) or `null` when it said nothing readable — a proxy's
14
- * HTML page. `status` is `null` when the request never got an answer.
15
- */
16
- export class TransportError extends Error {
17
- route;
18
- status;
19
- problem;
20
- constructor(route, status, problem, message) {
21
- super(message ?? problem?.detail ?? problem?.title ?? `${status ?? "no answer"} at ${route}`);
22
- this.route = route;
23
- this.status = status;
24
- this.problem = problem;
25
- this.name = "TransportError";
26
- }
27
- }
28
3
  /**
29
4
  * What a person reads about a failure: a heading, and a sentence with what happened and what
30
5
  * to do. The server's own words first; the copy table's when it sent none.
31
6
  *
32
7
  * explain(new TransportError("/x", 403, { kind: "permission_denied", guidance: "Pedí acceso.", … }))
33
8
  * -> { heading: "No tenés acceso", sentence: "Pedí acceso.", retryable: false }
9
+ *
10
+ * Context: the transport is @sincpro/client-framework's and speaks no language; how a refusal
11
+ * reads on a screen is the web's, with the words of its copy table.
34
12
  */
35
13
  export function explain(error) {
36
14
  const copy = frameworkCopy().failure;
@@ -1,5 +1,5 @@
1
+ import { type SummaryFields } from "@sincpro/client-framework";
1
2
  import type { Meta } from "@sincpro/criteria";
2
- import { type SummaryFields } from "./summary.js";
3
3
  /**
4
4
  * What a record's form shows when the screen names nothing: its fields, and the pages beside
5
5
  * them — read from the model, in the order it declares.
package/dist/core/form.js CHANGED
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  import { BOOKKEEPING } from "./present.js";
2
3
  import { summaryFieldsOf } from "./summary.js";
3
4
  export function formOf(meta, summary = {}) {
@@ -1,30 +1,24 @@
1
1
  /**
2
- * The plain logic: no React, no DOM, no design system — so it is tested in Node, fast, with
3
- * no browser. The transport, the entity, the model definition and what a value reads as.
4
- * `make doctor` keeps it that way.
2
+ * The plain logic of the screens: no React, no DOM, no design system — so it is tested in Node,
3
+ * fast, with no browser. What a value reads as, what a form sends, how lines are edited, a
4
+ * record's place in its list, a failure in a person's words. `make doctor` keeps it that way.
5
+ *
6
+ * Context: the transport, the entity, the client contract, the model definitions and the
7
+ * day/instant conversions (`installTimeZone`, `wallTimeOf`, `instantOf`, `dayOf`) are
8
+ * @sincpro/client-framework's — the same on every platform — and are imported from there.
5
9
  */
6
10
  export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
7
- export { type ClientContract, entityKeyOf, metasOf, versionsOf, } from "./contract.js";
8
11
  export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
9
12
  export { type Advice, adviceAt, changesOf, computedLocally, creationOf, defaultsOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, type ServerFieldState, } from "./edit.js";
10
- export { bodyFor, type CommandAnswers, type CommandBodies, type CommandRoute, type Entity, entity, type EntityRef, type EntityRoutes, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
13
+ export { explain } from "./explain.js";
11
14
  export { type FormLayout, formOf } from "./form.js";
12
15
  export { type HistoryEntry, historyOf } from "./history.js";
13
- export { isEntityId, newEntityId } from "./ids.js";
14
16
  export { addingOf, type AddingRule, blankLine, type Declared, editableLines, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
15
17
  export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, } from "./list.js";
16
18
  export { lookupOf, type LookupOption } from "./lookup.js";
17
19
  export { detailOf, measuresOf, sumsOf } from "./measure.js";
18
- export { type MemoryOptions, type MemoryTable, memoryTransport, } from "./memory.js";
19
- export { defineMeta, field, type FieldOptions, type MetaSpec, type Words, } from "./meta.js";
20
- export { type MetaStore, metaStore } from "./metas.js";
21
20
  export { BOOKKEEPING, defaultFields, type FieldView, sortKeyOf, textOf, viewOf, } from "./present.js";
22
21
  export { type Related, relatedOf } from "./related.js";
23
22
  export { entityFor, type RelationField, relationFieldOf, } from "./relation.js";
24
- export { type RestOptions, restTransport, urlOf, type VersionDrift, } from "./rest.js";
25
- export { type RetryKeys, retryKeys, unanswered } from "./retry.js";
26
- export { completeMeta, type JsonSchema, metaFromSchema, type SchemaComponents, } from "./schema.js";
27
- export { type RecordSummary, type SummaryFields, summaryFieldsOf, summaryOf, type SummaryPart, } from "./summary.js";
23
+ export { type RecordSummary, summaryFieldsOf, summaryOf, } from "./summary.js";
28
24
  export { placeOf, stepIn, type Trail } from "./trail.js";
29
- export { type Draft, explain, type Method, type One, readRoute, type SendOptions, type Transport, TransportError, } from "./transport.js";
30
- export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";
@@ -1,30 +1,24 @@
1
1
  /**
2
- * The plain logic: no React, no DOM, no design system — so it is tested in Node, fast, with
3
- * no browser. The transport, the entity, the model definition and what a value reads as.
4
- * `make doctor` keeps it that way.
2
+ * The plain logic of the screens: no React, no DOM, no design system — so it is tested in Node,
3
+ * fast, with no browser. What a value reads as, what a form sends, how lines are edited, a
4
+ * record's place in its list, a failure in a person's words. `make doctor` keeps it that way.
5
+ *
6
+ * Context: the transport, the entity, the client contract, the model definitions and the
7
+ * day/instant conversions (`installTimeZone`, `wallTimeOf`, `instantOf`, `dayOf`) are
8
+ * @sincpro/client-framework's — the same on every platform — and are imported from there.
5
9
  */
6
10
  export { cachedTransport, } from "./cache.js";
7
- export { entityKeyOf, metasOf, versionsOf, } from "./contract.js";
8
11
  export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
9
12
  export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
10
- export { bodyFor, entity, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./entity.js";
13
+ export { explain } from "./explain.js";
11
14
  export { formOf } from "./form.js";
12
15
  export { historyOf } from "./history.js";
13
- export { isEntityId, newEntityId } from "./ids.js";
14
16
  export { addingOf, blankLine, editableLines, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
15
17
  export { defineList, isList, scopeOf, } from "./list.js";
16
18
  export { lookupOf } from "./lookup.js";
17
19
  export { detailOf, measuresOf, sumsOf } from "./measure.js";
18
- export { memoryTransport, } from "./memory.js";
19
- export { defineMeta, field, } from "./meta.js";
20
- export { metaStore } from "./metas.js";
21
20
  export { BOOKKEEPING, defaultFields, sortKeyOf, textOf, viewOf, } from "./present.js";
22
21
  export { relatedOf } from "./related.js";
23
22
  export { entityFor, relationFieldOf, } from "./relation.js";
24
- export { restTransport, urlOf, } from "./rest.js";
25
- export { retryKeys, unanswered } from "./retry.js";
26
- export { completeMeta, metaFromSchema, } from "./schema.js";
27
23
  export { summaryFieldsOf, summaryOf, } from "./summary.js";
28
24
  export { placeOf, stepIn } from "./trail.js";
29
- export { explain, readRoute, TransportError, } from "./transport.js";
30
- export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";