@opra/core 1.21.0 → 1.22.1

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.
@@ -1,7 +1,5 @@
1
1
  export class AssetCache {
2
- constructor() {
3
- this._items = new WeakMap();
4
- }
2
+ _items = new WeakMap();
5
3
  get(obj, name) {
6
4
  const cache = this._items.get(obj);
7
5
  return cache && cache[name];
@@ -3,9 +3,13 @@ import { AsyncEventEmitter } from 'node-events-async';
3
3
  * @class ExecutionContext
4
4
  */
5
5
  export class ExecutionContext extends AsyncEventEmitter {
6
+ __docNode;
7
+ __adapter;
8
+ transport;
9
+ platform;
10
+ errors = [];
6
11
  constructor(init) {
7
12
  super();
8
- this.errors = [];
9
13
  this.__adapter = init.__adapter;
10
14
  this.__docNode = init.__docNode || init.__adapter.document.node;
11
15
  this.transport = init.transport || 'custom';
package/package.json CHANGED
@@ -1,52 +1,35 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "1.21.0",
3
+ "version": "1.22.1",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "node-events-async": "^1.2.0",
8
+ "node-events-async": "^1.5.0",
9
9
  "reflect-metadata": "^0.2.2",
10
10
  "tslib": "^2.8.1"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/common": "^1.21.0"
13
+ "@opra/common": "^1.22.1"
14
14
  },
15
15
  "type": "module",
16
+ "module": "./index.js",
17
+ "types": "./index.d.ts",
16
18
  "exports": {
17
19
  ".": {
18
- "import": {
19
- "types": "./types/index.d.ts",
20
- "default": "./esm/index.js"
21
- },
22
- "require": {
23
- "types": "./types/index.d.cts",
24
- "default": "./cjs/index.js"
25
- },
26
- "default": "./esm/index.js"
20
+ "types": "./index.d.ts",
21
+ "default": "./index.js"
27
22
  },
28
23
  "./package.json": "./package.json"
29
24
  },
30
- "main": "./cjs/index.js",
31
- "module": "./esm/index.js",
32
- "types": "./types/index.d.ts",
25
+ "engines": {
26
+ "node": ">=20.0"
27
+ },
33
28
  "repository": {
34
29
  "type": "git",
35
30
  "url": "git+https://github.com/panates/opra.git",
36
31
  "directory": "packages/core"
37
32
  },
38
- "engines": {
39
- "node": ">=16.0",
40
- "npm": ">=7.0.0"
41
- },
42
- "files": [
43
- "cjs/",
44
- "esm/",
45
- "i18n/",
46
- "types/",
47
- "LICENSE",
48
- "README.md"
49
- ],
50
33
  "keywords": [
51
34
  "opra",
52
35
  "rest",
@@ -1,13 +1,13 @@
1
1
  import './augmentation/18n.augmentation.js';
2
2
  import { ApiDocument, I18n, OpraSchema } from '@opra/common';
3
- import { AsyncEventEmitter, DefaultEventMap, EventMap } from 'node-events-async';
3
+ import { AsyncEventEmitter, EventMap } from 'node-events-async';
4
4
  import { AssetCache } from './asset-cache.js';
5
5
  import { kAssetCache } from './constants.js';
6
6
  import { ILogger } from './interfaces/logger.interface.js';
7
7
  /**
8
8
  * @class PlatformAdapter
9
9
  */
10
- export declare abstract class PlatformAdapter<T extends EventMap<T> = DefaultEventMap> extends AsyncEventEmitter<T> {
10
+ export declare abstract class PlatformAdapter<T extends EventMap<T> = never> extends AsyncEventEmitter<T> {
11
11
  protected [kAssetCache]: AssetCache;
12
12
  protected _document: ApiDocument;
13
13
  abstract readonly transform: OpraSchema.Transport;
@@ -1,12 +1,15 @@
1
1
  import './augmentation/18n.augmentation.js';
2
2
  import { I18n } from '@opra/common';
3
- import { AsyncEventEmitter, } from 'node-events-async';
3
+ import { AsyncEventEmitter } from 'node-events-async';
4
4
  import { AssetCache } from './asset-cache.js';
5
5
  import { kAssetCache } from './constants.js';
6
6
  /**
7
7
  * @class PlatformAdapter
8
8
  */
9
9
  export class PlatformAdapter extends AsyncEventEmitter {
10
+ [kAssetCache];
11
+ i18n;
12
+ logger;
10
13
  constructor(options) {
11
14
  super();
12
15
  this[kAssetCache] = new AssetCache();
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetCache = void 0;
4
- class AssetCache {
5
- constructor() {
6
- this._items = new WeakMap();
7
- }
8
- get(obj, name) {
9
- const cache = this._items.get(obj);
10
- return cache && cache[name];
11
- }
12
- set(obj, name, asset) {
13
- let cache = this._items.get(obj);
14
- if (!cache) {
15
- cache = {};
16
- this._items.set(obj, cache);
17
- }
18
- cache[name] = asset;
19
- }
20
- delete(obj, name) {
21
- const cache = this._items.get(obj);
22
- if (!cache)
23
- return;
24
- delete cache[name];
25
- }
26
- }
27
- exports.AssetCache = AssetCache;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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"));
6
- const common_1 = require("@opra/common");
7
- common_1.I18n.load = async function (options) {
8
- const opts = {
9
- ...options,
10
- };
11
- delete opts.resourceDirs;
12
- const instance = common_1.I18n.createInstance(opts);
13
- await instance.init();
14
- await instance.loadResourceDir(node_path_1.default.resolve((0, common_1.getStackFileName)(), '../../../i18n'));
15
- if (options?.resourceDirs)
16
- for (const dir of options.resourceDirs)
17
- await instance.loadResourceDir(dir);
18
- return instance;
19
- };
20
- common_1.I18n.prototype.loadResourceBundle = async function (lang, ns, filePath, deep, overwrite) {
21
- let obj;
22
- if (URL.canParse(filePath)) {
23
- obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
24
- }
25
- else {
26
- const content = node_fs_1.default.readFileSync(filePath, 'utf8');
27
- obj = JSON.parse(content);
28
- }
29
- this.addResourceBundle(lang, ns, obj, deep, overwrite);
30
- };
31
- common_1.I18n.prototype.loadResourceDir = async function (dirnames, deep, overwrite) {
32
- for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
33
- /* istanbul ignore next */
34
- if (!node_fs_1.default.existsSync(dirname))
35
- continue;
36
- const languageDirs = node_fs_1.default.readdirSync(dirname);
37
- for (const lang of languageDirs) {
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
- for (const nsfile of nsDirs) {
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
- await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
47
- }
48
- }
49
- }
50
- }
51
- }
52
- };
package/cjs/constants.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.kAssetCache = void 0;
4
- exports.kAssetCache = Symbol.for('kAssetCache');
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecutionContext = void 0;
4
- const node_events_async_1 = require("node-events-async");
5
- /**
6
- * @class ExecutionContext
7
- */
8
- class ExecutionContext extends node_events_async_1.AsyncEventEmitter {
9
- constructor(init) {
10
- super();
11
- this.errors = [];
12
- this.__adapter = init.__adapter;
13
- this.__docNode = init.__docNode || init.__adapter.document.node;
14
- this.transport = init.transport || 'custom';
15
- this.platform = init.platform || '';
16
- }
17
- }
18
- exports.ExecutionContext = ExecutionContext;
package/cjs/index.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("reflect-metadata");
5
- require("./augmentation/18n.augmentation.js");
6
- tslib_1.__exportStar(require("./asset-cache.js"), exports);
7
- tslib_1.__exportStar(require("./constants.js"), exports);
8
- tslib_1.__exportStar(require("./execution-context.js"), exports);
9
- tslib_1.__exportStar(require("./interfaces/logger.interface.js"), exports);
10
- tslib_1.__exportStar(require("./platform-adapter.js"), exports);
11
- tslib_1.__exportStar(require("./service-base.js"), exports);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformAdapter = void 0;
4
- require("./augmentation/18n.augmentation.js");
5
- const common_1 = require("@opra/common");
6
- const node_events_async_1 = require("node-events-async");
7
- const asset_cache_js_1 = require("./asset-cache.js");
8
- const constants_js_1 = require("./constants.js");
9
- /**
10
- * @class PlatformAdapter
11
- */
12
- class PlatformAdapter extends node_events_async_1.AsyncEventEmitter {
13
- constructor(options) {
14
- super();
15
- this[constants_js_1.kAssetCache] = new asset_cache_js_1.AssetCache();
16
- this.i18n = options?.i18n || common_1.I18n.defaultInstance;
17
- this.logger = options?.logger;
18
- }
19
- get document() {
20
- return this._document;
21
- }
22
- }
23
- exports.PlatformAdapter = PlatformAdapter;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceBase = void 0;
4
- class ServiceBase {
5
- get context() {
6
- this._assertContext();
7
- return this._context;
8
- }
9
- for(context, overwriteProperties, overwriteContext) {
10
- if (context instanceof ServiceBase)
11
- context = context.context;
12
- /** Create new context instance */
13
- const ctx = {};
14
- Object.setPrototypeOf(ctx, context);
15
- if (overwriteContext)
16
- Object.assign(ctx, overwriteContext);
17
- /** Create new service instance */
18
- const instance = { _context: ctx };
19
- Object.setPrototypeOf(instance, this);
20
- if (overwriteProperties)
21
- Object.assign(instance, overwriteProperties);
22
- if (this[ServiceBase.extendSymbol])
23
- this[ServiceBase.extendSymbol](instance);
24
- return instance;
25
- }
26
- _assertContext() {
27
- if (!this._context)
28
- throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
29
- }
30
- }
31
- exports.ServiceBase = ServiceBase;
32
- (function (ServiceBase) {
33
- ServiceBase.extendSymbol = Symbol('extend');
34
- })(ServiceBase || (exports.ServiceBase = ServiceBase = {}));
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/types/index.d.cts DELETED
@@ -1,8 +0,0 @@
1
- import 'reflect-metadata';
2
- import './augmentation/18n.augmentation.js';
3
- export * from './asset-cache.js';
4
- export * from './constants.js';
5
- export * from './execution-context.js';
6
- export * from './interfaces/logger.interface.js';
7
- export * from './platform-adapter.js';
8
- export * from './service-base.js';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes