@sincpro/web-framework 1.0.0 → 2.0.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.
Files changed (104) hide show
  1. package/README.md +207 -71
  2. package/dist/core/cache.d.ts +1 -2
  3. package/dist/core/cache.js +14 -4
  4. package/dist/core/explain.d.ts +15 -0
  5. package/dist/core/{transport.js → explain.js} +4 -17
  6. package/dist/core/form.d.ts +1 -1
  7. package/dist/core/form.js +1 -0
  8. package/dist/core/index.d.ts +9 -14
  9. package/dist/core/index.js +8 -13
  10. package/dist/core/list.d.ts +5 -4
  11. package/dist/core/list.js +1 -0
  12. package/dist/core/lookup.d.ts +1 -1
  13. package/dist/core/lookup.js +1 -0
  14. package/dist/core/present.js +1 -1
  15. package/dist/core/relation.d.ts +12 -2
  16. package/dist/core/relation.js +30 -2
  17. package/dist/core/summary.d.ts +1 -6
  18. package/dist/core/trail.d.ts +1 -1
  19. package/dist/core/trail.js +1 -0
  20. package/dist/errors/index.d.ts +48 -0
  21. package/dist/errors/index.js +56 -0
  22. package/dist/react/context.d.ts +1 -3
  23. package/dist/react/context.js +1 -2
  24. package/dist/react/index.d.ts +4 -1
  25. package/dist/react/index.js +3 -0
  26. package/dist/react/scope.d.ts +1 -1
  27. package/dist/react/scope.js +1 -1
  28. package/dist/react/useCommand.d.ts +15 -5
  29. package/dist/react/useCommand.js +7 -5
  30. package/dist/react/useContextValues.d.ts +15 -0
  31. package/dist/react/useContextValues.js +19 -0
  32. package/dist/react/useHistory.d.ts +1 -1
  33. package/dist/react/useHistory.js +1 -0
  34. package/dist/react/useListing.d.ts +8 -7
  35. package/dist/react/useListing.js +8 -7
  36. package/dist/react/useLookup.d.ts +1 -1
  37. package/dist/react/useLookup.js +1 -0
  38. package/dist/react/useNameOf.d.ts +13 -0
  39. package/dist/react/useNameOf.js +44 -0
  40. package/dist/react/useRecord.d.ts +1 -2
  41. package/dist/react/useRecord.js +1 -4
  42. package/dist/react/useRelated.d.ts +1 -1
  43. package/dist/react/useRelated.js +1 -0
  44. package/dist/react/useService.d.ts +38 -0
  45. package/dist/react/useService.js +66 -0
  46. package/dist/react/useSummary.d.ts +1 -1
  47. package/dist/react/useSummary.js +1 -0
  48. package/dist/telemetry/index.d.ts +45 -0
  49. package/dist/telemetry/index.js +55 -0
  50. package/dist/web/Refused.js +1 -1
  51. package/dist/web/list/EntityList.d.ts +5 -4
  52. package/dist/web/list/EntityList.js +3 -3
  53. package/dist/web/list/EntitySearchBar.d.ts +2 -1
  54. package/dist/web/list/EntitySearchBar.js +17 -11
  55. package/dist/web/list/presentation.d.ts +3 -3
  56. package/dist/web/list/presentation.js +2 -0
  57. package/dist/web/list/rowCommands.d.ts +16 -12
  58. package/dist/web/list/rowCommands.js +3 -3
  59. package/dist/web/record/CommandButton.d.ts +9 -6
  60. package/dist/web/record/CommandButton.js +1 -0
  61. package/dist/web/record/EntityPicker.d.ts +1 -1
  62. package/dist/web/record/EntityPicker.js +1 -0
  63. package/dist/web/record/EntityTags.d.ts +1 -1
  64. package/dist/web/record/EntityTags.js +1 -0
  65. package/dist/web/record/RelatedList.d.ts +1 -1
  66. package/dist/web/record/RelatedList.js +1 -0
  67. package/dist/web/record/control.d.ts +1 -1
  68. package/dist/web/record/control.js +1 -1
  69. package/dist/web/record/edit.js +20 -7
  70. package/dist/web/record/lines.js +7 -1
  71. package/dist/web/record/opening.d.ts +1 -1
  72. package/dist/web/record/opening.js +1 -0
  73. package/dist/web/workspace/SincproApp.d.ts +1 -2
  74. package/dist/web/workspace/SincproApp.js +1 -0
  75. package/dist/web/workspace/composer.d.ts +1 -2
  76. package/dist/web/workspace/composer.js +2 -2
  77. package/dist/web/workspace/open.d.ts +1 -1
  78. package/dist/web/workspace/open.js +1 -0
  79. package/dist/web/workspace/record.d.ts +1 -1
  80. package/dist/web/workspace/record.js +1 -1
  81. package/dist/web/workspace/workspace.d.ts +1 -1
  82. package/dist/web/workspace/workspace.js +1 -0
  83. package/package.json +48 -7
  84. package/dist/core/discovery.d.ts +0 -47
  85. package/dist/core/discovery.js +0 -68
  86. package/dist/core/entity.d.ts +0 -159
  87. package/dist/core/entity.js +0 -142
  88. package/dist/core/ids.d.ts +0 -17
  89. package/dist/core/ids.js +0 -52
  90. package/dist/core/memory.d.ts +0 -43
  91. package/dist/core/memory.js +0 -99
  92. package/dist/core/meta.d.ts +0 -121
  93. package/dist/core/meta.js +0 -130
  94. package/dist/core/metas.d.ts +0 -17
  95. package/dist/core/metas.js +0 -7
  96. package/dist/core/rest.d.ts +0 -34
  97. package/dist/core/rest.js +0 -127
  98. package/dist/core/retry.d.ts +0 -24
  99. package/dist/core/retry.js +0 -25
  100. package/dist/core/schema.d.ts +0 -39
  101. package/dist/core/schema.js +0 -128
  102. package/dist/core/transport.d.ts +0 -79
  103. package/dist/core/zone.d.ts +0 -27
  104. package/dist/core/zone.js +0 -75
@@ -1,10 +1,7 @@
1
1
  "use client";
2
+ import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
2
3
  import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
3
- import { pathFor, startingValuesOf, WITH_PARAM, } from "../core/entity.js";
4
- import { newEntityId } from "../core/ids.js";
5
4
  import { linesAnswered } from "../core/lines.js";
6
- import { retryKeys } from "../core/retry.js";
7
- import { TransportError } from "../core/transport.js";
8
5
  import { useFramework } from "./context.js";
9
6
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
7
  /** How long typing has to pause before the server is asked what the record becomes. */
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
3
  import type { Listing, ListingOptions } from "./useListing.js";
4
4
  import type { RecordReading } from "./useRecord.js";
5
5
  /**
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { useListing } from "./useListing.js";
3
4
  /**
4
5
  * The records a relation of ONE record points to, as a live listing of the related entity.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What a screen keeps of running one of the application's use cases.
3
+ *
4
+ * `run` answers what the use case answered, or `undefined` when it failed — the failure is in
5
+ * `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen.
6
+ */
7
+ export type ServiceState<A extends unknown[], R> = {
8
+ run: (...args: A) => Promise<R | undefined>;
9
+ /** A run is on its way. */
10
+ busy: boolean;
11
+ /** What the last run answered, until another one starts or `reset`. */
12
+ answer: R | undefined;
13
+ error: unknown;
14
+ reset: () => void;
15
+ };
16
+ /** A use case as a screen runs it: a method of a service, read from its bounded context. */
17
+ type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
18
+ /**
19
+ * One of the application's use cases, run from a screen.
20
+ *
21
+ * const close = useService(project.Issues.close);
22
+ * <Button disabled={close.busy} onPress={() => close.run({ issue_id })}>Cerrar</Button>
23
+ * {close.error ? <Refused error={close.error} /> : null}
24
+ *
25
+ * Context: all of an application's logic lives in its services (@sincpro/client-framework's
26
+ * `Feature` and `ApplicationService`, reached through their bounded context), traced and reported
27
+ * by its interceptors; what a screen adds is the state of running one — busy, the answer, the
28
+ * failure. Written by hand, that state is the 300-line context every mobile screen repeats; here
29
+ * it is one hook, the same for every use case. The span and the report are the service's: this
30
+ * hook neither opens one nor reports. A bounded context answers the same function every time a
31
+ * method is read, so `project.Issues.close` can be handed as it is.
32
+ *
33
+ * The last run wins: an answer that arrives after a newer run started is dropped, so a slow first
34
+ * click never overwrites the second. A run is never aborted — the server may have done it — but
35
+ * its answer does not land on a screen that left.
36
+ */
37
+ export declare function useService<A extends unknown[], R>(useCase: UseCase<A, R>): ServiceState<A, Awaited<R>>;
38
+ export {};
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ /**
4
+ * One of the application's use cases, run from a screen.
5
+ *
6
+ * const close = useService(project.Issues.close);
7
+ * <Button disabled={close.busy} onPress={() => close.run({ issue_id })}>Cerrar</Button>
8
+ * {close.error ? <Refused error={close.error} /> : null}
9
+ *
10
+ * Context: all of an application's logic lives in its services (@sincpro/client-framework's
11
+ * `Feature` and `ApplicationService`, reached through their bounded context), traced and reported
12
+ * by its interceptors; what a screen adds is the state of running one — busy, the answer, the
13
+ * failure. Written by hand, that state is the 300-line context every mobile screen repeats; here
14
+ * it is one hook, the same for every use case. The span and the report are the service's: this
15
+ * hook neither opens one nor reports. A bounded context answers the same function every time a
16
+ * method is read, so `project.Issues.close` can be handed as it is.
17
+ *
18
+ * The last run wins: an answer that arrives after a newer run started is dropped, so a slow first
19
+ * click never overwrites the second. A run is never aborted — the server may have done it — but
20
+ * its answer does not land on a screen that left.
21
+ */
22
+ export function useService(useCase) {
23
+ const [busy, setBusy] = useState(false);
24
+ const [answer, setAnswer] = useState(undefined);
25
+ const [error, setError] = useState(null);
26
+ // The use case as the latest render gave it: a run started from an old callback still runs
27
+ // the one the screen holds now (`project.scoped(…)` changed, say).
28
+ const latest = useRef(useCase);
29
+ latest.current = useCase;
30
+ const mounted = useRef(true);
31
+ useEffect(() => {
32
+ mounted.current = true;
33
+ return () => void (mounted.current = false);
34
+ }, []);
35
+ const runs = useRef(0);
36
+ const run = useCallback(async (...args) => {
37
+ const mine = ++runs.current;
38
+ const current = () => mounted.current && runs.current === mine;
39
+ setBusy(true);
40
+ setError(null);
41
+ try {
42
+ const answered = (await latest.current(...args));
43
+ if (current())
44
+ setAnswer(answered);
45
+ return answered;
46
+ }
47
+ catch (failure) {
48
+ if (current()) {
49
+ setAnswer(undefined);
50
+ setError(failure);
51
+ }
52
+ return undefined;
53
+ }
54
+ finally {
55
+ if (current())
56
+ setBusy(false);
57
+ }
58
+ }, []);
59
+ const reset = useCallback(() => {
60
+ runs.current += 1;
61
+ setBusy(false);
62
+ setAnswer(undefined);
63
+ setError(null);
64
+ }, []);
65
+ return { run, busy, answer, error, reset };
66
+ }
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
3
  import { type RecordSummary } from "../core/summary.js";
4
4
  /**
5
5
  * The summary of any record of an entity, read with the model this application already knows
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { summaryOf } from "../core/summary.js";
3
4
  import { useFramework } from "./context.js";
4
5
  import { useCallback } from "react";
@@ -0,0 +1,45 @@
1
+ import type { Attributes, Tracer } from "@sincpro/client-framework";
2
+ /**
3
+ * A `Tracer` for the browser, built from the application's own settings: OpenTelemetry's SDK
4
+ * exporting OTLP/HTTP to the endpoint the application names.
5
+ *
6
+ * // the application — domains/common/infrastructure/telemetry.ts
7
+ * import { browserTracer } from "./index.js";
8
+ * const tracer = browserTracer({ endpoint: settings.otlp, service: "forge-web", release });
9
+ * configureProcess({ tracer, reporter }); // entrypoints/main.tsx
10
+ *
11
+ * Context: optional on every count. It is an entry of its own that nothing else in this package
12
+ * imports, and its SDK (`@opentelemetry/sdk-trace`, `@opentelemetry/exporter-trace-otlp-http`,
13
+ * `@opentelemetry/resources`, `@opentelemetry/api`) is an optional peer: an application that
14
+ * does not import it installs nothing and ships nothing. It is also only a convenience — an
15
+ * application that wants its own provider builds it and wraps its tracer with
16
+ * `openTelemetryTracer` (`@sincpro/client-framework/opentelemetry`), or hands any object that
17
+ * fulfils the `Tracer` port.
18
+ *
19
+ * Like sincpro_framework's optional extras, it never breaks what it serves: the SDK loads after
20
+ * the first render (`import()`), and until it is there — or if it is not installed, or fails —
21
+ * use cases run untraced and send no `traceparent`; a failure to load is said once on the
22
+ * console. Nothing is registered globally: the provider is this tracer's own.
23
+ */
24
+ export type BrowserTracerOptions = {
25
+ /** The application's OTLP/HTTP traces endpoint (`https://collector.example.com/v1/traces`). */
26
+ endpoint: string;
27
+ /** `service.name`: what this application is called in the traces. */
28
+ service: string;
29
+ /** `service.version`: the release running. */
30
+ release?: string;
31
+ /** `deployment.environment.name`: `production`, `staging`… */
32
+ environment?: string;
33
+ /** Headers the endpoint asks for. Never a secret: whatever ships to a browser is public. */
34
+ headers?: Readonly<Record<string, string>>;
35
+ /** Fraction of traces kept, 0 to 1. Default 1 — a backoffice is low volume; sample in the
36
+ * Collector, where a trace is decided whole. */
37
+ sampling?: number;
38
+ /** More resource attributes (`tenant.group`, …). */
39
+ attributes?: Attributes;
40
+ };
41
+ export type BrowserTracer = Tracer & {
42
+ /** Sends what is buffered now. Called by itself when the page is hidden or left. */
43
+ flush: () => Promise<void>;
44
+ };
45
+ export declare function browserTracer(options: BrowserTracerOptions): BrowserTracer;
@@ -0,0 +1,55 @@
1
+ const SILENT = {
2
+ traceId: "",
3
+ spanId: "",
4
+ sampled: false,
5
+ set: () => undefined,
6
+ end: () => undefined,
7
+ };
8
+ export function browserTracer(options) {
9
+ let ready = null;
10
+ let flush = () => Promise.resolve();
11
+ void (async () => {
12
+ try {
13
+ const [{ TracerProvider, BatchSpanProcessor, TraceIdRatioBasedSampler, ParentBasedSampler }, { OTLPTraceExporter }, { resourceFromAttributes }, { openTelemetryTracer },] = await Promise.all([
14
+ import("@opentelemetry/sdk-trace"),
15
+ import("@opentelemetry/exporter-trace-otlp-http"),
16
+ import("@opentelemetry/resources"),
17
+ import("@sincpro/client-framework/opentelemetry"),
18
+ ]);
19
+ const exporter = new OTLPTraceExporter({
20
+ url: options.endpoint,
21
+ ...(options.headers ? { headers: { ...options.headers } } : {}),
22
+ });
23
+ const provider = new TracerProvider({
24
+ resource: resourceFromAttributes({
25
+ "service.name": options.service,
26
+ ...(options.release ? { "service.version": options.release } : {}),
27
+ ...(options.environment
28
+ ? { "deployment.environment.name": options.environment }
29
+ : {}),
30
+ ...options.attributes,
31
+ }),
32
+ sampler: new ParentBasedSampler({
33
+ root: new TraceIdRatioBasedSampler(options.sampling ?? 1),
34
+ }),
35
+ spanProcessors: [new BatchSpanProcessor({ exporter })],
36
+ });
37
+ ready = openTelemetryTracer(provider.getTracer(options.service));
38
+ flush = () => provider.forceFlush();
39
+ // A page that is hidden may never come back: what is buffered goes now.
40
+ const leave = () => void flush().catch(() => undefined);
41
+ globalThis.addEventListener?.("pagehide", leave);
42
+ globalThis.document?.addEventListener("visibilitychange", () => {
43
+ if (globalThis.document?.visibilityState === "hidden")
44
+ leave();
45
+ });
46
+ }
47
+ catch (error) {
48
+ console.warn("@sincpro/web-framework/telemetry: tracing is off — OpenTelemetry's SDK did not load", error);
49
+ }
50
+ })();
51
+ return {
52
+ start: (name, startOptions) => ready === null ? SILENT : ready.start(name, startOptions),
53
+ flush: () => flush(),
54
+ };
55
+ }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { frameworkCopy } from "../core/copy.js";
4
- import { explain } from "../core/transport.js";
4
+ import { explain } from "../core/explain.js";
5
5
  import { Button, Failed } from "@sincpro/web-ui";
6
6
  /**
7
7
  * A failure, said the way the server said it: its title, what happened and what to do —
@@ -1,3 +1,4 @@
1
+ import { type CommandBodies } from "@sincpro/client-framework";
1
2
  import { type AnyRecord } from "@sincpro/criteria";
2
3
  import { type WorkspaceApi } from "@sincpro/web-composer";
3
4
  import type { GroupLevel, NamedFilter } from "../../core/list.js";
@@ -28,8 +29,8 @@ import { type ReactNode } from "react";
28
29
  * screen passes `onOpen`.
29
30
  */
30
31
  export type { NamedFilter };
31
- export type EntityListProps<T extends AnyRecord> = {
32
- listing: Listing<T>;
32
+ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
33
+ listing: Listing<T, C>;
33
34
  /**
34
35
  * The workspace this list is a view of. With it, a row opens its record as a page, the
35
36
  * identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
@@ -107,7 +108,7 @@ export type EntityListProps<T extends AnyRecord> = {
107
108
  * The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
108
109
  * the list is read again when one is done (`useRowCommands`).
109
110
  */
110
- commands?: readonly RowCommand<T>[];
111
+ commands?: readonly RowCommand<T, C>[];
111
112
  /** Any other action of a row — or the commands built by hand with `useRowCommands`. */
112
113
  rowActions?: (row: T) => readonly RowAction[];
113
114
  /**
@@ -128,4 +129,4 @@ export type EntityFace<T> = {
128
129
  render: (set: ListSet<T>) => ReactNode;
129
130
  };
130
131
  export type View = "table" | "rows" | "board" | "sheet" | "pivot";
131
- export declare function EntityList<T extends AnyRecord>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T>): import("react").JSX.Element;
132
+ export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
3
4
  import { nameOf } from "@sincpro/criteria";
4
5
  import { RecordLink, useCrumbs } from "@sincpro/web-composer";
5
6
  import { frameworkCopy } from "../../core/copy.js";
6
- import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM } from "../../core/entity.js";
7
+ import { explain } from "../../core/explain.js";
7
8
  import { textOf, viewOf } from "../../core/present.js";
8
- import { explain } from "../../core/transport.js";
9
9
  import { useFramework } from "../../react/context.js";
10
10
  import { useGroups } from "../../react/useGroups.js";
11
11
  import { usePivot } from "../../react/usePivot.js";
@@ -312,7 +312,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
312
312
  error: failure === null
313
313
  ? null
314
314
  : [failure.heading, failure.sentence].filter(Boolean).join(". "),
315
- }, filtered: listing.where !== undefined || listing.text !== "", empty: {
315
+ }, filtered: listing.selection !== undefined || listing.text !== "", empty: {
316
316
  sentence: empty ?? copy.empty,
317
317
  whenFiltered: { sentence: copy.emptyFiltered },
318
318
  }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
@@ -15,7 +15,8 @@ import type { Listing } from "../../react/useListing.js";
15
15
  * - «search by name»: facets are the fields the entity's search template names first;
16
16
  * - a typed question («total > 5000») is checked against each field's operators;
17
17
  * - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
18
- * - everything put becomes ONE `where` the SERVER answers (`listing.filter`);
18
+ * - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
19
+ * writes it in criteria's own shape, a filter through a relation included;
19
20
  * - with `groups`, «Group by» offers the fields the model says may split the set, and the
20
21
  * SERVER counts the groups (`useGroups`).
21
22
  *
@@ -4,7 +4,7 @@ import { matching } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { groupableOf } from "./groups.js";
6
6
  import { facetsOf, modelOf } from "./search.js";
7
- import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, toggleNamed, useGroupingControl, useUiCopy, whereOf, } from "@sincpro/web-ui";
7
+ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useUiCopy, } from "@sincpro/web-ui";
8
8
  import { useEffect, useMemo, useRef, useState } from "react";
9
9
  /** No grouping: one constant, so the control is not handed a new array on every render. */
10
10
  const NO_LEVELS = [];
@@ -22,12 +22,12 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
22
22
  if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
23
23
  return;
24
24
  seeded.current = true;
25
- const where = matching(meta, seed).selection;
26
- if (where === undefined)
25
+ const literal = matching(meta, seed).selection;
26
+ if (literal === undefined)
27
27
  return;
28
- const chip = filterCriteria(where, fillCopy(ui.search.literalChip, { text: seed }));
28
+ const chip = filterCriteria(literal, fillCopy(ui.search.literalChip, { text: seed }));
29
29
  setPut([chip]);
30
- listing.filter(whereOf([chip]));
30
+ listing.filter(selectionOf([chip]));
31
31
  // Once the definition is known; what the person changes afterwards is theirs.
32
32
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
33
  }, [meta, seed]);
@@ -39,8 +39,10 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
39
39
  return null;
40
40
  const place = (next) => {
41
41
  setPut(next);
42
- listing.filter(whereOf(next));
42
+ listing.filter(selectionOf(next));
43
43
  };
44
+ // What the bar holds, as one selection: what the builder opens on.
45
+ const current = selectionOf(put);
44
46
  return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
45
47
  ? {}
46
48
  : {
@@ -56,7 +58,11 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
56
58
  onFilterSelect: (id) => {
57
59
  const named = filters.find((one) => one.id === id);
58
60
  if (named !== undefined)
59
- place(toggleNamed(put, { ...named, where: named.where }));
61
+ place(toggleNamed(put, {
62
+ id: named.id,
63
+ label: named.label,
64
+ selection: named.selection,
65
+ }));
60
66
  },
61
67
  }), ...(groups === undefined || groupable.length === 0
62
68
  ? {}
@@ -64,11 +70,11 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
64
70
  ? {}
65
71
  : {
66
72
  literal: (text) => matching(meta, text).selection ?? null,
67
- }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
73
+ }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(current === undefined && listing.order.length === 0
68
74
  ? {}
69
75
  : {
70
76
  initial: {
71
- ...(whereOf(put) === undefined ? {} : { where: whereOf(put) }),
77
+ ...(current === undefined ? {} : { selection: current }),
72
78
  ...(listing.order.length === 0
73
79
  ? {}
74
80
  : {
@@ -79,9 +85,9 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
79
85
  }),
80
86
  },
81
87
  }), onApply: (built) => {
82
- place(built?.where === undefined
88
+ place(built?.selection === undefined
83
89
  ? []
84
- : [filterCriteria(built.where, describeFilter(built.where, model))]);
90
+ : [filterCriteria(built.selection, describeFilter(built.selection, model))]);
85
91
  listing.orderBy((built?.order ?? []).map((one) => ({
86
92
  field: one.field,
87
93
  ...(one.descending === true ? { descending: true } : {}),
@@ -1,5 +1,5 @@
1
+ import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import type { PickerItem, RecordCard, RowOf } from "@sincpro/web-ui";
5
5
  import type { ComponentProps } from "react";
@@ -40,11 +40,11 @@ export type Presentation<T> = {
40
40
  row?: (record: T) => RowLook;
41
41
  card?: (record: T) => CardLook;
42
42
  };
43
- export type Presented<T extends AnyRecord> = Entity<T> & {
43
+ export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
44
44
  readonly presentation: Presentation<T>;
45
45
  };
46
46
  /** The entity with how its records look: pass it wherever an entity goes. */
47
- export declare function presented<T extends AnyRecord>(entity: Entity<T>, presentation: Presentation<T>): Presented<T>;
47
+ export declare function presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, presentation: Presentation<T>): Presented<T, C, A>;
48
48
  /** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
49
49
  export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
50
50
  /** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
@@ -1,6 +1,8 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  import { isList } from "../../core/list.js";
2
3
  /** The entity with how its records look: pass it wherever an entity goes. */
3
4
  export function presented(entity, presentation) {
5
+ // Its typed Commands and answers go with it: a generated entity, presented, is still checked.
4
6
  return { ...entity, presentation };
5
7
  }
6
8
  /** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
@@ -1,3 +1,4 @@
1
+ import { type CommandBodies } from "@sincpro/client-framework";
1
2
  import { type AnyRecord, type Expression } from "@sincpro/criteria";
2
3
  import type { Listing } from "../../react/useListing.js";
3
4
  import type { RowAction } from "@sincpro/web-ui";
@@ -21,21 +22,24 @@ import type { LucideIcon } from "lucide-react";
21
22
  * ]);
22
23
  * <EntityList listing={listing} rowActions={commands.rowActions} />
23
24
  */
24
- export type RowCommand<T> = {
25
- /** A Command the entity declares (`entity({ commands })`). */
26
- command: string;
27
- label: string;
28
- icon: LucideIcon;
29
- tone?: RowAction["tone"];
30
- /** Offered only on rows that hold it — a hint, not protection: the server decides. */
31
- when?: Expression<T>;
32
- /** What the Command is sent with. Without it, an empty body: the route names the row. */
33
- body?: (row: T) => AnyRecord;
34
- };
25
+ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
26
+ [N in keyof C & string]: {
27
+ /** A Command the entity declares (`entity({ commands })`); a typed entity, only its own. */
28
+ command: N;
29
+ label: string;
30
+ icon: LucideIcon;
31
+ tone?: RowAction["tone"];
32
+ /** Offered only on rows that hold it — a hint, not protection: the server decides. */
33
+ when?: Expression<T>;
34
+ /** What the Command is sent with — checked against a typed entity's `C[command]`. Without
35
+ * it, an empty body: the route (or the Command's `target`) names the row. */
36
+ body?: (row: T) => C[N];
37
+ };
38
+ }[keyof C & string];
35
39
  export type RowCommands<T> = {
36
40
  rowActions: (row: T) => readonly RowAction[];
37
41
  /** The last refusal, until `dismiss`. */
38
42
  error: unknown;
39
43
  dismiss: () => void;
40
44
  };
41
- export declare function useRowCommands<T extends AnyRecord>(listing: Listing<T>, commands: readonly RowCommand<T>[]): RowCommands<T>;
45
+ export declare function useRowCommands<T extends AnyRecord, C extends CommandBodies = CommandBodies>(listing: Listing<T, C>, commands: readonly RowCommand<T, C>[]): RowCommands<T>;
@@ -1,7 +1,6 @@
1
1
  "use client";
2
+ import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
2
3
  import { matches } from "@sincpro/criteria";
3
- import { pathFor } from "../../core/entity.js";
4
- import { retryKeys } from "../../core/retry.js";
5
4
  import { useFramework } from "../../react/context.js";
6
5
  import { useCallback, useState } from "react";
7
6
  export function useRowCommands(listing, commands) {
@@ -20,7 +19,8 @@ export function useRowCommands(listing, commands) {
20
19
  const gesture = `${one.command}\u0000${id}`;
21
20
  const retry = keys.get(gesture) ?? retryKeys();
22
21
  keys.set(gesture, retry);
23
- const body = one.body?.(row) ?? {};
22
+ // A Command whose body names its record (`target`) gets the row's id there.
23
+ const body = bodyFor(route, id, one.body?.(row) ?? {});
24
24
  setRunning((now) => new Set(now).add(gesture));
25
25
  setError(null);
26
26
  try {
@@ -1,5 +1,6 @@
1
+ import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
+ import { type AnswerOf } from "../../react/useCommand.js";
3
4
  /**
4
5
  * An entity's Command as a button.
5
6
  *
@@ -9,16 +10,18 @@ import type { Entity } from "../../core/entity.js";
9
10
  * shows THAT in the window: the confirmation is the consequence, in the server's words, not a
10
11
  * question. A refusal is shown where it happened, with what to do.
11
12
  */
12
- export declare function CommandButton<T extends AnyRecord, R = unknown>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
13
- entity: Entity<T>;
14
- command: string;
13
+ export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
14
+ entity: Entity<T, C, A>;
15
+ /** One the entity declares; a typed entity takes only its own names. */
16
+ command: N;
15
17
  id?: string;
16
- body?: AnyRecord;
18
+ /** What it is sent with — checked against a typed entity's `C[command]`. */
19
+ body?: C[N];
17
20
  label: string;
18
21
  /** Asks the server what it would do before doing it. */
19
22
  destructive?: boolean;
20
23
  role?: "primary" | "secondary" | "ghost";
21
24
  /** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
22
25
  disabled?: boolean;
23
- onDone?: (answer: R) => void;
26
+ onDone?: (answer: AnswerOf<R, A, N>) => void;
24
27
  }): import("react").JSX.Element;
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { frameworkCopy } from "../../core/copy.js";
4
5
  import { useCommand } from "../../react/useCommand.js";
5
6
  import { Refused } from "../Refused.js";
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import { type OpenTarget } from "@sincpro/web-ui";
5
5
  /**
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { nameOf } from "@sincpro/criteria";
4
5
  import { frameworkCopy } from "../../core/copy.js";
5
6
  import { isList } from "../../core/list.js";
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import { type OpenTarget } from "@sincpro/web-ui";
5
5
  /**
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { isList } from "../../core/list.js";
4
5
  import { useFramework } from "../../react/context.js";
5
6
  import { excluding, useLookup } from "../../react/useLookup.js";
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import type { RecordReading } from "../../react/useRecord.js";
4
4
  import { type EntityListProps } from "../list/EntityList.js";
5
5
  /**
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import {} from "@sincpro/client-framework";
3
4
  import { frameworkCopy } from "../../core/copy.js";
4
5
  import { defaultFields } from "../../core/present.js";
5
6
  import { useRelated } from "../../react/useRelated.js";
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { AnyRecord } from "@sincpro/criteria";
2
- import type { Entity } from "../../core/entity.js";
3
3
  import type { ReactNode } from "react";
4
4
  /** What a control of a field receives: its value, how to change it, and its state now. */
5
5
  export type FieldControl = {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { instantOf, timeZoneNow, wallTimeOf } from "../../core/zone.js";
3
+ import { instantOf, timeZoneNow, wallTimeOf } from "@sincpro/client-framework";
4
4
  import { EntityPicker } from "./EntityPicker.js";
5
5
  import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
6
6
  /**