@torpor/build 0.0.4 → 0.0.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.
- package/CHANGELOG.md +10 -0
- package/package.json +3 -3
- package/src/bin/index.ts +1 -1
- package/src/index.ts +15 -7
- package/src/site/clientEntry.ts +4 -3
- package/src/site/defineConfig.ts +1 -1
- package/src/site/routeHandlers.ts +22 -11
- package/src/site/serverEntry.ts +15 -14
- package/src/types/CookieHelper.ts +2 -1
- package/src/types/PageEndPoint.ts +3 -2
- package/src/types/PageEvent.ts +2 -1
- package/src/types/PageServerAction.ts +4 -0
- package/src/types/PageServerEndPoint.ts +6 -7
- package/src/types/PageServerLoad.ts +4 -0
- package/src/types/RouteHandler.ts +3 -2
- package/src/types/RouteHandlerCollection.ts +4 -3
- package/src/types/RouteLayoutHandler.ts +2 -1
- package/src/types/RouteMatchResult.ts +3 -2
- package/src/types/ServerEndPoint.ts +9 -10
- package/src/types/ServerEvent.ts +3 -2
- package/src/types/ServerHook.ts +3 -2
- package/src/types/ServerRequest.ts +4 -0
- package/src/types/UserConfig.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @torpor/build
|
|
2
2
|
|
|
3
|
+
## 0.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 79da6cf: Refactor: export more types
|
|
8
|
+
- 3707fdb: Fix: better ordering of routes
|
|
9
|
+
- Updated dependencies [808da4c]
|
|
10
|
+
- @torpor/view@0.0.6
|
|
11
|
+
- @torpor/unplugin@0.0.5
|
|
12
|
+
|
|
3
13
|
## 0.0.4
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A framework for building sites and apps with Torpor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"license": "ISC",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"vinxi": "^0.5.3",
|
|
37
|
-
"@torpor/
|
|
38
|
-
"@torpor/
|
|
37
|
+
"@torpor/unplugin": "^0.0.5",
|
|
38
|
+
"@torpor/view": "^0.0.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
package/src/bin/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import defineConfig from "../site/defineConfig";
|
|
6
|
-
import
|
|
6
|
+
import type UserConfig from "../types/UserConfig";
|
|
7
7
|
|
|
8
8
|
// Check for a torpor.config.js/ts file in the working directory
|
|
9
9
|
// TODO: Make sure it's valid, try/catch, etc
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import buildRoutePath from "./site/buildRoutePath";
|
|
2
2
|
import defineConfig from "./site/defineConfig";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
3
|
+
import type CookieHelper from "./types/CookieHelper";
|
|
4
|
+
import type PageEndPoint from "./types/PageEndPoint";
|
|
5
|
+
import type PageEvent from "./types/PageEvent";
|
|
6
|
+
import type PageServerAction from "./types/PageServerAction";
|
|
7
|
+
import type PageServerEndPoint from "./types/PageServerEndPoint";
|
|
8
|
+
import type PageServerLoad from "./types/PageServerLoad";
|
|
9
|
+
import type ServerEndPoint from "./types/ServerEndPoint";
|
|
10
|
+
import type ServerEvent from "./types/ServerEvent";
|
|
11
|
+
import type ServerHook from "./types/ServerHook";
|
|
12
|
+
import type ServerRequest from "./types/ServerRequest";
|
|
13
|
+
import type UserConfig from "./types/UserConfig";
|
|
10
14
|
|
|
11
15
|
// NOTE: Do not export anything that relies on vinxi/vite from here, or it will
|
|
12
16
|
// cause problems when they are re-imported when routes are lazily loaded
|
|
@@ -17,8 +21,12 @@ export type {
|
|
|
17
21
|
UserConfig,
|
|
18
22
|
PageEndPoint,
|
|
19
23
|
PageServerEndPoint,
|
|
24
|
+
PageServerLoad,
|
|
25
|
+
PageServerAction,
|
|
20
26
|
ServerEndPoint,
|
|
27
|
+
ServerRequest,
|
|
21
28
|
ServerHook,
|
|
22
29
|
PageEvent,
|
|
23
30
|
ServerEvent,
|
|
31
|
+
CookieHelper,
|
|
24
32
|
};
|
package/src/site/clientEntry.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { hydrate, mount } from "@torpor/view";
|
|
|
2
2
|
import { type Component, type SlotRender } from "@torpor/view";
|
|
3
3
|
import "vinxi/client";
|
|
4
4
|
import $page from "../state/$page";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import type PageEndPoint from "../types/PageEndPoint";
|
|
6
|
+
import type PageServerEndPoint from "../types/PageServerEndPoint";
|
|
7
7
|
import routeHandlers from "./routeHandlers";
|
|
8
8
|
|
|
9
9
|
// Intercept clicks on links
|
|
@@ -43,7 +43,7 @@ async function navigate(
|
|
|
43
43
|
urlParams: URLSearchParams,
|
|
44
44
|
firstTime = false,
|
|
45
45
|
): Promise<boolean> {
|
|
46
|
-
console.log("navigating client to", path,
|
|
46
|
+
console.log("navigating client to", path, urlParams.size ? `with ${urlParams}` : "");
|
|
47
47
|
|
|
48
48
|
const parent = document.getElementById("app");
|
|
49
49
|
if (!parent) {
|
|
@@ -146,6 +146,7 @@ async function navigate(
|
|
|
146
146
|
} catch (error) {
|
|
147
147
|
// TODO: Show a proper Error component
|
|
148
148
|
parent.innerHTML = '<span style="color: red">Script syntax error</span><p>' + error + "</p>";
|
|
149
|
+
console.log(error);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
package/src/site/defineConfig.ts
CHANGED
|
@@ -2,7 +2,7 @@ import torpor from "@torpor/unplugin/vite";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { type AppOptions, type RouterSchemaInput, createApp } from "vinxi";
|
|
4
4
|
import { config } from "vinxi/plugins/config";
|
|
5
|
-
import
|
|
5
|
+
import type UserConfig from "../types/UserConfig";
|
|
6
6
|
import FileSystemRouter from "./FileSystemRouter";
|
|
7
7
|
|
|
8
8
|
export default function defineConfig(options?: UserConfig) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getManifest } from "vinxi/manifest";
|
|
2
2
|
import fileRoutes, { type RouteModule } from "vinxi/routes";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import type RouteHandler from "../types/RouteHandler";
|
|
4
|
+
import type RouteHandlerCollection from "../types/RouteHandlerCollection";
|
|
5
|
+
import type RouteLayoutHandler from "../types/RouteLayoutHandler";
|
|
6
6
|
import lazyRoute from "./lazyRoute";
|
|
7
7
|
|
|
8
8
|
const clientManifest = getManifest("client");
|
|
@@ -16,20 +16,34 @@ const routeHandlers: RouteHandlerCollection = {
|
|
|
16
16
|
return {
|
|
17
17
|
...route,
|
|
18
18
|
regex: pathToRegExp(route.path),
|
|
19
|
-
order: /\[([^\/]+?)\]/.test(route.path) ? 1 : 0,
|
|
20
19
|
// TODO: Implement the rest of the lazyRoute stuff from vinxi/react or vinxi/solid
|
|
21
20
|
endPoint: lazyRoute(route.$handler, clientManifest, serverManifest),
|
|
22
21
|
loaded: false,
|
|
23
22
|
};
|
|
24
23
|
})
|
|
25
|
-
.sort((a, b) =>
|
|
24
|
+
.sort((a, b) => {
|
|
25
|
+
// Sort [param]s after paths
|
|
26
|
+
// There might be a quicker/easier way to do this
|
|
27
|
+
for (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {
|
|
28
|
+
if (a.path[i] === "[" && b.path[i] !== "[") {
|
|
29
|
+
return 1;
|
|
30
|
+
} else if (b.path[i] === "[" && a.path[i] !== "[") {
|
|
31
|
+
return -1;
|
|
32
|
+
} else if (a.path[i] === b.path[i]) {
|
|
33
|
+
// Keep going...
|
|
34
|
+
} else {
|
|
35
|
+
return a.path[i].localeCompare(b.path[i]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return a.path.length - b.path.length;
|
|
39
|
+
}),
|
|
26
40
|
match(path, urlParams) {
|
|
27
|
-
console.log("matching", path);
|
|
28
|
-
|
|
29
41
|
// TODO: Lots of testing etc
|
|
30
42
|
for (let handler of (this as RouteHandlerCollection).handlers) {
|
|
31
43
|
let match = path.match(handler.regex);
|
|
32
44
|
if (match) {
|
|
45
|
+
console.log(`matching ${path}, found ${handler.path}`);
|
|
46
|
+
|
|
33
47
|
// Lazy load server endpoints and layouts
|
|
34
48
|
// Partly because it makes sense to do it here, but also because
|
|
35
49
|
// it doesn't work if we try to do it upfront for some reason
|
|
@@ -45,10 +59,7 @@ const routeHandlers: RouteHandlerCollection = {
|
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
console.log(
|
|
49
|
-
//for (let handler of (this as RouteHandlerCollection).handlers) {
|
|
50
|
-
// console.log(" have", handler.path, handler.regex);
|
|
51
|
-
//}
|
|
62
|
+
console.log(`matching ${path}, not found`);
|
|
52
63
|
},
|
|
53
64
|
};
|
|
54
65
|
|
package/src/site/serverEntry.ts
CHANGED
|
@@ -10,12 +10,12 @@ import ok from "../response/ok";
|
|
|
10
10
|
import seeOther from "../response/seeOther";
|
|
11
11
|
import serverError from "../response/serverError";
|
|
12
12
|
import $page from "../state/$page";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
13
|
+
import type PageEndPoint from "../types/PageEndPoint";
|
|
14
|
+
import type PageServerEndPoint from "../types/PageServerEndPoint";
|
|
15
|
+
import type RouteHandler from "../types/RouteHandler";
|
|
16
|
+
import type ServerEndPoint from "../types/ServerEndPoint";
|
|
17
|
+
import type ServerEvent from "../types/ServerEvent";
|
|
18
|
+
import type ServerHook from "../types/ServerHook";
|
|
19
19
|
import routeHandlers from "./routeHandlers";
|
|
20
20
|
|
|
21
21
|
let printedRoutes = false;
|
|
@@ -26,17 +26,17 @@ export default eventHandler(async (event) => {
|
|
|
26
26
|
|
|
27
27
|
const searchParams = url.searchParams;
|
|
28
28
|
|
|
29
|
-
console.log(
|
|
29
|
+
console.log(
|
|
30
|
+
"handling server",
|
|
31
|
+
event.method,
|
|
32
|
+
"for",
|
|
33
|
+
path,
|
|
34
|
+
searchParams.size ? `with ${searchParams}` : "",
|
|
35
|
+
);
|
|
30
36
|
|
|
31
37
|
if (!printedRoutes) {
|
|
32
38
|
printedRoutes = true;
|
|
33
|
-
console.log(
|
|
34
|
-
"routes:\n " +
|
|
35
|
-
routeHandlers.handlers
|
|
36
|
-
.map((h) => h.path)
|
|
37
|
-
.sort()
|
|
38
|
-
.join("\n "),
|
|
39
|
-
);
|
|
39
|
+
console.log("routes:\n " + routeHandlers.handlers.map((h) => h.path).join("\n "));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const route = routeHandlers.match(path, searchParams);
|
|
@@ -235,6 +235,7 @@ async function loadView(
|
|
|
235
235
|
} catch (error) {
|
|
236
236
|
// TODO: Show a proper Error component
|
|
237
237
|
componentCode = '<span style="color: red">Script syntax error</span><p>' + error + "</p>";
|
|
238
|
+
console.log(error);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
// Put it all together
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type CookieSerializeOptions } from "vinxi/http";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type CookieHelper = {
|
|
4
4
|
get: (name: string) => string | undefined;
|
|
5
5
|
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
6
6
|
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
7
7
|
};
|
|
8
|
+
export default CookieHelper;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Component } from "@torpor/view";
|
|
2
|
-
import
|
|
2
|
+
import type PageEvent from "./PageEvent";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* For +page.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type PageEndPoint = {
|
|
8
8
|
/**
|
|
9
9
|
* Builds the route path for the page in a type-safe manner.
|
|
10
10
|
* TODO: Not sure this is actually the best way to do it...
|
|
@@ -24,6 +24,7 @@ export type PageEndPoint = {
|
|
|
24
24
|
*/
|
|
25
25
|
head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
|
|
26
26
|
};
|
|
27
|
+
export default PageEndPoint;
|
|
27
28
|
|
|
28
29
|
type HeadElement = TitleElement | MetaElement;
|
|
29
30
|
|
package/src/types/PageEvent.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type PageServerAction from "./PageServerAction";
|
|
2
|
+
import type PageServerLoad from "./PageServerLoad";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* For +page.server.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
type PageServerEndPoint = {
|
|
7
8
|
/**
|
|
8
9
|
* Loads data from the server for a page.
|
|
9
10
|
*/
|
|
10
|
-
load?:
|
|
11
|
+
load?: PageServerLoad;
|
|
11
12
|
/**
|
|
12
13
|
* A map of actions that can be performed on the server for a page, generally from a form submit.
|
|
13
14
|
*/
|
|
14
|
-
actions?: Record<string,
|
|
15
|
+
actions?: Record<string, PageServerAction>;
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
-
type ServerLoad = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
18
|
-
type ServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
17
|
+
export default PageServerEndPoint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type RouteLayoutHandler from "./RouteLayoutHandler";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type RouteHandler = {
|
|
4
4
|
path: string;
|
|
5
5
|
regex: RegExp;
|
|
6
6
|
endPoint: Promise<any>;
|
|
@@ -10,3 +10,4 @@ export type RouteHandler = {
|
|
|
10
10
|
serverEndPoint?: Promise<any>;
|
|
11
11
|
serverHook?: Promise<any>;
|
|
12
12
|
};
|
|
13
|
+
export default RouteHandler;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type RouteHandler from "./RouteHandler";
|
|
2
|
+
import type RouteMatchResult from "./RouteMatchResult";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type RouteHandlerCollection = {
|
|
5
5
|
handlers: RouteHandler[];
|
|
6
6
|
match(path: string, urlParams?: URLSearchParams): RouteMatchResult | undefined;
|
|
7
7
|
};
|
|
8
|
+
export default RouteHandlerCollection;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type RouteHandler from "./RouteHandler";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type RouteMatchResult = {
|
|
4
4
|
handler: RouteHandler;
|
|
5
5
|
routeParams?: Record<string, string>;
|
|
6
6
|
urlParams?: Record<string, string>;
|
|
7
7
|
};
|
|
8
|
+
export default RouteMatchResult;
|
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type ServerRequest from "./ServerRequest";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* For +server.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
type ServerEndPoint = { [key: string]: ServerRequest } & {
|
|
7
7
|
/**
|
|
8
8
|
* Performs a GET.
|
|
9
9
|
*/
|
|
10
10
|
get?: ServerRequest;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Performs a POST.
|
|
13
13
|
*/
|
|
14
14
|
post?: ServerRequest;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Performs a PATCH.
|
|
17
17
|
*/
|
|
18
18
|
patch?: ServerRequest;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Performs a PUT.
|
|
21
21
|
*/
|
|
22
22
|
put?: ServerRequest;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Performs a DELETE.
|
|
25
25
|
*/
|
|
26
26
|
del?: ServerRequest;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Performs an OPTIONS request.
|
|
29
29
|
*/
|
|
30
30
|
options?: ServerRequest;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Performs a HEAD request.
|
|
33
33
|
*/
|
|
34
34
|
head?: ServerRequest;
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
36
|
+
export default ServerEndPoint;
|
package/src/types/ServerEvent.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerResponse } from "node:http";
|
|
2
|
-
import
|
|
2
|
+
import CookieHelper from "./CookieHelper";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type ServerEvent = {
|
|
5
5
|
/**
|
|
6
6
|
* The URL for the server function.
|
|
7
7
|
*/
|
|
@@ -25,3 +25,4 @@ export type ServerEvent = {
|
|
|
25
25
|
*/
|
|
26
26
|
cookies: CookieHelper;
|
|
27
27
|
};
|
|
28
|
+
export default ServerEvent;
|
package/src/types/ServerHook.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type ServerEvent from "./ServerEvent";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* For _hook.server.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
type ServerHook = {
|
|
7
7
|
/**
|
|
8
8
|
* Called on each server request.
|
|
9
9
|
*/
|
|
10
10
|
handle?: ServerLoad;
|
|
11
11
|
};
|
|
12
|
+
export default ServerHook;
|
|
12
13
|
|
|
13
14
|
type ServerLoad = (event: ServerEvent) => Promise<void> | void;
|
package/src/types/UserConfig.ts
CHANGED