@sincpro/web-framework 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -28
- package/dist/core/copy.d.ts +8 -0
- package/dist/core/copy.js +8 -0
- package/dist/core/edit.d.ts +19 -0
- package/dist/core/edit.js +46 -0
- package/dist/core/history.d.ts +7 -0
- package/dist/core/history.js +5 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/list.d.ts +20 -2
- package/dist/core/list.js +24 -0
- package/dist/core/present.d.ts +22 -0
- package/dist/core/present.js +51 -19
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.js +5 -1
- package/dist/react/useCommand.d.ts +7 -1
- package/dist/react/useCommand.js +12 -2
- package/dist/react/useCount.d.ts +18 -0
- package/dist/react/useCount.js +23 -0
- package/dist/react/useRecord.d.ts +6 -6
- package/dist/react/useRecord.js +10 -7
- package/dist/react/useRecordLifecycle.d.ts +43 -0
- package/dist/react/useRecordLifecycle.js +49 -0
- package/dist/react/useService.d.ts +5 -1
- package/dist/react/useServiceReading.d.ts +35 -0
- package/dist/react/useServiceReading.js +75 -0
- package/dist/react/useTextOf.d.ts +16 -0
- package/dist/react/useTextOf.js +21 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +23 -6
- package/dist/web/list/EntitySearchBar.d.ts +4 -1
- package/dist/web/list/EntitySearchBar.js +2 -2
- package/dist/web/list/groups.d.ts +13 -3
- package/dist/web/list/groups.js +21 -8
- package/dist/web/list/openIn.d.ts +4 -2
- package/dist/web/list/openIn.js +9 -2
- 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/control.d.ts +9 -3
- package/dist/web/record/control.js +13 -4
- package/dist/web/record/edit.js +1 -1
- package/dist/web/record/lines.js +1 -1
- package/dist/web/record/opening.d.ts +2 -2
- package/dist/web/record/record.js +36 -3
- package/dist/web/workspace/composer.d.ts +5 -1
- package/dist/web/workspace/composer.js +30 -12
- package/dist/web/workspace/open.d.ts +1 -1
- package/dist/web/workspace/open.js +7 -1
- package/dist/web/workspace/record.d.ts +6 -2
- package/dist/web/workspace/record.js +16 -7
- package/dist/web/workspace/workspace.d.ts +7 -1
- package/dist/web/workspace/workspace.js +13 -4
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -442,34 +442,39 @@ const tickets = defineMeta({
|
|
|
442
442
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
443
443
|
hook and draw your own, or go straight to the loose piece.
|
|
444
444
|
|
|
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
|
-
|
|
|
450
|
-
| What
|
|
451
|
-
| What
|
|
452
|
-
| What is
|
|
453
|
-
|
|
|
454
|
-
|
|
|
455
|
-
|
|
|
456
|
-
|
|
|
457
|
-
|
|
|
458
|
-
|
|
|
459
|
-
|
|
|
460
|
-
|
|
|
461
|
-
|
|
|
462
|
-
|
|
|
463
|
-
|
|
|
464
|
-
|
|
|
465
|
-
|
|
|
466
|
-
|
|
|
467
|
-
|
|
|
468
|
-
|
|
|
469
|
-
|
|
|
470
|
-
|
|
|
471
|
-
|
|
|
472
|
-
|
|
|
445
|
+
| Question | Declarative | Hook | Loose piece |
|
|
446
|
+
| -------------------------------- | --------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------- |
|
|
447
|
+
| Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
|
|
448
|
+
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
|
|
449
|
+
| Read through a use case | its `Feature`s (client-framework) | `useServiceReading` | `project.Accounts.balance(…)` |
|
|
450
|
+
| What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
|
|
451
|
+
| What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
|
|
452
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
453
|
+
| A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
|
|
454
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
455
|
+
| How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
|
|
456
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
457
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
458
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
|
|
459
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
460
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
461
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
462
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
463
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
464
|
+
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)` | `useCount` | `entity.listRef` (client-framework) |
|
|
465
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
466
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
467
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
468
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
469
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
|
|
470
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
471
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
472
|
+
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
473
|
+
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
474
|
+
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
475
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
476
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
477
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
473
478
|
|
|
474
479
|
The rules behind them, in short:
|
|
475
480
|
|
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. */
|
|
@@ -57,6 +59,12 @@ export type FrameworkCopy = {
|
|
|
57
59
|
create: string;
|
|
58
60
|
/** A record's one2many: the button that opens the form of a new related record. */
|
|
59
61
|
add: string;
|
|
62
|
+
/** The record's own `Delete` (its dry run is shown before it runs). */
|
|
63
|
+
delete: string;
|
|
64
|
+
/** Into the entity's trash (`Archive`): out of every reading, nothing lost. */
|
|
65
|
+
archive: string;
|
|
66
|
+
/** Out of the trash (`Restore`): read again. */
|
|
67
|
+
restore: string;
|
|
60
68
|
};
|
|
61
69
|
picker: {
|
|
62
70
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
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 ? "" : "+"}`,
|
|
@@ -30,6 +31,9 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
30
31
|
creating: (name) => (name ? `${name} · new` : "New"),
|
|
31
32
|
create: "New",
|
|
32
33
|
add: "Add",
|
|
34
|
+
delete: "Delete",
|
|
35
|
+
archive: "Move to the trash",
|
|
36
|
+
restore: "Restore",
|
|
33
37
|
},
|
|
34
38
|
picker: {
|
|
35
39
|
browse: "Search all",
|
|
@@ -75,6 +79,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
75
79
|
items: (count, exact) => `${count}${exact ? "" : "+"} ${count === 1 ? "elemento" : "elementos"}`,
|
|
76
80
|
},
|
|
77
81
|
list: {
|
|
82
|
+
trash: "Papelera",
|
|
78
83
|
loadMore: "Cargar más",
|
|
79
84
|
loading: "Cargando…",
|
|
80
85
|
shown: (shown, total, exact) => `${shown} de ${total}${exact ? "" : "+"}`,
|
|
@@ -100,6 +105,9 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
100
105
|
creating: (name) => (name ? `${name} · nuevo` : "Nuevo"),
|
|
101
106
|
create: "Nuevo",
|
|
102
107
|
add: "Agregar",
|
|
108
|
+
delete: "Eliminar",
|
|
109
|
+
archive: "Mover a la papelera",
|
|
110
|
+
restore: "Restaurar",
|
|
103
111
|
},
|
|
104
112
|
picker: {
|
|
105
113
|
browse: "Buscar en todos",
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -104,3 +104,22 @@ export declare function defaultsOf(meta: Meta | null | undefined): AnyRecord;
|
|
|
104
104
|
* the stored record. Both travel.
|
|
105
105
|
*/
|
|
106
106
|
export declare function creationOf(meta: Meta | null | undefined, values: AnyRecord): AnyRecord;
|
|
107
|
+
/**
|
|
108
|
+
* What an edit of a STORED record sends (sincpro_framework's `Edit`): the fields the person
|
|
109
|
+
* changed, and inside them nothing the model marks `readonly` — a line keeps only its identity,
|
|
110
|
+
* the way the form names the line it edits.
|
|
111
|
+
*
|
|
112
|
+
* editedOf(invoiceMeta, record, ["discount", "lines"])
|
|
113
|
+
* -> { discount: "5", lines: [{ id: "l1", qty: 2 }, { qty: 1 }] }
|
|
114
|
+
*
|
|
115
|
+
* Context: the form used to send the record whole, as it holds it — `id`, `version`,
|
|
116
|
+
* `created_at` and each line's own among them. sincpro_framework up to 3.36 refused a field the
|
|
117
|
+
* framework writes at every level (`apply_values`); 3.37 leaves that echo out, but still
|
|
118
|
+
* refuses a relation read as a page (`{items, count, cursor}`) written back, since it would
|
|
119
|
+
* remove every record the page did not bring. So a stored record could be created and never
|
|
120
|
+
* edited. The backend keeps what it stored and the caller's draft, and puts this edit on top of
|
|
121
|
+
* both: what changed is all it needs, on either version. The model marks the fields the
|
|
122
|
+
* framework writes `readonly` (and the computed ones), so nothing here names them. A new record
|
|
123
|
+
* goes through `creationOf`.
|
|
124
|
+
*/
|
|
125
|
+
export declare function editedOf(meta: Meta | null | undefined, values: AnyRecord, changed: readonly string[]): AnyRecord;
|
package/dist/core/edit.js
CHANGED
|
@@ -180,3 +180,49 @@ export function creationOf(meta, values) {
|
|
|
180
180
|
}
|
|
181
181
|
return sent;
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* What an edit of a STORED record sends (sincpro_framework's `Edit`): the fields the person
|
|
185
|
+
* changed, and inside them nothing the model marks `readonly` — a line keeps only its identity,
|
|
186
|
+
* the way the form names the line it edits.
|
|
187
|
+
*
|
|
188
|
+
* editedOf(invoiceMeta, record, ["discount", "lines"])
|
|
189
|
+
* -> { discount: "5", lines: [{ id: "l1", qty: 2 }, { qty: 1 }] }
|
|
190
|
+
*
|
|
191
|
+
* Context: the form used to send the record whole, as it holds it — `id`, `version`,
|
|
192
|
+
* `created_at` and each line's own among them. sincpro_framework up to 3.36 refused a field the
|
|
193
|
+
* framework writes at every level (`apply_values`); 3.37 leaves that echo out, but still
|
|
194
|
+
* refuses a relation read as a page (`{items, count, cursor}`) written back, since it would
|
|
195
|
+
* remove every record the page did not bring. So a stored record could be created and never
|
|
196
|
+
* edited. The backend keeps what it stored and the caller's draft, and puts this edit on top of
|
|
197
|
+
* both: what changed is all it needs, on either version. The model marks the fields the
|
|
198
|
+
* framework writes `readonly` (and the computed ones), so nothing here names them. A new record
|
|
199
|
+
* goes through `creationOf`.
|
|
200
|
+
*/
|
|
201
|
+
export function editedOf(meta, values, changed) {
|
|
202
|
+
const sent = {};
|
|
203
|
+
for (const name of changed) {
|
|
204
|
+
const field = meta?.fields[name];
|
|
205
|
+
if (field?.readonly === true)
|
|
206
|
+
continue;
|
|
207
|
+
sent[name] = writableOf(field?.definition, values[name]);
|
|
208
|
+
}
|
|
209
|
+
return sent;
|
|
210
|
+
}
|
|
211
|
+
/** A value of a list of records (the lines) or of one record held inside (a value object),
|
|
212
|
+
* without what the model of those records marks `readonly` — the identity kept. Anything else
|
|
213
|
+
* as it is. */
|
|
214
|
+
function writableOf(definition, value) {
|
|
215
|
+
if (definition == null || value === null || typeof value !== "object")
|
|
216
|
+
return value;
|
|
217
|
+
if (Array.isArray(value))
|
|
218
|
+
return value.map((one) => writableOf(definition, one));
|
|
219
|
+
const identity = definition.identity || "id";
|
|
220
|
+
const kept = {};
|
|
221
|
+
for (const [name, one] of Object.entries(value)) {
|
|
222
|
+
const field = definition.fields[name];
|
|
223
|
+
if (name !== identity && field?.readonly === true)
|
|
224
|
+
continue;
|
|
225
|
+
kept[name] = writableOf(field?.definition, one);
|
|
226
|
+
}
|
|
227
|
+
return kept;
|
|
228
|
+
}
|
package/dist/core/history.d.ts
CHANGED
|
@@ -11,11 +11,18 @@ 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) and who the record was then (`entity_display`), and
|
|
17
|
+
* the contract labels a subclass's own fields (`reason` → «Motivo»). Who did it is the entry's
|
|
18
|
+
* `by` — web-ui's activity draws it —; the rest of the envelope never repeats in its detail.
|
|
14
19
|
*/
|
|
15
20
|
export type HistoryEntry = {
|
|
16
21
|
id: string;
|
|
17
22
|
label: string;
|
|
18
23
|
at: string;
|
|
24
|
+
/** Who did it, as the fact says (`actor`); absent: the system, or a backend before 3.37. */
|
|
25
|
+
by?: string;
|
|
19
26
|
detail?: string;
|
|
20
27
|
};
|
|
21
28
|
export declare function historyOf(rows: readonly AnyRecord[], meta: Meta | null | undefined, locale?: string): HistoryEntry[];
|
package/dist/core/history.js
CHANGED
|
@@ -3,13 +3,16 @@ import { frameworkCopy } from "./copy.js";
|
|
|
3
3
|
/** What every fact carries: what remains is what this fact says. */
|
|
4
4
|
const ENVELOPE = new Set([
|
|
5
5
|
"id",
|
|
6
|
+
"name",
|
|
6
7
|
"created_at",
|
|
7
8
|
"updated_at",
|
|
8
9
|
"version",
|
|
9
10
|
"label",
|
|
10
11
|
"entity_type",
|
|
11
12
|
"entity_id",
|
|
13
|
+
"entity_display",
|
|
12
14
|
"entity_version",
|
|
15
|
+
"actor",
|
|
13
16
|
"correlation_id",
|
|
14
17
|
"causation_id",
|
|
15
18
|
]);
|
|
@@ -34,10 +37,12 @@ export function historyOf(rows, meta, locale) {
|
|
|
34
37
|
.map(([key, value]) => [key, said(value)])
|
|
35
38
|
.filter(([, value]) => value !== null && value !== row["entity_id"])
|
|
36
39
|
.map(([key, value]) => `${labelOf(meta, key, locale)}: ${value}`);
|
|
40
|
+
const actor = said(row["actor"]);
|
|
37
41
|
return {
|
|
38
42
|
id: String(row["id"]),
|
|
39
43
|
label: word,
|
|
40
44
|
at: String(row["created_at"] ?? ""),
|
|
45
|
+
...(actor === null ? {} : { by: actor }),
|
|
41
46
|
...(parts.length === 0 ? {} : { detail: parts.join(" · ") }),
|
|
42
47
|
};
|
|
43
48
|
});
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
|
|
11
11
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
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";
|
|
12
|
+
export { type Advice, adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, type ServerFieldState, } from "./edit.js";
|
|
13
13
|
export { explain } from "./explain.js";
|
|
14
14
|
export { type FormLayout, formOf } from "./form.js";
|
|
15
15
|
export { type HistoryEntry, historyOf } from "./history.js";
|
|
16
16
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, isReference, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
17
|
-
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, } from "./list.js";
|
|
17
|
+
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, trashOf, } from "./list.js";
|
|
18
18
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
19
19
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
|
-
export { BOOKKEEPING, defaultFields, type FieldView, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
20
|
+
export { BOOKKEEPING, dayTextOf, defaultFields, type FieldView, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
21
21
|
export { type Related, relatedOf } from "./related.js";
|
|
22
22
|
export { backReference, entityFor, relatedScope, type RelationField, relationFieldOf, } from "./relation.js";
|
|
23
23
|
export { type RecordSummary, summaryFieldsOf, summaryOf, } from "./summary.js";
|
package/dist/core/index.js
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { cachedTransport, } from "./cache.js";
|
|
11
11
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
12
|
-
export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
|
|
12
|
+
export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
|
|
13
13
|
export { explain } from "./explain.js";
|
|
14
14
|
export { formOf } from "./form.js";
|
|
15
15
|
export { historyOf } from "./history.js";
|
|
16
16
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
17
|
-
export { defineList, isList, scopeOf, } from "./list.js";
|
|
17
|
+
export { defineList, isList, scopeOf, trashOf, } from "./list.js";
|
|
18
18
|
export { lookupOf } from "./lookup.js";
|
|
19
19
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
|
-
export { BOOKKEEPING, defaultFields, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
20
|
+
export { BOOKKEEPING, dayTextOf, defaultFields, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
21
21
|
export { relatedOf } from "./related.js";
|
|
22
22
|
export { backReference, entityFor, relatedScope, relationFieldOf, } from "./relation.js";
|
|
23
23
|
export { summaryFieldsOf, summaryOf, } from "./summary.js";
|
package/dist/core/list.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Entity, type
|
|
1
|
+
import { type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord, Criteria, Expression, Grain, Sort } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* A named way of looking at an entity: «Por cobrar», «Borradores», «Mis tickets».
|
|
@@ -29,7 +29,7 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
29
29
|
/** `domain:kind-id` — how the workspace and the definitions store refer to it. */
|
|
30
30
|
key: string;
|
|
31
31
|
/** Where the workspace opens it: a kind of its own, so ⌘K can offer it by name. */
|
|
32
|
-
ref: () =>
|
|
32
|
+
ref: () => ResourceRef;
|
|
33
33
|
title: string;
|
|
34
34
|
description?: string;
|
|
35
35
|
/** The fixed cut, ANDed under everything a person searches or filters. */
|
|
@@ -44,6 +44,10 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
44
44
|
views?: readonly ("table" | "rows" | "board" | "sheet" | "pivot")[];
|
|
45
45
|
/** Grouped from the start — the server counts the groups. */
|
|
46
46
|
groupBy?: readonly GroupLevel[];
|
|
47
|
+
/** The fields «Group by» offers, in this order — among those the model lets split the set. */
|
|
48
|
+
groupable?: readonly string[];
|
|
49
|
+
/** The entity's trash (`trashOf`): each row offers «Restore» when the entity declares it. */
|
|
50
|
+
trash?: boolean;
|
|
47
51
|
};
|
|
48
52
|
/** A cut offered by name in the search bar: «sólo pagadas», «vencidas». */
|
|
49
53
|
export type NamedFilter<T> = {
|
|
@@ -63,3 +67,17 @@ export declare function defineList<T extends AnyRecord>(entity: Entity<T>, spec:
|
|
|
63
67
|
export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>): given is ListDefinition<T>;
|
|
64
68
|
/** The criteria a definition always asks: its scope, in its order. */
|
|
65
69
|
export declare function scopeOf<T extends AnyRecord>(list: ListDefinition<T>): Criteria<T>;
|
|
70
|
+
/**
|
|
71
|
+
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
72
|
+
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
73
|
+
*
|
|
74
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
75
|
+
*
|
|
76
|
+
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
77
|
+
* that names `archived_at` — the list route itself, under `archived_at` not null. So this is the
|
|
78
|
+
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
79
|
+
* comes back.
|
|
80
|
+
*/
|
|
81
|
+
export declare function trashOf<T extends AnyRecord>(entity: Entity<T>, options?: {
|
|
82
|
+
title?: string;
|
|
83
|
+
}): ListDefinition<T>;
|
package/dist/core/list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {} from "@sincpro/client-framework";
|
|
2
|
+
import { frameworkCopy } from "./copy.js";
|
|
2
3
|
export function defineList(entity, spec) {
|
|
3
4
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
|
|
4
5
|
throw new Error(`list id "${spec.id}" is not kebab-case: it becomes a workspace kind`);
|
|
@@ -21,3 +22,26 @@ export function scopeOf(list) {
|
|
|
21
22
|
...(list.order === undefined ? {} : { order: [list.order] }),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
27
|
+
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
28
|
+
*
|
|
29
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
30
|
+
*
|
|
31
|
+
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
32
|
+
* that names `archived_at` — the list route itself, under `archived_at` not null. So this is the
|
|
33
|
+
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
34
|
+
* comes back.
|
|
35
|
+
*/
|
|
36
|
+
export function trashOf(entity, options = {}) {
|
|
37
|
+
return {
|
|
38
|
+
...defineList(entity, {
|
|
39
|
+
id: "trash",
|
|
40
|
+
title: options.title ?? frameworkCopy().list.trash,
|
|
41
|
+
scope: {
|
|
42
|
+
selection: { field: "archived_at", operator: "is null", value: false },
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
trash: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
package/dist/core/present.d.ts
CHANGED
|
@@ -30,6 +30,28 @@ export declare function viewOf(meta: Meta | null | undefined, name: string, loca
|
|
|
30
30
|
export declare function defaultFields(meta: Meta | null | undefined): string[];
|
|
31
31
|
/** The bookkeeping every framework entity carries; shown on demand, never by default. */
|
|
32
32
|
export declare const BOOKKEEPING: ReadonlySet<string>;
|
|
33
|
+
/**
|
|
34
|
+
* What a value reads as when a screen holds it outside any model — a total it added up, a
|
|
35
|
+
* due date of its own: the same text `textOf` gives a field of that type, in `locale`, on the
|
|
36
|
+
* zone the application installed. `null` when there is nothing to read. `useTextOf()` binds them
|
|
37
|
+
* to the provider's locale.
|
|
38
|
+
*
|
|
39
|
+
* numberTextOf("1150.5", "es-BO") -> "1.150,5"
|
|
40
|
+
* dayTextOf("2026-03-12", "es") -> "12 mar 2026"
|
|
41
|
+
* instantTextOf("2026-03-12T14:00:00Z", "es") -> "12 mar 2026, 10:00" (La Paz)
|
|
42
|
+
* moneyTextOf({ amount: "1150.5", currency: "BOB" }, "es-BO") -> "Bs 1.150,50"
|
|
43
|
+
*
|
|
44
|
+
* Context: every application wrote its own money and date formatting for its own screens, on
|
|
45
|
+
* the browser's zone and its own locale, while the framework had the right one private.
|
|
46
|
+
*/
|
|
47
|
+
export declare function numberTextOf(value: unknown, locale?: string): string | null;
|
|
48
|
+
/** A day (`"2026-03-12"`) as a person reads it. A day has no zone: it is never converted. */
|
|
49
|
+
export declare function dayTextOf(value: unknown, locale?: string): string | null;
|
|
50
|
+
/** An instant as a person reads it, on the wall clock of the zone the application installed. */
|
|
51
|
+
export declare function instantTextOf(value: unknown, locale?: string): string | null;
|
|
52
|
+
/** A money (`{ amount, currency }`) as a person reads it, rounded to its currency's decimals;
|
|
53
|
+
* `null` when the value is not one. */
|
|
54
|
+
export declare function moneyTextOf(value: unknown, locale?: string): string | null;
|
|
33
55
|
/**
|
|
34
56
|
* The text a value reads as. `null` when there is nothing to read — the caller draws its own
|
|
35
57
|
* «empty» (a dash in a fact, nothing in a cell).
|
package/dist/core/present.js
CHANGED
|
@@ -137,6 +137,51 @@ function displayOf(field, value) {
|
|
|
137
137
|
const shown = value[key] ?? value["display_name"] ?? value["name"] ?? value["id"];
|
|
138
138
|
return shown === undefined || shown === null ? "" : String(shown);
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* What a value reads as when a screen holds it outside any model — a total it added up, a
|
|
142
|
+
* due date of its own: the same text `textOf` gives a field of that type, in `locale`, on the
|
|
143
|
+
* zone the application installed. `null` when there is nothing to read. `useTextOf()` binds them
|
|
144
|
+
* to the provider's locale.
|
|
145
|
+
*
|
|
146
|
+
* numberTextOf("1150.5", "es-BO") -> "1.150,5"
|
|
147
|
+
* dayTextOf("2026-03-12", "es") -> "12 mar 2026"
|
|
148
|
+
* instantTextOf("2026-03-12T14:00:00Z", "es") -> "12 mar 2026, 10:00" (La Paz)
|
|
149
|
+
* moneyTextOf({ amount: "1150.5", currency: "BOB" }, "es-BO") -> "Bs 1.150,50"
|
|
150
|
+
*
|
|
151
|
+
* Context: every application wrote its own money and date formatting for its own screens, on
|
|
152
|
+
* the browser's zone and its own locale, while the framework had the right one private.
|
|
153
|
+
*/
|
|
154
|
+
export function numberTextOf(value, locale) {
|
|
155
|
+
if (value === null || value === undefined || value === "")
|
|
156
|
+
return null;
|
|
157
|
+
if (Number.isNaN(Number(value)))
|
|
158
|
+
return String(value);
|
|
159
|
+
// A decimal that travels as text goes to `Intl` as text: every digit kept, none through a
|
|
160
|
+
// float (`"12345678901234567.89"` reads whole).
|
|
161
|
+
if (typeof value === "string")
|
|
162
|
+
return numberFormat(locale, decimals(value)).format(value.trim());
|
|
163
|
+
return numberFormat(locale, undefined).format(Number(value));
|
|
164
|
+
}
|
|
165
|
+
/** A day (`"2026-03-12"`) as a person reads it. A day has no zone: it is never converted. */
|
|
166
|
+
export function dayTextOf(value, locale) {
|
|
167
|
+
if (value === null || value === undefined || value === "")
|
|
168
|
+
return null;
|
|
169
|
+
return typeof value === "string"
|
|
170
|
+
? dateFormat(locale, false).format(localDate(value))
|
|
171
|
+
: String(value);
|
|
172
|
+
}
|
|
173
|
+
/** An instant as a person reads it, on the wall clock of the zone the application installed. */
|
|
174
|
+
export function instantTextOf(value, locale) {
|
|
175
|
+
if (value === null || value === undefined || value === "")
|
|
176
|
+
return null;
|
|
177
|
+
const date = new Date(String(value));
|
|
178
|
+
return Number.isNaN(date.getTime()) ? String(value) : dateFormat(locale, true).format(date);
|
|
179
|
+
}
|
|
180
|
+
/** A money (`{ amount, currency }`) as a person reads it, rounded to its currency's decimals;
|
|
181
|
+
* `null` when the value is not one. */
|
|
182
|
+
export function moneyTextOf(value, locale) {
|
|
183
|
+
return Money.isMoney(value) ? moneyText(value, locale) : null;
|
|
184
|
+
}
|
|
140
185
|
/**
|
|
141
186
|
* The text a value reads as. `null` when there is nothing to read — the caller draws its own
|
|
142
187
|
* «empty» (a dash in a fact, nothing in a cell).
|
|
@@ -159,25 +204,12 @@ export function textOf(meta, name, value, locale) {
|
|
|
159
204
|
case "boolean":
|
|
160
205
|
return value ? copy.value.yes : copy.value.no;
|
|
161
206
|
case "date":
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
case "datetime": {
|
|
166
|
-
const date = new Date(String(value));
|
|
167
|
-
return Number.isNaN(date.getTime())
|
|
168
|
-
? String(value)
|
|
169
|
-
: dateFormat(locale, true).format(date);
|
|
170
|
-
}
|
|
207
|
+
return dayTextOf(value, locale);
|
|
208
|
+
case "datetime":
|
|
209
|
+
return instantTextOf(value, locale);
|
|
171
210
|
case "integer":
|
|
172
|
-
case "number":
|
|
173
|
-
|
|
174
|
-
return String(value);
|
|
175
|
-
// A decimal that travels as text goes to `Intl` as text: every digit kept, none through a
|
|
176
|
-
// float (`"12345678901234567.89"` reads whole).
|
|
177
|
-
if (typeof value === "string")
|
|
178
|
-
return numberFormat(locale, decimals(value)).format(value.trim());
|
|
179
|
-
return numberFormat(locale, undefined).format(Number(value));
|
|
180
|
-
}
|
|
211
|
+
case "number":
|
|
212
|
+
return numberTextOf(value, locale);
|
|
181
213
|
case "text[]":
|
|
182
214
|
return Array.isArray(value)
|
|
183
215
|
? value.length === 0
|
|
@@ -193,7 +225,7 @@ export function textOf(meta, name, value, locale) {
|
|
|
193
225
|
return typeof value === "object" ? displayOf(field, value) : String(value);
|
|
194
226
|
case "embedded":
|
|
195
227
|
// A value object has no text of its own — but a money, the one every ERP holds, does.
|
|
196
|
-
return
|
|
228
|
+
return moneyTextOf(value, locale);
|
|
197
229
|
default:
|
|
198
230
|
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
199
231
|
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
-
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, } from "./useCommand.js";
|
|
8
|
+
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
9
|
export { useContextValues } from "./useContextValues.js";
|
|
10
|
+
export { useCount } from "./useCount.js";
|
|
10
11
|
export { type Groups, useGroups } from "./useGroups.js";
|
|
11
12
|
export { useHistory } from "./useHistory.js";
|
|
12
13
|
export { type Listing, type ListingOptions, type Paging, useListing, } from "./useListing.js";
|
|
@@ -14,7 +15,10 @@ export { excluding, type Lookup, useLookup } from "./useLookup.js";
|
|
|
14
15
|
export { useNameOf } from "./useNameOf.js";
|
|
15
16
|
export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
16
17
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
18
|
+
export { type LifecycleAction, type RecordLifecycleActions, useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
17
19
|
export { useRelated } from "./useRelated.js";
|
|
18
20
|
export { type ServiceState, useService } from "./useService.js";
|
|
21
|
+
export { type ServiceReading, useServiceReading, } from "./useServiceReading.js";
|
|
19
22
|
export { useSummaryOf } from "./useSummary.js";
|
|
23
|
+
export { useTextOf, type ValueTexts } from "./useTextOf.js";
|
|
20
24
|
export { useWrites } from "./useWrites.js";
|
package/dist/react/index.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
-
export { useCommand, } from "./useCommand.js";
|
|
8
|
+
export { useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
9
|
export { useContextValues } from "./useContextValues.js";
|
|
10
|
+
export { useCount } from "./useCount.js";
|
|
10
11
|
export { useGroups } from "./useGroups.js";
|
|
11
12
|
export { useHistory } from "./useHistory.js";
|
|
12
13
|
export { useListing, } from "./useListing.js";
|
|
@@ -14,7 +15,10 @@ export { excluding, useLookup } from "./useLookup.js";
|
|
|
14
15
|
export { useNameOf } from "./useNameOf.js";
|
|
15
16
|
export { usePivot, } from "./usePivot.js";
|
|
16
17
|
export { useRecord, } from "./useRecord.js";
|
|
18
|
+
export { useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
17
19
|
export { useRelated } from "./useRelated.js";
|
|
18
20
|
export { useService } from "./useService.js";
|
|
21
|
+
export { useServiceReading, } from "./useServiceReading.js";
|
|
19
22
|
export { useSummaryOf } from "./useSummary.js";
|
|
23
|
+
export { useTextOf } from "./useTextOf.js";
|
|
20
24
|
export { useWrites } from "./useWrites.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
1
|
+
import { type CommandAnswers, type CommandBodies, type Entity, type WriteRoute } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* One Command of an entity: run it, or ask first what it would do.
|
|
@@ -38,3 +38,9 @@ export type CommandState<R, B extends AnyRecord = AnyRecord> = {
|
|
|
38
38
|
*/
|
|
39
39
|
export type AnswerOf<R, A, N> = unknown extends R ? (N extends keyof A ? A[N] : unknown) : R;
|
|
40
40
|
export declare function useCommand<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, name: N): CommandState<AnswerOf<R, A, N>, C[N]>;
|
|
41
|
+
/**
|
|
42
|
+
* One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
|
|
43
|
+
* and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
|
|
44
|
+
* declares none): the hook is still called, and running it is refused naming the entity.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useRouteCommand<R, B extends AnyRecord = AnyRecord>(route: WriteRoute | undefined, owner: string): CommandState<R, B>;
|
package/dist/react/useCommand.js
CHANGED
|
@@ -3,11 +3,19 @@ import { bodyFor, pathFor, retryKeys, } from "@sincpro/client-framework";
|
|
|
3
3
|
import { useFramework } from "./context.js";
|
|
4
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
5
|
export function useCommand(entity, name) {
|
|
6
|
-
const { transport } = useFramework();
|
|
7
6
|
// A name outside the declared ones still reaches here from untyped code: say which.
|
|
8
7
|
const route = entity.commands[name];
|
|
9
8
|
if (route === undefined)
|
|
10
9
|
throw new Error(`${entity.key} declares no command "${name}"`);
|
|
10
|
+
return useRouteCommand(route, entity.key);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
|
|
14
|
+
* and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
|
|
15
|
+
* declares none): the hook is still called, and running it is refused naming the entity.
|
|
16
|
+
*/
|
|
17
|
+
export function useRouteCommand(route, owner) {
|
|
18
|
+
const { transport } = useFramework();
|
|
11
19
|
const [busy, setBusy] = useState(false);
|
|
12
20
|
const [error, setError] = useState(null);
|
|
13
21
|
const [rehearsal, setRehearsal] = useState(null);
|
|
@@ -22,6 +30,8 @@ export function useCommand(entity, name) {
|
|
|
22
30
|
// not run it twice. A dry run touches nothing, so each one gets a key of its own.
|
|
23
31
|
const keys = useRef(retryKeys());
|
|
24
32
|
const send = useCallback(async (id, body, gesture) => {
|
|
33
|
+
if (route === undefined)
|
|
34
|
+
throw new Error(`${owner} declares no route for this`);
|
|
25
35
|
setBusy(true);
|
|
26
36
|
setError(null);
|
|
27
37
|
const idempotencyKey = gesture.keyFor({ id, body });
|
|
@@ -42,7 +52,7 @@ export function useCommand(entity, name) {
|
|
|
42
52
|
if (mounted.current)
|
|
43
53
|
setBusy(false);
|
|
44
54
|
}
|
|
45
|
-
}, [transport, route]);
|
|
55
|
+
}, [transport, route, owner]);
|
|
46
56
|
return {
|
|
47
57
|
run: (id, body) => send(id, body ?? {}, keys.current),
|
|
48
58
|
rehearse: async (id, body) => {
|