@tstdl/base 0.90.31 → 0.90.32

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.
@@ -186,17 +186,25 @@ let ApiGateway = class ApiGateway {
186
186
  getToken: async () => this.requestTokenProvider.getToken(requestContext)
187
187
  };
188
188
  const result = await context.endpoint.implementation(requestContext);
189
- if (result instanceof HttpServerResponse) {
190
- return result;
189
+ const response = (result instanceof HttpServerResponse)
190
+ ? result
191
+ : new HttpServerResponse({
192
+ body: isUint8Array(result) ? { buffer: result }
193
+ : isBlob(result) ? { stream: result.stream() }
194
+ : isReadableStream(result) ? { stream: result }
195
+ : (result instanceof ServerSentEventsSource) ? { events: result }
196
+ : (context.endpoint.definition.result == String) ? { text: result }
197
+ : { json: result }
198
+ });
199
+ if (isUndefined(response.headers.contentType)) {
200
+ response.headers.contentType =
201
+ (isDefined(response.body?.json)) ? 'application/json; charset=utf-8'
202
+ : (isDefined(response.body?.text)) ? 'text/plain; charset=utf-8'
203
+ : (isDefined(response.body?.buffer)) ? 'application/octet-stream'
204
+ : (isDefined(response.body?.stream)) ? 'application/octet-stream'
205
+ : (isDefined(response.body?.events)) ? 'text/event-stream'
206
+ : undefined;
191
207
  }
192
- const response = new HttpServerResponse({
193
- body: isUint8Array(result) ? { buffer: result }
194
- : isBlob(result) ? { stream: result.stream() }
195
- : isReadableStream(result) ? { stream: result }
196
- : (result instanceof ServerSentEventsSource) ? { events: result }
197
- : (context.endpoint.definition.result == String) ? { text: result }
198
- : { json: result }
199
- });
200
208
  return response;
201
209
  }
202
210
  async getBody(request, options, schema) {
@@ -141,21 +141,6 @@ function getResponder(httpResponse) {
141
141
  return respond;
142
142
  }
143
143
  function writeHeaders(response, httpResponse) {
144
- if (isDefined(response.body?.json)) {
145
- httpResponse.setHeader('Content-Type', 'application/json; charset=utf-8');
146
- }
147
- else if (isDefined(response.body?.text)) {
148
- httpResponse.setHeader('Content-Type', 'text/plain; charset=utf-8');
149
- }
150
- else if (isDefined(response.body?.buffer)) {
151
- httpResponse.setHeader('Content-Type', 'application/octet-stream');
152
- }
153
- else if (isDefined(response.body?.stream)) {
154
- httpResponse.setHeader('Content-Type', 'application/octet-stream');
155
- }
156
- else if (isDefined(response.body?.events)) {
157
- httpResponse.setHeader('Content-Type', 'text/event-stream');
158
- }
159
144
  for (const [name, value] of response.headers.normalizedEntries()) {
160
145
  httpResponse.setHeader(name, value);
161
146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.31",
3
+ "version": "0.90.32",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -149,7 +149,7 @@
149
149
  "mongodb": "^6.2",
150
150
  "nodemailer": "^6.9",
151
151
  "playwright": "^1.39",
152
- "preact": "^10.18",
152
+ "preact": "^10.19",
153
153
  "preact-render-to-string": "^6.3",
154
154
  "undici": "^5.27",
155
155
  "urlpattern-polyfill": "^9.0"
@@ -1,5 +1,5 @@
1
1
  import type { Decorator } from '../../reflection/index.js';
2
2
  import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
3
3
  export type LiteralOptions = ValueSchemaOptions;
4
- export declare function literal<T>(value: T, options?: LiteralOptions): ValueSchema<T>;
4
+ export declare function literal<const T>(value: T, options?: LiteralOptions): ValueSchema<T>;
5
5
  export declare function Literal(value: any): Decorator<'property' | 'accessor'>;