@opra/core 1.0.0-beta.3 → 1.0.0-beta.5

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.
@@ -17,5 +17,11 @@ class AssetCache {
17
17
  }
18
18
  cache[name] = asset;
19
19
  }
20
+ delete(obj, name) {
21
+ const cache = this._items.get(obj);
22
+ if (!cache)
23
+ return;
24
+ delete cache[name];
25
+ }
20
26
  }
21
27
  exports.AssetCache = AssetCache;
@@ -8,6 +8,7 @@ const node_events_async_1 = require("node-events-async");
8
8
  class ExecutionContext extends node_events_async_1.AsyncEventEmitter {
9
9
  constructor(init) {
10
10
  super();
11
+ this.shared = new Map();
11
12
  this.errors = [];
12
13
  this.document = init.document;
13
14
  this.protocol = init.protocol;
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceBase = void 0;
4
4
  class ServiceBase {
5
5
  get context() {
6
- if (!this._context)
7
- throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
6
+ this._assertContext();
8
7
  return this._context;
9
8
  }
10
9
  for(context, overwriteProperties, overwriteContext) {
11
- // Create new context instance
10
+ if (context instanceof ServiceBase)
11
+ context = context.context;
12
+ /** Create new context instance */
12
13
  const ctx = {};
13
14
  Object.setPrototypeOf(ctx, context);
14
15
  if (overwriteContext)
15
16
  Object.assign(ctx, overwriteContext);
16
- // Create new service instance
17
+ /** Create new service instance */
17
18
  const instance = { _context: ctx };
18
19
  Object.setPrototypeOf(instance, this);
19
20
  if (overwriteProperties)
@@ -22,6 +23,10 @@ class ServiceBase {
22
23
  this[ServiceBase.extendSymbol](instance);
23
24
  return instance;
24
25
  }
26
+ _assertContext() {
27
+ if (!this._context)
28
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
29
+ }
25
30
  }
26
31
  exports.ServiceBase = ServiceBase;
27
32
  (function (ServiceBase) {
@@ -14,4 +14,10 @@ export class AssetCache {
14
14
  }
15
15
  cache[name] = asset;
16
16
  }
17
+ delete(obj, name) {
18
+ const cache = this._items.get(obj);
19
+ if (!cache)
20
+ return;
21
+ delete cache[name];
22
+ }
17
23
  }
@@ -5,6 +5,7 @@ import { AsyncEventEmitter } from 'node-events-async';
5
5
  export class ExecutionContext extends AsyncEventEmitter {
6
6
  constructor(init) {
7
7
  super();
8
+ this.shared = new Map();
8
9
  this.errors = [];
9
10
  this.document = init.document;
10
11
  this.protocol = init.protocol;
@@ -1,16 +1,17 @@
1
1
  export class ServiceBase {
2
2
  get context() {
3
- if (!this._context)
4
- throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
3
+ this._assertContext();
5
4
  return this._context;
6
5
  }
7
6
  for(context, overwriteProperties, overwriteContext) {
8
- // Create new context instance
7
+ if (context instanceof ServiceBase)
8
+ context = context.context;
9
+ /** Create new context instance */
9
10
  const ctx = {};
10
11
  Object.setPrototypeOf(ctx, context);
11
12
  if (overwriteContext)
12
13
  Object.assign(ctx, overwriteContext);
13
- // Create new service instance
14
+ /** Create new service instance */
14
15
  const instance = { _context: ctx };
15
16
  Object.setPrototypeOf(instance, this);
16
17
  if (overwriteProperties)
@@ -19,6 +20,10 @@ export class ServiceBase {
19
20
  this[ServiceBase.extendSymbol](instance);
20
21
  return instance;
21
22
  }
23
+ _assertContext() {
24
+ if (!this._context)
25
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
26
+ }
22
27
  }
23
28
  (function (ServiceBase) {
24
29
  ServiceBase.extendSymbol = Symbol('extend');
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@opra/common": "^1.0.0-beta.3",
8
+ "@opra/common": "^1.0.0-beta.5",
9
9
  "node-events-async": "^1.0.0",
10
10
  "reflect-metadata": "^0.2.2",
11
11
  "tslib": "^2.7.0"
@@ -2,4 +2,5 @@ export declare class AssetCache {
2
2
  protected _items: WeakMap<any, Record<string, any>>;
3
3
  get<T>(obj: any, name: string): T | undefined;
4
4
  set(obj: any, name: string, asset: any): void;
5
+ delete(obj: any, name: string): void;
5
6
  }
@@ -14,6 +14,7 @@ export declare namespace ExecutionContext {
14
14
  * @class ExecutionContext
15
15
  */
16
16
  export declare abstract class ExecutionContext extends AsyncEventEmitter {
17
+ readonly shared: Map<any, any>;
17
18
  readonly document: ApiDocument;
18
19
  readonly protocol: OpraSchema.Transport;
19
20
  readonly platform: string;
@@ -3,12 +3,14 @@ import { ApiDocument, I18n, OpraSchema } from '@opra/common';
3
3
  import { AsyncEventEmitter } from 'node-events-async';
4
4
  import { AssetCache } from './asset-cache.js';
5
5
  import { kAssetCache } from './constants.js';
6
+ import { ILogger } from './interfaces/logger.interface.js';
6
7
  /**
7
8
  * @namespace PlatformAdapter
8
9
  */
9
10
  export declare namespace PlatformAdapter {
10
11
  interface Options {
11
12
  i18n?: I18n;
13
+ logger?: ILogger;
12
14
  }
13
15
  }
14
16
  /**
@@ -19,6 +21,7 @@ export declare abstract class PlatformAdapter extends AsyncEventEmitter {
19
21
  readonly document: ApiDocument;
20
22
  abstract readonly protocol: OpraSchema.Transport;
21
23
  i18n: I18n;
24
+ logger?: ILogger;
22
25
  protected constructor(document: ApiDocument, options?: PlatformAdapter.Options);
23
26
  abstract close(): Promise<void>;
24
27
  }
@@ -3,7 +3,8 @@ import type { ExecutionContext } from './execution-context.js';
3
3
  export declare abstract class ServiceBase {
4
4
  protected _context: ExecutionContext;
5
5
  get context(): ExecutionContext;
6
- for<C extends ExecutionContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
6
+ for<C extends ExecutionContext, P extends Partial<this>>(context: C | ServiceBase, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
7
+ protected _assertContext(): void;
7
8
  }
8
9
  export declare namespace ServiceBase {
9
10
  const extendSymbol: unique symbol;