everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
52 lines (50 loc) • 2.79 kB
JavaScript
import { fetchRegistryKey } from "./fastkv.mjs";
//#region src/services/registry/pointer.ts
/**
* The release-pointer plane's pre-cutover wire (sprint registry-primitive,
* ticket 05). The key model (keys.ts) speaks the post-cutover wire —
* `manifest.json`, `versions/<v>.json`, `deploys/<ts>.json` — but the train
* still writes and the rollback still reads the old keys. Until ticket 10's
* cutover, THIS file is the only place the old wire keys are derived; every
* consumer derives them through here so the flip is one file.
*
* TODO(cutover): delete the templates below and re-point the helpers onto
* keyPathOf({ kind: "manifest" | "version" | "deployRecord", ... }).
*/
/** The pointer key relative to `apps/<account>/<gateway>/` — the form
* `fetchRegistryKey` takes (it wraps with the runtime prefix) and the form
* the history endpoint's `keyPath` parameter takes. The full-key helpers
* below are derived from these — one derivation per wire key, so ticket 10's
* cutover flips this file and nothing else. */
const PLATFORM_POINTER_REL_KEY = "platform.json";
function platformVersionSlotRelKeyOf(version) {
return `platform-versions/${version}.json`;
}
function platformPointerKeyOf(accountId, gatewayId) {
return `apps/${accountId}/${gatewayId}/${PLATFORM_POINTER_REL_KEY}`;
}
function platformVersionSlotKeyOf(accountId, gatewayId, version) {
return `apps/${accountId}/${gatewayId}/${platformVersionSlotRelKeyOf(version)}`;
}
/** The per-deploy audit record's key — the timestamp is munged into a
* FastKV-safe path form. */
function deployAuditKeyOf(accountId, gatewayId, publishedAt) {
return `apps/${accountId}/${gatewayId}/manifests/${publishedAt.replace(/[:.]/g, "-")}.json`;
}
/** The release classifier's pointer read: absent (null) means no release has
* published; a read failure throws — an unknown state must never silently
* classify a release as non-release. The keyPath is RELATIVE —
* `fetchRegistryKey` wraps it with the runtime prefix (a full key here
* double-prefixes the wire key and reads a slot that can never exist). */
function readPlatformPointer(accountId, gatewayId, registry) {
return fetchRegistryKey(accountId, gatewayId, PLATFORM_POINTER_REL_KEY, registry);
}
/** The release leg's immutability check: the version slot must either be
* absent or hold byte-identical content — a divergent republish is a burned
* version. */
function readPlatformVersionSlot(accountId, gatewayId, version, registry) {
return fetchRegistryKey(accountId, gatewayId, platformVersionSlotRelKeyOf(version), registry);
}
//#endregion
export { PLATFORM_POINTER_REL_KEY, deployAuditKeyOf, platformPointerKeyOf, platformVersionSlotKeyOf, platformVersionSlotRelKeyOf, readPlatformPointer, readPlatformVersionSlot };
//# sourceMappingURL=pointer.mjs.map