Skip to content

Commit

Permalink
updating for lint in deno 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mimiMonads committed Oct 25, 2024
1 parent fde7408 commit d42a284
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 88 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
}
}
2 changes: 1 addition & 1 deletion src/composer/checkPetition/checkTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default (((regex) => ({
(innerString) =>
innerString.slice(
innerString.indexOf("("),
innerString.indexOf(")") + 1 ?? innerString.indexOf("=") + 1,
innerString.indexOf(")") + 1 || innerString.indexOf("=") + 1,
)
)(
f.toString(),
Expand Down
49 changes: 25 additions & 24 deletions src/composer/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@ type Table = {

type CTX = WithPlugins<any, any, any, any, any, any, any, any, any>;

const compose = (o?: FunRouterOptions<any>) =>
(p: Petition): (ctx: Request) => Promise<Response> | Response =>
((isUsing) =>
(
(table) =>
resolveF(o)(table)(p)(isUsing) as (
ctx: Request,
) => Promise<Response> | Response
)(
//elements int table
{
isAsync: tools.localAsync(o)(p)(isUsing),
asyncResolve: tools.recursiveCheckAsync(p),
headers: typeof p.headings === "object" || typeof o?.cors === "object"
? {
...p.headings,
headers: joinHeaders(o)(p),
}
: null,
},
))(
tools.isUsing(o)(p),
);
const compose =
(o?: FunRouterOptions<any>) =>
(p: Petition): (ctx: Request) => Promise<Response> | Response =>
((isUsing) =>
(
(table) =>
resolveF(o)(table)(p)(isUsing) as (
ctx: Request,
) => Promise<Response> | Response
)(
//elements int table
{
isAsync: tools.localAsync(o)(p)(isUsing),
asyncResolve: tools.recursiveCheckAsync(p),
headers: typeof p.headings === "object" || typeof o?.cors === "object"
? {
...p.headings,
headers: joinHeaders(o)(p),
}
: null,
},
))(
tools.isUsing(o)(p),
);

const resolveF =
(o?: FunRouterOptions<any>) =>
Expand Down Expand Up @@ -170,4 +171,4 @@ const asyncMaybeOf =
}
};

export default compose
export default compose;
97 changes: 48 additions & 49 deletions src/composer/linker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,51 @@ export type specialOptions = {
} & FunRouterOptions<any>;

export default (o?: specialOptions) => (f: Petition) => (isUsing: string[]) => {

// Base case: if 'isUsing' is empty and 'branch' is not in options, return the identity function
// TODO: change it and add the branch flag in the petition
if (isUsing.length === 0 && !(o && "branch" in o)) {
return (r: Request) => r;
}

// Generate the 'table' using nativeMaps
const table = nativeMaps(o)(f)(isUsing)(false);

// Generate 'functions' using nativeComponents
const functions = nativeComponents(o)(f)(table);

// Determine if asynchronous functions are needed
const needsAsync =
(f.resolve && tools.recursiveCheckAsync(f)) ||
f.f.constructor.name === "AsyncFunction" ||
table.some((x) => 'isAsync' in x && x.isAsync === true);

// Build the function chain prefix from 'table'
const functionChain = table
.filter((x) => x.type === 1)
.map((x) => `${x.name}=>`)
.join("");



// Determine the function signature based on options
let functionSignature = "";
if (needsAsync) {
functionSignature = o && "branch" in o ? " r=>async b=> " : " async r=> ";
} else {
functionSignature = o && "branch" in o ? "r=>b=>" : "r=>";
}

// Build the function body, injecting variables from 'table'
const functionBody = `({${table.map((x) => `${x.name}:${x.value}`).join(",")}})`;

// Build the full function string
const functionString = `return ${functionChain} ${functionSignature} ${functionBody}`;

// Create the function using 'new Function'
const generatedFunc = new Function(functionString)();

// Reduce the functions over the generated function
const resultFunction = functions.reduce((s, k) => s(k), generatedFunc);

return resultFunction;
};
// Base case: if 'isUsing' is empty and 'branch' is not in options, return the identity function
// TODO: change it and add the branch flag in the petition
if (isUsing.length === 0 && !(o && "branch" in o)) {
return (r: Request) => r;
}

// Generate the 'table' using nativeMaps
const table = nativeMaps(o)(f)(isUsing)(false);

// Generate 'functions' using nativeComponents
const functions = nativeComponents(o)(f)(table);

// Determine if asynchronous functions are needed
const needsAsync = (f.resolve && tools.recursiveCheckAsync(f)) ||
f.f.constructor.name === "AsyncFunction" ||
table.some((x) => "isAsync" in x && x.isAsync === true);

// Build the function chain prefix from 'table'
const functionChain = table
.filter((x) => x.type === 1)
.map((x) => `${x.name}=>`)
.join("");

// Determine the function signature based on options
let functionSignature = "";
if (needsAsync) {
functionSignature = o && "branch" in o ? " r=>async b=> " : " async r=> ";
} else {
functionSignature = o && "branch" in o ? "r=>b=>" : "r=>";
}

// Build the function body, injecting variables from 'table'
const functionBody = `({${
table.map((x) => `${x.name}:${x.value}`).join(",")
}})`;

// Build the full function string
const functionString =
`return ${functionChain} ${functionSignature} ${functionBody}`;

// Create the function using 'new Function'
const generatedFunc = new Function(functionString)();

// Reduce the functions over the generated function
const resultFunction = functions.reduce((s, k) => s(k), generatedFunc);

return resultFunction;
};
14 changes: 7 additions & 7 deletions src/exportable/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,12 @@ export const wrap = ((o?) => (a = []) => ({
{ ...ob, type: "base" } as Petition,
)),

logPaths: () =>
logPaths: () => (
void a.forEach(
(x) => displayPaths(x),
) ?? wrap(o)(a),
debugLast: () =>
), wrap(o)(a)
),
debugLast: () => (
void (
(isUsing) =>
display(o)(a[a.length - 1])({
Expand All @@ -554,8 +555,8 @@ export const wrap = ((o?) => (a = []) => ({
})
)(
composerTools.isUsing(o)(a[a.length - 1]),
) ??
wrap(o)(a),
), wrap(o)(a)
),
handleRequest: (s: string) =>
(
injection: Partial<
Expand All @@ -572,8 +573,7 @@ export const wrap = ((o?) => (a = []) => ({
} as unknown as Petition,
)(r),
)
: void console.error(s + " was not found.") ??
((_: Request) => Promise.resolve(null))) as unknown as (
: ((_: Request) => Promise.resolve(null))) as unknown as (
r: Request,
) => Promise<Response>,
testRequests: () =>
Expand Down
4 changes: 3 additions & 1 deletion src/morphism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ type MapOptions = {
specificReturnType?: boolean;
returnType?: any;
hasMaybe?: boolean;
maybe?: boolean;
};

type HasPath<P extends MapOptions> = P extends { hasPath: true }
Expand Down Expand Up @@ -583,7 +584,8 @@ export type Morphism<
): MO["specificReturnType"] extends true ? MO["returnType"]
: MO["type"] extends "response" ? Response | Promise<Response>
: MO["type"] extends "request" ? Response | Promise<Response>
: MO["type"] extends "add" ? Response | Promise<Response> | BodyInit | Promise<BodyInit> | null
: MO["type"] extends "add"
? Response | Promise<Response> | BodyInit | Promise<BodyInit> | null
: MO["type"] extends "base" ? BodyInit | Promise<BodyInit> | null
: R;
};
Expand Down
2 changes: 1 addition & 1 deletion src/staticFiles/composedPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default (o?: FunRouterOptions<any>) =>
: ({
path: root.slice(1, -1) + x.slice(name.length - 1),
type: "base",
...mimeIsTrue(f)("." + x.lastIndexOf(".") ?? "text"),
...mimeIsTrue(f)("." + x.lastIndexOf(".") || "text"),
f: staticFileTools.fromStringToPetition(
//@ts-ignore
typeof Deno === "object"
Expand Down

0 comments on commit d42a284

Please sign in to comment.