@sincpro/client-framework 1.6.0 → 1.6.1
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/AGENTS.md +12 -2
- package/README.md +6 -3
- package/dist/client/adapters/json-rpc.js +3 -2
- package/dist/client/adapters/memory.js +3 -2
- package/dist/client/adapters/rest-operations.js +3 -2
- package/dist/client/adapters/rest.js +3 -2
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/services/guarded.js +4 -3
- package/dist/client/services/propagation.d.ts +21 -9
- package/dist/client/services/propagation.js +60 -3
- package/dist/core/entrypoint/screens.js +2 -1
- package/dist/core/services/binding.d.ts +5 -2
- package/dist/core/services/binding.js +5 -8
- package/dist/observability/adapters/console.d.ts +0 -4
- package/dist/observability/adapters/console.js +12 -4
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -158,9 +158,19 @@ module has only the layers it needs, and says what it offers in its own `index.t
|
|
|
158
158
|
- **Decorators are optional.** Function registration must work without any decorator
|
|
159
159
|
transform. Standard and legacy (`experimentalDecorators`) fixtures are compiled explicitly in
|
|
160
160
|
tests; do not claim Metro (Babel) or web bundler support without testing those configurations.
|
|
161
|
+
- **A run binds what says it can be bound, never what looks like a transport.** A dependency is
|
|
162
|
+
bound only when it carries `BIND`: a generated client, `restOperations`, `jsonRpcOperations`,
|
|
163
|
+
`restTransport`, `memoryTransport`, `guardedTransport`, `screensTransport`, and what a
|
|
164
|
+
platform marks with `bindableOperations(…)` / `bindableTransport(…)`. Nothing else — not an
|
|
165
|
+
object with `list`/`one`/`send`, not one with a `call` — is ever wrapped: an application's
|
|
166
|
+
abstraction reaches its use cases as it is.
|
|
167
|
+
An object is never taken for an `OperationTransport` because it has a `call`: an Odoo client's
|
|
168
|
+
is `call(service, method, args)`, and binding it hid `setServer` and rewrote its `args` — only
|
|
169
|
+
with a trace to carry, so never in a test without a tracer. Binding wraps only the wire's
|
|
170
|
+
methods; the dependency's state, methods and getters stay its own (`keeping`).
|
|
161
171
|
- **The trace reaches the wire through the dependencies.** A dependency is bound to the run when it
|
|
162
|
-
|
|
163
|
-
else is handed as it is. A client built elsewhere and closed over sends no trace.
|
|
172
|
+
carries `BIND` (every generated client does, through `bindable`; the framework's transports do);
|
|
173
|
+
anything else is handed as it is. A client built elsewhere and closed over sends no trace.
|
|
164
174
|
- **The process is read on every call, never at import.** `project` is defined when its module
|
|
165
175
|
loads, before `main` runs `configureProcess`; nothing may capture the tracer, the reporter or the
|
|
166
176
|
store at definition time. `configureProcess` replaces everything at once — a test calls it in
|
package/README.md
CHANGED
|
@@ -506,9 +506,12 @@ are its children, on the same trace. Each span, log record and report says who w
|
|
|
506
506
|
sincpro_framework's keys: `release` (`<name>:<version>`, the backend's `APP_RELEASE`) and, when
|
|
507
507
|
there is one, `tenant` — the run's context's, else the deployment's. `processIdentity()` gives
|
|
508
508
|
`release`, `serviceName` and `serviceVersion` (read out of the release with the backend's rules)
|
|
509
|
-
to a platform's tracer resource and log labels; nothing else of the context is copied. A dependency that
|
|
510
|
-
|
|
511
|
-
`
|
|
509
|
+
to a platform's tracer resource and log labels; nothing else of the context is copied. A dependency that says it can be bound — a generated
|
|
510
|
+
client, or one of the framework's transports (`restTransport`, `restOperations`,
|
|
511
|
+
`jsonRpcOperations`, `guardedTransport`; `bindableTransport`/`bindableOperations` for a
|
|
512
|
+
platform's own) — is bound to the run, so each request carries `traceparent` (and `tracestate`)
|
|
513
|
+
and `sincpro-context` — the backend continues the trace. Nothing is guessed from a method's
|
|
514
|
+
name: an application's own object (an Odoo client with a `call`) reaches its use cases as it is. A tracer, reporter or logger that fails is
|
|
512
515
|
ignored: telling about a use case never changes its answer.
|
|
513
516
|
|
|
514
517
|
The vendor entries wrap what the application built — they initialize nothing, read no
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OperationNotPublished, } from "../domain/operation.js";
|
|
2
|
+
import { bindableOperations } from "../services/propagation.js";
|
|
2
3
|
import { kindOfJsonRpcCode } from "../../common/failures.js";
|
|
3
4
|
import { readProblem } from "@sincpro/criteria";
|
|
4
5
|
/**
|
|
@@ -49,7 +50,7 @@ let next = 0;
|
|
|
49
50
|
export function jsonRpcOperations(options) {
|
|
50
51
|
const send = options.fetch ?? ((...args) => fetch(...args));
|
|
51
52
|
const own = () => typeof options.headers === "function" ? options.headers() : options.headers;
|
|
52
|
-
return {
|
|
53
|
+
return bindableOperations({
|
|
53
54
|
async call(operation, input, call = {}) {
|
|
54
55
|
const method = operation.rpc?.method;
|
|
55
56
|
if (method === undefined)
|
|
@@ -93,5 +94,5 @@ export function jsonRpcOperations(options) {
|
|
|
93
94
|
}
|
|
94
95
|
return answer.result;
|
|
95
96
|
},
|
|
96
|
-
};
|
|
97
|
+
});
|
|
97
98
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransportError, } from "../domain/transport.js";
|
|
2
|
+
import { bindableTransport } from "../services/propagation.js";
|
|
2
3
|
import { pack, readValues } from "../../common/serialization.js";
|
|
3
4
|
import { answer, answerGroups } from "@sincpro/criteria/engine";
|
|
4
5
|
/**
|
|
@@ -44,7 +45,7 @@ export function memoryTransport(tables, options = {}) {
|
|
|
44
45
|
});
|
|
45
46
|
return table;
|
|
46
47
|
}
|
|
47
|
-
return {
|
|
48
|
+
return bindableTransport({
|
|
48
49
|
async list(route, criteria, signal) {
|
|
49
50
|
options.observe?.(route, criteria);
|
|
50
51
|
await check(route, signal);
|
|
@@ -116,5 +117,5 @@ export function memoryTransport(tables, options = {}) {
|
|
|
116
117
|
return copyOf(await options.read(route));
|
|
117
118
|
},
|
|
118
119
|
}),
|
|
119
|
-
};
|
|
120
|
+
});
|
|
120
121
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OperationNotPublished, } from "../domain/operation.js";
|
|
2
2
|
import { downloadRoute, readRoute, } from "../domain/transport.js";
|
|
3
|
+
import { bindableOperations } from "../services/propagation.js";
|
|
3
4
|
const PATH_KEY = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
4
5
|
/** What a value is in a query string: text as it is, anything else as JSON (`criteria`). */
|
|
5
6
|
function queryValue(value) {
|
|
@@ -41,7 +42,7 @@ function withQuery(route, fields) {
|
|
|
41
42
|
* Final: the operation's answer, as the contract describes it.
|
|
42
43
|
*/
|
|
43
44
|
export function restOperations(transport) {
|
|
44
|
-
return {
|
|
45
|
+
return bindableOperations({
|
|
45
46
|
call(operation, input, options = {}) {
|
|
46
47
|
const rest = operation.rest;
|
|
47
48
|
if (rest === undefined)
|
|
@@ -62,5 +63,5 @@ export function restOperations(transport) {
|
|
|
62
63
|
return Promise.reject(error);
|
|
63
64
|
}
|
|
64
65
|
},
|
|
65
|
-
};
|
|
66
|
+
});
|
|
66
67
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TransportError, } from "../domain/transport.js";
|
|
2
2
|
import { definitionOf, modelAt, } from "../services/discovery.js";
|
|
3
|
+
import { bindableTransport } from "../services/propagation.js";
|
|
3
4
|
import { readProblem } from "@sincpro/criteria";
|
|
4
5
|
import { RestError, restSource } from "@sincpro/criteria/rest";
|
|
5
6
|
/** The keys of an answer that are not the record: what is left is the record's own field. */
|
|
@@ -130,7 +131,7 @@ export function restTransport(options = {}) {
|
|
|
130
131
|
throw new TransportError(route, response.status, readProblem(text), undefined);
|
|
131
132
|
return text ? JSON.parse(text) : null;
|
|
132
133
|
}
|
|
133
|
-
return {
|
|
134
|
+
return bindableTransport({
|
|
134
135
|
async list(route, criteria, signal, call) {
|
|
135
136
|
const source = restSource(`${base}${route}`, {
|
|
136
137
|
// Only a page may come in another format: the decoders are said here, and nowhere else.
|
|
@@ -184,5 +185,5 @@ export function restTransport(options = {}) {
|
|
|
184
185
|
async send(method, route, body, signal, sending) {
|
|
185
186
|
return (await get(route, urlOf(base, route), signal, { method, body, key: sending?.idempotencyKey }, sending));
|
|
186
187
|
},
|
|
187
|
-
};
|
|
188
|
+
});
|
|
188
189
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export { bodyFor, type CommandAnswers, type CommandBodies, type CommandRoute, ty
|
|
|
16
16
|
export { OperationNotPublished, type OperationOptions, type OperationTransport, type RemoteOperation, } from "./domain/operation.js";
|
|
17
17
|
export { type CallOptions, type Decoder, type Download, downloadRoute, type Draft, type Method, type One, readRoute, type SendOptions, type Transport, TransportError, } from "./domain/transport.js";
|
|
18
18
|
export { guardedTransport } from "./services/guarded.js";
|
|
19
|
-
export { bindable, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
|
|
19
|
+
export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
|
|
20
20
|
export { type RetryKeys, retryKeys, unanswered, } from "./services/retry.js";
|
package/dist/client/index.js
CHANGED
|
@@ -16,5 +16,5 @@ export { bodyFor, entity, exportRoute, listRoute, NEW_PARAM, pathFor, PICK_PARAM
|
|
|
16
16
|
export { OperationNotPublished, } from "./domain/operation.js";
|
|
17
17
|
export { downloadRoute, readRoute, TransportError, } from "./domain/transport.js";
|
|
18
18
|
export { guardedTransport } from "./services/guarded.js";
|
|
19
|
-
export { bindable, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
|
|
19
|
+
export { bindable, bindableOperations, bindableTransport, bindOperations, bindTransport, headersOf, } from "./services/propagation.js";
|
|
20
20
|
export { retryKeys, unanswered, } from "./services/retry.js";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isOperationTransport, } from "../domain/operation.js";
|
|
2
|
+
import { bindableOperations, bindableTransport, } from "./propagation.js";
|
|
2
3
|
export function guardedTransport(transport, breaker) {
|
|
3
4
|
if (isOperationTransport(transport))
|
|
4
|
-
return {
|
|
5
|
+
return bindableOperations({
|
|
5
6
|
call: (operation, input, options) => breaker.call(() => transport.call(operation, input, options)),
|
|
6
|
-
};
|
|
7
|
+
});
|
|
7
8
|
const guarded = {
|
|
8
9
|
list: (route, criteria, signal, options) => breaker.call(() => transport.list(route, criteria, signal, options)),
|
|
9
10
|
one: (route, signal, options) => breaker.call(() => transport.one(route, signal, options)),
|
|
@@ -15,5 +16,5 @@ export function guardedTransport(transport, breaker) {
|
|
|
15
16
|
const download = transport.download;
|
|
16
17
|
if (download !== undefined)
|
|
17
18
|
guarded.download = (route, signal, options) => breaker.call(() => download.call(transport, route, signal, options));
|
|
18
|
-
return guarded;
|
|
19
|
+
return bindableTransport(guarded);
|
|
19
20
|
}
|
|
@@ -9,15 +9,6 @@ export declare function isTransport(value: unknown): value is Transport;
|
|
|
9
9
|
* Nothing when there is no trace and no context that travels.
|
|
10
10
|
*/
|
|
11
11
|
export declare function headersOf(execution: Execution): Record<string, string>;
|
|
12
|
-
/**
|
|
13
|
-
* The transport, writing the execution's headers on every call — the caller's own headers of a
|
|
14
|
-
* call still win.
|
|
15
|
-
*
|
|
16
|
-
* Context: the transport's own headers (`restTransport({ headers })`) are the session's — the
|
|
17
|
-
* token, the tenant — the same for every call; these are the use case's, different for two use
|
|
18
|
-
* cases running at once, so they travel per call (`CallOptions`). A call that gives no signal of
|
|
19
|
-
* its own is cancelled with the run.
|
|
20
|
-
*/
|
|
21
12
|
export declare function bindTransport(transport: Transport, execution: Execution): Transport;
|
|
22
13
|
/**
|
|
23
14
|
* The operation transport, calling as `execution`: every call carries the run's trace and
|
|
@@ -25,6 +16,27 @@ export declare function bindTransport(transport: Transport, execution: Execution
|
|
|
25
16
|
* win.
|
|
26
17
|
*/
|
|
27
18
|
export declare function bindOperations(transport: OperationTransport, execution: Execution): OperationTransport;
|
|
19
|
+
/**
|
|
20
|
+
* A REST `Transport` a run binds to itself when it is a dependency: its requests carry the run's
|
|
21
|
+
* trace, context and signal. `restTransport`, `memoryTransport`, `guardedTransport` and
|
|
22
|
+
* `screensTransport` answer one; a platform's own marks itself with it.
|
|
23
|
+
*
|
|
24
|
+
* Context: a run binds only what says it can be bound — never an object because it has `list`,
|
|
25
|
+
* `one` and `send`: an application's own object with those names is the application's.
|
|
26
|
+
*/
|
|
27
|
+
export declare function bindableTransport<T extends Transport>(transport: T): T;
|
|
28
|
+
/**
|
|
29
|
+
* An `OperationTransport` a run binds to itself when it is a dependency: its `call` carries the
|
|
30
|
+
* run's trace, context and signal. `restOperations`, `jsonRpcOperations` and `guardedTransport`
|
|
31
|
+
* answer one; a platform's own (gRPC) marks itself with it.
|
|
32
|
+
*
|
|
33
|
+
* boundedContext.addDependency("operations", bindableOperations(grpcOperations(channel)));
|
|
34
|
+
*
|
|
35
|
+
* Context: an object is not taken for a transport because it has a `call` — an Odoo client's is
|
|
36
|
+
* `call(service, method, args)`, and binding it rewrote its arguments and hid its other methods.
|
|
37
|
+
* A run binds what says it can be bound (`BIND`) and a REST `Transport`; nothing else.
|
|
38
|
+
*/
|
|
39
|
+
export declare function bindableOperations<T extends OperationTransport>(transport: T): T;
|
|
28
40
|
/** A transport of either kind, bound to `execution`. */
|
|
29
41
|
export declare function bound<W extends Transport | OperationTransport>(wire: W, execution: Execution): W;
|
|
30
42
|
/**
|
|
@@ -39,6 +39,28 @@ export function headersOf(execution) {
|
|
|
39
39
|
* cases running at once, so they travel per call (`CallOptions`). A call that gives no signal of
|
|
40
40
|
* its own is cancelled with the run.
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* The dependency as it is — its state, its own methods, its getters —, with only its wire's
|
|
44
|
+
* methods carrying the run. Binding a transport never takes away what the dependency is: an
|
|
45
|
+
* Odoo client that happens to have a `call` is still the Odoo client, and `setServer` still sets
|
|
46
|
+
* the server of the one the app holds.
|
|
47
|
+
*
|
|
48
|
+
* Context: it used to answer a new object with only the wire's methods, and only when the run had
|
|
49
|
+
* something to carry (a trace, a context, a signal): with tracing on, every other method vanished
|
|
50
|
+
* — `this.odoo.setServer is not a function` on a phone, never in a test without a tracer.
|
|
51
|
+
*/
|
|
52
|
+
function keeping(original, wire) {
|
|
53
|
+
return new Proxy(original, {
|
|
54
|
+
get(target, property) {
|
|
55
|
+
if (Object.hasOwn(wire, property))
|
|
56
|
+
return wire[property];
|
|
57
|
+
const value = Reflect.get(target, property, target);
|
|
58
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
59
|
+
},
|
|
60
|
+
set: (target, property, value) => Reflect.set(target, property, value, target),
|
|
61
|
+
has: (target, property) => Object.hasOwn(wire, property) || property in target,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
42
64
|
export function bindTransport(transport, execution) {
|
|
43
65
|
const own = headersOf(execution);
|
|
44
66
|
const cancels = execution.signal;
|
|
@@ -56,7 +78,7 @@ export function bindTransport(transport, execution) {
|
|
|
56
78
|
const download = transport.download;
|
|
57
79
|
if (download !== undefined)
|
|
58
80
|
bound.download = (route, signal, options) => download.call(transport, route, signal ?? cancels, call(options));
|
|
59
|
-
return bound;
|
|
81
|
+
return keeping(transport, bound);
|
|
60
82
|
}
|
|
61
83
|
/**
|
|
62
84
|
* The operation transport, calling as `execution`: every call carries the run's trace and
|
|
@@ -68,13 +90,48 @@ export function bindOperations(transport, execution) {
|
|
|
68
90
|
const cancels = execution.signal;
|
|
69
91
|
if (Object.keys(own).length === 0 && cancels === undefined)
|
|
70
92
|
return transport;
|
|
71
|
-
return {
|
|
93
|
+
return keeping(transport, {
|
|
72
94
|
call: (operation, input, options) => transport.call(operation, input, {
|
|
73
95
|
...options,
|
|
74
96
|
headers: { ...own, ...options?.headers },
|
|
75
97
|
...((options?.signal ?? cancels) ? { signal: options?.signal ?? cancels } : {}),
|
|
76
98
|
}),
|
|
77
|
-
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A REST `Transport` a run binds to itself when it is a dependency: its requests carry the run's
|
|
103
|
+
* trace, context and signal. `restTransport`, `memoryTransport`, `guardedTransport` and
|
|
104
|
+
* `screensTransport` answer one; a platform's own marks itself with it.
|
|
105
|
+
*
|
|
106
|
+
* Context: a run binds only what says it can be bound — never an object because it has `list`,
|
|
107
|
+
* `one` and `send`: an application's own object with those names is the application's.
|
|
108
|
+
*/
|
|
109
|
+
export function bindableTransport(transport) {
|
|
110
|
+
Object.defineProperty(transport, BIND, {
|
|
111
|
+
value: (execution) => bindTransport(transport, execution),
|
|
112
|
+
enumerable: false,
|
|
113
|
+
configurable: true,
|
|
114
|
+
});
|
|
115
|
+
return transport;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* An `OperationTransport` a run binds to itself when it is a dependency: its `call` carries the
|
|
119
|
+
* run's trace, context and signal. `restOperations`, `jsonRpcOperations` and `guardedTransport`
|
|
120
|
+
* answer one; a platform's own (gRPC) marks itself with it.
|
|
121
|
+
*
|
|
122
|
+
* boundedContext.addDependency("operations", bindableOperations(grpcOperations(channel)));
|
|
123
|
+
*
|
|
124
|
+
* Context: an object is not taken for a transport because it has a `call` — an Odoo client's is
|
|
125
|
+
* `call(service, method, args)`, and binding it rewrote its arguments and hid its other methods.
|
|
126
|
+
* A run binds what says it can be bound (`BIND`) and a REST `Transport`; nothing else.
|
|
127
|
+
*/
|
|
128
|
+
export function bindableOperations(transport) {
|
|
129
|
+
Object.defineProperty(transport, BIND, {
|
|
130
|
+
value: (execution) => bindOperations(transport, execution),
|
|
131
|
+
enumerable: false,
|
|
132
|
+
configurable: true,
|
|
133
|
+
});
|
|
134
|
+
return transport;
|
|
78
135
|
}
|
|
79
136
|
/** A transport of either kind, bound to `execution`. */
|
|
80
137
|
export function bound(wire, execution) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bindableTransport } from "../../client/services/propagation.js";
|
|
1
2
|
import { Command } from "../domain/dto.js";
|
|
2
3
|
import { Feature } from "../domain/services.js";
|
|
3
4
|
import { BoundedContext } from "./bounded-context.js";
|
|
@@ -127,5 +128,5 @@ export function screensTransport(transport, name = "screens") {
|
|
|
127
128
|
through.download = (route, signal, options) => screens.execute(new Export(route, signal, options));
|
|
128
129
|
}
|
|
129
130
|
MADE.add(through);
|
|
130
|
-
return through;
|
|
131
|
+
return bindableTransport(through);
|
|
131
132
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type Execution } from "../../context/domain/execution.js";
|
|
2
2
|
/**
|
|
3
|
-
* A dependency as the execution should see it: bound when it can be (`BIND
|
|
4
|
-
*
|
|
3
|
+
* A dependency as the execution should see it: bound when it says it can be (`BIND` — a
|
|
4
|
+
* generated client, `restOperations`, `jsonRpcOperations`, `restTransport`, `memoryTransport`,
|
|
5
|
+
* `guardedTransport`, `bindableOperations(…)`, `bindableTransport(…)`); as it is otherwise.
|
|
6
|
+
* Never guessed from a method's name: an application's object — an Odoo client with a `call`,
|
|
7
|
+
* a repository with a `list` — is the application's, untouched.
|
|
5
8
|
*/
|
|
6
9
|
export declare function bindDependency<T>(value: T, execution: Execution): T;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { isOperationTransport } from "../../client/domain/operation.js";
|
|
2
|
-
import { bindOperations, bindTransport, isTransport, } from "../../client/services/propagation.js";
|
|
3
1
|
import { BIND, isBindable, } from "../../context/domain/execution.js";
|
|
4
2
|
/**
|
|
5
|
-
* A dependency as the execution should see it: bound when it can be (`BIND
|
|
6
|
-
*
|
|
3
|
+
* A dependency as the execution should see it: bound when it says it can be (`BIND` — a
|
|
4
|
+
* generated client, `restOperations`, `jsonRpcOperations`, `restTransport`, `memoryTransport`,
|
|
5
|
+
* `guardedTransport`, `bindableOperations(…)`, `bindableTransport(…)`); as it is otherwise.
|
|
6
|
+
* Never guessed from a method's name: an application's object — an Odoo client with a `call`,
|
|
7
|
+
* a repository with a `list` — is the application's, untouched.
|
|
7
8
|
*/
|
|
8
9
|
export function bindDependency(value, execution) {
|
|
9
10
|
if (isBindable(value))
|
|
10
11
|
return value[BIND](execution);
|
|
11
|
-
if (isTransport(value))
|
|
12
|
-
return bindTransport(value, execution);
|
|
13
|
-
if (isOperationTransport(value))
|
|
14
|
-
return bindOperations(value, execution);
|
|
15
12
|
return value;
|
|
16
13
|
}
|
|
@@ -5,8 +5,4 @@ export type ConsoleLoggerOptions = {
|
|
|
5
5
|
level?: LogLevel;
|
|
6
6
|
layers?: Partial<Record<LogLayer, boolean>>;
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
* Built-in console engine: silent in production, configurable
|
|
10
|
-
* development layers, and WARN/ERROR preserved. Other sinks are filtered independently.
|
|
11
|
-
*/
|
|
12
8
|
export declare function consoleLogger(options: ConsoleLoggerOptions): Logger;
|
|
@@ -3,6 +3,13 @@ const RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
|
3
3
|
* Built-in console engine: silent in production, configurable
|
|
4
4
|
* development layers, and WARN/ERROR preserved. Other sinks are filtered independently.
|
|
5
5
|
*/
|
|
6
|
+
/** The failure as an Error to print: its type as its name, its message, its stack. */
|
|
7
|
+
function errorOf(stack, failure) {
|
|
8
|
+
const shown = new Error(failure.message ?? failure.type ?? "");
|
|
9
|
+
shown.name = failure.type ?? "Error";
|
|
10
|
+
shown.stack = stack;
|
|
11
|
+
return shown;
|
|
12
|
+
}
|
|
6
13
|
export function consoleLogger(options) {
|
|
7
14
|
const mode = options.mode;
|
|
8
15
|
if (mode !== "development" && mode !== "production") {
|
|
@@ -29,15 +36,16 @@ export function consoleLogger(options) {
|
|
|
29
36
|
: record.level === "error"
|
|
30
37
|
? console.error
|
|
31
38
|
: console.log;
|
|
32
|
-
// An unexpected failure's stack prints as a stack, readable, after its line — not escaped
|
|
33
|
-
// inside the record.
|
|
34
39
|
const stack = record.failure?.stack;
|
|
35
40
|
if (!stack) {
|
|
36
41
|
method.call(console, prefix, record.message, record);
|
|
37
42
|
return;
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
// An unexpected failure goes as an Error — its name, its message, its stack —: what React
|
|
45
|
+
// Native's LogBox, Expo's terminal and a browser print as a failure, with its code frame.
|
|
46
|
+
// A bare stack string read as one printed `ERROR null null`.
|
|
47
|
+
const { stack: _shownBelow, ...failure } = record.failure ?? {};
|
|
48
|
+
method.call(console, `${prefix} ${record.message}`, { ...record, failure }, errorOf(stack, failure));
|
|
41
49
|
},
|
|
42
50
|
};
|
|
43
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/client-framework",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
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",
|