elysia 2.0.0-beta.4 → 2.0.0-beta.6
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/adapter/bun/index.js +52 -59
- package/dist/adapter/bun/index.mjs +53 -60
- package/dist/adapter/utils.js +0 -6
- package/dist/adapter/utils.mjs +0 -6
- package/dist/base.d.ts +25 -9
- package/dist/base.js +175 -198
- package/dist/base.mjs +175 -198
- package/dist/compile/aot-capture.js +1 -1
- package/dist/compile/aot-capture.mjs +1 -1
- package/dist/compile/aot.d.ts +5 -5
- package/dist/compile/handler/index.js +4 -0
- package/dist/compile/handler/index.mjs +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +16 -37
- package/dist/plugin/aot/core.js +21 -39
- package/dist/plugin/aot/core.mjs +22 -41
- package/dist/sucrose.js +6 -0
- package/dist/sucrose.mjs +6 -0
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/coerce-plan.d.ts +1 -1
- package/dist/type/coerce-plan.js +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +2 -2
- package/dist/type/coerce.js +1 -1
- package/dist/type/coerce.mjs +2 -2
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +10 -1
- package/dist/type/validator/index.mjs +10 -1
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/types.d.ts +46 -8
- package/dist/ws/route.js +36 -9
- package/dist/ws/route.mjs +37 -10
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_adapter_index = require('../index.js');
|
|
3
|
-
const require_constants = require('../../constants.js');
|
|
4
3
|
const require_utils = require('../../utils.js');
|
|
5
4
|
const require_adapter_web_standard_index = require('../web-standard/index.js');
|
|
6
5
|
const require_generation = require('../../generation.js');
|
|
@@ -97,6 +96,7 @@ const withOrigin = (fetch) => (request, server) => {
|
|
|
97
96
|
require_adapter_origin.origin.request = void 0;
|
|
98
97
|
}
|
|
99
98
|
};
|
|
99
|
+
const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
|
|
100
100
|
function collectStaticRoutes(app) {
|
|
101
101
|
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
102
102
|
app.fetch;
|
|
@@ -106,66 +106,57 @@ function collectStaticRoutes(app) {
|
|
|
106
106
|
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
107
107
|
const length = table?.length ?? 0;
|
|
108
108
|
if (!table || !length) return;
|
|
109
|
-
const { method: methods, path: paths, handler: handlers } = table;
|
|
110
|
-
const nativeStaticMethods = new Set([
|
|
111
|
-
"GET",
|
|
112
|
-
"POST",
|
|
113
|
-
"PUT",
|
|
114
|
-
"DELETE",
|
|
115
|
-
"PATCH",
|
|
116
|
-
"HEAD",
|
|
117
|
-
"OPTIONS"
|
|
118
|
-
]);
|
|
109
|
+
const { method: methods, path: paths, handler: handlers, flags } = table;
|
|
119
110
|
let hasCandidate = false;
|
|
120
111
|
for (let i = 0; i < length; i++) {
|
|
112
|
+
if (!isNativeStaticMethod(methods[i]) || (flags[i] & require_route_table.RouteFlag.Dynamic) !== 0) continue;
|
|
121
113
|
const h = handlers[i];
|
|
122
|
-
if (typeof h
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
if (typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
115
|
+
hasCandidate = true;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
126
118
|
}
|
|
127
119
|
if (!hasCandidate) return;
|
|
128
|
-
const ready = require_utils.nullObject();
|
|
129
120
|
const strictPath = frozenRoot["~config"]?.strictPath === true;
|
|
130
|
-
const
|
|
131
|
-
for (let i = 0; i < length; i++)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (require_constants.needEncodeRegex.test(path)) {
|
|
142
|
-
const encoded = encodeURI(path);
|
|
143
|
-
if (encoded !== path) set.add(encoded);
|
|
144
|
-
}
|
|
121
|
+
const routeIndex = /* @__PURE__ */ new Map();
|
|
122
|
+
for (let i = 0; i < length; i++) {
|
|
123
|
+
const method = methods[i];
|
|
124
|
+
if (!isNativeStaticMethod(method) || (flags[i] & require_route_table.RouteFlag.Dynamic) !== 0) continue;
|
|
125
|
+
const path = paths[i];
|
|
126
|
+
let pathsByMethod = routeIndex.get(method);
|
|
127
|
+
if (!pathsByMethod) routeIndex.set(method, pathsByMethod = /* @__PURE__ */ new Map());
|
|
128
|
+
pathsByMethod.set(path, i);
|
|
129
|
+
if (!strictPath && (flags[i] & require_route_table.RouteFlag.Encode) !== 0) {
|
|
130
|
+
const encoded = encodeURI(path);
|
|
131
|
+
if (encoded !== path && !pathsByMethod.has(encoded)) pathsByMethod.set(encoded, -1);
|
|
145
132
|
}
|
|
146
133
|
}
|
|
147
|
-
const
|
|
148
|
-
|
|
134
|
+
const ready = require_utils.nullObject();
|
|
135
|
+
let hasReady = false;
|
|
136
|
+
const add = (method, path, value, needsEncode) => {
|
|
137
|
+
if (needsEncode) path = encodeURI(path);
|
|
149
138
|
(ready[path] ??= require_utils.nullObject())[method] = value;
|
|
139
|
+
hasReady = true;
|
|
150
140
|
};
|
|
151
141
|
for (let i = 0; i < length; i++) {
|
|
152
142
|
const method = methods[i];
|
|
153
|
-
|
|
143
|
+
const routeFlags = flags[i];
|
|
144
|
+
if (!isNativeStaticMethod(method) || (routeFlags & require_route_table.RouteFlag.Dynamic) !== 0) continue;
|
|
145
|
+
const pathsByMethod = routeIndex.get(method);
|
|
154
146
|
const path = paths[i];
|
|
155
|
-
if (
|
|
156
|
-
if (!nativeStaticMethods.has(method)) continue;
|
|
157
|
-
if (require_constants.isDynamicRegex.test(path)) continue;
|
|
147
|
+
if (pathsByMethod.get(path) !== i) continue;
|
|
158
148
|
const h = handlers[i];
|
|
159
149
|
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
160
150
|
const value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
|
|
161
151
|
if (!value) continue;
|
|
162
|
-
|
|
152
|
+
const needsEncode = (routeFlags & require_route_table.RouteFlag.Encode) !== 0;
|
|
153
|
+
add(method, path, value, needsEncode);
|
|
163
154
|
if (!strictPath) {
|
|
164
155
|
const loose = require_utils.getLoosePath(path);
|
|
165
|
-
if (loose !== path && !
|
|
156
|
+
if (loose !== path && !pathsByMethod.has(loose)) add(method, loose, value, needsEncode);
|
|
166
157
|
}
|
|
167
158
|
}
|
|
168
|
-
if (!
|
|
159
|
+
if (!hasReady) return;
|
|
169
160
|
return ready;
|
|
170
161
|
}
|
|
171
162
|
const BunAdapter = require_adapter_index.createAdapter({
|
|
@@ -176,31 +167,40 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
176
167
|
response: require_adapter_web_standard_index.WebStandardAdapter.response,
|
|
177
168
|
listen(app, options, callback) {
|
|
178
169
|
if (app.server || app["~ext"]?.stop) throw new Error("[Elysia] Cannot call listen() while a server or teardown is active");
|
|
179
|
-
|
|
170
|
+
function gatedFetch(request, server) {
|
|
171
|
+
return live ? live(request, server) : Promise.resolve(ready).then(async () => {
|
|
172
|
+
if (!live) {
|
|
173
|
+
await startupShutdown;
|
|
174
|
+
throw new Error("[Elysia] Server was stopped before it was ready");
|
|
175
|
+
}
|
|
176
|
+
return live(request, server);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
180
179
|
const optionsIsObject = typeof options === "object";
|
|
181
|
-
let live;
|
|
182
|
-
let cancelled = false;
|
|
183
|
-
let startupShutdown;
|
|
184
|
-
let shutdownAttempt;
|
|
185
|
-
const gatedFetch = (request, server) => live ? live(request, server) : Promise.resolve(ready).then(async () => {
|
|
186
|
-
if (!live) {
|
|
187
|
-
await startupShutdown;
|
|
188
|
-
throw new Error("[Elysia] Server was stopped before it was ready");
|
|
189
|
-
}
|
|
190
|
-
return live(request, server);
|
|
191
|
-
});
|
|
192
180
|
const _options = optionsIsObject ? { ...options } : {
|
|
193
181
|
port: +options,
|
|
194
182
|
fetch: gatedFetch
|
|
195
183
|
};
|
|
196
184
|
if (optionsIsObject) _options.fetch = gatedFetch;
|
|
185
|
+
const _config = app["~config"]?.serve;
|
|
197
186
|
const serve = _config ? {
|
|
198
187
|
..._config,
|
|
199
188
|
..._options
|
|
200
189
|
} : _options;
|
|
190
|
+
const server = app.server = Bun.serve(serve.routes || serve.error ? {
|
|
191
|
+
...serve,
|
|
192
|
+
error: unavailableFetch,
|
|
193
|
+
routes: {}
|
|
194
|
+
} : serve);
|
|
195
|
+
let live;
|
|
196
|
+
let cancelled = false;
|
|
197
|
+
let startupShutdown;
|
|
198
|
+
let shutdownAttempt;
|
|
201
199
|
let ready;
|
|
202
200
|
let wsLifecycle;
|
|
203
201
|
let modulesReady;
|
|
202
|
+
let built;
|
|
203
|
+
let pendingSetups;
|
|
204
204
|
const build = () => {
|
|
205
205
|
const fetch = app.fetch;
|
|
206
206
|
let routes;
|
|
@@ -231,13 +231,6 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
231
231
|
websocket
|
|
232
232
|
};
|
|
233
233
|
};
|
|
234
|
-
let built;
|
|
235
|
-
let pendingSetups;
|
|
236
|
-
const server = app.server = Bun.serve(serve.routes || serve.error ? {
|
|
237
|
-
...serve,
|
|
238
|
-
error: unavailableFetch,
|
|
239
|
-
routes: {}
|
|
240
|
-
} : serve);
|
|
241
234
|
let startupFailure;
|
|
242
235
|
let forceRequested = false;
|
|
243
236
|
let forceDone = false;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createAdapter } from "../index.mjs";
|
|
2
|
-
import { isDynamicRegex, needEncodeRegex } from "../../constants.mjs";
|
|
3
2
|
import { flattenChain, getLoosePath, isSocketQuiet, nullObject, throwLifecycleErrors } from "../../utils.mjs";
|
|
4
3
|
import { WebStandardAdapter } from "../web-standard/index.mjs";
|
|
5
4
|
import { frozenRootOf, resolvedWsOf } from "../../generation.mjs";
|
|
6
5
|
import { origin } from "../origin.mjs";
|
|
7
6
|
import { buildNativeStaticResponse } from "../../compile/handler/index.mjs";
|
|
8
|
-
import { routeRow } from "../../route-table.mjs";
|
|
7
|
+
import { RouteFlag, routeRow } from "../../route-table.mjs";
|
|
9
8
|
|
|
10
9
|
//#region src/adapter/bun/index.ts
|
|
11
10
|
function runLifecycle(epoch, callback, ...args) {
|
|
@@ -96,6 +95,7 @@ const withOrigin = (fetch) => (request, server) => {
|
|
|
96
95
|
origin.request = void 0;
|
|
97
96
|
}
|
|
98
97
|
};
|
|
98
|
+
const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
|
|
99
99
|
function collectStaticRoutes(app) {
|
|
100
100
|
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
101
101
|
app.fetch;
|
|
@@ -105,66 +105,57 @@ function collectStaticRoutes(app) {
|
|
|
105
105
|
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
106
106
|
const length = table?.length ?? 0;
|
|
107
107
|
if (!table || !length) return;
|
|
108
|
-
const { method: methods, path: paths, handler: handlers } = table;
|
|
109
|
-
const nativeStaticMethods = new Set([
|
|
110
|
-
"GET",
|
|
111
|
-
"POST",
|
|
112
|
-
"PUT",
|
|
113
|
-
"DELETE",
|
|
114
|
-
"PATCH",
|
|
115
|
-
"HEAD",
|
|
116
|
-
"OPTIONS"
|
|
117
|
-
]);
|
|
108
|
+
const { method: methods, path: paths, handler: handlers, flags } = table;
|
|
118
109
|
let hasCandidate = false;
|
|
119
110
|
for (let i = 0; i < length; i++) {
|
|
111
|
+
if (!isNativeStaticMethod(methods[i]) || (flags[i] & RouteFlag.Dynamic) !== 0) continue;
|
|
120
112
|
const h = handlers[i];
|
|
121
|
-
if (typeof h
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
if (typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
114
|
+
hasCandidate = true;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
125
117
|
}
|
|
126
118
|
if (!hasCandidate) return;
|
|
127
|
-
const ready = nullObject();
|
|
128
119
|
const strictPath = frozenRoot["~config"]?.strictPath === true;
|
|
129
|
-
const
|
|
130
|
-
for (let i = 0; i < length; i++)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (needEncodeRegex.test(path)) {
|
|
141
|
-
const encoded = encodeURI(path);
|
|
142
|
-
if (encoded !== path) set.add(encoded);
|
|
143
|
-
}
|
|
120
|
+
const routeIndex = /* @__PURE__ */ new Map();
|
|
121
|
+
for (let i = 0; i < length; i++) {
|
|
122
|
+
const method = methods[i];
|
|
123
|
+
if (!isNativeStaticMethod(method) || (flags[i] & RouteFlag.Dynamic) !== 0) continue;
|
|
124
|
+
const path = paths[i];
|
|
125
|
+
let pathsByMethod = routeIndex.get(method);
|
|
126
|
+
if (!pathsByMethod) routeIndex.set(method, pathsByMethod = /* @__PURE__ */ new Map());
|
|
127
|
+
pathsByMethod.set(path, i);
|
|
128
|
+
if (!strictPath && (flags[i] & RouteFlag.Encode) !== 0) {
|
|
129
|
+
const encoded = encodeURI(path);
|
|
130
|
+
if (encoded !== path && !pathsByMethod.has(encoded)) pathsByMethod.set(encoded, -1);
|
|
144
131
|
}
|
|
145
132
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
133
|
+
const ready = nullObject();
|
|
134
|
+
let hasReady = false;
|
|
135
|
+
const add = (method, path, value, needsEncode) => {
|
|
136
|
+
if (needsEncode) path = encodeURI(path);
|
|
148
137
|
(ready[path] ??= nullObject())[method] = value;
|
|
138
|
+
hasReady = true;
|
|
149
139
|
};
|
|
150
140
|
for (let i = 0; i < length; i++) {
|
|
151
141
|
const method = methods[i];
|
|
152
|
-
|
|
142
|
+
const routeFlags = flags[i];
|
|
143
|
+
if (!isNativeStaticMethod(method) || (routeFlags & RouteFlag.Dynamic) !== 0) continue;
|
|
144
|
+
const pathsByMethod = routeIndex.get(method);
|
|
153
145
|
const path = paths[i];
|
|
154
|
-
if (
|
|
155
|
-
if (!nativeStaticMethods.has(method)) continue;
|
|
156
|
-
if (isDynamicRegex.test(path)) continue;
|
|
146
|
+
if (pathsByMethod.get(path) !== i) continue;
|
|
157
147
|
const h = handlers[i];
|
|
158
148
|
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
159
149
|
const value = buildNativeStaticResponse(routeRow(table, i), app);
|
|
160
150
|
if (!value) continue;
|
|
161
|
-
|
|
151
|
+
const needsEncode = (routeFlags & RouteFlag.Encode) !== 0;
|
|
152
|
+
add(method, path, value, needsEncode);
|
|
162
153
|
if (!strictPath) {
|
|
163
154
|
const loose = getLoosePath(path);
|
|
164
|
-
if (loose !== path && !
|
|
155
|
+
if (loose !== path && !pathsByMethod.has(loose)) add(method, loose, value, needsEncode);
|
|
165
156
|
}
|
|
166
157
|
}
|
|
167
|
-
if (!
|
|
158
|
+
if (!hasReady) return;
|
|
168
159
|
return ready;
|
|
169
160
|
}
|
|
170
161
|
const BunAdapter = createAdapter({
|
|
@@ -175,31 +166,40 @@ const BunAdapter = createAdapter({
|
|
|
175
166
|
response: WebStandardAdapter.response,
|
|
176
167
|
listen(app, options, callback) {
|
|
177
168
|
if (app.server || app["~ext"]?.stop) throw new Error("[Elysia] Cannot call listen() while a server or teardown is active");
|
|
178
|
-
|
|
169
|
+
function gatedFetch(request, server) {
|
|
170
|
+
return live ? live(request, server) : Promise.resolve(ready).then(async () => {
|
|
171
|
+
if (!live) {
|
|
172
|
+
await startupShutdown;
|
|
173
|
+
throw new Error("[Elysia] Server was stopped before it was ready");
|
|
174
|
+
}
|
|
175
|
+
return live(request, server);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
179
178
|
const optionsIsObject = typeof options === "object";
|
|
180
|
-
let live;
|
|
181
|
-
let cancelled = false;
|
|
182
|
-
let startupShutdown;
|
|
183
|
-
let shutdownAttempt;
|
|
184
|
-
const gatedFetch = (request, server) => live ? live(request, server) : Promise.resolve(ready).then(async () => {
|
|
185
|
-
if (!live) {
|
|
186
|
-
await startupShutdown;
|
|
187
|
-
throw new Error("[Elysia] Server was stopped before it was ready");
|
|
188
|
-
}
|
|
189
|
-
return live(request, server);
|
|
190
|
-
});
|
|
191
179
|
const _options = optionsIsObject ? { ...options } : {
|
|
192
180
|
port: +options,
|
|
193
181
|
fetch: gatedFetch
|
|
194
182
|
};
|
|
195
183
|
if (optionsIsObject) _options.fetch = gatedFetch;
|
|
184
|
+
const _config = app["~config"]?.serve;
|
|
196
185
|
const serve = _config ? {
|
|
197
186
|
..._config,
|
|
198
187
|
..._options
|
|
199
188
|
} : _options;
|
|
189
|
+
const server = app.server = Bun.serve(serve.routes || serve.error ? {
|
|
190
|
+
...serve,
|
|
191
|
+
error: unavailableFetch,
|
|
192
|
+
routes: {}
|
|
193
|
+
} : serve);
|
|
194
|
+
let live;
|
|
195
|
+
let cancelled = false;
|
|
196
|
+
let startupShutdown;
|
|
197
|
+
let shutdownAttempt;
|
|
200
198
|
let ready;
|
|
201
199
|
let wsLifecycle;
|
|
202
200
|
let modulesReady;
|
|
201
|
+
let built;
|
|
202
|
+
let pendingSetups;
|
|
203
203
|
const build = () => {
|
|
204
204
|
const fetch = app.fetch;
|
|
205
205
|
let routes;
|
|
@@ -230,13 +230,6 @@ const BunAdapter = createAdapter({
|
|
|
230
230
|
websocket
|
|
231
231
|
};
|
|
232
232
|
};
|
|
233
|
-
let built;
|
|
234
|
-
let pendingSetups;
|
|
235
|
-
const server = app.server = Bun.serve(serve.routes || serve.error ? {
|
|
236
|
-
...serve,
|
|
237
|
-
error: unavailableFetch,
|
|
238
|
-
routes: {}
|
|
239
|
-
} : serve);
|
|
240
233
|
let startupFailure;
|
|
241
234
|
let forceRequested = false;
|
|
242
235
|
let forceDone = false;
|
package/dist/adapter/utils.js
CHANGED
|
@@ -370,7 +370,6 @@ function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = fals
|
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
}
|
|
373
|
-
const warnedStreamBorrows = /* @__PURE__ */ new WeakSet();
|
|
374
373
|
function createResponseHandler(handler) {
|
|
375
374
|
const handleStream = createStreamHandler(handler);
|
|
376
375
|
return (response, set, request, owned = false) => {
|
|
@@ -390,12 +389,7 @@ function createResponseHandler(handler) {
|
|
|
390
389
|
if (!borrowed && response.body?.locked) throw new TypeError("Cannot patch a Response whose body is locked");
|
|
391
390
|
let body = response.body;
|
|
392
391
|
if (borrowed) {
|
|
393
|
-
const bodyBefore = body;
|
|
394
392
|
const cloned = response.clone();
|
|
395
|
-
if (explicitlyBorrowed && bodyBefore && response.body !== bodyBefore && !warnedStreamBorrows.has(response)) {
|
|
396
|
-
warnedStreamBorrows.add(response);
|
|
397
|
-
console.warn("[elysia] borrow() was called on a stream-backed Response");
|
|
398
|
-
}
|
|
399
393
|
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body, explicitlyBorrowed) : cloned.body;
|
|
400
394
|
}
|
|
401
395
|
const newResponse = new Response(body, set ? {
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -369,7 +369,6 @@ function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = fals
|
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
const warnedStreamBorrows = /* @__PURE__ */ new WeakSet();
|
|
373
372
|
function createResponseHandler(handler) {
|
|
374
373
|
const handleStream = createStreamHandler(handler);
|
|
375
374
|
return (response, set, request, owned = false) => {
|
|
@@ -389,12 +388,7 @@ function createResponseHandler(handler) {
|
|
|
389
388
|
if (!borrowed && response.body?.locked) throw new TypeError("Cannot patch a Response whose body is locked");
|
|
390
389
|
let body = response.body;
|
|
391
390
|
if (borrowed) {
|
|
392
|
-
const bodyBefore = body;
|
|
393
391
|
const cloned = response.clone();
|
|
394
|
-
if (explicitlyBorrowed && bodyBefore && response.body !== bodyBefore && !warnedStreamBorrows.has(response)) {
|
|
395
|
-
warnedStreamBorrows.add(response);
|
|
396
|
-
console.warn("[elysia] borrow() was called on a stream-backed Response");
|
|
397
|
-
}
|
|
398
392
|
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body, explicitlyBorrowed) : cloned.body;
|
|
399
393
|
}
|
|
400
394
|
const newResponse = new Response(body, set ? {
|
package/dist/base.d.ts
CHANGED
|
@@ -28,6 +28,16 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
28
28
|
'~Ephemeral': Ephemeral;
|
|
29
29
|
'~Volatile': Volatile;
|
|
30
30
|
'~Routes': Routes;
|
|
31
|
+
private hasPlugin?;
|
|
32
|
+
private hasGlobal?;
|
|
33
|
+
private ready?;
|
|
34
|
+
private _pending;
|
|
35
|
+
private _error?;
|
|
36
|
+
private hash?;
|
|
37
|
+
private childrenHash?;
|
|
38
|
+
private scopeParent?;
|
|
39
|
+
private pluginMacros?;
|
|
40
|
+
private macroBaseline?;
|
|
31
41
|
'~ext'?: {
|
|
32
42
|
decorator?: Singleton['decorator'];
|
|
33
43
|
store?: Singleton['store'];
|
|
@@ -55,10 +65,18 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
55
65
|
};
|
|
56
66
|
'~hookChain'?: ChainNode;
|
|
57
67
|
'~wsConfig'?: WSOptions;
|
|
68
|
+
private declaredRoutes?;
|
|
69
|
+
private routeSources?;
|
|
58
70
|
server?: Server;
|
|
59
71
|
get history(): readonly HistoryEntry[];
|
|
60
72
|
get ['~routes'](): readonly InternalRoute[];
|
|
61
73
|
['~addRoute'](route: InternalRoute): this;
|
|
74
|
+
private compiled?;
|
|
75
|
+
private jitColdRemaining?;
|
|
76
|
+
private jitTable?;
|
|
77
|
+
private jitRoute?;
|
|
78
|
+
private jitStatic?;
|
|
79
|
+
private jitAliases?;
|
|
62
80
|
'~router'?: Memoirist<CompiledHandler>;
|
|
63
81
|
'~map'?: {
|
|
64
82
|
[method: string]: {
|
|
@@ -528,6 +546,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
528
546
|
parser: Metadata['parser'];
|
|
529
547
|
response: Metadata['response'] & MacroContext['response'] & ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle>;
|
|
530
548
|
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & NewElysia['~Routes'], Ephemeral, Volatile>;
|
|
549
|
+
private get ext();
|
|
531
550
|
['~resolvedCapability'](kind: 'trace'): TraceCapability | undefined;
|
|
532
551
|
['~resolvedCapability'](kind: 'ws'): {
|
|
533
552
|
provider: WSCapability;
|
|
@@ -869,8 +888,11 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
869
888
|
*/
|
|
870
889
|
compile(): this;
|
|
871
890
|
handler(index: number, immediate?: boolean, route?: InternalRoute, precomputedStatic?: Response, aliases?: StaticMapAliases, table?: RouteTable): CompiledHandler;
|
|
891
|
+
private routerBuilt;
|
|
872
892
|
['~newGeneration'](): this;
|
|
893
|
+
private fetchFn?;
|
|
873
894
|
get fetch(): (request: Request, ...rest: any[]) => MaybePromise<Response>;
|
|
895
|
+
private _handle?;
|
|
874
896
|
get handle(): (url: string | Request, options?: RequestInit) => Promise<Response>;
|
|
875
897
|
listen(options: string | number | Partial<Serve>, callback?: ListenCallback): this;
|
|
876
898
|
/**
|
|
@@ -904,21 +926,15 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
904
926
|
*/
|
|
905
927
|
cleanup(handler: MaybeArray<GracefulHandler<this>>): this;
|
|
906
928
|
/**
|
|
907
|
-
* Stop the underlying server (if any), then run every `cleanup` handler
|
|
908
|
-
* Omitted and `false` are the same graceful stop: new requests are gated,
|
|
909
|
-
* tracked WebSockets are settled and active HTTP is drained, then cleanup
|
|
910
|
-
* runs and the epoch is released. `true` force-closes the transport
|
|
911
|
-
* instead of draining it, and escalates a graceful stop already in flight.
|
|
929
|
+
* Stop the underlying server (if any), then run every `cleanup` handler
|
|
912
930
|
*
|
|
913
931
|
* Awaiting `stop()` from inside a `setup`, `cleanup` or WebSocket lifecycle
|
|
914
|
-
* callback is only supported while that callback is still synchronous
|
|
915
|
-
* teardown is waiting on the callback, so after an `await` it can only be
|
|
916
|
-
* issued as `void app.stop()`.
|
|
932
|
+
* callback is only supported while that callback is still synchronous
|
|
917
933
|
*
|
|
918
934
|
* @param closeActiveConnections Pass `true` to terminate active
|
|
919
935
|
* transports. Omit (or pass `false`) to drain safely.
|
|
920
936
|
*/
|
|
921
|
-
stop(closeActiveConnections?: boolean): Promise<void> |
|
|
937
|
+
stop(closeActiveConnections?: boolean): Promise<void> | undefined;
|
|
922
938
|
}
|
|
923
939
|
//#endregion
|
|
924
940
|
export { AnyElysia, Elysia };
|