@rvoh/psychic 1.1.5 → 1.1.7

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/CHANGELOG.md CHANGED
@@ -58,3 +58,11 @@ Fix route printing regression causing route printouts to show the path instead o
58
58
 
59
59
  - pass packageManager through to dream, now that it accepts a packageManager setting.
60
60
  - update dream shadowing within psychic application initialization to take place after initializers and plugins are processed, so that those initializers and plugins have an opportunity to adjust the settings.
61
+
62
+ ## 1.1.6
63
+
64
+ - fix regression caused by missing --schema-only option in psychic cli
65
+
66
+ ## 1.1.7
67
+
68
+ - Add support for middleware arrays, enabling express plugins like passport
@@ -54,9 +54,11 @@ class PsychicBin {
54
54
  static async routes() {
55
55
  await (0, printRoutes_js_1.default)();
56
56
  }
57
- static async sync({ bypassDreamSync = false } = {}) {
57
+ static async sync({ bypassDreamSync = false, schemaOnly = false, } = {}) {
58
58
  if (!bypassDreamSync)
59
- await dream_1.DreamBin.sync(() => { });
59
+ await dream_1.DreamBin.sync(() => { }, { schemaOnly });
60
+ if (schemaOnly)
61
+ return;
60
62
  await PsychicBin.syncTypes();
61
63
  const psychicApp = index_js_1.default.getOrFail();
62
64
  dream_1.DreamCLI.logger.logStartProgress('running post-sync operations...');
@@ -137,9 +137,10 @@ class PsychicCLI {
137
137
  program
138
138
  .command('sync')
139
139
  .description('sync introspects your database, updating your schema to reflect, and then syncs the new schema with the installed dream node module, allowing it provide your schema to the underlying kysely integration')
140
- .action(async () => {
140
+ .option('--schema-only')
141
+ .action(async (options = {}) => {
141
142
  await initializePsychicApp();
142
- await index_js_1.default.sync();
143
+ await index_js_1.default.sync(options);
143
144
  process.exit();
144
145
  });
145
146
  program
@@ -38,9 +38,7 @@ class PsychicRouter {
38
38
  this.routes.forEach(route => {
39
39
  if (route.middleware) {
40
40
  const routeConf = route;
41
- this.app[routeConf.httpMethod]((0, helpers_js_1.routePath)(routeConf.path), (req, res, next) => {
42
- this.handleMiddleware(routeConf.middleware, { req, res, next }).catch(() => { });
43
- });
41
+ this.app[routeConf.httpMethod]((0, helpers_js_1.routePath)(routeConf.path), ...(Array.isArray(routeConf.middleware) ? routeConf.middleware : [routeConf.middleware]));
44
42
  }
45
43
  else {
46
44
  const routeConf = route;
@@ -75,7 +73,7 @@ class PsychicRouter {
75
73
  }
76
74
  crud(httpMethod, path, controllerOrMiddleware, action) {
77
75
  this.checkPathForInvalidChars(path);
78
- const isMiddleware = typeof controllerOrMiddleware === 'function' &&
76
+ const isMiddleware = (typeof controllerOrMiddleware === 'function' || Array.isArray(controllerOrMiddleware)) &&
79
77
  !controllerOrMiddleware?.isPsychicController;
80
78
  // devs can provide custom express middleware which bypasses
81
79
  // the normal Controller#action paradigm.
@@ -222,9 +220,6 @@ suggested fix: "${(0, helpers_js_1.convertRouteParams)(path)}"
222
220
  if (nestedRouter)
223
221
  nestedRouter.currentNamespaces = this.currentNamespaces;
224
222
  }
225
- async handleMiddleware(middleware, { req, res, next, }) {
226
- await middleware(req, res, next);
227
- }
228
223
  async handle(controller, action, { req, res, }) {
229
224
  const controllerInstance = this._initializeController(controller, req, res, action);
230
225
  if (typeof controllerInstance[action] !== 'function') {
@@ -26,9 +26,11 @@ export default class PsychicBin {
26
26
  static async routes() {
27
27
  await printRoutes();
28
28
  }
29
- static async sync({ bypassDreamSync = false } = {}) {
29
+ static async sync({ bypassDreamSync = false, schemaOnly = false, } = {}) {
30
30
  if (!bypassDreamSync)
31
- await DreamBin.sync(() => { });
31
+ await DreamBin.sync(() => { }, { schemaOnly });
32
+ if (schemaOnly)
33
+ return;
32
34
  await PsychicBin.syncTypes();
33
35
  const psychicApp = PsychicApp.getOrFail();
34
36
  DreamCLI.logger.logStartProgress('running post-sync operations...');
@@ -132,9 +132,10 @@ export default class PsychicCLI {
132
132
  program
133
133
  .command('sync')
134
134
  .description('sync introspects your database, updating your schema to reflect, and then syncs the new schema with the installed dream node module, allowing it provide your schema to the underlying kysely integration')
135
- .action(async () => {
135
+ .option('--schema-only')
136
+ .action(async (options = {}) => {
136
137
  await initializePsychicApp();
137
- await PsychicBin.sync();
138
+ await PsychicBin.sync(options);
138
139
  process.exit();
139
140
  });
140
141
  program
@@ -32,9 +32,7 @@ export default class PsychicRouter {
32
32
  this.routes.forEach(route => {
33
33
  if (route.middleware) {
34
34
  const routeConf = route;
35
- this.app[routeConf.httpMethod](routePath(routeConf.path), (req, res, next) => {
36
- this.handleMiddleware(routeConf.middleware, { req, res, next }).catch(() => { });
37
- });
35
+ this.app[routeConf.httpMethod](routePath(routeConf.path), ...(Array.isArray(routeConf.middleware) ? routeConf.middleware : [routeConf.middleware]));
38
36
  }
39
37
  else {
40
38
  const routeConf = route;
@@ -69,7 +67,7 @@ export default class PsychicRouter {
69
67
  }
70
68
  crud(httpMethod, path, controllerOrMiddleware, action) {
71
69
  this.checkPathForInvalidChars(path);
72
- const isMiddleware = typeof controllerOrMiddleware === 'function' &&
70
+ const isMiddleware = (typeof controllerOrMiddleware === 'function' || Array.isArray(controllerOrMiddleware)) &&
73
71
  !controllerOrMiddleware?.isPsychicController;
74
72
  // devs can provide custom express middleware which bypasses
75
73
  // the normal Controller#action paradigm.
@@ -216,9 +214,6 @@ suggested fix: "${convertRouteParams(path)}"
216
214
  if (nestedRouter)
217
215
  nestedRouter.currentNamespaces = this.currentNamespaces;
218
216
  }
219
- async handleMiddleware(middleware, { req, res, next, }) {
220
- await middleware(req, res, next);
221
- }
222
217
  async handle(controller, action, { req, res, }) {
223
218
  const controllerInstance = this._initializeController(controller, req, res, action);
224
219
  if (typeof controllerInstance[action] !== 'function') {
@@ -7,8 +7,9 @@ export default class PsychicBin {
7
7
  owningModel?: string;
8
8
  }): Promise<void>;
9
9
  static routes(): Promise<void>;
10
- static sync({ bypassDreamSync }?: {
10
+ static sync({ bypassDreamSync, schemaOnly, }?: {
11
11
  bypassDreamSync?: boolean;
12
+ schemaOnly?: boolean;
12
13
  }): Promise<void>;
13
14
  static postSync(): Promise<void>;
14
15
  static syncTypes(customTypes?: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { Express, NextFunction, Request, RequestHandler, Response, Router } from 'express';
1
+ import { Express, Request, RequestHandler, Response, Router } from 'express';
2
2
  import PsychicController from '../controller/index.js';
3
3
  import PsychicApp from '../psychic-app/index.js';
4
4
  import { NamespaceConfig, PsychicControllerActions } from '../router/helpers.js';
@@ -15,26 +15,26 @@ export default class PsychicRouter {
15
15
  private get currentNamespacePaths();
16
16
  commit(): void;
17
17
  get(path: string): void;
18
- get(path: string, middleware: RequestHandler): void;
18
+ get(path: string, middleware: RequestHandler | RequestHandler[]): void;
19
19
  get<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
20
20
  post(path: string): void;
21
- post(path: string, middleware: RequestHandler): void;
21
+ post(path: string, middleware: RequestHandler | RequestHandler[]): void;
22
22
  post<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
23
23
  put(path: string): void;
24
- put(path: string, middleware: RequestHandler): void;
24
+ put(path: string, middleware: RequestHandler | RequestHandler[]): void;
25
25
  put<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
26
26
  patch(path: string): void;
27
- patch(path: string, middleware: RequestHandler): void;
27
+ patch(path: string, middleware: RequestHandler | RequestHandler[]): void;
28
28
  patch<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
29
29
  delete(path: string): void;
30
- delete(path: string, middleware: RequestHandler): void;
30
+ delete(path: string, middleware: RequestHandler | RequestHandler[]): void;
31
31
  delete<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
32
32
  options(path: string): void;
33
- options(path: string, middleware: RequestHandler): void;
33
+ options(path: string, middleware: RequestHandler | RequestHandler[]): void;
34
34
  options<T extends typeof PsychicController>(path: string, controller: T, action: PsychicControllerActions<T>): void;
35
35
  private prefixPathWithNamespaces;
36
36
  crud(httpMethod: HttpMethod, path: string): void;
37
- crud(httpMethod: HttpMethod, path: string, middleware: RequestHandler): void;
37
+ crud(httpMethod: HttpMethod, path: string, middleware: RequestHandler | RequestHandler[]): void;
38
38
  crud(httpMethod: HttpMethod, path: string, controller: typeof PsychicController, action: string): void;
39
39
  private checkPathForInvalidChars;
40
40
  namespace(namespace: string, cb: (router: PsychicNestedRouter) => void): void;
@@ -48,11 +48,6 @@ export default class PsychicRouter {
48
48
  private addNamespace;
49
49
  private removeLastNamespace;
50
50
  private makeRoomForNewIdParam;
51
- handleMiddleware(middleware: RequestHandler, { req, res, next, }: {
52
- req: Request;
53
- res: Response;
54
- next: NextFunction;
55
- }): Promise<void>;
56
51
  handle(controller: typeof PsychicController, action: string, { req, res, }: {
57
52
  req: Request;
58
53
  res: Response;
@@ -12,7 +12,7 @@ export default class RouteManager {
12
12
  addMiddleware({ httpMethod, path, middleware, }: {
13
13
  httpMethod: HttpMethod;
14
14
  path: string;
15
- middleware: RequestHandler;
15
+ middleware: RequestHandler | RequestHandler[];
16
16
  }): void;
17
17
  }
18
18
  export type RouteConfig = ControllerActionRouteConfig | MiddlewareRouteConfig;
@@ -25,6 +25,6 @@ export type ControllerActionRouteConfig = BaseRouteConfig & {
25
25
  action: string;
26
26
  };
27
27
  export type MiddlewareRouteConfig = BaseRouteConfig & {
28
- middleware: RequestHandler;
28
+ middleware: RequestHandler | RequestHandler[];
29
29
  };
30
30
  export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic",
4
4
  "description": "Typescript web framework",
5
- "version": "1.1.5",
5
+ "version": "1.1.7",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",
@@ -63,17 +63,23 @@
63
63
  "@rvoh/dream-spec-helpers": "^1.0.0",
64
64
  "@rvoh/psychic-spec-helpers": "^1.0.0",
65
65
  "@types/express": "^5.0.1",
66
+ "@types/express-session": "^1",
66
67
  "@types/node": "^22.5.1",
68
+ "@types/passport": "^0",
69
+ "@types/passport-local": "^1",
67
70
  "@types/pg": "^8.11.8",
68
71
  "@types/supertest": "^6.0.3",
69
72
  "@typescript/analyze-trace": "^0.10.1",
70
73
  "eslint": "^9.19.0",
71
74
  "express": "^5.1.0",
75
+ "express-session": "^1.18.1",
72
76
  "jsdom": "^26.0.0",
73
77
  "kysely": "^0.27.4",
74
78
  "kysely-codegen": "~0.17.0",
75
79
  "luxon-jest-matchers": "^0.1.14",
76
80
  "openapi-typescript": "^7.8.0",
81
+ "passport": "^0.7.0",
82
+ "passport-local": "^1.0.0",
77
83
  "pg": "^8.12.0",
78
84
  "prettier": "^3.3.3",
79
85
  "puppeteer": "^24.4.0",