elysia 2.0.0-exp.57 → 2.0.0-exp.59

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.
@@ -2,6 +2,6 @@ import { AnyElysia } from "../../base.js";
2
2
  import { ElysiaAdapterOptions } from "../types.js";
3
3
  //#region src/adapter/bun/index.d.ts
4
4
  declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, readonly []] | undefined;
5
- declare const BunAdapter: ElysiaAdapterOptions;
5
+ declare const BunAdapter: ElysiaAdapterOptions<void>;
6
6
  //#endregion
7
7
  export { BunAdapter, collectStaticRoutes };
@@ -1,6 +1,6 @@
1
1
  import { ElysiaAdapterOptions } from "./types.js";
2
2
 
3
3
  //#region src/adapter/constants.d.ts
4
- declare const defaultAdapter: ElysiaAdapterOptions;
4
+ declare const defaultAdapter: ElysiaAdapterOptions<void>;
5
5
  //#endregion
6
6
  export { defaultAdapter };
@@ -1,7 +1,8 @@
1
+ import { AnyElysia } from "../base.js";
1
2
  import { ElysiaAdapterOptions } from "./types.js";
2
3
 
3
4
  //#region src/adapter/index.d.ts
4
- declare const createAdapter: (adapter: ElysiaAdapterOptions) => ElysiaAdapterOptions;
5
+ declare const createAdapter: <App extends AnyElysia | void = void>(adapter: ElysiaAdapterOptions<App>) => ElysiaAdapterOptions<App>;
5
6
  type ElysiaAdapter = ReturnType<typeof createAdapter>;
6
7
  //#endregion
7
8
  export { ElysiaAdapter, type ElysiaAdapterOptions, createAdapter };
@@ -9,7 +9,7 @@ import { AnyElysia } from "../base.js";
9
9
  *
10
10
  * @since 2.0.0
11
11
  */
12
- interface ElysiaAdapterOptions {
12
+ interface ElysiaAdapterOptions<App extends AnyElysia | void = void> {
13
13
  /**
14
14
  * Name of the adapter, preferably runtime
15
15
  */
@@ -49,6 +49,7 @@ interface ElysiaAdapterOptions {
49
49
  */
50
50
  compact?(response: unknown, ...params: unknown[]): unknown;
51
51
  };
52
+ setup?(app: AnyElysia): App;
52
53
  }
53
54
  //#endregion
54
55
  export { ElysiaAdapterOptions };
@@ -1,5 +1,5 @@
1
1
  import { ElysiaAdapterOptions } from "../types.js";
2
2
  //#region src/adapter/web-standard/index.d.ts
3
- declare const WebStandardAdapter: ElysiaAdapterOptions;
3
+ declare const WebStandardAdapter: ElysiaAdapterOptions<void>;
4
4
  //#endregion
5
5
  export { WebStandardAdapter };
package/dist/base.js CHANGED
@@ -124,9 +124,10 @@ var Elysia = class Elysia {
124
124
  this["~scopeChildren"] = void 0;
125
125
  this["~programId"] = require_compile_aot.createProgramId();
126
126
  if (config) {
127
- const { prefix, name, seed } = config;
127
+ const { prefix, name, seed, adapter } = config;
128
128
  this["~Prefix"] = prefix ? prefix.charCodeAt(0) === 47 ? prefix : `/${prefix}` : void 0;
129
129
  if (name) this.#hash = require_utils.fnv1a(seed ? `${name}_${typeof seed === "object" ? JSON.stringify(seed, require_utils.serializeMacroSeed) : seed}` : name);
130
+ if (adapter?.setup) this.#useFn(adapter.setup);
130
131
  } else this["~Prefix"] = void 0;
131
132
  }
132
133
  get routes() {
@@ -1107,8 +1108,6 @@ var Elysia = class Elysia {
1107
1108
  }
1108
1109
  ws(path, optionsOrHandler, handler) {
1109
1110
  this["~hasWS"] = true;
1110
- const adapter = this["~config"]?.adapter;
1111
- if (!adapter?.websocket && !require_universal_constants.isBun) throw new Error(`[Elysia] WebSocket is not supported on '${adapter?.name ?? "web-standard"}' adapter.`);
1112
1111
  let opts;
1113
1112
  if (handler !== void 0) {
1114
1113
  opts = Object.assign(require_utils.nullObject(), optionsOrHandler);
@@ -1504,7 +1503,7 @@ var Elysia = class Elysia {
1504
1503
  }
1505
1504
  #handle;
1506
1505
  get handle() {
1507
- 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);
1508
1507
  }
1509
1508
  listen(options, callback) {
1510
1509
  const listen = (this["~config"]?.adapter ?? (require_universal_constants.isBun ? require_adapter_bun_index.BunAdapter : void 0))?.listen;
package/dist/base.mjs CHANGED
@@ -121,9 +121,10 @@ var Elysia = class Elysia {
121
121
  this["~scopeChildren"] = void 0;
122
122
  this["~programId"] = createProgramId();
123
123
  if (config) {
124
- const { prefix, name, seed } = config;
124
+ const { prefix, name, seed, adapter } = config;
125
125
  this["~Prefix"] = prefix ? prefix.charCodeAt(0) === 47 ? prefix : `/${prefix}` : void 0;
126
126
  if (name) this.#hash = fnv1a(seed ? `${name}_${typeof seed === "object" ? JSON.stringify(seed, serializeMacroSeed) : seed}` : name);
127
+ if (adapter?.setup) this.#useFn(adapter.setup);
127
128
  } else this["~Prefix"] = void 0;
128
129
  }
129
130
  get routes() {
@@ -1104,8 +1105,6 @@ var Elysia = class Elysia {
1104
1105
  }
1105
1106
  ws(path, optionsOrHandler, handler) {
1106
1107
  this["~hasWS"] = true;
1107
- const adapter = this["~config"]?.adapter;
1108
- if (!adapter?.websocket && !isBun) throw new Error(`[Elysia] WebSocket is not supported on '${adapter?.name ?? "web-standard"}' adapter.`);
1109
1108
  let opts;
1110
1109
  if (handler !== void 0) {
1111
1110
  opts = Object.assign(nullObject(), optionsOrHandler);
@@ -1501,7 +1500,7 @@ var Elysia = class Elysia {
1501
1500
  }
1502
1501
  #handle;
1503
1502
  get handle() {
1504
- 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);
1505
1504
  }
1506
1505
  listen(options, callback) {
1507
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.57";
3
+ var version = "2.0.0-exp.59";
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.57";
2
+ var version = "2.0.0-exp.59";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -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<1 | 2 | 6 | 3 | 10 | 11 | 13 | 14>;
20
+ declare const primitiveElysiaTypes: Set<1 | 2 | 3 | 6 | 10 | 11 | 13 | 14>;
21
21
  declare const noEnumerable: {
22
22
  readonly enumerable: false;
23
23
  };
package/dist/types.d.ts CHANGED
@@ -13,7 +13,7 @@ import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from
13
13
  import { OpenAPIV3 } from "openapi-types";
14
14
 
15
15
  //#region src/types.d.ts
16
- interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope extends EventScope> {
16
+ interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope extends EventScope, in out Adapter extends ElysiaAdapter = ElysiaAdapter> {
17
17
  /**
18
18
  * Define event scope for the instance
19
19
  *
@@ -21,10 +21,10 @@ interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope ex
21
21
  */
22
22
  as?: Scope;
23
23
  /**
24
- * @default BunAdapter
25
- * @since 1.1.11
24
+ * @default BunAdapter v2
25
+ * @since 2.0.0
26
26
  */
27
- adapter?: ElysiaAdapter;
27
+ adapter?: Adapter;
28
28
  /**
29
29
  * Path prefix of the instance
30
30
  *
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.57",
4
+ "version": "2.0.0-exp.59",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",