elysia 2.0.0-exp.32 → 2.0.0-exp.33

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.
@@ -1,5 +1,5 @@
1
1
  //#region src/compile/lexer.d.ts
2
- declare const isSpace: (ch: string) => ch is "\n" | " " | "\t" | "\r";
2
+ declare const isSpace: (ch: string) => ch is " " | "\n" | "\t" | "\r";
3
3
  declare const isIdentChar: (ch: string) => boolean;
4
4
  declare const isIdentCharCode: (code: number) => boolean;
5
5
  declare function skipString(src: string, start: number): number;
package/dist/error.d.ts CHANGED
@@ -79,8 +79,8 @@ declare class ValidationError extends ElysiaError {
79
79
  on?: undefined;
80
80
  property?: undefined;
81
81
  detail?: undefined;
82
- expected?: undefined;
83
82
  found?: undefined;
83
+ expected?: undefined;
84
84
  errors?: undefined;
85
85
  } | {
86
86
  type: string;
@@ -89,8 +89,8 @@ declare class ValidationError extends ElysiaError {
89
89
  on: string | undefined;
90
90
  property: string;
91
91
  detail?: undefined;
92
- expected?: undefined;
93
92
  found?: undefined;
93
+ expected?: undefined;
94
94
  errors?: undefined;
95
95
  } | {
96
96
  type: string;
@@ -99,8 +99,8 @@ declare class ValidationError extends ElysiaError {
99
99
  detail: any;
100
100
  on: string | undefined;
101
101
  property: string;
102
- expected: unknown;
103
102
  found: unknown;
103
+ expected: unknown;
104
104
  errors: any[];
105
105
  };
106
106
  toResponse(headers?: Record<string, any>): Response;
@@ -192,6 +192,13 @@ type NumericStatus<Code extends number | keyof StatusMap> = Code extends keyof S
192
192
  type ProblemStatus<P> = P extends {
193
193
  status: infer S extends number | keyof StatusMap;
194
194
  } ? NumericStatus<S> : 500;
195
+ type ProblemResponseBody<Status extends number, P> = {
196
+ type: string;
197
+ title: string;
198
+ status: Status;
199
+ detail?: string;
200
+ instance?: string;
201
+ } & Omit<P, keyof Problem>;
195
202
  declare function problemBody(p: Problem): Record<string, unknown> & {
196
203
  status: number;
197
204
  };
@@ -199,13 +206,28 @@ declare function problemResponse(p: Problem, headers?: Record<string, any>): Res
199
206
  declare function internalServerErrorBody(error: any): Record<string, unknown>;
200
207
  declare function internalServerErrorBodyString(error: any): string;
201
208
  declare function internalServerErrorResponse(error: any): Response;
202
- declare const problem: <const P extends Problem>(detail: P) => ElysiaStatus<ProblemStatus<P>, {
203
- type: string;
204
- title: string;
205
- status: ProblemStatus<P>;
206
- detail?: string;
207
- instance?: string;
208
- } & Omit<P, keyof Problem>>;
209
+ /**
210
+ * RFC 9457 Problem Details function
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * problem(400, { detail: 'Something went wrong' })
215
+ * ````
216
+ *
217
+ * @see https://www.rfc-editor.org/info/rfc9457
218
+ */
219
+ declare function problem<const Code extends number | keyof StatusMap, const P extends Record<string, unknown> = {}>(status: Code, detail?: P & Omit<Problem<Code>, 'status'>): ElysiaStatus<NumericStatus<Code>, ProblemResponseBody<NumericStatus<Code>, P>>;
220
+ /**
221
+ * RFC 9457 Problem Details function
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * problem({ status: 400, detail: 'Something went wrong' })
226
+ * ````
227
+ *
228
+ * @see https://www.rfc-editor.org/info/rfc9457
229
+ */
230
+ declare function problem<const P extends Problem>(detail: P): ElysiaStatus<ProblemStatus<P>, ProblemResponseBody<ProblemStatus<P>, P>>;
209
231
  type CheckExcessProps<T, U> = 0 extends 1 & T ? T : U extends U ? Exclude<keyof T, keyof U> extends never ? T : { [K in keyof U]: U[K] } & { [K in Exclude<keyof T, keyof U>]: never } : never;
210
232
  type SelectiveStatus<in out Res> = <const Code extends keyof Res | StatusMapBack[Extract<keyof StatusMapBack, keyof Res>], T extends (Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never)>(code: Code, response: CheckExcessProps<T, Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never>) => ElysiaStatus<Code, T>;
211
233
  //#endregion
package/dist/error.js CHANGED
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_constants = require('./constants.js');
3
- const require_utils = require('./utils.js');
4
3
  const require_type_bridge = require('./type/bridge.js');
5
4
  const require_type_constants = require('./type/constants.js');
6
5
  const require_adapter_skip_clone = require('./adapter/skip-clone.js');
@@ -319,7 +318,7 @@ var ValidationError = class extends ElysiaError {
319
318
  let expected;
320
319
  const schemaForExpected = first?.schema ?? this.schema;
321
320
  if (schemaForExpected) try {
322
- expected = require_type_bridge.Default(require_utils.nullObject(), schemaForExpected, void 0);
321
+ expected = require_type_bridge.Create(schemaForExpected);
323
322
  } catch {}
324
323
  return {
325
324
  type: "validation",
@@ -328,8 +327,8 @@ var ValidationError = class extends ElysiaError {
328
327
  detail,
329
328
  on: this.type,
330
329
  property,
331
- expected,
332
330
  found: scopeFound(this.value, first),
331
+ expected,
333
332
  errors
334
333
  };
335
334
  }
@@ -447,7 +446,13 @@ function internalServerErrorResponse(error) {
447
446
  require_adapter_skip_clone.skipClone.add(response);
448
447
  return response;
449
448
  }
450
- const problem = (detail) => new ElysiaStatus(detail.status ?? 500, problemBody(detail), { "content-type": PROBLEM_JSON });
449
+ function problem(statusOrDetail, detail) {
450
+ const body = typeof statusOrDetail === "object" ? statusOrDetail : {
451
+ ...detail,
452
+ status: statusOrDetail
453
+ };
454
+ return new ElysiaStatus(body.status ?? 500, problemBody(body), { "content-type": PROBLEM_JSON });
455
+ }
451
456
 
452
457
  //#endregion
453
458
  exports.ElysiaError = ElysiaError;
package/dist/error.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { StatusMap, StatusMapBack } from "./constants.mjs";
2
- import { nullObject } from "./utils.mjs";
3
- import { Default } from "./type/bridge.mjs";
2
+ import { Create } from "./type/bridge.mjs";
4
3
  import { primitiveElysiaTypes } from "./type/constants.mjs";
5
4
  import { skipClone } from "./adapter/skip-clone.mjs";
6
5
  import { env } from "./universal/env.mjs";
@@ -318,7 +317,7 @@ var ValidationError = class extends ElysiaError {
318
317
  let expected;
319
318
  const schemaForExpected = first?.schema ?? this.schema;
320
319
  if (schemaForExpected) try {
321
- expected = Default(nullObject(), schemaForExpected, void 0);
320
+ expected = Create(schemaForExpected);
322
321
  } catch {}
323
322
  return {
324
323
  type: "validation",
@@ -327,8 +326,8 @@ var ValidationError = class extends ElysiaError {
327
326
  detail,
328
327
  on: this.type,
329
328
  property,
330
- expected,
331
329
  found: scopeFound(this.value, first),
330
+ expected,
332
331
  errors
333
332
  };
334
333
  }
@@ -446,7 +445,13 @@ function internalServerErrorResponse(error) {
446
445
  skipClone.add(response);
447
446
  return response;
448
447
  }
449
- const problem = (detail) => new ElysiaStatus(detail.status ?? 500, problemBody(detail), { "content-type": PROBLEM_JSON });
448
+ function problem(statusOrDetail, detail) {
449
+ const body = typeof statusOrDetail === "object" ? statusOrDetail : {
450
+ ...detail,
451
+ status: statusOrDetail
452
+ };
453
+ return new ElysiaStatus(body.status ?? 500, problemBody(body), { "content-type": PROBLEM_JSON });
454
+ }
450
455
 
451
456
  //#endregion
452
457
  export { ElysiaError, ElysiaStatus, InternalServerError, NotFound, PROBLEM_JSON, ParseError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, validationDetail };
@@ -6,9 +6,9 @@ import { TypeBoxValidatorCache } from "./validator/validator-cache.js";
6
6
  import { TypeBoxValidator } from "./validator/index.js";
7
7
  import { Ref } from "typebox/type";
8
8
  import { Compile } from "typebox/compile";
9
- import { Clone, Decode, Default, HasCodec } from "typebox/value";
9
+ import { Clone, Create, Decode, Default, 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;
13
13
  //#endregion
14
- export { Clone, Compile, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
14
+ export { Clone, Compile, Create, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
@@ -17,6 +17,7 @@ function useTypebox(_mod) {}
17
17
  //#endregion
18
18
  exports.Clone = typebox_value.Clone;
19
19
  exports.Compile = typebox_compile.Compile;
20
+ exports.Create = typebox_value.Create;
20
21
  exports.Decode = typebox_value.Decode;
21
22
  exports.Default = typebox_value.Default;
22
23
  exports.HasCodec = typebox_value.HasCodec;
@@ -5,7 +5,7 @@ import { TypeBoxValidator } from "./validator/index.mjs";
5
5
  import { Intersect } from "./elysia/intersect.mjs";
6
6
  import { Ref } from "typebox/type";
7
7
  import { Compile } from "typebox/compile";
8
- import { Clone, Decode, Default, HasCodec } from "typebox/value";
8
+ import { Clone, Create, Decode, Default, HasCodec } from "typebox/value";
9
9
  import { Settings } from "typebox/system";
10
10
 
11
11
  //#region src/type/bridge-live.ts
@@ -13,4 +13,4 @@ Settings.Set({ unionPrioritySort: false });
13
13
  function useTypebox(_mod) {}
14
14
 
15
15
  //#endregion
16
- export { Clone, Compile, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
16
+ export { Clone, Compile, Create, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
@@ -5,11 +5,12 @@ import { TypeBoxValidatorCache as TypeBoxValidatorCache$1 } from "./validator/va
5
5
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
6
6
  import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
7
7
  import { Compile as Compile$1 } from "typebox/compile";
8
- import { Clone as Clone$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
8
+ import { Clone as Clone$1, Create as Create$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
9
9
 
10
10
  //#region src/type/bridge.d.ts
11
11
  interface TypeboxModule {
12
12
  Compile: typeof Compile$1;
13
+ Create: typeof Create$1;
13
14
  Decode: typeof Decode$1;
14
15
  applyCoercions: typeof applyCoercions$1;
15
16
  TypeBoxValidator: TypeBoxValidator$1;
@@ -27,6 +28,7 @@ interface TypeboxModule {
27
28
  Clone: typeof Clone$1;
28
29
  }
29
30
  declare let Compile: typeof Compile$1;
31
+ declare let Create: typeof Create$1;
30
32
  declare let Decode: typeof Decode$1;
31
33
  declare let applyCoercions: typeof applyCoercions$1;
32
34
  declare let TypeBoxValidator: TypeBoxValidator$1;
@@ -46,4 +48,4 @@ declare let Ref: typeof Ref$1;
46
48
  declare let Clone: typeof Clone$1;
47
49
  declare function useTypebox(mod: TypeboxModule): void;
48
50
  //#endregion
49
- export { Clone, Compile, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
51
+ export { Clone, Compile, Create, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
@@ -20,6 +20,7 @@ function stubClass(name) {
20
20
  };
21
21
  }
22
22
  let Compile = stub("Compile");
23
+ let Create = stub("Create");
23
24
  let Decode = stub("Decode");
24
25
  let applyCoercions = stub("applyCoercions");
25
26
  let TypeBoxValidator = stubClass("TypeBoxValidator");
@@ -38,6 +39,7 @@ let Clone = stub("Clone");
38
39
  function useTypebox(mod) {
39
40
  live = mod;
40
41
  Compile = mod.Compile;
42
+ Create = mod.Create;
41
43
  Decode = mod.Decode;
42
44
  applyCoercions = mod.applyCoercions;
43
45
  TypeBoxValidator = mod.TypeBoxValidator;
@@ -68,6 +70,12 @@ Object.defineProperty(exports, 'Compile', {
68
70
  return Compile;
69
71
  }
70
72
  });
73
+ Object.defineProperty(exports, 'Create', {
74
+ enumerable: true,
75
+ get: function () {
76
+ return Create;
77
+ }
78
+ });
71
79
  Object.defineProperty(exports, 'Decode', {
72
80
  enumerable: true,
73
81
  get: function () {
@@ -18,6 +18,7 @@ function stubClass(name) {
18
18
  };
19
19
  }
20
20
  let Compile = stub("Compile");
21
+ let Create = stub("Create");
21
22
  let Decode = stub("Decode");
22
23
  let applyCoercions = stub("applyCoercions");
23
24
  let TypeBoxValidator = stubClass("TypeBoxValidator");
@@ -36,6 +37,7 @@ let Clone = stub("Clone");
36
37
  function useTypebox(mod) {
37
38
  live = mod;
38
39
  Compile = mod.Compile;
40
+ Create = mod.Create;
39
41
  Decode = mod.Decode;
40
42
  applyCoercions = mod.applyCoercions;
41
43
  TypeBoxValidator = mod.TypeBoxValidator;
@@ -54,4 +56,4 @@ function useTypebox(mod) {
54
56
  }
55
57
 
56
58
  //#endregion
57
- export { Clone, Compile, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
59
+ export { Clone, Compile, Create, Decode, Default, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, useTypebox };
@@ -19,6 +19,7 @@ function setupTypebox() {
19
19
  typebox_system.Settings.Set({ unionPrioritySort: false });
20
20
  require_type_bridge.useTypebox({
21
21
  Compile: typebox_compile.Compile,
22
+ Create: typebox_value.Create,
22
23
  Decode: typebox_value.Decode,
23
24
  applyCoercions: require_type_coerce.applyCoercions,
24
25
  TypeBoxValidator: require_type_validator_index.TypeBoxValidator,
@@ -6,7 +6,7 @@ import { TypeBoxValidator } from "./validator/index.mjs";
6
6
  import { Intersect as Intersect$1 } from "./elysia/intersect.mjs";
7
7
  import { Ref } from "typebox/type";
8
8
  import { Compile } from "typebox/compile";
9
- import { Clone, Decode as Decode$1, Default, HasCodec } from "typebox/value";
9
+ import { Clone, Create, Decode as Decode$1, Default, HasCodec } from "typebox/value";
10
10
  import { Settings } from "typebox/system";
11
11
 
12
12
  //#region src/type/compat.ts
@@ -17,6 +17,7 @@ function setupTypebox() {
17
17
  Settings.Set({ unionPrioritySort: false });
18
18
  useTypebox({
19
19
  Compile,
20
+ Create,
20
21
  Decode: Decode$1,
21
22
  applyCoercions,
22
23
  TypeBoxValidator,
@@ -1,9 +1,9 @@
1
1
  import { ELYSIA_TYPES } from "./constants.js";
2
2
  import { CookieOptions } from "../cookie/types.js";
3
3
  import { MaybeArray } from "../types.js";
4
+ import { Validator } from "typebox/schema";
4
5
  import { TObjectOptions, TSchemaOptions } from "typebox";
5
6
  import { TLocalizedValidationError } from "typebox/error";
6
- import { Validator } from "typebox/schema";
7
7
 
8
8
  //#region src/type/types.d.ts
9
9
  type FileUnit = number | `${number}${'k' | 'm'}`;
@@ -2,8 +2,8 @@ import { Validator as Validator$1, ValidatorOptions } from "../../validator/inde
2
2
  import { TypeBoxValidatorCache } from "./validator-cache.js";
3
3
  import { MaybePromise } from "../../types.js";
4
4
  import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
5
- import { TLocalizedValidationError } from "typebox/error";
6
5
  import { Validator } from "typebox/schema";
6
+ import { TLocalizedValidationError } from "typebox/error";
7
7
 
8
8
  //#region src/type/validator/index.d.ts
9
9
  declare function shallowMergeObjects(members: any[]): TSchema | null;
package/dist/types.d.ts CHANGED
@@ -10,8 +10,8 @@ import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.j
10
10
  import { WebSocketHandler } from "./ws/types.js";
11
11
  import { AnyElysia, Elysia } from "./base.js";
12
12
  import { ElysiaAdapter } from "./adapter/index.js";
13
- import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
14
13
  import { Instruction } from "exact-mirror";
14
+ import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
15
15
  import { OpenAPIV3 } from "openapi-types";
16
16
 
17
17
  //#region src/types.d.ts
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.32",
4
+ "version": "2.0.0-exp.33",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",