eser 3.0.0 → 3.0.2

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.
@@ -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,20 +1,25 @@
1
1
  {
2
2
  "name": "eser",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "main.js",
7
- "module": "mod.js",
8
- "scripts": {
9
- "start": "node main.js"
10
- },
11
6
  "author": "Eser Ozvataf",
12
7
  "license": "Apache-2.0",
13
8
  "exports": {
14
- ".": "./mod.js",
15
- "./hizli-api": "./hizli-api.js"
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
+ }
16
18
  },
17
19
  "dependencies": {
18
- "hono": "3.10.1"
20
+ "hono": "^3.10.1"
21
+ },
22
+ "devDependencies": {
23
+ "@deno/shim-deno": "^0.17.0"
19
24
  }
20
25
  }
@@ -1,8 +1,32 @@
1
1
  import { Hono } from "hono";
2
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
+ // @ts-ignore Deno namespace
3
26
  const kv = await Deno.openKv();
4
27
 
5
- export function routeHome(config, ctx) {
28
+ // deno-lint-ignore no-explicit-any
29
+ export function routeHome(config: Config, ctx: any) {
6
30
  return ctx.json({
7
31
  system: config.options.name,
8
32
  motd: config.options.messages.welcome,
@@ -14,7 +38,8 @@ export function routeHome(config, ctx) {
14
38
  });
15
39
  }
16
40
 
17
- export async function routeItem(item, config, ctx) {
41
+ // deno-lint-ignore no-explicit-any
42
+ export async function routeItem(item: any, ctx: any) {
18
43
  const itemKey = ["items", item];
19
44
 
20
45
  const getResult = await kv.get(itemKey);
@@ -23,11 +48,13 @@ export async function routeItem(item, config, ctx) {
23
48
  return ctx.json(records);
24
49
  }
25
50
 
26
- export async function routeItemsAdd(item, config, ctx) {
51
+ // deno-lint-ignore no-explicit-any
52
+ export async function routeItemsAdd(item: any, ctx: any) {
27
53
  const itemKey = ["items", item];
28
54
 
29
55
  const getResult = await kv.get(itemKey);
30
- const records = getResult?.value ?? [];
56
+ // deno-lint-ignore no-explicit-any
57
+ const records: any = getResult?.value ?? [];
31
58
 
32
59
  const value = ctx.req.param("value");
33
60
  records.push(value);
@@ -37,7 +64,8 @@ export async function routeItemsAdd(item, config, ctx) {
37
64
  return ctx.redirect(`/${item}`);
38
65
  }
39
66
 
40
- export async function routeItemsClear(item, config, ctx) {
67
+ // deno-lint-ignore no-explicit-any
68
+ export async function routeItemsClear(item: any, ctx: any) {
41
69
  const itemKey = ["items", item];
42
70
 
43
71
  await kv.set(itemKey, []);
@@ -45,7 +73,7 @@ export async function routeItemsClear(item, config, ctx) {
45
73
  return ctx.redirect(`/${item}`);
46
74
  }
47
75
 
48
- export function validateConfig(options) {
76
+ export function validateConfig(options: Options) {
49
77
  return {
50
78
  options: {
51
79
  name: options?.isim ?? "hizli-api",
@@ -60,18 +88,19 @@ export function validateConfig(options) {
60
88
  };
61
89
  }
62
90
 
63
- export function hizliApi(options) {
91
+ export function hizliApi(options: Options) {
64
92
  const config = validateConfig(options);
65
93
 
66
94
  const app = new Hono();
67
95
 
68
96
  app.get("/", (ctx) => routeHome(config, ctx));
69
97
  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));
98
+ app.get(`/${item}`, (ctx) => routeItem(item, ctx));
99
+ app.get(`/${item}/add/:value`, (ctx) => routeItemsAdd(item, ctx));
100
+ app.get(`/${item}/clear`, (ctx) => routeItemsClear(item, ctx));
73
101
  }
74
102
 
103
+ // @ts-ignore Deno namespace
75
104
  Deno.serve(app.fetch);
76
105
  }
77
106
 
package/src/mod.js ADDED
File without changes
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.js DELETED
@@ -1,13 +0,0 @@
1
- import hizliApi from "./hizli-api.js";
2
-
3
- hizliApi({
4
- isim: "defterdar",
5
-
6
- mesajlar: {
7
- hosgeldin: "Selam!",
8
- basarili: "Oldu",
9
- basarisiz: "Olmadı",
10
- },
11
-
12
- nesneler: ["dil", "runtime", "browser"],
13
- });
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.js DELETED
@@ -1,3 +0,0 @@
1
- export function add(a, b) {
2
- return a + b;
3
- }
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
- });