@carno.js/core 0.2.3 → 0.2.5
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/dist/Carno.d.ts +6 -2
- package/dist/Carno.js +38 -39
- package/dist/container/DependencyResolver.d.ts +2 -0
- package/dist/container/DependencyResolver.js +4 -0
- package/dist/container/InjectorService.d.ts +24 -2
- package/dist/container/InjectorService.js +138 -12
- package/dist/domain/Context.d.ts +14 -4
- package/dist/domain/Context.js +87 -33
- package/dist/domain/cors-headers-cache.d.ts +15 -0
- package/dist/domain/cors-headers-cache.js +57 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/route/CompiledRoute.d.ts +23 -0
- package/dist/route/CompiledRoute.js +9 -0
- package/dist/route/FastPathExecutor.d.ts +4 -0
- package/dist/route/FastPathExecutor.js +19 -0
- package/dist/route/JITCompiler.d.ts +4 -0
- package/dist/route/JITCompiler.js +138 -0
- package/dist/route/ParamResolverFactory.d.ts +17 -0
- package/dist/route/ParamResolverFactory.js +71 -0
- package/dist/route/RouteCompiler.d.ts +29 -0
- package/dist/route/RouteCompiler.js +209 -0
- package/dist/route/RouteExecutor.d.ts +3 -2
- package/dist/route/RouteExecutor.js +15 -7
- package/dist/route/memoirist.d.ts +4 -0
- package/dist/route/memoirist.js +91 -2
- package/dist/utils/ValidationCache.d.ts +3 -0
- package/dist/utils/ValidationCache.js +27 -0
- package/package.json +3 -3
package/dist/route/memoirist.js
CHANGED
|
@@ -167,11 +167,100 @@ class Memoirist {
|
|
|
167
167
|
return null;
|
|
168
168
|
return matchRoute(url, url.length, root, 0);
|
|
169
169
|
}
|
|
170
|
+
updateStore(method, path, oldStore, newStore) {
|
|
171
|
+
const node = this.findNode(method, path);
|
|
172
|
+
if (!node) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (node.store === oldStore) {
|
|
176
|
+
node.store = newStore;
|
|
177
|
+
this.updateHistoryStore(method, path, newStore);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
if (node.params?.store === oldStore) {
|
|
181
|
+
node.params.store = newStore;
|
|
182
|
+
this.updateHistoryStore(method, path, newStore);
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (node.wildcardStore === oldStore) {
|
|
186
|
+
node.wildcardStore = newStore;
|
|
187
|
+
this.updateHistoryStore(method, path, newStore);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
updateHistoryStore(method, path, newStore) {
|
|
193
|
+
const normalizedPath = this.normalizePath(path);
|
|
194
|
+
for (let i = 0; i < this.history.length; i++) {
|
|
195
|
+
const [m, p] = this.history[i];
|
|
196
|
+
if (m === method && this.normalizePath(p) === normalizedPath) {
|
|
197
|
+
this.history[i] = [method, p, newStore];
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
normalizePath(path) {
|
|
203
|
+
if (path === '') {
|
|
204
|
+
return '/';
|
|
205
|
+
}
|
|
206
|
+
return path[0] !== '/' ? `/${path}` : path;
|
|
207
|
+
}
|
|
208
|
+
findNode(method, path) {
|
|
209
|
+
if (path === '') {
|
|
210
|
+
path = '/';
|
|
211
|
+
}
|
|
212
|
+
else if (path[0] !== '/') {
|
|
213
|
+
path = `/${path}`;
|
|
214
|
+
}
|
|
215
|
+
const isWildcard = path[path.length - 1] === '*';
|
|
216
|
+
if (isWildcard) {
|
|
217
|
+
path = path.slice(0, -1);
|
|
218
|
+
}
|
|
219
|
+
const inertParts = path.split(Memoirist.regex.static);
|
|
220
|
+
const paramParts = path.match(Memoirist.regex.params) || [];
|
|
221
|
+
if (inertParts[inertParts.length - 1] === '') {
|
|
222
|
+
inertParts.pop();
|
|
223
|
+
}
|
|
224
|
+
let node = this.root[method];
|
|
225
|
+
if (!node) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
let paramPartsIndex = 0;
|
|
229
|
+
for (let i = 0; i < inertParts.length; ++i) {
|
|
230
|
+
let part = inertParts[i];
|
|
231
|
+
if (i > 0) {
|
|
232
|
+
paramPartsIndex++;
|
|
233
|
+
if (!node.params?.inert) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
node = node.params.inert;
|
|
237
|
+
}
|
|
238
|
+
for (let j = 0;;) {
|
|
239
|
+
if (j === part.length) {
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
if (j === node.part.length) {
|
|
243
|
+
if (!node.inert?.has(part.charCodeAt(j))) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
node = node.inert.get(part.charCodeAt(j));
|
|
247
|
+
part = part.slice(j);
|
|
248
|
+
j = 0;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (part[j] !== node.part[j]) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
++j;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return node;
|
|
258
|
+
}
|
|
170
259
|
}
|
|
171
260
|
exports.Memoirist = Memoirist;
|
|
172
261
|
Memoirist.regex = {
|
|
173
|
-
static:
|
|
174
|
-
params:
|
|
262
|
+
static: /:[^/]+/,
|
|
263
|
+
params: /:[^/]+/g
|
|
175
264
|
};
|
|
176
265
|
const matchRoute = (url, urlLength, node, startIndex) => {
|
|
177
266
|
const part = node?.part;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidatable = isValidatable;
|
|
4
|
+
exports.preloadValidationForParams = preloadValidationForParams;
|
|
5
|
+
exports.clearValidationCache = clearValidationCache;
|
|
6
|
+
const isClassValidator_1 = require("./isClassValidator");
|
|
7
|
+
const cache = new Map();
|
|
8
|
+
function isValidatable(token) {
|
|
9
|
+
let result = cache.get(token);
|
|
10
|
+
if (result === undefined) {
|
|
11
|
+
result = (0, isClassValidator_1.isClassValidator)(token);
|
|
12
|
+
cache.set(token, result);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
function preloadValidationForParams(args) {
|
|
17
|
+
const indices = [];
|
|
18
|
+
for (let i = 0; i < args.length; i++) {
|
|
19
|
+
if (typeof args[i] === 'function' && isValidatable(args[i])) {
|
|
20
|
+
indices.push(i);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return indices;
|
|
24
|
+
}
|
|
25
|
+
function clearValidationCache() {
|
|
26
|
+
cache.clear();
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carno.js/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Carno.js is a framework for building web applications object oriented with TypeScript and Bun.sh",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "git+ssh://git@github.com:
|
|
31
|
+
"url": "git+ssh://git@github.com:carnojs/carno.js.git"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "2be3063988696f2cd3eb13363e1f679b9f58c2f1"
|
|
55
55
|
}
|