Skip to content

Commit 3e2b58c

Browse files
logaretmclaude
andcommitted
fix: standard schema validation works with arktype (#5110)
Arktype schemas are callable (typeof === 'function'), so isStandardSchema() was rejecting them because isObject() only accepts typeof === 'object'. Updated the check to accept both objects and functions with the ~standard property, matching the standard schema spec. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d8cc52 commit 3e2b58c

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vee-validate": patch
3+
---
4+
5+
Fix standard schema validation compatibility with arktype (#5110)

packages/vee-validate/src/utils/assertions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export function isLocator(value: unknown): value is Locator {
1010
}
1111

1212
export function isStandardSchema(value: unknown): value is StandardSchemaV1 {
13-
return isObject(value) && '~standard' in (value as unknown as StandardSchemaV1);
13+
return (
14+
!!value &&
15+
(typeof value === 'object' || typeof value === 'function') &&
16+
'~standard' in (value as Record<PropertyKey, unknown>)
17+
);
1418
}
1519

1620
export function hasCheckedAttr(type: unknown) {

packages/vee-validate/tests/utils/assertions.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEqual } from 'packages/vee-validate/src/utils';
1+
import { isEqual, isStandardSchema } from 'packages/vee-validate/src/utils';
22

33
describe('assertions', () => {
44
test('equal objects are equal', () => {
@@ -229,3 +229,60 @@ describe('assertions', () => {
229229
expect(isEqual(a6, b2)).toBe(false);
230230
});
231231
});
232+
233+
// #5110 - arktype compatibility
234+
describe('isStandardSchema', () => {
235+
test('detects a plain object with ~standard property as a standard schema', () => {
236+
const schema = {
237+
'~standard': {
238+
version: 1,
239+
vendor: 'test',
240+
validate: (value: unknown) => ({ value }),
241+
},
242+
};
243+
244+
expect(isStandardSchema(schema)).toBe(true);
245+
});
246+
247+
test('detects a callable object with ~standard property as a standard schema (like arktype)', () => {
248+
// Arktype schemas are functions that also have the ~standard property
249+
const callableSchema = Object.assign(
250+
function (value: unknown) {
251+
return value;
252+
},
253+
{
254+
'~standard': {
255+
version: 1,
256+
vendor: 'arktype',
257+
validate: (value: unknown) => ({ value }),
258+
},
259+
},
260+
);
261+
262+
expect(isStandardSchema(callableSchema)).toBe(true);
263+
});
264+
265+
test('returns false for a plain function without ~standard', () => {
266+
const fn = (value: unknown) => value;
267+
expect(isStandardSchema(fn)).toBe(false);
268+
});
269+
270+
test('returns false for primitive values', () => {
271+
expect(isStandardSchema(null)).toBe(false);
272+
expect(isStandardSchema(undefined)).toBe(false);
273+
expect(isStandardSchema('')).toBe(false);
274+
expect(isStandardSchema('required')).toBe(false);
275+
expect(isStandardSchema(0)).toBe(false);
276+
expect(isStandardSchema(true)).toBe(false);
277+
});
278+
279+
test('returns false for arrays', () => {
280+
expect(isStandardSchema([])).toBe(false);
281+
expect(isStandardSchema([() => true])).toBe(false);
282+
});
283+
284+
test('returns false for plain objects without ~standard', () => {
285+
expect(isStandardSchema({})).toBe(false);
286+
expect(isStandardSchema({ required: true })).toBe(false);
287+
});
288+
});

0 commit comments

Comments
 (0)