@innet/server 1.6.2 → 1.6.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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { CookieSerializeOptions } from 'cookie';
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
+ import { FormOptions } from 'multiparty';
4
5
  import { ParsedQs } from 'qs';
5
6
  export declare const ACTION: string;
6
7
  export declare type Body = Record<string, any>;
@@ -22,12 +23,16 @@ export interface ActionOptions {
22
23
  body?: Body;
23
24
  files?: Files;
24
25
  }
26
+ export interface ActionParams {
27
+ multipartyForm?: FormOptions;
28
+ }
25
29
  export declare type Resources = Exclude<keyof ActionOptions, undefined>;
26
30
  export declare const URL_PARSER: RegExp;
27
31
  export declare class Action<O extends ActionOptions = ActionOptions> {
28
32
  readonly req: Request;
29
33
  readonly res: Response;
30
- constructor(req: Request, res: Response);
34
+ params: ActionParams;
35
+ constructor(req: Request, res: Response, params?: ActionParams);
31
36
  get cookies(): O['cookies'];
32
37
  setCookie(key: string, value?: string, opt?: CookieSerializeOptions): void;
33
38
  parseBody(): Promise<unknown>;
@@ -9,9 +9,10 @@ import 'qs';
9
9
  const ACTION = Symbol('Action');
10
10
  const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
11
11
  class Action {
12
- constructor(req, res) {
12
+ constructor(req, res, params = {}) {
13
13
  this.req = req;
14
14
  this.res = res;
15
+ this.params = params;
15
16
  }
16
17
  get cookies() {
17
18
  return cookie.parse(this.req.headers.cookie || '');
@@ -32,7 +33,7 @@ class Action {
32
33
  }
33
34
  parseBody() {
34
35
  return new Promise((resolve, reject) => {
35
- new multiparty.Form().parse(this.req, (err, fields, files) => {
36
+ new multiparty.Form(this.params.multipartyForm).parse(this.req, (err, fields, files) => {
36
37
  if (err) {
37
38
  reject(err);
38
39
  }
@@ -18,9 +18,11 @@ var multiparty__default = /*#__PURE__*/_interopDefaultLegacy(multiparty);
18
18
  var ACTION = Symbol('Action');
19
19
  var URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
20
20
  var Action = /** @class */ (function () {
21
- function Action(req, res) {
21
+ function Action(req, res, params) {
22
+ if (params === void 0) { params = {}; }
22
23
  this.req = req;
23
24
  this.res = res;
25
+ this.params = params;
24
26
  }
25
27
  Object.defineProperty(Action.prototype, "cookies", {
26
28
  get: function () {
@@ -46,7 +48,7 @@ var Action = /** @class */ (function () {
46
48
  Action.prototype.parseBody = function () {
47
49
  var _this = this;
48
50
  return new Promise(function (resolve, reject) {
49
- new multiparty__default["default"].Form().parse(_this.req, function (err, fields, files) {
51
+ new multiparty__default["default"].Form(_this.params.multipartyForm).parse(_this.req, function (err, fields, files) {
50
52
  if (err) {
51
53
  reject(err);
52
54
  }
@@ -3,7 +3,7 @@ import { context, ContextProps, slot, SlotProps, slots, SlotsProps } from '@inne
3
3
  import { switchAsync, SwitchProps } from '@innet/switch';
4
4
  import { arrayAsync, async } from '@innet/utils';
5
5
  import { serverFn } from '../experimental/serverFn';
6
- import { access, AccessProps, cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
6
+ import { access, AccessProps, cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, parseBody, ParseBodyProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
7
7
  import { server, ServerProps } from '../server';
8
8
  export declare const arrayPlugins: (typeof arrayAsync)[];
9
9
  export declare const JSXPlugins: {
@@ -25,6 +25,7 @@ export declare const JSXPlugins: {
25
25
  slot: typeof slot;
26
26
  slots: typeof slots;
27
27
  access: typeof access;
28
+ 'parse-body': typeof parseBody;
28
29
  };
29
30
  export declare const fnPlugins: (typeof serverFn)[];
30
31
  export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
@@ -50,6 +51,7 @@ declare global {
50
51
  slot: SlotProps;
51
52
  slots: SlotsProps;
52
53
  access: AccessProps;
54
+ 'parse-body': ParseBodyProps;
53
55
  }
54
56
  }
55
57
  }
@@ -16,6 +16,7 @@ import { redirect } from '../plugins/redirect/redirect.es6.js';
16
16
  import { validation } from '../plugins/validation/validation.es6.js';
17
17
  import { formatter } from '../plugins/formatter/formatter.es6.js';
18
18
  import { access } from '../plugins/access/access.es6.js';
19
+ import { parseBody } from '../plugins/parseBody/parseBody.es6.js';
19
20
  import { server } from '../server/server.es6.js';
20
21
 
21
22
  const arrayPlugins = [
@@ -42,6 +43,7 @@ const JSXPlugins = {
42
43
  slot,
43
44
  slots,
44
45
  access,
46
+ 'parse-body': parseBody,
45
47
  };
46
48
  const fnPlugins = [
47
49
  serverFn,
@@ -20,6 +20,7 @@ var redirect = require('../plugins/redirect/redirect.js');
20
20
  var validation = require('../plugins/validation/validation.js');
21
21
  var formatter = require('../plugins/formatter/formatter.js');
22
22
  var access = require('../plugins/access/access.js');
23
+ var parseBody = require('../plugins/parseBody/parseBody.js');
23
24
  var server = require('../server/server.js');
24
25
 
25
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -50,6 +51,7 @@ var JSXPlugins = {
50
51
  slot: jsx.slot,
51
52
  slots: jsx.slots,
52
53
  access: access.access,
54
+ 'parse-body': parseBody.parseBody,
53
55
  };
54
56
  var fnPlugins = [
55
57
  serverFn.serverFn,
package/index.es6.js CHANGED
@@ -12,6 +12,7 @@ export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
12
12
  export { validation, validationContext } from './plugins/validation/validation.es6.js';
13
13
  export { formatter } from './plugins/formatter/formatter.es6.js';
14
14
  export { access, accessContext } from './plugins/access/access.es6.js';
15
+ export { parseBody } from './plugins/parseBody/parseBody.es6.js';
15
16
  export { ACTION, Action, URL_PARSER, useAction } from './action/Action/Action.es6.js';
16
17
  export { parseSearch } from './utils/parseSearch/parseSearch.es6.js';
17
18
  export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
package/index.js CHANGED
@@ -16,6 +16,7 @@ var redirect = require('./plugins/redirect/redirect.js');
16
16
  var validation = require('./plugins/validation/validation.js');
17
17
  var formatter = require('./plugins/formatter/formatter.js');
18
18
  var access = require('./plugins/access/access.js');
19
+ var parseBody = require('./plugins/parseBody/parseBody.js');
19
20
  var Action = require('./action/Action/Action.js');
20
21
  var parseSearch = require('./utils/parseSearch/parseSearch.js');
21
22
  var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
@@ -50,6 +51,7 @@ exports.validationContext = validation.validationContext;
50
51
  exports.formatter = formatter.formatter;
51
52
  exports.access = access.access;
52
53
  exports.accessContext = access.accessContext;
54
+ exports.parseBody = parseBody.parseBody;
53
55
  exports.ACTION = Action.ACTION;
54
56
  exports.Action = Action.Action;
55
57
  exports.URL_PARSER = Action.URL_PARSER;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "homepage": "https://github.com/d8corp/innet-server",
24
24
  "dependencies": {
25
+ "@types/multiparty": "^0.0.33",
25
26
  "@cantinc/utils": "^1.2.7",
26
27
  "@innet/html": "^1.0.1",
27
28
  "@innet/jsx": "^1.1.0",
@@ -10,3 +10,4 @@ export * from './redirect';
10
10
  export * from './validation';
11
11
  export * from './formatter';
12
12
  export * from './access';
13
+ export * from './parseBody';
@@ -10,3 +10,4 @@ export { redirect, redirectStatuses } from './redirect/redirect.es6.js';
10
10
  export { validation, validationContext } from './validation/validation.es6.js';
11
11
  export { formatter } from './formatter/formatter.es6.js';
12
12
  export { access, accessContext } from './access/access.es6.js';
13
+ export { parseBody } from './parseBody/parseBody.es6.js';
package/plugins/index.js CHANGED
@@ -14,6 +14,7 @@ var redirect = require('./redirect/redirect.js');
14
14
  var validation = require('./validation/validation.js');
15
15
  var formatter = require('./formatter/formatter.js');
16
16
  var access = require('./access/access.js');
17
+ var parseBody = require('./parseBody/parseBody.js');
17
18
 
18
19
 
19
20
 
@@ -37,3 +38,4 @@ exports.validationContext = validation.validationContext;
37
38
  exports.formatter = formatter.formatter;
38
39
  exports.access = access.access;
39
40
  exports.accessContext = access.accessContext;
41
+ exports.parseBody = parseBody.parseBody;
@@ -0,0 +1 @@
1
+ export * from './parseBody';
@@ -0,0 +1 @@
1
+ export { parseBody } from './parseBody.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var parseBody = require('./parseBody.js');
6
+
7
+
8
+
9
+ exports.parseBody = parseBody.parseBody;
@@ -0,0 +1,7 @@
1
+ export interface ParseBodyProps {
2
+ }
3
+ export interface ParseBodyJsxElement {
4
+ props: ParseBodyProps;
5
+ children?: any;
6
+ }
7
+ export declare function parseBody({ props, children }: ParseBodyJsxElement, handler: any): any;
@@ -0,0 +1,8 @@
1
+ import innet from 'innet';
2
+ import { ACTION } from '../../action/Action/Action.es6.js';
3
+
4
+ function parseBody({ props, children }, handler) {
5
+ return handler[ACTION].parseBody().then(() => innet(children, handler));
6
+ }
7
+
8
+ export { parseBody };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var innet = require('innet');
6
+ var Action = require('../../action/Action/Action.js');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
11
+
12
+ function parseBody(_a, handler) {
13
+ _a.props; var children = _a.children;
14
+ return handler[Action.ACTION].parseBody().then(function () { return innet__default["default"](children, handler); });
15
+ }
16
+
17
+ exports.parseBody = parseBody;
@@ -1,10 +1,11 @@
1
1
  import { Handler } from 'innet';
2
- import { Action } from '../action';
2
+ import { Action, ActionParams } from '../action';
3
3
  export interface SSL {
4
4
  cert: string;
5
5
  key: string;
6
6
  }
7
7
  export interface ServerProps {
8
+ actionParams?: ActionParams;
8
9
  port?: number;
9
10
  ssl?: SSL;
10
11
  unknownError?: string;
@@ -10,7 +10,7 @@ import { CONTINUE } from '../constants.es6.js';
10
10
  const isInvalidPath = require('is-invalid-path');
11
11
  function server({ props = {}, children }, handler) {
12
12
  const { env } = process;
13
- let { ssl: { key = env.SSL_KEY, cert = env.SSL_CRT } = {} } = props;
13
+ let { ssl: { key = env.SSL_KEY, cert = env.SSL_CRT } = {}, actionParams } = props;
14
14
  if (!isInvalidPath(key)) {
15
15
  key = fs.readFileSync(key).toString();
16
16
  }
@@ -27,7 +27,7 @@ function server({ props = {}, children }, handler) {
27
27
  });
28
28
  server.on('request', (req, res) => __awaiter(this, void 0, void 0, function* () {
29
29
  const childHandler = Object.create(handler);
30
- childHandler[ACTION] = new Action(req, res);
30
+ childHandler[ACTION] = new Action(req, res, actionParams);
31
31
  if (onRequest) {
32
32
  yield onRequest(childHandler[ACTION]);
33
33
  }
package/server/server.js CHANGED
@@ -23,7 +23,7 @@ function server(_a, handler) {
23
23
  var _this = this;
24
24
  var _b = _a.props, props = _b === void 0 ? {} : _b, children = _a.children;
25
25
  var env = process.env;
26
- var _c = props.ssl, _d = _c === void 0 ? {} : _c, _e = _d.key, key = _e === void 0 ? env.SSL_KEY : _e, _f = _d.cert, cert = _f === void 0 ? env.SSL_CRT : _f;
26
+ var _c = props.ssl, _d = _c === void 0 ? {} : _c, _e = _d.key, key = _e === void 0 ? env.SSL_KEY : _e, _f = _d.cert, cert = _f === void 0 ? env.SSL_CRT : _f, actionParams = props.actionParams;
27
27
  if (!isInvalidPath(key)) {
28
28
  key = fs__default["default"].readFileSync(key).toString();
29
29
  }
@@ -44,7 +44,7 @@ function server(_a, handler) {
44
44
  switch (_a.label) {
45
45
  case 0:
46
46
  childHandler = Object.create(handler);
47
- childHandler[Action.ACTION] = new Action.Action(req, res);
47
+ childHandler[Action.ACTION] = new Action.Action(req, res, actionParams);
48
48
  if (!onRequest) return [3 /*break*/, 2];
49
49
  return [4 /*yield*/, onRequest(childHandler[Action.ACTION])];
50
50
  case 1: