Skip to content

Commit

Permalink
🧴 Move vm to ethereum/mock
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Aug 24, 2024
1 parent a948d16 commit beb2010
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 202 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions birimler/cloudflare/kvPageWorker.d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @author KimlikDAO
* @externs
*/

import { KeyValue } from "./types.d";

/**
* @typedef {{
* KV: KeyValue
* }}
*/
const Env = {};

export { Env };
15 changes: 8 additions & 7 deletions cloudflare/pageWorker.js → birimler/cloudflare/kvPageWorker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./moduleWorker.d";
import "./pageWorker.d";
import { Env } from "./kvPageWorker.d";
import { ModuleWorker } from "./moduleWorker.d";
import { CfRequest } from "./types.d";

/** @const {!Object<string, string>} */
const MIMES = {
Expand Down Expand Up @@ -37,15 +38,15 @@ const err = () => new Response("NAPİM?", {
/**
* @param {string} hostUrl
* @param {!Object<string, string>} pages
* @return {!cloudflare.ModuleWorker}
* @return {!ModuleWorker}
*/
const create = (hostUrl, pages) => /** @type {!cloudflare.ModuleWorker} */({
const create = (hostUrl, pages) => /** @type {!ModuleWorker} */({
/**
* @override
*
* @param {!cloudflare.Request} req
* @param {!cloudflare.PageWorkerEnv} env
* @param {!cloudflare.Context} ctx
* @param {!CfRequest} req
* @param {Env} env
* @param {!Context} ctx
* @return {!Promise<!Response>|!Response}
*/
fetch(req, env, ctx) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { KeyValue, KeyValueList } from "../types.d";

/**
* @constructor
* @implements {cloudflare.KeyValue}
* @implements {KeyValue}
*/
function MockKeyValue() { }

Expand Down Expand Up @@ -35,8 +37,12 @@ MockKeyValue.prototype.delete = (key) => Promise.resolve();
/**
* @override
*
* @return {!Promise<!cloudflare.KeyValueList>}
* @return {!Promise<KeyValueList>}
*/
MockKeyValue.prototype.list = () => Promise.resolve(new cloudflare.KeyValueList());
MockKeyValue.prototype.list = () => Promise.resolve({
cursor: "",
keys: [],
list_complete: true
});

export { MockKeyValue };
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
*/

import "./cache.d";
import cloudflare from "./cloudflare.d";
import { CfRequest } from "./types.d";

/**
* @interface
*/
cloudflare.Context = function () { }
function Context() { }

/**
* @param {!Promise<*>} promise
*/
cloudflare.Context.prototype.waitUntil = function (promise) { }
Context.prototype.waitUntil = function (promise) { }

/**
* @interface
*/
cloudflare.ModuleWorker = function () { }
function ModuleWorker() { }

/**
* @param {!cloudflare.Request} req
* @param {!cloudflare.Environment=} env
* @param {!cloudflare.Context=} ctx
* @param {!CfRequest} req
* @param {*} env
* @param {!Context=} ctx
* @return {!Promise<!Response>|!Response}
*/
cloudflare.ModuleWorker.prototype.fetch = function (req, env, ctx) { }
ModuleWorker.prototype.fetch = function (req, env, ctx) { }

/**
* @interface
*/
cloudflare.ModuleWorkerStub = function () { }
function ModuleWorkerStub() { }

/**
* A module worker stub has the same fetch interface as the web api fetch.
Expand All @@ -45,4 +45,10 @@ cloudflare.ModuleWorkerStub = function () { }
* @see https://fetch.spec.whatwg.org/#fetch-method
* @see https://developers.cloudflare.com/workers/runtime-apis/fetch/
*/
cloudflare.ModuleWorkerStub.prototype.fetch = function (input, init) { }
ModuleWorkerStub.prototype.fetch = function (input, init) { }

export {
Context,
ModuleWorker,
ModuleWorkerStub
};
File renamed without changes.
18 changes: 18 additions & 0 deletions birimler/cloudflare/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

/**
* @typedef {{
* accountId: string,
* authToken: string
* }}
*/
const Auth = {};

/**
* @param {Auth} auth
* @param {string} name
* @param {string} url
* @param {string} code
*/
const uploadWoker = (auth, name, url, code) => {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { expect, it } from "bun:test";
import { create } from "../kvPageWorker";
import { Env } from "../kvPageWorker.d";
import { MockKeyValue } from "../mock/keyValue";
import { create } from "../pageWorker";
import { Context, ModuleWorker } from "../moduleWorker.d";
import { CfRequest } from "../types.d";

globalThis["caches"] = {};
globalThis["caches"]["default"] = /** @type {!Cache} */({
Expand All @@ -20,13 +23,13 @@ globalThis["caches"]["default"] = /** @type {!Cache} */({
put(key, res) { return Promise.resolve(); },
});

/** @const {!cloudflare.PageWorkerEnv} */
const env = /** @type {!cloudflare.PageWorkerEnv} */({
/** @const {Env} */
const env = /** @type {Env} */({
KV: new MockKeyValue()
});

/** @const {!cloudflare.Context} */
const ctx = /** @type {!cloudflare.Context} */({
/** @const {!Context} */
const ctx = /** @type {!Context} */({
/**
* @param {!Promise<*>} promise
*/
Expand All @@ -37,9 +40,9 @@ const ctx = /** @type {!cloudflare.Context} */({
* @param {string} url
* @param {string} encoding
* @param {string} cookie
* @return {!cloudflare.Request}
* @return {!CfRequest}
*/
const createRequest = (url, encoding, cookie) => /** @type {!cloudflare.Request} */({
const createRequest = (url, encoding, cookie) => /** @type {!CfRequest} */({
url,
headers: {
/**
Expand All @@ -53,8 +56,8 @@ const createRequest = (url, encoding, cookie) => /** @type {!cloudflare.Request}
}
});

/** @const {!cloudflare.ModuleWorker} */
const PageWorker = create("https://kimlikdao.org/", {
/** @const {!ModuleWorker} */
const KvPageWorker = create("https://kimlikdao.org/", {
"?tr": "ana-tr.html",
"?en": "ana-en.html",
"al": "al-tr.html",
Expand All @@ -70,7 +73,7 @@ const PageWorker = create("https://kimlikdao.org/", {
const testKvName = (url, acceptEncoding, cookie, kvName) => it(
`returns the correct result for ${acceptEncoding}, ${cookie}, ${kvName}`,
() => /** @type {!Promise<Response>} */(
PageWorker.fetch(
KvPageWorker.fetch(
createRequest(url, acceptEncoding, cookie), env, ctx))
.then((res) => res.text())
.then((res) => expect(res).toBe(kvName))
Expand Down
35 changes: 10 additions & 25 deletions cloudflare/cloudflare.d.js → birimler/cloudflare/types.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@
* @externs
*/

/**
* @const
*/
const cloudflare = {};

/**
* @constructor
* @extends {Request}
*/
cloudflare.Request = function () { }
function CfRequest() { }

/**
* @const {{
* clientAcceptEncoding: ?string
* }}
*/
cloudflare.Request.prototype.cf;

/**
* @const {?BodyInit}
*/
cloudflare.Request.prototype.body;
CfRequest.prototype.cf;

/**
* The Cloudflare Response object contains this convenience method.
Expand All @@ -51,15 +41,15 @@ FormData.prototype.values = function () { }
/**
* @interface
*/
cloudflare.KeyValue = function () { }
function KeyValue() { }

/**
* @nosideeffects
* @param {string} key
* @param {string=} type
* @return {!Promise<ArrayBuffer>}
*/
cloudflare.KeyValue.prototype.get = function (key, type) { }
KeyValue.prototype.get = function (key, type) { }

/**
* @param {string} key
Expand All @@ -69,13 +59,13 @@ cloudflare.KeyValue.prototype.get = function (key, type) { }
* }=} options
* @return {!Promise<void>}
*/
cloudflare.KeyValue.prototype.put = function (key, value, options) { }
KeyValue.prototype.put = function (key, value, options) { }

/**
* @param {string} key
* @return {!Promise<void>}
*/
cloudflare.KeyValue.prototype.delete = function (key) { }
KeyValue.prototype.delete = function (key) { }

/**
* @typedef {{
Expand All @@ -87,17 +77,12 @@ cloudflare.KeyValue.prototype.delete = function (key) { }
* cursor: string,
* }}
*/
cloudflare.KeyValueList = {};
const KeyValueList = {};

/**
* @nosideeffects
* @return {!Promise<!cloudflare.KeyValueList>}
*/
cloudflare.KeyValue.prototype.list = function () { }

/**
* @interface
* @return {!Promise<KeyValueList>}
*/
cloudflare.Environment = function () { }
KeyValue.prototype.list = function () { }

export default cloudflare;
export { CfRequest, KeyValue, KeyValueList };
File renamed without changes.
4 changes: 4 additions & 0 deletions birimler/js/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

const sayfaJs = () => {

}
4 changes: 0 additions & 4 deletions birimler/js/sayfa.js

This file was deleted.

13 changes: 13 additions & 0 deletions birimler/js/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { compile } from "../../kdjs/compile";

/**
* @param {string} worker
* @return {!Promise<string>}
*/
const build = (worker) => compile({
"entry": worker,
"nologs": true,
"output": "build/" + worker
})

const deployToCloudflare = () => { }
9 changes: 7 additions & 2 deletions birimler/okuyucu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const keymapOku = (dosyaAdı, harita) => {
/**
* @param {string} birimAdı
* @param {!Seçimler} seçimler
* @param {!Object<string, string>} anaNitelikler
* @param {!Object<string, string>} anaNitelikler Kök birimin nitelikleri
* @return {{
* html: string,
* cssler: !Set<string>
Expand Down Expand Up @@ -74,7 +74,12 @@ const birimOku = (birimAdı, seçimler, anaNitelikler) => {

seçimler.kök ||= "";

/** @const {!Object<string, string>} */
/**
* Bütün `Seçimler`i değerlere de kopyalıyoruz, böylelikle html
* içerisinde de seçimlere ulaşabiliyoruz.
*
* @const {!Object<string, string>}
*/
const değerler = Object.assign({}, seçimler);
for (const nitelik in anaNitelikler)
if (nitelik.startsWith("data-")) {
Expand Down
8 changes: 8 additions & 0 deletions birimler/sunucu/kanarya.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { serve } from "bun";

serve({
port: 8787,
fetch(req) {
console.log(req);
}
});
15 changes: 0 additions & 15 deletions cloudflare/pageWorker.d.js

This file was deleted.

Loading

0 comments on commit beb2010

Please sign in to comment.