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

オープン
#268 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

adobe/data のほかの issue

adobe/data の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。