@opra/core 0.26.1 → 0.26.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.
@@ -8,7 +8,6 @@ class ExecutionContextHost extends strict_typed_events_1.AsyncEventEmitter {
8
8
  this.api = api;
9
9
  this.platform = platform;
10
10
  this.errors = [];
11
- this.session = {};
12
11
  this.ws = protocol.ws;
13
12
  this.rpc = protocol.rpc;
14
13
  if (protocol.http) {
@@ -120,7 +120,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
120
120
  let resource = this.api.root;
121
121
  let request;
122
122
  // Walk through container
123
- while (resource instanceof common_1.Container) {
123
+ while (resource instanceof common_1.Container && i < parsedUrl.path.length) {
124
124
  p = parsedUrl.path[i];
125
125
  const r = resource.resources.get(p.resource);
126
126
  if (r) {
@@ -174,7 +174,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
174
174
  return new request_host_js_1.RequestHost({
175
175
  endpoint,
176
176
  operation: 'action',
177
- action: p.resource,
177
+ action: endpoint.name,
178
178
  controller,
179
179
  handler,
180
180
  http: incoming,
package/cjs/index.js CHANGED
@@ -24,3 +24,4 @@ tslib_1.__exportStar(require("./interfaces/interceptor.interface.js"), exports);
24
24
  tslib_1.__exportStar(require("./interfaces/logger.interface.js"), exports);
25
25
  tslib_1.__exportStar(require("./interfaces/request-handler.interface.js"), exports);
26
26
  tslib_1.__exportStar(require("./services/logger.js"), exports);
27
+ tslib_1.__exportStar(require("./services/api-service.js"), exports);
@@ -110,7 +110,7 @@ class PlatformAdapterHost extends strict_typed_events_1.AsyncEventEmitter {
110
110
  const endpoint = (resource instanceof common_1.CrudResource && resource.operations.get(operationOrAction)) ||
111
111
  resource.actions.get(operationOrAction);
112
112
  if (endpoint) {
113
- const handler = typeof controller[operationOrAction] === 'function' ? controller[operationOrAction] : undefined;
113
+ const handler = typeof controller[endpoint.name] === 'function' ? controller[endpoint.name] : undefined;
114
114
  if (handler)
115
115
  return { controller, endpoint, handler };
116
116
  }
@@ -7,7 +7,6 @@ var RequestContext;
7
7
  const out = {
8
8
  request,
9
9
  response,
10
- session: {}
11
10
  };
12
11
  Object.setPrototypeOf(out, executionContext);
13
12
  return out;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiService = void 0;
4
+ class ApiService {
5
+ get context() {
6
+ if (!this._context)
7
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).name}`);
8
+ return this._context;
9
+ }
10
+ forContext(context) {
11
+ const instance = { context };
12
+ Object.setPrototypeOf(instance, this);
13
+ return instance;
14
+ }
15
+ }
16
+ exports.ApiService = ApiService;
@@ -5,7 +5,6 @@ export class ExecutionContextHost extends AsyncEventEmitter {
5
5
  this.api = api;
6
6
  this.platform = platform;
7
7
  this.errors = [];
8
- this.session = {};
9
8
  this.ws = protocol.ws;
10
9
  this.rpc = protocol.rpc;
11
10
  if (protocol.http) {
@@ -116,7 +116,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
116
116
  let resource = this.api.root;
117
117
  let request;
118
118
  // Walk through container
119
- while (resource instanceof Container) {
119
+ while (resource instanceof Container && i < parsedUrl.path.length) {
120
120
  p = parsedUrl.path[i];
121
121
  const r = resource.resources.get(p.resource);
122
122
  if (r) {
@@ -170,7 +170,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
170
170
  return new RequestHost({
171
171
  endpoint,
172
172
  operation: 'action',
173
- action: p.resource,
173
+ action: endpoint.name,
174
174
  controller,
175
175
  handler,
176
176
  http: incoming,
package/esm/index.js CHANGED
@@ -21,3 +21,4 @@ export * from './interfaces/interceptor.interface.js';
21
21
  export * from './interfaces/logger.interface.js';
22
22
  export * from './interfaces/request-handler.interface.js';
23
23
  export * from './services/logger.js';
24
+ export * from './services/api-service.js';
@@ -106,7 +106,7 @@ export class PlatformAdapterHost extends AsyncEventEmitter {
106
106
  const endpoint = (resource instanceof CrudResource && resource.operations.get(operationOrAction)) ||
107
107
  resource.actions.get(operationOrAction);
108
108
  if (endpoint) {
109
- const handler = typeof controller[operationOrAction] === 'function' ? controller[operationOrAction] : undefined;
109
+ const handler = typeof controller[endpoint.name] === 'function' ? controller[endpoint.name] : undefined;
110
110
  if (handler)
111
111
  return { controller, endpoint, handler };
112
112
  }
@@ -4,7 +4,6 @@ export var RequestContext;
4
4
  const out = {
5
5
  request,
6
6
  response,
7
- session: {}
8
7
  };
9
8
  Object.setPrototypeOf(out, executionContext);
10
9
  return out;
@@ -0,0 +1,12 @@
1
+ export class ApiService {
2
+ get context() {
3
+ if (!this._context)
4
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).name}`);
5
+ return this._context;
6
+ }
7
+ forContext(context) {
8
+ const instance = { context };
9
+ Object.setPrototypeOf(instance, this);
10
+ return instance;
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "0.26.1",
3
+ "version": "0.26.4",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "clean:cover": "rimraf ../../coverage/core"
28
28
  },
29
29
  "dependencies": {
30
- "@opra/common": "^0.26.1",
30
+ "@opra/common": "^0.26.4",
31
31
  "accepts": "^1.3.8",
32
32
  "content-disposition": "^0.5.4",
33
33
  "content-type": "^1.0.5",
@@ -8,7 +8,7 @@ declare module "@opra/common" {
8
8
  operation: 'action';
9
9
  action: string;
10
10
  }
11
- interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
11
+ interface Context extends Resource.Context {
12
12
  }
13
13
  }
14
14
  namespace Create {
@@ -22,7 +22,7 @@ declare module "@opra/common" {
22
22
  [key: string]: any;
23
23
  };
24
24
  }
25
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
25
+ interface Context extends RequestContext {
26
26
  request: Request;
27
27
  }
28
28
  }
@@ -31,7 +31,7 @@ declare module "@opra/common" {
31
31
  operation: 'delete';
32
32
  key: any;
33
33
  }
34
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
34
+ interface Context extends RequestContext {
35
35
  request: Request;
36
36
  }
37
37
  }
@@ -43,7 +43,7 @@ declare module "@opra/common" {
43
43
  [key: string]: any;
44
44
  };
45
45
  }
46
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
46
+ interface Context extends RequestContext {
47
47
  request: Request;
48
48
  }
49
49
  }
@@ -63,7 +63,7 @@ declare module "@opra/common" {
63
63
  [key: string]: any;
64
64
  };
65
65
  }
66
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
66
+ interface Context extends RequestContext {
67
67
  request: Request;
68
68
  }
69
69
  }
@@ -78,7 +78,7 @@ declare module "@opra/common" {
78
78
  [key: string]: any;
79
79
  };
80
80
  }
81
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
81
+ interface Context extends RequestContext {
82
82
  request: Request;
83
83
  }
84
84
  }
@@ -94,7 +94,7 @@ declare module "@opra/common" {
94
94
  [key: string]: any;
95
95
  };
96
96
  }
97
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
97
+ interface Context extends RequestContext {
98
98
  request: Request;
99
99
  }
100
100
  }
@@ -107,7 +107,7 @@ declare module "@opra/common" {
107
107
  [key: string]: any;
108
108
  };
109
109
  }
110
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
110
+ interface Context extends RequestContext {
111
111
  request: Request;
112
112
  }
113
113
  }
@@ -6,7 +6,7 @@ declare module "@opra/common" {
6
6
  operation: 'action';
7
7
  action: string;
8
8
  }
9
- interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
9
+ interface Context extends Resource.Context {
10
10
  }
11
11
  }
12
12
  }
@@ -9,7 +9,7 @@ declare module "@opra/common" {
9
9
  OnShutdown(): any;
10
10
  }
11
11
  namespace Resource {
12
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
12
+ interface Context extends RequestContext {
13
13
  params: Record<string, any>;
14
14
  }
15
15
  }
@@ -8,7 +8,7 @@ declare module "@opra/common" {
8
8
  operation: 'action';
9
9
  action: string;
10
10
  }
11
- interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
11
+ interface Context extends Resource.Context {
12
12
  }
13
13
  }
14
14
  namespace Create {
@@ -21,7 +21,7 @@ declare module "@opra/common" {
21
21
  include?: string[];
22
22
  };
23
23
  }
24
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
24
+ interface Context extends RequestContext {
25
25
  request: Request;
26
26
  }
27
27
  }
@@ -29,7 +29,7 @@ declare module "@opra/common" {
29
29
  interface Request extends _Request {
30
30
  operation: 'delete';
31
31
  }
32
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
32
+ interface Context extends RequestContext {
33
33
  request: Request;
34
34
  }
35
35
  }
@@ -42,7 +42,7 @@ declare module "@opra/common" {
42
42
  include?: string[];
43
43
  };
44
44
  }
45
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
45
+ interface Context extends RequestContext {
46
46
  request: Request;
47
47
  }
48
48
  }
@@ -56,7 +56,7 @@ declare module "@opra/common" {
56
56
  include?: string[];
57
57
  };
58
58
  }
59
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
59
+ interface Context extends RequestContext {
60
60
  request: Request;
61
61
  }
62
62
  }
@@ -8,7 +8,7 @@ declare module "@opra/common" {
8
8
  operation: 'action';
9
9
  action: string;
10
10
  }
11
- interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
11
+ interface Context extends Resource.Context {
12
12
  }
13
13
  }
14
14
  namespace Delete {
@@ -16,7 +16,7 @@ declare module "@opra/common" {
16
16
  operation: 'delete';
17
17
  path?: string;
18
18
  }
19
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
19
+ interface Context extends RequestContext {
20
20
  request: Request;
21
21
  }
22
22
  }
@@ -25,7 +25,7 @@ declare module "@opra/common" {
25
25
  operation: 'get';
26
26
  path?: string;
27
27
  }
28
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
28
+ interface Context extends RequestContext {
29
29
  request: Request;
30
30
  }
31
31
  }
@@ -35,7 +35,7 @@ declare module "@opra/common" {
35
35
  path?: string;
36
36
  parts: MultipartIterator;
37
37
  }
38
- interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
38
+ interface Context extends RequestContext {
39
39
  request: Request;
40
40
  }
41
41
  }
@@ -1,10 +1,9 @@
1
1
  import type { HttpServerRequest } from './http/http-server-request.js';
2
2
  import type { HttpServerResponse } from './http/http-server-response.js';
3
3
  import type { Protocol } from './platform-adapter.js';
4
- export interface ExecutionContext<TSession extends {} = {}> {
4
+ export interface ExecutionContext {
5
5
  readonly protocol: Protocol;
6
6
  readonly platform: string;
7
- session: TSession;
8
7
  errors: Error[];
9
8
  switchToHttp(): HttpMessageContext;
10
9
  switchToWs(): WsMessageContext;
@@ -4,7 +4,7 @@ import type { ExecutionContext, HttpMessageContext, RpcMessageContext, WsMessage
4
4
  import type { HttpServerRequest } from './http/http-server-request.js';
5
5
  import type { HttpServerResponse } from './http/http-server-response.js';
6
6
  import { Protocol } from './platform-adapter.js';
7
- export declare class ExecutionContextHost<TSession extends {} = {}> extends AsyncEventEmitter implements ExecutionContext<TSession> {
7
+ export declare class ExecutionContextHost extends AsyncEventEmitter implements ExecutionContext {
8
8
  readonly api: ApiDocument;
9
9
  readonly platform: string;
10
10
  readonly protocol: Protocol;
@@ -12,7 +12,6 @@ export declare class ExecutionContextHost<TSession extends {} = {}> extends Asyn
12
12
  readonly ws?: WsMessageContext;
13
13
  readonly rpc?: RpcMessageContext;
14
14
  errors: Error[];
15
- session: TSession;
16
15
  constructor(api: ApiDocument, platform: string, protocol: {
17
16
  http?: {
18
17
  incoming: HttpServerRequest;
package/types/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from './interfaces/interceptor.interface.js';
21
21
  export * from './interfaces/logger.interface.js';
22
22
  export * from './interfaces/request-handler.interface.js';
23
23
  export * from './services/logger.js';
24
+ export * from './services/api-service.js';
@@ -1,7 +1,7 @@
1
1
  import type { ExecutionContext } from './execution-context.js';
2
2
  import type { Request } from './request.js';
3
3
  import type { Response } from './response.js';
4
- export interface RequestContext<TSession extends {} = {}> extends ExecutionContext<TSession> {
4
+ export interface RequestContext extends ExecutionContext {
5
5
  request: Request;
6
6
  response: Response;
7
7
  }
@@ -0,0 +1,6 @@
1
+ import { RequestContext } from '../request-context.js';
2
+ export declare abstract class ApiService {
3
+ protected _context: RequestContext;
4
+ get context(): RequestContext;
5
+ forContext(context: RequestContext): typeof this;
6
+ }