elysia 2.0.0-beta.22 → 2.0.0-beta.24

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/base.js CHANGED
@@ -239,7 +239,7 @@ var Elysia = class Elysia {
239
239
  if (!entry?.response) continue;
240
240
  merged.response = require_utils.mergeResponse(merged.response, entry.response);
241
241
  }
242
- if (merged?.response && !require_utils.isRecordNumber(merged.response)) merged.response = { 200: merged.response };
242
+ if (merged?.response) merged.response = require_utils.isRecordNumber(merged.response) ? { ...merged.response } : { 200: merged.response };
243
243
  return {
244
244
  method,
245
245
  path,
@@ -669,7 +669,7 @@ var Elysia = class Elysia {
669
669
  return this;
670
670
  }
671
671
  has(plugin) {
672
- return this.childrenHash?.has(plugin.hash ?? require_utils.pluginId(plugin)) ?? false;
672
+ return this.childrenHash?.has(plugin.hash) ?? false;
673
673
  }
674
674
  #useFn(app) {
675
675
  const prevBaseline = this.macroBaseline;
@@ -712,13 +712,12 @@ var Elysia = class Elysia {
712
712
  const config = app["~config"];
713
713
  if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
714
714
  const name = config?.name;
715
- const childKey = name ? app.hash : require_utils.pluginId(app);
716
- const exists = this.childrenHash?.has(childKey);
717
- if (name && exists) return;
718
- if (!exists) {
715
+ if (name) {
716
+ const hash = app.hash;
717
+ if (this.childrenHash?.has(hash)) return;
719
718
  this.childrenHash ??= /* @__PURE__ */ new Set();
720
- this.childrenHash.add(childKey);
721
- (addedByThisCall ??= /* @__PURE__ */ new Set()).add(childKey);
719
+ this.childrenHash.add(hash);
720
+ (addedByThisCall ??= /* @__PURE__ */ new Set()).add(hash);
722
721
  }
723
722
  if (app.childrenHash && !app["~scopeChild"]) addedByThisCall = this.#absorbChildrenHash(app, addedByThisCall);
724
723
  if (app["~ext"]) this.#assertMacroUnique(app, addedByThisCall);
@@ -737,9 +736,8 @@ var Elysia = class Elysia {
737
736
  if (hookChain) this.#propagateHooks(app, hookChain, addedByThisCall);
738
737
  }
739
738
  #absorbChildrenHash(app, addedByThisCall) {
740
- const childrenHash = this.childrenHash;
741
- for (let h of app.childrenHash) {
742
- if (typeof h === "object") h = require_utils.pluginId(h);
739
+ const childrenHash = this.childrenHash ??= /* @__PURE__ */ new Set();
740
+ for (const h of app.childrenHash) {
743
741
  if (childrenHash.has(h)) continue;
744
742
  childrenHash.add(h);
745
743
  (addedByThisCall ??= /* @__PURE__ */ new Set()).add(h);
@@ -820,7 +818,7 @@ var Elysia = class Elysia {
820
818
  const fn = hoc[i];
821
819
  const registration = source.hocOrigin?.[i] ?? app.hash;
822
820
  const origin = typeof registration === "object" ? registration.origin ??= app.hash : registration;
823
- if (origin !== void 0 && childrenHash.has(origin) && !addedByThisCall?.has(origin)) continue;
821
+ if (origin !== void 0 && childrenHash?.has(origin) && !addedByThisCall?.has(origin)) continue;
824
822
  if (target.some((f, j) => f === fn && hocOriginOf(origins[j]) === origin)) continue;
825
823
  origins.push(registration);
826
824
  target.push(fn);
package/dist/base.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
2
  import { isBun } from "./universal/constants.mjs";
3
- import { clearFlattenChainMemo, clonePlainDecorators, clonePlainDeep, coalesceSchemas, createErrorEventHandler, eventProperties, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isEmpty, isHTMLBundle, isNotEmpty, isPlainObject, isRecordNumber, joinPath, macroOrigin, mapDeriveEntry, markPropertySingletons, markSingletons, mergeDeep, mergeResponse, nullObject, pluginHash, pluginId, schemaProperties, serializeMacroSeed, throwLifecycleErrors } from "./utils.mjs";
3
+ import { clearFlattenChainMemo, clonePlainDecorators, clonePlainDeep, coalesceSchemas, createErrorEventHandler, eventProperties, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isEmpty, isHTMLBundle, isNotEmpty, isPlainObject, isRecordNumber, joinPath, macroOrigin, mapDeriveEntry, markPropertySingletons, markSingletons, mergeDeep, mergeResponse, nullObject, pluginHash, schemaProperties, serializeMacroSeed, throwLifecycleErrors } from "./utils.mjs";
4
4
  import { Ref, warmTypebox } from "./type/bridge.mjs";
5
5
  import { isProduction } from "./universal/is-production.mjs";
6
6
  import { Capture, Compiled, beginCompilerSession, createAotFingerprint, endCompilerSession } from "./compile/aot.mjs";
@@ -237,7 +237,7 @@ var Elysia = class Elysia {
237
237
  if (!entry?.response) continue;
238
238
  merged.response = mergeResponse(merged.response, entry.response);
239
239
  }
240
- if (merged?.response && !isRecordNumber(merged.response)) merged.response = { 200: merged.response };
240
+ if (merged?.response) merged.response = isRecordNumber(merged.response) ? { ...merged.response } : { 200: merged.response };
241
241
  return {
242
242
  method,
243
243
  path,
@@ -667,7 +667,7 @@ var Elysia = class Elysia {
667
667
  return this;
668
668
  }
669
669
  has(plugin) {
670
- return this.childrenHash?.has(plugin.hash ?? pluginId(plugin)) ?? false;
670
+ return this.childrenHash?.has(plugin.hash) ?? false;
671
671
  }
672
672
  #useFn(app) {
673
673
  const prevBaseline = this.macroBaseline;
@@ -710,13 +710,12 @@ var Elysia = class Elysia {
710
710
  const config = app["~config"];
711
711
  if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
712
712
  const name = config?.name;
713
- const childKey = name ? app.hash : pluginId(app);
714
- const exists = this.childrenHash?.has(childKey);
715
- if (name && exists) return;
716
- if (!exists) {
713
+ if (name) {
714
+ const hash = app.hash;
715
+ if (this.childrenHash?.has(hash)) return;
717
716
  this.childrenHash ??= /* @__PURE__ */ new Set();
718
- this.childrenHash.add(childKey);
719
- (addedByThisCall ??= /* @__PURE__ */ new Set()).add(childKey);
717
+ this.childrenHash.add(hash);
718
+ (addedByThisCall ??= /* @__PURE__ */ new Set()).add(hash);
720
719
  }
721
720
  if (app.childrenHash && !app["~scopeChild"]) addedByThisCall = this.#absorbChildrenHash(app, addedByThisCall);
722
721
  if (app["~ext"]) this.#assertMacroUnique(app, addedByThisCall);
@@ -735,9 +734,8 @@ var Elysia = class Elysia {
735
734
  if (hookChain) this.#propagateHooks(app, hookChain, addedByThisCall);
736
735
  }
737
736
  #absorbChildrenHash(app, addedByThisCall) {
738
- const childrenHash = this.childrenHash;
739
- for (let h of app.childrenHash) {
740
- if (typeof h === "object") h = pluginId(h);
737
+ const childrenHash = this.childrenHash ??= /* @__PURE__ */ new Set();
738
+ for (const h of app.childrenHash) {
741
739
  if (childrenHash.has(h)) continue;
742
740
  childrenHash.add(h);
743
741
  (addedByThisCall ??= /* @__PURE__ */ new Set()).add(h);
@@ -818,7 +816,7 @@ var Elysia = class Elysia {
818
816
  const fn = hoc[i];
819
817
  const registration = source.hocOrigin?.[i] ?? app.hash;
820
818
  const origin = typeof registration === "object" ? registration.origin ??= app.hash : registration;
821
- if (origin !== void 0 && childrenHash.has(origin) && !addedByThisCall?.has(origin)) continue;
819
+ if (origin !== void 0 && childrenHash?.has(origin) && !addedByThisCall?.has(origin)) continue;
822
820
  if (target.some((f, j) => f === fn && hocOriginOf(origins[j]) === origin)) continue;
823
821
  origins.push(registration);
824
822
  target.push(fn);
@@ -13,8 +13,8 @@ const require_type_validator_frozen_check = require('../type/validator/frozen-ch
13
13
  const require_type_validator_custom_error = require('../type/validator/custom-error.js');
14
14
  const require_type_validator_exact_mirror = require('../type/validator/exact-mirror.js');
15
15
  const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
16
- let typebox_schema = require("typebox/schema");
17
16
  let typebox_value = require("typebox/value");
17
+ let typebox_schema = require("typebox/schema");
18
18
 
19
19
  //#region src/compile/aot-capture.ts
20
20
  function emptyContainers(node, depth) {
@@ -12,8 +12,8 @@ import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
12
12
  import { captureCustomErrors } from "../type/validator/custom-error.mjs";
13
13
  import { getExactMirror } from "../type/validator/exact-mirror.mjs";
14
14
  import { captureStringCodecEntries, compileWithBuild } from "../type/validator/string-codec-aot.mjs";
15
- import { Build, Compile } from "typebox/schema";
16
15
  import { Default } from "typebox/value";
16
+ import { Build, Compile } from "typebox/schema";
17
17
 
18
18
  //#region src/compile/aot-capture.ts
19
19
  function emptyContainers(node, depth) {
@@ -43,6 +43,7 @@ function promoteDerive(hook) {
43
43
  function runIntrospect(hook) {
44
44
  const introspects = hook?.["~introspect"];
45
45
  if (!introspects) return;
46
+ if (hook.response && require_utils.isRecordNumber(hook.response)) hook.response = { ...hook.response };
46
47
  for (let i = 0; i < introspects.length; i++) introspects[i](hook);
47
48
  delete hook["~introspect"];
48
49
  }
@@ -273,42 +274,47 @@ function routeShape(hook, handler, root) {
273
274
  const visiting = /* @__PURE__ */ new Set();
274
275
  let unsupported = false;
275
276
  for (const _ in []) return;
277
+ let hash;
278
+ const feed = (s) => {
279
+ hash = require_utils.fnv1a(s, hash);
280
+ };
281
+ const quote = (s) => feed(JSON.stringify(s));
276
282
  const shape = (v, at = "") => {
277
283
  switch (typeof v) {
278
- case "string": return JSON.stringify(v);
279
- case "number": return "n" + (Object.is(v, -0) ? "-0" : v);
280
- case "bigint": return "b" + v;
281
- case "boolean": return v ? "T" : "F";
282
- case "undefined": return "U";
284
+ case "string": return quote(v);
285
+ case "number": return feed("n" + (Object.is(v, -0) ? "-0" : v));
286
+ case "bigint": return feed("b" + v);
287
+ case "boolean": return feed(v ? "T" : "F");
288
+ case "undefined": return feed("U");
283
289
  case "function":
284
- if (ids.has(v)) return "#" + ids.get(v);
290
+ if (ids.has(v)) return feed("#" + ids.get(v));
285
291
  ids.set(v, ids.size);
286
- return require_compile_utils.isAsyncFunction(v) ? "fa" : "fs";
292
+ return feed(require_compile_utils.isAsyncFunction(v) ? "fa" : "fs");
287
293
  case "symbol":
288
294
  unsupported = true;
289
- return "";
295
+ return;
290
296
  }
291
- if (v === null) return "N";
292
- if ("~standard" in v) return "S";
297
+ if (v === null) return feed("N");
298
+ if ("~standard" in v) return feed("S");
293
299
  if (visiting.has(v)) {
294
300
  unsupported = true;
295
- return "";
301
+ return;
296
302
  }
297
- let tag = "";
303
+ let kind;
298
304
  const list = Array.isArray(v);
299
305
  const proto = Object.getPrototypeOf(v);
300
306
  if (list ? proto !== Array.prototype : proto !== null && proto !== Object.prototype) {
301
- const kind = proto && Object.getOwnPropertyDescriptor(proto, "~kind");
307
+ kind = proto && Object.getOwnPropertyDescriptor(proto, "~kind");
302
308
  if (!kind || !("value" in kind) || Reflect.ownKeys(proto).length !== 1 || Object.getPrototypeOf(proto) !== Object.prototype) {
303
309
  unsupported = true;
304
- return "";
310
+ return;
305
311
  }
306
- tag = shape(kind.value);
307
312
  }
313
+ feed(list ? "[" : "{");
314
+ if (kind) shape(kind.value);
308
315
  visiting.add(v);
309
316
  const map = at === "response" && require_compile_handler_frozen_validator.isResponseMap(v);
310
317
  const deferred = v["~kind"] === "Deferred";
311
- let s = (list ? "[" : "{") + tag;
312
318
  for (const k of Reflect.ownKeys(v)) {
313
319
  const d = Object.getOwnPropertyDescriptor(v, k);
314
320
  if (typeof k === "symbol" || !("value" in d)) {
@@ -317,31 +323,41 @@ function routeShape(hook, handler, root) {
317
323
  }
318
324
  const value = d.value;
319
325
  if (k === "$ref" && typeof value === "string") addRef(value, at);
320
- s += "," + (d.enumerable ? "" : "!") + JSON.stringify(k) + ":";
321
- if (map) s += named(value);
322
- else if (k === "config" && isCookieAt(at)) s += shape([value?.sign, !!value?.secrets]);
323
- else if (k === "secrets" && (typeof value === "string" || Array.isArray(value))) s += shape(!!value);
324
- else s += shape(value, childAt(at, k, value, deferred));
326
+ feed(d.enumerable ? "," : ",!");
327
+ quote(k);
328
+ feed(":");
329
+ if (map) named(value);
330
+ else if (k === "config" && isCookieAt(at)) shape([value?.sign, !!value?.secrets]);
331
+ else if (k === "secrets" && (typeof value === "string" || Array.isArray(value))) shape(!!value);
332
+ else shape(value, childAt(at, k, value, deferred));
325
333
  }
326
334
  visiting.delete(v);
327
- return s + (list ? "]" : "}");
335
+ feed(list ? "]" : "}");
328
336
  };
329
337
  const named = (v, at) => {
330
338
  if (typeof v === "string") addRef(v, at);
331
- return shape(v, at);
339
+ shape(v, at);
332
340
  };
333
- let s = typeof handler === "function" || handler == null ? shape(handler) : handler instanceof Response ? "R" : handler instanceof Promise ? "P" : typeof handler === "object" ? "O" : "V";
341
+ if (typeof handler === "function" || handler == null) shape(handler);
342
+ else feed(handler instanceof Response ? "R" : handler instanceof Promise ? "P" : typeof handler === "object" ? "O" : "V");
334
343
  for (const event of shapeEvents) {
335
- s += "|";
344
+ feed("|");
336
345
  const fns = hook?.[event];
337
- if (fns) for (const fn of Array.isArray(fns) ? fns : [fns]) s += shape(fn);
346
+ if (fns) for (const fn of Array.isArray(fns) ? fns : [fns]) shape(fn);
338
347
  }
339
348
  const bf = hook?.beforeHandle;
340
- s += "|" + JSON.stringify(bf && require_compile_handler_utils.deriveModes(Array.isArray(bf) ? bf : [bf], hook["~deriveEntries"]));
341
- for (const from of [hook, ...hook?.schemas || []]) for (const slot of shapeSlots) s += "|" + named(from?.[slot], slot);
349
+ feed("|" + JSON.stringify(bf && require_compile_handler_utils.deriveModes(Array.isArray(bf) ? bf : [bf], hook["~deriveEntries"])));
350
+ for (const from of [hook, ...hook?.schemas || []]) for (const slot of shapeSlots) {
351
+ feed("|");
352
+ named(from?.[slot], slot);
353
+ }
342
354
  let targets;
343
- for (const [ref, at] of refs) for (const target of at ? (targets ??= require_utils.refTargets([], models))(ref) : [models?.[ref]]) s += "|" + JSON.stringify(ref) + shape(target, at);
344
- s += "|" + JSON.stringify([
355
+ for (const [ref, at] of refs) for (const target of at ? (targets ??= require_utils.refTargets([], models))(ref) : [models?.[ref]]) {
356
+ feed("|");
357
+ quote(ref);
358
+ shape(target, at);
359
+ }
360
+ feed("|" + JSON.stringify([
345
361
  config?.cookie?.sign,
346
362
  config?.cookie?.verify,
347
363
  config?.normalize,
@@ -350,8 +366,9 @@ function routeShape(hook, handler, root) {
350
366
  require_utils.isNotEmpty(frozenRoot["~ext"]?.headers),
351
367
  !!(config?.adapter ?? require_adapter_constants.defaultAdapter).response.supportsDefaultHeaderSink,
352
368
  !!require_handler_utils.returnedErrorClasses(hook)
353
- ]) + shape(config?.sanitize);
354
- return unsupported ? void 0 : require_utils.fnv1a(s);
369
+ ]));
370
+ shape(config?.sanitize);
371
+ return unsupported ? void 0 : hash;
355
372
  }
356
373
  const throwsOnCall = (error) => () => {
357
374
  throw error;
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import { isBun } from "../../universal/constants.mjs";
3
3
  import { ElysiaFile } from "../../universal/file.mjs";
4
- import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, isCompactBeforeHandleOnly, isHTMLBundle, isNotEmpty, macroEpoch, mergeHook, nullObject, refTargets, replaceUrlPath } from "../../utils.mjs";
4
+ import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, isCompactBeforeHandleOnly, isHTMLBundle, isNotEmpty, isRecordNumber, macroEpoch, mergeHook, nullObject, refTargets, replaceUrlPath } from "../../utils.mjs";
5
5
  import { ElysiaStatus } from "../../error.mjs";
6
6
  import { mapResponse } from "../../adapter/web-standard/handler.mjs";
7
7
  import { Capture, Compiled, aotDriftMessage, warnAotDrift } from "../aot.mjs";
@@ -43,6 +43,7 @@ function promoteDerive(hook) {
43
43
  function runIntrospect(hook) {
44
44
  const introspects = hook?.["~introspect"];
45
45
  if (!introspects) return;
46
+ if (hook.response && isRecordNumber(hook.response)) hook.response = { ...hook.response };
46
47
  for (let i = 0; i < introspects.length; i++) introspects[i](hook);
47
48
  delete hook["~introspect"];
48
49
  }
@@ -273,42 +274,47 @@ function routeShape(hook, handler, root) {
273
274
  const visiting = /* @__PURE__ */ new Set();
274
275
  let unsupported = false;
275
276
  for (const _ in []) return;
277
+ let hash;
278
+ const feed = (s) => {
279
+ hash = fnv1a(s, hash);
280
+ };
281
+ const quote = (s) => feed(JSON.stringify(s));
276
282
  const shape = (v, at = "") => {
277
283
  switch (typeof v) {
278
- case "string": return JSON.stringify(v);
279
- case "number": return "n" + (Object.is(v, -0) ? "-0" : v);
280
- case "bigint": return "b" + v;
281
- case "boolean": return v ? "T" : "F";
282
- case "undefined": return "U";
284
+ case "string": return quote(v);
285
+ case "number": return feed("n" + (Object.is(v, -0) ? "-0" : v));
286
+ case "bigint": return feed("b" + v);
287
+ case "boolean": return feed(v ? "T" : "F");
288
+ case "undefined": return feed("U");
283
289
  case "function":
284
- if (ids.has(v)) return "#" + ids.get(v);
290
+ if (ids.has(v)) return feed("#" + ids.get(v));
285
291
  ids.set(v, ids.size);
286
- return isAsyncFunction(v) ? "fa" : "fs";
292
+ return feed(isAsyncFunction(v) ? "fa" : "fs");
287
293
  case "symbol":
288
294
  unsupported = true;
289
- return "";
295
+ return;
290
296
  }
291
- if (v === null) return "N";
292
- if ("~standard" in v) return "S";
297
+ if (v === null) return feed("N");
298
+ if ("~standard" in v) return feed("S");
293
299
  if (visiting.has(v)) {
294
300
  unsupported = true;
295
- return "";
301
+ return;
296
302
  }
297
- let tag = "";
303
+ let kind;
298
304
  const list = Array.isArray(v);
299
305
  const proto = Object.getPrototypeOf(v);
300
306
  if (list ? proto !== Array.prototype : proto !== null && proto !== Object.prototype) {
301
- const kind = proto && Object.getOwnPropertyDescriptor(proto, "~kind");
307
+ kind = proto && Object.getOwnPropertyDescriptor(proto, "~kind");
302
308
  if (!kind || !("value" in kind) || Reflect.ownKeys(proto).length !== 1 || Object.getPrototypeOf(proto) !== Object.prototype) {
303
309
  unsupported = true;
304
- return "";
310
+ return;
305
311
  }
306
- tag = shape(kind.value);
307
312
  }
313
+ feed(list ? "[" : "{");
314
+ if (kind) shape(kind.value);
308
315
  visiting.add(v);
309
316
  const map = at === "response" && isResponseMap(v);
310
317
  const deferred = v["~kind"] === "Deferred";
311
- let s = (list ? "[" : "{") + tag;
312
318
  for (const k of Reflect.ownKeys(v)) {
313
319
  const d = Object.getOwnPropertyDescriptor(v, k);
314
320
  if (typeof k === "symbol" || !("value" in d)) {
@@ -317,31 +323,41 @@ function routeShape(hook, handler, root) {
317
323
  }
318
324
  const value = d.value;
319
325
  if (k === "$ref" && typeof value === "string") addRef(value, at);
320
- s += "," + (d.enumerable ? "" : "!") + JSON.stringify(k) + ":";
321
- if (map) s += named(value);
322
- else if (k === "config" && isCookieAt(at)) s += shape([value?.sign, !!value?.secrets]);
323
- else if (k === "secrets" && (typeof value === "string" || Array.isArray(value))) s += shape(!!value);
324
- else s += shape(value, childAt(at, k, value, deferred));
326
+ feed(d.enumerable ? "," : ",!");
327
+ quote(k);
328
+ feed(":");
329
+ if (map) named(value);
330
+ else if (k === "config" && isCookieAt(at)) shape([value?.sign, !!value?.secrets]);
331
+ else if (k === "secrets" && (typeof value === "string" || Array.isArray(value))) shape(!!value);
332
+ else shape(value, childAt(at, k, value, deferred));
325
333
  }
326
334
  visiting.delete(v);
327
- return s + (list ? "]" : "}");
335
+ feed(list ? "]" : "}");
328
336
  };
329
337
  const named = (v, at) => {
330
338
  if (typeof v === "string") addRef(v, at);
331
- return shape(v, at);
339
+ shape(v, at);
332
340
  };
333
- let s = typeof handler === "function" || handler == null ? shape(handler) : handler instanceof Response ? "R" : handler instanceof Promise ? "P" : typeof handler === "object" ? "O" : "V";
341
+ if (typeof handler === "function" || handler == null) shape(handler);
342
+ else feed(handler instanceof Response ? "R" : handler instanceof Promise ? "P" : typeof handler === "object" ? "O" : "V");
334
343
  for (const event of shapeEvents) {
335
- s += "|";
344
+ feed("|");
336
345
  const fns = hook?.[event];
337
- if (fns) for (const fn of Array.isArray(fns) ? fns : [fns]) s += shape(fn);
346
+ if (fns) for (const fn of Array.isArray(fns) ? fns : [fns]) shape(fn);
338
347
  }
339
348
  const bf = hook?.beforeHandle;
340
- s += "|" + JSON.stringify(bf && deriveModes(Array.isArray(bf) ? bf : [bf], hook["~deriveEntries"]));
341
- for (const from of [hook, ...hook?.schemas || []]) for (const slot of shapeSlots) s += "|" + named(from?.[slot], slot);
349
+ feed("|" + JSON.stringify(bf && deriveModes(Array.isArray(bf) ? bf : [bf], hook["~deriveEntries"])));
350
+ for (const from of [hook, ...hook?.schemas || []]) for (const slot of shapeSlots) {
351
+ feed("|");
352
+ named(from?.[slot], slot);
353
+ }
342
354
  let targets;
343
- for (const [ref, at] of refs) for (const target of at ? (targets ??= refTargets([], models))(ref) : [models?.[ref]]) s += "|" + JSON.stringify(ref) + shape(target, at);
344
- s += "|" + JSON.stringify([
355
+ for (const [ref, at] of refs) for (const target of at ? (targets ??= refTargets([], models))(ref) : [models?.[ref]]) {
356
+ feed("|");
357
+ quote(ref);
358
+ shape(target, at);
359
+ }
360
+ feed("|" + JSON.stringify([
345
361
  config?.cookie?.sign,
346
362
  config?.cookie?.verify,
347
363
  config?.normalize,
@@ -350,8 +366,9 @@ function routeShape(hook, handler, root) {
350
366
  isNotEmpty(frozenRoot["~ext"]?.headers),
351
367
  !!(config?.adapter ?? defaultAdapter).response.supportsDefaultHeaderSink,
352
368
  !!returnedErrorClasses(hook)
353
- ]) + shape(config?.sanitize);
354
- return unsupported ? void 0 : fnv1a(s);
369
+ ]));
370
+ shape(config?.sanitize);
371
+ return unsupported ? void 0 : hash;
355
372
  }
356
373
  const throwsOnCall = (error) => () => {
357
374
  throw error;
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-beta.22";
3
+ var version = "2.0.0-beta.24";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
2
  //#region package.json
3
- var version = "2.0.0-beta.22";
3
+ var version = "2.0.0-beta.24";
4
4
 
5
5
  //#endregion
6
6
  export { version };
@@ -100,7 +100,7 @@ interface ElysiaAotOptions {
100
100
  }
101
101
  declare const resolveEntry: (entry: string) => string;
102
102
  /** @internal Resolve the package condition used to evaluate an AOT entry. */
103
- declare const resolveEntryModuleKind: (entry: string) => "esm" | "cjs";
103
+ declare const resolveEntryModuleKind: (entry: string) => "cjs" | "esm";
104
104
  /** Runtime handler-JIT module a strip build can replace with a throwing stub. */
105
105
  interface StubPlan {
106
106
  /** Stub the internal handler codegen module. */
@@ -221,9 +221,34 @@ function snapshotSlots(target, intern) {
221
221
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
222
222
  const response = target.response;
223
223
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
224
- const next = {};
225
- for (const status in response) next[status] = internSchema(response[status], intern);
226
- target.response = next;
224
+ let next = {};
225
+ const state = { bail: false };
226
+ let key = "M";
227
+ for (const status in response) {
228
+ const schema = internSchema(response[status], intern);
229
+ Object.defineProperty(next, status, {
230
+ value: schema,
231
+ enumerable: true
232
+ });
233
+ key += status.length + ":" + status + byRefKey(schema, state);
234
+ }
235
+ if (key === "M") target.response = next;
236
+ else {
237
+ if (intern && !state.bail) {
238
+ const shared = interned.get(key);
239
+ if (shared === void 0) {
240
+ if (interned.size >= INTERN_LIMIT) require_utils.evictOldestHalf(interned);
241
+ interned.set(key, next);
242
+ } else {
243
+ if (interned.size >= INTERN_LIMIT) {
244
+ interned.delete(key);
245
+ interned.set(key, shared);
246
+ }
247
+ next = shared;
248
+ }
249
+ }
250
+ target.response = Object.freeze(next);
251
+ }
227
252
  } else target.response = internSchema(response, intern);
228
253
  }
229
254
  function isStatusMap(response) {
@@ -221,9 +221,34 @@ function snapshotSlots(target, intern) {
221
221
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
222
222
  const response = target.response;
223
223
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
224
- const next = {};
225
- for (const status in response) next[status] = internSchema(response[status], intern);
226
- target.response = next;
224
+ let next = {};
225
+ const state = { bail: false };
226
+ let key = "M";
227
+ for (const status in response) {
228
+ const schema = internSchema(response[status], intern);
229
+ Object.defineProperty(next, status, {
230
+ value: schema,
231
+ enumerable: true
232
+ });
233
+ key += status.length + ":" + status + byRefKey(schema, state);
234
+ }
235
+ if (key === "M") target.response = next;
236
+ else {
237
+ if (intern && !state.bail) {
238
+ const shared = interned.get(key);
239
+ if (shared === void 0) {
240
+ if (interned.size >= INTERN_LIMIT) evictOldestHalf(interned);
241
+ interned.set(key, next);
242
+ } else {
243
+ if (interned.size >= INTERN_LIMIT) {
244
+ interned.delete(key);
245
+ interned.set(key, shared);
246
+ }
247
+ next = shared;
248
+ }
249
+ }
250
+ target.response = Object.freeze(next);
251
+ }
227
252
  } else target.response = internSchema(response, intern);
228
253
  }
229
254
  function isStatusMap(response) {
@@ -5,8 +5,8 @@ import { useTypebox as useTypebox$1 } from "./bridge.js";
5
5
  import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.js";
6
6
  import { TypeBoxValidator } from "./validator/index.js";
7
7
  import { Ref } from "typebox/type";
8
- import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
9
8
  import { Compile } from "typebox/compile";
9
+ import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
10
10
 
11
11
  //#region src/type/bridge-live.d.ts
12
12
  declare function useTypebox(_mod?: Parameters<typeof useTypebox$1>[0]): void;
@@ -6,8 +6,8 @@ const require_type_validator_validator_cache = require('./validator/validator-ca
6
6
  const require_type_validator_index = require('./validator/index.js');
7
7
  const require_type_elysia_intersect = require('./elysia/intersect.js');
8
8
  let typebox_type = require("typebox/type");
9
- let typebox_value = require("typebox/value");
10
9
  let typebox_compile = require("typebox/compile");
10
+ let typebox_value = require("typebox/value");
11
11
  let typebox_system = require("typebox/system");
12
12
 
13
13
  //#region src/type/bridge-live.ts
@@ -5,8 +5,8 @@ import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-ca
5
5
  import { TypeBoxValidator } from "./validator/index.mjs";
6
6
  import { Intersect } from "./elysia/intersect.mjs";
7
7
  import { Ref } from "typebox/type";
8
- import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
9
8
  import { Compile } from "typebox/compile";
9
+ import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
10
10
  import { Settings } from "typebox/system";
11
11
 
12
12
  //#region src/type/bridge-live.ts
@@ -4,8 +4,8 @@ import { hasTypes as hasTypes$1 } from "./utils.js";
4
4
  import { TypeBoxValidatorCache as TypeBoxValidatorCache$1, mayHaveFileType as mayHaveFileType$1 } from "./validator/validator-cache.js";
5
5
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
6
6
  import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
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
7
  import { Compile as Compile$1 } from "typebox/compile";
8
+ import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$2, HasCodec as HasCodec$1 } from "typebox/value";
9
9
 
10
10
  //#region src/type/bridge.d.ts
11
11
  interface TypeboxModule {
@@ -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<6 | 1 | 2 | 3 | 10 | 11 | 13 | 14>;
20
+ declare const primitiveElysiaTypes: Set<1 | 2 | 6 | 3 | 10 | 11 | 13 | 14>;
21
21
  declare const noEnumerable: {
22
22
  readonly enumerable: false;
23
23
  };
@@ -1,7 +1,7 @@
1
1
  import { TypeboxNamespaces } from "./typebox-value.js";
2
- import { Build, Compile as SchemaCompile } from "typebox/schema";
3
- import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
4
2
  import { Compile } from "typebox/compile";
3
+ import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
4
+ import { Build, Compile as SchemaCompile } from "typebox/schema";
5
5
 
6
6
  //#region src/type/typebox-value-live.d.ts
7
7
  declare function injectTypebox(_typebox?: TypeboxNamespaces): void;
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
- let typebox_schema = require("typebox/schema");
4
- let typebox_value = require("typebox/value");
5
3
  let typebox_compile = require("typebox/compile");
4
+ let typebox_value = require("typebox/value");
6
5
  let typebox_system = require("typebox/system");
6
+ let typebox_schema = require("typebox/schema");
7
7
 
8
8
  //#region src/type/typebox-value-live.ts
9
9
  typebox_system.Settings.Set({ unionPrioritySort: false });
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import { Build, Compile as SchemaCompile } from "typebox/schema";
3
- import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
4
2
  import { Compile } from "typebox/compile";
3
+ import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
5
4
  import { Settings } from "typebox/system";
5
+ import { Build, Compile as SchemaCompile } from "typebox/schema";
6
6
 
7
7
  //#region src/type/typebox-value-live.ts
8
8
  Settings.Set({ unionPrioritySort: false });
@@ -1,4 +1,4 @@
1
- import { Build, Compile as SchemaCompile } from "typebox/schema";
2
- import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
3
1
  import { Compile } from "typebox/compile";
2
+ import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
3
+ import { Build, Compile as SchemaCompile } from "typebox/schema";
4
4
  export { Build, Check, Clean, Clone, Compile, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile };
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
- let typebox_schema = require("typebox/schema");
4
- let typebox_value = require("typebox/value");
5
3
  let typebox_compile = require("typebox/compile");
4
+ let typebox_value = require("typebox/value");
5
+ let typebox_schema = require("typebox/schema");
6
6
 
7
7
  Object.defineProperty(exports, 'Build', {
8
8
  enumerable: true,
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import { Build, Compile as SchemaCompile } from "typebox/schema";
3
- import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
4
2
  import { Compile } from "typebox/compile";
3
+ import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
4
+ import { Build, Compile as SchemaCompile } from "typebox/schema";
5
5
 
6
6
  export { Build, Check, Clean, Clone, Compile, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile };
@@ -1,9 +1,9 @@
1
- import * as _$typebox_schema0 from "typebox/schema";
2
- import { Build as Build$1, Compile as Compile$1 } from "typebox/schema";
1
+ import * as _$typebox_compile0 from "typebox/compile";
2
+ import { Compile as Compile$1 } from "typebox/compile";
3
3
  import * as _$typebox_value0 from "typebox/value";
4
4
  import { Check as Check$1, Clean as Clean$1, Clone as Clone$1, Create as Create$1, Decode as Decode$1, DecodeUnsafe as DecodeUnsafe$1, Default as Default$1, Encode as Encode$1, EncodeUnsafe as EncodeUnsafe$1, Errors as Errors$1, HasCodec as HasCodec$1 } from "typebox/value";
5
- import * as _$typebox_compile0 from "typebox/compile";
6
- import { Compile as Compile$2 } from "typebox/compile";
5
+ import * as _$typebox_schema0 from "typebox/schema";
6
+ import { Build as Build$1, Compile as Compile$2 } from "typebox/schema";
7
7
 
8
8
  //#region src/type/typebox-value.d.ts
9
9
  interface TypeboxNamespaces {
@@ -27,9 +27,9 @@ declare let Encode: typeof Encode$1;
27
27
  declare let EncodeUnsafe: typeof EncodeUnsafe$1;
28
28
  declare let Errors: typeof Errors$1;
29
29
  declare let HasCodec: typeof HasCodec$1;
30
- declare let SchemaCompile: typeof Compile$1;
30
+ declare let SchemaCompile: typeof Compile$2;
31
31
  declare let Build: typeof Build$1;
32
- declare let Compile: typeof Compile$2;
32
+ declare let Compile: typeof Compile$1;
33
33
  declare function injectTypebox(typebox: TypeboxNamespaces): void;
34
34
  //#endregion
35
35
  export { Build, Check, Clean, Clone, Compile, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile, TypeboxNamespaces, injectTypebox, preloadTypebox, load as warmTypebox };
package/dist/types.d.ts CHANGED
@@ -508,13 +508,13 @@ type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema
508
508
  /**
509
509
  * Type-level route metadata surfaced on the route's Eden type
510
510
  * (`CreateEdenResponse['meta']`). Reserved key like `seed`/`detail`/
511
- * `introspect` — stripped at runtime, never lands on route hooks
511
+ * `introspect` stripped at runtime, never lands on route hooks
512
512
  */
513
513
  meta?: unknown;
514
514
  /**
515
515
  * Phantom {@link MacroTypeLambda} computing per call site context from
516
516
  * the route's literal hook value. Reserved key like `seed`/`meta`/
517
- * `introspect` — set it with `macroType<Lambda>()`; stripped at runtime
517
+ * `introspect` set it with `macroType<Lambda>()`; stripped at runtime
518
518
  */
519
519
  $type?: MacroTypeLambda;
520
520
  /**
@@ -523,7 +523,9 @@ type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema
523
523
  * on the route's final hooks: its own, the ones every macro added and
524
524
  * the ones it inherits from hooks registered before it. A WebSocket
525
525
  * route hands over its own hooks only. Applied by
526
- * a guard, it sees the guard's hooks once instead of each route's
526
+ * a guard, it sees the guard's hooks once instead of each route's.
527
+ * A `schema: 'merge'` guard's response map
528
+ * (`hooks.schemas[i].response`) is read-only
527
529
  *
528
530
  * @param option
529
531
  */
package/dist/utils.d.ts CHANGED
@@ -29,7 +29,7 @@ declare const isNotEmpty: <T extends Object>(obj?: T) => boolean | undefined;
29
29
  * amortizes to O(1) per insertion.
30
30
  */
31
31
  declare function evictOldestHalf(cache: Map<any, any>): void;
32
- declare function fnv1a(str: string): number;
32
+ declare function fnv1a(str: string, hash?: number): number;
33
33
  /**
34
34
  * 48-bit hash of a named plugin's key (fnv1a + 16 bits of a second hash): at
35
35
  * 32 bits two plugins collide by ~77k and the second is dropped. 48 keeps
@@ -39,11 +39,6 @@ declare function pluginHash(str: string): number;
39
39
  declare const compositionKeys: readonly string[];
40
40
  declare function refTargets(roots: unknown[], models?: Record<string, unknown>): (name: string) => Iterable<unknown>;
41
41
  declare const macroOrigin: WeakMap<object | Function, number>;
42
- /**
43
- * Id of an unnamed plugin in `childrenHash`, negative so it never collides
44
- * with a named plugin's unsigned hash
45
- */
46
- declare const pluginId: (plugin: object) => number;
47
42
  /**
48
43
  * Linked-list representation of the scope/global hook chain of a route
49
44
  *
@@ -229,4 +224,4 @@ declare const isSocketQuiet: (socket: {
229
224
  }) => boolean;
230
225
  declare const isHTMLBundle: (value: unknown) => value is BunHTMLBundlelike;
231
226
  //#endregion
232
- export { ChainInfo, ChainNode, CompactBeforeHandleChunk, CompactBeforeHandlePrefix, DeriveEntry, ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, constantTimeEqual, createErrorEventHandler, deriveEntryFn, deriveQueues, eventProperties, evictOldestHalf, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isDisposable, isElysiaForm, isEmpty, isHTMLBundle, isMapDeriveEntry, isNotEmpty, isPlainDeriveEntry, isPlainObject, isRecordNumber, isSingleton, isSocketQuiet, joinPath, macroEpoch, macroOrigin, macroType, mapDeriveEntry, markPropertySingletons, markSingletons, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, occurrenceDeriveEntries, pluginHash, pluginId, prefix, redirect, refTargets, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData, throwLifecycleErrors };
227
+ export { ChainInfo, ChainNode, CompactBeforeHandleChunk, CompactBeforeHandlePrefix, DeriveEntry, ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, constantTimeEqual, createErrorEventHandler, deriveEntryFn, deriveQueues, eventProperties, evictOldestHalf, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isDisposable, isElysiaForm, isEmpty, isHTMLBundle, isMapDeriveEntry, isNotEmpty, isPlainDeriveEntry, isPlainObject, isRecordNumber, isSingleton, isSocketQuiet, joinPath, macroEpoch, macroOrigin, macroType, mapDeriveEntry, markPropertySingletons, markSingletons, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, occurrenceDeriveEntries, pluginHash, prefix, redirect, refTargets, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData, throwLifecycleErrors };
package/dist/utils.js CHANGED
@@ -49,8 +49,7 @@ function evictOldestHalf(cache) {
49
49
  cache.clear();
50
50
  for (const entry of keep) cache.set(entry[0], entry[1]);
51
51
  }
52
- function fnv1a(str) {
53
- let hash = FNV_OFFSET_BASIS;
52
+ function fnv1a(str, hash = FNV_OFFSET_BASIS) {
54
53
  const len = str.length;
55
54
  for (let i = 0; i < len; i++) {
56
55
  hash ^= str.charCodeAt(i);
@@ -95,13 +94,13 @@ function refTargets(roots, models = {}) {
95
94
  }
96
95
  const macroOrigin = /* @__PURE__ */ new WeakMap();
97
96
  /**
98
- * Id of `ref` in the registry at `globalThis[key]`, `next` being the last id
99
- * handed out. Weak so it doesn't retain `ref`, realm-wide so every installed
100
- * Elysia copy agrees
97
+ * Id of `ref` in the registry at `globalThis['~elysiaSeedIds']`, `next` being
98
+ * the last id handed out. Weak so it doesn't retain `ref`, realm-wide so every
99
+ * installed Elysia copy agrees
101
100
  */
102
- function realmId(key, ref) {
101
+ function realmId(ref) {
103
102
  const realm = globalThis;
104
- const registry = realm[key] ??= {
103
+ const registry = realm["~elysiaSeedIds"] ??= {
105
104
  ids: /* @__PURE__ */ new WeakMap(),
106
105
  next: 0
107
106
  };
@@ -109,11 +108,6 @@ function realmId(key, ref) {
109
108
  if (id === void 0) registry.ids.set(ref, id = ++registry.next);
110
109
  return id;
111
110
  }
112
- /**
113
- * Id of an unnamed plugin in `childrenHash`, negative so it never collides
114
- * with a named plugin's unsigned hash
115
- */
116
- const pluginId = (plugin) => -realmId("~elysiaPluginIds", plugin);
117
111
  const COMPACT_CHUNK_SIZE = 32;
118
112
  const emptyCompactBeforeHandlePrefix = {
119
113
  length: 0,
@@ -757,11 +751,11 @@ prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
757
751
  };
758
752
  function serializeMacroSeed(_key, value) {
759
753
  switch (typeof value) {
760
- case "function": return "\0ref:" + realmId("~elysiaSeedIds", value);
754
+ case "function": return "\0ref:" + realmId(value);
761
755
  case "bigint": return "\0bigint:" + value.toString();
762
756
  case "symbol": {
763
757
  const key = Symbol.keyFor(value);
764
- return key === void 0 ? "\0ref:" + realmId("~elysiaSeedIds", value) : "\0symfor:" + key;
758
+ return key === void 0 ? "\0ref:" + realmId(value) : "\0symfor:" + key;
765
759
  }
766
760
  case "undefined": return "\0undefined";
767
761
  default: return value;
@@ -888,7 +882,6 @@ exports.mergeResponse = mergeResponse;
888
882
  exports.nullObject = nullObject;
889
883
  exports.occurrenceDeriveEntries = occurrenceDeriveEntries;
890
884
  exports.pluginHash = pluginHash;
891
- exports.pluginId = pluginId;
892
885
  exports.prefix = prefix;
893
886
  exports.redirect = redirect;
894
887
  exports.refTargets = refTargets;
package/dist/utils.mjs CHANGED
@@ -49,8 +49,7 @@ function evictOldestHalf(cache) {
49
49
  cache.clear();
50
50
  for (const entry of keep) cache.set(entry[0], entry[1]);
51
51
  }
52
- function fnv1a(str) {
53
- let hash = FNV_OFFSET_BASIS;
52
+ function fnv1a(str, hash = FNV_OFFSET_BASIS) {
54
53
  const len = str.length;
55
54
  for (let i = 0; i < len; i++) {
56
55
  hash ^= str.charCodeAt(i);
@@ -95,13 +94,13 @@ function refTargets(roots, models = {}) {
95
94
  }
96
95
  const macroOrigin = /* @__PURE__ */ new WeakMap();
97
96
  /**
98
- * Id of `ref` in the registry at `globalThis[key]`, `next` being the last id
99
- * handed out. Weak so it doesn't retain `ref`, realm-wide so every installed
100
- * Elysia copy agrees
97
+ * Id of `ref` in the registry at `globalThis['~elysiaSeedIds']`, `next` being
98
+ * the last id handed out. Weak so it doesn't retain `ref`, realm-wide so every
99
+ * installed Elysia copy agrees
101
100
  */
102
- function realmId(key, ref) {
101
+ function realmId(ref) {
103
102
  const realm = globalThis;
104
- const registry = realm[key] ??= {
103
+ const registry = realm["~elysiaSeedIds"] ??= {
105
104
  ids: /* @__PURE__ */ new WeakMap(),
106
105
  next: 0
107
106
  };
@@ -109,11 +108,6 @@ function realmId(key, ref) {
109
108
  if (id === void 0) registry.ids.set(ref, id = ++registry.next);
110
109
  return id;
111
110
  }
112
- /**
113
- * Id of an unnamed plugin in `childrenHash`, negative so it never collides
114
- * with a named plugin's unsigned hash
115
- */
116
- const pluginId = (plugin) => -realmId("~elysiaPluginIds", plugin);
117
111
  const COMPACT_CHUNK_SIZE = 32;
118
112
  const emptyCompactBeforeHandlePrefix = {
119
113
  length: 0,
@@ -757,11 +751,11 @@ prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
757
751
  };
758
752
  function serializeMacroSeed(_key, value) {
759
753
  switch (typeof value) {
760
- case "function": return "\0ref:" + realmId("~elysiaSeedIds", value);
754
+ case "function": return "\0ref:" + realmId(value);
761
755
  case "bigint": return "\0bigint:" + value.toString();
762
756
  case "symbol": {
763
757
  const key = Symbol.keyFor(value);
764
- return key === void 0 ? "\0ref:" + realmId("~elysiaSeedIds", value) : "\0symfor:" + key;
758
+ return key === void 0 ? "\0ref:" + realmId(value) : "\0symfor:" + key;
765
759
  }
766
760
  case "undefined": return "\0undefined";
767
761
  default: return value;
@@ -831,4 +825,4 @@ const isSocketQuiet = (socket) => socket.readyState === 3 && !socket.data.inflig
831
825
  const isHTMLBundle = (value) => Object.prototype.toString.call(value) === "[object HTMLBundle]" || typeof value?.index === "string" && Array.isArray(value.files);
832
826
 
833
827
  //#endregion
834
- export { ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, constantTimeEqual, createErrorEventHandler, deriveEntryFn, deriveQueues, eventProperties, evictOldestHalf, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isDisposable, isElysiaForm, isEmpty, isHTMLBundle, isMapDeriveEntry, isNotEmpty, isPlainDeriveEntry, isPlainObject, isRecordNumber, isSingleton, isSocketQuiet, joinPath, macroEpoch, macroOrigin, macroType, mapDeriveEntry, markPropertySingletons, markSingletons, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, occurrenceDeriveEntries, pluginHash, pluginId, prefix, redirect, refTargets, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData, throwLifecycleErrors };
828
+ export { ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, constantTimeEqual, createErrorEventHandler, deriveEntryFn, deriveQueues, eventProperties, evictOldestHalf, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isDisposable, isElysiaForm, isEmpty, isHTMLBundle, isMapDeriveEntry, isNotEmpty, isPlainDeriveEntry, isPlainObject, isRecordNumber, isSingleton, isSocketQuiet, joinPath, macroEpoch, macroOrigin, macroType, mapDeriveEntry, markPropertySingletons, markSingletons, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, occurrenceDeriveEntries, pluginHash, prefix, redirect, refTargets, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData, throwLifecycleErrors };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elysia",
3
3
  "description": "Ergonomic Framework for Human",
4
- "version": "2.0.0-beta.22",
4
+ "version": "2.0.0-beta.24",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",