@sincpro/web-framework 3.5.0 → 3.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 +2 -0
- package/dist/core/command.d.ts +16 -0
- package/dist/core/command.js +17 -0
- package/dist/core/copy.d.ts +16 -0
- package/dist/core/copy.js +26 -0
- package/dist/core/history.d.ts +16 -4
- package/dist/core/history.js +20 -17
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +3 -2
- package/dist/core/list.d.ts +12 -0
- package/dist/core/list.js +14 -0
- package/dist/core/present.d.ts +12 -0
- package/dist/core/present.js +39 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/useBatchCommand.d.ts +50 -0
- package/dist/react/useBatchCommand.js +124 -0
- package/dist/react/useCommand.js +3 -4
- package/dist/react/useSelection.d.ts +37 -0
- package/dist/react/useSelection.js +40 -0
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- package/dist/web/list/BatchProgress.d.ts +16 -0
- package/dist/web/list/BatchProgress.js +40 -0
- package/dist/web/list/EntityList.d.ts +12 -6
- package/dist/web/list/EntityList.js +37 -22
- package/dist/web/list/EntitySearchBar.d.ts +9 -0
- package/dist/web/list/EntitySearchBar.js +15 -5
- package/dist/web/list/pivot.d.ts +5 -1
- package/dist/web/list/pivot.js +28 -11
- package/dist/web/list/records.d.ts +100 -0
- package/dist/web/list/records.js +219 -0
- package/dist/web/list/search.d.ts +0 -17
- package/dist/web/list/search.js +33 -5
- package/dist/web/record/EntityTags.d.ts +5 -2
- package/dist/web/record/EntityTags.js +34 -12
- package/dist/web/record/opening.d.ts +6 -2
- package/dist/web/workspace/SincproApp.js +13 -2
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +23 -25
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -499,6 +499,8 @@ hook and draw your own, or go straight to the loose piece.
|
|
|
499
499
|
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
500
500
|
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
501
501
|
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
502
|
+
| What is chosen in a list | `EntityList selectable selection` | `useSelection` | `Selection`, `chosen`, `allMatching` (client-framework) |
|
|
503
|
+
| Act on each chosen one | `BatchProgress`, `selectionActions={(chosen) => …}` | `useBatchCommand` | `runBatch`, `keysOf` (client-framework), `sendRoute` |
|
|
502
504
|
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
503
505
|
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
504
506
|
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SendOptions, type Transport, type WriteRoute } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
/**
|
|
4
|
+
* A write route of an entity sent as a Command for one record — what a button runs once
|
|
5
|
+
* (`useCommand`) and a batch once per record (`useBatchCommand`).
|
|
6
|
+
*
|
|
7
|
+
* await sendRoute(transport, invoices.commands.confirm, "F-7", {}, { idempotencyKey })
|
|
8
|
+
* -> POST /invoices/F-7/confirm
|
|
9
|
+
*
|
|
10
|
+
* A Command whose body names its record (`target`) gets the id there; the path takes it, and
|
|
11
|
+
* every other `{name}`, from the body (`bodyFor`, `pathFor`). The idempotency key is the caller's:
|
|
12
|
+
* one per gesture and record, kept while it goes unanswered (`retryKeys`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendRoute<A>(transport: Transport, route: WriteRoute, id: string | undefined, body: AnyRecord, options?: SendOptions & {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}): Promise<A>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { bodyFor, pathFor, } from "@sincpro/client-framework";
|
|
2
|
+
/**
|
|
3
|
+
* A write route of an entity sent as a Command for one record — what a button runs once
|
|
4
|
+
* (`useCommand`) and a batch once per record (`useBatchCommand`).
|
|
5
|
+
*
|
|
6
|
+
* await sendRoute(transport, invoices.commands.confirm, "F-7", {}, { idempotencyKey })
|
|
7
|
+
* -> POST /invoices/F-7/confirm
|
|
8
|
+
*
|
|
9
|
+
* A Command whose body names its record (`target`) gets the id there; the path takes it, and
|
|
10
|
+
* every other `{name}`, from the body (`bodyFor`, `pathFor`). The idempotency key is the caller's:
|
|
11
|
+
* one per gesture and record, kept while it goes unanswered (`retryKeys`).
|
|
12
|
+
*/
|
|
13
|
+
export function sendRoute(transport, route, id, body, options = {}) {
|
|
14
|
+
const { signal, ...sending } = options;
|
|
15
|
+
const sent = bodyFor(route, id, body);
|
|
16
|
+
return transport.send(route.method, pathFor(route, id, sent), sent, signal, sending);
|
|
17
|
+
}
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ export type FrameworkCopy = {
|
|
|
77
77
|
browse: string;
|
|
78
78
|
/** The choice of nothing, when a field may be left empty (`EntityPicker none`). */
|
|
79
79
|
none: string;
|
|
80
|
+
/** A chooser of several: what puts the chosen on the field that asked — «Agregar (3)». */
|
|
81
|
+
addChosen: (count: number | null) => string;
|
|
80
82
|
};
|
|
81
83
|
summary: {
|
|
82
84
|
/** The facts of a record's summary: when it was made and last changed. */
|
|
@@ -99,6 +101,20 @@ export type FrameworkCopy = {
|
|
|
99
101
|
/** Sends what an action asked for (`ask`). */
|
|
100
102
|
send: string;
|
|
101
103
|
};
|
|
104
|
+
batch: {
|
|
105
|
+
/** The bar of a Command running once per record: its accessible name. */
|
|
106
|
+
running: string;
|
|
107
|
+
/** «2 de 3»: how far it is. */
|
|
108
|
+
progress: (settled: number, total: number) => string;
|
|
109
|
+
/** «3 hechos · 1 no», what became of them; `skipped` never ran. */
|
|
110
|
+
outcome: (done: number, failed: number, skipped: number) => string;
|
|
111
|
+
/** Runs it again for the records it failed for. */
|
|
112
|
+
retry: string;
|
|
113
|
+
/** Stops it: what has not started does not. */
|
|
114
|
+
stop: string;
|
|
115
|
+
/** More were chosen than a Command runs on at once. */
|
|
116
|
+
tooMany: (size: number | null, limit: number) => string;
|
|
117
|
+
};
|
|
102
118
|
failure: {
|
|
103
119
|
/** The server could not be reached at all — nothing it said is known. */
|
|
104
120
|
unreachable: string;
|
package/dist/core/copy.js
CHANGED
|
@@ -41,6 +41,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
41
41
|
picker: {
|
|
42
42
|
browse: "Search all",
|
|
43
43
|
none: "None",
|
|
44
|
+
addChosen: (count) => (count === null ? "Add them" : `Add (${count})`),
|
|
44
45
|
},
|
|
45
46
|
summary: {
|
|
46
47
|
created: "Created",
|
|
@@ -56,6 +57,18 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
56
57
|
rehearsing: "Checking what it would do…",
|
|
57
58
|
send: "Confirm",
|
|
58
59
|
},
|
|
60
|
+
batch: {
|
|
61
|
+
running: "Running on each record",
|
|
62
|
+
progress: (settled, total) => `${settled} of ${total}`,
|
|
63
|
+
outcome: (done, failed, skipped) => [
|
|
64
|
+
`${done} done`,
|
|
65
|
+
...(failed > 0 ? [`${failed} failed`] : []),
|
|
66
|
+
...(skipped > 0 ? [`${skipped} not run`] : []),
|
|
67
|
+
].join(" · "),
|
|
68
|
+
retry: "Retry the ones that failed",
|
|
69
|
+
stop: "Stop",
|
|
70
|
+
tooMany: (size, limit) => `${size === null ? "More than " + limit : size} records are chosen; at most ${limit} at once. Narrow the search.`,
|
|
71
|
+
},
|
|
59
72
|
failure: {
|
|
60
73
|
unreachable: "The server could not be reached",
|
|
61
74
|
unexpected: "The server answered something else",
|
|
@@ -131,6 +144,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
131
144
|
picker: {
|
|
132
145
|
browse: "Buscar en todos",
|
|
133
146
|
none: "Ninguno",
|
|
147
|
+
addChosen: (count) => (count === null ? "Agregarlos" : `Agregar (${count})`),
|
|
134
148
|
},
|
|
135
149
|
summary: {
|
|
136
150
|
created: "Creado",
|
|
@@ -146,6 +160,18 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
146
160
|
rehearsing: "Revisando qué haría…",
|
|
147
161
|
send: "Confirmar",
|
|
148
162
|
},
|
|
163
|
+
batch: {
|
|
164
|
+
running: "Ejecutando en cada registro",
|
|
165
|
+
progress: (settled, total) => `${settled} de ${total}`,
|
|
166
|
+
outcome: (done, failed, skipped) => [
|
|
167
|
+
`${done} ${done === 1 ? "hecho" : "hechos"}`,
|
|
168
|
+
...(failed > 0 ? [`${failed} ${failed === 1 ? "falló" : "fallaron"}`] : []),
|
|
169
|
+
...(skipped > 0 ? [`${skipped} sin ejecutar`] : []),
|
|
170
|
+
].join(" · "),
|
|
171
|
+
retry: "Reintentar los que fallaron",
|
|
172
|
+
stop: "Detener",
|
|
173
|
+
tooMany: (size, limit) => `${size === null ? "Son más de " + limit : "Son " + size} registros elegidos; a la vez, como mucho ${limit}. Acotá la búsqueda.`,
|
|
174
|
+
},
|
|
149
175
|
failure: {
|
|
150
176
|
unreachable: "No se pudo hablar con el servidor",
|
|
151
177
|
unexpected: "El servidor contestó otra cosa",
|
package/dist/core/history.d.ts
CHANGED
|
@@ -22,9 +22,11 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
|
22
22
|
*
|
|
23
23
|
* An edit (`EntityUpdated`) carries each field it moved as `changes: {field: [before, after]}`
|
|
24
24
|
* and the word it was called then (`field_labels`, kept because an audit says what a person saw
|
|
25
|
-
* at the time)
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* at the time). It is handed to web-ui's activity as `changes` — «Título», «Bienvenidos» struck
|
|
26
|
+
* → «Bienvenidos al CAUOR» —, in sight under the event and scanned field by field, each side as
|
|
27
|
+
* the record's own model writes it (a state by its word, an amount as money, a date in the
|
|
28
|
+
* installed style). It used to be one line in `detail` («Título: Bienvenidos → …»), which could
|
|
29
|
+
* be read but not scanned, and an empty side was a «—» that read as a dash somebody typed.
|
|
28
30
|
*/
|
|
29
31
|
export type HistoryEntry = {
|
|
30
32
|
id: string;
|
|
@@ -33,9 +35,18 @@ export type HistoryEntry = {
|
|
|
33
35
|
/** Who did it, as the fact says (`actor`); absent: the system, or a backend before 3.37. */
|
|
34
36
|
by?: string;
|
|
35
37
|
detail?: string;
|
|
38
|
+
/** The fields an edit moved, as web-ui's `ActivityEvent.changes` draws them. */
|
|
39
|
+
changes?: readonly HistoryChange[];
|
|
36
40
|
/** The colour of this kind of fact (`FACT_TONES`, or the application's by `name`). */
|
|
37
41
|
tone?: FactTone;
|
|
38
42
|
};
|
|
43
|
+
/** One field an edit moved: its word then, and each side as the record's model writes it —
|
|
44
|
+
* `null` is empty, which web-ui writes «vacío». */
|
|
45
|
+
export type HistoryChange = {
|
|
46
|
+
field: string;
|
|
47
|
+
from: string | null;
|
|
48
|
+
to: string | null;
|
|
49
|
+
};
|
|
39
50
|
/** The tones a fact may take — web-ui's `Tone`, named here because `core/` imports no UI. */
|
|
40
51
|
export type FactTone = "neutral" | "info" | "good" | "warn" | "bad" | "accent";
|
|
41
52
|
/**
|
|
@@ -51,7 +62,8 @@ export declare function toneOfFact(name: unknown, tones?: Readonly<Record<string
|
|
|
51
62
|
* The facts of a record as entries of web-ui's activity.
|
|
52
63
|
*
|
|
53
64
|
* historyOf(rows, eventsMeta, "es", { record: pagoMeta, tones: { pago_aprobado: "good" } })
|
|
54
|
-
* -> [{ label: "Se actualizó",
|
|
65
|
+
* -> [{ label: "Se actualizó", changes: [{ field: "Estado", from: "En revisión",
|
|
66
|
+
* to: "Validado" }], by: "ana", … }]
|
|
55
67
|
*
|
|
56
68
|
* `meta` is the history route's definition; `events` each event's own, by its wire name
|
|
57
69
|
* (`eventMetasOf(contract)`), which names a fact's own fields first; `record` is the record's,
|
package/dist/core/history.js
CHANGED
|
@@ -33,7 +33,7 @@ const ENVELOPE = new Set([
|
|
|
33
33
|
"actor",
|
|
34
34
|
"correlation_id",
|
|
35
35
|
"causation_id",
|
|
36
|
-
// An edit's own:
|
|
36
|
+
// An edit's own: its `changes`, field by field, never as JSON.
|
|
37
37
|
"changes",
|
|
38
38
|
"field_labels",
|
|
39
39
|
]);
|
|
@@ -50,7 +50,7 @@ function wordOf(word, locale) {
|
|
|
50
50
|
return word === "" ? undefined : word;
|
|
51
51
|
return (locale ? word?.[locale] : undefined) ?? word?.["default"];
|
|
52
52
|
}
|
|
53
|
-
/** One side of a change, as the record's model writes the field; nothing is
|
|
53
|
+
/** One side of a change, as the record's model writes the field; nothing is `null`. */
|
|
54
54
|
function sideOf(record, field, value, locale) {
|
|
55
55
|
// A record's own model writes it (a choice by its word, money as money); without one, a
|
|
56
56
|
// boolean is still the copy table's word and never «true».
|
|
@@ -59,10 +59,10 @@ function sideOf(record, field, value, locale) {
|
|
|
59
59
|
? frameworkCopy().value.yes
|
|
60
60
|
: frameworkCopy().value.no
|
|
61
61
|
: (textOf(record, field, value, locale) ?? said(value));
|
|
62
|
-
return text
|
|
62
|
+
return text === null || text === undefined || text === "" ? null : text;
|
|
63
63
|
}
|
|
64
|
-
/** What an edit moved
|
|
65
|
-
function
|
|
64
|
+
/** What an edit moved, one field each: its word then, as it was and as it is. */
|
|
65
|
+
function editOf(row, record, locale) {
|
|
66
66
|
const changes = row["changes"];
|
|
67
67
|
if (typeof changes !== "object" || changes === null || Array.isArray(changes))
|
|
68
68
|
return [];
|
|
@@ -70,16 +70,20 @@ function changesOf(row, record, locale) {
|
|
|
70
70
|
return Object.entries(changes).map(([field, pair]) => {
|
|
71
71
|
// `(before, after)` travels as a list; anything else is only what it is now.
|
|
72
72
|
const [before, after] = Array.isArray(pair) ? pair : [undefined, pair];
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
return {
|
|
74
|
+
// The word it had THEN, else the record's model's, else its name.
|
|
75
|
+
field: wordOf(labels[field], locale) ?? labelOf(record, field, locale),
|
|
76
|
+
from: sideOf(record, field, before, locale),
|
|
77
|
+
to: sideOf(record, field, after, locale),
|
|
78
|
+
};
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
79
82
|
* The facts of a record as entries of web-ui's activity.
|
|
80
83
|
*
|
|
81
84
|
* historyOf(rows, eventsMeta, "es", { record: pagoMeta, tones: { pago_aprobado: "good" } })
|
|
82
|
-
* -> [{ label: "Se actualizó",
|
|
85
|
+
* -> [{ label: "Se actualizó", changes: [{ field: "Estado", from: "En revisión",
|
|
86
|
+
* to: "Validado" }], by: "ana", … }]
|
|
83
87
|
*
|
|
84
88
|
* `meta` is the history route's definition; `events` each event's own, by its wire name
|
|
85
89
|
* (`eventMetasOf(contract)`), which names a fact's own fields first; `record` is the record's,
|
|
@@ -94,14 +98,12 @@ export function historyOf(rows, meta, locale, options = {}) {
|
|
|
94
98
|
const word = wordOf(label, locale) ?? frameworkCopy().summary.recorded;
|
|
95
99
|
// This kind of fact's own definition names its fields; the route's, when it is not known.
|
|
96
100
|
const own = (typeof row["name"] === "string" && options.events?.[row["name"]]) || meta;
|
|
97
|
-
const parts =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.map(([key, value]) => `${labelOf(own, key, locale)}: ${value}`),
|
|
104
|
-
];
|
|
101
|
+
const parts = Object.entries(row)
|
|
102
|
+
.filter(([key]) => !ENVELOPE.has(key))
|
|
103
|
+
.map(([key, value]) => [key, said(value)])
|
|
104
|
+
.filter(([, value]) => value !== null && value !== row["entity_id"])
|
|
105
|
+
.map(([key, value]) => `${labelOf(own, key, locale)}: ${value}`);
|
|
106
|
+
const changes = editOf(row, options.record, locale);
|
|
105
107
|
const actor = said(row["actor"]);
|
|
106
108
|
const tone = toneOfFact(row["name"], tones);
|
|
107
109
|
return {
|
|
@@ -110,6 +112,7 @@ export function historyOf(rows, meta, locale, options = {}) {
|
|
|
110
112
|
at: String(row["created_at"] ?? ""),
|
|
111
113
|
...(actor === null ? {} : { by: actor }),
|
|
112
114
|
...(parts.length === 0 ? {} : { detail: parts.join(" · ") }),
|
|
115
|
+
...(changes.length === 0 ? {} : { changes }),
|
|
113
116
|
...(tone === undefined ? {} : { tone }),
|
|
114
117
|
};
|
|
115
118
|
});
|
package/dist/core/index.d.ts
CHANGED
|
@@ -8,17 +8,18 @@
|
|
|
8
8
|
* @sincpro/client-framework's — the same on every platform — and are imported from there.
|
|
9
9
|
*/
|
|
10
10
|
export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
|
|
11
|
+
export { sendRoute } from "./command.js";
|
|
11
12
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
12
13
|
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
14
|
export { explain } from "./explain.js";
|
|
14
15
|
export { type FormLayout, formOf } from "./form.js";
|
|
15
16
|
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
|
-
export { FACT_TONES, type FactTone, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
|
|
17
|
+
export { FACT_TONES, type FactTone, type HistoryChange, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
|
|
17
18
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, isReference, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
18
|
-
export { defineList, type GroupLevel, isList, type ListDefinition, listingAsk, type ListingQuestion, type ListSpec, type NamedFilter, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
|
+
export { CHOOSE_MANY, choosesMany, defineList, type GroupLevel, isList, type ListDefinition, listingAsk, type ListingQuestion, type ListSpec, type NamedFilter, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
20
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
20
21
|
export { detailOf, measuresOf, sumsOf, type Total, totalOf, } from "./measure.js";
|
|
21
|
-
export { BOOKKEEPING, currencyNow, type DateStyle, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, type FieldView, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
|
22
|
+
export { BOOKKEEPING, currencyNow, type DateStyle, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, type FieldView, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, shortTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
|
22
23
|
export { type Related, relatedOf } from "./related.js";
|
|
23
24
|
export { backReference, entityFor, relatedScope, type RelationField, relationFieldOf, } from "./relation.js";
|
|
24
25
|
export { type RecordSummary, summaryFieldsOf, summaryOf, } from "./summary.js";
|
package/dist/core/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @sincpro/client-framework's — the same on every platform — and are imported from there.
|
|
9
9
|
*/
|
|
10
10
|
export { cachedTransport, } from "./cache.js";
|
|
11
|
+
export { sendRoute } from "./command.js";
|
|
11
12
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
12
13
|
export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
|
|
13
14
|
export { explain } from "./explain.js";
|
|
@@ -15,10 +16,10 @@ export { formOf } from "./form.js";
|
|
|
15
16
|
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
17
|
export { FACT_TONES, historyOf, toneOfFact, } from "./history.js";
|
|
17
18
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
18
|
-
export { defineList, isList, listingAsk, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
|
+
export { CHOOSE_MANY, choosesMany, defineList, isList, listingAsk, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
20
|
export { lookupOf } from "./lookup.js";
|
|
20
21
|
export { detailOf, measuresOf, sumsOf, totalOf, } from "./measure.js";
|
|
21
|
-
export { BOOKKEEPING, currencyNow, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
|
22
|
+
export { BOOKKEEPING, currencyNow, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, shortTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
|
22
23
|
export { relatedOf } from "./related.js";
|
|
23
24
|
export { backReference, entityFor, relatedScope, relationFieldOf, } from "./relation.js";
|
|
24
25
|
export { summaryFieldsOf, summaryOf, } from "./summary.js";
|
package/dist/core/list.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { type Entity, type ResourceRef, type Transport } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Criteria, type Expression, type Grain, type Page, type Sort } from "@sincpro/criteria";
|
|
3
|
+
/**
|
|
4
|
+
* What a chooser of SEVERAL is asked (composer's `pick` `question`): the entity's list opened to
|
|
5
|
+
* choose many answers a `Selection` — what was ticked, or every record its question matches —
|
|
6
|
+
* instead of the one record a row press answers.
|
|
7
|
+
*
|
|
8
|
+
* api.pick<Selection>(entity.chooserRef(query, scope), add, { question: CHOOSE_MANY })
|
|
9
|
+
*/
|
|
10
|
+
export declare const CHOOSE_MANY: Readonly<{
|
|
11
|
+
many: true;
|
|
12
|
+
}>;
|
|
13
|
+
/** Whether a chooser was asked for several (`CHOOSE_MANY`). */
|
|
14
|
+
export declare function choosesMany(question: unknown): boolean;
|
|
3
15
|
/**
|
|
4
16
|
* A named way of looking at an entity: «Por cobrar», «Borradores», «Mis tickets».
|
|
5
17
|
*
|
package/dist/core/list.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { listRoute, screensTransport, } from "@sincpro/client-framework";
|
|
2
2
|
import { merge, } from "@sincpro/criteria";
|
|
3
3
|
import { frameworkCopy } from "./copy.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a chooser of SEVERAL is asked (composer's `pick` `question`): the entity's list opened to
|
|
6
|
+
* choose many answers a `Selection` — what was ticked, or every record its question matches —
|
|
7
|
+
* instead of the one record a row press answers.
|
|
8
|
+
*
|
|
9
|
+
* api.pick<Selection>(entity.chooserRef(query, scope), add, { question: CHOOSE_MANY })
|
|
10
|
+
*/
|
|
11
|
+
export const CHOOSE_MANY = Object.freeze({ many: true });
|
|
12
|
+
/** Whether a chooser was asked for several (`CHOOSE_MANY`). */
|
|
13
|
+
export function choosesMany(question) {
|
|
14
|
+
return (typeof question === "object" &&
|
|
15
|
+
question !== null &&
|
|
16
|
+
question.many === true);
|
|
17
|
+
}
|
|
4
18
|
export function defineList(entity, spec) {
|
|
5
19
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
|
|
6
20
|
throw new Error(`list id "${spec.id}" is not kebab-case: it becomes a workspace kind`);
|
package/dist/core/present.d.ts
CHANGED
|
@@ -112,6 +112,18 @@ export declare function isMoneyDefinition(definition: Meta | null | undefined):
|
|
|
112
112
|
* textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
|
|
113
113
|
*/
|
|
114
114
|
export declare function textOf(meta: Meta | null | undefined, name: string, value: unknown, locale?: string): string | null;
|
|
115
|
+
/**
|
|
116
|
+
* A number where room is short — a chart's axis, beside a sparkline: the same value `textOf`
|
|
117
|
+
* reads, to the thousand or the million, money still in its currency.
|
|
118
|
+
*
|
|
119
|
+
* shortTextOf(meta, "monto", 120000, "es-BO") -> "Bs 120 k" (widget money, BOB installed)
|
|
120
|
+
* shortTextOf(meta, "bytes", 79691776, "es") -> "79,7 M"
|
|
121
|
+
* shortTextOf(meta, "state", "paid", "es") -> "Pagada" (not a number: as textOf)
|
|
122
|
+
*
|
|
123
|
+
* Context: web-ui's `PivotMeasure.formatShort`. Without it an axis wrote the bare number, and a
|
|
124
|
+
* money lost its currency under every tick.
|
|
125
|
+
*/
|
|
126
|
+
export declare function shortTextOf(meta: Meta | null | undefined, name: string, value: unknown, locale?: string): string | null;
|
|
115
127
|
/**
|
|
116
128
|
* The value a column orders and groups on: the raw scalar, never the text. ISO dates order
|
|
117
129
|
* as text; a decimal that travels as text orders as a number.
|
package/dist/core/present.js
CHANGED
|
@@ -377,6 +377,45 @@ export function textOf(meta, name, value, locale) {
|
|
|
377
377
|
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
+
function compactFormat(locale, currency) {
|
|
381
|
+
const key = `k|${locale ?? ""}|${currency ?? ""}`;
|
|
382
|
+
let format = formatters.get(key);
|
|
383
|
+
if (format === undefined) {
|
|
384
|
+
try {
|
|
385
|
+
format = new Intl.NumberFormat(locale, {
|
|
386
|
+
notation: "compact",
|
|
387
|
+
maximumFractionDigits: 1,
|
|
388
|
+
...(currency === undefined ? {} : { style: "currency", currency }),
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
// A currency `Intl` does not know: the long text says it whole.
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
formatters.set(key, format);
|
|
396
|
+
}
|
|
397
|
+
return format;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* A number where room is short — a chart's axis, beside a sparkline: the same value `textOf`
|
|
401
|
+
* reads, to the thousand or the million, money still in its currency.
|
|
402
|
+
*
|
|
403
|
+
* shortTextOf(meta, "monto", 120000, "es-BO") -> "Bs 120 k" (widget money, BOB installed)
|
|
404
|
+
* shortTextOf(meta, "bytes", 79691776, "es") -> "79,7 M"
|
|
405
|
+
* shortTextOf(meta, "state", "paid", "es") -> "Pagada" (not a number: as textOf)
|
|
406
|
+
*
|
|
407
|
+
* Context: web-ui's `PivotMeasure.formatShort`. Without it an axis wrote the bare number, and a
|
|
408
|
+
* money lost its currency under every tick.
|
|
409
|
+
*/
|
|
410
|
+
export function shortTextOf(meta, name, value, locale) {
|
|
411
|
+
const field = fieldOf(meta, name);
|
|
412
|
+
const money = field.widget === "money" && field.kind === "scalar";
|
|
413
|
+
const number = value === null || value === undefined || value === "" ? NaN : Number(value);
|
|
414
|
+
if ((!money && field.type !== "number" && field.type !== "integer") || Number.isNaN(number))
|
|
415
|
+
return textOf(meta, name, value, locale);
|
|
416
|
+
return (compactFormat(locale, money ? currency : undefined)?.format(number) ??
|
|
417
|
+
textOf(meta, name, value, locale));
|
|
418
|
+
}
|
|
380
419
|
/**
|
|
381
420
|
* The value a column orders and groups on: the raw scalar, never the text. ISO dates order
|
|
382
421
|
* as text; a decimal that travels as text orders as a number.
|
package/dist/react/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
+
export { BATCH_LIMIT, type BatchCommandState, useBatchCommand, } from "./useBatchCommand.js";
|
|
8
9
|
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
10
|
export { useContextValues } from "./useContextValues.js";
|
|
10
11
|
export { useCount } from "./useCount.js";
|
|
@@ -17,6 +18,7 @@ export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
|
17
18
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
18
19
|
export { type LifecycleAction, type RecordLifecycleActions, useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
19
20
|
export { useRelated } from "./useRelated.js";
|
|
21
|
+
export { type ListSelection, useSelection } from "./useSelection.js";
|
|
20
22
|
export { type ServiceState, useService } from "./useService.js";
|
|
21
23
|
export { type ServiceReading, useServiceReading, } from "./useServiceReading.js";
|
|
22
24
|
export { useSummaryOf } from "./useSummary.js";
|
package/dist/react/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
+
export { BATCH_LIMIT, useBatchCommand, } from "./useBatchCommand.js";
|
|
8
9
|
export { useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
10
|
export { useContextValues } from "./useContextValues.js";
|
|
10
11
|
export { useCount } from "./useCount.js";
|
|
@@ -17,6 +18,7 @@ export { usePivot, } from "./usePivot.js";
|
|
|
17
18
|
export { useRecord, } from "./useRecord.js";
|
|
18
19
|
export { useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
19
20
|
export { useRelated } from "./useRelated.js";
|
|
21
|
+
export { useSelection } from "./useSelection.js";
|
|
20
22
|
export { useService } from "./useService.js";
|
|
21
23
|
export { useServiceReading, } from "./useServiceReading.js";
|
|
22
24
|
export { useSummaryOf } from "./useSummary.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type BatchResult, type CommandAnswers, type CommandBodies, type Entity, type Selection } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import type { AnswerOf } from "./useCommand.js";
|
|
4
|
+
/** The most records a Command runs on at once from a screen, unless the screen says otherwise. */
|
|
5
|
+
export declare const BATCH_LIMIT = 200;
|
|
6
|
+
export type BatchCommandState<R, B extends AnyRecord = AnyRecord, T extends AnyRecord = AnyRecord> = {
|
|
7
|
+
/** Runs the Command once per chosen record. Without a body, an empty one. */
|
|
8
|
+
run: (selection: Selection<T>, body?: B) => Promise<BatchResult<string, R> | undefined>;
|
|
9
|
+
/** Again, only for the records it failed for — each with the key it went with, so a record
|
|
10
|
+
* the server did run after all is not run twice. */
|
|
11
|
+
retry: () => Promise<BatchResult<string, R> | undefined>;
|
|
12
|
+
/** What has not started does not; what runs finishes — the server may be doing it. */
|
|
13
|
+
stop: () => void;
|
|
14
|
+
running: boolean;
|
|
15
|
+
/** How far it is while it runs. */
|
|
16
|
+
progress: {
|
|
17
|
+
settled: number;
|
|
18
|
+
total: number;
|
|
19
|
+
} | null;
|
|
20
|
+
/** One outcome per record, once it ended. */
|
|
21
|
+
result: BatchResult<string, R> | null;
|
|
22
|
+
/** Why it did not start: too many chosen (`SelectionTooLarge`), the keys could not be read. */
|
|
23
|
+
error: unknown;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* One Command of an entity, run once per record of a selection — «Confirmar» on the invoices
|
|
28
|
+
* ticked, «Aprobar» on every payment a filter shows —, one outcome per record.
|
|
29
|
+
*
|
|
30
|
+
* const confirm = useBatchCommand(invoices, "confirm");
|
|
31
|
+
* <Button onPress={() => confirm.run(chosen.selection)}>Confirmar</Button>
|
|
32
|
+
* <BatchProgress batch={confirm} /> // «2 de 3», then «2 hechos · 1 falló: F-7 — …»
|
|
33
|
+
*
|
|
34
|
+
* Context: `for rec in self` from a screen. The keys come from the selection (`keysOf`: in
|
|
35
|
+
* hand, or read once as references — never more than `limit`); each record is the Command sent
|
|
36
|
+
* through the screens' transport — a use case of its own, traced — with an idempotency key of
|
|
37
|
+
* its own, kept while it goes unanswered (`retryKeys`): a retry after a dropped request is the
|
|
38
|
+
* same confirmation, never a second one. A failure is that record's (`runBatch`); the lists
|
|
39
|
+
* follow every write as they do for one.
|
|
40
|
+
*
|
|
41
|
+
* In order, one at a time, by default: a server is not asked for two hundred writes at once
|
|
42
|
+
* because a person ticked them. `concurrency` changes that.
|
|
43
|
+
*
|
|
44
|
+
* Not here: a batch the server runs in one request («everything matching» as a criteria) —
|
|
45
|
+
* sincpro_framework#185.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useBatchCommand<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, options?: {
|
|
48
|
+
limit?: number;
|
|
49
|
+
concurrency?: number;
|
|
50
|
+
}): BatchCommandState<AnswerOf<R, A, N>, C[N], T>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keysOf, listRoute, retryKeys, runBatch, } from "@sincpro/client-framework";
|
|
3
|
+
import { sendRoute } from "../core/command.js";
|
|
4
|
+
import { useFramework } from "./context.js";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
/** The most records a Command runs on at once from a screen, unless the screen says otherwise. */
|
|
7
|
+
export const BATCH_LIMIT = 200;
|
|
8
|
+
/**
|
|
9
|
+
* One Command of an entity, run once per record of a selection — «Confirmar» on the invoices
|
|
10
|
+
* ticked, «Aprobar» on every payment a filter shows —, one outcome per record.
|
|
11
|
+
*
|
|
12
|
+
* const confirm = useBatchCommand(invoices, "confirm");
|
|
13
|
+
* <Button onPress={() => confirm.run(chosen.selection)}>Confirmar</Button>
|
|
14
|
+
* <BatchProgress batch={confirm} /> // «2 de 3», then «2 hechos · 1 falló: F-7 — …»
|
|
15
|
+
*
|
|
16
|
+
* Context: `for rec in self` from a screen. The keys come from the selection (`keysOf`: in
|
|
17
|
+
* hand, or read once as references — never more than `limit`); each record is the Command sent
|
|
18
|
+
* through the screens' transport — a use case of its own, traced — with an idempotency key of
|
|
19
|
+
* its own, kept while it goes unanswered (`retryKeys`): a retry after a dropped request is the
|
|
20
|
+
* same confirmation, never a second one. A failure is that record's (`runBatch`); the lists
|
|
21
|
+
* follow every write as they do for one.
|
|
22
|
+
*
|
|
23
|
+
* In order, one at a time, by default: a server is not asked for two hundred writes at once
|
|
24
|
+
* because a person ticked them. `concurrency` changes that.
|
|
25
|
+
*
|
|
26
|
+
* Not here: a batch the server runs in one request («everything matching» as a criteria) —
|
|
27
|
+
* sincpro_framework#185.
|
|
28
|
+
*/
|
|
29
|
+
export function useBatchCommand(entity, name, options = {}) {
|
|
30
|
+
const route = entity.commands[name];
|
|
31
|
+
if (route === undefined)
|
|
32
|
+
throw new Error(`${entity.key} declares no command "${name}"`);
|
|
33
|
+
const { limit = BATCH_LIMIT, concurrency = 1 } = options;
|
|
34
|
+
const { transport, metas } = useFramework();
|
|
35
|
+
const [running, setRunning] = useState(false);
|
|
36
|
+
const [progress, setProgress] = useState(null);
|
|
37
|
+
const [result, setResult] = useState(null);
|
|
38
|
+
const [error, setError] = useState(null);
|
|
39
|
+
// The answers must not land on a screen that left; the Commands themselves go on.
|
|
40
|
+
const mounted = useRef(true);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
mounted.current = true;
|
|
43
|
+
return () => void (mounted.current = false);
|
|
44
|
+
}, []);
|
|
45
|
+
/** One gesture per record, kept across a retry: what went unanswered keeps its key. */
|
|
46
|
+
const gestures = useRef(new Map());
|
|
47
|
+
const last = useRef(null);
|
|
48
|
+
const stopping = useRef(null);
|
|
49
|
+
const execute = useCallback(async (keys, body) => {
|
|
50
|
+
const stopper = new AbortController();
|
|
51
|
+
stopping.current = stopper;
|
|
52
|
+
last.current = { body };
|
|
53
|
+
setRunning(true);
|
|
54
|
+
setResult(null);
|
|
55
|
+
setProgress({ settled: 0, total: keys.length });
|
|
56
|
+
const done = await runBatch(keys, async (key) => {
|
|
57
|
+
const gesture = gestures.current.get(key) ?? retryKeys();
|
|
58
|
+
gestures.current.set(key, gesture);
|
|
59
|
+
try {
|
|
60
|
+
const answer = await sendRoute(transport, route, key, body, {
|
|
61
|
+
idempotencyKey: gesture.keyFor({ id: key, body }),
|
|
62
|
+
});
|
|
63
|
+
gesture.settle(null);
|
|
64
|
+
return answer;
|
|
65
|
+
}
|
|
66
|
+
catch (failure) {
|
|
67
|
+
gesture.settle(failure);
|
|
68
|
+
throw failure;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
concurrency,
|
|
72
|
+
// Never handed to the send: a Command sent is not taken back, only the next ones.
|
|
73
|
+
signal: stopper.signal,
|
|
74
|
+
onOutcome: (_, now) => {
|
|
75
|
+
if (mounted.current)
|
|
76
|
+
setProgress(now);
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
if (mounted.current) {
|
|
80
|
+
setResult(done);
|
|
81
|
+
setRunning(false);
|
|
82
|
+
}
|
|
83
|
+
return done;
|
|
84
|
+
}, [transport, route, concurrency]);
|
|
85
|
+
return {
|
|
86
|
+
run: async (selection, body) => {
|
|
87
|
+
setError(null);
|
|
88
|
+
const meta = metas.get(entity.key);
|
|
89
|
+
let keys;
|
|
90
|
+
try {
|
|
91
|
+
keys = await keysOf(selection, {
|
|
92
|
+
transport,
|
|
93
|
+
route: listRoute(entity.list),
|
|
94
|
+
identity: meta?.get_id || meta?.identity || "id",
|
|
95
|
+
limit,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (failure) {
|
|
99
|
+
if (mounted.current)
|
|
100
|
+
setError(failure);
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return execute(keys, body ?? {});
|
|
104
|
+
},
|
|
105
|
+
retry: async () => {
|
|
106
|
+
const failed = (result?.outcomes ?? [])
|
|
107
|
+
.filter((one) => one.status !== "done")
|
|
108
|
+
.map((one) => one.item);
|
|
109
|
+
if (failed.length === 0 || last.current === null)
|
|
110
|
+
return undefined;
|
|
111
|
+
return execute(failed, last.current.body);
|
|
112
|
+
},
|
|
113
|
+
stop: () => stopping.current?.abort(),
|
|
114
|
+
running,
|
|
115
|
+
progress,
|
|
116
|
+
result,
|
|
117
|
+
error,
|
|
118
|
+
reset: () => {
|
|
119
|
+
setResult(null);
|
|
120
|
+
setError(null);
|
|
121
|
+
setProgress(null);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|