emr-bridge 1.4.0 → 1.5.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.
package/README.md CHANGED
@@ -24,11 +24,11 @@ npm i emr-bridge
24
24
 
25
25
  ## Usage
26
26
 
27
- _If you need CommonJS modules, then use `emr-bridge/cjs`_
27
+ *If you need CommonJS modules, then use `emr-bridge/cjs`*
28
28
 
29
29
  There are three ways to use
30
30
 
31
- **IMPORTANT**: In any of the cases, you need to insert this code into preload
31
+ > In any of the cases, you need to insert this code into preload
32
32
 
33
33
  ```js
34
34
  // Preload process
@@ -37,7 +37,7 @@ import { provideFromMain } from 'emr-bridge/preload'
37
37
  provideFromMain(true /* context isolation */)
38
38
  ```
39
39
 
40
- **IMPORTANT**: To use experimental non-static decorators, it is required to wrap the creation of a class instance in the `providePublic` function
40
+ > To use experimental non-static decorators, it is required to wrap the creation of a class instance in the `providePublic` function
41
41
 
42
42
  ```js
43
43
  // Main process
@@ -48,7 +48,7 @@ class MainPublic { /*...*/ }
48
48
  const instance = providePublic(new MainPublic())
49
49
  ```
50
50
 
51
- **NOTE**: All experimental decorators can be found in `emr-bridge/exp`
51
+ > All experimental decorators can be found in `emr-bridge/exp`
52
52
 
53
53
  ### Static methods and properties
54
54
 
package/cjs/exp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Access, Scope } from './enums';
2
- export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMainEvent, publicStaticMethod, publicStaticProperty, publicStaticRendererEvent } from './scripts/oldDecorators';
2
+ export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/oldDecorators';
3
3
  export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
4
4
  export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
package/cjs/exp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.publicStaticRendererEvent = exports.publicStaticProperty = exports.publicStaticMethod = exports.publicStaticMainEvent = exports.publicProperty = exports.publicMethod = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.providePublic = exports.Scope = exports.Access = void 0;
3
+ exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.publicStaticProperty = exports.publicStaticMethod = exports.publicProperty = exports.publicMethod = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.providePublic = exports.Scope = exports.Access = void 0;
4
4
  var enums_1 = require("./enums");
5
5
  Object.defineProperty(exports, "Access", { enumerable: true, get: function () { return enums_1.Access; } });
6
6
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return enums_1.Scope; } });
@@ -10,10 +10,8 @@ Object.defineProperty(exports, "publicClassMainEvent", { enumerable: true, get:
10
10
  Object.defineProperty(exports, "publicClassRendererEvent", { enumerable: true, get: function () { return oldDecorators_1.publicClassRendererEvent; } });
11
11
  Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return oldDecorators_1.publicMethod; } });
12
12
  Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return oldDecorators_1.publicProperty; } });
13
- Object.defineProperty(exports, "publicStaticMainEvent", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMainEvent; } });
14
13
  Object.defineProperty(exports, "publicStaticMethod", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMethod; } });
15
14
  Object.defineProperty(exports, "publicStaticProperty", { enumerable: true, get: function () { return oldDecorators_1.publicStaticProperty; } });
16
- Object.defineProperty(exports, "publicStaticRendererEvent", { enumerable: true, get: function () { return oldDecorators_1.publicStaticRendererEvent; } });
17
15
  var publish_1 = require("./scripts/publish");
18
16
  Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_1.publicFunction; } });
19
17
  Object.defineProperty(exports, "publicMainEvent", { enumerable: true, get: function () { return publish_1.publicMainEvent; } });
@@ -15,8 +15,7 @@ const info = provider.getInfo();
15
15
  * _only for renderer process_
16
16
  */
17
17
  const Bridge = (0, provider_1.default)({
18
- info,
19
- scope: enums_1.Scope.renderer,
18
+ info, scope: enums_1.Scope.renderer,
20
19
  callFunction(name, ...args) {
21
20
  return provider.provided.functions[name](...args);
22
21
  },
@@ -27,11 +26,11 @@ const Bridge = (0, provider_1.default)({
27
26
  return provider.provided.mainEvents[name](type, handler);
28
27
  },
29
28
  getVariable(name) {
30
- return provider.provided.properties[name];
29
+ return provider.provided.properties[name].get();
31
30
  },
32
31
  setVariable(name, value) {
33
- provider.provided.properties[name] = value;
34
- return;
32
+ provider.provided.properties[name].set(value);
33
+ return undefined;
35
34
  },
36
35
  waitPromise(channel) {
37
36
  return new Promise((resolve, reject) => {
@@ -15,8 +15,7 @@ if (!info)
15
15
  * _only for preload process_
16
16
  */
17
17
  const Main = (0, provider_1.default)({
18
- info,
19
- scope: enums_1.Scope.preload,
18
+ info, scope: enums_1.Scope.preload,
20
19
  callFunction(name, ...args) {
21
20
  return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + name, ...args);
22
21
  },
@@ -85,11 +85,11 @@ function publicProperty(arg) {
85
85
  context.addInitializer(function () {
86
86
  (0, publish_1.publicVariable)(name, {
87
87
  get: () => {
88
- // @ts-ignore
88
+ // @ts-expect-error
89
89
  return this[key];
90
90
  },
91
91
  set: (value) => {
92
- // @ts-ignore
92
+ // @ts-expect-error
93
93
  this[key] = value;
94
94
  }
95
95
  });
@@ -57,32 +57,6 @@ export declare function publicMethod(name: string): MethodDecorator;
57
57
  * @param args - publish args
58
58
  */
59
59
  export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
60
- /**
61
- * Makes the event available for **renderer** and **preload** processes.
62
- *
63
- * _only for static_
64
- *
65
- * _experimental decorators_
66
- */
67
- export declare function publicStaticMainEvent(): MethodDecorator;
68
- /**
69
- * Makes the event available for **renderer** and **preload** processes.
70
- *
71
- * _only for static_
72
- *
73
- * _experimental decorators_
74
- * @param name - name by which the event will be accessed
75
- */
76
- export declare function publicStaticMainEvent(name: string): MethodDecorator;
77
- /**
78
- * Makes the event available for **renderer** and **preload** processes.
79
- *
80
- * _only for static_
81
- *
82
- * _experimental decorators_
83
- * @param args - publish args
84
- */
85
- export declare function publicStaticMainEvent(args: IPublishMainEventArgs): MethodDecorator;
86
60
  /**
87
61
  * Makes the event available for **renderer** and **preload** processes.
88
62
  *
@@ -115,60 +89,6 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
115
89
  * @param args - publish args
116
90
  */
117
91
  export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
118
- /**
119
- * Makes the event from **renderer** and **preload** available for **main** process.
120
- *
121
- * _only for static_
122
- *
123
- * _experimental decorators_
124
- */
125
- export declare function publicStaticRendererEvent(): PropertyDecorator;
126
- /**
127
- * Makes the event from **renderer** and **preload** available for **main** process.
128
- *
129
- * _only for static_
130
- *
131
- * _experimental decorators_
132
- * @param name - name by which the event will be accessed
133
- */
134
- export declare function publicStaticRendererEvent(name: string): PropertyDecorator;
135
- /**
136
- * Makes the event from **renderer** and **preload** available for **main** process.
137
- *
138
- * _only for static_
139
- *
140
- * _experimental decorators_
141
- * @param receiver - linked receiver
142
- */
143
- export declare function publicStaticRendererEvent(receiver: EventReceiver): PropertyDecorator;
144
- /**
145
- * Makes the event from **renderer** and **preload** available for **main** process.
146
- *
147
- * _only for static_
148
- *
149
- * _experimental decorators_
150
- * @param name - name by which the event will be accessed
151
- * @param receiver - linked receiver
152
- */
153
- export declare function publicStaticRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
154
- /**
155
- * Makes the event from **renderer** and **preload** available for **main** process.
156
- *
157
- * _only for static_
158
- *
159
- * _experimental decorators_
160
- * @param args - publish args
161
- */
162
- export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
163
- /**
164
- * Makes the event from **renderer** and **preload** available for **main** process.
165
- *
166
- * _only for static_
167
- *
168
- * _experimental decorators_
169
- * @param args - publish args
170
- */
171
- export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
172
92
  /**
173
93
  * Makes the event from **renderer** and **preload** available for **main** process.
174
94
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicStaticRendererEvent = exports.publicClassMainEvent = exports.publicStaticMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
3
+ exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
4
4
  const publish_1 = require("./publish");
5
5
  function publicStaticMethod(arg) {
6
6
  return (target, key) => {
@@ -30,63 +30,51 @@ function publicMethod(arg) {
30
30
  };
31
31
  }
32
32
  exports.publicMethod = publicMethod;
33
- function publicStaticMainEvent(arg) {
34
- return (target, key) => {
35
- let name = String(key);
36
- if (arg) {
37
- if (typeof arg === 'string') {
38
- name = arg;
39
- }
40
- else {
41
- name = arg.name ?? String(key);
42
- if (arg.scope)
43
- (0, publish_1.addScope)(name, arg.scope);
44
- }
45
- }
46
- target[key] = (0, publish_1.publicMainEvent)(name, target[key].bind(target));
47
- };
48
- }
49
- exports.publicStaticMainEvent = publicStaticMainEvent;
50
33
  function publicClassMainEvent(arg) {
51
34
  return (tgt, key, _) => {
52
35
  const target = tgt;
53
36
  const prevRegister = target.__register__ ?? (() => { });
54
37
  target.__register__ = instance => {
55
38
  prevRegister(instance);
56
- publicStaticMainEvent(arg)(instance, key, _);
39
+ let name = String(key);
40
+ if (arg) {
41
+ if (typeof arg === 'string') {
42
+ name = arg;
43
+ }
44
+ else {
45
+ name = arg.name ?? String(key);
46
+ if (arg.scope)
47
+ (0, publish_1.addScope)(name, arg.scope);
48
+ }
49
+ }
50
+ instance[key] = (0, publish_1.publicMainEvent)(name, instance[key].bind(instance));
57
51
  };
58
52
  };
59
53
  }
60
54
  exports.publicClassMainEvent = publicClassMainEvent;
61
- function publicStaticRendererEvent(arg) {
62
- return (target, key) => {
63
- let name = String(key);
64
- let receiver = (v) => v;
65
- if (arg) {
66
- if (typeof arg === 'string') {
67
- name = arg;
68
- }
69
- else if (typeof arg === 'object') {
70
- name = arg.name ?? String(key);
71
- receiver = arg.receiver ?? receiver;
72
- if (arg.scope)
73
- (0, publish_1.addScope)(name, arg.scope);
74
- }
75
- else {
76
- receiver = arg;
77
- }
78
- }
79
- target[key] = (0, publish_1.publicRendererEvent)(name, receiver);
80
- };
81
- }
82
- exports.publicStaticRendererEvent = publicStaticRendererEvent;
83
55
  function publicClassRendererEvent(arg) {
84
56
  return (tgt, key) => {
85
57
  const target = tgt;
86
58
  const prevRegister = target.__register__ ?? (() => { });
87
59
  target.__register__ = instance => {
88
60
  prevRegister(instance);
89
- publicStaticRendererEvent(arg)(instance, key);
61
+ let name = String(key);
62
+ let receiver = (v) => v;
63
+ if (arg) {
64
+ if (typeof arg === 'string') {
65
+ name = arg;
66
+ }
67
+ else if (typeof arg === 'object') {
68
+ name = arg.name ?? String(key);
69
+ receiver = arg.receiver ?? receiver;
70
+ if (arg.scope)
71
+ (0, publish_1.addScope)(name, arg.scope);
72
+ }
73
+ else {
74
+ receiver = arg;
75
+ }
76
+ }
77
+ instance[key] = (0, publish_1.publicRendererEvent)(name, receiver);
90
78
  };
91
79
  };
92
80
  }
@@ -25,61 +25,51 @@ function provideFromMain(contextIsolation = true) {
25
25
  properties: {},
26
26
  functions: {},
27
27
  mainEvents: {},
28
- rendererEvents: {}
28
+ rendererEvents: {},
29
29
  }
30
30
  };
31
31
  info.functions.forEach(funcName => {
32
- Object.defineProperty(provider.provided.functions, funcName, {
33
- value(...args) {
34
- return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + funcName, ...args);
35
- },
36
- enumerable: true
37
- });
32
+ provider.provided.functions[funcName] = (...args) => {
33
+ return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + funcName, ...args);
34
+ };
38
35
  });
39
- info.rendererEvents.forEach(rendererEventName => {
40
- Object.defineProperty(provider.provided.rendererEvents, rendererEventName, {
41
- value(arg) {
42
- const emitChannel = enums_1.IPCChannel.rendererEventEmit + rendererEventName;
43
- if (arg instanceof Promise) {
44
- arg
45
- .then(value => electron_1.ipcRenderer.send(emitChannel, { value }))
46
- .catch(reason => electron_1.ipcRenderer.send(emitChannel, { error: String(reason) }));
47
- }
48
- else {
49
- electron_1.ipcRenderer.send(emitChannel, { value: arg });
50
- }
51
- },
52
- enumerable: true
53
- });
36
+ info.rendererEvents.forEach(eventName => {
37
+ provider.provided.rendererEvents[eventName] = (arg) => {
38
+ const emitChannel = enums_1.IPCChannel.rendererEventEmit + eventName;
39
+ if (arg instanceof Promise) {
40
+ arg
41
+ .then(value => electron_1.ipcRenderer.send(emitChannel, { value }))
42
+ .catch(reason => electron_1.ipcRenderer.send(emitChannel, { error: String(reason) }));
43
+ }
44
+ else {
45
+ electron_1.ipcRenderer.send(emitChannel, { value: arg });
46
+ }
47
+ };
54
48
  });
55
- info.mainEvents.forEach(mainEventName => {
56
- Object.defineProperty(provider.provided.mainEvents, mainEventName, {
57
- value(type, handler) {
58
- const listener = (_, result) => handler(result);
59
- const emitChannel = enums_1.IPCChannel.mainEventEmit + mainEventName;
60
- if (type === 'on') {
61
- electron_1.ipcRenderer.on(emitChannel, listener);
62
- electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + mainEventName);
63
- }
64
- else {
65
- electron_1.ipcRenderer.once(emitChannel, listener);
66
- electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + mainEventName);
67
- }
68
- return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
69
- },
70
- enumerable: true
71
- });
49
+ info.mainEvents.forEach(eventName => {
50
+ provider.provided.mainEvents[eventName] = (type, handler) => {
51
+ const listener = (_, result) => handler(result);
52
+ const emitChannel = enums_1.IPCChannel.mainEventEmit + eventName;
53
+ if (type === 'on') {
54
+ electron_1.ipcRenderer.on(emitChannel, listener);
55
+ electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + eventName);
56
+ }
57
+ else {
58
+ electron_1.ipcRenderer.once(emitChannel, listener);
59
+ electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + eventName);
60
+ }
61
+ return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
62
+ };
72
63
  });
73
64
  info.properties.forEach(propName => {
74
- Object.defineProperty(provider.provided.properties, propName, {
65
+ provider.provided.properties[propName] = {
75
66
  get() {
76
67
  return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + propName);
77
68
  },
78
69
  set(value) {
79
70
  electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertySet + propName, value);
80
- },
81
- enumerable: true
82
- });
71
+ }
72
+ };
83
73
  });
84
74
  if (contextIsolation)
85
75
  electron_1.contextBridge.exposeInMainWorld('__provider__', provider);
@@ -7,153 +7,106 @@ function errorHandler(error, channel) {
7
7
  function createProvider(args) {
8
8
  const { info, scope, getVariable, setVariable, callFunction, handleMainEvent, waitPromise, emitRendererEvent } = args;
9
9
  const target = {
10
- as: () => proxy
10
+ as: () => target
11
11
  };
12
+ function define(name, attrs) {
13
+ let descriptor;
14
+ if (!info.scopes.get(name).has(scope)) {
15
+ descriptor = {
16
+ get() { throw new Error(`'${name}' is not provided into ${scope} scope`); },
17
+ set() { throw new Error(`'${name}' is not provided into ${scope} scope`); }
18
+ };
19
+ }
20
+ else if (attrs?.value) {
21
+ descriptor = {
22
+ get: () => attrs.value,
23
+ set: () => { throw new Error(`'${name}' is readonly`); },
24
+ enumerable: true
25
+ };
26
+ }
27
+ else {
28
+ descriptor = {
29
+ get: attrs?.get || (() => { throw new Error(`No access to getting '${name}'`); }),
30
+ set: attrs?.set || (() => { throw new Error(`'${name}' is readonly`); }),
31
+ enumerable: true
32
+ };
33
+ }
34
+ Object.defineProperty(target, name, descriptor);
35
+ }
12
36
  info.functions.forEach(funcName => {
13
- if (!info.scopes[funcName].has(scope))
14
- return;
15
- Object.defineProperty(target, funcName, {
16
- get() {
17
- return (...args) => {
18
- const result = callFunction(funcName, ...args);
19
- if (result.error) {
20
- errorHandler(result.error, funcName);
21
- return;
22
- }
23
- if (result.promiseChannel)
24
- return waitPromise(result.promiseChannel);
25
- return result.value;
26
- };
27
- },
28
- set() {
29
- throw new Error(`Function '${funcName}' is readonly`);
30
- },
31
- enumerable: true
37
+ define(funcName, {
38
+ value(...args) {
39
+ const result = callFunction(funcName, ...args);
40
+ if (result.error) {
41
+ errorHandler(result.error, funcName);
42
+ return;
43
+ }
44
+ if (result.promiseChannel)
45
+ return waitPromise(result.promiseChannel);
46
+ return result.value;
47
+ }
32
48
  });
33
49
  });
34
- info.rendererEvents.forEach(rendererEventName => {
35
- if (!info.scopes[rendererEventName].has(scope))
36
- return;
37
- Object.defineProperty(target, rendererEventName, {
38
- get() {
39
- return (arg) => emitRendererEvent(rendererEventName, arg);
40
- },
41
- set() {
42
- throw new Error(`Function '${rendererEventName}' is readonly`);
43
- },
44
- enumerable: true
50
+ info.rendererEvents.forEach(eventName => {
51
+ define(eventName, {
52
+ value(arg) {
53
+ emitRendererEvent(eventName, arg);
54
+ }
45
55
  });
46
56
  });
47
57
  info.mainEvents.forEach(mainEventName => {
48
- if (!info.scopes[mainEventName].has(scope))
49
- return;
50
58
  const eventNameOn = `on${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
51
59
  const eventNameOnce = `once${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
52
- Object.defineProperty(target, eventNameOn, {
53
- get() {
54
- return (handler) => {
55
- return handleMainEvent(mainEventName, 'on', (result) => {
56
- if (result.error) {
57
- errorHandler(result.error, mainEventName);
58
- return;
59
- }
60
- if (result.promiseChannel)
61
- waitPromise(result.promiseChannel).then(handler);
62
- handler(result.value);
63
- });
64
- };
65
- },
66
- set() {
67
- throw new Error(`Function '${eventNameOn}' is readonly`);
68
- },
69
- enumerable: true
60
+ define(eventNameOn, {
61
+ value(handler) {
62
+ return handleMainEvent(mainEventName, 'on', (result) => {
63
+ if (result.error) {
64
+ errorHandler(result.error, mainEventName);
65
+ return;
66
+ }
67
+ if (result.promiseChannel)
68
+ waitPromise(result.promiseChannel).then(handler);
69
+ handler(result.value);
70
+ });
71
+ }
70
72
  });
71
- Object.defineProperty(target, eventNameOnce, {
72
- get() {
73
- return (handler) => {
74
- return handleMainEvent(mainEventName, 'once', (result) => {
75
- if (result.error) {
76
- errorHandler(result.error, mainEventName);
77
- return;
78
- }
79
- if (result.promiseChannel)
80
- waitPromise(result.promiseChannel).then(handler);
81
- handler(result.value);
82
- });
83
- };
84
- },
85
- set() {
86
- throw new Error(`Function '${eventNameOnce}' is readonly`);
87
- },
88
- enumerable: true
73
+ define(eventNameOnce, {
74
+ value(handler) {
75
+ return handleMainEvent(mainEventName, 'once', (result) => {
76
+ if (result.error) {
77
+ errorHandler(result.error, mainEventName);
78
+ return;
79
+ }
80
+ if (result.promiseChannel)
81
+ waitPromise(result.promiseChannel).then(handler);
82
+ handler(result.value);
83
+ });
84
+ }
89
85
  });
90
86
  });
91
87
  info.properties.forEach(propName => {
92
- if (!info.scopes[propName].has(scope))
93
- return;
94
- let getter = () => {
95
- const result = getVariable(propName);
96
- if (result.error) {
97
- errorHandler(result.error, propName);
98
- return;
99
- }
100
- return result.value;
101
- };
102
- let setter = (value) => {
103
- const result = setVariable(propName, value);
104
- if (result?.error) {
105
- errorHandler(result.error, propName);
106
- return;
107
- }
108
- };
109
- if (!info.accesses[propName].has(enums_1.Access.get))
110
- getter = () => { throw new Error(`No access to getting the '${propName}' property`); };
111
- if (!info.accesses[propName].has(enums_1.Access.set))
112
- setter = () => { throw new Error(`No access to setting the '${propName}' property`); };
113
- Object.defineProperty(target, propName, {
114
- get: getter,
115
- set: setter,
116
- enumerable: true
88
+ define(propName, {
89
+ get: info.accesses.get(propName).has(enums_1.Access.get)
90
+ ? () => {
91
+ const result = getVariable(propName);
92
+ if (result.error) {
93
+ errorHandler(result.error, propName);
94
+ return;
95
+ }
96
+ return result.value;
97
+ }
98
+ : () => { throw new Error(`No access to getting the '${propName}' property`); },
99
+ set: info.accesses.get(propName).has(enums_1.Access.set)
100
+ ? (value) => {
101
+ const result = setVariable(propName, value);
102
+ if (result?.error) {
103
+ errorHandler(result.error, propName);
104
+ return;
105
+ }
106
+ }
107
+ : () => { throw new Error(`No access to setting the '${propName}' property`); }
117
108
  });
118
109
  });
119
- const proxy = new Proxy(target, {
120
- get(target, key) {
121
- if (key in target)
122
- return target[key];
123
- const isFunction = info.functions.has(key);
124
- const isProperty = info.properties.has(key);
125
- if (!isFunction && !isProperty)
126
- throw new Error(`'${key}' is not provided from main`);
127
- if (!info.scopes[key].has(enums_1.Scope.renderer))
128
- throw new Error(`'${key}' is not provided into renderer scope`);
129
- if (isProperty && !info.accesses[key].has(enums_1.Access.get))
130
- throw new Error(`No access to getting the '${key}' property`);
131
- throw new Error(`Unknown error on get '${key}'`);
132
- },
133
- set(target, key, newValue) {
134
- if (key in target) {
135
- target[key] = newValue;
136
- return true;
137
- }
138
- const isFunction = info.functions.has(key);
139
- const isProperty = info.properties.has(key);
140
- if (isFunction)
141
- throw new Error(`Function '${key}' is readonly`);
142
- if (!isProperty)
143
- throw new Error(`Property '${key}' is not provided from main`);
144
- if (!info.scopes[key].has(enums_1.Scope.renderer))
145
- throw new Error(`'${key}' is not provided into renderer scope`);
146
- if (!info.accesses[key].has(enums_1.Access.set))
147
- throw new Error(`No access to setting the '${key}' property`);
148
- throw new Error(`Unknown error on set '${key}'`);
149
- },
150
- ownKeys(target) {
151
- return Object.keys(target);
152
- },
153
- has(target, key) {
154
- return key in target;
155
- }
156
- });
157
- return proxy;
110
+ return target;
158
111
  }
159
112
  exports.default = createProvider;