@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.
@@ -1 +1 @@
1
- {"root":["../src/zerospinerror.ts","../src/zerospinerrorjsonschema.ts","../src/index.ts","../src/types.ts"],"version":"5.9.0-dev.20250623"}
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
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /Users/morgs32/GitHub/zerospin/packages/error/tsup.config.ts
9
+ CLI Target: es2022
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ ESM dist/index.js 1.30 KB
13
+ ESM ⚡️ 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
+  RUN  v3.2.4 /Users/morgs32/GitHub/zerospin/packages/error
7
+
8
+ No test files found, exiting with code 1
9
+ 
10
+ filter: packages/profiler/src/toMatchProcedure
11
+ include: **/*.{test,spec}.?(c|m)[jt]s?(x)
12
+ exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
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: { userId: '123' },
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
- new ZerospinError<ErrorCode, { userId: string; action: string }>({
445
+ new ZerospinError<ErrorCode, { actorId: string; action: string }>({
446
446
  code: 'permission-denied',
447
- extra: { userId: '123', action: 'delete' },
447
+ extra: { actorId: '123', action: 'delete' },
448
448
  })
449
449
  ```
450
450
 
@@ -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
- export * from './ZerospinError';
2
- export * from './ZerospinErrorJsonSchema';
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.0.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": "./src/index.ts",
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
- "type-fest": "^4.41.0"
15
+ "drizzle-orm": "^0.45.1",
16
+ "type-fest": "^5.4.1"
15
17
  },
16
18
  "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",
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.15.2"
37
+ "effect": "^3.17.11"
34
38
  },
35
39
  "scripts": {
36
- "build": "tsc -b tsconfig.build.json",
37
- "watch": "tsc -b tsconfig.build.json --watch",
40
+ "build": "tsup",
41
+ "watch": "tsup --watch",
38
42
  "typecheck": "tsc --noEmit",
39
43
  "test": "vitest",
40
44
  "lint": "eslint .",
@@ -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
- import type { IAnyErrorJson } from './types'
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
- 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
+ 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, E = unknown> {
17
- code: T
18
- status: null | number
19
- cause?: unknown
20
- extra?: E
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
- E = unknown,
27
- > extends Data.TaggedError('ZerospinError')<IError<T, E>> {
28
- public override message!: string
34
+ > extends Data.TaggedError('ZerospinError')<IError<T>> {
35
+ public override message!: string;
29
36
 
30
- constructor(props: IProps<T, E> | T) {
37
+ constructor(props: IProps<T> | T) {
31
38
  if (typeof props === 'string') {
32
39
  super({
33
40
  code: props,
34
- extra: null as E,
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
  }
@@ -1,6 +1,6 @@
1
1
  import { Schema } from 'effect'
2
2
 
3
- import type { IAnyErrorJson } from './types'
3
+ import type { IAnyErrorJson } from './ZerospinError'
4
4
 
5
5
  export const ZerospinErrorJsonSchema = Schema.Struct({
6
6
  code: Schema.String,
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- export type * from './types';
2
1
  export * from './ZerospinError';
3
2
  export * from './ZerospinErrorJsonSchema';
package/tsconfig.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "compilerOptions": {
8
8
  "incremental": false,
9
9
  "types": [
10
+ "node",
10
11
  "vitest/globals"
11
12
  ],
12
13
  "outDir": "./dist",
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
+
@@ -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
- }
@@ -1,7 +0,0 @@
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/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>;