qlara 0.1.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.
- package/dist/aws.cjs +1054 -0
- package/dist/aws.d.cts +45 -0
- package/dist/aws.d.ts +45 -0
- package/dist/aws.js +1048 -0
- package/dist/chunk-5K3GS3TV.js +70 -0
- package/dist/cli.js +1141 -0
- package/dist/index.cjs +100 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +14 -0
- package/dist/plugin/next.cjs +169 -0
- package/dist/plugin/next.d.cts +31 -0
- package/dist/plugin/next.d.ts +31 -0
- package/dist/plugin/next.js +99 -0
- package/dist/types-gl2xFqEX.d.cts +412 -0
- package/dist/types-gl2xFqEX.d.ts +412 -0
- package/package.json +87 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
function validateConfig(config, routes) {
|
|
3
|
+
if (!config.routeFile || typeof config.routeFile !== "string") {
|
|
4
|
+
throw new Error("[qlara] config.routeFile is required");
|
|
5
|
+
}
|
|
6
|
+
if (!config.provider) {
|
|
7
|
+
throw new Error("[qlara] config.provider is required");
|
|
8
|
+
}
|
|
9
|
+
if (routes.length === 0) {
|
|
10
|
+
throw new Error("[qlara] no routes found \u2014 routeFile must export at least one route pattern");
|
|
11
|
+
}
|
|
12
|
+
for (const route of routes) {
|
|
13
|
+
if (!route.pattern || typeof route.pattern !== "string") {
|
|
14
|
+
throw new Error("[qlara] each route must have a pattern string");
|
|
15
|
+
}
|
|
16
|
+
if (!route.pattern.startsWith("/")) {
|
|
17
|
+
throw new Error(`[qlara] route pattern must start with '/': ${route.pattern}`);
|
|
18
|
+
}
|
|
19
|
+
if (!route.pattern.includes(":")) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`[qlara] route pattern must contain at least one dynamic parameter (e.g. ':id'): ${route.pattern}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/routes.ts
|
|
28
|
+
function extractParamNames(pattern) {
|
|
29
|
+
const matches = pattern.match(/:([^/]+)/g);
|
|
30
|
+
if (!matches) return [];
|
|
31
|
+
return matches.map((m) => m.slice(1));
|
|
32
|
+
}
|
|
33
|
+
function patternToRegex(pattern) {
|
|
34
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35
|
+
const withParams = escaped.replace(/:([^/]+)/g, "([^/]+)");
|
|
36
|
+
return `^${withParams}$`;
|
|
37
|
+
}
|
|
38
|
+
function matchRoute(url, routes) {
|
|
39
|
+
const cleanUrl = url.split("?")[0].replace(/\/$/, "") || "/";
|
|
40
|
+
for (const route of routes) {
|
|
41
|
+
const regex = new RegExp(route.regex);
|
|
42
|
+
const match = cleanUrl.match(regex);
|
|
43
|
+
if (match) {
|
|
44
|
+
const params = {};
|
|
45
|
+
route.paramNames.forEach((name, i) => {
|
|
46
|
+
params[name] = match[i + 1];
|
|
47
|
+
});
|
|
48
|
+
return { route, params };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function buildManifest(routes) {
|
|
54
|
+
return {
|
|
55
|
+
version: 1,
|
|
56
|
+
routes: routes.map((route) => ({
|
|
57
|
+
pattern: route.pattern,
|
|
58
|
+
paramNames: extractParamNames(route.pattern),
|
|
59
|
+
regex: patternToRegex(route.pattern)
|
|
60
|
+
}))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
validateConfig,
|
|
66
|
+
extractParamNames,
|
|
67
|
+
patternToRegex,
|
|
68
|
+
matchRoute,
|
|
69
|
+
buildManifest
|
|
70
|
+
};
|