Skip to content

Commit

Permalink
extract regexp parser for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-theriault-swi committed Aug 31, 2023
1 parent aa6d1c1 commit cea568c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/solarwinds-apm/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ const boolean = z.union([
.transform((b) => b === "true" || b === "1"),
])

const regex = z.union([
z.instanceof(RegExp),
z.string().transform((s, ctx) => {
try {
return new RegExp(s)
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: (err as SyntaxError).message,
})
return z.NEVER
}
}),
])

const serviceKey = z
.string()
.includes(":")
Expand Down Expand Up @@ -100,20 +115,7 @@ const transactionSettings = z.array(
.union([
z.object({
tracing: tracingMode,
regex: z.union([
z.instanceof(RegExp),
z.string().transform((s, ctx) => {
try {
return new RegExp(s)
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: (err as SyntaxError).message,
})
return z.NEVER
}
}),
]),
regex,
}),
z.object({
tracing: tracingMode,
Expand Down Expand Up @@ -234,7 +236,7 @@ export function printError(err: unknown) {
: // `full.key[0].path`
path
.map((p) => (typeof p === "string" ? `.${p}` : `[${p}]`))
.join(".")
.join("")
.slice(1)

const formatIssue =
Expand Down

0 comments on commit cea568c

Please sign in to comment.