@sincpro/web-framework 3.22.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +114 -112
  2. package/dist/core/cache.d.ts +20 -23
  3. package/dist/core/cache.js +37 -52
  4. package/dist/core/changes.d.ts +10 -18
  5. package/dist/core/changes.js +11 -30
  6. package/dist/core/command.d.ts +25 -11
  7. package/dist/core/command.js +9 -12
  8. package/dist/core/edit.d.ts +16 -2
  9. package/dist/core/edit.js +13 -2
  10. package/dist/core/groups.d.ts +3 -2
  11. package/dist/core/groups.js +4 -3
  12. package/dist/core/index.d.ts +3 -2
  13. package/dist/core/index.js +3 -2
  14. package/dist/core/list.d.ts +17 -11
  15. package/dist/core/list.js +17 -11
  16. package/dist/core/models.d.ts +16 -0
  17. package/dist/core/models.js +18 -0
  18. package/dist/core/names.d.ts +8 -6
  19. package/dist/core/names.js +16 -19
  20. package/dist/core/server.d.ts +9 -7
  21. package/dist/core/server.js +17 -21
  22. package/dist/core/trail.d.ts +6 -3
  23. package/dist/core/trail.js +2 -2
  24. package/dist/react/context.d.ts +13 -6
  25. package/dist/react/context.js +22 -10
  26. package/dist/react/index.d.ts +1 -1
  27. package/dist/react/index.js +1 -1
  28. package/dist/react/useBatchCommand.d.ts +5 -5
  29. package/dist/react/useBatchCommand.js +12 -13
  30. package/dist/react/useCommand.d.ts +11 -15
  31. package/dist/react/useCommand.js +15 -13
  32. package/dist/react/useCount.d.ts +2 -2
  33. package/dist/react/useCounts.js +10 -9
  34. package/dist/react/useGroups.d.ts +1 -1
  35. package/dist/react/useGroups.js +22 -13
  36. package/dist/react/useHistory.js +9 -8
  37. package/dist/react/useListing.d.ts +14 -7
  38. package/dist/react/useListing.js +35 -10
  39. package/dist/react/useLookup.js +8 -9
  40. package/dist/react/useNameOf.d.ts +2 -2
  41. package/dist/react/useNameOf.js +4 -13
  42. package/dist/react/usePivot.d.ts +1 -1
  43. package/dist/react/usePivot.js +13 -7
  44. package/dist/react/useRecord.js +40 -57
  45. package/dist/react/useRecordLifecycle.js +8 -9
  46. package/dist/react/useServiceReading.js +6 -18
  47. package/dist/react/useSummary.js +2 -1
  48. package/dist/react/useUpload.js +9 -2
  49. package/dist/react/useWrites.d.ts +13 -12
  50. package/dist/react/useWrites.js +17 -16
  51. package/dist/web/board/Dashboard.d.ts +2 -2
  52. package/dist/web/list/EntityList.d.ts +2 -2
  53. package/dist/web/list/entityList/choosing.d.ts +3 -3
  54. package/dist/web/list/entityList/faces.d.ts +6 -6
  55. package/dist/web/list/entityList/grouping.d.ts +3 -3
  56. package/dist/web/list/entityList/opening.d.ts +4 -4
  57. package/dist/web/list/entityList/opening.js +2 -1
  58. package/dist/web/list/entityList/paging.d.ts +3 -3
  59. package/dist/web/list/entityList/props.d.ts +4 -4
  60. package/dist/web/list/entityList/rowActions.d.ts +4 -4
  61. package/dist/web/list/entityList/rowActions.js +1 -1
  62. package/dist/web/list/export.d.ts +2 -2
  63. package/dist/web/list/export.js +7 -8
  64. package/dist/web/list/presentation.d.ts +3 -3
  65. package/dist/web/list/records.d.ts +13 -10
  66. package/dist/web/list/records.js +25 -45
  67. package/dist/web/list/reorder.d.ts +1 -1
  68. package/dist/web/list/reorder.js +8 -6
  69. package/dist/web/list/rowCommands.d.ts +10 -9
  70. package/dist/web/list/rowCommands.js +14 -15
  71. package/dist/web/list/useEntityList.d.ts +4 -4
  72. package/dist/web/record/CommandButton.d.ts +8 -8
  73. package/dist/web/record/CommandButton.js +2 -1
  74. package/dist/web/record/EntityPicker.js +2 -1
  75. package/dist/web/record/EntityTags.js +7 -6
  76. package/dist/web/record/RelatedList.js +2 -2
  77. package/dist/web/record/ServiceButton.js +6 -1
  78. package/dist/web/record/choice.js +2 -1
  79. package/dist/web/record/edit.js +2 -1
  80. package/dist/web/record/lines.js +6 -5
  81. package/dist/web/record/richText.js +1 -1
  82. package/dist/web/workspace/SincproApp.d.ts +8 -6
  83. package/dist/web/workspace/SincproApp.js +17 -19
  84. package/dist/web/workspace/composer.d.ts +14 -9
  85. package/dist/web/workspace/composer.js +31 -8
  86. package/dist/web/workspace/record.js +2 -2
  87. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import type { CommandBodies } from "@sincpro/client-framework";
1
+ import type { EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { WorkspaceApi } from "@sincpro/web-composer";
4
4
  import type { GroupLevel, NamedFilter } from "../../../core/list.js";
@@ -13,8 +13,8 @@ export type { NamedFilter };
13
13
  * What a screen says to an `EntityList`: values, never regions — a region is a part
14
14
  * (`EntityList.Bar`, `EntityList.Table`…).
15
15
  */
16
- export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
17
- listing: Listing<T, C>;
16
+ export type EntityListProps<T extends AnyRecord, O extends EntityOperations = EntityOperations> = {
17
+ listing: Listing<T, O>;
18
18
  /**
19
19
  * The workspace this list is a view of. With it, a row opens its record as a page, the
20
20
  * identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
@@ -135,7 +135,7 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
135
135
  * The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
136
136
  * the list is read again when one is done (`useRowCommands`).
137
137
  */
138
- commands?: readonly RowCommand<T, C>[];
138
+ commands?: readonly RowCommand<T, O>[];
139
139
  /** Any other action of a row — or the commands built by hand with `useRowCommands`. */
140
140
  rowActions?: (row: T) => readonly RowAction[];
141
141
  /**
@@ -1,4 +1,4 @@
1
- import type { CommandBodies } from "@sincpro/client-framework";
1
+ import type { EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { Listing } from "../../../react/useListing.js";
4
4
  import { type RowCommand } from "../rowCommands.js";
@@ -11,10 +11,10 @@ import type { RowAction } from "@sincpro/web-ui";
11
11
  * undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
12
12
  * whole order, never grouped or while choosing.
13
13
  */
14
- export declare function useListRowActions<T extends AnyRecord, C extends CommandBodies>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
15
- listing: Listing<T, C>;
14
+ export declare function useListRowActions<T extends AnyRecord, O extends EntityOperations>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
15
+ listing: Listing<T, O>;
16
16
  idOf: (row: T) => string;
17
- commands: readonly RowCommand<T, C>[];
17
+ commands: readonly RowCommand<T, O>[];
18
18
  rowActions: ((row: T) => readonly RowAction[]) | undefined;
19
19
  grouped: boolean;
20
20
  choosing: boolean;
@@ -14,7 +14,7 @@ import { useMemo } from "react";
14
14
  * whole order, never grouped or while choosing.
15
15
  */
16
16
  export function useListRowActions({ listing, idOf, commands, rowActions: asked, grouped, choosing, }) {
17
- const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
17
+ const restoring = listing.definition?.trash === true && listing.entity.operations.restore !== undefined;
18
18
  const offered = useMemo(() => restoring
19
19
  ? [
20
20
  ...commands,
@@ -3,8 +3,8 @@ import type { Listing } from "../../react/useListing.js";
3
3
  import { type DockAction } from "@sincpro/web-ui";
4
4
  /**
5
5
  * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
6
- * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
7
- * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
6
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
7
+ * operation (its contract publishes one); `null` otherwise.
8
8
  *
9
9
  * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
10
10
  * fetched to build it, so a million rows is the server's work, not the page's), and this writes
@@ -1,5 +1,4 @@
1
1
  "use client";
2
- import { downloadRoute, exportRoute } from "@sincpro/client-framework";
3
2
  import { nameOf } from "@sincpro/criteria";
4
3
  import { frameworkCopy } from "../../core/copy.js";
5
4
  import { csvOf, exportColumnsOf } from "../../core/export.js";
@@ -9,20 +8,19 @@ import { useToastIfAny } from "@sincpro/web-ui";
9
8
  import { Download } from "lucide-react";
10
9
  /**
11
10
  * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
12
- * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
13
- * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
11
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
12
+ * operation (its contract publishes one); `null` otherwise.
14
13
  *
15
14
  * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
16
15
  * fetched to build it, so a million rows is the server's work, not the page's), and this writes
17
16
  * what a person opens: the model's words as headers, the region's separator and decimal.
18
17
  */
19
18
  export function useListExport(listing, enabled) {
20
- const { transport, locale } = useFramework();
19
+ const { operations, locale } = useFramework();
21
20
  const toast = useToastIfAny();
22
- const entity = listing.entity;
23
- if (!enabled || entity.export === undefined)
21
+ const exporting = listing.entity.operations.export;
22
+ if (!enabled || exporting === undefined)
24
23
  return null;
25
- const path = entity.export;
26
24
  return {
27
25
  id: "export",
28
26
  label: frameworkCopy().list.export,
@@ -31,7 +29,8 @@ export function useListExport(listing, enabled) {
31
29
  onSelect: () => {
32
30
  // The question on screen without its page: every record it keeps, in its order.
33
31
  const { pagination: _page, ...asked } = listing.question;
34
- void downloadRoute(transport, exportRoute(path, asked, "jsonl"))
32
+ void operations
33
+ .call(exporting, { ...listing.input, criteria: asked, format: "jsonl" })
35
34
  .then((download) => download.blob())
36
35
  .then((blob) => blob.text())
37
36
  .then((text) => {
@@ -1,4 +1,4 @@
1
- import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
+ import { type Entity, type EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import type { DockMoment, PickerItem, RecordCard, RowOf, Tone } from "@sincpro/web-ui";
@@ -106,11 +106,11 @@ export type PartOf<V> = unknown extends V ? AnyRecord : NonNullable<V> extends {
106
106
  export type PartLooks<T> = {
107
107
  readonly [K in keyof T & string as [PartOf<T[K]>] extends [never] ? never : K]?: PartLook<PartOf<T[K]>>;
108
108
  };
109
- export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
109
+ export type Presented<T extends AnyRecord, O extends EntityOperations = EntityOperations> = Entity<T, O> & {
110
110
  readonly presentation: Presentation<T>;
111
111
  };
112
112
  /** The entity with how its records look: pass it wherever an entity goes. */
113
- 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>;
113
+ export declare function presented<T extends AnyRecord, O extends EntityOperations = EntityOperations>(entity: Entity<T, O>, presentation: Presentation<T>): Presented<T, O>;
114
114
  /** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
115
115
  export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
116
116
  /** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
@@ -1,6 +1,6 @@
1
- import { type Entity, type MetaStore, type Selection, type Transport } from "@sincpro/client-framework";
1
+ import { type Entity, type MetaStore, type OperationTransport, type Selection } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Expression, type Meta } from "@sincpro/criteria";
3
- import type { NameBook } from "../../core/names.js";
3
+ import { type NameBook } from "../../core/names.js";
4
4
  import type { BrowseRecords, LoadModel, SearchRecords, ToastSpec } from "@sincpro/web-ui";
5
5
  import { type ReactNode } from "react";
6
6
  /** A record as a person picks it by name: its key, its name, and what tells it apart. */
@@ -15,7 +15,7 @@ export type Choice = {
15
15
  * template and a short page), each record whole, read as its name and, beside it, what tells it
16
16
  * apart — the entity's `option` look, else its summary's description or type. Never its key.
17
17
  *
18
- * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
18
+ * await findChoices(operations, clientes, clienteMeta, "andres", "es")
19
19
  * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
20
20
  *
21
21
  * Context: `matching` asks for references (identity and display), and the `option` look and the
@@ -23,11 +23,14 @@ export type Choice = {
23
23
  * backend (#48). The question keeps `matching`'s template and its page, and brings each record
24
24
  * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
25
25
  */
26
- export declare function findChoices<T extends AnyRecord>(transport: Transport, entity: Entity<T>, meta: Meta, route: string, text: string, locale: string | undefined, signal?: AbortSignal): Promise<Choice[]>;
27
- /** What the searches of records ask of the framework: its transport, its definitions, its
28
- * names and its entities — `useFramework()`'s. */
26
+ export declare function findChoices<T extends AnyRecord>(operations: OperationTransport, entity: Entity<T>, meta: Meta, text: string, locale: string | undefined, options?: {
27
+ signal?: AbortSignal;
28
+ input?: Readonly<Record<string, unknown>>;
29
+ }): Promise<Choice[]>;
30
+ /** What the searches of records ask of the framework: the screens' operations, its definitions,
31
+ * its names and its entities — `useFramework()`'s. */
29
32
  export type FrameworkReads = {
30
- transport: Transport;
33
+ operations: OperationTransport;
31
34
  metas: MetaStore;
32
35
  names: NameBook;
33
36
  entities: readonly Entity[];
@@ -41,10 +44,10 @@ export type FrameworkReads = {
41
44
  * application did not declare finds nothing — the bar still offers the relation's text.
42
45
  * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
43
46
  * cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
44
- * 3. Else the entity's literal search (`findChoices`), its definition known or read once.
47
+ * 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
45
48
  */
46
49
  export declare function recordsSearch(framework: FrameworkReads, locale: string | undefined): SearchRecords;
47
- /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
50
+ /** `recordsSearch` over the framework's context: the screens' operations, its definitions and
48
51
  * its names, in the provider's language. */
49
52
  export declare function useSearchRecords(): SearchRecords;
50
53
  /**
@@ -56,7 +59,7 @@ export declare function useSearchRecords(): SearchRecords;
56
59
  *
57
60
  * 1. From the root's definition, each name of the path is a relation of the model before it.
58
61
  * 2. Its model is the relation's own definition, when the server published it inside; else its
59
- * entity's (`entityFor` by the aggregate it names), known or read once.
62
+ * entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
60
63
  * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
61
64
  * the model lacks, a relation to an entity the application did not declare — is refused.
62
65
  */
@@ -1,10 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { keysOf, listRoute, SelectionTooLarge, } from "@sincpro/client-framework";
3
+ import { keysOf, readPage, SelectionTooLarge, } from "@sincpro/client-framework";
4
4
  import { matching } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { explain } from "../../core/explain.js";
7
7
  import { lookupOf } from "../../core/lookup.js";
8
+ import { knownModelOf } from "../../core/models.js";
9
+ import { searchedAlone } from "../../core/names.js";
8
10
  import { entityFor } from "../../core/relation.js";
9
11
  import { summaryOf } from "../../core/summary.js";
10
12
  import { useFramework } from "../../react/context.js";
@@ -18,7 +20,7 @@ import { createContext, useContext, useMemo } from "react";
18
20
  * template and a short page), each record whole, read as its name and, beside it, what tells it
19
21
  * apart — the entity's `option` look, else its summary's description or type. Never its key.
20
22
  *
21
- * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
23
+ * await findChoices(operations, clientes, clienteMeta, "andres", "es")
22
24
  * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
23
25
  *
24
26
  * Context: `matching` asks for references (identity and display), and the `option` look and the
@@ -26,9 +28,9 @@ import { createContext, useContext, useMemo } from "react";
26
28
  * backend (#48). The question keeps `matching`'s template and its page, and brings each record
27
29
  * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
28
30
  */
29
- export async function findChoices(transport, entity, meta, route, text, locale, signal) {
31
+ export async function findChoices(operations, entity, meta, text, locale, options = {}) {
30
32
  const { specification: _reference, ...question } = matching(meta, text);
31
- const page = await transport.list(route, question, signal);
33
+ const page = await readPage(operations, entity, question, { ...options, meta });
32
34
  const look = presentationOf(entity).option;
33
35
  return lookupOf(meta, page.rows, entity.summary).map((one) => {
34
36
  const own = look === undefined || one.record === undefined ? {} : look(one.record);
@@ -46,30 +48,6 @@ export async function findChoices(transport, entity, meta, route, text, locale,
46
48
  };
47
49
  });
48
50
  }
49
- /** Where an entity is listed, or `undefined` when only under another record (`/{id}/lines`). */
50
- function routeOf(entity) {
51
- try {
52
- return listRoute(entity.list);
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- }
58
- /** An entity's definition: known, or read once (one row) and kept for every place after. */
59
- async function metaOf(framework, entity, signal) {
60
- const known = framework.metas.get(entity.key);
61
- if (known !== undefined)
62
- return known;
63
- const route = routeOf(entity);
64
- if (route === undefined)
65
- return undefined;
66
- const read = (await framework.transport.list(route, { pagination: { limit: 1 } }, signal))
67
- .meta;
68
- if (read == null)
69
- return undefined;
70
- framework.metas.set(entity.key, read);
71
- return read;
72
- }
73
51
  /**
74
52
  * web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
75
53
  * bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
@@ -79,7 +57,7 @@ async function metaOf(framework, entity, signal) {
79
57
  * application did not declare finds nothing — the bar still offers the relation's text.
80
58
  * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
81
59
  * cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
82
- * 3. Else the entity's literal search (`findChoices`), its definition known or read once.
60
+ * 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
83
61
  */
84
62
  export function recordsSearch(framework, locale) {
85
63
  return async ({ relation, text, keys, signal }) => {
@@ -91,11 +69,14 @@ export function recordsSearch(framework, locale) {
91
69
  id: key,
92
70
  name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
93
71
  })));
94
- const route = routeOf(entity);
95
- const meta = await metaOf(framework, entity, signal);
96
- if (route === undefined || meta === undefined)
72
+ if (!searchedAlone(entity))
73
+ return [];
74
+ const meta = knownModelOf(framework.metas, entity);
75
+ if (meta === undefined)
97
76
  return [];
98
- const choices = await findChoices(framework.transport, entity, meta, route, text, locale, signal);
77
+ const choices = await findChoices(framework.operations, entity, meta, text, locale, {
78
+ signal,
79
+ });
99
80
  return choices.map((one) => ({
100
81
  id: one.id,
101
82
  name: one.name,
@@ -103,11 +84,11 @@ export function recordsSearch(framework, locale) {
103
84
  }));
104
85
  };
105
86
  }
106
- /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
87
+ /** `recordsSearch` over the framework's context: the screens' operations, its definitions and
107
88
  * its names, in the provider's language. */
108
89
  export function useSearchRecords() {
109
- const { transport, metas, names, entities, locale } = useFramework();
110
- return useMemo(() => recordsSearch({ transport, metas, names, entities }, locale), [transport, metas, names, entities, locale]);
90
+ const { operations, metas, names, entities, locale } = useFramework();
91
+ return useMemo(() => recordsSearch({ operations, metas, names, entities }, locale), [operations, metas, names, entities, locale]);
111
92
  }
112
93
  /**
113
94
  * web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
@@ -118,7 +99,7 @@ export function useSearchRecords() {
118
99
  *
119
100
  * 1. From the root's definition, each name of the path is a relation of the model before it.
120
101
  * 2. Its model is the relation's own definition, when the server published it inside; else its
121
- * entity's (`entityFor` by the aggregate it names), known or read once.
102
+ * entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
122
103
  * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
123
104
  * the model lacks, a relation to an entity the application did not declare — is refused.
124
105
  */
@@ -132,7 +113,7 @@ export function modelLoader(framework, root, locale) {
132
113
  const entity = typeof field.relation === "string"
133
114
  ? entityFor(framework.entities, field.relation, framework.metas.get)
134
115
  : undefined;
135
- return entity === undefined ? undefined : metaOf(framework, entity);
116
+ return entity === undefined ? undefined : knownModelOf(framework.metas, entity);
136
117
  };
137
118
  return async (path) => {
138
119
  let meta = root;
@@ -147,10 +128,10 @@ export function modelLoader(framework, root, locale) {
147
128
  }
148
129
  /** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
149
130
  export function useLoadModel(root) {
150
- const { transport, metas, names, entities, locale } = useFramework();
131
+ const { operations, metas, names, entities, locale } = useFramework();
151
132
  return useMemo(() => root == null
152
133
  ? undefined
153
- : modelLoader({ transport, metas, names, entities }, root, locale), [root, transport, metas, names, entities, locale]);
134
+ : modelLoader({ operations, metas, names, entities }, root, locale), [root, operations, metas, names, entities, locale]);
154
135
  }
155
136
  /**
156
137
  * web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
@@ -169,7 +150,7 @@ export function recordsBrowser(framework, open, names, refused) {
169
150
  const entity = entityFor(framework.entities, browse.relation, framework.metas.get);
170
151
  if (entity === undefined)
171
152
  return;
172
- const meta = framework.metas.get(entity.key);
153
+ const meta = knownModelOf(framework.metas, entity);
173
154
  const identity = meta?.get_id || meta?.identity || "id";
174
155
  const chosen = browse.chosen.map((one) => String(one.id));
175
156
  const scope = chosen.length === 0
@@ -182,11 +163,10 @@ export function recordsBrowser(framework, open, names, refused) {
182
163
  keys,
183
164
  signal: new AbortController().signal,
184
165
  }).then(browse.choose, refused);
185
- const route = routeOf(entity);
186
- if (browse.many && open.chooseMany !== undefined && route !== undefined)
166
+ if (browse.many && open.chooseMany !== undefined && searchedAlone(entity))
187
167
  open.chooseMany(entity, (selection) => void keysOf(selection, {
188
- transport: framework.transport,
189
- route,
168
+ transport: framework.operations,
169
+ entity,
190
170
  identity,
191
171
  limit: BATCH_LIMIT,
192
172
  }).then(answer, refused), browse.text, scope);
@@ -4,7 +4,7 @@ import type { Listing } from "../../react/useListing.js";
4
4
  /**
5
5
  * A listing's rows put in their order by hand: when they may be dragged (`reorderingOf`), the
6
6
  * rows as the screen shows them while a move travels, and the move itself — one `Edit` of the
7
- * record moved through its entity's own edit route, or one per row when its group is respaced.
7
+ * record moved through its entity's `edit` operation, or one per row when its group is respaced.
8
8
  *
9
9
  * const reorder = useReorder(listing, idOf);
10
10
  * <List.Table onReorder={reorder.move} /> // absent: no grip
@@ -1,22 +1,23 @@
1
1
  "use client";
2
- import { pathFor } from "@sincpro/client-framework";
2
+ import { targeted } from "@sincpro/client-framework";
3
+ import { withTargetsOf } from "../../core/edit.js";
3
4
  import { movesFor, placed, reorderingOf, } from "../../core/reorder.js";
4
5
  import { useFramework } from "../../react/context.js";
5
6
  import { useEffect, useMemo, useState } from "react";
6
7
  export function useReorder(listing, keyOf,
7
8
  /** `false` while the screen does not allow it (grouped, choosing). */
8
9
  allowed = true) {
9
- const { transport } = useFramework();
10
+ const { operations } = useFramework();
10
11
  const { entity, meta, order, rows: read } = listing;
11
- const route = entity.edit;
12
- const reordering = useMemo(() => (allowed && route !== undefined ? reorderingOf(meta, order) : undefined), [allowed, route, meta, order]);
12
+ const editing = entity.operations.edit;
13
+ const reordering = useMemo(() => (allowed && editing !== undefined ? reorderingOf(meta, order) : undefined), [allowed, editing, meta, order]);
13
14
  const [shown, setShown] = useState(null);
14
15
  const [error, setError] = useState(null);
15
16
  const [elsewhere, setElsewhere] = useState(false);
16
17
  // A new reading is what is stored: it replaces the order a move showed ahead of it.
17
18
  useEffect(() => setShown(null), [read]);
18
19
  const rows = shown ?? read;
19
- const move = reordering === undefined || route === undefined
20
+ const move = reordering === undefined || editing === undefined
20
21
  ? undefined
21
22
  : (id, before) => {
22
23
  const moves = movesFor(rows, keyOf, reordering, id, before);
@@ -33,7 +34,7 @@ allowed = true) {
33
34
  try {
34
35
  for (const one of moves) {
35
36
  const row = rows.find((candidate) => keyOf(candidate) === one.id) ?? {};
36
- await transport.send(route.method, pathFor(route, one.id, row), {
37
+ const edit = targeted(entity, editing, one.id, {
37
38
  id: one.id,
38
39
  values: { [reordering.handle]: one.value },
39
40
  changed: [reordering.handle],
@@ -43,6 +44,7 @@ allowed = true) {
43
44
  : {}),
44
45
  action: "save",
45
46
  });
47
+ await operations.call(editing, withTargetsOf(editing, row, edit));
46
48
  }
47
49
  }
48
50
  catch (failure) {
@@ -1,5 +1,6 @@
1
- import { type CommandBodies } from "@sincpro/client-framework";
1
+ import { type EntityOperations } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Expression } from "@sincpro/criteria";
3
+ import type { BodyOf, CommandName } from "../../core/command.js";
3
4
  import type { Listing } from "../../react/useListing.js";
4
5
  import type { RowAction } from "@sincpro/web-ui";
5
6
  import type { LucideIcon } from "lucide-react";
@@ -22,8 +23,8 @@ import type { LucideIcon } from "lucide-react";
22
23
  * ]);
23
24
  * <EntityList listing={listing} rowActions={commands.rowActions} />
24
25
  */
25
- export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
26
- [N in keyof C & string]: {
26
+ export type RowCommand<T, O extends EntityOperations = EntityOperations> = {
27
+ [N in CommandName<O>]: {
27
28
  /** A Command the entity declares (`entity({ commands })`); a typed entity, only its own. */
28
29
  command: N;
29
30
  label: string;
@@ -31,12 +32,12 @@ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
31
32
  tone?: RowAction["tone"];
32
33
  /** Offered only on rows that hold it — a hint, not protection: the server decides. */
33
34
  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];
35
+ /** What the Command is sent with — checked against its operation's input. Without it, an
36
+ * empty body: the row's key goes where the operation names it. */
37
+ body?: (row: T) => BodyOf<O, N>;
37
38
  };
38
- }[keyof C & string];
39
- /** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
39
+ }[CommandName<O>];
40
+ /** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
40
41
  export declare const RESTORE = "restore";
41
42
  export type RowCommands<T> = {
42
43
  rowActions: (row: T) => readonly RowAction[];
@@ -44,4 +45,4 @@ export type RowCommands<T> = {
44
45
  error: unknown;
45
46
  dismiss: () => void;
46
47
  };
47
- export declare function useRowCommands<T extends AnyRecord, C extends CommandBodies = CommandBodies>(listing: Listing<T, C>, commands: readonly RowCommand<T, C>[]): RowCommands<T>;
48
+ export declare function useRowCommands<T extends AnyRecord, O extends EntityOperations = EntityOperations>(listing: Listing<T, O>, commands: readonly RowCommand<T, O>[]): RowCommands<T>;
@@ -1,12 +1,13 @@
1
1
  "use client";
2
- import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
2
+ import { retryKeys, targeted } from "@sincpro/client-framework";
3
3
  import { matches } from "@sincpro/criteria";
4
+ import { withTargetsOf } from "../../core/edit.js";
4
5
  import { useFramework } from "../../react/context.js";
5
6
  import { useCallback, useState } from "react";
6
- /** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
7
+ /** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
7
8
  export const RESTORE = "restore";
8
9
  export function useRowCommands(listing, commands) {
9
- const { transport } = useFramework();
10
+ const { operations } = useFramework();
10
11
  const [running, setRunning] = useState(new Set());
11
12
  const [error, setError] = useState(null);
12
13
  // One key per row and Command, kept while it goes unanswered: retrying is the same gesture.
@@ -14,25 +15,23 @@ export function useRowCommands(listing, commands) {
14
15
  const { entity, meta } = listing;
15
16
  const key = meta?.get_id || meta?.identity || "id";
16
17
  const run = useCallback(async (one, row) => {
17
- // «Restore» on a row of the trash runs the entity's own `restore` route (`trashOf`), unless
18
- // the entity declares a Command of that name.
19
- const route = entity.commands[one.command] ??
20
- (one.command === RESTORE ? entity.restore : undefined);
21
- if (route === undefined)
18
+ // «Restore» on a row of the trash runs the entity's own `restore` (`trashOf`), unless the
19
+ // entity declares a Command of that name.
20
+ const operation = entity.operations.commands?.[one.command] ??
21
+ (one.command === RESTORE ? entity.operations.restore : undefined);
22
+ if (operation === undefined)
22
23
  throw new Error(`${entity.key} declares no command "${one.command}"`);
23
24
  const id = String(row[key]);
24
25
  const gesture = `${one.command}\u0000${id}`;
25
26
  const retry = keys.get(gesture) ?? retryKeys();
26
27
  keys.set(gesture, retry);
27
- // A Command whose body names its record (`target`) gets the row's id there.
28
- const body = bodyFor(route, id, one.body?.(row) ?? {});
28
+ // The row's id where the operation names its record; what else it names (`tenant_id`)
29
+ // is the row's, unless the body says it.
30
+ const body = withTargetsOf(operation, row, targeted(entity, operation, id, one.body?.(row) ?? {}));
29
31
  setRunning((now) => new Set(now).add(gesture));
30
32
  setError(null);
31
33
  try {
32
- // A key of the route beyond `{id}` (`{tenant_id}`) is the row's, unless the body says it.
33
- await transport.send(route.method, pathFor(route, id, { ...row, ...body }), body, undefined, {
34
- idempotencyKey: retry.keyFor(body),
35
- });
34
+ await operations.call(operation, body, { idempotencyKey: retry.keyFor(body) });
36
35
  retry.settle(null);
37
36
  listing.reload();
38
37
  }
@@ -47,7 +46,7 @@ export function useRowCommands(listing, commands) {
47
46
  return next;
48
47
  });
49
48
  }
50
- }, [transport, entity, key, keys, listing]);
49
+ }, [operations, entity, key, keys, listing]);
51
50
  const rowActions = (row) => commands
52
51
  .filter((one) => meta === null || one.when === undefined || matches(row, one.when, meta))
53
52
  .map((one) => ({
@@ -1,4 +1,4 @@
1
- import { type CommandBodies } from "@sincpro/client-framework";
1
+ import { type EntityOperations } from "@sincpro/client-framework";
2
2
  import { type AnyRecord } from "@sincpro/criteria";
3
3
  import { type EntityListProps } from "./entityList/props.js";
4
4
  export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } from "./entityList/props.js";
@@ -21,10 +21,10 @@ export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } fro
21
21
  * What the screen asks wins over the named list's (`defineList`), which wins over the entity's
22
22
  * own look (`presented`), which wins over the model.
23
23
  */
24
- export declare function useEntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>,
24
+ export declare function useEntityList<T extends AnyRecord, O extends EntityOperations = EntityOperations>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, O>,
25
25
  /** The faces the screen's tree writes, when it writes one (`EntityList.Table`…). */
26
26
  writtenViews?: readonly string[]): {
27
- listing: import("../../index.js").Listing<T, C>;
27
+ listing: import("../../index.js").Listing<T, O>;
28
28
  meta: import("@sincpro/criteria").Meta | null;
29
29
  locale: string | undefined;
30
30
  embedded: boolean;
@@ -180,4 +180,4 @@ writtenViews?: readonly string[]): {
180
180
  };
181
181
  };
182
182
  /** What a list's root and its parts read. */
183
- export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, CommandBodies>>;
183
+ export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, EntityOperations>>;
@@ -1,6 +1,6 @@
1
- import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
+ import { type Entity, type EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
- import { type AnswerOf } from "../../react/useCommand.js";
3
+ import type { BodyOf, CommandAnswer, CommandName } from "../../core/command.js";
4
4
  import { type ActionDialog } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
6
  import { type ActionLook, type DockedAction } from "./dock.js";
@@ -17,13 +17,13 @@ import { type ActionLook, type DockedAction } from "./dock.js";
17
17
  * beside `body`.
18
18
  */
19
19
  /** What a Command's button and dock action are given. */
20
- export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies, N extends keyof C & string, A extends CommandAnswers> = {
21
- entity: Entity<T, C, A>;
20
+ export type CommandActionProps<T extends AnyRecord, R, O extends EntityOperations, N extends CommandName<O>> = {
21
+ entity: Entity<T, O>;
22
22
  /** One the entity declares; a typed entity takes only its own names. */
23
23
  command: N;
24
24
  id?: string;
25
25
  /** What it is sent with — checked against a typed entity's `C[command]`. */
26
- body?: C[N];
26
+ body?: BodyOf<O, N>;
27
27
  label: string;
28
28
  /** Asks the server what it would do before doing it. */
29
29
  destructive?: boolean;
@@ -35,9 +35,9 @@ export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies,
35
35
  record?: AnyRecord;
36
36
  /** What its window says — its title (the label without «…» by default), a sentence under it. */
37
37
  dialog?: ActionDialog;
38
- onDone?: (answer: AnswerOf<R, A, N>) => void;
38
+ onDone?: (answer: CommandAnswer<R, O, N>) => void;
39
39
  };
40
- 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>({ role, ...props }: CommandActionProps<T, R, C, N, A> & {
40
+ export declare function CommandButton<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ role, ...props }: CommandActionProps<T, R, O, N> & {
41
41
  role?: "primary" | "secondary" | "ghost";
42
42
  }): import("react").JSX.Element;
43
43
  /**
@@ -52,7 +52,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
52
52
  * <Record.Dock actions={[confirmar.action, anular.action]} />
53
53
  * {anular.dialog}
54
54
  */
55
- export declare function useCommandAction<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, C, N, A> & Omit<ActionLook, "id"> & {
55
+ export declare function useCommandAction<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, O, N> & Omit<ActionLook, "id"> & {
56
56
  /** The dock's id for it — the record's is `id`. Defaults to the label. */
57
57
  actionId?: string;
58
58
  }): DockedAction;
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
+ import { knownModelOf } from "../../core/models.js";
4
5
  import { entityFor } from "../../core/relation.js";
5
6
  import { useFramework } from "../../react/context.js";
6
7
  import { useCommand } from "../../react/useCommand.js";
@@ -49,7 +50,7 @@ function useCommandBehind({ entity, command, id, body, destructive = false, ask,
49
50
  const form = ask === undefined
50
51
  ? undefined
51
52
  : askFormOf(ask, {
52
- meta: metas.get(entity.key),
53
+ meta: knownModelOf(metas, entity),
53
54
  locale,
54
55
  record,
55
56
  entityFor: (target) => entityFor(entities, target, metas.get),
@@ -4,6 +4,7 @@ import {} from "@sincpro/client-framework";
4
4
  import { nameOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { isList } from "../../core/list.js";
7
+ import { knownModelOf } from "../../core/models.js";
7
8
  import { useFramework } from "../../react/context.js";
8
9
  import { useListing } from "../../react/useListing.js";
9
10
  import { excluding, useLookup } from "../../react/useLookup.js";
@@ -63,7 +64,7 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
63
64
  ...(exclude === undefined ? {} : { exclude }),
64
65
  });
65
66
  // The chooser opens after the picker read the definition: it excludes from its first page.
66
- const scope = excluding(criteria, exclude, metas.get(base.key));
67
+ const scope = excluding(criteria, exclude, knownModelOf(metas, base));
67
68
  const person = base.summary.person === true;
68
69
  const nothing = none === undefined || none === false || lookup.text !== ""
69
70
  ? []