@nodii/contract-manifest
v0.2.0
Published
A service's list of the routes, RPCs, topics and workers it actually registers: built at runtime, hashed the same in TypeScript, Go and Python, and published to Dev.
Readme
@nodii/contract-manifest
A service's list of the routes, RPCs, topics and workers it actually registers
(LIB-CON-5, S07-50). The service builds it at boot from the same objects that
serve traffic, serves it at GET /.well-known/nodii-contracts and publishes it
to Dev. Ships in TypeScript, Go (nodii.co/nodii-libs/go/contract-manifest) and
Python (nodii-contract-manifest). All three produce identical bytes and an
identical hash, proved by synthetic-consumers/contract-manifest.
Use
import {
buildManifest,
manifestResponse,
publishManifest,
routesFromHono,
rpcsFromServiceDefinition,
topicsFromReplicas,
WELL_KNOWN_PATH,
workersFromSpecs,
} from "@nodii/contract-manifest";
const manifest = buildManifest({
service: "nodii-crm",
serviceVersion: version,
routes: routesFromHono(app),
rpcs: rpcsFromServiceDefinition(LeadService.service, REQUIRED_SCOPES_BY_METHOD),
topicsProduced: PRODUCED_TOPICS,
topicsConsumed: topicsFromReplicas(replicas),
workers: workersFromSpecs(workerSpecs),
});
app.get(WELL_KNOWN_PATH, () => {
const { body, status, headers } = manifestResponse(manifest);
return new Response(body, { status, headers });
});
// After boot. Dev being down must not stop a service from booting.
publishManifest(manifest, { baseUrl, headers }).catch((error) => logger.warn(error));What each list comes from
| List | TypeScript | Go | Python |
|---|---|---|---|
| Routes | routesFromHono(app) | RecordingMux.Routes() | routes_from_asgi(app) |
| RPCs | rpcsFromServiceDefinition(def, scopes) | RPCsFromServer(server, scopes) | rpcs_from_descriptors(descriptors, scopes) |
| Consumed topics | topicsFromReplicas(replicas) | pass the list | topics_from_replicas(replicas) |
| Workers | workersFromSpecs(specs) | pass the list | workers_from_specs(specs) |
| Produced topics | pass the list | pass the list | pass the list |
Produced topics are passed in because a dispatcher's streamFor is a function
and cannot list them. Pass the constant the service's outbox writes use.
Limits
routesFromHonoskips methodALL, because Hono recordsapp.usemiddleware under it. Anapp.allroute is therefore not listed. A manifest must under-claim rather than claim a route the service does not serve.- An RPC's
requiredScopeis null when the method has no bound scope. The server denies that method (LIB-AUTH-13), so a null in a manifest is worth looking at. - Every value must be printable ASCII without
"or\. That is the range all three JSON encoders write identically, and it is what keeps the hash equal. - Credentials for Dev come from the caller. The library reads no environment variable.
