~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.17.0 Latest 2 packages, 1 image

1
10

knotless-serve answers npm's registry for a repository's packages

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:serve/npm

knotless-serve now answers npm's registry protocol for each repository's releases, the same way it answers Cargo's. npm login (your handle and an app password), npm publish, npm install, npm view and npm search work, and npm deprecate yanks a version. Worth a look: the npm object this adds to dev.knotless.release, since a lexicon can only grow once published.

Claude Opus 5.5 · high

What changes

knotless-serve serves an npm registry for each repository at /npm/<did>/<repo key>/. A scope is pointed at it with @scope:registry= in .npmrc. It answers the packument (each version's manifest, dist.tarball pointing back here, deprecated on a yanked version, and dist-tags.latest worked out from the versions there are), tarball downloads, npm publish, npm deprecate and taking it back with "", legacy npm login, whoami, ping, dist-tag ls and search. npm unpublish, npm dist-tag add and --provenance are refused, each with its reason. A web login answers 404, so plain npm login asks for a handle and a password and needs no flag.

A release gains an optional npm object: its manifest, the version's manifest as npm publish sent it, without its readme or dist.tarball. A publish checks the manifest's dist.integrity (SHA-512) and dist.shasum (SHA-1) against the tarball, and that package/package.json names the same package and version. So the hash npm checks an install against is signed in the owner's account beside the file's SHA-256. The file is <name without scope>-<version>.tgz.

What the two registries share is moved out of web/cargo.rs into web/registry.rs: opening the repository by what the index has, logging in by <handle>:<app password>, reading a file out of a gzipped tar, an answer sent no-cache with an ETag, sending a release's file, and putting a publish or a yank in the index at once. Each registry still writes refusals in its own error format. release::latest_of finds the latest of one package's releases without copying them.

docs/design/packages.md has a new npm packages section, and npm protocol is gone from its Not yet list. docs/reference/api.md lists the routes. There is a change file.

Why

Package names were kept to npm's rules so that npm's protocol could be served from the same records, and it was the next item in packages.md's Not yet list. It follows the Cargo registry's choices, for the same reasons. The address holds a DID and a repository key, as lockfiles keep each tarball's URL. Its manifest is npm's own JSON, kept in the record. What it reads is what the index has, so a takedown holds.

  • One registry per repository, as for crates: two repositories can publish the same name, and a publish would not say which one it is for.
  • No fallback to registry.npmjs.org. Passing unknown names on would let anyone publish a name a repository here depends on and have it installed in its place. A scope is pointed at the repository's registry. An unscoped package publishes, but installing one means naming this registry for every unscoped name, so the docs recommend scoped names.
  • Legacy login only. A web login would need serve to keep a session for each token. npm falls back to legacy login by itself, so plain npm login works.

How it was checked

an_npm_registry runs real npm against a served registry and the PDS:

  • the login exchange, whoami and ping
  • publishing a scoped package, an unscoped one, and one that depends on both, then installing it from nothing kept and running it
  • a pre-release published under a tag, which does not become the latest
  • dist-tag ls, and the refused dist-tag add and unpublish
  • deprecate and taking it back, checked against the yank record and with npm ci from nothing kept
  • search
  • every refusal npm would not send itself, and a repository that is not there

Unit tests cover the packument, tarball names, what a publish keeps, and a file found in a tarball. All seven checks passed at 39d65c61.

Shortcomings

npm login itself is not run, since it reads from a terminal. The test sends the same PUT -/user/org.couchdb.user:<name> instead.

As with crates: public repositories only; no commit or check on a release made this way; and an app password, which can do far more than publish, sits in .npmrc in plain text. Deprecation messages are not kept: a yanked version reads yanked by its owner. A package name with ~ can't publish, since its tarball name would not be a release file's name.

The releases page does not show how to install an npm package yet. That comes in the next pull of this stack.

Review

The lexicon first, then crates/knotless-serve/src/web/npm.rs's kept and Writing::publish.

Approved

This adds an npm registry to knotless-serve at /npm/<did>/<repo key>/, built on the same release records as the Cargo one. It adds an optional npm.manifest object to dev.knotless.release. The code shared with Cargo moves into web/registry.rs, and the docs and a change file are included. All seven checks pass at 39d65c61. I read the lexicon, npm.rs, registry.rs, the cargo.rs refactor, the records and release changes, and the routes. I did not read tests/web.rs or the docs diffs; the passing checks cover them.

  • Lexicon: The npm object is a single required manifest string, kept as npm's own JSON. Optional fields can be added later, so the shape leaves room to grow. kept limits the manifest to 100,000 bytes, and the lexicon's maxLength counts bytes too, so the two agree.
  • kept and publish:
    • A publish checks the name and version in the manifest.
    • It checks dist.integrity and dist.shasum against the tarball.
    • It checks that package/package.json names the same package and version.
    • It strips readme, deprecated and dist.tarball before keeping the manifest.
    • Only the repository owner, logged in with an app password, can write.
    • A tarball read from the PDS can't be swapped for different bytes, because the stored SHA-256 and the signed SHA-512 and SHA-1 all pin it.
  • Refactor: The cargo.rs refactor keeps its behavior. The new file_in matches the same <dir>/<name> shape as the old manifest_of, and its test covers the case where the file is missing, is too large, has a bad header size or isn't gzip.
  • Routes: Static routes such as -/ping and -/user/{user} don't clash with {name}/-/{file}, and the real-npm test passes through them.

I left no line comments.

Merged as e293763