elysia 2.0.0-beta.2 → 2.0.0-beta.21
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.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- 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 +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -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/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
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
|
|
|
@@ -17,58 +16,45 @@ const defer = {
|
|
|
17
16
|
return append;
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
|
-
function
|
|
19
|
+
function buildDecorator(members) {
|
|
21
20
|
class Decorator {}
|
|
22
|
-
Object.assign(Decorator.prototype,
|
|
23
|
-
status: require_error.status,
|
|
24
|
-
redirect: require_utils.redirect
|
|
25
|
-
});
|
|
21
|
+
Object.assign(Decorator.prototype, members);
|
|
26
22
|
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
27
23
|
return Decorator;
|
|
28
24
|
}
|
|
25
|
+
const buildEmptyDecorator = () => buildDecorator({
|
|
26
|
+
status: require_error.status,
|
|
27
|
+
problem: require_error.problem,
|
|
28
|
+
redirect: require_utils.redirect
|
|
29
|
+
});
|
|
29
30
|
function createBaseContext(app) {
|
|
30
31
|
const ext = app["~ext"];
|
|
31
32
|
const decorator = ext?.decorator;
|
|
32
33
|
const store = ext?.store;
|
|
33
34
|
if (!decorator && !store) return sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
34
|
-
|
|
35
|
-
Object.assign(Decorator.prototype, {
|
|
35
|
+
return buildDecorator({
|
|
36
36
|
...decorator,
|
|
37
37
|
store,
|
|
38
38
|
status: require_error.status,
|
|
39
|
+
problem: require_error.problem,
|
|
39
40
|
redirect: require_utils.redirect
|
|
40
41
|
});
|
|
41
|
-
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
42
|
-
return Decorator;
|
|
43
42
|
}
|
|
44
|
-
function clearContextCache() {
|
|
43
|
+
function clearContextCache(app) {
|
|
44
|
+
if (app !== void 0) {
|
|
45
|
+
contextCache.delete(app);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
45
48
|
contextCache = /* @__PURE__ */ new WeakMap();
|
|
46
49
|
sharedEmptyDecorator = null;
|
|
47
50
|
sharedEmptyContext = null;
|
|
48
51
|
}
|
|
49
|
-
|
|
50
|
-
function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
|
|
52
|
+
function buildEmptyContext(Base, headers = null) {
|
|
51
53
|
const immutableHeaders = headers !== null && Object.isFrozen(headers);
|
|
52
|
-
let warnedPathMutation = false;
|
|
53
|
-
const pathDescriptor = warnPathMutation ? {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
configurable: true,
|
|
56
|
-
get() {
|
|
57
|
-
return this[pathValue];
|
|
58
|
-
},
|
|
59
|
-
set(value) {
|
|
60
|
-
if (pathValue in this && !warnedPathMutation) {
|
|
61
|
-
warnedPathMutation = true;
|
|
62
|
-
console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
|
|
63
|
-
}
|
|
64
|
-
this[pathValue] = value;
|
|
65
|
-
}
|
|
66
|
-
} : void 0;
|
|
67
54
|
class Context extends Base {
|
|
68
55
|
constructor(request) {
|
|
69
56
|
super();
|
|
70
57
|
this.request = request;
|
|
71
|
-
if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
|
|
72
58
|
if (immutableHeaders) this.set = {
|
|
73
59
|
headers,
|
|
74
60
|
status: void 0,
|
|
@@ -88,7 +74,6 @@ function createContext(app) {
|
|
|
88
74
|
if (cached) return cached;
|
|
89
75
|
const ext = app["~ext"];
|
|
90
76
|
const adapter = app["~config"]?.adapter;
|
|
91
|
-
const warnPathMutation = !require_universal_is_production.isProduction() && !!require_utils.flattenChain(app["~hookChain"])?.request?.length;
|
|
92
77
|
const headers = ext?.headers && require_utils.isNotEmpty(ext.headers) ? Object.assign(require_utils.nullObject(), ext.headers) : null;
|
|
93
78
|
if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
|
|
94
79
|
Object.defineProperty(headers, "\0", { value: headers });
|
|
@@ -96,11 +81,11 @@ function createContext(app) {
|
|
|
96
81
|
}
|
|
97
82
|
if (headers === null && !ext?.decorator && !ext?.store) {
|
|
98
83
|
sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
99
|
-
const context =
|
|
84
|
+
const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
|
|
100
85
|
contextCache.set(app, context);
|
|
101
86
|
return context;
|
|
102
87
|
}
|
|
103
|
-
const context = buildEmptyContext(createBaseContext(app), headers
|
|
88
|
+
const context = buildEmptyContext(createBaseContext(app), headers);
|
|
104
89
|
contextCache.set(app, context);
|
|
105
90
|
return context;
|
|
106
91
|
}
|
package/dist/context.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { status } from "./error.mjs";
|
|
1
|
+
import { isNotEmpty, nullObject, redirect } from "./utils.mjs";
|
|
2
|
+
import { problem, status } from "./error.mjs";
|
|
4
3
|
import { defaultHeaders } from "./adapter/default-headers.mjs";
|
|
5
4
|
|
|
6
5
|
//#region src/context.ts
|
|
@@ -16,58 +15,45 @@ const defer = {
|
|
|
16
15
|
return append;
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
|
-
function
|
|
18
|
+
function buildDecorator(members) {
|
|
20
19
|
class Decorator {}
|
|
21
|
-
Object.assign(Decorator.prototype,
|
|
22
|
-
status,
|
|
23
|
-
redirect
|
|
24
|
-
});
|
|
20
|
+
Object.assign(Decorator.prototype, members);
|
|
25
21
|
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
26
22
|
return Decorator;
|
|
27
23
|
}
|
|
24
|
+
const buildEmptyDecorator = () => buildDecorator({
|
|
25
|
+
status,
|
|
26
|
+
problem,
|
|
27
|
+
redirect
|
|
28
|
+
});
|
|
28
29
|
function createBaseContext(app) {
|
|
29
30
|
const ext = app["~ext"];
|
|
30
31
|
const decorator = ext?.decorator;
|
|
31
32
|
const store = ext?.store;
|
|
32
33
|
if (!decorator && !store) return sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
33
|
-
|
|
34
|
-
Object.assign(Decorator.prototype, {
|
|
34
|
+
return buildDecorator({
|
|
35
35
|
...decorator,
|
|
36
36
|
store,
|
|
37
37
|
status,
|
|
38
|
+
problem,
|
|
38
39
|
redirect
|
|
39
40
|
});
|
|
40
|
-
Object.defineProperty(Decorator.prototype, "defer", defer);
|
|
41
|
-
return Decorator;
|
|
42
41
|
}
|
|
43
|
-
function clearContextCache() {
|
|
42
|
+
function clearContextCache(app) {
|
|
43
|
+
if (app !== void 0) {
|
|
44
|
+
contextCache.delete(app);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
44
47
|
contextCache = /* @__PURE__ */ new WeakMap();
|
|
45
48
|
sharedEmptyDecorator = null;
|
|
46
49
|
sharedEmptyContext = null;
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
|
|
51
|
+
function buildEmptyContext(Base, headers = null) {
|
|
50
52
|
const immutableHeaders = headers !== null && Object.isFrozen(headers);
|
|
51
|
-
let warnedPathMutation = false;
|
|
52
|
-
const pathDescriptor = warnPathMutation ? {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
get() {
|
|
56
|
-
return this[pathValue];
|
|
57
|
-
},
|
|
58
|
-
set(value) {
|
|
59
|
-
if (pathValue in this && !warnedPathMutation) {
|
|
60
|
-
warnedPathMutation = true;
|
|
61
|
-
console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
|
|
62
|
-
}
|
|
63
|
-
this[pathValue] = value;
|
|
64
|
-
}
|
|
65
|
-
} : void 0;
|
|
66
53
|
class Context extends Base {
|
|
67
54
|
constructor(request) {
|
|
68
55
|
super();
|
|
69
56
|
this.request = request;
|
|
70
|
-
if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
|
|
71
57
|
if (immutableHeaders) this.set = {
|
|
72
58
|
headers,
|
|
73
59
|
status: void 0,
|
|
@@ -87,7 +73,6 @@ function createContext(app) {
|
|
|
87
73
|
if (cached) return cached;
|
|
88
74
|
const ext = app["~ext"];
|
|
89
75
|
const adapter = app["~config"]?.adapter;
|
|
90
|
-
const warnPathMutation = !isProduction() && !!flattenChain(app["~hookChain"])?.request?.length;
|
|
91
76
|
const headers = ext?.headers && isNotEmpty(ext.headers) ? Object.assign(nullObject(), ext.headers) : null;
|
|
92
77
|
if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
|
|
93
78
|
Object.defineProperty(headers, "\0", { value: headers });
|
|
@@ -95,11 +80,11 @@ function createContext(app) {
|
|
|
95
80
|
}
|
|
96
81
|
if (headers === null && !ext?.decorator && !ext?.store) {
|
|
97
82
|
sharedEmptyDecorator ??= buildEmptyDecorator();
|
|
98
|
-
const context =
|
|
83
|
+
const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
|
|
99
84
|
contextCache.set(app, context);
|
|
100
85
|
return context;
|
|
101
86
|
}
|
|
102
|
-
const context = buildEmptyContext(createBaseContext(app), headers
|
|
87
|
+
const context = buildEmptyContext(createBaseContext(app), headers);
|
|
103
88
|
contextCache.set(app, context);
|
|
104
89
|
return context;
|
|
105
90
|
}
|
package/dist/cookie/config.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface FieldCookieConfig {
|
|
|
9
9
|
secrets?: string | null | (string | null)[];
|
|
10
10
|
sign: boolean;
|
|
11
11
|
defaults?: Partial<BaseCookie>;
|
|
12
|
+
legacySignature?: boolean;
|
|
12
13
|
}
|
|
13
14
|
interface CompiledCookieConfig {
|
|
14
15
|
defaults: Partial<BaseCookie>;
|
|
@@ -18,8 +19,12 @@ interface CompiledCookieConfig {
|
|
|
18
19
|
globalSecrets: string | null | (string | null)[] | undefined;
|
|
19
20
|
hasSign: boolean;
|
|
20
21
|
verify: 'lazy' | 'eager';
|
|
22
|
+
legacySignature: boolean;
|
|
21
23
|
}
|
|
22
|
-
declare function compileCookieConfig(routeSchema: AnySchema | undefined, appConfig: AppCookieConfig | undefined
|
|
24
|
+
declare function compileCookieConfig(routeSchema: AnySchema | string | undefined, appConfig: AppCookieConfig | undefined, models?: Record<string, unknown>, schemas?: {
|
|
25
|
+
cookie?: unknown;
|
|
26
|
+
}[]): CompiledCookieConfig;
|
|
27
|
+
declare const legacySignatureOf: (name: string, config: CompiledCookieConfig) => boolean;
|
|
23
28
|
declare function resolveSignSecrets(name: string, config: CompiledCookieConfig): CompiledCookieConfig['globalSecrets'] | undefined;
|
|
24
29
|
declare function isCookieSigned(name: string, config: CompiledCookieConfig): {
|
|
25
30
|
signed: true;
|
|
@@ -28,4 +33,4 @@ declare function isCookieSigned(name: string, config: CompiledCookieConfig): {
|
|
|
28
33
|
signed: false;
|
|
29
34
|
};
|
|
30
35
|
//#endregion
|
|
31
|
-
export { AppCookieConfig, CompiledCookieConfig, FieldCookieConfig, compileCookieConfig, isCookieSigned, resolveSignSecrets };
|
|
36
|
+
export { AppCookieConfig, CompiledCookieConfig, FieldCookieConfig, compileCookieConfig, isCookieSigned, legacySignatureOf, resolveSignSecrets };
|
package/dist/cookie/config.js
CHANGED
|
@@ -25,15 +25,68 @@ function getAttributes(source) {
|
|
|
25
25
|
}
|
|
26
26
|
return out;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
|
|
29
|
+
const gathered = () => ({
|
|
30
|
+
config: require_utils.nullObject(),
|
|
31
|
+
fields: require_utils.nullObject()
|
|
32
|
+
});
|
|
33
|
+
function canonical(config) {
|
|
34
|
+
const out = require_utils.nullObject();
|
|
35
|
+
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ? asList(config[key]) : config[key];
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
const unsigned = (from) => {
|
|
39
|
+
const fields = require_utils.nullObject();
|
|
40
|
+
for (const name of Object.keys(from.fields).sort()) {
|
|
41
|
+
const field = canonical(from.fields[name]);
|
|
42
|
+
if (Object.keys(field).length) fields[name] = field;
|
|
43
|
+
}
|
|
44
|
+
return JSON.stringify([canonical(from.config), fields]);
|
|
45
|
+
};
|
|
46
|
+
const unclear = () => /* @__PURE__ */ new Error("[Elysia] Cookie schema `$ref` is unresolvable or ambiguous; use a model name or `$id` instead");
|
|
47
|
+
const asList = (value) => JSON.stringify(typeof value === "string" ? [value] : value);
|
|
48
|
+
function foldConfig(into, config) {
|
|
49
|
+
for (const key in config) {
|
|
50
|
+
const value = config[key];
|
|
51
|
+
const prev = into[key];
|
|
52
|
+
if (value === void 0) continue;
|
|
53
|
+
if (prev === void 0) into[key] = value;
|
|
54
|
+
else if (key === "sign") into.sign = prev === true || value === true || [].concat(prev, value);
|
|
55
|
+
else if ((key === "secrets" || key === "legacySignature") && asList(prev) !== asList(value)) throw new Error(`[Elysia] Merged cookie schemas disagree on \`${key}\``);
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
59
|
+
const roots = [routeSchema, ...(schemas ?? []).map((schema) => schema?.cookie).reverse()].map((schema) => typeof schema === "string" ? models?.[schema] : schema);
|
|
60
|
+
let targets;
|
|
61
|
+
const resolve = (name) => (targets ??= require_utils.refTargets(roots, models))(name);
|
|
62
|
+
const gather = (schema, into, field, path) => {
|
|
63
|
+
if (!schema || path.has(schema)) return;
|
|
64
|
+
path.add(schema);
|
|
65
|
+
const ref = schema.$ref;
|
|
66
|
+
const targets = typeof ref === "string" ? [...resolve(ref)] : [ref];
|
|
67
|
+
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw unclear();
|
|
68
|
+
if (field === void 0) {
|
|
69
|
+
foldConfig(into.config, schema.config);
|
|
70
|
+
for (const name in schema.properties) gather(schema.properties[name], into, name, /* @__PURE__ */ new Set());
|
|
71
|
+
} else if (schema.config) foldConfig(into.fields[field] ??= require_utils.nullObject(), schema.config);
|
|
72
|
+
if (targets.length > 1) {
|
|
73
|
+
let first;
|
|
74
|
+
for (const target of targets) {
|
|
75
|
+
const from = gathered();
|
|
76
|
+
gather(target, from, field, path);
|
|
77
|
+
if ((first ??= unsigned(from)) !== unsigned(from)) throw unclear();
|
|
78
|
+
foldConfig(into.config, from.config);
|
|
79
|
+
for (const name in from.fields) foldConfig(into.fields[name] ??= require_utils.nullObject(), from.fields[name]);
|
|
80
|
+
}
|
|
81
|
+
} else gather(targets[0], into, field, path);
|
|
82
|
+
for (const key of require_utils.compositionKeys) if (Array.isArray(schema[key])) for (const member of schema[key]) gather(member, into, field, path);
|
|
83
|
+
if (schema["~kind"] === "Deferred") for (const operand of [].concat(schema.parameters?.[0])) gather(operand, into, field, path);
|
|
84
|
+
path.delete(schema);
|
|
85
|
+
};
|
|
86
|
+
const route = gathered();
|
|
87
|
+
for (const root of roots) gather(root, route, void 0, /* @__PURE__ */ new Set());
|
|
88
|
+
const routeConfig = route.config;
|
|
89
|
+
const fieldConfigs = route.fields;
|
|
37
90
|
const appAttributes = getAttributes(appConfig);
|
|
38
91
|
const routeAttributes = getAttributes(routeConfig);
|
|
39
92
|
const defaults = appAttributes && routeAttributes ? {
|
|
@@ -41,20 +94,24 @@ function compileCookieConfig(routeSchema, appConfig) {
|
|
|
41
94
|
...routeAttributes
|
|
42
95
|
} : appAttributes ?? routeAttributes ?? require_utils.nullObject();
|
|
43
96
|
if (!defaults.path) defaults.path = "/";
|
|
44
|
-
const
|
|
97
|
+
const rawSign = routeConfig?.sign ?? appConfig?.sign;
|
|
98
|
+
let globalSign;
|
|
99
|
+
if (rawSign === void 0) globalSign = void 0;
|
|
100
|
+
else if (rawSign === true) globalSign = true;
|
|
101
|
+
else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
|
|
102
|
+
else globalSign = [rawSign];
|
|
45
103
|
const globalSecrets = routeConfig?.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
|
|
46
104
|
const fields = require_utils.nullObject();
|
|
47
|
-
const properties = routeSchema?.properties;
|
|
48
105
|
let hasSign = false;
|
|
49
|
-
|
|
50
|
-
const config =
|
|
51
|
-
|
|
52
|
-
const sign = !!config.secrets || config.sign === true;
|
|
106
|
+
for (const name in fieldConfigs) {
|
|
107
|
+
const config = fieldConfigs[name];
|
|
108
|
+
const sign = config.secrets != null || config.sign === true;
|
|
53
109
|
if (sign) hasSign = true;
|
|
54
110
|
fields[name] = {
|
|
55
111
|
secrets: config.secrets,
|
|
56
112
|
sign,
|
|
57
|
-
defaults: getAttributes(config)
|
|
113
|
+
defaults: getAttributes(config),
|
|
114
|
+
legacySignature: config.legacySignature
|
|
58
115
|
};
|
|
59
116
|
}
|
|
60
117
|
if (globalSign !== void 0) hasSign = true;
|
|
@@ -74,9 +131,11 @@ function compileCookieConfig(routeSchema, appConfig) {
|
|
|
74
131
|
globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
|
|
75
132
|
globalSecrets,
|
|
76
133
|
hasSign,
|
|
77
|
-
verify: appConfig?.verify ?? "lazy"
|
|
134
|
+
verify: appConfig?.verify ?? "lazy",
|
|
135
|
+
legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
|
|
78
136
|
};
|
|
79
137
|
}
|
|
138
|
+
const legacySignatureOf = (name, config) => config.fields[name]?.legacySignature ?? config.legacySignature;
|
|
80
139
|
function resolveSignSecrets(name, config) {
|
|
81
140
|
const field = config.fields[name];
|
|
82
141
|
if (field?.sign) return field.secrets ?? config.globalSecrets;
|
|
@@ -95,4 +154,5 @@ function isCookieSigned(name, config) {
|
|
|
95
154
|
//#endregion
|
|
96
155
|
exports.compileCookieConfig = compileCookieConfig;
|
|
97
156
|
exports.isCookieSigned = isCookieSigned;
|
|
157
|
+
exports.legacySignatureOf = legacySignatureOf;
|
|
98
158
|
exports.resolveSignSecrets = resolveSignSecrets;
|
package/dist/cookie/config.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nullObject } from "../utils.mjs";
|
|
1
|
+
import { compositionKeys, nullObject, refTargets } from "../utils.mjs";
|
|
2
2
|
import { InvalidCookie } from "./error.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/cookie/config.ts
|
|
@@ -24,15 +24,68 @@ function getAttributes(source) {
|
|
|
24
24
|
}
|
|
25
25
|
return out;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
|
|
28
|
+
const gathered = () => ({
|
|
29
|
+
config: nullObject(),
|
|
30
|
+
fields: nullObject()
|
|
31
|
+
});
|
|
32
|
+
function canonical(config) {
|
|
33
|
+
const out = nullObject();
|
|
34
|
+
for (const key of Object.keys(config).sort()) if (key !== "sign") out[key] = key === "secrets" ? asList(config[key]) : config[key];
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
const unsigned = (from) => {
|
|
38
|
+
const fields = nullObject();
|
|
39
|
+
for (const name of Object.keys(from.fields).sort()) {
|
|
40
|
+
const field = canonical(from.fields[name]);
|
|
41
|
+
if (Object.keys(field).length) fields[name] = field;
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify([canonical(from.config), fields]);
|
|
44
|
+
};
|
|
45
|
+
const unclear = () => /* @__PURE__ */ new Error("[Elysia] Cookie schema `$ref` is unresolvable or ambiguous; use a model name or `$id` instead");
|
|
46
|
+
const asList = (value) => JSON.stringify(typeof value === "string" ? [value] : value);
|
|
47
|
+
function foldConfig(into, config) {
|
|
48
|
+
for (const key in config) {
|
|
49
|
+
const value = config[key];
|
|
50
|
+
const prev = into[key];
|
|
51
|
+
if (value === void 0) continue;
|
|
52
|
+
if (prev === void 0) into[key] = value;
|
|
53
|
+
else if (key === "sign") into.sign = prev === true || value === true || [].concat(prev, value);
|
|
54
|
+
else if ((key === "secrets" || key === "legacySignature") && asList(prev) !== asList(value)) throw new Error(`[Elysia] Merged cookie schemas disagree on \`${key}\``);
|
|
55
|
+
}
|
|
32
56
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
function compileCookieConfig(routeSchema, appConfig, models, schemas) {
|
|
58
|
+
const roots = [routeSchema, ...(schemas ?? []).map((schema) => schema?.cookie).reverse()].map((schema) => typeof schema === "string" ? models?.[schema] : schema);
|
|
59
|
+
let targets;
|
|
60
|
+
const resolve = (name) => (targets ??= refTargets(roots, models))(name);
|
|
61
|
+
const gather = (schema, into, field, path) => {
|
|
62
|
+
if (!schema || path.has(schema)) return;
|
|
63
|
+
path.add(schema);
|
|
64
|
+
const ref = schema.$ref;
|
|
65
|
+
const targets = typeof ref === "string" ? [...resolve(ref)] : [ref];
|
|
66
|
+
if (typeof ref === "string" && !targets.length || schema.$dynamicRef !== void 0 || schema.$recursiveRef !== void 0) throw unclear();
|
|
67
|
+
if (field === void 0) {
|
|
68
|
+
foldConfig(into.config, schema.config);
|
|
69
|
+
for (const name in schema.properties) gather(schema.properties[name], into, name, /* @__PURE__ */ new Set());
|
|
70
|
+
} else if (schema.config) foldConfig(into.fields[field] ??= nullObject(), schema.config);
|
|
71
|
+
if (targets.length > 1) {
|
|
72
|
+
let first;
|
|
73
|
+
for (const target of targets) {
|
|
74
|
+
const from = gathered();
|
|
75
|
+
gather(target, from, field, path);
|
|
76
|
+
if ((first ??= unsigned(from)) !== unsigned(from)) throw unclear();
|
|
77
|
+
foldConfig(into.config, from.config);
|
|
78
|
+
for (const name in from.fields) foldConfig(into.fields[name] ??= nullObject(), from.fields[name]);
|
|
79
|
+
}
|
|
80
|
+
} else gather(targets[0], into, field, path);
|
|
81
|
+
for (const key of compositionKeys) if (Array.isArray(schema[key])) for (const member of schema[key]) gather(member, into, field, path);
|
|
82
|
+
if (schema["~kind"] === "Deferred") for (const operand of [].concat(schema.parameters?.[0])) gather(operand, into, field, path);
|
|
83
|
+
path.delete(schema);
|
|
84
|
+
};
|
|
85
|
+
const route = gathered();
|
|
86
|
+
for (const root of roots) gather(root, route, void 0, /* @__PURE__ */ new Set());
|
|
87
|
+
const routeConfig = route.config;
|
|
88
|
+
const fieldConfigs = route.fields;
|
|
36
89
|
const appAttributes = getAttributes(appConfig);
|
|
37
90
|
const routeAttributes = getAttributes(routeConfig);
|
|
38
91
|
const defaults = appAttributes && routeAttributes ? {
|
|
@@ -40,20 +93,24 @@ function compileCookieConfig(routeSchema, appConfig) {
|
|
|
40
93
|
...routeAttributes
|
|
41
94
|
} : appAttributes ?? routeAttributes ?? nullObject();
|
|
42
95
|
if (!defaults.path) defaults.path = "/";
|
|
43
|
-
const
|
|
96
|
+
const rawSign = routeConfig?.sign ?? appConfig?.sign;
|
|
97
|
+
let globalSign;
|
|
98
|
+
if (rawSign === void 0) globalSign = void 0;
|
|
99
|
+
else if (rawSign === true) globalSign = true;
|
|
100
|
+
else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
|
|
101
|
+
else globalSign = [rawSign];
|
|
44
102
|
const globalSecrets = routeConfig?.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
|
|
45
103
|
const fields = nullObject();
|
|
46
|
-
const properties = routeSchema?.properties;
|
|
47
104
|
let hasSign = false;
|
|
48
|
-
|
|
49
|
-
const config =
|
|
50
|
-
|
|
51
|
-
const sign = !!config.secrets || config.sign === true;
|
|
105
|
+
for (const name in fieldConfigs) {
|
|
106
|
+
const config = fieldConfigs[name];
|
|
107
|
+
const sign = config.secrets != null || config.sign === true;
|
|
52
108
|
if (sign) hasSign = true;
|
|
53
109
|
fields[name] = {
|
|
54
110
|
secrets: config.secrets,
|
|
55
111
|
sign,
|
|
56
|
-
defaults: getAttributes(config)
|
|
112
|
+
defaults: getAttributes(config),
|
|
113
|
+
legacySignature: config.legacySignature
|
|
57
114
|
};
|
|
58
115
|
}
|
|
59
116
|
if (globalSign !== void 0) hasSign = true;
|
|
@@ -73,9 +130,11 @@ function compileCookieConfig(routeSchema, appConfig) {
|
|
|
73
130
|
globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
|
|
74
131
|
globalSecrets,
|
|
75
132
|
hasSign,
|
|
76
|
-
verify: appConfig?.verify ?? "lazy"
|
|
133
|
+
verify: appConfig?.verify ?? "lazy",
|
|
134
|
+
legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
|
|
77
135
|
};
|
|
78
136
|
}
|
|
137
|
+
const legacySignatureOf = (name, config) => config.fields[name]?.legacySignature ?? config.legacySignature;
|
|
79
138
|
function resolveSignSecrets(name, config) {
|
|
80
139
|
const field = config.fields[name];
|
|
81
140
|
if (field?.sign) return field.secrets ?? config.globalSecrets;
|
|
@@ -92,4 +151,4 @@ function isCookieSigned(name, config) {
|
|
|
92
151
|
}
|
|
93
152
|
|
|
94
153
|
//#endregion
|
|
95
|
-
export { compileCookieConfig, isCookieSigned, resolveSignSecrets };
|
|
154
|
+
export { compileCookieConfig, isCookieSigned, legacySignatureOf, resolveSignSecrets };
|
package/dist/cookie/cookie.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ declare class Cookie<T = any> implements BaseCookie {
|
|
|
10
10
|
constructor(name: string, setRef: {
|
|
11
11
|
cookie?: Record<string, BaseCookie>;
|
|
12
12
|
}, initial?: Partial<BaseCookie>);
|
|
13
|
+
static isCookie(v: unknown): v is Cookie;
|
|
13
14
|
get cookie(): BaseCookie;
|
|
14
15
|
set cookie(jar: BaseCookie);
|
|
15
16
|
protected get setCookie(): BaseCookie;
|
|
16
|
-
protected set setCookie(jar: BaseCookie);
|
|
17
17
|
get value(): T;
|
|
18
18
|
set value(value: T);
|
|
19
19
|
update(config: Updater<Partial<BaseCookie>>): this;
|
package/dist/cookie/cookie.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils = require('../utils.js');
|
|
2
3
|
const require_cookie_crypto = require('./crypto.js');
|
|
3
4
|
|
|
4
5
|
//#region src/cookie/cookie.ts
|
|
@@ -23,6 +24,9 @@ var Cookie = class {
|
|
|
23
24
|
this.#setRef = setRef;
|
|
24
25
|
this.#initial = initial;
|
|
25
26
|
}
|
|
27
|
+
static isCookie(v) {
|
|
28
|
+
return typeof v === "object" && v !== null && #name in v;
|
|
29
|
+
}
|
|
26
30
|
get #jar() {
|
|
27
31
|
return this.#setRef.cookie ??= Object.create(null);
|
|
28
32
|
}
|
|
@@ -41,9 +45,6 @@ var Cookie = class {
|
|
|
41
45
|
if (entry && "~unsign" in entry) require_cookie_crypto.resolvePendingCookie(entry, this.#name);
|
|
42
46
|
return entry;
|
|
43
47
|
}
|
|
44
|
-
set setCookie(jar) {
|
|
45
|
-
this.cookie = jar;
|
|
46
|
-
}
|
|
47
48
|
get value() {
|
|
48
49
|
const cookie = this.cookie;
|
|
49
50
|
const value = cookie.value;
|
|
@@ -56,22 +57,19 @@ var Cookie = class {
|
|
|
56
57
|
set value(value) {
|
|
57
58
|
if (this.cookie.value === value && (!value || typeof value !== "object")) return;
|
|
58
59
|
const j = this.#jar;
|
|
59
|
-
if (!(this.#name in j)) j[this.#name] =
|
|
60
|
+
if (!(this.#name in j)) j[this.#name] = Object.assign(require_utils.nullObject(), this.#initial);
|
|
60
61
|
j[this.#name].value = value;
|
|
61
62
|
}
|
|
62
63
|
update(config) {
|
|
63
64
|
const cookie = Object.assign(this.cookie, typeof config === "function" ? config(this.cookie) : config);
|
|
64
65
|
delete cookie["~raw"];
|
|
65
|
-
this.
|
|
66
|
+
this.cookie = cookie;
|
|
66
67
|
return this;
|
|
67
68
|
}
|
|
68
69
|
set(config) {
|
|
69
|
-
const cookie = Object.assign({
|
|
70
|
-
...this.#initial,
|
|
71
|
-
value: this.value
|
|
72
|
-
}, typeof config === "function" ? config(this.cookie) : config);
|
|
70
|
+
const cookie = Object.assign(require_utils.nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
|
|
73
71
|
delete cookie["~raw"];
|
|
74
|
-
this.
|
|
72
|
+
this.cookie = cookie;
|
|
75
73
|
return this;
|
|
76
74
|
}
|
|
77
75
|
remove() {
|
package/dist/cookie/cookie.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nullObject } from "../utils.mjs";
|
|
1
2
|
import { resolvePendingCookie } from "./crypto.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/cookie/cookie.ts
|
|
@@ -22,6 +23,9 @@ var Cookie = class {
|
|
|
22
23
|
this.#setRef = setRef;
|
|
23
24
|
this.#initial = initial;
|
|
24
25
|
}
|
|
26
|
+
static isCookie(v) {
|
|
27
|
+
return typeof v === "object" && v !== null && #name in v;
|
|
28
|
+
}
|
|
25
29
|
get #jar() {
|
|
26
30
|
return this.#setRef.cookie ??= Object.create(null);
|
|
27
31
|
}
|
|
@@ -40,9 +44,6 @@ var Cookie = class {
|
|
|
40
44
|
if (entry && "~unsign" in entry) resolvePendingCookie(entry, this.#name);
|
|
41
45
|
return entry;
|
|
42
46
|
}
|
|
43
|
-
set setCookie(jar) {
|
|
44
|
-
this.cookie = jar;
|
|
45
|
-
}
|
|
46
47
|
get value() {
|
|
47
48
|
const cookie = this.cookie;
|
|
48
49
|
const value = cookie.value;
|
|
@@ -55,22 +56,19 @@ var Cookie = class {
|
|
|
55
56
|
set value(value) {
|
|
56
57
|
if (this.cookie.value === value && (!value || typeof value !== "object")) return;
|
|
57
58
|
const j = this.#jar;
|
|
58
|
-
if (!(this.#name in j)) j[this.#name] =
|
|
59
|
+
if (!(this.#name in j)) j[this.#name] = Object.assign(nullObject(), this.#initial);
|
|
59
60
|
j[this.#name].value = value;
|
|
60
61
|
}
|
|
61
62
|
update(config) {
|
|
62
63
|
const cookie = Object.assign(this.cookie, typeof config === "function" ? config(this.cookie) : config);
|
|
63
64
|
delete cookie["~raw"];
|
|
64
|
-
this.
|
|
65
|
+
this.cookie = cookie;
|
|
65
66
|
return this;
|
|
66
67
|
}
|
|
67
68
|
set(config) {
|
|
68
|
-
const cookie = Object.assign({
|
|
69
|
-
...this.#initial,
|
|
70
|
-
value: this.value
|
|
71
|
-
}, typeof config === "function" ? config(this.cookie) : config);
|
|
69
|
+
const cookie = Object.assign(nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
|
|
72
70
|
delete cookie["~raw"];
|
|
73
|
-
this.
|
|
71
|
+
this.cookie = cookie;
|
|
74
72
|
return this;
|
|
75
73
|
}
|
|
76
74
|
remove() {
|
package/dist/cookie/crypto.d.ts
CHANGED
|
@@ -7,14 +7,15 @@ declare const signCookieSyncImpl: (val: string, secret: string) => string;
|
|
|
7
7
|
declare const keyCache: Map<string, Promise<CryptoKey>>;
|
|
8
8
|
declare function importSecretKey(secret: string): Promise<CryptoKey>;
|
|
9
9
|
declare function signCookieSubtle(val: string, secret: string): Promise<string>;
|
|
10
|
-
declare
|
|
11
|
-
declare function
|
|
12
|
-
declare function
|
|
13
|
-
declare function
|
|
14
|
-
declare function
|
|
15
|
-
declare function
|
|
10
|
+
declare const deriveSignKey: (secret: string, name: string) => string;
|
|
11
|
+
declare function signCookie(val: string, secret: string | null, name?: string): Promise<string>;
|
|
12
|
+
declare function signCookieSync(val: string, secret: string | null, name?: string): string;
|
|
13
|
+
declare function unsignCookie(input: string, secret: string | null, name?: string): Promise<string | false>;
|
|
14
|
+
declare function unsignCookieSync(input: string, secret: string | null, name?: string): string | false;
|
|
15
|
+
declare function unsignWithSecretsSync(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined, legacy?: boolean): string;
|
|
16
|
+
declare function unsignWithSecrets(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined, legacy?: boolean): Promise<string>;
|
|
16
17
|
declare const rawJsonValue: WeakMap<object, string>;
|
|
17
18
|
declare function maybeJsonDecode(value: unknown): any;
|
|
18
19
|
declare function resolvePendingCookie(entry: Record<string, any>, name: string): void;
|
|
19
20
|
//#endregion
|
|
20
|
-
export { hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|
|
21
|
+
export { deriveSignKey, hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|