@dooboostore/simple-boot-http-server 1.0.30 → 1.0.31

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.
Files changed (40) hide show
  1. package/README.md +58 -1
  2. package/dist/cjs/SimpleBootHttpServer.js +6 -3
  3. package/dist/cjs/SimpleBootHttpServer.js.map +2 -2
  4. package/dist/cjs/codes/Mimes.js +2 -0
  5. package/dist/cjs/codes/Mimes.js.map +2 -2
  6. package/dist/cjs/generators/ContentTypeGenerator.js +320 -0
  7. package/dist/cjs/generators/ContentTypeGenerator.js.map +7 -0
  8. package/dist/cjs/index.js +2 -0
  9. package/dist/cjs/index.js.map +2 -2
  10. package/dist/cjs/models/RequestResponse.js +3 -2
  11. package/dist/cjs/models/RequestResponse.js.map +2 -2
  12. package/dist/esm/SimpleBootHttpServer.js +6 -3
  13. package/dist/esm/SimpleBootHttpServer.js.map +2 -2
  14. package/dist/esm/codes/Mimes.js +2 -0
  15. package/dist/esm/codes/Mimes.js.map +2 -2
  16. package/dist/esm/generators/ContentTypeGenerator.js +287 -0
  17. package/dist/esm/generators/ContentTypeGenerator.js.map +7 -0
  18. package/dist/esm/index.js +1 -0
  19. package/dist/esm/index.js.map +2 -2
  20. package/dist/esm/models/RequestResponse.js +3 -2
  21. package/dist/esm/models/RequestResponse.js.map +2 -2
  22. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +625 -5218
  23. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
  24. package/dist/types/SimpleBootHttpServer.d.ts.map +1 -1
  25. package/dist/types/codes/Mimes.d.ts +2 -0
  26. package/dist/types/codes/Mimes.d.ts.map +1 -1
  27. package/dist/types/generators/ContentTypeGenerator.d.ts +172 -0
  28. package/dist/types/generators/ContentTypeGenerator.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/models/RequestResponse.d.ts +4 -1
  32. package/dist/types/models/RequestResponse.d.ts.map +1 -1
  33. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +625 -5218
  34. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
  35. package/package.json +4 -4
  36. package/src/SimpleBootHttpServer.ts +7 -3
  37. package/src/codes/Mimes.ts +2 -0
  38. package/src/generators/ContentTypeGenerator.ts +431 -0
  39. package/src/index.ts +1 -0
  40. package/src/models/RequestResponse.ts +3 -2
package/README.md CHANGED
@@ -15,6 +15,7 @@
15
15
  - **Middleware & Filters**: Systematically separate pre/post-processing logic (CORS, caching, auth, logging, OpenAPI generation, etc.) through the `Filter` interface.
16
16
  - **Powerful Exception Handling**: Leverage AOP-based `GlobalAdvice` to isolate business logic from error handling logic.
17
17
  - **Generator Streaming**: Return a (async) generator and each yielded value is written to the body immediately after the headers — SSE with no plumbing.
18
+ - **Content-Type Streams**: `ContentTypeGenerator` adds the wire format for SSE, MJPEG/multipart, NDJSON, JSON Text Sequences, streamed JSON arrays, CSV, and text lines — pull from your generator or `push()` into a channel.
18
19
  - **Manual Response Streaming**: Opt out of the automatic response pipeline with `res: 'manual'` to stream Server-Sent Events, NDJSON, or any long-lived response directly from the injected `ServerResponse`.
19
20
  - **Real-time WebSocket Protocol**: A topic-based pub/sub protocol over a single socket — subscribe/unsubscribe, request/response, *and* server-initiated events the server can `await` a client reply for — with automatic reconnection and re-subscription.
20
21
  - **Binary File Transfer over WebSocket**: `Buffer`/`File` values anywhere in a message are detected automatically and shipped as raw bytes in a compact binary frame (length header + JSON metadata + concatenated buffers) instead of being bloated with base64 — no separate upload endpoint needed.
@@ -134,7 +135,7 @@ async *events(signal: AbortSignal) {
134
135
  try {
135
136
  while (!signal.aborted) {
136
137
  const msg = await nextMessage(signal); // rejects as soon as the client disconnects
137
- yield `data: ${JSON.stringify(msg)}\n\n`; // SSE framing is up to you
138
+ yield `data: ${JSON.stringify(msg)}\n\n`; // SSE framing is up to you — or let ContentTypeGenerator do it (below)
138
139
  }
139
140
  } finally {
140
141
  // runs when the client disconnects — release subscriptions here
@@ -144,6 +145,62 @@ async *events(signal: AbortSignal) {
144
145
 
145
146
  Every handler can take an `AbortSignal` parameter (injected by type, like `ReqJsonBody`). It aborts when the client disconnects before the response finishes. Pass it to anything that waits (`fetch`, `timers/promises`, `events.once`, ...) — a generator suspended on an `await` isn't stopped by `return()` until its next `yield`, so the signal is what releases an event wait. Errors thrown after the client disconnected (e.g. that `AbortError`) are swallowed.
146
147
 
148
+ ### Content-Type Streams (`ContentTypeGenerator`)
149
+ Yielding raw chunks means writing the wire format yourself — SSE `data:` lines, multipart boundaries + `Content-Length`, NDJSON newlines, CSV escaping. `ContentTypeGenerator` does that part: you hand it the **content** and get back a stream that carries its own `contentType` (boundary included) and `compress` flag. Return it from a handler — no `contentType` needed in the decorator (if one is set, the stream's wins; other `res.header`s still apply).
150
+
151
+ Two ways to feed it:
152
+
153
+ - **pull** — wrap a generator you loop in yourself: `CTG.ndjson(rows())`. Client disconnect calls `return()` on your generator, so its `finally` runs.
154
+ - **push** — `CTG.ndjson.channel({ signal })` gives a stream you `push()` into from callbacks/events. It queues values and yields them; `close()` ends the response after the queue drains, and `onClose(fn)` runs once on close, abort, or client disconnect (even while idle — the place to unsubscribe).
155
+
156
+ ```typescript
157
+ import { ContentTypeGenerator as CTG } from '@dooboostore/simple-boot-http-server';
158
+
159
+ // pull: MJPEG from a generator of frames (Content-Type / Content-Length per part are filled in)
160
+ @Route({ path: '/camera.mjpeg' })
161
+ @GET
162
+ camera(signal: AbortSignal) {
163
+ return CTG.multipartReplace(this.frames(signal), { boundary: 'frame' });
164
+ }
165
+
166
+ // push: job progress as SSE, released when the client leaves
167
+ @Route({ path: '/jobs/progress' })
168
+ @GET
169
+ progress(signal: AbortSignal) {
170
+ const out = CTG.sse.channel({ signal, heartbeatMs: 15000 });
171
+ const onProgress = (p: number) => out.push({ event: 'progress', data: { p } });
172
+ job.on('progress', onProgress);
173
+ job.once('done', () => out.close());
174
+ out.onClose(() => job.off('progress', onProgress));
175
+ return out;
176
+ }
177
+
178
+ // CSV download that opens in Excel without breaking Korean text
179
+ @Route({ path: '/rows.csv' })
180
+ @GET({ res: { header: { 'Content-Disposition': 'attachment; filename="rows.csv"' } } })
181
+ rows() {
182
+ return CTG.csv(db.cursor(), { columns: ['name', 'memo'], bom: true });
183
+ }
184
+ ```
185
+
186
+ | pull / push | Content-Type | You give | Framing added |
187
+ |---|---|---|---|
188
+ | `sse(src, { heartbeatMs? })` / `sse.channel()` | `text/event-stream` | `string` or `{ data, event, id, retry, comment }` | `data:` per line (multi-line safe), field lines, blank line; `: ping` heartbeat while idle |
189
+ | `multipartReplace(src, { boundary?, type? })` / `.channel()` | `multipart/x-mixed-replace; boundary=…` | `Buffer` / `Uint8Array` / `string` / `{ body, type?, name?, headers? }` | `--boundary`, `Content-Type`, `Content-Length` (bytes), CRLFs. **Not gzipped** (frames are already compressed) |
190
+ | `multipartMixed(src, { boundary?, type? })` / `.channel()` | `multipart/mixed; boundary=…` | same as above | same, plus `--boundary--` at the end |
191
+ | `ndjson(src)` / `.channel()` | `application/x-ndjson` | any JSON value | `JSON + \n` |
192
+ | `jsonSeq(src)` / `.channel()` | `application/json-seq` (RFC 7464) | any JSON value | `\x1e JSON \n` |
193
+ | `jsonArray(src)` / `.channel()` | `application/json` | any JSON value | `[`, `,` between items, `]` — the client just calls `res.json()` |
194
+ | `csv(src, { columns?, bom? })` / `.channel()` | `text/csv; charset=utf-8` | row arrays, or objects mapped by `columns` | RFC 4180 quoting, CRLF, header row from `columns`, optional UTF-8 BOM |
195
+ | `text(src)` / `.channel()` | `text/plain; charset=utf-8` | strings (others as JSON) | `\n` per item |
196
+
197
+ - `src` is any iterable or async iterable (array, `function*`, `async function*`).
198
+ - A part's MIME type is resolved as the part's `type` > `mime-types` lookup of its `name` > then for string bodies the stream's `type` option or `text/plain; charset=utf-8`, for bytes sniffing (JPEG/PNG/GIF/WEBP) > the `type` option > `application/octet-stream`.
199
+ - A missing `boundary` is randomized; an invalid one (RFC 2046) throws when the stream is created.
200
+ - Channel options: `signal` (closes on abort), `keep: 'queue'` (default, every value in order, up to `max` = 1000, oldest dropped) or `keep: 'latest'` (only the newest pending value — video frames).
201
+ - `jsonArray` is valid JSON only once it finishes; for streams that may be cut off, prefer `ndjson` / `jsonSeq`.
202
+ - The per-item formatters are exported too: `sseChunk`, `ssePing`, `multipartPart`, `multipartEnd`, `partType`, `ndjsonLine`, `jsonSeqRecord`, `csvCell`, `csvRow`, `textLine`, `boundary`, and `isStream`.
203
+
147
204
  ### Manual Response Streaming (SSE / NDJSON)
148
205
  By default, a route's return value is automatically serialized and written as a single response. Set `res: 'manual'` to skip that entirely and take direct control of the injected `ServerResponse` — the request handler's promise simply stays pending until you're done, so nothing else writes to the response underneath you.
149
206
 
@@ -45,6 +45,7 @@ var import_simple_boot7 = require("@dooboostore/simple-boot");
45
45
  var import_url = require("url");
46
46
  var import_HttpMethod = require("./codes/HttpMethod");
47
47
  var import_SessionManager = require("./session/SessionManager");
48
+ var import_ContentTypeGenerator = require("./generators/ContentTypeGenerator");
48
49
  var import_ReqSearchParamsObj = require("./models/datas/path/ReqSearchParamsObj");
49
50
  var import_ReqPathData = require("./models/datas/path/ReqPathData");
50
51
  class SimpleBootHttpServer extends import_simple_boot.SimpleApplication {
@@ -301,13 +302,15 @@ class SimpleBootHttpServer extends import_simple_boot.SimpleApplication {
301
302
  const resConfig = it.config?.res;
302
303
  if (resConfig === "manual") {
303
304
  } else if (import_core2.ValidUtils.isGenerator(data) || import_core2.ValidUtils.isAsyncGenerator(data)) {
305
+ const stream = import_ContentTypeGenerator.ContentTypeGenerator.isStream(data) ? data : void 0;
304
306
  const headers = resConfig?.header ?? {};
305
- if (resConfig?.contentType) {
306
- headers[import_HttpHeaders.HttpHeaders.ContentType] = resConfig.contentType;
307
+ const contentType = stream?.contentType ?? resConfig?.contentType;
308
+ if (contentType) {
309
+ headers[import_HttpHeaders.HttpHeaders.ContentType] = contentType;
307
310
  }
308
311
  rr.resSetHeaders(headers);
309
312
  rr.resSetStatusCode(resConfig?.status ?? import_HttpStatus.HttpStatus.Ok);
310
- await rr.resStream(data);
313
+ await rr.resStream(data, { compress: stream?.compress });
311
314
  } else {
312
315
  if (it.config?.resolver) {
313
316
  const execute = typeof it.config.resolver === "function" ? this.simstanceManager.getOrNewSim({ target: it.config.resolver }) : it.config.resolver;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/SimpleBootHttpServer.ts"],
4
- "sourcesContent": ["import {SimpleApplication} from '@dooboostore/simple-boot';\nimport {HttpServerOption} from './option/HttpServerOption';\nimport {ConstructorType} from '@dooboostore/core';\nimport {IncomingMessage, Server as HttpServer, ServerResponse} from 'http'\nimport {Server as HttpsServer} from 'https'; // Add HTTPS support\nimport {WebSocketServer, WebSocket} from 'ws';\nimport {RequestResponse} from './models/RequestResponse';\nimport {getUrlMapping, getUrlMappings, SaveMappingConfig, UrlMappingSituationType} from './decorators/MethodMapping';\nimport {HttpStatus} from './codes/HttpStatus';\nimport {HttpHeaders} from './codes/HttpHeaders';\nimport {Mimes} from './codes/Mimes';\nimport {Filter} from './filters/Filter';\nimport {ExceptionHandlerSituationType, targetExceptionHandler} from '@dooboostore/simple-boot';\nimport {getInject, SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot';\nimport {EndPoint} from './endpoints/EndPoint';\nimport {ReflectUtils, ValidUtils} from '@dooboostore/core';\nimport {ReqFormUrlBody} from './models/datas/body/ReqFormUrlBody';\nimport {ReqJsonBody} from './models/datas/body/ReqJsonBody';\nimport {ReqHeader} from './models/datas/ReqHeader';\nimport {RouterModule} from '@dooboostore/simple-boot';\nimport {ReqMultipartFormBody} from './models/datas/body/ReqMultipartFormBody';\nimport {execValidationInValid, getValidIndex} from '@dooboostore/simple-boot';\nimport {ValidException} from '@dooboostore/simple-boot';\nimport {HttpError} from './errors/HttpError';\nimport {getRoute} from '@dooboostore/simple-boot';\nimport {OnInit} from './lifecycle/OnInit';\nimport {URLSearchParams} from 'url';\nimport {HttpMethod} from './codes/HttpMethod';\nimport {SessionManager} from './session/SessionManager';\nimport {InjectSituationType} from './inject/InjectSituationType';\nimport {ReqSearchParamsObj} from \"./models/datas/path/ReqSearchParamsObj\";\nimport {SimConfig} from '@dooboostore/simple-boot';\nimport {ReqPathData} from './models/datas/path/ReqPathData';\nimport {WebSocketEndPoint} from './endpoints/WebSocketEndPoint';\n\nexport class SimpleBootHttpServer extends SimpleApplication {\n public server?: HttpServer | HttpsServer;\n private sessionManager: SessionManager;\n private webSocketClients = new Map<WebSocket, { request: IncomingMessage }>();\n\n constructor(public option: HttpServerOption = new HttpServerOption()) {\n super(option);\n this.sessionManager = new SessionManager(this.option);\n }\n\n\n public run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>) {\n otherInstanceSim ??= new Map<ConstructorType<any> | Function | SimConfig | symbol, any>();\n otherInstanceSim.set(SimpleBootHttpServer, this);\n super.run(otherInstanceSim);\n const targets = [...this.option.closeEndPoints ?? [], ...this.option.errorEndPoints ?? [], ...this.option.requestEndPoints ?? [], ...(this.option.filters ?? []).map(it=>it.filter)];\n Promise.all(targets.map(it => (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it as ConstructorType<any>}) : it) as OnInit).map(it => it.onInit(this))).then(it => {\n this.startServer();\n });\n return this;\n }\n\n private startServer() {\n\n // const a = this.option.serverOption as HttpsServerOption;\n // this.option.serverOption?.\n\n if (this.option.serverOption && 'key' in this.option.serverOption && 'cert' in this.option.serverOption) {\n this.server = new HttpsServer(this.option.serverOption);\n const httpServer = new HttpServer();\n httpServer.on('request', (req: IncomingMessage, res: ServerResponse) => {\n res.writeHead(301, {Location: `https://${req.headers.host}${req.url}`});\n res.end();\n });\n httpServer.listen(80, this.option.listen.hostname, () => {\n console.log('HTTP redirect server running on port 80');\n });\n } else if (this.option.serverOption) {\n this.server = new HttpServer(this.option.serverOption);\n } else {\n this.server = new HttpServer();\n }\n // const thisRef = this;\n this.server.on('request', async (req: IncomingMessage, res: ServerResponse) => {\n // console.log('request', req.url);\n const transactionManager = this.option.transactionManagerFactory ? await this.option.transactionManagerFactory() : undefined;\n res.on('close', async () => {\n if (this.option.closeEndPoints) {\n for (const it of this.option.closeEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;\n const endPoint = execute?.endPoint(rr, this);\n if (endPoint instanceof Promise) {\n await endPoint;\n }\n } catch (e) {\n }\n }\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n res.on('error', async () => {\n if (this.option.errorEndPoints) {\n for (const it of this.option.errorEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;\n const endPoint = execute?.endPoint(rr, this);\n if (endPoint instanceof Promise) {\n await endPoint;\n }\n } catch (e) {\n }\n }\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n\n const rr = new RequestResponse(req, res, {sessionManager: this.sessionManager, option: this.option});\n /*\n default setting first\n */\n rr.resSetHeader(HttpHeaders.Server, 'simple-boot-http-server');\n const cookie = rr.reqCookieGet(this.option.sessionOption.key);\n if (!cookie) {\n const session = await this.sessionManager.session();\n\n const cookieParts: string[] = [];\n cookieParts.push(`${this.option.sessionOption.key}=${session.uuid}`);\n cookieParts.push(`Path=${this.option.sessionOption.path}`);\n if (this.option.sessionOption.httpOnly) cookieParts.push('HttpOnly');\n if (this.option.sessionOption.secure) cookieParts.push('Secure');\n if (this.option.sessionOption.sameSite != null && this.option.sessionOption.sameSite) cookieParts.push(`SameSite=${this.option.sessionOption.sameSite}`);\n const maxAge = (this.option.sessionOption as any).maxAge ?? (this.sessionManager.sessionOption)?.maxAge;\n if (maxAge != null) cookieParts.push(`Max-Age=${maxAge}`);\n rr.resSetHeader(HttpHeaders.SetCookie, cookieParts.join('; '));\n }\n\n const otherStorage = new Map<ConstructorType<any>, any>();\n otherStorage.set(RequestResponse, rr);\n otherStorage.set(IncomingMessage, req);\n otherStorage.set(ServerResponse, res);\n // \uD074\uB77C\uC774\uC5B8\uD2B8\uAC00 \uC751\uB2F5 \uC644\uB8CC \uC804\uC5D0 \uB04A\uC73C\uBA74 abort. \uD578\uB4E4\uB7EC\uB294 \uD30C\uB77C\uBBF8\uD130 \uD0C0\uC785 AbortSignal \uB85C \uC8FC\uC785\uBC1B\uC544\n // fetch/timers/events.once \uB4F1\uC5D0 \uB118\uAE30\uBA74 \uB300\uAE30 \uC911\uC774\uC5B4\uB3C4 \uBC14\uB85C \uD480\uB9B0\uB2E4 (\uC81C\uB108\uB808\uC774\uD130 \uC2A4\uD2B8\uB9BC\uC758 \uC774\uBCA4\uD2B8 \uB300\uAE30 \uB204\uC218 \uBC29\uC9C0)\n const abortController = new AbortController();\n res.once('close', () => {\n if (!res.writableFinished) abortController.abort();\n });\n otherStorage.set(AbortSignal, abortController.signal);\n try {\n transactionManager?.try();\n if (this.option.requestEndPoints) {\n for (const it of this.option.requestEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim<EndPoint>({target: it}) : it) as EndPoint;\n execute?.endPoint(rr, this);\n } catch (e) {\n }\n }\n }\n\n const filter = {\n carrier: new Map<string, any>(),\n filters: [] as { filter: Filter, sw: boolean }[]\n };\n for (let i = 0; this.option.filters && i < this.option.filters.length; i++) {\n const it = this.option.filters[i];\n\n let isSkip = false;\n if (typeof it.isSupport === 'boolean') {\n isSkip = !it.isSupport;\n } else if (typeof it.isSupport === 'object') {\n isSkip = !it.isSupport.test(rr.reqUrlPathName)\n } else if (typeof it.isSupport === 'function') {\n isSkip = !it.isSupport(rr);\n }\n if(isSkip) {\n continue;\n }\n\n let sw = true;\n const itFilter = it.filter;\n const execute = (typeof itFilter === 'function' ? this.simstanceManager.getOrNewSim({target: itFilter}) : itFilter) as Filter;\n if (execute?.proceedBefore) {\n sw = await execute.proceedBefore({rr, app: this, carrier: filter.carrier});\n filter.filters.push({filter: execute, sw});\n }\n if (!sw) {\n break;\n }\n }\n\n // body.. something..\n // \uB77C\uC6B0\uD130 \uC5C6\uC774 \uD544\uD130\uB9CC\uC73C\uB85C \uB3C4\uB294 \uC11C\uBC84(\uC608: SSR \uC804\uC6A9)\uBA74, \uC5B4\uB290 \uD544\uD130\uB3C4 \uCC98\uB9AC\uD558\uC9C0 \uC54A\uC740 \uC694\uCCAD\uC740 404 \uB85C \uB05D\uB0B8\uB2E4\n // (\uBE0C\uB77C\uC6B0\uC800\uAC00 \uC54C\uC544\uC11C \uBCF4\uB0B4\uB294 /favicon.ico, /.well-known/... \uAC19\uC740 \uAC83 \u2014 \uC608\uC804\uC5D4 'no router' \uC5D0\uB7EC\uB85C 500 + \uB85C\uADF8)\n if (!rr.resIsDone() && !this.option.rootRouter) {\n rr.resStatusCode(HttpStatus.NotFound);\n } else if (!rr.resIsDone()) {\n const routerModule = await super.routing(rr.reqIntent);\n otherStorage.set(RouterModule, routerModule);\n const moduleInstance = routerModule?.getModuleInstance?.();\n let methods: SaveMappingConfig[] = [];\n if (routerModule && moduleInstance) {\n // router \uD074\uB798\uC2A4 \uB0B4\uBD80\uC5D0\uC11C \uC120\uC5B8\uB41C Route\uC77C\uB54C\n if (routerModule.propertyKeys) {\n const map = routerModule.propertyKeys?.map((it: string | symbol) => {\n return {propertyKey: it, config: getUrlMapping(moduleInstance, it)} as SaveMappingConfig\n });\n methods.push(...(map ?? []));\n } else {\n methods.push(...(getUrlMappings(moduleInstance).filter(it => !getRoute(moduleInstance, it.propertyKey)) ?? []));\n }\n\n // options\uB85C \uC694\uCCAD\uC624\uBA74\uC740 allow\uB85C \uB123\uACE0 \uADF8\uB0E5 200\uCC98\uB9AC\uD574\uC57C\uB428.\n if (rr.reqMethod()?.toUpperCase() === HttpMethod.OPTIONS.toUpperCase()) {\n rr.resSetHeader(HttpHeaders.Allow, methods.map(it => it.config.method).join(', '));\n rr.resStatusCode(HttpStatus.Ok);\n }\n\n // method \uCC3E\uAE30\n methods = methods.filter(it => it && it.propertyKey && it.config && rr.reqMethod()?.toUpperCase() === it.config.method.toUpperCase());\n methods.sort((a, b) => {\n return ((b.config?.req?.contentType?.length ?? 0) + (b.config?.req?.accept?.length ?? 0)) - ((a.config?.req?.contentType?.length ?? 0) + (a.config?.req?.accept?.length ?? 0));\n });\n methods = methods\n .filter(it => it.config?.req?.contentType ? (!!it.config?.req?.contentType?.find(sit => rr.reqHasContentTypeHeader(sit))) : true)\n .filter(it => it.config?.req?.accept ? (!!it.config?.req?.accept?.find(sit => rr.reqHasAcceptHeader(sit))) : true);\n\n if (methods[0]) {\n const it = methods[0];\n const paramTypes = ReflectUtils.getParameterTypes(moduleInstance, it.propertyKey)\n const injects = getInject(moduleInstance, it.propertyKey);\n const validIndexs = getValidIndex(moduleInstance, it.propertyKey);\n if (injects) {\n const isPathData = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_PATH_DATA);\n const isJson = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_JSON_BODY);\n const isSearchParamsObj = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ);\n const isFormUrl = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_FORM_URL_BODY);\n // \uC6B0\uC120 \uB2E4\uC2DC \uC81C\uAC70\uD55C\uB2E4.. \uD2B8\uB79C\uC81D\uC158 \uC5B4\uB5BB\uAC8C \uD560\uC9C0 \uB2E4\uC2DC \uC0DD\uAC01\n // const isTransactionManager = injects.find(it => it.config?.situationType === InjectSituationType.TransactionManager);\n const siturationContainers = new SituationTypeContainers();\n if (isPathData) {\n let data = await routerModule.pathData\n if (isPathData.type) {\n data = Object.assign(new isPathData.type(), data);\n }\n if (validIndexs.includes(isPathData.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_PATH_DATA,\n data\n }));\n }\n if (isJson) {\n let data = await rr.reqBodyJsonData();\n if (data !== null && isJson.type) {\n data = Object.assign(new isJson.type(), data);\n }\n if (validIndexs.includes(isJson.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_JSON_BODY,\n data\n }));\n }\n if (isSearchParamsObj) {\n let data = rr.reqUrlSearchParamsObj\n if (validIndexs.includes(isSearchParamsObj.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ,\n data\n }));\n }\n if (isFormUrl) {\n let data = await rr.reqBodyFormUrlData()\n if (isFormUrl.type) {\n data = Object.assign(new isFormUrl.type(), data);\n }\n if (validIndexs.includes(isFormUrl.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({situationType: UrlMappingSituationType.REQ_FORM_URL_BODY, data}));\n }\n // \uD2B8\uB79C\uC81D\uC158 \uC6B0\uC120 \uC81C\uAC70 \uB098\uC911\uC5D0 \uC5B4\uB5BB\uAC8C \uAD6C\uD604\uD560\uC9C0 \uC0DD\uAC01..\n // if (isTransactionManager && isTransactionManager.type && transactionManager && transactionManager.hasTransaction(isTransactionManager.type)) {\n // let data = await transactionManager.getTransaction(isTransactionManager.type);\n // if (data) {\n // data = await data.try(isTransactionManager.config.argument);\n // siturationContainers.push(new SituationTypeContainer({situationType: InjectSituationType.TransactionManager, data, index: isTransactionManager.index}));\n // }\n // }\n if (siturationContainers.length) {\n otherStorage.set(SituationTypeContainers, siturationContainers);\n }\n }\n\n for (const paramType of paramTypes) {\n if (paramType === ReqFormUrlBody) {\n otherStorage.set(ReqFormUrlBody, await rr.reqBodyReqFormUrlBody())\n } else if (paramType === ReqPathData) {\n otherStorage.set(ReqPathData, routerModule.pathData)\n } else if (paramType === ReqJsonBody) {\n otherStorage.set(ReqJsonBody, await rr.reqBodyReqJsonBody())\n } else if (paramType === ReqSearchParamsObj) {\n otherStorage.set(ReqSearchParamsObj, rr.reqUrlSearchParamsObj)\n } else if (paramType === URLSearchParams) {\n otherStorage.set(URLSearchParams, rr.reqUrlSearchParams)\n } else if (paramType === ReqMultipartFormBody) {\n otherStorage.set(ReqMultipartFormBody, rr.reqBodyMultipartFormData())\n } else if (paramType === ReqHeader) {\n otherStorage.set(ReqHeader, rr.reqHeaderObj)\n }\n }\n\n // execute !!!\n let data = await this.simstanceManager.executeBindParameterSimPromise({\n target: moduleInstance,\n targetKey: it.propertyKey\n }, otherStorage);\n /*\n \uC5EC\uAE30\uC5D0\uC11C \uC815\uD574\uC9C4 \uD0C0\uC785 \uB9AC\uD134\uC5D0 \uB530\uB978 \uC870\uCE58\n ...\n */\n const resConfig = it.config?.res;\n if (resConfig === 'manual') {\n // \uD578\uB4E4\uB7EC\uAC00 ServerResponse\uB97C \uC9C1\uC811 \uC8FC\uC785\uBC1B\uC544 \uC2A4\uC2A4\uB85C write/end\uB97C \uC81C\uC5B4\uD55C\uB2E4 (\uC608: SSE \uC2A4\uD2B8\uB9AC\uBC0D)\n } else if (ValidUtils.isGenerator(data) || ValidUtils.isAsyncGenerator(data)) {\n // \uC81C\uB108\uB808\uC774\uD130 \uB9AC\uD134: \uD5E4\uB354 \uBA3C\uC800 \uBCF4\uB0B4\uACE0, yield \uB41C \uAC12\uC744 \uD558\uB098\uC529 \uBC14\uB85C body \uB85C \uD758\uB824\uBCF4\uB0B8\uB2E4 (\uC608: SSE)\n const headers = resConfig?.header ?? {};\n if (resConfig?.contentType) {\n headers[HttpHeaders.ContentType] = resConfig.contentType;\n }\n rr.resSetHeaders(headers);\n rr.resSetStatusCode(resConfig?.status ?? HttpStatus.Ok);\n await rr.resStream(data);\n } else {\n if (it.config?.resolver) {\n const execute = typeof it.config.resolver === 'function' ? this.simstanceManager.getOrNewSim({target: it.config.resolver}) : it.config.resolver;\n data = await execute?.resolve?.(data, rr, resConfig);\n }\n const status = resConfig?.status ?? HttpStatus.Ok;\n const headers = resConfig?.header ?? {};\n if (resConfig?.contentType) {\n headers[HttpHeaders.ContentType] = resConfig.contentType;\n }\n if ((resConfig?.contentType?.toLowerCase().indexOf(Mimes.ApplicationJson.toLowerCase()) ?? -1) > -1) {\n data = JSON.stringify(data);\n } else if (data && typeof data === 'object') {\n data = JSON.stringify(data);\n }\n rr.resSetHeaders(headers)\n rr.resSetStatusCode(status);\n rr.resWrite(data);\n }\n }\n }\n\n if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && rr.reqMethod()?.toUpperCase() !== HttpMethod.OPTIONS) {\n throw this.option.noSuchRouteEndPointMappingThrow(rr);\n }\n }\n\n // after\n for (const it of filter.filters.reverse()) {\n if (it.filter?.proceedAfter && !await it.filter.proceedAfter({rr, app: this, before: it.sw, carrier: filter.carrier})) {\n break;\n }\n }\n } catch (e) {\n console.error('request error:', e);\n transactionManager?.catch(e);\n rr.resStatusCode(e instanceof HttpError ? e.status : HttpStatus.InternalServerError)\n const execute = typeof this.option.globalAdvice === 'function' ? this.simstanceManager.getOrNewSim(this.option.globalAdvice) : this.option.globalAdvice;\n if (!execute) {\n rr.resEnd();\n // rr.resEnd().catch(e => {\n // });\n return;\n }\n if (e && typeof e === 'object') {\n otherStorage.set(e.constructor as ConstructorType<any>, e);\n otherStorage.set(SituationTypeContainer, new SituationTypeContainer({\n situationType: ExceptionHandlerSituationType.ERROR_OBJECT,\n data: e\n }));\n }\n const target = targetExceptionHandler(execute, e);\n if (target) {\n await this.simstanceManager.executeBindParameterSimPromise({\n target: execute,\n targetKey: target.propertyKey\n }, otherStorage);\n }\n } finally {\n transactionManager?.finally();\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n\n if (this.option.webSocketEndPoints) {\n const webSocketServer = new WebSocketServer({server: this.server});\n const execute = this.option.webSocketEndPoints.map(it => typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it);\n webSocketServer.on('connection', async (ws, request) => {\n this.webSocketClients.set(ws, {request});\n const wsSet = {socket: ws, request};\n execute.forEach(it => it.connect?.(wsSet));\n ws.on('error', err => execute.forEach(it => it.error?.(wsSet, err)));\n ws.on('message', (data, isBinary) => execute.forEach(it => it.message(wsSet, {data, isBinary})));\n ws.on('ping', () => execute.forEach(it => it.ping?.(wsSet)));\n ws.on('close', () => {\n this.webSocketClients.delete(ws);\n execute.forEach(it => it.close?.(wsSet));\n });\n });\n }\n this.server.listen(this.option.listen.port, this.option.listen.hostname, this.option.listen.backlog, () => {\n this.option.listen.listeningListener?.(this, this.server);\n });\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAgC;AAChC,8BAA+B;AAE/B,kBAAoE;AACpE,mBAAoC;AACpC,gBAAyC;AACzC,6BAA8B;AAC9B,2BAAwF;AACxF,wBAAyB;AACzB,yBAA0B;AAC1B,mBAAoB;AAEpB,IAAAA,sBAAoE;AACpE,IAAAA,sBAAyE;AAEzE,IAAAC,eAAuC;AACvC,4BAA6B;AAC7B,yBAA0B;AAC1B,uBAAwB;AACxB,IAAAD,sBAA2B;AAC3B,kCAAmC;AACnC,IAAAA,sBAAmD;AACnD,IAAAA,sBAA6B;AAC7B,uBAAwB;AACxB,IAAAA,sBAAuB;AAEvB,iBAA8B;AAC9B,wBAAyB;AACzB,4BAA6B;AAE7B,gCAAiC;AAEjC,yBAA0B;AAGnB,MAAM,6BAA6B,qCAAkB;AAAA,EAK1D,YAAmB,SAA2B,IAAI,yCAAiB,GAAG;AACpE,UAAM,MAAM;AADK;AAFnB,SAAQ,mBAAmB,oBAAI,IAA6C;AAI1E,SAAK,iBAAiB,IAAI,qCAAe,KAAK,MAAM;AAAA,EACtD;AAA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,SAAS,MAAM;AACzG,WAAK,OAAO,OAAO,oBAAoB,MAAM,KAAK,MAAM;AAAA,IAC1D,CAAC;AAAA,EACH;AACF;",
4
+ "sourcesContent": ["import {SimpleApplication} from '@dooboostore/simple-boot';\nimport {HttpServerOption} from './option/HttpServerOption';\nimport {ConstructorType} from '@dooboostore/core';\nimport {IncomingMessage, Server as HttpServer, ServerResponse} from 'http'\nimport {Server as HttpsServer} from 'https'; // Add HTTPS support\nimport {WebSocketServer, WebSocket} from 'ws';\nimport {RequestResponse} from './models/RequestResponse';\nimport {getUrlMapping, getUrlMappings, SaveMappingConfig, UrlMappingSituationType} from './decorators/MethodMapping';\nimport {HttpStatus} from './codes/HttpStatus';\nimport {HttpHeaders} from './codes/HttpHeaders';\nimport {Mimes} from './codes/Mimes';\nimport {Filter} from './filters/Filter';\nimport {ExceptionHandlerSituationType, targetExceptionHandler} from '@dooboostore/simple-boot';\nimport {getInject, SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot';\nimport {EndPoint} from './endpoints/EndPoint';\nimport {ReflectUtils, ValidUtils} from '@dooboostore/core';\nimport {ReqFormUrlBody} from './models/datas/body/ReqFormUrlBody';\nimport {ReqJsonBody} from './models/datas/body/ReqJsonBody';\nimport {ReqHeader} from './models/datas/ReqHeader';\nimport {RouterModule} from '@dooboostore/simple-boot';\nimport {ReqMultipartFormBody} from './models/datas/body/ReqMultipartFormBody';\nimport {execValidationInValid, getValidIndex} from '@dooboostore/simple-boot';\nimport {ValidException} from '@dooboostore/simple-boot';\nimport {HttpError} from './errors/HttpError';\nimport {getRoute} from '@dooboostore/simple-boot';\nimport {OnInit} from './lifecycle/OnInit';\nimport {URLSearchParams} from 'url';\nimport {HttpMethod} from './codes/HttpMethod';\nimport {SessionManager} from './session/SessionManager';\nimport {InjectSituationType} from './inject/InjectSituationType';\nimport {ContentTypeGenerator} from './generators/ContentTypeGenerator';\nimport {ReqSearchParamsObj} from \"./models/datas/path/ReqSearchParamsObj\";\nimport {SimConfig} from '@dooboostore/simple-boot';\nimport {ReqPathData} from './models/datas/path/ReqPathData';\nimport {WebSocketEndPoint} from './endpoints/WebSocketEndPoint';\n\nexport class SimpleBootHttpServer extends SimpleApplication {\n public server?: HttpServer | HttpsServer;\n private sessionManager: SessionManager;\n private webSocketClients = new Map<WebSocket, { request: IncomingMessage }>();\n\n constructor(public option: HttpServerOption = new HttpServerOption()) {\n super(option);\n this.sessionManager = new SessionManager(this.option);\n }\n\n\n public run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>) {\n otherInstanceSim ??= new Map<ConstructorType<any> | Function | SimConfig | symbol, any>();\n otherInstanceSim.set(SimpleBootHttpServer, this);\n super.run(otherInstanceSim);\n const targets = [...this.option.closeEndPoints ?? [], ...this.option.errorEndPoints ?? [], ...this.option.requestEndPoints ?? [], ...(this.option.filters ?? []).map(it=>it.filter)];\n Promise.all(targets.map(it => (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it as ConstructorType<any>}) : it) as OnInit).map(it => it.onInit(this))).then(it => {\n this.startServer();\n });\n return this;\n }\n\n private startServer() {\n\n // const a = this.option.serverOption as HttpsServerOption;\n // this.option.serverOption?.\n\n if (this.option.serverOption && 'key' in this.option.serverOption && 'cert' in this.option.serverOption) {\n this.server = new HttpsServer(this.option.serverOption);\n const httpServer = new HttpServer();\n httpServer.on('request', (req: IncomingMessage, res: ServerResponse) => {\n res.writeHead(301, {Location: `https://${req.headers.host}${req.url}`});\n res.end();\n });\n httpServer.listen(80, this.option.listen.hostname, () => {\n console.log('HTTP redirect server running on port 80');\n });\n } else if (this.option.serverOption) {\n this.server = new HttpServer(this.option.serverOption);\n } else {\n this.server = new HttpServer();\n }\n // const thisRef = this;\n this.server.on('request', async (req: IncomingMessage, res: ServerResponse) => {\n // console.log('request', req.url);\n const transactionManager = this.option.transactionManagerFactory ? await this.option.transactionManagerFactory() : undefined;\n res.on('close', async () => {\n if (this.option.closeEndPoints) {\n for (const it of this.option.closeEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;\n const endPoint = execute?.endPoint(rr, this);\n if (endPoint instanceof Promise) {\n await endPoint;\n }\n } catch (e) {\n }\n }\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n res.on('error', async () => {\n if (this.option.errorEndPoints) {\n for (const it of this.option.errorEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;\n const endPoint = execute?.endPoint(rr, this);\n if (endPoint instanceof Promise) {\n await endPoint;\n }\n } catch (e) {\n }\n }\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n\n const rr = new RequestResponse(req, res, {sessionManager: this.sessionManager, option: this.option});\n /*\n default setting first\n */\n rr.resSetHeader(HttpHeaders.Server, 'simple-boot-http-server');\n const cookie = rr.reqCookieGet(this.option.sessionOption.key);\n if (!cookie) {\n const session = await this.sessionManager.session();\n\n const cookieParts: string[] = [];\n cookieParts.push(`${this.option.sessionOption.key}=${session.uuid}`);\n cookieParts.push(`Path=${this.option.sessionOption.path}`);\n if (this.option.sessionOption.httpOnly) cookieParts.push('HttpOnly');\n if (this.option.sessionOption.secure) cookieParts.push('Secure');\n if (this.option.sessionOption.sameSite != null && this.option.sessionOption.sameSite) cookieParts.push(`SameSite=${this.option.sessionOption.sameSite}`);\n const maxAge = (this.option.sessionOption as any).maxAge ?? (this.sessionManager.sessionOption)?.maxAge;\n if (maxAge != null) cookieParts.push(`Max-Age=${maxAge}`);\n rr.resSetHeader(HttpHeaders.SetCookie, cookieParts.join('; '));\n }\n\n const otherStorage = new Map<ConstructorType<any>, any>();\n otherStorage.set(RequestResponse, rr);\n otherStorage.set(IncomingMessage, req);\n otherStorage.set(ServerResponse, res);\n // \uD074\uB77C\uC774\uC5B8\uD2B8\uAC00 \uC751\uB2F5 \uC644\uB8CC \uC804\uC5D0 \uB04A\uC73C\uBA74 abort. \uD578\uB4E4\uB7EC\uB294 \uD30C\uB77C\uBBF8\uD130 \uD0C0\uC785 AbortSignal \uB85C \uC8FC\uC785\uBC1B\uC544\n // fetch/timers/events.once \uB4F1\uC5D0 \uB118\uAE30\uBA74 \uB300\uAE30 \uC911\uC774\uC5B4\uB3C4 \uBC14\uB85C \uD480\uB9B0\uB2E4 (\uC81C\uB108\uB808\uC774\uD130 \uC2A4\uD2B8\uB9BC\uC758 \uC774\uBCA4\uD2B8 \uB300\uAE30 \uB204\uC218 \uBC29\uC9C0)\n const abortController = new AbortController();\n res.once('close', () => {\n if (!res.writableFinished) abortController.abort();\n });\n otherStorage.set(AbortSignal, abortController.signal);\n try {\n transactionManager?.try();\n if (this.option.requestEndPoints) {\n for (const it of this.option.requestEndPoints) {\n try {\n const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim<EndPoint>({target: it}) : it) as EndPoint;\n execute?.endPoint(rr, this);\n } catch (e) {\n }\n }\n }\n\n const filter = {\n carrier: new Map<string, any>(),\n filters: [] as { filter: Filter, sw: boolean }[]\n };\n for (let i = 0; this.option.filters && i < this.option.filters.length; i++) {\n const it = this.option.filters[i];\n\n let isSkip = false;\n if (typeof it.isSupport === 'boolean') {\n isSkip = !it.isSupport;\n } else if (typeof it.isSupport === 'object') {\n isSkip = !it.isSupport.test(rr.reqUrlPathName)\n } else if (typeof it.isSupport === 'function') {\n isSkip = !it.isSupport(rr);\n }\n if(isSkip) {\n continue;\n }\n\n let sw = true;\n const itFilter = it.filter;\n const execute = (typeof itFilter === 'function' ? this.simstanceManager.getOrNewSim({target: itFilter}) : itFilter) as Filter;\n if (execute?.proceedBefore) {\n sw = await execute.proceedBefore({rr, app: this, carrier: filter.carrier});\n filter.filters.push({filter: execute, sw});\n }\n if (!sw) {\n break;\n }\n }\n\n // body.. something..\n // \uB77C\uC6B0\uD130 \uC5C6\uC774 \uD544\uD130\uB9CC\uC73C\uB85C \uB3C4\uB294 \uC11C\uBC84(\uC608: SSR \uC804\uC6A9)\uBA74, \uC5B4\uB290 \uD544\uD130\uB3C4 \uCC98\uB9AC\uD558\uC9C0 \uC54A\uC740 \uC694\uCCAD\uC740 404 \uB85C \uB05D\uB0B8\uB2E4\n // (\uBE0C\uB77C\uC6B0\uC800\uAC00 \uC54C\uC544\uC11C \uBCF4\uB0B4\uB294 /favicon.ico, /.well-known/... \uAC19\uC740 \uAC83 \u2014 \uC608\uC804\uC5D4 'no router' \uC5D0\uB7EC\uB85C 500 + \uB85C\uADF8)\n if (!rr.resIsDone() && !this.option.rootRouter) {\n rr.resStatusCode(HttpStatus.NotFound);\n } else if (!rr.resIsDone()) {\n const routerModule = await super.routing(rr.reqIntent);\n otherStorage.set(RouterModule, routerModule);\n const moduleInstance = routerModule?.getModuleInstance?.();\n let methods: SaveMappingConfig[] = [];\n if (routerModule && moduleInstance) {\n // router \uD074\uB798\uC2A4 \uB0B4\uBD80\uC5D0\uC11C \uC120\uC5B8\uB41C Route\uC77C\uB54C\n if (routerModule.propertyKeys) {\n const map = routerModule.propertyKeys?.map((it: string | symbol) => {\n return {propertyKey: it, config: getUrlMapping(moduleInstance, it)} as SaveMappingConfig\n });\n methods.push(...(map ?? []));\n } else {\n methods.push(...(getUrlMappings(moduleInstance).filter(it => !getRoute(moduleInstance, it.propertyKey)) ?? []));\n }\n\n // options\uB85C \uC694\uCCAD\uC624\uBA74\uC740 allow\uB85C \uB123\uACE0 \uADF8\uB0E5 200\uCC98\uB9AC\uD574\uC57C\uB428.\n if (rr.reqMethod()?.toUpperCase() === HttpMethod.OPTIONS.toUpperCase()) {\n rr.resSetHeader(HttpHeaders.Allow, methods.map(it => it.config.method).join(', '));\n rr.resStatusCode(HttpStatus.Ok);\n }\n\n // method \uCC3E\uAE30\n methods = methods.filter(it => it && it.propertyKey && it.config && rr.reqMethod()?.toUpperCase() === it.config.method.toUpperCase());\n methods.sort((a, b) => {\n return ((b.config?.req?.contentType?.length ?? 0) + (b.config?.req?.accept?.length ?? 0)) - ((a.config?.req?.contentType?.length ?? 0) + (a.config?.req?.accept?.length ?? 0));\n });\n methods = methods\n .filter(it => it.config?.req?.contentType ? (!!it.config?.req?.contentType?.find(sit => rr.reqHasContentTypeHeader(sit))) : true)\n .filter(it => it.config?.req?.accept ? (!!it.config?.req?.accept?.find(sit => rr.reqHasAcceptHeader(sit))) : true);\n\n if (methods[0]) {\n const it = methods[0];\n const paramTypes = ReflectUtils.getParameterTypes(moduleInstance, it.propertyKey)\n const injects = getInject(moduleInstance, it.propertyKey);\n const validIndexs = getValidIndex(moduleInstance, it.propertyKey);\n if (injects) {\n const isPathData = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_PATH_DATA);\n const isJson = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_JSON_BODY);\n const isSearchParamsObj = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ);\n const isFormUrl = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_FORM_URL_BODY);\n // \uC6B0\uC120 \uB2E4\uC2DC \uC81C\uAC70\uD55C\uB2E4.. \uD2B8\uB79C\uC81D\uC158 \uC5B4\uB5BB\uAC8C \uD560\uC9C0 \uB2E4\uC2DC \uC0DD\uAC01\n // const isTransactionManager = injects.find(it => it.config?.situationType === InjectSituationType.TransactionManager);\n const siturationContainers = new SituationTypeContainers();\n if (isPathData) {\n let data = await routerModule.pathData\n if (isPathData.type) {\n data = Object.assign(new isPathData.type(), data);\n }\n if (validIndexs.includes(isPathData.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_PATH_DATA,\n data\n }));\n }\n if (isJson) {\n let data = await rr.reqBodyJsonData();\n if (data !== null && isJson.type) {\n data = Object.assign(new isJson.type(), data);\n }\n if (validIndexs.includes(isJson.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_JSON_BODY,\n data\n }));\n }\n if (isSearchParamsObj) {\n let data = rr.reqUrlSearchParamsObj\n if (validIndexs.includes(isSearchParamsObj.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({\n situationType: UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ,\n data\n }));\n }\n if (isFormUrl) {\n let data = await rr.reqBodyFormUrlData()\n if (isFormUrl.type) {\n data = Object.assign(new isFormUrl.type(), data);\n }\n if (validIndexs.includes(isFormUrl.index)) {\n const inValid = execValidationInValid(data);\n if ((inValid?.length ?? 0) > 0) {\n throw new ValidException(inValid);\n }\n }\n siturationContainers.push(new SituationTypeContainer({situationType: UrlMappingSituationType.REQ_FORM_URL_BODY, data}));\n }\n // \uD2B8\uB79C\uC81D\uC158 \uC6B0\uC120 \uC81C\uAC70 \uB098\uC911\uC5D0 \uC5B4\uB5BB\uAC8C \uAD6C\uD604\uD560\uC9C0 \uC0DD\uAC01..\n // if (isTransactionManager && isTransactionManager.type && transactionManager && transactionManager.hasTransaction(isTransactionManager.type)) {\n // let data = await transactionManager.getTransaction(isTransactionManager.type);\n // if (data) {\n // data = await data.try(isTransactionManager.config.argument);\n // siturationContainers.push(new SituationTypeContainer({situationType: InjectSituationType.TransactionManager, data, index: isTransactionManager.index}));\n // }\n // }\n if (siturationContainers.length) {\n otherStorage.set(SituationTypeContainers, siturationContainers);\n }\n }\n\n for (const paramType of paramTypes) {\n if (paramType === ReqFormUrlBody) {\n otherStorage.set(ReqFormUrlBody, await rr.reqBodyReqFormUrlBody())\n } else if (paramType === ReqPathData) {\n otherStorage.set(ReqPathData, routerModule.pathData)\n } else if (paramType === ReqJsonBody) {\n otherStorage.set(ReqJsonBody, await rr.reqBodyReqJsonBody())\n } else if (paramType === ReqSearchParamsObj) {\n otherStorage.set(ReqSearchParamsObj, rr.reqUrlSearchParamsObj)\n } else if (paramType === URLSearchParams) {\n otherStorage.set(URLSearchParams, rr.reqUrlSearchParams)\n } else if (paramType === ReqMultipartFormBody) {\n otherStorage.set(ReqMultipartFormBody, rr.reqBodyMultipartFormData())\n } else if (paramType === ReqHeader) {\n otherStorage.set(ReqHeader, rr.reqHeaderObj)\n }\n }\n\n // execute !!!\n let data = await this.simstanceManager.executeBindParameterSimPromise({\n target: moduleInstance,\n targetKey: it.propertyKey\n }, otherStorage);\n /*\n \uC5EC\uAE30\uC5D0\uC11C \uC815\uD574\uC9C4 \uD0C0\uC785 \uB9AC\uD134\uC5D0 \uB530\uB978 \uC870\uCE58\n ...\n */\n const resConfig = it.config?.res;\n if (resConfig === 'manual') {\n // \uD578\uB4E4\uB7EC\uAC00 ServerResponse\uB97C \uC9C1\uC811 \uC8FC\uC785\uBC1B\uC544 \uC2A4\uC2A4\uB85C write/end\uB97C \uC81C\uC5B4\uD55C\uB2E4 (\uC608: SSE \uC2A4\uD2B8\uB9AC\uBC0D)\n } else if (ValidUtils.isGenerator(data) || ValidUtils.isAsyncGenerator(data)) {\n // \uC81C\uB108\uB808\uC774\uD130 \uB9AC\uD134: \uD5E4\uB354 \uBA3C\uC800 \uBCF4\uB0B4\uACE0, yield \uB41C \uAC12\uC744 \uD558\uB098\uC529 \uBC14\uB85C body \uB85C \uD758\uB824\uBCF4\uB0B8\uB2E4 (\uC608: SSE)\n // ContentTypeGenerator.Stream \uC774\uBA74 Content-Type(boundary \uD3EC\uD568)\u00B7\uC555\uCD95 \uC5EC\uBD80\uB97C \uC2A4\uD2B8\uB9BC\uC774 \uC815\uD55C\uB2E4\n const stream = ContentTypeGenerator.isStream(data) ? data : undefined;\n const headers = resConfig?.header ?? {};\n const contentType = stream?.contentType ?? resConfig?.contentType;\n if (contentType) {\n headers[HttpHeaders.ContentType] = contentType;\n }\n rr.resSetHeaders(headers);\n rr.resSetStatusCode(resConfig?.status ?? HttpStatus.Ok);\n await rr.resStream(data, { compress: stream?.compress });\n } else {\n if (it.config?.resolver) {\n const execute = typeof it.config.resolver === 'function' ? this.simstanceManager.getOrNewSim({target: it.config.resolver}) : it.config.resolver;\n data = await execute?.resolve?.(data, rr, resConfig);\n }\n const status = resConfig?.status ?? HttpStatus.Ok;\n const headers = resConfig?.header ?? {};\n if (resConfig?.contentType) {\n headers[HttpHeaders.ContentType] = resConfig.contentType;\n }\n if ((resConfig?.contentType?.toLowerCase().indexOf(Mimes.ApplicationJson.toLowerCase()) ?? -1) > -1) {\n data = JSON.stringify(data);\n } else if (data && typeof data === 'object') {\n data = JSON.stringify(data);\n }\n rr.resSetHeaders(headers)\n rr.resSetStatusCode(status);\n rr.resWrite(data);\n }\n }\n }\n\n if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && rr.reqMethod()?.toUpperCase() !== HttpMethod.OPTIONS) {\n throw this.option.noSuchRouteEndPointMappingThrow(rr);\n }\n }\n\n // after\n for (const it of filter.filters.reverse()) {\n if (it.filter?.proceedAfter && !await it.filter.proceedAfter({rr, app: this, before: it.sw, carrier: filter.carrier})) {\n break;\n }\n }\n } catch (e) {\n console.error('request error:', e);\n transactionManager?.catch(e);\n rr.resStatusCode(e instanceof HttpError ? e.status : HttpStatus.InternalServerError)\n const execute = typeof this.option.globalAdvice === 'function' ? this.simstanceManager.getOrNewSim(this.option.globalAdvice) : this.option.globalAdvice;\n if (!execute) {\n rr.resEnd();\n // rr.resEnd().catch(e => {\n // });\n return;\n }\n if (e && typeof e === 'object') {\n otherStorage.set(e.constructor as ConstructorType<any>, e);\n otherStorage.set(SituationTypeContainer, new SituationTypeContainer({\n situationType: ExceptionHandlerSituationType.ERROR_OBJECT,\n data: e\n }));\n }\n const target = targetExceptionHandler(execute, e);\n if (target) {\n await this.simstanceManager.executeBindParameterSimPromise({\n target: execute,\n targetKey: target.propertyKey\n }, otherStorage);\n }\n } finally {\n transactionManager?.finally();\n }\n\n if (!rr.resIsDone()) {\n rr.resEnd();\n }\n });\n\n if (this.option.webSocketEndPoints) {\n const webSocketServer = new WebSocketServer({server: this.server});\n const execute = this.option.webSocketEndPoints.map(it => typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it);\n webSocketServer.on('connection', async (ws, request) => {\n this.webSocketClients.set(ws, {request});\n const wsSet = {socket: ws, request};\n execute.forEach(it => it.connect?.(wsSet));\n ws.on('error', err => execute.forEach(it => it.error?.(wsSet, err)));\n ws.on('message', (data, isBinary) => execute.forEach(it => it.message(wsSet, {data, isBinary})));\n ws.on('ping', () => execute.forEach(it => it.ping?.(wsSet)));\n ws.on('close', () => {\n this.webSocketClients.delete(ws);\n execute.forEach(it => it.close?.(wsSet));\n });\n });\n }\n this.server.listen(this.option.listen.port, this.option.listen.hostname, this.option.listen.backlog, () => {\n this.option.listen.listeningListener?.(this, this.server);\n });\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAgC;AAChC,8BAA+B;AAE/B,kBAAoE;AACpE,mBAAoC;AACpC,gBAAyC;AACzC,6BAA8B;AAC9B,2BAAwF;AACxF,wBAAyB;AACzB,yBAA0B;AAC1B,mBAAoB;AAEpB,IAAAA,sBAAoE;AACpE,IAAAA,sBAAyE;AAEzE,IAAAC,eAAuC;AACvC,4BAA6B;AAC7B,yBAA0B;AAC1B,uBAAwB;AACxB,IAAAD,sBAA2B;AAC3B,kCAAmC;AACnC,IAAAA,sBAAmD;AACnD,IAAAA,sBAA6B;AAC7B,uBAAwB;AACxB,IAAAA,sBAAuB;AAEvB,iBAA8B;AAC9B,wBAAyB;AACzB,4BAA6B;AAE7B,kCAAmC;AACnC,gCAAiC;AAEjC,yBAA0B;AAGnB,MAAM,6BAA6B,qCAAkB;AAAA,EAK1D,YAAmB,SAA2B,IAAI,yCAAiB,GAAG;AACpE,UAAM,MAAM;AADK;AAFnB,SAAQ,mBAAmB,oBAAI,IAA6C;AAI1E,SAAK,iBAAiB,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,KAAK,CAAC;AAAA,QACzC,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AACA,SAAK,OAAO,OAAO,KAAK,OAAO,OAAO,MAAM,KAAK,OAAO,OAAO,UAAU,KAAK,OAAO,OAAO,SAAS,MAAM;AACzG,WAAK,OAAO,OAAO,oBAAoB,MAAM,KAAK,MAAM;AAAA,IAC1D,CAAC;AAAA,EACH;AACF;",
6
6
  "names": ["import_simple_boot", "import_core", "HttpsServer", "HttpServer", "it", "data"]
7
7
  }
@@ -48,6 +48,8 @@ var Mimes = /* @__PURE__ */ ((Mimes2) => {
48
48
  Mimes2["MultipartFormData"] = "multipart/form-data";
49
49
  Mimes2["TextEventStream"] = "text/event-stream";
50
50
  Mimes2["ApplicationXndjson"] = "application/x-ndjson";
51
+ Mimes2["ApplicationJsonSeq"] = "application/json-seq";
52
+ Mimes2["TextCsv"] = "text/csv";
51
53
  Mimes2["ApplicationJsonPostSimpleBootSsrIntentScheme"] = "application/json-post+simple-boot-ssr-intent-scheme";
52
54
  Mimes2["Intent"] = "intent";
53
55
  return Mimes2;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/codes/Mimes.ts"],
4
- "sourcesContent": ["export enum Mimes {\n ApplicationJson = 'application/json',\n ApplicationOctetStream = 'application/octet-stream',\n ApplicationXml = 'application/xml',\n ApplicationJsonPatch = 'application/json-patch+json',\n ApplicationXWwwFormUrlencoded = 'application/x-www-form-urlencoded',\n TextPlain = 'text/plain',\n TextHtml = 'text/html',\n All = '*/*',\n TextCss = 'text/css',\n TextJavascript = 'text/javascript',\n TextXml = 'text/xml',\n TextXslt = 'text/xslt',\n TextXmlDtd = 'text/xml-dtd',\n TextPlainUtf8 = 'text/plain; charset=utf-8',\n ImagePng = 'image/png',\n ImageGif = 'image/gif',\n ImageJpeg = 'image/jpeg',\n ImageSvg = 'image/svg+xml',\n ImageBmp = 'image/bmp',\n ImageTiff = 'image/tiff',\n ImagePdf = 'application/pdf',\n ImageXBmp = 'image/x-bmp',\n ImageXpixmap = 'image/x-xpixmap',\n ImageXxbm = 'image/x-xbm',\n MultipartFormData = 'multipart/form-data',\n TextEventStream = 'text/event-stream', // SSE \uC2E4\uC2DC\uAC04 \uD14D\uC2A4\uD2B8 \uC2A4\uD2B8\uB9AC\uBC0D\n ApplicationXndjson = 'application/x-ndjson',\n ApplicationJsonPostSimpleBootSsrIntentScheme = 'application/json-post+simple-boot-ssr-intent-scheme',\n Intent = 'intent'\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,4BAAyB;AACzB,EAAAA,OAAA,oBAAiB;AACjB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,mCAAgC;AAChC,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,SAAM;AACN,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,oBAAiB;AACjB,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,wBAAqB;AACrB,EAAAA,OAAA,kDAA+C;AAC/C,EAAAA,OAAA,YAAS;AA7BC,SAAAA;AAAA,GAAA;",
4
+ "sourcesContent": ["export enum Mimes {\n ApplicationJson = 'application/json',\n ApplicationOctetStream = 'application/octet-stream',\n ApplicationXml = 'application/xml',\n ApplicationJsonPatch = 'application/json-patch+json',\n ApplicationXWwwFormUrlencoded = 'application/x-www-form-urlencoded',\n TextPlain = 'text/plain',\n TextHtml = 'text/html',\n All = '*/*',\n TextCss = 'text/css',\n TextJavascript = 'text/javascript',\n TextXml = 'text/xml',\n TextXslt = 'text/xslt',\n TextXmlDtd = 'text/xml-dtd',\n TextPlainUtf8 = 'text/plain; charset=utf-8',\n ImagePng = 'image/png',\n ImageGif = 'image/gif',\n ImageJpeg = 'image/jpeg',\n ImageSvg = 'image/svg+xml',\n ImageBmp = 'image/bmp',\n ImageTiff = 'image/tiff',\n ImagePdf = 'application/pdf',\n ImageXBmp = 'image/x-bmp',\n ImageXpixmap = 'image/x-xpixmap',\n ImageXxbm = 'image/x-xbm',\n MultipartFormData = 'multipart/form-data',\n TextEventStream = 'text/event-stream', // SSE \uC2E4\uC2DC\uAC04 \uD14D\uC2A4\uD2B8 \uC2A4\uD2B8\uB9AC\uBC0D\n ApplicationXndjson = 'application/x-ndjson',\n ApplicationJsonSeq = 'application/json-seq', // RFC 7464 JSON Text Sequences\n TextCsv = 'text/csv',\n ApplicationJsonPostSimpleBootSsrIntentScheme = 'application/json-post+simple-boot-ssr-intent-scheme',\n Intent = 'intent'\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,4BAAyB;AACzB,EAAAA,OAAA,oBAAiB;AACjB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,mCAAgC;AAChC,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,SAAM;AACN,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,oBAAiB;AACjB,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,eAAY;AACZ,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,wBAAqB;AACrB,EAAAA,OAAA,wBAAqB;AACrB,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,kDAA+C;AAC/C,EAAAA,OAAA,YAAS;AA/BC,SAAAA;AAAA,GAAA;",
6
6
  "names": ["Mimes"]
7
7
  }
@@ -0,0 +1,320 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var ContentTypeGenerator_exports = {};
29
+ __export(ContentTypeGenerator_exports, {
30
+ ContentTypeGenerator: () => ContentTypeGenerator
31
+ });
32
+ module.exports = __toCommonJS(ContentTypeGenerator_exports);
33
+ var import_crypto = require("crypto");
34
+ var import_mime_types = __toESM(require("mime-types"), 1);
35
+ var import_core = require("@dooboostore/core");
36
+ var import_Mimes = require("../codes/Mimes");
37
+ var ContentTypeGenerator;
38
+ ((ContentTypeGenerator2) => {
39
+ ContentTypeGenerator2.isStream = (value) => import_core.ValidUtils.isAsyncGenerator(value) && typeof value.contentType === "string";
40
+ const oneLine = (v) => v.replace(/[\r\n]/g, " ");
41
+ ContentTypeGenerator2.sseChunk = (e) => {
42
+ const ev = typeof e === "string" ? { data: e } : e;
43
+ let out = "";
44
+ if (ev.comment !== void 0) out += ev.comment.split(/\r\n|\r|\n/).map((l) => `: ${l}
45
+ `).join("");
46
+ if (ev.event !== void 0) out += `event: ${oneLine(ev.event)}
47
+ `;
48
+ if (ev.id !== void 0) out += `id: ${oneLine(ev.id)}
49
+ `;
50
+ if (ev.retry !== void 0) out += `retry: ${Math.max(0, Math.floor(ev.retry))}
51
+ `;
52
+ if (ev.data !== void 0) {
53
+ const text2 = typeof ev.data === "string" ? ev.data : JSON.stringify(ev.data);
54
+ out += text2.split(/\r\n|\r|\n/).map((l) => `data: ${l}
55
+ `).join("");
56
+ }
57
+ return out + "\n";
58
+ };
59
+ ContentTypeGenerator2.ssePing = () => ": ping\n\n";
60
+ const sniff = (b) => {
61
+ if (b.length >= 3 && b[0] === 255 && b[1] === 216 && b[2] === 255) return import_Mimes.Mimes.ImageJpeg;
62
+ if (b.length >= 8 && b.readUInt32BE(0) === 2303741511 && b.readUInt32BE(4) === 218765834) return import_Mimes.Mimes.ImagePng;
63
+ if (b.length >= 6 && b.toString("ascii", 0, 4) === "GIF8") return import_Mimes.Mimes.ImageGif;
64
+ if (b.length >= 12 && b.toString("ascii", 0, 4) === "RIFF" && b.toString("ascii", 8, 12) === "WEBP") return "image/webp";
65
+ return void 0;
66
+ };
67
+ ContentTypeGenerator2.partType = (part, fallback) => {
68
+ const p = isPartObject(part) ? part : { body: part };
69
+ if (p.type) return p.type;
70
+ if (p.name) {
71
+ const byName = import_mime_types.default.lookup(p.name);
72
+ if (byName) return import_mime_types.default.contentType(byName) || byName;
73
+ }
74
+ if (typeof p.body === "string") return fallback ?? import_Mimes.Mimes.TextPlainUtf8;
75
+ return sniff(Buffer.from(p.body.buffer, p.body.byteOffset, p.body.byteLength)) ?? fallback ?? import_Mimes.Mimes.ApplicationOctetStream;
76
+ };
77
+ const isPartObject = (part) => typeof part === "object" && !(part instanceof Uint8Array);
78
+ const toBuffer = (body) => typeof body === "string" ? Buffer.from(body, "utf8") : Buffer.isBuffer(body) ? body : Buffer.from(body.buffer, body.byteOffset, body.byteLength);
79
+ ContentTypeGenerator2.multipartPart = (part, boundary2, fallbackType) => {
80
+ const p = isPartObject(part) ? part : { body: part };
81
+ const body = toBuffer(p.body);
82
+ let head = `--${boundary2}\r
83
+ Content-Type: ${(0, ContentTypeGenerator2.partType)(part, fallbackType)}\r
84
+ Content-Length: ${body.length}\r
85
+ `;
86
+ for (const [k, v] of Object.entries(p.headers ?? {})) head += `${oneLine(k)}: ${oneLine(v)}\r
87
+ `;
88
+ return Buffer.concat([Buffer.from(head + "\r\n", "latin1"), body, Buffer.from("\r\n")]);
89
+ };
90
+ ContentTypeGenerator2.multipartEnd = (boundary2) => Buffer.from(`--${boundary2}--\r
91
+ `);
92
+ ContentTypeGenerator2.ndjsonLine = (value) => json(value) + "\n";
93
+ const json = (value) => JSON.stringify(value) ?? "null";
94
+ ContentTypeGenerator2.jsonSeqRecord = (value) => "" + json(value) + "\n";
95
+ ContentTypeGenerator2.csvCell = (value) => {
96
+ if (value === null || value === void 0) return "";
97
+ const s = typeof value === "string" ? value : value instanceof Date ? value.toISOString() : typeof value === "object" ? json(value) : String(value);
98
+ return /[",\r\n]|^\s|\s$/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
99
+ };
100
+ ContentTypeGenerator2.csvRow = (cells) => cells.map(ContentTypeGenerator2.csvCell).join(",") + "\r\n";
101
+ ContentTypeGenerator2.textLine = (value) => (typeof value === "string" ? value : json(value)) + "\n";
102
+ ContentTypeGenerator2.boundary = (value) => {
103
+ const b = value ?? `boundary-${(0, import_crypto.randomBytes)(12).toString("hex")}`;
104
+ if (!/^[0-9A-Za-z'()+_,\-./:=? ]{0,69}[0-9A-Za-z'()+_,\-./:=?]$/.test(b)) {
105
+ throw new Error(`invalid multipart boundary: ${JSON.stringify(b)}`);
106
+ }
107
+ return b;
108
+ };
109
+ const toStream = (gen, contentType, compress) => Object.assign(gen, { contentType, compress });
110
+ async function* encode(src, fn) {
111
+ for await (const v of src) yield fn(v);
112
+ }
113
+ async function* framed(src, fn, start, end) {
114
+ if (start !== void 0) yield start;
115
+ yield* encode(src, fn);
116
+ if (end !== void 0) yield end;
117
+ }
118
+ const jsonArrayItem = () => {
119
+ let n = 0;
120
+ return (v) => (n++ ? "," : "") + json(v);
121
+ };
122
+ const csvEncoder = (opt) => (r) => (0, ContentTypeGenerator2.csvRow)(Array.isArray(r) ? r : opt.columns ? opt.columns.map((c) => r[c]) : Object.values(r));
123
+ const csvStart = (opt) => opt.bom || opt.columns ? (opt.bom ? "\uFEFF" : "") + (opt.columns ? (0, ContentTypeGenerator2.csvRow)(opt.columns) : "") : void 0;
124
+ const CsvType = `${import_Mimes.Mimes.TextCsv}; charset=utf-8`;
125
+ function sse(src, opt = {}) {
126
+ const contentType = import_Mimes.Mimes.TextEventStream;
127
+ if (!opt.heartbeatMs) return toStream(encode(src, ContentTypeGenerator2.sseChunk), contentType, true);
128
+ const ms = opt.heartbeatMs;
129
+ async function* withPing() {
130
+ const it = Symbol.asyncIterator in src ? src[Symbol.asyncIterator]() : src[Symbol.iterator]();
131
+ let pending;
132
+ try {
133
+ while (true) {
134
+ pending ??= Promise.resolve(it.next());
135
+ let timer;
136
+ const tick = new Promise((r2) => timer = setTimeout(() => r2("ping"), ms));
137
+ const r = await Promise.race([pending, tick]);
138
+ clearTimeout(timer);
139
+ if (r === "ping") {
140
+ yield (0, ContentTypeGenerator2.ssePing)();
141
+ continue;
142
+ }
143
+ pending = void 0;
144
+ if (r.done) return;
145
+ yield (0, ContentTypeGenerator2.sseChunk)(r.value);
146
+ }
147
+ } finally {
148
+ await it.return?.();
149
+ }
150
+ }
151
+ return toStream(withPing(), contentType, true);
152
+ }
153
+ ContentTypeGenerator2.sse = sse;
154
+ function multipartReplace(src, opt = {}) {
155
+ const b = (0, ContentTypeGenerator2.boundary)(opt.boundary);
156
+ return toStream(encode(src, (p) => (0, ContentTypeGenerator2.multipartPart)(p, b, opt.type)), `multipart/x-mixed-replace; boundary=${b}`, false);
157
+ }
158
+ ContentTypeGenerator2.multipartReplace = multipartReplace;
159
+ function multipartMixed(src, opt = {}) {
160
+ const b = (0, ContentTypeGenerator2.boundary)(opt.boundary);
161
+ return toStream(framed(src, (p) => (0, ContentTypeGenerator2.multipartPart)(p, b, opt.type), void 0, (0, ContentTypeGenerator2.multipartEnd)(b)), `multipart/mixed; boundary=${b}`, true);
162
+ }
163
+ ContentTypeGenerator2.multipartMixed = multipartMixed;
164
+ function ndjson(src) {
165
+ return toStream(encode(src, ContentTypeGenerator2.ndjsonLine), import_Mimes.Mimes.ApplicationXndjson, true);
166
+ }
167
+ ContentTypeGenerator2.ndjson = ndjson;
168
+ function jsonSeq(src) {
169
+ return toStream(encode(src, ContentTypeGenerator2.jsonSeqRecord), import_Mimes.Mimes.ApplicationJsonSeq, true);
170
+ }
171
+ ContentTypeGenerator2.jsonSeq = jsonSeq;
172
+ function jsonArray(src) {
173
+ return toStream(framed(src, jsonArrayItem(), "[", "]"), import_Mimes.Mimes.ApplicationJson, true);
174
+ }
175
+ ContentTypeGenerator2.jsonArray = jsonArray;
176
+ function csv(src, opt = {}) {
177
+ return toStream(framed(src, csvEncoder(opt), csvStart(opt)), CsvType, true);
178
+ }
179
+ ContentTypeGenerator2.csv = csv;
180
+ function text(src) {
181
+ return toStream(encode(src, ContentTypeGenerator2.textLine), import_Mimes.Mimes.TextPlainUtf8, true);
182
+ }
183
+ ContentTypeGenerator2.text = text;
184
+ function channel(encodeFn, contentType, compress, opt = {}) {
185
+ const keep = opt.keep ?? "queue";
186
+ const max = Math.max(1, opt.max ?? 1e3);
187
+ const queue = [];
188
+ const closers = [];
189
+ let closed = false;
190
+ let finished = false;
191
+ let startSent = false;
192
+ let endSent = false;
193
+ let wake;
194
+ const finish = () => {
195
+ if (finished) return;
196
+ finished = closed = true;
197
+ queue.length = 0;
198
+ opt.signal?.removeEventListener("abort", onAbort);
199
+ wake?.();
200
+ for (const fn of closers.splice(0)) {
201
+ try {
202
+ fn();
203
+ } catch {
204
+ }
205
+ }
206
+ };
207
+ const onAbort = () => finish();
208
+ if (opt.signal?.aborted) closed = finished = true;
209
+ else opt.signal?.addEventListener("abort", onAbort, { once: true });
210
+ const next = async () => {
211
+ while (!finished) {
212
+ if (opt.start && !startSent) {
213
+ startSent = true;
214
+ return { value: opt.start(), done: false };
215
+ }
216
+ if (queue.length) return { value: encodeFn(queue.shift()), done: false };
217
+ if (closed) {
218
+ if (opt.end && !endSent) {
219
+ endSent = true;
220
+ return { value: opt.end(), done: false };
221
+ }
222
+ finish();
223
+ break;
224
+ }
225
+ let timer;
226
+ const ping = await new Promise((resolve) => {
227
+ wake = () => resolve(false);
228
+ if (opt.heartbeat) timer = setTimeout(() => resolve(true), opt.heartbeat.ms);
229
+ });
230
+ wake = void 0;
231
+ clearTimeout(timer);
232
+ if (ping && !finished && !queue.length && !closed) return { value: opt.heartbeat.chunk(), done: false };
233
+ }
234
+ return { value: void 0, done: true };
235
+ };
236
+ const iterator = {
237
+ contentType,
238
+ compress,
239
+ get closed() {
240
+ return closed;
241
+ },
242
+ push(value) {
243
+ if (closed) return false;
244
+ if (keep === "latest") queue.length = 0;
245
+ else if (queue.length >= max) queue.shift();
246
+ queue.push(value);
247
+ wake?.();
248
+ return true;
249
+ },
250
+ close() {
251
+ closed = true;
252
+ wake?.();
253
+ },
254
+ onClose(fn) {
255
+ if (finished) fn();
256
+ else closers.push(fn);
257
+ },
258
+ next,
259
+ async return() {
260
+ finish();
261
+ return { value: void 0, done: true };
262
+ },
263
+ async throw(e) {
264
+ finish();
265
+ throw e;
266
+ },
267
+ [Symbol.asyncIterator]() {
268
+ return this;
269
+ }
270
+ };
271
+ const dispose = Symbol.asyncDispose;
272
+ if (dispose) iterator[dispose] = async () => finish();
273
+ return iterator;
274
+ }
275
+ ContentTypeGenerator2.channel = channel;
276
+ ((sse2) => {
277
+ sse2.channel = (opt = {}) => ContentTypeGenerator2.channel(ContentTypeGenerator2.sseChunk, import_Mimes.Mimes.TextEventStream, true, {
278
+ ...opt,
279
+ heartbeat: opt.heartbeatMs ? { ms: opt.heartbeatMs, chunk: ContentTypeGenerator2.ssePing } : void 0
280
+ });
281
+ })(sse = ContentTypeGenerator2.sse || (ContentTypeGenerator2.sse = {}));
282
+ ((multipartReplace2) => {
283
+ multipartReplace2.channel = (opt = {}) => {
284
+ const b = (0, ContentTypeGenerator2.boundary)(opt.boundary);
285
+ return ContentTypeGenerator2.channel((p) => (0, ContentTypeGenerator2.multipartPart)(p, b, opt.type), `multipart/x-mixed-replace; boundary=${b}`, false, opt);
286
+ };
287
+ })(multipartReplace = ContentTypeGenerator2.multipartReplace || (ContentTypeGenerator2.multipartReplace = {}));
288
+ ((multipartMixed2) => {
289
+ multipartMixed2.channel = (opt = {}) => {
290
+ const b = (0, ContentTypeGenerator2.boundary)(opt.boundary);
291
+ return ContentTypeGenerator2.channel((p) => (0, ContentTypeGenerator2.multipartPart)(p, b, opt.type), `multipart/mixed; boundary=${b}`, true, {
292
+ ...opt,
293
+ end: () => (0, ContentTypeGenerator2.multipartEnd)(b)
294
+ });
295
+ };
296
+ })(multipartMixed = ContentTypeGenerator2.multipartMixed || (ContentTypeGenerator2.multipartMixed = {}));
297
+ ((ndjson2) => {
298
+ ndjson2.channel = (opt = {}) => ContentTypeGenerator2.channel(ContentTypeGenerator2.ndjsonLine, import_Mimes.Mimes.ApplicationXndjson, true, opt);
299
+ })(ndjson = ContentTypeGenerator2.ndjson || (ContentTypeGenerator2.ndjson = {}));
300
+ ((jsonSeq2) => {
301
+ jsonSeq2.channel = (opt = {}) => ContentTypeGenerator2.channel(ContentTypeGenerator2.jsonSeqRecord, import_Mimes.Mimes.ApplicationJsonSeq, true, opt);
302
+ })(jsonSeq = ContentTypeGenerator2.jsonSeq || (ContentTypeGenerator2.jsonSeq = {}));
303
+ ((jsonArray2) => {
304
+ jsonArray2.channel = (opt = {}) => ContentTypeGenerator2.channel(jsonArrayItem(), import_Mimes.Mimes.ApplicationJson, true, { ...opt, start: () => "[", end: () => "]" });
305
+ })(jsonArray = ContentTypeGenerator2.jsonArray || (ContentTypeGenerator2.jsonArray = {}));
306
+ ((csv2) => {
307
+ csv2.channel = (opt = {}) => {
308
+ const start = csvStart(opt);
309
+ return ContentTypeGenerator2.channel(csvEncoder(opt), CsvType, true, { ...opt, start: start === void 0 ? void 0 : () => start });
310
+ };
311
+ })(csv = ContentTypeGenerator2.csv || (ContentTypeGenerator2.csv = {}));
312
+ ((text2) => {
313
+ text2.channel = (opt = {}) => ContentTypeGenerator2.channel(ContentTypeGenerator2.textLine, import_Mimes.Mimes.TextPlainUtf8, true, opt);
314
+ })(text = ContentTypeGenerator2.text || (ContentTypeGenerator2.text = {}));
315
+ })(ContentTypeGenerator || (ContentTypeGenerator = {}));
316
+ // Annotate the CommonJS export names for ESM import in node:
317
+ 0 && (module.exports = {
318
+ ContentTypeGenerator
319
+ });
320
+ //# sourceMappingURL=ContentTypeGenerator.js.map