fix(core): split updateRecord into intent-revealing adapter operations#81
Merged
Conversation
StackRecordAdapter.updateRecord() was a grab-bag: Stack funneled content patches, permission replacement, version restore, and migration commits through one Partial<StackRecord> method, and the API adapter forwarded whatever it was given straight into a content-only PATCH body — corrupting record fields into content on a spec-conforming server, and silently breaking null-deletion, setPermissions(), restoreVersion(), and migrateAll() over the wire. associate(), dissociate(), delete(), and undelete() carried the same bug via a trailing updateRecord() call used only to bump version/updatedAt. Replace updateRecord() with patchContent(), setPermissions(), restoreVersion(), and commitMigration() — each maps 1:1 to its own wire endpoint (PATCH /records/:id, PUT .../permissions, POST .../restore/:version, new POST .../migrate) and bumps version internally, so no mutation needs a second round-trip through a different intent's endpoint. Content merging now uses a shared RFC 7396 helper (applyMergePatch) so local adapters and Stack's validation merge identically. Updates StackRecordAdapter, Stack, combineAdapters, MemoryAdapter, APIAdapter, SQLiteRecordAdapter, and LocalAdapter accordingly, plus spec docs for the new /migrate endpoint and the permissions envelope. Refs #52. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KjkNN8wW5Abm5pEDVkKHM
The new patchContent() implementation added a real (value) import of applyMergePatch from @haverstack/core — the package's first runtime dependency on core's build output. Without a build step, vite couldn't resolve it, so CI's test job (which runs before build) failed with "Failed to resolve entry for package @haverstack/core". Add the same src-aliasing vitest.config.ts already used by adapter-api and adapter-local. feat(conformance-fixtures): add shared wire-protocol fixtures Adds @haverstack/conformance-fixtures: request/response pairs for every record-mutation endpoint (create, patchContent, delete/undelete, associate/dissociate, setPermissions, restoreVersion, commitMigration), pinning down the wire shapes #52 fixes — in particular that PATCH /records/:id carries a content-only patch, never record fields. The package is pure data with no test-framework dependency, so it can be imported by both this repo and a server implementation's test suite. adapter-api's new tests/conformance.test.ts drives APIAdapter through every fixture; haverstack/server can drive its own handlers through the same fixtures separately. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KjkNN8wW5Abm5pEDVkKHM
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.
Summary
StackRecordAdapter.updateRecord()was a grab-bag:Stackfunneled content patches, permission replacement, version restore, and migration commits through onePartial<StackRecord>method, andAPIAdapterforwarded whatever it was given straight into a content-onlyPATCHbody — corrupting record fields (typeId,version,updatedAt) into content on a spec-conforming server, and silently breakingnull-deletion,setPermissions(),restoreVersion(), andmigrateAll()over the wire.associate(),dissociate(),delete(), andundelete()carried the same bug via a trailingupdateRecord()call used only to bumpversion/updatedAt.updateRecord()withpatchContent(),setPermissions(),restoreVersion(), andcommitMigration()onStackRecordAdapter— each maps 1:1 to its own wire endpoint (PATCH /records/:id,PUT /records/:id/permissions,POST /records/:id/restore/:version, newPOST /records/:id/migrate) and bumpsversioninternally, so no mutation needs a second round-trip through a different intent's endpoint.applyMergePatch) soStack's client-side validation merge and every adapter'spatchContent()implementation produce identical results.Stack,combineAdapters,MemoryAdapter(core),APIAdapter(adapter-api),SQLiteRecordAdapter(record-adapter-sqljs), andLocalAdapter(adapter-local) to the new contract.docs/spec.md: documents the new/migrateendpoint and the permissions request/response envelope ({ "permissions": [...] }).Closes #52.
Test plan
pnpm -r build— all packages buildpnpm -r typecheck— clean across all 6 packagespnpm -r lint— cleanpnpm -r test— all existing tests pass unchanged (258 core, 76 sqljs, 57 adapter-api, 17 adapter-local, 12 blob-adapter-disk), plus new coverage added forpatchContent,setPermissions,restoreVersion,commitMigration, and version-bump-on-mutation forassociate/dissociateGenerated by Claude Code