From 73ae0262b97742d619ee4cada3ad784dfaa60d65 Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Mon, 30 Dec 2024 00:42:41 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Kastro=20auto=20deploy=201/2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kastro/cloudflare/kvPageWorker.js | 22 ++++++++++----------- kastro/cloudflare/test/kvPageWorker.test.js | 5 +---- kastro/kastro.js | 7 +++++++ testing/runner.js | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/kastro/cloudflare/kvPageWorker.js b/kastro/cloudflare/kvPageWorker.js index 402dd32..8c2c07a 100644 --- a/kastro/cloudflare/kvPageWorker.js +++ b/kastro/cloudflare/kvPageWorker.js @@ -3,6 +3,9 @@ import { KvPageWorkerEnv } from "./kvPageWorker.d"; import { ModuleWorker } from "./moduleWorker.d"; import { CfRequest } from "./types.d"; +/** @define {string} */ +const HOST_URL = "https://kimlikdao.org/"; + /** @const {string} */ const PAGE_CACHE_CONTROL = "max-age=90,public"; /** @@ -16,17 +19,14 @@ const STATIC_CACHE_CONTROL = "max-age=29030400,public,immutable"; */ const err = () => Response.redirect("/"); -/** - * @param {string} hostUrl - * @return {ModuleWorker} - */ -const create = (hostUrl) => /** @type {ModuleWorker} */({ +/** @const {ModuleWorker} */ +const KvPageWorker = { /** * @override * * @param {!CfRequest} req - * @param {KvPageWorkerEnv} env - * @param {!Context} ctx + * @param {!KvPageWorkerEnv=} env + * @param {!Context=} ctx * @return {!Promise|!Response} */ fetch(req, env, ctx) { @@ -35,7 +35,7 @@ const create = (hostUrl) => /** @type {ModuleWorker} */({ /** @const {string} */ const enc = req.cf.clientAcceptEncoding || ""; /** @type {?string} */ - let kvKey = url.slice(hostUrl.length); + let kvKey = url.slice(HOST_URL.length); /** @type {number} */ let qmk = kvKey.indexOf("?") if (qmk != -1) kvKey = kvKey.slice(0, qmk); @@ -62,7 +62,7 @@ const create = (hostUrl) => /** @type {ModuleWorker} */({ } kvKey += ext.slice(0, 3); /** @const {string} */ - const cacheKey = hostUrl + kvKey; + const cacheKey = HOST_URL + kvKey; /** @type {boolean} */ let inCache = false; /** @@ -140,6 +140,6 @@ const create = (hostUrl) => /** @type {ModuleWorker} */({ return Promise.any([fromCache, fromKV]).catch(err); } -}); +} -export { create, err }; +export default KvPageWorker; diff --git a/kastro/cloudflare/test/kvPageWorker.test.js b/kastro/cloudflare/test/kvPageWorker.test.js index 5c08a6c..b3deafc 100644 --- a/kastro/cloudflare/test/kvPageWorker.test.js +++ b/kastro/cloudflare/test/kvPageWorker.test.js @@ -1,5 +1,5 @@ import { expect, it } from "bun:test"; -import { create } from "../kvPageWorker"; +import KvPageWorker from "../kvPageWorker"; import { KvPageWorkerEnv } from "../kvPageWorker.d"; import { MockKeyValue } from "../mock/keyValue"; import { Context, ModuleWorker } from "../moduleWorker.d"; @@ -55,9 +55,6 @@ const createRequest = (url, encoding, cookie) => /** @type {!CfRequest} */({ } }); -/** @const {!ModuleWorker} */ -const KvPageWorker = create("https://kimlikdao.org/"); - const testKvName = (url, acceptEncoding, cookie, kvName) => it( `returns the correct result for ${acceptEncoding}, ${cookie}, ${kvName}`, () => /** @type {!Promise} */( diff --git a/kastro/kastro.js b/kastro/kastro.js index f8237db..75609f7 100644 --- a/kastro/kastro.js +++ b/kastro/kastro.js @@ -149,6 +149,11 @@ const buildCrate = (crateName, buildMode) => import(crateName) } }) +const deployCrate = (crateName) => import(crateName) + .then(async (crate) => { + // TODO(KimlikDAO-bot) + }) + setupKastro(); const args = parseArgs(process.argv.slice(2), "command"); @@ -159,3 +164,5 @@ if (args.command == "serve") serveCrate(crateName, args["compiled"] ? compiler.BuildMode.Compiled : compiler.BuildMode.Dev); else if (args.command == "build") buildCrate(crateName, compiler.BuildMode.Compiled); +else if (args.command == "deploy") + deployCrate(crateName); diff --git a/testing/runner.js b/testing/runner.js index 0bfb319..eaddf8b 100644 --- a/testing/runner.js +++ b/testing/runner.js @@ -67,7 +67,7 @@ const targetPattern = target == "bench" : "**/*.test.js"; /** @const {!Array} */ -const filter = createMatcher(["build/", "kastro/", "node_modules/"] +const filter = createMatcher(["build/", "node_modules/"] .concat(args["filter"] || [])); const command = targetPattern.includes("bench")