@openworkers/adapter-sveltekit 0.5.3 → 0.5.5

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.
@@ -1,4 +1,4 @@
1
- // src/function-worker.ts
1
+ // src/runtime/function-worker.ts
2
2
  import * as handlers from "ENDPOINT";
3
3
  var worker = {
4
4
  async fetch(req, env, ctx) {
@@ -28,6 +28,7 @@ var worker = {
28
28
  cookiesData = getCookies(req, url);
29
29
  cookiesData.set_trailing_slash("ignore");
30
30
  }
31
+ const noopSpan = {};
31
32
  const event = {
32
33
  fetch: globalThis.fetch.bind(globalThis),
33
34
  request: req,
@@ -36,6 +37,11 @@ var worker = {
36
37
  cookies: WITH_COOKIES && cookiesData?.cookies || void 0,
37
38
  locals: {},
38
39
  platform: { env, ctx },
40
+ route: { id: ROUTE_PATTERN },
41
+ isDataRequest: false,
42
+ isSubRequest: false,
43
+ isRemoteRequest: false,
44
+ tracing: { enabled: false, root: noopSpan, current: noopSpan },
39
45
  getClientAddress() {
40
46
  return req.headers.get("x-real-ip") ?? req.headers.get("x-forwarded-for") ?? "";
41
47
  },
@@ -45,8 +51,8 @@ var worker = {
45
51
  }
46
52
  }
47
53
  };
48
- try {
49
- const response = await handler(event);
54
+ const resolve = async (resolvedEvent) => {
55
+ const response = await handler(resolvedEvent);
50
56
  if (WITH_COOKIES && cookiesData?.new_cookies) {
51
57
  const { addCookiesToHeaders } = await import("lib:cookies");
52
58
  addCookiesToHeaders(response.headers, cookiesData.new_cookies.values());
@@ -55,6 +61,14 @@ var worker = {
55
61
  response.headers.append(key, value);
56
62
  }
57
63
  return response;
64
+ };
65
+ try {
66
+ if (WITH_HOOKS) {
67
+ const { handle } = await import("lib:hooks");
68
+ return await handle({ event, resolve });
69
+ } else {
70
+ return await resolve(event);
71
+ }
58
72
  } catch (error) {
59
73
  if (error?.status >= 300 && error?.status < 400 && error?.location) {
60
74
  return new Response(null, {
@@ -63,13 +77,18 @@ var worker = {
63
77
  });
64
78
  }
65
79
  if (error?.status && error?.body) {
66
- return new Response(JSON.stringify(error.body), {
80
+ return Response.json(error.body, {
67
81
  status: error.status,
68
82
  headers: { "Content-Type": "application/json" }
69
83
  });
70
84
  }
71
85
  console.error(`[Function] Error in ${method} handler:`, error);
72
- return new Response(JSON.stringify({ error: "Internal Server Error" }), {
86
+ const body = { error: "Internal Server Error" };
87
+ if (DEBUG_ERRORS) {
88
+ body.details = error?.message ?? String(error);
89
+ body.stack = error?.stack ?? "";
90
+ }
91
+ return Response.json(body, {
73
92
  status: 500,
74
93
  headers: { "Content-Type": "application/json" }
75
94
  });
@@ -1,9 +1,7 @@
1
- // src/worker.ts
1
+ // src/runtime/worker.ts
2
2
  import { Server, manifest, prerendered, base_path } from "SERVER";
3
- var server = new Server(manifest);
4
- var app_path = `/${manifest.appPath}`;
5
- var immutable = `${app_path}/immutable/`;
6
- var version_file = `${app_path}/version.json`;
3
+
4
+ // src/shims/caches.ts
7
5
  if (typeof caches === "undefined") {
8
6
  const noopCache = {
9
7
  match: async () => void 0,
@@ -16,6 +14,12 @@ if (typeof caches === "undefined") {
16
14
  open: async () => noopCache
17
15
  };
18
16
  }
17
+
18
+ // src/runtime/worker.ts
19
+ var server = new Server(manifest);
20
+ var app_path = `/${manifest.appPath}`;
21
+ var immutable = `${app_path}/immutable/`;
22
+ var version_file = `${app_path}/version.json`;
19
23
  var origin;
20
24
  var initialized = server.init({
21
25
  env: globalThis.env ?? {},
@@ -30,7 +34,6 @@ var initialized = server.init({
30
34
  });
31
35
  var worker = {
32
36
  async fetch(req, env, ctx) {
33
- globalThis.env = env;
34
37
  const proto = req.headers.get("x-forwarded-proto");
35
38
  if (proto && !req.url.startsWith(proto)) {
36
39
  req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
@@ -1,4 +1,4 @@
1
- // src/lib/async-hooks.ts
1
+ // src/shims/async-hooks.ts
2
2
  var AsyncLocalStorage = class {
3
3
  #store;
4
4
  run(store, fn, ...args) {
@@ -1,4 +1,4 @@
1
- // src/lib/node-fs.ts
1
+ // src/shims/node-fs.ts
2
2
  function existsSync() {
3
3
  return false;
4
4
  }
@@ -1,4 +1,4 @@
1
- // src/lib/node-path.ts
1
+ // src/shims/node-path.ts
2
2
  var sep = "/";
3
3
  function dirname(p) {
4
4
  return p.replace(/\/[^/]*$/, "") || "/";
@@ -1,4 +1,4 @@
1
- // src/lib/node-url.ts
1
+ // src/shims/node-url.ts
2
2
  function pathToFileURL(p) {
3
3
  return new URL(`file://${p}`);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/adapter-sveltekit",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "SvelteKit adapter for OpenWorkers",
5
5
  "keywords": [
6
6
  "adapter",
File without changes
File without changes