elysia 2.0.0-exp.56 → 2.0.0-exp.58

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');
@@ -1108,8 +1107,6 @@ var Elysia = class Elysia {
1108
1107
  }
1109
1108
  ws(path, optionsOrHandler, handler) {
1110
1109
  this["~hasWS"] = true;
1111
- const adapter = this["~config"]?.adapter;
1112
- if (!adapter?.websocket && !require_universal_constants.isBun) throw new Error(`[Elysia] WebSocket is not supported on '${adapter?.name ?? "web-standard"}' adapter.`);
1113
1110
  let opts;
1114
1111
  if (handler !== void 0) {
1115
1112
  opts = Object.assign(require_utils.nullObject(), optionsOrHandler);
@@ -1275,7 +1272,8 @@ var Elysia = class Elysia {
1275
1272
  #routeMayHaveModelRef(table, i) {
1276
1273
  const macroScope = table.macroScope?.get(i);
1277
1274
  const owner = table.owner[i];
1278
- if (require_compile_handler_index.localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
1275
+ const candidate = macroScope ?? owner ?? this;
1276
+ if ((candidate === this ? this : require_compile_handler_index.localMacroRoot(candidate, this))["~ext"]?.macro) return true;
1279
1277
  if (Elysia.#hookHasString(table.localHook[i])) return true;
1280
1278
  const appHook = table.appHook[i];
1281
1279
  if (appHook !== void 0 && appHook.refs) return true;
@@ -1416,25 +1414,19 @@ var Elysia = class Elysia {
1416
1414
  else for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(require_route_table.routeRow(table, i), method[i]);
1417
1415
  if (length) require_compile_aot.Compiled.claim(this["~programId"], this["~aotFingerprint"] = require_compile_aot.createAotFingerprint());
1418
1416
  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
1417
  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);
1418
+ if (isLoose && table.hasLoose) {
1419
+ explicitPaths = /* @__PURE__ */ new Map();
1420
+ for (let i = 0; i < length; i++) {
1421
+ const m = method[i];
1422
+ const p = path[i];
1423
+ let set = explicitPaths.get(m);
1424
+ if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1425
+ set.add(p);
1426
+ if ((flags[i] & require_route_table.RouteFlag.Encode) !== 0) {
1427
+ const encoded = encodeURI(p);
1428
+ if (encoded !== p) set.add(encoded);
1429
+ }
1438
1430
  }
1439
1431
  }
1440
1432
  for (let i = 0; i < length; i++) {
@@ -1442,6 +1434,7 @@ var Elysia = class Elysia {
1442
1434
  const routePath = path[i];
1443
1435
  const routeFlags = flags[i];
1444
1436
  if ((routeFlags & require_route_table.RouteFlag.WS) !== 0) {
1437
+ if (!wsCap) throw new Error(`[Elysia] WebSocket route ${routeMethod} ${routePath} defined, but no WS capability is available. Ensure that .use(websocket()) is applied.`);
1445
1438
  const ws = wsCap.provider.buildWSRoute(require_route_table.routeRow(table, i), this);
1446
1439
  const handler = ws[0];
1447
1440
  const options = ws[1];
@@ -1465,7 +1458,7 @@ var Elysia = class Elysia {
1465
1458
  continue;
1466
1459
  }
1467
1460
  const isDynamic = (routeFlags & require_route_table.RouteFlag.Dynamic) !== 0;
1468
- const needsEncode = require_constants.needEncodeRegex.test(routePath);
1461
+ const needsEncode = (routeFlags & require_route_table.RouteFlag.Encode) !== 0;
1469
1462
  const registerLoose = isLoose && canRegisterLoose(routePath, isDynamic);
1470
1463
  const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
1471
1464
  if (!isDynamic && !needsEncode && !registerLoose) {
@@ -1510,7 +1503,7 @@ var Elysia = class Elysia {
1510
1503
  }
1511
1504
  #handle;
1512
1505
  get handle() {
1513
- return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.startsWith("/") ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1506
+ return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.charCodeAt(0) === 47 ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1514
1507
  }
1515
1508
  listen(options, callback) {
1516
1509
  const listen = (this["~config"]?.adapter ?? (require_universal_constants.isBun ? require_adapter_bun_index.BunAdapter : void 0))?.listen;
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";
@@ -1105,8 +1104,6 @@ var Elysia = class Elysia {
1105
1104
  }
1106
1105
  ws(path, optionsOrHandler, handler) {
1107
1106
  this["~hasWS"] = true;
1108
- const adapter = this["~config"]?.adapter;
1109
- if (!adapter?.websocket && !isBun) throw new Error(`[Elysia] WebSocket is not supported on '${adapter?.name ?? "web-standard"}' adapter.`);
1110
1107
  let opts;
1111
1108
  if (handler !== void 0) {
1112
1109
  opts = Object.assign(nullObject(), optionsOrHandler);
@@ -1272,7 +1269,8 @@ var Elysia = class Elysia {
1272
1269
  #routeMayHaveModelRef(table, i) {
1273
1270
  const macroScope = table.macroScope?.get(i);
1274
1271
  const owner = table.owner[i];
1275
- if (localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
1272
+ const candidate = macroScope ?? owner ?? this;
1273
+ if ((candidate === this ? this : localMacroRoot(candidate, this))["~ext"]?.macro) return true;
1276
1274
  if (Elysia.#hookHasString(table.localHook[i])) return true;
1277
1275
  const appHook = table.appHook[i];
1278
1276
  if (appHook !== void 0 && appHook.refs) return true;
@@ -1413,25 +1411,19 @@ var Elysia = class Elysia {
1413
1411
  else for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(routeRow(table, i), method[i]);
1414
1412
  if (length) Compiled.claim(this["~programId"], this["~aotFingerprint"] = createAotFingerprint());
1415
1413
  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
1414
  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);
1415
+ if (isLoose && table.hasLoose) {
1416
+ explicitPaths = /* @__PURE__ */ new Map();
1417
+ for (let i = 0; i < length; i++) {
1418
+ const m = method[i];
1419
+ const p = path[i];
1420
+ let set = explicitPaths.get(m);
1421
+ if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
1422
+ set.add(p);
1423
+ if ((flags[i] & RouteFlag.Encode) !== 0) {
1424
+ const encoded = encodeURI(p);
1425
+ if (encoded !== p) set.add(encoded);
1426
+ }
1435
1427
  }
1436
1428
  }
1437
1429
  for (let i = 0; i < length; i++) {
@@ -1439,6 +1431,7 @@ var Elysia = class Elysia {
1439
1431
  const routePath = path[i];
1440
1432
  const routeFlags = flags[i];
1441
1433
  if ((routeFlags & RouteFlag.WS) !== 0) {
1434
+ if (!wsCap) throw new Error(`[Elysia] WebSocket route ${routeMethod} ${routePath} defined, but no WS capability is available. Ensure that .use(websocket()) is applied.`);
1442
1435
  const ws = wsCap.provider.buildWSRoute(routeRow(table, i), this);
1443
1436
  const handler = ws[0];
1444
1437
  const options = ws[1];
@@ -1462,7 +1455,7 @@ var Elysia = class Elysia {
1462
1455
  continue;
1463
1456
  }
1464
1457
  const isDynamic = (routeFlags & RouteFlag.Dynamic) !== 0;
1465
- const needsEncode = needEncodeRegex.test(routePath);
1458
+ const needsEncode = (routeFlags & RouteFlag.Encode) !== 0;
1466
1459
  const registerLoose = isLoose && canRegisterLoose(routePath, isDynamic);
1467
1460
  const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
1468
1461
  if (!isDynamic && !needsEncode && !registerLoose) {
@@ -1507,7 +1500,7 @@ var Elysia = class Elysia {
1507
1500
  }
1508
1501
  #handle;
1509
1502
  get handle() {
1510
- return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.startsWith("/") ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1503
+ return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.charCodeAt(0) === 47 ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1511
1504
  }
1512
1505
  listen(options, callback) {
1513
1506
  const listen = (this["~config"]?.adapter ?? (isBun ? BunAdapter : void 0))?.listen;
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.58";
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.58";
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.58",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",