@opra/core 1.0.0-alpha.37 → 1.0.0-alpha.39
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/http/express-adapter.js +1 -1
- package/cjs/http/http-handler.js +9 -6
- package/cjs/http/impl/http-outgoing.host.js +2 -2
- package/esm/augmentation/18n.augmentation.js +2 -2
- package/esm/http/express-adapter.js +1 -1
- package/esm/http/http-handler.js +10 -7
- package/esm/http/impl/http-outgoing.host.js +1 -1
- package/package.json +4 -3
- package/types/helpers/service-base.d.ts +1 -1
- package/types/http/express-adapter.d.ts +1 -1
- package/types/http/impl/multipart-reader.d.ts +1 -1
- package/types/http/impl/node-incoming-message.host.d.ts +2 -2
- package/types/http/impl/node-outgoing-message.host.d.ts +1 -1
- package/types/http/interfaces/http-incoming.interface.d.ts +1 -1
- package/types/http/interfaces/http-outgoing.interface.d.ts +1 -1
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +1 -1
- package/types/http/utils/convert-to-raw-headers.d.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
4
6
|
const common_1 = require("@opra/common");
|
|
5
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
common_1.I18n.load = async function (options) {
|
|
8
8
|
const opts = {
|
|
9
9
|
...options,
|
|
@@ -11,7 +11,7 @@ common_1.I18n.load = async function (options) {
|
|
|
11
11
|
delete opts.resourceDirs;
|
|
12
12
|
const instance = common_1.I18n.createInstance(opts);
|
|
13
13
|
await instance.init();
|
|
14
|
-
await instance.loadResourceDir(
|
|
14
|
+
await instance.loadResourceDir(node_path_1.default.resolve((0, common_1.getStackFileName)(), '../../../i18n'));
|
|
15
15
|
if (options?.resourceDirs)
|
|
16
16
|
for (const dir of options.resourceDirs)
|
|
17
17
|
await instance.loadResourceDir(dir);
|
|
@@ -23,7 +23,7 @@ common_1.I18n.prototype.loadResourceBundle = async function (lang, ns, filePath,
|
|
|
23
23
|
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
const content =
|
|
26
|
+
const content = node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
27
27
|
obj = JSON.parse(content);
|
|
28
28
|
}
|
|
29
29
|
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
@@ -31,18 +31,18 @@ common_1.I18n.prototype.loadResourceBundle = async function (lang, ns, filePath,
|
|
|
31
31
|
common_1.I18n.prototype.loadResourceDir = async function (dirnames, deep, overwrite) {
|
|
32
32
|
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
33
33
|
/* istanbul ignore next */
|
|
34
|
-
if (!
|
|
34
|
+
if (!node_fs_1.default.existsSync(dirname))
|
|
35
35
|
continue;
|
|
36
|
-
const languageDirs =
|
|
36
|
+
const languageDirs = node_fs_1.default.readdirSync(dirname);
|
|
37
37
|
for (const lang of languageDirs) {
|
|
38
|
-
const langDir =
|
|
39
|
-
if (
|
|
40
|
-
const nsDirs =
|
|
38
|
+
const langDir = node_path_1.default.join(dirname, lang);
|
|
39
|
+
if (node_fs_1.default.statSync(langDir).isDirectory()) {
|
|
40
|
+
const nsDirs = node_fs_1.default.readdirSync(langDir);
|
|
41
41
|
for (const nsfile of nsDirs) {
|
|
42
|
-
const nsFilePath =
|
|
43
|
-
const ext =
|
|
44
|
-
if (ext === '.json' &&
|
|
45
|
-
const ns =
|
|
42
|
+
const nsFilePath = node_path_1.default.join(langDir, nsfile);
|
|
43
|
+
const ext = node_path_1.default.extname(nsfile);
|
|
44
|
+
if (ext === '.json' && node_fs_1.default.statSync(nsFilePath).isFile()) {
|
|
45
|
+
const ns = node_path_1.default.basename(nsfile, ext);
|
|
46
46
|
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExpressAdapter = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const nodePath = tslib_1.__importStar(require("node:path"));
|
|
5
6
|
const common_1 = require("@opra/common");
|
|
6
7
|
const express_1 = require("express");
|
|
7
|
-
const nodePath = tslib_1.__importStar(require("path"));
|
|
8
8
|
const http_adapter_js_1 = require("./http-adapter.js");
|
|
9
9
|
const http_context_js_1 = require("./http-context.js");
|
|
10
10
|
const http_incoming_interface_js_1 = require("./interfaces/http-incoming.interface.js");
|
package/cjs/http/http-handler.js
CHANGED
|
@@ -7,6 +7,7 @@ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
|
|
|
7
7
|
const common_1 = require("@opra/common");
|
|
8
8
|
const content_type_1 = require("content-type");
|
|
9
9
|
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
10
|
+
const super_fast_md5_1 = require("super-fast-md5");
|
|
10
11
|
const ts_gems_1 = require("ts-gems");
|
|
11
12
|
const valgen_1 = require("valgen");
|
|
12
13
|
const constants_js_1 = require("../constants.js");
|
|
@@ -305,11 +306,13 @@ class HttpHandler {
|
|
|
305
306
|
if (operationResponse?.type) {
|
|
306
307
|
if (!(body == null && statusCode === common_1.HttpStatusCode.NO_CONTENT)) {
|
|
307
308
|
/** Generate encoder */
|
|
308
|
-
|
|
309
|
+
const projection = responseArgs.projection || '*';
|
|
310
|
+
const assetKey = (0, super_fast_md5_1.md5)(String(projection));
|
|
311
|
+
let encode = this[constants_js_1.kAssetCache].get(operationResponse, 'encode:' + assetKey);
|
|
309
312
|
if (!encode) {
|
|
310
313
|
encode = operationResponse.type.generateCodec('encode', {
|
|
311
314
|
partial: operationResponse.partial,
|
|
312
|
-
projection
|
|
315
|
+
projection,
|
|
313
316
|
ignoreWriteonlyFields: true,
|
|
314
317
|
ignoreHiddenFields: true,
|
|
315
318
|
onFail: issue => `Response body validation failed: ` + issue.message,
|
|
@@ -317,7 +320,7 @@ class HttpHandler {
|
|
|
317
320
|
if (operationResponse) {
|
|
318
321
|
if (operationResponse.isArray)
|
|
319
322
|
encode = valgen_1.vg.isArray(encode);
|
|
320
|
-
this[constants_js_1.kAssetCache].set(operationResponse, 'encode', encode);
|
|
323
|
+
this[constants_js_1.kAssetCache].set(operationResponse, 'encode:' + assetKey, encode);
|
|
321
324
|
}
|
|
322
325
|
}
|
|
323
326
|
/** Encode body */
|
|
@@ -416,13 +419,13 @@ class HttpHandler {
|
|
|
416
419
|
encode = dt.generateCodec('encode', { ignoreWriteonlyFields: true });
|
|
417
420
|
this[constants_js_1.kAssetCache].set(dt, 'encode', encode);
|
|
418
421
|
}
|
|
419
|
-
const { i18n } = this.adapter;
|
|
422
|
+
// const { i18n } = this.adapter;
|
|
420
423
|
const bodyObject = new common_1.OperationResult({
|
|
421
424
|
errors: errors.map(x => {
|
|
422
425
|
const o = x.toJSON();
|
|
423
426
|
if (!(process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'development'))
|
|
424
427
|
delete o.stack;
|
|
425
|
-
return i18n.deep(o);
|
|
428
|
+
return o; // i18n.deep(o);
|
|
426
429
|
}),
|
|
427
430
|
});
|
|
428
431
|
const body = encode(bodyObject);
|
|
@@ -431,7 +434,7 @@ class HttpHandler {
|
|
|
431
434
|
response.setHeader(common_1.HttpHeaderCodes.Pragma, 'no-cache');
|
|
432
435
|
response.setHeader(common_1.HttpHeaderCodes.Expires, '-1');
|
|
433
436
|
response.setHeader(common_1.HttpHeaderCodes.X_Opra_Version, common_1.OpraSchema.SpecVersion);
|
|
434
|
-
response.send(
|
|
437
|
+
response.send((0, common_1.safeJsonStringify)(body));
|
|
435
438
|
response.end();
|
|
436
439
|
}
|
|
437
440
|
async sendDocumentSchema(context) {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.HttpOutgoingHost = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
9
10
|
const common_1 = require("@opra/common");
|
|
10
11
|
const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
|
|
11
12
|
const content_type_1 = tslib_1.__importDefault(require("content-type"));
|
|
@@ -13,14 +14,13 @@ const cookie_1 = tslib_1.__importDefault(require("cookie"));
|
|
|
13
14
|
const cookie_signature_1 = tslib_1.__importDefault(require("cookie-signature"));
|
|
14
15
|
const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
|
|
15
16
|
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
16
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
17
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
18
18
|
const vary_1 = tslib_1.__importDefault(require("vary"));
|
|
19
19
|
const charsetRegExp = /;\s*charset\s*=/;
|
|
20
20
|
class HttpOutgoingHost {
|
|
21
21
|
attachment(filename) {
|
|
22
22
|
if (filename)
|
|
23
|
-
this.contentType(
|
|
23
|
+
this.contentType(node_path_1.default.extname(filename));
|
|
24
24
|
this.setHeader('Content-Disposition', (0, content_disposition_1.default)(filename));
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import * as nodePath from 'node:path';
|
|
1
2
|
import { HttpApi, NotFoundError } from '@opra/common';
|
|
2
3
|
import { Router } from 'express';
|
|
3
|
-
import * as nodePath from 'path';
|
|
4
4
|
import { HttpAdapter } from './http-adapter.js';
|
|
5
5
|
import { HttpContext } from './http-context.js';
|
|
6
6
|
import { HttpIncoming } from './interfaces/http-incoming.interface.js';
|
package/esm/http/http-handler.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as process from 'node:process';
|
|
2
2
|
import typeIs from '@browsery/type-is';
|
|
3
|
-
import { BadRequestError, HttpHeaderCodes, HttpStatusCode, InternalServerError, isBlob, isReadableStream, IssueSeverity, MethodNotAllowedError, MimeTypes, OperationResult, OpraException, OpraSchema, } from '@opra/common';
|
|
3
|
+
import { BadRequestError, HttpHeaderCodes, HttpStatusCode, InternalServerError, isBlob, isReadableStream, IssueSeverity, MethodNotAllowedError, MimeTypes, OperationResult, OpraException, OpraSchema, safeJsonStringify, } from '@opra/common';
|
|
4
4
|
import { parse as parseContentType } from 'content-type';
|
|
5
5
|
import { splitString } from 'fast-tokenizer';
|
|
6
|
+
import { md5 } from 'super-fast-md5';
|
|
6
7
|
import { asMutable } from 'ts-gems';
|
|
7
8
|
import { toArray, ValidationError, vg } from 'valgen';
|
|
8
9
|
import { kAssetCache } from '../constants.js';
|
|
@@ -301,11 +302,13 @@ export class HttpHandler {
|
|
|
301
302
|
if (operationResponse?.type) {
|
|
302
303
|
if (!(body == null && statusCode === HttpStatusCode.NO_CONTENT)) {
|
|
303
304
|
/** Generate encoder */
|
|
304
|
-
|
|
305
|
+
const projection = responseArgs.projection || '*';
|
|
306
|
+
const assetKey = md5(String(projection));
|
|
307
|
+
let encode = this[kAssetCache].get(operationResponse, 'encode:' + assetKey);
|
|
305
308
|
if (!encode) {
|
|
306
309
|
encode = operationResponse.type.generateCodec('encode', {
|
|
307
310
|
partial: operationResponse.partial,
|
|
308
|
-
projection
|
|
311
|
+
projection,
|
|
309
312
|
ignoreWriteonlyFields: true,
|
|
310
313
|
ignoreHiddenFields: true,
|
|
311
314
|
onFail: issue => `Response body validation failed: ` + issue.message,
|
|
@@ -313,7 +316,7 @@ export class HttpHandler {
|
|
|
313
316
|
if (operationResponse) {
|
|
314
317
|
if (operationResponse.isArray)
|
|
315
318
|
encode = vg.isArray(encode);
|
|
316
|
-
this[kAssetCache].set(operationResponse, 'encode', encode);
|
|
319
|
+
this[kAssetCache].set(operationResponse, 'encode:' + assetKey, encode);
|
|
317
320
|
}
|
|
318
321
|
}
|
|
319
322
|
/** Encode body */
|
|
@@ -412,13 +415,13 @@ export class HttpHandler {
|
|
|
412
415
|
encode = dt.generateCodec('encode', { ignoreWriteonlyFields: true });
|
|
413
416
|
this[kAssetCache].set(dt, 'encode', encode);
|
|
414
417
|
}
|
|
415
|
-
const { i18n } = this.adapter;
|
|
418
|
+
// const { i18n } = this.adapter;
|
|
416
419
|
const bodyObject = new OperationResult({
|
|
417
420
|
errors: errors.map(x => {
|
|
418
421
|
const o = x.toJSON();
|
|
419
422
|
if (!(process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'development'))
|
|
420
423
|
delete o.stack;
|
|
421
|
-
return i18n.deep(o);
|
|
424
|
+
return o; // i18n.deep(o);
|
|
422
425
|
}),
|
|
423
426
|
});
|
|
424
427
|
const body = encode(bodyObject);
|
|
@@ -427,7 +430,7 @@ export class HttpHandler {
|
|
|
427
430
|
response.setHeader(HttpHeaderCodes.Pragma, 'no-cache');
|
|
428
431
|
response.setHeader(HttpHeaderCodes.Expires, '-1');
|
|
429
432
|
response.setHeader(HttpHeaderCodes.X_Opra_Version, OpraSchema.SpecVersion);
|
|
430
|
-
response.send(
|
|
433
|
+
response.send(safeJsonStringify(body));
|
|
431
434
|
response.end();
|
|
432
435
|
}
|
|
433
436
|
async sendDocumentSchema(context) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Some parts of this file contains codes from open source express library
|
|
3
3
|
https://github.com/expressjs
|
|
4
4
|
*/
|
|
5
|
+
import path from 'node:path';
|
|
5
6
|
import { HttpStatusCode } from '@opra/common';
|
|
6
7
|
import contentDisposition from 'content-disposition';
|
|
7
8
|
import contentType from 'content-type';
|
|
@@ -9,7 +10,6 @@ import cookie from 'cookie';
|
|
|
9
10
|
import cookieSignature from 'cookie-signature';
|
|
10
11
|
import encodeUrl from 'encodeurl';
|
|
11
12
|
import mime from 'mime-types';
|
|
12
|
-
import path from 'path';
|
|
13
13
|
import { toString } from 'putil-varhelpers';
|
|
14
14
|
import vary from 'vary';
|
|
15
15
|
const charsetRegExp = /;\s*charset\s*=/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.39",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@browsery/antlr4": "^4.13.3-r1",
|
|
9
9
|
"@browsery/http-parser": "^0.5.9-r1",
|
|
10
10
|
"@browsery/type-is": "^1.6.18-r5",
|
|
11
|
-
"@opra/common": "^1.0.0-alpha.
|
|
11
|
+
"@opra/common": "^1.0.0-alpha.39",
|
|
12
12
|
"accepts": "^1.3.8",
|
|
13
13
|
"base64-stream": "^1.0.0",
|
|
14
14
|
"busboy": "^1.6.0",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"raw-body": "^3.0.0",
|
|
32
32
|
"reflect-metadata": "^0.2.2",
|
|
33
33
|
"strict-typed-events": "^2.8.0",
|
|
34
|
-
"
|
|
34
|
+
"super-fast-md5": "^1.0.3",
|
|
35
|
+
"tslib": "^2.7.0",
|
|
35
36
|
"valgen": "^5.9.0",
|
|
36
37
|
"vary": "^1.1.2"
|
|
37
38
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiDocument, HttpController } from '@opra/common';
|
|
2
|
-
import { Application } from 'express';
|
|
2
|
+
import { type Application } from 'express';
|
|
3
3
|
import { HttpAdapter } from './http-adapter.js';
|
|
4
4
|
export declare class ExpressAdapter extends HttpAdapter {
|
|
5
5
|
readonly app: Application;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpMediaType } from '@opra/common';
|
|
2
2
|
import busboy from 'busboy';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import { StrictOmit } from 'ts-gems';
|
|
4
|
+
import type { StrictOmit } from 'ts-gems';
|
|
5
5
|
import { HttpContext } from '../http-context.js';
|
|
6
6
|
export declare namespace MultipartReader {
|
|
7
7
|
interface Options extends StrictOmit<busboy.BusboyConfig, 'headers'> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HTTPParserJS } from '@browsery/http-parser';
|
|
2
|
-
import { IncomingHttpHeaders } from 'http';
|
|
1
|
+
import { type HTTPParserJS } from '@browsery/http-parser';
|
|
2
|
+
import type { IncomingHttpHeaders } from 'http';
|
|
3
3
|
import { Duplex, Readable } from 'stream';
|
|
4
4
|
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
5
5
|
export declare const CRLF: Buffer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutgoingHttpHeaders } from 'http';
|
|
1
|
+
import type { OutgoingHttpHeaders } from 'http';
|
|
2
2
|
import { Duplex } from 'stream';
|
|
3
3
|
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
4
4
|
import type { NodeOutgoingMessage } from '../interfaces/node-outgoing-message.interface.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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';
|
|
2
2
|
import { BodyReader } from '../utils/body-reader.js';
|
|
3
3
|
import type { HttpOutgoing } from './http-outgoing.interface.js';
|
|
4
4
|
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
1
|
+
import { type StrictOmit } from 'ts-gems';
|
|
2
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'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import http, { OutgoingHttpHeaders } from 'http';
|
|
1
|
+
import http, { type OutgoingHttpHeaders } from 'http';
|
|
2
2
|
import { Writable } from 'stream';
|
|
3
3
|
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
4
4
|
export interface NodeOutgoingMessage extends Writable, Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'flushHeaders' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'> {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'http';
|
|
1
|
+
import type { IncomingHttpHeaders } from 'http';
|
|
2
2
|
export declare function convertToRawHeaders(src: IncomingHttpHeaders | Record<string, any>): string[];
|