@sincpro/client-framework 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -509,6 +509,7 @@ import { sentryReporter } from "@sincpro/client-framework/sentry";
509
509
 
510
510
  configureProcess({
511
511
  identity: { release: "forge-web:1.4.0" }, // + tenant, when the deployment serves one
512
+ timeZone: { keys: ["timezone"] }, // where a run's zone is read from — the backend's key, the default
512
513
  tracer: openTelemetryTracer(provider.getTracer("forge-web")), // the app's provider
513
514
  reporter: sentryReporter(client), // the app's Sentry or GlitchTip client
514
515
  logger: { mode: production ? "production" : "development" },
@@ -625,6 +626,26 @@ optional `watch`. `memoryContexts()` is the default; a browser, a phone or a ser
625
626
  its own. `values` is the same object until it changes, so a screen can hand it to React's
626
627
  `useSyncExternalStore`.
627
628
 
629
+ ### The time zone of a run
630
+
631
+ A run reads days and times in the zone its context says, not in the device's: a user in La Paz
632
+ looking at a company in Madrid sees «today» as Madrid's. The zone is the context's `timezone` —
633
+ the key sincpro_framework reads to cut `today` and `period` —; with none, the process's zone
634
+ (`installTimeZone`, else the platform's).
635
+
636
+ ```ts
637
+ await salesBoundedContext.scoped({ timezone: "Europe/Madrid" }).execute(new CommandQuote(1));
638
+
639
+ const zone = timeZoneOf(this.execution); // or timeZoneOf(context)
640
+ dayOf(instant, zone); // «today» for that company
641
+ ```
642
+
643
+ The context travels to the server in `sincpro-context`, so under `timezone` the backend cuts days
644
+ the same way. An application that keeps the zone under another key names it —
645
+ `configureProcess({ timeZone: { keys: ["company_zone", "timezone"] } })`, the first found wins —,
646
+ but the backend reads only `timezone`: a zone under another key is the client's alone, and the
647
+ server cuts in UTC.
648
+
628
649
  ## Talking to a server
629
650
 
630
651
  A remote service is reached through a port. The generated client never names a wire: it says
@@ -645,7 +666,7 @@ await forge.sendIssue({ issue_id: "acme-3", message: "hola" }); // ResponseSendI
645
666
  | Piece | What it does |
646
667
  | --------------------------------- | ------------------------------------------------------------------------------------- |
647
668
  | `OperationTransport` port | `call(operation, input, options)`: an operation by who it is, over any wire |
648
- | `restOperations(transport)` | over REST: the path from the input's fields, a Query's query, a Command's body |
669
+ | `restOperations(transport)` | over REST: the path from the input, a Query's and a DELETE's query, a Command's body |
649
670
  | `jsonRpcOperations({ endpoint })` | over JSON-RPC 2.0: one `POST`, the operation's method, its input as named params |
650
671
  | `restTransport({ base })` | REST over `fetch`: `Idempotency-Key`, the server's `Problem`, model versions, Parquet |
651
672
  | `memoryTransport(tables)` | the same REST contract in memory, copying by the wire's rules — for tests and demos |
@@ -653,6 +674,7 @@ await forge.sendIssue({ issue_id: "acme-3", message: "hola" }); // ResponseSendI
653
674
  | `retryKeys()` | one `Idempotency-Key` per gesture, kept while a retry may repeat it |
654
675
  | `guardedTransport(t, breaker)` | every call of a transport through a circuit breaker |
655
676
  | `screensTransport(transport)` | screen reads and writes run as use cases of `screens`: traced and reported |
677
+ | `markedAs(wrapper, inner)` | a wrapper of a screens transport keeps its mark: one `screens` context, not two |
656
678
  | `parquetDecoder` (`./parquet`) | large pages read as Parquet through the same transport |
657
679
 
658
680
  Inside a Feature, inject the generated client as it is: the run binds it, so every call carries
@@ -660,6 +682,27 @@ its trace (`traceparent`), its context (`sincpro-context`) and its signal — as
660
682
  as metadata where a platform's adapter puts them. `screensTransport` and `entity()` stay on the
661
683
  REST `Transport`: they are how a screen reads pages of an entity, with its model and its drafts.
662
684
 
685
+ An edit — the backend's `Edit`, role `edit` — creates a record under the key its caller names.
686
+ Its generated method mints one when the input names none (`newEntityId`, a UUID v7, as the
687
+ server would), so `forge.editProject({ values, action: "save" })` creates a project over any
688
+ wire, REST's `PUT /projects/{id}/edit` included. A screen that keeps a draft of a new record
689
+ names its key once, so every save of the draft reaches the same record. A Command that answers
690
+ nothing — a `DELETE`'s 204 — resolves `null`, never `undefined`.
691
+
692
+ A `DELETE` — the backend's `Delete`, role `delete`, an entity's `delete` route — is read from its
693
+ URL, never from a body. `restTransport` sends its fields in the query string, as the server decodes
694
+ them (plain values as text, anything else as JSON): `DELETE /projects/acme?dry_run=true` answers
695
+ the `Preview` of what would go, and `origin_version` refuses a delete of a record that moved on.
696
+ Sent in a body they are dropped, and a rehearsal would run the real delete.
697
+
698
+ Which of the ways a screen reaches the backend fits a call — an entity's screens, the generated
699
+ client over the screens transport, or a Command and its Feature — is in
700
+ [docs/WEB.md](docs/WEB.md#which-way-a-screen-reaches-the-backend).
701
+
702
+ A wrapper over a screens transport — a cache, a guard — keeps its mark, so the screens are not made
703
+ twice: `guardedTransport` does it, and a platform's own wrapper calls `markedAs(wrapper, inner)`.
704
+ One span then answers each screen read, whether the wrapper answered it from its own memory or not.
705
+
663
706
  ### What a write changed
664
707
 
665
708
  A client keeps what it read — a cache, a list on screen, a record — and every one of them goes
@@ -728,7 +771,7 @@ each file in the layer it belongs to, under the bounded context's folder (`--out
728
771
  | `domain/generated/events.ts` | the domain events and `DomainEvent`, their union — when the contract carries them |
729
772
  | `domain/generated/index.ts` | the three, re-exported: `import type * as remote from "../domain/generated"` |
730
773
  | `adapters/generated/client.ts` | `clientOf(operations)`: a method per operation, over any wire; `operations` and `events` data |
731
- | `adapters/generated/entities.ts` | each entity's list, record, edit, export, Commands and history, for screens |
774
+ | `adapters/generated/entities.ts` | each entity's list, record, edit, delete, export, Commands and history, for screens |
732
775
 
733
776
  The backend keeps them apart — the domain's words, the application layer's DTOs, the facts, the
734
777
  adapters to another system —, and so does the application: each beside its own code of that layer.
@@ -806,7 +849,7 @@ needs them.
806
849
  | Decimal | exact text, `"10.50"` | `Decimal` |
807
850
  | Money | `{ amount: "10.50", currency: "BOB" }` | `Money` |
808
851
  | Day | `"2026-10-02"`, never an instant | `isDay`, `dayOf` |
809
- | Instant | ISO text | `wallTimeOf`, `instantOf` |
852
+ | Instant | ISO text | `wallTimeOf`, `instantOf`, `timeZoneOf` |
810
853
  | ID | UUID v7 as 32 hex | `newEntityId`, `isEntityId`, `momentOf` |
811
854
  | Bytes | `{ "$bytes": "<base64>" }` | `valuesOf`, `readValues` |
812
855
  | Collection | items, count and cursor | `collectionOf`, `isPartial`, `relatedCriteria` |
@@ -30,6 +30,10 @@ export type MemoryOptions = {
30
30
  * Answer a Command — a write, an action, a preview — the way the service would. It may
31
31
  * change the tables' rows (they are read on every request) and throw a `TransportError` to
32
32
  * refuse. Without it, every Command is a 404.
33
+ *
34
+ * Its `body` is the Command's fields whatever the method — a `DELETE`'s too, which REST sends
35
+ * in its query string (`restTransport`): this stands for the service, which reads a DTO, not a
36
+ * URL.
33
37
  */
34
38
  handle?: (method: Method, route: string, body: unknown) => unknown;
35
39
  /** Answer a read that is neither a page nor a record (`GET /me`), its route with its query.
@@ -9,11 +9,13 @@ import { type Transport } from "../domain/transport.js";
9
9
  *
10
10
  * 1. The operation's REST binding (`operation.rest`); none: `OperationNotPublished`.
11
11
  * 2. Each `{field}` of its path taken from the input.
12
- * 3. A `GET` — a Query — sends every other field as its query (text as it is, `criteria` and any
13
- * other value as JSON) and reads the answer as it came; one that answers bytes (`streamed`,
14
- * an export) is downloaded.
15
- * 4. Anything else — a Command — sends the input as its body, with the gesture's
16
- * `Idempotency-Key`.
17
- * Final: the operation's answer, as the contract describes it.
12
+ * 3. A `GET` — a Query — sends every other field as its query, as the wire reads it back
13
+ * (`queryOf`: plain values as text, `criteria` and any other value as JSON), and reads the
14
+ * answer as it came; one that answers bytes (`streamed`, an export) is downloaded.
15
+ * 4. Anything else — a Command — is sent with the gesture's `Idempotency-Key`: the input whole as
16
+ * its body; a `DELETE`, read from its URL as a `GET` is, only the fields its path did not take
17
+ * — the REST transport writes them as its query (`restTransport`), and a key is not said twice.
18
+ * Final: the operation's answer, as the contract describes it — `null` for one that answers
19
+ * nothing (a `DELETE`'s 204).
18
20
  */
19
21
  export declare function restOperations(transport: Transport): OperationTransport;
@@ -1,11 +1,8 @@
1
+ import { queryOf, withQuery } from "./rest.js";
1
2
  import { OperationNotPublished, } from "../domain/operation.js";
2
3
  import { downloadRoute, readRoute, } from "../domain/transport.js";
3
4
  import { bindableOperations } from "../services/propagation.js";
4
5
  const PATH_KEY = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
5
- /** What a value is in a query string: text as it is, anything else as JSON (`criteria`). */
6
- function queryValue(value) {
7
- return typeof value === "string" ? value : JSON.stringify(value);
8
- }
9
6
  /** The path with each `{field}` taken from the input, and the input's fields it did not take. */
10
7
  function placed(operation, path, input) {
11
8
  const rest = { ...input };
@@ -18,13 +15,6 @@ function placed(operation, path, input) {
18
15
  });
19
16
  return { route, rest };
20
17
  }
21
- /** The route with every other field of a GET as its query. */
22
- function withQuery(route, fields) {
23
- const query = new URLSearchParams(Object.entries(fields)
24
- .filter(([, value]) => value !== undefined && value !== null && value !== "")
25
- .map(([name, value]) => [name, queryValue(value)])).toString();
26
- return query === "" ? route : `${route}${route.includes("?") ? "&" : "?"}${query}`;
27
- }
28
18
  /**
29
19
  * Operations over REST, as sincpro_framework's REST gateway publishes them — on a `Transport`
30
20
  * (`restTransport`, `memoryTransport`, a platform's):
@@ -34,12 +24,14 @@ function withQuery(route, fields) {
34
24
  *
35
25
  * 1. The operation's REST binding (`operation.rest`); none: `OperationNotPublished`.
36
26
  * 2. Each `{field}` of its path taken from the input.
37
- * 3. A `GET` — a Query — sends every other field as its query (text as it is, `criteria` and any
38
- * other value as JSON) and reads the answer as it came; one that answers bytes (`streamed`,
39
- * an export) is downloaded.
40
- * 4. Anything else — a Command — sends the input as its body, with the gesture's
41
- * `Idempotency-Key`.
42
- * Final: the operation's answer, as the contract describes it.
27
+ * 3. A `GET` — a Query — sends every other field as its query, as the wire reads it back
28
+ * (`queryOf`: plain values as text, `criteria` and any other value as JSON), and reads the
29
+ * answer as it came; one that answers bytes (`streamed`, an export) is downloaded.
30
+ * 4. Anything else — a Command — is sent with the gesture's `Idempotency-Key`: the input whole as
31
+ * its body; a `DELETE`, read from its URL as a `GET` is, only the fields its path did not take
32
+ * — the REST transport writes them as its query (`restTransport`), and a key is not said twice.
33
+ * Final: the operation's answer, as the contract describes it — `null` for one that answers
34
+ * nothing (a `DELETE`'s 204).
43
35
  */
44
36
  export function restOperations(transport) {
45
37
  return bindableOperations({
@@ -52,12 +44,13 @@ export function restOperations(transport) {
52
44
  try {
53
45
  const { route, rest: others } = placed(operation, rest.path, fields);
54
46
  if (rest.method === "GET") {
55
- const asked = withQuery(route, others);
47
+ const asked = withQuery(route, queryOf(others));
56
48
  return operation.streamed
57
49
  ? downloadRoute(transport, asked, signal, call)
58
50
  : readRoute(transport, asked, signal, call);
59
51
  }
60
- return transport.send(rest.method, route, fields, signal, call);
52
+ const sent = rest.method === "DELETE" ? others : fields;
53
+ return transport.send(rest.method, route, sent, signal, call);
61
54
  }
62
55
  catch (error) {
63
56
  return Promise.reject(error);
@@ -10,6 +10,19 @@ import { type Criteria } from "@sincpro/criteria";
10
10
  * one record (`one()`), a write (`send()`, with its `Idempotency-Key`), and its refusals as a
11
11
  * `TransportError`, the one error every screen explains.
12
12
  *
13
+ * A write's fields travel where the wire reads them. sincpro_framework reads a `DELETE`'s DTO
14
+ * from its URL, as a `GET`'s (`READ_FROM_URL`), and never its body: a field sent there is dropped
15
+ * — or refused with a 422 (`out_of_place`) where the server checks it. So a `DELETE` sends its
16
+ * fields as its query string (`queryOf`) and no body; every other method sends them as a JSON
17
+ * body. Sent in a body, `dry_run` is lost and a rehearsal would run the real delete, and so is
18
+ * `origin_version`, so a stale delete would go through.
19
+ *
20
+ * The fields reach `send` as its `body` whatever the method — the change feed reads `dry_run`
21
+ * there — and `send` gets the path already filled, so leaving out a key the path took is the
22
+ * caller's, who knows the template: `restOperations` does, and an entity's `delete` puts its key
23
+ * only in the path. A key that travels in both is harmless: the wire reads a `DELETE` as
24
+ * `{**query, **path_params}` — the path wins — and looks for misplaced fields only in its body.
25
+ *
13
26
  * The definition of each model — what a list, a form and a select are built from — is read
14
27
  * from the bounded context's discovery document (`document`, `/openapi.json` by default), once,
15
28
  * and read again only when an answer says another version of its model (`model_version`); the
@@ -55,5 +68,22 @@ export type VersionDrift = {
55
68
  snapshot: string;
56
69
  live: string;
57
70
  };
71
+ /**
72
+ * The fields of a DTO as a query string, the way sincpro_framework's REST wire reads them back
73
+ * (`payload_from_query`): a plain value — text, a number, a boolean — as its text, which the
74
+ * server coerces to the field's type; anything else — a list, an object, a `Money` — as JSON,
75
+ * which it decodes. A value with a wire form of its own is written as that first (`valuesOf`):
76
+ * a `Decimal` as its text, a `Date` as its instant. A field with no value (`undefined`, `null`,
77
+ * `""`) is not sent, and the DTO's default stands — as a filter left blank.
78
+ *
79
+ * queryOf({ dry_run: true, origin_version: 3, tags: ["a"] })
80
+ * -> "dry_run=true&origin_version=3&tags=%5B%22a%22%5D"
81
+ *
82
+ * Context: the client does not know each field's schema, so `null` cannot be told apart: as
83
+ * text it would be the word «null» for a plain field. Left out, the field takes its default.
84
+ */
85
+ export declare function queryOf(fields: Readonly<Record<string, unknown>>): string;
86
+ /** `route` with `query` added to the query it may already carry. */
87
+ export declare function withQuery(route: string, query: string): string;
58
88
  export declare function urlOf<T>(base: string, route: string, criteria?: Criteria<T>): string;
59
89
  export declare function restTransport(options?: RestOptions): Transport;
@@ -2,6 +2,7 @@ import { TransportError, } from "../domain/transport.js";
2
2
  import { announced, processChanges } from "../services/changes.js";
3
3
  import { definitionOf, modelAt, } from "../services/discovery.js";
4
4
  import { bindableTransport } from "../services/propagation.js";
5
+ import { valuesOf } from "../../common/serialization.js";
5
6
  import { readProblem } from "@sincpro/criteria";
6
7
  import { RestError, restSource } from "@sincpro/criteria/rest";
7
8
  /** The keys of an answer that are not the record: what is left is the record's own field. */
@@ -25,6 +26,47 @@ function filenameOf(disposition) {
25
26
  const plain = /filename\s*=\s*("([^"]*)"|[^;]+)/i.exec(said);
26
27
  return (plain?.[2] ?? plain?.[1] ?? "").trim();
27
28
  }
29
+ /**
30
+ * The fields of a DTO as a query string, the way sincpro_framework's REST wire reads them back
31
+ * (`payload_from_query`): a plain value — text, a number, a boolean — as its text, which the
32
+ * server coerces to the field's type; anything else — a list, an object, a `Money` — as JSON,
33
+ * which it decodes. A value with a wire form of its own is written as that first (`valuesOf`):
34
+ * a `Decimal` as its text, a `Date` as its instant. A field with no value (`undefined`, `null`,
35
+ * `""`) is not sent, and the DTO's default stands — as a filter left blank.
36
+ *
37
+ * queryOf({ dry_run: true, origin_version: 3, tags: ["a"] })
38
+ * -> "dry_run=true&origin_version=3&tags=%5B%22a%22%5D"
39
+ *
40
+ * Context: the client does not know each field's schema, so `null` cannot be told apart: as
41
+ * text it would be the word «null» for a plain field. Left out, the field takes its default.
42
+ */
43
+ export function queryOf(fields) {
44
+ return new URLSearchParams(Object.entries(fields).flatMap(([name, value]) => {
45
+ const wire = value === undefined ? null : valuesOf(value);
46
+ if (wire === null || wire === "")
47
+ return [];
48
+ return [[name, typeof wire === "object" ? JSON.stringify(wire) : String(wire)]];
49
+ })).toString();
50
+ }
51
+ /** `route` with `query` added to the query it may already carry. */
52
+ export function withQuery(route, query) {
53
+ return query === "" ? route : `${route}${route.includes("?") ? "&" : "?"}${query}`;
54
+ }
55
+ /**
56
+ * The fields a `DELETE` carries in its URL: its body, which must be a set of fields as the wire
57
+ * writes it — a list or a lone value has no field to put in a query, and dropping it silently is
58
+ * the bug this exists to prevent.
59
+ */
60
+ function urlFieldsOf(route, body) {
61
+ if (body === undefined || body === null)
62
+ return {};
63
+ const fields = valuesOf(body);
64
+ if (fields === null || typeof fields !== "object" || Array.isArray(fields))
65
+ throw new TypeError(`DELETE ${route} sends its fields in the URL: its body is an object of them, not ${Array.isArray(fields) ? "a list" : typeof fields}`);
66
+ return fields;
67
+ }
68
+ /** The methods of a write sincpro_framework reads from the URL alone (its `READ_FROM_URL`). */
69
+ const FROM_URL = new Set(["DELETE"]);
28
70
  export function urlOf(base, route, criteria) {
29
71
  const url = `${base}${route}`;
30
72
  if (criteria === undefined)
@@ -114,18 +156,22 @@ export function restTransport(options = {}) {
114
156
  const again = await documentRead(true);
115
157
  return (again === null ? undefined : definitionOf(again, name))?.meta ?? known.meta;
116
158
  }
159
+ /** A request and its answer: a write's body as JSON — none for one read from its URL. */
117
160
  async function get(route, url, signal, write, call) {
161
+ const json = write !== undefined && !FROM_URL.has(write.method);
118
162
  const headers = write
119
163
  ? {
120
164
  ...own(),
121
165
  ...call?.headers,
122
- "Content-Type": "application/json",
166
+ ...(json ? { "Content-Type": "application/json" } : {}),
123
167
  ...(write.key === undefined ? {} : { "Idempotency-Key": write.key }),
124
168
  }
125
169
  : { ...own(), ...call?.headers };
126
170
  const response = await doFetch(url, {
127
171
  headers,
128
- ...(write ? { method: write.method, body: JSON.stringify(write.body) } : {}),
172
+ ...(write
173
+ ? { method: write.method, ...(json ? { body: JSON.stringify(write.body) } : {}) }
174
+ : {}),
129
175
  ...(signal ? { signal } : {}),
130
176
  });
131
177
  const text = await response.text();
@@ -185,8 +231,10 @@ export function restTransport(options = {}) {
185
231
  };
186
232
  },
187
233
  async send(method, route, body, signal, sending) {
234
+ // A DELETE is read from its URL: its fields go in the query, and it has no body.
235
+ const url = urlOf(base, FROM_URL.has(method) ? withQuery(route, queryOf(urlFieldsOf(route, body))) : route);
188
236
  return announced(changes, method, route, body, async () => {
189
- return (await get(route, urlOf(base, route), signal, { method, body, key: sending?.idempotencyKey }, sending));
237
+ return (await get(route, url, signal, { method, body, key: sending?.idempotencyKey }, sending));
190
238
  });
191
239
  },
192
240
  });
@@ -36,8 +36,8 @@ export type CommandAnswers = Readonly<Record<string, unknown>>;
36
36
  * Everything a screen needs to know about where an entity lives on the server, declared once.
37
37
  *
38
38
  * Context: a screen should not know a URL. It names the entity, and the entity says where its
39
- * list is, where one record is, which Commands it takes, how it is saved and previewed, where a
40
- * draft is kept and where its history is. `key` is how the workspace refers to it
39
+ * list is, where one record is, which Commands it takes, how it is saved, previewed and deleted,
40
+ * where a draft is kept and where its history is. `key` is how the workspace refers to it
41
41
  * (`domain:kind`, the shape of a composer `ResourceRef`).
42
42
  *
43
43
  * The routes are declared, not guessed: sincpro_framework publishes a route per use case and
@@ -48,6 +48,7 @@ export type CommandAnswers = Readonly<Record<string, unknown>>;
48
48
  * create: "POST /invoices",
49
49
  * save: "PUT /invoices/{id}",
50
50
  * preview: "POST /invoices/preview",
51
+ * delete: "DELETE /invoices/{id}",
51
52
  * commands: { confirm: "POST /invoices/{id}/confirm", cancel: "POST /invoices/{id}/cancel" },
52
53
  * history: "/invoices/{id}/events",
53
54
  * });
@@ -89,9 +90,15 @@ export type Entity<T extends AnyRecord = AnyRecord, C extends CommandBodies = Co
89
90
  /** Where this caller keeps an edit between requests — sincpro_framework's `Drafts`. */
90
91
  draft?: WriteRoute;
91
92
  /** sincpro_framework's `Edit`: ONE route that keeps the draft, saves and discards, by its
92
- * `action`. Declared, a save sends the record whole as the form holds it — not the fields
93
- * that changed under `save` — and it is also where the draft is kept. */
93
+ * `action`. Declared, a save goes through it — what changed, with the draft and stored
94
+ * versions it started from: the server puts it over what it stored and the caller's draft —
95
+ * and it is also where the draft is kept. */
94
96
  edit?: WriteRoute;
97
+ /** sincpro_framework's `Delete`: the record deleted by its key, `{id}` in the path. It answers
98
+ * nothing (`null`); with `dry_run: true` it answers the `Preview` of what would go and deletes
99
+ * nothing, and `origin_version` refuses it when the record moved past the version read. Over
100
+ * REST those fields travel in the query string — a `DELETE` is read from its URL. */
101
+ delete?: WriteRoute;
95
102
  /** Its business events: where ONE record's events are read (sincpro_framework's
96
103
  * `DomainEvents`), `{id}` where its key goes — a page of them, as a list answers. */
97
104
  history?: string;
@@ -189,6 +196,8 @@ export type EntityRoutes<C extends CommandBodies = CommandBodies> = CommandRoute
189
196
  draft?: string;
190
197
  /** `"PUT /invoices/{id}/edit"`: the use case that answers sincpro_framework's `Edit`. */
191
198
  edit?: string;
199
+ /** `"DELETE /invoices/{id}"`: the use case that answers sincpro_framework's `Delete`. */
200
+ delete?: string;
192
201
  /** `"/invoices/{id}/events"`: a record's events (`DomainEvents[Invoice, …]`), oldest first. */
193
202
  history?: string;
194
203
  /** `"/invoices/export"`: every record of a criteria as a file (`Export[Invoice, Streamed]`),
@@ -194,6 +194,7 @@ export function entity(key, routes) {
194
194
  ...(routes.preview === undefined ? {} : { preview: writeRoute(routes.preview) }),
195
195
  ...(routes.draft === undefined ? {} : { draft: writeRoute(routes.draft) }),
196
196
  ...(routes.edit === undefined ? {} : { edit: writeRoute(routes.edit) }),
197
+ ...(routes.delete === undefined ? {} : { delete: writeRoute(routes.delete) }),
197
198
  ...(routes.history === undefined ? {} : { history: routes.history }),
198
199
  ...(routes.export === undefined ? {} : { export: routes.export }),
199
200
  summary: routes.summary ?? {},
@@ -11,12 +11,27 @@ import type { AnyRecord, Criteria, Dropped, Envelope, Meta, Page, Problem } from
11
11
  * Every adapter throws `TransportError` for a refusal, so a screen explains a failure once
12
12
  * whichever wire it came over.
13
13
  */
14
+ /**
15
+ * The mark of a screens transport: `screensTransport` answers one it already made, and a wrapper
16
+ * over one (`cachedTransport`, `guardedTransport`) copies the mark, so the screens are not made
17
+ * twice — one span per screen read, however many wrappers stand between.
18
+ *
19
+ * Context: a mark, not a remembered object — a wrapper is a new object, and the screens context
20
+ * it sits on is the one that answers. A platform's wrapper copies it with `markedAs`.
21
+ */
22
+ export declare const SCREENS: unique symbol;
14
23
  export interface Transport {
24
+ /** Set on a screens transport and on what wraps one (`SCREENS`). */
25
+ [SCREENS]?: true;
15
26
  /** A page of records under the criteria. */
16
27
  list<T>(route: string, criteria: Criteria<T>, signal?: AbortSignal, options?: CallOptions): Promise<Page<T>>;
17
28
  /** One record, with the definition of its model. */
18
29
  one<T>(route: string, signal?: AbortSignal, options?: CallOptions): Promise<One<T>>;
19
- /** A Command — a write, an action, a preview: `method` and a JSON body, its answer back. */
30
+ /**
31
+ * A Command — a write, an action, a preview: `method` and its fields (`body`), its answer back,
32
+ * `null` when it answers nothing. Where the fields travel is the wire's: over REST a `DELETE` is
33
+ * read from its URL, so its fields go in the query string; any other method's, in a JSON body.
34
+ */
20
35
  send<T>(method: Method, route: string, body: unknown, signal?: AbortSignal, options?: SendOptions): Promise<T>;
21
36
  /**
22
37
  * A read that is neither a page nor one record — a Query of the context's own, `GET /me` —:
@@ -123,3 +138,5 @@ export declare class TransportError extends Error {
123
138
  readonly problem: Problem | null;
124
139
  constructor(route: string, status: number | null, problem: Problem | null, message?: string);
125
140
  }
141
+ /** Carries the screens mark from `from` onto `to`, a wrapper of it; `to` is answered. */
142
+ export declare function markedAs<T extends Transport>(to: T, from: Transport): T;
@@ -1,3 +1,24 @@
1
+ /**
2
+ * The one seam between this package and a server.
3
+ *
4
+ * Context: a list and a record are the same two questions whatever the wire is — «a page of
5
+ * these, under this criteria» and «this one». REST today; JSON-RPC and gRPC are the other
6
+ * wires sincpro_framework serves. Each of those is
7
+ * one adapter implementing this, and nothing above it changes. A route is a string the adapter
8
+ * understands: a path for REST, a method for RPC.
9
+ *
10
+ * Every adapter throws `TransportError` for a refusal, so a screen explains a failure once
11
+ * whichever wire it came over.
12
+ */
13
+ /**
14
+ * The mark of a screens transport: `screensTransport` answers one it already made, and a wrapper
15
+ * over one (`cachedTransport`, `guardedTransport`) copies the mark, so the screens are not made
16
+ * twice — one span per screen read, however many wrappers stand between.
17
+ *
18
+ * Context: a mark, not a remembered object — a wrapper is a new object, and the screens context
19
+ * it sits on is the one that answers. A platform's wrapper copies it with `markedAs`.
20
+ */
21
+ export const SCREENS = Symbol.for("sincpro.client-framework.screens");
1
22
  /** A download through `transport.download`, or the reason it cannot be, by name. */
2
23
  export function downloadRoute(transport, route, signal, options) {
3
24
  if (transport.download === undefined)
@@ -30,3 +51,9 @@ export class TransportError extends Error {
30
51
  this.name = "TransportError";
31
52
  }
32
53
  }
54
+ /** Carries the screens mark from `from` onto `to`, a wrapper of it; `to` is answered. */
55
+ export function markedAs(to, from) {
56
+ if (from[SCREENS] === true)
57
+ to[SCREENS] = true;
58
+ return to;
59
+ }
@@ -16,7 +16,7 @@ export { type Change, type ChangeFeed, changeOf, } from "./domain/changes.js";
16
16
  export { type ClientContract, entityKeyOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
17
17
  export { bodyFor, type CommandAnswers, type CommandBodies, type CommandRoute, type Entity, entity, type EntityRef, type EntityRoutes, type ExportFormat, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, type SummaryFields, type SummaryPart, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./domain/entity.js";
18
18
  export { OperationNotPublished, type OperationOptions, type OperationTransport, type RemoteOperation, } from "./domain/operation.js";
19
- export { type CallOptions, type Decoder, type Download, downloadRoute, type Draft, type Method, type One, readRoute, type SendOptions, type Transport, TransportError, } from "./domain/transport.js";
19
+ export { type CallOptions, type Decoder, type Download, downloadRoute, type Draft, markedAs, type Method, type One, readRoute, SCREENS, type SendOptions, type Transport, TransportError, } from "./domain/transport.js";
20
20
  export { announced, changeFeed, processChanges, } from "./services/changes.js";
21
21
  export { guardedTransport } from "./services/guarded.js";
22
22
  export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
@@ -16,7 +16,7 @@ export { changeOf, } from "./domain/changes.js";
16
16
  export { entityKeyOf, kindOf, metasOf, versionsOf, } from "./domain/contract.js";
17
17
  export { bodyFor, entity, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./domain/entity.js";
18
18
  export { OperationNotPublished, } from "./domain/operation.js";
19
- export { downloadRoute, readRoute, TransportError, } from "./domain/transport.js";
19
+ export { downloadRoute, markedAs, readRoute, SCREENS, TransportError, } from "./domain/transport.js";
20
20
  export { announced, changeFeed, processChanges, } from "./services/changes.js";
21
21
  export { guardedTransport } from "./services/guarded.js";
22
22
  export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
@@ -1,6 +1,6 @@
1
1
  import type { CircuitBreaker } from "../../circuit_breaker/entrypoint/circuit-breaker.js";
2
2
  import { type OperationTransport } from "../domain/operation.js";
3
- import type { Transport } from "../domain/transport.js";
3
+ import { type Transport } from "../domain/transport.js";
4
4
  /**
5
5
  * `transport`, every call through `breaker` — an `OperationTransport` of any wire, or REST's
6
6
  * `Transport`:
@@ -1,4 +1,5 @@
1
1
  import { isOperationTransport, } from "../domain/operation.js";
2
+ import { markedAs, } from "../domain/transport.js";
2
3
  import { bindableOperations, bindableTransport, } from "./propagation.js";
3
4
  export function guardedTransport(transport, breaker) {
4
5
  if (isOperationTransport(transport))
@@ -16,5 +17,5 @@ export function guardedTransport(transport, breaker) {
16
17
  const download = transport.download;
17
18
  if (download !== undefined)
18
19
  guarded.download = (route, signal, options) => breaker.call(() => download.call(transport, route, signal, options));
19
- return bindableTransport(guarded);
20
+ return bindableTransport(markedAs(guarded, transport));
20
21
  }
@@ -7,6 +7,7 @@ import { type GenerateOptions } from "./rest.js";
7
7
  * whether it answers bytes, and the binding of each wire that publishes it.
8
8
  * 2. A method per operation, named by `methodOf`: its input — optional when nothing in it is
9
9
  * required — and the call's options (headers, signal, idempotency key), answering its answer.
10
+ * An edit's method mints the record's key when the input names none (`mintsKey`).
10
11
  * 3. When the contract carries them, every domain event as data, by its type's name: its wire
11
12
  * name, and whether the bounded context records it or handles it.
12
13
  * Final: `clientOf(transport)` over an `OperationTransport`, bound to each run that uses it; two
@@ -27,6 +27,29 @@ function isStreamed(operation) {
27
27
  return (operation.output !== null &&
28
28
  operation.output["x-sincpro-streamed"] !== undefined);
29
29
  }
30
+ /**
31
+ * The field of an edit that names its record, minted by the client when the caller names none.
32
+ *
33
+ * Context: an operation of role `edit` is sincpro_framework's `Edit` (`role_of`: what descends
34
+ * from it), whose `id` — the record's key — the server mints with `new_entity_id()` when none is
35
+ * sent. Over REST its route carries the key in its path (`PUT /invoices/{id}/edit`), so creating
36
+ * a record through the generated method failed before it left («needs "id"»). The method mints it
37
+ * as the server would (`newEntityId`, a UUID v7), the same on every wire; a key the caller names
38
+ * — a stored record's, or the one a form minted for its draft — goes as it is.
39
+ */
40
+ const EDIT_KEY = "id";
41
+ /** Whether `operation` is an edit whose key the caller may leave out — the method mints it. */
42
+ function mintsKey(operation) {
43
+ return (operation.role === "edit" &&
44
+ operation.input.properties?.[EDIT_KEY] !== undefined &&
45
+ !(operation.input.required ?? []).includes(EDIT_KEY));
46
+ }
47
+ /** The input a method hands the transport: as the caller gave it, an edit's key minted if absent. */
48
+ function inputOf(operation, optional) {
49
+ if (mintsKey(operation))
50
+ return `{ ...input, ${EDIT_KEY}: input?.${EDIT_KEY} || newEntityId() }`;
51
+ return optional ? "input ?? {}" : "input";
52
+ }
30
53
  /** The data of one operation: what it is, and how each wire reaches it. */
31
54
  function dataOf(metamodel, identity, operation, rest) {
32
55
  const lines = [
@@ -58,6 +81,7 @@ function dataOf(metamodel, identity, operation, rest) {
58
81
  * whether it answers bytes, and the binding of each wire that publishes it.
59
82
  * 2. A method per operation, named by `methodOf`: its input — optional when nothing in it is
60
83
  * required — and the call's options (headers, signal, idempotency key), answering its answer.
84
+ * An edit's method mints the record's key when the input names none (`mintsKey`).
61
85
  * 3. When the contract carries them, every domain event as data, by its type's name: its wire
62
86
  * name, and whether the bounded context records it or handles it.
63
87
  * Final: `clientOf(transport)` over an `OperationTransport`, bound to each run that uses it; two
@@ -67,26 +91,32 @@ export function clientFileOf(metamodel, options = {}) {
67
91
  const claim = claimed();
68
92
  const data = [];
69
93
  const methods = [];
94
+ let minting = false;
70
95
  for (const [identity, operation] of sorted(metamodel.operations)) {
71
96
  const local = localOf(metamodel, identity);
72
97
  data.push(dataOf(metamodel, identity, operation, restOf(metamodel, identity, options)));
73
98
  const method = methodOf(local);
74
99
  claim(method, `operation ${identity}`);
75
100
  const wires = wiresOf(metamodel, identity);
101
+ const mints = mintsKey(operation);
102
+ minting ||= mints;
76
103
  const doc = docOf([
77
104
  operation.description,
78
105
  deprecationOf(metamodel, operation),
106
+ mints
107
+ ? `A new record's \`${EDIT_KEY}\` is minted here when the input names none (\`newEntityId\`).`
108
+ : undefined,
79
109
  wires.length === 0 ? undefined : `Published over ${wires.join(", ")}.`,
80
110
  ], " ");
81
111
  const optional = (operation.input.required ?? []).length === 0;
82
112
  methods.push([
83
113
  `${doc} ${method}: (input${optional ? "?" : ""}: dto.${local}, options?: OperationOptions) =>`,
84
- ` transport.call<dto.${answerOf(metamodel, identity)}>(operations.${local}, input${optional ? " ?? {}" : ""}, options),`,
114
+ ` transport.call<dto.${answerOf(metamodel, identity)}>(operations.${local}, ${inputOf(operation, optional)}, options),`,
85
115
  ].join("\n"));
86
116
  }
87
117
  const events = sorted(metamodel.events ?? {}).map(([name, event]) => ` ${identifierOf(event.title)}: { name: ${JSON.stringify(name)}, recorded: ${event.recorded}, handled: ${event.handled} },`);
88
118
  const imports = [
89
- `import { bindable, type OperationOptions, type OperationTransport } from "${FRAMEWORK}";`,
119
+ `import { bindable,${minting ? " newEntityId," : ""} type OperationOptions, type OperationTransport } from "${FRAMEWORK}";`,
90
120
  "",
91
121
  `import type * as dto from "${DOMAIN_MODULE}";`,
92
122
  ].join("\n");
@@ -5,9 +5,9 @@ import { type GenerateOptions } from "./rest.js";
5
5
  *
6
6
  * 1. Per model, by name: the one `search` a transport reads for it (`own` when there are
7
7
  * several) — none, and the model gets no entity, said in the file's own doc.
8
- * 2. Its `get`, `edit` and `preview` the same way, the record's field written `{id}`; its
9
- * `events` — a record's `DomainEvents` — as `history`, the same way; and its `export` — every
10
- * record of a criteria as a file — by its path.
8
+ * 2. Its `get`, `edit`, `preview` and `delete` the same way, the record's field written `{id}`;
9
+ * its `events` — a record's `DomainEvents` — as `history`, the same way; and its `export` —
10
+ * every record of a criteria as a file — by its path.
11
11
  * 3. Every write of role `command` that concerns it: with `target` when its body names the
12
12
  * record, as it is when it creates one; its body typed without that field.
13
13
  * Final: an `entity<T, C>()` per model listed, keyed `<domain>:<kind>`, and `entities`, all of
@@ -78,7 +78,8 @@ function entitySourceOf(metamodel, model, domain, options, claim) {
78
78
  }
79
79
  else if (one !== undefined)
80
80
  missing.push(`one: ${one.missing}`);
81
- for (const role of ["edit", "preview"]) {
81
+ // sincpro_framework's `Delete` (role `delete`) is the record's own route too, never a Command.
82
+ for (const role of ["edit", "preview", "delete"]) {
82
83
  const write = oneOf(reads(role, isWrite), role);
83
84
  if (write === undefined)
84
85
  continue;
@@ -155,9 +156,9 @@ function entitySourceOf(metamodel, model, domain, options, claim) {
155
156
  *
156
157
  * 1. Per model, by name: the one `search` a transport reads for it (`own` when there are
157
158
  * several) — none, and the model gets no entity, said in the file's own doc.
158
- * 2. Its `get`, `edit` and `preview` the same way, the record's field written `{id}`; its
159
- * `events` — a record's `DomainEvents` — as `history`, the same way; and its `export` — every
160
- * record of a criteria as a file — by its path.
159
+ * 2. Its `get`, `edit`, `preview` and `delete` the same way, the record's field written `{id}`;
160
+ * its `events` — a record's `DomainEvents` — as `history`, the same way; and its `export` —
161
+ * every record of a criteria as a file — by its path.
161
162
  * 3. Every write of role `command` that concerns it: with `target` when its body names the
162
163
  * record, as it is when it creates one; its body typed without that field.
163
164
  * Final: an `entity<T, C>()` per model listed, keyed `<domain>:<kind>`, and `entities`, all of
@@ -5,7 +5,8 @@
5
5
  * Context: sincpro_framework's `Edit` creates a new record under the id the CLIENT names («a
6
6
  * UUID v7 it mints»), and the draft and the stored record share it from the first draft save.
7
7
  * A form that waited for the server to name it could neither keep a draft of a new record nor
8
- * reach the edit route at all (`PUT /invoices/{id}/edit` needs the id in its path). The layout
8
+ * reach the edit route at all (`PUT /invoices/{id}/edit` needs the id in its path) — so a
9
+ * generated client's edit mints one here when its caller names none. The layout
9
10
  * is the backend's (RFC 9562): 48 bits of unix milliseconds, the version, a 12-bit counter
10
11
  * within the millisecond, the variant and 62 random bits — so ids minted here sort by when
11
12
  * they were minted, like the server's, and ordering by `id` is still ordering by creation.
@@ -5,7 +5,8 @@
5
5
  * Context: sincpro_framework's `Edit` creates a new record under the id the CLIENT names («a
6
6
  * UUID v7 it mints»), and the draft and the stored record share it from the first draft save.
7
7
  * A form that waited for the server to name it could neither keep a draft of a new record nor
8
- * reach the edit route at all (`PUT /invoices/{id}/edit` needs the id in its path). The layout
8
+ * reach the edit route at all (`PUT /invoices/{id}/edit` needs the id in its path) — so a
9
+ * generated client's edit mints one here when its caller names none. The layout
9
10
  * is the backend's (RFC 9562): 48 bits of unix milliseconds, the version, a 12-bit counter
10
11
  * within the millisecond, the variant and 62 random bits — so ids minted here sort by when
11
12
  * they were minted, like the server's, and ordering by `id` is still ordering by creation.
@@ -8,4 +8,4 @@ export { type DeclaredFailure, type Failure, failureOf, kindOfGrpcCode, kindOfHt
8
8
  export { isEntityId, momentOf, newEntityId } from "./ids.js";
9
9
  export { Money } from "./money.js";
10
10
  export { BYTES, type JsonValue, pack, readValues, type Rebuild, rebuilt, unpack, valuesOf, } from "./serialization.js";
11
- export { dayOf, installTimeZone, instantOf, isDay, timeZoneNow, wallTimeOf, } from "./time.js";
11
+ export { dayOf, installTimeZone, instantOf, isDay, timeZoneNow, timeZoneOf, wallTimeOf, } from "./time.js";
@@ -8,4 +8,4 @@ export { failureOf, kindOfGrpcCode, kindOfHttpStatus, kindOfJsonRpcCode, PERMANE
8
8
  export { isEntityId, momentOf, newEntityId } from "./ids.js";
9
9
  export { Money } from "./money.js";
10
10
  export { BYTES, pack, readValues, rebuilt, unpack, valuesOf, } from "./serialization.js";
11
- export { dayOf, installTimeZone, instantOf, isDay, timeZoneNow, wallTimeOf, } from "./time.js";
11
+ export { dayOf, installTimeZone, instantOf, isDay, timeZoneNow, timeZoneOf, wallTimeOf, } from "./time.js";
@@ -22,6 +22,33 @@
22
22
  export declare function installTimeZone(timeZone: string | undefined): void;
23
23
  /** The time zone in use. */
24
24
  export declare function timeZoneNow(): string;
25
+ /**
26
+ * The context keys a run's time zone is read from, first found wins. `undefined` goes back to
27
+ * `timezone`. Set by `configureProcess({ timeZone: { keys } })`, as the identity's keys are.
28
+ */
29
+ export declare function installTimeZoneKeys(keys: string | readonly string[] | undefined): void;
30
+ /** The context of a run, or any context: what `timeZoneOf` reads. */
31
+ type ZoneContext = Readonly<Record<string, unknown>>;
32
+ type ZoneRun = {
33
+ readonly useCase: string;
34
+ readonly context: ZoneContext;
35
+ };
36
+ type ZoneSource = ZoneContext | ZoneRun;
37
+ /**
38
+ * The time zone a run reads dates in: its context's, under the key the application named
39
+ * (`timezone` by default, the backend's), else the process's (`timeZoneNow`). Takes an execution
40
+ * or a context.
41
+ *
42
+ * timeZoneOf(execution) → the company's zone, when the run carries one
43
+ * dayOf(instant, timeZoneOf(execution)) → «today» for that company
44
+ *
45
+ * Context: the process's zone is the device's, or the one a platform installed for the company in
46
+ * use; a run whose context says another belongs to another company (a user in La Paz looking at
47
+ * Madrid). Read on every call, never kept, so a run's zone is its own. The context travels in
48
+ * `sincpro-context`, and the backend reads only `timezone`: a zone kept under another key is this
49
+ * client's alone, and the server cuts its days in UTC.
50
+ */
51
+ export declare function timeZoneOf(source: ZoneSource): string;
25
52
  /** `"2026-03-12T14:30:00Z"` → `"2026-03-12T10:30"` in `America/La_Paz`: the wall clock there,
26
53
  * as a date-and-time control reads it. `null` when it is not an instant. */
27
54
  export declare function wallTimeOf(instant: string, timeZone: string): string | null;
@@ -39,3 +66,4 @@ export declare function isDay(text: string): boolean;
39
66
  /** The day it is at `instant` on the wall clock of `timeZone`: what «today» means for a company.
40
67
  * `null` when it is not an instant. */
41
68
  export declare function dayOf(instant: string, timeZone: string): string | null;
69
+ export {};
@@ -27,6 +27,55 @@ export function installTimeZone(timeZone) {
27
27
  export function timeZoneNow() {
28
28
  return installed ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
29
29
  }
30
+ /**
31
+ * The context key a run's time zone is read from, unless the application names another: the
32
+ * backend's own (`ambient_resolution`, `context.get("timezone")`), so the zone a client reads in
33
+ * is the one the server cuts `today` and `period` with.
34
+ */
35
+ const DEFAULT_TIME_ZONE_KEYS = ["timezone"];
36
+ let zoneKeys = DEFAULT_TIME_ZONE_KEYS;
37
+ /**
38
+ * The context keys a run's time zone is read from, first found wins. `undefined` goes back to
39
+ * `timezone`. Set by `configureProcess({ timeZone: { keys } })`, as the identity's keys are.
40
+ */
41
+ export function installTimeZoneKeys(keys) {
42
+ zoneKeys =
43
+ keys === undefined
44
+ ? DEFAULT_TIME_ZONE_KEYS
45
+ : typeof keys === "string"
46
+ ? [keys]
47
+ : [...keys];
48
+ }
49
+ /** An execution, not a context that happens to have a `useCase` key. */
50
+ function isRun(source) {
51
+ const context = source.context;
52
+ return (typeof source.useCase === "string" &&
53
+ typeof context === "object" &&
54
+ context !== null);
55
+ }
56
+ /**
57
+ * The time zone a run reads dates in: its context's, under the key the application named
58
+ * (`timezone` by default, the backend's), else the process's (`timeZoneNow`). Takes an execution
59
+ * or a context.
60
+ *
61
+ * timeZoneOf(execution) → the company's zone, when the run carries one
62
+ * dayOf(instant, timeZoneOf(execution)) → «today» for that company
63
+ *
64
+ * Context: the process's zone is the device's, or the one a platform installed for the company in
65
+ * use; a run whose context says another belongs to another company (a user in La Paz looking at
66
+ * Madrid). Read on every call, never kept, so a run's zone is its own. The context travels in
67
+ * `sincpro-context`, and the backend reads only `timezone`: a zone kept under another key is this
68
+ * client's alone, and the server cuts its days in UTC.
69
+ */
70
+ export function timeZoneOf(source) {
71
+ const context = isRun(source) ? source.context : source;
72
+ for (const key of zoneKeys) {
73
+ const value = context[key];
74
+ if (typeof value === "string" && value.trim() !== "")
75
+ return value.trim();
76
+ }
77
+ return timeZoneNow();
78
+ }
30
79
  const clocks = new Map();
31
80
  /** One formatter per zone, kept: building one costs far more than using it. */
32
81
  function clockOf(timeZone) {
@@ -1,4 +1,4 @@
1
- import type { Transport } from "../../client/domain/transport.js";
1
+ import { type Transport } from "../../client/domain/transport.js";
2
2
  /**
3
3
  * Screen requests enter the same command pipeline as application services. A generated
4
4
  * client injected into a Feature uses its raw transport instead, continuing that execution.
@@ -1,3 +1,4 @@
1
+ import { SCREENS, } from "../../client/domain/transport.js";
1
2
  import { bindableTransport } from "../../client/services/propagation.js";
2
3
  import { Command } from "../domain/dto.js";
3
4
  import { Feature } from "../domain/services.js";
@@ -101,13 +102,12 @@ class EntitySend extends Feature {
101
102
  return this.transport.send(dto.method, dto.route, dto.body, dto.signal, dto.options);
102
103
  }
103
104
  }
104
- const MADE = new WeakSet();
105
105
  /**
106
106
  * Screen requests enter the same command pipeline as application services. A generated
107
107
  * client injected into a Feature uses its raw transport instead, continuing that execution.
108
108
  */
109
109
  export function screensTransport(transport, name = "screens") {
110
- if (MADE.has(transport))
110
+ if (transport[SCREENS] === true)
111
111
  return transport;
112
112
  const screens = new BoundedContext(name);
113
113
  screens.addDependency("transport", transport);
@@ -127,6 +127,6 @@ export function screensTransport(transport, name = "screens") {
127
127
  if (transport.download) {
128
128
  through.download = (route, signal, options) => screens.execute(new Export(route, signal, options));
129
129
  }
130
- MADE.add(through);
130
+ through[SCREENS] = true;
131
131
  return bindableTransport(through);
132
132
  }
@@ -55,6 +55,15 @@ export type ProcessOptions = {
55
55
  tenant?: string;
56
56
  keys?: IdentityKeys;
57
57
  };
58
+ /**
59
+ * The context key a run's time zone is read from (`timezone` by default — the backend's, see
60
+ * `timeZoneOf`). Another key is read only here: the backend reads `timezone` alone.
61
+ * An application that keeps its company's zone under another name says `keys: "company_zone"`
62
+ * — or a list, the first found wins.
63
+ */
64
+ timeZone?: {
65
+ keys?: string | readonly string[];
66
+ };
58
67
  /** The platform's (OpenTelemetry in a browser, a queue on a phone, memory in a test). */
59
68
  tracer?: Tracer;
60
69
  /** The platform's (GlitchTip, Sentry, memory in a test). Only what nobody expected reaches it. */
@@ -1,3 +1,4 @@
1
+ import { installTimeZoneKeys } from "../../common/time.js";
1
2
  import { memoryContexts } from "../../context/adapters/memory.js";
2
3
  import { replaceProcessStore } from "../../context/infrastructure/process.js";
3
4
  import { consoleLogger, } from "../../observability/adapters/console.js";
@@ -31,6 +32,7 @@ export function configureProcess(options = {}) {
31
32
  logger,
32
33
  outcomeOf: options.outcomeOf ?? outcomeOf,
33
34
  });
35
+ installTimeZoneKeys(options.timeZone?.keys);
34
36
  replaceProcessStore(options.context ?? memoryContexts());
35
37
  }
36
38
  /**
@@ -27,8 +27,8 @@ export type FieldOptions = {
27
27
  help?: Words;
28
28
  required?: boolean;
29
29
  readonly?: boolean;
30
- /** Holds no value sometimes. A nullable field is never sortable: keyset paging over it
31
- * loses the rows that hold NULL, which is why the framework refuses to order by one. */
30
+ /** Holds no value sometimes. It still orders, as sincpro_framework orders it: NULL first
31
+ * ascending and last descending, and the keyset walks past it. */
32
32
  nullable?: boolean;
33
33
  default?: unknown;
34
34
  /** Form hints over the record, as sincpro_framework's `Presentation` publishes them. */
@@ -30,7 +30,7 @@ function scalar(type, options = {}) {
30
30
  type,
31
31
  kind: "scalar",
32
32
  nullable,
33
- sortable: !nullable && !listed,
33
+ sortable: !listed,
34
34
  groupable: !listed,
35
35
  ops,
36
36
  ...(options.label === undefined ? {} : { label: words(options.label) }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",