@opra/nestjs 0.2.0 → 0.4.0

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,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceFactory = void 0;
3
+ exports.OpraApiFactory = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  const common_1 = require("@nestjs/common");
@@ -16,9 +16,8 @@ const nest_explorer_js_1 = require("../services/nest-explorer.js");
16
16
  const function_utils_js_1 = require("../utils/function.utils.js");
17
17
  const params_factory_js_1 = require("./params.factory.js");
18
18
  const noOpFunction = () => void 0;
19
- const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
20
19
  const METHOD_PATCHED = 'ServiceFactory.method-patched';
21
- let ServiceFactory = class ServiceFactory {
20
+ let OpraApiFactory = class OpraApiFactory {
22
21
  paramsFactory = new params_factory_js_1.OpraParamsFactory();
23
22
  injector = new injector_1.Injector();
24
23
  modulesContainer;
@@ -28,10 +27,11 @@ let ServiceFactory = class ServiceFactory {
28
27
  const info = { title: '', version: '', ...moduleOptions.info };
29
28
  info.title = info.title || 'Untitled service';
30
29
  info.version = info.version || '1';
30
+ const resources = [];
31
31
  const serviceArgs = {
32
32
  info,
33
33
  types: [],
34
- resources: [],
34
+ resources,
35
35
  };
36
36
  const wrappers = this.explorerService.exploreResourceWrappers(rootModule);
37
37
  for (const wrapper of wrappers) {
@@ -40,11 +40,11 @@ let ServiceFactory = class ServiceFactory {
40
40
  /* istanbul ignore next */
41
41
  if (!resourceDef)
42
42
  continue;
43
- serviceArgs.resources.push(instance);
43
+ resources.push(instance);
44
44
  /* Wrap resolver functions */
45
45
  const prototype = Object.getPrototypeOf(instance);
46
46
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
47
- const methodsToWrap = schema_1.OpraSchema.isEntityResource(resourceDef) ? entityMethods : [];
47
+ const methodsToWrap = schema_1.OpraSchema.isCollectionResource(resourceDef) ? schema_1.collectionMethods : [];
48
48
  for (const methodName of methodsToWrap) {
49
49
  const fn = prototype[methodName];
50
50
  if (typeof fn !== 'function')
@@ -108,7 +108,7 @@ let ServiceFactory = class ServiceFactory {
108
108
  });
109
109
  }
110
110
  }
111
- return await schema_1.OpraService.create(serviceArgs);
111
+ return await schema_1.OpraDocument.create(serviceArgs);
112
112
  }
113
113
  _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_1.default.identity, contextType, forPre) {
114
114
  const paramsFactory = this.paramsFactory;
@@ -188,16 +188,16 @@ let ServiceFactory = class ServiceFactory {
188
188
  tslib_1.__decorate([
189
189
  (0, common_1.Inject)(),
190
190
  tslib_1.__metadata("design:type", core_1.ModulesContainer)
191
- ], ServiceFactory.prototype, "modulesContainer", void 0);
191
+ ], OpraApiFactory.prototype, "modulesContainer", void 0);
192
192
  tslib_1.__decorate([
193
193
  (0, common_1.Inject)(),
194
194
  tslib_1.__metadata("design:type", external_context_creator_1.ExternalContextCreator)
195
- ], ServiceFactory.prototype, "externalContextCreator", void 0);
195
+ ], OpraApiFactory.prototype, "externalContextCreator", void 0);
196
196
  tslib_1.__decorate([
197
197
  (0, common_1.Inject)(),
198
198
  tslib_1.__metadata("design:type", nest_explorer_js_1.NestExplorer)
199
- ], ServiceFactory.prototype, "explorerService", void 0);
200
- ServiceFactory = tslib_1.__decorate([
199
+ ], OpraApiFactory.prototype, "explorerService", void 0);
200
+ OpraApiFactory = tslib_1.__decorate([
201
201
  (0, common_1.Injectable)()
202
- ], ServiceFactory);
203
- exports.ServiceFactory = ServiceFactory;
202
+ ], OpraApiFactory);
203
+ exports.OpraApiFactory = OpraApiFactory;
@@ -8,9 +8,9 @@ const common_1 = require("@nestjs/common");
8
8
  const core_1 = require("@nestjs/core");
9
9
  const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
10
10
  const constants_js_1 = require("./constants.js");
11
- const service_factory_js_1 = require("./factories/service.factory.js");
11
+ const opra_api_factory_js_1 = require("./factories/opra-api.factory.js");
12
12
  const nest_explorer_js_1 = require("./services/nest-explorer.js");
13
- const service_loader_js_1 = require("./services/service-loader.js");
13
+ const opra_api_loader_js_1 = require("./services/opra-api-loader.js");
14
14
  let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
15
15
  httpAdapterHost;
16
16
  modulesContainer;
@@ -34,7 +34,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
34
34
  },
35
35
  {
36
36
  provide: constants_js_1.OPRA_INITIALIZER,
37
- useClass: service_loader_js_1.OpraServiceLoader
37
+ useClass: opra_api_loader_js_1.OpraApiLoader
38
38
  }
39
39
  ],
40
40
  exports: [...(options.exports || [])]
@@ -52,7 +52,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
52
52
  },
53
53
  {
54
54
  provide: constants_js_1.OPRA_INITIALIZER,
55
- useClass: service_loader_js_1.OpraServiceLoader
55
+ useClass: opra_api_loader_js_1.OpraApiLoader
56
56
  },
57
57
  ...this.createAsyncProviders(asyncOptions)
58
58
  ]
@@ -114,7 +114,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
114
114
  OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
115
115
  (0, common_1.Module)({
116
116
  providers: [
117
- service_factory_js_1.ServiceFactory,
117
+ opra_api_factory_js_1.OpraApiFactory,
118
118
  metadata_scanner_1.MetadataScanner,
119
119
  nest_explorer_js_1.NestExplorer
120
120
  ]
@@ -122,6 +122,6 @@ OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
122
122
  tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)),
123
123
  tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER)),
124
124
  tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost,
125
- core_1.ModulesContainer, Object, service_loader_js_1.OpraServiceLoader])
125
+ core_1.ModulesContainer, Object, opra_api_loader_js_1.OpraApiLoader])
126
126
  ], OpraCoreModule);
127
127
  exports.OpraCoreModule = OpraCoreModule;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraServiceLoader = void 0;
3
+ exports.OpraApiLoader = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const core_1 = require("@nestjs/core");
7
7
  const core_2 = require("@opra/core");
8
8
  const url_1 = require("@opra/url");
9
9
  const constants_js_1 = require("../constants.js");
10
- const service_factory_js_1 = require("../factories/service.factory.js");
11
- class OpraServiceLoader {
12
- logger = new common_1.Logger(OpraServiceLoader.name, { timestamp: true });
10
+ const opra_api_factory_js_1 = require("../factories/opra-api.factory.js");
11
+ class OpraApiLoader {
12
+ logger = new common_1.Logger(OpraApiLoader.name, { timestamp: true });
13
13
  adapter;
14
14
  httpAdapterHost;
15
15
  applicationConfig;
@@ -61,17 +61,17 @@ class OpraServiceLoader {
61
61
  tslib_1.__decorate([
62
62
  (0, common_1.Inject)(),
63
63
  tslib_1.__metadata("design:type", core_1.HttpAdapterHost)
64
- ], OpraServiceLoader.prototype, "httpAdapterHost", void 0);
64
+ ], OpraApiLoader.prototype, "httpAdapterHost", void 0);
65
65
  tslib_1.__decorate([
66
66
  (0, common_1.Inject)(),
67
67
  tslib_1.__metadata("design:type", core_1.ApplicationConfig)
68
- ], OpraServiceLoader.prototype, "applicationConfig", void 0);
68
+ ], OpraApiLoader.prototype, "applicationConfig", void 0);
69
69
  tslib_1.__decorate([
70
70
  (0, common_1.Inject)(),
71
- tslib_1.__metadata("design:type", service_factory_js_1.ServiceFactory)
72
- ], OpraServiceLoader.prototype, "opraFactory", void 0);
71
+ tslib_1.__metadata("design:type", opra_api_factory_js_1.OpraApiFactory)
72
+ ], OpraApiLoader.prototype, "opraFactory", void 0);
73
73
  tslib_1.__decorate([
74
74
  (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS),
75
75
  tslib_1.__metadata("design:type", Object)
76
- ], OpraServiceLoader.prototype, "opraModuleOptions", void 0);
77
- exports.OpraServiceLoader = OpraServiceLoader;
76
+ ], OpraApiLoader.prototype, "opraModuleOptions", void 0);
77
+ exports.OpraApiLoader = OpraApiLoader;
@@ -2,22 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNumberOfArguments = void 0;
4
4
  const fast_tokenizer_1 = require("fast-tokenizer");
5
- const anythingEnclosedInParenthesesRegex = /\((.+)\)/;
6
5
  function getNumberOfArguments(fn) {
7
6
  const functionAsString = fn.toString();
8
- const parametersEnclosedInParentheses = functionAsString.match(anythingEnclosedInParenthesesRegex);
9
- if (parametersEnclosedInParentheses) {
10
- const matchString = parametersEnclosedInParentheses[1];
11
- const argumentsArray = (0, fast_tokenizer_1.splitString)(matchString, {
12
- brackets: {
13
- '(': ')',
14
- '{': '}',
15
- '[': ']',
16
- '/*': '*/'
17
- }, delimiters: ','
18
- });
19
- return argumentsArray.length;
7
+ const tokenizer = (0, fast_tokenizer_1.tokenize)(functionAsString, {
8
+ // keepBrackets: true,
9
+ keepDelimiters: true,
10
+ keepQuotes: true,
11
+ brackets: {}
12
+ });
13
+ let k = 0;
14
+ let s = '';
15
+ for (const token of tokenizer) {
16
+ if (token.startsWith('(')) {
17
+ s += token.substring(1);
18
+ k++;
19
+ }
20
+ else if (token.startsWith(')')) {
21
+ if (k === 1)
22
+ break;
23
+ }
24
+ else if (k)
25
+ s += token;
20
26
  }
21
- return 0;
27
+ const x = (0, fast_tokenizer_1.splitString)(s, {
28
+ brackets: {
29
+ '{': '}',
30
+ '(': ')',
31
+ '[': ']',
32
+ '/*': '*/'
33
+ }, delimiters: ','
34
+ });
35
+ return x.length > 1 ? x.length : (x[0] ? 1 : 0);
22
36
  }
23
37
  exports.getNumberOfArguments = getNumberOfArguments;
@@ -1,14 +1,14 @@
1
1
  import { ContextType } from '@nestjs/common';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
- import { OpraService } from '@opra/schema';
3
+ import { OpraDocument } from '@opra/schema';
4
4
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
5
- export declare class ServiceFactory {
5
+ export declare class OpraApiFactory {
6
6
  private readonly paramsFactory;
7
7
  private readonly injector;
8
8
  private readonly modulesContainer;
9
9
  private readonly externalContextCreator;
10
10
  private readonly explorerService;
11
- generateService(rootModule: Module, moduleOptions: OpraModuleOptions, contextType: ContextType): Promise<OpraService>;
11
+ generateService(rootModule: Module, moduleOptions: OpraModuleOptions, contextType: ContextType): Promise<OpraDocument>;
12
12
  private _createContextCallback;
13
13
  private getContextId;
14
14
  private registerContextProvider;
@@ -6,16 +6,15 @@ import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-cr
6
6
  import { Injector } from '@nestjs/core/injector/injector';
7
7
  import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module';
8
8
  import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants';
9
- import { OpraSchema, OpraService, RESOURCE_METADATA } from '@opra/schema';
9
+ import { collectionMethods, OpraDocument, OpraSchema, RESOURCE_METADATA } from '@opra/schema';
10
10
  import { PARAM_ARGS_METADATA } from '../constants.js';
11
11
  import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
12
12
  import { NestExplorer } from '../services/nest-explorer.js';
13
13
  import { getNumberOfArguments } from '../utils/function.utils.js';
14
14
  import { OpraParamsFactory } from './params.factory.js';
15
15
  const noOpFunction = () => void 0;
16
- const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
17
16
  const METHOD_PATCHED = 'ServiceFactory.method-patched';
18
- let ServiceFactory = class ServiceFactory {
17
+ let OpraApiFactory = class OpraApiFactory {
19
18
  paramsFactory = new OpraParamsFactory();
20
19
  injector = new Injector();
21
20
  modulesContainer;
@@ -25,10 +24,11 @@ let ServiceFactory = class ServiceFactory {
25
24
  const info = { title: '', version: '', ...moduleOptions.info };
26
25
  info.title = info.title || 'Untitled service';
27
26
  info.version = info.version || '1';
27
+ const resources = [];
28
28
  const serviceArgs = {
29
29
  info,
30
30
  types: [],
31
- resources: [],
31
+ resources,
32
32
  };
33
33
  const wrappers = this.explorerService.exploreResourceWrappers(rootModule);
34
34
  for (const wrapper of wrappers) {
@@ -37,11 +37,11 @@ let ServiceFactory = class ServiceFactory {
37
37
  /* istanbul ignore next */
38
38
  if (!resourceDef)
39
39
  continue;
40
- serviceArgs.resources.push(instance);
40
+ resources.push(instance);
41
41
  /* Wrap resolver functions */
42
42
  const prototype = Object.getPrototypeOf(instance);
43
43
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
44
- const methodsToWrap = OpraSchema.isEntityResource(resourceDef) ? entityMethods : [];
44
+ const methodsToWrap = OpraSchema.isCollectionResource(resourceDef) ? collectionMethods : [];
45
45
  for (const methodName of methodsToWrap) {
46
46
  const fn = prototype[methodName];
47
47
  if (typeof fn !== 'function')
@@ -105,7 +105,7 @@ let ServiceFactory = class ServiceFactory {
105
105
  });
106
106
  }
107
107
  }
108
- return await OpraService.create(serviceArgs);
108
+ return await OpraDocument.create(serviceArgs);
109
109
  }
110
110
  _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = _.identity, contextType, forPre) {
111
111
  const paramsFactory = this.paramsFactory;
@@ -185,16 +185,16 @@ let ServiceFactory = class ServiceFactory {
185
185
  __decorate([
186
186
  Inject(),
187
187
  __metadata("design:type", ModulesContainer)
188
- ], ServiceFactory.prototype, "modulesContainer", void 0);
188
+ ], OpraApiFactory.prototype, "modulesContainer", void 0);
189
189
  __decorate([
190
190
  Inject(),
191
191
  __metadata("design:type", ExternalContextCreator)
192
- ], ServiceFactory.prototype, "externalContextCreator", void 0);
192
+ ], OpraApiFactory.prototype, "externalContextCreator", void 0);
193
193
  __decorate([
194
194
  Inject(),
195
195
  __metadata("design:type", NestExplorer)
196
- ], ServiceFactory.prototype, "explorerService", void 0);
197
- ServiceFactory = __decorate([
196
+ ], OpraApiFactory.prototype, "explorerService", void 0);
197
+ OpraApiFactory = __decorate([
198
198
  Injectable()
199
- ], ServiceFactory);
200
- export { ServiceFactory };
199
+ ], OpraApiFactory);
200
+ export { OpraApiFactory };
@@ -1,13 +1,13 @@
1
1
  import { DynamicModule, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
2
2
  import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
3
3
  import { OpraModuleAsyncOptions, OpraModuleOptions } from './interfaces/opra-module-options.interface.js';
4
- import { OpraServiceLoader } from './services/service-loader.js';
4
+ import { OpraApiLoader } from './services/opra-api-loader.js';
5
5
  export declare class OpraCoreModule implements OnModuleInit, OnModuleDestroy {
6
6
  private readonly httpAdapterHost;
7
7
  protected readonly modulesContainer: ModulesContainer;
8
8
  private readonly options;
9
9
  private readonly opraServiceLoader;
10
- constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, opraServiceLoader: OpraServiceLoader);
10
+ constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, opraServiceLoader: OpraApiLoader);
11
11
  static forRoot(options: OpraModuleOptions & Pick<DynamicModule, 'imports' | 'providers' | 'exports'>): DynamicModule;
12
12
  static forRootAsync(asyncOptions: OpraModuleAsyncOptions): DynamicModule;
13
13
  private static createAsyncProviders;
@@ -5,9 +5,9 @@ import { Inject, Module } from '@nestjs/common';
5
5
  import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
6
6
  import { MetadataScanner } from '@nestjs/core/metadata-scanner';
7
7
  import { OPRA_INITIALIZER, OPRA_MODULE_ID, OPRA_MODULE_OPTIONS } from './constants.js';
8
- import { ServiceFactory } from './factories/service.factory.js';
8
+ import { OpraApiFactory } from './factories/opra-api.factory.js';
9
9
  import { NestExplorer } from './services/nest-explorer.js';
10
- import { OpraServiceLoader } from './services/service-loader.js';
10
+ import { OpraApiLoader } from './services/opra-api-loader.js';
11
11
  let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
12
12
  httpAdapterHost;
13
13
  modulesContainer;
@@ -31,7 +31,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
31
31
  },
32
32
  {
33
33
  provide: OPRA_INITIALIZER,
34
- useClass: OpraServiceLoader
34
+ useClass: OpraApiLoader
35
35
  }
36
36
  ],
37
37
  exports: [...(options.exports || [])]
@@ -49,7 +49,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
49
49
  },
50
50
  {
51
51
  provide: OPRA_INITIALIZER,
52
- useClass: OpraServiceLoader
52
+ useClass: OpraApiLoader
53
53
  },
54
54
  ...this.createAsyncProviders(asyncOptions)
55
55
  ]
@@ -111,7 +111,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
111
111
  OpraCoreModule = OpraCoreModule_1 = __decorate([
112
112
  Module({
113
113
  providers: [
114
- ServiceFactory,
114
+ OpraApiFactory,
115
115
  MetadataScanner,
116
116
  NestExplorer
117
117
  ]
@@ -119,6 +119,6 @@ OpraCoreModule = OpraCoreModule_1 = __decorate([
119
119
  __param(2, Inject(OPRA_MODULE_OPTIONS)),
120
120
  __param(3, Inject(OPRA_INITIALIZER)),
121
121
  __metadata("design:paramtypes", [HttpAdapterHost,
122
- ModulesContainer, Object, OpraServiceLoader])
122
+ ModulesContainer, Object, OpraApiLoader])
123
123
  ], OpraCoreModule);
124
124
  export { OpraCoreModule };
@@ -1,17 +1,17 @@
1
1
  import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
3
  import { OpraExpressAdapter } from '@opra/core';
4
- import { OpraService } from '@opra/schema';
5
- import { ServiceFactory } from '../factories/service.factory.js';
4
+ import { OpraDocument } from '@opra/schema';
5
+ import { OpraApiFactory } from '../factories/opra-api.factory.js';
6
6
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
7
- export declare class OpraServiceLoader {
7
+ export declare class OpraApiLoader {
8
8
  private readonly logger;
9
9
  private adapter;
10
10
  protected readonly httpAdapterHost: HttpAdapterHost;
11
11
  protected readonly applicationConfig: ApplicationConfig;
12
- protected readonly opraFactory: ServiceFactory;
12
+ protected readonly opraFactory: OpraApiFactory;
13
13
  protected readonly opraModuleOptions: OpraModuleOptions;
14
14
  initialize(rootModule: Module): Promise<void>;
15
15
  stop(): Promise<void>;
16
- protected registerExpress(service: OpraService, moduleOptions: OpraModuleOptions): Promise<OpraExpressAdapter | undefined>;
16
+ protected registerExpress(service: OpraDocument, moduleOptions: OpraModuleOptions): Promise<OpraExpressAdapter | undefined>;
17
17
  }
@@ -4,9 +4,9 @@ import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
4
4
  import { OpraExpressAdapter } from '@opra/core';
5
5
  import { joinPath, normalizePath } from '@opra/url';
6
6
  import { OPRA_MODULE_OPTIONS } from '../constants.js';
7
- import { ServiceFactory } from '../factories/service.factory.js';
8
- export class OpraServiceLoader {
9
- logger = new Logger(OpraServiceLoader.name, { timestamp: true });
7
+ import { OpraApiFactory } from '../factories/opra-api.factory.js';
8
+ export class OpraApiLoader {
9
+ logger = new Logger(OpraApiLoader.name, { timestamp: true });
10
10
  adapter;
11
11
  httpAdapterHost;
12
12
  applicationConfig;
@@ -58,16 +58,16 @@ export class OpraServiceLoader {
58
58
  __decorate([
59
59
  Inject(),
60
60
  __metadata("design:type", HttpAdapterHost)
61
- ], OpraServiceLoader.prototype, "httpAdapterHost", void 0);
61
+ ], OpraApiLoader.prototype, "httpAdapterHost", void 0);
62
62
  __decorate([
63
63
  Inject(),
64
64
  __metadata("design:type", ApplicationConfig)
65
- ], OpraServiceLoader.prototype, "applicationConfig", void 0);
65
+ ], OpraApiLoader.prototype, "applicationConfig", void 0);
66
66
  __decorate([
67
67
  Inject(),
68
- __metadata("design:type", ServiceFactory)
69
- ], OpraServiceLoader.prototype, "opraFactory", void 0);
68
+ __metadata("design:type", OpraApiFactory)
69
+ ], OpraApiLoader.prototype, "opraFactory", void 0);
70
70
  __decorate([
71
71
  Inject(OPRA_MODULE_OPTIONS),
72
72
  __metadata("design:type", Object)
73
- ], OpraServiceLoader.prototype, "opraModuleOptions", void 0);
73
+ ], OpraApiLoader.prototype, "opraModuleOptions", void 0);
@@ -1,19 +1,33 @@
1
- import { splitString } from 'fast-tokenizer';
2
- const anythingEnclosedInParenthesesRegex = /\((.+)\)/;
1
+ import { splitString, tokenize } from 'fast-tokenizer';
3
2
  export function getNumberOfArguments(fn) {
4
3
  const functionAsString = fn.toString();
5
- const parametersEnclosedInParentheses = functionAsString.match(anythingEnclosedInParenthesesRegex);
6
- if (parametersEnclosedInParentheses) {
7
- const matchString = parametersEnclosedInParentheses[1];
8
- const argumentsArray = splitString(matchString, {
9
- brackets: {
10
- '(': ')',
11
- '{': '}',
12
- '[': ']',
13
- '/*': '*/'
14
- }, delimiters: ','
15
- });
16
- return argumentsArray.length;
4
+ const tokenizer = tokenize(functionAsString, {
5
+ // keepBrackets: true,
6
+ keepDelimiters: true,
7
+ keepQuotes: true,
8
+ brackets: {}
9
+ });
10
+ let k = 0;
11
+ let s = '';
12
+ for (const token of tokenizer) {
13
+ if (token.startsWith('(')) {
14
+ s += token.substring(1);
15
+ k++;
16
+ }
17
+ else if (token.startsWith(')')) {
18
+ if (k === 1)
19
+ break;
20
+ }
21
+ else if (k)
22
+ s += token;
17
23
  }
18
- return 0;
24
+ const x = splitString(s, {
25
+ brackets: {
26
+ '{': '}',
27
+ '(': ')',
28
+ '[': ']',
29
+ '/*': '*/'
30
+ }, delimiters: ','
31
+ });
32
+ return x.length > 1 ? x.length : (x[0] ? 1 : 0);
19
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Opra NestJS module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,23 +25,23 @@
25
25
  "clean:cover": "rimraf ../../coverage/nestjs"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/core": "^0.2.0",
29
- "@opra/i18n": "^0.2.0",
30
- "@opra/schema": "^0.2.0",
31
- "@opra/url": "^0.2.0",
32
- "fast-tokenizer": "^1.1.0",
28
+ "@opra/core": "^0.4.0",
29
+ "@opra/i18n": "^0.4.0",
30
+ "@opra/schema": "^0.4.0",
31
+ "@opra/url": "^0.4.0",
32
+ "fast-tokenizer": "^1.2.0",
33
33
  "lodash": "^4.17.21",
34
34
  "reflect-metadata": "^0.1.13"
35
35
  },
36
36
  "peerDependencies": {
37
- "@nestjs/common": "^9.0.11"
37
+ "@nestjs/common": "^9.1.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@nestjs/platform-express": "^9.0.11",
41
- "@nestjs/testing": "^9.0.11",
42
- "@types/lodash": "^4.14.185",
40
+ "@nestjs/platform-express": "^9.1.4",
41
+ "@nestjs/testing": "^9.1.4",
42
+ "@types/lodash": "^4.14.186",
43
43
  "filedirname": "^2.7.0",
44
- "supertest": "^6.2.4"
44
+ "supertest": "^6.3.0"
45
45
  },
46
46
  "type": "module",
47
47
  "types": "esm/index.d.ts",