@rvoh/psychic 3.0.0-alpha.3 → 3.0.0-alpha.4

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.
@@ -607,16 +607,14 @@ export default class PsychicController {
607
607
  if (this._responseSent)
608
608
  return;
609
609
  this.ctx.status = statusCode;
610
- // Try to use fast-json-stringify if an OpenAPI schema exists for this endpoint
611
- const stringifyFn = this.currentOpenapiRenderer?.['disableFastJson']
612
- ? undefined
613
- : this.getFastJsonStringifyFunction(statusCode);
610
+ const stringifyFn = this.currentOpenapiRenderer?.['fastJsonStringify']
611
+ ? this.getFastJsonStringifyFunction(statusCode)
612
+ : undefined;
614
613
  if (stringifyFn) {
615
614
  this.ctx.type = 'application/json';
616
615
  this.ctx.body = stringifyFn(data);
617
616
  }
618
617
  else {
619
- // Fall back to toJson() if no OpenAPI schema exists
620
618
  this.ctx.type = 'json';
621
619
  this.ctx.body = toJson(data);
622
620
  }
@@ -35,6 +35,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
35
35
  status: 201,
36
36
  tags: openApiTags,
37
37
  description: 'Create ${aOrAnDreamModelName(modelClassName)}',${defaultOpenapiSerializerKeyProperty}
38
+ fastJsonStringify: true,
38
39
  })
39
40
  public async create() {
40
41
  // let ${modelAttributeName} = await ${forAdmin ? `${modelClassName}.create(` : `this.${owningModelProperty}.createAssociation('${pluralizedModelAttributeName}', `}this.paramsFor(${modelClassName}))
@@ -47,6 +48,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
47
48
  // status: 201,
48
49
  // tags: openApiTags,
49
50
  // description: '<tbd>',
51
+ // fastJsonStringify: true,
50
52
  // })
51
53
  public async create() {
52
54
  }`;
@@ -59,6 +61,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
59
61
  description: 'Paginated index of ${pluralize(modelClassName)}',
60
62
  cursorPaginate: true,
61
63
  serializerKey: '${forAdmin ? 'adminSummary' : 'summary'}',
64
+ fastJsonStringify: true,
62
65
  })
63
66
  public async index() {
64
67
  // const ${pluralizedModelAttributeName} = await ${loadQueryBase}
@@ -74,6 +77,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
74
77
  // description: '<tbd>',
75
78
  // many: true,
76
79
  // serializerKey: '${forAdmin ? 'adminSummary' : 'summary'}',
80
+ // fastJsonStringify: true,
77
81
  // })
78
82
  public async index() {
79
83
  }`;
@@ -84,6 +88,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
84
88
  status: 200,
85
89
  tags: openApiTags,
86
90
  description: 'Fetch ${aOrAnDreamModelName(modelClassName)}',${defaultOpenapiSerializerKeyProperty}
91
+ fastJsonStringify: true,
87
92
  })
88
93
  public async show() {
89
94
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -95,6 +100,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
95
100
  // status: 200,
96
101
  // tags: openApiTags,
97
102
  // description: '<tbd>',
103
+ // fastJsonStringify: true,
98
104
  // })
99
105
  public async show() {
100
106
  }`;
@@ -105,6 +111,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
105
111
  status: 204,
106
112
  tags: openApiTags,
107
113
  description: 'Update ${aOrAnDreamModelName(modelClassName)}',
114
+ fastJsonStringify: true,
108
115
  })
109
116
  public async update() {
110
117
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -117,6 +124,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
117
124
  // status: 204,
118
125
  // tags: openApiTags,
119
126
  // description: '<tbd>',
127
+ // fastJsonStringify: true,
120
128
  // })
121
129
  public async update() {
122
130
  }`;
@@ -127,6 +135,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
127
135
  status: 204,
128
136
  tags: openApiTags,
129
137
  description: 'Destroy ${aOrAnDreamModelName(modelClassName)}',
138
+ fastJsonStringify: true,
130
139
  })
131
140
  public async destroy() {
132
141
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -139,6 +148,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
139
148
  // status: 204,
140
149
  // tags: openApiTags,
141
150
  // description: '<tbd>',
151
+ // fastJsonStringify: true,
142
152
  // })
143
153
  public async destroy() {
144
154
  }`;
@@ -149,6 +159,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
149
159
  status: 200,
150
160
  tags: openApiTags,
151
161
  description: 'Fetch ${aOrAnDreamModelName(modelClassName)}',
162
+ fastJsonStringify: true,
152
163
  })
153
164
  public async ${methodName}() {
154
165
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -160,6 +171,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
160
171
  // status: 200,
161
172
  // tags: openApiTags,
162
173
  // description: '<tbd>',
174
+ // fastJsonStringify: true,
163
175
  // })
164
176
  public async ${methodName}() {
165
177
  }`;
@@ -197,7 +197,7 @@ export default class SerializerOpenapiRenderer {
197
197
  accumulator[outputAttributeName] = {
198
198
  type: 'object',
199
199
  additionalProperties: true,
200
- description: `Serializer ${this.serializer['globalName']} includes a rendersOne "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or disableFastJson on the endpoint.`,
200
+ description: `Serializer ${this.serializer['globalName']} includes a rendersOne "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or fastJsonStringify on the endpoint.`,
201
201
  };
202
202
  return accumulator;
203
203
  }
@@ -229,7 +229,7 @@ export default class SerializerOpenapiRenderer {
229
229
  accumulator[outputAttributeName] = {
230
230
  type: 'array',
231
231
  items: { type: 'object', additionalProperties: true },
232
- description: `Serializer ${this.serializer['globalName']} includes a rendersMany "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or disableFastJson on the endpoint.`,
232
+ description: `Serializer ${this.serializer['globalName']} includes a rendersMany "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or fastJsonStringify on the endpoint.`,
233
233
  };
234
234
  return accumulator;
235
235
  }
@@ -40,7 +40,7 @@ export default class OpenapiEndpointRenderer {
40
40
  omitDefaultResponses;
41
41
  defaultResponse;
42
42
  validate = undefined;
43
- disableFastJson = false;
43
+ fastJsonStringify = false;
44
44
  /**
45
45
  * instantiates a new OpenapiEndpointRenderer.
46
46
  * This class is used by the `@Openapi` decorator
@@ -55,7 +55,7 @@ export default class OpenapiEndpointRenderer {
55
55
  * const json = JSON.encode(openapiJsonContents, null, 2)
56
56
  * ```
57
57
  */
58
- constructor(dreamsOrSerializers, controllerClass, action, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, disableFastJson, } = {}) {
58
+ constructor(dreamsOrSerializers, controllerClass, action, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, fastJsonStringify, } = {}) {
59
59
  this.dreamsOrSerializers = dreamsOrSerializers;
60
60
  this.controllerClass = controllerClass;
61
61
  this.action = action;
@@ -84,7 +84,7 @@ export default class OpenapiEndpointRenderer {
84
84
  : omitDefaultResponses;
85
85
  this.defaultResponse = defaultResponse;
86
86
  this.validate = validate;
87
- this.disableFastJson = disableFastJson ?? false;
87
+ this.fastJsonStringify = fastJsonStringify ?? false;
88
88
  }
89
89
  /**
90
90
  * @internal
@@ -607,16 +607,14 @@ export default class PsychicController {
607
607
  if (this._responseSent)
608
608
  return;
609
609
  this.ctx.status = statusCode;
610
- // Try to use fast-json-stringify if an OpenAPI schema exists for this endpoint
611
- const stringifyFn = this.currentOpenapiRenderer?.['disableFastJson']
612
- ? undefined
613
- : this.getFastJsonStringifyFunction(statusCode);
610
+ const stringifyFn = this.currentOpenapiRenderer?.['fastJsonStringify']
611
+ ? this.getFastJsonStringifyFunction(statusCode)
612
+ : undefined;
614
613
  if (stringifyFn) {
615
614
  this.ctx.type = 'application/json';
616
615
  this.ctx.body = stringifyFn(data);
617
616
  }
618
617
  else {
619
- // Fall back to toJson() if no OpenAPI schema exists
620
618
  this.ctx.type = 'json';
621
619
  this.ctx.body = toJson(data);
622
620
  }
@@ -35,6 +35,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
35
35
  status: 201,
36
36
  tags: openApiTags,
37
37
  description: 'Create ${aOrAnDreamModelName(modelClassName)}',${defaultOpenapiSerializerKeyProperty}
38
+ fastJsonStringify: true,
38
39
  })
39
40
  public async create() {
40
41
  // let ${modelAttributeName} = await ${forAdmin ? `${modelClassName}.create(` : `this.${owningModelProperty}.createAssociation('${pluralizedModelAttributeName}', `}this.paramsFor(${modelClassName}))
@@ -47,6 +48,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
47
48
  // status: 201,
48
49
  // tags: openApiTags,
49
50
  // description: '<tbd>',
51
+ // fastJsonStringify: true,
50
52
  // })
51
53
  public async create() {
52
54
  }`;
@@ -59,6 +61,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
59
61
  description: 'Paginated index of ${pluralize(modelClassName)}',
60
62
  cursorPaginate: true,
61
63
  serializerKey: '${forAdmin ? 'adminSummary' : 'summary'}',
64
+ fastJsonStringify: true,
62
65
  })
63
66
  public async index() {
64
67
  // const ${pluralizedModelAttributeName} = await ${loadQueryBase}
@@ -74,6 +77,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
74
77
  // description: '<tbd>',
75
78
  // many: true,
76
79
  // serializerKey: '${forAdmin ? 'adminSummary' : 'summary'}',
80
+ // fastJsonStringify: true,
77
81
  // })
78
82
  public async index() {
79
83
  }`;
@@ -84,6 +88,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
84
88
  status: 200,
85
89
  tags: openApiTags,
86
90
  description: 'Fetch ${aOrAnDreamModelName(modelClassName)}',${defaultOpenapiSerializerKeyProperty}
91
+ fastJsonStringify: true,
87
92
  })
88
93
  public async show() {
89
94
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -95,6 +100,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
95
100
  // status: 200,
96
101
  // tags: openApiTags,
97
102
  // description: '<tbd>',
103
+ // fastJsonStringify: true,
98
104
  // })
99
105
  public async show() {
100
106
  }`;
@@ -105,6 +111,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
105
111
  status: 204,
106
112
  tags: openApiTags,
107
113
  description: 'Update ${aOrAnDreamModelName(modelClassName)}',
114
+ fastJsonStringify: true,
108
115
  })
109
116
  public async update() {
110
117
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -117,6 +124,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
117
124
  // status: 204,
118
125
  // tags: openApiTags,
119
126
  // description: '<tbd>',
127
+ // fastJsonStringify: true,
120
128
  // })
121
129
  public async update() {
122
130
  }`;
@@ -127,6 +135,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
127
135
  status: 204,
128
136
  tags: openApiTags,
129
137
  description: 'Destroy ${aOrAnDreamModelName(modelClassName)}',
138
+ fastJsonStringify: true,
130
139
  })
131
140
  public async destroy() {
132
141
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -139,6 +148,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
139
148
  // status: 204,
140
149
  // tags: openApiTags,
141
150
  // description: '<tbd>',
151
+ // fastJsonStringify: true,
142
152
  // })
143
153
  public async destroy() {
144
154
  }`;
@@ -149,6 +159,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
149
159
  status: 200,
150
160
  tags: openApiTags,
151
161
  description: 'Fetch ${aOrAnDreamModelName(modelClassName)}',
162
+ fastJsonStringify: true,
152
163
  })
153
164
  public async ${methodName}() {
154
165
  // const ${modelAttributeName} = await this.${modelAttributeName}()
@@ -160,6 +171,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
160
171
  // status: 200,
161
172
  // tags: openApiTags,
162
173
  // description: '<tbd>',
174
+ // fastJsonStringify: true,
163
175
  // })
164
176
  public async ${methodName}() {
165
177
  }`;
@@ -197,7 +197,7 @@ export default class SerializerOpenapiRenderer {
197
197
  accumulator[outputAttributeName] = {
198
198
  type: 'object',
199
199
  additionalProperties: true,
200
- description: `Serializer ${this.serializer['globalName']} includes a rendersOne "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or disableFastJson on the endpoint.`,
200
+ description: `Serializer ${this.serializer['globalName']} includes a rendersOne "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or fastJsonStringify on the endpoint.`,
201
201
  };
202
202
  return accumulator;
203
203
  }
@@ -229,7 +229,7 @@ export default class SerializerOpenapiRenderer {
229
229
  accumulator[outputAttributeName] = {
230
230
  type: 'array',
231
231
  items: { type: 'object', additionalProperties: true },
232
- description: `Serializer ${this.serializer['globalName']} includes a rendersMany "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or disableFastJson on the endpoint.`,
232
+ description: `Serializer ${this.serializer['globalName']} includes a rendersMany "${outputAttributeName}" with an OpenAPI shape that cannot be defined. This will break fast-json-stringify. Define the OpenAPI shape or fastJsonStringify on the endpoint.`,
233
233
  };
234
234
  return accumulator;
235
235
  }
@@ -40,7 +40,7 @@ export default class OpenapiEndpointRenderer {
40
40
  omitDefaultResponses;
41
41
  defaultResponse;
42
42
  validate = undefined;
43
- disableFastJson = false;
43
+ fastJsonStringify = false;
44
44
  /**
45
45
  * instantiates a new OpenapiEndpointRenderer.
46
46
  * This class is used by the `@Openapi` decorator
@@ -55,7 +55,7 @@ export default class OpenapiEndpointRenderer {
55
55
  * const json = JSON.encode(openapiJsonContents, null, 2)
56
56
  * ```
57
57
  */
58
- constructor(dreamsOrSerializers, controllerClass, action, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, disableFastJson, } = {}) {
58
+ constructor(dreamsOrSerializers, controllerClass, action, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, fastJsonStringify, } = {}) {
59
59
  this.dreamsOrSerializers = dreamsOrSerializers;
60
60
  this.controllerClass = controllerClass;
61
61
  this.action = action;
@@ -84,7 +84,7 @@ export default class OpenapiEndpointRenderer {
84
84
  : omitDefaultResponses;
85
85
  this.defaultResponse = defaultResponse;
86
86
  this.validate = validate;
87
- this.disableFastJson = disableFastJson ?? false;
87
+ this.fastJsonStringify = fastJsonStringify ?? false;
88
88
  }
89
89
  /**
90
90
  * @internal
@@ -46,7 +46,7 @@ export default class OpenapiEndpointRenderer<DreamsOrSerializersOrViewModels ext
46
46
  private omitDefaultResponses;
47
47
  private defaultResponse;
48
48
  private validate;
49
- private disableFastJson;
49
+ private fastJsonStringify;
50
50
  /**
51
51
  * instantiates a new OpenapiEndpointRenderer.
52
52
  * This class is used by the `@Openapi` decorator
@@ -61,7 +61,7 @@ export default class OpenapiEndpointRenderer<DreamsOrSerializersOrViewModels ext
61
61
  * const json = JSON.encode(openapiJsonContents, null, 2)
62
62
  * ```
63
63
  */
64
- constructor(dreamsOrSerializers: DreamsOrSerializersOrViewModels | null, controllerClass: typeof PsychicController, action: string, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, disableFastJson, }?: OpenapiEndpointRendererOpts<DreamsOrSerializersOrViewModels, ForOption>);
64
+ constructor(dreamsOrSerializers: DreamsOrSerializersOrViewModels | null, controllerClass: typeof PsychicController, action: string, { requestBody, headers, many, paginate, cursorPaginate, scrollPaginate, query, responses, serializerKey, status, tags, security, pathParams, description, summary, omitDefaultHeaders, omitDefaultResponses, defaultResponse, validate, fastJsonStringify, }?: OpenapiEndpointRendererOpts<DreamsOrSerializersOrViewModels, ForOption>);
65
65
  /**
66
66
  * @internal
67
67
  *
@@ -614,9 +614,9 @@ export interface OpenapiEndpointRendererOpts<I extends DreamSerializable | Dream
614
614
  validate?: OpenapiValidateOption | undefined;
615
615
  /**
616
616
  * The OpenAPI response body automatically enables fast-json-stringify.
617
- * If you want to render via JSON.stringify instead, set `disableFastJson` to `true`.
617
+ * If you want to render via JSON.stringify instead, set `fastJsonStringify` to `true`.
618
618
  */
619
- disableFastJson?: boolean;
619
+ fastJsonStringify?: boolean;
620
620
  }
621
621
  export type OpenapiValidateOption = {
622
622
  /**
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": "3.0.0-alpha.3",
5
+ "version": "3.0.0-alpha.4",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",