tsledge 0.1.6 → 0.1.8

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,19 +1,20 @@
1
- import { FluentAPIPath, FluentExpressRequest } from './types';
1
+ import { FluentApiOption, FluentExpressRequest, FluentMiddleware } from './types';
2
2
  import { PromiseDefaultCodec, QueryBuilder } from '../core/index';
3
3
  export declare class FluentPatternHandler {
4
4
  private static _singleton;
5
- private _paths;
5
+ private _options;
6
+ private _execMiddlewareFunctions;
6
7
  /**
7
8
  * Constructor for QueryPatternExecutor.
8
- * @param paths - Array of query pattern paths for filtering.
9
+ * @param options - Array of query pattern options for filtering.
9
10
  */
10
- constructor(paths?: FluentAPIPath[]);
11
+ constructor(options?: FluentApiOption[], execMiddleware?: FluentMiddleware[]);
11
12
  /**
12
- * Initializes the singleton instance of FluentPatternHandler with the provided paths.
13
- * @param paths - Array of query pattern paths for filtering.
13
+ * Initializes the singleton instance of FluentPatternHandler with the provided options.
14
+ * @param options - Array of query pattern options for filtering.
14
15
  * @returns Singleton instance of FluentPatternHandler.
15
16
  */
16
- static init(paths?: FluentAPIPath[]): FluentPatternHandler;
17
+ static init(options?: FluentApiOption[], execMiddleware?: FluentMiddleware[]): FluentPatternHandler;
17
18
  /**
18
19
  * Returns the singleton instance of FluentPatternHandler.
19
20
  * @returns Singleton instance of FluentPatternHandler.
@@ -33,7 +34,7 @@ export declare class FluentPatternHandler {
33
34
  */
34
35
  private _applyParameters;
35
36
  /**
36
- * Retrieves filter fields for the given model from the paths configuration.
37
+ * Retrieves filter fields for the given model from the options configuration.
37
38
  * @param model - The Mongoose model.
38
39
  * @returns Array of filter fields.
39
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"fluent-pattern-handler.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/fluent-pattern-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,aAAa,EACb,oBAAoB,EAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAA8B,mBAAmB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAY9F,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB;IAChD,OAAO,CAAC,MAAM,CAAkB;IAEhC;;;OAGG;gBACS,KAAK,GAAE,aAAa,EAAO;IAUvC;;;;OAIG;WACW,IAAI,CAAC,KAAK,GAAE,aAAa,EAAO,GAAG,oBAAoB;IAQrE;;;OAGG;WACW,WAAW,IAAI,oBAAoB;IASjD;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAsChC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAoCxB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAYhC;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;;;;OAKG;IACU,IAAI,CAAC,CAAC,GAAG,GAAG,EACvB,GAAG,EAAE,oBAAoB,EACzB,YAAY,EAAE,YAAY,GACzB,mBAAmB;CAWvB"}
1
+ {"version":3,"file":"fluent-pattern-handler.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/fluent-pattern-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EACf,oBAAoB,EAEpB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAA8B,mBAAmB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAY9F,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB;IAChD,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,wBAAwB,CAA0B;IAE1D;;;OAGG;gBACS,OAAO,GAAE,eAAe,EAAO,EAAE,cAAc,GAAE,gBAAgB,EAAO;IAWpF;;;;OAIG;WACW,IAAI,CAChB,OAAO,GAAE,eAAe,EAAO,EAC/B,cAAc,GAAE,gBAAgB,EAAO,GACtC,oBAAoB;IAQvB;;;OAGG;WACW,WAAW,IAAI,oBAAoB;IASjD;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAsChC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAoCxB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAYhC;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;;;;OAKG;IACU,IAAI,CAAC,CAAC,GAAG,GAAG,EACvB,GAAG,EAAE,oBAAoB,EACzB,YAAY,EAAE,YAAY,GACzB,mBAAmB;CAgBvB"}
@@ -1,6 +1,7 @@
1
1
  import mongoose from 'mongoose';
2
2
  import { Request, Response } from 'express';
3
- import { DefaultResponseBody, KeysEnum } from '../core/index';
3
+ import { DefaultResponseBody, KeysEnum, QueryBuilder } from '../core/index';
4
+ export type FluentMiddleware = (queryBuilder: QueryBuilder) => void;
4
5
  export interface FluentRequestParams extends Record<string, string> {
5
6
  collection: string;
6
7
  }
@@ -19,7 +20,7 @@ export interface FluentRequestQuery {
19
20
  * Attributes of FluentRequestQuery used for validation and parsing.
20
21
  */
21
22
  export declare const fluentRequestQueryAttributes: KeysEnum<FluentRequestQuery>;
22
- export interface FluentAPIPath<T = any> {
23
+ export interface FluentApiOption<T = any> {
23
24
  model: mongoose.Model<T>;
24
25
  filters?: string[];
25
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/types.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACjE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;CAAG;AAErC,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAAC,kBAAkB,CAQrE,CAAC;AAEF,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IAEpC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC,mBAAmB,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/types.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,MAAM,gBAAgB,GAAG,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;AAEpE,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACjE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;CAAG;AAErC,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAAC,kBAAkB,CAQrE,CAAC;AAEF,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG;IAEtC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC,mBAAmB,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -808,27 +808,29 @@ async function httpRequest(config) {
808
808
  var FluentPatternHandler = class _FluentPatternHandler {
809
809
  /**
810
810
  * Constructor for QueryPatternExecutor.
811
- * @param paths - Array of query pattern paths for filtering.
811
+ * @param options - Array of query pattern options for filtering.
812
812
  */
813
- constructor(paths = []) {
813
+ constructor(options = [], execMiddleware = []) {
814
+ this._execMiddlewareFunctions = [];
814
815
  if (_FluentPatternHandler._singleton) {
815
816
  throw new Error(
816
817
  "FluentPatternHandler is a singleton class. Use FluentPatternHandler.getInstance() to access the instance."
817
818
  );
818
819
  }
819
- this._paths = paths;
820
+ this._options = options;
821
+ this._execMiddlewareFunctions = execMiddleware;
820
822
  _FluentPatternHandler._singleton = this;
821
823
  }
822
824
  /**
823
- * Initializes the singleton instance of FluentPatternHandler with the provided paths.
824
- * @param paths - Array of query pattern paths for filtering.
825
+ * Initializes the singleton instance of FluentPatternHandler with the provided options.
826
+ * @param options - Array of query pattern options for filtering.
825
827
  * @returns Singleton instance of FluentPatternHandler.
826
828
  */
827
- static init(paths = []) {
829
+ static init(options = [], execMiddleware = []) {
828
830
  if (_FluentPatternHandler._singleton != void 0) {
829
831
  throw new Error("FluentPatternHandler is already initialized");
830
832
  }
831
- _FluentPatternHandler._singleton = new _FluentPatternHandler(paths);
833
+ _FluentPatternHandler._singleton = new _FluentPatternHandler(options, execMiddleware);
832
834
  return _FluentPatternHandler._singleton;
833
835
  }
834
836
  /**
@@ -919,15 +921,15 @@ var FluentPatternHandler = class _FluentPatternHandler {
919
921
  }
920
922
  }
921
923
  /**
922
- * Retrieves filter fields for the given model from the paths configuration.
924
+ * Retrieves filter fields for the given model from the options configuration.
923
925
  * @param model - The Mongoose model.
924
926
  * @returns Array of filter fields.
925
927
  */
926
928
  _getFilterFieldsForModel(model) {
927
- for (const path2 of this._paths) {
928
- if (path2.model.collection.name === model.collection.name) {
929
- if (path2.filters) {
930
- return path2.filters;
929
+ for (const option of this._options) {
930
+ if (option.model.collection.name === model.collection.name) {
931
+ if (option.filters) {
932
+ return option.filters;
931
933
  }
932
934
  return [];
933
935
  }
@@ -955,6 +957,11 @@ var FluentPatternHandler = class _FluentPatternHandler {
955
957
  */
956
958
  async exec(req, queryBuilder) {
957
959
  try {
960
+ if (this._execMiddlewareFunctions && this._execMiddlewareFunctions.length > 0) {
961
+ this._execMiddlewareFunctions.forEach((func) => {
962
+ func(queryBuilder);
963
+ });
964
+ }
958
965
  const queryParams = this._parseFluentRequestQuery(req.query);
959
966
  this._applyParameters(queryBuilder, queryParams);
960
967
  const execConfig = this._buildExecutionConfig(queryParams);
package/dist/src/index.js CHANGED
@@ -270,8 +270,8 @@ async function validateJwt(req, res, next, jwtSecret) {
270
270
  console.log("[WARN] JWT token for blocked user");
271
271
  return res.sendStatus(FORBIDDEN);
272
272
  }
273
- req.user = result.payload;
274
- req.token = token;
273
+ res.locals.user = result.payload;
274
+ res.locals.token = token;
275
275
  next();
276
276
  } catch (err) {
277
277
  console.log("[ERROR] JWT validation error:", err);
@@ -335,7 +335,7 @@ async function generateCredentials(auth) {
335
335
  appUser
336
336
  };
337
337
  }
338
- async function register(req, res, next) {
338
+ async function authRegister(req, res, next) {
339
339
  let { identifier = void 0, secret = void 0 } = req.body || {};
340
340
  if (!identifier || !secret) {
341
341
  return res.sendStatus(FORBIDDEN2);
@@ -345,14 +345,13 @@ async function register(req, res, next) {
345
345
  if (user) {
346
346
  return res.sendStatus(BAD_REQUEST);
347
347
  }
348
- let authUser = new AuthUser({
348
+ res.locals.authUser = new AuthUser({
349
349
  identifier,
350
350
  secretHash: await bcrypt.hash(secret, 10)
351
351
  });
352
- authUser.save();
353
352
  next();
354
353
  }
355
- async function login(req, res, next) {
354
+ async function authLogin(req, res, next) {
356
355
  let { identifier = void 0, secret = void 0 } = req.body || {};
357
356
  if (!identifier || !secret) {
358
357
  return res.sendStatus(FORBIDDEN2);
@@ -376,9 +375,9 @@ async function login(req, res, next) {
376
375
  res.locals.credentials = credentials;
377
376
  next();
378
377
  }
379
- async function logout(req, res, next) {
378
+ async function authLogout(req, res, next) {
380
379
  await jwtRefreshRequired(req, res, async () => {
381
- const refreshToken = req.token;
380
+ const refreshToken = res.locals.token;
382
381
  if (!refreshToken) {
383
382
  return res.sendStatus(BAD_REQUEST);
384
383
  }
@@ -404,8 +403,10 @@ async function logout(req, res, next) {
404
403
  next();
405
404
  });
406
405
  }
407
- async function refreshJWT(req, res, next) {
408
- const refreshToken = req.token;
406
+ async function authRefresh(req, res, next) {
407
+ await jwtRefreshRequired(req, res, async () => {
408
+ });
409
+ const refreshToken = res.locals.token;
409
410
  if (!refreshToken) {
410
411
  return res.sendStatus(BAD_REQUEST);
411
412
  }
@@ -436,6 +437,7 @@ async function refreshJWT(req, res, next) {
436
437
  if (!credentials) {
437
438
  return res.sendStatus(BAD_REQUEST);
438
439
  }
440
+ res.locals.credentials = credentials;
439
441
  next();
440
442
  } catch (err) {
441
443
  console.log("[WARN] refreshing JWT:", err);
@@ -806,17 +808,35 @@ async function httpRequest(config) {
806
808
  var FluentPatternHandler = class _FluentPatternHandler {
807
809
  /**
808
810
  * Constructor for QueryPatternExecutor.
809
- * @param paths - Array of query pattern paths for filtering.
811
+ * @param options - Array of query pattern options for filtering.
810
812
  */
811
- constructor(paths = []) {
813
+ constructor(options = [], execMiddleware = []) {
814
+ this._execMiddlewareFunctions = [];
812
815
  if (_FluentPatternHandler._singleton) {
813
816
  throw new Error(
814
817
  "FluentPatternHandler is a singleton class. Use FluentPatternHandler.getInstance() to access the instance."
815
818
  );
816
819
  }
817
- this._paths = paths;
820
+ this._options = options;
821
+ this._execMiddlewareFunctions = execMiddleware;
818
822
  _FluentPatternHandler._singleton = this;
819
823
  }
824
+ /**
825
+ * Initializes the singleton instance of FluentPatternHandler with the provided options.
826
+ * @param options - Array of query pattern options for filtering.
827
+ * @returns Singleton instance of FluentPatternHandler.
828
+ */
829
+ static init(options = [], execMiddleware = []) {
830
+ if (_FluentPatternHandler._singleton != void 0) {
831
+ throw new Error("FluentPatternHandler is already initialized");
832
+ }
833
+ _FluentPatternHandler._singleton = new _FluentPatternHandler(options, execMiddleware);
834
+ return _FluentPatternHandler._singleton;
835
+ }
836
+ /**
837
+ * Returns the singleton instance of FluentPatternHandler.
838
+ * @returns Singleton instance of FluentPatternHandler.
839
+ */
820
840
  static getInstance() {
821
841
  if (_FluentPatternHandler._singleton == void 0) {
822
842
  throw new Error(
@@ -901,15 +921,15 @@ var FluentPatternHandler = class _FluentPatternHandler {
901
921
  }
902
922
  }
903
923
  /**
904
- * Retrieves filter fields for the given model from the paths configuration.
924
+ * Retrieves filter fields for the given model from the options configuration.
905
925
  * @param model - The Mongoose model.
906
926
  * @returns Array of filter fields.
907
927
  */
908
928
  _getFilterFieldsForModel(model) {
909
- for (const path2 of this._paths) {
910
- if (path2.model.collection.name === model.collection.name) {
911
- if (path2.filters) {
912
- return path2.filters;
929
+ for (const option of this._options) {
930
+ if (option.model.collection.name === model.collection.name) {
931
+ if (option.filters) {
932
+ return option.filters;
913
933
  }
914
934
  return [];
915
935
  }
@@ -937,6 +957,11 @@ var FluentPatternHandler = class _FluentPatternHandler {
937
957
  */
938
958
  async exec(req, queryBuilder) {
939
959
  try {
960
+ if (this._execMiddlewareFunctions && this._execMiddlewareFunctions.length > 0) {
961
+ this._execMiddlewareFunctions.forEach((func) => {
962
+ func(queryBuilder);
963
+ });
964
+ }
940
965
  const queryParams = this._parseFluentRequestQuery(req.query);
941
966
  this._applyParameters(queryBuilder, queryParams);
942
967
  const execConfig = this._buildExecutionConfig(queryParams);
@@ -973,6 +998,10 @@ export {
973
998
  JwtSecret,
974
999
  QueryBuilder,
975
1000
  TokenBlocklist,
1001
+ authLogin,
1002
+ authLogout,
1003
+ authRefresh,
1004
+ authRegister,
976
1005
  connectMongoDB,
977
1006
  createApp,
978
1007
  diskFileUpload,
@@ -987,12 +1016,8 @@ export {
987
1016
  isNonEmptyObjectOrArray,
988
1017
  jwtRefreshRequired,
989
1018
  jwtRequired,
990
- login,
991
- logout,
992
1019
  memoryFileUpload,
993
1020
  mergeCollectionRelations,
994
- refreshJWT,
995
- register,
996
1021
  requestLogger,
997
1022
  socketToken,
998
1023
  validateString,
@@ -195,8 +195,8 @@ async function validateJwt(req, res, next, jwtSecret) {
195
195
  console.log("[WARN] JWT token for blocked user");
196
196
  return res.sendStatus(FORBIDDEN);
197
197
  }
198
- req.user = result.payload;
199
- req.token = token;
198
+ res.locals.user = result.payload;
199
+ res.locals.token = token;
200
200
  next();
201
201
  } catch (err) {
202
202
  console.log("[ERROR] JWT validation error:", err);
@@ -239,7 +239,7 @@ async function generateCredentials(auth) {
239
239
  appUser
240
240
  };
241
241
  }
242
- async function register(req, res, next) {
242
+ async function authRegister(req, res, next) {
243
243
  let { identifier = void 0, secret = void 0 } = req.body || {};
244
244
  if (!identifier || !secret) {
245
245
  return res.sendStatus(FORBIDDEN2);
@@ -249,14 +249,13 @@ async function register(req, res, next) {
249
249
  if (user) {
250
250
  return res.sendStatus(BAD_REQUEST);
251
251
  }
252
- let authUser = new AuthUser({
252
+ res.locals.authUser = new AuthUser({
253
253
  identifier,
254
254
  secretHash: await bcrypt.hash(secret, 10)
255
255
  });
256
- authUser.save();
257
256
  next();
258
257
  }
259
- async function login(req, res, next) {
258
+ async function authLogin(req, res, next) {
260
259
  let { identifier = void 0, secret = void 0 } = req.body || {};
261
260
  if (!identifier || !secret) {
262
261
  return res.sendStatus(FORBIDDEN2);
@@ -280,9 +279,9 @@ async function login(req, res, next) {
280
279
  res.locals.credentials = credentials;
281
280
  next();
282
281
  }
283
- async function logout(req, res, next) {
282
+ async function authLogout(req, res, next) {
284
283
  await jwtRefreshRequired(req, res, async () => {
285
- const refreshToken = req.token;
284
+ const refreshToken = res.locals.token;
286
285
  if (!refreshToken) {
287
286
  return res.sendStatus(BAD_REQUEST);
288
287
  }
@@ -308,8 +307,10 @@ async function logout(req, res, next) {
308
307
  next();
309
308
  });
310
309
  }
311
- async function refreshJWT(req, res, next) {
312
- const refreshToken = req.token;
310
+ async function authRefresh(req, res, next) {
311
+ await jwtRefreshRequired(req, res, async () => {
312
+ });
313
+ const refreshToken = res.locals.token;
313
314
  if (!refreshToken) {
314
315
  return res.sendStatus(BAD_REQUEST);
315
316
  }
@@ -340,6 +341,7 @@ async function refreshJWT(req, res, next) {
340
341
  if (!credentials) {
341
342
  return res.sendStatus(BAD_REQUEST);
342
343
  }
344
+ res.locals.credentials = credentials;
343
345
  next();
344
346
  } catch (err) {
345
347
  console.log("[WARN] refreshing JWT:", err);
@@ -642,17 +644,35 @@ var QueryBuilder = class {
642
644
  var FluentPatternHandler = class _FluentPatternHandler {
643
645
  /**
644
646
  * Constructor for QueryPatternExecutor.
645
- * @param paths - Array of query pattern paths for filtering.
647
+ * @param options - Array of query pattern options for filtering.
646
648
  */
647
- constructor(paths = []) {
649
+ constructor(options = [], execMiddleware = []) {
650
+ this._execMiddlewareFunctions = [];
648
651
  if (_FluentPatternHandler._singleton) {
649
652
  throw new Error(
650
653
  "FluentPatternHandler is a singleton class. Use FluentPatternHandler.getInstance() to access the instance."
651
654
  );
652
655
  }
653
- this._paths = paths;
656
+ this._options = options;
657
+ this._execMiddlewareFunctions = execMiddleware;
654
658
  _FluentPatternHandler._singleton = this;
655
659
  }
660
+ /**
661
+ * Initializes the singleton instance of FluentPatternHandler with the provided options.
662
+ * @param options - Array of query pattern options for filtering.
663
+ * @returns Singleton instance of FluentPatternHandler.
664
+ */
665
+ static init(options = [], execMiddleware = []) {
666
+ if (_FluentPatternHandler._singleton != void 0) {
667
+ throw new Error("FluentPatternHandler is already initialized");
668
+ }
669
+ _FluentPatternHandler._singleton = new _FluentPatternHandler(options, execMiddleware);
670
+ return _FluentPatternHandler._singleton;
671
+ }
672
+ /**
673
+ * Returns the singleton instance of FluentPatternHandler.
674
+ * @returns Singleton instance of FluentPatternHandler.
675
+ */
656
676
  static getInstance() {
657
677
  if (_FluentPatternHandler._singleton == void 0) {
658
678
  throw new Error(
@@ -737,15 +757,15 @@ var FluentPatternHandler = class _FluentPatternHandler {
737
757
  }
738
758
  }
739
759
  /**
740
- * Retrieves filter fields for the given model from the paths configuration.
760
+ * Retrieves filter fields for the given model from the options configuration.
741
761
  * @param model - The Mongoose model.
742
762
  * @returns Array of filter fields.
743
763
  */
744
764
  _getFilterFieldsForModel(model) {
745
- for (const path2 of this._paths) {
746
- if (path2.model.collection.name === model.collection.name) {
747
- if (path2.filters) {
748
- return path2.filters;
765
+ for (const option of this._options) {
766
+ if (option.model.collection.name === model.collection.name) {
767
+ if (option.filters) {
768
+ return option.filters;
749
769
  }
750
770
  return [];
751
771
  }
@@ -773,6 +793,11 @@ var FluentPatternHandler = class _FluentPatternHandler {
773
793
  */
774
794
  async exec(req, queryBuilder) {
775
795
  try {
796
+ if (this._execMiddlewareFunctions && this._execMiddlewareFunctions.length > 0) {
797
+ this._execMiddlewareFunctions.forEach((func) => {
798
+ func(queryBuilder);
799
+ });
800
+ }
776
801
  const queryParams = this._parseFluentRequestQuery(req.query);
777
802
  this._applyParameters(queryBuilder, queryParams);
778
803
  const execConfig = this._buildExecutionConfig(queryParams);
@@ -870,16 +895,21 @@ var fluent_api_default = router2;
870
895
  // tests/auth.ts
871
896
  import express4 from "express";
872
897
  var router3 = express4.Router();
873
- router3.post("/register", register, async (req, res) => {
874
- res.status(200).json({});
875
- });
876
- router3.post("/login", login, async (req, res) => {
898
+ router3.post(
899
+ "/register",
900
+ authRegister,
901
+ async (req, res) => {
902
+ res.locals.authUser.save();
903
+ res.status(200).json({});
904
+ }
905
+ );
906
+ router3.post("/login", authLogin, async (req, res) => {
877
907
  res.status(200).json(res.locals.credentials);
878
908
  });
879
- router3.post("/logout", logout, async (req, res) => {
909
+ router3.post("/logout", authLogout, async (req, res) => {
880
910
  res.status(200).json({});
881
911
  });
882
- router3.post("/refresh", refreshJWT, async (req, res) => {
912
+ router3.post("/refresh", authRefresh, async (req, res) => {
883
913
  res.status(200).json({});
884
914
  });
885
915
  router3.get("/secure", jwtRequired, async (req, res) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Niklas Wockenfuß",
3
3
  "homepage": "https://niklaswockenfuss.de/",
4
4
  "name": "tsledge",
5
- "version": "0.1.6",
5
+ "version": "0.1.8",
6
6
  "license": "MIT",
7
7
  "description": "My playground and some helpful tools for web development ",
8
8
  "main": "dist/index.js",