Skip to content

Commit

Permalink
feat(deno/sdk): throw on unsupported cases
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-0acf4 committed Feb 23, 2024
1 parent 7f25865 commit aa50f6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions typegate/tests/runtimes/deno/deno_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ Meta.test("Deno runtime with typescript", async (t) => {
await gql`
query {
hello(name: "World")
helloFn(name: "World!")
helloFn(name: "wOrLd")
}
`
.expectData({
hello: "Hello World",
helloFn: "Hello World!",
helloFn: "Hello world",
})
.on(e);
});
Expand Down
4 changes: 2 additions & 2 deletions typegate/tests/runtimes/deno/deno_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

const hello = ({ name }: any) => `Hello ${name}`;
function helloFn({ name }: any) {
return `Hello ${name}`;
return `Hello ${(name as string).toLowerCase()}`;
}

typegraph("test-deno-static", (g: any) => {
typegraph("test-deno-tyepscript", (g: any) => {
const deno = new DenoRuntime();
const pub = Policy.public();

Expand Down
18 changes: 17 additions & 1 deletion typegraph/node/sdk/src/runtimes/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ export interface DenoImport {
}

function stringifyFn(code: string | Function) {
return typeof code == "function" ? code.toString() : code;
if (typeof code == "function") {
const source = code.toString();
const namedFnMatch = source.match(/function\s*(\*?\s*[a-zA-Z0-9_]+)/);
if (namedFnMatch) {
const [, name] = namedFnMatch;
if (name.replace(/s/g, "").startsWith("*")) {
throw new Error(`Generator function "${name}" not supported`);
}
if (/function\s[a-zA-Z0-9_]+\(\) { \[native code\] }/.test(source)) {
throw new Error(
`"${name}" is not supported as it is a native function`,
);
}
}
return source;
}
return code;
}

export class DenoRuntime extends Runtime {
Expand Down

0 comments on commit aa50f6a

Please sign in to comment.