@carno.js/core 1.0.2 → 1.0.4
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/LICENSE +21 -674
- package/README.md +188 -188
- package/dist/bun/index.js +7 -20
- package/dist/bun/index.js.map +28 -28
- package/dist/context/Context.js +2 -1
- package/dist/context/Context.mjs +2 -1
- package/dist/utils/parseQuery.js +84 -0
- package/dist/utils/parseQuery.mjs +63 -0
- package/package.json +3 -2
- package/src/Carno.ts +605 -605
- package/src/DefaultRoutes.ts +34 -34
- package/src/cache/CacheDriver.ts +50 -50
- package/src/cache/CacheService.ts +139 -139
- package/src/cache/MemoryDriver.ts +104 -104
- package/src/cache/RedisDriver.ts +116 -116
- package/src/compiler/JITCompiler.ts +167 -167
- package/src/container/Container.ts +168 -168
- package/src/context/Context.ts +130 -128
- package/src/cors/CorsHandler.ts +145 -145
- package/src/decorators/Controller.ts +63 -63
- package/src/decorators/Inject.ts +16 -16
- package/src/decorators/Middleware.ts +22 -22
- package/src/decorators/Service.ts +18 -18
- package/src/decorators/methods.ts +58 -58
- package/src/decorators/params.ts +47 -47
- package/src/events/Lifecycle.ts +97 -97
- package/src/exceptions/HttpException.ts +99 -99
- package/src/index.ts +92 -92
- package/src/metadata.ts +46 -46
- package/src/middleware/CarnoMiddleware.ts +14 -14
- package/src/router/RadixRouter.ts +225 -225
- package/src/testing/TestHarness.ts +177 -177
- package/src/utils/Metadata.ts +43 -43
- package/src/utils/parseQuery.ts +161 -0
- package/src/validation/ValibotAdapter.ts +95 -95
- package/src/validation/ValidatorAdapter.ts +69 -69
- package/src/validation/ZodAdapter.ts +102 -102
package/dist/context/Context.js
CHANGED
|
@@ -17,6 +17,7 @@ __export(Context_exports, {
|
|
|
17
17
|
Context: () => Context
|
|
18
18
|
});
|
|
19
19
|
module.exports = __toCommonJS(Context_exports);
|
|
20
|
+
var import_parseQuery = require('../utils/parseQuery.js');
|
|
20
21
|
const EMPTY_PARAMS = Object.freeze({});
|
|
21
22
|
class Context {
|
|
22
23
|
constructor(req, params = EMPTY_PARAMS) {
|
|
@@ -38,7 +39,7 @@ class Context {
|
|
|
38
39
|
return this._url || (this._url = new URL(this.req.url)), this._url;
|
|
39
40
|
}
|
|
40
41
|
get query() {
|
|
41
|
-
return this._query || (this._query =
|
|
42
|
+
return this._query || (this._query = (0, import_parseQuery.parseQueryFromURL)(this.req.url)), this._query;
|
|
42
43
|
}
|
|
43
44
|
get body() {
|
|
44
45
|
return this._body;
|
package/dist/context/Context.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseQueryFromURL } from "../utils/parseQuery.mjs";
|
|
1
2
|
const EMPTY_PARAMS = Object.freeze({});
|
|
2
3
|
class Context {
|
|
3
4
|
constructor(req, params = EMPTY_PARAMS) {
|
|
@@ -19,7 +20,7 @@ class Context {
|
|
|
19
20
|
return this._url || (this._url = new URL(this.req.url)), this._url;
|
|
20
21
|
}
|
|
21
22
|
get query() {
|
|
22
|
-
return this._query || (this._query =
|
|
23
|
+
return this._query || (this._query = parseQueryFromURL(this.req.url)), this._query;
|
|
23
24
|
}
|
|
24
25
|
get body() {
|
|
25
26
|
return this._body;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var parseQuery_exports = {};
|
|
16
|
+
__export(parseQuery_exports, {
|
|
17
|
+
parseQueryFromURL: () => parseQueryFromURL,
|
|
18
|
+
parseQueryString: () => parseQueryString
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(parseQuery_exports);
|
|
21
|
+
const KEY_HAS_PLUS = 1, KEY_NEEDS_DECODE = 2, VALUE_HAS_PLUS = 4, VALUE_NEEDS_DECODE = 8;
|
|
22
|
+
function parseQueryFromURL(url) {
|
|
23
|
+
const queryStart = url.indexOf("?");
|
|
24
|
+
if (queryStart === -1)
|
|
25
|
+
return /* @__PURE__ */ Object.create(null);
|
|
26
|
+
let queryEnd = url.indexOf("#", queryStart);
|
|
27
|
+
return queryEnd === -1 && (queryEnd = url.length), parseQuery(url, queryStart + 1, queryEnd);
|
|
28
|
+
}
|
|
29
|
+
function parseQueryString(input) {
|
|
30
|
+
return parseQuery(input, 0, input.length);
|
|
31
|
+
}
|
|
32
|
+
function parseQuery(input, startIndex, endIndex) {
|
|
33
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
34
|
+
let flags = 0, startingIndex = startIndex - 1, equalityIndex = startingIndex;
|
|
35
|
+
for (let i = startIndex; i < endIndex; i++)
|
|
36
|
+
switch (input.charCodeAt(i)) {
|
|
37
|
+
// '&' - separator between key-value pairs
|
|
38
|
+
case 38:
|
|
39
|
+
processKeyValuePair(i), startingIndex = i, equalityIndex = i, flags = 0;
|
|
40
|
+
break;
|
|
41
|
+
// '=' - separator between key and value
|
|
42
|
+
case 61:
|
|
43
|
+
equalityIndex <= startingIndex ? equalityIndex = i : flags |= 8;
|
|
44
|
+
break;
|
|
45
|
+
// '+' - space encoding
|
|
46
|
+
case 43:
|
|
47
|
+
equalityIndex > startingIndex ? flags |= 4 : flags |= 1;
|
|
48
|
+
break;
|
|
49
|
+
// '%' - URL encoding
|
|
50
|
+
case 37:
|
|
51
|
+
equalityIndex > startingIndex ? flags |= 8 : flags |= 2;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return startingIndex < endIndex && processKeyValuePair(endIndex), result;
|
|
55
|
+
function processKeyValuePair(pairEndIndex) {
|
|
56
|
+
const hasBothKeyValuePair = equalityIndex > startingIndex, effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : pairEndIndex, keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
|
|
57
|
+
if (!hasBothKeyValuePair && keySlice.length === 0)
|
|
58
|
+
return;
|
|
59
|
+
let finalKey = keySlice;
|
|
60
|
+
if (flags & 1 && (finalKey = finalKey.replace(/\+/g, " ")), flags & 2)
|
|
61
|
+
try {
|
|
62
|
+
finalKey = decodeURIComponent(finalKey);
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
let finalValue = "";
|
|
66
|
+
if (hasBothKeyValuePair) {
|
|
67
|
+
let valueSlice = input.slice(equalityIndex + 1, pairEndIndex);
|
|
68
|
+
if (flags & 4 && (valueSlice = valueSlice.replace(/\+/g, " ")), flags & 8)
|
|
69
|
+
try {
|
|
70
|
+
finalValue = decodeURIComponent(valueSlice);
|
|
71
|
+
} catch {
|
|
72
|
+
finalValue = valueSlice;
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
finalValue = valueSlice;
|
|
76
|
+
}
|
|
77
|
+
result[finalKey] = finalValue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
parseQueryFromURL,
|
|
83
|
+
parseQueryString
|
|
84
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const KEY_HAS_PLUS = 1, KEY_NEEDS_DECODE = 2, VALUE_HAS_PLUS = 4, VALUE_NEEDS_DECODE = 8;
|
|
2
|
+
function parseQueryFromURL(url) {
|
|
3
|
+
const queryStart = url.indexOf("?");
|
|
4
|
+
if (queryStart === -1)
|
|
5
|
+
return /* @__PURE__ */ Object.create(null);
|
|
6
|
+
let queryEnd = url.indexOf("#", queryStart);
|
|
7
|
+
return queryEnd === -1 && (queryEnd = url.length), parseQuery(url, queryStart + 1, queryEnd);
|
|
8
|
+
}
|
|
9
|
+
function parseQueryString(input) {
|
|
10
|
+
return parseQuery(input, 0, input.length);
|
|
11
|
+
}
|
|
12
|
+
function parseQuery(input, startIndex, endIndex) {
|
|
13
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
14
|
+
let flags = 0, startingIndex = startIndex - 1, equalityIndex = startingIndex;
|
|
15
|
+
for (let i = startIndex; i < endIndex; i++)
|
|
16
|
+
switch (input.charCodeAt(i)) {
|
|
17
|
+
// '&' - separator between key-value pairs
|
|
18
|
+
case 38:
|
|
19
|
+
processKeyValuePair(i), startingIndex = i, equalityIndex = i, flags = 0;
|
|
20
|
+
break;
|
|
21
|
+
// '=' - separator between key and value
|
|
22
|
+
case 61:
|
|
23
|
+
equalityIndex <= startingIndex ? equalityIndex = i : flags |= 8;
|
|
24
|
+
break;
|
|
25
|
+
// '+' - space encoding
|
|
26
|
+
case 43:
|
|
27
|
+
equalityIndex > startingIndex ? flags |= 4 : flags |= 1;
|
|
28
|
+
break;
|
|
29
|
+
// '%' - URL encoding
|
|
30
|
+
case 37:
|
|
31
|
+
equalityIndex > startingIndex ? flags |= 8 : flags |= 2;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return startingIndex < endIndex && processKeyValuePair(endIndex), result;
|
|
35
|
+
function processKeyValuePair(pairEndIndex) {
|
|
36
|
+
const hasBothKeyValuePair = equalityIndex > startingIndex, effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : pairEndIndex, keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
|
|
37
|
+
if (!hasBothKeyValuePair && keySlice.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
let finalKey = keySlice;
|
|
40
|
+
if (flags & 1 && (finalKey = finalKey.replace(/\+/g, " ")), flags & 2)
|
|
41
|
+
try {
|
|
42
|
+
finalKey = decodeURIComponent(finalKey);
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
let finalValue = "";
|
|
46
|
+
if (hasBothKeyValuePair) {
|
|
47
|
+
let valueSlice = input.slice(equalityIndex + 1, pairEndIndex);
|
|
48
|
+
if (flags & 4 && (valueSlice = valueSlice.replace(/\+/g, " ")), flags & 8)
|
|
49
|
+
try {
|
|
50
|
+
finalValue = decodeURIComponent(valueSlice);
|
|
51
|
+
} catch {
|
|
52
|
+
finalValue = valueSlice;
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
finalValue = valueSlice;
|
|
56
|
+
}
|
|
57
|
+
result[finalKey] = finalValue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
parseQueryFromURL,
|
|
62
|
+
parseQueryString
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carno.js/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Ultra-fast HTTP framework with aggressive AOT/JIT compilation",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"valibot": "^1.2.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"reflect-metadata": "^0.2.2",
|
|
17
18
|
"zod": "^4.3.5"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"esbuild-fix-imports-plugin": "^1.0.23",
|
|
21
22
|
"tsup": "^8.5.1"
|
|
22
23
|
},
|
|
23
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "8aba0ef37b8be1b9b5441feb9a29a8d686821561"
|
|
24
25
|
}
|