@sincpro/web-framework 0.3.0 → 0.4.1
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/dist/core/cache.d.ts +10 -2
- package/dist/core/cache.js +31 -9
- package/dist/core/copy.d.ts +4 -0
- package/dist/core/copy.js +4 -0
- package/dist/core/edit.d.ts +5 -0
- package/dist/core/edit.js +6 -2
- package/dist/core/entity.d.ts +21 -2
- package/dist/core/entity.js +30 -3
- package/dist/core/history.js +5 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +2 -1
- package/dist/core/lines.d.ts +1 -2
- package/dist/core/lines.js +2 -2
- package/dist/core/present.js +7 -2
- package/dist/core/zone.d.ts +27 -0
- package/dist/core/zone.js +75 -0
- package/dist/react/context.d.ts +5 -1
- package/dist/react/context.js +10 -2
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/useCommand.js +1 -1
- package/dist/react/useListing.d.ts +1 -1
- package/dist/react/useListing.js +2 -7
- package/dist/react/useLookup.d.ts +10 -1
- package/dist/react/useLookup.js +29 -3
- package/dist/react/useRecord.d.ts +7 -2
- package/dist/react/useRecord.js +42 -20
- package/dist/web/list/rowCommands.js +2 -1
- package/dist/web/record/CommandButton.d.ts +3 -1
- package/dist/web/record/CommandButton.js +2 -2
- package/dist/web/record/EntityPicker.d.ts +15 -3
- package/dist/web/record/EntityPicker.js +35 -14
- package/dist/web/record/control.d.ts +2 -1
- package/dist/web/record/control.js +9 -2
- package/dist/web/workspace/SincproApp.d.ts +18 -4
- package/dist/web/workspace/SincproApp.js +18 -7
- package/dist/web/workspace/composer.d.ts +20 -1
- package/dist/web/workspace/composer.js +22 -9
- package/dist/web/workspace/record.js +12 -2
- package/package.json +3 -3
package/dist/core/cache.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Entity } from "./entity.js";
|
|
1
2
|
import type { Transport } from "./transport.js";
|
|
2
3
|
/**
|
|
3
4
|
* A transport that remembers what it read, for a while, and forgets it when something writes.
|
|
@@ -13,12 +14,17 @@ import type { Transport } from "./transport.js";
|
|
|
13
14
|
* different filters, orders or pages never share an answer. A read that fails is not kept.
|
|
14
15
|
* Only completed answers are remembered: a request aborted half-way is simply not cached.
|
|
15
16
|
*
|
|
17
|
+
* A write forgets every collection its route NAMES, not only the first: «leave a tenant»
|
|
18
|
+
* (`POST /users/{email}/tenants/{tenant}/leave`) changes the tenant's members as much as the
|
|
19
|
+
* user. And an entity's business events live on a route of their own (`/project-events`): with
|
|
20
|
+
* `entities`, a write under an entity's list also forgets its history.
|
|
21
|
+
*
|
|
16
22
|
* const transport = cachedTransport(restTransport({ base: "/v1" }), { ttl: 30_000 });
|
|
17
23
|
* transport.invalidate("/facturas"); // forget an entity by hand (a push from the server)
|
|
18
24
|
*/
|
|
19
25
|
export type CachedTransport = Transport & {
|
|
20
|
-
/** Forget every answer whose route
|
|
21
|
-
* every page and filter of it, and every record under it
|
|
26
|
+
/** Forget every answer whose route lies under this path: `"/facturas"` forgets the list,
|
|
27
|
+
* every page and filter of it, and every record under it — not `"/facturas-events"`. */
|
|
22
28
|
invalidate: (path?: string) => void;
|
|
23
29
|
};
|
|
24
30
|
export type CacheOptions = {
|
|
@@ -26,5 +32,7 @@ export type CacheOptions = {
|
|
|
26
32
|
ttl?: number;
|
|
27
33
|
/** The clock — for tests. */
|
|
28
34
|
now?: () => number;
|
|
35
|
+
/** The application's entities: a write to one also forgets its history route. */
|
|
36
|
+
entities?: readonly Entity[];
|
|
29
37
|
};
|
|
30
38
|
export declare function cachedTransport(transport: Transport, options?: CacheOptions): CachedTransport;
|
package/dist/core/cache.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function pathOf(route) {
|
|
2
|
+
return route.split("?")[0] ?? route;
|
|
3
|
+
}
|
|
4
|
+
/** `route` is `path` or lies under it: `"/facturas"` holds `"/facturas/F-1"`, never `"/facturas-events"`. */
|
|
5
|
+
function under(route, path) {
|
|
6
|
+
const own = pathOf(route);
|
|
7
|
+
return own === path || own.startsWith(path.endsWith("/") ? path : `${path}/`);
|
|
8
|
+
}
|
|
9
|
+
/** What a write may have changed: every segment of its route as a collection, and the history
|
|
10
|
+
* of each entity it writes under. A segment that is a key (`/F-1`) forgets nothing. */
|
|
11
|
+
function touchedBy(route, entities) {
|
|
12
|
+
const path = pathOf(route);
|
|
13
|
+
const segments = path.split("/").filter((one) => one !== "");
|
|
14
|
+
const history = entities
|
|
15
|
+
.filter((one) => one.history !== undefined && under(path, pathOf(one.list)))
|
|
16
|
+
.map((one) => pathOf(one.history?.route ?? ""));
|
|
17
|
+
return [...segments.map((one) => `/${one}`), ...history];
|
|
6
18
|
}
|
|
7
19
|
export function cachedTransport(transport, options = {}) {
|
|
8
20
|
const ttl = options.ttl ?? 30_000;
|
|
@@ -16,12 +28,22 @@ export function cachedTransport(transport, options = {}) {
|
|
|
16
28
|
entries.set(key, { at: now(), answer });
|
|
17
29
|
return answer;
|
|
18
30
|
}
|
|
31
|
+
const entities = options.entities ?? [];
|
|
32
|
+
/** Forget every answer under any of `paths` — one walk over the entries, whatever their
|
|
33
|
+
* number. A path with a query (`/projects?tenant_id=acme`) forgets its whole collection. */
|
|
34
|
+
const forget = (paths) => {
|
|
35
|
+
const targets = paths.map(pathOf);
|
|
36
|
+
for (const key of [...entries.keys()]) {
|
|
37
|
+
// `list <route> <criteria>` / `one <route>`: the route is the second word.
|
|
38
|
+
const route = key.split(" ", 2)[1] ?? "";
|
|
39
|
+
if (targets.some((path) => under(route, path)))
|
|
40
|
+
entries.delete(key);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
19
43
|
const invalidate = (path) => {
|
|
20
44
|
if (path === undefined)
|
|
21
45
|
return entries.clear();
|
|
22
|
-
|
|
23
|
-
if (key.slice(key.indexOf(" ") + 1).startsWith(path))
|
|
24
|
-
entries.delete(key);
|
|
46
|
+
forget([path]);
|
|
25
47
|
};
|
|
26
48
|
return {
|
|
27
49
|
list(route, criteria, signal) {
|
|
@@ -39,7 +61,7 @@ export function cachedTransport(transport, options = {}) {
|
|
|
39
61
|
finally {
|
|
40
62
|
// Even a refused write may have changed something (a 409 says someone else did).
|
|
41
63
|
if (!preview)
|
|
42
|
-
|
|
64
|
+
forget(touchedBy(route, entities));
|
|
43
65
|
}
|
|
44
66
|
},
|
|
45
67
|
invalidate,
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export type FrameworkCopy = {
|
|
|
59
59
|
picker: {
|
|
60
60
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
|
61
61
|
browse: string;
|
|
62
|
+
/** The choice of nothing, when a field may be left empty (`EntityPicker none`). */
|
|
63
|
+
none: string;
|
|
62
64
|
};
|
|
63
65
|
summary: {
|
|
64
66
|
/** The facts of a record's summary: when it was made and last changed. */
|
|
@@ -69,6 +71,8 @@ export type FrameworkCopy = {
|
|
|
69
71
|
/** A card's last line: «Updated 12 Mar 2026 by Ana», or «Created …» if never changed. */
|
|
70
72
|
updatedLine: (at: string, by: string | null) => string;
|
|
71
73
|
createdLine: (at: string, by: string | null) => string;
|
|
74
|
+
/** A fact of a record's history that carries no label of its own. */
|
|
75
|
+
recorded: string;
|
|
72
76
|
};
|
|
73
77
|
command: {
|
|
74
78
|
/** The confirmation of an action that cannot be undone, after its dry run. */
|
package/dist/core/copy.js
CHANGED
|
@@ -33,6 +33,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
33
33
|
},
|
|
34
34
|
picker: {
|
|
35
35
|
browse: "Search all",
|
|
36
|
+
none: "None",
|
|
36
37
|
},
|
|
37
38
|
summary: {
|
|
38
39
|
created: "Created",
|
|
@@ -40,6 +41,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
40
41
|
when: (at, by) => (by === null ? at : `${at} · ${by}`),
|
|
41
42
|
updatedLine: (at, by) => (by === null ? `Updated ${at}` : `Updated ${at} by ${by}`),
|
|
42
43
|
createdLine: (at, by) => (by === null ? `Created ${at}` : `Created ${at} by ${by}`),
|
|
44
|
+
recorded: "Change recorded",
|
|
43
45
|
},
|
|
44
46
|
command: {
|
|
45
47
|
confirm: "Do it",
|
|
@@ -101,6 +103,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
101
103
|
},
|
|
102
104
|
picker: {
|
|
103
105
|
browse: "Buscar en todos",
|
|
106
|
+
none: "Ninguno",
|
|
104
107
|
},
|
|
105
108
|
summary: {
|
|
106
109
|
created: "Creado",
|
|
@@ -108,6 +111,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
108
111
|
when: (at, by) => (by === null ? at : `${at} · ${by}`),
|
|
109
112
|
updatedLine: (at, by) => by === null ? `Actualizado el ${at}` : `Actualizado el ${at} por ${by}`,
|
|
110
113
|
createdLine: (at, by) => (by === null ? `Creado el ${at}` : `Creado el ${at} por ${by}`),
|
|
114
|
+
recorded: "Cambio registrado",
|
|
111
115
|
},
|
|
112
116
|
command: {
|
|
113
117
|
confirm: "Hacerlo",
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -68,5 +68,10 @@ export declare function defaultsOf(meta: Meta | null | undefined): AnyRecord;
|
|
|
68
68
|
* What a create sends: every value on screen the caller may write. A field the model marks
|
|
69
69
|
* `readonly` is the server's to fill (the number, the totals), and an empty one is left for
|
|
70
70
|
* the server's own default — never sent as `""`.
|
|
71
|
+
*
|
|
72
|
+
* Context: only the model's fixed `readonly` counts, never a `readonly_when`: a currency chosen
|
|
73
|
+
* and then locked by the lines added after it is still the record's currency, and a key written
|
|
74
|
+
* when creating and never after (a tenant's slug) is a `readonly_when` the backend publishes for
|
|
75
|
+
* the stored record. Both travel.
|
|
71
76
|
*/
|
|
72
77
|
export declare function creationOf(meta: Meta | null | undefined, values: AnyRecord): AnyRecord;
|
package/dist/core/edit.js
CHANGED
|
@@ -110,12 +110,16 @@ export function defaultsOf(meta) {
|
|
|
110
110
|
* What a create sends: every value on screen the caller may write. A field the model marks
|
|
111
111
|
* `readonly` is the server's to fill (the number, the totals), and an empty one is left for
|
|
112
112
|
* the server's own default — never sent as `""`.
|
|
113
|
+
*
|
|
114
|
+
* Context: only the model's fixed `readonly` counts, never a `readonly_when`: a currency chosen
|
|
115
|
+
* and then locked by the lines added after it is still the record's currency, and a key written
|
|
116
|
+
* when creating and never after (a tenant's slug) is a `readonly_when` the backend publishes for
|
|
117
|
+
* the stored record. Both travel.
|
|
113
118
|
*/
|
|
114
119
|
export function creationOf(meta, values) {
|
|
115
120
|
const sent = {};
|
|
116
121
|
for (const [name, value] of Object.entries(values)) {
|
|
117
|
-
|
|
118
|
-
if (field?.readonly === true)
|
|
122
|
+
if (meta?.fields[name]?.readonly === true)
|
|
119
123
|
continue;
|
|
120
124
|
if (value === undefined || value === null || value === "")
|
|
121
125
|
continue;
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ export type Entity<T extends AnyRecord = AnyRecord> = {
|
|
|
50
50
|
preview?: WriteRoute;
|
|
51
51
|
/** Where this caller keeps an edit between requests — sincpro_framework's `Drafts`. */
|
|
52
52
|
draft?: WriteRoute;
|
|
53
|
+
/** sincpro_framework's `Edit`: ONE route that keeps the draft, saves and discards, by its
|
|
54
|
+
* `action`. Declared, a save sends the record whole as the form holds it — not the fields
|
|
55
|
+
* that changed under `save` — and it is also where the draft is kept. */
|
|
56
|
+
edit?: WriteRoute;
|
|
53
57
|
/** Its business events: the context's events route, and the `entity_type` they carry. */
|
|
54
58
|
history?: {
|
|
55
59
|
route: string;
|
|
@@ -108,6 +112,8 @@ export type EntityRoutes = {
|
|
|
108
112
|
save?: string;
|
|
109
113
|
preview?: string;
|
|
110
114
|
draft?: string;
|
|
115
|
+
/** `"PUT /invoices/{id}/edit"`: the use case that answers sincpro_framework's `Edit`. */
|
|
116
|
+
edit?: string;
|
|
111
117
|
history?: {
|
|
112
118
|
route: string;
|
|
113
119
|
type: string;
|
|
@@ -120,6 +126,19 @@ export type EntityRoutes = {
|
|
|
120
126
|
};
|
|
121
127
|
/** `"POST /invoices/{id}/confirm"` → its method and path. A write without a method is a bug. */
|
|
122
128
|
export declare function writeRoute(text: string): WriteRoute;
|
|
123
|
-
/**
|
|
124
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The path with the record's key in place of `{id}`, and every other `{name}` taken from the
|
|
131
|
+
* body's field of that name: `POST /projects/{id}/shares/{tenant_id}/revoke` with
|
|
132
|
+
* `{ tenant_id: "acme" }`.
|
|
133
|
+
*
|
|
134
|
+
* Context: sincpro_framework reads a path parameter as a field of the use case's DTO (its
|
|
135
|
+
* wire merges `{...body, ...path_params}`), so the body already names every key a route
|
|
136
|
+
* needs — a second argument for them would say the same thing twice. A key the body lacks is
|
|
137
|
+
* the screen's bug, said before anything is sent. Without an `id`, `{id}` stays: a create or a
|
|
138
|
+
* preview of a new record has none.
|
|
139
|
+
*/
|
|
140
|
+
export declare function pathFor(route: WriteRoute, id?: string, body?: AnyRecord): string;
|
|
141
|
+
/** A list's route with its own parameters: `{ tenant_id: "acme" }` → `/projects?tenant_id=acme`.
|
|
142
|
+
* An empty value is no parameter — a filter left blank. */
|
|
143
|
+
export declare function listRoute(list: string, params?: Readonly<Record<string, string>>): string;
|
|
125
144
|
export declare function entity<T extends AnyRecord = AnyRecord>(key: string, routes: EntityRoutes): Entity<T>;
|
package/dist/core/entity.js
CHANGED
|
@@ -40,9 +40,35 @@ export function writeRoute(text) {
|
|
|
40
40
|
throw new Error(`"${text}" is not "METHOD /path": a write says how it is sent`);
|
|
41
41
|
return { method: method, path };
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const PATH_KEY = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
44
|
+
/**
|
|
45
|
+
* The path with the record's key in place of `{id}`, and every other `{name}` taken from the
|
|
46
|
+
* body's field of that name: `POST /projects/{id}/shares/{tenant_id}/revoke` with
|
|
47
|
+
* `{ tenant_id: "acme" }`.
|
|
48
|
+
*
|
|
49
|
+
* Context: sincpro_framework reads a path parameter as a field of the use case's DTO (its
|
|
50
|
+
* wire merges `{...body, ...path_params}`), so the body already names every key a route
|
|
51
|
+
* needs — a second argument for them would say the same thing twice. A key the body lacks is
|
|
52
|
+
* the screen's bug, said before anything is sent. Without an `id`, `{id}` stays: a create or a
|
|
53
|
+
* preview of a new record has none.
|
|
54
|
+
*/
|
|
55
|
+
export function pathFor(route, id, body) {
|
|
56
|
+
return route.path.replace(PATH_KEY, (whole, name) => {
|
|
57
|
+
if (name === "id")
|
|
58
|
+
return id === undefined ? whole : encodeURIComponent(id);
|
|
59
|
+
const value = body?.[name];
|
|
60
|
+
if (value === undefined || value === null || value === "")
|
|
61
|
+
throw new Error(`"${route.method} ${route.path}" needs "${name}" in the body`);
|
|
62
|
+
return encodeURIComponent(String(value));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** A list's route with its own parameters: `{ tenant_id: "acme" }` → `/projects?tenant_id=acme`.
|
|
66
|
+
* An empty value is no parameter — a filter left blank. */
|
|
67
|
+
export function listRoute(list, params) {
|
|
68
|
+
const query = new URLSearchParams(Object.entries(params ?? {}).filter(([, value]) => value !== "")).toString();
|
|
69
|
+
if (query === "")
|
|
70
|
+
return list;
|
|
71
|
+
return `${list}${list.includes("?") ? "&" : "?"}${query}`;
|
|
46
72
|
}
|
|
47
73
|
export function entity(key, routes) {
|
|
48
74
|
if (!/^[^:\s]+:[^:\s]+$/.test(key))
|
|
@@ -82,6 +108,7 @@ export function entity(key, routes) {
|
|
|
82
108
|
...(routes.save === undefined ? {} : { save: writeRoute(routes.save) }),
|
|
83
109
|
...(routes.preview === undefined ? {} : { preview: writeRoute(routes.preview) }),
|
|
84
110
|
...(routes.draft === undefined ? {} : { draft: writeRoute(routes.draft) }),
|
|
111
|
+
...(routes.edit === undefined ? {} : { edit: writeRoute(routes.edit) }),
|
|
85
112
|
...(routes.history === undefined ? {} : { history: routes.history }),
|
|
86
113
|
summary: routes.summary ?? {},
|
|
87
114
|
...(routes.aggregate === undefined ? {} : { aggregate: routes.aggregate }),
|
package/dist/core/history.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { labelOf } from "@sincpro/criteria";
|
|
2
|
+
import { frameworkCopy } from "./copy.js";
|
|
2
3
|
/** What every fact carries: what remains is what this fact says. */
|
|
3
4
|
const ENVELOPE = new Set([
|
|
4
5
|
"id",
|
|
@@ -24,7 +25,10 @@ export function historyOf(rows, meta, locale) {
|
|
|
24
25
|
const label = row["label"];
|
|
25
26
|
const word = typeof label === "string"
|
|
26
27
|
? label
|
|
27
|
-
:
|
|
28
|
+
: // A fact without a label is still a change; its id is not a word anyone reads.
|
|
29
|
+
((locale ? label?.[locale] : undefined) ??
|
|
30
|
+
label?.["default"] ??
|
|
31
|
+
frameworkCopy().summary.recorded);
|
|
28
32
|
const parts = Object.entries(row)
|
|
29
33
|
.filter(([key]) => !ENVELOPE.has(key))
|
|
30
34
|
.map(([key, value]) => [key, said(value)])
|
package/dist/core/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
8
|
export { type Advice, adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, lineStatesOf, missingOf, pathOf, type ServerFieldState, } from "./edit.js";
|
|
9
|
-
export { type Entity, entity, type EntityRef, type EntityRoutes, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
|
|
9
|
+
export { type Entity, entity, type EntityRef, type EntityRoutes, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
|
|
10
10
|
export { type FormLayout, formOf } from "./form.js";
|
|
11
11
|
export { type HistoryEntry, historyOf } from "./history.js";
|
|
12
12
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
@@ -25,3 +25,4 @@ export { completeMeta, type JsonSchema, metaFromSchema, type SchemaComponents, }
|
|
|
25
25
|
export { type RecordSummary, type SummaryFields, summaryFieldsOf, summaryOf, type SummaryPart, } from "./summary.js";
|
|
26
26
|
export { placeOf, stepIn, type Trail } from "./trail.js";
|
|
27
27
|
export { type Draft, explain, type Method, type One, type SendOptions, type Transport, TransportError, } from "./transport.js";
|
|
28
|
+
export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";
|
package/dist/core/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { cachedTransport, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
8
|
export { adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, lineStatesOf, missingOf, pathOf, } from "./edit.js";
|
|
9
|
-
export { entity, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./entity.js";
|
|
9
|
+
export { entity, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./entity.js";
|
|
10
10
|
export { formOf } from "./form.js";
|
|
11
11
|
export { historyOf } from "./history.js";
|
|
12
12
|
export { addingOf, blankLine, editableLines, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
@@ -25,3 +25,4 @@ export { completeMeta, metaFromSchema, } from "./schema.js";
|
|
|
25
25
|
export { summaryFieldsOf, summaryOf, } from "./summary.js";
|
|
26
26
|
export { placeOf, stepIn } from "./trail.js";
|
|
27
27
|
export { explain, TransportError, } from "./transport.js";
|
|
28
|
+
export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";
|
package/dist/core/lines.d.ts
CHANGED
|
@@ -29,8 +29,7 @@ export declare function lineFields(definition: Meta | null): string[];
|
|
|
29
29
|
*
|
|
30
30
|
* Context: a cell holds a control as wide as its column. A many2one is a picker only when the
|
|
31
31
|
* application declared the entity it points at — otherwise its key is an id nobody types.
|
|
32
|
-
*
|
|
33
|
-
* dialog's room.
|
|
32
|
+
* An embedded value or anything the table has no control for needs the dialog's room.
|
|
34
33
|
*/
|
|
35
34
|
export declare function writtenInCell(definition: Meta, field: string, declared: Declared): boolean;
|
|
36
35
|
/** What decides where a line is written, besides its model. */
|
package/dist/core/lines.js
CHANGED
|
@@ -74,6 +74,7 @@ const CELL_TYPES = new Set([
|
|
|
74
74
|
"integer",
|
|
75
75
|
"number",
|
|
76
76
|
"date",
|
|
77
|
+
"datetime",
|
|
77
78
|
"boolean",
|
|
78
79
|
"text[]",
|
|
79
80
|
]);
|
|
@@ -92,8 +93,7 @@ export function lineFields(definition) {
|
|
|
92
93
|
*
|
|
93
94
|
* Context: a cell holds a control as wide as its column. A many2one is a picker only when the
|
|
94
95
|
* application declared the entity it points at — otherwise its key is an id nobody types.
|
|
95
|
-
*
|
|
96
|
-
* dialog's room.
|
|
96
|
+
* An embedded value or anything the table has no control for needs the dialog's room.
|
|
97
97
|
*/
|
|
98
98
|
export function writtenInCell(definition, field, declared) {
|
|
99
99
|
const relation = relationFieldOf(definition, field);
|
package/dist/core/present.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { choiceLabelOf, labelOf, } from "@sincpro/criteria";
|
|
2
2
|
import { frameworkCopy } from "./copy.js";
|
|
3
3
|
import { relatedOf } from "./related.js";
|
|
4
|
+
import { timeZoneNow } from "./zone.js";
|
|
4
5
|
/** Present when a field is named that the model does not declare: drawn plain, never thrown. */
|
|
5
6
|
const UNKNOWN = {
|
|
6
7
|
type: "unknown",
|
|
@@ -63,10 +64,14 @@ function decimals(text) {
|
|
|
63
64
|
*/
|
|
64
65
|
const formatters = new Map();
|
|
65
66
|
function dateFormat(locale, withTime) {
|
|
66
|
-
|
|
67
|
+
// An instant reads on the wall clock of the installed zone; a calendar day has no zone.
|
|
68
|
+
const zone = withTime ? timeZoneNow() : "";
|
|
69
|
+
const key = `d|${locale ?? ""}|${withTime}|${zone}`;
|
|
67
70
|
let format = formatters.get(key);
|
|
68
71
|
if (format === undefined) {
|
|
69
|
-
format = new Intl.DateTimeFormat(locale, withTime
|
|
72
|
+
format = new Intl.DateTimeFormat(locale, withTime
|
|
73
|
+
? { dateStyle: "medium", timeStyle: "short", timeZone: zone }
|
|
74
|
+
: { dateStyle: "medium" });
|
|
70
75
|
formatters.set(key, format);
|
|
71
76
|
}
|
|
72
77
|
return format;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time zone a date and time is read and written in — and the two conversions a form needs:
|
|
3
|
+
* the server's instant to the wall clock of that zone, and back.
|
|
4
|
+
*
|
|
5
|
+
* Context: sincpro_framework sends a `datetime` as an instant (`2026-03-12T14:30:00Z`); a person
|
|
6
|
+
* reads and types the wall clock of where the business is (10:30 in La Paz). Which zone that is
|
|
7
|
+
* belongs to whoever is above the screens — the application, the company the user works in —
|
|
8
|
+
* so it is installed once, like the framework's words (`FrameworkProvider timeZone`), and every
|
|
9
|
+
* date and time follows it. Without it, the runtime's. A date with no time (`date`) is a day of
|
|
10
|
+
* the calendar, not an instant: it is never converted.
|
|
11
|
+
*/
|
|
12
|
+
/** Install the time zone dates and times are read and written in (IANA: `"America/La_Paz"`);
|
|
13
|
+
* `undefined` goes back to the runtime's. */
|
|
14
|
+
export declare function installTimeZone(timeZone: string | undefined): void;
|
|
15
|
+
/** The time zone in use. */
|
|
16
|
+
export declare function timeZoneNow(): string;
|
|
17
|
+
/** `"2026-03-12T14:30:00Z"` → `"2026-03-12T10:30"` in `America/La_Paz`: the wall clock there,
|
|
18
|
+
* as a date-and-time control reads it. `null` when it is not an instant. */
|
|
19
|
+
export declare function wallTimeOf(instant: string, timeZone: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* `"2026-03-12T10:30"` on the wall clock of `timeZone` → the instant, `"2026-03-12T14:30:00.000Z"`.
|
|
22
|
+
* `null` when it is not a wall time.
|
|
23
|
+
*
|
|
24
|
+
* Context: the offset depends on the instant (daylight saving), so it is asked twice: at the
|
|
25
|
+
* first guess, and again at the answer when the guess fell on the other side of a change.
|
|
26
|
+
*/
|
|
27
|
+
export declare function instantOf(wall: string, timeZone: string): string | null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time zone a date and time is read and written in — and the two conversions a form needs:
|
|
3
|
+
* the server's instant to the wall clock of that zone, and back.
|
|
4
|
+
*
|
|
5
|
+
* Context: sincpro_framework sends a `datetime` as an instant (`2026-03-12T14:30:00Z`); a person
|
|
6
|
+
* reads and types the wall clock of where the business is (10:30 in La Paz). Which zone that is
|
|
7
|
+
* belongs to whoever is above the screens — the application, the company the user works in —
|
|
8
|
+
* so it is installed once, like the framework's words (`FrameworkProvider timeZone`), and every
|
|
9
|
+
* date and time follows it. Without it, the runtime's. A date with no time (`date`) is a day of
|
|
10
|
+
* the calendar, not an instant: it is never converted.
|
|
11
|
+
*/
|
|
12
|
+
let installed;
|
|
13
|
+
/** Install the time zone dates and times are read and written in (IANA: `"America/La_Paz"`);
|
|
14
|
+
* `undefined` goes back to the runtime's. */
|
|
15
|
+
export function installTimeZone(timeZone) {
|
|
16
|
+
installed = timeZone;
|
|
17
|
+
}
|
|
18
|
+
/** The time zone in use. */
|
|
19
|
+
export function timeZoneNow() {
|
|
20
|
+
return installed ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
21
|
+
}
|
|
22
|
+
const clocks = new Map();
|
|
23
|
+
/** One formatter per zone, kept: building one costs far more than using it. */
|
|
24
|
+
function clockOf(timeZone) {
|
|
25
|
+
let clock = clocks.get(timeZone);
|
|
26
|
+
if (clock === undefined) {
|
|
27
|
+
clock = new Intl.DateTimeFormat("en-US", {
|
|
28
|
+
timeZone,
|
|
29
|
+
hourCycle: "h23",
|
|
30
|
+
year: "numeric",
|
|
31
|
+
month: "2-digit",
|
|
32
|
+
day: "2-digit",
|
|
33
|
+
hour: "2-digit",
|
|
34
|
+
minute: "2-digit",
|
|
35
|
+
second: "2-digit",
|
|
36
|
+
});
|
|
37
|
+
clocks.set(timeZone, clock);
|
|
38
|
+
}
|
|
39
|
+
return clock;
|
|
40
|
+
}
|
|
41
|
+
/** The wall clock of `timeZone` at `at` (ms), as the fields of a UTC date: what to compare. */
|
|
42
|
+
function wallAt(at, timeZone) {
|
|
43
|
+
const parts = Object.fromEntries(clockOf(timeZone)
|
|
44
|
+
.formatToParts(new Date(at))
|
|
45
|
+
.map((part) => [part.type, part.value]));
|
|
46
|
+
return Date.UTC(Number(parts["year"]), Number(parts["month"]) - 1, Number(parts["day"]), Number(parts["hour"]), Number(parts["minute"]), Number(parts["second"]));
|
|
47
|
+
}
|
|
48
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
49
|
+
/** `"2026-03-12T14:30:00Z"` → `"2026-03-12T10:30"` in `America/La_Paz`: the wall clock there,
|
|
50
|
+
* as a date-and-time control reads it. `null` when it is not an instant. */
|
|
51
|
+
export function wallTimeOf(instant, timeZone) {
|
|
52
|
+
const at = Date.parse(instant);
|
|
53
|
+
if (Number.isNaN(at))
|
|
54
|
+
return null;
|
|
55
|
+
const wall = new Date(wallAt(at, timeZone));
|
|
56
|
+
return (`${wall.getUTCFullYear()}-${pad(wall.getUTCMonth() + 1)}-${pad(wall.getUTCDate())}` +
|
|
57
|
+
`T${pad(wall.getUTCHours())}:${pad(wall.getUTCMinutes())}`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `"2026-03-12T10:30"` on the wall clock of `timeZone` → the instant, `"2026-03-12T14:30:00.000Z"`.
|
|
61
|
+
* `null` when it is not a wall time.
|
|
62
|
+
*
|
|
63
|
+
* Context: the offset depends on the instant (daylight saving), so it is asked twice: at the
|
|
64
|
+
* first guess, and again at the answer when the guess fell on the other side of a change.
|
|
65
|
+
*/
|
|
66
|
+
export function instantOf(wall, timeZone) {
|
|
67
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(wall);
|
|
68
|
+
if (match === null)
|
|
69
|
+
return null;
|
|
70
|
+
const [, year, month, day, hour, minute] = match.map(Number);
|
|
71
|
+
const guess = Date.UTC(year, month - 1, day, hour, minute);
|
|
72
|
+
const first = guess - (wallAt(guess, timeZone) - guess);
|
|
73
|
+
const second = guess - (wallAt(first, timeZone) - first);
|
|
74
|
+
return new Date(second).toISOString();
|
|
75
|
+
}
|
package/dist/react/context.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ type FrameworkContextValue = {
|
|
|
29
29
|
/** Where each open record came from (`Trail`), by the key its reference carries. */
|
|
30
30
|
trails: Map<string, Trail>;
|
|
31
31
|
};
|
|
32
|
-
export declare function FrameworkProvider({ transport, locale, metas: seed, entities, children, }: {
|
|
32
|
+
export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, children, }: {
|
|
33
33
|
transport: Transport;
|
|
34
34
|
/** The language labels and values are read in (`"es"`); the model's `default` without it. */
|
|
35
35
|
locale?: string;
|
|
@@ -38,6 +38,10 @@ export declare function FrameworkProvider({ transport, locale, metas: seed, enti
|
|
|
38
38
|
/** The entities of the application: a form draws a many2one as a picker of the one its
|
|
39
39
|
* model points at (`relation: "Cliente"`) without being told. */
|
|
40
40
|
entities?: readonly Entity[];
|
|
41
|
+
/** Where the business is (IANA: `"America/La_Paz"`) — the application's, or the company's
|
|
42
|
+
* the user works in: every date and time reads and is typed on its wall clock. Without it,
|
|
43
|
+
* the browser's. */
|
|
44
|
+
timeZone?: string;
|
|
41
45
|
children: ReactNode;
|
|
42
46
|
}): import("react").JSX.Element;
|
|
43
47
|
export declare function useFramework(): FrameworkContextValue;
|
package/dist/react/context.js
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { metaStore } from "../core/metas.js";
|
|
4
4
|
import { entityFor } from "../core/relation.js";
|
|
5
|
-
import {
|
|
5
|
+
import { installTimeZone } from "../core/zone.js";
|
|
6
|
+
import { createContext, useContext, useMemo, useRef, useState } from "react";
|
|
6
7
|
const FrameworkContext = createContext(null);
|
|
7
|
-
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, children, }) {
|
|
8
|
+
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, children, }) {
|
|
9
|
+
// Installed before the children draw, and again when it changes (another company): the
|
|
10
|
+
// formatters read it, so it cannot wait for an effect.
|
|
11
|
+
const zoned = useRef(null);
|
|
12
|
+
if (zoned.current !== timeZone) {
|
|
13
|
+
installTimeZone(timeZone);
|
|
14
|
+
zoned.current = timeZone;
|
|
15
|
+
}
|
|
8
16
|
// One store for the provider's life: a new seed object on a re-render must not forget what
|
|
9
17
|
// the screens already learned.
|
|
10
18
|
const [metas] = useState(() => metaStore(seed));
|
package/dist/react/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { type CommandState, type Rehearsal, useCommand, } from "./useCommand.js"
|
|
|
8
8
|
export { type Groups, useGroups } from "./useGroups.js";
|
|
9
9
|
export { useHistory } from "./useHistory.js";
|
|
10
10
|
export { type Listing, type ListingOptions, type Paging, useListing, } from "./useListing.js";
|
|
11
|
-
export { type Lookup, useLookup } from "./useLookup.js";
|
|
11
|
+
export { excluding, type Lookup, useLookup } from "./useLookup.js";
|
|
12
12
|
export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
13
13
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
14
14
|
export { useRelated } from "./useRelated.js";
|
package/dist/react/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { useCommand, } from "./useCommand.js";
|
|
|
8
8
|
export { useGroups } from "./useGroups.js";
|
|
9
9
|
export { useHistory } from "./useHistory.js";
|
|
10
10
|
export { useListing, } from "./useListing.js";
|
|
11
|
-
export { useLookup } from "./useLookup.js";
|
|
11
|
+
export { excluding, useLookup } from "./useLookup.js";
|
|
12
12
|
export { usePivot, } from "./usePivot.js";
|
|
13
13
|
export { useRecord, } from "./useRecord.js";
|
|
14
14
|
export { useRelated } from "./useRelated.js";
|
package/dist/react/useCommand.js
CHANGED
|
@@ -26,7 +26,7 @@ export function useCommand(entity, name) {
|
|
|
26
26
|
setError(null);
|
|
27
27
|
const idempotencyKey = gesture.keyFor({ id, body });
|
|
28
28
|
try {
|
|
29
|
-
const answer = await transport.send(route.method, pathFor(route, id), body, undefined, { idempotencyKey });
|
|
29
|
+
const answer = await transport.send(route.method, pathFor(route, id, body), body, undefined, { idempotencyKey });
|
|
30
30
|
gesture.settle(null);
|
|
31
31
|
return answer;
|
|
32
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type ReadingStatus, type Sort } from "@sincpro/criteria";
|
|
2
|
-
import type
|
|
2
|
+
import { type Entity } from "../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../core/list.js";
|
|
4
4
|
/**
|
|
5
5
|
* N records of an entity, live: what a list draws and the gestures that drive it.
|
package/dist/react/useListing.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { merge, resource, resumingFrom, searchOver, } from "@sincpro/criteria";
|
|
3
3
|
import { useReading } from "@sincpro/criteria-react";
|
|
4
|
+
import { listRoute } from "../core/entity.js";
|
|
4
5
|
import { isList, scopeOf } from "../core/list.js";
|
|
5
6
|
import { useFramework } from "./context.js";
|
|
6
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
8
|
/** How long typing has to pause before the search goes out. */
|
|
8
9
|
const TYPING_PAUSE = 200;
|
|
9
|
-
function routeOf(list, params) {
|
|
10
|
-
const query = new URLSearchParams(Object.entries(params ?? {}).filter(([, value]) => value !== "")).toString();
|
|
11
|
-
if (query === "")
|
|
12
|
-
return list;
|
|
13
|
-
return `${list}${list.includes("?") ? "&" : "?"}${query}`;
|
|
14
|
-
}
|
|
15
10
|
export function useListing(given, own = {}) {
|
|
16
11
|
const { transport, locale, metas } = useFramework();
|
|
17
12
|
// A named list is its entity under a fixed scope: the scope ANDs under the caller's own.
|
|
@@ -25,7 +20,7 @@ export function useListing(given, own = {}) {
|
|
|
25
20
|
? scopeOf(definition)
|
|
26
21
|
: merge(scopeOf(definition), own.criteria),
|
|
27
22
|
};
|
|
28
|
-
const route =
|
|
23
|
+
const route = listRoute(entity.list, options.params);
|
|
29
24
|
const source = useMemo(() => resource((criteria, signal) => transport.list(route, criteria, signal)), [transport, route]);
|
|
30
25
|
// Decided once, at mount: a definition already known means the server is not asked for it
|
|
31
26
|
// again. Deciding it later would change the criteria and restart the reading.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyRecord, type Criteria, type Meta } from "@sincpro/criteria";
|
|
2
2
|
import type { Entity } from "../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../core/list.js";
|
|
4
4
|
import { type LookupOption } from "../core/lookup.js";
|
|
@@ -14,6 +14,11 @@ import { type LookupOption } from "../core/lookup.js";
|
|
|
14
14
|
* The chosen record usually is NOT on the page on screen — a search narrowed it, or it lies
|
|
15
15
|
* past the first ten — so its name is kept: from the options it was seen among, or asked of
|
|
16
16
|
* the server once by its key (`chosen`).
|
|
17
|
+
*
|
|
18
|
+
* `exclude` leaves keys out of the choices — the tenants a project is already shared with — and
|
|
19
|
+
* the SERVER leaves them out (`not in` under `criteria`), so the ten are ten that may be chosen.
|
|
20
|
+
* It needs the entity's key field: until its definition is known the first ten come
|
|
21
|
+
* unexcluded, and the reading starts over when it arrives.
|
|
17
22
|
*/
|
|
18
23
|
export type Lookup = {
|
|
19
24
|
options: LookupOption[];
|
|
@@ -31,6 +36,8 @@ export type Lookup = {
|
|
|
31
36
|
* not known yet are asked of the server in one question. */
|
|
32
37
|
chosenAll: LookupOption[];
|
|
33
38
|
};
|
|
39
|
+
/** What may be chosen: the screen's own cut, without the keys it excludes. */
|
|
40
|
+
export declare function excluding<T extends AnyRecord>(criteria: Criteria<T> | undefined, exclude: readonly string[] | undefined, meta: Meta | null | undefined): Criteria<T> | undefined;
|
|
34
41
|
export declare function useLookup<T extends AnyRecord>(
|
|
35
42
|
/** The entity, or a named list of it: «active customers» chooses only those. */
|
|
36
43
|
entity: Entity<T> | ListDefinition<T>, options?: {
|
|
@@ -44,4 +51,6 @@ entity: Entity<T> | ListDefinition<T>, options?: {
|
|
|
44
51
|
value?: string;
|
|
45
52
|
/** The keys chosen in a many2many, to keep their names (`chosenAll`). */
|
|
46
53
|
values?: readonly string[];
|
|
54
|
+
/** Keys never offered — those already chosen elsewhere. Left out by the server. */
|
|
55
|
+
exclude?: readonly string[];
|
|
47
56
|
}): Lookup;
|