@jwn-js/common 1.3.1 → 1.3.5

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as formidable from 'formidable';
2
- import * as stream from 'stream';
2
+ import * as stream$1 from 'stream';
3
3
  import { Stream } from 'stream';
4
4
  import * as uWebSockets_js from 'uWebSockets.js';
5
5
  import { HttpResponse, HttpRequest } from 'uWebSockets.js';
@@ -8,6 +8,7 @@ export { Server, Handler as ServerHandler, Options as ServerOptions, Routes as S
8
8
  export { Jwt } from './Jwt';
9
9
  import { Client } from 'memjs';
10
10
  import { Query } from 'buildmsql';
11
+ export { Context as ContextSsr } from 'vite-ssr-vue';
11
12
 
12
13
  declare class Memcached {
13
14
  memjs: Client;
@@ -57,19 +58,21 @@ declare class Memcached {
57
58
  */
58
59
  declare function staticBody(res: HttpResponse, req: HttpRequest, base: string): Promise<void>;
59
60
 
60
- interface Context$3 {
61
+ interface OptionsSsr {
61
62
  readonly manifest: Record<string, any>;
62
63
  readonly memcached: Memcached;
63
64
  readonly [key: string]: any;
64
65
  }
66
+ declare type EntryFunction = (url: string, opt: Record<string, any>) => Promise<any>;
67
+
65
68
  /**
66
69
  * Ssr handler for production
67
70
  */
68
71
  declare class Ssr {
69
72
  res: HttpResponse;
70
73
  req: HttpRequest;
71
- context: Context$3;
72
- entry: CallableFunction;
74
+ context: OptionsSsr;
75
+ entry: EntryFunction | any;
73
76
  /**
74
77
  * @constructor
75
78
  * @param res response
@@ -77,7 +80,7 @@ declare class Ssr {
77
80
  * @param context params
78
81
  * @param entry - entry point function
79
82
  */
80
- constructor(res: HttpResponse, req: HttpRequest, context: Context$3, entry: CallableFunction);
83
+ constructor(res: HttpResponse, req: HttpRequest, context: OptionsSsr, entry: EntryFunction | any);
81
84
  /**
82
85
  * @param request addition request params
83
86
  */
@@ -133,7 +136,7 @@ declare class ApiError extends Error {
133
136
  getHeaders(): Record<string, string>;
134
137
  }
135
138
 
136
- declare type method$1 = 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
139
+ declare type method$2 = 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
137
140
  declare module "uWebSockets.js" {
138
141
  interface HttpRequest {
139
142
  cookies: Record<string, any>;
@@ -141,16 +144,16 @@ declare module "uWebSockets.js" {
141
144
  }
142
145
  interface Route$1 {
143
146
  name: string;
144
- method?: method$1 | Array<method$1>;
147
+ method?: method$2 | Array<method$2>;
145
148
  component: any;
146
149
  }
147
- interface Context$2 {
150
+ interface OptionsWeb {
148
151
  readonly routes: Array<Route$1>;
149
152
  readonly config: Config$1;
150
153
  readonly db: Record<string, Query>;
151
154
  readonly [key: string]: any;
152
155
  }
153
- interface Response {
156
+ interface Response$1 {
154
157
  statusCode: number;
155
158
  headers: Record<string, any>;
156
159
  body: any;
@@ -181,7 +184,7 @@ interface ContextWeb {
181
184
  id: number;
182
185
  name: string;
183
186
  isActive: boolean;
184
- method: method$1;
187
+ method: method$2;
185
188
  };
186
189
  [key: string]: any;
187
190
  }
@@ -205,7 +208,7 @@ interface ContextWebController extends ContextWeb {
205
208
  declare class Web {
206
209
  res: HttpResponse;
207
210
  req: HttpRequest;
208
- context: Context$2;
211
+ context: OptionsWeb;
209
212
  defaultRequest: {
210
213
  controller: string;
211
214
  subaction: string;
@@ -226,7 +229,7 @@ declare class Web {
226
229
  * @param req request
227
230
  * @param context params
228
231
  */
229
- constructor(res: HttpResponse, req: HttpRequest, context: Context$2);
232
+ constructor(res: HttpResponse, req: HttpRequest, context: OptionsWeb);
230
233
  request(request?: Record<string, any>): Promise<void>;
231
234
  /**
232
235
  * Import controller class
@@ -255,14 +258,14 @@ declare class Web {
255
258
  /**
256
259
  * Success response
257
260
  */
258
- success(response: Response): void;
261
+ success(response: Response$1): void;
259
262
  /**
260
263
  * Error response
261
264
  */
262
265
  error(e: ApiError | Error): void;
263
266
  }
264
267
 
265
- declare type method = 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
268
+ declare type method$1 = 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
266
269
  declare module "uWebSockets.js" {
267
270
  interface HttpRequest {
268
271
  cookies: Record<string, any>;
@@ -270,7 +273,7 @@ declare module "uWebSockets.js" {
270
273
  }
271
274
  interface Route {
272
275
  name: string;
273
- method?: method | Array<method>;
276
+ method?: method$1 | Array<method$1>;
274
277
  component: any;
275
278
  }
276
279
  interface Config {
@@ -300,9 +303,9 @@ interface TestContext {
300
303
  id: number;
301
304
  name: string;
302
305
  isActive: boolean;
303
- method: method;
306
+ method: method$1;
304
307
  };
305
- method?: method;
308
+ method?: method$1;
306
309
  cookies?: Record<string, any>;
307
310
  hostname?: string;
308
311
  protocol?: string;
@@ -358,7 +361,7 @@ declare class Model$1 {
358
361
  id: number;
359
362
  name: string;
360
363
  isActive: boolean;
361
- method: method$1;
364
+ method: method$2;
362
365
  };
363
366
  getSubaction(): {
364
367
  id: number;
@@ -491,7 +494,7 @@ declare class Controller {
491
494
  id: number;
492
495
  name: string;
493
496
  isActive: boolean;
494
- method: method$1;
497
+ method: method$2;
495
498
  };
496
499
  getSubaction(): {
497
500
  id: number;
@@ -543,7 +546,7 @@ declare class Model {
543
546
  id: number;
544
547
  name: string;
545
548
  isActive: boolean;
546
- method: method$1;
549
+ method: method$2;
547
550
  };
548
551
  getSubaction(): {
549
552
  id: number;
@@ -555,12 +558,123 @@ declare class Model {
555
558
  };
556
559
  }
557
560
 
561
+ /**
562
+ * Response interface
563
+ */
564
+ interface Response {
565
+ memcache?: number | null;
566
+ headers?: Record<string, any>;
567
+ statusCode?: number;
568
+ }
569
+ declare type CallbackFunctionAny = (...args: any[]) => any;
570
+ /**
571
+ * Mixin helper for decorators
572
+ * @param behaviour
573
+ * @param sharedBehaviour
574
+ * http://raganwald.com/2015/06/26/decorators-in-es7.html
575
+ * http://raganwald.com/2015/06/17/functional-mixins.html
576
+ * https://habr.com/ru/post/277021/
577
+ */
578
+ declare function mixin<T extends Record<string, any>>(behaviour: T, sharedBehaviour?: {}): (clazz: any) => any;
579
+ /**
580
+ * @request() decorator
581
+ */
582
+ declare function request(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
583
+ /**
584
+ * @context() decorator
585
+ */
586
+ declare function context(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
587
+ /**
588
+ * @config() decorator
589
+ */
590
+ declare function config(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
591
+ /**
592
+ * @method() decorator
593
+ */
594
+ declare function method(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
595
+ /**
596
+ * @cookies() decorator
597
+ */
598
+ declare function cookies(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
599
+ /**
600
+ * @hostname() decorator
601
+ */
602
+ declare function hostname(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
603
+ /**
604
+ * @url() decorator
605
+ */
606
+ declare function url(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
607
+ /**
608
+ * @protocol() decorator
609
+ */
610
+ declare function protocol(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
611
+ /**
612
+ * @db() decorator
613
+ */
614
+ declare function db(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
615
+ /**
616
+ * @headers() decorator
617
+ */
618
+ declare function headers(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
619
+ /**
620
+ * @controller() decorator
621
+ */
622
+ declare function controller(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
623
+ /**
624
+ * @action() decorator
625
+ */
626
+ declare function action(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
627
+ /**
628
+ * @subaction() decorator
629
+ */
630
+ declare function subaction(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
631
+ /**
632
+ * @body() decorator
633
+ */
634
+ declare function body(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
635
+ /**
636
+ * @stream() decorator
637
+ */
638
+ declare function stream(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
639
+ /**
640
+ * @home() decorator
641
+ */
642
+ declare function home(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
643
+ /**
644
+ * @connection() decorator
645
+ */
646
+ declare function connection(name?: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
647
+ /**
648
+ * Json response
649
+ * @param opt response options
650
+ */
651
+ declare function json(opt?: Response): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<CallbackFunctionAny>) => void;
652
+ /**
653
+ * Xml response
654
+ * @param opt response options
655
+ */
656
+ declare function xml(opt?: Response): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<CallbackFunctionAny>) => void;
657
+ /**
658
+ * Logger
659
+ * @param name logger name
660
+ */
661
+ declare function logerror(name: string): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<CallbackFunctionAny>) => void;
662
+ /**
663
+ * Subaction method decorator
664
+ * @http() decorator
665
+ */
666
+ declare function http(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<CallbackFunctionAny>) => void;
667
+ /**
668
+ * @init decorator
669
+ */
670
+ declare function init(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<CallbackFunctionAny>) => void;
671
+
558
672
  declare const helpers: {
559
673
  cookieParse: (str: string) => Record<string, any>;
560
674
  cookieString: (name: string, value: any, options?: Record<string, any>) => string;
561
675
  jsonBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest) => Promise<any>;
562
676
  rawBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest) => Promise<Buffer>;
563
- streamBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest) => stream.Stream;
677
+ streamBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest) => stream$1.Stream;
564
678
  urlencodedBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest) => Promise<any>;
565
679
  multipartBody: (res: uWebSockets_js.HttpResponse, req: uWebSockets_js.HttpRequest, options?: formidable.Options) => Promise<any>;
566
680
  readConfig: (jsonfile: string) => Promise<any>;
@@ -570,4 +684,4 @@ declare const helpers: {
570
684
  getExt: (path: string) => string;
571
685
  };
572
686
 
573
- export { Controller, Memcached, Model, Ssr, Web, helpers, mountWithContext as mount };
687
+ export { ContextWeb, Controller, Memcached, Model, OptionsSsr, OptionsWeb, Route$1 as Route, Ssr, Web, action, body, config, connection, context, controller, cookies, db, headers, helpers, home, hostname, http, init, json, logerror, method, mixin, mountWithContext as mount, protocol, request, stream, subaction, url, xml };
package/index.js CHANGED
@@ -6,7 +6,7 @@ var ApiError = require('./ApiError.js');
6
6
  var Server = require('./Server-77093d28.js');
7
7
  var Jwt = require('./Jwt.js');
8
8
  var ApiError$1 = require('./ApiError-b517f53a.js');
9
- var stream = require('stream');
9
+ var stream$1 = require('stream');
10
10
  var querystring = require('querystring');
11
11
  var formidable = require('formidable');
12
12
  var path = require('path');
@@ -15,6 +15,7 @@ require('dns');
15
15
  require('uWebSockets.js');
16
16
  var easyAsh = require('easy-ash');
17
17
  var xmljs = require('xml-js');
18
+ require('reflect-metadata');
18
19
  require('crypto');
19
20
 
20
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -129,17 +130,17 @@ function readRaw(res, cb, err) {
129
130
  const streamBody = (res, req) => {
130
131
  const err = new ApiError$1.ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 });
131
132
  res.onAborted(() => err);
132
- const stream$1 = new stream.PassThrough();
133
- stream$1.headers = {};
134
- req.forEach((key, val) => stream$1.headers[key] = val);
133
+ const stream = new stream$1.PassThrough();
134
+ stream.headers = {};
135
+ req.forEach((key, val) => stream.headers[key] = val);
135
136
  res.onData((chunk, isLast) => {
136
- stream$1.write(Buffer.from(Buffer.from(chunk)));
137
- stream$1.resume();
137
+ stream.write(Buffer.from(Buffer.from(chunk)));
138
+ stream.resume();
138
139
  if (isLast) {
139
- stream$1.end();
140
+ stream.end();
140
141
  }
141
142
  });
142
- return stream$1;
143
+ return stream;
143
144
  };
144
145
 
145
146
  const urlencodedBody = (res, req) => new Promise((resolve, reject) => {
@@ -169,18 +170,18 @@ const multipartBody = (res, req, options = { multiples: true }) => new Promise(a
169
170
  const err = new ApiError$1.ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 });
170
171
  res.onAborted(() => err);
171
172
  try {
172
- const stream$1 = new stream.PassThrough();
173
- stream$1.headers = {};
174
- req.forEach((key, val) => stream$1.headers[key] = val);
173
+ const stream = new stream$1.PassThrough();
174
+ stream.headers = {};
175
+ req.forEach((key, val) => stream.headers[key] = val);
175
176
  res.onData((chunk, isLast) => {
176
- stream$1.write(Buffer.from(Buffer.from(chunk)));
177
- stream$1.resume();
177
+ stream.write(Buffer.from(Buffer.from(chunk)));
178
+ stream.resume();
178
179
  if (isLast) {
179
- stream$1.end();
180
+ stream.end();
180
181
  }
181
182
  });
182
183
  const form = formidable__default['default'](options);
183
- form.parse(stream$1, (err2, fields, files) => {
184
+ form.parse(stream, (err2, fields, files) => {
184
185
  if (err2) {
185
186
  reject(err2);
186
187
  }
@@ -761,7 +762,7 @@ class Web {
761
762
  }
762
763
  }
763
764
 
764
- const config = readConfigSync("./connect.json");
765
+ const config$1 = readConfigSync("./connect.json");
765
766
  const mountWithContext = async ($class, $context, request = {}) => {
766
767
  const initComponent = async (obj2) => {
767
768
  let out;
@@ -776,12 +777,12 @@ const mountWithContext = async ($class, $context, request = {}) => {
776
777
  }
777
778
  };
778
779
  $context = Object.assign({
779
- config,
780
+ config: config$1,
780
781
  getRequest: () => request,
781
782
  method: "get",
782
783
  ...request.controller && request.subaction && $context.db?.home ? await selectControllerParams($context.db.home, $context.method || "get", request.controller, request.subaction) : {},
783
784
  cookies: {},
784
- hostname: config.server?.development?.host,
785
+ hostname: config$1.server?.development?.host,
785
786
  protocol: "http",
786
787
  headers: {}
787
788
  }, $context);
@@ -914,7 +915,7 @@ class Controller {
914
915
  return this.$context["$body"] || Buffer.from("");
915
916
  }
916
917
  getStream() {
917
- return this.$context["$stream"] || new stream.PassThrough().end();
918
+ return this.$context["$stream"] || new stream$1.PassThrough().end();
918
919
  }
919
920
  getConfig() {
920
921
  return this.$context.config;
@@ -1003,6 +1004,206 @@ class Model {
1003
1004
  }
1004
1005
  }
1005
1006
 
1007
+ const argumentsSubactionsKey = Symbol("arguments");
1008
+ const argumentsConnectionsKey = Symbol("connections");
1009
+ const responseSubactionsKey = Symbol("response");
1010
+ const responseInitKey = Symbol("init");
1011
+ const responseLoggerKey = Symbol("logger");
1012
+ const upperCaseFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
1013
+ function mixin(behaviour, sharedBehaviour = {}) {
1014
+ const instanceKeys = Reflect.ownKeys(behaviour);
1015
+ const sharedKeys = Reflect.ownKeys(sharedBehaviour);
1016
+ const typeTag = Symbol("isa");
1017
+ function _mixin(clazz) {
1018
+ for (const property of instanceKeys) {
1019
+ Object.defineProperty(clazz.prototype, property, { value: behaviour[property] });
1020
+ }
1021
+ Object.defineProperty(clazz.prototype, typeTag, { value: true });
1022
+ return clazz;
1023
+ }
1024
+ for (const property of sharedKeys) {
1025
+ Object.defineProperty(_mixin, property, {
1026
+ value: sharedBehaviour[property],
1027
+ enumerable: sharedBehaviour.propertyIsEnumerable(property)
1028
+ });
1029
+ }
1030
+ Object.defineProperty(_mixin, Symbol.hasInstance, {
1031
+ value: (i) => !!i[typeTag]
1032
+ });
1033
+ return _mixin;
1034
+ }
1035
+ const defineMetadataArgument = (key, target, propertyKey, parameterIndex, argumentType, params) => {
1036
+ const existingArguments = Reflect.getOwnMetadata(key, target, propertyKey) || {};
1037
+ existingArguments[parameterIndex] = {
1038
+ type: argumentType,
1039
+ params
1040
+ };
1041
+ Reflect.defineMetadata(key, existingArguments, target, propertyKey);
1042
+ };
1043
+ function request() {
1044
+ return function(target, propertyKey, parameterIndex) {
1045
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "request");
1046
+ };
1047
+ }
1048
+ function context() {
1049
+ return function(target, propertyKey, parameterIndex) {
1050
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "context");
1051
+ };
1052
+ }
1053
+ function config() {
1054
+ return function(target, propertyKey, parameterIndex) {
1055
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "config");
1056
+ };
1057
+ }
1058
+ function method() {
1059
+ return function(target, propertyKey, parameterIndex) {
1060
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "method");
1061
+ };
1062
+ }
1063
+ function cookies() {
1064
+ return function(target, propertyKey, parameterIndex) {
1065
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "cookies");
1066
+ };
1067
+ }
1068
+ function hostname() {
1069
+ return function(target, propertyKey, parameterIndex) {
1070
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "hostname");
1071
+ };
1072
+ }
1073
+ function url() {
1074
+ return function(target, propertyKey, parameterIndex) {
1075
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "url");
1076
+ };
1077
+ }
1078
+ function protocol() {
1079
+ return function(target, propertyKey, parameterIndex) {
1080
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "protocol");
1081
+ };
1082
+ }
1083
+ function db() {
1084
+ return function(target, propertyKey, parameterIndex) {
1085
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "db");
1086
+ };
1087
+ }
1088
+ function headers() {
1089
+ return function(target, propertyKey, parameterIndex) {
1090
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "headers");
1091
+ };
1092
+ }
1093
+ function controller() {
1094
+ return function(target, propertyKey, parameterIndex) {
1095
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "controller");
1096
+ };
1097
+ }
1098
+ function action() {
1099
+ return function(target, propertyKey, parameterIndex) {
1100
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "action");
1101
+ };
1102
+ }
1103
+ function subaction() {
1104
+ return function(target, propertyKey, parameterIndex) {
1105
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "subaction");
1106
+ };
1107
+ }
1108
+ function body() {
1109
+ return function(target, propertyKey, parameterIndex) {
1110
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "body");
1111
+ };
1112
+ }
1113
+ function stream() {
1114
+ return function(target, propertyKey, parameterIndex) {
1115
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "stream");
1116
+ };
1117
+ }
1118
+ function home() {
1119
+ return function(target, propertyKey, parameterIndex) {
1120
+ defineMetadataArgument(argumentsSubactionsKey, target, propertyKey, parameterIndex, "home");
1121
+ };
1122
+ }
1123
+ function connection(name = "home") {
1124
+ return function(target, propertyKey, parameterIndex) {
1125
+ defineMetadataArgument(argumentsConnectionsKey, target, propertyKey, parameterIndex, "connection", name);
1126
+ };
1127
+ }
1128
+ function json(opt = {}) {
1129
+ return function(target, propertyKey, descriptor) {
1130
+ defineMetadataArgument(responseSubactionsKey, target, propertyKey, 0, "json", opt);
1131
+ };
1132
+ }
1133
+ function xml(opt = {}) {
1134
+ return function(target, propertyKey, descriptor) {
1135
+ defineMetadataArgument(responseSubactionsKey, target, propertyKey, 0, "xml", opt);
1136
+ };
1137
+ }
1138
+ function logerror(name) {
1139
+ return function(target, propertyKey, descriptor) {
1140
+ defineMetadataArgument(responseLoggerKey, target, propertyKey, name, "logger", name);
1141
+ };
1142
+ }
1143
+ function http() {
1144
+ return function(target, propertyKey, descriptor) {
1145
+ const method2 = descriptor.value;
1146
+ const args = [];
1147
+ const connections = [];
1148
+ descriptor.value = async function() {
1149
+ const existingArguments = Reflect.getOwnMetadata(argumentsSubactionsKey, target, propertyKey) || {};
1150
+ const existingConnections = Reflect.getOwnMetadata(argumentsConnectionsKey, target, propertyKey) || {};
1151
+ const existingLoggers = Reflect.getOwnMetadata(responseLoggerKey, target, propertyKey) || {};
1152
+ const response = Reflect.getOwnMetadata(responseSubactionsKey, target, propertyKey)?.[0] || { type: "json", params: {} };
1153
+ const responseInit = Reflect.getOwnMetadata(responseInitKey, target, propertyKey)?.[0] || { type: "", params: {} };
1154
+ for (const key in existingArguments) {
1155
+ if (!existingArguments.hasOwnProperty(key)) {
1156
+ continue;
1157
+ }
1158
+ const getterName = `get${upperCaseFirstLetter(existingArguments[key].type)}`;
1159
+ args[+key] = this[getterName]();
1160
+ }
1161
+ for (const key in existingConnections) {
1162
+ if (!existingConnections.hasOwnProperty(key)) {
1163
+ continue;
1164
+ }
1165
+ existingConnections[key].type;
1166
+ args[+key] = await this.getDb()[existingConnections[key].params].getConnection();
1167
+ connections.push(args[+key]);
1168
+ }
1169
+ try {
1170
+ const out = await method2.apply(this, args);
1171
+ if (responseInit.type !== "init") {
1172
+ if (response.type === "xml") {
1173
+ return this.successXml(out, response.params);
1174
+ }
1175
+ return this.success(out, response.params);
1176
+ }
1177
+ } catch (e) {
1178
+ await Promise.all([...connections.map((connection2) => connection2.rollback())]);
1179
+ for (const key in existingLoggers) {
1180
+ if (!existingLoggers.hasOwnProperty(key)) {
1181
+ continue;
1182
+ }
1183
+ const logger = existingLoggers[key].params;
1184
+ await this[logger].error(e);
1185
+ }
1186
+ if (response.type === "xml") {
1187
+ return this.errorXml(e);
1188
+ }
1189
+ return this.error(e);
1190
+ } finally {
1191
+ await Promise.all([...connections.map((connection2) => connection2.release())]);
1192
+ }
1193
+ };
1194
+ };
1195
+ }
1196
+ function init() {
1197
+ return function(target, propertyKey, descriptor) {
1198
+ defineMetadataArgument(responseInitKey, target, propertyKey, 0, "init");
1199
+ descriptor.value;
1200
+ if (!("$inits" in target)) {
1201
+ Object.defineProperty(target, "$inits", { value: [] });
1202
+ }
1203
+ target.$inits.push(propertyKey);
1204
+ };
1205
+ }
1206
+
1006
1207
  const helpers = {
1007
1208
  cookieParse: Server.cookieParse,
1008
1209
  cookieString,
@@ -1027,5 +1228,28 @@ exports.Memcached = Memcached;
1027
1228
  exports.Model = Model;
1028
1229
  exports.Ssr = Ssr;
1029
1230
  exports.Web = Web;
1231
+ exports.action = action;
1232
+ exports.body = body;
1233
+ exports.config = config;
1234
+ exports.connection = connection;
1235
+ exports.context = context;
1236
+ exports.controller = controller;
1237
+ exports.cookies = cookies;
1238
+ exports.db = db;
1239
+ exports.headers = headers;
1030
1240
  exports.helpers = helpers;
1241
+ exports.home = home;
1242
+ exports.hostname = hostname;
1243
+ exports.http = http;
1244
+ exports.init = init;
1245
+ exports.json = json;
1246
+ exports.logerror = logerror;
1247
+ exports.method = method;
1248
+ exports.mixin = mixin;
1031
1249
  exports.mount = mountWithContext;
1250
+ exports.protocol = protocol;
1251
+ exports.request = request;
1252
+ exports.stream = stream;
1253
+ exports.subaction = subaction;
1254
+ exports.url = url;
1255
+ exports.xml = xml;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jwn-js/common",
3
3
  "private": false,
4
- "version": "1.3.1",
4
+ "version": "1.3.5",
5
5
  "description": "@jwn-js/common package",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",