eser 3.0.0-rc.4 → 3.0.1

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.
@@ -1,4 +1,4 @@
1
- import hizliApi from "./hizli-api.js";
1
+ import hizliApi from "./hizli-api.ts";
2
2
 
3
3
  hizliApi({
4
4
  isim: "defterdar",
package/hizli-api.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { Hono } from "hono";
2
+
3
+ export interface Options {
4
+ isim?: string;
5
+ mesajlar?: {
6
+ hosgeldin?: string;
7
+ basarili?: string;
8
+ basarisiz?: string;
9
+ };
10
+ nesneler?: string[];
11
+ }
12
+
13
+ export interface Config {
14
+ options: {
15
+ name: string;
16
+ messages: {
17
+ welcome: string;
18
+ success: string;
19
+ fail: string;
20
+ };
21
+ items: string[];
22
+ };
23
+ }
24
+
25
+ const kv = await Deno.openKv();
26
+
27
+ // deno-lint-ignore no-explicit-any
28
+ export function routeHome(config: Config, ctx: any) {
29
+ return ctx.json({
30
+ system: config.options.name,
31
+ motd: config.options.messages.welcome,
32
+ items: config.options.items,
33
+ commands: [
34
+ "add",
35
+ "clear",
36
+ ],
37
+ });
38
+ }
39
+
40
+ // deno-lint-ignore no-explicit-any
41
+ export async function routeItem(item: any, ctx: any) {
42
+ const itemKey = ["items", item];
43
+
44
+ const getResult = await kv.get(itemKey);
45
+ const records = getResult?.value ?? [];
46
+
47
+ return ctx.json(records);
48
+ }
49
+
50
+ // deno-lint-ignore no-explicit-any
51
+ export async function routeItemsAdd(item: any, ctx: any) {
52
+ const itemKey = ["items", item];
53
+
54
+ const getResult = await kv.get(itemKey);
55
+ // deno-lint-ignore no-explicit-any
56
+ const records: any = getResult?.value ?? [];
57
+
58
+ const value = ctx.req.param("value");
59
+ records.push(value);
60
+
61
+ await kv.set(itemKey, records);
62
+
63
+ return ctx.redirect(`/${item}`);
64
+ }
65
+
66
+ // deno-lint-ignore no-explicit-any
67
+ export async function routeItemsClear(item: any, ctx: any) {
68
+ const itemKey = ["items", item];
69
+
70
+ await kv.set(itemKey, []);
71
+
72
+ return ctx.redirect(`/${item}`);
73
+ }
74
+
75
+ export function validateConfig(options: Options) {
76
+ return {
77
+ options: {
78
+ name: options?.isim ?? "hizli-api",
79
+ messages: {
80
+ welcome: options?.mesajlar?.hosgeldin ?? "Hoş geldin!",
81
+ success: options?.mesajlar?.basarili ?? "Başarılı",
82
+ fail: options?.mesajlar?.basarisiz ?? "Başarısız",
83
+ },
84
+
85
+ items: options?.nesneler ?? [],
86
+ },
87
+ };
88
+ }
89
+
90
+ export function hizliApi(options: Options) {
91
+ const config = validateConfig(options);
92
+
93
+ const app = new Hono();
94
+
95
+ app.get("/", (ctx) => routeHome(config, ctx));
96
+ for (const item of config.options.items) {
97
+ app.get(`/${item}`, (ctx) => routeItem(item, ctx));
98
+ app.get(`/${item}/add/:value`, (ctx) => routeItemsAdd(item, ctx));
99
+ app.get(`/${item}/clear`, (ctx) => routeItemsClear(item, ctx));
100
+ }
101
+
102
+ Deno.serve(app.fetch);
103
+ }
104
+
105
+ export { hizliApi as default };
package/mod.js CHANGED
@@ -1,3 +0,0 @@
1
- export function add(a, b) {
2
- return a + b;
3
- }
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "eser",
3
- "version": "3.0.0-rc.4",
3
+ "version": "3.0.1",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "main.js",
7
- "module": "mod.js",
8
6
  "scripts": {
9
7
  "start": "node main.js"
10
8
  },
@@ -12,7 +10,7 @@
12
10
  "license": "Apache-2.0",
13
11
  "exports": {
14
12
  ".": "./mod.js",
15
- "./hizli-api": "./hizli-api.js"
13
+ "./hizli-api": "./hizli-api.ts"
16
14
  },
17
15
  "dependencies": {
18
16
  "hono": "3.10.1"
package/hizli-api.js DELETED
@@ -1,78 +0,0 @@
1
- import { Hono } from "hono";
2
-
3
- const kv = await Deno.openKv();
4
-
5
- export function routeHome(config, ctx) {
6
- return ctx.json({
7
- system: config.options.name,
8
- motd: config.options.messages.welcome,
9
- items: config.options.items,
10
- commands: [
11
- "add",
12
- "clear",
13
- ],
14
- });
15
- }
16
-
17
- export async function routeItem(item, config, ctx) {
18
- const itemKey = ["items", item];
19
-
20
- const getResult = await kv.get(itemKey);
21
- const records = getResult?.value ?? [];
22
-
23
- return ctx.json(records);
24
- }
25
-
26
- export async function routeItemsAdd(item, config, ctx) {
27
- const itemKey = ["items", item];
28
-
29
- const getResult = await kv.get(itemKey);
30
- const records = getResult?.value ?? [];
31
-
32
- const value = ctx.req.param("value");
33
- records.push(value);
34
-
35
- await kv.set(itemKey, records);
36
-
37
- return ctx.redirect(`/${item}`);
38
- }
39
-
40
- export async function routeItemsClear(item, config, ctx) {
41
- const itemKey = ["items", item];
42
-
43
- await kv.set(itemKey, []);
44
-
45
- return ctx.redirect(`/${item}`);
46
- }
47
-
48
- export function validateConfig(options) {
49
- return {
50
- options: {
51
- name: options.isim ?? "hizli-api",
52
- messages: {
53
- welcome: options.mesajlar.hosgeldin ?? "Hoş geldin!",
54
- success: options.mesajlar.basarili ?? "Başarılı",
55
- fail: options.mesajlar.basarisiz ?? "Başarısız",
56
- },
57
-
58
- items: options.nesneler ?? [],
59
- },
60
- };
61
- }
62
-
63
- export function hizliApi(options) {
64
- const config = validateConfig(options);
65
-
66
- const app = new Hono();
67
-
68
- app.get("/", (ctx) => routeHome(config, ctx));
69
- for (const item of config.options.items) {
70
- app.get(`/${item}`, (ctx) => routeItem(item, config, ctx));
71
- app.get(`/${item}/add/:value`, (ctx) => routeItemsAdd(item, config, ctx));
72
- app.get(`/${item}/clear`, (ctx) => routeItemsClear(item, config, ctx));
73
- }
74
-
75
- Deno.serve(app.fetch);
76
- }
77
-
78
- export { hizliApi as default };
package/main.js DELETED
@@ -1,5 +0,0 @@
1
- import { add } from "./mod.js";
2
-
3
- if (import.meta.main === undefined || import.meta.main) {
4
- console.log("Add 2 + 3 =", add(2, 3));
5
- }
package/mod_test.js DELETED
@@ -1,5 +0,0 @@
1
- import { add } from "./mod.js";
2
-
3
- Deno.test(function addTest() {
4
- assertEquals(add(2, 3), 5);
5
- });