@zerospin/error 2.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.
@@ -0,0 +1 @@
1
+ {"root":["../src/zerospinerror.ts","../src/zerospinerrorjsonschema.ts","../src/index.ts","../src/types.ts"],"version":"5.9.0-dev.20250623"}
@@ -0,0 +1,20 @@
1
+
2
+ 
3
+ > @zerospin/error@2.0.1 lint /Users/morgs32/GitHub/zerospin/packages/error
4
+ > eslint .
5
+
6
+ =============
7
+
8
+
9
+ WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.
10
+
11
+
12
+ * @typescript-eslint/typescript-estree version: 8.34.1
13
+ * Supported TypeScript versions: >=4.8.4 <5.9.0
14
+ * Your TypeScript version: 5.9.0-dev.20250623
15
+
16
+
17
+ Please only submit bug reports when using the officially supported version.
18
+
19
+
20
+ =============
@@ -0,0 +1,44 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ import { Schema } from 'effect';
2
+ export const ZerospinErrorJsonSchema = Schema.Struct({
3
+ code: Schema.String,
4
+ extra: Schema.Unknown,
5
+ message: Schema.String,
6
+ status: Schema.Union(Schema.Null, Schema.Number),
7
+ });
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './ZerospinError';
2
+ export * from './ZerospinErrorJsonSchema';
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { baseConfig, defineConfig } from '@zerospin/utils'
2
+
3
+ const eslintConfig = defineConfig(
4
+ {
5
+ ignores: ['dist', 'node_modules', '.turbo'],
6
+ },
7
+ baseConfig
8
+ )
9
+
10
+ export default eslintConfig
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@zerospin/error",
3
+ "version": "2.0.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "type-fest": "^4.41.0"
15
+ },
16
+ "devDependencies": {
17
+ "@effect/language-service": "^0.43.2",
18
+ "@effect/vitest": "^0.25.1",
19
+ "@vitest/coverage-v8": "^3.2.4",
20
+ "@vitest/pretty-format": "^3.1.4",
21
+ "effect": "^3.17.11",
22
+ "eslint": "^9.27.0",
23
+ "glob": "^11.0.3",
24
+ "jsdom": "^26.1.0",
25
+ "knip": "^4.2.4",
26
+ "tsafe": "^1.8.5",
27
+ "tsx": "^4.20.3",
28
+ "vite-tsconfig-paths": "^5.1.4",
29
+ "vitest": "^3.2.4",
30
+ "@zerospin/utils": "2.0.1"
31
+ },
32
+ "peerDependencies": {
33
+ "effect": "^3.15.2"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -b tsconfig.build.json",
37
+ "watch": "tsc -b tsconfig.build.json --watch",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest",
40
+ "lint": "eslint .",
41
+ "test:watch": "vitest watch",
42
+ "test:coverage": "vitest run --coverage",
43
+ "knip": "knip"
44
+ }
45
+ }
@@ -0,0 +1,83 @@
1
+ import type { RequiredKeysOf } from 'type-fest'
2
+
3
+ import { Brand, Data } from 'effect'
4
+ import { isObject } from 'effect/Predicate'
5
+
6
+ import type { IAnyErrorJson } from './types'
7
+
8
+ interface IProps<T extends string = string, E = unknown> {
9
+ code: T
10
+ cause?: unknown
11
+ extra?: E
12
+ message?: string
13
+ status?: null | number
14
+ }
15
+
16
+ export interface IError<T extends string = string, E = unknown> {
17
+ code: T
18
+ status: null | number
19
+ cause?: unknown
20
+ extra?: E
21
+ message?: string
22
+ }
23
+
24
+ export class ZerospinError<
25
+ T extends string = never,
26
+ E = unknown,
27
+ > extends Data.TaggedError('ZerospinError')<IError<T, E>> {
28
+ public override message!: string
29
+
30
+ constructor(props: IProps<T, E> | T) {
31
+ if (typeof props === 'string') {
32
+ super({
33
+ code: props,
34
+ extra: null as E,
35
+ message: props,
36
+ status: null,
37
+ })
38
+ this.message = props
39
+ } else {
40
+ super({
41
+ status: null,
42
+ ...props,
43
+ })
44
+ this.message = props.message ?? props.code
45
+ }
46
+ }
47
+
48
+ static isZerospinError(data: unknown): data is ZerospinError {
49
+ return isObject(data) && '_tag' in data && data._tag === 'ZerospinError'
50
+ }
51
+
52
+ static makeZerospinErrorJson(props: {
53
+ cause: unknown
54
+ code: string
55
+ extra: unknown
56
+ message: string
57
+ status: null | number
58
+ }): IAnyErrorJson {
59
+ return Brand.nominal<IAnyErrorJson>()(props)
60
+ }
61
+
62
+ serialize(
63
+ // You can omit anything BUT id, code
64
+ omit: Exclude<
65
+ keyof IAnyErrorJson,
66
+ RequiredKeysOf<IAnyErrorJson>
67
+ >[] = []
68
+ ): IAnyErrorJson {
69
+ const json = ZerospinError.makeZerospinErrorJson({
70
+ cause: this.cause,
71
+ code: this.code,
72
+ extra: this.extra,
73
+ message: this.message,
74
+ status: this.status,
75
+ })
76
+
77
+ for (const key of omit) {
78
+ delete json[key]
79
+ }
80
+
81
+ return json
82
+ }
83
+ }
@@ -0,0 +1,10 @@
1
+ import { Schema } from 'effect'
2
+
3
+ import type { IAnyErrorJson } from './types'
4
+
5
+ export const ZerospinErrorJsonSchema = Schema.Struct({
6
+ code: Schema.String,
7
+ extra: Schema.Unknown,
8
+ message: Schema.String,
9
+ status: Schema.Union(Schema.Null, Schema.Number),
10
+ }) as any as Schema.Schema<IAnyErrorJson, any>
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type * from './types';
2
+ export * from './ZerospinError';
3
+ export * from './ZerospinErrorJsonSchema';
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
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>;
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": [
4
+ "src"
5
+ ],
6
+ "compilerOptions": {
7
+ "tsBuildInfoFile": ".tsbuildinfo/build.tsbuildinfo",
8
+ "outDir": "dist",
9
+ "stripInternal": true,
10
+ "noEmit": false,
11
+ "rootDir": "./src"
12
+ }
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": [
4
+ "src",
5
+ "*.ts"
6
+ ],
7
+ "compilerOptions": {
8
+ "incremental": false,
9
+ "types": [
10
+ "vitest/globals"
11
+ ],
12
+ "outDir": "./dist",
13
+ "rootDir": "."
14
+ }
15
+ }