@stacksjs/router 0.58.58 → 0.58.60

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/index.js CHANGED
@@ -77,7 +77,60 @@ var normalizeString = function(path, allowAboveRoot) {
77
77
  return res;
78
78
  };
79
79
  var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
80
+ var _UNC_REGEX = /^[/\\]{2}/;
80
81
  var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
82
+ var _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
83
+ var _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
84
+ var sep = "/";
85
+ var delimiter = ":";
86
+ var normalize = function(path) {
87
+ if (path.length === 0) {
88
+ return ".";
89
+ }
90
+ path = normalizeWindowsPath(path);
91
+ const isUNCPath = path.match(_UNC_REGEX);
92
+ const isPathAbsolute = isAbsolute(path);
93
+ const trailingSeparator = path[path.length - 1] === "/";
94
+ path = normalizeString(path, !isPathAbsolute);
95
+ if (path.length === 0) {
96
+ if (isPathAbsolute) {
97
+ return "/";
98
+ }
99
+ return trailingSeparator ? "./" : ".";
100
+ }
101
+ if (trailingSeparator) {
102
+ path += "/";
103
+ }
104
+ if (_DRIVE_LETTER_RE.test(path)) {
105
+ path += "/";
106
+ }
107
+ if (isUNCPath) {
108
+ if (!isPathAbsolute) {
109
+ return `//./${path}`;
110
+ }
111
+ return `//${path}`;
112
+ }
113
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
114
+ };
115
+ var join = function(...arguments_) {
116
+ if (arguments_.length === 0) {
117
+ return ".";
118
+ }
119
+ let joined;
120
+ for (const argument of arguments_) {
121
+ if (argument && argument.length > 0) {
122
+ if (joined === undefined) {
123
+ joined = argument;
124
+ } else {
125
+ joined += `/${argument}`;
126
+ }
127
+ }
128
+ }
129
+ if (joined === undefined) {
130
+ return ".";
131
+ }
132
+ return normalize(joined.replace(/\/\/+/g, "/"));
133
+ };
81
134
  var resolve = function(...arguments_) {
82
135
  arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
83
136
  let resolvedPath = "";
@@ -99,16 +152,462 @@ var resolve = function(...arguments_) {
99
152
  var isAbsolute = function(p) {
100
153
  return _IS_ABSOLUTE_RE.test(p);
101
154
  };
155
+ var toNamespacedPath = function(p) {
156
+ return normalizeWindowsPath(p);
157
+ };
158
+ var _EXTNAME_RE = /.(\.[^./]+)$/;
159
+ var extname = function(p) {
160
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
161
+ return match && match[1] || "";
162
+ };
163
+ var relative = function(from, to) {
164
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
165
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
166
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
167
+ return _to.join("/");
168
+ }
169
+ const _fromCopy = [..._from];
170
+ for (const segment of _fromCopy) {
171
+ if (_to[0] !== segment) {
172
+ break;
173
+ }
174
+ _from.shift();
175
+ _to.shift();
176
+ }
177
+ return [..._from.map(() => ".."), ..._to].join("/");
178
+ };
179
+ var dirname = function(p) {
180
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
181
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
182
+ segments[0] += "/";
183
+ }
184
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
185
+ };
186
+ var format = function(p) {
187
+ const segments = [p.root, p.dir, p.base ?? p.name + p.ext].filter(Boolean);
188
+ return normalizeWindowsPath(p.root ? resolve(...segments) : segments.join("/"));
189
+ };
190
+ var basename = function(p, extension) {
191
+ const lastSegment = normalizeWindowsPath(p).split("/").pop();
192
+ return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
193
+ };
194
+ var parse = function(p) {
195
+ const root = normalizeWindowsPath(p).split("/").shift() || "/";
196
+ const base = basename(p);
197
+ const extension = extname(base);
198
+ return {
199
+ root,
200
+ dir: dirname(p),
201
+ base,
202
+ ext: extension,
203
+ name: base.slice(0, base.length - extension.length)
204
+ };
205
+ };
102
206
  // /home/runner/work/stacks/stacks/storage/framework/core/path/src/index.ts
207
+ function actionsPath(path2) {
208
+ return corePath(`actions/src/${path2 || ""}`);
209
+ }
210
+ function relativeActionsPath(path2) {
211
+ return relative(projectPath(), actionsPath(path2));
212
+ }
213
+ function aiPath(path2) {
214
+ return corePath(`ai/${path2 || ""}`);
215
+ }
216
+ function assetsPath(path2) {
217
+ return resourcesPath(`assets/${path2 || ""}`);
218
+ }
219
+ function aliasPath() {
220
+ return corePath("alias/src/index.ts");
221
+ }
222
+ function buddyPath(path2, options) {
223
+ const absolutePath = corePath(`buddy/${path2 || ""}`);
224
+ if (options?.relative)
225
+ return relative(process2.cwd(), absolutePath);
226
+ return absolutePath;
227
+ }
228
+ function runtimePath(path2) {
229
+ return frameworkPath(`buddy/${path2 || ""}`);
230
+ }
231
+ function analyticsPath(path2) {
232
+ return corePath(`analytics/${path2 || ""}`);
233
+ }
234
+ function arraysPath(path2) {
235
+ return corePath(`arrays/${path2 || ""}`);
236
+ }
103
237
  function appPath(path2) {
104
238
  return projectPath(`app/${path2 || ""}`);
105
239
  }
240
+ function authPath(path2) {
241
+ return corePath(`auth/${path2 || ""}`);
242
+ }
243
+ function buildPath(path2) {
244
+ return corePath(`build/${path2 || ""}`);
245
+ }
246
+ function buildEnginePath(path2) {
247
+ return buildPath(`${path2 || ""}`);
248
+ }
249
+ function libsPath(path2) {
250
+ return frameworkPath(`libs/${path2 || ""}`);
251
+ }
252
+ function libsEntriesPath(path2) {
253
+ return libsPath(`entries/${path2 || ""}`);
254
+ }
255
+ function cachePath(path2) {
256
+ return corePath(`cache/${path2 || ""}`);
257
+ }
258
+ function chatPath(path2) {
259
+ return corePath(`chat/${path2 || ""}`);
260
+ }
261
+ function cliPath(path2) {
262
+ return corePath(`cli/${path2 || ""}`);
263
+ }
264
+ function cloudPath(path2) {
265
+ return corePath(`cloud/${path2 || ""}`);
266
+ }
267
+ function collectionsPath(path2) {
268
+ return corePath(`collections/${path2 || ""}`);
269
+ }
270
+ function commandsPath(path2) {
271
+ return appPath(`Commands/${path2 || ""}`);
272
+ }
273
+ function componentsPath(path2) {
274
+ return resourcesPath(`components/${path2 || ""}`);
275
+ }
276
+ function configPath(path2) {
277
+ return corePath(`config/${path2 || ""}`);
278
+ }
279
+ function corePath(path2) {
280
+ return frameworkPath(`core/${path2 || ""}`);
281
+ }
282
+ function customElementsDataPath() {
283
+ return frameworkPath("core/custom-elements.json");
284
+ }
285
+ function databasePath(path2) {
286
+ return corePath(`database/${path2 || ""}`);
287
+ }
288
+ function datetimePath(path2) {
289
+ return corePath(`datetime/${path2 || ""}`);
290
+ }
291
+ function developmentPath(path2) {
292
+ return corePath(`development/${path2 || ""}`);
293
+ }
294
+ function desktopPath(path2) {
295
+ return corePath(`desktop/${path2 || ""}`);
296
+ }
297
+ function docsPath(path2) {
298
+ return corePath(`docs/${path2 || ""}`);
299
+ }
300
+ function dnsPath(path2) {
301
+ return corePath(`domains/${path2 || ""}`);
302
+ }
303
+ function emailPath(path2) {
304
+ return notificationsPath(`email/${path2 || ""}`);
305
+ }
306
+ function enumsPath(path2) {
307
+ return corePath(`enums/${path2 || ""}`);
308
+ }
309
+ function errorHandlingPath(path2) {
310
+ return corePath(`error-handling/${path2 || ""}`);
311
+ }
312
+ function eventsPath(path2) {
313
+ return corePath(`events/${path2 || ""}`);
314
+ }
315
+ function coreEnvPath(path2) {
316
+ return corePath(`env/${path2 || ""}`);
317
+ }
318
+ function examplesPath(type) {
319
+ return frameworkPath(`examples/${type || ""}`);
320
+ }
321
+ function fakerPath(path2) {
322
+ return corePath(`faker/${path2 || ""}`);
323
+ }
324
+ function frameworkPath(path2, options) {
325
+ const absolutePath = projectStoragePath(`framework/${path2 || ""}`);
326
+ if (options?.relative)
327
+ return relative(options.cwd || process2.cwd(), absolutePath);
328
+ return absolutePath;
329
+ }
330
+ function healthPath(path2) {
331
+ return corePath(`health/${path2 || ""}`);
332
+ }
333
+ function functionsPath(path2) {
334
+ return resourcesPath(`functions/${path2 || ""}`);
335
+ }
336
+ function gitPath(path2) {
337
+ return corePath(`git/${path2 || ""}`);
338
+ }
339
+ function langPath(path2) {
340
+ return projectPath(`lang/${path2 || ""}`);
341
+ }
342
+ function layoutsPath(path2, options) {
343
+ const absolutePath = resourcesPath(`layouts/${path2 || ""}`);
344
+ if (options?.relative)
345
+ return relative(process2.cwd(), absolutePath);
346
+ return absolutePath;
347
+ }
348
+ function libraryEntryPath(type) {
349
+ return libsEntriesPath(`${type}.ts`);
350
+ }
351
+ function lintPath(path2) {
352
+ return corePath(`lint/${path2 || ""}`);
353
+ }
354
+ function listenersPath(path2) {
355
+ return appPath(`Listeners/${path2 || ""}`);
356
+ }
357
+ function jobsPath(path2) {
358
+ return appPath(`Jobs/${path2 || ""}`);
359
+ }
360
+ function loggingPath(path2) {
361
+ return corePath(`logging/${path2 || ""}`);
362
+ }
363
+ function modulesPath(path2) {
364
+ return resourcesPath(`modules/${path2 || ""}`);
365
+ }
366
+ function notificationsPath(path2) {
367
+ return corePath(`notifications/${path2 || ""}`);
368
+ }
369
+ function ormPath(path2) {
370
+ return corePath(`orm/${path2 || ""}`);
371
+ }
372
+ function objectsPath(path2) {
373
+ return corePath(`objects/${path2 || ""}`);
374
+ }
375
+ function onboardingPath(path2) {
376
+ return projectPath(`${path2 || "views/dashboard/onboarding"}`);
377
+ }
378
+ function packageJsonPath(type) {
379
+ if (type === "vue-components")
380
+ return frameworkPath("libs/components/vue/package.json");
381
+ if (type === "web-components")
382
+ return frameworkPath("libs/components/web/package.json");
383
+ return frameworkPath(`libs/${type}/package.json`);
384
+ }
385
+ function viewsPath(path2) {
386
+ return resourcesPath(`views/${path2 || ""}`);
387
+ }
388
+ function pathPath(path2) {
389
+ return corePath(`path/${path2 || ""}`);
390
+ }
391
+ function paymentsPath(path2) {
392
+ return corePath(`payments/${path2 || ""}`);
393
+ }
106
394
  function projectPath(filePath = "") {
107
395
  let path2 = process2.cwd();
108
396
  while (path2.includes("storage"))
109
397
  path2 = resolve(path2, "..");
110
398
  return resolve(path2, filePath);
111
399
  }
400
+ function projectConfigPath(path2) {
401
+ return projectPath(`config/${path2 || ""}`);
402
+ }
403
+ function projectStoragePath(path2) {
404
+ return projectPath(`storage/${path2 || ""}`);
405
+ }
406
+ function publicPath(path2) {
407
+ return projectPath(`public/${path2 || ""}`);
408
+ }
409
+ function pushPath(path2) {
410
+ return notificationsPath(`push/${path2 || ""}`);
411
+ }
412
+ function queryBuilderPath(path2) {
413
+ return corePath(`query-builder/${path2 || ""}`);
414
+ }
415
+ function queuePath(path2) {
416
+ return corePath(`queue/${path2 || ""}`);
417
+ }
418
+ function realtimePath(path2) {
419
+ return corePath(`realtime/${path2 || ""}`);
420
+ }
421
+ function resourcesPath(path2) {
422
+ return projectPath(`resources/${path2 || ""}`);
423
+ }
424
+ function replPath(path2) {
425
+ return corePath(`repl/${path2 || ""}`);
426
+ }
427
+ function routerPath(path2) {
428
+ return corePath(`router/${path2 || ""}`);
429
+ }
430
+ function routesPath(path2) {
431
+ return projectPath(`routes/${path2 || ""}`);
432
+ }
433
+ function searchEnginePath(path2) {
434
+ return corePath(`search-engine/${path2 || ""}`);
435
+ }
436
+ function settingsPath(path2) {
437
+ return projectPath(`${path2 || "views/dashboard/settings"}`);
438
+ }
439
+ function scriptsPath(path2) {
440
+ return frameworkPath(`scripts/${path2 || ""}`);
441
+ }
442
+ function schedulerPath(path2) {
443
+ return corePath(`scheduler/${path2 || ""}`);
444
+ }
445
+ function signalsPath(path2) {
446
+ return corePath(`signals/${path2 || ""}`);
447
+ }
448
+ function slugPath(path2) {
449
+ return corePath(`slug/${path2 || ""}`);
450
+ }
451
+ function smsPath(path2) {
452
+ return notificationsPath(`sms/${path2 || ""}`);
453
+ }
454
+ function storagePath(path2) {
455
+ return corePath(`storage/${path2 || ""}`);
456
+ }
457
+ function storesPath(path2) {
458
+ return resourcesPath(`stores/${path2 || ""}`);
459
+ }
460
+ function securityPath(path2) {
461
+ return corePath(`security/${path2 || ""}`);
462
+ }
463
+ function serverPath(path2) {
464
+ return corePath(`server/${path2 || ""}`);
465
+ }
466
+ function serverlessPath(path2) {
467
+ return corePath(`serverless/${path2 || ""}`);
468
+ }
469
+ function stacksPath(path2) {
470
+ return frameworkPath(`src/${path2 || ""}`);
471
+ }
472
+ function stringsPath(path2) {
473
+ return corePath(`strings/${path2 || ""}`);
474
+ }
475
+ function testingPath(path2) {
476
+ return corePath(`testing/${path2 || ""}`);
477
+ }
478
+ function tinkerPath(path2) {
479
+ return corePath(`tinker/${path2 || ""}`);
480
+ }
481
+ function testsPath(path2) {
482
+ return frameworkPath(`tests/${path2 || ""}`);
483
+ }
484
+ function typesPath(path2) {
485
+ return corePath(`types/${path2 || ""}`);
486
+ }
487
+ function uiPath(path2) {
488
+ return corePath(`ui/${path2 || ""}`);
489
+ }
490
+ function utilsPath(path2) {
491
+ return corePath(`utils/${path2 || ""}`);
492
+ }
493
+ function validationPath(path2) {
494
+ return corePath(`validation/${path2 || ""}`);
495
+ }
496
+ function vitePath(path2) {
497
+ return corePath(`vite/${path2 || ""}`);
498
+ }
499
+ function xRayPath(path2) {
500
+ return frameworkPath(`stacks/x-ray/${path2 || ""}`);
501
+ }
502
+ var path2 = {
503
+ actionsPath,
504
+ aiPath,
505
+ assetsPath,
506
+ relativeActionsPath,
507
+ aliasPath,
508
+ analyticsPath,
509
+ arraysPath,
510
+ appPath,
511
+ authPath,
512
+ buddyPath,
513
+ buildEnginePath,
514
+ libsEntriesPath,
515
+ buildPath,
516
+ cachePath,
517
+ chatPath,
518
+ cliPath,
519
+ cloudPath,
520
+ collectionsPath,
521
+ commandsPath,
522
+ componentsPath,
523
+ configPath,
524
+ projectConfigPath,
525
+ corePath,
526
+ customElementsDataPath,
527
+ databasePath,
528
+ datetimePath,
529
+ developmentPath,
530
+ desktopPath,
531
+ docsPath,
532
+ dnsPath,
533
+ emailPath,
534
+ enumsPath,
535
+ errorHandlingPath,
536
+ eventsPath,
537
+ coreEnvPath,
538
+ healthPath,
539
+ examplesPath,
540
+ fakerPath,
541
+ frameworkPath,
542
+ storagePath,
543
+ functionsPath,
544
+ gitPath,
545
+ langPath,
546
+ layoutsPath,
547
+ libsPath,
548
+ libraryEntryPath,
549
+ lintPath,
550
+ listenersPath,
551
+ loggingPath,
552
+ jobsPath,
553
+ modulesPath,
554
+ ormPath,
555
+ objectsPath,
556
+ onboardingPath,
557
+ notificationsPath,
558
+ packageJsonPath,
559
+ viewsPath,
560
+ pathPath,
561
+ paymentsPath,
562
+ projectPath,
563
+ projectStoragePath,
564
+ publicPath,
565
+ pushPath,
566
+ queryBuilderPath,
567
+ queuePath,
568
+ realtimePath,
569
+ resourcesPath,
570
+ replPath,
571
+ routerPath,
572
+ routesPath,
573
+ runtimePath,
574
+ searchEnginePath,
575
+ schedulerPath,
576
+ settingsPath,
577
+ smsPath,
578
+ signalsPath,
579
+ slugPath,
580
+ scriptsPath,
581
+ securityPath,
582
+ serverPath,
583
+ serverlessPath,
584
+ stacksPath,
585
+ stringsPath,
586
+ storesPath,
587
+ testingPath,
588
+ testsPath,
589
+ tinkerPath,
590
+ typesPath,
591
+ uiPath,
592
+ utilsPath,
593
+ validationPath,
594
+ vitePath,
595
+ xRayPath,
596
+ basename,
597
+ delimiter,
598
+ dirname,
599
+ extname,
600
+ format,
601
+ isAbsolute,
602
+ join,
603
+ normalize,
604
+ normalizeString,
605
+ parse,
606
+ relative,
607
+ resolve,
608
+ sep,
609
+ toNamespacedPath
610
+ };
112
611
 
113
612
  // src/middleware.ts
114
613
  async function importMiddlewares(directory) {
@@ -281,32 +780,36 @@ class Router {
281
780
  paramNames: []
282
781
  });
283
782
  }
284
- get(path4, callback) {
285
- this.addRoute("GET", path4, callback, 200);
783
+ async get(path5, callback) {
784
+ if (typeof callback === "string") {
785
+ const actionModule = await import(path2.actionsPath(`${callback}.ts`));
786
+ callback = actionModule.default.handle;
787
+ }
788
+ this.addRoute("GET", path5, callback, 200);
286
789
  return this;
287
790
  }
288
- post(path4, callback) {
289
- this.addRoute("POST", path4, callback, 201);
791
+ post(path5, callback) {
792
+ this.addRoute("POST", path5, callback, 201);
290
793
  return this;
291
794
  }
292
- view(path4, callback) {
293
- this.addRoute("GET", path4, callback, 200);
795
+ view(path5, callback) {
796
+ this.addRoute("GET", path5, callback, 200);
294
797
  return this;
295
798
  }
296
- redirect(path4, callback, _status) {
297
- this.addRoute("GET", path4, callback, 302);
799
+ redirect(path5, callback, _status) {
800
+ this.addRoute("GET", path5, callback, 302);
298
801
  return this;
299
802
  }
300
- delete(path4, callback) {
301
- this.addRoute("DELETE", path4, callback, 204);
803
+ delete(path5, callback) {
804
+ this.addRoute("DELETE", path5, callback, 204);
302
805
  return this;
303
806
  }
304
- patch(path4, callback) {
305
- this.addRoute("PATCH", path4, callback, 202);
807
+ patch(path5, callback) {
808
+ this.addRoute("PATCH", path5, callback, 202);
306
809
  return this;
307
810
  }
308
- put(path4, callback) {
309
- this.addRoute("PUT", path4, callback, 202);
811
+ put(path5, callback) {
812
+ this.addRoute("PUT", path5, callback, 202);
310
813
  return this;
311
814
  }
312
815
  group(options, callback) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/router",
3
3
  "type": "module",
4
- "version": "0.58.58",
4
+ "version": "0.58.60",
5
5
  "description": "The Stacks framework router.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
package/src/router.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { RedirectCode, Route, RouteGroupOptions, StatusCode } from '@stacksjs/types'
2
- import { projectPath } from '@stacksjs/path'
2
+ import { path as p, projectPath } from '@stacksjs/path'
3
3
 
4
4
  export interface RouterInterface {
5
- get: (url: Route['url'], callback: Route['callback']) => this
5
+ get: (url: Route['url'], callback: Route['callback']) => Promise<this>
6
6
  post: (url: Route['url'], callback: Route['callback']) => this
7
7
  view: (url: Route['url'], callback: Route['callback']) => this
8
8
  redirect: (url: Route['url'], callback: Route['callback'], status?: RedirectCode) => this
@@ -46,7 +46,14 @@ export class Router implements RouterInterface {
46
46
  })
47
47
  }
48
48
 
49
- public get(path: Route['url'], callback: Route['callback']): this {
49
+ public async get(path: Route['url'], callback: Route['callback']): Promise<this> {
50
+ // check if callback is a string and if it is, then import that module path and use the default.handle function as the callback
51
+ if (typeof callback === 'string') {
52
+ // import the module and use the default.handle function as the callback
53
+ const actionModule = await import(p.actionsPath(`${callback}.ts`))
54
+ callback = actionModule.default.handle
55
+ }
56
+
50
57
  this.addRoute('GET', path, callback, 200)
51
58
  return this
52
59
  }