milkio 1.3.71 → 1.3.73

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.
@@ -0,0 +1,121 @@
1
+ import type { MilkioResponseFailure } from "../types/index.ts";
2
+ import type { Logger } from "../logger/index.ts";
3
+ export type MilkioFailureKind = "fail" | "fault";
4
+ export interface $failCode {
5
+ NOT_FOUND: {
6
+ path: string;
7
+ };
8
+ METHOD_NOT_ALLOWED: undefined;
9
+ PARAMS_TYPE_INCORRECT: {
10
+ path: string;
11
+ expected: string;
12
+ value: any;
13
+ message: string;
14
+ } | null;
15
+ PARAMS_TYPE_NOT_SUPPORTED: {
16
+ expected: string;
17
+ contentType: string | null;
18
+ params: string;
19
+ };
20
+ NOT_DEVELOP_MODE: string;
21
+ UNACCEPTABLE: {
22
+ expected: string;
23
+ message: string;
24
+ };
25
+ REQUEST_TOO_LARGE: {
26
+ maxBodySize: number;
27
+ };
28
+ }
29
+ export interface $faultCode {
30
+ INTERNAL_SERVER_ERROR: undefined;
31
+ FRAMEWORK_ERROR: {
32
+ message: string;
33
+ };
34
+ RESULTS_TYPE_INCORRECT: {
35
+ path: string;
36
+ expected: string;
37
+ value: any;
38
+ message: string;
39
+ } | null;
40
+ }
41
+ export interface MilkioFail<Code extends string = string, Data = unknown> {
42
+ readonly $milkioFailure: true;
43
+ readonly kind: "fail";
44
+ readonly code: Code;
45
+ readonly data: Data;
46
+ }
47
+ export interface MilkioFaultShape<Code extends string = string, Data = unknown> {
48
+ readonly $milkioFailure: true;
49
+ readonly kind: "fault";
50
+ readonly code: Code;
51
+ readonly data: Data;
52
+ readonly stack?: string;
53
+ }
54
+ export type MilkioFailure = MilkioFail | MilkioFaultShape;
55
+ export interface MilkioPublicFault {
56
+ readonly $milkioFailure: true;
57
+ readonly kind: "fault";
58
+ readonly code: "INTERNAL_SERVER_ERROR";
59
+ readonly data?: undefined;
60
+ }
61
+ export interface MilkioFailWire<Code extends string = string, Data = unknown> {
62
+ kind: "fail";
63
+ code: Code;
64
+ data: Data;
65
+ }
66
+ export interface MilkioFaultWire {
67
+ kind: "fault";
68
+ code: "INTERNAL_SERVER_ERROR";
69
+ }
70
+ export type MilkioFailureWire = MilkioFailWire | MilkioFaultWire;
71
+ /** fail: plain object only — no Error, no stack, no captureStackTrace (hot path). */
72
+ export declare function fail<Code extends string = string>(code: Code, data?: unknown): MilkioFail<Code, unknown>;
73
+ /** fault: Error subclass — captures stack/cause for server-side logs only. */
74
+ export declare class MilkioFaultError extends Error implements MilkioFaultShape {
75
+ readonly $milkioFailure: true;
76
+ readonly kind: "fault";
77
+ readonly code: string;
78
+ readonly data: unknown;
79
+ constructor(code: string, data?: unknown, options?: {
80
+ cause?: unknown;
81
+ stack?: string;
82
+ });
83
+ }
84
+ export declare function fault(code: string, data?: unknown, options?: {
85
+ cause?: unknown;
86
+ }): MilkioFaultError;
87
+ export declare function isMilkioFailure(value: unknown): value is MilkioFailure;
88
+ export interface MilkioFaultReport {
89
+ executeId: string;
90
+ path?: string;
91
+ routeType?: "action" | "stream" | "raw" | "event";
92
+ kind: "fault";
93
+ code: string;
94
+ data: unknown;
95
+ stack?: string;
96
+ cause?: unknown;
97
+ source: "fault" | "unexpected";
98
+ }
99
+ export declare function serializeCause(error: unknown): string;
100
+ type Classified = {
101
+ kind: "fail";
102
+ code: string;
103
+ data: unknown;
104
+ } | {
105
+ kind: "fault";
106
+ code: string;
107
+ data: unknown;
108
+ stack?: string;
109
+ cause?: unknown;
110
+ source: "fault" | "unexpected";
111
+ };
112
+ export declare function classifyFailure(error: unknown): Classified;
113
+ export declare function failureHandler(executeId: string, logger: Logger, error: unknown, options?: {
114
+ path?: string;
115
+ routeType?: MilkioFaultReport["routeType"];
116
+ onError?: (report: MilkioFaultReport) => void;
117
+ }): {
118
+ response: MilkioResponseFailure;
119
+ report?: MilkioFaultReport;
120
+ };
121
+ export {};
package/index.d.ts CHANGED
@@ -15,4 +15,4 @@ export * from "./context/index.ts";
15
15
  export * from "./meta/index.ts";
16
16
  export * from "./step/index.ts";
17
17
  export * from "./listener/index.ts";
18
- export * from "./exception/index.ts";
18
+ export * from "./failure/index.ts";