@markless/router 0.1.0 → 0.2.0

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.
@@ -0,0 +1,35 @@
1
+ const routeParamPattern = /\[\.\.\.([A-Za-z_$][\w$]*)\]|\[([A-Za-z_$][\w$]*)\]/g;
2
+
3
+ export function __marklessRouteHref(
4
+ pattern: string,
5
+ params: Readonly<Record<string, unknown>>,
6
+ ): string {
7
+ return pattern.replace(routeParamPattern, (_match, catchAll, dynamic) => {
8
+ const name = catchAll || dynamic;
9
+ const value = params?.[name];
10
+
11
+ if (catchAll) {
12
+ return encodeCatchAllParam(pattern, value);
13
+ }
14
+
15
+ if (value === null || value === undefined) {
16
+ throw new Error(`Typed route error: ${pattern} requires params:\n- ${name}`);
17
+ }
18
+
19
+ return encodeURIComponent(String(value));
20
+ });
21
+ }
22
+
23
+ function encodeCatchAllParam(pattern: string, value: unknown): string {
24
+ const segments = Array.isArray(value)
25
+ ? value
26
+ : value === null || value === undefined
27
+ ? []
28
+ : String(value).split('/');
29
+
30
+ if (segments.length === 0 || segments.some((segment) => String(segment) === '')) {
31
+ throw new Error(`Typed route error: ${pattern} requires a non-empty catch-all param.`);
32
+ }
33
+
34
+ return segments.map((segment) => encodeURIComponent(String(segment))).join('/');
35
+ }
@@ -0,0 +1,25 @@
1
+ import { createServerEntry } from '@markless/router/vite/runtime/create-server-entry';
2
+ import { resumeEntryPath } from 'virtual:markless-router/resume-entry-path';
3
+ import { navigationEntryPath } from 'virtual:markless-router/navigation-entry-path';
4
+ import {
5
+ routeModulePreloads,
6
+ routeSsrModulePreloads,
7
+ routeStylesheets,
8
+ } from 'virtual:markless-router/route-preloads';
9
+ import { pageModuleLoaders, routeFileIds } from 'virtual:markless-router/routes';
10
+
11
+ const documentModuleLoaders = import.meta.glob(['/document.tsrx']);
12
+ const entry = createServerEntry({
13
+ dev: import.meta.env.DEV,
14
+ resumeEntryPath,
15
+ navigationEntryPath,
16
+ routeModulePreloads,
17
+ routeSsrModulePreloads,
18
+ routeStylesheets,
19
+ documentModuleLoader: documentModuleLoaders['/document.tsrx'],
20
+ pageModuleLoaders,
21
+ routeFileIds,
22
+ });
23
+
24
+ export const fetch = entry.fetch;
25
+ export default entry;