From 4d8da180a724e538674279efa6f5c6294ae2b156 Mon Sep 17 00:00:00 2001 From: Vitaly Budovski Date: Tue, 10 Sep 2024 20:06:31 +0900 Subject: [PATCH] fix: Performance regression --- paseri-lib/src/schemas/object.ts | 8 ++++---- paseri-lib/src/schemas/schema.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/paseri-lib/src/schemas/object.ts b/paseri-lib/src/schemas/object.ts index 907a46a..d430578 100644 --- a/paseri-lib/src/schemas/object.ts +++ b/paseri-lib/src/schemas/object.ts @@ -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'; @@ -123,7 +123,7 @@ class ObjectSchema> extends Schema); + return { ok: true, value: sanitizedValue as Infer }; } if (hasUnrecognisedKey && this._mode === 'strip' && !hasModifiedChildValue) { @@ -136,11 +136,11 @@ class ObjectSchema> extends Schema); + return { ok: true, value: sanitizedValue as Infer }; } if (hasModifiedChildValue) { - return ok({ ...value, ...modifiedValues } as Infer); + return { ok: true, value: { ...value, ...modifiedValues } as Infer }; } return undefined; diff --git a/paseri-lib/src/schemas/schema.ts b/paseri-lib/src/schemas/schema.ts index f5b9fd7..e38bcd1 100644 --- a/paseri-lib/src/schemas/schema.ts +++ b/paseri-lib/src/schemas/schema.ts @@ -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 { @@ -16,7 +16,7 @@ abstract class Schema { 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)) { @@ -116,7 +116,7 @@ class ChainSchema extends Schema { const issueOrSuccessTo = this._toSchema._parse(transformedResult.value); if (issueOrSuccessTo === undefined) { - return ok(transformedResult.value); + return { ok: true, value: transformedResult.value }; } return issueOrSuccessTo;