dol.content: ContentRef + flat content-addressed storage (blob layer) - #79
Merged
Conversation
…yer) The "content half" of the content-metadata bifurcation (see misc/docs/dol_content_metadata_bifurcation.md): a flat bytes store plus a small serializable ContentRef token that stands in for the bytes inside a record. - ContentRef: frozen dataclass; to_json/from_json emit the camelCase wire shape (_tag/itemId/mimeType) matching the zodal TypeScript ContentRef, so refs cross the Python<->JS boundary unchanged. is_content_ref predicate. - put_content (location-addressed) / add_content (content-addressed, idempotent CAS) / get_content / delete_content — all over an INJECTED MutableMapping backend (dict in tests, dol.Files locally, s3dol in the cloud). - ContentAddressedStore / with_content_addressing: CAS facade; add(data)->ContentRef mints the hash key; direct __setitem__ guards the key==hash invariant. - url_for seam (SupportsUrlFor Protocol + content_url): reads can redirect to a CDN/presigned/static URL while writes stay on the backend. URLs resolved ON DEMAND, never baked into a (persisted) ref — a backend's url_for may mint an expiring presigned URL. All S3/presigning knowledge stays in s3dol; dol.content is pure stdlib (dataclasses/hashlib/mimetypes), zero new dependencies. CAS-by-hash is a capability zodal explicitly defers to an opt-in wrapper, so this puts the Python side slightly ahead while staying contract-compatible. 11 doctests + 17 unit tests; full dol suite green. Claude-Session: https://claude.ai/code/session_01Gw5RPgrQhC88Hc3DyACYWF
This was referenced Aug 1, 2026
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.
Closes #78.
Adds
dol.content— the content half of the content–metadata bifurcation: a flat bytes store plus a small serializableContentRefthat stands in for the bytes inside a record. Pure stdlib, zero new dependencies.API
ContentRef— frozen dataclass (item_id,field,hash?,url?,mime_type?,size?);to_json/from_json;is_content_ref.put_content(location-addressed) /add_content(content-addressed, idempotent CAS) /get_content/delete_content— over an injectedMutableMappingbackend.ContentAddressedStore/with_content_addressing— CAS facade:store.add(bytes) -> ContentRef.SupportsUrlForProtocol +content_url— the URL seam.Design rationales worth noting
put_content/add_contentleaveContentRef.urlempty;content_url(store, ref)resolves it when needed (preferring a url the ref already carries, else the backend'surl_for). Reason: a backend'surl_formay mint a presigned, expiring URL (S3), and aContentRefis designed to be persisted inside a record — freezing an expiring URL into it would be a latent bug. This mirrors zodal's "getUrl on demand is preferred."dolentirely. The only cloud-aware bit — presigned-URL minting — is reached through the duck-typedurl_forseam (SupportsUrlFor).dol.contentimports nothing beyonddataclasses/hashlib/mimetypes; the S3url_forimplementation belongs ins3dol.dict. Every function/store takes the backend as a parameter (dictin tests →Fileslocally →s3dolin the cloud), per dol convention — no backend is imported here.ContentAddressedStore.__setitem__rejects a key that isn't the content hash of the value (raise, don't silently corrupt); minting goes through.add().ContentRef.to_json()emits the camelCase{_tag, itemId, mimeType, …}shape, byte-identical to zodal'sContentRef, so a reference crosses the Python↔JS boundary unchanged.with_content_addressing) puts the Python side slightly ahead while staying contract-compatible. Truncated hashes (length=) document the collision tradeoff.Scope
The record/metadata half (a queryable
DataProvider-style facade + bifurcated composition) is intentionally out of scope — a separate follow-up.Tests
11 doctests + 17 unit tests (
dol/tests/test_content.py); full dol suite green (188 passed, 3 skipped).https://claude.ai/code/session_01Gw5RPgrQhC88Hc3DyACYWF