Skip to content

Include.Surface["included"] and the flat groups' included slot widen decoding services to unknown #595

Closed

Description

@thomasfosterau

Relayed from preferenceflow#382 phase 2, which is blocked on this. website and gardeneria are probably affected too.

What's wrong

Include.make(Resource, spec)'s included is Included<S>, the union of the member resources. When a member's relationships use lazyTarget (Relationship.many(lazyTarget(...))), that union's DecodingServices is unknown. The unknown then spreads:

  • Passed to Document.wire(…) or DataDocument({ included }), it carries unknown into every endpoint's success schema.
  • Group.flat / flatReadOnly do the same, because their included slot is WireSchema<Schema.Top, TM>.
  • As a result, typed Client.make methods require unknown services, and effect/cli commands fail Command<…, HttpClient | …> assignability.

Repro

preferenceflow at 64bb034:

  • Include.make(ElectionEvent, { elections: Include.nested(Election, { contests: Contest }) }) with lazyTarget back-references gives included["DecodingServices"] = unknown.
  • Building CollectionDocument(Document.wire(ElectionEvent, …), { included: Document.wire(surface.included, …) }) into a group gives 4 errors in apps/cli.

The app works around it with a Codec<…, never, never> cast.

Fix

  • Type Included<S> and the flat groups' slot over the members' concrete schemas, so the services stay never; or make lazyTarget's suspended target declare never services.
  • Add a type test: a Client.make method over a lazy-target include surface requires only HttpClient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions