@opra/core 0.27.0 → 0.28.0

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.
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const fs_1 = tslib_1.__importDefault(require("fs"));
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const common_1 = require("@opra/common");
7
+ common_1.I18n.prototype.loadResourceBundle = async function (lang, ns, filePath, deep, overwrite) {
8
+ let obj;
9
+ if ((0, common_1.isUrlString)(filePath)) {
10
+ obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
11
+ }
12
+ else {
13
+ const content = fs_1.default.readFileSync(filePath, 'utf8');
14
+ obj = JSON.parse(content);
15
+ }
16
+ this.addResourceBundle(lang, ns, obj, deep, overwrite);
17
+ };
18
+ common_1.I18n.prototype.loadResourceDir = async function (dirnames, deep, overwrite) {
19
+ for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
20
+ /* istanbul ignore next */
21
+ if (!(fs_1.default.existsSync(dirname)))
22
+ continue;
23
+ const languageDirs = fs_1.default.readdirSync(dirname);
24
+ for (const lang of languageDirs) {
25
+ const langDir = path_1.default.join(dirname, lang);
26
+ if ((fs_1.default.statSync(langDir)).isDirectory()) {
27
+ const nsDirs = fs_1.default.readdirSync(langDir);
28
+ for (const nsfile of nsDirs) {
29
+ const nsFilePath = path_1.default.join(langDir, nsfile);
30
+ const ext = path_1.default.extname(nsfile);
31
+ if (ext === '.json' && (fs_1.default.statSync(nsFilePath)).isFile()) {
32
+ const ns = path_1.default.basename(nsfile, ext);
33
+ await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+ };
@@ -4,8 +4,8 @@ exports.HttpAdapterHost = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const promises_1 = tslib_1.__importDefault(require("fs/promises"));
6
6
  const os_1 = tslib_1.__importDefault(require("os"));
7
- const type_is_1 = tslib_1.__importDefault(require("type-is"));
8
7
  const vg = tslib_1.__importStar(require("valgen"));
8
+ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
9
9
  const common_1 = require("@opra/common");
10
10
  const execution_context_host_js_1 = require("../execution-context.host.js");
11
11
  const platform_adapter_host_js_1 = require("../platform-adapter.host.js");
@@ -90,7 +90,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
90
90
  throw e;
91
91
  if (e instanceof vg.ValidationError) {
92
92
  throw new common_1.BadRequestError({
93
- message: (0, common_1.translate)('error:RESPONSE_VALIDATION,', 'Response validation failed'),
93
+ message: (0, common_1.translate)('error:RESPONSE_VALIDATION,'),
94
94
  code: 'RESPONSE_VALIDATION',
95
95
  details: e.issues
96
96
  }, e);
@@ -109,7 +109,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
109
109
  throw e;
110
110
  if (e instanceof vg.ValidationError) {
111
111
  throw new common_1.InternalServerError({
112
- message: (0, common_1.translate)('error:RESPONSE_VALIDATION,', 'Response validation failed'),
112
+ message: (0, common_1.translate)('error:RESPONSE_VALIDATION,'),
113
113
  code: 'RESPONSE_VALIDATION',
114
114
  details: e.issues
115
115
  }, e);
@@ -9,7 +9,7 @@ const tslib_1 = require("tslib");
9
9
  const accepts_1 = tslib_1.__importDefault(require("accepts"));
10
10
  const fresh_1 = tslib_1.__importDefault(require("fresh"));
11
11
  const range_parser_1 = tslib_1.__importDefault(require("range-parser"));
12
- const type_is_1 = tslib_1.__importDefault(require("type-is"));
12
+ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
13
13
  const common_1 = require("@opra/common");
14
14
  const http_incoming_message_host_js_1 = require("./impl/http-incoming-message.host.js");
15
15
  function isHttpIncomingMessage(v) {
package/cjs/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  require("reflect-metadata");
5
+ require("./augmentation/18n.augmentation.js");
5
6
  require("./augmentation/resource.augmentation.js");
6
7
  require("./augmentation/collection.augmentation.js");
7
8
  require("./augmentation/container.augmentation.js");
@@ -114,7 +114,7 @@ class PlatformAdapterHost extends strict_typed_events_1.AsyncEventEmitter {
114
114
  return { controller, endpoint, handler };
115
115
  }
116
116
  throw new common_1.BadRequestError({
117
- message: (0, common_1.translate)('ACTION_NOT_FOUND', { resource: resource.name, action: name }, `The {{resource}} resource doesn't have an action named '{{action}}'`),
117
+ message: (0, common_1.translate)('error:ACTION_NOT_FOUND', { resource: resource.name, action: name }),
118
118
  severity: 'error',
119
119
  code: 'ACTION_NOT_FOUND'
120
120
  });
@@ -131,7 +131,7 @@ class PlatformAdapterHost extends strict_typed_events_1.AsyncEventEmitter {
131
131
  return { controller, endpoint, handler };
132
132
  }
133
133
  throw new common_1.ForbiddenError({
134
- message: (0, common_1.translate)('OPERATION_FORBIDDEN', { resource: resource.name, operation: name }, `'The {{resource}} resource does not accept '{{operation}}' operations`),
134
+ message: (0, common_1.translate)('error:OPERATION_FORBIDDEN', { resource: resource.name, operation: name }),
135
135
  severity: 'error',
136
136
  code: 'OPERATION_FORBIDDEN'
137
137
  });
@@ -0,0 +1,36 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { I18n, isUrlString } from '@opra/common';
4
+ I18n.prototype.loadResourceBundle = async function (lang, ns, filePath, deep, overwrite) {
5
+ let obj;
6
+ if (isUrlString(filePath)) {
7
+ obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
8
+ }
9
+ else {
10
+ const content = fs.readFileSync(filePath, 'utf8');
11
+ obj = JSON.parse(content);
12
+ }
13
+ this.addResourceBundle(lang, ns, obj, deep, overwrite);
14
+ };
15
+ I18n.prototype.loadResourceDir = async function (dirnames, deep, overwrite) {
16
+ for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
17
+ /* istanbul ignore next */
18
+ if (!(fs.existsSync(dirname)))
19
+ continue;
20
+ const languageDirs = fs.readdirSync(dirname);
21
+ for (const lang of languageDirs) {
22
+ const langDir = path.join(dirname, lang);
23
+ if ((fs.statSync(langDir)).isDirectory()) {
24
+ const nsDirs = fs.readdirSync(langDir);
25
+ for (const nsfile of nsDirs) {
26
+ const nsFilePath = path.join(langDir, nsfile);
27
+ const ext = path.extname(nsfile);
28
+ if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
29
+ const ns = path.basename(nsfile, ext);
30
+ await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ };
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs/promises';
2
2
  import os from 'os';
3
- import typeIs from 'type-is';
4
3
  import * as vg from 'valgen';
4
+ import typeIs from '@browsery/type-is';
5
5
  import { BadRequestError, Collection, Container, HttpHeaderCodes, HttpStatusCodes, InternalServerError, isReadable, IssueSeverity, MethodNotAllowedError, OperationResult, OpraException, OpraSchema, OpraURL, ResourceNotFoundError, Singleton, Storage, translate, uid, wrapException } from '@opra/common';
6
6
  import { ExecutionContextHost } from '../execution-context.host.js';
7
7
  import { PlatformAdapterHost } from '../platform-adapter.host.js';
@@ -86,7 +86,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
86
86
  throw e;
87
87
  if (e instanceof vg.ValidationError) {
88
88
  throw new BadRequestError({
89
- message: translate('error:RESPONSE_VALIDATION,', 'Response validation failed'),
89
+ message: translate('error:RESPONSE_VALIDATION,'),
90
90
  code: 'RESPONSE_VALIDATION',
91
91
  details: e.issues
92
92
  }, e);
@@ -105,7 +105,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
105
105
  throw e;
106
106
  if (e instanceof vg.ValidationError) {
107
107
  throw new InternalServerError({
108
- message: translate('error:RESPONSE_VALIDATION,', 'Response validation failed'),
108
+ message: translate('error:RESPONSE_VALIDATION,'),
109
109
  code: 'RESPONSE_VALIDATION',
110
110
  details: e.issues
111
111
  }, e);
@@ -5,7 +5,7 @@
5
5
  import accepts from 'accepts';
6
6
  import fresh from 'fresh';
7
7
  import parseRange from 'range-parser';
8
- import typeIs from 'type-is';
8
+ import typeIs from '@browsery/type-is';
9
9
  import { isReadable, mergePrototype, OpraURL } from '@opra/common';
10
10
  import { HttpIncomingMessageHost } from './impl/http-incoming-message.host.js';
11
11
  function isHttpIncomingMessage(v) {
package/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import './augmentation/18n.augmentation.js';
2
3
  import './augmentation/resource.augmentation.js';
3
4
  import './augmentation/collection.augmentation.js';
4
5
  import './augmentation/container.augmentation.js';
@@ -110,7 +110,7 @@ export class PlatformAdapterHost extends AsyncEventEmitter {
110
110
  return { controller, endpoint, handler };
111
111
  }
112
112
  throw new BadRequestError({
113
- message: translate('ACTION_NOT_FOUND', { resource: resource.name, action: name }, `The {{resource}} resource doesn't have an action named '{{action}}'`),
113
+ message: translate('error:ACTION_NOT_FOUND', { resource: resource.name, action: name }),
114
114
  severity: 'error',
115
115
  code: 'ACTION_NOT_FOUND'
116
116
  });
@@ -127,7 +127,7 @@ export class PlatformAdapterHost extends AsyncEventEmitter {
127
127
  return { controller, endpoint, handler };
128
128
  }
129
129
  throw new ForbiddenError({
130
- message: translate('OPERATION_FORBIDDEN', { resource: resource.name, operation: name }, `'The {{resource}} resource does not accept '{{operation}}' operations`),
130
+ message: translate('error:OPERATION_FORBIDDEN', { resource: resource.name, operation: name }),
131
131
  severity: 'error',
132
132
  code: 'OPERATION_FORBIDDEN'
133
133
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -27,7 +27,8 @@
27
27
  "clean:cover": "rimraf ../../coverage/core"
28
28
  },
29
29
  "dependencies": {
30
- "@opra/common": "^0.27.0",
30
+ "@browsery/type-is": "^0.6.3",
31
+ "@opra/common": "^0.28.0",
31
32
  "accepts": "^1.3.8",
32
33
  "content-disposition": "^0.5.4",
33
34
  "content-type": "^1.0.5",
@@ -42,14 +43,13 @@
42
43
  "putil-varhelpers": "^1.6.5",
43
44
  "range-parser": "^1.2.1",
44
45
  "strict-typed-events": "^2.3.2",
45
- "type-is": "^1.6.18",
46
46
  "vary": "^1.1.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "express": "^4.x.x || ^5.x.x"
50
50
  },
51
51
  "devDependencies": {
52
- "@faker-js/faker": "^8.1.0",
52
+ "@faker-js/faker": "^8.2.0",
53
53
  "@types/accepts": "^1.3.5",
54
54
  "@types/content-disposition": "^0.5.6",
55
55
  "@types/content-type": "^1.1.6",
@@ -0,0 +1,7 @@
1
+ declare module "@opra/common" {
2
+ interface I18n {
3
+ loadResourceDir(dirnames: string | string[], deep?: boolean, overwrite?: boolean): Promise<void>;
4
+ loadResourceBundle(lang: string, ns: string, filePath: string, deep?: boolean, overwrite?: boolean): Promise<void>;
5
+ }
6
+ }
7
+ export {};
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import './augmentation/18n.augmentation.js';
2
3
  import './augmentation/resource.augmentation.js';
3
4
  import './augmentation/collection.augmentation.js';
4
5
  import './augmentation/container.augmentation.js';