@rvoh/psychic 0.31.2 → 0.32.0

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.
@@ -8,14 +8,17 @@ exports.stopDevServer = stopDevServer;
8
8
  exports.stopDevServers = stopDevServers;
9
9
  const child_process_1 = require("child_process");
10
10
  const net_1 = require("net");
11
+ const node_util_1 = require("node:util");
11
12
  const sleep_js_1 = __importDefault(require("../../../spec/helpers/sleep.js"));
12
13
  const UnexpectedUndefined_js_1 = __importDefault(require("../../error/UnexpectedUndefined.js"));
14
+ const index_js_1 = __importDefault(require("../../psychic-app/index.js"));
13
15
  const devServerProcesses = {};
16
+ const debugEnabled = (0, node_util_1.debuglog)('psychic').enabled;
14
17
  async function launchDevServer(key, { port = 3000, cmd = 'yarn client', timeout = 5000 } = {}) {
15
18
  if (devServerProcesses[key])
16
19
  return;
17
- if (process.env.DEBUG === '1')
18
- console.log('Starting server...');
20
+ if (debugEnabled)
21
+ index_js_1.default.log('Starting server...');
19
22
  const [_cmd, ...args] = cmd.split(' ');
20
23
  if (_cmd === undefined)
21
24
  throw new UnexpectedUndefined_js_1.default();
@@ -31,19 +34,19 @@ async function launchDevServer(key, { port = 3000, cmd = 'yarn client', timeout
31
34
  throw err;
32
35
  });
33
36
  proc.stdout.on('data', data => {
34
- if (process.env.DEBUG === '1')
35
- console.log(`Server output: ${data}`);
37
+ if (debugEnabled)
38
+ index_js_1.default.log(`Server output: ${data}`);
36
39
  });
37
40
  proc.stderr.on('data', data => {
38
- if (process.env.DEBUG === '1')
39
- console.error(`Server error: ${data}`);
41
+ if (debugEnabled)
42
+ index_js_1.default.logWithLevel('error', `Server error: ${data}`);
40
43
  });
41
44
  proc.on('error', err => {
42
- console.error(`Server process error: ${err}`);
45
+ index_js_1.default.logWithLevel('error', `Server process error: ${err}`);
43
46
  });
44
47
  proc.on('close', code => {
45
- if (process.env.DEBUG === '1')
46
- console.log(`Server process exited with code ${code}`);
48
+ if (debugEnabled)
49
+ index_js_1.default.log(`Server process exited with code ${code}`);
47
50
  });
48
51
  }
49
52
  function stopDevServer(key) {
@@ -52,8 +55,8 @@ function stopDevServer(key) {
52
55
  throw new Error(`Cannot find a dev server by the key: ${key}`);
53
56
  }
54
57
  if (proc?.pid) {
55
- if (process.env.DEBUG === '1')
56
- console.log('Stopping server...');
58
+ if (debugEnabled)
59
+ index_js_1.default.log('Stopping server...');
57
60
  try {
58
61
  // proc.kill('SIGINT')
59
62
  process.kill(-proc.pid, 'SIGKILL');
@@ -62,8 +65,8 @@ function stopDevServer(key) {
62
65
  // noop
63
66
  }
64
67
  delete devServerProcesses[key];
65
- if (process.env.DEBUG === '1')
66
- console.log('server stopped');
68
+ if (debugEnabled)
69
+ index_js_1.default.log('server stopped');
67
70
  }
68
71
  }
69
72
  function stopDevServers() {
@@ -29,13 +29,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const dream_1 = require("@rvoh/dream");
30
30
  const lodash_es_1 = require("lodash-es");
31
31
  const fs = __importStar(require("node:fs/promises"));
32
+ const node_util_1 = require("node:util");
32
33
  const UnexpectedUndefined_js_1 = __importDefault(require("../error/UnexpectedUndefined.js"));
33
- const EnvInternal_js_1 = __importDefault(require("../helpers/EnvInternal.js"));
34
34
  const openapiJsonPath_js_1 = __importDefault(require("../helpers/openapiJsonPath.js"));
35
35
  const index_js_1 = __importDefault(require("../psychic-app/index.js"));
36
36
  const types_js_1 = require("../router/types.js");
37
37
  const index_js_2 = __importDefault(require("../server/index.js"));
38
38
  const defaults_js_1 = require("./defaults.js");
39
+ const debugEnabled = (0, node_util_1.debuglog)('psychic').enabled;
39
40
  class OpenapiAppRenderer {
40
41
  /**
41
42
  * @internal
@@ -114,8 +115,8 @@ class OpenapiAppRenderer {
114
115
  }
115
116
  for (const [controllerName, controller] of Object.entries(controllers).filter(([, controller]) => controller.openapiNames.includes(openapiName))) {
116
117
  for (const key of Object.keys(controller.openapi || {})) {
117
- if (EnvInternal_js_1.default.isDebug)
118
- console.log(`Processing OpenAPI key ${key} for controller ${controllerName}`);
118
+ if (debugEnabled)
119
+ index_js_1.default.log(`Processing OpenAPI key ${key} for controller ${controllerName}`);
119
120
  const renderer = controller.openapi[key];
120
121
  if (renderer === undefined)
121
122
  throw new UnexpectedUndefined_js_1.default();
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dream_1 = require("@rvoh/dream");
7
+ const node_util_1 = require("node:util");
7
8
  const CannotFlattenMultiplePolymorphicRendersOneAssociations_js_1 = __importDefault(require("../error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js"));
8
9
  const UnexpectedUndefined_js_1 = __importDefault(require("../error/UnexpectedUndefined.js"));
9
- const EnvInternal_js_1 = __importDefault(require("../helpers/EnvInternal.js"));
10
10
  const index_js_1 = __importDefault(require("../psychic-app/index.js"));
11
11
  const body_segment_js_1 = __importDefault(require("./body-segment.js"));
12
12
  const schemaToRef_js_1 = __importDefault(require("./helpers/schemaToRef.js"));
13
+ const debugEnabled = (0, node_util_1.debuglog)('psychic').enabled;
13
14
  class OpenapiSerializerRenderer {
14
15
  openapiName;
15
16
  controllerClass;
@@ -165,7 +166,7 @@ Error: ${this.serializerClass.name} missing explicit serializer definition for $
165
166
  if (associatedSerializer === undefined)
166
167
  throw new UnexpectedUndefined_js_1.default();
167
168
  const associatedSerializerKey = associatedSerializer.openapiName;
168
- if (EnvInternal_js_1.default.isDebug)
169
+ if (debugEnabled)
169
170
  index_js_1.default.log(`Processing serializer ${associatedSerializerKey}`);
170
171
  let flattenedData;
171
172
  const finalOutputForSerializerKey = finalOutput[serializerKey];
@@ -285,7 +286,7 @@ Error: ${this.serializerClass.name} missing explicit serializer definition for $
285
286
  const anyOf = [];
286
287
  associatedSerializers.forEach(associatedSerializer => {
287
288
  const associatedSerializerKey = associatedSerializer.openapiName;
288
- if (EnvInternal_js_1.default.isDebug)
289
+ if (debugEnabled)
289
290
  index_js_1.default.log(`Processing serializer ${associatedSerializerKey}`);
290
291
  finalOutputForSerializerKey.required = (0, dream_1.uniq)([
291
292
  ...(finalOutputForSerializerKey.required || []),
@@ -32,11 +32,12 @@ const cors = __importStar(require("cors"));
32
32
  const express = __importStar(require("express"));
33
33
  const OpenApiValidator = __importStar(require("express-openapi-validator"));
34
34
  const path = __importStar(require("node:path"));
35
- const EnvInternal_js_1 = __importDefault(require("../helpers/EnvInternal.js"));
35
+ const node_util_1 = require("node:util");
36
36
  const isOpenapiError_js_1 = __importDefault(require("../helpers/isOpenapiError.js"));
37
37
  const index_js_1 = __importDefault(require("../psychic-app/index.js"));
38
38
  const index_js_2 = __importDefault(require("../router/index.js"));
39
39
  const startPsychicServer_js_1 = __importStar(require("./helpers/startPsychicServer.js"));
40
+ const debugEnabled = (0, node_util_1.debuglog)('psychic').enabled;
40
41
  class PsychicServer {
41
42
  static async startPsychicServer(opts) {
42
43
  return await (0, startPsychicServer_js_1.default)(opts);
@@ -178,7 +179,7 @@ class PsychicServer {
178
179
  this.expressApp.use(OpenApiValidator.middleware(opts));
179
180
  this.expressApp.use((err, req, res, next) => {
180
181
  if ((0, isOpenapiError_js_1.default)(err)) {
181
- if (EnvInternal_js_1.default.isDebug) {
182
+ if (debugEnabled) {
182
183
  index_js_1.default.log(JSON.stringify(err));
183
184
  console.trace();
184
185
  }
@@ -188,7 +189,7 @@ class PsychicServer {
188
189
  });
189
190
  }
190
191
  else {
191
- if (EnvInternal_js_1.default.isDebug) {
192
+ if (debugEnabled) {
192
193
  index_js_1.default.logWithLevel('error', err);
193
194
  }
194
195
  next();
@@ -1,13 +1,16 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { createServer } from 'net';
3
+ import { debuglog } from 'node:util';
3
4
  import sleep from '../../../spec/helpers/sleep.js';
4
5
  import UnexpectedUndefined from '../../error/UnexpectedUndefined.js';
6
+ import PsychicApp from '../../psychic-app/index.js';
5
7
  const devServerProcesses = {};
8
+ const debugEnabled = debuglog('psychic').enabled;
6
9
  export async function launchDevServer(key, { port = 3000, cmd = 'yarn client', timeout = 5000 } = {}) {
7
10
  if (devServerProcesses[key])
8
11
  return;
9
- if (process.env.DEBUG === '1')
10
- console.log('Starting server...');
12
+ if (debugEnabled)
13
+ PsychicApp.log('Starting server...');
11
14
  const [_cmd, ...args] = cmd.split(' ');
12
15
  if (_cmd === undefined)
13
16
  throw new UnexpectedUndefined();
@@ -23,19 +26,19 @@ export async function launchDevServer(key, { port = 3000, cmd = 'yarn client', t
23
26
  throw err;
24
27
  });
25
28
  proc.stdout.on('data', data => {
26
- if (process.env.DEBUG === '1')
27
- console.log(`Server output: ${data}`);
29
+ if (debugEnabled)
30
+ PsychicApp.log(`Server output: ${data}`);
28
31
  });
29
32
  proc.stderr.on('data', data => {
30
- if (process.env.DEBUG === '1')
31
- console.error(`Server error: ${data}`);
33
+ if (debugEnabled)
34
+ PsychicApp.logWithLevel('error', `Server error: ${data}`);
32
35
  });
33
36
  proc.on('error', err => {
34
- console.error(`Server process error: ${err}`);
37
+ PsychicApp.logWithLevel('error', `Server process error: ${err}`);
35
38
  });
36
39
  proc.on('close', code => {
37
- if (process.env.DEBUG === '1')
38
- console.log(`Server process exited with code ${code}`);
40
+ if (debugEnabled)
41
+ PsychicApp.log(`Server process exited with code ${code}`);
39
42
  });
40
43
  }
41
44
  export function stopDevServer(key) {
@@ -44,8 +47,8 @@ export function stopDevServer(key) {
44
47
  throw new Error(`Cannot find a dev server by the key: ${key}`);
45
48
  }
46
49
  if (proc?.pid) {
47
- if (process.env.DEBUG === '1')
48
- console.log('Stopping server...');
50
+ if (debugEnabled)
51
+ PsychicApp.log('Stopping server...');
49
52
  try {
50
53
  // proc.kill('SIGINT')
51
54
  process.kill(-proc.pid, 'SIGKILL');
@@ -54,8 +57,8 @@ export function stopDevServer(key) {
54
57
  // noop
55
58
  }
56
59
  delete devServerProcesses[key];
57
- if (process.env.DEBUG === '1')
58
- console.log('server stopped');
60
+ if (debugEnabled)
61
+ PsychicApp.log('server stopped');
59
62
  }
60
63
  }
61
64
  export function stopDevServers() {
@@ -1,13 +1,14 @@
1
1
  import { compact } from '@rvoh/dream';
2
2
  import { groupBy } from 'lodash-es';
3
3
  import * as fs from 'node:fs/promises';
4
+ import { debuglog } from 'node:util';
4
5
  import UnexpectedUndefined from '../error/UnexpectedUndefined.js';
5
- import EnvInternal from '../helpers/EnvInternal.js';
6
6
  import openapiJsonPath from '../helpers/openapiJsonPath.js';
7
7
  import PsychicApp from '../psychic-app/index.js';
8
8
  import { HttpMethods } from '../router/types.js';
9
9
  import PsychicServer from '../server/index.js';
10
10
  import { DEFAULT_OPENAPI_COMPONENT_RESPONSES, DEFAULT_OPENAPI_COMPONENT_SCHEMAS } from './defaults.js';
11
+ const debugEnabled = debuglog('psychic').enabled;
11
12
  export default class OpenapiAppRenderer {
12
13
  /**
13
14
  * @internal
@@ -86,8 +87,8 @@ export default class OpenapiAppRenderer {
86
87
  }
87
88
  for (const [controllerName, controller] of Object.entries(controllers).filter(([, controller]) => controller.openapiNames.includes(openapiName))) {
88
89
  for (const key of Object.keys(controller.openapi || {})) {
89
- if (EnvInternal.isDebug)
90
- console.log(`Processing OpenAPI key ${key} for controller ${controllerName}`);
90
+ if (debugEnabled)
91
+ PsychicApp.log(`Processing OpenAPI key ${key} for controller ${controllerName}`);
91
92
  const renderer = controller.openapi[key];
92
93
  if (renderer === undefined)
93
94
  throw new UnexpectedUndefined();
@@ -1,10 +1,11 @@
1
1
  import { DreamSerializer, uniq, } from '@rvoh/dream';
2
+ import { debuglog } from 'node:util';
2
3
  import CannotFlattenMultiplePolymorphicRendersOneAssociations from '../error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js';
3
4
  import UnexpectedUndefined from '../error/UnexpectedUndefined.js';
4
- import EnvInternal from '../helpers/EnvInternal.js';
5
5
  import PsychicApp from '../psychic-app/index.js';
6
6
  import OpenapiBodySegmentRenderer from './body-segment.js';
7
7
  import schemaToRef from './helpers/schemaToRef.js';
8
+ const debugEnabled = debuglog('psychic').enabled;
8
9
  export default class OpenapiSerializerRenderer {
9
10
  openapiName;
10
11
  controllerClass;
@@ -160,7 +161,7 @@ Error: ${this.serializerClass.name} missing explicit serializer definition for $
160
161
  if (associatedSerializer === undefined)
161
162
  throw new UnexpectedUndefined();
162
163
  const associatedSerializerKey = associatedSerializer.openapiName;
163
- if (EnvInternal.isDebug)
164
+ if (debugEnabled)
164
165
  PsychicApp.log(`Processing serializer ${associatedSerializerKey}`);
165
166
  let flattenedData;
166
167
  const finalOutputForSerializerKey = finalOutput[serializerKey];
@@ -280,7 +281,7 @@ Error: ${this.serializerClass.name} missing explicit serializer definition for $
280
281
  const anyOf = [];
281
282
  associatedSerializers.forEach(associatedSerializer => {
282
283
  const associatedSerializerKey = associatedSerializer.openapiName;
283
- if (EnvInternal.isDebug)
284
+ if (debugEnabled)
284
285
  PsychicApp.log(`Processing serializer ${associatedSerializerKey}`);
285
286
  finalOutputForSerializerKey.required = uniq([
286
287
  ...(finalOutputForSerializerKey.required || []),
@@ -4,11 +4,12 @@ import * as cors from 'cors';
4
4
  import * as express from 'express';
5
5
  import * as OpenApiValidator from 'express-openapi-validator';
6
6
  import * as path from 'node:path';
7
- import EnvInternal from '../helpers/EnvInternal.js';
7
+ import { debuglog } from 'node:util';
8
8
  import isOpenapiError from '../helpers/isOpenapiError.js';
9
9
  import PsychicApp from '../psychic-app/index.js';
10
10
  import PsychicRouter from '../router/index.js';
11
11
  import startPsychicServer, { createPsychicHttpInstance, } from './helpers/startPsychicServer.js';
12
+ const debugEnabled = debuglog('psychic').enabled;
12
13
  export default class PsychicServer {
13
14
  static async startPsychicServer(opts) {
14
15
  return await startPsychicServer(opts);
@@ -150,7 +151,7 @@ export default class PsychicServer {
150
151
  this.expressApp.use(OpenApiValidator.middleware(opts));
151
152
  this.expressApp.use((err, req, res, next) => {
152
153
  if (isOpenapiError(err)) {
153
- if (EnvInternal.isDebug) {
154
+ if (debugEnabled) {
154
155
  PsychicApp.log(JSON.stringify(err));
155
156
  console.trace();
156
157
  }
@@ -160,7 +161,7 @@ export default class PsychicServer {
160
161
  });
161
162
  }
162
163
  else {
163
- if (EnvInternal.isDebug) {
164
+ if (debugEnabled) {
164
165
  PsychicApp.logWithLevel('error', err);
165
166
  }
166
167
  next();
@@ -2,6 +2,6 @@ import { Env } from '@rvoh/dream';
2
2
  declare const EnvInternal: Env<{
3
3
  string: "SPEC_SERVER_PORT" | "NODE_ENV";
4
4
  integer: "PORT";
5
- boolean: "CLIENT" | "DEBUG" | "PSYCHIC_DANGEROUSLY_PERMIT_WS_EXCEPTIONS" | "BYPASS_DB_CONNECTIONS_DURING_INIT" | "PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR";
6
- }, "SPEC_SERVER_PORT" | "NODE_ENV", "PORT", "CLIENT" | "DEBUG" | "PSYCHIC_DANGEROUSLY_PERMIT_WS_EXCEPTIONS" | "BYPASS_DB_CONNECTIONS_DURING_INIT" | "PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR">;
5
+ boolean: "CLIENT" | "PSYCHIC_DANGEROUSLY_PERMIT_WS_EXCEPTIONS" | "BYPASS_DB_CONNECTIONS_DURING_INIT" | "PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR";
6
+ }, "SPEC_SERVER_PORT" | "NODE_ENV", "PORT", "CLIENT" | "PSYCHIC_DANGEROUSLY_PERMIT_WS_EXCEPTIONS" | "BYPASS_DB_CONNECTIONS_DURING_INIT" | "PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR">;
7
7
  export default EnvInternal;
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": "0.31.2",
5
+ "version": "0.32.0",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",