feat: rename evidence to attachments and update schema#121
Conversation
🦋 Changeset detectedLatest commit: 0d250f3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughRenames "evidence" to "attachment" across sdk-core: APIs, types, lexicons, repository implementations, emitted events, schema/examples, and tests; adds CreateAttachmentParams and addAttachment(), removes legacy evidence exports, and normalizes subjects/content to array forms. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant HypercertOps as HypercertOperationsImpl
participant ATProto as ATProto/Storage
participant Events as EventEmitter
Client->>HypercertOps: addAttachment(CreateAttachmentParams)
HypercertOps->>HypercertOps: resolveAttachmentSubjects()
HypercertOps->>HypercertOps: resolveAttachmentContent()
HypercertOps->>HypercertOps: buildAttachmentRecord()
HypercertOps->>ATProto: create record in ATTACHMENT collection
ATProto-->>HypercertOps: record URI + CID
HypercertOps->>Events: emit attachmentAdded {uri, cid}
HypercertOps-->>Client: Promise<UpdateResult> (attachmentUris)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.changeset/evidence-to-attachment-rename.md:
- Around line 5-13: Update the changeset text to explicitly document
schema-level breaking changes in addition to the API renames: state that subject
fields were renamed/removed and content fields were changed/removed (list the
exact fields affected), and show how existing payloads map to the new attachment
schema (e.g., which subject/content properties were removed or renamed). Also
call out the exact symbol renames (addEvidence → addAttachment,
CreateHypercertEvidenceParams → CreateAttachmentParams, evidenceUris →
attachmentUris, evidenceAdded → attachmentAdded) and add a compatibility note
that for pre-1.0 versions minor bumps may introduce breaking changes so
consumers should audit payloads and update code accordingly.
🧹 Nitpick comments (2)
packages/sdk-core/src/repository/HypercertOperationsImpl.ts (2)
481-507: Avoid extra subject lookups when creating attachments during create().
You already have the hypercert CID, so passing a StrongRef avoids redundantgetRecordcalls and reduces failure points.♻️ Suggested refactor
- private async createAttachmentsWithProgress( - hypercertUri: string, + private async createAttachmentsWithProgress( + hypercertRef: StrongRef, attachmentItems: Array<Omit<CreateAttachmentParams, "subjects">>, onProgress?: (step: ProgressStep) => void, ): Promise<string[]> { @@ - this.addAttachment({ - ...attachment, - subjects: hypercertUri, - } as CreateAttachmentParams).then((result) => result.uri), + this.addAttachment({ + ...attachment, + subjects: hypercertRef, + } as CreateAttachmentParams).then((result) => result.uri), @@ - result.attachmentUris = await this.createAttachmentsWithProgress( - hypercertUri, - params.attachments, - params.onProgress, - ); + const hypercertRef: StrongRef = { + $type: "com.atproto.repo.strongRef", + uri: hypercertUri, + cid: hypercertCid, + }; + result.attachmentUris = await this.createAttachmentsWithProgress( + hypercertRef, + params.attachments, + params.onProgress, + );Also applies to: 624-632
1207-1218: Guard against empty subjects/content arrays for clearer validation.
!contentInputwon’t catch[], and empty subjects/content should fail fast with a deterministic ValidationError.✅ Suggested guard rails
- if (!contentInput) { - throw new ValidationError("content is required for attachments"); - } + if (!contentInput || (Array.isArray(contentInput) && contentInput.length === 0)) { + throw new ValidationError("content is required for attachments"); + } + if (!subjectsInput || (Array.isArray(subjectsInput) && subjectsInput.length === 0)) { + throw new ValidationError("subjects is required for attachments"); + }
e4f585f to
49b9895
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/sdk-core/src/repository/HypercertOperationsImpl.ts (1)
556-573: Update the create() example to usecontent.
The example still shows the oldurifield, which is no longer valid for attachments.✍️ Suggested doc fix
- attachments: [{ uri: "https://...", description: "Satellite data" }], + attachments: [{ content: "https://...", description: "Satellite data" }],
🤖 Fix all issues with AI agents
In @.changeset/evidence-to-attachment-rename.md:
- Around line 17-52: Update the example payload so it matches the new schema:
make "subjects" an array of StrongRefs (not a single string), make "content" an
array of URI/Blob refs (not a single string), and fix the JSON syntax by adding
the missing comma after the "title" field; ensure the example uses the exact
field names "subjects" and "content" to reflect the schema change.
In `@packages/sdk-core/src/repository/HypercertOperationsImpl.ts`:
- Around line 1108-1167: The buildAttachmentRecord currently unconditionally
overwrites $type and createdAt; change it to preserve caller-supplied values by
computing local defaults and only filling when missing (e.g. const type = (rest
as Partial<CreateAttachmentParams>).$type ?? HYPERCERT_COLLECTIONS.ATTACHMENT;
const createdAt = (rest as Partial<CreateAttachmentParams>).createdAt ?? new
Date().toISOString()), then include those computed values in the returned object
instead of hardcoding; also ensure CreateAttachmentParams declares $type and
createdAt as optional so callers can pass them through.
49b9895 to
0d250f3
Compare
Summary
Rename evidence records to attachments throughout the SDK to match lexicon updates in beta.13.
Breaking Changes:
addEvidence()→addAttachment()CreateHypercertEvidenceParams→CreateAttachmentParamsevidenceUris→attachmentUrisin create resultsevidenceAdded→attachmentAddedeventKey Updates:
subjects(array) instead ofsubject(single)contentis now required and accepts arraysrelationType,contributors,locationsThis aligns the SDK with the latest lexicon definitions and prepares for the beta.13 release.
Summary by CodeRabbit
Breaking Changes
New Types
Tests & Docs
✏️ Tip: You can customize this high-level summary in your review settings.