exlo 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +11 -0
- package/dist/config.d.ts +35 -0
- package/dist/defineConfig.d.ts +125 -0
- package/dist/defineConfig.mjs +1 -0
- package/dist/lib/esbuild/buildOptimizer.d.ts +9 -0
- package/dist/lib/esbuild/knownCjs.d.ts +1 -0
- package/dist/lib/esbuild/mergeEsbuildConfig.d.ts +2 -0
- package/dist/lib/esbuild/parseCustomEsbuild.d.ts +2 -0
- package/dist/lib/parseEvents/ddbStream.d.ts +17 -0
- package/dist/lib/parseEvents/endpoints.d.ts +29 -0
- package/dist/lib/parseEvents/funcUrl.d.ts +2 -0
- package/dist/lib/parseEvents/index.d.ts +16 -0
- package/dist/lib/parseEvents/sqs.d.ts +11 -0
- package/dist/lib/runtime/bufferedStreamResponse.d.ts +24 -0
- package/dist/lib/runtime/callDestinations.d.ts +12 -0
- package/dist/lib/runtime/eventSourceMapping/base.d.ts +66 -0
- package/dist/lib/runtime/eventSourceMapping/base.mjs +1 -0
- package/dist/lib/runtime/eventSourceMapping/errors/eventSourceMappingError.d.ts +5 -0
- package/dist/lib/runtime/eventSourceMapping/esmBatch.d.ts +15 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileFilterPolicy.d.ts +12 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileFilterPolicy.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileWildcard.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileWildcard.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/expandDotPathsWithStrictConflicts.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/expandDotPathsWithStrictConflicts.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/matchesFilterPolicy.d.ts +2 -0
- package/dist/lib/runtime/eventSourceMapping/filter/matchesFilterPolicy.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/sqs.d.ts +19 -0
- package/dist/lib/runtime/eventSourceMapping/utils.d.ts +6 -0
- package/dist/lib/runtime/rapidApi.d.ts +97 -0
- package/dist/lib/runtime/runners/index.d.ts +25 -0
- package/dist/lib/runtime/runners/node/awslambda.d.ts +11 -0
- package/dist/lib/runtime/runners/node/index.d.ts +1 -0
- package/dist/lib/runtime/runners/node/index.js +19 -0
- package/dist/lib/runtime/runners/node/runner.d.ts +34 -0
- package/dist/lib/runtime/runners/node/streamResponse.d.ts +90 -0
- package/dist/lib/runtime/runners/node/utils.d.ts +39 -0
- package/dist/lib/runtime/runners/python/runner.d.ts +48 -0
- package/dist/lib/runtime/runners/ruby/runner.d.ts +43 -0
- package/dist/lib/server/daemon.d.ts +27 -0
- package/dist/lib/server/handlers.d.ts +13 -0
- package/dist/lib/services/index.d.ts +10 -0
- package/dist/lib/utils/amazonifyHeaders.d.ts +3 -0
- package/dist/lib/utils/colorize.d.ts +12 -0
- package/dist/lib/utils/getPackageInstalledDir.d.ts +1 -0
- package/dist/lib/utils/readDefineConfig.d.ts +6 -0
- package/dist/main.d.ts +80 -0
- package/dist/plugins/lambda/events/alb.d.ts +44 -0
- package/dist/plugins/lambda/events/apg.d.ts +111 -0
- package/dist/plugins/lambda/events/common.d.ts +114 -0
- package/dist/plugins/lambda/functionUrlInvoke.d.ts +3 -0
- package/dist/plugins/lambda/htmlStatusMsg.d.ts +4 -0
- package/dist/plugins/lambda/index.d.ts +3 -0
- package/dist/plugins/lambda/invokeRequests.d.ts +3 -0
- package/dist/plugins/lambda/lambdaApi.d.ts +6 -0
- package/dist/plugins/lambda/responseStreamingInvoke.d.ts +3 -0
- package/dist/plugins/lambda/streamEncoder.d.ts +19 -0
- package/dist/plugins/lambda/utils.d.ts +29 -0
- package/dist/plugins/restApi/compileAjvSchema.d.ts +1 -0
- package/dist/plugins/restApi/errors.d.ts +32 -0
- package/dist/plugins/restApi/findRequestResource.d.ts +9 -0
- package/dist/plugins/restApi/findRequestResource.test.d.ts +1 -0
- package/dist/plugins/restApi/index.d.ts +8 -0
- package/dist/plugins/restApi/index.mjs +1 -0
- package/dist/plugins/restApi/resourcesFromOpenApi.d.ts +4 -0
- package/dist/plugins/restApi/restApiServer.d.ts +265 -0
- package/dist/plugins/restApi/restApiServer.test.d.ts +1 -0
- package/dist/plugins/restApi/utils.d.ts +9 -0
- package/dist/plugins/s3/actions/AbortMultipartUploadAction.d.ts +10 -0
- package/dist/plugins/s3/actions/CompleteMultipartUploadAction.d.ts +15 -0
- package/dist/plugins/s3/actions/CopyObjectAction.d.ts +24 -0
- package/dist/plugins/s3/actions/CreateBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/CreateMultipartUploadAction.d.ts +13 -0
- package/dist/plugins/s3/actions/DeleteBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteBucketPolicyAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteObjectAction.d.ts +10 -0
- package/dist/plugins/s3/actions/DeleteObjectTaggingAction.d.ts +9 -0
- package/dist/plugins/s3/actions/DeleteObjectsAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketPolicy.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetObjectAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetObjectAction.d.ts +30 -0
- package/dist/plugins/s3/actions/GetObjectTaggingAction.d.ts +10 -0
- package/dist/plugins/s3/actions/HeadBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/HeadObjectAction.d.ts +18 -0
- package/dist/plugins/s3/actions/ListBucketsAction.d.ts +15 -0
- package/dist/plugins/s3/actions/ListMultipartUploadsAction.d.ts +19 -0
- package/dist/plugins/s3/actions/ListObjectsAction.d.ts +31 -0
- package/dist/plugins/s3/actions/ListPartsAction.d.ts +14 -0
- package/dist/plugins/s3/actions/PutBucketAclAction.d.ts +11 -0
- package/dist/plugins/s3/actions/PutBucketCorsAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutBucketPolicyAction.d.ts +9 -0
- package/dist/plugins/s3/actions/PutBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutObjectAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutObjectAction.d.ts +22 -0
- package/dist/plugins/s3/actions/PutObjectTaggingAction.d.ts +9 -0
- package/dist/plugins/s3/actions/UnknownAction.d.ts +7 -0
- package/dist/plugins/s3/actions/UploadPartAction.d.ts +12 -0
- package/dist/plugins/s3/actions/localAction.d.ts +92 -0
- package/dist/plugins/s3/calulcateETag.d.ts +1 -0
- package/dist/plugins/s3/commons/constants.d.ts +6 -0
- package/dist/plugins/s3/commons/utils.d.ts +3 -0
- package/dist/plugins/s3/errors/notFound.d.ts +8 -0
- package/dist/plugins/s3/errors/s3Error.d.ts +65 -0
- package/dist/plugins/s3/getLocalStoragePath.d.ts +1 -0
- package/dist/plugins/s3/index.d.ts +32 -0
- package/dist/plugins/s3/index.mjs +97 -0
- package/dist/plugins/s3/lib/createS3Server.d.ts +38 -0
- package/dist/plugins/s3/parsers/parseDeleteRequest.d.ts +10 -0
- package/dist/plugins/s3/parsers/parseGetRequest.d.ts +14 -0
- package/dist/plugins/s3/parsers/parseHeadRequest.d.ts +5 -0
- package/dist/plugins/s3/parsers/parsePostRequest.d.ts +7 -0
- package/dist/plugins/s3/parsers/parsePutRequest.d.ts +14 -0
- package/dist/plugins/s3/triggerEvent.d.ts +12 -0
- package/dist/plugins/sns/errors.d.ts +26 -0
- package/dist/plugins/sns/filter.d.ts +1 -0
- package/dist/plugins/sns/filter.test.d.ts +1 -0
- package/dist/plugins/sns/index.d.ts +23 -0
- package/dist/plugins/sns/index.mjs +106 -0
- package/dist/plugins/sns/parsers/parseCreateTopic.d.ts +2 -0
- package/dist/plugins/sns/parsers/parseMessage.d.ts +18 -0
- package/dist/plugins/sns/parsers/parsePublishMessage.d.ts +6 -0
- package/dist/plugins/sns/parsers/parsePublishMessageBatch.d.ts +9 -0
- package/dist/plugins/sns/parsers/parseSubscribe.d.ts +17 -0
- package/dist/plugins/sns/parsers/parseSubscriptionArn.d.ts +6 -0
- package/dist/plugins/sns/parsers/parseTopicArn.d.ts +4 -0
- package/dist/plugins/sns/server.d.ts +36 -0
- package/dist/plugins/sns/server.test.d.ts +1 -0
- package/dist/plugins/sns/subscriber/index.d.ts +61 -0
- package/dist/plugins/sns/subscriber/validateConfig.d.ts +0 -0
- package/dist/plugins/sns/topic.d.ts +91 -0
- package/dist/plugins/sns/utils.d.ts +20 -0
- package/dist/plugins/sns/validateFilterPolicy.d.ts +19 -0
- package/dist/plugins/sns/validateFilterPolicy.test.d.ts +1 -0
- package/dist/plugins/sqs/index.d.ts +16 -0
- package/dist/plugins/sqs/index.mjs +1 -0
- package/dist/plugins/sqs/types.d.ts +11 -0
- package/dist/plugins/sqs/utils.d.ts +7 -0
- package/dist/plugins/vitest/coverage.d.ts +6 -0
- package/dist/plugins/vitest/index.d.ts +29 -0
- package/dist/plugins/vitest/index.mjs +1 -0
- package/dist/standalone.d.ts +17 -0
- package/dist/standalone.js +13 -0
- package/dist/standalone.mjs +13 -0
- package/dist/standalone_types.d.ts +190 -0
- package/package.json +119 -0
- package/src/lib/runtime/runners/python/index.py +105 -0
- package/src/lib/runtime/runners/ruby/index.rb +67 -0
package/dist/cli.d.ts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{readFile as F}from"node:fs/promises";import u from"node:path";import{pathToFileURL as _}from"node:url";import{parseArgs as I}from"node:util";import{run as O}from"exlo";var h="exlo",b="0.0.1";var g=!1,E=e=>{g=e},k=()=>g,a=(e,t)=>{g&&console.log(`\x1B[${e}m${t}\x1B[0m`)},N=e=>console.log(`\x1B[31m${e}\x1B[0m`),R=e=>a("32",e),A=e=>a("33",e),$=e=>a("36",e),q=e=>a("90",e),S=e=>a("94",e),L=e=>a("95",e),C=e=>g?console.log(e):void 0,n={GREEN:R,YELLOW:A,CYAN:$,BR_BLUE:S,RED:N,GREY:q,PINK:L,setDebug:E,getDebug:k,info:C};function Y(){n.setDebug(!0),n.GREY("Usage example:"),console.log(`exlo -p 3000 --debug --functions "src/lambdas/**/*.ts"
|
|
3
|
+
`),n.BR_BLUE("Options:");for(let[e,t]of Object.entries(v)){let i=e;if(t.skip)continue;if(t.short&&(i+=`, -${t.short}`),t.skipFullPrint){n.CYAN(` --${i}
|
|
4
|
+
`);continue}let s=` type: ${t.type}`;t.description&&(s+=`
|
|
5
|
+
description: ${t.description}`),"default"in t&&(s+=`
|
|
6
|
+
default: ${t.default}`),t.example&&(s+=`
|
|
7
|
+
example: ${t.example}`),s+=`
|
|
8
|
+
`,n.CYAN(` --${i}`),n.GREY(s)}n.CYAN(" --esbuild-[option]"),n.GREY(`
|
|
9
|
+
description: where 'options' is one of esbuild build options`),n.GREY(`
|
|
10
|
+
example: exlo --esbuild-external="@aws-sdk/*" --esbuild-external=react --esbuild-format=esm --esbuild-outExtension..js=.mjs --esbuild-outExtension..css=.CSS`),console.log(`
|
|
11
|
+
${h} v${b}`),process.exit(0)}function j(e,t){return!e||Number.isNaN(e)?t:Number(e)}async function D(e){if(e){if(e.endsWith(".js"))throw new Error("Only .json, .mjs and .cjs are supported for --definitions option.");if(e.endsWith(".json"))return JSON.parse(await F(e,"utf-8")).functions;if(e.endsWith(".mjs")||e.endsWith(".cjs"))return(await import(_(u.resolve(process.cwd(),e)).href)).functions}}async function G(e,t,i){if(!i)return;let s=Number(process.versions.node.slice(0,process.versions.node.indexOf(".")));if(s<22)throw new Error("--functions option is only supported on Node22 and higher.");let{glob:p}=await import("node:fs/promises"),m={};for await(let l of p(i)){if(l.match(e))continue;let f=u.basename(u.dirname(l)),o=u.parse(l),r;o.name=="index"?m[f]?r=l.replaceAll(u.sep,"_"):r=f:m[o.name]?m[`${f}_${o.name}`]?r=l.replaceAll(u.sep,"_"):r=`${f}_${o.name}`:r=o.name,m[r]={name:r,handler:l.replace(o.ext,`.${t}`),runtime:o.ext==".py"?"python3.7":o.ext==".rb"?"ruby2.7":`nodejs${s}.x`}}return m}function P(e){let t={};for(let i of e){let[s,...p]=i.split("=");t[s]=p.join("=")}return t}var v={port:{type:"string",short:"p",default:"0",description:"Set server port."},debug:{type:"boolean",default:!1,description:"Enable debug mode. When enabled exlo will print usefull informations."},config:{type:"string",short:"c",description:"Path to 'defineConfig' file."},runtime:{type:"string",short:"r",description:"Set default runtime (ex: nodejs22.x, python3.7, ruby2.7 etc.)."},timeout:{type:"string",short:"t",default:"3",description:"Set default timeout."},definitions:{type:"string",short:"d",description:"Path to .json, .mjs, .cjs file with Lambda function definitions."},functions:{type:"string",short:"f",multiple:!0,description:"Glob pattern to automatically find and define Lambda handlers."},exclude:{type:"string",short:"x",default:".(test|spec).",description:"RegExp string to exclude found enteries from --functions."},handlerName:{type:"string",default:"handler",description:"Handler function name. To be used with --functions."},env:{type:"string",short:"e",multiple:!0,default:[],description:"Environment variables to be injected into Lambdas. All existing AWS_* are automatically injected.",example:"-e API_KEY=supersecret -e API_URL=https://website.com"},"optimize-build":{type:"boolean",default:!0,description:"externalize dependencies and other stuff"},"shim-require":{type:"boolean",default:!1,description:"shim 'require()', '__dirname' and '__filename' when bundeling Lambdas with ESM format"},help:{type:"boolean",short:"h",skipFullPrint:!0},version:{type:"boolean",short:"v",skipFullPrint:!0},"esbuild-external":{type:"string",multiple:!0,skip:!0},"esbuild-resolveExtensions":{type:"string",multiple:!0,skip:!0},"esbuild-mainFields":{type:"string",multiple:!0,skip:!0},"esbuild-conditions":{type:"string",multiple:!0,skip:!0},"esbuild-entryPoints":{type:"string",multiple:!0,skip:!0},"esbuild-inject":{type:"string",multiple:!0,skip:!0},"esbuild-nodePaths":{type:"string",multiple:!0,skip:!0}},{values:d}=I({strict:!1,options:v}),{port:W,config:B,debug:M,help:U,runtime:z,definitions:w,timeout:T,functions:y,handlerName:V,exclude:H,env:K}=d;d.version?(console.log(b),process.exit(0)):U&&Y();if(w&&y)throw new Error("Can not use --definitions (-d) and --functions (-f) together.");var J=y?await G(new RegExp(H),V,y):await D(w),c={};for(let e of Object.keys(d).filter(t=>t.startsWith("esbuild-"))){let t=e.split("esbuild-")[1];if(t.includes(".")){let i=t.indexOf("."),s=t.slice(0,i),p=t.slice(i+1);c[s]||(c[s]={}),c[s][p]=d[e]}else c[t]=d[e]}var Q=d["optimize-build"],X=d["shim-require"],Z={debug:M,config:B,port:j(W,0),functions:J,esbuild:c,optimizeBuild:Q,shimRequire:X,defaults:{environment:P(K),runtime:z,timeout:j(T,3)}};O(Z);
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { BuildOptions, BuildResult } from "esbuild";
|
|
3
|
+
import type { awslambda } from "./lib/runtime/runners/node/awslambda";
|
|
4
|
+
import type { HttpMethod } from "./lib/server/handlers";
|
|
5
|
+
export interface OfflineConfig {
|
|
6
|
+
port?: number;
|
|
7
|
+
onReady?: (port: number, ip: string) => Promise<void> | void;
|
|
8
|
+
request?: {
|
|
9
|
+
method?: HttpMethod | HttpMethod[];
|
|
10
|
+
filter: string | RegExp;
|
|
11
|
+
callback: (req: IncomingMessage, res: ServerResponse) => Promise<void> | void;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export interface Config {
|
|
15
|
+
build: {
|
|
16
|
+
esbuild?: Omit<BuildOptions, "outfile" | "bundle" | "splitting" | "stdin" | "platforme" | "metafile" | "format"> & {
|
|
17
|
+
format?: "cjs" | "esm";
|
|
18
|
+
};
|
|
19
|
+
shimRequire?: boolean;
|
|
20
|
+
optimizeBuild?: boolean;
|
|
21
|
+
};
|
|
22
|
+
server?: OfflineConfig;
|
|
23
|
+
buildCallback?: (result: BuildResult, isRebuild: boolean) => Promise<void> | void;
|
|
24
|
+
onKill?: (() => Promise<void> | void)[];
|
|
25
|
+
}
|
|
26
|
+
export interface ServerConfig {
|
|
27
|
+
stage?: string;
|
|
28
|
+
watch?: boolean;
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
port?: number;
|
|
31
|
+
onRebuild?: () => Promise<void> | void;
|
|
32
|
+
}
|
|
33
|
+
declare global {
|
|
34
|
+
var awslambda: awslambda;
|
|
35
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { DynamoDB } from "@aws-sdk/client-dynamodb";
|
|
3
|
+
import type { S3 } from "@aws-sdk/client-s3";
|
|
4
|
+
import type { SNS } from "@aws-sdk/client-sns";
|
|
5
|
+
import type { SQS } from "@aws-sdk/client-sqs";
|
|
6
|
+
import type { BuildResult, PluginBuild } from "esbuild";
|
|
7
|
+
import type { Config } from "./config";
|
|
8
|
+
import type { ILambdaMock } from "./lib/runtime/rapidApi";
|
|
9
|
+
import type { HttpMethod } from "./lib/server/handlers";
|
|
10
|
+
import type { log } from "./lib/utils/colorize";
|
|
11
|
+
import type { IAwsProvider, ILambdaFunction } from "./standalone_types";
|
|
12
|
+
export type ILambda = {
|
|
13
|
+
/**
|
|
14
|
+
* Set environment variable.
|
|
15
|
+
*/
|
|
16
|
+
setEnv: (key: string, value: string | null) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Be notified when this lambda is invoked.
|
|
19
|
+
*
|
|
20
|
+
* Can be used to edit input payload before invokation.
|
|
21
|
+
*/
|
|
22
|
+
onInvoke: (callback: (event: any, info?: any) => void) => void | {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Called when handler throws an error.
|
|
27
|
+
*/
|
|
28
|
+
onInvokeError: (callback: (input: any, error: any, info?: any) => void) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Called when handler returns successfully.
|
|
31
|
+
*/
|
|
32
|
+
onInvokeSuccess: (callback: (input: any, output: any, info?: any) => void) => void;
|
|
33
|
+
} & Omit<ILambdaMock, "invokeSub" | "invokeSuccessSub" | "invokeErrorSub" | "runner">;
|
|
34
|
+
interface IServicesConfig {
|
|
35
|
+
dynamoDb?: DynamoDB;
|
|
36
|
+
s3?: S3;
|
|
37
|
+
sns?: SNS;
|
|
38
|
+
sqs?: SQS;
|
|
39
|
+
}
|
|
40
|
+
export type IAwsProviderDefaults = Pick<IAwsProvider, "region" | "accountId" | "environment" | "timeout" | "runtime" | "memorySize">;
|
|
41
|
+
export interface ClientConfigParams {
|
|
42
|
+
stop: (err?: any) => Promise<void>;
|
|
43
|
+
lambdas: ILambda[];
|
|
44
|
+
region: string;
|
|
45
|
+
esbuild: PluginBuild["esbuild"];
|
|
46
|
+
config: Config;
|
|
47
|
+
options: Options;
|
|
48
|
+
getServices(): IServicesConfig;
|
|
49
|
+
setService<ServiceName extends "s3" | "sqs" | "sns" | "dynamoDb">(service: ServiceName, client: ServiceName extends "sqs" ? SQS : ServiceName extends "sns" ? SNS : ServiceName extends "dynamoDb" ? DynamoDB : ServiceName extends "s3" ? S3 : never): void;
|
|
50
|
+
/** Must be called only inside `onInit`, otherwise it has no effect */
|
|
51
|
+
addLambda(lambdaName: string, config: ILambdaFunction): void;
|
|
52
|
+
setEndpoint(serviceName: string, url: string, asLambdaEnvVar?: `AWS_ENDPOINT_URL_${string}`): void;
|
|
53
|
+
getEndpoint(serviceName: string): string;
|
|
54
|
+
getAwsProviderDefaults(): IAwsProviderDefaults;
|
|
55
|
+
log: typeof log;
|
|
56
|
+
}
|
|
57
|
+
export interface OfflineRequest {
|
|
58
|
+
/**
|
|
59
|
+
* @default "ANY"
|
|
60
|
+
*/
|
|
61
|
+
method?: HttpMethod | HttpMethod[];
|
|
62
|
+
/**
|
|
63
|
+
* Filter for request path.
|
|
64
|
+
*/
|
|
65
|
+
filter: string | RegExp;
|
|
66
|
+
callback: (this: ClientConfigParams, req: IncomingMessage, res: ServerResponse) => Promise<any | void> | any | void;
|
|
67
|
+
}
|
|
68
|
+
export interface ExloPlugin<PluginData = any> {
|
|
69
|
+
/**
|
|
70
|
+
* Plugin name
|
|
71
|
+
*/
|
|
72
|
+
name: string;
|
|
73
|
+
/**
|
|
74
|
+
* Share any data with other plugins
|
|
75
|
+
*/
|
|
76
|
+
shared?: PluginData;
|
|
77
|
+
buildCallback?: (this: ClientConfigParams, result: BuildResult, isRebuild: boolean) => Promise<void> | void;
|
|
78
|
+
onInit?: (this: ClientConfigParams) => Promise<void> | void;
|
|
79
|
+
onKill?: (this: ClientConfigParams) => Promise<void> | void;
|
|
80
|
+
server?: {
|
|
81
|
+
onReady?: (this: ClientConfigParams, port: number, ip: string) => Promise<void> | void;
|
|
82
|
+
/**
|
|
83
|
+
* Add new requests to the local server.
|
|
84
|
+
*/
|
|
85
|
+
request?: OfflineRequest[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface Options {
|
|
89
|
+
build?: {
|
|
90
|
+
esbuild?: Config["build"]["esbuild"];
|
|
91
|
+
/**
|
|
92
|
+
* shim `require`, `__dirname` and `__filename` when bundeling Lambdas with ESM format
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
shimRequire?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Speed up build process during dev mode
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
optimizeBuild?: boolean;
|
|
101
|
+
};
|
|
102
|
+
/** AWS Lambda API */
|
|
103
|
+
server?: {
|
|
104
|
+
port?: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Only ExloPlugin type objects are considered as valid plugins.
|
|
108
|
+
*
|
|
109
|
+
* Others are ignored.
|
|
110
|
+
*
|
|
111
|
+
* This allows conditionnally ( condition == true ?? customPlugin) plugin apply.
|
|
112
|
+
*/
|
|
113
|
+
plugins?: (ExloPlugin | null | undefined | boolean)[];
|
|
114
|
+
/**
|
|
115
|
+
* AWS clients used by EventSourceMapping, Lambda error/success destination.
|
|
116
|
+
*/
|
|
117
|
+
services?: IServicesConfig;
|
|
118
|
+
functions?: {
|
|
119
|
+
[lambdaName: string]: ILambdaFunction;
|
|
120
|
+
};
|
|
121
|
+
defaults?: Partial<IAwsProviderDefaults>;
|
|
122
|
+
}
|
|
123
|
+
export type ConfigDefiner = (this: ClientConfigParams, internalResources: ClientConfigParams) => Promise<Omit<Config, "config" | "options">>;
|
|
124
|
+
export declare function defineConfig(options: Options): ConfigDefiner;
|
|
125
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function h(e){let u=new Set;e.plugins&&(e.plugins=e.plugins.filter((n,t)=>typeof n!="object"||!n||!("name"in n)?!1:((!n.name||!n.name.length||typeof n.name!="string")&&(n.name=`plugin-${t}`,console.warn(`No Plugin name provided at index ${t}`)),u.has(n.name)?n.name=n.name+t:u.add(n.name),!0)));async function c({stop:n,lambdas:t,region:g,esbuild:b,getServices:y,setService:l,addLambda:v,log:f,setEndpoint:p,getEndpoint:C,getAwsProviderDefaults:P,setAwsProviderDefaults:S}){let a={build:{esbuild:e?.build?.esbuild??{},shimRequire:e?.build?.shimRequire,optimizeBuild:e?.build?.optimizeBuild},server:{port:e.server?.port},onKill:[]};if(e.defaults&&typeof e.defaults=="object"&&!Array.isArray(e.defaults)&&S(e.defaults),e.functions&&typeof e.functions=="object"&&!Array.isArray(e.functions))for(let[d,i]of Object.entries(e.functions))v(d,i);e.services&&(e.services.sqs&&l("sqs",e.services.sqs),e.services.sns&&l("sns",e.services.sns),e.services.dynamoDb&&l("dynamoDb",e.services.dynamoDb));let o={stop:n,lambdas:t,region:g,esbuild:b,options:e,config:a,getServices:y,setService:l,addLambda:v,log:f,setEndpoint:p,getEndpoint:C,getAwsProviderDefaults:P};if(e.plugins){a.server.onReady=async(i,r)=>{for(let s of e.plugins)if(s.server?.onReady)try{await s.server.onReady.call(o,i,r)}catch(m){f.RED(s.name),console.error(m)}},a.buildCallback=async(i,r)=>{for(let s of e.plugins)if(s.buildCallback)try{await s.buildCallback.call(o,i,r)}catch(m){f.RED(s.name),console.error(m),r||process.exit(1)}};let d=e.plugins.reduce((i,r)=>(r.server?.request?.length&&i.push(...r.server.request),i),[]);d?.length&&(a.server.request=d.map(i=>(i.callback=i.callback.bind(o),i)));for(let i of e.plugins)if(i.onKill&&a.onKill.push(i.onKill.bind(o)),i.onInit)try{await i.onInit.call(o)}catch(r){throw f.RED(i.name),r}}return a}return c.plugins=e.plugins??[],c}export{h as defineConfig};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Socket } from "node:net";
|
|
2
|
+
import type { BuildResult, Plugin } from "esbuild";
|
|
3
|
+
export declare const buildOptimizer: ({ nodeVersion, shimRequire, optimizeBuild, buildCallback, getSockets, }: {
|
|
4
|
+
nodeVersion: number;
|
|
5
|
+
shimRequire: boolean;
|
|
6
|
+
optimizeBuild: boolean;
|
|
7
|
+
buildCallback: (result: BuildResult, isRebuild: boolean, format: string, outdir: string) => void | Promise<void>;
|
|
8
|
+
getSockets: () => Socket[];
|
|
9
|
+
}) => Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const knownCjs: string[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ITriggersDynamoDb } from "../../standalone_types";
|
|
2
|
+
import type { IDestination } from "./index";
|
|
3
|
+
export interface IDdbEvent {
|
|
4
|
+
TableName: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
startingPosition: "TRIM_HORIZON" | "LATEST";
|
|
7
|
+
batchSize?: number;
|
|
8
|
+
maximumBatchingWindow?: number;
|
|
9
|
+
tumblingWindowInSeconds?: number;
|
|
10
|
+
maximumRecordAgeInSeconds?: number;
|
|
11
|
+
maximumRetryAttempts?: number;
|
|
12
|
+
bisectBatchOnFunctionError?: boolean;
|
|
13
|
+
functionResponseType?: string;
|
|
14
|
+
filterPatterns?: any;
|
|
15
|
+
onFailure?: IDestination;
|
|
16
|
+
}
|
|
17
|
+
export declare const parseDdbStreamDefinitions: (event: ITriggersDynamoDb) => IDdbEvent | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpMethod } from "../server/handlers";
|
|
2
|
+
interface IAlbQuery {
|
|
3
|
+
Key?: string;
|
|
4
|
+
Value: string;
|
|
5
|
+
}
|
|
6
|
+
type query = IAlbQuery[];
|
|
7
|
+
export interface LambdaEndpoint {
|
|
8
|
+
kind: "alb" | "apg" | "url";
|
|
9
|
+
proxy?: "url" | "http" | "httpApi";
|
|
10
|
+
paths: string[];
|
|
11
|
+
pathsRegex: RegExp[];
|
|
12
|
+
methods: HttpMethod[];
|
|
13
|
+
async?: boolean;
|
|
14
|
+
multiValueHeaders?: boolean;
|
|
15
|
+
version?: 1 | 2;
|
|
16
|
+
header?: {
|
|
17
|
+
name: string;
|
|
18
|
+
values: string[];
|
|
19
|
+
}[];
|
|
20
|
+
query?: query[];
|
|
21
|
+
headers?: string[];
|
|
22
|
+
querystrings?: string[];
|
|
23
|
+
requestPaths?: string[];
|
|
24
|
+
stream?: boolean;
|
|
25
|
+
private?: boolean;
|
|
26
|
+
schema?: any;
|
|
27
|
+
}
|
|
28
|
+
export declare const parseEndpoints: (event: any, httpApiPayload: LambdaEndpoint["version"], provider: Record<string, any>) => LambdaEndpoint | null;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ITriggers } from "../../standalone_types";
|
|
2
|
+
import type { LambdaEndpoint } from "./endpoints";
|
|
3
|
+
export interface IDestination {
|
|
4
|
+
kind: "lambda" | "sns" | "sqs";
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const parseEvents: ({ triggers }: {
|
|
8
|
+
triggers: ITriggers[];
|
|
9
|
+
}) => {
|
|
10
|
+
ddb: any[];
|
|
11
|
+
endpoints: LambdaEndpoint[];
|
|
12
|
+
s3: any[];
|
|
13
|
+
sns: any[];
|
|
14
|
+
sqs: any[];
|
|
15
|
+
};
|
|
16
|
+
export declare const parseDestination: (destination: any) => IDestination | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITriggersSqs } from "../../standalone_types";
|
|
2
|
+
export interface ISqs {
|
|
3
|
+
name: string;
|
|
4
|
+
arn?: string;
|
|
5
|
+
batchSize?: number;
|
|
6
|
+
maximumBatchingWindow?: number;
|
|
7
|
+
filterPatterns?: any;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
functionResponseType?: ["ReportBatchItemFailures"];
|
|
10
|
+
}
|
|
11
|
+
export declare const parseSqs: (event: ITriggersSqs) => ISqs | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LambdaEndpoint } from "../parseEvents/endpoints";
|
|
2
|
+
export declare class BufferedStreamResponse {
|
|
3
|
+
#private;
|
|
4
|
+
buffer?: Uint8Array;
|
|
5
|
+
_isHttpIntegrationResponse: boolean;
|
|
6
|
+
_metaDelimiter: number;
|
|
7
|
+
_endDelimiter: number;
|
|
8
|
+
_ct?: any;
|
|
9
|
+
_isStreamResponse: boolean;
|
|
10
|
+
static codec: TextDecoder;
|
|
11
|
+
static splitMessage: (buffer?: Uint8Array, metaDelimiter?: number) => Uint8Array<ArrayBuffer> | undefined;
|
|
12
|
+
constructor(mockEvent?: LambdaEndpoint);
|
|
13
|
+
setHeader(_name: string, value: string): void;
|
|
14
|
+
write(chunk: Uint8Array, _encoding?: BufferEncoding): void;
|
|
15
|
+
end(chunk?: Uint8Array): void;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
getParsedResponse(): string | {
|
|
18
|
+
statusCode: number;
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": string;
|
|
21
|
+
};
|
|
22
|
+
body: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IDestination } from "../parseEvents/index";
|
|
2
|
+
interface ICallDestination {
|
|
3
|
+
destination: IDestination;
|
|
4
|
+
LOCAL_PORT: string;
|
|
5
|
+
event: any;
|
|
6
|
+
payload: any;
|
|
7
|
+
requestId: string;
|
|
8
|
+
lambdaName: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const callErrorDest: ({ destination, LOCAL_PORT, event, payload, requestId, lambdaName }: ICallDestination) => void;
|
|
11
|
+
export declare const callSuccessDest: ({ destination, LOCAL_PORT, event, payload, requestId, lambdaName, }: ICallDestination) => void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface IEventSourceMappingConfig {
|
|
2
|
+
AmazonManagedKafkaEventSourceConfig?: {
|
|
3
|
+
ConsumerGroupId: string;
|
|
4
|
+
};
|
|
5
|
+
BatchSize: number;
|
|
6
|
+
BisectBatchOnFunctionError?: boolean;
|
|
7
|
+
DestinationConfig?: {
|
|
8
|
+
OnFailure?: {
|
|
9
|
+
Destination: string;
|
|
10
|
+
};
|
|
11
|
+
OnSuccess?: {
|
|
12
|
+
Destination: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
DocumentDBEventSourceConfig?: {
|
|
16
|
+
CollectionName: string;
|
|
17
|
+
DatabaseName: string;
|
|
18
|
+
FullDocument: "UpdateLookup" | "Default";
|
|
19
|
+
};
|
|
20
|
+
Enabled: boolean;
|
|
21
|
+
EventSourceArn: string;
|
|
22
|
+
FilterCriteria?: {
|
|
23
|
+
Filters: {
|
|
24
|
+
Pattern: string;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
FunctionName: string;
|
|
28
|
+
FunctionResponseTypes?: ["ReportBatchItemFailures"];
|
|
29
|
+
MaximumBatchingWindowInSeconds?: number;
|
|
30
|
+
MaximumRecordAgeInSeconds?: number;
|
|
31
|
+
MaximumRetryAttempts?: number;
|
|
32
|
+
ParallelizationFactor?: number;
|
|
33
|
+
Queues?: string[];
|
|
34
|
+
ScalingConfig?: {
|
|
35
|
+
MaximumConcurrency?: number;
|
|
36
|
+
};
|
|
37
|
+
SelfManagedEventSource?: {
|
|
38
|
+
Endpoints?: string[];
|
|
39
|
+
};
|
|
40
|
+
SelfManagedKafkaEventSourceConfig?: {
|
|
41
|
+
ConsumerGroupId?: string;
|
|
42
|
+
};
|
|
43
|
+
SourceAccessConfigurations?: {
|
|
44
|
+
Type?: "BASIC_AUTH" | "VPC_SUBNET" | "VPC_SECURITY_GROUP" | "SASL_SCRAM_512_AUTH" | "SASL_SCRAM_256_AUTH" | "VIRTUAL_HOST" | "CLIENT_CERTIFICATE_TLS_AUTH" | "SERVER_ROOT_CA_CERTIFICATE";
|
|
45
|
+
URI?: string;
|
|
46
|
+
}[];
|
|
47
|
+
StartingPosition?: "TRIM_HORIZON" | "LATEST" | "AT_TIMESTAMP";
|
|
48
|
+
StartingPositionTimestamp?: number;
|
|
49
|
+
Topics?: string[];
|
|
50
|
+
TumblingWindowInSeconds?: number;
|
|
51
|
+
}
|
|
52
|
+
export declare abstract class EventSourceMapping {
|
|
53
|
+
config: IEventSourceMappingConfig;
|
|
54
|
+
static SOURCES: EventSourceMapping[];
|
|
55
|
+
UUID: `${string}-${string}-${string}-${string}-${string}`;
|
|
56
|
+
LastModified: number;
|
|
57
|
+
LastProcessingResult: "No records processed";
|
|
58
|
+
State: "Creating" | "Enabling" | "Enabled" | "Disabling" | "Disabled";
|
|
59
|
+
StateTransitionReason: "USER_INITIATED" | "User action";
|
|
60
|
+
private compiledFilterPolicy?;
|
|
61
|
+
constructor(config: IEventSourceMappingConfig);
|
|
62
|
+
filterRecords(records: any[]): any[][];
|
|
63
|
+
abstract init(): Promise<void> | void;
|
|
64
|
+
abstract enable(): Promise<void> | void;
|
|
65
|
+
abstract disable(): Promise<void> | void;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{randomUUID as L}from"node:crypto";var m=class extends Error{},s=class extends m{constructor(e){let n="Invalid Filter Pattern";e&&(n+=`: ${e}`),super(n),this.name="InvalidEventPatternException"}};import{EventSourceMapping as at}from"exlo/internal/esm";import{EventSourceMapping as K}from"exlo/internal/esm";var u=t=>Object.prototype.toString.call(t)=="[object Object]";var x=["*","\\"],E=[".","^","$","+","?","(",")","[","{","|"];function w(t){let e=t.split("");for(let a=0;a<e.length;a++)if(e[a]=="\\"){let c=e[a+1];if(!c||!x.includes(c))throw new s("Using backslash to escape characters other than * and \\ is not supported.")}let n=t;for(let a of E)n=n.replaceAll(a,["\\",a].join(""));let r=["^"];for(let a=0;a<n.split("").length;a++){let o=n[a];(o=="/"||o=="*")&&n[a-1]!="\\"&&(o=="/"?r.push("\\"):o=="*"&&r.push(".")),r.push(o)}let i=r.join("");try{return new RegExp(i)}catch{throw new s(`Invalid Wildcard pattern "${i}"`)}}function R(t){let e=new Map;for(let r of Object.keys(t)){let i=r.split(".")[0];e.set(i,(e.get(i)||0)+1)}let n=new Set;for(let[r,i]of e.entries())i>1&&n.add(r);return n}function F(t){let e={},n=R(t);for(let[r,i]of Object.entries(t)){let a=r.split(".")[0];if(n.has(a)){e[a]={"@invalid":["=:@"]};continue}if(r.includes(".")){let o=r.split("."),c=e;for(let d=0;d<o.length-1;d++){let h=o[d];h in c||(c[h]={}),c=c[h]}c[o[o.length-1]]=i}else e[r]=i}return e}function g(t){function e(n){let r=F(n);for(let[i,a]of Object.entries(r))if(a&&typeof a=="object"){if(!Array.isArray(a))r[i]=e(a);else if(i=="$or"){r[i]=[];for(let o of a){let c=g(o);r[i].push(c)}}}return r}return e(t)}var S=["<",">","<=",">="],C=["exists","numeric","anything-but","equals-ignore-case","prefix","suffix","cidr"],M=/^(?:(?:25[0-5]|2[0-4][0-9]|1?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|1?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/;function k(t){if(typeof t!="boolean")throw new s("exists match pattern must be either true or false")}function T(t){if(typeof t!="string")throw new s("equals-ignore-case match pattern must be a string")}function v(t){if(u(t)){let e=Object.keys(t);if(!e.length)throw new s("prefix: empty objects are not allowed");if(e.length>1)throw new s("prefix: only one key allowed in match expression");let n=e[0];if(n!="equals-ignore-case")throw new s(`Unsupported prefix pattern: ${n}`);if(typeof t[n]!="string")throw new s("prefix: equals-ignore-case match pattern must be a string");return}if(typeof t!="string")throw new s("prefix match pattern must be a string");if(!t)throw new s("Null prefix not allowed")}function P(t){if(u(t)){let e=Object.keys(t);if(!e.length)throw new s("suffix: empty objects are not allowed");if(e.length>1)throw new s("suffix: only one key allowed in match expression");let n=e[0];if(n!="equals-ignore-case")throw new s(`Unsupported suffix pattern: ${n}`);if(typeof t[n]!="string")throw new s("suffix: equals-ignore-case match pattern must be a string");return}if(typeof t!="string")throw new s("suffix match pattern must be a string");if(!t)throw new s("Null suffix not allowed")}var B=["prefix","suffix","wildcard","equals-ignore-case"];function O(t,e){if(typeof t=="boolean"||t===null)throw new s("Value of anything-but must be an array or single string/number value");if(u(t)){let n=Object.keys(t);if(!n.length)throw new s("Anything-But expression name not found");if(n.length>1)throw new s("Only one key allowed in match expression");let r=n[0];if(!B.includes(r))throw new s(`Unsupported anything-but pattern: ${r}`);let i=t[r];if(r=="wildcard"){if(Array.isArray(i)){for(let a of i)p(a,e);return}p(i,e)}if(typeof i=="string"||Array.isArray(i)&&i.every(a=>typeof a=="string"))return;throw new s(`Invalid anything-but ${r}: Must be string or array of string`)}if(Array.isArray(t)){let n;for(let r of t){let i=typeof r;if(i=="string"||i=="number"){if(n||(n=i),n!=i)throw new s("Inside anything but list, either all values are number or string, mixed type is not supported");continue}throw new s("Inside anything but list, start|null|boolean is not supported")}}}function N(t){if(!Array.isArray(t))throw new s("Value of numeric must be an array");if(!t.length)throw new s("Invalid member in numeric match");let e=t[0];if(e!="=")throw new s(`Unrecognized numeric range operator: ${e}`);if(e!="="&&!S.includes(e))throw new s(`Unrecognized numeric range operator: ${e}`);if(typeof t[1]!="number")throw new s("Value of equals must be numeric");if(t.length>2){if(e=="=")throw new s("Too many elements in numeric expression");let r=t[2];if(e==r||!S.includes(r)||t.length==3)throw new s(`Bad numeric range operator: ${r}`);if(typeof t[4]!="number")throw new s(`Value of ${r} must be numeric`);if(t.length!=4)throw new s("Too many terms in numeric range expression")}}function y(t){return t.split(".").map(Number).reduce((e,n)=>(e<<8)+n,0)>>>0}function D(t,e){if(typeof t!="string")throw new s("cidr match pattern must be a string");if(!M.test(t))throw t.includes("/")?new s("Malformed CIDR"):new s("Malformed CIDR, one '/' required");if(!e.cidrs.has(t)){let[n,r]=t.split("/");e.cidrs.set(t,{ip:y(n),subnet:Number(r)})}}function p(t,e){if(typeof t!="string")throw new s("wildcard match pattern must be a string");e.wildcards.has(t)||e.wildcards.set(t,w(t))}function U(t,e,n){switch(t){case"exists":k(e);break;case"numeric":N(e);break;case"anything-but":O(e,n);break;case"equals-ignore-case":T(e);break;case"prefix":v(e);break;case"suffix":P(e);break;case"wildcard":p(e,n);break;case"cidr":D(e,n);break;default:throw new s(`Unrecognized match type ${t}`)}}function q(t,e){for(let n of t){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null)continue;if(Array.isArray(n))throw new s("Match value must be String, number, true, false, or null");let r=Object.keys(n);if(!r.length)throw new s("Empty objects are not allowed");if(r.length>1)throw new s("Only one key allowed in match expression");let i=r[0];U(i,n[i],e)}}function V(t,e){if(t.length<2)throw new s("There must have at least 2 Objects in $or relationship.");for(let n of t){if(!u(n))throw new s("Only JSON object is allowed in array of $or relationship.");let r=Object.keys(n);if(!r.length)throw new s("Empty objects are not allowed");let i=r.find(a=>C.includes(a));if(i)throw new s(`${i} is Ruler reserved fieldName which cannot be used inside $or.`);b(n,e)}}function b(t,e){let n=0;for(let[r,i]of Object.entries(t)){if(n++,Array.isArray(i)){if(!i.length)throw new s("Empty arrays are not allowed");r=="$or"?V(i,e):q(i,e);continue}if(u(i)){b(i,e);continue}throw new s(`"${r}" must be an object or an array`)}if(!n)throw new s("Invalid filter pattern definition. Empty objects are not allowed.")}function I(t){if(!Array.isArray(t.Filters))throw new s("Policy must include Filters list");if(!t.Filters.length)throw new s("Filters list can not be empty");if(t.Filters.length>5)throw new s(`Too many filter patterns, maximum allowed 5 patterns, provided ${t.Filters.length} patterns.`);let e=[],n={wildcards:new Map,cidrs:new Map};for(let i of t.Filters){if(typeof i?.Pattern!="string")throw new s("Invalid Filter member. Filter must include Pattern valid JSON string");if(i.Pattern.length>4096)throw new s(`Too many characters provided for pattern, maximum allowed 4096 characters, provided ${i.Pattern.length} characters.`);let a;try{a=JSON.parse(i.Pattern)}catch{throw new s("failed to parse Pattern JSON")}if(!u(a))throw new s("Pattern must be an object");b(a,n),e.push(a)}let r=[];for(let i of e){let a=g(i);r.push(a)}return{patterns:r,validatorData:n}}function j(t,e){if(typeof e!="number")return!1;for(let n=0;n<t.length;n+=2){let r=t[n],i=t[n+1];if(!$(e,r,i))return!1}return!0}function $(t,e,n){switch(e){case"=":return t===n;case">":return t>n;case">=":return t>=n;case"<":return t<n;case"<=":return t<=n;default:return!1}}function _(t,e,n){let{ip:r,subnet:i}=n.cidrs.get(t),a=y(e),o=~(2**(32-i)-1)>>>0;return(a&o)===(r&o)}function f(t,e,n){if(t&&typeof t=="object"&&!Array.isArray(t)){if(t["anything-but"])return Array.isArray(t["anything-but"])?t["anything-but"].indexOf(e)==-1:!f(t["anything-but"],e,n);if(t["equals-ignore-case"]){if(typeof e!="string")return!1;let r=e.toLowerCase();return Array.isArray(t["equals-ignore-case"])?t["equals-ignore-case"].some(i=>i.toLowerCase()===r):r==t["equals-ignore-case"].toLowerCase()}if(t.cidr)return typeof e!="string"?!1:_(t.cidr,e,n);if(t.prefix){if(typeof e!="string")return!1;if(typeof t.prefix=="string")return e.startsWith(t.prefix);if(Array.isArray(t.prefix))return t.prefix.some(r=>e.startsWith(r));if(typeof t.prefix=="object"&&typeof t.prefix["equals-ignore-case"]=="string")return e.toLowerCase().startsWith(t.prefix["equals-ignore-case"].toLowerCase())}if(t.suffix){if(typeof e!="string")return!1;if(typeof t.suffix=="string")return e.endsWith(t.suffix);if(Array.isArray(t.suffix))return t.suffix.some(r=>e.endsWith(r));if(typeof t.suffix=="object"&&typeof t.suffix["equals-ignore-case"]=="string")return typeof e=="string"&&e.toLowerCase().endsWith(t.suffix["equals-ignore-case"].toLowerCase())}if(t.exists!==void 0)return t.exists?e!==void 0:e===void 0;if(t.numeric)return j(t.numeric,e);if(t.$or)return t.$or.some(r=>l(r,e,n));if(t.wildcard)return typeof e!="string"?!1:Array.isArray(t.wildcard)?t.wildcard.some(r=>n.wildcards.get(r).test(e)):n.wildcards.get(t.wildcard).test(e)}if(Array.isArray(t)){if(Array.isArray(e)){if(!e.length){let r=t[0];if(u(r)&&"exists"in r)return!!r.exists}return t.some(r=>e.some(i=>f(r,i,n)))}return t.some(r=>f(r,e,n))}return e===t}function l(t,e,n){let r=[];for(let[i,a]of Object.entries(t)){if(Array.isArray(a)){if(i=="$or"){if(!a.some(c=>l(c,e,n)))return!1;r.push(!0)}else{if(!f(a,e?.[i],n))return!1;r.push(!0)}continue}r.push(l(a,e?.[i],n))}return!r.some(i=>!i)}var A=class{constructor(e){this.config=e;this.config.FilterCriteria&&(this.compiledFilterPolicy=I(this.config.FilterCriteria))}static SOURCES=[];UUID=L();LastModified=Date.now();LastProcessingResult="No records processed";State="Creating";StateTransitionReason="User action";compiledFilterPolicy;filterRecords(e){let n=[],r=[];if(!this.compiledFilterPolicy)return[e,[]];for(let i of e)this.compiledFilterPolicy.patterns.some(o=>l(o,i,this.compiledFilterPolicy.validatorData))?n.push(i):r.push(i);return[n,r]}};export{A as EventSourceMapping};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ILambdaMock } from "../rapidApi";
|
|
2
|
+
type onInvokeFinished = (records: any[], result: any) => Promise<void> | void;
|
|
3
|
+
export declare class EsmBatch {
|
|
4
|
+
#private;
|
|
5
|
+
private MaximumBatchingWindowInSeconds;
|
|
6
|
+
private BatchSize;
|
|
7
|
+
private lambdaName;
|
|
8
|
+
private handlers;
|
|
9
|
+
private onInvokeFinished;
|
|
10
|
+
available: boolean;
|
|
11
|
+
constructor(MaximumBatchingWindowInSeconds: number, BatchSize: number, lambdaName: string, handlers: ILambdaMock[], onInvokeFinished: onInvokeFinished);
|
|
12
|
+
get messages(): any[];
|
|
13
|
+
setRecord(message: any): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function ipToInt(ip: string): number;
|
|
2
|
+
export interface IValidatorData {
|
|
3
|
+
wildcards: Map<string, RegExp>;
|
|
4
|
+
cidrs: Map<string, {
|
|
5
|
+
ip: number;
|
|
6
|
+
subnet: number;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare function compileFilterPolicy(policy: Record<string, any>): {
|
|
10
|
+
patterns: any[];
|
|
11
|
+
validatorData: IValidatorData;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compileWildcard(pattern: string): RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function expandDotPathsWithStrictConflicts(input: Record<string, any>): Record<string, any>;
|
package/dist/lib/runtime/eventSourceMapping/filter/expandDotPathsWithStrictConflicts.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SQS } from "@aws-sdk/client-sqs";
|
|
2
|
+
import { EventSourceMapping, type IEventSourceMappingConfig } from "exlo/internal/esm";
|
|
3
|
+
import type { ILambdaMock } from "../rapidApi";
|
|
4
|
+
export declare const SQS_DEFAULT_BATCH_SIZE = 10;
|
|
5
|
+
export declare const SQS_DEFAULT_MaximumBatchingWindowInSeconds = 0;
|
|
6
|
+
export declare class SqsEventSourceMapping extends EventSourceMapping {
|
|
7
|
+
#private;
|
|
8
|
+
config: IEventSourceMappingConfig;
|
|
9
|
+
handlers: ILambdaMock[];
|
|
10
|
+
sqsClient: SQS;
|
|
11
|
+
QueueName: string;
|
|
12
|
+
QueueUrl: string;
|
|
13
|
+
constructor(config: IEventSourceMappingConfig, handlers: ILambdaMock[], sqsClient: SQS);
|
|
14
|
+
onInvokeFinished(records: any[], result: any): Promise<void>;
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
cleanBatchs(): void;
|
|
17
|
+
enable(): Promise<void>;
|
|
18
|
+
disable(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IAwsProvider } from "../../../standalone_types";
|
|
2
|
+
import type { ILambdaMock } from "../rapidApi";
|
|
3
|
+
export declare const initEventSourceMapping: (lambdas: ILambdaMock[], aws: IAwsProvider) => Promise<void>;
|
|
4
|
+
export declare const getBatchItemFailures: (records: any[], response?: any) => any[] | undefined;
|
|
5
|
+
export declare const createBatch: (records: any, batchSize: number) => any[];
|
|
6
|
+
export declare const isJsObject: (value: any) => boolean;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
import type { IDdbEvent } from "../parseEvents/ddbStream";
|
|
3
|
+
import type { LambdaEndpoint } from "../parseEvents/endpoints";
|
|
4
|
+
import type { IDestination } from "../parseEvents/index";
|
|
5
|
+
import type { ISqs } from "../parseEvents/sqs";
|
|
6
|
+
import type { Runner } from "./runners/index";
|
|
7
|
+
type InvokeSub = (event: any, info?: any) => void | {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
type InvokeSuccessSub = (input: any, output: any, info?: any) => void;
|
|
11
|
+
type InvokeErrorSub = InvokeSuccessSub;
|
|
12
|
+
export interface ILambdaMock {
|
|
13
|
+
/**
|
|
14
|
+
* Function name.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
runtime: string;
|
|
18
|
+
ddb: IDdbEvent[];
|
|
19
|
+
sqs: ISqs[];
|
|
20
|
+
url?: LambdaEndpoint;
|
|
21
|
+
timeout: number;
|
|
22
|
+
memorySize: number;
|
|
23
|
+
environment: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* function handler.
|
|
28
|
+
*/
|
|
29
|
+
handlerPath: string;
|
|
30
|
+
/**
|
|
31
|
+
* exported function name
|
|
32
|
+
*/
|
|
33
|
+
handlerName: string;
|
|
34
|
+
/**
|
|
35
|
+
* esbuild entry point absolute path.
|
|
36
|
+
*/
|
|
37
|
+
esEntryPoint: string;
|
|
38
|
+
/**
|
|
39
|
+
* bundle absolute path.
|
|
40
|
+
*/
|
|
41
|
+
esOutputPath: string;
|
|
42
|
+
/**
|
|
43
|
+
* resolved entry point.
|
|
44
|
+
*/
|
|
45
|
+
entryPoint: string;
|
|
46
|
+
invokeSub: InvokeSub[];
|
|
47
|
+
invokeSuccessSub: InvokeSuccessSub[];
|
|
48
|
+
invokeErrorSub: InvokeErrorSub[];
|
|
49
|
+
/**
|
|
50
|
+
* Invoke this lambda.
|
|
51
|
+
*
|
|
52
|
+
* must always be called with "await" or ".then()"
|
|
53
|
+
* @returns {Promise}
|
|
54
|
+
* @throws Error
|
|
55
|
+
*/
|
|
56
|
+
invoke: (event: any, info?: any, clientContext?: any) => Promise<any>;
|
|
57
|
+
onError?: IDestination;
|
|
58
|
+
onSuccess?: IDestination;
|
|
59
|
+
onFailure?: IDestination;
|
|
60
|
+
runner: Runner;
|
|
61
|
+
shutdown(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export declare class LambdaMock implements ILambdaMock {
|
|
64
|
+
#private;
|
|
65
|
+
name: string;
|
|
66
|
+
runtime: string;
|
|
67
|
+
sqs: ISqs[];
|
|
68
|
+
ddb: IDdbEvent[];
|
|
69
|
+
url?: LambdaEndpoint;
|
|
70
|
+
timeout: number;
|
|
71
|
+
memorySize: number;
|
|
72
|
+
environment: {
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
};
|
|
75
|
+
handlerPath: string;
|
|
76
|
+
handlerName: string;
|
|
77
|
+
esEntryPoint: string;
|
|
78
|
+
esOutputPath: string;
|
|
79
|
+
entryPoint: string;
|
|
80
|
+
onError?: IDestination;
|
|
81
|
+
onSuccess?: IDestination;
|
|
82
|
+
onFailure?: IDestination;
|
|
83
|
+
invokeSub: InvokeSub[];
|
|
84
|
+
invokeSuccessSub: InvokeSuccessSub[];
|
|
85
|
+
invokeErrorSub: InvokeErrorSub[];
|
|
86
|
+
runner: Runner;
|
|
87
|
+
static ENABLE_TIMEOUT: boolean;
|
|
88
|
+
constructor({ name, runtime, timeout, memorySize, environment, handlerPath, handlerName, esEntryPoint, esOutputPath, entryPoint, sqs, ddb, url, invokeSub, invokeSuccessSub, invokeErrorSub, onError, onSuccess, onFailure, runner, }: ILambdaMock & {
|
|
89
|
+
runner: Runner;
|
|
90
|
+
});
|
|
91
|
+
handleErrorDestination(event: any, info: any, error: any, awsRequestId: string): void;
|
|
92
|
+
handleSuccessDestination(event: any, info: any, response: any, awsRequestId: string): void;
|
|
93
|
+
invoke(event: any, info?: any, clientContext?: any, response?: ServerResponse): Promise<unknown>;
|
|
94
|
+
clear: () => void;
|
|
95
|
+
shutdown(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
export type { ISqs, IDdbEvent, IDestination, LambdaEndpoint };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
interface IRunnerInvoke {
|
|
3
|
+
event: any;
|
|
4
|
+
awsRequestId: string;
|
|
5
|
+
info?: any;
|
|
6
|
+
clientContext?: any;
|
|
7
|
+
response?: ServerResponse;
|
|
8
|
+
}
|
|
9
|
+
export interface Runner {
|
|
10
|
+
isMounted: boolean;
|
|
11
|
+
mount: () => Promise<any> | any;
|
|
12
|
+
unmount: (lifecycleEnds?: boolean) => Promise<any> | any;
|
|
13
|
+
invoke: (request: IRunnerInvoke) => Promise<any>;
|
|
14
|
+
onComplete: (awsRequestId: string, timeout?: boolean) => any;
|
|
15
|
+
}
|
|
16
|
+
export declare class UnsupportedRuntime implements Runner {
|
|
17
|
+
err: Error;
|
|
18
|
+
constructor(runtime: string);
|
|
19
|
+
isMounted: boolean;
|
|
20
|
+
mount: () => undefined;
|
|
21
|
+
unmount: () => undefined;
|
|
22
|
+
invoke: () => Promise<never>;
|
|
23
|
+
onComplete: () => undefined;
|
|
24
|
+
}
|
|
25
|
+
export {};
|