@openworkers/adapter-sveltekit 0.4.1 → 0.4.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/dist/index.js CHANGED
@@ -156,7 +156,7 @@ async function buildFunctionWorker(options) {
156
156
  const adapterRoot = urlPath.includes("/dist/") ? fileURLToPath(new URL("..", import.meta.url)) : fileURLToPath(new URL("../..", import.meta.url));
157
157
  const files = path.join(adapterRoot, "dist");
158
158
  const functionTemplate = path.join(files, "function-worker.js");
159
- const libCookies = path.join(files, "../src/lib/cookies.js");
159
+ const libCookies = path.join(files, "lib/cookies.js");
160
160
  const svelteKitCookie = path.join(process.cwd(), "node_modules/@sveltejs/kit/src/runtime/server/cookie.js");
161
161
  const svelteKitRouting = path.join(process.cwd(), "node_modules/@sveltejs/kit/src/utils/routing.js");
162
162
  const external = ["node:*"];
@@ -0,0 +1,413 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // node_modules/cookie/index.js
28
+ var require_cookie = __commonJS({
29
+ "node_modules/cookie/index.js"(exports) {
30
+ "use strict";
31
+ exports.parse = parse2;
32
+ exports.serialize = serialize2;
33
+ var __toString = Object.prototype.toString;
34
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
35
+ function parse2(str, options) {
36
+ if (typeof str !== "string") {
37
+ throw new TypeError("argument str must be a string");
38
+ }
39
+ var obj = {};
40
+ var opt = options || {};
41
+ var dec = opt.decode || decode;
42
+ var index = 0;
43
+ while (index < str.length) {
44
+ var eqIdx = str.indexOf("=", index);
45
+ if (eqIdx === -1) {
46
+ break;
47
+ }
48
+ var endIdx = str.indexOf(";", index);
49
+ if (endIdx === -1) {
50
+ endIdx = str.length;
51
+ } else if (endIdx < eqIdx) {
52
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
53
+ continue;
54
+ }
55
+ var key = str.slice(index, eqIdx).trim();
56
+ if (void 0 === obj[key]) {
57
+ var val = str.slice(eqIdx + 1, endIdx).trim();
58
+ if (val.charCodeAt(0) === 34) {
59
+ val = val.slice(1, -1);
60
+ }
61
+ obj[key] = tryDecode(val, dec);
62
+ }
63
+ index = endIdx + 1;
64
+ }
65
+ return obj;
66
+ }
67
+ function serialize2(name, val, options) {
68
+ var opt = options || {};
69
+ var enc = opt.encode || encode;
70
+ if (typeof enc !== "function") {
71
+ throw new TypeError("option encode is invalid");
72
+ }
73
+ if (!fieldContentRegExp.test(name)) {
74
+ throw new TypeError("argument name is invalid");
75
+ }
76
+ var value = enc(val);
77
+ if (value && !fieldContentRegExp.test(value)) {
78
+ throw new TypeError("argument val is invalid");
79
+ }
80
+ var str = name + "=" + value;
81
+ if (null != opt.maxAge) {
82
+ var maxAge = opt.maxAge - 0;
83
+ if (isNaN(maxAge) || !isFinite(maxAge)) {
84
+ throw new TypeError("option maxAge is invalid");
85
+ }
86
+ str += "; Max-Age=" + Math.floor(maxAge);
87
+ }
88
+ if (opt.domain) {
89
+ if (!fieldContentRegExp.test(opt.domain)) {
90
+ throw new TypeError("option domain is invalid");
91
+ }
92
+ str += "; Domain=" + opt.domain;
93
+ }
94
+ if (opt.path) {
95
+ if (!fieldContentRegExp.test(opt.path)) {
96
+ throw new TypeError("option path is invalid");
97
+ }
98
+ str += "; Path=" + opt.path;
99
+ }
100
+ if (opt.expires) {
101
+ var expires = opt.expires;
102
+ if (!isDate(expires) || isNaN(expires.valueOf())) {
103
+ throw new TypeError("option expires is invalid");
104
+ }
105
+ str += "; Expires=" + expires.toUTCString();
106
+ }
107
+ if (opt.httpOnly) {
108
+ str += "; HttpOnly";
109
+ }
110
+ if (opt.secure) {
111
+ str += "; Secure";
112
+ }
113
+ if (opt.partitioned) {
114
+ str += "; Partitioned";
115
+ }
116
+ if (opt.priority) {
117
+ var priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
118
+ switch (priority) {
119
+ case "low":
120
+ str += "; Priority=Low";
121
+ break;
122
+ case "medium":
123
+ str += "; Priority=Medium";
124
+ break;
125
+ case "high":
126
+ str += "; Priority=High";
127
+ break;
128
+ default:
129
+ throw new TypeError("option priority is invalid");
130
+ }
131
+ }
132
+ if (opt.sameSite) {
133
+ var sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
134
+ switch (sameSite) {
135
+ case true:
136
+ str += "; SameSite=Strict";
137
+ break;
138
+ case "lax":
139
+ str += "; SameSite=Lax";
140
+ break;
141
+ case "strict":
142
+ str += "; SameSite=Strict";
143
+ break;
144
+ case "none":
145
+ str += "; SameSite=None";
146
+ break;
147
+ default:
148
+ throw new TypeError("option sameSite is invalid");
149
+ }
150
+ }
151
+ return str;
152
+ }
153
+ function decode(str) {
154
+ return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
155
+ }
156
+ function encode(val) {
157
+ return encodeURIComponent(val);
158
+ }
159
+ function isDate(val) {
160
+ return __toString.call(val) === "[object Date]" || val instanceof Date;
161
+ }
162
+ function tryDecode(str, decode2) {
163
+ try {
164
+ return decode2(str);
165
+ } catch (e) {
166
+ return str;
167
+ }
168
+ }
169
+ }
170
+ });
171
+
172
+ // node_modules/@sveltejs/kit/src/runtime/server/cookie.js
173
+ var import_cookie = __toESM(require_cookie(), 1);
174
+
175
+ // node_modules/esm-env/dev-fallback.js
176
+ var node_env = globalThis.process?.env?.NODE_ENV;
177
+ var dev_fallback_default = node_env && !node_env.toLowerCase().startsWith("prod");
178
+
179
+ // node_modules/@sveltejs/kit/src/utils/url.js
180
+ var internal = new URL("sveltekit-internal://");
181
+ function resolve(base, path) {
182
+ if (path[0] === "/" && path[1] === "/") return path;
183
+ let url = new URL(base, internal);
184
+ url = new URL(path, url);
185
+ return url.protocol === internal.protocol ? url.pathname + url.search + url.hash : url.href;
186
+ }
187
+ function normalize_path(path, trailing_slash) {
188
+ if (path === "/" || trailing_slash === "ignore") return path;
189
+ if (trailing_slash === "never") {
190
+ return path.endsWith("/") ? path.slice(0, -1) : path;
191
+ } else if (trailing_slash === "always" && !path.endsWith("/")) {
192
+ return path + "/";
193
+ }
194
+ return path;
195
+ }
196
+
197
+ // node_modules/@sveltejs/kit/src/runtime/pathname.js
198
+ var DATA_SUFFIX = "/__data.json";
199
+ var HTML_DATA_SUFFIX = ".html__data.json";
200
+ function add_data_suffix(pathname) {
201
+ if (pathname.endsWith(".html")) return pathname.replace(/\.html$/, HTML_DATA_SUFFIX);
202
+ return pathname.replace(/\/$/, "") + DATA_SUFFIX;
203
+ }
204
+
205
+ // node_modules/@sveltejs/kit/src/runtime/utils.js
206
+ var text_encoder = new TextEncoder();
207
+ var text_decoder = new TextDecoder();
208
+
209
+ // node_modules/@sveltejs/kit/src/runtime/server/cookie.js
210
+ var INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
211
+ var cookie_paths = {};
212
+ var MAX_COOKIE_SIZE = 4129;
213
+ function validate_options(options) {
214
+ if (options?.path === void 0) {
215
+ throw new Error("You must specify a `path` when setting, deleting or serializing cookies");
216
+ }
217
+ }
218
+ function generate_cookie_key(domain, path, name) {
219
+ return `${domain || ""}${path}?${encodeURIComponent(name)}`;
220
+ }
221
+ function get_cookies(request, url) {
222
+ const header = request.headers.get("cookie") ?? "";
223
+ const initial_cookies = (0, import_cookie.parse)(header, { decode: (value) => value });
224
+ let normalized_url;
225
+ const new_cookies = /* @__PURE__ */ new Map();
226
+ const defaults = {
227
+ httpOnly: true,
228
+ sameSite: "lax",
229
+ secure: url.hostname === "localhost" && url.protocol === "http:" ? false : true
230
+ };
231
+ const cookies = {
232
+ // The JSDoc param annotations appearing below for get, set and delete
233
+ // are necessary to expose the `cookie` library types to
234
+ // typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
235
+ // sufficient to do so.
236
+ /**
237
+ * @param {string} name
238
+ * @param {import('cookie').CookieParseOptions} [opts]
239
+ */
240
+ get(name, opts) {
241
+ const best_match = Array.from(new_cookies.values()).filter((c) => {
242
+ return c.name === name && domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path);
243
+ }).sort((a, b) => b.options.path.length - a.options.path.length)[0];
244
+ if (best_match) {
245
+ return best_match.options.maxAge === 0 ? void 0 : best_match.value;
246
+ }
247
+ const req_cookies = (0, import_cookie.parse)(header, { decode: opts?.decode });
248
+ const cookie = req_cookies[name];
249
+ if (dev_fallback_default && !cookie) {
250
+ const paths = Array.from(cookie_paths[name] ?? []).filter((path) => {
251
+ return path_matches(path, url.pathname) && path !== url.pathname;
252
+ });
253
+ if (paths.length > 0) {
254
+ console.warn(
255
+ // prettier-ignore
256
+ `'${name}' cookie does not exist for ${url.pathname}, but was previously set at ${conjoin([...paths])}. Did you mean to set its 'path' to '/' instead?`
257
+ );
258
+ }
259
+ }
260
+ return cookie;
261
+ },
262
+ /**
263
+ * @param {import('cookie').CookieParseOptions} [opts]
264
+ */
265
+ getAll(opts) {
266
+ const cookies2 = (0, import_cookie.parse)(header, { decode: opts?.decode });
267
+ const lookup = /* @__PURE__ */ new Map();
268
+ for (const c of new_cookies.values()) {
269
+ if (domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path)) {
270
+ const existing = lookup.get(c.name);
271
+ if (!existing || c.options.path.length > existing.options.path.length) {
272
+ lookup.set(c.name, c);
273
+ }
274
+ }
275
+ }
276
+ for (const c of lookup.values()) {
277
+ cookies2[c.name] = c.value;
278
+ }
279
+ return Object.entries(cookies2).map(([name, value]) => ({ name, value }));
280
+ },
281
+ /**
282
+ * @param {string} name
283
+ * @param {string} value
284
+ * @param {import('./page/types.js').Cookie['options']} options
285
+ */
286
+ set(name, value, options) {
287
+ const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
288
+ if (illegal_characters) {
289
+ console.warn(
290
+ `The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
291
+ " and "
292
+ )}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
293
+ );
294
+ }
295
+ validate_options(options);
296
+ set_internal(name, value, { ...defaults, ...options });
297
+ },
298
+ /**
299
+ * @param {string} name
300
+ * @param {import('./page/types.js').Cookie['options']} options
301
+ */
302
+ delete(name, options) {
303
+ validate_options(options);
304
+ cookies.set(name, "", { ...options, maxAge: 0 });
305
+ },
306
+ /**
307
+ * @param {string} name
308
+ * @param {string} value
309
+ * @param {import('./page/types.js').Cookie['options']} options
310
+ */
311
+ serialize(name, value, options) {
312
+ validate_options(options);
313
+ let path = options.path;
314
+ if (!options.domain || options.domain === url.hostname) {
315
+ if (!normalized_url) {
316
+ throw new Error("Cannot serialize cookies until after the route is determined");
317
+ }
318
+ path = resolve(normalized_url, path);
319
+ }
320
+ return (0, import_cookie.serialize)(name, value, { ...defaults, ...options, path });
321
+ }
322
+ };
323
+ function get_cookie_header(destination, header2) {
324
+ const combined_cookies = {
325
+ // cookies sent by the user agent have lowest precedence
326
+ ...initial_cookies
327
+ };
328
+ for (const cookie of new_cookies.values()) {
329
+ if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
330
+ if (!path_matches(destination.pathname, cookie.options.path)) continue;
331
+ const encoder = cookie.options.encode || encodeURIComponent;
332
+ combined_cookies[cookie.name] = encoder(cookie.value);
333
+ }
334
+ if (header2) {
335
+ const parsed = (0, import_cookie.parse)(header2, { decode: (value) => value });
336
+ for (const name in parsed) {
337
+ combined_cookies[name] = parsed[name];
338
+ }
339
+ }
340
+ return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
341
+ }
342
+ const internal_queue = [];
343
+ function set_internal(name, value, options) {
344
+ if (!normalized_url) {
345
+ internal_queue.push(() => set_internal(name, value, options));
346
+ return;
347
+ }
348
+ let path = options.path;
349
+ if (!options.domain || options.domain === url.hostname) {
350
+ path = resolve(normalized_url, path);
351
+ }
352
+ const cookie_key = generate_cookie_key(options.domain, path, name);
353
+ const cookie = { name, value, options: { ...options, path } };
354
+ new_cookies.set(cookie_key, cookie);
355
+ if (dev_fallback_default) {
356
+ const serialized = (0, import_cookie.serialize)(name, value, cookie.options);
357
+ if (text_encoder.encode(serialized).byteLength > MAX_COOKIE_SIZE) {
358
+ throw new Error(`Cookie "${name}" is too large, and will be discarded by the browser`);
359
+ }
360
+ cookie_paths[name] ??= /* @__PURE__ */ new Set();
361
+ if (!value) {
362
+ cookie_paths[name].delete(path);
363
+ } else {
364
+ cookie_paths[name].add(path);
365
+ }
366
+ }
367
+ }
368
+ function set_trailing_slash(trailing_slash) {
369
+ normalized_url = normalize_path(url.pathname, trailing_slash);
370
+ internal_queue.forEach((fn) => fn());
371
+ }
372
+ return { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash };
373
+ }
374
+ function domain_matches(hostname, constraint) {
375
+ if (!constraint) return true;
376
+ const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
377
+ if (hostname === normalized) return true;
378
+ return hostname.endsWith("." + normalized);
379
+ }
380
+ function path_matches(path, constraint) {
381
+ if (!constraint) return true;
382
+ const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
383
+ if (path === normalized) return true;
384
+ return path.startsWith(normalized + "/");
385
+ }
386
+ function add_cookies_to_headers(headers, cookies) {
387
+ for (const new_cookie of cookies) {
388
+ const { name, value, options } = new_cookie;
389
+ headers.append("set-cookie", (0, import_cookie.serialize)(name, value, options));
390
+ if (options.path.endsWith(".html")) {
391
+ const path = add_data_suffix(options.path);
392
+ headers.append("set-cookie", (0, import_cookie.serialize)(name, value, { ...options, path }));
393
+ }
394
+ }
395
+ }
396
+ function conjoin(array) {
397
+ if (array.length <= 2) return array.join(" and ");
398
+ return `${array.slice(0, -1).join(", ")} and ${array.at(-1)}`;
399
+ }
400
+ export {
401
+ add_cookies_to_headers as addCookiesToHeaders,
402
+ get_cookies as getCookies
403
+ };
404
+ /*! Bundled license information:
405
+
406
+ cookie/index.js:
407
+ (*!
408
+ * cookie
409
+ * Copyright(c) 2012-2014 Roman Shtylman
410
+ * Copyright(c) 2015 Douglas Christopher Wilson
411
+ * MIT Licensed
412
+ *)
413
+ */
@@ -0,0 +1,127 @@
1
+ // node_modules/esm-env/true.js
2
+ var true_default = true;
3
+
4
+ // node_modules/esm-env/dev-fallback.js
5
+ var node_env = globalThis.process?.env?.NODE_ENV;
6
+ var dev_fallback_default = node_env && !node_env.toLowerCase().startsWith("prod");
7
+
8
+ // node_modules/@sveltejs/kit/src/utils/routing.js
9
+ var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
10
+ function parse_route_id(id) {
11
+ const params = [];
12
+ const pattern = id === "/" ? /^\/$/ : new RegExp(
13
+ `^${get_route_segments(id).map((segment) => {
14
+ const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
15
+ if (rest_match) {
16
+ params.push({
17
+ name: rest_match[1],
18
+ matcher: rest_match[2],
19
+ optional: false,
20
+ rest: true,
21
+ chained: true
22
+ });
23
+ return "(?:/([^]*))?";
24
+ }
25
+ const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
26
+ if (optional_match) {
27
+ params.push({
28
+ name: optional_match[1],
29
+ matcher: optional_match[2],
30
+ optional: true,
31
+ rest: false,
32
+ chained: true
33
+ });
34
+ return "(?:/([^/]+))?";
35
+ }
36
+ if (!segment) {
37
+ return;
38
+ }
39
+ const parts = segment.split(/\[(.+?)\](?!\])/);
40
+ const result = parts.map((content, i) => {
41
+ if (i % 2) {
42
+ if (content.startsWith("x+")) {
43
+ return escape(String.fromCharCode(parseInt(content.slice(2), 16)));
44
+ }
45
+ if (content.startsWith("u+")) {
46
+ return escape(
47
+ String.fromCharCode(
48
+ ...content.slice(2).split("-").map((code) => parseInt(code, 16))
49
+ )
50
+ );
51
+ }
52
+ const match = (
53
+ /** @type {RegExpExecArray} */
54
+ param_pattern.exec(content)
55
+ );
56
+ if (!true_default && !match) {
57
+ throw new Error(
58
+ `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
59
+ );
60
+ }
61
+ const [, is_optional, is_rest, name, matcher] = match;
62
+ params.push({
63
+ name,
64
+ matcher,
65
+ optional: !!is_optional,
66
+ rest: !!is_rest,
67
+ chained: is_rest ? i === 1 && parts[0] === "" : false
68
+ });
69
+ return is_rest ? "([^]*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
70
+ }
71
+ return escape(content);
72
+ }).join("");
73
+ return "/" + result;
74
+ }).join("")}/?$`
75
+ );
76
+ return { pattern, params };
77
+ }
78
+ function affects_path(segment) {
79
+ return segment !== "" && !/^\([^)]+\)$/.test(segment);
80
+ }
81
+ function get_route_segments(route) {
82
+ return route.slice(1).split("/").filter(affects_path);
83
+ }
84
+ function exec(match, params, matchers) {
85
+ const result = {};
86
+ const values = match.slice(1);
87
+ const values_needing_match = values.filter((value) => value !== void 0);
88
+ let buffered = 0;
89
+ for (let i = 0; i < params.length; i += 1) {
90
+ const param = params[i];
91
+ let value = values[i - buffered];
92
+ if (param.chained && param.rest && buffered) {
93
+ value = values.slice(i - buffered, i + 1).filter((s) => s).join("/");
94
+ buffered = 0;
95
+ }
96
+ if (value === void 0) {
97
+ if (param.rest) result[param.name] = "";
98
+ continue;
99
+ }
100
+ if (!param.matcher || matchers[param.matcher](value)) {
101
+ result[param.name] = value;
102
+ const next_param = params[i + 1];
103
+ const next_value = values[i + 1];
104
+ if (next_param && !next_param.rest && next_param.optional && next_value && param.chained) {
105
+ buffered = 0;
106
+ }
107
+ if (!next_param && !next_value && Object.keys(result).length === values_needing_match.length) {
108
+ buffered = 0;
109
+ }
110
+ continue;
111
+ }
112
+ if (param.optional && param.chained) {
113
+ buffered++;
114
+ continue;
115
+ }
116
+ return;
117
+ }
118
+ if (buffered) return;
119
+ return result;
120
+ }
121
+ function escape(str) {
122
+ return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
123
+ }
124
+ export {
125
+ exec as execRouteMatch,
126
+ parse_route_id as parseRouteId
127
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/adapter-sveltekit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "SvelteKit adapter for OpenWorkers",
5
5
  "keywords": [
6
6
  "adapter",