@adobe/aio-commerce-lib-core 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/CHANGELOG.md +9 -0
- package/README.md +106 -113
- package/dist/cjs/error-DkqwTy7o.cjs +225 -0
- package/dist/cjs/index-Bde1DS_G.d.cts +45 -0
- package/dist/cjs/index.cjs +3 -10
- package/dist/cjs/index.d.cts +2 -3
- package/dist/cjs/lib/error/index.cjs +4 -0
- package/dist/cjs/lib/error/index.d.cts +2 -0
- package/dist/es/error-CPCTGRuV.js +180 -0
- package/dist/es/index-C9-P5X0V.d.ts +43 -0
- package/dist/es/index.d.ts +2 -3
- package/dist/es/index.js +2 -3
- package/dist/es/lib/error/index.d.ts +2 -0
- package/dist/es/lib/error/index.js +3 -0
- package/package.json +12 -6
- package/.turbo/turbo-build.log +0 -36
- package/dist/cjs/chunk-CsX-DzYB.cjs +0 -42
- package/dist/cjs/lib/result.cjs +0 -10
- package/dist/cjs/lib/validation.cjs +0 -4
- package/dist/cjs/result-B_qN_g1r.d.cts +0 -26
- package/dist/cjs/result-fxmTDycS.cjs +0 -160
- package/dist/cjs/validation-12iMy71C.cjs +0 -71
- package/dist/cjs/validation-BonM9W9Z.d.cts +0 -21
- package/dist/es/lib/result.d.ts +0 -2
- package/dist/es/lib/result.js +0 -3
- package/dist/es/lib/validation.d.ts +0 -3
- package/dist/es/lib/validation.js +0 -3
- package/dist/es/result-B394X-_m.js +0 -107
- package/dist/es/result-BooxElIJ.d.ts +0 -26
- package/dist/es/validation-B2JQpDTl.d.ts +0 -21
- package/dist/es/validation-DmGRxtJ7.js +0 -54
- package/dist/lib/result.d.cts +0 -2
- package/dist/lib/validation.d.cts +0 -3
- package/source/index.ts +0 -15
- package/source/lib/result.ts +0 -156
- package/source/lib/validation.ts +0 -97
- package/test/result.test.ts +0 -56
- package/test/validation.test.ts +0 -71
- package/tsconfig.json +0 -15
- package/tsdown.config.ts +0 -11
- package/vitest.config.ts +0 -16
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import util from "node:util";
|
|
3
|
+
import { cyanBright, dim, whiteBright, yellowBright } from "ansis";
|
|
4
|
+
import { getDotPath } from "valibot";
|
|
5
|
+
|
|
6
|
+
//#region source/lib/error/base-error.ts
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all AioCommerceSdk errors.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* class ValidationError extends CommerceSdkErrorBase {
|
|
12
|
+
* constructor(message: string, options: ValidationErrorOptions) {
|
|
13
|
+
* super(message, options);
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* const err = new ValidationError("Invalid value", {
|
|
18
|
+
* tag: "ValidationError",
|
|
19
|
+
* field: "name",
|
|
20
|
+
* value: "John Doe",
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* console.log(err.toJSON());
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
var CommerceSdkErrorBase = class CommerceSdkErrorBase extends Error {
|
|
27
|
+
traceId;
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a new CommerceSdkErrorBase instance.
|
|
30
|
+
*
|
|
31
|
+
* @param message - A human-friendly description of the error.
|
|
32
|
+
* @param traceId - An optional trace ID for tracking the error in logs.
|
|
33
|
+
* @param options - Required error options.
|
|
34
|
+
*/
|
|
35
|
+
constructor(message, { traceId,...options }) {
|
|
36
|
+
super(message, options);
|
|
37
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
38
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
39
|
+
this.name = new.target.name || "CommerceSdkError";
|
|
40
|
+
this.traceId = traceId;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the error is any CommerceSdkErrorBase instance.
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* class ValidationError extends CommerceSdkErrorBase {}
|
|
47
|
+
* const err = new ValidationError("Invalid", {});
|
|
48
|
+
*
|
|
49
|
+
* CommerceSdkErrorBase.isSdkError(err); // true
|
|
50
|
+
* ValidationError.isSdkError(err); // true
|
|
51
|
+
* CommerceSdkErrorBase.isSdkError(new Error("Regular")); // false
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
static isSdkError(error) {
|
|
55
|
+
return error instanceof CommerceSdkErrorBase;
|
|
56
|
+
}
|
|
57
|
+
/** Returns the full stack trace of the error and its causes. */
|
|
58
|
+
get fullStack() {
|
|
59
|
+
let out = this.stack ?? "";
|
|
60
|
+
let cause = this.cause;
|
|
61
|
+
while (cause instanceof Error) {
|
|
62
|
+
out += `\nCaused by: ${cause.stack ?? cause.message}`;
|
|
63
|
+
cause = cause.cause;
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** Returns the root cause of the error. */
|
|
68
|
+
get rootCause() {
|
|
69
|
+
let cause = this.cause;
|
|
70
|
+
while (cause) if (typeof cause === "object" && cause !== null && "cause" in cause) cause = cause.cause;
|
|
71
|
+
else break;
|
|
72
|
+
return cause;
|
|
73
|
+
}
|
|
74
|
+
/** Converts the error to a JSON-like representation. */
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
name: this.name,
|
|
78
|
+
message: this.message,
|
|
79
|
+
stack: this.fullStack,
|
|
80
|
+
cause: this.cause,
|
|
81
|
+
traceId: this.traceId
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Returns a pretty string representation of the error. */
|
|
85
|
+
toString(inspect = true) {
|
|
86
|
+
if (inspect) return util.inspect(this, {
|
|
87
|
+
depth: null,
|
|
88
|
+
colors: true,
|
|
89
|
+
sorted: true,
|
|
90
|
+
maxStringLength: Number.POSITIVE_INFINITY
|
|
91
|
+
});
|
|
92
|
+
return super.toString();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region source/lib/error/validation-error.ts
|
|
98
|
+
const LAST_RETURN_CHAR = "└── ";
|
|
99
|
+
const RETURN_CHAR = "├── ";
|
|
100
|
+
/** Maps issue kinds to their corresponding error titles for display purposes. */
|
|
101
|
+
const ISSUE_KIND_TO_ERROR_TITLE = {
|
|
102
|
+
schema: "Schema validation error",
|
|
103
|
+
transformation: "Transformation error",
|
|
104
|
+
validation: "Input error"
|
|
105
|
+
};
|
|
106
|
+
function getReturnChar(isLastItem, withColor) {
|
|
107
|
+
const char = isLastItem ? LAST_RETURN_CHAR : RETURN_CHAR;
|
|
108
|
+
return withColor ? cyanBright(char) : char;
|
|
109
|
+
}
|
|
110
|
+
function getKindText(kind, withColor) {
|
|
111
|
+
const text = ISSUE_KIND_TO_ERROR_TITLE[kind] ?? "Unknown issue kind";
|
|
112
|
+
return withColor ? yellowBright(text) : text;
|
|
113
|
+
}
|
|
114
|
+
function getPathText(dotPath, withColor) {
|
|
115
|
+
if (!dotPath) return "";
|
|
116
|
+
return withColor ? `${cyanBright(dotPath)}${whiteBright(dim(" →"))}` : `${dotPath} →`;
|
|
117
|
+
}
|
|
118
|
+
function issueToDisplay(issues, withColor = true) {
|
|
119
|
+
const lines = issues?.map((issue, index) => {
|
|
120
|
+
const returnChar = getReturnChar(index === issues.length - 1, withColor);
|
|
121
|
+
const kindText = getKindText(issue.kind, withColor);
|
|
122
|
+
const path = getPathText(getDotPath(issue), withColor);
|
|
123
|
+
const message = withColor ? whiteBright(issue.message) : issue.message;
|
|
124
|
+
const at = withColor ? whiteBright("at") : "at";
|
|
125
|
+
const issueLine = `${kindText} ${at} ${path} ${message}`;
|
|
126
|
+
return `${returnChar} ${issueLine}`;
|
|
127
|
+
});
|
|
128
|
+
return lines?.join("\n") ?? "";
|
|
129
|
+
}
|
|
130
|
+
function displayValidationError(error, withColor = true) {
|
|
131
|
+
const display = issueToDisplay(error.issues, withColor);
|
|
132
|
+
const message = withColor ? whiteBright(error.message) : error.message;
|
|
133
|
+
return `${message}\n${display}`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Represents a validation error in the Commerce SDK.
|
|
137
|
+
* This error is thrown when the input does not conform to the expected schema.
|
|
138
|
+
* It contains a list of issues that describe the validation errors.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const error = new CommerceSdkValidationError("Invalid input", {
|
|
143
|
+
* // `someIssues` is in scope, returned by some `valibot` operation.
|
|
144
|
+
* issues: someIssues
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* console.log(error.display());
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
var CommerceSdkValidationError = class extends CommerceSdkErrorBase {
|
|
151
|
+
issues;
|
|
152
|
+
/**
|
|
153
|
+
* Constructs a new {@link CommerceSdkValidationError} instance.
|
|
154
|
+
*
|
|
155
|
+
* @param message - A human-friendly description of the validation error.
|
|
156
|
+
* @param options - Options for the validation error, including the issues that caused the error.
|
|
157
|
+
*/
|
|
158
|
+
constructor(message, { issues,...options }) {
|
|
159
|
+
super(message, options);
|
|
160
|
+
this.issues = issues;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns a pretty string (and colored) representation of the validation error.
|
|
164
|
+
* @param withColor Whether to use color in the output.
|
|
165
|
+
*/
|
|
166
|
+
display(withColor = true) {
|
|
167
|
+
return displayValidationError(this, withColor);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region source/lib/error/index.ts
|
|
173
|
+
var error_exports = {};
|
|
174
|
+
__export(error_exports, {
|
|
175
|
+
CommerceSdkErrorBase: () => CommerceSdkErrorBase,
|
|
176
|
+
CommerceSdkValidationError: () => CommerceSdkValidationError
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
export { CommerceSdkErrorBase, CommerceSdkValidationError, error_exports };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GenericIssue } from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region source/lib/error/base-error.d.ts
|
|
4
|
+
type CommerceSdkErrorBaseOptions = ErrorOptions & {
|
|
5
|
+
traceId?: string;
|
|
6
|
+
};
|
|
7
|
+
type CommerceSdkErrorOptions<T extends Record<string, unknown> = Record<string, unknown>> = CommerceSdkErrorBaseOptions & T;
|
|
8
|
+
declare abstract class CommerceSdkErrorBase extends Error {
|
|
9
|
+
readonly traceId?: string;
|
|
10
|
+
constructor(message: string, {
|
|
11
|
+
traceId,
|
|
12
|
+
...options
|
|
13
|
+
}: CommerceSdkErrorBaseOptions);
|
|
14
|
+
static isSdkError(error: unknown): error is CommerceSdkErrorBase;
|
|
15
|
+
get fullStack(): string;
|
|
16
|
+
get rootCause(): unknown;
|
|
17
|
+
toJSON(): {
|
|
18
|
+
name: string;
|
|
19
|
+
message: string;
|
|
20
|
+
stack: string;
|
|
21
|
+
cause: unknown;
|
|
22
|
+
traceId: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
toString(inspect?: boolean): string;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region source/lib/error/validation-error.d.ts
|
|
28
|
+
type CommerceSdkValidationErrorOptions = CommerceSdkErrorOptions<{
|
|
29
|
+
issues: GenericIssue[];
|
|
30
|
+
}>;
|
|
31
|
+
declare class CommerceSdkValidationError extends CommerceSdkErrorBase {
|
|
32
|
+
readonly issues: GenericIssue[];
|
|
33
|
+
constructor(message: string, {
|
|
34
|
+
issues,
|
|
35
|
+
...options
|
|
36
|
+
}: CommerceSdkValidationErrorOptions);
|
|
37
|
+
display(withColor?: boolean): string;
|
|
38
|
+
}
|
|
39
|
+
declare namespace index_d_exports {
|
|
40
|
+
export { CommerceSdkErrorBase, CommerceSdkValidationError };
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CommerceSdkErrorBase, CommerceSdkValidationError, index_d_exports };
|
package/dist/es/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export { result_d_exports as Result, validation_d_exports as Validation };
|
|
1
|
+
import { index_d_exports } from "./index-C9-P5X0V.js";
|
|
2
|
+
export { index_d_exports as Error };
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { validation_exports } from "./validation-DmGRxtJ7.js";
|
|
1
|
+
import { error_exports } from "./error-CPCTGRuV.js";
|
|
3
2
|
|
|
4
|
-
export {
|
|
3
|
+
export { error_exports as Error };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-commerce-lib-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Adobe Inc.",
|
|
7
7
|
"engines": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/cjs/index.cjs",
|
|
31
31
|
"module": "./dist/es/index.js",
|
|
32
|
-
"types": "./dist/
|
|
32
|
+
"types": "./dist/cjs/index.d.cts",
|
|
33
33
|
"exports": {
|
|
34
34
|
".": {
|
|
35
35
|
"import": {
|
|
@@ -43,16 +43,22 @@
|
|
|
43
43
|
},
|
|
44
44
|
"./*": {
|
|
45
45
|
"import": {
|
|
46
|
-
"types": "./dist/es/lib
|
|
47
|
-
"default": "./dist/es/lib
|
|
46
|
+
"types": "./dist/es/lib/*/index.d.ts",
|
|
47
|
+
"default": "./dist/es/lib/*/index.js"
|
|
48
48
|
},
|
|
49
49
|
"require": {
|
|
50
|
-
"types": "./dist/cjs/lib
|
|
51
|
-
"default": "./dist/cjs/lib
|
|
50
|
+
"types": "./dist/cjs/lib/*/index.d.cts",
|
|
51
|
+
"default": "./dist/cjs/lib/*/index.cjs"
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"./package.json": "./package.json"
|
|
55
55
|
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"package.json",
|
|
59
|
+
"CHANGELOG.md",
|
|
60
|
+
"README.md"
|
|
61
|
+
],
|
|
56
62
|
"dependencies": {
|
|
57
63
|
"ansis": "^4.1.0",
|
|
58
64
|
"valibot": "^1.1.0"
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @adobe/aio-commerce-lib-core@0.2.0 build /home/runner/work/aio-commerce-sdk/aio-commerce-sdk/packages/aio-commerce-lib-core
|
|
3
|
-
> tsdown
|
|
4
|
-
|
|
5
|
-
[34mℹ[39m tsdown [2mv0.12.9[22m powered by rolldown [2mv1.0.0-beta.24[22m
|
|
6
|
-
[34mℹ[39m Using tsdown config: [4m/home/runner/work/aio-commerce-sdk/aio-commerce-sdk/packages/aio-commerce-lib-core/tsdown.config.ts[24m
|
|
7
|
-
[34mℹ[39m entry: [34msource/index.ts, source/lib/result.ts, source/lib/validation.ts[39m
|
|
8
|
-
[34mℹ[39m target: [34mnode22.0.0[39m
|
|
9
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
|
-
[34mℹ[39m Build start
|
|
11
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22m[1mindex.cjs[22m [2m0.40 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
12
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22m[1mlib/result.cjs[22m [2m0.36 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
13
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22m[1mlib/validation.cjs[22m [2m0.22 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
14
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22mresult-fxmTDycS.cjs [2m3.88 kB[22m [2m│ gzip: 0.97 kB[22m
|
|
15
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22mvalidation-12iMy71C.cjs [2m2.39 kB[22m [2m│ gzip: 0.90 kB[22m
|
|
16
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/cjs/[22mchunk-CsX-DzYB.cjs [2m1.33 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
17
|
-
[34mℹ[39m [33m[CJS][39m 6 files, total: 8.59 kB
|
|
18
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mlib/validation.d.cts[22m[39m [2m0.26 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
19
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mlib/result.d.cts[22m[39m [2m0.23 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
20
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m0.20 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
21
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mresult-B_qN_g1r.d.cts[39m [2m1.39 kB[22m [2m│ gzip: 0.41 kB[22m
|
|
22
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mvalidation-BonM9W9Z.d.cts[39m [2m1.19 kB[22m [2m│ gzip: 0.40 kB[22m
|
|
23
|
-
[34mℹ[39m [33m[CJS][39m 5 files, total: 3.28 kB
|
|
24
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[1mindex.js[22m [2m0.19 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
25
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[1mlib/result.js[22m [2m0.16 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
26
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[1mlib/validation.js[22m [2m0.15 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
27
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22mresult-B394X-_m.js [2m2.95 kB[22m [2m│ gzip: 0.86 kB[22m
|
|
28
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22mvalidation-DmGRxtJ7.js [2m1.92 kB[22m [2m│ gzip: 0.81 kB[22m
|
|
29
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22mchunk-Cl8Af3a2.js [2m0.23 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
30
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[32m[1mlib/validation.d.ts[22m[39m [2m0.26 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
31
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[32m[1mlib/result.d.ts[22m[39m [2m0.23 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
32
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[32m[1mindex.d.ts[22m[39m [2m0.20 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
33
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[32mresult-BooxElIJ.d.ts[39m [2m1.38 kB[22m [2m│ gzip: 0.41 kB[22m
|
|
34
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/es/[22m[32mvalidation-B2JQpDTl.d.ts[39m [2m1.18 kB[22m [2m│ gzip: 0.39 kB[22m
|
|
35
|
-
[34mℹ[39m [34m[ESM][39m 11 files, total: 8.85 kB
|
|
36
|
-
[32m✔[39m Build complete in [32m2032ms[39m
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all) __defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
-
key = keys[i];
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
-
get: ((k) => from[k]).bind(null, key),
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
-
value: mod,
|
|
26
|
-
enumerable: true
|
|
27
|
-
}) : target, mod));
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
|
|
31
|
-
Object.defineProperty(exports, '__export', {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return __export;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, '__toESM', {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return __toESM;
|
|
41
|
-
}
|
|
42
|
-
});
|
package/dist/cjs/lib/result.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const require_result = require('../result-fxmTDycS.cjs');
|
|
2
|
-
|
|
3
|
-
exports.err = require_result.err;
|
|
4
|
-
exports.isErr = require_result.isErr;
|
|
5
|
-
exports.isOk = require_result.isOk;
|
|
6
|
-
exports.map = require_result.map;
|
|
7
|
-
exports.mapErr = require_result.mapErr;
|
|
8
|
-
exports.ok = require_result.ok;
|
|
9
|
-
exports.unwrap = require_result.unwrap;
|
|
10
|
-
exports.unwrapErr = require_result.unwrapErr;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
declare namespace result_d_exports {
|
|
2
|
-
export { Err, ErrorTag, ErrorType, Ok, Result, err, isErr, isOk, map, mapErr, ok, unwrap, unwrapErr };
|
|
3
|
-
}
|
|
4
|
-
type ErrorTag = `${string}Error`;
|
|
5
|
-
type Ok<T> = {
|
|
6
|
-
type: "success";
|
|
7
|
-
value: T;
|
|
8
|
-
};
|
|
9
|
-
type Err<E extends ErrorType<ErrorTag>> = {
|
|
10
|
-
type: "failure";
|
|
11
|
-
error: E;
|
|
12
|
-
};
|
|
13
|
-
type Result<T, E extends ErrorType<ErrorTag>> = Ok<T> | Err<E>;
|
|
14
|
-
type ErrorType<TTag extends ErrorTag = `Error`, TInfo extends Record<string, unknown> = Record<string, unknown>> = TInfo & {
|
|
15
|
-
_tag: TTag;
|
|
16
|
-
};
|
|
17
|
-
declare function ok<T>(value: T): Ok<T>;
|
|
18
|
-
declare function err<E extends ErrorType<ErrorTag>>(error: E): Err<E>;
|
|
19
|
-
declare function unwrap<T, E extends ErrorType<ErrorTag>>(result: Result<T, E>): T;
|
|
20
|
-
declare function unwrapErr<T, E extends ErrorType<ErrorTag>>(result: Result<T, E>): E;
|
|
21
|
-
declare function isOk<T, E extends ErrorType<ErrorTag>>(result: Result<T, E>): result is Ok<T>;
|
|
22
|
-
declare function isErr<T, E extends ErrorType<ErrorTag>>(result: Result<T, E>): result is Err<E>;
|
|
23
|
-
declare function map<T, U, E extends ErrorType<ErrorTag>>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
|
|
24
|
-
declare function mapErr<T, E extends ErrorType<ErrorTag>, F extends ErrorType<ErrorTag>>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { Err, ErrorTag, ErrorType, Ok, Result, __export, err, isErr, isOk, map, mapErr, ok, result_d_exports, unwrap, unwrapErr };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
|
|
3
|
-
//#region source/lib/result.ts
|
|
4
|
-
var result_exports = {};
|
|
5
|
-
require_chunk.__export(result_exports, {
|
|
6
|
-
err: () => err,
|
|
7
|
-
isErr: () => isErr,
|
|
8
|
-
isOk: () => isOk,
|
|
9
|
-
map: () => map,
|
|
10
|
-
mapErr: () => mapErr,
|
|
11
|
-
ok: () => ok,
|
|
12
|
-
unwrap: () => unwrap,
|
|
13
|
-
unwrapErr: () => unwrapErr
|
|
14
|
-
});
|
|
15
|
-
const SuccessOrFailure = {
|
|
16
|
-
SUCCESS: "success",
|
|
17
|
-
FAILURE: "failure"
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Wraps the given value in a successful result.
|
|
21
|
-
* @param value The value to wrap.
|
|
22
|
-
* @returns A successful result containing the given value.
|
|
23
|
-
*/
|
|
24
|
-
function ok(value) {
|
|
25
|
-
return {
|
|
26
|
-
type: SuccessOrFailure.SUCCESS,
|
|
27
|
-
value
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Wraps the given error in a failed result.
|
|
32
|
-
* @param error The error to wrap.
|
|
33
|
-
* @returns A failed result containing the given error.
|
|
34
|
-
*/
|
|
35
|
-
function err(error) {
|
|
36
|
-
return {
|
|
37
|
-
type: SuccessOrFailure.FAILURE,
|
|
38
|
-
error
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Unwraps a result to retrieve its value.
|
|
43
|
-
* If the result is a failure, an error will be thrown.
|
|
44
|
-
*
|
|
45
|
-
* @param result The result to unwrap.
|
|
46
|
-
* @returns The value contained in the successful result.
|
|
47
|
-
* @throws An error if the result is a failure.
|
|
48
|
-
*/
|
|
49
|
-
function unwrap(result) {
|
|
50
|
-
if (result.type === SuccessOrFailure.SUCCESS) return result.value;
|
|
51
|
-
throw new Error("Can't unwrap the value from this result because it's a failure");
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Unwraps a result to retrieve its error.
|
|
55
|
-
* If the result is a success, an error will be thrown.
|
|
56
|
-
*
|
|
57
|
-
* @param result The result to unwrap.
|
|
58
|
-
* @returns The error contained in the failed result.
|
|
59
|
-
* @throws An error if the result is a success.
|
|
60
|
-
*/
|
|
61
|
-
function unwrapErr(result) {
|
|
62
|
-
if (result.type === SuccessOrFailure.FAILURE) return result.error;
|
|
63
|
-
throw new Error("Can't unwrap the error from this result because it's a success");
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Checks if a result is a success.
|
|
67
|
-
* @param result The result to check.
|
|
68
|
-
* @returns True if the result is a success, false otherwise.
|
|
69
|
-
*/
|
|
70
|
-
function isOk(result) {
|
|
71
|
-
return result.type === SuccessOrFailure.SUCCESS;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Checks if a result is a failure.
|
|
75
|
-
* @param result The result to check.
|
|
76
|
-
* @returns True if the result is a failure, false otherwise.
|
|
77
|
-
*/
|
|
78
|
-
function isErr(result) {
|
|
79
|
-
return result.type === SuccessOrFailure.FAILURE;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Maps a successful result to another value.
|
|
83
|
-
* If the result is a failure, it is returned unchanged.
|
|
84
|
-
*
|
|
85
|
-
* @param result The result to map.
|
|
86
|
-
* @param fn A function to transform the success value.
|
|
87
|
-
* @returns A new {@link Result} with the transformed value or the original error.
|
|
88
|
-
*/
|
|
89
|
-
function map(result, fn) {
|
|
90
|
-
if (isOk(result)) return ok(fn(result.value));
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Maps a failed result's error to another error value.
|
|
95
|
-
* If the result is a success, it is returned unchanged.
|
|
96
|
-
*
|
|
97
|
-
* @param result The result to map.
|
|
98
|
-
* @param fn A function to transform the error value.
|
|
99
|
-
* @returns A new Result with the original value or transformed error.
|
|
100
|
-
*/
|
|
101
|
-
function mapErr(result, fn) {
|
|
102
|
-
if (isErr(result)) return err(fn(result.error));
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
Object.defineProperty(exports, 'err', {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () {
|
|
110
|
-
return err;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(exports, 'isErr', {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
get: function () {
|
|
116
|
-
return isErr;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(exports, 'isOk', {
|
|
120
|
-
enumerable: true,
|
|
121
|
-
get: function () {
|
|
122
|
-
return isOk;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
Object.defineProperty(exports, 'map', {
|
|
126
|
-
enumerable: true,
|
|
127
|
-
get: function () {
|
|
128
|
-
return map;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
Object.defineProperty(exports, 'mapErr', {
|
|
132
|
-
enumerable: true,
|
|
133
|
-
get: function () {
|
|
134
|
-
return mapErr;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
Object.defineProperty(exports, 'ok', {
|
|
138
|
-
enumerable: true,
|
|
139
|
-
get: function () {
|
|
140
|
-
return ok;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
Object.defineProperty(exports, 'result_exports', {
|
|
144
|
-
enumerable: true,
|
|
145
|
-
get: function () {
|
|
146
|
-
return result_exports;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
Object.defineProperty(exports, 'unwrap', {
|
|
150
|
-
enumerable: true,
|
|
151
|
-
get: function () {
|
|
152
|
-
return unwrap;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
Object.defineProperty(exports, 'unwrapErr', {
|
|
156
|
-
enumerable: true,
|
|
157
|
-
get: function () {
|
|
158
|
-
return unwrapErr;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const ansis = require_chunk.__toESM(require("ansis"));
|
|
3
|
-
const valibot = require_chunk.__toESM(require("valibot"));
|
|
4
|
-
|
|
5
|
-
//#region source/lib/validation.ts
|
|
6
|
-
var validation_exports = {};
|
|
7
|
-
require_chunk.__export(validation_exports, {
|
|
8
|
-
makeValidationError: () => makeValidationError,
|
|
9
|
-
summarizeValidationError: () => summarizeValidationError
|
|
10
|
-
});
|
|
11
|
-
const LAST_RETURN_CHAR = "└── ";
|
|
12
|
-
const RETURN_CHAR = "├── ";
|
|
13
|
-
const ISSUE_KIND_TO_ERROR_TITLE = {
|
|
14
|
-
schema: "Schema validation error",
|
|
15
|
-
validation: "Input error",
|
|
16
|
-
transformation: "Transformation error"
|
|
17
|
-
};
|
|
18
|
-
function issueToDisplay(issues) {
|
|
19
|
-
const lines = issues.map((issue, index) => {
|
|
20
|
-
const returnChar = (0, ansis.cyanBright)(index === issues.length - 1 ? LAST_RETURN_CHAR : RETURN_CHAR);
|
|
21
|
-
const kindText = (0, ansis.yellowBright)(ISSUE_KIND_TO_ERROR_TITLE[issue.kind] || "Unknown issue kind");
|
|
22
|
-
const dotPath = (0, valibot.getDotPath)(issue);
|
|
23
|
-
const path = dotPath ? (0, ansis.cyanBright)(dotPath) + (0, ansis.whiteBright)((0, ansis.dim)(" →")) : "";
|
|
24
|
-
const issueLine = `${kindText} ${(0, ansis.whiteBright)("at")} ${path} ${(0, ansis.whiteBright)(issue.message)}`;
|
|
25
|
-
return `${returnChar} ${issueLine}`;
|
|
26
|
-
});
|
|
27
|
-
return lines.join("\n");
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Summarizes a validation error by displaying the error message and the issues.
|
|
31
|
-
* @param error The validation error to summarize.
|
|
32
|
-
* @returns A pretty-printed string containing the summary of the validation error.
|
|
33
|
-
*/
|
|
34
|
-
function summarizeValidationError(error) {
|
|
35
|
-
return `${(0, ansis.whiteBright)(error.message)}\n${issueToDisplay(error.issues)}`;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Creates a validation error.
|
|
39
|
-
* @param message The validation error message.
|
|
40
|
-
* @param issues The issues that occurred during validation.
|
|
41
|
-
* @param info Additional information about the error.
|
|
42
|
-
* @returns A validation error.
|
|
43
|
-
*/
|
|
44
|
-
function makeValidationError(message, issues, info = {}) {
|
|
45
|
-
return {
|
|
46
|
-
_tag: "ValidationError",
|
|
47
|
-
message,
|
|
48
|
-
issues,
|
|
49
|
-
...info
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
Object.defineProperty(exports, 'makeValidationError', {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return makeValidationError;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, 'summarizeValidationError', {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return summarizeValidationError;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, 'validation_exports', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return validation_exports;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ErrorType, __export } from "./result-B_qN_g1r.cjs";
|
|
2
|
-
import { GenericIssue } from "valibot";
|
|
3
|
-
|
|
4
|
-
//#region source/lib/validation.d.ts
|
|
5
|
-
declare namespace validation_d_exports {
|
|
6
|
-
export { ValidationError, ValidationErrorType, makeValidationError, summarizeValidationError };
|
|
7
|
-
}
|
|
8
|
-
type ValidationErrorTag = `${string}ValidationError`;
|
|
9
|
-
declare function summarizeValidationError(error: ValidationError): string;
|
|
10
|
-
declare function makeValidationError<TIssues extends GenericIssue[] = GenericIssue[], TInfo extends Record<string, unknown> = Record<string, unknown>>(message: string, issues: TIssues, info?: TInfo): {
|
|
11
|
-
_tag: "ValidationError";
|
|
12
|
-
message: string;
|
|
13
|
-
issues: TIssues;
|
|
14
|
-
} & TInfo;
|
|
15
|
-
type ValidationErrorType<TErrorTag extends ValidationErrorTag = "ValidationError", TIssues extends GenericIssue[] = GenericIssue[], TInfo extends Record<string, unknown> = Record<string, unknown>> = ErrorType<TErrorTag, TInfo & {
|
|
16
|
-
message: string;
|
|
17
|
-
issues: TIssues;
|
|
18
|
-
}>;
|
|
19
|
-
type ValidationError = ValidationErrorType<ValidationErrorTag, GenericIssue[], Record<string, unknown>>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { ValidationError, ValidationErrorType, makeValidationError, summarizeValidationError, validation_d_exports };
|
package/dist/es/lib/result.d.ts
DELETED
package/dist/es/lib/result.js
DELETED