init ingestion

This commit is contained in:
2026-05-24 22:59:24 +07:00
commit 4e8c11d545
80 changed files with 5639 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
// Function registry -- an in-memory cache of (workspace_id, slug) -> code.
//
// The console writes function code into Postgres; rotor loads it lazily on
// first miss and refreshes on pub/sub invalidation.
//
// For this scaffold we keep it dumb: a Map you can preload via /api/admin
// or set directly in tests. Replace `loader` with a real PG loader when the
// console exists.
export class Registry {
/**
* @param {{ loader?: (workspaceId: string, slug: string) => Promise<string|null> }} opts
*/
constructor(opts = {}) {
this.loader = opts.loader ?? (async () => null);
/** @type {Map<string, { code: string, version: number }>} */
this.cache = new Map();
}
key(workspaceId, slug) { return `${workspaceId}:${slug}`; }
async get(workspaceId, slug) {
const k = this.key(workspaceId, slug);
if (this.cache.has(k)) return this.cache.get(k);
const code = await this.loader(workspaceId, slug);
if (code == null) return null;
const entry = { code, version: 1 };
this.cache.set(k, entry);
return entry;
}
set(workspaceId, slug, code, version = 1) {
this.cache.set(this.key(workspaceId, slug), { code, version });
}
invalidate(workspaceId, slug) {
this.cache.delete(this.key(workspaceId, slug));
}
}