@sincpro/web-framework 2.6.0 → 3.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.
- package/README.md +62 -31
- package/dist/core/copy.d.ts +19 -1
- package/dist/core/copy.js +36 -0
- package/dist/core/explain.d.ts +12 -4
- package/dist/core/explain.js +18 -6
- package/dist/core/form.d.ts +7 -3
- package/dist/core/form.js +11 -5
- package/dist/core/groups.d.ts +17 -0
- package/dist/core/groups.js +31 -0
- package/dist/core/history.d.ts +45 -1
- package/dist/core/history.js +84 -12
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -4
- package/dist/core/list.d.ts +14 -16
- package/dist/core/list.js +18 -25
- package/dist/core/measure.d.ts +14 -5
- package/dist/core/measure.js +32 -7
- package/dist/core/present.d.ts +51 -3
- package/dist/core/present.js +162 -15
- package/dist/core/summary.d.ts +6 -2
- package/dist/react/context.d.ts +23 -2
- package/dist/react/context.js +51 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useCommand.d.ts +7 -1
- package/dist/react/useCommand.js +12 -2
- package/dist/react/useGroups.js +15 -4
- package/dist/react/useHistory.d.ts +4 -2
- package/dist/react/useHistory.js +20 -5
- package/dist/react/usePivot.js +18 -3
- package/dist/react/useRecord.d.ts +5 -2
- package/dist/react/useRecord.js +14 -2
- package/dist/react/useRecordLifecycle.d.ts +43 -0
- package/dist/react/useRecordLifecycle.js +49 -0
- package/dist/web/Refused.d.ts +3 -3
- package/dist/web/Refused.js +3 -3
- package/dist/web/index.d.ts +3 -2
- package/dist/web/index.js +2 -1
- package/dist/web/list/EntityList.js +70 -17
- package/dist/web/list/columns.d.ts +6 -1
- package/dist/web/list/columns.js +53 -8
- package/dist/web/list/presentation.d.ts +20 -1
- package/dist/web/list/rowCommands.d.ts +2 -0
- package/dist/web/list/rowCommands.js +6 -1
- package/dist/web/record/RecordLifecycle.d.ts +23 -0
- package/dist/web/record/RecordLifecycle.js +29 -0
- package/dist/web/record/RelatedList.d.ts +0 -15
- package/dist/web/record/RelatedList.js +35 -6
- package/dist/web/record/edit.d.ts +5 -0
- package/dist/web/record/edit.js +48 -8
- package/dist/web/record/opening.d.ts +2 -2
- package/dist/web/record/record.js +5 -2
- package/dist/web/workspace/SincproApp.d.ts +10 -1
- package/dist/web/workspace/SincproApp.js +18 -4
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +3 -4
- package/dist/web/workspace/record.d.ts +7 -2
- package/dist/web/workspace/record.js +41 -8
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -213,6 +213,20 @@ workspace (`domain:kind`). `summary` only when its fields are not the convention
|
|
|
213
213
|
on sincpro_framework does not write them: `sincpro-client generate` does, from its contract
|
|
214
214
|
(«From the contract», below).
|
|
215
215
|
|
|
216
|
+
`summary` is how an application says which of its fields plays each part of a record — its
|
|
217
|
+
state, its type, its description, its picture, who made it. The convention only knows English
|
|
218
|
+
names (`state`/`status`, `type`/`kind`/`category`, `description`/`summary`, `image`…): a model
|
|
219
|
+
whose state is `estado` names it, or its header shows no state and its rows no tag. Guessing is
|
|
220
|
+
not safe — an entity may hold two choices — so a field not named this way plays no part.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// quipu's payment: Spanish field names, said once.
|
|
224
|
+
export const payments = {
|
|
225
|
+
...generated.pagos,
|
|
226
|
+
summary: { state: "estado", description: "descripcion" },
|
|
227
|
+
};
|
|
228
|
+
```
|
|
229
|
+
|
|
216
230
|
```ts
|
|
217
231
|
import { entity } from "@sincpro/client-framework";
|
|
218
232
|
|
|
@@ -229,6 +243,21 @@ export const invoices = entity<Invoice>("sales:invoice", {
|
|
|
229
243
|
});
|
|
230
244
|
```
|
|
231
245
|
|
|
246
|
+
An entity with neither `edit` nor `save` — a payment, an order that only its Commands move — has
|
|
247
|
+
its records drawn read only, whole: nothing on screen invites typing what nobody can store.
|
|
248
|
+
|
|
249
|
+
**How a record looks** is the client's, declared once with the entity (`presented`): its row,
|
|
250
|
+
card and option, the columns of a table of it, the colour of each value of a choice and of each
|
|
251
|
+
kind of fact in its history. Cells, rows, cards, the record's tag and its activity use them:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
export const payments = presented(entity<Payment>("billing:payment", { list: "/payments" }), {
|
|
255
|
+
tones: { estado: { EN_REVISION: "warn", VALIDADO: "good", RECHAZADO: "bad" } },
|
|
256
|
+
facts: { pago_aprobado: "good", pago_rechazado: "bad" }, // by a fact's `name`, or its last part
|
|
257
|
+
columns: ["periodo", "monto", "estado"],
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
232
261
|
**4. The views** — each entity becomes a composer view: its list without an id, its record with
|
|
233
262
|
one, its search in ⌘K. Declared and nothing more, it already has both screens, drawn from its
|
|
234
263
|
model: `EntityList` (literal search on Enter, pages, «New») and `EntityRecord` (its name, type and
|
|
@@ -442,37 +471,39 @@ const tickets = defineMeta({
|
|
|
442
471
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
443
472
|
hook and draw your own, or go straight to the loose piece.
|
|
444
473
|
|
|
445
|
-
| Question | Declarative
|
|
446
|
-
| -------------------------------- |
|
|
447
|
-
| Where is the data? | `entity()` (client-framework)
|
|
448
|
-
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework)
|
|
449
|
-
| Read through a use case | its `Feature`s (client-framework)
|
|
450
|
-
| What every use case runs with | `processContext`, `project.context` (client-framework)
|
|
451
|
-
| What happened, what broke | `./telemetry`, `./errors` (optional)
|
|
452
|
-
| What is each field? | `Meta` from the server, or `defineMeta`
|
|
453
|
-
| A value outside a model | —
|
|
454
|
-
| What is a record, at any size? | `cardOf`, `relationOf`
|
|
455
|
-
| How does a record look? | `presented(entity, { option, row, card })`
|
|
456
|
-
| N records: search, filter, page | `EntityList`, `EntitySearchBar`
|
|
457
|
-
| A named slice (to collect, …) | `defineList` + `listView`
|
|
458
|
-
| A record's whole screen | `EntityRecord`, `entityView` without `record`
|
|
459
|
-
| Previous / next from a record | `EntityRecord` (from a list)
|
|
460
|
-
| How much each group adds up | `EntityList sums`
|
|
461
|
-
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines`
|
|
462
|
-
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`)
|
|
463
|
-
| Its relations, inside it | `RelatedList`
|
|
464
|
-
| What other records hold of it | web-ui's `SmartButton` opening `
|
|
465
|
-
| Choose one (literal search) | `EntityPicker`, `chooserIn`
|
|
466
|
-
| Choose several (many2many) | `EntityTags`
|
|
467
|
-
| A relation, from the model alone | `RecordField name="customer_id"`
|
|
468
|
-
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets`
|
|
469
|
-
| Look at the set several ways | `EntityList views` (table, rows, board, sheet)
|
|
470
|
-
| Cross it by two fields | `EntityList pivot`
|
|
471
|
-
| Order by several fields | the bar's criteria builder
|
|
472
|
-
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands
|
|
473
|
-
|
|
|
474
|
-
|
|
|
475
|
-
|
|
|
474
|
+
| Question | Declarative | Hook | Loose piece |
|
|
475
|
+
| -------------------------------- | --------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------- |
|
|
476
|
+
| Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
|
|
477
|
+
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
|
|
478
|
+
| Read through a use case | its `Feature`s (client-framework) | `useServiceReading` | `project.Accounts.balance(…)` |
|
|
479
|
+
| What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
|
|
480
|
+
| What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
|
|
481
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
482
|
+
| A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
|
|
483
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
484
|
+
| How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
|
|
485
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
486
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
487
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
|
|
488
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
489
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
490
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
491
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
492
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
493
|
+
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)` | `useCount` | `entity.listRef` (client-framework) |
|
|
494
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
495
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
496
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
497
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
498
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
|
|
499
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
500
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
501
|
+
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
502
|
+
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
503
|
+
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
504
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
505
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
506
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
476
507
|
|
|
477
508
|
The rules behind them, in short:
|
|
478
509
|
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type FrameworkCopy = {
|
|
|
15
15
|
items: (count: number, exact: boolean) => string;
|
|
16
16
|
};
|
|
17
17
|
list: {
|
|
18
|
+
/** The entity's trash: its archived records (`trashOf`). */
|
|
19
|
+
trash: string;
|
|
18
20
|
loadMore: string;
|
|
19
21
|
loading: string;
|
|
20
22
|
/** «12 of 120»: what is on screen against what matches. */
|
|
@@ -36,6 +38,10 @@ export type FrameworkCopy = {
|
|
|
36
38
|
groupsCapped: (shown: number) => string;
|
|
37
39
|
/** «12 groups · 187 records»: what the grouping split. */
|
|
38
40
|
groups: (groups: number, records: number) => string;
|
|
41
|
+
/** The foot adds up the rows in hand, and they are not the whole set. */
|
|
42
|
+
pageTotals: string;
|
|
43
|
+
/** A grouped question answered with something that is not groups. */
|
|
44
|
+
notGrouped: string;
|
|
39
45
|
};
|
|
40
46
|
record: {
|
|
41
47
|
/** A draft this caller kept is back on screen. */
|
|
@@ -57,6 +63,12 @@ export type FrameworkCopy = {
|
|
|
57
63
|
create: string;
|
|
58
64
|
/** A record's one2many: the button that opens the form of a new related record. */
|
|
59
65
|
add: string;
|
|
66
|
+
/** The record's own `Delete` (its dry run is shown before it runs). */
|
|
67
|
+
delete: string;
|
|
68
|
+
/** Into the entity's trash (`Archive`): out of every reading, nothing lost. */
|
|
69
|
+
archive: string;
|
|
70
|
+
/** Out of the trash (`Restore`): read again. */
|
|
71
|
+
restore: string;
|
|
60
72
|
};
|
|
61
73
|
picker: {
|
|
62
74
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
|
@@ -86,11 +98,17 @@ export type FrameworkCopy = {
|
|
|
86
98
|
failure: {
|
|
87
99
|
/** The server could not be reached at all — nothing it said is known. */
|
|
88
100
|
unreachable: string;
|
|
101
|
+
/** It answered, but not what was asked (a grouped question answered with records). */
|
|
102
|
+
unexpected: string;
|
|
89
103
|
/** It answered with a status and no problem to read. */
|
|
90
104
|
status: (status: number) => string;
|
|
91
105
|
retry: string;
|
|
92
|
-
/** What each kind of refusal is called
|
|
106
|
+
/** What each kind of refusal is called — the heading, before the server's own `title`. */
|
|
93
107
|
kind: Record<FailureKind, string>;
|
|
108
|
+
/** What to do next, by kind, when it is the same whatever was refused. A kind left out
|
|
109
|
+
* (`invalid`, `domain`) keeps the server's `guidance`: only the use case knows what fixes
|
|
110
|
+
* its own refusal. */
|
|
111
|
+
next: Partial<Record<FailureKind, string>>;
|
|
94
112
|
};
|
|
95
113
|
};
|
|
96
114
|
export declare const ENGLISH_FRAMEWORK_COPY: FrameworkCopy;
|
package/dist/core/copy.js
CHANGED
|
@@ -5,6 +5,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
5
5
|
items: (count, exact) => `${count}${exact ? "" : "+"} ${count === 1 ? "item" : "items"}`,
|
|
6
6
|
},
|
|
7
7
|
list: {
|
|
8
|
+
trash: "Trash",
|
|
8
9
|
loadMore: "Load more",
|
|
9
10
|
loading: "Loading…",
|
|
10
11
|
shown: (shown, total, exact) => `${shown} of ${total}${exact ? "" : "+"}`,
|
|
@@ -18,6 +19,8 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
18
19
|
noValue: "No value",
|
|
19
20
|
groupsCapped: (shown) => `The first ${shown} groups. Narrow the search to see the rest.`,
|
|
20
21
|
groups: (groups, records) => `${groups} ${groups === 1 ? "group" : "groups"} · ${records} ${records === 1 ? "record" : "records"}`,
|
|
22
|
+
pageTotals: "Totals of this page",
|
|
23
|
+
notGrouped: "The server did not answer with groups: this list cannot be grouped there.",
|
|
21
24
|
},
|
|
22
25
|
record: {
|
|
23
26
|
restored: "A draft you kept is back. Save it or discard it.",
|
|
@@ -30,6 +33,9 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
30
33
|
creating: (name) => (name ? `${name} · new` : "New"),
|
|
31
34
|
create: "New",
|
|
32
35
|
add: "Add",
|
|
36
|
+
delete: "Delete",
|
|
37
|
+
archive: "Move to the trash",
|
|
38
|
+
restore: "Restore",
|
|
33
39
|
},
|
|
34
40
|
picker: {
|
|
35
41
|
browse: "Search all",
|
|
@@ -50,6 +56,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
50
56
|
},
|
|
51
57
|
failure: {
|
|
52
58
|
unreachable: "The server could not be reached",
|
|
59
|
+
unexpected: "The server answered something else",
|
|
53
60
|
status: (status) => `The server answered ${status}`,
|
|
54
61
|
retry: "Retry",
|
|
55
62
|
kind: {
|
|
@@ -66,6 +73,17 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
66
73
|
unknown_outcome: "It is not known whether it was done",
|
|
67
74
|
internal: "Something failed on the server",
|
|
68
75
|
},
|
|
76
|
+
next: {
|
|
77
|
+
permission_denied: "Ask whoever administers it for access.",
|
|
78
|
+
not_found: "It may have been deleted, or the link is old.",
|
|
79
|
+
conflict: "Read it again before changing it.",
|
|
80
|
+
in_progress: "Wait a moment and look again.",
|
|
81
|
+
key_reused: "Read it again to see whether it was done.",
|
|
82
|
+
exhausted: "Wait a moment and try again.",
|
|
83
|
+
unavailable: "Try again in a few minutes.",
|
|
84
|
+
unknown_outcome: "Read it again before repeating it.",
|
|
85
|
+
internal: "If it happens again, report it.",
|
|
86
|
+
},
|
|
69
87
|
},
|
|
70
88
|
};
|
|
71
89
|
export const SPANISH_FRAMEWORK_COPY = {
|
|
@@ -75,6 +93,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
75
93
|
items: (count, exact) => `${count}${exact ? "" : "+"} ${count === 1 ? "elemento" : "elementos"}`,
|
|
76
94
|
},
|
|
77
95
|
list: {
|
|
96
|
+
trash: "Papelera",
|
|
78
97
|
loadMore: "Cargar más",
|
|
79
98
|
loading: "Cargando…",
|
|
80
99
|
shown: (shown, total, exact) => `${shown} de ${total}${exact ? "" : "+"}`,
|
|
@@ -88,6 +107,8 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
88
107
|
noValue: "Sin valor",
|
|
89
108
|
groupsCapped: (shown) => `Los primeros ${shown} grupos. Acotá la búsqueda para ver el resto.`,
|
|
90
109
|
groups: (groups, records) => `${groups} ${groups === 1 ? "grupo" : "grupos"} · ${records} ${records === 1 ? "registro" : "registros"}`,
|
|
110
|
+
pageTotals: "Totales de esta página",
|
|
111
|
+
notGrouped: "El servidor no contestó con grupos: esta lista no se puede agrupar ahí.",
|
|
91
112
|
},
|
|
92
113
|
record: {
|
|
93
114
|
restored: "Volvió un borrador que guardaste. Guardalo o descartalo.",
|
|
@@ -100,6 +121,9 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
100
121
|
creating: (name) => (name ? `${name} · nuevo` : "Nuevo"),
|
|
101
122
|
create: "Nuevo",
|
|
102
123
|
add: "Agregar",
|
|
124
|
+
delete: "Eliminar",
|
|
125
|
+
archive: "Mover a la papelera",
|
|
126
|
+
restore: "Restaurar",
|
|
103
127
|
},
|
|
104
128
|
picker: {
|
|
105
129
|
browse: "Buscar en todos",
|
|
@@ -120,6 +144,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
120
144
|
},
|
|
121
145
|
failure: {
|
|
122
146
|
unreachable: "No se pudo hablar con el servidor",
|
|
147
|
+
unexpected: "El servidor contestó otra cosa",
|
|
123
148
|
status: (status) => `El servidor respondió ${status}`,
|
|
124
149
|
retry: "Reintentar",
|
|
125
150
|
kind: {
|
|
@@ -136,6 +161,17 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
136
161
|
unknown_outcome: "No se sabe si se hizo",
|
|
137
162
|
internal: "Algo falló en el servidor",
|
|
138
163
|
},
|
|
164
|
+
next: {
|
|
165
|
+
permission_denied: "Pedí acceso a quien lo administra.",
|
|
166
|
+
not_found: "Puede que lo hayan eliminado, o el enlace es viejo.",
|
|
167
|
+
conflict: "Volvé a leerlo antes de cambiarlo.",
|
|
168
|
+
in_progress: "Esperá un momento y volvé a mirar.",
|
|
169
|
+
key_reused: "Volvé a leerlo para ver si se hizo.",
|
|
170
|
+
exhausted: "Esperá un momento y reintentá.",
|
|
171
|
+
unavailable: "Reintentá en unos minutos.",
|
|
172
|
+
unknown_outcome: "Volvé a leerlo antes de repetirlo.",
|
|
173
|
+
internal: "Si vuelve a pasar, avisá a soporte.",
|
|
174
|
+
},
|
|
139
175
|
},
|
|
140
176
|
};
|
|
141
177
|
let installed = ENGLISH_FRAMEWORK_COPY;
|
package/dist/core/explain.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What a person reads about a failure: a heading, and a sentence with what happened and what
|
|
3
|
-
* to do. The
|
|
3
|
+
* to do. The heading is the client's word for the kind of failure; the sentence is what the
|
|
4
|
+
* server said happened (`detail`) and what to do next — the copy table's for a kind whose next
|
|
5
|
+
* step is always the same, the server's `guidance` for one only the use case knows (`invalid`,
|
|
6
|
+
* `domain`).
|
|
4
7
|
*
|
|
5
|
-
* explain(new TransportError("/x", 403, { kind: "permission_denied",
|
|
6
|
-
* -> { heading: "No tenés acceso", sentence: "Pedí acceso.",
|
|
8
|
+
* explain(new TransportError("/x", 403, { kind: "permission_denied", detail: "No es tu pago.", … }))
|
|
9
|
+
* -> { heading: "No tenés acceso", sentence: "No es tu pago. Pedí acceso a quien lo administra.",
|
|
10
|
+
* retryable: false }
|
|
7
11
|
*
|
|
8
12
|
* 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.
|
|
13
|
+
* reads on a screen is the web's, with the words of its copy table. The server's `title` is one
|
|
14
|
+
* per kind and English until the language travels at the edge (sincpro_framework #190), and its
|
|
15
|
+
* default `guidance` too — so the heading and the generic next step are the copy's, and the
|
|
16
|
+
* server's words are kept where only it knows them: what happened, and how to fix a refusal of
|
|
17
|
+
* its own. quipu drew its own box because the server's English headed every refusal.
|
|
10
18
|
*/
|
|
11
19
|
export declare function explain(error: unknown): {
|
|
12
20
|
heading: string;
|
package/dist/core/explain.js
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { TransportError } from "@sincpro/client-framework";
|
|
2
2
|
import { frameworkCopy } from "./copy.js";
|
|
3
|
+
import { NotGrouped } from "./groups.js";
|
|
3
4
|
/**
|
|
4
5
|
* What a person reads about a failure: a heading, and a sentence with what happened and what
|
|
5
|
-
* to do. The
|
|
6
|
+
* to do. The heading is the client's word for the kind of failure; the sentence is what the
|
|
7
|
+
* server said happened (`detail`) and what to do next — the copy table's for a kind whose next
|
|
8
|
+
* step is always the same, the server's `guidance` for one only the use case knows (`invalid`,
|
|
9
|
+
* `domain`).
|
|
6
10
|
*
|
|
7
|
-
* explain(new TransportError("/x", 403, { kind: "permission_denied",
|
|
8
|
-
* -> { heading: "No tenés acceso", sentence: "Pedí acceso.",
|
|
11
|
+
* explain(new TransportError("/x", 403, { kind: "permission_denied", detail: "No es tu pago.", … }))
|
|
12
|
+
* -> { heading: "No tenés acceso", sentence: "No es tu pago. Pedí acceso a quien lo administra.",
|
|
13
|
+
* retryable: false }
|
|
9
14
|
*
|
|
10
15
|
* 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.
|
|
16
|
+
* reads on a screen is the web's, with the words of its copy table. The server's `title` is one
|
|
17
|
+
* per kind and English until the language travels at the edge (sincpro_framework #190), and its
|
|
18
|
+
* default `guidance` too — so the heading and the generic next step are the copy's, and the
|
|
19
|
+
* server's words are kept where only it knows them: what happened, and how to fix a refusal of
|
|
20
|
+
* its own. quipu drew its own box because the server's English headed every refusal.
|
|
12
21
|
*/
|
|
13
22
|
export function explain(error) {
|
|
14
23
|
const copy = frameworkCopy().failure;
|
|
15
24
|
if (error instanceof TransportError && error.problem !== null) {
|
|
16
25
|
const { kind, title, detail, guidance, retryable } = error.problem;
|
|
17
26
|
return {
|
|
18
|
-
heading:
|
|
19
|
-
sentence: [detail, guidance].filter(Boolean).join(" "),
|
|
27
|
+
heading: copy.kind[kind] ?? title ?? copy.status(error.status ?? 0),
|
|
28
|
+
sentence: [detail, copy.next[kind] ?? guidance].filter(Boolean).join(" "),
|
|
20
29
|
retryable,
|
|
21
30
|
};
|
|
22
31
|
}
|
|
32
|
+
// It answered, and not what was asked: retrying asks the same thing again.
|
|
33
|
+
if (error instanceof NotGrouped)
|
|
34
|
+
return { heading: copy.unexpected, sentence: error.message, retryable: false };
|
|
23
35
|
if (error instanceof TransportError && error.status !== null)
|
|
24
36
|
return { heading: copy.status(error.status), sentence: error.message, retryable: true };
|
|
25
37
|
return {
|
package/dist/core/form.d.ts
CHANGED
|
@@ -6,16 +6,20 @@ import type { Meta } from "@sincpro/criteria";
|
|
|
6
6
|
*
|
|
7
7
|
* Context: the default form must be useful on any entity, not a dump of every key. So:
|
|
8
8
|
*
|
|
9
|
-
* - the
|
|
10
|
-
* paper says them on its last line (`Record.Audit`)
|
|
9
|
+
* - the framework's stamps (`version`, who made and changed it and when, `archived_at`) are not
|
|
10
|
+
* fields: the paper says them on its last line (`Record.Audit`) and the activity says the
|
|
11
|
+
* rest; the picture is not a text box;
|
|
11
12
|
* - a read-only identity is the record's name, not a field to look at;
|
|
12
13
|
* - a many2one is written by its KEY (`customer_id`, a picker of customers): the expanded
|
|
13
14
|
* relation beside it (`customer`) would be the same thing twice;
|
|
14
15
|
* - a one2many is a page of its own — a list, not a field;
|
|
15
|
-
* - a value object
|
|
16
|
+
* - a value object the record embeds (a payment's receipt) is a section of its own fields, read
|
|
17
|
+
* from its definition (`sections`, each field named `recibo.numero`); a money stays a field;
|
|
18
|
+
* - a list of values and a many2many the backend cannot write yet are left to the screen.
|
|
16
19
|
*/
|
|
17
20
|
export type FormLayout = {
|
|
18
21
|
fields: string[];
|
|
19
22
|
pages: string[];
|
|
23
|
+
sections: string[];
|
|
20
24
|
};
|
|
21
25
|
export declare function formOf(meta: Meta | null | undefined, summary?: SummaryFields): FormLayout;
|
package/dist/core/form.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {} from "@sincpro/client-framework";
|
|
2
|
-
import { BOOKKEEPING } from "./present.js";
|
|
2
|
+
import { BOOKKEEPING, isMoneyDefinition, STAMPS } from "./present.js";
|
|
3
3
|
import { summaryFieldsOf } from "./summary.js";
|
|
4
4
|
export function formOf(meta, summary = {}) {
|
|
5
5
|
if (!meta)
|
|
6
|
-
return { fields: [], pages: [] };
|
|
6
|
+
return { fields: [], pages: [], sections: [] };
|
|
7
7
|
const parts = summaryFieldsOf(meta, {}, summary);
|
|
8
8
|
const told = new Set([parts.createdAt, parts.createdBy, parts.updatedAt, parts.updatedBy, parts.image].filter((name) => name !== undefined));
|
|
9
9
|
const keys = new Set(Object.values(meta.fields)
|
|
@@ -11,13 +11,19 @@ export function formOf(meta, summary = {}) {
|
|
|
11
11
|
.filter((name) => typeof name === "string" && name in meta.fields));
|
|
12
12
|
const fields = [];
|
|
13
13
|
const pages = [];
|
|
14
|
+
const sections = [];
|
|
14
15
|
for (const [name, field] of Object.entries(meta.fields)) {
|
|
15
|
-
if (BOOKKEEPING.has(name) || told.has(name))
|
|
16
|
+
if (BOOKKEEPING.has(name) || STAMPS.has(name) || told.has(name))
|
|
16
17
|
continue;
|
|
17
18
|
if (name === meta.identity && field.readonly)
|
|
18
19
|
continue;
|
|
19
|
-
if (field.kind === "embedded")
|
|
20
|
+
if (field.kind === "embedded") {
|
|
21
|
+
// A money is one value; any other value object with a definition is its fields.
|
|
22
|
+
const money = field.widget === "money" || isMoneyDefinition(field.definition);
|
|
23
|
+
if (field.many !== true && field.definition && !money)
|
|
24
|
+
sections.push(name);
|
|
20
25
|
continue;
|
|
26
|
+
}
|
|
21
27
|
if (field.kind === "relation") {
|
|
22
28
|
if (field.type === "one2many")
|
|
23
29
|
pages.push(name);
|
|
@@ -27,5 +33,5 @@ export function formOf(meta, summary = {}) {
|
|
|
27
33
|
}
|
|
28
34
|
fields.push(name);
|
|
29
35
|
}
|
|
30
|
-
return { fields, pages };
|
|
36
|
+
return { fields, pages, sections };
|
|
31
37
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Bucket } from "@sincpro/criteria";
|
|
2
|
+
/**
|
|
3
|
+
* Whether an answer to a grouped question holds groups — each with how many records it holds
|
|
4
|
+
* (`count`) and the criteria that opens it, its levels below too.
|
|
5
|
+
*
|
|
6
|
+
* Context: a backend that does not group answers records to the same question (sincpro_framework
|
|
7
|
+
* before 3.37.1, a fake that never learned), and a record read as a group has no `count`: web-ui's
|
|
8
|
+
* table fell over drawing it, and drawing «—» instead would show N empty groups that look valid
|
|
9
|
+
* (web-ui decided so in Sincpro-SRL/sincpro_web_ui#33). So the answer is checked here, once, and
|
|
10
|
+
* a list that got no groups says so in its failed state.
|
|
11
|
+
*/
|
|
12
|
+
export declare function areGroups(rows: readonly unknown[]): rows is readonly Bucket[];
|
|
13
|
+
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
14
|
+
export declare class NotGrouped extends Error {
|
|
15
|
+
readonly route: string;
|
|
16
|
+
constructor(route: string);
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { frameworkCopy } from "./copy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether an answer to a grouped question holds groups — each with how many records it holds
|
|
4
|
+
* (`count`) and the criteria that opens it, its levels below too.
|
|
5
|
+
*
|
|
6
|
+
* Context: a backend that does not group answers records to the same question (sincpro_framework
|
|
7
|
+
* before 3.37.1, a fake that never learned), and a record read as a group has no `count`: web-ui's
|
|
8
|
+
* table fell over drawing it, and drawing «—» instead would show N empty groups that look valid
|
|
9
|
+
* (web-ui decided so in Sincpro-SRL/sincpro_web_ui#33). So the answer is checked here, once, and
|
|
10
|
+
* a list that got no groups says so in its failed state.
|
|
11
|
+
*/
|
|
12
|
+
export function areGroups(rows) {
|
|
13
|
+
return rows.every((row) => {
|
|
14
|
+
if (typeof row !== "object" || row === null)
|
|
15
|
+
return false;
|
|
16
|
+
const bucket = row;
|
|
17
|
+
return (typeof bucket.count === "number" &&
|
|
18
|
+
typeof bucket.criteria === "object" &&
|
|
19
|
+
bucket.criteria !== null &&
|
|
20
|
+
(bucket.groups === undefined || areGroups(bucket.groups)));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
24
|
+
export class NotGrouped extends Error {
|
|
25
|
+
route;
|
|
26
|
+
constructor(route) {
|
|
27
|
+
super(frameworkCopy().list.notGrouped);
|
|
28
|
+
this.route = route;
|
|
29
|
+
this.name = "NotGrouped";
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/core/history.d.ts
CHANGED
|
@@ -11,11 +11,55 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
|
11
11
|
*
|
|
12
12
|
* These are business facts («Factura confirmada»), never technical logs: those belong to the
|
|
13
13
|
* observability stack, not to a record's screen.
|
|
14
|
+
*
|
|
15
|
+
* Since sincpro_framework 3.37 every fact also says which one it is (`name`, `billing.v1.deleted`),
|
|
16
|
+
* who did it (`actor`, the context's user — from the caller's identity since 3.37.1) and who the
|
|
17
|
+
* record was then (`entity_display`). Who did it is the entry's `by` — web-ui's activity draws
|
|
18
|
+
* it —; the rest of the envelope never repeats in its detail. What a fact's own fields are
|
|
19
|
+
* called is its event's definition in the contract (3.37.1): `eventMetasOf(contract)`
|
|
20
|
+
* (client-framework), by the fact's `name` — «reason» reads «Motivo» —, given to the provider as
|
|
21
|
+
* `events`; without it, the history route's own definition.
|
|
22
|
+
*
|
|
23
|
+
* An edit (`EntityUpdated`) carries each field it moved as `changes: {field: [before, after]}`
|
|
24
|
+
* and the word it was called then (`field_labels`, kept because an audit says what a person saw
|
|
25
|
+
* at the time): it reads «Título: Bienvenidos → Bienvenidos al CAUOR», each side as the record's
|
|
26
|
+
* own model writes it (a state by its word, an amount as money, a date in the installed style).
|
|
27
|
+
* quipu wrote this formatter itself, because the detail read `changes: {…} · field_labels: {…}`.
|
|
14
28
|
*/
|
|
15
29
|
export type HistoryEntry = {
|
|
16
30
|
id: string;
|
|
17
31
|
label: string;
|
|
18
32
|
at: string;
|
|
33
|
+
/** Who did it, as the fact says (`actor`); absent: the system, or a backend before 3.37. */
|
|
34
|
+
by?: string;
|
|
19
35
|
detail?: string;
|
|
36
|
+
/** The colour of this kind of fact (`FACT_TONES`, or the application's by `name`). */
|
|
37
|
+
tone?: FactTone;
|
|
20
38
|
};
|
|
21
|
-
|
|
39
|
+
/** The tones a fact may take — web-ui's `Tone`, named here because `core/` imports no UI. */
|
|
40
|
+
export type FactTone = "neutral" | "info" | "good" | "warn" | "bad" | "accent";
|
|
41
|
+
/**
|
|
42
|
+
* The colour of a kind of fact, by its `name` — whole (`quipu.pagos.v1.pago_aprobado`) or its
|
|
43
|
+
* last part (`pago_aprobado`), so a version bump keeps it. These are the framework's own facts
|
|
44
|
+
* of a record's life; an application names its own (`presented(entity, { facts })`), over these.
|
|
45
|
+
* An edit and a creation carry no tone: they are the ordinary life of a record.
|
|
46
|
+
*/
|
|
47
|
+
export declare const FACT_TONES: Readonly<Record<string, FactTone>>;
|
|
48
|
+
/** The tone of a fact by its name, among `tones`; none when nothing names it. */
|
|
49
|
+
export declare function toneOfFact(name: unknown, tones?: Readonly<Record<string, FactTone>>): FactTone | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The facts of a record as entries of web-ui's activity.
|
|
52
|
+
*
|
|
53
|
+
* historyOf(rows, eventsMeta, "es", { record: pagoMeta, tones: { pago_aprobado: "good" } })
|
|
54
|
+
* -> [{ label: "Se actualizó", detail: "Estado: En revisión → Validado", by: "ana", … }]
|
|
55
|
+
*
|
|
56
|
+
* `meta` is the history route's definition; `events` each event's own, by its wire name
|
|
57
|
+
* (`eventMetasOf(contract)`), which names a fact's own fields first; `record` is the record's,
|
|
58
|
+
* which writes each side of an edit. `tones` colour each kind of fact by its `name`, over the
|
|
59
|
+
* framework's own (`FACT_TONES`).
|
|
60
|
+
*/
|
|
61
|
+
export declare function historyOf(rows: readonly AnyRecord[], meta: Meta | null | undefined, locale?: string, options?: {
|
|
62
|
+
record?: Meta | null | undefined;
|
|
63
|
+
events?: Readonly<Record<string, Meta>> | undefined;
|
|
64
|
+
tones?: Readonly<Record<string, FactTone>> | undefined;
|
|
65
|
+
}): HistoryEntry[];
|