Skip to content

Commit

Permalink
Avoid cyclic import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Dec 18, 2024
1 parent a892b72 commit a8dfc8f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 73 deletions.
67 changes: 67 additions & 0 deletions library/agent/getWrappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { BetterSQLite3 } from "../sinks/BetterSQLite3";
import { ChildProcess } from "../sinks/ChildProcess";
import { ClickHouse } from "../sinks/ClickHouse";
import { Eval } from "../sinks/Eval";
import { Fetch } from "../sinks/Fetch";
import { FileSystem } from "../sinks/FileSystem";
import { Function } from "../sinks/Function";
import { HTTPRequest } from "../sinks/HTTPRequest";
import { MariaDB } from "../sinks/MariaDB";
import { MongoDB } from "../sinks/MongoDB";
import { MySQL } from "../sinks/MySQL";
import { MySQL2 } from "../sinks/MySQL2";
import { NodeSQLite } from "../sinks/NodeSqlite";
import { Path } from "../sinks/Path";
import { Postgres } from "../sinks/Postgres";
import { Postgresjs } from "../sinks/Postgresjs";
import { Shelljs } from "../sinks/Shelljs";
import { SQLite3 } from "../sinks/SQLite3";
import { Undici } from "../sinks/Undici";
import { Express } from "../sources/Express";
import { Fastify } from "../sources/Fastify";
import { FastXmlParser } from "../sources/FastXmlParser";
import { FunctionsFramework } from "../sources/FunctionsFramework";
import { GraphQL } from "../sources/GraphQL";
import { Hapi } from "../sources/Hapi";
import { Hono } from "../sources/Hono";
import { HTTPServer } from "../sources/HTTPServer";
import { Koa } from "../sources/Koa";
import { PubSub } from "../sources/PubSub";
import { Xml2js } from "../sources/Xml2js";
import { XmlMinusJs } from "../sources/XmlMinusJs";

export function getWrappers() {
return [
new Express(),
new MongoDB(),
new Postgres(),
new MySQL(),
new MySQL2(),
new PubSub(),
new FunctionsFramework(),
new ChildProcess(),
new FileSystem(),
new HTTPRequest(),
new Fetch(),
new Undici(),
new Path(),
new HTTPServer(),
new Hono(),
new GraphQL(),
new Xml2js(),
new FastXmlParser(),
new SQLite3(),
new XmlMinusJs(),
new Shelljs(),
new Hapi(),
new MariaDB(),
new NodeSQLite(),
new BetterSQLite3(),
new Postgresjs(),
new Fastify(),
new Koa(),
new ClickHouse(),
new Eval(),
new Function(),
];
}
76 changes: 4 additions & 72 deletions library/agent/protect.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import type { HttpFunction } from "@google-cloud/functions-framework";
import type { Handler } from "aws-lambda";
import { ChildProcess } from "../sinks/ChildProcess";
import { Fetch } from "../sinks/Fetch";
import { FileSystem } from "../sinks/FileSystem";
import { HTTPRequest } from "../sinks/HTTPRequest";
import { MariaDB } from "../sinks/MariaDB";
import { MongoDB } from "../sinks/MongoDB";
import { MySQL } from "../sinks/MySQL";
import { MySQL2 } from "../sinks/MySQL2";
import { Path } from "../sinks/Path";
import { Postgres } from "../sinks/Postgres";
import { Undici } from "../sinks/Undici";
import { Express } from "../sources/Express";
import {
createCloudFunctionWrapper,
FunctionsFramework,
} from "../sources/FunctionsFramework";
import { Hono } from "../sources/Hono";
import { HTTPServer } from "../sources/HTTPServer";
import { isDebugging } from "../helpers/isDebugging";
import { shouldBlock } from "../helpers/shouldBlock";
import { createCloudFunctionWrapper } from "../sources/FunctionsFramework";
import { createLambdaWrapper } from "../sources/Lambda";
import { PubSub } from "../sources/PubSub";
import { Agent } from "./Agent";
import { getInstance, setInstance } from "./AgentSingleton";
import { ReportingAPI } from "./api/ReportingAPI";
Expand All @@ -29,26 +13,10 @@ import { ReportingAPIRateLimitedServerSide } from "./api/ReportingAPIRateLimited
import { ReportingAPIThatValidatesToken } from "./api/ReportingAPIThatValidatesToken";
import { Token } from "./api/Token";
import { getAPIURL } from "./getAPIURL";
import { getWrappers } from "./getWrappers";
import { Logger } from "./logger/Logger";
import { LoggerConsole } from "./logger/LoggerConsole";
import { LoggerNoop } from "./logger/LoggerNoop";
import { GraphQL } from "../sources/GraphQL";
import { Xml2js } from "../sources/Xml2js";
import { FastXmlParser } from "../sources/FastXmlParser";
import { SQLite3 } from "../sinks/SQLite3";
import { XmlMinusJs } from "../sources/XmlMinusJs";
import { Hapi } from "../sources/Hapi";
import { Shelljs } from "../sinks/Shelljs";
import { NodeSQLite } from "../sinks/NodeSqlite";
import { BetterSQLite3 } from "../sinks/BetterSQLite3";
import { isDebugging } from "../helpers/isDebugging";
import { shouldBlock } from "../helpers/shouldBlock";
import { Postgresjs } from "../sinks/Postgresjs";
import { Fastify } from "../sources/Fastify";
import { Koa } from "../sources/Koa";
import { ClickHouse } from "../sinks/ClickHouse";
import { Eval } from "../sinks/Eval";
import { Function } from "../sinks/Function";

function getLogger(): Logger {
if (isDebugging()) {
Expand Down Expand Up @@ -107,42 +75,6 @@ function getAgent({ serverless }: { serverless: string | undefined }) {
return agent;
}

export function getWrappers() {
return [
new Express(),
new MongoDB(),
new Postgres(),
new MySQL(),
new MySQL2(),
new PubSub(),
new FunctionsFramework(),
new ChildProcess(),
new FileSystem(),
new HTTPRequest(),
new Fetch(),
new Undici(),
new Path(),
new HTTPServer(),
new Hono(),
new GraphQL(),
new Xml2js(),
new FastXmlParser(),
new SQLite3(),
new XmlMinusJs(),
new Shelljs(),
new Hapi(),
new MariaDB(),
new NodeSQLite(),
new BetterSQLite3(),
new Postgresjs(),
new Fastify(),
new Koa(),
new ClickHouse(),
new Eval(),
new Function(),
];
}

// eslint-disable-next-line import/no-unused-modules
export function protect() {
const agent = getAgent({
Expand Down
2 changes: 1 addition & 1 deletion library/bundler/externals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWrappers } from "../agent/getWrappers";
import { Hooks } from "../agent/hooks/Hooks";
import { getWrappers } from "../agent/protect";

export function externals() {
const wrappers = getWrappers();
Expand Down

0 comments on commit a8dfc8f

Please sign in to comment.