Skip to content

Commit

Permalink
fix(commons): allow clearing sourcemap paths
Browse files Browse the repository at this point in the history
fix(schema): fix moment date formatting
  • Loading branch information
blakebyrnes committed Feb 1, 2023
1 parent 19a33b5 commit 4d14167
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions commons/lib/SourceMapSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const fileUrlPrefix = 'file://';
export class SourceMapSupport {
private static sourceMapCache: { [source: string]: { map: SourceMapConsumer; url: string } } = {};
private static resolvedPathCache: { [file_url: string]: string } = {};
private static stackPathsToClear = new Set<string>();

static clearStackPath(stackPath: string): void {
this.stackPathsToClear.add(stackPath)
}

static resetCache(): void {
this.sourceMapCache = {};
Expand Down Expand Up @@ -145,6 +150,12 @@ export class SourceMapSupport {
});
if (position.filename !== filename) {
const fnName = containingFnName ?? frame.getFunctionName();
for (const toReplace of this.stackPathsToClear) {
if (position.filename.startsWith(toReplace)) {
position.filename = position.filename.replace(toReplace, '');
}
}

containingFnName = position.name;
frame = new Proxy(frame, {
get(target: NodeJS.CallSite, p: string | symbol): any {
Expand Down
4 changes: 2 additions & 2 deletions schema/lib/StringSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class StringSchema<TOptional extends boolean = boolean> extends B
if (config.format) {
switch (config.format) {
case 'date': {
if (!moment(value, StringSchema.DateFormat).isValid()) {
if (!moment(value, StringSchema.DateFormat, true).isValid()) {
return this.failedConstraint(
value,
` This value does not follow the YYYY-MM-DD date pattern`,
Expand All @@ -98,7 +98,7 @@ export default class StringSchema<TOptional extends boolean = boolean> extends B
break;
}
case 'time': {
if (!moment(value, StringSchema.TimeFormat).isValid()) {
if (!moment(value, StringSchema.TimeFormat, true).isValid()) {
return this.failedConstraint(
value,
` This value does not follow the HH:mm time pattern`,
Expand Down

0 comments on commit 4d14167

Please sign in to comment.