@brickkit/core 0.11.0 → 0.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/dist/chunks/client.d.ts +5 -2763
- package/dist/chunks/client.js +17 -12
- package/dist/chunks/client.js.map +1 -1
- package/dist/chunks/index.d.ts +1106 -0
- package/dist/chunks/server.js +4624 -0
- package/dist/chunks/server.js.map +1 -0
- package/dist/chunks/types.d.ts +2701 -0
- package/dist/chunks/workflow.d.ts +74 -0
- package/dist/client.d.ts +3 -2
- package/dist/index.d.ts +5 -1151
- package/dist/index.js +128 -4705
- package/dist/index.js.map +1 -1
- package/dist/pg.d.ts +0 -2
- package/dist/tanstack-query.d.ts +2 -3
- package/dist/tanstack-query.js +1 -2
- package/dist/testing.d.ts +31 -0
- package/dist/testing.js +47 -0
- package/dist/testing.js.map +1 -0
- package/dist/workflow.d.ts +2 -0
- package/dist/workflow.js +93 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +31 -17
- package/dist/chunks/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/pg.d.ts.map +0 -1
- package/dist/tanstack-query.d.ts.map +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { C as ErrorDetails, Xn as ListenerFailure, s as ActionErrorDefinition } from "./types.js";
|
|
2
|
+
import { TSchema, Type as t } from "@sinclair/typebox";
|
|
3
|
+
/**
|
|
4
|
+
* Define a reusable error. Spread it into the `errors` of any action, listener,
|
|
5
|
+
* command, socket or step; give it a `details` schema and
|
|
6
|
+
* `error.CODE(message, details)` checks the details against it in types. The
|
|
7
|
+
* details are not validated at runtime.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const SlugExists = defineError("SLUG_EXISTS", {
|
|
11
|
+
* status: 409,
|
|
12
|
+
* message: "Slug is already taken",
|
|
13
|
+
* details: t.Object({ slug: t.String() }),
|
|
14
|
+
* });
|
|
15
|
+
* // errors: { ...SlugExists } then error.SLUG_EXISTS(undefined, { slug })
|
|
16
|
+
*/
|
|
17
|
+
declare function defineError<const TCode extends string, TDetails extends TSchema | undefined = undefined>(code: TCode, definition: {
|
|
18
|
+
status?: number;
|
|
19
|
+
message: string;
|
|
20
|
+
details?: TDetails;
|
|
21
|
+
}): { [K in TCode]: {
|
|
22
|
+
status?: number;
|
|
23
|
+
message: string;
|
|
24
|
+
} & (TDetails extends TSchema ? {
|
|
25
|
+
details: TDetails;
|
|
26
|
+
} : {}); };
|
|
27
|
+
/** The `error` helpers of a step: one per declared code, each throws a step error that is not retried. */
|
|
28
|
+
type StepErrorBuilder<TErrors extends Record<string, ActionErrorDefinition>> = { [K in keyof TErrors]: TErrors[K] extends {
|
|
29
|
+
details: TSchema;
|
|
30
|
+
} ? (message: string | undefined, details: ErrorDetails<TErrors[K]>, options?: ErrorOptions) => never : (message?: string, details?: unknown, options?: ErrorOptions) => never; };
|
|
31
|
+
/**
|
|
32
|
+
* Helpers that raise typed errors from a workflow step: `error.CODE(message?,
|
|
33
|
+
* details?)`, as in an action or listener. A declared error is an outcome, not
|
|
34
|
+
* a glitch, so the Workflow SDK does not retry the step: the workflow's `await`
|
|
35
|
+
* rejects at once. Read it in the workflow with {@link stepFailure}.
|
|
36
|
+
*
|
|
37
|
+
* @param errors - The codes the step can raise: `defineError(...)` results or
|
|
38
|
+
* `errorsOf(action)`, spread into one object.
|
|
39
|
+
* @returns One helper per code. Each always throws.
|
|
40
|
+
* @example
|
|
41
|
+
* import { stepErrors } from "@brickkit/core/workflow";
|
|
42
|
+
*
|
|
43
|
+
* export const carrierErrors = { ...CarrierRejected };
|
|
44
|
+
* const error = stepErrors(carrierErrors);
|
|
45
|
+
*
|
|
46
|
+
* async function bookCarrier(orderId: string) {
|
|
47
|
+
* "use step";
|
|
48
|
+
* const booking = await carrier.book(orderId);
|
|
49
|
+
* if (!booking.ok) error.CARRIER_REJECTED(undefined, { reason: booking.reason });
|
|
50
|
+
* return booking.trackingId;
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
declare function stepErrors<const TErrors extends Record<string, ActionErrorDefinition>>(errors: TErrors): StepErrorBuilder<TErrors>;
|
|
54
|
+
/**
|
|
55
|
+
* Read a failed step in the workflow: the typed error it raised with
|
|
56
|
+
* {@link stepErrors}, or `{ code: "UNKNOWN", message, cause }` for anything
|
|
57
|
+
* else (a step that threw something undeclared, or ran out of retries). The
|
|
58
|
+
* same shape a listener's `retry` receives.
|
|
59
|
+
*
|
|
60
|
+
* @param error - What the workflow caught from `await step()`.
|
|
61
|
+
* @param errors - The codes to recognize: the same object given to `stepErrors`.
|
|
62
|
+
* @returns A union with one member per declared code, narrowed by `code`.
|
|
63
|
+
* @example
|
|
64
|
+
* try {
|
|
65
|
+
* await bookCarrier(order.id);
|
|
66
|
+
* } catch (caught) {
|
|
67
|
+
* const failure = stepFailure(caught, carrierErrors);
|
|
68
|
+
* if (failure.code !== "CARRIER_REJECTED") throw caught;
|
|
69
|
+
* await notifyCustomer(order, failure.details.reason);
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
declare function stepFailure<const TErrors extends Record<string, ActionErrorDefinition>>(error: unknown, errors: TErrors): ListenerFailure<TErrors>;
|
|
73
|
+
export { t as a, stepFailure as i, defineError as n, stepErrors as r, StepErrorBuilder as t };
|
|
74
|
+
//# sourceMappingURL=workflow.d.ts.map
|
package/dist/client.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { $ as BrickSocketConnectOptions, X as BrickClientSocket, Z as BrickSocketClient, at as BrickSocketSender, dt as SocketEventArgs, et as BrickSocketError, nt as BrickSocketHandlerError, ot as BrickSocketStatus, rt as BrickSocketReconnectOptions } from "./chunks/types.js";
|
|
2
|
+
import { a as BrickClientOptions, c as BrickTransportError, d as InferActionInput, f as InferActionOutput, h as isBrickTransportError, i as BrickClientAction, l as InferActionErrorCodes, m as isBrickServerError, n as BrickCallOptions, o as BrickServerError, p as createBrickClient, r as BrickClient, s as BrickServices, t as BrickActionCaller, u as InferActionFailure } from "./chunks/client.js";
|
|
3
|
+
export { BrickActionCaller, BrickCallOptions, BrickClient, BrickClientAction, BrickClientOptions, type BrickClientSocket, BrickServerError, BrickServices, type BrickSocketClient, type BrickSocketConnectOptions, BrickSocketError, type BrickSocketHandlerError, type BrickSocketReconnectOptions, type BrickSocketSender, type BrickSocketStatus, BrickTransportError, InferActionErrorCodes, InferActionFailure, InferActionInput, InferActionOutput, type SocketEventArgs, createBrickClient, isBrickServerError, isBrickTransportError };
|