@devp0nt/error0 1.0.0-next.52 → 1.0.0-next.54
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/dist/cjs/index.cjs +109 -105
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +44 -85
- package/dist/cjs/plugins/code.d.cts +40 -2
- package/dist/cjs/plugins/expected.d.cts +53 -11
- package/dist/cjs/plugins/meta.d.cts +40 -2
- package/dist/cjs/plugins/stack-merge.cjs +3 -3
- package/dist/cjs/plugins/stack-merge.cjs.map +1 -1
- package/dist/cjs/plugins/status.d.cts +40 -2
- package/dist/cjs/plugins/tags.cjs +13 -14
- package/dist/cjs/plugins/tags.cjs.map +1 -1
- package/dist/cjs/plugins/tags.d.cts +73 -5
- package/dist/esm/index.d.ts +44 -85
- package/dist/esm/index.js +109 -105
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugins/code.d.ts +40 -2
- package/dist/esm/plugins/expected.d.ts +53 -11
- package/dist/esm/plugins/meta.d.ts +40 -2
- package/dist/esm/plugins/stack-merge.js +3 -3
- package/dist/esm/plugins/stack-merge.js.map +1 -1
- package/dist/esm/plugins/status.d.ts +40 -2
- package/dist/esm/plugins/tags.d.ts +73 -5
- package/dist/esm/plugins/tags.js +13 -14
- package/dist/esm/plugins/tags.js.map +1 -1
- package/package.json +4 -2
- package/src/index.test.ts +187 -5
- package/src/index.ts +327 -311
- package/src/plugins/stack-merge.ts +2 -3
- package/src/plugins/tags.test.ts +1 -3
- package/src/plugins/tags.ts +28 -16
|
@@ -11,10 +11,9 @@ export const stackMergePlugin = ({
|
|
|
11
11
|
}
|
|
12
12
|
return error
|
|
13
13
|
.causes()
|
|
14
|
-
.
|
|
15
|
-
return cause instanceof Error ? cause.stack :
|
|
14
|
+
.flatMap((cause) => {
|
|
15
|
+
return cause instanceof Error && cause.stack && typeof cause.stack === 'string' ? cause.stack : []
|
|
16
16
|
})
|
|
17
|
-
.filter((value): value is string => typeof value === 'string')
|
|
18
17
|
.join(delimiter)
|
|
19
18
|
},
|
|
20
19
|
})
|
package/src/plugins/tags.test.ts
CHANGED
|
@@ -11,7 +11,7 @@ describe('tagsPlugin', () => {
|
|
|
11
11
|
const leaf = new AppError('leaf', { tags: ['api', 'retry'], cause: root })
|
|
12
12
|
expect(leaf.tags).toEqual(['api', 'retry', 'db'])
|
|
13
13
|
expectTypeOf(leaf.tags).toEqualTypeOf<string[] | undefined>()
|
|
14
|
-
expectTypeOf(leaf.own
|
|
14
|
+
expectTypeOf(leaf.own?.tags).toEqualTypeOf<string[] | undefined>()
|
|
15
15
|
expectTypeOf(leaf.flow('tags')).toEqualTypeOf<Array<string[] | undefined>>()
|
|
16
16
|
})
|
|
17
17
|
|
|
@@ -66,8 +66,6 @@ describe('tagsPlugin', () => {
|
|
|
66
66
|
|
|
67
67
|
// @ts-expect-error - unknown tag is not part of allow-list
|
|
68
68
|
error.hasTag('custom')
|
|
69
|
-
// @ts-expect-error - array checks require policy argument
|
|
70
|
-
error.hasTag(['api', 'db'])
|
|
71
69
|
// @ts-expect-error - unsupported policy
|
|
72
70
|
error.hasTag(['api', 'db'], 'all')
|
|
73
71
|
})
|
package/src/plugins/tags.ts
CHANGED
|
@@ -5,21 +5,21 @@ export const tagsPlugin = <TTag extends string>({
|
|
|
5
5
|
tags,
|
|
6
6
|
strict = true,
|
|
7
7
|
}: { isPublic?: boolean; tags?: TTag[] | readonly TTag[]; strict?: boolean } = {}) => {
|
|
8
|
-
function hasTag(error: Error0, tag: TTag): boolean
|
|
9
|
-
function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean
|
|
10
|
-
function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
8
|
+
// function hasTag(error: Error0, tag: TTag): boolean
|
|
9
|
+
// function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean
|
|
10
|
+
// function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {
|
|
11
|
+
// const tags = (error as any).tags as string[] | undefined
|
|
12
|
+
// if (!tags) {
|
|
13
|
+
// return false
|
|
14
|
+
// }
|
|
15
|
+
// if (Array.isArray(tag)) {
|
|
16
|
+
// if (policy === 'every') {
|
|
17
|
+
// return tag.every((item) => tags.includes(item))
|
|
18
|
+
// }
|
|
19
|
+
// return tag.some((item) => tags.includes(item))
|
|
20
|
+
// }
|
|
21
|
+
// return tags.includes(tag)
|
|
22
|
+
// }
|
|
23
23
|
const isTag = (value: unknown): value is TTag =>
|
|
24
24
|
typeof value === 'string' && (!tags || !strict || tags.includes(value as TTag))
|
|
25
25
|
return Error0.plugin()
|
|
@@ -47,5 +47,17 @@ export const tagsPlugin = <TTag extends string>({
|
|
|
47
47
|
return value.filter((item) => isTag(item))
|
|
48
48
|
},
|
|
49
49
|
})
|
|
50
|
-
.method('hasTag',
|
|
50
|
+
.method('hasTag', (error, tag: TTag | TTag[], policy: 'every' | 'some' = 'every'): boolean => {
|
|
51
|
+
const tags = error.tags
|
|
52
|
+
if (!tags) {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(tag)) {
|
|
56
|
+
if (policy === 'every') {
|
|
57
|
+
return tag.every((item) => tags.includes(item))
|
|
58
|
+
}
|
|
59
|
+
return tag.some((item) => tags.includes(item))
|
|
60
|
+
}
|
|
61
|
+
return tags.includes(tag)
|
|
62
|
+
})
|
|
51
63
|
}
|