a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lexicons): optional defaults not being set properly

Mary 9ef363fa 0b0850c4

+25 -14
+5
.changeset/smart-loops-take.md
··· 1 + --- 2 + '@atcute/lexicons': patch 3 + --- 4 + 5 + fix optional defaults not being set properly
+9 -1
packages/lexicons/lexicons/lib/validations/index.test.ts
··· 1 - import { it } from 'vitest'; 1 + import { expect, it } from 'vitest'; 2 2 3 3 import * as v from './index.js'; 4 4 ··· 68 68 69 69 v.parse(recordSchema, res); 70 70 }); 71 + 72 + it.only('sets optional defaults', () => { 73 + const objectSchema = v.object({ 74 + foo: v.optional(v.integer(), 123), 75 + }); 76 + 77 + expect(v.parse(objectSchema, {})).toEqual({ foo: 123 }); 78 + });
+11 -13
packages/lexicons/lexicons/lib/validations/index.ts
··· 1341 1341 1342 1342 const r = entry.schema['~run'](value, flags); 1343 1343 1344 - if (r === undefined) { 1345 - if (output !== undefined) { 1346 - /*#__INLINE__*/ set(output, key, value); 1347 - } 1348 - } else if (r.ok) { 1349 - if (output === undefined) { 1350 - output = { ...input }; 1351 - } 1344 + if (r !== undefined) { 1345 + if (r.ok) { 1346 + if (output === undefined) { 1347 + output = { ...input }; 1348 + } 1352 1349 1353 - /*#__INLINE__*/ set(output, key, value); 1354 - } else { 1355 - issues = joinIssues(issues, prependPath(key, r)); 1350 + /*#__INLINE__*/ set(output, key, r.value); 1351 + } else { 1352 + issues = joinIssues(issues, prependPath(key, r)); 1356 1353 1357 - if (flags & FLAG_ABORT_EARLY) { 1358 - return issues; 1354 + if (flags & FLAG_ABORT_EARLY) { 1355 + return issues; 1356 + } 1359 1357 } 1360 1358 } 1361 1359 }