@opra/core 0.33.13 → 1.0.0-alpha.1

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.
Files changed (155) hide show
  1. package/cjs/augmentation/18n.augmentation.js +17 -4
  2. package/cjs/augmentation/http-controller.augmentation.js +25 -0
  3. package/cjs/constants.js +5 -0
  4. package/cjs/execution-context.js +25 -12
  5. package/cjs/{services → helpers}/logger.js +1 -2
  6. package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
  7. package/cjs/http/express-adapter.js +164 -0
  8. package/cjs/http/http-adapter.js +27 -0
  9. package/cjs/http/http-context.js +116 -0
  10. package/cjs/http/impl/asset-cache.js +21 -0
  11. package/cjs/http/impl/http-handler.js +575 -0
  12. package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +21 -46
  13. package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -26
  14. package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +24 -22
  15. package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +13 -54
  16. package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
  17. package/cjs/http/interfaces/http-incoming.interface.js +25 -0
  18. package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
  19. package/cjs/http/interfaces/node-incoming-message.interface.js +63 -0
  20. package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
  21. package/cjs/http/utils/body-reader.js +215 -0
  22. package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
  23. package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
  24. package/cjs/http/utils/wrap-exception.js +34 -0
  25. package/cjs/index.js +25 -25
  26. package/cjs/platform-adapter.js +21 -0
  27. package/cjs/type-guards.js +23 -0
  28. package/esm/augmentation/18n.augmentation.js +20 -7
  29. package/esm/augmentation/http-controller.augmentation.js +23 -0
  30. package/esm/constants.js +2 -0
  31. package/esm/execution-context.js +25 -13
  32. package/esm/{services → helpers}/logger.js +1 -2
  33. package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
  34. package/esm/http/express-adapter.js +159 -0
  35. package/esm/http/http-adapter.js +23 -0
  36. package/esm/http/http-context.js +111 -0
  37. package/esm/http/impl/asset-cache.js +17 -0
  38. package/esm/http/impl/http-handler.js +570 -0
  39. package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +17 -43
  40. package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +6 -26
  41. package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +22 -20
  42. package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +11 -52
  43. package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
  44. package/esm/http/interfaces/http-incoming.interface.js +22 -0
  45. package/esm/http/interfaces/http-outgoing.interface.js +19 -0
  46. package/esm/http/interfaces/node-incoming-message.interface.js +60 -0
  47. package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
  48. package/esm/http/utils/body-reader.js +210 -0
  49. package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
  50. package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
  51. package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
  52. package/esm/http/utils/wrap-exception.js +30 -0
  53. package/esm/index.js +25 -26
  54. package/esm/platform-adapter.js +19 -1
  55. package/esm/type-guards.js +16 -0
  56. package/package.json +21 -9
  57. package/types/augmentation/18n.augmentation.d.ts +32 -2
  58. package/types/augmentation/http-controller.augmentation.d.ts +21 -0
  59. package/types/constants.d.ts +2 -0
  60. package/types/execution-context.d.ts +24 -26
  61. package/types/helpers/service-base.d.ts +10 -0
  62. package/types/http/express-adapter.d.ts +13 -0
  63. package/types/http/http-adapter.d.ts +27 -0
  64. package/types/http/http-context.d.ts +44 -0
  65. package/types/http/impl/asset-cache.d.ts +5 -0
  66. package/types/http/impl/http-handler.d.ts +73 -0
  67. package/types/http/impl/http-incoming.host.d.ts +23 -0
  68. package/types/http/impl/http-outgoing.host.d.ts +17 -0
  69. package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
  70. package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +9 -22
  71. package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
  72. package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
  73. package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
  74. package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
  75. package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
  76. package/types/http/utils/body-reader.d.ts +41 -0
  77. package/types/http/utils/wrap-exception.d.ts +2 -0
  78. package/types/index.d.ts +24 -26
  79. package/types/platform-adapter.d.ts +20 -48
  80. package/types/type-guards.d.ts +8 -0
  81. package/cjs/augmentation/collection.augmentation.js +0 -2
  82. package/cjs/augmentation/container.augmentation.js +0 -2
  83. package/cjs/augmentation/resource.augmentation.js +0 -26
  84. package/cjs/augmentation/singleton.augmentation.js +0 -2
  85. package/cjs/augmentation/storage.augmentation.js +0 -2
  86. package/cjs/execution-context.host.js +0 -46
  87. package/cjs/http/adapters/express-adapter.host.js +0 -34
  88. package/cjs/http/adapters/express-adapter.js +0 -14
  89. package/cjs/http/adapters/node-http-adapter.host.js +0 -70
  90. package/cjs/http/adapters/node-http-adapter.js +0 -14
  91. package/cjs/http/helpers/json-body-loader.js +0 -29
  92. package/cjs/http/helpers/query-parsers.js +0 -16
  93. package/cjs/http/http-adapter-host.js +0 -715
  94. package/cjs/interfaces/interceptor.interface.js +0 -2
  95. package/cjs/interfaces/request-handler.interface.js +0 -2
  96. package/cjs/platform-adapter.host.js +0 -154
  97. package/cjs/request-context.js +0 -25
  98. package/cjs/request.host.js +0 -24
  99. package/cjs/request.js +0 -2
  100. package/cjs/response.host.js +0 -22
  101. package/cjs/response.js +0 -2
  102. package/esm/augmentation/collection.augmentation.js +0 -1
  103. package/esm/augmentation/container.augmentation.js +0 -1
  104. package/esm/augmentation/resource.augmentation.js +0 -24
  105. package/esm/augmentation/singleton.augmentation.js +0 -1
  106. package/esm/augmentation/storage.augmentation.js +0 -1
  107. package/esm/execution-context.host.js +0 -42
  108. package/esm/http/adapters/express-adapter.host.js +0 -30
  109. package/esm/http/adapters/express-adapter.js +0 -11
  110. package/esm/http/adapters/node-http-adapter.host.js +0 -65
  111. package/esm/http/adapters/node-http-adapter.js +0 -11
  112. package/esm/http/helpers/json-body-loader.js +0 -24
  113. package/esm/http/helpers/query-parsers.js +0 -12
  114. package/esm/http/http-adapter-host.js +0 -710
  115. package/esm/interfaces/interceptor.interface.js +0 -1
  116. package/esm/interfaces/request-handler.interface.js +0 -1
  117. package/esm/platform-adapter.host.js +0 -149
  118. package/esm/request-context.js +0 -22
  119. package/esm/request.host.js +0 -20
  120. package/esm/request.js +0 -1
  121. package/esm/response.host.js +0 -18
  122. package/esm/response.js +0 -1
  123. package/types/augmentation/collection.augmentation.d.ts +0 -146
  124. package/types/augmentation/container.augmentation.d.ts +0 -14
  125. package/types/augmentation/resource.augmentation.d.ts +0 -38
  126. package/types/augmentation/singleton.augmentation.d.ts +0 -83
  127. package/types/augmentation/storage.augmentation.d.ts +0 -50
  128. package/types/execution-context.host.d.ts +0 -25
  129. package/types/http/adapters/express-adapter.d.ts +0 -15
  130. package/types/http/adapters/express-adapter.host.d.ts +0 -12
  131. package/types/http/adapters/node-http-adapter.d.ts +0 -17
  132. package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
  133. package/types/http/helpers/json-body-loader.d.ts +0 -5
  134. package/types/http/helpers/query-parsers.d.ts +0 -1
  135. package/types/http/http-adapter-host.d.ts +0 -34
  136. package/types/interfaces/interceptor.interface.d.ts +0 -2
  137. package/types/interfaces/request-handler.interface.d.ts +0 -4
  138. package/types/platform-adapter.host.d.ts +0 -43
  139. package/types/request-context.d.ts +0 -13
  140. package/types/request.d.ts +0 -14
  141. package/types/request.host.d.ts +0 -27
  142. package/types/response.d.ts +0 -22
  143. package/types/response.host.d.ts +0 -22
  144. package/types/services/api-service.d.ts +0 -10
  145. /package/cjs/http/{helpers → utils}/common.js +0 -0
  146. /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
  147. /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
  148. /package/esm/http/{helpers → utils}/common.js +0 -0
  149. /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
  150. /package/types/{services → helpers}/logger.d.ts +0 -0
  151. /package/types/http/{helpers → utils}/common.d.ts +0 -0
  152. /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
  153. /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
  154. /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
  155. /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
@@ -1,34 +0,0 @@
1
- import { Collection, OpraURLPath, Parameter, Resource, Singleton, Storage } from '@opra/common';
2
- import { ExecutionContext } from '../execution-context.js';
3
- import { PlatformAdapterHost } from '../platform-adapter.host.js';
4
- import type { Protocol } from '../platform-adapter.js';
5
- import { RequestHost } from '../request.host.js';
6
- import { Request } from '../request.js';
7
- import { RequestContext } from '../request-context.js';
8
- import { HttpServerRequest } from './http-server-request.js';
9
- import { HttpServerResponse } from './http-server-response.js';
10
- /**
11
- *
12
- * @class HttpAdapterHost
13
- */
14
- export declare abstract class HttpAdapterHost extends PlatformAdapterHost {
15
- protected _protocol: Protocol;
16
- protected _tempDir: string;
17
- /**
18
- * Main http request handler
19
- * @param incoming
20
- * @param outgoing
21
- * @protected
22
- */
23
- protected handleHttp(incoming: HttpServerRequest, outgoing: HttpServerResponse): Promise<void>;
24
- handleExecution(executionContext: ExecutionContext): Promise<void>;
25
- parseRequest(executionContext: ExecutionContext): Promise<Request>;
26
- protected _parseRequestAction(executionContext: ExecutionContext, resource: Resource, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
27
- protected _parseRequestCollection(executionContext: ExecutionContext, resource: Collection, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
28
- protected _parseRequestSingleton(executionContext: ExecutionContext, resource: Singleton, urlPath: OpraURLPath, searchParams?: URLSearchParams): Promise<RequestHost>;
29
- protected _parseRequestStorage(executionContext: ExecutionContext, resource: Storage, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
30
- protected parseParameters(paramDefs: Map<string, Parameter>, searchParams?: URLSearchParams): Record<string, any>;
31
- protected executeRequest(context: RequestContext): Promise<void>;
32
- sendResponse(context: RequestContext): Promise<void>;
33
- protected sendErrorResponse(context: ExecutionContext, errors: any[]): Promise<void>;
34
- }
@@ -1,2 +0,0 @@
1
- import { ExecutionContext } from '../execution-context.js';
2
- export type Interceptor = (context: ExecutionContext, next: (() => Promise<void>)) => Promise<void>;
@@ -1,4 +0,0 @@
1
- import type { ExecutionContext } from '../execution-context.js';
2
- export interface RequestHandler {
3
- handleExecution(executionContext: ExecutionContext): Promise<void>;
4
- }
@@ -1,43 +0,0 @@
1
- import './augmentation/18n.augmentation.js';
2
- import { AsyncEventEmitter } from 'strict-typed-events';
3
- import { Action, ApiDocument, CrudOperation, I18n, Resource } from '@opra/common';
4
- import { ExecutionContext } from './execution-context.js';
5
- import { Interceptor } from './interfaces/interceptor.interface.js';
6
- import type { PlatformAdapter, Protocol } from './platform-adapter.js';
7
- import { Logger } from './services/logger.js';
8
- /**
9
- * @class PlatformAdapterHost
10
- */
11
- export declare abstract class PlatformAdapterHost extends AsyncEventEmitter implements PlatformAdapter {
12
- protected _api: ApiDocument;
13
- protected _controllers: Map<Resource, any>;
14
- protected _protocol: Protocol;
15
- protected _platform: string;
16
- protected _serviceName: string;
17
- protected _i18n: I18n;
18
- protected _logger: Logger;
19
- protected _interceptors: Interceptor[];
20
- get api(): ApiDocument;
21
- get platform(): string;
22
- get protocol(): Protocol;
23
- get serviceName(): string;
24
- get i18n(): I18n;
25
- close(): Promise<void>;
26
- /**
27
- * Initializes the adapter
28
- */
29
- protected init(api: ApiDocument, options?: PlatformAdapter.Options): Promise<void>;
30
- getController(resource: Resource | string): Promise<any>;
31
- getActionHandler(resource: Resource | string, name: string): Promise<{
32
- endpoint: Action;
33
- controller: any;
34
- handler: Function;
35
- }>;
36
- getOperationHandler(resource: Resource | string, name: string): Promise<{
37
- endpoint: CrudOperation;
38
- controller: any;
39
- handler: Function;
40
- }>;
41
- protected _createI18n(options?: PlatformAdapter.I18nOptions): Promise<I18n>;
42
- abstract handleExecution(executionContext: ExecutionContext): Promise<void>;
43
- }
@@ -1,13 +0,0 @@
1
- import { ApiDocument } from '@opra/common';
2
- import { ExecutionContext } from './execution-context.js';
3
- import type { Request } from './request.js';
4
- import type { Response } from './response.js';
5
- export interface RequestContext extends ExecutionContext {
6
- request: Request;
7
- response: Response;
8
- api: ApiDocument;
9
- }
10
- export declare namespace RequestContext {
11
- function from(executionContext: ExecutionContext, api: ApiDocument, request: Request, response: Response): RequestContext;
12
- function is(v: any): v is RequestContext;
13
- }
@@ -1,14 +0,0 @@
1
- import { Action, CrudOperation, Resource } from '@opra/common';
2
- import { HttpServerRequest } from './http/http-server-request.js';
3
- export interface Request {
4
- resource: Resource;
5
- endpoint: Action | CrudOperation;
6
- key?: any;
7
- controller: Object;
8
- handler: Function;
9
- contentId?: string;
10
- params: Record<string, any>;
11
- switchToHttp(): HttpServerRequest;
12
- switchToWs(): never;
13
- switchToRpc(): never;
14
- }
@@ -1,27 +0,0 @@
1
- import type { PartialSome, StrictOmit } from 'ts-gems';
2
- import type { Resource } from '@opra/common';
3
- import { Action, CrudOperation } from '@opra/common';
4
- import type { HttpServerRequest } from './http/http-server-request.js';
5
- import type { Request } from './request.js';
6
- export declare namespace RequestHost {
7
- interface Initiator extends PartialSome<StrictOmit<Request, 'resource' | 'switchToHttp' | 'switchToWs' | 'switchToRpc'>, 'params'> {
8
- controller: Object;
9
- handler: Function;
10
- http?: HttpServerRequest;
11
- [key: string]: any;
12
- }
13
- }
14
- export interface RequestHost extends Request {
15
- }
16
- export declare class RequestHost implements Request {
17
- controller: any;
18
- endpoint: Action | CrudOperation;
19
- http?: HttpServerRequest;
20
- key?: any;
21
- params: Record<string, any>;
22
- constructor(init: RequestHost.Initiator);
23
- get resource(): Resource;
24
- switchToHttp(): HttpServerRequest;
25
- switchToWs(): never;
26
- switchToRpc(): never;
27
- }
@@ -1,22 +0,0 @@
1
- import type { HttpServerResponse } from './http/http-server-response.js';
2
- export interface Response {
3
- /**
4
- * Result value
5
- */
6
- value?: any;
7
- /**
8
- * List of errors
9
- */
10
- errors: any[];
11
- /**
12
- *
13
- */
14
- continueOnError?: boolean;
15
- /**
16
- * Total count of matched entities. (Used in "search" endpoint with "count" option
17
- */
18
- totalMatches?: number;
19
- switchToHttp(): HttpServerResponse;
20
- switchToWs(): never;
21
- switchToRpc(): never;
22
- }
@@ -1,22 +0,0 @@
1
- import type { HttpServerResponse } from './http/http-server-response.js';
2
- import type { Response } from './response.js';
3
- export declare namespace ResponseHost {
4
- interface Initiator {
5
- value?: any;
6
- errors?: Error[];
7
- continueOnError?: boolean;
8
- count?: number;
9
- http?: HttpServerResponse;
10
- }
11
- }
12
- export declare class ResponseHost implements Response {
13
- value?: any;
14
- errors: Error[];
15
- continueOnError?: boolean;
16
- count?: number;
17
- http?: HttpServerResponse;
18
- constructor(init: ResponseHost.Initiator);
19
- switchToHttp(): HttpServerResponse;
20
- switchToWs(): never;
21
- switchToRpc(): never;
22
- }
@@ -1,10 +0,0 @@
1
- import { Nullish } from 'ts-gems';
2
- import { RequestContext } from '../request-context.js';
3
- export declare abstract class ApiService {
4
- protected _context: RequestContext;
5
- get context(): RequestContext;
6
- for<C extends RequestContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
7
- }
8
- export declare namespace ApiService {
9
- const extendSymbol: unique symbol;
10
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes