Tags: zio/zio-blocks
Tags
Misc fixes related to JSON schemas and syntax (#1049) * Shrink too long error messages when validating enums * Fix JSON schemas for some primitive values * Memorize JSON schema values for derived codecs to avoid recalculations * Fix regex patterns for "date-time" and "time" JSON schema types * Test cleanup * Fix runtime overhead for `toJson...` and `fromJson...` syntax * Formatting * Fix surrogate char filtering in tests
Filter common base types from TypeDefKind to reduce generated bytecode ( #1000) * Filter common base types from TypeDefKind to reduce generated bytecode Exclude Product, Equals, Serializable, Mirror.*, and Mirror.Sum from the base types list in TypeDefKind. These standard library types are automatically synthesized and generate substantial bytecode in macro expansions, contributing to "Method Too Large" errors for complex ADTs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fmt * Add tests + fix --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
fix(schema): restore structural type derivation support for Scala 3 (#… …962) * fix(schema): restore structural type derivation support for Scala 3 Restores structural type schema derivation that was accidentally removed in PR #800 (TypeId migration). Pure structural types like { def name: String } can now derive schemas again. Changes: - Added isStructuralType() - detects refinement types - Added getStructuralMembers() - extracts field names and types - Added structuralFieldOffset() - calculates register offsets - Added deriveSchemaForStructuralType() - entry point with JVM reflection check - Added deriveSchemaForPureStructuralType() - full schema generation - Added structural type branch in deriveSchema() before isNonAbstractScalaClass - Enabled PureStructuralTypeSpec tests (4 tests) Structural types require JVM reflection for deconstruction via getMethod/invoke. * feat(schema): add Scala 2 structural type support - Add RefinedType handling to Scala 2 TypeIdMacros for structural types - Add structural type schema derivation to Scala 2 SchemaCompanionVersionSpecific - Add 4 structural type tests mirroring Scala 3 PureStructuralTypeSpec This restores structural type derivation for Scala 2, which was missing after the TypeId migration in PR #800. * Fix merging error --------- Co-authored-by: Andriy Plokhotnyuk <plokhotnyuk@gmail.com>
Clean up Json.scala API for consistency and simplicity (#841) * Clean up Json.scala API for consistency and simplicity API changes: - Rename apply(index) to get(index) for consistency with get(key) - Rename encode → print, encodeToBytes → printBytes, encodeToChunk → printChunk - Remove decode alias (use parse instead) - Change Array.value, fields, elements return types from Vector to Chunk - Delete shorthand constructors (str, number, bool, obj, arr) - use case classes directly - Make jsonCodec implicit in Json companion - Add toBigDecimalOption to Json.Number - Consolidate MergeStrategy (Auto/Deep/Concat handled by default case) - Make Json.toDynamicValue private (instance method still available) Test updates: - Update all test files to use new API patterns - Replace Vector comparisons with Chunk for elements/fields * refactor(json): Redesign MergeStrategy for consistency and simplicity - Create JsonType.scala with sealed trait representing JSON value types - Add Json#jsonType to all Json subtypes (Object, Array, String, Number, Boolean, Null) - Refactor MergeStrategy to extend (DynamicOptic, Json, Json) => Json - Add recurse(path, jsonType) method for recursion control decisions - Remove redundant MergeStrategy.Deep (now covered by Auto) - Reimplement MergeStrategy.Concat to recurse only into objects - Replace merge implementation with symmetric mergeByKey/mergeByIndex approach BREAKING CHANGE: Arrays now merge by index with Auto strategy (right wins on shared indices, union of indices preserved). Use MergeStrategy.Concat for the previous concatenation behavior. Closes #841 * Unify Json type operations with path-dependent types Add type members to JsonType for compile-time type safety: - type Type <: Json: maps to corresponding Json subtype - type Unwrap: maps to underlying Scala value type Make JsonType extend (Json => Boolean) so it can be used directly as a predicate for filtering operations. Add unified methods to Json trait: - is(jsonType): Boolean - type testing - as(jsonType): Option[jsonType.Type] - type narrowing - unwrap(jsonType): Option[jsonType.Unwrap] - value extraction Refactor query methods: - query(Json => Boolean) - filter by value predicate - queryPath(DynamicOptic => Boolean) - filter by path predicate - queryBoth((DynamicOptic, Json) => Boolean) - filter by both Remove redundant type-specific methods: - isObject, isArray, isString, isNumber, isBoolean, isNull - asObject, asArray, asString, asNumber, asBoolean, asNull - stringValue, numberValue, booleanValue Update JsonSelection to use JsonType predicates for filtering. Update all tests and documentation. Amp-Thread-ID: https://ampcode.com/threads/T-019bf62a-58e0-7598-8bdc-4e2a1084811d Co-authored-by: Amp <amp@ampcode.com> * Add comprehensive tests for unified Json type operations Add tests for: - JsonType.apply as predicate function (Json => Boolean) - query(Json => Boolean) with JsonType and custom predicates - queryPath(DynamicOptic => Boolean) for path-based filtering - queryBoth((DynamicOptic, Json) => Boolean) combining predicates - Complete unwrap coverage for all JsonType cases Ensures full coverage of new path-dependent type methods. Amp-Thread-ID: https://ampcode.com/threads/T-019bf62a-58e0-7598-8bdc-4e2a1084811d Co-authored-by: Amp <amp@ampcode.com> * refactor(json): unify selection/query API with select, prune, retain * Add partition/partitionPath/partitionBoth for API consistency Align partition with the prune/retain/query trio pattern: - partition(p: Json => Boolean) - value-only predicate - partitionPath(p: DynamicOptic => Boolean) - path-only predicate - partitionBoth(p: (DynamicOptic, Json) => Boolean) - both path and value This makes partition consistent with prune, retain, and query which all follow the foo/fooPath/fooBoth naming convention. * Add fluent API methods to JsonSelection Implement convenience methods on JsonSelection that delegate to underlying Json methods, enabling fluent chaining without manual map(_.method) calls. Unary methods (infallible): - Normalization: sortKeys, dropNulls, dropEmpty, normalize - Path ops: modify, set, delete, insert - Transformation: transformUp, transformDown, transformKeys - Pruning: prune, prunePath, pruneBoth - Retention: retain, retainPath, retainBoth - Projection: project Binary method: - merge(that, strategy): cartesian product semantics (N × M results) Fallible mutation methods: - modifyOrFail, setOrFail, deleteOrFail, insertOrFail Type-directed extraction: - as(jsonType), asAll(jsonType): narrow to specific JSON types - unwrap(jsonType), unwrapAll(jsonType): extract underlying Scala values Add comprehensive tests in JsonSelectionSpec covering all new methods. --------- Co-authored-by: Amp <amp@ampcode.com>
PreviousNext