@sincpro/client-framework 0.2.0 → 0.3.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/AGENTS.md +31 -14
- package/MANIFESTO.md +37 -23
- package/README.md +274 -29
- package/dist/adapters/opentelemetry.d.ts +1 -1
- package/dist/adapters/opentelemetry.js +1 -1
- package/dist/adapters/sentry.d.ts +2 -2
- package/dist/adapters/sentry.js +2 -2
- package/dist/client/memory.js +13 -6
- package/dist/context/context.d.ts +45 -0
- package/dist/context/context.js +70 -0
- package/dist/context/store.d.ts +51 -0
- package/dist/context/store.js +59 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +8 -3
- package/dist/observability/ports.d.ts +2 -2
- package/dist/services/bounded-context.d.ts +79 -0
- package/dist/services/bounded-context.js +272 -0
- package/dist/services/execution.d.ts +6 -6
- package/dist/services/execution.js +2 -2
- package/dist/services/feature.d.ts +70 -48
- package/dist/services/feature.js +57 -191
- package/dist/services/process.d.ts +60 -0
- package/dist/services/process.js +57 -0
- package/dist/testing/index.d.ts +3 -3
- package/package.json +2 -2
- package/dist/services/runtime.d.ts +0 -48
- package/dist/services/runtime.js +0 -30
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type ErrorReporter, type Outcome, type Tracer } from "../observability/ports.js";
|
|
2
|
-
/**
|
|
3
|
-
* What every use case of an application runs with: who traces, who reports, and the context
|
|
4
|
-
* each one carries to the server.
|
|
5
|
-
*
|
|
6
|
-
* const runtime = createRuntime({
|
|
7
|
-
* tracer, // the platform's (OpenTelemetry, …)
|
|
8
|
-
* reporter, // the platform's (GlitchTip, …)
|
|
9
|
-
* context: () => ({ tenant_id: session.tenant }),
|
|
10
|
-
* });
|
|
11
|
-
* const project = bindServices(runtime, "project", { sendIssue, closeIssue });
|
|
12
|
-
* await project.closeIssue.execute({ issue_id: "acme-3" });
|
|
13
|
-
*
|
|
14
|
-
* Context: sincpro_framework's bus is what gives every use case its span, its error report and
|
|
15
|
-
* its context; here the same comes from the interceptors of `Feature`, and this is what they
|
|
16
|
-
* read. A use case that was never bound runs too — with nothing tracing and nothing reporting —
|
|
17
|
-
* so a Feature is tested by constructing it.
|
|
18
|
-
*/
|
|
19
|
-
export type RuntimeOptions = {
|
|
20
|
-
tracer?: Tracer;
|
|
21
|
-
reporter?: ErrorReporter;
|
|
22
|
-
/**
|
|
23
|
-
* What a use case runs with, read once where a gesture starts and inherited by every use case
|
|
24
|
-
* it executes. It is what services read (`this.context`) and what travels to the server in
|
|
25
|
-
* `sincpro-context` — never a secret: the token goes in the transport's headers.
|
|
26
|
-
*/
|
|
27
|
-
context?: () => Readonly<Record<string, unknown>>;
|
|
28
|
-
/** How an error ended a use case (`outcomeOf` by default). Only `failed` is reported. */
|
|
29
|
-
outcomeOf?: (error: unknown) => Outcome;
|
|
30
|
-
};
|
|
31
|
-
export type Runtime = {
|
|
32
|
-
readonly tracer: Tracer;
|
|
33
|
-
readonly reporter: ErrorReporter | undefined;
|
|
34
|
-
readonly context: () => Readonly<Record<string, unknown>>;
|
|
35
|
-
readonly outcomeOf: (error: unknown) => Outcome;
|
|
36
|
-
};
|
|
37
|
-
export declare function createRuntime(options?: RuntimeOptions): Runtime;
|
|
38
|
-
/** Where a use case that was never bound runs: nothing traces, nothing reports. */
|
|
39
|
-
export declare const DETACHED: Runtime;
|
|
40
|
-
/**
|
|
41
|
-
* How an error ended a use case, by default.
|
|
42
|
-
*
|
|
43
|
-
* Context: the backend reports what nobody expected and only that — a refusal it explained is
|
|
44
|
-
* the business answering, not a fault. Here the same: a `TransportError` the server answered
|
|
45
|
-
* with a 4xx is `refused`; a request the caller stopped waiting for is `aborted`; everything
|
|
46
|
-
* else — a bug, a 5xx, a server nobody could reach — is `failed`, and reported.
|
|
47
|
-
*/
|
|
48
|
-
export declare function outcomeOf(error: unknown): Outcome;
|
package/dist/services/runtime.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TransportError } from "../client/transport.js";
|
|
2
|
-
import { NO_TRACER, } from "../observability/ports.js";
|
|
3
|
-
const NO_CONTEXT = Object.freeze({});
|
|
4
|
-
export function createRuntime(options = {}) {
|
|
5
|
-
return {
|
|
6
|
-
tracer: options.tracer ?? NO_TRACER,
|
|
7
|
-
reporter: options.reporter,
|
|
8
|
-
context: options.context ?? (() => NO_CONTEXT),
|
|
9
|
-
outcomeOf: options.outcomeOf ?? outcomeOf,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/** Where a use case that was never bound runs: nothing traces, nothing reports. */
|
|
13
|
-
export const DETACHED = createRuntime();
|
|
14
|
-
/**
|
|
15
|
-
* How an error ended a use case, by default.
|
|
16
|
-
*
|
|
17
|
-
* Context: the backend reports what nobody expected and only that — a refusal it explained is
|
|
18
|
-
* the business answering, not a fault. Here the same: a `TransportError` the server answered
|
|
19
|
-
* with a 4xx is `refused`; a request the caller stopped waiting for is `aborted`; everything
|
|
20
|
-
* else — a bug, a 5xx, a server nobody could reach — is `failed`, and reported.
|
|
21
|
-
*/
|
|
22
|
-
export function outcomeOf(error) {
|
|
23
|
-
if (error instanceof TransportError && error.status !== null)
|
|
24
|
-
return error.status >= 400 && error.status < 500 ? "refused" : "failed";
|
|
25
|
-
if (error !== null &&
|
|
26
|
-
typeof error === "object" &&
|
|
27
|
-
error.name === "AbortError")
|
|
28
|
-
return "aborted";
|
|
29
|
-
return "failed";
|
|
30
|
-
}
|