@adobe/aio-commerce-lib-core 0.2.0 → 0.4.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 +15 -0
- package/README.md +2 -136
- package/dist/cjs/error/index.cjs +98 -0
- package/dist/cjs/error/index.d.cts +133 -0
- package/dist/cjs/index.cjs +13 -15
- package/dist/cjs/index.d.cts +1 -3
- package/dist/es/error/index.d.ts +133 -0
- package/dist/es/error/index.js +90 -0
- package/dist/es/index.d.ts +1 -3
- package/dist/es/index.js +13 -4
- package/package.json +30 -28
- 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/chunk-Cl8Af3a2.js +0 -11
- 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
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-commerce-lib-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.0",
|
|
5
|
-
"private": false,
|
|
6
4
|
"author": "Adobe Inc.",
|
|
5
|
+
"version": "0.4.0",
|
|
6
|
+
"private": false,
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=20 <=24"
|
|
9
9
|
},
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"description": "Core utilities for AIO Commerce SDK Libraries",
|
|
@@ -24,54 +24,56 @@
|
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/adobe/aio-commerce-sdk.git",
|
|
27
|
+
"url": "git+https://github.com/adobe/aio-commerce-sdk.git",
|
|
28
28
|
"directory": "packages/aio-commerce-lib-core"
|
|
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
|
-
".": {
|
|
35
|
-
"import": {
|
|
36
|
-
"types": "./dist/es/index.d.ts",
|
|
37
|
-
"default": "./dist/es/index.js"
|
|
38
|
-
},
|
|
39
|
-
"require": {
|
|
40
|
-
"types": "./dist/cjs/index.d.cts",
|
|
41
|
-
"default": "./dist/cjs/index.cjs"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
34
|
"./*": {
|
|
45
35
|
"import": {
|
|
46
|
-
"types": "./dist/es
|
|
47
|
-
"default": "./dist/es
|
|
36
|
+
"types": "./dist/es/*/index.d.ts",
|
|
37
|
+
"default": "./dist/es/*/index.js"
|
|
48
38
|
},
|
|
49
39
|
"require": {
|
|
50
|
-
"types": "./dist/cjs/lib
|
|
51
|
-
"default": "./dist/cjs/lib
|
|
40
|
+
"types": "./dist/cjs/lib/*/index.d.cts",
|
|
41
|
+
"default": "./dist/cjs/lib/*/index.cjs"
|
|
52
42
|
}
|
|
53
43
|
},
|
|
54
44
|
"./package.json": "./package.json"
|
|
55
45
|
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"package.json",
|
|
49
|
+
"CHANGELOG.md",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
56
52
|
"dependencies": {
|
|
57
53
|
"ansis": "^4.1.0",
|
|
58
54
|
"valibot": "^1.1.0"
|
|
59
55
|
},
|
|
60
56
|
"devDependencies": {
|
|
61
|
-
"vitest": "^2.0.0",
|
|
62
57
|
"@aio-commerce-sdk/config-tsdown": "1.0.0",
|
|
63
|
-
"@aio-commerce-sdk/config-
|
|
58
|
+
"@aio-commerce-sdk/config-typedoc": "1.0.0",
|
|
59
|
+
"@aio-commerce-sdk/config-typescript": "1.0.0",
|
|
60
|
+
"@aio-commerce-sdk/config-vitest": "1.0.0"
|
|
64
61
|
},
|
|
65
62
|
"sideEffects": false,
|
|
66
63
|
"scripts": {
|
|
67
64
|
"build": "tsdown",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
65
|
+
"docs": "typedoc && prettier --write '**/*.md'",
|
|
66
|
+
"assist": "biome check --formatter-enabled=false --linter-enabled=false --assist-enabled=true --no-errors-on-unmatched",
|
|
67
|
+
"assist:apply": "biome check --write --formatter-enabled=false --linter-enabled=false --assist-enabled=true --no-errors-on-unmatched",
|
|
68
|
+
"check:ci": "biome ci --formatter-enabled=true --linter-enabled=true --assist-enabled=true --no-errors-on-unmatched",
|
|
69
|
+
"format": "biome format --write --no-errors-on-unmatched",
|
|
70
|
+
"format:markdown": "prettier --no-error-on-unmatched-pattern --write '**/*.md' \"!**/{CODE_OF_CONDUCT.md,COPYRIGHT,LICENSE,SECURITY.md,CONTRIBUTING.md}\"",
|
|
71
|
+
"format:check": "biome format --no-errors-on-unmatched",
|
|
72
|
+
"lint": "biome lint --no-errors-on-unmatched",
|
|
73
|
+
"lint:fix": "biome lint --write --no-errors-on-unmatched",
|
|
73
74
|
"typecheck": "tsc --noEmit && echo '✅ No type errors found.'",
|
|
74
|
-
"test": "vitest run",
|
|
75
|
-
"test:watch": "vitest --
|
|
75
|
+
"test": "vitest run --coverage",
|
|
76
|
+
"test:watch": "vitest --coverage",
|
|
77
|
+
"test:ui": "vitest --ui"
|
|
76
78
|
}
|
|
77
79
|
}
|
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
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
-
|
|
3
|
-
//#region source/lib/result.ts
|
|
4
|
-
var result_exports = {};
|
|
5
|
-
__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
|
-
export { err, isErr, isOk, map, mapErr, ok, result_exports, unwrap, 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, err, isErr, isOk, map, mapErr, ok, result_d_exports, unwrap, unwrapErr };
|