Skip to content

Commit

Permalink
🤖 Kastro auto deploy 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Dec 30, 2024
1 parent 4c9dbba commit 73ae026
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
22 changes: 11 additions & 11 deletions kastro/cloudflare/kvPageWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/**
Expand All @@ -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>|!Response}
*/
fetch(req, env, ctx) {
Expand All @@ -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);
Expand All @@ -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;
/**
Expand Down Expand Up @@ -140,6 +140,6 @@ const create = (hostUrl) => /** @type {ModuleWorker} */({

return Promise.any([fromCache, fromKV]).catch(err);
}
});
}

export { create, err };
export default KvPageWorker;
5 changes: 1 addition & 4 deletions kastro/cloudflare/test/kvPageWorker.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<Response>} */(
Expand Down
7 changes: 7 additions & 0 deletions kastro/kastro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
2 changes: 1 addition & 1 deletion testing/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const targetPattern = target == "bench"
: "**/*.test.js";

/** @const {!Array<string>} */
const filter = createMatcher(["build/", "kastro/", "node_modules/"]
const filter = createMatcher(["build/", "node_modules/"]
.concat(args["filter"] || []));

const command = targetPattern.includes("bench")
Expand Down

0 comments on commit 73ae026

Please sign in to comment.