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

Offen
#268 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
57/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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>.

Vorherrschende Sprache
TypeScript
Sterne
12
Forks
8
Ø Merge
9 Std. 2 Min.
Gemergte PRs (30 T.)
25

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus adobe/data

Alle Issues in adobe/data

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.