@torpor/build 0.0.4 → 0.0.6
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 +18 -0
- package/dist/bin/index.cjs.map +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/{chunk-L7GOYKUG.js → chunk-IE5EKBNX.js} +1 -1
- package/dist/chunk-IE5EKBNX.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -19
- package/dist/index.d.ts +24 -19
- package/dist/index.js +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- 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/dist/chunk-L7GOYKUG.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @torpor/build
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [b90d729]
|
|
8
|
+
- @torpor/view@0.0.7
|
|
9
|
+
- @torpor/unplugin@0.0.6
|
|
10
|
+
|
|
11
|
+
## 0.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 79da6cf: Refactor: export more types
|
|
16
|
+
- 3707fdb: Fix: better ordering of routes
|
|
17
|
+
- Updated dependencies [808da4c]
|
|
18
|
+
- @torpor/view@0.0.6
|
|
19
|
+
- @torpor/unplugin@0.0.5
|
|
20
|
+
|
|
3
21
|
## 0.0.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/bin/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.ts","../../src/site/defineConfig.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 defineConfig from \"../site/defineConfig\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.ts","../../src/site/defineConfig.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 defineConfig from \"../site/defineConfig\";\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\ndefineConfig(options);\n\n// This already gets done in vinxi.createApp so we can't do it twice\n//const app = defineConfig(options);\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 \"node:path\";\nimport { type AppOptions, type RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineConfig(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\tname: \"torpor\",\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(/_hook.server$/, \"_hook/~server\")\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,kBAAiB;;;ACHjB,kBAAmB;AACnB,uBAAiB;AACjB,mBAAmE;AACnE,oBAAuB;;;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,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEA,SAAS,OAAO,QAA2B,KAAiB;AAC3D,SAAO,IAAI;AAAA,IACV;AAAA,MACC,KAAK,iBAAAC,QAAK,QAAQ,YAAY;AAAA,MAC9B,YAAY,CAAC,MAAM,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,cAAc;AACtB,SAAO;AAAA,IACN,SAAS;AAAA,MACR,OAAO;AAAA,QACN,KAAK,iBAAAA,QAAK,QAAQ,KAAK;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;;;ADhEA,IAAI;AACJ,IAAM,aAAa,QAAQ,IAAI;AAC/B,IAAM,eAAe,YAAAC,QAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAM,eAAe,YAAAA,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,aAAa,OAAO;","names":["options","torpor","path","path","fs"]}
|
package/dist/bin/index.js
CHANGED
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.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 defineConfig from \"../site/defineConfig\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.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 defineConfig from \"../site/defineConfig\";\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\ndefineConfig(options);\n\n// This already gets done in vinxi.createApp so we can't do it twice\n//const app = defineConfig(options);\n//if (process.argv.includes(\"--dev\")) {\n//\tawait app.dev();\n//} else if (process.argv.includes(\"--build\")) {\n//\tawait app.build();\n//}\n"],"mappings":";;;;;;AAEA,OAAO,QAAQ;AACf,OAAO,UAAU;AAOjB,IAAI;AACJ,IAAM,aAAa,QAAQ,IAAI;AAC/B,IAAM,eAAe,KAAK,KAAK,YAAY,kBAAkB;AAC7D,IAAM,eAAe,KAAK,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,aAAa,OAAO;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/site/defineConfig.ts","../src/site/FileSystemRouter.ts"],"sourcesContent":["import torpor from \"@torpor/unplugin/vite\";\nimport path from \"node:path\";\nimport { type AppOptions, type RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineConfig(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\tname: \"torpor\",\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(/_hook.server$/, \"_hook/~server\")\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":";AAAA,OAAO,YAAY;AACnB,OAAO,UAAU;AACjB,SAAkD,iBAAiB;AACnE,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,iBAAiB,eA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AAA,IACxB;AAAA,IACA;AAAA,IACA;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;","names":[]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/site/buildRoutePath.ts","../src/site/defineConfig.ts","../src/site/FileSystemRouter.ts"],"sourcesContent":["import buildRoutePath from \"./site/buildRoutePath\";\nimport defineConfig from \"./site/defineConfig\";\nimport
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/site/buildRoutePath.ts","../src/site/defineConfig.ts","../src/site/FileSystemRouter.ts"],"sourcesContent":["import buildRoutePath from \"./site/buildRoutePath\";\nimport defineConfig from \"./site/defineConfig\";\nimport type CookieHelper from \"./types/CookieHelper\";\nimport type PageEndPoint from \"./types/PageEndPoint\";\nimport type PageEvent from \"./types/PageEvent\";\nimport type PageServerAction from \"./types/PageServerAction\";\nimport type PageServerEndPoint from \"./types/PageServerEndPoint\";\nimport type PageServerLoad from \"./types/PageServerLoad\";\nimport type ServerEndPoint from \"./types/ServerEndPoint\";\nimport type ServerEvent from \"./types/ServerEvent\";\nimport type ServerHook from \"./types/ServerHook\";\nimport type ServerRequest from \"./types/ServerRequest\";\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\tPageServerLoad,\n\tPageServerAction,\n\tServerEndPoint,\n\tServerRequest,\n\tServerHook,\n\tPageEvent,\n\tServerEvent,\n\tCookieHelper,\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 torpor from \"@torpor/unplugin/vite\";\nimport path from \"node:path\";\nimport { type AppOptions, type RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineConfig(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\tname: \"torpor\",\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(/_hook.server$/, \"_hook/~server\")\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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B,MAAM;AAAA,IACN,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,QAA2B,KAAiB;AAC3D,SAAO,IAAI;AAAA,IACV;AAAA,MACC,KAAK,iBAAAC,QAAK,QAAQ,YAAY;AAAA,MAC9B,YAAY,CAAC,MAAM,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,cAAc;AACtB,SAAO;AAAA,IACN,SAAS;AAAA,MACR,OAAO;AAAA,QACN,KAAK,iBAAAA,QAAK,QAAQ,KAAK;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;","names":["path","torpor","path"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vinxi from 'vinxi';
|
|
2
|
+
import { CookieSerializeOptions } from 'vinxi/http';
|
|
2
3
|
import { Component } from '@torpor/view';
|
|
3
4
|
import { ServerResponse } from 'node:http';
|
|
4
|
-
import { CookieSerializeOptions } from 'vinxi/http';
|
|
5
5
|
|
|
6
6
|
type ParamsType = Record<PropertyKey, any>;
|
|
7
7
|
declare function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(path: string, routeParams: RP, urlParams?: UP): string;
|
|
@@ -12,6 +12,12 @@ type UserConfig = {
|
|
|
12
12
|
|
|
13
13
|
declare function defineConfig(options?: UserConfig): vinxi.App;
|
|
14
14
|
|
|
15
|
+
type CookieHelper = {
|
|
16
|
+
get: (name: string) => string | undefined;
|
|
17
|
+
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
18
|
+
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
type PageEvent = {
|
|
16
22
|
/**
|
|
17
23
|
* The URL for the server function.
|
|
@@ -49,6 +55,7 @@ type PageEndPoint = {
|
|
|
49
55
|
*/
|
|
50
56
|
head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
|
|
51
57
|
};
|
|
58
|
+
|
|
52
59
|
type HeadElement = TitleElement | MetaElement;
|
|
53
60
|
interface TitleElement {
|
|
54
61
|
title: string;
|
|
@@ -58,12 +65,6 @@ interface MetaElement {
|
|
|
58
65
|
content: string;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
type CookieHelper = {
|
|
62
|
-
get: (name: string) => string | undefined;
|
|
63
|
-
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
64
|
-
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
68
|
type ServerEvent = {
|
|
68
69
|
/**
|
|
69
70
|
* The URL for the server function.
|
|
@@ -86,6 +87,10 @@ type ServerEvent = {
|
|
|
86
87
|
cookies: CookieHelper;
|
|
87
88
|
};
|
|
88
89
|
|
|
90
|
+
type PageServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
91
|
+
|
|
92
|
+
type PageServerLoad = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
93
|
+
|
|
89
94
|
/**
|
|
90
95
|
* For +page.server.
|
|
91
96
|
*/
|
|
@@ -93,14 +98,14 @@ type PageServerEndPoint = {
|
|
|
93
98
|
/**
|
|
94
99
|
* Loads data from the server for a page.
|
|
95
100
|
*/
|
|
96
|
-
load?:
|
|
101
|
+
load?: PageServerLoad;
|
|
97
102
|
/**
|
|
98
103
|
* A map of actions that can be performed on the server for a page, generally from a form submit.
|
|
99
104
|
*/
|
|
100
|
-
actions?: Record<string,
|
|
105
|
+
actions?: Record<string, PageServerAction>;
|
|
101
106
|
};
|
|
102
|
-
|
|
103
|
-
type
|
|
107
|
+
|
|
108
|
+
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
104
109
|
|
|
105
110
|
/**
|
|
106
111
|
* For +server.
|
|
@@ -113,31 +118,30 @@ type ServerEndPoint = {
|
|
|
113
118
|
*/
|
|
114
119
|
get?: ServerRequest;
|
|
115
120
|
/**
|
|
116
|
-
*
|
|
121
|
+
* Performs a POST.
|
|
117
122
|
*/
|
|
118
123
|
post?: ServerRequest;
|
|
119
124
|
/**
|
|
120
|
-
*
|
|
125
|
+
* Performs a PATCH.
|
|
121
126
|
*/
|
|
122
127
|
patch?: ServerRequest;
|
|
123
128
|
/**
|
|
124
|
-
*
|
|
129
|
+
* Performs a PUT.
|
|
125
130
|
*/
|
|
126
131
|
put?: ServerRequest;
|
|
127
132
|
/**
|
|
128
|
-
*
|
|
133
|
+
* Performs a DELETE.
|
|
129
134
|
*/
|
|
130
135
|
del?: ServerRequest;
|
|
131
136
|
/**
|
|
132
|
-
*
|
|
137
|
+
* Performs an OPTIONS request.
|
|
133
138
|
*/
|
|
134
139
|
options?: ServerRequest;
|
|
135
140
|
/**
|
|
136
|
-
*
|
|
141
|
+
* Performs a HEAD request.
|
|
137
142
|
*/
|
|
138
143
|
head?: ServerRequest;
|
|
139
144
|
};
|
|
140
|
-
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
141
145
|
|
|
142
146
|
/**
|
|
143
147
|
* For _hook.server.
|
|
@@ -148,6 +152,7 @@ type ServerHook = {
|
|
|
148
152
|
*/
|
|
149
153
|
handle?: ServerLoad;
|
|
150
154
|
};
|
|
155
|
+
|
|
151
156
|
type ServerLoad = (event: ServerEvent) => Promise<void> | void;
|
|
152
157
|
|
|
153
|
-
export { type PageEndPoint, type PageEvent, type PageServerEndPoint, type ServerEndPoint, type ServerEvent, type ServerHook, type UserConfig, buildRoutePath, defineConfig };
|
|
158
|
+
export { type CookieHelper, type PageEndPoint, type PageEvent, type PageServerAction, type PageServerEndPoint, type PageServerLoad, type ServerEndPoint, type ServerEvent, type ServerHook, type ServerRequest, type UserConfig, buildRoutePath, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vinxi from 'vinxi';
|
|
2
|
+
import { CookieSerializeOptions } from 'vinxi/http';
|
|
2
3
|
import { Component } from '@torpor/view';
|
|
3
4
|
import { ServerResponse } from 'node:http';
|
|
4
|
-
import { CookieSerializeOptions } from 'vinxi/http';
|
|
5
5
|
|
|
6
6
|
type ParamsType = Record<PropertyKey, any>;
|
|
7
7
|
declare function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(path: string, routeParams: RP, urlParams?: UP): string;
|
|
@@ -12,6 +12,12 @@ type UserConfig = {
|
|
|
12
12
|
|
|
13
13
|
declare function defineConfig(options?: UserConfig): vinxi.App;
|
|
14
14
|
|
|
15
|
+
type CookieHelper = {
|
|
16
|
+
get: (name: string) => string | undefined;
|
|
17
|
+
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
18
|
+
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
type PageEvent = {
|
|
16
22
|
/**
|
|
17
23
|
* The URL for the server function.
|
|
@@ -49,6 +55,7 @@ type PageEndPoint = {
|
|
|
49
55
|
*/
|
|
50
56
|
head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
|
|
51
57
|
};
|
|
58
|
+
|
|
52
59
|
type HeadElement = TitleElement | MetaElement;
|
|
53
60
|
interface TitleElement {
|
|
54
61
|
title: string;
|
|
@@ -58,12 +65,6 @@ interface MetaElement {
|
|
|
58
65
|
content: string;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
type CookieHelper = {
|
|
62
|
-
get: (name: string) => string | undefined;
|
|
63
|
-
set: (name: string, value: string, options?: CookieSerializeOptions) => void;
|
|
64
|
-
delete: (name: string, options?: CookieSerializeOptions) => void;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
68
|
type ServerEvent = {
|
|
68
69
|
/**
|
|
69
70
|
* The URL for the server function.
|
|
@@ -86,6 +87,10 @@ type ServerEvent = {
|
|
|
86
87
|
cookies: CookieHelper;
|
|
87
88
|
};
|
|
88
89
|
|
|
90
|
+
type PageServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
91
|
+
|
|
92
|
+
type PageServerLoad = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
93
|
+
|
|
89
94
|
/**
|
|
90
95
|
* For +page.server.
|
|
91
96
|
*/
|
|
@@ -93,14 +98,14 @@ type PageServerEndPoint = {
|
|
|
93
98
|
/**
|
|
94
99
|
* Loads data from the server for a page.
|
|
95
100
|
*/
|
|
96
|
-
load?:
|
|
101
|
+
load?: PageServerLoad;
|
|
97
102
|
/**
|
|
98
103
|
* A map of actions that can be performed on the server for a page, generally from a form submit.
|
|
99
104
|
*/
|
|
100
|
-
actions?: Record<string,
|
|
105
|
+
actions?: Record<string, PageServerAction>;
|
|
101
106
|
};
|
|
102
|
-
|
|
103
|
-
type
|
|
107
|
+
|
|
108
|
+
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
104
109
|
|
|
105
110
|
/**
|
|
106
111
|
* For +server.
|
|
@@ -113,31 +118,30 @@ type ServerEndPoint = {
|
|
|
113
118
|
*/
|
|
114
119
|
get?: ServerRequest;
|
|
115
120
|
/**
|
|
116
|
-
*
|
|
121
|
+
* Performs a POST.
|
|
117
122
|
*/
|
|
118
123
|
post?: ServerRequest;
|
|
119
124
|
/**
|
|
120
|
-
*
|
|
125
|
+
* Performs a PATCH.
|
|
121
126
|
*/
|
|
122
127
|
patch?: ServerRequest;
|
|
123
128
|
/**
|
|
124
|
-
*
|
|
129
|
+
* Performs a PUT.
|
|
125
130
|
*/
|
|
126
131
|
put?: ServerRequest;
|
|
127
132
|
/**
|
|
128
|
-
*
|
|
133
|
+
* Performs a DELETE.
|
|
129
134
|
*/
|
|
130
135
|
del?: ServerRequest;
|
|
131
136
|
/**
|
|
132
|
-
*
|
|
137
|
+
* Performs an OPTIONS request.
|
|
133
138
|
*/
|
|
134
139
|
options?: ServerRequest;
|
|
135
140
|
/**
|
|
136
|
-
*
|
|
141
|
+
* Performs a HEAD request.
|
|
137
142
|
*/
|
|
138
143
|
head?: ServerRequest;
|
|
139
144
|
};
|
|
140
|
-
type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
|
|
141
145
|
|
|
142
146
|
/**
|
|
143
147
|
* For _hook.server.
|
|
@@ -148,6 +152,7 @@ type ServerHook = {
|
|
|
148
152
|
*/
|
|
149
153
|
handle?: ServerLoad;
|
|
150
154
|
};
|
|
155
|
+
|
|
151
156
|
type ServerLoad = (event: ServerEvent) => Promise<void> | void;
|
|
152
157
|
|
|
153
|
-
export { type PageEndPoint, type PageEvent, type PageServerEndPoint, type ServerEndPoint, type ServerEvent, type ServerHook, type UserConfig, buildRoutePath, defineConfig };
|
|
158
|
+
export { type CookieHelper, type PageEndPoint, type PageEvent, type PageServerAction, type PageServerEndPoint, type PageServerLoad, type ServerEndPoint, type ServerEvent, type ServerHook, type ServerRequest, type UserConfig, buildRoutePath, defineConfig };
|
package/dist/index.js
CHANGED
package/dist/metafile-cjs.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/site/buildRoutePath.ts":{"bytes":599,"imports":[],"format":"esm"},"src/site/FileSystemRouter.ts":{"bytes":651,"imports":[{"path":"vinxi/fs-router","kind":"import-statement","external":true}],"format":"esm"},"src/site/defineConfig.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/site/buildRoutePath.ts":{"bytes":599,"imports":[],"format":"esm"},"src/site/FileSystemRouter.ts":{"bytes":651,"imports":[{"path":"vinxi/fs-router","kind":"import-statement","external":true}],"format":"esm"},"src/site/defineConfig.ts":{"bytes":1922,"imports":[{"path":"@torpor/unplugin/vite","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"vinxi","kind":"import-statement","external":true},{"path":"vinxi/plugins/config","kind":"import-statement","external":true},{"path":"src/site/FileSystemRouter.ts","kind":"import-statement","original":"./FileSystemRouter"}],"format":"esm"},"src/index.ts":{"bytes":1095,"imports":[{"path":"src/site/buildRoutePath.ts","kind":"import-statement","original":"./site/buildRoutePath"},{"path":"src/site/defineConfig.ts","kind":"import-statement","original":"./site/defineConfig"}],"format":"esm"},"src/response/response.ts":{"bytes":681,"imports":[],"format":"esm"},"src/response/badRequest.ts":{"bytes":451,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/created.ts":{"bytes":384,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/forbidden.ts":{"bytes":458,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/methodNotAllowed.ts":{"bytes":419,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/transfer.ts":{"bytes":264,"imports":[],"format":"esm"},"src/response/moved.ts":{"bytes":613,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/notFound.ts":{"bytes":671,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/notModified.ts":{"bytes":419,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/ok.ts":{"bytes":684,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/redirect.ts":{"bytes":640,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/seeOther.ts":{"bytes":355,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/serverError.ts":{"bytes":315,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/unauthorized.ts":{"bytes":432,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/unprocessable.ts":{"bytes":337,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response.ts":{"bytes":886,"imports":[{"path":"src/response/badRequest.ts","kind":"import-statement","original":"./response/badRequest"},{"path":"src/response/created.ts","kind":"import-statement","original":"./response/created"},{"path":"src/response/forbidden.ts","kind":"import-statement","original":"./response/forbidden"},{"path":"src/response/methodNotAllowed.ts","kind":"import-statement","original":"./response/methodNotAllowed"},{"path":"src/response/moved.ts","kind":"import-statement","original":"./response/moved"},{"path":"src/response/notFound.ts","kind":"import-statement","original":"./response/notFound"},{"path":"src/response/notModified.ts","kind":"import-statement","original":"./response/notModified"},{"path":"src/response/ok.ts","kind":"import-statement","original":"./response/ok"},{"path":"src/response/redirect.ts","kind":"import-statement","original":"./response/redirect"},{"path":"src/response/response.ts","kind":"import-statement","original":"./response/response"},{"path":"src/response/seeOther.ts","kind":"import-statement","original":"./response/seeOther"},{"path":"src/response/serverError.ts","kind":"import-statement","original":"./response/serverError"},{"path":"src/response/transfer.ts","kind":"import-statement","original":"./response/transfer"},{"path":"src/response/unauthorized.ts","kind":"import-statement","original":"./response/unauthorized"},{"path":"src/response/unprocessable.ts","kind":"import-statement","original":"./response/unprocessable"}],"format":"esm"},"src/state/$page.ts":{"bytes":166,"imports":[{"path":"@torpor/view","kind":"import-statement","external":true}],"format":"esm"},"src/state.ts":{"bytes":54,"imports":[{"path":"src/state/$page.ts","kind":"import-statement","original":"./state/$page"}],"format":"esm"},"src/bin/index.ts":{"bytes":1367,"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"src/site/defineConfig.ts","kind":"import-statement","original":"../site/defineConfig"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6989},"dist/index.cjs":{"imports":[{"path":"@torpor/unplugin/vite","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"vinxi","kind":"require-call","external":true},{"path":"vinxi/plugins/config","kind":"require-call","external":true},{"path":"vinxi/fs-router","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":175},"src/site/buildRoutePath.ts":{"bytesInOutput":436},"src/site/defineConfig.ts":{"bytesInOutput":1996},"src/site/FileSystemRouter.ts":{"bytesInOutput":647}},"bytes":4913},"dist/response.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10303},"dist/response.cjs":{"imports":[],"exports":[],"entryPoint":"src/response.ts","inputs":{"src/response.ts":{"bytesInOutput":560},"src/response/response.ts":{"bytesInOutput":334},"src/response/badRequest.ts":{"bytesInOutput":60},"src/response/created.ts":{"bytesInOutput":57},"src/response/forbidden.ts":{"bytesInOutput":59},"src/response/methodNotAllowed.ts":{"bytesInOutput":66},"src/response/transfer.ts":{"bytesInOutput":124},"src/response/moved.ts":{"bytesInOutput":63},"src/response/notFound.ts":{"bytesInOutput":58},"src/response/notModified.ts":{"bytesInOutput":69},"src/response/ok.ts":{"bytesInOutput":52},"src/response/redirect.ts":{"bytesInOutput":66},"src/response/seeOther.ts":{"bytesInOutput":66},"src/response/serverError.ts":{"bytesInOutput":61},"src/response/unauthorized.ts":{"bytesInOutput":62},"src/response/unprocessable.ts":{"bytesInOutput":63}},"bytes":3376},"dist/state.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":577},"dist/state.cjs":{"imports":[{"path":"@torpor/view","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/state.ts","inputs":{"src/state.ts":{"bytesInOutput":128},"src/state/$page.ts":{"bytesInOutput":192}},"bytes":1258},"dist/bin/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6593},"dist/bin/index.cjs":{"imports":[{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"@torpor/unplugin/vite","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"vinxi","kind":"require-call","external":true},{"path":"vinxi/plugins/config","kind":"require-call","external":true},{"path":"vinxi/fs-router","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/bin/index.ts","inputs":{"src/bin/index.ts":{"bytesInOutput":779},"src/site/defineConfig.ts":{"bytesInOutput":1998},"src/site/FileSystemRouter.ts":{"bytesInOutput":647}},"bytes":4754}}}
|
package/dist/metafile-esm.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/site/buildRoutePath.ts":{"bytes":599,"imports":[],"format":"esm"},"src/site/FileSystemRouter.ts":{"bytes":651,"imports":[{"path":"vinxi/fs-router","kind":"import-statement","external":true}],"format":"esm"},"src/site/defineConfig.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/site/buildRoutePath.ts":{"bytes":599,"imports":[],"format":"esm"},"src/site/FileSystemRouter.ts":{"bytes":651,"imports":[{"path":"vinxi/fs-router","kind":"import-statement","external":true}],"format":"esm"},"src/site/defineConfig.ts":{"bytes":1922,"imports":[{"path":"@torpor/unplugin/vite","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vinxi","kind":"import-statement","external":true},{"path":"vinxi/plugins/config","kind":"import-statement","external":true},{"path":"src/site/FileSystemRouter.ts","kind":"import-statement","original":"./FileSystemRouter"}],"format":"esm"},"src/index.ts":{"bytes":1095,"imports":[{"path":"src/site/buildRoutePath.ts","kind":"import-statement","original":"./site/buildRoutePath"},{"path":"src/site/defineConfig.ts","kind":"import-statement","original":"./site/defineConfig"}],"format":"esm"},"src/response/response.ts":{"bytes":681,"imports":[],"format":"esm"},"src/response/badRequest.ts":{"bytes":451,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/created.ts":{"bytes":384,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/forbidden.ts":{"bytes":458,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/methodNotAllowed.ts":{"bytes":419,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/transfer.ts":{"bytes":264,"imports":[],"format":"esm"},"src/response/moved.ts":{"bytes":613,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/notFound.ts":{"bytes":671,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/notModified.ts":{"bytes":419,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/ok.ts":{"bytes":684,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/redirect.ts":{"bytes":640,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/seeOther.ts":{"bytes":355,"imports":[{"path":"src/response/transfer.ts","kind":"import-statement","original":"./transfer"}],"format":"esm"},"src/response/serverError.ts":{"bytes":315,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/unauthorized.ts":{"bytes":432,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response/unprocessable.ts":{"bytes":337,"imports":[{"path":"src/response/response.ts","kind":"import-statement","original":"./response"}],"format":"esm"},"src/response.ts":{"bytes":886,"imports":[{"path":"src/response/badRequest.ts","kind":"import-statement","original":"./response/badRequest"},{"path":"src/response/created.ts","kind":"import-statement","original":"./response/created"},{"path":"src/response/forbidden.ts","kind":"import-statement","original":"./response/forbidden"},{"path":"src/response/methodNotAllowed.ts","kind":"import-statement","original":"./response/methodNotAllowed"},{"path":"src/response/moved.ts","kind":"import-statement","original":"./response/moved"},{"path":"src/response/notFound.ts","kind":"import-statement","original":"./response/notFound"},{"path":"src/response/notModified.ts","kind":"import-statement","original":"./response/notModified"},{"path":"src/response/ok.ts","kind":"import-statement","original":"./response/ok"},{"path":"src/response/redirect.ts","kind":"import-statement","original":"./response/redirect"},{"path":"src/response/response.ts","kind":"import-statement","original":"./response/response"},{"path":"src/response/seeOther.ts","kind":"import-statement","original":"./response/seeOther"},{"path":"src/response/serverError.ts","kind":"import-statement","original":"./response/serverError"},{"path":"src/response/transfer.ts","kind":"import-statement","original":"./response/transfer"},{"path":"src/response/unauthorized.ts","kind":"import-statement","original":"./response/unauthorized"},{"path":"src/response/unprocessable.ts","kind":"import-statement","original":"./response/unprocessable"}],"format":"esm"},"src/state/$page.ts":{"bytes":166,"imports":[{"path":"@torpor/view","kind":"import-statement","external":true}],"format":"esm"},"src/state.ts":{"bytes":54,"imports":[{"path":"src/state/$page.ts","kind":"import-statement","original":"./state/$page"}],"format":"esm"},"src/bin/index.ts":{"bytes":1367,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"src/site/defineConfig.ts","kind":"import-statement","original":"../site/defineConfig"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1199},"dist/index.js":{"imports":[{"path":"dist/chunk-IE5EKBNX.js","kind":"import-statement"}],"exports":["buildRoutePath","defineConfig"],"entryPoint":"src/index.ts","inputs":{"src/site/buildRoutePath.ts":{"bytesInOutput":431},"src/index.ts":{"bytesInOutput":0}},"bytes":561},"dist/response.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":9197},"dist/response.js":{"imports":[],"exports":["badRequest","created","forbidden","methodNotAllowed","moved","notFound","notModified","ok","redirect","response","seeOther","serverError","transfer","unauthorized","unprocessable"],"entryPoint":"src/response.ts","inputs":{"src/response/response.ts":{"bytesInOutput":334},"src/response/badRequest.ts":{"bytesInOutput":60},"src/response/created.ts":{"bytesInOutput":57},"src/response/forbidden.ts":{"bytesInOutput":59},"src/response/methodNotAllowed.ts":{"bytesInOutput":66},"src/response/transfer.ts":{"bytesInOutput":124},"src/response/moved.ts":{"bytesInOutput":63},"src/response/notFound.ts":{"bytesInOutput":58},"src/response/notModified.ts":{"bytesInOutput":69},"src/response/ok.ts":{"bytesInOutput":52},"src/response/redirect.ts":{"bytesInOutput":66},"src/response/seeOther.ts":{"bytesInOutput":66},"src/response/serverError.ts":{"bytesInOutput":61},"src/response/unauthorized.ts":{"bytesInOutput":62},"src/response/unprocessable.ts":{"bytesInOutput":63},"src/response.ts":{"bytesInOutput":0}},"bytes":1917},"dist/state.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":452},"dist/state.js":{"imports":[{"path":"@torpor/view","kind":"import-statement","external":true}],"exports":["$page"],"entryPoint":"src/state.ts","inputs":{"src/state/$page.ts":{"bytesInOutput":171},"src/state.ts":{"bytesInOutput":0}},"bytes":229},"dist/bin/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1992},"dist/bin/index.js":{"imports":[{"path":"dist/chunk-IE5EKBNX.js","kind":"import-statement"},{"path":"node:fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true}],"exports":[],"entryPoint":"src/bin/index.ts","inputs":{"src/bin/index.ts":{"bytesInOutput":645}},"bytes":742},"dist/chunk-IE5EKBNX.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4590},"dist/chunk-IE5EKBNX.js":{"imports":[{"path":"@torpor/unplugin/vite","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vinxi","kind":"import-statement","external":true},{"path":"vinxi/plugins/config","kind":"import-statement","external":true},{"path":"vinxi/fs-router","kind":"import-statement","external":true}],"exports":["defineConfig"],"inputs":{"src/site/defineConfig.ts":{"bytesInOutput":1814},"src/site/FileSystemRouter.ts":{"bytesInOutput":624}},"bytes":2556}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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/view": "^0.0.
|
|
38
|
-
"@torpor/unplugin": "^0.0.
|
|
37
|
+
"@torpor/view": "^0.0.7",
|
|
38
|
+
"@torpor/unplugin": "^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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/site/defineConfig.ts","../src/site/FileSystemRouter.ts"],"sourcesContent":["import torpor from \"@torpor/unplugin/vite\";\nimport path from \"node:path\";\nimport { type AppOptions, type RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport { type UserConfig } from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineConfig(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\tname: \"torpor\",\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(/_hook.server$/, \"_hook/~server\")\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: [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