@x-titan/fetcher 0.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.
Files changed (139) hide show
  1. package/.obsidian/app.json +7 -0
  2. package/.obsidian/appearance.json +5 -0
  3. package/.obsidian/community-plugins.json +7 -0
  4. package/.obsidian/core-plugins.json +33 -0
  5. package/.obsidian/hotkeys.json +19 -0
  6. package/.obsidian/icons/boxicons.zip +0 -0
  7. package/.obsidian/icons/font-awesome-brands.zip +0 -0
  8. package/.obsidian/icons/font-awesome-regular.zip +0 -0
  9. package/.obsidian/icons/font-awesome-solid.zip +0 -0
  10. package/.obsidian/icons/simple-icons.zip +0 -0
  11. package/.obsidian/plugins/advanced-canvas/main.js +7372 -0
  12. package/.obsidian/plugins/advanced-canvas/manifest.json +11 -0
  13. package/.obsidian/plugins/advanced-canvas/styles.css +508 -0
  14. package/.obsidian/plugins/canvas-mindmap/main.js +8 -0
  15. package/.obsidian/plugins/canvas-mindmap/manifest.json +15 -0
  16. package/.obsidian/plugins/canvas-mindmap/styles.css +29 -0
  17. package/.obsidian/plugins/custom-sidebar-icons/main.js +37831 -0
  18. package/.obsidian/plugins/custom-sidebar-icons/manifest.json +15 -0
  19. package/.obsidian/plugins/custom-sidebar-icons/styles.css +1 -0
  20. package/.obsidian/plugins/iconic/data.json +38 -0
  21. package/.obsidian/plugins/iconic/main.js +9 -0
  22. package/.obsidian/plugins/iconic/manifest.json +10 -0
  23. package/.obsidian/plugins/iconic/styles.css +609 -0
  24. package/.obsidian/plugins/obsidian-excalidraw-plugin/main.js +10 -0
  25. package/.obsidian/plugins/obsidian-excalidraw-plugin/manifest.json +12 -0
  26. package/.obsidian/plugins/obsidian-excalidraw-plugin/styles.css +1 -0
  27. package/.obsidian/plugins/obsidian-icon-folder/data.json +31 -0
  28. package/.obsidian/plugins/obsidian-icon-folder/main.js +7158 -0
  29. package/.obsidian/plugins/obsidian-icon-folder/manifest.json +10 -0
  30. package/.obsidian/plugins/obsidian-icon-folder/styles.css +120 -0
  31. package/.obsidian/plugins/obsidian-kanban/main.js +153 -0
  32. package/.obsidian/plugins/obsidian-kanban/manifest.json +11 -0
  33. package/.obsidian/plugins/obsidian-kanban/styles.css +1 -0
  34. package/.obsidian/plugins/table-editor-obsidian/data.json +6 -0
  35. package/.obsidian/plugins/table-editor-obsidian/main.js +236 -0
  36. package/.obsidian/plugins/table-editor-obsidian/manifest.json +17 -0
  37. package/.obsidian/plugins/table-editor-obsidian/styles.css +78 -0
  38. package/.obsidian/snippets/CustomIcon-AutoGen.css +17 -0
  39. package/.obsidian/templates.json +3 -0
  40. package/.obsidian/themes/ASET Simple/.editorconfig +10 -0
  41. package/.obsidian/themes/ASET Simple/.git1/HEAD +1 -0
  42. package/.obsidian/themes/ASET Simple/.git1/config +13 -0
  43. package/.obsidian/themes/ASET Simple/.git1/description +1 -0
  44. package/.obsidian/themes/ASET Simple/.git1/hooks/applypatch-msg.sample +15 -0
  45. package/.obsidian/themes/ASET Simple/.git1/hooks/commit-msg.sample +24 -0
  46. package/.obsidian/themes/ASET Simple/.git1/hooks/fsmonitor-watchman.sample +174 -0
  47. package/.obsidian/themes/ASET Simple/.git1/hooks/post-update.sample +8 -0
  48. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-applypatch.sample +14 -0
  49. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-commit.sample +49 -0
  50. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-merge-commit.sample +13 -0
  51. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-push.sample +53 -0
  52. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-rebase.sample +169 -0
  53. package/.obsidian/themes/ASET Simple/.git1/hooks/pre-receive.sample +24 -0
  54. package/.obsidian/themes/ASET Simple/.git1/hooks/prepare-commit-msg.sample +42 -0
  55. package/.obsidian/themes/ASET Simple/.git1/hooks/push-to-checkout.sample +78 -0
  56. package/.obsidian/themes/ASET Simple/.git1/hooks/sendemail-validate.sample +77 -0
  57. package/.obsidian/themes/ASET Simple/.git1/hooks/update.sample +128 -0
  58. package/.obsidian/themes/ASET Simple/.git1/index +0 -0
  59. package/.obsidian/themes/ASET Simple/.git1/info/exclude +6 -0
  60. package/.obsidian/themes/ASET Simple/.git1/objects/pack/pack-37b1d733e37d8c14f634edcfb396cffa341c1de9.idx +0 -0
  61. package/.obsidian/themes/ASET Simple/.git1/objects/pack/pack-37b1d733e37d8c14f634edcfb396cffa341c1de9.pack +0 -0
  62. package/.obsidian/themes/ASET Simple/.git1/objects/pack/pack-37b1d733e37d8c14f634edcfb396cffa341c1de9.rev +0 -0
  63. package/.obsidian/themes/ASET Simple/.git1/packed-refs +2 -0
  64. package/.obsidian/themes/ASET Simple/.git1/refs/heads/master +1 -0
  65. package/.obsidian/themes/ASET Simple/.git1/refs/remotes/origin/HEAD +1 -0
  66. package/.obsidian/themes/ASET Simple/.github/workflows/release-version.yml +50 -0
  67. package/.obsidian/themes/ASET Simple/README.md +95 -0
  68. package/.obsidian/themes/ASET Simple/manifest.json +7 -0
  69. package/.obsidian/themes/ASET Simple/package.json +7 -0
  70. package/.obsidian/themes/ASET Simple/theme.css +164 -0
  71. package/.obsidian/themes/ASET Simple/version-bump.mjs +26 -0
  72. package/.obsidian/themes/ASET Simple/versions.json +3 -0
  73. package/.obsidian/themes/Atom/manifest.json +6 -0
  74. package/.obsidian/themes/Atom/theme.css +339 -0
  75. package/.obsidian/themes/Borealis/manifest.json +7 -0
  76. package/.obsidian/themes/Borealis/theme.css +1164 -0
  77. package/.obsidian/themes/Cupertino/manifest.json +8 -0
  78. package/.obsidian/themes/Cupertino/theme.css +107 -0
  79. package/.obsidian/themes/Flexoki/manifest.json +7 -0
  80. package/.obsidian/themes/Flexoki/theme.css +82 -0
  81. package/.obsidian/themes/Focus/manifest.json +7 -0
  82. package/.obsidian/themes/Focus/theme.css +1047 -0
  83. package/.obsidian/themes/GitHub Theme/manifest.json +7 -0
  84. package/.obsidian/themes/GitHub Theme/theme.css +1245 -0
  85. package/.obsidian/themes/Minimal/manifest.json +8 -0
  86. package/.obsidian/themes/Minimal/theme.css +2223 -0
  87. package/.obsidian/themes/Notation/manifest.json +6 -0
  88. package/.obsidian/themes/Notation/theme.css +831 -0
  89. package/.obsidian/themes/Notation 2/manifest.json +7 -0
  90. package/.obsidian/themes/Notation 2/theme.css +1887 -0
  91. package/.obsidian/themes/Oreo/manifest.json +7 -0
  92. package/.obsidian/themes/Oreo/theme.css +2242 -0
  93. package/.obsidian/themes/Pure/manifest.json +6 -0
  94. package/.obsidian/themes/Pure/theme.css +288 -0
  95. package/.obsidian/themes/Simple/manifest.json +7 -0
  96. package/.obsidian/themes/Simple/theme.css +1005 -0
  97. package/.obsidian/themes/Sodalite/manifest.json +7 -0
  98. package/.obsidian/themes/Sodalite/theme.css +905 -0
  99. package/.obsidian/themes/Things/manifest.json +7 -0
  100. package/.obsidian/themes/Things/theme.css +1628 -0
  101. package/.obsidian/themes/Vanilla AMOLED/manifest.json +7 -0
  102. package/.obsidian/themes/Vanilla AMOLED/theme.css +25 -0
  103. package/.obsidian/themes/Vanilla AMOLED Color/manifest.json +7 -0
  104. package/.obsidian/themes/Vanilla AMOLED Color/theme.css +49 -0
  105. package/.obsidian/themes/Wikipedia/manifest.json +7 -0
  106. package/.obsidian/themes/Wikipedia/theme.css +1134 -0
  107. package/.obsidian/themes/mono black (monochrome, charcoal)/manifest.json +7 -0
  108. package/.obsidian/themes/mono black (monochrome, charcoal)/theme.css +17 -0
  109. package/.obsidian/workspace.json +218 -0
  110. package/LICENCE +21 -0
  111. package/dist/fetcher.d.ts +17 -0
  112. package/dist/fetcher.d.ts.map +1 -0
  113. package/dist/fetcher.js +54 -0
  114. package/dist/fetcher.js.map +1 -0
  115. package/dist/index.d.ts +6 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +25 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/responses.d.ts +6 -0
  120. package/dist/responses.d.ts.map +1 -0
  121. package/dist/responses.js +23 -0
  122. package/dist/responses.js.map +1 -0
  123. package/dist/types.d.ts +9 -0
  124. package/dist/types.d.ts.map +1 -0
  125. package/dist/types.js +3 -0
  126. package/dist/types.js.map +1 -0
  127. package/dist/utils.d.ts +3 -0
  128. package/dist/utils.d.ts.map +1 -0
  129. package/dist/utils.js +9 -0
  130. package/dist/utils.js.map +1 -0
  131. package/nodemon.json +6 -0
  132. package/package.json +38 -0
  133. package/src/fetcher.ts +68 -0
  134. package/src/index.ts +7 -0
  135. package/src/responses.ts +19 -0
  136. package/src/types.ts +15 -0
  137. package/src/utils.ts +9 -0
  138. package/tsconfig.json +49 -0
  139. package/tsup.config.ts +11 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "mono black (monochrome, charcoal)",
3
+ "version": "1.0.0",
4
+ "minAppVersion": "1.0.0",
5
+ "author": "zc",
6
+ "authorUrl": "https://github.com/ZeChArtiahSaher"
7
+ }
@@ -0,0 +1,17 @@
1
+ .theme-dark {
2
+ --color-base-00: #111111;
3
+ --color-base-05: #111111;
4
+ --color-base-10: #131313;
5
+ --color-base-20: #151515;
6
+ --color-base-25: #171717;
7
+ --color-base-30: #272727;
8
+ --color-base-35: #272727;
9
+ --color-base-40: #333333;
10
+ --color-base-50: #404040;
11
+ --color-base-60: #666666;
12
+ --color-base-70: #787878;
13
+ --color-base-100: #cbcbcb;
14
+
15
+ --background-secondary: #111111;
16
+ --background-secondary-alt: #151515;
17
+ }
@@ -0,0 +1,218 @@
1
+ {
2
+ "main": {
3
+ "id": "569acdfc22d70b3a",
4
+ "type": "split",
5
+ "children": [
6
+ {
7
+ "id": "57459cdf445f31d7",
8
+ "type": "tabs",
9
+ "children": [
10
+ {
11
+ "id": "1f5695ada88d361b",
12
+ "type": "leaf",
13
+ "state": {
14
+ "type": "canvas",
15
+ "state": {
16
+ "file": "docs/Untitled 1.canvas",
17
+ "viewState": {
18
+ "x": 176,
19
+ "y": 98,
20
+ "zoom": 0
21
+ }
22
+ },
23
+ "icon": "lucide-layout-dashboard",
24
+ "title": "Untitled 1"
25
+ }
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ "id": "a5812876f88e254f",
31
+ "type": "tabs",
32
+ "children": [
33
+ {
34
+ "id": "2cb57fa29fcf3af7",
35
+ "type": "leaf",
36
+ "state": {
37
+ "type": "markdown",
38
+ "state": {
39
+ "file": "docs/index.md",
40
+ "mode": "source",
41
+ "source": false
42
+ },
43
+ "icon": "lucide-file",
44
+ "title": "index"
45
+ }
46
+ }
47
+ ]
48
+ }
49
+ ],
50
+ "direction": "vertical"
51
+ },
52
+ "left": {
53
+ "id": "24cb1df9d608beba",
54
+ "type": "split",
55
+ "children": [
56
+ {
57
+ "id": "d51f43f06f8294a8",
58
+ "type": "tabs",
59
+ "children": [
60
+ {
61
+ "id": "e22d174ff178ab76",
62
+ "type": "leaf",
63
+ "state": {
64
+ "type": "file-explorer",
65
+ "state": {
66
+ "sortOrder": "alphabetical",
67
+ "autoReveal": false
68
+ },
69
+ "icon": "lucide-folder-closed",
70
+ "title": "Files"
71
+ }
72
+ },
73
+ {
74
+ "id": "0497651a512a7b14",
75
+ "type": "leaf",
76
+ "state": {
77
+ "type": "search",
78
+ "state": {
79
+ "query": "",
80
+ "matchingCase": false,
81
+ "explainSearch": false,
82
+ "collapseAll": false,
83
+ "extraContext": false,
84
+ "sortOrder": "alphabetical"
85
+ },
86
+ "icon": "lucide-search",
87
+ "title": "Search"
88
+ }
89
+ },
90
+ {
91
+ "id": "f755e7b0b0ac97c5",
92
+ "type": "leaf",
93
+ "state": {
94
+ "type": "bookmarks",
95
+ "state": {},
96
+ "icon": "lucide-bookmark",
97
+ "title": "Bookmarks"
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ ],
103
+ "direction": "horizontal",
104
+ "width": 300
105
+ },
106
+ "right": {
107
+ "id": "e850cf9e4db2b468",
108
+ "type": "split",
109
+ "children": [
110
+ {
111
+ "id": "03422f43317f336f",
112
+ "type": "tabs",
113
+ "children": [
114
+ {
115
+ "id": "5eec0704346aba99",
116
+ "type": "leaf",
117
+ "state": {
118
+ "type": "backlink",
119
+ "state": {
120
+ "collapseAll": false,
121
+ "extraContext": false,
122
+ "sortOrder": "alphabetical",
123
+ "showSearch": false,
124
+ "searchQuery": "",
125
+ "backlinkCollapsed": false,
126
+ "unlinkedCollapsed": true
127
+ },
128
+ "icon": "links-coming-in",
129
+ "title": "Backlinks"
130
+ }
131
+ },
132
+ {
133
+ "id": "e5a38cbe19b83b3a",
134
+ "type": "leaf",
135
+ "state": {
136
+ "type": "outgoing-link",
137
+ "state": {
138
+ "linksCollapsed": false,
139
+ "unlinkedCollapsed": true
140
+ },
141
+ "icon": "links-going-out",
142
+ "title": "Outgoing links"
143
+ }
144
+ },
145
+ {
146
+ "id": "6c8a6d29d687c140",
147
+ "type": "leaf",
148
+ "state": {
149
+ "type": "tag",
150
+ "state": {
151
+ "sortOrder": "frequency",
152
+ "useHierarchy": true,
153
+ "showSearch": false,
154
+ "searchQuery": ""
155
+ },
156
+ "icon": "lucide-tags",
157
+ "title": "Tags"
158
+ }
159
+ },
160
+ {
161
+ "id": "c78eeb819197afd7",
162
+ "type": "leaf",
163
+ "state": {
164
+ "type": "all-properties",
165
+ "state": {
166
+ "sortOrder": "frequency",
167
+ "showSearch": false,
168
+ "searchQuery": ""
169
+ },
170
+ "icon": "lucide-ghost",
171
+ "title": "all-properties"
172
+ }
173
+ },
174
+ {
175
+ "id": "07385f75a5c2c016",
176
+ "type": "leaf",
177
+ "state": {
178
+ "type": "outline",
179
+ "state": {
180
+ "followCursor": false,
181
+ "showSearch": false,
182
+ "searchQuery": ""
183
+ },
184
+ "icon": "lucide-list",
185
+ "title": "Outline"
186
+ }
187
+ }
188
+ ]
189
+ }
190
+ ],
191
+ "direction": "horizontal",
192
+ "width": 300,
193
+ "collapsed": true
194
+ },
195
+ "left-ribbon": {
196
+ "hiddenItems": {
197
+ "switcher:Open quick switcher": false,
198
+ "graph:Open graph view": false,
199
+ "canvas:Create new canvas": false,
200
+ "daily-notes:Open today's daily note": false,
201
+ "templates:Insert template": false,
202
+ "command-palette:Open command palette": false,
203
+ "bases:Create new base": false,
204
+ "table-editor-obsidian:Advanced Tables Toolbar": false,
205
+ "iconic:Open rulebook": false,
206
+ "obsidian-kanban:Create new board": false
207
+ }
208
+ },
209
+ "active": "e22d174ff178ab76",
210
+ "lastOpenFiles": [
211
+ "docs/Untitled.base",
212
+ "docs/Untitled 1.base",
213
+ "docs/Untitled 1.canvas",
214
+ "docs/Untitled.canvas",
215
+ "docs/Untitled Kanban.md",
216
+ "docs/index.md"
217
+ ]
218
+ }
package/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Aset Telmanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ import type { Fetch } from "./types";
2
+ export default class Fetcher {
3
+ private fetchHandler;
4
+ /**
5
+ * Constructor for FetchServer.
6
+ * @example const server = new FetchServer((request) => new Response("Hello world!", { status: 200 }))
7
+ */
8
+ constructor(handler: Fetch);
9
+ /**
10
+ * Handles an incoming request and emits events for request, response, error and end.
11
+ * @param {RequestInfo | URL} input - The request input.
12
+ * @param {RequestInit} [init] - The request initialization object.
13
+ * @return {Promise<Response>} - The response object.
14
+ */
15
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
16
+ }
17
+ //# sourceMappingURL=fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,KAAK,EAEN,MAAM,SAAS,CAAA;AAEhB,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,OAAO,CAAC,YAAY,CAAO;IAE3B;;;OAGG;gBACS,OAAO,EAAE,KAAK;IAQ1B;;;;;OAKG;IACG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CAiC7E"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const responses_1 = require("./responses");
4
+ const utils_1 = require("./utils");
5
+ class Fetcher {
6
+ fetchHandler;
7
+ /**
8
+ * Constructor for FetchServer.
9
+ * @example const server = new FetchServer((request) => new Response("Hello world!", { status: 200 }))
10
+ */
11
+ constructor(handler) {
12
+ if (typeof handler !== "function")
13
+ throw new TypeError("handler must be a function");
14
+ this.fetchHandler = handler;
15
+ this.fetch = this.fetch.bind(this);
16
+ }
17
+ /**
18
+ * Handles an incoming request and emits events for request, response, error and end.
19
+ * @param {RequestInfo | URL} input - The request input.
20
+ * @param {RequestInit} [init] - The request initialization object.
21
+ * @return {Promise<Response>} - The response object.
22
+ */
23
+ async fetch(input, init) {
24
+ let request;
25
+ let info;
26
+ let response;
27
+ if ((input instanceof Request) &&
28
+ (0, utils_1.isSocketInfo)(init)) {
29
+ request = input;
30
+ info = init;
31
+ }
32
+ else {
33
+ request = new Request(input, init);
34
+ info = {
35
+ remoteAddress: null,
36
+ localAddress: null,
37
+ alpn: null
38
+ };
39
+ }
40
+ try {
41
+ response = await this.fetchHandler.call(this, request, info);
42
+ if (response instanceof Error)
43
+ throw response;
44
+ }
45
+ catch (error) {
46
+ response = (0, responses_1.internalServerError)();
47
+ }
48
+ if (!(response instanceof Response))
49
+ response = (0, responses_1.noContent)();
50
+ return response;
51
+ }
52
+ }
53
+ exports.default = Fetcher;
54
+ //# sourceMappingURL=fetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":";;AAAA,2CAGoB;AACpB,mCAEgB;AAOhB,MAAqB,OAAO;IAClB,YAAY,CAAO;IAE3B;;;OAGG;IACH,YAAY,OAAc;QACxB,IAAI,OAAO,OAAO,KAAK,UAAU;YAC/B,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAA;QACnD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAA;QAE3B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,KAAwB,EAAE,IAAkB;QACtD,IAAI,OAAgB,CAAA;QACpB,IAAI,IAAgB,CAAA;QACpB,IAAI,QAAkB,CAAA;QAEtB,IACE,CAAC,KAAK,YAAY,OAAO,CAAC;YAC1B,IAAA,oBAAY,EAAC,IAAI,CAAC,EAClB,CAAC;YACD,OAAO,GAAG,KAAK,CAAA;YACf,IAAI,GAAG,IAAI,CAAA;QACb,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YAClC,IAAI,GAAG;gBACL,aAAa,EAAE,IAAI;gBACnB,YAAY,EAAE,IAAI;gBAClB,IAAI,EAAE,IAAI;aACX,CAAA;QACH,CAAC;QAED,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;YAC5D,IAAI,QAAQ,YAAY,KAAK;gBAC3B,MAAM,QAAQ,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,GAAG,IAAA,+BAAmB,GAAE,CAAA;QAClC,CAAC;QAED,IAAI,CAAC,CAAC,QAAQ,YAAY,QAAQ,CAAC;YACjC,QAAQ,GAAG,IAAA,qBAAS,GAAE,CAAA;QAExB,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAtDD,0BAsDC"}
@@ -0,0 +1,6 @@
1
+ import Fetcher from "./fetcher";
2
+ export * from "./responses";
3
+ export type * from "./types";
4
+ export default Fetcher;
5
+ export { Fetcher };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,mBAAmB,SAAS,CAAA;AAC5B,eAAe,OAAO,CAAA;AAGtB,OAAO,EAAE,OAAO,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Fetcher = void 0;
21
+ const fetcher_1 = __importDefault(require("./fetcher"));
22
+ exports.Fetcher = fetcher_1.default;
23
+ __exportStar(require("./responses"), exports);
24
+ exports.default = fetcher_1.default;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,wDAA+B;AAMtB,kBANF,iBAAO,CAME;AALhB,8CAA2B;AAE3B,kBAAe,iBAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare function noContent(): Response;
2
+ export declare function notFound(): Response;
3
+ export declare function badRequest(): Response;
4
+ export declare function internalServerError(): Response;
5
+ export declare function ok(): Response;
6
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,aAExB;AAED,wBAAgB,QAAQ,aAEvB;AAED,wBAAgB,UAAU,aAEzB;AAED,wBAAgB,mBAAmB,aAElC;AAED,wBAAgB,EAAE,aAEjB"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noContent = noContent;
4
+ exports.notFound = notFound;
5
+ exports.badRequest = badRequest;
6
+ exports.internalServerError = internalServerError;
7
+ exports.ok = ok;
8
+ function noContent() {
9
+ return new Response(null, { status: 204, statusText: "No Content" });
10
+ }
11
+ function notFound() {
12
+ return new Response(null, { status: 404, statusText: "Not Found" });
13
+ }
14
+ function badRequest() {
15
+ return new Response(null, { status: 400, statusText: "Bad Request" });
16
+ }
17
+ function internalServerError() {
18
+ return new Response(null, { status: 500, statusText: "Internal Server Error" });
19
+ }
20
+ function ok() {
21
+ return new Response(null, { status: 200, statusText: "OK" });
22
+ }
23
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":";;AAAA,8BAEC;AAED,4BAEC;AAED,gCAEC;AAED,kDAEC;AAED,gBAEC;AAlBD,SAAgB,SAAS;IACvB,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAA;AACtE,CAAC;AAED,SAAgB,QAAQ;IACtB,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAA;AACrE,CAAC;AAED,SAAgB,UAAU;IACxB,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAA;AACvE,CAAC;AAED,SAAgB,mBAAmB;IACjC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC,CAAA;AACjF,CAAC;AAED,SAAgB,EAAE;IAChB,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type Fetcher from "./fetcher";
2
+ export type MaybePromise<T> = Promise<T> | T;
3
+ export interface SocketInfo {
4
+ remoteAddress: string | null;
5
+ localAddress: string | null;
6
+ alpn: string | null;
7
+ }
8
+ export type Fetch = (this: Fetcher, request: Request, socketInfo: SocketInfo) => MaybePromise<Response>;
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA;AAEpC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE5C,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAED,MAAM,MAAM,KAAK,GAAG,CAClB,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,KACnB,YAAY,CAAC,QAAQ,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { SocketInfo } from "./types";
2
+ export declare function isSocketInfo(obj: any): obj is SocketInfo;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,UAAU,CAMxD"}
package/dist/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSocketInfo = isSocketInfo;
4
+ function isSocketInfo(obj) {
5
+ return (("localAddress" in obj) &&
6
+ ("remoteAddress" in obj) &&
7
+ ("alpn" in obj));
8
+ }
9
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAEA,oCAMC;AAND,SAAgB,YAAY,CAAC,GAAQ;IACnC,OAAO,CACL,CAAC,cAAc,IAAI,GAAG,CAAC;QACvB,CAAC,eAAe,IAAI,GAAG,CAAC;QACxB,CAAC,MAAM,IAAI,GAAG,CAAC,CAChB,CAAA;AACH,CAAC"}
package/nodemon.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src/"],
3
+ "ext": "ts,json,ejs",
4
+ "ignore": ["dist/"],
5
+ "exec":"ts-node src"
6
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@x-titan/fetcher",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "license": "MIT",
6
+ "author": "Aset Telmanov",
7
+ "type": "commonjs",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./adapters/*": "./dist/adapters/*"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "scripts": {
18
+ "dev": "nodemon",
19
+ "dev:bun": "bun --hot run ./test",
20
+ "start": "node dist",
21
+ "test": "ts-node test",
22
+ "test:node": "node test/index",
23
+ "test:bun": "bun run ./test/index.ts",
24
+ "build": "tsc",
25
+ "build:tsup": "tsup",
26
+ "build:tsc": "tsc"
27
+ },
28
+ "devDependencies": {
29
+ "@types/bun": "*",
30
+ "@types/deno": "*",
31
+ "@types/node": "^24",
32
+ "@x-titan/type-is": "^1.0.1",
33
+ "nodemon": "^3",
34
+ "ts-node": "^10",
35
+ "tsup": "^8",
36
+ "typescript": "^5"
37
+ }
38
+ }
package/src/fetcher.ts ADDED
@@ -0,0 +1,68 @@
1
+ import {
2
+ internalServerError,
3
+ noContent,
4
+ } from "./responses"
5
+ import {
6
+ isSocketInfo,
7
+ } from "./utils"
8
+
9
+ import type {
10
+ Fetch,
11
+ SocketInfo,
12
+ } from "./types"
13
+
14
+ export default class Fetcher {
15
+ private fetchHandler: Fetch
16
+
17
+ /**
18
+ * Constructor for FetchServer.
19
+ * @example const server = new FetchServer((request) => new Response("Hello world!", { status: 200 }))
20
+ */
21
+ constructor(handler: Fetch) {
22
+ if (typeof handler !== "function")
23
+ throw new TypeError("handler must be a function")
24
+ this.fetchHandler = handler
25
+
26
+ this.fetch = this.fetch.bind(this)
27
+ }
28
+
29
+ /**
30
+ * Handles an incoming request and emits events for request, response, error and end.
31
+ * @param {RequestInfo | URL} input - The request input.
32
+ * @param {RequestInit} [init] - The request initialization object.
33
+ * @return {Promise<Response>} - The response object.
34
+ */
35
+ async fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
36
+ let request: Request
37
+ let info: SocketInfo
38
+ let response: Response
39
+
40
+ if (
41
+ (input instanceof Request) &&
42
+ isSocketInfo(init)
43
+ ) {
44
+ request = input
45
+ info = init
46
+ } else {
47
+ request = new Request(input, init)
48
+ info = {
49
+ remoteAddress: null,
50
+ localAddress: null,
51
+ alpn: null
52
+ }
53
+ }
54
+
55
+ try {
56
+ response = await this.fetchHandler.call(this, request, info)
57
+ if (response instanceof Error)
58
+ throw response
59
+ } catch (error) {
60
+ response = internalServerError()
61
+ }
62
+
63
+ if (!(response instanceof Response))
64
+ response = noContent()
65
+
66
+ return response
67
+ }
68
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import Fetcher from "./fetcher"
2
+ export * from "./responses"
3
+ export type * from "./types"
4
+ export default Fetcher
5
+
6
+ // For backwards compatibility
7
+ export { Fetcher }
@@ -0,0 +1,19 @@
1
+ export function noContent() {
2
+ return new Response(null, { status: 204, statusText: "No Content" })
3
+ }
4
+
5
+ export function notFound() {
6
+ return new Response(null, { status: 404, statusText: "Not Found" })
7
+ }
8
+
9
+ export function badRequest() {
10
+ return new Response(null, { status: 400, statusText: "Bad Request" })
11
+ }
12
+
13
+ export function internalServerError() {
14
+ return new Response(null, { status: 500, statusText: "Internal Server Error" })
15
+ }
16
+
17
+ export function ok() {
18
+ return new Response(null, { status: 200, statusText: "OK" })
19
+ }
package/src/types.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type Fetcher from "./fetcher"
2
+
3
+ export type MaybePromise<T> = Promise<T> | T
4
+
5
+ export interface SocketInfo {
6
+ remoteAddress: string | null
7
+ localAddress: string | null
8
+ alpn: string | null
9
+ }
10
+
11
+ export type Fetch = (
12
+ this: Fetcher,
13
+ request: Request,
14
+ socketInfo: SocketInfo
15
+ ) => MaybePromise<Response>
package/src/utils.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { SocketInfo } from "./types"
2
+
3
+ export function isSocketInfo(obj: any): obj is SocketInfo {
4
+ return (
5
+ ("localAddress" in obj) &&
6
+ ("remoteAddress" in obj) &&
7
+ ("alpn" in obj)
8
+ )
9
+ }