@skgo/sveltekit-adapter 0.16.3 → 0.16.4
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 +1 -1
- package/skgo-adapter/app-server.js +12 -4
- package/skgo-adapter/entry.js +6 -0
package/package.json
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
// below shadows the star, which is how the four substitutions take effect.
|
|
24
24
|
import * as real from 'skgo:kit/remote';
|
|
25
25
|
import { stringify_remote_arg } from 'skgo:kit/shared';
|
|
26
|
-
import { HttpError, Redirect } from '@sveltejs/kit/internal
|
|
26
|
+
import { HandledHttpError, HttpError, Redirect } from '@sveltejs/kit/internal';
|
|
27
|
+
import { DEV } from 'esm-env';
|
|
27
28
|
import { parse } from 'skgo:kit/transport';
|
|
28
29
|
|
|
29
30
|
export * from 'skgo:kit/app-server';
|
|
@@ -47,6 +48,9 @@ export * from 'skgo:kit/app-server';
|
|
|
47
48
|
async function host(id, payload) {
|
|
48
49
|
const raw = await globalThis.__skgo_remote(id, payload);
|
|
49
50
|
const res = JSON.parse(raw);
|
|
51
|
+
if (res.h) {
|
|
52
|
+
throw new HandledHttpError(res.h);
|
|
53
|
+
}
|
|
50
54
|
if (res.r) {
|
|
51
55
|
throw new Redirect(res.r.status, res.r.location);
|
|
52
56
|
}
|
|
@@ -64,9 +68,13 @@ export function query(validate_or_fn, maybe_fn) {
|
|
|
64
68
|
|
|
65
69
|
export function prerender(validate_or_fn, maybe_fn, options) {
|
|
66
70
|
const fn = (arg) => host(wrapper.__.id, stringify_remote_arg(arg));
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
const hasValidator = typeof maybe_fn === 'function';
|
|
72
|
+
const normalizedOptions = options ?? (hasValidator ? undefined : maybe_fn);
|
|
73
|
+
const wrapper = !DEV && !normalizedOptions?.dynamic
|
|
74
|
+
? real.prerender('unchecked', fn, normalizedOptions)
|
|
75
|
+
: hasValidator
|
|
76
|
+
? real.prerender(validate_or_fn, fn, options)
|
|
77
|
+
: real.prerender(fn, maybe_fn);
|
|
70
78
|
return wrapper;
|
|
71
79
|
}
|
|
72
80
|
|
package/skgo-adapter/entry.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
SvelteKitError,
|
|
21
21
|
ValidationError
|
|
22
22
|
} from '@sveltejs/kit/internal/server';
|
|
23
|
+
import { HandledHttpError } from '@sveltejs/kit/internal';
|
|
23
24
|
import * as devalue from 'skgo:devalue';
|
|
24
25
|
import { decoders, init_transport, parse } from 'skgo:kit/transport';
|
|
25
26
|
import { components, universalLoads } from 'skgo:nodes';
|
|
@@ -47,6 +48,7 @@ init_transport(transport ?? {});
|
|
|
47
48
|
* skgo has no handleError hook, so there is nothing here to await or merge.
|
|
48
49
|
*/
|
|
49
50
|
function handle_error(error) {
|
|
51
|
+
if (error instanceof HandledHttpError) return error.body;
|
|
50
52
|
if (error instanceof HttpError) return error.body;
|
|
51
53
|
if (error instanceof SvelteKitError) return { status: error.status, message: error.text };
|
|
52
54
|
if (error instanceof ValidationError) return { status: 400, message: 'Bad Request' };
|
|
@@ -418,6 +420,8 @@ globalThis.__skgo_render = function (req_json) {
|
|
|
418
420
|
(err) => {
|
|
419
421
|
if (err instanceof Redirect) {
|
|
420
422
|
result.redirect = { status: err.status, location: err.location };
|
|
423
|
+
} else if (err instanceof HandledHttpError) {
|
|
424
|
+
result.handled_error = err.body;
|
|
421
425
|
} else {
|
|
422
426
|
result.failure = (err && (err.stack || err.message)) || String(err);
|
|
423
427
|
}
|
|
@@ -427,6 +431,8 @@ globalThis.__skgo_render = function (req_json) {
|
|
|
427
431
|
} catch (err) {
|
|
428
432
|
if (err instanceof Redirect) {
|
|
429
433
|
result.redirect = { status: err.status, location: err.location };
|
|
434
|
+
} else if (err instanceof HandledHttpError) {
|
|
435
|
+
result.handled_error = err.body;
|
|
430
436
|
} else {
|
|
431
437
|
result.failure = (err && (err.stack || err.message)) || String(err);
|
|
432
438
|
}
|