equipped 5.0.0-beta.9 → 5.0.0-rc.2

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/lib/bull/index.js +33 -44
  3. package/lib/cache/cache.d.ts +1 -0
  4. package/lib/cache/types/redis-cache.d.ts +1 -0
  5. package/lib/cache/types/redis-cache.js +8 -0
  6. package/lib/db/_instance.d.ts +2 -2
  7. package/lib/db/_instance.js +9 -25
  8. package/lib/db/mongoose/changes.d.ts +1 -26
  9. package/lib/db/mongoose/changes.js +7 -20
  10. package/lib/db/mongoose/index.d.ts +2 -27
  11. package/lib/db/mongoose/index.js +8 -24
  12. package/lib/db/mongoose/query.d.ts +0 -25
  13. package/lib/errors/customError.js +2 -0
  14. package/lib/errors/types/accessTokenExpired.js +1 -1
  15. package/lib/errors/types/badRequestError.js +1 -1
  16. package/lib/errors/types/notAuthenticatedError.js +1 -1
  17. package/lib/errors/types/notAuthorizedError.js +1 -1
  18. package/lib/errors/types/notFoundError.js +1 -1
  19. package/lib/errors/types/refreshTokenMisusedError.js +1 -1
  20. package/lib/errors/types/validationError.js +1 -1
  21. package/lib/events/index.js +1 -3
  22. package/lib/events/kafka.d.ts +1 -1
  23. package/lib/events/kafka.js +19 -25
  24. package/lib/events/rabbit.d.ts +1 -1
  25. package/lib/events/rabbit.js +9 -22
  26. package/lib/instance/index.d.ts +2 -1
  27. package/lib/instance/index.js +28 -41
  28. package/lib/instance/settings.d.ts +2 -2
  29. package/lib/instance/settings.js +4 -4
  30. package/lib/listeners/emitter.d.ts +6 -3
  31. package/lib/listeners/emitter.js +97 -109
  32. package/lib/scripts/json-schema.d.ts +2 -1
  33. package/lib/scripts/json-schema.js +29 -22
  34. package/lib/server/impls/base.d.ts +18 -7
  35. package/lib/server/impls/base.js +177 -80
  36. package/lib/server/impls/express.d.ts +0 -1
  37. package/lib/server/impls/express.js +16 -34
  38. package/lib/server/impls/fastify.d.ts +2 -4
  39. package/lib/server/impls/fastify.js +21 -39
  40. package/lib/server/middlewares/errorHandler.d.ts +2 -2
  41. package/lib/server/middlewares/notFoundHandler.d.ts +2 -2
  42. package/lib/server/middlewares/parseAuthUser.d.ts +2 -2
  43. package/lib/server/middlewares/requireAuthUser.d.ts +2 -2
  44. package/lib/server/middlewares/requireAuthUser.js +2 -2
  45. package/lib/server/middlewares/requireRefreshUser.d.ts +2 -2
  46. package/lib/server/middlewares/requireRefreshUser.js +2 -2
  47. package/lib/server/requests.d.ts +10 -7
  48. package/lib/server/requests.js +27 -21
  49. package/lib/server/routes.d.ts +4 -2
  50. package/lib/server/routes.js +33 -33
  51. package/lib/server/types.d.ts +19 -9
  52. package/lib/server/types.js +3 -0
  53. package/lib/storage/index.d.ts +0 -1
  54. package/lib/structure/baseEntity.js +7 -9
  55. package/lib/types/index.d.ts +2 -2
  56. package/lib/utils/auth.d.ts +5 -5
  57. package/lib/utils/authUser.d.ts +3 -2
  58. package/lib/utils/media.d.ts +0 -1
  59. package/lib/utils/utils.d.ts +1 -0
  60. package/lib/utils/utils.js +9 -0
  61. package/lib/validations/index.d.ts +79 -85
  62. package/lib/validations/index.js +4 -4
  63. package/package.json +24 -25
@@ -11,8 +11,8 @@ exports.requireAuthUser = (0, types_1.makeMiddleware)(async (request) => {
11
11
  if (!request.authUser)
12
12
  throw new errors_1.NotAuthenticatedError();
13
13
  }, (route) => {
14
- route.security ?? (route.security = []);
14
+ route.security ??= [];
15
15
  route.security.push({ AccessToken: [] });
16
- route.descriptions ?? (route.descriptions = []);
16
+ route.descriptions ??= [];
17
17
  route.descriptions.push('Requires a valid Access-Token header.');
18
18
  });
@@ -1,4 +1,4 @@
1
1
  export declare const requireRefreshUser: {
2
- cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, import("../types").SupportedStatusCodes>>;
3
- onSetup?: import("../types").HandlerSetup | undefined;
2
+ cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
3
+ onSetup?: import("../types").HandlerSetup;
4
4
  };
@@ -12,8 +12,8 @@ exports.requireRefreshUser = (0, types_1.makeMiddleware)(async (request) => {
12
12
  if (!request.refreshUser)
13
13
  throw new errors_1.NotAuthorizedError();
14
14
  }, (route) => {
15
- route.security ?? (route.security = []);
15
+ route.security ??= [];
16
16
  route.security.push({ RefreshToken: [] });
17
- route.descriptions ?? (route.descriptions = []);
17
+ route.descriptions ??= [];
18
18
  route.descriptions.push('Requires a valid Refresh-Token header.');
19
19
  });
@@ -1,27 +1,30 @@
1
- /// <reference types="node" />
2
1
  import { Writable } from 'stream';
3
2
  import { CustomError } from '../errors';
4
3
  import { StorageFile } from '../storage';
5
4
  import { Defined } from '../types';
6
5
  import { AuthUser, RefreshUser } from '../utils/authUser';
7
- import { Api, SupportedStatusCodes } from './types';
6
+ import { Api, FileSchema, SupportedStatusCodes } from './types';
8
7
  type HeaderKeys = 'AccessToken' | 'RefreshToken' | 'Referer' | 'ContentType' | 'UserAgent';
9
- type ApiToFiles<Def extends Api> = {
10
- [K in keyof Defined<Def['files']>]: StorageFile[];
8
+ type IsFileOrFileArray<T> = T extends FileSchema ? StorageFile[] : T extends FileSchema[] ? StorageFile[] : T;
9
+ type ApiToBody<Def extends Api> = MappedUnion<Def['body']>;
10
+ type UnionMapper<T> = {
11
+ [K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? {
12
+ [Q in keyof T]: IsFileOrFileArray<T[Q]>;
13
+ } : never : never;
11
14
  };
15
+ type MappedUnion<T> = UnionMapper<T>[keyof UnionMapper<T>];
12
16
  export declare class Request<Def extends Api = Api> {
13
17
  #private;
14
18
  private readonly response;
15
19
  readonly ip: string | undefined;
16
20
  readonly method: Def['method'];
17
21
  readonly path: string;
18
- readonly body: Def['body'];
22
+ readonly body: ApiToBody<Def>;
19
23
  readonly params: Defined<Def['params']>;
20
24
  readonly query: Defined<Def['query']>;
21
25
  readonly cookies: Record<string, any>;
22
26
  readonly rawBody: unknown;
23
27
  readonly headers: Record<HeaderKeys, string | null> & Record<string, string | string[] | null>;
24
- readonly files: ApiToFiles<Def>;
25
28
  authUser: null | AuthUser;
26
29
  refreshUser: null | RefreshUser;
27
30
  pendingError: null | CustomError;
@@ -32,7 +35,7 @@ export declare class Request<Def extends Api = Api> {
32
35
  query: Def['query'];
33
36
  cookies: Record<string, any>;
34
37
  headers: Record<HeaderKeys, string | null> & Record<string, string | string[] | null>;
35
- files: ApiToFiles<Def>;
38
+ files: Record<string, StorageFile[]>;
36
39
  method: Def['method'];
37
40
  path: string;
38
41
  }, response: Writable);
@@ -1,37 +1,46 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _Request_instances, _Request_parseQueryStrings;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.Response = exports.Request = void 0;
10
4
  const json_1 = require("../utils/json");
11
5
  const types_1 = require("./types");
12
6
  class Request {
7
+ response;
8
+ ip;
9
+ method;
10
+ path;
11
+ body;
12
+ params;
13
+ query;
14
+ cookies;
15
+ rawBody;
16
+ headers;
17
+ authUser = null;
18
+ refreshUser = null;
19
+ pendingError = null;
13
20
  constructor({ ip, body, cookies, params, query, method, path, headers, files }, response) {
14
- _Request_instances.add(this);
15
21
  this.response = response;
16
- this.authUser = null;
17
- this.refreshUser = null;
18
- this.pendingError = null;
19
22
  this.ip = ip;
20
23
  this.method = method;
21
24
  this.path = path;
22
25
  this.rawBody = body;
23
- this.body = Object.fromEntries(Object.entries(body && typeof body === 'object' ? body : { raw: body })
24
- .map(([key, value]) => [key, (0, json_1.parseJSONValue)(value)]));
26
+ this.body = Object.assign(Object.fromEntries(Object.entries(body && typeof body === 'object' ? body : { raw: body })
27
+ .map(([key, value]) => [key, (0, json_1.parseJSONValue)(value)])), files);
25
28
  this.cookies = cookies;
26
29
  this.params = params;
27
30
  this.query = Object.fromEntries(Object.entries(query && typeof body === 'object' ? query : {})
28
- .map(([key, val]) => [key, __classPrivateFieldGet(this, _Request_instances, "m", _Request_parseQueryStrings).call(this, val)]));
31
+ .map(([key, val]) => [key, this.#parseQueryStrings(val)]));
29
32
  if (this.query?.['auth'])
30
33
  delete this.query['auth'];
31
34
  if (this.query?.['authType'])
32
35
  delete this.query['authType'];
33
36
  this.headers = headers;
34
- this.files = files;
37
+ }
38
+ #parseQueryStrings(value) {
39
+ if (Array.isArray(value))
40
+ return value.map(this.#parseQueryStrings);
41
+ if (typeof value === 'string')
42
+ return (0, json_1.parseJSONValue)(value);
43
+ return value;
35
44
  }
36
45
  pipe(cb) {
37
46
  cb(this.response);
@@ -39,14 +48,11 @@ class Request {
39
48
  }
40
49
  }
41
50
  exports.Request = Request;
42
- _Request_instances = new WeakSet(), _Request_parseQueryStrings = function _Request_parseQueryStrings(value) {
43
- if (Array.isArray(value))
44
- return value.map(__classPrivateFieldGet(this, _Request_instances, "m", _Request_parseQueryStrings));
45
- if (typeof value === 'string')
46
- return (0, json_1.parseJSONValue)(value);
47
- return value;
48
- };
49
51
  class Response {
52
+ body;
53
+ status;
54
+ headers;
55
+ piped;
50
56
  constructor({ body, status = types_1.StatusCodes.Ok, headers = { 'Content-Type': 'application/json' }, piped = false }) {
51
57
  this.body = body;
52
58
  this.status = status;
@@ -1,9 +1,11 @@
1
1
  import { ClassPropertiesWrapper } from 'valleyed';
2
2
  import { AddMethodImpls, GeneralConfig, Route } from './types';
3
+ export declare const cleanPath: (path: string) => string;
3
4
  export declare const groupRoutes: (config: GeneralConfig, routes: Route[]) => Route[];
4
5
  export declare class Router extends ClassPropertiesWrapper<AddMethodImpls> {
5
6
  #private;
6
7
  constructor(config?: GeneralConfig);
7
- include(router: Router): void;
8
- get routes(): Route<import("./types").ApiDef<import("./types").Api<any, string, import("./types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, import("./types").SupportedStatusCodes>>>[];
8
+ add(...routes: Route[]): void;
9
+ nest(...routers: Router[]): void;
10
+ get routes(): Route<import("./types").ApiDef<import("./types").Api<any, string, import("./types").MethodTypes, any, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("./types").SupportedStatusCodes>>>[];
9
11
  }
@@ -1,59 +1,59 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var _Router_instances, _Router_config, _Router_routes, _Router_children, _Router_addRoute;
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Router = exports.groupRoutes = void 0;
3
+ exports.Router = exports.groupRoutes = exports.cleanPath = void 0;
16
4
  const valleyed_1 = require("valleyed");
17
5
  const types_1 = require("./types");
6
+ const cleanPath = (path) => {
7
+ let cleaned = path.replace(/(\/\s*)+/g, '/');
8
+ if (!cleaned.startsWith('/'))
9
+ cleaned = `/${cleaned}`;
10
+ if (cleaned !== '/' && cleaned.endsWith('/'))
11
+ cleaned = cleaned.slice(0, -1);
12
+ return cleaned;
13
+ };
14
+ exports.cleanPath = cleanPath;
18
15
  const groupRoutes = (config, routes) => routes
19
16
  .map((route) => ({
20
17
  ...config,
21
18
  ...route,
22
- path: `${config.path}/${route.path}`,
23
- tags: [...(config.tags ?? []), ...(route.tags ?? [])],
19
+ path: (0, exports.cleanPath)(`${config.path}/${route.path}`),
20
+ groups: [...(config.groups ?? []), ...(route.groups ?? [])],
24
21
  middlewares: [...(config.middlewares ?? []), ...(route.middlewares ?? [])],
25
22
  security: [...(config.security ?? []), ...(route.security ?? [])],
26
23
  }));
27
24
  exports.groupRoutes = groupRoutes;
28
25
  class Router extends valleyed_1.ClassPropertiesWrapper {
26
+ #config = { path: '' };
27
+ #routes = [];
28
+ #children = [];
29
29
  constructor(config) {
30
- const methodImpls = Object.fromEntries(Object.values(types_1.Methods).map((method) => [method, (route) => __classPrivateFieldGet(this, _Router_instances, "m", _Router_addRoute).call(this, method, route)]));
30
+ const methodImpls = Object.fromEntries(Object.values(types_1.Methods).map((method) => [method, (route) => this.#addRoute(method, route)]));
31
31
  super(methodImpls);
32
- _Router_instances.add(this);
33
- _Router_config.set(this, { path: '' });
34
- _Router_routes.set(this, []);
35
- _Router_children.set(this, []);
36
32
  if (config)
37
- __classPrivateFieldSet(this, _Router_config, config, "f");
33
+ this.#config = config;
38
34
  }
39
- include(router) {
40
- __classPrivateFieldGet(this, _Router_children, "f").push(router);
35
+ #addRoute(method, routeConfig, collection = this.#routes) {
36
+ return (handler) => {
37
+ const route = (0, exports.groupRoutes)(this.#config, [{ ...routeConfig, method, handler }])[0];
38
+ collection.push(route);
39
+ return route;
40
+ };
41
+ }
42
+ add(...routes) {
43
+ const mapped = (0, exports.groupRoutes)(this.#config, routes);
44
+ this.#routes.push(...mapped);
45
+ }
46
+ nest(...routers) {
47
+ routers.forEach((router) => this.#children.push(router));
41
48
  }
42
49
  get routes() {
43
- const routes = __classPrivateFieldGet(this, _Router_routes, "f");
44
- __classPrivateFieldGet(this, _Router_children, "f").forEach((child) => {
50
+ const routes = [...this.#routes];
51
+ this.#children.forEach((child) => {
45
52
  child.routes.forEach((route) => {
46
- __classPrivateFieldGet(this, _Router_instances, "m", _Router_addRoute).call(this, route.method, route, routes)(route.handler);
53
+ this.#addRoute(route.method, route, routes)(route.handler);
47
54
  });
48
55
  });
49
56
  return routes;
50
57
  }
51
58
  }
52
59
  exports.Router = Router;
53
- _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_children = new WeakMap(), _Router_instances = new WeakSet(), _Router_addRoute = function _Router_addRoute(method, routeConfig, collection = __classPrivateFieldGet(this, _Router_routes, "f")) {
54
- return (handler) => {
55
- const route = (0, exports.groupRoutes)(__classPrivateFieldGet(this, _Router_config, "f"), [{ ...routeConfig, method, handler }])[0];
56
- collection.push(route);
57
- return route;
58
- };
59
- };
@@ -13,6 +13,7 @@ export declare const Methods: {
13
13
  export type MethodTypes = Enum<typeof Methods>;
14
14
  export declare const StatusCodes: {
15
15
  readonly Ok: 200;
16
+ readonly Found: 302;
16
17
  readonly BadRequest: 400;
17
18
  readonly NotAuthenticated: 401;
18
19
  readonly NotAuthorized: 403;
@@ -22,29 +23,33 @@ export declare const StatusCodes: {
22
23
  readonly AccessTokenExpired: 461;
23
24
  };
24
25
  export type SupportedStatusCodes = Enum<typeof StatusCodes>;
25
- type GoodStatusCodes = 200;
26
+ type GoodStatusCodes = 200 | 302;
26
27
  type ApiErrors = Record<Exclude<SupportedStatusCodes, GoodStatusCodes>, JSONValue<CustomError['serializedErrors']>>;
27
28
  type ApiResponse<T, StatusCode extends SupportedStatusCodes> = Record<StatusCode, JSONValue<T>> | Omit<ApiErrors, StatusCode>;
28
- export interface Api<Res = any, Key extends string = string, Method extends MethodTypes = MethodTypes, Body = any, Files extends Record<string, boolean> = Record<string, boolean>, Params extends Record<string, string> = Record<string, string>, Query extends Record<string, any> = Record<string, any>, DefaultStatus extends SupportedStatusCodes = SupportedStatusCodes> {
29
+ export interface Api<Res = any, Key extends string = string, Method extends MethodTypes = MethodTypes, Body = any, Params extends Record<string, string> = Record<string, string>, Query extends Record<string, any> = Record<string, any>, RequestHeaders extends Record<string, string | string[]> = Record<string, string | string[]>, ResponeHeaders extends Record<string, string | string[]> = Record<string, string | string[]>, DefaultStatus extends SupportedStatusCodes = SupportedStatusCodes> {
29
30
  key: Key;
30
31
  method: Method;
31
32
  response: Res;
32
33
  body?: Body;
33
- files?: Files;
34
34
  params?: Params;
35
35
  query?: Query;
36
+ requestHeaders?: RequestHeaders;
37
+ responseHeaders?: ResponeHeaders;
36
38
  defaultStatusCode?: DefaultStatus;
37
39
  }
38
- export interface ApiDef<T extends AnyApi> {
40
+ export type FileSchema = 'equipped-file-schema';
41
+ export interface ApiDef<T extends Api> {
39
42
  key: Defined<T['key']>;
40
43
  method: Defined<T['method']>;
41
44
  body: Defined<T['body']>;
42
45
  params: Defined<T['params']>;
43
46
  query: Defined<T['query']>;
44
- files: Defined<T['files']>;
47
+ requestHeaders: Defined<T['requestHeaders']>;
48
+ responseHeaders: Defined<T['responseHeaders']>;
45
49
  responses: ApiResponse<T['response'], GetDefaultStatusCode<T['defaultStatusCode']>>;
50
+ __apiDef: true;
46
51
  }
47
- type AnyApi<Method extends MethodTypes = MethodTypes> = Api<any, any, Method, any, any, any, any, any>;
52
+ type AnyApi<Method extends MethodTypes = MethodTypes> = Api<any, any, Method, any, any, any, any, any, any>;
48
53
  type Awaitable<T> = Promise<T> | T;
49
54
  type Res<T, S extends SupportedStatusCodes> = Awaitable<Response<T, S> | T>;
50
55
  type InferApiFromApiDef<T> = T extends ApiDef<infer A> ? A : never;
@@ -55,6 +60,11 @@ export type RouteMiddlewareHandler<Def extends Api = Api> = (req: Request<Def>)
55
60
  export type HandlerSetup = (route: Route) => void;
56
61
  export type RouteSchema = Omit<FastifySchema, 'tags' | 'security' | 'hide' | 'description'> & {
57
62
  descriptions?: string[];
63
+ title?: string;
64
+ };
65
+ type RouteGroup = {
66
+ name: string;
67
+ description?: string;
58
68
  };
59
69
  export interface Route<Def extends ApiDef<AnyApi> = ApiDef<Api>> {
60
70
  key?: Def['key'];
@@ -65,7 +75,7 @@ export interface Route<Def extends ApiDef<AnyApi> = ApiDef<Api>> {
65
75
  middlewares?: ReturnType<typeof makeMiddleware>[];
66
76
  onError?: ReturnType<typeof makeErrorMiddleware>;
67
77
  schema?: RouteSchema;
68
- tags?: string[];
78
+ groups?: (RouteGroup | RouteGroup['name'])[];
69
79
  descriptions?: string[];
70
80
  hideSchema?: boolean;
71
81
  security?: Record<string, string[]>[];
@@ -81,6 +91,6 @@ declare class MiddlewareHandler<Cb extends Function> {
81
91
  private constructor();
82
92
  static make<Cb extends Function>(cb: Cb, onSetup?: HandlerSetup): MiddlewareHandler<Cb>;
83
93
  }
84
- export declare const makeMiddleware: <Def extends AnyApi<MethodTypes> = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, SupportedStatusCodes>>(cb: RouteMiddlewareHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<RouteMiddlewareHandler<Def>>;
85
- export declare const makeErrorMiddleware: <Def extends AnyApi<MethodTypes> = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, SupportedStatusCodes>>(cb: ErrorHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<ErrorHandler<Def>>;
94
+ export declare const makeMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: RouteMiddlewareHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<RouteMiddlewareHandler<Def>>;
95
+ export declare const makeErrorMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: ErrorHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<ErrorHandler<Def>>;
86
96
  export {};
@@ -10,6 +10,7 @@ exports.Methods = {
10
10
  };
11
11
  exports.StatusCodes = {
12
12
  Ok: 200,
13
+ Found: 302,
13
14
  BadRequest: 400,
14
15
  NotAuthenticated: 401,
15
16
  NotAuthorized: 403,
@@ -19,6 +20,8 @@ exports.StatusCodes = {
19
20
  AccessTokenExpired: 461,
20
21
  };
21
22
  class MiddlewareHandler {
23
+ cb;
24
+ onSetup;
22
25
  constructor(cb, onSetup) {
23
26
  this.cb = cb;
24
27
  this.onSetup = onSetup;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export interface StorageFile {
3
2
  name: string;
4
3
  type: string;
@@ -14,22 +14,20 @@ const deleteKeyFromObject = (obj, keys) => {
14
14
  return deleteKeyFromObject(obj[keys[0]], keys.slice(1));
15
15
  };
16
16
  class BaseEntity extends valleyed_1.ClassPropertiesWrapper {
17
- constructor() {
18
- super(...arguments);
19
- this.__hash = utils_1.Random.string();
20
- this.__type = this.constructor.name;
21
- this.__ignoreInJSON = [];
22
- }
17
+ __hash = utils_1.Random.string();
18
+ __type = this.constructor.name;
19
+ __ignoreInJSON = [];
23
20
  toJSON(includeIgnored = false) {
24
21
  const json = {};
25
22
  Object.keys(this)
26
23
  .concat(Object.getOwnPropertyNames(Object.getPrototypeOf(this)))
27
- .filter((k) => k !== 'constructor')
28
24
  .forEach((key) => {
29
25
  const value = this[key];
30
- json[key] = value?.toJSON?.(includeIgnored) ?? structuredClone(value);
26
+ if (typeof value === 'function')
27
+ return;
28
+ json[key] = value?.toJSON?.(includeIgnored) ?? (0, utils_1.clone)(value);
31
29
  });
32
- if (!includeIgnored)
30
+ if (includeIgnored !== true)
33
31
  this.__ignoreInJSON.concat('__ignoreInJSON').forEach((k) => deleteKeyFromObject(json, k.split('.')));
34
32
  return json;
35
33
  }
@@ -15,6 +15,6 @@ export type Paths<T, D = never> = T extends StopTypes ? '' : T extends readonly
15
15
  }[keyof T & string];
16
16
  export type JSONPrimitives = string | number | boolean | null;
17
17
  export type JSONValue<T> = T extends JSONPrimitives ? T : T extends Array<infer U> ? JSONValue<U>[] : T extends BaseEntity<infer _M, infer I> ? JSONValue<DeepOmit<T, I, '__ignoreInJSON'>> : T extends Function ? never : T extends object ? {
18
- [K in keyof T & (number | string) as JSONValue<T[K]> extends never ? never : JSONValue<T[K]> extends undefined ? never : K]: JSONValue<T[K]>;
19
- } : T extends unknown ? unknown : undefined extends T ? JSONValue<Exclude<T, undefined>> | undefined : never;
18
+ [K in keyof T as JSONValue<T[K]> extends never ? never : JSONValue<T[K]> extends undefined ? never : K]: JSONValue<T[K]>;
19
+ } : never;
20
20
  export {};
@@ -1,21 +1,21 @@
1
1
  export declare const signinWithGoogle: (idToken: string) => Promise<{
2
2
  email: string;
3
- email_verified: 'true' | 'false';
3
+ email_verified: "true" | "false";
4
4
  first_name: string;
5
5
  last_name: string;
6
6
  picture: string;
7
7
  sub: string;
8
8
  } & Record<string, any>>;
9
9
  export declare const signinWithApple: (idToken: string) => Promise<{
10
- email?: string | undefined;
10
+ email?: string;
11
11
  sub: string;
12
- email_verified?: "false" | "true" | undefined;
13
- is_private_email?: "false" | "true" | undefined;
12
+ email_verified?: "true" | "false";
13
+ is_private_email?: "true" | "false";
14
14
  } & Record<string, any>>;
15
15
  export declare const signinWithFacebook: (accessToken: string, fields?: string[]) => Promise<{
16
16
  id: string;
17
17
  email: string;
18
- email_verified: 'true' | 'false';
18
+ email_verified: "true" | "false";
19
19
  name: string;
20
20
  picture: {
21
21
  data: {
@@ -6,5 +6,6 @@ export interface AuthUser {
6
6
  id: string;
7
7
  roles: AuthRoles;
8
8
  }
9
- export interface AuthRoles extends Partial<Record<Enum<IAuthRole>, boolean>> {
10
- }
9
+ export type AuthRoles = {
10
+ [Role in Enum<IAuthRole>]?: boolean;
11
+ };
@@ -1,2 +1 @@
1
- /// <reference types="node" />
2
1
  export declare const getMediaDuration: (buffer: Buffer) => Promise<number>;
@@ -2,3 +2,4 @@ export declare class Random {
2
2
  static string(length?: number): string;
3
3
  static number(min?: number, max?: number): number;
4
4
  }
5
+ export declare function clone<T>(value: T): T;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Random = void 0;
7
+ exports.clone = clone;
7
8
  const crypto_1 = __importDefault(require("crypto"));
8
9
  class Random {
9
10
  static string(length = 20) {
@@ -14,3 +15,11 @@ class Random {
14
15
  }
15
16
  }
16
17
  exports.Random = Random;
18
+ function clone(value) {
19
+ try {
20
+ return structuredClone(value);
21
+ }
22
+ catch (err) {
23
+ return value;
24
+ }
25
+ }