@sincpro/web-framework 1.1.0 → 2.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 (129) hide show
  1. package/README.md +188 -87
  2. package/dist/core/cache.d.ts +1 -2
  3. package/dist/core/cache.js +8 -5
  4. package/dist/core/explain.d.ts +15 -0
  5. package/dist/core/{transport.js → explain.js} +4 -26
  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 -15
  9. package/dist/core/index.js +8 -14
  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.d.ts +1 -0
  15. package/dist/core/present.js +54 -6
  16. package/dist/core/relation.d.ts +1 -1
  17. package/dist/core/relation.js +1 -1
  18. package/dist/core/summary.d.ts +1 -6
  19. package/dist/core/trail.d.ts +1 -1
  20. package/dist/core/trail.js +1 -0
  21. package/dist/errors/index.d.ts +48 -0
  22. package/dist/errors/index.js +56 -0
  23. package/dist/react/context.d.ts +6 -4
  24. package/dist/react/context.js +11 -3
  25. package/dist/react/index.d.ts +2 -0
  26. package/dist/react/index.js +2 -0
  27. package/dist/react/scope.d.ts +1 -1
  28. package/dist/react/scope.js +1 -1
  29. package/dist/react/useCommand.d.ts +1 -1
  30. package/dist/react/useCommand.js +1 -2
  31. package/dist/react/useContextValues.d.ts +15 -0
  32. package/dist/react/useContextValues.js +19 -0
  33. package/dist/react/useGroups.js +2 -2
  34. package/dist/react/useHistory.d.ts +1 -1
  35. package/dist/react/useHistory.js +3 -2
  36. package/dist/react/useListing.d.ts +4 -4
  37. package/dist/react/useListing.js +16 -7
  38. package/dist/react/useLookup.d.ts +1 -1
  39. package/dist/react/useLookup.js +3 -2
  40. package/dist/react/useNameOf.d.ts +1 -1
  41. package/dist/react/useNameOf.js +3 -3
  42. package/dist/react/usePivot.js +2 -2
  43. package/dist/react/useRecord.d.ts +1 -2
  44. package/dist/react/useRecord.js +18 -6
  45. package/dist/react/useRelated.d.ts +1 -1
  46. package/dist/react/useRelated.js +1 -0
  47. package/dist/react/useService.d.ts +38 -0
  48. package/dist/react/useService.js +66 -0
  49. package/dist/react/useSummary.d.ts +1 -1
  50. package/dist/react/useSummary.js +1 -0
  51. package/dist/telemetry/index.d.ts +45 -0
  52. package/dist/telemetry/index.js +55 -0
  53. package/dist/web/Refused.js +1 -1
  54. package/dist/web/index.d.ts +1 -1
  55. package/dist/web/index.js +1 -1
  56. package/dist/web/list/EntityList.d.ts +1 -1
  57. package/dist/web/list/EntityList.js +3 -3
  58. package/dist/web/list/EntitySearchBar.d.ts +2 -1
  59. package/dist/web/list/EntitySearchBar.js +17 -11
  60. package/dist/web/list/presentation.d.ts +1 -1
  61. package/dist/web/list/presentation.js +1 -0
  62. package/dist/web/list/rowCommands.d.ts +1 -1
  63. package/dist/web/list/rowCommands.js +1 -2
  64. package/dist/web/record/CommandButton.d.ts +1 -1
  65. package/dist/web/record/CommandButton.js +1 -0
  66. package/dist/web/record/EntityPicker.d.ts +8 -5
  67. package/dist/web/record/EntityPicker.js +6 -5
  68. package/dist/web/record/EntityTags.d.ts +1 -1
  69. package/dist/web/record/EntityTags.js +1 -0
  70. package/dist/web/record/RelatedList.d.ts +1 -1
  71. package/dist/web/record/RelatedList.js +1 -0
  72. package/dist/web/record/control.d.ts +4 -2
  73. package/dist/web/record/control.js +8 -5
  74. package/dist/web/record/edit.js +21 -1
  75. package/dist/web/record/lines.js +13 -2
  76. package/dist/web/record/opening.d.ts +1 -1
  77. package/dist/web/record/opening.js +1 -0
  78. package/dist/web/record/record.d.ts +12 -2
  79. package/dist/web/record/record.js +10 -2
  80. package/dist/web/workspace/SincproApp.d.ts +9 -20
  81. package/dist/web/workspace/SincproApp.js +17 -4
  82. package/dist/web/workspace/composer.d.ts +1 -2
  83. package/dist/web/workspace/composer.js +2 -2
  84. package/dist/web/workspace/open.d.ts +1 -1
  85. package/dist/web/workspace/open.js +1 -0
  86. package/dist/web/workspace/record.d.ts +60 -13
  87. package/dist/web/workspace/record.js +89 -28
  88. package/dist/web/workspace/workspace.d.ts +1 -1
  89. package/dist/web/workspace/workspace.js +1 -0
  90. package/package.json +45 -15
  91. package/dist/codegen/cli.d.ts +0 -2
  92. package/dist/codegen/cli.js +0 -82
  93. package/dist/codegen/client.d.ts +0 -14
  94. package/dist/codegen/client.js +0 -178
  95. package/dist/codegen/domain.d.ts +0 -14
  96. package/dist/codegen/domain.js +0 -195
  97. package/dist/codegen/entities.d.ts +0 -14
  98. package/dist/codegen/entities.js +0 -158
  99. package/dist/codegen/index.d.ts +0 -11
  100. package/dist/codegen/index.js +0 -9
  101. package/dist/codegen/metamodel.d.ts +0 -89
  102. package/dist/codegen/metamodel.js +0 -1
  103. package/dist/codegen/names.d.ts +0 -40
  104. package/dist/codegen/names.js +0 -114
  105. package/dist/codegen/rest.d.ts +0 -31
  106. package/dist/codegen/rest.js +0 -27
  107. package/dist/core/contract.d.ts +0 -34
  108. package/dist/core/contract.js +0 -41
  109. package/dist/core/discovery.d.ts +0 -47
  110. package/dist/core/discovery.js +0 -68
  111. package/dist/core/entity.d.ts +0 -227
  112. package/dist/core/entity.js +0 -187
  113. package/dist/core/ids.d.ts +0 -17
  114. package/dist/core/ids.js +0 -52
  115. package/dist/core/memory.d.ts +0 -46
  116. package/dist/core/memory.js +0 -108
  117. package/dist/core/meta.d.ts +0 -121
  118. package/dist/core/meta.js +0 -130
  119. package/dist/core/metas.d.ts +0 -17
  120. package/dist/core/metas.js +0 -7
  121. package/dist/core/rest.d.ts +0 -49
  122. package/dist/core/rest.js +0 -143
  123. package/dist/core/retry.d.ts +0 -24
  124. package/dist/core/retry.js +0 -25
  125. package/dist/core/schema.d.ts +0 -39
  126. package/dist/core/schema.js +0 -128
  127. package/dist/core/transport.d.ts +0 -90
  128. package/dist/core/zone.d.ts +0 -27
  129. package/dist/core/zone.js +0 -75
@@ -1,5 +1,5 @@
1
+ import { type Entity, type EntityRef } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Criteria, Expression, Grain, Sort } from "@sincpro/criteria";
2
- import type { Entity, EntityRef } from "./entity.js";
3
3
  /**
4
4
  * A named way of looking at an entity: «Por cobrar», «Borradores», «Mis tickets».
5
5
  *
@@ -17,9 +17,9 @@ import type { Entity, EntityRef } from "./entity.js";
17
17
  * export const porCobrar = defineList(facturas, {
18
18
  * id: "por-cobrar",
19
19
  * title: "Por cobrar",
20
- * scope: { where: { field: "state", operator: "=", value: "posted" } },
20
+ * scope: { selection: { field: "state", operator: "=", value: "posted" } },
21
21
  * columns: ["number", "customer", "due_date", "amount_total"],
22
- * filters: [{ id: "vencidas", label: "Vencidas", where: … }],
22
+ * filters: [{ id: "vencidas", label: "Vencidas", selection: … }],
23
23
  * });
24
24
  */
25
25
  export type ListDefinition<T extends AnyRecord = AnyRecord> = {
@@ -49,7 +49,8 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
49
49
  export type NamedFilter<T> = {
50
50
  id: string;
51
51
  label: string;
52
- where: Expression<T>;
52
+ /** What it keeps, as criteria's `selection`. */
53
+ selection: Expression<T>;
53
54
  };
54
55
  /** One level of a grouping: by which field, and by which cut of time when it is a date. */
55
56
  export type GroupLevel = {
package/dist/core/list.js CHANGED
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  export function defineList(entity, spec) {
2
3
  if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
3
4
  throw new Error(`list id "${spec.id}" is not kebab-case: it becomes a workspace kind`);
@@ -1,5 +1,5 @@
1
+ import { type SummaryFields } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
- import { type SummaryFields } from "./summary.js";
3
3
  /**
4
4
  * A record as a choice: what a many2one select, a «share with» and ⌘K show for it.
5
5
  *
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  import { summaryFieldsOf } from "./summary.js";
2
3
  export function lookupOf(meta, rows, summary = {}) {
3
4
  const key = meta?.get_id || meta?.identity || "id";
@@ -38,6 +38,7 @@ export declare const BOOKKEEPING: ReadonlySet<string>;
38
38
  * textOf(meta, "active", true, "es") -> "sí"
39
39
  * textOf(meta, "due", "2026-03-12", "es") -> "12 mar 2026"
40
40
  * textOf(meta, "total", "1150.5", "es") -> "1150,5" (exact: digits kept)
41
+ * textOf(meta, "price", { amount: "19.9", currency: "BOB" }, "es") -> "19,90 Bs"
41
42
  * textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
42
43
  */
43
44
  export declare function textOf(meta: Meta | null | undefined, name: string, value: unknown, locale?: string): string | null;
@@ -1,7 +1,7 @@
1
+ import { Money, timeZoneNow } from "@sincpro/client-framework";
1
2
  import { choiceLabelOf, labelOf, } from "@sincpro/criteria";
2
3
  import { frameworkCopy } from "./copy.js";
3
4
  import { relatedOf } from "./related.js";
4
- import { timeZoneNow } from "./zone.js";
5
5
  /** Present when a field is named that the model does not declare: drawn plain, never thrown. */
6
6
  const UNKNOWN = {
7
7
  type: "unknown",
@@ -85,6 +85,50 @@ function numberFormat(locale, kept) {
85
85
  }
86
86
  return format;
87
87
  }
88
+ /** The currency codes `Intl` refused, by locale: asked once, not on every cell. */
89
+ const unknownCurrencies = new Set();
90
+ function currencyFormat(locale, currency) {
91
+ const key = `c|${locale ?? ""}|${currency}`;
92
+ if (unknownCurrencies.has(key))
93
+ return null;
94
+ let format = formatters.get(key);
95
+ if (format === undefined) {
96
+ try {
97
+ format = new Intl.NumberFormat(locale, {
98
+ style: "currency",
99
+ currency,
100
+ minimumFractionDigits: Money.decimalsOf(currency),
101
+ maximumFractionDigits: Money.decimalsOf(currency),
102
+ });
103
+ }
104
+ catch {
105
+ // Not an ISO 4217 code Intl knows (a token, a loyalty point): drawn as «amount CODE».
106
+ unknownCurrencies.add(key);
107
+ return null;
108
+ }
109
+ formatters.set(key, format);
110
+ }
111
+ return format;
112
+ }
113
+ /**
114
+ * A money as a person reads it: `{ amount: "1150.5", currency: "BOB" }` → «Bs 1.150,50». The
115
+ * amount goes to `Intl` as text, so no digit passes through a float, rounded to the currency's
116
+ * decimals as an invoice shows it (`Money.rounded`).
117
+ */
118
+ function moneyText(value, locale) {
119
+ let money;
120
+ try {
121
+ money = Money.fromJSON(value).rounded();
122
+ }
123
+ catch {
124
+ // A money of the right shape with an amount or a code that is not one (`"1,50"`, `""`): no
125
+ // text, as any value object — never an error that takes the whole view down.
126
+ return null;
127
+ }
128
+ const amount = money.amount;
129
+ return (currencyFormat(locale, money.currency)?.format(amount) ??
130
+ `${numberFormat(locale, money.decimals).format(amount)} ${money.currency}`);
131
+ }
88
132
  /** The record a many2one points at, read by the display its definition names. */
89
133
  function displayOf(field, value) {
90
134
  const definition = field.definition;
@@ -101,6 +145,7 @@ function displayOf(field, value) {
101
145
  * textOf(meta, "active", true, "es") -> "sí"
102
146
  * textOf(meta, "due", "2026-03-12", "es") -> "12 mar 2026"
103
147
  * textOf(meta, "total", "1150.5", "es") -> "1150,5" (exact: digits kept)
148
+ * textOf(meta, "price", { amount: "19.9", currency: "BOB" }, "es") -> "19,90 Bs"
104
149
  * textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
105
150
  */
106
151
  export function textOf(meta, name, value, locale) {
@@ -125,11 +170,13 @@ export function textOf(meta, name, value, locale) {
125
170
  }
126
171
  case "integer":
127
172
  case "number": {
128
- const number = Number(value);
129
- if (Number.isNaN(number))
173
+ if (Number.isNaN(Number(value)))
130
174
  return String(value);
131
- const kept = typeof value === "string" ? decimals(value) : undefined;
132
- return numberFormat(locale, kept).format(number);
175
+ // A decimal that travels as text goes to `Intl` as text: every digit kept, none through a
176
+ // float (`"12345678901234567.89"` reads whole).
177
+ if (typeof value === "string")
178
+ return numberFormat(locale, decimals(value)).format(value.trim());
179
+ return numberFormat(locale, undefined).format(Number(value));
133
180
  }
134
181
  case "text[]":
135
182
  return Array.isArray(value)
@@ -145,7 +192,8 @@ export function textOf(meta, name, value, locale) {
145
192
  case "many2one":
146
193
  return typeof value === "object" ? displayOf(field, value) : String(value);
147
194
  case "embedded":
148
- return null;
195
+ // A value object has no text of its own — but a money, the one every ERP holds, does.
196
+ return Money.isMoney(value) ? moneyText(value, locale) : null;
149
197
  default:
150
198
  return typeof value === "object" ? JSON.stringify(value) : String(value);
151
199
  }
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import type { FieldMeta, Meta } from "@sincpro/criteria";
2
- import type { Entity } from "./entity.js";
3
3
  /**
4
4
  * Which record a field of a form is about, read from the model — so a form draws a many2one
5
5
  * as a picker of the right entity without being told.
@@ -1,4 +1,4 @@
1
- import { entityKeyOf, kindOf } from "./contract.js";
1
+ import { entityKeyOf, kindOf } from "@sincpro/client-framework";
2
2
  export function relationFieldOf(meta, name) {
3
3
  if (!meta)
4
4
  return undefined;
@@ -1,3 +1,4 @@
1
+ import type { SummaryFields, SummaryPart } from "@sincpro/client-framework";
1
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
3
  /**
3
4
  * What is known about ANY record, the same for every entity: its name and, when it has them,
@@ -13,12 +14,6 @@ import type { AnyRecord, Meta } from "@sincpro/criteria";
13
14
  * …). The name is the model's own `display`. When the backend publishes these parts in its
14
15
  * model definition, they are read from there and the convention steps aside.
15
16
  */
16
- export type SummaryPart = "description" | "state" | "type" | "image" | "createdAt" | "createdBy" | "updatedAt" | "updatedBy";
17
- /** Which field of the entity plays each part, when it is not the conventional one.
18
- * `person`: its records are people or companies — a round face, initials without a photo. */
19
- export type SummaryFields = Partial<Record<SummaryPart, string>> & {
20
- person?: boolean;
21
- };
22
17
  export type RecordSummary = {
23
18
  id: string;
24
19
  name: string;
@@ -1,5 +1,5 @@
1
+ import { type Transport } from "@sincpro/client-framework";
1
2
  import type { Criteria } from "@sincpro/criteria";
2
- import type { Transport } from "./transport.js";
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
5
5
  * to the previous and the next one — «3 / 64» and two arrows — without going back to the list.
@@ -1,3 +1,4 @@
1
+ import {} from "@sincpro/client-framework";
1
2
  import { resumingFrom } from "@sincpro/criteria";
2
3
  /** Where a record stands in its trail: «3 of 64», 1-based. */
3
4
  export function placeOf(trail, id) {
@@ -0,0 +1,48 @@
1
+ import type { ErrorReporter } from "@sincpro/client-framework";
2
+ /**
3
+ * An `ErrorReporter` for the browser, built from the application's own settings: a
4
+ * Sentry-compatible client — GlitchTip, where the backend reports too — with the application's
5
+ * DSN.
6
+ *
7
+ * // the application — domains/common/infrastructure/telemetry.ts
8
+ * import { glitchtipReporter } from "./index.js";
9
+ * const reporter = glitchtipReporter({ dsn: settings.glitchtip, release, environment });
10
+ * configureProcess({ tracer, reporter }); // entrypoints/main.tsx
11
+ *
12
+ * Context: optional on every count, like `./telemetry`: an entry of its own, `@sentry/browser`
13
+ * an optional peer, and only a convenience — an application with its own client wraps it with
14
+ * `sentryReporter` (`@sincpro/client-framework/sentry`), or hands any `ErrorReporter`.
15
+ *
16
+ * It never breaks what it serves: the SDK loads after the first render; what is reported before
17
+ * it is there waits (a handful), and if it is not installed or fails, reports are dropped and
18
+ * that is said once on the console. Nothing global: no `Sentry.init`, no handlers on `window` —
19
+ * this client is the reporter's own, and only what the process decides is unexpected reaches it.
20
+ *
21
+ * What it sends is narrow by default, because in an ERP a request body is an invoice and a
22
+ * customer: no breadcrumbs or default integrations, and every event leaves without cookies,
23
+ * headers, request bodies, query strings or the user's address. `beforeSend` is the
24
+ * application's, run after that.
25
+ */
26
+ export type GlitchtipOptions = {
27
+ /** The application's DSN. Public by nature: it ships to the browser. */
28
+ dsn: string;
29
+ release?: string;
30
+ environment?: string;
31
+ /** Fraction of errors sent, 0 to 1. Default 1. */
32
+ sampling?: number;
33
+ /** The application's last word on an event: change it, or answer `null` to drop it. */
34
+ beforeSend?: (event: SentEvent) => SentEvent | null;
35
+ };
36
+ /** The parts of an event this reporter narrows; the rest passes as the SDK built it. */
37
+ export type SentEvent = {
38
+ request?: {
39
+ url?: string;
40
+ cookies?: unknown;
41
+ headers?: unknown;
42
+ data?: unknown;
43
+ query_string?: unknown;
44
+ };
45
+ user?: unknown;
46
+ [key: string]: unknown;
47
+ };
48
+ export declare function glitchtipReporter(options: GlitchtipOptions): ErrorReporter;
@@ -0,0 +1,56 @@
1
+ const WAITING_AT_MOST = 20;
2
+ /** Every event leaves without what may carry a person's or a customer's data. */
3
+ function narrowed(event) {
4
+ const { user: _user, ...rest } = event;
5
+ if (rest.request === undefined)
6
+ return rest;
7
+ const { cookies: _c, headers: _h, data: _d, query_string: _q, ...request } = rest.request;
8
+ return {
9
+ ...rest,
10
+ request: { ...request, ...(request.url ? { url: request.url.split("?")[0] } : {}) },
11
+ };
12
+ }
13
+ export function glitchtipReporter(options) {
14
+ let ready = null;
15
+ let failed = false;
16
+ const waiting = [];
17
+ void (async () => {
18
+ try {
19
+ const [sentry, { sentryReporter }] = await Promise.all([
20
+ import("@sentry/browser"),
21
+ import("@sincpro/client-framework/sentry"),
22
+ ]);
23
+ const client = new sentry.BrowserClient({
24
+ dsn: options.dsn,
25
+ transport: sentry.makeFetchTransport,
26
+ stackParser: sentry.defaultStackParser,
27
+ integrations: [],
28
+ ...(options.release ? { release: options.release } : {}),
29
+ ...(options.environment ? { environment: options.environment } : {}),
30
+ ...(options.sampling === undefined ? {} : { sampleRate: options.sampling }),
31
+ beforeSend: (event) => {
32
+ const own = narrowed(event);
33
+ const kept = options.beforeSend ? options.beforeSend(own) : own;
34
+ return kept;
35
+ },
36
+ });
37
+ client.init();
38
+ ready = sentryReporter(client);
39
+ for (const [error, about] of waiting.splice(0))
40
+ ready.report(error, about);
41
+ }
42
+ catch (error) {
43
+ failed = true;
44
+ waiting.length = 0;
45
+ console.warn("@sincpro/web-framework/errors: error reporting is off — @sentry/browser did not load", error);
46
+ }
47
+ })();
48
+ return {
49
+ report(error, about) {
50
+ if (ready !== null)
51
+ return ready.report(error, about);
52
+ if (!failed && waiting.length < WAITING_AT_MOST)
53
+ waiting.push([error, about]);
54
+ },
55
+ };
56
+ }
@@ -1,8 +1,6 @@
1
+ import { type Entity, type MetaStore, type Transport } from "@sincpro/client-framework";
1
2
  import type { Meta } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
- import { type MetaStore } from "../core/metas.js";
4
3
  import type { Trail } from "../core/trail.js";
5
- import type { Transport } from "../core/transport.js";
6
4
  import { type ReactNode } from "react";
7
5
  /**
8
6
  * Who answers, in which language a screen reads, and which model definitions are already
@@ -18,7 +16,9 @@ import { type ReactNode } from "react";
18
16
  * `api.choosing` (what a chooser was asked, in memory) and `api.context` (what the user is on,
19
17
  * what is selected). Read `~/dev/sincpro_web_composer/README.md` before writing a second one
20
18
  * here. A value the backend must see on every request (the active company) goes in the
21
- * transport's `headers` — the backend's `sincpro-context` header is read by every entrance.
19
+ * process's context (`processContext.set({ company_id })`, @sincpro/client-framework): every
20
+ * request under this provider carries it in `sincpro-context` (`screensTransport`), and a change
21
+ * reads every screen again.
22
22
  */
23
23
  type FrameworkContextValue = {
24
24
  transport: Transport;
@@ -28,6 +28,8 @@ type FrameworkContextValue = {
28
28
  entities: readonly Entity[];
29
29
  /** Where each open record came from (`Trail`), by the key its reference carries. */
30
30
  trails: Map<string, Trail>;
31
+ /** The process's context now: a reading reads again when it changes (another company). */
32
+ context: Readonly<Record<string, unknown>>;
31
33
  };
32
34
  export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, children, }: {
33
35
  transport: Transport;
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { metaStore } from "../core/metas.js";
3
+ import { installTimeZone, metaStore, processContext, screensTransport, } from "@sincpro/client-framework";
4
4
  import { entityFor } from "../core/relation.js";
5
- import { installTimeZone } from "../core/zone.js";
5
+ import { useContextValues } from "./useContextValues.js";
6
6
  import { createContext, useContext, useMemo, useRef, useState } from "react";
7
7
  const FrameworkContext = createContext(null);
8
8
  export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, children, }) {
@@ -17,7 +17,15 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
17
17
  // the screens already learned.
18
18
  const [metas] = useState(() => metaStore(seed));
19
19
  const [trails] = useState(() => new Map());
20
- const value = useMemo(() => ({ transport, locale, metas, entities, trails }), [transport, locale, metas, entities, trails]);
20
+ // What the screens read and write is a use case of `screens` (`screensTransport`,
21
+ // client-framework): each request traced, carrying the process's context (the company, the
22
+ // tenant) read at the moment it is sent, and reported when it failed unexpectedly.
23
+ const screens = useMemo(() => screensTransport(transport), [transport]);
24
+ // When the context changes, every reading on screen reads its same question again — a list
25
+ // keeps its filter, order and page, a record what was typed (`useListing`, `useRecord`). The
26
+ // transport stays the same one: a new one would start every reading over.
27
+ const context = useContextValues(processContext);
28
+ const value = useMemo(() => ({ transport: screens, locale, metas, entities, trails, context }), [screens, locale, metas, entities, trails, context]);
21
29
  return _jsx(FrameworkContext.Provider, { value: value, children: children });
22
30
  }
23
31
  const NO_ENTITIES = [];
@@ -6,6 +6,7 @@
6
6
  export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
7
7
  export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
8
8
  export { type AnswerOf, type CommandState, type Rehearsal, useCommand, } from "./useCommand.js";
9
+ export { useContextValues } from "./useContextValues.js";
9
10
  export { type Groups, useGroups } from "./useGroups.js";
10
11
  export { useHistory } from "./useHistory.js";
11
12
  export { type Listing, type ListingOptions, type Paging, useListing, } from "./useListing.js";
@@ -14,4 +15,5 @@ export { useNameOf } from "./useNameOf.js";
14
15
  export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
15
16
  export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
16
17
  export { useRelated } from "./useRelated.js";
18
+ export { type ServiceState, useService } from "./useService.js";
17
19
  export { useSummaryOf } from "./useSummary.js";
@@ -6,6 +6,7 @@
6
6
  export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
7
7
  export { ListScopeProvider, useListScope, } from "./scope.js";
8
8
  export { useCommand, } from "./useCommand.js";
9
+ export { useContextValues } from "./useContextValues.js";
9
10
  export { useGroups } from "./useGroups.js";
10
11
  export { useHistory } from "./useHistory.js";
11
12
  export { useListing, } from "./useListing.js";
@@ -14,4 +15,5 @@ export { useNameOf } from "./useNameOf.js";
14
15
  export { usePivot, } from "./usePivot.js";
15
16
  export { useRecord, } from "./useRecord.js";
16
17
  export { useRelated } from "./useRelated.js";
18
+ export { useService } from "./useService.js";
17
19
  export { useSummaryOf } from "./useSummary.js";
@@ -13,7 +13,7 @@ import { type ReactNode } from "react";
13
13
  */
14
14
  export type ListScope = {
15
15
  key: string;
16
- where: Expression;
16
+ selection: Expression;
17
17
  };
18
18
  export declare function ListScopeProvider({ value, children, }: {
19
19
  value: ListScope;
@@ -8,5 +8,5 @@ export function ListScopeProvider({ value, children, }) {
8
8
  /** The cut the screen gave for the lists of `key`, or none. */
9
9
  export function useListScope(key) {
10
10
  const scope = useContext(Scope);
11
- return scope !== null && scope.key === key ? scope.where : undefined;
11
+ return scope !== null && scope.key === key ? scope.selection : undefined;
12
12
  }
@@ -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 CommandAnswers, type CommandBodies, type Entity } from "../core/entity.js";
3
3
  /**
4
4
  * One Command of an entity: run it, or ask first what it would do.
5
5
  *
@@ -1,6 +1,5 @@
1
1
  "use client";
2
- import { bodyFor, pathFor, } from "../core/entity.js";
3
- import { retryKeys } from "../core/retry.js";
2
+ import { bodyFor, pathFor, retryKeys, } from "@sincpro/client-framework";
4
3
  import { useFramework } from "./context.js";
5
4
  import { useCallback, useEffect, useRef, useState } from "react";
6
5
  export function useCommand(entity, name) {
@@ -0,0 +1,15 @@
1
+ import type { Context, ContextValues } from "@sincpro/client-framework";
2
+ /**
3
+ * The values of one level of the context, drawn again whenever they change.
4
+ *
5
+ * const { company_id } = useContextValues(processContext); // the company picker changed it
6
+ * const own = useContextValues(project.context); // only what «project» runs with
7
+ *
8
+ * Context: the context is @sincpro/client-framework's — what every use case runs with and sends
9
+ * to the server — and where it lives is the platform's (`ContextStore`, chosen in `main` with
10
+ * `configureProcess`). A screen only reads it: a level's `values` is the same object until it
11
+ * changes and its `watch` is bound, which is exactly what React's external stores ask for. Writing
12
+ * stays the level's (`processContext.set({ company_id })`), so a screen, a service and a test
13
+ * change it the same way and nothing here is a second store.
14
+ */
15
+ export declare function useContextValues<C extends object = ContextValues>(context: Context<C>): Readonly<Partial<C>>;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { useSyncExternalStore } from "react";
3
+ /**
4
+ * The values of one level of the context, drawn again whenever they change.
5
+ *
6
+ * const { company_id } = useContextValues(processContext); // the company picker changed it
7
+ * const own = useContextValues(project.context); // only what «project» runs with
8
+ *
9
+ * Context: the context is @sincpro/client-framework's — what every use case runs with and sends
10
+ * to the server — and where it lives is the platform's (`ContextStore`, chosen in `main` with
11
+ * `configureProcess`). A screen only reads it: a level's `values` is the same object until it
12
+ * changes and its `watch` is bound, which is exactly what React's external stores ask for. Writing
13
+ * stays the level's (`processContext.set({ company_id })`), so a screen, a service and a test
14
+ * change it the same way and nothing here is a second store.
15
+ */
16
+ export function useContextValues(context) {
17
+ const values = () => context.values;
18
+ return useSyncExternalStore(context.watch, values, values);
19
+ }
@@ -8,7 +8,7 @@ const MAX_GROUPS = 100;
8
8
  /** A group is known by its criteria: unique per group, and stable across renders. */
9
9
  const keyOf = (bucket) => JSON.stringify(bucket.criteria);
10
10
  export function useGroups(listing, options = {}) {
11
- const { transport } = useFramework();
11
+ const { transport, context } = useFramework();
12
12
  // A named list may open grouped (`groupBy`); a person regroups from there.
13
13
  const [levels, setLevels] = useState(() => listing.definition?.groupBy ?? []);
14
14
  const [state, setState] = useState({ status: "idle", buckets: [], error: null });
@@ -54,7 +54,7 @@ export function useGroups(listing, options = {}) {
54
54
  setState({ status: "failed", buckets: [], error });
55
55
  });
56
56
  return () => aborter.abort();
57
- }, [transport, route, question, levels, sums, waiting]);
57
+ }, [transport, route, question, levels, sums, waiting, context]);
58
58
  /** One page of a group: the first (`after` null) or the one the cursor points at. */
59
59
  const read = useCallback((bucket, after) => {
60
60
  const key = keyOf(bucket);
@@ -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 HistoryEntry } from "../core/history.js";
4
4
  import { type DependencyList } from "react";
5
5
  export declare function useHistory<T extends AnyRecord>(entity: Entity<T>, id: string, deps?: DependencyList): HistoryEntry[] | undefined;
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { historyOf } from "../core/history.js";
3
4
  import { useFramework } from "./context.js";
4
5
  import { useEffect, useState } from "react";
@@ -16,7 +17,7 @@ import { useEffect, useState } from "react";
16
17
  */
17
18
  const SHOWN = 100;
18
19
  export function useHistory(entity, id, deps = []) {
19
- const { transport, locale } = useFramework();
20
+ const { transport, locale, context } = useFramework();
20
21
  const [entries, setEntries] = useState(undefined);
21
22
  const history = entity.history;
22
23
  useEffect(() => {
@@ -36,6 +37,6 @@ export function useHistory(entity, id, deps = []) {
36
37
  transport.list(history.route, criteria, aborter.signal).then((page) => aborter.signal.aborted || setEntries(historyOf(page.rows, page.meta, locale)), () => aborter.signal.aborted || setEntries(undefined));
37
38
  return () => aborter.abort();
38
39
  // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller names what reloads it
39
- }, [transport, history, id, locale, ...deps]);
40
+ }, [transport, history, id, locale, context, ...deps]);
40
41
  return entries;
41
42
  }
@@ -1,5 +1,5 @@
1
+ import { type CommandBodies, type Entity } from "@sincpro/client-framework";
1
2
  import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type ReadingStatus, type Sort } from "@sincpro/criteria";
2
- import { type CommandBodies, type Entity } from "../core/entity.js";
3
3
  import { type ListDefinition } from "../core/list.js";
4
4
  /**
5
5
  * N records of an entity, live: what a list draws and the gestures that drive it.
@@ -47,9 +47,9 @@ export type Listing<T, C extends CommandBodies = CommandBodies> = {
47
47
  search: (text: string, options?: {
48
48
  now?: boolean;
49
49
  }) => void;
50
- /** What the search bar put; `undefined` is nothing. */
51
- where: Expression<T> | undefined;
52
- filter: (where: Expression<T> | undefined) => void;
50
+ /** What the search bar put, as criteria's `selection`; `undefined` is nothing. */
51
+ selection: Expression<T> | undefined;
52
+ filter: (selection: Expression<T> | undefined) => void;
53
53
  /** The order the server was asked for, by one field then the next; empty is the entity's own
54
54
  * default. */
55
55
  order: readonly Sort[];
@@ -1,7 +1,7 @@
1
1
  "use client";
2
+ import { listRoute } from "@sincpro/client-framework";
2
3
  import { merge, resource, resumingFrom, searchOver, } from "@sincpro/criteria";
3
4
  import { useReading } from "@sincpro/criteria-react";
4
- import { listRoute, } from "../core/entity.js";
5
5
  import { isList, scopeOf } from "../core/list.js";
6
6
  import { useFramework } from "./context.js";
7
7
  import { useListScope } from "./scope.js";
@@ -9,7 +9,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9
9
  /** How long typing has to pause before the search goes out. */
10
10
  const TYPING_PAUSE = 200;
11
11
  export function useListing(given, own = {}) {
12
- const { transport, locale, metas } = useFramework();
12
+ const { transport, locale, metas, context } = useFramework();
13
13
  // A named list is its entity under a fixed scope: the scope ANDs under the caller's own.
14
14
  const definition = isList(given) ? given : undefined;
15
15
  // A named list's entity has no typed Commands of its own: the default, as `C` then is.
@@ -51,18 +51,27 @@ export function useListing(given, own = {}) {
51
51
  const meta = reading.meta ?? known.current;
52
52
  const [narrowing, setNarrowing] = useState({
53
53
  text: "",
54
- where: undefined,
54
+ selection: undefined,
55
55
  order: [],
56
56
  });
57
57
  const typing = useRef(null);
58
58
  useEffect(() => () => void (typing.current && clearTimeout(typing.current)), []);
59
+ // Another company (the process's context changed): the same question read again — its filter,
60
+ // order and page kept, never a reading started over.
61
+ const askedIn = useRef(context);
62
+ useEffect(() => {
63
+ if (askedIn.current === context)
64
+ return;
65
+ askedIn.current = context;
66
+ void reading.reload();
67
+ }, [context, reading]);
59
68
  const narrowed = (next) => {
60
69
  let criteria = base;
61
70
  const found = searchOver(meta, next.text);
62
71
  if (found !== undefined)
63
72
  criteria = merge(criteria, { selection: found });
64
- if (next.where !== undefined)
65
- criteria = merge(criteria, { selection: next.where });
73
+ if (next.selection !== undefined)
74
+ criteria = merge(criteria, { selection: next.selection });
66
75
  if (next.order.length > 0)
67
76
  criteria = merge(criteria, { order: [...next.order] });
68
77
  return criteria;
@@ -135,8 +144,8 @@ export function useListing(given, own = {}) {
135
144
  reload: () => void reading.reload(),
136
145
  text: narrowing.text,
137
146
  search: (text, options) => narrow({ text }, options?.now !== true),
138
- where: narrowing.where,
139
- filter: (where) => narrow({ where }, false),
147
+ selection: narrowing.selection,
148
+ filter: (selection) => narrow({ selection }, false),
140
149
  order: narrowing.order,
141
150
  orderBy: (order) => narrow({ order: order === null ? [] : Array.isArray(order) ? order : [order] }, false),
142
151
  paging,
@@ -1,5 +1,5 @@
1
+ import { type Entity } from "@sincpro/client-framework";
1
2
  import { type AnyRecord, type Criteria, type Meta } from "@sincpro/criteria";
2
- import type { Entity } from "../core/entity.js";
3
3
  import { type ListDefinition } from "../core/list.js";
4
4
  import { type LookupOption } from "../core/lookup.js";
5
5
  /**
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import {} from "@sincpro/client-framework";
2
3
  import { merge } from "@sincpro/criteria";
3
4
  import { isList } from "../core/list.js";
4
5
  import { lookupOf } from "../core/lookup.js";
@@ -23,7 +24,7 @@ export function excluding(criteria, exclude, meta) {
23
24
  export function useLookup(
24
25
  /** The entity, or a named list of it: «active customers» chooses only those. */
25
26
  entity, options = {}) {
26
- const { transport, metas } = useFramework();
27
+ const { transport, metas, context } = useFramework();
27
28
  const base = isList(entity) ? entity.entity : entity;
28
29
  // The key field to exclude by comes with the definition: known already, or with the first
29
30
  // answer — then this renders again and the reading starts over without the excluded.
@@ -76,7 +77,7 @@ entity, options = {}) {
76
77
  })
77
78
  .catch(() => undefined); // unnamed is not an error: the field shows its key
78
79
  return () => aborter.abort();
79
- }, [transport, route, meta, missingKey, base.summary]);
80
+ }, [transport, route, meta, missingKey, base.summary, context]);
80
81
  const known = value === "" ? undefined : seen.current.get(value);
81
82
  const chosenAll = wanted.map((id) => seen.current.get(id) ?? { id, label: id });
82
83
  return {
@@ -1,4 +1,4 @@
1
- import { type Entity } from "../core/entity.js";
1
+ import { type Entity } from "@sincpro/client-framework";
2
2
  /**
3
3
  * The name of one record of an entity, by its key — what a field shows when it holds only the
4
4
  * key (`EntityID[Tenant]`) and not the record it points at.