elysia 2.0.0-beta.11 → 2.0.0-beta.13
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 +36 -21
- package/dist/adapter/bun/index.mjs +36 -21
- package/dist/adapter/utils.js +1 -0
- package/dist/adapter/utils.mjs +1 -0
- package/dist/adapter/web-standard/handler.js +8 -2
- package/dist/adapter/web-standard/handler.mjs +8 -2
- package/dist/base.d.ts +5 -0
- package/dist/base.js +109 -4
- package/dist/base.mjs +111 -6
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +5 -27
- package/dist/compile/aot-capture.mjs +6 -24
- package/dist/compile/aot-emit.js +1 -1
- package/dist/compile/aot-emit.mjs +1 -1
- package/dist/compile/aot.d.ts +1 -1
- package/dist/compile/aot.js +2 -2
- package/dist/compile/aot.mjs +2 -2
- package/dist/compile/handler/descriptor.d.ts +4 -8
- package/dist/compile/handler/descriptor.js +8 -21
- package/dist/compile/handler/descriptor.mjs +9 -21
- package/dist/compile/handler/index.d.ts +4 -3
- package/dist/compile/handler/index.js +16 -6
- package/dist/compile/handler/index.mjs +16 -7
- package/dist/compile/handler/jit.js +82 -76
- package/dist/compile/handler/jit.mjs +83 -77
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +3 -4
- package/dist/compile/handler/params.mjs +5 -5
- package/dist/compile/handler/reconstruct.d.ts +1 -1
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +7 -7
- package/dist/compile/handler/utils.js +24 -20
- package/dist/compile/handler/utils.mjs +24 -20
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/context.js +3 -21
- package/dist/context.mjs +4 -22
- package/dist/cookie/index.d.ts +1 -2
- package/dist/cookie/index.js +0 -2
- package/dist/cookie/index.mjs +1 -2
- package/dist/cookie/lib.js +2 -1
- package/dist/cookie/lib.mjs +2 -1
- package/dist/cookie/utils.d.ts +3 -7
- package/dist/cookie/utils.js +9 -28
- package/dist/cookie/utils.mjs +11 -29
- package/dist/error.d.ts +40 -83
- package/dist/error.js +18 -19
- package/dist/error.mjs +18 -20
- package/dist/handler/error.js +4 -5
- package/dist/handler/error.mjs +4 -5
- package/dist/handler/fetch.js +31 -17
- package/dist/handler/fetch.mjs +32 -18
- package/dist/handler/utils.d.ts +3 -3
- package/dist/handler/utils.js +28 -17
- package/dist/handler/utils.mjs +28 -17
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +3 -7
- package/dist/plugin/aot/core.js +8 -18
- package/dist/plugin/aot/core.mjs +9 -17
- package/dist/plugin/aot/hooks.js +5 -1
- package/dist/plugin/aot/hooks.mjs +5 -1
- package/dist/trace.js +23 -10
- package/dist/trace.mjs +23 -10
- package/dist/type/bridge-live.d.ts +3 -2
- package/dist/type/bridge-live.js +4 -2
- package/dist/type/bridge-live.mjs +3 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +9 -1
- package/dist/type/bridge.mjs +3 -1
- package/dist/type/coerce-plan.d.ts +2 -2
- package/dist/type/coerce-plan.js +0 -1
- package/dist/type/coerce-plan.mjs +2 -2
- package/dist/type/compat.js +2 -1
- package/dist/type/compat.mjs +3 -2
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/shared.d.ts +1 -3
- package/dist/type/shared.js +0 -3
- package/dist/type/shared.mjs +1 -3
- package/dist/type/typebox-value-live.d.ts +4 -3
- package/dist/type/typebox-value-live.js +5 -3
- package/dist/type/typebox-value-live.mjs +4 -3
- package/dist/type/typebox-value.d.ts +11 -7
- package/dist/type/typebox-value.js +2 -1
- package/dist/type/typebox-value.mjs +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/types.d.ts +10 -17
- package/dist/universal/file.d.ts +1 -3
- package/dist/universal/file.js +0 -2
- package/dist/universal/file.mjs +1 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/utils.d.ts +0 -1
- package/package.json +13 -6
|
@@ -25,7 +25,9 @@ function cloneResponse(r) {
|
|
|
25
25
|
}
|
|
26
26
|
function cloneStaticValue(value) {
|
|
27
27
|
try {
|
|
28
|
-
|
|
28
|
+
const cloned = structuredClone(value);
|
|
29
|
+
if (Object.getPrototypeOf(value) === require_error.ElysiaStatus.prototype) Object.setPrototypeOf(cloned, require_error.ElysiaStatus.prototype);
|
|
30
|
+
return cloned;
|
|
29
31
|
} catch {
|
|
30
32
|
return value;
|
|
31
33
|
}
|
|
@@ -51,10 +53,9 @@ function armEntryAbort(context) {
|
|
|
51
53
|
}
|
|
52
54
|
const trace = (report, fn) => report?.resolveChild(childName(fn)) ?? noTrace;
|
|
53
55
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
54
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report]) => {
|
|
56
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report, arm]) => {
|
|
55
57
|
const t = trace(report, fn);
|
|
56
|
-
const
|
|
57
|
-
const call = guard ? `_tf=tf${at(i)}(c)\n${guard}` : `${Await(fn)}tf${at(i)}(c)\n`;
|
|
58
|
+
const call = isAsync ? `_tf=tf${at(i)}(c)\n${awaitGuard(fn, isAsync, "_tf", arm)}` : `tf${at(i)}(c)\n`;
|
|
58
59
|
return t.begin + call + t.end();
|
|
59
60
|
});
|
|
60
61
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -318,7 +319,7 @@ function skipValue(src, i) {
|
|
|
318
319
|
}
|
|
319
320
|
return -1;
|
|
320
321
|
}
|
|
321
|
-
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
322
|
+
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
|
|
322
323
|
const hooks = toArray(_hooks);
|
|
323
324
|
const modes = deriveModes(hooks, derive);
|
|
324
325
|
let code = "";
|
|
@@ -332,8 +333,8 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
|
332
333
|
}
|
|
333
334
|
const t = trace(report, fn);
|
|
334
335
|
code += t.begin;
|
|
335
|
-
code += `tmp
|
|
336
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
336
|
+
code += `tmp=bf${at(i)}(c)\n`;
|
|
337
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
337
338
|
if (modes?.[i] !== void 0) {
|
|
338
339
|
needsEs = true;
|
|
339
340
|
if (modes[i]) {
|
|
@@ -379,7 +380,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
379
380
|
if (!first && abort && context["~sig"]?.aborted) return;
|
|
380
381
|
first = false;
|
|
381
382
|
let result = values[j](context);
|
|
382
|
-
if (result
|
|
383
|
+
if (typeof result?.then === "function") {
|
|
383
384
|
result = await result;
|
|
384
385
|
if (abort) context["~sig"] ??= context.request.signal;
|
|
385
386
|
}
|
|
@@ -387,7 +388,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
|
-
function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
391
|
+
function mapChainHook(hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
391
392
|
let code = "";
|
|
392
393
|
let depth = 0;
|
|
393
394
|
for (let i = 0; i < hooks.length; i++) {
|
|
@@ -398,25 +399,25 @@ function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
|
398
399
|
}
|
|
399
400
|
const t = trace(report, fn);
|
|
400
401
|
code += t.begin;
|
|
401
|
-
code += `tmp=${
|
|
402
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
402
|
+
code += `tmp=${prefix}${at(i)}(c)\n`;
|
|
403
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
403
404
|
code += t.end("tmp");
|
|
404
405
|
}
|
|
405
406
|
code += "}".repeat(depth);
|
|
406
407
|
code += `if(tmp!==undefined)_r=c.responseValue=tmp\n`;
|
|
407
408
|
return code;
|
|
408
409
|
}
|
|
409
|
-
const mapAfterHandle = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard);
|
|
410
|
-
const mapMapResponse = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard);
|
|
410
|
+
const mapAfterHandle = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard, arm);
|
|
411
|
+
const mapMapResponse = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard, arm);
|
|
411
412
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
412
413
|
const t = trace(report, fn);
|
|
413
|
-
const call = require_compile_utils.isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(_ar
|
|
414
|
-
return `try{
|
|
414
|
+
const call = require_compile_utils.isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
415
|
+
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
415
416
|
});
|
|
416
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync]) => {
|
|
417
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync, arm]) => {
|
|
417
418
|
link(mapResponse, "rm");
|
|
418
419
|
link(require_handler_error.adoptErrorType, "aet");
|
|
419
|
-
return `_r
|
|
420
|
+
return `_r=er${at(i)}(c)\n` + awaitGuard(fn, isAsync, "_r", arm) + "if(_r!==undefined){\nif(_r instanceof Response)c.set.status=_r.status\nelse if(c.set.status===undefined||c.set.status===200)c.set.status=500\n" + schedule + sign + `return _em(c,${map}(aet(_r,e),c.set,c.request,true))\n}\n`;
|
|
420
421
|
});
|
|
421
422
|
function map(map) {
|
|
422
423
|
return function(event, rest, abortGuard) {
|
|
@@ -502,16 +503,19 @@ function getQueryParseChannels(querySchema) {
|
|
|
502
503
|
queryParseChannelsCache.set(querySchema, result);
|
|
503
504
|
return result ?? void 0;
|
|
504
505
|
}
|
|
505
|
-
|
|
506
|
-
|
|
506
|
+
function awaitGuard(fn, isAsync, target, arm = "") {
|
|
507
|
+
if (!isAsync) return "";
|
|
508
|
+
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
509
|
+
return require_compile_utils.isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
510
|
+
}
|
|
507
511
|
|
|
508
512
|
//#endregion
|
|
509
513
|
exports.armEntryAbort = armEntryAbort;
|
|
514
|
+
exports.awaitGuard = awaitGuard;
|
|
510
515
|
exports.cloneResponse = cloneResponse;
|
|
511
516
|
exports.cloneStaticValue = cloneStaticValue;
|
|
512
517
|
exports.deriveModes = deriveModes;
|
|
513
518
|
exports.emptyResponse = require_handler_utils.emptyResponse;
|
|
514
|
-
exports.extractDeriveKeys = extractDeriveKeys;
|
|
515
519
|
exports.getQueryParseChannels = getQueryParseChannels;
|
|
516
520
|
exports.hasRequestBody = hasRequestBody;
|
|
517
521
|
exports.mapAfterHandle = mapAfterHandle;
|
|
@@ -24,7 +24,9 @@ function cloneResponse(r) {
|
|
|
24
24
|
}
|
|
25
25
|
function cloneStaticValue(value) {
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
const cloned = structuredClone(value);
|
|
28
|
+
if (Object.getPrototypeOf(value) === ElysiaStatus.prototype) Object.setPrototypeOf(cloned, ElysiaStatus.prototype);
|
|
29
|
+
return cloned;
|
|
28
30
|
} catch {
|
|
29
31
|
return value;
|
|
30
32
|
}
|
|
@@ -50,10 +52,9 @@ function armEntryAbort(context) {
|
|
|
50
52
|
}
|
|
51
53
|
const trace = (report, fn) => report?.resolveChild(childName(fn)) ?? noTrace;
|
|
52
54
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
53
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report]) => {
|
|
55
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report, arm]) => {
|
|
54
56
|
const t = trace(report, fn);
|
|
55
|
-
const
|
|
56
|
-
const call = guard ? `_tf=tf${at(i)}(c)\n${guard}` : `${Await(fn)}tf${at(i)}(c)\n`;
|
|
57
|
+
const call = isAsync ? `_tf=tf${at(i)}(c)\n${awaitGuard(fn, isAsync, "_tf", arm)}` : `tf${at(i)}(c)\n`;
|
|
57
58
|
return t.begin + call + t.end();
|
|
58
59
|
});
|
|
59
60
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -317,7 +318,7 @@ function skipValue(src, i) {
|
|
|
317
318
|
}
|
|
318
319
|
return -1;
|
|
319
320
|
}
|
|
320
|
-
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
321
|
+
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
|
|
321
322
|
const hooks = toArray(_hooks);
|
|
322
323
|
const modes = deriveModes(hooks, derive);
|
|
323
324
|
let code = "";
|
|
@@ -331,8 +332,8 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
|
331
332
|
}
|
|
332
333
|
const t = trace(report, fn);
|
|
333
334
|
code += t.begin;
|
|
334
|
-
code += `tmp
|
|
335
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
335
|
+
code += `tmp=bf${at(i)}(c)\n`;
|
|
336
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
336
337
|
if (modes?.[i] !== void 0) {
|
|
337
338
|
needsEs = true;
|
|
338
339
|
if (modes[i]) {
|
|
@@ -378,7 +379,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
378
379
|
if (!first && abort && context["~sig"]?.aborted) return;
|
|
379
380
|
first = false;
|
|
380
381
|
let result = values[j](context);
|
|
381
|
-
if (result
|
|
382
|
+
if (typeof result?.then === "function") {
|
|
382
383
|
result = await result;
|
|
383
384
|
if (abort) context["~sig"] ??= context.request.signal;
|
|
384
385
|
}
|
|
@@ -386,7 +387,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
|
-
function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
390
|
+
function mapChainHook(hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
390
391
|
let code = "";
|
|
391
392
|
let depth = 0;
|
|
392
393
|
for (let i = 0; i < hooks.length; i++) {
|
|
@@ -397,25 +398,25 @@ function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
|
397
398
|
}
|
|
398
399
|
const t = trace(report, fn);
|
|
399
400
|
code += t.begin;
|
|
400
|
-
code += `tmp=${
|
|
401
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
401
|
+
code += `tmp=${prefix}${at(i)}(c)\n`;
|
|
402
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
402
403
|
code += t.end("tmp");
|
|
403
404
|
}
|
|
404
405
|
code += "}".repeat(depth);
|
|
405
406
|
code += `if(tmp!==undefined)_r=c.responseValue=tmp\n`;
|
|
406
407
|
return code;
|
|
407
408
|
}
|
|
408
|
-
const mapAfterHandle = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard);
|
|
409
|
-
const mapMapResponse = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard);
|
|
409
|
+
const mapAfterHandle = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard, arm);
|
|
410
|
+
const mapMapResponse = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard, arm);
|
|
410
411
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
411
412
|
const t = trace(report, fn);
|
|
412
|
-
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(_ar
|
|
413
|
-
return `try{
|
|
413
|
+
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
414
|
+
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
414
415
|
});
|
|
415
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync]) => {
|
|
416
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync, arm]) => {
|
|
416
417
|
link(mapResponse, "rm");
|
|
417
418
|
link(adoptErrorType, "aet");
|
|
418
|
-
return `_r
|
|
419
|
+
return `_r=er${at(i)}(c)\n` + awaitGuard(fn, isAsync, "_r", arm) + "if(_r!==undefined){\nif(_r instanceof Response)c.set.status=_r.status\nelse if(c.set.status===undefined||c.set.status===200)c.set.status=500\n" + schedule + sign + `return _em(c,${map}(aet(_r,e),c.set,c.request,true))\n}\n`;
|
|
419
420
|
});
|
|
420
421
|
function map(map) {
|
|
421
422
|
return function(event, rest, abortGuard) {
|
|
@@ -501,8 +502,11 @@ function getQueryParseChannels(querySchema) {
|
|
|
501
502
|
queryParseChannelsCache.set(querySchema, result);
|
|
502
503
|
return result ?? void 0;
|
|
503
504
|
}
|
|
504
|
-
|
|
505
|
-
|
|
505
|
+
function awaitGuard(fn, isAsync, target, arm = "") {
|
|
506
|
+
if (!isAsync) return "";
|
|
507
|
+
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
508
|
+
return isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
509
|
+
}
|
|
506
510
|
|
|
507
511
|
//#endregion
|
|
508
|
-
export { armEntryAbort, cloneResponse, cloneStaticValue, deriveModes, emptyResponse,
|
|
512
|
+
export { armEntryAbort, awaitGuard, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
package/dist/compile/utils.js
CHANGED
|
@@ -4,14 +4,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
function isAsyncFunction(fn) {
|
|
5
5
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
8
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
9
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
9
10
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
10
11
|
function mayReturnPromise(fn) {
|
|
11
12
|
let result = mayReturnPromiseCache.get(fn);
|
|
12
13
|
if (result !== void 0) return result;
|
|
13
|
-
const literal =
|
|
14
|
-
|
|
14
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
15
|
+
const arrow = matchArrow.exec(literal);
|
|
16
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
17
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
15
18
|
mayReturnPromiseCache.set(fn, result);
|
|
16
19
|
return result;
|
|
17
20
|
}
|
package/dist/compile/utils.mjs
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
function isAsyncFunction(fn) {
|
|
3
3
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
4
4
|
}
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
6
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
7
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
7
8
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function mayReturnPromise(fn) {
|
|
9
10
|
let result = mayReturnPromiseCache.get(fn);
|
|
10
11
|
if (result !== void 0) return result;
|
|
11
|
-
const literal =
|
|
12
|
-
|
|
12
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
13
|
+
const arrow = matchArrow.exec(literal);
|
|
14
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
15
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
13
16
|
mayReturnPromiseCache.set(fn, result);
|
|
14
17
|
return result;
|
|
15
18
|
}
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_utils = require('./utils.js');
|
|
3
|
-
const require_universal_is_production = require('./universal/is-production.js');
|
|
4
3
|
const require_error = require('./error.js');
|
|
5
4
|
const require_adapter_default_headers = require('./adapter/default-headers.js');
|
|
6
5
|
|
|
@@ -50,28 +49,12 @@ function clearContextCache(app) {
|
|
|
50
49
|
sharedEmptyDecorator = null;
|
|
51
50
|
sharedEmptyContext = null;
|
|
52
51
|
}
|
|
53
|
-
function buildEmptyContext(Base, headers = null
|
|
52
|
+
function buildEmptyContext(Base, headers = null) {
|
|
54
53
|
const immutableHeaders = headers !== null && Object.isFrozen(headers);
|
|
55
|
-
let warnedPathMutation = false;
|
|
56
|
-
const pathDescriptor = warnPathMutation ? {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
get() {
|
|
60
|
-
return this["~path"];
|
|
61
|
-
},
|
|
62
|
-
set(value) {
|
|
63
|
-
if ("~path" in this && !warnedPathMutation) {
|
|
64
|
-
warnedPathMutation = true;
|
|
65
|
-
console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
|
|
66
|
-
}
|
|
67
|
-
this["~path"] = value;
|
|
68
|
-
}
|
|
69
|
-
} : void 0;
|
|
70
54
|
class Context extends Base {
|
|
71
55
|
constructor(request) {
|
|
72
56
|
super();
|
|
73
57
|
this.request = request;
|
|
74
|
-
if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
|
|
75
58
|
if (immutableHeaders) this.set = {
|
|
76
59
|
headers,
|
|
77
60
|
status: void 0,
|
|
@@ -91,7 +74,6 @@ function createContext(app) {
|
|
|
91
74
|
if (cached) return cached;
|
|
92
75
|
const ext = app["~ext"];
|
|
93
76
|
const adapter = app["~config"]?.adapter;
|
|
94
|
-
const warnPathMutation = !require_universal_is_production.isProduction() && !!require_utils.flattenChain(app["~hookChain"])?.request?.length;
|
|
95
77
|
const headers = ext?.headers && require_utils.isNotEmpty(ext.headers) ? Object.assign(require_utils.nullObject(), ext.headers) : null;
|
|
96
78
|
if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
|
|
97
79
|
Object.defineProperty(headers, "\0", { value: headers });
|
|
@@ -99,11 +81,11 @@ function createContext(app) {
|
|
|
99
81
|
}
|
|
100
82
|
if (headers === null && !ext?.decorator && !ext?.store) {
|
|
101
83
|
sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
102
|
-
const context =
|
|
84
|
+
const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
|
|
103
85
|
contextCache.set(app, context);
|
|
104
86
|
return context;
|
|
105
87
|
}
|
|
106
|
-
const context = buildEmptyContext(createBaseContext(app), headers
|
|
88
|
+
const context = buildEmptyContext(createBaseContext(app), headers);
|
|
107
89
|
contextCache.set(app, context);
|
|
108
90
|
return context;
|
|
109
91
|
}
|
package/dist/context.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isProduction } from "./universal/is-production.mjs";
|
|
1
|
+
import { isNotEmpty, nullObject, redirect } from "./utils.mjs";
|
|
3
2
|
import { status } from "./error.mjs";
|
|
4
3
|
import { defaultHeaders } from "./adapter/default-headers.mjs";
|
|
5
4
|
|
|
@@ -49,28 +48,12 @@ function clearContextCache(app) {
|
|
|
49
48
|
sharedEmptyDecorator = null;
|
|
50
49
|
sharedEmptyContext = null;
|
|
51
50
|
}
|
|
52
|
-
function buildEmptyContext(Base, headers = null
|
|
51
|
+
function buildEmptyContext(Base, headers = null) {
|
|
53
52
|
const immutableHeaders = headers !== null && Object.isFrozen(headers);
|
|
54
|
-
let warnedPathMutation = false;
|
|
55
|
-
const pathDescriptor = warnPathMutation ? {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
get() {
|
|
59
|
-
return this["~path"];
|
|
60
|
-
},
|
|
61
|
-
set(value) {
|
|
62
|
-
if ("~path" in this && !warnedPathMutation) {
|
|
63
|
-
warnedPathMutation = true;
|
|
64
|
-
console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
|
|
65
|
-
}
|
|
66
|
-
this["~path"] = value;
|
|
67
|
-
}
|
|
68
|
-
} : void 0;
|
|
69
53
|
class Context extends Base {
|
|
70
54
|
constructor(request) {
|
|
71
55
|
super();
|
|
72
56
|
this.request = request;
|
|
73
|
-
if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
|
|
74
57
|
if (immutableHeaders) this.set = {
|
|
75
58
|
headers,
|
|
76
59
|
status: void 0,
|
|
@@ -90,7 +73,6 @@ function createContext(app) {
|
|
|
90
73
|
if (cached) return cached;
|
|
91
74
|
const ext = app["~ext"];
|
|
92
75
|
const adapter = app["~config"]?.adapter;
|
|
93
|
-
const warnPathMutation = !isProduction() && !!flattenChain(app["~hookChain"])?.request?.length;
|
|
94
76
|
const headers = ext?.headers && isNotEmpty(ext.headers) ? Object.assign(nullObject(), ext.headers) : null;
|
|
95
77
|
if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
|
|
96
78
|
Object.defineProperty(headers, "\0", { value: headers });
|
|
@@ -98,11 +80,11 @@ function createContext(app) {
|
|
|
98
80
|
}
|
|
99
81
|
if (headers === null && !ext?.decorator && !ext?.store) {
|
|
100
82
|
sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
101
|
-
const context =
|
|
83
|
+
const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
|
|
102
84
|
contextCache.set(app, context);
|
|
103
85
|
return context;
|
|
104
86
|
}
|
|
105
|
-
const context = buildEmptyContext(createBaseContext(app), headers
|
|
87
|
+
const context = buildEmptyContext(createBaseContext(app), headers);
|
|
106
88
|
contextCache.set(app, context);
|
|
107
89
|
return context;
|
|
108
90
|
}
|
package/dist/cookie/index.d.ts
CHANGED
|
@@ -2,6 +2,5 @@ import { BaseCookie, CookieOptions } from "./types.js";
|
|
|
2
2
|
import { Cookie } from "./cookie.js";
|
|
3
3
|
import { serializeCookie } from "./serialize.js";
|
|
4
4
|
import { signCookie, unsignCookie } from "./crypto.js";
|
|
5
|
-
import { parseCookie } from "./utils.js";
|
|
6
5
|
import { InvalidCookie } from "./error.js";
|
|
7
|
-
export { type BaseCookie, Cookie, type CookieOptions, InvalidCookie,
|
|
6
|
+
export { type BaseCookie, Cookie, type CookieOptions, InvalidCookie, serializeCookie, signCookie, unsignCookie };
|
package/dist/cookie/index.js
CHANGED
|
@@ -3,11 +3,9 @@ const require_cookie_error = require('./error.js');
|
|
|
3
3
|
const require_cookie_serialize = require('./serialize.js');
|
|
4
4
|
const require_cookie_crypto = require('./crypto.js');
|
|
5
5
|
const require_cookie_cookie = require('./cookie.js');
|
|
6
|
-
const require_cookie_utils = require('./utils.js');
|
|
7
6
|
|
|
8
7
|
exports.Cookie = require_cookie_cookie.Cookie;
|
|
9
8
|
exports.InvalidCookie = require_cookie_error.InvalidCookie;
|
|
10
|
-
exports.parseCookie = require_cookie_utils.parseCookie;
|
|
11
9
|
exports.serializeCookie = require_cookie_serialize.serializeCookie;
|
|
12
10
|
exports.signCookie = require_cookie_crypto.signCookie;
|
|
13
11
|
exports.unsignCookie = require_cookie_crypto.unsignCookie;
|
package/dist/cookie/index.mjs
CHANGED
|
@@ -2,6 +2,5 @@ import { InvalidCookie } from "./error.mjs";
|
|
|
2
2
|
import { serializeCookie } from "./serialize.mjs";
|
|
3
3
|
import { signCookie, unsignCookie } from "./crypto.mjs";
|
|
4
4
|
import { Cookie } from "./cookie.mjs";
|
|
5
|
-
import { parseCookie } from "./utils.mjs";
|
|
6
5
|
|
|
7
|
-
export { Cookie, InvalidCookie,
|
|
6
|
+
export { Cookie, InvalidCookie, serializeCookie, signCookie, unsignCookie };
|
package/dist/cookie/lib.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_constants = require('../constants.js');
|
|
2
3
|
const require_utils = require('../utils.js');
|
|
3
4
|
const require_cookie_error = require('./error.js');
|
|
4
5
|
|
|
@@ -21,7 +22,7 @@ function parse(str) {
|
|
|
21
22
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
22
23
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
23
24
|
const key = str.slice(ks, ke);
|
|
24
|
-
if (obj[key] === void 0) {
|
|
25
|
+
if (obj[key] === void 0 && !require_constants.dangerousKeys.has(key)) {
|
|
25
26
|
let vs = eq + 1, ve = semi;
|
|
26
27
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
27
28
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
package/dist/cookie/lib.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dangerousKeys } from "../constants.mjs";
|
|
1
2
|
import { nullObject } from "../utils.mjs";
|
|
2
3
|
import { InvalidCookie } from "./error.mjs";
|
|
3
4
|
|
|
@@ -20,7 +21,7 @@ function parse(str) {
|
|
|
20
21
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
21
22
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
22
23
|
const key = str.slice(ks, ke);
|
|
23
|
-
if (obj[key] === void 0) {
|
|
24
|
+
if (obj[key] === void 0 && !dangerousKeys.has(key)) {
|
|
24
25
|
let vs = eq + 1, ve = semi;
|
|
25
26
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
26
27
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
package/dist/cookie/utils.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { CookieOptions } from "./types.js";
|
|
2
1
|
import { Cookie } from "./cookie.js";
|
|
3
2
|
import { Context } from "../context.js";
|
|
4
|
-
import { CompiledCookieConfig } from "./config.js";
|
|
5
3
|
import { hasSyncHmac } from "./crypto.js";
|
|
4
|
+
import { CompiledCookieConfig } from "./config.js";
|
|
6
5
|
|
|
7
6
|
//#region src/cookie/utils.d.ts
|
|
8
|
-
declare function
|
|
9
|
-
sign?: true | string | string[];
|
|
10
|
-
}): Promise<Record<string, Cookie<unknown>>>;
|
|
11
|
-
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig): Record<string, unknown>;
|
|
7
|
+
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig): any;
|
|
12
8
|
/**
|
|
13
9
|
* Unsigned + unvalidated lane only
|
|
14
10
|
*
|
|
@@ -22,4 +18,4 @@ declare function parseCookieRawSigned(cookieString: string | null | undefined, c
|
|
|
22
18
|
declare function buildCookieJar(set: Context['set'], raw: Record<string, unknown>, config: CompiledCookieConfig, lazySign?: 1, deferDecode?: 1): Record<string, Cookie<unknown>>;
|
|
23
19
|
declare function signCookieValues(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig): Promise<void> | undefined;
|
|
24
20
|
//#endregion
|
|
25
|
-
export { buildCookieJar, hasSyncHmac,
|
|
21
|
+
export { buildCookieJar, hasSyncHmac, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|
package/dist/cookie/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_constants = require('../constants.js');
|
|
4
3
|
const require_utils = require('../utils.js');
|
|
5
4
|
const require_cookie_lib = require('./lib.js');
|
|
6
5
|
const require_cookie_crypto = require('./crypto.js');
|
|
@@ -10,16 +9,11 @@ let deuri = require("deuri");
|
|
|
10
9
|
deuri = require_runtime.__toESM(deuri);
|
|
11
10
|
|
|
12
11
|
//#region src/cookie/utils.ts
|
|
13
|
-
async function parseCookie(set, cookieString, options) {
|
|
14
|
-
const config = require_cookie_config.compileCookieConfig(void 0, options);
|
|
15
|
-
return buildCookieJar(set, await parseCookieRaw(cookieString, config), config);
|
|
16
|
-
}
|
|
17
12
|
function parseCookieRawSync(cookieString, _config) {
|
|
18
|
-
|
|
19
|
-
if (!cookieString) return out;
|
|
13
|
+
if (!cookieString) return require_utils.nullObject();
|
|
20
14
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
15
|
+
const out = cookies;
|
|
21
16
|
for (const name in cookies) {
|
|
22
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
23
17
|
const v = cookies[name];
|
|
24
18
|
if (v === void 0) continue;
|
|
25
19
|
out[name] = require_cookie_crypto.maybeJsonDecode((0, deuri.default)(v) ?? v);
|
|
@@ -33,23 +27,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
33
27
|
* the raw record before the handler touches a name.
|
|
34
28
|
*/
|
|
35
29
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
36
|
-
|
|
37
|
-
if (!cookieString) return out;
|
|
38
|
-
const cookies = require_cookie_lib.parse(cookieString);
|
|
39
|
-
for (const name in cookies) {
|
|
40
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
41
|
-
const v = cookies[name];
|
|
42
|
-
if (v === void 0) continue;
|
|
43
|
-
out[name] = v;
|
|
44
|
-
}
|
|
45
|
-
return out;
|
|
30
|
+
return cookieString ? require_cookie_lib.parse(cookieString) : require_utils.nullObject();
|
|
46
31
|
}
|
|
47
32
|
function parseCookieRawLazy(cookieString, config) {
|
|
48
|
-
|
|
49
|
-
if (!cookieString) return out;
|
|
33
|
+
if (!cookieString) return require_utils.nullObject();
|
|
50
34
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
35
|
+
const out = cookies;
|
|
51
36
|
for (const name in cookies) {
|
|
52
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
53
37
|
const v = cookies[name];
|
|
54
38
|
if (v === void 0) continue;
|
|
55
39
|
const decoded = (0, deuri.default)(v) ?? v;
|
|
@@ -60,11 +44,10 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
60
44
|
async function parseCookieRaw(cookieString, config) {
|
|
61
45
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
62
46
|
if (require_cookie_crypto.hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
63
|
-
|
|
64
|
-
if (!cookieString) return out;
|
|
47
|
+
if (!cookieString) return require_utils.nullObject();
|
|
65
48
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
49
|
+
const out = cookies;
|
|
66
50
|
for (const name in cookies) {
|
|
67
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
68
51
|
const v = cookies[name];
|
|
69
52
|
if (v === void 0) continue;
|
|
70
53
|
let value = (0, deuri.default)(v) ?? v;
|
|
@@ -76,11 +59,10 @@ async function parseCookieRaw(cookieString, config) {
|
|
|
76
59
|
}
|
|
77
60
|
function parseCookieRawSigned(cookieString, config) {
|
|
78
61
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
79
|
-
|
|
80
|
-
if (!cookieString) return out;
|
|
62
|
+
if (!cookieString) return require_utils.nullObject();
|
|
81
63
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
64
|
+
const out = cookies;
|
|
82
65
|
for (const name in cookies) {
|
|
83
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
84
66
|
const v = cookies[name];
|
|
85
67
|
if (v === void 0) continue;
|
|
86
68
|
let value = (0, deuri.default)(v) ?? v;
|
|
@@ -187,7 +169,6 @@ async function signPending(pending) {
|
|
|
187
169
|
//#endregion
|
|
188
170
|
exports.buildCookieJar = buildCookieJar;
|
|
189
171
|
exports.hasSyncHmac = require_cookie_crypto.hasSyncHmac;
|
|
190
|
-
exports.parseCookie = parseCookie;
|
|
191
172
|
exports.parseCookieRaw = parseCookieRaw;
|
|
192
173
|
exports.parseCookieRawDeferred = parseCookieRawDeferred;
|
|
193
174
|
exports.parseCookieRawLazy = parseCookieRawLazy;
|
package/dist/cookie/utils.mjs
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { dangerousKeys } from "../constants.mjs";
|
|
2
1
|
import { nullObject } from "../utils.mjs";
|
|
3
2
|
import { parse } from "./lib.mjs";
|
|
4
3
|
import { deriveSignKey, hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieSyncImpl, unsignWithSecrets, unsignWithSecretsSync } from "./crypto.mjs";
|
|
5
4
|
import { Cookie } from "./cookie.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { isCookieSigned, resolveSignSecrets } from "./config.mjs";
|
|
7
6
|
import decodeComponent from "deuri";
|
|
8
7
|
|
|
9
8
|
//#region src/cookie/utils.ts
|
|
10
|
-
async function parseCookie(set, cookieString, options) {
|
|
11
|
-
const config = compileCookieConfig(void 0, options);
|
|
12
|
-
return buildCookieJar(set, await parseCookieRaw(cookieString, config), config);
|
|
13
|
-
}
|
|
14
9
|
function parseCookieRawSync(cookieString, _config) {
|
|
15
|
-
|
|
16
|
-
if (!cookieString) return out;
|
|
10
|
+
if (!cookieString) return nullObject();
|
|
17
11
|
const cookies = parse(cookieString);
|
|
12
|
+
const out = cookies;
|
|
18
13
|
for (const name in cookies) {
|
|
19
|
-
if (dangerousKeys.has(name)) continue;
|
|
20
14
|
const v = cookies[name];
|
|
21
15
|
if (v === void 0) continue;
|
|
22
16
|
out[name] = maybeJsonDecode(decodeComponent(v) ?? v);
|
|
@@ -30,23 +24,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
30
24
|
* the raw record before the handler touches a name.
|
|
31
25
|
*/
|
|
32
26
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
33
|
-
|
|
34
|
-
if (!cookieString) return out;
|
|
35
|
-
const cookies = parse(cookieString);
|
|
36
|
-
for (const name in cookies) {
|
|
37
|
-
if (dangerousKeys.has(name)) continue;
|
|
38
|
-
const v = cookies[name];
|
|
39
|
-
if (v === void 0) continue;
|
|
40
|
-
out[name] = v;
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
27
|
+
return cookieString ? parse(cookieString) : nullObject();
|
|
43
28
|
}
|
|
44
29
|
function parseCookieRawLazy(cookieString, config) {
|
|
45
|
-
|
|
46
|
-
if (!cookieString) return out;
|
|
30
|
+
if (!cookieString) return nullObject();
|
|
47
31
|
const cookies = parse(cookieString);
|
|
32
|
+
const out = cookies;
|
|
48
33
|
for (const name in cookies) {
|
|
49
|
-
if (dangerousKeys.has(name)) continue;
|
|
50
34
|
const v = cookies[name];
|
|
51
35
|
if (v === void 0) continue;
|
|
52
36
|
const decoded = decodeComponent(v) ?? v;
|
|
@@ -57,11 +41,10 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
57
41
|
async function parseCookieRaw(cookieString, config) {
|
|
58
42
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
59
43
|
if (hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
60
|
-
|
|
61
|
-
if (!cookieString) return out;
|
|
44
|
+
if (!cookieString) return nullObject();
|
|
62
45
|
const cookies = parse(cookieString);
|
|
46
|
+
const out = cookies;
|
|
63
47
|
for (const name in cookies) {
|
|
64
|
-
if (dangerousKeys.has(name)) continue;
|
|
65
48
|
const v = cookies[name];
|
|
66
49
|
if (v === void 0) continue;
|
|
67
50
|
let value = decodeComponent(v) ?? v;
|
|
@@ -73,11 +56,10 @@ async function parseCookieRaw(cookieString, config) {
|
|
|
73
56
|
}
|
|
74
57
|
function parseCookieRawSigned(cookieString, config) {
|
|
75
58
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
76
|
-
|
|
77
|
-
if (!cookieString) return out;
|
|
59
|
+
if (!cookieString) return nullObject();
|
|
78
60
|
const cookies = parse(cookieString);
|
|
61
|
+
const out = cookies;
|
|
79
62
|
for (const name in cookies) {
|
|
80
|
-
if (dangerousKeys.has(name)) continue;
|
|
81
63
|
const v = cookies[name];
|
|
82
64
|
if (v === void 0) continue;
|
|
83
65
|
let value = decodeComponent(v) ?? v;
|
|
@@ -182,4 +164,4 @@ async function signPending(pending) {
|
|
|
182
164
|
}
|
|
183
165
|
|
|
184
166
|
//#endregion
|
|
185
|
-
export { buildCookieJar, hasSyncHmac,
|
|
167
|
+
export { buildCookieJar, hasSyncHmac, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|