Skip to content

Commit

Permalink
fix: Performance regression
Browse files Browse the repository at this point in the history
  • Loading branch information
vbudovski committed Sep 10, 2024
1 parent efff193 commit 4d8da18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions paseri-lib/src/schemas/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NonEmptyObject } from 'type-fest';
import type { Infer } from '../infer.ts';
import type { TreeNode } from '../issue.ts';
import { addIssue } from '../issue.ts';
import { type InternalParseResult, isParseSuccess, ok } from '../result.ts';
import { type InternalParseResult, isParseSuccess } from '../result.ts';
import { isPlainObject } from '../utils.ts';
import { OptionalSchema, Schema } from './schema.ts';

Expand Down Expand Up @@ -123,7 +123,7 @@ class ObjectSchema<ShapeType extends ValidShapeType<ShapeType>> extends Schema<I
}
}

return ok(sanitizedValue as Infer<ShapeType>);
return { ok: true, value: sanitizedValue as Infer<ShapeType> };
}

if (hasUnrecognisedKey && this._mode === 'strip' && !hasModifiedChildValue) {
Expand All @@ -136,11 +136,11 @@ class ObjectSchema<ShapeType extends ValidShapeType<ShapeType>> extends Schema<I
sanitizedValue[key] = value[key];
}

return ok(sanitizedValue as Infer<ShapeType>);
return { ok: true, value: sanitizedValue as Infer<ShapeType> };
}

if (hasModifiedChildValue) {
return ok({ ...value, ...modifiedValues } as Infer<ShapeType>);
return { ok: true, value: { ...value, ...modifiedValues } as Infer<ShapeType> };
}

return undefined;
Expand Down
6 changes: 3 additions & 3 deletions paseri-lib/src/schemas/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isParseSuccess, ok } from '../result.ts';
import { isParseSuccess } from '../result.ts';
import type { InternalParseResult, ParseResult } from '../result.ts';

abstract class Schema<OutputType> {
Expand All @@ -16,7 +16,7 @@ abstract class Schema<OutputType> {
const issueOrSuccess = this._parse(value);
if (issueOrSuccess === undefined) {
// We're dealing with a primitive value, and no issue was found, so just assert type and pass it through.
return ok(value as OutputType);
return { ok: true, value: value as OutputType };
}

if (isParseSuccess(issueOrSuccess)) {
Expand Down Expand Up @@ -116,7 +116,7 @@ class ChainSchema<FromOutputType, ToOutputType> extends Schema<ToOutputType> {

const issueOrSuccessTo = this._toSchema._parse(transformedResult.value);
if (issueOrSuccessTo === undefined) {
return ok(transformedResult.value);
return { ok: true, value: transformedResult.value };
}

return issueOrSuccessTo;
Expand Down

0 comments on commit 4d8da18

Please sign in to comment.