Skip to content

Agent-facing service schemas (external on any schema, toTypeScript audience, AsyncDataService.toObserveState) + defaultFactory Store<any> fix - #214

Merged
krisnye merged 5 commits into
mainfrom
krisnye/data-service-to-state
Oct 9, 2026
Merged

krisnye merged 5 commits into
mainfrom
krisnye/data-service-to-state

Conversation

@krisnye

@krisnye krisnye commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Agent-facing service schemas

  • Schema-level external (Schema.external) — the { agent?, link? } exposure policy now lives on the member schema itself and is valid on any schema (actions, states, nested groups). BREAKING: signature.external is removed — move it up one level onto the function schema.
  • toTypeScript(schema, name, { audience }) — audience defaults to "agent", omitting every property (at any depth) whose policy hides it from that channel, so external: { agent: false } members are never documented to an agent. "link" keeps only link: true members; "all" emits everything.
  • AsyncDataService.toObserveState(service) — walks the service's schema (through nested groups), observes every observe member in parallel via Observe.fromProperties, and emits one object with the service's nested shape (state.foo.state.b). Typed as AsyncDataService.State<T>: Observe<X> → X, actions and action-only groups omitted, optional members stay optional. Re-derives the member set when service.schema changes. Does not filter by external.

defaultFactory type collapse fix

A defaultFactory store was not assignable to Store<any, any, any>: relating Archetype.insert's generic <T>(row: Exact<V, T>) signature to an any-row archetype infers T = any, and Exact<V, any> collapsed to never. So a single Store<any, any, any>-typed transaction member (e.g. the library's own applyOperations) was rejected, erasing every transaction on its plugin, and Store.Resources / Store.Archetypes of such a store silently evaluated to never. Exact now passes any through (excess-property rejection on real inserts is unchanged).

Verified against the standalone 30-probe consumer repro: on 0.10.13 the bomb configs give 8 errors and 6/30 probes fail; against this branch the bomb gives 0 errors and 29/30 pass. The remaining line (p29 §5, mutable Store → ReadonlyStore<any, any, any>) also fails for a plain store and predates defaultFactory — out of scope here.

Version bump to 0.10.26.

Test plan

  • resolve-external-invocation.test.ts — schema-level policy on function and non-function members
  • to-typescript.test.ts — agent (default) / link / all audiences, nested hiding, hoisting reacts to hidden members
  • to-observe-state.test.ts — nested reconstruction, dotted keys, waits for all values, re-emit on change, unobserve, missing optional members, schema change releases old subscriptions; State<T> type assertion
  • default-factory.test.ts — compile-time regressions (fail without the fix): applyOperations + DFK plugin keeps transactions, DFK store → Store<any, any, any>, Store.Archetypes/Resources not never
  • Clean monorepo pnpm -r run typecheck, pnpm -r run test, pnpm run lint

🤖 Generated with Claude Code

krisnye and others added 4 commits October 7, 2026 13:03
…ence filter, AsyncDataService.toState

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…signable to Store<any, any, any>

Relating Archetype.insert's generic Exact signature to an any-row archetype
infers U = any, and Exact<T, any> collapsed to never. A defaultFactory store
was therefore not assignable to Store<any, any, any>, so a single such
transaction member (e.g. applyOperations) erased every transaction on its
plugin and Store.Resources/Archetypes of that store evaluated to never.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@krisnye krisnye changed the title Agent-facing service schemas (external on any schema, toTypeScript audience, AsyncDataService.toState) + defaultFactory Store<any> fix Agent-facing service schemas (external on any schema, toTypeScript audience, AsyncDataService.toObserveState) + defaultFactory Store<any> fix Oct 8, 2026
… schema

Removes the deprecated signature.external fallback and inlines the policy
shape on Schema.external instead of exporting a separate External type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@krisnye
krisnye merged commit 55c21bb into main Oct 9, 2026
3 checks passed
@krisnye
krisnye deleted the krisnye/data-service-to-state branch October 9, 2026 17:32
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.

1 participant