@torpor/build 0.0.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.
- package/LICENSE.md +5 -0
- package/README.md +55 -0
- package/dist/bin/index.cjs +137 -0
- package/dist/bin/index.cjs.map +1 -0
- package/dist/bin/index.d.cts +1 -0
- package/dist/bin/index.d.ts +1 -0
- package/dist/bin/index.js +114 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/response.cjs +150 -0
- package/dist/response.cjs.map +1 -0
- package/dist/response.d.cts +162 -0
- package/dist/response.d.ts +162 -0
- package/dist/response.js +109 -0
- package/dist/response.js.map +1 -0
- package/dist/state.cjs +41 -0
- package/dist/state.cjs.map +1 -0
- package/dist/state.d.cts +6 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +14 -0
- package/dist/state.js.map +1 -0
- package/package.json +49 -0
- package/src/bin/index.ts +41 -0
- package/src/index.ts +24 -0
- package/src/response/badRequest.ts +14 -0
- package/src/response/created.ts +13 -0
- package/src/response/forbidden.ts +14 -0
- package/src/response/methodNotAllowed.ts +14 -0
- package/src/response/moved.ts +16 -0
- package/src/response/notFound.ts +17 -0
- package/src/response/notModified.ts +14 -0
- package/src/response/ok.ts +20 -0
- package/src/response/redirect.ts +17 -0
- package/src/response/response.ts +22 -0
- package/src/response/seeOther.ts +13 -0
- package/src/response/serverError.ts +10 -0
- package/src/response/transfer.ts +14 -0
- package/src/response/unauthorized.ts +12 -0
- package/src/response/unprocessable.ts +12 -0
- package/src/response.ts +33 -0
- package/src/site/FileSystemRouter.ts +24 -0
- package/src/site/buildRoutePath.ts +25 -0
- package/src/site/clientEntry.ts +191 -0
- package/src/site/defineConfig.ts +5 -0
- package/src/site/defineSite.ts +74 -0
- package/src/site/lazyRoute.ts +72 -0
- package/src/site/routeHandlers.ts +113 -0
- package/src/site/serverEntry.ts +384 -0
- package/src/state/$page.ts +11 -0
- package/src/state.ts +3 -0
- package/src/types/CookieHelper.ts +7 -0
- package/src/types/PageEndPoint.ts +37 -0
- package/src/types/PageEvent.ts +14 -0
- package/src/types/PageServerEndPoint.ts +18 -0
- package/src/types/RouteHandler.ts +12 -0
- package/src/types/RouteHandlerCollection.ts +7 -0
- package/src/types/RouteLayoutHandler.ts +5 -0
- package/src/types/RouteMatchResult.ts +7 -0
- package/src/types/ServerEndPoint.ts +37 -0
- package/src/types/ServerEvent.ts +27 -0
- package/src/types/ServerHook.ts +13 -0
- package/src/types/UserConfig.ts +3 -0
- package/tsconfig.json +4 -0
- package/tsup.config.ts +10 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2024 <OWNER>
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# torpor/build
|
|
2
|
+
|
|
3
|
+
A framework for building sites and apps with Torpor.
|
|
4
|
+
|
|
5
|
+
Built on top of [Vinxi](https://github.com/nksaraf/vinxi).
|
|
6
|
+
|
|
7
|
+
🚧 WARNING: WORK IN PROGRESS 🚧
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Use `npm` (or your preferred package manager) to create a Vite project:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm create vite
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Folder structure
|
|
18
|
+
|
|
19
|
+
- /src
|
|
20
|
+
- /assets
|
|
21
|
+
- /components
|
|
22
|
+
- /lib
|
|
23
|
+
- /routes
|
|
24
|
+
- /api
|
|
25
|
+
|
|
26
|
+
## Maybe
|
|
27
|
+
|
|
28
|
+
Ideally, sites built with torpor/build will be easy to get set up and running, with flexible overrides for complex uses.
|
|
29
|
+
|
|
30
|
+
- middleware setup for auth etc
|
|
31
|
+
- file-based routing by default, with programmatic overrides
|
|
32
|
+
- type-safe routing and fetching
|
|
33
|
+
- type-safe websocket communication
|
|
34
|
+
- immediate or scheduled background tasks
|
|
35
|
+
- authentication and authorization
|
|
36
|
+
- localization and internationalization
|
|
37
|
+
- logs and (basic) analytics
|
|
38
|
+
|
|
39
|
+
## Routing
|
|
40
|
+
|
|
41
|
+
TODO:
|
|
42
|
+
|
|
43
|
+
File based routing with overrides.
|
|
44
|
+
|
|
45
|
+
## Layouts
|
|
46
|
+
|
|
47
|
+
TODO:
|
|
48
|
+
|
|
49
|
+
## Middleware
|
|
50
|
+
|
|
51
|
+
TODO:
|
|
52
|
+
|
|
53
|
+
## API versioning
|
|
54
|
+
|
|
55
|
+
TODO:
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/bin/index.ts
|
|
27
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
28
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
29
|
+
|
|
30
|
+
// src/site/defineSite.ts
|
|
31
|
+
var import_vite = __toESM(require("@torpor/unplugin/vite"), 1);
|
|
32
|
+
var import_path = __toESM(require("path"), 1);
|
|
33
|
+
var import_vinxi = require("vinxi");
|
|
34
|
+
var import_config = require("vinxi/plugins/config");
|
|
35
|
+
|
|
36
|
+
// src/site/FileSystemRouter.ts
|
|
37
|
+
var import_fs_router = require("vinxi/fs-router");
|
|
38
|
+
var FileSystemRouter = class extends import_fs_router.BaseFileSystemRouter {
|
|
39
|
+
toPath(src) {
|
|
40
|
+
let routePath = (0, import_fs_router.cleanPath)(src, this.config).replace(/^\//, "").replace(/_layout.server$/, "_layout/~server").replace(/\+page.server$/, "~server").replace(/\+page$/, "").replace(/\+server$/, "").replace(/\/$/, "");
|
|
41
|
+
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
42
|
+
}
|
|
43
|
+
toRoute(filePath) {
|
|
44
|
+
return {
|
|
45
|
+
path: this.toPath(filePath),
|
|
46
|
+
$handler: {
|
|
47
|
+
src: filePath,
|
|
48
|
+
pick: ["default"]
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/site/defineSite.ts
|
|
55
|
+
function defineSite(options2) {
|
|
56
|
+
process.env.PORT = (options2?.port || 7059).toString();
|
|
57
|
+
return (0, import_vinxi.createApp)({
|
|
58
|
+
routers: [
|
|
59
|
+
{
|
|
60
|
+
name: "assets",
|
|
61
|
+
type: "static",
|
|
62
|
+
dir: "./src/assets"
|
|
63
|
+
},
|
|
64
|
+
// Doesn't look like we can have two server routes?
|
|
65
|
+
// Have to put api in /routes
|
|
66
|
+
// Maybe we can support having /routes/api and routes/site and stripping /site from the start?
|
|
67
|
+
//{
|
|
68
|
+
// name: "api",
|
|
69
|
+
// type: "http",
|
|
70
|
+
// target: "server",
|
|
71
|
+
// // TODO: change this when published
|
|
72
|
+
// handler: "node_modules/@torpor/build/src/site/serverEntry.ts",
|
|
73
|
+
// routes: apiRoutes,
|
|
74
|
+
// plugins: () => [config("custom", viteOptions())],
|
|
75
|
+
//},
|
|
76
|
+
{
|
|
77
|
+
name: "server",
|
|
78
|
+
type: "http",
|
|
79
|
+
target: "server",
|
|
80
|
+
// TODO: change this when published
|
|
81
|
+
handler: "node_modules/@torpor/build/src/site/serverEntry.ts",
|
|
82
|
+
routes,
|
|
83
|
+
plugins: () => [(0, import_config.config)("custom", viteOptions()), (0, import_vite.default)({ server: true })]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "client",
|
|
87
|
+
type: "client",
|
|
88
|
+
target: "browser",
|
|
89
|
+
// TODO: change this when published
|
|
90
|
+
handler: "node_modules/@torpor/build/src/site/clientEntry.ts",
|
|
91
|
+
base: "/_build",
|
|
92
|
+
routes,
|
|
93
|
+
plugins: () => [(0, import_config.config)("custom", viteOptions()), (0, import_vite.default)()]
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function routes(router, app2) {
|
|
99
|
+
return new FileSystemRouter(
|
|
100
|
+
{
|
|
101
|
+
dir: import_path.default.resolve("src/routes"),
|
|
102
|
+
extensions: ["js", "ts"]
|
|
103
|
+
},
|
|
104
|
+
router,
|
|
105
|
+
app2
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
function viteOptions() {
|
|
109
|
+
return {
|
|
110
|
+
resolve: {
|
|
111
|
+
alias: {
|
|
112
|
+
"@": import_path.default.resolve("src")
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/bin/index.ts
|
|
119
|
+
var options;
|
|
120
|
+
var workingDir = process.cwd();
|
|
121
|
+
var jsConfigFile = import_path2.default.join(workingDir, "torpor.config.js");
|
|
122
|
+
var tsConfigFile = import_path2.default.join(workingDir, "torpor.config.ts");
|
|
123
|
+
var source;
|
|
124
|
+
if (import_node_fs.default.existsSync(jsConfigFile)) {
|
|
125
|
+
source = import_node_fs.default.readFileSync(jsConfigFile, "utf8");
|
|
126
|
+
source = source.replace(
|
|
127
|
+
/import\s+\{\s+defineConfig\s+\}\s+from\s+["']@torpor\/build["']/,
|
|
128
|
+
"const defineConfig = (x) => x"
|
|
129
|
+
).replace("export default", "");
|
|
130
|
+
} else if (import_node_fs.default.existsSync(tsConfigFile)) {
|
|
131
|
+
console.log("TS config file is not supported");
|
|
132
|
+
}
|
|
133
|
+
if (source) {
|
|
134
|
+
options = eval(source);
|
|
135
|
+
}
|
|
136
|
+
var app = defineSite(options);
|
|
137
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.ts","../../src/site/defineSite.ts","../../src/site/FileSystemRouter.ts"],"sourcesContent":["#! /usr/bin/env node\n//import { existsSync, promises as fs } from \"node:fs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport defineSite from \"../site/defineSite\";\nimport type UserConfig from \"../types/UserConfig\";\n\n// Check for a torpor.config.js/ts file in the working directory\n// TODO: Make sure it's valid, try/catch, etc\n// TODO: There has GOT to be an easier way\nlet options: UserConfig | undefined;\nconst workingDir = process.cwd();\nconst jsConfigFile = path.join(workingDir, \"torpor.config.js\");\nconst tsConfigFile = path.join(workingDir, \"torpor.config.ts\");\nlet source: string | undefined;\nif (fs.existsSync(jsConfigFile)) {\n\t//const configFile = path.relative(\".\", tsConfigFile);\n\t//options = await import(configFile);\n\tsource = fs.readFileSync(jsConfigFile, \"utf8\");\n\tsource = source\n\t\t.replace(\n\t\t\t/import\\s+\\{\\s+defineConfig\\s+\\}\\s+from\\s+[\"']@torpor\\/build[\"']/,\n\t\t\t\"const defineConfig = (x) => x\",\n\t\t)\n\t\t.replace(\"export default\", \"\");\n} else if (fs.existsSync(tsConfigFile)) {\n\tconsole.log(\"TS config file is not supported\");\n}\n\nif (source) {\n\toptions = eval(source);\n}\n\nconst app = defineSite(options);\n\n// This already gets done in vinxi.createApp so we can't do it twice\n//if (process.argv.includes(\"--dev\")) {\n//\tawait app.dev();\n//} else if (process.argv.includes(\"--build\")) {\n//\tawait app.build();\n//}\n","import torpor from \"@torpor/unplugin/vite\";\nimport path from \"path\";\nimport { AppOptions, RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineSite(options?: UserConfig) {\n\t// Set the port\n\tprocess.env.PORT = (options?.port || 7059).toString();\n\n\t// Get Vinxi to create and serve the app\n\treturn createApp({\n\t\trouters: [\n\t\t\t{\n\t\t\t\tname: \"assets\",\n\t\t\t\ttype: \"static\",\n\t\t\t\tdir: \"./src/assets\",\n\t\t\t},\n\t\t\t// Doesn't look like we can have two server routes?\n\t\t\t// Have to put api in /routes\n\t\t\t// Maybe we can support having /routes/api and routes/site and stripping /site from the start?\n\t\t\t//{\n\t\t\t//\tname: \"api\",\n\t\t\t//\ttype: \"http\",\n\t\t\t//\ttarget: \"server\",\n\t\t\t//\t// TODO: change this when published\n\t\t\t//\thandler: \"node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t//\troutes: apiRoutes,\n\t\t\t//\tplugins: () => [config(\"custom\", viteOptions())],\n\t\t\t//},\n\t\t\t{\n\t\t\t\tname: \"server\",\n\t\t\t\ttype: \"http\",\n\t\t\t\ttarget: \"server\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor({ server: true })],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"client\",\n\t\t\t\ttype: \"client\",\n\t\t\t\ttarget: \"browser\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"node_modules/@torpor/build/src/site/clientEntry.ts\",\n\t\t\t\tbase: \"/_build\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor()],\n\t\t\t},\n\t\t],\n\t});\n}\n\nfunction routes(router: RouterSchemaInput, app: AppOptions) {\n\treturn new FileSystemRouter(\n\t\t{\n\t\t\tdir: path.resolve(\"src/routes\"),\n\t\t\textensions: [\"js\", \"ts\"],\n\t\t},\n\t\trouter,\n\t\tapp,\n\t);\n}\n\nfunction viteOptions() {\n\treturn {\n\t\tresolve: {\n\t\t\talias: {\n\t\t\t\t\"@\": path.resolve(\"src\"),\n\t\t\t},\n\t\t},\n\t};\n}\n","import { BaseFileSystemRouter, cleanPath } from \"vinxi/fs-router\";\n\nexport default class FileSystemRouter extends BaseFileSystemRouter {\n\ttoPath(src: string) {\n\t\tlet routePath = cleanPath(src, this.config)\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath?.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\ttoRoute(filePath: string) {\n\t\treturn {\n\t\t\tpath: this.toPath(filePath),\n\t\t\t$handler: {\n\t\t\t\tsrc: filePath,\n\t\t\t\tpick: [\"default\"],\n\t\t\t},\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qBAAe;AACf,IAAAA,eAAiB;;;ACHjB,kBAAmB;AACnB,kBAAiB;AACjB,mBAAyD;AACzD,oBAAuB;;;ACHvB,uBAAgD;AAEhD,IAAqB,mBAArB,cAA8C,sCAAqB;AAAA,EAClE,OAAO,KAAa;AACnB,QAAI,gBAAY,4BAAU,KAAK,KAAK,MAAM,EACxC,QAAQ,OAAO,EAAE,EACjB,QAAQ,mBAAmB,iBAAiB,EAC5C,QAAQ,kBAAkB,SAAS,EACnC,QAAQ,WAAW,EAAE,EACrB,QAAQ,aAAa,EAAE,EACvB,QAAQ,OAAO,EAAE;AACnB,WAAO,WAAW,SAAS,IAAI,IAAI,SAAS,KAAK;AAAA,EAClD;AAAA,EAEA,QAAQ,UAAkB;AACzB,WAAO;AAAA,MACN,MAAM,KAAK,OAAO,QAAQ;AAAA,MAC1B,UAAU;AAAA,QACT,KAAK;AAAA,QACL,MAAM,CAAC,SAAS;AAAA,MACjB;AAAA,IACD;AAAA,EACD;AACD;;;ADhBe,SAAR,WAA4BC,UAAsB;AAExD,UAAQ,IAAI,QAAQA,UAAS,QAAQ,MAAM,SAAS;AAGpD,aAAO,wBAAU;AAAA,IAChB,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,KAAK;AAAA,MACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAaA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT;AAAA,QACA,SAAS,MAAM,KAAC,sBAAO,UAAU,YAAY,CAAC,OAAG,YAAAC,SAAO,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,MAC1E;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT,MAAM;AAAA,QACN;AAAA,QACA,SAAS,MAAM,KAAC,sBAAO,UAAU,YAAY,CAAC,OAAG,YAAAA,SAAO,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEA,SAAS,OAAO,QAA2BC,MAAiB;AAC3D,SAAO,IAAI;AAAA,IACV;AAAA,MACC,KAAK,YAAAC,QAAK,QAAQ,YAAY;AAAA,MAC9B,YAAY,CAAC,MAAM,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,IACAD;AAAA,EACD;AACD;AAEA,SAAS,cAAc;AACtB,SAAO;AAAA,IACN,SAAS;AAAA,MACR,OAAO;AAAA,QACN,KAAK,YAAAC,QAAK,QAAQ,KAAK;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;;;AD/DA,IAAI;AACJ,IAAM,aAAa,QAAQ,IAAI;AAC/B,IAAM,eAAe,aAAAC,QAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAM,eAAe,aAAAA,QAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAI;AACJ,IAAI,eAAAC,QAAG,WAAW,YAAY,GAAG;AAGhC,WAAS,eAAAA,QAAG,aAAa,cAAc,MAAM;AAC7C,WAAS,OACP;AAAA,IACA;AAAA,IACA;AAAA,EACD,EACC,QAAQ,kBAAkB,EAAE;AAC/B,WAAW,eAAAA,QAAG,WAAW,YAAY,GAAG;AACvC,UAAQ,IAAI,iCAAiC;AAC9C;AAEA,IAAI,QAAQ;AACX,YAAU,KAAK,MAAM;AACtB;AAEA,IAAM,MAAM,WAAW,OAAO;","names":["import_path","options","torpor","app","path","path","fs"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin/index.ts
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path2 from "path";
|
|
6
|
+
|
|
7
|
+
// src/site/defineSite.ts
|
|
8
|
+
import torpor from "@torpor/unplugin/vite";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { createApp } from "vinxi";
|
|
11
|
+
import { config } from "vinxi/plugins/config";
|
|
12
|
+
|
|
13
|
+
// src/site/FileSystemRouter.ts
|
|
14
|
+
import { BaseFileSystemRouter, cleanPath } from "vinxi/fs-router";
|
|
15
|
+
var FileSystemRouter = class extends BaseFileSystemRouter {
|
|
16
|
+
toPath(src) {
|
|
17
|
+
let routePath = cleanPath(src, this.config).replace(/^\//, "").replace(/_layout.server$/, "_layout/~server").replace(/\+page.server$/, "~server").replace(/\+page$/, "").replace(/\+server$/, "").replace(/\/$/, "");
|
|
18
|
+
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
19
|
+
}
|
|
20
|
+
toRoute(filePath) {
|
|
21
|
+
return {
|
|
22
|
+
path: this.toPath(filePath),
|
|
23
|
+
$handler: {
|
|
24
|
+
src: filePath,
|
|
25
|
+
pick: ["default"]
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/site/defineSite.ts
|
|
32
|
+
function defineSite(options2) {
|
|
33
|
+
process.env.PORT = (options2?.port || 7059).toString();
|
|
34
|
+
return createApp({
|
|
35
|
+
routers: [
|
|
36
|
+
{
|
|
37
|
+
name: "assets",
|
|
38
|
+
type: "static",
|
|
39
|
+
dir: "./src/assets"
|
|
40
|
+
},
|
|
41
|
+
// Doesn't look like we can have two server routes?
|
|
42
|
+
// Have to put api in /routes
|
|
43
|
+
// Maybe we can support having /routes/api and routes/site and stripping /site from the start?
|
|
44
|
+
//{
|
|
45
|
+
// name: "api",
|
|
46
|
+
// type: "http",
|
|
47
|
+
// target: "server",
|
|
48
|
+
// // TODO: change this when published
|
|
49
|
+
// handler: "node_modules/@torpor/build/src/site/serverEntry.ts",
|
|
50
|
+
// routes: apiRoutes,
|
|
51
|
+
// plugins: () => [config("custom", viteOptions())],
|
|
52
|
+
//},
|
|
53
|
+
{
|
|
54
|
+
name: "server",
|
|
55
|
+
type: "http",
|
|
56
|
+
target: "server",
|
|
57
|
+
// TODO: change this when published
|
|
58
|
+
handler: "node_modules/@torpor/build/src/site/serverEntry.ts",
|
|
59
|
+
routes,
|
|
60
|
+
plugins: () => [config("custom", viteOptions()), torpor({ server: true })]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "client",
|
|
64
|
+
type: "client",
|
|
65
|
+
target: "browser",
|
|
66
|
+
// TODO: change this when published
|
|
67
|
+
handler: "node_modules/@torpor/build/src/site/clientEntry.ts",
|
|
68
|
+
base: "/_build",
|
|
69
|
+
routes,
|
|
70
|
+
plugins: () => [config("custom", viteOptions()), torpor()]
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function routes(router, app2) {
|
|
76
|
+
return new FileSystemRouter(
|
|
77
|
+
{
|
|
78
|
+
dir: path.resolve("src/routes"),
|
|
79
|
+
extensions: ["js", "ts"]
|
|
80
|
+
},
|
|
81
|
+
router,
|
|
82
|
+
app2
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function viteOptions() {
|
|
86
|
+
return {
|
|
87
|
+
resolve: {
|
|
88
|
+
alias: {
|
|
89
|
+
"@": path.resolve("src")
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/bin/index.ts
|
|
96
|
+
var options;
|
|
97
|
+
var workingDir = process.cwd();
|
|
98
|
+
var jsConfigFile = path2.join(workingDir, "torpor.config.js");
|
|
99
|
+
var tsConfigFile = path2.join(workingDir, "torpor.config.ts");
|
|
100
|
+
var source;
|
|
101
|
+
if (fs.existsSync(jsConfigFile)) {
|
|
102
|
+
source = fs.readFileSync(jsConfigFile, "utf8");
|
|
103
|
+
source = source.replace(
|
|
104
|
+
/import\s+\{\s+defineConfig\s+\}\s+from\s+["']@torpor\/build["']/,
|
|
105
|
+
"const defineConfig = (x) => x"
|
|
106
|
+
).replace("export default", "");
|
|
107
|
+
} else if (fs.existsSync(tsConfigFile)) {
|
|
108
|
+
console.log("TS config file is not supported");
|
|
109
|
+
}
|
|
110
|
+
if (source) {
|
|
111
|
+
options = eval(source);
|
|
112
|
+
}
|
|
113
|
+
var app = defineSite(options);
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.ts","../../src/site/defineSite.ts","../../src/site/FileSystemRouter.ts"],"sourcesContent":["#! /usr/bin/env node\n//import { existsSync, promises as fs } from \"node:fs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport defineSite from \"../site/defineSite\";\nimport type UserConfig from \"../types/UserConfig\";\n\n// Check for a torpor.config.js/ts file in the working directory\n// TODO: Make sure it's valid, try/catch, etc\n// TODO: There has GOT to be an easier way\nlet options: UserConfig | undefined;\nconst workingDir = process.cwd();\nconst jsConfigFile = path.join(workingDir, \"torpor.config.js\");\nconst tsConfigFile = path.join(workingDir, \"torpor.config.ts\");\nlet source: string | undefined;\nif (fs.existsSync(jsConfigFile)) {\n\t//const configFile = path.relative(\".\", tsConfigFile);\n\t//options = await import(configFile);\n\tsource = fs.readFileSync(jsConfigFile, \"utf8\");\n\tsource = source\n\t\t.replace(\n\t\t\t/import\\s+\\{\\s+defineConfig\\s+\\}\\s+from\\s+[\"']@torpor\\/build[\"']/,\n\t\t\t\"const defineConfig = (x) => x\",\n\t\t)\n\t\t.replace(\"export default\", \"\");\n} else if (fs.existsSync(tsConfigFile)) {\n\tconsole.log(\"TS config file is not supported\");\n}\n\nif (source) {\n\toptions = eval(source);\n}\n\nconst app = defineSite(options);\n\n// This already gets done in vinxi.createApp so we can't do it twice\n//if (process.argv.includes(\"--dev\")) {\n//\tawait app.dev();\n//} else if (process.argv.includes(\"--build\")) {\n//\tawait app.build();\n//}\n","import torpor from \"@torpor/unplugin/vite\";\nimport path from \"path\";\nimport { AppOptions, RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineSite(options?: UserConfig) {\n\t// Set the port\n\tprocess.env.PORT = (options?.port || 7059).toString();\n\n\t// Get Vinxi to create and serve the app\n\treturn createApp({\n\t\trouters: [\n\t\t\t{\n\t\t\t\tname: \"assets\",\n\t\t\t\ttype: \"static\",\n\t\t\t\tdir: \"./src/assets\",\n\t\t\t},\n\t\t\t// Doesn't look like we can have two server routes?\n\t\t\t// Have to put api in /routes\n\t\t\t// Maybe we can support having /routes/api and routes/site and stripping /site from the start?\n\t\t\t//{\n\t\t\t//\tname: \"api\",\n\t\t\t//\ttype: \"http\",\n\t\t\t//\ttarget: \"server\",\n\t\t\t//\t// TODO: change this when published\n\t\t\t//\thandler: \"node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t//\troutes: apiRoutes,\n\t\t\t//\tplugins: () => [config(\"custom\", viteOptions())],\n\t\t\t//},\n\t\t\t{\n\t\t\t\tname: \"server\",\n\t\t\t\ttype: \"http\",\n\t\t\t\ttarget: \"server\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor({ server: true })],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"client\",\n\t\t\t\ttype: \"client\",\n\t\t\t\ttarget: \"browser\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"node_modules/@torpor/build/src/site/clientEntry.ts\",\n\t\t\t\tbase: \"/_build\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor()],\n\t\t\t},\n\t\t],\n\t});\n}\n\nfunction routes(router: RouterSchemaInput, app: AppOptions) {\n\treturn new FileSystemRouter(\n\t\t{\n\t\t\tdir: path.resolve(\"src/routes\"),\n\t\t\textensions: [\"js\", \"ts\"],\n\t\t},\n\t\trouter,\n\t\tapp,\n\t);\n}\n\nfunction viteOptions() {\n\treturn {\n\t\tresolve: {\n\t\t\talias: {\n\t\t\t\t\"@\": path.resolve(\"src\"),\n\t\t\t},\n\t\t},\n\t};\n}\n","import { BaseFileSystemRouter, cleanPath } from \"vinxi/fs-router\";\n\nexport default class FileSystemRouter extends BaseFileSystemRouter {\n\ttoPath(src: string) {\n\t\tlet routePath = cleanPath(src, this.config)\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath?.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\ttoRoute(filePath: string) {\n\t\treturn {\n\t\t\tpath: this.toPath(filePath),\n\t\t\t$handler: {\n\t\t\t\tsrc: filePath,\n\t\t\t\tpick: [\"default\"],\n\t\t\t},\n\t\t};\n\t}\n}\n"],"mappings":";;;AAEA,OAAO,QAAQ;AACf,OAAOA,WAAU;;;ACHjB,OAAO,YAAY;AACnB,OAAO,UAAU;AACjB,SAAwC,iBAAiB;AACzD,SAAS,cAAc;;;ACHvB,SAAS,sBAAsB,iBAAiB;AAEhD,IAAqB,mBAArB,cAA8C,qBAAqB;AAAA,EAClE,OAAO,KAAa;AACnB,QAAI,YAAY,UAAU,KAAK,KAAK,MAAM,EACxC,QAAQ,OAAO,EAAE,EACjB,QAAQ,mBAAmB,iBAAiB,EAC5C,QAAQ,kBAAkB,SAAS,EACnC,QAAQ,WAAW,EAAE,EACrB,QAAQ,aAAa,EAAE,EACvB,QAAQ,OAAO,EAAE;AACnB,WAAO,WAAW,SAAS,IAAI,IAAI,SAAS,KAAK;AAAA,EAClD;AAAA,EAEA,QAAQ,UAAkB;AACzB,WAAO;AAAA,MACN,MAAM,KAAK,OAAO,QAAQ;AAAA,MAC1B,UAAU;AAAA,QACT,KAAK;AAAA,QACL,MAAM,CAAC,SAAS;AAAA,MACjB;AAAA,IACD;AAAA,EACD;AACD;;;ADhBe,SAAR,WAA4BC,UAAsB;AAExD,UAAQ,IAAI,QAAQA,UAAS,QAAQ,MAAM,SAAS;AAGpD,SAAO,UAAU;AAAA,IAChB,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,KAAK;AAAA,MACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAaA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT;AAAA,QACA,SAAS,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,GAAG,OAAO,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,MAC1E;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT,MAAM;AAAA,QACN;AAAA,QACA,SAAS,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,GAAG,OAAO,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEA,SAAS,OAAO,QAA2BC,MAAiB;AAC3D,SAAO,IAAI;AAAA,IACV;AAAA,MACC,KAAK,KAAK,QAAQ,YAAY;AAAA,MAC9B,YAAY,CAAC,MAAM,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,IACAA;AAAA,EACD;AACD;AAEA,SAAS,cAAc;AACtB,SAAO;AAAA,IACN,SAAS;AAAA,MACR,OAAO;AAAA,QACN,KAAK,KAAK,QAAQ,KAAK;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;;;AD/DA,IAAI;AACJ,IAAM,aAAa,QAAQ,IAAI;AAC/B,IAAM,eAAeC,MAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAM,eAAeA,MAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAI;AACJ,IAAI,GAAG,WAAW,YAAY,GAAG;AAGhC,WAAS,GAAG,aAAa,cAAc,MAAM;AAC7C,WAAS,OACP;AAAA,IACA;AAAA,IACA;AAAA,EACD,EACC,QAAQ,kBAAkB,EAAE;AAC/B,WAAW,GAAG,WAAW,YAAY,GAAG;AACvC,UAAQ,IAAI,iCAAiC;AAC9C;AAEA,IAAI,QAAQ;AACX,YAAU,KAAK,MAAM;AACtB;AAEA,IAAM,MAAM,WAAW,OAAO;","names":["path","options","app","path"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
buildRoutePath: () => buildRoutePath,
|
|
24
|
+
defineConfig: () => defineConfig
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/site/buildRoutePath.ts
|
|
29
|
+
function buildRoutePath(path, routeParams, urlParams) {
|
|
30
|
+
for (let [key, value] of Object.entries(routeParams)) {
|
|
31
|
+
path = path.replace(`[${key}]`, value);
|
|
32
|
+
}
|
|
33
|
+
if (urlParams) {
|
|
34
|
+
let params = Object.entries(urlParams).map(([key, value]) => {
|
|
35
|
+
if (value != null) {
|
|
36
|
+
return `${key}=${value}`;
|
|
37
|
+
}
|
|
38
|
+
}).filter(Boolean);
|
|
39
|
+
if (params.length) {
|
|
40
|
+
path += `?${params.join("&")}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/site/defineConfig.ts
|
|
47
|
+
function defineConfig(config) {
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
buildRoutePath,
|
|
53
|
+
defineConfig
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/site/buildRoutePath.ts","../src/site/defineConfig.ts"],"sourcesContent":["import buildRoutePath from \"./site/buildRoutePath\";\nimport defineConfig from \"./site/defineConfig\";\nimport type PageEndPoint from \"./types/PageEndPoint\";\nimport type PageEvent from \"./types/PageEvent\";\nimport type PageServerEndPoint from \"./types/PageServerEndPoint\";\nimport type ServerEndPoint from \"./types/ServerEndPoint\";\nimport type ServerEvent from \"./types/ServerEvent\";\nimport type ServerHook from \"./types/ServerHook\";\nimport type UserConfig from \"./types/UserConfig\";\n\n// NOTE: Do not export anything that relies on vinxi/vite from here, or it will\n// cause problems when they are re-imported when routes are lazily loaded\n\nexport { defineConfig, buildRoutePath };\n\nexport type {\n\tUserConfig,\n\tPageEndPoint,\n\tPageServerEndPoint,\n\tServerEndPoint,\n\tServerHook,\n\tPageEvent,\n\tServerEvent,\n};\n","type ParamsType = Record<PropertyKey, any>;\n\nexport default function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(\n\tpath: string,\n\trouteParams: RP,\n\turlParams?: UP,\n) {\n\tfor (let [key, value] of Object.entries(routeParams)) {\n\t\tpath = path.replace(`[${key}]`, value);\n\t}\n\tif (urlParams) {\n\t\t// TODO: More sophisticated url params serialization\n\t\tlet params = Object.entries(urlParams)\n\t\t\t.map(([key, value]) => {\n\t\t\t\tif (value != null) {\n\t\t\t\t\treturn `${key}=${value}`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter(Boolean);\n\t\tif (params.length) {\n\t\t\tpath += `?${params.join(\"&\")}`;\n\t\t}\n\t}\n\treturn path;\n}\n","import type UserConfig from \"../types/UserConfig\";\n\nexport default function defineConfig(config: UserConfig): UserConfig {\n\treturn config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEe,SAAR,eACN,MACA,aACA,WACC;AACD,WAAS,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACrD,WAAO,KAAK,QAAQ,IAAI,GAAG,KAAK,KAAK;AAAA,EACtC;AACA,MAAI,WAAW;AAEd,QAAI,SAAS,OAAO,QAAQ,SAAS,EACnC,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACtB,UAAI,SAAS,MAAM;AAClB,eAAO,GAAG,GAAG,IAAI,KAAK;AAAA,MACvB;AAAA,IACD,CAAC,EACA,OAAO,OAAO;AAChB,QAAI,OAAO,QAAQ;AAClB,cAAQ,IAAI,OAAO,KAAK,GAAG,CAAC;AAAA,IAC7B;AAAA,EACD;AACA,SAAO;AACR;;;ACtBe,SAAR,aAA8B,QAAgC;AACpE,SAAO;AACR;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Component } from '@torpor/view';
|
|
2
|
+
import { ServerResponse } from 'node:http';
|
|
3
|
+
import { CookieSerializeOptions } from 'vinxi/http';
|
|
4
|
+
|
|
5
|
+
type ParamsType = Record<PropertyKey, any>;
|
|
6
|
+
declare function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(path: string, routeParams: RP, urlParams?: UP): string;
|
|
7
|
+
|
|
8
|
+
interface UserConfig {
|
|
9
|
+
port?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare function defineConfig(config: UserConfig): UserConfig;
|
|
13
|
+
|
|
14
|
+
interface PageEvent {
|
|
15
|
+
/**
|
|
16
|
+
* The URL for the server function.
|
|
17
|
+
*/
|
|
18
|
+
url: URL;
|
|
19
|
+
/**
|
|
20
|
+
* Route params from the URL and route path.
|
|
21
|
+
*/
|
|
22
|
+
params: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Data that is (optionally) loaded from the load function and passed into the page as $props.data.
|
|
25
|
+
*/
|
|
26
|
+
data: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* For +page.
|
|
31
|
+
*/
|
|
32
|
+
interface PageEndPoint {
|
|
33
|
+
/**
|
|
34
|
+
* Builds the route path for the page in a type-safe manner.
|
|
35
|
+
* TODO: Not sure this is actually the best way to do it...
|
|
36
|
+
*/
|
|
37
|
+
route?: (...args: any[]) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Loads data for the page.
|
|
40
|
+
*/
|
|
41
|
+
load?: (event: PageEvent) => any;
|
|
42
|
+
/**
|
|
43
|
+
* The component that is displayed for the page.
|
|
44
|
+
*/
|
|
45
|
+
component?: Component;
|
|
46
|
+
/**
|
|
47
|
+
* The head element data for the page, which may include a <title> and <meta> elements.
|
|
48
|
+
*/
|
|
49
|
+
head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
|
|
50
|
+
}
|
|
51
|
+
type HeadElement = TitleElement | MetaElement;
|
|
52
|
+
interface TitleElement {
|
|
53
|
+
title: string;
|
|
54
|
+
}
|
|
55
|
+
interface MetaElement {
|
|
56
|
+
name: string;
|
|
57
|
+
content: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface CookieHelper {
|
|
61
|
+
get: (name: string) => string | undefined;
|
|
62
|
+
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
63
|
+
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface ServerEvent {
|
|
67
|
+
/**
|
|
68
|
+
* The URL for the server function.
|
|
69
|
+
*/
|
|
70
|
+
url: URL;
|
|
71
|
+
/**
|
|
72
|
+
* Route params from the URL and route path.
|
|
73
|
+
*/
|
|
74
|
+
params: Record<string, string>;
|
|
75
|
+
/**
|
|
76
|
+
* Data that is available to functions in +server hooks, layouts, endpoints
|
|
77
|
+
* and pages. It flows down in that order.
|
|
78
|
+
*/
|
|
79
|
+
appData: Record<string, any>;
|
|
80
|
+
request: Request;
|
|
81
|
+
response: ServerResponse;
|
|
82
|
+
/**
|
|
83
|
+
* A helper for getting and setting cookie data.
|
|
84
|
+
*/
|
|
85
|
+
cookies: CookieHelper;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* For +page.server.
|
|
90
|
+
*/
|
|
91
|
+
interface PageServerEndPoint {
|
|
92
|
+
/**
|
|
93
|
+
* Loads data from the server for a page.
|
|
94
|
+
*/
|
|
95
|
+
load?: ServerLoad$1;
|
|
96
|
+
/**
|
|
97
|
+
* A map of actions that can be performed on the server for a page, generally from a form submit.
|
|
98
|
+
*/
|
|
99
|
+
actions?: Record<string, ServerAction>;
|
|
100
|
+
}
|
|
101
|
+
type ServerLoad$1 = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
102
|
+
type ServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* For +server.
|
|
106
|
+
*/
|
|
107
|
+
interface ServerEndPoint {
|
|
108
|
+
/**
|
|
109
|
+
* Performs a GET.
|
|
110
|
+
*/
|
|
111
|
+
get?: ServerRequest;
|
|
112
|
+
/**
|
|
113
|
+
* Perfroms a POST.
|
|
114
|
+
*/
|
|
115
|
+
post?: ServerRequest;
|
|
116
|
+
/**
|
|
117
|
+
* Perfroms a PATCH.
|
|
118
|
+
*/
|
|
119
|
+
patch?: ServerRequest;
|
|
120
|
+
/**
|
|
121
|
+
* Perfroms a PUT.
|
|
122
|
+
*/
|
|
123
|
+
put?: ServerRequest;
|
|
124
|
+
/**
|
|
125
|
+
* Perfroms a DELETE.
|
|
126
|
+
*/
|
|
127
|
+
del?: ServerRequest;
|
|
128
|
+
/**
|
|
129
|
+
* Perfroms an OPTIONS request.
|
|
130
|
+
*/
|
|
131
|
+
options?: ServerRequest;
|
|
132
|
+
/**
|
|
133
|
+
* Perfroms a HEAD request.
|
|
134
|
+
*/
|
|
135
|
+
head?: ServerRequest;
|
|
136
|
+
}
|
|
137
|
+
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* For _hook.server.
|
|
141
|
+
*/
|
|
142
|
+
interface ServerHook {
|
|
143
|
+
/**
|
|
144
|
+
* Called on each server request.
|
|
145
|
+
*/
|
|
146
|
+
handle?: ServerLoad;
|
|
147
|
+
}
|
|
148
|
+
type ServerLoad = (event: ServerEvent) => Promise<void> | void;
|
|
149
|
+
|
|
150
|
+
export { type PageEndPoint, type PageEvent, type PageServerEndPoint, type ServerEndPoint, type ServerEvent, type ServerHook, type UserConfig, buildRoutePath, defineConfig };
|