elysia 2.0.0-beta.21 → 2.0.0-beta.22
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/_virtual/_rolldown/runtime.mjs +1 -0
- package/dist/adapter/bun/index.d.ts +6 -8
- package/dist/adapter/bun/index.js +6 -8
- package/dist/adapter/bun/index.mjs +7 -8
- package/dist/adapter/constants.mjs +1 -0
- package/dist/adapter/default-headers.mjs +1 -0
- package/dist/adapter/index.mjs +1 -0
- package/dist/adapter/origin.mjs +1 -0
- package/dist/adapter/response-ownership.mjs +1 -0
- package/dist/adapter/skip-clone.mjs +1 -0
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +5 -8
- package/dist/adapter/utils.js +24 -18
- package/dist/adapter/utils.mjs +25 -18
- package/dist/adapter/web-standard/handler.mjs +2 -1
- package/dist/adapter/web-standard/index.mjs +1 -0
- package/dist/adapter/web-standard/utils.mjs +1 -0
- package/dist/base.d.ts +118 -69
- package/dist/base.js +213 -193
- package/dist/base.mjs +220 -199
- package/dist/compile/aot-capture.js +2 -2
- package/dist/compile/aot-capture.mjs +4 -3
- package/dist/compile/aot-emit.js +7 -8
- package/dist/compile/aot-emit.mjs +8 -8
- package/dist/compile/aot-reconstruct.mjs +3 -2
- package/dist/compile/aot.d.ts +3 -3
- package/dist/compile/aot.js +5 -5
- package/dist/compile/aot.mjs +6 -5
- package/dist/compile/handler/descriptor.d.ts +2 -5
- package/dist/compile/handler/descriptor.js +12 -17
- package/dist/compile/handler/descriptor.mjs +16 -21
- package/dist/compile/handler/frozen-validator.d.ts +2 -2
- package/dist/compile/handler/frozen-validator.js +3 -3
- package/dist/compile/handler/frozen-validator.mjs +4 -3
- package/dist/compile/handler/index.d.ts +3 -1
- package/dist/compile/handler/index.js +77 -118
- package/dist/compile/handler/index.mjs +83 -125
- package/dist/compile/handler/jit.d.ts +12 -12
- package/dist/compile/handler/jit.js +60 -43
- package/dist/compile/handler/jit.mjs +63 -47
- package/dist/compile/handler/params.d.ts +5 -1
- package/dist/compile/handler/params.js +14 -5
- package/dist/compile/handler/params.mjs +16 -7
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +2 -2
- package/dist/compile/handler/reconstruct.mjs +3 -2
- package/dist/compile/handler/static-clone-resolver.mjs +1 -0
- package/dist/compile/handler/utils.d.ts +13 -7
- package/dist/compile/handler/utils.js +75 -52
- package/dist/compile/handler/utils.mjs +77 -54
- package/dist/compile/jit-probe.mjs +1 -0
- package/dist/compile/lexer.js +4 -4
- package/dist/compile/lexer.mjs +5 -4
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +8 -3
- package/dist/compile/utils.mjs +8 -3
- package/dist/compiled.mjs +1 -0
- package/dist/constants.mjs +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.d.ts +2 -2
- package/dist/cookie/config.js +21 -26
- package/dist/cookie/config.mjs +22 -26
- package/dist/cookie/cookie.mjs +1 -0
- package/dist/cookie/crypto.mjs +1 -0
- package/dist/cookie/error.mjs +1 -0
- package/dist/cookie/lib.mjs +1 -0
- package/dist/cookie/serialize.mjs +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +1 -1
- package/dist/cookie/utils.js +64 -45
- package/dist/cookie/utils.mjs +66 -46
- package/dist/error.d.ts +10 -6
- package/dist/error.js +22 -6
- package/dist/error.mjs +25 -9
- package/dist/generation.mjs +1 -0
- package/dist/handler/error.d.ts +12 -15
- package/dist/handler/error.js +43 -40
- package/dist/handler/error.mjs +45 -41
- package/dist/handler/fetch.js +59 -21
- package/dist/handler/fetch.mjs +61 -22
- package/dist/handler/utils.d.ts +16 -3
- package/dist/handler/utils.js +14 -13
- package/dist/handler/utils.mjs +16 -15
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -0
- package/dist/index.mjs +3 -2
- package/dist/memory.mjs +1 -0
- package/dist/package.js +1 -1
- package/dist/package.mjs +2 -1
- package/dist/parse-query.js +76 -76
- package/dist/parse-query.mjs +77 -76
- package/dist/plugin/aot/bun.mjs +1 -0
- package/dist/plugin/aot/core.js +7 -4
- package/dist/plugin/aot/core.mjs +8 -5
- package/dist/plugin/aot/esbuild.mjs +1 -0
- package/dist/plugin/aot/rspack-loader.mjs +1 -0
- package/dist/plugin/aot/rspack.mjs +1 -0
- package/dist/plugin/aot/treeshake.mjs +1 -0
- package/dist/plugin/aot/unplugin.mjs +4 -3
- package/dist/plugin/aot/vite.mjs +1 -0
- package/dist/plugin/aot/worker.mjs +1 -0
- package/dist/plugin/auto-head.mjs +1 -0
- package/dist/plugin/trace.mjs +1 -0
- package/dist/plugin/websocket.mjs +1 -0
- package/dist/route-table.mjs +1 -0
- package/dist/schema-snapshot.mjs +1 -0
- package/dist/sucrose.d.ts +2 -2
- package/dist/sucrose.js +11 -11
- package/dist/sucrose.mjs +12 -11
- package/dist/trace.js +8 -10
- package/dist/trace.mjs +10 -11
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.mjs +1 -0
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/bridge.mjs +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.mjs +1 -0
- package/dist/type/compat.mjs +1 -0
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/constants.mjs +1 -0
- package/dist/type/elysia/accelerate.mjs +1 -0
- package/dist/type/elysia/array-buffer.d.ts +3 -2
- package/dist/type/elysia/array-buffer.js +5 -5
- package/dist/type/elysia/array-buffer.mjs +6 -5
- package/dist/type/elysia/array-string.mjs +1 -0
- package/dist/type/elysia/array.mjs +1 -0
- package/dist/type/elysia/boolean-string.mjs +1 -0
- package/dist/type/elysia/boolean.mjs +1 -0
- package/dist/type/elysia/cookie.mjs +1 -0
- package/dist/type/elysia/date.mjs +1 -0
- package/dist/type/elysia/file-type.mjs +1 -0
- package/dist/type/elysia/file.mjs +1 -0
- package/dist/type/elysia/files.mjs +1 -0
- package/dist/type/elysia/form.mjs +1 -0
- package/dist/type/elysia/integer-string.mjs +1 -0
- package/dist/type/elysia/integer.mjs +1 -0
- package/dist/type/elysia/intersect.mjs +1 -0
- package/dist/type/elysia/json-string.mjs +1 -0
- package/dist/type/elysia/keep-config.js +8 -8
- package/dist/type/elysia/keep-config.mjs +9 -8
- package/dist/type/elysia/maybe-empty.mjs +1 -0
- package/dist/type/elysia/no-validate.mjs +1 -0
- package/dist/type/elysia/nullable.mjs +1 -0
- package/dist/type/elysia/number.mjs +1 -0
- package/dist/type/elysia/numeric-enum.d.ts +4 -2
- package/dist/type/elysia/numeric-enum.mjs +1 -0
- package/dist/type/elysia/numeric.mjs +1 -0
- package/dist/type/elysia/object-string.mjs +1 -0
- package/dist/type/elysia/object.mjs +1 -0
- package/dist/type/elysia/optional.mjs +1 -0
- package/dist/type/elysia/problem.mjs +1 -0
- package/dist/type/elysia/string.mjs +1 -0
- package/dist/type/elysia/uint8-array.d.ts +2 -1
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +3 -2
- package/dist/type/elysia/union-enum.mjs +1 -0
- package/dist/type/elysia/union.mjs +1 -0
- package/dist/type/elysia/utils.js +3 -3
- package/dist/type/elysia/utils.mjs +4 -3
- package/dist/type/exports.mjs +1 -0
- package/dist/type/index.mjs +2 -1
- package/dist/type/shared.mjs +1 -0
- package/dist/type/sync-require.mjs +1 -0
- package/dist/type/typebox-system-lite.mjs +1 -0
- package/dist/type/typebox-system-require.mjs +1 -0
- package/dist/type/typebox-type-live.mjs +1 -0
- package/dist/type/typebox-value-live.mjs +1 -0
- package/dist/type/typebox-value-ops.mjs +1 -0
- package/dist/type/typebox-value.mjs +1 -0
- package/dist/type/types.d.ts +1 -1
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.mjs +1 -0
- package/dist/type/validator/clean-safe.mjs +1 -0
- package/dist/type/validator/custom-error.js +41 -33
- package/dist/type/validator/custom-error.mjs +42 -33
- package/dist/type/validator/default-precompute.d.ts +2 -2
- package/dist/type/validator/default-precompute.js +10 -11
- package/dist/type/validator/default-precompute.mjs +13 -13
- package/dist/type/validator/exact-mirror.mjs +1 -0
- package/dist/type/validator/frozen-check.js +7 -7
- package/dist/type/validator/frozen-check.mjs +8 -7
- package/dist/type/validator/index.d.ts +2 -2
- package/dist/type/validator/index.js +4 -8
- package/dist/type/validator/index.mjs +5 -8
- package/dist/type/validator/string-codec-aot.d.ts +1 -1
- package/dist/type/validator/string-codec-aot.mjs +1 -0
- package/dist/type/validator/validator-cache.js +18 -18
- package/dist/type/validator/validator-cache.mjs +19 -18
- package/dist/types.d.ts +105 -69
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.mjs +1 -0
- package/dist/universal/file.mjs +1 -0
- package/dist/universal/index.mjs +1 -0
- package/dist/universal/is-production.mjs +1 -0
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +49 -31
- package/dist/utils.js +221 -109
- package/dist/utils.mjs +215 -106
- package/dist/validator/index.d.ts +3 -3
- package/dist/validator/index.js +4 -4
- package/dist/validator/index.mjs +5 -4
- package/dist/validator/route.d.ts +2 -2
- package/dist/validator/route.mjs +1 -0
- package/dist/ws/context.js +1 -1
- package/dist/ws/context.mjs +2 -1
- package/dist/ws/index.mjs +1 -0
- package/dist/ws/parser.mjs +1 -0
- package/dist/ws/route.js +34 -25
- package/dist/ws/route.mjs +40 -30
- package/dist/ws/types.d.ts +2 -3
- package/dist/ws/types.mjs +1 -0
- package/package.json +2 -2
package/dist/compile/utils.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { MaybeArray } from "../types.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/compile/utils.d.ts
|
|
4
4
|
declare function isAsyncFunction(fn: Function): boolean;
|
|
5
|
+
declare const resetMayReturnPromiseCache: () => void;
|
|
5
6
|
declare function mayReturnPromise(fn: Function): boolean;
|
|
6
7
|
declare const isAsyncLifecycle: (handlers: MaybeArray<Function> | undefined) => boolean;
|
|
7
8
|
//#endregion
|
|
8
|
-
export { isAsyncFunction, isAsyncLifecycle, mayReturnPromise };
|
|
9
|
+
export { isAsyncFunction, isAsyncLifecycle, mayReturnPromise, resetMayReturnPromiseCache };
|
package/dist/compile/utils.js
CHANGED
|
@@ -7,14 +7,18 @@ function isAsyncFunction(fn) {
|
|
|
7
7
|
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
8
8
|
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
9
9
|
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
10
|
-
|
|
10
|
+
let mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
const resetMayReturnPromiseCache = () => {
|
|
12
|
+
mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
};
|
|
11
14
|
function mayReturnPromise(fn) {
|
|
12
15
|
let result = mayReturnPromiseCache.get(fn);
|
|
13
16
|
if (result !== void 0) return result;
|
|
14
17
|
const literal = Function.prototype.toString.call(fn).trim();
|
|
15
18
|
const arrow = matchArrow.exec(literal);
|
|
16
19
|
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
17
|
-
|
|
20
|
+
const neverPromise = body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body);
|
|
21
|
+
result = literal.includes("[native code]") || !neverPromise;
|
|
18
22
|
mayReturnPromiseCache.set(fn, result);
|
|
19
23
|
return result;
|
|
20
24
|
}
|
|
@@ -23,4 +27,5 @@ const isAsyncLifecycle = (handlers) => handlers ? Array.isArray(handlers) ? hand
|
|
|
23
27
|
//#endregion
|
|
24
28
|
exports.isAsyncFunction = isAsyncFunction;
|
|
25
29
|
exports.isAsyncLifecycle = isAsyncLifecycle;
|
|
26
|
-
exports.mayReturnPromise = mayReturnPromise;
|
|
30
|
+
exports.mayReturnPromise = mayReturnPromise;
|
|
31
|
+
exports.resetMayReturnPromiseCache = resetMayReturnPromiseCache;
|
package/dist/compile/utils.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
//#region src/compile/utils.ts
|
|
2
3
|
function isAsyncFunction(fn) {
|
|
3
4
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
@@ -5,18 +6,22 @@ function isAsyncFunction(fn) {
|
|
|
5
6
|
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
6
7
|
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
7
8
|
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
8
|
-
|
|
9
|
+
let mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
const resetMayReturnPromiseCache = () => {
|
|
11
|
+
mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
};
|
|
9
13
|
function mayReturnPromise(fn) {
|
|
10
14
|
let result = mayReturnPromiseCache.get(fn);
|
|
11
15
|
if (result !== void 0) return result;
|
|
12
16
|
const literal = Function.prototype.toString.call(fn).trim();
|
|
13
17
|
const arrow = matchArrow.exec(literal);
|
|
14
18
|
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
15
|
-
|
|
19
|
+
const neverPromise = body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body);
|
|
20
|
+
result = literal.includes("[native code]") || !neverPromise;
|
|
16
21
|
mayReturnPromiseCache.set(fn, result);
|
|
17
22
|
return result;
|
|
18
23
|
}
|
|
19
24
|
const isAsyncLifecycle = (handlers) => handlers ? Array.isArray(handlers) ? handlers.some(isAsyncFunction) : isAsyncFunction(handlers) : false;
|
|
20
25
|
|
|
21
26
|
//#endregion
|
|
22
|
-
export { isAsyncFunction, isAsyncLifecycle, mayReturnPromise };
|
|
27
|
+
export { isAsyncFunction, isAsyncLifecycle, mayReturnPromise, resetMayReturnPromiseCache };
|
package/dist/compiled.mjs
CHANGED
package/dist/constants.mjs
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseCookie } from "./cookie/types.js";
|
|
2
1
|
import { StatusMap } from "./constants.js";
|
|
3
2
|
import { SelectiveProblem, SelectiveStatus, problem, status } from "./error.js";
|
|
4
3
|
import { redirect } from "./utils.js";
|
|
5
4
|
import { Server } from "./universal/server.js";
|
|
5
|
+
import { BaseCookie } from "./cookie/types.js";
|
|
6
6
|
import { Cookie } from "./cookie/cookie.js";
|
|
7
7
|
import { AfterResponseHandler, DefaultSingleton, HTTPHeaders, InputSchema, MaybePromise, Prettify, ResolvePath, RouteSchema, SingletonBase } from "./types.js";
|
|
8
8
|
import { AnyElysia } from "./base.js";
|
package/dist/context.js
CHANGED
|
@@ -19,6 +19,7 @@ const defer = {
|
|
|
19
19
|
function buildDecorator(members) {
|
|
20
20
|
class Decorator {}
|
|
21
21
|
Object.assign(Decorator.prototype, members);
|
|
22
|
+
for (const key of Reflect.ownKeys(members)) require_utils.markSingletons(members[key], 0);
|
|
22
23
|
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
23
24
|
return Decorator;
|
|
24
25
|
}
|
package/dist/context.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
import { isNotEmpty, markSingletons, nullObject, redirect } from "./utils.mjs";
|
|
2
3
|
import { problem, status } from "./error.mjs";
|
|
3
4
|
import { defaultHeaders } from "./adapter/default-headers.mjs";
|
|
4
5
|
|
|
@@ -18,6 +19,7 @@ const defer = {
|
|
|
18
19
|
function buildDecorator(members) {
|
|
19
20
|
class Decorator {}
|
|
20
21
|
Object.assign(Decorator.prototype, members);
|
|
22
|
+
for (const key of Reflect.ownKeys(members)) markSingletons(members[key], 0);
|
|
21
23
|
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
22
24
|
return Decorator;
|
|
23
25
|
}
|
package/dist/cookie/config.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface CompiledCookieConfig {
|
|
|
24
24
|
declare function compileCookieConfig(routeSchema: AnySchema | string | undefined, appConfig: AppCookieConfig | undefined, models?: Record<string, unknown>, schemas?: {
|
|
25
25
|
cookie?: unknown;
|
|
26
26
|
}[]): CompiledCookieConfig;
|
|
27
|
-
declare const
|
|
27
|
+
declare const acceptsLegacySignature: (name: string, config: CompiledCookieConfig) => boolean;
|
|
28
28
|
declare function resolveSignSecrets(name: string, config: CompiledCookieConfig): CompiledCookieConfig['globalSecrets'] | undefined;
|
|
29
29
|
declare function isCookieSigned(name: string, config: CompiledCookieConfig): {
|
|
30
30
|
signed: true;
|
|
@@ -33,4 +33,4 @@ declare function isCookieSigned(name: string, config: CompiledCookieConfig): {
|
|
|
33
33
|
signed: false;
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
36
|
-
export { AppCookieConfig, CompiledCookieConfig, FieldCookieConfig, compileCookieConfig, isCookieSigned,
|
|
36
|
+
export { AppCookieConfig, CompiledCookieConfig, FieldCookieConfig, acceptsLegacySignature, compileCookieConfig, isCookieSigned, resolveSignSecrets };
|
package/dist/cookie/config.js
CHANGED
|
@@ -16,35 +16,30 @@ const ATTRIBUTE_KEYS = new Set([
|
|
|
16
16
|
]);
|
|
17
17
|
function getAttributes(source) {
|
|
18
18
|
if (!source) return;
|
|
19
|
-
const keys = Object.keys(source);
|
|
20
|
-
if (!keys.length) return;
|
|
21
19
|
let out;
|
|
22
|
-
for (const key of keys) if (ATTRIBUTE_KEYS.has(key))
|
|
23
|
-
out ??= require_utils.nullObject();
|
|
24
|
-
out[key] = source[key];
|
|
25
|
-
}
|
|
20
|
+
for (const key of Object.keys(source)) if (ATTRIBUTE_KEYS.has(key)) (out ??= require_utils.nullObject())[key] = source[key];
|
|
26
21
|
return out;
|
|
27
22
|
}
|
|
28
23
|
const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
|
|
29
|
-
const
|
|
24
|
+
const emptyGathered = () => ({
|
|
30
25
|
config: require_utils.nullObject(),
|
|
31
26
|
fields: require_utils.nullObject()
|
|
32
27
|
});
|
|
33
|
-
function
|
|
28
|
+
function comparableConfig(config) {
|
|
34
29
|
const out = require_utils.nullObject();
|
|
35
|
-
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ?
|
|
30
|
+
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ? listKey(config[key]) : config[key];
|
|
36
31
|
return out;
|
|
37
32
|
}
|
|
38
|
-
const
|
|
33
|
+
const signlessKey = (from) => {
|
|
39
34
|
const fields = require_utils.nullObject();
|
|
40
35
|
for (const name of Object.keys(from.fields).sort()) {
|
|
41
|
-
const field =
|
|
36
|
+
const field = comparableConfig(from.fields[name]);
|
|
42
37
|
if (Object.keys(field).length) fields[name] = field;
|
|
43
38
|
}
|
|
44
|
-
return JSON.stringify([
|
|
39
|
+
return JSON.stringify([comparableConfig(from.config), fields]);
|
|
45
40
|
};
|
|
46
|
-
const
|
|
47
|
-
const
|
|
41
|
+
const badRefError = () => /* @__PURE__ */ new Error("[Elysia] Cookie schema `$ref` is unresolvable or ambiguous; use a model name or `$id` instead");
|
|
42
|
+
const listKey = (value) => JSON.stringify(typeof value === "string" ? [value] : value);
|
|
48
43
|
function foldConfig(into, config) {
|
|
49
44
|
for (const key in config) {
|
|
50
45
|
const value = config[key];
|
|
@@ -52,19 +47,19 @@ function foldConfig(into, config) {
|
|
|
52
47
|
if (value === void 0) continue;
|
|
53
48
|
if (prev === void 0) into[key] = value;
|
|
54
49
|
else if (key === "sign") into.sign = prev === true || value === true || [].concat(prev, value);
|
|
55
|
-
else if ((key === "secrets" || key === "legacySignature") &&
|
|
50
|
+
else if ((key === "secrets" || key === "legacySignature") && listKey(prev) !== listKey(value)) throw new Error(`[Elysia] Merged cookie schemas disagree on \`${key}\``);
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
59
54
|
const roots = [routeSchema, ...(schemas ?? []).map((schema) => schema?.cookie).reverse()].map((schema) => typeof schema === "string" ? models?.[schema] : schema);
|
|
60
|
-
let
|
|
61
|
-
const resolve = (name) => (
|
|
55
|
+
let findTargets;
|
|
56
|
+
const resolve = (name) => (findTargets ??= require_utils.refTargets(roots, models))(name);
|
|
62
57
|
const gather = (schema, into, field, path) => {
|
|
63
58
|
if (!schema || path.has(schema)) return;
|
|
64
59
|
path.add(schema);
|
|
65
60
|
const ref = schema.$ref;
|
|
66
61
|
const targets = typeof ref === "string" ? [...resolve(ref)] : [ref];
|
|
67
|
-
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw
|
|
62
|
+
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw badRefError();
|
|
68
63
|
if (field === void 0) {
|
|
69
64
|
foldConfig(into.config, schema.config);
|
|
70
65
|
for (const name in schema.properties) gather(schema.properties[name], into, name, /* @__PURE__ */ new Set());
|
|
@@ -72,9 +67,9 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
72
67
|
if (targets.length > 1) {
|
|
73
68
|
let first;
|
|
74
69
|
for (const target of targets) {
|
|
75
|
-
const from =
|
|
70
|
+
const from = emptyGathered();
|
|
76
71
|
gather(target, from, field, path);
|
|
77
|
-
if ((first ??=
|
|
72
|
+
if ((first ??= signlessKey(from)) !== signlessKey(from)) throw badRefError();
|
|
78
73
|
foldConfig(into.config, from.config);
|
|
79
74
|
for (const name in from.fields) foldConfig(into.fields[name] ??= require_utils.nullObject(), from.fields[name]);
|
|
80
75
|
}
|
|
@@ -83,7 +78,7 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
83
78
|
if (schema["~kind"] === "Deferred") for (const operand of [].concat(schema.parameters?.[0])) gather(operand, into, field, path);
|
|
84
79
|
path.delete(schema);
|
|
85
80
|
};
|
|
86
|
-
const route =
|
|
81
|
+
const route = emptyGathered();
|
|
87
82
|
for (const root of roots) gather(root, route, void 0, /* @__PURE__ */ new Set());
|
|
88
83
|
const routeConfig = route.config;
|
|
89
84
|
const fieldConfigs = route.fields;
|
|
@@ -94,13 +89,13 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
94
89
|
...routeAttributes
|
|
95
90
|
} : appAttributes ?? routeAttributes ?? require_utils.nullObject();
|
|
96
91
|
if (!defaults.path) defaults.path = "/";
|
|
97
|
-
const rawSign = routeConfig
|
|
92
|
+
const rawSign = routeConfig.sign ?? appConfig?.sign;
|
|
98
93
|
let globalSign;
|
|
99
94
|
if (rawSign === void 0) globalSign = void 0;
|
|
100
95
|
else if (rawSign === true) globalSign = true;
|
|
101
96
|
else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
|
|
102
97
|
else globalSign = [rawSign];
|
|
103
|
-
const globalSecrets = routeConfig
|
|
98
|
+
const globalSecrets = routeConfig.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
|
|
104
99
|
const fields = require_utils.nullObject();
|
|
105
100
|
let hasSign = false;
|
|
106
101
|
for (const name in fieldConfigs) {
|
|
@@ -132,10 +127,10 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
132
127
|
globalSecrets,
|
|
133
128
|
hasSign,
|
|
134
129
|
verify: appConfig?.verify ?? "lazy",
|
|
135
|
-
legacySignature: (routeConfig
|
|
130
|
+
legacySignature: (routeConfig.legacySignature ?? appConfig?.legacySignature) !== false
|
|
136
131
|
};
|
|
137
132
|
}
|
|
138
|
-
const
|
|
133
|
+
const acceptsLegacySignature = (name, config) => config.fields[name]?.legacySignature ?? config.legacySignature;
|
|
139
134
|
function resolveSignSecrets(name, config) {
|
|
140
135
|
const field = config.fields[name];
|
|
141
136
|
if (field?.sign) return field.secrets ?? config.globalSecrets;
|
|
@@ -152,7 +147,7 @@ function isCookieSigned(name, config) {
|
|
|
152
147
|
}
|
|
153
148
|
|
|
154
149
|
//#endregion
|
|
150
|
+
exports.acceptsLegacySignature = acceptsLegacySignature;
|
|
155
151
|
exports.compileCookieConfig = compileCookieConfig;
|
|
156
152
|
exports.isCookieSigned = isCookieSigned;
|
|
157
|
-
exports.legacySignatureOf = legacySignatureOf;
|
|
158
153
|
exports.resolveSignSecrets = resolveSignSecrets;
|
package/dist/cookie/config.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { compositionKeys, nullObject, refTargets } from "../utils.mjs";
|
|
2
3
|
import { InvalidCookie } from "./error.mjs";
|
|
3
4
|
|
|
@@ -15,35 +16,30 @@ const ATTRIBUTE_KEYS = new Set([
|
|
|
15
16
|
]);
|
|
16
17
|
function getAttributes(source) {
|
|
17
18
|
if (!source) return;
|
|
18
|
-
const keys = Object.keys(source);
|
|
19
|
-
if (!keys.length) return;
|
|
20
19
|
let out;
|
|
21
|
-
for (const key of keys) if (ATTRIBUTE_KEYS.has(key))
|
|
22
|
-
out ??= nullObject();
|
|
23
|
-
out[key] = source[key];
|
|
24
|
-
}
|
|
20
|
+
for (const key of Object.keys(source)) if (ATTRIBUTE_KEYS.has(key)) (out ??= nullObject())[key] = source[key];
|
|
25
21
|
return out;
|
|
26
22
|
}
|
|
27
23
|
const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
|
|
28
|
-
const
|
|
24
|
+
const emptyGathered = () => ({
|
|
29
25
|
config: nullObject(),
|
|
30
26
|
fields: nullObject()
|
|
31
27
|
});
|
|
32
|
-
function
|
|
28
|
+
function comparableConfig(config) {
|
|
33
29
|
const out = nullObject();
|
|
34
|
-
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ?
|
|
30
|
+
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ? listKey(config[key]) : config[key];
|
|
35
31
|
return out;
|
|
36
32
|
}
|
|
37
|
-
const
|
|
33
|
+
const signlessKey = (from) => {
|
|
38
34
|
const fields = nullObject();
|
|
39
35
|
for (const name of Object.keys(from.fields).sort()) {
|
|
40
|
-
const field =
|
|
36
|
+
const field = comparableConfig(from.fields[name]);
|
|
41
37
|
if (Object.keys(field).length) fields[name] = field;
|
|
42
38
|
}
|
|
43
|
-
return JSON.stringify([
|
|
39
|
+
return JSON.stringify([comparableConfig(from.config), fields]);
|
|
44
40
|
};
|
|
45
|
-
const
|
|
46
|
-
const
|
|
41
|
+
const badRefError = () => /* @__PURE__ */ new Error("[Elysia] Cookie schema `$ref` is unresolvable or ambiguous; use a model name or `$id` instead");
|
|
42
|
+
const listKey = (value) => JSON.stringify(typeof value === "string" ? [value] : value);
|
|
47
43
|
function foldConfig(into, config) {
|
|
48
44
|
for (const key in config) {
|
|
49
45
|
const value = config[key];
|
|
@@ -51,19 +47,19 @@ function foldConfig(into, config) {
|
|
|
51
47
|
if (value === void 0) continue;
|
|
52
48
|
if (prev === void 0) into[key] = value;
|
|
53
49
|
else if (key === "sign") into.sign = prev === true || value === true || [].concat(prev, value);
|
|
54
|
-
else if ((key === "secrets" || key === "legacySignature") &&
|
|
50
|
+
else if ((key === "secrets" || key === "legacySignature") && listKey(prev) !== listKey(value)) throw new Error(`[Elysia] Merged cookie schemas disagree on \`${key}\``);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
58
54
|
const roots = [routeSchema, ...(schemas ?? []).map((schema) => schema?.cookie).reverse()].map((schema) => typeof schema === "string" ? models?.[schema] : schema);
|
|
59
|
-
let
|
|
60
|
-
const resolve = (name) => (
|
|
55
|
+
let findTargets;
|
|
56
|
+
const resolve = (name) => (findTargets ??= refTargets(roots, models))(name);
|
|
61
57
|
const gather = (schema, into, field, path) => {
|
|
62
58
|
if (!schema || path.has(schema)) return;
|
|
63
59
|
path.add(schema);
|
|
64
60
|
const ref = schema.$ref;
|
|
65
61
|
const targets = typeof ref === "string" ? [...resolve(ref)] : [ref];
|
|
66
|
-
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw
|
|
62
|
+
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw badRefError();
|
|
67
63
|
if (field === void 0) {
|
|
68
64
|
foldConfig(into.config, schema.config);
|
|
69
65
|
for (const name in schema.properties) gather(schema.properties[name], into, name, /* @__PURE__ */ new Set());
|
|
@@ -71,9 +67,9 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
71
67
|
if (targets.length > 1) {
|
|
72
68
|
let first;
|
|
73
69
|
for (const target of targets) {
|
|
74
|
-
const from =
|
|
70
|
+
const from = emptyGathered();
|
|
75
71
|
gather(target, from, field, path);
|
|
76
|
-
if ((first ??=
|
|
72
|
+
if ((first ??= signlessKey(from)) !== signlessKey(from)) throw badRefError();
|
|
77
73
|
foldConfig(into.config, from.config);
|
|
78
74
|
for (const name in from.fields) foldConfig(into.fields[name] ??= nullObject(), from.fields[name]);
|
|
79
75
|
}
|
|
@@ -82,7 +78,7 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
82
78
|
if (schema["~kind"] === "Deferred") for (const operand of [].concat(schema.parameters?.[0])) gather(operand, into, field, path);
|
|
83
79
|
path.delete(schema);
|
|
84
80
|
};
|
|
85
|
-
const route =
|
|
81
|
+
const route = emptyGathered();
|
|
86
82
|
for (const root of roots) gather(root, route, void 0, /* @__PURE__ */ new Set());
|
|
87
83
|
const routeConfig = route.config;
|
|
88
84
|
const fieldConfigs = route.fields;
|
|
@@ -93,13 +89,13 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
93
89
|
...routeAttributes
|
|
94
90
|
} : appAttributes ?? routeAttributes ?? nullObject();
|
|
95
91
|
if (!defaults.path) defaults.path = "/";
|
|
96
|
-
const rawSign = routeConfig
|
|
92
|
+
const rawSign = routeConfig.sign ?? appConfig?.sign;
|
|
97
93
|
let globalSign;
|
|
98
94
|
if (rawSign === void 0) globalSign = void 0;
|
|
99
95
|
else if (rawSign === true) globalSign = true;
|
|
100
96
|
else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
|
|
101
97
|
else globalSign = [rawSign];
|
|
102
|
-
const globalSecrets = routeConfig
|
|
98
|
+
const globalSecrets = routeConfig.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
|
|
103
99
|
const fields = nullObject();
|
|
104
100
|
let hasSign = false;
|
|
105
101
|
for (const name in fieldConfigs) {
|
|
@@ -131,10 +127,10 @@ function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
|
131
127
|
globalSecrets,
|
|
132
128
|
hasSign,
|
|
133
129
|
verify: appConfig?.verify ?? "lazy",
|
|
134
|
-
legacySignature: (routeConfig
|
|
130
|
+
legacySignature: (routeConfig.legacySignature ?? appConfig?.legacySignature) !== false
|
|
135
131
|
};
|
|
136
132
|
}
|
|
137
|
-
const
|
|
133
|
+
const acceptsLegacySignature = (name, config) => config.fields[name]?.legacySignature ?? config.legacySignature;
|
|
138
134
|
function resolveSignSecrets(name, config) {
|
|
139
135
|
const field = config.fields[name];
|
|
140
136
|
if (field?.sign) return field.secrets ?? config.globalSecrets;
|
|
@@ -151,4 +147,4 @@ function isCookieSigned(name, config) {
|
|
|
151
147
|
}
|
|
152
148
|
|
|
153
149
|
//#endregion
|
|
154
|
-
export { compileCookieConfig, isCookieSigned,
|
|
150
|
+
export { acceptsLegacySignature, compileCookieConfig, isCookieSigned, resolveSignSecrets };
|
package/dist/cookie/cookie.mjs
CHANGED
package/dist/cookie/crypto.mjs
CHANGED
package/dist/cookie/error.mjs
CHANGED
package/dist/cookie/lib.mjs
CHANGED
package/dist/cookie/types.mjs
CHANGED
package/dist/cookie/utils.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ declare function parseCookieRawLazy(cookieString: string | null | undefined, con
|
|
|
16
16
|
declare function parseCookieRaw(cookieString: string | null | undefined, config: CompiledCookieConfig, lazy?: 1): Promise<Record<string, unknown>>;
|
|
17
17
|
declare function parseCookieRawSigned(cookieString: string | null | undefined, config: CompiledCookieConfig, lazy?: 1): Record<string, unknown>;
|
|
18
18
|
declare function buildCookieJar(set: Context['set'], raw: Record<string, unknown>, config: CompiledCookieConfig, lazySign?: 1, deferDecode?: 1): Record<string, Cookie<unknown>>;
|
|
19
|
-
declare function signCookieValues(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig): Promise<void> | undefined;
|
|
19
|
+
declare function signCookieValues(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig, set?: Context['set']): Promise<void> | undefined;
|
|
20
20
|
//#endregion
|
|
21
21
|
export { buildCookieJar, hasSyncHmac, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|
package/dist/cookie/utils.js
CHANGED
|
@@ -43,13 +43,13 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
43
43
|
return out;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* Stands in for a signed cookie that failed verification on a lane that can't
|
|
47
|
+
* verify on access (async HMAC, AOT); the jar rejects its first read.
|
|
48
|
+
* String key so a second Elysia copy agrees; null-prototype, which
|
|
49
|
+
* `JSON.parse` never yields, so no client-sent value (unsigned, or accepted by a
|
|
50
|
+
* `null` rotation secret) can forge it
|
|
51
51
|
*/
|
|
52
|
-
const
|
|
52
|
+
const invalidSignatureMarker = () => {
|
|
53
53
|
const marker = require_utils.nullObject();
|
|
54
54
|
marker["~invalid"] = 1;
|
|
55
55
|
return marker;
|
|
@@ -66,10 +66,10 @@ async function parseCookieRaw(cookieString, config, lazy) {
|
|
|
66
66
|
let value = (0, deuri.default)(v) ?? v;
|
|
67
67
|
const signCheck = require_cookie_config.resolveSignSecrets(name, config);
|
|
68
68
|
if (signCheck !== void 0) try {
|
|
69
|
-
value = await require_cookie_crypto.unsignWithSecrets(name, value, signCheck, require_cookie_config.
|
|
69
|
+
value = await require_cookie_crypto.unsignWithSecrets(name, value, signCheck, require_cookie_config.acceptsLegacySignature(name, config));
|
|
70
70
|
} catch (error) {
|
|
71
71
|
if (!lazy || !(error instanceof require_cookie_error.InvalidCookie)) throw error;
|
|
72
|
-
out[name] =
|
|
72
|
+
out[name] = invalidSignatureMarker();
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
out[name] = require_cookie_crypto.maybeJsonDecode(value);
|
|
@@ -87,31 +87,38 @@ function parseCookieRawSigned(cookieString, config, lazy) {
|
|
|
87
87
|
let value = (0, deuri.default)(v) ?? v;
|
|
88
88
|
const signCheck = require_cookie_config.resolveSignSecrets(name, config);
|
|
89
89
|
if (signCheck !== void 0) try {
|
|
90
|
-
value = require_cookie_crypto.unsignWithSecretsSync(name, value, signCheck, require_cookie_config.
|
|
90
|
+
value = require_cookie_crypto.unsignWithSecretsSync(name, value, signCheck, require_cookie_config.acceptsLegacySignature(name, config));
|
|
91
91
|
} catch (error) {
|
|
92
92
|
if (!lazy || !(error instanceof require_cookie_error.InvalidCookie)) throw error;
|
|
93
|
-
out[name] =
|
|
93
|
+
out[name] = invalidSignatureMarker();
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
96
|
out[name] = require_cookie_crypto.maybeJsonDecode(value);
|
|
97
97
|
}
|
|
98
98
|
return out;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
var CookieJarHandler = class {
|
|
101
|
+
constructor(setRef, config, lazySign, deferDecode) {
|
|
102
|
+
this.setRef = setRef;
|
|
103
|
+
this.config = config;
|
|
104
|
+
this.lazySign = lazySign;
|
|
105
|
+
this.deferDecode = deferDecode;
|
|
106
|
+
this.materialized = void 0;
|
|
107
|
+
this.cache = void 0;
|
|
108
|
+
}
|
|
109
|
+
materialize(store, name) {
|
|
110
|
+
if (this.materialized?.[name]) return store[name];
|
|
111
|
+
const config = this.config;
|
|
105
112
|
const rawValue = store[name];
|
|
106
113
|
const fieldDefaults = config.fields[name]?.defaults;
|
|
107
|
-
const entry = Object.assign(require_utils.nullObject(), config.defaults, fieldDefaults, { value: deferDecode ? require_cookie_crypto.maybeJsonDecode((0, deuri.default)(rawValue) ?? rawValue) : rawValue });
|
|
114
|
+
const entry = Object.assign(require_utils.nullObject(), config.defaults, fieldDefaults, { value: this.deferDecode ? require_cookie_crypto.maybeJsonDecode((0, deuri.default)(rawValue) ?? rawValue) : rawValue });
|
|
108
115
|
if (entry.expires instanceof Date) entry.expires = new Date(entry.expires.getTime());
|
|
109
116
|
if (rawValue?.["~invalid"] === 1 && Object.getPrototypeOf(rawValue) === null) entry["~unsign"] = 1;
|
|
110
|
-
else if (lazySign && typeof entry.value === "string") {
|
|
117
|
+
else if (this.lazySign && typeof entry.value === "string") {
|
|
111
118
|
const secrets = require_cookie_config.resolveSignSecrets(name, config);
|
|
112
119
|
if (secrets !== void 0) {
|
|
113
120
|
entry["~unsign"] = secrets;
|
|
114
|
-
if (!require_cookie_config.
|
|
121
|
+
if (!require_cookie_config.acceptsLegacySignature(name, config)) entry["~strict"] = 1;
|
|
115
122
|
}
|
|
116
123
|
} else {
|
|
117
124
|
const value = entry.value;
|
|
@@ -121,33 +128,33 @@ function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
store[name] = entry;
|
|
124
|
-
materialized[name] = 1;
|
|
131
|
+
(this.materialized ??= require_utils.nullObject())[name] = 1;
|
|
125
132
|
return entry;
|
|
126
133
|
}
|
|
127
|
-
|
|
128
|
-
function settle(key) {
|
|
134
|
+
settle(store, key) {
|
|
129
135
|
if (!(key in store)) return;
|
|
130
|
-
const entry =
|
|
136
|
+
const entry = this.materialize(store, key);
|
|
131
137
|
if ("~unsign" in entry) require_cookie_crypto.resolvePendingCookie(entry, key);
|
|
132
138
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
ownKeys(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
get(store, key) {
|
|
140
|
+
return (this.cache ??= require_utils.nullObject())[key] ??= new require_cookie_cookie.Cookie(key, this.setRef, key in store ? this.materialize(store, key) : Object.assign(require_utils.nullObject(), this.config.defaults, this.config.fields[key]?.defaults));
|
|
141
|
+
}
|
|
142
|
+
has(store, key) {
|
|
143
|
+
if (typeof key === "string") this.settle(store, key);
|
|
144
|
+
return Reflect.has(store, key);
|
|
145
|
+
}
|
|
146
|
+
ownKeys(store) {
|
|
147
|
+
const keys = Reflect.ownKeys(store);
|
|
148
|
+
for (let i = 0; i < keys.length; i++) this.settle(store, keys[i]);
|
|
149
|
+
return keys;
|
|
150
|
+
}
|
|
151
|
+
getOwnPropertyDescriptor(store, key) {
|
|
152
|
+
if (typeof key === "string") this.settle(store, key);
|
|
153
|
+
return Reflect.getOwnPropertyDescriptor(store, key);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
157
|
+
return new Proxy(raw, new CookieJarHandler(set, config, lazySign, deferDecode));
|
|
151
158
|
}
|
|
152
159
|
function collectSignPending(cookies, config) {
|
|
153
160
|
if (!cookies || !config.hasSign) return;
|
|
@@ -174,12 +181,24 @@ function collectSignPending(cookies, config) {
|
|
|
174
181
|
}
|
|
175
182
|
return pending;
|
|
176
183
|
}
|
|
177
|
-
function dropSigned(cookies, config) {
|
|
178
|
-
|
|
184
|
+
function dropSigned(cookies, config, set) {
|
|
185
|
+
if (set) Object.defineProperty(set, "~signFailed", {
|
|
186
|
+
value: true,
|
|
187
|
+
configurable: true
|
|
188
|
+
});
|
|
189
|
+
const signed = (name) => config.fields[name]?.sign || config.globalSign === true || config.globalSignSet?.has(name);
|
|
190
|
+
let kept = false;
|
|
191
|
+
for (const name in cookies) if (signed(name) && !Reflect.deleteProperty(cookies, name)) kept = true;
|
|
192
|
+
if (kept && set?.cookie === cookies) {
|
|
193
|
+
const copy = require_utils.nullObject();
|
|
194
|
+
for (const name in cookies) if (!signed(name)) copy[name] = cookies[name];
|
|
195
|
+
set.cookie = copy;
|
|
196
|
+
}
|
|
179
197
|
}
|
|
180
|
-
function signCookieValues(cookies, config) {
|
|
198
|
+
function signCookieValues(cookies, config, set) {
|
|
181
199
|
let pending;
|
|
182
200
|
try {
|
|
201
|
+
if (set?.["~signFailed"]) throw new TypeError("A signed cookie of this request failed to sign");
|
|
183
202
|
pending = collectSignPending(cookies, config);
|
|
184
203
|
if (!pending) return;
|
|
185
204
|
if (require_cookie_crypto.hasSyncHmac) {
|
|
@@ -190,11 +209,11 @@ function signCookieValues(cookies, config) {
|
|
|
190
209
|
return;
|
|
191
210
|
}
|
|
192
211
|
} catch (error) {
|
|
193
|
-
dropSigned(cookies, config);
|
|
212
|
+
dropSigned(cookies, config, set);
|
|
194
213
|
throw error;
|
|
195
214
|
}
|
|
196
215
|
return signPending(pending).catch((error) => {
|
|
197
|
-
dropSigned(cookies, config);
|
|
216
|
+
dropSigned(cookies, config, set);
|
|
198
217
|
throw error;
|
|
199
218
|
});
|
|
200
219
|
}
|