oc-fastify-server-adapter 0.1.1 → 0.1.2

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.
package/dist/index.d.ts CHANGED
@@ -100,5 +100,9 @@ export interface FastifyServerAdapterOptions {
100
100
  port?: number | string;
101
101
  trustProxy?: boolean | string | string[] | number;
102
102
  }
103
- export default function createFastifyAdapter(options?: unknown): HttpServerAdapter;
104
- export {};
103
+ type FastifyServerAdapterFactory = {
104
+ (options?: unknown): HttpServerAdapter;
105
+ readonly __serverAdapterOptions?: FastifyServerAdapterOptions | number | string;
106
+ };
107
+ declare const createFastifyAdapter: FastifyServerAdapterFactory;
108
+ export default createFastifyAdapter;
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = createFastifyAdapter;
7
6
  const node_fs_1 = require("node:fs");
8
7
  const promises_1 = require("node:fs/promises");
9
8
  const node_path_1 = __importDefault(require("node:path"));
@@ -21,9 +20,8 @@ const ocResponseSym = Symbol('ocResponse');
21
20
  const timingStartSym = Symbol('timingStart');
22
21
  const multipartParsedSym = Symbol('multipartParsed');
23
22
  const defaultBodyLimit = 100 * 1024;
24
- function createFastifyAdapter(options) {
25
- return new FastifyHttpServerAdapter(toFastifyAdapterOptions(options));
26
- }
23
+ const createFastifyAdapter = ((options) => new FastifyHttpServerAdapter(toFastifyAdapterOptions(options)));
24
+ exports.default = createFastifyAdapter;
27
25
  class FastifyHttpServerAdapter {
28
26
  name = 'fastify';
29
27
  app;
@@ -479,11 +477,6 @@ function parseBodyLimit(limit) {
479
477
  : 1;
480
478
  return Math.floor(value * multiplier);
481
479
  }
482
- function toFastifyAdapterOptions(options) {
483
- return typeof options === 'object' && options !== null
484
- ? options
485
- : { port: options };
486
- }
487
480
  function normalisePort(port) {
488
481
  if (typeof port === 'number') {
489
482
  return port;
@@ -494,6 +487,36 @@ function normalisePort(port) {
494
487
  }
495
488
  return parsed;
496
489
  }
490
+ function toFastifyAdapterOptions(options) {
491
+ if (typeof options === 'undefined' ||
492
+ typeof options === 'number' ||
493
+ typeof options === 'string') {
494
+ return { port: options };
495
+ }
496
+ if (isFastifyAdapterOptions(options)) {
497
+ return options;
498
+ }
499
+ throw new Error('Invalid Fastify server adapter options');
500
+ }
501
+ function isFastifyAdapterOptions(options) {
502
+ if (!options || typeof options !== 'object') {
503
+ return false;
504
+ }
505
+ const candidate = options;
506
+ const port = candidate.port;
507
+ const host = candidate.host;
508
+ const trustProxy = candidate.trustProxy;
509
+ return ((typeof port === 'undefined' ||
510
+ typeof port === 'number' ||
511
+ typeof port === 'string') &&
512
+ (typeof host === 'undefined' || typeof host === 'string') &&
513
+ (typeof trustProxy === 'undefined' ||
514
+ typeof trustProxy === 'boolean' ||
515
+ typeof trustProxy === 'string' ||
516
+ typeof trustProxy === 'number' ||
517
+ (Array.isArray(trustProxy) &&
518
+ trustProxy.every((item) => typeof item === 'string'))));
519
+ }
497
520
  function toFastifyRoutePath(routePath) {
498
521
  return routePath.replace(/\*[A-Za-z0-9_]+/g, '*');
499
522
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-fastify-server-adapter",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Fastify HTTP server adapter for OC",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",