@sincpro/web-framework 3.10.0 → 3.12.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.
@@ -0,0 +1,170 @@
1
+ import { outcomeOf } from "@sincpro/client-framework";
2
+ import { narrowed } from "./narrowed.js";
3
+ const HELD = Symbol.for("@sincpro/web-framework/errors/server");
4
+ const WHO = "@sincpro/web-framework/errors/server";
5
+ function held() {
6
+ const global = globalThis;
7
+ return (global[HELD] ??= {});
8
+ }
9
+ /**
10
+ * The process's error reporting: a Sentry-compatible client — GlitchTip — with the application's
11
+ * DSN, kept for every realm. Once per process: a second call, from any realm, answers the
12
+ * first's. It answers `undefined` when reporting stays off — no DSN, or the SDK did not load.
13
+ */
14
+ export function registerServerErrors(options) {
15
+ const dsn = options.dsn;
16
+ if (!dsn)
17
+ return Promise.resolve(undefined);
18
+ const shared = held();
19
+ shared.registered ??= started({ ...options, dsn });
20
+ return shared.registered;
21
+ }
22
+ /** A transport over `fetch` — Node 18+, an edge runtime, Bun: whatever the server runs on. */
23
+ function overFetch(transportOver) {
24
+ return (transportOptions) => transportOver(transportOptions, async (request) => {
25
+ const response = await fetch(transportOptions.url, {
26
+ method: "POST",
27
+ body: request.body,
28
+ ...(transportOptions.headers ? { headers: transportOptions.headers } : {}),
29
+ });
30
+ return {
31
+ statusCode: response.status,
32
+ headers: {
33
+ "x-sentry-rate-limits": response.headers.get("X-Sentry-Rate-Limits"),
34
+ "retry-after": response.headers.get("Retry-After"),
35
+ },
36
+ };
37
+ });
38
+ }
39
+ /**
40
+ * Each frame where it was in the source — `app/cursos/page.tsx:12:7`, not a built bundle's
41
+ * `page.js:1:4313` —, when the built file has a source map Node loaded (the server built with
42
+ * its source maps, Node run with `--enable-source-maps`). An SSR framework may print its stacks
43
+ * mapped and still hand over an error whose `stack` is not (Next replaces Node's formatter): the
44
+ * report is mapped here, with nothing uploaded anywhere.
45
+ */
46
+ function readable(event, findSourceMap) {
47
+ if (findSourceMap === undefined)
48
+ return event;
49
+ const exception = event["exception"];
50
+ for (const value of exception?.values ?? []) {
51
+ for (const frame of value.stacktrace?.frames ?? []) {
52
+ const file = (frame.abs_path ?? frame.filename)?.replace(/^file:\/\//, "");
53
+ if (!file || frame.lineno === undefined || frame.colno === undefined)
54
+ continue;
55
+ let origin;
56
+ try {
57
+ origin = findSourceMap(file)?.findOrigin(frame.lineno, frame.colno);
58
+ }
59
+ catch {
60
+ continue;
61
+ }
62
+ if (!origin?.fileName || origin.lineNumber === undefined)
63
+ continue;
64
+ frame.filename = origin.fileName;
65
+ frame.abs_path = origin.fileName;
66
+ frame.lineno = origin.lineNumber;
67
+ if (origin.columnNumber !== undefined)
68
+ frame.colno = origin.columnNumber;
69
+ frame.in_app = !origin.fileName.includes("node_modules");
70
+ }
71
+ }
72
+ return event;
73
+ }
74
+ async function started(options) {
75
+ try {
76
+ const [core, { ServerRuntimeClient, nodeStackLineParser }, { sentryReporter }] = await Promise.all([
77
+ import("@sentry/core"),
78
+ import("@sentry/core/server"),
79
+ import("@sincpro/client-framework/sentry"),
80
+ ]);
81
+ const runtime = globalThis.process?.version;
82
+ // An edge runtime has no `node:module`: its frames stay as they are.
83
+ // A bundler may hand a builtin over as its `default` (webpack does).
84
+ const findSourceMap = await import("node:module").then((module) => (module.findSourceMap ??
85
+ module.default
86
+ ?.findSourceMap), () => undefined);
87
+ const client = new ServerRuntimeClient({
88
+ dsn: options.dsn,
89
+ transport: overFetch(core.createTransport),
90
+ stackParser: core.createStackParser(nodeStackLineParser()),
91
+ integrations: [],
92
+ platform: "node",
93
+ runtime: { name: "node", ...(runtime ? { version: runtime } : {}) },
94
+ ...(options.release ? { release: options.release } : {}),
95
+ ...(options.environment ? { environment: options.environment } : {}),
96
+ ...(options.sampling === undefined ? {} : { sampleRate: options.sampling }),
97
+ beforeSend: (event) => {
98
+ const own = narrowed(readable(event, findSourceMap));
99
+ const kept = options.beforeSend ? options.beforeSend(own) : own;
100
+ return kept;
101
+ },
102
+ });
103
+ client.init();
104
+ const shared = held();
105
+ shared.client = client;
106
+ shared.reporter = sentryReporter(client);
107
+ shared.spans = await import("@opentelemetry/api").then(({ trace }) => trace, () => undefined);
108
+ return {
109
+ flush: async (timeoutMs) => client.flush(timeoutMs),
110
+ close: async (timeoutMs) => client.close(timeoutMs),
111
+ };
112
+ }
113
+ catch (error) {
114
+ console.warn(`${WHO}: error reporting is off — @sentry/core did not load`, error);
115
+ return undefined;
116
+ }
117
+ }
118
+ /**
119
+ * An `ErrorReporter` over the process's client — what `configureServerProcess({ reporter })`
120
+ * plugs, so a use case that fails unexpectedly on the server is reported with its trace, as
121
+ * the browser's are. Before `registerServerErrors` (or without a DSN) it reports nothing.
122
+ */
123
+ export function serverReporter() {
124
+ return { report: (error, about) => held().reporter?.report(error, about) };
125
+ }
126
+ function digestOf(error) {
127
+ if (typeof error !== "object" || error === null || !("digest" in error))
128
+ return undefined;
129
+ const digest = error.digest;
130
+ return typeof digest === "string" && digest !== "" ? digest : undefined;
131
+ }
132
+ /**
133
+ * A request that failed on the server — a page that broke while drawing —, reported with what
134
+ * finds it again: its `digest`, its route, its method and path (without the query), and
135
+ * the trace it failed in. What the server already explained (a refusal, a cancellation) is not
136
+ * a fault and is not reported. One error handed over twice (two phases of one render) is one
137
+ * event: the client marks what it captured. Before `registerServerErrors` (or without a DSN) it
138
+ * does nothing.
139
+ */
140
+ export function reportRequestError(error, request = {}) {
141
+ const shared = held();
142
+ const client = shared.client;
143
+ if (client === undefined)
144
+ return;
145
+ try {
146
+ if (outcomeOf(error) !== "failed")
147
+ return;
148
+ }
149
+ catch {
150
+ // An outcome that cannot be told is a failure.
151
+ }
152
+ const digest = request.digest ?? digestOf(error);
153
+ const path = request.path?.split("?")[0];
154
+ const span = shared.spans?.getActiveSpan()?.spanContext();
155
+ client.captureException(error, {
156
+ captureContext: {
157
+ tags: {
158
+ "sincpro.layer": "request",
159
+ ...(digest ? { digest } : {}),
160
+ ...(request.route ? { route: request.route } : {}),
161
+ ...(request.method ? { "http.method": request.method } : {}),
162
+ ...(path ? { "url.path": path } : {}),
163
+ ...(span ? { trace_id: span.traceId } : {}),
164
+ },
165
+ ...(span
166
+ ? { contexts: { trace: { trace_id: span.traceId, span_id: span.spanId } } }
167
+ : {}),
168
+ },
169
+ });
170
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What nobody caught in the browser — an error thrown in an event handler outside a use case, a
3
+ * promise nobody waited for —, reported through the process's reporter like everything else:
4
+ *
5
+ * configureProcess({ identity: { release }, reporter: glitchtipReporter({ dsn, release }) });
6
+ * reportUncaught(); // entrypoints/main.tsx, opt-in
7
+ *
8
+ * Context: it listens to `window`'s `error` and `unhandledrejection` and hands each over to
9
+ * client-framework's `reportError`, so the process's rules apply: whichever reporter it has
10
+ * (GlitchTip or another), a cancellation or a refusal the server explained is not a fault, and
11
+ * an error already reported — a use case's, the one that also went unhandled — is not reported
12
+ * again. A script of another origin says only «Script error.», with nothing to find it by: it
13
+ * is skipped, as is anything thrown without an error. On the server there is no `window` and it
14
+ * does nothing. Called again, it answers the same stop; nothing else is registered.
15
+ */
16
+ export declare function reportUncaught(): () => void;
@@ -0,0 +1,41 @@
1
+ import { reportError } from "@sincpro/client-framework";
2
+ /**
3
+ * What nobody caught in the browser — an error thrown in an event handler outside a use case, a
4
+ * promise nobody waited for —, reported through the process's reporter like everything else:
5
+ *
6
+ * configureProcess({ identity: { release }, reporter: glitchtipReporter({ dsn, release }) });
7
+ * reportUncaught(); // entrypoints/main.tsx, opt-in
8
+ *
9
+ * Context: it listens to `window`'s `error` and `unhandledrejection` and hands each over to
10
+ * client-framework's `reportError`, so the process's rules apply: whichever reporter it has
11
+ * (GlitchTip or another), a cancellation or a refusal the server explained is not a fault, and
12
+ * an error already reported — a use case's, the one that also went unhandled — is not reported
13
+ * again. A script of another origin says only «Script error.», with nothing to find it by: it
14
+ * is skipped, as is anything thrown without an error. On the server there is no `window` and it
15
+ * does nothing. Called again, it answers the same stop; nothing else is registered.
16
+ */
17
+ export function reportUncaught() {
18
+ const target = globalThis.window;
19
+ if (target === undefined)
20
+ return () => undefined;
21
+ return (listening ??= listen(target));
22
+ }
23
+ let listening;
24
+ function listen(target) {
25
+ const onError = (event) => {
26
+ const error = event.error;
27
+ if (error === undefined || error === null)
28
+ return;
29
+ reportError(error, "uncaught error");
30
+ };
31
+ const onRejection = (event) => {
32
+ reportError(event.reason, "unhandled rejection");
33
+ };
34
+ target.addEventListener("error", onError);
35
+ target.addEventListener("unhandledrejection", onRejection);
36
+ return () => {
37
+ target.removeEventListener("error", onError);
38
+ target.removeEventListener("unhandledrejection", onRejection);
39
+ listening = undefined;
40
+ };
41
+ }
@@ -1,6 +1,7 @@
1
1
  import { type Draft, type Entity, type ResourceRef } from "@sincpro/client-framework";
2
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
3
3
  import { type Advice, type FieldState } from "../core/edit.js";
4
+ import type { RecordRead } from "../core/server.js";
4
5
  /**
5
6
  * ONE record of an entity, with the definition of its model — read, and edited.
6
7
  *
@@ -36,9 +37,18 @@ import { type Advice, type FieldState } from "../core/edit.js";
36
37
  * that key — a retry names the same record, never a second one — and the hook becomes it.
37
38
  * Its `id` stays `""` until it is stored: until then it does not exist.
38
39
  *
40
+ * - **read on the server** — a page rendered on a server hands it what `readRecordOnServer`
41
+ * read there (`initial`): the hook starts `ready` with it — the screen is filled in the HTML,
42
+ * not a skeleton — and its model goes into the provider's `metas`; in the browser nothing is
43
+ * asked on mount. Only for the record it was read for (the entity's key and the id it opens
44
+ * with), and only when it mounts, as `useState`'s first value: another record afterwards, a
45
+ * `reload()`, a write or another company read as always, and editing, previews, drafts,
46
+ * conflicts and saving are the browser's, the same as without it.
47
+ *
39
48
  * const invoice = useRecord(invoices, ""); // a new one
40
49
  * const invoice = useRecord(invoices, "F-2026-7"); // an existing one
41
50
  * const invoice = useRecord(invoices, resource); // what the workspace opened
51
+ * const invoice = useRecord(invoices, id, { initial }); // what the server already read
42
52
  */
43
53
  export type RecordState<T> = {
44
54
  status: "loading";
@@ -104,4 +114,8 @@ export type RecordReading<T> = RecordState<T> & {
104
114
  reload: () => void;
105
115
  edit: Editing;
106
116
  };
107
- export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string | ResourceRef): RecordReading<T>;
117
+ export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string | ResourceRef, options?: {
118
+ /** The record and its model already read on the server that renders the screen
119
+ * (`readRecordOnServer`): the hook starts from it when it mounts on that same record. */
120
+ initial?: RecordRead<T> | undefined;
121
+ }): RecordReading<T>;
@@ -7,12 +7,36 @@ import { useWrites } from "./useWrites.js";
7
7
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
8
  /** How long typing has to pause before the server is asked what the record becomes. */
9
9
  const PREVIEW_PAUSE = 300;
10
- export function useRecord(entity, opened) {
10
+ export function useRecord(entity, opened, options = {}) {
11
11
  const { transport, locale, metas, context } = useFramework();
12
12
  const given = typeof opened === "string" ? opened : (opened.id ?? "");
13
13
  // As written in the reference: a text compares by value, so a new render with the same
14
14
  // reference is not a new start.
15
15
  const start = typeof opened === "string" ? undefined : opened.params?.[WITH_PARAM];
16
+ // What the server read, when it is THIS record — the entity and the id it opens with, a stored
17
+ // one with its record. Read only by the first render's initial values: an `initial` that
18
+ // arrives later, or one read for another record, is never shown.
19
+ const initial = options.initial;
20
+ const served = initial !== undefined &&
21
+ initial.entity === entity.key &&
22
+ initial.id === given &&
23
+ (given === "" || initial.record !== null)
24
+ ? initial
25
+ : undefined;
26
+ /** The state a read answered with: the record (a new one from its model's defaults and what
27
+ * its reference carries), its model — the same the effect below sets. */
28
+ const startedFrom = (read) => {
29
+ if (read.meta)
30
+ metas.set(entity.key, read.meta);
31
+ const meta = read.meta ?? metas.get(entity.key) ?? null;
32
+ const starting = start === undefined ? {} : startingValuesOf({ params: { [WITH_PARAM]: start } });
33
+ return {
34
+ status: "ready",
35
+ record: read.id === "" ? { ...defaultsOf(meta), ...starting } : read.record,
36
+ meta,
37
+ error: null,
38
+ };
39
+ };
16
40
  // A create that answered its identity turns this into that record — until the screen asks
17
41
  // for another one.
18
42
  const [born, setBorn] = useState(null);
@@ -23,17 +47,21 @@ export function useRecord(entity, opened) {
23
47
  // The key a new record is born under when it is created by `Edit`: minted once per new
24
48
  // record, on the first gesture that needs it, and kept for every draft save and the save.
25
49
  const minted = useRef(null);
26
- const [state, setState] = useState({
27
- status: "loading",
28
- record: null,
29
- meta: null,
30
- error: null,
31
- });
50
+ const [state, setState] = useState(() => served === undefined
51
+ ? { status: "loading", record: null, meta: null, error: null }
52
+ : startedFrom(served));
32
53
  // Which record `state` was read for: the render after the id changed — a create that answered,
33
54
  // another record asked — must not show the previous one under the new id.
34
- const [readFor, setReadFor] = useState(null);
55
+ const [readFor, setReadFor] = useState(served === undefined ? null : given);
35
56
  const [round, setRound] = useState(0);
36
- const [typed, setTyped] = useState({});
57
+ // The question the server already answered, as the read below asks it (its dependencies, in
58
+ // their order): on mount it is not asked again — nor in React's second mount of the same
59
+ // question (StrictMode). Any other question (a `reload()`, another id, another transport)
60
+ // reads as always.
61
+ const answered = useRef(served === undefined ? null : [transport, metas, entity, given, given === "", start, 0]);
62
+ // A server that answers the record FROM the draft (sincpro_framework) sends no values apart:
63
+ // the record is the draft. One that sends them apart, they are what was typed.
64
+ const [typed, setTyped] = useState(() => served?.draft?.values ?? {});
37
65
  const typedNow = useRef(typed);
38
66
  typedNow.current = typed;
39
67
  const [computed, setComputed] = useState({});
@@ -42,7 +70,7 @@ export function useRecord(entity, opened) {
42
70
  const [saving, setSaving] = useState(false);
43
71
  const [failure, setFailure] = useState(null);
44
72
  const [conflict, setConflict] = useState(false);
45
- const [draft, setDraft] = useState(null);
73
+ const [draft, setDraft] = useState(served?.draft ?? null);
46
74
  const pause = useRef(null);
47
75
  // The preview in flight. A newer one cancels it, and so do a save, a discard and leaving:
48
76
  // an answer about values that are no longer on screen must never land on them.
@@ -64,6 +92,12 @@ export function useRecord(entity, opened) {
64
92
  setConflict(false);
65
93
  };
66
94
  useEffect(() => {
95
+ // The server's question (`initial`) is answered already: nothing to read.
96
+ const asked = [transport, metas, entity, id, isNew, start, round];
97
+ const before = answered.current;
98
+ if (before !== null && asked.every((one, at) => Object.is(one, before[at])))
99
+ return;
100
+ answered.current = null;
67
101
  const aborter = new AbortController();
68
102
  // Read again — after a save, a reload — the record on screen STAYS until the answer: a form
69
103
  // that blinked through a skeleton lost its focus, its scroll and the click that landed then.
@@ -6,7 +6,7 @@ import { type Attributes, type Tracer } from "@sincpro/client-framework";
6
6
  * // the application — domains/common/infrastructure/telemetry.ts
7
7
  * import { browserTracer } from "./index.js";
8
8
  * const release = "forge-web:1.4.0"; // the backend's APP_RELEASE
9
- * const tracer = browserTracer({ endpoint: settings.otlp, release });
9
+ * const tracer = browserTracer({ endpoint: settings.otlp, release, recordExceptions: false });
10
10
  * configureProcess({ identity: { release }, tracer, reporter }); // entrypoints/main.tsx
11
11
  *
12
12
  * Context: optional on every count. It is an entry of its own that nothing else in this package
@@ -42,6 +42,15 @@ export type BrowserTracerOptions = {
42
42
  sampling?: number;
43
43
  /** More resource attributes (`tenant.group`, …). */
44
44
  attributes?: Attributes;
45
+ /**
46
+ * Whether a failed use case's span carries its exception — type, message and stack — or only
47
+ * that it failed (`error.type`, `sincpro.outcome`, an ERROR status). `false` where errors go to
48
+ * an error tracker (`@sincpro/web-framework/errors`): the detail is there already, with the
49
+ * trace's id, under that tool's access; copied into every span it also reaches whatever stores
50
+ * traces, and in an ERP a failure's message can name a customer or an amount. Default `true`,
51
+ * as client-framework's (`openTelemetryTracer`'s `recordExceptions`, 2.6+; older ignore it).
52
+ */
53
+ recordExceptions?: boolean;
45
54
  };
46
55
  export type BrowserTracer = Tracer & {
47
56
  /** Sends what is buffered now. Called by itself when the page is hidden or left. */
@@ -44,7 +44,9 @@ export function browserTracer(options) {
44
44
  }),
45
45
  spanProcessors: [new BatchSpanProcessor({ exporter })],
46
46
  });
47
- ready = openTelemetryTracer(provider.getTracer(String(resource["service.name"])));
47
+ ready = openTelemetryTracer(provider.getTracer(String(resource["service.name"])), options.recordExceptions === undefined
48
+ ? {}
49
+ : { recordExceptions: options.recordExceptions });
48
50
  flush = () => provider.forceFlush();
49
51
  // A page that is hidden may never come back: what is buffered goes now.
50
52
  const leave = () => void flush().catch(() => undefined);
@@ -26,7 +26,7 @@ import { type Attributes, type ProcessOptions, type Tracer } from "@sincpro/clie
26
26
  *
27
27
  * Optional on every count, like `./telemetry`: an entry of its own that nothing else imports,
28
28
  * the same optional peers (`@opentelemetry/api`, `@opentelemetry/sdk-trace`,
29
- * `@opentelemetry/exporter-trace-otlp-http`, `@opentelemetry/resources`, and
29
+ * `@opentelemetry/exporter-trace-otlp-http`, `@opentelemetry/resources`, `@opentelemetry/core`, and
30
30
  * `@opentelemetry/context-async-hooks` for `oneTreePerRequest`) loaded with `import()`,
31
31
  * and nothing throws: without an endpoint nothing loads and nothing is registered; if the SDK
32
32
  * is not installed or fails, that is said once on the console and use cases run untraced,
@@ -62,6 +62,15 @@ export type ServerTracingOptions = {
62
62
  * said once and the rest works as without it.
63
63
  */
64
64
  oneTreePerRequest?: boolean;
65
+ /**
66
+ * Whether a failed use case's span carries its exception — type, message and stack — or only
67
+ * that it failed (`error.type`, `sincpro.outcome`, an ERROR status). `false` where errors go to
68
+ * an error tracker (`@sincpro/web-framework/errors`): the detail is there already, with the
69
+ * trace's id, under that tool's access; copied into every span it also reaches whatever stores
70
+ * traces, and in an ERP a failure's message can name a customer or an amount. Default `true`,
71
+ * as client-framework's (`openTelemetryTracer`'s `recordExceptions`, 2.6+; older ignore it).
72
+ */
73
+ recordExceptions?: boolean;
65
74
  };
66
75
  /** The process's tracing, once registered. */
67
76
  export type ServerTracing = {
@@ -22,15 +22,21 @@ export function registerServerTracing(options) {
22
22
  if (shared.registered === undefined) {
23
23
  // Before the first page: every realm's tracer reads it when it is first asked for.
24
24
  shared.adoptActiveSpan = options.oneTreePerRequest === true;
25
+ if (options.recordExceptions !== undefined)
26
+ shared.recordExceptions = options.recordExceptions;
25
27
  shared.registered = started({ ...options, endpoint });
26
28
  }
27
29
  return shared.registered;
28
30
  }
29
31
  /** A tracer of client-framework's over OpenTelemetry's, as this process's registration asked. */
30
32
  function tracerOver(trace, overOpenTelemetry) {
31
- return (name) => overOpenTelemetry(trace.getTracer(name), {
32
- adoptActiveSpan: held().adoptActiveSpan === true,
33
- });
33
+ return (name) => {
34
+ const { adoptActiveSpan, recordExceptions } = held();
35
+ return overOpenTelemetry(trace.getTracer(name), {
36
+ adoptActiveSpan: adoptActiveSpan === true,
37
+ ...(recordExceptions === undefined ? {} : { recordExceptions }),
38
+ });
39
+ };
34
40
  }
35
41
  /**
36
42
  * What is active follows each request through its awaits: Node's AsyncLocalStorage, registered
@@ -53,13 +59,19 @@ async function followEachRequest() {
53
59
  }
54
60
  async function started(options) {
55
61
  try {
56
- const [{ trace }, { TracerProvider, BatchSpanProcessor, TraceIdRatioBasedSampler, ParentBasedSampler }, { OTLPTraceExporter }, { resourceFromAttributes }, { openTelemetryTracer },] = await Promise.all([
62
+ const [{ trace, propagation }, { TracerProvider, BatchSpanProcessor, TraceIdRatioBasedSampler, ParentBasedSampler }, { OTLPTraceExporter }, { resourceFromAttributes }, { W3CTraceContextPropagator }, { openTelemetryTracer },] = await Promise.all([
57
63
  import("@opentelemetry/api"),
58
64
  import("@opentelemetry/sdk-trace"),
59
65
  import("@opentelemetry/exporter-trace-otlp-http"),
60
66
  import("@opentelemetry/resources"),
67
+ import("@opentelemetry/core"),
61
68
  import("@sincpro/client-framework/opentelemetry"),
62
69
  ]);
70
+ // An SSR framework reads and writes `traceparent` only through the global propagator: with
71
+ // it Next continues a request's incoming trace and can write it into the page
72
+ // (`experimental.clientTraceMetadata`); without one, both are silently nothing. W3C trace
73
+ // context only — no baggage —, unless the platform registered a propagator first.
74
+ propagation.setGlobalPropagator(new W3CTraceContextPropagator());
63
75
  if (options.oneTreePerRequest === true)
64
76
  await followEachRequest();
65
77
  const exporter = new OTLPTraceExporter({
@@ -5,12 +5,12 @@ export { attachmentOf } from "./files.js";
5
5
  export { BatchProgress } from "./list/BatchProgress.js";
6
6
  export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
7
7
  export { actionsOf, type ScreenActions } from "./list/dock.js";
8
- export { type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
8
+ export { type EntityEmpty, type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
9
9
  export { EntitySearchBar } from "./list/EntitySearchBar.js";
10
10
  export { groupableOf, pilesOf } from "./list/groups.js";
11
11
  export { OpenInMenu } from "./list/openIn.js";
12
12
  export { pivotOf } from "./list/pivot.js";
13
- export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, tonesOver, } from "./list/presentation.js";
13
+ export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, type TileLook, tonesOver, } from "./list/presentation.js";
14
14
  export { type Choice, type Chooser, findChoices, type FrameworkReads, modelLoader, recordsBrowser, RecordsBrowserProvider, recordsSearch, refusalNotice, useLoadModel, useRecordsBrowser, useSearchRecords, } from "./list/records.js";
15
15
  export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
16
16
  export { facetsOf, modelOf } from "./list/search.js";
@@ -6,7 +6,7 @@ import type { Listing } from "../../react/useListing.js";
6
6
  import { type ListSelection } from "../../react/useSelection.js";
7
7
  import { type ScreenActions } from "./dock.js";
8
8
  import { type RowCommand } from "./rowCommands.js";
9
- import { type ListCrumb, type ListPresentProps, type ListSet, type OpenTarget, type RowAction, type YesNoColumn } from "@sincpro/web-ui";
9
+ import { type ListCrumb, type ListEmpty, type ListPresentProps, type ListSet, type OpenTarget, type RowAction, type YesNoColumn } from "@sincpro/web-ui";
10
10
  import { type ReactNode } from "react";
11
11
  /**
12
12
  * A whole collection from a `Listing`: the bar, the search, the set in the views it offers,
@@ -53,10 +53,12 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
53
53
  yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>>;
54
54
  /**
55
55
  * The ways to look at the set, the first one shown: `table` (columns), `rows` (a name and
56
- * its facts, what a narrow panel wants), `board` (cards) and `sheet` (a spreadsheet, every
57
- * cell a value — web-ui's, windowed). The same set, the same search, the same page in each.
58
- * Without it, a named list's; else all four on a screen, and the table (rows when narrow)
59
- * inside a record. The id of one of `faces` opens on that face.
56
+ * its facts, what a narrow panel wants), `board` (cards), `sheet` (a spreadsheet, every
57
+ * cell a value — web-ui's, windowed) and `tiles` (a grid of pictures — a till's products, a
58
+ * shop's items; asked for, never offered by itself: a set of invoices has no picture). The
59
+ * same set, the same search, the same page in each. Without it, a named list's; else the
60
+ * first four on a screen, and the table (rows when narrow) inside a record. The id of one
61
+ * of `faces` opens on that face.
60
62
  */
61
63
  views?: readonly (View | (string & {}))[];
62
64
  /**
@@ -91,14 +93,27 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
91
93
  openTargets?: readonly OpenTarget[];
92
94
  /** Open a row's record there — without `api`, how a screen (a one2many) places it. */
93
95
  onOpenIn?: (row: T, to: OpenTarget) => void;
94
- /** What an empty list says. */
95
- empty?: string;
96
+ /**
97
+ * What an empty list says. A text is its sentence; an object is web-ui's empty (2.14) — a
98
+ * `title`, an `icon` or the application's `illustration`, an `action` — for a list that IS the
99
+ * screen («Todavía no hay facturas» with a button to create one). What it leaves out is the
100
+ * framework's words, and `whenFiltered` is what it says when a search emptied it.
101
+ */
102
+ empty?: string | EntityEmpty;
96
103
  /**
97
104
  * `"bar"` (the default) is the full search bar with the criteria builder; `"box"` is one
98
105
  * text box over the entity's search template — a chooser, a narrow panel; `false` is none.
99
106
  * Both ask the server on Enter, never per keystroke: a table is searched on purpose.
100
107
  */
101
108
  search?: "bar" | "box" | false;
109
+ /**
110
+ * The bar remembers, in this browser, the last searches put on this list, and offers them
111
+ * when it takes the focus empty («Recientes»). `true` keeps them under the list's key (a
112
+ * named list's, else its entity's); a text, under that name — one per tenant, say. Off by
113
+ * default: what was searched may name a customer, and whether a browser may keep it is the
114
+ * application's call.
115
+ */
116
+ recent?: boolean | string;
102
117
  /** What each group adds up when the list is grouped — «Total 1.204.933,00» in its header,
103
118
  * summed by the server over every row of it. Without it, the figures the model computes
104
119
  * (read-only exact numbers, `sumsOf`); `false` adds nothing up. */
@@ -157,5 +172,12 @@ export type EntityFace<T> = {
157
172
  wide?: boolean;
158
173
  render: (set: ListSet<T>) => ReactNode;
159
174
  };
160
- export type View = "table" | "rows" | "board" | "sheet" | "pivot";
161
- export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
175
+ /** An empty list as web-ui draws it (`ListEmpty`), every sentence optional: the copy's words. */
176
+ export type EntityEmpty = Omit<ListEmpty, "sentence" | "whenFiltered"> & {
177
+ sentence?: string;
178
+ whenFiltered?: Omit<NonNullable<ListEmpty["whenFiltered"]>, "sentence"> & {
179
+ sentence?: string;
180
+ };
181
+ };
182
+ export type View = "table" | "rows" | "board" | "tiles" | "sheet" | "pivot";
183
+ export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, recent: askedRecent, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;