@opra/core 1.0.0-alpha.32 → 1.0.0-alpha.33

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.
@@ -9,15 +9,15 @@ const content_type_1 = require("content-type");
9
9
  const fast_tokenizer_1 = require("fast-tokenizer");
10
10
  const ts_gems_1 = require("ts-gems");
11
11
  const valgen_1 = require("valgen");
12
- const constants_1 = require("../constants");
13
- const wrap_exception_1 = require("./utils/wrap-exception");
12
+ const constants_js_1 = require("../constants.js");
13
+ const wrap_exception_js_1 = require("./utils/wrap-exception.js");
14
14
  /**
15
15
  * @class HttpHandler
16
16
  */
17
17
  class HttpHandler {
18
18
  constructor(adapter) {
19
19
  this.adapter = adapter;
20
- this[constants_1.kAssetCache] = adapter[constants_1.kAssetCache];
20
+ this[constants_js_1.kAssetCache] = adapter[constants_js_1.kAssetCache];
21
21
  }
22
22
  /**
23
23
  * Main http request handler
@@ -77,7 +77,7 @@ class HttpHandler {
77
77
  }, e);
78
78
  }
79
79
  else
80
- e = (0, wrap_exception_1.wrapException)(e);
80
+ e = (0, wrap_exception_js_1.wrapException)(e);
81
81
  if (this.onError)
82
82
  await this.onError(context, error);
83
83
  context.errors.push(e);
@@ -124,10 +124,10 @@ class HttpHandler {
124
124
  };
125
125
  /** prepare decoders */
126
126
  const getDecoder = (prm) => {
127
- let decode = this[constants_1.kAssetCache].get(prm, 'decode');
127
+ let decode = this[constants_js_1.kAssetCache].get(prm, 'decode');
128
128
  if (!decode) {
129
129
  decode = prm.type?.generateCodec('decode', { ignoreReadonlyFields: true }) || valgen_1.vg.isAny();
130
- this[constants_1.kAssetCache].set(prm, 'decode', decode);
130
+ this[constants_js_1.kAssetCache].set(prm, 'decode', decode);
131
131
  }
132
132
  return decode;
133
133
  };
@@ -293,19 +293,19 @@ class HttpHandler {
293
293
  const { operationResponse, statusCode } = responseArgs;
294
294
  let { contentType, body } = responseArgs;
295
295
  const operationResultType = document.node.getDataType(common_1.OperationResult);
296
- let operationResultEncoder = this[constants_1.kAssetCache].get(operationResultType, 'encode');
296
+ let operationResultEncoder = this[constants_js_1.kAssetCache].get(operationResultType, 'encode');
297
297
  if (!operationResultEncoder) {
298
298
  operationResultEncoder = operationResultType.generateCodec('encode', {
299
299
  ignoreWriteonlyFields: true,
300
300
  ignoreHiddenFields: true,
301
301
  });
302
- this[constants_1.kAssetCache].set(operationResultType, 'encode', operationResultEncoder);
302
+ this[constants_js_1.kAssetCache].set(operationResultType, 'encode', operationResultEncoder);
303
303
  }
304
304
  /** Validate response */
305
305
  if (operationResponse?.type) {
306
306
  if (!(body == null && statusCode === common_1.HttpStatusCode.NO_CONTENT)) {
307
307
  /** Generate encoder */
308
- let encode = this[constants_1.kAssetCache].get(operationResponse, 'encode');
308
+ let encode = this[constants_js_1.kAssetCache].get(operationResponse, 'encode');
309
309
  if (!encode) {
310
310
  encode = operationResponse.type.generateCodec('encode', {
311
311
  partial: operationResponse.partial,
@@ -317,7 +317,7 @@ class HttpHandler {
317
317
  if (operationResponse) {
318
318
  if (operationResponse.isArray)
319
319
  encode = valgen_1.vg.isArray(encode);
320
- this[constants_1.kAssetCache].set(operationResponse, 'encode', encode);
320
+ this[constants_js_1.kAssetCache].set(operationResponse, 'encode', encode);
321
321
  }
322
322
  }
323
323
  /** Encode body */
@@ -411,10 +411,10 @@ class HttpHandler {
411
411
  response.statusCode = status;
412
412
  const { document } = this.adapter;
413
413
  const dt = document.node.getComplexType('OperationResult');
414
- let encode = this[constants_1.kAssetCache].get(dt, 'encode');
414
+ let encode = this[constants_js_1.kAssetCache].get(dt, 'encode');
415
415
  if (!encode) {
416
416
  encode = dt.generateCodec('encode', { ignoreWriteonlyFields: true });
417
- this[constants_1.kAssetCache].set(dt, 'encode', encode);
417
+ this[constants_js_1.kAssetCache].set(dt, 'encode', encode);
418
418
  }
419
419
  const { i18n } = this.adapter;
420
420
  const bodyObject = new common_1.OperationResult({
@@ -449,12 +449,12 @@ class HttpHandler {
449
449
  return this.sendResponse(context);
450
450
  }
451
451
  /** Check if response cache exists */
452
- let responseBody = this[constants_1.kAssetCache].get(doc, `$schema`);
452
+ let responseBody = this[constants_js_1.kAssetCache].get(doc, `$schema`);
453
453
  /** Create response if response cache does not exists */
454
454
  if (!responseBody) {
455
455
  const schema = doc.export();
456
456
  responseBody = JSON.stringify(schema);
457
- this[constants_1.kAssetCache].set(doc, `$schema`, responseBody);
457
+ this[constants_js_1.kAssetCache].set(doc, `$schema`, responseBody);
458
458
  }
459
459
  response.end(responseBody);
460
460
  }
@@ -480,7 +480,7 @@ class HttpHandler {
480
480
  }
481
481
  let operationResponse;
482
482
  const cacheKey = `HttpOperationResponse:${statusCode}${contentType ? ':' + contentType : ''}`;
483
- let responseArgs = this[constants_1.kAssetCache].get(response, cacheKey);
483
+ let responseArgs = this[constants_js_1.kAssetCache].get(response, cacheKey);
484
484
  if (!responseArgs) {
485
485
  responseArgs = { statusCode, contentType };
486
486
  if (operation?.responses.length) {
@@ -532,7 +532,7 @@ class HttpHandler {
532
532
  if (context.queryParams.projection)
533
533
  responseArgs.projection = context.queryParams.projection;
534
534
  }
535
- this[constants_1.kAssetCache].set(response, cacheKey, { ...responseArgs });
535
+ this[constants_js_1.kAssetCache].set(response, cacheKey, { ...responseArgs });
536
536
  }
537
537
  /** Fix response value according to composition */
538
538
  const composition = operationResponse?.owner.composition;
@@ -590,7 +590,7 @@ class HttpHandler {
590
590
  return responseArgs;
591
591
  }
592
592
  _wrapExceptions(exceptions) {
593
- const wrappedErrors = exceptions.map(wrap_exception_1.wrapException);
593
+ const wrappedErrors = exceptions.map(wrap_exception_js_1.wrapException);
594
594
  if (!wrappedErrors.length)
595
595
  wrappedErrors.push(new common_1.InternalServerError());
596
596
  // Sort errors from fatal to info
@@ -5,8 +5,8 @@ import { parse as parseContentType } from 'content-type';
5
5
  import { splitString } from 'fast-tokenizer';
6
6
  import { asMutable } from 'ts-gems';
7
7
  import { toArray, ValidationError, vg } from 'valgen';
8
- import { kAssetCache } from '../constants';
9
- import { wrapException } from './utils/wrap-exception';
8
+ import { kAssetCache } from '../constants.js';
9
+ import { wrapException } from './utils/wrap-exception.js';
10
10
  /**
11
11
  * @class HttpHandler
12
12
  */
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,39 +1,14 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.33",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/panates/opra.git",
10
- "directory": "packages/core"
11
- },
12
- "scripts": {
13
- "compile": "tsc",
14
- "prebuild": "npm run lint && npm run clean",
15
- "build": "npm run build:cjs && npm run build:esm",
16
- "build:cjs": "tsc -b tsconfig-build-cjs.json",
17
- "build:esm": "tsc -b tsconfig-build-esm.json",
18
- "postbuild": "npm run postbuild:copy_1 && npm run postbuild:copy_2",
19
- "postbuild:copy_1": "cp README.md package.json ../../LICENSE ../../build/core && cp ../../package.cjs.json ../../build/core/cjs/package.json",
20
- "postbuild:copy_2": "cp -R i18n ../../build/core/i18n",
21
- "lint": "eslint . --max-warnings=0",
22
- "lint:fix": "eslint . --max-warnings=0 --fix",
23
- "format": "prettier . --write --log-level=warn",
24
- "check": "madge --circular src/**",
25
- "test": "jest --passWithNoTests",
26
- "cover": "jest --passWithNoTests --collect-coverage",
27
- "clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
28
- "clean:src": "ts-cleanup -s src --all",
29
- "clean:test": "ts-cleanup -s test --all",
30
- "clean:dist": "rimraf ../../build/client",
31
- "clean:cover": "rimraf ../../coverage/client"
32
- },
33
7
  "dependencies": {
34
- "@browsery/http-parser": "^0.5.8",
35
- "@browsery/type-is": "^1.6.18-r2",
36
- "@opra/common": "^1.0.0-alpha.32",
8
+ "@browsery/antlr4": "^4.13.3-r1",
9
+ "@browsery/http-parser": "^0.5.9-r1",
10
+ "@browsery/type-is": "^1.6.18-r5",
11
+ "@opra/common": "^1.0.0-alpha.33",
37
12
  "accepts": "^1.3.8",
38
13
  "base64-stream": "^1.0.0",
39
14
  "busboy": "^1.6.0",
@@ -44,59 +19,54 @@
44
19
  "cookie-signature": "^1.2.1",
45
20
  "cppzst": "^2.0.12",
46
21
  "encodeurl": "^2.0.0",
22
+ "fast-tokenizer": "^1.6.1",
47
23
  "fresh": "^0.5.2",
48
24
  "iconv-lite": "^0.6.3",
49
25
  "mime-types": "^2.1.35",
50
- "power-tasks": "^1.7.7",
26
+ "power-tasks": "^1.10.1",
51
27
  "putil-isplainobject": "^1.1.5",
52
28
  "putil-merge": "^3.13.0",
53
29
  "putil-varhelpers": "^1.6.5",
54
30
  "range-parser": "^1.2.1",
55
31
  "raw-body": "^3.0.0",
56
32
  "reflect-metadata": "^0.2.2",
57
- "strict-typed-events": "^2.4.0",
33
+ "strict-typed-events": "^2.7.2",
58
34
  "tslib": "^2.6.3",
35
+ "valgen": "^5.8.2",
59
36
  "vary": "^1.1.2"
60
37
  },
61
38
  "optionalDependencies": {
62
39
  "express": "^4.x.x || ^5.x.x",
63
40
  "fastify": "^4.x.x"
64
41
  },
65
- "devDependencies": {
66
- "@faker-js/faker": "^8.4.1",
67
- "@types/accepts": "^1.3.7",
68
- "@types/base64-stream": "^1.0.5",
69
- "@types/busboy": "^1.5.4",
70
- "@types/bytes": "^3.1.4",
71
- "@types/content-disposition": "^0.5.8",
72
- "@types/content-type": "^1.1.8",
73
- "@types/cookie": "^0.6.0",
74
- "@types/cookie-parser": "^1.4.7",
75
- "@types/cookie-signature": "^1.1.2",
76
- "@types/encodeurl": "^1.0.2",
77
- "@types/express": "^4.17.21",
78
- "@types/fresh": "^0.5.2",
79
- "@types/mime-types": "^2.1.4",
80
- "@types/range-parser": "^1.2.7",
81
- "@types/vary": "^1.1.3",
82
- "cookie-parser": "^1.4.6",
83
- "crypto-browserify": "^3.12.0",
84
- "express": "^4.19.2",
85
- "fastify": "^4.28.1",
86
- "path-browserify": "^1.0.1",
87
- "supertest": "^7.0.0",
88
- "ts-gems": "^3.4.0"
89
- },
90
42
  "type": "module",
91
- "module": "./esm/index.js",
43
+ "exports": {
44
+ ".": {
45
+ "import": {
46
+ "types": "./types/index.d.ts",
47
+ "default": "./esm/index.js"
48
+ },
49
+ "require": {
50
+ "types": "./types/index.d.ts",
51
+ "default": "./cjs/index.js"
52
+ },
53
+ "default": "./esm/index.js"
54
+ },
55
+ "./package.json": "./package.json"
56
+ },
92
57
  "main": "./cjs/index.js",
58
+ "module": "./esm/index.js",
93
59
  "types": "./types/index.d.ts",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "https://github.com/panates/opra.git",
63
+ "directory": "packages/core"
64
+ },
94
65
  "engines": {
95
66
  "node": ">=16.0",
96
67
  "npm": ">=7.0.0"
97
68
  },
98
69
  "files": [
99
- "bin/",
100
70
  "cjs/",
101
71
  "esm/",
102
72
  "i18n/",
@@ -114,4 +84,4 @@
114
84
  "swagger",
115
85
  "raml"
116
86
  ]
117
- }
87
+ }
@@ -1,8 +1,8 @@
1
1
  import { HttpOperationResponse, OpraException, OpraHttpError } 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';
2
+ import { kAssetCache } from '../constants.js';
3
+ import type { HttpAdapter } from './http-adapter.js';
4
+ import { HttpContext } from './http-context.js';
5
+ import { AssetCache } from './impl/asset-cache.js';
6
6
  /**
7
7
  * @namespace
8
8
  */
@@ -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
- }