@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.
@@ -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: /:.+?(?=\/|$)/g
262
+ static: /:[^/]+/,
263
+ params: /:[^/]+/g
175
264
  };
176
265
  const matchRoute = (url, urlLength, node, startIndex) => {
177
266
  const part = node?.part;
@@ -0,0 +1,3 @@
1
+ export declare function isValidatable(token: Function): boolean;
2
+ export declare function preloadValidationForParams(args: any[]): number[];
3
+ export declare function clearValidationCache(): void;
@@ -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",
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:mlusca/carno.js.git"
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": "179037d66f41ab7014a008b141afce3c9232190e"
54
+ "gitHead": "2be3063988696f2cd3eb13363e1f679b9f58c2f1"
55
55
  }