@nyssa-ai/result 0.0.0-stage → 0.1.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/README.md +111 -2
- package/dist/Err.d.ts +53 -0
- package/dist/Err.d.ts.map +1 -0
- package/dist/Err.js +172 -0
- package/dist/Err.js.map +1 -0
- package/dist/Error.d.ts +47 -0
- package/dist/Error.d.ts.map +1 -0
- package/dist/Error.js +306 -0
- package/dist/Error.js.map +1 -0
- package/dist/ErrorCategory.d.ts +27 -0
- package/dist/ErrorCategory.d.ts.map +1 -0
- package/dist/ErrorCategory.js +25 -0
- package/dist/ErrorCategory.js.map +1 -0
- package/dist/Guard.d.ts +54 -0
- package/dist/Guard.d.ts.map +1 -0
- package/dist/Guard.js +229 -0
- package/dist/Guard.js.map +1 -0
- package/dist/Ok.d.ts +66 -0
- package/dist/Ok.d.ts.map +1 -0
- package/dist/Ok.js +151 -0
- package/dist/Ok.js.map +1 -0
- package/dist/Result.d.ts +112 -0
- package/dist/Result.d.ts.map +1 -0
- package/dist/Result.js +195 -0
- package/dist/Result.js.map +1 -0
- package/dist/ResultException.d.ts +13 -0
- package/dist/ResultException.d.ts.map +1 -0
- package/dist/ResultException.js +30 -0
- package/dist/ResultException.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -4
package/dist/Result.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Responsibility: Provide railway-oriented discriminated-union Result with pure combinators and explicit boundaries.
|
|
2
|
+
// Public interface:
|
|
3
|
+
// +-- Err
|
|
4
|
+
// +-- Ok
|
|
5
|
+
// +-- Result
|
|
6
|
+
// | +-- category
|
|
7
|
+
// | +-- error
|
|
8
|
+
// | +-- errors
|
|
9
|
+
// | +-- isFailure
|
|
10
|
+
// | +-- isSuccess
|
|
11
|
+
// | +-- map(transformation)
|
|
12
|
+
// | +-- mapAsync(transformation)
|
|
13
|
+
// | +-- message
|
|
14
|
+
// | +-- ok
|
|
15
|
+
// | +-- resolve(onSuccess, onFailure)
|
|
16
|
+
// | +-- resolveAsync(onSuccess, onFailure)
|
|
17
|
+
// | +-- then(nextOperation)
|
|
18
|
+
// | +-- thenAsync(nextOperation)
|
|
19
|
+
// | +-- throwIfError()
|
|
20
|
+
// | +-- transform(transformation)
|
|
21
|
+
// | +-- transformAsync(transformation)
|
|
22
|
+
// | +-- tryGetValue()
|
|
23
|
+
// | +-- unwrap()
|
|
24
|
+
// | `-- value
|
|
25
|
+
// +-- fail(errorOrErrors, category, cause)
|
|
26
|
+
// +-- failError(error)
|
|
27
|
+
// +-- ok(value)
|
|
28
|
+
// +-- tryAsync(action, errorHandler, cancellationToken)
|
|
29
|
+
// `-- try_(action, errorHandler, cancellationToken)
|
|
30
|
+
import { Err as ErrClass } from "./Err.js";
|
|
31
|
+
import { Error } from "./Error.js";
|
|
32
|
+
import { ErrorCategory } from "./ErrorCategory.js";
|
|
33
|
+
import { Ok as OkClass } from "./Ok.js";
|
|
34
|
+
function extractCauseType(cause) {
|
|
35
|
+
if (cause === null || cause === undefined) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (typeof cause === "object") {
|
|
39
|
+
const obj = cause;
|
|
40
|
+
if (typeof obj.name === "string" && obj.name.length > 0 && obj.name !== "Error" && obj.name !== "DOMException") {
|
|
41
|
+
return obj.name;
|
|
42
|
+
}
|
|
43
|
+
if (obj.constructor &&
|
|
44
|
+
typeof obj.constructor.name === "string" &&
|
|
45
|
+
obj.constructor.name.length > 0 &&
|
|
46
|
+
obj.constructor.name !== "Object" &&
|
|
47
|
+
obj.constructor.name !== "Error") {
|
|
48
|
+
return obj.constructor.name;
|
|
49
|
+
}
|
|
50
|
+
if (typeof obj.name === "string" && obj.name.length > 0) {
|
|
51
|
+
return obj.name;
|
|
52
|
+
}
|
|
53
|
+
if (obj.constructor && typeof obj.constructor.name === "string" && obj.constructor.name.length > 0) {
|
|
54
|
+
return obj.constructor.name;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return typeof cause;
|
|
58
|
+
}
|
|
59
|
+
function isAbortOrTimeout(exc, cancellationToken) {
|
|
60
|
+
if (cancellationToken === true) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (typeof cancellationToken === "object" && cancellationToken !== null) {
|
|
64
|
+
const tok = cancellationToken;
|
|
65
|
+
if (tok.aborted === true ||
|
|
66
|
+
tok.isCancellationRequested === true ||
|
|
67
|
+
tok.is_cancellation_requested === true ||
|
|
68
|
+
(typeof tok.isSet === "function" && Boolean(tok.isSet())) ||
|
|
69
|
+
(typeof tok.is_set === "function" && Boolean(tok.is_set()))) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (exc !== null && typeof exc === "object") {
|
|
74
|
+
const typeName = (extractCauseType(exc) ?? "").toLowerCase();
|
|
75
|
+
if (typeName === "aborterror" ||
|
|
76
|
+
typeName === "cancelederror" ||
|
|
77
|
+
typeName === "cancellederror" ||
|
|
78
|
+
typeName === "operationcanceledexception" ||
|
|
79
|
+
typeName === "taskcanceledexception" ||
|
|
80
|
+
typeName === "timeouterror" ||
|
|
81
|
+
typeName === "timeoutexception") {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const code = exc.code;
|
|
85
|
+
if (code === "ETIMEDOUT" || code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
/** Re-export Ok class constructor for callers importing from Result. */
|
|
92
|
+
export const Ok = OkClass;
|
|
93
|
+
/** Re-export Err class constructor for callers importing from Result. */
|
|
94
|
+
export const Err = ErrClass;
|
|
95
|
+
/**
|
|
96
|
+
* Wraps a successful value in an immutable Ok arm.
|
|
97
|
+
*/
|
|
98
|
+
export function ok(value) {
|
|
99
|
+
return new OkClass(value);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Wraps a message, category, Error, or sequence of Errors in an immutable Err arm.
|
|
103
|
+
*/
|
|
104
|
+
export function fail(errorOrErrors = undefined, category = ErrorCategory.Validation, cause = null) {
|
|
105
|
+
if (errorOrErrors instanceof Error) {
|
|
106
|
+
return new ErrClass(errorOrErrors);
|
|
107
|
+
}
|
|
108
|
+
if (typeof errorOrErrors === "string") {
|
|
109
|
+
const err = Error.fromMessages(errorOrErrors, errorOrErrors, category, extractCauseType(cause));
|
|
110
|
+
return new ErrClass(err);
|
|
111
|
+
}
|
|
112
|
+
if (errorOrErrors !== null && errorOrErrors !== undefined) {
|
|
113
|
+
const allErrors = Error.atLeastOne(errorOrErrors);
|
|
114
|
+
return new ErrClass(allErrors[0], allErrors);
|
|
115
|
+
}
|
|
116
|
+
return new ErrClass(Error.fromMessage(null, category));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wraps an arbitrary domain error value in an immutable Err arm.
|
|
120
|
+
*/
|
|
121
|
+
export function failError(error) {
|
|
122
|
+
return new ErrClass(error);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Explicit boundary executing a synchronous action and translating thrown exceptions into an Err.
|
|
126
|
+
*/
|
|
127
|
+
export function try_(action, errorHandler = undefined, cancellationToken = null) {
|
|
128
|
+
if (typeof action !== "function") {
|
|
129
|
+
throw new TypeError("action cannot be null or undefined");
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return new OkClass(action());
|
|
133
|
+
}
|
|
134
|
+
catch (exc) {
|
|
135
|
+
if (isAbortOrTimeout(exc, cancellationToken)) {
|
|
136
|
+
return new ErrClass(Error.fromCancellation(exc, cancellationToken));
|
|
137
|
+
}
|
|
138
|
+
if (errorHandler !== null && errorHandler !== undefined) {
|
|
139
|
+
try {
|
|
140
|
+
return new ErrClass(errorHandler(exc));
|
|
141
|
+
}
|
|
142
|
+
catch (handlerExc) {
|
|
143
|
+
const caught = Error.fromCaught(handlerExc, cancellationToken);
|
|
144
|
+
return new ErrClass(caught[0], caught);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const caught = Error.fromCaught(exc, cancellationToken);
|
|
148
|
+
return new ErrClass(caught[0], caught);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Explicit boundary executing an asynchronous action and translating thrown exceptions into an Err.
|
|
153
|
+
*/
|
|
154
|
+
export function tryAsync(action, errorHandler = undefined, cancellationToken = null) {
|
|
155
|
+
return (async () => {
|
|
156
|
+
if (typeof action !== "function") {
|
|
157
|
+
throw new TypeError("action cannot be null or undefined");
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const value = await action();
|
|
161
|
+
return new OkClass(value);
|
|
162
|
+
}
|
|
163
|
+
catch (exc) {
|
|
164
|
+
if (isAbortOrTimeout(exc, cancellationToken)) {
|
|
165
|
+
return new ErrClass(Error.fromCancellation(exc, cancellationToken));
|
|
166
|
+
}
|
|
167
|
+
if (errorHandler !== null && errorHandler !== undefined) {
|
|
168
|
+
try {
|
|
169
|
+
return new ErrClass(errorHandler(exc));
|
|
170
|
+
}
|
|
171
|
+
catch (handlerExc) {
|
|
172
|
+
const caught = Error.fromCaught(handlerExc, cancellationToken);
|
|
173
|
+
return new ErrClass(caught[0], caught);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const caught = Error.fromCaught(exc, cancellationToken);
|
|
177
|
+
return new ErrClass(caught[0], caught);
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
}
|
|
181
|
+
const resultCompanion = Object.freeze({
|
|
182
|
+
ok,
|
|
183
|
+
fail,
|
|
184
|
+
failError,
|
|
185
|
+
success: ok,
|
|
186
|
+
failure: fail,
|
|
187
|
+
try: try_,
|
|
188
|
+
try_,
|
|
189
|
+
tryAsync,
|
|
190
|
+
});
|
|
191
|
+
/**
|
|
192
|
+
* Result companion namespace providing static factories and explicit exception boundary wrappers.
|
|
193
|
+
*/
|
|
194
|
+
export const Result = resultCompanion;
|
|
195
|
+
//# sourceMappingURL=Result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Result.js","sourceRoot":"","sources":["../src/Result.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,oBAAoB;AACpB,UAAU;AACV,SAAS;AACT,aAAa;AACb,mBAAmB;AACnB,gBAAgB;AAChB,iBAAiB;AACjB,oBAAoB;AACpB,oBAAoB;AACpB,8BAA8B;AAC9B,mCAAmC;AACnC,kBAAkB;AAClB,aAAa;AACb,wCAAwC;AACxC,6CAA6C;AAC7C,8BAA8B;AAC9B,mCAAmC;AACnC,yBAAyB;AACzB,oCAAoC;AACpC,yCAAyC;AACzC,wBAAwB;AACxB,mBAAmB;AACnB,gBAAgB;AAChB,2CAA2C;AAC3C,uBAAuB;AACvB,gBAAgB;AAChB,wDAAwD;AACxD,oDAAoD;AAEpD,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,EAAE,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAExC,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,KAAuF,CAAC;QACpG,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC/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AAO,UAAU,EAAE,CAAC;oBACpB,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;oBAC/D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,MAAM,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;YACD,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YACxD,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,EAA+B,CAAC;AACpC,CAAC;AAED,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,EAAE;IACF,IAAI;IACJ,SAAS;IACT,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,IAAI;IACb,GAAG,EAAE,IAAI;IACT,IAAI;IACJ,QAAQ;CACT,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Error } from "./Error.js";
|
|
2
|
+
/**
|
|
3
|
+
* ResultException carries an immutable snapshot of structured errors when a failed Result is
|
|
4
|
+
* explicitly unwrapped or thrown.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResultException {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly stack: string | undefined;
|
|
10
|
+
readonly errors: readonly Error[];
|
|
11
|
+
constructor(errors?: Iterable<Error | null | undefined> | Error | null);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ResultException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultException.d.ts","sourceRoot":"","sources":["../src/ResultException.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,qBAAa,eAAe;IAC1B,SAAgB,IAAI,EAAE,MAAM,CAAqB;IACjD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,SAAgB,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;gBAEtB,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,KAAK,GAAG,IAAI;CAU9E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Responsibility: Carry structured errors from an explicitly thrown or unwrapped failed result.
|
|
2
|
+
// Public interface:
|
|
3
|
+
// `-- ResultException
|
|
4
|
+
// +-- errors
|
|
5
|
+
// +-- message
|
|
6
|
+
// +-- name
|
|
7
|
+
// +-- new(errors)
|
|
8
|
+
// `-- stack
|
|
9
|
+
import { Error } from "./Error.js";
|
|
10
|
+
/**
|
|
11
|
+
* ResultException carries an immutable snapshot of structured errors when a failed Result is
|
|
12
|
+
* explicitly unwrapped or thrown.
|
|
13
|
+
*/
|
|
14
|
+
export class ResultException {
|
|
15
|
+
name = "ResultException";
|
|
16
|
+
message;
|
|
17
|
+
stack;
|
|
18
|
+
errors;
|
|
19
|
+
constructor(errors) {
|
|
20
|
+
const normalized = errors instanceof Error ? Object.freeze([errors]) : Error.atLeastOne(errors);
|
|
21
|
+
this.errors = normalized;
|
|
22
|
+
const messages = normalized.map((e) => e.userMessage);
|
|
23
|
+
this.message = messages.length > 0 ? messages.join("\n") : "Result failure";
|
|
24
|
+
const captured = new globalThis.Error(this.message);
|
|
25
|
+
this.stack = captured.stack;
|
|
26
|
+
Object.setPrototypeOf(this, ResultException.prototype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Object.setPrototypeOf(ResultException.prototype, globalThis.Error.prototype);
|
|
30
|
+
//# sourceMappingURL=ResultException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultException.js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err.js";
|
|
2
|
+
import { Error as ErrorClass } from "./Error.js";
|
|
3
|
+
import { Guard as GuardClass } from "./Guard.js";
|
|
4
|
+
import { Ok as OkClass } from "./Ok.js";
|
|
5
|
+
import { fail as failFn, failError as failErrorFn, ok as okFn, try_ as tryFn, tryAsync as tryAsyncFn } from "./Result.js";
|
|
6
|
+
import { ResultException as ResultExceptionClass } from "./ResultException.js";
|
|
7
|
+
/** Default user message for unexpected errors. */
|
|
8
|
+
export declare const DEFAULT_USER_MESSAGE = "An unexpected error occurred";
|
|
9
|
+
/** Default user message for cancelled operations. */
|
|
10
|
+
export declare const CANCELED_USER_MESSAGE = "The operation was cancelled.";
|
|
11
|
+
/** Default user message for timed-out operations. */
|
|
12
|
+
export declare const TIMED_OUT_USER_MESSAGE = "The operation timed out.";
|
|
13
|
+
/** Failure category constants. */
|
|
14
|
+
export declare const ErrorCategory: {
|
|
15
|
+
readonly Unexpected: "Unexpected";
|
|
16
|
+
readonly Validation: "Validation";
|
|
17
|
+
readonly NotFound: "NotFound";
|
|
18
|
+
readonly Conflict: "Conflict";
|
|
19
|
+
readonly Forbidden: "Forbidden";
|
|
20
|
+
readonly Unavailable: "Unavailable";
|
|
21
|
+
readonly Canceled: "Canceled";
|
|
22
|
+
readonly Indeterminate: "Indeterminate";
|
|
23
|
+
readonly UNEXPECTED: "Unexpected";
|
|
24
|
+
readonly VALIDATION: "Validation";
|
|
25
|
+
readonly NOT_FOUND: "NotFound";
|
|
26
|
+
readonly CONFLICT: "Conflict";
|
|
27
|
+
readonly FORBIDDEN: "Forbidden";
|
|
28
|
+
readonly UNAVAILABLE: "Unavailable";
|
|
29
|
+
readonly CANCELED: "Canceled";
|
|
30
|
+
readonly INDETERMINATE: "Indeterminate";
|
|
31
|
+
};
|
|
32
|
+
/** Immutable failure value object class. */
|
|
33
|
+
export declare const Error: typeof ErrorClass;
|
|
34
|
+
/** Exception thrown when unwrapping a failed Result. */
|
|
35
|
+
export declare const ResultException: typeof ResultExceptionClass;
|
|
36
|
+
/** Successful Result arm class. */
|
|
37
|
+
export declare const Ok: typeof OkClass;
|
|
38
|
+
/** Failed Result arm class. */
|
|
39
|
+
export declare const Err: typeof ErrClass;
|
|
40
|
+
/** Result companion namespace. */
|
|
41
|
+
export declare const Result: Readonly<{
|
|
42
|
+
ok: typeof okFn;
|
|
43
|
+
fail: typeof failFn;
|
|
44
|
+
failError: typeof failErrorFn;
|
|
45
|
+
success: typeof okFn;
|
|
46
|
+
failure: typeof failFn;
|
|
47
|
+
try: typeof tryFn;
|
|
48
|
+
try_: typeof tryFn;
|
|
49
|
+
tryAsync: typeof tryAsyncFn;
|
|
50
|
+
}>;
|
|
51
|
+
/** Railway-oriented precondition guards. */
|
|
52
|
+
export declare const Guard: typeof GuardClass;
|
|
53
|
+
/** Factory wrapping a value in an Ok arm. */
|
|
54
|
+
export declare const ok: typeof okFn;
|
|
55
|
+
/** Factory wrapping an error or message in an Err arm. */
|
|
56
|
+
export declare const fail: typeof failFn;
|
|
57
|
+
/** Factory wrapping a custom domain error in an Err arm. */
|
|
58
|
+
export declare const failError: typeof failErrorFn;
|
|
59
|
+
/** Synchronous explicit exception boundary wrapper. */
|
|
60
|
+
export declare const try_: typeof tryFn;
|
|
61
|
+
/** Asynchronous explicit exception boundary wrapper. */
|
|
62
|
+
export declare const tryAsync: typeof tryAsyncFn;
|
|
63
|
+
/** Package barrel index reference. */
|
|
64
|
+
export declare const index: Readonly<{
|
|
65
|
+
ok: typeof okFn;
|
|
66
|
+
fail: typeof failFn;
|
|
67
|
+
failError: typeof failErrorFn;
|
|
68
|
+
success: typeof okFn;
|
|
69
|
+
failure: typeof failFn;
|
|
70
|
+
try: typeof tryFn;
|
|
71
|
+
try_: typeof tryFn;
|
|
72
|
+
tryAsync: typeof tryAsyncFn;
|
|
73
|
+
}>;
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
75
|
+
export type { ErrorCategory } from './ErrorCategory.js';
|
|
76
|
+
export type { Error } from './Error.js';
|
|
77
|
+
export type { ResultException } from './ResultException.js';
|
|
78
|
+
export type { Ok } from './Ok.js';
|
|
79
|
+
export type { Err } from './Err.js';
|
|
80
|
+
export type { Result } from './Result.js';
|
|
81
|
+
export type { Guard } from './Guard.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAGL,KAAK,IAAI,UAAU,EAEpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,EAAE,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EACL,IAAI,IAAI,MAAM,EACd,SAAS,IAAI,WAAW,EACxB,EAAE,IAAI,IAAI,EAEV,IAAI,IAAI,KAAK,EACb,QAAQ,IAAI,UAAU,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,IAAI,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE/E,kDAAkD;AAClD,eAAO,MAAM,oBAAoB,iCAAiB,CAAC;AAEnD,qDAAqD;AACrD,eAAO,MAAM,qBAAqB,iCAAkB,CAAC;AAErD,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,6BAAkB,CAAC;AAEtD,kCAAkC;AAClC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;CAAoB,CAAC;AAE/C,4CAA4C;AAC5C,eAAO,MAAM,KAAK,mBAAa,CAAC;AAEhC,wDAAwD;AACxD,eAAO,MAAM,eAAe,6BAAuB,CAAC;AAEpD,mCAAmC;AACnC,eAAO,MAAM,EAAE,gBAAU,CAAC;AAE1B,+BAA+B;AAC/B,eAAO,MAAM,GAAG,iBAAW,CAAC;AAE5B,kCAAkC;AAClC,eAAO,MAAM,MAAM;;;;;;;;;EAAkB,CAAC;AAEtC,4CAA4C;AAC5C,eAAO,MAAM,KAAK,mBAAa,CAAC;AAEhC,6CAA6C;AAC7C,eAAO,MAAM,EAAE,aAAO,CAAC;AAEvB,0DAA0D;AAC1D,eAAO,MAAM,IAAI,eAAS,CAAC;AAE3B,4DAA4D;AAC5D,eAAO,MAAM,SAAS,oBAAc,CAAC;AAErC,uDAAuD;AACvD,eAAO,MAAM,IAAI,cAAQ,CAAC;AAE1B,wDAAwD;AACxD,eAAO,MAAM,QAAQ,mBAAa,CAAC;AAEnC,sCAAsC;AACtC,eAAO,MAAM,KAAK;;;;;;;;;EAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Responsibility: Export the public surface of nyssa-ai-result.
|
|
2
|
+
// Public interface:
|
|
3
|
+
// +-- CANCELED_USER_MESSAGE
|
|
4
|
+
// +-- DEFAULT_USER_MESSAGE
|
|
5
|
+
// +-- Err
|
|
6
|
+
// +-- Error
|
|
7
|
+
// +-- ErrorCategory
|
|
8
|
+
// +-- Guard
|
|
9
|
+
// +-- Ok
|
|
10
|
+
// +-- Result
|
|
11
|
+
// +-- ResultException
|
|
12
|
+
// +-- TIMED_OUT_USER_MESSAGE
|
|
13
|
+
// +-- fail
|
|
14
|
+
// +-- failError
|
|
15
|
+
// +-- index
|
|
16
|
+
// +-- ok
|
|
17
|
+
// +-- tryAsync
|
|
18
|
+
// `-- try_
|
|
19
|
+
import { Err as ErrClass } from "./Err.js";
|
|
20
|
+
import { CANCELED_USER_MESSAGE as CanceledUserMsg, DEFAULT_USER_MESSAGE as DefaultUserMsg, Error as ErrorClass, TIMED_OUT_USER_MESSAGE as TimedOutUserMsg, } from "./Error.js";
|
|
21
|
+
import { ErrorCategory as ErrorCategoryEnum } from "./ErrorCategory.js";
|
|
22
|
+
import { Guard as GuardClass } from "./Guard.js";
|
|
23
|
+
import { Ok as OkClass } from "./Ok.js";
|
|
24
|
+
import { fail as failFn, failError as failErrorFn, ok as okFn, Result as ResultCompanion, try_ as tryFn, tryAsync as tryAsyncFn, } from "./Result.js";
|
|
25
|
+
import { ResultException as ResultExceptionClass } from "./ResultException.js";
|
|
26
|
+
/** Default user message for unexpected errors. */
|
|
27
|
+
export const DEFAULT_USER_MESSAGE = DefaultUserMsg;
|
|
28
|
+
/** Default user message for cancelled operations. */
|
|
29
|
+
export const CANCELED_USER_MESSAGE = CanceledUserMsg;
|
|
30
|
+
/** Default user message for timed-out operations. */
|
|
31
|
+
export const TIMED_OUT_USER_MESSAGE = TimedOutUserMsg;
|
|
32
|
+
/** Failure category constants. */
|
|
33
|
+
export const ErrorCategory = ErrorCategoryEnum;
|
|
34
|
+
/** Immutable failure value object class. */
|
|
35
|
+
export const Error = ErrorClass;
|
|
36
|
+
/** Exception thrown when unwrapping a failed Result. */
|
|
37
|
+
export const ResultException = ResultExceptionClass;
|
|
38
|
+
/** Successful Result arm class. */
|
|
39
|
+
export const Ok = OkClass;
|
|
40
|
+
/** Failed Result arm class. */
|
|
41
|
+
export const Err = ErrClass;
|
|
42
|
+
/** Result companion namespace. */
|
|
43
|
+
export const Result = ResultCompanion;
|
|
44
|
+
/** Railway-oriented precondition guards. */
|
|
45
|
+
export const Guard = GuardClass;
|
|
46
|
+
/** Factory wrapping a value in an Ok arm. */
|
|
47
|
+
export const ok = okFn;
|
|
48
|
+
/** Factory wrapping an error or message in an Err arm. */
|
|
49
|
+
export const fail = failFn;
|
|
50
|
+
/** Factory wrapping a custom domain error in an Err arm. */
|
|
51
|
+
export const failError = failErrorFn;
|
|
52
|
+
/** Synchronous explicit exception boundary wrapper. */
|
|
53
|
+
export const try_ = tryFn;
|
|
54
|
+
/** Asynchronous explicit exception boundary wrapper. */
|
|
55
|
+
export const tryAsync = tryAsyncFn;
|
|
56
|
+
/** Package barrel index reference. */
|
|
57
|
+
export const index = ResultCompanion;
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceR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wDAAwD;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAEpD,mCAAmC;AACnC,MAAM,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC;AAE1B,+BAA+B;AAC/B,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC;AAE5B,kCAAkC;AAClC,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC;AAEtC,4CAA4C;AAC5C,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAAC;AAEhC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;AAEvB,0DAA0D;AAC1D,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAE3B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AAErC,uDAAuD;AACvD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC;AAE1B,wDAAwD;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AAEnC,sCAAsC;AACtC,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyssa-ai/result",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Railway-oriented Result discriminated union with pure combinators and explicit exception boundaries matching NyssaAI.Result",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"import": "./dist/*.js",
|
|
15
|
+
"types": "./dist/*.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', { recursive: true, force: true })\"",
|
|
24
|
+
"build": "npm run clean && tsc && node -e \"const fs = require('node:fs'); fs.appendFileSync('./dist/index.d.ts', '\\nexport type { ErrorCategory } from \\'./ErrorCategory.js\\';\\nexport type { Error } from \\'./Error.js\\';\\nexport type { ResultException } from \\'./ResultException.js\\';\\nexport type { Ok } from \\'./Ok.js\\';\\nexport type { Err } from \\'./Err.js\\';\\nexport type { Result } from \\'./Result.js\\';\\nexport type { Guard } from \\'./Guard.js\\';\\n'); fs.appendFileSync('./dist/Result.d.ts', '\\nexport type { Ok } from \\'./Ok.js\\';\\nexport type { Err } from \\'./Err.js\\';\\n');\"",
|
|
25
|
+
"prepack": "npm run build",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:unit": "vitest run test/unit",
|
|
28
|
+
"test:usecase": "vitest run test/use_case",
|
|
29
|
+
"typecheck": "tsc --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/NyssaAI/NyssaAI.Shared.git",
|
|
34
|
+
"directory": "nyssa-ai-result-ts"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"result",
|
|
38
|
+
"railway-oriented-programming",
|
|
39
|
+
"error-handling",
|
|
40
|
+
"discriminated-union",
|
|
41
|
+
"guard"
|
|
42
|
+
],
|
|
43
|
+
"author": "NyssaAI",
|
|
44
|
+
"license": "Apache-2.0",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^24.10.0",
|
|
47
|
+
"typescript": "^5.8.0",
|
|
48
|
+
"vitest": "^3.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|