netlify
Version:
Netlify command line tool
138 lines • 5.19 kB
TypeScript
import type { AIGatewayContext } from '@netlify/ai/bootstrap';
import BaseCommand from '../../commands/base-command.js';
import { type NormalizedCachedConfigConfig } from '../../utils/command-helpers.js';
import type { FeatureFlags } from '../../utils/feature-flags.js';
type RunIsolate = Awaited<ReturnType<typeof import('@netlify/edge-bundler').serve>>;
interface EdgeFunctionsRegistryOptions {
aiGatewayContext?: AIGatewayContext | null;
bundler: typeof import('@netlify/edge-bundler');
command: BaseCommand;
config: NormalizedCachedConfigConfig;
configPath: string;
debug: boolean;
env: Record<string, {
sources: string[];
value: string;
}>;
featureFlags: FeatureFlags;
getUpdatedConfig: () => Promise<NormalizedCachedConfigConfig>;
importMapFromTOML?: string;
projectDir: string;
runIsolate: RunIsolate;
servePath: string;
deployEnvironment: {
key: string;
value: string;
isSecret: boolean;
}[];
}
/** Public contract for EdgeFunctionsRegistry - consumers should use this type */
export interface EdgeFunctionsRegistry {
initialize(): Promise<void>;
matchURLPath(urlPath: string, method: string, headers: Record<string, string | string[] | undefined>): {
functionNames: string[];
invocationMetadata: unknown;
};
}
export declare class EdgeFunctionsRegistryImpl implements EdgeFunctionsRegistry {
importMapFromDeployConfig?: string;
private aiGatewayContext?;
private buildError;
/** @internal Exposed for testing - not part of the public EdgeFunctionsRegistry interface */
buildPending: boolean;
/** @internal Exposed for testing - not part of the public EdgeFunctionsRegistry interface */
buildPromise: Promise<{
warnings: Record<string, string[]>;
}> | null;
private bundler;
private configPath;
private importMapFromTOML?;
private declarationsFromDeployConfig;
private declarationsFromTOML;
private dependencyPaths;
private directoryWatchers;
private env;
private featureFlags;
private userFunctions;
private internalFunctions;
private functionPaths;
private getUpdatedConfig;
private initialScan;
private manifest;
private routes;
private runIsolate;
private servePath;
private projectDir;
private command;
constructor({ aiGatewayContext, bundler, command, config, configPath, env, featureFlags, getUpdatedConfig, importMapFromTOML, projectDir, runIsolate, servePath, deployEnvironment, }: EdgeFunctionsRegistryOptions);
private doInitialScan;
private get functions();
/**
* Triggers a build of edge functions with coalescing behavior.
*
* Note: We intentionally don't use @netlify/dev-utils memoize() here because
* it has a 300ms debounce and fire-and-forget logic. Edge function build
* needs callers to receive the latest build result.
*
* @internal Exposed for testing - not part of the public EdgeFunctionsRegistry interface
*/
build(): Promise<{
warnings: Record<string, string[]>;
}>;
/** @internal Exposed for testing - not part of the public EdgeFunctionsRegistry interface */
doBuild(): Promise<{
warnings: Record<string, string[]>;
}>;
/**
* Builds a manifest and corresponding routes for the functions in the
* registry, taking into account the declarations from the TOML, from
* the deploy configuration API, and from the in-source configuration
* found in both internal and user functions.
*/
private buildRoutes;
private checkForAddedOrDeletedFunctions;
private static getDeclarationsFromTOML;
private getDisplayName;
private static getEnvironmentVariables;
private handleFileChange;
initialize(): Promise<void>;
/**
* Logs an event associated with functions.
*/
private logEvent;
/**
* Returns the functions in the registry that should run for a given URL path
* and HTTP method, based on the routes registered for each function.
*/
matchURLPath(urlPath: string, method: string, headers: Record<string, string | string[] | undefined>): {
functionNames: string[];
invocationMetadata: {
function_config: Record<string, import("@netlify/edge-bundler").EdgeFunctionConfig> | undefined;
req_routes: number[];
routes: {
function: string;
path: string | undefined;
pattern: string;
}[];
};
};
/**
* Takes the module graph returned from the server and tracks dependencies of
* each function.
*/
private processGraph;
/**
* Thin wrapper for `#runIsolate` that skips running a build and returns an
* empty response if there are no functions in the registry.
*/
private runBuild;
private get internalImportMapPath();
private readDeployConfig;
private scanForDeployConfig;
private scanForFunctions;
private setupWatchers;
private setupWatcherForDirectory;
private get usesFrameworksAPI();
}
export {};
//# sourceMappingURL=registry.d.ts.map