@opra/core 0.31.4 → 0.31.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.
@@ -100,7 +100,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
100
100
  try {
101
101
  const { outgoing } = executionContext.switchToHttp();
102
102
  const response = new response_host_js_1.ResponseHost({ http: outgoing });
103
- const context = request_context_js_1.RequestContext.from(executionContext, request, response);
103
+ const context = request_context_js_1.RequestContext.from(executionContext, this.api, request, response);
104
104
  await this.executeRequest(context);
105
105
  await this.sendResponse(context);
106
106
  }
@@ -617,7 +617,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
617
617
  if (returnType) {
618
618
  if (response.value == null)
619
619
  throw new common_1.InternalServerError(`"${request.endpoint.name}" endpoint should return value`);
620
- if (returnType.name) {
620
+ if (!returnType.isAnonymous) {
621
621
  const ns = this.api.getDataTypeNs(returnType);
622
622
  // const isOpraSpec = returnType.document.url?.startsWith('https://oprajs.com/spec/v1.0')
623
623
  body.type = (ns ? ns + ':' : '') + returnType.name;
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestContext = void 0;
4
4
  var RequestContext;
5
5
  (function (RequestContext) {
6
- function from(executionContext, request, response) {
6
+ function from(executionContext, api, request, response) {
7
7
  const out = {
8
+ api,
8
9
  request,
9
10
  response
10
11
  };
@@ -7,7 +7,9 @@ class ApiService {
7
7
  throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
8
8
  return this._context;
9
9
  }
10
- forContext(context) {
10
+ forContext(context, options) {
11
+ if (this._context === context && !options?.newInstance)
12
+ return this;
11
13
  const instance = { context };
12
14
  Object.setPrototypeOf(instance, this);
13
15
  return instance;
@@ -96,7 +96,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
96
96
  try {
97
97
  const { outgoing } = executionContext.switchToHttp();
98
98
  const response = new ResponseHost({ http: outgoing });
99
- const context = RequestContext.from(executionContext, request, response);
99
+ const context = RequestContext.from(executionContext, this.api, request, response);
100
100
  await this.executeRequest(context);
101
101
  await this.sendResponse(context);
102
102
  }
@@ -613,7 +613,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
613
613
  if (returnType) {
614
614
  if (response.value == null)
615
615
  throw new InternalServerError(`"${request.endpoint.name}" endpoint should return value`);
616
- if (returnType.name) {
616
+ if (!returnType.isAnonymous) {
617
617
  const ns = this.api.getDataTypeNs(returnType);
618
618
  // const isOpraSpec = returnType.document.url?.startsWith('https://oprajs.com/spec/v1.0')
619
619
  body.type = (ns ? ns + ':' : '') + returnType.name;
@@ -1,7 +1,8 @@
1
1
  export var RequestContext;
2
2
  (function (RequestContext) {
3
- function from(executionContext, request, response) {
3
+ function from(executionContext, api, request, response) {
4
4
  const out = {
5
+ api,
5
6
  request,
6
7
  response
7
8
  };
@@ -4,7 +4,9 @@ export class ApiService {
4
4
  throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
5
5
  return this._context;
6
6
  }
7
- forContext(context) {
7
+ forContext(context, options) {
8
+ if (this._context === context && !options?.newInstance)
9
+ return this;
8
10
  const instance = { context };
9
11
  Object.setPrototypeOf(instance, this);
10
12
  return instance;
@@ -0,0 +1,21 @@
1
+ {
2
+ "BAD_REQUEST": "Bad request",
3
+ "FAILED_DEPENDENCY": "The request failed due to failure of a previous request",
4
+ "FORBIDDEN": "You are not authorized to perform this action",
5
+ "INTERNAL_SERVER_ERROR": "Internal server error",
6
+ "METHOD_NOT_ALLOWED": "Method not allowed",
7
+ "NOT_ACCEPTABLE": "Not acceptable",
8
+ "NOT_FOUND": "Not found",
9
+ "UNAUTHORIZED": "You have not been authenticated to perform this action",
10
+ "UNPROCESSABLE_ENTITY": "Unprocessable entity",
11
+ "REQUEST_VALIDATION": "Request validation failed",
12
+ "RESPONSE_VALIDATION": "Response validation failed",
13
+ "RESOURCE_NOT_FOUND": "Resource not found",
14
+ "RESOURCE_CONFLICT": "There is already an other {{resource}} resource with same field values ({{fields}})",
15
+ "OPERATION_FORBIDDEN": "The {{resource}} resource does not accept '{{operation}}' operations",
16
+ "ACTION_NOT_FOUND": "The {{resource}} resource doesn't have an action named '{{action}}'",
17
+ "UNKNOWN_FIELD": "Unknown field '{{field}}'",
18
+ "UNACCEPTED_SORT_FIELD": "Field '{{field}}' is not available for sort operation",
19
+ "UNACCEPTED_FILTER_FIELD": "Field '{{field}}' is not available for filter operation",
20
+ "UNACCEPTED_FILTER_OPERATION": "'{{operation}}' for field '{{field}}' is not available for filter operation"
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "0.31.4",
3
+ "version": "0.31.5",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -21,14 +21,15 @@
21
21
  "lint": "eslint . --max-warnings=0",
22
22
  "test": "jest",
23
23
  "cover": "jest --collect-coverage",
24
- "clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
25
- "clean:src": "ts-cleanup -s src --all && ts-cleanup -s test --all",
26
- "clean:dist": "rimraf ../../build/core",
27
- "clean:cover": "rimraf ../../coverage/core"
24
+ "clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
25
+ "clean:src": "ts-cleanup -s src --all",
26
+ "clean:test": "ts-cleanup -s test --all",
27
+ "clean:dist": "rimraf ../../build/client",
28
+ "clean:cover": "rimraf ../../coverage/client"
28
29
  },
29
30
  "dependencies": {
30
31
  "@browsery/type-is": "^0.6.3",
31
- "@opra/common": "^0.31.4",
32
+ "@opra/common": "^0.31.5",
32
33
  "accepts": "^1.3.8",
33
34
  "content-disposition": "^0.5.4",
34
35
  "content-type": "^1.0.5",
@@ -7,6 +7,9 @@ declare module "@opra/common" {
7
7
  namespace Action {
8
8
  interface Request extends StrictOmit<_Request, 'endpoint'> {
9
9
  endpoint: _Action;
10
+ params: {
11
+ [key: string]: any;
12
+ };
10
13
  }
11
14
  interface Context extends Resource.Context {
12
15
  }
@@ -34,6 +37,9 @@ declare module "@opra/common" {
34
37
  name: 'delete';
35
38
  };
36
39
  key: any;
40
+ params: {
41
+ [key: string]: any;
42
+ };
37
43
  }
38
44
  interface Context extends RequestContext {
39
45
  request: Request;
@@ -21,6 +21,7 @@ declare module "@opra/common" {
21
21
  pick?: string[];
22
22
  omit?: string[];
23
23
  include?: string[];
24
+ [key: string]: any;
24
25
  };
25
26
  }
26
27
  interface Context extends RequestContext {
@@ -46,6 +47,7 @@ declare module "@opra/common" {
46
47
  pick?: string[];
47
48
  omit?: string[];
48
49
  include?: string[];
50
+ [key: string]: any;
49
51
  };
50
52
  }
51
53
  interface Context extends RequestContext {
@@ -62,6 +64,7 @@ declare module "@opra/common" {
62
64
  pick?: string[];
63
65
  omit?: string[];
64
66
  include?: string[];
67
+ [key: string]: any;
65
68
  };
66
69
  }
67
70
  interface Context extends RequestContext {
@@ -1,10 +1,12 @@
1
+ import { ApiDocument } from '@opra/common';
1
2
  import type { ExecutionContext } from './execution-context.js';
2
3
  import type { Request } from './request.js';
3
4
  import type { Response } from './response.js';
4
5
  export interface RequestContext extends ExecutionContext {
5
6
  request: Request;
6
7
  response: Response;
8
+ api: ApiDocument;
7
9
  }
8
10
  export declare namespace RequestContext {
9
- function from(executionContext: ExecutionContext, request: Request, response: Response): RequestContext;
11
+ function from(executionContext: ExecutionContext, api: ApiDocument, request: Request, response: Response): RequestContext;
10
12
  }
@@ -2,5 +2,7 @@ import { RequestContext } from '../request-context.js';
2
2
  export declare abstract class ApiService {
3
3
  protected _context: RequestContext;
4
4
  get context(): RequestContext;
5
- forContext(context: RequestContext): this;
5
+ forContext(context: RequestContext, options?: {
6
+ newInstance?: boolean;
7
+ }): this;
6
8
  }