@rvoh/psychic 1.1.10 → 1.2.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.
@@ -15,7 +15,10 @@ async function enumsFileStr() {
15
15
  const values = enums[enumName] || [];
16
16
  enumsFileStr += `\
17
17
  export const ${exportedTypeName} = [
18
- ${values.map(val => `'${val}'`).join(',\n ')}
18
+ ${values
19
+ .sort()
20
+ .map(val => `'${val}'`)
21
+ .join(',\n ')}
19
22
  ] as const
20
23
 
21
24
  `;
@@ -248,7 +248,9 @@ class PsychicController {
248
248
  return this._castParam(keys, nestedParams, expectedType, opts);
249
249
  }
250
250
  paramsFor(dreamClass, opts) {
251
- return params_js_1.default.for(opts?.key ? this.params[opts.key] || {} : this.params, dreamClass, opts);
251
+ return params_js_1.default.for(opts?.key ? this.params[opts.key] || {} : this.params, dreamClass,
252
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
+ opts);
252
254
  }
253
255
  getCookie(name) {
254
256
  return (this.session.getCookie(name) ?? null);
@@ -258,7 +260,7 @@ class PsychicController {
258
260
  }
259
261
  startSession(user) {
260
262
  return this.setCookie(this.config.sessionCookieName, JSON.stringify({
261
- id: user.primaryKeyValue,
263
+ id: user.primaryKeyValue().toString(),
262
264
  modelKey: user.constructor.globalName,
263
265
  }));
264
266
  }
@@ -245,11 +245,12 @@ suggested fix: "${(0, helpers_js_1.convertRouteParams)(path)}"
245
245
  else if (err instanceof dream_1.RecordNotFound) {
246
246
  res.sendStatus(404);
247
247
  }
248
- else if (err instanceof dream_1.DataTypeColumnTypeMismatch ||
249
- err instanceof dream_1.NotNullViolation ||
250
- err instanceof dream_1.CheckConstraintViolation) {
248
+ else if (err instanceof dream_1.NotNullViolation || err instanceof dream_1.CheckConstraintViolation) {
251
249
  res.status(422).json();
252
250
  }
251
+ else if (err instanceof dream_1.DataTypeColumnTypeMismatch) {
252
+ res.status(400).json();
253
+ }
253
254
  else if (err instanceof dream_1.ValidationError) {
254
255
  res.status(422).json({ errors: err.errors || {} });
255
256
  }
@@ -44,6 +44,7 @@ class Params {
44
44
  const columns = schema[dreamClass.prototype.table]?.columns;
45
45
  const returnObj = {};
46
46
  const errors = {};
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
48
  const paramSafeColumns = (0, paramNamesForDreamClass_js_1.default)(dreamClass, forOpts);
48
49
  for (const columnName of paramSafeColumns) {
49
50
  if (params[columnName] === undefined)
@@ -9,7 +9,10 @@ export default async function enumsFileStr() {
9
9
  const values = enums[enumName] || [];
10
10
  enumsFileStr += `\
11
11
  export const ${exportedTypeName} = [
12
- ${values.map(val => `'${val}'`).join(',\n ')}
12
+ ${values
13
+ .sort()
14
+ .map(val => `'${val}'`)
15
+ .join(',\n ')}
13
16
  ] as const
14
17
 
15
18
  `;
@@ -242,7 +242,9 @@ export default class PsychicController {
242
242
  return this._castParam(keys, nestedParams, expectedType, opts);
243
243
  }
244
244
  paramsFor(dreamClass, opts) {
245
- return Params.for(opts?.key ? this.params[opts.key] || {} : this.params, dreamClass, opts);
245
+ return Params.for(opts?.key ? this.params[opts.key] || {} : this.params, dreamClass,
246
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
+ opts);
246
248
  }
247
249
  getCookie(name) {
248
250
  return (this.session.getCookie(name) ?? null);
@@ -252,7 +254,7 @@ export default class PsychicController {
252
254
  }
253
255
  startSession(user) {
254
256
  return this.setCookie(this.config.sessionCookieName, JSON.stringify({
255
- id: user.primaryKeyValue,
257
+ id: user.primaryKeyValue().toString(),
256
258
  modelKey: user.constructor.globalName,
257
259
  }));
258
260
  }
@@ -239,11 +239,12 @@ suggested fix: "${convertRouteParams(path)}"
239
239
  else if (err instanceof RecordNotFound) {
240
240
  res.sendStatus(404);
241
241
  }
242
- else if (err instanceof DataTypeColumnTypeMismatch ||
243
- err instanceof NotNullViolation ||
244
- err instanceof CheckConstraintViolation) {
242
+ else if (err instanceof NotNullViolation || err instanceof CheckConstraintViolation) {
245
243
  res.status(422).json();
246
244
  }
245
+ else if (err instanceof DataTypeColumnTypeMismatch) {
246
+ res.status(400).json();
247
+ }
247
248
  else if (err instanceof ValidationError) {
248
249
  res.status(422).json({ errors: err.errors || {} });
249
250
  }
@@ -39,6 +39,7 @@ export default class Params {
39
39
  const columns = schema[dreamClass.prototype.table]?.columns;
40
40
  const returnObj = {};
41
41
  const errors = {};
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
43
  const paramSafeColumns = paramNamesForDreamClass(dreamClass, forOpts);
43
44
  for (const columnName of paramSafeColumns) {
44
45
  if (params[columnName] === undefined)
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.10",
5
+ "version": "1.2.0",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",
@@ -59,8 +59,8 @@
59
59
  "devDependencies": {
60
60
  "@eslint/js": "^9.19.0",
61
61
  "@jest-mock/express": "^3.0.0",
62
- "@rvoh/dream": "^1.3.1",
63
- "@rvoh/dream-spec-helpers": "^1.0.0",
62
+ "@rvoh/dream": "^1.4.0",
63
+ "@rvoh/dream-spec-helpers": "^1.1.0",
64
64
  "@rvoh/psychic-spec-helpers": "^1.0.0",
65
65
  "@types/express": "^5.0.1",
66
66
  "@types/express-session": "^1",