feat: initial server implementation#1
Open
cuibonobo wants to merge 15 commits into
Open
Conversation
…request-id version sensitivity
…d early 404 Replaces the brittle extension-scanning approach (detectMimeType + extToMime) with a direct DB query via the new optional StackAdapter.getAttachmentMeta method. When available this gives the exact MIME type stored at upload time and lets the GET handler return 404 before reading the binary payload.
… method is required
… deletion - MAX_ATTACHMENT_BYTES env var (default 50 MB); 413 on oversized uploads - POST reads filename from Content-Disposition header and passes to adapter - GET sets Content-Disposition response header when filename is stored - GET uses meta.size for Content-Length instead of reading buffer length - DELETE delegates file removal to adapter.deleteAttachment (no more manual scan) - attachmentRoutes no longer needs dbPath; takes maxAttachmentBytes instead
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 server implementation for the Haverstack stack spec (
docs/spec.mdinhaverstack/core).Stack
@hono/node-serverfor Node.js@haverstack/adapter-sqlite— SQLiteAdapter for storageEndpoints
All 24 endpoints from the spec plus
GET /health:GET /.well-known/stackGET /healthGET /records,POST /records/query,POST /records,GET /records/:id,PATCH /records/:id,DELETE /records/:idGET /records/:id/permissions,PUT /records/:id/permissionsGET /records/:id/associations,POST /records/:id/associations,DELETE /records/:id/associationsGET /records/:id/versions,GET /records/:id/versions/:version,POST /records/:id/restore/:versionGET /types,GET /types/:id,POST /typesPOST /attachments,GET /attachments/:fileId,DELETE /attachments/:fileIdGET /entity,PATCH /entityNotable implementation details
Auth —
AUTH_TOKENS=token:entityId,...env var; bearer token middleware maps token → entityId. Unauthenticated requests getnullauth and are subject to permission checks.Permission enforcement —
src/lib/access.tsimplements the full permission model: private (owner only),public,entity(direct entityId match), andgroup(walks_grouprecord'srelationshipassociations for member/admin).Version snapshotting — server calls
adapter.saveVersion()before everyPATCH, capturing the previous state.APIAdapter.saveVersion()is a no-op per spec; snapshotting is the server's responsibility.Attachments — content-addressed storage: file ID = SHA-256 of bytes. Uploading identical content twice returns the same
fileIdwithout writing a second copy.Content-Dispositionheader accepted on upload to store an original filename; returned on download if stored. Upload size limit viaMAX_ATTACHMENT_BYTES(default 50 MB).adapter.deleteAttachment()handles file removal so the route layer is clean.MIME types — stored verbatim at upload time and retrieved via
adapter.getAttachmentMeta(), avoiding any extension-mapping round-trip.Configuration
DB_PATHAUTH_TOKENStoken:entityIdpairs, comma-separated (required)ENTITY_IDPORT3000TIMEZONEUTCCORS_ORIGINS*BASE_URLMAX_ATTACHMENT_BYTES52428800Test plan
pnpm testpasses — integration tests cover all route groups using an in-process Hono app backed by a real SQLiteAdapter in a per-test temp directorypnpm typecheckpassesDB_PATH=./stack.db ENTITY_ID=test AUTH_TOKENS=tok:test pnpm devstarts andGET /healthreturns{ status: "ok" }GET /.well-known/stackreturns correct capabilitiesContent-Disposition, verify filename returned on downloadGenerated by Claude Code