Skip to content

Add Schema Result decode and encode helpers#1633

Merged
gcanti merged 1 commit intomainfrom
kit/schema-result-combinators
Mar 19, 2026
Merged

Add Schema Result decode and encode helpers#1633
gcanti merged 1 commit intomainfrom
kit/schema-result-combinators

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

  • add SchemaParser.decodeUnknownResult / decodeResult and encodeUnknownResult / encodeResult for synchronous Result-based parsing
  • re-export the new Result-based helpers from Schema
  • ensure asResult maps typed parse errors to Result.fail(issue) and throws for defect-only causes
  • add schema tests for success / typed failure behavior and throw behavior for async decoders and missing dependencies
  • add a patch changeset for effect

Testing

  • pnpm lint-fix
  • pnpm test packages/effect/test/schema/Schema.test.ts
  • pnpm check:tsgo
  • pnpm docgen

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 6f4f653

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 4, 2026

📊 JSDoc Documentation Analysis

📈 Current Analysis Results
Analyzing 134 TypeScript files in packages/effect/src/ (including schema and config subdirectories)...

============================================================
         EFFECT JSDOC ANALYSIS REPORT
============================================================

📊 SUMMARY STATISTICS
------------------------------
Total files analyzed: 134
Total exported members: 4228
Missing @example: 2082 (49.2%)
Missing @category: 454 (10.7%)

🎯 TOP FILES NEEDING ATTENTION
----------------------------------------
1. Schema.ts
   📝 486 missing examples, 🏷️  268 missing categories
   📦 486 total exports
2. Array.ts
   📝 135 missing examples, 🏷️  2 missing categories
   📦 140 total exports
3. SchemaRepresentation.ts
   📝 96 missing examples, 🏷️  12 missing categories
   📦 96 total exports
4. SchemaAST.ts
   📝 77 missing examples, 🏷️  21 missing categories
   📦 77 total exports
5. Channel.ts
   📝 79 missing examples, 🏷️  0 missing categories
   📦 150 total exports
6. Cause.ts
   📝 75 missing examples, 🏷️  2 missing categories
   📦 75 total exports
7. Option.ts
   📝 66 missing examples, 🏷️  3 missing categories
   📦 66 total exports
8. Sink.ts
   📝 64 missing examples, 🏷️  2 missing categories
   📦 81 total exports
9. SchemaTransformation.ts
   📝 37 missing examples, 🏷️  26 missing categories
   📦 37 total exports
10. Predicate.ts
   📝 57 missing examples, 🏷️  0 missing categories
   📦 57 total exports
11. SchemaGetter.ts
   📝 49 missing examples, 🏷️  0 missing categories
   📦 49 total exports
12. Result.ts
   📝 46 missing examples, 🏷️  0 missing categories
   📦 46 total exports
13. Config.ts
   📝 34 missing examples, 🏷️  5 missing categories
   📦 34 total exports
14. Types.ts
   📝 39 missing examples, 🏷️  0 missing categories
   📦 39 total exports
15. Effect.ts
   📝 31 missing examples, 🏷️  2 missing categories
   📦 256 total exports

✅ PERFECTLY DOCUMENTED FILES
-----------------------------------
   Chunk.ts (86 exports)
   Clock.ts (5 exports)
   FiberHandle.ts (15 exports)
   FiberMap.ts (19 exports)
   FiberSet.ts (14 exports)
   HKT.ts (4 exports)
   HashMap.ts (44 exports)
   HashSet.ts (21 exports)
   Latch.ts (3 exports)
   Match.ts (57 exports)
   MutableHashSet.ts (9 exports)
   MutableRef.ts (17 exports)
   NonEmptyIterable.ts (3 exports)
   Random.ts (9 exports)
   Redacted.ts (9 exports)
   RegExp.ts (3 exports)
   Symbol.ts (1 exports)
   Trie.ts (29 exports)
   TxChunk.ts (22 exports)
   TxDeferred.ts (7 exports)
   TxHashMap.ts (41 exports)
   TxHashSet.ts (24 exports)
   TxPriorityQueue.ts (19 exports)
   TxReentrantLock.ts (18 exports)
   TxRef.ts (7 exports)
   TxSemaphore.ts (14 exports)
   TxSubscriptionRef.ts (12 exports)
   Unify.ts (8 exports)
   index.ts (0 exports)

🔍 SAMPLE MISSING ITEMS FROM Schema.ts
-----------------------------------
   Optionality (type, line 64): missing example, category
   Mutability (type, line 71): missing example, category
   ConstructorDefault (type, line 78): missing example, category
   MakeOptions (interface, line 86): missing example, category
   Bottom (interface, line 110): missing example, category
   declareConstructor (interface, line 163): missing example, category
   declareConstructor (function, line 187): missing example
   declare (interface, line 211): missing example
   declare (function, line 220): missing example, category
   revealBottom (function, line 240): missing example, category

📋 BREAKDOWN BY EXPORT TYPE
-----------------------------------
const: 1069 missing examples, 130 missing categories
interface: 319 missing examples, 132 missing categories
type: 240 missing examples, 74 missing categories
function: 347 missing examples, 97 missing categories
namespace: 48 missing examples, 20 missing categories
class: 59 missing examples, 1 missing categories

📈 DOCUMENTATION PROGRESS
------------------------------
Examples: 2146/4228 (50.8% complete)
Categories: 3774/4228 (89.3% complete)

============================================================
Analysis complete! 2536 items need attention.
============================================================

📄 Detailed results saved to: jsdoc-analysis-results.json

This comment is automatically updated on each push. View the analysis script for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 4, 2026

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.33 KB 6.33 KB 0.00 KB (0.00%)
batching.ts 8.49 KB 8.49 KB 0.00 KB (0.00%)
brand.ts 6.29 KB 6.29 KB 0.00 KB (0.00%)
cache.ts 9.64 KB 9.64 KB 0.00 KB (0.00%)
config.ts 16.70 KB 16.70 KB 0.00 KB (0.00%)
differ.ts 15.06 KB 15.06 KB 0.00 KB (0.00%)
http-client.ts 19.09 KB 19.09 KB 0.00 KB (0.00%)
logger.ts 8.82 KB 8.82 KB 0.00 KB (0.00%)
metric.ts 8.19 KB 8.19 KB 0.00 KB (0.00%)
optic.ts 7.54 KB 7.54 KB 0.00 KB (0.00%)
pubsub.ts 13.32 KB 13.32 KB 0.00 KB (0.00%)
queue.ts 10.54 KB 10.54 KB 0.00 KB (0.00%)
schedule.ts 9.93 KB 9.93 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.35 KB 24.35 KB 0.00 KB (0.00%)
schema-string-transformation.ts 11.61 KB 11.61 KB 0.00 KB (0.00%)
schema-string.ts 9.91 KB 9.91 KB 0.00 KB (0.00%)
schema-template-literal.ts 12.52 KB 12.52 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 16.75 KB 16.75 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 19.43 KB 19.43 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 15.93 KB 15.93 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 15.90 KB 15.90 KB 0.00 KB (0.00%)
schema-toFormatter.ts 15.75 KB 15.75 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 18.18 KB 18.18 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 16.33 KB 16.33 KB 0.00 KB (0.00%)
schema.ts 15.39 KB 15.39 KB 0.00 KB (0.00%)
stm.ts 11.46 KB 11.46 KB 0.00 KB (0.00%)
stream.ts 8.73 KB 8.73 KB 0.00 KB (0.00%)

@IMax153 IMax153 requested a review from gcanti March 10, 2026 14:50
@gcanti
Copy link
Copy Markdown
Contributor

gcanti commented Mar 10, 2026

@IMax153 looks good to me, but it's still marked as draft, not sure whether it's just an oversight

@kitlangton ?

@kitlangton kitlangton marked this pull request as ready for review March 19, 2026 01:42
@kitlangton
Copy link
Copy Markdown
Contributor Author

kitlangton commented Mar 19, 2026

@IMax153 looks good to me, but it's still marked as draft. I'm not sure whether it's just an oversight.

@kitlangton?

Ah, sorry for not getting back to this. Yes, I kept it as a draft because I was somewhat dissatisfied with my own implementation. If I had not happened to implement this myself, I don't think I would have expected decodeResult to throw.

I don't know if there's any other sensible implementation (returning an... Option<Result> seems equally awful), but it crossed my mind that perhaps this is why this component was missing. 😄 But if it feels reasonable to you, I am more than happy!

@gcanti gcanti merged commit 65f7f57 into main Mar 19, 2026
15 checks passed
@gcanti gcanti deleted the kit/schema-result-combinators branch March 19, 2026 06:25
@gcanti
Copy link
Copy Markdown
Contributor

gcanti commented Mar 19, 2026

@kitlangton yes, it was missing because

  • I didn't need it for development and
  • I didn't like that it throws an error

however it already behaves this way in v3, so it makes sense to reintroduce it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants