@opra/core 1.0.0-alpha.9 → 1.0.0-beta.2
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/cjs/augmentation/18n.augmentation.js +13 -13
- package/cjs/constants.js +1 -2
- package/cjs/execution-context.js +1 -0
- package/cjs/http/express-adapter.js +22 -20
- package/cjs/http/http-adapter.js +2 -5
- package/cjs/http/http-context.js +16 -31
- package/cjs/http/{impl/http-handler.js → http-handler.js} +194 -169
- package/cjs/http/impl/http-outgoing.host.js +2 -2
- package/cjs/http/impl/multipart-reader.js +141 -44
- package/cjs/http/utils/body-reader.js +0 -1
- package/cjs/http/utils/common.js +4 -4
- package/cjs/http/utils/concat-readable.js +1 -2
- package/cjs/http/utils/convert-to-headers.js +2 -3
- package/cjs/http/utils/convert-to-raw-headers.js +1 -2
- package/cjs/http/utils/match-known-fields.js +2 -2
- package/cjs/http/utils/wrap-exception.js +1 -2
- package/cjs/index.js +1 -1
- package/cjs/platform-adapter.js +0 -3
- package/cjs/type-guards.js +4 -5
- package/esm/augmentation/18n.augmentation.js +2 -2
- package/esm/constants.js +0 -1
- package/esm/execution-context.js +1 -0
- package/esm/http/express-adapter.js +22 -20
- package/esm/http/http-adapter.js +2 -5
- package/esm/http/http-context.js +17 -32
- package/esm/http/{impl/http-handler.js → http-handler.js} +195 -170
- package/esm/http/impl/http-outgoing.host.js +1 -1
- package/esm/http/impl/multipart-reader.js +142 -45
- package/esm/http/utils/body-reader.js +0 -1
- package/esm/index.js +1 -1
- package/esm/package.json +3 -0
- package/esm/platform-adapter.js +0 -3
- package/package.json +35 -63
- package/types/augmentation/http-controller.augmentation.d.ts +1 -2
- package/types/constants.d.ts +0 -1
- package/types/execution-context.d.ts +2 -1
- package/types/helpers/service-base.d.ts +1 -1
- package/types/http/express-adapter.d.ts +1 -1
- package/types/http/http-adapter.d.ts +35 -8
- package/types/http/http-context.d.ts +4 -4
- package/types/http/{impl/http-handler.d.ts → http-handler.d.ts} +11 -9
- package/types/http/impl/http-incoming.host.d.ts +1 -2
- package/types/http/impl/http-outgoing.host.d.ts +1 -1
- package/types/http/impl/multipart-reader.d.ts +38 -20
- package/types/http/impl/node-incoming-message.host.d.ts +3 -7
- package/types/http/impl/node-outgoing-message.host.d.ts +5 -8
- package/types/http/interfaces/http-incoming.interface.d.ts +2 -3
- package/types/http/interfaces/http-outgoing.interface.d.ts +2 -2
- package/types/http/interfaces/node-incoming-message.interface.d.ts +0 -2
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +1 -3
- package/types/http/utils/body-reader.d.ts +1 -4
- package/types/http/utils/concat-readable.d.ts +0 -1
- package/types/http/utils/convert-to-raw-headers.d.ts +1 -2
- package/types/index.d.cts +28 -0
- package/types/index.d.ts +1 -1
- package/types/platform-adapter.d.ts +0 -4
- package/cjs/helpers/logger.js +0 -35
- package/esm/helpers/logger.js +0 -31
- package/i18n/i18n/en/error.json +0 -21
- package/types/helpers/logger.d.ts +0 -14
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpMediaType } from '@opra/common';
|
|
2
|
+
import busboy from 'busboy';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import type { StrictOmit } from 'ts-gems';
|
|
5
|
+
import { HttpContext } from '../http-context.js';
|
|
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
|
+
}
|
|
13
27
|
export declare class MultipartReader extends EventEmitter {
|
|
14
|
-
protected
|
|
28
|
+
protected context: HttpContext;
|
|
29
|
+
protected mediaType?: HttpMediaType | undefined;
|
|
15
30
|
protected _started: boolean;
|
|
31
|
+
protected _finished: boolean;
|
|
16
32
|
protected _cancelled: boolean;
|
|
17
|
-
protected _form:
|
|
18
|
-
protected _items:
|
|
19
|
-
protected _stack:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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[]>;
|
|
24
42
|
cancel(): void;
|
|
25
43
|
resume(): void;
|
|
26
44
|
pause(): void;
|
|
27
|
-
|
|
45
|
+
purge(): Promise<PromiseSettledResult<any>[]>;
|
|
28
46
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
import { HTTPParserJS } from '@browsery/http-parser';
|
|
6
|
-
import { IncomingHttpHeaders } from 'http';
|
|
1
|
+
import { type HTTPParserJS } from '@browsery/http-parser';
|
|
2
|
+
import type { IncomingHttpHeaders } from 'http';
|
|
7
3
|
import { Duplex, Readable } from 'stream';
|
|
8
|
-
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface';
|
|
4
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
9
5
|
export declare const CRLF: Buffer;
|
|
10
6
|
export declare const kHeaders: unique symbol;
|
|
11
7
|
export declare const kHeadersDistinct: unique symbol;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { OutgoingHttpHeaders } from 'http';
|
|
1
|
+
import type { OutgoingHttpHeaders } from 'http';
|
|
5
2
|
import { Duplex } from 'stream';
|
|
6
|
-
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface';
|
|
7
|
-
import type { NodeOutgoingMessage } from '../interfaces/node-outgoing-message.interface';
|
|
3
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
4
|
+
import type { NodeOutgoingMessage } from '../interfaces/node-outgoing-message.interface.js';
|
|
8
5
|
export declare const kOutHeaders: unique symbol;
|
|
9
6
|
export declare const kOutTrailers: unique symbol;
|
|
10
7
|
declare global {
|
|
@@ -18,8 +15,8 @@ declare global {
|
|
|
18
15
|
* @class NodeOutgoingMessageHost
|
|
19
16
|
*/
|
|
20
17
|
export declare class NodeOutgoingMessageHost extends Duplex implements NodeOutgoingMessage {
|
|
21
|
-
protected [kOutHeaders]
|
|
22
|
-
protected [kOutTrailers]
|
|
18
|
+
protected [kOutHeaders]?: Record<string, any>;
|
|
19
|
+
protected [kOutTrailers]?: Record<string, any>;
|
|
23
20
|
protected _headersSent: boolean;
|
|
24
21
|
protected _httpVersionMajor?: number;
|
|
25
22
|
protected _httpVersionMinor?: number;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
1
|
+
import type { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
3
2
|
import { BodyReader } from '../utils/body-reader.js';
|
|
4
|
-
import type { HttpOutgoing } from './http-outgoing.interface';
|
|
3
|
+
import type { HttpOutgoing } from './http-outgoing.interface.js';
|
|
5
4
|
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
6
5
|
/**
|
|
7
6
|
* @interface HttpIncoming
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import type { HttpIncoming } from './http-incoming.interface';
|
|
1
|
+
import { type StrictOmit } from 'ts-gems';
|
|
2
|
+
import type { HttpIncoming } from './http-incoming.interface.js';
|
|
3
3
|
import { NodeOutgoingMessage } from './node-outgoing-message.interface.js';
|
|
4
4
|
export interface HttpOutgoing extends StrictOmit<NodeOutgoingMessage, 'req' | 'appendHeader' | 'setHeader'> {
|
|
5
5
|
req: HttpIncoming;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import http, { OutgoingHttpHeaders } from 'http';
|
|
1
|
+
import http, { type OutgoingHttpHeaders } from 'http';
|
|
4
2
|
import { Writable } from 'stream';
|
|
5
3
|
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
6
4
|
export interface NodeOutgoingMessage extends Writable, Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'flushHeaders' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'> {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import nodeStream from 'node:stream';
|
|
5
2
|
import { EventEmitter } from 'events';
|
|
6
3
|
import type { HttpIncoming } from '../interfaces/http-incoming.interface.js';
|
|
@@ -21,7 +18,7 @@ type Callback = (...args: any[]) => any;
|
|
|
21
18
|
export declare class BodyReader extends EventEmitter {
|
|
22
19
|
readonly req: HttpIncoming;
|
|
23
20
|
limit?: number;
|
|
24
|
-
protected _stream
|
|
21
|
+
protected _stream?: nodeStream.Readable;
|
|
25
22
|
protected _buffer?: string | Buffer[];
|
|
26
23
|
protected _completed?: boolean | undefined;
|
|
27
24
|
protected _receivedSize: number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import './augmentation/18n.augmentation.js';
|
|
3
|
+
import './augmentation/http-controller.augmentation.js';
|
|
4
|
+
import * as HttpIncomingHost_ from './http/impl/http-incoming.host.js';
|
|
5
|
+
import * as HttpOutgoingHost_ from './http/impl/http-outgoing.host.js';
|
|
6
|
+
import * as NodeIncomingMessageHost_ from './http/impl/node-incoming-message.host.js';
|
|
7
|
+
import * as NodeOutgoingMessageHost_ from './http/impl/node-outgoing-message.host.js';
|
|
8
|
+
export * from './execution-context.js';
|
|
9
|
+
export * from './helpers/service-base.js';
|
|
10
|
+
export * from './http/express-adapter.js';
|
|
11
|
+
export * from './http/http-adapter.js';
|
|
12
|
+
export * from './http/http-context.js';
|
|
13
|
+
export * from './http/http-handler.js';
|
|
14
|
+
export * from './http/impl/multipart-reader.js';
|
|
15
|
+
export * from './http/interfaces/http-incoming.interface.js';
|
|
16
|
+
export * from './http/interfaces/http-outgoing.interface.js';
|
|
17
|
+
export * from './http/interfaces/node-incoming-message.interface.js';
|
|
18
|
+
export * from './http/interfaces/node-outgoing-message.interface.js';
|
|
19
|
+
export * from './http/utils/wrap-exception.js';
|
|
20
|
+
export * from './interfaces/logger.interface.js';
|
|
21
|
+
export * from './platform-adapter.js';
|
|
22
|
+
export * from './type-guards.js';
|
|
23
|
+
export declare namespace classes {
|
|
24
|
+
export import HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
|
|
25
|
+
export import HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
|
|
26
|
+
export import NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
|
|
27
|
+
export import NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
|
|
28
|
+
}
|
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';
|
|
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>;
|
package/cjs/helpers/logger.js
DELETED
|
@@ -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;
|
package/esm/helpers/logger.js
DELETED
|
@@ -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
|
-
}
|
package/i18n/i18n/en/error.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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_AVAILABLE": "Resource is not available or you dont have access",
|
|
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
|
-
}
|
|
@@ -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
|
-
}
|