diff --git a/README.md b/README.md index 285cacb..c17bef9 100644 --- a/README.md +++ b/README.md @@ -79,12 +79,19 @@ This will map in `registry` to ### index.ts ```ts -import { createHandler } from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0-rc.5/packages/micro/mod.ts"; - -export default createHandler(async (_) => "Hello, world"); +import { + createHandler, + createResponse, +} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0/packages/micro/functions/mod.ts"; + +export default createHandler(async (req, res) => { + return createResponse({ + body: "Hello, World", + }); +}); ``` -`createHandler` gives you a Request object and requires a string or Response object. See typings in `packages/micro/mod.ts`. Handlers must _always_ be async. +`createHandler` gives you a server Request and an empty Response object that you can populate with your data. A Handler always returns a Response and _must always be async_. ### registry.json diff --git a/fixtures/dfn_reg/packages/micro/deps.ts b/fixtures/dfn_reg/packages/micro/deps.ts index 829f32f..b05f57c 100644 --- a/fixtures/dfn_reg/packages/micro/deps.ts +++ b/fixtures/dfn_reg/packages/micro/deps.ts @@ -1 +1 @@ -export * as server from "https://deno.land/std@0.61.0/http/server.ts"; +export * as server from "https://deno.land/std@0.62.0/http/server.ts"; diff --git a/fixtures/dfn_reg/packages/micro/functions/mod.ts b/fixtures/dfn_reg/packages/micro/functions/mod.ts new file mode 100644 index 0000000..255a6f5 --- /dev/null +++ b/fixtures/dfn_reg/packages/micro/functions/mod.ts @@ -0,0 +1,5 @@ +export { createHandler } from "../src/createHandler.ts"; +export { createResponse } from "../src/createResponse.ts"; +export { createResponseFromError } from "../src/createResponseFromError.ts"; +export { NetworkError } from "../src/networkError.ts"; +export { Request, Response, Handler, Methods } from "../src/types.ts"; diff --git a/fixtures/dfn_reg/packages/micro/lock.json b/fixtures/dfn_reg/packages/micro/lock.json index 9da1cfc..45f686b 100644 --- a/fixtures/dfn_reg/packages/micro/lock.json +++ b/fixtures/dfn_reg/packages/micro/lock.json @@ -1,14 +1,14 @@ { - "https://deno.land/std@0.61.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", - "https://deno.land/std@0.61.0/async/deferred.ts": "ac95025f46580cf5197928ba90995d87f26e202c19ad961bc4e3177310894cdc", - "https://deno.land/std@0.61.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a", - "https://deno.land/std@0.61.0/async/mod.ts": "bf46766747775d0fc4070940d20d45fb311c814989485861cdc8a8ef0e3bbbab", - "https://deno.land/std@0.61.0/async/mux_async_iterator.ts": "f6ca1b70f05e3cb676956d70a3230c99925288cf67e4e0b0bbaf34759b41945b", - "https://deno.land/std@0.61.0/bytes/mod.ts": "b1a149ac741728db00bda9ce1a2d044f248edd5ac95e708a6cc501bfd3adb4a7", - "https://deno.land/std@0.61.0/encoding/utf8.ts": "8654fa820aa69a37ec5eb11908e20b39d056c9bf1c23ab294303ff467f3d50a1", - "https://deno.land/std@0.61.0/http/_io.ts": "7a31bf7d0167685d8d0ff4eca93b558cd26539695d1ddbd715ee28bf1dc7db17", - "https://deno.land/std@0.61.0/http/http_status.ts": "0ecc0799a208f49452023b1b927106ba5a2c13cc6cf6666345db028239d554ab", - "https://deno.land/std@0.61.0/http/server.ts": "3bae933acb2645d863f0f87a91070d2478ad24b828ce27936711377426896b29", - "https://deno.land/std@0.61.0/io/bufio.ts": "dd1fc575524fe8b44e128091ba0e6833be7d0966336ef12a407544440b762e17", - "https://deno.land/std@0.61.0/textproto/mod.ts": "ee6bad9818d3fb44ecb2e0bbf9fc5b6a871fb332145800c54f732bf805dddff2" + "https://deno.land/std@0.62.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", + "https://deno.land/std@0.62.0/async/deferred.ts": "ac95025f46580cf5197928ba90995d87f26e202c19ad961bc4e3177310894cdc", + "https://deno.land/std@0.62.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a", + "https://deno.land/std@0.62.0/async/mod.ts": "bf46766747775d0fc4070940d20d45fb311c814989485861cdc8a8ef0e3bbbab", + "https://deno.land/std@0.62.0/async/mux_async_iterator.ts": "1352b10a5cee1821a963eb8f4f05603bd7e25f8886eaf8d1888f4b416ddccdf5", + "https://deno.land/std@0.62.0/bytes/mod.ts": "b1a149ac741728db00bda9ce1a2d044f248edd5ac95e708a6cc501bfd3adb4a7", + "https://deno.land/std@0.62.0/encoding/utf8.ts": "8654fa820aa69a37ec5eb11908e20b39d056c9bf1c23ab294303ff467f3d50a1", + "https://deno.land/std@0.62.0/http/_io.ts": "a6108623563611e901b1128ca91aca02982af552aa7c4f39f2240cf6e6cd9ac7", + "https://deno.land/std@0.62.0/http/http_status.ts": "0ecc0799a208f49452023b1b927106ba5a2c13cc6cf6666345db028239d554ab", + "https://deno.land/std@0.62.0/http/server.ts": "9f39d814950c741e0dcf0dfb9a046515f5fb342a62fbc28607c44ac5692e8a7e", + "https://deno.land/std@0.62.0/io/bufio.ts": "e76c5b7bf978a638aae6f62b87efde3ab7203b85902ce9b84ac8388c8c2bb104", + "https://deno.land/std@0.62.0/textproto/mod.ts": "ebd84342f62216af1850279d32581c51d0958e36d477c6c26c961987e6240356" } \ No newline at end of file diff --git a/fixtures/dfn_reg/packages/micro/src/createHandler.ts b/fixtures/dfn_reg/packages/micro/src/createHandler.ts index c29c5e6..b92cda7 100644 --- a/fixtures/dfn_reg/packages/micro/src/createHandler.ts +++ b/fixtures/dfn_reg/packages/micro/src/createHandler.ts @@ -1,17 +1,7 @@ import { server } from "../deps.ts"; import { createResponse } from "./createResponse.ts"; -import { NetworkError } from "./networkError.ts"; +import { returnNetworkErrorOnCatch } from "./createResponseFromError.ts"; import * as T from "./types.ts"; -export const createHandler = (h: T.Handler): T.LibHandler => async (req: server.ServerRequest) => { - try { - const response = createResponse(await h(req, createResponse({}))); - return response; - } catch (e) { - const E: NetworkError = e; - return createResponse({ - status: E.statusCode ?? 500, - body: E.message ?? `Internal Server Error`, - }); - } -}; +export const createHandler = (h: T.Handler): T.LibHandler => async (req: server.ServerRequest) => + returnNetworkErrorOnCatch(async () => createResponse(await h(req, createResponse({})))); diff --git a/fixtures/dfn_reg/packages/micro/src/createHandler_test.ts b/fixtures/dfn_reg/packages/micro/src/createHandler_test.ts index 725ef5c..d73b92c 100644 --- a/fixtures/dfn_reg/packages/micro/src/createHandler_test.ts +++ b/fixtures/dfn_reg/packages/micro/src/createHandler_test.ts @@ -35,3 +35,15 @@ Deno.test("should return error response", async () => { assertEquals(response.status, 404); assertEquals(response.body, "Not found"); }); + +Deno.test("should return generic error response", async () => { + const libHandler = createHandler( + mockHandler(() => { + throw new Error(); + }) + ); + + const response = await libHandler(mockRequest); + assertEquals(response.status, 500); + assertEquals(response.body, "Internal Server Error"); +}); diff --git a/fixtures/dfn_reg/packages/micro/src/createResponseFromError.ts b/fixtures/dfn_reg/packages/micro/src/createResponseFromError.ts index 8b9f705..f1debc0 100644 --- a/fixtures/dfn_reg/packages/micro/src/createResponseFromError.ts +++ b/fixtures/dfn_reg/packages/micro/src/createResponseFromError.ts @@ -1,9 +1,26 @@ import { createResponse } from "./createResponse.ts"; import { NetworkError } from "./networkError.ts"; +import { Response } from "./types.ts"; export const createResponseFromError = (e: NetworkError) => { return createResponse({ - status: e.statusCode ?? 500, - body: e.message ?? `Internal Server Error`, + status: e.statusCode, + body: e.message, }); }; + +export async function returnNetworkErrorOnCatch( + fn: (...args: any[]) => Promise +): Promise { + try { + const response = await fn(); + return response; + } catch (e) { + let error: NetworkError; + if (e instanceof NetworkError) error = e; + else if (e instanceof Error) + error = new NetworkError(500, e.message || "Internal Server Error"); + else error = new NetworkError(); + return createResponseFromError(error); + } +} diff --git a/fixtures/dfn_reg/packages/micro/src/networkError.ts b/fixtures/dfn_reg/packages/micro/src/networkError.ts index ffa889d..eb2bd76 100644 --- a/fixtures/dfn_reg/packages/micro/src/networkError.ts +++ b/fixtures/dfn_reg/packages/micro/src/networkError.ts @@ -1,6 +1,6 @@ export class NetworkError extends Error { statusCode: number; - constructor(statusCode: number = 500, message: string = "Internal server error") { + constructor(statusCode: number = 500, message: string = "Internal Server Error") { super(message); this.statusCode = statusCode; } diff --git a/fixtures/dfn_reg/packages/micro/src/networkError_test.ts b/fixtures/dfn_reg/packages/micro/src/networkError_test.ts index 914dec7..27e8e5e 100644 --- a/fixtures/dfn_reg/packages/micro/src/networkError_test.ts +++ b/fixtures/dfn_reg/packages/micro/src/networkError_test.ts @@ -4,7 +4,7 @@ import { NetworkError } from "./networkError.ts"; Deno.test("NetworkError", () => { const defaultNetworkError = new NetworkError(); assertEquals(defaultNetworkError.statusCode, 500); - assertEquals(defaultNetworkError.message, "Internal server error"); + assertEquals(defaultNetworkError.message, "Internal Server Error"); let newNetworkError = new NetworkError(404, "Not found"); assertEquals(newNetworkError.statusCode, 404); diff --git a/fixtures/dfn_reg/packages/micro/src/router.test.ts b/fixtures/dfn_reg/packages/micro/src/router.test.ts new file mode 100644 index 0000000..563aa39 --- /dev/null +++ b/fixtures/dfn_reg/packages/micro/src/router.test.ts @@ -0,0 +1,61 @@ +import { assertEquals, ServerRequest } from "../../testing/mod.ts"; +import { createResponse } from "./createResponse.ts"; +import { Router } from "./router.ts"; + +const req1 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/" }); +const req2 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test" }); +const req3 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test?abc" }); +const req4 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test/abc" }); +const req5 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/testt" }); + +const body1 = "Hello, World!"; +const body2 = "Hello, Test!"; + +const app = new Router(); +app.use("/", async () => createResponse({ body: body1 })); +app.use("/test", async () => createResponse({ body: body2 })); + +Deno.test("should respond with data on request", async () => { + const response = await app.handle(req1(), createResponse({})); + assertEquals(response.body, body1); +}); + +Deno.test("should respond with different data on different routes", async () => { + const response1 = await app.handle(req1(), createResponse({})); + const response2 = await app.handle(req2(), createResponse({})); + assertEquals(response1.body, body1); + assertEquals(response2.body, body2); +}); + +Deno.test("should still route subroutes and queries to parent route", async () => { + const response3 = await app.handle(req3(), createResponse({})); + const response4 = await app.handle(req4(), createResponse({})); + assertEquals(response3.body, body2); + assertEquals(response4.body, body2); +}); + +Deno.test("should properly resolve routes and fallback to 404", async () => { + const response5 = await app.handle(req5(), createResponse({})); + assertEquals(response5.body, `Cannot find ${req5().url}`); +}); + +Deno.test( + "should properly resolve routes and fallback to default route when provided", + async () => { + const _app = new Router(); + _app.use(async (_, res) => ({ ...res, body: body1 })); + _app.use("/test", async (_, res) => ({ ...res, body: body2 })); + const response5 = await _app.handle(req5(), createResponse({})); + assertEquals(response5.body, body1); + } +); + +Deno.test("should make clear distinction between app.use with or without route", async () => { + const _app = new Router(); + _app.use(async () => createResponse({ body: "1" })); + _app.use("", async () => createResponse({ body: "2" })); + const responseA = await _app.handle(req1(), createResponse({})); + const responseB = await _app.handle(req2(), createResponse({})); + assertEquals(responseA.body, "2"); + assertEquals(responseB.body, "1"); +}); diff --git a/fixtures/dfn_reg/packages/micro/src/router.ts b/fixtures/dfn_reg/packages/micro/src/router.ts index 6dc97bb..5ffee49 100644 --- a/fixtures/dfn_reg/packages/micro/src/router.ts +++ b/fixtures/dfn_reg/packages/micro/src/router.ts @@ -1,4 +1,5 @@ import { createHandler } from "./createHandler.ts"; +import { createResponseFromError } from "./createResponseFromError.ts"; import { filterOutQuery } from "./filters.ts"; import { NetworkError } from "./networkError.ts"; import { serve } from "./serve.ts"; @@ -14,6 +15,9 @@ export class Router { private _stack: [[string] | [string, T.Methods], T.Handler][]; constructor() { this._stack = []; + this.use(async (req) => + createResponseFromError(new NetworkError(404, `Cannot find ${req.url}`)) + ); } use(middleware: T.Handler): void; @@ -22,7 +26,7 @@ export class Router { if (typeof pathOrMiddleware !== "string") { this._stack.push([[""], pathOrMiddleware]); } else if (typeof pathOrMiddleware === "string" && !!middleware) { - this._stack.push([[pathOrMiddleware], middleware]); + this._stack.push([[shouldStartWithSlash(pathOrMiddleware)], middleware]); } else { throw new NetworkError(); } @@ -45,9 +49,11 @@ export class Router { req.url = reqUrl; if (!method || method === req.method.toLowerCase()) { - if (filterOutQuery(reqUrl) === "/" && originalPath === "/") { + if (originalPath === "") { + return next(req, await layer(req, res)); + } else if (filterOutQuery(reqUrl) === "/" && originalPath === "/") { return next(req, await layer(req, res)); - } else if (reqUrl.startsWith(path)) { + } else if (filterOutQuery(reqUrl).split("/")[1] === path.split("/")[1]) { const strippedReq = assignUrl(req, shouldStartWithSlash(reqUrl.substring(path.length))); return next(req, await layer(strippedReq, res)); } else { diff --git a/fixtures/dfn_reg/packages/templates/bundle.ts b/fixtures/dfn_reg/packages/templates/bundle.ts index 2f726df..14dabf4 100644 --- a/fixtures/dfn_reg/packages/templates/bundle.ts +++ b/fixtures/dfn_reg/packages/templates/bundle.ts @@ -1,4 +1,4 @@ -import { serve } from "./packages/micro/mod.ts"; +import { serve } from "./packages/micro/src/serve.ts"; import fn from "./registry_in/%SCRIPT_NAME%/index.ts"; console.log("%SCRIPT_NAME%"); diff --git a/packages/micro/functions/mod.ts b/packages/micro/functions/mod.ts new file mode 100644 index 0000000..255a6f5 --- /dev/null +++ b/packages/micro/functions/mod.ts @@ -0,0 +1,5 @@ +export { createHandler } from "../src/createHandler.ts"; +export { createResponse } from "../src/createResponse.ts"; +export { createResponseFromError } from "../src/createResponseFromError.ts"; +export { NetworkError } from "../src/networkError.ts"; +export { Request, Response, Handler, Methods } from "../src/types.ts"; diff --git a/packages/micro/src/createHandler.ts b/packages/micro/src/createHandler.ts index c29c5e6..b92cda7 100644 --- a/packages/micro/src/createHandler.ts +++ b/packages/micro/src/createHandler.ts @@ -1,17 +1,7 @@ import { server } from "../deps.ts"; import { createResponse } from "./createResponse.ts"; -import { NetworkError } from "./networkError.ts"; +import { returnNetworkErrorOnCatch } from "./createResponseFromError.ts"; import * as T from "./types.ts"; -export const createHandler = (h: T.Handler): T.LibHandler => async (req: server.ServerRequest) => { - try { - const response = createResponse(await h(req, createResponse({}))); - return response; - } catch (e) { - const E: NetworkError = e; - return createResponse({ - status: E.statusCode ?? 500, - body: E.message ?? `Internal Server Error`, - }); - } -}; +export const createHandler = (h: T.Handler): T.LibHandler => async (req: server.ServerRequest) => + returnNetworkErrorOnCatch(async () => createResponse(await h(req, createResponse({})))); diff --git a/packages/micro/src/createHandler_test.ts b/packages/micro/src/createHandler_test.ts index 725ef5c..d73b92c 100644 --- a/packages/micro/src/createHandler_test.ts +++ b/packages/micro/src/createHandler_test.ts @@ -35,3 +35,15 @@ Deno.test("should return error response", async () => { assertEquals(response.status, 404); assertEquals(response.body, "Not found"); }); + +Deno.test("should return generic error response", async () => { + const libHandler = createHandler( + mockHandler(() => { + throw new Error(); + }) + ); + + const response = await libHandler(mockRequest); + assertEquals(response.status, 500); + assertEquals(response.body, "Internal Server Error"); +}); diff --git a/packages/micro/src/createResponseFromError.ts b/packages/micro/src/createResponseFromError.ts index 8b9f705..f1debc0 100644 --- a/packages/micro/src/createResponseFromError.ts +++ b/packages/micro/src/createResponseFromError.ts @@ -1,9 +1,26 @@ import { createResponse } from "./createResponse.ts"; import { NetworkError } from "./networkError.ts"; +import { Response } from "./types.ts"; export const createResponseFromError = (e: NetworkError) => { return createResponse({ - status: e.statusCode ?? 500, - body: e.message ?? `Internal Server Error`, + status: e.statusCode, + body: e.message, }); }; + +export async function returnNetworkErrorOnCatch( + fn: (...args: any[]) => Promise +): Promise { + try { + const response = await fn(); + return response; + } catch (e) { + let error: NetworkError; + if (e instanceof NetworkError) error = e; + else if (e instanceof Error) + error = new NetworkError(500, e.message || "Internal Server Error"); + else error = new NetworkError(); + return createResponseFromError(error); + } +} diff --git a/packages/micro/src/networkError.ts b/packages/micro/src/networkError.ts index ffa889d..eb2bd76 100644 --- a/packages/micro/src/networkError.ts +++ b/packages/micro/src/networkError.ts @@ -1,6 +1,6 @@ export class NetworkError extends Error { statusCode: number; - constructor(statusCode: number = 500, message: string = "Internal server error") { + constructor(statusCode: number = 500, message: string = "Internal Server Error") { super(message); this.statusCode = statusCode; } diff --git a/packages/micro/src/networkError_test.ts b/packages/micro/src/networkError_test.ts index 914dec7..27e8e5e 100644 --- a/packages/micro/src/networkError_test.ts +++ b/packages/micro/src/networkError_test.ts @@ -4,7 +4,7 @@ import { NetworkError } from "./networkError.ts"; Deno.test("NetworkError", () => { const defaultNetworkError = new NetworkError(); assertEquals(defaultNetworkError.statusCode, 500); - assertEquals(defaultNetworkError.message, "Internal server error"); + assertEquals(defaultNetworkError.message, "Internal Server Error"); let newNetworkError = new NetworkError(404, "Not found"); assertEquals(newNetworkError.statusCode, 404); diff --git a/packages/micro/src/router.test.ts b/packages/micro/src/router.test.ts new file mode 100644 index 0000000..563aa39 --- /dev/null +++ b/packages/micro/src/router.test.ts @@ -0,0 +1,61 @@ +import { assertEquals, ServerRequest } from "../../testing/mod.ts"; +import { createResponse } from "./createResponse.ts"; +import { Router } from "./router.ts"; + +const req1 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/" }); +const req2 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test" }); +const req3 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test?abc" }); +const req4 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/test/abc" }); +const req5 = () => Object.assign({}, new ServerRequest(), { method: "get", url: "/testt" }); + +const body1 = "Hello, World!"; +const body2 = "Hello, Test!"; + +const app = new Router(); +app.use("/", async () => createResponse({ body: body1 })); +app.use("/test", async () => createResponse({ body: body2 })); + +Deno.test("should respond with data on request", async () => { + const response = await app.handle(req1(), createResponse({})); + assertEquals(response.body, body1); +}); + +Deno.test("should respond with different data on different routes", async () => { + const response1 = await app.handle(req1(), createResponse({})); + const response2 = await app.handle(req2(), createResponse({})); + assertEquals(response1.body, body1); + assertEquals(response2.body, body2); +}); + +Deno.test("should still route subroutes and queries to parent route", async () => { + const response3 = await app.handle(req3(), createResponse({})); + const response4 = await app.handle(req4(), createResponse({})); + assertEquals(response3.body, body2); + assertEquals(response4.body, body2); +}); + +Deno.test("should properly resolve routes and fallback to 404", async () => { + const response5 = await app.handle(req5(), createResponse({})); + assertEquals(response5.body, `Cannot find ${req5().url}`); +}); + +Deno.test( + "should properly resolve routes and fallback to default route when provided", + async () => { + const _app = new Router(); + _app.use(async (_, res) => ({ ...res, body: body1 })); + _app.use("/test", async (_, res) => ({ ...res, body: body2 })); + const response5 = await _app.handle(req5(), createResponse({})); + assertEquals(response5.body, body1); + } +); + +Deno.test("should make clear distinction between app.use with or without route", async () => { + const _app = new Router(); + _app.use(async () => createResponse({ body: "1" })); + _app.use("", async () => createResponse({ body: "2" })); + const responseA = await _app.handle(req1(), createResponse({})); + const responseB = await _app.handle(req2(), createResponse({})); + assertEquals(responseA.body, "2"); + assertEquals(responseB.body, "1"); +}); diff --git a/packages/micro/src/router.ts b/packages/micro/src/router.ts index 6dc97bb..5ffee49 100644 --- a/packages/micro/src/router.ts +++ b/packages/micro/src/router.ts @@ -1,4 +1,5 @@ import { createHandler } from "./createHandler.ts"; +import { createResponseFromError } from "./createResponseFromError.ts"; import { filterOutQuery } from "./filters.ts"; import { NetworkError } from "./networkError.ts"; import { serve } from "./serve.ts"; @@ -14,6 +15,9 @@ export class Router { private _stack: [[string] | [string, T.Methods], T.Handler][]; constructor() { this._stack = []; + this.use(async (req) => + createResponseFromError(new NetworkError(404, `Cannot find ${req.url}`)) + ); } use(middleware: T.Handler): void; @@ -22,7 +26,7 @@ export class Router { if (typeof pathOrMiddleware !== "string") { this._stack.push([[""], pathOrMiddleware]); } else if (typeof pathOrMiddleware === "string" && !!middleware) { - this._stack.push([[pathOrMiddleware], middleware]); + this._stack.push([[shouldStartWithSlash(pathOrMiddleware)], middleware]); } else { throw new NetworkError(); } @@ -45,9 +49,11 @@ export class Router { req.url = reqUrl; if (!method || method === req.method.toLowerCase()) { - if (filterOutQuery(reqUrl) === "/" && originalPath === "/") { + if (originalPath === "") { + return next(req, await layer(req, res)); + } else if (filterOutQuery(reqUrl) === "/" && originalPath === "/") { return next(req, await layer(req, res)); - } else if (reqUrl.startsWith(path)) { + } else if (filterOutQuery(reqUrl).split("/")[1] === path.split("/")[1]) { const strippedReq = assignUrl(req, shouldStartWithSlash(reqUrl.substring(path.length))); return next(req, await layer(strippedReq, res)); } else { diff --git a/packages/registry-ui/package.json b/packages/registry-ui/package.json index 878d2c2..6670f75 100644 --- a/packages/registry-ui/package.json +++ b/packages/registry-ui/package.json @@ -1,6 +1,6 @@ { "name": "registry-ui", - "version": "1.0.0-rc.5", + "version": "1.0.0", "private": true, "dependencies": { "@auth0/auth0-react": "^1.0.0", diff --git a/packages/registry-ui/src/components/CreateFunction.tsx b/packages/registry-ui/src/components/CreateFunction.tsx index 0ab7663..7f0fdb2 100644 --- a/packages/registry-ui/src/components/CreateFunction.tsx +++ b/packages/registry-ui/src/components/CreateFunction.tsx @@ -57,16 +57,13 @@ export function CreateFunction({ reload }: { reload: () => void }) { index: `import { createHandler, createResponse, - Handler, -} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0-rc.5/packages/micro/mod.ts"; +} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0/packages/micro/functions/mod.ts"; -const handler: Handler = async () => { +export default createHandler(async (req, res) => { return createResponse({ body: "Hello, World", }); -}; - -export default createHandler(handler); +}); `, registry: { whitelist: [], diff --git a/packages/registry-ui/src/components/__snapshots__/CreateFunction.test.tsx.snap b/packages/registry-ui/src/components/__snapshots__/CreateFunction.test.tsx.snap index 43e90ea..8a39b90 100644 --- a/packages/registry-ui/src/components/__snapshots__/CreateFunction.test.tsx.snap +++ b/packages/registry-ui/src/components/__snapshots__/CreateFunction.test.tsx.snap @@ -118,16 +118,13 @@ exports[`renders with the correct styles 1`] = ` import { createHandler, createResponse, - Handler, -} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0-rc.5/packages/micro/mod.ts"; +} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0/packages/micro/functions/mod.ts"; -const handler: Handler = async () => { +export default createHandler(async (req, res) => { return createResponse({ body: "Hello, World", }); -}; - -export default createHandler(handler); +});
           
-  Handler
-          
-            ,
-          
-          
 
           
-            "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0-rc.5/packages/micro/mod.ts"
+            "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0/packages/micro/functions/mod.ts"
           
           
-            const
+            export
           
-           handler
+           
           
-            :
+            default
           
            
           
-            Handler
+            createHandler
           
-           
           
-            =
+            (
           
-           
           
@@ -228,6 +216,17 @@ export default createHandler(handler);
           >
             (
           
+          
+            req
+            
+              ,
+            
+             res
+          
           
@@ -310,37 +309,6 @@ export default createHandler(handler);
           >
             }
           
-          
-            ;
-          
-          
-
-
-          
-            export
-          
-           
-          
-            default
-          
-           
-          
-            createHandler
-          
-          
-            (
-          
-          handler
           
diff --git a/packages/registry/src/bundle.ts b/packages/registry/src/bundle.ts
index f4a648f..4234180 100644
--- a/packages/registry/src/bundle.ts
+++ b/packages/registry/src/bundle.ts
@@ -4,7 +4,7 @@ const toReplaceId = `%SCRIPT_NAME%`;
 const toReplacePortId = `%PORT%`;
 
 export const bundle = async (scriptName: string, port: number) => {
-  const toBundlePath = appendCwd(`/toBundle.ts`);
+  const toBundlePath = appendCwd(`/toBundle-${scriptName}.ts`);
 
   if (!dirExists(appendCwd(`/registry_in/${scriptName}`))) {
     throw new Error(`Function ${scriptName} does not exist.`);
@@ -17,18 +17,19 @@ export const bundle = async (scriptName: string, port: number) => {
   Deno.writeTextFileSync(toBundlePath, bundlerFile);
 
   try {
-    const p = runBundle(toBundlePath, appendCwd(`/registry/${scriptName}.js`));
-    await p.status();
-    p.close();
-
-    logger.system("Registry", `Successfully registered ${scriptName}`, "file");
+    await runBundle(scriptName, toBundlePath);
   } finally {
     // Clean up
     Deno.removeSync(toBundlePath);
   }
 };
 
-const runBundle = (toBundlePath: string, scriptPath: string) =>
-  Deno.run({
-    cmd: ["time", "deno", "bundle", toBundlePath, scriptPath],
-  });
+async function runBundle(scriptName: string, toBundlePath: string) {
+  const destination = appendCwd(`/registry/${scriptName}.js`);
+  const [diagnostics, emit] = await Deno.bundle(toBundlePath);
+
+  if (!diagnostics) {
+    Deno.writeTextFileSync(destination, emit);
+    logger.system("Registry", `Successfully registered ${scriptName}`, "file");
+  }
+}
diff --git a/packages/registry/src/index.ts b/packages/registry/src/index.ts
index 67ff391..e835e2c 100644
--- a/packages/registry/src/index.ts
+++ b/packages/registry/src/index.ts
@@ -17,4 +17,4 @@ const checkRegistry = async () => {
 };
 
 await checkRegistry();
-setInterval(() => checkRegistry(), 30_000);
+setInterval(() => checkRegistry(), 10_000);
diff --git a/packages/shared/src/logger.ts b/packages/shared/src/logger.ts
index 0b90988..4b8f3a0 100644
--- a/packages/shared/src/logger.ts
+++ b/packages/shared/src/logger.ts
@@ -22,7 +22,7 @@ const log = (tag: string, message: string, level: LogLevel) => {
     case "info":
       if (level === "verbose") return;
     case "verbose":
-      logFn(tag.padEnd(20), message.padStart(60));
+      logFn(tag, message);
   }
 };
 
diff --git a/packages/templates/bundle.ts b/packages/templates/bundle.ts
index 2f726df..14dabf4 100644
--- a/packages/templates/bundle.ts
+++ b/packages/templates/bundle.ts
@@ -1,4 +1,4 @@
-import { serve } from "./packages/micro/mod.ts";
+import { serve } from "./packages/micro/src/serve.ts";
 import fn from "./registry_in/%SCRIPT_NAME%/index.ts";
 
 console.log("%SCRIPT_NAME%");
diff --git a/packages/testing/deps.ts b/packages/testing/deps.ts
index 6a4bdf7..1c13004 100644
--- a/packages/testing/deps.ts
+++ b/packages/testing/deps.ts
@@ -1,2 +1,3 @@
 export * from "https://deno.land/std@0.62.0/testing/asserts.ts";
 export * from "https://deno.land/std@0.62.0/io/bufio.ts";
+export { ServerRequest } from "https://deno.land/std@0.62.0/http/server.ts";
diff --git a/packages/testing/lock.json b/packages/testing/lock.json
index d21da18..c9d14bb 100644
--- a/packages/testing/lock.json
+++ b/packages/testing/lock.json
@@ -1,8 +1,17 @@
 {
   "https://deno.land/std@0.62.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149",
+  "https://deno.land/std@0.62.0/async/deferred.ts": "ac95025f46580cf5197928ba90995d87f26e202c19ad961bc4e3177310894cdc",
+  "https://deno.land/std@0.62.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a",
+  "https://deno.land/std@0.62.0/async/mod.ts": "bf46766747775d0fc4070940d20d45fb311c814989485861cdc8a8ef0e3bbbab",
+  "https://deno.land/std@0.62.0/async/mux_async_iterator.ts": "1352b10a5cee1821a963eb8f4f05603bd7e25f8886eaf8d1888f4b416ddccdf5",
   "https://deno.land/std@0.62.0/bytes/mod.ts": "b1a149ac741728db00bda9ce1a2d044f248edd5ac95e708a6cc501bfd3adb4a7",
+  "https://deno.land/std@0.62.0/encoding/utf8.ts": "8654fa820aa69a37ec5eb11908e20b39d056c9bf1c23ab294303ff467f3d50a1",
   "https://deno.land/std@0.62.0/fmt/colors.ts": "eb606cfb06e3f03a0222f09768a9701de2dd31c1fc8fa3a939137792a472962a",
+  "https://deno.land/std@0.62.0/http/_io.ts": "a6108623563611e901b1128ca91aca02982af552aa7c4f39f2240cf6e6cd9ac7",
+  "https://deno.land/std@0.62.0/http/http_status.ts": "0ecc0799a208f49452023b1b927106ba5a2c13cc6cf6666345db028239d554ab",
+  "https://deno.land/std@0.62.0/http/server.ts": "9f39d814950c741e0dcf0dfb9a046515f5fb342a62fbc28607c44ac5692e8a7e",
   "https://deno.land/std@0.62.0/io/bufio.ts": "e76c5b7bf978a638aae6f62b87efde3ab7203b85902ce9b84ac8388c8c2bb104",
   "https://deno.land/std@0.62.0/testing/asserts.ts": "1e9f87e0ecc456caa00a95f3345c5a7aeea0a4bf25c443a54341d9f6e36e5edf",
-  "https://deno.land/std@0.62.0/testing/diff.ts": "b685fb818c3527f0890628711934863672de2e94f01db421731654243f1eac8f"
+  "https://deno.land/std@0.62.0/testing/diff.ts": "b685fb818c3527f0890628711934863672de2e94f01db421731654243f1eac8f",
+  "https://deno.land/std@0.62.0/textproto/mod.ts": "ebd84342f62216af1850279d32581c51d0958e36d477c6c26c961987e6240356"
 }
\ No newline at end of file
diff --git a/registry.Dockerfile b/registry.Dockerfile
index b66b153..6907f7b 100644
--- a/registry.Dockerfile
+++ b/registry.Dockerfile
@@ -13,4 +13,4 @@ ADD packages /functions/packages
 RUN /functions/denofn.sh cache reload
 RUN deno cache ./packages/registry/src/index.ts
 
-ENTRYPOINT ["deno", "run", "--allow-read=/functions", "--allow-write=/functions", "--allow-run", "./packages/registry/src/index.ts"]
+ENTRYPOINT ["deno", "run", "--unstable", "--allow-read=/functions", "--allow-write=/functions", "--allow-run", "./packages/registry/src/index.ts"]
diff --git a/static/asset-manifest.json b/static/asset-manifest.json
index 8aaf66f..40077ae 100644
--- a/static/asset-manifest.json
+++ b/static/asset-manifest.json
@@ -1,12 +1,12 @@
 {
   "files": {
     "main.css": "/static/css/main.52631082.chunk.css",
-    "main.js": "/static/js/main.68dfd46b.chunk.js",
+    "main.js": "/static/js/main.57770d27.chunk.js",
     "runtime-main.js": "/static/js/runtime-main.b6c99207.js",
     "static/css/2.42d961f9.chunk.css": "/static/css/2.42d961f9.chunk.css",
     "static/js/2.c6381a6d.chunk.js": "/static/js/2.c6381a6d.chunk.js",
     "index.html": "/index.html",
-    "precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js": "/precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js",
+    "precache-manifest.f669b744feb131854f1fc6a7c50f468f.js": "/precache-manifest.f669b744feb131854f1fc6a7c50f468f.js",
     "service-worker.js": "/service-worker.js",
     "static/js/2.c6381a6d.chunk.js.LICENSE.txt": "/static/js/2.c6381a6d.chunk.js.LICENSE.txt",
     "static/media/denofn_transparent.png": "/static/media/denofn_transparent.bc01bd66.png"
@@ -16,6 +16,6 @@
     "static/css/2.42d961f9.chunk.css",
     "static/js/2.c6381a6d.chunk.js",
     "static/css/main.52631082.chunk.css",
-    "static/js/main.68dfd46b.chunk.js"
+    "static/js/main.57770d27.chunk.js"
   ]
 }
\ No newline at end of file
diff --git a/static/index.html b/static/index.html
index 736b787..68f7e09 100644
--- a/static/index.html
+++ b/static/index.html
@@ -1 +1 @@
-denoFn
\ No newline at end of file +denoFn
\ No newline at end of file diff --git a/static/js/main.68dfd46b.chunk.js b/static/js/main.57770d27.chunk.js similarity index 60% rename from static/js/main.68dfd46b.chunk.js rename to static/js/main.57770d27.chunk.js index b467c19..18e6217 100644 --- a/static/js/main.68dfd46b.chunk.js +++ b/static/js/main.57770d27.chunk.js @@ -1 +1 @@ -(this["webpackJsonpregistry-ui"]=this["webpackJsonpregistry-ui"]||[]).push([[0],{31:function(e,t,a){e.exports=a.p+"static/media/denofn_transparent.bc01bd66.png"},38:function(e,t,a){e.exports=a(66)},46:function(e,t,a){},66:function(e,t,a){"use strict";a.r(t);var r=a(3),n=a(4),i=a(0),l=a.n(i),c=a(7),o=a.n(c),s=(a(46),a(2)),m=a(1);function u(e){return l.a.createElement("svg",Object.assign({viewBox:"0 0 24 24",width:24,height:24},e),l.a.createElement("path",{className:"prefix__heroicon-ui",d:"M5.41 11H21a1 1 0 010 2H5.41l5.3 5.3a1 1 0 01-1.42 1.4l-7-7a1 1 0 010-1.4l7-7a1 1 0 011.42 1.4L5.4 11z"}))}var d=a(31),g=a.n(d);function b(e){var t=e.title,a=e.onClick;return l.a.createElement("button",{onClick:a,className:Object(m.a)({boxSizing:"border-box",backgroundColor:"transparent",color:"white",borderColor:"white",fontWeight:"bold",borderWidth:"1px",borderStyle:"solid",borderRadius:"0.25rem",padding:"7px 1rem",cursor:"pointer",lineHeight:"1rem",fontSize:"1rem",":hover":{color:"black",backgroundColor:"white",borderColor:"transparent"}})},t)}var p=l.a.createContext([{current:"view-all"},function(){}]);function f(e){var t=e.children,a=l.a.useState({current:"view-all"});return l.a.createElement(p.Provider,{value:a},t)}function h(e){var t=e.title,a=void 0===t?"denoFn":t,n=l.a.useContext(p),i=Object(s.a)(n,2),c=i[0],o=c.current,d=c.manage,f=i[1],h=Object(r.b)(),v=h.isAuthenticated,E=h.loginWithRedirect;return l.a.createElement("header",{className:Object(m.a)({display:"flex",backgroundColor:"rgb(0, 0, 0)",color:"white",borderColor:"rgb(237,242,247)",borderBottomStyle:"solid",borderBottomWidth:"1px",height:"4rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginLeft:"auto",marginRight:"auto",width:"100%",paddingLeft:"1.5rem",paddingRight:"1.5rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex"})},"manage"===o||"create"===o?l.a.createElement(u,{onClick:function(){return f({current:"view-all"})},className:Object(m.a)({display:"inline-block",lineHeight:"1.5rem",marginTop:"1.25rem",marginBottom:"1.25rem",marginRight:"0.5rem",cursor:"pointer",fill:"white"})}):l.a.createElement("img",{className:Object(m.a)({marginTop:".5rem",height:"3rem",width:"3rem",lineHeight:"3rem",marginRight:".5rem"}),src:g.a,alt:"denoFn logo"}),l.a.createElement("h4",{className:Object(m.a)({display:"inline-block",lineHeight:"1.5rem",marginTop:"1.25rem",marginBottom:"1.25rem",textTransform:"lowercase"})},"manage"===o?d:"create"===o?"create fn":a)),l.a.createElement("div",{className:Object(m.a)({marginTop:"1rem"})},!v&&l.a.createElement(b,{title:"Sign in",onClick:function(){return E()}}))))}var v=a(13);function E(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({padding:"1.5rem"})},t)}var w=Object(m.b)({from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}});function y(e){var t=e.dim,a=e.thickness;return l.a.createElement("div",{className:Object(m.a)({display:"inline-block",transitionTimingFunction:"linear",width:t||"1.5rem",height:t||"1.5rem",borderWidth:null!==a&&void 0!==a?a:".25rem",borderColor:"#edf2f7",borderStyle:"solid",borderTopWidth:null!==a&&void 0!==a?a:".25rem",borderTopColor:"rgb(26, 32, 44)",borderRadius:"9999px",animation:"".concat(w," 1.5s linear infinite")})})}var O=l.a.memo((function(e){var t=e.className,a=e.loading,r=e.disabled,n=e.title,i=e.onClick;return l.a.createElement("button",{className:"".concat(Object(m.a)({backgroundColor:"transparent",fontWeight:"bold",padding:".5rem 1rem",borderWidth:"1px",borderStyle:"solid",borderColor:"rgb(26, 32, 44)",borderRadius:".25rem",lineHeight:"1rem",fontSize:"1rem",cursor:"pointer",":hover":{backgroundColor:"rgb(26, 32, 44) !important",color:"white",borderColor:"transparent"},":disabled":{color:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)",borderColor:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)",cursor:"not-allowed"},selectors:{"&:disabled:hover":{backgroundColor:"transparent !important",borderColor:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)"}}})).concat(t?" ".concat(t):""),disabled:null!==r&&void 0!==r&&r,onClick:i},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center"})},a&&l.a.createElement("span",{className:Object(m.a)({marginRight:".33rem"})},l.a.createElement(y,{dim:".66rem",thickness:".125rem"})),n))})),x=l.a.memo((function(){var e=l.a.useContext(p),t=Object(s.a)(e,2)[1];return l.a.createElement(O,{title:"Create Fn",onClick:function(){return t({current:"create"})}})}));function j(e){var t=e.title,a=e.message;return l.a.createElement("div",{className:Object(m.a)({paddingLeft:"1rem",paddingRight:"1rem",color:"rgb(197,48,48)",borderStyle:"solid",borderColor:"rgb(252,129,129)",borderRadius:".25rem",borderWidth:"1px",paddingTop:".75rem",paddingBottom:".75rem",position:"relative",backgroundColor:"rgb(255,245,245)"}),role:"alert"},l.a.createElement("strong",{className:Object(m.a)({fontFamily:"'Rubik', sans-serif",fontWeight:"bold",display:"block",lineHeight:"1.5rem"})},t),l.a.createElement("span",null,a))}function C(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({width:"100%",marginLeft:"auto",marginRight:"auto",display:"flex",alignItems:"center",justifyContent:"center"})},t)}function N(e){return l.a.createElement(C,null,l.a.createElement(j,e))}const k={display:"flex",alignItems:"flex-start",flexDirection:"column",justifyContent:"space-between"},S={display:"block"},H=l.a.memo((function({className:e,children:t,onClick:a,padding:r,flex:n=!0}){const i=null!==a&&void 0!==a?a:function(){},c=a?{cursor:"pointer"}:{};return l.a.createElement("div",{onClick:i,className:`${Object(m.a)({...c,...n?k:S,backgroundColor:"white",boxSizing:"border-box",borderRadius:".25rem",minHeight:"6rem",padding:null!==r&&void 0!==r?r:"1rem",boxShadow:"0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05)"})}${e?` ${e}`:""}`},t)}));var W=l.a.memo((function(e){var t=e.className,a=e.status,r=e.statusText,n=Object(s.a)(r,2),i=n[0],c=n[1];return l.a.createElement("div",{className:"".concat(t?"".concat(t," "):"").concat(Object(m.a)({display:"inline-block",borderRadius:"9999px",fontWeight:"bold",fontSize:".75rem",padding:".25rem .5rem",lineHeight:"1rem",textTransform:"uppercase",backgroundColor:a?"rgb(56,178,172)":"rgb(245,101,101)",color:"white"}))},a?i:c)}));function R(e){var t=e.children;return l.a.createElement("span",{className:Object(m.a)({wordBreak:"break-all"})},t)}var T=l.a.memo((function(e){var t=e.f,a=e.status,r=l.a.useContext(p),n=Object(s.a)(r,2)[1];return l.a.createElement(H,{onClick:function(){return n({current:"manage",manage:t})},key:t},l.a.createElement(R,null,t),l.a.createElement(W,{className:Object(m.a)({marginTop:".75rem"}),status:a,statusText:["warm","cold"]}))}));function F(){return l.a.createElement(C,null,l.a.createElement(y,null),l.a.createElement("h3",{className:Object(m.a)({display:"inline-block",lineHeight:"2rem",margin:"0",marginLeft:".5rem",alignSelf:"top"})},"Loading..."))}function I(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({width:"100%",display:"grid",gridGap:"1rem",gridTemplateColumns:"repeat(auto-fill, minmax(252px, 1fr))"})},t)}function B(){return window.location.origin}function L(e){return"".concat(B(),"/api/v1").concat(e)}function z(){var e=Object(r.b)(),t=e.isAuthenticated,a=e.user;return t?l.a.createElement(A,{isAuthenticated:!0,user:a}):l.a.createElement("div",null)}function A(e){var t=e.isAuthenticated,a=e.user,r=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===a||void 0===a?void 0:a.sub}}),i=r.get,c=r.loading,o=r.error,s=r.data;return l.a.useEffect((function(){t&&i()}),[t,i]),l.a.createElement(E,null,c&&l.a.createElement(F,null),o&&l.a.createElement(N,{title:"Error!",message:o.message}),!c&&!o&&!!s&&l.a.createElement(l.a.Fragment,null,l.a.createElement(I,null,[].concat(Object(v.a)(Object.keys(s).map((function(e){return l.a.createElement(T,{status:s[e],f:e,key:e})}))),[l.a.createElement(H,{key:"denofn-createNewFunctionAction-viewallfunctions"},l.a.createElement("div",{className:Object(m.a)({width:"100%",display:"flex",alignItems:"center",justifyContent:"center",height:"4rem"})},l.a.createElement(x,null)))]))))}var $=a(32),_=a.n($),D=a(33),M=a.n(D),J=a(16),V=a(34),P=a.n(V),U=(a(61),a(62),l.a.memo((function(e){var t=e.index,a=e.dispatch;return l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0"})},l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0 0.75rem",fontWeight:"bold"})},"index.ts"),l.a.createElement(P.a,{value:"".concat(t),onValueChange:function(e){a({type:"index",value:e})},highlight:function(e){return Object(J.highlight)(e,J.languages.ts,"ts")},onBlur:function(){var e=_.a.format("".concat(t),{semi:!0,printWidth:100,parser:"typescript",plugins:[M.a]});a({type:"index",value:e})},padding:4,className:Object(m.a)({fontFamily:"'Fira Code', monospace"})}))}))),K=a(37);function X(e){return{label:e,value:e}}function q(e){return(null!==e&&void 0!==e?e:[]).map((function(e){return e.value}))}var G=l.a.memo((function(e){var t,a=e.dispatch,r=e.registry,n=l.a.useState(""),i=Object(s.a)(n,2),c=i[0],o=i[1],u=l.a.useState(null===r||void 0===r?void 0:r.whitelist.map(X)),d=Object(s.a)(u,2),g=d[0],b=d[1];function p(e){b(e),a({type:"whitelist",value:q(e)})}return l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0"})},l.a.createElement("div",{className:Object(m.a)({fontWeight:"bold",marginBottom:"0.75rem"})},"URL Whitelist"),l.a.createElement(K.a,{components:{DropdownIndicator:null},inputValue:c,isClearable:!0,isMulti:!0,menuIsOpen:!1,placeholder:"Enter the domains you want to send requests to here...",value:g,onChange:p,onKeyDown:function(e){if(c)switch(e.key){case"Enter":case"Tab":p([].concat(Object(v.a)(null!==g&&void 0!==g?g:[]),[X(c)])),o(""),e.preventDefault()}},onInputChange:function(e){o(e)}}),l.a.createElement("div",{className:Object(m.a)({marginTop:"1.5rem",display:"flex",alignItems:"center"})},l.a.createElement("label",{htmlFor:"warmupOnStart",className:Object(m.a)({marginRight:".5rem",fontWeight:"bold"})},"Post-registration warmup"),l.a.createElement("input",{type:"checkbox",checked:null!==(t=null===r||void 0===r?void 0:r.warmupOnStart)&&void 0!==t&&t,id:"warmupOnStart",onChange:function(e){a({type:"warmupOnStart",value:!(null===r||void 0===r?void 0:r.warmupOnStart)})}})))}));function Q(e,t){switch(t.type){case"scriptName":return{...e,scriptName:t.value};case"index":return{...e,index:t.value};case"warmupOnStart":return{...e,registry:{...e.registry,warmupOnStart:t.value}};case"whitelist":return{...e,registry:{...e.registry,whitelist:t.value}};default:return e}}function Y({reload:e}){const{user:t}=Object(r.b)(),[a,i]=l.a.useReducer(Q,{scriptName:"",index:'import {\n createHandler,\n createResponse,\n Handler,\n} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0-rc.5/packages/micro/mod.ts";\n\nconst handler: Handler = async () => {\n return createResponse({\n body: "Hello, World",\n });\n};\n\nexport default createHandler(handler);\n',registry:{whitelist:[],warmupOnStart:!1}}),{post:c,loading:o,response:s,error:u,data:d}=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===t||void 0===t?void 0:t.sub}});return l.a.createElement(l.a.Fragment,null,u&&l.a.createElement(C,null,l.a.createElement(N,{title:"Something went wrong while creating your new function",message:d})),l.a.createElement(H,{padding:"1.5rem",flex:!1,className:Object(m.a)({minHeight:"calc(75vh - 7.5rem)",marginTop:u?"1.5rem":"0"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center",justifyContent:"space-between",margin:"0",marginBottom:"1.5rem"})},l.a.createElement("input",{className:Object(m.a)({width:"100%",padding:".25rem .5rem",lineHeight:"1.5rem",borderStyle:"none",backgroundColor:"transparent",appearance:"none",fontSize:"1.5rem",fontFamily:"'Rubik', sans-serif",fontWeight:"bold","::placeholder":{fontFamily:"'Karla', sans-serif",fontWeight:"initial"}}),value:a.scriptName,onChange:function(e){i({value:e.target.value,type:"scriptName"})},placeholder:"Enter your scriptname here",autoFocus:!0}),l.a.createElement(O,{disabled:""===a.scriptName,title:"Create",onClick:async function(){await c(a),s.ok&&e()},loading:o,className:Object(m.a)({marginLeft:"1.5rem"})})),l.a.createElement("hr",{color:"#e2e8f0"}),l.a.createElement(G,{registry:a.registry,dispatch:i}),l.a.createElement(U,{index:a.index,dispatch:i})))}function Z(){var e=l.a.useContext(p),t=Object(s.a)(e,2)[1],a=l.a.useCallback((function(){t({current:"view-all"})}),[t]);return l.a.createElement(E,null,l.a.createElement(Y,{reload:a}))}var ee=a(17),te=a.n(ee),ae=a(36);function re(e){return i.createElement("svg",Object.assign({viewBox:"0 0 24 24",width:24,height:24},e),i.createElement("path",{className:"prefix__heroicon-ui",d:"M19 6.41L8.7 16.71a1 1 0 11-1.4-1.42L17.58 5H14a1 1 0 010-2h6a1 1 0 011 1v6a1 1 0 01-2 0V6.41zM17 14a1 1 0 012 0v5a2 2 0 01-2 2H5a2 2 0 01-2-2V7c0-1.1.9-2 2-2h5a1 1 0 010 2H5v12h12v-5z"}))}function ne(e,t){switch(t.type){case"index":return{...e,index:t.value};case"warmupOnStart":return{...e,registry:{...e.registry,warmupOnStart:t.value}};case"whitelist":return{...e,registry:{...e.registry,whitelist:t.value}};default:return e}}function ie({scriptName:e,isWarmedUp:t,reload:a,...i}){const{user:c}=Object(r.b)(),[o,s]=l.a.useReducer(ne,{index:i.index,registry:i.registry}),{post:u,loading:d,response:g}=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===c||void 0===c?void 0:c.sub}}),b=(p={index:i.index,registry:i.registry},f=o,p.index===f.index&&p.registry.warmupOnStart===f.registry.warmupOnStart&&JSON.stringify(p.registry.whitelist)===JSON.stringify(f.registry.whitelist));var p,f;return l.a.createElement(H,{padding:"1.5rem",flex:!1,className:Object(m.a)({minHeight:"calc(75vh - 7.5rem)"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center",justifyContent:"space-between",margin:"0",marginBottom:"1.5rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center"})},l.a.createElement("h2",{className:Object(m.a)({margin:"0",lineHeight:"1.5rem",fontSize:"1.5rem"})},e),l.a.createElement("a",{href:`${B()}/${e}`,target:"_blank",rel:"noopener noreferrer",className:Object(m.a)({height:"1.5rem",width:"1.5rem"})},l.a.createElement(re,{className:Object(m.a)({marginLeft:".25rem",fill:"rgba(26, 32, 44, 0.5)",alignSelf:"flex-start"})})),l.a.createElement(W,{className:Object(m.a)({marginLeft:".75rem"}),status:null!==t&&void 0!==t&&t,statusText:["WARM","COLD"]})),l.a.createElement(O,{disabled:b,title:"Save Changes",onClick:async function(){await u(`/${e}`,o),g.ok&&a()},loading:d})),l.a.createElement("hr",{color:"#e2e8f0"}),l.a.createElement(G,{registry:o.registry,dispatch:s}),l.a.createElement(U,{index:o.index,dispatch:s}))}function le(){var e=Object(r.b)().user,t=l.a.useContext(p),a=Object(s.a)(t,1)[0].manage,i=Object(n.e)(L("/functions/".concat(a)),{headers:{"x-denofn-user":null===e||void 0===e?void 0:e.sub}}),c=i.get,o=i.loading,m=i.error,u=i.data,d=i.response,g=l.a.useCallback(Object(ae.a)(te.a.mark((function e(){return te.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c();case 2:case"end":return e.stop()}}),e)}))),[c]);return l.a.useEffect((function(){g()}),[g]),l.a.createElement(E,null,o&&l.a.createElement(F,null),m&&l.a.createElement(N,{title:"Error!",message:m.message}),!o&&!m&&!!u&&d.ok&&l.a.createElement(ie,Object.assign({scriptName:"".concat(a)},u,{reload:g})))}var ce=function(){var e=l.a.useContext(p),t=function(e){switch(e){case"view-all":return function(){return l.a.createElement(z,null)};case"create":return function(){return l.a.createElement(Z,null)};case"manage":return function(){return l.a.createElement(le,null)};default:return function(){return l.a.createElement("div",null)}}}(Object(s.a)(e,1)[0].current);return l.a.createElement(l.a.Fragment,null,l.a.createElement(h,null),l.a.createElement(t,null))};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));o.a.render(l.a.createElement(l.a.StrictMode,null,l.a.createElement(r.a,{domain:"denofn.eu.auth0.com",clientId:"b43779wH6t2S4r7TXXWDWQzC56kg5voI",redirectUri:window.location.origin},l.a.createElement(f,null,l.a.createElement(n.c,{options:{cachePolicy:n.a.NO_CACHE}},l.a.createElement(ce,null))))),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()})).catch((function(e){console.error(e.message)}))}},[[38,1,2]]]); \ No newline at end of file +(this["webpackJsonpregistry-ui"]=this["webpackJsonpregistry-ui"]||[]).push([[0],{31:function(e,t,a){e.exports=a.p+"static/media/denofn_transparent.bc01bd66.png"},38:function(e,t,a){e.exports=a(66)},46:function(e,t,a){},66:function(e,t,a){"use strict";a.r(t);var r=a(3),n=a(4),i=a(0),l=a.n(i),c=a(7),o=a.n(c),s=(a(46),a(2)),m=a(1);function u(e){return l.a.createElement("svg",Object.assign({viewBox:"0 0 24 24",width:24,height:24},e),l.a.createElement("path",{className:"prefix__heroicon-ui",d:"M5.41 11H21a1 1 0 010 2H5.41l5.3 5.3a1 1 0 01-1.42 1.4l-7-7a1 1 0 010-1.4l7-7a1 1 0 011.42 1.4L5.4 11z"}))}var d=a(31),g=a.n(d);function b(e){var t=e.title,a=e.onClick;return l.a.createElement("button",{onClick:a,className:Object(m.a)({boxSizing:"border-box",backgroundColor:"transparent",color:"white",borderColor:"white",fontWeight:"bold",borderWidth:"1px",borderStyle:"solid",borderRadius:"0.25rem",padding:"7px 1rem",cursor:"pointer",lineHeight:"1rem",fontSize:"1rem",":hover":{color:"black",backgroundColor:"white",borderColor:"transparent"}})},t)}var p=l.a.createContext([{current:"view-all"},function(){}]);function f(e){var t=e.children,a=l.a.useState({current:"view-all"});return l.a.createElement(p.Provider,{value:a},t)}function h(e){var t=e.title,a=void 0===t?"denoFn":t,n=l.a.useContext(p),i=Object(s.a)(n,2),c=i[0],o=c.current,d=c.manage,f=i[1],h=Object(r.b)(),v=h.isAuthenticated,E=h.loginWithRedirect;return l.a.createElement("header",{className:Object(m.a)({display:"flex",backgroundColor:"rgb(0, 0, 0)",color:"white",borderColor:"rgb(237,242,247)",borderBottomStyle:"solid",borderBottomWidth:"1px",height:"4rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginLeft:"auto",marginRight:"auto",width:"100%",paddingLeft:"1.5rem",paddingRight:"1.5rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex"})},"manage"===o||"create"===o?l.a.createElement(u,{onClick:function(){return f({current:"view-all"})},className:Object(m.a)({display:"inline-block",lineHeight:"1.5rem",marginTop:"1.25rem",marginBottom:"1.25rem",marginRight:"0.5rem",cursor:"pointer",fill:"white"})}):l.a.createElement("img",{className:Object(m.a)({marginTop:".5rem",height:"3rem",width:"3rem",lineHeight:"3rem",marginRight:".5rem"}),src:g.a,alt:"denoFn logo"}),l.a.createElement("h4",{className:Object(m.a)({display:"inline-block",lineHeight:"1.5rem",marginTop:"1.25rem",marginBottom:"1.25rem",textTransform:"lowercase"})},"manage"===o?d:"create"===o?"create fn":a)),l.a.createElement("div",{className:Object(m.a)({marginTop:"1rem"})},!v&&l.a.createElement(b,{title:"Sign in",onClick:function(){return E()}}))))}var v=a(13);function E(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({padding:"1.5rem"})},t)}var w=Object(m.b)({from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}});function y(e){var t=e.dim,a=e.thickness;return l.a.createElement("div",{className:Object(m.a)({display:"inline-block",transitionTimingFunction:"linear",width:t||"1.5rem",height:t||"1.5rem",borderWidth:null!==a&&void 0!==a?a:".25rem",borderColor:"#edf2f7",borderStyle:"solid",borderTopWidth:null!==a&&void 0!==a?a:".25rem",borderTopColor:"rgb(26, 32, 44)",borderRadius:"9999px",animation:"".concat(w," 1.5s linear infinite")})})}var O=l.a.memo((function(e){var t=e.className,a=e.loading,r=e.disabled,n=e.title,i=e.onClick;return l.a.createElement("button",{className:"".concat(Object(m.a)({backgroundColor:"transparent",fontWeight:"bold",padding:".5rem 1rem",borderWidth:"1px",borderStyle:"solid",borderColor:"rgb(26, 32, 44)",borderRadius:".25rem",lineHeight:"1rem",fontSize:"1rem",cursor:"pointer",":hover":{backgroundColor:"rgb(26, 32, 44) !important",color:"white",borderColor:"transparent"},":disabled":{color:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)",borderColor:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)",cursor:"not-allowed"},selectors:{"&:disabled:hover":{backgroundColor:"transparent !important",borderColor:a?"rgb(26, 32, 44)":"rgba(26,32,44,.5)"}}})).concat(t?" ".concat(t):""),disabled:null!==r&&void 0!==r&&r,onClick:i},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center"})},a&&l.a.createElement("span",{className:Object(m.a)({marginRight:".33rem"})},l.a.createElement(y,{dim:".66rem",thickness:".125rem"})),n))})),x=l.a.memo((function(){var e=l.a.useContext(p),t=Object(s.a)(e,2)[1];return l.a.createElement(O,{title:"Create Fn",onClick:function(){return t({current:"create"})}})}));function j(e){var t=e.title,a=e.message;return l.a.createElement("div",{className:Object(m.a)({paddingLeft:"1rem",paddingRight:"1rem",color:"rgb(197,48,48)",borderStyle:"solid",borderColor:"rgb(252,129,129)",borderRadius:".25rem",borderWidth:"1px",paddingTop:".75rem",paddingBottom:".75rem",position:"relative",backgroundColor:"rgb(255,245,245)"}),role:"alert"},l.a.createElement("strong",{className:Object(m.a)({fontFamily:"'Rubik', sans-serif",fontWeight:"bold",display:"block",lineHeight:"1.5rem"})},t),l.a.createElement("span",null,a))}function C(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({width:"100%",marginLeft:"auto",marginRight:"auto",display:"flex",alignItems:"center",justifyContent:"center"})},t)}function N(e){return l.a.createElement(C,null,l.a.createElement(j,e))}const k={display:"flex",alignItems:"flex-start",flexDirection:"column",justifyContent:"space-between"},S={display:"block"},W=l.a.memo((function({className:e,children:t,onClick:a,padding:r,flex:n=!0}){const i=null!==a&&void 0!==a?a:function(){},c=a?{cursor:"pointer"}:{};return l.a.createElement("div",{onClick:i,className:`${Object(m.a)({...c,...n?k:S,backgroundColor:"white",boxSizing:"border-box",borderRadius:".25rem",minHeight:"6rem",padding:null!==r&&void 0!==r?r:"1rem",boxShadow:"0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05)"})}${e?` ${e}`:""}`},t)}));var H=l.a.memo((function(e){var t=e.className,a=e.status,r=e.statusText,n=Object(s.a)(r,2),i=n[0],c=n[1];return l.a.createElement("div",{className:"".concat(t?"".concat(t," "):"").concat(Object(m.a)({display:"inline-block",borderRadius:"9999px",fontWeight:"bold",fontSize:".75rem",padding:".25rem .5rem",lineHeight:"1rem",textTransform:"uppercase",backgroundColor:a?"rgb(56,178,172)":"rgb(245,101,101)",color:"white"}))},a?i:c)}));function R(e){var t=e.children;return l.a.createElement("span",{className:Object(m.a)({wordBreak:"break-all"})},t)}var T=l.a.memo((function(e){var t=e.f,a=e.status,r=l.a.useContext(p),n=Object(s.a)(r,2)[1];return l.a.createElement(W,{onClick:function(){return n({current:"manage",manage:t})},key:t},l.a.createElement(R,null,t),l.a.createElement(H,{className:Object(m.a)({marginTop:".75rem"}),status:a,statusText:["warm","cold"]}))}));function F(){return l.a.createElement(C,null,l.a.createElement(y,null),l.a.createElement("h3",{className:Object(m.a)({display:"inline-block",lineHeight:"2rem",margin:"0",marginLeft:".5rem",alignSelf:"top"})},"Loading..."))}function I(e){var t=e.children;return l.a.createElement("div",{className:Object(m.a)({width:"100%",display:"grid",gridGap:"1rem",gridTemplateColumns:"repeat(auto-fill, minmax(252px, 1fr))"})},t)}function B(){return window.location.origin}function L(e){return"".concat(B(),"/api/v1").concat(e)}function z(){var e=Object(r.b)(),t=e.isAuthenticated,a=e.user;return t?l.a.createElement(A,{isAuthenticated:!0,user:a}):l.a.createElement("div",null)}function A(e){var t=e.isAuthenticated,a=e.user,r=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===a||void 0===a?void 0:a.sub}}),i=r.get,c=r.loading,o=r.error,s=r.data;return l.a.useEffect((function(){t&&i()}),[t,i]),l.a.createElement(E,null,c&&l.a.createElement(F,null),o&&l.a.createElement(N,{title:"Error!",message:o.message}),!c&&!o&&!!s&&l.a.createElement(l.a.Fragment,null,l.a.createElement(I,null,[].concat(Object(v.a)(Object.keys(s).map((function(e){return l.a.createElement(T,{status:s[e],f:e,key:e})}))),[l.a.createElement(W,{key:"denofn-createNewFunctionAction-viewallfunctions"},l.a.createElement("div",{className:Object(m.a)({width:"100%",display:"flex",alignItems:"center",justifyContent:"center",height:"4rem"})},l.a.createElement(x,null)))]))))}var $=a(32),_=a.n($),D=a(33),M=a.n(D),J=a(16),V=a(34),P=a.n(V),U=(a(61),a(62),l.a.memo((function(e){var t=e.index,a=e.dispatch;return l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0"})},l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0 0.75rem",fontWeight:"bold"})},"index.ts"),l.a.createElement(P.a,{value:"".concat(t),onValueChange:function(e){a({type:"index",value:e})},highlight:function(e){return Object(J.highlight)(e,J.languages.ts,"ts")},onBlur:function(){var e=_.a.format("".concat(t),{semi:!0,printWidth:100,parser:"typescript",plugins:[M.a]});a({type:"index",value:e})},padding:4,className:Object(m.a)({fontFamily:"'Fira Code', monospace"})}))}))),q=a(37);function K(e){return{label:e,value:e}}function X(e){return(null!==e&&void 0!==e?e:[]).map((function(e){return e.value}))}var G=l.a.memo((function(e){var t,a=e.dispatch,r=e.registry,n=l.a.useState(""),i=Object(s.a)(n,2),c=i[0],o=i[1],u=l.a.useState(null===r||void 0===r?void 0:r.whitelist.map(K)),d=Object(s.a)(u,2),g=d[0],b=d[1];function p(e){b(e),a({type:"whitelist",value:X(e)})}return l.a.createElement("div",{className:Object(m.a)({margin:"1.5rem 0"})},l.a.createElement("div",{className:Object(m.a)({fontWeight:"bold",marginBottom:"0.75rem"})},"URL Whitelist"),l.a.createElement(q.a,{components:{DropdownIndicator:null},inputValue:c,isClearable:!0,isMulti:!0,menuIsOpen:!1,placeholder:"Enter the domains you want to send requests to here...",value:g,onChange:p,onKeyDown:function(e){if(c)switch(e.key){case"Enter":case"Tab":p([].concat(Object(v.a)(null!==g&&void 0!==g?g:[]),[K(c)])),o(""),e.preventDefault()}},onInputChange:function(e){o(e)}}),l.a.createElement("div",{className:Object(m.a)({marginTop:"1.5rem",display:"flex",alignItems:"center"})},l.a.createElement("label",{htmlFor:"warmupOnStart",className:Object(m.a)({marginRight:".5rem",fontWeight:"bold"})},"Post-registration warmup"),l.a.createElement("input",{type:"checkbox",checked:null!==(t=null===r||void 0===r?void 0:r.warmupOnStart)&&void 0!==t&&t,id:"warmupOnStart",onChange:function(e){a({type:"warmupOnStart",value:!(null===r||void 0===r?void 0:r.warmupOnStart)})}})))}));function Q(e,t){switch(t.type){case"scriptName":return{...e,scriptName:t.value};case"index":return{...e,index:t.value};case"warmupOnStart":return{...e,registry:{...e.registry,warmupOnStart:t.value}};case"whitelist":return{...e,registry:{...e.registry,whitelist:t.value}};default:return e}}function Y({reload:e}){const{user:t}=Object(r.b)(),[a,i]=l.a.useReducer(Q,{scriptName:"",index:'import {\n createHandler,\n createResponse,\n} from "https://cdn.jsdelivr.net/gh/jeroenptrs/denofn@1.0.0/packages/micro/functions/mod.ts";\n\nexport default createHandler(async (req, res) => {\n return createResponse({\n body: "Hello, World",\n });\n});\n',registry:{whitelist:[],warmupOnStart:!1}}),{post:c,loading:o,response:s,error:u,data:d}=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===t||void 0===t?void 0:t.sub}});return l.a.createElement(l.a.Fragment,null,u&&l.a.createElement(C,null,l.a.createElement(N,{title:"Something went wrong while creating your new function",message:d})),l.a.createElement(W,{padding:"1.5rem",flex:!1,className:Object(m.a)({minHeight:"calc(75vh - 7.5rem)",marginTop:u?"1.5rem":"0"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center",justifyContent:"space-between",margin:"0",marginBottom:"1.5rem"})},l.a.createElement("input",{className:Object(m.a)({width:"100%",padding:".25rem .5rem",lineHeight:"1.5rem",borderStyle:"none",backgroundColor:"transparent",appearance:"none",fontSize:"1.5rem",fontFamily:"'Rubik', sans-serif",fontWeight:"bold","::placeholder":{fontFamily:"'Karla', sans-serif",fontWeight:"initial"}}),value:a.scriptName,onChange:function(e){i({value:e.target.value,type:"scriptName"})},placeholder:"Enter your scriptname here",autoFocus:!0}),l.a.createElement(O,{disabled:""===a.scriptName,title:"Create",onClick:async function(){await c(a),s.ok&&e()},loading:o,className:Object(m.a)({marginLeft:"1.5rem"})})),l.a.createElement("hr",{color:"#e2e8f0"}),l.a.createElement(G,{registry:a.registry,dispatch:i}),l.a.createElement(U,{index:a.index,dispatch:i})))}function Z(){var e=l.a.useContext(p),t=Object(s.a)(e,2)[1],a=l.a.useCallback((function(){t({current:"view-all"})}),[t]);return l.a.createElement(E,null,l.a.createElement(Y,{reload:a}))}var ee=a(17),te=a.n(ee),ae=a(36);function re(e){return i.createElement("svg",Object.assign({viewBox:"0 0 24 24",width:24,height:24},e),i.createElement("path",{className:"prefix__heroicon-ui",d:"M19 6.41L8.7 16.71a1 1 0 11-1.4-1.42L17.58 5H14a1 1 0 010-2h6a1 1 0 011 1v6a1 1 0 01-2 0V6.41zM17 14a1 1 0 012 0v5a2 2 0 01-2 2H5a2 2 0 01-2-2V7c0-1.1.9-2 2-2h5a1 1 0 010 2H5v12h12v-5z"}))}function ne(e,t){switch(t.type){case"index":return{...e,index:t.value};case"warmupOnStart":return{...e,registry:{...e.registry,warmupOnStart:t.value}};case"whitelist":return{...e,registry:{...e.registry,whitelist:t.value}};default:return e}}function ie({scriptName:e,isWarmedUp:t,reload:a,...i}){const{user:c}=Object(r.b)(),[o,s]=l.a.useReducer(ne,{index:i.index,registry:i.registry}),{post:u,loading:d,response:g}=Object(n.e)(L("/functions"),{headers:{"x-denofn-user":null===c||void 0===c?void 0:c.sub}}),b=(p={index:i.index,registry:i.registry},f=o,p.index===f.index&&p.registry.warmupOnStart===f.registry.warmupOnStart&&JSON.stringify(p.registry.whitelist)===JSON.stringify(f.registry.whitelist));var p,f;return l.a.createElement(W,{padding:"1.5rem",flex:!1,className:Object(m.a)({minHeight:"calc(75vh - 7.5rem)"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center",justifyContent:"space-between",margin:"0",marginBottom:"1.5rem"})},l.a.createElement("div",{className:Object(m.a)({display:"flex",alignItems:"center"})},l.a.createElement("h2",{className:Object(m.a)({margin:"0",lineHeight:"1.5rem",fontSize:"1.5rem"})},e),l.a.createElement("a",{href:`${B()}/${e}`,target:"_blank",rel:"noopener noreferrer",className:Object(m.a)({height:"1.5rem",width:"1.5rem"})},l.a.createElement(re,{className:Object(m.a)({marginLeft:".25rem",fill:"rgba(26, 32, 44, 0.5)",alignSelf:"flex-start"})})),l.a.createElement(H,{className:Object(m.a)({marginLeft:".75rem"}),status:null!==t&&void 0!==t&&t,statusText:["WARM","COLD"]})),l.a.createElement(O,{disabled:b,title:"Save Changes",onClick:async function(){await u(`/${e}`,o),g.ok&&a()},loading:d})),l.a.createElement("hr",{color:"#e2e8f0"}),l.a.createElement(G,{registry:o.registry,dispatch:s}),l.a.createElement(U,{index:o.index,dispatch:s}))}function le(){var e=Object(r.b)().user,t=l.a.useContext(p),a=Object(s.a)(t,1)[0].manage,i=Object(n.e)(L("/functions/".concat(a)),{headers:{"x-denofn-user":null===e||void 0===e?void 0:e.sub}}),c=i.get,o=i.loading,m=i.error,u=i.data,d=i.response,g=l.a.useCallback(Object(ae.a)(te.a.mark((function e(){return te.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c();case 2:case"end":return e.stop()}}),e)}))),[c]);return l.a.useEffect((function(){g()}),[g]),l.a.createElement(E,null,o&&l.a.createElement(F,null),m&&l.a.createElement(N,{title:"Error!",message:m.message}),!o&&!m&&!!u&&d.ok&&l.a.createElement(ie,Object.assign({scriptName:"".concat(a)},u,{reload:g})))}var ce=function(){var e=l.a.useContext(p),t=function(e){switch(e){case"view-all":return function(){return l.a.createElement(z,null)};case"create":return function(){return l.a.createElement(Z,null)};case"manage":return function(){return l.a.createElement(le,null)};default:return function(){return l.a.createElement("div",null)}}}(Object(s.a)(e,1)[0].current);return l.a.createElement(l.a.Fragment,null,l.a.createElement(h,null),l.a.createElement(t,null))};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));o.a.render(l.a.createElement(l.a.StrictMode,null,l.a.createElement(r.a,{domain:"denofn.eu.auth0.com",clientId:"b43779wH6t2S4r7TXXWDWQzC56kg5voI",redirectUri:window.location.origin},l.a.createElement(f,null,l.a.createElement(n.c,{options:{cachePolicy:n.a.NO_CACHE}},l.a.createElement(ce,null))))),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()})).catch((function(e){console.error(e.message)}))}},[[38,1,2]]]); \ No newline at end of file diff --git a/static/precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js b/static/precache-manifest.f669b744feb131854f1fc6a7c50f468f.js similarity index 79% rename from static/precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js rename to static/precache-manifest.f669b744feb131854f1fc6a7c50f468f.js index 55ca967..6ef8f3a 100644 --- a/static/precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js +++ b/static/precache-manifest.f669b744feb131854f1fc6a7c50f468f.js @@ -1,6 +1,6 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([ { - "revision": "dec364348ee7b22e2045d26999d60cac", + "revision": "3cda9a5b82ad0071ef1ed070a4ff6646", "url": "/index.html" }, { @@ -8,7 +8,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([ "url": "/static/css/2.42d961f9.chunk.css" }, { - "revision": "5be24a995f6241472aa2", + "revision": "01d68011149bad07b946", "url": "/static/css/main.52631082.chunk.css" }, { @@ -20,8 +20,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([ "url": "/static/js/2.c6381a6d.chunk.js.LICENSE.txt" }, { - "revision": "5be24a995f6241472aa2", - "url": "/static/js/main.68dfd46b.chunk.js" + "revision": "01d68011149bad07b946", + "url": "/static/js/main.57770d27.chunk.js" }, { "revision": "d0883a43ad76ebaecb55", diff --git a/static/service-worker.js b/static/service-worker.js index 48e7548..6aa69af 100644 --- a/static/service-worker.js +++ b/static/service-worker.js @@ -14,7 +14,7 @@ importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); importScripts( - "/precache-manifest.0e16f0574a28ce2cb77cacc7ad9f4aea.js" + "/precache-manifest.f669b744feb131854f1fc6a7c50f468f.js" ); self.addEventListener('message', (event) => {