@zerospin/error 2.0.2 → 2.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/.tsbuildinfo/build.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +13 -0
- package/.turbo/turbo-test.log +14 -0
- package/README.md +3 -3
- package/dist/index.d.ts +46 -0
- package/dist/index.js +55 -2
- package/package.json +23 -19
- package/src/ZerospinError.ts +44 -40
- package/src/ZerospinErrorJsonSchema.ts +1 -1
- package/src/index.ts +0 -1
- package/tsconfig.json +1 -0
- package/tsup.config.ts +13 -0
- package/dist/ZerospinError.js +0 -44
- package/dist/ZerospinErrorJsonSchema.js +0 -7
- package/dist/types.js +0 -1
- package/src/types.ts +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/zerospinerror.ts","../src/zerospinerrorjsonschema.ts","../src/index.ts","../src/types.ts"],"version":"5.9.
|
|
1
|
+
{"root":["../src/zerospinerror.ts","../src/zerospinerrorjsonschema.ts","../src/index.ts","../src/types.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
> @zerospin/error@2.0.2 build /Users/morgs32/GitHub/zerospin/packages/error
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Using tsup config: /Users/morgs32/GitHub/zerospin/packages/error/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Target: es2022
|
|
10
|
+
[34mCLI[39m Cleaning output folder
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m1.30 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 7ms
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> @zerospin/error@2.0.2 test /Users/morgs32/GitHub/zerospin/packages/error
|
|
3
|
+
> vitest packages/profiler/src/toMatchProcedure
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/Users/morgs32/GitHub/zerospin/packages/error[39m
|
|
7
|
+
|
|
8
|
+
[31mNo test files found, exiting with code 1
|
|
9
|
+
[39m
|
|
10
|
+
[2mfilter: [22m[33mpackages/profiler/src/toMatchProcedure[39m
|
|
11
|
+
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
12
|
+
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
13
|
+
|
|
14
|
+
ELIFECYCLE Test failed. See above for more details.
|
package/README.md
CHANGED
|
@@ -416,7 +416,7 @@ Serialize errors for transmission over networks or storage:
|
|
|
416
416
|
const error = new ZerospinError({
|
|
417
417
|
code: 'my-error',
|
|
418
418
|
message: 'Something went wrong',
|
|
419
|
-
extra: {
|
|
419
|
+
extra: { actorId: '123' },
|
|
420
420
|
status: 400,
|
|
421
421
|
})
|
|
422
422
|
|
|
@@ -442,9 +442,9 @@ const jsonWithoutExtra = error.serialize(['extra'])
|
|
|
442
442
|
|
|
443
443
|
3. **Use typed extra data**: Leverage TypeScript generics for type-safe metadata:
|
|
444
444
|
```typescript
|
|
445
|
-
|
|
445
|
+
new ZerospinError<ErrorCode, { actorId: string; action: string }>({
|
|
446
446
|
code: 'permission-denied',
|
|
447
|
-
|
|
447
|
+
extra: { actorId: '123', action: 'delete' },
|
|
448
448
|
})
|
|
449
449
|
```
|
|
450
450
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as effect_Cause from 'effect/Cause';
|
|
2
|
+
import * as effect_Types from 'effect/Types';
|
|
3
|
+
import { RequiredKeysOf } from 'type-fest';
|
|
4
|
+
import { Brand, Schema } from 'effect';
|
|
5
|
+
|
|
6
|
+
type IAnyErrorJson<ERROR extends IAnyError = IAnyError> = Brand.Brand<'ZerospinErrorJson'> & {
|
|
7
|
+
code: ERROR['code'];
|
|
8
|
+
extra: ERROR['extra'];
|
|
9
|
+
message: string;
|
|
10
|
+
status: null | number;
|
|
11
|
+
};
|
|
12
|
+
type IAnyError = ZerospinError<string>;
|
|
13
|
+
interface IProps<T extends string = string, E = unknown> {
|
|
14
|
+
code: T;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
extra?: E;
|
|
17
|
+
message?: string;
|
|
18
|
+
status?: null | number;
|
|
19
|
+
}
|
|
20
|
+
interface IError<T extends string = string, E = unknown> {
|
|
21
|
+
code: T;
|
|
22
|
+
status: null | number;
|
|
23
|
+
cause?: unknown;
|
|
24
|
+
extra?: E;
|
|
25
|
+
message?: string;
|
|
26
|
+
}
|
|
27
|
+
declare const ZerospinError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
28
|
+
readonly _tag: "ZerospinError";
|
|
29
|
+
} & Readonly<A>;
|
|
30
|
+
declare class ZerospinError<T extends string = never, E = unknown> extends ZerospinError_base<IError<T, E>> {
|
|
31
|
+
message: string;
|
|
32
|
+
constructor(props: IProps<T, E> | T);
|
|
33
|
+
static isZerospinError(data: unknown): data is ZerospinError;
|
|
34
|
+
static makeZerospinErrorJson(props: {
|
|
35
|
+
cause: unknown;
|
|
36
|
+
code: string;
|
|
37
|
+
extra: unknown;
|
|
38
|
+
message: string;
|
|
39
|
+
status: null | number;
|
|
40
|
+
}): IAnyErrorJson;
|
|
41
|
+
serialize(omit?: Exclude<keyof IAnyErrorJson, RequiredKeysOf<IAnyErrorJson>>[]): IAnyErrorJson;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare const ZerospinErrorJsonSchema: Schema.Schema<IAnyErrorJson, any>;
|
|
45
|
+
|
|
46
|
+
export { type IAnyError, type IAnyErrorJson, type IError, ZerospinError, ZerospinErrorJsonSchema };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/ZerospinError.ts
|
|
2
|
+
import { Brand, Data } from "effect";
|
|
3
|
+
import { isObject } from "effect/Predicate";
|
|
4
|
+
var ZerospinError = class _ZerospinError extends Data.TaggedError("ZerospinError") {
|
|
5
|
+
message;
|
|
6
|
+
constructor(props) {
|
|
7
|
+
if (typeof props === "string") {
|
|
8
|
+
super({
|
|
9
|
+
code: props,
|
|
10
|
+
extra: null,
|
|
11
|
+
message: props,
|
|
12
|
+
status: null
|
|
13
|
+
});
|
|
14
|
+
this.message = props;
|
|
15
|
+
} else {
|
|
16
|
+
super({
|
|
17
|
+
status: null,
|
|
18
|
+
...props
|
|
19
|
+
});
|
|
20
|
+
this.message = props.message ?? props.code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static isZerospinError(data) {
|
|
24
|
+
return isObject(data) && "_tag" in data && data._tag === "ZerospinError";
|
|
25
|
+
}
|
|
26
|
+
static makeZerospinErrorJson(props) {
|
|
27
|
+
return Brand.nominal()(props);
|
|
28
|
+
}
|
|
29
|
+
serialize(omit = []) {
|
|
30
|
+
const json = _ZerospinError.makeZerospinErrorJson({
|
|
31
|
+
cause: this.cause,
|
|
32
|
+
code: this.code,
|
|
33
|
+
extra: this.extra,
|
|
34
|
+
message: this.message,
|
|
35
|
+
status: this.status
|
|
36
|
+
});
|
|
37
|
+
for (const key of omit) {
|
|
38
|
+
delete json[key];
|
|
39
|
+
}
|
|
40
|
+
return json;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/ZerospinErrorJsonSchema.ts
|
|
45
|
+
import { Schema } from "effect";
|
|
46
|
+
var ZerospinErrorJsonSchema = Schema.Struct({
|
|
47
|
+
code: Schema.String,
|
|
48
|
+
extra: Schema.Unknown,
|
|
49
|
+
message: Schema.String,
|
|
50
|
+
status: Schema.Union(Schema.Null, Schema.Number)
|
|
51
|
+
});
|
|
52
|
+
export {
|
|
53
|
+
ZerospinError,
|
|
54
|
+
ZerospinErrorJsonSchema
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerospin/error",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
|
-
"types": "./
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js",
|
|
10
11
|
"require": "./dist/index.js"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
+
"drizzle-orm": "^0.45.1",
|
|
16
|
+
"type-fest": "^5.4.1"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
17
|
-
"@effect/language-service": "^0.
|
|
18
|
-
"@effect/vitest": "^0.
|
|
19
|
-
"@
|
|
20
|
-
"@vitest/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
19
|
+
"@effect/language-service": "^0.68.0",
|
|
20
|
+
"@effect/vitest": "^0.27.0",
|
|
21
|
+
"@types/node": "^22.13.2",
|
|
22
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
23
|
+
"@vitest/pretty-format": "^4.0.17",
|
|
24
|
+
"effect": "^3.19.14",
|
|
25
|
+
"eslint": "^9.39.2",
|
|
26
|
+
"glob": "^13.0.0",
|
|
27
|
+
"jsdom": "^27.4.0",
|
|
28
|
+
"knip": "^5.81.0",
|
|
29
|
+
"tsafe": "^1.8.12",
|
|
30
|
+
"tsup": "^8.5.1",
|
|
31
|
+
"tsx": "^4.21.0",
|
|
32
|
+
"vite-tsconfig-paths": "^6.0.4",
|
|
33
|
+
"vitest": "^4.0.17",
|
|
30
34
|
"@zerospin/utils": "2.0.1"
|
|
31
35
|
},
|
|
32
36
|
"peerDependencies": {
|
|
33
|
-
"effect": "^3.
|
|
37
|
+
"effect": "^3.17.11"
|
|
34
38
|
},
|
|
35
39
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"watch": "
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"watch": "tsup --watch",
|
|
38
42
|
"typecheck": "tsc --noEmit",
|
|
39
43
|
"test": "vitest",
|
|
40
44
|
"lint": "eslint .",
|
package/src/ZerospinError.ts
CHANGED
|
@@ -1,83 +1,87 @@
|
|
|
1
|
-
import type { RequiredKeysOf } from 'type-fest'
|
|
1
|
+
import type { RequiredKeysOf } from 'type-fest';
|
|
2
2
|
|
|
3
|
-
import { Brand, Data } from 'effect'
|
|
4
|
-
import { isObject } from 'effect/Predicate'
|
|
3
|
+
import { Brand, Data } from 'effect';
|
|
4
|
+
import { isObject } from 'effect/Predicate';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export type IAnyErrorJson<ERROR extends IAnyError = IAnyError> =
|
|
7
|
+
Brand.Brand<'ZerospinErrorJson'> & {
|
|
8
|
+
code: ERROR['code'];
|
|
9
|
+
extra: ERROR['extra'];
|
|
10
|
+
message: string;
|
|
11
|
+
status: null | number;
|
|
12
|
+
};
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
export type IAnyError = ZerospinError<string>;
|
|
15
|
+
|
|
16
|
+
interface IProps<T extends string = string, > {
|
|
17
|
+
code: T;
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
extra?: Record<string, unknown>;
|
|
20
|
+
message?: string;
|
|
21
|
+
status?: null | number;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
export interface IError<T extends string = string,
|
|
17
|
-
code: T
|
|
18
|
-
status: null | number
|
|
19
|
-
cause?: unknown
|
|
20
|
-
extra?:
|
|
21
|
-
message?: string
|
|
24
|
+
export interface IError<T extends string = string, > {
|
|
25
|
+
code: T;
|
|
26
|
+
status: null | number;
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
extra?: null | Record<string, unknown>;
|
|
29
|
+
message?: string;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export class ZerospinError<
|
|
25
33
|
T extends string = never,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
public override message!: string
|
|
34
|
+
> extends Data.TaggedError('ZerospinError')<IError<T>> {
|
|
35
|
+
public override message!: string;
|
|
29
36
|
|
|
30
|
-
constructor(props: IProps<T
|
|
37
|
+
constructor(props: IProps<T> | T) {
|
|
31
38
|
if (typeof props === 'string') {
|
|
32
39
|
super({
|
|
33
40
|
code: props,
|
|
34
|
-
extra: null
|
|
41
|
+
extra: null,
|
|
35
42
|
message: props,
|
|
36
43
|
status: null,
|
|
37
|
-
})
|
|
38
|
-
this.message = props
|
|
44
|
+
});
|
|
45
|
+
this.message = props;
|
|
39
46
|
} else {
|
|
40
47
|
super({
|
|
41
48
|
status: null,
|
|
42
49
|
...props,
|
|
43
|
-
})
|
|
44
|
-
this.message = props.message ?? props.code
|
|
50
|
+
});
|
|
51
|
+
this.message = props.message ?? props.code;
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
static isZerospinError(data: unknown): data is ZerospinError {
|
|
49
|
-
return isObject(data) && '_tag' in data && data._tag === 'ZerospinError'
|
|
56
|
+
return isObject(data) && '_tag' in data && data._tag === 'ZerospinError';
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
static makeZerospinErrorJson(props: {
|
|
53
|
-
cause: unknown
|
|
54
|
-
code: string
|
|
55
|
-
extra: unknown
|
|
56
|
-
message: string
|
|
57
|
-
status: null | number
|
|
60
|
+
cause: unknown;
|
|
61
|
+
code: string;
|
|
62
|
+
extra: null | Record<string, unknown>;
|
|
63
|
+
message: string;
|
|
64
|
+
status: null | number;
|
|
58
65
|
}): IAnyErrorJson {
|
|
59
|
-
return Brand.nominal<IAnyErrorJson>()(props)
|
|
66
|
+
return Brand.nominal<IAnyErrorJson>()(props);
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
serialize(
|
|
63
70
|
// You can omit anything BUT id, code
|
|
64
|
-
omit: Exclude<
|
|
65
|
-
keyof IAnyErrorJson,
|
|
66
|
-
RequiredKeysOf<IAnyErrorJson>
|
|
67
|
-
>[] = []
|
|
71
|
+
omit: Exclude<keyof IAnyErrorJson, RequiredKeysOf<IAnyErrorJson>>[] = []
|
|
68
72
|
): IAnyErrorJson {
|
|
69
73
|
const json = ZerospinError.makeZerospinErrorJson({
|
|
70
74
|
cause: this.cause,
|
|
71
75
|
code: this.code,
|
|
72
|
-
extra: this.extra,
|
|
76
|
+
extra: this.extra ?? null,
|
|
73
77
|
message: this.message,
|
|
74
78
|
status: this.status,
|
|
75
|
-
})
|
|
79
|
+
});
|
|
76
80
|
|
|
77
81
|
for (const key of omit) {
|
|
78
|
-
delete json[key]
|
|
82
|
+
delete json[key];
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
return json
|
|
85
|
+
return json;
|
|
82
86
|
}
|
|
83
87
|
}
|
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
clean: true,
|
|
5
|
+
dts: true, // Declarations via tsup; typecheck script still separate
|
|
6
|
+
entry: ['src/index.ts'],
|
|
7
|
+
format: ['esm'],
|
|
8
|
+
minify: process.env.NODE_ENV === 'production',
|
|
9
|
+
outDir: 'dist',
|
|
10
|
+
sourcemap: false,
|
|
11
|
+
splitting: false,
|
|
12
|
+
});
|
|
13
|
+
|
package/dist/ZerospinError.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Brand, Data } from 'effect';
|
|
2
|
-
import { isObject } from 'effect/Predicate';
|
|
3
|
-
export class ZerospinError extends Data.TaggedError('ZerospinError') {
|
|
4
|
-
message;
|
|
5
|
-
constructor(props) {
|
|
6
|
-
if (typeof props === 'string') {
|
|
7
|
-
super({
|
|
8
|
-
code: props,
|
|
9
|
-
extra: null,
|
|
10
|
-
message: props,
|
|
11
|
-
status: null,
|
|
12
|
-
});
|
|
13
|
-
this.message = props;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
super({
|
|
17
|
-
status: null,
|
|
18
|
-
...props,
|
|
19
|
-
});
|
|
20
|
-
this.message = props.message ?? props.code;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
static isZerospinError(data) {
|
|
24
|
-
return isObject(data) && '_tag' in data && data._tag === 'ZerospinError';
|
|
25
|
-
}
|
|
26
|
-
static makeZerospinErrorJson(props) {
|
|
27
|
-
return Brand.nominal()(props);
|
|
28
|
-
}
|
|
29
|
-
serialize(
|
|
30
|
-
// You can omit anything BUT id, code
|
|
31
|
-
omit = []) {
|
|
32
|
-
const json = ZerospinError.makeZerospinErrorJson({
|
|
33
|
-
cause: this.cause,
|
|
34
|
-
code: this.code,
|
|
35
|
-
extra: this.extra,
|
|
36
|
-
message: this.message,
|
|
37
|
-
status: this.status,
|
|
38
|
-
});
|
|
39
|
-
for (const key of omit) {
|
|
40
|
-
delete json[key];
|
|
41
|
-
}
|
|
42
|
-
return json;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Brand } from 'effect';
|
|
2
|
-
|
|
3
|
-
import type { ZerospinError } from './ZerospinError';
|
|
4
|
-
|
|
5
|
-
export type IAnyErrorJson<ERROR extends IAnyError = IAnyError> =
|
|
6
|
-
Brand.Brand<'ZerospinErrorJson'> & {
|
|
7
|
-
code: ERROR['code'];
|
|
8
|
-
extra: ERROR['extra'];
|
|
9
|
-
message: string;
|
|
10
|
-
status: null | number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type IAnyError = ZerospinError<string>;
|