@noverax/courier-sveltekit 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -6
- package/lib/handle.d.ts +2 -4
- package/lib/handle.js +2 -3
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -3
- package/lib/plugin.d.ts +2 -0
- package/lib/plugin.js +1 -0
- package/lib/{request-context-CXZTuX53.d.ts → request-context-CCrSKMZT.d.ts} +0 -2
- package/lib/{request-context-UtZzeQWD.js → request-context-D_B34mll.js} +2 -4
- package/package.json +22 -3
package/README.md
CHANGED
|
@@ -127,20 +127,53 @@ In `vite dev`, a chunked body larger than the limit resets the connection instea
|
|
|
127
127
|
|
|
128
128
|
## With Frontend
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
Add the routes plugin beside SvelteKit's, so every page — and the server that renders it — gets the routes its proxy client may call, built from `courier.config.ts`.
|
|
131
|
+
|
|
132
|
+
The plugin runs on `@noverax/courier-build`, which only the build needs, so install it as a dev dependency:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm install --save-dev @noverax/courier-build
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Then add it:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
// vite.config.ts
|
|
142
|
+
import { sveltekit } from "@sveltejs/kit/vite"
|
|
143
|
+
import { courierRoutes } from "@noverax/courier-sveltekit/plugin"
|
|
144
|
+
import { defineConfig } from "vite"
|
|
145
|
+
|
|
146
|
+
export default defineConfig({ plugins: [sveltekit(), courierRoutes()] })
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Register the config once, so `routes` is typed from it:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// src/courier-env.d.ts
|
|
153
|
+
import type config from "../courier.config"
|
|
154
|
+
|
|
155
|
+
declare module "@noverax/courier/routes" {
|
|
156
|
+
interface Register {
|
|
157
|
+
config: typeof config
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Then pair with `createProxyCaller` on the client:
|
|
131
163
|
|
|
132
164
|
```ts
|
|
133
165
|
import { createProxyCaller } from "@noverax/courier"
|
|
134
|
-
import {
|
|
166
|
+
import { routes } from "@noverax/courier/routes"
|
|
135
167
|
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
const caller = createProxyCaller(
|
|
168
|
+
// What a page may call of the source registered as `api` in your `sources` map:
|
|
169
|
+
// the endpoints you mark .expose(), and how each is reached.
|
|
170
|
+
const caller = createProxyCaller(routes.api, {
|
|
139
171
|
proxyPath: { http: "/api/request" },
|
|
140
172
|
})
|
|
141
|
-
const users = await caller.users.getAll()
|
|
142
173
|
```
|
|
143
174
|
|
|
175
|
+
A project that would rather keep the routes in its tree writes them with `npx @noverax/courier-cli routes`, and gives the caller `apiRoutes` from `./courier.routes` in place of `routes.api`.
|
|
176
|
+
|
|
144
177
|
<br />
|
|
145
178
|
|
|
146
179
|
## Cancelled calls
|
|
@@ -187,6 +220,10 @@ The request SvelteKit 2.20 and later is serving, for `registerRequestContext`.
|
|
|
187
220
|
|
|
188
221
|
From `@noverax/courier-sveltekit/handle`: a `handle` hook that serves every request with its session at hand.
|
|
189
222
|
|
|
223
|
+
### `courierRoutes(options?)`
|
|
224
|
+
|
|
225
|
+
From `@noverax/courier-sveltekit/plugin`: the Vite plugin that builds the routes a page's proxy client may call from `courier.config.ts`, in place of `@noverax/courier/routes`. `config` names the config file when it is not the one found from the root.
|
|
226
|
+
|
|
190
227
|
<br />
|
|
191
228
|
|
|
192
229
|
## Part of Courier
|
package/lib/handle.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as SvelteKitServerEvent } from "./request-context-
|
|
2
|
-
//#region src/handle.d.ts
|
|
1
|
+
import { t as SvelteKitServerEvent } from "./request-context-CCrSKMZT.js";
|
|
3
2
|
/** A SvelteKit `handle` hook, as far as it reads its input. */
|
|
4
3
|
export type RequestContextHandle = <TEvent extends SvelteKitServerEvent, TResponse>(input: {
|
|
5
4
|
event: TEvent;
|
|
@@ -21,5 +20,4 @@ export type RequestContextHandle = <TEvent extends SvelteKitServerEvent, TRespon
|
|
|
21
20
|
* export const handle = requestContextHandle();
|
|
22
21
|
* ```
|
|
23
22
|
*/
|
|
24
|
-
export declare function requestContextHandle(): RequestContextHandle;
|
|
25
|
-
//#endregion
|
|
23
|
+
export declare function requestContextHandle(): RequestContextHandle;
|
package/lib/handle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as svelteKitIncomingRequest } from "./request-context-
|
|
1
|
+
import { t as svelteKitIncomingRequest } from "./request-context-D_B34mll.js";
|
|
2
2
|
import { withIncomingRequest } from "@noverax/courier/node";
|
|
3
|
-
|
|
3
|
+
// src/handle.ts
|
|
4
4
|
/**
|
|
5
5
|
* A `handle` hook that serves every request with its session and headers at
|
|
6
6
|
* hand: each call the request's hooks, `load` functions, form actions and
|
|
@@ -20,5 +20,4 @@ import { withIncomingRequest } from "@noverax/courier/node";
|
|
|
20
20
|
function requestContextHandle() {
|
|
21
21
|
return ({ event, resolve }) => withIncomingRequest(svelteKitIncomingRequest(event), () => resolve(event));
|
|
22
22
|
}
|
|
23
|
-
//#endregion
|
|
24
23
|
export { requestContextHandle };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as svelteKitIncomingRequest, r as svelteKitRequestContext, t as SvelteKitServerEvent } from "./request-context-
|
|
1
|
+
import { n as svelteKitIncomingRequest, r as svelteKitRequestContext, t as SvelteKitServerEvent } from "./request-context-CCrSKMZT.js";
|
|
2
2
|
import { ClientConnection, ConnectResult, HandlerConfig } from "@noverax/courier";
|
|
3
|
-
//#region src/index.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* The parts of SvelteKit's `RequestEvent` the handler reads. `platform.req`
|
|
6
5
|
* is the Node request `@sveltejs/adapter-node` passes along.
|
|
@@ -47,5 +46,4 @@ export interface SvelteKitRequestEvent {
|
|
|
47
46
|
* ```
|
|
48
47
|
*/
|
|
49
48
|
export declare function courierHandler<TConnect extends ConnectResult = ConnectResult>(config?: HandlerConfig<TConnect>): (event: SvelteKitRequestEvent) => Promise<Response>;
|
|
50
|
-
//#endregion
|
|
51
49
|
export { type SvelteKitServerEvent, svelteKitIncomingRequest, svelteKitRequestContext };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as svelteKitRequestContext, r as svelteKitClientAddress, t as svelteKitIncomingRequest } from "./request-context-
|
|
1
|
+
import { n as svelteKitRequestContext, r as svelteKitClientAddress, t as svelteKitIncomingRequest } from "./request-context-D_B34mll.js";
|
|
2
2
|
import { createHandler, handleWhileConnected } from "@noverax/courier";
|
|
3
3
|
import { announceWhenRegistered } from "@noverax/courier/announce";
|
|
4
4
|
import { rememberPeerAddress, serverOriginOf } from "@noverax/courier/internal";
|
|
5
|
-
|
|
5
|
+
// src/index.ts
|
|
6
6
|
/**
|
|
7
7
|
* Create a SvelteKit request handler for the courier proxy.
|
|
8
8
|
*
|
|
@@ -46,5 +46,4 @@ function courierHandler(config) {
|
|
|
46
46
|
return handleWhileConnected(handle, event.request, event.platform?.req?.socket);
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
//#endregion
|
|
50
49
|
export { courierHandler, svelteKitIncomingRequest, svelteKitRequestContext };
|
package/lib/plugin.d.ts
ADDED
package/lib/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { courierRoutes } from "@noverax/courier-build/vite";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IncomingRequest, RequestContextProvider } from "@noverax/courier";
|
|
2
|
-
//#region src/request-context.d.ts
|
|
3
2
|
/** A cookie's options, as SvelteKit's `cookies.set()` takes them. */
|
|
4
3
|
interface SvelteKitCookieOptions {
|
|
5
4
|
path: string;
|
|
@@ -55,5 +54,4 @@ declare function svelteKitRequestContext(getRequestEvent: () => SvelteKitServerE
|
|
|
55
54
|
* ```
|
|
56
55
|
*/
|
|
57
56
|
declare function svelteKitIncomingRequest(event: SvelteKitServerEvent): IncomingRequest;
|
|
58
|
-
//#endregion
|
|
59
57
|
export { svelteKitIncomingRequest as n, svelteKitRequestContext as r, SvelteKitServerEvent as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLogger } from "@noverax/courier";
|
|
2
2
|
import { forwardedChain } from "@noverax/courier/internal";
|
|
3
|
-
|
|
3
|
+
// src/client-address.ts
|
|
4
4
|
const log$1 = createLogger("SvelteKit");
|
|
5
5
|
/**
|
|
6
6
|
* The address SvelteKit's adapter reports a request came from, where it
|
|
@@ -22,8 +22,7 @@ function svelteKitClientAddress(event) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
//#region src/request-context.ts
|
|
25
|
+
// src/request-context.ts
|
|
27
26
|
const log = createLogger("SvelteKit");
|
|
28
27
|
const providers = /* @__PURE__ */ new WeakMap();
|
|
29
28
|
/**
|
|
@@ -111,5 +110,4 @@ function optionsOf(cookie) {
|
|
|
111
110
|
function lower(value) {
|
|
112
111
|
return value.toLowerCase();
|
|
113
112
|
}
|
|
114
|
-
//#endregion
|
|
115
113
|
export { svelteKitRequestContext as n, svelteKitClientAddress as r, svelteKitIncomingRequest as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noverax/courier-sveltekit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "SvelteKit adapter for Courier: an endpoint that proxies typed calls to any backend, with the user's session in load functions and form actions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"courier",
|
|
@@ -49,12 +49,20 @@
|
|
|
49
49
|
"types": "./lib/handle.d.ts",
|
|
50
50
|
"import": "./lib/handle.js",
|
|
51
51
|
"default": "./lib/handle.js"
|
|
52
|
+
},
|
|
53
|
+
"./plugin": {
|
|
54
|
+
"types": "./lib/plugin.d.ts",
|
|
55
|
+
"import": "./lib/plugin.js",
|
|
56
|
+
"default": "./lib/plugin.js"
|
|
52
57
|
}
|
|
53
58
|
},
|
|
54
59
|
"typesVersions": {
|
|
55
60
|
"*": {
|
|
56
61
|
"handle": [
|
|
57
62
|
"./lib/handle.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"plugin": [
|
|
65
|
+
"./lib/plugin.d.ts"
|
|
58
66
|
]
|
|
59
67
|
}
|
|
60
68
|
},
|
|
@@ -72,9 +80,20 @@
|
|
|
72
80
|
"access": "public"
|
|
73
81
|
},
|
|
74
82
|
"peerDependencies": {
|
|
75
|
-
"@noverax/courier": "^0.
|
|
83
|
+
"@noverax/courier": "^0.4.0",
|
|
84
|
+
"@noverax/courier-build": "^0.4.0",
|
|
85
|
+
"vite": ">=5.0.0"
|
|
86
|
+
},
|
|
87
|
+
"peerDependenciesMeta": {
|
|
88
|
+
"@noverax/courier-build": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"vite": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
76
94
|
},
|
|
77
95
|
"devDependencies": {
|
|
78
|
-
"@noverax/courier": "*"
|
|
96
|
+
"@noverax/courier": "*",
|
|
97
|
+
"@noverax/courier-build": "*"
|
|
79
98
|
}
|
|
80
99
|
}
|