core-3nweb-client-lib 0.27.10 → 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.
@@ -65,6 +65,7 @@ class ServerEvents {
65
65
  return () => {
66
66
  if (detach) {
67
67
  detach();
68
+ detach = undefined;
68
69
  }
69
70
  else {
70
71
  obs = undefined;
@@ -0,0 +1 @@
1
+ export declare function makeRuntimeException<T extends web3n.RuntimeException>(type: NonNullable<T['type']>, params: Partial<T>, flags: Partial<T>): T;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2021 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.makeRuntimeException = void 0;
20
+ function makeRuntimeException(type, params, flags) {
21
+ const exc = {
22
+ runtimeException: true,
23
+ type,
24
+ };
25
+ for (const [field, val] of Object.entries(params)) {
26
+ if (val !== undefined) {
27
+ exc[field] = val;
28
+ }
29
+ }
30
+ for (const [field, val] of Object.entries(flags)) {
31
+ if (val === true) {
32
+ exc[field] = val;
33
+ }
34
+ }
35
+ return exc;
36
+ }
37
+ exports.makeRuntimeException = makeRuntimeException;
38
+ Object.freeze(exports);
@@ -1,11 +1,12 @@
1
1
  import { TimedCache } from './timed-cache';
2
2
  export declare class WeakCache<TKey, TVal> {
3
3
  private readonly wRefs;
4
+ private readonly valFinalRegistry;
4
5
  constructor();
5
6
  get(key: TKey): TVal | undefined;
6
7
  has(key: TKey): boolean;
7
8
  set(key: TKey, val: TVal): void;
8
- private makeCB;
9
+ private finalize;
9
10
  delete(key: TKey): void;
10
11
  clear(): void;
11
12
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2019, 2021 3NSoft Inc.
3
+ Copyright (C) 2016 - 2019, 2021, 2023 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -17,24 +17,16 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.WeakCacheWithMinLifeTime = exports.WeakCache = void 0;
20
- const weakref_1 = require("./weakref");
21
- // XXX WeakReference shields choice between inbuilt and napi implementations of
22
- // weaks. But inbuilt uses FinalizationRegistry, which is better used in cache
23
- // directly. Take a look at following code:
24
- // let registry = new FinalizationRegistry(key => { ... removes WeakRef });
25
- // registry.register(val, key, val);
26
- // ... on delete do: registry.unregister(val);
27
- // Note that our WeakReference wrap has its own FinalizationRegistry, making it
28
- // heavier.
29
20
  class WeakCache {
30
21
  constructor() {
31
22
  this.wRefs = new Map();
23
+ this.valFinalRegistry = new FinalizationRegistry(this.finalize.bind(this));
32
24
  Object.freeze(this);
33
25
  }
34
26
  get(key) {
35
27
  const wRef = this.wRefs.get(key);
36
28
  if (wRef) {
37
- const v = wRef.get();
29
+ const v = wRef.deref();
38
30
  if (v === undefined) {
39
31
  this.wRefs.delete(key);
40
32
  }
@@ -48,16 +40,14 @@ class WeakCache {
48
40
  return (this.get(key) !== undefined);
49
41
  }
50
42
  set(key, val) {
51
- const wRef = (0, weakref_1.makeWeakRefFor)(val);
52
- wRef.addCallback(this.makeCB(key, wRef));
43
+ const wRef = new WeakRef(val);
44
+ this.valFinalRegistry.register(val, { key, wRef });
53
45
  this.wRefs.set(key, wRef);
54
46
  }
55
- makeCB(key, wRef) {
56
- return () => {
57
- if (wRef === this.wRefs.get(key)) {
58
- this.wRefs.delete(key);
59
- }
60
- };
47
+ finalize({ key, wRef }) {
48
+ if (wRef === this.wRefs.get(key)) {
49
+ this.wRefs.delete(key);
50
+ }
61
51
  }
62
52
  delete(key) {
63
53
  this.wRefs.delete(key);
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.27.10",
3
+ "version": "0.28.0",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",
7
7
  "scripts": {
8
8
  "build-only-ts": "tsc -p ts-code && bash -c 'cp -rf ts-code/lib-sqlite-on-3nstorage/sqljs.* build/lib-sqlite-on-3nstorage/' ",
9
9
  "build": "bash packing/protos-to-node-module.sh && npm run build-only-ts && bash packing/copy-api.sh && bash packing/build-wasm-cryptor.sh",
10
- "test": "node build/tests/jasmine.js"
10
+ "test": "node build/tests/jasmine.js",
11
+ "postinstall": "node -e \"try{require('./postinstall')}catch(e){}\""
11
12
  },
12
13
  "repository": {
13
14
  "type": "git",
package/postinstall.js ADDED
@@ -0,0 +1,25 @@
1
+
2
+ function is(it) {
3
+ return !!it && it !== '0' && it !== 'false';
4
+ }
5
+
6
+ const env = process.env;
7
+
8
+ const ADBLOCK = is(env.ADBLOCK);
9
+ const SILENT = ['silent', 'error', 'warn'].includes(env.npm_config_loglevel) ;
10
+ const COLOR = is(env.npm_config_color);
11
+
12
+ const BANNER = `\u001B[96mThank you for using core-3nweb-client-lib (\u001B[94m https://github.com/3nsoft/core-3nweb-client-lib.git \u001B[96m) to power core of 3NWeb client side platform, like PrivacySafe, within which this library is developed\u001B[0m
13
+
14
+ \u001B[96mThe project needs your help! Please consider supporting PrivacySafe on Open Collective: \u001B[0m
15
+ \u001B[96m>\u001B[94m https://opencollective.com/privacysafe \u001B[0m
16
+ `;
17
+
18
+ function isBannerRequired() {
19
+ if (ADBLOCK || SILENT) { return false; }
20
+ return true;
21
+ }
22
+
23
+ if (isBannerRequired()) {
24
+ console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
25
+ }
@@ -1,7 +0,0 @@
1
- export interface WeakReference<T> {
2
- addCallback(cb: Function): void;
3
- removeCallback(cb: Function): void;
4
- removeCallbacks(): void;
5
- get(): T | undefined;
6
- }
7
- export declare function makeWeakRefFor<T>(o: T): WeakReference<T>;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (C) 2019, 2021 3NSoft Inc.
4
-
5
- This program is free software: you can redistribute it and/or modify it under
6
- the terms of the GNU General Public License as published by the Free Software
7
- Foundation, either version 3 of the License, or (at your option) any later
8
- version.
9
-
10
- This program is distributed in the hope that it will be useful, but
11
- WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
- See the GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.makeWeakRefFor = void 0;
20
- if (!WeakRef || !FinalizationRegistry) {
21
- throw new Error(`Weak references are not available, and this module can't be used`);
22
- }
23
- function makeWeakRefFor(o) {
24
- return new WeakRefInbuiltImpl(o);
25
- }
26
- exports.makeWeakRefFor = makeWeakRefFor;
27
- class WeakRefInbuiltImpl {
28
- constructor(o) {
29
- this.callbacks = [];
30
- this.ref = new WeakRef(o);
31
- this.registry = new FinalizationRegistry(this.makeCleanupCallback());
32
- Object.freeze(this);
33
- }
34
- makeCleanupCallback() {
35
- return () => {
36
- for (const cb of this.callbacks) {
37
- try {
38
- cb();
39
- }
40
- catch (err) {
41
- console.error(err);
42
- }
43
- }
44
- };
45
- }
46
- addCallback(cb) {
47
- this.callbacks.push(cb);
48
- }
49
- removeCallback(cb) {
50
- const ind = this.callbacks.indexOf(cb);
51
- if (ind >= 0) {
52
- this.callbacks.splice(ind, 1);
53
- }
54
- }
55
- removeCallbacks() {
56
- this.callbacks.splice(0, this.callbacks.length);
57
- }
58
- get() {
59
- return this.ref.deref();
60
- }
61
- }
62
- Object.freeze(WeakRefInbuiltImpl.prototype);
63
- Object.freeze(WeakRefInbuiltImpl);
64
- Object.freeze(exports);