@rvoh/psychic 0.37.0-beta.7 → 0.37.0-beta.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.
@@ -268,7 +268,6 @@ class PsychicController {
268
268
  singleObjectJson(data, opts) {
269
269
  if (!data)
270
270
  return data;
271
- const dreamApp = dream_1.DreamApp.getOrFail();
272
271
  const psychicControllerClass = this.constructor;
273
272
  // if we already have a serializer, let's just render it
274
273
  if (data instanceof dream_1.DreamSerializerBuilder || data instanceof dream_1.ObjectSerializerBuilder) {
@@ -292,30 +291,20 @@ class PsychicController {
292
291
  }
293
292
  }
294
293
  else {
295
- const serializerKey =
296
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
297
- data.serializers?.[opts.serializerKey ||
294
+ const serializer = (0, dream_1.inferSerializerFromDreamOrViewModel)(data, opts.serializerKey ||
298
295
  psychicControllerClass['controllerActionMetadata'][this.action]?.['serializerKey'] ||
299
- 'default'];
300
- if (serializerKey && Object.prototype.hasOwnProperty.call(dreamApp.serializers, serializerKey)) {
301
- const serializer = dreamApp.serializers[serializerKey];
302
- if (serializer && (0, dream_1.isDreamSerializer)(serializer)) {
303
- // passthrough data going into the serializer is the argument that gets
304
- // used in the custom attribute callback function
305
- return serializer(data, this.defaultSerializerPassthrough).render(
306
- // passthrough data must be passed both into the serializer and render
307
- // because, if the serializer does accept passthrough data, then passing it in is how
308
- // it gets into the serializer, but if it does not accept passthrough data, and therefore
309
- // does not pass it into the call to DreamSerializer/ObjectSerializer,
310
- // then it would be lost to serializers rendered via rendersOne/Many, and SerializerRenderer
311
- // handles passing its passthrough data into those
312
- this.defaultSerializerPassthrough, this.renderOpts);
313
- }
314
- else {
315
- throw new Error(`
316
- A serializer key was detected, but the server was unable to identify an associated serializer class matching the key.
317
- The key in question is: "${serializerKey}"`);
318
- }
296
+ 'default');
297
+ if (serializer && (0, dream_1.isDreamSerializer)(serializer)) {
298
+ // passthrough data going into the serializer is the argument that gets
299
+ // used in the custom attribute callback function
300
+ return serializer(data, this.defaultSerializerPassthrough).render(
301
+ // passthrough data must be passed both into the serializer and render
302
+ // because, if the serializer does accept passthrough data, then passing it in is how
303
+ // it gets into the serializer, but if it does not accept passthrough data, and therefore
304
+ // does not pass it into the call to DreamSerializer/ObjectSerializer,
305
+ // then it would be lost to serializers rendered via rendersOne/Many, and SerializerRenderer
306
+ // handles passing its passthrough data into those
307
+ this.defaultSerializerPassthrough, this.renderOpts);
319
308
  }
320
309
  }
321
310
  return data;
@@ -603,9 +592,6 @@ class ControllerSerializerIndex {
603
592
  lookupModel(ControllerClass, ModelClass) {
604
593
  return this.associations.find(association => association[0] === ControllerClass && association[2] === ModelClass);
605
594
  }
606
- lookupSerializer(ControllerClass, SerializerClass) {
607
- return this.associations.find(association => association[0] === ControllerClass && association[1] === SerializerClass);
608
- }
609
595
  }
610
596
  exports.ControllerSerializerIndex = ControllerSerializerIndex;
611
597
  exports.controllerSerializerIndex = new ControllerSerializerIndex();
@@ -1,4 +1,4 @@
1
- import { DreamApp, DreamSerializerBuilder, GlobalNameNotSet, isDreamSerializer, ObjectSerializerBuilder, } from '@rvoh/dream';
1
+ import { DreamSerializerBuilder, GlobalNameNotSet, inferSerializerFromDreamOrViewModel, isDreamSerializer, ObjectSerializerBuilder, } from '@rvoh/dream';
2
2
  import ParamValidationError from '../error/controller/ParamValidationError.js';
3
3
  import HttpStatusBadGateway from '../error/http/BadGateway.js';
4
4
  import HttpStatusBadRequest from '../error/http/BadRequest.js';
@@ -262,7 +262,6 @@ export default class PsychicController {
262
262
  singleObjectJson(data, opts) {
263
263
  if (!data)
264
264
  return data;
265
- const dreamApp = DreamApp.getOrFail();
266
265
  const psychicControllerClass = this.constructor;
267
266
  // if we already have a serializer, let's just render it
268
267
  if (data instanceof DreamSerializerBuilder || data instanceof ObjectSerializerBuilder) {
@@ -286,30 +285,20 @@ export default class PsychicController {
286
285
  }
287
286
  }
288
287
  else {
289
- const serializerKey =
290
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
291
- data.serializers?.[opts.serializerKey ||
288
+ const serializer = inferSerializerFromDreamOrViewModel(data, opts.serializerKey ||
292
289
  psychicControllerClass['controllerActionMetadata'][this.action]?.['serializerKey'] ||
293
- 'default'];
294
- if (serializerKey && Object.prototype.hasOwnProperty.call(dreamApp.serializers, serializerKey)) {
295
- const serializer = dreamApp.serializers[serializerKey];
296
- if (serializer && isDreamSerializer(serializer)) {
297
- // passthrough data going into the serializer is the argument that gets
298
- // used in the custom attribute callback function
299
- return serializer(data, this.defaultSerializerPassthrough).render(
300
- // passthrough data must be passed both into the serializer and render
301
- // because, if the serializer does accept passthrough data, then passing it in is how
302
- // it gets into the serializer, but if it does not accept passthrough data, and therefore
303
- // does not pass it into the call to DreamSerializer/ObjectSerializer,
304
- // then it would be lost to serializers rendered via rendersOne/Many, and SerializerRenderer
305
- // handles passing its passthrough data into those
306
- this.defaultSerializerPassthrough, this.renderOpts);
307
- }
308
- else {
309
- throw new Error(`
310
- A serializer key was detected, but the server was unable to identify an associated serializer class matching the key.
311
- The key in question is: "${serializerKey}"`);
312
- }
290
+ 'default');
291
+ if (serializer && isDreamSerializer(serializer)) {
292
+ // passthrough data going into the serializer is the argument that gets
293
+ // used in the custom attribute callback function
294
+ return serializer(data, this.defaultSerializerPassthrough).render(
295
+ // passthrough data must be passed both into the serializer and render
296
+ // because, if the serializer does accept passthrough data, then passing it in is how
297
+ // it gets into the serializer, but if it does not accept passthrough data, and therefore
298
+ // does not pass it into the call to DreamSerializer/ObjectSerializer,
299
+ // then it would be lost to serializers rendered via rendersOne/Many, and SerializerRenderer
300
+ // handles passing its passthrough data into those
301
+ this.defaultSerializerPassthrough, this.renderOpts);
313
302
  }
314
303
  }
315
304
  return data;
@@ -596,8 +585,5 @@ export class ControllerSerializerIndex {
596
585
  lookupModel(ControllerClass, ModelClass) {
597
586
  return this.associations.find(association => association[0] === ControllerClass && association[2] === ModelClass);
598
587
  }
599
- lookupSerializer(ControllerClass, SerializerClass) {
600
- return this.associations.find(association => association[0] === ControllerClass && association[1] === SerializerClass);
601
- }
602
588
  }
603
589
  export const controllerSerializerIndex = new ControllerSerializerIndex();
@@ -200,7 +200,6 @@ export declare class ControllerSerializerIndex {
200
200
  ][];
201
201
  add(ControllerClass: typeof PsychicController, SerializerClass: DreamModelSerializerType | SimpleObjectSerializerType, ModelClass: typeof Dream): void;
202
202
  lookupModel(ControllerClass: typeof PsychicController, ModelClass: typeof Dream): [typeof PsychicController, DreamModelSerializerType | SimpleObjectSerializerType, typeof Dream] | undefined;
203
- lookupSerializer(ControllerClass: typeof PsychicController, SerializerClass: DreamModelSerializerType | SimpleObjectSerializerType): [typeof PsychicController, DreamModelSerializerType | SimpleObjectSerializerType, typeof Dream] | undefined;
204
203
  }
205
204
  export declare const controllerSerializerIndex: ControllerSerializerIndex;
206
205
  export type RenderOptions = {
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.37.0-beta.7",
5
+ "version": "0.37.0-beta.8",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",