Skip to content

Commit

Permalink
🐴 Add more worker tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Aug 26, 2024
1 parent 3d30e60 commit a483136
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
10 changes: 6 additions & 4 deletions birimler/cloudflare/kvPageWorker.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import { KeyValue } from "./types.d";

/**
* @typedef {{
* KV: KeyValue
* }}
* @interface
* @struct
*/
const KvPageWorkerEnv = {};
const KvPageWorkerEnv = function () { };

/** @type {!KeyValue} */
KvPageWorkerEnv.prototype.KV;

export { KvPageWorkerEnv };
14 changes: 4 additions & 10 deletions birimler/cloudflare/moduleWorker.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ function Context() { }
Context.prototype.waitUntil = function (promise) { }

/**
* @interface
*/
function ModuleWorker() { }

/**
* @param {!CfRequest} req
* @param {*} env
* @param {!Context=} ctx
* @return {!Promise<!Response>|!Response}
* @typedef {{
* fetch: function(!CfRequest, ?=, !Context=):(!Promise<!Response>|!Response)
* }}
*/
ModuleWorker.prototype.fetch = function (req, env, ctx) { }
const ModuleWorker = {};

/**
* @interface
Expand Down
1 change: 1 addition & 0 deletions birimler/cloudflare/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Auth = {};
* name: string,
* namespace_id: string
* }>=} kvBindings
* @return {!Promise<*>}
*/
const uploadWorker = (auth, name, code, kvBindings) => {
/** @const {string} */
Expand Down
21 changes: 21 additions & 0 deletions birimler/email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @define {string} */
const RESEND_API_KEY = "RESEND_API_KEY";

/**
* @param {{
* from: string,
* to: (string|!Array<string>),
* subject: string,
* html: string
* }} params
*/
const sendEmail = (params) => fetch("https://api.resend.com/emails", {
method: "POST",
headers: {
"content-type": "application/json",
"authorization": `Bearer ${RESEND_API_KEY}`
},
body: JSON.stringify(params)
});

export { sendEmail };
13 changes: 11 additions & 2 deletions birimler/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import toml from "toml";
const readDefines = (definesFile, module) => readFile(definesFile)
.then(
(fileContent) => {
const moduleName = module.replace("/", "$");
const moduleName = module.replaceAll("/", "$");
return Object.entries(toml.parse(fileContent)).map(
([key, value]) => `${key}$$module$${moduleName}="${value}"`)
},
() => []
)

export { readDefines };
/**
* @param {string} module
* @param {string} name
* @param {string} value
* @return {string}
*/
const define = (module, name, value) =>
`${name}$$module$${module.replaceAll("/", "$")}=${value}`;

export { define, readDefines };

0 comments on commit a483136

Please sign in to comment.