Schema: add typed set and map types (ReadonlySet / ReadonlyMap)

Aperta
#268 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
57/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with ecs/packages/ecs/src/interface/schema/schema.ts, the existing reference implementation mentioned in the issue, then trace this repository’s Schema, schemaTypes, Schema.ToType, toTypeScript, validation, and createCoerceFunction entry points. Add typed set and map support across those areas and pin the inferred types with type tests. Done means values validate and coerce their typed elements, render as ReadonlySet<T> and ReadonlyMap<K, V>, and round-trip through Data.stringify and Data.parse.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

Data includes ReadonlySet<Data> and ReadonlyMap<Data, Data>, and Data.stringify / Data.parse round-trip both, but Schema has no way to describe either with typed elements.

  • type accepts number | integer | string | boolean | null | array | object | typed-buffer | blob | observe | promise | generator | function. There's no set or map.
  • The only escape hatch is typeName: Schema.ToType<{ typeName: 'Set' }> is ReadonlySet<any>, which loses the element type. toTypeScript renders it as a bare Set. { typeName: 'ReadonlySet' } resolves to any, because ReadonlySet isn't a runtime global.
  • uniqueItems on an array doesn't map to a set either.

So a schema-described value that's naturally a set, such as an observable set of ids exposed to an agent, has to be modeled as an array.

Proposal

Port the set and map forms that @adobe/ecs already has (ecs/packages/ecs/src/interface/schema/schema.ts):

{ type: 'set', items: S }                 // ToType → ReadonlySet<ToType<S>>
{ type: 'map', keys: K, values: V }       // ToType → ReadonlyMap<ToType<K>, ToType<V>>

Covering:

  • Schema / schemaTypes: add set and map.
  • Schema.ToType: map them to ReadonlySet / ReadonlyMap with typed elements.
  • toTypeScript: render ReadonlySet<T> / ReadonlyMap<K, V>.
  • Validation and createCoerceFunction: check elements against items, and keys / values.
  • Type-tests pinning ToType for both, plus a round-trip test through Data.stringify / Data.parse.

Motivation

Firefly Platform's agentic surface types (Agentic.State<S> derives its value type from Schema.ToType<S>) need an Observe<ReadonlySet<AppId>> state. Until this lands it uses ReadonlyArray<AppId>.

Lingua principale
TypeScript
Stelle
12
Fork
8
Merge medio
9h 2m
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di adobe/data

Tutte le issue di adobe/data

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.