eser 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hizli-api.d.ts +37 -0
- package/dist/hizli-api.js +61 -0
- package/package.json +14 -7
- package/{hizli-api.ts → src/hizli-api.ts} +4 -0
- package/tsconfig.json +13 -0
- package/defterdar.ts +0 -13
- /package/{mod.js → src/mod.js} +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
isim?: string;
|
|
3
|
+
mesajlar?: {
|
|
4
|
+
hosgeldin?: string;
|
|
5
|
+
basarili?: string;
|
|
6
|
+
basarisiz?: string;
|
|
7
|
+
};
|
|
8
|
+
nesneler?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface Config {
|
|
11
|
+
options: {
|
|
12
|
+
name: string;
|
|
13
|
+
messages: {
|
|
14
|
+
welcome: string;
|
|
15
|
+
success: string;
|
|
16
|
+
fail: string;
|
|
17
|
+
};
|
|
18
|
+
items: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare function routeHome(config: Config, ctx: any): any;
|
|
22
|
+
export declare function routeItem(item: any, ctx: any): Promise<any>;
|
|
23
|
+
export declare function routeItemsAdd(item: any, ctx: any): Promise<any>;
|
|
24
|
+
export declare function routeItemsClear(item: any, ctx: any): Promise<any>;
|
|
25
|
+
export declare function validateConfig(options: Options): {
|
|
26
|
+
options: {
|
|
27
|
+
name: string;
|
|
28
|
+
messages: {
|
|
29
|
+
welcome: string;
|
|
30
|
+
success: string;
|
|
31
|
+
fail: string;
|
|
32
|
+
};
|
|
33
|
+
items: string[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function hizliApi(options: Options): void;
|
|
37
|
+
export { hizliApi as default };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
const kv = await Deno.openKv();
|
|
3
|
+
export function routeHome(config, ctx) {
|
|
4
|
+
return ctx.json({
|
|
5
|
+
system: config.options.name,
|
|
6
|
+
motd: config.options.messages.welcome,
|
|
7
|
+
items: config.options.items,
|
|
8
|
+
commands: [
|
|
9
|
+
"add",
|
|
10
|
+
"clear",
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function routeItem(item, ctx) {
|
|
15
|
+
var _a;
|
|
16
|
+
const itemKey = ["items", item];
|
|
17
|
+
const getResult = await kv.get(itemKey);
|
|
18
|
+
const records = (_a = getResult === null || getResult === void 0 ? void 0 : getResult.value) !== null && _a !== void 0 ? _a : [];
|
|
19
|
+
return ctx.json(records);
|
|
20
|
+
}
|
|
21
|
+
export async function routeItemsAdd(item, ctx) {
|
|
22
|
+
var _a;
|
|
23
|
+
const itemKey = ["items", item];
|
|
24
|
+
const getResult = await kv.get(itemKey);
|
|
25
|
+
const records = (_a = getResult === null || getResult === void 0 ? void 0 : getResult.value) !== null && _a !== void 0 ? _a : [];
|
|
26
|
+
const value = ctx.req.param("value");
|
|
27
|
+
records.push(value);
|
|
28
|
+
await kv.set(itemKey, records);
|
|
29
|
+
return ctx.redirect(`/${item}`);
|
|
30
|
+
}
|
|
31
|
+
export async function routeItemsClear(item, ctx) {
|
|
32
|
+
const itemKey = ["items", item];
|
|
33
|
+
await kv.set(itemKey, []);
|
|
34
|
+
return ctx.redirect(`/${item}`);
|
|
35
|
+
}
|
|
36
|
+
export function validateConfig(options) {
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
38
|
+
return {
|
|
39
|
+
options: {
|
|
40
|
+
name: (_a = options === null || options === void 0 ? void 0 : options.isim) !== null && _a !== void 0 ? _a : "hizli-api",
|
|
41
|
+
messages: {
|
|
42
|
+
welcome: (_c = (_b = options === null || options === void 0 ? void 0 : options.mesajlar) === null || _b === void 0 ? void 0 : _b.hosgeldin) !== null && _c !== void 0 ? _c : "Hoş geldin!",
|
|
43
|
+
success: (_e = (_d = options === null || options === void 0 ? void 0 : options.mesajlar) === null || _d === void 0 ? void 0 : _d.basarili) !== null && _e !== void 0 ? _e : "Başarılı",
|
|
44
|
+
fail: (_g = (_f = options === null || options === void 0 ? void 0 : options.mesajlar) === null || _f === void 0 ? void 0 : _f.basarisiz) !== null && _g !== void 0 ? _g : "Başarısız",
|
|
45
|
+
},
|
|
46
|
+
items: (_h = options === null || options === void 0 ? void 0 : options.nesneler) !== null && _h !== void 0 ? _h : [],
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function hizliApi(options) {
|
|
51
|
+
const config = validateConfig(options);
|
|
52
|
+
const app = new Hono();
|
|
53
|
+
app.get("/", (ctx) => routeHome(config, ctx));
|
|
54
|
+
for (const item of config.options.items) {
|
|
55
|
+
app.get(`/${item}`, (ctx) => routeItem(item, ctx));
|
|
56
|
+
app.get(`/${item}/add/:value`, (ctx) => routeItemsAdd(item, ctx));
|
|
57
|
+
app.get(`/${item}/clear`, (ctx) => routeItemsClear(item, ctx));
|
|
58
|
+
}
|
|
59
|
+
Deno.serve(app.fetch);
|
|
60
|
+
}
|
|
61
|
+
export { hizliApi as default };
|
package/package.json
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eser",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node main.js"
|
|
8
|
-
},
|
|
9
6
|
"author": "Eser Ozvataf",
|
|
10
7
|
"license": "Apache-2.0",
|
|
11
8
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/mod.js",
|
|
11
|
+
"require": "./dist/mod.js"
|
|
12
|
+
},
|
|
13
|
+
"./hizli-api": {
|
|
14
|
+
"import": "./dist/hizli-api.js",
|
|
15
|
+
"require": "./dist/hizli-api.js",
|
|
16
|
+
"types": "./dist/hizli-api.d.ts"
|
|
17
|
+
}
|
|
14
18
|
},
|
|
15
19
|
"dependencies": {
|
|
16
|
-
"hono": "3.10.1"
|
|
20
|
+
"hono": "^3.10.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@deno/shim-deno": "^0.17.0"
|
|
17
24
|
}
|
|
18
25
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
+
import { cors } from "hono/cors";
|
|
2
3
|
|
|
3
4
|
export interface Options {
|
|
4
5
|
isim?: string;
|
|
@@ -22,6 +23,7 @@ export interface Config {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
// @ts-ignore Deno namespace
|
|
25
27
|
const kv = await Deno.openKv();
|
|
26
28
|
|
|
27
29
|
// deno-lint-ignore no-explicit-any
|
|
@@ -91,6 +93,7 @@ export function hizliApi(options: Options) {
|
|
|
91
93
|
const config = validateConfig(options);
|
|
92
94
|
|
|
93
95
|
const app = new Hono();
|
|
96
|
+
app.use("/*", cors());
|
|
94
97
|
|
|
95
98
|
app.get("/", (ctx) => routeHome(config, ctx));
|
|
96
99
|
for (const item of config.options.items) {
|
|
@@ -99,6 +102,7 @@ export function hizliApi(options: Options) {
|
|
|
99
102
|
app.get(`/${item}/clear`, (ctx) => routeItemsClear(item, ctx));
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
// @ts-ignore Deno namespace
|
|
102
106
|
Deno.serve(app.fetch);
|
|
103
107
|
}
|
|
104
108
|
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./dist/",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"module": "ES2022",
|
|
7
|
+
"target": "ES2017",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"removeComments": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["./src/**/*"],
|
|
12
|
+
"exclude": ["./node_modules", "./**/*.test.ts"]
|
|
13
|
+
}
|
package/defterdar.ts
DELETED
/package/{mod.js → src/mod.js}
RENAMED
|
File without changes
|