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

未关闭
#268 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
57/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
12
派生
8
平均合并
9 小时 2 分钟
30 天内合并 PR
25

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

adobe/data 的其他 Issue

查看 adobe/data 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。