@sincpro/web-framework 2.5.0 → 2.6.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 +31 -28
- package/dist/core/edit.d.ts +19 -0
- package/dist/core/edit.js +46 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/list.d.ts +20 -0
- package/dist/core/list.js +32 -1
- package/dist/core/present.d.ts +22 -0
- package/dist/core/present.js +51 -19
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +3 -0
- package/dist/react/useCount.d.ts +18 -0
- package/dist/react/useCount.js +23 -0
- package/dist/react/useRecord.d.ts +4 -4
- package/dist/react/useRecord.js +10 -7
- 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/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +6 -3
- 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/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/record.js +36 -3
- package/dist/web/workspace/composer.d.ts +6 -2
- package/dist/web/workspace/composer.js +31 -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 +6 -5
- package/dist/web/workspace/workspace.d.ts +7 -1
- package/dist/web/workspace/workspace.js +13 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -442,34 +442,37 @@ 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 | 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
|
-
|
|
|
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 `scopedRef(entity, cut)` | `useCount` | `scopedRef` |
|
|
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
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
474
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
475
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
473
476
|
|
|
474
477
|
The rules behind them, in short:
|
|
475
478
|
|
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/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, SCOPE_NAME_PARAM, scopedRef, scopeNameOf, scopeOf, } 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, SCOPE_NAME_PARAM, scopedRef, scopeNameOf, scopeOf, } 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
|
@@ -44,6 +44,8 @@ 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[];
|
|
47
49
|
};
|
|
48
50
|
/** A cut offered by name in the search bar: «sólo pagadas», «vencidas». */
|
|
49
51
|
export type NamedFilter<T> = {
|
|
@@ -63,3 +65,21 @@ export declare function defineList<T extends AnyRecord>(entity: Entity<T>, spec:
|
|
|
63
65
|
export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>): given is ListDefinition<T>;
|
|
64
66
|
/** The criteria a definition always asks: its scope, in its order. */
|
|
65
67
|
export declare function scopeOf<T extends AnyRecord>(list: ListDefinition<T>): Criteria<T>;
|
|
68
|
+
/** What a list opened under a cut is named by — «María» of «Pagos · María». */
|
|
69
|
+
export declare const SCOPE_NAME_PARAM = "of";
|
|
70
|
+
/**
|
|
71
|
+
* An entity's list as a workspace reference, opened under a cut: «this member's payments»,
|
|
72
|
+
* what a smart button opens. With `name`, the list says whose it is: «Pagos · María» in its
|
|
73
|
+
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
74
|
+
*
|
|
75
|
+
* api.open(scopedRef(payments, { field: "member_id", value: member.id }, member.name))
|
|
76
|
+
*
|
|
77
|
+
* Context: the cut travels in the reference — client-framework's `SCOPE_PARAM`, the param a
|
|
78
|
+
* chooser carries its cut in (`chooserRef(query, scope)`) — so it survives a reload and a link,
|
|
79
|
+
* and the list opened from it, the application's own too, reads under it ANDed with everything
|
|
80
|
+
* a person searches (`entityView` gives it to `useListing`). An application built this reference
|
|
81
|
+
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
82
|
+
*/
|
|
83
|
+
export declare function scopedRef<T extends AnyRecord>(entity: Entity<T>, selection: Expression<T>, name?: string): EntityRef;
|
|
84
|
+
/** The name a reference's cut carries (`scopedRef(…, name)`), or nothing. */
|
|
85
|
+
export declare function scopeNameOf(ref: Pick<EntityRef, "params">): string | undefined;
|
package/dist/core/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {} from "@sincpro/client-framework";
|
|
1
|
+
import { SCOPE_PARAM } from "@sincpro/client-framework";
|
|
2
2
|
export function defineList(entity, spec) {
|
|
3
3
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
|
|
4
4
|
throw new Error(`list id "${spec.id}" is not kebab-case: it becomes a workspace kind`);
|
|
@@ -21,3 +21,34 @@ export function scopeOf(list) {
|
|
|
21
21
|
...(list.order === undefined ? {} : { order: [list.order] }),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/** What a list opened under a cut is named by — «María» of «Pagos · María». */
|
|
25
|
+
export const SCOPE_NAME_PARAM = "of";
|
|
26
|
+
/**
|
|
27
|
+
* An entity's list as a workspace reference, opened under a cut: «this member's payments»,
|
|
28
|
+
* what a smart button opens. With `name`, the list says whose it is: «Pagos · María» in its
|
|
29
|
+
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
30
|
+
*
|
|
31
|
+
* api.open(scopedRef(payments, { field: "member_id", value: member.id }, member.name))
|
|
32
|
+
*
|
|
33
|
+
* Context: the cut travels in the reference — client-framework's `SCOPE_PARAM`, the param a
|
|
34
|
+
* chooser carries its cut in (`chooserRef(query, scope)`) — so it survives a reload and a link,
|
|
35
|
+
* and the list opened from it, the application's own too, reads under it ANDed with everything
|
|
36
|
+
* a person searches (`entityView` gives it to `useListing`). An application built this reference
|
|
37
|
+
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
38
|
+
*/
|
|
39
|
+
export function scopedRef(entity, selection, name) {
|
|
40
|
+
const list = entity.ref();
|
|
41
|
+
return {
|
|
42
|
+
...list,
|
|
43
|
+
params: {
|
|
44
|
+
...list.params,
|
|
45
|
+
[SCOPE_PARAM]: JSON.stringify(selection),
|
|
46
|
+
...(name === undefined || name === "" ? {} : { [SCOPE_NAME_PARAM]: name }),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The name a reference's cut carries (`scopedRef(…, name)`), or nothing. */
|
|
51
|
+
export function scopeNameOf(ref) {
|
|
52
|
+
const name = ref.params?.[SCOPE_NAME_PARAM];
|
|
53
|
+
return name === undefined || name === "" ? undefined : name;
|
|
54
|
+
}
|
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
|
@@ -7,6 +7,7 @@ export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
8
|
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, } 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";
|
|
@@ -16,5 +17,7 @@ export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
|
16
17
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
17
18
|
export { useRelated } from "./useRelated.js";
|
|
18
19
|
export { type ServiceState, useService } from "./useService.js";
|
|
20
|
+
export { type ServiceReading, useServiceReading, } from "./useServiceReading.js";
|
|
19
21
|
export { useSummaryOf } from "./useSummary.js";
|
|
22
|
+
export { useTextOf, type ValueTexts } from "./useTextOf.js";
|
|
20
23
|
export { useWrites } from "./useWrites.js";
|
package/dist/react/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
8
|
export { useCommand, } 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";
|
|
@@ -16,5 +17,7 @@ export { usePivot, } from "./usePivot.js";
|
|
|
16
17
|
export { useRecord, } from "./useRecord.js";
|
|
17
18
|
export { useRelated } from "./useRelated.js";
|
|
18
19
|
export { useService } from "./useService.js";
|
|
20
|
+
export { useServiceReading, } from "./useServiceReading.js";
|
|
19
21
|
export { useSummaryOf } from "./useSummary.js";
|
|
22
|
+
export { useTextOf } from "./useTextOf.js";
|
|
20
23
|
export { useWrites } from "./useWrites.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommandBodies, Entity } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord, Count, Criteria } from "@sincpro/criteria";
|
|
3
|
+
import type { ListDefinition } from "../core/list.js";
|
|
4
|
+
/**
|
|
5
|
+
* How many records of an entity a criteria holds, counted by the SERVER: «this member's
|
|
6
|
+
* payments (2)», the number of a smart button. `null` until it answers — and while it fails —,
|
|
7
|
+
* which web-ui's `SmartButton` reads as «—», never as 0.
|
|
8
|
+
*
|
|
9
|
+
* const pagos = useCount(payments, { selection: { field: "member_id", value: member.id } });
|
|
10
|
+
* <SmartButton icon={Wallet} label="Pagos" count={pagos?.value} onClick={…} />
|
|
11
|
+
*
|
|
12
|
+
* Context: an application counted «this member's payments» with a hook of its own over a list
|
|
13
|
+
* reference it built by hand. It is a listing of one row: the count is the one the server sends
|
|
14
|
+
* with every page (a floor, `exact: false`, when it stopped counting at its cap), and it follows
|
|
15
|
+
* the context and every write to the entity as any list does — a payment saved in a modal moves
|
|
16
|
+
* the number behind it. Never a page fetched to be counted here.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useCount<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, criteria?: Criteria<T>): Count | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useListing } from "./useListing.js";
|
|
3
|
+
/**
|
|
4
|
+
* How many records of an entity a criteria holds, counted by the SERVER: «this member's
|
|
5
|
+
* payments (2)», the number of a smart button. `null` until it answers — and while it fails —,
|
|
6
|
+
* which web-ui's `SmartButton` reads as «—», never as 0.
|
|
7
|
+
*
|
|
8
|
+
* const pagos = useCount(payments, { selection: { field: "member_id", value: member.id } });
|
|
9
|
+
* <SmartButton icon={Wallet} label="Pagos" count={pagos?.value} onClick={…} />
|
|
10
|
+
*
|
|
11
|
+
* Context: an application counted «this member's payments» with a hook of its own over a list
|
|
12
|
+
* reference it built by hand. It is a listing of one row: the count is the one the server sends
|
|
13
|
+
* with every page (a floor, `exact: false`, when it stopped counting at its cap), and it follows
|
|
14
|
+
* the context and every write to the entity as any list does — a payment saved in a modal moves
|
|
15
|
+
* the number behind it. Never a page fetched to be counted here.
|
|
16
|
+
*/
|
|
17
|
+
export function useCount(given, criteria) {
|
|
18
|
+
const listing = useListing(given, {
|
|
19
|
+
pageSize: 1,
|
|
20
|
+
...(criteria === undefined ? {} : { criteria }),
|
|
21
|
+
});
|
|
22
|
+
return listing.status === "failed" ? null : listing.count;
|
|
23
|
+
}
|
|
@@ -18,10 +18,10 @@ import { type Advice, type FieldState } from "../core/edit.js";
|
|
|
18
18
|
* - **drafts** — an edit kept between requests (sincpro_framework's `Drafts`) comes back with
|
|
19
19
|
* the record and is shown as restored; `keep()` stores the current one.
|
|
20
20
|
* - **`Edit`** — an entity that declares `edit` speaks sincpro_framework's `Edit` on it for all
|
|
21
|
-
* three: `keep()` is `save_draft`, `save()` is `save` — the
|
|
22
|
-
* the draft version read and the stored version it started
|
|
23
|
-
* `discard`, which drops the draft on the server too. Without it,
|
|
24
|
-
* fields and the version to `save`.
|
|
21
|
+
* three: `keep()` is `save_draft`, `save()` is `save` — the fields changed, without what the
|
|
22
|
+
* framework writes (`editedOf`), the draft version read and the stored version it started
|
|
23
|
+
* from — and `discard()` is `discard`, which drops the draft on the server too. Without it,
|
|
24
|
+
* a save sends the changed fields and the version to `save`.
|
|
25
25
|
* - **creating** — with no id it is a record that does not exist yet: it starts from the
|
|
26
26
|
* defaults the model publishes, previews like any other, and `save()` sends it to the
|
|
27
27
|
* entity's `create` route with an `Idempotency-Key` (a retry never creates two). When the
|
package/dist/react/useRecord.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
|
|
3
|
-
import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
3
|
+
import { changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
4
4
|
import { linesAnswered } from "../core/lines.js";
|
|
5
5
|
import { useFramework } from "./context.js";
|
|
6
6
|
import { useWrites } from "./useWrites.js";
|
|
@@ -232,14 +232,17 @@ export function useRecord(entity, opened) {
|
|
|
232
232
|
else
|
|
233
233
|
setFailure(error);
|
|
234
234
|
};
|
|
235
|
-
// sincpro_framework's `Edit`:
|
|
236
|
-
//
|
|
237
|
-
//
|
|
235
|
+
// sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
|
|
236
|
+
// (`0`: none) — another tab that kept first wins —, and the stored version the edit started
|
|
237
|
+
// from. Without an `action` it is the server's default, `save_draft`.
|
|
238
238
|
const editOf = (action) => ({
|
|
239
239
|
id: keyNow(),
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
|
|
240
|
+
// Never a field the framework writes (its id, its stamps, a line's version), which `Edit`
|
|
241
|
+
// refuses: a new record carries what a person may write, a stored one what changed — the
|
|
242
|
+
// server puts it over what it stored and the caller's draft.
|
|
243
|
+
values: isNew
|
|
244
|
+
? creationOf(state.meta, values)
|
|
245
|
+
: editedOf(state.meta, values, Object.keys(changed)),
|
|
243
246
|
changed: Object.keys(changed),
|
|
244
247
|
version: draft?.version ?? 0,
|
|
245
248
|
...(typeof version === "number" ? { origin_version: version } : {}),
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
* What a screen keeps of running one of the application's use cases.
|
|
3
3
|
*
|
|
4
4
|
* `run` answers what the use case answered, or `undefined` when it failed — the failure is in
|
|
5
|
-
* `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen.
|
|
5
|
+
* `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen. So a use
|
|
6
|
+
* case that answers nothing answers `null`, never `undefined`: a `DELETE` the server answers
|
|
7
|
+
* with 204 resolves `null` through the transport, and a Feature hands that on instead of typing
|
|
8
|
+
* itself `void` — or «done» and «failed» look the same to the screen
|
|
9
|
+
* (Sincpro-SRL/sincpro_client_framework#51).
|
|
6
10
|
*/
|
|
7
11
|
export type ServiceState<A extends unknown[], R> = {
|
|
8
12
|
run: (...args: A) => Promise<R | undefined>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
2
|
+
/** What a screen shows of a use case that reads: the answer to the arguments it asks with NOW. */
|
|
3
|
+
export type ServiceReading<R> = {
|
|
4
|
+
/** `loading` until the answer to these arguments arrives — never another's answer. */
|
|
5
|
+
status: "loading" | "ready" | "failed";
|
|
6
|
+
answer: R | undefined;
|
|
7
|
+
error: unknown;
|
|
8
|
+
/** Read again with the same arguments; the answer stays on screen until the new one. */
|
|
9
|
+
reload: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** A use case as a screen reads with it: a method of a service, read from its bounded context. */
|
|
12
|
+
type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
|
|
13
|
+
/**
|
|
14
|
+
* A use case that READS, run by the screen that shows it: on mount, again whenever its
|
|
15
|
+
* arguments change, when the process's context changes (another company), and when a write
|
|
16
|
+
* touches an entity it follows.
|
|
17
|
+
*
|
|
18
|
+
* const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
|
|
19
|
+
* follows: [payments],
|
|
20
|
+
* });
|
|
21
|
+
* balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
|
|
22
|
+
*
|
|
23
|
+
* Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
|
|
24
|
+
* screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
|
|
25
|
+
* screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
|
|
26
|
+
* (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
|
|
27
|
+
* as `useRecord` does for another id — while reading the same ones again keeps the answer on
|
|
28
|
+
* screen until the new one lands. The last question wins: an answer to arguments no longer on
|
|
29
|
+
* screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
|
|
30
|
+
* function per `scoped(…)`); its trace and report are the service's, never this hook's.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useServiceReading<A extends unknown[], R>(useCase: UseCase<A, R>, args: A, options?: {
|
|
33
|
+
follows?: readonly Entity[];
|
|
34
|
+
}): ServiceReading<Awaited<R>>;
|
|
35
|
+
export {};
|