k99 0.2.0 → 0.3.0-beta.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 (154) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -0
  3. package/README.zh.md +8 -0
  4. package/browser/package.json +8 -0
  5. package/browser/types.d.ts +20 -0
  6. package/cli/command/create.js +1 -2
  7. package/cli/command/index.js +1 -2
  8. package/cli/command/init.js +3 -5
  9. package/cli/command/start.js +9 -10
  10. package/cli/index.js +3 -4
  11. package/cli/opt/bind.js +1 -2
  12. package/cli/opt/index.js +1 -2
  13. package/cli/opt/listen.js +1 -2
  14. package/cli/opt/path.js +1 -2
  15. package/cli/opt/port.js +1 -2
  16. package/cli/opt/show-router.js +1 -2
  17. package/dist/k99.browser.js +3110 -0
  18. package/dist/k99.browser.min.js +6 -0
  19. package/dist/k99.esm.js +3082 -0
  20. package/dist/k99.esm.min.js +6 -0
  21. package/dist/k99.js +3104 -0
  22. package/dist/k99.mjs +3082 -0
  23. package/dist/k99Browser.browser.js +490 -0
  24. package/dist/k99Browser.browser.min.js +6 -0
  25. package/dist/k99Browser.esm.js +475 -0
  26. package/dist/k99Browser.esm.min.js +6 -0
  27. package/dist/k99Browser.js +484 -0
  28. package/dist/k99Browser.mjs +475 -0
  29. package/dist/k99Services.browser.js +145 -0
  30. package/dist/k99Services.browser.min.js +6 -0
  31. package/dist/k99Services.esm.js +136 -0
  32. package/dist/k99Services.esm.min.js +6 -0
  33. package/dist/k99Services.js +141 -0
  34. package/dist/k99Services.mjs +136 -0
  35. package/node/index.js +1386 -0
  36. package/node/index.mjs +1350 -0
  37. package/node/package.json +5 -0
  38. package/node/types.d.ts +166 -0
  39. package/package.json +77 -11
  40. package/services/package.json +8 -0
  41. package/services/types.d.ts +22 -0
  42. package/starter.js +0 -1
  43. package/types.d.ts +748 -0
  44. package/Container.d.ts +0 -92
  45. package/Container.js +0 -242
  46. package/Container.js.map +0 -1
  47. package/Controller/index.d.ts +0 -178
  48. package/Controller/index.js +0 -576
  49. package/Controller/index.js.map +0 -1
  50. package/Controller/patch/cookie.d.ts +0 -33
  51. package/Controller/patch/cookie.js +0 -168
  52. package/Controller/patch/cookie.js.map +0 -1
  53. package/Controller/patch/index.d.ts +0 -7
  54. package/Controller/patch/index.js +0 -26
  55. package/Controller/patch/index.js.map +0 -1
  56. package/Controller/patch/render.d.ts +0 -5
  57. package/Controller/patch/render.js +0 -24
  58. package/Controller/patch/render.js.map +0 -1
  59. package/ExitSignal.d.ts +0 -14
  60. package/ExitSignal.js +0 -29
  61. package/ExitSignal.js.map +0 -1
  62. package/Extension.d.ts +0 -56
  63. package/Extension.js +0 -93
  64. package/Extension.js.map +0 -1
  65. package/ExtensionContainer.d.ts +0 -55
  66. package/ExtensionContainer.js +0 -105
  67. package/ExtensionContainer.js.map +0 -1
  68. package/Plugin.d.ts +0 -52
  69. package/Plugin.js +0 -278
  70. package/Plugin.js.map +0 -1
  71. package/Preprocessor.d.ts +0 -86
  72. package/Preprocessor.js +0 -135
  73. package/Preprocessor.js.map +0 -1
  74. package/Router/assets.d.ts +0 -33
  75. package/Router/assets.js +0 -106
  76. package/Router/assets.js.map +0 -1
  77. package/Router/callback.d.ts +0 -9
  78. package/Router/callback.js +0 -152
  79. package/Router/callback.js.map +0 -1
  80. package/Router/extendsInterface.d.ts +0 -8
  81. package/Router/extendsInterface.js +0 -43
  82. package/Router/extendsInterface.js.map +0 -1
  83. package/Router/index.d.ts +0 -184
  84. package/Router/index.js +0 -615
  85. package/Router/index.js.map +0 -1
  86. package/Router/log.d.ts +0 -23
  87. package/Router/log.js +0 -120
  88. package/Router/log.js.map +0 -1
  89. package/Router/order.d.ts +0 -14
  90. package/Router/order.js +0 -71
  91. package/Router/order.js.map +0 -1
  92. package/Router/register.d.ts +0 -9
  93. package/Router/register.js +0 -252
  94. package/Router/register.js.map +0 -1
  95. package/Router/registerManager.d.ts +0 -22
  96. package/Router/registerManager.js +0 -102
  97. package/Router/registerManager.js.map +0 -1
  98. package/Router/scan.d.ts +0 -2
  99. package/Router/scan.js +0 -72
  100. package/Router/scan.js.map +0 -1
  101. package/Router/setHandleItem.d.ts +0 -3
  102. package/Router/setHandleItem.js +0 -94
  103. package/Router/setHandleItem.js.map +0 -1
  104. package/Router/settings.d.ts +0 -12
  105. package/Router/settings.js +0 -74
  106. package/Router/settings.js.map +0 -1
  107. package/Router/start.d.ts +0 -3
  108. package/Router/start.js +0 -270
  109. package/Router/start.js.map +0 -1
  110. package/Router/vars.d.ts +0 -10
  111. package/Router/vars.js +0 -40
  112. package/Router/vars.js.map +0 -1
  113. package/Service.d.ts +0 -12
  114. package/Service.js +0 -20
  115. package/Service.js.map +0 -1
  116. package/cli/command/create.d.ts +0 -7
  117. package/cli/command/create.js.map +0 -1
  118. package/cli/command/index.d.ts +0 -7
  119. package/cli/command/index.js.map +0 -1
  120. package/cli/command/init.d.ts +0 -6
  121. package/cli/command/init.js.map +0 -1
  122. package/cli/command/start.d.ts +0 -6
  123. package/cli/command/start.js.map +0 -1
  124. package/cli/index.d.ts +0 -2
  125. package/cli/index.js.map +0 -1
  126. package/cli/opt/bind.d.ts +0 -3
  127. package/cli/opt/bind.js.map +0 -1
  128. package/cli/opt/index.d.ts +0 -16
  129. package/cli/opt/index.js.map +0 -1
  130. package/cli/opt/listen.d.ts +0 -3
  131. package/cli/opt/listen.js.map +0 -1
  132. package/cli/opt/path.d.ts +0 -3
  133. package/cli/opt/path.js.map +0 -1
  134. package/cli/opt/port.d.ts +0 -3
  135. package/cli/opt/port.js.map +0 -1
  136. package/cli/opt/show-router.d.ts +0 -3
  137. package/cli/opt/show-router.js.map +0 -1
  138. package/index.d.ts +0 -354
  139. package/index.js +0 -155
  140. package/index.js.map +0 -1
  141. package/setOptions.d.ts +0 -12
  142. package/setOptions.js +0 -60
  143. package/setOptions.js.map +0 -1
  144. package/starter.d.ts +0 -2
  145. package/starter.js.map +0 -1
  146. package/symbols.d.ts +0 -13
  147. package/symbols.js +0 -31
  148. package/symbols.js.map +0 -1
  149. package/util/index.d.ts +0 -5
  150. package/util/index.js +0 -92
  151. package/util/index.js.map +0 -1
  152. package/util/stream.d.ts +0 -19
  153. package/util/stream.js +0 -66
  154. package/util/stream.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ /*!
2
+ * k99 v0.3.0-beta.1
3
+ * (c) 2019-2022 Fierflame
4
+ * @license MIT
5
+ */
6
+ import { Service } from 'k99';
7
+
8
+ async function readText(read) {
9
+ const text = [];
10
+
11
+ for (;;) {
12
+ const t = await read(0, true);
13
+
14
+ if (t === null) {
15
+ break;
16
+ }
17
+
18
+ text.push(t);
19
+ }
20
+
21
+ return text.join('');
22
+ }
23
+
24
+ function getNameValue(s) {
25
+ const index = s.indexOf('=');
26
+
27
+ if (index < 0) {
28
+ return [decodeURIComponent(s), ''];
29
+ }
30
+
31
+ return [decodeURIComponent(s.substring(0, index)), decodeURIComponent(s.substring(index + 1))];
32
+ }
33
+
34
+ function parseQuery(s) {
35
+ const query = {};
36
+
37
+ for (const k of s.split('&').filter(Boolean)) {
38
+ const [index, value] = getNameValue(k);
39
+
40
+ if (index in query) {
41
+ query[index] = [query[index], value].flat();
42
+ } else {
43
+ query[index] = [value];
44
+ }
45
+ }
46
+
47
+ return query;
48
+ }
49
+
50
+ class FormBodyService extends Service {
51
+ export() {
52
+ const res = this.__result;
53
+
54
+ if (res !== undefined) {
55
+ return res;
56
+ }
57
+
58
+ const result = this.exec();
59
+ this.__result = result;
60
+ return result;
61
+ }
62
+
63
+ async parse() {
64
+ try {
65
+ let data = await readText(this.read);
66
+
67
+ if (!data.length) {
68
+ return null;
69
+ }
70
+
71
+ return parseQuery(data);
72
+ } catch {}
73
+
74
+ return null;
75
+ }
76
+
77
+ exec() {
78
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
79
+
80
+ if (mime !== 'application/x-www-form-urlencoded') {
81
+ return null;
82
+ }
83
+
84
+ if (charset && charset !== 'charset=UTF-8') {
85
+ return null;
86
+ }
87
+
88
+ return this.parse();
89
+ }
90
+
91
+ }
92
+
93
+ class JsonBodyService extends Service {
94
+ export() {
95
+ const res = this.__result;
96
+
97
+ if (res !== undefined) {
98
+ return res;
99
+ }
100
+
101
+ const result = this.exec();
102
+ this.__result = result;
103
+ return result;
104
+ }
105
+
106
+ async parse() {
107
+ try {
108
+ let data = await readText(this.read);
109
+
110
+ if (!data.length) {
111
+ return null;
112
+ }
113
+
114
+ return JSON.parse(data);
115
+ } catch {}
116
+
117
+ return null;
118
+ }
119
+
120
+ exec() {
121
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
122
+
123
+ if (mime !== 'application/json' && mime !== 'text/json') {
124
+ return null;
125
+ }
126
+
127
+ if (charset && charset !== 'charset=UTF-8') {
128
+ return null;
129
+ }
130
+
131
+ return this.parse();
132
+ }
133
+
134
+ }
135
+
136
+ export { FormBodyService, JsonBodyService };
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * k99 v0.3.0-beta.1
3
+ * (c) 2019-2022 Fierflame
4
+ * @license MIT
5
+ */
6
+ import{Service as t}from"k99";async function e(t){const e=[];for(;;){const n=await t(0,!0);if(null===n)break;e.push(n)}return e.join("")}function n(t){const e=t.indexOf("=");return e<0?[decodeURIComponent(t),""]:[decodeURIComponent(t.substring(0,e)),decodeURIComponent(t.substring(e+1))]}class r extends t{export(){const t=this.__result;if(void 0!==t)return t;const e=this.exec();return this.__result=e,e}async parse(){try{let t=await e(this.read);return t.length?function(t){const e={};for(const r of t.split("&").filter(Boolean)){const[t,s]=n(r);e[t]=t in e?[e[t],s].flat():[s]}return e}(t):null}catch{}return null}exec(){const[t,e]=this.requestType.replace(/\s/g,"").split(";");return"application/x-www-form-urlencoded"!==t||e&&"charset=UTF-8"!==e?null:this.parse()}}class s extends t{export(){const t=this.__result;if(void 0!==t)return t;const e=this.exec();return this.__result=e,e}async parse(){try{let t=await e(this.read);return t.length?JSON.parse(t):null}catch{}return null}exec(){const[t,e]=this.requestType.replace(/\s/g,"").split(";");return"application/json"!==t&&"text/json"!==t||e&&"charset=UTF-8"!==e?null:this.parse()}}export{r as FormBodyService,s as JsonBodyService};
@@ -0,0 +1,141 @@
1
+ /*!
2
+ * k99 v0.3.0-beta.1
3
+ * (c) 2019-2022 Fierflame
4
+ * @license MIT
5
+ */
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ var k99 = require('k99');
11
+
12
+ async function readText(read) {
13
+ const text = [];
14
+
15
+ for (;;) {
16
+ const t = await read(0, true);
17
+
18
+ if (t === null) {
19
+ break;
20
+ }
21
+
22
+ text.push(t);
23
+ }
24
+
25
+ return text.join('');
26
+ }
27
+
28
+ function getNameValue(s) {
29
+ const index = s.indexOf('=');
30
+
31
+ if (index < 0) {
32
+ return [decodeURIComponent(s), ''];
33
+ }
34
+
35
+ return [decodeURIComponent(s.substring(0, index)), decodeURIComponent(s.substring(index + 1))];
36
+ }
37
+
38
+ function parseQuery(s) {
39
+ const query = {};
40
+
41
+ for (const k of s.split('&').filter(Boolean)) {
42
+ const [index, value] = getNameValue(k);
43
+
44
+ if (index in query) {
45
+ query[index] = [query[index], value].flat();
46
+ } else {
47
+ query[index] = [value];
48
+ }
49
+ }
50
+
51
+ return query;
52
+ }
53
+
54
+ class FormBodyService extends k99.Service {
55
+ export() {
56
+ const res = this.__result;
57
+
58
+ if (res !== undefined) {
59
+ return res;
60
+ }
61
+
62
+ const result = this.exec();
63
+ this.__result = result;
64
+ return result;
65
+ }
66
+
67
+ async parse() {
68
+ try {
69
+ let data = await readText(this.read);
70
+
71
+ if (!data.length) {
72
+ return null;
73
+ }
74
+
75
+ return parseQuery(data);
76
+ } catch {}
77
+
78
+ return null;
79
+ }
80
+
81
+ exec() {
82
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
83
+
84
+ if (mime !== 'application/x-www-form-urlencoded') {
85
+ return null;
86
+ }
87
+
88
+ if (charset && charset !== 'charset=UTF-8') {
89
+ return null;
90
+ }
91
+
92
+ return this.parse();
93
+ }
94
+
95
+ }
96
+
97
+ class JsonBodyService extends k99.Service {
98
+ export() {
99
+ const res = this.__result;
100
+
101
+ if (res !== undefined) {
102
+ return res;
103
+ }
104
+
105
+ const result = this.exec();
106
+ this.__result = result;
107
+ return result;
108
+ }
109
+
110
+ async parse() {
111
+ try {
112
+ let data = await readText(this.read);
113
+
114
+ if (!data.length) {
115
+ return null;
116
+ }
117
+
118
+ return JSON.parse(data);
119
+ } catch {}
120
+
121
+ return null;
122
+ }
123
+
124
+ exec() {
125
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
126
+
127
+ if (mime !== 'application/json' && mime !== 'text/json') {
128
+ return null;
129
+ }
130
+
131
+ if (charset && charset !== 'charset=UTF-8') {
132
+ return null;
133
+ }
134
+
135
+ return this.parse();
136
+ }
137
+
138
+ }
139
+
140
+ exports.FormBodyService = FormBodyService;
141
+ exports.JsonBodyService = JsonBodyService;
@@ -0,0 +1,136 @@
1
+ /*!
2
+ * k99 v0.3.0-beta.1
3
+ * (c) 2019-2022 Fierflame
4
+ * @license MIT
5
+ */
6
+ import { Service } from 'k99';
7
+
8
+ async function readText(read) {
9
+ const text = [];
10
+
11
+ for (;;) {
12
+ const t = await read(0, true);
13
+
14
+ if (t === null) {
15
+ break;
16
+ }
17
+
18
+ text.push(t);
19
+ }
20
+
21
+ return text.join('');
22
+ }
23
+
24
+ function getNameValue(s) {
25
+ const index = s.indexOf('=');
26
+
27
+ if (index < 0) {
28
+ return [decodeURIComponent(s), ''];
29
+ }
30
+
31
+ return [decodeURIComponent(s.substring(0, index)), decodeURIComponent(s.substring(index + 1))];
32
+ }
33
+
34
+ function parseQuery(s) {
35
+ const query = {};
36
+
37
+ for (const k of s.split('&').filter(Boolean)) {
38
+ const [index, value] = getNameValue(k);
39
+
40
+ if (index in query) {
41
+ query[index] = [query[index], value].flat();
42
+ } else {
43
+ query[index] = [value];
44
+ }
45
+ }
46
+
47
+ return query;
48
+ }
49
+
50
+ class FormBodyService extends Service {
51
+ export() {
52
+ const res = this.__result;
53
+
54
+ if (res !== undefined) {
55
+ return res;
56
+ }
57
+
58
+ const result = this.exec();
59
+ this.__result = result;
60
+ return result;
61
+ }
62
+
63
+ async parse() {
64
+ try {
65
+ let data = await readText(this.read);
66
+
67
+ if (!data.length) {
68
+ return null;
69
+ }
70
+
71
+ return parseQuery(data);
72
+ } catch {}
73
+
74
+ return null;
75
+ }
76
+
77
+ exec() {
78
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
79
+
80
+ if (mime !== 'application/x-www-form-urlencoded') {
81
+ return null;
82
+ }
83
+
84
+ if (charset && charset !== 'charset=UTF-8') {
85
+ return null;
86
+ }
87
+
88
+ return this.parse();
89
+ }
90
+
91
+ }
92
+
93
+ class JsonBodyService extends Service {
94
+ export() {
95
+ const res = this.__result;
96
+
97
+ if (res !== undefined) {
98
+ return res;
99
+ }
100
+
101
+ const result = this.exec();
102
+ this.__result = result;
103
+ return result;
104
+ }
105
+
106
+ async parse() {
107
+ try {
108
+ let data = await readText(this.read);
109
+
110
+ if (!data.length) {
111
+ return null;
112
+ }
113
+
114
+ return JSON.parse(data);
115
+ } catch {}
116
+
117
+ return null;
118
+ }
119
+
120
+ exec() {
121
+ const [mime, charset] = this.requestType.replace(/\s/g, '').split(';');
122
+
123
+ if (mime !== 'application/json' && mime !== 'text/json') {
124
+ return null;
125
+ }
126
+
127
+ if (charset && charset !== 'charset=UTF-8') {
128
+ return null;
129
+ }
130
+
131
+ return this.parse();
132
+ }
133
+
134
+ }
135
+
136
+ export { FormBodyService, JsonBodyService };