elysia 2.0.0-exp.56 → 2.0.0-exp.57

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
@@ -1,7 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.js');
3
3
  const require_universal_constants = require('./universal/constants.js');
4
- const require_constants = require('./constants.js');
5
4
  const require_utils = require('./utils.js');
6
5
  const require_type_bridge = require('./type/bridge.js');
7
6
  const require_universal_is_production = require('./universal/is-production.js');
@@ -1275,7 +1274,8 @@ var Elysia = class Elysia {
1275
1274
  #routeMayHaveModelRef(table, i) {
1276
1275
  const macroScope = table.macroScope?.get(i);
1277
1276
  const owner = table.owner[i];
1278
- if (require_compile_handler_index.localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
1277
+ const candidate = macroScope ?? owner ?? this;
1278
+ if ((candidate === this ? this : require_compile_handler_index.localMacroRoot(candidate, this))["~ext"]?.macro) return true;
1279
1279
  if (Elysia.#hookHasString(table.localHook[i])) return true;
1280
1280
  const appHook = table.appHook[i];
1281
1281
  if (appHook !== void 0 && appHook.refs) return true;
@@ -1416,25 +1416,19 @@ var Elysia = class Elysia {
1416
1416
  else for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(require_route_table.routeRow(table, i), method[i]);
1417
1417
  if (length) require_compile_aot.Compiled.claim(this["~programId"], this["~aotFingerprint"] = require_compile_aot.createAotFingerprint());
1418
1418
  const isLoose = this["~config"]?.strictPath !== true;
1419
- let hasLooseCandidate = false;
1420
- if (isLoose) for (let i = 0; i < length; i++) {
1421
- const p = path[i];
1422
- if (canRegisterLoose(p, (flags[i] & require_route_table.RouteFlag.Dynamic) !== 0)) {
1423
- hasLooseCandidate = true;
1424
- break;
1425
- }
1426
- }
1427
1419
  let explicitPaths;
1428
- if (hasLooseCandidate) explicitPaths = /* @__PURE__ */ new Map();
1429
- if (explicitPaths) for (let i = 0; i < length; i++) {
1430
- const m = method[i];
1431
- const p = path[i];
1432
- let set = explicitPaths.get(m);
1433
- if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1434
- set.add(p);
1435
- if (require_constants.needEncodeRegex.test(p)) {
1436
- const encoded = encodeURI(p);
1437
- if (encoded !== p) set.add(encoded);
1420
+ if (isLoose && table.hasLoose) {
1421
+ explicitPaths = /* @__PURE__ */ new Map();
1422
+ for (let i = 0; i < length; i++) {
1423
+ const m = method[i];
1424
+ const p = path[i];
1425
+ let set = explicitPaths.get(m);
1426
+ if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1427
+ set.add(p);
1428
+ if ((flags[i] & require_route_table.RouteFlag.Encode) !== 0) {
1429
+ const encoded = encodeURI(p);
1430
+ if (encoded !== p) set.add(encoded);
1431
+ }
1438
1432
  }
1439
1433
  }
1440
1434
  for (let i = 0; i < length; i++) {
@@ -1465,7 +1459,7 @@ var Elysia = class Elysia {
1465
1459
  continue;
1466
1460
  }
1467
1461
  const isDynamic = (routeFlags & require_route_table.RouteFlag.Dynamic) !== 0;
1468
- const needsEncode = require_constants.needEncodeRegex.test(routePath);
1462
+ const needsEncode = (routeFlags & require_route_table.RouteFlag.Encode) !== 0;
1469
1463
  const registerLoose = isLoose && canRegisterLoose(routePath, isDynamic);
1470
1464
  const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
1471
1465
  if (!isDynamic && !needsEncode && !registerLoose) {
package/dist/base.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { isBun } from "./universal/constants.mjs";
2
- import { needEncodeRegex } from "./constants.mjs";
3
2
  import { clonePlainDecorators, clonePlainDeep, coalesceStandaloneSchemas, createErrorEventHandler, eventProperties, fnOrigin, fnv1a, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isEmpty, isNotEmpty, isRecordNumber, joinPath, macroOrigin, mapDeriveEntry, mergeDeep, mergeResponse, nullObject, pushField, schemaProperties, serializeMacroSeed } from "./utils.mjs";
4
3
  import { Ref } from "./type/bridge.mjs";
5
4
  import { isProduction } from "./universal/is-production.mjs";
@@ -1272,7 +1271,8 @@ var Elysia = class Elysia {
1272
1271
  #routeMayHaveModelRef(table, i) {
1273
1272
  const macroScope = table.macroScope?.get(i);
1274
1273
  const owner = table.owner[i];
1275
- if (localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
1274
+ const candidate = macroScope ?? owner ?? this;
1275
+ if ((candidate === this ? this : localMacroRoot(candidate, this))["~ext"]?.macro) return true;
1276
1276
  if (Elysia.#hookHasString(table.localHook[i])) return true;
1277
1277
  const appHook = table.appHook[i];
1278
1278
  if (appHook !== void 0 && appHook.refs) return true;
@@ -1413,25 +1413,19 @@ var Elysia = class Elysia {
1413
1413
  else for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(routeRow(table, i), method[i]);
1414
1414
  if (length) Compiled.claim(this["~programId"], this["~aotFingerprint"] = createAotFingerprint());
1415
1415
  const isLoose = this["~config"]?.strictPath !== true;
1416
- let hasLooseCandidate = false;
1417
- if (isLoose) for (let i = 0; i < length; i++) {
1418
- const p = path[i];
1419
- if (canRegisterLoose(p, (flags[i] & RouteFlag.Dynamic) !== 0)) {
1420
- hasLooseCandidate = true;
1421
- break;
1422
- }
1423
- }
1424
1416
  let explicitPaths;
1425
- if (hasLooseCandidate) explicitPaths = /* @__PURE__ */ new Map();
1426
- if (explicitPaths) for (let i = 0; i < length; i++) {
1427
- const m = method[i];
1428
- const p = path[i];
1429
- let set = explicitPaths.get(m);
1430
- if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1431
- set.add(p);
1432
- if (needEncodeRegex.test(p)) {
1433
- const encoded = encodeURI(p);
1434
- if (encoded !== p) set.add(encoded);
1417
+ if (isLoose && table.hasLoose) {
1418
+ explicitPaths = /* @__PURE__ */ new Map();
1419
+ for (let i = 0; i < length; i++) {
1420
+ const m = method[i];
1421
+ const p = path[i];
1422
+ let set = explicitPaths.get(m);
1423
+ if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1424
+ set.add(p);
1425
+ if ((flags[i] & RouteFlag.Encode) !== 0) {
1426
+ const encoded = encodeURI(p);
1427
+ if (encoded !== p) set.add(encoded);
1428
+ }
1435
1429
  }
1436
1430
  }
1437
1431
  for (let i = 0; i < length; i++) {
@@ -1462,7 +1456,7 @@ var Elysia = class Elysia {
1462
1456
  continue;
1463
1457
  }
1464
1458
  const isDynamic = (routeFlags & RouteFlag.Dynamic) !== 0;
1465
- const needsEncode = needEncodeRegex.test(routePath);
1459
+ const needsEncode = (routeFlags & RouteFlag.Encode) !== 0;
1466
1460
  const registerLoose = isLoose && canRegisterLoose(routePath, isDynamic);
1467
1461
  const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
1468
1462
  if (!isDynamic && !needsEncode && !registerLoose) {
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-exp.56";
3
+ var version = "2.0.0-exp.57";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.0.0-exp.56";
2
+ var version = "2.0.0-exp.57";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -6,6 +6,7 @@ import { AnyElysia } from "./base.js";
6
6
  declare const RouteFlag: {
7
7
  readonly WS: 1;
8
8
  readonly Dynamic: 2;
9
+ readonly Encode: 4;
9
10
  };
10
11
  interface RouteTable {
11
12
  readonly length: number;
@@ -17,6 +18,8 @@ interface RouteTable {
17
18
  readonly appHook: (ChainNode | undefined)[];
18
19
  readonly inheritedChain: (ChainNode | undefined)[];
19
20
  readonly flags: number[];
21
+ /** any static route path is '' or ends with '/' (loose-alias candidate) */
22
+ readonly hasLoose: boolean;
20
23
  readonly macroScope?: Map<number, AnyElysia>;
21
24
  }
22
25
  declare function buildRouteTable(declaredRoutes: readonly InternalRoute[]): RouteTable;
@@ -4,18 +4,20 @@ const require_constants = require('./constants.js');
4
4
  //#region src/route-table.ts
5
5
  const RouteFlag = {
6
6
  WS: 1,
7
- Dynamic: 2
7
+ Dynamic: 2,
8
+ Encode: 4
8
9
  };
9
10
  function buildRouteTable(declaredRoutes) {
10
11
  const length = declaredRoutes.length;
11
- const method = [];
12
- const path = [];
13
- const handler = [];
14
- const owner = [];
15
- const localHook = [];
16
- const appHook = [];
17
- const inheritedChain = [];
18
- const flags = [];
12
+ const method = new Array(length);
13
+ const path = new Array(length);
14
+ const handler = new Array(length);
15
+ const owner = new Array(length);
16
+ const localHook = new Array(length);
17
+ const appHook = new Array(length);
18
+ const inheritedChain = new Array(length);
19
+ const flags = new Array(length);
20
+ let hasLoose = false;
19
21
  let macroScope;
20
22
  for (let i = 0; i < length; i++) {
21
23
  const route = declaredRoutes[i];
@@ -26,7 +28,9 @@ function buildRouteTable(declaredRoutes) {
26
28
  localHook[i] = route[4];
27
29
  appHook[i] = route[5];
28
30
  inheritedChain[i] = route[6];
29
- flags[i] = (route[0] === "WS" ? RouteFlag.WS : 0) | (require_constants.isDynamicRegex.test(p) ? RouteFlag.Dynamic : 0);
31
+ const isDynamic = p.indexOf(":") !== -1 || p.indexOf("*") !== -1;
32
+ flags[i] = (route[0] === "WS" ? RouteFlag.WS : 0) | (isDynamic ? RouteFlag.Dynamic : 0) | (require_constants.needEncodeRegex.test(p) ? RouteFlag.Encode : 0);
33
+ if (!isDynamic && (p.length === 0 || p.charCodeAt(p.length - 1) === 47)) hasLoose = true;
30
34
  if (route[7]) (macroScope ??= /* @__PURE__ */ new Map()).set(i, route[7]);
31
35
  }
32
36
  return {
@@ -39,6 +43,7 @@ function buildRouteTable(declaredRoutes) {
39
43
  appHook,
40
44
  inheritedChain,
41
45
  flags,
46
+ hasLoose,
42
47
  macroScope
43
48
  };
44
49
  }
@@ -1,20 +1,22 @@
1
- import { isDynamicRegex } from "./constants.mjs";
1
+ import { needEncodeRegex } from "./constants.mjs";
2
2
 
3
3
  //#region src/route-table.ts
4
4
  const RouteFlag = {
5
5
  WS: 1,
6
- Dynamic: 2
6
+ Dynamic: 2,
7
+ Encode: 4
7
8
  };
8
9
  function buildRouteTable(declaredRoutes) {
9
10
  const length = declaredRoutes.length;
10
- const method = [];
11
- const path = [];
12
- const handler = [];
13
- const owner = [];
14
- const localHook = [];
15
- const appHook = [];
16
- const inheritedChain = [];
17
- const flags = [];
11
+ const method = new Array(length);
12
+ const path = new Array(length);
13
+ const handler = new Array(length);
14
+ const owner = new Array(length);
15
+ const localHook = new Array(length);
16
+ const appHook = new Array(length);
17
+ const inheritedChain = new Array(length);
18
+ const flags = new Array(length);
19
+ let hasLoose = false;
18
20
  let macroScope;
19
21
  for (let i = 0; i < length; i++) {
20
22
  const route = declaredRoutes[i];
@@ -25,7 +27,9 @@ function buildRouteTable(declaredRoutes) {
25
27
  localHook[i] = route[4];
26
28
  appHook[i] = route[5];
27
29
  inheritedChain[i] = route[6];
28
- flags[i] = (route[0] === "WS" ? RouteFlag.WS : 0) | (isDynamicRegex.test(p) ? RouteFlag.Dynamic : 0);
30
+ const isDynamic = p.indexOf(":") !== -1 || p.indexOf("*") !== -1;
31
+ flags[i] = (route[0] === "WS" ? RouteFlag.WS : 0) | (isDynamic ? RouteFlag.Dynamic : 0) | (needEncodeRegex.test(p) ? RouteFlag.Encode : 0);
32
+ if (!isDynamic && (p.length === 0 || p.charCodeAt(p.length - 1) === 47)) hasLoose = true;
29
33
  if (route[7]) (macroScope ??= /* @__PURE__ */ new Map()).set(i, route[7]);
30
34
  }
31
35
  return {
@@ -38,6 +42,7 @@ function buildRouteTable(declaredRoutes) {
38
42
  appHook,
39
43
  inheritedChain,
40
44
  flags,
45
+ hasLoose,
41
46
  macroScope
42
47
  };
43
48
  }
@@ -34,7 +34,7 @@ declare const coerceQuery: () => CoerceOption[];
34
34
  declare const coerceBody: () => CoerceOption[];
35
35
  declare const coerceFormData: () => CoerceOption[];
36
36
  declare const coerceStringToStructure: () => CoerceOption[];
37
- declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): TSchema | BaseSchema;
37
+ declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): BaseSchema | TSchema;
38
38
  declare function captureCoercePlan(original: any, coerced: any): CoercePlan | null;
39
39
  /** Full rebuild: scalar leaves + ObjectString/ArrayString sites (wired path). */
40
40
  declare const buildCoercedFromPlan: (original: any, plan: CoercePlan, seen?: Set<string>) => any;
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-exp.56",
4
+ "version": "2.0.0-exp.57",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",