elysia 2.0.0-exp.30 → 2.0.0-exp.32
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/skip-clone.d.ts +4 -0
- package/dist/adapter/{transferable.js → skip-clone.js} +1 -1
- package/dist/adapter/{transferable.mjs → skip-clone.mjs} +1 -1
- package/dist/adapter/utils.js +26 -34
- package/dist/adapter/utils.mjs +25 -33
- package/dist/adapter/web-standard/handler.js +2 -4
- package/dist/adapter/web-standard/handler.mjs +2 -4
- package/dist/base.d.ts +6 -4
- package/dist/base.js +18 -58
- package/dist/base.mjs +18 -58
- package/dist/compile/aot.d.ts +1 -6
- package/dist/compile/aot.js +1 -7
- package/dist/compile/aot.mjs +1 -6
- package/dist/compile/handler/frozen-validator.js +3 -35
- package/dist/compile/handler/frozen-validator.mjs +1 -33
- package/dist/compile/handler/index.d.ts +1 -7
- package/dist/compile/handler/index.js +0 -1
- package/dist/compile/handler/index.mjs +1 -1
- package/dist/compile/handler/utils.d.ts +2 -4
- package/dist/compile/handler/utils.js +16 -35
- package/dist/compile/handler/utils.mjs +16 -34
- package/dist/compile/lexer.d.ts +1 -1
- package/dist/error.js +4 -4
- package/dist/error.mjs +1 -1
- package/dist/plugin/core.d.ts +1 -3
- package/dist/plugin/core.js +5 -5
- package/dist/plugin/core.mjs +6 -4
- package/dist/plugin/vite.js +3 -13
- package/dist/plugin/vite.mjs +2 -11
- package/dist/sucrose.d.ts +1 -23
- package/dist/sucrose.js +4 -8
- package/dist/sucrose.mjs +5 -7
- package/dist/type/coerce.js +1 -2
- package/dist/type/coerce.mjs +1 -2
- package/dist/type/elysia/intersect.js +3 -3
- package/dist/type/elysia/intersect.mjs +1 -1
- package/dist/type/elysia/utils.d.ts +1 -2
- package/dist/type/elysia/utils.js +0 -5
- package/dist/type/elysia/utils.mjs +1 -5
- package/dist/type/types.d.ts +1 -1
- package/dist/type/validator/clean-safe.d.ts +7 -0
- package/dist/type/validator/clean-safe.js +73 -0
- package/dist/type/validator/clean-safe.mjs +68 -0
- package/dist/type/validator/default-precompute.d.ts +1 -3
- package/dist/type/validator/default-precompute.js +0 -2
- package/dist/type/validator/default-precompute.mjs +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +3 -58
- package/dist/type/validator/index.mjs +1 -56
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/type/validator/validator-cache.js +5 -34
- package/dist/type/validator/validator-cache.mjs +5 -34
- package/dist/types.d.ts +4 -34
- package/dist/universal/constants.d.ts +1 -3
- package/dist/universal/constants.js +1 -5
- package/dist/universal/constants.mjs +1 -3
- package/dist/ws/route.js +1 -2
- package/dist/ws/route.mjs +1 -2
- package/package.json +1 -1
- package/dist/adapter/transferable.d.ts +0 -4
- package/dist/compile/index.d.ts +0 -3
- package/dist/compile/index.js +0 -10
- package/dist/compile/index.mjs +0 -4
- package/dist/compile/types.d.ts +0 -4
- package/dist/compile/types.js +0 -1
- package/dist/compile/types.mjs +0 -1
- package/dist/universal/types.d.ts +0 -127
- package/dist/universal/types.js +0 -20
- package/dist/universal/types.mjs +0 -17
package/dist/adapter/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_universal_constants = require('../universal/constants.js');
|
|
3
3
|
const require_constants = require('../constants.js');
|
|
4
4
|
const require_utils = require('../utils.js');
|
|
5
|
-
const
|
|
5
|
+
const require_adapter_skip_clone = require('./skip-clone.js');
|
|
6
6
|
const require_cookie_serialize = require('../cookie/serialize.js');
|
|
7
7
|
|
|
8
8
|
//#region src/adapter/utils.ts
|
|
@@ -180,6 +180,26 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
180
180
|
if (r && typeof r.then === "function") r.catch(() => {});
|
|
181
181
|
} catch {}
|
|
182
182
|
};
|
|
183
|
+
const closeSafely = (controller) => {
|
|
184
|
+
try {
|
|
185
|
+
controller.close();
|
|
186
|
+
} catch {}
|
|
187
|
+
cleanupAbort();
|
|
188
|
+
};
|
|
189
|
+
const enqueueValue = async (controller, value) => {
|
|
190
|
+
if (value.toSSE) {
|
|
191
|
+
controller.enqueue(encodeChunk(value.toSSE()));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const p = enqueueBinaryChunk(controller, value);
|
|
195
|
+
if (p !== false) return void await p;
|
|
196
|
+
if (typeof value === "object") try {
|
|
197
|
+
controller.enqueue(encodeChunk(format(JSON.stringify(value))));
|
|
198
|
+
} catch {
|
|
199
|
+
controller.enqueue(encodeChunk(format(value.toString())));
|
|
200
|
+
}
|
|
201
|
+
else controller.enqueue(encodeChunk(format(value.toString())));
|
|
202
|
+
};
|
|
183
203
|
return new Response(new ReadableStream({
|
|
184
204
|
async start(controller) {
|
|
185
205
|
if (signal) {
|
|
@@ -195,49 +215,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
195
215
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
196
216
|
}
|
|
197
217
|
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
198
|
-
|
|
199
|
-
controller.enqueue(encodeChunk(init.value.toSSE()));
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const p = enqueueBinaryChunk(controller, init.value);
|
|
203
|
-
if (p !== false) return void await p;
|
|
204
|
-
if (typeof init.value === "object") try {
|
|
205
|
-
controller.enqueue(encodeChunk(format(JSON.stringify(init.value))));
|
|
206
|
-
} catch {
|
|
207
|
-
controller.enqueue(encodeChunk(format(init.value.toString())));
|
|
208
|
-
}
|
|
209
|
-
else controller.enqueue(encodeChunk(format(init.value.toString())));
|
|
218
|
+
await enqueueValue(controller, init.value);
|
|
210
219
|
},
|
|
211
220
|
async pull(controller) {
|
|
212
221
|
if (end) {
|
|
213
|
-
|
|
214
|
-
controller.close();
|
|
215
|
-
} catch {}
|
|
216
|
-
cleanupAbort();
|
|
222
|
+
closeSafely(controller);
|
|
217
223
|
return;
|
|
218
224
|
}
|
|
219
225
|
try {
|
|
220
226
|
const { value: chunk, done } = await iterator.next();
|
|
221
227
|
if (done || end) {
|
|
222
|
-
|
|
223
|
-
controller.close();
|
|
224
|
-
} catch {}
|
|
225
|
-
cleanupAbort();
|
|
228
|
+
closeSafely(controller);
|
|
226
229
|
return;
|
|
227
230
|
}
|
|
228
231
|
if (chunk === void 0 || chunk === null) return;
|
|
229
|
-
|
|
230
|
-
controller.enqueue(encodeChunk(chunk.toSSE()));
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const p = enqueueBinaryChunk(controller, chunk);
|
|
234
|
-
if (p !== false) return void await p;
|
|
235
|
-
if (typeof chunk === "object") try {
|
|
236
|
-
controller.enqueue(encodeChunk(format(JSON.stringify(chunk))));
|
|
237
|
-
} catch {
|
|
238
|
-
controller.enqueue(encodeChunk(format(chunk.toString())));
|
|
239
|
-
}
|
|
240
|
-
else controller.enqueue(encodeChunk(format(chunk.toString())));
|
|
232
|
+
await enqueueValue(controller, chunk);
|
|
241
233
|
} catch (error) {
|
|
242
234
|
cleanupAbort();
|
|
243
235
|
controller.error(error);
|
|
@@ -315,7 +307,7 @@ function createResponseHandler(handler) {
|
|
|
315
307
|
if ((status === void 0 || status === response.status) && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
|
|
316
308
|
}
|
|
317
309
|
let body = response.body;
|
|
318
|
-
if (
|
|
310
|
+
if (require_adapter_skip_clone.skipClone.has(response) && !response.bodyUsed) require_adapter_skip_clone.skipClone.delete(response);
|
|
319
311
|
else {
|
|
320
312
|
const cloned = response.clone();
|
|
321
313
|
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body) : cloned.body;
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hasHeaderShorthand, isBun } from "../universal/constants.mjs";
|
|
2
2
|
import { StatusMap } from "../constants.mjs";
|
|
3
3
|
import { isNotEmpty, nullObject } from "../utils.mjs";
|
|
4
|
-
import { skipClone } from "./
|
|
4
|
+
import { skipClone } from "./skip-clone.mjs";
|
|
5
5
|
import { serializeCookie } from "../cookie/serialize.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/adapter/utils.ts
|
|
@@ -179,6 +179,26 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
179
179
|
if (r && typeof r.then === "function") r.catch(() => {});
|
|
180
180
|
} catch {}
|
|
181
181
|
};
|
|
182
|
+
const closeSafely = (controller) => {
|
|
183
|
+
try {
|
|
184
|
+
controller.close();
|
|
185
|
+
} catch {}
|
|
186
|
+
cleanupAbort();
|
|
187
|
+
};
|
|
188
|
+
const enqueueValue = async (controller, value) => {
|
|
189
|
+
if (value.toSSE) {
|
|
190
|
+
controller.enqueue(encodeChunk(value.toSSE()));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const p = enqueueBinaryChunk(controller, value);
|
|
194
|
+
if (p !== false) return void await p;
|
|
195
|
+
if (typeof value === "object") try {
|
|
196
|
+
controller.enqueue(encodeChunk(format(JSON.stringify(value))));
|
|
197
|
+
} catch {
|
|
198
|
+
controller.enqueue(encodeChunk(format(value.toString())));
|
|
199
|
+
}
|
|
200
|
+
else controller.enqueue(encodeChunk(format(value.toString())));
|
|
201
|
+
};
|
|
182
202
|
return new Response(new ReadableStream({
|
|
183
203
|
async start(controller) {
|
|
184
204
|
if (signal) {
|
|
@@ -194,49 +214,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
194
214
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
195
215
|
}
|
|
196
216
|
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
197
|
-
|
|
198
|
-
controller.enqueue(encodeChunk(init.value.toSSE()));
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const p = enqueueBinaryChunk(controller, init.value);
|
|
202
|
-
if (p !== false) return void await p;
|
|
203
|
-
if (typeof init.value === "object") try {
|
|
204
|
-
controller.enqueue(encodeChunk(format(JSON.stringify(init.value))));
|
|
205
|
-
} catch {
|
|
206
|
-
controller.enqueue(encodeChunk(format(init.value.toString())));
|
|
207
|
-
}
|
|
208
|
-
else controller.enqueue(encodeChunk(format(init.value.toString())));
|
|
217
|
+
await enqueueValue(controller, init.value);
|
|
209
218
|
},
|
|
210
219
|
async pull(controller) {
|
|
211
220
|
if (end) {
|
|
212
|
-
|
|
213
|
-
controller.close();
|
|
214
|
-
} catch {}
|
|
215
|
-
cleanupAbort();
|
|
221
|
+
closeSafely(controller);
|
|
216
222
|
return;
|
|
217
223
|
}
|
|
218
224
|
try {
|
|
219
225
|
const { value: chunk, done } = await iterator.next();
|
|
220
226
|
if (done || end) {
|
|
221
|
-
|
|
222
|
-
controller.close();
|
|
223
|
-
} catch {}
|
|
224
|
-
cleanupAbort();
|
|
227
|
+
closeSafely(controller);
|
|
225
228
|
return;
|
|
226
229
|
}
|
|
227
230
|
if (chunk === void 0 || chunk === null) return;
|
|
228
|
-
|
|
229
|
-
controller.enqueue(encodeChunk(chunk.toSSE()));
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const p = enqueueBinaryChunk(controller, chunk);
|
|
233
|
-
if (p !== false) return void await p;
|
|
234
|
-
if (typeof chunk === "object") try {
|
|
235
|
-
controller.enqueue(encodeChunk(format(JSON.stringify(chunk))));
|
|
236
|
-
} catch {
|
|
237
|
-
controller.enqueue(encodeChunk(format(chunk.toString())));
|
|
238
|
-
}
|
|
239
|
-
else controller.enqueue(encodeChunk(format(chunk.toString())));
|
|
231
|
+
await enqueueValue(controller, chunk);
|
|
240
232
|
} catch (error) {
|
|
241
233
|
cleanupAbort();
|
|
242
234
|
controller.error(error);
|
|
@@ -21,7 +21,6 @@ function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, r
|
|
|
21
21
|
});
|
|
22
22
|
return require_adapter_utils.handleFile(file.value, set, request);
|
|
23
23
|
}
|
|
24
|
-
const isNotBun = !require_universal_constants.isBun;
|
|
25
24
|
function responseTag(response) {
|
|
26
25
|
if (response === null || response === void 0) return void 0;
|
|
27
26
|
const proto = Object.getPrototypeOf(response);
|
|
@@ -34,7 +33,7 @@ function mapResponse(response, set, request) {
|
|
|
34
33
|
const headers = set.headers;
|
|
35
34
|
switch (responseTag(response)) {
|
|
36
35
|
case "String":
|
|
37
|
-
if (
|
|
36
|
+
if (!require_universal_constants.isBun && !headers["content-type"]) headers["content-type"] = "text/plain";
|
|
38
37
|
return new Response(response, set);
|
|
39
38
|
case "Array": return Response.json(response, set);
|
|
40
39
|
case "Object":
|
|
@@ -68,10 +67,9 @@ function mapResponse(response, set, request) {
|
|
|
68
67
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request);
|
|
69
68
|
return mapCompactResponse(response, request);
|
|
70
69
|
}
|
|
71
|
-
const stringHeaders = require_universal_constants.isBun ? void 0 : { headers: { "content-type": "text/plain" } };
|
|
72
70
|
function mapCompactResponse(response, request) {
|
|
73
71
|
switch (responseTag(response)) {
|
|
74
|
-
case "String": return new Response(response,
|
|
72
|
+
case "String": return new Response(response, require_universal_constants.isBun ? void 0 : { headers: { "content-type": "text/plain" } });
|
|
75
73
|
case "Array": return Response.json(response);
|
|
76
74
|
case "Object":
|
|
77
75
|
if (response["~ely-form"]) return new Response(require_utils.formToFormData(response));
|
|
@@ -20,7 +20,6 @@ function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
|
20
20
|
});
|
|
21
21
|
return handleFile(file.value, set, request);
|
|
22
22
|
}
|
|
23
|
-
const isNotBun = !isBun;
|
|
24
23
|
function responseTag(response) {
|
|
25
24
|
if (response === null || response === void 0) return void 0;
|
|
26
25
|
const proto = Object.getPrototypeOf(response);
|
|
@@ -33,7 +32,7 @@ function mapResponse(response, set, request) {
|
|
|
33
32
|
const headers = set.headers;
|
|
34
33
|
switch (responseTag(response)) {
|
|
35
34
|
case "String":
|
|
36
|
-
if (
|
|
35
|
+
if (!isBun && !headers["content-type"]) headers["content-type"] = "text/plain";
|
|
37
36
|
return new Response(response, set);
|
|
38
37
|
case "Array": return Response.json(response, set);
|
|
39
38
|
case "Object":
|
|
@@ -67,10 +66,9 @@ function mapResponse(response, set, request) {
|
|
|
67
66
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request);
|
|
68
67
|
return mapCompactResponse(response, request);
|
|
69
68
|
}
|
|
70
|
-
const stringHeaders = isBun ? void 0 : { headers: { "content-type": "text/plain" } };
|
|
71
69
|
function mapCompactResponse(response, request) {
|
|
72
70
|
switch (responseTag(response)) {
|
|
73
|
-
case "String": return new Response(response,
|
|
71
|
+
case "String": return new Response(response, isBun ? void 0 : { headers: { "content-type": "text/plain" } });
|
|
74
72
|
case "Array": return Response.json(response);
|
|
75
73
|
case "Object":
|
|
76
74
|
if (response["~ely-form"]) return new Response(formToFormData(response));
|
package/dist/base.d.ts
CHANGED
|
@@ -203,10 +203,12 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
203
203
|
derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'local', transform: (context: Context<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>) => MaybePromise<Derivative>): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
|
|
204
204
|
derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'plugin', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'plugin'>) => MaybePromise<Derivative>): PluginHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
|
|
205
205
|
derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'global', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'global'>) => MaybePromise<Derivative>): GlobalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
/**
|
|
207
|
+
* ### mapDerive
|
|
208
|
+
* Alias of {@link derive}. Shares the same implementation at the
|
|
209
|
+
* prototype level (see `Elysia.prototype.mapDerive` after the class).
|
|
210
|
+
*/
|
|
211
|
+
mapDerive: this['derive'];
|
|
210
212
|
afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>>>(fn: Handler): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
|
|
211
213
|
afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>>>(scope: 'local', fn: Handler): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
|
|
212
214
|
afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'plugin'>>>(scope: 'plugin', fn: Handler): PluginHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
|
package/dist/base.js
CHANGED
|
@@ -4,7 +4,6 @@ const require_universal_constants = require('./universal/constants.js');
|
|
|
4
4
|
const require_constants = require('./constants.js');
|
|
5
5
|
const require_utils = require('./utils.js');
|
|
6
6
|
const require_type_bridge = require('./type/bridge.js');
|
|
7
|
-
const require_error = require('./error.js');
|
|
8
7
|
const require_compile_aot = require('./compile/aot.js');
|
|
9
8
|
const require_compile_handler_index = require('./compile/handler/index.js');
|
|
10
9
|
const require_ws_route = require('./ws/route.js');
|
|
@@ -93,31 +92,35 @@ var Elysia = class Elysia {
|
|
|
93
92
|
}
|
|
94
93
|
return this;
|
|
95
94
|
}
|
|
96
|
-
#
|
|
95
|
+
#setField(field, as, name, value) {
|
|
97
96
|
const ext = this.#ext;
|
|
98
|
-
const fresh = !ext
|
|
99
|
-
const
|
|
97
|
+
const fresh = !ext[field];
|
|
98
|
+
const target = ext[field] ??= require_utils.nullObject();
|
|
100
99
|
switch (typeof value) {
|
|
101
100
|
case "object":
|
|
102
|
-
if (value
|
|
101
|
+
if (!value) return this;
|
|
102
|
+
if (!name && require_utils.isEmpty(value)) return this;
|
|
103
103
|
if (name) {
|
|
104
|
-
if (!fresh && name in
|
|
105
|
-
else
|
|
104
|
+
if (!fresh && name in target) target[name] = require_utils.mergeDeep(target[name], value, void 0, as === "override");
|
|
105
|
+
else target[name] = value;
|
|
106
106
|
return this;
|
|
107
107
|
}
|
|
108
|
-
if (fresh) Object.assign(
|
|
109
|
-
else ext
|
|
108
|
+
if (fresh) Object.assign(target, value);
|
|
109
|
+
else ext[field] = require_utils.mergeDeep(target, value, void 0, as === "override");
|
|
110
110
|
return this;
|
|
111
111
|
case "function":
|
|
112
112
|
if (name) {
|
|
113
|
-
if (as === "override" || !(name in
|
|
114
|
-
} else ext
|
|
113
|
+
if (as === "override" || !(name in target)) target[name] = value;
|
|
114
|
+
} else ext[field] = value(target);
|
|
115
115
|
return this;
|
|
116
116
|
default:
|
|
117
|
-
if (as === "override" || !(name in
|
|
117
|
+
if (as === "override" || !(name in target)) target[name] = value;
|
|
118
118
|
return this;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
#decorate(as, name, value) {
|
|
122
|
+
return this.#setField("decorator", as, name, value);
|
|
123
|
+
}
|
|
121
124
|
state(typeOrNameOrStore, nameOrStore, value) {
|
|
122
125
|
switch (arguments.length) {
|
|
123
126
|
case 1: return this.#state("append", "", typeOrNameOrStore);
|
|
@@ -129,30 +132,7 @@ var Elysia = class Elysia {
|
|
|
129
132
|
return this;
|
|
130
133
|
}
|
|
131
134
|
#state(as, name, value) {
|
|
132
|
-
|
|
133
|
-
const fresh = !ext.store;
|
|
134
|
-
const store = ext.store ??= require_utils.nullObject();
|
|
135
|
-
switch (typeof value) {
|
|
136
|
-
case "object":
|
|
137
|
-
if (!value) return this;
|
|
138
|
-
if (!name && require_utils.isEmpty(value)) return this;
|
|
139
|
-
if (name) {
|
|
140
|
-
if (!fresh && name in store) store[name] = require_utils.mergeDeep(store[name], value, void 0, as === "override");
|
|
141
|
-
else store[name] = value;
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
if (fresh) Object.assign(store, value);
|
|
145
|
-
else ext.store = require_utils.mergeDeep(store, value, void 0, as === "override");
|
|
146
|
-
return this;
|
|
147
|
-
case "function":
|
|
148
|
-
if (name) {
|
|
149
|
-
if (as === "override" || !(name in store)) store[name] = value;
|
|
150
|
-
} else ext.store = value(store);
|
|
151
|
-
return this;
|
|
152
|
-
default:
|
|
153
|
-
if (as === "override" || !(name in store)) store[name] = value;
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
135
|
+
return this.#setField("store", as, name, value);
|
|
156
136
|
}
|
|
157
137
|
headers(headers) {
|
|
158
138
|
const ext = this.#ext;
|
|
@@ -237,9 +217,6 @@ var Elysia = class Elysia {
|
|
|
237
217
|
}
|
|
238
218
|
return result;
|
|
239
219
|
}
|
|
240
|
-
mapDerive(scopeOrFn, fn) {
|
|
241
|
-
return this.derive(scopeOrFn, fn);
|
|
242
|
-
}
|
|
243
220
|
afterHandle(scopeOrFn, fn) {
|
|
244
221
|
return this.#onBranch("afterHandle", scopeOrFn, fn);
|
|
245
222
|
}
|
|
@@ -1104,21 +1081,6 @@ var Elysia = class Elysia {
|
|
|
1104
1081
|
this.#initMap();
|
|
1105
1082
|
const methods = this["~map"];
|
|
1106
1083
|
const length = this.#history.length;
|
|
1107
|
-
let hasDuplicate = false;
|
|
1108
|
-
const seen = /* @__PURE__ */ new Map();
|
|
1109
|
-
for (let i = 0; i < length; i++) {
|
|
1110
|
-
const route = this.#history[i];
|
|
1111
|
-
const m = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
|
|
1112
|
-
const key = m + " " + route[1];
|
|
1113
|
-
if (this.#routeMayHaveModelRef(route)) this.#assertRouteModelRefs(route, m);
|
|
1114
|
-
if (seen.has(key)) {
|
|
1115
|
-
hasDuplicate = true;
|
|
1116
|
-
if (!require_error.isProduction()) {
|
|
1117
|
-
if (this.#history[seen.get(key)][2] !== route[2]) console.warn(`[Elysia] Duplicate route ${key} at`, (/* @__PURE__ */ new Error()).stack);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
seen.set(key, i);
|
|
1121
|
-
}
|
|
1122
1084
|
let explicitHead;
|
|
1123
1085
|
if (enableAutoHead) {
|
|
1124
1086
|
for (let i = 0; i < length; i++) if (require_utils.mapMethodBack(this.#history[i][0]) === "HEAD") (explicitHead ??= /* @__PURE__ */ new Set()).add(this.#history[i][1]);
|
|
@@ -1145,10 +1107,7 @@ var Elysia = class Elysia {
|
|
|
1145
1107
|
const route = this.#history[i];
|
|
1146
1108
|
const method = require_utils.mapMethodBack(route[0]);
|
|
1147
1109
|
const path = route[1];
|
|
1148
|
-
if (
|
|
1149
|
-
const key = (route[0] === "WS" ? "WS" : method) + " " + path;
|
|
1150
|
-
if (seen.get(key) !== i) continue;
|
|
1151
|
-
}
|
|
1110
|
+
if (this.#routeMayHaveModelRef(route)) this.#assertRouteModelRefs(route, method);
|
|
1152
1111
|
if (route[0] === "WS") {
|
|
1153
1112
|
const ws = require_ws_route.buildWSRoute(route, this);
|
|
1154
1113
|
const handler = ws[0];
|
|
@@ -1297,6 +1256,7 @@ var Elysia = class Elysia {
|
|
|
1297
1256
|
return r;
|
|
1298
1257
|
}
|
|
1299
1258
|
};
|
|
1259
|
+
Elysia.prototype.mapDerive = Elysia.prototype.derive;
|
|
1300
1260
|
|
|
1301
1261
|
//#endregion
|
|
1302
1262
|
exports.Elysia = Elysia;
|
package/dist/base.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { isBun } from "./universal/constants.mjs";
|
|
|
2
2
|
import { MethodMap, isDynamicRegex, needEncodeRegex } from "./constants.mjs";
|
|
3
3
|
import { clonePlainDecorators, clonePlainDeep, coalesceStandaloneSchemas, createErrorEventHandler, eventProperties, fnOrigin, fnv1a, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isEmpty, isNotEmpty, isRecordNumber, joinPath, macroOrigin, mapMethodBack, mergeDeep, mergeResponse, nullObject, pushField, schemaProperties, serializeMacroSeed } from "./utils.mjs";
|
|
4
4
|
import { Ref } from "./type/bridge.mjs";
|
|
5
|
-
import { isProduction } from "./error.mjs";
|
|
6
5
|
import { Capture } from "./compile/aot.mjs";
|
|
7
6
|
import { compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook } from "./compile/handler/index.mjs";
|
|
8
7
|
import { buildWSRoute } from "./ws/route.mjs";
|
|
@@ -90,31 +89,35 @@ var Elysia = class Elysia {
|
|
|
90
89
|
}
|
|
91
90
|
return this;
|
|
92
91
|
}
|
|
93
|
-
#
|
|
92
|
+
#setField(field, as, name, value) {
|
|
94
93
|
const ext = this.#ext;
|
|
95
|
-
const fresh = !ext
|
|
96
|
-
const
|
|
94
|
+
const fresh = !ext[field];
|
|
95
|
+
const target = ext[field] ??= nullObject();
|
|
97
96
|
switch (typeof value) {
|
|
98
97
|
case "object":
|
|
99
|
-
if (value
|
|
98
|
+
if (!value) return this;
|
|
99
|
+
if (!name && isEmpty(value)) return this;
|
|
100
100
|
if (name) {
|
|
101
|
-
if (!fresh && name in
|
|
102
|
-
else
|
|
101
|
+
if (!fresh && name in target) target[name] = mergeDeep(target[name], value, void 0, as === "override");
|
|
102
|
+
else target[name] = value;
|
|
103
103
|
return this;
|
|
104
104
|
}
|
|
105
|
-
if (fresh) Object.assign(
|
|
106
|
-
else ext
|
|
105
|
+
if (fresh) Object.assign(target, value);
|
|
106
|
+
else ext[field] = mergeDeep(target, value, void 0, as === "override");
|
|
107
107
|
return this;
|
|
108
108
|
case "function":
|
|
109
109
|
if (name) {
|
|
110
|
-
if (as === "override" || !(name in
|
|
111
|
-
} else ext
|
|
110
|
+
if (as === "override" || !(name in target)) target[name] = value;
|
|
111
|
+
} else ext[field] = value(target);
|
|
112
112
|
return this;
|
|
113
113
|
default:
|
|
114
|
-
if (as === "override" || !(name in
|
|
114
|
+
if (as === "override" || !(name in target)) target[name] = value;
|
|
115
115
|
return this;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
+
#decorate(as, name, value) {
|
|
119
|
+
return this.#setField("decorator", as, name, value);
|
|
120
|
+
}
|
|
118
121
|
state(typeOrNameOrStore, nameOrStore, value) {
|
|
119
122
|
switch (arguments.length) {
|
|
120
123
|
case 1: return this.#state("append", "", typeOrNameOrStore);
|
|
@@ -126,30 +129,7 @@ var Elysia = class Elysia {
|
|
|
126
129
|
return this;
|
|
127
130
|
}
|
|
128
131
|
#state(as, name, value) {
|
|
129
|
-
|
|
130
|
-
const fresh = !ext.store;
|
|
131
|
-
const store = ext.store ??= nullObject();
|
|
132
|
-
switch (typeof value) {
|
|
133
|
-
case "object":
|
|
134
|
-
if (!value) return this;
|
|
135
|
-
if (!name && isEmpty(value)) return this;
|
|
136
|
-
if (name) {
|
|
137
|
-
if (!fresh && name in store) store[name] = mergeDeep(store[name], value, void 0, as === "override");
|
|
138
|
-
else store[name] = value;
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
if (fresh) Object.assign(store, value);
|
|
142
|
-
else ext.store = mergeDeep(store, value, void 0, as === "override");
|
|
143
|
-
return this;
|
|
144
|
-
case "function":
|
|
145
|
-
if (name) {
|
|
146
|
-
if (as === "override" || !(name in store)) store[name] = value;
|
|
147
|
-
} else ext.store = value(store);
|
|
148
|
-
return this;
|
|
149
|
-
default:
|
|
150
|
-
if (as === "override" || !(name in store)) store[name] = value;
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
132
|
+
return this.#setField("store", as, name, value);
|
|
153
133
|
}
|
|
154
134
|
headers(headers) {
|
|
155
135
|
const ext = this.#ext;
|
|
@@ -234,9 +214,6 @@ var Elysia = class Elysia {
|
|
|
234
214
|
}
|
|
235
215
|
return result;
|
|
236
216
|
}
|
|
237
|
-
mapDerive(scopeOrFn, fn) {
|
|
238
|
-
return this.derive(scopeOrFn, fn);
|
|
239
|
-
}
|
|
240
217
|
afterHandle(scopeOrFn, fn) {
|
|
241
218
|
return this.#onBranch("afterHandle", scopeOrFn, fn);
|
|
242
219
|
}
|
|
@@ -1101,21 +1078,6 @@ var Elysia = class Elysia {
|
|
|
1101
1078
|
this.#initMap();
|
|
1102
1079
|
const methods = this["~map"];
|
|
1103
1080
|
const length = this.#history.length;
|
|
1104
|
-
let hasDuplicate = false;
|
|
1105
|
-
const seen = /* @__PURE__ */ new Map();
|
|
1106
|
-
for (let i = 0; i < length; i++) {
|
|
1107
|
-
const route = this.#history[i];
|
|
1108
|
-
const m = route[0] === "WS" ? "WS" : mapMethodBack(route[0]);
|
|
1109
|
-
const key = m + " " + route[1];
|
|
1110
|
-
if (this.#routeMayHaveModelRef(route)) this.#assertRouteModelRefs(route, m);
|
|
1111
|
-
if (seen.has(key)) {
|
|
1112
|
-
hasDuplicate = true;
|
|
1113
|
-
if (!isProduction()) {
|
|
1114
|
-
if (this.#history[seen.get(key)][2] !== route[2]) console.warn(`[Elysia] Duplicate route ${key} at`, (/* @__PURE__ */ new Error()).stack);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
seen.set(key, i);
|
|
1118
|
-
}
|
|
1119
1081
|
let explicitHead;
|
|
1120
1082
|
if (enableAutoHead) {
|
|
1121
1083
|
for (let i = 0; i < length; i++) if (mapMethodBack(this.#history[i][0]) === "HEAD") (explicitHead ??= /* @__PURE__ */ new Set()).add(this.#history[i][1]);
|
|
@@ -1142,10 +1104,7 @@ var Elysia = class Elysia {
|
|
|
1142
1104
|
const route = this.#history[i];
|
|
1143
1105
|
const method = mapMethodBack(route[0]);
|
|
1144
1106
|
const path = route[1];
|
|
1145
|
-
if (
|
|
1146
|
-
const key = (route[0] === "WS" ? "WS" : method) + " " + path;
|
|
1147
|
-
if (seen.get(key) !== i) continue;
|
|
1148
|
-
}
|
|
1107
|
+
if (this.#routeMayHaveModelRef(route)) this.#assertRouteModelRefs(route, method);
|
|
1149
1108
|
if (route[0] === "WS") {
|
|
1150
1109
|
const ws = buildWSRoute(route, this);
|
|
1151
1110
|
const handler = ws[0];
|
|
@@ -1294,6 +1253,7 @@ var Elysia = class Elysia {
|
|
|
1294
1253
|
return r;
|
|
1295
1254
|
}
|
|
1296
1255
|
};
|
|
1256
|
+
Elysia.prototype.mapDerive = Elysia.prototype.derive;
|
|
1297
1257
|
|
|
1298
1258
|
//#endregion
|
|
1299
1259
|
export { Elysia };
|
package/dist/compile/aot.d.ts
CHANGED
|
@@ -227,10 +227,5 @@ declare const Capture: {
|
|
|
227
227
|
readonly isCapturing: () => boolean;
|
|
228
228
|
readonly isAotBuildEnv: () => boolean;
|
|
229
229
|
};
|
|
230
|
-
/**
|
|
231
|
-
* Reset module-level capture lifecycle state.
|
|
232
|
-
* FOR TESTS ONLY
|
|
233
|
-
*/
|
|
234
|
-
declare const resetCaptureLifecycleForTests: () => void;
|
|
235
230
|
//#endregion
|
|
236
|
-
export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs
|
|
231
|
+
export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
|
package/dist/compile/aot.js
CHANGED
|
@@ -344,11 +344,6 @@ const Capture = {
|
|
|
344
344
|
isCapturing: isValidatorCapturing,
|
|
345
345
|
isAotBuildEnv
|
|
346
346
|
};
|
|
347
|
-
/**
|
|
348
|
-
* Reset module-level capture lifecycle state.
|
|
349
|
-
* FOR TESTS ONLY
|
|
350
|
-
*/
|
|
351
|
-
const resetCaptureLifecycleForTests = () => void 0;
|
|
352
347
|
|
|
353
348
|
//#endregion
|
|
354
349
|
exports.Capture = Capture;
|
|
@@ -367,5 +362,4 @@ exports.instantiateFrozenDecodeMirror = instantiateFrozenDecodeMirror;
|
|
|
367
362
|
exports.instantiateFrozenEncodeMirror = instantiateFrozenEncodeMirror;
|
|
368
363
|
exports.instantiateFrozenMirror = instantiateFrozenMirror;
|
|
369
364
|
exports.reconstructCheck = reconstructCheck;
|
|
370
|
-
exports.reconstructInnerCodecs = reconstructInnerCodecs;
|
|
371
|
-
exports.resetCaptureLifecycleForTests = resetCaptureLifecycleForTests;
|
|
365
|
+
exports.reconstructInnerCodecs = reconstructInnerCodecs;
|
package/dist/compile/aot.mjs
CHANGED
|
@@ -343,11 +343,6 @@ const Capture = {
|
|
|
343
343
|
isCapturing: isValidatorCapturing,
|
|
344
344
|
isAotBuildEnv
|
|
345
345
|
};
|
|
346
|
-
/**
|
|
347
|
-
* Reset module-level capture lifecycle state.
|
|
348
|
-
* FOR TESTS ONLY
|
|
349
|
-
*/
|
|
350
|
-
const resetCaptureLifecycleForTests = () => void 0;
|
|
351
346
|
|
|
352
347
|
//#endregion
|
|
353
|
-
export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs
|
|
348
|
+
export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
|