UNPKG

5.85 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ProtoFab } from './models/ProtoFab';
3import { ConfigTypes } from './constants';
4export interface PluginArgs {
5 [arg_name: string]: any;
6}
7export interface BuildConfig {
8 [plugin_name: string]: PluginArgs;
9}
10export declare type FabSettings = {
11 [var_name: string]: string | boolean;
12};
13export declare type DeployConfig = {
14 'cf-workers'?: ConfigTypes.CFWorkers;
15 'aws-lambda-edge'?: ConfigTypes.AwsLambda;
16 'aws-s3'?: ConfigTypes.AwsS3;
17};
18export declare type DeployProviders = keyof DeployConfig;
19export interface FabConfig {
20 plugins: BuildConfig;
21 settings?: {
22 [env_name: string]: FabSettings;
23 };
24 deploy?: DeployConfig;
25}
26export interface PluginMetadataContent<T extends PluginArgs = {}> {
27 args: T;
28 [metadata_name: string]: any;
29}
30export interface PluginMetadata<T extends PluginArgs = {}> {
31 [plugin_name: string]: PluginMetadataContent<T>;
32}
33export declare type FabBuildStep<T extends PluginArgs = PluginArgs, U extends PluginMetadata = PluginMetadata> = (args: T, proto_fab: ProtoFab<U>, config_path: string, skip_cache?: boolean) => Promise<void>;
34export declare type FabResponderMutableContext = {
35 [key: string]: any;
36};
37export declare type FabResponderArgs = {
38 request: Request;
39 settings: FabSettings;
40 url: URL;
41 context: FabResponderMutableContext;
42};
43export declare type FabRequestResponder = (context: FabResponderArgs) => Promise<undefined | Request | Response | Directive>;
44export declare type MatchParams = {
45 [match_name: string]: string;
46};
47export declare type FabRequestResponderWithParams = (contextWithParams: FabResponderArgs & {
48 params: MatchParams;
49}) => ReturnType<FabRequestResponder>;
50export declare type ResponseInterceptor = (response: Response) => Promise<Response>;
51export declare type Directive = {
52 interceptResponse?: ResponseInterceptor;
53 replaceRequest?: Request;
54};
55export declare type FabFilesObject = {
56 [k: string]: string;
57};
58export declare type FabFiles = Map<string, Buffer>;
59export declare type FabFileMetadata = {
60 [filename: string]: {
61 content_type: string;
62 content_length: number;
63 };
64};
65export declare type FabMetadata = {
66 file_metadata: FabFileMetadata;
67 plugin_metadata: PluginMetadata;
68};
69export declare type FabCacheValue = string | number | ArrayBuffer | ReadableStream;
70export declare type FabCache = {
71 set: (key: string, value: FabCacheValue, ttl_seconds?: number) => Promise<void>;
72 setJSON: (key: string, value: any, ttl_seconds?: number) => Promise<void>;
73 get: (key: string) => Promise<string | undefined>;
74 getJSON: (key: string) => Promise<any | undefined>;
75 getNumber: (key: string) => Promise<number | undefined>;
76 getArrayBuffer: (key: string) => Promise<ArrayBuffer | undefined>;
77 getStream: (key: string) => Promise<ReadableStream | undefined>;
78};
79export declare type FABServerContext = {
80 bundle_id: string;
81 cache?: FabCache;
82};
83export declare type ServerConstructor = (filename: string, args: ServerArgs) => ServerType;
84export interface ServerType {
85 serve(runtimeType: SandboxType): Promise<void>;
86}
87export declare type ServerArgs = {
88 port: string;
89 cert: string | undefined;
90 key: string | undefined;
91 env: string | undefined;
92 config: string;
93};
94export declare enum SandboxType {
95 v8isolate = 0,
96 nodeVm = 1
97}
98export declare type FabSpecRender = (request: Request, settings: FabSettings) => Promise<Request | Response>;
99export declare type FabSpecMetadata = {
100 production_settings: FabSettings;
101 fab_version: string;
102};
103export declare type FabSpecExports = {
104 render: FabSpecRender;
105 metadata: FabSpecMetadata;
106 initialize: (server_context: FABServerContext) => void;
107};
108export declare type FetchApi = (url: string | Request, init?: RequestInit) => Promise<Response>;
109export declare type FabServerDeployer<T extends ConfigTypes.Union> = (fab_path: string, working_dir: string, config: T, env_overrides: FabSettings, assets_url: string) => Promise<string>;
110export declare type FabAssetsDeployer<T extends ConfigTypes.Union> = (fab_path: string, working_dir: string, config: T) => Promise<string>;
111export declare type FabDeployer<T extends ConfigTypes.Union> = (fab_path: string, working_dir: string, config: T, env_overrides: FabSettings) => Promise<string>;
112export declare type FabDeployerExports<T extends ConfigTypes.Union> = {
113 deployServer?: FabServerDeployer<T>;
114 deployAssets?: FabAssetsDeployer<T>;
115 deployBoth?: FabDeployer<T>;
116};
117export declare type FabPackager<T extends ConfigTypes.Union> = (fab_path: string, package_path: string, config: T, env_overrides: FabSettings, assets_url: string) => Promise<void>;
118export declare type FabPackagerExports<T extends ConfigTypes.Union> = {
119 createPackage: FabPackager<T>;
120};
121export interface JSON5ConfigI {
122 data: FabConfig;
123 str_contents: string;
124 write(file_path: string): Promise<void>;
125}
126export declare type PackageFn = (file_path: string, config: FabConfig, target: DeployProviders, output_path: string | undefined, assets_url: string, env: string | undefined) => Promise<void>;
127export declare type DeployFn = (config: JSON5ConfigI, file_path: string, package_dir: string, server_host: DeployProviders | undefined, assets_host: DeployProviders | undefined, env: string | undefined, assets_only: boolean, assets_already_deployed_at: string | undefined, auto_install: boolean) => Promise<string>;
128export declare type BuildFn = (config_path: string, config: FabConfig, skip_cache: boolean) => Promise<void>;
129export declare type FabActionsExports = {
130 Packager: {
131 package: PackageFn;
132 };
133 Deployer: {
134 deploy: DeployFn;
135 };
136 Builder: {
137 build: BuildFn;
138 };
139};
140export declare type FabServerExports = {
141 createServer: ServerConstructor;
142};