UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

71 lines (70 loc) • 2.35 kB
//#region src/services/registry/keys.ts var RegistryRefError = class extends Error { constructor(message) { super(message); this.name = "RegistryRefError"; } }; /** `runtimeRefOf({ accountId, gatewayId })` — the runtime identity. */ function runtimeRefOf(parts) { if (!parts.accountId || !parts.gatewayId) throw new RegistryRefError(`Invalid runtime ref: account "${parts.accountId}", gateway "${parts.gatewayId}" — both segments are required`); return `bos://${parts.accountId}/${parts.gatewayId}`; } /** * Parse a runtime ref into its parts. Extra path segments beyond * `<gateway>` are the config sub-path (`bos://a/g/team/app` → * `path: ["team", "app"]`); a `#fragment` is stripped. Throws * `RegistryRefError` on any malformed ref. */ function parseRuntimeRef(ref) { const match = ref.split("#")[0].match(/^bos:\/\/([^/]+)\/(.+)$/); if (!match?.[1] || !match[2]) throw new RegistryRefError(`Invalid runtime ref: ${ref}`); const [gatewayId, ...path] = match[2].split("/").filter(Boolean).map((segment) => decodeURIComponent(segment)); if (!gatewayId) throw new RegistryRefError(`Invalid runtime ref: ${ref}`); return { accountId: match[1], gatewayId, path }; } const singleSegment = (value, label) => { if (!value || value.includes("/")) throw new RegistryRefError(`Invalid registry key: ${label} "${value}" must be one path segment`); return value; }; /** The exact wire key for a registry key — raw (unencoded); the client * encodes it as a single path segment per the FastKV read API. */ function keyPathOf(key) { const { accountId, gatewayId } = parseRuntimeRef(key.ref); switch (key.kind) { case "runtimeConfig": return [ "apps", accountId, gatewayId, ...(key.path ?? []).map((segment) => singleSegment(segment, "config path")), "bos.config.json" ].join("/"); case "manifest": return [ "apps", accountId, gatewayId, "manifest.json" ].join("/"); case "version": return [ "apps", accountId, gatewayId, "versions", `${singleSegment(key.version, "version")}.json` ].join("/"); case "deployRecord": return [ "apps", accountId, gatewayId, "deploys", `${singleSegment(key.ts, "deploy timestamp")}.json` ].join("/"); } } //#endregion export { RegistryRefError, keyPathOf, parseRuntimeRef, runtimeRefOf }; //# sourceMappingURL=keys.mjs.map