translate-effect-errors 0.0.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 +23 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +34 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# vite-plus-starter
|
|
2
|
+
|
|
3
|
+
A starter for creating a Vite Plus project.
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
- Install dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
vp install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Run the unit tests:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
vp test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Build the library:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
vp pack
|
|
23
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type TaggedCause = {
|
|
5
|
+
readonly _tag: string;
|
|
6
|
+
};
|
|
7
|
+
type TaggedErrors<E> = Extract<E, TaggedCause>;
|
|
8
|
+
type TaggedByTags<E, Tags extends ReadonlyArray<string>> = Extract<TaggedErrors<E>, {
|
|
9
|
+
readonly _tag: Tags[number];
|
|
10
|
+
}>;
|
|
11
|
+
type TaggedExcept<E, KeepTag extends string> = Exclude<TaggedErrors<E>, {
|
|
12
|
+
readonly _tag: KeepTag;
|
|
13
|
+
}>;
|
|
14
|
+
type DefectError = {
|
|
15
|
+
readonly cause: unknown;
|
|
16
|
+
};
|
|
17
|
+
type DefectErrorFactory<E2 extends DefectError> = {
|
|
18
|
+
readonly from: (cause: unknown) => E2;
|
|
19
|
+
};
|
|
20
|
+
declare function translateTaggedErrors<E, Tags extends ReadonlyArray<TaggedErrors<E>["_tag"]>, E2>(tags: readonly [...Tags], map: (cause: TaggedByTags<E, Tags>) => E2): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Exclude<E, TaggedByTags<E, Tags>> | E2, R>;
|
|
21
|
+
declare function translateTaggedErrorsExcept<E, KeepTag extends TaggedErrors<E>["_tag"], E2>(keepTag: KeepTag, map: (cause: TaggedExcept<E, KeepTag>) => E2): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Exclude<E, TaggedExcept<E, KeepTag>> | E2, R>;
|
|
22
|
+
declare function translateErrorsInto<E2 extends DefectError>(factory: DefectErrorFactory<E2>): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Exclude<E, TaggedErrors<E>> | E2, R>;
|
|
23
|
+
declare function translateErrorsIntoExcept<KeepTag extends string, E2 extends DefectError>(keepTag: KeepTag, factory: DefectErrorFactory<E2>): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Exclude<E, TaggedExcept<E, KeepTag>> | E2, R>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { translateErrorsInto, translateErrorsIntoExcept, translateTaggedErrors, translateTaggedErrorsExcept };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const hasTag = (cause, tags) => {
|
|
4
|
+
if (typeof cause !== "object" || cause === null || !("_tag" in cause)) return false;
|
|
5
|
+
const tag = cause._tag;
|
|
6
|
+
return typeof tag === "string" && tags.has(tag);
|
|
7
|
+
};
|
|
8
|
+
const isTaggedCause = (cause) => {
|
|
9
|
+
if (typeof cause !== "object" || cause === null || !("_tag" in cause)) return false;
|
|
10
|
+
return typeof cause._tag === "string";
|
|
11
|
+
};
|
|
12
|
+
function translateTaggedErrors(tags, map) {
|
|
13
|
+
return (self) => {
|
|
14
|
+
const tagSet = new Set(tags);
|
|
15
|
+
return Effect.catchIf(self, (cause) => hasTag(cause, tagSet), (cause) => Effect.fail(map(cause)));
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function translateTaggedErrorsExcept(keepTag, map) {
|
|
19
|
+
return (self) => {
|
|
20
|
+
return Effect.catchIf(self, (cause) => isTaggedCause(cause) && cause._tag !== keepTag, (cause) => Effect.fail(map(cause)));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function translateErrorsInto(factory) {
|
|
24
|
+
return (self) => {
|
|
25
|
+
return Effect.catchIf(self, (cause) => isTaggedCause(cause), (cause) => Effect.fail(factory.from(cause)));
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function translateErrorsIntoExcept(keepTag, factory) {
|
|
29
|
+
return (self) => {
|
|
30
|
+
return Effect.catchIf(self, (cause) => isTaggedCause(cause) && cause._tag !== keepTag, (cause) => Effect.fail(factory.from(cause)));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { translateErrorsInto, translateErrorsIntoExcept, translateTaggedErrors, translateTaggedErrorsExcept };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "translate-effect-errors",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A starter for creating a TypeScript package.",
|
|
5
|
+
"homepage": "https://github.com/author/library#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/author/library/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Hank Stoever",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/author/library.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.mjs",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vp pack",
|
|
28
|
+
"dev": "vp pack --watch",
|
|
29
|
+
"test": "vp test --typecheck",
|
|
30
|
+
"check": "vp check",
|
|
31
|
+
"prepublishOnly": "vp run build",
|
|
32
|
+
"prepare": "vp config",
|
|
33
|
+
"patch-ts": "effect-language-service patch",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@effect/language-service": "^0.84.3",
|
|
39
|
+
"@effect/platform": "^0.96.0",
|
|
40
|
+
"@types/node": "^25.5.0",
|
|
41
|
+
"@typescript/native-preview": "7.0.0-dev.20260328.1",
|
|
42
|
+
"bumpp": "^11.0.1",
|
|
43
|
+
"effect": "^3.21.0",
|
|
44
|
+
"typescript": "^6.0.2",
|
|
45
|
+
"vite-plus": "^0.1.14",
|
|
46
|
+
"vitest": "catalog:"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"effect": "^3.21.0"
|
|
50
|
+
},
|
|
51
|
+
"packageManager": "pnpm@10.33.0"
|
|
52
|
+
}
|