Improve perf by changing ~standard implementation#1534
Conversation
WalkthroughIntroduces Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
valibot-website | abca1c4 | Commit Preview URL Branch Preview URL |
Jul 18 2026, 06:27 PM |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7cd4bdbcd9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1,10 +1,10 @@ | |||
| export * from './_addIssue/index.ts'; | |||
| export * from './_addStandardProp/index.ts'; | |||
There was a problem hiding this comment.
Keep the documented Standard helper available
Replacing the _getStandardProps export breaks the documented advanced custom-schema flow: website/src/routes/guides/(advanced)/extend-valibot/index.mdx still tells users to call v._getStandardProps(this) and explicitly says _getStandardProps is exported for advanced use, while internal-architecture also shows the old getter pattern. After this export swap, anyone following those examples gets a missing export from valibot; either keep a compatibility export or update the docs/examples in the same change.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
1 issue found across 97 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="library/src/utils/index.ts">
<violation number="1" location="library/src/utils/index.ts:2">
P2: Removing the `_getStandardProps` export is a breaking change for users following the documented advanced custom-schema guides. The [Extend Valibot](https://valibot.dev/guides/extend-valibot/) guide explicitly tells users to call `v._getStandardProps(this)` in custom schema factories, and the [Internal Architecture](https://valibot.dev/guides/internal-architecture/) guide shows the same pattern. After this change, anyone following those examples will get a missing export error at runtime.
Consider either keeping a deprecated compatibility re-export (e.g., `export { _addStandardProp as _getStandardProps }` with adjusted semantics, or a thin wrapper) or updating the website documentation in the same PR so the guides stay consistent with the library's public surface.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| @@ -1,10 +1,10 @@ | |||
| export * from './_addIssue/index.ts'; | |||
| export * from './_addStandardProp/index.ts'; | |||
There was a problem hiding this comment.
P2: Removing the _getStandardProps export is a breaking change for users following the documented advanced custom-schema guides. The Extend Valibot guide explicitly tells users to call v._getStandardProps(this) in custom schema factories, and the Internal Architecture guide shows the same pattern. After this change, anyone following those examples will get a missing export error at runtime.
Consider either keeping a deprecated compatibility re-export (e.g., export { _addStandardProp as _getStandardProps } with adjusted semantics, or a thin wrapper) or updating the website documentation in the same PR so the guides stay consistent with the library's public surface.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/utils/index.ts, line 2:
<comment>Removing the `_getStandardProps` export is a breaking change for users following the documented advanced custom-schema guides. The [Extend Valibot](https://valibot.dev/guides/extend-valibot/) guide explicitly tells users to call `v._getStandardProps(this)` in custom schema factories, and the [Internal Architecture](https://valibot.dev/guides/internal-architecture/) guide shows the same pattern. After this change, anyone following those examples will get a missing export error at runtime.
Consider either keeping a deprecated compatibility re-export (e.g., `export { _addStandardProp as _getStandardProps }` with adjusted semantics, or a thin wrapper) or updating the website documentation in the same PR so the guides stay consistent with the library's public surface.</comment>
<file context>
@@ -1,10 +1,10 @@
export * from './_addIssue/index.ts';
+export * from './_addStandardProp/index.ts';
export * from './_cloneDataset/index.ts';
export * from './_formatCase/index.ts';
</file context>
There was a problem hiding this comment.
Pull request overview
This PR improves Valibot schema construction performance by replacing the lazy get '~standard'() accessor (and its _getStandardProps WeakMap cache) with an eager, plain data-property assignment via the new internal _addStandardProp utility. It updates schema factories and spread-based methods to ensure schema['~standard'].validate continues to validate against the newly created schema object after spreads/copies.
Changes:
- Introduces
library/src/utils/_addStandardPropand exports it fromlibrary/src/utils/index.ts. - Removes
_getStandardProps(and the_standardCacheWeakMap) and replaces lazy~standardgetters across schema factories with_addStandardProp(...). - Re-wraps spread-based method results (e.g.
pipe,fallback,omit,partial,required,cache,config,message) and adds regression tests to ensure~standard.validatetargets the correct schema.
Reviewed changes
Copilot reviewed 97 out of 97 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| library/src/utils/index.ts | Exports the new _addStandardProp utility and stops exporting _getStandardProps. |
| library/src/utils/_getStandardProps/index.ts | Removed export barrel for _getStandardProps (deprecated path). |
| library/src/utils/_getStandardProps/_getStandardProps.ts | Removes lazy ~standard props generator and WeakMap cache. |
| library/src/utils/_addStandardProp/index.ts | Adds export barrel for _addStandardProp. |
| library/src/utils/_addStandardProp/_addStandardProp.ts | New internal helper to eagerly attach ~standard as a data property. |
| library/src/utils/_addStandardProp/_addStandardProp.test.ts | Updates runtime tests to validate eager ~standard behavior and repeated access identity. |
| library/src/utils/_addStandardProp/_addStandardProp.test-d.ts | Updates type tests to validate ~standard inference through pipe(...). |
| library/src/schemas/any/any.ts | Wraps schema literal in _addStandardProp(...) instead of a ~standard getter. |
| library/src/schemas/unknown/unknown.ts | Wraps schema literal in _addStandardProp(...) instead of a ~standard getter. |
| library/src/schemas/void/void.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/undefined/undefined.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/null/null.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/boolean/boolean.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/bigint/bigint.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/blob/blob.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/date/date.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/file/file.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/function/function.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/instance/instance.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/lazy/lazy.ts | Wraps schema literal in _addStandardProp(...) (removes ~standard getter). |
| library/src/schemas/lazy/lazyAsync.ts | Wraps schema literal in _addStandardProp(...) (removes ~standard getter). |
| library/src/schemas/literal/literal.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nan/nan.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/number/number.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/picklist/picklist.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/promise/promise.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/string/string.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/symbol/symbol.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/enum/enum.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/array/array.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/array/arrayAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/custom/custom.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/custom/customAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/exactOptional/exactOptional.ts | Wraps schema literal in _addStandardProp(...) (removes ~standard getter). |
| library/src/schemas/exactOptional/exactOptionalAsync.ts | Wraps schema literal in _addStandardProp(...) (removes ~standard getter). |
| library/src/schemas/intersect/intersect.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/intersect/intersectAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/looseObject/looseObject.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/looseObject/looseObjectAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/looseTuple/looseTuple.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/looseTuple/looseTupleAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/map/map.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/map/mapAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonNullable/nonNullable.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonNullable/nonNullableAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonNullish/nonNullish.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonNullish/nonNullishAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonOptional/nonOptional.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nonOptional/nonOptionalAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nullable/nullable.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nullable/nullableAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nullish/nullish.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/nullish/nullishAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/object/object.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/object/objectAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/objectWithRest/objectWithRest.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/objectWithRest/objectWithRestAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/optional/optional.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/optional/optionalAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/record/record.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/record/recordAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/set/set.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/set/setAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/strictObject/strictObject.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/strictObject/strictObjectAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/strictTuple/strictTuple.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/strictTuple/strictTupleAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/tuple/tuple.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/tuple/tupleAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/tupleWithRest/tupleWithRest.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/tupleWithRest/tupleWithRestAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/undefinedable/undefinedable.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/undefinedable/undefinedableAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/union/union.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/union/unionAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/variant/variant.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/variant/variantAsync.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/schemas/never/never.ts | Wraps schema literal in _addStandardProp(...) and updates ~run typing. |
| library/src/methods/cache/cache.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/cache/cacheAsync.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/config/config.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/message/message.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/fallback/fallback.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/fallback/fallbackAsync.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/omit/omit.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/omit/omit.test.ts | Adds regression test ensuring ~standard.validate reflects omitted entries. |
| library/src/methods/partial/partial.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/partial/partialAsync.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/partial/partial.test.ts | Adds regression test ensuring ~standard.validate reflects partial entries. |
| library/src/methods/pick/pick.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/pipe/pipe.ts | Re-wraps piped schema with _addStandardProp(...) and adds ~standard regression tests. |
| library/src/methods/pipe/pipe.test.ts | Adds regression tests for ~standard.validate correctness and destructuring safety. |
| library/src/methods/pipe/pipeAsync.ts | Re-wraps piped async schema with _addStandardProp(...) and adds ~standard regression tests. |
| library/src/methods/pipe/pipeAsync.test.ts | Adds regression tests for async ~standard.validate correctness. |
| library/src/methods/required/required.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/required/requiredAsync.ts | Re-wraps spread result with _addStandardProp(...) to refresh ~standard.validate binding. |
| library/src/methods/required/required.test.ts | Adds regression test ensuring ~standard.validate reflects required entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
| }); | ||
|
|
||
| test('should validate against the partialed entries via "~standard"', () => { |
| } as unknown as Omit< | ||
| SchemaWithPipeAsync<readonly [TSchema, ...TItems]>, | ||
| '~standard' | ||
| >); |
| } as unknown as Omit< | ||
| SchemaWithFallbackAsync<TSchema, TFallback>, | ||
| '~standard' | ||
| >); |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
library/src/methods/message/message.ts (1)
24-29: 🎯 Functional Correctness | 🔴 Critical | 🏗️ Heavy liftPreserve the
thiscontext when delegating to the underlying schema's~runmethod.Currently,
message()overrides the~runmethod by callingschema['~run'](...). This drops thethiscontext and hard-binds execution to the originalschemaobject.If a user applies a structural modifier (like
required(),partial(),pick(), oromit()) aftermessage(), the modifier creates a new schema with updated properties (e.g., modifiedentries). However, during validation, the wrapper's~runexecutes the original schema's~runbound to the original object. This causes the underlying schema to access the originalentriesand completely ignore the structural modifications, leading to silent validation bypasses.To fix this, delegate the call using
.call(this, ...)so that schemas likeobjectorarraycorrectly access the modified properties (likethis.entriesorthis.item) from the outer schema instance. (Note: Consider reviewing other wrappers likefallbackorconfigto ensure they also preserve thethiscontext if they share this pattern).🐛 Proposed fix
- '~run'(dataset, config) { - return schema['~run'](dataset, { ...config, message: message_ }); + '~run'(this: any, dataset, config) { + return schema['~run'].call(this, dataset, { ...config, message: message_ }); },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@library/src/methods/message/message.ts` around lines 24 - 29, Update the `~run` override inside `message()` to invoke the underlying `schema['~run']` with `this` bound to the outer schema instance, while preserving the merged message configuration. This ensures structural modifiers applied after `message()` use updated properties such as entries or item.
🧹 Nitpick comments (1)
library/src/methods/omit/omit.ts (1)
482-487: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix typographical error.
Correct
RerturntoReturn.💡 Proposed fix
- // Rerturn modified copy of schema + // Return modified copy of schema // `@ts-expect-error` return _standardSchema<SchemaWithOmit<TSchema, TKeys>>({🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@library/src/methods/omit/omit.ts` around lines 482 - 487, Correct the typo in the comment immediately above the _standardSchema call, changing “Rerturn” to “Return” without modifying the surrounding implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@library/src/methods/message/message.ts`:
- Around line 24-29: Update the `~run` override inside `message()` to invoke the
underlying `schema['~run']` with `this` bound to the outer schema instance,
while preserving the merged message configuration. This ensures structural
modifiers applied after `message()` use updated properties such as entries or
item.
---
Nitpick comments:
In `@library/src/methods/omit/omit.ts`:
- Around line 482-487: Correct the typo in the comment immediately above the
_standardSchema call, changing “Rerturn” to “Return” without modifying the
surrounding implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 35d3610d-4e27-467a-bd42-ecf4de74b386
📒 Files selected for processing (90)
library/src/methods/cache/cache.tslibrary/src/methods/cache/cacheAsync.tslibrary/src/methods/config/config.tslibrary/src/methods/fallback/fallback.tslibrary/src/methods/fallback/fallbackAsync.tslibrary/src/methods/message/message.tslibrary/src/methods/omit/omit.tslibrary/src/methods/partial/partial.tslibrary/src/methods/partial/partialAsync.tslibrary/src/methods/pick/pick.tslibrary/src/methods/pipe/pipe.tslibrary/src/methods/pipe/pipeAsync.tslibrary/src/methods/required/required.tslibrary/src/methods/required/requiredAsync.tslibrary/src/schemas/any/any.tslibrary/src/schemas/array/array.tslibrary/src/schemas/array/arrayAsync.tslibrary/src/schemas/bigint/bigint.tslibrary/src/schemas/blob/blob.tslibrary/src/schemas/boolean/boolean.tslibrary/src/schemas/custom/custom.tslibrary/src/schemas/custom/customAsync.tslibrary/src/schemas/date/date.tslibrary/src/schemas/enum/enum.tslibrary/src/schemas/exactOptional/exactOptional.tslibrary/src/schemas/exactOptional/exactOptionalAsync.tslibrary/src/schemas/file/file.tslibrary/src/schemas/function/function.tslibrary/src/schemas/instance/instance.tslibrary/src/schemas/intersect/intersect.tslibrary/src/schemas/intersect/intersectAsync.tslibrary/src/schemas/lazy/lazy.tslibrary/src/schemas/lazy/lazyAsync.tslibrary/src/schemas/literal/literal.tslibrary/src/schemas/looseObject/looseObject.tslibrary/src/schemas/looseObject/looseObjectAsync.tslibrary/src/schemas/looseTuple/looseTuple.tslibrary/src/schemas/looseTuple/looseTupleAsync.tslibrary/src/schemas/map/map.tslibrary/src/schemas/map/mapAsync.tslibrary/src/schemas/nan/nan.tslibrary/src/schemas/never/never.tslibrary/src/schemas/nonNullable/nonNullable.tslibrary/src/schemas/nonNullable/nonNullableAsync.tslibrary/src/schemas/nonNullish/nonNullish.tslibrary/src/schemas/nonNullish/nonNullishAsync.tslibrary/src/schemas/nonOptional/nonOptional.tslibrary/src/schemas/nonOptional/nonOptionalAsync.tslibrary/src/schemas/null/null.tslibrary/src/schemas/nullable/nullable.tslibrary/src/schemas/nullable/nullableAsync.tslibrary/src/schemas/nullish/nullish.tslibrary/src/schemas/nullish/nullishAsync.tslibrary/src/schemas/number/number.tslibrary/src/schemas/object/object.tslibrary/src/schemas/object/objectAsync.tslibrary/src/schemas/objectWithRest/objectWithRest.tslibrary/src/schemas/objectWithRest/objectWithRestAsync.tslibrary/src/schemas/optional/optional.tslibrary/src/schemas/optional/optionalAsync.tslibrary/src/schemas/picklist/picklist.tslibrary/src/schemas/promise/promise.tslibrary/src/schemas/record/record.tslibrary/src/schemas/record/recordAsync.tslibrary/src/schemas/set/set.tslibrary/src/schemas/set/setAsync.tslibrary/src/schemas/strictObject/strictObject.tslibrary/src/schemas/strictObject/strictObjectAsync.tslibrary/src/schemas/strictTuple/strictTuple.tslibrary/src/schemas/strictTuple/strictTupleAsync.tslibrary/src/schemas/string/string.tslibrary/src/schemas/symbol/symbol.tslibrary/src/schemas/tuple/tuple.tslibrary/src/schemas/tuple/tupleAsync.tslibrary/src/schemas/tupleWithRest/tupleWithRest.tslibrary/src/schemas/tupleWithRest/tupleWithRestAsync.tslibrary/src/schemas/undefined/undefined.tslibrary/src/schemas/undefinedable/undefinedable.tslibrary/src/schemas/undefinedable/undefinedableAsync.tslibrary/src/schemas/union/union.tslibrary/src/schemas/union/unionAsync.tslibrary/src/schemas/unknown/unknown.tslibrary/src/schemas/variant/variant.tslibrary/src/schemas/variant/variantAsync.tslibrary/src/schemas/void/void.tslibrary/src/utils/_standardSchema/_standardSchema.test-d.tslibrary/src/utils/_standardSchema/_standardSchema.test.tslibrary/src/utils/_standardSchema/_standardSchema.tslibrary/src/utils/_standardSchema/index.tslibrary/src/utils/index.ts
🚧 Files skipped from review as they are similar to previous changes (17)
- library/src/methods/config/config.ts
- library/src/schemas/date/date.ts
- library/src/schemas/nullable/nullable.ts
- library/src/methods/fallback/fallbackAsync.ts
- library/src/schemas/optional/optionalAsync.ts
- library/src/schemas/bigint/bigint.ts
- library/src/methods/pick/pick.ts
- library/src/schemas/objectWithRest/objectWithRest.ts
- library/src/schemas/promise/promise.ts
- library/src/schemas/nonOptional/nonOptional.ts
- library/src/methods/required/requiredAsync.ts
- library/src/schemas/enum/enum.ts
- library/src/schemas/never/never.ts
- library/src/schemas/string/string.ts
- library/src/schemas/tupleWithRest/tupleWithRestAsync.ts
- library/src/schemas/symbol/symbol.ts
- library/src/schemas/strictObject/strictObjectAsync.ts
| BaseSchema<unknown, unknown, BaseIssue<unknown>>, | ||
| ErrorMessage<ArrayIssue> | undefined | ||
| > | ||
| >({ |
There was a problem hiding this comment.
Redundant explicit generic argument _standardSchema<...>(...), repeated in ~90 places and duplicating the function's return type annotation.
Improve schema init performance: eager
~standardassignmentReplaces the lazy
get '~standard'()accessor on every schema factory with eager assignment of the Standard Schema props as a plain data property (_addStandardProp), removing_getStandardPropsand its_standardCacheWeakMap.Why: the getter made schema construction slow on every build — an accessor in an object literal disables V8's fast-literal path, and
pipe()'s spread ofpipe[0]invoked the getter (plus a WeakMap get/set) on each call, all to produce a value only read when someone actually uses Standard Schema. Allocating the props eagerly is cheaper than installing an accessor.Changes:
_addStandardProputil;_getStandardProps+ WeakMap removed._addStandardProp(...).pipe,omit,partial,fallback, …) re-wrap their result — required for correctness, since a spread copies the source'svalidatebinding. Regression tests added (e.g.pipe(string(), maxLength(3))['~standard'].validate('too long')must fail).Compat: no public API change;
~standardstays an own enumerable property (now writable data instead of a getter).Results: ~3× faster construction locally (~6.8 → ~2.1 µs); bundle 85.32 → 82.80 kB. Lint + full suite (3065 tests) pass.
Summary by CodeRabbit
New Features
Bug Fixes