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/plugin/aot/core.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isResponseParam } from "../../compile/handler/params.mjs";
|
|
1
2
|
import { REQUEST_SLOTS, isResponseMap, isStandardSchema, mergeSchemasAllStandard, resolveModelRef } from "../../compile/handler/frozen-validator.mjs";
|
|
2
|
-
import { composeRouteHook } from "../../compile/handler/index.mjs";
|
|
3
|
+
import { composeRouteHook, runIntrospect } from "../../compile/handler/index.mjs";
|
|
3
4
|
import { captureArtifacts, compileToSource, replayStubbability } from "./source.mjs";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
@@ -140,7 +141,7 @@ const STUB_SOURCES = {
|
|
|
140
141
|
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
|
|
141
142
|
}, {
|
|
142
143
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]descriptor\.(m?js|ts)$/,
|
|
143
|
-
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\n"
|
|
144
|
+
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport function releaseAnalysisCaches(){}\nexport const routeDescriptors=new WeakMap()\n"
|
|
144
145
|
}],
|
|
145
146
|
ws: [{
|
|
146
147
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]ws[\\/]route\.(m?js|ts)$/,
|
|
@@ -148,7 +149,7 @@ const STUB_SOURCES = {
|
|
|
148
149
|
}],
|
|
149
150
|
reconstruct: [{
|
|
150
151
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]reconstruct\.(m?js|ts)$/,
|
|
151
|
-
source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class
|
|
152
|
+
source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class Reconstruct {\n static validator(){return e()}\n static cookie(){return e()}\n static trace(){return e()}\n}\n"
|
|
152
153
|
}],
|
|
153
154
|
cookie: [
|
|
154
155
|
{
|
|
@@ -489,7 +490,7 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
|
|
|
489
490
|
const artifacts = await captureArtifacts(typedApp, sourceOptions);
|
|
490
491
|
const report = replayStubbability(typedApp, artifacts.handlers);
|
|
491
492
|
const aliases = /* @__PURE__ */ new Set();
|
|
492
|
-
for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(name);
|
|
493
|
+
for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(isResponseParam(name) ? "va" : name);
|
|
493
494
|
const history = typedApp["~routes"];
|
|
494
495
|
const hasWS = !!typedApp["~hasWS"] || history.some((route) => route[0] === "WS");
|
|
495
496
|
const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
|
|
@@ -515,6 +516,7 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
|
|
|
515
516
|
};
|
|
516
517
|
const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
|
|
517
518
|
const hooks = composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
|
|
519
|
+
runIntrospect(hooks);
|
|
518
520
|
if (method === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
|
|
519
521
|
if (!hooks) continue;
|
|
520
522
|
let routeHasTypeBoxDirectSlot = false;
|
|
@@ -543,7 +545,8 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
|
|
|
543
545
|
}
|
|
544
546
|
if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
|
|
545
547
|
const validatorSlotsMatch = validatorSlotSetsMatch(expectedSlots, artifacts.validators);
|
|
546
|
-
const
|
|
548
|
+
const hasReplayableCapture = artifacts.handlers.some((h) => h.code) || artifacts.validators.length > 0;
|
|
549
|
+
const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, hasReplayableCapture && !routesForbidSeal && validatorSlotsMatch && artifacts.validators.every((v) => v.bridgeFree === true), !hasReplayableCapture, adapterStub, productionStub, wsCookie, exactMirror);
|
|
547
550
|
if (options?.target === "workerd") {
|
|
548
551
|
if (!report.jit) throw new Error(`[elysia-aot] target 'workerd' but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Every route must be captured into the AOT manifest.`);
|
|
549
552
|
if (!validatorSlotsMatch) console.warn("[elysia-aot] target 'workerd': captured validator slots do not exactly match declared slots; unfrozen slots compile at runtime and will fail on workerd.");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { createAotPluginHooks } from "./hooks.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/plugin/aot/unplugin.ts
|
|
@@ -19,9 +20,9 @@ const forceManifestSideEffect = (compiler) => {
|
|
|
19
20
|
*
|
|
20
21
|
* const aot = createUnplugin(aotFactory)
|
|
21
22
|
*
|
|
22
|
-
* // webpack.config.js
|
|
23
|
-
* // rollup.config.js
|
|
24
|
-
* // farm.config.ts
|
|
23
|
+
* // webpack.config.js \u2192 aot.webpack({ entry: 'src/index.ts' })
|
|
24
|
+
* // rollup.config.js \u2192 aot.rollup({ entry: 'src/index.ts' })
|
|
25
|
+
* // farm.config.ts \u2192 aot.farm({ entry: 'src/index.ts' })
|
|
25
26
|
* ```
|
|
26
27
|
*
|
|
27
28
|
* For rspack, prefer the native `elysia/plugin/aot/rspack` plugin
|
package/dist/plugin/aot/vite.mjs
CHANGED
package/dist/plugin/trace.mjs
CHANGED
package/dist/route-table.mjs
CHANGED
package/dist/schema-snapshot.mjs
CHANGED
package/dist/sucrose.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Su
|
|
|
19
19
|
* @internal Which `channelOf`-mapped members of a function's first parameter
|
|
20
20
|
* the function may read, or `null` when any member may be read
|
|
21
21
|
*/
|
|
22
|
-
declare function
|
|
22
|
+
declare function inferParameterReads<K extends string>(source: string, channelOf: (value: string) => K | undefined, strict?: boolean): Set<K> | null;
|
|
23
23
|
declare function sucrose(handler: Handler | undefined, lifeCycle: Sucrose.LifeCycle | undefined): Sucrose.Inference;
|
|
24
24
|
//#endregion
|
|
25
|
-
export { Sucrose, clearSucroseCache,
|
|
25
|
+
export { Sucrose, clearSucroseCache, inferParameterReads, mergeInference, sucrose };
|
package/dist/sucrose.js
CHANGED
|
@@ -59,7 +59,7 @@ function computedDestructuringChannel(tokens, index, channelOf) {
|
|
|
59
59
|
* @internal Which `channelOf`-mapped members of a function's first parameter
|
|
60
60
|
* the function may read, or `null` when any member may be read
|
|
61
61
|
*/
|
|
62
|
-
function
|
|
62
|
+
function inferParameterReads(source, channelOf, strict = false) {
|
|
63
63
|
if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) return null;
|
|
64
64
|
let tokens;
|
|
65
65
|
try {
|
|
@@ -232,7 +232,7 @@ function sucrose(handler, lifeCycle) {
|
|
|
232
232
|
let inference;
|
|
233
233
|
let merged = false;
|
|
234
234
|
const events = [];
|
|
235
|
-
if (
|
|
235
|
+
if (typeof handler === "function") events.push(handler);
|
|
236
236
|
if (lifeCycle) for (const name of lifeCycleEvents) {
|
|
237
237
|
const array = lifeCycle[name];
|
|
238
238
|
if (array) {
|
|
@@ -240,7 +240,7 @@ function sucrose(handler, lifeCycle) {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
const session = require_compile_aot.getCompilerSession();
|
|
243
|
-
const
|
|
243
|
+
const sourceCache = session?.external ? session.sucroseCache : globalSourceCache;
|
|
244
244
|
for (let i = 0; i < events.length; i++) {
|
|
245
245
|
const event = events[i];
|
|
246
246
|
if (!event) continue;
|
|
@@ -250,22 +250,22 @@ function sucrose(handler, lifeCycle) {
|
|
|
250
250
|
else {
|
|
251
251
|
const content = event.toString();
|
|
252
252
|
const key = require_utils.fnv1a(content);
|
|
253
|
-
const cached =
|
|
253
|
+
const cached = sourceCache.get(key);
|
|
254
254
|
if (cached && cached.content === content) {
|
|
255
255
|
inferred = cached.inference;
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
if (sourceCache.size >= DEFAULT_CACHE_LIMIT) {
|
|
257
|
+
sourceCache.delete(key);
|
|
258
|
+
sourceCache.set(key, cached);
|
|
259
259
|
}
|
|
260
260
|
} else {
|
|
261
|
-
const channels =
|
|
261
|
+
const channels = inferParameterReads(content, channel);
|
|
262
262
|
if (channels) {
|
|
263
263
|
const fresh = defaultSucrose();
|
|
264
264
|
for (const c of channels) fresh[c] = true;
|
|
265
265
|
inferred = Object.freeze(fresh);
|
|
266
266
|
} else inferred = allAccessed;
|
|
267
|
-
if (
|
|
268
|
-
|
|
267
|
+
if (sourceCache.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(sourceCache);
|
|
268
|
+
sourceCache.set(key, {
|
|
269
269
|
content,
|
|
270
270
|
inference: inferred
|
|
271
271
|
});
|
|
@@ -285,6 +285,6 @@ function sucrose(handler, lifeCycle) {
|
|
|
285
285
|
|
|
286
286
|
//#endregion
|
|
287
287
|
exports.clearSucroseCache = clearSucroseCache;
|
|
288
|
-
exports.
|
|
288
|
+
exports.inferParameterReads = inferParameterReads;
|
|
289
289
|
exports.mergeInference = mergeInference;
|
|
290
290
|
exports.sucrose = sucrose;
|
package/dist/sucrose.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { evictOldestHalf, fnv1a } from "./utils.mjs";
|
|
2
3
|
import { getCompilerSession } from "./compile/aot.mjs";
|
|
3
4
|
import { scanTokens } from "./compile/lexer.mjs";
|
|
@@ -58,7 +59,7 @@ function computedDestructuringChannel(tokens, index, channelOf) {
|
|
|
58
59
|
* @internal Which `channelOf`-mapped members of a function's first parameter
|
|
59
60
|
* the function may read, or `null` when any member may be read
|
|
60
61
|
*/
|
|
61
|
-
function
|
|
62
|
+
function inferParameterReads(source, channelOf, strict = false) {
|
|
62
63
|
if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) return null;
|
|
63
64
|
let tokens;
|
|
64
65
|
try {
|
|
@@ -231,7 +232,7 @@ function sucrose(handler, lifeCycle) {
|
|
|
231
232
|
let inference;
|
|
232
233
|
let merged = false;
|
|
233
234
|
const events = [];
|
|
234
|
-
if (
|
|
235
|
+
if (typeof handler === "function") events.push(handler);
|
|
235
236
|
if (lifeCycle) for (const name of lifeCycleEvents) {
|
|
236
237
|
const array = lifeCycle[name];
|
|
237
238
|
if (array) {
|
|
@@ -239,7 +240,7 @@ function sucrose(handler, lifeCycle) {
|
|
|
239
240
|
}
|
|
240
241
|
}
|
|
241
242
|
const session = getCompilerSession();
|
|
242
|
-
const
|
|
243
|
+
const sourceCache = session?.external ? session.sucroseCache : globalSourceCache;
|
|
243
244
|
for (let i = 0; i < events.length; i++) {
|
|
244
245
|
const event = events[i];
|
|
245
246
|
if (!event) continue;
|
|
@@ -249,22 +250,22 @@ function sucrose(handler, lifeCycle) {
|
|
|
249
250
|
else {
|
|
250
251
|
const content = event.toString();
|
|
251
252
|
const key = fnv1a(content);
|
|
252
|
-
const cached =
|
|
253
|
+
const cached = sourceCache.get(key);
|
|
253
254
|
if (cached && cached.content === content) {
|
|
254
255
|
inferred = cached.inference;
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
if (sourceCache.size >= DEFAULT_CACHE_LIMIT) {
|
|
257
|
+
sourceCache.delete(key);
|
|
258
|
+
sourceCache.set(key, cached);
|
|
258
259
|
}
|
|
259
260
|
} else {
|
|
260
|
-
const channels =
|
|
261
|
+
const channels = inferParameterReads(content, channel);
|
|
261
262
|
if (channels) {
|
|
262
263
|
const fresh = defaultSucrose();
|
|
263
264
|
for (const c of channels) fresh[c] = true;
|
|
264
265
|
inferred = Object.freeze(fresh);
|
|
265
266
|
} else inferred = allAccessed;
|
|
266
|
-
if (
|
|
267
|
-
|
|
267
|
+
if (sourceCache.size >= DEFAULT_CACHE_LIMIT) evictOldestHalf(sourceCache);
|
|
268
|
+
sourceCache.set(key, {
|
|
268
269
|
content,
|
|
269
270
|
inference: inferred
|
|
270
271
|
});
|
|
@@ -283,4 +284,4 @@ function sucrose(handler, lifeCycle) {
|
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
//#endregion
|
|
286
|
-
export { clearSucroseCache,
|
|
287
|
+
export { clearSucroseCache, inferParameterReads, mergeInference, sucrose };
|
package/dist/trace.js
CHANGED
|
@@ -21,10 +21,8 @@ function scanTracePhases(fn) {
|
|
|
21
21
|
if (cached !== void 0) return cached;
|
|
22
22
|
let result = null;
|
|
23
23
|
if (fn.length) try {
|
|
24
|
-
result = require_sucrose.
|
|
25
|
-
} catch {
|
|
26
|
-
result = null;
|
|
27
|
-
}
|
|
24
|
+
result = require_sucrose.inferParameterReads(Function.prototype.toString.call(fn), phaseOf, true);
|
|
25
|
+
} catch {}
|
|
28
26
|
tracePhaseCache.set(fn, result);
|
|
29
27
|
return result;
|
|
30
28
|
}
|
|
@@ -39,7 +37,7 @@ function unionTracePhases(handlers) {
|
|
|
39
37
|
return union;
|
|
40
38
|
}
|
|
41
39
|
/** Prevent rejected trace callbacks from becoming unhandled rejections. */
|
|
42
|
-
function
|
|
40
|
+
function logRejection(result) {
|
|
43
41
|
if (typeof result?.then === "function") result.then(void 0, (error) => console.error(error));
|
|
44
42
|
}
|
|
45
43
|
var TraceRecorder = class {
|
|
@@ -103,7 +101,7 @@ var TraceRecorder = class {
|
|
|
103
101
|
const result = this.#result();
|
|
104
102
|
resolve(result);
|
|
105
103
|
const callbacks = this.callbacksBegin;
|
|
106
|
-
if (callbacks) for (let i = 0; i < callbacks.length; i++)
|
|
104
|
+
if (callbacks) for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](result));
|
|
107
105
|
}
|
|
108
106
|
return this;
|
|
109
107
|
}
|
|
@@ -130,7 +128,7 @@ var TraceRecorder = class {
|
|
|
130
128
|
return end;
|
|
131
129
|
}
|
|
132
130
|
};
|
|
133
|
-
for (let i = 0; i < children.length; i++)
|
|
131
|
+
for (let i = 0; i < children.length; i++) logRejection(children[i](result));
|
|
134
132
|
let resolved = false;
|
|
135
133
|
return (err = null) => {
|
|
136
134
|
if (resolved) return;
|
|
@@ -144,7 +142,7 @@ var TraceRecorder = class {
|
|
|
144
142
|
return endAt - process.begin;
|
|
145
143
|
}
|
|
146
144
|
};
|
|
147
|
-
for (let i = 0; i < callbacksEnd.length; i++)
|
|
145
|
+
for (let i = 0; i < callbacksEnd.length; i++) logRejection(callbacksEnd[i](detail));
|
|
148
146
|
resolveEnd(endAt);
|
|
149
147
|
resolveError(err);
|
|
150
148
|
};
|
|
@@ -167,7 +165,7 @@ var TraceRecorder = class {
|
|
|
167
165
|
return end - begun.begin;
|
|
168
166
|
}
|
|
169
167
|
};
|
|
170
|
-
for (let i = 0; i < callbacks.length; i++)
|
|
168
|
+
for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](detail));
|
|
171
169
|
}
|
|
172
170
|
this.endResolve?.(end);
|
|
173
171
|
this.errorResolve?.(error);
|
|
@@ -269,7 +267,7 @@ var TracerLifecycle = class {
|
|
|
269
267
|
const createTracer = (traceListener) => (context) => {
|
|
270
268
|
const handle = new TracerHandle();
|
|
271
269
|
handle.rid = context.rid ?? "";
|
|
272
|
-
|
|
270
|
+
logRejection(traceListener(new TracerLifecycle(handle, context)));
|
|
273
271
|
return handle;
|
|
274
272
|
};
|
|
275
273
|
|
package/dist/trace.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { traceEvents } from "./constants.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { inferParameterReads } from "./sucrose.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/trace.ts
|
|
5
6
|
const phaseGetter = {
|
|
@@ -20,10 +21,8 @@ function scanTracePhases(fn) {
|
|
|
20
21
|
if (cached !== void 0) return cached;
|
|
21
22
|
let result = null;
|
|
22
23
|
if (fn.length) try {
|
|
23
|
-
result =
|
|
24
|
-
} catch {
|
|
25
|
-
result = null;
|
|
26
|
-
}
|
|
24
|
+
result = inferParameterReads(Function.prototype.toString.call(fn), phaseOf, true);
|
|
25
|
+
} catch {}
|
|
27
26
|
tracePhaseCache.set(fn, result);
|
|
28
27
|
return result;
|
|
29
28
|
}
|
|
@@ -38,7 +37,7 @@ function unionTracePhases(handlers) {
|
|
|
38
37
|
return union;
|
|
39
38
|
}
|
|
40
39
|
/** Prevent rejected trace callbacks from becoming unhandled rejections. */
|
|
41
|
-
function
|
|
40
|
+
function logRejection(result) {
|
|
42
41
|
if (typeof result?.then === "function") result.then(void 0, (error) => console.error(error));
|
|
43
42
|
}
|
|
44
43
|
var TraceRecorder = class {
|
|
@@ -102,7 +101,7 @@ var TraceRecorder = class {
|
|
|
102
101
|
const result = this.#result();
|
|
103
102
|
resolve(result);
|
|
104
103
|
const callbacks = this.callbacksBegin;
|
|
105
|
-
if (callbacks) for (let i = 0; i < callbacks.length; i++)
|
|
104
|
+
if (callbacks) for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](result));
|
|
106
105
|
}
|
|
107
106
|
return this;
|
|
108
107
|
}
|
|
@@ -129,7 +128,7 @@ var TraceRecorder = class {
|
|
|
129
128
|
return end;
|
|
130
129
|
}
|
|
131
130
|
};
|
|
132
|
-
for (let i = 0; i < children.length; i++)
|
|
131
|
+
for (let i = 0; i < children.length; i++) logRejection(children[i](result));
|
|
133
132
|
let resolved = false;
|
|
134
133
|
return (err = null) => {
|
|
135
134
|
if (resolved) return;
|
|
@@ -143,7 +142,7 @@ var TraceRecorder = class {
|
|
|
143
142
|
return endAt - process.begin;
|
|
144
143
|
}
|
|
145
144
|
};
|
|
146
|
-
for (let i = 0; i < callbacksEnd.length; i++)
|
|
145
|
+
for (let i = 0; i < callbacksEnd.length; i++) logRejection(callbacksEnd[i](detail));
|
|
147
146
|
resolveEnd(endAt);
|
|
148
147
|
resolveError(err);
|
|
149
148
|
};
|
|
@@ -166,7 +165,7 @@ var TraceRecorder = class {
|
|
|
166
165
|
return end - begun.begin;
|
|
167
166
|
}
|
|
168
167
|
};
|
|
169
|
-
for (let i = 0; i < callbacks.length; i++)
|
|
168
|
+
for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](detail));
|
|
170
169
|
}
|
|
171
170
|
this.endResolve?.(end);
|
|
172
171
|
this.errorResolve?.(error);
|
|
@@ -268,7 +267,7 @@ var TracerLifecycle = class {
|
|
|
268
267
|
const createTracer = (traceListener) => (context) => {
|
|
269
268
|
const handle = new TracerHandle();
|
|
270
269
|
handle.rid = context.rid ?? "";
|
|
271
|
-
|
|
270
|
+
logRejection(traceListener(new TracerLifecycle(handle, context)));
|
|
272
271
|
return handle;
|
|
273
272
|
};
|
|
274
273
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Intersect } from "./elysia/intersect.js";
|
|
2
|
+
import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
|
|
2
3
|
import { hasTypes } from "./utils.js";
|
|
3
4
|
import { useTypebox as useTypebox$1 } from "./bridge.js";
|
|
4
5
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.js";
|
|
5
6
|
import { TypeBoxValidator } from "./validator/index.js";
|
|
6
|
-
import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
|
|
7
7
|
import { Ref } from "typebox/type";
|
|
8
8
|
import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
|
|
9
9
|
import { Compile } from "typebox/compile";
|
package/dist/type/bridge.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Intersect as Intersect$2 } from "./elysia/intersect.js";
|
|
2
|
+
import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
|
|
2
3
|
import { hasTypes as hasTypes$1 } from "./utils.js";
|
|
3
4
|
import { TypeBoxValidatorCache as TypeBoxValidatorCache$1, mayHaveFileType as mayHaveFileType$1 } from "./validator/validator-cache.js";
|
|
4
5
|
import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
|
|
5
|
-
import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
|
|
6
6
|
import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
|
|
7
7
|
import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$2, HasCodec as HasCodec$1 } from "typebox/value";
|
|
8
8
|
import { Compile as Compile$1 } from "typebox/compile";
|
package/dist/type/bridge.mjs
CHANGED
package/dist/type/coerce.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare const coerceQuery: () => CoerceOption[];
|
|
|
30
30
|
declare const coerceBody: () => CoerceOption[];
|
|
31
31
|
declare const coerceFormData: () => CoerceOption[];
|
|
32
32
|
declare const coerceStringToStructure: () => CoerceOption[];
|
|
33
|
-
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined):
|
|
33
|
+
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): BaseSchema | TSchema;
|
|
34
34
|
declare function captureCoercePlan(original: any, coerced: any): CoerceNode | null;
|
|
35
35
|
/** Full rebuild: scalar leaves + ObjectString/ArrayString sites (wired path). */
|
|
36
36
|
declare const buildCoercedFromPlan: (original: any, plan: CoerceNode, seen?: Set<string>) => any;
|
package/dist/type/coerce.mjs
CHANGED
package/dist/type/compat.mjs
CHANGED
package/dist/type/constants.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
|
|
|
17
17
|
readonly NoValidate: 15;
|
|
18
18
|
};
|
|
19
19
|
type ELYSIA_TYPES = typeof ELYSIA_TYPES;
|
|
20
|
-
declare const primitiveElysiaTypes: Set<
|
|
20
|
+
declare const primitiveElysiaTypes: Set<6 | 1 | 2 | 3 | 10 | 11 | 13 | 14>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|
package/dist/type/constants.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ELYSIA_TYPES } from "../constants.js";
|
|
2
2
|
import { ArrayBufferOptions } from "../types.js";
|
|
3
|
+
import * as _$typebox from "typebox";
|
|
3
4
|
import { TSchema } from "typebox";
|
|
4
5
|
|
|
5
6
|
//#region src/type/elysia/array-buffer.d.ts
|
|
6
|
-
declare function bufferType(tag: ELYSIA_TYPES[keyof ELYSIA_TYPES],
|
|
7
|
-
declare function ArrayBufferType(property?: ArrayBufferOptions):
|
|
7
|
+
declare function bufferType<S extends TSchema>(tag: ELYSIA_TYPES[keyof ELYSIA_TYPES], createBase: () => S): (property?: ArrayBufferOptions) => Readonly<S>;
|
|
8
|
+
declare function ArrayBufferType(property?: ArrayBufferOptions): Readonly<_$typebox.TRefine<_$typebox.TUnsafe<ArrayBuffer>>>;
|
|
8
9
|
//#endregion
|
|
9
10
|
export { ArrayBufferType, bufferType };
|
|
@@ -5,16 +5,16 @@ const require_type_typebox_type = require('../typebox-type.js');
|
|
|
5
5
|
const require_type_elysia_utils = require('./utils.js');
|
|
6
6
|
|
|
7
7
|
//#region src/type/elysia/array-buffer.ts
|
|
8
|
-
function bufferType(tag,
|
|
9
|
-
let
|
|
8
|
+
function bufferType(tag, createBase) {
|
|
9
|
+
let base;
|
|
10
10
|
let empty;
|
|
11
11
|
return (property) => {
|
|
12
|
-
|
|
13
|
-
if (!property || require_utils.isEmpty(property)) return empty ??= Object.freeze(require_type_elysia_utils.elyType(tag,
|
|
12
|
+
base ??= createBase();
|
|
13
|
+
if (!property || require_utils.isEmpty(property)) return empty ??= Object.freeze(require_type_elysia_utils.elyType(tag, base));
|
|
14
14
|
const refines = [];
|
|
15
15
|
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
16
16
|
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
17
|
-
return require_type_elysia_utils.elyType(tag, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(
|
|
17
|
+
return require_type_elysia_utils.elyType(tag, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(base, refines), property));
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
const arrayBuffer = /* @__PURE__ */ bufferType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, () => require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer"));
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { isEmpty } from "../../utils.mjs";
|
|
2
3
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
4
|
import { Refine, Unsafe } from "../typebox-type.mjs";
|
|
4
5
|
import { Refines, elyType, withMeta } from "./utils.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/type/elysia/array-buffer.ts
|
|
7
|
-
function bufferType(tag,
|
|
8
|
-
let
|
|
8
|
+
function bufferType(tag, createBase) {
|
|
9
|
+
let base;
|
|
9
10
|
let empty;
|
|
10
11
|
return (property) => {
|
|
11
|
-
|
|
12
|
-
if (!property || isEmpty(property)) return empty ??= Object.freeze(elyType(tag,
|
|
12
|
+
base ??= createBase();
|
|
13
|
+
if (!property || isEmpty(property)) return empty ??= Object.freeze(elyType(tag, base));
|
|
13
14
|
const refines = [];
|
|
14
15
|
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
15
16
|
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
16
|
-
return elyType(tag, withMeta(Refines(
|
|
17
|
+
return elyType(tag, withMeta(Refines(base, refines), property));
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
const arrayBuffer = /* @__PURE__ */ bufferType(ELYSIA_TYPES.ArrayBuffer, () => Refine(Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer"));
|