@sincpro/client-framework 1.9.0 → 1.11.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 +74 -18
- package/dist/client/adapters/memory.d.ts +4 -0
- package/dist/client/adapters/memory.js +25 -21
- package/dist/client/adapters/rest.d.ts +4 -0
- package/dist/client/adapters/rest.js +5 -1
- package/dist/client/domain/changes.d.ts +45 -0
- package/dist/client/domain/changes.js +15 -0
- package/dist/client/domain/transport.d.ts +13 -0
- package/dist/client/domain/transport.js +27 -0
- package/dist/client/index.d.ts +6 -3
- package/dist/client/index.js +6 -3
- package/dist/client/services/changes.d.ts +32 -0
- package/dist/client/services/changes.js +60 -0
- package/dist/client/services/guarded.d.ts +1 -1
- package/dist/client/services/guarded.js +2 -1
- package/dist/codegen/domain/names.d.ts +10 -0
- package/dist/codegen/domain/names.js +13 -1
- package/dist/codegen/entrypoint/cli.js +28 -23
- package/dist/codegen/index.d.ts +5 -3
- package/dist/codegen/index.js +2 -1
- package/dist/codegen/services/domain.d.ts +18 -16
- package/dist/codegen/services/domain.js +140 -61
- package/dist/codegen/services/generated.d.ts +23 -0
- package/dist/codegen/services/generated.js +34 -0
- package/dist/codegen/services/scaffold.d.ts +3 -2
- package/dist/codegen/services/scaffold.js +5 -3
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/common/time.d.ts +28 -0
- package/dist/common/time.js +49 -0
- package/dist/core/entrypoint/screens.d.ts +1 -1
- package/dist/core/entrypoint/screens.js +3 -3
- package/dist/core/infrastructure/process.d.ts +9 -0
- package/dist/core/infrastructure/process.js +2 -0
- package/dist/model/domain/meta.d.ts +2 -2
- package/dist/model/domain/meta.js +1 -1
- package/package.json +1 -1
package/dist/common/time.js
CHANGED
|
@@ -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
|
|
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 (
|
|
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
|
-
|
|
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.
|
|
31
|
-
*
|
|
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. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/client-framework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|