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

Abierto
#268 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
57/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
12
Forks
8
Merge medio
9 h 2 min
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de adobe/data

Todos los issues de adobe/data

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.