@opra/core 1.0.0-alpha.23 → 1.0.0-alpha.25

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.25",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -33,10 +33,10 @@
33
33
  "dependencies": {
34
34
  "@browsery/http-parser": "^0.5.8",
35
35
  "@browsery/type-is": "^1.6.18-r2",
36
- "@opra/common": "^1.0.0-alpha.23",
37
- "@types/formidable": "^3.4.5",
36
+ "@opra/common": "^1.0.0-alpha.25",
38
37
  "accepts": "^1.3.8",
39
38
  "base64-stream": "^1.0.0",
39
+ "busboy": "^1.6.0",
40
40
  "bytes": "^3.1.2",
41
41
  "content-disposition": "^0.5.4",
42
42
  "content-type": "^1.0.5",
@@ -44,7 +44,6 @@
44
44
  "cookie-signature": "^1.2.1",
45
45
  "cppzst": "^2.0.12",
46
46
  "encodeurl": "^2.0.0",
47
- "formidable": "^3.5.1",
48
47
  "fresh": "^0.5.2",
49
48
  "iconv-lite": "^0.6.3",
50
49
  "mime-types": "^2.1.35",
@@ -55,7 +54,7 @@
55
54
  "range-parser": "^1.2.1",
56
55
  "raw-body": "^2.5.2",
57
56
  "reflect-metadata": "^0.2.2",
58
- "strict-typed-events": "^2.3.3",
57
+ "strict-typed-events": "^2.4.0",
59
58
  "vary": "^1.1.2"
60
59
  },
61
60
  "optionalDependencies": {
@@ -66,6 +65,7 @@
66
65
  "@faker-js/faker": "^8.4.1",
67
66
  "@types/accepts": "^1.3.7",
68
67
  "@types/base64-stream": "^1.0.5",
68
+ "@types/busboy": "^1.5.4",
69
69
  "@types/bytes": "^3.1.4",
70
70
  "@types/content-disposition": "^0.5.8",
71
71
  "@types/content-type": "^1.1.8",
@@ -1,2 +1 @@
1
- export declare const kHandler: unique symbol;
2
1
  export declare const kAssetCache: unique symbol;
@@ -1,4 +1,4 @@
1
- import { ApiDocument, OpraSchema } from '@opra/common';
1
+ import { ApiDocument, OpraException, OpraSchema } from '@opra/common';
2
2
  import { AsyncEventEmitter } from 'strict-typed-events';
3
3
  /**
4
4
  * @namespace ExecutionContext
@@ -18,6 +18,7 @@ export declare abstract class ExecutionContext extends AsyncEventEmitter {
18
18
  readonly document: ApiDocument;
19
19
  readonly protocol: OpraSchema.Protocol;
20
20
  readonly platform: string;
21
+ errors: OpraException[];
21
22
  protected constructor(init: ExecutionContext.Initiator);
22
23
  addListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
23
24
  removeListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
@@ -1,8 +1,7 @@
1
- import { ApiDocument, HttpApi, OpraSchema } from '@opra/common';
2
- import { kHandler } from '../constants.js';
1
+ import { ApiDocument, HttpApi, OpraException, OpraSchema } from '@opra/common';
3
2
  import { PlatformAdapter } from '../platform-adapter.js';
4
3
  import { HttpContext } from './http-context.js';
5
- import { HttpHandler } from './impl/http-handler.js';
4
+ import { HttpHandler } from './http-handler.js';
6
5
  export declare namespace HttpAdapter {
7
6
  /**
8
7
  * @type Interceptor
@@ -11,15 +10,34 @@ export declare namespace HttpAdapter {
11
10
  interface Options extends PlatformAdapter.Options {
12
11
  basePath?: string;
13
12
  interceptors?: HttpAdapter.Interceptor[];
14
- onRequest?: (ctx: HttpContext) => void | Promise<void>;
15
13
  }
14
+ interface Events {
15
+ error: (error: OpraException, context: HttpContext) => void | Promise<void>;
16
+ request: (context: HttpContext) => void | Promise<void>;
17
+ }
18
+ }
19
+ export interface HttpAdapter {
20
+ addListener<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
21
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
22
+ on<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
23
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
24
+ once<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
25
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
26
+ removeListener<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
27
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
28
+ off<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
29
+ off(event: string | symbol, listener: (...args: any[]) => void): this;
30
+ prependListener<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
31
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
32
+ prependOnceListener<Event extends keyof HttpAdapter.Events>(event: Event, listener: HttpAdapter.Events[Event]): this;
33
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
16
34
  }
17
35
  /**
18
36
  *
19
37
  * @class HttpAdapter
20
38
  */
21
39
  export declare abstract class HttpAdapter extends PlatformAdapter {
22
- protected [kHandler]: HttpHandler;
40
+ readonly handler: HttpHandler;
23
41
  readonly protocol: OpraSchema.Protocol;
24
42
  interceptors: HttpAdapter.Interceptor[];
25
43
  protected constructor(document: ApiDocument, options?: HttpAdapter.Options);
@@ -1,9 +1,8 @@
1
- import { HttpOperationResponse } from '@opra/common';
2
- import { kAssetCache } from '../../constants.js';
3
- import type { HttpAdapter } from '../http-adapter.js';
4
- import { HttpContext } from '../http-context.js';
5
- import { HttpOutgoing } from '../interfaces/http-outgoing.interface.js';
6
- import { AssetCache } from './asset-cache.js';
1
+ import { HttpOperationResponse, OpraException } from '@opra/common';
2
+ import { kAssetCache } from '../constants';
3
+ import type { HttpAdapter } from './http-adapter';
4
+ import { HttpContext } from './http-context';
5
+ import { AssetCache } from './impl/asset-cache';
7
6
  /**
8
7
  * @namespace
9
8
  */
@@ -24,6 +23,7 @@ export declare namespace HttpHandler {
24
23
  export declare class HttpHandler {
25
24
  readonly adapter: HttpAdapter;
26
25
  protected [kAssetCache]: AssetCache;
26
+ onError?: (context: HttpContext, error: OpraException) => void | Promise<void>;
27
27
  constructor(adapter: HttpAdapter);
28
28
  /**
29
29
  * Main http request handler
@@ -60,7 +60,8 @@ export declare class HttpHandler {
60
60
  * @param responseValue
61
61
  * @protected
62
62
  */
63
- protected _sendResponse(context: HttpContext, responseValue: any): Promise<void>;
63
+ sendResponse(context: HttpContext, responseValue?: any): Promise<void>;
64
+ protected _sendErrorResponse(context: HttpContext): Promise<void>;
64
65
  /**
65
66
  *
66
67
  * @param context
@@ -69,5 +70,4 @@ export declare class HttpHandler {
69
70
  */
70
71
  protected _determineResponseArgs(context: HttpContext, body: any): HttpHandler.ResponseArgs;
71
72
  sendDocumentSchema(context: HttpContext): Promise<void>;
72
- sendErrorResponse(response: HttpOutgoing, errors: any[]): Promise<void>;
73
73
  }
@@ -1,27 +1,46 @@
1
+ import { HttpMediaType } from '@opra/common';
2
+ import busboy from 'busboy';
1
3
  import { EventEmitter } from 'events';
2
- import formidable from 'formidable';
3
- import type IncomingForm from 'formidable/Formidable.js';
4
- import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
5
- export type MultipartFile = formidable.File;
6
- export type MultipartItem = {
7
- fieldName: string;
8
- type: 'field' | 'file';
9
- value?: string;
10
- file?: MultipartFile;
11
- };
4
+ import { StrictOmit } from 'ts-gems';
5
+ import { HttpContext } from '../http-context';
6
+ export declare namespace MultipartReader {
7
+ interface Options extends StrictOmit<busboy.BusboyConfig, 'headers'> {
8
+ tempDirectory?: string;
9
+ }
10
+ interface FieldInfo {
11
+ kind: 'field';
12
+ field: string;
13
+ value?: any;
14
+ mimeType?: string;
15
+ encoding?: string;
16
+ }
17
+ interface FileInfo {
18
+ kind: 'file';
19
+ field: string;
20
+ filename: string;
21
+ storedPath: string;
22
+ mimeType?: string;
23
+ encoding?: string;
24
+ }
25
+ type Item = FieldInfo | FileInfo;
26
+ }
12
27
  export declare class MultipartReader extends EventEmitter {
13
- protected _incoming: NodeIncomingMessage;
28
+ protected context: HttpContext;
29
+ protected mediaType?: HttpMediaType | undefined;
14
30
  protected _started: boolean;
31
+ protected _finished: boolean;
15
32
  protected _cancelled: boolean;
16
- protected _form: IncomingForm;
17
- protected _items: MultipartItem[];
18
- protected _stack: MultipartItem[];
19
- constructor(incoming: NodeIncomingMessage, options?: formidable.Options);
20
- get items(): MultipartItem[];
21
- getNext(): Promise<MultipartItem | undefined>;
22
- getAll(): Promise<MultipartItem[]>;
33
+ protected _form: busboy.Busboy;
34
+ protected _items: MultipartReader.Item[];
35
+ protected _stack: MultipartReader.Item[];
36
+ protected tempDirectory: string;
37
+ constructor(context: HttpContext, options?: MultipartReader.Options, mediaType?: HttpMediaType | undefined);
38
+ get items(): MultipartReader.Item[];
39
+ getNext(): Promise<MultipartReader.Item | undefined>;
40
+ getAll(): Promise<MultipartReader.Item[]>;
41
+ getAll_(): Promise<MultipartReader.Item[]>;
23
42
  cancel(): void;
24
43
  resume(): void;
25
44
  pause(): void;
26
- deleteTempFiles(): Promise<PromiseSettledResult<any>[]>;
45
+ purge(): Promise<PromiseSettledResult<any>[]>;
27
46
  }
package/types/index.d.ts CHANGED
@@ -6,11 +6,11 @@ import * as HttpOutgoingHost_ from './http/impl/http-outgoing.host.js';
6
6
  import * as NodeIncomingMessageHost_ from './http/impl/node-incoming-message.host.js';
7
7
  import * as NodeOutgoingMessageHost_ from './http/impl/node-outgoing-message.host.js';
8
8
  export * from './execution-context.js';
9
- export * from './helpers/logger.js';
10
9
  export * from './helpers/service-base.js';
11
10
  export * from './http/express-adapter.js';
12
11
  export * from './http/http-adapter.js';
13
12
  export * from './http/http-context.js';
13
+ export * from './http/http-handler.js';
14
14
  export * from './http/impl/multipart-reader.js';
15
15
  export * from './http/interfaces/http-incoming.interface.js';
16
16
  export * from './http/interfaces/http-outgoing.interface.js';
@@ -2,16 +2,13 @@ import './augmentation/18n.augmentation.js';
2
2
  import { ApiDocument, I18n, OpraSchema } from '@opra/common';
3
3
  import { AsyncEventEmitter } from 'strict-typed-events';
4
4
  import { kAssetCache } from './constants.js';
5
- import { Logger } from './helpers/logger.js';
6
5
  import { AssetCache } from './http/impl/asset-cache.js';
7
- import type { ILogger } from './interfaces/logger.interface.js';
8
6
  /**
9
7
  * @namespace PlatformAdapter
10
8
  */
11
9
  export declare namespace PlatformAdapter {
12
10
  interface Options {
13
11
  i18n?: I18n;
14
- logger?: ILogger;
15
12
  }
16
13
  }
17
14
  /**
@@ -21,7 +18,6 @@ export declare abstract class PlatformAdapter extends AsyncEventEmitter {
21
18
  protected [kAssetCache]: AssetCache;
22
19
  readonly document: ApiDocument;
23
20
  abstract readonly protocol: OpraSchema.Protocol;
24
- logger: Logger;
25
21
  i18n: I18n;
26
22
  protected constructor(document: ApiDocument, options?: PlatformAdapter.Options);
27
23
  abstract close(): Promise<void>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = void 0;
4
- class Logger {
5
- constructor(options = {}) {
6
- this._instance = options.instance || (!(process.env.NODE_ENV || '').includes('test') ? globalThis.console : {});
7
- }
8
- info(message, ...optionalParams) {
9
- (this._instance.info || this._instance.log)?.(message, ...optionalParams);
10
- }
11
- error(message, ...optionalParams) {
12
- if (this._instance.error) {
13
- this._instance.error(message, ...optionalParams);
14
- return;
15
- }
16
- this.info(message, ...optionalParams);
17
- }
18
- fatal(message, ...optionalParams) {
19
- if (this._instance.fatal) {
20
- this._instance.fatal(message, ...optionalParams);
21
- return;
22
- }
23
- this.error(message, ...optionalParams);
24
- }
25
- warn(message, ...optionalParams) {
26
- this._instance.warn?.(message, ...optionalParams);
27
- }
28
- debug(message, ...optionalParams) {
29
- this._instance.debug?.(message, ...optionalParams);
30
- }
31
- verbose(message, ...optionalParams) {
32
- this._instance.verbose?.(message, ...optionalParams);
33
- }
34
- }
35
- exports.Logger = Logger;
@@ -1,31 +0,0 @@
1
- export class Logger {
2
- constructor(options = {}) {
3
- this._instance = options.instance || (!(process.env.NODE_ENV || '').includes('test') ? globalThis.console : {});
4
- }
5
- info(message, ...optionalParams) {
6
- (this._instance.info || this._instance.log)?.(message, ...optionalParams);
7
- }
8
- error(message, ...optionalParams) {
9
- if (this._instance.error) {
10
- this._instance.error(message, ...optionalParams);
11
- return;
12
- }
13
- this.info(message, ...optionalParams);
14
- }
15
- fatal(message, ...optionalParams) {
16
- if (this._instance.fatal) {
17
- this._instance.fatal(message, ...optionalParams);
18
- return;
19
- }
20
- this.error(message, ...optionalParams);
21
- }
22
- warn(message, ...optionalParams) {
23
- this._instance.warn?.(message, ...optionalParams);
24
- }
25
- debug(message, ...optionalParams) {
26
- this._instance.debug?.(message, ...optionalParams);
27
- }
28
- verbose(message, ...optionalParams) {
29
- this._instance.verbose?.(message, ...optionalParams);
30
- }
31
- }
@@ -1,14 +0,0 @@
1
- import { ILogger } from '../interfaces/logger.interface.js';
2
- export interface LoggerOptions {
3
- instance?: ILogger;
4
- }
5
- export declare class Logger implements ILogger {
6
- protected _instance: ILogger;
7
- constructor(options?: LoggerOptions);
8
- info(message: any, ...optionalParams: any[]): void;
9
- error(message: any, ...optionalParams: any[]): void;
10
- fatal(message: any, ...optionalParams: any[]): void;
11
- warn(message: any, ...optionalParams: any[]): void;
12
- debug(message: any, ...optionalParams: any[]): void;
13
- verbose(message: any, ...optionalParams: any[]): void;
14
- }