feat(content-references): reference フィールドを参照先コンテンツへ展開するパッケージを追加 - #62
Closed
atsushifujikawa wants to merge 1 commit into
Closed
atsushifujikawa wants to merge 1 commit into
atsushifujikawa wants to merge 1 commit into
Conversation
…o referenced contents
xcms の配信 API は reference フィールドを参照先 ID のまま返す。参照先を展開する
ルール(未公開は null・multiple は配列から除外・1 階層のみ・失敗時は全体 reject)を
1 箇所に置き、管理画面・サイト生成・利用者のコードが同じ結果を得られるようにする。
- `buildCmsReferencePlan(fields)`: モデル定義から reference フィールドの plan を導出
- `resolveCmsReferences(items, plan, { fetchByIds })`: ID を収集・重複排除・`$in` 上限
50 でチャンク・同時実行数を制限して取得し、書き戻す。fetch は注入するので依存ゼロで
Node / ブラウザ両対応
- 解決ルールの正本は README
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lo53z71NvuSbRrZ82nW6eY
atsushifujikawa
requested review from
kujilab765 and
y-meguro
as code owners
September 11, 2026 13:03
Collaborator
Author
|
方針転換のためクローズします。depth 解決のロジックは obel の 理由:
設計の正本: plaidev/karte-io-systems#170508 の設計コメント(更新予定) |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
reference フィールドの参照先を展開するパッケージ
@craft-cross-cms/content-referencesを追加します。設計の経緯と Craft Studio 側の利用計画: plaidev/karte-io-systems#170508(設計コメント: https://github.com/plaidev/karte-io-systems/issues/170508#issuecomment-5633998193)の PR0 に相当します。
背景
xcms の配信 API は reference フィールドを参照先 ID(
multipleなら ID の配列)のまま返します。CDN API 自体にdepthを持たせるとフォーマット・asset 解決の再帰と client/server 契約が増えるため、CDN は薄いまま、「参照先をどう展開するか」のルールと実装を SDK パッケージとして 1 箇所に置き、管理画面・サイト生成(Craft Studio)・利用者のコードで共有します。内容
buildCmsReferencePlan(fields): 管理 API が返すモデル定義のfieldsから、reference フィールドの plan(field/refModel/multiple)を導出。refModelが無いフィールドは対象外resolveCmsReferences(items, plan, { fetchByIds, chunkSize?, concurrency? }): ID をモデルごとに収集・重複排除し、$in上限の 50 件ずつ・同時実行数 4 でfetchByIdsを呼び、参照先コンテンツを書き戻すnull(ID は残さない)multiple: 元の順序の配列。取得できない要素は落とす。null/ 未設定は[]fetchByIdsが throw したら全体 reject(部分結果を返すと「未公開」と区別できないため)rich-text-coreと同じ tsup の ESM / CJS dual ビルド検証
pnpm lint(eslint / knip / secretlint / prettier)、pnpm build、pnpm test(18 tests)すべて通過import) / CJS (require) の両方から読み込んで動作確認確認したい点
@craft-cross-cms/content-referencesで問題ないかmultipleで取得できない要素は落とす」(nullを残さない)で問題ないか🤖 Generated with Claude Code
https://claude.ai/code/session_01Lo53z71NvuSbRrZ82nW6eY