@opra/nestjs 0.3.0 → 0.5.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.
@@ -16,7 +16,6 @@ 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
20
  let OpraApiFactory = class OpraApiFactory {
22
21
  paramsFactory = new params_factory_js_1.OpraParamsFactory();
@@ -28,10 +27,11 @@ let OpraApiFactory = class OpraApiFactory {
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 OpraApiFactory = class OpraApiFactory {
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 OpraApiFactory = class OpraApiFactory {
108
108
  });
109
109
  }
110
110
  }
111
- return await schema_1.OpraApi.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;
@@ -1,6 +1,6 @@
1
1
  import { ContextType } from '@nestjs/common';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
- import { OpraApi } from '@opra/schema';
3
+ import { OpraDocument } from '@opra/schema';
4
4
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
5
5
  export declare class OpraApiFactory {
6
6
  private readonly paramsFactory;
@@ -8,7 +8,7 @@ export declare class OpraApiFactory {
8
8
  private readonly modulesContainer;
9
9
  private readonly externalContextCreator;
10
10
  private readonly explorerService;
11
- generateService(rootModule: Module, moduleOptions: OpraModuleOptions, contextType: ContextType): Promise<OpraApi>;
11
+ generateService(rootModule: Module, moduleOptions: OpraModuleOptions, contextType: ContextType): Promise<OpraDocument>;
12
12
  private _createContextCallback;
13
13
  private getContextId;
14
14
  private registerContextProvider;
@@ -6,14 +6,13 @@ 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 { OpraApi, OpraSchema, 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
17
  let OpraApiFactory = class OpraApiFactory {
19
18
  paramsFactory = new OpraParamsFactory();
@@ -25,10 +24,11 @@ let OpraApiFactory = class OpraApiFactory {
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 OpraApiFactory = class OpraApiFactory {
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 OpraApiFactory = class OpraApiFactory {
105
105
  });
106
106
  }
107
107
  }
108
- return await OpraApi.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;
@@ -1,7 +1,7 @@
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 { OpraApi } from '@opra/schema';
4
+ import { OpraDocument } from '@opra/schema';
5
5
  import { OpraApiFactory } from '../factories/opra-api.factory.js';
6
6
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
7
7
  export declare class OpraApiLoader {
@@ -13,5 +13,5 @@ export declare class OpraApiLoader {
13
13
  protected readonly opraModuleOptions: OpraModuleOptions;
14
14
  initialize(rootModule: Module): Promise<void>;
15
15
  stop(): Promise<void>;
16
- protected registerExpress(service: OpraApi, moduleOptions: OpraModuleOptions): Promise<OpraExpressAdapter | undefined>;
16
+ protected registerExpress(service: OpraDocument, moduleOptions: OpraModuleOptions): Promise<OpraExpressAdapter | undefined>;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.3.0",
3
+ "version": "0.5.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.3.0",
29
- "@opra/i18n": "^0.3.0",
30
- "@opra/schema": "^0.3.0",
31
- "@opra/url": "^0.3.0",
32
- "fast-tokenizer": "^1.1.0",
28
+ "@opra/core": "^0.5.0",
29
+ "@opra/i18n": "^0.5.0",
30
+ "@opra/schema": "^0.5.0",
31
+ "@opra/url": "^0.5.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",