/** * Source scanner for the new `Cloudflare` injection surface. * * A photon that takes `private cf: Cloudflare` (or any other parameter * name typed `Cloudflare`) reaches into per-binding resources via * `cf.kv(qualifier?)`, `cf.r2(qualifier?)`, etc. The runtime needs to * know — at boot time, before any tool runs — which **qualifiers** the * photon will use, because both miniflare (local sandbox) and * wrangler.toml (deploy) require every binding to be declared up front. * * This scanner walks the photon source and discovers: * 1. Constructor parameter names typed `Cloudflare` (so we recognize * `this..kv(...)` regardless of what the author named * the field — `cf`, `xCloud`, `cloud`, etc.). * 2. Every literal qualifier passed to a scoped category method on * one of those parameter names. * 3. The boolean `share` flags inferred from any reference to the * shared categories (`ai`, `images`, `browser`). * * Dynamic qualifiers (e.g. `cf.kv(this.tenantId)`) are flagged as * `dynamicQualifiers` per category so the runtime can throw a clear * error pointing the author at `protected cfBindings` overrides — far * better than letting miniflare crash with "binding undefined." * * Single source of truth for both runtime seeding and deploy autogen, * so the binding-name convention can never drift between the two * (a real risk before this scanner — `bindingNameFor(...)` lived in one * place but every consumer recomputed it). */ import { type ScopedBindingCategory } from '@portel/photon-core'; /** Categories that take an optional qualifier and use auto-naming. */ declare const SCOPED_CATEGORIES: readonly ScopedBindingCategory[]; /** Categories with a single shared binding per Worker (no qualifier). */ declare const SHARED_CATEGORIES: readonly ["ai", "images", "browser"]; export type SharedCategory = (typeof SHARED_CATEGORIES)[number]; export interface CfUsage { /** * Per-category set of literal qualifier strings the photon uses. * The empty-string entry `''` means the default (no-qualifier) call * `cf.kv()`. Other entries are the literal arg passed to a qualified * call like `cf.kv('cache')`. */ qualifiers: Record>; /** * Categories where at least one call passed a non-literal expression * (e.g. a variable). The runtime can't statically resolve the * binding name; surfaces as a clear error rather than a silent * miniflare miss. */ dynamicQualifiers: Set; /** True if the photon reads the corresponding shared binding. */ shared: Record; /** * Constructor parameter names (or property names) recognized as the * Cloudflare access path on this photon. Always at least includes * `cf` for the legacy `this.cf` shape so existing static-analysis * sites continue to work; extended with any additional names found * via a typed constructor parameter. */ accessPaths: Set; } /** * Scan a photon's TypeScript source and return everything the runtime * + deploy code-gen needs to know about its CF usage. */ export declare function scanCfUsage(tsContent: string): CfUsage; /** * All scoped binding names the photon will use, expanded against the * photon's name. Hands a deduplicated list to miniflare-config emission * and wrangler.toml emission. Dynamic qualifiers contribute only the * default name — the rest must come from `protected cfBindings` * overrides. */ export declare function expandScopedBindingNames(photonName: string, usage: CfUsage): Record; export { SCOPED_CATEGORIES, SHARED_CATEGORIES }; //# sourceMappingURL=cf-usage-scanner.d.ts.map