@sincpro/web-framework 2.6.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -31
- package/dist/core/copy.d.ts +19 -1
- package/dist/core/copy.js +36 -0
- package/dist/core/explain.d.ts +12 -4
- package/dist/core/explain.js +18 -6
- package/dist/core/form.d.ts +7 -3
- package/dist/core/form.js +11 -5
- package/dist/core/groups.d.ts +17 -0
- package/dist/core/groups.js +31 -0
- package/dist/core/history.d.ts +45 -1
- package/dist/core/history.js +84 -12
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -4
- package/dist/core/list.d.ts +14 -16
- package/dist/core/list.js +18 -25
- package/dist/core/measure.d.ts +14 -5
- package/dist/core/measure.js +32 -7
- package/dist/core/present.d.ts +51 -3
- package/dist/core/present.js +162 -15
- package/dist/core/summary.d.ts +6 -2
- package/dist/react/context.d.ts +23 -2
- package/dist/react/context.js +51 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useCommand.d.ts +7 -1
- package/dist/react/useCommand.js +12 -2
- package/dist/react/useGroups.js +15 -4
- package/dist/react/useHistory.d.ts +4 -2
- package/dist/react/useHistory.js +20 -5
- package/dist/react/usePivot.js +18 -3
- package/dist/react/useRecord.d.ts +5 -2
- package/dist/react/useRecord.js +14 -2
- package/dist/react/useRecordLifecycle.d.ts +43 -0
- package/dist/react/useRecordLifecycle.js +49 -0
- package/dist/web/Refused.d.ts +3 -3
- package/dist/web/Refused.js +3 -3
- package/dist/web/index.d.ts +3 -2
- package/dist/web/index.js +2 -1
- package/dist/web/list/EntityList.js +70 -17
- package/dist/web/list/columns.d.ts +6 -1
- package/dist/web/list/columns.js +53 -8
- package/dist/web/list/presentation.d.ts +20 -1
- package/dist/web/list/rowCommands.d.ts +2 -0
- package/dist/web/list/rowCommands.js +6 -1
- package/dist/web/record/RecordLifecycle.d.ts +23 -0
- package/dist/web/record/RecordLifecycle.js +29 -0
- package/dist/web/record/RelatedList.d.ts +0 -15
- package/dist/web/record/RelatedList.js +35 -6
- package/dist/web/record/edit.d.ts +5 -0
- package/dist/web/record/edit.js +48 -8
- package/dist/web/record/opening.d.ts +2 -2
- package/dist/web/record/record.js +5 -2
- package/dist/web/workspace/SincproApp.d.ts +10 -1
- package/dist/web/workspace/SincproApp.js +18 -4
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +3 -4
- package/dist/web/workspace/record.d.ts +7 -2
- package/dist/web/workspace/record.js +41 -8
- package/package.json +6 -6
package/dist/core/history.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { labelOf } from "@sincpro/criteria";
|
|
2
2
|
import { frameworkCopy } from "./copy.js";
|
|
3
|
+
import { textOf } from "./present.js";
|
|
4
|
+
/**
|
|
5
|
+
* The colour of a kind of fact, by its `name` — whole (`quipu.pagos.v1.pago_aprobado`) or its
|
|
6
|
+
* last part (`pago_aprobado`), so a version bump keeps it. These are the framework's own facts
|
|
7
|
+
* of a record's life; an application names its own (`presented(entity, { facts })`), over these.
|
|
8
|
+
* An edit and a creation carry no tone: they are the ordinary life of a record.
|
|
9
|
+
*/
|
|
10
|
+
export const FACT_TONES = {
|
|
11
|
+
deleted: "bad",
|
|
12
|
+
archived: "warn",
|
|
13
|
+
restored: "info",
|
|
14
|
+
};
|
|
15
|
+
/** The tone of a fact by its name, among `tones`; none when nothing names it. */
|
|
16
|
+
export function toneOfFact(name, tones = FACT_TONES) {
|
|
17
|
+
if (typeof name !== "string" || name === "")
|
|
18
|
+
return undefined;
|
|
19
|
+
return tones[name] ?? tones[name.slice(name.lastIndexOf(".") + 1)];
|
|
20
|
+
}
|
|
3
21
|
/** What every fact carries: what remains is what this fact says. */
|
|
4
22
|
const ENVELOPE = new Set([
|
|
5
23
|
"id",
|
|
24
|
+
"name",
|
|
6
25
|
"created_at",
|
|
7
26
|
"updated_at",
|
|
8
27
|
"version",
|
|
9
28
|
"label",
|
|
10
29
|
"entity_type",
|
|
11
30
|
"entity_id",
|
|
31
|
+
"entity_display",
|
|
12
32
|
"entity_version",
|
|
33
|
+
"actor",
|
|
13
34
|
"correlation_id",
|
|
14
35
|
"causation_id",
|
|
36
|
+
// An edit's own: drawn as «Field: before → after», never as JSON.
|
|
37
|
+
"changes",
|
|
38
|
+
"field_labels",
|
|
15
39
|
]);
|
|
16
40
|
function said(value) {
|
|
17
41
|
if (value === null || value === undefined || value === "")
|
|
@@ -20,25 +44,73 @@ function said(value) {
|
|
|
20
44
|
return value.length === 0 ? null : value.map(String).join(", ");
|
|
21
45
|
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
22
46
|
}
|
|
23
|
-
|
|
47
|
+
/** A word in every language (`{default, es}`), or a plain one, in `locale`. */
|
|
48
|
+
function wordOf(word, locale) {
|
|
49
|
+
if (typeof word === "string")
|
|
50
|
+
return word === "" ? undefined : word;
|
|
51
|
+
return (locale ? word?.[locale] : undefined) ?? word?.["default"];
|
|
52
|
+
}
|
|
53
|
+
/** One side of a change, as the record's model writes the field; nothing is «—». */
|
|
54
|
+
function sideOf(record, field, value, locale) {
|
|
55
|
+
// A record's own model writes it (a choice by its word, money as money); without one, a
|
|
56
|
+
// boolean is still the copy table's word and never «true».
|
|
57
|
+
const text = typeof value === "boolean" && !record?.fields[field]
|
|
58
|
+
? value
|
|
59
|
+
? frameworkCopy().value.yes
|
|
60
|
+
: frameworkCopy().value.no
|
|
61
|
+
: (textOf(record, field, value, locale) ?? said(value));
|
|
62
|
+
return text ?? "—";
|
|
63
|
+
}
|
|
64
|
+
/** What an edit moved: «Título: Bienvenidos → Bienvenidos al CAUOR», one per field. */
|
|
65
|
+
function changesOf(row, record, locale) {
|
|
66
|
+
const changes = row["changes"];
|
|
67
|
+
if (typeof changes !== "object" || changes === null || Array.isArray(changes))
|
|
68
|
+
return [];
|
|
69
|
+
const labels = (row["field_labels"] ?? {});
|
|
70
|
+
return Object.entries(changes).map(([field, pair]) => {
|
|
71
|
+
// `(before, after)` travels as a list; anything else is only what it is now.
|
|
72
|
+
const [before, after] = Array.isArray(pair) ? pair : [undefined, pair];
|
|
73
|
+
// The word it had THEN, else the record's model's, else its name.
|
|
74
|
+
const word = wordOf(labels[field], locale) ?? labelOf(record, field, locale);
|
|
75
|
+
return `${word}: ${sideOf(record, field, before, locale)} → ${sideOf(record, field, after, locale)}`;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The facts of a record as entries of web-ui's activity.
|
|
80
|
+
*
|
|
81
|
+
* historyOf(rows, eventsMeta, "es", { record: pagoMeta, tones: { pago_aprobado: "good" } })
|
|
82
|
+
* -> [{ label: "Se actualizó", detail: "Estado: En revisión → Validado", by: "ana", … }]
|
|
83
|
+
*
|
|
84
|
+
* `meta` is the history route's definition; `events` each event's own, by its wire name
|
|
85
|
+
* (`eventMetasOf(contract)`), which names a fact's own fields first; `record` is the record's,
|
|
86
|
+
* which writes each side of an edit. `tones` colour each kind of fact by its `name`, over the
|
|
87
|
+
* framework's own (`FACT_TONES`).
|
|
88
|
+
*/
|
|
89
|
+
export function historyOf(rows, meta, locale, options = {}) {
|
|
90
|
+
const tones = { ...FACT_TONES, ...options.tones };
|
|
24
91
|
return rows.map((row) => {
|
|
25
92
|
const label = row["label"];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
93
|
+
// A fact without a label is still a change; its id is not a word anyone reads.
|
|
94
|
+
const word = wordOf(label, locale) ?? frameworkCopy().summary.recorded;
|
|
95
|
+
// This kind of fact's own definition names its fields; the route's, when it is not known.
|
|
96
|
+
const own = (typeof row["name"] === "string" && options.events?.[row["name"]]) || meta;
|
|
97
|
+
const parts = [
|
|
98
|
+
...changesOf(row, options.record, locale),
|
|
99
|
+
...Object.entries(row)
|
|
100
|
+
.filter(([key]) => !ENVELOPE.has(key))
|
|
101
|
+
.map(([key, value]) => [key, said(value)])
|
|
102
|
+
.filter(([, value]) => value !== null && value !== row["entity_id"])
|
|
103
|
+
.map(([key, value]) => `${labelOf(own, key, locale)}: ${value}`),
|
|
104
|
+
];
|
|
105
|
+
const actor = said(row["actor"]);
|
|
106
|
+
const tone = toneOfFact(row["name"], tones);
|
|
37
107
|
return {
|
|
38
108
|
id: String(row["id"]),
|
|
39
109
|
label: word,
|
|
40
110
|
at: String(row["created_at"] ?? ""),
|
|
111
|
+
...(actor === null ? {} : { by: actor }),
|
|
41
112
|
...(parts.length === 0 ? {} : { detail: parts.join(" · ") }),
|
|
113
|
+
...(tone === undefined ? {} : { tone }),
|
|
42
114
|
};
|
|
43
115
|
});
|
|
44
116
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -12,12 +12,13 @@ export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrame
|
|
|
12
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
|
-
export {
|
|
15
|
+
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
|
+
export { FACT_TONES, type FactTone, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
|
|
16
17
|
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,
|
|
18
|
+
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, trashOf, } from "./list.js";
|
|
18
19
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
19
|
-
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
|
-
export { BOOKKEEPING, dayTextOf, defaultFields, type FieldView, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
20
|
+
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";
|
|
21
22
|
export { type Related, relatedOf } from "./related.js";
|
|
22
23
|
export { backReference, entityFor, relatedScope, type RelationField, relationFieldOf, } from "./relation.js";
|
|
23
24
|
export { type RecordSummary, summaryFieldsOf, summaryOf, } from "./summary.js";
|
package/dist/core/index.js
CHANGED
|
@@ -12,12 +12,13 @@ export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FR
|
|
|
12
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
|
-
export {
|
|
15
|
+
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
|
+
export { FACT_TONES, historyOf, toneOfFact, } from "./history.js";
|
|
16
17
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
17
|
-
export { defineList, isList,
|
|
18
|
+
export { defineList, isList, scopeOf, trashOf, } from "./list.js";
|
|
18
19
|
export { lookupOf } from "./lookup.js";
|
|
19
|
-
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
|
-
export { BOOKKEEPING, dayTextOf, defaultFields, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
|
20
|
+
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";
|
|
21
22
|
export { relatedOf } from "./related.js";
|
|
22
23
|
export { backReference, entityFor, relatedScope, relationFieldOf, } from "./relation.js";
|
|
23
24
|
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. */
|
|
@@ -46,6 +46,8 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
46
46
|
groupBy?: readonly GroupLevel[];
|
|
47
47
|
/** The fields «Group by» offers, in this order — among those the model lets split the set. */
|
|
48
48
|
groupable?: readonly string[];
|
|
49
|
+
/** The entity's trash (`trashOf`): each row offers «Restore» when the entity declares it. */
|
|
50
|
+
trash?: boolean;
|
|
49
51
|
};
|
|
50
52
|
/** A cut offered by name in the search bar: «sólo pagadas», «vencidas». */
|
|
51
53
|
export type NamedFilter<T> = {
|
|
@@ -65,21 +67,17 @@ export declare function defineList<T extends AnyRecord>(entity: Entity<T>, spec:
|
|
|
65
67
|
export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>): given is ListDefinition<T>;
|
|
66
68
|
/** The criteria a definition always asks: its scope, in its order. */
|
|
67
69
|
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
70
|
/**
|
|
71
|
-
* An entity's
|
|
72
|
-
*
|
|
73
|
-
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
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`.
|
|
74
73
|
*
|
|
75
|
-
*
|
|
74
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
76
75
|
*
|
|
77
|
-
* Context:
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
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.
|
|
82
80
|
*/
|
|
83
|
-
export declare function
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
import {
|
|
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,34 +22,26 @@ export function scopeOf(list) {
|
|
|
21
22
|
...(list.order === undefined ? {} : { order: [list.order] }),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
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
25
|
/**
|
|
27
|
-
* An entity's
|
|
28
|
-
*
|
|
29
|
-
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
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`.
|
|
30
28
|
*
|
|
31
|
-
*
|
|
29
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
32
30
|
*
|
|
33
|
-
* Context:
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
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.
|
|
38
35
|
*/
|
|
39
|
-
export function
|
|
40
|
-
const list = entity.ref();
|
|
36
|
+
export function trashOf(entity, options = {}) {
|
|
41
37
|
return {
|
|
42
|
-
...
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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,
|
|
48
46
|
};
|
|
49
47
|
}
|
|
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/measure.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { type Measure, type Meta } from "@sincpro/criteria";
|
|
2
|
+
/**
|
|
3
|
+
* How the model adds a field up (`Presentation.totals` on the server, `"total": "sum"` in the
|
|
4
|
+
* Meta), as one of the functions a screen draws; none when it says nothing, or names one this
|
|
5
|
+
* package does not draw.
|
|
6
|
+
*/
|
|
7
|
+
export type Total = "sum" | "avg" | "min" | "max";
|
|
8
|
+
export declare function totalOf(meta: Meta | null | undefined, name: string): Total | undefined;
|
|
2
9
|
/**
|
|
3
10
|
* What a group ADDS UP TO — «Total 1.204.933,00» beside «Pagadas · 187» — summed by the server
|
|
4
11
|
* over every row of the group, never the page.
|
|
5
12
|
*
|
|
6
13
|
* Context: a count says how many; whoever groups invoices by state wants to know how much. Which
|
|
7
|
-
* fields add up is the domain's
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* fields add up is the domain's: the model says it with `total` (sincpro_framework's
|
|
15
|
+
* `Presentation.totals`), and those are the default. A model that says nothing falls back to
|
|
16
|
+
* the figure a record computes: an exact number that is read-only (a total, a subtotal, a
|
|
17
|
+
* balance). What a person types — a discount, a percentage, a limit — is not added up: a sum of
|
|
10
18
|
* percentages means nothing. A screen names its own (`EntityList sums`).
|
|
11
19
|
*/
|
|
12
20
|
export declare function sumsOf(meta: Meta | null | undefined): string[];
|
|
13
|
-
/** The grouping's measures for these fields, each under its own name
|
|
14
|
-
|
|
21
|
+
/** The grouping's measures for these fields, each under its own name — by the function the
|
|
22
|
+
* model adds it up with (`total`), a sum when it names none. */
|
|
23
|
+
export declare function measuresOf(fields: readonly string[], meta?: Meta | null): Record<string, Measure>;
|
|
15
24
|
/** What a group's measures read as: «Total 1.204.933,00 · Saldo 12,50». */
|
|
16
25
|
export declare function detailOf(meta: Meta | null | undefined, measures: Readonly<Record<string, unknown>> | undefined, locale?: string): string | undefined;
|
package/dist/core/measure.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { labelOf, measure } from "@sincpro/criteria";
|
|
2
|
-
import { BOOKKEEPING, textOf } from "./present.js";
|
|
2
|
+
import { BOOKKEEPING, fieldMetaOf, textOf } from "./present.js";
|
|
3
|
+
const TOTALS = new Set(["sum", "avg", "min", "max"]);
|
|
4
|
+
export function totalOf(meta, name) {
|
|
5
|
+
const total = fieldMetaOf(meta, name)?.total;
|
|
6
|
+
if (typeof total !== "string")
|
|
7
|
+
return undefined;
|
|
8
|
+
// `mean` is the same function by web-ui's name.
|
|
9
|
+
const said = total === "mean" ? "avg" : total;
|
|
10
|
+
return TOTALS.has(said) ? said : undefined;
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* What a group ADDS UP TO — «Total 1.204.933,00» beside «Pagadas · 187» — summed by the server
|
|
5
14
|
* over every row of the group, never the page.
|
|
6
15
|
*
|
|
7
16
|
* Context: a count says how many; whoever groups invoices by state wants to know how much. Which
|
|
8
|
-
* fields add up is the domain's
|
|
9
|
-
*
|
|
10
|
-
*
|
|
17
|
+
* fields add up is the domain's: the model says it with `total` (sincpro_framework's
|
|
18
|
+
* `Presentation.totals`), and those are the default. A model that says nothing falls back to
|
|
19
|
+
* the figure a record computes: an exact number that is read-only (a total, a subtotal, a
|
|
20
|
+
* balance). What a person types — a discount, a percentage, a limit — is not added up: a sum of
|
|
11
21
|
* percentages means nothing. A screen names its own (`EntityList sums`).
|
|
12
22
|
*/
|
|
13
23
|
export function sumsOf(meta) {
|
|
14
24
|
if (!meta)
|
|
15
25
|
return [];
|
|
26
|
+
const totalled = Object.keys(meta.fields).filter((name) => totalOf(meta, name) !== undefined);
|
|
27
|
+
if (totalled.length > 0)
|
|
28
|
+
return totalled;
|
|
16
29
|
return Object.entries(meta.fields)
|
|
17
30
|
.filter(([name, field]) => !BOOKKEEPING.has(name) &&
|
|
18
31
|
(field.type === "number" || field.type === "integer") &&
|
|
@@ -20,9 +33,21 @@ export function sumsOf(meta) {
|
|
|
20
33
|
field.readonly === true)
|
|
21
34
|
.map(([name]) => name);
|
|
22
35
|
}
|
|
23
|
-
/** The grouping's measures for these fields, each under its own name
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
/** The grouping's measures for these fields, each under its own name — by the function the
|
|
37
|
+
* model adds it up with (`total`), a sum when it names none. */
|
|
38
|
+
export function measuresOf(fields, meta) {
|
|
39
|
+
return Object.fromEntries(fields.map((field) => {
|
|
40
|
+
switch (totalOf(meta, field)) {
|
|
41
|
+
case "avg":
|
|
42
|
+
return [field, measure.avg(field)];
|
|
43
|
+
case "min":
|
|
44
|
+
return [field, measure.min(field)];
|
|
45
|
+
case "max":
|
|
46
|
+
return [field, measure.max(field)];
|
|
47
|
+
default:
|
|
48
|
+
return [field, measure.sum(field)];
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
26
51
|
}
|
|
27
52
|
/** What a group's measures read as: «Total 1.204.933,00 · Saldo 12,50». */
|
|
28
53
|
export function detailOf(meta, measures, locale) {
|
package/dist/core/present.d.ts
CHANGED
|
@@ -21,6 +21,24 @@ export type FieldView = {
|
|
|
21
21
|
required: boolean;
|
|
22
22
|
readonly: boolean;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Where a name lives: a field of the model, or — written `recibo.numero` — a field of the
|
|
26
|
+
* definition of a value the record embeds. The model the field is described by, and its own
|
|
27
|
+
* name there.
|
|
28
|
+
*
|
|
29
|
+
* Context: the Meta publishes an embedded value with its fields, their labels and types (a
|
|
30
|
+
* payment's receipt: number, issued, concept, amount); an application wrote each of them by
|
|
31
|
+
* hand because nothing here could name one. A path is the same name a screen writes in a form.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fieldAt(meta: Meta | null | undefined, name: string): {
|
|
34
|
+
meta: Meta | null | undefined;
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
/** The value a name holds in a record: a field, or a field of an embedded value
|
|
38
|
+
* (`recibo.numero`). */
|
|
39
|
+
export declare function valueAt(meta: Meta | null | undefined, record: Readonly<Record<string, unknown>> | null | undefined, name: string): unknown;
|
|
40
|
+
/** What the model says of a name — a field, or a field of an embedded value — if it says it. */
|
|
41
|
+
export declare function fieldMetaOf(meta: Meta | null | undefined, name: string): FieldMeta | undefined;
|
|
24
42
|
export declare function viewOf(meta: Meta | null | undefined, name: string, locale?: string): FieldView;
|
|
25
43
|
/**
|
|
26
44
|
* The fields a screen shows when it names none: every scalar the model holds, in the order it
|
|
@@ -30,6 +48,27 @@ export declare function viewOf(meta: Meta | null | undefined, name: string, loca
|
|
|
30
48
|
export declare function defaultFields(meta: Meta | null | undefined): string[];
|
|
31
49
|
/** The bookkeeping every framework entity carries; shown on demand, never by default. */
|
|
32
50
|
export declare const BOOKKEEPING: ReadonlySet<string>;
|
|
51
|
+
/**
|
|
52
|
+
* What the framework writes on every record of its own: when and by whom it was made and last
|
|
53
|
+
* changed, its version, when it went to the trash. A record's audit and its activity say these;
|
|
54
|
+
* a form, a list inside a record and a record's facts never repeat them.
|
|
55
|
+
*/
|
|
56
|
+
export declare const STAMPS: ReadonlySet<string>;
|
|
57
|
+
/**
|
|
58
|
+
* How a date is written: `numeric` — «16/11/2026», «16/11/2026 15:36» — or `literal`, its month
|
|
59
|
+
* in words — «16 nov 2026, 15:36» —, where space asks for a word (a phone).
|
|
60
|
+
*
|
|
61
|
+
* Context: Sincpro's standard is numeric, day first, whatever the language: a back office reads
|
|
62
|
+
* columns of dates, and «16 nov» and «6 nov» do not line up. The month in words was the only
|
|
63
|
+
* style, chosen by `Intl` for the locale. An application installs its style once
|
|
64
|
+
* (`FrameworkProvider dateStyle`), as it installs its zone, and every cell, field, fact and
|
|
65
|
+
* `useTextOf` writes it.
|
|
66
|
+
*/
|
|
67
|
+
export type DateStyle = "numeric" | "literal";
|
|
68
|
+
/** Install how dates are written; `undefined` puts the default back (numeric). */
|
|
69
|
+
export declare function installDateStyle(style: DateStyle | undefined): void;
|
|
70
|
+
/** The style dates are written in now. */
|
|
71
|
+
export declare const dateStyleNow: () => DateStyle;
|
|
33
72
|
/**
|
|
34
73
|
* What a value reads as when a screen holds it outside any model — a total it added up, a
|
|
35
74
|
* due date of its own: the same text `textOf` gives a field of that type, in `locale`, on the
|
|
@@ -37,8 +76,8 @@ export declare const BOOKKEEPING: ReadonlySet<string>;
|
|
|
37
76
|
* to the provider's locale.
|
|
38
77
|
*
|
|
39
78
|
* numberTextOf("1150.5", "es-BO") -> "1.150,5"
|
|
40
|
-
* dayTextOf("2026-03-12", "es") -> "12
|
|
41
|
-
* instantTextOf("2026-03-12T14:00:00Z", "es") -> "12
|
|
79
|
+
* dayTextOf("2026-03-12", "es") -> "12/03/2026"
|
|
80
|
+
* instantTextOf("2026-03-12T14:00:00Z", "es") -> "12/03/2026 10:00" (La Paz)
|
|
42
81
|
* moneyTextOf({ amount: "1150.5", currency: "BOB" }, "es-BO") -> "Bs 1.150,50"
|
|
43
82
|
*
|
|
44
83
|
* Context: every application wrote its own money and date formatting for its own screens, on
|
|
@@ -52,15 +91,24 @@ export declare function instantTextOf(value: unknown, locale?: string): string |
|
|
|
52
91
|
/** A money (`{ amount, currency }`) as a person reads it, rounded to its currency's decimals;
|
|
53
92
|
* `null` when the value is not one. */
|
|
54
93
|
export declare function moneyTextOf(value: unknown, locale?: string): string | null;
|
|
94
|
+
/** Install the business's currency (`"BOB"`); `undefined` forgets it. */
|
|
95
|
+
export declare function installCurrency(code: string | undefined): void;
|
|
96
|
+
/** The business's currency now, if one was installed. */
|
|
97
|
+
export declare const currencyNow: () => string | undefined;
|
|
98
|
+
/** A definition of exactly an amount and a currency: a money, whatever the entity calls it. */
|
|
99
|
+
export declare function isMoneyDefinition(definition: Meta | null | undefined): boolean;
|
|
55
100
|
/**
|
|
56
101
|
* The text a value reads as. `null` when there is nothing to read — the caller draws its own
|
|
57
102
|
* «empty» (a dash in a fact, nothing in a cell).
|
|
58
103
|
*
|
|
59
104
|
* textOf(meta, "state", "paid", "es") -> "Pagada" (choice_labels)
|
|
60
105
|
* textOf(meta, "active", true, "es") -> "sí"
|
|
61
|
-
* textOf(meta, "due", "2026-03-12", "es") -> "12 mar 2026
|
|
106
|
+
* textOf(meta, "due", "2026-03-12", "es") -> "12/03/2026" («12 mar 2026» literal)
|
|
62
107
|
* textOf(meta, "total", "1150.5", "es") -> "1150,5" (exact: digits kept)
|
|
63
108
|
* textOf(meta, "price", { amount: "19.9", currency: "BOB" }, "es") -> "19,90 Bs"
|
|
109
|
+
* textOf(meta, "monto", "25", "es") -> "Bs 25,00" (widget money, BOB installed)
|
|
110
|
+
* textOf(meta, "recibo", {numero: "0042", …}) -> "N.º de recibo: 0042 · …"
|
|
111
|
+
* textOf(meta, "recibo.numero", "0042") -> "0042"
|
|
64
112
|
* textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
|
|
65
113
|
*/
|
|
66
114
|
export declare function textOf(meta: Meta | null | undefined, name: string, value: unknown, locale?: string): string | null;
|