@sincpro/web-framework 3.21.0 → 4.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 (88) 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/copy.d.ts +4 -0
  9. package/dist/core/copy.js +2 -0
  10. package/dist/core/edit.d.ts +16 -2
  11. package/dist/core/edit.js +13 -2
  12. package/dist/core/groups.d.ts +3 -2
  13. package/dist/core/groups.js +4 -3
  14. package/dist/core/index.d.ts +2 -2
  15. package/dist/core/index.js +2 -2
  16. package/dist/core/list.d.ts +17 -11
  17. package/dist/core/list.js +17 -11
  18. package/dist/core/names.d.ts +8 -6
  19. package/dist/core/names.js +14 -18
  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 +11 -9
  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 +10 -12
  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 +7 -7
  37. package/dist/react/useListing.d.ts +14 -7
  38. package/dist/react/useListing.js +33 -9
  39. package/dist/react/useLookup.js +5 -7
  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 +49 -57
  45. package/dist/react/useRecordLifecycle.js +8 -9
  46. package/dist/react/useServiceReading.js +6 -18
  47. package/dist/react/useUpload.js +9 -2
  48. package/dist/react/useWrites.d.ts +13 -12
  49. package/dist/react/useWrites.js +17 -16
  50. package/dist/web/board/Dashboard.d.ts +112 -0
  51. package/dist/web/board/Dashboard.js +106 -0
  52. package/dist/web/board/index.d.ts +1 -0
  53. package/dist/web/board/index.js +1 -0
  54. package/dist/web/index.d.ts +2 -0
  55. package/dist/web/index.js +2 -0
  56. package/dist/web/list/EntityList.d.ts +2 -2
  57. package/dist/web/list/entityList/choosing.d.ts +3 -3
  58. package/dist/web/list/entityList/faces.d.ts +6 -6
  59. package/dist/web/list/entityList/grouping.d.ts +3 -3
  60. package/dist/web/list/entityList/opening.d.ts +4 -4
  61. package/dist/web/list/entityList/opening.js +2 -1
  62. package/dist/web/list/entityList/paging.d.ts +3 -3
  63. package/dist/web/list/entityList/props.d.ts +4 -4
  64. package/dist/web/list/entityList/rowActions.d.ts +4 -4
  65. package/dist/web/list/entityList/rowActions.js +1 -1
  66. package/dist/web/list/export.d.ts +2 -2
  67. package/dist/web/list/export.js +7 -8
  68. package/dist/web/list/presentation.d.ts +3 -3
  69. package/dist/web/list/records.d.ts +13 -10
  70. package/dist/web/list/records.js +23 -44
  71. package/dist/web/list/reorder.d.ts +1 -1
  72. package/dist/web/list/reorder.js +8 -6
  73. package/dist/web/list/rowCommands.d.ts +10 -9
  74. package/dist/web/list/rowCommands.js +14 -15
  75. package/dist/web/list/useEntityList.d.ts +4 -4
  76. package/dist/web/record/CommandButton.d.ts +8 -8
  77. package/dist/web/record/EntityTags.js +4 -4
  78. package/dist/web/record/RelatedList.js +2 -2
  79. package/dist/web/record/Wizard.d.ts +65 -0
  80. package/dist/web/record/Wizard.js +90 -0
  81. package/dist/web/record/lines.js +4 -4
  82. package/dist/web/record/richText.js +1 -1
  83. package/dist/web/workspace/SincproApp.d.ts +8 -6
  84. package/dist/web/workspace/SincproApp.js +17 -19
  85. package/dist/web/workspace/composer.d.ts +14 -9
  86. package/dist/web/workspace/composer.js +29 -8
  87. package/dist/web/workspace/record.js +2 -2
  88. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { describeFailure, logger, outcomeOf, screensTransport, } from "@sincpro/client-framework";
1
+ import { describeFailure, logger, outcomeOf, readRecord, screensOperations, } from "@sincpro/client-framework";
2
2
  /**
3
3
  * A use case's answer read on the server that renders a page, before it is drawn — the very use
4
4
  * case the page reads with in the browser (`useServiceReading`), so the page arrives with its
@@ -59,21 +59,22 @@ function notRead(what, error) {
59
59
  }
60
60
  /**
61
61
  * One record and its model, read on the server that renders the page — the same question
62
- * `useRecord` asks in the browser, through the same transport the `FrameworkProvider` is given —,
62
+ * `useRecord` asks in the browser, through the same operations the `FrameworkProvider` is given —,
63
63
  * so its screen arrives FILLED in the HTML, not as a skeleton, and the browser does not ask
64
64
  * again on mount.
65
65
  *
66
66
  * // a route's loader or a Server Component — plain logic, no screen loaded
67
- * const invoice = await readRecordOnServer(transport, invoices, params.id);
67
+ * const invoice = await readRecordOnServer(operations, invoices, params.id, { meta });
68
68
  * return <InvoicePage id={params.id} initial={invoice} />;
69
69
  *
70
70
  * // the page, rendered there and hydrated in the browser
71
71
  * const invoice = useRecord(invoices, id, { initial });
72
72
  *
73
- * `opened` is what the screen opens: a record's id, `""` for a new one — only its model is read,
74
- * as `useRecord` reads it (the list, one row) — or the reference the screen receives.
73
+ * `opened` is what the screen opens: a record's id, `""` for a new one — nothing is read: it
74
+ * starts from its model's definition (`meta`, the contract's) — or the reference the screen
75
+ * receives.
75
76
  *
76
- * Context: it asks through the screens' use case (`screensTransport`), as `useRecord` and
77
+ * Context: it asks through the screens' use case (`screensOperations`), as `useRecord` and
77
78
  * `readListing` do — traced like the browser's reads, with the process's context — and answers
78
79
  * plain JSON (`RecordRead`): a Client Component is handed data, never instances. A read that
79
80
  * fails never refuses the page, as `readOnServer`: it answers `undefined` and one WARN line on
@@ -87,26 +88,21 @@ function notRead(what, error) {
87
88
  */
88
89
  export async function readRecordOnServer(transport, entity, opened, options = {}) {
89
90
  const id = typeof opened === "string" ? opened : (opened.id ?? "");
90
- const screens = screensTransport(transport);
91
+ const meta = options.meta ?? null;
92
+ // Nothing to read but the model: the screen starts a new record from its definition.
93
+ if (id === "")
94
+ return plain({ entity: entity.key, id, record: null, meta, draft: null });
91
95
  try {
92
- if (id === "") {
93
- // Nothing to read but the model: asked of the list with no rows, as `useRecord` asks it.
94
- const page = await screens.list(entity.list, { pagination: { limit: 1 } }, options.signal);
95
- return plain({
96
- entity: entity.key,
97
- id,
98
- record: null,
99
- meta: page.meta ?? null,
100
- draft: null,
101
- });
102
- }
103
- const answer = await screens.one(entity.one(id), options.signal);
96
+ const answer = await readRecord(screensOperations(transport), entity, id, {
97
+ meta,
98
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
99
+ });
104
100
  return plain({
105
101
  entity: entity.key,
106
102
  id,
107
103
  record: answer.record,
108
- meta: answer.meta ?? null,
109
- draft: answer.draft ?? null,
104
+ meta: answer.meta,
105
+ draft: answer.draft,
110
106
  });
111
107
  }
112
108
  catch (error) {
@@ -1,4 +1,4 @@
1
- import { type Transport } from "@sincpro/client-framework";
1
+ import { type Entity, type OperationTransport } from "@sincpro/client-framework";
2
2
  import type { Criteria } from "@sincpro/criteria";
3
3
  /**
4
4
  * Where a record was opened from: the page of the list it was a row of, so the record can go
@@ -11,7 +11,10 @@ import type { Criteria } from "@sincpro/criteria";
11
11
  * cheap as the first. Over a list of millions the arrows never stop at the page.
12
12
  */
13
13
  export type Trail = {
14
- route: string;
14
+ /** The entity listed, searched through its `search`. */
15
+ entity: Entity;
16
+ /** What its search takes beside the criteria: the record a list lives under. */
17
+ input: Readonly<Record<string, unknown>>;
15
18
  /** The list's question, without a page: what the neighbouring pages are asked with. */
16
19
  question: Criteria;
17
20
  /** The field the ids are read from. */
@@ -49,7 +52,7 @@ export declare function placeOf(trail: Trail, id: string): {
49
52
  * The record next to `id` (`step` 1) or before it (`step` -1), with the trail moved to its page
50
53
  * when it lies on the neighbouring one. `null` at either end of the set.
51
54
  */
52
- export declare function stepIn(transport: Transport, trail: Trail, id: string, step: 1 | -1): Promise<{
55
+ export declare function stepIn(transport: OperationTransport, trail: Trail, id: string, step: 1 | -1): Promise<{
53
56
  id: string;
54
57
  trail: Trail;
55
58
  } | null>;
@@ -1,4 +1,4 @@
1
- import {} from "@sincpro/client-framework";
1
+ import { readPage } from "@sincpro/client-framework";
2
2
  import { resumingFrom } from "@sincpro/criteria";
3
3
  /** This page load's mark: drawn once per load of this module, never sent anywhere. */
4
4
  const PAGE_LOAD = Math.random().toString(36).slice(2, 8);
@@ -28,7 +28,7 @@ async function page(transport, trail, cursor) {
28
28
  ...trail.question,
29
29
  pagination: { ...trail.question.pagination, limit: trail.size },
30
30
  };
31
- const answer = await transport.list(trail.route, resumingFrom(sized, cursor));
31
+ const answer = await readPage(transport, trail.entity, resumingFrom(sized, cursor), { input: trail.input });
32
32
  return {
33
33
  ids: answer.rows.map((row) => String(row[trail.key] ?? "")),
34
34
  after: answer.cursor,
@@ -1,4 +1,4 @@
1
- import { type ChangeFeed, type Entity, type MetaStore, type Transport } from "@sincpro/client-framework";
1
+ import { type ChangeFeed, type Entity, type MetaStore, type OperationTransport, type Transport } from "@sincpro/client-framework";
2
2
  import type { Meta } from "@sincpro/criteria";
3
3
  import type { Uploads } from "../core/files.js";
4
4
  import { type NameBook } from "../core/names.js";
@@ -21,7 +21,7 @@ import { type ReactNode } from "react";
21
21
  * what is selected). Read `~/dev/sincpro_web_composer/README.md` before writing a second one
22
22
  * here. A value the backend must see on every request (the active company) goes in the
23
23
  * process's context (`processContext.set({ company_id })`, @sincpro/client-framework): every
24
- * request under this provider carries it in `sincpro-context` (`screensTransport`), and a change
24
+ * request under this provider carries it in `sincpro-context` (`screensOperations`), and a change
25
25
  * reads every screen again. The language is one of those values: the provider puts its `locale`
26
26
  * there as `lang`, so what the server writes in the call's language — a dry run's «Se eliminará
27
27
  * «F-0042»», a use case's message — comes in the screen's. An application that sets `lang`
@@ -34,7 +34,10 @@ import { type ReactNode } from "react";
34
34
  * transport and company (`nameBook`), and forget what a write touches.
35
35
  */
36
36
  type FrameworkContextValue = {
37
- transport: Transport;
37
+ /** What the screens read and write: each call a use case of `screens` (`screensOperations`). */
38
+ operations: OperationTransport;
39
+ /** REST's own transport, for a file's bytes (`uploadTo`); none: a file field is read only. */
40
+ transport: Transport | undefined;
38
41
  locale: string | undefined;
39
42
  metas: MetaStore;
40
43
  /** The application's entities: what a relation of a model is resolved to. */
@@ -63,8 +66,12 @@ type FrameworkContextValue = {
63
66
  };
64
67
  /** Who is who: usernames → the names a person reads, for every username asked at once. */
65
68
  export type People = (who: readonly string[]) => Promise<Readonly<Record<string, string>>>;
66
- export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, dateStyle, currency, region, events, richText, uploads, people, changes, children, }: {
67
- transport: Transport;
69
+ export declare function FrameworkProvider({ operations, transport, locale, metas: seed, entities, timeZone, dateStyle, currency, region, events, richText, uploads, people, changes, children, }: {
70
+ /** The operations every screen reads and writes through — `restOperations(…)`,
71
+ * `jsonRpcOperations(…)`, a cache over one (`cachedOperations`). */
72
+ operations: OperationTransport;
73
+ /** REST's transport, where a file's bytes go (`uploadTo`) — needed only with `uploads`. */
74
+ transport?: Transport;
68
75
  /** The language labels and values are read in (`"es"`); the model's `default` without it. */
69
76
  locale?: string;
70
77
  /** Definitions known before any request, by entity key: the preload. */
@@ -121,7 +128,7 @@ export declare function useEntityFor(target: string | undefined): Entity | undef
121
128
  * their entities, their definitions and their facts, added to the provider's for the screens
122
129
  * under it.
123
130
  *
124
- * <FrameworkProvider transport={transport}> ← the public site: none
131
+ * <FrameworkProvider operations={operations}> ← the public site: none
125
132
  * <ModelDefinitions metas={metasOf(billing)} events={eventMetasOf(billing)}>
126
133
  * <Backoffice /> ← loads them with its code
127
134
  * </ModelDefinitions>
@@ -1,13 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { installTimeZone, metaStore, processChanges, processContext, screensTransport, } from "@sincpro/client-framework";
3
+ import { installTimeZone, metaStore, processChanges, processContext, screensOperations, } from "@sincpro/client-framework";
4
4
  import { nameBook } from "../core/names.js";
5
5
  import { installCurrency, installDateStyle, installRegion, } from "../core/present.js";
6
6
  import { entityFor } from "../core/relation.js";
7
7
  import { useContextValues } from "./useContextValues.js";
8
8
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
9
9
  const FrameworkContext = createContext(null);
10
- export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, region, events = NO_EVENTS, richText = NO_RICH_TEXT, uploads, people, changes = processChanges, children, }) {
10
+ export function FrameworkProvider({ operations, transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, region, events = NO_EVENTS, richText = NO_RICH_TEXT, uploads, people, changes = processChanges, children, }) {
11
11
  // Installed before the children draw, and again when it changes (another company): the
12
12
  // formatters read it, so it cannot wait for an effect.
13
13
  const zoned = useRef(null);
@@ -44,22 +44,23 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
44
44
  // the screens already learned.
45
45
  const [metas] = useState(() => metaStore(seed));
46
46
  const [trails] = useState(() => new Map());
47
- // What the screens read and write is a use case of `screens` (`screensTransport`,
48
- // client-framework): each request traced, carrying the process's context (the company, the
47
+ // What the screens read and write is a use case of `screens` (`screensOperations`,
48
+ // client-framework): each call traced, carrying the process's context (the company, the
49
49
  // tenant) read at the moment it is sent, and reported when it failed unexpectedly.
50
- const screens = useMemo(() => screensTransport(transport), [transport]);
50
+ const screens = useMemo(() => screensOperations(operations), [operations]);
51
51
  // When the context changes, every reading on screen reads its same question again — a list
52
52
  // keeps its filter, order and page, a record what was typed (`useListing`, `useRecord`). The
53
53
  // transport stays the same one: a new one would start every reading over.
54
54
  const context = useContextValues(processContext);
55
55
  // One book per transport and company: another company's names are not this one's.
56
- const names = useMemo(() => nameBook(screens, metas, entities),
56
+ const names = useMemo(() => nameBook(screens, metas),
57
57
  // `context` renews it: what was named in one company is asked again in the next.
58
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
59
- [screens, metas, entities, context]);
59
+ [screens, metas, context]);
60
60
  useEffect(() => changes.follow((change) => names.changed(change)), [changes, names]);
61
61
  const value = useMemo(() => ({
62
- transport: screens,
62
+ operations: screens,
63
+ transport,
63
64
  locale,
64
65
  metas,
65
66
  entities,
@@ -75,6 +76,7 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
75
76
  people,
76
77
  }), [
77
78
  screens,
79
+ transport,
78
80
  locale,
79
81
  metas,
80
82
  entities,
@@ -115,7 +117,7 @@ export function useEntityFor(target) {
115
117
  * their entities, their definitions and their facts, added to the provider's for the screens
116
118
  * under it.
117
119
  *
118
- * <FrameworkProvider transport={transport}> ← the public site: none
120
+ * <FrameworkProvider operations={operations}> ← the public site: none
119
121
  * <ModelDefinitions metas={metasOf(billing)} events={eventMetasOf(billing)}>
120
122
  * <Backoffice /> ← loads them with its code
121
123
  * </ModelDefinitions>
@@ -6,7 +6,7 @@
6
6
  export { FrameworkProvider, ModelDefinitions, type People, useEntityFor, useFramework, } from "./context.js";
7
7
  export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
8
8
  export { BATCH_LIMIT, type BatchCommandState, useBatchCommand, } from "./useBatchCommand.js";
9
- export { type AnswerOf, type CommandState, type Rehearsal, useCommand, useRouteCommand, } from "./useCommand.js";
9
+ export { type CommandState, type Rehearsal, useCommand, useOperationCommand, } from "./useCommand.js";
10
10
  export { useContextValues } from "./useContextValues.js";
11
11
  export { useCount } from "./useCount.js";
12
12
  export { type CountAsked, useCounts } from "./useCounts.js";
@@ -6,7 +6,7 @@
6
6
  export { FrameworkProvider, ModelDefinitions, useEntityFor, useFramework, } from "./context.js";
7
7
  export { ListScopeProvider, useListScope, } from "./scope.js";
8
8
  export { BATCH_LIMIT, useBatchCommand, } from "./useBatchCommand.js";
9
- export { useCommand, useRouteCommand, } from "./useCommand.js";
9
+ export { useCommand, useOperationCommand, } from "./useCommand.js";
10
10
  export { useContextValues } from "./useContextValues.js";
11
11
  export { useCount } from "./useCount.js";
12
12
  export { useCounts } from "./useCounts.js";
@@ -1,6 +1,6 @@
1
- import { type BatchResult, type CommandAnswers, type CommandBodies, type Entity, type Selection } from "@sincpro/client-framework";
1
+ import { type BatchResult, type Entity, type EntityOperations, type Selection } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
- import type { AnswerOf } from "./useCommand.js";
3
+ import { type BodyOf, type CommandAnswer, type CommandName } from "../core/command.js";
4
4
  /** The most records a Command runs on at once from a screen, unless the screen says otherwise. */
5
5
  export declare const BATCH_LIMIT = 200;
6
6
  export type BatchCommandState<R, B extends AnyRecord = AnyRecord, T extends AnyRecord = AnyRecord> = {
@@ -33,7 +33,7 @@ export type BatchCommandState<R, B extends AnyRecord = AnyRecord, T extends AnyR
33
33
  *
34
34
  * Context: `for rec in self` from a screen. The keys come from the selection (`keysOf`: in
35
35
  * hand, or read once as references — never more than `limit`); each record is the Command sent
36
- * through the screens' transport — a use case of its own, traced — with an idempotency key of
36
+ * through the screens' operations — a use case of its own, traced — with an idempotency key of
37
37
  * its own, kept while it goes unanswered (`retryKeys`): a retry after a dropped request is the
38
38
  * same confirmation, never a second one. A failure is that record's (`runBatch`); the lists
39
39
  * follow every write as they do for one.
@@ -44,7 +44,7 @@ export type BatchCommandState<R, B extends AnyRecord = AnyRecord, T extends AnyR
44
44
  * Not here: a batch the server runs in one request («everything matching» as a criteria) —
45
45
  * sincpro_framework#185.
46
46
  */
47
- export declare function useBatchCommand<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, name: N, options?: {
47
+ export declare function useBatchCommand<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>(entity: Entity<T, O>, name: N, options?: {
48
48
  limit?: number;
49
49
  concurrency?: number;
50
- }): BatchCommandState<AnswerOf<R, A, N>, C[N], T>;
50
+ }): BatchCommandState<CommandAnswer<R, O, N>, BodyOf<O, N>, T>;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { keysOf, listRoute, retryKeys, runBatch, } from "@sincpro/client-framework";
3
- import { sendRoute } from "../core/command.js";
2
+ import { keysOf, retryKeys, runBatch, } from "@sincpro/client-framework";
3
+ import { callFor, } from "../core/command.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useCallback, useEffect, useRef, useState } from "react";
6
6
  /** The most records a Command runs on at once from a screen, unless the screen says otherwise. */
@@ -15,7 +15,7 @@ export const BATCH_LIMIT = 200;
15
15
  *
16
16
  * Context: `for rec in self` from a screen. The keys come from the selection (`keysOf`: in
17
17
  * hand, or read once as references — never more than `limit`); each record is the Command sent
18
- * through the screens' transport — a use case of its own, traced — with an idempotency key of
18
+ * through the screens' operations — a use case of its own, traced — with an idempotency key of
19
19
  * its own, kept while it goes unanswered (`retryKeys`): a retry after a dropped request is the
20
20
  * same confirmation, never a second one. A failure is that record's (`runBatch`); the lists
21
21
  * follow every write as they do for one.
@@ -27,11 +27,11 @@ export const BATCH_LIMIT = 200;
27
27
  * sincpro_framework#185.
28
28
  */
29
29
  export function useBatchCommand(entity, name, options = {}) {
30
- const route = entity.commands[name];
31
- if (route === undefined)
30
+ const operation = entity.operations.commands?.[name];
31
+ if (operation === undefined)
32
32
  throw new Error(`${entity.key} declares no command "${name}"`);
33
33
  const { limit = BATCH_LIMIT, concurrency = 1 } = options;
34
- const { transport, metas } = useFramework();
34
+ const { operations, metas } = useFramework();
35
35
  const [running, setRunning] = useState(false);
36
36
  const [progress, setProgress] = useState(null);
37
37
  const [result, setResult] = useState(null);
@@ -57,9 +57,7 @@ export function useBatchCommand(entity, name, options = {}) {
57
57
  const gesture = gestures.current.get(key) ?? retryKeys();
58
58
  gestures.current.set(key, gesture);
59
59
  try {
60
- const answer = await sendRoute(transport, route, key, body, {
61
- idempotencyKey: gesture.keyFor({ id: key, body }),
62
- });
60
+ const answer = await callFor(operations, entity, operation, key, body, { idempotencyKey: gesture.keyFor({ id: key, body }) });
63
61
  gesture.settle(null);
64
62
  return answer;
65
63
  }
@@ -81,7 +79,7 @@ export function useBatchCommand(entity, name, options = {}) {
81
79
  setRunning(false);
82
80
  }
83
81
  return done;
84
- }, [transport, route, concurrency]);
82
+ }, [operations, entity, operation, concurrency]);
85
83
  return {
86
84
  run: async (selection, body) => {
87
85
  setError(null);
@@ -89,8 +87,8 @@ export function useBatchCommand(entity, name, options = {}) {
89
87
  let keys;
90
88
  try {
91
89
  keys = await keysOf(selection, {
92
- transport,
93
- route: listRoute(entity.list),
90
+ transport: operations,
91
+ entity,
94
92
  identity: meta?.get_id || meta?.identity || "id",
95
93
  limit,
96
94
  });
@@ -1,5 +1,6 @@
1
- import { type CommandAnswers, type CommandBodies, type Entity, type WriteRoute } from "@sincpro/client-framework";
1
+ import { type Entity, type EntityOperations, type Operation } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
+ import { type BodyOf, type CommandAnswer, type CommandName } from "../core/command.js";
3
4
  /**
4
5
  * One Command of an entity: run it, or ask first what it would do.
5
6
  *
@@ -13,16 +14,16 @@ import type { AnyRecord } from "@sincpro/criteria";
13
14
  * once sent, the same gesture keeps its `Idempotency-Key` until the server answers: a retry
14
15
  * after a dropped request is the same payment, never a second one (`retryKeys`).
15
16
  *
16
- * A typed entity (`entity<Issue, { send: { message: string } }>`) gets its names and bodies
17
- * checked: `useCommand(issues, "send").run(id, { mesage })` does not compile. TypeScript infers
18
- * that only when no type argument is written — `useCommand<Issue, Answer>(…)` stays loose.
17
+ * A generated entity types its Commands by their operations: `useCommand(issues, "send")` exists
18
+ * only when the entity has a `send`, and `.run(id, { mesage })` does not compile. TypeScript
19
+ * infers that only when no type argument is written — `useCommand<Issue, Answer>(…)` stays loose.
19
20
  */
20
21
  export type Rehearsal = {
21
22
  text: string;
22
23
  data: Record<string, unknown>;
23
24
  };
24
25
  export type CommandState<R, B extends AnyRecord = AnyRecord> = {
25
- /** Without a body, an empty one: the route may name everything. A body given is checked. */
26
+ /** Without a body, an empty one: the record may be all it needs. A body given is checked. */
26
27
  run: (id?: string, body?: B) => Promise<R | undefined>;
27
28
  /** The dry run: what it would do, nothing touched. */
28
29
  rehearse: (id?: string, body?: B) => Promise<Rehearsal | undefined>;
@@ -32,15 +33,10 @@ export type CommandState<R, B extends AnyRecord = AnyRecord> = {
32
33
  rehearsal: Rehearsal | null;
33
34
  reset: () => void;
34
35
  };
36
+ export declare function useCommand<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>(entity: Entity<T, O>, name: N): CommandState<CommandAnswer<R, O, N>, BodyOf<O, N>>;
35
37
  /**
36
- * What a Command answers: `R` when the screen writes it, else what its entity says the Command
37
- * answers (`CommandAnswers`), else `unknown`.
38
+ * One operation of an entity run as a Command on a record — what `useCommand` runs for a declared
39
+ * Command, and `useRecordLifecycle` for the record's own `delete`. `operation` may be absent (an
40
+ * entity that has none): the hook is still called, and running it is refused naming the entity.
38
41
  */
39
- export type AnswerOf<R, A, N> = unknown extends R ? (N extends keyof A ? A[N] : unknown) : R;
40
- export declare function useCommand<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, name: N): CommandState<AnswerOf<R, A, N>, C[N]>;
41
- /**
42
- * One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
43
- * and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
44
- * declares none): the hook is still called, and running it is refused naming the entity.
45
- */
46
- export declare function useRouteCommand<R, B extends AnyRecord = AnyRecord>(route: WriteRoute | undefined, owner: string): CommandState<R, B>;
42
+ export declare function useOperationCommand<R, B extends AnyRecord = AnyRecord>(entity: Pick<Entity, "key" | "model">, operation: Operation | undefined): CommandState<R, B>;
@@ -1,22 +1,22 @@
1
1
  "use client";
2
2
  import { retryKeys, } from "@sincpro/client-framework";
3
- import { sendRoute } from "../core/command.js";
3
+ import { callFor, } from "../core/command.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useCallback, useEffect, useRef, useState } from "react";
6
6
  export function useCommand(entity, name) {
7
7
  // A name outside the declared ones still reaches here from untyped code: say which.
8
- const route = entity.commands[name];
9
- if (route === undefined)
8
+ const operation = entity.operations.commands?.[name];
9
+ if (operation === undefined)
10
10
  throw new Error(`${entity.key} declares no command "${name}"`);
11
- return useRouteCommand(route, entity.key);
11
+ return useOperationCommand(entity, operation);
12
12
  }
13
13
  /**
14
- * One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
15
- * and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
16
- * declares none): the hook is still called, and running it is refused naming the entity.
14
+ * One operation of an entity run as a Command on a record — what `useCommand` runs for a declared
15
+ * Command, and `useRecordLifecycle` for the record's own `delete`. `operation` may be absent (an
16
+ * entity that has none): the hook is still called, and running it is refused naming the entity.
17
17
  */
18
- export function useRouteCommand(route, owner) {
19
- const { transport } = useFramework();
18
+ export function useOperationCommand(entity, operation) {
19
+ const { operations } = useFramework();
20
20
  const [busy, setBusy] = useState(false);
21
21
  const [error, setError] = useState(null);
22
22
  const [rehearsal, setRehearsal] = useState(null);
@@ -31,13 +31,15 @@ export function useRouteCommand(route, owner) {
31
31
  // not run it twice. A dry run touches nothing, so each one gets a key of its own.
32
32
  const keys = useRef(retryKeys());
33
33
  const send = useCallback(async (id, body, gesture) => {
34
- if (route === undefined)
35
- throw new Error(`${owner} declares no route for this`);
34
+ if (operation === undefined)
35
+ throw new Error(`${entity.key} has no operation for this`);
36
36
  setBusy(true);
37
37
  setError(null);
38
38
  const idempotencyKey = gesture.keyFor({ id, body });
39
39
  try {
40
- const answer = await sendRoute(transport, route, id, body, { idempotencyKey });
40
+ const answer = await callFor(operations, entity, operation, id, body, {
41
+ idempotencyKey,
42
+ });
41
43
  gesture.settle(null);
42
44
  return answer;
43
45
  }
@@ -51,7 +53,7 @@ export function useRouteCommand(route, owner) {
51
53
  if (mounted.current)
52
54
  setBusy(false);
53
55
  }
54
- }, [transport, route, owner]);
56
+ }, [operations, operation, entity]);
55
57
  return {
56
58
  run: (id, body) => send(id, body ?? {}, keys.current),
57
59
  rehearse: async (id, body) => {
@@ -1,4 +1,4 @@
1
- import type { CommandBodies, Entity } from "@sincpro/client-framework";
1
+ import type { Entity, EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord, Count, Criteria } from "@sincpro/criteria";
3
3
  import type { ListDefinition } from "../core/list.js";
4
4
  /**
@@ -15,4 +15,4 @@ import type { ListDefinition } from "../core/list.js";
15
15
  * the context and every write to the entity as any list does — a payment saved in a modal moves
16
16
  * the number behind it. Never a page fetched to be counted here.
17
17
  */
18
- export declare function useCount<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, criteria?: Criteria<T>): Count | null;
18
+ export declare function useCount<T extends AnyRecord, O extends EntityOperations = EntityOperations>(given: Entity<T, O> | ListDefinition<T>, criteria?: Criteria<T>): Count | null;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
- import { listRoute } from "@sincpro/client-framework";
2
+ import { readPage } from "@sincpro/client-framework";
3
3
  import { useFramework } from "./context.js";
4
- import { useEffect, useState } from "react";
4
+ import { useEffect, useRef, useState } from "react";
5
5
  /**
6
6
  * How many records each question keeps, asked together — a record's smart buttons («Sus pagos 4»,
7
7
  * «Cuotas pendientes 2»), as many as the record has. `null` while it is asked, or when the server
@@ -18,26 +18,27 @@ import { useEffect, useState } from "react";
18
18
  * process's context change.
19
19
  */
20
20
  export function useCounts(asked) {
21
- const { transport, context } = useFramework();
21
+ const { operations, context } = useFramework();
22
22
  // The questions by their content: a new array of the same questions asks nothing again.
23
- const key = JSON.stringify(asked.map((one) => [listRoute(one.entity.list), one.where]));
23
+ const key = JSON.stringify(asked.map((one) => [one.entity.key, one.where]));
24
+ // The entities of the questions now: the key says which, the latest render says what they are.
25
+ const entities = useRef(asked.map((one) => one.entity));
26
+ entities.current = asked.map((one) => one.entity);
24
27
  const [counted, setCounted] = useState();
25
28
  useEffect(() => {
26
29
  const questions = JSON.parse(key);
27
30
  if (questions.length === 0)
28
31
  return;
29
32
  let current = true;
30
- void Promise.all(questions.map(([route, where]) => transport
31
- .list(route, {
33
+ void Promise.all(questions.map(([, where], at) => readPage(operations, entities.current[at], {
32
34
  selection: where,
33
35
  count: "exact",
34
36
  pagination: { limit: 1 },
35
- })
36
- .then((page) => page.count?.value ?? null, () => null))).then((values) => {
37
+ }).then((page) => page.count?.value ?? null, () => null))).then((values) => {
37
38
  if (current)
38
39
  setCounted({ key, values });
39
40
  });
40
41
  return () => void (current = false);
41
- }, [transport, key, context]);
42
+ }, [operations, key, context]);
42
43
  return counted?.key === key ? counted.values : asked.map(() => null);
43
44
  }
@@ -1,6 +1,6 @@
1
1
  import { type AnyRecord, type Bucket } from "@sincpro/criteria";
2
2
  import type { GroupLevel } from "../core/list.js";
3
- import type { Listing } from "./useListing.js";
3
+ import { type Listing } from "./useListing.js";
4
4
  /**
5
5
  * The set of a list, split into groups — counted by the SERVER over every row that matches, a
6
6
  * page of groups at a time, each level read when its group is opened.