elysia 2.0.0-beta.22 → 2.0.0-beta.23

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,
package/dist/base.mjs CHANGED
@@ -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,
@@ -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
  }
@@ -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
  }
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.23";
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.23";
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) {
@@ -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<2 | 1 | 6 | 3 | 10 | 11 | 13 | 14>;
21
21
  declare const noEnumerable: {
22
22
  readonly enumerable: false;
23
23
  };
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/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.23",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",