@riducms/sveltekit 0.16.0 → 0.16.2
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/package.json +7 -4
- package/src/index.ts +3 -2
- package/src/server.ts +11 -2
package/package.json
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
"bugs": {
|
|
3
3
|
"url": "https://github.com/riducms/ridu/issues"
|
|
4
4
|
},
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"esm-env": "^1.2.2"
|
|
7
|
+
},
|
|
5
8
|
"description": "SvelteKit integration for Ridu: direct browser requests, server rendering, and one session owner.",
|
|
6
9
|
"devDependencies": {
|
|
7
|
-
"@riducms/sdk": "0.16.
|
|
10
|
+
"@riducms/sdk": "0.16.2",
|
|
8
11
|
"@sveltejs/kit": "^2.48.0"
|
|
9
12
|
},
|
|
10
13
|
"exports": {
|
|
@@ -27,8 +30,8 @@
|
|
|
27
30
|
"license": "MIT",
|
|
28
31
|
"name": "@riducms/sveltekit",
|
|
29
32
|
"peerDependencies": {
|
|
30
|
-
"@riducms/sdk": "0.16.
|
|
31
|
-
"@sveltejs/kit": "^2.20.0",
|
|
33
|
+
"@riducms/sdk": "0.16.2",
|
|
34
|
+
"@sveltejs/kit": "^2.20.0 || ^3.0.0",
|
|
32
35
|
"svelte": "^5.29.0"
|
|
33
36
|
},
|
|
34
37
|
"publishConfig": {
|
|
@@ -45,5 +48,5 @@
|
|
|
45
48
|
"test": "bun test"
|
|
46
49
|
},
|
|
47
50
|
"type": "module",
|
|
48
|
-
"version": "0.16.
|
|
51
|
+
"version": "0.16.2"
|
|
49
52
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AuthCollectionSlug, RiduClient, RiduConfigShape, SessionFor } from "@riducms/sdk";
|
|
2
2
|
import { getContext, onDestroy, onMount, setContext } from "svelte";
|
|
3
3
|
import { createSubscriber } from "svelte/reactivity";
|
|
4
|
-
import { browser } from "$app/environment";
|
|
5
4
|
import { invalidate } from "$app/navigation";
|
|
5
|
+
// SvelteKit 2 re-exports this from $app/environment, which SvelteKit 3 deprecates.
|
|
6
|
+
import { BROWSER } from "esm-env";
|
|
6
7
|
|
|
7
8
|
import { BrowserSessionStore } from "./browser-session.js";
|
|
8
9
|
import {
|
|
@@ -78,7 +79,7 @@ export function defineRidu<
|
|
|
78
79
|
const provided = provideOptions.session;
|
|
79
80
|
const snapshot =
|
|
80
81
|
typeof provided === "function" ? provided : () => provided as Session | null | undefined;
|
|
81
|
-
const client =
|
|
82
|
+
const client = BROWSER
|
|
82
83
|
? browserClient(definition, snapshot)
|
|
83
84
|
: renderClient(definition, snapshot);
|
|
84
85
|
setContext(clientKey, client);
|
package/src/server.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
RiduConfigShape,
|
|
6
6
|
SessionFor,
|
|
7
7
|
} from "@riducms/sdk";
|
|
8
|
-
import type {
|
|
8
|
+
import type { RequestEvent } from "@sveltejs/kit";
|
|
9
9
|
|
|
10
10
|
import { definitionKey, type RiduDefinition } from "./definition.js";
|
|
11
11
|
import { RequestSessionStore } from "./request-session.js";
|
|
@@ -49,6 +49,15 @@ export function createServerClient<
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* A server `handle` hook. SvelteKit 2 exports `Handle` from `@sveltejs/kit` and SvelteKit 3 from
|
|
54
|
+
* `@sveltejs/kit/hooks`; this shape is assignable to both.
|
|
55
|
+
*/
|
|
56
|
+
export type RiduHandle = (input: {
|
|
57
|
+
event: RequestEvent;
|
|
58
|
+
resolve: (event: RequestEvent) => Response | Promise<Response>;
|
|
59
|
+
}) => Response | Promise<Response>;
|
|
60
|
+
|
|
52
61
|
/**
|
|
53
62
|
* A SvelteKit `handle` that sets `event.locals.ridu` for each request. Compose it with other hooks
|
|
54
63
|
* through `sequence`.
|
|
@@ -56,7 +65,7 @@ export function createServerClient<
|
|
|
56
65
|
export function createRiduHandle<
|
|
57
66
|
Config extends RiduConfigShape,
|
|
58
67
|
Slug extends AuthCollectionSlug<Config>,
|
|
59
|
-
>(ridu: Binding<Config, Slug>, options: ServerClientOptions = {}):
|
|
68
|
+
>(ridu: Binding<Config, Slug>, options: ServerClientOptions = {}): RiduHandle {
|
|
60
69
|
return ({ event, resolve }) => {
|
|
61
70
|
// Applications type `App.Locals.ridu` with their own client; assign without widening it.
|
|
62
71
|
Object.assign(event.locals, { ridu: createServerClient(ridu, event, options) });
|