litestar-vite-plugin 0.5.2 → 0.6.1
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.
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
2
|
+
declare global {
|
|
3
|
+
var routes: {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export declare function route(routeName: string, ...args: any[]): string | null;
|
package/inertia-helpers/index.js
CHANGED
|
@@ -1,10 +1,56 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
export async function resolvePageComponent(path, pages) {
|
|
2
|
-
for (const p of
|
|
3
|
+
for (const p of Array.isArray(path) ? path : [path]) {
|
|
3
4
|
const page = pages[p];
|
|
4
|
-
if (typeof page ===
|
|
5
|
+
if (typeof page === "undefined") {
|
|
5
6
|
continue;
|
|
6
7
|
}
|
|
7
|
-
return typeof page ===
|
|
8
|
+
return typeof page === "function" ? page() : page;
|
|
8
9
|
}
|
|
9
10
|
throw new Error(`Page not found: ${path}`);
|
|
10
11
|
}
|
|
12
|
+
globalThis.routes = globalThis.routes || {};
|
|
13
|
+
export function route(routeName, ...args) {
|
|
14
|
+
let url = globalThis.routes[routeName];
|
|
15
|
+
if (!url) {
|
|
16
|
+
console.error(`URL '${routeName}' not found in routes.`);
|
|
17
|
+
return null; // Return null to indicate failure
|
|
18
|
+
}
|
|
19
|
+
const argTokens = url.match(/<(\w+:?)?\w+>/g);
|
|
20
|
+
if (!argTokens && args.length > 0) {
|
|
21
|
+
console.error(`Invalid URL lookup: URL '${routeName}' does not expect arguments.`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (typeof args[0] === "object" && !Array.isArray(args[0])) {
|
|
26
|
+
argTokens?.forEach((token) => {
|
|
27
|
+
let argName = token.slice(1, -1);
|
|
28
|
+
if (argName.includes(":")) {
|
|
29
|
+
argName = argName.split(":")[1];
|
|
30
|
+
}
|
|
31
|
+
const argValue = args[0][argName];
|
|
32
|
+
if (argValue === undefined) {
|
|
33
|
+
throw new Error(`Invalid URL lookup: Argument '${argName}' was not provided.`);
|
|
34
|
+
}
|
|
35
|
+
url = url.replace(token, argValue.toString());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const argsArray = Array.isArray(args[0])
|
|
40
|
+
? args[0]
|
|
41
|
+
: Array.prototype.slice.call(args);
|
|
42
|
+
if (argTokens && argTokens.length !== argsArray.length) {
|
|
43
|
+
throw new Error(`Invalid URL lookup: Wrong number of arguments; expected ${argTokens.length.toString()} arguments.`);
|
|
44
|
+
}
|
|
45
|
+
argTokens?.forEach((token, i) => {
|
|
46
|
+
const argValue = argsArray[i];
|
|
47
|
+
url = url.replace(token, argValue.toString());
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error(error.message);
|
|
53
|
+
return null; // Return null to indicate failure
|
|
54
|
+
}
|
|
55
|
+
return url;
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litestar-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type":"module",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"description": "Litestar plugin for Vite.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"litestar",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"homepage": "https://github.com/litestar-org/vite-plugin",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/litestar-org/vite-plugin"
|
|
14
|
+
"url": "git+https://github.com/litestar-org/vite-plugin.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Litestar",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"/dist",
|
|
31
31
|
"/inertia-helpers"
|
|
32
|
-
],
|
|
32
|
+
],
|
|
33
|
+
"bin": {
|
|
33
34
|
"clean-orphaned-assets": "bin/clean.js"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|