@eslym/sveltekit-adapter-bun 1.0.7 → 1.0.9
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 +272 -1
- package/dist/types.d.ts +52 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,6 +20,277 @@ import commonjs from "@rollup/plugin-commonjs";
|
|
|
20
20
|
import json from "@rollup/plugin-json";
|
|
21
21
|
import {join as join2} from "path/posix";
|
|
22
22
|
|
|
23
|
+
// node_modules/devalue/src/utils.js
|
|
24
|
+
function is_primitive(thing) {
|
|
25
|
+
return Object(thing) !== thing;
|
|
26
|
+
}
|
|
27
|
+
function is_plain_object(thing) {
|
|
28
|
+
const proto = Object.getPrototypeOf(thing);
|
|
29
|
+
return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
|
30
|
+
}
|
|
31
|
+
function get_type(thing) {
|
|
32
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
33
|
+
}
|
|
34
|
+
var get_escaped_char = function(char) {
|
|
35
|
+
switch (char) {
|
|
36
|
+
case '"':
|
|
37
|
+
return '\\"';
|
|
38
|
+
case "<":
|
|
39
|
+
return "\\u003C";
|
|
40
|
+
case "\\":
|
|
41
|
+
return "\\\\";
|
|
42
|
+
case "\n":
|
|
43
|
+
return "\\n";
|
|
44
|
+
case "\r":
|
|
45
|
+
return "\\r";
|
|
46
|
+
case "\t":
|
|
47
|
+
return "\\t";
|
|
48
|
+
case "\b":
|
|
49
|
+
return "\\b";
|
|
50
|
+
case "\f":
|
|
51
|
+
return "\\f";
|
|
52
|
+
case "\u2028":
|
|
53
|
+
return "\\u2028";
|
|
54
|
+
case "\u2029":
|
|
55
|
+
return "\\u2029";
|
|
56
|
+
default:
|
|
57
|
+
return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function stringify_string(str) {
|
|
61
|
+
let result = "";
|
|
62
|
+
let last_pos = 0;
|
|
63
|
+
const len = str.length;
|
|
64
|
+
for (let i = 0;i < len; i += 1) {
|
|
65
|
+
const char = str[i];
|
|
66
|
+
const replacement = get_escaped_char(char);
|
|
67
|
+
if (replacement) {
|
|
68
|
+
result += str.slice(last_pos, i) + replacement;
|
|
69
|
+
last_pos = i + 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
73
|
+
}
|
|
74
|
+
function enumerable_symbols(object) {
|
|
75
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable);
|
|
76
|
+
}
|
|
77
|
+
var escaped = {
|
|
78
|
+
"<": "\\u003C",
|
|
79
|
+
"\\": "\\\\",
|
|
80
|
+
"\b": "\\b",
|
|
81
|
+
"\f": "\\f",
|
|
82
|
+
"\n": "\\n",
|
|
83
|
+
"\r": "\\r",
|
|
84
|
+
"\t": "\\t",
|
|
85
|
+
"\u2028": "\\u2028",
|
|
86
|
+
"\u2029": "\\u2029"
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
class DevalueError extends Error {
|
|
90
|
+
constructor(message, keys) {
|
|
91
|
+
super(message);
|
|
92
|
+
this.name = "DevalueError";
|
|
93
|
+
this.path = keys.join("");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
var object_proto_names = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
97
|
+
|
|
98
|
+
// node_modules/devalue/src/uneval.js
|
|
99
|
+
function uneval(value, replacer) {
|
|
100
|
+
const counts = new Map;
|
|
101
|
+
const keys = [];
|
|
102
|
+
const custom = new Map;
|
|
103
|
+
function walk(thing) {
|
|
104
|
+
if (typeof thing === "function") {
|
|
105
|
+
throw new DevalueError(`Cannot stringify a function`, keys);
|
|
106
|
+
}
|
|
107
|
+
if (!is_primitive(thing)) {
|
|
108
|
+
if (counts.has(thing)) {
|
|
109
|
+
counts.set(thing, counts.get(thing) + 1);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
counts.set(thing, 1);
|
|
113
|
+
if (replacer) {
|
|
114
|
+
const str2 = replacer(thing);
|
|
115
|
+
if (typeof str2 === "string") {
|
|
116
|
+
custom.set(thing, str2);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const type = get_type(thing);
|
|
121
|
+
switch (type) {
|
|
122
|
+
case "Number":
|
|
123
|
+
case "BigInt":
|
|
124
|
+
case "String":
|
|
125
|
+
case "Boolean":
|
|
126
|
+
case "Date":
|
|
127
|
+
case "RegExp":
|
|
128
|
+
return;
|
|
129
|
+
case "Array":
|
|
130
|
+
thing.forEach((value2, i) => {
|
|
131
|
+
keys.push(`[${i}]`);
|
|
132
|
+
walk(value2);
|
|
133
|
+
keys.pop();
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
case "Set":
|
|
137
|
+
Array.from(thing).forEach(walk);
|
|
138
|
+
break;
|
|
139
|
+
case "Map":
|
|
140
|
+
for (const [key, value2] of thing) {
|
|
141
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
|
|
142
|
+
walk(value2);
|
|
143
|
+
keys.pop();
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
if (!is_plain_object(thing)) {
|
|
148
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys);
|
|
149
|
+
}
|
|
150
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
151
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys);
|
|
152
|
+
}
|
|
153
|
+
for (const key in thing) {
|
|
154
|
+
keys.push(`.${key}`);
|
|
155
|
+
walk(thing[key]);
|
|
156
|
+
keys.pop();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
walk(value);
|
|
162
|
+
const names = new Map;
|
|
163
|
+
Array.from(counts).filter((entry) => entry[1] > 1).sort((a, b) => b[1] - a[1]).forEach((entry, i) => {
|
|
164
|
+
names.set(entry[0], get_name(i));
|
|
165
|
+
});
|
|
166
|
+
function stringify(thing) {
|
|
167
|
+
if (names.has(thing)) {
|
|
168
|
+
return names.get(thing);
|
|
169
|
+
}
|
|
170
|
+
if (is_primitive(thing)) {
|
|
171
|
+
return stringify_primitive(thing);
|
|
172
|
+
}
|
|
173
|
+
if (custom.has(thing)) {
|
|
174
|
+
return custom.get(thing);
|
|
175
|
+
}
|
|
176
|
+
const type = get_type(thing);
|
|
177
|
+
switch (type) {
|
|
178
|
+
case "Number":
|
|
179
|
+
case "String":
|
|
180
|
+
case "Boolean":
|
|
181
|
+
return `Object(${stringify(thing.valueOf())})`;
|
|
182
|
+
case "RegExp":
|
|
183
|
+
return `new RegExp(${stringify_string(thing.source)}, "${thing.flags}")`;
|
|
184
|
+
case "Date":
|
|
185
|
+
return `new Date(${thing.getTime()})`;
|
|
186
|
+
case "Array":
|
|
187
|
+
const members = thing.map((v, i) => (i in thing) ? stringify(v) : "");
|
|
188
|
+
const tail = thing.length === 0 || thing.length - 1 in thing ? "" : ",";
|
|
189
|
+
return `[${members.join(",")}${tail}]`;
|
|
190
|
+
case "Set":
|
|
191
|
+
case "Map":
|
|
192
|
+
return `new ${type}([${Array.from(thing).map(stringify).join(",")}])`;
|
|
193
|
+
default:
|
|
194
|
+
const obj = `{${Object.keys(thing).map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(",")}}`;
|
|
195
|
+
const proto = Object.getPrototypeOf(thing);
|
|
196
|
+
if (proto === null) {
|
|
197
|
+
return Object.keys(thing).length > 0 ? `Object.assign(Object.create(null),${obj})` : `Object.create(null)`;
|
|
198
|
+
}
|
|
199
|
+
return obj;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const str = stringify(value);
|
|
203
|
+
if (names.size) {
|
|
204
|
+
const params = [];
|
|
205
|
+
const statements = [];
|
|
206
|
+
const values = [];
|
|
207
|
+
names.forEach((name2, thing) => {
|
|
208
|
+
params.push(name2);
|
|
209
|
+
if (custom.has(thing)) {
|
|
210
|
+
values.push(custom.get(thing));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (is_primitive(thing)) {
|
|
214
|
+
values.push(stringify_primitive(thing));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const type = get_type(thing);
|
|
218
|
+
switch (type) {
|
|
219
|
+
case "Number":
|
|
220
|
+
case "String":
|
|
221
|
+
case "Boolean":
|
|
222
|
+
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
223
|
+
break;
|
|
224
|
+
case "RegExp":
|
|
225
|
+
values.push(thing.toString());
|
|
226
|
+
break;
|
|
227
|
+
case "Date":
|
|
228
|
+
values.push(`new Date(${thing.getTime()})`);
|
|
229
|
+
break;
|
|
230
|
+
case "Array":
|
|
231
|
+
values.push(`Array(${thing.length})`);
|
|
232
|
+
thing.forEach((v, i) => {
|
|
233
|
+
statements.push(`${name2}[${i}]=${stringify(v)}`);
|
|
234
|
+
});
|
|
235
|
+
break;
|
|
236
|
+
case "Set":
|
|
237
|
+
values.push(`new Set`);
|
|
238
|
+
statements.push(`${name2}.${Array.from(thing).map((v) => `add(${stringify(v)})`).join(".")}`);
|
|
239
|
+
break;
|
|
240
|
+
case "Map":
|
|
241
|
+
values.push(`new Map`);
|
|
242
|
+
statements.push(`${name2}.${Array.from(thing).map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`).join(".")}`);
|
|
243
|
+
break;
|
|
244
|
+
default:
|
|
245
|
+
values.push(Object.getPrototypeOf(thing) === null ? "Object.create(null)" : "{}");
|
|
246
|
+
Object.keys(thing).forEach((key) => {
|
|
247
|
+
statements.push(`${name2}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
statements.push(`return ${str}`);
|
|
252
|
+
return `(function(${params.join(",")}){${statements.join(";")}}(${values.join(",")}))`;
|
|
253
|
+
} else {
|
|
254
|
+
return str;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
var get_name = function(num) {
|
|
258
|
+
let name2 = "";
|
|
259
|
+
do {
|
|
260
|
+
name2 = chars[num % chars.length] + name2;
|
|
261
|
+
num = ~~(num / chars.length) - 1;
|
|
262
|
+
} while (num >= 0);
|
|
263
|
+
return reserved.test(name2) ? `${name2}0` : name2;
|
|
264
|
+
};
|
|
265
|
+
var escape_unsafe_char = function(c) {
|
|
266
|
+
return escaped[c] || c;
|
|
267
|
+
};
|
|
268
|
+
var escape_unsafe_chars = function(str) {
|
|
269
|
+
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
270
|
+
};
|
|
271
|
+
var safe_key = function(key) {
|
|
272
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
273
|
+
};
|
|
274
|
+
var safe_prop = function(key) {
|
|
275
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? `.${key}` : `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
276
|
+
};
|
|
277
|
+
var stringify_primitive = function(thing) {
|
|
278
|
+
if (typeof thing === "string")
|
|
279
|
+
return stringify_string(thing);
|
|
280
|
+
if (thing === undefined)
|
|
281
|
+
return "void 0";
|
|
282
|
+
if (thing === 0 && 1 / thing < 0)
|
|
283
|
+
return "-0";
|
|
284
|
+
const str = String(thing);
|
|
285
|
+
if (typeof thing === "number")
|
|
286
|
+
return str.replace(/^(-)?0\./, "$1.");
|
|
287
|
+
if (typeof thing === "bigint")
|
|
288
|
+
return thing + "n";
|
|
289
|
+
return str;
|
|
290
|
+
};
|
|
291
|
+
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
|
|
292
|
+
var unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
293
|
+
var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
|
|
23
294
|
// src/symbols.ts
|
|
24
295
|
var symServer = Symbol.for(`${name}/server`);
|
|
25
296
|
var symUpgrades = Symbol.for(`${name}/upgrades`);
|
|
@@ -376,7 +647,7 @@ function adapter(userOpts = {}) {
|
|
|
376
647
|
delete pkg.devDependencies;
|
|
377
648
|
writeFileSync(`${out}/package.json`, JSON.stringify(pkg, null, 2) + "\n");
|
|
378
649
|
if (opts.exportPrerender) {
|
|
379
|
-
const js = `export const paths = ${
|
|
650
|
+
const js = `export const paths = ${uneval(builder.prerendered.paths)};\n` + `export const prerendered = ${uneval(builder.prerendered.pages)};\n` + `export const assets = ${uneval(builder.prerendered.assets)};\n` + `export const redirects = ${uneval(builder.prerendered.redirects)};\n` + `export default { paths, prerendered, assets, redirects };\n`;
|
|
380
651
|
writeFileSync(`${out}/prerendered.js`, "//@bun\n" + transpiler.transformSync(js));
|
|
381
652
|
}
|
|
382
653
|
builder.log.success(`Build done.`);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
/// <reference types="bun-types" />
|
|
3
|
-
import type { WebSocketHandler as BunWSHandler } from 'bun';
|
|
4
|
+
import type { WebSocketHandler as BunWSHandler, ServerWebSocket } from 'bun';
|
|
4
5
|
import type { Server } from 'bun';
|
|
5
6
|
export type ServeOptions = {
|
|
6
7
|
port: number;
|
|
@@ -13,7 +14,55 @@ export type ServeOptions = {
|
|
|
13
14
|
xffDepth?: number;
|
|
14
15
|
};
|
|
15
16
|
export type WebSocketOptions = Omit<BunWSHandler, 'message' | 'open' | 'close' | 'ping' | 'pong' | 'drain'>;
|
|
16
|
-
export
|
|
17
|
+
export interface WebSocketHandler {
|
|
18
|
+
/**
|
|
19
|
+
* Called when the server receives an incoming message.
|
|
20
|
+
*
|
|
21
|
+
* If the message is not a `string`, its type is based on the value of `binaryType`.
|
|
22
|
+
* - if `nodebuffer`, then the message is a `Buffer`.
|
|
23
|
+
* - if `arraybuffer`, then the message is an `ArrayBuffer`.
|
|
24
|
+
* - if `uint8array`, then the message is a `Uint8Array`.
|
|
25
|
+
*
|
|
26
|
+
* @param ws The websocket that sent the message
|
|
27
|
+
* @param message The message received
|
|
28
|
+
*/
|
|
29
|
+
message(ws: ServerWebSocket<this>, message: string | Buffer): void | Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Called when a connection is opened.
|
|
32
|
+
*
|
|
33
|
+
* @param ws The websocket that was opened
|
|
34
|
+
*/
|
|
35
|
+
open?(ws: ServerWebSocket<this>): void | Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Called when a connection was previously under backpressure,
|
|
38
|
+
* meaning it had too many queued messages, but is now ready to receive more data.
|
|
39
|
+
*
|
|
40
|
+
* @param ws The websocket that is ready for more data
|
|
41
|
+
*/
|
|
42
|
+
drain?(ws: ServerWebSocket<this>): void | Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Called when a connection is closed.
|
|
45
|
+
*
|
|
46
|
+
* @param ws The websocket that was closed
|
|
47
|
+
* @param code The close code
|
|
48
|
+
* @param message The close message
|
|
49
|
+
*/
|
|
50
|
+
close?(ws: ServerWebSocket<this>, code: number, reason: string): void | Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Called when a ping is sent.
|
|
53
|
+
*
|
|
54
|
+
* @param ws The websocket that received the ping
|
|
55
|
+
* @param data The data sent with the ping
|
|
56
|
+
*/
|
|
57
|
+
ping?(ws: ServerWebSocket<this>, data: Buffer): void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Called when a pong is received.
|
|
60
|
+
*
|
|
61
|
+
* @param ws The websocket that received the ping
|
|
62
|
+
* @param data The data sent with the ping
|
|
63
|
+
*/
|
|
64
|
+
pong?(ws: ServerWebSocket<this>, data: Buffer): void | Promise<void>;
|
|
65
|
+
}
|
|
17
66
|
export interface AdapterPlatform {
|
|
18
67
|
/**
|
|
19
68
|
* The original request received from Bun.serve
|
|
@@ -32,7 +81,7 @@ export interface AdapterPlatform {
|
|
|
32
81
|
* @param response The response to mark
|
|
33
82
|
* @param ws The websocket handler
|
|
34
83
|
*/
|
|
35
|
-
markForUpgrade(response: Response, ws: WebSocketHandler
|
|
84
|
+
markForUpgrade(response: Response, ws: WebSocketHandler): Response;
|
|
36
85
|
}
|
|
37
86
|
export type PreCompressOptions = {
|
|
38
87
|
[k in 'gzip' | 'brotli']?: boolean;
|
package/package.json
CHANGED